@ndustrial/contxt-sdk 4.3.6 → 5.1.0
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/.gitattributes +1 -0
- package/CHANGELOG.md +8 -0
- package/docs/Facilities.md +0 -144
- package/docs/FacilityGroupings.md +0 -160
- package/docs/Nionic.md +63 -0
- package/docs/README.md +3 -29
- package/docs/Typedefs.md +0 -101
- package/esm/config/audiences.js +13 -13
- package/esm/config/audiences.js.map +1 -1
- package/esm/index.js +3 -6
- package/esm/index.js.map +1 -1
- package/esm/nionic/index.js +126 -0
- package/esm/nionic/index.js.map +1 -0
- package/lib/config/audiences.js +13 -13
- package/lib/config/audiences.js.map +1 -1
- package/lib/index.js +19 -13
- package/lib/index.js.map +1 -1
- package/lib/nionic/index.js +130 -0
- package/lib/nionic/index.js.map +1 -0
- package/meta.yaml +11 -0
- package/package.json +9 -10
- package/src/bus/index.spec.js +3 -2
- package/src/bus/webSocketConnection.spec.js +31 -31
- package/src/config/audiences.js +13 -13
- package/src/config/index.spec.js +6 -6
- package/src/coordinator/applications.spec.js +8 -8
- package/src/coordinator/consent.spec.js +1 -1
- package/src/coordinator/edgeNodes.spec.js +3 -3
- package/src/coordinator/organizations.spec.js +4 -4
- package/src/coordinator/permissions.spec.js +4 -4
- package/src/coordinator/roles.spec.js +3 -3
- package/src/coordinator/users.spec.js +14 -15
- package/src/events/index.spec.js +16 -16
- package/src/files/index.spec.js +7 -7
- package/src/index.js +3 -6
- package/src/index.spec.js +8 -22
- package/src/iot/feeds.spec.js +4 -4
- package/src/iot/fieldCategories.spec.js +4 -4
- package/src/iot/fieldGroupings.spec.js +5 -5
- package/src/iot/outputs.spec.js +6 -6
- package/src/nionic/index.js +151 -0
- package/src/request.spec.js +3 -3
- package/src/sessionTypes/auth0WebAuth.spec.js +2 -2
- package/src/sessionTypes/index.spec.js +3 -3
- package/src/sessionTypes/machineAuth.spec.js +3 -3
- package/src/sessionTypes/passwordGrantAuth.spec.js +1 -1
- package/src/utils/iot/formatOutputFieldDataFromServer.spec.js +6 -6
- package/src/utils/iot/parseOutputFieldNextPageUrlMetadata.spec.js +2 -2
- package/src/utils/pagination/formatPaginatedDataFromServer.spec.js +2 -2
- package/src/utils/url/stringifyParams.spec.js +2 -3
- package/support/fixtures/factories/IOSDevice.js +3 -3
- package/support/fixtures/factories/applicationGrouping.js +4 -4
- package/support/fixtures/factories/applicationModule.js +2 -2
- package/support/fixtures/factories/asset.js +1 -1
- package/support/fixtures/factories/assetAttribute.js +2 -2
- package/support/fixtures/factories/assetAttributeValue.js +2 -2
- package/support/fixtures/factories/assetMetric.js +1 -1
- package/support/fixtures/factories/assetMetricValue.js +3 -3
- package/support/fixtures/factories/assetMetricValueCompact.js +2 -2
- package/support/fixtures/factories/assetType.js +1 -1
- package/support/fixtures/factories/authResults.js +3 -3
- package/support/fixtures/factories/channel.js +1 -1
- package/support/fixtures/factories/contxtApplication.js +5 -5
- package/support/fixtures/factories/contxtOrganization.js +2 -2
- package/support/fixtures/factories/contxtOrganizationFeaturedApplication.js +3 -3
- package/support/fixtures/factories/contxtProject.js +2 -2
- package/support/fixtures/factories/contxtProjectEnvironment.js +2 -2
- package/support/fixtures/factories/contxtRole.js +3 -3
- package/support/fixtures/factories/contxtRoleApplication.js +1 -1
- package/support/fixtures/factories/contxtRoleProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUser.js +2 -2
- package/support/fixtures/factories/contxtUserApplication.js +1 -1
- package/support/fixtures/factories/contxtUserFavoriteApplication.js +2 -2
- package/support/fixtures/factories/contxtUserPermissions.js +5 -5
- package/support/fixtures/factories/contxtUserProjectEnvironment.js +1 -1
- package/support/fixtures/factories/contxtUserRole.js +2 -2
- package/support/fixtures/factories/costCenter.js +2 -2
- package/support/fixtures/factories/costCenterFacility.js +3 -3
- package/support/fixtures/factories/edgeNode.js +1 -1
- package/support/fixtures/factories/event.js +5 -5
- package/support/fixtures/factories/eventType.js +4 -4
- package/support/fixtures/factories/eventUser.js +5 -5
- package/support/fixtures/factories/facility.js +4 -4
- package/support/fixtures/factories/facilityGrouping.js +3 -3
- package/support/fixtures/factories/facilityGroupingFacility.js +3 -3
- package/support/fixtures/factories/facilityInfo.js +2 -2
- package/support/fixtures/factories/facilityTag.js +1 -1
- package/support/fixtures/factories/feedStatus.js +1 -1
- package/support/fixtures/factories/feedType.js +1 -1
- package/support/fixtures/factories/feeds.js +5 -5
- package/support/fixtures/factories/fieldCategory.js +3 -3
- package/support/fixtures/factories/fieldGrouping.js +4 -4
- package/support/fixtures/factories/fieldGroupingField.js +3 -3
- package/support/fixtures/factories/fieldGroupingStatus.js +1 -1
- package/support/fixtures/factories/file.js +1 -1
- package/support/fixtures/factories/fileUploadInfo.js +1 -1
- package/support/fixtures/factories/organization.js +1 -1
- package/support/fixtures/factories/outputField.js +10 -10
- package/support/fixtures/factories/outputFieldData.js +1 -1
- package/support/fixtures/factories/owner.js +2 -2
- package/support/fixtures/factories/paginationMetadata.js +2 -2
- package/support/fixtures/factories/triggeredEvent.js +4 -4
- package/support/fixtures/factories/userEventSubscription.js +1 -1
- package/support/fixtures/factories/userMobileNumber.js +1 -1
- package/support/fixtures/factories/userPermissionsMap.js +2 -2
- package/.huskyrc.js +0 -11
- package/.nycrc +0 -12
- package/esm/assets/assetAttributes.js +0 -574
- package/esm/assets/assetAttributes.js.map +0 -1
- package/esm/assets/assetMetrics.js +0 -690
- package/esm/assets/assetMetrics.js.map +0 -1
- package/esm/assets/assetTypes.js +0 -273
- package/esm/assets/assetTypes.js.map +0 -1
- package/esm/assets/index.js +0 -283
- package/esm/assets/index.js.map +0 -1
- package/esm/facilities/costCenters.js +0 -306
- package/esm/facilities/costCenters.js.map +0 -1
- package/esm/facilities/groupings.js +0 -323
- package/esm/facilities/groupings.js.map +0 -1
- package/esm/facilities/index.js +0 -343
- package/esm/facilities/index.js.map +0 -1
- package/esm/health/index.js +0 -229
- package/esm/health/index.js.map +0 -1
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js +0 -65
- package/esm/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/esm/utils/facilities/index.js +0 -4
- package/esm/utils/facilities/index.js.map +0 -1
- package/lib/assets/assetAttributes.js +0 -588
- package/lib/assets/assetAttributes.js.map +0 -1
- package/lib/assets/assetMetrics.js +0 -705
- package/lib/assets/assetMetrics.js.map +0 -1
- package/lib/assets/assetTypes.js +0 -287
- package/lib/assets/assetTypes.js.map +0 -1
- package/lib/assets/index.js +0 -302
- package/lib/assets/index.js.map +0 -1
- package/lib/facilities/costCenters.js +0 -316
- package/lib/facilities/costCenters.js.map +0 -1
- package/lib/facilities/groupings.js +0 -333
- package/lib/facilities/groupings.js.map +0 -1
- package/lib/facilities/index.js +0 -360
- package/lib/facilities/index.js.map +0 -1
- package/lib/health/index.js +0 -232
- package/lib/health/index.js.map +0 -1
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js +0 -71
- package/lib/utils/facilities/formatFacilityWithInfoFromServer.js.map +0 -1
- package/lib/utils/facilities/index.js +0 -15
- package/lib/utils/facilities/index.js.map +0 -1
- package/src/assets/assetAttributes.js +0 -619
- package/src/assets/assetAttributes.spec.js +0 -1143
- package/src/assets/assetMetrics.js +0 -736
- package/src/assets/assetMetrics.spec.js +0 -1180
- package/src/assets/assetTypes.js +0 -260
- package/src/assets/assetTypes.spec.js +0 -556
- package/src/assets/index.js +0 -271
- package/src/assets/index.spec.js +0 -515
- package/src/facilities/costCenters.js +0 -295
- package/src/facilities/costCenters.spec.js +0 -529
- package/src/facilities/groupings.js +0 -320
- package/src/facilities/groupings.spec.js +0 -567
- package/src/facilities/index.js +0 -343
- package/src/facilities/index.spec.js +0 -551
- package/src/health/index.js +0 -200
- package/src/health/index.spec.js +0 -501
- package/src/utils/facilities/formatFacilityWithInfoFromServer.js +0 -62
- package/src/utils/facilities/formatFacilityWithInfoFromServer.spec.js +0 -73
- package/src/utils/facilities/index.js +0 -3
package/esm/config/audiences.js
CHANGED
|
@@ -17,8 +17,8 @@ export default {
|
|
|
17
17
|
host: 'https://contxtauth.com'
|
|
18
18
|
},
|
|
19
19
|
staging: {
|
|
20
|
-
clientId: '
|
|
21
|
-
host: 'https://contxt-auth-staging.
|
|
20
|
+
clientId: '7TceUsM1eC4nKmdoC717383DWyfc9QoY',
|
|
21
|
+
host: 'https://contxt-auth-service.staging.ndustrial.io'
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
coordinator: {
|
|
@@ -28,7 +28,7 @@ export default {
|
|
|
28
28
|
},
|
|
29
29
|
staging: {
|
|
30
30
|
clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',
|
|
31
|
-
host: 'https://contxt
|
|
31
|
+
host: 'https://contxt.api.staging.ndustrial.io'
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
events: {
|
|
@@ -61,16 +61,6 @@ export default {
|
|
|
61
61
|
host: 'https://files.api.staging.ndustrial.io'
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
health: {
|
|
65
|
-
staging: {
|
|
66
|
-
clientId: '1zQ2YXbHXotrf2dDKgySqEjlJBz465qq',
|
|
67
|
-
host: 'https://health-staging.api.ndustrial.io'
|
|
68
|
-
},
|
|
69
|
-
production: {
|
|
70
|
-
clientId: '6uaQIV1KnnWhXiTm09iGDvy2aQaz2xVI',
|
|
71
|
-
host: 'https://health.api.ndustrial.io'
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
64
|
iot: {
|
|
75
65
|
staging: {
|
|
76
66
|
clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES',
|
|
@@ -80,6 +70,16 @@ export default {
|
|
|
80
70
|
clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA',
|
|
81
71
|
host: 'https://feeds.api.ndustrial.io'
|
|
82
72
|
}
|
|
73
|
+
},
|
|
74
|
+
nionic: {
|
|
75
|
+
staging: {
|
|
76
|
+
clientId: 'vhGxildn8hRRWZj49y18BGtbjTkFHcTG',
|
|
77
|
+
host: 'https://<tenant>.api.staging.ndustrial.io'
|
|
78
|
+
},
|
|
79
|
+
production: {
|
|
80
|
+
clientId: 'vtiZlMRo4apDvThTRiH7kLifQXWUdi9j',
|
|
81
|
+
host: 'https://<tenant>.api.ndustrial.io'
|
|
82
|
+
}
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
//# sourceMappingURL=audiences.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","
|
|
1
|
+
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","iot","nionic"],"mappings":"AAAA,eAAe;AACbA,OAAK;AACHC,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM,0BAFI;AAGVC,iBAAW;AAHD,KADT;AAMHC,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM,kCAFC;AAGPC,iBAAW;AAHJ;AANN,GADQ;AAabE,cAAY;AACVL,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADF;AAKVE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALC,GAbC;AAuBbI,eAAa;AACXN,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADD;AAKXE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALE,GAvBA;AAiCbK,UAAQ;AACNH,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GAjCK;AA2CbM,cAAY;AACVR,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADF;AAKVE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALC,GA3CC;AAqDbO,SAAO;AACLT,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADP;AAKLE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALJ,GArDM;AA+DbQ,OAAK;AACHN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT,GA/DQ;AAyEbS,UAAQ;AACNP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN;AAzEK,CAAf","file":"audiences.js","sourcesContent":["export default {\n bus: {\n production: {\n clientId: 'bmoJ2jhfyIP5s4IZx5Ss6xQ9lmkoDixO',\n host: 'https://bus.ndustrial.io',\n webSocket: 'wss://bus.ndustrial.io'\n },\n staging: {\n clientId: '1HD1NG1VTBtkqRt2HRRj3E3hdmqmwzoz',\n host: 'https://bus-staging.ndustrial.io',\n webSocket: 'wss://bus-staging.ndustrial.io'\n }\n },\n contxtAuth: {\n production: {\n clientId: '75wT048QcpE7ujwBJPPjr263eTHl4gEX',\n host: 'https://contxtauth.com'\n },\n staging: {\n clientId: '7TceUsM1eC4nKmdoC717383DWyfc9QoY',\n host: 'https://contxt-auth-service.staging.ndustrial.io'\n }\n },\n coordinator: {\n production: {\n clientId: '8qY2xJob1JAxhmVhIDLCNnGriTM9bct8',\n host: 'https://contxt.api.ndustrial.io'\n },\n staging: {\n clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',\n host: 'https://contxt.api.staging.ndustrial.io'\n }\n },\n events: {\n staging: {\n clientId: 'dn4MaocJFdKtsBy9sFFaTeuJWL1nt5xu',\n host: 'https://events.api.staging.ndustrial.io'\n },\n production: {\n clientId: '7jzwfE20O2XZ4aq3cO1wmk63G9GzNc8j',\n host: 'https://events.api.ndustrial.io'\n }\n },\n facilities: {\n production: {\n clientId: 'SgbCopArnGMa9PsRlCVUCVRwxocntlg0',\n host: 'https://facilities.api.ndustrial.io'\n },\n staging: {\n clientId: 'xG775XHIOZVUn84seNeHXi0Qe55YuR5w',\n host: 'https://facilities-staging.api.ndustrial.io'\n }\n },\n files: {\n production: {\n clientId: 'VZJ2MRd71dM9oX2hB1EVAEjUe6loL7pl',\n host: 'https://files.api.ndustrial.io'\n },\n staging: {\n clientId: 'SLE310LY4nDT5p06sUGPVOLlGXk5osbQ',\n host: 'https://files.api.staging.ndustrial.io'\n }\n },\n iot: {\n staging: {\n clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES',\n host: 'https://feeds-staging.api.ndustrial.io'\n },\n production: {\n clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA',\n host: 'https://feeds.api.ndustrial.io'\n }\n },\n nionic: {\n staging: {\n clientId: 'vhGxildn8hRRWZj49y18BGtbjTkFHcTG',\n host: 'https://<tenant>.api.staging.ndustrial.io'\n },\n production: {\n clientId: 'vtiZlMRo4apDvThTRiH7kLifQXWUdi9j',\n host: 'https://<tenant>.api.ndustrial.io'\n }\n }\n};\n"]}
|
package/esm/index.js
CHANGED
|
@@ -4,15 +4,13 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
|
|
|
4
4
|
|
|
5
5
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
6
6
|
|
|
7
|
-
import Assets from './assets';
|
|
8
7
|
import Bus from './bus';
|
|
9
8
|
import Config from './config';
|
|
10
9
|
import Coordinator from './coordinator';
|
|
11
10
|
import Events from './events';
|
|
12
|
-
import Facilities from './facilities';
|
|
13
11
|
import Files from './files';
|
|
14
|
-
import Health from './health';
|
|
15
12
|
import Iot from './iot';
|
|
13
|
+
import Nionic from './nionic';
|
|
16
14
|
import Request from './request';
|
|
17
15
|
import * as sessionTypes from './sessionTypes';
|
|
18
16
|
|
|
@@ -93,15 +91,13 @@ var ContxtSdk = function () {
|
|
|
93
91
|
|
|
94
92
|
this.config = new Config(config, externalModules);
|
|
95
93
|
|
|
96
|
-
this.assets = new Assets(this, this._createRequest('facilities'));
|
|
97
94
|
this.auth = this._createAuthSession(sessionType);
|
|
98
95
|
this.bus = new Bus(this, this._createRequest('bus'));
|
|
99
96
|
this.coordinator = new Coordinator(this, this._createRequest('coordinator'));
|
|
100
97
|
this.events = new Events(this, this._createRequest('events'));
|
|
101
|
-
this.facilities = new Facilities(this, this._createRequest('facilities'));
|
|
102
98
|
this.files = new Files(this, this._createRequest('files'));
|
|
103
|
-
this.health = new Health(this, this._createRequest('health'));
|
|
104
99
|
this.iot = new Iot(this, this._createRequest('iot'));
|
|
100
|
+
this.nionic = new Nionic(this, this._createRequest('nionic'));
|
|
105
101
|
|
|
106
102
|
this._decorate(externalModules);
|
|
107
103
|
}
|
|
@@ -233,4 +229,5 @@ var ContxtSdk = function () {
|
|
|
233
229
|
}();
|
|
234
230
|
|
|
235
231
|
export default ContxtSdk;
|
|
232
|
+
export { toSnakeCase, toCamelCase } from './utils/objects';
|
|
236
233
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"names":["Assets","Bus","Config","Coordinator","Events","Facilities","Files","Health","Iot","Request","sessionTypes","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","assets","_createRequest","auth","_createAuthSession","bus","coordinator","events","facilities","files","health","iot","_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,MAAP,MAAmB,UAAnB;AACA,OAAOC,GAAP,MAAgB,OAAhB;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA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,CAAkCR,UAAlC;;AAEA,WAAKA,UAAL,IAAmB,KAAKb,gBAAL,CAAsBa,UAAtB,CAAnB;;AAEA,aAAO,KAAKb,gBAAL,CAAsBa,UAAtB,CAAP;AACA,WAAKd,mBAAL,GAA2B,KAAKA,mBAAL,CAAyBuB,MAAzB,CACzB,UAACC,IAAD;AAAA,eAAUA,SAASV,UAAnB;AAAA,OADyB,CAA3B;AAGD;;AAED;;;;;;;;;;;;;uCAUmBf,W,EAAa;AAC9B,cAAQA,WAAR;AACE,aAAKJ,aAAa8B,KAAb,CAAmBC,cAAxB;AACE,iBAAO,IAAI/B,aAAagC,YAAjB,CAA8B,IAA9B,CAAP;;AAEF,aAAKhC,aAAa8B,KAAb,CAAmBG,mBAAxB;AACE,iBAAO,IAAIjC,aAAakC,iBAAjB,CAAmC,IAAnC,CAAP;;AAEF,aAAKlC,aAAa8B,KAAb,CAAmBK,YAAxB;AACE,iBAAO,IAAInC,aAAaoC,WAAjB,CAA6B,IAA7B,CAAP;;AAEF;AACE,gBAAM,IAAIZ,KAAJ,CAAU,8BAAV,CAAN;AAXJ;AAaD;;AAED;;;;;;;;;;;;;mCAUea,Y,EAAc;AAC3B,aAAO,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,MAAKd,cAAL,CAAoBW,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;AAGH,eAAelB,SAAf","file":"index.js","sourcesContent":["import Assets from './assets';\nimport Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Facilities from './facilities';\nimport Files from './files';\nimport Health from './health';\nimport Iot from './iot';\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.assets = new Assets(this, this._createRequest('facilities'));\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.facilities = new Facilities(this, this._createRequest('facilities'));\n this.files = new Files(this, this._createRequest('files'));\n this.health = new Health(this, this._createRequest('health'));\n this.iot = new Iot(this, this._createRequest('iot'));\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;\n"]}
|
|
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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AACE,aAAKJ,aAAa4B,KAAb,CAAmBC,cAAxB;AACE,iBAAO,IAAI7B,aAAa8B,YAAjB,CAA8B,IAA9B,CAAP;;AAEF,aAAK9B,aAAa4B,KAAb,CAAmBG,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"]}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
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; }; }();
|
|
2
|
+
|
|
3
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Module that provides access to Nionic platform.
|
|
7
|
+
*
|
|
8
|
+
* @typicalname contxtSdk.nionic
|
|
9
|
+
*/
|
|
10
|
+
var Nionic = function () {
|
|
11
|
+
/**
|
|
12
|
+
* @param {Object} sdk An instance of the SDK so the module can communicate with other modules.
|
|
13
|
+
* @param {Object} request An instance of the request module tied to this module's audience.
|
|
14
|
+
*/
|
|
15
|
+
function Nionic(sdk, request) {
|
|
16
|
+
_classCallCheck(this, Nionic);
|
|
17
|
+
|
|
18
|
+
this._baseUrl = '' + sdk.config.audiences.nionic.host;
|
|
19
|
+
this._request = request;
|
|
20
|
+
this._sdk = sdk;
|
|
21
|
+
|
|
22
|
+
// Backwards compatibility for legacy uuid's
|
|
23
|
+
this._orgIdToTenantId = {
|
|
24
|
+
'18d8b68e-3e59-418e-9f23-47b7cd6bdd6b': 'genan',
|
|
25
|
+
'02efa741-a96f-4124-a463-ae13a704b8fc': 'lineage',
|
|
26
|
+
'5209751f-ea46-4b3e-a5dd-b8d03311b791': 'ndustrial',
|
|
27
|
+
'2fe29680-fc3d-4888-9e9b-44be1e59c22c': 'sfnt',
|
|
28
|
+
'b2c6705d-1727-467f-a450-207f110c9966': 'trenton'
|
|
29
|
+
};
|
|
30
|
+
this._tenants = new Set(Object.values(this._orgIdToTenantId));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_createClass(Nionic, [{
|
|
34
|
+
key: '_getTenantId',
|
|
35
|
+
value: function _getTenantId(orgOrTenantId) {
|
|
36
|
+
if (!orgOrTenantId) throw Error('Tenant is required');
|
|
37
|
+
if (!(orgOrTenantId in this._orgIdToTenantId) && !this._tenants.has(orgOrTenantId)) {
|
|
38
|
+
throw Error('Tenant is either unrecognized or not yet supported: ' + orgOrTenantId);
|
|
39
|
+
}
|
|
40
|
+
return this._orgIdToTenantId[orgOrTenantId] || orgOrTenantId;
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
43
|
+
key: '_query',
|
|
44
|
+
value: function _query(orgOrTenantId, options) {
|
|
45
|
+
var tenantId = this._getTenantId(orgOrTenantId);
|
|
46
|
+
var url = this._baseUrl.replace('<tenant>', tenantId) + '/graphql';
|
|
47
|
+
return this._request.post(url, options).then(function (resp) {
|
|
48
|
+
if (resp.data && resp.data.errors) {
|
|
49
|
+
return Promise.reject(Error(resp.data.errors));
|
|
50
|
+
}
|
|
51
|
+
return Promise.resolve(resp.data);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}, {
|
|
55
|
+
key: 'executeQuery',
|
|
56
|
+
value: function executeQuery(orgOrTenantId, query) {
|
|
57
|
+
var variables = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
58
|
+
|
|
59
|
+
return this._query(orgOrTenantId, { query: query, variables: variables });
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: 'getAllFacilities',
|
|
63
|
+
value: function getAllFacilities(orgOrTenantId) {
|
|
64
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Nionic.queryDefaults;
|
|
65
|
+
var additionalFields = options.additionalFields;
|
|
66
|
+
|
|
67
|
+
return this._query(orgOrTenantId, {
|
|
68
|
+
query: '\n query {\n facilities {\n nodes {\n id\n name\n slug\n address\n city\n state\n zip\n timezone: timezoneName\n createdAt\n updatedAt\n ' + additionalFields.join('\n') + '\n }\n }\n }\n '
|
|
69
|
+
}).then(function (data) {
|
|
70
|
+
return data.facilities.nodes;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}, {
|
|
74
|
+
key: 'getFacility',
|
|
75
|
+
value: function getFacility(orgOrTenantId, facilityId) {
|
|
76
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Nionic.queryDefaults;
|
|
77
|
+
var additionalFields = options.additionalFields;
|
|
78
|
+
|
|
79
|
+
return this._query(orgOrTenantId, {
|
|
80
|
+
query: '\n query($facilityId: Int!) {\n facility(id: $facilityId) {\n id\n name\n slug\n address\n city\n state\n zip\n timezone: timezoneName\n createdAt\n updatedAt\n ' + additionalFields.join('\n') + '\n }\n }\n ',
|
|
81
|
+
variables: { facilityId: parseInt(facilityId) }
|
|
82
|
+
}).then(function (resp) {
|
|
83
|
+
return resp.facility;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: 'getFacilityMetricLabels',
|
|
88
|
+
value: function getFacilityMetricLabels(orgOrTenantId, _ref) {
|
|
89
|
+
var facilityId = _ref.facilityId;
|
|
90
|
+
|
|
91
|
+
return this._query(orgOrTenantId, {
|
|
92
|
+
query: '\n query($facilityId: Int!) {\n facility(id: $facilityId) {\n metricLabels {\n sourceId\n label\n }\n }\n }\n ',
|
|
93
|
+
variables: { facilityId: parseInt(facilityId) }
|
|
94
|
+
}).then(function (resp) {
|
|
95
|
+
return resp.facility.metricLabels;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: 'getFacilityMetrics',
|
|
100
|
+
value: function getFacilityMetrics(orgOrTenantId, _ref2) {
|
|
101
|
+
var facilityId = _ref2.facilityId,
|
|
102
|
+
metricLabel = _ref2.metricLabel,
|
|
103
|
+
_ref2$mutableOnly = _ref2.mutableOnly,
|
|
104
|
+
mutableOnly = _ref2$mutableOnly === undefined ? false : _ref2$mutableOnly;
|
|
105
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Nionic.queryDefaults;
|
|
106
|
+
var additionalFields = options.additionalFields;
|
|
107
|
+
|
|
108
|
+
return this._query(orgOrTenantId, {
|
|
109
|
+
query: '\n query($facilityId: Int!, $metricLabel: String!, $mutableOnly: Boolean) {\n facility(id: $facilityId) {\n metricData(label: $metricLabel, mutableOnly: $mutableOnly) {\n nodes {\n time\n sourceId\n label\n data\n ' + additionalFields.join('\n') + '\n }\n }\n }\n }\n ',
|
|
110
|
+
variables: { facilityId: parseInt(facilityId), metricLabel: metricLabel, mutableOnly: mutableOnly }
|
|
111
|
+
}).then(function (resp) {
|
|
112
|
+
return resp.facility.metricData.nodes;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}]);
|
|
116
|
+
|
|
117
|
+
return Nionic;
|
|
118
|
+
}();
|
|
119
|
+
|
|
120
|
+
Nionic.queryDefaults = {
|
|
121
|
+
additionalFields: []
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
export default Nionic;
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["nionic/index.js"],"names":["Nionic","sdk","request","_baseUrl","config","audiences","nionic","host","_request","_sdk","_orgIdToTenantId","_tenants","Set","Object","values","orgOrTenantId","Error","has","options","tenantId","_getTenantId","url","replace","post","then","resp","data","errors","Promise","reject","resolve","query","variables","_query","queryDefaults","additionalFields","join","facilities","nodes","facilityId","parseInt","facility","metricLabels","metricLabel","mutableOnly","metricData"],"mappings":";;;;AAAA;;;;;IAKMA,M;AACJ;;;;AAIA,kBAAYC,GAAZ,EAAiBC,OAAjB,EAA0B;AAAA;;AACxB,SAAKC,QAAL,QAAmBF,IAAIG,MAAJ,CAAWC,SAAX,CAAqBC,MAArB,CAA4BC,IAA/C;AACA,SAAKC,QAAL,GAAgBN,OAAhB;AACA,SAAKO,IAAL,GAAYR,GAAZ;;AAEA;AACA,SAAKS,gBAAL,GAAwB;AACtB,8CAAwC,OADlB;AAEtB,8CAAwC,SAFlB;AAGtB,8CAAwC,WAHlB;AAItB,8CAAwC,MAJlB;AAKtB,8CAAwC;AALlB,KAAxB;AAOA,SAAKC,QAAL,GAAgB,IAAIC,GAAJ,CAAQC,OAAOC,MAAP,CAAc,KAAKJ,gBAAnB,CAAR,CAAhB;AACD;;;;iCAMYK,a,EAAe;AAC1B,UAAI,CAACA,aAAL,EAAoB,MAAMC,MAAM,oBAAN,CAAN;AACpB,UACE,EAAED,iBAAiB,KAAKL,gBAAxB,KACA,CAAC,KAAKC,QAAL,CAAcM,GAAd,CAAkBF,aAAlB,CAFH,EAGE;AACA,cAAMC,+DACmDD,aADnD,CAAN;AAGD;AACD,aAAO,KAAKL,gBAAL,CAAsBK,aAAtB,KAAwCA,aAA/C;AACD;;;2BAEMA,a,EAAeG,O,EAAS;AAC7B,UAAMC,WAAW,KAAKC,YAAL,CAAkBL,aAAlB,CAAjB;AACA,UAAMM,MAAS,KAAKlB,QAAL,CAAcmB,OAAd,CAAsB,UAAtB,EAAkCH,QAAlC,CAAT,aAAN;AACA,aAAO,KAAKX,QAAL,CAAce,IAAd,CAAmBF,GAAnB,EAAwBH,OAAxB,EAAiCM,IAAjC,CAAsC,UAACC,IAAD,EAAU;AACrD,YAAIA,KAAKC,IAAL,IAAaD,KAAKC,IAAL,CAAUC,MAA3B,EAAmC;AACjC,iBAAOC,QAAQC,MAAR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I,CAYC,UAACC,IAAD;AAAA,eAAUA,KAAKgB,QAAL,CAAcC,YAAxB;AAAA,OAZD,CAAP;AAaD;;;uCAGC3B,a,SAGA;AAAA,UAFEwB,UAEF,SAFEA,UAEF;AAAA,UAFcI,WAEd,SAFcA,WAEd;AAAA,oCAF2BC,WAE3B;AAAA,UAF2BA,WAE3B,qCAFyC,KAEzC;AAAA,UADA1B,OACA,uEADUlB,OAAOkC,aACjB;AAAA,UACQC,gBADR,GAC6BjB,OAD7B,CACQiB,gBADR;;AAEA,aAAO,KAAKF,MAAL,CAAYlB,aAAZ,EAA2B;AAChCgB,6VASYI,iBAAiBC,IAAjB,CAAsB,IAAtB,CATZ,qEADgC;AAgBhCJ,mBAAW,EAAEO,YAAYC,SAASD,UAAT,CAAd,EAAoCI,wBAApC,EAAiDC,wBAAjD;AAhBqB,OAA3B,EAiBJpB,IAjBI,CAiBC,UAACC,IAAD;AAAA,eAAUA,KAAKgB,QAAL,CAAcI,UAAd,CAAyBP,KAAnC;AAAA,OAjBD,CAAP;AAkBD;;;;;;AA9IGtC,M,CAqBGkC,a,GAAgB;AACrBC,oBAAkB;AADG,C;;;AA4HzB,eAAenC,MAAf","file":"index.js","sourcesContent":["/**\n * Module that provides access to Nionic platform.\n *\n * @typicalname contxtSdk.nionic\n */\nclass Nionic {\n /**\n * @param {Object} sdk An instance of the SDK so the module can communicate with other modules.\n * @param {Object} request An instance of the request module tied to this module's audience.\n */\n constructor(sdk, request) {\n this._baseUrl = `${sdk.config.audiences.nionic.host}`;\n this._request = request;\n this._sdk = sdk;\n\n // Backwards compatibility for legacy uuid's\n this._orgIdToTenantId = {\n '18d8b68e-3e59-418e-9f23-47b7cd6bdd6b': 'genan',\n '02efa741-a96f-4124-a463-ae13a704b8fc': 'lineage',\n '5209751f-ea46-4b3e-a5dd-b8d03311b791': 'ndustrial',\n '2fe29680-fc3d-4888-9e9b-44be1e59c22c': 'sfnt',\n 'b2c6705d-1727-467f-a450-207f110c9966': 'trenton'\n };\n this._tenants = new Set(Object.values(this._orgIdToTenantId));\n }\n\n static queryDefaults = {\n additionalFields: []\n };\n\n _getTenantId(orgOrTenantId) {\n if (!orgOrTenantId) throw Error('Tenant is required');\n if (\n !(orgOrTenantId in this._orgIdToTenantId) &&\n !this._tenants.has(orgOrTenantId)\n ) {\n throw Error(\n `Tenant is either unrecognized or not yet supported: ${orgOrTenantId}`\n );\n }\n return this._orgIdToTenantId[orgOrTenantId] || orgOrTenantId;\n }\n\n _query(orgOrTenantId, options) {\n const tenantId = this._getTenantId(orgOrTenantId);\n const url = `${this._baseUrl.replace('<tenant>', tenantId)}/graphql`;\n return this._request.post(url, options).then((resp) => {\n if (resp.data && resp.data.errors) {\n return Promise.reject(Error(resp.data.errors));\n }\n return Promise.resolve(resp.data);\n });\n }\n\n executeQuery(orgOrTenantId, query, variables = {}) {\n return this._query(orgOrTenantId, { query, variables });\n }\n\n getAllFacilities(orgOrTenantId, options = Nionic.queryDefaults) {\n const { additionalFields } = options;\n return this._query(orgOrTenantId, {\n query: `\n query {\n facilities {\n nodes {\n id\n name\n slug\n address\n city\n state\n zip\n timezone: timezoneName\n createdAt\n updatedAt\n ${additionalFields.join('\\n')}\n }\n }\n }\n `\n }).then((data) => data.facilities.nodes);\n }\n\n getFacility(orgOrTenantId, facilityId, options = Nionic.queryDefaults) {\n const { additionalFields } = options;\n return this._query(orgOrTenantId, {\n query: `\n query($facilityId: Int!) {\n facility(id: $facilityId) {\n id\n name\n slug\n address\n city\n state\n zip\n timezone: timezoneName\n createdAt\n updatedAt\n ${additionalFields.join('\\n')}\n }\n }\n `,\n variables: { facilityId: parseInt(facilityId) }\n }).then((resp) => resp.facility);\n }\n\n getFacilityMetricLabels(orgOrTenantId, { facilityId }) {\n return this._query(orgOrTenantId, {\n query: `\n query($facilityId: Int!) {\n facility(id: $facilityId) {\n metricLabels {\n sourceId\n label\n }\n }\n }\n `,\n variables: { facilityId: parseInt(facilityId) }\n }).then((resp) => resp.facility.metricLabels);\n }\n\n getFacilityMetrics(\n orgOrTenantId,\n { facilityId, metricLabel, mutableOnly = false },\n options = Nionic.queryDefaults\n ) {\n const { additionalFields } = options;\n return this._query(orgOrTenantId, {\n query: `\n query($facilityId: Int!, $metricLabel: String!, $mutableOnly: Boolean) {\n facility(id: $facilityId) {\n metricData(label: $metricLabel, mutableOnly: $mutableOnly) {\n nodes {\n time\n sourceId\n label\n data\n ${additionalFields.join('\\n')}\n }\n }\n }\n }\n `,\n variables: { facilityId: parseInt(facilityId), metricLabel, mutableOnly }\n }).then((resp) => resp.facility.metricData.nodes);\n }\n}\n\nexport default Nionic;\n"]}
|
package/lib/config/audiences.js
CHANGED
|
@@ -22,8 +22,8 @@ exports.default = {
|
|
|
22
22
|
host: 'https://contxtauth.com'
|
|
23
23
|
},
|
|
24
24
|
staging: {
|
|
25
|
-
clientId: '
|
|
26
|
-
host: 'https://contxt-auth-staging.
|
|
25
|
+
clientId: '7TceUsM1eC4nKmdoC717383DWyfc9QoY',
|
|
26
|
+
host: 'https://contxt-auth-service.staging.ndustrial.io'
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
coordinator: {
|
|
@@ -33,7 +33,7 @@ exports.default = {
|
|
|
33
33
|
},
|
|
34
34
|
staging: {
|
|
35
35
|
clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',
|
|
36
|
-
host: 'https://contxt
|
|
36
|
+
host: 'https://contxt.api.staging.ndustrial.io'
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
events: {
|
|
@@ -66,16 +66,6 @@ exports.default = {
|
|
|
66
66
|
host: 'https://files.api.staging.ndustrial.io'
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
-
health: {
|
|
70
|
-
staging: {
|
|
71
|
-
clientId: '1zQ2YXbHXotrf2dDKgySqEjlJBz465qq',
|
|
72
|
-
host: 'https://health-staging.api.ndustrial.io'
|
|
73
|
-
},
|
|
74
|
-
production: {
|
|
75
|
-
clientId: '6uaQIV1KnnWhXiTm09iGDvy2aQaz2xVI',
|
|
76
|
-
host: 'https://health.api.ndustrial.io'
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
69
|
iot: {
|
|
80
70
|
staging: {
|
|
81
71
|
clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES',
|
|
@@ -85,6 +75,16 @@ exports.default = {
|
|
|
85
75
|
clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA',
|
|
86
76
|
host: 'https://feeds.api.ndustrial.io'
|
|
87
77
|
}
|
|
78
|
+
},
|
|
79
|
+
nionic: {
|
|
80
|
+
staging: {
|
|
81
|
+
clientId: 'vhGxildn8hRRWZj49y18BGtbjTkFHcTG',
|
|
82
|
+
host: 'https://<tenant>.api.staging.ndustrial.io'
|
|
83
|
+
},
|
|
84
|
+
production: {
|
|
85
|
+
clientId: 'vtiZlMRo4apDvThTRiH7kLifQXWUdi9j',
|
|
86
|
+
host: 'https://<tenant>.api.ndustrial.io'
|
|
87
|
+
}
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
//# sourceMappingURL=audiences.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","
|
|
1
|
+
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","iot","nionic"],"mappings":";;;;;kBAAe;AACbA,OAAK;AACHC,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM,0BAFI;AAGVC,iBAAW;AAHD,KADT;AAMHC,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM,kCAFC;AAGPC,iBAAW;AAHJ;AANN,GADQ;AAabE,cAAY;AACVL,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADF;AAKVE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALC,GAbC;AAuBbI,eAAa;AACXN,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADD;AAKXE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALE,GAvBA;AAiCbK,UAAQ;AACNH,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GAjCK;AA2CbM,cAAY;AACVR,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADF;AAKVE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALC,GA3CC;AAqDbO,SAAO;AACLT,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI,KADP;AAKLE,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC;AALJ,GArDM;AA+DbQ,OAAK;AACHN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT,GA/DQ;AAyEbS,UAAQ;AACNP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN;AAzEK,C","file":"audiences.js","sourcesContent":["export default {\n bus: {\n production: {\n clientId: 'bmoJ2jhfyIP5s4IZx5Ss6xQ9lmkoDixO',\n host: 'https://bus.ndustrial.io',\n webSocket: 'wss://bus.ndustrial.io'\n },\n staging: {\n clientId: '1HD1NG1VTBtkqRt2HRRj3E3hdmqmwzoz',\n host: 'https://bus-staging.ndustrial.io',\n webSocket: 'wss://bus-staging.ndustrial.io'\n }\n },\n contxtAuth: {\n production: {\n clientId: '75wT048QcpE7ujwBJPPjr263eTHl4gEX',\n host: 'https://contxtauth.com'\n },\n staging: {\n clientId: '7TceUsM1eC4nKmdoC717383DWyfc9QoY',\n host: 'https://contxt-auth-service.staging.ndustrial.io'\n }\n },\n coordinator: {\n production: {\n clientId: '8qY2xJob1JAxhmVhIDLCNnGriTM9bct8',\n host: 'https://contxt.api.ndustrial.io'\n },\n staging: {\n clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',\n host: 'https://contxt.api.staging.ndustrial.io'\n }\n },\n events: {\n staging: {\n clientId: 'dn4MaocJFdKtsBy9sFFaTeuJWL1nt5xu',\n host: 'https://events.api.staging.ndustrial.io'\n },\n production: {\n clientId: '7jzwfE20O2XZ4aq3cO1wmk63G9GzNc8j',\n host: 'https://events.api.ndustrial.io'\n }\n },\n facilities: {\n production: {\n clientId: 'SgbCopArnGMa9PsRlCVUCVRwxocntlg0',\n host: 'https://facilities.api.ndustrial.io'\n },\n staging: {\n clientId: 'xG775XHIOZVUn84seNeHXi0Qe55YuR5w',\n host: 'https://facilities-staging.api.ndustrial.io'\n }\n },\n files: {\n production: {\n clientId: 'VZJ2MRd71dM9oX2hB1EVAEjUe6loL7pl',\n host: 'https://files.api.ndustrial.io'\n },\n staging: {\n clientId: 'SLE310LY4nDT5p06sUGPVOLlGXk5osbQ',\n host: 'https://files.api.staging.ndustrial.io'\n }\n },\n iot: {\n staging: {\n clientId: 'm35AEcxD8hf65sq04ZU7yFxqpqVkKzES',\n host: 'https://feeds-staging.api.ndustrial.io'\n },\n production: {\n clientId: 'iznTb30Sfp2Jpaf398I5DN6MyPuDCftA',\n host: 'https://feeds.api.ndustrial.io'\n }\n },\n nionic: {\n staging: {\n clientId: 'vhGxildn8hRRWZj49y18BGtbjTkFHcTG',\n host: 'https://<tenant>.api.staging.ndustrial.io'\n },\n production: {\n clientId: 'vtiZlMRo4apDvThTRiH7kLifQXWUdi9j',\n host: 'https://<tenant>.api.ndustrial.io'\n }\n }\n};\n"]}
|
package/lib/index.js
CHANGED
|
@@ -3,12 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.toCamelCase = exports.toSnakeCase = undefined;
|
|
6
7
|
|
|
7
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; }; }();
|
|
8
9
|
|
|
9
|
-
var
|
|
10
|
+
var _objects = require('./utils/objects');
|
|
10
11
|
|
|
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
|
+
});
|
|
12
24
|
|
|
13
25
|
var _bus = require('./bus');
|
|
14
26
|
|
|
@@ -26,22 +38,18 @@ var _events = require('./events');
|
|
|
26
38
|
|
|
27
39
|
var _events2 = _interopRequireDefault(_events);
|
|
28
40
|
|
|
29
|
-
var _facilities = require('./facilities');
|
|
30
|
-
|
|
31
|
-
var _facilities2 = _interopRequireDefault(_facilities);
|
|
32
|
-
|
|
33
41
|
var _files = require('./files');
|
|
34
42
|
|
|
35
43
|
var _files2 = _interopRequireDefault(_files);
|
|
36
44
|
|
|
37
|
-
var _health = require('./health');
|
|
38
|
-
|
|
39
|
-
var _health2 = _interopRequireDefault(_health);
|
|
40
|
-
|
|
41
45
|
var _iot = require('./iot');
|
|
42
46
|
|
|
43
47
|
var _iot2 = _interopRequireDefault(_iot);
|
|
44
48
|
|
|
49
|
+
var _nionic = require('./nionic');
|
|
50
|
+
|
|
51
|
+
var _nionic2 = _interopRequireDefault(_nionic);
|
|
52
|
+
|
|
45
53
|
var _request = require('./request');
|
|
46
54
|
|
|
47
55
|
var _request2 = _interopRequireDefault(_request);
|
|
@@ -134,15 +142,13 @@ var ContxtSdk = function () {
|
|
|
134
142
|
|
|
135
143
|
this.config = new _config2.default(config, externalModules);
|
|
136
144
|
|
|
137
|
-
this.assets = new _assets2.default(this, this._createRequest('facilities'));
|
|
138
145
|
this.auth = this._createAuthSession(sessionType);
|
|
139
146
|
this.bus = new _bus2.default(this, this._createRequest('bus'));
|
|
140
147
|
this.coordinator = new _coordinator2.default(this, this._createRequest('coordinator'));
|
|
141
148
|
this.events = new _events2.default(this, this._createRequest('events'));
|
|
142
|
-
this.facilities = new _facilities2.default(this, this._createRequest('facilities'));
|
|
143
149
|
this.files = new _files2.default(this, this._createRequest('files'));
|
|
144
|
-
this.health = new _health2.default(this, this._createRequest('health'));
|
|
145
150
|
this.iot = new _iot2.default(this, this._createRequest('iot'));
|
|
151
|
+
this.nionic = new _nionic2.default(this, this._createRequest('nionic'));
|
|
146
152
|
|
|
147
153
|
this._decorate(externalModules);
|
|
148
154
|
}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.js"],"names":["sessionTypes","ContxtSdk","config","externalModules","sessionType","_dynamicModuleNames","_replacedModules","Config","assets","Assets","_createRequest","auth","_createAuthSession","bus","Bus","coordinator","Coordinator","events","Events","facilities","Facilities","files","Files","health","Health","iot","Iot","_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":";;;;;;;;AAAA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;;;AACA;;IAAYA,Y;;;;;;;;;;AAEZ;;;;;;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V,UAAnB;AAAA,OADyB,CAA3B;AAGD;;AAED;;;;;;;;;;;;;uCAUmBxB,W,EAAa;AAC9B,cAAQA,WAAR;AACE,aAAKJ,aAAauC,KAAb,CAAmBC,cAAxB;AACE,iBAAO,IAAIxC,aAAayC,YAAjB,CAA8B,IAA9B,CAAP;;AAEF,aAAKzC,aAAauC,KAAb,CAAmBG,mBAAxB;AACE,iBAAO,IAAI1C,aAAa2C,iBAAjB,CAAmC,IAAnC,CAAP;;AAEF,aAAK3C,aAAauC,KAAb,CAAmBK,YAAxB;AACE,iBAAO,IAAI5C,aAAa6C,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,MAAKrB,cAAL,CAAoBkB,UAApB,CAFiB,CAAnB;AAID,OALD;AAMD;;;;;;kBAGY3B,S","file":"index.js","sourcesContent":["import Assets from './assets';\nimport Bus from './bus';\nimport Config from './config';\nimport Coordinator from './coordinator';\nimport Events from './events';\nimport Facilities from './facilities';\nimport Files from './files';\nimport Health from './health';\nimport Iot from './iot';\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.assets = new Assets(this, this._createRequest('facilities'));\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.facilities = new Facilities(this, this._createRequest('facilities'));\n this.files = new Files(this, this._createRequest('files'));\n this.health = new Health(this, this._createRequest('health'));\n this.iot = new Iot(this, this._createRequest('iot'));\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;\n"]}
|
|
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,S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;;;;;;;;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"]}
|