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