@decocms/apps-vtex 7.9.0 → 7.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -5
- package/src/__tests__/schemas.test.ts +71 -0
- package/src/commerceLoaders.ts +6 -0
- package/src/mod.ts +5 -0
- package/src/schemas.gen.ts +3191 -0
- package/src/schemas.ts +30 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/apps-vtex",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco commerce app: VTEX integration",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
".": "./src/index.ts",
|
|
18
18
|
"./commerceLoaders": "./src/commerceLoaders.ts",
|
|
19
19
|
"./mod": "./src/mod.ts",
|
|
20
|
+
"./schemas": "./src/schemas.ts",
|
|
20
21
|
"./client": "./src/client.ts",
|
|
21
22
|
"./types": "./src/types.ts",
|
|
22
23
|
"./actions": "./src/actions/index.ts",
|
|
@@ -44,15 +45,16 @@
|
|
|
44
45
|
},
|
|
45
46
|
"scripts": {
|
|
46
47
|
"build": "tsc",
|
|
48
|
+
"generate:schemas": "bun ../blocks-cli/scripts/generate-app-schemas.ts",
|
|
47
49
|
"test": "vitest run --root ../.. packages/apps-vtex/",
|
|
48
50
|
"typecheck": "tsc --noEmit",
|
|
49
51
|
"lint:unused": "knip"
|
|
50
52
|
},
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"@decocms/blocks": "7.
|
|
53
|
-
"@decocms/apps-commerce": "7.
|
|
54
|
-
"@decocms/apps-website": "7.
|
|
55
|
-
"@decocms/tanstack": "7.
|
|
54
|
+
"@decocms/blocks": "7.10.0",
|
|
55
|
+
"@decocms/apps-commerce": "7.10.0",
|
|
56
|
+
"@decocms/apps-website": "7.10.0",
|
|
57
|
+
"@decocms/tanstack": "7.10.0"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"react": "^19.0.0",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end guard for the acceptance criteria of "real props schemas in
|
|
3
|
+
* /deco/meta": after a site wires VTEX the standard way
|
|
4
|
+
* (createVtexCommerceLoaders → registerCommerceLoaders), the composed meta
|
|
5
|
+
* must publish the real props of the app's loaders/actions — enums included —
|
|
6
|
+
* not the `__resolveType`-only stubs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { registerCommerceLoaders } from "@decocms/blocks/cms";
|
|
10
|
+
import { composeMeta, type MetaResponse } from "@decocms/blocks/cms/client";
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import { createVtexCommerceLoaders } from "../commerceLoaders";
|
|
13
|
+
import { registerVtexSchemas } from "../schemas";
|
|
14
|
+
|
|
15
|
+
const b64 = (s: string) => Buffer.from(s).toString("base64");
|
|
16
|
+
|
|
17
|
+
const emptySiteMeta = (): MetaResponse => ({
|
|
18
|
+
major: 1,
|
|
19
|
+
version: "1.0.0",
|
|
20
|
+
namespace: "site",
|
|
21
|
+
site: "test",
|
|
22
|
+
manifest: { blocks: {} },
|
|
23
|
+
schema: { definitions: {}, root: {} },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("vtex schemas in the composed meta", () => {
|
|
27
|
+
// Mirrors a real site setup: build the loader map (this also registers the
|
|
28
|
+
// real schemas), then register it (which auto-registers the stubs).
|
|
29
|
+
registerCommerceLoaders(createVtexCommerceLoaders());
|
|
30
|
+
registerVtexSchemas();
|
|
31
|
+
const meta = composeMeta(emptySiteMeta());
|
|
32
|
+
const def = (key: string) => meta.schema.definitions[b64(key)];
|
|
33
|
+
|
|
34
|
+
it("publishes real props for the intelligent-search PDP loader (both key forms)", () => {
|
|
35
|
+
for (const key of [
|
|
36
|
+
"vtex/loaders/intelligentSearch/productDetailsPage.ts",
|
|
37
|
+
"vtex/loaders/intelligentSearch/productDetailsPage",
|
|
38
|
+
]) {
|
|
39
|
+
const d = def(key);
|
|
40
|
+
expect(d, key).toBeDefined();
|
|
41
|
+
expect(d.properties.slug, key).toMatchObject({ type: "string" });
|
|
42
|
+
expect(d.properties.__resolveType.enum, key).toEqual([key]);
|
|
43
|
+
expect(d.additionalProperties, key).toBeUndefined();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("publishes the legacy PLP loader with its sort enum preserved", () => {
|
|
48
|
+
const d = def("vtex/loaders/legacy/productListingPage.ts");
|
|
49
|
+
expect(d).toBeDefined();
|
|
50
|
+
expect(d.properties.sort.enum).toContain("OrderByPriceDESC");
|
|
51
|
+
expect(d.properties.sort.enum).toContain("OrderByPriceASC");
|
|
52
|
+
expect(d.properties.count).toMatchObject({ type: "number" });
|
|
53
|
+
expect(d.properties.fq).toMatchObject({ type: "string" });
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("publishes real props for a checkout action", () => {
|
|
57
|
+
const d = def("vtex/actions/checkout/addItemsToCart.ts");
|
|
58
|
+
expect(d).toBeDefined();
|
|
59
|
+
expect(d.properties.orderItems).toMatchObject({ type: "array" });
|
|
60
|
+
expect(d.additionalProperties).toBeUndefined();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("keeps the JSON-editor stub shape for keys without a generated schema", () => {
|
|
64
|
+
// Registered by createVtexCommerceLoaders but owned by another namespace —
|
|
65
|
+
// no schemas.gen entry, so the stub (additionalProperties: true) survives.
|
|
66
|
+
const d = def("commerce/loaders/navbar.ts");
|
|
67
|
+
expect(d).toBeDefined();
|
|
68
|
+
expect(d.additionalProperties).toBe(true);
|
|
69
|
+
expect(Object.keys(d.properties)).toEqual(["__resolveType"]);
|
|
70
|
+
});
|
|
71
|
+
});
|
package/src/commerceLoaders.ts
CHANGED
|
@@ -19,6 +19,7 @@ import vtexSuggestions from "./loaders/intelligentSearch/suggestions";
|
|
|
19
19
|
import vtexRelatedProducts from "./loaders/legacy/relatedProductsLoader";
|
|
20
20
|
import vtexProductList from "./loaders/productListFull";
|
|
21
21
|
import vtexWorkflowProducts from "./loaders/workflow/products";
|
|
22
|
+
import { registerVtexSchemas } from "./schemas";
|
|
22
23
|
import { VALID_IS_SORTS } from "./utils/intelligentSearch";
|
|
23
24
|
|
|
24
25
|
export type CommerceLoaderFn = (props: any) => Promise<any>;
|
|
@@ -85,6 +86,11 @@ function extractCollectionName(result: any, collectionId: string): string | null
|
|
|
85
86
|
export function createVtexCommerceLoaders(
|
|
86
87
|
options?: VtexCommerceLoadersOptions,
|
|
87
88
|
): Record<string, CommerceLoaderFn> {
|
|
89
|
+
// Real props schemas for the admin meta. The stub registration that
|
|
90
|
+
// registerCommerceLoaders() later performs for this returned map never
|
|
91
|
+
// overwrites these (real-over-stub precedence in the schema registry).
|
|
92
|
+
registerVtexSchemas();
|
|
93
|
+
|
|
88
94
|
const profiles = {
|
|
89
95
|
listing: options?.cacheProfiles?.listing ?? "listing",
|
|
90
96
|
product: options?.cacheProfiles?.product ?? "product",
|
package/src/mod.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type { Secret } from "@decocms/apps-website/mod";
|
|
|
20
20
|
import { configureVtex, type VtexConfig } from "./client";
|
|
21
21
|
import manifest from "./manifest.gen";
|
|
22
22
|
import { extractVtexContext, propagateISCookies, vtexCacheControl } from "./middleware";
|
|
23
|
+
import { registerVtexSchemas } from "./schemas";
|
|
23
24
|
|
|
24
25
|
// -------------------------------------------------------------------------
|
|
25
26
|
// CMS Props (mirrors deco-cx/apps/vtex/mod.ts)
|
|
@@ -118,6 +119,10 @@ export async function configure(
|
|
|
118
119
|
): Promise<AppDefinition<VtexState> | null> {
|
|
119
120
|
if (!block?.account) return null;
|
|
120
121
|
|
|
122
|
+
// Real props schemas for the admin meta — must be in place before
|
|
123
|
+
// setupApps() auto-registers the __resolveType-only stubs.
|
|
124
|
+
registerVtexSchemas();
|
|
125
|
+
|
|
121
126
|
const appKey = await resolveSecret(block.appKey, "VTEX_APP_KEY");
|
|
122
127
|
const appToken = await resolveSecret(block.appToken, "VTEX_APP_TOKEN");
|
|
123
128
|
|