@shopify/cli-kit 4.1.0 → 4.3.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.
Files changed (72) hide show
  1. package/assets/graphiql/favicon.ico +0 -0
  2. package/assets/graphiql/style.css +58 -0
  3. package/dist/private/common/array.js +2 -1
  4. package/dist/private/common/array.js.map +1 -1
  5. package/dist/private/node/api/headers.js +6 -3
  6. package/dist/private/node/api/headers.js.map +1 -1
  7. package/dist/private/node/session/device-authorization.js +4 -16
  8. package/dist/private/node/session/device-authorization.js.map +1 -1
  9. package/dist/private/node/session/store.js +10 -1
  10. package/dist/private/node/session/store.js.map +1 -1
  11. package/dist/private/node/ui.js +4 -1
  12. package/dist/private/node/ui.js.map +1 -1
  13. package/dist/public/common/gid.d.ts +24 -0
  14. package/dist/public/common/gid.js +32 -0
  15. package/dist/public/common/gid.js.map +1 -0
  16. package/dist/public/common/url.d.ts +16 -0
  17. package/dist/public/common/url.js +39 -0
  18. package/dist/public/common/url.js.map +1 -1
  19. package/dist/public/common/version.d.ts +1 -1
  20. package/dist/public/common/version.js +1 -1
  21. package/dist/public/common/version.js.map +1 -1
  22. package/dist/public/node/analytics.js +3 -5
  23. package/dist/public/node/analytics.js.map +1 -1
  24. package/dist/public/node/cli.d.ts +13 -0
  25. package/dist/public/node/cli.js +12 -0
  26. package/dist/public/node/cli.js.map +1 -1
  27. package/dist/public/node/context/fqdn.js +1 -1
  28. package/dist/public/node/context/fqdn.js.map +1 -1
  29. package/dist/public/node/error-handler.js +1 -1
  30. package/dist/public/node/error-handler.js.map +1 -1
  31. package/dist/public/node/graphiql/server.d.ts +80 -0
  32. package/dist/public/node/graphiql/server.js +234 -0
  33. package/dist/public/node/graphiql/server.js.map +1 -0
  34. package/dist/public/node/graphiql/templates/graphiql.d.ts +12 -0
  35. package/dist/public/node/graphiql/templates/graphiql.js +314 -0
  36. package/dist/public/node/graphiql/templates/graphiql.js.map +1 -0
  37. package/dist/public/node/graphiql/templates/unauthorized.d.ts +5 -0
  38. package/dist/public/node/graphiql/templates/unauthorized.js +111 -0
  39. package/dist/public/node/graphiql/templates/unauthorized.js.map +1 -0
  40. package/dist/public/node/graphiql/utilities.d.ts +12 -0
  41. package/dist/public/node/graphiql/utilities.js +44 -0
  42. package/dist/public/node/graphiql/utilities.js.map +1 -0
  43. package/dist/public/node/graphql.d.ts +19 -0
  44. package/dist/public/node/graphql.js +41 -0
  45. package/dist/public/node/graphql.js.map +1 -0
  46. package/dist/public/node/hooks/postrun.js +12 -2
  47. package/dist/public/node/hooks/postrun.js.map +1 -1
  48. package/dist/public/node/http.js +27 -31
  49. package/dist/public/node/http.js.map +1 -1
  50. package/dist/public/node/json-schema.js +22 -6
  51. package/dist/public/node/json-schema.js.map +1 -1
  52. package/dist/public/node/metadata.d.ts +3 -0
  53. package/dist/public/node/metadata.js.map +1 -1
  54. package/dist/public/node/monorail.d.ts +3 -1
  55. package/dist/public/node/monorail.js +1 -1
  56. package/dist/public/node/monorail.js.map +1 -1
  57. package/dist/public/node/output.js +20 -11
  58. package/dist/public/node/output.js.map +1 -1
  59. package/dist/public/node/session.d.ts +2 -1
  60. package/dist/public/node/session.js +3 -2
  61. package/dist/public/node/session.js.map +1 -1
  62. package/dist/public/node/system.js +3 -0
  63. package/dist/public/node/system.js.map +1 -1
  64. package/dist/public/node/tcp.js +11 -3
  65. package/dist/public/node/tcp.js.map +1 -1
  66. package/dist/public/node/themes/api.js +76 -4
  67. package/dist/public/node/themes/api.js.map +1 -1
  68. package/dist/public/node/toml/toml-file.d.ts +3 -2
  69. package/dist/public/node/toml/toml-file.js +3 -2
  70. package/dist/public/node/toml/toml-file.js.map +1 -1
  71. package/dist/tsconfig.tsbuildinfo +1 -1
  72. package/package.json +34 -29
@@ -19,6 +19,7 @@ import { adminRequestDoc } from '../api/admin.js';
19
19
  import { AbortError } from '../error.js';
20
20
  import { outputDebug } from '../output.js';
21
21
  import { recordTiming, recordEvent, recordError } from '../analytics.js';
22
+ import { ClientError } from 'graphql-request';
22
23
  const SkeletonThemeCdn = 'https://cdn.shopify.com/static/online-store/theme-skeleton.zip';
23
24
  const THEME_API_NETWORK_BEHAVIOUR = {
24
25
  useNetworkLevelRetry: true,
@@ -26,6 +27,7 @@ const THEME_API_NETWORK_BEHAVIOUR = {
26
27
  maxRetryTimeMs: 90 * 1000,
27
28
  recordCommandRetries: true,
28
29
  };
30
+ const DEFAULT_THEME_ACCESS_REQUIREMENT = 'the required theme access scope';
29
31
  export async function fetchTheme(id, session) {
30
32
  const gid = composeThemeGid(id);
31
33
  recordEvent('theme-api:fetch-theme');
@@ -48,6 +50,7 @@ export async function fetchTheme(id, session) {
48
50
  // eslint-disable-next-line no-catch-all/no-catch-all
49
51
  }
50
52
  catch (error) {
53
+ abortIfMissingThemeAccessScope(error);
51
54
  /**
52
55
  * Consumers of this and other theme APIs in this file expect either a theme
53
56
  * or `undefined`.
@@ -65,7 +68,7 @@ export async function fetchThemes(session) {
65
68
  recordEvent('theme-api:fetch-themes');
66
69
  while (true) {
67
70
  // eslint-disable-next-line no-await-in-loop
68
- const response = await adminRequestDoc({
71
+ const response = await requestThemeAdminDoc({
69
72
  query: GetThemes,
70
73
  session,
71
74
  variables: { after },
@@ -95,7 +98,7 @@ export async function fetchThemes(session) {
95
98
  }
96
99
  export async function findDevelopmentThemeByName(name, session) {
97
100
  recordEvent('theme-api:find-development-theme-by-name');
98
- const { themes } = await adminRequestDoc({
101
+ const { themes } = await requestThemeAdminDoc({
99
102
  query: FindDevelopmentThemeByName,
100
103
  session,
101
104
  variables: { name },
@@ -155,7 +158,7 @@ export async function fetchThemeAssets(id, filenames, session) {
155
158
  recordEvent('theme-api:fetch-assets');
156
159
  while (true) {
157
160
  // eslint-disable-next-line no-await-in-loop
158
- const response = await adminRequestDoc({
161
+ const response = await requestThemeAdminDoc({
159
162
  query: GetThemeFileBodies,
160
163
  session,
161
164
  variables: { id: themeGid(id), filenames, after },
@@ -306,7 +309,7 @@ export async function fetchChecksums(id, session) {
306
309
  recordEvent('theme-api:fetch-checksums');
307
310
  while (true) {
308
311
  // eslint-disable-next-line no-await-in-loop
309
- const response = await adminRequestDoc({
312
+ const response = await requestThemeAdminDoc({
310
313
  query: GetThemeFileChecksums,
311
314
  session,
312
315
  variables: { id: themeGid(id), after },
@@ -493,6 +496,75 @@ export async function passwordProtected(session) {
493
496
  function unexpectedGraphQLError(message) {
494
497
  throw recordError(new AbortError(message));
495
498
  }
499
+ async function requestThemeAdminDoc(options) {
500
+ try {
501
+ const response = await adminRequestDoc(options);
502
+ return response;
503
+ }
504
+ catch (error) {
505
+ abortIfMissingThemeAccessScope(error);
506
+ throw error;
507
+ }
508
+ }
509
+ function abortIfMissingThemeAccessScope(error) {
510
+ if (!(error instanceof ClientError))
511
+ return;
512
+ const requiredAccess = getThemeAccessRequirementForAccessDeniedError(error);
513
+ if (!requiredAccess)
514
+ return;
515
+ const nextSteps = [
516
+ [
517
+ 'If you authenticated with an Admin API access token, update the app or integration that issued the token to include the required theme access scopes, then reauthorize it or generate a new token.',
518
+ ],
519
+ [
520
+ 'For',
521
+ { command: 'theme pull' },
522
+ { char: ',' },
523
+ { command: 'theme list' },
524
+ { char: ',' },
525
+ 'and',
526
+ { command: 'theme info' },
527
+ { char: ',' },
528
+ 'add the',
529
+ { command: 'read_themes' },
530
+ 'scope',
531
+ { char: '.' },
532
+ ],
533
+ [
534
+ 'For',
535
+ { command: 'theme push' },
536
+ 'and',
537
+ { command: 'theme dev' },
538
+ { char: ',' },
539
+ 'add both the',
540
+ { command: 'read_themes' },
541
+ 'and',
542
+ { command: 'write_themes' },
543
+ 'scopes',
544
+ { char: '.' },
545
+ ],
546
+ [
547
+ 'If you authenticated with your Shopify account, make sure your staff or collaborator account can access Online Store themes, then run',
548
+ { command: 'shopify auth logout' },
549
+ 'and try again',
550
+ { char: '.' },
551
+ ],
552
+ ['See', { link: { label: 'Shopify access scopes', url: 'https://shopify.dev/api/usage/access-scopes' } }, { char: '.' }],
553
+ ];
554
+ throw recordError(new AbortError(`The authenticated account or access token is missing ${requiredAccess}.`, undefined, nextSteps));
555
+ }
556
+ function getThemeAccessRequirementForAccessDeniedError(error) {
557
+ const graphQLErrors = error.response.errors;
558
+ if (!Array.isArray(graphQLErrors))
559
+ return undefined;
560
+ const accessDeniedError = graphQLErrors.find((graphQLError) => graphQLError.extensions?.code === 'ACCESS_DENIED');
561
+ if (!accessDeniedError)
562
+ return undefined;
563
+ const requiredAccess = accessDeniedError.extensions?.requiredAccess;
564
+ if (typeof requiredAccess !== 'string')
565
+ return DEFAULT_THEME_ACCESS_REQUIREMENT;
566
+ return requiredAccess.trim().replace(/\.$/, '') || DEFAULT_THEME_ACCESS_REQUIREMENT;
567
+ }
496
568
  function themeGid(id) {
497
569
  return `gid://shopify/OnlineStoreTheme/${id}`;
498
570
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,SAAS,EAAC,MAAM,YAAY,CAAA;AAC9E,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,cAAc,EAAC,MAAM,6DAA6D,CAAA;AAC1F,OAAO,EAAC,YAAY,EAAC,MAAM,2DAA2D,CAAA;AACtF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,kBAAkB,EAAC,MAAM,mEAAmE,CAAA;AACpG,OAAO,EAAC,qBAAqB,EAAC,MAAM,sEAAsE,CAAA;AAC1G,OAAO,EACL,gBAAgB,GAEjB,MAAM,gEAAgE,CAAA;AACvE,OAAO,EAAC,gBAAgB,EAAC,MAAM,g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, Checksum, Key, Theme, ThemeAsset, Operation} from './types.js'\nimport {buildTheme} from './factories.js'\nimport {composeThemeGid, parseGid, DEVELOPMENT_THEME_ROLE} from './utils.js'\nimport {ThemeUpdate} from '../../../cli/api/graphql/admin/generated/theme_update.js'\nimport {ThemeDelete} from '../../../cli/api/graphql/admin/generated/theme_delete.js'\nimport {ThemeDuplicate} from '../../../cli/api/graphql/admin/generated/theme_duplicate.js'\nimport {ThemePublish} from '../../../cli/api/graphql/admin/generated/theme_publish.js'\nimport {ThemeCreate} from '../../../cli/api/graphql/admin/generated/theme_create.js'\nimport {GetThemeFileBodies} from '../../../cli/api/graphql/admin/generated/get_theme_file_bodies.js'\nimport {GetThemeFileChecksums} from '../../../cli/api/graphql/admin/generated/get_theme_file_checksums.js'\nimport {\n ThemeFilesUpsert,\n ThemeFilesUpsertMutation,\n} from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js'\nimport {ThemeFilesDelete} from '../../../cli/api/graphql/admin/generated/theme_files_delete.js'\nimport {\n OnlineStoreThemeFileBodyInputType,\n OnlineStoreThemeFilesUpsertFileInput,\n MetafieldOwnerType,\n ThemeRole,\n} from '../../../cli/api/graphql/admin/generated/types.js'\nimport {MetafieldDefinitionsByOwnerType} from '../../../cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js'\nimport {GetThemes} from '../../../cli/api/graphql/admin/generated/get_themes.js'\nimport {GetTheme} from '../../../cli/api/graphql/admin/generated/get_theme.js'\nimport {FindDevelopmentThemeByName} from '../../../cli/api/graphql/admin/generated/find_development_theme_by_name.js'\nimport {OnlineStorePasswordProtection} from '../../../cli/api/graphql/admin/generated/online_store_password_protection.js'\nimport {RequestModeInput} from '../http.js'\nimport {adminRequestDoc} from '../api/admin.js'\nimport {AdminSession} from '../session.js'\nimport {AbortError} from '../error.js'\nimport {outputDebug} from '../output.js'\nimport {recordTiming, recordEvent, recordError} from '../analytics.js'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\nconst SkeletonThemeCdn = 'https://cdn.shopify.com/static/online-store/theme-skeleton.zip'\nconst THEME_API_NETWORK_BEHAVIOUR: RequestModeInput = {\n useNetworkLevelRetry: true,\n useAbortSignal: false,\n maxRetryTimeMs: 90 * 1000,\n recordCommandRetries: true,\n}\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const gid = composeThemeGid(id)\n recordEvent('theme-api:fetch-theme')\n\n try {\n const {theme} = await adminRequestDoc({\n query: GetTheme,\n session,\n variables: {id: gid},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (theme) {\n return buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n }\n\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n /**\n * Consumers of this and other theme APIs in this file expect either a theme\n * or `undefined`.\n *\n * Error handlers should not inspect GraphQL error messages directly, as\n * they are internationalized.\n */\n recordError(error)\n outputDebug(`Error fetching theme with ID: ${id}`)\n }\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const themes: Theme[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-themes')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc({\n query: GetThemes,\n session,\n variables: {after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!response.themes) {\n unexpectedGraphQLError('Failed to fetch themes')\n }\n const {nodes, pageInfo} = response.themes\n nodes.forEach((theme) => {\n const t = buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n if (t) {\n themes.push(t)\n }\n })\n if (!pageInfo.hasNextPage) {\n return themes\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function findDevelopmentThemeByName(name: string, session: AdminSession): Promise<Theme | undefined> {\n recordEvent('theme-api:find-development-theme-by-name')\n\n const {themes} = await adminRequestDoc({\n query: FindDevelopmentThemeByName,\n session,\n variables: {name},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themes) {\n unexpectedGraphQLError('Failed to fetch themes')\n }\n\n if (themes.nodes.length > 1) {\n throw recordError(new AbortError(`More than one development theme is named \"${name}\"`))\n }\n\n if (themes.nodes.length === 1) {\n const {id, processing, role, name} = themes.nodes[0]!\n\n return buildTheme({\n id: parseGid(id),\n processing,\n role: role.toLowerCase(),\n name,\n })\n }\n}\n\nexport async function themeCreate(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const themeSource = params.src ?? SkeletonThemeCdn\n recordEvent('theme-api:create-theme')\n const {themeCreate} = await adminRequestDoc({\n query: ThemeCreate,\n session,\n variables: {\n name: params.name ?? '',\n source: themeSource,\n role: (params.role ?? DEVELOPMENT_THEME_ROLE).toUpperCase() as ThemeRole,\n },\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themeCreate) {\n unexpectedGraphQLError('Failed to create theme')\n }\n\n const {theme, userErrors} = themeCreate\n if (userErrors.length) {\n const userErrors = themeCreate.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n unexpectedGraphQLError('Failed to create theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function fetchThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<ThemeAsset[]> {\n const assets: ThemeAsset[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-assets')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc({\n query: GetThemeFileBodies,\n session,\n variables: {id: themeGid(id), filenames, after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!response.theme?.files?.nodes || !response.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n unexpectedGraphQLError(`Error fetching assets: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n assets.push(\n // eslint-disable-next-line no-await-in-loop\n ...(await Promise.all(\n nodes.map(async (file) => {\n const {attachment, value} = await parseThemeFileContent(file.body)\n return {\n attachment,\n key: file.filename,\n checksum: file.checksumMd5 as string,\n value,\n }\n }),\n )),\n )\n\n if (!pageInfo.hasNextPage) {\n return assets\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function deleteThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<Result[]> {\n const batchSize = 50\n const results: Result[] = []\n recordEvent('theme-api:delete-assets')\n\n for (let i = 0; i < filenames.length; i += batchSize) {\n const batch = filenames.slice(i, i + batchSize)\n // eslint-disable-next-line no-await-in-loop\n const {themeFilesDelete} = await adminRequestDoc({\n query: ThemeFilesDelete,\n session,\n variables: {\n themeId: composeThemeGid(id),\n files: batch,\n },\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themeFilesDelete) {\n unexpectedGraphQLError('Failed to delete theme assets')\n }\n\n const {deletedThemeFiles, userErrors} = themeFilesDelete\n\n if (deletedThemeFiles) {\n deletedThemeFiles.forEach((file) => {\n results.push({key: file.filename, success: true, operation: Operation.Delete})\n })\n }\n\n if (userErrors.length > 0) {\n userErrors.forEach((error) => {\n if (error.filename) {\n recordError(`Asset deletion failed for ${error.filename}: ${error.message}`)\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Delete,\n errors: {asset: [error.message]},\n })\n } else {\n unexpectedGraphQLError(`Failed to delete theme assets: ${error.message}`)\n }\n })\n }\n }\n\n return results\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const results: Result[] = []\n recordEvent('theme-api:bulk-upload-assets')\n for (let i = 0; i < assets.length; i += 50) {\n const chunk = assets.slice(i, i + 50)\n const files = prepareFilesForUpload(chunk)\n\n recordTiming('theme-api:upload-files')\n // eslint-disable-next-line no-await-in-loop\n const uploadResults = await uploadFiles(id, files, session)\n recordTiming('theme-api:upload-files')\n\n results.push(...processUploadResults(uploadResults))\n }\n return results\n}\n\nfunction prepareFilesForUpload(assets: AssetParams[]): OnlineStoreThemeFilesUpsertFileInput[] {\n return assets.map((asset) => {\n if (asset.attachment) {\n return {\n filename: asset.key,\n body: {\n type: 'BASE64' as const,\n value: asset.attachment,\n },\n }\n } else {\n return {\n filename: asset.key,\n body: {\n type: 'TEXT' as const,\n value: asset.value ?? '',\n },\n }\n }\n })\n}\n\nasync function uploadFiles(\n themeId: number,\n files: {filename: string; body: {type: OnlineStoreThemeFileBodyInputType; value: string}}[],\n session: AdminSession,\n): Promise<ThemeFilesUpsertMutation> {\n return adminRequestDoc({\n query: ThemeFilesUpsert,\n session,\n variables: {themeId: themeGid(themeId), files},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n}\n\nfunction processUploadResults(uploadResults: ThemeFilesUpsertMutation): Result[] {\n const {themeFilesUpsert} = uploadResults\n\n if (!themeFilesUpsert) {\n unexpectedGraphQLError('Failed to upload theme files')\n }\n\n const {upsertedThemeFiles, userErrors} = themeFilesUpsert\n\n const results: Result[] = []\n\n upsertedThemeFiles?.forEach((file) => {\n results.push({\n key: file.filename,\n success: true,\n operation: Operation.Upload,\n })\n })\n\n userErrors.forEach((error) => {\n if (!error.filename) {\n unexpectedGraphQLError(`Error uploading theme files: ${error.message}`)\n }\n recordError(`Asset upload failed for ${error.filename}: ${error.message}`)\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Upload,\n errors: {asset: [error.message]},\n })\n })\n\n return results\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const checksums: Checksum[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-checksums')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await adminRequestDoc({\n query: GetThemeFileChecksums,\n session,\n variables: {id: themeGid(id), after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!response?.theme?.files?.nodes || !response?.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n throw recordError(new AbortError(`Failed to fetch checksums for: ${userErrors}`))\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n checksums.push(\n ...nodes.map((file) => ({\n key: file.filename,\n checksum: file.checksumMd5 as string,\n })),\n )\n\n if (!pageInfo.hasNextPage) {\n return checksums\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function themeUpdate(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const name = params.name\n const input: Record<string, string> = {}\n if (name) {\n input.name = name\n }\n recordEvent('theme-api:update-theme')\n\n const {themeUpdate} = await adminRequestDoc({\n query: ThemeUpdate,\n session,\n variables: {id: composeThemeGid(id), input},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themeUpdate) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themeUpdate\n if (userErrors.length) {\n const userErrors = themeUpdate.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themePublish(id: number, session: AdminSession): Promise<Theme | undefined> {\n recordEvent('theme-api:publish-theme')\n const {themePublish} = await adminRequestDoc({\n query: ThemePublish,\n session,\n variables: {id: composeThemeGid(id)},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themePublish) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themePublish\n if (userErrors.length) {\n const userErrors = themePublish.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themeDelete(id: number, session: AdminSession): Promise<boolean | undefined> {\n recordEvent('theme-api:delete-theme')\n const {themeDelete} = await adminRequestDoc({\n query: ThemeDelete,\n session,\n variables: {id: composeThemeGid(id)},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themeDelete) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {deletedThemeId, userErrors} = themeDelete\n if (userErrors.length) {\n const userErrors = themeDelete.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!deletedThemeId) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return true\n}\n\nexport interface ThemeDuplicateResult {\n theme?: Theme\n userErrors: {field?: string[] | null; message: string}[]\n requestId?: string\n}\n\nexport async function themeDuplicate(\n id: number,\n name: string | undefined,\n session: AdminSession,\n): Promise<ThemeDuplicateResult> {\n let requestId: string | undefined\n recordEvent('theme-api:duplicate-theme')\n\n const {themeDuplicate} = await adminRequestDoc({\n query: ThemeDuplicate,\n session,\n variables: {id: composeThemeGid(id), name},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n responseOptions: {\n onResponse: (response) => {\n requestId = response.headers.get('x-request-id') ?? undefined\n },\n },\n })\n\n if (!themeDuplicate) {\n // An unexpected error occurred during the GraphQL request execution\n recordError('Failed to duplicate theme')\n return {\n theme: undefined,\n userErrors: [{message: 'Failed to duplicate theme'}],\n requestId,\n }\n }\n\n const {newTheme, userErrors} = themeDuplicate\n\n if (userErrors.length > 0) {\n return {\n theme: undefined,\n userErrors,\n requestId,\n }\n }\n\n if (!newTheme) {\n // An unexpected error if neither theme nor userErrors are returned\n return {\n theme: undefined,\n userErrors: [{message: 'Failed to duplicate theme'}],\n requestId,\n }\n }\n\n const theme = buildTheme({\n id: parseGid(newTheme.id),\n name: newTheme.name,\n role: newTheme.role.toLowerCase(),\n })\n\n return {\n theme,\n userErrors: [],\n requestId,\n }\n}\n\nexport async function metafieldDefinitionsByOwnerType(type: MetafieldOwnerType, session: AdminSession) {\n recordEvent('theme-api:fetch-metafield-definitions')\n const {metafieldDefinitions} = await adminRequestDoc({\n query: MetafieldDefinitionsByOwnerType,\n session,\n variables: {ownerType: type},\n })\n\n return metafieldDefinitions.nodes.map((definition) => ({\n key: definition.key,\n namespace: definition.namespace,\n name: definition.name,\n description: definition.description,\n type: {\n name: definition.type.name,\n category: definition.type.category,\n },\n }))\n}\n\nexport async function passwordProtected(session: AdminSession): Promise<boolean> {\n recordEvent('theme-api:check-password-protection')\n const {onlineStore} = await adminRequestDoc({\n query: OnlineStorePasswordProtection,\n session,\n })\n if (!onlineStore) {\n unexpectedGraphQLError(\"Unable to get details about the storefront's password protection\")\n }\n\n const {passwordProtection} = onlineStore\n\n return passwordProtection.enabled\n}\n\nfunction unexpectedGraphQLError(message: string): never {\n throw recordError(new AbortError(message))\n}\n\nfunction themeGid(id: number): string {\n return `gid://shopify/OnlineStoreTheme/${id}`\n}\n\ntype OnlineStoreThemeFileBody =\n | {__typename: 'OnlineStoreThemeFileBodyBase64'; contentBase64: string}\n | {__typename: 'OnlineStoreThemeFileBodyText'; content: string}\n | {__typename: 'OnlineStoreThemeFileBodyUrl'; url: string}\n\nexport async function parseThemeFileContent(\n body: OnlineStoreThemeFileBody,\n): Promise<{value?: string; attachment?: string}> {\n switch (body.__typename) {\n case 'OnlineStoreThemeFileBodyText':\n return {value: body.content}\n case 'OnlineStoreThemeFileBodyBase64':\n return {attachment: body.contentBase64}\n case 'OnlineStoreThemeFileBodyUrl':\n try {\n // eslint-disable-next-line no-restricted-globals\n const response = await fetch(body.url)\n\n const arrayBuffer = await response.arrayBuffer()\n return {attachment: Buffer.from(arrayBuffer).toString('base64')}\n } catch (error) {\n // Raise error if we can't download the file\n throw recordError(new AbortError(`Error downloading content from URL: ${body.url}`))\n }\n }\n}\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../src/public/node/themes/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2C,SAAS,EAAC,MAAM,YAAY,CAAA;AAC9E,OAAO,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAC,eAAe,EAAE,QAAQ,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAA;AAC5E,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,cAAc,EAAC,MAAM,6DAA6D,CAAA;AAC1F,OAAO,EAAC,YAAY,EAAC,MAAM,2DAA2D,CAAA;AACtF,OAAO,EAAC,WAAW,EAAC,MAAM,0DAA0D,CAAA;AACpF,OAAO,EAAC,kBAAkB,EAAC,MAAM,mEAAmE,CAAA;AACpG,OAAO,EAAC,qBAAqB,EAAC,MAAM,sEAAsE,CAAA;AAC1G,OAAO,EACL,gBAAgB,GAEjB,MAAM,gEAAgE,CAAA;AACvE,OAAO,EAAC,gBAAgB,EAAC,MAAM,gEAAgE,CAAA;AAO/F,OAAO,EAAC,+BAA+B,EAAC,MAAM,iFAAiF,CAAA;AAC/H,OAAO,EAAC,SAAS,EAAC,MAAM,wDAAwD,CAAA;AAChF,OAAO,EAAC,QAAQ,EAAC,MAAM,uDAAuD,CAAA;AAC9E,OAAO,EAAC,0BAA0B,EAAC,MAAM,4EAA4E,CAAA;AACrH,OA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EAAE,EAAE,CAAA;AAC/C,CAAC;AAOD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,IAA8B;IAE9B,QAAQ,IAAI,CAAC,UAAU,EAAE,CAAC;QACxB,KAAK,8BAA8B;YACjC,OAAO,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAC,CAAA;QAC9B,KAAK,gCAAgC;YACnC,OAAO,EAAC,UAAU,EAAE,IAAI,CAAC,aAAa,EAAC,CAAA;QACzC,KAAK,6BAA6B;YAChC,IAAI,CAAC;gBACH,iDAAiD;gBACjD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBAEtC,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAA;gBAChD,OAAO,EAAC,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAC,CAAA;YAClE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,4CAA4C;gBAC5C,MAAM,WAAW,CAAC,IAAI,UAAU,CAAC,uCAAuC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;YACtF,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import {Result, Checksum, Key, Theme, ThemeAsset, Operation} from './types.js'\nimport {buildTheme} from './factories.js'\nimport {composeThemeGid, parseGid, DEVELOPMENT_THEME_ROLE} from './utils.js'\nimport {ThemeUpdate} from '../../../cli/api/graphql/admin/generated/theme_update.js'\nimport {ThemeDelete} from '../../../cli/api/graphql/admin/generated/theme_delete.js'\nimport {ThemeDuplicate} from '../../../cli/api/graphql/admin/generated/theme_duplicate.js'\nimport {ThemePublish} from '../../../cli/api/graphql/admin/generated/theme_publish.js'\nimport {ThemeCreate} from '../../../cli/api/graphql/admin/generated/theme_create.js'\nimport {GetThemeFileBodies} from '../../../cli/api/graphql/admin/generated/get_theme_file_bodies.js'\nimport {GetThemeFileChecksums} from '../../../cli/api/graphql/admin/generated/get_theme_file_checksums.js'\nimport {\n ThemeFilesUpsert,\n ThemeFilesUpsertMutation,\n} from '../../../cli/api/graphql/admin/generated/theme_files_upsert.js'\nimport {ThemeFilesDelete} from '../../../cli/api/graphql/admin/generated/theme_files_delete.js'\nimport {\n OnlineStoreThemeFileBodyInputType,\n OnlineStoreThemeFilesUpsertFileInput,\n MetafieldOwnerType,\n ThemeRole,\n} from '../../../cli/api/graphql/admin/generated/types.js'\nimport {MetafieldDefinitionsByOwnerType} from '../../../cli/api/graphql/admin/generated/metafield_definitions_by_owner_type.js'\nimport {GetThemes} from '../../../cli/api/graphql/admin/generated/get_themes.js'\nimport {GetTheme} from '../../../cli/api/graphql/admin/generated/get_theme.js'\nimport {FindDevelopmentThemeByName} from '../../../cli/api/graphql/admin/generated/find_development_theme_by_name.js'\nimport {OnlineStorePasswordProtection} from '../../../cli/api/graphql/admin/generated/online_store_password_protection.js'\nimport {RequestModeInput} from '../http.js'\nimport {adminRequestDoc, type AdminRequestOptions} from '../api/admin.js'\nimport {AdminSession} from '../session.js'\nimport {AbortError} from '../error.js'\nimport {outputDebug} from '../output.js'\nimport {recordTiming, recordEvent, recordError} from '../analytics.js'\nimport {ClientError, type Variables} from 'graphql-request'\nimport type {InlineToken, TokenItem} from '../ui.js'\n\nexport type ThemeParams = Partial<Pick<Theme, 'name' | 'role' | 'processing' | 'src'>>\nexport type AssetParams = Pick<ThemeAsset, 'key'> & Partial<Pick<ThemeAsset, 'value' | 'attachment'>>\nconst SkeletonThemeCdn = 'https://cdn.shopify.com/static/online-store/theme-skeleton.zip'\nconst THEME_API_NETWORK_BEHAVIOUR: RequestModeInput = {\n useNetworkLevelRetry: true,\n useAbortSignal: false,\n maxRetryTimeMs: 90 * 1000,\n recordCommandRetries: true,\n}\nconst DEFAULT_THEME_ACCESS_REQUIREMENT = 'the required theme access scope'\n\nexport async function fetchTheme(id: number, session: AdminSession): Promise<Theme | undefined> {\n const gid = composeThemeGid(id)\n recordEvent('theme-api:fetch-theme')\n\n try {\n const {theme} = await adminRequestDoc({\n query: GetTheme,\n session,\n variables: {id: gid},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (theme) {\n return buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n }\n\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n abortIfMissingThemeAccessScope(error)\n /**\n * Consumers of this and other theme APIs in this file expect either a theme\n * or `undefined`.\n *\n * Error handlers should not inspect GraphQL error messages directly, as\n * they are internationalized.\n */\n recordError(error)\n outputDebug(`Error fetching theme with ID: ${id}`)\n }\n}\n\nexport async function fetchThemes(session: AdminSession): Promise<Theme[]> {\n const themes: Theme[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-themes')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await requestThemeAdminDoc({\n query: GetThemes,\n session,\n variables: {after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!response.themes) {\n unexpectedGraphQLError('Failed to fetch themes')\n }\n const {nodes, pageInfo} = response.themes\n nodes.forEach((theme) => {\n const t = buildTheme({\n id: parseGid(theme.id),\n processing: theme.processing,\n role: theme.role.toLowerCase(),\n name: theme.name,\n })\n if (t) {\n themes.push(t)\n }\n })\n if (!pageInfo.hasNextPage) {\n return themes\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function findDevelopmentThemeByName(name: string, session: AdminSession): Promise<Theme | undefined> {\n recordEvent('theme-api:find-development-theme-by-name')\n\n const {themes} = await requestThemeAdminDoc({\n query: FindDevelopmentThemeByName,\n session,\n variables: {name},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themes) {\n unexpectedGraphQLError('Failed to fetch themes')\n }\n\n if (themes.nodes.length > 1) {\n throw recordError(new AbortError(`More than one development theme is named \"${name}\"`))\n }\n\n if (themes.nodes.length === 1) {\n const {id, processing, role, name} = themes.nodes[0]!\n\n return buildTheme({\n id: parseGid(id),\n processing,\n role: role.toLowerCase(),\n name,\n })\n }\n}\n\nexport async function themeCreate(params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const themeSource = params.src ?? SkeletonThemeCdn\n recordEvent('theme-api:create-theme')\n const {themeCreate} = await adminRequestDoc({\n query: ThemeCreate,\n session,\n variables: {\n name: params.name ?? '',\n source: themeSource,\n role: (params.role ?? DEVELOPMENT_THEME_ROLE).toUpperCase() as ThemeRole,\n },\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themeCreate) {\n unexpectedGraphQLError('Failed to create theme')\n }\n\n const {theme, userErrors} = themeCreate\n if (userErrors.length) {\n const userErrors = themeCreate.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n unexpectedGraphQLError('Failed to create theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function fetchThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<ThemeAsset[]> {\n const assets: ThemeAsset[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-assets')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await requestThemeAdminDoc({\n query: GetThemeFileBodies,\n session,\n variables: {id: themeGid(id), filenames, after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!response.theme?.files?.nodes || !response.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n unexpectedGraphQLError(`Error fetching assets: ${userErrors}`)\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n assets.push(\n // eslint-disable-next-line no-await-in-loop\n ...(await Promise.all(\n nodes.map(async (file) => {\n const {attachment, value} = await parseThemeFileContent(file.body)\n return {\n attachment,\n key: file.filename,\n checksum: file.checksumMd5 as string,\n value,\n }\n }),\n )),\n )\n\n if (!pageInfo.hasNextPage) {\n return assets\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function deleteThemeAssets(id: number, filenames: Key[], session: AdminSession): Promise<Result[]> {\n const batchSize = 50\n const results: Result[] = []\n recordEvent('theme-api:delete-assets')\n\n for (let i = 0; i < filenames.length; i += batchSize) {\n const batch = filenames.slice(i, i + batchSize)\n // eslint-disable-next-line no-await-in-loop\n const {themeFilesDelete} = await adminRequestDoc({\n query: ThemeFilesDelete,\n session,\n variables: {\n themeId: composeThemeGid(id),\n files: batch,\n },\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!themeFilesDelete) {\n unexpectedGraphQLError('Failed to delete theme assets')\n }\n\n const {deletedThemeFiles, userErrors} = themeFilesDelete\n\n if (deletedThemeFiles) {\n deletedThemeFiles.forEach((file) => {\n results.push({key: file.filename, success: true, operation: Operation.Delete})\n })\n }\n\n if (userErrors.length > 0) {\n userErrors.forEach((error) => {\n if (error.filename) {\n recordError(`Asset deletion failed for ${error.filename}: ${error.message}`)\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Delete,\n errors: {asset: [error.message]},\n })\n } else {\n unexpectedGraphQLError(`Failed to delete theme assets: ${error.message}`)\n }\n })\n }\n }\n\n return results\n}\n\nexport async function bulkUploadThemeAssets(\n id: number,\n assets: AssetParams[],\n session: AdminSession,\n): Promise<Result[]> {\n const results: Result[] = []\n recordEvent('theme-api:bulk-upload-assets')\n for (let i = 0; i < assets.length; i += 50) {\n const chunk = assets.slice(i, i + 50)\n const files = prepareFilesForUpload(chunk)\n\n recordTiming('theme-api:upload-files')\n // eslint-disable-next-line no-await-in-loop\n const uploadResults = await uploadFiles(id, files, session)\n recordTiming('theme-api:upload-files')\n\n results.push(...processUploadResults(uploadResults))\n }\n return results\n}\n\nfunction prepareFilesForUpload(assets: AssetParams[]): OnlineStoreThemeFilesUpsertFileInput[] {\n return assets.map((asset) => {\n if (asset.attachment) {\n return {\n filename: asset.key,\n body: {\n type: 'BASE64' as const,\n value: asset.attachment,\n },\n }\n } else {\n return {\n filename: asset.key,\n body: {\n type: 'TEXT' as const,\n value: asset.value ?? '',\n },\n }\n }\n })\n}\n\nasync function uploadFiles(\n themeId: number,\n files: {filename: string; body: {type: OnlineStoreThemeFileBodyInputType; value: string}}[],\n session: AdminSession,\n): Promise<ThemeFilesUpsertMutation> {\n return adminRequestDoc({\n query: ThemeFilesUpsert,\n session,\n variables: {themeId: themeGid(themeId), files},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n}\n\nfunction processUploadResults(uploadResults: ThemeFilesUpsertMutation): Result[] {\n const {themeFilesUpsert} = uploadResults\n\n if (!themeFilesUpsert) {\n unexpectedGraphQLError('Failed to upload theme files')\n }\n\n const {upsertedThemeFiles, userErrors} = themeFilesUpsert\n\n const results: Result[] = []\n\n upsertedThemeFiles?.forEach((file) => {\n results.push({\n key: file.filename,\n success: true,\n operation: Operation.Upload,\n })\n })\n\n userErrors.forEach((error) => {\n if (!error.filename) {\n unexpectedGraphQLError(`Error uploading theme files: ${error.message}`)\n }\n recordError(`Asset upload failed for ${error.filename}: ${error.message}`)\n results.push({\n key: error.filename,\n success: false,\n operation: Operation.Upload,\n errors: {asset: [error.message]},\n })\n })\n\n return results\n}\n\nexport async function fetchChecksums(id: number, session: AdminSession): Promise<Checksum[]> {\n const checksums: Checksum[] = []\n let after: string | null = null\n recordEvent('theme-api:fetch-checksums')\n\n while (true) {\n // eslint-disable-next-line no-await-in-loop\n const response = await requestThemeAdminDoc({\n query: GetThemeFileChecksums,\n session,\n variables: {id: themeGid(id), after},\n responseOptions: {handleErrors: false},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n\n if (!response?.theme?.files?.nodes || !response?.theme?.files?.pageInfo) {\n const userErrors = response.theme?.files?.userErrors.map((error) => error.filename).join(', ')\n throw recordError(new AbortError(`Failed to fetch checksums for: ${userErrors}`))\n }\n\n const {nodes, pageInfo} = response.theme.files\n\n checksums.push(\n ...nodes.map((file) => ({\n key: file.filename,\n checksum: file.checksumMd5 as string,\n })),\n )\n\n if (!pageInfo.hasNextPage) {\n return checksums\n }\n\n after = pageInfo.endCursor as string\n }\n}\n\nexport async function themeUpdate(id: number, params: ThemeParams, session: AdminSession): Promise<Theme | undefined> {\n const name = params.name\n const input: Record<string, string> = {}\n if (name) {\n input.name = name\n }\n recordEvent('theme-api:update-theme')\n\n const {themeUpdate} = await adminRequestDoc({\n query: ThemeUpdate,\n session,\n variables: {id: composeThemeGid(id), input},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themeUpdate) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themeUpdate\n if (userErrors.length) {\n const userErrors = themeUpdate.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themePublish(id: number, session: AdminSession): Promise<Theme | undefined> {\n recordEvent('theme-api:publish-theme')\n const {themePublish} = await adminRequestDoc({\n query: ThemePublish,\n session,\n variables: {id: composeThemeGid(id)},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themePublish) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {theme, userErrors} = themePublish\n if (userErrors.length) {\n const userErrors = themePublish.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!theme) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return buildTheme({\n id: parseGid(theme.id),\n name: theme.name,\n role: theme.role.toLowerCase(),\n })\n}\n\nexport async function themeDelete(id: number, session: AdminSession): Promise<boolean | undefined> {\n recordEvent('theme-api:delete-theme')\n const {themeDelete} = await adminRequestDoc({\n query: ThemeDelete,\n session,\n variables: {id: composeThemeGid(id)},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n })\n if (!themeDelete) {\n // An unexpected error occurred during the GraphQL request execution\n unexpectedGraphQLError('Failed to update theme')\n }\n\n const {deletedThemeId, userErrors} = themeDelete\n if (userErrors.length) {\n const userErrors = themeDelete.userErrors.map((error) => error.message).join(', ')\n throw recordError(new AbortError(userErrors))\n }\n\n if (!deletedThemeId) {\n // An unexpected error if neither theme nor userErrors are returned\n unexpectedGraphQLError('Failed to update theme')\n }\n\n return true\n}\n\nexport interface ThemeDuplicateResult {\n theme?: Theme\n userErrors: {field?: string[] | null; message: string}[]\n requestId?: string\n}\n\nexport async function themeDuplicate(\n id: number,\n name: string | undefined,\n session: AdminSession,\n): Promise<ThemeDuplicateResult> {\n let requestId: string | undefined\n recordEvent('theme-api:duplicate-theme')\n\n const {themeDuplicate} = await adminRequestDoc({\n query: ThemeDuplicate,\n session,\n variables: {id: composeThemeGid(id), name},\n preferredBehaviour: THEME_API_NETWORK_BEHAVIOUR,\n responseOptions: {\n onResponse: (response) => {\n requestId = response.headers.get('x-request-id') ?? undefined\n },\n },\n })\n\n if (!themeDuplicate) {\n // An unexpected error occurred during the GraphQL request execution\n recordError('Failed to duplicate theme')\n return {\n theme: undefined,\n userErrors: [{message: 'Failed to duplicate theme'}],\n requestId,\n }\n }\n\n const {newTheme, userErrors} = themeDuplicate\n\n if (userErrors.length > 0) {\n return {\n theme: undefined,\n userErrors,\n requestId,\n }\n }\n\n if (!newTheme) {\n // An unexpected error if neither theme nor userErrors are returned\n return {\n theme: undefined,\n userErrors: [{message: 'Failed to duplicate theme'}],\n requestId,\n }\n }\n\n const theme = buildTheme({\n id: parseGid(newTheme.id),\n name: newTheme.name,\n role: newTheme.role.toLowerCase(),\n })\n\n return {\n theme,\n userErrors: [],\n requestId,\n }\n}\n\nexport async function metafieldDefinitionsByOwnerType(type: MetafieldOwnerType, session: AdminSession) {\n recordEvent('theme-api:fetch-metafield-definitions')\n const {metafieldDefinitions} = await adminRequestDoc({\n query: MetafieldDefinitionsByOwnerType,\n session,\n variables: {ownerType: type},\n })\n\n return metafieldDefinitions.nodes.map((definition) => ({\n key: definition.key,\n namespace: definition.namespace,\n name: definition.name,\n description: definition.description,\n type: {\n name: definition.type.name,\n category: definition.type.category,\n },\n }))\n}\n\nexport async function passwordProtected(session: AdminSession): Promise<boolean> {\n recordEvent('theme-api:check-password-protection')\n const {onlineStore} = await adminRequestDoc({\n query: OnlineStorePasswordProtection,\n session,\n })\n if (!onlineStore) {\n unexpectedGraphQLError(\"Unable to get details about the storefront's password protection\")\n }\n\n const {passwordProtection} = onlineStore\n\n return passwordProtection.enabled\n}\n\nfunction unexpectedGraphQLError(message: string): never {\n throw recordError(new AbortError(message))\n}\n\nasync function requestThemeAdminDoc<TResult, TVariables extends Variables>(\n options: AdminRequestOptions<TResult, TVariables>,\n): Promise<TResult> {\n try {\n const response = await adminRequestDoc(options)\n return response\n } catch (error) {\n abortIfMissingThemeAccessScope(error)\n throw error\n }\n}\n\nfunction abortIfMissingThemeAccessScope(error: unknown): void {\n if (!(error instanceof ClientError)) return\n\n const requiredAccess = getThemeAccessRequirementForAccessDeniedError(error)\n if (!requiredAccess) return\n\n const nextSteps: TokenItem<InlineToken>[] = [\n [\n 'If you authenticated with an Admin API access token, update the app or integration that issued the token to include the required theme access scopes, then reauthorize it or generate a new token.',\n ],\n [\n 'For',\n {command: 'theme pull'},\n {char: ','},\n {command: 'theme list'},\n {char: ','},\n 'and',\n {command: 'theme info'},\n {char: ','},\n 'add the',\n {command: 'read_themes'},\n 'scope',\n {char: '.'},\n ],\n [\n 'For',\n {command: 'theme push'},\n 'and',\n {command: 'theme dev'},\n {char: ','},\n 'add both the',\n {command: 'read_themes'},\n 'and',\n {command: 'write_themes'},\n 'scopes',\n {char: '.'},\n ],\n [\n 'If you authenticated with your Shopify account, make sure your staff or collaborator account can access Online Store themes, then run',\n {command: 'shopify auth logout'},\n 'and try again',\n {char: '.'},\n ],\n ['See', {link: {label: 'Shopify access scopes', url: 'https://shopify.dev/api/usage/access-scopes'}}, {char: '.'}],\n ]\n\n throw recordError(\n new AbortError(`The authenticated account or access token is missing ${requiredAccess}.`, undefined, nextSteps),\n )\n}\n\nfunction getThemeAccessRequirementForAccessDeniedError(error: ClientError): string | undefined {\n const graphQLErrors = error.response.errors\n if (!Array.isArray(graphQLErrors)) return undefined\n\n const accessDeniedError = graphQLErrors.find((graphQLError) => graphQLError.extensions?.code === 'ACCESS_DENIED')\n if (!accessDeniedError) return undefined\n\n const requiredAccess = accessDeniedError.extensions?.requiredAccess\n if (typeof requiredAccess !== 'string') return DEFAULT_THEME_ACCESS_REQUIREMENT\n\n return requiredAccess.trim().replace(/\\.$/, '') || DEFAULT_THEME_ACCESS_REQUIREMENT\n}\n\nfunction themeGid(id: number): string {\n return `gid://shopify/OnlineStoreTheme/${id}`\n}\n\ntype OnlineStoreThemeFileBody =\n | {__typename: 'OnlineStoreThemeFileBodyBase64'; contentBase64: string}\n | {__typename: 'OnlineStoreThemeFileBodyText'; content: string}\n | {__typename: 'OnlineStoreThemeFileBodyUrl'; url: string}\n\nexport async function parseThemeFileContent(\n body: OnlineStoreThemeFileBody,\n): Promise<{value?: string; attachment?: string}> {\n switch (body.__typename) {\n case 'OnlineStoreThemeFileBodyText':\n return {value: body.content}\n case 'OnlineStoreThemeFileBodyBase64':\n return {attachment: body.contentBase64}\n case 'OnlineStoreThemeFileBodyUrl':\n try {\n // eslint-disable-next-line no-restricted-globals\n const response = await fetch(body.url)\n\n const arrayBuffer = await response.arrayBuffer()\n return {attachment: Buffer.from(arrayBuffer).toString('base64')}\n } catch (error) {\n // Raise error if we can't download the file\n throw recordError(new AbortError(`Error downloading content from URL: ${body.url}`))\n }\n }\n}\n"]}
@@ -1,9 +1,10 @@
1
1
  import { JsonMapType } from './codec.js';
2
+ import { AbortError } from '../error.js';
2
3
  /**
3
4
  * An error on a TOML file — missing or malformed.
4
- * Extends Error so it can be thrown. Carries path and a clean message suitable for JSON output.
5
+ * Carries path and a clean message suitable for JSON output.
5
6
  */
6
- export declare class TomlFileError extends Error {
7
+ export declare class TomlFileError extends AbortError {
7
8
  readonly path: string;
8
9
  constructor(path: string, message: string);
9
10
  }
@@ -1,11 +1,12 @@
1
1
  import { decodeToml, encodeToml } from './codec.js';
2
+ import { AbortError } from '../error.js';
2
3
  import { fileExists, readFile, writeFile } from '../fs.js';
3
4
  import { updateTomlValues } from '@shopify/toml-patch';
4
5
  /**
5
6
  * An error on a TOML file — missing or malformed.
6
- * Extends Error so it can be thrown. Carries path and a clean message suitable for JSON output.
7
+ * Carries path and a clean message suitable for JSON output.
7
8
  */
8
- export class TomlFileError extends Error {
9
+ export class TomlFileError extends AbortError {
9
10
  constructor(path, message) {
10
11
  super(message);
11
12
  this.name = 'TomlFileError';
@@ -1 +1 @@
1
- {"version":3,"file":"toml-file.js","sourceRoot":"","sources":["../../../../src/public/node/toml/toml-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,UAAU,EAAC,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,UAAU,CAAA;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAA;AAIpD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGtC,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,QAAQ;IACnB;;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GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAA;gBACxE,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,WAAW,WAAW,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAAE,CAAC,CAAA;YACzF,CAAC;YACD,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,SAAS,qBAAqB,CAAC,GAA6B,EAAE,SAAmB,EAAE;IACjF,MAAM,OAAO,GAAiC,EAAE,CAAA;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;QAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzE,OAAO,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,KAAiC,EAAE,IAAI,CAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAuB,CAAC,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import {JsonMapType, decodeToml, encodeToml} from './codec.js'\nimport {fileExists, readFile, writeFile} from '../fs.js'\nimport {updateTomlValues} from '@shopify/toml-patch'\n\ntype TomlPatchValue = string | number | boolean | undefined | (string | number | boolean)[]\n\n/**\n * An error on a TOML file — missing or malformed.\n * Extends Error so it can be thrown. Carries path and a clean message suitable for JSON output.\n */\nexport class TomlFileError extends Error {\n readonly path: string\n\n constructor(path: string, message: string) {\n super(message)\n this.name = 'TomlFileError'\n this.path = path\n }\n}\n\n/**\n * General-purpose TOML file abstraction.\n *\n * Provides a unified interface for reading, patching, removing keys from, and replacing\n * the content of TOML files on disk.\n *\n * - `read` populates content from disk\n * - `patch` does surgical WASM-based edits (preserves comments and formatting)\n * - `remove` deletes a key by dotted path (preserves comments and formatting)\n * - `replace` does a full re-serialization (comments and formatting are NOT preserved).\n * - `transformRaw` applies a function to the raw TOML string on disk.\n */\nexport class TomlFile {\n /**\n * Read and parse a TOML file from disk. Throws {@link TomlFileError} if the file\n * doesn't exist or contains invalid TOML.\n *\n * @param path - Absolute path to the TOML file.\n * @returns A TomlFile instance with parsed content.\n */\n static async read(path: string): Promise<TomlFile> {\n if (!(await fileExists(path))) {\n throw new TomlFileError(path, `TOML file not found: ${path}`)\n }\n const raw = await readFile(path)\n const file = new TomlFile(path, {})\n file.content = file.decode(raw)\n return file\n }\n\n readonly path: string\n content: JsonMapType\n readonly errors: TomlFileError[] = []\n\n constructor(path: string, content: JsonMapType) {\n this.path = path\n this.content = content\n }\n\n /**\n * Surgically patch values in the TOML file, preserving comments and formatting.\n *\n * Accepts a nested object whose leaf values are set in the TOML. Intermediate tables are\n * created automatically. Setting a leaf to `undefined` removes it (use `remove()` for a\n * clearer API when deleting keys).\n *\n * @example\n * ```ts\n * await file.patch({build: {dev_store_url: 'my-store.myshopify.com'}})\n * await file.patch({application_url: 'https://example.com', auth: {redirect_urls: ['...']}})\n * ```\n */\n async patch(changes: {[key: string]: unknown}): Promise<void> {\n const patches = flattenToPatchEntries(changes)\n const raw = await readFile(this.path)\n const updated = updateTomlValues(raw, patches)\n const parsed = this.decode(updated)\n await writeFile(this.path, updated)\n this.content = parsed\n }\n\n /**\n * Remove a key from the TOML file by dotted path, preserving comments and formatting.\n *\n * @param keyPath - Dotted key path to remove (e.g. 'build.include_config_on_deploy').\n * @example\n * ```ts\n * await file.remove('build.include_config_on_deploy')\n * ```\n */\n async remove(keyPath: string): Promise<void> {\n const keys = keyPath.split('.')\n const raw = await readFile(this.path)\n const updated = updateTomlValues(raw, [[keys, undefined]])\n const parsed = this.decode(updated)\n await writeFile(this.path, updated)\n this.content = parsed\n }\n\n /**\n * Replace the entire file content. The file is fully re-serialized — comments and formatting\n * are NOT preserved.\n *\n * @param content - The new content to write.\n * @example\n * ```ts\n * await file.replace({client_id: 'abc', name: 'My App'})\n * ```\n */\n async replace(content: JsonMapType): Promise<void> {\n const encoded = encodeToml(content)\n this.decode(encoded)\n await writeFile(this.path, encoded)\n this.content = content\n }\n\n /**\n * Transform the raw TOML string on disk. Reads the file, applies the transform function\n * to the raw text, writes back, and re-parses to keep `content` in sync.\n *\n * Use this for text-level operations that can't be expressed as structured edits —\n * e.g. Injecting comments or positional insertion of keys in arrays-of-tables.\n * Subsequent `patch()` calls will preserve any comments added this way.\n *\n * @param transform - A function that receives the raw TOML string and returns the modified string.\n * @example\n * ```ts\n * await file.transformRaw((raw) => `# Header comment\\n${raw}`)\n * ```\n */\n async transformRaw(transform: (raw: string) => string): Promise<void> {\n const raw = await readFile(this.path)\n const transformed = transform(raw)\n const parsed = this.decode(transformed)\n await writeFile(this.path, transformed)\n this.content = parsed\n }\n\n private decode(raw: string): JsonMapType {\n try {\n return decodeToml(raw)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n if (err.line !== undefined && err.col !== undefined) {\n const description = String(err.message).split('\\n')[0] ?? 'Invalid TOML'\n throw new TomlFileError(this.path, `${description} at row ${err.line}, col ${err.col}`)\n }\n throw err\n }\n }\n}\n\n/**\n * Flatten a nested object into an array of `[keyPath, value]` patch entries\n * suitable for `updateTomlValues`.\n *\n * @param obj - The nested object to flatten.\n * @param prefix - Key path prefix for recursion.\n * @returns Flattened patch entries.\n */\nfunction flattenToPatchEntries(obj: {[key: string]: unknown}, prefix: string[] = []): [string[], TomlPatchValue][] {\n const entries: [string[], TomlPatchValue][] = []\n for (const [key, value] of Object.entries(obj)) {\n const path = [...prefix, key]\n if (value !== null && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...flattenToPatchEntries(value as {[key: string]: unknown}, path))\n } else {\n entries.push([path, value as TomlPatchValue])\n }\n }\n return entries\n}\n"]}
1
+ {"version":3,"file":"toml-file.js","sourceRoot":"","sources":["../../../../src/public/node/toml/toml-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,UAAU,EAAE,UAAU,EAAC,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAC,MAAM,UAAU,CAAA;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAA;AAIpD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAG3C,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,QAAQ;IACnB;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAY;QAC5B,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,aAAa,CAAC,IAAI,EAAE,wBAAwB,IAAI,EAAE,CAAC,CAAA;QAC/D,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAA;QAChC,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACnC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC/B,OAAO,IAAI,CAAA;IACb,CAAC;IAMD,YAAY,IAAY,EAAE,OAAoB;QAFrC,WAAM,GAAoB,EAAE,CAAA;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IAAI,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,CAAA;QAC7B,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzE,OAAO,CAAC,IAAI,CAAC,GAAG,qBAAqB,CAAC,KAAiC,EAAE,IAAI,CAAC,CAAC,CAAA;QACjF,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAuB,CAAC,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import {JsonMapType, decodeToml, encodeToml} from './codec.js'\nimport {AbortError} from '../error.js'\nimport {fileExists, readFile, writeFile} from '../fs.js'\nimport {updateTomlValues} from '@shopify/toml-patch'\n\ntype TomlPatchValue = string | number | boolean | undefined | (string | number | boolean)[]\n\n/**\n * An error on a TOML file — missing or malformed.\n * Carries path and a clean message suitable for JSON output.\n */\nexport class TomlFileError extends AbortError {\n readonly path: string\n\n constructor(path: string, message: string) {\n super(message)\n this.name = 'TomlFileError'\n this.path = path\n }\n}\n\n/**\n * General-purpose TOML file abstraction.\n *\n * Provides a unified interface for reading, patching, removing keys from, and replacing\n * the content of TOML files on disk.\n *\n * - `read` populates content from disk\n * - `patch` does surgical WASM-based edits (preserves comments and formatting)\n * - `remove` deletes a key by dotted path (preserves comments and formatting)\n * - `replace` does a full re-serialization (comments and formatting are NOT preserved).\n * - `transformRaw` applies a function to the raw TOML string on disk.\n */\nexport class TomlFile {\n /**\n * Read and parse a TOML file from disk. Throws {@link TomlFileError} if the file\n * doesn't exist or contains invalid TOML.\n *\n * @param path - Absolute path to the TOML file.\n * @returns A TomlFile instance with parsed content.\n */\n static async read(path: string): Promise<TomlFile> {\n if (!(await fileExists(path))) {\n throw new TomlFileError(path, `TOML file not found: ${path}`)\n }\n const raw = await readFile(path)\n const file = new TomlFile(path, {})\n file.content = file.decode(raw)\n return file\n }\n\n readonly path: string\n content: JsonMapType\n readonly errors: TomlFileError[] = []\n\n constructor(path: string, content: JsonMapType) {\n this.path = path\n this.content = content\n }\n\n /**\n * Surgically patch values in the TOML file, preserving comments and formatting.\n *\n * Accepts a nested object whose leaf values are set in the TOML. Intermediate tables are\n * created automatically. Setting a leaf to `undefined` removes it (use `remove()` for a\n * clearer API when deleting keys).\n *\n * @example\n * ```ts\n * await file.patch({build: {dev_store_url: 'my-store.myshopify.com'}})\n * await file.patch({application_url: 'https://example.com', auth: {redirect_urls: ['...']}})\n * ```\n */\n async patch(changes: {[key: string]: unknown}): Promise<void> {\n const patches = flattenToPatchEntries(changes)\n const raw = await readFile(this.path)\n const updated = updateTomlValues(raw, patches)\n const parsed = this.decode(updated)\n await writeFile(this.path, updated)\n this.content = parsed\n }\n\n /**\n * Remove a key from the TOML file by dotted path, preserving comments and formatting.\n *\n * @param keyPath - Dotted key path to remove (e.g. 'build.include_config_on_deploy').\n * @example\n * ```ts\n * await file.remove('build.include_config_on_deploy')\n * ```\n */\n async remove(keyPath: string): Promise<void> {\n const keys = keyPath.split('.')\n const raw = await readFile(this.path)\n const updated = updateTomlValues(raw, [[keys, undefined]])\n const parsed = this.decode(updated)\n await writeFile(this.path, updated)\n this.content = parsed\n }\n\n /**\n * Replace the entire file content. The file is fully re-serialized — comments and formatting\n * are NOT preserved.\n *\n * @param content - The new content to write.\n * @example\n * ```ts\n * await file.replace({client_id: 'abc', name: 'My App'})\n * ```\n */\n async replace(content: JsonMapType): Promise<void> {\n const encoded = encodeToml(content)\n this.decode(encoded)\n await writeFile(this.path, encoded)\n this.content = content\n }\n\n /**\n * Transform the raw TOML string on disk. Reads the file, applies the transform function\n * to the raw text, writes back, and re-parses to keep `content` in sync.\n *\n * Use this for text-level operations that can't be expressed as structured edits —\n * e.g. Injecting comments or positional insertion of keys in arrays-of-tables.\n * Subsequent `patch()` calls will preserve any comments added this way.\n *\n * @param transform - A function that receives the raw TOML string and returns the modified string.\n * @example\n * ```ts\n * await file.transformRaw((raw) => `# Header comment\\n${raw}`)\n * ```\n */\n async transformRaw(transform: (raw: string) => string): Promise<void> {\n const raw = await readFile(this.path)\n const transformed = transform(raw)\n const parsed = this.decode(transformed)\n await writeFile(this.path, transformed)\n this.content = parsed\n }\n\n private decode(raw: string): JsonMapType {\n try {\n return decodeToml(raw)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (err: any) {\n if (err.line !== undefined && err.col !== undefined) {\n const description = String(err.message).split('\\n')[0] ?? 'Invalid TOML'\n throw new TomlFileError(this.path, `${description} at row ${err.line}, col ${err.col}`)\n }\n throw err\n }\n }\n}\n\n/**\n * Flatten a nested object into an array of `[keyPath, value]` patch entries\n * suitable for `updateTomlValues`.\n *\n * @param obj - The nested object to flatten.\n * @param prefix - Key path prefix for recursion.\n * @returns Flattened patch entries.\n */\nfunction flattenToPatchEntries(obj: {[key: string]: unknown}, prefix: string[] = []): [string[], TomlPatchValue][] {\n const entries: [string[], TomlPatchValue][] = []\n for (const [key, value] of Object.entries(obj)) {\n const path = [...prefix, key]\n if (value !== null && typeof value === 'object' && !Array.isArray(value)) {\n entries.push(...flattenToPatchEntries(value as {[key: string]: unknown}, path))\n } else {\n entries.push([path, value as TomlPatchValue])\n }\n }\n return entries\n}\n"]}