@ndustrial/contxt-sdk 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/esm/index.js CHANGED
@@ -13,6 +13,7 @@ import Iot from './iot';
13
13
  import Nionic from './nionic';
14
14
  import Request from './request';
15
15
  import * as sessionTypes from './sessionTypes';
16
+ import { toSnakeCase, toCamelCase } from './utils/objects';
16
17
 
17
18
  /**
18
19
  * An adapter that allows the SDK to authenticate with different services and manage various tokens.
@@ -229,5 +230,5 @@ var ContxtSdk = function () {
229
230
  }();
230
231
 
231
232
  export default ContxtSdk;
232
- export { toSnakeCase, toCamelCase } from './utils/objects';
233
+ export { toSnakeCase, toCamelCase };
233
234
  //# sourceMappingURL=index.js.map
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"names":["Bus","Config","Coordinator","Events","Files","Iot","Nionic","Request","sessionTypes","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","auth","_createAuthSession","bus","_createRequest","coordinator","events","files","iot","nionic","_decorate","moduleName","clientId","host","module","indexOf","Error","addDynamicAudience","clearCurrentApiToken","removeDynamicAudience","filter","name","TYPES","AUTH0_WEB_AUTH","Auth0WebAuth","PASSWORD_GRANT_AUTH","PasswordGrantAuth","MACHINE_AUTH","MachineAuth","audienceName","modules","Object","keys","forEach","toSnakeCase","toCamelCase"],"mappings":";;;;;;AAAA,OAAOA,GAAP,MAAgB,OAAhB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,GAAP,MAAgB,OAAhB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,YAAZ,MAA8B,gBAA9B;;AAEA;;;;;;;;;;;;;;;;;;;;;;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mBAAxB;AACE,iBAAO,IAAI/B,aAAagC,iBAAjB,CAAmC,IAAnC,CAAP;;AAEF,aAAKhC,aAAa4B,KAAb,CAAmBK,YAAxB;AACE,iBAAO,IAAIjC,aAAakC,WAAjB,CAA6B,IAA7B,CAAP;;AAEF;AACE,gBAAM,IAAIZ,KAAJ,CAAU,8BAAV,CAAN;AAXJ;AAaD;;AAED;;;;;;;;;;;;;mCAUea,Y,EAAc;AAC3B,aAAO,IAAIpC,OAAJ,CAAY,IAAZ,EAAkBoC,YAAlB,CAAP;AACD;;AAED;;;;;;;;;;;8BAQUC,O,EAAS;AAAA;;AACjBC,aAAOC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACtB,UAAD,EAAgB;AAC3C,cAAKA,UAAL,IAAmB,IAAImB,QAAQnB,UAAR,EAAoBG,MAAxB,CACjB,KADiB,EAEjB,MAAKV,cAAL,CAAoBO,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;AAGH,eAAehB,SAAf;AACA,SAASuC,WAAT,EAAsBC,WAAtB,QAAyC,iBAAzC","file":"index.js","sourcesContent":["import Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Files from './files';\nimport Iot from './iot';\nimport Nionic from './nionic';\nimport Request from './request';\nimport * as sessionTypes from './sessionTypes';\n\n/**\n * An adapter that allows the SDK to authenticate with different services and manage various tokens.\n * Can authenticate with a service like Auth0 and then with Contxt or can communicate directly\n * with Contxt. The adapter must implement required methods, but most methods are optional. Some of\n * the optional methods are documented below.\n *\n * @typedef {Object} SessionType\n * @property {function} [getCurrentAccessToken] Provides a current access token from Auth0 that is\n * used for profile information and can be used to get API token for Contxt itself\n * @property {function} getCurrentApiToken Provides a current API token that is used across\n * different Contxt services\n * @property {function} [getProfile] Provides profile information about the current user\n * @property {function} [handleAuthentication] Is called by front-end code in the Auth0 reference\n * implementation to handle getting the access token from Auth0\n * @property {function} [isAuthenticated] Tells caller if the current user is authenticated.\n * Different session types may determine if a user is authenticated in different ways.\n * @property {function} [logIn] Is used by front-end code in the Auth0 reference implementation to\n * start the sign in process\n * @property {function} [logOut] Is used by the front-end code in the Auth0 reference implementation\n * to sign the user out\n */\n\n/**\n * ContxtSdk constructor\n *\n * @example\n * import ContxtSdk from '@ndustrial/contxt-sdk';\n * import ExternalModule1 from './ExternalModule1';\n * import history from '../services/history';\n *\n * const contxtSdk = new ContxtSdk({\n * config: {\n * auth: {\n * clientId: 'Auth0 client id of the application being built',\n * customModuleConfigs: {\n * facilities: {\n * env: 'production'\n * }\n * },\n * env: 'staging',\n * onAuthenticate: (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo),\n * onRedirect: (pathname) => history.push(pathname)\n * }\n * },\n * externalModules: {\n * externalModule1: {\n * clientId: 'Auth0 client id of the external module',\n * host: 'https://www.example.com/externalModule1',\n * module: ExternalModule1\n * }\n * },\n * sessionType: 'auth0WebAuth'\n * });\n */\nclass ContxtSdk {\n /**\n * @param {UserConfig} config The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that\n * should be treated as first class citizens\n * @param {string} sessionType The type of auth session you wish to use (e.g. auth0WebAuth\n * or machine)\n */\n constructor({ config = {}, externalModules = {}, sessionType }) {\n this._dynamicModuleNames = [];\n this._replacedModules = {};\n\n this.config = new Config(config, externalModules);\n\n this.auth = this._createAuthSession(sessionType);\n this.bus = new Bus(this, this._createRequest('bus'));\n this.coordinator = new Coordinator(\n this,\n this._createRequest('coordinator')\n );\n this.events = new Events(this, this._createRequest('events'));\n this.files = new Files(this, this._createRequest('files'));\n this.iot = new Iot(this, this._createRequest('iot'));\n this.nionic = new Nionic(this, this._createRequest('nionic'));\n\n this._decorate(externalModules);\n }\n\n /**\n * Mounts a dynamic module into the SDK. Is used to add a module after initial\n * instatiation that will use the SDK's authentication and request methods to\n * access an ndustrial.io API\n *\n * @param {string} moduleName The name (or key) that will serve as the mount\n * point for the module in the SDK (i.e. customModule -> sdk.customModule)\n * @param {ExternalModule} externalModule\n */\n mountDynamicModule(moduleName, { clientId, host, module }) {\n if (this._dynamicModuleNames.indexOf(moduleName) > -1) {\n throw new Error(\n `An dynamic module of the name \\`${moduleName}\\` already exists. This problem can be rectified by using a different name for the new module.`\n );\n }\n\n this.config.addDynamicAudience(moduleName, { clientId, host });\n\n this._dynamicModuleNames = [...this._dynamicModuleNames, moduleName];\n\n if (this[moduleName]) {\n this._replacedModules[moduleName] = this[moduleName];\n }\n\n this[moduleName] = new module(this, this._createRequest(moduleName));\n }\n\n /**\n * Unmounts a dynamic module from the SDK\n *\n * @param {string} moduleName The name of the dynamic module to unmount\n */\n unmountDynamicModule(moduleName) {\n if (this._dynamicModuleNames.indexOf(moduleName) === -1) {\n throw new Error('There is no external module to unmount.');\n }\n\n this.auth.clearCurrentApiToken(moduleName);\n this.config.removeDynamicAudience(moduleName);\n\n this[moduleName] = this._replacedModules[moduleName];\n\n delete this._replacedModules[moduleName];\n this._dynamicModuleNames = this._dynamicModuleNames.filter(\n (name) => name !== moduleName\n );\n }\n\n /**\n * Returns a new instance of the session type requested\n *\n * @param {string} sessionType\n *\n * @returns {SessionType} sessionType\n * @throws {Error}\n *\n * @private\n */\n _createAuthSession(sessionType) {\n switch (sessionType) {\n case sessionTypes.TYPES.AUTH0_WEB_AUTH:\n return new sessionTypes.Auth0WebAuth(this);\n\n case sessionTypes.TYPES.PASSWORD_GRANT_AUTH:\n return new sessionTypes.PasswordGrantAuth(this);\n\n case sessionTypes.TYPES.MACHINE_AUTH:\n return new sessionTypes.MachineAuth(this);\n\n default:\n throw new Error('Invalid sessionType provided');\n }\n }\n\n /**\n * Returns an instance of the Request module that is tied to the requested audience\n *\n * @param {string} audienceName The audience name of the service you are trying to reach\n * (e.g. facilities or feeds)\n *\n * @returns {Object} Request module\n *\n * @private\n */\n _createRequest(audienceName) {\n return new Request(this, audienceName);\n }\n\n /**\n * Decorates custom modules onto the SDK instance so they behave as first-class citizens.\n *\n * @param {Object} modules\n * @param {function} modules.module\n *\n * @private\n */\n _decorate(modules) {\n Object.keys(modules).forEach((moduleName) => {\n this[moduleName] = new modules[moduleName].module(\n this,\n this._createRequest(moduleName)\n );\n });\n }\n}\n\nexport default ContxtSdk;\nexport { toSnakeCase, toCamelCase } from './utils/objects';\n"]}
1
+ {"version":3,"sources":["index.js"],"names":["Bus","Config","Coordinator","Events","Files","Iot","Nionic","Request","sessionTypes","toSnakeCase","toCamelCase","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","auth","_createAuthSession","bus","_createRequest","coordinator","events","files","iot","nionic","_decorate","moduleName","clientId","host","module","indexOf","Error","addDynamicAudience","clearCurrentApiToken","removeDynamicAudience","filter","name","TYPES","AUTH0_WEB_AUTH","Auth0WebAuth","PASSWORD_GRANT_AUTH","PasswordGrantAuth","MACHINE_AUTH","MachineAuth","audienceName","modules","Object","keys","forEach"],"mappings":";;;;;;AAAA,OAAOA,GAAP,MAAgB,OAAhB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,GAAP,MAAgB,OAAhB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,YAAZ,MAA8B,gBAA9B;AACA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,iBAAzC;;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgCMC,S;AACJ;;;;;;;AAOA,2BAAgE;AAAA,2BAAlDC,MAAkD;AAAA,QAAlDA,MAAkD,+BAAzC,EAAyC;AAAA,oCAArCC,eAAqC;AAAA,QAArCA,eAAqC,wCAAnB,EAAmB;AAAA,QAAfC,WAAe,QAAfA,WAAe;;AAAA;;AAC9D,SAAKC,mBAAL,GAA2B,EAA3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IAAItC,OAAJ,CAAY,IAAZ,EAAkBsC,YAAlB,CAAP;AACD;;AAED;;;;;;;;;;;8BAQUC,O,EAAS;AAAA;;AACjBC,aAAOC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACtB,UAAD,EAAgB;AAC3C,cAAKA,UAAL,IAAmB,IAAImB,QAAQnB,UAAR,EAAoBG,MAAxB,CACjB,KADiB,EAEjB,MAAKV,cAAL,CAAoBO,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;AAGH,eAAehB,SAAf;AACA,SAASF,WAAT,EAAsBC,WAAtB","file":"index.js","sourcesContent":["import Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Files from './files';\nimport Iot from './iot';\nimport Nionic from './nionic';\nimport Request from './request';\nimport * as sessionTypes from './sessionTypes';\nimport { toSnakeCase, toCamelCase } from './utils/objects';\n\n/**\n * An adapter that allows the SDK to authenticate with different services and manage various tokens.\n * Can authenticate with a service like Auth0 and then with Contxt or can communicate directly\n * with Contxt. The adapter must implement required methods, but most methods are optional. Some of\n * the optional methods are documented below.\n *\n * @typedef {Object} SessionType\n * @property {function} [getCurrentAccessToken] Provides a current access token from Auth0 that is\n * used for profile information and can be used to get API token for Contxt itself\n * @property {function} getCurrentApiToken Provides a current API token that is used across\n * different Contxt services\n * @property {function} [getProfile] Provides profile information about the current user\n * @property {function} [handleAuthentication] Is called by front-end code in the Auth0 reference\n * implementation to handle getting the access token from Auth0\n * @property {function} [isAuthenticated] Tells caller if the current user is authenticated.\n * Different session types may determine if a user is authenticated in different ways.\n * @property {function} [logIn] Is used by front-end code in the Auth0 reference implementation to\n * start the sign in process\n * @property {function} [logOut] Is used by the front-end code in the Auth0 reference implementation\n * to sign the user out\n */\n\n/**\n * ContxtSdk constructor\n *\n * @example\n * import ContxtSdk from '@ndustrial/contxt-sdk';\n * import ExternalModule1 from './ExternalModule1';\n * import history from '../services/history';\n *\n * const contxtSdk = new ContxtSdk({\n * config: {\n * auth: {\n * clientId: 'Auth0 client id of the application being built',\n * customModuleConfigs: {\n * facilities: {\n * env: 'production'\n * }\n * },\n * env: 'staging',\n * onAuthenticate: (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo),\n * onRedirect: (pathname) => history.push(pathname)\n * }\n * },\n * externalModules: {\n * externalModule1: {\n * clientId: 'Auth0 client id of the external module',\n * host: 'https://www.example.com/externalModule1',\n * module: ExternalModule1\n * }\n * },\n * sessionType: 'auth0WebAuth'\n * });\n */\nclass ContxtSdk {\n /**\n * @param {UserConfig} config The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that\n * should be treated as first class citizens\n * @param {string} sessionType The type of auth session you wish to use (e.g. auth0WebAuth\n * or machine)\n */\n constructor({ config = {}, externalModules = {}, sessionType }) {\n this._dynamicModuleNames = [];\n this._replacedModules = {};\n\n this.config = new Config(config, externalModules);\n\n this.auth = this._createAuthSession(sessionType);\n this.bus = new Bus(this, this._createRequest('bus'));\n this.coordinator = new Coordinator(\n this,\n this._createRequest('coordinator')\n );\n this.events = new Events(this, this._createRequest('events'));\n this.files = new Files(this, this._createRequest('files'));\n this.iot = new Iot(this, this._createRequest('iot'));\n this.nionic = new Nionic(this, this._createRequest('nionic'));\n\n this._decorate(externalModules);\n }\n\n /**\n * Mounts a dynamic module into the SDK. Is used to add a module after initial\n * instatiation that will use the SDK's authentication and request methods to\n * access an ndustrial.io API\n *\n * @param {string} moduleName The name (or key) that will serve as the mount\n * point for the module in the SDK (i.e. customModule -> sdk.customModule)\n * @param {ExternalModule} externalModule\n */\n mountDynamicModule(moduleName, { clientId, host, module }) {\n if (this._dynamicModuleNames.indexOf(moduleName) > -1) {\n throw new Error(\n `An dynamic module of the name \\`${moduleName}\\` already exists. This problem can be rectified by using a different name for the new module.`\n );\n }\n\n this.config.addDynamicAudience(moduleName, { clientId, host });\n\n this._dynamicModuleNames = [...this._dynamicModuleNames, moduleName];\n\n if (this[moduleName]) {\n this._replacedModules[moduleName] = this[moduleName];\n }\n\n this[moduleName] = new module(this, this._createRequest(moduleName));\n }\n\n /**\n * Unmounts a dynamic module from the SDK\n *\n * @param {string} moduleName The name of the dynamic module to unmount\n */\n unmountDynamicModule(moduleName) {\n if (this._dynamicModuleNames.indexOf(moduleName) === -1) {\n throw new Error('There is no external module to unmount.');\n }\n\n this.auth.clearCurrentApiToken(moduleName);\n this.config.removeDynamicAudience(moduleName);\n\n this[moduleName] = this._replacedModules[moduleName];\n\n delete this._replacedModules[moduleName];\n this._dynamicModuleNames = this._dynamicModuleNames.filter(\n (name) => name !== moduleName\n );\n }\n\n /**\n * Returns a new instance of the session type requested\n *\n * @param {string} sessionType\n *\n * @returns {SessionType} sessionType\n * @throws {Error}\n *\n * @private\n */\n _createAuthSession(sessionType) {\n switch (sessionType) {\n case sessionTypes.TYPES.AUTH0_WEB_AUTH:\n return new sessionTypes.Auth0WebAuth(this);\n\n case sessionTypes.TYPES.PASSWORD_GRANT_AUTH:\n return new sessionTypes.PasswordGrantAuth(this);\n\n case sessionTypes.TYPES.MACHINE_AUTH:\n return new sessionTypes.MachineAuth(this);\n\n default:\n throw new Error('Invalid sessionType provided');\n }\n }\n\n /**\n * Returns an instance of the Request module that is tied to the requested audience\n *\n * @param {string} audienceName The audience name of the service you are trying to reach\n * (e.g. facilities or feeds)\n *\n * @returns {Object} Request module\n *\n * @private\n */\n _createRequest(audienceName) {\n return new Request(this, audienceName);\n }\n\n /**\n * Decorates custom modules onto the SDK instance so they behave as first-class citizens.\n *\n * @param {Object} modules\n * @param {function} modules.module\n *\n * @private\n */\n _decorate(modules) {\n Object.keys(modules).forEach((moduleName) => {\n this[moduleName] = new modules[moduleName].module(\n this,\n this._createRequest(moduleName)\n );\n });\n }\n}\n\nexport default ContxtSdk;\nexport { toSnakeCase, toCamelCase };\n"]}
package/lib/index.js CHANGED
@@ -7,21 +7,6 @@ exports.toCamelCase = exports.toSnakeCase = undefined;
7
7
 
8
8
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
9
9
 
10
- var _objects = require('./utils/objects');
11
-
12
- Object.defineProperty(exports, 'toSnakeCase', {
13
- enumerable: true,
14
- get: function get() {
15
- return _objects.toSnakeCase;
16
- }
17
- });
18
- Object.defineProperty(exports, 'toCamelCase', {
19
- enumerable: true,
20
- get: function get() {
21
- return _objects.toCamelCase;
22
- }
23
- });
24
-
25
10
  var _bus = require('./bus');
26
11
 
27
12
  var _bus2 = _interopRequireDefault(_bus);
@@ -58,6 +43,8 @@ var _sessionTypes = require('./sessionTypes');
58
43
 
59
44
  var sessionTypes = _interopRequireWildcard(_sessionTypes);
60
45
 
46
+ var _objects = require('./utils/objects');
47
+
61
48
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
62
49
 
63
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -280,4 +267,6 @@ var ContxtSdk = function () {
280
267
  }();
281
268
 
282
269
  exports.default = ContxtSdk;
270
+ exports.toSnakeCase = _objects.toSnakeCase;
271
+ exports.toCamelCase = _objects.toCamelCase;
283
272
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.js"],"names":["toSnakeCase","toCamelCase","sessionTypes","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","Config","auth","_createAuthSession","bus","Bus","_createRequest","coordinator","Coordinator","events","Events","files","Files","iot","Iot","nionic","Nionic","_decorate","moduleName","clientId","host","module","indexOf","Error","addDynamicAudience","clearCurrentApiToken","removeDynamicAudience","filter","name","TYPES","AUTH0_WEB_AUTH","Auth0WebAuth","PASSWORD_GRANT_AUTH","PasswordGrantAuth","MACHINE_AUTH","MachineAuth","audienceName","Request","modules","Object","keys","forEach"],"mappings":";;;;;;;;;;;;;;oBAuMSA,W;;;;;;oBAAaC,W;;;;AAvMtB;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;IAAYC,Y;;;;;;;;;;AAEZ;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgCMC,S;AACJ;;;;;;;AAOA,2BAAgE;AAAA,2BAAlDC,MAAkD;AAAA,QAAlDA,MAAkD,+BAAzC,EAAyC;AAAA,oCAArCC,eAAqC;AAAA,QAArCA,eAAqC,wCAAnB,EAAmB;AAAA,QAAfC,WAAe,QAAfA,WAAe;;AAAA;;AAC9D,SAAKC,mBAAL,GAA2B,EAA3B;AACA,SAAKC,gBAAL,GAAwB,EAAxB;;AAEA,SAAKJ,MAAL,GAAc,IAAIK,gBAAJ,CAAWL,MAAX,EAAmBC,eAAnB,CAAd;;AAEA,SAAKK,IAAL,GAAY,KAAKC,kBAAL,CAAwBL,WAAxB,CAAZ;AACA,SAAKM,GAAL,GAAW,IAAIC,aAAJ,CAAQ,IAAR,EAAc,KAAKC,cAAL,CAAoB,KAApB,CAAd,CAAX;AACA,SAAKC,WAAL,GAAmB,IAAIC,qBAAJ,CACjB,IADiB,EAEjB,KAAKF,cAAL,CAAoB,aAApB,CAFiB,CAAnB;AAIA,SAAKG,MAAL,GAAc,IAAIC,gBAAJ,CAAW,IAAX,EAAiB,KAAKJ,cAAL,CAAoB,QAApB,CAAjB,CAAd;AACA,SAAKK,KAAL,GAAa,IAAIC,eAAJ,CAAU,IAAV,EAAgB,KAAKN,cAAL,CAAoB,OAApB,CAAhB,CAAb;A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AAtB,CAAnB;;AAEA,aAAO,KAAKlB,gBAAL,CAAsBkB,UAAtB,CAAP;AACA,WAAKnB,mBAAL,GAA2B,KAAKA,mBAAL,CAAyB4B,MAAzB,CACzB,UAACC,IAAD;AAAA,eAAUA,SAASV,UAAnB;AAAA,OADyB,CAA3B;AAGD;;AAED;;;;;;;;;;;;;uCAUmBpB,W,EAAa;AAC9B,cAAQA,WAAR;AACE,aAAKJ,aAAamC,KAAb,CAAmBC,cAAxB;AACE,iBAAO,IAAIpC,aAAaqC,YAAjB,CAA8B,IAA9B,CAAP;;AAEF,aAAKrC,aAAamC,KAAb,CAAmBG,mBAAxB;AACE,iBAAO,IAAItC,aAAauC,iBAAjB,CAAmC,IAAnC,CAAP;;AAEF,aAAKvC,aAAamC,KAAb,CAAmBK,YAAxB;AACE,iBAAO,IAAIxC,aAAayC,WAAjB,CAA6B,IAA7B,CAAP;;AAEF;AACE,gBAAM,IAAIZ,KAAJ,CAAU,8BAAV,CAAN;AAXJ;AAaD;;AAED;;;;;;;;;;;;;mCAUea,Y,EAAc;AAC3B,aAAO,IAAIC,iBAAJ,CAAY,IAAZ,EAAkBD,YAAlB,CAAP;AACD;;AAED;;;;;;;;;;;8BAQUE,O,EAAS;AAAA;;AACjBC,aAAOC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACvB,UAAD,EAAgB;AAC3C,cAAKA,UAAL,IAAmB,IAAIoB,QAAQpB,UAAR,EAAoBG,MAAxB,CACjB,KADiB,EAEjB,MAAKf,cAAL,CAAoBY,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;kBAGYvB,S","file":"index.js","sourcesContent":["import Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Files from './files';\nimport Iot from './iot';\nimport Nionic from './nionic';\nimport Request from './request';\nimport * as sessionTypes from './sessionTypes';\n\n/**\n * An adapter that allows the SDK to authenticate with different services and manage various tokens.\n * Can authenticate with a service like Auth0 and then with Contxt or can communicate directly\n * with Contxt. The adapter must implement required methods, but most methods are optional. Some of\n * the optional methods are documented below.\n *\n * @typedef {Object} SessionType\n * @property {function} [getCurrentAccessToken] Provides a current access token from Auth0 that is\n * used for profile information and can be used to get API token for Contxt itself\n * @property {function} getCurrentApiToken Provides a current API token that is used across\n * different Contxt services\n * @property {function} [getProfile] Provides profile information about the current user\n * @property {function} [handleAuthentication] Is called by front-end code in the Auth0 reference\n * implementation to handle getting the access token from Auth0\n * @property {function} [isAuthenticated] Tells caller if the current user is authenticated.\n * Different session types may determine if a user is authenticated in different ways.\n * @property {function} [logIn] Is used by front-end code in the Auth0 reference implementation to\n * start the sign in process\n * @property {function} [logOut] Is used by the front-end code in the Auth0 reference implementation\n * to sign the user out\n */\n\n/**\n * ContxtSdk constructor\n *\n * @example\n * import ContxtSdk from '@ndustrial/contxt-sdk';\n * import ExternalModule1 from './ExternalModule1';\n * import history from '../services/history';\n *\n * const contxtSdk = new ContxtSdk({\n * config: {\n * auth: {\n * clientId: 'Auth0 client id of the application being built',\n * customModuleConfigs: {\n * facilities: {\n * env: 'production'\n * }\n * },\n * env: 'staging',\n * onAuthenticate: (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo),\n * onRedirect: (pathname) => history.push(pathname)\n * }\n * },\n * externalModules: {\n * externalModule1: {\n * clientId: 'Auth0 client id of the external module',\n * host: 'https://www.example.com/externalModule1',\n * module: ExternalModule1\n * }\n * },\n * sessionType: 'auth0WebAuth'\n * });\n */\nclass ContxtSdk {\n /**\n * @param {UserConfig} config The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that\n * should be treated as first class citizens\n * @param {string} sessionType The type of auth session you wish to use (e.g. auth0WebAuth\n * or machine)\n */\n constructor({ config = {}, externalModules = {}, sessionType }) {\n this._dynamicModuleNames = [];\n this._replacedModules = {};\n\n this.config = new Config(config, externalModules);\n\n this.auth = this._createAuthSession(sessionType);\n this.bus = new Bus(this, this._createRequest('bus'));\n this.coordinator = new Coordinator(\n this,\n this._createRequest('coordinator')\n );\n this.events = new Events(this, this._createRequest('events'));\n this.files = new Files(this, this._createRequest('files'));\n this.iot = new Iot(this, this._createRequest('iot'));\n this.nionic = new Nionic(this, this._createRequest('nionic'));\n\n this._decorate(externalModules);\n }\n\n /**\n * Mounts a dynamic module into the SDK. Is used to add a module after initial\n * instatiation that will use the SDK's authentication and request methods to\n * access an ndustrial.io API\n *\n * @param {string} moduleName The name (or key) that will serve as the mount\n * point for the module in the SDK (i.e. customModule -> sdk.customModule)\n * @param {ExternalModule} externalModule\n */\n mountDynamicModule(moduleName, { clientId, host, module }) {\n if (this._dynamicModuleNames.indexOf(moduleName) > -1) {\n throw new Error(\n `An dynamic module of the name \\`${moduleName}\\` already exists. This problem can be rectified by using a different name for the new module.`\n );\n }\n\n this.config.addDynamicAudience(moduleName, { clientId, host });\n\n this._dynamicModuleNames = [...this._dynamicModuleNames, moduleName];\n\n if (this[moduleName]) {\n this._replacedModules[moduleName] = this[moduleName];\n }\n\n this[moduleName] = new module(this, this._createRequest(moduleName));\n }\n\n /**\n * Unmounts a dynamic module from the SDK\n *\n * @param {string} moduleName The name of the dynamic module to unmount\n */\n unmountDynamicModule(moduleName) {\n if (this._dynamicModuleNames.indexOf(moduleName) === -1) {\n throw new Error('There is no external module to unmount.');\n }\n\n this.auth.clearCurrentApiToken(moduleName);\n this.config.removeDynamicAudience(moduleName);\n\n this[moduleName] = this._replacedModules[moduleName];\n\n delete this._replacedModules[moduleName];\n this._dynamicModuleNames = this._dynamicModuleNames.filter(\n (name) => name !== moduleName\n );\n }\n\n /**\n * Returns a new instance of the session type requested\n *\n * @param {string} sessionType\n *\n * @returns {SessionType} sessionType\n * @throws {Error}\n *\n * @private\n */\n _createAuthSession(sessionType) {\n switch (sessionType) {\n case sessionTypes.TYPES.AUTH0_WEB_AUTH:\n return new sessionTypes.Auth0WebAuth(this);\n\n case sessionTypes.TYPES.PASSWORD_GRANT_AUTH:\n return new sessionTypes.PasswordGrantAuth(this);\n\n case sessionTypes.TYPES.MACHINE_AUTH:\n return new sessionTypes.MachineAuth(this);\n\n default:\n throw new Error('Invalid sessionType provided');\n }\n }\n\n /**\n * Returns an instance of the Request module that is tied to the requested audience\n *\n * @param {string} audienceName The audience name of the service you are trying to reach\n * (e.g. facilities or feeds)\n *\n * @returns {Object} Request module\n *\n * @private\n */\n _createRequest(audienceName) {\n return new Request(this, audienceName);\n }\n\n /**\n * Decorates custom modules onto the SDK instance so they behave as first-class citizens.\n *\n * @param {Object} modules\n * @param {function} modules.module\n *\n * @private\n */\n _decorate(modules) {\n Object.keys(modules).forEach((moduleName) => {\n this[moduleName] = new modules[moduleName].module(\n this,\n this._createRequest(moduleName)\n );\n });\n }\n}\n\nexport default ContxtSdk;\nexport { toSnakeCase, toCamelCase } from './utils/objects';\n"]}
1
+ {"version":3,"sources":["index.js"],"names":["sessionTypes","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","Config","auth","_createAuthSession","bus","Bus","_createRequest","coordinator","Coordinator","events","Events","files","Files","iot","Iot","nionic","Nionic","_decorate","moduleName","clientId","host","module","indexOf","Error","addDynamicAudience","clearCurrentApiToken","removeDynamicAudience","filter","name","TYPES","AUTH0_WEB_AUTH","Auth0WebAuth","PASSWORD_GRANT_AUTH","PasswordGrantAuth","MACHINE_AUTH","MachineAuth","audienceName","Request","modules","Object","keys","forEach","toSnakeCase","toCamelCase"],"mappings":";;;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;IAAYA,Y;;AACZ;;;;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgCMC,S;AACJ;;;;;;;AAOA,2BAAgE;AAAA,2BAAlDC,MAAkD;AAAA,QAAlDA,MAAkD,+BAAzC,EAAyC;AAAA,oCAArCC,eAAqC;AAAA,QAArCA,eAAqC,wCA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M,IAAIZ,KAAJ,CAAU,8BAAV,CAAN;AAXJ;AAaD;;AAED;;;;;;;;;;;;;mCAUea,Y,EAAc;AAC3B,aAAO,IAAIC,iBAAJ,CAAY,IAAZ,EAAkBD,YAAlB,CAAP;AACD;;AAED;;;;;;;;;;;8BAQUE,O,EAAS;AAAA;;AACjBC,aAAOC,IAAP,CAAYF,OAAZ,EAAqBG,OAArB,CAA6B,UAACvB,UAAD,EAAgB;AAC3C,cAAKA,UAAL,IAAmB,IAAIoB,QAAQpB,UAAR,EAAoBG,MAAxB,CACjB,KADiB,EAEjB,MAAKf,cAAL,CAAoBY,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;kBAGYvB,S;QACN+C,W,GAAAA,oB;QAAaC,W,GAAAA,oB","file":"index.js","sourcesContent":["import Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Files from './files';\nimport Iot from './iot';\nimport Nionic from './nionic';\nimport Request from './request';\nimport * as sessionTypes from './sessionTypes';\nimport { toSnakeCase, toCamelCase } from './utils/objects';\n\n/**\n * An adapter that allows the SDK to authenticate with different services and manage various tokens.\n * Can authenticate with a service like Auth0 and then with Contxt or can communicate directly\n * with Contxt. The adapter must implement required methods, but most methods are optional. Some of\n * the optional methods are documented below.\n *\n * @typedef {Object} SessionType\n * @property {function} [getCurrentAccessToken] Provides a current access token from Auth0 that is\n * used for profile information and can be used to get API token for Contxt itself\n * @property {function} getCurrentApiToken Provides a current API token that is used across\n * different Contxt services\n * @property {function} [getProfile] Provides profile information about the current user\n * @property {function} [handleAuthentication] Is called by front-end code in the Auth0 reference\n * implementation to handle getting the access token from Auth0\n * @property {function} [isAuthenticated] Tells caller if the current user is authenticated.\n * Different session types may determine if a user is authenticated in different ways.\n * @property {function} [logIn] Is used by front-end code in the Auth0 reference implementation to\n * start the sign in process\n * @property {function} [logOut] Is used by the front-end code in the Auth0 reference implementation\n * to sign the user out\n */\n\n/**\n * ContxtSdk constructor\n *\n * @example\n * import ContxtSdk from '@ndustrial/contxt-sdk';\n * import ExternalModule1 from './ExternalModule1';\n * import history from '../services/history';\n *\n * const contxtSdk = new ContxtSdk({\n * config: {\n * auth: {\n * clientId: 'Auth0 client id of the application being built',\n * customModuleConfigs: {\n * facilities: {\n * env: 'production'\n * }\n * },\n * env: 'staging',\n * onAuthenticate: (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo),\n * onRedirect: (pathname) => history.push(pathname)\n * }\n * },\n * externalModules: {\n * externalModule1: {\n * clientId: 'Auth0 client id of the external module',\n * host: 'https://www.example.com/externalModule1',\n * module: ExternalModule1\n * }\n * },\n * sessionType: 'auth0WebAuth'\n * });\n */\nclass ContxtSdk {\n /**\n * @param {UserConfig} config The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that\n * should be treated as first class citizens\n * @param {string} sessionType The type of auth session you wish to use (e.g. auth0WebAuth\n * or machine)\n */\n constructor({ config = {}, externalModules = {}, sessionType }) {\n this._dynamicModuleNames = [];\n this._replacedModules = {};\n\n this.config = new Config(config, externalModules);\n\n this.auth = this._createAuthSession(sessionType);\n this.bus = new Bus(this, this._createRequest('bus'));\n this.coordinator = new Coordinator(\n this,\n this._createRequest('coordinator')\n );\n this.events = new Events(this, this._createRequest('events'));\n this.files = new Files(this, this._createRequest('files'));\n this.iot = new Iot(this, this._createRequest('iot'));\n this.nionic = new Nionic(this, this._createRequest('nionic'));\n\n this._decorate(externalModules);\n }\n\n /**\n * Mounts a dynamic module into the SDK. Is used to add a module after initial\n * instatiation that will use the SDK's authentication and request methods to\n * access an ndustrial.io API\n *\n * @param {string} moduleName The name (or key) that will serve as the mount\n * point for the module in the SDK (i.e. customModule -> sdk.customModule)\n * @param {ExternalModule} externalModule\n */\n mountDynamicModule(moduleName, { clientId, host, module }) {\n if (this._dynamicModuleNames.indexOf(moduleName) > -1) {\n throw new Error(\n `An dynamic module of the name \\`${moduleName}\\` already exists. This problem can be rectified by using a different name for the new module.`\n );\n }\n\n this.config.addDynamicAudience(moduleName, { clientId, host });\n\n this._dynamicModuleNames = [...this._dynamicModuleNames, moduleName];\n\n if (this[moduleName]) {\n this._replacedModules[moduleName] = this[moduleName];\n }\n\n this[moduleName] = new module(this, this._createRequest(moduleName));\n }\n\n /**\n * Unmounts a dynamic module from the SDK\n *\n * @param {string} moduleName The name of the dynamic module to unmount\n */\n unmountDynamicModule(moduleName) {\n if (this._dynamicModuleNames.indexOf(moduleName) === -1) {\n throw new Error('There is no external module to unmount.');\n }\n\n this.auth.clearCurrentApiToken(moduleName);\n this.config.removeDynamicAudience(moduleName);\n\n this[moduleName] = this._replacedModules[moduleName];\n\n delete this._replacedModules[moduleName];\n this._dynamicModuleNames = this._dynamicModuleNames.filter(\n (name) => name !== moduleName\n );\n }\n\n /**\n * Returns a new instance of the session type requested\n *\n * @param {string} sessionType\n *\n * @returns {SessionType} sessionType\n * @throws {Error}\n *\n * @private\n */\n _createAuthSession(sessionType) {\n switch (sessionType) {\n case sessionTypes.TYPES.AUTH0_WEB_AUTH:\n return new sessionTypes.Auth0WebAuth(this);\n\n case sessionTypes.TYPES.PASSWORD_GRANT_AUTH:\n return new sessionTypes.PasswordGrantAuth(this);\n\n case sessionTypes.TYPES.MACHINE_AUTH:\n return new sessionTypes.MachineAuth(this);\n\n default:\n throw new Error('Invalid sessionType provided');\n }\n }\n\n /**\n * Returns an instance of the Request module that is tied to the requested audience\n *\n * @param {string} audienceName The audience name of the service you are trying to reach\n * (e.g. facilities or feeds)\n *\n * @returns {Object} Request module\n *\n * @private\n */\n _createRequest(audienceName) {\n return new Request(this, audienceName);\n }\n\n /**\n * Decorates custom modules onto the SDK instance so they behave as first-class citizens.\n *\n * @param {Object} modules\n * @param {function} modules.module\n *\n * @private\n */\n _decorate(modules) {\n Object.keys(modules).forEach((moduleName) => {\n this[moduleName] = new modules[moduleName].module(\n this,\n this._createRequest(moduleName)\n );\n });\n }\n}\n\nexport default ContxtSdk;\nexport { toSnakeCase, toCamelCase };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndustrial/contxt-sdk",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
package/src/index.js CHANGED
@@ -7,6 +7,7 @@ import Iot from './iot';
7
7
  import Nionic from './nionic';
8
8
  import Request from './request';
9
9
  import * as sessionTypes from './sessionTypes';
10
+ import { toSnakeCase, toCamelCase } from './utils/objects';
10
11
 
11
12
  /**
12
13
  * An adapter that allows the SDK to authenticate with different services and manage various tokens.
@@ -197,4 +198,4 @@ class ContxtSdk {
197
198
  }
198
199
 
199
200
  export default ContxtSdk;
200
- export { toSnakeCase, toCamelCase } from './utils/objects';
201
+ export { toSnakeCase, toCamelCase };