@shopify/cli-kit 3.34.0 → 3.36.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/content-tokens.js +1 -1
- package/dist/content-tokens.js.map +1 -1
- package/dist/error.js +2 -2
- package/dist/error.js.map +1 -1
- package/dist/git.js +2 -2
- package/dist/git.js.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/metadata.d.ts +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/monorail.d.ts +1 -1
- package/dist/monorail.js +1 -1
- package/dist/monorail.js.map +1 -1
- package/dist/output.js +3 -7
- package/dist/output.js.map +1 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/{typing → private/common/ts}/deep-required.d.ts +3 -3
- package/dist/{typing → private/common/ts}/deep-required.js +0 -0
- package/dist/private/common/ts/deep-required.js.map +1 -0
- package/dist/{typing → private/common/ts}/overloaded-parameters.d.ts +0 -0
- package/dist/{typing → private/common/ts}/overloaded-parameters.js +0 -0
- package/dist/private/common/ts/overloaded-parameters.js.map +1 -0
- package/dist/private/node/api/graphql.js +2 -3
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.d.ts +11 -2
- package/dist/private/node/api/headers.js +29 -3
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/api/rest.d.ts +5 -3
- package/dist/private/node/api/rest.js +8 -7
- package/dist/private/node/api/rest.js.map +1 -1
- package/dist/private/node/constants.d.ts +42 -0
- package/dist/private/node/constants.js +58 -0
- package/dist/private/node/constants.js.map +1 -0
- package/dist/private/node/environment/service.js +2 -2
- package/dist/private/node/environment/service.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +1 -1
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/exchange.js +1 -1
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/identity-token-validation.js +1 -1
- package/dist/private/node/session/identity-token-validation.js.map +1 -1
- package/dist/private/node/session/post-auth.js +10 -10
- package/dist/private/node/session/post-auth.js.map +1 -1
- package/dist/private/node/session/store.js +6 -6
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session/validate.js +2 -2
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.js +2 -2
- package/dist/private/node/session.js.map +1 -1
- package/dist/{typing → private/node}/simple-definitions.d.ts +0 -0
- package/dist/{typing → private/node}/simple-definitions.js +0 -0
- package/dist/private/node/simple-definitions.js.map +1 -0
- package/dist/private/node/ui/alert.d.ts +1 -1
- package/dist/private/node/ui/alert.js +2 -2
- package/dist/private/node/ui/alert.js.map +1 -1
- package/dist/private/node/ui/components/Alert.d.ts +5 -0
- package/dist/private/node/ui/components/Alert.js +9 -6
- package/dist/private/node/ui/components/Alert.js.map +1 -1
- package/dist/private/node/ui/components/Alert.test.js +30 -4
- package/dist/private/node/ui/components/Alert.test.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.d.ts +12 -0
- package/dist/private/node/ui/components/AutocompletePrompt.js +111 -0
- package/dist/private/node/ui/components/AutocompletePrompt.js.map +1 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.d.ts +1 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +473 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -0
- package/dist/private/node/ui/components/Banner.d.ts +0 -1
- package/dist/private/node/ui/components/Banner.js +4 -4
- package/dist/private/node/ui/components/Banner.js.map +1 -1
- package/dist/private/node/ui/components/Banner.test.js +10 -5
- package/dist/private/node/ui/components/Banner.test.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.js +1 -1
- package/dist/private/node/ui/components/FatalError.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.test.js +4 -8
- package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
- package/dist/private/node/ui/components/{Table.d.ts → Prompts/InfoTable.d.ts} +2 -2
- package/dist/private/node/ui/components/{Table.js → Prompts/InfoTable.js} +6 -6
- package/dist/private/node/ui/components/Prompts/InfoTable.js.map +1 -0
- package/dist/private/node/ui/components/SelectInput.d.ts +9 -2
- package/dist/private/node/ui/components/SelectInput.js +96 -52
- package/dist/private/node/ui/components/SelectInput.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.test.js +140 -54
- package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.d.ts +6 -4
- package/dist/private/node/ui/components/SelectPrompt.js +18 -11
- package/dist/private/node/ui/components/SelectPrompt.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +113 -23
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Table/Column.d.ts +5 -0
- package/dist/private/node/ui/components/Table/Column.js +2 -0
- package/dist/private/node/ui/components/Table/Column.js.map +1 -0
- package/dist/private/node/ui/components/Table/Row.d.ts +12 -0
- package/dist/private/node/ui/components/Table/Row.js +24 -0
- package/dist/private/node/ui/components/Table/Row.js.map +1 -0
- package/dist/private/node/ui/components/Table/ScalarDict.d.ts +5 -0
- package/dist/private/node/ui/components/Table/ScalarDict.js +2 -0
- package/dist/private/node/ui/components/Table/ScalarDict.js.map +1 -0
- package/dist/private/node/ui/components/Table/Table.d.ts +12 -0
- package/dist/private/node/ui/components/Table/Table.js +30 -0
- package/dist/private/node/ui/components/Table/Table.js.map +1 -0
- package/dist/private/node/ui/components/Table/Table.test.d.ts +1 -0
- package/dist/private/node/ui/components/Table/Table.test.js +41 -0
- package/dist/private/node/ui/components/Table/Table.test.js.map +1 -0
- package/dist/private/node/ui/components/Tasks.d.ts +6 -5
- package/dist/private/node/ui/components/Tasks.js +32 -11
- package/dist/private/node/ui/components/Tasks.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +55 -9
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.d.ts +4 -1
- package/dist/private/node/ui/components/TextInput.js +22 -13
- package/dist/private/node/ui/components/TextInput.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.test.js +47 -40
- package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.d.ts +3 -1
- package/dist/private/node/ui/components/TextPrompt.js +28 -15
- package/dist/private/node/ui/components/TextPrompt.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.test.js +71 -15
- package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.d.ts +3 -0
- package/dist/private/node/ui/components/TokenizedText.js +33 -1
- package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
- package/dist/private/node/ui/utilities.d.ts +2 -0
- package/dist/private/node/ui/utilities.js +6 -0
- package/dist/private/node/ui/utilities.js.map +1 -0
- package/dist/public/common/string.d.ts +11 -0
- package/dist/public/common/string.js +21 -0
- package/dist/public/common/string.js.map +1 -1
- package/dist/{typing → public/common/ts}/pick-by-prefix.d.ts +4 -3
- package/dist/{typing → public/common/ts}/pick-by-prefix.js +0 -0
- package/dist/public/common/ts/pick-by-prefix.js.map +1 -0
- package/dist/public/common/version.d.ts +1 -0
- package/dist/public/common/version.js +2 -0
- package/dist/public/common/version.js.map +1 -0
- package/dist/public/node/analytics.js +2 -2
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.d.ts +4 -1
- package/dist/public/node/api/admin.js +5 -4
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/http.d.ts +0 -0
- package/dist/public/node/api/http.js +2 -0
- package/dist/public/node/api/http.js.map +1 -0
- package/dist/public/node/api/oxygen.js +1 -1
- package/dist/public/node/api/oxygen.js.map +1 -1
- package/dist/public/node/archiver.js +2 -1
- package/dist/public/node/archiver.js.map +1 -1
- package/dist/public/node/cli.js +6 -6
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/dot-env.js +2 -2
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/environment/local.js +17 -17
- package/dist/public/node/environment/local.js.map +1 -1
- package/dist/public/node/environment/spin.js +6 -6
- package/dist/public/node/environment/spin.js.map +1 -1
- package/dist/public/node/error-handler.js +13 -10
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/framework.js +2 -2
- package/dist/public/node/framework.js.map +1 -1
- package/dist/public/node/fs.d.ts +241 -4
- package/dist/public/node/fs.js +366 -2
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.d.ts +90 -0
- package/dist/public/node/git.js +174 -0
- package/dist/public/node/git.js.map +1 -0
- package/dist/public/node/github.js +1 -1
- package/dist/public/node/github.js.map +1 -1
- package/dist/{http/fetch.d.ts → public/node/http.d.ts} +18 -7
- package/dist/{http/fetch.js → public/node/http.js} +21 -8
- package/dist/public/node/http.js.map +1 -0
- package/dist/public/node/liquid.js +9 -9
- package/dist/public/node/liquid.js.map +1 -1
- package/dist/public/node/node-package-manager.d.ts +20 -9
- package/dist/public/node/node-package-manager.js +19 -25
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/path.d.ts +22 -0
- package/dist/{path.js → public/node/path.js} +8 -20
- package/dist/public/node/path.js.map +1 -0
- package/dist/public/node/presets.js +5 -5
- package/dist/public/node/presets.js.map +1 -1
- package/dist/public/node/ruby.js +29 -33
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/session.js +2 -2
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/ui.d.ts +63 -9
- package/dist/public/node/ui.js +83 -8
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vscode.js +8 -8
- package/dist/public/node/vscode.js.map +1 -1
- package/dist/secure-store.js +4 -4
- package/dist/secure-store.js.map +1 -1
- package/dist/store.d.ts +10 -10
- package/dist/store.js +21 -22
- package/dist/store.js.map +1 -1
- package/dist/testing/store.js +3 -3
- package/dist/testing/store.js.map +1 -1
- package/dist/testing/ui.d.ts +4 -1
- package/dist/testing/ui.js +24 -1
- package/dist/testing/ui.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui/executor.d.ts +2 -14
- package/dist/ui/executor.js +38 -72
- package/dist/ui/executor.js.map +1 -1
- package/dist/ui.js +9 -26
- package/dist/ui.js.map +1 -1
- package/package.json +4 -6
- package/dist/constants.d.ts +0 -48
- package/dist/constants.js +0 -67
- package/dist/constants.js.map +0 -1
- package/dist/file.d.ts +0 -98
- package/dist/file.js +0 -216
- package/dist/file.js.map +0 -1
- package/dist/http/fetch.js.map +0 -1
- package/dist/http/formdata.d.ts +0 -3
- package/dist/http/formdata.js +0 -6
- package/dist/http/formdata.js.map +0 -1
- package/dist/http.d.ts +0 -26
- package/dist/http.js +0 -31
- package/dist/http.js.map +0 -1
- package/dist/npm.d.ts +0 -27
- package/dist/npm.js +0 -20
- package/dist/npm.js.map +0 -1
- package/dist/path.d.ts +0 -25
- package/dist/path.js.map +0 -1
- package/dist/private/node/ui/components/Table.js.map +0 -1
- package/dist/typing/deep-required.js.map +0 -1
- package/dist/typing/overloaded-parameters.js.map +0 -1
- package/dist/typing/pick-by-prefix.js.map +0 -1
- package/dist/typing/simple-definitions.js.map +0 -1
- package/dist/ui/inquirer/autocomplete.d.ts +0 -11
- package/dist/ui/inquirer/autocomplete.js +0 -110
- package/dist/ui/inquirer/autocomplete.js.map +0 -1
- package/dist/ui/inquirer/input.d.ts +0 -16
- package/dist/ui/inquirer/input.js +0 -45
- package/dist/ui/inquirer/input.js.map +0 -1
- package/dist/ui/inquirer/password.d.ts +0 -7
- package/dist/ui/inquirer/password.js +0 -8
- package/dist/ui/inquirer/password.js.map +0 -1
- package/dist/ui/inquirer/select.d.ts +0 -14
- package/dist/ui/inquirer/select.js +0 -26
- package/dist/ui/inquirer/select.js.map +0 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CLI_KIT_VERSION } from '../../../public/common/version.js';
|
|
2
2
|
import { firstPartyDev } from '../../../public/node/environment/local.js';
|
|
3
3
|
import { ExtendableError } from '../../../error.js';
|
|
4
4
|
import { randomUUID } from '../../../public/node/crypto.js';
|
|
5
|
+
import { Environment, serviceEnvironment } from '../environment/service.js';
|
|
6
|
+
import https from 'https';
|
|
5
7
|
export class RequestClientError extends ExtendableError {
|
|
6
8
|
constructor(message, statusCode) {
|
|
7
9
|
super(message);
|
|
@@ -27,8 +29,8 @@ export function sanitizedHeadersOutput(headers) {
|
|
|
27
29
|
})
|
|
28
30
|
.join('\n');
|
|
29
31
|
}
|
|
30
|
-
export
|
|
31
|
-
const userAgent = `Shopify CLI; v=${
|
|
32
|
+
export function buildHeaders(token) {
|
|
33
|
+
const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`;
|
|
32
34
|
const headers = {
|
|
33
35
|
'User-Agent': userAgent,
|
|
34
36
|
// 'Sec-CH-UA': secCHUA, This header requires the Git sha.
|
|
@@ -44,4 +46,28 @@ export async function buildHeaders(token) {
|
|
|
44
46
|
}
|
|
45
47
|
return headers;
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* This utility function returns the https.Agent to use for a given service. The agent
|
|
51
|
+
* includes the right configuration based on the service's environment. For example,
|
|
52
|
+
* if the service is running in a Spin environment, the attribute "rejectUnauthorized" is
|
|
53
|
+
* set to false
|
|
54
|
+
*/
|
|
55
|
+
export async function httpsAgent() {
|
|
56
|
+
return new https.Agent({ rejectUnauthorized: await shouldRejectUnauthorizedRequests() });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Spin stores the CA certificate in the keychain and it should be used when sending HTTP
|
|
60
|
+
* requests to Spin instances. However, Node doesn't read certificates from the Keychain
|
|
61
|
+
* by default, which leads to Shopifolks running into issues that they workaround by setting the
|
|
62
|
+
* NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP
|
|
63
|
+
* requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)
|
|
64
|
+
* This utility function allows controlling the behavior in a per-service level by returning
|
|
65
|
+
* the value of for the "rejectUnauthorized" attribute that's used in the https agent.
|
|
66
|
+
*
|
|
67
|
+
* @returns A promise that resolves with a boolean indicating whether
|
|
68
|
+
* unauthorized requests should be rejected or not.
|
|
69
|
+
*/
|
|
70
|
+
async function shouldRejectUnauthorizedRequests() {
|
|
71
|
+
return (await serviceEnvironment()) !== Environment.Spin;
|
|
72
|
+
}
|
|
47
73
|
//# sourceMappingURL=headers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../../src/private/node/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../../../../src/private/node/api/headers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,mCAAmC,CAAA;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,2CAA2C,CAAA;AACvE,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAC,UAAU,EAAC,MAAM,gCAAgC,CAAA;AACzD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,2BAA2B,CAAA;AACzE,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,OAAO,kBAAmB,SAAQ,eAAe;IAErD,YAAmB,OAAe,EAAE,UAAkB;QACpD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,MAAM,SAAS,GAA4B,EAAE,CAAA;IAC7C,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IAC3C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;QACtC,IAAI,QAAQ,CAAC,IAAI,CA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,WAAW,CAAC,IAAI,CAAA;AAC1D,CAAC","sourcesContent":["import {CLI_KIT_VERSION} from '../../../public/common/version.js'\nimport {firstPartyDev} from '../../../public/node/environment/local.js'\nimport {ExtendableError} from '../../../error.js'\nimport {randomUUID} from '../../../public/node/crypto.js'\nimport {Environment, serviceEnvironment} from '../environment/service.js'\nimport https from 'https'\n\nexport class RequestClientError extends ExtendableError {\n statusCode: number\n public constructor(message: string, statusCode: number) {\n super(message)\n this.statusCode = statusCode\n }\n}\n\n/**\n * Removes the sensitive data from the headers and outputs them as a string.\n * @param headers - HTTP headers.\n * @returns A sanitized version of the headers as a string.\n */\nexport function sanitizedHeadersOutput(headers: {[key: string]: string}): string {\n const sanitized: {[key: string]: string} = {}\n const keywords = ['token', 'authorization']\n Object.keys(headers).forEach((header) => {\n if (keywords.find((keyword) => header.toLocaleLowerCase().includes(keyword)) === undefined) {\n sanitized[header] = headers[header]!\n }\n })\n return Object.keys(sanitized)\n .map((header) => {\n return ` - ${header}: ${sanitized[header]}`\n })\n .join('\\n')\n}\n\nexport function buildHeaders(token?: string): {[key: string]: string} {\n const userAgent = `Shopify CLI; v=${CLI_KIT_VERSION}`\n\n const headers: {[header: string]: string} = {\n 'User-Agent': userAgent,\n // 'Sec-CH-UA': secCHUA, This header requires the Git sha.\n 'Sec-CH-UA-PLATFORM': process.platform,\n 'X-Request-Id': randomUUID(),\n 'Content-Type': 'application/json',\n ...(firstPartyDev() && {'X-Shopify-Cli-Employee': '1'}),\n }\n if (token) {\n // eslint-disable-next-line dot-notation\n headers['authorization'] = `Bearer ${token}`\n headers['X-Shopify-Access-Token'] = `Bearer ${token}`\n }\n\n return headers\n}\n\n/**\n * This utility function returns the https.Agent to use for a given service. The agent\n * includes the right configuration based on the service's environment. For example,\n * if the service is running in a Spin environment, the attribute \"rejectUnauthorized\" is\n * set to false\n */\nexport async function httpsAgent() {\n return new https.Agent({rejectUnauthorized: await shouldRejectUnauthorizedRequests()})\n}\n\n/**\n * Spin stores the CA certificate in the keychain and it should be used when sending HTTP\n * requests to Spin instances. However, Node doesn't read certificates from the Keychain\n * by default, which leads to Shopifolks running into issues that they workaround by setting the\n * NODE_TLS_REJECT_UNAUTHORIZED=0 environment variable, which applies to all the HTTP\n * requests sent from the CLI (context: https://github.com/nodejs/node/issues/39657)\n * This utility function allows controlling the behavior in a per-service level by returning\n * the value of for the \"rejectUnauthorized\" attribute that's used in the https agent.\n *\n * @returns A promise that resolves with a boolean indicating whether\n * unauthorized requests should be rejected or not.\n */\nasync function shouldRejectUnauthorizedRequests(): Promise<boolean> {\n return (await serviceEnvironment()) !== Environment.Spin\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AdminSession } from '@shopify/cli-kit/node/session';
|
|
2
2
|
export declare function restRequestBody<T>(requestBody?: T): string | undefined;
|
|
3
|
-
export declare function restRequestUrl(session: AdminSession, apiVersion: string, path: string
|
|
4
|
-
|
|
3
|
+
export declare function restRequestUrl(session: AdminSession, apiVersion: string, path: string, searchParams?: {
|
|
4
|
+
[name: string]: string;
|
|
5
|
+
}): string;
|
|
6
|
+
export declare function restRequestHeaders(session: AdminSession): {
|
|
5
7
|
[key: string]: string;
|
|
6
|
-
}
|
|
8
|
+
};
|
|
@@ -5,16 +5,17 @@ export function restRequestBody(requestBody) {
|
|
|
5
5
|
}
|
|
6
6
|
return JSON.stringify(requestBody);
|
|
7
7
|
}
|
|
8
|
-
export function restRequestUrl(session, apiVersion, path) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export function restRequestUrl(session, apiVersion, path, searchParams = {}) {
|
|
9
|
+
const url = new URL(isThemeAccessSession(session)
|
|
10
|
+
? `https://theme-kit-access.shopifyapps.com/cli/admin/api/${apiVersion}${path}.json`
|
|
11
|
+
: `https://${session.storeFqdn}/admin/api/${apiVersion}${path}.json`);
|
|
12
|
+
Object.entries(searchParams).forEach(([name, value]) => url.searchParams.set(name, value));
|
|
13
|
+
return url.toString();
|
|
13
14
|
}
|
|
14
|
-
export
|
|
15
|
+
export function restRequestHeaders(session) {
|
|
15
16
|
const store = session.storeFqdn;
|
|
16
17
|
const token = session.token;
|
|
17
|
-
const headers =
|
|
18
|
+
const headers = buildHeaders(session.token);
|
|
18
19
|
if (isThemeAccessSession(session)) {
|
|
19
20
|
headers['X-Shopify-Shop'] = store;
|
|
20
21
|
headers['X-Shopify-Access-Token'] = token;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/private/node/api/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAA;AAGzC,MAAM,UAAU,eAAe,CAAI,WAAe;IAChD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAM;KACP;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../../../src/private/node/api/rest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,cAAc,CAAA;AAGzC,MAAM,UAAU,eAAe,CAAI,WAAe;IAChD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAM;KACP;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAqB,EACrB,UAAkB,EAClB,IAAY,EACZ,eAAyC,EAAE;IAE3C,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,oBAAoB,CAAC,OAAO,CAAC;QAC3B,CAAC,CAAC,0DAA0D,UAAU,GAAG,IAAI,OAAO;QACpF,CAAC,CAAC,WAAW,OAAO,CAAC,SAAS,cAAc,UAAU,GAAG,IAAI,OAAO,CACvE,CAAA;IACD,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;IAE1F,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAA;AACvB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAqB;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;IAC3B,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE3C,IAAI,oBAAoB,CAAC,OAAO,CAAC,EAAE;QACjC,OAAO,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAA;QACjC,OAAO,CAAC,wBAAwB,CAAC,GAAG,KAAK,CAAA;KAC1C;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAAqB;IACjD,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;AAC5C,CAAC","sourcesContent":["import {buildHeaders} from './headers.js'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function restRequestBody<T>(requestBody?: T) {\n if (!requestBody) {\n return\n }\n return JSON.stringify(requestBody)\n}\n\nexport function restRequestUrl(\n session: AdminSession,\n apiVersion: string,\n path: string,\n searchParams: {[name: string]: string} = {},\n) {\n const url = new URL(\n isThemeAccessSession(session)\n ? `https://theme-kit-access.shopifyapps.com/cli/admin/api/${apiVersion}${path}.json`\n : `https://${session.storeFqdn}/admin/api/${apiVersion}${path}.json`,\n )\n Object.entries(searchParams).forEach(([name, value]) => url.searchParams.set(name, value))\n\n return url.toString()\n}\n\nexport function restRequestHeaders(session: AdminSession) {\n const store = session.storeFqdn\n const token = session.token\n const headers = buildHeaders(session.token)\n\n if (isThemeAccessSession(session)) {\n headers['X-Shopify-Shop'] = store\n headers['X-Shopify-Access-Token'] = token\n }\n\n return headers\n}\n\nfunction isThemeAccessSession(session: AdminSession) {\n return session.token.startsWith('shptka_')\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const environmentVariables: {
|
|
2
|
+
alwaysLogAnalytics: string;
|
|
3
|
+
deviceAuth: string;
|
|
4
|
+
enableCliRedirect: string;
|
|
5
|
+
env: string;
|
|
6
|
+
firstPartyDev: string;
|
|
7
|
+
noAnalytics: string;
|
|
8
|
+
partnersToken: string;
|
|
9
|
+
runAsUser: string;
|
|
10
|
+
serviceEnv: string;
|
|
11
|
+
skipCliRedirect: string;
|
|
12
|
+
spinInstance: string;
|
|
13
|
+
themeToken: string;
|
|
14
|
+
unitTest: string;
|
|
15
|
+
verbose: string;
|
|
16
|
+
themeBundling: string;
|
|
17
|
+
codespaceName: string;
|
|
18
|
+
codespaces: string;
|
|
19
|
+
gitpod: string;
|
|
20
|
+
spin: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const pathConstants: {
|
|
23
|
+
executables: {
|
|
24
|
+
dev: string;
|
|
25
|
+
};
|
|
26
|
+
directories: {
|
|
27
|
+
cache: {
|
|
28
|
+
path: () => string;
|
|
29
|
+
vendor: {
|
|
30
|
+
path: () => any;
|
|
31
|
+
binaries: () => any;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export declare const keychainConstants: {
|
|
37
|
+
service: string;
|
|
38
|
+
};
|
|
39
|
+
export declare const sessionConstants: {
|
|
40
|
+
expirationTimeMarginInMinutes: number;
|
|
41
|
+
};
|
|
42
|
+
export declare const bugsnagApiKey = "9e1e6889176fd0c795d5c659225e0fae";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { joinPath } from '../../public/node/path.js';
|
|
2
|
+
import envPaths from 'env-paths';
|
|
3
|
+
const identifier = 'shopify-cli';
|
|
4
|
+
const cacheFolder = () => {
|
|
5
|
+
if (process.env.XDG_CACHE_HOME)
|
|
6
|
+
return process.env.XDG_CACHE_HOME;
|
|
7
|
+
return envPaths(identifier).cache;
|
|
8
|
+
};
|
|
9
|
+
export const environmentVariables = {
|
|
10
|
+
alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',
|
|
11
|
+
deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',
|
|
12
|
+
enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',
|
|
13
|
+
env: 'SHOPIFY_CLI_ENV',
|
|
14
|
+
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
|
|
15
|
+
noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',
|
|
16
|
+
partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',
|
|
17
|
+
runAsUser: 'SHOPIFY_RUN_AS_USER',
|
|
18
|
+
serviceEnv: 'SHOPIFY_SERVICE_ENV',
|
|
19
|
+
skipCliRedirect: 'SHOPIFY_CLI_SKIP_CLI_REDIRECT',
|
|
20
|
+
spinInstance: 'SPIN_INSTANCE',
|
|
21
|
+
themeToken: 'SHOPIFY_CLI_THEME_TOKEN',
|
|
22
|
+
unitTest: 'SHOPIFY_UNIT_TEST',
|
|
23
|
+
verbose: 'SHOPIFY_FLAG_VERBOSE',
|
|
24
|
+
themeBundling: 'SHOPIFY_THEME_BUNDLING',
|
|
25
|
+
// Variables to detect if the CLI is running in a cloud environment
|
|
26
|
+
codespaceName: 'CODESPACE_NAME',
|
|
27
|
+
codespaces: 'CODESPACES',
|
|
28
|
+
gitpod: 'GITPOD_WORKSPACE_URL',
|
|
29
|
+
spin: 'SPIN',
|
|
30
|
+
};
|
|
31
|
+
export const pathConstants = {
|
|
32
|
+
executables: {
|
|
33
|
+
dev: '/opt/dev/bin/dev',
|
|
34
|
+
},
|
|
35
|
+
directories: {
|
|
36
|
+
cache: {
|
|
37
|
+
path: () => {
|
|
38
|
+
return cacheFolder();
|
|
39
|
+
},
|
|
40
|
+
vendor: {
|
|
41
|
+
path: () => {
|
|
42
|
+
return joinPath(cacheFolder(), 'vendor');
|
|
43
|
+
},
|
|
44
|
+
binaries: () => {
|
|
45
|
+
return joinPath(cacheFolder(), 'vendor', 'binaries');
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
export const keychainConstants = {
|
|
52
|
+
service: 'shopify-cli',
|
|
53
|
+
};
|
|
54
|
+
export const sessionConstants = {
|
|
55
|
+
expirationTimeMarginInMinutes: 4,
|
|
56
|
+
};
|
|
57
|
+
export const bugsnagApiKey = '9e1e6889176fd0c795d5c659225e0fae';
|
|
58
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/private/node/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,2BAA2B,CAAA;AAClD,OAAO,QAAQ,MAAM,WAAW,CAAA;AAEhC,MAAM,UAAU,GAAG,aAAa,CAAA;AAEhC,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc;QAAE,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,CAAA;IACjE,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,KAAK,CAAA;AACnC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kBAAkB,EAAE,kCAAkC;IACtD,UAAU,EAAE,yBAAyB;IACrC,iBAAiB,EAAE,iCAAiC;IACpD,GAAG,EAAE,iBAAiB;IACtB,aAAa,EAAE,oBAAoB;IACnC,WAAW,EAAE,0BAA0B;IACvC,aAAa,EAAE,4BAA4B;IAC3C,SAAS,EAAE,qBAAqB;IAChC,UAAU,EAAE,qBAAqB;IACjC,eAAe,EAAE,+BAA+B;IAChD,YAAY,EAAE,eAAe;IAC7B,UAAU,EAAE,yBAAyB;IACrC,QAAQ,EAAE,mBAAmB;IAC7B,OAAO,EAAE,sBAAsB;IAC/B,aAAa,EAAE,wBAAwB;IACvC,mEAAmE;IACnE,aAAa,EAAE,gBAAgB;IAC/B,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,sBAAsB;IAC9B,IAAI,EAAE,MAAM;CACb,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,WAAW,EAAE;QACX,GAAG,EAAE,kBAAkB;KACxB;IACD,WAAW,EAAE;QACX,KAAK,EAAE;YACL,IAAI,EAAE,GAAG,EAAE;gBACT,OAAO,WAAW,EAAE,CAAA;YACtB,CAAC;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,GAAG,EAAE;oBACT,OAAO,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,CAAC,CAAA;gBAC1C,CAAC;gBACD,QAAQ,EAAE,GAAG,EAAE;oBACb,OAAO,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;gBACtD,CAAC;aACF;SACF;KACF;CACF,CAAA;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,aAAa;CACvB,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,6BAA6B,EAAE,CAAC;CACjC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,kCAAkC,CAAA","sourcesContent":["import {joinPath} from '../../public/node/path.js'\nimport envPaths from 'env-paths'\n\nconst identifier = 'shopify-cli'\n\nconst cacheFolder = () => {\n if (process.env.XDG_CACHE_HOME) return process.env.XDG_CACHE_HOME\n return envPaths(identifier).cache\n}\n\nexport const environmentVariables = {\n alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',\n deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',\n enableCliRedirect: 'SHOPIFY_CLI_ENABLE_CLI_REDIRECT',\n env: 'SHOPIFY_CLI_ENV',\n firstPartyDev: 'SHOPIFY_CLI_1P_DEV',\n noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',\n partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',\n runAsUser: 'SHOPIFY_RUN_AS_USER',\n serviceEnv: 'SHOPIFY_SERVICE_ENV',\n skipCliRedirect: 'SHOPIFY_CLI_SKIP_CLI_REDIRECT',\n spinInstance: 'SPIN_INSTANCE',\n themeToken: 'SHOPIFY_CLI_THEME_TOKEN',\n unitTest: 'SHOPIFY_UNIT_TEST',\n verbose: 'SHOPIFY_FLAG_VERBOSE',\n themeBundling: 'SHOPIFY_THEME_BUNDLING',\n // Variables to detect if the CLI is running in a cloud environment\n codespaceName: 'CODESPACE_NAME',\n codespaces: 'CODESPACES',\n gitpod: 'GITPOD_WORKSPACE_URL',\n spin: 'SPIN',\n}\n\nexport const pathConstants = {\n executables: {\n dev: '/opt/dev/bin/dev',\n },\n directories: {\n cache: {\n path: () => {\n return cacheFolder()\n },\n vendor: {\n path: () => {\n return joinPath(cacheFolder(), 'vendor')\n },\n binaries: () => {\n return joinPath(cacheFolder(), 'vendor', 'binaries')\n },\n },\n },\n },\n}\n\nexport const keychainConstants = {\n service: 'shopify-cli',\n}\n\nexport const sessionConstants = {\n expirationTimeMarginInMinutes: 4,\n}\n\nexport const bugsnagApiKey = '9e1e6889176fd0c795d5c659225e0fae'\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isSpin } from '../../../public/node/environment/spin.js';
|
|
2
|
-
import
|
|
2
|
+
import { environmentVariables } from '../constants.js';
|
|
3
3
|
/**
|
|
4
4
|
* Enum that represents the environment to use for a given service.
|
|
5
5
|
*
|
|
@@ -18,7 +18,7 @@ export var Environment;
|
|
|
18
18
|
* @returns The environment to use for a given service.
|
|
19
19
|
*/
|
|
20
20
|
export function serviceEnvironment(env = process.env) {
|
|
21
|
-
const value = env[
|
|
21
|
+
const value = env[environmentVariables.serviceEnv];
|
|
22
22
|
if (value === 'local') {
|
|
23
23
|
return Environment.Local;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/private/node/environment/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,0CAA0C,CAAA;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/private/node/environment/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,0CAA0C,CAAA;AAC/D,OAAO,EAAC,oBAAoB,EAAC,MAAM,iBAAiB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,wCAAyB,CAAA;IACzB,4BAAa,CAAA;AACf,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAClD,MAAM,KAAK,GAAG,GAAG,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAA;IAClD,IAAI,KAAK,KAAK,OAAO,EAAE;QACrB,OAAO,WAAW,CAAC,KAAK,CAAA;KACzB;SAAM,IAAI,KAAK,KAAK,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC,IAAI,CAAA;KACxB;SAAM;QACL,OAAO,WAAW,CAAC,UAAU,CAAA;KAC9B;AACH,CAAC","sourcesContent":["import {isSpin} from '../../../public/node/environment/spin.js'\nimport {environmentVariables} from '../constants.js'\n\n/**\n * Enum that represents the environment to use for a given service.\n *\n * @readonly\n */\nexport enum Environment {\n Local = 'local',\n Production = 'production',\n Spin = 'spin',\n}\n\n/**\n * Returns the environment to use for a given service.\n *\n * @param env - Environment variables.\n * @returns The environment to use for a given service.\n */\nexport function serviceEnvironment(env = process.env): Environment {\n const value = env[environmentVariables.serviceEnv]\n if (value === 'local') {\n return Environment.Local\n } else if (value === 'spin' || isSpin(env)) {\n return Environment.Spin\n } else {\n return Environment.Production\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clientId } from './identity.js';
|
|
2
2
|
import { exchangeDeviceCodeForAccessToken } from './exchange.js';
|
|
3
3
|
import { identityFqdn } from '../../../public/node/environment/fqdn.js';
|
|
4
|
-
import { shopifyFetch } from '../../../http.js';
|
|
4
|
+
import { shopifyFetch } from '../../../public/node/http.js';
|
|
5
5
|
import { content, debug, info, token } from '../../../output.js';
|
|
6
6
|
import { Bug } from '../../../error.js';
|
|
7
7
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device-authorization.js","sourceRoot":"","sources":["../../../../src/private/node/session/device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,gCAAgC,EAAC,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"device-authorization.js","sourceRoot":"","sources":["../../../../src/private/node/session/device-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,OAAO,EAAC,gCAAgC,EAAC,MAAM,eAAe,CAAA;AAE9D,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AAWrC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,MAAgB;IAC/D,MAAM,IAAI,GAAG,MAAM,YAAY,EAAE,CAAA;IACjC,MAAM,gBAA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AC,OAAO,CAAC,QAAQ,CAAC,CAAC;SACvC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC","sourcesContent":["import {clientId} from './identity.js'\nimport {exchangeDeviceCodeForAccessToken} from './exchange.js'\nimport {IdentityToken} from './schema.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {content, debug, info, token} from '../../../output.js'\nimport {Bug} from '../../../error.js'\n\nexport interface DeviceAuthorizationResponse {\n deviceCode: string\n userCode: string\n verificationUri: string\n expiresIn: number\n verificationUriComplete?: string\n interval?: number\n}\n\n/**\n * Initiate a device authorization flow.\n * This will return a DeviceAuthorizationResponse containing the URL where user\n * should go to authorize the device without the need of a callback to the CLI.\n *\n * Also returns a `deviceCode` used for polling the token endpoint in the next step.\n *\n * @param scopes - The scopes to request\n * @returns An object with the device authorization response.\n */\nexport async function requestDeviceAuthorization(scopes: string[]): Promise<DeviceAuthorizationResponse> {\n const fqdn = await identityFqdn()\n const identityClientId = await clientId()\n const queryParams = {client_id: identityClientId, scope: scopes.join(' ')}\n const url = `https://${fqdn}/oauth/device_authorization`\n\n const response = await shopifyFetch(url, {\n method: 'POST',\n headers: {'Content-type': 'application/x-www-form-urlencoded'},\n body: convertRequestToParams(queryParams),\n })\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const jsonResult: any = await response.json()\n\n debug(content`Received device authorization code: ${token.json(jsonResult)}`)\n if (!jsonResult.device_code || !jsonResult.verification_uri_complete) {\n throw new Bug('Failed to start authorization process')\n }\n\n info('\\nTo run this command, log in to Shopify Partners.')\n info(content`User verification code: ${jsonResult.user_code}`)\n info(content`👉 Open this link to start the auth process: ${token.green(jsonResult.verification_uri_complete)}`)\n\n return {\n deviceCode: jsonResult.device_code,\n userCode: jsonResult.user_code,\n verificationUri: jsonResult.verification_uri,\n expiresIn: jsonResult.expires_in,\n verificationUriComplete: jsonResult.verification_uri_complete,\n interval: jsonResult.interval,\n }\n}\n\n/**\n * Poll the Oauth token endpoint with the device code obtained from a DeviceAuthorizationResponse.\n * The endpoint will return `authorization_pending` until the user completes the auth flow in the browser.\n * Once the user completes the auth flow, the endpoint will return the identity token.\n *\n * Timeout for the polling is defined by the server and is around 600 seconds.\n *\n * @param code - The device code obtained after starting a device identity flow\n * @param interval - The interval to poll the token endpoint\n * @returns The identity token\n */\nexport async function pollForDeviceAuthorization(code: string, interval = 5): Promise<IdentityToken> {\n let currentIntervalInSeconds = interval\n\n return new Promise<IdentityToken>((resolve, reject) => {\n const onPoll = async () => {\n const result = await exchangeDeviceCodeForAccessToken(code)\n if (!result.isErr()) return resolve(result.value)\n\n const error = result.error ?? 'unknown_failure'\n\n debug(content`Polling for device authorization... status: ${error}`)\n switch (error) {\n case 'authorization_pending':\n return startPolling()\n case 'slow_down':\n currentIntervalInSeconds += 5\n return startPolling()\n case 'access_denied':\n case 'expired_token':\n case 'unknown_failure':\n return reject(result)\n }\n }\n\n const startPolling = () => {\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n setTimeout(onPoll, currentIntervalInSeconds * 1000)\n }\n\n startPolling()\n })\n}\n\nfunction convertRequestToParams(queryParams: {client_id: string; scope: string}): string {\n return Object.entries(queryParams)\n .map(([key, value]) => value && `${key}=${value}`)\n .filter((hasValue) => Boolean(hasValue))\n .join('&')\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { applicationId, clientId as getIdentityClientId } from './identity.js';
|
|
2
2
|
import { identityFqdn } from '../../../public/node/environment/fqdn.js';
|
|
3
|
-
import { shopifyFetch } from '../../../http.js';
|
|
3
|
+
import { shopifyFetch } from '../../../public/node/http.js';
|
|
4
4
|
import { err, ok } from '../../../public/node/result.js';
|
|
5
5
|
import { AbortError } from '../../../public/node/error.js';
|
|
6
6
|
import { ExtendableError } from '../../../error.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../../../src/private/node/session/exchange.ts"],"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AI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,MAA0B;IACvD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {ApplicationToken, IdentityToken} from './schema.js'\nimport {applicationId, clientId as getIdentityClientId} from './identity.js'\nimport {CodeAuthResult} from './authorize.js'\nimport {API} from '../../../network/api.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../http.js'\nimport {err, ok, Result} from '../../../public/node/result.js'\nimport {AbortError} from '../../../public/node/error.js'\nimport {ExtendableError} from '../../../error.js'\n\nexport class InvalidGrantError extends ExtendableError {}\nexport class InvalidRequestError extends ExtendableError {}\n\nexport interface ExchangeScopes {\n admin: string[]\n partners: string[]\n storefront: string[]\n}\n/**\n * Given a valid authorization code, request an identity access token.\n * This token can then be used to get API specific tokens.\n * @param codeData - code and codeVerifier from the authorize endpoint\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeCodeForAccessToken(codeData: CodeAuthResult): Promise<IdentityToken> {\n const clientId = await getIdentityClientId()\n const params = {\n grant_type: 'authorization_code',\n code: codeData.code,\n redirect_uri: 'http://127.0.0.1:3456',\n client_id: clientId,\n code_verifier: codeData.codeVerifier,\n }\n\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given an identity token, request an application token.\n * @param identityToken - access token obtained in a previous step\n * @param store - the store to use, only needed for admin API\n * @returns An array with the application access tokens.\n */\nexport async function exchangeAccessForApplicationTokens(\n identityToken: IdentityToken,\n scopes: ExchangeScopes,\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const token = identityToken.accessToken\n\n const [partners, storefront] = await Promise.all([\n requestAppToken('partners', token, scopes.partners),\n requestAppToken('storefront-renderer', token, scopes.storefront),\n ])\n\n const result = {\n ...partners,\n ...storefront,\n }\n\n if (store) {\n const admin = await requestAppToken('admin', token, scopes.admin, store)\n Object.assign(result, admin)\n }\n return result\n}\n\n/**\n * Given an expired access token, refresh it to get a new one.\n */\nexport async function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken> {\n const clientId = getIdentityClientId()\n const params = {\n grant_type: 'refresh_token',\n access_token: currentToken.accessToken,\n refresh_token: currentToken.refreshToken,\n client_id: clientId,\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid partners API token\n * This token does not accept extra scopes, just the cli one.\n * @param token - The CLI token passed as ENV variable\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCustomPartnerToken(token: string): Promise<ApplicationToken> {\n const appId = applicationId('partners')\n const newToken = await requestAppToken('partners', token, ['https://api.shopify.com/auth/partners.app.cli.access'])\n return newToken[appId]!\n}\n\nexport type IdentityDeviceError =\n | 'authorization_pending'\n | 'access_denied'\n | 'expired_token'\n | 'slow_down'\n | 'unknown_failure'\n\n/**\n * Given a deviceCode obtained after starting a device identity flow, request an identity token.\n * @param deviceCode - The device code obtained after starting a device identity flow\n * @param scopes - The scopes to request\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeDeviceCodeForAccessToken(\n deviceCode: string,\n): Promise<Result<IdentityToken, IdentityDeviceError>> {\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: deviceCode,\n client_id: clientId,\n }\n\n const tokenResult = await tokenRequest(params)\n if (tokenResult.isErr()) {\n return err(tokenResult.error as IdentityDeviceError)\n }\n const identityToken = buildIdentityToken(tokenResult.value)\n return ok(identityToken)\n}\n\nasync function requestAppToken(\n api: API,\n token: string,\n scopes: string[] = [],\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const appId = applicationId(api)\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',\n requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n client_id: clientId,\n audience: appId,\n scope: scopes.join(' '),\n subject_token: token,\n ...(api === 'admin' && {destination: `https://${store}/admin`}),\n }\n\n let identifier = appId\n if (api === 'admin' && store) {\n identifier = `${store}-${appId}`\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n const appToken = await buildApplicationToken(value)\n return {[identifier]: appToken}\n}\n\ninterface TokenRequestResult {\n access_token: string\n expires_in: number\n refresh_token: string\n scope: string\n}\n\nfunction tokenRequestErrorHandler(error: string) {\n if (error === 'invalid_grant') {\n // There's an scenario when Identity returns \"invalid_grant\" when trying to refresh the token\n // using a valid refresh token. When that happens, we take the user through the authentication flow.\n return new InvalidGrantError()\n }\n if (error === 'invalid_request') {\n // There's an scenario when Identity returns \"invalid_request\" when exchanging an identity token.\n // This means the token is invalid. We clear the session and throw an error to let the caller know.\n return new InvalidRequestError()\n }\n return new AbortError(error)\n}\n\nasync function tokenRequest(params: {[key: string]: string}): Promise<Result<TokenRequestResult, string>> {\n const fqdn = await identityFqdn()\n const url = new URL(`https://${fqdn}/oauth/token`)\n url.search = new URLSearchParams(Object.entries(params)).toString()\n const res = await shopifyFetch(url.href, {method: 'POST'})\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const payload: any = await res.json()\n\n if (res.ok) return ok(payload)\n return err(payload.error)\n}\n\nfunction buildIdentityToken(result: TokenRequestResult): IdentityToken {\n return {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n\nfunction buildApplicationToken(result: TokenRequestResult): ApplicationToken {\n return {\n accessToken: result.access_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../../../src/private/node/session/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,IAAI,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAG5E,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAA;AAEjD,MAAM,OAAO,iBAAkB,SAAQ,eAAe;CAAG;AACzD,MAAM,OAAO,mBAAoB,SAAQ,eAAe;CAAG;AAO3D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,QAAwB;IACvE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,EAAE,CAAA;IAC5C,MAAM,MAAM,GAAG;QACb,UAAU,EAAE,oBAAoB;QAChC,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,YAAY,EAAE,uBAAuB;QACrC,SAAS,EAAE,QAAQ;QACnB,aAAa,EAAE,QAAQ,CAAC,YAAY;KACrC,CAAA;IAED,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC,UAAU,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,GAAQ,MAAM,GAAG,CAAC,IAAI,EAAE,CAAA;IAErC,IAAI,GAAG,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAA;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA0B;IACpD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,YAAY,EAAE,MAAM,CAAC,aAAa;QAClC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,MAA0B;IACvD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {ApplicationToken, IdentityToken} from './schema.js'\nimport {applicationId, clientId as getIdentityClientId} from './identity.js'\nimport {CodeAuthResult} from './authorize.js'\nimport {API} from '../../../network/api.js'\nimport {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {err, ok, Result} from '../../../public/node/result.js'\nimport {AbortError} from '../../../public/node/error.js'\nimport {ExtendableError} from '../../../error.js'\n\nexport class InvalidGrantError extends ExtendableError {}\nexport class InvalidRequestError extends ExtendableError {}\n\nexport interface ExchangeScopes {\n admin: string[]\n partners: string[]\n storefront: string[]\n}\n/**\n * Given a valid authorization code, request an identity access token.\n * This token can then be used to get API specific tokens.\n * @param codeData - code and codeVerifier from the authorize endpoint\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeCodeForAccessToken(codeData: CodeAuthResult): Promise<IdentityToken> {\n const clientId = await getIdentityClientId()\n const params = {\n grant_type: 'authorization_code',\n code: codeData.code,\n redirect_uri: 'http://127.0.0.1:3456',\n client_id: clientId,\n code_verifier: codeData.codeVerifier,\n }\n\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given an identity token, request an application token.\n * @param identityToken - access token obtained in a previous step\n * @param store - the store to use, only needed for admin API\n * @returns An array with the application access tokens.\n */\nexport async function exchangeAccessForApplicationTokens(\n identityToken: IdentityToken,\n scopes: ExchangeScopes,\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const token = identityToken.accessToken\n\n const [partners, storefront] = await Promise.all([\n requestAppToken('partners', token, scopes.partners),\n requestAppToken('storefront-renderer', token, scopes.storefront),\n ])\n\n const result = {\n ...partners,\n ...storefront,\n }\n\n if (store) {\n const admin = await requestAppToken('admin', token, scopes.admin, store)\n Object.assign(result, admin)\n }\n return result\n}\n\n/**\n * Given an expired access token, refresh it to get a new one.\n */\nexport async function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken> {\n const clientId = getIdentityClientId()\n const params = {\n grant_type: 'refresh_token',\n access_token: currentToken.accessToken,\n refresh_token: currentToken.refreshToken,\n client_id: clientId,\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value)\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid partners API token\n * This token does not accept extra scopes, just the cli one.\n * @param token - The CLI token passed as ENV variable\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCustomPartnerToken(token: string): Promise<ApplicationToken> {\n const appId = applicationId('partners')\n const newToken = await requestAppToken('partners', token, ['https://api.shopify.com/auth/partners.app.cli.access'])\n return newToken[appId]!\n}\n\nexport type IdentityDeviceError =\n | 'authorization_pending'\n | 'access_denied'\n | 'expired_token'\n | 'slow_down'\n | 'unknown_failure'\n\n/**\n * Given a deviceCode obtained after starting a device identity flow, request an identity token.\n * @param deviceCode - The device code obtained after starting a device identity flow\n * @param scopes - The scopes to request\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeDeviceCodeForAccessToken(\n deviceCode: string,\n): Promise<Result<IdentityToken, IdentityDeviceError>> {\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: deviceCode,\n client_id: clientId,\n }\n\n const tokenResult = await tokenRequest(params)\n if (tokenResult.isErr()) {\n return err(tokenResult.error as IdentityDeviceError)\n }\n const identityToken = buildIdentityToken(tokenResult.value)\n return ok(identityToken)\n}\n\nasync function requestAppToken(\n api: API,\n token: string,\n scopes: string[] = [],\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const appId = applicationId(api)\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',\n requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n client_id: clientId,\n audience: appId,\n scope: scopes.join(' '),\n subject_token: token,\n ...(api === 'admin' && {destination: `https://${store}/admin`}),\n }\n\n let identifier = appId\n if (api === 'admin' && store) {\n identifier = `${store}-${appId}`\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n const appToken = await buildApplicationToken(value)\n return {[identifier]: appToken}\n}\n\ninterface TokenRequestResult {\n access_token: string\n expires_in: number\n refresh_token: string\n scope: string\n}\n\nfunction tokenRequestErrorHandler(error: string) {\n if (error === 'invalid_grant') {\n // There's an scenario when Identity returns \"invalid_grant\" when trying to refresh the token\n // using a valid refresh token. When that happens, we take the user through the authentication flow.\n return new InvalidGrantError()\n }\n if (error === 'invalid_request') {\n // There's an scenario when Identity returns \"invalid_request\" when exchanging an identity token.\n // This means the token is invalid. We clear the session and throw an error to let the caller know.\n return new InvalidRequestError()\n }\n return new AbortError(error)\n}\n\nasync function tokenRequest(params: {[key: string]: string}): Promise<Result<TokenRequestResult, string>> {\n const fqdn = await identityFqdn()\n const url = new URL(`https://${fqdn}/oauth/token`)\n url.search = new URLSearchParams(Object.entries(params)).toString()\n const res = await shopifyFetch(url.href, {method: 'POST'})\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const payload: any = await res.json()\n\n if (res.ok) return ok(payload)\n return err(payload.error)\n}\n\nfunction buildIdentityToken(result: TokenRequestResult): IdentityToken {\n return {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n\nfunction buildApplicationToken(result: TokenRequestResult): ApplicationToken {\n return {\n accessToken: result.access_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { identityFqdn } from '../../../public/node/environment/fqdn.js';
|
|
2
2
|
import { debug } from '../../../output.js';
|
|
3
|
-
import { shopifyFetch } from '../../../http.js';
|
|
3
|
+
import { shopifyFetch } from '../../../public/node/http.js';
|
|
4
4
|
export async function validateIdentityToken(token) {
|
|
5
5
|
try {
|
|
6
6
|
const instrospectionURL = await getInstrospectionEndpoint();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-token-validation.js","sourceRoot":"","sources":["../../../../src/private/node/session/identity-token-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,0CAA0C,CAAA;AACrE,OAAO,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAC,YAAY,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"identity-token-validation.js","sourceRoot":"","sources":["../../../../src/private/node/session/identity-token-validation.ts"],"names":[],"mappings":"AAA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,KAAK,EAAE;QACd,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAA;QAChD,OAAO,KAAK,CAAA;KACb;AACH,CAAC;AAED,KAAK,UAAU,yBAAyB;IACtC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,WAAW,MAAM,YAAY,EAAE,wCAAwC,CAAC,CAAA;IAC5G,8DAA8D;IAC9D,MAAM,IAAI,GAAQ,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACvC,OAAO,IAAI,CAAC,sBAAsB,CAAA;AACpC,CAAC","sourcesContent":["import {identityFqdn} from '../../../public/node/environment/fqdn.js'\nimport {debug} from '../../../output.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\n\nexport async function validateIdentityToken(token: string) {\n try {\n const instrospectionURL = await getInstrospectionEndpoint()\n const options = {\n method: 'POST',\n headers: {Authorization: `Bearer ${token}`, 'Content-Type': 'application/json'},\n body: JSON.stringify({token}),\n }\n debug(`Sending Identity Introspection request to URL: ${instrospectionURL}`)\n\n const response = await shopifyFetch(instrospectionURL, options)\n\n if (response.ok && response.headers.get('content-type')?.includes('json')) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const json: any = await response.json()\n debug(`The identity token is valid: ${json.valid}`)\n return json.valid\n } else {\n const text = await response.text()\n debug(`The Introspection request failed with:\n - status: ${response.status}\n - www-authenticate header: ${JSON.stringify(response.headers.get('www-authenticate'))}\n - body: ${JSON.stringify(text)}`)\n return false\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n debug(`The identity token is invalid: ${error}`)\n return false\n }\n}\n\nasync function getInstrospectionEndpoint(): Promise<string> {\n const response = await shopifyFetch(`https://${await identityFqdn()}/.well-known/openid-configuration.json`)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const json: any = await response.json()\n return json.introspection_endpoint\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { moduleDirectory } from '../../../public/node/path.js';
|
|
2
|
+
import { readFile, findPathUp } from '../../../public/node/fs.js';
|
|
3
3
|
import { Bug } from '../../../error.js';
|
|
4
4
|
const HTMLFileNames = [
|
|
5
5
|
'empty-url.html',
|
|
@@ -17,7 +17,7 @@ const FaviconFileName = 'favicon.svg';
|
|
|
17
17
|
* @returns The full path of the file, or null if not found.
|
|
18
18
|
*/
|
|
19
19
|
const getFilePath = async (fileName) => {
|
|
20
|
-
const filePath = await
|
|
20
|
+
const filePath = await findPathUp(`assets/${fileName}`, {
|
|
21
21
|
type: 'file',
|
|
22
22
|
cwd: moduleDirectory(import.meta.url),
|
|
23
23
|
});
|
|
@@ -28,31 +28,31 @@ const getFilePath = async (fileName) => {
|
|
|
28
28
|
};
|
|
29
29
|
export const getEmptyUrlHTML = async () => {
|
|
30
30
|
const filePath = await getFilePath(HTMLFileNames[0]);
|
|
31
|
-
return
|
|
31
|
+
return readFile(filePath);
|
|
32
32
|
};
|
|
33
33
|
export const getAuthErrorHTML = async () => {
|
|
34
34
|
const filePath = await getFilePath(HTMLFileNames[1]);
|
|
35
|
-
return
|
|
35
|
+
return readFile(filePath);
|
|
36
36
|
};
|
|
37
37
|
export const getMissingCodeHTML = async () => {
|
|
38
38
|
const filePath = await getFilePath(HTMLFileNames[2]);
|
|
39
|
-
return
|
|
39
|
+
return readFile(filePath);
|
|
40
40
|
};
|
|
41
41
|
export const getMissingStateHTML = async () => {
|
|
42
42
|
const filePath = await getFilePath(HTMLFileNames[3]);
|
|
43
|
-
return
|
|
43
|
+
return readFile(filePath);
|
|
44
44
|
};
|
|
45
45
|
export const getSuccessHTML = async () => {
|
|
46
46
|
const filePath = await getFilePath(HTMLFileNames[4]);
|
|
47
|
-
return
|
|
47
|
+
return readFile(filePath);
|
|
48
48
|
};
|
|
49
49
|
export const getStylesheet = async () => {
|
|
50
50
|
const filePath = await getFilePath(StylesheetFilename);
|
|
51
|
-
return
|
|
51
|
+
return readFile(filePath);
|
|
52
52
|
};
|
|
53
53
|
export const getFavicon = async () => {
|
|
54
54
|
const filePath = await getFilePath(FaviconFileName);
|
|
55
|
-
return
|
|
55
|
+
return readFile(filePath);
|
|
56
56
|
};
|
|
57
57
|
export const EmptyUrlString = 'We received the authentication redirect but the URL is empty.';
|
|
58
58
|
export const AuthErrorString = 'There was an issue while trying to authenticate.';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-auth.js","sourceRoot":"","sources":["../../../../src/private/node/session/post-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"post-auth.js","sourceRoot":"","sources":["../../../../src/private/node/session/post-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAA;AAC5D,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAC,GAAG,EAAC,MAAM,mBAAmB,CAAA;AAErC,MAAM,aAAa,GAAG;IACpB,gBAAgB;IAChB,iBAAiB;IACjB,mBAAmB;IACnB,oBAAoB;IACpB,cAAc;CACN,CAAA;AACV,MAAM,kBAAkB,GAAG,WAAW,CAAA;AACtC,MAAM,eAAe,GAAG,aAAa,CAAA;AAErC;;;;;GAKG;AACH,MAAM,WAAW,GAAG,KAAK,EAAE,QAAgB,EAAmB,EAAE;IAC9D,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,UAAU,QAAQ,EAAE,EAAE;QACtD,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;KACtC,CAAC,CAAA;IACF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,8BAA8B,EAAE,CAAA;KACvC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IACzD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,CA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;AAC3B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,+DAA+D,CAAA;AAE7F,MAAM,CAAC,MAAM,eAAe,GAAG,kDAAkD,CAAA;AAEjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,kFAAkF,CAAA;AAEnH,MAAM,CAAC,MAAM,kBAAkB,GAAG,mFAAmF,CAAA;AAErH,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE,CAAC,IAAI,GAAG,CAAC,+BAA+B,CAAC,CAAA","sourcesContent":["import {moduleDirectory} from '../../../public/node/path.js'\nimport {readFile, findPathUp} from '../../../public/node/fs.js'\nimport {Bug} from '../../../error.js'\n\nconst HTMLFileNames = [\n 'empty-url.html',\n 'auth-error.html',\n 'missing-code.html',\n 'missing-state.html',\n 'success.html',\n] as const\nconst StylesheetFilename = 'style.css'\nconst FaviconFileName = 'favicon.svg'\n\n/**\n * Finds the full path of the given file-name from the assets folder.\n *\n * @param fileName - The name of the file to look for.\n * @returns The full path of the file, or null if not found.\n */\nconst getFilePath = async (fileName: string): Promise<string> => {\n const filePath = await findPathUp(`assets/${fileName}`, {\n type: 'file',\n cwd: moduleDirectory(import.meta.url),\n })\n if (!filePath) {\n throw RedirectPageAssetNotFoundError()\n }\n return filePath\n}\n\nexport const getEmptyUrlHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[0])\n return readFile(filePath)\n}\n\nexport const getAuthErrorHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[1])\n return readFile(filePath)\n}\n\nexport const getMissingCodeHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[2])\n return readFile(filePath)\n}\n\nexport const getMissingStateHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[3])\n return readFile(filePath)\n}\n\nexport const getSuccessHTML = async (): Promise<string> => {\n const filePath = await getFilePath(HTMLFileNames[4])\n return readFile(filePath)\n}\n\nexport const getStylesheet = async (): Promise<string> => {\n const filePath = await getFilePath(StylesheetFilename)\n return readFile(filePath)\n}\n\nexport const getFavicon = async (): Promise<string> => {\n const filePath = await getFilePath(FaviconFileName)\n return readFile(filePath)\n}\n\nexport const EmptyUrlString = 'We received the authentication redirect but the URL is empty.'\n\nexport const AuthErrorString = 'There was an issue while trying to authenticate.'\n\nexport const MissingCodeString = \"The authentication can't continue because the redirect doesn't include the code.\"\n\nexport const MissingStateString = \"The authentication can't continue because the redirect doesn't include the state.\"\n\nexport const RedirectPageAssetNotFoundError = () => new Bug(`Redirect page asset not found`)\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SessionSchema } from './schema.js';
|
|
2
|
-
import
|
|
2
|
+
import { keychainConstants } from '../constants.js';
|
|
3
3
|
import { platformAndArch } from '../../../public/node/os.js';
|
|
4
4
|
import { store as secureStore, fetch as secureFetch, remove as secureRemove } from '../../../secure-store.js';
|
|
5
5
|
import { content, debug } from '../../../output.js';
|
|
@@ -19,7 +19,7 @@ export async function store(session) {
|
|
|
19
19
|
await secureStore(identifier, jsonSession);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
|
|
22
|
+
setSession(jsonSession);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -36,7 +36,7 @@ export async function fetch() {
|
|
|
36
36
|
content = await secureFetch(identifier);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
content =
|
|
39
|
+
content = getSession();
|
|
40
40
|
}
|
|
41
41
|
if (!content) {
|
|
42
42
|
return undefined;
|
|
@@ -59,9 +59,9 @@ export async function remove() {
|
|
|
59
59
|
await secureRemove(identifier);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
|
|
62
|
+
removeSession();
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
clearAllAppInfo();
|
|
65
65
|
}
|
|
66
66
|
/**
|
|
67
67
|
* Returns true if the secure store is available on the system.
|
|
@@ -76,7 +76,7 @@ async function secureStoreAvailable() {
|
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
const keytar = await import('keytar');
|
|
79
|
-
await keytar.default.findCredentials(
|
|
79
|
+
await keytar.default.findCredentials(keychainConstants.service);
|
|
80
80
|
debug(content `Secure store is available`);
|
|
81
81
|
return true;
|
|
82
82
|
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAC,KAAK,IAAI,WAAW,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,IAAI,YAAY,EAAC,MAAM,0BAA0B,CAAA;AAC3G,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAA;AAGxF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAgB;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC3C,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,WAAW,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;KAC3C;SAAM;QACL,UAAU,CAAC,WAAW,CAAC,CAAA;KACxB;AACH,CAAC;AA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,CAAC,OAAO,CAAA,6BAA6B,CAAC,CAAA;QAC3C,OAAO,KAAK,CAAA;KACb;AACH,CAAC","sourcesContent":["import {SessionSchema} from './schema.js'\nimport {keychainConstants} from '../constants.js'\nimport {platformAndArch} from '../../../public/node/os.js'\nimport {store as secureStore, fetch as secureFetch, remove as secureRemove} from '../../../secure-store.js'\nimport {content, debug} from '../../../output.js'\nimport {getSession, removeSession, setSession, clearAllAppInfo} from '../../../store.js'\nimport type {Session} from './schema.js'\n\n/**\n * The identifier of the session in the secure store.\n */\nexport const identifier = 'session'\n\n/**\n * Serializes the session as a JSON and stores it securely in the system.\n * If the secure store is not available, the session is stored in the local config.\n * @param session - the session to store.\n */\nexport async function store(session: Session) {\n const jsonSession = JSON.stringify(session)\n if (await secureStoreAvailable()) {\n await secureStore(identifier, jsonSession)\n } else {\n setSession(jsonSession)\n }\n}\n\n/**\n * Fetches the session from the secure store and returns it.\n * If the secure store is not available, the session is fetched from the local config.\n * If the format of the session is invalid, the method will discard it.\n * In the future might add some logic for supporting migrating the schema\n * of already-persisted sessions.\n * @returns Returns a promise that resolves with the session if it exists and is valid.\n */\nexport async function fetch(): Promise<Session | undefined> {\n let content\n if (await secureStoreAvailable()) {\n content = await secureFetch(identifier)\n } else {\n content = getSession()\n }\n\n if (!content) {\n return undefined\n }\n const contentJson = JSON.parse(content)\n const parsedSession = await SessionSchema.safeParseAsync(contentJson)\n if (parsedSession.success) {\n return parsedSession.data\n } else {\n await remove()\n return undefined\n }\n}\n\n/**\n * Removes a session from the system.\n */\nexport async function remove() {\n if (await secureStoreAvailable()) {\n await secureRemove(identifier)\n } else {\n removeSession()\n }\n\n clearAllAppInfo()\n}\n\n/**\n * Returns true if the secure store is available on the system.\n * Keytar it's not supported on some Linux environments or Windows.\n * More details: https://github.com/Shopify/shopify-cli-planning/issues/261\n * @returns a boolean indicating if the secure store is available.\n */\nasync function secureStoreAvailable(): Promise<boolean> {\n try {\n if (platformAndArch().platform === 'windows') {\n debug(content`Secure store not supported on Windows`)\n return false\n }\n const keytar = await import('keytar')\n await keytar.default.findCredentials(keychainConstants.service)\n debug(content`Secure store is available`)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (_error) {\n debug(content`Failed to load secure store`)\n return false\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { applicationId } from './identity.js';
|
|
2
2
|
import { validateIdentityToken } from './identity-token-validation.js';
|
|
3
|
-
import
|
|
3
|
+
import { sessionConstants } from '../constants.js';
|
|
4
4
|
import { debug } from '../../../output.js';
|
|
5
5
|
import { firstPartyDev } from '../../../public/node/environment/local.js';
|
|
6
6
|
/**
|
|
@@ -60,6 +60,6 @@ function isTokenExpired(token) {
|
|
|
60
60
|
return token.expiresAt < expireThreshold();
|
|
61
61
|
}
|
|
62
62
|
function expireThreshold() {
|
|
63
|
-
return new Date(Date.now() +
|
|
63
|
+
return new Date(Date.now() + sessionConstants.expirationTimeMarginInMinutes * 60 * 1000);
|
|
64
64
|
}
|
|
65
65
|
//# sourceMappingURL=validate.js.map
|