shopify-api-node
Advanced tools
Comparing version 1.2.0 to 2.0.0
45
index.js
'use strict'; | ||
const camelCase = require('lodash/camelCase'); | ||
const defaults = require('lodash/defaults'); | ||
const assign = require('lodash/assign'); | ||
@@ -14,24 +15,25 @@ const path = require('path'); | ||
* | ||
* @param {String} shop The name of the shop | ||
* @param {String} key The API Key | ||
* @param {String} password The password | ||
* @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 {Number} [options.timeout] The request timeout | ||
* @constructor | ||
* @public | ||
*/ | ||
function Shopify(shop, key, password) { | ||
if (!(this instanceof Shopify)) return new Shopify(shop, key, password); | ||
if (!shop || !key) throw new Error('Missing required arguments'); | ||
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'); | ||
} | ||
let auth; | ||
this.options = defaults(options, { timeout: 60000 }); | ||
// | ||
// If we have only 2 arguments, `key` is a persistent OAuth2 token. | ||
// | ||
if (password) { | ||
auth = `${key}:${password}`; | ||
} else { | ||
this.token = key; | ||
} | ||
// | ||
// API call limits, updated with each request. | ||
@@ -46,5 +48,5 @@ // | ||
this.baseUrl = { | ||
hostname: `${shop}.myshopify.com`, | ||
protocol: 'https:', | ||
auth | ||
auth: !options.accessToken && `${options.apiKey}:${options.password}`, | ||
hostname: `${options.shopName}.myshopify.com`, | ||
protocol: 'https:' | ||
}; | ||
@@ -83,2 +85,3 @@ } | ||
headers: { 'User-Agent': `${pkg.name}/${pkg.version}` }, | ||
timeout: this.options.timeout, | ||
json: true, | ||
@@ -89,3 +92,5 @@ retries: 0, | ||
if (this.token) options.headers['X-Shopify-Access-Token'] = this.token; | ||
if (this.options.accessToken) { | ||
options.headers['X-Shopify-Access-Token'] = this.options.accessToken; | ||
} | ||
@@ -92,0 +97,0 @@ if (params) { |
{ | ||
"name": "shopify-api-node", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "Shopify API bindings for Node.js", | ||
@@ -24,5 +24,5 @@ "main": "index.js", | ||
"chai": "^3.5.0", | ||
"eslint": "^2.2.0", | ||
"eslint": "^3.0.1", | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.4.5", | ||
"mocha": "^3.0.1", | ||
"nock": "^8.0.0", | ||
@@ -29,0 +29,0 @@ "pre-commit": "^1.1.2" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
57167
47
1580
0
395