@esri/arcgis-rest-developer-credentials 2.0.0 → 2.1.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.
- package/dist/bundled/developer-credentials.esm.js +94 -22
- package/dist/bundled/developer-credentials.esm.js.map +1 -1
- package/dist/bundled/developer-credentials.esm.min.js +2 -2
- package/dist/bundled/developer-credentials.esm.min.js.map +1 -1
- package/dist/bundled/developer-credentials.umd.js +95 -21
- package/dist/bundled/developer-credentials.umd.js.map +1 -1
- package/dist/bundled/developer-credentials.umd.min.js +2 -2
- package/dist/bundled/developer-credentials.umd.min.js.map +1 -1
- package/dist/cjs/createApiKey.js +8 -2
- package/dist/cjs/createApiKey.js.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/invalidateApiKey.js +46 -0
- package/dist/cjs/invalidateApiKey.js.map +1 -0
- package/dist/cjs/shared/generateApiKeyToken.js +1 -1
- package/dist/cjs/shared/generateApiKeyToken.js.map +1 -1
- package/dist/cjs/shared/helpers.js +24 -3
- package/dist/cjs/shared/helpers.js.map +1 -1
- package/dist/cjs/shared/registerApp.js +1 -1
- package/dist/cjs/shared/registerApp.js.map +1 -1
- package/dist/cjs/shared/types/apiKeyType.js.map +1 -1
- package/dist/cjs/updateApiKey.js +22 -14
- package/dist/cjs/updateApiKey.js.map +1 -1
- package/dist/esm/createApiKey.d.ts +8 -2
- package/dist/esm/createApiKey.js +8 -2
- package/dist/esm/createApiKey.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/invalidateApiKey.d.ts +18 -0
- package/dist/esm/invalidateApiKey.js +42 -0
- package/dist/esm/invalidateApiKey.js.map +1 -0
- package/dist/esm/shared/generateApiKeyToken.js +1 -1
- package/dist/esm/shared/generateApiKeyToken.js.map +1 -1
- package/dist/esm/shared/helpers.d.ts +7 -2
- package/dist/esm/shared/helpers.js +22 -2
- package/dist/esm/shared/helpers.js.map +1 -1
- package/dist/esm/shared/registerApp.d.ts +1 -1
- package/dist/esm/shared/registerApp.js +1 -1
- package/dist/esm/shared/registerApp.js.map +1 -1
- package/dist/esm/shared/types/apiKeyType.d.ts +17 -0
- package/dist/esm/shared/types/apiKeyType.js.map +1 -1
- package/dist/esm/updateApiKey.d.ts +8 -2
- package/dist/esm/updateApiKey.js +22 -14
- package/dist/esm/updateApiKey.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
(0, tslib_1.__exportStar)(require("./createApiKey.js"), exports);
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./updateApiKey.js"), exports);
|
|
8
8
|
(0, tslib_1.__exportStar)(require("./getApiKey.js"), exports);
|
|
9
|
+
(0, tslib_1.__exportStar)(require("./invalidateApiKey.js"), exports);
|
|
9
10
|
(0, tslib_1.__exportStar)(require("./getOAuthApp.js"), exports);
|
|
10
11
|
(0, tslib_1.__exportStar)(require("./updateOAuthApp.js"), exports);
|
|
11
12
|
(0, tslib_1.__exportStar)(require("./createOAuthApp.js"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,iEAAkC;AAClC,iEAAkC;AAClC,8DAA+B;AAC/B,gEAAiC;AACjC,mEAAoC;AACpC,mEAAoC;AACpC,2EAA4C;AAC5C,yEAA0C;AAC1C,4EAA6C;AAC7C,2EAA4C;AAC5C,gFAAiD;AACjD,uEAAwC;AACxC,yEAA0C;AAC1C,mEAAoC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,iEAAkC;AAClC,iEAAkC;AAClC,8DAA+B;AAC/B,qEAAsC;AACtC,gEAAiC;AACjC,mEAAoC;AACpC,mEAAoC;AACpC,2EAA4C;AAC5C,yEAA0C;AAC1C,4EAA6C;AAC7C,2EAA4C;AAC5C,gFAAiD;AACjD,uEAAwC;AACxC,yEAA0C;AAC1C,mEAAoC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./invalidateApiKey.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
3
|
+
* Apache-2.0 */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.invalidateApiKey = void 0;
|
|
6
|
+
const getRegisteredAppInfo_js_1 = require("./shared/getRegisteredAppInfo.js");
|
|
7
|
+
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
|
|
8
|
+
const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
9
|
+
const helpers_js_1 = require("./shared/helpers.js");
|
|
10
|
+
/**
|
|
11
|
+
* Used to invalidate an API key.
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
|
+
* import { invalidateApiKey } from "@esri/arcgis-rest-developer-credentials";
|
|
15
|
+
*
|
|
16
|
+
* invalidateApiKey({
|
|
17
|
+
* itemId: ITEM_ID,
|
|
18
|
+
* authentication,
|
|
19
|
+
* apiKey: 1, // invalidate the key in slot 1
|
|
20
|
+
* }).then((response) => {
|
|
21
|
+
* // => {success: true}
|
|
22
|
+
* }).catch(e => {
|
|
23
|
+
* // => an exception object
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
async function invalidateApiKey(requestOptions) {
|
|
27
|
+
const portal = (0, arcgis_rest_portal_1.getPortalUrl)(requestOptions);
|
|
28
|
+
const url = `${portal}/oauth2/revokeToken`;
|
|
29
|
+
const appInfo = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)({
|
|
30
|
+
itemId: requestOptions.itemId,
|
|
31
|
+
authentication: requestOptions.authentication
|
|
32
|
+
});
|
|
33
|
+
const params = {
|
|
34
|
+
client_id: appInfo.client_id,
|
|
35
|
+
client_secret: appInfo.client_secret,
|
|
36
|
+
apiToken: (0, helpers_js_1.slotForInvalidationKey)(requestOptions.apiKey),
|
|
37
|
+
regenerateApiToken: true,
|
|
38
|
+
grant_type: "client_credentials"
|
|
39
|
+
};
|
|
40
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
41
|
+
return (0, arcgis_rest_request_1.request)(url, {
|
|
42
|
+
params
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.invalidateApiKey = invalidateApiKey;
|
|
46
|
+
//# sourceMappingURL=invalidateApiKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidateApiKey.js","sourceRoot":"","sources":["../../src/invalidateApiKey.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAMhB,8EAAwE;AACxE,iEAAwD;AACxD,mEAAoD;AACpD,oDAA6D;AAE7D;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,gBAAgB,CACpC,cAAwC;IAExC,MAAM,MAAM,GAAG,IAAA,iCAAY,EAAC,cAAc,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,GAAG,MAAM,qBAAqB,CAAC;IAE3C,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAoB,EAAC;QACzC,MAAM,EAAE,cAAc,CAAC,MAAM;QAC7B,cAAc,EAAE,cAAc,CAAC,cAAc;KAC9C,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,IAAA,mCAAsB,EAAC,cAAc,CAAC,MAAM,CAAC;QACvD,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,2FAA2F;IAC3F,OAAO,IAAA,6BAAO,EAAC,GAAG,EAAE;QAClB,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAvBD,4CAuBC","sourcesContent":["/* 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"]}
|
|
@@ -18,8 +18,8 @@ async function generateApiKeyToken(options) {
|
|
|
18
18
|
regenerateApiToken: true,
|
|
19
19
|
grant_type: "client_credentials"
|
|
20
20
|
};
|
|
21
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
21
22
|
return (0, arcgis_rest_request_1.request)(url, {
|
|
22
|
-
authentication: options.authentication,
|
|
23
23
|
params
|
|
24
24
|
});
|
|
25
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":";;;AAAA,mEAImC;AACnC,uEAAiE;AACjE,iEAAwD;AASjD,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAoB,EAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,OAAO,IAAA,6BAAO,EAAC,GAAG,EAAE;QAClB,
|
|
1
|
+
{"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":";;;AAAA,mEAImC;AACnC,uEAAiE;AACjE,iEAAwD;AASjD,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAoB,EAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,2FAA2F;IAC3F,OAAO,IAAA,6BAAO,EAAC,GAAG,EAAE;QAClB,MAAM;KACP,CAAC,CAAC;AACL,CAAC;AAvBD,kDAuBC","sourcesContent":["import {\n request,\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { getRegisteredAppInfo } from \"./getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\n\nexport interface IGenerateApiKeyTokenOptions extends IRequestOptions {\n itemId: string;\n apiKey: 1 | 2;\n portal?: string;\n authentication: IAuthenticationManager;\n}\n\nexport async function generateApiKeyToken(\n options: IGenerateApiKeyTokenOptions\n): Promise<{ access_token: string; expires_in: number }> {\n const portal = getPortalUrl(options);\n const url = `${portal}/oauth2/token`;\n\n const appInfo = await getRegisteredAppInfo({\n itemId: options.itemId,\n authentication: options.authentication\n });\n\n const params = {\n client_id: appInfo.client_id,\n client_secret: appInfo.client_secret,\n apiToken: options.apiKey,\n regenerateApiToken: true,\n grant_type: \"client_credentials\"\n };\n\n // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildExpirationDateParams = exports.generateOptionsToSlots = exports.generateApiKeyTokens = exports.slotForKey = exports.filterKeys = exports.extractBaseRequestOptions = exports.appToOAuthAppProperties = exports.appToApiKeyProperties = exports.registeredAppResponseToApp = exports.stringifyArrays = void 0;
|
|
3
|
+
exports.buildExpirationDateParams = exports.generateOptionsToSlots = exports.generateApiKeyTokens = exports.slotForInvalidationKey = exports.slotForKey = exports.filterKeys = exports.extractBaseRequestOptions = exports.appToOAuthAppProperties = exports.appToApiKeyProperties = exports.registeredAppResponseToApp = exports.stringifyArrays = void 0;
|
|
4
4
|
const generateApiKeyToken_js_1 = require("./generateApiKeyToken.js");
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
@@ -103,12 +103,33 @@ function filterKeys(object, includedKeys) {
|
|
|
103
103
|
}
|
|
104
104
|
exports.filterKeys = filterKeys;
|
|
105
105
|
/**
|
|
106
|
-
* Used to determine if a generated key is in slot 1 or slot 2 key.
|
|
106
|
+
* 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.
|
|
107
107
|
*/
|
|
108
108
|
function slotForKey(key) {
|
|
109
|
-
|
|
109
|
+
const slot = parseInt(key.substring(key.length - 10, key.length - 9));
|
|
110
|
+
if (slot === 1 || slot === 2) {
|
|
111
|
+
return slot;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
110
114
|
}
|
|
111
115
|
exports.slotForKey = slotForKey;
|
|
116
|
+
/**
|
|
117
|
+
* @internal
|
|
118
|
+
* Used to determine which slot to invalidate a key in given a number or a full or patial key.
|
|
119
|
+
*/
|
|
120
|
+
function slotForInvalidationKey(param) {
|
|
121
|
+
if (param === 1 || param === 2) {
|
|
122
|
+
return param;
|
|
123
|
+
}
|
|
124
|
+
if (typeof param !== "string") {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
const fullKeySlot = slotForKey(param);
|
|
128
|
+
if (fullKeySlot) {
|
|
129
|
+
return fullKeySlot;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.slotForInvalidationKey = slotForInvalidationKey;
|
|
112
133
|
/**
|
|
113
134
|
* @internal
|
|
114
135
|
* Used to generate tokens in slot 1 and/or 2 of an API key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/shared/helpers.ts"],"names":[],"mappings":";;;AAOA,qEAA+D;AAE/D;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,cAA+B,EAAE,EAAE;IACjE,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;QAC3B,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;YACtC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEF;;;GAGG;AACH,SAAgB,0BAA0B,CACxC,QAAgC;IAEhC,MAAM,WAAW,GAAG;QA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\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisteredAppResponse, IApp } from \"./types/appType.js\";\nimport { IApiKeyInfo } from \"./types/apiKeyType.js\";\nimport { IOAuthAppInfo } from \"./types/oAuthType.js\";\nimport { generateApiKeyToken } from \"./generateApiKeyToken.js\";\n\n/**\n * @internal\n * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.\n */\nexport const stringifyArrays = (requestOptions: IRequestOptions) => {\n Object.entries(requestOptions.params).forEach((entry) => {\n const [key, value] = entry;\n if (value.constructor.name === \"Array\") {\n requestOptions.params[key] = JSON.stringify(value);\n }\n });\n};\n\n/**\n * @internal\n * Used to convert {@linkcode IRegisteredAppResponse} to {@linkcode IApp}.\n */\nexport function registeredAppResponseToApp(\n response: IRegisteredAppResponse\n): IApp {\n const omittedKeys = [\n \"apnsProdCert\",\n \"apnsSandboxCert\",\n \"gcmApiKey\",\n \"isBeta\",\n \"customAppLoginShowTriage\"\n ];\n const dateKeys = [\"modified\", \"registered\"];\n\n return Object.keys(response)\n .filter((key) => !omittedKeys.includes(key))\n .reduce((obj: any, key) => {\n if (dateKeys.includes(key)) {\n obj[key] = new Date((response as any)[key]);\n } else {\n obj[key] = (response as any)[key];\n }\n return obj;\n }, {});\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is \"apikey\".\n */\nexport function appToApiKeyProperties(response: IApp): IApiKeyInfo {\n delete response.client_secret;\n delete response.redirect_uris;\n delete response.appType;\n delete (response as any).customAppLoginShowTriage;\n delete response.apiKey;\n\n return response as IApiKeyInfo;\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.\n */\nexport function appToOAuthAppProperties(response: IApp): IOAuthAppInfo {\n delete response.appType;\n delete response.httpReferrers;\n delete response.privileges;\n delete response.apiKey;\n delete (response as any).customAppLoginShowTriage;\n delete response.isPersonalAPIToken;\n delete response.apiToken1Active;\n delete response.apiToken2Active;\n\n return response as IOAuthAppInfo;\n}\n\n/**\n * @internal\n * Used to extract base request options from a hybrid option and exclude `params` and `authentication`.\n */\nexport function extractBaseRequestOptions<T extends IRequestOptions>(\n options: T\n): Partial<IRequestOptions> {\n const requestOptionsProperties: Array<keyof T> = [\n \"credentials\",\n \"headers\",\n \"hideToken\",\n \"httpMethod\",\n \"maxUrlLength\",\n \"portal\",\n \"rawResponse\",\n \"signal\",\n \"suppressWarnings\"\n ];\n\n return filterKeys(options, requestOptionsProperties);\n}\n\n/**\n * @internal\n * Used to create a new object including only specified keys from another object.\n */\nexport function filterKeys<T extends object>(\n object: T,\n includedKeys: Array<keyof T>\n): any {\n return includedKeys.reduce(\n (obj: { [key: string | number | symbol]: any }, ele) => {\n if (ele in object) {\n obj[ele] = object[ele];\n }\n return obj;\n },\n {}\n );\n}\n\n/**\n * Used to determine if a generated key is in slot 1 or slot 2 key.\n */\nexport function slotForKey(key: string) {\n return parseInt(key.substring(key.length - 10, key.length - 9));\n}\n\ninterface IGenerateApiKeyTokenOptions extends IRequestOptions {\n authentication: IAuthenticationManager;\n}\n\n/**\n * @internal\n * Used to generate tokens in slot 1 and/or 2 of an API key.\n */\nexport function generateApiKeyTokens(\n itemId: string,\n slots: Array<1 | 2>,\n requestOptions: IGenerateApiKeyTokenOptions\n) {\n return Promise.all(\n slots.map((slot) => {\n return generateApiKeyToken({\n itemId,\n apiKey: slot,\n ...requestOptions\n });\n })\n ).then((responses) => {\n return responses\n .map((responses) => responses.access_token)\n .reduce((obj, token, index) => {\n obj[`accessToken${slotForKey(token)}`] = token;\n return obj;\n }, {} as { [key: string]: string });\n });\n}\n\n/**\n * @internal\n * Convert boolean flags to an array of slots for {@linkcode generateApiKeyTokens}.\n */\nexport function generateOptionsToSlots(\n generateToken1: boolean,\n generateToken2: boolean\n): Array<1 | 2> {\n const slots: Array<1 | 2> = [];\n if (generateToken1) {\n slots.push(1);\n }\n if (generateToken2) {\n slots.push(2);\n }\n return slots;\n}\n\ntype expirationDateParams =\n | {\n apiToken1ExpirationDate: Date | -1;\n apiToken2ExpirationDate: Date | -1;\n }\n | {\n apiToken1ExpirationDate: Date | -1;\n }\n | {\n apiToken2ExpirationDate: Date | -1;\n }\n | {};\n\n/**\n * @internal\n * Build params for updating expiration dates\n */\nexport function buildExpirationDateParams(\n requestOptions: {\n apiToken1ExpirationDate?: Date;\n apiToken2ExpirationDate?: Date;\n },\n fillDefaults?: boolean\n): expirationDateParams {\n const updateparams: any = {};\n if (requestOptions.apiToken1ExpirationDate) {\n updateparams.apiToken1ExpirationDate =\n requestOptions.apiToken1ExpirationDate;\n }\n\n if (requestOptions.apiToken2ExpirationDate) {\n updateparams.apiToken2ExpirationDate =\n requestOptions.apiToken2ExpirationDate;\n }\n\n if (fillDefaults && !updateparams.apiToken1ExpirationDate) {\n updateparams.apiToken1ExpirationDate = -1;\n }\n\n if (fillDefaults && !updateparams.apiToken2ExpirationDate) {\n updateparams.apiToken2ExpirationDate = -1;\n }\n return updateparams;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/shared/helpers.ts"],"names":[],"mappings":";;;AAOA,qEAA+D;AAE/D;;;GAGG;AACI,MAAM,eAAe,GAAG,CAAC,cAA+B,EAAE,EAAE;IACjE,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC;QAC3B,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,OAAO,EAAE;YACtC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACpD;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAPW,QAAA,eAAe,mBAO1B;AAEF;;;GAGG;AACH,SAAgB,0BAA0B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E,CAAC;IAC7B,IAAI,cAAc,CAAC,uBAAuB,EAAE;QAC1C,YAAY,CAAC,uBAAuB;YAClC,cAAc,CAAC,uBAAuB,CAAC;KAC1C;IAED,IAAI,cAAc,CAAC,uBAAuB,EAAE;QAC1C,YAAY,CAAC,uBAAuB;YAClC,cAAc,CAAC,uBAAuB,CAAC;KAC1C;IAED,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE;QACzD,YAAY,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC;KAC3C;IAED,IAAI,YAAY,IAAI,CAAC,YAAY,CAAC,uBAAuB,EAAE;QACzD,YAAY,CAAC,uBAAuB,GAAG,CAAC,CAAC,CAAC;KAC3C;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AA1BD,8DA0BC","sourcesContent":["import {\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisteredAppResponse, IApp } from \"./types/appType.js\";\nimport { IApiKeyInfo } from \"./types/apiKeyType.js\";\nimport { IOAuthAppInfo } from \"./types/oAuthType.js\";\nimport { generateApiKeyToken } from \"./generateApiKeyToken.js\";\n\n/**\n * @internal\n * Encode special params value (e.g. array type...) in advance in order to make {@linkcode encodeParam} works correctly. Usage is case by case.\n */\nexport const stringifyArrays = (requestOptions: IRequestOptions) => {\n Object.entries(requestOptions.params).forEach((entry) => {\n const [key, value] = entry;\n if (value.constructor.name === \"Array\") {\n requestOptions.params[key] = JSON.stringify(value);\n }\n });\n};\n\n/**\n * @internal\n * Used to convert {@linkcode IRegisteredAppResponse} to {@linkcode IApp}.\n */\nexport function registeredAppResponseToApp(\n response: IRegisteredAppResponse\n): IApp {\n const omittedKeys = [\n \"apnsProdCert\",\n \"apnsSandboxCert\",\n \"gcmApiKey\",\n \"isBeta\",\n \"customAppLoginShowTriage\"\n ];\n const dateKeys = [\"modified\", \"registered\"];\n\n return Object.keys(response)\n .filter((key) => !omittedKeys.includes(key))\n .reduce((obj: any, key) => {\n if (dateKeys.includes(key)) {\n obj[key] = new Date((response as any)[key]);\n } else {\n obj[key] = (response as any)[key];\n }\n return obj;\n }, {});\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IApiKeyInfo} only if `appType` is \"apikey\".\n */\nexport function appToApiKeyProperties(response: IApp): IApiKeyInfo {\n delete response.client_secret;\n delete response.redirect_uris;\n delete response.appType;\n delete (response as any).customAppLoginShowTriage;\n delete response.apiKey;\n\n return response as IApiKeyInfo;\n}\n\n/**\n * @internal\n * Used to convert {@linkcode IApp} to {@linkcode IOAuthAppInfo}.\n */\nexport function appToOAuthAppProperties(response: IApp): IOAuthAppInfo {\n delete response.appType;\n delete response.httpReferrers;\n delete response.privileges;\n delete response.apiKey;\n delete (response as any).customAppLoginShowTriage;\n delete response.isPersonalAPIToken;\n delete response.apiToken1Active;\n delete response.apiToken2Active;\n\n return response as IOAuthAppInfo;\n}\n\n/**\n * @internal\n * Used to extract base request options from a hybrid option and exclude `params` and `authentication`.\n */\nexport function extractBaseRequestOptions<T extends IRequestOptions>(\n options: T\n): Partial<IRequestOptions> {\n const requestOptionsProperties: Array<keyof T> = [\n \"credentials\",\n \"headers\",\n \"hideToken\",\n \"httpMethod\",\n \"maxUrlLength\",\n \"portal\",\n \"rawResponse\",\n \"signal\",\n \"suppressWarnings\"\n ];\n\n return filterKeys(options, requestOptionsProperties);\n}\n\n/**\n * @internal\n * Used to create a new object including only specified keys from another object.\n */\nexport function filterKeys<T extends object>(\n object: T,\n includedKeys: Array<keyof T>\n): any {\n return includedKeys.reduce(\n (obj: { [key: string | number | symbol]: any }, ele) => {\n if (ele in object) {\n obj[ele] = object[ele];\n }\n return obj;\n },\n {}\n );\n}\n\n/**\n * Used to determine if a generated key is in slot 1 or slot 2 key. 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"]}
|
|
@@ -30,7 +30,7 @@ const helpers_js_1 = require("./helpers.js");
|
|
|
30
30
|
* appType: "multiple",
|
|
31
31
|
* redirect_uris: ["http://localhost:3000/"],
|
|
32
32
|
* httpReferrers: ["http://localhost:3000/"],
|
|
33
|
-
* privileges: [
|
|
33
|
+
* privileges: ["premium:user:geocode:temporary", Privileges.FeatureReport],
|
|
34
34
|
* authentication: authSession
|
|
35
35
|
* }).then((registeredApp: IApp) => {
|
|
36
36
|
* // => {client_id: "xyz_id", client_secret: "xyz_secret", ...}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerApp.js","sourceRoot":"","sources":["../../../src/shared/registerApp.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAwE;AACxE,iEAAwD;AAMxD,6CAA2E;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,eAAe;IACf,MAAM,OAAO,GAAG,IAAA,wCAAkB,EAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC;IAC1D,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;IAE1B,MAAM,qBAAqB,GAA2B,MAAM,IAAA,6BAAO,EACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,IAAA,uCAA0B,EAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC;AAxBD,kCAwBC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, appendCustomParams } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport {\n IApp,\n IRegisterAppOptions,\n IRegisteredAppResponse\n} from \"./types/appType.js\";\nimport { stringifyArrays, registeredAppResponseToApp } from \"./helpers.js\";\n\n/**\n * Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.\n *\n * Accepted app types:\n * - apikey\n * - multiple\n * - browser\n * - server\n * - native\n *\n * ```js\n * import { registerApp, IApp } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * registerApp({\n * itemId: \"xyz_itemId\",\n * appType: \"multiple\",\n * redirect_uris: [\"http://localhost:3000/\"],\n * httpReferrers: [\"http://localhost:3000/\"],\n * privileges: [
|
|
1
|
+
{"version":3,"file":"registerApp.js","sourceRoot":"","sources":["../../../src/shared/registerApp.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAEhB,mEAAwE;AACxE,iEAAwD;AAMxD,6CAA2E;AAE3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACI,KAAK,UAAU,WAAW,CAC/B,cAAmC;IAEnC,eAAe;IACf,MAAM,OAAO,GAAG,IAAA,wCAAkB,EAAC,cAAc,EAAE;QACjD,QAAQ;QACR,SAAS;QACT,eAAe;QACf,eAAe;QACf,YAAY;KACb,CAAC,CAAC;IACH,mHAAmH;IACnH,IAAA,4BAAe,EAAC,OAAO,CAAC,CAAC;IAEzB,MAAM,GAAG,GAAG,IAAA,iCAAY,EAAC,OAAO,CAAC,GAAG,qBAAqB,CAAC;IAC1D,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;IAE1B,MAAM,qBAAqB,GAA2B,MAAM,IAAA,6BAAO,EACjE,GAAG,EACH,OAAO,CACR,CAAC;IAEF,OAAO,IAAA,uCAA0B,EAAC,qBAAqB,CAAC,CAAC;AAC3D,CAAC;AAxBD,kCAwBC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport { request, appendCustomParams } from \"@esri/arcgis-rest-request\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\nimport {\n IApp,\n IRegisterAppOptions,\n IRegisteredAppResponse\n} from \"./types/appType.js\";\nimport { stringifyArrays, registeredAppResponseToApp } from \"./helpers.js\";\n\n/**\n * Used to register an app. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/register-app.htm) for more information.\n *\n * Accepted app types:\n * - apikey\n * - multiple\n * - browser\n * - server\n * - native\n *\n * ```js\n * import { registerApp, IApp } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * registerApp({\n * itemId: \"xyz_itemId\",\n * appType: \"multiple\",\n * redirect_uris: [\"http://localhost:3000/\"],\n * httpReferrers: [\"http://localhost:3000/\"],\n * privileges: [\"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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiKeyType.js","sourceRoot":"","sources":["../../../../src/shared/types/apiKeyType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IAuthenticationManager,\n IRequestOptions,\n ISpatialReference\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisterAppOptions, IApp } from \"./appType.js\";\nimport { Privileges } from \"../enum/privileges.js\";\nimport { IItem } from \"@esri/arcgis-rest-portal\";\n\n/**\n * Options to register an API Key.\n */\nexport interface ICreateApiKeyOptions\n extends Omit<\n IRegisterAppOptions,\n \"itemId\" | \"redirect_uris\" | \"appType\" | \"httpReferrers\"\n > {\n httpReferrers?: string[];\n title: string;\n owner?: string;\n typeKeywords?: string[];\n description?: string;\n snippet?: string;\n documentation?: string;\n extent?: number[][];\n categories?: string[];\n spatialReference?: ISpatialReference;\n culture?: string;\n properties?: any;\n url?: string;\n tags?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to retrieve an API Key.\n */\nexport interface IGetApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Represent only the API key related properties from {@linkcode IApp}.\n */\nexport interface IApiKeyInfo\n extends Omit<IApp, \"client_secret\" | \"redirect_uris\" | \"appType\"> {}\n\n/**\n * Return value of {@linkcode createApiKey}, {@linkcode getApiKey}, {@linkcode updateApiKey} representing an API Key entity. `accessToken1`/`accessToken2` properties are only available when `generateToken1`/`generateToken2` are `true`.\n */\nexport interface IApiKeyResponse extends IApiKeyInfo {\n /**\n * Represent item info attached to this API Key.\n */\n item: IItem;\n accessToken1?: null | string;\n accessToken2?: null | string;\n}\n\n/**\n * Options to update an API Key.\n */\nexport interface IUpdateApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key will be updated.\n */\n itemId: string;\n /**\n * Override previous `httpReferrers` if this value is provided.\n */\n httpReferrers?: string[];\n /**\n * Override previous `privileges` if this value is provided.\n */\n privileges?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to delete an API key.\n */\nexport interface IDeleteApiKeyOption extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be removed.\n */\n itemId: string;\n}\n\n/**\n * Response of API key deletion.\n */\nexport interface IDeleteApiKeyResponse {\n /**\n * itemId of which API key has been removed.\n */\n itemId: string;\n success: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"apiKeyType.js","sourceRoot":"","sources":["../../../../src/shared/types/apiKeyType.ts"],"names":[],"mappings":"","sourcesContent":["import {\n IAuthenticationManager,\n IRequestOptions,\n ISpatialReference\n} from \"@esri/arcgis-rest-request\";\nimport { IRegisterAppOptions, IApp } from \"./appType.js\";\nimport { Privileges } from \"../enum/privileges.js\";\nimport { IItem } from \"@esri/arcgis-rest-portal\";\n\n/**\n * Options to register an API Key.\n */\nexport interface ICreateApiKeyOptions\n extends Omit<\n IRegisterAppOptions,\n \"itemId\" | \"redirect_uris\" | \"appType\" | \"httpReferrers\"\n > {\n httpReferrers?: string[];\n title: string;\n owner?: string;\n typeKeywords?: string[];\n description?: string;\n snippet?: string;\n documentation?: string;\n extent?: number[][];\n categories?: string[];\n spatialReference?: ISpatialReference;\n culture?: string;\n properties?: any;\n url?: string;\n tags?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to retrieve an API Key.\n */\nexport interface IGetApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be retrieved.\n */\n itemId: string;\n}\n\n/**\n * Represent only the API key related properties from {@linkcode IApp}.\n */\nexport interface IApiKeyInfo\n extends Omit<IApp, \"client_secret\" | \"redirect_uris\" | \"appType\"> {}\n\n/**\n * Return value of {@linkcode createApiKey}, {@linkcode getApiKey}, {@linkcode updateApiKey} representing an API Key entity. `accessToken1`/`accessToken2` properties are only available when `generateToken1`/`generateToken2` are `true`.\n */\nexport interface IApiKeyResponse extends IApiKeyInfo {\n /**\n * Represent item info attached to this API Key.\n */\n item: IItem;\n accessToken1?: null | string;\n accessToken2?: null | string;\n}\n\n/**\n * Options to update an API Key.\n */\nexport interface IUpdateApiKeyOptions extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key will be updated.\n */\n itemId: string;\n /**\n * Override previous `httpReferrers` if this value is provided.\n */\n httpReferrers?: string[];\n /**\n * Override previous `privileges` if this value is provided.\n */\n privileges?: string[];\n /**\n * Expiration date of the access token in slot 1 of this API Key.\n */\n apiToken1ExpirationDate?: Date;\n /**\n * Expiration date of the access token in slot 2 of this API Key.\n */\n apiToken2ExpirationDate?: Date;\n /**\n * Generate a new access token in slot 1 of this API. Will override and invalidate any existing token.\n */\n generateToken1?: boolean;\n /**\n * Generate a new access token in slot 2 of this API. Will override and invalidate any existing token.\n */\n generateToken2?: boolean;\n}\n\n/**\n * Options to delete an API key.\n */\nexport interface IDeleteApiKeyOption extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of which API key to be removed.\n */\n itemId: string;\n}\n\n/**\n * Response of API key deletion.\n */\nexport interface IDeleteApiKeyResponse {\n /**\n * itemId of which API key has been removed.\n */\n itemId: string;\n success: boolean;\n}\n\nexport interface IInvalidateApiKeyOptions\n extends Omit<IRequestOptions, \"params\"> {\n /**\n * {@linkcode IAuthenticationManager} authentication.\n */\n authentication: IAuthenticationManager;\n /**\n * itemId of the item of the API key to be revoked.\n */\n itemId: string;\n /**\n * The API key to be revoked. The full or partial API key or the slot number (1 or 2) can be provided.\n */\n apiKey?: string | 1 | 2;\n}\n\nexport interface IInvalidateApiKeyResponse {\n success: boolean;\n}\n"]}
|
package/dist/cjs/updateApiKey.js
CHANGED
|
@@ -23,13 +23,19 @@ const arcgis_rest_request_1 = require("@esri/arcgis-rest-request");
|
|
|
23
23
|
* password: "xyz_pw"
|
|
24
24
|
* });
|
|
25
25
|
*
|
|
26
|
+
* const threeDaysFromToday = new Date();
|
|
27
|
+
* threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
|
|
28
|
+
* threeDaysFromToday.setHours(23, 59, 59, 999);
|
|
29
|
+
*
|
|
26
30
|
* updateApiKey({
|
|
27
31
|
* itemId: "xyz_itemId",
|
|
28
|
-
* privileges: [
|
|
32
|
+
* privileges: ["premium:user:geocode:temporary"],
|
|
29
33
|
* httpReferrers: [], // httpReferrers will be set to be empty
|
|
30
34
|
* authentication: authSession
|
|
35
|
+
* generateToken1: true, // optional,generate a new token
|
|
36
|
+
* apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
|
|
31
37
|
* }).then((updatedAPIKey: IApiKeyResponse) => {
|
|
32
|
-
* // => {
|
|
38
|
+
* // => {accessToken1: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
33
39
|
* }).catch(e => {
|
|
34
40
|
* // => an exception object
|
|
35
41
|
* });
|
|
@@ -52,18 +58,20 @@ async function updateApiKey(requestOptions) {
|
|
|
52
58
|
/**
|
|
53
59
|
* step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.
|
|
54
60
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
if (requestOptions.privileges || requestOptions.httpReferrers) {
|
|
62
|
+
const getAppOption = Object.assign(Object.assign({}, baseRequestOptions), { authentication: requestOptions.authentication, itemId: requestOptions.itemId });
|
|
63
|
+
const appResponse = await (0, getRegisteredAppInfo_js_1.getRegisteredAppInfo)(getAppOption);
|
|
64
|
+
const clientId = appResponse.client_id;
|
|
65
|
+
const options = (0, arcgis_rest_request_1.appendCustomParams)(Object.assign(Object.assign({}, appResponse), requestOptions), // object with the custom params to look in
|
|
66
|
+
["privileges", "httpReferrers"] // keys you want copied to the params object
|
|
67
|
+
);
|
|
68
|
+
options.params.f = "json";
|
|
69
|
+
// encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
|
|
70
|
+
(0, helpers_js_1.stringifyArrays)(options);
|
|
71
|
+
const url = (0, arcgis_rest_portal_1.getPortalUrl)(options) + `/oauth2/apps/${clientId}/update`;
|
|
72
|
+
// Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
|
|
73
|
+
const updateResponse = await (0, arcgis_rest_request_1.request)(url, Object.assign(Object.assign({}, options), { authentication: requestOptions.authentication }));
|
|
74
|
+
}
|
|
67
75
|
/**
|
|
68
76
|
* step 3: get the updated item info to return to the user.
|
|
69
77
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateApiKey.js","sourceRoot":"","sources":["../../src/updateApiKey.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAMhB,8EAAwE;AACxE,oDAQ6B;AAC7B,iEAA6E;AAC7E,mEAAwE;AAOxE
|
|
1
|
+
{"version":3,"file":"updateApiKey.js","sourceRoot":"","sources":["../../src/updateApiKey.ts"],"names":[],"mappings":";AAAA;gBACgB;;;AAMhB,8EAAwE;AACxE,oDAQ6B;AAC7B,iEAA6E;AAC7E,mEAAwE;AAOxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACI,KAAK,UAAU,YAAY,CAChC,cAAoC;IAEpC,cAAc,CAAC,UAAU,GAAG,MAAM,CAAC;IACnC,MAAM,kBAAkB,GAAG,IAAA,sCAAyB,EAAC,cAAc,CAAC,CAAC,CAAC,mCAAmC;IAEzG;;OAEG;IACH,IACE,cAAc,CAAC,uBAAuB;QACtC,cAAc,CAAC,uBAAuB,EACtC;QACA,MAAM,YAAY,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AAA,iCAAoB,EAChD,cAAc,CAAC,MAAM,EACrB,IAAA,mCAAsB,EACpB,cAAc,CAAC,cAAc,EAC7B,cAAc,CAAC,cAAc,CAC9B,kCAEI,kBAAkB,KACrB,cAAc,EAAE,cAAc,CAAC,cAAc,IAEhD,CAAC;IAEF;;OAEG;IACH,MAAM,4BAA4B,GAAG,MAAM,IAAA,8CAAoB,kCAC1D,kBAAkB,KACrB,MAAM,EAAE,cAAc,CAAC,MAAM,EAC7B,cAAc,EAAE,cAAc,CAAC,cAAc,IAC7C,CAAC;IAEH,qDACK,eAAe,GACf,IAAA,kCAAqB,EAAC,4BAA4B,CAAC,KACtD,IAAI,EAAE,eAAe,IACrB;AACJ,CAAC;AA3FD,oCA2FC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n IApiKeyResponse,\n IUpdateApiKeyOptions\n} from \"./shared/types/apiKeyType.js\";\nimport { getRegisteredAppInfo } from \"./shared/getRegisteredAppInfo.js\";\nimport {\n appToApiKeyProperties,\n extractBaseRequestOptions,\n stringifyArrays,\n registeredAppResponseToApp,\n generateApiKeyTokens,\n generateOptionsToSlots,\n buildExpirationDateParams\n} from \"./shared/helpers.js\";\nimport { getItem, getPortalUrl, updateItem } from \"@esri/arcgis-rest-portal\";\nimport { appendCustomParams, request } from \"@esri/arcgis-rest-request\";\nimport {\n IApp,\n IGetAppInfoOptions,\n IRegisteredAppResponse\n} from \"./shared/types/appType.js\";\n\n/**\n * Used to update an API key.\n *\n * Notes about `privileges` and `httpReferrers` options:\n * 1. Provided option will override corresponding old option.\n * 2. Unprovided option will not trigger corresponding option updates.\n *\n * ```js\n * import { updateApiKey, IApiKeyResponse } from '@esri/arcgis-rest-developer-credentials';\n * import { ArcGISIdentityManager } from \"@esri/arcgis-rest-request\";\n *\n * const authSession: ArcGISIdentityManager = await ArcGISIdentityManager.signIn({\n * username: \"xyz_usrName\",\n * password: \"xyz_pw\"\n * });\n *\n * 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"]}
|
|
@@ -11,14 +11,20 @@ import { IApiKeyResponse, ICreateApiKeyOptions } from "./shared/types/apiKeyType
|
|
|
11
11
|
* password: "xyz_pw"
|
|
12
12
|
* });
|
|
13
13
|
*
|
|
14
|
+
* const threeDaysFromToday = new Date();
|
|
15
|
+
* threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
|
|
16
|
+
* threeDaysFromToday.setHours(23, 59, 59, 999);
|
|
17
|
+
*
|
|
14
18
|
* createApiKey({
|
|
15
19
|
* title: "xyz_title",
|
|
16
20
|
* description: "xyz_desc",
|
|
17
21
|
* tags: ["xyz_tag1", "xyz_tag2"],
|
|
18
22
|
* privileges: ["premium:user:networkanalysis:routing"],
|
|
19
|
-
* authentication: authSession
|
|
23
|
+
* authentication: authSession,
|
|
24
|
+
* generateToken1: true, // optional,generate a new token
|
|
25
|
+
* apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
|
|
20
26
|
* }).then((registeredAPIKey: IApiKeyResponse) => {
|
|
21
|
-
* // => {
|
|
27
|
+
* // => {accessToken1: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
22
28
|
* }).catch(e => {
|
|
23
29
|
* // => an exception object
|
|
24
30
|
* });
|
package/dist/esm/createApiKey.js
CHANGED
|
@@ -16,14 +16,20 @@ import { getRegisteredAppInfo } from "./shared/getRegisteredAppInfo.js";
|
|
|
16
16
|
* password: "xyz_pw"
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
|
+
* const threeDaysFromToday = new Date();
|
|
20
|
+
* threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
|
|
21
|
+
* threeDaysFromToday.setHours(23, 59, 59, 999);
|
|
22
|
+
*
|
|
19
23
|
* createApiKey({
|
|
20
24
|
* title: "xyz_title",
|
|
21
25
|
* description: "xyz_desc",
|
|
22
26
|
* tags: ["xyz_tag1", "xyz_tag2"],
|
|
23
27
|
* privileges: ["premium:user:networkanalysis:routing"],
|
|
24
|
-
* authentication: authSession
|
|
28
|
+
* authentication: authSession,
|
|
29
|
+
* generateToken1: true, // optional,generate a new token
|
|
30
|
+
* apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
|
|
25
31
|
* }).then((registeredAPIKey: IApiKeyResponse) => {
|
|
26
|
-
* // => {
|
|
32
|
+
* // => {accessToken1: "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
|
|
27
33
|
* }).catch(e => {
|
|
28
34
|
* // => an exception object
|
|
29
35
|
* });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiKey.js","sourceRoot":"","sources":["../../src/createApiKey.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,OAAO,EAEL,UAAU,EACV,OAAO,EAEP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C,cAAc,IAC7C,CAAC;IAEH,qDACK,eAAe,GACf,qBAAqB,CAAC,4BAA4B,CAAC,KACtD,IAAI,EAAE,QAAQ,IACd;AACJ,CAAC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nimport {\n ICreateItemOptions,\n createItem,\n getItem,\n IItemAdd,\n 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"]}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;gBACgB;AAEhB,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC","sourcesContent":["/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.\n * Apache-2.0 */\n\nexport * from \"./createApiKey.js\";\nexport * from \"./updateApiKey.js\";\nexport * from \"./getApiKey.js\";\nexport * from \"./invalidateApiKey.js\";\nexport * from \"./getOAuthApp.js\";\nexport * from \"./updateOAuthApp.js\";\nexport * from \"./createOAuthApp.js\";\nexport * from \"./shared/enum/privileges.js\";\nexport * from \"./shared/types/appType.js\";\nexport * from \"./shared/types/apiKeyType.js\";\nexport * from \"./shared/types/oAuthType.js\";\nexport * from \"./shared/getRegisteredAppInfo.js\";\nexport * from \"./shared/registerApp.js\";\nexport * from \"./shared/unregisterApp.js\";\nexport * from \"./shared/helpers.js\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IInvalidateApiKeyOptions, IInvalidateApiKeyResponse } from "./shared/types/apiKeyType.js";
|
|
2
|
+
/**
|
|
3
|
+
* Used to invalidate an API key.
|
|
4
|
+
*
|
|
5
|
+
* ```js
|
|
6
|
+
* import { invalidateApiKey } from "@esri/arcgis-rest-developer-credentials";
|
|
7
|
+
*
|
|
8
|
+
* invalidateApiKey({
|
|
9
|
+
* itemId: ITEM_ID,
|
|
10
|
+
* authentication,
|
|
11
|
+
* apiKey: 1, // invalidate the key in slot 1
|
|
12
|
+
* }).then((response) => {
|
|
13
|
+
* // => {success: true}
|
|
14
|
+
* }).catch(e => {
|
|
15
|
+
* // => an exception object
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare function invalidateApiKey(requestOptions: IInvalidateApiKeyOptions): Promise<IInvalidateApiKeyResponse>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* Copyright (c) 2023 Environmental Systems Research Institute, Inc.
|
|
2
|
+
* Apache-2.0 */
|
|
3
|
+
import { getRegisteredAppInfo } from "./shared/getRegisteredAppInfo.js";
|
|
4
|
+
import { getPortalUrl } from "@esri/arcgis-rest-portal";
|
|
5
|
+
import { request } from "@esri/arcgis-rest-request";
|
|
6
|
+
import { slotForInvalidationKey } from "./shared/helpers.js";
|
|
7
|
+
/**
|
|
8
|
+
* Used to invalidate an API key.
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* import { invalidateApiKey } from "@esri/arcgis-rest-developer-credentials";
|
|
12
|
+
*
|
|
13
|
+
* invalidateApiKey({
|
|
14
|
+
* itemId: ITEM_ID,
|
|
15
|
+
* authentication,
|
|
16
|
+
* apiKey: 1, // invalidate the key in slot 1
|
|
17
|
+
* }).then((response) => {
|
|
18
|
+
* // => {success: true}
|
|
19
|
+
* }).catch(e => {
|
|
20
|
+
* // => an exception object
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
export async function invalidateApiKey(requestOptions) {
|
|
24
|
+
const portal = getPortalUrl(requestOptions);
|
|
25
|
+
const url = `${portal}/oauth2/revokeToken`;
|
|
26
|
+
const appInfo = await getRegisteredAppInfo({
|
|
27
|
+
itemId: requestOptions.itemId,
|
|
28
|
+
authentication: requestOptions.authentication
|
|
29
|
+
});
|
|
30
|
+
const params = {
|
|
31
|
+
client_id: appInfo.client_id,
|
|
32
|
+
client_secret: appInfo.client_secret,
|
|
33
|
+
apiToken: slotForInvalidationKey(requestOptions.apiKey),
|
|
34
|
+
regenerateApiToken: true,
|
|
35
|
+
grant_type: "client_credentials"
|
|
36
|
+
};
|
|
37
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
38
|
+
return request(url, {
|
|
39
|
+
params
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=invalidateApiKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invalidateApiKey.js","sourceRoot":"","sources":["../../src/invalidateApiKey.ts"],"names":[],"mappings":"AAAA;gBACgB;AAMhB,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,cAAwC;IAExC,MAAM,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC;IAC5C,MAAM,GAAG,GAAG,GAAG,MAAM,qBAAqB,CAAC;IAE3C,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;QACzC,MAAM,EAAE,cAAc,CAAC,MAAM;QAC7B,cAAc,EAAE,cAAc,CAAC,cAAc;KAC9C,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,MAAM,CAAC;QACvD,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,2FAA2F;IAC3F,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,MAAM;KACP,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* 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"]}
|
|
@@ -15,8 +15,8 @@ export async function generateApiKeyToken(options) {
|
|
|
15
15
|
regenerateApiToken: true,
|
|
16
16
|
grant_type: "client_credentials"
|
|
17
17
|
};
|
|
18
|
+
// authentication is not being passed to the request because client_secret acts as the auth
|
|
18
19
|
return request(url, {
|
|
19
|
-
authentication: options.authentication,
|
|
20
20
|
params
|
|
21
21
|
});
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGR,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AASxD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,
|
|
1
|
+
{"version":3,"file":"generateApiKeyToken.js","sourceRoot":"","sources":["../../../src/shared/generateApiKeyToken.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAGR,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AASxD,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAoC;IAEpC,MAAM,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,GAAG,GAAG,GAAG,MAAM,eAAe,CAAC;IAErC,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;QACzC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,cAAc,EAAE,OAAO,CAAC,cAAc;KACvC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,kBAAkB,EAAE,IAAI;QACxB,UAAU,EAAE,oBAAoB;KACjC,CAAC;IAEF,2FAA2F;IAC3F,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,MAAM;KACP,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n request,\n IRequestOptions,\n IAuthenticationManager\n} from \"@esri/arcgis-rest-request\";\nimport { getRegisteredAppInfo } from \"./getRegisteredAppInfo.js\";\nimport { getPortalUrl } from \"@esri/arcgis-rest-portal\";\n\nexport interface IGenerateApiKeyTokenOptions extends IRequestOptions {\n itemId: string;\n apiKey: 1 | 2;\n portal?: string;\n authentication: IAuthenticationManager;\n}\n\nexport async function generateApiKeyToken(\n options: IGenerateApiKeyTokenOptions\n): Promise<{ access_token: string; expires_in: number }> {\n const portal = getPortalUrl(options);\n const url = `${portal}/oauth2/token`;\n\n const appInfo = await getRegisteredAppInfo({\n itemId: options.itemId,\n authentication: options.authentication\n });\n\n const params = {\n client_id: appInfo.client_id,\n client_secret: appInfo.client_secret,\n apiToken: options.apiKey,\n regenerateApiToken: true,\n grant_type: \"client_credentials\"\n };\n\n // authentication is not being passed to the request because client_secret acts as the auth\n return request(url, {\n params\n });\n}\n"]}
|
|
@@ -33,9 +33,14 @@ export declare function extractBaseRequestOptions<T extends IRequestOptions>(opt
|
|
|
33
33
|
*/
|
|
34
34
|
export declare function filterKeys<T extends object>(object: T, includedKeys: Array<keyof T>): any;
|
|
35
35
|
/**
|
|
36
|
-
* Used to determine if a generated key is in slot 1 or slot 2 key.
|
|
36
|
+
* 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.
|
|
37
37
|
*/
|
|
38
|
-
export declare function slotForKey(key: string):
|
|
38
|
+
export declare function slotForKey(key: string): 1 | 2;
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
* Used to determine which slot to invalidate a key in given a number or a full or patial key.
|
|
42
|
+
*/
|
|
43
|
+
export declare function slotForInvalidationKey(param: string | 1 | 2): 2 | 1;
|
|
39
44
|
interface IGenerateApiKeyTokenOptions extends IRequestOptions {
|
|
40
45
|
authentication: IAuthenticationManager;
|
|
41
46
|
}
|
|
@@ -94,10 +94,30 @@ export function filterKeys(object, includedKeys) {
|
|
|
94
94
|
}, {});
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
* Used to determine if a generated key is in slot 1 or slot 2 key.
|
|
97
|
+
* 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.
|
|
98
98
|
*/
|
|
99
99
|
export function slotForKey(key) {
|
|
100
|
-
|
|
100
|
+
const slot = parseInt(key.substring(key.length - 10, key.length - 9));
|
|
101
|
+
if (slot === 1 || slot === 2) {
|
|
102
|
+
return slot;
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @internal
|
|
108
|
+
* Used to determine which slot to invalidate a key in given a number or a full or patial key.
|
|
109
|
+
*/
|
|
110
|
+
export function slotForInvalidationKey(param) {
|
|
111
|
+
if (param === 1 || param === 2) {
|
|
112
|
+
return param;
|
|
113
|
+
}
|
|
114
|
+
if (typeof param !== "string") {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
const fullKeySlot = slotForKey(param);
|
|
118
|
+
if (fullKeySlot) {
|
|
119
|
+
return fullKeySlot;
|
|
120
|
+
}
|
|
101
121
|
}
|
|
102
122
|
/**
|
|
103
123
|
* @internal
|