@decocms/apps 0.27.0 → 0.28.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/vtex/invoke.ts DELETED
@@ -1,196 +0,0 @@
1
- /**
2
- * Typed invoke object for VTEX actions — same DX as deco-cx/deco.
3
- *
4
- * Client-side components call `invoke.vtex.actions.*({ data: ... })`.
5
- * Under the hood, each call is a `createServerFn` that executes
6
- * on the server with full VTEX credentials (appKey/appToken).
7
- *
8
- * @example
9
- * ```tsx
10
- * import { invoke } from "@decocms/apps/vtex/invoke";
11
- *
12
- * // Add to cart
13
- * const cart = await invoke.vtex.actions.addItemsToCart({
14
- * data: { orderFormId: "abc", orderItems: [{ id: "1", seller: "1", quantity: 1 }] }
15
- * });
16
- *
17
- * // Subscribe to newsletter
18
- * await invoke.vtex.actions.subscribe({ data: { email: "user@example.com" } });
19
- *
20
- * // Notify me when back in stock
21
- * await invoke.vtex.actions.notifyMe({ data: { email: "u@e.com", skuId: "123" } });
22
- * ```
23
- */
24
- import { createInvokeFn } from "@decocms/start/sdk/createInvoke";
25
- import type { RegionResult } from "./actions/checkout";
26
- import {
27
- addCouponToCart,
28
- addItemsToCart,
29
- getOrCreateCart,
30
- getSellersByRegion,
31
- type SimulationItem,
32
- setShippingPostalCode,
33
- simulateCart,
34
- updateCartItems,
35
- updateOrderFormAttachment,
36
- } from "./actions/checkout";
37
- import {
38
- type CreateDocumentResult,
39
- createDocument,
40
- getDocument,
41
- patchDocument,
42
- searchDocuments,
43
- type UploadAttachmentOpts,
44
- uploadAttachment,
45
- } from "./actions/masterData";
46
- import { type NotifyMeProps, notifyMe } from "./actions/misc";
47
- import { type SubscribeProps, subscribe } from "./actions/newsletter";
48
- import { createSession, editSession, type SessionData } from "./actions/session";
49
- import type { OrderForm } from "./types";
50
-
51
- // ---------------------------------------------------------------------------
52
- // invoke.vtex.actions — typed server functions callable from client
53
- // ---------------------------------------------------------------------------
54
-
55
- export const invoke = {
56
- vtex: {
57
- actions: {
58
- // -- Cart (unwrap VtexFetchResult -> OrderForm) -----------------------
59
-
60
- getOrCreateCart: createInvokeFn(
61
- (input: { orderFormId?: string }) => getOrCreateCart(input.orderFormId),
62
- { unwrap: true },
63
- ) as unknown as (ctx: { data: { orderFormId?: string } }) => Promise<OrderForm>,
64
-
65
- addItemsToCart: createInvokeFn(
66
- (input: {
67
- orderFormId: string;
68
- orderItems: Array<{
69
- id: string;
70
- seller: string;
71
- quantity: number;
72
- }>;
73
- }) => addItemsToCart(input.orderFormId, input.orderItems),
74
- { unwrap: true },
75
- ) as unknown as (ctx: {
76
- data: {
77
- orderFormId: string;
78
- orderItems: Array<{
79
- id: string;
80
- seller: string;
81
- quantity: number;
82
- }>;
83
- };
84
- }) => Promise<OrderForm>,
85
-
86
- updateCartItems: createInvokeFn(
87
- (input: { orderFormId: string; orderItems: Array<{ index: number; quantity: number }> }) =>
88
- updateCartItems(input.orderFormId, input.orderItems),
89
- { unwrap: true },
90
- ) as unknown as (ctx: {
91
- data: {
92
- orderFormId: string;
93
- orderItems: Array<{ index: number; quantity: number }>;
94
- };
95
- }) => Promise<OrderForm>,
96
-
97
- addCouponToCart: createInvokeFn(
98
- (input: { orderFormId: string; text: string }) =>
99
- addCouponToCart(input.orderFormId, input.text),
100
- { unwrap: true },
101
- ) as unknown as (ctx: { data: { orderFormId: string; text: string } }) => Promise<OrderForm>,
102
-
103
- simulateCart: createInvokeFn(
104
- (input: { items: SimulationItem[]; postalCode: string; country?: string }) =>
105
- simulateCart(input.items, input.postalCode, input.country),
106
- ),
107
-
108
- // -- Shipping / Region ------------------------------------------------
109
-
110
- getSellersByRegion: createInvokeFn((input: { postalCode: string; salesChannel?: string }) =>
111
- getSellersByRegion(input.postalCode, input.salesChannel),
112
- ) as (ctx: {
113
- data: { postalCode: string; salesChannel?: string };
114
- }) => Promise<RegionResult | null>,
115
-
116
- setShippingPostalCode: createInvokeFn(
117
- (input: { orderFormId: string; postalCode: string; country?: string }) =>
118
- setShippingPostalCode(input.orderFormId, input.postalCode, input.country),
119
- ) as (ctx: {
120
- data: {
121
- orderFormId: string;
122
- postalCode: string;
123
- country?: string;
124
- };
125
- }) => Promise<boolean>,
126
-
127
- updateOrderFormAttachment: createInvokeFn(
128
- (input: { orderFormId: string; attachment: string; body: Record<string, unknown> }) =>
129
- updateOrderFormAttachment(input.orderFormId, input.attachment, input.body),
130
- { unwrap: true },
131
- ) as unknown as (ctx: {
132
- data: {
133
- orderFormId: string;
134
- attachment: string;
135
- body: Record<string, unknown>;
136
- };
137
- }) => Promise<OrderForm>,
138
-
139
- // -- Session ----------------------------------------------------------
140
-
141
- createSession: createInvokeFn((input: Record<string, any>) => createSession(input), {
142
- unwrap: true,
143
- }),
144
-
145
- editSession: createInvokeFn(
146
- (input: { public: Record<string, { value: string }> }) => editSession(input.public),
147
- { unwrap: true },
148
- ) as unknown as (ctx: {
149
- data: { public: Record<string, { value: string }> };
150
- }) => Promise<SessionData>,
151
-
152
- // -- MasterData -------------------------------------------------------
153
-
154
- createDocument: createInvokeFn((input: { entity: string; data: Record<string, any> }) =>
155
- createDocument(input.entity, input.data),
156
- ) as (ctx: {
157
- data: { entity: string; data: Record<string, any> };
158
- }) => Promise<CreateDocumentResult>,
159
-
160
- getDocument: createInvokeFn((input: { entity: string; documentId: string }) =>
161
- getDocument(input.entity, input.documentId),
162
- ),
163
-
164
- patchDocument: createInvokeFn(
165
- (input: { entity: string; documentId: string; data: Record<string, any> }) =>
166
- patchDocument(input.entity, input.documentId, input.data),
167
- ) as (ctx: {
168
- data: {
169
- entity: string;
170
- documentId: string;
171
- data: Record<string, any>;
172
- };
173
- }) => Promise<void>,
174
-
175
- searchDocuments: createInvokeFn((input: { entity: string; filter: string }) =>
176
- searchDocuments(input.entity, input.filter),
177
- ),
178
-
179
- uploadAttachment: createInvokeFn((input: UploadAttachmentOpts) =>
180
- uploadAttachment(input),
181
- ) as (ctx: { data: UploadAttachmentOpts }) => Promise<{ ok: true }>,
182
-
183
- // -- Newsletter -------------------------------------------------------
184
-
185
- subscribe: createInvokeFn((input: SubscribeProps) => subscribe(input)) as (ctx: {
186
- data: SubscribeProps;
187
- }) => Promise<void>,
188
-
189
- // -- Misc -------------------------------------------------------------
190
-
191
- notifyMe: createInvokeFn((input: NotifyMeProps) => notifyMe(input)) as (ctx: {
192
- data: NotifyMeProps;
193
- }) => Promise<void>,
194
- },
195
- },
196
- } as const;