Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cimpress-customizr

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cimpress-customizr - npm Package Compare versions

Comparing version 0.0.6 to 1.0.0

9

CHANGELOG.md

@@ -7,4 +7,11 @@ # Changelog

## [0.0.6] -
## [0.1.0] - 2018.09.05
### Added
- Added get/setPreferredTimezone helpers
- Added auto-retry capability (options: retryAttempts and retryDelayInMs)
- Added tests
## [0.0.6] - 2018.08.14
### Added
- Initial version

@@ -9,2 +9,14 @@ 'use strict';

var _pope = require('pope');
var _axios = require('axios');
var _axios2 = _interopRequireDefault(_axios);
var _axiosRetry = require('axios-retry');
var _axiosRetry2 = _interopRequireDefault(_axiosRetry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

@@ -14,7 +26,2 @@

var _require = require('pope'),
pope = _require.pope;
var axios = require('axios');
var DEFAULT_BASE_URL = 'https://customizr.at.cimpress.io';

@@ -29,2 +36,12 @@

this.timeout = options.timeout || 3000;
this.retryAttempts = options.retryAttempts || 2;
this.retryDelayInMs = options.retryDelayInMs || 1000;
var understoodOptions = ['baseUrl', 'resource', 'timeout', 'retryAttempts', 'retryDelayInMs'];
Object.keys(options).forEach(function (passedOption) {
if (understoodOptions.indexOf(passedOption) === -1) {
// eslint-disable-next-line no-console
console.error('[CustomizrClient] Option \'' + passedOption + '\' is not understood and will be ignored.');
}
});
}

@@ -35,3 +52,3 @@

value: function __getUrl(resource) {
return '' + pope('/v1/resources/{{resource}}/settings', { resource: resource || this.resource });
return '' + (0, _pope.pope)('/v1/resources/{{resource}}/settings', { resource: resource || this.resource });
}

@@ -41,3 +58,5 @@ }, {

value: function __getAxiosInstance(accessToken) {
return axios.create({
var _this = this;
var instance = _axios2.default.create({
baseURL: this.baseUrl,

@@ -49,2 +68,13 @@ timeout: this.timeout,

});
if (this.retryAttempts > 0) {
(0, _axiosRetry2.default)(instance, {
retries: this.retryAttempts,
retryDelay: function retryDelay(retryCount) {
return _this.retryDelayInMs;
}
});
}
return instance;
}

@@ -74,3 +104,3 @@ }, {

if (!(_context.t0.response.status !== 404)) {
if (!(_context.t0.response && _context.t0.response.status !== 404)) {
_context.next = 12;

@@ -77,0 +107,0 @@ break;

10

lib/index.js

@@ -6,3 +6,3 @@ 'use strict';

});
exports.putMcpRegionalSettings = exports.getMcpRegionalSettings = exports.setPreferredMcpLanguage = exports.getPreferredMcpLanguages = exports.putMcpSettings = exports.getMcpSettings = exports.CustomizrClient = undefined;
exports.setPreferredMcpRegionalSettings = exports.getPreferredMcpRegionalSettings = exports.setPreferredMcpTimezone = exports.getPreferredMcpTimezone = exports.setPreferredMcpLanguage = exports.getPreferredMcpLanguages = exports.setMcpSettings = exports.getMcpSettings = exports.CustomizrClient = undefined;

@@ -21,6 +21,8 @@ require('regenerator-runtime/runtime');

exports.getMcpSettings = _mcpHelpers.getMcpSettings;
exports.putMcpSettings = _mcpHelpers.putMcpSettings;
exports.setMcpSettings = _mcpHelpers.setMcpSettings;
exports.getPreferredMcpLanguages = _mcpHelpers.getPreferredMcpLanguages;
exports.setPreferredMcpLanguage = _mcpHelpers.setPreferredMcpLanguage;
exports.getMcpRegionalSettings = _mcpHelpers.getMcpRegionalSettings;
exports.putMcpRegionalSettings = _mcpHelpers.putMcpRegionalSettings;
exports.getPreferredMcpTimezone = _mcpHelpers.getPreferredMcpTimezone;
exports.setPreferredMcpTimezone = _mcpHelpers.setPreferredMcpTimezone;
exports.getPreferredMcpRegionalSettings = _mcpHelpers.getPreferredMcpRegionalSettings;
exports.setPreferredMcpRegionalSettings = _mcpHelpers.setPreferredMcpRegionalSettings;

@@ -6,3 +6,3 @@ 'use strict';

});
exports.putMcpRegionalSettings = exports.getMcpRegionalSettings = exports.setPreferredMcpLanguage = exports.getPreferredMcpLanguages = exports.putMcpSettings = exports.getMcpSettings = undefined;
exports.setPreferredMcpTimezone = exports.getPreferredMcpTimezone = exports.setPreferredMcpRegionalSettings = exports.getPreferredMcpRegionalSettings = exports.setPreferredMcpLanguage = exports.getPreferredMcpLanguages = exports.setMcpSettings = exports.getMcpSettings = undefined;

@@ -34,3 +34,3 @@ var getMcpSettings = function () {

var putMcpSettings = function () {
var setMcpSettings = function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(accessToken, settings) {

@@ -43,3 +43,4 @@ return regeneratorRuntime.wrap(function _callee2$(_context2) {

language: settings.language,
regionalSettings: settings.regionalSettings
regionalSettings: settings.regionalSettings,
timezone: settings.timezone
});

@@ -55,3 +56,3 @@

return function putMcpSettings(_x2, _x3) {
return function setMcpSettings(_x2, _x3) {
return _ref2.apply(this, arguments);

@@ -115,3 +116,3 @@ };

throw new Error('Provided language code is not valid. Please pass valid ISO-639 code');
throw new Error('Provided language code is not valid. Please pass a valid ISO-639 code');

@@ -146,3 +147,3 @@ case 3:

var getMcpRegionalSettings = function () {
var getPreferredMcpRegionalSettings = function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(accessToken) {

@@ -159,3 +160,3 @@ var mcpSettings;

mcpSettings = _context5.sent;
return _context5.abrupt('return', mcpSettings.language);
return _context5.abrupt('return', mcpSettings.regionalSettings);

@@ -170,3 +171,3 @@ case 4:

return function getMcpRegionalSettings(_x7) {
return function getPreferredMcpRegionalSettings(_x7) {
return _ref5.apply(this, arguments);

@@ -176,4 +177,5 @@ };

var putMcpRegionalSettings = function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(accessToken, regionalSettings) {
var setPreferredMcpRegionalSettings = function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(accessToken, languageTag) {
var valid, rfcCompliantValue, tag;
return regeneratorRuntime.wrap(function _callee6$(_context6) {

@@ -183,7 +185,28 @@ while (1) {

case 0:
valid = false;
rfcCompliantValue = void 0;
try {
tag = new _rfc2.default(languageTag);
valid = !!tag.language;
rfcCompliantValue = tag.truncate({ script: false }).toString();
} catch (e) {
valid = false;
}
if (valid) {
_context6.next = 5;
break;
}
throw new Error('Expected a valid rfc5646 language tag (eg. "en", "en-US", ...)');
case 5:
mcpCustomizr.putSettings(accessToken, {
regionalSettings: regionalSettings
regionalSettings: rfcCompliantValue
});
case 1:
case 6:
case 'end':

@@ -196,3 +219,3 @@ return _context6.stop();

return function putMcpRegionalSettings(_x8, _x9) {
return function setPreferredMcpRegionalSettings(_x8, _x9) {
return _ref6.apply(this, arguments);

@@ -202,2 +225,66 @@ };

var getPreferredMcpTimezone = function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(accessToken) {
var mcpSettings;
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return mcpCustomizr.getSettings(accessToken);
case 2:
mcpSettings = _context7.sent;
return _context7.abrupt('return', mcpSettings.timezone);
case 4:
case 'end':
return _context7.stop();
}
}
}, _callee7, this);
}));
return function getPreferredMcpTimezone(_x10) {
return _ref7.apply(this, arguments);
};
}();
var setPreferredMcpTimezone = function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(accessToken, timezone) {
var tz;
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
tz = validTimezones.find(function (t) {
return t === timezone;
});
if (tz) {
_context8.next = 3;
break;
}
throw new Error('Provided timezone is not valid. Please pass valid IANA timezone identifier, eg. Europe/Amsterdam');
case 3:
mcpCustomizr.putSettings(accessToken, {
timezone: timezone
});
case 4:
case 'end':
return _context8.stop();
}
}
}, _callee8, this);
}));
return function setPreferredMcpTimezone(_x11, _x12) {
return _ref8.apply(this, arguments);
};
}();
var _CustomizrClient = require('./CustomizrClient');

@@ -211,2 +298,10 @@

var _ianaTzData = require('iana-tz-data');
var _ianaTzData2 = _interopRequireDefault(_ianaTzData);
var _rfc = require('rfc5646');
var _rfc2 = _interopRequireDefault(_rfc);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -220,7 +315,17 @@

var validTimezones = [];
var regions = Object.keys(_ianaTzData2.default.zoneData);
regions.forEach(function (region) {
Object.keys(_ianaTzData2.default.zoneData[region]).forEach(function (city) {
validTimezones.push(region + '/' + city);
});
});
exports.getMcpSettings = getMcpSettings;
exports.putMcpSettings = putMcpSettings;
exports.setMcpSettings = setMcpSettings;
exports.getPreferredMcpLanguages = getPreferredMcpLanguages;
exports.setPreferredMcpLanguage = setPreferredMcpLanguage;
exports.getMcpRegionalSettings = getMcpRegionalSettings;
exports.putMcpRegionalSettings = putMcpRegionalSettings;
exports.getPreferredMcpRegionalSettings = getPreferredMcpRegionalSettings;
exports.setPreferredMcpRegionalSettings = setPreferredMcpRegionalSettings;
exports.getPreferredMcpTimezone = getPreferredMcpTimezone;
exports.setPreferredMcpTimezone = setPreferredMcpTimezone;
{
"name": "cimpress-customizr",
"version": "0.0.6",
"version": "1.0.0",
"description": "A thin client for Cimpress Customizr service",

@@ -10,3 +10,3 @@ "main": "./lib/index.js",

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "node ./node_modules/mocha/bin/mocha --require babel-core/register tests/",
"code-check": "eslint --ext .js --ext .jsx src",

@@ -31,12 +31,20 @@ "build": "node ./node_modules/babel-cli/bin/babel.js src -d lib --copy-files"

"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"eslint": "^5.4.0",
"eslint-config-google": "^0.9.1"
"eslint-config-google": "^0.9.1",
"nock": "^9.6.1",
"chai": "^4.1.2",
"mocha": "^5.2.0"
},
"dependencies": {
"axios": "^0.18.0",
"axios-retry": "^3.1.1",
"country-language": "^0.1.7",
"iana-tz-data": "^2017.1.0",
"pope": "^2.0.2",
"regenerator": "^0.13.2",
"regenerator-runtime": "^0.12.1"
"regenerator-runtime": "^0.12.1",
"rfc5646": "^3.0.0"
}
}

@@ -24,3 +24,9 @@ # cimpress-customizr

// The address of Cimpress Customizr service
baseUrl: 'https://customizr.at.cimpress.io'
baseUrl: 'https://customizr.at.cimpress.io',
// How many try to retry the request in case of network error or 5xx response
retryAttempts: 2,
// How long to wait between retries in milliseconds
retryDelayInMs: 1000
});

@@ -34,6 +40,17 @@

import {getMcpSettings, putMcpSettings,
getPreferredMcpLanguages, setPreferredMcpLanguage,
getMcpRegionalSettings, putMcpRegionalSettings} from 'cimpress-customizr'
import {
getMcpSettings,
setMcpSettings,
getPreferredMcpLanguages,
setPreferredMcpLanguage,
getPreferredMcpTimezone,
setPreferredMcpTimezone
getMcpRegionalSettings,
setMcpRegionalSettings
} from 'cimpress-customizr'
getPreferredMcpLanguages(accessToken).then( languageArray => {

@@ -40,0 +57,0 @@ /*

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc