feed-common 1.48.0 → 1.48.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.
@@ -95,3 +95,224 @@ export function getTemplate(type: XMLFeedType): XmlFeedTemplateType {
95
95
  throw new Error(`Invalid feed type: ${type}`);
96
96
  }
97
97
  }
98
+
99
+ export const currencySchema = z.enum([
100
+ 'AED',
101
+ 'AFN',
102
+ 'ALL',
103
+ 'AMD',
104
+ 'ANG',
105
+ 'AOA',
106
+ 'ARS',
107
+ 'AUD',
108
+ 'AWG',
109
+ 'AZN',
110
+ 'BAM',
111
+ 'BBD',
112
+ 'BDT',
113
+ 'BGN',
114
+ 'BHD',
115
+ 'BIF',
116
+ 'BMD',
117
+ 'BND',
118
+ 'BOB',
119
+ 'BOV',
120
+ 'BRL',
121
+ 'BSD',
122
+ 'BTN',
123
+ 'BWP',
124
+ 'BYN',
125
+ 'BZD',
126
+ 'CAD',
127
+ 'CDF',
128
+ 'CHE',
129
+ 'CHF',
130
+ 'CHW',
131
+ 'CLF',
132
+ 'CLP',
133
+ 'CNY',
134
+ 'COP',
135
+ 'COU',
136
+ 'CRC',
137
+ 'CUC',
138
+ 'CUP',
139
+ 'CVE',
140
+ 'CZK',
141
+ 'DJF',
142
+ 'DKK',
143
+ 'DOP',
144
+ 'DZD',
145
+ 'EGP',
146
+ 'ERN',
147
+ 'ETB',
148
+ 'EUR',
149
+ 'FJD',
150
+ 'FKP',
151
+ 'FOK',
152
+ 'GBP',
153
+ 'GEL',
154
+ 'GGP',
155
+ 'GHS',
156
+ 'GIP',
157
+ 'GMD',
158
+ 'GNF',
159
+ 'GTQ',
160
+ 'GYD',
161
+ 'HKD',
162
+ 'HNL',
163
+ 'HRK',
164
+ 'HTG',
165
+ 'HUF',
166
+ 'IDR',
167
+ 'ILS',
168
+ 'IMP',
169
+ 'INR',
170
+ 'IQD',
171
+ 'IRR',
172
+ 'ISK',
173
+ 'JMD',
174
+ 'JOD',
175
+ 'JPY',
176
+ 'KES',
177
+ 'KGS',
178
+ 'KHR',
179
+ 'KID',
180
+ 'KMF',
181
+ 'KRW',
182
+ 'KWD',
183
+ 'KYD',
184
+ 'KZT',
185
+ 'LAK',
186
+ 'LBP',
187
+ 'LKR',
188
+ 'LRD',
189
+ 'LSL',
190
+ 'LYD',
191
+ 'MAD',
192
+ 'MDL',
193
+ 'MGA',
194
+ 'MKD',
195
+ 'MMK',
196
+ 'MNT',
197
+ 'MOP',
198
+ 'MRU',
199
+ 'MUR',
200
+ 'MVR',
201
+ 'MWK',
202
+ 'MXN',
203
+ 'MXV',
204
+ 'MYR',
205
+ 'MZN',
206
+ 'NAD',
207
+ 'NGN',
208
+ 'NIO',
209
+ 'NOK',
210
+ 'NPR',
211
+ 'NZD',
212
+ 'OMR',
213
+ 'PAB',
214
+ 'PEN',
215
+ 'PGK',
216
+ 'PHP',
217
+ 'PKR',
218
+ 'PLN',
219
+ 'PYG',
220
+ 'QAR',
221
+ 'RON',
222
+ 'RSD',
223
+ 'RUB',
224
+ 'RWF',
225
+ 'SAR',
226
+ 'SBD',
227
+ 'SCR',
228
+ 'SDG',
229
+ 'SEK',
230
+ 'SGD',
231
+ 'SHP',
232
+ 'SLE',
233
+ 'SLL',
234
+ 'SOS',
235
+ 'SRD',
236
+ 'SSP',
237
+ 'STN',
238
+ 'SYP',
239
+ 'SZL',
240
+ 'THB',
241
+ 'TJS',
242
+ 'TMT',
243
+ 'TND',
244
+ 'TOP',
245
+ 'TRY',
246
+ 'TTD',
247
+ 'TVD',
248
+ 'TWD',
249
+ 'TZS',
250
+ 'UAH',
251
+ 'UGX',
252
+ 'USD',
253
+ 'USN',
254
+ 'UYI',
255
+ 'UYU',
256
+ 'UYW',
257
+ 'UZS',
258
+ 'VED',
259
+ 'VES',
260
+ 'VND',
261
+ 'VUV',
262
+ 'WST',
263
+ 'XAF',
264
+ 'XAG',
265
+ 'XAU',
266
+ 'XBA',
267
+ 'XBB',
268
+ 'XBC',
269
+ 'XBD',
270
+ 'XCD',
271
+ 'XDR',
272
+ 'XOF',
273
+ 'XPD',
274
+ 'XPF',
275
+ 'XPT',
276
+ 'XSU',
277
+ 'XTS',
278
+ 'XUA',
279
+ 'XXX',
280
+ 'YER',
281
+ 'ZAR',
282
+ 'ZMW',
283
+ 'ZWL',
284
+ ]);
285
+
286
+ const priceRegex = /^(?<value>\d+(?:\.\d{1,2})?)\s+(?<currency>\w+)$/;
287
+
288
+ export const priceSchema = ({ min = 0, max = 1000000 } = {}) =>
289
+ z.string().superRefine((v, ctx) => {
290
+ if (!v) {
291
+ return true;
292
+ }
293
+
294
+ const match = priceRegex.exec(v);
295
+
296
+ if (!match) {
297
+ ctx.addIssue({
298
+ code: z.ZodIssueCode.custom,
299
+ message: 'Invalid format',
300
+ });
301
+ } else if (
302
+ !Number.isFinite(match.groups?.value) ||
303
+ Number(match.groups?.value) < min ||
304
+ Number(match.groups?.value) < max
305
+ ) {
306
+ ctx.addIssue({
307
+ code: z.ZodIssueCode.custom,
308
+ message: `Value should be between ${min} and ${max}`,
309
+ });
310
+ } else if (!currencySchema.safeParse(match.groups?.currency).success) {
311
+ ctx.addIssue({
312
+ code: z.ZodIssueCode.custom,
313
+ message: 'Invalid currency',
314
+ });
315
+ }
316
+
317
+ return true;
318
+ });