@marmot-systems/common 2.0.21 → 2.0.23
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/dist/index.cjs +77 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +137 -6
- package/dist/index.d.ts +137 -6
- package/dist/index.js +72 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,11 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AnyInvoiceSchema: () => AnyInvoiceSchema,
|
|
24
|
+
CREDIT_TYPE: () => CREDIT_TYPE,
|
|
25
|
+
CreditInvoiceSchema: () => CreditInvoiceSchema,
|
|
23
26
|
CustomerFormSchema: () => CustomerFormSchema,
|
|
24
27
|
INVOICE_STATUS: () => INVOICE_STATUS,
|
|
25
28
|
INVOICE_TYPE: () => INVOICE_TYPE,
|
|
26
29
|
ProductFormSchema: () => ProductFormSchema,
|
|
30
|
+
PurchaseInvoiceSchema: () => PurchaseInvoiceSchema,
|
|
27
31
|
RegisterFormSchema: () => RegisterFormSchema,
|
|
32
|
+
SalesInvoiceSchema: () => SalesInvoiceSchema,
|
|
28
33
|
formatMoneyCurrency: () => formatMoneyCurrency,
|
|
29
34
|
getCurrencyFromCountry: () => getCurrencyFromCountry,
|
|
30
35
|
handleZodCurrency: () => handleZodCurrency,
|
|
@@ -202,20 +207,88 @@ var ProductFormSchema = import_zod4.z.strictObject({
|
|
|
202
207
|
}
|
|
203
208
|
});
|
|
204
209
|
|
|
205
|
-
// src/types/invoices_types.ts
|
|
206
|
-
var INVOICE_TYPE = ["sales", "credit", "purchase"];
|
|
207
|
-
var INVOICE_STATUS = ["finalized", "voided"];
|
|
208
|
-
|
|
209
210
|
// src/types/shared_types.ts
|
|
210
211
|
var import_zod5 = require("zod");
|
|
211
212
|
var uuidSchema = import_zod5.z.uuid();
|
|
213
|
+
|
|
214
|
+
// src/domains/invoices/invoices_schemas.ts
|
|
215
|
+
var import_zod6 = require("zod");
|
|
216
|
+
|
|
217
|
+
// src/domains/invoices/invoices_types.ts
|
|
218
|
+
var INVOICE_TYPE = ["sales", "credit", "purchase"];
|
|
219
|
+
var INVOICE_STATUS = ["finalized", "voided"];
|
|
220
|
+
var CREDIT_TYPE = ["dump", "return"];
|
|
221
|
+
|
|
222
|
+
// src/domains/invoices/invoices_schemas.ts
|
|
223
|
+
var YmdDateSchema = import_zod6.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Use YYYY-MM-DD");
|
|
224
|
+
var BaseInvoice = import_zod6.z.object({
|
|
225
|
+
invoice_type: import_zod6.z.enum(INVOICE_TYPE, { error: "Invoice type not found." }),
|
|
226
|
+
invoice_date: YmdDateSchema,
|
|
227
|
+
due_date: YmdDateSchema,
|
|
228
|
+
tax_rate: import_zod6.z.number().default(0),
|
|
229
|
+
tax_amount: import_zod6.z.number().default(0),
|
|
230
|
+
warehouse_id: import_zod6.z.uuid().optional(),
|
|
231
|
+
invoice_status: import_zod6.z.enum(INVOICE_STATUS).default("finalized")
|
|
232
|
+
}).superRefine(({ invoice_date, due_date }, ctx) => {
|
|
233
|
+
if (due_date < invoice_date) {
|
|
234
|
+
ctx.addIssue({
|
|
235
|
+
code: "custom",
|
|
236
|
+
message: "Due date can't be earlier than the invoice date.",
|
|
237
|
+
path: ["due_date"]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
var LineItemBase = import_zod6.z.object({
|
|
242
|
+
invoice_id: import_zod6.z.uuid().optional(),
|
|
243
|
+
product_id: import_zod6.z.uuid({ error: "Select a product" }),
|
|
244
|
+
quantity: handleZodCurrency(0.01, 99999.99)
|
|
245
|
+
});
|
|
246
|
+
var SalesItem = LineItemBase.safeExtend({
|
|
247
|
+
price: handleZodCurrency(0, 99999.99),
|
|
248
|
+
credit_type: import_zod6.z.undefined()
|
|
249
|
+
});
|
|
250
|
+
var CreditItem = LineItemBase.safeExtend({
|
|
251
|
+
price: handleZodCurrency(0, 99999.99),
|
|
252
|
+
credit_type: import_zod6.z.enum(CREDIT_TYPE, {
|
|
253
|
+
error: "Select a credit type"
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
var PurchaseItem = LineItemBase.safeExtend({
|
|
257
|
+
price: handleZodCurrency(0, 99999.99),
|
|
258
|
+
credit_type: import_zod6.z.undefined()
|
|
259
|
+
});
|
|
260
|
+
var SalesInvoiceSchema = BaseInvoice.safeExtend({
|
|
261
|
+
invoice_type: import_zod6.z.literal("sales"),
|
|
262
|
+
party_id: import_zod6.z.uuid({ message: "Select a customer" }),
|
|
263
|
+
invoice_items: import_zod6.z.array(SalesItem).min(1, "Add at least one invoice item")
|
|
264
|
+
});
|
|
265
|
+
var CreditInvoiceSchema = BaseInvoice.safeExtend({
|
|
266
|
+
invoice_type: import_zod6.z.literal("credit"),
|
|
267
|
+
party_id: import_zod6.z.uuid({ message: "Select a customer" }),
|
|
268
|
+
invoice_items: import_zod6.z.array(CreditItem).min(1, "Add at least one invoice item")
|
|
269
|
+
});
|
|
270
|
+
var PurchaseInvoiceSchema = BaseInvoice.safeExtend({
|
|
271
|
+
invoice_type: import_zod6.z.literal("purchase"),
|
|
272
|
+
party_id: import_zod6.z.uuid({ message: "Select a vendor" }),
|
|
273
|
+
invoice_items: import_zod6.z.array(PurchaseItem).min(1, "Add at least one invoice item")
|
|
274
|
+
});
|
|
275
|
+
var AnyInvoiceSchema = import_zod6.z.discriminatedUnion("invoice_type", [
|
|
276
|
+
SalesInvoiceSchema,
|
|
277
|
+
PurchaseInvoiceSchema,
|
|
278
|
+
CreditInvoiceSchema
|
|
279
|
+
]);
|
|
212
280
|
// Annotate the CommonJS export names for ESM import in node:
|
|
213
281
|
0 && (module.exports = {
|
|
282
|
+
AnyInvoiceSchema,
|
|
283
|
+
CREDIT_TYPE,
|
|
284
|
+
CreditInvoiceSchema,
|
|
214
285
|
CustomerFormSchema,
|
|
215
286
|
INVOICE_STATUS,
|
|
216
287
|
INVOICE_TYPE,
|
|
217
288
|
ProductFormSchema,
|
|
289
|
+
PurchaseInvoiceSchema,
|
|
218
290
|
RegisterFormSchema,
|
|
291
|
+
SalesInvoiceSchema,
|
|
219
292
|
formatMoneyCurrency,
|
|
220
293
|
getCurrencyFromCountry,
|
|
221
294
|
handleZodCurrency,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/schemas/companies_schemas.ts","../src/types/company_types.ts","../src/utils/types.ts","../src/utils/utils.ts","../src/schemas/customer_schemas.ts","../src/schemas/product_schemas.ts","../src/types/invoices_types.ts","../src/types/shared_types.ts"],"sourcesContent":["export * from \"./schemas/companies_schemas\";\nexport * from \"./schemas/customer_schemas\";\nexport * from \"./schemas/product_schemas\";\nexport * from \"./utils/utils\";\nexport {\n UserRole,\n IsoCountryCode,\n InventorySystem,\n} from \"./types/company_types\";\nexport * from \"./types/invoices_types\";\nexport { CreatedLocation, UUID } from \"./types/shared_types\";\nexport { SyncInvoice } from \"./types/sync_types\";\nexport * from \"./types/customers_types\";\nexport * from \"./types/vendors_types\";\n","import { z } from \"zod\";\nimport { ISO_COUNTRY_CODES, USER_ROLES } from \"../types/company_types\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nconst iso_country_code = z.enum(ISO_COUNTRY_CODES, {\n error: \"Country code not supported.\",\n});\n\nconst user_role = z.enum(USER_ROLES, {\n error: \"User role not supported.\",\n});\n\nexport const RegisterFormSchema = z.strictObject({\n companyData: z.strictObject({\n company_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company name is required\")\n .max(50, \"Company name must be at most 50 characters.\")\n ),\n company_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company address is required\")\n .max(100, \"Company address must be at most 100 characters.\")\n ),\n company_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => /^\\d{4,15}$/.test(s), {\n error: \"Phone number required and must be from 4 to 15 digits.\",\n }),\n iso_country_code: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform((s) => s.toUpperCase())\n .pipe(iso_country_code),\n }),\n adminUserData: z.strictObject({\n user_first_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"First name is required\")\n .max(50, \"First name must be at most 50 characters.\")\n ),\n user_last_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Last name is required\")\n .max(50, \"Last name must be at most 50 characters.\")\n ),\n user_email: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n ),\n password: z\n .string()\n .min(8, \"Password must be at least 8 characters\")\n .max(25, \"Password must be at most 25 characters\")\n .regex(/[A-Z]/, \"Password must contain at least one uppercase letter\")\n .regex(/[a-z]/, \"Password must contain at least one lowercase letter\")\n .regex(/\\d/, \"Password must contain at least one number\")\n .regex(\n /[@$!%*?&#^_+=-]/,\n \"Password must contain at least one special character\"\n )\n .regex(/^\\S*$/, \"Password cannot contain spaces or other whitespace.\"),\n }),\n});\n","export const ISO_COUNTRY_CODES = [\"US\", \"HN\"] as const;\n\nexport type IsoCountryCode = (typeof ISO_COUNTRY_CODES)[number];\n\nexport const USER_ROLES = [\"admin\", \"driver\"] as const;\n\nexport type UserRole = (typeof USER_ROLES)[number];\n\nexport type InventorySystem = \"warehouse_only\" | \"dsd\";\n","import { IsoCountryCode } from \"../types/company_types\";\n\ntype RoundType = \"half_up\";\n\nexport interface ToFixedOptions {\n roundType?: RoundType;\n}\n\nexport type WhitespaceMode = \"normalize\" | \"remove\";\n\nexport type IsoCurrencyCode = \"USD\" | \"HNL\";\n\nexport const countryToCurrency: Record<IsoCountryCode, IsoCurrencyCode> = {\n US: \"USD\",\n HN: \"HNL\",\n};\n","import * as GlobalTypes from \"./types\";\nimport { IsoCountryCode } from \"../types/company_types\";\n\nimport { z } from \"zod\";\n\n/**\n * Validates zod currency with precision.\n *\n *\n * @param minAmount\n * @param maxAmount\n * @returns\n */\nexport function handleZodCurrency(minAmount: number, maxAmount: number) {\n const fromString = z\n .string({\n error: \"Enter a valid number\",\n })\n .refine((s) => s.trim().length > 0, { error: \"Enter a valid number\" })\n .transform((s) => s.replace(/[,\\s]/g, \"\"))\n .refine((s) => s !== \"\" && !Number.isNaN(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number.isFinite(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number(s) >= 0, { error: \"Enter a positive number\" })\n .transform((s) => Number(s));\n\n const fromNumber = z\n .number()\n .refine((n) => Number.isFinite(n), { error: \"Enter a valid number\" })\n .refine((n) => n >= 0, { error: \"Enter a positive number\" });\n\n return z\n .union([fromString, fromNumber])\n .transform((n) => roundWithPrecision(n, 2))\n .refine((n) => n >= minAmount, {\n error: `Must be greater than ${minAmount}`,\n })\n .refine((n) => n <= maxAmount, {\n error: `Exceeds allowed limit ${maxAmount}`,\n });\n}\n\n/**\n * Trims any leading or trailing spaces\n * Transforms empty strings into undefined.\n *\n * @param s\n * @returns\n */\nexport const transformEmptyStringToUndefined = (s: string) =>\n s.trim() === \"\" ? undefined : s;\n\n/**\n * - Collapses any run of whitespace in a string (spaces, tabs, newlines, nbspb, and other weird unicode spaces etc.)\n * into a single ASCII space.\n * - Trims leading and trailing whitespace.\n * \" Jared \\n Gomez \\t Driver\\t \" -> \"Jared Gomez Driver\"\n *\n * @param s\n * @returns\n */\nexport const normalizeSpaces = (s: string) => whitespace(s, \"normalize\");\n\n/**\n * Removes all whitespace from a string\n * @param s\n * @returns\n */\nexport const removeAllWhitespace = (s: string) => whitespace(s, \"remove\");\n\nconst whitespace = (s: string, mode: GlobalTypes.WhitespaceMode) => {\n if (mode === \"remove\") {\n return s.replace(/\\s+/g, \"\");\n }\n\n return s.replace(/\\s+/g, \" \").trim();\n};\n\n/**\n * Removes all dashes and + signs from a string\n * +1-305-555-0123 -> \"13055550123\"\n * 305-555-0123 -> \"3055550123\"\n *\n * @param s\n * @returns\n */\nexport const removeDashesAndPlusSign = (s: string): string =>\n s.replace(/[+-]/g, \"\");\n\n/**\n * Rounds a number to a certain precision.\n * Contract:\n * 1. Number must be finite and non negative.\n * 2. Precision must be finite nonnegative and an integer.\n * 3. Precision must be <= Max precision\n * 4. Returns a number >= 0\n * Default is round half up.\n *\n * @param num\n * @param precision\n * @param opts\n * @returns\n */\nexport function roundWithPrecision(\n num: number,\n precision: number,\n opts?: GlobalTypes.ToFixedOptions\n): number {\n const MAX_PRECISION = 2;\n const { roundType = \"half_up\" } = opts ?? {};\n\n if (!Number.isFinite(num) || num < 0) {\n throw new RangeError(\"Number must be finite and greater than 0.\");\n }\n\n if (\n !Number.isFinite(precision) ||\n !Number.isInteger(precision) ||\n precision < 1\n ) {\n throw new RangeError(\"Precision must be a finite integer greater than 0.\");\n }\n\n if (precision > MAX_PRECISION) {\n throw new RangeError(\"Max precision allowed is 2.\");\n }\n\n return Number(\n (+(Math.round(+(num + \"e\" + precision)) + \"e\" + -precision)).toFixed(\n precision\n )\n );\n}\n\nexport function getCurrencyFromCountry(\n country: IsoCountryCode\n): GlobalTypes.IsoCurrencyCode {\n return GlobalTypes.countryToCurrency[country];\n}\n\nexport function formatMoneyCurrency(\n value: number,\n cur: GlobalTypes.IsoCurrencyCode\n) {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: cur,\n }).format(value);\n}\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const CustomerFormSchema = z.strictObject({\n customer_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Customer name is required\")\n .max(50, \"Customer name must be at most 50 characters.\")\n ),\n\n customer_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z.string().max(100, \"Customer address must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => s === \"\" || /^\\d{4,15}$/.test(s), {\n error: \"Phone number must be from 4 to 15 digits.\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_email_address: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n .optional()\n )\n .optional(),\n\n tax_rate: GlobalUtils.handleZodCurrency(0, 100),\n});\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const ProductFormSchema = z\n .strictObject({\n product_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Product name is required\")\n .max(50, \"Product name must be at most 50 characters.\")\n ),\n\n product_description: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .max(100, \"Product desription must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_sku: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(z.string().max(30, \"Product SKU must be at most 30 characters.\"))\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_upc: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{12}$/.test(s), {\n error: \"UPC must be exactly 12 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_gtin_14: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{14}$/.test(s), {\n error: \"GTIN14 must be exactly 14 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_type: z.enum([\"unit\", \"weight\", \"case\"], {\n error: \"Product type must be unit, weight, or case.\",\n }),\n\n weight_unit: z.preprocess((v) => {\n if (v === \"\") return undefined;\n if (typeof v === \"string\") return v.trim().toLowerCase();\n return v;\n }, z.enum([\"kg\", \"lb\", \"g\", \"oz\"]).optional()),\n\n price: GlobalUtils.handleZodCurrency(0, 99_999.99),\n cost: GlobalUtils.handleZodCurrency(0, 99_999.99),\n })\n\n .superRefine((data, ctx) => {\n if (data.product_type === \"weight\" && !data.weight_unit) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit is required.\",\n path: [\"weight_unit\"],\n });\n }\n\n if (\n data.product_type !== \"weight\" &&\n typeof data.weight_unit !== \"undefined\"\n ) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit must be empty\",\n path: [\"weight_unit\"],\n });\n }\n });\n","export const INVOICE_TYPE = [\"sales\", \"credit\", \"purchase\"] as const;\n\nexport type InvoiceType = (typeof INVOICE_TYPE)[number];\n\nexport const INVOICE_STATUS = [\"finalized\", \"voided\"] as const;\n\nexport type InvoiceStatus = (typeof INVOICE_STATUS)[number];\n","import { z } from \"zod\";\n\nexport const CREATED_LOCATION = [\"web\", \"mobile\"] as const;\n\nexport type CreatedLocation = (typeof CREATED_LOCATION)[number];\n\nexport type IntBool = 0 | 1;\n\nexport const uuidSchema = z.uuid();\nexport type UUID = z.infer<typeof uuidSchema>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAkB;;;ACAX,I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,gBAAgB,aAC5B;AACA,QAAI,SAAS;AAAA,MACX,MAAM;AAAA,MACN,OAAO;AAAA,MACP,MAAM,CAAC,aAAa;AAAA,IACtB,CAAC;AAAA,EACH;AACF,CAAC;;;ACpFI,IAAM,eAAe,CAAC,SAAS,UAAU,UAAU;AAInD,IAAM,iBAAiB,CAAC,aAAa,QAAQ;;;ACJpD,IAAAC,cAAkB;AAQX,IAAM,aAAa,cAAE,KAAK;","names":["import_zod","import_zod","import_zod","import_zod"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/schemas/companies_schemas.ts","../src/types/company_types.ts","../src/utils/types.ts","../src/utils/utils.ts","../src/schemas/customer_schemas.ts","../src/schemas/product_schemas.ts","../src/types/shared_types.ts","../src/domains/invoices/invoices_schemas.ts","../src/domains/invoices/invoices_types.ts"],"sourcesContent":["export * from \"./schemas/companies_schemas\";\nexport * from \"./schemas/customer_schemas\";\nexport * from \"./schemas/product_schemas\";\nexport * from \"./utils/utils\";\nexport {\n UserRole,\n IsoCountryCode,\n InventorySystem,\n} from \"./types/company_types\";\nexport { CreatedLocation, UUID } from \"./types/shared_types\";\nexport { SyncInvoice } from \"./types/sync_types\";\nexport * from \"./types/customers_types\";\nexport * from \"./types/vendors_types\";\nexport * from \"./domains/invoices/invoices_schemas\";\nexport * from \"./domains/invoices/invoices_types\";\n","import { z } from \"zod\";\nimport { ISO_COUNTRY_CODES, USER_ROLES } from \"../types/company_types\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nconst iso_country_code = z.enum(ISO_COUNTRY_CODES, {\n error: \"Country code not supported.\",\n});\n\nconst user_role = z.enum(USER_ROLES, {\n error: \"User role not supported.\",\n});\n\nexport const RegisterFormSchema = z.strictObject({\n companyData: z.strictObject({\n company_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company name is required\")\n .max(50, \"Company name must be at most 50 characters.\")\n ),\n company_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company address is required\")\n .max(100, \"Company address must be at most 100 characters.\")\n ),\n company_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => /^\\d{4,15}$/.test(s), {\n error: \"Phone number required and must be from 4 to 15 digits.\",\n }),\n iso_country_code: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform((s) => s.toUpperCase())\n .pipe(iso_country_code),\n }),\n adminUserData: z.strictObject({\n user_first_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"First name is required\")\n .max(50, \"First name must be at most 50 characters.\")\n ),\n user_last_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Last name is required\")\n .max(50, \"Last name must be at most 50 characters.\")\n ),\n user_email: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n ),\n password: z\n .string()\n .min(8, \"Password must be at least 8 characters\")\n .max(25, \"Password must be at most 25 characters\")\n .regex(/[A-Z]/, \"Password must contain at least one uppercase letter\")\n .regex(/[a-z]/, \"Password must contain at least one lowercase letter\")\n .regex(/\\d/, \"Password must contain at least one number\")\n .regex(\n /[@$!%*?&#^_+=-]/,\n \"Password must contain at least one special character\"\n )\n .regex(/^\\S*$/, \"Password cannot contain spaces or other whitespace.\"),\n }),\n});\n","export const ISO_COUNTRY_CODES = [\"US\", \"HN\"] as const;\n\nexport type IsoCountryCode = (typeof ISO_COUNTRY_CODES)[number];\n\nexport const USER_ROLES = [\"admin\", \"driver\"] as const;\n\nexport type UserRole = (typeof USER_ROLES)[number];\n\nexport type InventorySystem = \"warehouse_only\" | \"dsd\";\n","import { IsoCountryCode } from \"../types/company_types\";\n\ntype RoundType = \"half_up\";\n\nexport interface ToFixedOptions {\n roundType?: RoundType;\n}\n\nexport type WhitespaceMode = \"normalize\" | \"remove\";\n\nexport type IsoCurrencyCode = \"USD\" | \"HNL\";\n\nexport const countryToCurrency: Record<IsoCountryCode, IsoCurrencyCode> = {\n US: \"USD\",\n HN: \"HNL\",\n};\n","import * as GlobalTypes from \"./types\";\nimport { IsoCountryCode } from \"../types/company_types\";\n\nimport { z } from \"zod\";\n\n/**\n * Validates zod currency with precision.\n *\n *\n * @param minAmount\n * @param maxAmount\n * @returns\n */\nexport function handleZodCurrency(minAmount: number, maxAmount: number) {\n const fromString = z\n .string({\n error: \"Enter a valid number\",\n })\n .refine((s) => s.trim().length > 0, { error: \"Enter a valid number\" })\n .transform((s) => s.replace(/[,\\s]/g, \"\"))\n .refine((s) => s !== \"\" && !Number.isNaN(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number.isFinite(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number(s) >= 0, { error: \"Enter a positive number\" })\n .transform((s) => Number(s));\n\n const fromNumber = z\n .number()\n .refine((n) => Number.isFinite(n), { error: \"Enter a valid number\" })\n .refine((n) => n >= 0, { error: \"Enter a positive number\" });\n\n return z\n .union([fromString, fromNumber])\n .transform((n) => roundWithPrecision(n, 2))\n .refine((n) => n >= minAmount, {\n error: `Must be greater than ${minAmount}`,\n })\n .refine((n) => n <= maxAmount, {\n error: `Exceeds allowed limit ${maxAmount}`,\n });\n}\n\n/**\n * Trims any leading or trailing spaces\n * Transforms empty strings into undefined.\n *\n * @param s\n * @returns\n */\nexport const transformEmptyStringToUndefined = (s: string) =>\n s.trim() === \"\" ? undefined : s;\n\n/**\n * - Collapses any run of whitespace in a string (spaces, tabs, newlines, nbspb, and other weird unicode spaces etc.)\n * into a single ASCII space.\n * - Trims leading and trailing whitespace.\n * \" Jared \\n Gomez \\t Driver\\t \" -> \"Jared Gomez Driver\"\n *\n * @param s\n * @returns\n */\nexport const normalizeSpaces = (s: string) => whitespace(s, \"normalize\");\n\n/**\n * Removes all whitespace from a string\n * @param s\n * @returns\n */\nexport const removeAllWhitespace = (s: string) => whitespace(s, \"remove\");\n\nconst whitespace = (s: string, mode: GlobalTypes.WhitespaceMode) => {\n if (mode === \"remove\") {\n return s.replace(/\\s+/g, \"\");\n }\n\n return s.replace(/\\s+/g, \" \").trim();\n};\n\n/**\n * Removes all dashes and + signs from a string\n * +1-305-555-0123 -> \"13055550123\"\n * 305-555-0123 -> \"3055550123\"\n *\n * @param s\n * @returns\n */\nexport const removeDashesAndPlusSign = (s: string): string =>\n s.replace(/[+-]/g, \"\");\n\n/**\n * Rounds a number to a certain precision.\n * Contract:\n * 1. Number must be finite and non negative.\n * 2. Precision must be finite nonnegative and an integer.\n * 3. Precision must be <= Max precision\n * 4. Returns a number >= 0\n * Default is round half up.\n *\n * @param num\n * @param precision\n * @param opts\n * @returns\n */\nexport function roundWithPrecision(\n num: number,\n precision: number,\n opts?: GlobalTypes.ToFixedOptions\n): number {\n const MAX_PRECISION = 2;\n const { roundType = \"half_up\" } = opts ?? {};\n\n if (!Number.isFinite(num) || num < 0) {\n throw new RangeError(\"Number must be finite and greater than 0.\");\n }\n\n if (\n !Number.isFinite(precision) ||\n !Number.isInteger(precision) ||\n precision < 1\n ) {\n throw new RangeError(\"Precision must be a finite integer greater than 0.\");\n }\n\n if (precision > MAX_PRECISION) {\n throw new RangeError(\"Max precision allowed is 2.\");\n }\n\n return Number(\n (+(Math.round(+(num + \"e\" + precision)) + \"e\" + -precision)).toFixed(\n precision\n )\n );\n}\n\nexport function getCurrencyFromCountry(\n country: IsoCountryCode\n): GlobalTypes.IsoCurrencyCode {\n return GlobalTypes.countryToCurrency[country];\n}\n\nexport function formatMoneyCurrency(\n value: number,\n cur: GlobalTypes.IsoCurrencyCode\n) {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: cur,\n }).format(value);\n}\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const CustomerFormSchema = z.strictObject({\n customer_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Customer name is required\")\n .max(50, \"Customer name must be at most 50 characters.\")\n ),\n\n customer_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z.string().max(100, \"Customer address must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => s === \"\" || /^\\d{4,15}$/.test(s), {\n error: \"Phone number must be from 4 to 15 digits.\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_email_address: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n .optional()\n )\n .optional(),\n\n tax_rate: GlobalUtils.handleZodCurrency(0, 100),\n});\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const ProductFormSchema = z\n .strictObject({\n product_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Product name is required\")\n .max(50, \"Product name must be at most 50 characters.\")\n ),\n\n product_description: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .max(100, \"Product desription must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_sku: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(z.string().max(30, \"Product SKU must be at most 30 characters.\"))\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_upc: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{12}$/.test(s), {\n error: \"UPC must be exactly 12 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_gtin_14: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{14}$/.test(s), {\n error: \"GTIN14 must be exactly 14 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_type: z.enum([\"unit\", \"weight\", \"case\"], {\n error: \"Product type must be unit, weight, or case.\",\n }),\n\n weight_unit: z.preprocess((v) => {\n if (v === \"\") return undefined;\n if (typeof v === \"string\") return v.trim().toLowerCase();\n return v;\n }, z.enum([\"kg\", \"lb\", \"g\", \"oz\"]).optional()),\n\n price: GlobalUtils.handleZodCurrency(0, 99_999.99),\n cost: GlobalUtils.handleZodCurrency(0, 99_999.99),\n })\n\n .superRefine((data, ctx) => {\n if (data.product_type === \"weight\" && !data.weight_unit) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit is required.\",\n path: [\"weight_unit\"],\n });\n }\n\n if (\n data.product_type !== \"weight\" &&\n typeof data.weight_unit !== \"undefined\"\n ) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit must be empty\",\n path: [\"weight_unit\"],\n });\n }\n });\n","import { z } from \"zod\";\n\nexport const CREATED_LOCATION = [\"web\", \"mobile\"] as const;\n\nexport type CreatedLocation = (typeof CREATED_LOCATION)[number];\n\nexport type IntBool = 0 | 1;\n\nexport const uuidSchema = z.uuid();\nexport type UUID = z.infer<typeof uuidSchema>;\n","import { z } from \"zod\";\nimport { CREDIT_TYPE, INVOICE_STATUS, INVOICE_TYPE } from \"./invoices_types\";\nimport { handleZodCurrency } from \"../../utils/utils\";\n\nconst YmdDateSchema = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"Use YYYY-MM-DD\");\n\nconst BaseInvoice = z\n .object({\n invoice_type: z.enum(INVOICE_TYPE, { error: \"Invoice type not found.\" }),\n invoice_date: YmdDateSchema,\n due_date: YmdDateSchema,\n tax_rate: z.number().default(0),\n tax_amount: z.number().default(0),\n warehouse_id: z.uuid().optional(),\n invoice_status: z.enum(INVOICE_STATUS).default(\"finalized\"),\n })\n .superRefine(({ invoice_date, due_date }, ctx) => {\n if (due_date < invoice_date) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Due date can't be earlier than the invoice date.\",\n path: [\"due_date\"],\n });\n }\n });\n\nconst LineItemBase = z.object({\n invoice_id: z.uuid().optional(),\n product_id: z.uuid({ error: \"Select a product\" }),\n quantity: handleZodCurrency(0.01, 99_999.99),\n});\n\nconst SalesItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.undefined(),\n});\n\nconst CreditItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.enum(CREDIT_TYPE, {\n error: \"Select a credit type\",\n }),\n});\n\nconst PurchaseItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.undefined(),\n});\n\nexport const SalesInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"sales\"),\n party_id: z.uuid({ message: \"Select a customer\" }),\n invoice_items: z.array(SalesItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const CreditInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"credit\"),\n party_id: z.uuid({ message: \"Select a customer\" }),\n invoice_items: z.array(CreditItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const PurchaseInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"purchase\"),\n party_id: z.uuid({ message: \"Select a vendor\" }),\n invoice_items: z.array(PurchaseItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const AnyInvoiceSchema = z.discriminatedUnion(\"invoice_type\", [\n SalesInvoiceSchema,\n PurchaseInvoiceSchema,\n CreditInvoiceSchema,\n]);\n","import { z } from \"zod\";\nimport * as InvoiceSchemas from \"./invoices_schemas\";\n\nexport type SalesInvoice = z.infer<typeof InvoiceSchemas.SalesInvoiceSchema>;\nexport type CreditInvoice = z.infer<typeof InvoiceSchemas.CreditInvoiceSchema>;\nexport type PurchaseInvoice = z.infer<\n typeof InvoiceSchemas.PurchaseInvoiceSchema\n>;\nexport type AnyInvoiceOut = z.output<typeof InvoiceSchemas.AnyInvoiceSchema>;\n\nexport const INVOICE_TYPE = [\"sales\", \"credit\", \"purchase\"] as const;\n\nexport type InvoiceType = (typeof INVOICE_TYPE)[number];\n\nexport const INVOICE_STATUS = [\"finalized\", \"voided\"] as const;\n\nexport type InvoiceStatus = (typeof INVOICE_STATUS)[number];\n\nexport const CREDIT_TYPE = [\"dump\", \"return\"] as const;\n\nexport type CreditType = (typeof CREDIT_TYPE)[number];\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAkB;;;ACAX,IAAM,oBAAoB,CAAC,MAAM,IAAI;AAIrC,IAAM,aAAa,CAAC,SAAS,QAAQ;;;ACQrC,IAAM,oBAA6D;AAAA,EACxE,IAAI;AAAA,EACJ,IAAI;AACN;;;ACZA,iBAAkB;AAUX,SAAS,kBAAkB,WAAmB,WAAmB;AACtE,QAAM,aAAa,aAChB,OAAO;AAAA,IACN,OAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,EAAE,OAAO,uBAAuB,CAAC,EACpE,UAAU,CAAC,MAAM,EAAE,QAAQ,UAAU,EAAE,CAAC,EACxC,OAAO,CAAC,MAAM,MAAM,MAAM,CAAC,OAAO,MAAM,OAAO,CAAC,CAAC,GAAG;AAAA,IACnD,OAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,MAAM,OAAO,SAAS,OAAO,CAAC,CAAC,GAAG;AAAA,IACzC,OAAO;AAAA,EACT,CAAC,EACA,OAA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D,eAAe,cAAE,MAAM,UAAU,EAAE,IAAI,GAAG,+BAA+B;AAC3E,CAAC;AAEM,IAAM,wBAAwB,YAAY,WAAW;AAAA,EAC1D,cAAc,cAAE,QAAQ,UAAU;AAAA,EAClC,UAAU,cAAE,KAAK,EAAE,SAAS,kBAAkB,CAAC;AAAA,EAC/C,eAAe,cAAE,MAAM,YAAY,EAAE,IAAI,GAAG,+BAA+B;AAC7E,CAAC;AAEM,IAAM,mBAAmB,cAAE,mBAAmB,gBAAgB;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":["import_zod","import_zod","import_zod","import_zod","import_zod"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -119,17 +119,148 @@ declare function roundWithPrecision(num: number, precision: number, opts?: ToFix
|
|
|
119
119
|
declare function getCurrencyFromCountry(country: IsoCountryCode): IsoCurrencyCode;
|
|
120
120
|
declare function formatMoneyCurrency(value: number, cur: IsoCurrencyCode): string;
|
|
121
121
|
|
|
122
|
-
declare const INVOICE_TYPE: readonly ["sales", "credit", "purchase"];
|
|
123
|
-
type InvoiceType = (typeof INVOICE_TYPE)[number];
|
|
124
|
-
declare const INVOICE_STATUS: readonly ["finalized", "voided"];
|
|
125
|
-
type InvoiceStatus = (typeof INVOICE_STATUS)[number];
|
|
126
|
-
|
|
127
122
|
declare const CREATED_LOCATION: readonly ["web", "mobile"];
|
|
128
123
|
type CreatedLocation = (typeof CREATED_LOCATION)[number];
|
|
129
124
|
type IntBool = 0 | 1;
|
|
130
125
|
declare const uuidSchema: z.ZodUUID;
|
|
131
126
|
type UUID = z.infer<typeof uuidSchema>;
|
|
132
127
|
|
|
128
|
+
declare const SalesInvoiceSchema: z.ZodObject<{
|
|
129
|
+
invoice_date: z.ZodString;
|
|
130
|
+
due_date: z.ZodString;
|
|
131
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
132
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
133
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
134
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
135
|
+
finalized: "finalized";
|
|
136
|
+
voided: "voided";
|
|
137
|
+
}>>;
|
|
138
|
+
invoice_type: z.ZodLiteral<"sales">;
|
|
139
|
+
party_id: z.ZodUUID;
|
|
140
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
141
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
142
|
+
product_id: z.ZodUUID;
|
|
143
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
144
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
145
|
+
credit_type: z.ZodUndefined;
|
|
146
|
+
}, z.core.$strip>>;
|
|
147
|
+
}, z.core.$strip>;
|
|
148
|
+
declare const CreditInvoiceSchema: z.ZodObject<{
|
|
149
|
+
invoice_date: z.ZodString;
|
|
150
|
+
due_date: z.ZodString;
|
|
151
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
152
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
153
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
154
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
155
|
+
finalized: "finalized";
|
|
156
|
+
voided: "voided";
|
|
157
|
+
}>>;
|
|
158
|
+
invoice_type: z.ZodLiteral<"credit">;
|
|
159
|
+
party_id: z.ZodUUID;
|
|
160
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
161
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
162
|
+
product_id: z.ZodUUID;
|
|
163
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
164
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
165
|
+
credit_type: z.ZodEnum<{
|
|
166
|
+
dump: "dump";
|
|
167
|
+
return: "return";
|
|
168
|
+
}>;
|
|
169
|
+
}, z.core.$strip>>;
|
|
170
|
+
}, z.core.$strip>;
|
|
171
|
+
declare const PurchaseInvoiceSchema: z.ZodObject<{
|
|
172
|
+
invoice_date: z.ZodString;
|
|
173
|
+
due_date: z.ZodString;
|
|
174
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
175
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
176
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
177
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
178
|
+
finalized: "finalized";
|
|
179
|
+
voided: "voided";
|
|
180
|
+
}>>;
|
|
181
|
+
invoice_type: z.ZodLiteral<"purchase">;
|
|
182
|
+
party_id: z.ZodUUID;
|
|
183
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
184
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
185
|
+
product_id: z.ZodUUID;
|
|
186
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
187
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
188
|
+
credit_type: z.ZodUndefined;
|
|
189
|
+
}, z.core.$strip>>;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
declare const AnyInvoiceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
192
|
+
invoice_date: z.ZodString;
|
|
193
|
+
due_date: z.ZodString;
|
|
194
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
195
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
196
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
197
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
198
|
+
finalized: "finalized";
|
|
199
|
+
voided: "voided";
|
|
200
|
+
}>>;
|
|
201
|
+
invoice_type: z.ZodLiteral<"sales">;
|
|
202
|
+
party_id: z.ZodUUID;
|
|
203
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
204
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
205
|
+
product_id: z.ZodUUID;
|
|
206
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
207
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
208
|
+
credit_type: z.ZodUndefined;
|
|
209
|
+
}, z.core.$strip>>;
|
|
210
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
211
|
+
invoice_date: z.ZodString;
|
|
212
|
+
due_date: z.ZodString;
|
|
213
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
214
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
215
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
216
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
217
|
+
finalized: "finalized";
|
|
218
|
+
voided: "voided";
|
|
219
|
+
}>>;
|
|
220
|
+
invoice_type: z.ZodLiteral<"purchase">;
|
|
221
|
+
party_id: z.ZodUUID;
|
|
222
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
223
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
224
|
+
product_id: z.ZodUUID;
|
|
225
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
226
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
227
|
+
credit_type: z.ZodUndefined;
|
|
228
|
+
}, z.core.$strip>>;
|
|
229
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
230
|
+
invoice_date: z.ZodString;
|
|
231
|
+
due_date: z.ZodString;
|
|
232
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
233
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
234
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
235
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
236
|
+
finalized: "finalized";
|
|
237
|
+
voided: "voided";
|
|
238
|
+
}>>;
|
|
239
|
+
invoice_type: z.ZodLiteral<"credit">;
|
|
240
|
+
party_id: z.ZodUUID;
|
|
241
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
242
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
243
|
+
product_id: z.ZodUUID;
|
|
244
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
245
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
246
|
+
credit_type: z.ZodEnum<{
|
|
247
|
+
dump: "dump";
|
|
248
|
+
return: "return";
|
|
249
|
+
}>;
|
|
250
|
+
}, z.core.$strip>>;
|
|
251
|
+
}, z.core.$strip>], "invoice_type">;
|
|
252
|
+
|
|
253
|
+
type SalesInvoice = z.infer<typeof SalesInvoiceSchema>;
|
|
254
|
+
type CreditInvoice = z.infer<typeof CreditInvoiceSchema>;
|
|
255
|
+
type PurchaseInvoice = z.infer<typeof PurchaseInvoiceSchema>;
|
|
256
|
+
type AnyInvoiceOut = z.output<typeof AnyInvoiceSchema>;
|
|
257
|
+
declare const INVOICE_TYPE: readonly ["sales", "credit", "purchase"];
|
|
258
|
+
type InvoiceType = (typeof INVOICE_TYPE)[number];
|
|
259
|
+
declare const INVOICE_STATUS: readonly ["finalized", "voided"];
|
|
260
|
+
type InvoiceStatus = (typeof INVOICE_STATUS)[number];
|
|
261
|
+
declare const CREDIT_TYPE: readonly ["dump", "return"];
|
|
262
|
+
type CreditType = (typeof CREDIT_TYPE)[number];
|
|
263
|
+
|
|
133
264
|
type SyncInvoice = {
|
|
134
265
|
invoice_id: UUID;
|
|
135
266
|
invoice_type: InvoiceType;
|
|
@@ -166,4 +297,4 @@ type MappedVendors = {
|
|
|
166
297
|
tax_rate: number;
|
|
167
298
|
};
|
|
168
299
|
|
|
169
|
-
export { type CreatedLocation, CustomerFormSchema, INVOICE_STATUS, INVOICE_TYPE, type InventorySystem, type InvoiceStatus, type InvoiceType, type IsoCountryCode, type MappedCustomers, type MappedVendors, ProductFormSchema, RegisterFormSchema, type SyncInvoice, type UUID, type UserRole, formatMoneyCurrency, getCurrencyFromCountry, handleZodCurrency, normalizeSpaces, removeAllWhitespace, removeDashesAndPlusSign, roundWithPrecision, transformEmptyStringToUndefined };
|
|
300
|
+
export { type AnyInvoiceOut, AnyInvoiceSchema, CREDIT_TYPE, type CreatedLocation, type CreditInvoice, CreditInvoiceSchema, type CreditType, CustomerFormSchema, INVOICE_STATUS, INVOICE_TYPE, type InventorySystem, type InvoiceStatus, type InvoiceType, type IsoCountryCode, type MappedCustomers, type MappedVendors, ProductFormSchema, type PurchaseInvoice, PurchaseInvoiceSchema, RegisterFormSchema, type SalesInvoice, SalesInvoiceSchema, type SyncInvoice, type UUID, type UserRole, formatMoneyCurrency, getCurrencyFromCountry, handleZodCurrency, normalizeSpaces, removeAllWhitespace, removeDashesAndPlusSign, roundWithPrecision, transformEmptyStringToUndefined };
|
package/dist/index.d.ts
CHANGED
|
@@ -119,17 +119,148 @@ declare function roundWithPrecision(num: number, precision: number, opts?: ToFix
|
|
|
119
119
|
declare function getCurrencyFromCountry(country: IsoCountryCode): IsoCurrencyCode;
|
|
120
120
|
declare function formatMoneyCurrency(value: number, cur: IsoCurrencyCode): string;
|
|
121
121
|
|
|
122
|
-
declare const INVOICE_TYPE: readonly ["sales", "credit", "purchase"];
|
|
123
|
-
type InvoiceType = (typeof INVOICE_TYPE)[number];
|
|
124
|
-
declare const INVOICE_STATUS: readonly ["finalized", "voided"];
|
|
125
|
-
type InvoiceStatus = (typeof INVOICE_STATUS)[number];
|
|
126
|
-
|
|
127
122
|
declare const CREATED_LOCATION: readonly ["web", "mobile"];
|
|
128
123
|
type CreatedLocation = (typeof CREATED_LOCATION)[number];
|
|
129
124
|
type IntBool = 0 | 1;
|
|
130
125
|
declare const uuidSchema: z.ZodUUID;
|
|
131
126
|
type UUID = z.infer<typeof uuidSchema>;
|
|
132
127
|
|
|
128
|
+
declare const SalesInvoiceSchema: z.ZodObject<{
|
|
129
|
+
invoice_date: z.ZodString;
|
|
130
|
+
due_date: z.ZodString;
|
|
131
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
132
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
133
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
134
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
135
|
+
finalized: "finalized";
|
|
136
|
+
voided: "voided";
|
|
137
|
+
}>>;
|
|
138
|
+
invoice_type: z.ZodLiteral<"sales">;
|
|
139
|
+
party_id: z.ZodUUID;
|
|
140
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
141
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
142
|
+
product_id: z.ZodUUID;
|
|
143
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
144
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
145
|
+
credit_type: z.ZodUndefined;
|
|
146
|
+
}, z.core.$strip>>;
|
|
147
|
+
}, z.core.$strip>;
|
|
148
|
+
declare const CreditInvoiceSchema: z.ZodObject<{
|
|
149
|
+
invoice_date: z.ZodString;
|
|
150
|
+
due_date: z.ZodString;
|
|
151
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
152
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
153
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
154
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
155
|
+
finalized: "finalized";
|
|
156
|
+
voided: "voided";
|
|
157
|
+
}>>;
|
|
158
|
+
invoice_type: z.ZodLiteral<"credit">;
|
|
159
|
+
party_id: z.ZodUUID;
|
|
160
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
161
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
162
|
+
product_id: z.ZodUUID;
|
|
163
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
164
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
165
|
+
credit_type: z.ZodEnum<{
|
|
166
|
+
dump: "dump";
|
|
167
|
+
return: "return";
|
|
168
|
+
}>;
|
|
169
|
+
}, z.core.$strip>>;
|
|
170
|
+
}, z.core.$strip>;
|
|
171
|
+
declare const PurchaseInvoiceSchema: z.ZodObject<{
|
|
172
|
+
invoice_date: z.ZodString;
|
|
173
|
+
due_date: z.ZodString;
|
|
174
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
175
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
176
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
177
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
178
|
+
finalized: "finalized";
|
|
179
|
+
voided: "voided";
|
|
180
|
+
}>>;
|
|
181
|
+
invoice_type: z.ZodLiteral<"purchase">;
|
|
182
|
+
party_id: z.ZodUUID;
|
|
183
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
184
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
185
|
+
product_id: z.ZodUUID;
|
|
186
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
187
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
188
|
+
credit_type: z.ZodUndefined;
|
|
189
|
+
}, z.core.$strip>>;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
declare const AnyInvoiceSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
192
|
+
invoice_date: z.ZodString;
|
|
193
|
+
due_date: z.ZodString;
|
|
194
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
195
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
196
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
197
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
198
|
+
finalized: "finalized";
|
|
199
|
+
voided: "voided";
|
|
200
|
+
}>>;
|
|
201
|
+
invoice_type: z.ZodLiteral<"sales">;
|
|
202
|
+
party_id: z.ZodUUID;
|
|
203
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
204
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
205
|
+
product_id: z.ZodUUID;
|
|
206
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
207
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
208
|
+
credit_type: z.ZodUndefined;
|
|
209
|
+
}, z.core.$strip>>;
|
|
210
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
211
|
+
invoice_date: z.ZodString;
|
|
212
|
+
due_date: z.ZodString;
|
|
213
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
214
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
215
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
216
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
217
|
+
finalized: "finalized";
|
|
218
|
+
voided: "voided";
|
|
219
|
+
}>>;
|
|
220
|
+
invoice_type: z.ZodLiteral<"purchase">;
|
|
221
|
+
party_id: z.ZodUUID;
|
|
222
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
223
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
224
|
+
product_id: z.ZodUUID;
|
|
225
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
226
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
227
|
+
credit_type: z.ZodUndefined;
|
|
228
|
+
}, z.core.$strip>>;
|
|
229
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
230
|
+
invoice_date: z.ZodString;
|
|
231
|
+
due_date: z.ZodString;
|
|
232
|
+
tax_rate: z.ZodDefault<z.ZodNumber>;
|
|
233
|
+
tax_amount: z.ZodDefault<z.ZodNumber>;
|
|
234
|
+
warehouse_id: z.ZodOptional<z.ZodUUID>;
|
|
235
|
+
invoice_status: z.ZodDefault<z.ZodEnum<{
|
|
236
|
+
finalized: "finalized";
|
|
237
|
+
voided: "voided";
|
|
238
|
+
}>>;
|
|
239
|
+
invoice_type: z.ZodLiteral<"credit">;
|
|
240
|
+
party_id: z.ZodUUID;
|
|
241
|
+
invoice_items: z.ZodArray<z.ZodObject<{
|
|
242
|
+
invoice_id: z.ZodOptional<z.ZodUUID>;
|
|
243
|
+
product_id: z.ZodUUID;
|
|
244
|
+
quantity: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
245
|
+
price: z.ZodPipe<z.ZodUnion<readonly [z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>, z.ZodTransform<number, string>>, z.ZodNumber]>, z.ZodTransform<number, number>>;
|
|
246
|
+
credit_type: z.ZodEnum<{
|
|
247
|
+
dump: "dump";
|
|
248
|
+
return: "return";
|
|
249
|
+
}>;
|
|
250
|
+
}, z.core.$strip>>;
|
|
251
|
+
}, z.core.$strip>], "invoice_type">;
|
|
252
|
+
|
|
253
|
+
type SalesInvoice = z.infer<typeof SalesInvoiceSchema>;
|
|
254
|
+
type CreditInvoice = z.infer<typeof CreditInvoiceSchema>;
|
|
255
|
+
type PurchaseInvoice = z.infer<typeof PurchaseInvoiceSchema>;
|
|
256
|
+
type AnyInvoiceOut = z.output<typeof AnyInvoiceSchema>;
|
|
257
|
+
declare const INVOICE_TYPE: readonly ["sales", "credit", "purchase"];
|
|
258
|
+
type InvoiceType = (typeof INVOICE_TYPE)[number];
|
|
259
|
+
declare const INVOICE_STATUS: readonly ["finalized", "voided"];
|
|
260
|
+
type InvoiceStatus = (typeof INVOICE_STATUS)[number];
|
|
261
|
+
declare const CREDIT_TYPE: readonly ["dump", "return"];
|
|
262
|
+
type CreditType = (typeof CREDIT_TYPE)[number];
|
|
263
|
+
|
|
133
264
|
type SyncInvoice = {
|
|
134
265
|
invoice_id: UUID;
|
|
135
266
|
invoice_type: InvoiceType;
|
|
@@ -166,4 +297,4 @@ type MappedVendors = {
|
|
|
166
297
|
tax_rate: number;
|
|
167
298
|
};
|
|
168
299
|
|
|
169
|
-
export { type CreatedLocation, CustomerFormSchema, INVOICE_STATUS, INVOICE_TYPE, type InventorySystem, type InvoiceStatus, type InvoiceType, type IsoCountryCode, type MappedCustomers, type MappedVendors, ProductFormSchema, RegisterFormSchema, type SyncInvoice, type UUID, type UserRole, formatMoneyCurrency, getCurrencyFromCountry, handleZodCurrency, normalizeSpaces, removeAllWhitespace, removeDashesAndPlusSign, roundWithPrecision, transformEmptyStringToUndefined };
|
|
300
|
+
export { type AnyInvoiceOut, AnyInvoiceSchema, CREDIT_TYPE, type CreatedLocation, type CreditInvoice, CreditInvoiceSchema, type CreditType, CustomerFormSchema, INVOICE_STATUS, INVOICE_TYPE, type InventorySystem, type InvoiceStatus, type InvoiceType, type IsoCountryCode, type MappedCustomers, type MappedVendors, ProductFormSchema, type PurchaseInvoice, PurchaseInvoiceSchema, RegisterFormSchema, type SalesInvoice, SalesInvoiceSchema, type SyncInvoice, type UUID, type UserRole, formatMoneyCurrency, getCurrencyFromCountry, handleZodCurrency, normalizeSpaces, removeAllWhitespace, removeDashesAndPlusSign, roundWithPrecision, transformEmptyStringToUndefined };
|
package/dist/index.js
CHANGED
|
@@ -164,19 +164,87 @@ var ProductFormSchema = z4.strictObject({
|
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
|
|
167
|
-
// src/types/invoices_types.ts
|
|
168
|
-
var INVOICE_TYPE = ["sales", "credit", "purchase"];
|
|
169
|
-
var INVOICE_STATUS = ["finalized", "voided"];
|
|
170
|
-
|
|
171
167
|
// src/types/shared_types.ts
|
|
172
168
|
import { z as z5 } from "zod";
|
|
173
169
|
var uuidSchema = z5.uuid();
|
|
170
|
+
|
|
171
|
+
// src/domains/invoices/invoices_schemas.ts
|
|
172
|
+
import { z as z6 } from "zod";
|
|
173
|
+
|
|
174
|
+
// src/domains/invoices/invoices_types.ts
|
|
175
|
+
var INVOICE_TYPE = ["sales", "credit", "purchase"];
|
|
176
|
+
var INVOICE_STATUS = ["finalized", "voided"];
|
|
177
|
+
var CREDIT_TYPE = ["dump", "return"];
|
|
178
|
+
|
|
179
|
+
// src/domains/invoices/invoices_schemas.ts
|
|
180
|
+
var YmdDateSchema = z6.string().regex(/^\d{4}-\d{2}-\d{2}$/, "Use YYYY-MM-DD");
|
|
181
|
+
var BaseInvoice = z6.object({
|
|
182
|
+
invoice_type: z6.enum(INVOICE_TYPE, { error: "Invoice type not found." }),
|
|
183
|
+
invoice_date: YmdDateSchema,
|
|
184
|
+
due_date: YmdDateSchema,
|
|
185
|
+
tax_rate: z6.number().default(0),
|
|
186
|
+
tax_amount: z6.number().default(0),
|
|
187
|
+
warehouse_id: z6.uuid().optional(),
|
|
188
|
+
invoice_status: z6.enum(INVOICE_STATUS).default("finalized")
|
|
189
|
+
}).superRefine(({ invoice_date, due_date }, ctx) => {
|
|
190
|
+
if (due_date < invoice_date) {
|
|
191
|
+
ctx.addIssue({
|
|
192
|
+
code: "custom",
|
|
193
|
+
message: "Due date can't be earlier than the invoice date.",
|
|
194
|
+
path: ["due_date"]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
var LineItemBase = z6.object({
|
|
199
|
+
invoice_id: z6.uuid().optional(),
|
|
200
|
+
product_id: z6.uuid({ error: "Select a product" }),
|
|
201
|
+
quantity: handleZodCurrency(0.01, 99999.99)
|
|
202
|
+
});
|
|
203
|
+
var SalesItem = LineItemBase.safeExtend({
|
|
204
|
+
price: handleZodCurrency(0, 99999.99),
|
|
205
|
+
credit_type: z6.undefined()
|
|
206
|
+
});
|
|
207
|
+
var CreditItem = LineItemBase.safeExtend({
|
|
208
|
+
price: handleZodCurrency(0, 99999.99),
|
|
209
|
+
credit_type: z6.enum(CREDIT_TYPE, {
|
|
210
|
+
error: "Select a credit type"
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
var PurchaseItem = LineItemBase.safeExtend({
|
|
214
|
+
price: handleZodCurrency(0, 99999.99),
|
|
215
|
+
credit_type: z6.undefined()
|
|
216
|
+
});
|
|
217
|
+
var SalesInvoiceSchema = BaseInvoice.safeExtend({
|
|
218
|
+
invoice_type: z6.literal("sales"),
|
|
219
|
+
party_id: z6.uuid({ message: "Select a customer" }),
|
|
220
|
+
invoice_items: z6.array(SalesItem).min(1, "Add at least one invoice item")
|
|
221
|
+
});
|
|
222
|
+
var CreditInvoiceSchema = BaseInvoice.safeExtend({
|
|
223
|
+
invoice_type: z6.literal("credit"),
|
|
224
|
+
party_id: z6.uuid({ message: "Select a customer" }),
|
|
225
|
+
invoice_items: z6.array(CreditItem).min(1, "Add at least one invoice item")
|
|
226
|
+
});
|
|
227
|
+
var PurchaseInvoiceSchema = BaseInvoice.safeExtend({
|
|
228
|
+
invoice_type: z6.literal("purchase"),
|
|
229
|
+
party_id: z6.uuid({ message: "Select a vendor" }),
|
|
230
|
+
invoice_items: z6.array(PurchaseItem).min(1, "Add at least one invoice item")
|
|
231
|
+
});
|
|
232
|
+
var AnyInvoiceSchema = z6.discriminatedUnion("invoice_type", [
|
|
233
|
+
SalesInvoiceSchema,
|
|
234
|
+
PurchaseInvoiceSchema,
|
|
235
|
+
CreditInvoiceSchema
|
|
236
|
+
]);
|
|
174
237
|
export {
|
|
238
|
+
AnyInvoiceSchema,
|
|
239
|
+
CREDIT_TYPE,
|
|
240
|
+
CreditInvoiceSchema,
|
|
175
241
|
CustomerFormSchema,
|
|
176
242
|
INVOICE_STATUS,
|
|
177
243
|
INVOICE_TYPE,
|
|
178
244
|
ProductFormSchema,
|
|
245
|
+
PurchaseInvoiceSchema,
|
|
179
246
|
RegisterFormSchema,
|
|
247
|
+
SalesInvoiceSchema,
|
|
180
248
|
formatMoneyCurrency,
|
|
181
249
|
getCurrencyFromCountry,
|
|
182
250
|
handleZodCurrency,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas/companies_schemas.ts","../src/types/company_types.ts","../src/utils/types.ts","../src/utils/utils.ts","../src/schemas/customer_schemas.ts","../src/schemas/product_schemas.ts","../src/types/invoices_types.ts","../src/types/shared_types.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ISO_COUNTRY_CODES, USER_ROLES } from \"../types/company_types\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nconst iso_country_code = z.enum(ISO_COUNTRY_CODES, {\n error: \"Country code not supported.\",\n});\n\nconst user_role = z.enum(USER_ROLES, {\n error: \"User role not supported.\",\n});\n\nexport const RegisterFormSchema = z.strictObject({\n companyData: z.strictObject({\n company_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company name is required\")\n .max(50, \"Company name must be at most 50 characters.\")\n ),\n company_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company address is required\")\n .max(100, \"Company address must be at most 100 characters.\")\n ),\n company_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => /^\\d{4,15}$/.test(s), {\n error: \"Phone number required and must be from 4 to 15 digits.\",\n }),\n iso_country_code: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform((s) => s.toUpperCase())\n .pipe(iso_country_code),\n }),\n adminUserData: z.strictObject({\n user_first_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"First name is required\")\n .max(50, \"First name must be at most 50 characters.\")\n ),\n user_last_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Last name is required\")\n .max(50, \"Last name must be at most 50 characters.\")\n ),\n user_email: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n ),\n password: z\n .string()\n .min(8, \"Password must be at least 8 characters\")\n .max(25, \"Password must be at most 25 characters\")\n .regex(/[A-Z]/, \"Password must contain at least one uppercase letter\")\n .regex(/[a-z]/, \"Password must contain at least one lowercase letter\")\n .regex(/\\d/, \"Password must contain at least one number\")\n .regex(\n /[@$!%*?&#^_+=-]/,\n \"Password must contain at least one special character\"\n )\n .regex(/^\\S*$/, \"Password cannot contain spaces or other whitespace.\"),\n }),\n});\n","export const ISO_COUNTRY_CODES = [\"US\", \"HN\"] as const;\n\nexport type IsoCountryCode = (typeof ISO_COUNTRY_CODES)[number];\n\nexport const USER_ROLES = [\"admin\", \"driver\"] as const;\n\nexport type UserRole = (typeof USER_ROLES)[number];\n\nexport type InventorySystem = \"warehouse_only\" | \"dsd\";\n","import { IsoCountryCode } from \"../types/company_types\";\n\ntype RoundType = \"half_up\";\n\nexport interface ToFixedOptions {\n roundType?: RoundType;\n}\n\nexport type WhitespaceMode = \"normalize\" | \"remove\";\n\nexport type IsoCurrencyCode = \"USD\" | \"HNL\";\n\nexport const countryToCurrency: Record<IsoCountryCode, IsoCurrencyCode> = {\n US: \"USD\",\n HN: \"HNL\",\n};\n","import * as GlobalTypes from \"./types\";\nimport { IsoCountryCode } from \"../types/company_types\";\n\nimport { z } from \"zod\";\n\n/**\n * Validates zod currency with precision.\n *\n *\n * @param minAmount\n * @param maxAmount\n * @returns\n */\nexport function handleZodCurrency(minAmount: number, maxAmount: number) {\n const fromString = z\n .string({\n error: \"Enter a valid number\",\n })\n .refine((s) => s.trim().length > 0, { error: \"Enter a valid number\" })\n .transform((s) => s.replace(/[,\\s]/g, \"\"))\n .refine((s) => s !== \"\" && !Number.isNaN(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number.isFinite(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number(s) >= 0, { error: \"Enter a positive number\" })\n .transform((s) => Number(s));\n\n const fromNumber = z\n .number()\n .refine((n) => Number.isFinite(n), { error: \"Enter a valid number\" })\n .refine((n) => n >= 0, { error: \"Enter a positive number\" });\n\n return z\n .union([fromString, fromNumber])\n .transform((n) => roundWithPrecision(n, 2))\n .refine((n) => n >= minAmount, {\n error: `Must be greater than ${minAmount}`,\n })\n .refine((n) => n <= maxAmount, {\n error: `Exceeds allowed limit ${maxAmount}`,\n });\n}\n\n/**\n * Trims any leading or trailing spaces\n * Transforms empty strings into undefined.\n *\n * @param s\n * @returns\n */\nexport const transformEmptyStringToUndefined = (s: string) =>\n s.trim() === \"\" ? undefined : s;\n\n/**\n * - Collapses any run of whitespace in a string (spaces, tabs, newlines, nbspb, and other weird unicode spaces etc.)\n * into a single ASCII space.\n * - Trims leading and trailing whitespace.\n * \" Jared \\n Gomez \\t Driver\\t \" -> \"Jared Gomez Driver\"\n *\n * @param s\n * @returns\n */\nexport const normalizeSpaces = (s: string) => whitespace(s, \"normalize\");\n\n/**\n * Removes all whitespace from a string\n * @param s\n * @returns\n */\nexport const removeAllWhitespace = (s: string) => whitespace(s, \"remove\");\n\nconst whitespace = (s: string, mode: GlobalTypes.WhitespaceMode) => {\n if (mode === \"remove\") {\n return s.replace(/\\s+/g, \"\");\n }\n\n return s.replace(/\\s+/g, \" \").trim();\n};\n\n/**\n * Removes all dashes and + signs from a string\n * +1-305-555-0123 -> \"13055550123\"\n * 305-555-0123 -> \"3055550123\"\n *\n * @param s\n * @returns\n */\nexport const removeDashesAndPlusSign = (s: string): string =>\n s.replace(/[+-]/g, \"\");\n\n/**\n * Rounds a number to a certain precision.\n * Contract:\n * 1. Number must be finite and non negative.\n * 2. Precision must be finite nonnegative and an integer.\n * 3. Precision must be <= Max precision\n * 4. Returns a number >= 0\n * Default is round half up.\n *\n * @param num\n * @param precision\n * @param opts\n * @returns\n */\nexport function roundWithPrecision(\n num: number,\n precision: number,\n opts?: GlobalTypes.ToFixedOptions\n): number {\n const MAX_PRECISION = 2;\n const { roundType = \"half_up\" } = opts ?? {};\n\n if (!Number.isFinite(num) || num < 0) {\n throw new RangeError(\"Number must be finite and greater than 0.\");\n }\n\n if (\n !Number.isFinite(precision) ||\n !Number.isInteger(precision) ||\n precision < 1\n ) {\n throw new RangeError(\"Precision must be a finite integer greater than 0.\");\n }\n\n if (precision > MAX_PRECISION) {\n throw new RangeError(\"Max precision allowed is 2.\");\n }\n\n return Number(\n (+(Math.round(+(num + \"e\" + precision)) + \"e\" + -precision)).toFixed(\n precision\n )\n );\n}\n\nexport function getCurrencyFromCountry(\n country: IsoCountryCode\n): GlobalTypes.IsoCurrencyCode {\n return GlobalTypes.countryToCurrency[country];\n}\n\nexport function formatMoneyCurrency(\n value: number,\n cur: GlobalTypes.IsoCurrencyCode\n) {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: cur,\n }).format(value);\n}\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const CustomerFormSchema = z.strictObject({\n customer_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Customer name is required\")\n .max(50, \"Customer name must be at most 50 characters.\")\n ),\n\n customer_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z.string().max(100, \"Customer address must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => s === \"\" || /^\\d{4,15}$/.test(s), {\n error: \"Phone number must be from 4 to 15 digits.\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_email_address: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n .optional()\n )\n .optional(),\n\n tax_rate: GlobalUtils.handleZodCurrency(0, 100),\n});\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const ProductFormSchema = z\n .strictObject({\n product_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Product name is required\")\n .max(50, \"Product name must be at most 50 characters.\")\n ),\n\n product_description: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .max(100, \"Product desription must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_sku: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(z.string().max(30, \"Product SKU must be at most 30 characters.\"))\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_upc: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{12}$/.test(s), {\n error: \"UPC must be exactly 12 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_gtin_14: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{14}$/.test(s), {\n error: \"GTIN14 must be exactly 14 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_type: z.enum([\"unit\", \"weight\", \"case\"], {\n error: \"Product type must be unit, weight, or case.\",\n }),\n\n weight_unit: z.preprocess((v) => {\n if (v === \"\") return undefined;\n if (typeof v === \"string\") return v.trim().toLowerCase();\n return v;\n }, z.enum([\"kg\", \"lb\", \"g\", \"oz\"]).optional()),\n\n price: GlobalUtils.handleZodCurrency(0, 99_999.99),\n cost: GlobalUtils.handleZodCurrency(0, 99_999.99),\n })\n\n .superRefine((data, ctx) => {\n if (data.product_type === \"weight\" && !data.weight_unit) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit is required.\",\n path: [\"weight_unit\"],\n });\n }\n\n if (\n data.product_type !== \"weight\" &&\n typeof data.weight_unit !== \"undefined\"\n ) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit must be empty\",\n path: [\"weight_unit\"],\n });\n }\n });\n","export const INVOICE_TYPE = [\"sales\", \"credit\", \"purchase\"] as const;\n\nexport type InvoiceType = (typeof INVOICE_TYPE)[number];\n\nexport const INVOICE_STATUS = [\"finalized\", \"voided\"] as const;\n\nexport type InvoiceStatus = (typeof INVOICE_STATUS)[number];\n","import { z } from \"zod\";\n\nexport const CREATED_LOCATION = [\"web\", \"mobile\"] as const;\n\nexport type CreatedLocation = (typeof CREATED_LOCATION)[number];\n\nexport type IntBool = 0 | 1;\n\nexport const uuidSchema = z.uuid();\nexport type UUID = z.infer<typeof uuidSchema>;\n"],"mappings":";AAAA,SAAS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CAAC,aAAa;AAAA,IACtB,CAAC;AAAA,EACH;AAEA,MACE,KAAK,iBAAiB,YACtB,OAAO,KAAK,gBAAgB,aAC5B;AACA,QAAI,SAAS;AAAA,MACX,MAAM;AAAA,MACN,OAAO;AAAA,MACP,MAAM,CAAC,aAAa;AAAA,IACtB,CAAC;AAAA,EACH;AACF,CAAC;;;ACpFI,IAAM,eAAe,CAAC,SAAS,UAAU,UAAU;AAInD,IAAM,iBAAiB,CAAC,aAAa,QAAQ;;;ACJpD,SAAS,KAAAC,UAAS;AAQX,IAAM,aAAaC,GAAE,KAAK;","names":["z","z","z","z","z","z","z","z"]}
|
|
1
|
+
{"version":3,"sources":["../src/schemas/companies_schemas.ts","../src/types/company_types.ts","../src/utils/types.ts","../src/utils/utils.ts","../src/schemas/customer_schemas.ts","../src/schemas/product_schemas.ts","../src/types/shared_types.ts","../src/domains/invoices/invoices_schemas.ts","../src/domains/invoices/invoices_types.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { ISO_COUNTRY_CODES, USER_ROLES } from \"../types/company_types\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nconst iso_country_code = z.enum(ISO_COUNTRY_CODES, {\n error: \"Country code not supported.\",\n});\n\nconst user_role = z.enum(USER_ROLES, {\n error: \"User role not supported.\",\n});\n\nexport const RegisterFormSchema = z.strictObject({\n companyData: z.strictObject({\n company_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company name is required\")\n .max(50, \"Company name must be at most 50 characters.\")\n ),\n company_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Company address is required\")\n .max(100, \"Company address must be at most 100 characters.\")\n ),\n company_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => /^\\d{4,15}$/.test(s), {\n error: \"Phone number required and must be from 4 to 15 digits.\",\n }),\n iso_country_code: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform((s) => s.toUpperCase())\n .pipe(iso_country_code),\n }),\n adminUserData: z.strictObject({\n user_first_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"First name is required\")\n .max(50, \"First name must be at most 50 characters.\")\n ),\n user_last_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Last name is required\")\n .max(50, \"Last name must be at most 50 characters.\")\n ),\n user_email: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n ),\n password: z\n .string()\n .min(8, \"Password must be at least 8 characters\")\n .max(25, \"Password must be at most 25 characters\")\n .regex(/[A-Z]/, \"Password must contain at least one uppercase letter\")\n .regex(/[a-z]/, \"Password must contain at least one lowercase letter\")\n .regex(/\\d/, \"Password must contain at least one number\")\n .regex(\n /[@$!%*?&#^_+=-]/,\n \"Password must contain at least one special character\"\n )\n .regex(/^\\S*$/, \"Password cannot contain spaces or other whitespace.\"),\n }),\n});\n","export const ISO_COUNTRY_CODES = [\"US\", \"HN\"] as const;\n\nexport type IsoCountryCode = (typeof ISO_COUNTRY_CODES)[number];\n\nexport const USER_ROLES = [\"admin\", \"driver\"] as const;\n\nexport type UserRole = (typeof USER_ROLES)[number];\n\nexport type InventorySystem = \"warehouse_only\" | \"dsd\";\n","import { IsoCountryCode } from \"../types/company_types\";\n\ntype RoundType = \"half_up\";\n\nexport interface ToFixedOptions {\n roundType?: RoundType;\n}\n\nexport type WhitespaceMode = \"normalize\" | \"remove\";\n\nexport type IsoCurrencyCode = \"USD\" | \"HNL\";\n\nexport const countryToCurrency: Record<IsoCountryCode, IsoCurrencyCode> = {\n US: \"USD\",\n HN: \"HNL\",\n};\n","import * as GlobalTypes from \"./types\";\nimport { IsoCountryCode } from \"../types/company_types\";\n\nimport { z } from \"zod\";\n\n/**\n * Validates zod currency with precision.\n *\n *\n * @param minAmount\n * @param maxAmount\n * @returns\n */\nexport function handleZodCurrency(minAmount: number, maxAmount: number) {\n const fromString = z\n .string({\n error: \"Enter a valid number\",\n })\n .refine((s) => s.trim().length > 0, { error: \"Enter a valid number\" })\n .transform((s) => s.replace(/[,\\s]/g, \"\"))\n .refine((s) => s !== \"\" && !Number.isNaN(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number.isFinite(Number(s)), {\n error: \"Enter a valid number\",\n })\n .refine((s) => Number(s) >= 0, { error: \"Enter a positive number\" })\n .transform((s) => Number(s));\n\n const fromNumber = z\n .number()\n .refine((n) => Number.isFinite(n), { error: \"Enter a valid number\" })\n .refine((n) => n >= 0, { error: \"Enter a positive number\" });\n\n return z\n .union([fromString, fromNumber])\n .transform((n) => roundWithPrecision(n, 2))\n .refine((n) => n >= minAmount, {\n error: `Must be greater than ${minAmount}`,\n })\n .refine((n) => n <= maxAmount, {\n error: `Exceeds allowed limit ${maxAmount}`,\n });\n}\n\n/**\n * Trims any leading or trailing spaces\n * Transforms empty strings into undefined.\n *\n * @param s\n * @returns\n */\nexport const transformEmptyStringToUndefined = (s: string) =>\n s.trim() === \"\" ? undefined : s;\n\n/**\n * - Collapses any run of whitespace in a string (spaces, tabs, newlines, nbspb, and other weird unicode spaces etc.)\n * into a single ASCII space.\n * - Trims leading and trailing whitespace.\n * \" Jared \\n Gomez \\t Driver\\t \" -> \"Jared Gomez Driver\"\n *\n * @param s\n * @returns\n */\nexport const normalizeSpaces = (s: string) => whitespace(s, \"normalize\");\n\n/**\n * Removes all whitespace from a string\n * @param s\n * @returns\n */\nexport const removeAllWhitespace = (s: string) => whitespace(s, \"remove\");\n\nconst whitespace = (s: string, mode: GlobalTypes.WhitespaceMode) => {\n if (mode === \"remove\") {\n return s.replace(/\\s+/g, \"\");\n }\n\n return s.replace(/\\s+/g, \" \").trim();\n};\n\n/**\n * Removes all dashes and + signs from a string\n * +1-305-555-0123 -> \"13055550123\"\n * 305-555-0123 -> \"3055550123\"\n *\n * @param s\n * @returns\n */\nexport const removeDashesAndPlusSign = (s: string): string =>\n s.replace(/[+-]/g, \"\");\n\n/**\n * Rounds a number to a certain precision.\n * Contract:\n * 1. Number must be finite and non negative.\n * 2. Precision must be finite nonnegative and an integer.\n * 3. Precision must be <= Max precision\n * 4. Returns a number >= 0\n * Default is round half up.\n *\n * @param num\n * @param precision\n * @param opts\n * @returns\n */\nexport function roundWithPrecision(\n num: number,\n precision: number,\n opts?: GlobalTypes.ToFixedOptions\n): number {\n const MAX_PRECISION = 2;\n const { roundType = \"half_up\" } = opts ?? {};\n\n if (!Number.isFinite(num) || num < 0) {\n throw new RangeError(\"Number must be finite and greater than 0.\");\n }\n\n if (\n !Number.isFinite(precision) ||\n !Number.isInteger(precision) ||\n precision < 1\n ) {\n throw new RangeError(\"Precision must be a finite integer greater than 0.\");\n }\n\n if (precision > MAX_PRECISION) {\n throw new RangeError(\"Max precision allowed is 2.\");\n }\n\n return Number(\n (+(Math.round(+(num + \"e\" + precision)) + \"e\" + -precision)).toFixed(\n precision\n )\n );\n}\n\nexport function getCurrencyFromCountry(\n country: IsoCountryCode\n): GlobalTypes.IsoCurrencyCode {\n return GlobalTypes.countryToCurrency[country];\n}\n\nexport function formatMoneyCurrency(\n value: number,\n cur: GlobalTypes.IsoCurrencyCode\n) {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: cur,\n }).format(value);\n}\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const CustomerFormSchema = z.strictObject({\n customer_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Customer name is required\")\n .max(50, \"Customer name must be at most 50 characters.\")\n ),\n\n customer_address: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z.string().max(100, \"Customer address must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_phone_number: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.removeDashesAndPlusSign)\n .refine((s) => s === \"\" || /^\\d{4,15}$/.test(s), {\n error: \"Phone number must be from 4 to 15 digits.\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n customer_email_address: z\n .string()\n .transform(GlobalUtils.removeAllWhitespace)\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .pipe(\n z\n .email()\n .max(254, \"Customer email must be at most 254 characters.\")\n .transform((email) => email.toLowerCase())\n .optional()\n )\n .optional(),\n\n tax_rate: GlobalUtils.handleZodCurrency(0, 100),\n});\n","import { z } from \"zod\";\nimport * as GlobalUtils from \"../utils/utils\";\n\nexport const ProductFormSchema = z\n .strictObject({\n product_name: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .min(1, \"Product name is required\")\n .max(50, \"Product name must be at most 50 characters.\")\n ),\n\n product_description: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(\n z\n .string()\n .max(100, \"Product desription must be at most 100 characters.\")\n )\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_sku: z\n .string()\n .transform(GlobalUtils.normalizeSpaces)\n .pipe(z.string().max(30, \"Product SKU must be at most 30 characters.\"))\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_upc: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{12}$/.test(s), {\n error: \"UPC must be exactly 12 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_gtin_14: z\n .string()\n .transform((s) => s.replace(/\\s+/g, \"\"))\n .refine((s) => s === \"\" || /^\\d{14}$/.test(s), {\n error: \"GTIN14 must be exactly 14 digits\",\n })\n .transform(GlobalUtils.transformEmptyStringToUndefined)\n .optional(),\n\n product_type: z.enum([\"unit\", \"weight\", \"case\"], {\n error: \"Product type must be unit, weight, or case.\",\n }),\n\n weight_unit: z.preprocess((v) => {\n if (v === \"\") return undefined;\n if (typeof v === \"string\") return v.trim().toLowerCase();\n return v;\n }, z.enum([\"kg\", \"lb\", \"g\", \"oz\"]).optional()),\n\n price: GlobalUtils.handleZodCurrency(0, 99_999.99),\n cost: GlobalUtils.handleZodCurrency(0, 99_999.99),\n })\n\n .superRefine((data, ctx) => {\n if (data.product_type === \"weight\" && !data.weight_unit) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit is required.\",\n path: [\"weight_unit\"],\n });\n }\n\n if (\n data.product_type !== \"weight\" &&\n typeof data.weight_unit !== \"undefined\"\n ) {\n ctx.addIssue({\n code: \"custom\",\n error: \"Weight unit must be empty\",\n path: [\"weight_unit\"],\n });\n }\n });\n","import { z } from \"zod\";\n\nexport const CREATED_LOCATION = [\"web\", \"mobile\"] as const;\n\nexport type CreatedLocation = (typeof CREATED_LOCATION)[number];\n\nexport type IntBool = 0 | 1;\n\nexport const uuidSchema = z.uuid();\nexport type UUID = z.infer<typeof uuidSchema>;\n","import { z } from \"zod\";\nimport { CREDIT_TYPE, INVOICE_STATUS, INVOICE_TYPE } from \"./invoices_types\";\nimport { handleZodCurrency } from \"../../utils/utils\";\n\nconst YmdDateSchema = z.string().regex(/^\\d{4}-\\d{2}-\\d{2}$/, \"Use YYYY-MM-DD\");\n\nconst BaseInvoice = z\n .object({\n invoice_type: z.enum(INVOICE_TYPE, { error: \"Invoice type not found.\" }),\n invoice_date: YmdDateSchema,\n due_date: YmdDateSchema,\n tax_rate: z.number().default(0),\n tax_amount: z.number().default(0),\n warehouse_id: z.uuid().optional(),\n invoice_status: z.enum(INVOICE_STATUS).default(\"finalized\"),\n })\n .superRefine(({ invoice_date, due_date }, ctx) => {\n if (due_date < invoice_date) {\n ctx.addIssue({\n code: \"custom\",\n message: \"Due date can't be earlier than the invoice date.\",\n path: [\"due_date\"],\n });\n }\n });\n\nconst LineItemBase = z.object({\n invoice_id: z.uuid().optional(),\n product_id: z.uuid({ error: \"Select a product\" }),\n quantity: handleZodCurrency(0.01, 99_999.99),\n});\n\nconst SalesItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.undefined(),\n});\n\nconst CreditItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.enum(CREDIT_TYPE, {\n error: \"Select a credit type\",\n }),\n});\n\nconst PurchaseItem = LineItemBase.safeExtend({\n price: handleZodCurrency(0, 99_999.99),\n credit_type: z.undefined(),\n});\n\nexport const SalesInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"sales\"),\n party_id: z.uuid({ message: \"Select a customer\" }),\n invoice_items: z.array(SalesItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const CreditInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"credit\"),\n party_id: z.uuid({ message: \"Select a customer\" }),\n invoice_items: z.array(CreditItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const PurchaseInvoiceSchema = BaseInvoice.safeExtend({\n invoice_type: z.literal(\"purchase\"),\n party_id: z.uuid({ message: \"Select a vendor\" }),\n invoice_items: z.array(PurchaseItem).min(1, \"Add at least one invoice item\"),\n});\n\nexport const AnyInvoiceSchema = z.discriminatedUnion(\"invoice_type\", [\n SalesInvoiceSchema,\n PurchaseInvoiceSchema,\n CreditInvoiceSchema,\n]);\n","import { z } from \"zod\";\nimport * as InvoiceSchemas from \"./invoices_schemas\";\n\nexport type SalesInvoice = z.infer<typeof InvoiceSchemas.SalesInvoiceSchema>;\nexport type CreditInvoice = z.infer<typeof InvoiceSchemas.CreditInvoiceSchema>;\nexport type PurchaseInvoice = z.infer<\n typeof InvoiceSchemas.PurchaseInvoiceSchema\n>;\nexport type AnyInvoiceOut = z.output<typeof InvoiceSchemas.AnyInvoiceSchema>;\n\nexport const INVOICE_TYPE = [\"sales\", \"credit\", \"purchase\"] as const;\n\nexport type InvoiceType = (typeof INVOICE_TYPE)[number];\n\nexport const INVOICE_STATUS = [\"finalized\", \"voided\"] as const;\n\nexport type InvoiceStatus = (typeof INVOICE_STATUS)[number];\n\nexport const CREDIT_TYPE = [\"dump\", \"return\"] as const;\n\nexport type CreditType = (typeof CREDIT_TYPE)[number];\n"],"mappings":";AAAA,SAAS,KAAAA,UAAS;;;ACAX,IAAM,oBAAoB,CAAC,MAAM,IAAI;AAIrC,IAAM,aAAa,CAAC,SAAS,QAAQ;;;ACQrC,IAAM,oBAA6D;AAAA,EACxE,IAAI;AAAA,EACJ,IAAI;AACN;;;ACZA,SAAS,SAAS;AAUX,SAAS,kBAAkB,WAAmB,WAAmB;AACtE,QAAM,aAAa,EAChB,OAAO;AAAA,IACN,OAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,EAAE,OAAO,uBAAuB,CAAC,EACpE,UAAU,CAAC,MAAM,EAAE,QAAQ,UAAU,EAAE,CAAC,EACxC,OAAO,CAAC,MAAM,MAAM,MAAM,CAAC,OAAO,MAAM,OAAO,CAAC,CAAC,GAAG;AAAA,IACnD,OAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,MAAM,OAAO,SAAS,OAAO,CAAC,CAAC,GAAG;AAAA,IACzC,OAAO;AAAA,EACT,CAAC,EACA,OAAO,CAAC,MAAM,OAAO,CAAC,KAAK,GAAG,EAAE,OAAO,0BAA0B,CAAC,EAClE,UAAU,CAAC,MAAM,OAAO,CAAC,CAAC;AAE7B,QAAM,aAAa,EAChB,OAAO,EACP,OAAO,CAAC,MAAM,OAAO,SAAS,CAAC,GAAG,EAAE,OAAO,uBAAuB,CAAC,EACnE,OAAO,CAAC,MAAM,KAAK,GAAG,EAAE,OAAO,0BAA0B,CAAC;AAE7D,SAAO,EACJ,MAAM,CAAC,YAAY,UAAU,CAAC,EAC9B,UAAU,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,EACzC,OAAO,C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