@shopify/cli-kit 3.53.1 → 3.54.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/assets/cli-ruby/lib/shopify_cli/theme/dev_server/proxy.rb +14 -0
- package/dist/private/node/analytics.js +2 -4
- package/dist/private/node/analytics.js.map +1 -1
- package/dist/private/node/ui/components/List.d.ts +8 -1
- package/dist/private/node/ui/components/List.js +26 -5
- package/dist/private/node/ui/components/List.js.map +1 -1
- package/dist/private/node/ui/components/List.test.js +17 -0
- package/dist/private/node/ui/components/List.test.js.map +1 -1
- package/dist/private/node/ui/components/Prompts/InfoTable.d.ts +3 -1
- package/dist/private/node/ui/components/Prompts/InfoTable.js +4 -1
- package/dist/private/node/ui/components/Prompts/InfoTable.js.map +1 -1
- package/dist/private/node/ui/components/Prompts/InfoTable.test.js +26 -0
- package/dist/private/node/ui/components/Prompts/InfoTable.test.js.map +1 -1
- package/dist/public/common/object.d.ts +7 -0
- package/dist/public/common/object.js +10 -0
- package/dist/public/common/object.js.map +1 -1
- package/dist/public/common/retry.d.ts +14 -0
- package/dist/public/common/retry.js +27 -0
- package/dist/public/common/retry.js.map +1 -0
- 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 +1 -1
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/partners.d.ts +15 -7
- package/dist/public/node/api/partners.js +16 -20
- package/dist/public/node/api/partners.js.map +1 -1
- package/dist/public/node/base-command.js +1 -1
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/context/local.d.ts +0 -7
- package/dist/public/node/context/local.js +0 -9
- package/dist/public/node/context/local.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/fs.d.ts +5 -1
- package/dist/public/node/fs.js +3 -2
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/monorail.js +9 -0
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/schema.d.ts +8 -0
- package/dist/public/node/schema.js +20 -0
- package/dist/public/node/schema.js.map +1 -1
- package/dist/public/node/themes/{themes-api.d.ts → api.d.ts} +3 -1
- package/dist/public/node/themes/{themes-api.js → api.js} +21 -13
- package/dist/public/node/themes/api.js.map +1 -0
- package/dist/public/node/themes/factories.d.ts +18 -0
- package/dist/public/node/themes/factories.js +27 -0
- package/dist/public/node/themes/factories.js.map +1 -0
- package/dist/public/node/themes/theme-manager.d.ts +1 -1
- package/dist/public/node/themes/theme-manager.js +2 -2
- package/dist/public/node/themes/theme-manager.js.map +1 -1
- package/dist/public/node/themes/types.d.ts +68 -0
- package/dist/public/node/themes/types.js +2 -0
- package/dist/public/node/themes/types.js.map +1 -0
- package/dist/public/node/themes/{theme-urls.d.ts → urls.d.ts} +1 -1
- package/dist/public/node/themes/{theme-urls.js → urls.js} +1 -1
- package/dist/public/node/themes/urls.js.map +1 -0
- package/dist/public/node/themes/utils.d.ts +3 -0
- package/dist/public/node/themes/utils.js +5 -0
- package/dist/public/node/themes/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/public/node/themes/models/theme.d.ts +0 -12
- package/dist/public/node/themes/models/theme.js +0 -30
- package/dist/public/node/themes/models/theme.js.map +0 -1
- package/dist/public/node/themes/theme-urls.js.map +0 -1
- package/dist/public/node/themes/themes-api.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/cli-kit",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.54.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A set of utilities, interfaces, and models that are common across all the platform features",
|
|
6
6
|
"keywords": [
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"dependencies": {
|
|
84
84
|
"@bugsnag/js": "7.21.0",
|
|
85
85
|
"@iarna/toml": "2.2.5",
|
|
86
|
-
"@oclif/core": "
|
|
86
|
+
"@oclif/core": "3.15.1",
|
|
87
87
|
"@opentelemetry/api": "1.6.0",
|
|
88
88
|
"@opentelemetry/core": "1.17.1",
|
|
89
89
|
"@opentelemetry/exporter-metrics-otlp-http": "0.43.0",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const DEVELOPMENT_THEME_ROLE = "development";
|
|
2
|
-
export declare class Theme {
|
|
3
|
-
id: number;
|
|
4
|
-
name: string;
|
|
5
|
-
private _role;
|
|
6
|
-
createdAtRuntime: boolean;
|
|
7
|
-
processing: boolean;
|
|
8
|
-
constructor(id: number, name: string, _role: string, createdAtRuntime?: boolean, processing?: boolean);
|
|
9
|
-
get role(): string;
|
|
10
|
-
set role(_role: string);
|
|
11
|
-
get hasDevelopmentRole(): boolean;
|
|
12
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const DEVELOPMENT_THEME_ROLE = 'development';
|
|
2
|
-
export class Theme {
|
|
3
|
-
constructor(id, name, _role, createdAtRuntime = false, processing = false) {
|
|
4
|
-
this.id = id;
|
|
5
|
-
this.name = name;
|
|
6
|
-
this._role = _role;
|
|
7
|
-
this.createdAtRuntime = createdAtRuntime;
|
|
8
|
-
this.processing = processing;
|
|
9
|
-
}
|
|
10
|
-
get role() {
|
|
11
|
-
if (this._role === 'main') {
|
|
12
|
-
return 'live';
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
return this._role;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
set role(_role) {
|
|
19
|
-
if (_role === 'live') {
|
|
20
|
-
this._role = 'main';
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
this._role = _role;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
get hasDevelopmentRole() {
|
|
27
|
-
return this.role === DEVELOPMENT_THEME_ROLE;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=theme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../../../../src/public/node/themes/models/theme.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAAA;AAEnD,MAAM,OAAO,KAAK;IAChB,YACS,EAAU,EACV,IAAY,EACX,KAAa,EACd,mBAAmB,KAAK,EACxB,aAAa,KAAK;QAJlB,OAAE,GAAF,EAAE,CAAQ;QACV,SAAI,GAAJ,IAAI,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QACd,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,eAAU,GAAV,UAAU,CAAQ;IACxB,CAAC;IAEJ,IAAI,IAAI;QACN,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,EAAE;YACzB,OAAO,MAAM,CAAA;SACd;aAAM;YACL,OAAO,IAAI,CAAC,KAAK,CAAA;SAClB;IACH,CAAC;IAED,IAAI,IAAI,CAAC,KAAa;QACpB,IAAI,KAAK,KAAK,MAAM,EAAE;YACpB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;SACpB;aAAM;YACL,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;SACnB;IACH,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,IAAI,KAAK,sBAAsB,CAAA;IAC7C,CAAC;CACF","sourcesContent":["export const DEVELOPMENT_THEME_ROLE = 'development'\n\nexport class Theme {\n constructor(\n public id: number,\n public name: string,\n private _role: string,\n public createdAtRuntime = false,\n public processing = false,\n ) {}\n\n get role(): string {\n if (this._role === 'main') {\n return 'live'\n } else {\n return this._role\n }\n }\n\n set role(_role: string) {\n if (_role === 'live') {\n this._role = 'main'\n } else {\n this._role = _role\n }\n }\n\n get hasDevelopmentRole(): boolean {\n return this.role === DEVELOPMENT_THEME_ROLE\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"theme-urls.js","sourceRoot":"","sources":["../../../../src/public/node/themes/theme-urls.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,OAAqB;IACjE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE;QACzB,OAAO,WAAW,KAAK,EAAE,CAAA;KAC1B;IAED,OAAO,WAAW,KAAK,qBAAqB,KAAK,CAAC,EAAE,EAAE,CAAA;AACxD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY,EAAE,OAAqB;IAChE,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,SAAS,CAAA;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAY,EAAE,OAAqB;IAC/D,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,iBAAiB,KAAK,CAAC,EAAE,EAAE,CAAA;AACpD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAA;IAC/B,OAAO,WAAW,KAAK,QAAQ,CAAA;AACjC,CAAC","sourcesContent":["import {Theme} from '@shopify/cli-kit/node/themes/models/theme'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\n\nexport function themePreviewUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n if (theme.role === 'live') {\n return `https://${store}`\n }\n\n return `https://${store}?preview_theme_id=${theme.id}`\n}\n\nexport function themeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}/editor`\n}\n\nexport function codeEditorUrl(theme: Theme, session: AdminSession) {\n const store = session.storeFqdn\n return `https://${store}/admin/themes/${theme.id}`\n}\n\nexport function storeAdminUrl(session: AdminSession) {\n const store = session.storeFqdn\n return `https://${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esContent":["import {storeAdminUrl} from './theme-urls.js'\nimport {Theme} from './models/theme.js'\nimport * as throttler from '../../../private/node/themes/themes-api/throttler.js'\nimport {apiCallLimit, retryAfter} from '../../../private/node/themes/themes-api/headers.js'\nimport {retry} from '../../../private/node/themes/themes-api/retry.js'\nimport {restRequest, RestResponse} from '@shopify/cli-kit/node/api/admin'\nimport {AdminSession} from '@shopify/cli-kit/node/session'\nimport {AbortError} from '@shopify/cli-kit/node/error'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing'>>\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('GET', `/themes/${id}`, session, undefined, {fields: 'id,processing'})\n return buildTheme(response.json.theme)\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const response = await request('GET', '/themes', session, undefined, {fields: 'id,name,role,processing'})\n return buildThemes(response)\n}\n\nexport async function createTheme(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('POST', '/themes', session, {theme: {...params}})\n return buildTheme({...response.json.theme, createdAtRuntime: true})\n}\n\ninterface UpgradeThemeOptions {\n fromTheme: number\n toTheme: number\n script?: string\n session: AdminSession\n}\n\nexport async function upgradeTheme(upgradeOptions: UpgradeThemeOptions): Promise<Theme | undefined> {\n const {fromTheme, toTheme, session, script} = upgradeOptions\n const params = {from_theme: fromTheme, to_theme: toTheme, ...(script && {script})}\n const response = await request('POST', `/themes`, session, params)\n return buildTheme(response.json.theme)\n}\n\nexport async function updateTheme(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('PUT', `/themes/${id}`, session, {theme: {id, ...params}})\n return buildTheme(response.json.theme)\n}\n\nexport async function publishTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n return updateTheme(id, {role: 'main'}, session)\n}\n\nexport async function deleteTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const response = await request('DELETE', `/themes/${id}`, session)\n return buildTheme(response.json.theme)\n}\n\nasync function request<T>(\n method: string,\n path: string,\n session: AdminSession,\n params?: T,\n searchParams: {[name: string]: string} = {},\n): Promise<RestResponse> {\n const response = await throttler.throttle(() => restRequest(method, path, session, params, searchParams))\n\n const status = response.status\n const callLimit = apiCallLimit(response)\n\n throttler.updateApiCallLimit(callLimit)\n\n switch (true) {\n case status >= 200 && status <= 399:\n // Returns the successful reponse\n return response\n case status === 404:\n // Defer the decision when a resource is not found\n return response\n case status === 429:\n // Retry following the \"retry-after\" header\n return retry(() => request(method, path, session, params, searchParams), retryAfter(response))\n case status === 403:\n return handleForbiddenError(session)\n case status === 401:\n throw new AbortError(`[${status}] API request unauthorized error`)\n case status === 422:\n throw new AbortError(`[${status}] API request unprocessable content: ${errors(response)}`)\n case status >= 400 && status <= 499:\n throw new AbortError(`[${status}] API request client error`)\n case status >= 500 && status <= 599:\n throw new AbortError(`[${status}] API request server error`)\n default:\n throw new AbortError(`[${status}] API request unexpected error`)\n }\n}\n\nfunction buildThemes(response: RestResponse): Theme[] {\n const themes = response.json?.themes\n\n if (themes?.length > 0) {\n return themes.map(buildTheme)\n }\n\n return []\n}\n\n// Using `any` to avoid introducing extra DTO layers.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction buildTheme(themeJson: any): Theme | undefined {\n if (!themeJson?.id) {\n return undefined\n }\n\n return new Theme(themeJson.id, themeJson.name, themeJson.role, themeJson.createdAtRuntime, themeJson.processing)\n}\n\nfunction handleForbiddenError(session: AdminSession): never {\n const store = session.storeFqdn\n const adminUrl = storeAdminUrl(session)\n\n throw new AbortError(\n `You are not authorized to edit themes on \"${store}\".`,\n \"You can't use Shopify CLI with development stores if you only have Partner staff \" +\n 'member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n `store URL at least once (for example, using \"${adminUrl}\") before you log in using ` +\n 'Shopify CLI. Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.',\n )\n}\n\nfunction errors(response: RestResponse) {\n return JSON.stringify(response.json?.errors)\n}\n"]}
|