diff --git a/packages/sync-engine/src/database/postgres.ts b/packages/sync-engine/src/database/postgres.ts index f3e3f220b..d0a028759 100644 --- a/packages/sync-engine/src/database/postgres.ts +++ b/packages/sync-engine/src/database/postgres.ts @@ -1,6 +1,6 @@ import pg, { QueryResult } from 'pg' import { pg as sql } from 'yesql' -import { JsonSchema } from '../schemas/types' +import { EntitySchema } from '../schemas/types' type PostgresConfig = { databaseUrl: string @@ -37,7 +37,7 @@ export class PostgresClient { T extends { [Key: string]: any // eslint-disable-line @typescript-eslint/no-explicit-any }, - >(entries: T[], table: string, tableSchema: JsonSchema): Promise { + >(entries: T[], table: string, tableSchema: EntitySchema): Promise { if (!entries.length) return [] // Max 5 in parallel to avoid exhausting connection pool @@ -96,7 +96,7 @@ export class PostgresClient { private constructUpsertSql( schema: string, table: string, - tableSchema: JsonSchema, + tableSchema: EntitySchema, options?: { conflict?: string } @@ -106,22 +106,16 @@ export class PostgresClient { return ` insert into "${schema}"."${table}" ( - ${Object.keys(properties) - .map((x) => `"${x}"`) - .join(',')} + ${properties.map((x) => `"${x}"`).join(',')} ) values ( - ${Object.keys(properties) - .map((x) => `:${x}`) - .join(',')} + ${properties.map((x) => `:${x}`).join(',')} ) on conflict ( ${conflict} ) do update set - ${Object.keys(properties) - .map((x) => `"${x}" = :${x}`) - .join(',')} + ${properties.map((x) => `"${x}" = :${x}`).join(',')} ;` } diff --git a/packages/sync-engine/src/schemas/charge.ts b/packages/sync-engine/src/schemas/charge.ts index 5121c0afa..64c2c1d86 100644 --- a/packages/sync-engine/src/schemas/charge.ts +++ b/packages/sync-engine/src/schemas/charge.ts @@ -1,46 +1,43 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const chargeSchema: JsonSchema = { - $id: 'chargeSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - paid: { type: 'boolean' }, - order: { type: 'string' }, - amount: { type: 'number' }, - review: { type: 'string' }, - source: { type: 'object' }, - status: { type: 'string' }, - created: { type: 'number' }, - dispute: { type: 'string' }, - invoice: { type: 'string' }, - outcome: { type: 'object' }, - refunds: { type: 'object' }, - captured: { type: 'boolean' }, - currency: { type: 'string' }, - customer: { type: 'string' }, - livemode: { type: 'boolean' }, - metadata: { type: 'object' }, - refunded: { type: 'boolean' }, - shipping: { type: 'object' }, - application: { type: 'string' }, - description: { type: 'string' }, - destination: { type: 'string' }, - failure_code: { type: 'string' }, - on_behalf_of: { type: 'string' }, - fraud_details: { type: 'object' }, - receipt_email: { type: 'string' }, - payment_intent: { type: 'string' }, - receipt_number: { type: 'string' }, - transfer_group: { type: 'string' }, - amount_refunded: { type: 'number' }, - application_fee: { type: 'string' }, - failure_message: { type: 'string' }, - source_transfer: { type: 'string' }, - balance_transaction: { type: 'string' }, - statement_descriptor: { type: 'string' }, - payment_method_details: { type: 'object' }, - }, - required: ['id'], +export const chargeSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'paid', + 'order', + 'amount', + 'review', + 'source', + 'status', + 'created', + 'dispute', + 'invoice', + 'outcome', + 'refunds', + 'captured', + 'currency', + 'customer', + 'livemode', + 'metadata', + 'refunded', + 'shipping', + 'application', + 'description', + 'destination', + 'failure_code', + 'on_behalf_of', + 'fraud_details', + 'receipt_email', + 'payment_intent', + 'receipt_number', + 'transfer_group', + 'amount_refunded', + 'application_fee', + 'failure_message', + 'source_transfer', + 'balance_transaction', + 'statement_descriptor', + 'payment_method_details', + ], } as const diff --git a/packages/sync-engine/src/schemas/credit_note.ts b/packages/sync-engine/src/schemas/credit_note.ts index 48bb73f2f..577cd4708 100644 --- a/packages/sync-engine/src/schemas/credit_note.ts +++ b/packages/sync-engine/src/schemas/credit_note.ts @@ -1,38 +1,35 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const creditNoteSchema: JsonSchema = { - $id: 'creditNoteSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - amount: { type: 'number' }, - amount_shipping: { type: 'number' }, - created: { type: 'number' }, - currency: { type: 'string' }, - customer: { type: 'string' }, - customer_balance_transaction: { type: 'string' }, - discount_amount: { type: 'number' }, - discount_amounts: { type: 'object' }, - invoice: { type: 'string' }, - lines: { type: 'object' }, - livemode: { type: 'boolean' }, - memo: { type: 'string' }, - metadata: { type: 'object' }, - number: { type: 'string' }, - out_of_band_amount: { type: 'number' }, - pdf: { type: 'string' }, - reason: { type: 'string' }, - refund: { type: 'string' }, - shipping_cost: { type: 'object' }, - status: { type: 'string' }, - subtotal: { type: 'number' }, - subtotal_excluding_tax: { type: 'number' }, - tax_amounts: { type: 'object' }, - total: { type: 'number' }, - total_excluding_tax: { type: 'number' }, - type: { type: 'string' }, - voided_at: { type: 'string' }, - }, - required: ['id'], +export const creditNoteSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'amount', + 'amount_shipping', + 'created', + 'currency', + 'customer', + 'customer_balance_transaction', + 'discount_amount', + 'discount_amounts', + 'invoice', + 'lines', + 'livemode', + 'memo', + 'metadata', + 'number', + 'out_of_band_amount', + 'pdf', + 'reason', + 'refund', + 'shipping_cost', + 'status', + 'subtotal', + 'subtotal_excluding_tax', + 'tax_amounts', + 'total', + 'total_excluding_tax', + 'type', + 'voided_at', + ], } as const diff --git a/packages/sync-engine/src/schemas/customer.ts b/packages/sync-engine/src/schemas/customer.ts index 46a9e1da7..2e543f311 100644 --- a/packages/sync-engine/src/schemas/customer.ts +++ b/packages/sync-engine/src/schemas/customer.ts @@ -1,41 +1,31 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const customerSchema: JsonSchema = { - $id: 'customerSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - address: { type: 'object' }, - description: { type: 'string' }, - email: { type: 'string' }, - metadata: { type: 'object' }, - name: { type: 'string' }, - phone: { type: 'string' }, - shipping: { type: 'object' }, - balance: { type: 'integer' }, - created: { type: 'integer' }, - currency: { type: 'string' }, - default_source: { type: 'string' }, - delinquent: { type: 'boolean' }, - discount: { type: 'object' }, - invoice_prefix: { type: 'string' }, - invoice_settings: { type: 'object' }, - livemode: { type: 'boolean' }, - next_invoice_sequence: { type: 'integer' }, - preferred_locales: { type: 'object' }, - tax_exempt: { type: 'boolean' }, - }, - required: ['id'], +export const customerSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'address', + 'description', + 'email', + 'metadata', + 'name', + 'phone', + 'shipping', + 'balance', + 'created', + 'currency', + 'default_source', + 'delinquent', + 'discount', + 'invoice_prefix', + 'invoice_settings', + 'livemode', + 'next_invoice_sequence', + 'preferred_locales', + 'tax_exempt', + ], } as const -export const customerDeletedSchema: JsonSchema = { - $id: 'customerSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - deleted: { type: 'boolean' }, - }, - required: ['id'], +export const customerDeletedSchema: EntitySchema = { + properties: ['id', 'object', 'deleted'], } as const diff --git a/packages/sync-engine/src/schemas/dispute.ts b/packages/sync-engine/src/schemas/dispute.ts index 1ae8ccadd..79b7163f2 100644 --- a/packages/sync-engine/src/schemas/dispute.ts +++ b/packages/sync-engine/src/schemas/dispute.ts @@ -1,24 +1,21 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const disputeSchema: JsonSchema = { - $id: 'disputeSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - amount: { type: 'integer' }, - charge: { type: 'string' }, - created: { type: 'integer' }, - currency: { type: 'string' }, - balance_transactions: { type: 'object' }, - evidence: { type: 'object' }, - evidence_details: { type: 'object' }, - is_charge_refundable: { type: 'boolean' }, - livemode: { type: 'boolean' }, - metadata: { type: 'object' }, - payment_intent: { type: 'string' }, - reason: { type: 'string' }, - status: { type: 'string' }, - }, - required: ['id'], +export const disputeSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'amount', + 'charge', + 'created', + 'currency', + 'balance_transactions', + 'evidence', + 'evidence_details', + 'is_charge_refundable', + 'livemode', + 'metadata', + 'payment_intent', + 'reason', + 'status', + ], } as const diff --git a/packages/sync-engine/src/schemas/invoice.ts b/packages/sync-engine/src/schemas/invoice.ts index bdb265d23..786f7a022 100644 --- a/packages/sync-engine/src/schemas/invoice.ts +++ b/packages/sync-engine/src/schemas/invoice.ts @@ -1,73 +1,70 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const invoiceSchema: JsonSchema = { - $id: 'invoiceSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - auto_advance: { type: 'boolean' }, - collection_method: { type: 'string' }, - currency: { type: 'string' }, - description: { type: 'string' }, - hosted_invoice_url: { type: 'string' }, - lines: { type: 'object' }, - metadata: { type: 'object' }, - period_end: { type: 'number' }, - period_start: { type: 'number' }, - status: { type: 'string' }, - total: { type: 'number' }, - account_country: { type: 'string' }, - account_name: { type: 'string' }, - account_tax_ids: { type: 'object' }, - amount_due: { type: 'number' }, - amount_paid: { type: 'number' }, - amount_remaining: { type: 'number' }, - application_fee_amount: { type: 'number' }, - attempt_count: { type: 'number' }, - attempted: { type: 'boolean' }, - billing_reason: { type: 'string' }, - created: { type: 'number' }, - custom_fields: { type: 'object' }, - customer_address: { type: 'object' }, - customer_email: { type: 'string' }, - customer_name: { type: 'string' }, - customer_phone: { type: 'string' }, - customer_shipping: { type: 'object' }, - customer_tax_exempt: { type: 'string' }, - customer_tax_ids: { type: 'object' }, - default_tax_rates: { type: 'object' }, - discount: { type: 'object' }, - discounts: { type: 'object' }, - due_date: { type: 'number' }, - ending_balance: { type: 'number' }, - footer: { type: 'string' }, - invoice_pdf: { type: 'string' }, - last_finalization_error: { type: 'object' }, - livemode: { type: 'boolean' }, - next_payment_attempt: { type: 'number' }, - number: { type: 'string' }, - paid: { type: 'boolean' }, - payment_settings: { type: 'object' }, - post_payment_credit_notes_amount: { type: 'number' }, - pre_payment_credit_notes_amount: { type: 'number' }, - receipt_number: { type: 'string' }, - starting_balance: { type: 'number' }, - statement_descriptor: { type: 'string' }, - status_transitions: { type: 'object' }, - subtotal: { type: 'number' }, - tax: { type: 'number' }, - total_discount_amounts: { type: 'object' }, - total_tax_amounts: { type: 'object' }, - transfer_data: { type: 'object' }, - webhooks_delivered_at: { type: 'number' }, - customer: { type: 'string' }, - subscription: { type: 'string' }, - payment_intent: { type: 'string' }, - default_payment_method: { type: 'string' }, - default_source: { type: 'string' }, - on_behalf_of: { type: 'string' }, - charge: { type: 'string' }, - }, - required: ['id'], +export const invoiceSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'auto_advance', + 'collection_method', + 'currency', + 'description', + 'hosted_invoice_url', + 'lines', + 'metadata', + 'period_end', + 'period_start', + 'status', + 'total', + 'account_country', + 'account_name', + 'account_tax_ids', + 'amount_due', + 'amount_paid', + 'amount_remaining', + 'application_fee_amount', + 'attempt_count', + 'attempted', + 'billing_reason', + 'created', + 'custom_fields', + 'customer_address', + 'customer_email', + 'customer_name', + 'customer_phone', + 'customer_shipping', + 'customer_tax_exempt', + 'customer_tax_ids', + 'default_tax_rates', + 'discount', + 'discounts', + 'due_date', + 'ending_balance', + 'footer', + 'invoice_pdf', + 'last_finalization_error', + 'livemode', + 'next_payment_attempt', + 'number', + 'paid', + 'payment_settings', + 'post_payment_credit_notes_amount', + 'pre_payment_credit_notes_amount', + 'receipt_number', + 'starting_balance', + 'statement_descriptor', + 'status_transitions', + 'subtotal', + 'tax', + 'total_discount_amounts', + 'total_tax_amounts', + 'transfer_data', + 'webhooks_delivered_at', + 'customer', + 'subscription', + 'payment_intent', + 'default_payment_method', + 'default_source', + 'on_behalf_of', + 'charge', + ], } as const diff --git a/packages/sync-engine/src/schemas/payment_intent.ts b/packages/sync-engine/src/schemas/payment_intent.ts index a94b32dab..02676e9ca 100644 --- a/packages/sync-engine/src/schemas/payment_intent.ts +++ b/packages/sync-engine/src/schemas/payment_intent.ts @@ -1,46 +1,43 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const paymentIntentSchema: JsonSchema = { - $id: 'paymentIntentSchema', - type: 'object', - properties: { - id: { type: 'text' }, - object: { type: 'text' }, - amount: { type: 'integer' }, - amount_capturable: { type: 'integer' }, - amount_details: { type: 'object' }, - amount_received: { type: 'integer' }, - application: { type: 'text' }, - application_fee_amount: { type: 'integer' }, - automatic_payment_methods: { type: 'text' }, - canceled_at: { type: 'integer' }, - cancellation_reason: { type: 'text' }, - capture_method: { type: 'text' }, - client_secret: { type: 'text' }, - confirmation_method: { type: 'text' }, - created: { type: 'integer' }, - currency: { type: 'text' }, - customer: { type: 'text' }, - description: { type: 'text' }, - invoice: { type: 'text' }, - last_payment_error: { type: 'text' }, - livemode: { type: 'boolean' }, - metadata: { type: 'object' }, - next_action: { type: 'text' }, - on_behalf_of: { type: 'text' }, - payment_method: { type: 'text' }, - payment_method_options: { type: 'object' }, - payment_method_types: { type: 'object' }, - processing: { type: 'text' }, - receipt_email: { type: 'text' }, - review: { type: 'text' }, - setup_future_usage: { type: 'text' }, - shipping: { type: 'object' }, - statement_descriptor: { type: 'text' }, - statement_descriptor_suffix: { type: 'text' }, - status: { type: 'text' }, - transfer_data: { type: 'object' }, - transfer_group: { type: 'text' }, - }, - required: ['id'], +export const paymentIntentSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'amount', + 'amount_capturable', + 'amount_details', + 'amount_received', + 'application', + 'application_fee_amount', + 'automatic_payment_methods', + 'canceled_at', + 'cancellation_reason', + 'capture_method', + 'client_secret', + 'confirmation_method', + 'created', + 'currency', + 'customer', + 'description', + 'invoice', + 'last_payment_error', + 'livemode', + 'metadata', + 'next_action', + 'on_behalf_of', + 'payment_method', + 'payment_method_options', + 'payment_method_types', + 'processing', + 'receipt_email', + 'review', + 'setup_future_usage', + 'shipping', + 'statement_descriptor', + 'statement_descriptor_suffix', + 'status', + 'transfer_data', + 'transfer_group', + ], } as const diff --git a/packages/sync-engine/src/schemas/payment_methods.ts b/packages/sync-engine/src/schemas/payment_methods.ts index 3053b6238..4612dbebd 100644 --- a/packages/sync-engine/src/schemas/payment_methods.ts +++ b/packages/sync-engine/src/schemas/payment_methods.ts @@ -1,17 +1,14 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const paymentMethodsSchema: JsonSchema = { - $id: 'paymentMethodSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - created: { type: 'integer' }, - customer: { type: 'string' }, - type: { type: 'string' }, - billing_details: { type: 'object' }, - metadata: { type: 'object' }, - card: { type: 'object' }, - }, - required: ['id'], +export const paymentMethodsSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'created', + 'customer', + 'type', + 'billing_details', + 'metadata', + 'card', + ], } as const diff --git a/packages/sync-engine/src/schemas/plan.ts b/packages/sync-engine/src/schemas/plan.ts index 08deb1321..aea4aa7da 100644 --- a/packages/sync-engine/src/schemas/plan.ts +++ b/packages/sync-engine/src/schemas/plan.ts @@ -1,27 +1,24 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const planSchema: JsonSchema = { - $id: 'planSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - active: { type: 'boolean' }, - amount: { type: 'number' }, - created: { type: 'number' }, - product: { type: 'string' }, - currency: { type: 'string' }, - interval: { type: 'string' }, - livemode: { type: 'boolean' }, - metadata: { type: 'object' }, - nickname: { type: 'string' }, - tiers_mode: { type: 'string' }, - usage_type: { type: 'string' }, - billing_scheme: { type: 'string' }, - interval_count: { type: 'number' }, - aggregate_usage: { type: 'string' }, - transform_usage: { type: 'string' }, - trial_period_days: { type: 'number' }, - }, - required: ['id'], +export const planSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'active', + 'amount', + 'created', + 'product', + 'currency', + 'interval', + 'livemode', + 'metadata', + 'nickname', + 'tiers_mode', + 'usage_type', + 'billing_scheme', + 'interval_count', + 'aggregate_usage', + 'transform_usage', + 'trial_period_days', + ], } as const diff --git a/packages/sync-engine/src/schemas/price.ts b/packages/sync-engine/src/schemas/price.ts index 7f4023d82..ca19ef849 100644 --- a/packages/sync-engine/src/schemas/price.ts +++ b/packages/sync-engine/src/schemas/price.ts @@ -1,26 +1,23 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const priceSchema: JsonSchema = { - $id: 'priceSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - active: { type: 'boolean' }, - currency: { type: 'string' }, - metadata: { type: 'object' }, - nickname: { type: 'string' }, - recurring: { type: 'object' }, - type: { type: 'string' }, - unit_amount: { type: 'integer' }, - billing_scheme: { type: 'string' }, - created: { type: 'integer' }, - livemode: { type: 'boolean' }, - lookup_key: { type: 'string' }, - tiers_mode: { type: 'string' }, - transform_quantity: { type: 'object' }, - unit_amount_decimal: { type: 'string' }, - product: { type: 'string' }, - }, - required: ['id'], +export const priceSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'active', + 'currency', + 'metadata', + 'nickname', + 'recurring', + 'type', + 'unit_amount', + 'billing_scheme', + 'created', + 'livemode', + 'lookup_key', + 'tiers_mode', + 'transform_quantity', + 'unit_amount_decimal', + 'product', + ], } as const diff --git a/packages/sync-engine/src/schemas/product.ts b/packages/sync-engine/src/schemas/product.ts index 2516ac25c..dba05ba72 100644 --- a/packages/sync-engine/src/schemas/product.ts +++ b/packages/sync-engine/src/schemas/product.ts @@ -1,25 +1,22 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const productSchema: JsonSchema = { - $id: 'productSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - active: { type: 'boolean' }, - description: { type: 'string' }, - metadata: { type: 'object' }, - name: { type: 'string' }, - created: { type: 'integer' }, - images: { type: 'object' }, - marketing_features: { type: 'object' }, - livemode: { type: 'boolean' }, - package_dimensions: { type: 'object' }, - shippable: { type: 'boolean' }, - statement_descriptor: { type: 'string' }, - unit_label: { type: 'string' }, - updated: { type: 'integer' }, - url: { type: 'string' }, - }, - required: ['id'], +export const productSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'active', + 'description', + 'metadata', + 'name', + 'created', + 'images', + 'marketing_features', + 'livemode', + 'package_dimensions', + 'shippable', + 'statement_descriptor', + 'unit_label', + 'updated', + 'url', + ], } as const diff --git a/packages/sync-engine/src/schemas/setup_intents.ts b/packages/sync-engine/src/schemas/setup_intents.ts index 58ed1a2d0..6f590574a 100644 --- a/packages/sync-engine/src/schemas/setup_intents.ts +++ b/packages/sync-engine/src/schemas/setup_intents.ts @@ -1,22 +1,19 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const setupIntentsSchema: JsonSchema = { - $id: 'setupIntentSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - created: { type: 'integer' }, - customer: { type: 'string' }, - description: { type: 'string' }, - payment_method: { type: 'string' }, - status: { type: 'string' }, - usage: { type: 'string' }, - cancellation_reason: { type: 'string' }, - latest_attempt: { type: 'string' }, - mandate: { type: 'string' }, - single_use_mandate: { type: 'string' }, - on_behalf_of: { type: 'string' }, - }, - required: ['id'], +export const setupIntentsSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'created', + 'customer', + 'description', + 'payment_method', + 'status', + 'usage', + 'cancellation_reason', + 'latest_attempt', + 'mandate', + 'single_use_mandate', + 'on_behalf_of', + ], } as const diff --git a/packages/sync-engine/src/schemas/subscription.ts b/packages/sync-engine/src/schemas/subscription.ts index af63c9fca..7062f5fce 100644 --- a/packages/sync-engine/src/schemas/subscription.ts +++ b/packages/sync-engine/src/schemas/subscription.ts @@ -1,44 +1,41 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const subscriptionSchema: JsonSchema = { - $id: 'subscriptionSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - cancel_at_period_end: { type: 'boolean' }, - current_period_end: { type: 'number' }, - current_period_start: { type: 'number' }, - default_payment_method: { type: 'string' }, - items: { type: 'object' }, - metadata: { type: 'object' }, - pending_setup_intent: { type: 'string' }, - pending_update: { type: 'object' }, - status: { type: 'string' }, - application_fee_percent: { type: 'number' }, - billing_cycle_anchor: { type: 'number' }, - billing_thresholds: { type: 'object' }, - cancel_at: { type: 'number' }, - canceled_at: { type: 'number' }, - collection_method: { type: 'string' }, - created: { type: 'number' }, - days_until_due: { type: 'number' }, - default_source: { type: 'string' }, - default_tax_rates: { type: 'object' }, - discount: { type: 'object' }, - ended_at: { type: 'number' }, - livemode: { type: 'boolean' }, - next_pending_invoice_item_invoice: { type: 'number' }, - pause_collection: { type: 'object' }, - pending_invoice_item_interval: { type: 'object' }, - start_date: { type: 'number' }, - transfer_data: { type: 'object' }, - trial_end: { type: 'object' }, - trial_start: { type: 'object' }, - schedule: { type: 'string' }, - customer: { type: 'string' }, - latest_invoice: { type: 'string' }, - plan: { type: 'string' }, - }, - required: ['id'], +export const subscriptionSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'cancel_at_period_end', + 'current_period_end', + 'current_period_start', + 'default_payment_method', + 'items', + 'metadata', + 'pending_setup_intent', + 'pending_update', + 'status', + 'application_fee_percent', + 'billing_cycle_anchor', + 'billing_thresholds', + 'cancel_at', + 'canceled_at', + 'collection_method', + 'created', + 'days_until_due', + 'default_source', + 'default_tax_rates', + 'discount', + 'ended_at', + 'livemode', + 'next_pending_invoice_item_invoice', + 'pause_collection', + 'pending_invoice_item_interval', + 'start_date', + 'transfer_data', + 'trial_end', + 'trial_start', + 'schedule', + 'customer', + 'latest_invoice', + 'plan', + ], } as const diff --git a/packages/sync-engine/src/schemas/subscription_item.ts b/packages/sync-engine/src/schemas/subscription_item.ts index 1f7f1d79d..75abad0e3 100644 --- a/packages/sync-engine/src/schemas/subscription_item.ts +++ b/packages/sync-engine/src/schemas/subscription_item.ts @@ -1,19 +1,16 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const subscriptionItemSchema: JsonSchema = { - $id: 'subscriptionItemSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - billing_thresholds: { type: 'object' }, - created: { type: 'number' }, - deleted: { type: 'boolean' }, - metadata: { type: 'object' }, - quantity: { type: 'number' }, - price: { type: 'string' }, - subscription: { type: 'string' }, - tax_rates: { type: 'object' }, - }, - required: ['id'], +export const subscriptionItemSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'billing_thresholds', + 'created', + 'deleted', + 'metadata', + 'quantity', + 'price', + 'subscription', + 'tax_rates', + ], } as const diff --git a/packages/sync-engine/src/schemas/subscription_schedules.ts b/packages/sync-engine/src/schemas/subscription_schedules.ts index 6ef5e6fd2..a27df1b33 100644 --- a/packages/sync-engine/src/schemas/subscription_schedules.ts +++ b/packages/sync-engine/src/schemas/subscription_schedules.ts @@ -1,27 +1,24 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const subscriptionScheduleSchema: JsonSchema = { - $id: 'subscriptionScheduleSchema', - type: 'object', - properties: { - id: { type: 'string' }, - object: { type: 'string' }, - application: { type: 'string' }, - canceled_at: { type: 'number' }, - completed_at: { type: 'number' }, - created: { type: 'number' }, - current_phase: { type: 'object' }, - customer: { type: 'string' }, - default_settings: { type: 'object' }, - end_behavior: { type: 'string' }, - livemode: { type: 'boolean' }, - metadata: { type: 'object' }, - phases: { type: 'object' }, - released_at: { type: 'number' }, - released_subscription: { type: 'string' }, - status: { type: 'string' }, - subscription: { type: 'string' }, - test_clock: { type: 'string' }, - }, - required: ['id'], +export const subscriptionScheduleSchema: EntitySchema = { + properties: [ + 'id', + 'object', + 'application', + 'canceled_at', + 'completed_at', + 'created', + 'current_phase', + 'customer', + 'default_settings', + 'end_behavior', + 'livemode', + 'metadata', + 'phases', + 'released_at', + 'released_subscription', + 'status', + 'subscription', + 'test_clock', + ], } as const diff --git a/packages/sync-engine/src/schemas/tax_id.ts b/packages/sync-engine/src/schemas/tax_id.ts index 9c0f3192b..6fb45c942 100644 --- a/packages/sync-engine/src/schemas/tax_id.ts +++ b/packages/sync-engine/src/schemas/tax_id.ts @@ -1,18 +1,15 @@ -import type { JsonSchema } from './types' +import type { EntitySchema } from './types' -export const taxIdSchema: JsonSchema = { - $id: 'taxIdSchema', - type: 'object', - properties: { - id: { type: 'string' }, - country: { type: 'string' }, - customer: { type: 'string' }, - type: { type: 'string' }, - value: { type: 'string' }, - object: { type: 'string' }, - created: { type: 'integer' }, - livemode: { type: 'boolean' }, - owner: { type: 'object' }, - }, - required: ['id'], +export const taxIdSchema: EntitySchema = { + properties: [ + 'id', + 'country', + 'customer', + 'type', + 'value', + 'object', + 'created', + 'livemode', + 'owner', + ], } as const diff --git a/packages/sync-engine/src/schemas/types.ts b/packages/sync-engine/src/schemas/types.ts index c47626a7e..4f9a491a3 100644 --- a/packages/sync-engine/src/schemas/types.ts +++ b/packages/sync-engine/src/schemas/types.ts @@ -1,6 +1,3 @@ -export interface JsonSchema { - readonly $id: string - readonly type: 'object' - readonly properties: Record - required: readonly string[] +export interface EntitySchema { + readonly properties: string[] }