@ndustrial/contxt-sdk 4.1.2 → 4.3.5
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/.nvmrc +1 -1
- package/CHANGELOG.md +12 -0
- package/README.md +2 -12
- package/esm/config/audiences.js +4 -4
- package/esm/config/audiences.js.map +1 -1
- package/esm/coordinator/roles.js +6 -6
- package/esm/coordinator/roles.js.map +1 -1
- package/esm/coordinator/users.js +6 -6
- package/esm/coordinator/users.js.map +1 -1
- package/lib/config/audiences.js +4 -4
- package/lib/config/audiences.js.map +1 -1
- package/lib/coordinator/roles.js +6 -6
- package/lib/coordinator/roles.js.map +1 -1
- package/lib/coordinator/users.js +6 -6
- package/lib/coordinator/users.js.map +1 -1
- package/package.json +5 -2
- package/src/config/audiences.js +4 -4
- package/src/coordinator/roles.js +6 -6
- package/src/coordinator/roles.spec.js +8 -8
- package/src/coordinator/users.js +6 -6
- package/src/coordinator/users.spec.js +8 -8
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v14.
|
|
1
|
+
v14.19.0
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [v4.3.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.3.0) (2021-11-01)
|
|
2
|
+
|
|
3
|
+
**Changed**
|
|
4
|
+
|
|
5
|
+
- updates the files staging default url to files.api.staging.ndustrial.io
|
|
6
|
+
|
|
7
|
+
## [v4.2.0](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.2.0) (2021-02-18)
|
|
8
|
+
|
|
9
|
+
**Changed**
|
|
10
|
+
|
|
11
|
+
- updates uris for updating project environment and user role associations to use an project environment id instead of a slug
|
|
12
|
+
|
|
1
13
|
## [v4.1.2](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.1.2) (2021-02-12)
|
|
2
14
|
|
|
3
15
|
**Changed**
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# contxt-sdk 
|
|
2
2
|
|
|
3
3
|
## Installation
|
|
4
4
|
|
|
@@ -233,14 +233,4 @@ We use [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) for do
|
|
|
233
233
|
|
|
234
234
|
### Publishing
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
your pull request is approved and merged into `master`, follow the steps below.
|
|
238
|
-
|
|
239
|
-
1. Checkout `master` locally and perform a `git pull origin master` so your local repo is up to date with your merged changes.
|
|
240
|
-
1. Run `npm version x.x.x` in your terminal on `master` where the `x`'s are the new version numbers.
|
|
241
|
-
- This sets the new version in `package.json` and `package-lock.json` and also creates a new `git tag`.
|
|
242
|
-
- Example `npm version 0.30.1`
|
|
243
|
-
1. Perform a `git push --tags origin master` while on your local copy of `master`.
|
|
244
|
-
1. Perform an `npm publish` to publish the updated package to NPM.
|
|
245
|
-
|
|
246
|
-
You've now successfully updated and published the package.
|
|
236
|
+
New versions will be published automatically on merges to `main`. The changelog and version will be determined using [Conventional Commits](https://www.conventionalcommits.org/).
|
package/esm/config/audiences.js
CHANGED
|
@@ -27,14 +27,14 @@ export default {
|
|
|
27
27
|
host: 'https://contxt.api.ndustrial.io'
|
|
28
28
|
},
|
|
29
29
|
staging: {
|
|
30
|
-
clientId: '
|
|
31
|
-
host: 'https://contxt-staging.
|
|
30
|
+
clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',
|
|
31
|
+
host: 'https://contxt-api.staging.ndustrial.io'
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
events: {
|
|
35
35
|
staging: {
|
|
36
36
|
clientId: 'dn4MaocJFdKtsBy9sFFaTeuJWL1nt5xu',
|
|
37
|
-
host: 'https://events
|
|
37
|
+
host: 'https://events.api.staging.ndustrial.io'
|
|
38
38
|
},
|
|
39
39
|
production: {
|
|
40
40
|
clientId: '7jzwfE20O2XZ4aq3cO1wmk63G9GzNc8j',
|
|
@@ -58,7 +58,7 @@ export default {
|
|
|
58
58
|
},
|
|
59
59
|
staging: {
|
|
60
60
|
clientId: 'SLE310LY4nDT5p06sUGPVOLlGXk5osbQ',
|
|
61
|
-
host: 'https://files
|
|
61
|
+
host: 'https://files.api.staging.ndustrial.io'
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
health: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","health","iot"],"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,UAAQ;AACNN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GA/DK;AAyEbS,OAAK;AACHP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT;AAzEQ,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: 'XzgumXUg5U57015haylz4zaJsiQqZy4l',\n host: 'https://contxt-auth-staging.api.ndustrial.io'\n }\n },\n coordinator: {\n production: {\n clientId: '8qY2xJob1JAxhmVhIDLCNnGriTM9bct8',\n host: 'https://contxt.api.ndustrial.io'\n },\n staging: {\n clientId: '
|
|
1
|
+
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","health","iot"],"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,UAAQ;AACNN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GA/DK;AAyEbS,OAAK;AACHP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT;AAzEQ,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: 'XzgumXUg5U57015haylz4zaJsiQqZy4l',\n host: 'https://contxt-auth-staging.api.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 health: {\n staging: {\n clientId: '1zQ2YXbHXotrf2dDKgySqEjlJBz465qq',\n host: 'https://health-staging.api.ndustrial.io'\n },\n production: {\n clientId: '6uaQIV1KnnWhXiTm09iGDvy2aQaz2xVI',\n host: 'https://health.api.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};\n"]}
|
package/esm/coordinator/roles.js
CHANGED
|
@@ -131,12 +131,12 @@ var Roles = function () {
|
|
|
131
131
|
|
|
132
132
|
}, {
|
|
133
133
|
key: 'addProjectEnvironment',
|
|
134
|
-
value: function addProjectEnvironment(roleId,
|
|
134
|
+
value: function addProjectEnvironment(roleId, projectEnvironmentId, accessType) {
|
|
135
135
|
if (!roleId) {
|
|
136
136
|
return Promise.reject(new Error('A roleId is required for adding a project environment to a role.'));
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
if (!
|
|
139
|
+
if (!projectEnvironmentId) {
|
|
140
140
|
return Promise.reject(new Error('A project environment slug is required for adding a project environment to a role.'));
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -144,7 +144,7 @@ var Roles = function () {
|
|
|
144
144
|
return Promise.reject(new Error('An accessType of "reader" or "admin" is required for adding a project environment to a role.'));
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
return this._request.post(this._baseUrl + '/roles/' + roleId + '/project_environments/' +
|
|
147
|
+
return this._request.post(this._baseUrl + '/roles/' + roleId + '/project_environments/' + projectEnvironmentId, {
|
|
148
148
|
access_type: accessType
|
|
149
149
|
}).then(function (response) {
|
|
150
150
|
return toCamelCase(response);
|
|
@@ -341,16 +341,16 @@ var Roles = function () {
|
|
|
341
341
|
|
|
342
342
|
}, {
|
|
343
343
|
key: 'removeProjectEnvironment',
|
|
344
|
-
value: function removeProjectEnvironment(roleId,
|
|
344
|
+
value: function removeProjectEnvironment(roleId, projectEnvironmentId) {
|
|
345
345
|
if (!roleId) {
|
|
346
346
|
return Promise.reject(new Error('A roleId is required for removing a project environment from a role.'));
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
if (!
|
|
349
|
+
if (!projectEnvironmentId) {
|
|
350
350
|
return Promise.reject(new Error('A project environment slug is required for removing a project environment from a role.'));
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
return this._request.delete(this._baseUrl + '/roles/' + roleId + '/project_environments/' +
|
|
353
|
+
return this._request.delete(this._baseUrl + '/roles/' + roleId + '/project_environments/' + projectEnvironmentId);
|
|
354
354
|
}
|
|
355
355
|
}]);
|
|
356
356
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["coordinator/roles.js"],"names":["toSnakeCase","toCamelCase","Roles","sdk","request","baseUrl","organizationId","_baseUrl","_request","_sdk","_organizationId","roleId","applicationId","Promise","reject","Error","post","then","response","projectEnvironmentSlug","accessType","indexOf","access_type","role","name","description","delete","get","roles"],"mappings":";;;;AAAA,SAASA,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;AAWA;;;;;;;;;AASA;;;;;;;;;AASA;;;;;;;;;;;;;;AAcA;;;;;;IAKMC,K;AACJ;;;;;;AAMA,iBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAA0D;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AACxD,SAAKC,QAAL,GAAgBF,OAAhB;AACA,SAAKG,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,IAAL,GAAYN,GAAZ;AACA,SAAKO,eAAL,GAAuBJ,cAAvB;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;mCAmBeK,M,EAAQC,a,EAAe;AACpC,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,2DAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACH,aAAL,EAAoB;AAClB,eAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,mEADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CACJQ,IADI,CACI,KAAKT,QADT,eAC2BI,MAD3B,sBACkDC,aADlD,EAEJK,IAFI,CAEC,UAACC,QAAD;AAAA,eAAcjB,YAAYiB,QAAZ,CAAd;AAAA,OAFD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;;;0CAoBsBP,M,EAAQQ,sB,EAAwBC,U,EAAY;AAChE,UAAI,CAACT,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,kEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACI,sBAAL,EAA6B;AAC3B,eAAON,QAAQC,MAAR,CACL,IAAIC,K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,eAAW3B,YAAY2B,KAAZ,CAAX;AAAA,OAFD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;sCAkBkBjB,M,EAAQC,a,EAAe;AACvC,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,+DADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACH,aAAL,EAAoB;AAClB,eAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,uEADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CAAckB,MAAd,CACF,KAAKnB,QADH,eACqBI,MADrB,sBAC4CC,aAD5C,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;6CAkByBD,M,EAAQQ,sB,EAAwB;AACvD,UAAI,CAACR,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACI,sBAAL,EAA6B;AAC3B,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CAAckB,MAAd,CAEH,KAAKnB,QAFF,eAGKI,MAHL,8BAGoCQ,sBAHpC,CAAP;AAKD;;;;;;AAGH,eAAejB,KAAf","file":"roles.js","sourcesContent":["import { toSnakeCase, toCamelCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtRole\n * @property {ContxtApplication[]} applications\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id\n * @property {string} name\n * @property {string} organizationId\n * @property {ContxtProjectEnvironment[]} projectEnvironments\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n/**\n * @typedef {Object} ContxtRoleApplication\n * @property {number} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {number} id\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtRoleProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} userId\n * @property {string} environmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtProjectEnvironment\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} organizationId\n * @property {number} projectId\n * @property {string} clusterId\n * @property {string} slug\n * @property {string} name\n * @property {string} type\n * @property {string} description\n */\n\n/**\n * Module that provides access to contxt roles\n *\n * @typicalname contxtSdk.coordinator.roles\n */\nclass Roles {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, baseUrl, organizationId = null) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n /**\n * Add an application to a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleApplication}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .then((roleApplication) => console.log(roleApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for adding an application to a role.')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for adding an application to a role.'\n )\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles/${roleId}/applications/${applicationId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Add a project environment to a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleProjectEnvironment}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((roleProject) => console.log(roleProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(roleId, projectEnvironmentSlug, accessType) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for adding a project environment to a role.'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a role.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An accessType of \"reader\" or \"admin\" is required for adding a project environment to a role.'\n )\n );\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentSlug}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Create a new role for an organization\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} role\n * @param {string} role.name The name of the new role\n * @param {string} role.description Some text describing the purpose of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRole} The newly created role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .create('36b8421a-cc4a-4204-b839-1397374fb16b', {\n * name: 'view-myapp',\n * description: 'Give this role for viewing myapp'\n * })\n * .then((role) => console.log(role))\n * .catch((err) => console.log(err));\n */\n create(organizationId, role = {}) {\n if (this._organizationId) {\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles`, toSnakeCase(role))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for creating roles for an organization.'\n )\n );\n }\n\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${organizationId}/roles`,\n toSnakeCase(role)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a role from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles/:roleId'\n * API Endpiont: '/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} roleId The UUID formatted ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles.delete('4f0e51c6-728b-4892-9863-6d002e61204d', '8b64fb12-e649-46be-b330-e672d28eed99s');\n */\n delete(organizationId, roleId) {\n if (this._organizationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/roles/${roleId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organizationId is required for deleting a role.')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/organizations/${organizationId}/roles/${roleId}`\n );\n }\n\n /**\n * Gets an organization's list of roles\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles'\n * API Endpoint: '/roles'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtRole[]} A list of roles\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((roles) => console.log(roles))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._baseUrl}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for getting roles for an organization.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n /**\n * Remove an application from a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .catch((err) => console.log(err));\n */\n removeApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing an application from a role.'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for removing an application from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/roles/${roleId}/applications/${applicationId}`\n );\n }\n\n /**\n * Remove a project environment from a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(roleId, projectEnvironmentSlug) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing a project environment from a role.'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentSlug}`\n );\n }\n}\n\nexport default Roles;\n"]}
|
|
1
|
+
{"version":3,"sources":["coordinator/roles.js"],"names":["toSnakeCase","toCamelCase","Roles","sdk","request","baseUrl","organizationId","_baseUrl","_request","_sdk","_organizationId","roleId","applicationId","Promise","reject","Error","post","then","response","projectEnvironmentId","accessType","indexOf","access_type","role","name","description","delete","get","roles"],"mappings":";;;;AAAA,SAASA,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;AAWA;;;;;;;;;AASA;;;;;;;;;AASA;;;;;;;;;;;;;;AAcA;;;;;;IAKMC,K;AACJ;;;;;;AAMA,iBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAA0D;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AACxD,SAAKC,QAAL,GAAgBF,OAAhB;AACA,SAAKG,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,IAAL,GAAYN,GAAZ;AACA,SAAKO,eAAL,GAAuBJ,cAAvB;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;mCAmBeK,M,EAAQC,a,EAAe;AACpC,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,2DAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACH,aAAL,EAAoB;AAClB,eAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,mEADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CACJQ,IADI,CACI,KAAKT,QADT,eAC2BI,MAD3B,sBACkDC,aADlD,EAEJK,IAFI,CAEC,UAACC,QAAD;AAAA,eAAcjB,YAAYiB,QAAZ,CAAd;AAAA,OAFD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;;;0CAoBsBP,M,EAAQQ,oB,EAAs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EAAqB;AACnB,eAAOO,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CACJmB,GADI,CACG,KAAKpB,QADR,uBACkCD,cADlC,aAEJW,IAFI,CAEC,UAACW,KAAD;AAAA,eAAW3B,YAAY2B,KAAZ,CAAX;AAAA,OAFD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;sCAkBkBjB,M,EAAQC,a,EAAe;AACvC,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,+DADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACH,aAAL,EAAoB;AAClB,eAAOC,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,uEADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CAAckB,MAAd,CACF,KAAKnB,QADH,eACqBI,MADrB,sBAC4CC,aAD5C,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;6CAkByBD,M,EAAQQ,oB,EAAsB;AACrD,UAAI,CAACR,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACI,oBAAL,EAA2B;AACzB,eAAON,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CAAckB,MAAd,CAEH,KAAKnB,QAFF,eAGKI,MAHL,8BAGoCQ,oBAHpC,CAAP;AAKD;;;;;;AAGH,eAAejB,KAAf","file":"roles.js","sourcesContent":["import { toSnakeCase, toCamelCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtRole\n * @property {ContxtApplication[]} applications\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id\n * @property {string} name\n * @property {string} organizationId\n * @property {ContxtProjectEnvironment[]} projectEnvironments\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n/**\n * @typedef {Object} ContxtRoleApplication\n * @property {number} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {number} id\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtRoleProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} userId\n * @property {string} environmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtProjectEnvironment\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} organizationId\n * @property {number} projectId\n * @property {string} clusterId\n * @property {string} slug\n * @property {string} name\n * @property {string} type\n * @property {string} description\n */\n\n/**\n * Module that provides access to contxt roles\n *\n * @typicalname contxtSdk.coordinator.roles\n */\nclass Roles {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, baseUrl, organizationId = null) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n /**\n * Add an application to a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleApplication}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .then((roleApplication) => console.log(roleApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for adding an application to a role.')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for adding an application to a role.'\n )\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles/${roleId}/applications/${applicationId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Add a project environment to a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleProjectEnvironment}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((roleProject) => console.log(roleProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(roleId, projectEnvironmentId, accessType) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for adding a project environment to a role.'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a role.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An accessType of \"reader\" or \"admin\" is required for adding a project environment to a role.'\n )\n );\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentId}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Create a new role for an organization\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} role\n * @param {string} role.name The name of the new role\n * @param {string} role.description Some text describing the purpose of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRole} The newly created role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .create('36b8421a-cc4a-4204-b839-1397374fb16b', {\n * name: 'view-myapp',\n * description: 'Give this role for viewing myapp'\n * })\n * .then((role) => console.log(role))\n * .catch((err) => console.log(err));\n */\n create(organizationId, role = {}) {\n if (this._organizationId) {\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles`, toSnakeCase(role))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for creating roles for an organization.'\n )\n );\n }\n\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${organizationId}/roles`,\n toSnakeCase(role)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a role from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles/:roleId'\n * API Endpiont: '/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} roleId The UUID formatted ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles.delete('4f0e51c6-728b-4892-9863-6d002e61204d', '8b64fb12-e649-46be-b330-e672d28eed99s');\n */\n delete(organizationId, roleId) {\n if (this._organizationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/roles/${roleId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organizationId is required for deleting a role.')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/organizations/${organizationId}/roles/${roleId}`\n );\n }\n\n /**\n * Gets an organization's list of roles\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles'\n * API Endpoint: '/roles'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtRole[]} A list of roles\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((roles) => console.log(roles))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._baseUrl}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for getting roles for an organization.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n /**\n * Remove an application from a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .catch((err) => console.log(err));\n */\n removeApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing an application from a role.'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for removing an application from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/roles/${roleId}/applications/${applicationId}`\n );\n }\n\n /**\n * Remove a project environment from a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(roleId, projectEnvironmentId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing a project environment from a role.'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentId}`\n );\n }\n}\n\nexport default Roles;\n"]}
|
package/esm/coordinator/users.js
CHANGED
|
@@ -240,12 +240,12 @@ var Users = function () {
|
|
|
240
240
|
|
|
241
241
|
}, {
|
|
242
242
|
key: 'addProjectEnvironment',
|
|
243
|
-
value: function addProjectEnvironment(userId,
|
|
243
|
+
value: function addProjectEnvironment(userId, projectEnvironmentId, accessType) {
|
|
244
244
|
if (!userId) {
|
|
245
245
|
return Promise.reject(new Error('A user ID is required for adding a project environment to a user'));
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
if (!
|
|
248
|
+
if (!projectEnvironmentId) {
|
|
249
249
|
return Promise.reject(new Error('A project environment slug is required for adding a project environment to a user.'));
|
|
250
250
|
}
|
|
251
251
|
|
|
@@ -253,7 +253,7 @@ var Users = function () {
|
|
|
253
253
|
return Promise.reject(new Error('An access type of "reader" or "admin" is required for adding a project environment to a user'));
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
return this._request.post(this._getBaseUrl() + '/users/' + userId + '/project_environments/' +
|
|
256
|
+
return this._request.post(this._getBaseUrl() + '/users/' + userId + '/project_environments/' + projectEnvironmentId, {
|
|
257
257
|
access_type: accessType
|
|
258
258
|
}).then(function (response) {
|
|
259
259
|
return toCamelCase(response);
|
|
@@ -534,16 +534,16 @@ var Users = function () {
|
|
|
534
534
|
|
|
535
535
|
}, {
|
|
536
536
|
key: 'removeProjectEnvironment',
|
|
537
|
-
value: function removeProjectEnvironment(userId,
|
|
537
|
+
value: function removeProjectEnvironment(userId, projectEnvironmentId) {
|
|
538
538
|
if (!userId) {
|
|
539
539
|
return Promise.reject(new Error('A user ID is required for removing a project environment from a user'));
|
|
540
540
|
}
|
|
541
541
|
|
|
542
|
-
if (!
|
|
542
|
+
if (!projectEnvironmentId) {
|
|
543
543
|
return Promise.reject(new Error('A project environment slug is required for removing a project environment from a user.'));
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
return this._request.delete(this._getBaseUrl() + '/users/' + userId + '/project_environments/' +
|
|
546
|
+
return this._request.delete(this._getBaseUrl() + '/users/' + userId + '/project_environments/' + projectEnvironmentId);
|
|
547
547
|
}
|
|
548
548
|
|
|
549
549
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["coordinator/users.js"],"names":["axios","toCamelCase","toSnakeCase","Users","sdk","request","baseUrl","tenantBaseUrl","legacyBaseUrl","organizationId","_baseUrl","_tenantBaseUrl","_legacyBaseUrl","_request","_sdk","_organizationId","type","userId","user","Promise","reject","Error","requiredFields","i","length","field","post","_getBaseUrl","applicationId","then","response","roleId","projectEnvironmentSlug","accessType","indexOf","access_type","get","orgUsers","delete"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;;AAEA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;;AASA;;;;;;;;;;AAUA;;;;;;;;;;AAUA;;;;;;IAKMC,K;AACJ;;;;;;;;AAQA,iBACEC,GADF,EAEEC,OAFF,EAGEC,OAHF,EAOE;AAAA,QAHAC,aAGA,uEAHgB,IAGhB;AAAA,QAFAC,aAEA,uEAFgB,IAEhB;AAAA,QADAC,cACA,uEADiB,IACjB;;AAAA;;AACA,SAAKC,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,cAAL,GAAsBJ,aAAtB;AACA,SAAKK,cAAL,GAAsBJ,aAAtB;AACA,SAAKK,QAAL,GAAgBR,OAAhB;AACA,SAAKS,IAAL,GAAYV,GAAZ;AACA,SAAKW,eAAL,GAAuBN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CADK,CAAP;AAKD;;AAED,UAAI,CAACW,sBAAL,EAA6B;AAC3B,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKR,QAAL,CAAcyB,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BV,MAD1B,8BACyDe,sBADzD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;yBAiBKf,M,EAAQ;AACX,UAAI,CAACA,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,oDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAcuB,GAAd,CACF,KAAKT,WAAL,CAAiB,QAAjB,CADE,eACkCV,MADlC,WAAP;AAGD;;;;;;AAGH,eAAed,KAAf","file":"users.js","sourcesContent":["import axios from 'axios';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtUser\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} email\n * @property {string} firstName\n * @property {string} id\n * @property {boolean} isActivated\n * @property {boolean} isSuperuser\n * @property {string} lastName\n * @property {string} [phoneNumber]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserApplication\n * @property {string} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserRole\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {boolean} mappedFromExternalGroup\n * @property {string} userId\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} projectEnvironmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to contxt users\n *\n * @typicalname contxtSdk.coordinator.users\n */\nclass Users {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [tenantBaseUrl] The tenant base URL provided by the parent module\n * @param {string} [legacyBaseUrl] The legacy base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(\n sdk,\n request,\n baseUrl,\n tenantBaseUrl = null,\n legacyBaseUrl = null,\n organizationId = null\n ) {\n this._baseUrl = baseUrl;\n this._tenantBaseUrl = tenantBaseUrl;\n this._legacyBaseUrl = legacyBaseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n _getBaseUrl(type) {\n switch (type) {\n case 'legacy':\n return this._legacyBaseUrl || this._baseUrl;\n\n case 'access':\n return this._baseUrl;\n\n default:\n return this._tenantBaseUrl || this._baseUrl;\n }\n }\n\n /**\n * Activates a new user\n *\n * API Endpoint: '/users/:userId/activate'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} userId The ID of the user to activate\n * @param {Object} user\n * @param {string} user.email The email address of the user\n * @param {string} user.password The password to set for the user\n * @param {string} user.userToken The JWT token provided by the invite link\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .activate('7bb79bdf-7492-45c2-8640-2dde63535827', {\n * email: 'bob.sagat56@gmail.com',\n * password: 'ds32jX32jaMM1Nr',\n * userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'\n * })\n * .then(() => console.log(\"User Activated\"))\n * .catch((err) => console.log(err));\n */\n activate(userId, user = {}) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for activating a user')\n );\n }\n\n const requiredFields = ['email', 'password', 'userToken'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to activate a user.`)\n );\n }\n }\n\n // Uses axios directly instead of this.request to bypass authorization interceptors\n return axios.post(\n `${this._getBaseUrl('access')}/users/${userId}/activate`,\n toSnakeCase(user)\n );\n }\n\n /**\n * Adds a application to a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtUserApplication} The newly created user application\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userApplication) => console.log(userApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a application to a user')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for adding a application to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a role to a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtUserRole} The newly created user role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userRole) => console.log(userRole))\n * .catch((err) => console.log(err));\n */\n addRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a role to a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for adding a role to a user')\n );\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users/${userId}/roles/${roleId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a project environment to a user\n *\n * API Endpoint: '/users/:userId/project_environments/:projectEnvironmentSlug\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUserProjectEnvironment} The newly created user project environment\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((userProject) => console.log(userProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(userId, projectEnvironmentSlug, accessType) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for adding a project environment to a user'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a user.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An access type of \"reader\" or \"admin\" is required for adding a project environment to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentSlug}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Gets information about a contxt user\n *\n * API Endpoint: '/users/:userId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} Information about a contxt user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .get('auth0|12345')\n * .then((user) => console.log(user))\n * .catch((err) => console.log(err));\n */\n get(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for getting information about a user')\n );\n }\n\n return this._request\n .get(`${this._getBaseUrl('access')}/users/${userId}`)\n .then((user) => toCamelCase(user));\n }\n\n /**\n * Gets a list of users for a contxt organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtUser[]} List of users for a contxt organization\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((orgUsers) => console.log(orgUsers))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._getBaseUrl()}/users`)\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for getting a list of users for an organization'\n )\n );\n }\n\n return this._request\n .get(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`\n )\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n /**\n * Creates a new contxt user, adds them to an organization, and\n * sends them an email invite link to do final account setup.\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} user\n * @param {string} user.email The email address of the new user\n * @param {string} user.firstName The first name of the new user\n * @param {string} user.lastName The last name of the new user\n * @param {string} user.redirectUrl The url that the user will be redirected\n * to after using the invite email link. Typically this is an /activate\n * endpoint that accepts url query params userToken and userId and uses them\n * to do final activation on the user's account.\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} The new user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .invite('fdf01507-a26a-4dfe-89a2-bc91861169b8', {\n * email: 'bob.sagat56@gmail.com',\n * firstName: 'Bob',\n * lastName: 'Sagat',\n * redirectUrl: 'https://contxt.ndustrial.io/activate'\n * })\n * .then((newUser) => console.log(newUser))\n * .catch((err) => console.log(err));\n */\n invite(organizationId, user = {}) {\n if (this._organizationId) {\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users`, toSnakeCase(user))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organization ID is required for inviting a new user')\n );\n }\n\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`,\n toSnakeCase(user)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Removes a user from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users/:userId'\n * API Endpoint: '/users/:userId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .remove('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52')\n * .catch((err) => console.log(err));\n */\n remove(organizationId, userId) {\n if (this._organizationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(`${this._getBaseUrl()}/users/${userId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for removing a user from an organization'\n )\n );\n }\n\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl(\n 'legacy'\n )}/organizations/${organizationId}/users/${userId}`\n );\n }\n\n /**\n * Removes a application from a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a application from a user'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for removing a application from a user'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n );\n }\n\n /**\n * Removes a role from a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for removing a role from a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for removing a role from a user')\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/roles/${roleId}`\n );\n }\n\n /**\n * Removes a project environment from a user\n *\n * API Endpoint: 'users/:userId/project_environments/:projectEnvironmentSlug\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(userId, projectEnvironmentSlug) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a project environment from a user'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a user.'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentSlug}`\n );\n }\n\n /**\n * Syncs the user's roles and application access with the external auth provider\n *\n * API Endpoint: '/users/:userId/sync'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .sync('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .catch((err) => console.log(err));\n */\n sync(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for syncing user permissions')\n );\n }\n\n return this._request.get(\n `${this._getBaseUrl('access')}/users/${userId}/sync`\n );\n }\n}\n\nexport default Users;\n"]}
|
|
1
|
+
{"version":3,"sources":["coordinator/users.js"],"names":["axios","toCamelCase","toSnakeCase","Users","sdk","request","baseUrl","tenantBaseUrl","legacyBaseUrl","organizationId","_baseUrl","_tenantBaseUrl","_legacyBaseUrl","_request","_sdk","_organizationId","type","userId","user","Promise","reject","Error","requiredFields","i","length","field","post","_getBaseUrl","applicationId","then","response","roleId","projectEnvironmentId","accessType","indexOf","access_type","get","orgUsers","delete"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;;AAEA,SAASC,WAAT,EAAsBC,WAAtB,QAAyC,kBAAzC;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;;AASA;;;;;;;;;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,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACU,MAAL,EAAa;AACX,eAAOZ,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAcyB,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BV,MAD1B,eAC0Cc,MAD1C,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;6CAkByBd,M,EAAQe,oB,EAAsB;AACrD,UAAI,CAACf,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACW,oBAAL,EAA2B;AACzB,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKR,QAAL,CAAcyB,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BV,MAD1B,8BACyDe,oBADzD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;yBAiBKf,M,EAAQ;AACX,UAAI,CAACA,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,oDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAcuB,GAAd,CACF,KAAKT,WAAL,CAAiB,QAAjB,CADE,eACkCV,MADlC,WAAP;AAGD;;;;;;AAGH,eAAed,KAAf","file":"users.js","sourcesContent":["import axios from 'axios';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtUser\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} email\n * @property {string} firstName\n * @property {string} id\n * @property {boolean} isActivated\n * @property {boolean} isSuperuser\n * @property {string} lastName\n * @property {string} [phoneNumber]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserApplication\n * @property {string} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserRole\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {boolean} mappedFromExternalGroup\n * @property {string} userId\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} projectEnvironmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to contxt users\n *\n * @typicalname contxtSdk.coordinator.users\n */\nclass Users {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [tenantBaseUrl] The tenant base URL provided by the parent module\n * @param {string} [legacyBaseUrl] The legacy base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(\n sdk,\n request,\n baseUrl,\n tenantBaseUrl = null,\n legacyBaseUrl = null,\n organizationId = null\n ) {\n this._baseUrl = baseUrl;\n this._tenantBaseUrl = tenantBaseUrl;\n this._legacyBaseUrl = legacyBaseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n _getBaseUrl(type) {\n switch (type) {\n case 'legacy':\n return this._legacyBaseUrl || this._baseUrl;\n\n case 'access':\n return this._baseUrl;\n\n default:\n return this._tenantBaseUrl || this._baseUrl;\n }\n }\n\n /**\n * Activates a new user\n *\n * API Endpoint: '/users/:userId/activate'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} userId The ID of the user to activate\n * @param {Object} user\n * @param {string} user.email The email address of the user\n * @param {string} user.password The password to set for the user\n * @param {string} user.userToken The JWT token provided by the invite link\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .activate('7bb79bdf-7492-45c2-8640-2dde63535827', {\n * email: 'bob.sagat56@gmail.com',\n * password: 'ds32jX32jaMM1Nr',\n * userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'\n * })\n * .then(() => console.log(\"User Activated\"))\n * .catch((err) => console.log(err));\n */\n activate(userId, user = {}) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for activating a user')\n );\n }\n\n const requiredFields = ['email', 'password', 'userToken'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to activate a user.`)\n );\n }\n }\n\n // Uses axios directly instead of this.request to bypass authorization interceptors\n return axios.post(\n `${this._getBaseUrl('access')}/users/${userId}/activate`,\n toSnakeCase(user)\n );\n }\n\n /**\n * Adds a application to a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtUserApplication} The newly created user application\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userApplication) => console.log(userApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a application to a user')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for adding a application to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a role to a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtUserRole} The newly created user role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userRole) => console.log(userRole))\n * .catch((err) => console.log(err));\n */\n addRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a role to a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for adding a role to a user')\n );\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users/${userId}/roles/${roleId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a project environment to a user\n *\n * API Endpoint: '/users/:userId/project_environments/:projectEnvironmentSlug\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUserProjectEnvironment} The newly created user project environment\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((userProject) => console.log(userProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(userId, projectEnvironmentId, accessType) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for adding a project environment to a user'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a user.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An access type of \"reader\" or \"admin\" is required for adding a project environment to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Gets information about a contxt user\n *\n * API Endpoint: '/users/:userId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} Information about a contxt user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .get('auth0|12345')\n * .then((user) => console.log(user))\n * .catch((err) => console.log(err));\n */\n get(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for getting information about a user')\n );\n }\n\n return this._request\n .get(`${this._getBaseUrl('access')}/users/${userId}`)\n .then((user) => toCamelCase(user));\n }\n\n /**\n * Gets a list of users for a contxt organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtUser[]} List of users for a contxt organization\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((orgUsers) => console.log(orgUsers))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._getBaseUrl()}/users`)\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for getting a list of users for an organization'\n )\n );\n }\n\n return this._request\n .get(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`\n )\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n /**\n * Creates a new contxt user, adds them to an organization, and\n * sends them an email invite link to do final account setup.\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} user\n * @param {string} user.email The email address of the new user\n * @param {string} user.firstName The first name of the new user\n * @param {string} user.lastName The last name of the new user\n * @param {string} user.redirectUrl The url that the user will be redirected\n * to after using the invite email link. Typically this is an /activate\n * endpoint that accepts url query params userToken and userId and uses them\n * to do final activation on the user's account.\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} The new user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .invite('fdf01507-a26a-4dfe-89a2-bc91861169b8', {\n * email: 'bob.sagat56@gmail.com',\n * firstName: 'Bob',\n * lastName: 'Sagat',\n * redirectUrl: 'https://contxt.ndustrial.io/activate'\n * })\n * .then((newUser) => console.log(newUser))\n * .catch((err) => console.log(err));\n */\n invite(organizationId, user = {}) {\n if (this._organizationId) {\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users`, toSnakeCase(user))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organization ID is required for inviting a new user')\n );\n }\n\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`,\n toSnakeCase(user)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Removes a user from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users/:userId'\n * API Endpoint: '/users/:userId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .remove('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52')\n * .catch((err) => console.log(err));\n */\n remove(organizationId, userId) {\n if (this._organizationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(`${this._getBaseUrl()}/users/${userId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for removing a user from an organization'\n )\n );\n }\n\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl(\n 'legacy'\n )}/organizations/${organizationId}/users/${userId}`\n );\n }\n\n /**\n * Removes a application from a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a application from a user'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for removing a application from a user'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n );\n }\n\n /**\n * Removes a role from a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for removing a role from a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for removing a role from a user')\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/roles/${roleId}`\n );\n }\n\n /**\n * Removes a project environment from a user\n *\n * API Endpoint: 'users/:userId/project_environments/:projectEnvironmentSlug\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(userId, projectEnvironmentId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a project environment from a user'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a user.'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`\n );\n }\n\n /**\n * Syncs the user's roles and application access with the external auth provider\n *\n * API Endpoint: '/users/:userId/sync'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .sync('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .catch((err) => console.log(err));\n */\n sync(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for syncing user permissions')\n );\n }\n\n return this._request.get(\n `${this._getBaseUrl('access')}/users/${userId}/sync`\n );\n }\n}\n\nexport default Users;\n"]}
|
package/lib/config/audiences.js
CHANGED
|
@@ -32,14 +32,14 @@ exports.default = {
|
|
|
32
32
|
host: 'https://contxt.api.ndustrial.io'
|
|
33
33
|
},
|
|
34
34
|
staging: {
|
|
35
|
-
clientId: '
|
|
36
|
-
host: 'https://contxt-staging.
|
|
35
|
+
clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',
|
|
36
|
+
host: 'https://contxt-api.staging.ndustrial.io'
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
events: {
|
|
40
40
|
staging: {
|
|
41
41
|
clientId: 'dn4MaocJFdKtsBy9sFFaTeuJWL1nt5xu',
|
|
42
|
-
host: 'https://events
|
|
42
|
+
host: 'https://events.api.staging.ndustrial.io'
|
|
43
43
|
},
|
|
44
44
|
production: {
|
|
45
45
|
clientId: '7jzwfE20O2XZ4aq3cO1wmk63G9GzNc8j',
|
|
@@ -63,7 +63,7 @@ exports.default = {
|
|
|
63
63
|
},
|
|
64
64
|
staging: {
|
|
65
65
|
clientId: 'SLE310LY4nDT5p06sUGPVOLlGXk5osbQ',
|
|
66
|
-
host: 'https://files
|
|
66
|
+
host: 'https://files.api.staging.ndustrial.io'
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
health: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","health","iot"],"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,UAAQ;AACNN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GA/DK;AAyEbS,OAAK;AACHP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT;AAzEQ,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: 'XzgumXUg5U57015haylz4zaJsiQqZy4l',\n host: 'https://contxt-auth-staging.api.ndustrial.io'\n }\n },\n coordinator: {\n production: {\n clientId: '8qY2xJob1JAxhmVhIDLCNnGriTM9bct8',\n host: 'https://contxt.api.ndustrial.io'\n },\n staging: {\n clientId: '
|
|
1
|
+
{"version":3,"sources":["config/audiences.js"],"names":["bus","production","clientId","host","webSocket","staging","contxtAuth","coordinator","events","facilities","files","health","iot"],"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,UAAQ;AACNN,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADH;AAKNF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALN,GA/DK;AAyEbS,OAAK;AACHP,aAAS;AACPH,gBAAU,kCADH;AAEPC,YAAM;AAFC,KADN;AAKHF,gBAAY;AACVC,gBAAU,kCADA;AAEVC,YAAM;AAFI;AALT;AAzEQ,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: 'XzgumXUg5U57015haylz4zaJsiQqZy4l',\n host: 'https://contxt-auth-staging.api.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 health: {\n staging: {\n clientId: '1zQ2YXbHXotrf2dDKgySqEjlJBz465qq',\n host: 'https://health-staging.api.ndustrial.io'\n },\n production: {\n clientId: '6uaQIV1KnnWhXiTm09iGDvy2aQaz2xVI',\n host: 'https://health.api.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};\n"]}
|
package/lib/coordinator/roles.js
CHANGED
|
@@ -136,12 +136,12 @@ var Roles = function () {
|
|
|
136
136
|
|
|
137
137
|
}, {
|
|
138
138
|
key: 'addProjectEnvironment',
|
|
139
|
-
value: function addProjectEnvironment(roleId,
|
|
139
|
+
value: function addProjectEnvironment(roleId, projectEnvironmentId, accessType) {
|
|
140
140
|
if (!roleId) {
|
|
141
141
|
return Promise.reject(new Error('A roleId is required for adding a project environment to a role.'));
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
if (!
|
|
144
|
+
if (!projectEnvironmentId) {
|
|
145
145
|
return Promise.reject(new Error('A project environment slug is required for adding a project environment to a role.'));
|
|
146
146
|
}
|
|
147
147
|
|
|
@@ -149,7 +149,7 @@ var Roles = function () {
|
|
|
149
149
|
return Promise.reject(new Error('An accessType of "reader" or "admin" is required for adding a project environment to a role.'));
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
return this._request.post(this._baseUrl + '/roles/' + roleId + '/project_environments/' +
|
|
152
|
+
return this._request.post(this._baseUrl + '/roles/' + roleId + '/project_environments/' + projectEnvironmentId, {
|
|
153
153
|
access_type: accessType
|
|
154
154
|
}).then(function (response) {
|
|
155
155
|
return (0, _objects.toCamelCase)(response);
|
|
@@ -346,16 +346,16 @@ var Roles = function () {
|
|
|
346
346
|
|
|
347
347
|
}, {
|
|
348
348
|
key: 'removeProjectEnvironment',
|
|
349
|
-
value: function removeProjectEnvironment(roleId,
|
|
349
|
+
value: function removeProjectEnvironment(roleId, projectEnvironmentId) {
|
|
350
350
|
if (!roleId) {
|
|
351
351
|
return Promise.reject(new Error('A roleId is required for removing a project environment from a role.'));
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
if (!
|
|
354
|
+
if (!projectEnvironmentId) {
|
|
355
355
|
return Promise.reject(new Error('A project environment slug is required for removing a project environment from a role.'));
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
return this._request.delete(this._baseUrl + '/roles/' + roleId + '/project_environments/' +
|
|
358
|
+
return this._request.delete(this._baseUrl + '/roles/' + roleId + '/project_environments/' + projectEnvironmentId);
|
|
359
359
|
}
|
|
360
360
|
}]);
|
|
361
361
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["coordinator/roles.js"],"names":["Roles","sdk","request","baseUrl","organizationId","_baseUrl","_request","_sdk","_organizationId","roleId","applicationId","Promise","reject","Error","post","then","response","projectEnvironmentSlug","accessType","indexOf","access_type","role","name","description","delete","get","roles"],"mappings":";;;;;;;;AAAA;;;;AAEA;;;;;;;;;;;AAWA;;;;;;;;;AASA;;;;;;;;;AASA;;;;;;;;;;;;;;AAcA;;;;;IAKMA,K;AACJ;;;;;;AAMA,iBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAA0D;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AACxD,SAAKC,QAAL,GAAgBF,OAAhB;AACA,SAAKG,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,IAAL,GAAYN,GAAZ;AACA,SAAKO,eAAL,GAAuBJ,cAAvB;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;mCAmBeK,M,EAAQC,a,EAAe;AACpC,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,2DAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACH,aAAL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nB,QAFF,eAGKI,MAHL,8BAGoCQ,sBAHpC,CAAP;AAKD;;;;;;kBAGYjB,K","file":"roles.js","sourcesContent":["import { toSnakeCase, toCamelCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtRole\n * @property {ContxtApplication[]} applications\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id\n * @property {string} name\n * @property {string} organizationId\n * @property {ContxtProjectEnvironment[]} projectEnvironments\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n/**\n * @typedef {Object} ContxtRoleApplication\n * @property {number} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {number} id\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtRoleProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} userId\n * @property {string} environmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtProjectEnvironment\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} organizationId\n * @property {number} projectId\n * @property {string} clusterId\n * @property {string} slug\n * @property {string} name\n * @property {string} type\n * @property {string} description\n */\n\n/**\n * Module that provides access to contxt roles\n *\n * @typicalname contxtSdk.coordinator.roles\n */\nclass Roles {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, baseUrl, organizationId = null) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n /**\n * Add an application to a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleApplication}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .then((roleApplication) => console.log(roleApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for adding an application to a role.')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for adding an application to a role.'\n )\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles/${roleId}/applications/${applicationId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Add a project environment to a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleProjectEnvironment}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((roleProject) => console.log(roleProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(roleId, projectEnvironmentSlug, accessType) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for adding a project environment to a role.'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a role.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An accessType of \"reader\" or \"admin\" is required for adding a project environment to a role.'\n )\n );\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentSlug}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Create a new role for an organization\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} role\n * @param {string} role.name The name of the new role\n * @param {string} role.description Some text describing the purpose of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRole} The newly created role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .create('36b8421a-cc4a-4204-b839-1397374fb16b', {\n * name: 'view-myapp',\n * description: 'Give this role for viewing myapp'\n * })\n * .then((role) => console.log(role))\n * .catch((err) => console.log(err));\n */\n create(organizationId, role = {}) {\n if (this._organizationId) {\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles`, toSnakeCase(role))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for creating roles for an organization.'\n )\n );\n }\n\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${organizationId}/roles`,\n toSnakeCase(role)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a role from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles/:roleId'\n * API Endpiont: '/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} roleId The UUID formatted ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles.delete('4f0e51c6-728b-4892-9863-6d002e61204d', '8b64fb12-e649-46be-b330-e672d28eed99s');\n */\n delete(organizationId, roleId) {\n if (this._organizationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/roles/${roleId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organizationId is required for deleting a role.')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/organizations/${organizationId}/roles/${roleId}`\n );\n }\n\n /**\n * Gets an organization's list of roles\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles'\n * API Endpoint: '/roles'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtRole[]} A list of roles\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((roles) => console.log(roles))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._baseUrl}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for getting roles for an organization.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n /**\n * Remove an application from a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .catch((err) => console.log(err));\n */\n removeApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing an application from a role.'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for removing an application from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/roles/${roleId}/applications/${applicationId}`\n );\n }\n\n /**\n * Remove a project environment from a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(roleId, projectEnvironmentSlug) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing a project environment from a role.'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentSlug}`\n );\n }\n}\n\nexport default Roles;\n"]}
|
|
1
|
+
{"version":3,"sources":["coordinator/roles.js"],"names":["Roles","sdk","request","baseUrl","organizationId","_baseUrl","_request","_sdk","_organizationId","roleId","applicationId","Promise","reject","Error","post","then","response","projectEnvironmentId","accessType","indexOf","access_type","role","name","description","delete","get","roles"],"mappings":";;;;;;;;AAAA;;;;AAEA;;;;;;;;;;;AAWA;;;;;;;;;AASA;;;;;;;;;AASA;;;;;;;;;;;;;;AAcA;;;;;IAKMA,K;AACJ;;;;;;AAMA,iBAAYC,GAAZ,EAAiBC,OAAjB,EAA0BC,OAA1B,EAA0D;AAAA,QAAvBC,cAAuB,uEAAN,IAAM;;AAAA;;AACxD,SAAKC,QAAL,GAAgBF,OAAhB;AACA,SAAKG,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,IAAL,GAAYN,GAAZ;AACA,SAAKO,eAAL,GAAuBJ,cAAvB;AACD;;AAED;;;;;;;;;;;;;;;;;;;;;;;mCAmBeK,M,EAAQC,a,EAAe;AACpC,UAAI,CAACD,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AAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKP,QAAL,CAAckB,MAAd,CAEH,KAAKnB,QAFF,eAGKI,MAHL,8BAGoCQ,oBAHpC,CAAP;AAKD;;;;;;kBAGYjB,K","file":"roles.js","sourcesContent":["import { toSnakeCase, toCamelCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtRole\n * @property {ContxtApplication[]} applications\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} description\n * @property {string} id\n * @property {string} name\n * @property {string} organizationId\n * @property {ContxtProjectEnvironment[]} projectEnvironments\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n/**\n * @typedef {Object} ContxtRoleApplication\n * @property {number} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {number} id\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtRoleProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} userId\n * @property {string} environmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtProjectEnvironment\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} organizationId\n * @property {number} projectId\n * @property {string} clusterId\n * @property {string} slug\n * @property {string} name\n * @property {string} type\n * @property {string} description\n */\n\n/**\n * Module that provides access to contxt roles\n *\n * @typicalname contxtSdk.coordinator.roles\n */\nclass Roles {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(sdk, request, baseUrl, organizationId = null) {\n this._baseUrl = baseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n /**\n * Add an application to a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleApplication}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .then((roleApplication) => console.log(roleApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for adding an application to a role.')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for adding an application to a role.'\n )\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles/${roleId}/applications/${applicationId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Add a project environment to a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: POST\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRoleProjectEnvironment}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((roleProject) => console.log(roleProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(roleId, projectEnvironmentId, accessType) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for adding a project environment to a role.'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a role.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An accessType of \"reader\" or \"admin\" is required for adding a project environment to a role.'\n )\n );\n }\n\n return this._request\n .post(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentId}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Create a new role for an organization\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} role\n * @param {string} role.name The name of the new role\n * @param {string} role.description Some text describing the purpose of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtRole} The newly created role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .create('36b8421a-cc4a-4204-b839-1397374fb16b', {\n * name: 'view-myapp',\n * description: 'Give this role for viewing myapp'\n * })\n * .then((role) => console.log(role))\n * .catch((err) => console.log(err));\n */\n create(organizationId, role = {}) {\n if (this._organizationId) {\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(`${this._baseUrl}/roles`, toSnakeCase(role))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for creating roles for an organization.'\n )\n );\n }\n\n if (!role.name) {\n return Promise.reject(\n new Error(`A name is required to create a new role.`)\n );\n }\n\n if (!role.description) {\n return Promise.reject(\n new Error(`A description is required to create a new role.`)\n );\n }\n\n return this._request\n .post(\n `${this._baseUrl}/organizations/${organizationId}/roles`,\n toSnakeCase(role)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Deletes a role from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles/:roleId'\n * API Endpiont: '/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} roleId The UUID formatted ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles.delete('4f0e51c6-728b-4892-9863-6d002e61204d', '8b64fb12-e649-46be-b330-e672d28eed99s');\n */\n delete(organizationId, roleId) {\n if (this._organizationId) {\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(`${this._baseUrl}/roles/${roleId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organizationId is required for deleting a role.')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A roleId is required for deleting a role.')\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/organizations/${organizationId}/roles/${roleId}`\n );\n }\n\n /**\n * Gets an organization's list of roles\n *\n * Legacy API Endpoint: '/organizations/:organizationId/roles'\n * API Endpoint: '/roles'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtRole[]} A list of roles\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.roles\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((roles) => console.log(roles))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._baseUrl}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organizationId is required for getting roles for an organization.'\n )\n );\n }\n\n return this._request\n .get(`${this._baseUrl}/organizations/${organizationId}/roles`)\n .then((roles) => toCamelCase(roles));\n }\n\n /**\n * Remove an application from a role\n *\n * API Endpoint: '/roles/:roleId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {number} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', 42)\n * .catch((err) => console.log(err));\n */\n removeApplication(roleId, applicationId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing an application from a role.'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An applicationId is required for removing an application from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${this._baseUrl}/roles/${roleId}/applications/${applicationId}`\n );\n }\n\n /**\n * Remove a project environment from a role\n *\n * API Endpoint: 'roles/:roleId/project_environments/:projectEnvironmentSlug'\n * Method: DELETE\n *\n * @param {string} roleId The UUID formatted ID of the role\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.roles\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(roleId, projectEnvironmentId) {\n if (!roleId) {\n return Promise.reject(\n new Error(\n 'A roleId is required for removing a project environment from a role.'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a role.'\n )\n );\n }\n\n return this._request.delete(\n `${\n this._baseUrl\n }/roles/${roleId}/project_environments/${projectEnvironmentId}`\n );\n }\n}\n\nexport default Roles;\n"]}
|
package/lib/coordinator/users.js
CHANGED
|
@@ -249,12 +249,12 @@ var Users = function () {
|
|
|
249
249
|
|
|
250
250
|
}, {
|
|
251
251
|
key: 'addProjectEnvironment',
|
|
252
|
-
value: function addProjectEnvironment(userId,
|
|
252
|
+
value: function addProjectEnvironment(userId, projectEnvironmentId, accessType) {
|
|
253
253
|
if (!userId) {
|
|
254
254
|
return Promise.reject(new Error('A user ID is required for adding a project environment to a user'));
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
if (!
|
|
257
|
+
if (!projectEnvironmentId) {
|
|
258
258
|
return Promise.reject(new Error('A project environment slug is required for adding a project environment to a user.'));
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -262,7 +262,7 @@ var Users = function () {
|
|
|
262
262
|
return Promise.reject(new Error('An access type of "reader" or "admin" is required for adding a project environment to a user'));
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
return this._request.post(this._getBaseUrl() + '/users/' + userId + '/project_environments/' +
|
|
265
|
+
return this._request.post(this._getBaseUrl() + '/users/' + userId + '/project_environments/' + projectEnvironmentId, {
|
|
266
266
|
access_type: accessType
|
|
267
267
|
}).then(function (response) {
|
|
268
268
|
return (0, _objects.toCamelCase)(response);
|
|
@@ -543,16 +543,16 @@ var Users = function () {
|
|
|
543
543
|
|
|
544
544
|
}, {
|
|
545
545
|
key: 'removeProjectEnvironment',
|
|
546
|
-
value: function removeProjectEnvironment(userId,
|
|
546
|
+
value: function removeProjectEnvironment(userId, projectEnvironmentId) {
|
|
547
547
|
if (!userId) {
|
|
548
548
|
return Promise.reject(new Error('A user ID is required for removing a project environment from a user'));
|
|
549
549
|
}
|
|
550
550
|
|
|
551
|
-
if (!
|
|
551
|
+
if (!projectEnvironmentId) {
|
|
552
552
|
return Promise.reject(new Error('A project environment slug is required for removing a project environment from a user.'));
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
-
return this._request.delete(this._getBaseUrl() + '/users/' + userId + '/project_environments/' +
|
|
555
|
+
return this._request.delete(this._getBaseUrl() + '/users/' + userId + '/project_environments/' + projectEnvironmentId);
|
|
556
556
|
}
|
|
557
557
|
|
|
558
558
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["coordinator/users.js"],"names":["Users","sdk","request","baseUrl","tenantBaseUrl","legacyBaseUrl","organizationId","_baseUrl","_tenantBaseUrl","_legacyBaseUrl","_request","_sdk","_organizationId","type","userId","user","Promise","reject","Error","requiredFields","i","length","field","axios","post","_getBaseUrl","applicationId","then","response","roleId","projectEnvironmentSlug","accessType","indexOf","access_type","get","orgUsers","delete"],"mappings":";;;;;;;;AAAA;;;;AAEA;;;;;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;;AASA;;;;;;;;;;AAUA;;;;;;;;;;AAUA;;;;;IAKMA,K;AACJ;;;;;;;;AAQA,iBACEC,GAD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,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAc0B,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BX,MAD1B,eAC0Ce,MAD1C,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;6CAkByBf,M,EAAQgB,sB,EAAwB;AACvD,UAAI,CAAChB,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACY,sBAAL,EAA6B;AAC3B,eAAOd,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKR,QAAL,CAAc0B,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BX,MAD1B,8BACyDgB,sBADzD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;yBAiBKhB,M,EAAQ;AACX,UAAI,CAACA,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,oDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAcwB,GAAd,CACF,KAAKT,WAAL,CAAiB,QAAjB,CADE,eACkCX,MADlC,WAAP;AAGD;;;;;;kBAGYd,K","file":"users.js","sourcesContent":["import axios from 'axios';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtUser\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} email\n * @property {string} firstName\n * @property {string} id\n * @property {boolean} isActivated\n * @property {boolean} isSuperuser\n * @property {string} lastName\n * @property {string} [phoneNumber]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserApplication\n * @property {string} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserRole\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {boolean} mappedFromExternalGroup\n * @property {string} userId\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} projectEnvironmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to contxt users\n *\n * @typicalname contxtSdk.coordinator.users\n */\nclass Users {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [tenantBaseUrl] The tenant base URL provided by the parent module\n * @param {string} [legacyBaseUrl] The legacy base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(\n sdk,\n request,\n baseUrl,\n tenantBaseUrl = null,\n legacyBaseUrl = null,\n organizationId = null\n ) {\n this._baseUrl = baseUrl;\n this._tenantBaseUrl = tenantBaseUrl;\n this._legacyBaseUrl = legacyBaseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n _getBaseUrl(type) {\n switch (type) {\n case 'legacy':\n return this._legacyBaseUrl || this._baseUrl;\n\n case 'access':\n return this._baseUrl;\n\n default:\n return this._tenantBaseUrl || this._baseUrl;\n }\n }\n\n /**\n * Activates a new user\n *\n * API Endpoint: '/users/:userId/activate'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} userId The ID of the user to activate\n * @param {Object} user\n * @param {string} user.email The email address of the user\n * @param {string} user.password The password to set for the user\n * @param {string} user.userToken The JWT token provided by the invite link\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .activate('7bb79bdf-7492-45c2-8640-2dde63535827', {\n * email: 'bob.sagat56@gmail.com',\n * password: 'ds32jX32jaMM1Nr',\n * userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'\n * })\n * .then(() => console.log(\"User Activated\"))\n * .catch((err) => console.log(err));\n */\n activate(userId, user = {}) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for activating a user')\n );\n }\n\n const requiredFields = ['email', 'password', 'userToken'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to activate a user.`)\n );\n }\n }\n\n // Uses axios directly instead of this.request to bypass authorization interceptors\n return axios.post(\n `${this._getBaseUrl('access')}/users/${userId}/activate`,\n toSnakeCase(user)\n );\n }\n\n /**\n * Adds a application to a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtUserApplication} The newly created user application\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userApplication) => console.log(userApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a application to a user')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for adding a application to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a role to a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtUserRole} The newly created user role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userRole) => console.log(userRole))\n * .catch((err) => console.log(err));\n */\n addRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a role to a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for adding a role to a user')\n );\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users/${userId}/roles/${roleId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a project environment to a user\n *\n * API Endpoint: '/users/:userId/project_environments/:projectEnvironmentSlug\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUserProjectEnvironment} The newly created user project environment\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((userProject) => console.log(userProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(userId, projectEnvironmentSlug, accessType) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for adding a project environment to a user'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a user.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An access type of \"reader\" or \"admin\" is required for adding a project environment to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentSlug}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Gets information about a contxt user\n *\n * API Endpoint: '/users/:userId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} Information about a contxt user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .get('auth0|12345')\n * .then((user) => console.log(user))\n * .catch((err) => console.log(err));\n */\n get(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for getting information about a user')\n );\n }\n\n return this._request\n .get(`${this._getBaseUrl('access')}/users/${userId}`)\n .then((user) => toCamelCase(user));\n }\n\n /**\n * Gets a list of users for a contxt organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtUser[]} List of users for a contxt organization\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((orgUsers) => console.log(orgUsers))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._getBaseUrl()}/users`)\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for getting a list of users for an organization'\n )\n );\n }\n\n return this._request\n .get(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`\n )\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n /**\n * Creates a new contxt user, adds them to an organization, and\n * sends them an email invite link to do final account setup.\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} user\n * @param {string} user.email The email address of the new user\n * @param {string} user.firstName The first name of the new user\n * @param {string} user.lastName The last name of the new user\n * @param {string} user.redirectUrl The url that the user will be redirected\n * to after using the invite email link. Typically this is an /activate\n * endpoint that accepts url query params userToken and userId and uses them\n * to do final activation on the user's account.\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} The new user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .invite('fdf01507-a26a-4dfe-89a2-bc91861169b8', {\n * email: 'bob.sagat56@gmail.com',\n * firstName: 'Bob',\n * lastName: 'Sagat',\n * redirectUrl: 'https://contxt.ndustrial.io/activate'\n * })\n * .then((newUser) => console.log(newUser))\n * .catch((err) => console.log(err));\n */\n invite(organizationId, user = {}) {\n if (this._organizationId) {\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users`, toSnakeCase(user))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organization ID is required for inviting a new user')\n );\n }\n\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`,\n toSnakeCase(user)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Removes a user from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users/:userId'\n * API Endpoint: '/users/:userId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .remove('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52')\n * .catch((err) => console.log(err));\n */\n remove(organizationId, userId) {\n if (this._organizationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(`${this._getBaseUrl()}/users/${userId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for removing a user from an organization'\n )\n );\n }\n\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl(\n 'legacy'\n )}/organizations/${organizationId}/users/${userId}`\n );\n }\n\n /**\n * Removes a application from a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a application from a user'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for removing a application from a user'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n );\n }\n\n /**\n * Removes a role from a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for removing a role from a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for removing a role from a user')\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/roles/${roleId}`\n );\n }\n\n /**\n * Removes a project environment from a user\n *\n * API Endpoint: 'users/:userId/project_environments/:projectEnvironmentSlug\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(userId, projectEnvironmentSlug) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a project environment from a user'\n )\n );\n }\n\n if (!projectEnvironmentSlug) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a user.'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentSlug}`\n );\n }\n\n /**\n * Syncs the user's roles and application access with the external auth provider\n *\n * API Endpoint: '/users/:userId/sync'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .sync('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .catch((err) => console.log(err));\n */\n sync(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for syncing user permissions')\n );\n }\n\n return this._request.get(\n `${this._getBaseUrl('access')}/users/${userId}/sync`\n );\n }\n}\n\nexport default Users;\n"]}
|
|
1
|
+
{"version":3,"sources":["coordinator/users.js"],"names":["Users","sdk","request","baseUrl","tenantBaseUrl","legacyBaseUrl","organizationId","_baseUrl","_tenantBaseUrl","_legacyBaseUrl","_request","_sdk","_organizationId","type","userId","user","Promise","reject","Error","requiredFields","i","length","field","axios","post","_getBaseUrl","applicationId","then","response","roleId","projectEnvironmentId","accessType","indexOf","access_type","get","orgUsers","delete"],"mappings":";;;;;;;;AAAA;;;;AAEA;;;;;;AAEA;;;;;;;;;;;;;AAaA;;;;;;;;;AASA;;;;;;;;;;AAUA;;;;;;;;;;AAUA;;;;;IAKMA,K;AACJ;;;;;;;;AAQA,iBACEC,GADF,EAEEC,OAFF,EAGEC,OAHF,EAOE;AAAA,QAHAC,aAGA,uEAHgB,IAGhB;AAAA,QAFAC,aAEA,uEAFgB,IAEhB;AAAA,QADAC,cACA,uEADiB,IACjB;;AAAA;;AACA,SAAKC,QAAL,GAAgBJ,OAAhB;AACA,SAAKK,cAAL,GAAsBJ,aAAtB;AACA,SAAKK,cAAL,GAAsBJ,aAAtB;AACA,SAAKK,QAAL,GAAgBR,OAAhB;AACA,SAAKS,IAAL,GAAYV,GAAZ;AACA,SAAKW,eAAL,GAAuBN,cAAvB;AACD;;;;gCAEWO,I,EAAM;AAChB,cAAQA,IAAR;AACE,aAAK,QAAL;AACE,iBAAO,KAAKJ,cAAL,IAAuB,KAAKF,QAAnC;;AAEF,aAAK,QAAL;AACE,iBAAO,KAAKA,QAAZ;;AAEF;AACE,iBAAO,KAAKC,cAAL,IAAuB,KAAKD,QAAnC;AARJ;AAUD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA4BSO,M,EAAmB;AAAA,UAAXC,IAAW,uEAAJ,EAAI;;AAC1B,UAAI,CAACD,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,6CAAV,CADK,CAAP;AAGD;;AAED,UAAMC,iBAAiB,CAAC,OAAD,EAAU,UAAV,EAAsB,WAAtB,CAAvB;;AAEA,WAAK,IAAIC,IAAI,CAAb,EAAgBD,eAAeE,MAAf,GAAwBD,CAAxC,EAA2CA,GA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AP;AAKD;;AAED,aAAO,KAAKR,QAAL,CAAc0B,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BX,MAD1B,sBACiDY,aADjD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;+BAkBWZ,M,EAAQe,M,EAAQ;AACzB,UAAI,CAACf,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,UAAI,CAACW,MAAL,EAAa;AACX,eAAOb,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,uDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAc0B,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BX,MAD1B,eAC0Ce,MAD1C,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;;6CAkByBf,M,EAAQgB,oB,EAAsB;AACrD,UAAI,CAAChB,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,sEADF,CADK,CAAP;AAKD;;AAED,UAAI,CAACY,oBAAL,EAA2B;AACzB,eAAOd,QAAQC,MAAR,CACL,IAAIC,KAAJ,CACE,wFADF,CADK,CAAP;AAKD;;AAED,aAAO,KAAKR,QAAL,CAAc0B,MAAd,CACF,KAAKX,WAAL,EADE,eAC0BX,MAD1B,8BACyDgB,oBADzD,CAAP;AAGD;;AAED;;;;;;;;;;;;;;;;;;;;yBAiBKhB,M,EAAQ;AACX,UAAI,CAACA,MAAL,EAAa;AACX,eAAOE,QAAQC,MAAR,CACL,IAAIC,KAAJ,CAAU,oDAAV,CADK,CAAP;AAGD;;AAED,aAAO,KAAKR,QAAL,CAAcwB,GAAd,CACF,KAAKT,WAAL,CAAiB,QAAjB,CADE,eACkCX,MADlC,WAAP;AAGD;;;;;;kBAGYd,K","file":"users.js","sourcesContent":["import axios from 'axios';\n\nimport { toCamelCase, toSnakeCase } from '../utils/objects';\n\n/**\n * @typedef {Object} ContxtUser\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} email\n * @property {string} firstName\n * @property {string} id\n * @property {boolean} isActivated\n * @property {boolean} isSuperuser\n * @property {string} lastName\n * @property {string} [phoneNumber]\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserApplication\n * @property {string} applicationId\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserRole\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {boolean} mappedFromExternalGroup\n * @property {string} userId\n * @property {string} roleId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * @typedef {Object} ContxtUserProjectEnvironment\n * @property {string} accessType Access Type of the user for this project with options \"reader\", \"admin\"\n * @property {string} createdAt ISO 8601 Extended Format date/time string\n * @property {string} id\n * @property {string} userId\n * @property {string} projectEnvironmentId\n * @property {string} updatedAt ISO 8601 Extended Format date/time string\n */\n\n/**\n * Module that provides access to contxt users\n *\n * @typicalname contxtSdk.coordinator.users\n */\nclass Users {\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 * @param {string} baseUrl The base URL provided by the parent module\n * @param {string} [tenantBaseUrl] The tenant base URL provided by the parent module\n * @param {string} [legacyBaseUrl] The legacy base URL provided by the parent module\n * @param {string} [organizationId] The organization ID to be used in tenant url requests\n */\n constructor(\n sdk,\n request,\n baseUrl,\n tenantBaseUrl = null,\n legacyBaseUrl = null,\n organizationId = null\n ) {\n this._baseUrl = baseUrl;\n this._tenantBaseUrl = tenantBaseUrl;\n this._legacyBaseUrl = legacyBaseUrl;\n this._request = request;\n this._sdk = sdk;\n this._organizationId = organizationId;\n }\n\n _getBaseUrl(type) {\n switch (type) {\n case 'legacy':\n return this._legacyBaseUrl || this._baseUrl;\n\n case 'access':\n return this._baseUrl;\n\n default:\n return this._tenantBaseUrl || this._baseUrl;\n }\n }\n\n /**\n * Activates a new user\n *\n * API Endpoint: '/users/:userId/activate'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} userId The ID of the user to activate\n * @param {Object} user\n * @param {string} user.email The email address of the user\n * @param {string} user.password The password to set for the user\n * @param {string} user.userToken The JWT token provided by the invite link\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .activate('7bb79bdf-7492-45c2-8640-2dde63535827', {\n * email: 'bob.sagat56@gmail.com',\n * password: 'ds32jX32jaMM1Nr',\n * userToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'\n * })\n * .then(() => console.log(\"User Activated\"))\n * .catch((err) => console.log(err));\n */\n activate(userId, user = {}) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for activating a user')\n );\n }\n\n const requiredFields = ['email', 'password', 'userToken'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to activate a user.`)\n );\n }\n }\n\n // Uses axios directly instead of this.request to bypass authorization interceptors\n return axios.post(\n `${this._getBaseUrl('access')}/users/${userId}/activate`,\n toSnakeCase(user)\n );\n }\n\n /**\n * Adds a application to a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {ContxtUserApplication} The newly created user application\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userApplication) => console.log(userApplication))\n * .catch((err) => console.log(err));\n */\n addApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a application to a user')\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for adding a application to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a role to a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {ContxtUserRole} The newly created user role\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .then((userRole) => console.log(userRole))\n * .catch((err) => console.log(err));\n */\n addRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for adding a role to a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for adding a role to a user')\n );\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users/${userId}/roles/${roleId}`)\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Adds a project environment to a user\n *\n * API Endpoint: '/users/:userId/project_environments/:projectEnvironmentSlug\n * Method: POST\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n * @param {'reader' | 'admin'} accessType The level of access for the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUserProjectEnvironment} The newly created user project environment\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .addProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug', 'admin')\n * .then((userProject) => console.log(userProject))\n * .catch((err) => console.log(err));\n */\n addProjectEnvironment(userId, projectEnvironmentId, accessType) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for adding a project environment to a user'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for adding a project environment to a user.'\n )\n );\n }\n\n if (['reader', 'admin'].indexOf(accessType) === -1) {\n return Promise.reject(\n new Error(\n 'An access type of \"reader\" or \"admin\" is required for adding a project environment to a user'\n )\n );\n }\n\n return this._request\n .post(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`,\n {\n access_type: accessType\n }\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Gets information about a contxt user\n *\n * API Endpoint: '/users/:userId'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} Information about a contxt user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .get('auth0|12345')\n * .then((user) => console.log(user))\n * .catch((err) => console.log(err));\n */\n get(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for getting information about a user')\n );\n }\n\n return this._request\n .get(`${this._getBaseUrl('access')}/users/${userId}`)\n .then((user) => toCamelCase(user));\n }\n\n /**\n * Gets a list of users for a contxt organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: GET\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n *\n * @returns {Promise}\n * @fulfill {ContxtUser[]} List of users for a contxt organization\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .getByOrganizationId('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .then((orgUsers) => console.log(orgUsers))\n * .catch((err) => console.log(err));\n */\n getByOrganizationId(organizationId) {\n if (this._organizationId) {\n return this._request\n .get(`${this._getBaseUrl()}/users`)\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for getting a list of users for an organization'\n )\n );\n }\n\n return this._request\n .get(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`\n )\n .then((orgUsers) => toCamelCase(orgUsers));\n }\n\n /**\n * Creates a new contxt user, adds them to an organization, and\n * sends them an email invite link to do final account setup.\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users'\n * API Endpoint: '/users'\n * Method: POST\n *\n * Note: Only valid for web users using auth0WebAuth session type\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {Object} user\n * @param {string} user.email The email address of the new user\n * @param {string} user.firstName The first name of the new user\n * @param {string} user.lastName The last name of the new user\n * @param {string} user.redirectUrl The url that the user will be redirected\n * to after using the invite email link. Typically this is an /activate\n * endpoint that accepts url query params userToken and userId and uses them\n * to do final activation on the user's account.\n *\n * @returns {Promise}\n * @fulfill {ContxtUser} The new user\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .invite('fdf01507-a26a-4dfe-89a2-bc91861169b8', {\n * email: 'bob.sagat56@gmail.com',\n * firstName: 'Bob',\n * lastName: 'Sagat',\n * redirectUrl: 'https://contxt.ndustrial.io/activate'\n * })\n * .then((newUser) => console.log(newUser))\n * .catch((err) => console.log(err));\n */\n invite(organizationId, user = {}) {\n if (this._organizationId) {\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(`${this._getBaseUrl()}/users`, toSnakeCase(user))\n .then((response) => toCamelCase(response));\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error('An organization ID is required for inviting a new user')\n );\n }\n\n const requiredFields = ['email', 'firstName', 'lastName', 'redirectUrl'];\n\n for (let i = 0; requiredFields.length > i; i++) {\n const field = requiredFields[i];\n\n if (!user[field]) {\n return Promise.reject(\n new Error(`A ${field} is required to create a new user.`)\n );\n }\n }\n\n return this._request\n .post(\n `${this._getBaseUrl('legacy')}/organizations/${organizationId}/users`,\n toSnakeCase(user)\n )\n .then((response) => toCamelCase(response));\n }\n\n /**\n * Removes a user from an organization\n *\n * Legacy API Endpoint: '/organizations/:organizationId/users/:userId'\n * API Endpoint: '/users/:userId'\n * Method: DELETE\n *\n * @param {string} organizationId The ID of the organization, optional when using the tenant API and an organization ID has been set\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .remove('ed2e8e24-79ef-4404-bf5f-995ef31b2298', '4a577e87-7437-4342-b183-00c18ec26d52')\n * .catch((err) => console.log(err));\n */\n remove(organizationId, userId) {\n if (this._organizationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(`${this._getBaseUrl()}/users/${userId}`);\n }\n\n if (!organizationId) {\n return Promise.reject(\n new Error(\n 'An organization ID is required for removing a user from an organization'\n )\n );\n }\n\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a user from an organization'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl(\n 'legacy'\n )}/organizations/${organizationId}/users/${userId}`\n );\n }\n\n /**\n * Removes a application from a user\n *\n * API Endpoint: '/users/:userId/applications/:applicationId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} applicationId The ID of the application\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeApplication('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeApplication(userId, applicationId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a application from a user'\n )\n );\n }\n\n if (!applicationId) {\n return Promise.reject(\n new Error(\n 'An application ID is required for removing a application from a user'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/applications/${applicationId}`\n );\n }\n\n /**\n * Removes a role from a user\n *\n * API Endpoint: '/users/:userId/roles/:roleId'\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} roleId The ID of the role\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeRole('36b8421a-cc4a-4204-b839-1397374fb16b', '007ca9ee-ece7-4931-9d11-9b4fd97d4d58')\n * .catch((err) => console.log(err));\n */\n removeRole(userId, roleId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for removing a role from a user')\n );\n }\n\n if (!roleId) {\n return Promise.reject(\n new Error('A role ID is required for removing a role from a user')\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/roles/${roleId}`\n );\n }\n\n /**\n * Removes a project environment from a user\n *\n * API Endpoint: 'users/:userId/project_environments/:projectEnvironmentSlug\n * Method: DELETE\n *\n * @param {string} userId The ID of the user\n * @param {string} projectEnvironmentSlug The slug of the project environment\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')\n * .catch((err) => console.log(err));\n */\n removeProjectEnvironment(userId, projectEnvironmentId) {\n if (!userId) {\n return Promise.reject(\n new Error(\n 'A user ID is required for removing a project environment from a user'\n )\n );\n }\n\n if (!projectEnvironmentId) {\n return Promise.reject(\n new Error(\n 'A project environment slug is required for removing a project environment from a user.'\n )\n );\n }\n\n return this._request.delete(\n `${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`\n );\n }\n\n /**\n * Syncs the user's roles and application access with the external auth provider\n *\n * API Endpoint: '/users/:userId/sync'\n * Method: GET\n *\n * @param {string} userId The ID of the user\n *\n * @returns {Promise}\n * @fulfill {undefined}\n * @reject {Error}\n *\n * @example\n * contxtSdk.coordinator.users\n * .sync('36b8421a-cc4a-4204-b839-1397374fb16b')\n * .catch((err) => console.log(err));\n */\n sync(userId) {\n if (!userId) {\n return Promise.reject(\n new Error('A user ID is required for syncing user permissions')\n );\n }\n\n return this._request.get(\n `${this._getBaseUrl('access')}/users/${userId}/sync`\n );\n }\n}\n\nexport default Users;\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndustrial/contxt-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
7
10
|
"browser": {
|
|
8
11
|
"./esm/bus/index.js": "./esm/bus/index.browser.js",
|
|
9
12
|
"./lib/bus/index.js": "./lib/bus/index.browser.js",
|
|
@@ -102,4 +105,4 @@
|
|
|
102
105
|
"sinon": "^7.3.2",
|
|
103
106
|
"sinon-chai": "^3.2.0"
|
|
104
107
|
}
|
|
105
|
-
}
|
|
108
|
+
}
|
package/src/config/audiences.js
CHANGED
|
@@ -27,14 +27,14 @@ export default {
|
|
|
27
27
|
host: 'https://contxt.api.ndustrial.io'
|
|
28
28
|
},
|
|
29
29
|
staging: {
|
|
30
|
-
clientId: '
|
|
31
|
-
host: 'https://contxt-staging.
|
|
30
|
+
clientId: 'qGzdTXcmB57zlTp86rYsivG9qEss1lbF',
|
|
31
|
+
host: 'https://contxt-api.staging.ndustrial.io'
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
events: {
|
|
35
35
|
staging: {
|
|
36
36
|
clientId: 'dn4MaocJFdKtsBy9sFFaTeuJWL1nt5xu',
|
|
37
|
-
host: 'https://events
|
|
37
|
+
host: 'https://events.api.staging.ndustrial.io'
|
|
38
38
|
},
|
|
39
39
|
production: {
|
|
40
40
|
clientId: '7jzwfE20O2XZ4aq3cO1wmk63G9GzNc8j',
|
|
@@ -58,7 +58,7 @@ export default {
|
|
|
58
58
|
},
|
|
59
59
|
staging: {
|
|
60
60
|
clientId: 'SLE310LY4nDT5p06sUGPVOLlGXk5osbQ',
|
|
61
|
-
host: 'https://files
|
|
61
|
+
host: 'https://files.api.staging.ndustrial.io'
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
health: {
|
package/src/coordinator/roles.js
CHANGED
|
@@ -121,7 +121,7 @@ class Roles {
|
|
|
121
121
|
* .then((roleProject) => console.log(roleProject))
|
|
122
122
|
* .catch((err) => console.log(err));
|
|
123
123
|
*/
|
|
124
|
-
addProjectEnvironment(roleId,
|
|
124
|
+
addProjectEnvironment(roleId, projectEnvironmentId, accessType) {
|
|
125
125
|
if (!roleId) {
|
|
126
126
|
return Promise.reject(
|
|
127
127
|
new Error(
|
|
@@ -130,7 +130,7 @@ class Roles {
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
if (!
|
|
133
|
+
if (!projectEnvironmentId) {
|
|
134
134
|
return Promise.reject(
|
|
135
135
|
new Error(
|
|
136
136
|
'A project environment slug is required for adding a project environment to a role.'
|
|
@@ -150,7 +150,7 @@ class Roles {
|
|
|
150
150
|
.post(
|
|
151
151
|
`${
|
|
152
152
|
this._baseUrl
|
|
153
|
-
}/roles/${roleId}/project_environments/${
|
|
153
|
+
}/roles/${roleId}/project_environments/${projectEnvironmentId}`,
|
|
154
154
|
{
|
|
155
155
|
access_type: accessType
|
|
156
156
|
}
|
|
@@ -368,7 +368,7 @@ class Roles {
|
|
|
368
368
|
* .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')
|
|
369
369
|
* .catch((err) => console.log(err));
|
|
370
370
|
*/
|
|
371
|
-
removeProjectEnvironment(roleId,
|
|
371
|
+
removeProjectEnvironment(roleId, projectEnvironmentId) {
|
|
372
372
|
if (!roleId) {
|
|
373
373
|
return Promise.reject(
|
|
374
374
|
new Error(
|
|
@@ -377,7 +377,7 @@ class Roles {
|
|
|
377
377
|
);
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
-
if (!
|
|
380
|
+
if (!projectEnvironmentId) {
|
|
381
381
|
return Promise.reject(
|
|
382
382
|
new Error(
|
|
383
383
|
'A project environment slug is required for removing a project environment from a role.'
|
|
@@ -388,7 +388,7 @@ class Roles {
|
|
|
388
388
|
return this._request.delete(
|
|
389
389
|
`${
|
|
390
390
|
this._baseUrl
|
|
391
|
-
}/roles/${roleId}/project_environments/${
|
|
391
|
+
}/roles/${roleId}/project_environments/${projectEnvironmentId}`
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
394
|
}
|
|
@@ -199,7 +199,7 @@ describe('Coordinator/Roles', function() {
|
|
|
199
199
|
const roles = new Roles(baseSdk, request, expectedHost);
|
|
200
200
|
promise = roles.addProjectEnvironment(
|
|
201
201
|
role.id,
|
|
202
|
-
projectEnvironment.
|
|
202
|
+
projectEnvironment.id,
|
|
203
203
|
expectedRoleProjectEnvironment.accessType
|
|
204
204
|
);
|
|
205
205
|
});
|
|
@@ -207,7 +207,7 @@ describe('Coordinator/Roles', function() {
|
|
|
207
207
|
it('posts the role project environment to the server', function() {
|
|
208
208
|
expect(request.post).to.be.calledWith(
|
|
209
209
|
`${expectedHost}/roles/${role.id}/project_environments/${
|
|
210
|
-
projectEnvironment.
|
|
210
|
+
projectEnvironment.id
|
|
211
211
|
}`,
|
|
212
212
|
{
|
|
213
213
|
access_type: expectedRoleProjectEnvironment.accessType
|
|
@@ -241,7 +241,7 @@ describe('Coordinator/Roles', function() {
|
|
|
241
241
|
const roles = new Roles(baseSdk, baseRequest, expectedHost);
|
|
242
242
|
const promise = roles.addProjectEnvironment(
|
|
243
243
|
null,
|
|
244
|
-
projectEnvironment.
|
|
244
|
+
projectEnvironment.id,
|
|
245
245
|
roleProjectEnvironment.accessType
|
|
246
246
|
);
|
|
247
247
|
|
|
@@ -277,7 +277,7 @@ describe('Coordinator/Roles', function() {
|
|
|
277
277
|
const roles = new Roles(baseSdk, baseRequest, expectedHost);
|
|
278
278
|
const promise = roles.addProjectEnvironment(
|
|
279
279
|
role.id,
|
|
280
|
-
projectEnvironment.
|
|
280
|
+
projectEnvironment.id,
|
|
281
281
|
null
|
|
282
282
|
);
|
|
283
283
|
|
|
@@ -295,7 +295,7 @@ describe('Coordinator/Roles', function() {
|
|
|
295
295
|
const roles = new Roles(baseSdk, baseRequest, expectedHost);
|
|
296
296
|
const promise = roles.addProjectEnvironment(
|
|
297
297
|
role.id,
|
|
298
|
-
projectEnvironment.
|
|
298
|
+
projectEnvironment.id,
|
|
299
299
|
faker.random.word()
|
|
300
300
|
);
|
|
301
301
|
|
|
@@ -900,14 +900,14 @@ describe('Coordinator/Roles', function() {
|
|
|
900
900
|
const roles = new Roles(baseSdk, baseRequest, expectedHost);
|
|
901
901
|
promise = roles.removeProjectEnvironment(
|
|
902
902
|
role.id,
|
|
903
|
-
projectEnvironment.
|
|
903
|
+
projectEnvironment.id
|
|
904
904
|
);
|
|
905
905
|
});
|
|
906
906
|
|
|
907
907
|
it('sends a request to remove the project environment role role from the organization', function() {
|
|
908
908
|
expect(baseRequest.delete).to.be.calledWith(
|
|
909
909
|
`${expectedHost}/roles/${role.id}/project_environments/${
|
|
910
|
-
projectEnvironment.
|
|
910
|
+
projectEnvironment.id
|
|
911
911
|
}`
|
|
912
912
|
);
|
|
913
913
|
});
|
|
@@ -923,7 +923,7 @@ describe('Coordinator/Roles', function() {
|
|
|
923
923
|
const roles = new Roles(baseSdk, baseRequest, expectedHost);
|
|
924
924
|
const promise = roles.removeProjectEnvironment(
|
|
925
925
|
null,
|
|
926
|
-
projectEnvironment.
|
|
926
|
+
projectEnvironment.id
|
|
927
927
|
);
|
|
928
928
|
|
|
929
929
|
return expect(promise).to.be.rejectedWith(
|
package/src/coordinator/users.js
CHANGED
|
@@ -239,7 +239,7 @@ class Users {
|
|
|
239
239
|
* .then((userProject) => console.log(userProject))
|
|
240
240
|
* .catch((err) => console.log(err));
|
|
241
241
|
*/
|
|
242
|
-
addProjectEnvironment(userId,
|
|
242
|
+
addProjectEnvironment(userId, projectEnvironmentId, accessType) {
|
|
243
243
|
if (!userId) {
|
|
244
244
|
return Promise.reject(
|
|
245
245
|
new Error(
|
|
@@ -248,7 +248,7 @@ class Users {
|
|
|
248
248
|
);
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
-
if (!
|
|
251
|
+
if (!projectEnvironmentId) {
|
|
252
252
|
return Promise.reject(
|
|
253
253
|
new Error(
|
|
254
254
|
'A project environment slug is required for adding a project environment to a user.'
|
|
@@ -266,7 +266,7 @@ class Users {
|
|
|
266
266
|
|
|
267
267
|
return this._request
|
|
268
268
|
.post(
|
|
269
|
-
`${this._getBaseUrl()}/users/${userId}/project_environments/${
|
|
269
|
+
`${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`,
|
|
270
270
|
{
|
|
271
271
|
access_type: accessType
|
|
272
272
|
}
|
|
@@ -574,7 +574,7 @@ class Users {
|
|
|
574
574
|
* .removeProjectEnvironment('36b8421a-cc4a-4204-b839-1397374fb16b', 'project-environment-slug')
|
|
575
575
|
* .catch((err) => console.log(err));
|
|
576
576
|
*/
|
|
577
|
-
removeProjectEnvironment(userId,
|
|
577
|
+
removeProjectEnvironment(userId, projectEnvironmentId) {
|
|
578
578
|
if (!userId) {
|
|
579
579
|
return Promise.reject(
|
|
580
580
|
new Error(
|
|
@@ -583,7 +583,7 @@ class Users {
|
|
|
583
583
|
);
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
-
if (!
|
|
586
|
+
if (!projectEnvironmentId) {
|
|
587
587
|
return Promise.reject(
|
|
588
588
|
new Error(
|
|
589
589
|
'A project environment slug is required for removing a project environment from a user.'
|
|
@@ -592,7 +592,7 @@ class Users {
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
return this._request.delete(
|
|
595
|
-
`${this._getBaseUrl()}/users/${userId}/project_environments/${
|
|
595
|
+
`${this._getBaseUrl()}/users/${userId}/project_environments/${projectEnvironmentId}`
|
|
596
596
|
);
|
|
597
597
|
}
|
|
598
598
|
|
|
@@ -491,7 +491,7 @@ describe('Coordinator/Users', function() {
|
|
|
491
491
|
|
|
492
492
|
promise = users.addProjectEnvironment(
|
|
493
493
|
user.id,
|
|
494
|
-
projectEnvironment.
|
|
494
|
+
projectEnvironment.id,
|
|
495
495
|
expectedUserProjectEnvironment.accessType
|
|
496
496
|
);
|
|
497
497
|
});
|
|
@@ -503,7 +503,7 @@ describe('Coordinator/Users', function() {
|
|
|
503
503
|
it('posts the user project to the server', function() {
|
|
504
504
|
expect(request.post).to.be.calledWith(
|
|
505
505
|
`${expectedTenantBaseUrl}/users/${user.id}/project_environments/${
|
|
506
|
-
projectEnvironment.
|
|
506
|
+
projectEnvironment.id
|
|
507
507
|
}`,
|
|
508
508
|
{
|
|
509
509
|
access_type: expectedUserProjectEnvironment.accessType
|
|
@@ -535,7 +535,7 @@ describe('Coordinator/Users', function() {
|
|
|
535
535
|
const users = new Users(baseSdk, baseRequest, expectedTenantBaseUrl);
|
|
536
536
|
const promise = users.addProjectEnvironment(
|
|
537
537
|
null,
|
|
538
|
-
projectEnvironment.
|
|
538
|
+
projectEnvironment.id,
|
|
539
539
|
userProjectEnvironment.accessType
|
|
540
540
|
);
|
|
541
541
|
|
|
@@ -571,7 +571,7 @@ describe('Coordinator/Users', function() {
|
|
|
571
571
|
const users = new Users(baseSdk, baseRequest, expectedTenantBaseUrl);
|
|
572
572
|
const promise = users.addProjectEnvironment(
|
|
573
573
|
user.id,
|
|
574
|
-
projectEnvironment.
|
|
574
|
+
projectEnvironment.id,
|
|
575
575
|
null
|
|
576
576
|
);
|
|
577
577
|
|
|
@@ -588,7 +588,7 @@ describe('Coordinator/Users', function() {
|
|
|
588
588
|
const users = new Users(baseSdk, baseRequest, expectedTenantBaseUrl);
|
|
589
589
|
const promise = users.addProjectEnvironment(
|
|
590
590
|
user.id,
|
|
591
|
-
projectEnvironment.
|
|
591
|
+
projectEnvironment.id,
|
|
592
592
|
faker.random.word()
|
|
593
593
|
);
|
|
594
594
|
|
|
@@ -1339,7 +1339,7 @@ describe('Coordinator/Users', function() {
|
|
|
1339
1339
|
|
|
1340
1340
|
promise = users.removeProjectEnvironment(
|
|
1341
1341
|
user.id,
|
|
1342
|
-
projectEnvironment.
|
|
1342
|
+
projectEnvironment.id
|
|
1343
1343
|
);
|
|
1344
1344
|
});
|
|
1345
1345
|
|
|
@@ -1350,7 +1350,7 @@ describe('Coordinator/Users', function() {
|
|
|
1350
1350
|
it('sends a request to removeProjectEnvironment the user from the organization', function() {
|
|
1351
1351
|
expect(baseRequest.delete).to.be.calledWith(
|
|
1352
1352
|
`${expectedTenantBaseUrl}/users/${user.id}/project_environments/${
|
|
1353
|
-
projectEnvironment.
|
|
1353
|
+
projectEnvironment.id
|
|
1354
1354
|
}`
|
|
1355
1355
|
);
|
|
1356
1356
|
});
|
|
@@ -1366,7 +1366,7 @@ describe('Coordinator/Users', function() {
|
|
|
1366
1366
|
const users = new Users(baseSdk, baseRequest, expectedTenantBaseUrl);
|
|
1367
1367
|
const promise = users.removeProjectEnvironment(
|
|
1368
1368
|
null,
|
|
1369
|
-
projectEnvironment.
|
|
1369
|
+
projectEnvironment.id
|
|
1370
1370
|
);
|
|
1371
1371
|
|
|
1372
1372
|
return expect(promise).to.be.rejectedWith(
|