@graphcommerce/next-config 9.0.0-canary.57 → 9.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 9.0.0-canary.58
4
+
5
+ ### Minor Changes
6
+
7
+ - [#2330](https://github.com/graphcommerce-org/graphcommerce/pull/2330) [`5701e71`](https://github.com/graphcommerce-org/graphcommerce/commit/5701e71454ffb52880cd15c3341826d9502284d0) - Added support for boolean `ifConfig: ['customerXMagentoCacheIdDisable', true]` values in plugin configurations ([@paales](https://github.com/paales))
8
+
3
9
  ## 9.0.0-canary.57
4
10
 
5
11
  ## 9.0.0-canary.56
@@ -40,6 +40,7 @@ exports[`traverses a schema and returns a list of env variables that match 1`] =
40
40
  "GC_CUSTOMER_ADDRESS_NOTE_ENABLE",
41
41
  "GC_CUSTOMER_COMPANY_FIELDS_ENABLE",
42
42
  "GC_CUSTOMER_DELETE_ENABLED",
43
+ "GC_CUSTOMER_X_MAGENTO_CACHE_ID_DISABLE",
43
44
  "GC_DATA_LAYER",
44
45
  "GC_DATA_LAYER_CORE_WEB_VITALS",
45
46
  "GC_DEBUG",
@@ -227,6 +227,18 @@ it('finds plugins', () => {
227
227
  "targetModule": "@graphcommerce/graphql",
228
228
  "type": "function",
229
229
  },
230
+ {
231
+ "enabled": true,
232
+ "ifConfig": [
233
+ "customerXMagentoCacheIdDisable",
234
+ false,
235
+ ],
236
+ "sourceExport": "GraphQLProvider",
237
+ "sourceModule": "@graphcommerce/magento-customer/plugins/XMagentoCacheIdGraphQLProvider",
238
+ "targetExport": "GraphQLProvider",
239
+ "targetModule": "@graphcommerce/graphql",
240
+ "type": "component",
241
+ },
230
242
  {
231
243
  "enabled": true,
232
244
  "sourceExport": "GraphQLProvider",
@@ -206,3 +206,83 @@ export const Plugin = AddAdyenMethods
206
206
  `)
207
207
  expect(plugins[1]).toMatchInlineSnapshot(`undefined`)
208
208
  })
209
+
210
+ it('correctly allows false value in the ifConfig', () => {
211
+ const src = `
212
+ import { PluginConfig, PluginProps } from '@graphcommerce/next-config'
213
+ import { xMagentoCacheIdHeader } from '../link/xMagentoCacheIdHeader'
214
+ import { GraphQLProviderProps } from '@graphcommerce/graphql'
215
+
216
+ export const config: PluginConfig = {
217
+ type: 'component',
218
+ module: '@graphcommerce/graphql',
219
+ ifConfig: ['customerXMagentoCacheIdDisable', false],
220
+ }
221
+
222
+ export function GraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
223
+ const { Prev, links = [], ...rest } = props
224
+ return <Prev {...rest} links={[...links, xMagentoCacheIdHeader]} />
225
+ }
226
+ `
227
+ const ast = parseSync(src)
228
+
229
+ expect(
230
+ parseStructure(ast, {} as GraphCommerceConfig, './plugins/MyReplace')[0].enabled,
231
+ ).toBeTruthy()
232
+
233
+ expect(
234
+ parseStructure(
235
+ ast,
236
+ { customerXMagentoCacheIdDisable: true } as GraphCommerceConfig,
237
+ './plugins/MyReplace',
238
+ )[0].enabled,
239
+ ).toBeFalsy()
240
+
241
+ expect(
242
+ parseStructure(
243
+ ast,
244
+ { customerXMagentoCacheIdDisable: false } as GraphCommerceConfig,
245
+ './plugins/MyReplace',
246
+ )[0].enabled,
247
+ ).toBeTruthy()
248
+ })
249
+
250
+ it('correctly allows true value in the ifConfig', () => {
251
+ const src = `
252
+ import { PluginConfig, PluginProps } from '@graphcommerce/next-config'
253
+ import { xMagentoCacheIdHeader } from '../link/xMagentoCacheIdHeader'
254
+ import { GraphQLProviderProps } from '@graphcommerce/graphql'
255
+
256
+ export const config: PluginConfig = {
257
+ type: 'component',
258
+ module: '@graphcommerce/graphql',
259
+ ifConfig: ['customerXMagentoCacheIdDisable', true],
260
+ }
261
+
262
+ export function GraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
263
+ const { Prev, links = [], ...rest } = props
264
+ return <Prev {...rest} links={[...links, xMagentoCacheIdHeader]} />
265
+ }
266
+ `
267
+ const ast = parseSync(src)
268
+
269
+ expect(
270
+ parseStructure(ast, {} as GraphCommerceConfig, './plugins/MyReplace')[0].enabled,
271
+ ).toBeFalsy()
272
+
273
+ expect(
274
+ parseStructure(
275
+ ast,
276
+ { customerXMagentoCacheIdDisable: true } as GraphCommerceConfig,
277
+ './plugins/MyReplace',
278
+ )[0].enabled,
279
+ ).toBeTruthy()
280
+
281
+ expect(
282
+ parseStructure(
283
+ ast,
284
+ { customerXMagentoCacheIdDisable: false } as GraphCommerceConfig,
285
+ './plugins/MyReplace',
286
+ )[0].enabled,
287
+ ).toBeFalsy()
288
+ })
@@ -36,6 +36,7 @@ function GraphCommerceConfigSchema() {
36
36
  customerAddressNoteEnable: zod_1.z.boolean().nullish(),
37
37
  customerCompanyFieldsEnable: zod_1.z.boolean().nullish(),
38
38
  customerDeleteEnabled: zod_1.z.boolean().nullish(),
39
+ customerXMagentoCacheIdDisable: zod_1.z.boolean().nullish(),
39
40
  dataLayer: DatalayerConfigSchema().nullish(),
40
41
  debug: GraphCommerceDebugConfigSchema().nullish(),
41
42
  demoMode: zod_1.z.boolean().default(true).nullish(),
@@ -11,7 +11,7 @@ const pluginConfigParsed = zod_1.z.object({
11
11
  type: zod_1.z.enum(['component', 'function', 'replace']),
12
12
  module: zod_1.z.string(),
13
13
  export: zod_1.z.string(),
14
- ifConfig: zod_1.z.union([zod_1.z.string(), zod_1.z.tuple([zod_1.z.string(), zod_1.z.string()])]).optional(),
14
+ ifConfig: zod_1.z.union([zod_1.z.string(), zod_1.z.tuple([zod_1.z.string(), zod_1.z.unknown()])]).optional(),
15
15
  });
16
16
  function nonNullable(value) {
17
17
  return value !== null && value !== undefined;
@@ -51,9 +51,15 @@ function parseStructure(ast, gcConfig, sourceModule) {
51
51
  }
52
52
  let enabled = true;
53
53
  if (parsed.data.ifConfig) {
54
- enabled = Array.isArray(parsed.data.ifConfig)
55
- ? (0, get_1.default)(gcConfig, parsed.data.ifConfig[0]) === parsed.data.ifConfig[1]
56
- : Boolean((0, get_1.default)(gcConfig, parsed.data.ifConfig));
54
+ if (Array.isArray(parsed.data.ifConfig)) {
55
+ const isBoolean = typeof parsed.data.ifConfig[1] === 'boolean';
56
+ let confValue = (0, get_1.default)(gcConfig, parsed.data.ifConfig[0]);
57
+ confValue = isBoolean ? Boolean(confValue) : confValue;
58
+ enabled = confValue === parsed.data.ifConfig[1];
59
+ }
60
+ else {
61
+ enabled = Boolean((0, get_1.default)(gcConfig, parsed.data.ifConfig));
62
+ }
57
63
  }
58
64
  const val = {
59
65
  targetExport: exports.component || exports.func || parsed.data.export,
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": "9.0.0-canary.57",
5
+ "version": "9.0.0-canary.58",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
8
8
  "types": "src/index.ts",
@@ -169,6 +169,12 @@ export type GraphCommerceConfig = {
169
169
  customerCompanyFieldsEnable?: InputMaybe<Scalars['Boolean']['input']>;
170
170
  /** Enable customer account deletion through the account section */
171
171
  customerDeleteEnabled?: InputMaybe<Scalars['Boolean']['input']>;
172
+ /**
173
+ * X-Magento-Cache-Id allows Varnish to cache requests that are made in the browser while users are logged in. For example the products query can now be cached for logged in users.
174
+ *
175
+ * This can be disabled when Varnish is running out of available memory.
176
+ */
177
+ customerXMagentoCacheIdDisable?: InputMaybe<Scalars['Boolean']['input']>;
172
178
  /** Datalayer config */
173
179
  dataLayer?: InputMaybe<DatalayerConfig>;
174
180
  /** Debug configuration for GraphCommerce */
@@ -498,6 +504,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
498
504
  customerAddressNoteEnable: z.boolean().nullish(),
499
505
  customerCompanyFieldsEnable: z.boolean().nullish(),
500
506
  customerDeleteEnabled: z.boolean().nullish(),
507
+ customerXMagentoCacheIdDisable: z.boolean().nullish(),
501
508
  dataLayer: DatalayerConfigSchema().nullish(),
502
509
  debug: GraphCommerceDebugConfigSchema().nullish(),
503
510
  demoMode: z.boolean().default(true).nullish(),
@@ -14,7 +14,7 @@ type PluginBaseConfig = {
14
14
  sourceModule: string
15
15
  targetExport: string
16
16
  enabled: boolean
17
- ifConfig?: string | [string, string]
17
+ ifConfig?: string | [string, any]
18
18
  }
19
19
 
20
20
  export function isPluginBaseConfig(plugin: Partial<PluginBaseConfig>): plugin is PluginBaseConfig {
@@ -9,7 +9,7 @@ const pluginConfigParsed = z.object({
9
9
  type: z.enum(['component', 'function', 'replace']),
10
10
  module: z.string(),
11
11
  export: z.string(),
12
- ifConfig: z.union([z.string(), z.tuple([z.string(), z.string()])]).optional(),
12
+ ifConfig: z.union([z.string(), z.tuple([z.string(), z.unknown()])]).optional(),
13
13
  })
14
14
 
15
15
  function nonNullable<T>(value: T): value is NonNullable<T> {
@@ -62,10 +62,17 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
62
62
  }
63
63
 
64
64
  let enabled = true
65
+
65
66
  if (parsed.data.ifConfig) {
66
- enabled = Array.isArray(parsed.data.ifConfig)
67
- ? get(gcConfig, parsed.data.ifConfig[0]) === parsed.data.ifConfig[1]
68
- : Boolean(get(gcConfig, parsed.data.ifConfig))
67
+ if (Array.isArray(parsed.data.ifConfig)) {
68
+ const isBoolean = typeof parsed.data.ifConfig[1] === 'boolean'
69
+ let confValue = get(gcConfig, parsed.data.ifConfig[0])
70
+ confValue = isBoolean ? Boolean(confValue) : confValue
71
+
72
+ enabled = confValue === parsed.data.ifConfig[1]
73
+ } else {
74
+ enabled = Boolean(get(gcConfig, parsed.data.ifConfig))
75
+ }
69
76
  }
70
77
 
71
78
  const val: PluginConfig = {