@deliverart/sdk-js-core 0.0.0-dev-20260721002647
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/README.md +429 -0
- package/dist/index.cjs +646 -0
- package/dist/index.d.cts +125 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.js +603 -0
- package/package.json +35 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
"use strict";
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AbstractApiRequest: () => AbstractApiRequest,
|
|
34
|
+
InputValidationError: () => InputValidationError,
|
|
35
|
+
OutputValidationError: () => OutputValidationError,
|
|
36
|
+
createApiClient: () => createApiClient,
|
|
37
|
+
deserializeFromClient: () => deserializeFromClient,
|
|
38
|
+
serializeForClient: () => serializeForClient,
|
|
39
|
+
serializedIriObjectSchema: () => serializedIriObjectSchema
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// ../global-types/dist/index.js
|
|
44
|
+
var import_zod = require("zod");
|
|
45
|
+
var import_zod2 = require("zod");
|
|
46
|
+
var import_zod3 = require("zod");
|
|
47
|
+
var import_zod4 = require("zod");
|
|
48
|
+
var daysOfWeek = [
|
|
49
|
+
"monday",
|
|
50
|
+
"tuesday",
|
|
51
|
+
"wednesday",
|
|
52
|
+
"thursday",
|
|
53
|
+
"friday",
|
|
54
|
+
"saturday",
|
|
55
|
+
"sunday"
|
|
56
|
+
];
|
|
57
|
+
var sortDirections = ["asc", "desc"];
|
|
58
|
+
var queryParamsDateCompare = [
|
|
59
|
+
"before",
|
|
60
|
+
"strictly_before",
|
|
61
|
+
"after",
|
|
62
|
+
"strictly_after"
|
|
63
|
+
];
|
|
64
|
+
var queryParamsNumberCompare = ["gt", "gte", "lt", "lte"];
|
|
65
|
+
var arrayContainsMatchOptions = ["all", "any"];
|
|
66
|
+
var emailTemplateKeys = [
|
|
67
|
+
"delivery_started",
|
|
68
|
+
"delivery_taken_over",
|
|
69
|
+
"order_created",
|
|
70
|
+
"order_delivered",
|
|
71
|
+
"order_in_preparation",
|
|
72
|
+
"order_preparation_done",
|
|
73
|
+
"subscription_expiring",
|
|
74
|
+
"subscription_low_credits",
|
|
75
|
+
"subscription_pending_renewal",
|
|
76
|
+
"subscription_payment_pending_verification"
|
|
77
|
+
];
|
|
78
|
+
var emailTemplateKeySchema = import_zod.z.enum(emailTemplateKeys);
|
|
79
|
+
var apiTokenTypes = ["full_access", "point_of_sale"];
|
|
80
|
+
var apiTokenTypeSchema = import_zod.z.enum(apiTokenTypes);
|
|
81
|
+
var apiTokenModes = ["READ_ONLY", "READ_AND_WRITE"];
|
|
82
|
+
var apiTokenModeSchema = import_zod.z.enum(apiTokenModes);
|
|
83
|
+
var deliveryFeeTypes = ["amount", "distance", "postal_code"];
|
|
84
|
+
var deliveryFeeTypeSchema = import_zod.z.enum(deliveryFeeTypes);
|
|
85
|
+
var menuChannels = [
|
|
86
|
+
"application",
|
|
87
|
+
"ecommerce",
|
|
88
|
+
"deliveroo",
|
|
89
|
+
"justeat",
|
|
90
|
+
"glovo",
|
|
91
|
+
"tilby",
|
|
92
|
+
"cassa_in_cloud",
|
|
93
|
+
"elephant"
|
|
94
|
+
];
|
|
95
|
+
var menuChannelSchema = import_zod.z.enum(menuChannels);
|
|
96
|
+
var orderPartners = [
|
|
97
|
+
"cassa_in_cloud",
|
|
98
|
+
"deliveroo",
|
|
99
|
+
"justeat",
|
|
100
|
+
"glovo",
|
|
101
|
+
"tilby",
|
|
102
|
+
"elephant"
|
|
103
|
+
];
|
|
104
|
+
var orderPartnerSchema = import_zod.z.enum(orderPartners);
|
|
105
|
+
var menuItemAllergens = [
|
|
106
|
+
"peanuts-and-derivatives",
|
|
107
|
+
"crustaceans",
|
|
108
|
+
"nuts",
|
|
109
|
+
"gluten",
|
|
110
|
+
"milk-and-derivatives",
|
|
111
|
+
"lupins",
|
|
112
|
+
"molluscs",
|
|
113
|
+
"mustard",
|
|
114
|
+
"fish",
|
|
115
|
+
"celery",
|
|
116
|
+
"sesame",
|
|
117
|
+
"sulfur-dioxide",
|
|
118
|
+
"soy",
|
|
119
|
+
"eggs-and-derivatives",
|
|
120
|
+
"mushrooms"
|
|
121
|
+
];
|
|
122
|
+
var menuItemAllergenSchema = import_zod.z.enum(menuItemAllergens);
|
|
123
|
+
var menuItemDiets = ["vegan", "vegetarian", "gluten-free", "dairy-free"];
|
|
124
|
+
var menuItemDietSchema = import_zod.z.enum(menuItemDiets);
|
|
125
|
+
var menuItemPriceOverrideTypes = ["ITEM", "MODIFIER"];
|
|
126
|
+
var menuItemPriceOverrideTypeSchema = import_zod.z.enum(menuItemPriceOverrideTypes);
|
|
127
|
+
var menuItemTypes = ["ITEM", "CHOICE", "BUNDLE"];
|
|
128
|
+
var menuItemTypeSchema = import_zod.z.enum(menuItemTypes);
|
|
129
|
+
var menuItemModifierTargetItemTypes = ["ITEM", "BUNDLE"];
|
|
130
|
+
var menuItemModifierTargetItemTypeSchema = import_zod.z.enum(menuItemModifierTargetItemTypes);
|
|
131
|
+
var menuItemModifierScopes = ["global", "category", "item"];
|
|
132
|
+
var menuItemModifierScopeSchema = import_zod.z.enum(menuItemModifierScopes);
|
|
133
|
+
var orderTypes = ["delivery", "collection", "kitchen"];
|
|
134
|
+
var orderTypeSchema = import_zod.z.union([import_zod.z.enum(orderTypes), import_zod.z.literal("take_away")]).transform((value) => value === "take_away" ? "collection" : value);
|
|
135
|
+
var orderSources = ["application", "ecommerce", "partner"];
|
|
136
|
+
var orderSourceSchema = import_zod.z.enum(orderSources);
|
|
137
|
+
var orderStatuses = ["pending", "confirmed", "rejected"];
|
|
138
|
+
var orderStatusSchema = import_zod.z.enum(orderStatuses);
|
|
139
|
+
var orderPreparationStatuses = ["to_prepare", "in_preparation", "done"];
|
|
140
|
+
var orderPreparationStatusSchema = import_zod.z.enum(orderPreparationStatuses);
|
|
141
|
+
var orderMenuItemActions = ["add", "remove"];
|
|
142
|
+
var orderMenuItemActionSchema = import_zod.z.enum(orderMenuItemActions);
|
|
143
|
+
var orderPlanningModes = ["PLANNED", "FORCED"];
|
|
144
|
+
var orderPlanningModeSchema = import_zod.z.enum(orderPlanningModes);
|
|
145
|
+
var bundleStatuses = ["pending", "busy", "broken", "released"];
|
|
146
|
+
var bundleStatusSchema = import_zod.z.enum(bundleStatuses);
|
|
147
|
+
var bundleTypes = ["REGULAR", "FORCED"];
|
|
148
|
+
var bundleTypeSchema = import_zod.z.enum(bundleTypes);
|
|
149
|
+
var bundleBundleBrokenReasons = ["delivery_removed"];
|
|
150
|
+
var bundleBundleBrokenReasonSchema = import_zod.z.enum(bundleBundleBrokenReasons);
|
|
151
|
+
var slotInvalidReasons = [
|
|
152
|
+
"store_closed",
|
|
153
|
+
"no_capacity",
|
|
154
|
+
"outside_lead_time",
|
|
155
|
+
"journey_outside_window"
|
|
156
|
+
];
|
|
157
|
+
var slotInvalidReasonSchema = import_zod.z.enum(slotInvalidReasons);
|
|
158
|
+
var rescheduleOptionStatuses = [
|
|
159
|
+
"keep_current_bundle",
|
|
160
|
+
"create_new_bundle",
|
|
161
|
+
"move_to_reference_bundle",
|
|
162
|
+
"unavailable"
|
|
163
|
+
];
|
|
164
|
+
var rescheduleOptionStatusSchema = import_zod.z.enum(rescheduleOptionStatuses);
|
|
165
|
+
var deliveryRunStates = [
|
|
166
|
+
"not_started",
|
|
167
|
+
"awaiting_stop_selection",
|
|
168
|
+
"delivering_stop",
|
|
169
|
+
"ready_to_finish",
|
|
170
|
+
"finished"
|
|
171
|
+
];
|
|
172
|
+
var deliveryRunStateSchema = import_zod.z.enum(deliveryRunStates);
|
|
173
|
+
var paymentMethods = ["stripe", "bank_transfer", "cash", "credit_card"];
|
|
174
|
+
var paymentMethodSchema = import_zod.z.enum(paymentMethods);
|
|
175
|
+
var paymentStatuses = [
|
|
176
|
+
"pending",
|
|
177
|
+
"pending_verification",
|
|
178
|
+
"paid",
|
|
179
|
+
"canceled",
|
|
180
|
+
"refunded",
|
|
181
|
+
"failed"
|
|
182
|
+
];
|
|
183
|
+
var paymentStatusSchema = import_zod.z.enum(paymentStatuses);
|
|
184
|
+
var subscriptionStatuses = [
|
|
185
|
+
"created",
|
|
186
|
+
"active",
|
|
187
|
+
"pending_renewal",
|
|
188
|
+
"expired",
|
|
189
|
+
"suspended",
|
|
190
|
+
"cancelled"
|
|
191
|
+
];
|
|
192
|
+
var subscriptionStatusSchema = import_zod.z.enum(subscriptionStatuses);
|
|
193
|
+
var subscriptionTypes = ["infinite", "time_based", "consumption"];
|
|
194
|
+
var subscriptionTypeSchema = import_zod.z.enum(subscriptionTypes);
|
|
195
|
+
var renewalStatuses = [
|
|
196
|
+
"pending",
|
|
197
|
+
"pending_verification",
|
|
198
|
+
"completed",
|
|
199
|
+
"cancelled",
|
|
200
|
+
"failed"
|
|
201
|
+
];
|
|
202
|
+
var renewalStatusSchema = import_zod.z.enum(renewalStatuses);
|
|
203
|
+
var creditTransactionTypes = [
|
|
204
|
+
"consumption",
|
|
205
|
+
"renewal",
|
|
206
|
+
"gift",
|
|
207
|
+
"bonus",
|
|
208
|
+
"refund",
|
|
209
|
+
"manual_adjustment"
|
|
210
|
+
];
|
|
211
|
+
var creditTransactionTypeSchema = import_zod.z.enum(creditTransactionTypes);
|
|
212
|
+
var printerProtocols = ["epson_epos", "esc_pos"];
|
|
213
|
+
var printerProtocolSchema = import_zod.z.enum(printerProtocols);
|
|
214
|
+
var printerDrivers = ["epson_sdk", "epos_print_xml"];
|
|
215
|
+
var printerDriverSchema = import_zod.z.enum(printerDrivers);
|
|
216
|
+
var printerReceiptProfiles = [
|
|
217
|
+
"80mm_42col",
|
|
218
|
+
"80mm_48col",
|
|
219
|
+
"58mm_32col",
|
|
220
|
+
"58mm_35col"
|
|
221
|
+
];
|
|
222
|
+
var printerReceiptProfileSchema = import_zod.z.enum(printerReceiptProfiles);
|
|
223
|
+
var webhookEvents = ["create", "update", "delete"];
|
|
224
|
+
var webhookEventSchema = import_zod.z.enum(webhookEvents);
|
|
225
|
+
var webhookLogStatuses = ["pending", "success", "failed", "timeout"];
|
|
226
|
+
var webhookLogStatusSchema = import_zod.z.enum(webhookLogStatuses);
|
|
227
|
+
var webhookEntities = [
|
|
228
|
+
"App\\Entity\\Bundle",
|
|
229
|
+
"App\\Entity\\Customer",
|
|
230
|
+
"App\\Entity\\CustomerAddress",
|
|
231
|
+
"App\\Entity\\CustomerBusinessProfile",
|
|
232
|
+
"App\\Entity\\Delivery",
|
|
233
|
+
"App\\Entity\\DeliveryPosition",
|
|
234
|
+
"App\\Entity\\Integration",
|
|
235
|
+
"App\\Entity\\IntegrationActivationRequest",
|
|
236
|
+
"App\\Entity\\Order",
|
|
237
|
+
"App\\Entity\\PointOfSale"
|
|
238
|
+
];
|
|
239
|
+
var webhookEntitySchema = import_zod.z.enum(webhookEntities);
|
|
240
|
+
var uuidPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/i;
|
|
241
|
+
var isUuid = (s) => uuidPattern.test(s);
|
|
242
|
+
var uuidLikeSchema = import_zod2.z.string().regex(uuidPattern, { message: "Invalid UUID format" });
|
|
243
|
+
var IriObject = class {
|
|
244
|
+
constructor(iri, pattern) {
|
|
245
|
+
this.iri = iri;
|
|
246
|
+
this.params = this.extractParams(iri, pattern);
|
|
247
|
+
this.__pattern = pattern;
|
|
248
|
+
}
|
|
249
|
+
extractParams(iri, pattern) {
|
|
250
|
+
const iriParts = iri.split("/").filter(Boolean);
|
|
251
|
+
const patternParts = pattern.split("/").filter(Boolean);
|
|
252
|
+
const result = {};
|
|
253
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
254
|
+
const part = patternParts[i];
|
|
255
|
+
if (part.startsWith(":")) {
|
|
256
|
+
const key = part.slice(1);
|
|
257
|
+
const value = iriParts[i];
|
|
258
|
+
if (!isUuid(value)) {
|
|
259
|
+
throw new Error(`Invalid UUID for parameter "${key}": "${value}"`);
|
|
260
|
+
}
|
|
261
|
+
result[key] = value;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return result;
|
|
265
|
+
}
|
|
266
|
+
toString() {
|
|
267
|
+
return this.iri;
|
|
268
|
+
}
|
|
269
|
+
toJSON() {
|
|
270
|
+
return this.iri;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
var addressSchema = import_zod3.z.object({
|
|
274
|
+
line1: import_zod3.z.string().nullable().optional(),
|
|
275
|
+
line2: import_zod3.z.string().nullable().optional(),
|
|
276
|
+
city: import_zod3.z.string().nullable().optional(),
|
|
277
|
+
region: import_zod3.z.string().nullable().optional(),
|
|
278
|
+
postalCode: import_zod3.z.string().nullable().optional(),
|
|
279
|
+
country: import_zod3.z.string().nullable().optional()
|
|
280
|
+
});
|
|
281
|
+
var billingDataITSchema = import_zod3.z.object({
|
|
282
|
+
sdi: import_zod3.z.string().trim().optional().nullable(),
|
|
283
|
+
pec: import_zod3.z.email({ message: "Invalid email format" }).optional().nullable()
|
|
284
|
+
}).check((ctx) => {
|
|
285
|
+
const { sdi, pec } = ctx.value;
|
|
286
|
+
const hasSdi = sdi?.trim();
|
|
287
|
+
const hasPec = pec?.trim();
|
|
288
|
+
if (!hasSdi && !hasPec) {
|
|
289
|
+
ctx.issues.push({
|
|
290
|
+
code: "custom",
|
|
291
|
+
message: "At least one of SDI or PEC must be provided",
|
|
292
|
+
path: ["sdi"],
|
|
293
|
+
input: sdi
|
|
294
|
+
});
|
|
295
|
+
ctx.issues.push({
|
|
296
|
+
code: "custom",
|
|
297
|
+
message: "At least one of SDI or PEC must be provided",
|
|
298
|
+
path: ["pec"],
|
|
299
|
+
input: pec
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
var booleanSchema = import_zod3.z.preprocess((val) => {
|
|
304
|
+
if (typeof val === "boolean") {
|
|
305
|
+
return val;
|
|
306
|
+
}
|
|
307
|
+
if (typeof val === "number") {
|
|
308
|
+
return val === 1;
|
|
309
|
+
}
|
|
310
|
+
if (typeof val === "string") {
|
|
311
|
+
if (val === "true" || val === "1") return true;
|
|
312
|
+
if (val === "false" || val === "0") return false;
|
|
313
|
+
}
|
|
314
|
+
return val;
|
|
315
|
+
}, import_zod3.z.boolean());
|
|
316
|
+
var datetimeSchema = import_zod3.z.string().refine(
|
|
317
|
+
(value) => {
|
|
318
|
+
return !isNaN(Date.parse(value));
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
message: "Invalid datetime format"
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
var dayOfWeekSchema = import_zod3.z.enum(daysOfWeek);
|
|
325
|
+
var locationSchema = import_zod3.z.object({
|
|
326
|
+
latitude: import_zod3.z.number(),
|
|
327
|
+
longitude: import_zod3.z.number()
|
|
328
|
+
});
|
|
329
|
+
var paginationSchema = import_zod3.z.object({
|
|
330
|
+
from: import_zod3.z.coerce.number(),
|
|
331
|
+
to: import_zod3.z.coerce.number(),
|
|
332
|
+
itemsPerPage: import_zod3.z.coerce.number(),
|
|
333
|
+
totalItems: import_zod3.z.coerce.number(),
|
|
334
|
+
currentPage: import_zod3.z.coerce.number(),
|
|
335
|
+
lastPage: import_zod3.z.coerce.number()
|
|
336
|
+
});
|
|
337
|
+
var sortDirSchema = import_zod3.z.enum(sortDirections);
|
|
338
|
+
var queryParamDateCompareSchema = import_zod3.z.enum(queryParamsDateCompare);
|
|
339
|
+
var queryParamNumberCompareSchema = import_zod3.z.enum(queryParamsNumberCompare);
|
|
340
|
+
var timestampsFilterSchema = import_zod3.z.object({
|
|
341
|
+
"createdAt[before]": import_zod3.z.string().optional(),
|
|
342
|
+
"createdAt[strictly_before]": import_zod3.z.string().optional(),
|
|
343
|
+
"createdAt[after]": import_zod3.z.string().optional(),
|
|
344
|
+
"createdAt[strictly_after]": import_zod3.z.string().optional(),
|
|
345
|
+
"updatedAt[before]": import_zod3.z.string().optional(),
|
|
346
|
+
"updatedAt[strictly_before]": import_zod3.z.string().optional(),
|
|
347
|
+
"updatedAt[after]": import_zod3.z.string().optional(),
|
|
348
|
+
"updatedAt[strictly_after]": import_zod3.z.string().optional()
|
|
349
|
+
});
|
|
350
|
+
var arrayContainsMatchSchema = import_zod3.z.enum(arrayContainsMatchOptions);
|
|
351
|
+
var emptyResponseSchema = import_zod3.z.union([import_zod3.z.void(), import_zod3.z.undefined(), import_zod3.z.null()]);
|
|
352
|
+
var responseToPagination = (response) => {
|
|
353
|
+
const getHeader = (name) => {
|
|
354
|
+
const value = response.headers.get(name);
|
|
355
|
+
return value !== null ? parseInt(value, 10) : NaN;
|
|
356
|
+
};
|
|
357
|
+
return {
|
|
358
|
+
from: getHeader("x-pagination-from"),
|
|
359
|
+
to: getHeader("x-pagination-to"),
|
|
360
|
+
itemsPerPage: getHeader("x-pagination-items-per-page"),
|
|
361
|
+
totalItems: getHeader("x-pagination-total-items"),
|
|
362
|
+
currentPage: getHeader("x-pagination-current-page"),
|
|
363
|
+
lastPage: getHeader("x-pagination-last-page")
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// src/ApiClient.ts
|
|
368
|
+
var import_qs = __toESM(require("qs"), 1);
|
|
369
|
+
var import_zod5 = require("zod");
|
|
370
|
+
|
|
371
|
+
// src/errors.ts
|
|
372
|
+
var InputValidationError = class extends Error {
|
|
373
|
+
// eslint-disable-next-line no-unused-vars
|
|
374
|
+
constructor(issues) {
|
|
375
|
+
super("Invalid input");
|
|
376
|
+
this.issues = issues;
|
|
377
|
+
this.name = "InputValidationError";
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
var OutputValidationError = class extends Error {
|
|
381
|
+
// eslint-disable-next-line no-unused-vars
|
|
382
|
+
constructor(issues) {
|
|
383
|
+
super("Invalid response");
|
|
384
|
+
this.issues = issues;
|
|
385
|
+
this.name = "OutputValidationError";
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// src/ApiClient.ts
|
|
390
|
+
function serializeQueryValue(value) {
|
|
391
|
+
if (Array.isArray(value)) {
|
|
392
|
+
return value.map(serializeQueryValue);
|
|
393
|
+
}
|
|
394
|
+
if (value && typeof value === "object") {
|
|
395
|
+
const v = value;
|
|
396
|
+
if (typeof v.iri === "string") {
|
|
397
|
+
return v.iri;
|
|
398
|
+
}
|
|
399
|
+
const maybeToString = value.toString;
|
|
400
|
+
if (typeof maybeToString === "function") {
|
|
401
|
+
const str = maybeToString.call(value);
|
|
402
|
+
if (!str.startsWith("[object")) {
|
|
403
|
+
return str;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
const out = {};
|
|
407
|
+
for (const [k, v2] of Object.entries(v)) {
|
|
408
|
+
out[k] = serializeQueryValue(v2);
|
|
409
|
+
}
|
|
410
|
+
return out;
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
var AbstractApiRequest = class {
|
|
415
|
+
constructor(input2, options) {
|
|
416
|
+
this.input = input2;
|
|
417
|
+
this.options = options;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Override this in list requests to provide pagination metadata from the raw HTTP response.
|
|
421
|
+
* Default implementation uses `responseToPagination`.
|
|
422
|
+
* Return `undefined` if pagination cannot be resolved.
|
|
423
|
+
*/
|
|
424
|
+
getPagination(rawResponse) {
|
|
425
|
+
return responseToPagination(rawResponse);
|
|
426
|
+
}
|
|
427
|
+
validateInput() {
|
|
428
|
+
const result = this.inputSchema.safeParse(this.input);
|
|
429
|
+
if (!result.success) throw new InputValidationError(result.error.issues);
|
|
430
|
+
return result.data;
|
|
431
|
+
}
|
|
432
|
+
validateQuery() {
|
|
433
|
+
if (!this.querySchema || !this.options?.query) return void 0;
|
|
434
|
+
const result = this.querySchema.safeParse(this.options.query);
|
|
435
|
+
if (!result.success) throw new InputValidationError(result.error.issues);
|
|
436
|
+
return result.data;
|
|
437
|
+
}
|
|
438
|
+
validateHeaders() {
|
|
439
|
+
if (!this.headersSchema || !this.options?.headers) return void 0;
|
|
440
|
+
const result = this.headersSchema.safeParse(this.options.headers);
|
|
441
|
+
if (!result.success) throw new InputValidationError(result.error.issues);
|
|
442
|
+
return result.data;
|
|
443
|
+
}
|
|
444
|
+
validateOutput(data, useArraySchema) {
|
|
445
|
+
if (useArraySchema && this.listItemSchema) {
|
|
446
|
+
const arraySchema = import_zod5.z.array(this.listItemSchema);
|
|
447
|
+
const result2 = arraySchema.safeParse(data);
|
|
448
|
+
if (!result2.success) throw new OutputValidationError(result2.error.issues);
|
|
449
|
+
return result2.data;
|
|
450
|
+
}
|
|
451
|
+
const result = this.outputSchema.safeParse(data);
|
|
452
|
+
if (!result.success) throw new OutputValidationError(result.error.issues);
|
|
453
|
+
return result.data;
|
|
454
|
+
}
|
|
455
|
+
parseResponse(data, rawResponse, paginationOption) {
|
|
456
|
+
if (this.listItemSchema) {
|
|
457
|
+
const paginationToggle = paginationOption ?? this.paginationDefaultEnabled ?? true;
|
|
458
|
+
if (paginationOption === false) {
|
|
459
|
+
return this.validateOutput(data, true);
|
|
460
|
+
}
|
|
461
|
+
const arraySchema = import_zod5.z.array(this.listItemSchema);
|
|
462
|
+
const arrayParse = arraySchema.safeParse(data);
|
|
463
|
+
if (arrayParse.success) {
|
|
464
|
+
if (paginationToggle) {
|
|
465
|
+
const pagination = rawResponse ? this.getPagination(rawResponse) : void 0;
|
|
466
|
+
if (pagination !== void 0) {
|
|
467
|
+
return this.validateOutput({ data: arrayParse.data, pagination });
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return this.validateOutput(arrayParse.data, true);
|
|
471
|
+
}
|
|
472
|
+
if (Array.isArray(data)) {
|
|
473
|
+
throw new OutputValidationError(arrayParse.error.issues);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
return this.validateOutput(data);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
function isFormDataInstance(input2) {
|
|
480
|
+
return typeof FormData === "function" && typeof input2 === "object" && input2 !== null && input2 instanceof FormData;
|
|
481
|
+
}
|
|
482
|
+
function createApiClient(config) {
|
|
483
|
+
const requestMiddlewares = [];
|
|
484
|
+
const responseMiddlewares = [];
|
|
485
|
+
const base = {
|
|
486
|
+
fetch,
|
|
487
|
+
addRequestMiddleware(mw) {
|
|
488
|
+
requestMiddlewares.push(mw);
|
|
489
|
+
},
|
|
490
|
+
addResponseMiddleware(middleware) {
|
|
491
|
+
responseMiddlewares.push(middleware);
|
|
492
|
+
},
|
|
493
|
+
async call(request, options) {
|
|
494
|
+
const input2 = request.validateInput();
|
|
495
|
+
const query = request.validateQuery();
|
|
496
|
+
const headers = request.validateHeaders();
|
|
497
|
+
const url = new URL(request.getPath(), config.baseUrl);
|
|
498
|
+
const queryParams = { ...query || {} };
|
|
499
|
+
if (options?.pagination === false) {
|
|
500
|
+
queryParams.pagination = false;
|
|
501
|
+
}
|
|
502
|
+
if (options?.itemsPerPage !== void 0) {
|
|
503
|
+
queryParams.itemsPerPage = options.itemsPerPage;
|
|
504
|
+
}
|
|
505
|
+
if (Object.keys(queryParams).length > 0) {
|
|
506
|
+
const queryString = import_qs.default.stringify(serializeQueryValue(queryParams), {
|
|
507
|
+
arrayFormat: "brackets",
|
|
508
|
+
skipNulls: true
|
|
509
|
+
});
|
|
510
|
+
if (queryString) {
|
|
511
|
+
url.search = queryString;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
const isGet = request.method === "GET";
|
|
515
|
+
const isFormData = request.contentType === "multipart/form-data";
|
|
516
|
+
const fetchHeaders = {
|
|
517
|
+
Accept: request.accept,
|
|
518
|
+
...headers ?? {}
|
|
519
|
+
};
|
|
520
|
+
let body;
|
|
521
|
+
if (!isGet) {
|
|
522
|
+
if (isFormData && isFormDataInstance(input2)) {
|
|
523
|
+
body = input2;
|
|
524
|
+
} else {
|
|
525
|
+
fetchHeaders["Content-Type"] = request.contentType;
|
|
526
|
+
body = JSON.stringify(input2);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
let ctx = {
|
|
530
|
+
url,
|
|
531
|
+
init: {
|
|
532
|
+
method: request.method,
|
|
533
|
+
headers: fetchHeaders,
|
|
534
|
+
body
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
for (const middleware of requestMiddlewares) {
|
|
538
|
+
ctx = await middleware(ctx);
|
|
539
|
+
}
|
|
540
|
+
let response = await fetch(ctx.url.toString(), ctx.init);
|
|
541
|
+
let contentType = response.headers.get("Content-Type") ?? "";
|
|
542
|
+
let parsedBody;
|
|
543
|
+
if (response.status === 204) {
|
|
544
|
+
parsedBody = null;
|
|
545
|
+
} else {
|
|
546
|
+
try {
|
|
547
|
+
if (contentType.includes("application/")) {
|
|
548
|
+
if (contentType.includes("json")) {
|
|
549
|
+
parsedBody = await response.json();
|
|
550
|
+
} else {
|
|
551
|
+
parsedBody = await response.text();
|
|
552
|
+
}
|
|
553
|
+
} else if (contentType.includes("text/")) {
|
|
554
|
+
parsedBody = await response.text();
|
|
555
|
+
} else {
|
|
556
|
+
parsedBody = await response.arrayBuffer();
|
|
557
|
+
}
|
|
558
|
+
} catch (err) {
|
|
559
|
+
parsedBody = void 0;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
let parsedResponse = {
|
|
563
|
+
response,
|
|
564
|
+
body: parsedBody
|
|
565
|
+
};
|
|
566
|
+
for (const middleware of responseMiddlewares) {
|
|
567
|
+
parsedResponse = await middleware(parsedResponse, ctx);
|
|
568
|
+
}
|
|
569
|
+
if (!parsedResponse.response.ok) {
|
|
570
|
+
throw new Error(`HTTP ${parsedResponse.response.status}`);
|
|
571
|
+
}
|
|
572
|
+
return request.parseResponse(
|
|
573
|
+
parsedResponse.body,
|
|
574
|
+
parsedResponse.response,
|
|
575
|
+
options?.pagination
|
|
576
|
+
);
|
|
577
|
+
},
|
|
578
|
+
addPlugin(plugin) {
|
|
579
|
+
const extension = plugin.setup(this);
|
|
580
|
+
return { ...this, ...extension };
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
return base;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/serialization.ts
|
|
587
|
+
var import_zod6 = require("zod");
|
|
588
|
+
var serializedIriObjectSchema = import_zod6.z.object({
|
|
589
|
+
iri: import_zod6.z.string().min(1),
|
|
590
|
+
params: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.string()),
|
|
591
|
+
__pattern: import_zod6.z.string().min(1)
|
|
592
|
+
}).strict();
|
|
593
|
+
function isSerializedIriObject(input2) {
|
|
594
|
+
return typeof input2 === "object" && input2 !== null && "iri" in input2 && "params" in input2 && "__pattern" in input2 && typeof input2.iri === "string" && typeof input2.__pattern === "string" && typeof input2.params === "object";
|
|
595
|
+
}
|
|
596
|
+
function deserializeIri(s) {
|
|
597
|
+
return new IriObject(s.iri, s.__pattern);
|
|
598
|
+
}
|
|
599
|
+
function serializeForClient(input2) {
|
|
600
|
+
if (input2 instanceof IriObject) {
|
|
601
|
+
return {
|
|
602
|
+
iri: input2.iri,
|
|
603
|
+
params: input2.params,
|
|
604
|
+
__pattern: input2.__pattern
|
|
605
|
+
// qui P è literal
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
if (Array.isArray(input2)) {
|
|
609
|
+
return input2.map((item) => serializeForClient(item));
|
|
610
|
+
}
|
|
611
|
+
if (input2 !== null && typeof input2 === "object") {
|
|
612
|
+
const result = {};
|
|
613
|
+
for (const key in input2) {
|
|
614
|
+
const value = input2[key];
|
|
615
|
+
result[key] = serializeForClient(value);
|
|
616
|
+
}
|
|
617
|
+
return result;
|
|
618
|
+
}
|
|
619
|
+
return input2;
|
|
620
|
+
}
|
|
621
|
+
function deserializeFromClient(input2) {
|
|
622
|
+
if (isSerializedIriObject(input2)) {
|
|
623
|
+
return deserializeIri(input2);
|
|
624
|
+
}
|
|
625
|
+
if (Array.isArray(input2)) {
|
|
626
|
+
return input2.map((item) => deserializeFromClient(item));
|
|
627
|
+
}
|
|
628
|
+
if (input2 !== null && typeof input2 === "object") {
|
|
629
|
+
const result = {};
|
|
630
|
+
for (const key in input2) {
|
|
631
|
+
result[key] = deserializeFromClient(input2[key]);
|
|
632
|
+
}
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
return input2;
|
|
636
|
+
}
|
|
637
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
638
|
+
0 && (module.exports = {
|
|
639
|
+
AbstractApiRequest,
|
|
640
|
+
InputValidationError,
|
|
641
|
+
OutputValidationError,
|
|
642
|
+
createApiClient,
|
|
643
|
+
deserializeFromClient,
|
|
644
|
+
serializeForClient,
|
|
645
|
+
serializedIriObjectSchema
|
|
646
|
+
});
|