@esri/arcgis-rest-developer-credentials 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/bundled/developer-credentials.esm.js +178 -178
  2. package/dist/bundled/developer-credentials.esm.js.map +1 -1
  3. package/dist/bundled/developer-credentials.esm.min.js +3 -3
  4. package/dist/bundled/developer-credentials.esm.min.js.map +1 -1
  5. package/dist/bundled/developer-credentials.umd.js +179 -178
  6. package/dist/bundled/developer-credentials.umd.js.map +1 -1
  7. package/dist/bundled/developer-credentials.umd.min.js +3 -3
  8. package/dist/bundled/developer-credentials.umd.min.js.map +1 -1
  9. package/dist/cjs/createApiKey.js +29 -10
  10. package/dist/cjs/createApiKey.js.map +1 -1
  11. package/dist/cjs/index.js +0 -2
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/shared/enum/privileges.js +0 -27
  14. package/dist/cjs/shared/enum/privileges.js.map +1 -1
  15. package/dist/cjs/shared/generateApiKeyToken.js +27 -0
  16. package/dist/cjs/shared/generateApiKeyToken.js.map +1 -0
  17. package/dist/cjs/shared/helpers.js +73 -16
  18. package/dist/cjs/shared/helpers.js.map +1 -1
  19. package/dist/cjs/shared/registerApp.js +0 -4
  20. package/dist/cjs/shared/registerApp.js.map +1 -1
  21. package/dist/cjs/shared/types/apiKeyType.js.map +1 -1
  22. package/dist/cjs/shared/types/appType.js.map +1 -1
  23. package/dist/cjs/updateApiKey.js +24 -13
  24. package/dist/cjs/updateApiKey.js.map +1 -1
  25. package/dist/esm/createApiKey.d.ts +1 -1
  26. package/dist/esm/createApiKey.js +31 -12
  27. package/dist/esm/createApiKey.js.map +1 -1
  28. package/dist/esm/index.d.ts +0 -2
  29. package/dist/esm/index.js +0 -2
  30. package/dist/esm/index.js.map +1 -1
  31. package/dist/esm/shared/enum/privileges.d.ts +2 -23
  32. package/dist/esm/shared/enum/privileges.js +1 -26
  33. package/dist/esm/shared/enum/privileges.js.map +1 -1
  34. package/dist/esm/shared/generateApiKeyToken.d.ts +11 -0
  35. package/dist/esm/shared/generateApiKeyToken.js +23 -0
  36. package/dist/esm/shared/generateApiKeyToken.js.map +1 -0
  37. package/dist/esm/shared/helpers.d.ts +37 -7
  38. package/dist/esm/shared/helpers.js +68 -14
  39. package/dist/esm/shared/helpers.js.map +1 -1
  40. package/dist/esm/shared/registerApp.js +1 -5
  41. package/dist/esm/shared/registerApp.js.map +1 -1
  42. package/dist/esm/shared/types/apiKeyType.d.ts +37 -5
  43. package/dist/esm/shared/types/apiKeyType.js.map +1 -1
  44. package/dist/esm/shared/types/appType.d.ts +7 -3
  45. package/dist/esm/shared/types/appType.js.map +1 -1
  46. package/dist/esm/updateApiKey.js +26 -15
  47. package/dist/esm/updateApiKey.js.map +1 -1
  48. package/package.json +1 -1
  49. package/dist/cjs/deleteApiKey.js +0 -43
  50. package/dist/cjs/deleteApiKey.js.map +0 -1
  51. package/dist/cjs/deleteOAuthApp.js +0 -43
  52. package/dist/cjs/deleteOAuthApp.js.map +0 -1
  53. package/dist/esm/deleteApiKey.d.ts +0 -27
  54. package/dist/esm/deleteApiKey.js +0 -39
  55. package/dist/esm/deleteApiKey.js.map +0 -1
  56. package/dist/esm/deleteOAuthApp.d.ts +0 -27
  57. package/dist/esm/deleteOAuthApp.js +0 -39
  58. package/dist/esm/deleteOAuthApp.js.map +0 -1
@@ -6,6 +6,7 @@ exports.createApiKey = void 0;
6
6
  const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
7
7
  const registerApp_js_1 = require("./shared/registerApp.js");
8
8
  const helpers_js_1 = require("./shared/helpers.js");
9
+ const getRegisteredAppInfo_js_1 = require("./shared/getRegisteredAppInfo.js");
9
10
  /**
10
11
  * Used to register an API key. See the [security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/) for more information about API key.
11
12
  *
@@ -22,7 +23,7 @@ const helpers_js_1 = require("./shared/helpers.js");
22
23
  * title: "xyz_title",
23
24
  * description: "xyz_desc",
24
25
  * tags: ["xyz_tag1", "xyz_tag2"],
25
- * privileges: [Privileges.Geocode, Privileges.FeatureReport],
26
+ * privileges: ["premium:user:networkanalysis:routing"],
26
27
  * authentication: authSession
27
28
  * }).then((registeredAPIKey: IApiKeyResponse) => {
28
29
  * // => {apiKey: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
@@ -35,9 +36,6 @@ const helpers_js_1 = require("./shared/helpers.js");
35
36
  * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.
36
37
  */
37
38
  async function createApiKey(requestOptions) {
38
- if (!(0, helpers_js_1.arePrivilegesValid)(requestOptions.privileges)) {
39
- throw new Error("The `privileges` option contains invalid privileges.");
40
- }
41
39
  requestOptions.httpMethod = "POST";
42
40
  // filter param buckets:
43
41
  const baseRequestOptions = (0, helpers_js_1.extractBaseRequestOptions)(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it
@@ -57,16 +55,37 @@ async function createApiKey(requestOptions) {
57
55
  "typeKeywords",
58
56
  "url"
59
57
  ];
60
- // step 1: add item
61
- const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, (0, helpers_js_1.filterKeys)(requestOptions, itemAddProperties)), { type: "API Key" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
58
+ /**
59
+ * step 1: create item
60
+ */
61
+ const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, (0, helpers_js_1.filterKeys)(requestOptions, itemAddProperties)), { type: "Application" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
62
62
  f: "json"
63
63
  } });
64
64
  const createItemResponse = await (0, arcgis_rest_portal_1.createItem)(createItemOption);
65
- // step 2: register app
66
- const registerAppOption = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "apikey", redirect_uris: [], httpReferrers: requestOptions.httpReferrers || [], privileges: requestOptions.privileges }, baseRequestOptions), { authentication: requestOptions.authentication });
67
- const registeredAppResponse = await (0, registerApp_js_1.registerApp)(registerAppOption);
65
+ /**
66
+ * getRegisteredAppInfoRoute
67
+ */
68
+ const registerAppOptions = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "multiple", redirect_uris: ["urn:ietf:wg:oauth:2.0:oob"], httpReferrers: requestOptions.httpReferrers || [], privileges: requestOptions.privileges }, baseRequestOptions), { authentication: requestOptions.authentication });
69
+ const registeredAppResponse = await (0, registerApp_js_1.registerApp)(registerAppOptions);
70
+ /**
71
+ * step 3: update item with desired expiration dates
72
+ * you cannot set the expiration date propierties until you
73
+ * regiester the app so this has to be a seperate step
74
+ */
75
+ await (0, arcgis_rest_portal_1.updateItem)(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: createItemResponse.id }, (0, helpers_js_1.buildExpirationDateParams)(requestOptions, true)), authentication: requestOptions.authentication }));
76
+ /*
77
+ * step 4: get item info
78
+ */
68
79
  const itemInfo = await (0, arcgis_rest_portal_1.getItem)(registeredAppResponse.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
69
- return Object.assign(Object.assign({}, (0, helpers_js_1.appToApiKeyProperties)(registeredAppResponse)), { item: itemInfo });
80
+ /**
81
+ * step 5: generate tokens if requested
82
+ */
83
+ const generatedTokens = await (0, helpers_js_1.generateApiKeyTokens)(itemInfo.id, (0, helpers_js_1.generateOptionsToSlots)(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
84
+ /**
85
+ * step 6: get registered app info to get updated active key status
86
+ */
87
+ const updatedRegisteredAppResponse = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)(Object.assign(Object.assign({}, baseRequestOptions), { itemId: itemInfo.id, authentication: requestOptions.authentication }));
88
+ return Object.assign(Object.assign(Object.assign({}, generatedTokens), (0, helpers_js_1.appToApiKeyProperties)(updatedRegisteredAppResponse)), { item: itemInfo });
70
89
  }
71
90
  exports.createApiKey = createApiKey;
72
91
  //# sourceMappingURL=createApiKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createApiKey.js","sourceRoot":"","sources":["../../src/createApiKey.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,iEAKkC;AAMlC,4DAAsD;AAEtD,oDAK6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACI,KAAK,UAAU,YAAY,CAChC,cAAoC;IAEpC,IAAI,CAAC,IAAA,+BAAkB,EAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QAClD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACzE;IAED,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC;IAEnC,wBAAwB;IAExB,MAAM,kBAAkB,GAAG,IAAA,sCAAyB,EAAC,cAAc,CAAC,CAAC,CAAC,iFAAiF;IAEvJ,MAAM,iBAAiB,GAA0B;QAC/C,YAAY;QACZ,SAAS;QACT,aAAa;QACb,eAAe;QACf,QAAQ;QACR,OAAO;QACP,YAAY;QACZ,SAAS;QACT,kBAAkB;QAClB,MAAM;QACN,OAAO;QACP,MAAM;QACN,cAAc;QACd,KAAK;KACN,CAAC;IAEF,mBAAmB;IACnB,MAAM,gBAAgB,iCACpB,IAAI,kCACC,IAAA,uBAAU,EAAC,cAAqB,EAAE,iBAAiB,CAAC,KACvD,IAAI,EAAE,SAAS,OAEd,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE;YACN,CAAC,EAAE,MAAM;SACV,GACF,CAAC;IAEF,MAAM,kBAAkB,GAAG,MAAM,IAAA,+BAAU,EAAC,gBAAgB,CAAC,CAAC;IAE9D,uBAAuB;IACvB,MAAM,iBAAiB,iCACrB,MAAM,EAAE,kBAAkB,CAAC,EAAE,EAC7B,OAAO,EAAE,QAAQ,EACjB,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,cAAc,CAAC,aAAa,IAAI,EAAE,EACjD,UAAU,EAAE,cAAc,CAAC,UAAU,IAClC,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,GAC9C,CAAC;IAEF,MAAM,qBAAqB,GAAG,MAAM,IAAA,4BAAW,EAAC,iBAAiB,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,MAAM,IAAA,4BAAO,EAAC,qBAAqB,CAAC,MAAM,kCACtD,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,IACrB,CAAC;IAEH,uCACK,IAAA,kCAAqB,EAAC,qBAAqB,CAAC,KAC/C,IAAI,EAAE,QAAQ,IACd;AACJ,CAAC;AAnED,oCAmEC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n ICreateItemOptions,\n createItem,\n getItem,\n IItemAdd\n} from \"@esri/arcgis-rest-portal\";\nimport {\n IApiKeyResponse,\n ICreateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\n\nimport { registerApp } from \"./shared/registerApp.js\";\nimport { IRegisterAppOptions } from \"./shared/types/appType.js\";\nimport {\n appToApiKeyProperties,\n filterKeys,\n extractBaseRequestOptions,\n arePrivilegesValid\n} from \"./shared/helpers.js\";\n\n/**\n * Used to register an API key. See the [security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/) for more information about API key.\n *\n * ```js\n * import { createApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * createApiKey({\n * title: \"xyz_title\",\n * description: \"xyz_desc\",\n * tags: [\"xyz_tag1\", \"xyz_tag2\"],\n * privileges: [Privileges.Geocode, Privileges.FeatureReport],\n * authentication: authSession\n * }).then((registeredAPIKey: IApiKeyResponse) => {\n * // => {apiKey: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode createApiKey | createApiKey()}, including necessary params to register an API key and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.\n */\nexport async function createApiKey(\n requestOptions: ICreateApiKeyOptions\n): Promise<IApiKeyResponse> {\n if (!arePrivilegesValid(requestOptions.privileges)) {\n throw new Error(\"The `privileges` option contains invalid privileges.\");\n }\n\n requestOptions.httpMethod = \"POST\";\n\n // filter param buckets:\n\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it\n\n const itemAddProperties: Array<keyof IItemAdd> = [\n \"categories\",\n \"culture\",\n \"description\",\n \"documentation\",\n \"extent\",\n \"owner\",\n \"properties\",\n \"snippet\",\n \"spatialReference\",\n \"tags\",\n \"title\",\n \"type\",\n \"typeKeywords\",\n \"url\"\n ];\n\n // step 1: add item\n const createItemOption: ICreateItemOptions = {\n item: {\n ...filterKeys(requestOptions as any, itemAddProperties),\n type: \"API Key\"\n },\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: {\n f: \"json\"\n }\n };\n\n const createItemResponse = await createItem(createItemOption);\n\n // step 2: register app\n const registerAppOption: IRegisterAppOptions = {\n itemId: createItemResponse.id,\n appType: \"apikey\",\n redirect_uris: [],\n httpReferrers: requestOptions.httpReferrers || [],\n privileges: requestOptions.privileges,\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n };\n\n const registeredAppResponse = await registerApp(registerAppOption);\n const itemInfo = await getItem(registeredAppResponse.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n return {\n ...appToApiKeyProperties(registeredAppResponse),\n item: itemInfo\n };\n}\n"]}
1
+ {"version":3,"file":"createApiKey.js","source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AAA,+BAAU,kCACX,kBAAkB,KACrB,IAAI,kBACF,EAAE,EAAE,kBAAkB,CAAC,EAAE,IACtB,IAAA,sCAAyB,EAAC,cAAc,EAAE,IAAI,CAAC,GAEpD,cAAc,EAAE,cAAc,CAAC,cAAc,IAC7C,CAAC;IAEH;;OAEG;IACH,MAAM,QAAQ,GAAG,MAAM,IAAA,4BAAO,EAAC,qBAAqB,CAAC,MAAM,kCACtD,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,IACrB,CAAC;IAEH;;OAEG;IACH,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAoB,EAChD,QAAQ,CAAC,EAAE,EACX,IAAA,mCAAsB,EACpB,cAAc,CAAC,cAAc,EAC7B,cAAc,CAAC,cAAc,CAC9B,kCAEI,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,IAEhD,CAAC;IAEF;;OAEG;IACH,MAAM,4BAA4B,GAAG,MAAM,IAAA,8CAAoB,kCAC1D,kBAAkB,KACrB,MAAM,EAAE,QAAQ,CAAC,EAAE,EACnB,cAAc,EAAE,cAAc,CAAC,cAAc,IAC7C,CAAC;IAEH,qDACK,eAAe,GACf,IAAA,kCAAqB,EAAC,4BAA4B,CAAC,KACtD,IAAI,EAAE,QAAQ,IACd;AACJ,CAAC;AA7GD,oCA6GC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n ICreateItemOptions,\n createItem,\n getItem,\n IItemAdd,\n updateItem\n} from \"@esri/arcgis-rest-portal\";\nimport {\n IApiKeyResponse,\n ICreateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\n\nimport { registerApp } from \"./shared/registerApp.js\";\nimport { IRegisterAppOptions } from \"./shared/types/appType.js\";\nimport {\n appToApiKeyProperties,\n filterKeys,\n extractBaseRequestOptions,\n generateApiKeyTokens,\n generateOptionsToSlots,\n buildExpirationDateParams\n} from \"./shared/helpers.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\n\n/**\n * Used to register an API key. See the [security and authentication](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/api-keys/) for more information about API key.\n *\n * ```js\n * import { createApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * createApiKey({\n * title: \"xyz_title\",\n * description: \"xyz_desc\",\n * tags: [\"xyz_tag1\", \"xyz_tag2\"],\n * privileges: [\"premium:user:networkanalysis:routing\"],\n * authentication: authSession\n * }).then((registeredAPIKey: IApiKeyResponse) => {\n * // => {apiKey: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode createApiKey | createApiKey()}, including necessary params to register an API key and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.\n */\nexport async function createApiKey(\n requestOptions: ICreateApiKeyOptions\n): Promise<IApiKeyResponse> {\n requestOptions.httpMethod = \"POST\";\n\n // filter param buckets:\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it\n\n const itemAddProperties: Array<keyof IItemAdd> = [\n \"categories\",\n \"culture\",\n \"description\",\n \"documentation\",\n \"extent\",\n \"owner\",\n \"properties\",\n \"snippet\",\n \"spatialReference\",\n \"tags\",\n \"title\",\n \"type\",\n \"typeKeywords\",\n \"url\"\n ];\n\n /**\n * step 1: create item\n */\n const createItemOption: ICreateItemOptions = {\n item: {\n ...filterKeys(requestOptions as any, itemAddProperties),\n type: \"Application\"\n },\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: {\n f: \"json\"\n }\n };\n\n const createItemResponse = await createItem(createItemOption);\n\n /**\n * getRegisteredAppInfoRoute\n */\n const registerAppOptions: IRegisterAppOptions = {\n itemId: createItemResponse.id,\n appType: \"multiple\",\n redirect_uris: [\"urn:ietf:wg:oauth:2.0:oob\"],\n httpReferrers: requestOptions.httpReferrers || [],\n privileges: requestOptions.privileges,\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n };\n\n const registeredAppResponse = await registerApp(registerAppOptions);\n\n /**\n * step 3: update item with desired expiration dates\n * you cannot set the expiration date propierties until you\n * regiester the app so this has to be a seperate step\n */\n await updateItem({\n ...baseRequestOptions,\n item: {\n id: createItemResponse.id,\n ...buildExpirationDateParams(requestOptions, true)\n },\n authentication: requestOptions.authentication\n });\n\n /*\n * step 4: get item info\n */\n const itemInfo = await getItem(registeredAppResponse.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n /**\n * step 5: generate tokens if requested\n */\n const generatedTokens = await generateApiKeyTokens(\n itemInfo.id,\n generateOptionsToSlots(\n requestOptions.generateToken1,\n requestOptions.generateToken2\n ),\n {\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n }\n );\n\n /**\n * step 6: get registered app info to get updated active key status\n */\n const updatedRegisteredAppResponse = await getRegisteredAppInfo({\n ...baseRequestOptions,\n itemId: itemInfo.id,\n authentication: requestOptions.authentication\n });\n\n return {\n ...generatedTokens,\n ...appToApiKeyProperties(updatedRegisteredAppResponse),\n item: itemInfo\n };\n}\n"]}
package/dist/cjs/index.js CHANGED
@@ -6,8 +6,6 @@ const tslib_1 = require("tslib");
6
6
  (0, tslib_1.__exportStar)(require("./createApiKey.js"), exports);
7
7
  (0, tslib_1.__exportStar)(require("./updateApiKey.js"), exports);
8
8
  (0, tslib_1.__exportStar)(require("./getApiKey.js"), exports);
9
- (0, tslib_1.__exportStar)(require("./deleteApiKey.js"), exports);
10
- (0, tslib_1.__exportStar)(require("./deleteOAuthApp.js"), exports);
11
9
  (0, tslib_1.__exportStar)(require("./getOAuthApp.js"), exports);
12
10
  (0, tslib_1.__exportStar)(require("./updateOAuthApp.js"), exports);
13
11
  (0, tslib_1.__exportStar)(require("./createOAuthApp.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,iEAAkC;AAClC,iEAAkC;AAClC,8DAA+B;AAC/B,iEAAkC;AAClC,mEAAoC;AACpC,gEAAiC;AACjC,mEAAoC;AACpC,mEAAoC;AACpC,2EAA4C;AAC5C,yEAA0C;AAC1C,4EAA6C;AAC7C,2EAA4C;AAC5C,gFAAiD;AACjD,uEAAwC;AACxC,yEAA0C;AAC1C,mEAAoC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./deleteApiKey.js\";\nexport * from \"./deleteOAuthApp.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,iEAAkC;AAClC,iEAAkC;AAClC,8DAA+B;AAC/B,gEAAiC;AACjC,mEAAoC;AACpC,mEAAoC;AACpC,2EAA4C;AAC5C,yEAA0C;AAC1C,4EAA6C;AAC7C,2EAA4C;AAC5C,gFAAiD;AACjD,uEAAwC;AACxC,yEAA0C;AAC1C,mEAAoC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
@@ -1,30 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Privileges = void 0;
4
- /**
5
- * Used to describe privilege list of an app.
6
- */
7
- var Privileges;
8
- (function (Privileges) {
9
- Privileges["Basemaps"] = "portal:apikey:basemaps";
10
- Privileges["Demographics"] = "premium:user:demographics";
11
- Privileges["Elevation"] = "premium:user:elevation";
12
- Privileges["FeatureReport"] = "premium:user:featurereport";
13
- Privileges["Geocode"] = "premium:user:geocode";
14
- Privileges["GeocodeStored"] = "premium:user:geocode:stored";
15
- Privileges["GeocodeTemporary"] = "premium:user:geocode:temporary";
16
- Privileges["GeoEnrichment"] = "premium:user:geoenrichment";
17
- Privileges["NetworkAnalysis"] = "premium:user:networkanalysis";
18
- Privileges["NetworkAnalysisRouting"] = "premium:user:networkanalysis:routing";
19
- Privileges["NetworkAnalysisOptimizedRouting"] = "premium:user:networkanalysis:optimizedrouting";
20
- Privileges["NetworkAnalysisClosestFacility"] = "premium:user:networkanalysis:closestfacility";
21
- Privileges["NetworkAnalysisServiceArea"] = "premium:user:networkanalysis:servicearea";
22
- Privileges["NetworkAnalysisLocationalLocation"] = "premium:user:networkanalysis:locationallocation";
23
- Privileges["NetworkAnalysisVehicleRouting"] = "premium:user:networkanalysis:vehiclerouting";
24
- Privileges["NetworkAnalysisOriginDestinationCostMatrix"] = "premium:user:networkanalysis:origindestinationcostmatrix";
25
- Privileges["Places"] = "premium:user:places";
26
- Privileges["SpatialAnalysis"] = "premium:user:spatialanalysis";
27
- Privileges["GeoAnalytics"] = "premium:publisher:geoanalytics";
28
- Privileges["RasterAnalysis"] = "premium:publisher:rasteranalysis";
29
- })(Privileges = exports.Privileges || (exports.Privileges = {}));
30
3
  //# sourceMappingURL=privileges.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"privileges.js","sourceRoot":"","sources":["../../../../src/shared/enum/privileges.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,UAqBX;AArBD,WAAY,UAAU;IACpB,iDAAmC,CAAA;IACnC,wDAA0C,CAAA;IAC1C,kDAAoC,CAAA;IACpC,0DAA4C,CAAA;IAC5C,8CAAgC,CAAA;IAChC,2DAA6C,CAAA;IAC7C,iEAAmD,CAAA;IACnD,0DAA4C,CAAA;IAC5C,8DAAgD,CAAA;IAChD,6EAA+D,CAAA;IAC/D,+FAAiF,CAAA;IACjF,6FAA+E,CAAA;IAC/E,qFAAuE,CAAA;IACvE,mGAAqF,CAAA;IACrF,2FAA6E,CAAA;IAC7E,qHAAuG,CAAA;IACvG,4CAA8B,CAAA;IAC9B,8DAAgD,CAAA;IAChD,6DAA+C,CAAA;IAC/C,iEAAmD,CAAA;AACrD,CAAC,EArBW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAqBrB","sourcesContent":["/**\n * Used to describe privilege list of an app.\n */\nexport enum Privileges {\n Basemaps = \"portal:apikey:basemaps\",\n Demographics = \"premium:user:demographics\",\n Elevation = \"premium:user:elevation\",\n FeatureReport = \"premium:user:featurereport\",\n Geocode = \"premium:user:geocode\",\n GeocodeStored = \"premium:user:geocode:stored\",\n GeocodeTemporary = \"premium:user:geocode:temporary\",\n GeoEnrichment = \"premium:user:geoenrichment\",\n NetworkAnalysis = \"premium:user:networkanalysis\",\n NetworkAnalysisRouting = \"premium:user:networkanalysis:routing\",\n NetworkAnalysisOptimizedRouting = \"premium:user:networkanalysis:optimizedrouting\",\n NetworkAnalysisClosestFacility = \"premium:user:networkanalysis:closestfacility\",\n NetworkAnalysisServiceArea = \"premium:user:networkanalysis:servicearea\",\n NetworkAnalysisLocationalLocation = \"premium:user:networkanalysis:locationallocation\",\n NetworkAnalysisVehicleRouting = \"premium:user:networkanalysis:vehiclerouting\",\n NetworkAnalysisOriginDestinationCostMatrix = \"premium:user:networkanalysis:origindestinationcostmatrix\",\n Places = \"premium:user:places\",\n SpatialAnalysis = \"premium:user:spatialanalysis\",\n GeoAnalytics = \"premium:publisher:geoanalytics\",\n RasterAnalysis = \"premium:publisher:rasteranalysis\"\n}\n"]}
1
+ {"version":3,"file":"privileges.js","sourceRoot":"","sources":["../../../../src/shared/enum/privileges.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Used to describe privilege list of an app. For a comlete list of privileges, see the [list of privileges in the security and authentication guide](https://developers.arcgis.com/documentation/security-and-authentication/reference/privileges/#list-of-privileges).\n */\nexport type Privileges = string[];\n"]}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateApiKeyToken = void 0;
4
+ const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
5
+ const getRegisteredAppInfo_js_1 = require("./getRegisteredAppInfo.js");
6
+ const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
7
+ async function generateApiKeyToken(options) {
8
+ const portal = (0, arcgis_rest_portal_1.getPortalUrl)(options);
9
+ const url = `${portal}/oauth2/token`;
10
+ const appInfo = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)({
11
+ itemId: options.itemId,
12
+ authentication: options.authentication
13
+ });
14
+ const params = {
15
+ client_id: appInfo.client_id,
16
+ client_secret: appInfo.client_secret,
17
+ apiToken: options.apiKey,
18
+ regenerateApiToken: true,
19
+ grant_type: "client_credentials"
20
+ };
21
+ return (0, arcgis_rest_request_1.request)(url, {
22
+ authentication: options.authentication,
23
+ params
24
+ });
25
+ }
26
+ exports.generateApiKeyToken = generateApiKeyToken;
27
+ //# sourceMappingURL=generateApiKeyToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":";;;AAAA,mEAImC;AACnC,uEAAiE;AACjE,iEAAwD;AASjD,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAoB,EAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,OAAO,IAAA,6BAAO,EAAC,GAAG,EAAE;QAClB,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAvBD,kDAuBC","sourcesContent":["import {\n request,\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { getRegisteredAppInfo } from \"./getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\n\nexport interface IGenerateApiKeyTokenOptions extends IRequestOptions {\n itemId: string;\n apiKey: 1 | 2;\n portal?: string;\n authentication: IAuthenticationManager;\n}\n\nexport async function generateApiKeyToken(\n options: IGenerateApiKeyTokenOptions\n): Promise<{ access_token: string; expires_in: number }> {\n const portal = getPortalUrl(options);\n const url = `${portal}/oauth2/token`;\n\n const appInfo = await getRegisteredAppInfo({\n itemId: options.itemId,\n authentication: options.authentication\n });\n\n const params = {\n client_id: appInfo.client_id,\n client_secret: appInfo.client_secret,\n apiToken: options.apiKey,\n regenerateApiToken: true,\n grant_type: \"client_credentials\"\n };\n\n return request(url, {\n authentication: options.authentication,\n params\n });\n}\n"]}
@@ -1,13 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.filterKeys = exports.extractBaseRequestOptions = exports.appToOAuthAppProperties = exports.appToApiKeyProperties = exports.registeredAppResponseToApp = exports.stringifyArrays = exports.arePrivilegesValid = void 0;
4
- const privileges_js_1 = require("./enum/privileges.js");
5
- /**
6
- * @internal
7
- * Used to check privileges validity.
8
- */
9
- const arePrivilegesValid = (privileges) => privileges.every((element) => Object.values(privileges_js_1.Privileges).includes(element));
10
- exports.arePrivilegesValid = arePrivilegesValid;
3
+ exports.buildExpirationDateParams = exports.generateOptionsToSlots = exports.generateApiKeyTokens = exports.slotForKey = exports.filterKeys = exports.extractBaseRequestOptions = exports.appToOAuthAppProperties = exports.appToApiKeyProperties = exports.registeredAppResponseToApp = exports.stringifyArrays = void 0;
4
+ const generateApiKeyToken_js_1 = require("./generateApiKeyToken.js");
11
5
  /**
12
6
  * @internal
13
7
  * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.
@@ -30,7 +24,8 @@ function registeredAppResponseToApp(response) {
30
24
  "apnsProdCert",
31
25
  "apnsSandboxCert",
32
26
  "gcmApiKey",
33
- "isBeta"
27
+ "isBeta",
28
+ "customAppLoginShowTriage"
34
29
  ];
35
30
  const dateKeys = ["modified", "registered"];
36
31
  return Object.keys(response)
@@ -51,13 +46,11 @@ exports.registeredAppResponseToApp = registeredAppResponseToApp;
51
46
  * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is "apikey".
52
47
  */
53
48
  function appToApiKeyProperties(response) {
54
- if (response.appType !== "apikey" || !("apiKey" in response)) {
55
- throw new Error("Item is not an API key.");
56
- }
57
- delete response.client_id;
58
49
  delete response.client_secret;
59
50
  delete response.redirect_uris;
60
51
  delete response.appType;
52
+ delete response.customAppLoginShowTriage;
53
+ delete response.apiKey;
61
54
  return response;
62
55
  }
63
56
  exports.appToApiKeyProperties = appToApiKeyProperties;
@@ -66,12 +59,14 @@ exports.appToApiKeyProperties = appToApiKeyProperties;
66
59
  * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.
67
60
  */
68
61
  function appToOAuthAppProperties(response) {
69
- if (response.appType === "apikey") {
70
- throw new Error("Item is not an OAuth 2.0 app.");
71
- }
72
62
  delete response.appType;
73
63
  delete response.httpReferrers;
74
64
  delete response.privileges;
65
+ delete response.apiKey;
66
+ delete response.customAppLoginShowTriage;
67
+ delete response.isPersonalAPIToken;
68
+ delete response.apiToken1Active;
69
+ delete response.apiToken2Active;
75
70
  return response;
76
71
  }
77
72
  exports.appToOAuthAppProperties = appToOAuthAppProperties;
@@ -107,4 +102,66 @@ function filterKeys(object, includedKeys) {
107
102
  }, {});
108
103
  }
109
104
  exports.filterKeys = filterKeys;
105
+ /**
106
+ * Used to determine if a generated key is in slot 1 or slot 2 key.
107
+ */
108
+ function slotForKey(key) {
109
+ return parseInt(key.substring(key.length - 10, key.length - 9));
110
+ }
111
+ exports.slotForKey = slotForKey;
112
+ /**
113
+ * @internal
114
+ * Used to generate tokens in slot 1 and/or 2 of an API key.
115
+ */
116
+ function generateApiKeyTokens(itemId, slots, requestOptions) {
117
+ return Promise.all(slots.map((slot) => {
118
+ return (0, generateApiKeyToken_js_1.generateApiKeyToken)(Object.assign({ itemId, apiKey: slot }, requestOptions));
119
+ })).then((responses) => {
120
+ return responses
121
+ .map((responses) => responses.access_token)
122
+ .reduce((obj, token, index) => {
123
+ obj[`accessToken${slotForKey(token)}`] = token;
124
+ return obj;
125
+ }, {});
126
+ });
127
+ }
128
+ exports.generateApiKeyTokens = generateApiKeyTokens;
129
+ /**
130
+ * @internal
131
+ * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.
132
+ */
133
+ function generateOptionsToSlots(generateToken1, generateToken2) {
134
+ const slots = [];
135
+ if (generateToken1) {
136
+ slots.push(1);
137
+ }
138
+ if (generateToken2) {
139
+ slots.push(2);
140
+ }
141
+ return slots;
142
+ }
143
+ exports.generateOptionsToSlots = generateOptionsToSlots;
144
+ /**
145
+ * @internal
146
+ * Build params for updating expiration dates
147
+ */
148
+ function buildExpirationDateParams(requestOptions, fillDefaults) {
149
+ const updateparams = {};
150
+ if (requestOptions.apiToken1ExpirationDate) {
151
+ updateparams.apiToken1ExpirationDate =
152
+ requestOptions.apiToken1ExpirationDate;
153
+ }
154
+ if (requestOptions.apiToken2ExpirationDate) {
155
+ updateparams.apiToken2ExpirationDate =
156
+ requestOptions.apiToken2ExpirationDate;
157
+ }
158
+ if (fillDefaults && !updateparams.apiToken1ExpirationDate) {
159
+ updateparams.apiToken1ExpirationDate = -1;
160
+ }
161
+ if (fillDefaults && !updateparams.apiToken2ExpirationDate) {
162
+ updateparams.apiToken2ExpirationDate = -1;
163
+ }
164
+ return updateparams;
165
+ }
166
+ exports.buildExpirationDateParams = buildExpirationDateParams;
110
167
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/shared/helpers.ts"],"names":[],"mappings":";;;AACA,wDAAkD;AAKlD;;;GAGG;AACI,MAAM,kBAAkB,GAAG,CAChC,UAA+C,EACtC,EAAE,CACX,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAC3B,MAAM,CAAC,MAAM,CAAC,0BAAU,CAAC,CAAC,QAAQ,CAAC,OAAc,CAAC,CACnD,CAAC;AALS,QAAA,kBAAkB,sBAK3B;AAEJ;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,cAA+B,EAAE,EAAE;IACjE,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um/privileges.js\";\nimport { IRegisteredAppResponse, IApp } from \"./types/appType.js\";\nimport { IApiKeyInfo } from \"./types/apiKeyType.js\";\nimport { IOAuthAppInfo } from \"./types/oAuthType.js\";\n\n/**\n * @internal\n * Used to check privileges validity.\n */\nexport const arePrivilegesValid = (\n privileges: Array<Privileges | `${Privileges}`>\n): boolean =>\n privileges.every((element) =>\n Object.values(Privileges).includes(element as any)\n );\n\n/**\n * @internal\n * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.\n */\nexport const stringifyArrays = (requestOptions: IRequestOptions) => {\n Object.entries(requestOptions.params).forEach((entry) => {\n const [key, value] = entry;\n if (value.constructor.name === \"Array\") {\n requestOptions.params[key] = JSON.stringify(value);\n }\n });\n};\n\n/**\n * @internal\n * Used to convert {@linkcode IRegisteredAppResponse} to {@linkcode IApp}.\n */\nexport function registeredAppResponseToApp(\n response: IRegisteredAppResponse\n): IApp {\n const omittedKeys = [\n \"apnsProdCert\",\n \"apnsSandboxCert\",\n \"gcmApiKey\",\n \"isBeta\"\n ];\n const dateKeys = [\"modified\", \"registered\"];\n\n return Object.keys(response)\n .filter((key) => !omittedKeys.includes(key))\n .reduce((obj: any, key) => {\n if (dateKeys.includes(key)) {\n obj[key] = new Date((response as any)[key]);\n } else {\n obj[key] = (response as any)[key];\n }\n return obj;\n }, {});\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is \"apikey\".\n */\nexport function appToApiKeyProperties(response: IApp): IApiKeyInfo {\n if (response.appType !== \"apikey\" || !(\"apiKey\" in response)) {\n throw new Error(\"Item is not an API key.\");\n }\n\n delete response.client_id;\n delete response.client_secret;\n delete response.redirect_uris;\n delete response.appType;\n\n return response as IApiKeyInfo;\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.\n */\nexport function appToOAuthAppProperties(response: IApp): IOAuthAppInfo {\n if (response.appType === \"apikey\") {\n throw new Error(\"Item is not an OAuth 2.0 app.\");\n }\n\n delete response.appType;\n delete response.httpReferrers;\n delete response.privileges;\n\n return response as IOAuthAppInfo;\n}\n\n/**\n * @internal\n * Used to extract base request options from a hybrid option and exclude `params` and `authentication`.\n */\nexport function extractBaseRequestOptions<T extends IRequestOptions>(\n options: T\n): Partial<IRequestOptions> {\n const requestOptionsProperties: Array<keyof T> = [\n \"credentials\",\n \"headers\",\n \"hideToken\",\n \"httpMethod\",\n \"maxUrlLength\",\n \"portal\",\n \"rawResponse\",\n \"signal\",\n \"suppressWarnings\"\n ];\n\n return filterKeys(options, requestOptionsProperties);\n}\n\n/**\n * @internal\n * Used to create a new object including only specified keys from another object.\n */\nexport function filterKeys<T extends object>(\n object: T,\n includedKeys: Array<keyof T>\n): any {\n return includedKeys.reduce(\n (obj: { [key: string | number | symbol]: any }, ele) => {\n if (ele in object) {\n obj[ele] = object[ele];\n }\n return obj;\n },\n {}\n );\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/shared/helpers.ts"],"names":[],"mappings":";;;AAOA,qEAA+D;AAE/D;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,cAA+B,EAAE,EAAE;IACjE,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;QAC3B,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;YACtC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEF;;;GAGG;AACH,SAAgB,0BAA0B,CACxC,QAAgC;IAEhC,MAAM,WAAW,GAAG;QAClB,cAAc;QACd,iBAAiB;Q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ager\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisteredAppResponse, IApp } from \"./types/appType.js\";\nimport { IApiKeyInfo } from \"./types/apiKeyType.js\";\nimport { IOAuthAppInfo } from \"./types/oAuthType.js\";\nimport { generateApiKeyToken } from \"./generateApiKeyToken.js\";\n\n/**\n * @internal\n * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.\n */\nexport const stringifyArrays = (requestOptions: IRequestOptions) => {\n Object.entries(requestOptions.params).forEach((entry) => {\n const [key, value] = entry;\n if (value.constructor.name === \"Array\") {\n requestOptions.params[key] = JSON.stringify(value);\n }\n });\n};\n\n/**\n * @internal\n * Used to convert {@linkcode IRegisteredAppResponse} to {@linkcode IApp}.\n */\nexport function registeredAppResponseToApp(\n response: IRegisteredAppResponse\n): IApp {\n const omittedKeys = [\n \"apnsProdCert\",\n \"apnsSandboxCert\",\n \"gcmApiKey\",\n \"isBeta\",\n \"customAppLoginShowTriage\"\n ];\n const dateKeys = [\"modified\", \"registered\"];\n\n return Object.keys(response)\n .filter((key) => !omittedKeys.includes(key))\n .reduce((obj: any, key) => {\n if (dateKeys.includes(key)) {\n obj[key] = new Date((response as any)[key]);\n } else {\n obj[key] = (response as any)[key];\n }\n return obj;\n }, {});\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is \"apikey\".\n */\nexport function appToApiKeyProperties(response: IApp): IApiKeyInfo {\n delete response.client_secret;\n delete response.redirect_uris;\n delete response.appType;\n delete (response as any).customAppLoginShowTriage;\n delete response.apiKey;\n\n return response as IApiKeyInfo;\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.\n */\nexport function appToOAuthAppProperties(response: IApp): IOAuthAppInfo {\n delete response.appType;\n delete response.httpReferrers;\n delete response.privileges;\n delete response.apiKey;\n delete (response as any).customAppLoginShowTriage;\n delete response.isPersonalAPIToken;\n delete response.apiToken1Active;\n delete response.apiToken2Active;\n\n return response as IOAuthAppInfo;\n}\n\n/**\n * @internal\n * Used to extract base request options from a hybrid option and exclude `params` and `authentication`.\n */\nexport function extractBaseRequestOptions<T extends IRequestOptions>(\n options: T\n): Partial<IRequestOptions> {\n const requestOptionsProperties: Array<keyof T> = [\n \"credentials\",\n \"headers\",\n \"hideToken\",\n \"httpMethod\",\n \"maxUrlLength\",\n \"portal\",\n \"rawResponse\",\n \"signal\",\n \"suppressWarnings\"\n ];\n\n return filterKeys(options, requestOptionsProperties);\n}\n\n/**\n * @internal\n * Used to create a new object including only specified keys from another object.\n */\nexport function filterKeys<T extends object>(\n object: T,\n includedKeys: Array<keyof T>\n): any {\n return includedKeys.reduce(\n (obj: { [key: string | number | symbol]: any }, ele) => {\n if (ele in object) {\n obj[ele] = object[ele];\n }\n return obj;\n },\n {}\n );\n}\n\n/**\n * Used to determine if a generated key is in slot 1 or slot 2 key.\n */\nexport function slotForKey(key: string) {\n return parseInt(key.substring(key.length - 10, key.length - 9));\n}\n\ninterface IGenerateApiKeyTokenOptions extends IRequestOptions {\n authentication: IAuthenticationManager;\n}\n\n/**\n * @internal\n * Used to generate tokens in slot 1 and/or 2 of an API key.\n */\nexport function generateApiKeyTokens(\n itemId: string,\n slots: Array<1 | 2>,\n requestOptions: IGenerateApiKeyTokenOptions\n) {\n return Promise.all(\n slots.map((slot) => {\n return generateApiKeyToken({\n itemId,\n apiKey: slot,\n ...requestOptions\n });\n })\n ).then((responses) => {\n return responses\n .map((responses) => responses.access_token)\n .reduce((obj, token, index) => {\n obj[`accessToken${slotForKey(token)}`] = token;\n return obj;\n }, {} as { [key: string]: string });\n });\n}\n\n/**\n * @internal\n * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.\n */\nexport function generateOptionsToSlots(\n generateToken1: boolean,\n generateToken2: boolean\n): Array<1 | 2> {\n const slots: Array<1 | 2> = [];\n if (generateToken1) {\n slots.push(1);\n }\n if (generateToken2) {\n slots.push(2);\n }\n return slots;\n}\n\ntype expirationDateParams =\n | {\n apiToken1ExpirationDate: Date | -1;\n apiToken2ExpirationDate: Date | -1;\n }\n | {\n apiToken1ExpirationDate: Date | -1;\n }\n | {\n apiToken2ExpirationDate: Date | -1;\n }\n | {};\n\n/**\n * @internal\n * Build params for updating expiration dates\n */\nexport function buildExpirationDateParams(\n requestOptions: {\n apiToken1ExpirationDate?: Date;\n apiToken2ExpirationDate?: Date;\n },\n fillDefaults?: boolean\n): expirationDateParams {\n const updateparams: any = {};\n if (requestOptions.apiToken1ExpirationDate) {\n updateparams.apiToken1ExpirationDate =\n requestOptions.apiToken1ExpirationDate;\n }\n\n if (requestOptions.apiToken2ExpirationDate) {\n updateparams.apiToken2ExpirationDate =\n requestOptions.apiToken2ExpirationDate;\n }\n\n if (fillDefaults && !updateparams.apiToken1ExpirationDate) {\n updateparams.apiToken1ExpirationDate = -1;\n }\n\n if (fillDefaults && !updateparams.apiToken2ExpirationDate) {\n updateparams.apiToken2ExpirationDate = -1;\n }\n return updateparams;\n}\n"]}
@@ -43,10 +43,6 @@ const helpers_js_1 = require("./helpers.js");
43
43
  * @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.
44
44
  */
45
45
  async function registerApp(requestOptions) {
46
- // privileges validation
47
- if (!(0, helpers_js_1.arePrivilegesValid)(requestOptions.privileges)) {
48
- throw new Error("The `privileges` option contains invalid privileges.");
49
- }
50
46
  // build params
51
47
  const options = (0, arcgis_rest_request_1.appendCustomParams)(requestOptions, [
52
48
  "itemId",
@@ -1 +1 @@
1
- {"version":3,"file":"registerApp.js","sourceRoot":"","sources":["../../../src/shared/registerApp.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAwE;AACxE,iEAAwD;AAMxD,6CAIsB;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,wBAAwB;IACxB,IAAI,CAAC,IAAA,+BAAkB,EAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QAClD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACzE;IAED,eAAe;IACf,MAAM,OAAO,GAAG,IAAA,wCAAkB,EAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC;IAC1D,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;IAE1B,MAAM,qBAAqB,GAA2B,MAAM,IAAA,6BAAO,EACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,IAAA,uCAA0B,EAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC;AA7BD,kCA6BC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, appendCustomParams } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport {\n IApp,\n IRegisterAppOptions,\n IRegisteredAppResponse\n} from \"./types/appType.js\";\nimport {\n arePrivilegesValid,\n stringifyArrays,\n registeredAppResponseToApp\n} from \"./helpers.js\";\n\n/**\n * Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.\n *\n * Accepted app types:\n * - apikey\n * - multiple\n * - browser\n * - server\n * - native\n *\n * ```js\n * import { registerApp, IApp } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * registerApp({\n * itemId: \"xyz_itemId\",\n * appType: \"multiple\",\n * redirect_uris: [\"http://localhost:3000/\"],\n * httpReferrers: [\"http://localhost:3000/\"],\n * privileges: [Privileges.Geocode, Privileges.FeatureReport],\n * authentication: authSession\n * }).then((registeredApp: IApp) => {\n * // => {client_id: \"xyz_id\", client_secret: \"xyz_secret\", ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode registerApp | registerApp()}, including necessary params to register an app and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.\n */\nexport async function registerApp(\n requestOptions: IRegisterAppOptions\n): Promise<IApp> {\n // privileges validation\n if (!arePrivilegesValid(requestOptions.privileges)) {\n throw new Error(\"The `privileges` option contains invalid privileges.\");\n }\n\n // build params\n const options = appendCustomParams(requestOptions, [\n \"itemId\",\n \"appType\",\n \"redirect_uris\",\n \"httpReferrers\",\n \"privileges\"\n ]);\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + \"/oauth2/registerApp\";\n options.httpMethod = \"POST\";\n options.params.f = \"json\";\n\n const registeredAppResponse: IRegisteredAppResponse = await request(\n url,\n options\n );\n\n return registeredAppResponseToApp(registeredAppResponse);\n}\n"]}
1
+ {"version":3,"file":"registerApp.js","sourceRoot":"","sources":["../../../src/shared/registerApp.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAwE;AACxE,iEAAwD;AAMxD,6CAA2E;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,eAAe;IACf,MAAM,OAAO,GAAG,IAAA,wCAAkB,EAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC;IAC1D,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;IAE1B,MAAM,qBAAqB,GAA2B,MAAM,IAAA,6BAAO,EACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,IAAA,uCAA0B,EAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC;AAxBD,kCAwBC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, appendCustomParams } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport {\n IApp,\n IRegisterAppOptions,\n IRegisteredAppResponse\n} from \"./types/appType.js\";\nimport { stringifyArrays, registeredAppResponseToApp } from \"./helpers.js\";\n\n/**\n * Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.\n *\n * Accepted app types:\n * - apikey\n * - multiple\n * - browser\n * - server\n * - native\n *\n * ```js\n * import { registerApp, IApp } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * registerApp({\n * itemId: \"xyz_itemId\",\n * appType: \"multiple\",\n * redirect_uris: [\"http://localhost:3000/\"],\n * httpReferrers: [\"http://localhost:3000/\"],\n * privileges: [Privileges.Geocode, Privileges.FeatureReport],\n * authentication: authSession\n * }).then((registeredApp: IApp) => {\n * // => {client_id: \"xyz_id\", client_secret: \"xyz_secret\", ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode registerApp | registerApp()}, including necessary params to register an app and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.\n */\nexport async function registerApp(\n requestOptions: IRegisterAppOptions\n): Promise<IApp> {\n // build params\n const options = appendCustomParams(requestOptions, [\n \"itemId\",\n \"appType\",\n \"redirect_uris\",\n \"httpReferrers\",\n \"privileges\"\n ]);\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + \"/oauth2/registerApp\";\n options.httpMethod = \"POST\";\n options.params.f = \"json\";\n\n const registeredAppResponse: IRegisteredAppResponse = await request(\n url,\n options\n );\n\n return registeredAppResponseToApp(registeredAppResponse);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"apiKeyType.js","sourceRoot":"","sources":["../../../../src/shared/types/apiKeyType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IAuthenticationManager,\n IRequestOptions,\n ISpatialReference\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisterAppOptions, IApp } from \"./appType.js\";\nimport { Privileges } from \"../enum/privileges.js\";\nimport { IItem } from \"@esri/arcgis-rest-portal\";\n\n/**\n * Options to register an API Key.\n */\nexport interface ICreateApiKeyOptions\n extends Omit<\n IRegisterAppOptions,\n \"itemId\" | \"redirect_uris\" | \"appType\" | \"httpReferrers\"\n > {\n httpReferrers?: string[];\n title: string;\n owner?: string;\n typeKeywords?: string[];\n description?: string;\n snippet?: string;\n documentation?: string;\n extent?: number[][];\n categories?: string[];\n spatialReference?: ISpatialReference;\n culture?: string;\n properties?: any;\n url?: string;\n tags?: string[];\n}\n\n/**\n * Options to retrieve an API Key.\n */\nexport interface IGetApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Represent only the API key related properties from {@linkcode IApp}.\n */\nexport interface IApiKeyInfo\n extends Omit<\n IApp,\n \"client_id\" | \"client_secret\" | \"redirect_uris\" | \"appType\"\n > {\n apiKey: string;\n}\n\n/**\n * Return value of {@linkcode createApiKey}, {@linkcode getApiKey}, {@linkcode updateApiKey} representing an API Key entity.\n */\nexport interface IApiKeyResponse extends IApiKeyInfo {\n /**\n * Represent item info attached to this API Key.\n */\n item: IItem;\n}\n\n/**\n * Options to update an API Key.\n */\nexport interface IUpdateApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key will be updated.\n */\n itemId: string;\n /**\n * Override previous `httpReferrers` if this value is provided.\n */\n httpReferrers?: string[];\n /**\n * Override previous `privileges` if this value is provided.\n */\n privileges?: Array<Privileges | `${Privileges}`>;\n}\n\n/**\n * Options to delete an API key.\n */\nexport interface IDeleteApiKeyOption extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be removed.\n */\n itemId: string;\n}\n\n/**\n * Response of API key deletion.\n */\nexport interface IDeleteApiKeyResponse {\n /**\n * itemId of which API key has been removed.\n */\n itemId: string;\n success: boolean;\n}\n"]}
1
+ {"version":3,"file":"apiKeyType.js","sourceRoot":"","sources":["../../../../src/shared/types/apiKeyType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IAuthenticationManager,\n IRequestOptions,\n ISpatialReference\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisterAppOptions, IApp } from \"./appType.js\";\nimport { Privileges } from \"../enum/privileges.js\";\nimport { IItem } from \"@esri/arcgis-rest-portal\";\n\n/**\n * Options to register an API Key.\n */\nexport interface ICreateApiKeyOptions\n extends Omit<\n IRegisterAppOptions,\n \"itemId\" | \"redirect_uris\" | \"appType\" | \"httpReferrers\"\n > {\n httpReferrers?: string[];\n title: string;\n owner?: string;\n typeKeywords?: string[];\n description?: string;\n snippet?: string;\n documentation?: string;\n extent?: number[][];\n categories?: string[];\n spatialReference?: ISpatialReference;\n culture?: string;\n properties?: any;\n url?: string;\n tags?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to retrieve an API Key.\n */\nexport interface IGetApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Represent only the API key related properties from {@linkcode IApp}.\n */\nexport interface IApiKeyInfo\n extends Omit<IApp, \"client_secret\" | \"redirect_uris\" | \"appType\"> {}\n\n/**\n * Return value of {@linkcode createApiKey}, {@linkcode getApiKey}, {@linkcode updateApiKey} representing an API Key entity. `accessToken1`/`accessToken2` properties are only available when `generateToken1`/`generateToken2` are `true`.\n */\nexport interface IApiKeyResponse extends IApiKeyInfo {\n /**\n * Represent item info attached to this API Key.\n */\n item: IItem;\n accessToken1?: null | string;\n accessToken2?: null | string;\n}\n\n/**\n * Options to update an API Key.\n */\nexport interface IUpdateApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key will be updated.\n */\n itemId: string;\n /**\n * Override previous `httpReferrers` if this value is provided.\n */\n httpReferrers?: string[];\n /**\n * Override previous `privileges` if this value is provided.\n */\n privileges?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to delete an API key.\n */\nexport interface IDeleteApiKeyOption extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be removed.\n */\n itemId: string;\n}\n\n/**\n * Response of API key deletion.\n */\nexport interface IDeleteApiKeyResponse {\n /**\n * itemId of which API key has been removed.\n */\n itemId: string;\n success: boolean;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"appType.js","sourceRoot":"","sources":["../../../../src/shared/types/appType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { UnixTime } from \"@esri/arcgis-rest-portal\";\nimport { Privileges } from \"../enum/privileges.js\";\n\n/**\n * Accepted app types.\n */\nexport type AppType = \"apikey\" | \"browser\" | \"native\" | \"server\" | \"multiple\";\n\n/**\n * Options to register an app.\n */\nexport interface IRegisterAppOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * itemId that the newly registered app will be based on.\n */\n itemId: string;\n /**\n * App types. For more info, refer to {@linkcode AppType}.\n */\n appType: AppType;\n /**\n * Redirect URIs set for this app.\n */\n redirect_uris: string[];\n /**\n * Http Referrers set for this app.\n */\n httpReferrers: string[];\n /**\n * Privilege lists. For more info, refer to {@linkcode Privileges}.\n */\n privileges: Array<Privileges | `${Privileges}`>;\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n}\n\n/**\n * Options to retrieve an app.\n */\nexport interface IGetAppInfoOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which app to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Raw response of app related endpoints calls.\n */\nexport interface IRegisteredAppResponse {\n itemId: string;\n /**\n * Only to be present if appType is apikey\n */\n apiKey?: string;\n appType: AppType;\n client_id: string;\n client_secret: string;\n httpReferrers: string[];\n redirect_uris: string[];\n privileges: Array<Privileges | `${Privileges}`>;\n registered: UnixTime;\n modified: UnixTime;\n apnsProdCert: any;\n apnsSandboxCert: any;\n gcmApiKey: any;\n isBeta: boolean;\n}\n\n/**\n * Return value of {@linkcode registerApp} and {@linkcode getRegisteredAppInfo} representing an app entity.\n */\nexport interface IApp\n extends Omit<\n IRegisteredAppResponse,\n | \"registered\"\n | \"modified\"\n | \"apnsProdCert\"\n | \"apnsSandboxCert\"\n | \"gcmApiKey\"\n | \"isBeta\"\n > {\n registered: Date;\n modified: Date;\n}\n\n/**\n * Options to unregister an app.\n */\nexport interface IUnregisterAppOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which app to be unregistered.\n */\n itemId: string;\n}\n\n/**\n * Response of app un-registration.\n */\nexport interface IUnregisterAppResponse {\n success: true | false;\n /**\n * itemId of which app has been unregistered.\n */\n itemId: string;\n}\n"]}
1
+ {"version":3,"file":"appType.js","sourceRoot":"","sources":["../../../../src/shared/types/appType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { UnixTime } from \"@esri/arcgis-rest-portal\";\nimport { Privileges } from \"../enum/privileges.js\";\n\n/**\n * Accepted app types.\n */\nexport type AppType = \"apikey\" | \"browser\" | \"native\" | \"server\" | \"multiple\";\n\n/**\n * Options to register an app.\n */\nexport interface IRegisterAppOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * itemId that the newly registered app will be based on.\n */\n itemId: string;\n /**\n * App types. For more info, refer to {@linkcode AppType}.\n */\n appType: AppType;\n /**\n * Redirect URIs set for this app.\n */\n redirect_uris: string[];\n /**\n * Http Referrers set for this app.\n */\n httpReferrers: string[];\n /**\n * Privilege lists. For more info, refer to {@linkcode Privileges}.\n */\n privileges: Privileges;\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n}\n\n/**\n * Options to retrieve an app.\n */\nexport interface IGetAppInfoOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which app to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Raw response of app related endpoints calls.\n */\nexport interface IRegisteredAppResponse {\n itemId: string;\n /**\n * Only to be present if appType is apikey\n */\n apiKey?: string;\n appType: AppType;\n client_id: string;\n client_secret: string;\n httpReferrers: string[];\n redirect_uris: string[];\n privileges: string[];\n registered: UnixTime;\n modified: UnixTime;\n apnsProdCert: any;\n apnsSandboxCert: any;\n gcmApiKey: any;\n isBeta: boolean;\n customAppLoginShowTriage: boolean;\n isPersonalAPIToken: boolean;\n apiToken1Active: boolean;\n apiToken2Active: boolean;\n}\n\n/**\n * Return value of {@linkcode registerApp} and {@linkcode getRegisteredAppInfo} representing an app entity.\n */\nexport interface IApp\n extends Omit<\n IRegisteredAppResponse,\n | \"registered\"\n | \"modified\"\n | \"apnsProdCert\"\n | \"apnsSandboxCert\"\n | \"gcmApiKey\"\n | \"isBeta\"\n | \"customAppLoginShowTriage\"\n > {\n registered: Date;\n modified: Date;\n}\n\n/**\n * Options to unregister an app.\n */\nexport interface IUnregisterAppOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which app to be unregistered.\n */\n itemId: string;\n}\n\n/**\n * Response of app un-registration.\n */\nexport interface IUnregisterAppResponse {\n success: true | false;\n /**\n * itemId of which app has been unregistered.\n */\n itemId: string;\n}\n"]}
@@ -39,20 +39,21 @@ const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
39
39
  * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.
40
40
  */
41
41
  async function updateApiKey(requestOptions) {
42
- // privileges validation
43
- if (requestOptions.privileges &&
44
- !(0, helpers_js_1.arePrivilegesValid)(requestOptions.privileges)) {
45
- throw new Error("The `privileges` option contains invalid privileges.");
46
- }
47
42
  requestOptions.httpMethod = "POST";
48
- // get app
49
43
  const baseRequestOptions = (0, helpers_js_1.extractBaseRequestOptions)(requestOptions); // get base requestOptions snapshot
44
+ /**
45
+ * step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.
46
+ */
47
+ if (requestOptions.apiToken1ExpirationDate ||
48
+ requestOptions.apiToken2ExpirationDate) {
49
+ const updateParams = (0, helpers_js_1.buildExpirationDateParams)(requestOptions);
50
+ await (0, arcgis_rest_portal_1.updateItem)(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: requestOptions.itemId }, updateParams), authentication: requestOptions.authentication }));
51
+ }
52
+ /**
53
+ * step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.
54
+ */
50
55
  const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
51
56
  const appResponse = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)(getAppOption);
52
- // appType must be APIKey to continue
53
- if (appResponse.appType !== "apikey" || !("apiKey" in appResponse)) {
54
- throw new Error("Item is not an API key.");
55
- }
56
57
  const clientId = appResponse.client_id;
57
58
  const options = (0, arcgis_rest_request_1.appendCustomParams)(Object.assign(Object.assign({}, appResponse), requestOptions), // object with the custom params to look in
58
59
  ["privileges", "httpReferrers"] // keys you want copied to the params object
@@ -63,9 +64,19 @@ async function updateApiKey(requestOptions) {
63
64
  const url = (0, arcgis_rest_portal_1.getPortalUrl)(options) + `/oauth2/apps/${clientId}/update`;
64
65
  // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
65
66
  const updateResponse = await (0, arcgis_rest_request_1.request)(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
66
- const app = (0, helpers_js_1.registeredAppResponseToApp)(Object.assign(Object.assign({}, updateResponse), { apiKey: appResponse.apiKey }));
67
- const itemInfo = await (0, arcgis_rest_portal_1.getItem)(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
68
- return Object.assign(Object.assign({}, (0, helpers_js_1.appToApiKeyProperties)(app)), { item: itemInfo });
67
+ /**
68
+ * step 3: get the updated item info to return to the user.
69
+ */
70
+ const updatedItemInfo = await (0, arcgis_rest_portal_1.getItem)(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
71
+ /**
72
+ * step 4: generate tokens if requested
73
+ */
74
+ const generatedTokens = await (0, helpers_js_1.generateApiKeyTokens)(requestOptions.itemId, (0, helpers_js_1.generateOptionsToSlots)(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
75
+ /**
76
+ * step 5: get updated registered app info
77
+ */
78
+ const updatedRegisteredAppResponse = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)(Object.assign(Object.assign({}, baseRequestOptions), { itemId: requestOptions.itemId, authentication: requestOptions.authentication }));
79
+ return Object.assign(Object.assign(Object.assign({}, generatedTokens), (0, helpers_js_1.appToApiKeyProperties)(updatedRegisteredAppResponse)), { item: updatedItemInfo });
69
80
  }
70
81
  exports.updateApiKey = updateApiKey;
71
82
  //# sourceMappingURL=updateApiKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateApiKey.js","sourceRoot":"","sources":["../../src/updateApiKey.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAMhB,8EAAwE;AACxE,oDAM6B;AAC7B,iEAAiE;AACjE,mEAAwE;AAOxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACI,KAAK,UAAU,YAAY,CAChC,cAAoC;IAEp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AAM,EAAE,WAAW,CAAC,MAAM,IAC1B,CAAC;IAEH,MAAM,QAAQ,GAAG,MAAM,IAAA,4BAAO,EAAC,cAAc,CAAC,MAAM,kCAC/C,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,IACrB,CAAC;IAEH,uCACK,IAAA,kCAAqB,EAAC,GAAG,CAAC,KAC7B,IAAI,EAAE,QAAQ,IACd;AACJ,CAAC;AA7DD,oCA6DC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IApiKeyResponse,\n IUpdateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions,\n arePrivilegesValid,\n stringifyArrays,\n registeredAppResponseToApp\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\n\n/**\n * Used to update an API key.\n *\n * Notes about `privileges` and `httpReferrers` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * updateApiKey({\n * itemId: \"xyz_itemId\",\n * privileges: [Privileges.Geocode],\n * httpReferrers: [], // httpReferrers will be set to be empty\n * authentication: authSession\n * }).then((updatedAPIKey: IApiKeyResponse) => {\n * // => {apiKey: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateApiKey | updateApiKey()}, including `itemId` of which API key to be operated on, optional new `privileges`, optional new `httpReferrers` and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.\n */\nexport async function updateApiKey(\n requestOptions: IUpdateApiKeyOptions\n): Promise<IApiKeyResponse> {\n // privileges validation\n if (\n requestOptions.privileges &&\n !arePrivilegesValid(requestOptions.privileges)\n ) {\n throw new Error(\"The `privileges` option contains invalid privileges.\");\n }\n\n requestOptions.httpMethod = \"POST\";\n\n // get app\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n\n const appResponse = await getRegisteredAppInfo(getAppOption);\n\n // appType must be APIKey to continue\n if (appResponse.appType !== \"apikey\" || !(\"apiKey\" in appResponse)) {\n throw new Error(\"Item is not an API key.\");\n }\n\n const clientId = appResponse.client_id;\n const options = appendCustomParams(\n { ...appResponse, ...requestOptions }, // object with the custom params to look in\n [\"privileges\", \"httpReferrers\"] // keys you want copied to the params object\n );\n options.params.f = \"json\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n\n const app: IApp = registeredAppResponseToApp({\n ...updateResponse,\n apiKey: appResponse.apiKey\n });\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n return {\n ...appToApiKeyProperties(app),\n item: itemInfo\n };\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gBAAgB,QAAQ,SAAS,CAAC;IAEtE,gGAAgG;IAChG,MAAM,cAAc,GAA2B,MAAM,IAAA,6BAAO,EAAC,GAAG,kCAC3D,OAAO,KACV,cAAc,EAAE,cAAc,CAAC,cAAc,IAC7C,CAAC;IAEH;;OAEG;IACH,MAAM,eAAe,GAAG,MAAM,IAAA,4BAAO,EAAC,cAAc,CAAC,MAAM,kCACtD,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,IACrB,CAAC;IAEH;;OAEG;IACH,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAoB,EAChD,cAAc,CAAC,MAAM,EACrB,IAAA,mCAAsB,EACpB,cAAc,CAAC,cAAc,EAC7B,cAAc,CAAC,cAAc,CAC9B,kCAEI,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,IAEhD,CAAC;IAEF;;OAEG;IACH,MAAM,4BAA4B,GAAG,MAAM,IAAA,8CAAoB,kCAC1D,kBAAkB,KACrB,MAAM,EAAE,cAAc,CAAC,MAAM,EAC7B,cAAc,EAAE,cAAc,CAAC,cAAc,IAC7C,CAAC;IAEH,qDACK,eAAe,GACf,IAAA,kCAAqB,EAAC,4BAA4B,CAAC,KACtD,IAAI,EAAE,eAAe,IACrB;AACJ,CAAC;AAzFD,oCAyFC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IApiKeyResponse,\n IUpdateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n generateApiKeyTokens,\n generateOptionsToSlots,\n buildExpirationDateParams\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl, updateItem } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\n\n/**\n * Used to update an API key.\n *\n * Notes about `privileges` and `httpReferrers` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * updateApiKey({\n * itemId: \"xyz_itemId\",\n * privileges: [Privileges.Geocode],\n * httpReferrers: [], // httpReferrers will be set to be empty\n * authentication: authSession\n * }).then((updatedAPIKey: IApiKeyResponse) => {\n * // => {apiKey: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateApiKey | updateApiKey()}, including `itemId` of which API key to be operated on, optional new `privileges`, optional new `httpReferrers` and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.\n */\nexport async function updateApiKey(\n requestOptions: IUpdateApiKeyOptions\n): Promise<IApiKeyResponse> {\n requestOptions.httpMethod = \"POST\";\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n\n /**\n * step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.\n */\n if (\n requestOptions.apiToken1ExpirationDate ||\n requestOptions.apiToken2ExpirationDate\n ) {\n const updateParams = buildExpirationDateParams(requestOptions);\n await updateItem({\n ...baseRequestOptions,\n item: {\n id: requestOptions.itemId,\n ...updateParams\n },\n authentication: requestOptions.authentication\n });\n }\n\n /**\n * step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.\n */\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n const appResponse = await getRegisteredAppInfo(getAppOption);\n const clientId = appResponse.client_id;\n const options = appendCustomParams(\n { ...appResponse, ...requestOptions }, // object with the custom params to look in\n [\"privileges\", \"httpReferrers\"] // keys you want copied to the params object\n );\n options.params.f = \"json\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n\n /**\n * step 3: get the updated item info to return to the user.\n */\n const updatedItemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n /**\n * step 4: generate tokens if requested\n */\n const generatedTokens = await generateApiKeyTokens(\n requestOptions.itemId,\n generateOptionsToSlots(\n requestOptions.generateToken1,\n requestOptions.generateToken2\n ),\n {\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n }\n );\n\n /**\n * step 5: get updated registered app info\n */\n const updatedRegisteredAppResponse = await getRegisteredAppInfo({\n ...baseRequestOptions,\n itemId: requestOptions.itemId,\n authentication: requestOptions.authentication\n });\n\n return {\n ...generatedTokens,\n ...appToApiKeyProperties(updatedRegisteredAppResponse),\n item: updatedItemInfo\n };\n}\n"]}
@@ -15,7 +15,7 @@ import { IApiKeyResponse, ICreateApiKeyOptions } from "./shared/types/apiKeyType
15
15
  * title: "xyz_title",
16
16
  * description: "xyz_desc",
17
17
  * tags: ["xyz_tag1", "xyz_tag2"],
18
- * privileges: [Privileges.Geocode, Privileges.FeatureReport],
18
+ * privileges: ["premium:user:networkanalysis:routing"],
19
19
  * authentication: authSession
20
20
  * }).then((registeredAPIKey: IApiKeyResponse) => {
21
21
  * // => {apiKey: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}