@esri/arcgis-rest-developer-credentials 1.0.1 → 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 (61) hide show
  1. package/dist/bundled/developer-credentials.esm.js +179 -179
  2. package/dist/bundled/developer-credentials.esm.js.map +1 -1
  3. package/dist/bundled/developer-credentials.esm.min.js +4 -4
  4. package/dist/bundled/developer-credentials.esm.min.js.map +1 -1
  5. package/dist/bundled/developer-credentials.umd.js +180 -179
  6. package/dist/bundled/developer-credentials.umd.js.map +1 -1
  7. package/dist/bundled/developer-credentials.umd.min.js +4 -4
  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/shared/types/oAuthType.js.map +1 -1
  24. package/dist/cjs/updateApiKey.js +24 -13
  25. package/dist/cjs/updateApiKey.js.map +1 -1
  26. package/dist/esm/createApiKey.d.ts +1 -1
  27. package/dist/esm/createApiKey.js +31 -12
  28. package/dist/esm/createApiKey.js.map +1 -1
  29. package/dist/esm/index.d.ts +0 -2
  30. package/dist/esm/index.js +0 -2
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/shared/enum/privileges.d.ts +2 -23
  33. package/dist/esm/shared/enum/privileges.js +1 -26
  34. package/dist/esm/shared/enum/privileges.js.map +1 -1
  35. package/dist/esm/shared/generateApiKeyToken.d.ts +11 -0
  36. package/dist/esm/shared/generateApiKeyToken.js +23 -0
  37. package/dist/esm/shared/generateApiKeyToken.js.map +1 -0
  38. package/dist/esm/shared/helpers.d.ts +37 -7
  39. package/dist/esm/shared/helpers.js +68 -14
  40. package/dist/esm/shared/helpers.js.map +1 -1
  41. package/dist/esm/shared/registerApp.js +1 -5
  42. package/dist/esm/shared/registerApp.js.map +1 -1
  43. package/dist/esm/shared/types/apiKeyType.d.ts +44 -12
  44. package/dist/esm/shared/types/apiKeyType.js.map +1 -1
  45. package/dist/esm/shared/types/appType.d.ts +14 -10
  46. package/dist/esm/shared/types/appType.js.map +1 -1
  47. package/dist/esm/shared/types/oAuthType.d.ts +9 -9
  48. package/dist/esm/shared/types/oAuthType.js.map +1 -1
  49. package/dist/esm/updateApiKey.js +26 -15
  50. package/dist/esm/updateApiKey.js.map +1 -1
  51. package/package.json +1 -1
  52. package/dist/cjs/deleteApiKey.js +0 -43
  53. package/dist/cjs/deleteApiKey.js.map +0 -1
  54. package/dist/cjs/deleteOAuthApp.js +0 -43
  55. package/dist/cjs/deleteOAuthApp.js.map +0 -1
  56. package/dist/esm/deleteApiKey.d.ts +0 -27
  57. package/dist/esm/deleteApiKey.js +0 -39
  58. package/dist/esm/deleteApiKey.js.map +0 -1
  59. package/dist/esm/deleteOAuthApp.d.ts +0 -27
  60. package/dist/esm/deleteOAuthApp.js +0 -39
  61. package/dist/esm/deleteOAuthApp.js.map +0 -1
@@ -1,8 +1,9 @@
1
1
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
2
2
  * Apache-2.0 */
3
- import { createItem, getItem } from "@esri/arcgis-rest-portal";
3
+ import { createItem, getItem, updateItem } from "@esri/arcgis-rest-portal";
4
4
  import { registerApp } from "./shared/registerApp.js";
5
- import { appToApiKeyProperties, filterKeys, extractBaseRequestOptions, arePrivilegesValid } from "./shared/helpers.js";
5
+ import { appToApiKeyProperties, filterKeys, extractBaseRequestOptions, generateApiKeyTokens, generateOptionsToSlots, buildExpirationDateParams } from "./shared/helpers.js";
6
+ import { getRegisteredAppInfo } from "./shared/getRegisteredAppInfo.js";
6
7
  /**
7
8
  * 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.
8
9
  *
@@ -19,7 +20,7 @@ import { appToApiKeyProperties, filterKeys, extractBaseRequestOptions, arePrivil
19
20
  * title: "xyz_title",
20
21
  * description: "xyz_desc",
21
22
  * tags: ["xyz_tag1", "xyz_tag2"],
22
- * privileges: [Privileges.Geocode, Privileges.FeatureReport],
23
+ * privileges: ["premium:user:networkanalysis:routing"],
23
24
  * authentication: authSession
24
25
  * }).then((registeredAPIKey: IApiKeyResponse) => {
25
26
  * // => {apiKey: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
@@ -32,9 +33,6 @@ import { appToApiKeyProperties, filterKeys, extractBaseRequestOptions, arePrivil
32
33
  * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.
33
34
  */
34
35
  export async function createApiKey(requestOptions) {
35
- if (!arePrivilegesValid(requestOptions.privileges)) {
36
- throw new Error("The `privileges` option contains invalid privileges.");
37
- }
38
36
  requestOptions.httpMethod = "POST";
39
37
  // filter param buckets:
40
38
  const baseRequestOptions = extractBaseRequestOptions(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it
@@ -54,15 +52,36 @@ export async function createApiKey(requestOptions) {
54
52
  "typeKeywords",
55
53
  "url"
56
54
  ];
57
- // step 1: add item
58
- const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "API Key" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
55
+ /**
56
+ * step 1: create item
57
+ */
58
+ const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "Application" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
59
59
  f: "json"
60
60
  } });
61
61
  const createItemResponse = await createItem(createItemOption);
62
- // step 2: register app
63
- const registerAppOption = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "apikey", redirect_uris: [], httpReferrers: requestOptions.httpReferrers || [], privileges: requestOptions.privileges }, baseRequestOptions), { authentication: requestOptions.authentication });
64
- const registeredAppResponse = await registerApp(registerAppOption);
62
+ /**
63
+ * getRegisteredAppInfoRoute
64
+ */
65
+ 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 });
66
+ const registeredAppResponse = await registerApp(registerAppOptions);
67
+ /**
68
+ * step 3: update item with desired expiration dates
69
+ * you cannot set the expiration date propierties until you
70
+ * regiester the app so this has to be a seperate step
71
+ */
72
+ await updateItem(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: createItemResponse.id }, buildExpirationDateParams(requestOptions, true)), authentication: requestOptions.authentication }));
73
+ /*
74
+ * step 4: get item info
75
+ */
65
76
  const itemInfo = await getItem(registeredAppResponse.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
66
- return Object.assign(Object.assign({}, appToApiKeyProperties(registeredAppResponse)), { item: itemInfo });
77
+ /**
78
+ * step 5: generate tokens if requested
79
+ */
80
+ const generatedTokens = await generateApiKeyTokens(itemInfo.id, generateOptionsToSlots(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
81
+ /**
82
+ * step 6: get registered app info to get updated active key status
83
+ */
84
+ const updatedRegisteredAppResponse = await getRegisteredAppInfo(Object.assign(Object.assign({}, baseRequestOptions), { itemId: itemInfo.id, authentication: requestOptions.authentication }));
85
+ return Object.assign(Object.assign(Object.assign({}, generatedTokens), appToApiKeyProperties(updatedRegisteredAppResponse)), { item: itemInfo });
67
86
  }
68
87
  //# sourceMappingURL=createApiKey.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createApiKey.js","sourceRoot":"","sources":["../../src/createApiKey.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAEL,UAAU,EACV,OAAO,EAER,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAoC;IAEpC,IAAI,CAAC,kBAAkB,CAAC,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,yBAAyB,CAAC,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,UAAU,CAAC,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,UAAU,CAAC,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,WAAW,CAAC,iBAAiB,CAAC,CAAC;IACnE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,qBAAqB,CAAC,MAAM,kCACtD,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,IACrB,CAAC;IAEH,uCACK,qBAAqB,CAAC,qBAAqB,CAAC,KAC/C,IAAI,EAAE,QAAQ,IACd;AACJ,CAAC","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","sourceRoot":"","sources":["../../src/createApiKey.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAEL,UAAU,EACV,OAAO,EAEP,UAAU,EACX,MAAM,0BAA0B,CAAC;AAMlC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,cAAoC;IAEpC,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC;IAEnC,wBAAwB;IACxB,MAAM,kBAAkB,GAAG,yBAAyB,CAAC,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;;OAEG;IACH,MAAM,gBAAgB,iCACpB,IAAI,kCACC,UAAU,CAAC,cAAqB,EAAE,iBAAiB,CAAC,KACvD,IAAI,EAAE,aAAa,OAElB,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,EAC7C,MAAM,EAAE;YACN,CAAC,EAAE,MAAM;SACV,GACF,CAAC;IAEF,MAAM,kBAAkB,GAAG,MAAM,U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ent":["/* 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"]}
@@ -1,8 +1,6 @@
1
1
  export * from "./createApiKey.js";
2
2
  export * from "./updateApiKey.js";
3
3
  export * from "./getApiKey.js";
4
- export * from "./deleteApiKey.js";
5
- export * from "./deleteOAuthApp.js";
6
4
  export * from "./getOAuthApp.js";
7
5
  export * from "./updateOAuthApp.js";
8
6
  export * from "./createOAuthApp.js";
package/dist/esm/index.js CHANGED
@@ -3,8 +3,6 @@
3
3
  export * from "./createApiKey.js";
4
4
  export * from "./updateApiKey.js";
5
5
  export * from "./getApiKey.js";
6
- export * from "./deleteApiKey.js";
7
- export * from "./deleteOAuthApp.js";
8
6
  export * from "./getOAuthApp.js";
9
7
  export * from "./updateOAuthApp.js";
10
8
  export * from "./createOAuthApp.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC","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,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC","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,25 +1,4 @@
1
1
  /**
2
- * Used to describe privilege list of an app.
2
+ * 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).
3
3
  */
4
- export declare enum Privileges {
5
- Basemaps = "portal:apikey:basemaps",
6
- Demographics = "premium:user:demographics",
7
- Elevation = "premium:user:elevation",
8
- FeatureReport = "premium:user:featurereport",
9
- Geocode = "premium:user:geocode",
10
- GeocodeStored = "premium:user:geocode:stored",
11
- GeocodeTemporary = "premium:user:geocode:temporary",
12
- GeoEnrichment = "premium:user:geoenrichment",
13
- NetworkAnalysis = "premium:user:networkanalysis",
14
- NetworkAnalysisRouting = "premium:user:networkanalysis:routing",
15
- NetworkAnalysisOptimizedRouting = "premium:user:networkanalysis:optimizedrouting",
16
- NetworkAnalysisClosestFacility = "premium:user:networkanalysis:closestfacility",
17
- NetworkAnalysisServiceArea = "premium:user:networkanalysis:servicearea",
18
- NetworkAnalysisLocationalLocation = "premium:user:networkanalysis:locationallocation",
19
- NetworkAnalysisVehicleRouting = "premium:user:networkanalysis:vehiclerouting",
20
- NetworkAnalysisOriginDestinationCostMatrix = "premium:user:networkanalysis:origindestinationcostmatrix",
21
- Places = "premium:user:places",
22
- SpatialAnalysis = "premium:user:spatialanalysis",
23
- GeoAnalytics = "premium:publisher:geoanalytics",
24
- RasterAnalysis = "premium:publisher:rasteranalysis"
25
- }
4
+ export declare type Privileges = string[];
@@ -1,27 +1,2 @@
1
- /**
2
- * Used to describe privilege list of an app.
3
- */
4
- export var Privileges;
5
- (function (Privileges) {
6
- Privileges["Basemaps"] = "portal:apikey:basemaps";
7
- Privileges["Demographics"] = "premium:user:demographics";
8
- Privileges["Elevation"] = "premium:user:elevation";
9
- Privileges["FeatureReport"] = "premium:user:featurereport";
10
- Privileges["Geocode"] = "premium:user:geocode";
11
- Privileges["GeocodeStored"] = "premium:user:geocode:stored";
12
- Privileges["GeocodeTemporary"] = "premium:user:geocode:temporary";
13
- Privileges["GeoEnrichment"] = "premium:user:geoenrichment";
14
- Privileges["NetworkAnalysis"] = "premium:user:networkanalysis";
15
- Privileges["NetworkAnalysisRouting"] = "premium:user:networkanalysis:routing";
16
- Privileges["NetworkAnalysisOptimizedRouting"] = "premium:user:networkanalysis:optimizedrouting";
17
- Privileges["NetworkAnalysisClosestFacility"] = "premium:user:networkanalysis:closestfacility";
18
- Privileges["NetworkAnalysisServiceArea"] = "premium:user:networkanalysis:servicearea";
19
- Privileges["NetworkAnalysisLocationalLocation"] = "premium:user:networkanalysis:locationallocation";
20
- Privileges["NetworkAnalysisVehicleRouting"] = "premium:user:networkanalysis:vehiclerouting";
21
- Privileges["NetworkAnalysisOriginDestinationCostMatrix"] = "premium:user:networkanalysis:origindestinationcostmatrix";
22
- Privileges["Places"] = "premium:user:places";
23
- Privileges["SpatialAnalysis"] = "premium:user:spatialanalysis";
24
- Privileges["GeoAnalytics"] = "premium:publisher:geoanalytics";
25
- Privileges["RasterAnalysis"] = "premium:publisher:rasteranalysis";
26
- })(Privileges || (Privileges = {}));
1
+ export {};
27
2
  //# sourceMappingURL=privileges.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"privileges.js","sourceRoot":"","sources":["../../../../src/shared/enum/privileges.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,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,KAAV,UAAU,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,11 @@
1
+ import { IRequestOptions, IAuthenticationManager } from "@esri/arcgis-rest-request";
2
+ export interface IGenerateApiKeyTokenOptions extends IRequestOptions {
3
+ itemId: string;
4
+ apiKey: 1 | 2;
5
+ portal?: string;
6
+ authentication: IAuthenticationManager;
7
+ }
8
+ export declare function generateApiKeyToken(options: IGenerateApiKeyTokenOptions): Promise<{
9
+ access_token: string;
10
+ expires_in: number;
11
+ }>;
@@ -0,0 +1,23 @@
1
+ import { request } from "@esri/arcgis-rest-request";
2
+ import { getRegisteredAppInfo } from "./getRegisteredAppInfo.js";
3
+ import { getPortalUrl } from "@esri/arcgis-rest-portal";
4
+ export async function generateApiKeyToken(options) {
5
+ const portal = getPortalUrl(options);
6
+ const url = `${portal}/oauth2/token`;
7
+ const appInfo = await getRegisteredAppInfo({
8
+ itemId: options.itemId,
9
+ authentication: options.authentication
10
+ });
11
+ const params = {
12
+ client_id: appInfo.client_id,
13
+ client_secret: appInfo.client_secret,
14
+ apiToken: options.apiKey,
15
+ regenerateApiToken: true,
16
+ grant_type: "client_credentials"
17
+ };
18
+ return request(url, {
19
+ authentication: options.authentication,
20
+ params
21
+ });
22
+ }
23
+ //# sourceMappingURL=generateApiKeyToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGR,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AASxD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;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,OAAO,CAAC,GAAG,EAAE;QAClB,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,MAAM;KACP,CAAC,CAAC;AACL,CAAC","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
- import { IRequestOptions } from "@esri/arcgis-rest-request";
2
- import { Privileges } from "./enum/privileges.js";
1
+ import { IRequestOptions, IAuthenticationManager } from "@esri/arcgis-rest-request";
3
2
  import { IRegisteredAppResponse, IApp } from "./types/appType.js";
4
3
  import { IApiKeyInfo } from "./types/apiKeyType.js";
5
4
  import { IOAuthAppInfo } from "./types/oAuthType.js";
6
- /**
7
- * @internal
8
- * Used to check privileges validity.
9
- */
10
- export declare const arePrivilegesValid: (privileges: Array<Privileges | `${Privileges}`>) => boolean;
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.
@@ -38,3 +32,39 @@ export declare function extractBaseRequestOptions<T extends IRequestOptions>(opt
38
32
  * Used to create a new object including only specified keys from another object.
39
33
  */
40
34
  export declare function filterKeys<T extends object>(object: T, includedKeys: Array<keyof T>): any;
35
+ /**
36
+ * Used to determine if a generated key is in slot 1 or slot 2 key.
37
+ */
38
+ export declare function slotForKey(key: string): number;
39
+ interface IGenerateApiKeyTokenOptions extends IRequestOptions {
40
+ authentication: IAuthenticationManager;
41
+ }
42
+ /**
43
+ * @internal
44
+ * Used to generate tokens in slot 1 and/or 2 of an API key.
45
+ */
46
+ export declare function generateApiKeyTokens(itemId: string, slots: Array<1 | 2>, requestOptions: IGenerateApiKeyTokenOptions): Promise<{
47
+ [key: string]: string;
48
+ }>;
49
+ /**
50
+ * @internal
51
+ * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.
52
+ */
53
+ export declare function generateOptionsToSlots(generateToken1: boolean, generateToken2: boolean): Array<1 | 2>;
54
+ declare type expirationDateParams = {
55
+ apiToken1ExpirationDate: Date | -1;
56
+ apiToken2ExpirationDate: Date | -1;
57
+ } | {
58
+ apiToken1ExpirationDate: Date | -1;
59
+ } | {
60
+ apiToken2ExpirationDate: Date | -1;
61
+ } | {};
62
+ /**
63
+ * @internal
64
+ * Build params for updating expiration dates
65
+ */
66
+ export declare function buildExpirationDateParams(requestOptions: {
67
+ apiToken1ExpirationDate?: Date;
68
+ apiToken2ExpirationDate?: Date;
69
+ }, fillDefaults?: boolean): expirationDateParams;
70
+ export {};
@@ -1,9 +1,4 @@
1
- import { Privileges } from "./enum/privileges.js";
2
- /**
3
- * @internal
4
- * Used to check privileges validity.
5
- */
6
- export const arePrivilegesValid = (privileges) => privileges.every((element) => Object.values(Privileges).includes(element));
1
+ import { generateApiKeyToken } from "./generateApiKeyToken.js";
7
2
  /**
8
3
  * @internal
9
4
  * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.
@@ -25,7 +20,8 @@ export function registeredAppResponseToApp(response) {
25
20
  "apnsProdCert",
26
21
  "apnsSandboxCert",
27
22
  "gcmApiKey",
28
- "isBeta"
23
+ "isBeta",
24
+ "customAppLoginShowTriage"
29
25
  ];
30
26
  const dateKeys = ["modified", "registered"];
31
27
  return Object.keys(response)
@@ -45,13 +41,11 @@ export function registeredAppResponseToApp(response) {
45
41
  * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is "apikey".
46
42
  */
47
43
  export function appToApiKeyProperties(response) {
48
- if (response.appType !== "apikey" || !("apiKey" in response)) {
49
- throw new Error("Item is not an API key.");
50
- }
51
- delete response.client_id;
52
44
  delete response.client_secret;
53
45
  delete response.redirect_uris;
54
46
  delete response.appType;
47
+ delete response.customAppLoginShowTriage;
48
+ delete response.apiKey;
55
49
  return response;
56
50
  }
57
51
  /**
@@ -59,12 +53,14 @@ export function appToApiKeyProperties(response) {
59
53
  * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.
60
54
  */
61
55
  export function appToOAuthAppProperties(response) {
62
- if (response.appType === "apikey") {
63
- throw new Error("Item is not an OAuth 2.0 app.");
64
- }
65
56
  delete response.appType;
66
57
  delete response.httpReferrers;
67
58
  delete response.privileges;
59
+ delete response.apiKey;
60
+ delete response.customAppLoginShowTriage;
61
+ delete response.isPersonalAPIToken;
62
+ delete response.apiToken1Active;
63
+ delete response.apiToken2Active;
68
64
  return response;
69
65
  }
70
66
  /**
@@ -97,4 +93,62 @@ export function filterKeys(object, includedKeys) {
97
93
  return obj;
98
94
  }, {});
99
95
  }
96
+ /**
97
+ * Used to determine if a generated key is in slot 1 or slot 2 key.
98
+ */
99
+ export function slotForKey(key) {
100
+ return parseInt(key.substring(key.length - 10, key.length - 9));
101
+ }
102
+ /**
103
+ * @internal
104
+ * Used to generate tokens in slot 1 and/or 2 of an API key.
105
+ */
106
+ export function generateApiKeyTokens(itemId, slots, requestOptions) {
107
+ return Promise.all(slots.map((slot) => {
108
+ return generateApiKeyToken(Object.assign({ itemId, apiKey: slot }, requestOptions));
109
+ })).then((responses) => {
110
+ return responses
111
+ .map((responses) => responses.access_token)
112
+ .reduce((obj, token, index) => {
113
+ obj[`accessToken${slotForKey(token)}`] = token;
114
+ return obj;
115
+ }, {});
116
+ });
117
+ }
118
+ /**
119
+ * @internal
120
+ * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.
121
+ */
122
+ export function generateOptionsToSlots(generateToken1, generateToken2) {
123
+ const slots = [];
124
+ if (generateToken1) {
125
+ slots.push(1);
126
+ }
127
+ if (generateToken2) {
128
+ slots.push(2);
129
+ }
130
+ return slots;
131
+ }
132
+ /**
133
+ * @internal
134
+ * Build params for updating expiration dates
135
+ */
136
+ export function buildExpirationDateParams(requestOptions, fillDefaults) {
137
+ const updateparams = {};
138
+ if (requestOptions.apiToken1ExpirationDate) {
139
+ updateparams.apiToken1ExpirationDate =
140
+ requestOptions.apiToken1ExpirationDate;
141
+ }
142
+ if (requestOptions.apiToken2ExpirationDate) {
143
+ updateparams.apiToken2ExpirationDate =
144
+ requestOptions.apiToken2ExpirationDate;
145
+ }
146
+ if (fillDefaults && !updateparams.apiToken1ExpirationDate) {
147
+ updateparams.apiToken1ExpirationDate = -1;
148
+ }
149
+ if (fillDefaults && !updateparams.apiToken2ExpirationDate) {
150
+ updateparams.apiToken2ExpirationDate = -1;
151
+ }
152
+ return updateparams;
153
+ }
100
154
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/shared/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKlD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,UAA+C,EACtC,EAAE,CACX,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAC3B,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,OAAc,CAAC,CACnD,CAAC;AAEJ;;;GAGG;AACH,MAA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port { 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,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,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;AAEF;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAgC;IAEhC,MAAM,WAAW,GAAG;QAClB,cAAc;QAC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AAC;aAC1C,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;YAC5B,GAAG,CAAC,cAAc,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC;YAC/C,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAA+B,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,cAAuB,EACvB,cAAuB;IAEvB,MAAM,KAAK,GAAiB,EAAE,CAAC;IAC/B,IAAI,cAAc,EAAE;QAClB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACf;IACD,IAAI,cAAc,EAAE;QAClB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACf;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAeD;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,cAGC,EACD,YAAsB;IAEtB,MAAM,YAAY,GAAQ,EAAE,CAAC;IAC7B,IAAI,cAAc,CAAC,uBAAuB,EAAE;QAC1C,YAAY,CAAC,uBAAuB;YAClC,cAAc,CAAC,uBAAuB,CAAC;KAC1C;IAED,IAAI,cAAc,CAAC,uBAAuB,EAAE;QAC1C,YAAY,CAAC,uBAAuB;YAClC,cAAc,CAAC,uBAAuB,CAAC;KAC1C;IAED,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE;QACzD,YAAY,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC;KAC3C;IAED,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE;QACzD,YAAY,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC;KAC3C;IACD,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["import {\n IRequestOptions,\n IAuthenticationManager\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"]}
@@ -2,7 +2,7 @@
2
2
  * Apache-2.0 */
3
3
  import { request, appendCustomParams } from "@esri/arcgis-rest-request";
4
4
  import { getPortalUrl } from "@esri/arcgis-rest-portal";
5
- import { arePrivilegesValid, stringifyArrays, registeredAppResponseToApp } from "./helpers.js";
5
+ import { stringifyArrays, registeredAppResponseToApp } from "./helpers.js";
6
6
  /**
7
7
  * Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.
8
8
  *
@@ -40,10 +40,6 @@ import { arePrivilegesValid, stringifyArrays, registeredAppResponseToApp } from
40
40
  * @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.
41
41
  */
42
42
  export async function registerApp(requestOptions) {
43
- // privileges validation
44
- if (!arePrivilegesValid(requestOptions.privileges)) {
45
- throw new Error("The `privileges` option contains invalid privileges.");
46
- }
47
43
  // build params
48
44
  const options = appendCustomParams(requestOptions, [
49
45
  "itemId",
@@ -1 +1 @@
1
- {"version":3,"file":"registerApp.js","sourceRoot":"","sources":["../../../src/shared/registerApp.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAMxD,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,0BAA0B,EAC3B,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,wBAAwB;IACxB,IAAI,CAAC,kBAAkB,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE;QAClD,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACzE;IAED,eAAe;IACf,MAAM,OAAO,GAAG,kBAAkB,CAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,eAAe,CAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,YAAY,CAAC,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,OAAO,CACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,0BAA0B,CAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC","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,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAMxD,OAAO,EAAE,eAAe,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,eAAe;IACf,MAAM,OAAO,GAAG,kBAAkB,CAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,eAAe,CAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,YAAY,CAAC,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,OAAO,CACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,0BAA0B,CAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC","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,6 +1,5 @@
1
- import { ArcGISIdentityManager, IRequestOptions, ISpatialReference } from "@esri/arcgis-rest-request";
1
+ import { IAuthenticationManager, IRequestOptions, ISpatialReference } from "@esri/arcgis-rest-request";
2
2
  import { IRegisterAppOptions, IApp } from "./appType.js";
3
- import { Privileges } from "../enum/privileges.js";
4
3
  import { IItem } from "@esri/arcgis-rest-portal";
5
4
  /**
6
5
  * Options to register an API Key.
@@ -20,15 +19,31 @@ export interface ICreateApiKeyOptions extends Omit<IRegisterAppOptions, "itemId"
20
19
  properties?: any;
21
20
  url?: string;
22
21
  tags?: string[];
22
+ /**
23
+ * Expiration date of the access token in slot 1 of this API Key.
24
+ */
25
+ apiToken1ExpirationDate?: Date;
26
+ /**
27
+ * Expiration date of the access token in slot 2 of this API Key.
28
+ */
29
+ apiToken2ExpirationDate?: Date;
30
+ /**
31
+ * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.
32
+ */
33
+ generateToken1?: boolean;
34
+ /**
35
+ * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.
36
+ */
37
+ generateToken2?: boolean;
23
38
  }
24
39
  /**
25
40
  * Options to retrieve an API Key.
26
41
  */
27
42
  export interface IGetApiKeyOptions extends Omit<IRequestOptions, "params"> {
28
43
  /**
29
- * {@linkcode ArcGISIdentityManager} authentication.
44
+ * {@linkcode IAuthenticationManager} authentication.
30
45
  */
31
- authentication: ArcGISIdentityManager;
46
+ authentication: IAuthenticationManager;
32
47
  /**
33
48
  * itemId of which API key to be retrieved.
34
49
  */
@@ -37,26 +52,27 @@ export interface IGetApiKeyOptions extends Omit<IRequestOptions, "params"> {
37
52
  /**
38
53
  * Represent only the API key related properties from {@linkcode IApp}.
39
54
  */
40
- export interface IApiKeyInfo extends Omit<IApp, "client_id" | "client_secret" | "redirect_uris" | "appType"> {
41
- apiKey: string;
55
+ export interface IApiKeyInfo extends Omit<IApp, "client_secret" | "redirect_uris" | "appType"> {
42
56
  }
43
57
  /**
44
- * Return value of {@linkcode createApiKey}, {@linkcode getApiKey}, {@linkcode updateApiKey} representing an API Key entity.
58
+ * 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`.
45
59
  */
46
60
  export interface IApiKeyResponse extends IApiKeyInfo {
47
61
  /**
48
62
  * Represent item info attached to this API Key.
49
63
  */
50
64
  item: IItem;
65
+ accessToken1?: null | string;
66
+ accessToken2?: null | string;
51
67
  }
52
68
  /**
53
69
  * Options to update an API Key.
54
70
  */
55
71
  export interface IUpdateApiKeyOptions extends Omit<IRequestOptions, "params"> {
56
72
  /**
57
- * {@linkcode ArcGISIdentityManager} authentication.
73
+ * {@linkcode IAuthenticationManager} authentication.
58
74
  */
59
- authentication: ArcGISIdentityManager;
75
+ authentication: IAuthenticationManager;
60
76
  /**
61
77
  * itemId of which API key will be updated.
62
78
  */
@@ -68,16 +84,32 @@ export interface IUpdateApiKeyOptions extends Omit<IRequestOptions, "params"> {
68
84
  /**
69
85
  * Override previous `privileges` if this value is provided.
70
86
  */
71
- privileges?: Array<Privileges | `${Privileges}`>;
87
+ privileges?: string[];
88
+ /**
89
+ * Expiration date of the access token in slot 1 of this API Key.
90
+ */
91
+ apiToken1ExpirationDate?: Date;
92
+ /**
93
+ * Expiration date of the access token in slot 2 of this API Key.
94
+ */
95
+ apiToken2ExpirationDate?: Date;
96
+ /**
97
+ * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.
98
+ */
99
+ generateToken1?: boolean;
100
+ /**
101
+ * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.
102
+ */
103
+ generateToken2?: boolean;
72
104
  }
73
105
  /**
74
106
  * Options to delete an API key.
75
107
  */
76
108
  export interface IDeleteApiKeyOption extends Omit<IRequestOptions, "params"> {
77
109
  /**
78
- * {@linkcode ArcGISIdentityManager} authentication.
110
+ * {@linkcode IAuthenticationManager} authentication.
79
111
  */
80
- authentication: ArcGISIdentityManager;
112
+ authentication: IAuthenticationManager;
81
113
  /**
82
114
  * itemId of which API key to be removed.
83
115
  */