@atomic-solutions/schemas 0.1.0 → 0.2.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.
@@ -0,0 +1,591 @@
1
+ import { z } from 'zod';
2
+
3
+ // src/woocommerce-admin/coupons/coupon-filter.schema.ts
4
+
5
+ // src/woocommerce-admin/enums/enums-raw.ts
6
+ var ORDER_STATUS = [
7
+ "cancelled",
8
+ "completed",
9
+ "pending",
10
+ "processing",
11
+ "on-hold",
12
+ "auto-draft",
13
+ "trash",
14
+ "refunded",
15
+ "failed",
16
+ "checkout-draft"
17
+ ];
18
+ var PAYMENT_METHODS = ["cod", "monri", "pikpay", "bacs", "cheque"];
19
+ var PRODUCT_TYPES = ["simple", "grouped", "external", "variable"];
20
+ var PRODUCT_STATUS = [
21
+ "any",
22
+ "future",
23
+ "trash",
24
+ "draft",
25
+ "pending",
26
+ "private",
27
+ "publish"
28
+ ];
29
+ var STOCK_STATUS = ["instock", "outofstock", "onbackorder"];
30
+ var USER_ROLES = [
31
+ "all",
32
+ "administrator",
33
+ "editor",
34
+ "author",
35
+ "contributor",
36
+ "subscriber",
37
+ "customer",
38
+ "shop_manager",
39
+ "dc_pending_vendor",
40
+ "dc_rejected_vendor",
41
+ "dc_vendor",
42
+ "translator"
43
+ ];
44
+ var REVIEW_STATUS = ["all", "hold", "approved", "spam", "trash"];
45
+ var SORT_ORDER = ["asc", "desc"];
46
+ var COUPONS_ORDER_BY = [
47
+ "date",
48
+ "id",
49
+ "include",
50
+ "title",
51
+ "slug",
52
+ "modified"
53
+ ];
54
+ var PRODUCT_SORT_FIELDS = [
55
+ "date",
56
+ "id",
57
+ "include",
58
+ "title",
59
+ "slug",
60
+ "modified",
61
+ "popularity",
62
+ "rating",
63
+ "menu_order",
64
+ "price"
65
+ ];
66
+ var CATEGORY_SORT_FIELDS = [
67
+ "id",
68
+ "include",
69
+ "name",
70
+ "slug",
71
+ "term_group",
72
+ "description",
73
+ "count"
74
+ ];
75
+ var ORDER_SORT_FIELDS = [
76
+ "date",
77
+ "id",
78
+ "include",
79
+ "title",
80
+ "slug",
81
+ "modified"
82
+ ];
83
+ var ERROR_CODES = [
84
+ "registration-error-email-exists",
85
+ "rest_no_route"
86
+ ];
87
+ var CATALOG_VISIBILITY = ["visible", "catalog", "search", "hidden"];
88
+ var CUSTOMER_ROLE = [
89
+ "all",
90
+ "administrator",
91
+ "editor",
92
+ "author",
93
+ "contributor",
94
+ "subscriber",
95
+ "customer",
96
+ "shop_manager"
97
+ ];
98
+ var CUSTOMER_SORT_FIELDS = [
99
+ "id",
100
+ "include",
101
+ "name",
102
+ "registered_date"
103
+ ];
104
+ var PRODUCT_REVIEWS_SORT_FIELDS = [
105
+ "date",
106
+ "date_gmt",
107
+ "id",
108
+ "include",
109
+ "product"
110
+ ];
111
+ var FILTER_CONTEXT = ["view", "edit"];
112
+ var ENUM_RAW = {
113
+ ORDER: {
114
+ STATUS: ORDER_STATUS,
115
+ SORT_FIELDS: ORDER_SORT_FIELDS
116
+ },
117
+ PAYMENT: {
118
+ METHODS: PAYMENT_METHODS
119
+ },
120
+ PRODUCT: {
121
+ TYPES: PRODUCT_TYPES,
122
+ STATUS: PRODUCT_STATUS,
123
+ STOCK_STATUS,
124
+ CATALOG_VISIBILITY,
125
+ SORT_FIELDS: PRODUCT_SORT_FIELDS
126
+ },
127
+ USER: {
128
+ ROLES: USER_ROLES
129
+ },
130
+ REVIEW: {
131
+ STATUS: REVIEW_STATUS,
132
+ SORT_FIELDS: PRODUCT_REVIEWS_SORT_FIELDS
133
+ },
134
+ CATEGORY: {
135
+ SORT_FIELDS: CATEGORY_SORT_FIELDS
136
+ },
137
+ COMMON: {
138
+ SORT_ORDER,
139
+ ERROR_CODES,
140
+ FILTER_CONTEXT
141
+ },
142
+ CUSTOMER: {
143
+ ROLE: CUSTOMER_ROLE,
144
+ SORT_FIELDS: CUSTOMER_SORT_FIELDS
145
+ },
146
+ COUPONS: {
147
+ ORDER_BY: COUPONS_ORDER_BY
148
+ }
149
+ };
150
+
151
+ // src/woocommerce-admin/enums/enums.ts
152
+ var APP_ENUMS = {
153
+ PRODUCT_TYPES: {
154
+ RAW: ENUM_RAW.PRODUCT.TYPES,
155
+ ZOD: z.enum(ENUM_RAW.PRODUCT.TYPES)
156
+ },
157
+ PRODUCT_STATUS: {
158
+ RAW: ENUM_RAW.PRODUCT.STATUS,
159
+ ZOD: z.enum(ENUM_RAW.PRODUCT.STATUS)
160
+ },
161
+ PRODUCT_STOCK_STATUS: {
162
+ RAW: ENUM_RAW.PRODUCT.STOCK_STATUS,
163
+ ZOD: z.enum(ENUM_RAW.PRODUCT.STOCK_STATUS)
164
+ },
165
+ PRODUCT_CATALOG_VISIBILITY: {
166
+ RAW: ENUM_RAW.PRODUCT.CATALOG_VISIBILITY,
167
+ ZOD: z.enum(ENUM_RAW.PRODUCT.CATALOG_VISIBILITY)
168
+ },
169
+ PRODUCT_SORT_FIELDS: {
170
+ RAW: ENUM_RAW.PRODUCT.SORT_FIELDS,
171
+ ZOD: z.enum(ENUM_RAW.PRODUCT.SORT_FIELDS)
172
+ },
173
+ ORDER_STATUS: {
174
+ RAW: ENUM_RAW.ORDER.STATUS,
175
+ ZOD: z.enum(ENUM_RAW.ORDER.STATUS)
176
+ },
177
+ ORDER_SORT_FIELDS: {
178
+ RAW: ENUM_RAW.ORDER.SORT_FIELDS,
179
+ ZOD: z.enum(ENUM_RAW.ORDER.SORT_FIELDS)
180
+ },
181
+ PAYMENT_METHODS: {
182
+ RAW: ENUM_RAW.PAYMENT.METHODS,
183
+ ZOD: z.enum(ENUM_RAW.PAYMENT.METHODS)
184
+ },
185
+ USER_ROLES: {
186
+ RAW: ENUM_RAW.USER.ROLES,
187
+ ZOD: z.enum(ENUM_RAW.USER.ROLES)
188
+ },
189
+ REVIEW_STATUS: {
190
+ RAW: ENUM_RAW.REVIEW.STATUS,
191
+ ZOD: z.enum(ENUM_RAW.REVIEW.STATUS)
192
+ },
193
+ CATEGORY_SORT_FIELDS: {
194
+ RAW: ENUM_RAW.CATEGORY.SORT_FIELDS,
195
+ ZOD: z.enum(ENUM_RAW.CATEGORY.SORT_FIELDS)
196
+ },
197
+ COMMON_SORT_ORDER: {
198
+ RAW: ENUM_RAW.COMMON.SORT_ORDER,
199
+ ZOD: z.enum(ENUM_RAW.COMMON.SORT_ORDER)
200
+ },
201
+ COMMON_ERROR_CODES: {
202
+ RAW: ENUM_RAW.COMMON.ERROR_CODES,
203
+ ZOD: z.enum(ENUM_RAW.COMMON.ERROR_CODES)
204
+ },
205
+ CUSTOMER_ROLE: {
206
+ RAW: ENUM_RAW.CUSTOMER.ROLE,
207
+ ZOD: z.enum(ENUM_RAW.CUSTOMER.ROLE)
208
+ },
209
+ CUSTOMER_SORT_FIELDS: {
210
+ RAW: ENUM_RAW.CUSTOMER.SORT_FIELDS,
211
+ ZOD: z.enum(ENUM_RAW.CUSTOMER.SORT_FIELDS)
212
+ },
213
+ REVIEW_SORT_FIELDS: {
214
+ RAW: ENUM_RAW.REVIEW.SORT_FIELDS,
215
+ ZOD: z.enum(ENUM_RAW.REVIEW.SORT_FIELDS)
216
+ },
217
+ COUPONS_ORDER_BY: {
218
+ RAW: ENUM_RAW.COUPONS.ORDER_BY,
219
+ ZOD: z.enum(ENUM_RAW.COUPONS.ORDER_BY)
220
+ }
221
+ };
222
+ var getAppEnumZod = (key) => APP_ENUMS[key].ZOD;
223
+ var getAppEnumRaw = (key) => APP_ENUMS[key].RAW;
224
+ var basePaginationSchema = z.object({
225
+ page: z.number().positive().default(1),
226
+ per_page: z.number().positive().max(100).default(10),
227
+ offset: z.number().nonnegative().optional()
228
+ });
229
+ var baseFilteringSchema = z.object({
230
+ search: z.string().optional(),
231
+ exclude: z.array(z.number()).default([]),
232
+ include: z.array(z.number()).default([])
233
+ });
234
+ var wpStatusSchema = z.object({
235
+ status: z.enum(["publish", "future", "draft", "pending", "private"]).optional()
236
+ });
237
+ var wpPaginationHeadersSchema = z.object({
238
+ "x-wp-total": z.string().transform(Number),
239
+ "x-wp-totalpages": z.string().transform(Number)
240
+ });
241
+ var wpBaseParamsSchema = z.object({
242
+ ...basePaginationSchema.shape,
243
+ ...baseFilteringSchema.shape,
244
+ context: z.enum(["view", "edit"]).default("view")
245
+ });
246
+ var wpLinksSchema = z.object({
247
+ self: z.array(z.object({ href: z.string() })),
248
+ collection: z.array(z.object({ href: z.string() })),
249
+ about: z.array(z.object({ href: z.string() })).optional(),
250
+ author: z.array(
251
+ z.object({
252
+ embeddable: z.boolean().optional(),
253
+ href: z.string()
254
+ })
255
+ ).optional()
256
+ });
257
+
258
+ // src/woocommerce-admin/base/base-wc.schema.ts
259
+ var wcSortingSchema = z.object({
260
+ order: getAppEnumZod("COMMON_SORT_ORDER").default("desc"),
261
+ orderby: z.string().optional()
262
+ });
263
+ var wcDateFilterSchema = z.object({
264
+ after: z.string().datetime().optional(),
265
+ before: z.string().datetime().optional(),
266
+ modified_after: z.string().datetime().optional(),
267
+ modified_before: z.string().datetime().optional(),
268
+ dates_are_gmt: z.boolean().default(false)
269
+ });
270
+ var wcMetaDataSchema = z.object({
271
+ id: z.number(),
272
+ key: z.string(),
273
+ value: z.any()
274
+ });
275
+ var wcAddressSchema = z.object({
276
+ first_name: z.string().default(""),
277
+ last_name: z.string().default(""),
278
+ company: z.string().default(""),
279
+ address_1: z.string().default(""),
280
+ address_2: z.string().default(""),
281
+ city: z.string().default(""),
282
+ state: z.string().default(""),
283
+ postcode: z.string().default(""),
284
+ country: z.string().default("BA"),
285
+ phone: z.string().default(""),
286
+ email: z.string().email().optional()
287
+ });
288
+ var wcBaseParamsSchema = z.object({
289
+ ...basePaginationSchema.shape,
290
+ ...baseFilteringSchema.shape,
291
+ ...wcSortingSchema.shape
292
+ });
293
+ var wcBaseResponseSchema = z.object({
294
+ _links: wpLinksSchema,
295
+ meta_data: z.array(wcMetaDataSchema).optional()
296
+ });
297
+ var wcPaginationMetaSchema = z.object({
298
+ total: z.number(),
299
+ totalPages: z.number(),
300
+ currentPage: z.number(),
301
+ perPage: z.number()
302
+ });
303
+ var wcErrorResponseSchema = z.object({
304
+ code: getAppEnumZod("COMMON_ERROR_CODES"),
305
+ message: z.string(),
306
+ data: z.object({
307
+ status: z.number()
308
+ }).optional()
309
+ }).passthrough();
310
+ var createPaginatedSchema = (schema) => z.object({
311
+ data: z.array(schema),
312
+ meta: wcPaginationMetaSchema
313
+ });
314
+
315
+ // src/woocommerce-admin/coupons/coupon-filter.schema.ts
316
+ var couponFilterSchema = wcBaseParamsSchema.extend({
317
+ orderby: getAppEnumZod("COUPONS_ORDER_BY").default("date"),
318
+ code: z.string().optional()
319
+ });
320
+ var couponSchema = wcBaseResponseSchema.extend({
321
+ id: z.number(),
322
+ code: z.string(),
323
+ amount: z.string(),
324
+ status: z.string(),
325
+ discount_type: z.enum(["percent", "fixed_cart", "fixed_product"]),
326
+ description: z.string(),
327
+ date_expires: z.string().nullable(),
328
+ usage_count: z.number(),
329
+ individual_use: z.boolean(),
330
+ product_ids: z.array(z.number()),
331
+ excluded_product_ids: z.array(z.number()),
332
+ usage_limit: z.number().nullable(),
333
+ usage_limit_per_user: z.number().nullable(),
334
+ limit_usage_to_x_items: z.number().nullable(),
335
+ free_shipping: z.boolean(),
336
+ product_categories: z.array(z.number()),
337
+ excluded_product_categories: z.array(z.number()),
338
+ exclude_sale_items: z.boolean(),
339
+ minimum_amount: z.string(),
340
+ maximum_amount: z.string(),
341
+ email_restrictions: z.array(z.string())
342
+ });
343
+ var createCouponSchema = couponSchema.omit({
344
+ id: true,
345
+ usage_count: true
346
+ }).extend({
347
+ code: z.string().min(1, "Code is required"),
348
+ amount: z.string().min(1, "Amount is required")
349
+ });
350
+ var customerFilterSchema = wcBaseParamsSchema.extend({
351
+ orderby: getAppEnumZod("CUSTOMER_SORT_FIELDS").default("name"),
352
+ role: getAppEnumZod("CUSTOMER_ROLE").default("customer"),
353
+ email: z.string().email().optional()
354
+ });
355
+ var customerSchema = wcBaseResponseSchema.extend({
356
+ id: z.number(),
357
+ username: z.string(),
358
+ first_name: z.string(),
359
+ last_name: z.string(),
360
+ email: z.string().email(),
361
+ role: getAppEnumZod("CUSTOMER_ROLE"),
362
+ date_created: z.string(),
363
+ date_modified: z.string(),
364
+ is_paying_customer: z.boolean(),
365
+ avatar_url: z.string(),
366
+ billing: wcAddressSchema.extend({
367
+ email: z.string().email()
368
+ }),
369
+ shipping: wcAddressSchema
370
+ });
371
+ var createCustomerSchema = customerSchema.pick({
372
+ email: true,
373
+ first_name: true,
374
+ last_name: true,
375
+ shipping: true
376
+ }).extend({
377
+ loyalty_card_number: z.string().optional()
378
+ });
379
+ var updateCustomerSchema = createCustomerSchema.merge(
380
+ customerSchema.pick({
381
+ billing: true
382
+ })
383
+ ).partial();
384
+ var orderFilterSchema = wcBaseParamsSchema.extend({
385
+ orderby: getAppEnumZod("ORDER_SORT_FIELDS").default("date"),
386
+ status: z.array(getAppEnumZod("ORDER_STATUS")).optional(),
387
+ customer: z.number().optional(),
388
+ product: z.number().optional(),
389
+ dp: z.number().default(2).optional()
390
+ // decimal points
391
+ }).merge(wcDateFilterSchema);
392
+ var orderLineItemSchema = z.object({
393
+ id: z.number(),
394
+ name: z.string(),
395
+ product_id: z.number(),
396
+ variation_id: z.number(),
397
+ quantity: z.number(),
398
+ tax_class: z.string(),
399
+ subtotal: z.string(),
400
+ subtotal_tax: z.string(),
401
+ total: z.string(),
402
+ total_tax: z.string(),
403
+ sku: z.string(),
404
+ price: z.number()
405
+ });
406
+ var orderSchema = wcBaseResponseSchema.extend({
407
+ id: z.number(),
408
+ parent_id: z.number(),
409
+ status: getAppEnumZod("ORDER_STATUS"),
410
+ currency: z.string(),
411
+ version: z.string(),
412
+ prices_include_tax: z.boolean(),
413
+ date_created: z.string(),
414
+ date_modified: z.string(),
415
+ discount_total: z.string(),
416
+ shipping_total: z.string(),
417
+ cart_tax: z.string(),
418
+ total: z.string(),
419
+ customer_id: z.number(),
420
+ order_key: z.string(),
421
+ billing: wcAddressSchema.extend({
422
+ email: z.string().email()
423
+ }),
424
+ shipping: wcAddressSchema,
425
+ payment_method: getAppEnumZod("PAYMENT_METHODS"),
426
+ payment_method_title: z.string(),
427
+ line_items: z.array(orderLineItemSchema),
428
+ // specific fields
429
+ payment_url: z.string().optional(),
430
+ pikpay_transaction_id: z.string().optional(),
431
+ pikpay_status: z.string().optional(),
432
+ monri_transaction_id: z.string().optional(),
433
+ monri_status: z.string().optional()
434
+ });
435
+ var paymentMethodFilterSchema = wcBaseParamsSchema.extend({
436
+ enabled: z.boolean().optional()
437
+ });
438
+ var paymentMethodSchema = wcBaseResponseSchema.extend({
439
+ id: getAppEnumZod("PAYMENT_METHODS"),
440
+ title: z.string(),
441
+ description: z.string(),
442
+ enabled: z.boolean(),
443
+ method_title: z.string(),
444
+ method_description: z.string()
445
+ });
446
+ var categoryFilterSchema = wcBaseParamsSchema.extend({
447
+ orderby: getAppEnumZod("CATEGORY_SORT_FIELDS").default("name"),
448
+ hide_empty: z.boolean().default(false),
449
+ parent: z.number().optional(),
450
+ product: z.number().nullable().default(null),
451
+ slug: z.string().optional()
452
+ });
453
+ var productImageSchema = z.object({
454
+ id: z.number(),
455
+ date_created: z.string(),
456
+ date_modified: z.string(),
457
+ src: z.string(),
458
+ name: z.string(),
459
+ alt: z.string()
460
+ });
461
+ var productSchema = wcBaseResponseSchema.extend({
462
+ id: z.number(),
463
+ name: z.string(),
464
+ slug: z.string(),
465
+ date_created: z.string(),
466
+ date_modified: z.string(),
467
+ type: z.string(),
468
+ status: z.string(),
469
+ featured: z.boolean(),
470
+ catalog_visibility: z.string(),
471
+ description: z.string(),
472
+ short_description: z.string(),
473
+ sku: z.string(),
474
+ price: z.string(),
475
+ regular_price: z.string(),
476
+ sale_price: z.string(),
477
+ stock_status: getAppEnumZod("PRODUCT_STOCK_STATUS"),
478
+ stock_quantity: z.number().nullable(),
479
+ categories: z.array(
480
+ z.object({
481
+ id: z.number(),
482
+ name: z.string(),
483
+ slug: z.string()
484
+ })
485
+ ),
486
+ images: z.array(productImageSchema),
487
+ attributes: z.array(
488
+ z.object({
489
+ id: z.number(),
490
+ name: z.string(),
491
+ position: z.number(),
492
+ visible: z.boolean(),
493
+ variation: z.boolean(),
494
+ options: z.array(z.string())
495
+ })
496
+ ),
497
+ meta_data: z.array(wcMetaDataSchema),
498
+ on_sale: z.boolean(),
499
+ manufacturer: z.string().optional()
500
+ });
501
+
502
+ // src/woocommerce-admin/products/category.schema.ts
503
+ var productCategorySchema = wcBaseResponseSchema.extend({
504
+ id: z.number(),
505
+ name: z.string(),
506
+ slug: z.string(),
507
+ parent: z.number(),
508
+ description: z.string(),
509
+ display: z.string(),
510
+ image: productImageSchema.nullable(),
511
+ menu_order: z.number(),
512
+ count: z.number()
513
+ });
514
+ var productFilterSchema = wcBaseParamsSchema.extend({
515
+ orderby: getAppEnumZod("PRODUCT_SORT_FIELDS").default("date"),
516
+ status: getAppEnumZod("PRODUCT_STATUS").default("any"),
517
+ type: getAppEnumZod("PRODUCT_TYPES").optional(),
518
+ sku: z.string().optional(),
519
+ featured: z.boolean().optional(),
520
+ category: z.string().optional(),
521
+ tag: z.string().optional(),
522
+ shipping_class: z.string().optional(),
523
+ attribute: z.string().optional(),
524
+ attribute_term: z.string().optional(),
525
+ stock_status: getAppEnumZod("PRODUCT_STOCK_STATUS").optional(),
526
+ on_sale: z.boolean().optional(),
527
+ min_price: z.string().optional(),
528
+ max_price: z.string().optional()
529
+ }).merge(wcDateFilterSchema);
530
+ var createCategorySchema = productCategorySchema.omit({
531
+ id: true,
532
+ count: true
533
+ }).extend({
534
+ name: z.string().min(1, "Name is required")
535
+ });
536
+ var loyaltySchemaFull = z.object({
537
+ brojkartice: z.number(),
538
+ ime: z.string(),
539
+ prezime: z.string(),
540
+ datumrodjenja: z.string(),
541
+ pol: z.string(),
542
+ adresastanovanja: z.string(),
543
+ adresazadostavu: z.string(),
544
+ telefon: z.string(),
545
+ mobilni: z.string(),
546
+ email: z.string(),
547
+ namaillisti: z.string(),
548
+ ukupnobodova: z.number()
549
+ });
550
+ var loyaltySchemaRedacted = loyaltySchemaFull.pick({
551
+ brojkartice: true,
552
+ ukupnobodova: true
553
+ });
554
+
555
+ // src/woocommerce-admin/index.ts
556
+ var schemas = {
557
+ resources: {
558
+ product: {
559
+ filter: productFilterSchema,
560
+ entity: productSchema,
561
+ category: {
562
+ filter: categoryFilterSchema,
563
+ entity: productCategorySchema
564
+ }
565
+ },
566
+ order: {
567
+ filter: orderFilterSchema,
568
+ entity: orderSchema,
569
+ lineItem: orderLineItemSchema
570
+ },
571
+ customer: {
572
+ filter: customerFilterSchema,
573
+ entity: customerSchema,
574
+ create: createCustomerSchema,
575
+ update: updateCustomerSchema
576
+ },
577
+ coupon: {
578
+ filter: couponFilterSchema,
579
+ entity: couponSchema,
580
+ create: createCouponSchema
581
+ },
582
+ paymentMethod: {
583
+ filter: paymentMethodFilterSchema,
584
+ entity: paymentMethodSchema
585
+ }
586
+ }
587
+ };
588
+
589
+ export { APP_ENUMS, ENUM_RAW, baseFilteringSchema, basePaginationSchema, categoryFilterSchema, couponFilterSchema, couponSchema, createCategorySchema, createCouponSchema, createCustomerSchema, createPaginatedSchema, customerFilterSchema, customerSchema, getAppEnumRaw, getAppEnumZod, loyaltySchemaFull, loyaltySchemaRedacted, orderFilterSchema, orderLineItemSchema, orderSchema, paymentMethodFilterSchema, paymentMethodSchema, productCategorySchema, productFilterSchema, productImageSchema, productSchema, schemas, updateCustomerSchema, wcAddressSchema, wcBaseParamsSchema, wcBaseResponseSchema, wcDateFilterSchema, wcErrorResponseSchema, wcMetaDataSchema, wcPaginationMetaSchema, wcSortingSchema, wpBaseParamsSchema, wpLinksSchema, wpPaginationHeadersSchema, wpStatusSchema };
590
+ //# sourceMappingURL=index.js.map
591
+ //# sourceMappingURL=index.js.map