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