@nexload-sdk/payload-fields 2.0.1 → 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 (100) hide show
  1. package/README.md +182 -55
  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 +6 -0
  9. package/dist/admin/jalali-date-cell.d.ts.map +1 -0
  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 +12 -0
  13. package/dist/admin/jalali-date-field.d.ts.map +1 -0
  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 +11 -0
  21. package/dist/admin/money-field.d.ts.map +1 -0
  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 +9 -0
  25. package/dist/admin/slug-field.d.ts.map +1 -0
  26. package/dist/admin/slug-field.js +210 -0
  27. package/dist/admin/slug-field.js.map +7 -0
  28. package/dist/admin/validated-text-field.d.ts +6 -0
  29. package/dist/admin/validated-text-field.d.ts.map +1 -0
  30. package/dist/admin/validated-text-field.js +35 -0
  31. package/dist/admin/validated-text-field.js.map +7 -0
  32. package/dist/bank/index.d.ts +7 -0
  33. package/dist/bank/index.d.ts.map +1 -0
  34. package/dist/common/index.d.ts +35 -0
  35. package/dist/common/index.d.ts.map +1 -0
  36. package/dist/contact/index.d.ts +9 -0
  37. package/dist/contact/index.d.ts.map +1 -0
  38. package/dist/date/format-date.d.ts +8 -1
  39. package/dist/date/format-date.d.ts.map +1 -1
  40. package/dist/date/index.d.ts +56 -4
  41. package/dist/date/index.d.ts.map +1 -1
  42. package/dist/date/index.js +258 -0
  43. package/dist/date/index.js.map +7 -0
  44. package/dist/date/picker-types.d.ts +2 -0
  45. package/dist/date/picker-types.d.ts.map +1 -0
  46. package/dist/i18n/messages.d.ts +6 -0
  47. package/dist/i18n/messages.d.ts.map +1 -0
  48. package/dist/i18n/messages.js +97 -0
  49. package/dist/i18n/messages.js.map +7 -0
  50. package/dist/identity/index.d.ts +9 -0
  51. package/dist/identity/index.d.ts.map +1 -0
  52. package/dist/index.d.ts +9 -4
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1038 -0
  55. package/dist/index.js.map +7 -0
  56. package/dist/internal/protect.d.ts +7 -0
  57. package/dist/internal/protect.d.ts.map +1 -0
  58. package/dist/internal/validated-text.d.ts +24 -0
  59. package/dist/internal/validated-text.d.ts.map +1 -0
  60. package/dist/internal/validated-text.js +161 -0
  61. package/dist/internal/validated-text.js.map +7 -0
  62. package/dist/money/index.d.ts +35 -0
  63. package/dist/money/index.d.ts.map +1 -0
  64. package/dist/money/index.js +212 -0
  65. package/dist/money/index.js.map +7 -0
  66. package/dist/plugin.d.ts +17 -0
  67. package/dist/plugin.d.ts.map +1 -0
  68. package/dist/schema/index.d.ts +51 -0
  69. package/dist/schema/index.d.ts.map +1 -0
  70. package/dist/schema/index.js +735 -0
  71. package/dist/schema/index.js.map +7 -0
  72. package/dist/slug/format-slug.d.ts +8 -2
  73. package/dist/slug/format-slug.d.ts.map +1 -1
  74. package/dist/slug/index.d.ts +13 -5
  75. package/dist/slug/index.d.ts.map +1 -1
  76. package/dist/slug/index.js +158 -0
  77. package/dist/slug/index.js.map +7 -0
  78. package/package.json +86 -34
  79. package/dist/date/date-cell.cjs +0 -60
  80. package/dist/date/date-cell.cjs.map +0 -7
  81. package/dist/date/date-cell.d.ts +0 -7
  82. package/dist/date/date-cell.d.ts.map +0 -1
  83. package/dist/date/date-cell.mjs +0 -34
  84. package/dist/date/date-cell.mjs.map +0 -7
  85. package/dist/date/date-picker.cjs +0 -221
  86. package/dist/date/date-picker.cjs.map +0 -7
  87. package/dist/date/date-picker.d.ts +0 -5
  88. package/dist/date/date-picker.d.ts.map +0 -1
  89. package/dist/date/date-picker.mjs +0 -197
  90. package/dist/date/date-picker.mjs.map +0 -7
  91. package/dist/index.cjs +0 -171
  92. package/dist/index.cjs.map +0 -7
  93. package/dist/index.mjs +0 -150
  94. package/dist/index.mjs.map +0 -7
  95. package/dist/slug/slug-field.cjs +0 -246
  96. package/dist/slug/slug-field.cjs.map +0 -7
  97. package/dist/slug/slug-field.d.ts +0 -10
  98. package/dist/slug/slug-field.d.ts.map +0 -1
  99. package/dist/slug/slug-field.mjs +0 -228
  100. package/dist/slug/slug-field.mjs.map +0 -7
@@ -0,0 +1,735 @@
1
+ // @nexload-sdk/payload-fields v4.0.0 (build 2026-11-25T11:31:43.661Z)
2
+
3
+ // src/schema/index.ts
4
+ import { z } from "zod";
5
+ import { field } from "@nexload-sdk/payload-schema";
6
+ import { cardNumberSchema, iranLandlineSchema, iranMobileSchema, legalIdSchema, nationalCodeSchema, postalCodeSchema, shebaSchema } from "@nexload-sdk/persian/zod";
7
+
8
+ // src/bank/index.ts
9
+ import {
10
+ normalizeCardNumber,
11
+ normalizeSheba,
12
+ validateCardNumber,
13
+ validateSheba
14
+ } from "@nexload-sdk/persian/bank";
15
+
16
+ // src/internal/validated-text.ts
17
+ import { text } from "payload/shared";
18
+
19
+ // src/i18n/messages.ts
20
+ import { CARD_ERROR_MESSAGES_FA, SHEBA_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/bank";
21
+ import { LANDLINE_ERROR_MESSAGES_FA, LEGAL_ID_ERROR_MESSAGES_FA, NATIONAL_CODE_ERROR_MESSAGES_FA, POSTAL_CODE_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/identity";
22
+ import { MOBILE_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/mobile";
23
+ var messages = {
24
+ fa: {
25
+ invalid: "\u0645\u0642\u062F\u0627\u0631 \u0648\u0627\u0631\u062F \u0634\u062F\u0647 \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
26
+ required: "\u0627\u06CC\u0646 \u0641\u06CC\u0644\u062F \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.",
27
+ "mobile.invalid": MOBILE_ERROR_MESSAGES_FA.invalid,
28
+ "landline.invalid": LANDLINE_ERROR_MESSAGES_FA.invalid,
29
+ "nationalCode.invalid_format": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_format,
30
+ "nationalCode.repeated_digits": NATIONAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
31
+ "nationalCode.invalid_checksum": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_checksum,
32
+ "legalId.invalid_format": LEGAL_ID_ERROR_MESSAGES_FA.invalid_format,
33
+ "legalId.invalid_checksum": LEGAL_ID_ERROR_MESSAGES_FA.invalid_checksum,
34
+ "postalCode.invalid_format": POSTAL_CODE_ERROR_MESSAGES_FA.invalid_format,
35
+ "postalCode.repeated_digits": POSTAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
36
+ "card.invalid_format": CARD_ERROR_MESSAGES_FA.invalid_format,
37
+ "card.invalid_checksum": CARD_ERROR_MESSAGES_FA.invalid_checksum,
38
+ "sheba.invalid_format": SHEBA_ERROR_MESSAGES_FA.invalid_format,
39
+ "sheba.invalid_checksum": SHEBA_ERROR_MESSAGES_FA.invalid_checksum,
40
+ "money.integer": "\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.",
41
+ "money.negative": "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.",
42
+ "money.min": "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
43
+ "money.max": "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
44
+ "date.invalid": "\u062A\u0627\u0631\u06CC\u062E \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
45
+ "date.min": "\u062A\u0627\u0631\u06CC\u062E \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
46
+ "date.max": "\u062A\u0627\u0631\u06CC\u062E \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
47
+ "dateRange.order": "\u062A\u0627\u0631\u06CC\u062E \u067E\u0627\u06CC\u0627\u0646 \u0646\u0628\u0627\u06CC\u062F \u0642\u0628\u0644 \u0627\u0632 \u062A\u0627\u0631\u06CC\u062E \u0634\u0631\u0648\u0639 \u0628\u0627\u0634\u062F.",
48
+ "dateRange.start": "\u062A\u0627\u0631\u06CC\u062E \u0634\u0631\u0648\u0639",
49
+ "dateRange.end": "\u062A\u0627\u0631\u06CC\u062E \u067E\u0627\u06CC\u0627\u0646",
50
+ "slug.taken": "\u0627\u06CC\u0646 \u0627\u0633\u0644\u0627\u06AF \u0642\u0628\u0644\u0627\u064B \u0627\u0633\u062A\u0641\u0627\u062F\u0647 \u0634\u062F\u0647 \u0627\u0633\u062A.",
51
+ "slug.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.",
52
+ "slug.forbidden": "\u0627\u062C\u0627\u0632\u0647 \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0631\u0627 \u0646\u062F\u0627\u0631\u06CC\u062F.",
53
+ "slug.invalidInput": "\u0648\u0631\u0648\u062F\u06CC \u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
54
+ "slug.notFound": "\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.",
55
+ "slug.failed": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.",
56
+ "sortOrder.integer": "\u062A\u0631\u062A\u06CC\u0628 \u0628\u0627\u06CC\u062F \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0628\u0627\u0634\u062F.",
57
+ "ui.clear": "\u067E\u0627\u06A9 \u06A9\u0631\u062F\u0646",
58
+ "ui.generateSlug": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF",
59
+ "ui.lock": "\u0642\u0641\u0644",
60
+ "ui.edit": "\u0648\u06CC\u0631\u0627\u06CC\u0634"
61
+ },
62
+ en: {
63
+ invalid: "Invalid value.",
64
+ required: "This field is required.",
65
+ "mobile.invalid": "Invalid mobile number.",
66
+ "landline.invalid": "Invalid phone number.",
67
+ "nationalCode.invalid_format": "Invalid national code.",
68
+ "nationalCode.repeated_digits": "Invalid national code.",
69
+ "nationalCode.invalid_checksum": "Invalid national code.",
70
+ "legalId.invalid_format": "Invalid legal ID.",
71
+ "legalId.invalid_checksum": "Invalid legal ID.",
72
+ "postalCode.invalid_format": "Invalid postal code.",
73
+ "postalCode.repeated_digits": "Invalid postal code.",
74
+ "card.invalid_format": "Invalid card number.",
75
+ "card.invalid_checksum": "Invalid card number.",
76
+ "sheba.invalid_format": "Invalid Sheba.",
77
+ "sheba.invalid_checksum": "Invalid Sheba.",
78
+ "money.integer": "Amount must be an integer.",
79
+ "money.negative": "Negative amounts are not allowed.",
80
+ "money.min": "Amount is below the minimum.",
81
+ "money.max": "Amount exceeds the maximum.",
82
+ "date.invalid": "Invalid date.",
83
+ "date.min": "Date is before the minimum.",
84
+ "date.max": "Date exceeds the maximum.",
85
+ "dateRange.order": "End date must be on or after the start date.",
86
+ "dateRange.start": "Start date",
87
+ "dateRange.end": "End date",
88
+ "slug.taken": "This slug is already taken.",
89
+ "slug.unauthenticated": "Sign in to generate a slug.",
90
+ "slug.forbidden": "You cannot generate a slug.",
91
+ "slug.invalidInput": "Invalid slug input.",
92
+ "slug.notFound": "Slug generator not found.",
93
+ "slug.failed": "Slug generation failed.",
94
+ "sortOrder.integer": "Order must be an integer.",
95
+ "ui.clear": "Clear",
96
+ "ui.generateSlug": "Generate slug",
97
+ "ui.lock": "Lock",
98
+ "ui.edit": "Edit"
99
+ }
100
+ };
101
+ function resolveLanguage(language) {
102
+ return language?.startsWith("fa") ? "fa" : "en";
103
+ }
104
+ function t(language, key) {
105
+ const dictionary = messages[resolveLanguage(language)];
106
+ return Object.hasOwn(dictionary, key) ? dictionary[key] : dictionary.invalid;
107
+ }
108
+
109
+ // src/internal/protect.ts
110
+ function assertProtected(overrides, name, type, label) {
111
+ if (overrides.name && overrides.name !== name) throw new Error(`${label} name is protected.`);
112
+ if (overrides.type && overrides.type !== type) throw new Error(`${label} type is protected.`);
113
+ }
114
+
115
+ // src/internal/validated-text.ts
116
+ function createValidatedTextField(options) {
117
+ const overrides = options.overrides ?? {};
118
+ assertProtected(overrides, options.name, "text", "Validated text field");
119
+ const consumerValidate = overrides.validate;
120
+ const validate = (value, args) => {
121
+ const language = args?.req?.i18n?.language;
122
+ if (value === null || value === void 0 || typeof value === "string" && value.trim() === "") {
123
+ if (args?.required ?? options.required ?? overrides.required) return t(language, "required");
124
+ } else {
125
+ const result = options.validate(value);
126
+ if (!result.ok) return t(language, `${options.messagePrefix}.${result.reason}`);
127
+ }
128
+ const defaultResult = text(value, args);
129
+ if (defaultResult !== true) return defaultResult;
130
+ return consumerValidate ? consumerValidate(value, args) : true;
131
+ };
132
+ const components = options.kind === "ltr" ? overrides.admin?.components : {
133
+ ...overrides.admin?.components,
134
+ Field: { path: "@nexload-sdk/payload-fields/admin/validated-text-field#ValidatedTextFieldComponent", clientProps: { kind: options.kind } },
135
+ Cell: { path: "@nexload-sdk/payload-fields/admin/formatted-cell#FormattedCell", clientProps: { kind: options.kind } }
136
+ };
137
+ return {
138
+ ...overrides,
139
+ name: options.name,
140
+ type: "text",
141
+ label: overrides.label ?? options.label,
142
+ unique: options.unique ?? overrides.unique,
143
+ required: options.required ?? overrides.required,
144
+ index: options.unique ?? overrides.unique ? true : overrides.index,
145
+ validate,
146
+ admin: {
147
+ ...overrides.admin,
148
+ rtl: false,
149
+ ...components ? { components } : {}
150
+ },
151
+ hooks: {
152
+ ...overrides.hooks,
153
+ beforeValidate: [
154
+ ...overrides.hooks?.beforeValidate ?? [],
155
+ ({ value }) => {
156
+ if (typeof value !== "string") return value;
157
+ if (value.trim() === "") return null;
158
+ return options.normalize(value) ?? value;
159
+ }
160
+ ]
161
+ },
162
+ custom: {
163
+ ...overrides.custom,
164
+ nexload: {
165
+ ...overrides.custom?.nexload,
166
+ text: { kind: options.kind }
167
+ }
168
+ }
169
+ };
170
+ }
171
+
172
+ // src/bank/index.ts
173
+ function bankCardField(options = {}) {
174
+ return createValidatedTextField({
175
+ name: options.name ?? "cardNumber",
176
+ kind: "card",
177
+ label: options.label ?? { fa: "\u0634\u0645\u0627\u0631\u0647 \u06A9\u0627\u0631\u062A", en: "Card number" },
178
+ normalize: normalizeCardNumber,
179
+ validate: validateCardNumber,
180
+ messagePrefix: "card",
181
+ unique: options.unique,
182
+ required: options.required,
183
+ overrides: options.overrides
184
+ });
185
+ }
186
+ function shebaField(options = {}) {
187
+ return createValidatedTextField({
188
+ name: options.name ?? "sheba",
189
+ kind: "sheba",
190
+ label: options.label ?? { fa: "\u0634\u0645\u0627\u0631\u0647 \u0634\u0628\u0627", en: "Sheba (IBAN)" },
191
+ normalize: normalizeSheba,
192
+ validate: validateSheba,
193
+ messagePrefix: "sheba",
194
+ unique: options.unique,
195
+ required: options.required,
196
+ overrides: options.overrides
197
+ });
198
+ }
199
+
200
+ // src/common/index.ts
201
+ import { number } from "payload/shared";
202
+ function ltrTextField(options) {
203
+ const classes = ["nexload-ltr"];
204
+ if (options.monospace) classes.push("nexload-ltr--mono");
205
+ const existingClass = options.overrides?.admin?.className;
206
+ const className = existingClass ? `${existingClass} ${classes.join(" ")}` : classes.join(" ");
207
+ return createValidatedTextField({
208
+ name: options.name,
209
+ kind: "ltr",
210
+ label: options.label,
211
+ normalize: (val) => val,
212
+ validate: (val) => ({ ok: true, value: val }),
213
+ messagePrefix: "ltr",
214
+ unique: options.unique,
215
+ required: options.required,
216
+ overrides: {
217
+ ...options.overrides,
218
+ ...options.minLength !== void 0 ? { minLength: options.minLength } : {},
219
+ ...options.maxLength !== void 0 ? { maxLength: options.maxLength } : {},
220
+ admin: {
221
+ ...options.overrides?.admin,
222
+ className
223
+ }
224
+ }
225
+ });
226
+ }
227
+ function sortOrderField(options = {}) {
228
+ const name = options.name ?? "sortOrder";
229
+ const overrides = options.overrides ?? {};
230
+ assertProtected(overrides, name, "number", "Sort order field");
231
+ const defaultLabel = { fa: "\u062A\u0631\u062A\u06CC\u0628 \u0646\u0645\u0627\u06CC\u0634", en: "Sort order" };
232
+ const consumerValidate = overrides.validate;
233
+ const validate = (value, args) => {
234
+ const language = args?.req?.i18n?.language;
235
+ if (value !== null && value !== void 0 && value !== "") {
236
+ const num = typeof value === "number" ? value : Number(value);
237
+ if (!Number.isInteger(num)) return t(language, "sortOrder.integer");
238
+ }
239
+ const defaultResult = number(value, args);
240
+ if (defaultResult !== true) return defaultResult;
241
+ return consumerValidate ? consumerValidate(value, args) : true;
242
+ };
243
+ return {
244
+ ...overrides,
245
+ name,
246
+ type: "number",
247
+ label: overrides.label ?? options.label ?? defaultLabel,
248
+ defaultValue: overrides.defaultValue ?? 0,
249
+ min: overrides.min ?? 0,
250
+ index: overrides.index ?? true,
251
+ validate,
252
+ admin: {
253
+ ...overrides.admin,
254
+ position: overrides.admin?.position ?? "sidebar"
255
+ }
256
+ };
257
+ }
258
+
259
+ // src/contact/index.ts
260
+ import { normalizeIranLandline, validateIranLandline } from "@nexload-sdk/persian/identity";
261
+ import { normalizeIranMobile, toE164Mobile, validateIranMobile } from "@nexload-sdk/persian/mobile";
262
+ function iranMobileField(options = {}) {
263
+ const normalize = options.storage === "e164" ? toE164Mobile : normalizeIranMobile;
264
+ return createValidatedTextField({
265
+ name: options.name ?? "mobile",
266
+ kind: "mobile",
267
+ label: options.label ?? { fa: "\u0647\u0645\u0631\u0627\u0647", en: "Mobile" },
268
+ normalize,
269
+ validate: validateIranMobile,
270
+ messagePrefix: "mobile",
271
+ unique: options.unique,
272
+ required: options.required,
273
+ overrides: options.overrides
274
+ });
275
+ }
276
+ function iranLandlineField(options = {}) {
277
+ return createValidatedTextField({
278
+ name: options.name ?? "landline",
279
+ kind: "landline",
280
+ label: options.label ?? { fa: "\u062A\u0644\u0641\u0646 \u062B\u0627\u0628\u062A", en: "Landline" },
281
+ normalize: normalizeIranLandline,
282
+ validate: validateIranLandline,
283
+ messagePrefix: "landline",
284
+ unique: options.unique,
285
+ required: options.required,
286
+ overrides: options.overrides
287
+ });
288
+ }
289
+
290
+ // src/date/index.ts
291
+ import { fromJalali, parseJalaliDate, TEHRAN_TIME_ZONE as TEHRAN_TIME_ZONE2, toValidDate } from "@nexload-sdk/persian/date";
292
+ import { toEnglishDigits } from "@nexload-sdk/persian/digits";
293
+
294
+ // src/date/format-date.ts
295
+ import { formatJalali, TEHRAN_TIME_ZONE } from "@nexload-sdk/persian/date";
296
+
297
+ // src/date/index.ts
298
+ function toStoredJalaliInstant(picked, appearance, timeZone = TEHRAN_TIME_ZONE2) {
299
+ const dateOnly = appearance === "dayOnly" || appearance === "monthOnly";
300
+ return fromJalali({
301
+ year: picked.year,
302
+ month: picked.month,
303
+ day: appearance === "monthOnly" ? 1 : picked.day,
304
+ hour: dateOnly ? 12 : picked.hour ?? 0,
305
+ minute: dateOnly ? 0 : picked.minute ?? 0
306
+ }, { timeZone }).toISOString();
307
+ }
308
+ var ISO_PREFIX = /^\d{4}-\d{2}-\d{2}/;
309
+ var JALALI_STRING = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s+(\d{1,2}:\d{2}))?$/;
310
+ function jalaliStringToIso(value, appearance, timeZone) {
311
+ const match = toEnglishDigits(value.trim()).match(JALALI_STRING);
312
+ if (!match) return null;
313
+ const [, y, m, d, time] = match;
314
+ if (!parseJalaliDate(`${y}/${m}/${d}`, { timeZone })) return null;
315
+ const picked = { year: Number(y), month: Number(m), day: Number(d) };
316
+ if (appearance === "dayOnly" || appearance === "monthOnly") return toStoredJalaliInstant(picked, appearance, timeZone);
317
+ return parseJalaliDate(`${y}/${m}/${d}`, { timeZone, time: time ?? "00:00" })?.toISOString() ?? null;
318
+ }
319
+ function jalaliDateField(options) {
320
+ const overrides = options.overrides ?? {};
321
+ assertProtected(overrides, options.name, "date", "Jalali date field");
322
+ const appearance = options.pickerAppearance ?? "dayOnly";
323
+ const timeZone = options.timeZone ?? TEHRAN_TIME_ZONE2;
324
+ const required = options.required ?? overrides.required;
325
+ const min = toValidDate(options.min, { timeZone });
326
+ const max = toValidDate(options.max, { timeZone });
327
+ if (options.min !== void 0 && !min || options.max !== void 0 && !max || min && max && min > max) {
328
+ throw new Error("Invalid Jalali date bounds.");
329
+ }
330
+ const display = {
331
+ digits: "persian",
332
+ dateStyle: "medium",
333
+ ...appearance === "dayAndTime" || appearance === "timeOnly" ? { timeStyle: "short" } : {},
334
+ timeZone,
335
+ ...options.display
336
+ };
337
+ return {
338
+ ...overrides,
339
+ name: options.name,
340
+ type: "date",
341
+ label: overrides.label ?? options.label,
342
+ required,
343
+ validate: (value, args) => {
344
+ const language = args?.req?.i18n?.language;
345
+ const candidate = value === void 0 ? args.previousValue : value;
346
+ if (candidate == null || typeof candidate === "string" && candidate === "") {
347
+ if (args.required ?? required) return t(language, "required");
348
+ } else {
349
+ const converted = typeof candidate === "string" && !ISO_PREFIX.test(candidate) ? jalaliStringToIso(candidate, appearance, timeZone) : candidate;
350
+ const instant = typeof candidate === "string" && converted === null ? null : toValidDate(converted, { timeZone });
351
+ if (!instant) return t(language, "date.invalid");
352
+ if (min && instant < min) return t(language, "date.min");
353
+ if (max && instant > max) return t(language, "date.max");
354
+ }
355
+ return overrides.validate?.(value, args) ?? true;
356
+ },
357
+ hooks: {
358
+ ...overrides.hooks,
359
+ beforeValidate: [
360
+ ...overrides.hooks?.beforeValidate ?? [],
361
+ ({ value }) => typeof value === "string" && !ISO_PREFIX.test(value) ? jalaliStringToIso(value, appearance, timeZone) ?? value : value
362
+ ]
363
+ },
364
+ admin: {
365
+ ...overrides.admin,
366
+ date: { ...overrides.admin?.date, pickerAppearance: appearance },
367
+ components: {
368
+ ...overrides.admin?.components,
369
+ Field: { path: "@nexload-sdk/payload-fields/admin/jalali-date-field#JalaliDateFieldComponent", clientProps: { appearance, display, timeZone } },
370
+ Cell: { path: "@nexload-sdk/payload-fields/admin/jalali-date-cell#JalaliDateCell", clientProps: { display } }
371
+ }
372
+ },
373
+ custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, jalaliDate: { appearance, display, timeZone } } }
374
+ };
375
+ }
376
+
377
+ // src/identity/index.ts
378
+ import {
379
+ normalizeLegalId,
380
+ normalizeNationalCode,
381
+ normalizePostalCode,
382
+ validateLegalId,
383
+ validateNationalCode,
384
+ validatePostalCode
385
+ } from "@nexload-sdk/persian/identity";
386
+ function nationalCodeField(options = {}) {
387
+ return createValidatedTextField({
388
+ name: options.name ?? "nationalCode",
389
+ kind: "nationalCode",
390
+ label: options.label ?? { fa: "\u06A9\u062F \u0645\u0644\u06CC", en: "National code" },
391
+ normalize: normalizeNationalCode,
392
+ validate: validateNationalCode,
393
+ messagePrefix: "nationalCode",
394
+ unique: options.unique,
395
+ required: options.required,
396
+ overrides: options.overrides
397
+ });
398
+ }
399
+ function legalIdField(options = {}) {
400
+ return createValidatedTextField({
401
+ name: options.name ?? "legalId",
402
+ kind: "legalId",
403
+ label: options.label ?? { fa: "\u0634\u0646\u0627\u0633\u0647 \u0645\u0644\u06CC", en: "Legal ID" },
404
+ normalize: normalizeLegalId,
405
+ validate: validateLegalId,
406
+ messagePrefix: "legalId",
407
+ unique: options.unique,
408
+ required: options.required,
409
+ overrides: options.overrides
410
+ });
411
+ }
412
+ function postalCodeField(options = {}) {
413
+ return createValidatedTextField({
414
+ name: options.name ?? "postalCode",
415
+ kind: "postalCode",
416
+ label: options.label ?? { fa: "\u06A9\u062F \u067E\u0633\u062A\u06CC", en: "Postal code" },
417
+ normalize: normalizePostalCode,
418
+ validate: validatePostalCode,
419
+ messagePrefix: "postalCode",
420
+ unique: options.unique,
421
+ required: options.required,
422
+ overrides: options.overrides
423
+ });
424
+ }
425
+
426
+ // src/money/index.ts
427
+ import { number as number2 } from "payload/shared";
428
+ import { formatNumber, parseNumber, toEnglishDigits as toEnglishDigits2 } from "@nexload-sdk/persian/digits";
429
+ var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
430
+ var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
431
+ function resolveCurrency(currency) {
432
+ const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
433
+ if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
434
+ return result;
435
+ }
436
+ function moneyField(options) {
437
+ const overrides = options.overrides ?? {};
438
+ assertProtected(overrides, options.name, "number", "Money field");
439
+ const currency = resolveCurrency(options.currency);
440
+ if (options.displayCurrency && (currency.code !== "IRR" && currency.code !== "IRT" || options.displayCurrency === currency.code)) throw new Error("Invalid money display currency.");
441
+ if (options.minMinorUnits !== void 0 && (!Number.isSafeInteger(options.minMinorUnits) || options.maxMinorUnits !== void 0 && options.minMinorUnits > options.maxMinorUnits)) throw new Error("Invalid money bounds.");
442
+ if (options.maxMinorUnits !== void 0 && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error("Invalid money bounds.");
443
+ const consumerValidate = overrides.validate;
444
+ const validate = (value, args) => {
445
+ const language = args?.req?.i18n?.language;
446
+ if (value === null || value === void 0) {
447
+ if (args?.required ?? options.required ?? overrides.required) return t(language, "required");
448
+ } else {
449
+ if (typeof value !== "number" || !Number.isSafeInteger(value)) return t(language, "money.integer");
450
+ if (!options.allowNegative && value < 0) return t(language, "money.negative");
451
+ if (options.minMinorUnits !== void 0 && value < options.minMinorUnits) return t(language, "money.min");
452
+ if (options.maxMinorUnits !== void 0 && value > options.maxMinorUnits) return t(language, "money.max");
453
+ }
454
+ const result = number2(value, args);
455
+ if (result !== true) return result;
456
+ return consumerValidate ? consumerValidate(value, args) : true;
457
+ };
458
+ const display = {
459
+ locale: "fa-IR",
460
+ digits: "persian",
461
+ grouping: true,
462
+ showCurrency: true,
463
+ ...options.display
464
+ };
465
+ return {
466
+ ...overrides,
467
+ name: options.name,
468
+ type: "number",
469
+ validate,
470
+ label: options.label ?? overrides.label,
471
+ required: options.required ?? overrides.required,
472
+ hooks: { ...overrides.hooks, beforeValidate: [...overrides.hooks?.beforeValidate ?? [], ({ value }) => {
473
+ if (typeof value !== "string") return value;
474
+ if (!value.trim()) return null;
475
+ const parsed = parseNumber(value);
476
+ return parsed !== null && Number.isSafeInteger(parsed) ? parsed : value;
477
+ }] },
478
+ admin: {
479
+ ...overrides.admin,
480
+ components: {
481
+ ...overrides.admin?.components,
482
+ Cell: { path: "@nexload-sdk/payload-fields/admin/money-cell#MoneyCell", clientProps: { currency, display, displayCurrency: options.displayCurrency } },
483
+ Field: {
484
+ path: "@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent",
485
+ clientProps: {
486
+ currency,
487
+ display,
488
+ displayCurrency: options.displayCurrency,
489
+ allowNegative: options.allowNegative ?? false
490
+ }
491
+ }
492
+ }
493
+ },
494
+ custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, money: currency } }
495
+ };
496
+ }
497
+
498
+ // src/slug/index.ts
499
+ import { text as text2 } from "payload/shared";
500
+
501
+ // src/slug/format-slug.ts
502
+ import { slugify } from "@nexload-sdk/persian/text";
503
+ function getPath(value, path) {
504
+ return path.split(".").reduce(
505
+ (current, key) => {
506
+ if (current && typeof current === "object") return current[key];
507
+ return void 0;
508
+ },
509
+ value
510
+ );
511
+ }
512
+ function hasPath(value, path) {
513
+ return path.split(".").every((key) => {
514
+ if (!value || typeof value !== "object" || !(key in value)) return false;
515
+ value = value[key];
516
+ return true;
517
+ });
518
+ }
519
+ var formatSlug = slugify;
520
+ var formatSlugHook = (options) => ({
521
+ data,
522
+ operation,
523
+ originalDoc,
524
+ siblingData,
525
+ previousSiblingDoc,
526
+ value
527
+ }) => {
528
+ const lock = siblingData?.[options.lockName] ?? data?.[options.lockName];
529
+ const previousSlug = previousSiblingDoc?.[options.name] ?? originalDoc?.[options.name];
530
+ const sourceChanged = hasPath(
531
+ data,
532
+ options.source
533
+ ) && getPath(
534
+ data,
535
+ options.source
536
+ ) !== getPath(
537
+ originalDoc,
538
+ options.source
539
+ );
540
+ const source = hasPath(
541
+ data,
542
+ options.source
543
+ ) ? getPath(
544
+ data,
545
+ options.source
546
+ ) : getPath(
547
+ originalDoc,
548
+ options.source
549
+ );
550
+ if (lock !== false && typeof source === "string" && source.trim() && (operation === "create" || options.regenerateOnSourceChange && sourceChanged)) {
551
+ return formatSlug(source);
552
+ }
553
+ if (operation === "update" && lock !== false && sourceChanged && !source && previousSlug !== void 0) {
554
+ return previousSlug;
555
+ }
556
+ if (lock !== false && operation === "update" && previousSlug !== void 0) return previousSlug;
557
+ if (typeof value === "string") return formatSlug(value);
558
+ return value;
559
+ };
560
+
561
+ // src/slug/index.ts
562
+ function slugField(options = {}) {
563
+ const name = options.name ?? "slug";
564
+ const lockName = options.lockName ?? `${name}Lock`;
565
+ const source = options.source ?? "title";
566
+ const localized = options.overrides?.slug?.localized === true;
567
+ if (options.overrides?.lock?.localized !== void 0 && options.overrides.lock.localized !== localized) throw new Error("Slug lock localization must match slug localization.");
568
+ const slugOverrides = options.overrides?.slug ?? {};
569
+ const lockOverrides = options.overrides?.lock ?? {};
570
+ assertProtected(slugOverrides, name, "text", "Slug field");
571
+ assertProtected(lockOverrides, lockName, "checkbox", "Slug lock");
572
+ const consumerHooks = slugOverrides.hooks?.beforeValidate ?? [];
573
+ const unique = options.unique ?? true;
574
+ const format = formatSlugHook({ name, lockName, source, regenerateOnSourceChange: options.regenerateOnSourceChange ?? true });
575
+ const normalize = async (args) => {
576
+ const base = await format(args);
577
+ if (!unique || typeof base !== "string" || !base || !args.req?.payload || !args.collection?.slug || args.path && (Array.isArray(args.path) ? args.path.length !== 1 || args.path[0] !== name : args.path !== name)) return base;
578
+ const id = args.originalDoc?.id ?? args.id;
579
+ for (let n = 1; n <= 50; n++) {
580
+ const candidate = n === 1 ? base : `${base}-${n}`;
581
+ const found = await args.req.payload.find({
582
+ collection: args.collection.slug,
583
+ where: { and: [{ [name]: { equals: candidate } }, ...id !== void 0 && id !== null ? [{ id: { not_equals: id } }] : []] },
584
+ limit: 1,
585
+ depth: 0,
586
+ pagination: false,
587
+ locale: args.req.locale ?? void 0,
588
+ req: args.req,
589
+ overrideAccess: true
590
+ });
591
+ if (!found.docs.length) return candidate;
592
+ }
593
+ return base;
594
+ };
595
+ const consumerValidate = slugOverrides.validate;
596
+ const validate = (value, args) => {
597
+ const result = text2(value, args);
598
+ if (result !== true) return result;
599
+ return consumerValidate ? consumerValidate(value, args) : true;
600
+ };
601
+ const slug = {
602
+ ...slugOverrides,
603
+ name,
604
+ type: "text",
605
+ index: unique ? true : slugOverrides.index,
606
+ unique,
607
+ validate,
608
+ localized,
609
+ admin: {
610
+ ...slugOverrides.admin,
611
+ position: slugOverrides.admin?.position ?? "sidebar",
612
+ components: {
613
+ ...slugOverrides.admin?.components,
614
+ Field: {
615
+ path: "@nexload-sdk/payload-fields/admin/slug-field#SlugFieldComponent",
616
+ clientProps: { source, lockName, generator: options.generator }
617
+ }
618
+ }
619
+ },
620
+ custom: { ...slugOverrides.custom, nexload: { ...slugOverrides.custom?.nexload, slug: { source, lockName, generator: options.generator } } },
621
+ hooks: {
622
+ ...slugOverrides.hooks,
623
+ beforeValidate: [
624
+ ...consumerHooks,
625
+ normalize
626
+ ]
627
+ }
628
+ };
629
+ const lock = {
630
+ ...lockOverrides,
631
+ name: lockName,
632
+ type: "checkbox",
633
+ localized,
634
+ defaultValue: true,
635
+ admin: { ...lockOverrides.admin, hidden: true, position: lockOverrides.admin?.position ?? "sidebar" }
636
+ };
637
+ return [
638
+ slug,
639
+ lock
640
+ ];
641
+ }
642
+
643
+ // src/schema/index.ts
644
+ function textField(config, schema, nullable = false) {
645
+ const { name: _name, defaultValue, ...payload } = config;
646
+ return field.native({
647
+ payload: { ...payload, required: !nullable },
648
+ schema: nullable ? schema.nullable() : schema,
649
+ ...typeof defaultValue === "string" ? { defaultValue } : {}
650
+ });
651
+ }
652
+ function numberField(config, schema, nullable = false) {
653
+ const { name: _name, defaultValue, ...payload } = config;
654
+ return field.native({
655
+ payload: { ...payload, required: !nullable },
656
+ schema: nullable ? schema.nullable() : schema,
657
+ ...typeof defaultValue === "number" ? { defaultValue } : {}
658
+ });
659
+ }
660
+ var schemaFieldsImplementation = {
661
+ iranMobile: (options = {}) => {
662
+ const { nullable = false, ...rest } = options;
663
+ return textField(iranMobileField({ ...rest, required: !nullable }), iranMobileSchema({ format: rest.storage }), nullable);
664
+ },
665
+ iranLandline: (options = {}) => {
666
+ const { nullable = false, ...rest } = options;
667
+ return textField(iranLandlineField({ ...rest, required: !nullable }), iranLandlineSchema(), nullable);
668
+ },
669
+ nationalCode: (options = {}) => {
670
+ const { nullable = false, ...rest } = options;
671
+ return textField(nationalCodeField({ ...rest, required: !nullable }), nationalCodeSchema(), nullable);
672
+ },
673
+ legalId: (options = {}) => {
674
+ const { nullable = false, ...rest } = options;
675
+ return textField(legalIdField({ ...rest, required: !nullable }), legalIdSchema(), nullable);
676
+ },
677
+ postalCode: (options = {}) => {
678
+ const { nullable = false, ...rest } = options;
679
+ return textField(postalCodeField({ ...rest, required: !nullable }), postalCodeSchema(), nullable);
680
+ },
681
+ bankCard: (options = {}) => {
682
+ const { nullable = false, ...rest } = options;
683
+ return textField(bankCardField({ ...rest, required: !nullable }), cardNumberSchema(), nullable);
684
+ },
685
+ sheba: (options = {}) => {
686
+ const { nullable = false, ...rest } = options;
687
+ return textField(shebaField({ ...rest, required: !nullable }), shebaSchema(), nullable);
688
+ },
689
+ ltrText: (options = {}) => {
690
+ const { nullable = false, ...rest } = options;
691
+ let schema = z.string();
692
+ if (rest.minLength !== void 0) schema = schema.min(rest.minLength);
693
+ if (rest.maxLength !== void 0) schema = schema.max(rest.maxLength);
694
+ return textField(ltrTextField({ ...rest, name: "field", required: !nullable }), schema, nullable);
695
+ },
696
+ sortOrder: (options = {}) => {
697
+ const { nullable = false, ...rest } = options;
698
+ return numberField(sortOrderField({ ...rest, overrides: { ...rest.overrides, required: !nullable } }), z.number().int().nonnegative(), nullable);
699
+ },
700
+ money: (options) => {
701
+ const { nullable = false, ...rest } = options;
702
+ let schema = z.number().int().safe();
703
+ if (!rest.allowNegative) schema = schema.nonnegative();
704
+ if (rest.minMinorUnits !== void 0) schema = schema.min(rest.minMinorUnits);
705
+ if (rest.maxMinorUnits !== void 0) schema = schema.max(rest.maxMinorUnits);
706
+ return numberField(moneyField({ ...rest, name: "field", required: !nullable }), schema, nullable);
707
+ },
708
+ jalaliDate: (options = {}) => {
709
+ const { nullable = false, ...rest } = options;
710
+ const config = jalaliDateField({ ...rest, name: "field", required: !nullable });
711
+ const { name: _name, defaultValue, ...payload } = config;
712
+ const schema = z.iso.datetime({ offset: true });
713
+ return field.native({
714
+ payload: { ...payload, required: !nullable },
715
+ schema: nullable ? schema.nullable() : schema,
716
+ ...typeof defaultValue === "string" ? { defaultValue } : {}
717
+ });
718
+ },
719
+ slug: (options = {}) => {
720
+ const name = options.name ?? "slug";
721
+ const lockName = options.lockName ?? `${name}Lock`;
722
+ const [slug, lock] = slugField({ ...options, name, lockName });
723
+ const { name: _name, defaultValue, ...payload } = lock;
724
+ return { [name]: textField(slug, z.string().transform(formatSlug).pipe(z.string().min(1))), [lockName]: field.native({
725
+ payload: { ...payload, required: true },
726
+ schema: z.boolean(),
727
+ ...typeof defaultValue === "boolean" ? { defaultValue } : {}
728
+ }) };
729
+ }
730
+ };
731
+ var schemaFields = schemaFieldsImplementation;
732
+ export {
733
+ schemaFields
734
+ };
735
+ //# sourceMappingURL=index.js.map