@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,7 +1,7 @@
1
1
  /* @preserve
2
- * @esri/arcgis-rest-developer-credentials - v1.0.0 - Apache-2.0
3
- * Copyright (c) 2017-2024 Esri, Inc.
4
- * Sat Jun 15 2024 00:23:29 GMT+0000 (Coordinated Universal Time)
2
+ * @esri/arcgis-rest-developer-credentials - v2.0.0 - Apache-2.0
3
+ * Copyright (c) 2017-2025 Esri, Inc.
4
+ * Thu Feb 20 2025 22:18:42 GMT+0000 (Coordinated Universal Time)
5
5
  */
6
6
  (function (global, factory) {
7
7
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@esri/arcgis-rest-portal'), require('@esri/arcgis-rest-request')) :
@@ -9,38 +9,62 @@
9
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.arcgisRest = global.arcgisRest || {}, global.arcgisRest, global.arcgisRest));
10
10
  })(this, (function (exports, arcgisRestPortal, arcgisRestRequest) { 'use strict';
11
11
 
12
+ /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
13
+ * Apache-2.0 */
12
14
  /**
13
- * Used to describe privilege list of an app.
15
+ * Used to retrieve registered app info. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/registered-app-info.htm) for more information.
16
+ *
17
+ * ```js
18
+ * import { getRegisteredAppInfo, IApp } from '@esri/arcgis-rest-developer-credentials';
19
+ * import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
20
+ *
21
+ * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
22
+ * username: "xyz_usrName",
23
+ * password: "xyz_pw"
24
+ * });
25
+ *
26
+ * getRegisteredAppInfo({
27
+ * itemId: "xyz_itemId",
28
+ * authentication: authSession
29
+ * }).then((registeredApp: IApp) => {
30
+ * // => {client_id: "xyz_id", client_secret: "xyz_secret", ...}
31
+ * }).catch(e => {
32
+ * // => an exception object
33
+ * });
34
+ * ```
35
+ *
36
+ * @param requestOptions - Options for {@linkcode getRegisteredAppInfo | getRegisteredAppInfo()}, including an itemId of which app to retrieve and an {@linkcode ArcGISIdentityManager} authentication session.
37
+ * @returns A Promise that will resolve to an {@linkcode IApp} object representing successfully retrieved app.
14
38
  */
15
- exports.Privileges = void 0;
16
- (function (Privileges) {
17
- Privileges["Basemaps"] = "portal:apikey:basemaps";
18
- Privileges["Demographics"] = "premium:user:demographics";
19
- Privileges["Elevation"] = "premium:user:elevation";
20
- Privileges["FeatureReport"] = "premium:user:featurereport";
21
- Privileges["Geocode"] = "premium:user:geocode";
22
- Privileges["GeocodeStored"] = "premium:user:geocode:stored";
23
- Privileges["GeocodeTemporary"] = "premium:user:geocode:temporary";
24
- Privileges["GeoEnrichment"] = "premium:user:geoenrichment";
25
- Privileges["NetworkAnalysis"] = "premium:user:networkanalysis";
26
- Privileges["NetworkAnalysisRouting"] = "premium:user:networkanalysis:routing";
27
- Privileges["NetworkAnalysisOptimizedRouting"] = "premium:user:networkanalysis:optimizedrouting";
28
- Privileges["NetworkAnalysisClosestFacility"] = "premium:user:networkanalysis:closestfacility";
29
- Privileges["NetworkAnalysisServiceArea"] = "premium:user:networkanalysis:servicearea";
30
- Privileges["NetworkAnalysisLocationalLocation"] = "premium:user:networkanalysis:locationallocation";
31
- Privileges["NetworkAnalysisVehicleRouting"] = "premium:user:networkanalysis:vehiclerouting";
32
- Privileges["NetworkAnalysisOriginDestinationCostMatrix"] = "premium:user:networkanalysis:origindestinationcostmatrix";
33
- Privileges["Places"] = "premium:user:places";
34
- Privileges["SpatialAnalysis"] = "premium:user:spatialanalysis";
35
- Privileges["GeoAnalytics"] = "premium:publisher:geoanalytics";
36
- Privileges["RasterAnalysis"] = "premium:publisher:rasteranalysis";
37
- })(exports.Privileges || (exports.Privileges = {}));
39
+ async function getRegisteredAppInfo(requestOptions) {
40
+ const userName = await requestOptions.authentication.getUsername();
41
+ const url = arcgisRestPortal.getPortalUrl(requestOptions) +
42
+ `/content/users/${userName}/items/${requestOptions.itemId}/registeredAppInfo`;
43
+ requestOptions.httpMethod = "POST";
44
+ const registeredAppResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, requestOptions), { params: { f: "json" } }));
45
+ return registeredAppResponseToApp(registeredAppResponse);
46
+ }
47
+
48
+ async function generateApiKeyToken(options) {
49
+ const portal = arcgisRestPortal.getPortalUrl(options);
50
+ const url = `${portal}/oauth2/token`;
51
+ const appInfo = await getRegisteredAppInfo({
52
+ itemId: options.itemId,
53
+ authentication: options.authentication
54
+ });
55
+ const params = {
56
+ client_id: appInfo.client_id,
57
+ client_secret: appInfo.client_secret,
58
+ apiToken: options.apiKey,
59
+ regenerateApiToken: true,
60
+ grant_type: "client_credentials"
61
+ };
62
+ return arcgisRestRequest.request(url, {
63
+ authentication: options.authentication,
64
+ params
65
+ });
66
+ }
38
67
 
39
- /**
40
- * @internal
41
- * Used to check privileges validity.
42
- */
43
- const arePrivilegesValid = (privileges) => privileges.every((element) => Object.values(exports.Privileges).includes(element));
44
68
  /**
45
69
  * @internal
46
70
  * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.
@@ -62,7 +86,8 @@
62
86
  "apnsProdCert",
63
87
  "apnsSandboxCert",
64
88
  "gcmApiKey",
65
- "isBeta"
89
+ "isBeta",
90
+ "customAppLoginShowTriage"
66
91
  ];
67
92
  const dateKeys = ["modified", "registered"];
68
93
  return Object.keys(response)
@@ -82,13 +107,11 @@
82
107
  * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is "apikey".
83
108
  */
84
109
  function appToApiKeyProperties(response) {
85
- if (response.appType !== "apikey" || !("apiKey" in response)) {
86
- throw new Error("Item is not an API key.");
87
- }
88
- delete response.client_id;
89
110
  delete response.client_secret;
90
111
  delete response.redirect_uris;
91
112
  delete response.appType;
113
+ delete response.customAppLoginShowTriage;
114
+ delete response.apiKey;
92
115
  return response;
93
116
  }
94
117
  /**
@@ -96,12 +119,14 @@
96
119
  * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.
97
120
  */
98
121
  function appToOAuthAppProperties(response) {
99
- if (response.appType === "apikey") {
100
- throw new Error("Item is not an OAuth 2.0 app.");
101
- }
102
122
  delete response.appType;
103
123
  delete response.httpReferrers;
104
124
  delete response.privileges;
125
+ delete response.apiKey;
126
+ delete response.customAppLoginShowTriage;
127
+ delete response.isPersonalAPIToken;
128
+ delete response.apiToken1Active;
129
+ delete response.apiToken2Active;
105
130
  return response;
106
131
  }
107
132
  /**
@@ -134,6 +159,64 @@
134
159
  return obj;
135
160
  }, {});
136
161
  }
162
+ /**
163
+ * Used to determine if a generated key is in slot 1 or slot 2 key.
164
+ */
165
+ function slotForKey(key) {
166
+ return parseInt(key.substring(key.length - 10, key.length - 9));
167
+ }
168
+ /**
169
+ * @internal
170
+ * Used to generate tokens in slot 1 and/or 2 of an API key.
171
+ */
172
+ function generateApiKeyTokens(itemId, slots, requestOptions) {
173
+ return Promise.all(slots.map((slot) => {
174
+ return generateApiKeyToken(Object.assign({ itemId, apiKey: slot }, requestOptions));
175
+ })).then((responses) => {
176
+ return responses
177
+ .map((responses) => responses.access_token)
178
+ .reduce((obj, token, index) => {
179
+ obj[`accessToken${slotForKey(token)}`] = token;
180
+ return obj;
181
+ }, {});
182
+ });
183
+ }
184
+ /**
185
+ * @internal
186
+ * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.
187
+ */
188
+ function generateOptionsToSlots(generateToken1, generateToken2) {
189
+ const slots = [];
190
+ if (generateToken1) {
191
+ slots.push(1);
192
+ }
193
+ if (generateToken2) {
194
+ slots.push(2);
195
+ }
196
+ return slots;
197
+ }
198
+ /**
199
+ * @internal
200
+ * Build params for updating expiration dates
201
+ */
202
+ function buildExpirationDateParams(requestOptions, fillDefaults) {
203
+ const updateparams = {};
204
+ if (requestOptions.apiToken1ExpirationDate) {
205
+ updateparams.apiToken1ExpirationDate =
206
+ requestOptions.apiToken1ExpirationDate;
207
+ }
208
+ if (requestOptions.apiToken2ExpirationDate) {
209
+ updateparams.apiToken2ExpirationDate =
210
+ requestOptions.apiToken2ExpirationDate;
211
+ }
212
+ if (fillDefaults && !updateparams.apiToken1ExpirationDate) {
213
+ updateparams.apiToken1ExpirationDate = -1;
214
+ }
215
+ if (fillDefaults && !updateparams.apiToken2ExpirationDate) {
216
+ updateparams.apiToken2ExpirationDate = -1;
217
+ }
218
+ return updateparams;
219
+ }
137
220
 
138
221
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
139
222
  * Apache-2.0 */
@@ -174,10 +257,6 @@
174
257
  * @returns A Promise that will resolve to an {@linkcode IApp} object representing the newly registered app.
175
258
  */
176
259
  async function registerApp(requestOptions) {
177
- // privileges validation
178
- if (!arePrivilegesValid(requestOptions.privileges)) {
179
- throw new Error("The `privileges` option contains invalid privileges.");
180
- }
181
260
  // build params
182
261
  const options = arcgisRestRequest.appendCustomParams(requestOptions, [
183
262
  "itemId",
@@ -213,7 +292,7 @@
213
292
  * title: "xyz_title",
214
293
  * description: "xyz_desc",
215
294
  * tags: ["xyz_tag1", "xyz_tag2"],
216
- * privileges: [Privileges.Geocode, Privileges.FeatureReport],
295
+ * privileges: ["premium:user:networkanalysis:routing"],
217
296
  * authentication: authSession
218
297
  * }).then((registeredAPIKey: IApiKeyResponse) => {
219
298
  * // => {apiKey: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
@@ -226,9 +305,6 @@
226
305
  * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing the newly registered API key.
227
306
  */
228
307
  async function createApiKey(requestOptions) {
229
- if (!arePrivilegesValid(requestOptions.privileges)) {
230
- throw new Error("The `privileges` option contains invalid privileges.");
231
- }
232
308
  requestOptions.httpMethod = "POST";
233
309
  // filter param buckets:
234
310
  const baseRequestOptions = extractBaseRequestOptions(requestOptions); // snapshot of basic IRequestOptions before customized params being built into it
@@ -248,52 +324,37 @@
248
324
  "typeKeywords",
249
325
  "url"
250
326
  ];
251
- // step 1: add item
252
- const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "API Key" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
327
+ /**
328
+ * step 1: create item
329
+ */
330
+ const createItemOption = Object.assign(Object.assign({ item: Object.assign(Object.assign({}, filterKeys(requestOptions, itemAddProperties)), { type: "Application" }) }, baseRequestOptions), { authentication: requestOptions.authentication, params: {
253
331
  f: "json"
254
332
  } });
255
333
  const createItemResponse = await arcgisRestPortal.createItem(createItemOption);
256
- // step 2: register app
257
- const registerAppOption = Object.assign(Object.assign({ itemId: createItemResponse.id, appType: "apikey", redirect_uris: [], httpReferrers: requestOptions.httpReferrers || [], privileges: requestOptions.privileges }, baseRequestOptions), { authentication: requestOptions.authentication });
258
- const registeredAppResponse = await registerApp(registerAppOption);
334
+ /**
335
+ * getRegisteredAppInfoRoute
336
+ */
337
+ 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 });
338
+ const registeredAppResponse = await registerApp(registerAppOptions);
339
+ /**
340
+ * step 3: update item with desired expiration dates
341
+ * you cannot set the expiration date propierties until you
342
+ * regiester the app so this has to be a seperate step
343
+ */
344
+ await arcgisRestPortal.updateItem(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: createItemResponse.id }, buildExpirationDateParams(requestOptions, true)), authentication: requestOptions.authentication }));
345
+ /*
346
+ * step 4: get item info
347
+ */
259
348
  const itemInfo = await arcgisRestPortal.getItem(registeredAppResponse.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
260
- return Object.assign(Object.assign({}, appToApiKeyProperties(registeredAppResponse)), { item: itemInfo });
261
- }
262
-
263
- /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
264
- * Apache-2.0 */
265
- /**
266
- * Used to retrieve registered app info. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/registered-app-info.htm) for more information.
267
- *
268
- * ```js
269
- * import { getRegisteredAppInfo, IApp } from '@esri/arcgis-rest-developer-credentials';
270
- * import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
271
- *
272
- * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
273
- * username: "xyz_usrName",
274
- * password: "xyz_pw"
275
- * });
276
- *
277
- * getRegisteredAppInfo({
278
- * itemId: "xyz_itemId",
279
- * authentication: authSession
280
- * }).then((registeredApp: IApp) => {
281
- * // => {client_id: "xyz_id", client_secret: "xyz_secret", ...}
282
- * }).catch(e => {
283
- * // => an exception object
284
- * });
285
- * ```
286
- *
287
- * @param requestOptions - Options for {@linkcode getRegisteredAppInfo | getRegisteredAppInfo()}, including an itemId of which app to retrieve and an {@linkcode ArcGISIdentityManager} authentication session.
288
- * @returns A Promise that will resolve to an {@linkcode IApp} object representing successfully retrieved app.
289
- */
290
- async function getRegisteredAppInfo(requestOptions) {
291
- const userName = await requestOptions.authentication.getUsername();
292
- const url = arcgisRestPortal.getPortalUrl(requestOptions) +
293
- `/content/users/${userName}/items/${requestOptions.itemId}/registeredAppInfo`;
294
- requestOptions.httpMethod = "POST";
295
- const registeredAppResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, requestOptions), { params: { f: "json" } }));
296
- return registeredAppResponseToApp(registeredAppResponse);
349
+ /**
350
+ * step 5: generate tokens if requested
351
+ */
352
+ const generatedTokens = await generateApiKeyTokens(itemInfo.id, generateOptionsToSlots(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
353
+ /**
354
+ * step 6: get registered app info to get updated active key status
355
+ */
356
+ const updatedRegisteredAppResponse = await getRegisteredAppInfo(Object.assign(Object.assign({}, baseRequestOptions), { itemId: itemInfo.id, authentication: requestOptions.authentication }));
357
+ return Object.assign(Object.assign(Object.assign({}, generatedTokens), appToApiKeyProperties(updatedRegisteredAppResponse)), { item: itemInfo });
297
358
  }
298
359
 
299
360
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
@@ -330,20 +391,21 @@
330
391
  * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.
331
392
  */
332
393
  async function updateApiKey(requestOptions) {
333
- // privileges validation
334
- if (requestOptions.privileges &&
335
- !arePrivilegesValid(requestOptions.privileges)) {
336
- throw new Error("The `privileges` option contains invalid privileges.");
337
- }
338
394
  requestOptions.httpMethod = "POST";
339
- // get app
340
395
  const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot
396
+ /**
397
+ * step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.
398
+ */
399
+ if (requestOptions.apiToken1ExpirationDate ||
400
+ requestOptions.apiToken2ExpirationDate) {
401
+ const updateParams = buildExpirationDateParams(requestOptions);
402
+ await arcgisRestPortal.updateItem(Object.assign(Object.assign({}, baseRequestOptions), { item: Object.assign({ id: requestOptions.itemId }, updateParams), authentication: requestOptions.authentication }));
403
+ }
404
+ /**
405
+ * step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.
406
+ */
341
407
  const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
342
408
  const appResponse = await getRegisteredAppInfo(getAppOption);
343
- // appType must be APIKey to continue
344
- if (appResponse.appType !== "apikey" || !("apiKey" in appResponse)) {
345
- throw new Error("Item is not an API key.");
346
- }
347
409
  const clientId = appResponse.client_id;
348
410
  const options = arcgisRestRequest.appendCustomParams(Object.assign(Object.assign({}, appResponse), requestOptions), // object with the custom params to look in
349
411
  ["privileges", "httpReferrers"] // keys you want copied to the params object
@@ -353,10 +415,20 @@
353
415
  stringifyArrays(options);
354
416
  const url = arcgisRestPortal.getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;
355
417
  // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
356
- const updateResponse = await arcgisRestRequest.request(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
357
- const app = registeredAppResponseToApp(Object.assign(Object.assign({}, updateResponse), { apiKey: appResponse.apiKey }));
358
- const itemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
359
- return Object.assign(Object.assign({}, appToApiKeyProperties(app)), { item: itemInfo });
418
+ await arcgisRestRequest.request(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
419
+ /**
420
+ * step 3: get the updated item info to return to the user.
421
+ */
422
+ const updatedItemInfo = await arcgisRestPortal.getItem(requestOptions.itemId, Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, params: { f: "json" } }));
423
+ /**
424
+ * step 4: generate tokens if requested
425
+ */
426
+ const generatedTokens = await generateApiKeyTokens(requestOptions.itemId, generateOptionsToSlots(requestOptions.generateToken1, requestOptions.generateToken2), Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication }));
427
+ /**
428
+ * step 5: get updated registered app info
429
+ */
430
+ const updatedRegisteredAppResponse = await getRegisteredAppInfo(Object.assign(Object.assign({}, baseRequestOptions), { itemId: requestOptions.itemId, authentication: requestOptions.authentication }));
431
+ return Object.assign(Object.assign(Object.assign({}, generatedTokens), appToApiKeyProperties(updatedRegisteredAppResponse)), { item: updatedItemInfo });
360
432
  }
361
433
 
362
434
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
@@ -392,42 +464,6 @@
392
464
  return Object.assign(Object.assign({}, appToApiKeyProperties(appResponse)), { item: itemInfo });
393
465
  }
394
466
 
395
- /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
396
- * Apache-2.0 */
397
- /**
398
- * Used to delete the API Key with given `itemId`.
399
- *
400
- * ```js
401
- * import { deleteApiKey, IDeleteApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';
402
- * import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
403
- *
404
- * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
405
- * username: "xyz_usrName",
406
- * password: "xyz_pw"
407
- * });
408
- *
409
- * deleteApiKey({
410
- * itemId: "xyz_itemId",
411
- * authentication: authSession
412
- * }).then((deletedApiKey: IDeleteApiKeyResponse) => {
413
- * // => {itemId: "xyz_itemId", success: true}
414
- * }).catch(e => {
415
- * // => an exception object
416
- * });
417
- * ```
418
- *
419
- * @param requestOptions - Options for {@linkcode deleteApiKey | deleteApiKey()}, including `itemId` of which API key to be deleted and an {@linkcode ArcGISIdentityManager} authentication session.
420
- * @returns A Promise that will resolve to an {@linkcode IDeleteApiKeyResponse} object representing deletion status.
421
- */
422
- async function deleteApiKey(requestOptions) {
423
- requestOptions.httpMethod = "POST";
424
- const baseRequestOptions = extractBaseRequestOptions(requestOptions);
425
- // validate provided itemId associates with API Key
426
- await getApiKey(Object.assign(Object.assign({}, baseRequestOptions), { itemId: requestOptions.itemId, authentication: requestOptions.authentication }));
427
- const removeItemResponse = await arcgisRestPortal.removeItem(Object.assign(Object.assign({}, baseRequestOptions), { id: requestOptions.itemId, authentication: requestOptions.authentication, params: { f: "json" } }));
428
- return removeItemResponse;
429
- }
430
-
431
467
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
432
468
  * Apache-2.0 */
433
469
  /**
@@ -461,42 +497,6 @@
461
497
  return Object.assign(Object.assign({}, appToOAuthAppProperties(appResponse)), { item: itemInfo });
462
498
  }
463
499
 
464
- /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
465
- * Apache-2.0 */
466
- /**
467
- * Used to delete the OAuth2.0 app with given `itemId`.
468
- *
469
- * ```js
470
- * import { deleteOAuthApp, IDeleteOAuthAppResponse } from '@esri/arcgis-rest-developer-credentials';
471
- * import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
472
- *
473
- * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({
474
- * username: "xyz_usrName",
475
- * password: "xyz_pw"
476
- * });
477
- *
478
- * deleteOAuthApp({
479
- * itemId: "xyz_itemId",
480
- * authentication: authSession
481
- * }).then((deletedOAuthApp: IDeleteOAuthAppResponse) => {
482
- * // => {itemId: "xyz_itemId", success: true}
483
- * }).catch(e => {
484
- * // => an exception object
485
- * });
486
- * ```
487
- *
488
- * @param requestOptions - Options for {@linkcode deleteOAuthApp | deleteOAuthApp()}, including `itemId` of which OAuth app to be deleted and an {@linkcode ArcGISIdentityManager} authentication session.
489
- * @returns A Promise that will resolve to an {@linkcode IDeleteOAuthAppResponse} object representing deletion status.
490
- */
491
- async function deleteOAuthApp(requestOptions) {
492
- requestOptions.httpMethod = "POST";
493
- const baseRequestOptions = extractBaseRequestOptions(requestOptions);
494
- // validate provided itemId associates with OAuth app
495
- await getOAuthApp(Object.assign(Object.assign({}, baseRequestOptions), { itemId: requestOptions.itemId, authentication: requestOptions.authentication }));
496
- const removeItemResponse = await arcgisRestPortal.removeItem(Object.assign(Object.assign({}, baseRequestOptions), { id: requestOptions.itemId, authentication: requestOptions.authentication, params: { f: "json" } }));
497
- return removeItemResponse;
498
- }
499
-
500
500
  /* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
501
501
  * Apache-2.0 */
502
502
  /**
@@ -655,18 +655,19 @@
655
655
 
656
656
  exports.appToApiKeyProperties = appToApiKeyProperties;
657
657
  exports.appToOAuthAppProperties = appToOAuthAppProperties;
658
- exports.arePrivilegesValid = arePrivilegesValid;
658
+ exports.buildExpirationDateParams = buildExpirationDateParams;
659
659
  exports.createApiKey = createApiKey;
660
660
  exports.createOAuthApp = createOAuthApp;
661
- exports.deleteApiKey = deleteApiKey;
662
- exports.deleteOAuthApp = deleteOAuthApp;
663
661
  exports.extractBaseRequestOptions = extractBaseRequestOptions;
664
662
  exports.filterKeys = filterKeys;
663
+ exports.generateApiKeyTokens = generateApiKeyTokens;
664
+ exports.generateOptionsToSlots = generateOptionsToSlots;
665
665
  exports.getApiKey = getApiKey;
666
666
  exports.getOAuthApp = getOAuthApp;
667
667
  exports.getRegisteredAppInfo = getRegisteredAppInfo;
668
668
  exports.registerApp = registerApp;
669
669
  exports.registeredAppResponseToApp = registeredAppResponseToApp;
670
+ exports.slotForKey = slotForKey;
670
671
  exports.stringifyArrays = stringifyArrays;
671
672
  exports.unregisterApp = unregisterApp;
672
673
  exports.updateApiKey = updateApiKey;