@voyantjs/finance 0.5.0 → 0.6.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.
@@ -1,8 +1,11 @@
1
1
  import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
2
  import type { PublicBookingFinanceDocuments, PublicBookingFinancePayments, PublicFinanceDocumentLookup, PublicPaymentOptionsQuery, PublicStartPaymentSessionInput, PublicValidateVoucherInput } from "./validation-public.js";
3
+ export interface PublicFinanceRuntimeOptions {
4
+ resolveDocumentDownloadUrl?: (storageKey: string) => Promise<string | null> | string | null;
5
+ }
3
6
  export declare const publicFinanceService: {
4
- getBookingDocuments(db: PostgresJsDatabase, bookingId: string): Promise<PublicBookingFinanceDocuments | null>;
5
- getDocumentByReference(db: PostgresJsDatabase, reference: string): Promise<PublicFinanceDocumentLookup | null>;
7
+ getBookingDocuments(db: PostgresJsDatabase, bookingId: string, runtime?: PublicFinanceRuntimeOptions): Promise<PublicBookingFinanceDocuments | null>;
8
+ getDocumentByReference(db: PostgresJsDatabase, reference: string, runtime?: PublicFinanceRuntimeOptions): Promise<PublicFinanceDocumentLookup | null>;
6
9
  getBookingPaymentOptions(db: PostgresJsDatabase, bookingId: string, query: PublicPaymentOptionsQuery): Promise<{
7
10
  bookingId: string;
8
11
  accounts: {
@@ -20,7 +23,7 @@ export declare const publicFinanceService: {
20
23
  schedules: {
21
24
  id: string;
22
25
  scheduleType: "other" | "deposit" | "installment" | "balance" | "hold";
23
- status: "expired" | "cancelled" | "pending" | "paid" | "due" | "waived";
26
+ status: "pending" | "expired" | "cancelled" | "paid" | "due" | "waived";
24
27
  dueDate: string;
25
28
  currency: string;
26
29
  amountCents: number;
@@ -30,7 +33,7 @@ export declare const publicFinanceService: {
30
33
  id: string;
31
34
  bookingPaymentScheduleId: string | null;
32
35
  guaranteeType: "other" | "voucher" | "bank_transfer" | "credit_card" | "deposit" | "preauth" | "card_on_file" | "agency_letter";
33
- status: "expired" | "cancelled" | "pending" | "released" | "failed" | "active";
36
+ status: "pending" | "expired" | "cancelled" | "released" | "failed" | "active";
34
37
  currency: string | null;
35
38
  amountCents: number | null;
36
39
  provider: string | null;
@@ -52,7 +55,7 @@ export declare const publicFinanceService: {
52
55
  invoiceId: string | null;
53
56
  bookingPaymentScheduleId: string | null;
54
57
  bookingGuaranteeId: string | null;
55
- status: "expired" | "cancelled" | "pending" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
58
+ status: "pending" | "expired" | "cancelled" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
56
59
  provider: string | null;
57
60
  providerSessionId: string | null;
58
61
  providerPaymentId: string | null;
@@ -79,7 +82,7 @@ export declare const publicFinanceService: {
79
82
  invoiceId: string | null;
80
83
  bookingPaymentScheduleId: string | null;
81
84
  bookingGuaranteeId: string | null;
82
- status: "expired" | "cancelled" | "pending" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
85
+ status: "pending" | "expired" | "cancelled" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
83
86
  provider: string | null;
84
87
  providerSessionId: string | null;
85
88
  providerPaymentId: string | null;
@@ -106,7 +109,7 @@ export declare const publicFinanceService: {
106
109
  invoiceId: string | null;
107
110
  bookingPaymentScheduleId: string | null;
108
111
  bookingGuaranteeId: string | null;
109
- status: "expired" | "cancelled" | "pending" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
112
+ status: "pending" | "expired" | "cancelled" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
110
113
  provider: string | null;
111
114
  providerSessionId: string | null;
112
115
  providerPaymentId: string | null;
@@ -133,7 +136,7 @@ export declare const publicFinanceService: {
133
136
  invoiceId: string | null;
134
137
  bookingPaymentScheduleId: string | null;
135
138
  bookingGuaranteeId: string | null;
136
- status: "expired" | "cancelled" | "pending" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
139
+ status: "pending" | "expired" | "cancelled" | "failed" | "paid" | "requires_redirect" | "processing" | "authorized";
137
140
  provider: string | null;
138
141
  providerSessionId: string | null;
139
142
  providerPaymentId: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"service-public.d.ts","sourceRoot":"","sources":["../src/service-public.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAWjE,OAAO,KAAK,EACV,6BAA6B,EAC7B,4BAA4B,EAE5B,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC9B,0BAA0B,EAC3B,MAAM,wBAAwB,CAAA;AA4J/B,eAAO,MAAM,oBAAoB;4BAEzB,kBAAkB,aACX,MAAM,GAChB,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC;+BA2C1C,kBAAkB,aACX,MAAM,GAChB,OAAO,CAAC,2BAA2B,GAAG,IAAI,CAAC;iCA0CxC,kBAAkB,aACX,MAAM,SACV,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAoH5B,kBAAkB,aACX,MAAM,GAChB,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;0BA2DnB,kBAAkB,aAAa,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;2CAM3D,kBAAkB,aACX,MAAM,cACL,MAAM,SACX,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;4CA4BjC,kBAAkB,aACX,MAAM,eACJ,MAAM,SACZ,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAuBjC,kBAAkB,aACX,MAAM,SACV,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAMb,kBAAkB,SAAS,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8FhF,CAAA"}
1
+ {"version":3,"file":"service-public.d.ts","sourceRoot":"","sources":["../src/service-public.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE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  };
107
107
  }
108
- function mapInvoiceDocument(invoice, renditions) {
108
+ async function mapInvoiceDocument(invoice, renditions, runtime = {}) {
109
109
  const selectedRendition = renditions.find((rendition) => rendition.status === "ready") ?? renditions[0] ?? null;
110
110
  const metadata = getMetadataRecord(selectedRendition?.metadata ?? null);
111
- const downloadUrl = getMetadataDownloadUrl(metadata) ?? maybeUrl(selectedRendition?.storageKey ?? null);
111
+ const resolvedDownloadUrl = selectedRendition?.storageKey && runtime.resolveDocumentDownloadUrl
112
+ ? await runtime.resolveDocumentDownloadUrl(selectedRendition.storageKey)
113
+ : null;
114
+ const downloadUrl = resolvedDownloadUrl ??
115
+ getMetadataDownloadUrl(metadata) ??
116
+ maybeUrl(selectedRendition?.storageKey ?? null);
112
117
  return {
113
118
  invoiceId: invoice.id,
114
119
  invoiceNumber: invoice.invoiceNumber,
@@ -131,7 +136,7 @@ function mapInvoiceDocument(invoice, renditions) {
131
136
  };
132
137
  }
133
138
  export const publicFinanceService = {
134
- async getBookingDocuments(db, bookingId) {
139
+ async getBookingDocuments(db, bookingId, runtime = {}) {
135
140
  const [booking] = await db
136
141
  .select({ id: bookings.id })
137
142
  .from(bookings)
@@ -161,10 +166,10 @@ export const publicFinanceService = {
161
166
  }
162
167
  return {
163
168
  bookingId,
164
- documents: invoiceRows.map((invoice) => mapInvoiceDocument(invoice, renditionByInvoiceId.get(invoice.id) ?? [])),
169
+ documents: await Promise.all(invoiceRows.map((invoice) => mapInvoiceDocument(invoice, renditionByInvoiceId.get(invoice.id) ?? [], runtime))),
165
170
  };
166
171
  },
167
- async getDocumentByReference(db, reference) {
172
+ async getDocumentByReference(db, reference, runtime = {}) {
168
173
  const [invoiceMatch, paymentMatch] = await Promise.all([
169
174
  db
170
175
  .select()
@@ -196,7 +201,7 @@ export const publicFinanceService = {
196
201
  .orderBy(desc(invoiceRenditions.createdAt));
197
202
  return {
198
203
  bookingId: invoice.bookingId,
199
- ...mapInvoiceDocument(invoice, renditions),
204
+ ...(await mapInvoiceDocument(invoice, renditions, runtime)),
200
205
  };
201
206
  },
202
207
  async getBookingPaymentOptions(db, bookingId, query) {
@@ -1 +1 @@
1
- {"version":3,"file":"service-settlement.d.ts","sourceRoot":"","sources":["../src/service-settlement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE,OAAO,KAAK,EAAE,OAAO,IAAI,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhF,OAAO,KAAK,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAA;AAEhG,KAAK,iBAAiB,GAAG,cAAc,CAAA;AACvC,KAAK,qBAAqB,GAAG,kBAAkB,CAAA;AAE/C,MAAM,WAAW,8BAA8B;IAC7C,EAAE,EAAE,kBAAkB,CAAA;IACtB,OAAO,EAAE,iBAAiB,CAAA;IAC1B,WAAW,EAAE,qBAAqB,CAAA;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACjC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAChC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,SAAS,CAAC,EAAE,M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Q,EAAE,MAAM,CAAA;IAChB,uBAAuB,EAAE,MAAM,CAAA;IAC/B,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;CACxB;AAyED,eAAO,MAAM,wBAAwB;8BAE7B,kBAAkB,aACX,MAAM,SACV,0BAA0B,YACxB,+BAA+B,GACvC,OAAO,CAAC,6BAA6B,GAAG;QAAE,MAAM,EAAE,WAAW,CAAA;KAAE,CAAC;CA0JpE,CAAA"}
@@ -128,6 +128,9 @@ export const financeSettlementService = {
128
128
  newlyAppliedAmountCents,
129
129
  paidCents: invoice.paidCents,
130
130
  balanceDueCents: invoice.balanceDueCents,
131
+ }, {
132
+ category: "domain",
133
+ source: "service",
131
134
  });
132
135
  }
133
136
  }