@kizlo/woocommerce 1.0.0-alpha.1 → 1.0.0-alpha.2
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/dist/client-BJuv_NtE.js +684 -0
- package/dist/client-BJuv_NtE.js.map +1 -0
- package/dist/client-CWtBT_hK.cjs +857 -0
- package/dist/{index-DbjII-g1.d.cts → index-D6PQxlBF.d.cts} +4699 -6794
- package/dist/index-D6PQxlBF.d.cts.map +1 -0
- package/dist/{index-B70N6Qy2.d.ts → index-DUK75443.d.ts} +4699 -6794
- package/dist/index-DUK75443.d.ts.map +1 -0
- package/dist/index.cjs +22 -20
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +4 -6
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/package.json +4 -3
- package/dist/client-ChYuRMN-.cjs +0 -684
- package/dist/client-g0rDKQEG.js +0 -511
- package/dist/client-g0rDKQEG.js.map +0 -1
- package/dist/index-B70N6Qy2.d.ts.map +0 -1
- package/dist/index-DbjII-g1.d.cts.map +0 -1
|
@@ -0,0 +1,684 @@
|
|
|
1
|
+
import { createRemoteFetchClient, createSafeClient, ensureProcedureResult, type } from "kizlo";
|
|
2
|
+
import { createClientExtension, createServerExtension, openApiProcedure, procedure, procedureErrors, remoteProcedure } from "kizlo/extensions";
|
|
3
|
+
|
|
4
|
+
//#region src/client.extension.ts
|
|
5
|
+
const woocommerceProcedure = procedure.use(procedure.middleware(({ context, next }) => {
|
|
6
|
+
return next({ context: { woocommerce: new KizloWoocommerce(context.kizlo) } });
|
|
7
|
+
}));
|
|
8
|
+
function woocommerce$1() {
|
|
9
|
+
return createClientExtension({
|
|
10
|
+
type: "router",
|
|
11
|
+
name: "woocommerce",
|
|
12
|
+
init() {
|
|
13
|
+
return woocommerceRouter;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/cart/client.ts
|
|
20
|
+
var KizloCartItem = class {
|
|
21
|
+
constructor(kizlo) {
|
|
22
|
+
this.kizlo = kizlo;
|
|
23
|
+
}
|
|
24
|
+
async add(input) {
|
|
25
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
26
|
+
const response = await this.kizlo._.http.post("/cart/items", {
|
|
27
|
+
body: input,
|
|
28
|
+
headers
|
|
29
|
+
});
|
|
30
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
31
|
+
return this.kizlo._.http.success(response.data);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async update(input) {
|
|
35
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
36
|
+
const response = await this.kizlo._.http.put(`/cart/items/${input.key}`, {
|
|
37
|
+
body: input,
|
|
38
|
+
headers
|
|
39
|
+
});
|
|
40
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
41
|
+
return this.kizlo._.http.success(response.data);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async remove(input) {
|
|
45
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
46
|
+
const response = await this.kizlo._.http.delete(`/cart/items/${input.key}`, { headers });
|
|
47
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
48
|
+
return this.kizlo._.http.success(response.data);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var KizloCoupon = class {
|
|
53
|
+
constructor(kizlo) {
|
|
54
|
+
this.kizlo = kizlo;
|
|
55
|
+
}
|
|
56
|
+
async apply(input) {
|
|
57
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
58
|
+
const response = await this.kizlo._.http.post(`/cart/coupons/${input.code}`, { headers });
|
|
59
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
60
|
+
return this.kizlo._.http.success(response.data);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async remove(input) {
|
|
64
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
65
|
+
const response = await this.kizlo._.http.delete(`/cart/coupons/${input.code}`, { headers });
|
|
66
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
67
|
+
return this.kizlo._.http.success(response.data);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var KizloCart = class {
|
|
72
|
+
items;
|
|
73
|
+
coupons;
|
|
74
|
+
constructor(kizlo) {
|
|
75
|
+
this.kizlo = kizlo;
|
|
76
|
+
this.items = new KizloCartItem(this.kizlo);
|
|
77
|
+
this.coupons = new KizloCoupon(this.kizlo);
|
|
78
|
+
}
|
|
79
|
+
async retrieve() {
|
|
80
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
81
|
+
const response = await this.kizlo._.http.get("/cart", { headers });
|
|
82
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
83
|
+
return this.kizlo._.http.success(response.data);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async update(input) {
|
|
87
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
88
|
+
const response = await this.kizlo._.http.put("/cart", {
|
|
89
|
+
body: input,
|
|
90
|
+
headers
|
|
91
|
+
});
|
|
92
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
93
|
+
return this.kizlo._.http.success(response.data);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const cart = {
|
|
98
|
+
retrieve: woocommerceProcedure.output(type()).errors(procedureErrors()).handler(async ({ context }) => {
|
|
99
|
+
return ensureProcedureResult(await context.woocommerce.cart.retrieve());
|
|
100
|
+
}),
|
|
101
|
+
update: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
102
|
+
return ensureProcedureResult(await context.woocommerce.cart.update(input));
|
|
103
|
+
}),
|
|
104
|
+
items: {
|
|
105
|
+
add: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
106
|
+
return ensureProcedureResult(await context.woocommerce.cart.items.add(input));
|
|
107
|
+
}),
|
|
108
|
+
update: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
109
|
+
return ensureProcedureResult(await context.woocommerce.cart.items.update(input));
|
|
110
|
+
}),
|
|
111
|
+
remove: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
112
|
+
return ensureProcedureResult(await context.woocommerce.cart.items.remove(input));
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
coupons: {
|
|
116
|
+
apply: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
117
|
+
return ensureProcedureResult(await context.woocommerce.cart.coupons.apply(input));
|
|
118
|
+
}),
|
|
119
|
+
remove: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
120
|
+
return ensureProcedureResult(await context.woocommerce.cart.coupons.remove(input));
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/customer/client.ts
|
|
127
|
+
var KizloAddress = class {
|
|
128
|
+
constructor(kizlo) {
|
|
129
|
+
this.kizlo = kizlo;
|
|
130
|
+
}
|
|
131
|
+
async create(input) {
|
|
132
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
133
|
+
const response = await this.kizlo._.http.post("/customers/addresses", {
|
|
134
|
+
headers,
|
|
135
|
+
body: input
|
|
136
|
+
});
|
|
137
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
138
|
+
return this.kizlo._.http.success(response.data);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
async update(input) {
|
|
142
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
143
|
+
const response = await this.kizlo._.http.put(`/customers/addresses/${input.id}`, {
|
|
144
|
+
body: input,
|
|
145
|
+
headers
|
|
146
|
+
});
|
|
147
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
148
|
+
return this.kizlo._.http.success(response.data);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async delete(input) {
|
|
152
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
153
|
+
const response = await this.kizlo._.http.delete(`/customers/addresses/${input.id}`, { headers });
|
|
154
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
155
|
+
return this.kizlo._.http.success(response.data);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
var KizloCustomer = class {
|
|
160
|
+
address;
|
|
161
|
+
constructor(kizlo) {
|
|
162
|
+
this.kizlo = kizlo;
|
|
163
|
+
this.address = new KizloAddress(this.kizlo);
|
|
164
|
+
}
|
|
165
|
+
async retrieve() {
|
|
166
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
167
|
+
const response = await this.kizlo._.http.get("/customers", { headers });
|
|
168
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
169
|
+
return this.kizlo._.http.success(response.data);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
const customer = {
|
|
174
|
+
retrieve: woocommerceProcedure.output(type()).errors(procedureErrors()).handler(async ({ context }) => {
|
|
175
|
+
return ensureProcedureResult(await context.woocommerce.customer.retrieve());
|
|
176
|
+
}),
|
|
177
|
+
address: {
|
|
178
|
+
create: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
179
|
+
return ensureProcedureResult(await context.woocommerce.customer.address.create(input));
|
|
180
|
+
}),
|
|
181
|
+
update: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
182
|
+
return ensureProcedureResult(await context.woocommerce.customer.address.update(input));
|
|
183
|
+
}),
|
|
184
|
+
delete: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
185
|
+
return ensureProcedureResult(await context.woocommerce.customer.address.delete(input));
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/order/client.ts
|
|
192
|
+
var KizloOrder = class {
|
|
193
|
+
constructor(kizlo) {
|
|
194
|
+
this.kizlo = kizlo;
|
|
195
|
+
}
|
|
196
|
+
async retrieve(input) {
|
|
197
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
198
|
+
const response = await this.kizlo._.http.get(`/orders/${input.id}`, { headers });
|
|
199
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
200
|
+
return this.kizlo._.http.success(response.data);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async list(input) {
|
|
204
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
205
|
+
const response = await this.kizlo._.http.get("/orders", {
|
|
206
|
+
headers,
|
|
207
|
+
query: input
|
|
208
|
+
});
|
|
209
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
210
|
+
return this.kizlo._.http.success(response.data);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const orders = {
|
|
215
|
+
retrieve: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
216
|
+
return ensureProcedureResult(await context.woocommerce.orders.retrieve(input));
|
|
217
|
+
}),
|
|
218
|
+
list: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
219
|
+
return ensureProcedureResult(await context.woocommerce.orders.list(input));
|
|
220
|
+
})
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/generated/contract.server.json
|
|
225
|
+
var contract_server_default = {
|
|
226
|
+
cart: {
|
|
227
|
+
"retrieve": { "~orpc": {
|
|
228
|
+
"errorMap": {},
|
|
229
|
+
"meta": {},
|
|
230
|
+
"route": {}
|
|
231
|
+
} },
|
|
232
|
+
"update": { "~orpc": {
|
|
233
|
+
"errorMap": {},
|
|
234
|
+
"meta": {},
|
|
235
|
+
"route": {}
|
|
236
|
+
} },
|
|
237
|
+
"items": {
|
|
238
|
+
"add": { "~orpc": {
|
|
239
|
+
"errorMap": {},
|
|
240
|
+
"meta": {},
|
|
241
|
+
"route": {}
|
|
242
|
+
} },
|
|
243
|
+
"update": { "~orpc": {
|
|
244
|
+
"errorMap": {},
|
|
245
|
+
"meta": {},
|
|
246
|
+
"route": {}
|
|
247
|
+
} },
|
|
248
|
+
"remove": { "~orpc": {
|
|
249
|
+
"errorMap": {},
|
|
250
|
+
"meta": {},
|
|
251
|
+
"route": {}
|
|
252
|
+
} }
|
|
253
|
+
},
|
|
254
|
+
"coupons": {
|
|
255
|
+
"apply": { "~orpc": {
|
|
256
|
+
"errorMap": {},
|
|
257
|
+
"meta": {},
|
|
258
|
+
"route": {}
|
|
259
|
+
} },
|
|
260
|
+
"remove": { "~orpc": {
|
|
261
|
+
"errorMap": {},
|
|
262
|
+
"meta": {},
|
|
263
|
+
"route": {}
|
|
264
|
+
} }
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
orders: {
|
|
268
|
+
"retrieve": { "~orpc": {
|
|
269
|
+
"errorMap": {},
|
|
270
|
+
"meta": {},
|
|
271
|
+
"route": {}
|
|
272
|
+
} },
|
|
273
|
+
"list": { "~orpc": {
|
|
274
|
+
"errorMap": {},
|
|
275
|
+
"meta": {},
|
|
276
|
+
"route": {}
|
|
277
|
+
} }
|
|
278
|
+
},
|
|
279
|
+
customer: {
|
|
280
|
+
"retrieve": { "~orpc": {
|
|
281
|
+
"errorMap": {},
|
|
282
|
+
"meta": {},
|
|
283
|
+
"route": {}
|
|
284
|
+
} },
|
|
285
|
+
"address": {
|
|
286
|
+
"create": { "~orpc": {
|
|
287
|
+
"errorMap": {},
|
|
288
|
+
"meta": {},
|
|
289
|
+
"route": {}
|
|
290
|
+
} },
|
|
291
|
+
"update": { "~orpc": {
|
|
292
|
+
"errorMap": {},
|
|
293
|
+
"meta": {},
|
|
294
|
+
"route": {}
|
|
295
|
+
} },
|
|
296
|
+
"delete": { "~orpc": {
|
|
297
|
+
"errorMap": {},
|
|
298
|
+
"meta": {},
|
|
299
|
+
"route": {}
|
|
300
|
+
} }
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
products: {
|
|
304
|
+
"retrieve": { "~orpc": {
|
|
305
|
+
"errorMap": {},
|
|
306
|
+
"meta": {},
|
|
307
|
+
"route": {}
|
|
308
|
+
} },
|
|
309
|
+
"list": { "~orpc": {
|
|
310
|
+
"errorMap": {},
|
|
311
|
+
"meta": {},
|
|
312
|
+
"route": {}
|
|
313
|
+
} },
|
|
314
|
+
"collection": { "~orpc": {
|
|
315
|
+
"errorMap": {},
|
|
316
|
+
"meta": {},
|
|
317
|
+
"route": {}
|
|
318
|
+
} },
|
|
319
|
+
"categories": { "list": { "~orpc": {
|
|
320
|
+
"errorMap": {},
|
|
321
|
+
"meta": {},
|
|
322
|
+
"route": {}
|
|
323
|
+
} } },
|
|
324
|
+
"reviews": {
|
|
325
|
+
"retrieve": { "~orpc": {
|
|
326
|
+
"errorMap": {},
|
|
327
|
+
"meta": {},
|
|
328
|
+
"route": {}
|
|
329
|
+
} },
|
|
330
|
+
"list": { "~orpc": {
|
|
331
|
+
"errorMap": {},
|
|
332
|
+
"meta": {},
|
|
333
|
+
"route": {}
|
|
334
|
+
} },
|
|
335
|
+
"create": { "~orpc": {
|
|
336
|
+
"errorMap": {},
|
|
337
|
+
"meta": {},
|
|
338
|
+
"route": {}
|
|
339
|
+
} }
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
payment: {
|
|
343
|
+
"confirm": { "~orpc": {
|
|
344
|
+
"errorMap": {},
|
|
345
|
+
"meta": {},
|
|
346
|
+
"route": {}
|
|
347
|
+
} },
|
|
348
|
+
"update": { "~orpc": {
|
|
349
|
+
"errorMap": {},
|
|
350
|
+
"meta": {},
|
|
351
|
+
"route": {}
|
|
352
|
+
} },
|
|
353
|
+
"methods": { "~orpc": {
|
|
354
|
+
"errorMap": {},
|
|
355
|
+
"meta": {},
|
|
356
|
+
"route": { "method": "GET" }
|
|
357
|
+
} },
|
|
358
|
+
"pay": { "~orpc": {
|
|
359
|
+
"errorMap": {},
|
|
360
|
+
"meta": {},
|
|
361
|
+
"route": {}
|
|
362
|
+
} },
|
|
363
|
+
"webhooks": { "~orpc": {
|
|
364
|
+
"errorMap": {},
|
|
365
|
+
"meta": {},
|
|
366
|
+
"route": {
|
|
367
|
+
"method": "POST",
|
|
368
|
+
"path": "/payment/webhooks/{id}",
|
|
369
|
+
"inputStructure": "detailed"
|
|
370
|
+
}
|
|
371
|
+
} }
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/server.client.ts
|
|
377
|
+
function createWoocommerceServerRouter(options) {
|
|
378
|
+
return {
|
|
379
|
+
...woocommerceRouter,
|
|
380
|
+
payment: createPaymentServerRouter(options)
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/server.extension.ts
|
|
386
|
+
const woocommerceRemoteProcedure = remoteProcedure.use(remoteProcedure.middleware(({ context, next }) => {
|
|
387
|
+
return next({ context: { woocommerce: new KizloWoocommerce(context.kizlo) } });
|
|
388
|
+
}));
|
|
389
|
+
const woocommerceOpenApiProcedure = openApiProcedure.use(openApiProcedure.middleware(({ context, next }) => {
|
|
390
|
+
return next({ context: { woocommerce: new KizloWoocommerce(context.kizlo) } });
|
|
391
|
+
}));
|
|
392
|
+
function woocommerce(options) {
|
|
393
|
+
return createServerExtension({
|
|
394
|
+
name: "woocommerce",
|
|
395
|
+
init() {
|
|
396
|
+
return createWoocommerceServerRouter(options);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
//#endregion
|
|
402
|
+
//#region src/payment/client.ts
|
|
403
|
+
var KizloPayment = class {
|
|
404
|
+
admin;
|
|
405
|
+
rpc;
|
|
406
|
+
constructor(kizlo) {
|
|
407
|
+
this.kizlo = kizlo;
|
|
408
|
+
this.admin = new KizloPaymentAdmin(this.kizlo);
|
|
409
|
+
this.rpc = createSafeClient(createRemoteFetchClient(contract_server_default, `${this.kizlo._.serverBaseUrl}/woocommerce`));
|
|
410
|
+
}
|
|
411
|
+
async methods() {
|
|
412
|
+
const { error, data, isDefined } = await this.rpc.payment.methods();
|
|
413
|
+
if (error) {
|
|
414
|
+
if (isDefined) return this.kizlo._.http.error({
|
|
415
|
+
code: error.code,
|
|
416
|
+
message: error.message,
|
|
417
|
+
status: error.status
|
|
418
|
+
});
|
|
419
|
+
throw error;
|
|
420
|
+
}
|
|
421
|
+
return this.kizlo._.http.success(data);
|
|
422
|
+
}
|
|
423
|
+
async pay(input) {
|
|
424
|
+
const { error, data, isDefined } = await this.rpc.payment.pay(input);
|
|
425
|
+
if (error) {
|
|
426
|
+
if (isDefined) return this.kizlo._.http.error({
|
|
427
|
+
code: error.code,
|
|
428
|
+
message: error.message,
|
|
429
|
+
status: error.status
|
|
430
|
+
});
|
|
431
|
+
throw error;
|
|
432
|
+
}
|
|
433
|
+
return this.kizlo._.http.success(data);
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
var KizloPaymentAdmin = class {
|
|
437
|
+
constructor(kizlo) {
|
|
438
|
+
this.kizlo = kizlo;
|
|
439
|
+
}
|
|
440
|
+
async confirm(input) {
|
|
441
|
+
const response = await this.kizlo._.http.post("/payment", { body: input });
|
|
442
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
443
|
+
return this.kizlo._.http.success(response.data);
|
|
444
|
+
}
|
|
445
|
+
async update(input) {
|
|
446
|
+
const response = await this.kizlo._.http.put(`/payment/${input.order_id}`, { body: input });
|
|
447
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
448
|
+
return this.kizlo._.http.success(response.data);
|
|
449
|
+
}
|
|
450
|
+
async methods(input) {
|
|
451
|
+
const groups = /* @__PURE__ */ new Map();
|
|
452
|
+
for (const adapter of input.adapters) {
|
|
453
|
+
const config = adapter;
|
|
454
|
+
if (!groups.has(config.type)) groups.set(config.type, []);
|
|
455
|
+
groups.get(config.type)?.push(config);
|
|
456
|
+
}
|
|
457
|
+
const getPrioritizedAdapter = (group) => {
|
|
458
|
+
let best = null;
|
|
459
|
+
for (const adapter of group) if (!best || adapter.priority > best.priority) best = adapter;
|
|
460
|
+
return best;
|
|
461
|
+
};
|
|
462
|
+
const methods = [];
|
|
463
|
+
for (const [, group] of groups) {
|
|
464
|
+
const selectedAdapters = [];
|
|
465
|
+
const combinableAdapters = group.filter((adapter) => adapter.isCombinable);
|
|
466
|
+
if (combinableAdapters.length > 1) for (const adapter of combinableAdapters) selectedAdapters.push(adapter);
|
|
467
|
+
else {
|
|
468
|
+
const bestAdapter = getPrioritizedAdapter(group);
|
|
469
|
+
if (bestAdapter) selectedAdapters.push(bestAdapter);
|
|
470
|
+
}
|
|
471
|
+
for (const adapter of selectedAdapters) {
|
|
472
|
+
const eligibility = await adapter.eligibility?.(input.context);
|
|
473
|
+
if (eligibility?.is_hidden) continue;
|
|
474
|
+
methods.push({
|
|
475
|
+
id: adapter.id,
|
|
476
|
+
type: adapter.type,
|
|
477
|
+
name: eligibility?.name ?? adapter.name,
|
|
478
|
+
is_disabled: eligibility?.is_disabled ?? false,
|
|
479
|
+
description: eligibility?.description ?? adapter.description
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (new Set(methods.map((method) => method.id)).size !== methods.length) return this.kizlo._.http.error("PAYMENT_DUPLICATE_ADAPTERS");
|
|
484
|
+
return this.kizlo._.http.success(methods);
|
|
485
|
+
}
|
|
486
|
+
async pay(input) {
|
|
487
|
+
const adapter = input.adapters.find((adp) => adp.id === input.payment_method_id);
|
|
488
|
+
if (!adapter) return this.kizlo._.http.error("PAYMENT_ADAPTER_NOT_FOUND");
|
|
489
|
+
const session = await this.kizlo.auth.session.retrieve();
|
|
490
|
+
if (!session) return this.kizlo._.http.error("AUTH_REQUIRED");
|
|
491
|
+
const confirmResult = await this.confirm({
|
|
492
|
+
user_id: session.user.id,
|
|
493
|
+
payment_method_id: adapter.id,
|
|
494
|
+
payment_method_name: adapter.name,
|
|
495
|
+
payment_method_type: adapter.type
|
|
496
|
+
});
|
|
497
|
+
if (confirmResult.isError) return this.kizlo._.http.error(confirmResult.error);
|
|
498
|
+
if (adapter.type === "online") {
|
|
499
|
+
const intent = await adapter.create({ order: confirmResult.data }, input.context);
|
|
500
|
+
if (!intent || !intent.url) return this.kizlo._.http.error("PAYMENT_ADAPTER_NOT_FOUND");
|
|
501
|
+
const updateResult = await this.update({
|
|
502
|
+
order_id: confirmResult.data.id,
|
|
503
|
+
payment_status: intent.status,
|
|
504
|
+
payment_session_id: intent.id,
|
|
505
|
+
transaction_id: intent.transaction_id,
|
|
506
|
+
payment_url: intent.url
|
|
507
|
+
});
|
|
508
|
+
if (updateResult.isError) return this.kizlo._.http.error(updateResult.error);
|
|
509
|
+
return this.kizlo._.http.success({ redirect_url: intent.url });
|
|
510
|
+
}
|
|
511
|
+
return this.kizlo._.http.success({ redirect_url: "" });
|
|
512
|
+
}
|
|
513
|
+
async handleWebhook(input) {
|
|
514
|
+
const adapter = input.adapters.find((a) => a.id === input.payment_method_id);
|
|
515
|
+
if (!adapter || adapter.type !== "online") return this.kizlo._.http.error("PAYMENT_ADAPTER_NOT_FOUND");
|
|
516
|
+
const data = await adapter.verify(input.context);
|
|
517
|
+
if (!data) return this.kizlo._.http.error("UNAUTHORIZED");
|
|
518
|
+
const updateResult = await this.update({
|
|
519
|
+
order_id: data.order_id,
|
|
520
|
+
payment_status: data.status,
|
|
521
|
+
transaction_id: data.transaction_id
|
|
522
|
+
});
|
|
523
|
+
if (updateResult.error) return this.kizlo._.http.error(updateResult.error);
|
|
524
|
+
return this.kizlo._.http.success({ success: true });
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
const paymentRouter = {
|
|
528
|
+
methods: woocommerceProcedure.output(type()).errors(procedureErrors()).handler(async ({ context }) => {
|
|
529
|
+
return ensureProcedureResult(await context.woocommerce.payment.methods());
|
|
530
|
+
}),
|
|
531
|
+
pay: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
532
|
+
return ensureProcedureResult(await context.woocommerce.payment.pay(input));
|
|
533
|
+
})
|
|
534
|
+
};
|
|
535
|
+
function createPaymentServerRouter(options) {
|
|
536
|
+
return {
|
|
537
|
+
confirm: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
538
|
+
return ensureProcedureResult(await context.woocommerce.payment.admin.confirm(input));
|
|
539
|
+
}),
|
|
540
|
+
update: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
541
|
+
return ensureProcedureResult(await context.woocommerce.payment.admin.update(input));
|
|
542
|
+
}),
|
|
543
|
+
methods: woocommerceRemoteProcedure.route({ method: "GET" }).output(type()).errors(procedureErrors()).handler(async ({ context }) => {
|
|
544
|
+
return ensureProcedureResult(await context.woocommerce.payment.admin.methods({
|
|
545
|
+
context,
|
|
546
|
+
adapters: options?.paymentAdapters ?? []
|
|
547
|
+
}));
|
|
548
|
+
}),
|
|
549
|
+
pay: woocommerceRemoteProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
550
|
+
return ensureProcedureResult(await context.woocommerce.payment.admin.pay({
|
|
551
|
+
context,
|
|
552
|
+
adapters: options?.paymentAdapters ?? [],
|
|
553
|
+
payment_method_id: input.payment_method_id
|
|
554
|
+
}));
|
|
555
|
+
}),
|
|
556
|
+
webhooks: woocommerceOpenApiProcedure.route({
|
|
557
|
+
method: "POST",
|
|
558
|
+
path: "/payment/webhooks/{id}",
|
|
559
|
+
inputStructure: "detailed"
|
|
560
|
+
}).input(type()).handler(async ({ input, context }) => {
|
|
561
|
+
return ensureProcedureResult(context.woocommerce.payment.admin.handleWebhook({
|
|
562
|
+
context,
|
|
563
|
+
payment_method_id: input.params.id,
|
|
564
|
+
adapters: options?.paymentAdapters ?? []
|
|
565
|
+
}));
|
|
566
|
+
})
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/product/client.ts
|
|
572
|
+
var KizloProductCategory = class {
|
|
573
|
+
constructor(kizlo) {
|
|
574
|
+
this.kizlo = kizlo;
|
|
575
|
+
}
|
|
576
|
+
async list(input) {
|
|
577
|
+
const response = await this.kizlo._.http.get("/products/categories", { query: input });
|
|
578
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
579
|
+
return this.kizlo._.http.success(response.data);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
var KizloProductReview = class {
|
|
583
|
+
constructor(kizlo) {
|
|
584
|
+
this.kizlo = kizlo;
|
|
585
|
+
}
|
|
586
|
+
async retrieve(input) {
|
|
587
|
+
const response = await this.kizlo._.http.get(`/products/reviews/${input.id}`, { query: input });
|
|
588
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
589
|
+
return this.kizlo._.http.success(response.data);
|
|
590
|
+
}
|
|
591
|
+
async list(input) {
|
|
592
|
+
const response = await this.kizlo._.http.get("/products/reviews", { query: input });
|
|
593
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
594
|
+
return this.kizlo._.http.success(response.data);
|
|
595
|
+
}
|
|
596
|
+
async create(input) {
|
|
597
|
+
return this.kizlo.auth.session.ensure(async ({ headers }) => {
|
|
598
|
+
const response = await this.kizlo._.http.post("/products/reviews", {
|
|
599
|
+
headers,
|
|
600
|
+
body: input
|
|
601
|
+
});
|
|
602
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
603
|
+
return this.kizlo._.http.success(response.data);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
var KizloProduct = class {
|
|
608
|
+
reviews;
|
|
609
|
+
categories;
|
|
610
|
+
constructor(kizlo) {
|
|
611
|
+
this.kizlo = kizlo;
|
|
612
|
+
this.reviews = new KizloProductReview(this.kizlo);
|
|
613
|
+
this.categories = new KizloProductCategory(this.kizlo);
|
|
614
|
+
}
|
|
615
|
+
async retrieve(input) {
|
|
616
|
+
const response = await this.kizlo._.http.get(`/products/${input.slug}`, { query: input });
|
|
617
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
618
|
+
return this.kizlo._.http.success(response.data);
|
|
619
|
+
}
|
|
620
|
+
async list(input) {
|
|
621
|
+
const response = await this.kizlo._.http.get("/products", { query: input });
|
|
622
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
623
|
+
return this.kizlo._.http.success(response.data);
|
|
624
|
+
}
|
|
625
|
+
async collection(input) {
|
|
626
|
+
const response = await this.kizlo._.http.get("/products/collection", { query: input });
|
|
627
|
+
if (response.error) return this.kizlo._.http.error(response.error);
|
|
628
|
+
return this.kizlo._.http.success(response.data);
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
const products = {
|
|
632
|
+
retrieve: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
633
|
+
return ensureProcedureResult(await context.woocommerce.products.retrieve(input));
|
|
634
|
+
}),
|
|
635
|
+
list: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
636
|
+
return ensureProcedureResult(await context.woocommerce.products.list(input));
|
|
637
|
+
}),
|
|
638
|
+
collection: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
639
|
+
return ensureProcedureResult(await context.woocommerce.products.collection(input));
|
|
640
|
+
}),
|
|
641
|
+
categories: { list: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
642
|
+
return ensureProcedureResult(await context.woocommerce.products.categories.list(input));
|
|
643
|
+
}) },
|
|
644
|
+
reviews: {
|
|
645
|
+
retrieve: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
646
|
+
return ensureProcedureResult(await context.woocommerce.products.reviews.retrieve(input));
|
|
647
|
+
}),
|
|
648
|
+
list: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
649
|
+
return ensureProcedureResult(await context.woocommerce.products.reviews.list(input));
|
|
650
|
+
}),
|
|
651
|
+
create: woocommerceProcedure.input(type()).output(type()).errors(procedureErrors()).handler(async ({ input, context }) => {
|
|
652
|
+
return ensureProcedureResult(await context.woocommerce.products.reviews.create(input));
|
|
653
|
+
})
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region src/client.ts
|
|
659
|
+
var KizloWoocommerce = class {
|
|
660
|
+
cart;
|
|
661
|
+
orders;
|
|
662
|
+
customer;
|
|
663
|
+
products;
|
|
664
|
+
payment;
|
|
665
|
+
constructor(kizlo) {
|
|
666
|
+
this.kizlo = kizlo;
|
|
667
|
+
this.cart = new KizloCart(this.kizlo);
|
|
668
|
+
this.orders = new KizloOrder(this.kizlo);
|
|
669
|
+
this.customer = new KizloCustomer(this.kizlo);
|
|
670
|
+
this.products = new KizloProduct(this.kizlo);
|
|
671
|
+
this.payment = new KizloPayment(this.kizlo);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
const woocommerceRouter = {
|
|
675
|
+
cart,
|
|
676
|
+
orders,
|
|
677
|
+
customer,
|
|
678
|
+
products,
|
|
679
|
+
payment: paymentRouter
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
//#endregion
|
|
683
|
+
export { cart as C, KizloCoupon as S, woocommerceProcedure as T, KizloAddress as _, KizloProductReview as a, KizloCart as b, KizloPaymentAdmin as c, woocommerce as d, woocommerceOpenApiProcedure as f, orders as g, KizloOrder as h, KizloProductCategory as i, createPaymentServerRouter as l, createWoocommerceServerRouter as m, woocommerceRouter as n, products as o, woocommerceRemoteProcedure as p, KizloProduct as r, KizloPayment as s, KizloWoocommerce as t, paymentRouter as u, KizloCustomer as v, woocommerce$1 as w, KizloCartItem as x, customer as y };
|
|
684
|
+
//# sourceMappingURL=client-BJuv_NtE.js.map
|