index.js
function Shopify(options) {
  if (!(this instanceof Shopify)) return new Shopify(options);
  if (
    !options ||
    !options.shopName ||
    !options.accessToken && (!options.apiKey || !options.password) ||
    options.accessToken && (options.apiKey || options.password)
  ) {
    throw new Error('Missing or invalid options');
  }

  EventEmitter.call(this);
  this.options = defaults(options, { timeout: 60000 });

  //
  // API call limits, updated with each request.
  //
  this.callLimits = {
    remaining: undefined,
    current: undefined,
    max: undefined
  };

  this.baseUrl = {
    auth: !options.accessToken && `${options.apiKey}:${options.password}`,
    hostname: !options.shopName.endsWith('.myshopify.com')
      ? `${options.shopName}.myshopify.com`
      : options.shopName,
    protocol: 'https:'
  };

  if (options.autoLimit) {
    const conf = transform(options.autoLimit, (result, value, key) => {
      if (key === 'calls') key = 'limit';
      result[key] = value;
    }, { bucketSize: 35 });

    this.request = stopcock(this.request, conf);
  }
}
function Shopify(options) {
  if (!(this instanceof Shopify)) return new Shopify(options);
  if (
    !options ||
    !options.shopName ||
    !options.accessToken && (!options.apiKey || !options.password) ||
    options.accessToken && (options.apiKey || options.password)
  ) {
    throw new Error('Missing or invalid options');
  }

  EventEmitter.call(this);
  this.options = defaults(options, { timeout: 60000 });

  //
  // API call limits, updated with each request.
  //
  this.callLimits = {
    remaining: undefined,
    current: undefined,
    max: undefined
  };

  this.baseUrl = {
    auth: !options.accessToken && `${options.apiKey}:${options.password}`,
    hostname: !options.shopName.endsWith('.myshopify.com')
      ? `${options.shopName}.myshopify.com`
      : options.shopName,
    protocol: 'https:'
  };

  if (options.autoLimit) {
    const conf = transform(options.autoLimit, (result, value, key) => {
      if (key === 'calls') key = 'limit';
      result[key] = value;
    }, { bucketSize: 35 });

    this.request = stopcock(this.request, conf);
  }
}
function Shopify ( options ) { if ( ! ( this instanceof Shopify ) ) return new Shopify ( options ) ; if ( ! options || ! options . shopName || ! options . accessToken && ( ! options . apiKey || ! options . password ) || options . accessToken && ( options . apiKey || options . password ) ) { throw new Error ( 'Missing or invalid options' ) ; } EventEmitter . call ( this ) ; this . options = defaults ( options , { timeout : 60000 } ) ; // // API call limits, updated with each request. // this . callLimits = { remaining : undefined , current : undefined , max : undefined } ; this . baseUrl = { auth : ! options . accessToken && ` ${ options . apiKey } ${ options . password } ` , hostname : ! options . shopName . endsWith ( '.myshopify.com' ) ? ` ${ options . shopName } ` : options . shopName , protocol : 'https:' } ; if ( options . autoLimit ) { const conf = transform ( options . autoLimit , ( result , value , key ) => { if ( key === 'calls' ) key = 'limit' ; result [ key ] = value ; } , { bucketSize : 35 } ) ; this . request = stopcock ( this . request , conf ) ; } }
Creates a Shopify instance.

@param {Object} options Configuration options
@param {String} options.shopName The name of the shop
@param {String} options.apiKey The API Key
@param {String} options.password The private app password
@param {String} options.accessToken The persistent OAuth public app token
@param {Boolean|Object} [options.autoLimit] Limits the request rate
@param {Number} [options.timeout] The request timeout
@constructor
@public
Creates a Shopify instance .