@ndustrial/contxt-sdk 4.1.1 → 4.3.4
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/.envrc +0 -0
- package/.nvmrc +1 -1
- package/CHANGELOG.md +19 -1
- package/README.md +2 -12
- package/docs/Typedefs.md +1 -0
- package/esm/config/audiences.js +4 -4
- package/esm/config/audiences.js.map +1 -1
- package/esm/config/defaults.js +1 -0
- package/esm/config/defaults.js.map +1 -1
- package/esm/config/index.js +2 -0
- package/esm/config/index.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/esm/sessionTypes/auth0WebAuth.js +1 -1
- package/esm/sessionTypes/auth0WebAuth.js.map +1 -1
- package/esm/sessionTypes/passwordGrantAuth.js +1 -1
- package/esm/sessionTypes/passwordGrantAuth.js.map +1 -1
- package/lib/config/audiences.js +4 -4
- package/lib/config/audiences.js.map +1 -1
- package/lib/config/defaults.js +1 -0
- package/lib/config/defaults.js.map +1 -1
- package/lib/config/index.js +2 -0
- package/lib/config/index.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/lib/sessionTypes/auth0WebAuth.js +1 -1
- package/lib/sessionTypes/auth0WebAuth.js.map +1 -1
- package/lib/sessionTypes/passwordGrantAuth.js +1 -1
- package/lib/sessionTypes/passwordGrantAuth.js.map +1 -1
- package/package.json +5 -2
- package/src/config/audiences.js +4 -4
- package/src/config/defaults.js +1 -0
- package/src/config/index.js +2 -0
- 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/src/sessionTypes/auth0WebAuth.js +1 -1
- package/src/sessionTypes/auth0WebAuth.spec.js +17 -1
- package/src/sessionTypes/passwordGrantAuth.js +1 -1
- package/src/sessionTypes/passwordGrantAuth.spec.js +2 -1
- package/tmp/package.json +11 -0
- package/.idea/codeStyles/Project.xml +0 -49
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/contxt-sdk-js.iml +0 -15
- package/.idea/inspectionProfiles/Project_Default.xml +0 -7
- package/.idea/inspectionProfiles/profiles_settings.xml +0 -6
- package/.idea/misc.xml +0 -4
- package/.idea/modules.xml +0 -9
- package/.idea/vcs.xml +0 -6
package/.envrc
ADDED
|
File without changes
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v14.
|
|
1
|
+
v14.19.0
|
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
## [v4.
|
|
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
|
+
|
|
13
|
+
## [v4.1.2](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.1.2) (2021-02-12)
|
|
14
|
+
|
|
15
|
+
**Changed**
|
|
16
|
+
|
|
17
|
+
- Allows custom Auth0 domain to be passed via the configuration `config.auth.domain`
|
|
18
|
+
|
|
19
|
+
## [v4.1.1](http://github.com/ndustrialio/contxt-sdk-js/tree/v4.1.1) (2021-02-05)
|
|
2
20
|
|
|
3
21
|
**Fixed**
|
|
4
22
|
|
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/docs/Typedefs.md
CHANGED
|
@@ -1283,6 +1283,7 @@ User provided configuration options
|
|
|
1283
1283
|
| [auth.authorizationPath] | <code>string</code> | | Path Auth0WebAuth process should redirect to after a successful sign in attempt |
|
|
1284
1284
|
| auth.clientId | <code>string</code> | | Client Id provided by Auth0 for this application |
|
|
1285
1285
|
| [auth.clientSecret] | <code>string</code> | | Client secret provided by Auth0 for this application. This is optional for the auth0WebAuth SessionType, but required for the machineAuth SessionType |
|
|
1286
|
+
| [auth.domain] | <code>string</code> | | Auth0 domain for this application. This is an optional configuration that defaults to the production Auth0 tenant |
|
|
1286
1287
|
| [auth.customModuleConfigs] | <code>Object.<string, CustomAudience></code> | | Custom environment setups for individual modules. Requires clientId/host or env |
|
|
1287
1288
|
| [auth.env] | <code>string</code> | <code>"'production'"</code> | The environment that every module should use for their clientId and host |
|
|
1288
1289
|
| [auth.onAuthenticate] | <code>function</code> | <code>(auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo);</code> | An optional hook for handling a successful authentication request or overriding returned values. |
|
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/config/defaults.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/defaults.js"],"names":["auth","authorizationPath","tokenExpiresAtBufferMs","interceptors","request","response"],"mappings":"AAAA,eAAe;AACbA,QAAM;AACJC,
|
|
1
|
+
{"version":3,"sources":["config/defaults.js"],"names":["auth","domain","authorizationPath","tokenExpiresAtBufferMs","interceptors","request","response"],"mappings":"AAAA,eAAe;AACbA,QAAM;AACJC,YAAQ,qBADJ;AAEJC,uBAAmB,WAFf;AAGJC,4BAAwB,IAAI,EAAJ,GAAS,IAH7B,CAGkC;AAHlC,GADO;AAMbC,gBAAc;AACZC,aAAS,EADG;AAEZC,cAAU;AAFE;AAND,CAAf","file":"defaults.js","sourcesContent":["export default {\n auth: {\n domain: 'ndustrial.auth0.com',\n authorizationPath: '/callback',\n tokenExpiresAtBufferMs: 5 * 60 * 1000 // 5 minutes\n },\n interceptors: {\n request: [],\n response: []\n }\n};\n"]}
|
package/esm/config/index.js
CHANGED
|
@@ -73,6 +73,8 @@ import defaultConfigs from './defaults';
|
|
|
73
73
|
* @property {string} auth.clientId Client Id provided by Auth0 for this application
|
|
74
74
|
* @property {string} [auth.clientSecret] Client secret provided by Auth0 for this application. This
|
|
75
75
|
* is optional for the auth0WebAuth SessionType, but required for the machineAuth SessionType
|
|
76
|
+
* @property {string} [auth.domain] Auth0 domain for this application. This is an optional configuration
|
|
77
|
+
* that defaults to the production Auth0 tenant
|
|
76
78
|
* @property {Object.<string, CustomAudience>} [auth.customModuleConfigs] Custom environment setups
|
|
77
79
|
* for individual modules. Requires clientId/host or env
|
|
78
80
|
* @property {string} [auth.env = 'production'] The environment that every module should use for
|
package/esm/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["config/index.js"],"names":["defaultAudiences","defaultConfigs","Config","userConfig","externalModules","Object","assign","_dynamicAudienceNames","_replacedAudiences","audiences","_getAudiences","customModuleConfigs","auth","env","interceptors","audienceName","clientId","host","Error","indexOf","filter","name","config","audience","webSocket","options","_getInternalAudiences","_getExternalAudiences","keys","reduce","memo","key","hasClientId","hasHost","customModuleConfig","moduleAudiences","_getAudienceFromCustomConfig"],"mappings":";;;;;;;;AAAA,OAAOA,gBAAP,MAA6B,aAA7B;AACA,OAAOC,cAAP,MAA2B,YAA3B;;AAEA;;;;;;;;;;AAUA;;;;;;;;;;;;;AAaA;;;;;;;AAOA;;;;;;;;;;;;;;AAcA;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA;;;;;;IAKMC,M;AACJ;;;;;AAKA,kBAAYC,UAAZ,EAAwBC,eAAxB,EAAyC;AAAA;;AACvCC,WAAOC,MAAP,CAAc,IAAd,EAAoBH,UAApB;;AAEA,SAAKI,qBAAL,GAA6B,EAA7B;AACA,SAAKC,kBAAL,GAA0B,EAA1B;;AAEA,SAAKC,SAAL,GAAiB,KAAKC,aAAL,CAAmB;AAClCN,sCADkC;AAElCO,2BAAqBR,WAAWS,IAAX,CAAgBD,mBAFH;AAGlCE,WAAKV,WAAWS,IAAX,CAAgBC;AAHa,KAAnB,CAAjB;;AAMA,SAAKD,IAAL,gBACKX,eAAeW,IADpB,EAEKT,WAAWS,IAFhB;;AAKA,SAAKE,YAAL,gBACK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EADI,CAAN;AAGD;;AAEDY,aAAKC,GAAL,IAAY;AACVf,4BADU;AAEVC;AAFU,SAAZ;;AAKA,eAAOa,IAAP;AACD,OAlBM,EAkBJ,EAlBI,CAAP;AAmBD;;AAED;;;;;;;;;;;;;;;;;iDAc+D;AAAA;;AAAA,UAAvCrB,SAAuC,SAAvCA,SAAuC;AAAA,UAA5BE,mBAA4B,SAA5BA,mBAA4B;AAAA,UAAPE,GAAO,SAAPA,GAAO;;AAC7D,aAAOR,OAAOuB,IAAP,CAAYnB,SAAZ,EAAuBoB,MAAvB,CAA8B,UAACC,IAAD,EAAOC,GAAP,EAAe;AAClD,YAAMG,qBAAqBvB,oBAAoBoB,GAApB,CAA3B;AACA,YAAMI,kBAAkB1B,UAAUsB,GAAV,CAAxB;;AAEA,YAAIG,kBAAJ,EAAwB;AACtBJ,eAAKC,GAAL,IAAY,MAAKK,4BAAL,CACVF,kBADU,EAEVC,eAFU,CAAZ;AAID,SALD,MAKO;AACLL,eAAKC,GAAL,IAAYI,gBAAgBtB,GAAhB,CAAZ;AACD;;AAED,eAAOiB,IAAP;AACD,OAdM,EAcJ,EAdI,CAAP;AAeD;;;;;;AAGH,eAAe5B,MAAf","file":"index.js","sourcesContent":["import defaultAudiences from './audiences';\nimport defaultConfigs from './defaults';\n\n/**\n * A single audience used for authenticating and communicating with an individual API.\n *\n * @typedef {Object} Audience\n * @param {string} config.clientId Client Id provided by Auth0 for the environment you are\n * trying to communicate with\n * @param {string} config.host Hostname for the API that corresponds with the clientId provided\n * @param {string} [config.webSocket] WebSocket URL for the API that corresponds with the clientId provided\n */\n\n/**\n * A custom audience that will override the configuration of an individual module. Consists of\n * either a reference to an environment that already exists or a clientId and host for a\n * custom environment.\n *\n * @typedef {Object} CustomAudience\n * @param {string} [config.clientId] Client Id provided by Auth0 for the environment you are\n * trying to communicate with\n * @param {string} [config.env] The SDK provided environment name you are trying to reach\n * @param {string} [config.host] Hostname for the API that corresponds with the clientId provided\n * @param {string} [config.webSocket] WebSocket URL for the API that corresponds with the clientId provided\n */\n\n/**\n * An object of audiences that corresponds to all the different environments available for a\n * single module.\n *\n * @typedef {Object.<string, Audience>} Environments\n */\n\n/**\n * An external module to be integrated into the SDK as a first class citizen. Includes information\n * for authenticating and communicating with an individual API and the external module itself.\n *\n * @typedef {Object} ExternalModule\n * @param {string} config.clientId Client Id provided by Auth0 for the environment you are\n * trying to communicate with. Can be a `null` value if the value is not needed. Some SessionType\n * adapters (currently, just the MachineAuth adapter) require a value other than `null` if the\n * built-in `request` module is used since they acquire contxt tokens based on a single clientId.\n * @param {string} config.host Hostname for the API that corresponds with the clientId provided.\n * Can be a `null` value if the value is not needed.\n * @param {function} config.module The module that will be decorated into the SDK\n */\n\n/**\n * An object of interceptors that get called on every request or response.\n * More information at {@link https://github.com/axios/axios#interceptors axios Interceptors}\n *\n * @typedef {Object} AxiosInterceptor\n * @param {function} interceptor.fulfilled A function that is run on every successful request or\n * response\n * @param {function} interceptor.rejected A function that is run on every failed request or response\n */\n\n/**\n * User provided configuration options\n *\n * @typedef {Object} UserConfig\n * @property {Object} auth User assigned configurations specific for their authentication methods\n * @property {string} [auth.authorizationPath] Path Auth0WebAuth process should redirect to after a\n * successful sign in attempt\n * @property {string} auth.clientId Client Id provided by Auth0 for this application\n * @property {string} [auth.clientSecret] Client secret provided by Auth0 for this application. This\n * is optional for the auth0WebAuth SessionType, but required for the machineAuth SessionType\n * @property {Object.<string, CustomAudience>} [auth.customModuleConfigs] Custom environment setups\n * for individual modules. Requires clientId/host or env\n * @property {string} [auth.env = 'production'] The environment that every module should use for\n * their clientId and host\n * @property {function} [auth.onAuthenticate = (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo); ] An optional\n * hook for handling a successful authentication request or overriding returned values.\n * @property {function} [auth.onRedirect = (pathname) => { window.location = pathname; }] A redirect\n * method used for navigating through Auth0 callbacks in Web applications\n * @property {number} [auth.tokenExpiresAtBufferMs = 300000] The time (in milliseconds) before a\n * token truly expires that we consider it expired (i.e. the token's expiresAt - this = calculated\n * expiresAt). Defaults to 5 minutes.\n * @property {Object} [interceptors] Axios interceptors that can transform requests and responses.\n * More information at {@link https://github.com/axios/axios#interceptors axios Interceptors}\n * @property {AxiosInterceptor[]} [interceptors.request] Interceptors that act on every request\n * @property {AxiosInterceptor[]} [intercepotrs.response] Intereptors that act on every response\n */\n\n/**\n * Module that merges user assigned configurations with default configurations.\n *\n * @typicalname contxtSdk.config\n */\nclass Config {\n /**\n * @param {UserConfig} userConfig The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that should be treated as\n * first class citizens\n */\n constructor(userConfig, externalModules) {\n Object.assign(this, userConfig);\n\n this._dynamicAudienceNames = [];\n this._replacedAudiences = {};\n\n this.audiences = this._getAudiences({\n externalModules,\n customModuleConfigs: userConfig.auth.customModuleConfigs,\n env: userConfig.auth.env\n });\n\n this.auth = {\n ...defaultConfigs.auth,\n ...userConfig.auth\n };\n\n this.interceptors = {\n ...defaultConfigs.interceptors,\n ...userConfig.interceptors\n };\n }\n\n addDynamicAudience(audienceName, { clientId, host }) {\n if (!clientId || !host) {\n throw new Error(\n 'A dynamic audience must contain `clientId` and `host` properties'\n );\n }\n\n if (this._dynamicAudienceNames.indexOf(audienceName) > -1) {\n throw new Error(\n `A dynamic audience of the name \\`${audienceName}\\` already exists. This problem can be rectified by using a different name for the audience.`\n );\n }\n\n this._dynamicAudienceNames = [...this._dynamicAudienceNames, audienceName];\n\n if (this.audiences[audienceName]) {\n this._replacedAudiences[audienceName] = this.audiences[audienceName];\n }\n\n this.audiences[audienceName] = {\n clientId,\n host\n };\n }\n\n removeDynamicAudience(audienceName) {\n if (this._dynamicAudienceNames.indexOf(audienceName) === -1) {\n throw new Error('There is no dynamic audience to remove.');\n }\n\n this.audiences[audienceName] = this._replacedAudiences[audienceName];\n\n delete this._replacedAudiences[audienceName];\n this._dynamicAudienceNames = this._dynamicAudienceNames.filter(\n (name) => name !== audienceName\n );\n }\n\n /**\n * Parses a custom module configuration for a valid environment/audience. Requires either a\n * clientId and host, or an environment that matches a default audience/environment.\n *\n * @param {CustomAudience} config A custom audience configuration to parse\n * @param {Object.<string, Audience>} audiences An object with keys for environment names and values of Audience information\n *\n * @returns {Audience}\n * @throws {Error}\n *\n * @private\n */\n _getAudienceFromCustomConfig(config, audiences) {\n if (config.clientId && config.host) {\n const audience = {\n clientId: config.clientId,\n host: config.host\n };\n\n if (config.webSocket) {\n audience.webSocket = config.webSocket;\n }\n\n return audience;\n } else if (config.env) {\n return audiences[config.env];\n } else {\n throw new Error(\n 'Custom module configurations must either contain a `host` and `clientId` or specify a specific target environment via the `env` property'\n );\n }\n }\n\n /**\n * Reconciles the main environment with custom environments and external modules.\n *\n * @param {Object} options\n * @param {Object.<string, CustomAudience>} [options.customModuleConfigs = {}] Any custom\n * configurations for internal modules\n * @param {string} [options.env = 'production'] The base environment for any\n * non-overridden modules\n * @param {Object.<string, ExternalModule>} [options.externalModules = {}] An object of external\n * modules from which to build a set of audiences\n *\n * @returns {Object.<string, Audience>}\n *\n * @private\n */\n _getAudiences(options = {}) {\n const {\n customModuleConfigs = {},\n env = 'production',\n externalModules = {}\n } = options;\n\n return {\n ...this._getInternalAudiences({\n customModuleConfigs,\n env,\n audiences: defaultAudiences\n }),\n ...this._getExternalAudiences({ externalModules })\n };\n }\n\n /**\n * Builds up the audiences for external modules.\n *\n * @param {Object}\n * @param {Object.<string, ExternalModule>} externalModules An object of external modules from\n * which to build a set of audiences\n *\n * @returns {Object.<string, Audience>}\n * @throws {Error}\n *\n * @private\n */\n _getExternalAudiences({ externalModules }) {\n return Object.keys(externalModules).reduce((memo, key) => {\n const clientId = externalModules[key].clientId;\n const host = externalModules[key].host;\n const hasClientId = !!clientId || clientId === null;\n const hasHost = !!host || host === null;\n\n if (!(hasClientId && hasHost)) {\n throw new Error(\n 'External modules must contain `clientId` and `host` properties'\n );\n }\n\n memo[key] = {\n clientId,\n host\n };\n\n return memo;\n }, {});\n }\n\n /**\n * Reconciles the main environment with custom environments to build up audiences for\n * internal modules.\n *\n * @param {Object.<string, Environments>} audiences All possible audiences/environments for\n * internal modules\n * @param {Object.<string, CustomAudience>} customModuleConfigs Any custom configurations for\n * internal modules\n * @param {string} env The base environment for any non-overridden modules\n *\n * @returns {Object.<string, Audience>}\n *\n * @private\n */\n _getInternalAudiences({ audiences, customModuleConfigs, env }) {\n return Object.keys(audiences).reduce((memo, key) => {\n const customModuleConfig = customModuleConfigs[key];\n const moduleAudiences = audiences[key];\n\n if (customModuleConfig) {\n memo[key] = this._getAudienceFromCustomConfig(\n customModuleConfig,\n moduleAudiences\n );\n } else {\n memo[key] = moduleAudiences[env];\n }\n\n return memo;\n }, {});\n }\n}\n\nexport default Config;\n"]}
|
|
1
|
+
{"version":3,"sources":["config/index.js"],"names":["defaultAudiences","defaultConfigs","Config","userConfig","externalModules","Object","assign","_dynamicAudienceNames","_replacedAudiences","audiences","_getAudiences","customModuleConfigs","auth","env","interceptors","audienceName","clientId","host","Error","indexOf","filter","name","config","audience","webSocket","options","_getInternalAudiences","_getExternalAudiences","keys","reduce","memo","key","hasClientId","hasHost","customModuleConfig","moduleAudiences","_getAudienceFromCustomConfig"],"mappings":";;;;;;;;AAAA,OAAOA,gBAAP,MAA6B,aAA7B;AACA,OAAOC,cAAP,MAA2B,YAA3B;;AAEA;;;;;;;;;;AAUA;;;;;;;;;;;;;AAaA;;;;;;;AAOA;;;;;;;;;;;;;;AAcA;;;;;;;;;;AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;IAKMC,M;AACJ;;;;;AAKA,kBAAYC,UAAZ,EAAwBC,eAAxB,EAAyC;AAAA;;AACvCC,WAAOC,MAAP,CAAc,IAAd,EAAoBH,UAApB;;AAEA,SAAKI,qBAAL,GAA6B,EAA7B;AACA,SAAKC,kBAAL,GAA0B,EAA1B;;AAEA,SAAKC,SAAL,GAAiB,KAAKC,aAAL,CAAmB;AAClCN,sCADkC;AAElCO,2BAA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,CAAChB,QAAF,IAAcA,aAAa,IAA/C;AACA,YAAMiB,UAAU,CAAC,CAAChB,IAAF,IAAUA,SAAS,IAAnC;;AAEA,YAAI,EAAEe,eAAeC,OAAjB,CAAJ,EAA+B;AAC7B,gBAAM,IAAIf,KAAJ,CACJ,gEADI,CAAN;AAGD;;AAEDY,aAAKC,GAAL,IAAY;AACVf,4BADU;AAEVC;AAFU,SAAZ;;AAKA,eAAOa,IAAP;AACD,OAlBM,EAkBJ,EAlBI,CAAP;AAmBD;;AAED;;;;;;;;;;;;;;;;;iDAc+D;AAAA;;AAAA,UAAvCrB,SAAuC,SAAvCA,SAAuC;AAAA,UAA5BE,mBAA4B,SAA5BA,mBAA4B;AAAA,UAAPE,GAAO,SAAPA,GAAO;;AAC7D,aAAOR,OAAOuB,IAAP,CAAYnB,SAAZ,EAAuBoB,MAAvB,CAA8B,UAACC,IAAD,EAAOC,GAAP,EAAe;AAClD,YAAMG,qBAAqBvB,oBAAoBoB,GAApB,CAA3B;AACA,YAAMI,kBAAkB1B,UAAUsB,GAAV,CAAxB;;AAEA,YAAIG,kBAAJ,EAAwB;AACtBJ,eAAKC,GAAL,IAAY,MAAKK,4BAAL,CACVF,kBADU,EAEVC,eAFU,CAAZ;AAID,SALD,MAKO;AACLL,eAAKC,GAAL,IAAYI,gBAAgBtB,GAAhB,CAAZ;AACD;;AAED,eAAOiB,IAAP;AACD,OAdM,EAcJ,EAdI,CAAP;AAeD;;;;;;AAGH,eAAe5B,MAAf","file":"index.js","sourcesContent":["import defaultAudiences from './audiences';\nimport defaultConfigs from './defaults';\n\n/**\n * A single audience used for authenticating and communicating with an individual API.\n *\n * @typedef {Object} Audience\n * @param {string} config.clientId Client Id provided by Auth0 for the environment you are\n * trying to communicate with\n * @param {string} config.host Hostname for the API that corresponds with the clientId provided\n * @param {string} [config.webSocket] WebSocket URL for the API that corresponds with the clientId provided\n */\n\n/**\n * A custom audience that will override the configuration of an individual module. Consists of\n * either a reference to an environment that already exists or a clientId and host for a\n * custom environment.\n *\n * @typedef {Object} CustomAudience\n * @param {string} [config.clientId] Client Id provided by Auth0 for the environment you are\n * trying to communicate with\n * @param {string} [config.env] The SDK provided environment name you are trying to reach\n * @param {string} [config.host] Hostname for the API that corresponds with the clientId provided\n * @param {string} [config.webSocket] WebSocket URL for the API that corresponds with the clientId provided\n */\n\n/**\n * An object of audiences that corresponds to all the different environments available for a\n * single module.\n *\n * @typedef {Object.<string, Audience>} Environments\n */\n\n/**\n * An external module to be integrated into the SDK as a first class citizen. Includes information\n * for authenticating and communicating with an individual API and the external module itself.\n *\n * @typedef {Object} ExternalModule\n * @param {string} config.clientId Client Id provided by Auth0 for the environment you are\n * trying to communicate with. Can be a `null` value if the value is not needed. Some SessionType\n * adapters (currently, just the MachineAuth adapter) require a value other than `null` if the\n * built-in `request` module is used since they acquire contxt tokens based on a single clientId.\n * @param {string} config.host Hostname for the API that corresponds with the clientId provided.\n * Can be a `null` value if the value is not needed.\n * @param {function} config.module The module that will be decorated into the SDK\n */\n\n/**\n * An object of interceptors that get called on every request or response.\n * More information at {@link https://github.com/axios/axios#interceptors axios Interceptors}\n *\n * @typedef {Object} AxiosInterceptor\n * @param {function} interceptor.fulfilled A function that is run on every successful request or\n * response\n * @param {function} interceptor.rejected A function that is run on every failed request or response\n */\n\n/**\n * User provided configuration options\n *\n * @typedef {Object} UserConfig\n * @property {Object} auth User assigned configurations specific for their authentication methods\n * @property {string} [auth.authorizationPath] Path Auth0WebAuth process should redirect to after a\n * successful sign in attempt\n * @property {string} auth.clientId Client Id provided by Auth0 for this application\n * @property {string} [auth.clientSecret] Client secret provided by Auth0 for this application. This\n * is optional for the auth0WebAuth SessionType, but required for the machineAuth SessionType\n * @property {string} [auth.domain] Auth0 domain for this application. This is an optional configuration\n * that defaults to the production Auth0 tenant\n * @property {Object.<string, CustomAudience>} [auth.customModuleConfigs] Custom environment setups\n * for individual modules. Requires clientId/host or env\n * @property {string} [auth.env = 'production'] The environment that every module should use for\n * their clientId and host\n * @property {function} [auth.onAuthenticate = (auth0WebAuthSessionInfo) => handleSuccessfulAuth(auth0WebAuthSessionInfo); ] An optional\n * hook for handling a successful authentication request or overriding returned values.\n * @property {function} [auth.onRedirect = (pathname) => { window.location = pathname; }] A redirect\n * method used for navigating through Auth0 callbacks in Web applications\n * @property {number} [auth.tokenExpiresAtBufferMs = 300000] The time (in milliseconds) before a\n * token truly expires that we consider it expired (i.e. the token's expiresAt - this = calculated\n * expiresAt). Defaults to 5 minutes.\n * @property {Object} [interceptors] Axios interceptors that can transform requests and responses.\n * More information at {@link https://github.com/axios/axios#interceptors axios Interceptors}\n * @property {AxiosInterceptor[]} [interceptors.request] Interceptors that act on every request\n * @property {AxiosInterceptor[]} [intercepotrs.response] Intereptors that act on every response\n */\n\n/**\n * Module that merges user assigned configurations with default configurations.\n *\n * @typicalname contxtSdk.config\n */\nclass Config {\n /**\n * @param {UserConfig} userConfig The user provided configuration options\n * @param {Object.<string, ExternalModule>} [externalModules] User provided external modules that should be treated as\n * first class citizens\n */\n constructor(userConfig, externalModules) {\n Object.assign(this, userConfig);\n\n this._dynamicAudienceNames = [];\n this._replacedAudiences = {};\n\n this.audiences = this._getAudiences({\n externalModules,\n customModuleConfigs: userConfig.auth.customModuleConfigs,\n env: userConfig.auth.env\n });\n\n this.auth = {\n ...defaultConfigs.auth,\n ...userConfig.auth\n };\n\n this.interceptors = {\n ...defaultConfigs.interceptors,\n ...userConfig.interceptors\n };\n }\n\n addDynamicAudience(audienceName, { clientId, host }) {\n if (!clientId || !host) {\n throw new Error(\n 'A dynamic audience must contain `clientId` and `host` properties'\n );\n }\n\n if (this._dynamicAudienceNames.indexOf(audienceName) > -1) {\n throw new Error(\n `A dynamic audience of the name \\`${audienceName}\\` already exists. This problem can be rectified by using a different name for the audience.`\n );\n }\n\n this._dynamicAudienceNames = [...this._dynamicAudienceNames, audienceName];\n\n if (this.audiences[audienceName]) {\n this._replacedAudiences[audienceName] = this.audiences[audienceName];\n }\n\n this.audiences[audienceName] = {\n clientId,\n host\n };\n }\n\n removeDynamicAudience(audienceName) {\n if (this._dynamicAudienceNames.indexOf(audienceName) === -1) {\n throw new Error('There is no dynamic audience to remove.');\n }\n\n this.audiences[audienceName] = this._replacedAudiences[audienceName];\n\n delete this._replacedAudiences[audienceName];\n this._dynamicAudienceNames = this._dynamicAudienceNames.filter(\n (name) => name !== audienceName\n );\n }\n\n /**\n * Parses a custom module configuration for a valid environment/audience. Requires either a\n * clientId and host, or an environment that matches a default audience/environment.\n *\n * @param {CustomAudience} config A custom audience configuration to parse\n * @param {Object.<string, Audience>} audiences An object with keys for environment names and values of Audience information\n *\n * @returns {Audience}\n * @throws {Error}\n *\n * @private\n */\n _getAudienceFromCustomConfig(config, audiences) {\n if (config.clientId && config.host) {\n const audience = {\n clientId: config.clientId,\n host: config.host\n };\n\n if (config.webSocket) {\n audience.webSocket = config.webSocket;\n }\n\n return audience;\n } else if (config.env) {\n return audiences[config.env];\n } else {\n throw new Error(\n 'Custom module configurations must either contain a `host` and `clientId` or specify a specific target environment via the `env` property'\n );\n }\n }\n\n /**\n * Reconciles the main environment with custom environments and external modules.\n *\n * @param {Object} options\n * @param {Object.<string, CustomAudience>} [options.customModuleConfigs = {}] Any custom\n * configurations for internal modules\n * @param {string} [options.env = 'production'] The base environment for any\n * non-overridden modules\n * @param {Object.<string, ExternalModule>} [options.externalModules = {}] An object of external\n * modules from which to build a set of audiences\n *\n * @returns {Object.<string, Audience>}\n *\n * @private\n */\n _getAudiences(options = {}) {\n const {\n customModuleConfigs = {},\n env = 'production',\n externalModules = {}\n } = options;\n\n return {\n ...this._getInternalAudiences({\n customModuleConfigs,\n env,\n audiences: defaultAudiences\n }),\n ...this._getExternalAudiences({ externalModules })\n };\n }\n\n /**\n * Builds up the audiences for external modules.\n *\n * @param {Object}\n * @param {Object.<string, ExternalModule>} externalModules An object of external modules from\n * which to build a set of audiences\n *\n * @returns {Object.<string, Audience>}\n * @throws {Error}\n *\n * @private\n */\n _getExternalAudiences({ externalModules }) {\n return Object.keys(externalModules).reduce((memo, key) => {\n const clientId = externalModules[key].clientId;\n const host = externalModules[key].host;\n const hasClientId = !!clientId || clientId === null;\n const hasHost = !!host || host === null;\n\n if (!(hasClientId && hasHost)) {\n throw new Error(\n 'External modules must contain `clientId` and `host` properties'\n );\n }\n\n memo[key] = {\n clientId,\n host\n };\n\n return memo;\n }, {});\n }\n\n /**\n * Reconciles the main environment with custom environments to build up audiences for\n * internal modules.\n *\n * @param {Object.<string, Environments>} audiences All possible audiences/environments for\n * internal modules\n * @param {Object.<string, CustomAudience>} customModuleConfigs Any custom configurations for\n * internal modules\n * @param {string} env The base environment for any non-overridden modules\n *\n * @returns {Object.<string, Audience>}\n *\n * @private\n */\n _getInternalAudiences({ audiences, customModuleConfigs, env }) {\n return Object.keys(audiences).reduce((memo, key) => {\n const customModuleConfig = customModuleConfigs[key];\n const moduleAudiences = audiences[key];\n\n if (customModuleConfig) {\n memo[key] = this._getAudienceFromCustomConfig(\n customModuleConfig,\n moduleAudiences\n );\n } else {\n memo[key] = moduleAudiences[env];\n }\n\n return memo;\n }, {});\n }\n}\n\nexport default Config;\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,OAA1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AAL,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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,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,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,CAAC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,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;;;;;;;;;;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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AAL,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"]}
|
|
@@ -97,7 +97,7 @@ var Auth0WebAuth = function () {
|
|
|
97
97
|
this._auth0 = new auth0.WebAuth({
|
|
98
98
|
audience: this._sdk.config.audiences.contxtAuth.clientId,
|
|
99
99
|
clientID: this._sdk.config.auth.clientId,
|
|
100
|
-
domain:
|
|
100
|
+
domain: this._sdk.config.auth.domain,
|
|
101
101
|
redirectUri: '' + currentUrl.origin + currentUrl.pathname,
|
|
102
102
|
responseType: 'token',
|
|
103
103
|
scope: 'email profile openid'
|