@nexload-sdk/payload-fields 3.1.0 → 4.0.0

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.
Files changed (111) hide show
  1. package/README.md +196 -17
  2. package/dist/address/index.d.ts +13 -0
  3. package/dist/address/index.d.ts.map +1 -0
  4. package/dist/admin/formatted-cell.d.ts +6 -0
  5. package/dist/admin/formatted-cell.d.ts.map +1 -0
  6. package/dist/admin/formatted-cell.js +18 -0
  7. package/dist/admin/formatted-cell.js.map +7 -0
  8. package/dist/admin/jalali-date-cell.d.ts +3 -3
  9. package/dist/admin/jalali-date-cell.d.ts.map +1 -1
  10. package/dist/admin/jalali-date-cell.js +27 -0
  11. package/dist/admin/jalali-date-cell.js.map +7 -0
  12. package/dist/admin/jalali-date-field.d.ts +4 -3
  13. package/dist/admin/jalali-date-field.d.ts.map +1 -1
  14. package/dist/admin/jalali-date-field.js +250 -0
  15. package/dist/admin/jalali-date-field.js.map +7 -0
  16. package/dist/admin/money-cell.d.ts +10 -0
  17. package/dist/admin/money-cell.d.ts.map +1 -0
  18. package/dist/admin/money-cell.js +124 -0
  19. package/dist/admin/money-cell.js.map +7 -0
  20. package/dist/admin/money-field.d.ts +3 -2
  21. package/dist/admin/money-field.d.ts.map +1 -1
  22. package/dist/admin/money-field.js +183 -0
  23. package/dist/admin/money-field.js.map +7 -0
  24. package/dist/admin/slug-field.d.ts.map +1 -1
  25. package/dist/admin/slug-field.js +210 -0
  26. package/dist/admin/slug-field.js.map +7 -0
  27. package/dist/admin/validated-text-field.d.ts +6 -0
  28. package/dist/admin/validated-text-field.d.ts.map +1 -0
  29. package/dist/admin/validated-text-field.js +35 -0
  30. package/dist/admin/validated-text-field.js.map +7 -0
  31. package/dist/bank/index.d.ts +7 -0
  32. package/dist/bank/index.d.ts.map +1 -0
  33. package/dist/common/index.d.ts +35 -0
  34. package/dist/common/index.d.ts.map +1 -0
  35. package/dist/contact/index.d.ts +9 -0
  36. package/dist/contact/index.d.ts.map +1 -0
  37. package/dist/date/format-date.d.ts.map +1 -1
  38. package/dist/date/index.d.ts +37 -4
  39. package/dist/date/index.d.ts.map +1 -1
  40. package/dist/date/index.js +258 -0
  41. package/dist/date/index.js.map +7 -0
  42. package/dist/i18n/messages.d.ts +6 -0
  43. package/dist/i18n/messages.d.ts.map +1 -0
  44. package/dist/i18n/messages.js +97 -0
  45. package/dist/i18n/messages.js.map +7 -0
  46. package/dist/identity/index.d.ts +9 -0
  47. package/dist/identity/index.d.ts.map +1 -0
  48. package/dist/index.d.ts +6 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1038 -0
  51. package/dist/index.js.map +7 -0
  52. package/dist/internal/protect.d.ts +7 -0
  53. package/dist/internal/protect.d.ts.map +1 -0
  54. package/dist/internal/validated-text.d.ts +24 -0
  55. package/dist/internal/validated-text.d.ts.map +1 -0
  56. package/dist/internal/validated-text.js +161 -0
  57. package/dist/internal/validated-text.js.map +7 -0
  58. package/dist/money/index.d.ts +6 -0
  59. package/dist/money/index.d.ts.map +1 -1
  60. package/dist/money/index.js +212 -0
  61. package/dist/money/index.js.map +7 -0
  62. package/dist/plugin.d.ts +1 -0
  63. package/dist/plugin.d.ts.map +1 -1
  64. package/dist/schema/index.d.ts +51 -0
  65. package/dist/schema/index.d.ts.map +1 -0
  66. package/dist/schema/index.js +735 -0
  67. package/dist/schema/index.js.map +7 -0
  68. package/dist/slug/format-slug.d.ts +1 -1
  69. package/dist/slug/format-slug.d.ts.map +1 -1
  70. package/dist/slug/index.d.ts +1 -0
  71. package/dist/slug/index.d.ts.map +1 -1
  72. package/dist/slug/{index.mjs → index.js} +47 -43
  73. package/dist/slug/index.js.map +7 -0
  74. package/package.json +64 -27
  75. package/dist/admin/jalali-date-cell.cjs +0 -58
  76. package/dist/admin/jalali-date-cell.cjs.map +0 -7
  77. package/dist/admin/jalali-date-cell.mjs +0 -32
  78. package/dist/admin/jalali-date-cell.mjs.map +0 -7
  79. package/dist/admin/jalali-date-field.cjs +0 -159
  80. package/dist/admin/jalali-date-field.cjs.map +0 -7
  81. package/dist/admin/jalali-date-field.mjs +0 -135
  82. package/dist/admin/jalali-date-field.mjs.map +0 -7
  83. package/dist/admin/jalali-picker-value.cjs +0 -42
  84. package/dist/admin/jalali-picker-value.cjs.map +0 -7
  85. package/dist/admin/jalali-picker-value.d.ts +0 -3
  86. package/dist/admin/jalali-picker-value.d.ts.map +0 -1
  87. package/dist/admin/jalali-picker-value.mjs +0 -18
  88. package/dist/admin/jalali-picker-value.mjs.map +0 -7
  89. package/dist/admin/money-field.cjs +0 -146
  90. package/dist/admin/money-field.cjs.map +0 -7
  91. package/dist/admin/money-field.mjs +0 -122
  92. package/dist/admin/money-field.mjs.map +0 -7
  93. package/dist/admin/slug-field.cjs +0 -135
  94. package/dist/admin/slug-field.cjs.map +0 -7
  95. package/dist/admin/slug-field.mjs +0 -115
  96. package/dist/admin/slug-field.mjs.map +0 -7
  97. package/dist/date/index.cjs +0 -117
  98. package/dist/date/index.cjs.map +0 -7
  99. package/dist/date/index.mjs +0 -86
  100. package/dist/date/index.mjs.map +0 -7
  101. package/dist/index.cjs +0 -469
  102. package/dist/index.cjs.map +0 -7
  103. package/dist/index.mjs +0 -425
  104. package/dist/index.mjs.map +0 -7
  105. package/dist/money/index.cjs +0 -147
  106. package/dist/money/index.cjs.map +0 -7
  107. package/dist/money/index.mjs +0 -117
  108. package/dist/money/index.mjs.map +0 -7
  109. package/dist/slug/index.cjs +0 -183
  110. package/dist/slug/index.cjs.map +0 -7
  111. package/dist/slug/index.mjs.map +0 -7
package/dist/index.mjs DELETED
@@ -1,425 +0,0 @@
1
- // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:56.848Z)
2
-
3
- // src/slug/format-slug.ts
4
- var persianDigits = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
5
- var arabicDigits = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
6
- function normalizeDigits(value) {
7
- return value.replace(
8
- /[۰-۹٠-٩]/g,
9
- (digit) => {
10
- const index = persianDigits.indexOf(digit);
11
- return String(index >= 0 ? index : arabicDigits.indexOf(digit));
12
- }
13
- );
14
- }
15
- function getPath(value, path) {
16
- return path.split(".").reduce(
17
- (current, key) => {
18
- if (current && typeof current === "object") return current[key];
19
- return void 0;
20
- },
21
- value
22
- );
23
- }
24
- function hasPath(value, path) {
25
- return path.split(".").every((key) => {
26
- if (!value || typeof value !== "object" || !(key in value)) return false;
27
- value = value[key];
28
- return true;
29
- });
30
- }
31
- function formatSlug(value) {
32
- return normalizeDigits(value.normalize("NFKC")).replace(
33
- /[يى]/g,
34
- "\u06CC"
35
- ).replace(
36
- /ك/g,
37
- "\u06A9"
38
- ).replace(
39
- /[\u064B-\u065F\u0670]/g,
40
- ""
41
- ).replace(
42
- /[\s_]+/g,
43
- "-"
44
- ).replace(
45
- /[^\p{L}\p{N}-]+/gu,
46
- ""
47
- ).replace(
48
- /-+/g,
49
- "-"
50
- ).replace(
51
- /^-+|-+$/g,
52
- ""
53
- );
54
- }
55
- var formatSlugHook = (options) => ({
56
- data,
57
- operation,
58
- originalDoc,
59
- siblingData,
60
- previousSiblingDoc,
61
- value
62
- }) => {
63
- const lock = siblingData?.[options.lockName] ?? data?.[options.lockName];
64
- const previousSlug = previousSiblingDoc?.[options.name] ?? originalDoc?.[options.name];
65
- const sourceChanged = hasPath(
66
- data,
67
- options.source
68
- ) && getPath(
69
- data,
70
- options.source
71
- ) !== getPath(
72
- originalDoc,
73
- options.source
74
- );
75
- const source = hasPath(
76
- data,
77
- options.source
78
- ) ? getPath(
79
- data,
80
- options.source
81
- ) : getPath(
82
- originalDoc,
83
- options.source
84
- );
85
- if (lock !== false && typeof source === "string" && source.trim() && (operation === "create" || options.regenerateOnSourceChange && sourceChanged)) {
86
- return formatSlug(source);
87
- }
88
- if (operation === "update" && lock !== false && sourceChanged && !source && previousSlug !== void 0) {
89
- return previousSlug;
90
- }
91
- if (lock !== false && operation === "update" && previousSlug !== void 0) return previousSlug;
92
- if (typeof value === "string") return formatSlug(value);
93
- return value;
94
- };
95
-
96
- // src/slug/index.ts
97
- function slugField(options = {}) {
98
- const name = options.name ?? "slug";
99
- const lockName = options.lockName ?? `${name}Lock`;
100
- const source = options.source ?? "title";
101
- const localized = options.overrides?.slug?.localized === true;
102
- if (options.overrides?.slug?.name && options.overrides.slug.name !== name) throw new Error("Slug field name is protected.");
103
- if (options.overrides?.lock?.name && options.overrides.lock.name !== lockName) throw new Error("Slug lock name is protected.");
104
- if (options.overrides?.lock?.localized !== void 0 && options.overrides.lock.localized !== localized) throw new Error("Slug lock localization must match slug localization.");
105
- if (options.overrides?.slug?.type && options.overrides.slug.type !== "text") throw new Error("Slug field type is protected.");
106
- if (options.overrides?.lock?.type && options.overrides.lock.type !== "checkbox") throw new Error("Slug lock type is protected.");
107
- const slugOverrides = options.overrides?.slug ?? {};
108
- const lockOverrides = options.overrides?.lock ?? {};
109
- const consumerHooks = slugOverrides.hooks?.beforeValidate ?? [];
110
- const slug = {
111
- ...slugOverrides,
112
- name,
113
- type: "text",
114
- index: slugOverrides.index ?? true,
115
- localized,
116
- admin: {
117
- ...slugOverrides.admin,
118
- position: slugOverrides.admin?.position ?? "sidebar",
119
- components: {
120
- ...slugOverrides.admin?.components,
121
- Field: {
122
- path: "@nexload-sdk/payload-fields/admin/slug-field#SlugFieldComponent",
123
- clientProps: { source, lockName, generator: options.generator }
124
- }
125
- }
126
- },
127
- custom: { ...slugOverrides.custom, nexload: { ...slugOverrides.custom?.nexload, slug: { source, lockName, generator: options.generator } } },
128
- hooks: {
129
- ...slugOverrides.hooks,
130
- beforeValidate: [
131
- ...consumerHooks,
132
- formatSlugHook({ name, lockName, source, regenerateOnSourceChange: options.regenerateOnSourceChange ?? true })
133
- ]
134
- }
135
- };
136
- const lock = {
137
- ...lockOverrides,
138
- name: lockName,
139
- type: "checkbox",
140
- localized,
141
- defaultValue: true,
142
- admin: { ...lockOverrides.admin, hidden: true, position: lockOverrides.admin?.position ?? "sidebar" }
143
- };
144
- return [
145
- slug,
146
- lock
147
- ];
148
- }
149
-
150
- // src/date/format-date.ts
151
- function formatJalaliDate(value, options = {}) {
152
- if (value === null || value === void 0) return null;
153
- const date = value instanceof Date ? value : new Date(value);
154
- if (Number.isNaN(date.getTime())) return null;
155
- const locale = options.digits === "latin" ? "fa-IR-u-ca-persian-nu-latn" : "fa-IR-u-ca-persian";
156
- return new Intl.DateTimeFormat(
157
- locale,
158
- {
159
- dateStyle: options.dateStyle ?? "medium",
160
- ...options.timeStyle ? { timeStyle: options.timeStyle } : {},
161
- ...options.timeZone ? { timeZone: options.timeZone } : {}
162
- }
163
- ).format(date);
164
- }
165
-
166
- // src/date/index.ts
167
- function jalaliDateField(options) {
168
- const overrides = options.overrides ?? {};
169
- if (overrides.name && overrides.name !== options.name) throw new Error("Jalali date field name is protected.");
170
- if (overrides.type && overrides.type !== "date") throw new Error("Jalali date field type is protected.");
171
- const appearance = options.pickerAppearance ?? "dayOnly";
172
- const display = {
173
- digits: "persian",
174
- dateStyle: "medium",
175
- ...appearance === "dayAndTime" || appearance === "timeOnly" ? { timeStyle: "short" } : {},
176
- ...options.display
177
- };
178
- return {
179
- ...overrides,
180
- name: options.name,
181
- type: "date",
182
- admin: {
183
- ...overrides.admin,
184
- date: { ...overrides.admin?.date, pickerAppearance: appearance },
185
- components: {
186
- ...overrides.admin?.components,
187
- Field: { path: "@nexload-sdk/payload-fields/admin/jalali-date-field#JalaliDateFieldComponent", clientProps: { appearance, display } },
188
- Cell: { path: "@nexload-sdk/payload-fields/admin/jalali-date-cell#JalaliDateCell", clientProps: { display } }
189
- }
190
- },
191
- custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, jalaliDate: { appearance, display } } }
192
- };
193
- }
194
- function withJalaliTimestamps(fields, options = {}) {
195
- const output = [...fields];
196
- const add = (name, source, override) => {
197
- if (output.some((field) => "name" in field && field.name === name)) throw new Error(`Duplicate Jalali timestamp field: ${name}`);
198
- output.push({
199
- ...override,
200
- name,
201
- type: "text",
202
- virtual: true,
203
- admin: { ...override?.admin, readOnly: true },
204
- hooks: {
205
- ...override?.hooks,
206
- afterRead: [
207
- ...override?.hooks?.afterRead ?? [],
208
- ({ siblingData }) => formatJalaliDate(
209
- siblingData?.[source],
210
- options.display
211
- )
212
- ]
213
- }
214
- });
215
- };
216
- if (options.createdAt !== false) add(
217
- "createdAtJalali",
218
- "createdAt",
219
- options.overrides?.createdAt
220
- );
221
- if (options.updatedAt !== false) add(
222
- "updatedAtJalali",
223
- "updatedAt",
224
- options.overrides?.updatedAt
225
- );
226
- return output;
227
- }
228
-
229
- // src/money/index.ts
230
- var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
231
- var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
232
- function resolveCurrency(currency) {
233
- const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
234
- if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
235
- return result;
236
- }
237
- function normalizedNumber(value) {
238
- const persian = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
239
- const arabic = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
240
- return value.trim().replace(
241
- /[۰-۹٠-٩]/g,
242
- (digit) => String(Math.max(
243
- persian.indexOf(digit),
244
- arabic.indexOf(digit)
245
- ) % 10)
246
- ).replace(
247
- /[٬,\s]/g,
248
- ""
249
- ).replace(
250
- /٫/g,
251
- "."
252
- );
253
- }
254
- function parseMoneyToMinorUnits(input, currency) {
255
- const definition = resolveCurrency(currency);
256
- const value = normalizedNumber(input);
257
- if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
258
- const negative = value.startsWith("-");
259
- const [
260
- whole,
261
- fraction = ""
262
- ] = (negative ? value.slice(1) : value).split(".");
263
- if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
264
- const digits = `${whole}${fraction.padEnd(
265
- definition.fractionDigits,
266
- "0"
267
- )}`.replace(
268
- /^0+(?=\d)/,
269
- ""
270
- ) || "0";
271
- const minor = Number(`${negative ? "-" : ""}${digits}`);
272
- if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
273
- return minor;
274
- }
275
- function formatMoney(value, currency, display = {}) {
276
- if (value === null || value === void 0) return null;
277
- if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
278
- const definition = resolveCurrency(currency);
279
- const locale = display.locale ?? (display.digits === "latin" ? "fa-IR-u-nu-latn" : "fa-IR");
280
- const major = value / 10 ** definition.fractionDigits;
281
- const formatted = new Intl.NumberFormat(
282
- locale,
283
- { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }
284
- ).format(major);
285
- return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
286
- }
287
- function moneyField(options) {
288
- const overrides = options.overrides ?? {};
289
- if (overrides.name && overrides.name !== options.name) throw new Error("Money field name is protected.");
290
- if (overrides.type && overrides.type !== "number") throw new Error("Money field type is protected.");
291
- const currency = resolveCurrency(options.currency);
292
- if (options.minMinorUnits !== void 0 && (!Number.isSafeInteger(options.minMinorUnits) || options.maxMinorUnits !== void 0 && options.minMinorUnits > options.maxMinorUnits)) throw new Error("Invalid money bounds.");
293
- if (options.maxMinorUnits !== void 0 && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error("Invalid money bounds.");
294
- const consumerValidate = overrides.validate;
295
- const validate = (value, args) => {
296
- if (value === null || value === void 0 || value === "") return args?.required ? "\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A." : true;
297
- if (typeof value !== "number" || !Number.isSafeInteger(value)) return "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u06CC\u06A9 \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F.";
298
- if (!options.allowNegative && value < 0) return "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.";
299
- if (options.minMinorUnits !== void 0 && value < options.minMinorUnits) return "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
300
- if (options.maxMinorUnits !== void 0 && value > options.maxMinorUnits) return "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
301
- return consumerValidate ? consumerValidate(
302
- value,
303
- args
304
- ) : true;
305
- };
306
- const display = {
307
- locale: "fa-IR",
308
- digits: "persian",
309
- grouping: true,
310
- showCurrency: true,
311
- ...options.display
312
- };
313
- return {
314
- ...overrides,
315
- name: options.name,
316
- type: "number",
317
- validate,
318
- admin: {
319
- ...overrides.admin,
320
- components: {
321
- ...overrides.admin?.components,
322
- Field: {
323
- path: "@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent",
324
- clientProps: {
325
- currency,
326
- display,
327
- allowNegative: options.allowNegative ?? false
328
- }
329
- }
330
- }
331
- },
332
- custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, money: currency } }
333
- };
334
- }
335
-
336
- // src/plugin.ts
337
- function failure(code, message, status) {
338
- return Response.json(
339
- { error: { code, message } },
340
- { status }
341
- );
342
- }
343
- function payloadFieldsPlugin(options = {}) {
344
- return (config) => ({
345
- ...config,
346
- endpoints: [
347
- ...config.endpoints ?? [],
348
- {
349
- path: "/payload-fields/generate-slug",
350
- method: "post",
351
- handler: async (req) => {
352
- if (!req.user) return failure(
353
- "PAYLOAD_FIELDS_UNAUTHENTICATED",
354
- "\u0628\u0631\u0627\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627\u06CC\u062F \u0648\u0627\u0631\u062F \u0634\u0648\u06CC\u062F.",
355
- 401
356
- );
357
- if (options.generateSlugAccess && !await options.generateSlugAccess({ req })) return failure(
358
- "PAYLOAD_FIELDS_FORBIDDEN",
359
- "\u0627\u062C\u0627\u0632\u0647 \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0631\u0627 \u0646\u062F\u0627\u0631\u06CC\u062F.",
360
- 403
361
- );
362
- let body;
363
- try {
364
- body = await req.json?.();
365
- } catch {
366
- return failure(
367
- "PAYLOAD_FIELDS_INVALID_INPUT",
368
- "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
369
- 400
370
- );
371
- }
372
- if (!body || typeof body !== "object" || Array.isArray(body)) return failure(
373
- "PAYLOAD_FIELDS_INVALID_INPUT",
374
- "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
375
- 400
376
- );
377
- const input = body;
378
- if (typeof input.generator !== "string" || typeof input.sourceValue !== "string" || input.currentSlug !== void 0 && typeof input.currentSlug !== "string") return failure(
379
- "PAYLOAD_FIELDS_INVALID_INPUT",
380
- "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
381
- 400
382
- );
383
- const generator = options.slugGenerators && Object.prototype.hasOwnProperty.call(
384
- options.slugGenerators,
385
- input.generator
386
- ) ? options.slugGenerators[input.generator] : void 0;
387
- if (!generator) return failure(
388
- "PAYLOAD_FIELDS_GENERATOR_NOT_FOUND",
389
- "\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.",
390
- 404
391
- );
392
- try {
393
- const result = await generator(
394
- { sourceValue: input.sourceValue, currentSlug: input.currentSlug },
395
- { req }
396
- );
397
- return Response.json({ slug: formatSlug(result) });
398
- } catch {
399
- return failure(
400
- "PAYLOAD_FIELDS_GENERATION_FAILED",
401
- "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.",
402
- 500
403
- );
404
- }
405
- }
406
- }
407
- ]
408
- });
409
- }
410
- export {
411
- IRR,
412
- IRT,
413
- formatJalaliDate,
414
- formatMoney,
415
- formatSlug,
416
- formatSlugHook,
417
- jalaliDateField,
418
- moneyField,
419
- parseMoneyToMinorUnits,
420
- payloadFieldsPlugin,
421
- resolveCurrency,
422
- slugField,
423
- withJalaliTimestamps
424
- };
425
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/slug/format-slug.ts", "../src/slug/index.ts", "../src/date/format-date.ts", "../src/date/index.ts", "../src/money/index.ts", "../src/plugin.ts"],
4
- "sourcesContent": ["import type { FieldHook } from \"payload\";\n\nexport type SlugHookOptions = {\n name: string\n lockName: string\n source: string\n regenerateOnSourceChange: boolean\n};\n\nconst persianDigits = \"\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9\";\nconst arabicDigits = \"\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669\";\n\nfunction normalizeDigits (value: string): string {\n return value.replace(\n /[\u06F0-\u06F9\u0660-\u0669]/g, (digit) => {\n const index = persianDigits.indexOf(digit);\n return String(index >= 0 ? index : arabicDigits.indexOf(digit));\n }\n );\n}\n\nfunction getPath (\n value: unknown, path: string\n): unknown {\n return path.split(\".\").reduce<unknown>(\n (\n current, key\n ) => {\n if (current && typeof current === \"object\") return (current as Record<string, unknown>)[key];\n return undefined;\n }, value\n );\n}\n\nfunction hasPath (\n value: unknown, path: string\n): boolean {\n return path.split(\".\").every((key) => {\n if (!value || typeof value !== \"object\" || !(key in value)) return false;\n value = (value as Record<string, unknown>)[key];\n return true;\n });\n}\n\nexport function formatSlug (value: string): string {\n return normalizeDigits(value.normalize(\"NFKC\"))\n .replace(\n /[\u064A\u0649]/g, \"\u06CC\"\n )\n .replace(\n /\u0643/g, \"\u06A9\"\n )\n .replace(\n /[\\u064B-\\u065F\\u0670]/g, \"\"\n )\n .replace(\n /[\\s_]+/g, \"-\"\n )\n .replace(\n /[^\\p{L}\\p{N}-]+/gu, \"\"\n )\n .replace(\n /-+/g, \"-\"\n )\n .replace(\n /^-+|-+$/g, \"\"\n );\n}\n\nexport const formatSlugHook = (options: SlugHookOptions): FieldHook => ({\n data,\n operation,\n originalDoc,\n siblingData,\n previousSiblingDoc,\n value,\n}) => {\n const lock = siblingData?.[options.lockName] ?? data?.[options.lockName];\n const previousSlug = previousSiblingDoc?.[options.name] ?? originalDoc?.[options.name];\n const sourceChanged = hasPath(\n data, options.source\n )\n && getPath(\n data, options.source\n ) !== getPath(\n originalDoc, options.source\n );\n const source = hasPath(\n data, options.source\n )\n ? getPath(\n data, options.source\n )\n : getPath(\n originalDoc, options.source\n );\n\n if (lock !== false && typeof source === \"string\" && source.trim() && (operation === \"create\" || (options.regenerateOnSourceChange && sourceChanged))) {\n return formatSlug(source);\n }\n\n if (operation === \"update\" && lock !== false && sourceChanged && !source && previousSlug !== undefined) {\n return previousSlug;\n }\n\n if (lock !== false && operation === \"update\" && previousSlug !== undefined) return previousSlug;\n if (typeof value === \"string\") return formatSlug(value);\n return value;\n};\n", "import { formatSlugHook } from \"./format-slug\";\n\nimport type { CheckboxField, TextField } from \"payload\";\n\nexport type SlugFieldOptions = {\n name?: string\n lockName?: string\n source?: string\n generator?: string\n regenerateOnSourceChange?: boolean\n overrides?: { slug?: Partial<TextField>, lock?: Partial<CheckboxField> }\n};\n\nexport type SlugFieldResult = readonly [TextField, CheckboxField];\n\nexport function slugField (options: SlugFieldOptions = {}): SlugFieldResult {\n const name = options.name ?? \"slug\";\n const lockName = options.lockName ?? `${name}Lock`;\n const source = options.source ?? \"title\";\n const localized = options.overrides?.slug?.localized === true;\n if (options.overrides?.slug?.name && options.overrides.slug.name !== name) throw new Error(\"Slug field name is protected.\");\n if (options.overrides?.lock?.name && options.overrides.lock.name !== lockName) throw new Error(\"Slug lock name is protected.\");\n if (options.overrides?.lock?.localized !== undefined && options.overrides.lock.localized !== localized) throw new Error(\"Slug lock localization must match slug localization.\");\n if (options.overrides?.slug?.type && options.overrides.slug.type !== \"text\") throw new Error(\"Slug field type is protected.\");\n if (options.overrides?.lock?.type && options.overrides.lock.type !== \"checkbox\") throw new Error(\"Slug lock type is protected.\");\n\n const slugOverrides = options.overrides?.slug ?? {};\n const lockOverrides = options.overrides?.lock ?? {};\n const consumerHooks = slugOverrides.hooks?.beforeValidate ?? [];\n const slug: TextField = {\n ...slugOverrides,\n name,\n type: \"text\",\n index: slugOverrides.index ?? true,\n localized,\n admin: {\n ...slugOverrides.admin,\n position: slugOverrides.admin?.position ?? \"sidebar\",\n components: {\n ...slugOverrides.admin?.components,\n Field: {\n path: \"@nexload-sdk/payload-fields/admin/slug-field#SlugFieldComponent\",\n clientProps: { source, lockName, generator: options.generator, },\n },\n },\n },\n custom: { ...slugOverrides.custom, nexload: { ...(slugOverrides.custom?.nexload as object), slug: { source, lockName, generator: options.generator, }, }, },\n hooks: {\n ...slugOverrides.hooks, beforeValidate: [\n ...consumerHooks,\n formatSlugHook({ name, lockName, source, regenerateOnSourceChange: options.regenerateOnSourceChange ?? true, })\n ],\n },\n } as TextField;\n const lock: CheckboxField = {\n ...lockOverrides,\n name: lockName,\n type: \"checkbox\",\n localized,\n defaultValue: true,\n admin: { ...lockOverrides.admin, hidden: true, position: lockOverrides.admin?.position ?? \"sidebar\", },\n } as CheckboxField;\n return [\n slug,\n lock\n ];\n}\n\nexport * from \"./format-slug\";\n", "export type JalaliDateValue = Date | string | number | null | undefined;\nexport type JalaliDateDisplayOptions = {\n dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\"\n timeStyle?: \"short\" | \"medium\"\n digits?: \"persian\" | \"latin\"\n timeZone?: string\n};\n\nexport function formatJalaliDate (\n value: JalaliDateValue, options: JalaliDateDisplayOptions = {}\n): string | null {\n if (value === null || value === undefined) return null;\n const date = value instanceof Date ? value : new Date(value);\n if (Number.isNaN(date.getTime())) return null;\n const locale = options.digits === \"latin\" ? \"fa-IR-u-ca-persian-nu-latn\" : \"fa-IR-u-ca-persian\";\n return new Intl.DateTimeFormat(\n locale, {\n dateStyle: options.dateStyle ?? \"medium\",\n ...(options.timeStyle ? { timeStyle: options.timeStyle, } : {}),\n ...(options.timeZone ? { timeZone: options.timeZone, } : {}),\n }\n ).format(date);\n}\n", "import { formatJalaliDate } from \"./format-date\";\n\nimport type { JalaliPickerAppearance } from \"./picker-types\";\nimport type { DateField, Field, TextField } from \"payload\";\n\nexport type { JalaliDateDisplayOptions, JalaliDateValue } from \"./format-date\";\nexport type { JalaliPickerAppearance } from \"./picker-types\";\nexport type JalaliDateFieldOptions = {\n name: string\n pickerAppearance?: JalaliPickerAppearance\n display?: import(\"./format-date\").JalaliDateDisplayOptions\n overrides?: Partial<DateField>\n};\nexport type JalaliTimestampsOptions = {\n createdAt?: boolean\n updatedAt?: boolean\n display?: import(\"./format-date\").JalaliDateDisplayOptions\n overrides?: { createdAt?: Partial<TextField>, updatedAt?: Partial<TextField> }\n};\n\nexport function jalaliDateField (options: JalaliDateFieldOptions): DateField {\n const overrides = options.overrides ?? {};\n if (overrides.name && overrides.name !== options.name) throw new Error(\"Jalali date field name is protected.\");\n if (overrides.type && overrides.type !== \"date\") throw new Error(\"Jalali date field type is protected.\");\n const appearance = options.pickerAppearance ?? \"dayOnly\";\n const display = {\n digits: \"persian\" as const,\n dateStyle: \"medium\" as const,\n ...(\n appearance === \"dayAndTime\" || appearance === \"timeOnly\"\n ? { timeStyle: \"short\" as const, }\n : {}\n ),\n ...options.display,\n };\n return {\n ...overrides,\n name: options.name,\n type: \"date\",\n admin: {\n ...overrides.admin,\n date: { ...overrides.admin?.date, pickerAppearance: appearance, },\n components: {\n ...overrides.admin?.components,\n Field: { path: \"@nexload-sdk/payload-fields/admin/jalali-date-field#JalaliDateFieldComponent\", clientProps: { appearance, display, }, },\n Cell: { path: \"@nexload-sdk/payload-fields/admin/jalali-date-cell#JalaliDateCell\", clientProps: { display, }, },\n },\n },\n custom: { ...overrides.custom, nexload: { ...(overrides.custom?.nexload as object), jalaliDate: { appearance, display, }, }, },\n } as DateField;\n}\n\nexport function withJalaliTimestamps<T extends Field[]> (\n fields: T, options: JalaliTimestampsOptions = {}\n): Field[] {\n const output = [...fields];\n const add = (\n name: \"createdAtJalali\" | \"updatedAtJalali\", source: \"createdAt\" | \"updatedAt\", override?: Partial<TextField>\n ) => {\n if (output.some((field) => \"name\" in field && field.name === name)) throw new Error(`Duplicate Jalali timestamp field: ${name}`);\n output.push({\n ...override,\n name,\n type: \"text\",\n virtual: true,\n admin: { ...override?.admin, readOnly: true, },\n hooks: {\n ...override?.hooks, afterRead: [\n ...(override?.hooks?.afterRead ?? []),\n ({ siblingData, }) => formatJalaliDate(\n siblingData?.[source] as import(\"./format-date\").JalaliDateValue, options.display\n )\n ],\n },\n } as TextField);\n };\n if (options.createdAt !== false) add(\n \"createdAtJalali\", \"createdAt\", options.overrides?.createdAt\n );\n if (options.updatedAt !== false) add(\n \"updatedAtJalali\", \"updatedAt\", options.overrides?.updatedAt\n );\n return output;\n}\n\nexport { formatJalaliDate };\n", "import type { NumberField } from \"payload\";\n\nexport type MoneyCurrencyDefinition = {\n code: string\n label: string\n fractionDigits: number\n};\nexport type MoneyCurrency = \"IRR\" | \"IRT\" | MoneyCurrencyDefinition;\nexport type MoneyDisplayOptions = {\n locale?: string\n digits?: \"persian\" | \"latin\"\n grouping?: boolean\n showCurrency?: boolean\n};\nexport type MoneyFieldOptions = {\n name: string\n currency: MoneyCurrency\n minMinorUnits?: number\n maxMinorUnits?: number\n allowNegative?: boolean\n display?: MoneyDisplayOptions\n overrides?: Partial<NumberField>\n};\n\nexport const IRR: Readonly<MoneyCurrencyDefinition> = { code: \"IRR\", label: \"\u0631\u06CC\u0627\u0644\", fractionDigits: 0, };\nexport const IRT: Readonly<MoneyCurrencyDefinition> = { code: \"IRT\", label: \"\u062A\u0648\u0645\u0627\u0646\", fractionDigits: 0, };\n\nexport function resolveCurrency (currency: MoneyCurrency): MoneyCurrencyDefinition {\n const result = currency === \"IRR\" ? IRR : currency === \"IRT\" ? IRT : currency;\n if (\n !result.code.trim()\n || !result.label.trim()\n || !Number.isInteger(result.fractionDigits)\n || result.fractionDigits < 0\n || result.fractionDigits > 20\n ) throw new Error(\"Invalid money currency definition.\");\n return result;\n}\n\nfunction normalizedNumber (value: string): string {\n const persian = \"\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9\";\n const arabic = \"\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669\";\n return value.trim().replace(\n /[\u06F0-\u06F9\u0660-\u0669]/g, (digit) => String(Math.max(\n persian.indexOf(digit), arabic.indexOf(digit)\n ) % 10)\n )\n .replace(\n /[\u066C,\\s]/g, \"\"\n )\n .replace(\n /\u066B/g, \".\"\n );\n}\n\nexport function parseMoneyToMinorUnits (\n input: string, currency: MoneyCurrency\n): number {\n const definition = resolveCurrency(currency);\n const value = normalizedNumber(input);\n if (!(/^-?\\d+(?:\\.\\d+)?$/).test(value)) throw new TypeError(\"Invalid money input.\");\n const negative = value.startsWith(\"-\");\n const [\n whole,\n fraction = \"\"\n ] = (negative ? value.slice(1) : value).split(\".\");\n if (fraction.length > definition.fractionDigits) throw new RangeError(\"Money input has unsupported precision.\");\n const digits = `${whole}${fraction.padEnd(\n definition.fractionDigits, \"0\"\n )}`.replace(\n /^0+(?=\\d)/, \"\"\n ) || \"0\";\n const minor = Number(`${negative ? \"-\" : \"\"}${digits}`);\n if (!Number.isSafeInteger(minor)) throw new RangeError(\"Money value is outside the safe integer range.\");\n return minor;\n}\n\nexport function formatMoney (\n value: number | null | undefined,\n currency: MoneyCurrency,\n display: MoneyDisplayOptions = {}\n): string | null {\n if (value === null || value === undefined) return null;\n if (!Number.isSafeInteger(value)) throw new RangeError(\"Money value is outside the safe integer range.\");\n const definition = resolveCurrency(currency);\n const locale = display.locale ?? (display.digits === \"latin\" ? \"fa-IR-u-nu-latn\" : \"fa-IR\");\n const major = value / 10 ** definition.fractionDigits;\n const formatted = new Intl.NumberFormat(\n locale, { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits, }\n ).format(major);\n return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;\n}\n\nexport function moneyField (options: MoneyFieldOptions): NumberField {\n const overrides = options.overrides ?? {};\n if (overrides.name && overrides.name !== options.name) throw new Error(\"Money field name is protected.\");\n if (overrides.type && overrides.type !== \"number\") throw new Error(\"Money field type is protected.\");\n const currency = resolveCurrency(options.currency);\n if (\n options.minMinorUnits !== undefined\n && (\n !Number.isSafeInteger(options.minMinorUnits)\n || (\n options.maxMinorUnits !== undefined\n && options.minMinorUnits > options.maxMinorUnits\n )\n )\n ) throw new Error(\"Invalid money bounds.\");\n if (options.maxMinorUnits !== undefined && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error(\"Invalid money bounds.\");\n const consumerValidate = overrides.validate;\n const validate: NumberField[\"validate\"] = (\n value: unknown, args: { required?: boolean } | undefined\n ) => {\n if (value === null || value === undefined || value === \"\") return args?.required ? \"\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.\" : true;\n if (typeof value !== \"number\" || !Number.isSafeInteger(value)) return \"\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u06CC\u06A9 \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F.\";\n if (!options.allowNegative && value < 0) return \"\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.\";\n if (options.minMinorUnits !== undefined && value < options.minMinorUnits) return \"\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n if (options.maxMinorUnits !== undefined && value > options.maxMinorUnits) return \"\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.\";\n return consumerValidate\n ? (consumerValidate as (value: number, args: unknown) => string | true)(\n value, args\n )\n : true;\n };\n const display = {\n locale: \"fa-IR\", digits: \"persian\" as const, grouping: true, showCurrency: true, ...options.display,\n };\n return {\n ...overrides,\n name: options.name,\n type: \"number\",\n validate,\n admin: {\n ...overrides.admin,\n components: {\n ...overrides.admin?.components,\n Field: {\n path: \"@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent\",\n clientProps: {\n currency,\n display,\n allowNegative: options.allowNegative ?? false,\n },\n },\n },\n },\n custom: { ...overrides.custom, nexload: { ...(overrides.custom?.nexload as object), money: currency, }, },\n } as NumberField;\n}\n", "import { formatSlug } from \"./slug/format-slug\";\n\nimport type { PayloadRequest, Plugin } from \"payload\";\n\nexport type SlugGeneratorInput = { sourceValue: string, currentSlug?: string };\nexport type SlugGeneratorContext = { req: PayloadRequest };\nexport type SlugGenerator = (input: SlugGeneratorInput, context: SlugGeneratorContext) => Promise<string>;\nexport type SlugGenerationAccess = (context: SlugGeneratorContext) => boolean | Promise<boolean>;\nexport type PayloadFieldsPluginOptions = { slugGenerators?: Record<string, SlugGenerator>, generateSlugAccess?: SlugGenerationAccess };\n\nfunction failure (\n code: string, message: string, status: number\n): Response {\n return Response.json(\n { error: { code, message, }, }, { status, }\n );\n}\n\nexport function payloadFieldsPlugin (options: PayloadFieldsPluginOptions = {}): Plugin {\n return (config) => ({\n ...config,\n endpoints: [\n ...(config.endpoints ?? []),\n {\n path: \"/payload-fields/generate-slug\",\n method: \"post\" as const,\n handler: async (req: PayloadRequest) => {\n if (!req.user) return failure(\n \"PAYLOAD_FIELDS_UNAUTHENTICATED\", \"\u0628\u0631\u0627\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627\u06CC\u062F \u0648\u0627\u0631\u062F \u0634\u0648\u06CC\u062F.\", 401\n );\n if (options.generateSlugAccess && !await options.generateSlugAccess({ req, })) return failure(\n \"PAYLOAD_FIELDS_FORBIDDEN\", \"\u0627\u062C\u0627\u0632\u0647 \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0631\u0627 \u0646\u062F\u0627\u0631\u06CC\u062F.\", 403\n );\n let body: unknown;\n try {\n body = await req.json?.();\n } catch {\n return failure(\n \"PAYLOAD_FIELDS_INVALID_INPUT\", \"\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.\", 400\n );\n }\n if (!body || typeof body !== \"object\" || Array.isArray(body)) return failure(\n \"PAYLOAD_FIELDS_INVALID_INPUT\", \"\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.\", 400\n );\n const input = body as {\n generator?: unknown\n sourceValue?: unknown\n currentSlug?: unknown\n };\n if (\n typeof input.generator !== \"string\"\n || typeof input.sourceValue !== \"string\"\n || (input.currentSlug !== undefined && typeof input.currentSlug !== \"string\")\n ) return failure(\n \"PAYLOAD_FIELDS_INVALID_INPUT\", \"\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.\", 400\n );\n const generator = options.slugGenerators && Object.prototype.hasOwnProperty.call(\n options.slugGenerators, input.generator\n )\n ? options.slugGenerators[input.generator]\n : undefined;\n if (!generator) return failure(\n \"PAYLOAD_FIELDS_GENERATOR_NOT_FOUND\", \"\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.\", 404\n );\n try {\n const result = await generator(\n { sourceValue: input.sourceValue, currentSlug: input.currentSlug, }, { req, }\n );\n return Response.json({ slug: formatSlug(result), });\n } catch {\n return failure(\n \"PAYLOAD_FIELDS_GENERATION_FAILED\", \"\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.\", 500\n );\n }\n },\n }\n ],\n });\n}\n"],
5
- "mappings": ";;;AASA,IAAM,gBAAgB;AACtB,IAAM,eAAe;AAErB,SAAS,gBAAiB,OAAuB;AAC/C,SAAO,MAAM;AAAA,IACX;AAAA,IAAa,CAAC,UAAU;AACtB,YAAM,QAAQ,cAAc,QAAQ,KAAK;AACzC,aAAO,OAAO,SAAS,IAAI,QAAQ,aAAa,QAAQ,KAAK,CAAC;AAAA,IAChE;AAAA,EACF;AACF;AAEA,SAAS,QACP,OAAgB,MACP;AACT,SAAO,KAAK,MAAM,GAAG,EAAE;AAAA,IACrB,CACE,SAAS,QACN;A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AA,YAAiC;AAAA,UACnE;AACA,gBAAM,QAAQ;AAKd,cACE,OAAO,MAAM,cAAc,YACxB,OAAO,MAAM,gBAAgB,YAC5B,MAAM,gBAAgB,UAAa,OAAO,MAAM,gBAAgB,SACpE,QAAO;AAAA,YACP;AAAA,YAAgC;AAAA,YAAiC;AAAA,UACnE;AACA,gBAAM,YAAY,QAAQ,kBAAkB,OAAO,UAAU,eAAe;AAAA,YAC1E,QAAQ;AAAA,YAAgB,MAAM;AAAA,UAChC,IACI,QAAQ,eAAe,MAAM,SAAS,IACtC;AACJ,cAAI,CAAC,UAAW,QAAO;AAAA,YACrB;AAAA,YAAsC;AAAA,YAA8B;AAAA,UACtE;AACA,cAAI;AACF,kBAAM,SAAS,MAAM;AAAA,cACnB,EAAE,aAAa,MAAM,aAAa,aAAa,MAAM,YAAa;AAAA,cAAG,EAAE,IAAK;AAAA,YAC9E;AACA,mBAAO,SAAS,KAAK,EAAE,MAAM,WAAW,MAAM,EAAG,CAAC;AAAA,UACpD,QAAQ;AACN,mBAAO;AAAA,cACL;AAAA,cAAoC;AAAA,cAAgC;AAAA,YACtE;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
6
- "names": []
7
- }
@@ -1,147 +0,0 @@
1
- // @nexload-sdk/payload-fields v3.0.0 (build 2026-07-20T16:56:57.614Z)
2
- "use strict";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/money/index.ts
22
- var money_exports = {};
23
- __export(money_exports, {
24
- IRR: () => IRR,
25
- IRT: () => IRT,
26
- formatMoney: () => formatMoney,
27
- moneyField: () => moneyField,
28
- parseMoneyToMinorUnits: () => parseMoneyToMinorUnits,
29
- resolveCurrency: () => resolveCurrency
30
- });
31
- module.exports = __toCommonJS(money_exports);
32
- var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
33
- var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
34
- function resolveCurrency(currency) {
35
- const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
36
- if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
37
- return result;
38
- }
39
- function normalizedNumber(value) {
40
- const persian = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
41
- const arabic = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
42
- return value.trim().replace(
43
- /[۰-۹٠-٩]/g,
44
- (digit) => String(Math.max(
45
- persian.indexOf(digit),
46
- arabic.indexOf(digit)
47
- ) % 10)
48
- ).replace(
49
- /[٬,\s]/g,
50
- ""
51
- ).replace(
52
- /٫/g,
53
- "."
54
- );
55
- }
56
- function parseMoneyToMinorUnits(input, currency) {
57
- const definition = resolveCurrency(currency);
58
- const value = normalizedNumber(input);
59
- if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
60
- const negative = value.startsWith("-");
61
- const [
62
- whole,
63
- fraction = ""
64
- ] = (negative ? value.slice(1) : value).split(".");
65
- if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
66
- const digits = `${whole}${fraction.padEnd(
67
- definition.fractionDigits,
68
- "0"
69
- )}`.replace(
70
- /^0+(?=\d)/,
71
- ""
72
- ) || "0";
73
- const minor = Number(`${negative ? "-" : ""}${digits}`);
74
- if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
75
- return minor;
76
- }
77
- function formatMoney(value, currency, display = {}) {
78
- if (value === null || value === void 0) return null;
79
- if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
80
- const definition = resolveCurrency(currency);
81
- const locale = display.locale ?? (display.digits === "latin" ? "fa-IR-u-nu-latn" : "fa-IR");
82
- const major = value / 10 ** definition.fractionDigits;
83
- const formatted = new Intl.NumberFormat(
84
- locale,
85
- { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }
86
- ).format(major);
87
- return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
88
- }
89
- function moneyField(options) {
90
- var _a, _b;
91
- const overrides = options.overrides ?? {};
92
- if (overrides.name && overrides.name !== options.name) throw new Error("Money field name is protected.");
93
- if (overrides.type && overrides.type !== "number") throw new Error("Money field type is protected.");
94
- const currency = resolveCurrency(options.currency);
95
- if (options.minMinorUnits !== void 0 && (!Number.isSafeInteger(options.minMinorUnits) || options.maxMinorUnits !== void 0 && options.minMinorUnits > options.maxMinorUnits)) throw new Error("Invalid money bounds.");
96
- if (options.maxMinorUnits !== void 0 && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error("Invalid money bounds.");
97
- const consumerValidate = overrides.validate;
98
- const validate = (value, args) => {
99
- if (value === null || value === void 0 || value === "") return (args == null ? void 0 : args.required) ? "\u0648\u0627\u0631\u062F \u06A9\u0631\u062F\u0646 \u0645\u0628\u0644\u063A \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A." : true;
100
- if (typeof value !== "number" || !Number.isSafeInteger(value)) return "\u0645\u0628\u0644\u063A \u0628\u0627\u06CC\u062F \u06CC\u06A9 \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0645\u0639\u062A\u0628\u0631 \u0628\u0627\u0634\u062F.";
101
- if (!options.allowNegative && value < 0) return "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.";
102
- if (options.minMinorUnits !== void 0 && value < options.minMinorUnits) return "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
103
- if (options.maxMinorUnits !== void 0 && value > options.maxMinorUnits) return "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.";
104
- return consumerValidate ? consumerValidate(
105
- value,
106
- args
107
- ) : true;
108
- };
109
- const display = {
110
- locale: "fa-IR",
111
- digits: "persian",
112
- grouping: true,
113
- showCurrency: true,
114
- ...options.display
115
- };
116
- return {
117
- ...overrides,
118
- name: options.name,
119
- type: "number",
120
- validate,
121
- admin: {
122
- ...overrides.admin,
123
- components: {
124
- ...(_a = overrides.admin) == null ? void 0 : _a.components,
125
- Field: {
126
- path: "@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent",
127
- clientProps: {
128
- currency,
129
- display,
130
- allowNegative: options.allowNegative ?? false
131
- }
132
- }
133
- }
134
- },
135
- custom: { ...overrides.custom, nexload: { ...(_b = overrides.custom) == null ? void 0 : _b.nexload, money: currency } }
136
- };
137
- }
138
- // Annotate the CommonJS export names for ESM import in node:
139
- 0 && (module.exports = {
140
- IRR,
141
- IRT,
142
- formatMoney,
143
- moneyField,
144
- parseMoneyToMinorUnits,
145
- resolveCurrency
146
- });
147
- //# sourceMappingURL=index.cjs.map