@esri/arcgis-rest-developer-credentials 2.1.1-alpha.1 → 4.8.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 (74) hide show
  1. package/dist/bundled/developer-credentials.esm.js +12 -12
  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 +731 -733
  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 +2 -3
  10. package/dist/cjs/createApiKey.js.map +1 -1
  11. package/dist/cjs/createOAuthApp.js +2 -3
  12. package/dist/cjs/createOAuthApp.js.map +1 -1
  13. package/dist/cjs/getApiKey.js +2 -3
  14. package/dist/cjs/getApiKey.js.map +1 -1
  15. package/dist/cjs/getOAuthApp.js +2 -3
  16. package/dist/cjs/getOAuthApp.js.map +1 -1
  17. package/dist/cjs/index.js +15 -15
  18. package/dist/cjs/index.js.map +1 -1
  19. package/dist/cjs/invalidateApiKey.js +1 -2
  20. package/dist/cjs/invalidateApiKey.js.map +1 -1
  21. package/dist/cjs/shared/generateApiKeyToken.js +1 -2
  22. package/dist/cjs/shared/generateApiKeyToken.js.map +1 -1
  23. package/dist/cjs/shared/getRegisteredAppInfo.js +2 -3
  24. package/dist/cjs/shared/getRegisteredAppInfo.js.map +1 -1
  25. package/dist/cjs/shared/helpers.js +11 -11
  26. package/dist/cjs/shared/helpers.js.map +1 -1
  27. package/dist/cjs/shared/registerApp.js +2 -3
  28. package/dist/cjs/shared/registerApp.js.map +1 -1
  29. package/dist/cjs/shared/types/apiKeyType.js.map +1 -1
  30. package/dist/cjs/shared/types/appType.js.map +1 -1
  31. package/dist/cjs/shared/types/oAuthType.js.map +1 -1
  32. package/dist/cjs/shared/unregisterApp.js +2 -3
  33. package/dist/cjs/shared/unregisterApp.js.map +1 -1
  34. package/dist/cjs/updateApiKey.js +2 -3
  35. package/dist/cjs/updateApiKey.js.map +1 -1
  36. package/dist/cjs/updateOAuthApp.js +2 -3
  37. package/dist/cjs/updateOAuthApp.js.map +1 -1
  38. package/dist/esm/createApiKey.d.ts +1 -1
  39. package/dist/esm/createApiKey.js +1 -1
  40. package/dist/esm/createApiKey.js.map +1 -1
  41. package/dist/esm/createOAuthApp.d.ts +1 -1
  42. package/dist/esm/createOAuthApp.js +1 -1
  43. package/dist/esm/createOAuthApp.js.map +1 -1
  44. package/dist/esm/getApiKey.d.ts +1 -1
  45. package/dist/esm/getApiKey.js +1 -1
  46. package/dist/esm/getApiKey.js.map +1 -1
  47. package/dist/esm/getOAuthApp.d.ts +1 -1
  48. package/dist/esm/getOAuthApp.js +1 -1
  49. package/dist/esm/getOAuthApp.js.map +1 -1
  50. package/dist/esm/shared/enum/privileges.d.ts +1 -1
  51. package/dist/esm/shared/getRegisteredAppInfo.d.ts +1 -1
  52. package/dist/esm/shared/getRegisteredAppInfo.js +1 -1
  53. package/dist/esm/shared/getRegisteredAppInfo.js.map +1 -1
  54. package/dist/esm/shared/helpers.d.ts +1 -1
  55. package/dist/esm/shared/helpers.js.map +1 -1
  56. package/dist/esm/shared/registerApp.d.ts +1 -1
  57. package/dist/esm/shared/registerApp.js +1 -1
  58. package/dist/esm/shared/registerApp.js.map +1 -1
  59. package/dist/esm/shared/types/apiKeyType.d.ts +4 -4
  60. package/dist/esm/shared/types/apiKeyType.js.map +1 -1
  61. package/dist/esm/shared/types/appType.d.ts +4 -4
  62. package/dist/esm/shared/types/appType.js.map +1 -1
  63. package/dist/esm/shared/types/oAuthType.d.ts +4 -4
  64. package/dist/esm/shared/types/oAuthType.js.map +1 -1
  65. package/dist/esm/shared/unregisterApp.d.ts +1 -1
  66. package/dist/esm/shared/unregisterApp.js +1 -1
  67. package/dist/esm/shared/unregisterApp.js.map +1 -1
  68. package/dist/esm/updateApiKey.d.ts +1 -1
  69. package/dist/esm/updateApiKey.js +1 -1
  70. package/dist/esm/updateApiKey.js.map +1 -1
  71. package/dist/esm/updateOAuthApp.d.ts +1 -1
  72. package/dist/esm/updateOAuthApp.js +1 -1
  73. package/dist/esm/updateOAuthApp.js.map +1 -1
  74. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"developer-credentials.esm.min.js","sources":["../../src/shared/getRegisteredAppInfo.ts","../../src/shared/helpers.ts","../../src/shared/generateApiKeyToken.ts","../../src/shared/registerApp.ts","../../src/createApiKey.ts","../../src/updateApiKey.ts","../../src/getApiKey.ts","../../src/invalidateApiKey.ts","../../src/getOAuthApp.ts","../../src/updateOAuthApp.ts","../../src/createOAuthApp.ts","../../src/shared/unregisterApp.ts"],"sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\nimport { request } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\n\nimport {\n IRegisteredAppResponse,\n IGetAppInfoOptions,\n IApp\n} from \"./types/appType.js\";\nimport { registeredAppResponseToApp } from \"./helpers.js\";\n\n/**\n * 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.\n *\n * ```js\n * import { getRegisteredAppInfo, 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 * getRegisteredAppInfo({\n * itemId: \"xyz_itemId\",\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 getRegisteredAppInfo | getRegisteredAppInfo()}, including an itemId of which app to retrieve and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApp} object representing successfully retrieved app.\n */\nexport async function getRegisteredAppInfo(\n requestOptions: IGetAppInfoOptions\n): Promise<IApp> {\n const userName = await requestOptions.authentication.getUsername();\n const url =\n getPortalUrl(requestOptions) +\n `/content/users/${userName}/items/${requestOptions.itemId}/registeredAppInfo`;\n requestOptions.httpMethod = \"POST\";\n\n const registeredAppResponse: IRegisteredAppResponse = await request(url, {\n ...requestOptions,\n params: { f: \"json\" }\n });\n\n return registeredAppResponseToApp(registeredAppResponse);\n}\n","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. The full API key should be passed. `undefined` will be returned if the proper slot could not be identified.\n */\nexport function slotForKey(key: string) {\n const slot = parseInt(key.substring(key.length - 10, key.length - 9));\n\n if (slot === 1 || slot === 2) {\n return slot;\n }\n\n return undefined;\n}\n\n/**\n * @internal\n * Used to determine which slot to invalidate a key in given a number or a full or patial key.\n */\nexport function slotForInvalidationKey(param: string | 1 | 2) {\n if (param === 1 || param === 2) {\n return param;\n }\n\n if (typeof param !== \"string\") {\n return undefined;\n }\n\n const fullKeySlot = slotForKey(param);\n if (fullKeySlot) {\n return fullKeySlot;\n }\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","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 // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n","/* 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: [\"premium:user:geocode:temporary\", 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","/* 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 * const threeDaysFromToday = new Date();\n * threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);\n * threeDaysFromToday.setHours(23, 59, 59, 999);\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 * generateToken1: true, // optional,generate a new token\n * apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date\n * }).then((registeredAPIKey: IApiKeyResponse) => {\n * // => {accessToken1: \"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","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IApiKeyResponse,\n IUpdateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n generateApiKeyTokens,\n generateOptionsToSlots,\n buildExpirationDateParams\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl, updateItem } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\n\n/**\n * Used to update an API key.\n *\n * Notes about `privileges` and `httpReferrers` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * const threeDaysFromToday = new Date();\n * threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);\n * threeDaysFromToday.setHours(23, 59, 59, 999);\n *\n * updateApiKey({\n * itemId: \"xyz_itemId\",\n * privileges: [\"premium:user:geocode:temporary\"],\n * httpReferrers: [], // httpReferrers will be set to be empty\n * authentication: authSession\n * generateToken1: true, // optional,generate a new token\n * apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date\n * }).then((updatedAPIKey: IApiKeyResponse) => {\n * // => {accessToken1: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateApiKey | updateApiKey()}, including `itemId` of which API key to be operated on, optional new `privileges`, optional new `httpReferrers` and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.\n */\nexport async function updateApiKey(\n requestOptions: IUpdateApiKeyOptions\n): Promise<IApiKeyResponse> {\n requestOptions.httpMethod = \"POST\";\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n\n /**\n * step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.\n */\n if (\n requestOptions.apiToken1ExpirationDate ||\n requestOptions.apiToken2ExpirationDate\n ) {\n const updateParams = buildExpirationDateParams(requestOptions);\n await updateItem({\n ...baseRequestOptions,\n item: {\n id: requestOptions.itemId,\n ...updateParams\n },\n authentication: requestOptions.authentication\n });\n }\n\n /**\n * step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.\n */\n if (requestOptions.privileges || requestOptions.httpReferrers) {\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n const appResponse = await getRegisteredAppInfo(getAppOption);\n const clientId = appResponse.client_id;\n const options = appendCustomParams(\n { ...appResponse, ...requestOptions }, // object with the custom params to look in\n [\"privileges\", \"httpReferrers\"] // keys you want copied to the params object\n );\n options.params.f = \"json\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n }\n\n /**\n * step 3: get the updated item info to return to the user.\n */\n const updatedItemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n /**\n * step 4: generate tokens if requested\n */\n const generatedTokens = await generateApiKeyTokens(\n requestOptions.itemId,\n generateOptionsToSlots(\n requestOptions.generateToken1,\n requestOptions.generateToken2\n ),\n {\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n }\n );\n\n /**\n * step 5: get updated registered app info\n */\n const updatedRegisteredAppResponse = await getRegisteredAppInfo({\n ...baseRequestOptions,\n itemId: requestOptions.itemId,\n authentication: requestOptions.authentication\n });\n\n return {\n ...generatedTokens,\n ...appToApiKeyProperties(updatedRegisteredAppResponse),\n item: updatedItemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n IApiKeyResponse,\n IGetApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getItem } from \"@esri/arcgis-rest-portal\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions\n} from \"./shared/helpers.js\";\n\n/**\n * Used to retrieve the API key with given `itemId`. 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 { getApiKey, 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 * getApiKey({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((retrievedAPIKey: 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 getApiKey | getApiKey()}, including `itemId` of which API key to retrieve and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing successfully retrieved API key.\n */\nexport async function getApiKey(\n requestOptions: IGetApiKeyOptions\n): Promise<IApiKeyResponse> {\n const appResponse = await getRegisteredAppInfo(requestOptions);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...extractBaseRequestOptions(requestOptions),\n authentication: requestOptions.authentication\n });\n\n return {\n ...appToApiKeyProperties(appResponse),\n item: itemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IInvalidateApiKeyOptions,\n IInvalidateApiKeyResponse\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { request } from \"@esri/arcgis-rest-request\";\nimport { slotForInvalidationKey } from \"./shared/helpers.js\";\n\n/**\n * Used to invalidate an API key.\n *\n * ```js\n * import { invalidateApiKey } from \"@esri/arcgis-rest-developer-credentials\";\n *\n * invalidateApiKey({\n * itemId: ITEM_ID,\n * authentication,\n * apiKey: 1, // invalidate the key in slot 1\n * }).then((response) => {\n * // => {success: true}\n * }).catch(e => {\n * // => an exception object\n * });\n */\nexport async function invalidateApiKey(\n requestOptions: IInvalidateApiKeyOptions\n): Promise<IInvalidateApiKeyResponse> {\n const portal = getPortalUrl(requestOptions);\n const url = `${portal}/oauth2/revokeToken`;\n\n const appInfo = await getRegisteredAppInfo({\n itemId: requestOptions.itemId,\n authentication: requestOptions.authentication\n });\n\n const params = {\n client_id: appInfo.client_id,\n client_secret: appInfo.client_secret,\n apiToken: slotForInvalidationKey(requestOptions.apiKey),\n regenerateApiToken: true,\n grant_type: \"client_credentials\"\n };\n\n // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport { getItem } from \"@esri/arcgis-rest-portal\";\nimport {\n appToOAuthAppProperties,\n extractBaseRequestOptions\n} from \"./shared/helpers.js\";\nimport { IGetOAuthAppOptions, IOAuthApp } from \"./shared/types/oAuthType.js\";\n\n/**\n * Used to retrieve the OAuth2.0 app with given `itemId`. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.\n *\n * ```js\n * import { getOAuthApp, IOAuthApp } 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 * getOAuthApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((retrievedOAuthApp: IOAuthApp) => {\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode getOAuthApp | getOAuthApp()}, including `itemId` of which OAuth app to retrieve and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing successfully retrieved OAuth app.\n */\nexport async function getOAuthApp(\n requestOptions: IGetOAuthAppOptions\n): Promise<IOAuthApp> {\n const appResponse = await getRegisteredAppInfo(requestOptions);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...extractBaseRequestOptions(requestOptions),\n authentication: requestOptions.authentication\n });\n\n return {\n ...appToOAuthAppProperties(appResponse),\n item: itemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n appToOAuthAppProperties\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\nimport { IOAuthApp, IUpdateOAuthOptions } from \"./shared/types/oAuthType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\n\n/**\n * Used to update an OAuth2.0 app.\n *\n * Notes about `redirect_uris` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateOAuthApp, IOAuthApp } 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 * updateOAuthApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((updatedOAuthApp: IOAuthApp) => {\n * // => This OAuth app will be not be updated because its redirect_uris is not provided.\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateOAuthApp | updateOAuthApp()}, including `itemId` of which OAuth app to be operated on, optional new `redirect_uris` and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing updated OAuth app.\n */\nexport async function updateOAuthApp(\n requestOptions: IUpdateOAuthOptions\n): Promise<IOAuthApp> {\n requestOptions.httpMethod = \"POST\";\n\n // get app\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n\n const appResponse = await getRegisteredAppInfo(getAppOption);\n\n if (appResponse.appType === \"apikey\") {\n throw new Error(\"Item is not an OAuth 2.0 app.\");\n }\n\n const clientId = appResponse.client_id;\n const options = appendCustomParams({ ...appResponse, ...requestOptions }, [\n \"redirect_uris\"\n ]);\n options.params.f = \"json\";\n options.params.appType = \"multiple\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n\n const app: IApp = registeredAppResponseToApp(updateResponse);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n return {\n ...appToOAuthAppProperties(app),\n item: itemInfo\n };\n}\n","/* 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\";\n\nimport { registerApp } from \"./shared/registerApp.js\";\nimport { IRegisterAppOptions } from \"./shared/types/appType.js\";\nimport {\n filterKeys,\n extractBaseRequestOptions,\n appToOAuthAppProperties\n} from \"./shared/helpers.js\";\nimport { ICreateOAuthAppOption, IOAuthApp } from \"./shared/types/oAuthType.js\";\n\n/**\n * Used to register an OAuth2.0 app. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.\n *\n * ```js\n * import { createOAuthApp, IOAuthApp } 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 * createOAuthApp({\n * title: \"xyz_title\",\n * description: \"xyz_desc\",\n * tags: [\"xyz_tag1\", \"xyz_tag2\"],\n * redirect_uris: [\"http://localhost:3000/\"],\n * authentication: authSession\n * }).then((registeredOAuthApp: IOAuthApp) => {\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode createOAuthApp | createOAuthApp()}, including necessary params to register an OAuth app and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing the newly registered OAuth app.\n */\nexport async function createOAuthApp(\n requestOptions: ICreateOAuthAppOption\n): Promise<IOAuthApp> {\n requestOptions.httpMethod = \"POST\";\n\n // filter param buckets:\n\n const baseRequestOptions = extractBaseRequestOptions(requestOptions);\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: \"Application\"\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: \"multiple\",\n redirect_uris: requestOptions.redirect_uris || [],\n httpReferrers: [],\n 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 ...appToOAuthAppProperties(registeredAppResponse),\n item: itemInfo\n };\n}\n","import {\n IGetAppInfoOptions,\n IUnregisterAppOptions,\n IUnregisterAppResponse\n} from \"./types/appType.js\";\nimport { extractBaseRequestOptions } from \"./helpers.js\";\nimport { getRegisteredAppInfo } from \"./getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { request } from \"@esri/arcgis-rest-request\";\n\n/**\n * Used to unregister the app with given `itemId`. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/unregister-app.htm) for more information.\n *\n * ```js\n * import { unregisterApp, IUnregisterAppResponse } 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 * unregisterApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((unregisteredApp: IUnregisterAppResponse) => {\n * // => {itemId: \"xyz_itemId\", success: true}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode unregisterApp | unregisterApp()}, including `itemId` of which app to be un-registered and an {@linkcode ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IUnregisterAppResponse} object representing un-registration status.\n */\nexport async function unregisterApp(\n requestOptions: IUnregisterAppOptions\n): Promise<IUnregisterAppResponse> {\n requestOptions.httpMethod = \"POST\";\n\n // get app\n const baseRequestOptions = extractBaseRequestOptions(requestOptions);\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n\n const appResponse = await getRegisteredAppInfo(getAppOption);\n\n const clientId = appResponse.client_id;\n\n const url =\n getPortalUrl(requestOptions) + `/oauth2/apps/${clientId}/unregister`;\n\n const unregisterAppResponse: IUnregisterAppResponse = await request(url, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n return unregisterAppResponse;\n}\n"],"names":["async","getRegisteredAppInfo","requestOptions","userName","authentication","getUsername","url","getPortalUrl","itemId","httpMethod","registeredAppResponseToApp","request","params","f","stringifyArrays","Object","entries","forEach","entry","key","value","constructor","name","JSON","stringify","response","omittedKeys","dateKeys","keys","filter","includes","reduce","obj","Date","appToApiKeyProperties","client_secret","redirect_uris","appType","customAppLoginShowTriage","apiKey","appToOAuthAppProperties","httpReferrers","privileges","isPersonalAPIToken","apiToken1Active","apiToken2Active","extractBaseRequestOptions","options","filterKeys","object","includedKeys","ele","slotForKey","slot","parseInt","substring","length","slotForInvalidationKey","param","fullKeySlot","generateApiKeyTokens","slots","Promise","all","map","appInfo","client_id","apiToken","regenerateApiToken","grant_type","generateApiKeyToken","then","responses","access_token","token","index","generateOptionsToSlots","generateToken1","generateToken2","push","buildExpirationDateParams","fillDefaults","updateparams","apiToken1ExpirationDate","apiToken2ExpirationDate","registerApp","appendCustomParams","createApiKey","baseRequestOptions","createItemOption","item","type","createItemResponse","createItem","registerAppOptions","id","registeredAppResponse","updateItem","itemInfo","getItem","generatedTokens","updatedRegisteredAppResponse","updateApiKey","updateParams","getAppOption","appResponse","clientId","updatedItemInfo","getApiKey","invalidateApiKey","getOAuthApp","updateOAuthApp","Error","app","createOAuthApp","registerAppOption","unregisterApp"],"mappings":";;;;;iLAqCOA,eAAeC,EACpBC,GAEA,MAAMC,QAAiBD,EAAeE,eAAeC,cAC/CC,EACJC,EAAaL,GACb,kBAAkBC,WAAkBD,EAAeM,2BACrDN,EAAeO,WAAa,OAO5B,OAAOC,QALqDC,EAAQL,iCAC/DJ,IACHU,OAAQ,CAAEC,EAAG,WAIjB,OCvCaC,EAAmBZ,IAC9Ba,OAAOC,QAAQd,EAAeU,QAAQK,SAASC,IAC7C,MAAOC,EAAKC,GAASF,EACU,UAA3BE,EAAMC,YAAYC,OACpBpB,EAAeU,OAAOO,GAAOI,KAAKC,UAAUJ,MAE9C,WAOYV,EACde,GAEA,MAAMC,EAAc,CAClB,eACA,kBACA,YACA,SACA,4BAEIC,EAAW,CAAC,WAAY,cAE9B,OAAOZ,OAAOa,KAAKH,GAChBI,QAAQV,IAASO,EAAYI,SAASX,KACtCY,QAAO,CAACC,EAAUb,KACbQ,EAASG,SAASX,GACpBa,EAAIb,GAAO,IAAIc,KAAMR,EAAiBN,IAEtCa,EAAIb,GAAQM,EAAiBN,GAExBa,IACN,GACP,UAMgBE,EAAsBT,GAOpC,cANOA,EAASU,qBACTV,EAASW,qBACTX,EAASY,eACRZ,EAAiBa,gCAClBb,EAASc,OAETd,CACT,UAMgBe,EAAwBf,GAUtC,cATOA,EAASY,eACTZ,EAASgB,qBACThB,EAASiB,kBACTjB,EAASc,cACRd,EAAiBa,gCAClBb,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ACpBhH,GAEAA,EAAeO,WAAa,OAI5B,MAAM+E,EAAqB1C,EAA0B5C,GAoB/CuF,+BACJC,oCACK1C,EAAW9C,EApB+B,CAC/C,aACA,UACA,cACA,gBACA,SACA,QACA,aACA,UACA,mBACA,OACA,QACA,OACA,eACA,UAOEyF,KAAM,iBAELH,IACHpF,eAAgBF,EAAeE,eAC/BQ,OAAQ,CACNC,EAAG,UAID+E,QAA2BC,EAAWJ,GAGtC0B,+BACJ3G,OAAQoF,EAAmBG,GAC3B1D,QAAS,WACTD,cAAelC,EAAekC,eAAiB,GAC/CK,cAAe,GACfC,WAAY,IACT8C,IACHpF,eAAgBF,EAAeE,iBAG3B4F,QAA8BX,EAAY8B,GAC1CjB,QAAiBC,EAAQH,EAAsBxF,sCAChDgF,IACHpF,eAAgBF,EAAeE,eAC/BQ,OAAQ,CAAEC,EAAG,WAGf,sCACK2B,EAAwBwD,KAC3BN,KAAMQ,GAEV,CC3EOlG,eAAeoH,EACpBlH,GAEAA,EAAeO,WAAa,OAG5B,MAAM+E,EAAqB1C,EAA0B5C,GAC/CsG,iCACDhB,IACHpF,eAAgBF,EAAeE,eAC/BI,OAAQN,EAAeM,SAKnBkG,SAFoBzG,EAAqBuG,IAElBtC,UAEvB5D,EACJC,EAAaL,GAAkB,gBAAgBwG,eAOjD,aAL4D/F,EAAQL,iCAC/DkF,IACHpF,eAAgBF,EAAeE,eAC/BQ,OAAQ,CAAEC,EAAG,UAGjB"}
1
+ {"version":3,"file":"developer-credentials.esm.min.js","sources":["../../src/shared/getRegisteredAppInfo.ts","../../src/shared/helpers.ts","../../src/shared/generateApiKeyToken.ts","../../src/shared/registerApp.ts","../../src/createApiKey.ts","../../src/updateApiKey.ts","../../src/getApiKey.ts","../../src/invalidateApiKey.ts","../../src/getOAuthApp.ts","../../src/updateOAuthApp.ts","../../src/createOAuthApp.ts","../../src/shared/unregisterApp.ts"],"sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\nimport { request } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\n\nimport {\n IRegisteredAppResponse,\n IGetAppInfoOptions,\n IApp\n} from \"./types/appType.js\";\nimport { registeredAppResponseToApp } from \"./helpers.js\";\n\n/**\n * 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.\n *\n * ```js\n * import { getRegisteredAppInfo, 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 * getRegisteredAppInfo({\n * itemId: \"xyz_itemId\",\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 getRegisteredAppInfo | getRegisteredAppInfo()}, including an itemId of which app to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApp} object representing successfully retrieved app.\n */\nexport async function getRegisteredAppInfo(\n requestOptions: IGetAppInfoOptions\n): Promise<IApp> {\n const userName = await requestOptions.authentication.getUsername();\n const url =\n getPortalUrl(requestOptions) +\n `/content/users/${userName}/items/${requestOptions.itemId}/registeredAppInfo`;\n requestOptions.httpMethod = \"POST\";\n\n const registeredAppResponse: IRegisteredAppResponse = await request(url, {\n ...requestOptions,\n params: { f: \"json\" }\n });\n\n return registeredAppResponseToApp(registeredAppResponse);\n}\n","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. The full API key should be passed. `undefined` will be returned if the proper slot could not be identified.\n */\nexport function slotForKey(key: string) {\n const slot = parseInt(key.substring(key.length - 10, key.length - 9));\n\n if (slot === 1 || slot === 2) {\n return slot;\n }\n\n return undefined;\n}\n\n/**\n * @internal\n * Used to determine which slot to invalidate a key in given a number or a full or patial key.\n */\nexport function slotForInvalidationKey(param: string | 1 | 2) {\n if (param === 1 || param === 2) {\n return param;\n }\n\n if (typeof param !== \"string\") {\n return undefined;\n }\n\n const fullKeySlot = slotForKey(param);\n if (fullKeySlot) {\n return fullKeySlot;\n }\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","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 // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n","/* 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: [\"premium:user:geocode:temporary\", 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 @esri/arcgis-rest-request!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","/* 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 * const threeDaysFromToday = new Date();\n * threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);\n * threeDaysFromToday.setHours(23, 59, 59, 999);\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 * generateToken1: true, // optional,generate a new token\n * apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date\n * }).then((registeredAPIKey: IApiKeyResponse) => {\n * // => {accessToken1: \"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 @esri/arcgis-rest-request!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","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IApiKeyResponse,\n IUpdateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n generateApiKeyTokens,\n generateOptionsToSlots,\n buildExpirationDateParams\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl, updateItem } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\n\n/**\n * Used to update an API key.\n *\n * Notes about `privileges` and `httpReferrers` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * const threeDaysFromToday = new Date();\n * threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);\n * threeDaysFromToday.setHours(23, 59, 59, 999);\n *\n * updateApiKey({\n * itemId: \"xyz_itemId\",\n * privileges: [\"premium:user:geocode:temporary\"],\n * httpReferrers: [], // httpReferrers will be set to be empty\n * authentication: authSession\n * generateToken1: true, // optional,generate a new token\n * apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date\n * }).then((updatedAPIKey: IApiKeyResponse) => {\n * // => {accessToken1: \"xyz_key\", item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateApiKey | updateApiKey()}, including `itemId` of which API key to be operated on, optional new `privileges`, optional new `httpReferrers` and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing updated API key.\n */\nexport async function updateApiKey(\n requestOptions: IUpdateApiKeyOptions\n): Promise<IApiKeyResponse> {\n requestOptions.httpMethod = \"POST\";\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n\n /**\n * step 1: update expiration dates if provided. Build the object up to avoid overwriting any existing properties.\n */\n if (\n requestOptions.apiToken1ExpirationDate ||\n requestOptions.apiToken2ExpirationDate\n ) {\n const updateParams = buildExpirationDateParams(requestOptions);\n await updateItem({\n ...baseRequestOptions,\n item: {\n id: requestOptions.itemId,\n ...updateParams\n },\n authentication: requestOptions.authentication\n });\n }\n\n /**\n * step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.\n */\n if (requestOptions.privileges || requestOptions.httpReferrers) {\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n const appResponse = await getRegisteredAppInfo(getAppOption);\n const clientId = appResponse.client_id;\n const options = appendCustomParams(\n { ...appResponse, ...requestOptions }, // object with the custom params to look in\n [\"privileges\", \"httpReferrers\"] // keys you want copied to the params object\n );\n options.params.f = \"json\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n }\n\n /**\n * step 3: get the updated item info to return to the user.\n */\n const updatedItemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n /**\n * step 4: generate tokens if requested\n */\n const generatedTokens = await generateApiKeyTokens(\n requestOptions.itemId,\n generateOptionsToSlots(\n requestOptions.generateToken1,\n requestOptions.generateToken2\n ),\n {\n ...baseRequestOptions,\n authentication: requestOptions.authentication\n }\n );\n\n /**\n * step 5: get updated registered app info\n */\n const updatedRegisteredAppResponse = await getRegisteredAppInfo({\n ...baseRequestOptions,\n itemId: requestOptions.itemId,\n authentication: requestOptions.authentication\n });\n\n return {\n ...generatedTokens,\n ...appToApiKeyProperties(updatedRegisteredAppResponse),\n item: updatedItemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n IApiKeyResponse,\n IGetApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getItem } from \"@esri/arcgis-rest-portal\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions\n} from \"./shared/helpers.js\";\n\n/**\n * Used to retrieve the API key with given `itemId`. 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 { getApiKey, 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 * getApiKey({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((retrievedAPIKey: 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 getApiKey | getApiKey()}, including `itemId` of which API key to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IApiKeyResponse} object representing successfully retrieved API key.\n */\nexport async function getApiKey(\n requestOptions: IGetApiKeyOptions\n): Promise<IApiKeyResponse> {\n const appResponse = await getRegisteredAppInfo(requestOptions);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...extractBaseRequestOptions(requestOptions),\n authentication: requestOptions.authentication\n });\n\n return {\n ...appToApiKeyProperties(appResponse),\n item: itemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IInvalidateApiKeyOptions,\n IInvalidateApiKeyResponse\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { request } from \"@esri/arcgis-rest-request\";\nimport { slotForInvalidationKey } from \"./shared/helpers.js\";\n\n/**\n * Used to invalidate an API key.\n *\n * ```js\n * import { invalidateApiKey } from \"@esri/arcgis-rest-developer-credentials\";\n *\n * invalidateApiKey({\n * itemId: ITEM_ID,\n * authentication,\n * apiKey: 1, // invalidate the key in slot 1\n * }).then((response) => {\n * // => {success: true}\n * }).catch(e => {\n * // => an exception object\n * });\n */\nexport async function invalidateApiKey(\n requestOptions: IInvalidateApiKeyOptions\n): Promise<IInvalidateApiKeyResponse> {\n const portal = getPortalUrl(requestOptions);\n const url = `${portal}/oauth2/revokeToken`;\n\n const appInfo = await getRegisteredAppInfo({\n itemId: requestOptions.itemId,\n authentication: requestOptions.authentication\n });\n\n const params = {\n client_id: appInfo.client_id,\n client_secret: appInfo.client_secret,\n apiToken: slotForInvalidationKey(requestOptions.apiKey),\n regenerateApiToken: true,\n grant_type: \"client_credentials\"\n };\n\n // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport { getItem } from \"@esri/arcgis-rest-portal\";\nimport {\n appToOAuthAppProperties,\n extractBaseRequestOptions\n} from \"./shared/helpers.js\";\nimport { IGetOAuthAppOptions, IOAuthApp } from \"./shared/types/oAuthType.js\";\n\n/**\n * Used to retrieve the OAuth2.0 app with given `itemId`. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.\n *\n * ```js\n * import { getOAuthApp, IOAuthApp } 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 * getOAuthApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((retrievedOAuthApp: IOAuthApp) => {\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode getOAuthApp | getOAuthApp()}, including `itemId` of which OAuth app to retrieve and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing successfully retrieved OAuth app.\n */\nexport async function getOAuthApp(\n requestOptions: IGetOAuthAppOptions\n): Promise<IOAuthApp> {\n const appResponse = await getRegisteredAppInfo(requestOptions);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...extractBaseRequestOptions(requestOptions),\n authentication: requestOptions.authentication\n });\n\n return {\n ...appToOAuthAppProperties(appResponse),\n item: itemInfo\n };\n}\n","/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n appToOAuthAppProperties\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\nimport { IOAuthApp, IUpdateOAuthOptions } from \"./shared/types/oAuthType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\n\n/**\n * Used to update an OAuth2.0 app.\n *\n * Notes about `redirect_uris` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateOAuthApp, IOAuthApp } 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 * updateOAuthApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((updatedOAuthApp: IOAuthApp) => {\n * // => This OAuth app will be not be updated because its redirect_uris is not provided.\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode updateOAuthApp | updateOAuthApp()}, including `itemId` of which OAuth app to be operated on, optional new `redirect_uris` and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing updated OAuth app.\n */\nexport async function updateOAuthApp(\n requestOptions: IUpdateOAuthOptions\n): Promise<IOAuthApp> {\n requestOptions.httpMethod = \"POST\";\n\n // get app\n const baseRequestOptions = extractBaseRequestOptions(requestOptions); // get base requestOptions snapshot\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n\n const appResponse = await getRegisteredAppInfo(getAppOption);\n\n if (appResponse.appType === \"apikey\") {\n throw new Error(\"Item is not an OAuth 2.0 app.\");\n }\n\n const clientId = appResponse.client_id;\n const options = appendCustomParams({ ...appResponse, ...requestOptions }, [\n \"redirect_uris\"\n ]);\n options.params.f = \"json\";\n options.params.appType = \"multiple\";\n\n // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly\n stringifyArrays(options);\n\n const url = getPortalUrl(options) + `/oauth2/apps/${clientId}/update`;\n\n // Raw response from `/oauth2/apps/${clientId}/update`.\n const updateResponse: IRegisteredAppResponse = await request(url, {\n ...options,\n authentication: requestOptions.authentication\n });\n\n const app: IApp = registeredAppResponseToApp(updateResponse);\n\n const itemInfo = await getItem(requestOptions.itemId, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n\n return {\n ...appToOAuthAppProperties(app),\n item: itemInfo\n };\n}\n","/* 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\";\n\nimport { registerApp } from \"./shared/registerApp.js\";\nimport { IRegisterAppOptions } from \"./shared/types/appType.js\";\nimport {\n filterKeys,\n extractBaseRequestOptions,\n appToOAuthAppProperties\n} from \"./shared/helpers.js\";\nimport { ICreateOAuthAppOption, IOAuthApp } from \"./shared/types/oAuthType.js\";\n\n/**\n * Used to register an OAuth2.0 app. See the [OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/) for more information.\n *\n * ```js\n * import { createOAuthApp, IOAuthApp } 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 * createOAuthApp({\n * title: \"xyz_title\",\n * description: \"xyz_desc\",\n * tags: [\"xyz_tag1\", \"xyz_tag2\"],\n * redirect_uris: [\"http://localhost:3000/\"],\n * authentication: authSession\n * }).then((registeredOAuthApp: IOAuthApp) => {\n * // => {redirect_uris: [\"http://localhost:3000/\"], item: {tags: [\"xyz_tag1\", \"xyz_tag2\"], ...}, ...}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode createOAuthApp | createOAuthApp()}, including necessary params to register an OAuth app and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IOAuthApp} object representing the newly registered OAuth app.\n */\nexport async function createOAuthApp(\n requestOptions: ICreateOAuthAppOption\n): Promise<IOAuthApp> {\n requestOptions.httpMethod = \"POST\";\n\n // filter param buckets:\n\n const baseRequestOptions = extractBaseRequestOptions(requestOptions);\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: \"Application\"\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: \"multiple\",\n redirect_uris: requestOptions.redirect_uris || [],\n httpReferrers: [],\n 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 ...appToOAuthAppProperties(registeredAppResponse),\n item: itemInfo\n };\n}\n","import {\n IGetAppInfoOptions,\n IUnregisterAppOptions,\n IUnregisterAppResponse\n} from \"./types/appType.js\";\nimport { extractBaseRequestOptions } from \"./helpers.js\";\nimport { getRegisteredAppInfo } from \"./getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport { request } from \"@esri/arcgis-rest-request\";\n\n/**\n * Used to unregister the app with given `itemId`. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/unregister-app.htm) for more information.\n *\n * ```js\n * import { unregisterApp, IUnregisterAppResponse } 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 * unregisterApp({\n * itemId: \"xyz_itemId\",\n * authentication: authSession\n * }).then((unregisteredApp: IUnregisterAppResponse) => {\n * // => {itemId: \"xyz_itemId\", success: true}\n * }).catch(e => {\n * // => an exception object\n * });\n * ```\n *\n * @param requestOptions - Options for {@linkcode unregisterApp | unregisterApp()}, including `itemId` of which app to be un-registered and an {@linkcode @esri/arcgis-rest-request!ArcGISIdentityManager} authentication session.\n * @returns A Promise that will resolve to an {@linkcode IUnregisterAppResponse} object representing un-registration status.\n */\nexport async function unregisterApp(\n requestOptions: IUnregisterAppOptions\n): Promise<IUnregisterAppResponse> {\n requestOptions.httpMethod = \"POST\";\n\n // get app\n const baseRequestOptions = extractBaseRequestOptions(requestOptions);\n const getAppOption: IGetAppInfoOptions = {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n itemId: requestOptions.itemId\n };\n\n const appResponse = await getRegisteredAppInfo(getAppOption);\n\n const clientId = appResponse.client_id;\n\n const url =\n getPortalUrl(requestOptions) + `/oauth2/apps/${clientId}/unregister`;\n\n const unregisterAppResponse: IUnregisterAppResponse = await request(url, {\n ...baseRequestOptions,\n authentication: requestOptions.authentication,\n params: { f: \"json\" }\n });\n return unregisterAppResponse;\n}\n"],"names":["async","getRegisteredAppInfo","requestOptions","userName","authentication","getUsername","url","getPortalUrl","itemId","httpMethod","registeredAppResponseToApp","request","Object","assign","params","f","stringifyArrays","entries","forEach","entry","key","value","constructor","name","JSON","stringify","response","omittedKeys","dateKeys","keys","filter","includes","reduce","obj","Date","appToApiKeyProperties","client_secret","redirect_uris","appType","customAppLoginShowTriage","apiKey","appToOAuthAppProperties","httpReferrers","privileges","isPersonalAPIToken","apiToken1Active","apiToken2Active","extractBaseRequestOptions","options","filterKeys","object","includedKeys","ele","slotForKey","slot","parseInt","substring","length","slotForInvalidationKey","param","fullKeySlot","generateApiKeyTokens","slots","Promise","all","map","appInfo","client_id","apiToken","regenerateApiToken","grant_type","generateApiKeyToken","then","responses","access_token","token","index","generateOptionsToSlots","generateToken1","generateToken2","push","buildExpirationDateParams","fillDefaults","updateparams","apiToken1ExpirationDate","apiToken2ExpirationDate","registerApp","appendCustomParams","createApiKey","baseRequestOptions","createItemOption","item","type","createItemResponse","createItem","registerAppOptions","id","registeredAppResponse","updateItem","itemInfo","getItem","generatedTokens","updatedRegisteredAppResponse","updateApiKey","updateParams","getAppOption","appResponse","clientId","updatedItemInfo","getApiKey","invalidateApiKey","getOAuthApp","updateOAuthApp","Error","app","createOAuthApp","registerAppOption","unregisterApp"],"mappings":";;;;;iLAqCOA,eAAeC,EACpBC,GAEA,MAAMC,QAAiBD,EAAeE,eAAeC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