@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.
- package/README.md +196 -17
- package/dist/address/index.d.ts +13 -0
- package/dist/address/index.d.ts.map +1 -0
- package/dist/admin/formatted-cell.d.ts +6 -0
- package/dist/admin/formatted-cell.d.ts.map +1 -0
- package/dist/admin/formatted-cell.js +18 -0
- package/dist/admin/formatted-cell.js.map +7 -0
- package/dist/admin/jalali-date-cell.d.ts +3 -3
- package/dist/admin/jalali-date-cell.d.ts.map +1 -1
- package/dist/admin/jalali-date-cell.js +27 -0
- package/dist/admin/jalali-date-cell.js.map +7 -0
- package/dist/admin/jalali-date-field.d.ts +4 -3
- package/dist/admin/jalali-date-field.d.ts.map +1 -1
- package/dist/admin/jalali-date-field.js +250 -0
- package/dist/admin/jalali-date-field.js.map +7 -0
- package/dist/admin/money-cell.d.ts +10 -0
- package/dist/admin/money-cell.d.ts.map +1 -0
- package/dist/admin/money-cell.js +124 -0
- package/dist/admin/money-cell.js.map +7 -0
- package/dist/admin/money-field.d.ts +3 -2
- package/dist/admin/money-field.d.ts.map +1 -1
- package/dist/admin/money-field.js +183 -0
- package/dist/admin/money-field.js.map +7 -0
- package/dist/admin/slug-field.d.ts.map +1 -1
- package/dist/admin/slug-field.js +210 -0
- package/dist/admin/slug-field.js.map +7 -0
- package/dist/admin/validated-text-field.d.ts +6 -0
- package/dist/admin/validated-text-field.d.ts.map +1 -0
- package/dist/admin/validated-text-field.js +35 -0
- package/dist/admin/validated-text-field.js.map +7 -0
- package/dist/bank/index.d.ts +7 -0
- package/dist/bank/index.d.ts.map +1 -0
- package/dist/common/index.d.ts +35 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/contact/index.d.ts +9 -0
- package/dist/contact/index.d.ts.map +1 -0
- package/dist/date/format-date.d.ts.map +1 -1
- package/dist/date/index.d.ts +37 -4
- package/dist/date/index.d.ts.map +1 -1
- package/dist/date/index.js +258 -0
- package/dist/date/index.js.map +7 -0
- package/dist/i18n/messages.d.ts +6 -0
- package/dist/i18n/messages.d.ts.map +1 -0
- package/dist/i18n/messages.js +97 -0
- package/dist/i18n/messages.js.map +7 -0
- package/dist/identity/index.d.ts +9 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1038 -0
- package/dist/index.js.map +7 -0
- package/dist/internal/protect.d.ts +7 -0
- package/dist/internal/protect.d.ts.map +1 -0
- package/dist/internal/validated-text.d.ts +24 -0
- package/dist/internal/validated-text.d.ts.map +1 -0
- package/dist/internal/validated-text.js +161 -0
- package/dist/internal/validated-text.js.map +7 -0
- package/dist/money/index.d.ts +6 -0
- package/dist/money/index.d.ts.map +1 -1
- package/dist/money/index.js +212 -0
- package/dist/money/index.js.map +7 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/schema/index.d.ts +51 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +735 -0
- package/dist/schema/index.js.map +7 -0
- package/dist/slug/format-slug.d.ts +1 -1
- package/dist/slug/format-slug.d.ts.map +1 -1
- package/dist/slug/index.d.ts +1 -0
- package/dist/slug/index.d.ts.map +1 -1
- package/dist/slug/{index.mjs → index.js} +47 -43
- package/dist/slug/index.js.map +7 -0
- package/package.json +64 -27
- package/dist/admin/jalali-date-cell.cjs +0 -58
- package/dist/admin/jalali-date-cell.cjs.map +0 -7
- package/dist/admin/jalali-date-cell.mjs +0 -32
- package/dist/admin/jalali-date-cell.mjs.map +0 -7
- package/dist/admin/jalali-date-field.cjs +0 -159
- package/dist/admin/jalali-date-field.cjs.map +0 -7
- package/dist/admin/jalali-date-field.mjs +0 -135
- package/dist/admin/jalali-date-field.mjs.map +0 -7
- package/dist/admin/jalali-picker-value.cjs +0 -42
- package/dist/admin/jalali-picker-value.cjs.map +0 -7
- package/dist/admin/jalali-picker-value.d.ts +0 -3
- package/dist/admin/jalali-picker-value.d.ts.map +0 -1
- package/dist/admin/jalali-picker-value.mjs +0 -18
- package/dist/admin/jalali-picker-value.mjs.map +0 -7
- package/dist/admin/money-field.cjs +0 -146
- package/dist/admin/money-field.cjs.map +0 -7
- package/dist/admin/money-field.mjs +0 -122
- package/dist/admin/money-field.mjs.map +0 -7
- package/dist/admin/slug-field.cjs +0 -135
- package/dist/admin/slug-field.cjs.map +0 -7
- package/dist/admin/slug-field.mjs +0 -115
- package/dist/admin/slug-field.mjs.map +0 -7
- package/dist/date/index.cjs +0 -117
- package/dist/date/index.cjs.map +0 -7
- package/dist/date/index.mjs +0 -86
- package/dist/date/index.mjs.map +0 -7
- package/dist/index.cjs +0 -469
- package/dist/index.cjs.map +0 -7
- package/dist/index.mjs +0 -425
- package/dist/index.mjs.map +0 -7
- package/dist/money/index.cjs +0 -147
- package/dist/money/index.cjs.map +0 -7
- package/dist/money/index.mjs +0 -117
- package/dist/money/index.mjs.map +0 -7
- package/dist/slug/index.cjs +0 -183
- package/dist/slug/index.cjs.map +0 -7
- package/dist/slug/index.mjs.map +0 -7
package/dist/index.js
ADDED
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
// @nexload-sdk/payload-fields v4.0.0 (build 2026-11-25T11:31:43.661Z)
|
|
2
|
+
|
|
3
|
+
// src/address/index.ts
|
|
4
|
+
import { IRAN_PROVINCES } from "@nexload-sdk/persian/geo";
|
|
5
|
+
|
|
6
|
+
// src/contact/index.ts
|
|
7
|
+
import { normalizeIranLandline, validateIranLandline } from "@nexload-sdk/persian/identity";
|
|
8
|
+
import { normalizeIranMobile, toE164Mobile, validateIranMobile } from "@nexload-sdk/persian/mobile";
|
|
9
|
+
|
|
10
|
+
// src/internal/validated-text.ts
|
|
11
|
+
import { text } from "payload/shared";
|
|
12
|
+
|
|
13
|
+
// src/i18n/messages.ts
|
|
14
|
+
import { CARD_ERROR_MESSAGES_FA, SHEBA_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/bank";
|
|
15
|
+
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";
|
|
16
|
+
import { MOBILE_ERROR_MESSAGES_FA } from "@nexload-sdk/persian/mobile";
|
|
17
|
+
var messages = {
|
|
18
|
+
fa: {
|
|
19
|
+
invalid: "\u0645\u0642\u062F\u0627\u0631 \u0648\u0627\u0631\u062F \u0634\u062F\u0647 \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
|
|
20
|
+
required: "\u0627\u06CC\u0646 \u0641\u06CC\u0644\u062F \u0627\u0644\u0632\u0627\u0645\u06CC \u0627\u0633\u062A.",
|
|
21
|
+
"mobile.invalid": MOBILE_ERROR_MESSAGES_FA.invalid,
|
|
22
|
+
"landline.invalid": LANDLINE_ERROR_MESSAGES_FA.invalid,
|
|
23
|
+
"nationalCode.invalid_format": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_format,
|
|
24
|
+
"nationalCode.repeated_digits": NATIONAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
|
|
25
|
+
"nationalCode.invalid_checksum": NATIONAL_CODE_ERROR_MESSAGES_FA.invalid_checksum,
|
|
26
|
+
"legalId.invalid_format": LEGAL_ID_ERROR_MESSAGES_FA.invalid_format,
|
|
27
|
+
"legalId.invalid_checksum": LEGAL_ID_ERROR_MESSAGES_FA.invalid_checksum,
|
|
28
|
+
"postalCode.invalid_format": POSTAL_CODE_ERROR_MESSAGES_FA.invalid_format,
|
|
29
|
+
"postalCode.repeated_digits": POSTAL_CODE_ERROR_MESSAGES_FA.repeated_digits,
|
|
30
|
+
"card.invalid_format": CARD_ERROR_MESSAGES_FA.invalid_format,
|
|
31
|
+
"card.invalid_checksum": CARD_ERROR_MESSAGES_FA.invalid_checksum,
|
|
32
|
+
"sheba.invalid_format": SHEBA_ERROR_MESSAGES_FA.invalid_format,
|
|
33
|
+
"sheba.invalid_checksum": SHEBA_ERROR_MESSAGES_FA.invalid_checksum,
|
|
34
|
+
"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.",
|
|
35
|
+
"money.negative": "\u0645\u0628\u0644\u063A \u0645\u0646\u0641\u06CC \u0645\u062C\u0627\u0632 \u0646\u06CC\u0633\u062A.",
|
|
36
|
+
"money.min": "\u0645\u0628\u0644\u063A \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
37
|
+
"money.max": "\u0645\u0628\u0644\u063A \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
38
|
+
"date.invalid": "\u062A\u0627\u0631\u06CC\u062E \u0645\u0639\u062A\u0628\u0631 \u0646\u06CC\u0633\u062A.",
|
|
39
|
+
"date.min": "\u062A\u0627\u0631\u06CC\u062E \u06A9\u0645\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
40
|
+
"date.max": "\u062A\u0627\u0631\u06CC\u062E \u0628\u06CC\u0634\u062A\u0631 \u0627\u0632 \u062D\u062F \u0645\u062C\u0627\u0632 \u0627\u0633\u062A.",
|
|
41
|
+
"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.",
|
|
42
|
+
"dateRange.start": "\u062A\u0627\u0631\u06CC\u062E \u0634\u0631\u0648\u0639",
|
|
43
|
+
"dateRange.end": "\u062A\u0627\u0631\u06CC\u062E \u067E\u0627\u06CC\u0627\u0646",
|
|
44
|
+
"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.",
|
|
45
|
+
"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.",
|
|
46
|
+
"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.",
|
|
47
|
+
"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.",
|
|
48
|
+
"slug.notFound": "\u062A\u0648\u0644\u06CC\u062F\u06A9\u0646\u0646\u062F\u0647 \u0627\u0633\u0644\u0627\u06AF \u067E\u06CC\u062F\u0627 \u0646\u0634\u062F.",
|
|
49
|
+
"slug.failed": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF \u0628\u0627 \u062E\u0637\u0627 \u0645\u0648\u0627\u062C\u0647 \u0634\u062F.",
|
|
50
|
+
"sortOrder.integer": "\u062A\u0631\u062A\u06CC\u0628 \u0628\u0627\u06CC\u062F \u0639\u062F\u062F \u0635\u062D\u06CC\u062D \u0628\u0627\u0634\u062F.",
|
|
51
|
+
"ui.clear": "\u067E\u0627\u06A9 \u06A9\u0631\u062F\u0646",
|
|
52
|
+
"ui.generateSlug": "\u062A\u0648\u0644\u06CC\u062F \u0627\u0633\u0644\u0627\u06AF",
|
|
53
|
+
"ui.lock": "\u0642\u0641\u0644",
|
|
54
|
+
"ui.edit": "\u0648\u06CC\u0631\u0627\u06CC\u0634"
|
|
55
|
+
},
|
|
56
|
+
en: {
|
|
57
|
+
invalid: "Invalid value.",
|
|
58
|
+
required: "This field is required.",
|
|
59
|
+
"mobile.invalid": "Invalid mobile number.",
|
|
60
|
+
"landline.invalid": "Invalid phone number.",
|
|
61
|
+
"nationalCode.invalid_format": "Invalid national code.",
|
|
62
|
+
"nationalCode.repeated_digits": "Invalid national code.",
|
|
63
|
+
"nationalCode.invalid_checksum": "Invalid national code.",
|
|
64
|
+
"legalId.invalid_format": "Invalid legal ID.",
|
|
65
|
+
"legalId.invalid_checksum": "Invalid legal ID.",
|
|
66
|
+
"postalCode.invalid_format": "Invalid postal code.",
|
|
67
|
+
"postalCode.repeated_digits": "Invalid postal code.",
|
|
68
|
+
"card.invalid_format": "Invalid card number.",
|
|
69
|
+
"card.invalid_checksum": "Invalid card number.",
|
|
70
|
+
"sheba.invalid_format": "Invalid Sheba.",
|
|
71
|
+
"sheba.invalid_checksum": "Invalid Sheba.",
|
|
72
|
+
"money.integer": "Amount must be an integer.",
|
|
73
|
+
"money.negative": "Negative amounts are not allowed.",
|
|
74
|
+
"money.min": "Amount is below the minimum.",
|
|
75
|
+
"money.max": "Amount exceeds the maximum.",
|
|
76
|
+
"date.invalid": "Invalid date.",
|
|
77
|
+
"date.min": "Date is before the minimum.",
|
|
78
|
+
"date.max": "Date exceeds the maximum.",
|
|
79
|
+
"dateRange.order": "End date must be on or after the start date.",
|
|
80
|
+
"dateRange.start": "Start date",
|
|
81
|
+
"dateRange.end": "End date",
|
|
82
|
+
"slug.taken": "This slug is already taken.",
|
|
83
|
+
"slug.unauthenticated": "Sign in to generate a slug.",
|
|
84
|
+
"slug.forbidden": "You cannot generate a slug.",
|
|
85
|
+
"slug.invalidInput": "Invalid slug input.",
|
|
86
|
+
"slug.notFound": "Slug generator not found.",
|
|
87
|
+
"slug.failed": "Slug generation failed.",
|
|
88
|
+
"sortOrder.integer": "Order must be an integer.",
|
|
89
|
+
"ui.clear": "Clear",
|
|
90
|
+
"ui.generateSlug": "Generate slug",
|
|
91
|
+
"ui.lock": "Lock",
|
|
92
|
+
"ui.edit": "Edit"
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function resolveLanguage(language) {
|
|
96
|
+
return language?.startsWith("fa") ? "fa" : "en";
|
|
97
|
+
}
|
|
98
|
+
function t(language, key) {
|
|
99
|
+
const dictionary = messages[resolveLanguage(language)];
|
|
100
|
+
return Object.hasOwn(dictionary, key) ? dictionary[key] : dictionary.invalid;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/internal/protect.ts
|
|
104
|
+
function assertProtected(overrides, name, type, label) {
|
|
105
|
+
if (overrides.name && overrides.name !== name) throw new Error(`${label} name is protected.`);
|
|
106
|
+
if (overrides.type && overrides.type !== type) throw new Error(`${label} type is protected.`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/internal/validated-text.ts
|
|
110
|
+
function createValidatedTextField(options) {
|
|
111
|
+
const overrides = options.overrides ?? {};
|
|
112
|
+
assertProtected(overrides, options.name, "text", "Validated text field");
|
|
113
|
+
const consumerValidate = overrides.validate;
|
|
114
|
+
const validate = (value, args) => {
|
|
115
|
+
const language = args?.req?.i18n?.language;
|
|
116
|
+
if (value === null || value === void 0 || typeof value === "string" && value.trim() === "") {
|
|
117
|
+
if (args?.required ?? options.required ?? overrides.required) return t(language, "required");
|
|
118
|
+
} else {
|
|
119
|
+
const result = options.validate(value);
|
|
120
|
+
if (!result.ok) return t(language, `${options.messagePrefix}.${result.reason}`);
|
|
121
|
+
}
|
|
122
|
+
const defaultResult = text(value, args);
|
|
123
|
+
if (defaultResult !== true) return defaultResult;
|
|
124
|
+
return consumerValidate ? consumerValidate(value, args) : true;
|
|
125
|
+
};
|
|
126
|
+
const components = options.kind === "ltr" ? overrides.admin?.components : {
|
|
127
|
+
...overrides.admin?.components,
|
|
128
|
+
Field: { path: "@nexload-sdk/payload-fields/admin/validated-text-field#ValidatedTextFieldComponent", clientProps: { kind: options.kind } },
|
|
129
|
+
Cell: { path: "@nexload-sdk/payload-fields/admin/formatted-cell#FormattedCell", clientProps: { kind: options.kind } }
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
...overrides,
|
|
133
|
+
name: options.name,
|
|
134
|
+
type: "text",
|
|
135
|
+
label: overrides.label ?? options.label,
|
|
136
|
+
unique: options.unique ?? overrides.unique,
|
|
137
|
+
required: options.required ?? overrides.required,
|
|
138
|
+
index: options.unique ?? overrides.unique ? true : overrides.index,
|
|
139
|
+
validate,
|
|
140
|
+
admin: {
|
|
141
|
+
...overrides.admin,
|
|
142
|
+
rtl: false,
|
|
143
|
+
...components ? { components } : {}
|
|
144
|
+
},
|
|
145
|
+
hooks: {
|
|
146
|
+
...overrides.hooks,
|
|
147
|
+
beforeValidate: [
|
|
148
|
+
...overrides.hooks?.beforeValidate ?? [],
|
|
149
|
+
({ value }) => {
|
|
150
|
+
if (typeof value !== "string") return value;
|
|
151
|
+
if (value.trim() === "") return null;
|
|
152
|
+
return options.normalize(value) ?? value;
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
custom: {
|
|
157
|
+
...overrides.custom,
|
|
158
|
+
nexload: {
|
|
159
|
+
...overrides.custom?.nexload,
|
|
160
|
+
text: { kind: options.kind }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/contact/index.ts
|
|
167
|
+
function iranMobileField(options = {}) {
|
|
168
|
+
const normalize = options.storage === "e164" ? toE164Mobile : normalizeIranMobile;
|
|
169
|
+
return createValidatedTextField({
|
|
170
|
+
name: options.name ?? "mobile",
|
|
171
|
+
kind: "mobile",
|
|
172
|
+
label: options.label ?? { fa: "\u0647\u0645\u0631\u0627\u0647", en: "Mobile" },
|
|
173
|
+
normalize,
|
|
174
|
+
validate: validateIranMobile,
|
|
175
|
+
messagePrefix: "mobile",
|
|
176
|
+
unique: options.unique,
|
|
177
|
+
required: options.required,
|
|
178
|
+
overrides: options.overrides
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function iranLandlineField(options = {}) {
|
|
182
|
+
return createValidatedTextField({
|
|
183
|
+
name: options.name ?? "landline",
|
|
184
|
+
kind: "landline",
|
|
185
|
+
label: options.label ?? { fa: "\u062A\u0644\u0641\u0646 \u062B\u0627\u0628\u062A", en: "Landline" },
|
|
186
|
+
normalize: normalizeIranLandline,
|
|
187
|
+
validate: validateIranLandline,
|
|
188
|
+
messagePrefix: "landline",
|
|
189
|
+
unique: options.unique,
|
|
190
|
+
required: options.required,
|
|
191
|
+
overrides: options.overrides
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/identity/index.ts
|
|
196
|
+
import {
|
|
197
|
+
normalizeLegalId,
|
|
198
|
+
normalizeNationalCode,
|
|
199
|
+
normalizePostalCode,
|
|
200
|
+
validateLegalId,
|
|
201
|
+
validateNationalCode,
|
|
202
|
+
validatePostalCode
|
|
203
|
+
} from "@nexload-sdk/persian/identity";
|
|
204
|
+
function nationalCodeField(options = {}) {
|
|
205
|
+
return createValidatedTextField({
|
|
206
|
+
name: options.name ?? "nationalCode",
|
|
207
|
+
kind: "nationalCode",
|
|
208
|
+
label: options.label ?? { fa: "\u06A9\u062F \u0645\u0644\u06CC", en: "National code" },
|
|
209
|
+
normalize: normalizeNationalCode,
|
|
210
|
+
validate: validateNationalCode,
|
|
211
|
+
messagePrefix: "nationalCode",
|
|
212
|
+
unique: options.unique,
|
|
213
|
+
required: options.required,
|
|
214
|
+
overrides: options.overrides
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function legalIdField(options = {}) {
|
|
218
|
+
return createValidatedTextField({
|
|
219
|
+
name: options.name ?? "legalId",
|
|
220
|
+
kind: "legalId",
|
|
221
|
+
label: options.label ?? { fa: "\u0634\u0646\u0627\u0633\u0647 \u0645\u0644\u06CC", en: "Legal ID" },
|
|
222
|
+
normalize: normalizeLegalId,
|
|
223
|
+
validate: validateLegalId,
|
|
224
|
+
messagePrefix: "legalId",
|
|
225
|
+
unique: options.unique,
|
|
226
|
+
required: options.required,
|
|
227
|
+
overrides: options.overrides
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function postalCodeField(options = {}) {
|
|
231
|
+
return createValidatedTextField({
|
|
232
|
+
name: options.name ?? "postalCode",
|
|
233
|
+
kind: "postalCode",
|
|
234
|
+
label: options.label ?? { fa: "\u06A9\u062F \u067E\u0633\u062A\u06CC", en: "Postal code" },
|
|
235
|
+
normalize: normalizePostalCode,
|
|
236
|
+
validate: validatePostalCode,
|
|
237
|
+
messagePrefix: "postalCode",
|
|
238
|
+
unique: options.unique,
|
|
239
|
+
required: options.required,
|
|
240
|
+
overrides: options.overrides
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/address/index.ts
|
|
245
|
+
function iranAddressField(options = {}) {
|
|
246
|
+
const name = options.name ?? "address";
|
|
247
|
+
const { required: overrideRequired, ...overrides } = options.overrides ?? {};
|
|
248
|
+
assertProtected(overrides, name, "group", "Iran address field");
|
|
249
|
+
const required = options.required ?? overrideRequired;
|
|
250
|
+
const recipient = options.recipient ?? true;
|
|
251
|
+
const defaultLabel = { fa: "\u0646\u0634\u0627\u0646\u06CC", en: "Address" };
|
|
252
|
+
const provinceField = {
|
|
253
|
+
name: "province",
|
|
254
|
+
type: "select",
|
|
255
|
+
label: { fa: "\u0627\u0633\u062A\u0627\u0646", en: "Province" },
|
|
256
|
+
options: IRAN_PROVINCES.map((p) => ({
|
|
257
|
+
value: p.code,
|
|
258
|
+
label: { fa: p.nameFa, en: p.nameEn }
|
|
259
|
+
})),
|
|
260
|
+
...required !== void 0 ? { required } : {}
|
|
261
|
+
};
|
|
262
|
+
const cityField = {
|
|
263
|
+
name: "city",
|
|
264
|
+
type: "text",
|
|
265
|
+
label: { fa: "\u0634\u0647\u0631", en: "City" },
|
|
266
|
+
...required !== void 0 ? { required } : {}
|
|
267
|
+
};
|
|
268
|
+
const lineField = {
|
|
269
|
+
name: "line",
|
|
270
|
+
type: "textarea",
|
|
271
|
+
label: { fa: "\u0646\u0634\u0627\u0646\u06CC", en: "Address line" },
|
|
272
|
+
...required !== void 0 ? { required } : {}
|
|
273
|
+
};
|
|
274
|
+
const postalCode = postalCodeField({
|
|
275
|
+
required
|
|
276
|
+
});
|
|
277
|
+
const fields = [
|
|
278
|
+
{
|
|
279
|
+
type: "row",
|
|
280
|
+
fields: [provinceField, cityField]
|
|
281
|
+
},
|
|
282
|
+
lineField,
|
|
283
|
+
postalCode
|
|
284
|
+
];
|
|
285
|
+
if (recipient) {
|
|
286
|
+
const recipientNameField = {
|
|
287
|
+
name: "recipientName",
|
|
288
|
+
type: "text",
|
|
289
|
+
label: { fa: "\u0646\u0627\u0645 \u06AF\u06CC\u0631\u0646\u062F\u0647", en: "Recipient name" },
|
|
290
|
+
...required !== void 0 ? { required } : {}
|
|
291
|
+
};
|
|
292
|
+
const recipientMobile = iranMobileField({
|
|
293
|
+
name: "recipientMobile",
|
|
294
|
+
label: { fa: "\u0647\u0645\u0631\u0627\u0647 \u06AF\u06CC\u0631\u0646\u062F\u0647", en: "Recipient mobile" },
|
|
295
|
+
required
|
|
296
|
+
});
|
|
297
|
+
fields.push({
|
|
298
|
+
type: "row",
|
|
299
|
+
fields: [recipientNameField, recipientMobile]
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return {
|
|
303
|
+
...overrides,
|
|
304
|
+
name,
|
|
305
|
+
type: "group",
|
|
306
|
+
label: overrides.label ?? options.label ?? defaultLabel,
|
|
307
|
+
fields
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// src/bank/index.ts
|
|
312
|
+
import {
|
|
313
|
+
normalizeCardNumber,
|
|
314
|
+
normalizeSheba,
|
|
315
|
+
validateCardNumber,
|
|
316
|
+
validateSheba
|
|
317
|
+
} from "@nexload-sdk/persian/bank";
|
|
318
|
+
function bankCardField(options = {}) {
|
|
319
|
+
return createValidatedTextField({
|
|
320
|
+
name: options.name ?? "cardNumber",
|
|
321
|
+
kind: "card",
|
|
322
|
+
label: options.label ?? { fa: "\u0634\u0645\u0627\u0631\u0647 \u06A9\u0627\u0631\u062A", en: "Card number" },
|
|
323
|
+
normalize: normalizeCardNumber,
|
|
324
|
+
validate: validateCardNumber,
|
|
325
|
+
messagePrefix: "card",
|
|
326
|
+
unique: options.unique,
|
|
327
|
+
required: options.required,
|
|
328
|
+
overrides: options.overrides
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
function shebaField(options = {}) {
|
|
332
|
+
return createValidatedTextField({
|
|
333
|
+
name: options.name ?? "sheba",
|
|
334
|
+
kind: "sheba",
|
|
335
|
+
label: options.label ?? { fa: "\u0634\u0645\u0627\u0631\u0647 \u0634\u0628\u0627", en: "Sheba (IBAN)" },
|
|
336
|
+
normalize: normalizeSheba,
|
|
337
|
+
validate: validateSheba,
|
|
338
|
+
messagePrefix: "sheba",
|
|
339
|
+
unique: options.unique,
|
|
340
|
+
required: options.required,
|
|
341
|
+
overrides: options.overrides
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/common/index.ts
|
|
346
|
+
import { number } from "payload/shared";
|
|
347
|
+
function ltrTextField(options) {
|
|
348
|
+
const classes = ["nexload-ltr"];
|
|
349
|
+
if (options.monospace) classes.push("nexload-ltr--mono");
|
|
350
|
+
const existingClass = options.overrides?.admin?.className;
|
|
351
|
+
const className = existingClass ? `${existingClass} ${classes.join(" ")}` : classes.join(" ");
|
|
352
|
+
return createValidatedTextField({
|
|
353
|
+
name: options.name,
|
|
354
|
+
kind: "ltr",
|
|
355
|
+
label: options.label,
|
|
356
|
+
normalize: (val) => val,
|
|
357
|
+
validate: (val) => ({ ok: true, value: val }),
|
|
358
|
+
messagePrefix: "ltr",
|
|
359
|
+
unique: options.unique,
|
|
360
|
+
required: options.required,
|
|
361
|
+
overrides: {
|
|
362
|
+
...options.overrides,
|
|
363
|
+
...options.minLength !== void 0 ? { minLength: options.minLength } : {},
|
|
364
|
+
...options.maxLength !== void 0 ? { maxLength: options.maxLength } : {},
|
|
365
|
+
admin: {
|
|
366
|
+
...options.overrides?.admin,
|
|
367
|
+
className
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function sortOrderField(options = {}) {
|
|
373
|
+
const name = options.name ?? "sortOrder";
|
|
374
|
+
const overrides = options.overrides ?? {};
|
|
375
|
+
assertProtected(overrides, name, "number", "Sort order field");
|
|
376
|
+
const defaultLabel = { fa: "\u062A\u0631\u062A\u06CC\u0628 \u0646\u0645\u0627\u06CC\u0634", en: "Sort order" };
|
|
377
|
+
const consumerValidate = overrides.validate;
|
|
378
|
+
const validate = (value, args) => {
|
|
379
|
+
const language = args?.req?.i18n?.language;
|
|
380
|
+
if (value !== null && value !== void 0 && value !== "") {
|
|
381
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
382
|
+
if (!Number.isInteger(num)) return t(language, "sortOrder.integer");
|
|
383
|
+
}
|
|
384
|
+
const defaultResult = number(value, args);
|
|
385
|
+
if (defaultResult !== true) return defaultResult;
|
|
386
|
+
return consumerValidate ? consumerValidate(value, args) : true;
|
|
387
|
+
};
|
|
388
|
+
return {
|
|
389
|
+
...overrides,
|
|
390
|
+
name,
|
|
391
|
+
type: "number",
|
|
392
|
+
label: overrides.label ?? options.label ?? defaultLabel,
|
|
393
|
+
defaultValue: overrides.defaultValue ?? 0,
|
|
394
|
+
min: overrides.min ?? 0,
|
|
395
|
+
index: overrides.index ?? true,
|
|
396
|
+
validate,
|
|
397
|
+
admin: {
|
|
398
|
+
...overrides.admin,
|
|
399
|
+
position: overrides.admin?.position ?? "sidebar"
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/date/index.ts
|
|
405
|
+
import { fromJalali, parseJalaliDate, TEHRAN_TIME_ZONE as TEHRAN_TIME_ZONE2, toValidDate } from "@nexload-sdk/persian/date";
|
|
406
|
+
import { toEnglishDigits } from "@nexload-sdk/persian/digits";
|
|
407
|
+
|
|
408
|
+
// src/date/format-date.ts
|
|
409
|
+
import { formatJalali, TEHRAN_TIME_ZONE } from "@nexload-sdk/persian/date";
|
|
410
|
+
function formatJalaliDate(value, options = {}) {
|
|
411
|
+
return formatJalali(value, {
|
|
412
|
+
format: options.dateStyle === "short" ? "short" : options.dateStyle === "long" || options.dateStyle === "full" ? "long" : "medium",
|
|
413
|
+
time: options.timeStyle,
|
|
414
|
+
digits: options.digits,
|
|
415
|
+
timeZone: options.timeZone ?? TEHRAN_TIME_ZONE
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/date/index.ts
|
|
420
|
+
function toStoredJalaliInstant(picked, appearance, timeZone = TEHRAN_TIME_ZONE2) {
|
|
421
|
+
const dateOnly = appearance === "dayOnly" || appearance === "monthOnly";
|
|
422
|
+
return fromJalali({
|
|
423
|
+
year: picked.year,
|
|
424
|
+
month: picked.month,
|
|
425
|
+
day: appearance === "monthOnly" ? 1 : picked.day,
|
|
426
|
+
hour: dateOnly ? 12 : picked.hour ?? 0,
|
|
427
|
+
minute: dateOnly ? 0 : picked.minute ?? 0
|
|
428
|
+
}, { timeZone }).toISOString();
|
|
429
|
+
}
|
|
430
|
+
var ISO_PREFIX = /^\d{4}-\d{2}-\d{2}/;
|
|
431
|
+
var JALALI_STRING = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s+(\d{1,2}:\d{2}))?$/;
|
|
432
|
+
function jalaliStringToIso(value, appearance, timeZone) {
|
|
433
|
+
const match = toEnglishDigits(value.trim()).match(JALALI_STRING);
|
|
434
|
+
if (!match) return null;
|
|
435
|
+
const [, y, m, d, time] = match;
|
|
436
|
+
if (!parseJalaliDate(`${y}/${m}/${d}`, { timeZone })) return null;
|
|
437
|
+
const picked = { year: Number(y), month: Number(m), day: Number(d) };
|
|
438
|
+
if (appearance === "dayOnly" || appearance === "monthOnly") return toStoredJalaliInstant(picked, appearance, timeZone);
|
|
439
|
+
return parseJalaliDate(`${y}/${m}/${d}`, { timeZone, time: time ?? "00:00" })?.toISOString() ?? null;
|
|
440
|
+
}
|
|
441
|
+
function jalaliDateField(options) {
|
|
442
|
+
const overrides = options.overrides ?? {};
|
|
443
|
+
assertProtected(overrides, options.name, "date", "Jalali date field");
|
|
444
|
+
const appearance = options.pickerAppearance ?? "dayOnly";
|
|
445
|
+
const timeZone = options.timeZone ?? TEHRAN_TIME_ZONE2;
|
|
446
|
+
const required = options.required ?? overrides.required;
|
|
447
|
+
const min = toValidDate(options.min, { timeZone });
|
|
448
|
+
const max = toValidDate(options.max, { timeZone });
|
|
449
|
+
if (options.min !== void 0 && !min || options.max !== void 0 && !max || min && max && min > max) {
|
|
450
|
+
throw new Error("Invalid Jalali date bounds.");
|
|
451
|
+
}
|
|
452
|
+
const display = {
|
|
453
|
+
digits: "persian",
|
|
454
|
+
dateStyle: "medium",
|
|
455
|
+
...appearance === "dayAndTime" || appearance === "timeOnly" ? { timeStyle: "short" } : {},
|
|
456
|
+
timeZone,
|
|
457
|
+
...options.display
|
|
458
|
+
};
|
|
459
|
+
return {
|
|
460
|
+
...overrides,
|
|
461
|
+
name: options.name,
|
|
462
|
+
type: "date",
|
|
463
|
+
label: overrides.label ?? options.label,
|
|
464
|
+
required,
|
|
465
|
+
validate: (value, args) => {
|
|
466
|
+
const language = args?.req?.i18n?.language;
|
|
467
|
+
const candidate = value === void 0 ? args.previousValue : value;
|
|
468
|
+
if (candidate == null || typeof candidate === "string" && candidate === "") {
|
|
469
|
+
if (args.required ?? required) return t(language, "required");
|
|
470
|
+
} else {
|
|
471
|
+
const converted = typeof candidate === "string" && !ISO_PREFIX.test(candidate) ? jalaliStringToIso(candidate, appearance, timeZone) : candidate;
|
|
472
|
+
const instant = typeof candidate === "string" && converted === null ? null : toValidDate(converted, { timeZone });
|
|
473
|
+
if (!instant) return t(language, "date.invalid");
|
|
474
|
+
if (min && instant < min) return t(language, "date.min");
|
|
475
|
+
if (max && instant > max) return t(language, "date.max");
|
|
476
|
+
}
|
|
477
|
+
return overrides.validate?.(value, args) ?? true;
|
|
478
|
+
},
|
|
479
|
+
hooks: {
|
|
480
|
+
...overrides.hooks,
|
|
481
|
+
beforeValidate: [
|
|
482
|
+
...overrides.hooks?.beforeValidate ?? [],
|
|
483
|
+
({ value }) => typeof value === "string" && !ISO_PREFIX.test(value) ? jalaliStringToIso(value, appearance, timeZone) ?? value : value
|
|
484
|
+
]
|
|
485
|
+
},
|
|
486
|
+
admin: {
|
|
487
|
+
...overrides.admin,
|
|
488
|
+
date: { ...overrides.admin?.date, pickerAppearance: appearance },
|
|
489
|
+
components: {
|
|
490
|
+
...overrides.admin?.components,
|
|
491
|
+
Field: { path: "@nexload-sdk/payload-fields/admin/jalali-date-field#JalaliDateFieldComponent", clientProps: { appearance, display, timeZone } },
|
|
492
|
+
Cell: { path: "@nexload-sdk/payload-fields/admin/jalali-date-cell#JalaliDateCell", clientProps: { display } }
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, jalaliDate: { appearance, display, timeZone } } }
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
function jalaliDateRangeField(options = {}) {
|
|
499
|
+
const { start = "startsAt", end = "endsAt", pickerAppearance, timeZone, required, labels } = options;
|
|
500
|
+
const shared = { pickerAppearance, timeZone, required };
|
|
501
|
+
return {
|
|
502
|
+
type: "row",
|
|
503
|
+
fields: [
|
|
504
|
+
jalaliDateField({ ...shared, name: start, label: labels?.start ?? { fa: t("fa", "dateRange.start"), en: t("en", "dateRange.start") } }),
|
|
505
|
+
jalaliDateField({
|
|
506
|
+
...shared,
|
|
507
|
+
name: end,
|
|
508
|
+
label: labels?.end ?? { fa: t("fa", "dateRange.end"), en: t("en", "dateRange.end") },
|
|
509
|
+
overrides: {
|
|
510
|
+
validate: (value, args) => {
|
|
511
|
+
const siblings = args.siblingData;
|
|
512
|
+
const startValue = siblings?.[start];
|
|
513
|
+
const startDate = typeof startValue === "string" || startValue instanceof Date ? toValidDate(startValue, { timeZone }) : null;
|
|
514
|
+
const endDate = toValidDate(value === void 0 ? args.previousValue : value, { timeZone });
|
|
515
|
+
return startDate && endDate && endDate < startDate ? t(args?.req?.i18n?.language, "dateRange.order") : true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
})
|
|
519
|
+
]
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
function withJalaliTimestamps(fields, options = {}) {
|
|
523
|
+
const output = [...fields];
|
|
524
|
+
const add = (name, source, override) => {
|
|
525
|
+
if (output.some((field) => "name" in field && field.name === name)) throw new Error(`Duplicate Jalali timestamp field: ${name}`);
|
|
526
|
+
output.push({
|
|
527
|
+
...override,
|
|
528
|
+
name,
|
|
529
|
+
type: "text",
|
|
530
|
+
virtual: true,
|
|
531
|
+
admin: { ...override?.admin, readOnly: true },
|
|
532
|
+
hooks: {
|
|
533
|
+
...override?.hooks,
|
|
534
|
+
afterRead: [
|
|
535
|
+
...override?.hooks?.afterRead ?? [],
|
|
536
|
+
({ siblingData = {} }) => formatJalaliDate(
|
|
537
|
+
siblingData[source],
|
|
538
|
+
options.display
|
|
539
|
+
)
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
};
|
|
544
|
+
if (options.createdAt !== false) add(
|
|
545
|
+
"createdAtJalali",
|
|
546
|
+
"createdAt",
|
|
547
|
+
options.overrides?.createdAt
|
|
548
|
+
);
|
|
549
|
+
if (options.updatedAt !== false) add(
|
|
550
|
+
"updatedAtJalali",
|
|
551
|
+
"updatedAt",
|
|
552
|
+
options.overrides?.updatedAt
|
|
553
|
+
);
|
|
554
|
+
return output;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/money/index.ts
|
|
558
|
+
import { number as number2 } from "payload/shared";
|
|
559
|
+
import { formatNumber, parseNumber, toEnglishDigits as toEnglishDigits2 } from "@nexload-sdk/persian/digits";
|
|
560
|
+
var IRR = { code: "IRR", label: "\u0631\u06CC\u0627\u0644", fractionDigits: 0 };
|
|
561
|
+
var IRT = { code: "IRT", label: "\u062A\u0648\u0645\u0627\u0646", fractionDigits: 0 };
|
|
562
|
+
function resolveCurrency(currency) {
|
|
563
|
+
const result = currency === "IRR" ? IRR : currency === "IRT" ? IRT : currency;
|
|
564
|
+
if (!result.code.trim() || !result.label.trim() || !Number.isInteger(result.fractionDigits) || result.fractionDigits < 0 || result.fractionDigits > 20) throw new Error("Invalid money currency definition.");
|
|
565
|
+
return result;
|
|
566
|
+
}
|
|
567
|
+
function normalizedNumber(value) {
|
|
568
|
+
return toEnglishDigits2(value.trim()).replace(/[٬,\s]/g, "").replace(/٫/g, ".");
|
|
569
|
+
}
|
|
570
|
+
function parseMoneyToMinorUnits(input, currency) {
|
|
571
|
+
const definition = resolveCurrency(currency);
|
|
572
|
+
const value = normalizedNumber(input);
|
|
573
|
+
if (!/^-?\d+(?:\.\d+)?$/.test(value)) throw new TypeError("Invalid money input.");
|
|
574
|
+
const negative = value.startsWith("-");
|
|
575
|
+
const [
|
|
576
|
+
whole,
|
|
577
|
+
fraction = ""
|
|
578
|
+
] = (negative ? value.slice(1) : value).split(".");
|
|
579
|
+
if (fraction.length > definition.fractionDigits) throw new RangeError("Money input has unsupported precision.");
|
|
580
|
+
const digits = `${whole}${fraction.padEnd(
|
|
581
|
+
definition.fractionDigits,
|
|
582
|
+
"0"
|
|
583
|
+
)}`.replace(
|
|
584
|
+
/^0+(?=\d)/,
|
|
585
|
+
""
|
|
586
|
+
) || "0";
|
|
587
|
+
const minor = Number(`${negative ? "-" : ""}${digits}`);
|
|
588
|
+
if (!Number.isSafeInteger(minor)) throw new RangeError("Money value is outside the safe integer range.");
|
|
589
|
+
return minor;
|
|
590
|
+
}
|
|
591
|
+
function formatMoney(value, currency, display = {}) {
|
|
592
|
+
if (value === null || value === void 0) return null;
|
|
593
|
+
if (!Number.isSafeInteger(value)) throw new RangeError("Money value is outside the safe integer range.");
|
|
594
|
+
const definition = resolveCurrency(currency);
|
|
595
|
+
const major = value / 10 ** definition.fractionDigits;
|
|
596
|
+
const formatted = display.locale ? new Intl.NumberFormat(display.locale, { useGrouping: display.grouping ?? true, minimumFractionDigits: definition.fractionDigits, maximumFractionDigits: definition.fractionDigits }).format(major) : formatNumber(major, { digits: display.digits, grouping: display.grouping, fractionDigits: definition.fractionDigits });
|
|
597
|
+
return display.showCurrency ?? true ? `${formatted} ${definition.label}` : formatted;
|
|
598
|
+
}
|
|
599
|
+
function moneyField(options) {
|
|
600
|
+
const overrides = options.overrides ?? {};
|
|
601
|
+
assertProtected(overrides, options.name, "number", "Money field");
|
|
602
|
+
const currency = resolveCurrency(options.currency);
|
|
603
|
+
if (options.displayCurrency && (currency.code !== "IRR" && currency.code !== "IRT" || options.displayCurrency === currency.code)) throw new Error("Invalid money display currency.");
|
|
604
|
+
if (options.minMinorUnits !== void 0 && (!Number.isSafeInteger(options.minMinorUnits) || options.maxMinorUnits !== void 0 && options.minMinorUnits > options.maxMinorUnits)) throw new Error("Invalid money bounds.");
|
|
605
|
+
if (options.maxMinorUnits !== void 0 && !Number.isSafeInteger(options.maxMinorUnits)) throw new Error("Invalid money bounds.");
|
|
606
|
+
const consumerValidate = overrides.validate;
|
|
607
|
+
const validate = (value, args) => {
|
|
608
|
+
const language = args?.req?.i18n?.language;
|
|
609
|
+
if (value === null || value === void 0) {
|
|
610
|
+
if (args?.required ?? options.required ?? overrides.required) return t(language, "required");
|
|
611
|
+
} else {
|
|
612
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) return t(language, "money.integer");
|
|
613
|
+
if (!options.allowNegative && value < 0) return t(language, "money.negative");
|
|
614
|
+
if (options.minMinorUnits !== void 0 && value < options.minMinorUnits) return t(language, "money.min");
|
|
615
|
+
if (options.maxMinorUnits !== void 0 && value > options.maxMinorUnits) return t(language, "money.max");
|
|
616
|
+
}
|
|
617
|
+
const result = number2(value, args);
|
|
618
|
+
if (result !== true) return result;
|
|
619
|
+
return consumerValidate ? consumerValidate(value, args) : true;
|
|
620
|
+
};
|
|
621
|
+
const display = {
|
|
622
|
+
locale: "fa-IR",
|
|
623
|
+
digits: "persian",
|
|
624
|
+
grouping: true,
|
|
625
|
+
showCurrency: true,
|
|
626
|
+
...options.display
|
|
627
|
+
};
|
|
628
|
+
return {
|
|
629
|
+
...overrides,
|
|
630
|
+
name: options.name,
|
|
631
|
+
type: "number",
|
|
632
|
+
validate,
|
|
633
|
+
label: options.label ?? overrides.label,
|
|
634
|
+
required: options.required ?? overrides.required,
|
|
635
|
+
hooks: { ...overrides.hooks, beforeValidate: [...overrides.hooks?.beforeValidate ?? [], ({ value }) => {
|
|
636
|
+
if (typeof value !== "string") return value;
|
|
637
|
+
if (!value.trim()) return null;
|
|
638
|
+
const parsed = parseNumber(value);
|
|
639
|
+
return parsed !== null && Number.isSafeInteger(parsed) ? parsed : value;
|
|
640
|
+
}] },
|
|
641
|
+
admin: {
|
|
642
|
+
...overrides.admin,
|
|
643
|
+
components: {
|
|
644
|
+
...overrides.admin?.components,
|
|
645
|
+
Cell: { path: "@nexload-sdk/payload-fields/admin/money-cell#MoneyCell", clientProps: { currency, display, displayCurrency: options.displayCurrency } },
|
|
646
|
+
Field: {
|
|
647
|
+
path: "@nexload-sdk/payload-fields/admin/money-field#MoneyFieldComponent",
|
|
648
|
+
clientProps: {
|
|
649
|
+
currency,
|
|
650
|
+
display,
|
|
651
|
+
displayCurrency: options.displayCurrency,
|
|
652
|
+
allowNegative: options.allowNegative ?? false
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
custom: { ...overrides.custom, nexload: { ...overrides.custom?.nexload, money: currency } }
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// src/plugin.ts
|
|
662
|
+
import { parseNumber as parseNumber2 } from "@nexload-sdk/persian/digits";
|
|
663
|
+
|
|
664
|
+
// src/slug/format-slug.ts
|
|
665
|
+
import { slugify } from "@nexload-sdk/persian/text";
|
|
666
|
+
function getPath(value, path) {
|
|
667
|
+
return path.split(".").reduce(
|
|
668
|
+
(current, key) => {
|
|
669
|
+
if (current && typeof current === "object") return current[key];
|
|
670
|
+
return void 0;
|
|
671
|
+
},
|
|
672
|
+
value
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
function hasPath(value, path) {
|
|
676
|
+
return path.split(".").every((key) => {
|
|
677
|
+
if (!value || typeof value !== "object" || !(key in value)) return false;
|
|
678
|
+
value = value[key];
|
|
679
|
+
return true;
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
var formatSlug = slugify;
|
|
683
|
+
var formatSlugHook = (options) => ({
|
|
684
|
+
data,
|
|
685
|
+
operation,
|
|
686
|
+
originalDoc,
|
|
687
|
+
siblingData,
|
|
688
|
+
previousSiblingDoc,
|
|
689
|
+
value
|
|
690
|
+
}) => {
|
|
691
|
+
const lock = siblingData?.[options.lockName] ?? data?.[options.lockName];
|
|
692
|
+
const previousSlug = previousSiblingDoc?.[options.name] ?? originalDoc?.[options.name];
|
|
693
|
+
const sourceChanged = hasPath(
|
|
694
|
+
data,
|
|
695
|
+
options.source
|
|
696
|
+
) && getPath(
|
|
697
|
+
data,
|
|
698
|
+
options.source
|
|
699
|
+
) !== getPath(
|
|
700
|
+
originalDoc,
|
|
701
|
+
options.source
|
|
702
|
+
);
|
|
703
|
+
const source = hasPath(
|
|
704
|
+
data,
|
|
705
|
+
options.source
|
|
706
|
+
) ? getPath(
|
|
707
|
+
data,
|
|
708
|
+
options.source
|
|
709
|
+
) : getPath(
|
|
710
|
+
originalDoc,
|
|
711
|
+
options.source
|
|
712
|
+
);
|
|
713
|
+
if (lock !== false && typeof source === "string" && source.trim() && (operation === "create" || options.regenerateOnSourceChange && sourceChanged)) {
|
|
714
|
+
return formatSlug(source);
|
|
715
|
+
}
|
|
716
|
+
if (operation === "update" && lock !== false && sourceChanged && !source && previousSlug !== void 0) {
|
|
717
|
+
return previousSlug;
|
|
718
|
+
}
|
|
719
|
+
if (lock !== false && operation === "update" && previousSlug !== void 0) return previousSlug;
|
|
720
|
+
if (typeof value === "string") return formatSlug(value);
|
|
721
|
+
return value;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
// src/plugin.ts
|
|
725
|
+
function isPlainObject(value) {
|
|
726
|
+
if (!value || typeof value !== "object") return false;
|
|
727
|
+
const proto = Object.getPrototypeOf(value);
|
|
728
|
+
return proto === Object.prototype || proto === null;
|
|
729
|
+
}
|
|
730
|
+
function normalizeMoneyValue(val) {
|
|
731
|
+
const trimmed = val.trim();
|
|
732
|
+
if (trimmed === "") return null;
|
|
733
|
+
const parsed = parseNumber2(trimmed);
|
|
734
|
+
return parsed !== null && Number.isSafeInteger(parsed) ? parsed : val;
|
|
735
|
+
}
|
|
736
|
+
function normalizeDataMoneyFields(fields, data, blocks) {
|
|
737
|
+
if (Array.isArray(data)) {
|
|
738
|
+
let out2 = data;
|
|
739
|
+
data.forEach((item, index) => {
|
|
740
|
+
const next = normalizeDataMoneyFields(fields, item, blocks);
|
|
741
|
+
if (next !== item) {
|
|
742
|
+
if (out2 === data) out2 = [...data];
|
|
743
|
+
out2[index] = next;
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
return out2;
|
|
747
|
+
}
|
|
748
|
+
if (!isPlainObject(data)) return data;
|
|
749
|
+
let out = data;
|
|
750
|
+
const assign = (key, value) => {
|
|
751
|
+
if (out === data) out = { ...data };
|
|
752
|
+
out[key] = value;
|
|
753
|
+
};
|
|
754
|
+
const nested = (key, nestedFields) => {
|
|
755
|
+
const current = out[key];
|
|
756
|
+
const next = normalizeDataMoneyFields(nestedFields, current, blocks);
|
|
757
|
+
if (next !== current) assign(key, next);
|
|
758
|
+
};
|
|
759
|
+
for (const field of fields) {
|
|
760
|
+
if (field.type === "number" && field.custom?.nexload?.money && "name" in field) {
|
|
761
|
+
const val = out[field.name];
|
|
762
|
+
if (typeof val === "string") {
|
|
763
|
+
const next = normalizeMoneyValue(val);
|
|
764
|
+
if (next !== val) assign(field.name, next);
|
|
765
|
+
}
|
|
766
|
+
} else if (field.type === "group" && "fields" in field && "name" in field) {
|
|
767
|
+
nested(field.name, field.fields);
|
|
768
|
+
} else if ((field.type === "row" || field.type === "collapsible") && "fields" in field) {
|
|
769
|
+
out = normalizeDataMoneyFields(field.fields, out, blocks);
|
|
770
|
+
} else if (field.type === "tabs" && "tabs" in field) {
|
|
771
|
+
for (const tab of field.tabs) {
|
|
772
|
+
if ("name" in tab && tab.name) {
|
|
773
|
+
nested(tab.name, tab.fields);
|
|
774
|
+
} else {
|
|
775
|
+
out = normalizeDataMoneyFields(tab.fields, out, blocks);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
} else if (field.type === "array" && "fields" in field && "name" in field) {
|
|
779
|
+
nested(field.name, field.fields);
|
|
780
|
+
} else if (field.type === "blocks" && "name" in field) {
|
|
781
|
+
const rows = out[field.name];
|
|
782
|
+
if (Array.isArray(rows)) {
|
|
783
|
+
const candidates = [];
|
|
784
|
+
for (const block of field.blocks ?? []) candidates.push(block);
|
|
785
|
+
for (const ref of field.blockReferences ?? []) {
|
|
786
|
+
const resolved = typeof ref === "string" ? blocks.get(ref) : ref;
|
|
787
|
+
if (resolved) candidates.push({ slug: typeof ref === "string" ? ref : ref.slug, fields: resolved.fields });
|
|
788
|
+
}
|
|
789
|
+
let nextRows = rows;
|
|
790
|
+
rows.forEach((block, index) => {
|
|
791
|
+
if (!isPlainObject(block)) return;
|
|
792
|
+
const def = candidates.find((b) => b.slug === block.blockType);
|
|
793
|
+
if (!def) return;
|
|
794
|
+
const next = normalizeDataMoneyFields(def.fields, block, blocks);
|
|
795
|
+
if (next !== block) {
|
|
796
|
+
if (nextRows === rows) nextRows = [...rows];
|
|
797
|
+
nextRows[index] = next;
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
if (nextRows !== rows) assign(field.name, nextRows);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return out;
|
|
805
|
+
}
|
|
806
|
+
function failure(code, message, status) {
|
|
807
|
+
return Response.json(
|
|
808
|
+
{ error: { code, message } },
|
|
809
|
+
{ status }
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
var PAYLOAD_FIELDS_PLUGIN_ORDER = 900;
|
|
813
|
+
function payloadFieldsPlugin(options = {}) {
|
|
814
|
+
const plugin = (config) => {
|
|
815
|
+
const blockMap = new Map((config.blocks ?? []).map((block) => [block.slug, block]));
|
|
816
|
+
return {
|
|
817
|
+
...config,
|
|
818
|
+
collections: (config.collections ?? []).map((collection) => ({
|
|
819
|
+
...collection,
|
|
820
|
+
hooks: {
|
|
821
|
+
...collection.hooks,
|
|
822
|
+
beforeOperation: [
|
|
823
|
+
...collection.hooks?.beforeOperation ?? [],
|
|
824
|
+
({ args, collection: colConfig }) => {
|
|
825
|
+
if (args && "data" in args && args.data && colConfig?.fields) {
|
|
826
|
+
const data = normalizeDataMoneyFields(colConfig.fields, args.data, blockMap);
|
|
827
|
+
return data === args.data ? args : { ...args, data };
|
|
828
|
+
}
|
|
829
|
+
return args;
|
|
830
|
+
}
|
|
831
|
+
]
|
|
832
|
+
}
|
|
833
|
+
})),
|
|
834
|
+
globals: (config.globals ?? []).map((global) => ({
|
|
835
|
+
...global,
|
|
836
|
+
hooks: {
|
|
837
|
+
...global.hooks,
|
|
838
|
+
beforeOperation: [
|
|
839
|
+
...global.hooks?.beforeOperation ?? [],
|
|
840
|
+
({ args, global: globConfig }) => {
|
|
841
|
+
if (args && "data" in args && args.data && globConfig?.fields) {
|
|
842
|
+
const data = normalizeDataMoneyFields(globConfig.fields, args.data, blockMap);
|
|
843
|
+
return data === args.data ? args : { ...args, data };
|
|
844
|
+
}
|
|
845
|
+
return args;
|
|
846
|
+
}
|
|
847
|
+
]
|
|
848
|
+
}
|
|
849
|
+
})),
|
|
850
|
+
endpoints: [
|
|
851
|
+
...config.endpoints ?? [],
|
|
852
|
+
{
|
|
853
|
+
path: "/payload-fields/generate-slug",
|
|
854
|
+
method: "post",
|
|
855
|
+
handler: async (req) => {
|
|
856
|
+
if (!req.user) return failure(
|
|
857
|
+
"PAYLOAD_FIELDS_UNAUTHENTICATED",
|
|
858
|
+
t(req.i18n?.language, "slug.unauthenticated"),
|
|
859
|
+
401
|
|
860
|
+
);
|
|
861
|
+
if (options.generateSlugAccess && !await options.generateSlugAccess({ req })) return failure(
|
|
862
|
+
"PAYLOAD_FIELDS_FORBIDDEN",
|
|
863
|
+
t(req.i18n?.language, "slug.forbidden"),
|
|
864
|
+
403
|
|
865
|
+
);
|
|
866
|
+
let body;
|
|
867
|
+
try {
|
|
868
|
+
body = await req.json?.();
|
|
869
|
+
} catch {
|
|
870
|
+
return failure(
|
|
871
|
+
"PAYLOAD_FIELDS_INVALID_INPUT",
|
|
872
|
+
t(req.i18n?.language, "slug.invalidInput"),
|
|
873
|
+
400
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return failure(
|
|
877
|
+
"PAYLOAD_FIELDS_INVALID_INPUT",
|
|
878
|
+
t(req.i18n?.language, "slug.invalidInput"),
|
|
879
|
+
400
|
|
880
|
+
);
|
|
881
|
+
const input = body;
|
|
882
|
+
if (typeof input.generator !== "string" || typeof input.sourceValue !== "string" || input.currentSlug !== void 0 && typeof input.currentSlug !== "string") return failure(
|
|
883
|
+
"PAYLOAD_FIELDS_INVALID_INPUT",
|
|
884
|
+
t(req.i18n?.language, "slug.invalidInput"),
|
|
885
|
+
400
|
|
886
|
+
);
|
|
887
|
+
const generator = options.slugGenerators && Object.prototype.hasOwnProperty.call(
|
|
888
|
+
options.slugGenerators,
|
|
889
|
+
input.generator
|
|
890
|
+
) ? options.slugGenerators[input.generator] : void 0;
|
|
891
|
+
if (!generator) return failure(
|
|
892
|
+
"PAYLOAD_FIELDS_GENERATOR_NOT_FOUND",
|
|
893
|
+
t(req.i18n?.language, "slug.notFound"),
|
|
894
|
+
404
|
|
895
|
+
);
|
|
896
|
+
try {
|
|
897
|
+
const result = await generator(
|
|
898
|
+
{ sourceValue: input.sourceValue, currentSlug: input.currentSlug },
|
|
899
|
+
{ req }
|
|
900
|
+
);
|
|
901
|
+
return Response.json({ slug: formatSlug(result) });
|
|
902
|
+
} catch (err) {
|
|
903
|
+
req.payload.logger.error(
|
|
904
|
+
{
|
|
905
|
+
err,
|
|
906
|
+
event: "payload_fields.slug.generation_failed",
|
|
907
|
+
generator: input.generator,
|
|
908
|
+
outcome: "failure"
|
|
909
|
+
},
|
|
910
|
+
"Slug generation failed"
|
|
911
|
+
);
|
|
912
|
+
return failure(
|
|
913
|
+
"PAYLOAD_FIELDS_GENERATION_FAILED",
|
|
914
|
+
t(req.i18n?.language, "slug.failed"),
|
|
915
|
+
500
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
]
|
|
921
|
+
};
|
|
922
|
+
};
|
|
923
|
+
plugin.order = PAYLOAD_FIELDS_PLUGIN_ORDER;
|
|
924
|
+
plugin.slug = "nexload-fields";
|
|
925
|
+
return plugin;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/slug/index.ts
|
|
929
|
+
import { text as text2 } from "payload/shared";
|
|
930
|
+
function slugField(options = {}) {
|
|
931
|
+
const name = options.name ?? "slug";
|
|
932
|
+
const lockName = options.lockName ?? `${name}Lock`;
|
|
933
|
+
const source = options.source ?? "title";
|
|
934
|
+
const localized = options.overrides?.slug?.localized === true;
|
|
935
|
+
if (options.overrides?.lock?.localized !== void 0 && options.overrides.lock.localized !== localized) throw new Error("Slug lock localization must match slug localization.");
|
|
936
|
+
const slugOverrides = options.overrides?.slug ?? {};
|
|
937
|
+
const lockOverrides = options.overrides?.lock ?? {};
|
|
938
|
+
assertProtected(slugOverrides, name, "text", "Slug field");
|
|
939
|
+
assertProtected(lockOverrides, lockName, "checkbox", "Slug lock");
|
|
940
|
+
const consumerHooks = slugOverrides.hooks?.beforeValidate ?? [];
|
|
941
|
+
const unique = options.unique ?? true;
|
|
942
|
+
const format = formatSlugHook({ name, lockName, source, regenerateOnSourceChange: options.regenerateOnSourceChange ?? true });
|
|
943
|
+
const normalize = async (args) => {
|
|
944
|
+
const base = await format(args);
|
|
945
|
+
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;
|
|
946
|
+
const id = args.originalDoc?.id ?? args.id;
|
|
947
|
+
for (let n = 1; n <= 50; n++) {
|
|
948
|
+
const candidate = n === 1 ? base : `${base}-${n}`;
|
|
949
|
+
const found = await args.req.payload.find({
|
|
950
|
+
collection: args.collection.slug,
|
|
951
|
+
where: { and: [{ [name]: { equals: candidate } }, ...id !== void 0 && id !== null ? [{ id: { not_equals: id } }] : []] },
|
|
952
|
+
limit: 1,
|
|
953
|
+
depth: 0,
|
|
954
|
+
pagination: false,
|
|
955
|
+
locale: args.req.locale ?? void 0,
|
|
956
|
+
req: args.req,
|
|
957
|
+
overrideAccess: true
|
|
958
|
+
});
|
|
959
|
+
if (!found.docs.length) return candidate;
|
|
960
|
+
}
|
|
961
|
+
return base;
|
|
962
|
+
};
|
|
963
|
+
const consumerValidate = slugOverrides.validate;
|
|
964
|
+
const validate = (value, args) => {
|
|
965
|
+
const result = text2(value, args);
|
|
966
|
+
if (result !== true) return result;
|
|
967
|
+
return consumerValidate ? consumerValidate(value, args) : true;
|
|
968
|
+
};
|
|
969
|
+
const slug = {
|
|
970
|
+
...slugOverrides,
|
|
971
|
+
name,
|
|
972
|
+
type: "text",
|
|
973
|
+
index: unique ? true : slugOverrides.index,
|
|
974
|
+
unique,
|
|
975
|
+
validate,
|
|
976
|
+
localized,
|
|
977
|
+
admin: {
|
|
978
|
+
...slugOverrides.admin,
|
|
979
|
+
position: slugOverrides.admin?.position ?? "sidebar",
|
|
980
|
+
components: {
|
|
981
|
+
...slugOverrides.admin?.components,
|
|
982
|
+
Field: {
|
|
983
|
+
path: "@nexload-sdk/payload-fields/admin/slug-field#SlugFieldComponent",
|
|
984
|
+
clientProps: { source, lockName, generator: options.generator }
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
},
|
|
988
|
+
custom: { ...slugOverrides.custom, nexload: { ...slugOverrides.custom?.nexload, slug: { source, lockName, generator: options.generator } } },
|
|
989
|
+
hooks: {
|
|
990
|
+
...slugOverrides.hooks,
|
|
991
|
+
beforeValidate: [
|
|
992
|
+
...consumerHooks,
|
|
993
|
+
normalize
|
|
994
|
+
]
|
|
995
|
+
}
|
|
996
|
+
};
|
|
997
|
+
const lock = {
|
|
998
|
+
...lockOverrides,
|
|
999
|
+
name: lockName,
|
|
1000
|
+
type: "checkbox",
|
|
1001
|
+
localized,
|
|
1002
|
+
defaultValue: true,
|
|
1003
|
+
admin: { ...lockOverrides.admin, hidden: true, position: lockOverrides.admin?.position ?? "sidebar" }
|
|
1004
|
+
};
|
|
1005
|
+
return [
|
|
1006
|
+
slug,
|
|
1007
|
+
lock
|
|
1008
|
+
];
|
|
1009
|
+
}
|
|
1010
|
+
export {
|
|
1011
|
+
IRR,
|
|
1012
|
+
IRT,
|
|
1013
|
+
PAYLOAD_FIELDS_PLUGIN_ORDER,
|
|
1014
|
+
bankCardField,
|
|
1015
|
+
formatJalaliDate,
|
|
1016
|
+
formatMoney,
|
|
1017
|
+
formatSlug,
|
|
1018
|
+
formatSlugHook,
|
|
1019
|
+
iranAddressField,
|
|
1020
|
+
iranLandlineField,
|
|
1021
|
+
iranMobileField,
|
|
1022
|
+
jalaliDateField,
|
|
1023
|
+
jalaliDateRangeField,
|
|
1024
|
+
legalIdField,
|
|
1025
|
+
ltrTextField,
|
|
1026
|
+
moneyField,
|
|
1027
|
+
nationalCodeField,
|
|
1028
|
+
parseMoneyToMinorUnits,
|
|
1029
|
+
payloadFieldsPlugin,
|
|
1030
|
+
postalCodeField,
|
|
1031
|
+
resolveCurrency,
|
|
1032
|
+
shebaField,
|
|
1033
|
+
slugField,
|
|
1034
|
+
sortOrderField,
|
|
1035
|
+
toStoredJalaliInstant,
|
|
1036
|
+
withJalaliTimestamps
|
|
1037
|
+
};
|
|
1038
|
+
//# sourceMappingURL=index.js.map
|