@shopify/cli-kit 3.92.1 → 3.93.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/README.md +1 -1
- package/dist/cli/api/graphql/admin/generated/find_development_theme_by_name.d.ts +16 -0
- package/dist/cli/api/graphql/admin/generated/find_development_theme_by_name.js +60 -0
- package/dist/cli/api/graphql/admin/generated/find_development_theme_by_name.js.map +1 -0
- package/dist/private/node/api/graphql.d.ts +10 -0
- package/dist/private/node/api/graphql.js +67 -5
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/conf-store.d.ts +13 -0
- package/dist/private/node/conf-store.js +17 -3
- package/dist/private/node/conf-store.js.map +1 -1
- package/dist/private/node/constants.d.ts +3 -0
- package/dist/private/node/constants.js +3 -0
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/session/exchange.d.ts +22 -8
- package/dist/private/node/session/exchange.js +37 -14
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/schema.d.ts +62 -62
- package/dist/private/node/session/scopes.js +3 -2
- package/dist/private/node/session/scopes.js.map +1 -1
- package/dist/private/node/session/store.d.ts +7 -0
- package/dist/private/node/session/store.js +17 -0
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/session/validate.d.ts +5 -4
- package/dist/private/node/session/validate.js +34 -7
- package/dist/private/node/session/validate.js.map +1 -1
- package/dist/private/node/session.d.ts +1 -1
- package/dist/private/node/session.js +77 -32
- package/dist/private/node/session.js.map +1 -1
- package/dist/private/node/testing/ui.js +6 -4
- package/dist/private/node/testing/ui.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.test.js +5 -5
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.js +5 -2
- package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.test.js +2 -2
- package/dist/private/node/ui/components/ConcurrentOutput.test.js.map +1 -1
- package/dist/private/node/ui/components/SelectInput.test.js +10 -10
- package/dist/private/node/ui/components/SelectInput.test.js.map +1 -1
- package/dist/private/node/ui/components/Table/Table.js +2 -2
- package/dist/private/node/ui/components/Table/Table.js.map +1 -1
- package/dist/private/node/ui/components/Tasks.test.js +6 -6
- package/dist/private/node/ui/components/Tasks.test.js.map +1 -1
- package/dist/private/node/ui/components/TextAnimation.test.js +1 -1
- package/dist/private/node/ui/components/TextAnimation.test.js.map +1 -1
- package/dist/private/node/ui/components/TextInput.test.js +4 -4
- package/dist/private/node/ui/components/TextInput.test.js.map +1 -1
- package/dist/private/node/ui/components/TokenizedText.js +1 -0
- package/dist/private/node/ui/components/TokenizedText.js.map +1 -1
- package/dist/private/node/ui/hooks/use-select-state.js +1 -3
- package/dist/private/node/ui/hooks/use-select-state.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 +4 -4
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.js +1 -3
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/rest-api-throttler.d.ts +14 -0
- package/dist/public/node/api/rest-api-throttler.js +14 -87
- package/dist/public/node/api/rest-api-throttler.js.map +1 -1
- package/dist/public/node/archiver.js +6 -7
- package/dist/public/node/archiver.js.map +1 -1
- package/dist/public/node/cli-launcher.d.ts +1 -1
- package/dist/public/node/cli-launcher.js +9 -9
- package/dist/public/node/cli-launcher.js.map +1 -1
- package/dist/public/node/cli.js +4 -1
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/context/fqdn.js +1 -0
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/context/local.d.ts +7 -0
- package/dist/public/node/context/local.js +9 -0
- package/dist/public/node/context/local.js.map +1 -1
- package/dist/public/node/dot-env.js +1 -1
- package/dist/public/node/dot-env.js.map +1 -1
- package/dist/public/node/environment.d.ts +4 -9
- package/dist/public/node/environment.js +6 -12
- package/dist/public/node/environment.js.map +1 -1
- package/dist/public/node/environments.js +4 -3
- package/dist/public/node/environments.js.map +1 -1
- package/dist/public/node/error-handler.js +1 -1
- package/dist/public/node/error-handler.js.map +1 -1
- package/dist/public/node/error.js +1 -0
- package/dist/public/node/error.js.map +1 -1
- package/dist/public/node/fs.d.ts +9 -1
- package/dist/public/node/fs.js +16 -4
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.d.ts +10 -4
- package/dist/public/node/git.js +101 -80
- package/dist/public/node/git.js.map +1 -1
- package/dist/public/node/global-context.js +1 -3
- package/dist/public/node/global-context.js.map +1 -1
- package/dist/public/node/hooks/postrun.d.ts +7 -0
- package/dist/public/node/hooks/postrun.js +61 -1
- package/dist/public/node/hooks/postrun.js.map +1 -1
- package/dist/public/node/hooks/prerun.d.ts +3 -2
- package/dist/public/node/hooks/prerun.js +9 -22
- package/dist/public/node/hooks/prerun.js.map +1 -1
- package/dist/public/node/http.js +1 -1
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/import-extractor.d.ts +17 -0
- package/dist/public/node/import-extractor.js +84 -23
- package/dist/public/node/import-extractor.js.map +1 -1
- package/dist/public/node/is-global.d.ts +9 -1
- package/dist/public/node/is-global.js +55 -12
- package/dist/public/node/is-global.js.map +1 -1
- package/dist/public/node/mimes.js +1 -1
- package/dist/public/node/mimes.js.map +1 -1
- package/dist/public/node/node-package-manager.d.ts +1 -1
- package/dist/public/node/node-package-manager.js +4 -1
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/os.js +1 -0
- package/dist/public/node/os.js.map +1 -1
- package/dist/public/node/output.js +3 -2
- package/dist/public/node/output.js.map +1 -1
- package/dist/public/node/path.d.ts +11 -0
- package/dist/public/node/path.js +30 -1
- package/dist/public/node/path.js.map +1 -1
- package/dist/public/node/result.js +1 -0
- package/dist/public/node/result.js.map +1 -1
- package/dist/public/node/serial-batch-processor.js +1 -3
- package/dist/public/node/serial-batch-processor.js.map +1 -1
- package/dist/public/node/session-prompt.js +10 -2
- package/dist/public/node/session-prompt.js.map +1 -1
- package/dist/public/node/session.js +6 -6
- package/dist/public/node/session.js.map +1 -1
- package/dist/public/node/themes/api.d.ts +1 -0
- package/dist/public/node/themes/api.js +26 -0
- package/dist/public/node/themes/api.js.map +1 -1
- package/dist/public/node/themes/conf.js +3 -5
- package/dist/public/node/themes/conf.js.map +1 -1
- package/dist/public/node/themes/factories.js +1 -0
- package/dist/public/node/themes/factories.js.map +1 -1
- package/dist/public/node/themes/theme-manager.d.ts +2 -2
- package/dist/public/node/themes/theme-manager.js +13 -8
- package/dist/public/node/themes/theme-manager.js.map +1 -1
- package/dist/public/node/{toml.d.ts → toml/codec.d.ts} +1 -1
- package/dist/public/node/{toml.js → toml/codec.js} +1 -1
- package/dist/public/node/toml/codec.js.map +1 -0
- package/dist/public/node/toml/index.d.ts +1 -0
- package/dist/public/node/toml/index.js +2 -0
- package/dist/public/node/toml/index.js.map +1 -0
- package/dist/public/node/toml/toml-file.d.ts +88 -0
- package/dist/public/node/toml/toml-file.js +159 -0
- package/dist/public/node/toml/toml-file.js.map +1 -0
- package/dist/public/node/tree-kill.js +1 -1
- package/dist/public/node/tree-kill.js.map +1 -1
- package/dist/public/node/ui.js +1 -0
- package/dist/public/node/ui.js.map +1 -1
- package/dist/public/node/upgrade.d.ts +28 -1
- package/dist/public/node/upgrade.js +184 -16
- package/dist/public/node/upgrade.js.map +1 -1
- package/dist/public/node/version.d.ts +9 -0
- package/dist/public/node/version.js +16 -1
- package/dist/public/node/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/dist/public/node/custom-oclif-loader.d.ts +0 -6
- package/dist/public/node/custom-oclif-loader.js +0 -79
- package/dist/public/node/custom-oclif-loader.js.map +0 -1
- package/dist/public/node/toml.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Learn more in the docs: [Create an app](https://shopify.dev/apps/getting-started
|
|
|
37
37
|
|
|
38
38
|
To work with themes, the CLI needs to be installed globally with:
|
|
39
39
|
|
|
40
|
-
- `npm install -g @shopify/cli
|
|
40
|
+
- `npm install -g @shopify/cli`
|
|
41
41
|
|
|
42
42
|
You can also use do it through Homebrew on macOS: `brew tap shopify/shopify && brew install shopify-cli`
|
|
43
43
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Types from './types.js';
|
|
2
|
+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
|
|
3
|
+
export type FindDevelopmentThemeByNameQueryVariables = Types.Exact<{
|
|
4
|
+
name: Types.Scalars['String']['input'];
|
|
5
|
+
}>;
|
|
6
|
+
export type FindDevelopmentThemeByNameQuery = {
|
|
7
|
+
themes?: {
|
|
8
|
+
nodes: {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
role: Types.ThemeRole;
|
|
12
|
+
processing: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
} | null;
|
|
15
|
+
};
|
|
16
|
+
export declare const FindDevelopmentThemeByName: DocumentNode<FindDevelopmentThemeByNameQuery, FindDevelopmentThemeByNameQueryVariables>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export const FindDevelopmentThemeByName = {
|
|
2
|
+
kind: 'Document',
|
|
3
|
+
definitions: [
|
|
4
|
+
{
|
|
5
|
+
kind: 'OperationDefinition',
|
|
6
|
+
operation: 'query',
|
|
7
|
+
name: { kind: 'Name', value: 'findDevelopmentThemeByName' },
|
|
8
|
+
variableDefinitions: [
|
|
9
|
+
{
|
|
10
|
+
kind: 'VariableDefinition',
|
|
11
|
+
variable: { kind: 'Variable', name: { kind: 'Name', value: 'name' } },
|
|
12
|
+
type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } },
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
selectionSet: {
|
|
16
|
+
kind: 'SelectionSet',
|
|
17
|
+
selections: [
|
|
18
|
+
{
|
|
19
|
+
kind: 'Field',
|
|
20
|
+
name: { kind: 'Name', value: 'themes' },
|
|
21
|
+
arguments: [
|
|
22
|
+
{ kind: 'Argument', name: { kind: 'Name', value: 'first' }, value: { kind: 'IntValue', value: '2' } },
|
|
23
|
+
{
|
|
24
|
+
kind: 'Argument',
|
|
25
|
+
name: { kind: 'Name', value: 'names' },
|
|
26
|
+
value: { kind: 'ListValue', values: [{ kind: 'Variable', name: { kind: 'Name', value: 'name' } }] },
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
kind: 'Argument',
|
|
30
|
+
name: { kind: 'Name', value: 'roles' },
|
|
31
|
+
value: { kind: 'ListValue', values: [{ kind: 'EnumValue', value: 'DEVELOPMENT' }] },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
selectionSet: {
|
|
35
|
+
kind: 'SelectionSet',
|
|
36
|
+
selections: [
|
|
37
|
+
{
|
|
38
|
+
kind: 'Field',
|
|
39
|
+
name: { kind: 'Name', value: 'nodes' },
|
|
40
|
+
selectionSet: {
|
|
41
|
+
kind: 'SelectionSet',
|
|
42
|
+
selections: [
|
|
43
|
+
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
|
|
44
|
+
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
|
|
45
|
+
{ kind: 'Field', name: { kind: 'Name', value: 'role' } },
|
|
46
|
+
{ kind: 'Field', name: { kind: 'Name', value: 'processing' } },
|
|
47
|
+
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=find_development_theme_by_name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find_development_theme_by_name.js","sourceRoot":"","sources":["../../../../../../src/cli/api/graphql/admin/generated/find_development_theme_by_name.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE;QACX;YACE,IAAI,EAAE,qBAAqB;YAC3B,SAAS,EAAE,OAAO;YAClB,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,4BAA4B,EAAC;YACzD,mBAAmB,EAAE;gBACnB;oBACE,IAAI,EAAE,oBAAoB;oBAC1B,QAAQ,EAAE,EAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC,EAAC;oBACjE,IAAI,EAAE,EAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,EAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAC,EAAC,EAAC;iBAC9F;aACF;YACD,YAAY,EAAE;gBACZ,IAAI,EAAE,cAAc;gBACpB,UAAU,EAAE;oBACV;wBACE,IAAI,EAAE,OAAO;wBACb,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAC;wBACrC,SAAS,EAAE;4BACT,EAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC,EAAE,KAAK,EAAE,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAC,EAAC;4BAC/F;gCACE,IAAI,EAAE,UAAU;gCAChB,IAAI,EAAE,EAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC;gCACpC,KAAK,EAAE,EAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EAAC,IAA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EAAE,KAAK,EAAE,YAAY,EAAC,EAAC;6BAC3D;yBACF;qBACF;iBACF;aACF;SACF;KACF;CACoG,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions */\nimport * as Types from './types.js'\n\nimport {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/core'\n\nexport type FindDevelopmentThemeByNameQueryVariables = Types.Exact<{\n name: Types.Scalars['String']['input']\n}>\n\nexport type FindDevelopmentThemeByNameQuery = {\n themes?: {nodes: {id: string; name: string; role: Types.ThemeRole; processing: boolean}[]} | null\n}\n\nexport const FindDevelopmentThemeByName = {\n kind: 'Document',\n definitions: [\n {\n kind: 'OperationDefinition',\n operation: 'query',\n name: {kind: 'Name', value: 'findDevelopmentThemeByName'},\n variableDefinitions: [\n {\n kind: 'VariableDefinition',\n variable: {kind: 'Variable', name: {kind: 'Name', value: 'name'}},\n type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},\n },\n ],\n selectionSet: {\n kind: 'SelectionSet',\n selections: [\n {\n kind: 'Field',\n name: {kind: 'Name', value: 'themes'},\n arguments: [\n {kind: 'Argument', name: {kind: 'Name', value: 'first'}, value: {kind: 'IntValue', value: '2'}},\n {\n kind: 'Argument',\n name: {kind: 'Name', value: 'names'},\n value: {kind: 'ListValue', values: [{kind: 'Variable', name: {kind: 'Name', value: 'name'}}]},\n },\n {\n kind: 'Argument',\n name: {kind: 'Name', value: 'roles'},\n value: {kind: 'ListValue', values: [{kind: 'EnumValue', value: 'DEVELOPMENT'}]},\n },\n ],\n selectionSet: {\n kind: 'SelectionSet',\n selections: [\n {\n kind: 'Field',\n name: {kind: 'Name', value: 'nodes'},\n selectionSet: {\n kind: 'SelectionSet',\n selections: [\n {kind: 'Field', name: {kind: 'Name', value: 'id'}},\n {kind: 'Field', name: {kind: 'Name', value: 'name'}},\n {kind: 'Field', name: {kind: 'Name', value: 'role'}},\n {kind: 'Field', name: {kind: 'Name', value: 'processing'}},\n {kind: 'Field', name: {kind: 'Name', value: '__typename'}},\n ],\n },\n },\n {kind: 'Field', name: {kind: 'Name', value: '__typename'}},\n ],\n },\n },\n ],\n },\n },\n ],\n} as unknown as DocumentNode<FindDevelopmentThemeByNameQuery, FindDevelopmentThemeByNameQueryVariables>\n"]}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { Variables } from 'graphql-request';
|
|
2
2
|
export declare function debugLogRequestInfo(api: string, query: string, url: string, variables?: Variables, headers?: Record<string, string>): void;
|
|
3
3
|
export declare function sanitizeVariables(variables: Variables): string;
|
|
4
|
+
/**
|
|
5
|
+
* Extracts human-readable error messages from a GraphQL errors array.
|
|
6
|
+
*
|
|
7
|
+
* Some APIs (e.g. App Management) return structured errors nested inside
|
|
8
|
+
* `extensions.app_errors.errors[].message`. When those are present, we extract
|
|
9
|
+
* them so the CLI displays a clean message instead of a raw JSON dump.
|
|
10
|
+
* Falls back to each error's top-level `message` field, and ultimately to
|
|
11
|
+
* the full JSON representation if no messages can be extracted.
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractGraphQLErrorMessages(errors: any[] | undefined): string | undefined;
|
|
4
14
|
export declare function errorHandler(api: string): (error: unknown, requestId?: string) => unknown;
|
|
@@ -48,19 +48,81 @@ function sanitizeDeepVariables(value, sensitiveKeys) {
|
|
|
48
48
|
}
|
|
49
49
|
return result;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Extracts human-readable error messages from a GraphQL errors array.
|
|
53
|
+
*
|
|
54
|
+
* Some APIs (e.g. App Management) return structured errors nested inside
|
|
55
|
+
* `extensions.app_errors.errors[].message`. When those are present, we extract
|
|
56
|
+
* them so the CLI displays a clean message instead of a raw JSON dump.
|
|
57
|
+
* Falls back to each error's top-level `message` field, and ultimately to
|
|
58
|
+
* the full JSON representation if no messages can be extracted.
|
|
59
|
+
*/
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
|
+
export function extractGraphQLErrorMessages(errors) {
|
|
62
|
+
if (!errors || errors.length === 0)
|
|
63
|
+
return undefined;
|
|
64
|
+
const messages = [];
|
|
65
|
+
for (const error of errors) {
|
|
66
|
+
// Check for nested app_errors (App Management API pattern)
|
|
67
|
+
const appErrors = error?.extensions?.app_errors?.errors;
|
|
68
|
+
if (Array.isArray(appErrors) && appErrors.length > 0) {
|
|
69
|
+
const appMessages = [];
|
|
70
|
+
for (const appError of appErrors) {
|
|
71
|
+
const friendlyMessage = friendlyAppErrorMessage(appError);
|
|
72
|
+
if (friendlyMessage) {
|
|
73
|
+
appMessages.push(friendlyMessage);
|
|
74
|
+
}
|
|
75
|
+
else if (typeof appError?.message === 'string') {
|
|
76
|
+
appMessages.push(appError.message);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Fall back to top-level error message if no app_error messages were extracted
|
|
80
|
+
if (appMessages.length > 0) {
|
|
81
|
+
messages.push(...appMessages);
|
|
82
|
+
}
|
|
83
|
+
else if (typeof error?.message === 'string') {
|
|
84
|
+
messages.push(error.message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// Fall back to top-level error message
|
|
88
|
+
else if (typeof error?.message === 'string') {
|
|
89
|
+
messages.push(error.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return messages.length > 0 ? messages.join('\n') : undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Maps known app_errors categories to user-friendly messages.
|
|
96
|
+
* Returns undefined if the error doesn't match a known pattern.
|
|
97
|
+
*/
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
function friendlyAppErrorMessage(appError) {
|
|
100
|
+
if (appError?.category === 'access_denied') {
|
|
101
|
+
return "You don't have the necessary permissions to perform this action. Check that you're using the correct account or token.";
|
|
102
|
+
}
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
51
105
|
export function errorHandler(api) {
|
|
52
106
|
return (error, requestId) => {
|
|
53
107
|
if (error instanceof ClientError) {
|
|
54
108
|
const { status } = error.response;
|
|
55
|
-
|
|
109
|
+
const extractedMessages = extractGraphQLErrorMessages(error.response.errors);
|
|
110
|
+
let errorMessage;
|
|
111
|
+
if (extractedMessages && status < 500) {
|
|
112
|
+
errorMessage = extractedMessages;
|
|
113
|
+
}
|
|
114
|
+
else if (extractedMessages && status >= 500) {
|
|
115
|
+
errorMessage = `The ${api} GraphQL API responded with HTTP status ${status}: ${extractedMessages}`;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
errorMessage = stringifyMessage(outputContent `
|
|
56
119
|
The ${outputToken.raw(api)} GraphQL API responded unsuccessfully with${status === 200 ? '' : ` the HTTP status ${status} and`} errors:
|
|
57
120
|
|
|
58
121
|
${outputToken.json(error.response.errors)}
|
|
59
|
-
|
|
122
|
+
`);
|
|
123
|
+
}
|
|
60
124
|
if (requestId) {
|
|
61
|
-
errorMessage +=
|
|
62
|
-
Request ID: ${requestId}
|
|
63
|
-
`;
|
|
125
|
+
errorMessage += `\n\nRequest ID: ${requestId}`;
|
|
64
126
|
}
|
|
65
127
|
let mappedError;
|
|
66
128
|
if (status < 500) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AACrC,OAAO,EAAC,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACxG,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAA;AAExD,OAAO,EAAC,WAAW,EAAY,MAAM,iBAAiB,CAAA;AAEtD,MAAM,UAAU,mBAAmB,CACjC,GAAW,EACX,KAAa,EACb,GAAW,EACX,SAAqB,EACrB,UAAkC,EAAE;IAEpC,WAAW,CAAC,aAAa,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,GAAG,EAAE,CAAC;gBACjB,WAAW,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YACnF,CAAC;iBAAM,CAAC;gBACN,WAAW,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YAC5C,CAAC;YACD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YAC/B,OAAO,WAAW,CAAA;QACpB,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {GraphQLClientError, sanitizedHeadersOutput} from './headers.js'\nimport {sanitizeURL} from './urls.js'\nimport {stringifyMessage, outputContent, outputToken, outputDebug} from '../../../public/node/output.js'\nimport {AbortError} from '../../../public/node/error.js'\n\nimport {ClientError, Variables} from 'graphql-request'\n\nexport function debugLogRequestInfo(\n api: string,\n query: string,\n url: string,\n variables?: Variables,\n headers: Record<string, string> = {},\n) {\n outputDebug(outputContent`Sending ${outputToken.json(api)} GraphQL request:\n ${outputToken.raw(query.toString().trim())}\n${variables ? `\\nWith variables:\\n${sanitizeVariables(variables)}\\n` : ''}\nWith request headers:\n${sanitizedHeadersOutput(headers)}\\n\nto ${sanitizeURL(url)}`)\n}\n\nexport function sanitizeVariables(variables: Variables): string {\n const result: Variables = {...variables}\n const sensitiveKeys = ['apiKey', 'serialized_script']\n\n const sanitizedResult = sanitizeDeepVariables(result, sensitiveKeys)\n\n return JSON.stringify(sanitizedResult, null, 2)\n}\n\nfunction sanitizeDeepVariables(value: unknown, sensitiveKeys: string[]): unknown {\n // Checking for JSON\n if (typeof value === 'string') {\n try {\n const parsed = JSON.parse(value)\n if (typeof parsed === 'object' && parsed !== null) {\n const sanitized = sanitizeDeepVariables(parsed, sensitiveKeys)\n return JSON.stringify(sanitized, null)\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return value\n }\n }\n\n if (typeof value !== 'object' || value === null) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => sanitizeDeepVariables(item, sensitiveKeys))\n }\n\n const result: Variables = {}\n\n for (const [key, val] of Object.entries(value)) {\n if (sensitiveKeys.includes(key) && typeof val === 'string') {\n result[key] = '*****'\n continue\n }\n\n result[key] = sanitizeDeepVariables(val, sensitiveKeys)\n }\n\n return result\n}\n\nexport function errorHandler(api: string): (error: unknown, requestId?: string) => unknown {\n return (error: unknown, requestId?: string) => {\n if (error instanceof ClientError) {\n const {status} = error.response\n let errorMessage = stringifyMessage(outputContent`\nThe ${outputToken.raw(api)} GraphQL API responded unsuccessfully with${\n status === 200 ? '' : ` the HTTP status ${status} and`\n } errors:\n\n${outputToken.json(error.response.errors)}\n `)\n if (requestId) {\n errorMessage += `\nRequest ID: ${requestId}\n`\n }\n let mappedError: Error\n if (status < 500) {\n mappedError = new GraphQLClientError(errorMessage, status, error.response.errors)\n } else {\n mappedError = new AbortError(errorMessage)\n }\n mappedError.stack = error.stack\n return mappedError\n } else {\n return error\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../../src/private/node/api/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,cAAc,CAAA;AACvE,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AACrC,OAAO,EAAC,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,gCAAgC,CAAA;AACxG,OAAO,EAAC,UAAU,EAAC,MAAM,+BAA+B,CAAA;AAExD,OAAO,EAAC,WAAW,EAAY,MAAM,iBAAiB,CAAA;AAEtD,MAAM,UAAU,mBAAmB,CACjC,GAAW,EACX,KAAa,EACb,GAAW,EACX,SAAqB,EACrB,UAAkC,EAAE;IAEpC,WAAW,CAAC,aAAa,CAAA,WAAW,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC;IACvD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,CAAA;YAE5E,IAAI,YAAoB,CAAA;YACxB,IAAI,iBAAiB,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;gBACtC,YAAY,GAAG,iBAAiB,CAAA;YAClC,CAAC;iBAAM,IAAI,iBAAiB,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;gBAC9C,YAAY,GAAG,OAAO,GAAG,2CAA2C,MAAM,KAAK,iBAAiB,EAAE,CAAA;YACpG,CAAC;iBAAM,CAAC;gBACN,YAAY,GAAG,gBAAgB,CAAC,aAAa,CAAA;MAC/C,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,6CAChB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,oBAAoB,MAAM,MAClD;;EAEN,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;SAChC,CAAC,CAAA;YACJ,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACd,YAAY,IAAI,mBAAmB,SAAS,EAAE,CAAA;YAChD,CAAC;YACD,IAAI,WAAkB,CAAA;YACtB,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;gBACjB,WAAW,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YACnF,CAAC;iBAAM,CAAC;gBACN,WAAW,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,CAAA;YAC5C,CAAC;YACD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;YAC/B,OAAO,WAAW,CAAA;QACpB,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {GraphQLClientError, sanitizedHeadersOutput} from './headers.js'\nimport {sanitizeURL} from './urls.js'\nimport {stringifyMessage, outputContent, outputToken, outputDebug} from '../../../public/node/output.js'\nimport {AbortError} from '../../../public/node/error.js'\n\nimport {ClientError, Variables} from 'graphql-request'\n\nexport function debugLogRequestInfo(\n api: string,\n query: string,\n url: string,\n variables?: Variables,\n headers: Record<string, string> = {},\n) {\n outputDebug(outputContent`Sending ${outputToken.json(api)} GraphQL request:\n ${outputToken.raw(query.toString().trim())}\n${variables ? `\\nWith variables:\\n${sanitizeVariables(variables)}\\n` : ''}\nWith request headers:\n${sanitizedHeadersOutput(headers)}\\n\nto ${sanitizeURL(url)}`)\n}\n\nexport function sanitizeVariables(variables: Variables): string {\n const result: Variables = {...variables}\n const sensitiveKeys = ['apiKey', 'serialized_script']\n\n const sanitizedResult = sanitizeDeepVariables(result, sensitiveKeys)\n\n return JSON.stringify(sanitizedResult, null, 2)\n}\n\nfunction sanitizeDeepVariables(value: unknown, sensitiveKeys: string[]): unknown {\n // Checking for JSON\n if (typeof value === 'string') {\n try {\n const parsed = JSON.parse(value)\n if (typeof parsed === 'object' && parsed !== null) {\n const sanitized = sanitizeDeepVariables(parsed, sensitiveKeys)\n return JSON.stringify(sanitized, null)\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return value\n }\n }\n\n if (typeof value !== 'object' || value === null) {\n return value\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => sanitizeDeepVariables(item, sensitiveKeys))\n }\n\n const result: Variables = {}\n\n for (const [key, val] of Object.entries(value)) {\n if (sensitiveKeys.includes(key) && typeof val === 'string') {\n result[key] = '*****'\n continue\n }\n\n result[key] = sanitizeDeepVariables(val, sensitiveKeys)\n }\n\n return result\n}\n\n/**\n * Extracts human-readable error messages from a GraphQL errors array.\n *\n * Some APIs (e.g. App Management) return structured errors nested inside\n * `extensions.app_errors.errors[].message`. When those are present, we extract\n * them so the CLI displays a clean message instead of a raw JSON dump.\n * Falls back to each error's top-level `message` field, and ultimately to\n * the full JSON representation if no messages can be extracted.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function extractGraphQLErrorMessages(errors: any[] | undefined): string | undefined {\n if (!errors || errors.length === 0) return undefined\n\n const messages: string[] = []\n\n for (const error of errors) {\n // Check for nested app_errors (App Management API pattern)\n const appErrors = error?.extensions?.app_errors?.errors\n if (Array.isArray(appErrors) && appErrors.length > 0) {\n const appMessages: string[] = []\n for (const appError of appErrors) {\n const friendlyMessage = friendlyAppErrorMessage(appError)\n if (friendlyMessage) {\n appMessages.push(friendlyMessage)\n } else if (typeof appError?.message === 'string') {\n appMessages.push(appError.message)\n }\n }\n // Fall back to top-level error message if no app_error messages were extracted\n if (appMessages.length > 0) {\n messages.push(...appMessages)\n } else if (typeof error?.message === 'string') {\n messages.push(error.message)\n }\n }\n // Fall back to top-level error message\n else if (typeof error?.message === 'string') {\n messages.push(error.message)\n }\n }\n\n return messages.length > 0 ? messages.join('\\n') : undefined\n}\n\n/**\n * Maps known app_errors categories to user-friendly messages.\n * Returns undefined if the error doesn't match a known pattern.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction friendlyAppErrorMessage(appError: any): string | undefined {\n if (appError?.category === 'access_denied') {\n return \"You don't have the necessary permissions to perform this action. Check that you're using the correct account or token.\"\n }\n return undefined\n}\n\nexport function errorHandler(api: string): (error: unknown, requestId?: string) => unknown {\n return (error: unknown, requestId?: string) => {\n if (error instanceof ClientError) {\n const {status} = error.response\n\n const extractedMessages = extractGraphQLErrorMessages(error.response.errors)\n\n let errorMessage: string\n if (extractedMessages && status < 500) {\n errorMessage = extractedMessages\n } else if (extractedMessages && status >= 500) {\n errorMessage = `The ${api} GraphQL API responded with HTTP status ${status}: ${extractedMessages}`\n } else {\n errorMessage = stringifyMessage(outputContent`\nThe ${outputToken.raw(api)} GraphQL API responded unsuccessfully with${\n status === 200 ? '' : ` the HTTP status ${status} and`\n } errors:\n\n${outputToken.json(error.response.errors)}\n `)\n }\n if (requestId) {\n errorMessage += `\\n\\nRequest ID: ${requestId}`\n }\n let mappedError: Error\n if (status < 500) {\n mappedError = new GraphQLClientError(errorMessage, status, error.response.errors)\n } else {\n mappedError = new AbortError(errorMessage)\n }\n mappedError.stack = error.stack\n return mappedError\n } else {\n return error\n }\n }\n}\n"]}
|
|
@@ -24,6 +24,7 @@ export interface ConfSchema {
|
|
|
24
24
|
devSessionStore?: string;
|
|
25
25
|
currentDevSessionId?: string;
|
|
26
26
|
cache?: Cache;
|
|
27
|
+
autoUpgradeEnabled?: boolean;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* Get session.
|
|
@@ -125,6 +126,18 @@ interface RunWithRateLimitOptions {
|
|
|
125
126
|
* @returns true, or undefined if the task was not run.
|
|
126
127
|
*/
|
|
127
128
|
export declare function runWithRateLimit(options: RunWithRateLimitOptions, config?: LocalStorage<ConfSchema>): Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Get auto-upgrade preference.
|
|
131
|
+
*
|
|
132
|
+
* @returns Whether auto-upgrade is enabled, or undefined if never set.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getAutoUpgradeEnabled(config?: LocalStorage<ConfSchema>): boolean | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Set auto-upgrade preference.
|
|
137
|
+
*
|
|
138
|
+
* @param enabled - Whether auto-upgrade should be enabled.
|
|
139
|
+
*/
|
|
140
|
+
export declare function setAutoUpgradeEnabled(enabled: boolean, config?: LocalStorage<ConfSchema>): void;
|
|
128
141
|
export declare function getConfigStoreForPartnerStatus(): LocalStorage<Record<string, {
|
|
129
142
|
status: true;
|
|
130
143
|
checkedAt: string;
|
|
@@ -9,9 +9,7 @@ let _instance;
|
|
|
9
9
|
* @returns CLIKitStore.
|
|
10
10
|
*/
|
|
11
11
|
function cliKitStore() {
|
|
12
|
-
|
|
13
|
-
_instance = new LocalStorage({ projectName: `shopify-cli-kit${isUnitTest() ? '-test' : ''}` });
|
|
14
|
-
}
|
|
12
|
+
_instance ?? (_instance = new LocalStorage({ projectName: `shopify-cli-kit${isUnitTest() ? '-test' : ''}` }));
|
|
15
13
|
return _instance;
|
|
16
14
|
}
|
|
17
15
|
function sessionStoreKey() {
|
|
@@ -167,6 +165,22 @@ export async function runWithRateLimit(options, config = cliKitStore()) {
|
|
|
167
165
|
config.set('cache', cache);
|
|
168
166
|
return true;
|
|
169
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Get auto-upgrade preference.
|
|
170
|
+
*
|
|
171
|
+
* @returns Whether auto-upgrade is enabled, or undefined if never set.
|
|
172
|
+
*/
|
|
173
|
+
export function getAutoUpgradeEnabled(config = cliKitStore()) {
|
|
174
|
+
return config.get('autoUpgradeEnabled');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Set auto-upgrade preference.
|
|
178
|
+
*
|
|
179
|
+
* @param enabled - Whether auto-upgrade should be enabled.
|
|
180
|
+
*/
|
|
181
|
+
export function setAutoUpgradeEnabled(enabled, config = cliKitStore()) {
|
|
182
|
+
config.set('autoUpgradeEnabled', enabled);
|
|
183
|
+
}
|
|
170
184
|
export function getConfigStoreForPartnerStatus() {
|
|
171
185
|
return new LocalStorage({
|
|
172
186
|
projectName: 'shopify-cli-kit-partner-status',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conf-store.js","sourceRoot":"","sources":["../../../src/private/node/conf-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAiCtE,IAAI,SAA+C,CAAA;AAEnD;;;;GAIG;AACH,SAAS,WAAW;IAClB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,SAAS,GAAG,IAAI,YAAY,CAAa,EAAC,WAAW,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,EAAC,CAAC,CAAA;IAC1G,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AAE,SAAS,EAAE,GAAG,EAAC,CAAA;IAClD,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAE1B,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,OAAO,IAAI,YAAY,CAAoD;QACzE,WAAW,EAAE,gCAAgC;KAC9C,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,aAAqB;IACjE,IAAI,CAAC,aAAa;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,KAAK,GAAG,8BAA8B,EAAE,CAAA;IAE9C,MAAM,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAClD,IAAI,iBAAiB,EAAE,CAAC;QACtB,6BAA6B;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,aAAqB;IACjE,MAAM,KAAK,GAAG,8BAA8B,EAAE,CAAA;IAE9C,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAC,CAAC,CAAA;AAC/E,CAAC","sourcesContent":["import {isLocalEnvironment} from './context/service.js'\nimport {isUnitTest} from '../../public/node/context/local.js'\nimport {LocalStorage} from '../../public/node/local-storage.js'\nimport {outputContent, outputDebug} from '../../public/node/output.js'\n\ninterface CacheValue<T> {\n value: T\n timestamp: number\n}\n\nexport type PackageVersionKey = `npm-package-${string}`\nexport type NotificationsKey = `notifications-${string}`\nexport type NotificationKey = `notification-${string}`\nexport type GraphQLRequestKey = `q-${string}-${string}-${string}`\ntype MostRecentOccurrenceKey = `most-recent-occurrence-${string}`\ntype RateLimitKey = `rate-limited-occurrences-${string}`\n\ntype ExportedKey = PackageVersionKey | NotificationsKey | NotificationKey | GraphQLRequestKey\n\ninterface Cache {\n [packageVersionKey: PackageVersionKey]: CacheValue<string>\n [notifications: NotificationsKey]: CacheValue<string>\n [notification: NotificationKey]: CacheValue<string>\n [graphQLRequestKey: GraphQLRequestKey]: CacheValue<string>\n [mostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>\n [rateLimitKey: RateLimitKey]: CacheValue<number[]>\n}\n\nexport interface ConfSchema {\n sessionStore: string\n currentSessionId?: string\n devSessionStore?: string\n currentDevSessionId?: string\n cache?: Cache\n}\n\nlet _instance: LocalStorage<ConfSchema> | undefined\n\n/**\n * CLIKIT Store.\n *\n * @returns CLIKitStore.\n */\nfunction cliKitStore() {\n if (!_instance) {\n _instance = new LocalStorage<ConfSchema>({projectName: `shopify-cli-kit${isUnitTest() ? '-test' : ''}`})\n }\n return _instance\n}\n\nfunction sessionStoreKey(): 'devSessionStore' | 'sessionStore' {\n return isLocalEnvironment() ? 'devSessionStore' : 'sessionStore'\n}\n\nfunction currentSessionIdKey(): 'currentDevSessionId' | 'currentSessionId' {\n return isLocalEnvironment() ? 'currentDevSessionId' : 'currentSessionId'\n}\n\n/**\n * Get session.\n *\n * @returns Session.\n */\nexport function getSessions(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting session store...`)\n return config.get(sessionStoreKey())\n}\n\n/**\n * Set session.\n *\n * @param session - Session.\n */\nexport function setSessions(session: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting session store...`)\n config.set(sessionStoreKey(), session)\n}\n\n/**\n * Remove session.\n */\nexport function removeSessions(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing session store...`)\n config.delete(sessionStoreKey())\n}\n\n/**\n * Get current session ID.\n *\n * @returns Current session ID.\n */\nexport function getCurrentSessionId(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting current session ID...`)\n return config.get(currentSessionIdKey())\n}\n\n/**\n * Set current session ID.\n *\n * @param sessionId - Session ID.\n */\nexport function setCurrentSessionId(sessionId: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting current session ID...`)\n config.set(currentSessionIdKey(), sessionId)\n}\n\n/**\n * Remove current session ID.\n */\nexport function removeCurrentSessionId(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing current session ID...`)\n config.delete(currentSessionIdKey())\n}\n\ntype CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['value']\n\n/**\n * Fetch from cache, or run the provided function to get the value, and cache it\n * before returning it.\n * @param key - The key to use for the cache.\n * @param fn - The function to run to get the value to cache, if a cache miss occurs.\n * @param timeout - The maximum valid age of a cached value, in milliseconds.\n * If the cached value is older than this, it will be refreshed.\n * @returns The value from the cache or the result of the function.\n */\nexport async function cacheRetrieveOrRepopulate(\n key: ExportedKey,\n fn: () => Promise<CacheValueForKey<typeof key>>,\n timeout?: number,\n config = cliKitStore(),\n): Promise<CacheValueForKey<typeof key>> {\n const cached = cacheRetrieve(key, config)\n\n if (cached?.value !== undefined && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {\n return cached.value\n }\n\n const value = await fn()\n cacheStore(key, value, config)\n return value\n}\n\nexport function cacheStore(key: ExportedKey, value: string, config = cliKitStore()): void {\n const cache: Cache = config.get('cache') ?? {}\n cache[key] = {value, timestamp: Date.now()}\n config.set('cache', cache)\n}\n\n/**\n * Fetch from cache if already populated, otherwise return undefined.\n * @param key - The key to use for the cache.\n * @returns The chache element.\n */\nexport function cacheRetrieve(key: ExportedKey, config = cliKitStore()): CacheValue<string> | undefined {\n const cache: Cache = config.get('cache') ?? {}\n return cache[key]\n}\n\nexport function cacheClear(config = cliKitStore()): void {\n config.delete('cache')\n}\n\nexport interface TimeInterval {\n days?: number\n hours?: number\n minutes?: number\n seconds?: number\n}\n\nexport function timeIntervalToMilliseconds({days = 0, hours = 0, minutes = 0, seconds = 0}: TimeInterval): number {\n return (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds) * 1000\n}\n\n/**\n * Execute a task only if the most recent occurrence of the task is older than the specified timeout.\n * @param key - The key to use for the cache.\n * @param timeout - The maximum valid age of the most recent occurrence, expressed as an object with\n * days, hours, minutes, and seconds properties.\n * If the most recent occurrence is older than this, the task will be executed.\n * @param task - The task to run if the most recent occurrence is older than the timeout.\n * @returns true if the task was run, or false if the task was not run.\n */\nexport async function runAtMinimumInterval(\n key: string,\n timeout: TimeInterval,\n task: () => Promise<void>,\n config = cliKitStore(),\n): Promise<boolean> {\n const cache: Cache = config.get('cache') ?? {}\n const cacheKey: MostRecentOccurrenceKey = `most-recent-occurrence-${key}`\n const cached = cache[cacheKey]\n\n if (cached?.value !== undefined && Date.now() - cached.timestamp < timeIntervalToMilliseconds(timeout)) {\n return false\n }\n\n await task()\n cache[cacheKey] = {value: true, timestamp: Date.now()}\n config.set('cache', cache)\n return true\n}\n\ninterface RunWithRateLimitOptions {\n /**\n * The key to use for the cache.\n */\n key: string\n\n /**\n * The number of times the task can be run within the limit\n */\n limit: number\n\n /**\n * The window of time after which the rate limit is refreshed,\n * expressed as an object with days, hours, minutes, and seconds properties.\n * If the most recent occurrence is older than this, the task will be executed.\n */\n timeout: TimeInterval\n\n /**\n * The task to run if the most recent occurrence is older than the timeout.\n */\n task: () => Promise<void>\n}\n\n/**\n * Execute a task with a time-based rate limit. The rate limit is enforced by\n * checking how many times that task has been executed in a window of time ending\n * at the current time. If the task has been executed more than the allowed number\n * of times in that window, the task will not be executed.\n *\n * Note that this function has side effects, as it will also remove events prior\n * to the window of time that is being checked.\n * @param options - The options for the rate limiting.\n * @returns true, or undefined if the task was not run.\n */\nexport async function runWithRateLimit(options: RunWithRateLimitOptions, config = cliKitStore()): Promise<boolean> {\n const {key, limit, timeout, task} = options\n const cache: Cache = config.get('cache') ?? {}\n const cacheKey: RateLimitKey = `rate-limited-occurrences-${key}`\n const cached = cache[cacheKey]\n const now = Date.now()\n\n if (cached?.value) {\n // First sweep through the cache and eliminate old events\n const windowStart = now - timeIntervalToMilliseconds(timeout)\n const occurrences = cached.value.filter((occurrence) => occurrence >= windowStart)\n\n // Now check that the number of occurrences within the interval is below the limit\n if (occurrences.length >= limit) {\n // First remove the old occurrences from the cache\n cache[cacheKey] = {value: occurrences, timestamp: Date.now()}\n config.set('cache', cache)\n\n return false\n }\n\n await task()\n cache[cacheKey] = {value: [...occurrences, now], timestamp: now}\n } else {\n await task()\n cache[cacheKey] = {value: [now], timestamp: now}\n }\n config.set('cache', cache)\n\n return true\n}\n\nexport function getConfigStoreForPartnerStatus() {\n return new LocalStorage<Record<string, {status: true; checkedAt: string}>>({\n projectName: 'shopify-cli-kit-partner-status',\n })\n}\n\nexport function getCachedPartnerAccountStatus(partnersToken: string): true | null {\n if (!partnersToken) return null\n const store = getConfigStoreForPartnerStatus()\n\n const hasPartnerAccount = store.get(partnersToken)\n if (hasPartnerAccount) {\n // this never needs to expire\n return true\n }\n return null\n}\n\nexport function setCachedPartnerAccountStatus(partnersToken: string) {\n const store = getConfigStoreForPartnerStatus()\n\n store.set(partnersToken, {status: true, checkedAt: new Date().toISOString()})\n}\n"]}
|
|
1
|
+
{"version":3,"file":"conf-store.js","sourceRoot":"","sources":["../../../src/private/node/conf-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAC,UAAU,EAAC,MAAM,oCAAoC,CAAA;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,oCAAoC,CAAA;AAC/D,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAkCtE,IAAI,SAA+C,CAAA;AAEnD;;;;GAIG;AACH,SAAS,WAAW;IAClB,SAAS,KAAT,SAAS,GAAK,IAAI,YAAY,CAAa,EAAC,WAAW,EAAE,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,E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GAAG,CAAC,EAAE,SAAS,EAAE,GAAG,EAAC,CAAA;IAClD,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAE1B,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAmC,WAAW,EAAE;IACpF,OAAO,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB,EAAE,SAAmC,WAAW,EAAE;IACtG,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAA;AAC3C,CAAC;AAED,MAAM,UAAU,8BAA8B;IAC5C,OAAO,IAAI,YAAY,CAAoD;QACzE,WAAW,EAAE,gCAAgC;KAC9C,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,aAAqB;IACjE,IAAI,CAAC,aAAa;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,KAAK,GAAG,8BAA8B,EAAE,CAAA;IAE9C,MAAM,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;IAClD,IAAI,iBAAiB,EAAE,CAAC;QACtB,6BAA6B;QAC7B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,6BAA6B,CAAC,aAAqB;IACjE,MAAM,KAAK,GAAG,8BAA8B,EAAE,CAAA;IAE9C,KAAK,CAAC,GAAG,CAAC,aAAa,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAC,CAAC,CAAA;AAC/E,CAAC","sourcesContent":["import {isLocalEnvironment} from './context/service.js'\nimport {isUnitTest} from '../../public/node/context/local.js'\nimport {LocalStorage} from '../../public/node/local-storage.js'\nimport {outputContent, outputDebug} from '../../public/node/output.js'\n\ninterface CacheValue<T> {\n value: T\n timestamp: number\n}\n\nexport type PackageVersionKey = `npm-package-${string}`\nexport type NotificationsKey = `notifications-${string}`\nexport type NotificationKey = `notification-${string}`\nexport type GraphQLRequestKey = `q-${string}-${string}-${string}`\ntype MostRecentOccurrenceKey = `most-recent-occurrence-${string}`\ntype RateLimitKey = `rate-limited-occurrences-${string}`\n\ntype ExportedKey = PackageVersionKey | NotificationsKey | NotificationKey | GraphQLRequestKey\n\ninterface Cache {\n [packageVersionKey: PackageVersionKey]: CacheValue<string>\n [notifications: NotificationsKey]: CacheValue<string>\n [notification: NotificationKey]: CacheValue<string>\n [graphQLRequestKey: GraphQLRequestKey]: CacheValue<string>\n [mostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>\n [rateLimitKey: RateLimitKey]: CacheValue<number[]>\n}\n\nexport interface ConfSchema {\n sessionStore: string\n currentSessionId?: string\n devSessionStore?: string\n currentDevSessionId?: string\n cache?: Cache\n autoUpgradeEnabled?: boolean\n}\n\nlet _instance: LocalStorage<ConfSchema> | undefined\n\n/**\n * CLIKIT Store.\n *\n * @returns CLIKitStore.\n */\nfunction cliKitStore() {\n _instance ??= new LocalStorage<ConfSchema>({projectName: `shopify-cli-kit${isUnitTest() ? '-test' : ''}`})\n return _instance\n}\n\nfunction sessionStoreKey(): 'devSessionStore' | 'sessionStore' {\n return isLocalEnvironment() ? 'devSessionStore' : 'sessionStore'\n}\n\nfunction currentSessionIdKey(): 'currentDevSessionId' | 'currentSessionId' {\n return isLocalEnvironment() ? 'currentDevSessionId' : 'currentSessionId'\n}\n\n/**\n * Get session.\n *\n * @returns Session.\n */\nexport function getSessions(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting session store...`)\n return config.get(sessionStoreKey())\n}\n\n/**\n * Set session.\n *\n * @param session - Session.\n */\nexport function setSessions(session: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting session store...`)\n config.set(sessionStoreKey(), session)\n}\n\n/**\n * Remove session.\n */\nexport function removeSessions(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing session store...`)\n config.delete(sessionStoreKey())\n}\n\n/**\n * Get current session ID.\n *\n * @returns Current session ID.\n */\nexport function getCurrentSessionId(config: LocalStorage<ConfSchema> = cliKitStore()): string | undefined {\n outputDebug(outputContent`Getting current session ID...`)\n return config.get(currentSessionIdKey())\n}\n\n/**\n * Set current session ID.\n *\n * @param sessionId - Session ID.\n */\nexport function setCurrentSessionId(sessionId: string, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Setting current session ID...`)\n config.set(currentSessionIdKey(), sessionId)\n}\n\n/**\n * Remove current session ID.\n */\nexport function removeCurrentSessionId(config: LocalStorage<ConfSchema> = cliKitStore()): void {\n outputDebug(outputContent`Removing current session ID...`)\n config.delete(currentSessionIdKey())\n}\n\ntype CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['value']\n\n/**\n * Fetch from cache, or run the provided function to get the value, and cache it\n * before returning it.\n * @param key - The key to use for the cache.\n * @param fn - The function to run to get the value to cache, if a cache miss occurs.\n * @param timeout - The maximum valid age of a cached value, in milliseconds.\n * If the cached value is older than this, it will be refreshed.\n * @returns The value from the cache or the result of the function.\n */\nexport async function cacheRetrieveOrRepopulate(\n key: ExportedKey,\n fn: () => Promise<CacheValueForKey<typeof key>>,\n timeout?: number,\n config = cliKitStore(),\n): Promise<CacheValueForKey<typeof key>> {\n const cached = cacheRetrieve(key, config)\n\n if (cached?.value !== undefined && (timeout === undefined || Date.now() - cached.timestamp < timeout)) {\n return cached.value\n }\n\n const value = await fn()\n cacheStore(key, value, config)\n return value\n}\n\nexport function cacheStore(key: ExportedKey, value: string, config = cliKitStore()): void {\n const cache: Cache = config.get('cache') ?? {}\n cache[key] = {value, timestamp: Date.now()}\n config.set('cache', cache)\n}\n\n/**\n * Fetch from cache if already populated, otherwise return undefined.\n * @param key - The key to use for the cache.\n * @returns The chache element.\n */\nexport function cacheRetrieve(key: ExportedKey, config = cliKitStore()): CacheValue<string> | undefined {\n const cache: Cache = config.get('cache') ?? {}\n return cache[key]\n}\n\nexport function cacheClear(config = cliKitStore()): void {\n config.delete('cache')\n}\n\nexport interface TimeInterval {\n days?: number\n hours?: number\n minutes?: number\n seconds?: number\n}\n\nexport function timeIntervalToMilliseconds({days = 0, hours = 0, minutes = 0, seconds = 0}: TimeInterval): number {\n return (days * 24 * 60 * 60 + hours * 60 * 60 + minutes * 60 + seconds) * 1000\n}\n\n/**\n * Execute a task only if the most recent occurrence of the task is older than the specified timeout.\n * @param key - The key to use for the cache.\n * @param timeout - The maximum valid age of the most recent occurrence, expressed as an object with\n * days, hours, minutes, and seconds properties.\n * If the most recent occurrence is older than this, the task will be executed.\n * @param task - The task to run if the most recent occurrence is older than the timeout.\n * @returns true if the task was run, or false if the task was not run.\n */\nexport async function runAtMinimumInterval(\n key: string,\n timeout: TimeInterval,\n task: () => Promise<void>,\n config = cliKitStore(),\n): Promise<boolean> {\n const cache: Cache = config.get('cache') ?? {}\n const cacheKey: MostRecentOccurrenceKey = `most-recent-occurrence-${key}`\n const cached = cache[cacheKey]\n\n if (cached?.value !== undefined && Date.now() - cached.timestamp < timeIntervalToMilliseconds(timeout)) {\n return false\n }\n\n await task()\n cache[cacheKey] = {value: true, timestamp: Date.now()}\n config.set('cache', cache)\n return true\n}\n\ninterface RunWithRateLimitOptions {\n /**\n * The key to use for the cache.\n */\n key: string\n\n /**\n * The number of times the task can be run within the limit\n */\n limit: number\n\n /**\n * The window of time after which the rate limit is refreshed,\n * expressed as an object with days, hours, minutes, and seconds properties.\n * If the most recent occurrence is older than this, the task will be executed.\n */\n timeout: TimeInterval\n\n /**\n * The task to run if the most recent occurrence is older than the timeout.\n */\n task: () => Promise<void>\n}\n\n/**\n * Execute a task with a time-based rate limit. The rate limit is enforced by\n * checking how many times that task has been executed in a window of time ending\n * at the current time. If the task has been executed more than the allowed number\n * of times in that window, the task will not be executed.\n *\n * Note that this function has side effects, as it will also remove events prior\n * to the window of time that is being checked.\n * @param options - The options for the rate limiting.\n * @returns true, or undefined if the task was not run.\n */\nexport async function runWithRateLimit(options: RunWithRateLimitOptions, config = cliKitStore()): Promise<boolean> {\n const {key, limit, timeout, task} = options\n const cache: Cache = config.get('cache') ?? {}\n const cacheKey: RateLimitKey = `rate-limited-occurrences-${key}`\n const cached = cache[cacheKey]\n const now = Date.now()\n\n if (cached?.value) {\n // First sweep through the cache and eliminate old events\n const windowStart = now - timeIntervalToMilliseconds(timeout)\n const occurrences = cached.value.filter((occurrence) => occurrence >= windowStart)\n\n // Now check that the number of occurrences within the interval is below the limit\n if (occurrences.length >= limit) {\n // First remove the old occurrences from the cache\n cache[cacheKey] = {value: occurrences, timestamp: Date.now()}\n config.set('cache', cache)\n\n return false\n }\n\n await task()\n cache[cacheKey] = {value: [...occurrences, now], timestamp: now}\n } else {\n await task()\n cache[cacheKey] = {value: [now], timestamp: now}\n }\n config.set('cache', cache)\n\n return true\n}\n\n/**\n * Get auto-upgrade preference.\n *\n * @returns Whether auto-upgrade is enabled, or undefined if never set.\n */\nexport function getAutoUpgradeEnabled(config: LocalStorage<ConfSchema> = cliKitStore()): boolean | undefined {\n return config.get('autoUpgradeEnabled')\n}\n\n/**\n * Set auto-upgrade preference.\n *\n * @param enabled - Whether auto-upgrade should be enabled.\n */\nexport function setAutoUpgradeEnabled(enabled: boolean, config: LocalStorage<ConfSchema> = cliKitStore()): void {\n config.set('autoUpgradeEnabled', enabled)\n}\n\nexport function getConfigStoreForPartnerStatus() {\n return new LocalStorage<Record<string, {status: true; checkedAt: string}>>({\n projectName: 'shopify-cli-kit-partner-status',\n })\n}\n\nexport function getCachedPartnerAccountStatus(partnersToken: string): true | null {\n if (!partnersToken) return null\n const store = getConfigStoreForPartnerStatus()\n\n const hasPartnerAccount = store.get(partnersToken)\n if (hasPartnerAccount) {\n // this never needs to expire\n return true\n }\n return null\n}\n\nexport function setCachedPartnerAccountStatus(partnersToken: string) {\n const store = getConfigStoreForPartnerStatus()\n\n store.set(partnersToken, {status: true, checkedAt: new Date().toISOString()})\n}\n"]}
|
|
@@ -8,6 +8,7 @@ export declare const environmentVariables: {
|
|
|
8
8
|
env: string;
|
|
9
9
|
firstPartyDev: string;
|
|
10
10
|
noAnalytics: string;
|
|
11
|
+
appAutomationToken: string;
|
|
11
12
|
partnersToken: string;
|
|
12
13
|
runAsUser: string;
|
|
13
14
|
serviceEnv: string;
|
|
@@ -32,6 +33,8 @@ export declare const environmentVariables: {
|
|
|
32
33
|
neverUsePartnersApi: string;
|
|
33
34
|
skipNetworkLevelRetry: string;
|
|
34
35
|
maxRequestTimeForNetworkCalls: string;
|
|
36
|
+
disableImportScanning: string;
|
|
37
|
+
hostedApps: string;
|
|
35
38
|
};
|
|
36
39
|
export declare const defaultThemeKitAccessDomain = "theme-kit-access.shopifyapps.com";
|
|
37
40
|
export declare const systemEnvironmentVariables: {
|
|
@@ -18,6 +18,7 @@ export const environmentVariables = {
|
|
|
18
18
|
env: 'SHOPIFY_CLI_ENV',
|
|
19
19
|
firstPartyDev: 'SHOPIFY_CLI_1P_DEV',
|
|
20
20
|
noAnalytics: 'SHOPIFY_CLI_NO_ANALYTICS',
|
|
21
|
+
appAutomationToken: 'SHOPIFY_APP_AUTOMATION_TOKEN',
|
|
21
22
|
partnersToken: 'SHOPIFY_CLI_PARTNERS_TOKEN',
|
|
22
23
|
runAsUser: 'SHOPIFY_RUN_AS_USER',
|
|
23
24
|
serviceEnv: 'SHOPIFY_SERVICE_ENV',
|
|
@@ -43,6 +44,8 @@ export const environmentVariables = {
|
|
|
43
44
|
neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',
|
|
44
45
|
skipNetworkLevelRetry: 'SHOPIFY_CLI_SKIP_NETWORK_LEVEL_RETRY',
|
|
45
46
|
maxRequestTimeForNetworkCalls: 'SHOPIFY_CLI_MAX_REQUEST_TIME_FOR_NETWORK_CALLS',
|
|
47
|
+
disableImportScanning: 'SHOPIFY_CLI_DISABLE_IMPORT_SCANNING',
|
|
48
|
+
hostedApps: 'HOSTED_APPS',
|
|
46
49
|
};
|
|
47
50
|
export const defaultThemeKitAccessDomain = 'theme-kit-access.shopifyapps.com';
|
|
48
51
|
export const systemEnvironmentVariables = {
|
|
@@ -1 +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,UAAU,GAAG,GAAG,EAAE;IAC7B,OAAO,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,kBAAkB,EAAE,kCAAkC;IACtD,gBAAgB,EAAE,gCAAgC;IAClD,UAAU,EAAE,yBAAyB;IACrC,MAAM,EAAE,oBAAoB;IAC5B,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,sB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,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,gBAAgB,GAAG;IAC9B,6BAA6B,EAAE,CAAC;CACjC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,kCAAkC,CAAA;AAE/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,EAAC,IAAI,EAAE,CAAC,EAAC,EAAC,CAAA;AAElE,MAAM,CAAC,MAAM,oBAAoB,GAC/B,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,oBAAoB,CAAC,IAAI,2BAA2B,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 logsFolder = () => {\n return envPaths(identifier).log\n}\n\nexport const environmentVariables = {\n alwaysLogAnalytics: 'SHOPIFY_CLI_ALWAYS_LOG_ANALYTICS',\n alwaysLogMetrics: 'SHOPIFY_CLI_ALWAYS_LOG_METRICS',\n deviceAuth: 'SHOPIFY_CLI_DEVICE_AUTH',\n doctor: 'SHOPIFY_CLI_DOCTOR',\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 appAutomationToken: 'SHOPIFY_APP_AUTOMATION_TOKEN',\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 // Variables to detect if the CLI is running in a cloud environment\n codespaces: 'CODESPACES',\n codespaceName: 'CODESPACE_NAME',\n codespacePortForwardingDomain: 'GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN',\n gitpod: 'GITPOD_WORKSPACE_URL',\n cloudShell: 'CLOUD_SHELL',\n spinAppPort: 'SERVER_PORT',\n spinAppHost: 'SPIN_APP_HOST',\n organization: 'SHOPIFY_CLI_ORGANIZATION',\n identityToken: 'SHOPIFY_CLI_IDENTITY_TOKEN',\n refreshToken: 'SHOPIFY_CLI_REFRESH_TOKEN',\n otelURL: 'SHOPIFY_CLI_OTEL_EXPORTER_OTLP_ENDPOINT',\n themeKitAccessDomain: 'SHOPIFY_CLI_THEME_KIT_ACCESS_DOMAIN',\n json: 'SHOPIFY_FLAG_JSON',\n neverUsePartnersApi: 'SHOPIFY_CLI_NEVER_USE_PARTNERS_API',\n skipNetworkLevelRetry: 'SHOPIFY_CLI_SKIP_NETWORK_LEVEL_RETRY',\n maxRequestTimeForNetworkCalls: 'SHOPIFY_CLI_MAX_REQUEST_TIME_FOR_NETWORK_CALLS',\n disableImportScanning: 'SHOPIFY_CLI_DISABLE_IMPORT_SCANNING',\n hostedApps: 'HOSTED_APPS',\n}\n\nexport const defaultThemeKitAccessDomain = 'theme-kit-access.shopifyapps.com'\n\nexport const systemEnvironmentVariables = {\n backendPort: 'BACKEND_PORT',\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 sessionConstants = {\n expirationTimeMarginInMinutes: 4,\n}\n\nexport const bugsnagApiKey = '9e1e6889176fd0c795d5c659225e0fae'\n\nexport const reportingRateLimit = {limit: 300, timeout: {days: 1}}\n\nexport const themeKitAccessDomain =\n process.env[environmentVariables.themeKitAccessDomain] ?? defaultThemeKitAccessDomain\n"]}
|
|
@@ -6,14 +6,28 @@ export declare class InvalidGrantError extends ExtendableError {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class InvalidRequestError extends ExtendableError {
|
|
8
8
|
}
|
|
9
|
+
export interface ExchangeScopes {
|
|
10
|
+
admin: string[];
|
|
11
|
+
partners: string[];
|
|
12
|
+
storefront: string[];
|
|
13
|
+
businessPlatform: string[];
|
|
14
|
+
appManagement: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Given an identity token, request an application token.
|
|
18
|
+
* @param identityToken - access token obtained in a previous step
|
|
19
|
+
* @param store - the store to use, only needed for admin API
|
|
20
|
+
* @returns An array with the application access tokens.
|
|
21
|
+
*/
|
|
22
|
+
export declare function exchangeAccessForApplicationTokens(identityToken: IdentityToken, scopes: ExchangeScopes, store?: string): Promise<Record<string, ApplicationToken>>;
|
|
9
23
|
/**
|
|
10
24
|
* Given an expired access token, refresh it to get a new one.
|
|
11
25
|
*/
|
|
12
26
|
export declare function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken>;
|
|
13
27
|
/**
|
|
14
|
-
* Given a custom
|
|
28
|
+
* Given a custom app automation token passed as ENV variable, request a valid Partners API token.
|
|
15
29
|
* This token does not accept extra scopes, just the cli one.
|
|
16
|
-
* @param token - The
|
|
30
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
17
31
|
* @returns An instance with the application access tokens.
|
|
18
32
|
*/
|
|
19
33
|
export declare function exchangeCustomPartnerToken(token: string): Promise<{
|
|
@@ -21,20 +35,20 @@ export declare function exchangeCustomPartnerToken(token: string): Promise<{
|
|
|
21
35
|
userId: string;
|
|
22
36
|
}>;
|
|
23
37
|
/**
|
|
24
|
-
* Given a custom
|
|
25
|
-
* @param token - The
|
|
38
|
+
* Given a custom app automation token passed as ENV variable, request a valid App Management API token.
|
|
39
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
26
40
|
* @returns An instance with the application access tokens.
|
|
27
41
|
*/
|
|
28
|
-
export declare function
|
|
42
|
+
export declare function exchangeAppAutomationTokenForAppManagementAccessToken(token: string): Promise<{
|
|
29
43
|
accessToken: string;
|
|
30
44
|
userId: string;
|
|
31
45
|
}>;
|
|
32
46
|
/**
|
|
33
|
-
* Given a custom
|
|
34
|
-
* @param token - The
|
|
47
|
+
* Given a custom app automation token passed as ENV variable, request a valid Business Platform API token.
|
|
48
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
35
49
|
* @returns An instance with the application access tokens.
|
|
36
50
|
*/
|
|
37
|
-
export declare function
|
|
51
|
+
export declare function exchangeAppAutomationTokenForBusinessPlatformAccessToken(token: string): Promise<{
|
|
38
52
|
accessToken: string;
|
|
39
53
|
userId: string;
|
|
40
54
|
}>;
|
|
@@ -13,6 +13,29 @@ export class InvalidRequestError extends ExtendableError {
|
|
|
13
13
|
}
|
|
14
14
|
class InvalidTargetError extends AbortError {
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Given an identity token, request an application token.
|
|
18
|
+
* @param identityToken - access token obtained in a previous step
|
|
19
|
+
* @param store - the store to use, only needed for admin API
|
|
20
|
+
* @returns An array with the application access tokens.
|
|
21
|
+
*/
|
|
22
|
+
export async function exchangeAccessForApplicationTokens(identityToken, scopes, store) {
|
|
23
|
+
const token = identityToken.accessToken;
|
|
24
|
+
const [partners, storefront, businessPlatform, admin, appManagement] = await Promise.all([
|
|
25
|
+
requestAppToken('partners', token, scopes.partners),
|
|
26
|
+
requestAppToken('storefront-renderer', token, scopes.storefront),
|
|
27
|
+
requestAppToken('business-platform', token, scopes.businessPlatform),
|
|
28
|
+
store ? requestAppToken('admin', token, scopes.admin, store) : {},
|
|
29
|
+
requestAppToken('app-management', token, scopes.appManagement),
|
|
30
|
+
]);
|
|
31
|
+
return {
|
|
32
|
+
...partners,
|
|
33
|
+
...storefront,
|
|
34
|
+
...businessPlatform,
|
|
35
|
+
...admin,
|
|
36
|
+
...appManagement,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
16
39
|
/**
|
|
17
40
|
* Given an expired access token, refresh it to get a new one.
|
|
18
41
|
*/
|
|
@@ -29,13 +52,13 @@ export async function refreshAccessToken(currentToken) {
|
|
|
29
52
|
return buildIdentityToken(value, currentToken.userId, currentToken.alias);
|
|
30
53
|
}
|
|
31
54
|
/**
|
|
32
|
-
* Given a custom
|
|
33
|
-
* @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`
|
|
55
|
+
* Given a custom app automation token passed as ENV variable, request a valid API access token.
|
|
34
56
|
* @param apiName - The API to exchange for the access token
|
|
57
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
35
58
|
* @param scopes - The scopes to request with the access token
|
|
36
59
|
* @returns An instance with the application access tokens.
|
|
37
60
|
*/
|
|
38
|
-
async function
|
|
61
|
+
async function exchangeAppAutomationTokenForAccessToken(apiName, token, scopes) {
|
|
39
62
|
const appId = applicationId(apiName);
|
|
40
63
|
try {
|
|
41
64
|
const newToken = await requestAppToken(apiName, token, scopes);
|
|
@@ -51,29 +74,29 @@ async function exchangeCliTokenForAccessToken(apiName, token, scopes) {
|
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
/**
|
|
54
|
-
* Given a custom
|
|
77
|
+
* Given a custom app automation token passed as ENV variable, request a valid Partners API token.
|
|
55
78
|
* This token does not accept extra scopes, just the cli one.
|
|
56
|
-
* @param token - The
|
|
79
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
57
80
|
* @returns An instance with the application access tokens.
|
|
58
81
|
*/
|
|
59
82
|
export async function exchangeCustomPartnerToken(token) {
|
|
60
|
-
return
|
|
83
|
+
return exchangeAppAutomationTokenForAccessToken('partners', token, tokenExchangeScopes('partners'));
|
|
61
84
|
}
|
|
62
85
|
/**
|
|
63
|
-
* Given a custom
|
|
64
|
-
* @param token - The
|
|
86
|
+
* Given a custom app automation token passed as ENV variable, request a valid App Management API token.
|
|
87
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
65
88
|
* @returns An instance with the application access tokens.
|
|
66
89
|
*/
|
|
67
|
-
export async function
|
|
68
|
-
return
|
|
90
|
+
export async function exchangeAppAutomationTokenForAppManagementAccessToken(token) {
|
|
91
|
+
return exchangeAppAutomationTokenForAccessToken('app-management', token, tokenExchangeScopes('app-management'));
|
|
69
92
|
}
|
|
70
93
|
/**
|
|
71
|
-
* Given a custom
|
|
72
|
-
* @param token - The
|
|
94
|
+
* Given a custom app automation token passed as ENV variable, request a valid Business Platform API token.
|
|
95
|
+
* @param token - The app automation token passed as ENV variable `SHOPIFY_APP_AUTOMATION_TOKEN`
|
|
73
96
|
* @returns An instance with the application access tokens.
|
|
74
97
|
*/
|
|
75
|
-
export async function
|
|
76
|
-
return
|
|
98
|
+
export async function exchangeAppAutomationTokenForBusinessPlatformAccessToken(token) {
|
|
99
|
+
return exchangeAppAutomationTokenForAccessToken('business-platform', token, tokenExchangeScopes('business-platform'));
|
|
77
100
|
}
|
|
78
101
|
/**
|
|
79
102
|
* Given a deviceCode obtained after starting a device identity flow, request an identity token.
|