@shopify/cli-kit 3.36.1 → 3.37.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/index.d.ts +0 -7
- package/dist/index.js +0 -7
- package/dist/index.js.map +1 -1
- package/dist/private/node/analytics.js +5 -4
- package/dist/private/node/analytics.js.map +1 -1
- package/dist/private/node/api/graphql.js +2 -2
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.d.ts +1 -1
- package/dist/private/node/api/headers.js +1 -1
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/conf-store.d.ts +21 -0
- package/dist/private/node/conf-store.js +41 -0
- package/dist/private/node/conf-store.js.map +1 -0
- package/dist/{secure-store.d.ts → private/node/secure-store.d.ts} +3 -3
- package/dist/{secure-store.js → private/node/secure-store.js} +7 -7
- package/dist/private/node/secure-store.js.map +1 -0
- package/dist/private/node/session/authorize.d.ts +0 -2
- package/dist/private/node/session/authorize.js +2 -3
- package/dist/private/node/session/authorize.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +2 -2
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/exchange.d.ts +1 -1
- package/dist/private/node/session/exchange.js +1 -2
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/identity.js +2 -2
- package/dist/private/node/session/identity.js.map +1 -1
- package/dist/private/node/session/post-auth.d.ts +2 -2
- package/dist/private/node/session/post-auth.js +2 -2
- package/dist/private/node/session/post-auth.js.map +1 -1
- package/dist/private/node/session/redirect-listener.js +5 -5
- package/dist/private/node/session/redirect-listener.js.map +1 -1
- package/dist/private/node/session/schema.d.ts +46 -46
- package/dist/private/node/session/schema.js +12 -12
- package/dist/private/node/session/schema.js.map +1 -1
- package/dist/private/node/session/scopes.js +2 -2
- package/dist/private/node/session/scopes.js.map +1 -1
- package/dist/private/node/session/store.js +5 -6
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session.js +3 -4
- package/dist/private/node/session.js.map +1 -1
- package/dist/{testing → private/node/testing}/ui.d.ts +0 -0
- package/dist/{testing → private/node/testing}/ui.js +1 -1
- package/dist/private/node/testing/ui.js.map +1 -0
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.test.js +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.d.ts +1 -1
- package/dist/private/node/ui/components/FatalError.js +2 -2
- package/dist/private/node/ui/components/FatalError.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.test.js +4 -4
- package/dist/private/node/ui/components/FatalError.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.test.js +1 -1
- package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +1 -1
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.test.js +1 -1
- package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
- package/dist/private/node/ui/components/TextPrompt.test.js +1 -1
- package/dist/private/node/ui/components/TextPrompt.test.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/analytics.js +6 -6
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.js +3 -3
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/base-command.js +6 -5
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/conf.d.ts +2 -0
- package/dist/public/node/conf.js +3 -0
- package/dist/public/node/conf.js.map +1 -0
- package/dist/public/node/environment/fqdn.d.ts +5 -5
- package/dist/public/node/environment/fqdn.js +5 -5
- package/dist/public/node/environment/fqdn.js.map +1 -1
- package/dist/public/node/environment/spin.js +2 -2
- package/dist/public/node/environment/spin.js.map +1 -1
- package/dist/public/node/error-handler.d.ts +2 -2
- package/dist/public/node/error-handler.js +7 -7
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/error.d.ts +84 -4
- package/dist/public/node/error.js +165 -4
- package/dist/public/node/error.js.map +1 -1
- package/dist/public/node/fs.js +4 -0
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.d.ts +2 -2
- package/dist/public/node/git.js +11 -10
- package/dist/public/node/git.js.map +1 -1
- package/dist/{metadata.d.ts → public/node/metadata.d.ts} +13 -13
- package/dist/{metadata.js → public/node/metadata.js} +13 -8
- package/dist/public/node/metadata.js.map +1 -0
- package/dist/{monorail.d.ts → public/node/monorail.d.ts} +11 -3
- package/dist/{monorail.js → public/node/monorail.js} +11 -3
- package/dist/public/node/monorail.js.map +1 -0
- package/dist/public/node/node-package-manager.d.ts +2 -2
- package/dist/public/node/node-package-manager.js +7 -2
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/path.d.ts +12 -2
- package/dist/public/node/path.js +17 -4
- package/dist/public/node/path.js.map +1 -1
- package/dist/public/node/plugins/tunnel.d.ts +2 -2
- package/dist/public/node/plugins/tunnel.js +1 -1
- package/dist/public/node/plugins/tunnel.js.map +1 -1
- package/dist/{plugins.d.ts → public/node/plugins.d.ts} +17 -11
- package/dist/{plugins.js → public/node/plugins.js} +15 -9
- package/dist/public/node/plugins.js.map +1 -0
- package/dist/public/node/result.js +3 -4
- package/dist/public/node/result.js.map +1 -1
- package/dist/public/node/ruby.d.ts +1 -0
- package/dist/public/node/ruby.js +24 -31
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/schema.d.ts +1 -0
- package/dist/public/node/schema.js +2 -0
- package/dist/public/node/schema.js.map +1 -0
- package/dist/public/node/session.js +4 -4
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/system.js +4 -3
- package/dist/public/node/system.js.map +1 -1
- package/dist/public/node/tcp.js +2 -2
- package/dist/public/node/tcp.js.map +1 -1
- package/dist/public/node/testing/output.d.ts +16 -0
- package/dist/{testing → public/node/testing}/output.js +6 -2
- package/dist/public/node/testing/output.js.map +1 -0
- package/dist/public/node/ui.d.ts +1 -1
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/vscode.js +2 -2
- package/dist/public/node/vscode.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui.js +5 -5
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/dist/error.d.ts +0 -68
- package/dist/error.js +0 -143
- package/dist/error.js.map +0 -1
- package/dist/git.d.ts +0 -36
- package/dist/git.js +0 -133
- package/dist/git.js.map +0 -1
- package/dist/metadata.js.map +0 -1
- package/dist/monorail.js.map +0 -1
- package/dist/plugins.js.map +0 -1
- package/dist/schema.d.ts +0 -1
- package/dist/schema.js +0 -2
- package/dist/schema.js.map +0 -1
- package/dist/secure-store.js.map +0 -1
- package/dist/store.d.ts +0 -53
- package/dist/store.js +0 -133
- package/dist/store.js.map +0 -1
- package/dist/testing/output.d.ts +0 -10
- package/dist/testing/output.js.map +0 -1
- package/dist/testing/store.d.ts +0 -7
- package/dist/testing/store.js +0 -26
- package/dist/testing/store.js.map +0 -1
- package/dist/testing/ui.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
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,
|
|
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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AC3B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,IAAqB,EAAE;IAC7D,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,IAAqB,EAAE;IACxD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,IAAqB,EAAE;IACvD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACtD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC3B,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,IAAqB,EAAE;IACpD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,eAAe,CAAC,CAAA;IACnD,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;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,QAAQ,CAAC,+BAA+B,CAAC,CAAA","sourcesContent":["import {moduleDirectory} from '../../../public/node/path.js'\nimport {readFile, findPathUp} from '../../../public/node/fs.js'\nimport {BugError} from '../../../public/node/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 BugError(`Redirect page asset not found`)\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getFavicon, getStylesheet, getEmptyUrlHTML, getAuthErrorHTML, getMissingCodeHTML, getMissingStateHTML, getSuccessHTML, EmptyUrlString, MissingCodeString, MissingStateString, } from './post-auth.js';
|
|
2
|
-
import {
|
|
2
|
+
import { AbortError, BugError } from '../../../public/node/error.js';
|
|
3
3
|
import { content, info, token } from '../../../output.js';
|
|
4
4
|
import { createApp } from 'h3';
|
|
5
5
|
import url from 'url';
|
|
@@ -46,26 +46,26 @@ export class RedirectListener {
|
|
|
46
46
|
// If there was an empty/malformed URL sent back.
|
|
47
47
|
if (!requestUrl) {
|
|
48
48
|
const file = await getEmptyUrlHTML();
|
|
49
|
-
const err = new
|
|
49
|
+
const err = new BugError(EmptyUrlString);
|
|
50
50
|
return respond(file, err, undefined, undefined);
|
|
51
51
|
}
|
|
52
52
|
// If an error was returned by the Identity server.
|
|
53
53
|
const queryObject = url.parse(requestUrl, true).query;
|
|
54
54
|
if (queryObject.error && queryObject.error_description) {
|
|
55
55
|
const file = await getAuthErrorHTML();
|
|
56
|
-
const err = new
|
|
56
|
+
const err = new AbortError(`${queryObject.error_description}`);
|
|
57
57
|
return respond(file, err, undefined, undefined);
|
|
58
58
|
}
|
|
59
59
|
// If the code isn't present in the URL.
|
|
60
60
|
if (!queryObject.code) {
|
|
61
61
|
const file = await getMissingCodeHTML();
|
|
62
|
-
const err = new
|
|
62
|
+
const err = new BugError(MissingCodeString);
|
|
63
63
|
return respond(file, err, undefined, undefined);
|
|
64
64
|
}
|
|
65
65
|
// If the state isn't present in the URL.
|
|
66
66
|
if (!queryObject.state) {
|
|
67
67
|
const file = await getMissingStateHTML();
|
|
68
|
-
const err = new
|
|
68
|
+
const err = new BugError(MissingStateString);
|
|
69
69
|
return respond(file, err, undefined, undefined);
|
|
70
70
|
}
|
|
71
71
|
const file = await getSuccessHTML();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirect-listener.js","sourceRoot":"","sources":["../../../../src/private/node/session/redirect-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"redirect-listener.js","sourceRoot":"","sources":["../../../../src/private/node/session/redirect-listener.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AAClE,OAAO,EAAC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAC,SAAS,EAAkC,MAAM,IAAI,CAAA;AAC7D,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAC,YAAY,EAAS,MAAM,MAAM,CAAA;AAEzC,MAAM,sBAAsB,GAAG,EAAE,CAAA;AACjC,MAAM,sBAAsB,GAAG,GAAG,CAAA;AAgBlC;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAmE3B,YAAY,OAAgC;QAC1C,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC/D,CAAC;IAtEO,MAAM,CAAC,YAAY,CAAC,QAA0B;QACpD,MAAM,GAAG,GAAG,SAAS,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAwB,EAAE,QAAwB,EAAE,EAAE;YAC5F,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAA;YAC9B,IAAI,UAAU,EAAE,QAAQ,CAAC,S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EmptyUrlString,\n MissingCodeString,\n MissingStateString,\n} from './post-auth.js'\nimport {AbortError, BugError} from '../../../public/node/error.js'\nimport {content, info, token} from '../../../output.js'\nimport {createApp, IncomingMessage, ServerResponse} from 'h3'\nimport url from 'url'\nimport {createServer, Server} from 'http'\n\nconst ResponseTimeoutSeconds = 10\nconst ServerStopDelaySeconds = 0.5\n\n/**\n * It represents the result of a redirect.\n */\ntype RedirectCallback = (error: Error | undefined, state: string | undefined, code: string | undefined) => void\n\n/**\n * Defines the interface of the options that\n * are used to instantiate a redirect listener.\n */\ninterface RedirectListenerOptions {\n host: string\n port: number\n callback: RedirectCallback\n}\n/**\n * When the authentication completes, Identity redirects\n * the user to a URL. In the case of the CLI, the redirect\n * is to localhost passing some parameters that are necessary\n * to continue the authentication. Because of that, we need\n * an HTTP server that runs and listens to the request.\n */\nexport class RedirectListener {\n private static createServer(callback: RedirectCallback): Server {\n const app = createApp().use('*', async (request: IncomingMessage, response: ServerResponse) => {\n const requestUrl = request.url\n if (requestUrl?.includes('favicon')) {\n const faviconFile = await getFavicon()\n response.setHeader('Content-Type', 'image/svg+xml')\n response.write(faviconFile)\n response.end()\n return {}\n } else if (requestUrl === '/style.css') {\n const stylesheetFile = await getStylesheet()\n response.setHeader('Content-Type', 'text/css')\n response.write(stylesheetFile)\n response.end()\n return {}\n }\n\n const respond = async (contents: string, error?: Error, state?: string, code?: string) => {\n response.setHeader('Content-Type', 'text/html')\n response.write(contents)\n response.end()\n callback(error, state, code)\n return {}\n }\n\n // If there was an empty/malformed URL sent back.\n if (!requestUrl) {\n const file = await getEmptyUrlHTML()\n const err = new BugError(EmptyUrlString)\n return respond(file, err, undefined, undefined)\n }\n\n // If an error was returned by the Identity server.\n const queryObject = url.parse(requestUrl, true).query\n if (queryObject.error && queryObject.error_description) {\n const file = await getAuthErrorHTML()\n const err = new AbortError(`${queryObject.error_description}`)\n return respond(file, err, undefined, undefined)\n }\n\n // If the code isn't present in the URL.\n if (!queryObject.code) {\n const file = await getMissingCodeHTML()\n const err = new BugError(MissingCodeString)\n return respond(file, err, undefined, undefined)\n }\n\n // If the state isn't present in the URL.\n if (!queryObject.state) {\n const file = await getMissingStateHTML()\n const err = new BugError(MissingStateString)\n return respond(file, err, undefined, undefined)\n }\n\n const file = await getSuccessHTML()\n return respond(file, undefined, `${queryObject.code}`, `${queryObject.state}`)\n })\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return createServer(app)\n }\n\n port: number\n host: string\n server: ReturnType<typeof RedirectListener.createServer>\n\n constructor(options: RedirectListenerOptions) {\n this.port = options.port\n this.host = options.host\n this.server = RedirectListener.createServer(options.callback)\n }\n\n start(): void {\n this.server.listen({port: this.port, host: this.host}, () => {})\n }\n\n async stop(): Promise<void> {\n await this.server.close()\n }\n}\n\nexport async function listenRedirect(host: string, port: number, url: string): Promise<{code: string; state: string}> {\n const result = await new Promise<{code: string; state: string}>((resolve, reject) => {\n const timeout = setTimeout(() => {\n const message = '\\nAuto-open timed out. Open the login page: '\n info(content`${message}${token.link('Log in to Shopify Partners', url)}\\n`)\n }, ResponseTimeoutSeconds * 1000)\n\n const callback: RedirectCallback = (error, code, state) => {\n clearTimeout(timeout)\n setTimeout(() => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n redirectListener.stop()\n if (error) reject(error)\n else resolve({code: code as string, state: state as string})\n }, ServerStopDelaySeconds * 1000)\n }\n\n const redirectListener = new RedirectListener({host, port, callback})\n redirectListener.start()\n })\n return result\n}\n"]}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { schema } from '../../../public/node/schema.js';
|
|
2
2
|
/**
|
|
3
3
|
* The schema represents an Identity token.
|
|
4
4
|
*/
|
|
5
|
-
declare const IdentityTokenSchema:
|
|
6
|
-
accessToken:
|
|
7
|
-
refreshToken:
|
|
8
|
-
expiresAt:
|
|
9
|
-
scopes:
|
|
10
|
-
}, "strip",
|
|
11
|
-
scopes: string[];
|
|
5
|
+
declare const IdentityTokenSchema: schema.ZodObject<{
|
|
6
|
+
accessToken: schema.ZodString;
|
|
7
|
+
refreshToken: schema.ZodString;
|
|
8
|
+
expiresAt: schema.ZodEffects<schema.ZodDate, Date, Date>;
|
|
9
|
+
scopes: schema.ZodArray<schema.ZodString, "many">;
|
|
10
|
+
}, "strip", schema.ZodTypeAny, {
|
|
12
11
|
accessToken: string;
|
|
13
12
|
refreshToken: string;
|
|
14
13
|
expiresAt: Date;
|
|
15
|
-
}, {
|
|
16
14
|
scopes: string[];
|
|
15
|
+
}, {
|
|
17
16
|
accessToken: string;
|
|
18
17
|
refreshToken: string;
|
|
19
18
|
expiresAt: Date;
|
|
19
|
+
scopes: string[];
|
|
20
20
|
}>;
|
|
21
21
|
/**
|
|
22
22
|
* The schema represents an application token.
|
|
23
23
|
*/
|
|
24
|
-
declare const ApplicationTokenSchema:
|
|
25
|
-
accessToken:
|
|
26
|
-
expiresAt:
|
|
27
|
-
scopes:
|
|
28
|
-
}, "strip",
|
|
29
|
-
scopes: string[];
|
|
24
|
+
declare const ApplicationTokenSchema: schema.ZodObject<{
|
|
25
|
+
accessToken: schema.ZodString;
|
|
26
|
+
expiresAt: schema.ZodEffects<schema.ZodDate, Date, Date>;
|
|
27
|
+
scopes: schema.ZodArray<schema.ZodString, "many">;
|
|
28
|
+
}, "strip", schema.ZodTypeAny, {
|
|
30
29
|
accessToken: string;
|
|
31
30
|
expiresAt: Date;
|
|
32
|
-
}, {
|
|
33
31
|
scopes: string[];
|
|
32
|
+
}, {
|
|
34
33
|
accessToken: string;
|
|
35
34
|
expiresAt: Date;
|
|
35
|
+
scopes: string[];
|
|
36
36
|
}>;
|
|
37
37
|
/**
|
|
38
38
|
* This schema represents the format of the session
|
|
@@ -57,119 +57,119 @@ declare const ApplicationTokenSchema: define.ZodObject<{
|
|
|
57
57
|
* }
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
export declare const SessionSchema:
|
|
60
|
+
export declare const SessionSchema: schema.ZodObject<{}, "strip", schema.ZodObject<{
|
|
61
61
|
/**
|
|
62
62
|
* It contains the identity token. Before usint it, we exchange it
|
|
63
63
|
* to get a token that we can use with different applications. The exchanged
|
|
64
64
|
* tokens for the applications are stored under applications.
|
|
65
65
|
*/
|
|
66
|
-
identity:
|
|
67
|
-
accessToken:
|
|
68
|
-
refreshToken:
|
|
69
|
-
expiresAt:
|
|
70
|
-
scopes:
|
|
71
|
-
}, "strip",
|
|
72
|
-
scopes: string[];
|
|
66
|
+
identity: schema.ZodObject<{
|
|
67
|
+
accessToken: schema.ZodString;
|
|
68
|
+
refreshToken: schema.ZodString;
|
|
69
|
+
expiresAt: schema.ZodEffects<schema.ZodDate, Date, Date>;
|
|
70
|
+
scopes: schema.ZodArray<schema.ZodString, "many">;
|
|
71
|
+
}, "strip", schema.ZodTypeAny, {
|
|
73
72
|
accessToken: string;
|
|
74
73
|
refreshToken: string;
|
|
75
74
|
expiresAt: Date;
|
|
76
|
-
}, {
|
|
77
75
|
scopes: string[];
|
|
76
|
+
}, {
|
|
78
77
|
accessToken: string;
|
|
79
78
|
refreshToken: string;
|
|
80
79
|
expiresAt: Date;
|
|
80
|
+
scopes: string[];
|
|
81
81
|
}>;
|
|
82
82
|
/**
|
|
83
83
|
* It contains exchanged tokens for the applications the CLI
|
|
84
84
|
* authenticates with. Tokens are scoped under the fqdn of the applications.
|
|
85
85
|
*/
|
|
86
|
-
applications:
|
|
87
|
-
accessToken:
|
|
88
|
-
expiresAt:
|
|
89
|
-
scopes:
|
|
90
|
-
}, "strip",
|
|
91
|
-
scopes: string[];
|
|
86
|
+
applications: schema.ZodObject<{}, "strip", schema.ZodObject<{
|
|
87
|
+
accessToken: schema.ZodString;
|
|
88
|
+
expiresAt: schema.ZodEffects<schema.ZodDate, Date, Date>;
|
|
89
|
+
scopes: schema.ZodArray<schema.ZodString, "many">;
|
|
90
|
+
}, "strip", schema.ZodTypeAny, {
|
|
92
91
|
accessToken: string;
|
|
93
92
|
expiresAt: Date;
|
|
94
|
-
}, {
|
|
95
93
|
scopes: string[];
|
|
94
|
+
}, {
|
|
96
95
|
accessToken: string;
|
|
97
96
|
expiresAt: Date;
|
|
97
|
+
scopes: string[];
|
|
98
98
|
}>, {
|
|
99
99
|
[x: string]: {
|
|
100
|
-
scopes: string[];
|
|
101
100
|
accessToken: string;
|
|
102
101
|
expiresAt: Date;
|
|
102
|
+
scopes: string[];
|
|
103
103
|
};
|
|
104
104
|
}, {
|
|
105
105
|
[x: string]: {
|
|
106
|
-
scopes: string[];
|
|
107
106
|
accessToken: string;
|
|
108
107
|
expiresAt: Date;
|
|
108
|
+
scopes: string[];
|
|
109
109
|
};
|
|
110
110
|
}>;
|
|
111
|
-
}, "strip",
|
|
111
|
+
}, "strip", schema.ZodTypeAny, {
|
|
112
112
|
identity: {
|
|
113
|
-
scopes: string[];
|
|
114
113
|
accessToken: string;
|
|
115
114
|
refreshToken: string;
|
|
116
115
|
expiresAt: Date;
|
|
116
|
+
scopes: string[];
|
|
117
117
|
};
|
|
118
118
|
applications: {
|
|
119
119
|
[x: string]: {
|
|
120
|
-
scopes: string[];
|
|
121
120
|
accessToken: string;
|
|
122
121
|
expiresAt: Date;
|
|
122
|
+
scopes: string[];
|
|
123
123
|
};
|
|
124
124
|
};
|
|
125
125
|
}, {
|
|
126
126
|
identity: {
|
|
127
|
-
scopes: string[];
|
|
128
127
|
accessToken: string;
|
|
129
128
|
refreshToken: string;
|
|
130
129
|
expiresAt: Date;
|
|
130
|
+
scopes: string[];
|
|
131
131
|
};
|
|
132
132
|
applications: {
|
|
133
133
|
[x: string]: {
|
|
134
|
-
scopes: string[];
|
|
135
134
|
accessToken: string;
|
|
136
135
|
expiresAt: Date;
|
|
136
|
+
scopes: string[];
|
|
137
137
|
};
|
|
138
138
|
};
|
|
139
139
|
}>, {
|
|
140
140
|
[x: string]: {
|
|
141
141
|
identity: {
|
|
142
|
-
scopes: string[];
|
|
143
142
|
accessToken: string;
|
|
144
143
|
refreshToken: string;
|
|
145
144
|
expiresAt: Date;
|
|
145
|
+
scopes: string[];
|
|
146
146
|
};
|
|
147
147
|
applications: {
|
|
148
148
|
[x: string]: {
|
|
149
|
-
scopes: string[];
|
|
150
149
|
accessToken: string;
|
|
151
150
|
expiresAt: Date;
|
|
151
|
+
scopes: string[];
|
|
152
152
|
};
|
|
153
153
|
};
|
|
154
154
|
};
|
|
155
155
|
}, {
|
|
156
156
|
[x: string]: {
|
|
157
157
|
identity: {
|
|
158
|
-
scopes: string[];
|
|
159
158
|
accessToken: string;
|
|
160
159
|
refreshToken: string;
|
|
161
160
|
expiresAt: Date;
|
|
161
|
+
scopes: string[];
|
|
162
162
|
};
|
|
163
163
|
applications: {
|
|
164
164
|
[x: string]: {
|
|
165
|
-
scopes: string[];
|
|
166
165
|
accessToken: string;
|
|
167
166
|
expiresAt: Date;
|
|
167
|
+
scopes: string[];
|
|
168
168
|
};
|
|
169
169
|
};
|
|
170
170
|
};
|
|
171
171
|
}>;
|
|
172
|
-
export declare type Session =
|
|
173
|
-
export declare type IdentityToken =
|
|
174
|
-
export declare type ApplicationToken =
|
|
172
|
+
export declare type Session = schema.infer<typeof SessionSchema>;
|
|
173
|
+
export declare type IdentityToken = schema.infer<typeof IdentityTokenSchema>;
|
|
174
|
+
export declare type ApplicationToken = schema.infer<typeof ApplicationTokenSchema>;
|
|
175
175
|
export {};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const DateSchema =
|
|
1
|
+
import { schema } from '../../../public/node/schema.js';
|
|
2
|
+
const DateSchema = schema.preprocess((arg) => {
|
|
3
3
|
if (typeof arg === 'string' || arg instanceof Date)
|
|
4
4
|
return new Date(arg);
|
|
5
5
|
return null;
|
|
6
|
-
},
|
|
6
|
+
}, schema.date());
|
|
7
7
|
/**
|
|
8
8
|
* The schema represents an Identity token.
|
|
9
9
|
*/
|
|
10
|
-
const IdentityTokenSchema =
|
|
11
|
-
accessToken:
|
|
12
|
-
refreshToken:
|
|
10
|
+
const IdentityTokenSchema = schema.object({
|
|
11
|
+
accessToken: schema.string(),
|
|
12
|
+
refreshToken: schema.string(),
|
|
13
13
|
expiresAt: DateSchema,
|
|
14
|
-
scopes:
|
|
14
|
+
scopes: schema.array(schema.string()),
|
|
15
15
|
});
|
|
16
16
|
/**
|
|
17
17
|
* The schema represents an application token.
|
|
18
18
|
*/
|
|
19
|
-
const ApplicationTokenSchema =
|
|
20
|
-
accessToken:
|
|
19
|
+
const ApplicationTokenSchema = schema.object({
|
|
20
|
+
accessToken: schema.string(),
|
|
21
21
|
expiresAt: DateSchema,
|
|
22
|
-
scopes:
|
|
22
|
+
scopes: schema.array(schema.string()),
|
|
23
23
|
});
|
|
24
24
|
/**
|
|
25
25
|
* This schema represents the format of the session
|
|
@@ -44,7 +44,7 @@ const ApplicationTokenSchema = define.object({
|
|
|
44
44
|
* }
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
export const SessionSchema =
|
|
47
|
+
export const SessionSchema = schema.object({}).catchall(schema.object({
|
|
48
48
|
/**
|
|
49
49
|
* It contains the identity token. Before usint it, we exchange it
|
|
50
50
|
* to get a token that we can use with different applications. The exchanged
|
|
@@ -55,6 +55,6 @@ export const SessionSchema = define.object({}).catchall(define.object({
|
|
|
55
55
|
* It contains exchanged tokens for the applications the CLI
|
|
56
56
|
* authenticates with. Tokens are scoped under the fqdn of the applications.
|
|
57
57
|
*/
|
|
58
|
-
applications:
|
|
58
|
+
applications: schema.object({}).catchall(ApplicationTokenSchema),
|
|
59
59
|
}));
|
|
60
60
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/private/node/session/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../../src/private/node/session/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,gCAAgC,CAAA;AAErD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,EAAE;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,YAAY,IAAI;QAAE,OAAO,IAAI,IAAI,CAAC,GAAG,CAAC,CAAA;IACxE,OAAO,IAAI,CAAA;AACb,CAAC,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;AAEjB;;GAEG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAC5B,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE;IAC7B,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;CACtC,CAAC,CAAA;AAEF;;GAEG;AACH,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3C,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;IAC5B,SAAS,EAAE,UAAU;IACrB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;CACtC,CAAC,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CACrD,MAAM,CAAC,MAAM,CAAC;IACZ;;;;OAIG;IACH,QAAQ,EAAE,mBAAmB;IAC7B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC;CACjE,CAAC,CACH,CAAA","sourcesContent":["import {schema} from '../../../public/node/schema.js'\n\nconst DateSchema = schema.preprocess((arg) => {\n if (typeof arg === 'string' || arg instanceof Date) return new Date(arg)\n return null\n}, schema.date())\n\n/**\n * The schema represents an Identity token.\n */\nconst IdentityTokenSchema = schema.object({\n accessToken: schema.string(),\n refreshToken: schema.string(),\n expiresAt: DateSchema,\n scopes: schema.array(schema.string()),\n})\n\n/**\n * The schema represents an application token.\n */\nconst ApplicationTokenSchema = schema.object({\n accessToken: schema.string(),\n expiresAt: DateSchema,\n scopes: schema.array(schema.string()),\n})\n\n/**\n * This schema represents the format of the session\n * that we cache in the system to avoid unnecessary\n * token exchanges.\n *\n * @example\n * ```\n * {\n * \"accounts.shopify.com\": {\n * \"identity\": {...} // IdentityTokenSchema\n * \"applications\": {\n * \"${domain}-application-id\": { // Admin APIs includes domain in the key\n * \"accessToken\": \"...\",\n * },\n * \"$application-id\": { // ApplicationTokenSchema\n * \"accessToken\": \"...\",\n * },\n * }\n * },\n * \"identity.spin.com\": {...}\n * }\n * ```\n */\nexport const SessionSchema = schema.object({}).catchall(\n schema.object({\n /**\n * It contains the identity token. Before usint it, we exchange it\n * to get a token that we can use with different applications. The exchanged\n * tokens for the applications are stored under applications.\n */\n identity: IdentityTokenSchema,\n /**\n * It contains exchanged tokens for the applications the CLI\n * authenticates with. Tokens are scoped under the fqdn of the applications.\n */\n applications: schema.object({}).catchall(ApplicationTokenSchema),\n }),\n)\n\nexport type Session = schema.infer<typeof SessionSchema>\nexport type IdentityToken = schema.infer<typeof IdentityTokenSchema>\nexport type ApplicationToken = schema.infer<typeof ApplicationTokenSchema>\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BugError } from '../../../public/node/error.js';
|
|
2
2
|
import { allAPIs } from '../../../network/api.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generate a flat array with all the default scopes for all the APIs plus
|
|
@@ -31,7 +31,7 @@ function defaultApiScopes(api) {
|
|
|
31
31
|
case 'partners':
|
|
32
32
|
return ['cli'];
|
|
33
33
|
default:
|
|
34
|
-
throw new
|
|
34
|
+
throw new BugError(`Unknown API: ${api}`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
function scopeTransform(scope) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../../../src/private/node/session/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"scopes.js","sourceRoot":"","sources":["../../../../src/private/node/session/scopes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,+BAA+B,CAAA;AACtD,OAAO,EAAC,OAAO,EAAM,MAAM,yBAAyB,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,cAAwB,EAAE;IACzD,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,CAAA;IACjD,MAAM,GAAG,CAAC,QAAQ,EAAE,GAAG,MAAM,EAAE,GAAG,WAAW,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAClE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAQ,EAAE,cAAwB,EAAE;IAC5D,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,GAAG,gBAAgB,CAAC,GAAG,CAAC,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC3G,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AACpC,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAQ;IAChC,QAAQ,GAAG,EAAE;QACX,KAAK,OAAO;YACV,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAA;QAC9C,KAAK,qBAAqB;YACxB,OAAO,CAAC,UAAU,CAAC,CAAA;QACrB,KAAK,UAAU;YACb,OAAO,CAAC,KAAK,CAAC,CAAA;QAChB;YACE,MAAM,IAAI,QAAQ,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAA;KAC5C;AACH,CAAC;AAED,SAAS,cAAc,CAAC,KAAa;IACnC,QAAQ,KAAK,EAAE;QACb,KAAK,SAAS;YACZ,OAAO,iDAAiD,CAAA;QAC1D,KAAK,QAAQ;YACX,OAAO,gDAAgD,CAAA;QACzD,KAAK,cAAc;YACjB,OAAO,2EAA2E,CAAA;QACpF,KAAK,KAAK;YACR,OAAO,sDAAsD,CAAA;QAC/D,KAAK,UAAU;YACb,OAAO,gEAAgE,CAAA;QACzE;YACE,OAAO,KAAK,CAAA;KACf;AACH,CAAC","sourcesContent":["import {BugError} from '../../../public/node/error.js'\nimport {allAPIs, API} from '../../../network/api.js'\n\n/**\n * Generate a flat array with all the default scopes for all the APIs plus\n * any custom scope defined by the user.\n * @param extraScopes - custom user-defined scopes\n * @returns Array of scopes\n */\nexport function allDefaultScopes(extraScopes: string[] = []): string[] {\n let scopes = allAPIs.map(defaultApiScopes).flat()\n scopes = ['openid', ...scopes, ...extraScopes].map(scopeTransform)\n return Array.from(new Set(scopes))\n}\n\n/**\n * Generate a flat array with the default scopes for the given API plus\n * any custom scope defined by the user\n * @param api - API to get the scopes for\n * @param extraScopes - custom user-defined scopes\n * @returns Array of scopes\n */\nexport function apiScopes(api: API, extraScopes: string[] = []): string[] {\n const scopes = ['openid', ...defaultApiScopes(api), ...extraScopes.map(scopeTransform)].map(scopeTransform)\n return Array.from(new Set(scopes))\n}\n\nfunction defaultApiScopes(api: API): string[] {\n switch (api) {\n case 'admin':\n return ['graphql', 'themes', 'collaborator']\n case 'storefront-renderer':\n return ['devtools']\n case 'partners':\n return ['cli']\n default:\n throw new BugError(`Unknown API: ${api}`)\n }\n}\n\nfunction scopeTransform(scope: string): string {\n switch (scope) {\n case 'graphql':\n return 'https://api.shopify.com/auth/shop.admin.graphql'\n case 'themes':\n return 'https://api.shopify.com/auth/shop.admin.themes'\n case 'collaborator':\n return 'https://api.shopify.com/auth/partners.collaborator-relationships.readonly'\n case 'cli':\n return 'https://api.shopify.com/auth/partners.app.cli.access'\n case 'devtools':\n return 'https://api.shopify.com/auth/shop.storefront-renderer.devtools'\n default:\n return scope\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SessionSchema } from './schema.js';
|
|
2
|
+
import { getSession, removeSession, setSession } from '../conf-store.js';
|
|
2
3
|
import { keychainConstants } from '../constants.js';
|
|
3
4
|
import { platformAndArch } from '../../../public/node/os.js';
|
|
4
|
-
import {
|
|
5
|
+
import { secureStoreSave, secureStoreFetch, secureStoreRemove } from '../secure-store.js';
|
|
5
6
|
import { content, debug } from '../../../output.js';
|
|
6
|
-
import { getSession, removeSession, setSession, clearAllAppInfo } from '../../../store.js';
|
|
7
7
|
/**
|
|
8
8
|
* The identifier of the session in the secure store.
|
|
9
9
|
*/
|
|
@@ -16,7 +16,7 @@ export const identifier = 'session';
|
|
|
16
16
|
export async function store(session) {
|
|
17
17
|
const jsonSession = JSON.stringify(session);
|
|
18
18
|
if (await secureStoreAvailable()) {
|
|
19
|
-
await
|
|
19
|
+
await secureStoreSave(identifier, jsonSession);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
22
|
setSession(jsonSession);
|
|
@@ -33,7 +33,7 @@ export async function store(session) {
|
|
|
33
33
|
export async function fetch() {
|
|
34
34
|
let content;
|
|
35
35
|
if (await secureStoreAvailable()) {
|
|
36
|
-
content = await
|
|
36
|
+
content = await secureStoreFetch(identifier);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
content = getSession();
|
|
@@ -56,12 +56,11 @@ export async function fetch() {
|
|
|
56
56
|
*/
|
|
57
57
|
export async function remove() {
|
|
58
58
|
if (await secureStoreAvailable()) {
|
|
59
|
-
await
|
|
59
|
+
await secureStoreRemove(identifier);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
removeSession();
|
|
63
63
|
}
|
|
64
|
-
clearAllAppInfo();
|
|
65
64
|
}
|
|
66
65
|
/**
|
|
67
66
|
* Returns true if the secure store is available on the system.
|
|
@@ -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,EAAC,
|
|
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,UAAU,EAAE,aAAa,EAAE,UAAU,EAAC,MAAM,kBAAkB,CAAA;AACtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAC,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AACvF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AAGjD;;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,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;KAC/C;SAAM;QACL,UAAU,CAAC,WAAW,CAAC,CAAA;KACxB;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,IAAI,OAAO,CAAA;IACX,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,OAAO,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAA;KAC7C;SAAM;QACL,OAAO,GAAG,UAAU,EAAE,CAAA;KACvB;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACrE,IAAI,aAAa,CAAC,OAAO,EAAE;QACzB,OAAO,aAAa,CAAC,IAAI,CAAA;KAC1B;SAAM;QACL,MAAM,MAAM,EAAE,CAAA;QACd,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAA;KACpC;SAAM;QACL,aAAa,EAAE,CAAA;KAChB;AACH,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB;IACjC,IAAI;QACF,IAAI,eAAe,EAAE,CAAC,QAAQ,KAAK,SAAS,EAAE;YAC5C,KAAK,CAAC,OAAO,CAAA,uCAAuC,CAAC,CAAA;YACrD,OAAO,KAAK,CAAA;SACb;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC/D,KAAK,CAAC,OAAO,CAAA,2BAA2B,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,OAAO,MAAM,EAAE;QACf,KAAK,CAAC,OAAO,CAAA,6BAA6B,CAAC,CAAA;QAC3C,OAAO,KAAK,CAAA;KACb;AACH,CAAC","sourcesContent":["import {SessionSchema} from './schema.js'\nimport {getSession, removeSession, setSession} from '../conf-store.js'\nimport {keychainConstants} from '../constants.js'\nimport {platformAndArch} from '../../../public/node/os.js'\nimport {secureStoreSave, secureStoreFetch, secureStoreRemove} from '../secure-store.js'\nimport {content, debug} from '../../../output.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 secureStoreSave(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 secureStoreFetch(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 secureStoreRemove(identifier)\n } else {\n removeSession()\n }\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"]}
|
|
@@ -11,11 +11,10 @@ import { content, token, debug } from '../../output.js';
|
|
|
11
11
|
import { keypress } from '../../ui.js';
|
|
12
12
|
import * as output from '../../output.js';
|
|
13
13
|
import { firstPartyDev, useDeviceAuth } from '../../public/node/environment/local.js';
|
|
14
|
-
import { AbortError } from '../../public/node/error.js';
|
|
14
|
+
import { AbortError, BugError } from '../../public/node/error.js';
|
|
15
15
|
import { partnersRequest } from '../../public/node/api/partners.js';
|
|
16
16
|
import { normalizeStoreFqdn, partnersFqdn, identityFqdn } from '../../public/node/environment/fqdn.js';
|
|
17
17
|
import { openURL } from '../../public/node/system.js';
|
|
18
|
-
import { Abort, Bug } from '../../error.js';
|
|
19
18
|
import { gql } from 'graphql-request';
|
|
20
19
|
/**
|
|
21
20
|
* This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.
|
|
@@ -140,7 +139,7 @@ async function ensureUserHasPartnerAccount(partnersToken) {
|
|
|
140
139
|
output.warn(output.content `Make sure you've confirmed your Shopify and the Partner organization from the email`);
|
|
141
140
|
await keypress();
|
|
142
141
|
if (!(await hasPartnerAccount(partnersToken))) {
|
|
143
|
-
throw new
|
|
142
|
+
throw new AbortError(`Couldn't find your Shopify Partners organization`, `Have you confirmed your accounts from the emails you received?`);
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
}
|
|
@@ -203,7 +202,7 @@ async function refreshTokens(token, applications, fqdn) {
|
|
|
203
202
|
async function tokensFor(applications, session, fqdn) {
|
|
204
203
|
const fqdnSession = session[fqdn];
|
|
205
204
|
if (!fqdnSession) {
|
|
206
|
-
throw new
|
|
205
|
+
throw new BugError('No session found after ensuring authenticated');
|
|
207
206
|
}
|
|
208
207
|
const tokens = {};
|
|
209
208
|
if (applications.adminApi) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,E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AA;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAA;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IAC3D,MAAM,eAAe,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,CAAA;IAC7D,OAAO,gBAAgB,CAAC,eAAe,CAAC,CAAA;AAC1C,CAAC;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,IAAuB;IAChD,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAA;IAC9C,MAAM,YAAY,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,EAAE,CAAA;IACnD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,IAAI,EAAE,CAAA;IACjE,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC;QACrC,QAAQ,EAAE,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {RequestClientError} from './api/headers.js'\nimport {environmentVariables} from './constants.js'\nimport {content, token, debug} from '../../output.js'\nimport {keypress} from '../../ui.js'\nimport * as output from '../../output.js'\nimport {firstPartyDev, useDeviceAuth} from '../../public/node/environment/local.js'\nimport {AbortError} from '../../public/node/error.js'\nimport {partnersRequest} from '../../public/node/api/partners.js'\nimport {normalizeStoreFqdn, partnersFqdn, identityFqdn} from '../../public/node/environment/fqdn.js'\nimport {openURL} from '../../public/node/system.js'\nimport {Abort, Bug} from '../../error.js'\nimport {gql} from 'graphql-request'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\n\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for. */\n storeFqdn: string\n /** List of scopes to request permissions for. */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param env - Optional environment variables to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n env = process.env,\n forceRefresh = false,\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n debug(content`Validating existing session against the scopes:\n${token.json(scopes)}\nFor applications:\n${token.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n debug(content`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n debug(content`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (error instanceof InvalidRequestError) {\n await secureStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = env[environmentVariables.partnersToken]\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param identityFqdn - The identity FQDN.\n */\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n debug(content`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n debug(content`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n debug(content`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n debug(content`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n debug(content`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n debug(content`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n output.completed('Logged in.')\n\n return session\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n *\n * @param partnersToken - Partners token.\n */\nasync function ensureUserHasPartnerAccount(partnersToken: string) {\n debug(content`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n output.info(`\\nA Shopify Partners organization is needed to proceed.`)\n output.info(`👉 Press any key to create one`)\n await keypress()\n await openURL(`https://${await partnersFqdn()}/signup`)\n output.info(output.content`👉 Press any key when you have ${output.token.cyan('created the organization')}`)\n output.warn(output.content`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw new Abort(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\n }\n }\n}\n\n/**\n * Validate if the current token is valid for partners API.\n *\n * @param partnersToken - Partners token.\n * @returns A promise that resolves to true if the token is valid for partners API.\n */\nasync function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partnersRequest(\n gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n `,\n partnersToken,\n )\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param token - Identity token.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param fqdn - The identity FQDN.\n */\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw new Bug('No session found after ensuring authenticated')\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\n */\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/private/node/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAC,gBAAgB,EAAE,SAAS,EAAC,MAAM,qBAAqB,CAAA;AAC/D,OAAO,EACL,kCAAkC,EAClC,0BAA0B,EAC1B,0BAA0B,EAE1B,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAEhD,OAAO,KAAK,WAAW,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,0BAA0B,EAAE,0BAA0B,EAAC,MAAM,mCAAmC,CAAA;AACxG,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAC,oBAAoB,EAAC,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,MAAM,MAAM,iBAAi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,SAAS,CAAC,UAAU,EAAE,YAAY,CAAC;QAC7C,UAAU,EAAE,SAAS,CAAC,qBAAqB,EAAE,gBAAgB,CAAC;KAC/D,CAAA;AACH,CAAC","sourcesContent":["import {applicationId} from './session/identity.js'\nimport {validateSession} from './session/validate.js'\nimport {allDefaultScopes, apiScopes} from './session/scopes.js'\nimport {\n exchangeAccessForApplicationTokens,\n exchangeCodeForAccessToken,\n exchangeCustomPartnerToken,\n ExchangeScopes,\n refreshAccessToken,\n InvalidGrantError,\n InvalidRequestError,\n} from './session/exchange.js'\nimport {authorize} from './session/authorize.js'\nimport {IdentityToken, Session} from './session/schema.js'\nimport * as secureStore from './session/store.js'\nimport {pollForDeviceAuthorization, requestDeviceAuthorization} from './session/device-authorization.js'\nimport {RequestClientError} from './api/headers.js'\nimport {environmentVariables} from './constants.js'\nimport {content, token, debug} from '../../output.js'\nimport {keypress} from '../../ui.js'\nimport * as output from '../../output.js'\nimport {firstPartyDev, useDeviceAuth} from '../../public/node/environment/local.js'\nimport {AbortError, BugError} from '../../public/node/error.js'\nimport {partnersRequest} from '../../public/node/api/partners.js'\nimport {normalizeStoreFqdn, partnersFqdn, identityFqdn} from '../../public/node/environment/fqdn.js'\nimport {openURL} from '../../public/node/system.js'\nimport {gql} from 'graphql-request'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\n/**\n * A scope supported by the Shopify Admin API.\n */\ntype AdminAPIScope = 'graphql' | 'themes' | 'collaborator' | string\n\n/**\n * It represents the options to authenticate against the Shopify Admin API.\n */\n\ninterface AdminAPIOAuthOptions {\n /** Store to request permissions for. */\n storeFqdn: string\n /** List of scopes to request permissions for. */\n scopes: AdminAPIScope[]\n}\n\n/**\n * A scope supported by the Partners API.\n */\ntype PartnersAPIScope = 'cli' | string\ninterface PartnersAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: PartnersAPIScope[]\n}\n\n/**\n * A scope supported by the Storefront Renderer API.\n */\ntype StorefrontRendererScope = 'devtools' | string\ninterface StorefrontRendererAPIOAuthOptions {\n /** List of scopes to request permissions for. */\n scopes: StorefrontRendererScope[]\n}\n\n/**\n * It represents the authentication requirements and\n * is the input necessary to trigger the authentication\n * flow.\n */\nexport interface OAuthApplications {\n adminApi?: AdminAPIOAuthOptions\n storefrontRendererApi?: StorefrontRendererAPIOAuthOptions\n partnersApi?: PartnersAPIOAuthOptions\n}\n\nexport interface OAuthSession {\n admin?: AdminSession\n partners?: string\n storefront?: string\n}\n\n/**\n * This method ensures that we have a valid session to authenticate against the given applications using the provided scopes.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param env - Optional environment variables to use.\n * @param forceRefresh - Optional flag to force a refresh of the token.\n * @returns An instance with the access tokens organized by application.\n */\nexport async function ensureAuthenticated(\n applications: OAuthApplications,\n env = process.env,\n forceRefresh = false,\n): Promise<OAuthSession> {\n const fqdn = await identityFqdn()\n\n const previousStoreFqdn = applications.adminApi?.storeFqdn\n if (previousStoreFqdn) {\n const normalizedStoreName = await normalizeStoreFqdn(previousStoreFqdn)\n if (previousStoreFqdn === applications.adminApi?.storeFqdn) {\n applications.adminApi.storeFqdn = normalizedStoreName\n }\n }\n\n const currentSession = (await secureStore.fetch()) || {}\n const fqdnSession = currentSession[fqdn]!\n const scopes = getFlattenScopes(applications)\n\n debug(content`Validating existing session against the scopes:\n${token.json(scopes)}\nFor applications:\n${token.json(applications)}\n`)\n const validationResult = await validateSession(scopes, applications, fqdnSession)\n\n let newSession = {}\n\n if (validationResult === 'needs_full_auth') {\n debug(content`Initiating the full authentication flow...`)\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (validationResult === 'needs_refresh' || forceRefresh) {\n debug(content`The current session is valid but needs refresh. Refreshing...`)\n try {\n newSession = await refreshTokens(fqdnSession.identity, applications, fqdn)\n } catch (error) {\n if (error instanceof InvalidGrantError) {\n newSession = await executeCompleteFlow(applications, fqdn)\n } else if (error instanceof InvalidRequestError) {\n await secureStore.remove()\n throw new AbortError('\\nError validating auth session', \"We've cleared the current session, please try again\")\n } else {\n throw error\n }\n }\n }\n\n const completeSession: Session = {...currentSession, ...newSession}\n await secureStore.store(completeSession)\n const tokens = await tokensFor(applications, completeSession, fqdn)\n\n // Overwrite partners token if using a custom CLI Token\n const envToken = env[environmentVariables.partnersToken]\n if (envToken && applications.partnersApi) {\n tokens.partners = (await exchangeCustomPartnerToken(envToken)).accessToken\n }\n if (!envToken && tokens.partners) {\n await ensureUserHasPartnerAccount(tokens.partners)\n }\n\n return tokens\n}\n\n/**\n * Execute the full authentication flow.\n *\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param identityFqdn - The identity FQDN.\n */\nasync function executeCompleteFlow(applications: OAuthApplications, identityFqdn: string): Promise<Session> {\n const scopes = getFlattenScopes(applications)\n const exchangeScopes = getExchangeScopes(applications)\n const store = applications.adminApi?.storeFqdn\n if (firstPartyDev()) {\n debug(content`Authenticating as Shopify Employee...`)\n scopes.push('employee')\n }\n\n let identityToken: IdentityToken\n if (useDeviceAuth()) {\n // Request a device code to authorize without a browser redirect.\n debug(content`Requesting device authorization code...`)\n const deviceAuth = await requestDeviceAuthorization(scopes)\n\n // Poll for the identity token\n debug(content`Starting polling for the identity token...`)\n identityToken = await pollForDeviceAuthorization(deviceAuth.deviceCode, deviceAuth.interval)\n } else {\n // Authorize user via browser\n debug(content`Authorizing through Identity's website...`)\n const code = await authorize(scopes)\n\n // Exchange code for identity token\n debug(content`Authorization code received. Exchanging it for a CLI token...`)\n identityToken = await exchangeCodeForAccessToken(code)\n }\n\n // Exchange identity token for application tokens\n debug(content`CLI token received. Exchanging it for application tokens...`)\n const result = await exchangeAccessForApplicationTokens(identityToken, exchangeScopes, store)\n\n const session: Session = {\n [identityFqdn]: {\n identity: identityToken,\n applications: result,\n },\n }\n\n output.completed('Logged in.')\n\n return session\n}\n\n/**\n * If the user creates an account from the Identity website, the created\n * account won't get a Partner organization created. We need to detect that\n * and take the user to create a partner organization.\n *\n * @param partnersToken - Partners token.\n */\nasync function ensureUserHasPartnerAccount(partnersToken: string) {\n debug(content`Verifying that the user has a Partner organization`)\n if (!(await hasPartnerAccount(partnersToken))) {\n output.info(`\\nA Shopify Partners organization is needed to proceed.`)\n output.info(`👉 Press any key to create one`)\n await keypress()\n await openURL(`https://${await partnersFqdn()}/signup`)\n output.info(output.content`👉 Press any key when you have ${output.token.cyan('created the organization')}`)\n output.warn(output.content`Make sure you've confirmed your Shopify and the Partner organization from the email`)\n await keypress()\n if (!(await hasPartnerAccount(partnersToken))) {\n throw new AbortError(\n `Couldn't find your Shopify Partners organization`,\n `Have you confirmed your accounts from the emails you received?`,\n )\n }\n }\n}\n\n/**\n * Validate if the current token is valid for partners API.\n *\n * @param partnersToken - Partners token.\n * @returns A promise that resolves to true if the token is valid for partners API.\n */\nasync function hasPartnerAccount(partnersToken: string): Promise<boolean> {\n try {\n await partnersRequest(\n gql`\n {\n organizations(first: 1) {\n nodes {\n id\n }\n }\n }\n `,\n partnersToken,\n )\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n if (error instanceof RequestClientError && error.statusCode === 404) {\n return false\n } else {\n return true\n }\n }\n}\n\n/**\n * Refresh the tokens for a given session.\n *\n * @param token - Identity token.\n * @param applications - An object containing the applications we need to be authenticated with.\n * @param fqdn - The identity FQDN.\n */\nasync function refreshTokens(token: IdentityToken, applications: OAuthApplications, fqdn: string): Promise<Session> {\n // Refresh Identity Token\n const identityToken = await refreshAccessToken(token)\n // Exchange new identity token for application tokens\n const exchangeScopes = getExchangeScopes(applications)\n const applicationTokens = await exchangeAccessForApplicationTokens(\n identityToken,\n exchangeScopes,\n applications.adminApi?.storeFqdn,\n )\n\n return {\n [fqdn]: {\n identity: identityToken,\n applications: applicationTokens,\n },\n }\n}\n\n/**\n * Get the application tokens for a given session.\n *\n * @param applications - An object containing the applications we need the tokens for.\n * @param session - The current session.\n * @param fqdn - The identity FQDN.\n */\nasync function tokensFor(applications: OAuthApplications, session: Session, fqdn: string): Promise<OAuthSession> {\n const fqdnSession = session[fqdn]\n if (!fqdnSession) {\n throw new BugError('No session found after ensuring authenticated')\n }\n const tokens: OAuthSession = {}\n if (applications.adminApi) {\n const appId = applicationId('admin')\n const realAppId = `${applications.adminApi.storeFqdn}-${appId}`\n const token = fqdnSession.applications[realAppId]?.accessToken\n if (token) {\n tokens.admin = {token, storeFqdn: applications.adminApi.storeFqdn}\n }\n }\n\n if (applications.partnersApi) {\n const appId = applicationId('partners')\n tokens.partners = fqdnSession.applications[appId]?.accessToken\n }\n\n if (applications.storefrontRendererApi) {\n const appId = applicationId('storefront-renderer')\n tokens.storefront = fqdnSession.applications[appId]?.accessToken\n }\n return tokens\n}\n\n// Scope Helpers\n/**\n * Get a flattened array of scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns A flattened array of scopes.\n */\nfunction getFlattenScopes(apps: OAuthApplications): string[] {\n const admin = apps.adminApi?.scopes || []\n const partner = apps.partnersApi?.scopes || []\n const storefront = apps.storefrontRendererApi?.scopes || []\n const requestedScopes = [...admin, ...partner, ...storefront]\n return allDefaultScopes(requestedScopes)\n}\n\n/**\n * Get the scopes for the given applications.\n *\n * @param apps - An object containing the applications we need the scopes for.\n * @returns An object containing the scopes for each application.\n */\nfunction getExchangeScopes(apps: OAuthApplications): ExchangeScopes {\n const adminScope = apps.adminApi?.scopes || []\n const partnerScope = apps.partnersApi?.scopes || []\n const storefrontScopes = apps.storefrontRendererApi?.scopes || []\n return {\n admin: apiScopes('admin', adminScope),\n partners: apiScopes('partners', partnerScope),\n storefront: apiScopes('storefront-renderer', storefrontScopes),\n }\n}\n"]}
|
|
File without changes
|