@paykit-sdk/core
Version:
The Payment Toolkit for Typescript
102 lines (96 loc) • 3.23 kB
JavaScript
;
var zod = require('zod');
// src/resources/customer.ts
var metadataSchema = zod.z.record(zod.z.string(), zod.z.string());
// src/tools/utils.ts
var schema = () => {
return (schema2) => schema2;
};
var billingAddressSchema = schema()(
zod.z.object({
name: zod.z.string().min(1, "Recipient name is required"),
line1: zod.z.string().min(1, "Address line 1 is required"),
line2: zod.z.string().default("").optional(),
city: zod.z.string().min(1, "City is required"),
state: zod.z.string().optional(),
// Optional because not all countries use states
postal_code: zod.z.string().min(1, "Postal code is required"),
country: zod.z.string().length(2, "Country must be a 2-letter ISO code").toUpperCase(),
phone: zod.z.string().optional()
})
);
var billingSchema = schema()(
zod.z.object({
address: billingAddressSchema,
carrier: zod.z.string().optional(),
currency: zod.z.string().min(1, "Currency is required")
})
);
// src/resources/customer.ts
var customerSchema = schema()(
zod.z.object({
id: zod.z.string(),
email: zod.z.string().email(),
name: zod.z.string(),
phone: zod.z.string().nullable(),
metadata: metadataSchema.optional(),
custom_fields: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
created_at: zod.z.date(),
updated_at: zod.z.date().nullable()
})
);
var payeeSchema = schema()(
zod.z.union([
zod.z.object({ email: zod.z.string().email() }),
zod.z.object({ id: zod.z.union([zod.z.string(), zod.z.number()]) })
])
);
var createCustomerSchema = schema()(
zod.z.object({
email: zod.z.string().email(),
name: zod.z.string().optional(),
phone: zod.z.string().nullable().optional(),
metadata: metadataSchema.optional(),
billing: billingSchema.nullable(),
provider_metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
})
);
var updateCustomerSchema = schema()(
zod.z.object({
email: zod.z.string().email().optional(),
name: zod.z.string().optional(),
metadata: metadataSchema.optional(),
provider_metadata: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
})
);
var retrieveCustomerSchema = schema()(
zod.z.object({
id: zod.z.string()
})
);
var isEmailCustomer = (customer) => {
return typeof customer === "object" && customer !== null && "email" in customer;
};
var isIdCustomer = (customer) => {
return typeof customer === "object" && customer !== null && "id" in customer;
};
var parseCustomerName = (params) => {
const full = params.name?.trim() || params.email.split("@")[0];
const parts = full.split(/\s+/);
const first = parts[0] || "";
const last = parts.slice(1).join(" ") || "";
return {
fullName: full,
firstName: first,
lastName: last,
initials: `${first[0] || ""}${last[0] || ""}`.toUpperCase()
};
};
exports.createCustomerSchema = createCustomerSchema;
exports.customerSchema = customerSchema;
exports.isEmailCustomer = isEmailCustomer;
exports.isIdCustomer = isIdCustomer;
exports.parseCustomerName = parseCustomerName;
exports.payeeSchema = payeeSchema;
exports.retrieveCustomerSchema = retrieveCustomerSchema;
exports.updateCustomerSchema = updateCustomerSchema;