@voyantjs/distribution 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,73 @@
1
+ import { typeId, typeIdRef } from "@voyantjs/db/lib/typeid-column";
2
+ import { boolean, index, integer, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
3
+ import { channelContracts, channels } from "./schema-core";
4
+ import { channelInventoryReleaseRules } from "./schema-inventory";
5
+ import { channelReconciliationPolicyFrequencyEnum, channelReleaseScheduleKindEnum, channelSettlementPolicyFrequencyEnum, } from "./schema-shared";
6
+ export const channelSettlementPolicies = pgTable("channel_settlement_policies", {
7
+ id: typeId("channel_settlement_policies"),
8
+ channelId: typeIdRef("channel_id")
9
+ .notNull()
10
+ .references(() => channels.id, { onDelete: "cascade" }),
11
+ contractId: typeIdRef("contract_id").references(() => channelContracts.id, {
12
+ onDelete: "set null",
13
+ }),
14
+ frequency: channelSettlementPolicyFrequencyEnum("frequency").notNull().default("manual"),
15
+ autoGenerate: boolean("auto_generate").notNull().default(false),
16
+ approvalRequired: boolean("approval_required").notNull().default(false),
17
+ remittanceDaysAfterPeriodEnd: integer("remittance_days_after_period_end"),
18
+ minimumPayoutAmountCents: integer("minimum_payout_amount_cents"),
19
+ currencyCode: text("currency_code"),
20
+ active: boolean("active").notNull().default(true),
21
+ notes: text("notes"),
22
+ metadata: jsonb("metadata").$type(),
23
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
24
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
25
+ }, (table) => [
26
+ index("idx_channel_settlement_policies_channel").on(table.channelId),
27
+ index("idx_channel_settlement_policies_contract").on(table.contractId),
28
+ index("idx_channel_settlement_policies_frequency").on(table.frequency),
29
+ index("idx_channel_settlement_policies_active").on(table.active),
30
+ ]);
31
+ export const channelReconciliationPolicies = pgTable("channel_reconciliation_policies", {
32
+ id: typeId("channel_reconciliation_policies"),
33
+ channelId: typeIdRef("channel_id")
34
+ .notNull()
35
+ .references(() => channels.id, { onDelete: "cascade" }),
36
+ contractId: typeIdRef("contract_id").references(() => channelContracts.id, {
37
+ onDelete: "set null",
38
+ }),
39
+ frequency: channelReconciliationPolicyFrequencyEnum("frequency").notNull().default("manual"),
40
+ autoRun: boolean("auto_run").notNull().default(false),
41
+ compareGrossAmounts: boolean("compare_gross_amounts").notNull().default(true),
42
+ compareStatuses: boolean("compare_statuses").notNull().default(true),
43
+ compareCancellations: boolean("compare_cancellations").notNull().default(true),
44
+ amountToleranceCents: integer("amount_tolerance_cents"),
45
+ active: boolean("active").notNull().default(true),
46
+ notes: text("notes"),
47
+ metadata: jsonb("metadata").$type(),
48
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
49
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
50
+ }, (table) => [
51
+ index("idx_channel_reconciliation_policies_channel").on(table.channelId),
52
+ index("idx_channel_reconciliation_policies_contract").on(table.contractId),
53
+ index("idx_channel_reconciliation_policies_frequency").on(table.frequency),
54
+ index("idx_channel_reconciliation_policies_active").on(table.active),
55
+ ]);
56
+ export const channelReleaseSchedules = pgTable("channel_release_schedules", {
57
+ id: typeId("channel_release_schedules"),
58
+ releaseRuleId: typeIdRef("release_rule_id")
59
+ .notNull()
60
+ .references(() => channelInventoryReleaseRules.id, { onDelete: "cascade" }),
61
+ scheduleKind: channelReleaseScheduleKindEnum("schedule_kind").notNull().default("manual"),
62
+ nextRunAt: timestamp("next_run_at", { withTimezone: true }),
63
+ lastRunAt: timestamp("last_run_at", { withTimezone: true }),
64
+ active: boolean("active").notNull().default(true),
65
+ notes: text("notes"),
66
+ metadata: jsonb("metadata").$type(),
67
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
68
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
69
+ }, (table) => [
70
+ index("idx_channel_release_schedules_rule").on(table.releaseRuleId),
71
+ index("idx_channel_release_schedules_kind").on(table.scheduleKind),
72
+ index("idx_channel_release_schedules_active").on(table.active),
73
+ ]);