@graphcommerce/next-config 11.0.0-canary.56 → 11.0.0-canary.58
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/CHANGELOG.md +10 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +1 -1
- package/__tests__/config/utils/replaceConfigInString.ts +1 -1
- package/dist/config/loadConfig.js +1 -1
- package/dist/generated/config.js +9 -8
- package/dist/index.js +13 -21
- package/dist/{loadConfig-S8JJz4LU.js → loadConfig-CGJPuSxu.js} +9 -12
- package/package.json +18 -20
- package/src/commands/generateConfig.ts +15 -16
- package/src/config/utils/mergeEnvIntoConfig.ts +15 -31
- package/src/generated/config.ts +42 -40
- package/src/interceptors/parseStructure.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 11.0.0-canary.58
|
|
4
|
+
|
|
5
|
+
## 11.0.0-canary.57
|
|
6
|
+
|
|
7
|
+
### Patch Changes
|
|
8
|
+
|
|
9
|
+
- [#2708](https://github.com/graphcommerce-org/graphcommerce/pull/2708) [`f0d0e93`](https://github.com/graphcommerce-org/graphcommerce/commit/f0d0e93b59adfc8b32fc0777727300675aaa48fb) - `@graphcommerce/next-config` and `@graphcommerce/hygraph-cli` require `dotenv` 18. `@graphcommerce/prettier-config-pwa` requires `prettier` 3.5.3: with Prettier 3.6 and later, only the last plugin formats the file, so the imports are not sorted. ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
11
|
+
- [#2708](https://github.com/graphcommerce-org/graphcommerce/pull/2708) [`38061a5`](https://github.com/graphcommerce-org/graphcommerce/commit/38061a5b4681ea0b77b88cf19e32e5a69f052218) - Uses Zod 4. The generated `*Schema()` functions in `@graphcommerce/next-config/config` return the inferred Zod 4 schema types. ([@paales](https://github.com/paales))
|
|
12
|
+
|
|
3
13
|
## 11.0.0-canary.56
|
|
4
14
|
|
|
5
15
|
## 11.0.0-canary.55
|
|
@@ -68,7 +68,7 @@ it('correctly validates if a value is JSON', () => {
|
|
|
68
68
|
})
|
|
69
69
|
expect(result.success).toBe(false)
|
|
70
70
|
if (!result.success) {
|
|
71
|
-
expect(result.error.
|
|
71
|
+
expect(result.error.issues).toMatchInlineSnapshot(`
|
|
72
72
|
[
|
|
73
73
|
{
|
|
74
74
|
"code": "custom",
|
|
@@ -5,7 +5,7 @@ import 'node:module';
|
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'node:worker_threads';
|
|
7
7
|
import '../generated/config.js';
|
|
8
|
-
export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-
|
|
8
|
+
export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-CGJPuSxu.js';
|
|
9
9
|
import 'zod';
|
|
10
10
|
import '@apollo/client/utilities/internal';
|
|
11
11
|
import 'chalk';
|
package/dist/generated/config.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod';
|
|
2
2
|
|
|
3
3
|
const isDefinedNonNullAny = (v) => v !== void 0 && v !== null;
|
|
4
4
|
const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v));
|
|
5
5
|
const BillingAddressPermissionsSchema = z.enum(["EDITABLE", "READONLY"]);
|
|
6
6
|
const CartPermissionsSchema = z.enum(["CUSTOMER_ONLY", "DISABLED", "ENABLED"]);
|
|
7
|
-
const CompareVariantSchema = z.enum([
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"DISABLED",
|
|
11
|
-
"DISABLE_REGISTRATION",
|
|
12
|
-
"ENABLED"
|
|
7
|
+
const CompareVariantSchema = z.enum([
|
|
8
|
+
"CHECKBOX",
|
|
9
|
+
"ICON"
|
|
13
10
|
]);
|
|
11
|
+
const ContainerSizingSchema = z.enum(["BREAKPOINT", "FULL_WIDTH"]);
|
|
12
|
+
const CustomerAccountPermissionsSchema = z.enum(["DISABLED", "DISABLE_REGISTRATION", "ENABLED"]);
|
|
14
13
|
const PaginationVariantSchema = z.enum(["COMPACT", "EXTENDED"]);
|
|
15
14
|
const ProductFiltersLayoutSchema = z.enum(["DEFAULT", "SIDEBAR"]);
|
|
16
15
|
const SidebarGalleryPaginationVariantSchema = z.enum(["DOTS", "THUMBNAILS_BOTTOM"]);
|
|
@@ -28,7 +27,9 @@ function GraphCommerceConfigSchema() {
|
|
|
28
27
|
compare: z.boolean().nullish(),
|
|
29
28
|
compareVariant: CompareVariantSchema.nullish().default("ICON"),
|
|
30
29
|
configurableVariantForSimple: z.boolean().nullish().default(false),
|
|
31
|
-
configurableVariantValues: z.lazy(
|
|
30
|
+
configurableVariantValues: z.lazy(
|
|
31
|
+
() => MagentoConfigurableVariantValuesSchema().nullish().default({ url: true, content: true })
|
|
32
|
+
),
|
|
32
33
|
containerSizingContent: ContainerSizingSchema.nullish().default("FULL_WIDTH"),
|
|
33
34
|
containerSizingShell: ContainerSizingSchema.nullish().default("FULL_WIDTH"),
|
|
34
35
|
crossSellsHideCartItems: z.boolean().nullish().default(false),
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@ import path from 'path';
|
|
|
4
4
|
import { glob, sync } from 'glob';
|
|
5
5
|
import { findParentPath } from './utils/findParentPath.js';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
|
-
import { l as loadConfig, t as toEnvStr } from './loadConfig-
|
|
8
|
-
export { r as replaceConfigInString } from './loadConfig-
|
|
7
|
+
import { l as loadConfig, t as toEnvStr } from './loadConfig-CGJPuSxu.js';
|
|
8
|
+
export { r as replaceConfigInString } from './loadConfig-CGJPuSxu.js';
|
|
9
9
|
import { parseFileSync, parseSync as parseSync$1, transformFileSync } from '@swc/core';
|
|
10
|
-
import fs$1, {
|
|
10
|
+
import fs$1, { readFileSync, writeFileSync, rmSync, mkdirSync, existsSync } from 'fs';
|
|
11
11
|
import { resolve as resolve$2 } from 'import-meta-resolve';
|
|
12
12
|
import assert from 'assert';
|
|
13
13
|
import crypto from 'crypto';
|
|
@@ -504,7 +504,7 @@ function parseStructure(ast, gcConfig, sourceModule) {
|
|
|
504
504
|
const parsed = pluginConfigParsed.safeParse(config);
|
|
505
505
|
if (!parsed.success) {
|
|
506
506
|
if (errors.length)
|
|
507
|
-
console.error(parsed.error.
|
|
507
|
+
console.error(parsed.error.issues.map((e) => `${e.path} ${e.message}`).join("\n"));
|
|
508
508
|
return void 0;
|
|
509
509
|
}
|
|
510
510
|
let enabled = true;
|
|
@@ -1413,8 +1413,7 @@ async function generateConfig() {
|
|
|
1413
1413
|
[targetTs]: {
|
|
1414
1414
|
plugins: ["typescript", "typescript-validation-schema"],
|
|
1415
1415
|
config: {
|
|
1416
|
-
|
|
1417
|
-
schema: "zod",
|
|
1416
|
+
schema: "zodv4",
|
|
1418
1417
|
notAllowEmptyString: true,
|
|
1419
1418
|
strictScalars: true,
|
|
1420
1419
|
enumsAsTypes: true,
|
|
@@ -1432,23 +1431,16 @@ async function generateConfig() {
|
|
|
1432
1431
|
}
|
|
1433
1432
|
}
|
|
1434
1433
|
});
|
|
1434
|
+
const schemaTs = readFileSync(targetTs, "utf-8").replace(/\.default\(([^()]+)\)\.nullish\(\)/g, ".nullish().default($1)").replace(/\):\s*z\.Zod(?:Object|Type)<\s*(?:Properties<)?\w+>?\s*>\s*\{/g, ") {").replace(/type Properties<T> = \{[^}]*\};?\n/, "");
|
|
1435
1435
|
writeFileSync(
|
|
1436
1436
|
targetTs,
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
{
|
|
1445
|
-
...prettierConf,
|
|
1446
|
-
parser: "typescript",
|
|
1447
|
-
plugins: prettierConf.plugins?.filter(
|
|
1448
|
-
(p) => typeof p === "string" && !p.includes("prettier-plugin-sort-imports")
|
|
1449
|
-
)
|
|
1450
|
-
}
|
|
1451
|
-
)
|
|
1437
|
+
await prettier.format(schemaTs, {
|
|
1438
|
+
...prettierConf,
|
|
1439
|
+
parser: "typescript",
|
|
1440
|
+
plugins: prettierConf.plugins?.filter(
|
|
1441
|
+
(p) => typeof p === "string" && !p.includes("prettier-plugin-sort-imports")
|
|
1442
|
+
)
|
|
1443
|
+
})
|
|
1452
1444
|
);
|
|
1453
1445
|
const result = transformFileSync(targetTs, {
|
|
1454
1446
|
module: { type: "nodenext" },
|
|
@@ -8,7 +8,7 @@ import { GraphCommerceConfigSchema } from './generated/config.js';
|
|
|
8
8
|
import { cloneDeep, mergeDeep } from '@apollo/client/utilities/internal';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
10
|
import lodash from 'lodash';
|
|
11
|
-
import { z,
|
|
11
|
+
import { z, ZodPipe, ZodOptional, ZodNullable, ZodDefault, ZodLazy, ZodObject, ZodArray, ZodNumber, ZodString, ZodEnum, ZodBoolean } from 'zod';
|
|
12
12
|
|
|
13
13
|
const demoConfig = {
|
|
14
14
|
canonicalBaseUrl: "https://graphcommerce.vercel.app",
|
|
@@ -109,8 +109,8 @@ function configToEnvSchema(schema) {
|
|
|
109
109
|
function walk(incomming, path = []) {
|
|
110
110
|
let node = incomming;
|
|
111
111
|
while (true) {
|
|
112
|
-
if (node instanceof
|
|
113
|
-
node = node.
|
|
112
|
+
if (node instanceof ZodPipe) {
|
|
113
|
+
node = node.in;
|
|
114
114
|
continue;
|
|
115
115
|
}
|
|
116
116
|
if (node instanceof ZodOptional) {
|
|
@@ -122,30 +122,27 @@ function configToEnvSchema(schema) {
|
|
|
122
122
|
continue;
|
|
123
123
|
}
|
|
124
124
|
if (node instanceof ZodDefault) {
|
|
125
|
-
node = node.
|
|
125
|
+
node = node.unwrap();
|
|
126
126
|
continue;
|
|
127
127
|
}
|
|
128
128
|
if (node instanceof ZodLazy) {
|
|
129
|
-
node = node.
|
|
129
|
+
node = node.unwrap();
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
132
|
break;
|
|
133
133
|
}
|
|
134
134
|
if (node instanceof ZodObject) {
|
|
135
135
|
if (path.length > 0) {
|
|
136
|
-
envSchema[toEnvStr(path)] = z.string().optional().refine(isJSON, {
|
|
136
|
+
envSchema[toEnvStr(path)] = z.string().optional().refine(isJSON, { error: "Invalid JSON" }).transform((val) => val ? JSON.parse(val) : val);
|
|
137
137
|
envToDot[toEnvStr(path)] = dotNotation(path);
|
|
138
138
|
}
|
|
139
|
-
|
|
140
|
-
Object.keys(typeNode.shape).forEach((key) => {
|
|
141
|
-
walk(typeNode.shape[key], [...path, key]);
|
|
142
|
-
});
|
|
139
|
+
Object.entries(node.shape).forEach(([key, value]) => walk(value, [...path, key]));
|
|
143
140
|
return;
|
|
144
141
|
}
|
|
145
142
|
if (node instanceof ZodArray) {
|
|
146
143
|
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
147
144
|
if (path.length > 0) {
|
|
148
|
-
envSchema[toEnvStr(path)] = z.string().optional().refine(isJSON, {
|
|
145
|
+
envSchema[toEnvStr(path)] = z.string().optional().refine(isJSON, { error: "Invalid JSON" }).transform((val) => val ? JSON.parse(val) : val);
|
|
149
146
|
envToDot[toEnvStr(path)] = dotNotation(path);
|
|
150
147
|
}
|
|
151
148
|
arr.forEach((key) => {
|
|
@@ -187,7 +184,7 @@ function mergeEnvIntoConfig(schema, config, env) {
|
|
|
187
184
|
const result = envSchema.safeParse(filteredEnv);
|
|
188
185
|
const applyResult = [];
|
|
189
186
|
if (!result.success) {
|
|
190
|
-
Object.entries(result.error
|
|
187
|
+
Object.entries(z.flattenError(result.error).fieldErrors).forEach(([envVar, error]) => {
|
|
191
188
|
const dotVar = envToDot[envVar];
|
|
192
189
|
const envValue = filteredEnv[envVar];
|
|
193
190
|
applyResult.push({ envVar, envValue, dotVar, error });
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-config",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "11.0.0-canary.
|
|
5
|
+
"version": "11.0.0-canary.58",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
@@ -44,32 +44,30 @@
|
|
|
44
44
|
"prepack": "pkgroll --clean-dist"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@graphql-codegen/cli": "6.1
|
|
48
|
-
"@swc/core": "1.
|
|
49
|
-
"@swc/wasm-web": "^1.
|
|
47
|
+
"@graphql-codegen/cli": "6.3.1",
|
|
48
|
+
"@swc/core": "1.16.21",
|
|
49
|
+
"@swc/wasm-web": "^1.16.21",
|
|
50
50
|
"@types/js-yaml": "^4.0.9",
|
|
51
|
-
"@types/lodash": "^4.17.
|
|
52
|
-
"chalk": "^
|
|
53
|
-
"cosmiconfig": "^
|
|
51
|
+
"@types/lodash": "^4.17.27",
|
|
52
|
+
"chalk": "^6.0.1",
|
|
53
|
+
"cosmiconfig": "^10.0.1",
|
|
54
54
|
"fast-glob": "^3.3.3",
|
|
55
|
-
"glob": "^
|
|
56
|
-
"graphql": "^16.
|
|
57
|
-
"import-meta-resolve": "^4.
|
|
58
|
-
"js-yaml": "^
|
|
55
|
+
"glob": "^14.0.3",
|
|
56
|
+
"graphql": "^16.14.2",
|
|
57
|
+
"import-meta-resolve": "^4.2.0",
|
|
58
|
+
"js-yaml": "^5.5.0",
|
|
59
59
|
"js-yaml-loader": "^1.2.2",
|
|
60
|
-
"lodash": "^4.
|
|
61
|
-
"react": "^19.
|
|
62
|
-
"typescript": "
|
|
63
|
-
"
|
|
64
|
-
"zod": "^3.25.76"
|
|
60
|
+
"lodash": "^4.18.1",
|
|
61
|
+
"react": "^19.3.1",
|
|
62
|
+
"typescript": "6.0.3",
|
|
63
|
+
"zod": "^4.6.7"
|
|
65
64
|
},
|
|
66
65
|
"peerDependencies": {
|
|
67
66
|
"@apollo/client": "*",
|
|
68
|
-
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.
|
|
67
|
+
"@graphcommerce/prettier-config-pwa": "^11.0.0-canary.58",
|
|
69
68
|
"@lingui/loader": "*",
|
|
70
|
-
"@lingui/macro": "*",
|
|
71
69
|
"@lingui/react": "*",
|
|
72
|
-
"dotenv": "^
|
|
70
|
+
"dotenv": "^18",
|
|
73
71
|
"next": "*",
|
|
74
72
|
"prettier": "^3"
|
|
75
73
|
},
|
|
@@ -84,6 +82,6 @@
|
|
|
84
82
|
}
|
|
85
83
|
},
|
|
86
84
|
"devDependencies": {
|
|
87
|
-
"pkgroll": "^2.
|
|
85
|
+
"pkgroll": "^2.29.0"
|
|
88
86
|
}
|
|
89
87
|
}
|
|
@@ -33,8 +33,7 @@ export async function generateConfig() {
|
|
|
33
33
|
[targetTs]: {
|
|
34
34
|
plugins: ['typescript', 'typescript-validation-schema'],
|
|
35
35
|
config: {
|
|
36
|
-
|
|
37
|
-
schema: 'zod',
|
|
36
|
+
schema: 'zodv4',
|
|
38
37
|
notAllowEmptyString: true,
|
|
39
38
|
strictScalars: true,
|
|
40
39
|
enumsAsTypes: true,
|
|
@@ -53,23 +52,23 @@ export async function generateConfig() {
|
|
|
53
52
|
},
|
|
54
53
|
})
|
|
55
54
|
|
|
55
|
+
// typescript-validation-schema writes `.default(x).nullish()`: `.nullish()` returns undefined
|
|
56
|
+
// before `.default()` runs. The zodv4 return types `z.ZodObject<Properties<T>>` make each
|
|
57
|
+
// optional key required in the inferred output.
|
|
58
|
+
const schemaTs = readFileSync(targetTs, 'utf-8')
|
|
59
|
+
.replace(/\.default\(([^()]+)\)\.nullish\(\)/g, '.nullish().default($1)')
|
|
60
|
+
.replace(/\):\s*z\.Zod(?:Object|Type)<\s*(?:Properties<)?\w+>?\s*>\s*\{/g, ') {')
|
|
61
|
+
.replace(/type Properties<T> = \{[^}]*\};?\n/, '')
|
|
62
|
+
|
|
56
63
|
writeFileSync(
|
|
57
64
|
targetTs,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'.nullish().default($1)',
|
|
65
|
+
await prettier.format(schemaTs, {
|
|
66
|
+
...prettierConf,
|
|
67
|
+
parser: 'typescript',
|
|
68
|
+
plugins: prettierConf.plugins?.filter(
|
|
69
|
+
(p) => typeof p === 'string' && !p.includes('prettier-plugin-sort-imports'),
|
|
64
70
|
),
|
|
65
|
-
|
|
66
|
-
...prettierConf,
|
|
67
|
-
parser: 'typescript',
|
|
68
|
-
plugins: prettierConf.plugins?.filter(
|
|
69
|
-
(p) => typeof p === 'string' && !p.includes('prettier-plugin-sort-imports'),
|
|
70
|
-
),
|
|
71
|
-
},
|
|
72
|
-
),
|
|
71
|
+
}),
|
|
73
72
|
)
|
|
74
73
|
|
|
75
74
|
const result = transformFileSync(targetTs, {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { cloneDeep, mergeDeep } from '@apollo/client/utilities/internal'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import lodash from 'lodash'
|
|
4
|
-
import type {
|
|
4
|
+
import type { core } from 'zod'
|
|
5
5
|
import {
|
|
6
6
|
z,
|
|
7
7
|
ZodArray,
|
|
8
8
|
ZodBoolean,
|
|
9
9
|
ZodDefault,
|
|
10
|
-
ZodEffects,
|
|
11
10
|
ZodEnum,
|
|
12
11
|
ZodLazy,
|
|
13
12
|
ZodNullable,
|
|
14
13
|
ZodNumber,
|
|
15
14
|
ZodObject,
|
|
16
15
|
ZodOptional,
|
|
16
|
+
ZodPipe,
|
|
17
17
|
ZodString,
|
|
18
18
|
} from 'zod'
|
|
19
19
|
import diff from './diff'
|
|
@@ -42,30 +42,18 @@ function isJSON(str: string | undefined): boolean {
|
|
|
42
42
|
return true
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
| ZodOptional<ZodTypeAny>
|
|
48
|
-
| ZodEffects<ZodTypeAny>
|
|
49
|
-
| ZodObject<ZodRawShape>
|
|
50
|
-
| ZodArray<ZodTypeAny>
|
|
51
|
-
| ZodLazy<ZodTypeAny>
|
|
52
|
-
| ZodString
|
|
53
|
-
| ZodNumber
|
|
54
|
-
| ZodBoolean
|
|
55
|
-
| ZodAny
|
|
56
|
-
|
|
57
|
-
export function configToEnvSchema(schema: ZodNode) {
|
|
58
|
-
const envSchema: ZodRawShape = {}
|
|
45
|
+
export function configToEnvSchema(schema: core.$ZodType) {
|
|
46
|
+
const envSchema: Record<string, core.$ZodType> = {}
|
|
59
47
|
const envToDot: Record<string, string> = {}
|
|
60
48
|
|
|
61
|
-
function walk(incomming:
|
|
49
|
+
function walk(incomming: core.$ZodType, path: string[] = []) {
|
|
62
50
|
let node = incomming
|
|
63
51
|
|
|
64
52
|
// Unwrap wrapper types in a loop to handle chained wrappers (e.g., ZodLazy containing ZodOptional)
|
|
65
53
|
// eslint-disable-next-line no-constant-condition
|
|
66
54
|
while (true) {
|
|
67
|
-
if (node instanceof
|
|
68
|
-
node = node.
|
|
55
|
+
if (node instanceof ZodPipe) {
|
|
56
|
+
node = node.in
|
|
69
57
|
continue
|
|
70
58
|
}
|
|
71
59
|
if (node instanceof ZodOptional) {
|
|
@@ -77,11 +65,11 @@ export function configToEnvSchema(schema: ZodNode) {
|
|
|
77
65
|
continue
|
|
78
66
|
}
|
|
79
67
|
if (node instanceof ZodDefault) {
|
|
80
|
-
node = node.
|
|
68
|
+
node = node.unwrap()
|
|
81
69
|
continue
|
|
82
70
|
}
|
|
83
71
|
if (node instanceof ZodLazy) {
|
|
84
|
-
node = node.
|
|
72
|
+
node = node.unwrap()
|
|
85
73
|
continue
|
|
86
74
|
}
|
|
87
75
|
break
|
|
@@ -92,16 +80,12 @@ export function configToEnvSchema(schema: ZodNode) {
|
|
|
92
80
|
envSchema[toEnvStr(path)] = z
|
|
93
81
|
.string()
|
|
94
82
|
.optional()
|
|
95
|
-
.refine(isJSON, {
|
|
83
|
+
.refine(isJSON, { error: 'Invalid JSON' })
|
|
96
84
|
.transform((val) => (val ? JSON.parse(val) : val))
|
|
97
85
|
envToDot[toEnvStr(path)] = dotNotation(path)
|
|
98
86
|
}
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
Object.keys(typeNode.shape).forEach((key) => {
|
|
103
|
-
walk(typeNode.shape[key], [...path, key])
|
|
104
|
-
})
|
|
88
|
+
Object.entries(node.shape).forEach(([key, value]) => walk(value, [...path, key]))
|
|
105
89
|
|
|
106
90
|
return
|
|
107
91
|
}
|
|
@@ -112,13 +96,13 @@ export function configToEnvSchema(schema: ZodNode) {
|
|
|
112
96
|
envSchema[toEnvStr(path)] = z
|
|
113
97
|
.string()
|
|
114
98
|
.optional()
|
|
115
|
-
.refine(isJSON, {
|
|
99
|
+
.refine(isJSON, { error: 'Invalid JSON' })
|
|
116
100
|
.transform((val) => (val ? JSON.parse(val) : val))
|
|
117
101
|
envToDot[toEnvStr(path)] = dotNotation(path)
|
|
118
102
|
}
|
|
119
103
|
|
|
120
104
|
arr.forEach((key) => {
|
|
121
|
-
walk(
|
|
105
|
+
walk(node.element, [...path, String(key)])
|
|
122
106
|
})
|
|
123
107
|
|
|
124
108
|
return
|
|
@@ -173,7 +157,7 @@ const filterEnv = (env: Record<string, string | undefined>) =>
|
|
|
173
157
|
Object.fromEntries(Object.entries(env).filter(([key]) => key.startsWith('GC_')))
|
|
174
158
|
|
|
175
159
|
export function mergeEnvIntoConfig(
|
|
176
|
-
schema:
|
|
160
|
+
schema: core.$ZodType,
|
|
177
161
|
config: Record<string, unknown>,
|
|
178
162
|
env: Record<string, string | undefined>,
|
|
179
163
|
) {
|
|
@@ -186,7 +170,7 @@ export function mergeEnvIntoConfig(
|
|
|
186
170
|
const applyResult: ApplyResult = []
|
|
187
171
|
|
|
188
172
|
if (!result.success) {
|
|
189
|
-
Object.entries(result.error
|
|
173
|
+
Object.entries(z.flattenError(result.error).fieldErrors).forEach(([envVar, error]) => {
|
|
190
174
|
const dotVar = envToDot[envVar]
|
|
191
175
|
const envValue = filteredEnv[envVar]
|
|
192
176
|
applyResult.push({ envVar, envValue, dotVar, error })
|
package/src/generated/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod'
|
|
2
2
|
export type Maybe<T> = T | null
|
|
3
3
|
export type InputMaybe<T> = Maybe<T>
|
|
4
4
|
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }
|
|
@@ -560,45 +560,57 @@ export type SidebarGalleryPaginationVariant = 'DOTS' | 'THUMBNAILS_BOTTOM'
|
|
|
560
560
|
|
|
561
561
|
export type WebsitePermissions = 'ENABLED'
|
|
562
562
|
|
|
563
|
-
type Properties<T> = Required<{
|
|
564
|
-
[K in keyof T]: z.ZodType<T[K], any, T[K]>
|
|
565
|
-
}>
|
|
566
|
-
|
|
567
563
|
type definedNonNullAny = {}
|
|
568
564
|
|
|
569
565
|
export const isDefinedNonNullAny = (v: any): v is definedNonNullAny => v !== undefined && v !== null
|
|
570
566
|
|
|
571
567
|
export const definedNonNullAnySchema = z.any().refine((v) => isDefinedNonNullAny(v))
|
|
572
568
|
|
|
573
|
-
export const BillingAddressPermissionsSchema
|
|
569
|
+
export const BillingAddressPermissionsSchema: z.ZodType<
|
|
570
|
+
'EDITABLE' | 'READONLY',
|
|
571
|
+
'EDITABLE' | 'READONLY'
|
|
572
|
+
> = z.enum(['EDITABLE', 'READONLY'])
|
|
574
573
|
|
|
575
|
-
export const CartPermissionsSchema
|
|
574
|
+
export const CartPermissionsSchema: z.ZodType<
|
|
575
|
+
'CUSTOMER_ONLY' | 'DISABLED' | 'ENABLED',
|
|
576
|
+
'CUSTOMER_ONLY' | 'DISABLED' | 'ENABLED'
|
|
577
|
+
> = z.enum(['CUSTOMER_ONLY', 'DISABLED', 'ENABLED'])
|
|
576
578
|
|
|
577
|
-
export const CompareVariantSchema
|
|
579
|
+
export const CompareVariantSchema: z.ZodType<'CHECKBOX' | 'ICON', 'CHECKBOX' | 'ICON'> = z.enum([
|
|
580
|
+
'CHECKBOX',
|
|
581
|
+
'ICON',
|
|
582
|
+
])
|
|
578
583
|
|
|
579
|
-
export const ContainerSizingSchema
|
|
584
|
+
export const ContainerSizingSchema: z.ZodType<
|
|
585
|
+
'BREAKPOINT' | 'FULL_WIDTH',
|
|
586
|
+
'BREAKPOINT' | 'FULL_WIDTH'
|
|
587
|
+
> = z.enum(['BREAKPOINT', 'FULL_WIDTH'])
|
|
580
588
|
|
|
581
|
-
export const CustomerAccountPermissionsSchema
|
|
582
|
-
'DISABLED',
|
|
583
|
-
'DISABLE_REGISTRATION'
|
|
584
|
-
|
|
585
|
-
])
|
|
589
|
+
export const CustomerAccountPermissionsSchema: z.ZodType<
|
|
590
|
+
'DISABLED' | 'DISABLE_REGISTRATION' | 'ENABLED',
|
|
591
|
+
'DISABLED' | 'DISABLE_REGISTRATION' | 'ENABLED'
|
|
592
|
+
> = z.enum(['DISABLED', 'DISABLE_REGISTRATION', 'ENABLED'])
|
|
586
593
|
|
|
587
|
-
export const PaginationVariantSchema
|
|
594
|
+
export const PaginationVariantSchema: z.ZodType<'COMPACT' | 'EXTENDED', 'COMPACT' | 'EXTENDED'> =
|
|
595
|
+
z.enum(['COMPACT', 'EXTENDED'])
|
|
588
596
|
|
|
589
|
-
export const ProductFiltersLayoutSchema
|
|
597
|
+
export const ProductFiltersLayoutSchema: z.ZodType<'DEFAULT' | 'SIDEBAR', 'DEFAULT' | 'SIDEBAR'> =
|
|
598
|
+
z.enum(['DEFAULT', 'SIDEBAR'])
|
|
590
599
|
|
|
591
|
-
export const SidebarGalleryPaginationVariantSchema
|
|
600
|
+
export const SidebarGalleryPaginationVariantSchema: z.ZodType<
|
|
601
|
+
'DOTS' | 'THUMBNAILS_BOTTOM',
|
|
602
|
+
'DOTS' | 'THUMBNAILS_BOTTOM'
|
|
603
|
+
> = z.enum(['DOTS', 'THUMBNAILS_BOTTOM'])
|
|
592
604
|
|
|
593
|
-
export const WebsitePermissionsSchema = z.enum(['ENABLED'])
|
|
605
|
+
export const WebsitePermissionsSchema: z.ZodType<'ENABLED', 'ENABLED'> = z.enum(['ENABLED'])
|
|
594
606
|
|
|
595
|
-
export function DatalayerConfigSchema()
|
|
607
|
+
export function DatalayerConfigSchema() {
|
|
596
608
|
return z.object({
|
|
597
609
|
coreWebVitals: z.boolean().nullish(),
|
|
598
610
|
})
|
|
599
611
|
}
|
|
600
612
|
|
|
601
|
-
export function GraphCommerceConfigSchema()
|
|
613
|
+
export function GraphCommerceConfigSchema() {
|
|
602
614
|
return z.object({
|
|
603
615
|
breadcrumbs: z.boolean().nullish().default(false),
|
|
604
616
|
canonicalBaseUrl: z.string().min(1),
|
|
@@ -606,7 +618,9 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
|
|
|
606
618
|
compare: z.boolean().nullish(),
|
|
607
619
|
compareVariant: CompareVariantSchema.nullish().default('ICON'),
|
|
608
620
|
configurableVariantForSimple: z.boolean().nullish().default(false),
|
|
609
|
-
configurableVariantValues: z.lazy(() =>
|
|
621
|
+
configurableVariantValues: z.lazy(() =>
|
|
622
|
+
MagentoConfigurableVariantValuesSchema().nullish().default({ url: true, content: true }),
|
|
623
|
+
),
|
|
610
624
|
containerSizingContent: ContainerSizingSchema.nullish().default('FULL_WIDTH'),
|
|
611
625
|
containerSizingShell: ContainerSizingSchema.nullish().default('FULL_WIDTH'),
|
|
612
626
|
crossSellsHideCartItems: z.boolean().nullish().default(false),
|
|
@@ -644,9 +658,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
|
|
|
644
658
|
})
|
|
645
659
|
}
|
|
646
660
|
|
|
647
|
-
export function GraphCommerceDebugConfigSchema()
|
|
648
|
-
Properties<GraphCommerceDebugConfig>
|
|
649
|
-
> {
|
|
661
|
+
export function GraphCommerceDebugConfigSchema() {
|
|
650
662
|
return z.object({
|
|
651
663
|
cart: z.boolean().nullish(),
|
|
652
664
|
pluginStatus: z.boolean().nullish(),
|
|
@@ -656,18 +668,14 @@ export function GraphCommerceDebugConfigSchema(): z.ZodObject<
|
|
|
656
668
|
})
|
|
657
669
|
}
|
|
658
670
|
|
|
659
|
-
export function GraphCommerceGooglePlaystoreConfigSchema()
|
|
660
|
-
Properties<GraphCommerceGooglePlaystoreConfig>
|
|
661
|
-
> {
|
|
671
|
+
export function GraphCommerceGooglePlaystoreConfigSchema() {
|
|
662
672
|
return z.object({
|
|
663
673
|
packageName: z.string().min(1),
|
|
664
674
|
sha256CertificateFingerprint: z.string().min(1),
|
|
665
675
|
})
|
|
666
676
|
}
|
|
667
677
|
|
|
668
|
-
export function GraphCommercePermissionsSchema()
|
|
669
|
-
Properties<GraphCommercePermissions>
|
|
670
|
-
> {
|
|
678
|
+
export function GraphCommercePermissionsSchema() {
|
|
671
679
|
return z.object({
|
|
672
680
|
billingAddress: BillingAddressPermissionsSchema.nullish(),
|
|
673
681
|
cart: CartPermissionsSchema.nullish(),
|
|
@@ -677,9 +685,7 @@ export function GraphCommercePermissionsSchema(): z.ZodObject<
|
|
|
677
685
|
})
|
|
678
686
|
}
|
|
679
687
|
|
|
680
|
-
export function GraphCommerceStorefrontConfigSchema()
|
|
681
|
-
Properties<GraphCommerceStorefrontConfig>
|
|
682
|
-
> {
|
|
688
|
+
export function GraphCommerceStorefrontConfigSchema() {
|
|
683
689
|
return z.object({
|
|
684
690
|
canonicalBaseUrl: z.string().nullish(),
|
|
685
691
|
cartDisplayPricesInclTax: z.boolean().nullish(),
|
|
@@ -697,9 +703,7 @@ export function GraphCommerceStorefrontConfigSchema(): z.ZodObject<
|
|
|
697
703
|
})
|
|
698
704
|
}
|
|
699
705
|
|
|
700
|
-
export function MagentoConfigurableVariantValuesSchema()
|
|
701
|
-
Properties<MagentoConfigurableVariantValues>
|
|
702
|
-
> {
|
|
706
|
+
export function MagentoConfigurableVariantValuesSchema() {
|
|
703
707
|
return z.object({
|
|
704
708
|
content: z.boolean().nullish(),
|
|
705
709
|
gallery: z.boolean().nullish(),
|
|
@@ -707,16 +711,14 @@ export function MagentoConfigurableVariantValuesSchema(): z.ZodObject<
|
|
|
707
711
|
})
|
|
708
712
|
}
|
|
709
713
|
|
|
710
|
-
export function RecentlyViewedProductsConfigSchema()
|
|
711
|
-
Properties<RecentlyViewedProductsConfig>
|
|
712
|
-
> {
|
|
714
|
+
export function RecentlyViewedProductsConfigSchema() {
|
|
713
715
|
return z.object({
|
|
714
716
|
enabled: z.boolean().nullish(),
|
|
715
717
|
maxCount: z.number().nullish(),
|
|
716
718
|
})
|
|
717
719
|
}
|
|
718
720
|
|
|
719
|
-
export function SidebarGalleryConfigSchema()
|
|
721
|
+
export function SidebarGalleryConfigSchema() {
|
|
720
722
|
return z.object({
|
|
721
723
|
paginationVariant: SidebarGalleryPaginationVariantSchema.nullish(),
|
|
722
724
|
})
|
|
@@ -57,7 +57,7 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
57
57
|
|
|
58
58
|
if (!parsed.success) {
|
|
59
59
|
if (errors.length)
|
|
60
|
-
console.error(parsed.error.
|
|
60
|
+
console.error(parsed.error.issues.map((e) => `${e.path} ${e.message}`).join('\n'))
|
|
61
61
|
return undefined
|
|
62
62
|
}
|
|
63
63
|
|