chore: 🤖 processor schema vusiness
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod/v4";
|
||||
import { AppEnv } from "../genModels/genEnums.js";
|
||||
import type { ExternalProcessors } from "./cusTable.js";
|
||||
import { ExternalProcessorsSchema } from "../genModels/processorSchemas.js";
|
||||
|
||||
export const CustomerSchema = z.object({
|
||||
id: z.string().nullish(), // given by user
|
||||
@@ -14,6 +14,7 @@ export const CustomerSchema = z.object({
|
||||
created_at: z.number(),
|
||||
env: z.nativeEnum(AppEnv),
|
||||
processor: z.any(),
|
||||
processors: ExternalProcessorsSchema.nullish(),
|
||||
metadata: z.record(z.any(), z.any()).nullish().default({}),
|
||||
});
|
||||
|
||||
@@ -64,7 +65,7 @@ export const CreateCustomerSchema = z.object({
|
||||
fingerprint: z.string().nullish(),
|
||||
metadata: z.record(z.any(), z.any()).default({}).nullish(),
|
||||
stripe_id: z.string().nullish(),
|
||||
processors: z.object<ExternalProcessors>().nullish(),
|
||||
processors: ExternalProcessorsSchema.nullish(),
|
||||
});
|
||||
|
||||
// export const CustomerDataSchema = z.object({
|
||||
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
unique,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { collatePgColumn } from "../../db/utils.js";
|
||||
import type {
|
||||
ExternalProcessors,
|
||||
VercelProcessor,
|
||||
} from "../genModels/processorSchemas.js";
|
||||
import { organizations } from "../orgModels/orgTable.js";
|
||||
|
||||
export type CustomerProcessor = {
|
||||
@@ -15,15 +19,6 @@ export type CustomerProcessor = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
export type ExternalProcessors = {
|
||||
vercel?: VercelProcessor;
|
||||
};
|
||||
|
||||
export type VercelProcessor = {
|
||||
installation_id: string;
|
||||
access_token: string;
|
||||
};
|
||||
|
||||
export const customers = pgTable(
|
||||
"customers",
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@ export const customerProducts = pgTable(
|
||||
created_at: numeric({ mode: "number" }),
|
||||
status: text(),
|
||||
processor: jsonb().$type<CustomerProductProcessor>(),
|
||||
|
||||
canceled: boolean("canceled").default(false),
|
||||
canceled_at: numeric({ mode: "number" }),
|
||||
ended_at: numeric({ mode: "number" }),
|
||||
|
||||
69
shared/models/genModels/processorSchemas.ts
Normal file
69
shared/models/genModels/processorSchemas.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { z } from "zod/v4";
|
||||
|
||||
/**
|
||||
* Customer-level Vercel processor
|
||||
* Stores installation-specific data for a customer's Vercel integration
|
||||
*/
|
||||
export const VercelProcessorSchema = z.object({
|
||||
installation_id: z.string(),
|
||||
access_token: z.string(),
|
||||
account_id: z.string(),
|
||||
custom_payment_method_id: z.string().optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Container for all external (non-Stripe) processors at customer level
|
||||
*/
|
||||
export const ExternalProcessorsSchema = z.object({
|
||||
vercel: VercelProcessorSchema.optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Organization-level Vercel processor configuration
|
||||
* Stores OAuth app credentials and webhook URL
|
||||
*/
|
||||
export const VercelProcessorConfigSchema = z.object({
|
||||
client_integration_id: z.string(),
|
||||
client_secret: z.string(),
|
||||
sandbox_client_id: z.string().optional(),
|
||||
sandbox_client_secret: z.string().optional(),
|
||||
sandbox_webhook_url: z.string().optional(),
|
||||
webhook_url: z.string(),
|
||||
custom_payment_method: z
|
||||
.object({
|
||||
live: z.string().optional(),
|
||||
sandbox: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const UpsertVercelProcessorConfigSchema = z.object({
|
||||
client_integration_id: z.string().min(8).optional(),
|
||||
client_secret: z.string().min(8).optional(),
|
||||
webhook_url: z.string().min(14).optional(),
|
||||
sandbox_client_id: z.string().min(8).optional(),
|
||||
sandbox_client_secret: z.string().min(8).optional(),
|
||||
sandbox_webhook_url: z.string().min(14).optional(),
|
||||
custom_payment_method: z
|
||||
.object({
|
||||
live: z.string().min(8).optional(),
|
||||
sandbox: z.string().min(8).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Container for all processor configurations at organization level
|
||||
*/
|
||||
export const ProcessorConfigsSchema = z.object({
|
||||
vercel: VercelProcessorConfigSchema.optional(),
|
||||
});
|
||||
|
||||
// Export inferred types for backward compatibility
|
||||
export type VercelProcessor = z.infer<typeof VercelProcessorSchema>;
|
||||
export type ExternalProcessors = z.infer<typeof ExternalProcessorsSchema>;
|
||||
export type VercelProcessorConfig = z.infer<typeof VercelProcessorConfigSchema>;
|
||||
export type UpsertVercelProcessorConfig = z.infer<
|
||||
typeof UpsertVercelProcessorConfigSchema
|
||||
>;
|
||||
export type ProcessorConfigs = z.infer<typeof ProcessorConfigsSchema>;
|
||||
Reference in New Issue
Block a user