@voyant-travel/distribution 0.109.8
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.
- package/LICENSE +201 -0
- package/README.md +42 -0
- package/dist/booking-extension.d.ts +168 -0
- package/dist/booking-extension.d.ts.map +1 -0
- package/dist/booking-extension.js +102 -0
- package/dist/channel-push/admin-routes.d.ts +31 -0
- package/dist/channel-push/admin-routes.d.ts.map +1 -0
- package/dist/channel-push/admin-routes.js +165 -0
- package/dist/channel-push/availability-push.d.ts +76 -0
- package/dist/channel-push/availability-push.d.ts.map +1 -0
- package/dist/channel-push/availability-push.js +236 -0
- package/dist/channel-push/booking-push-helpers.d.ts +36 -0
- package/dist/channel-push/booking-push-helpers.d.ts.map +1 -0
- package/dist/channel-push/booking-push-helpers.js +169 -0
- package/dist/channel-push/booking-push.d.ts +108 -0
- package/dist/channel-push/booking-push.d.ts.map +1 -0
- package/dist/channel-push/booking-push.js +335 -0
- package/dist/channel-push/boundary-sql.d.ts +23 -0
- package/dist/channel-push/boundary-sql.d.ts.map +1 -0
- package/dist/channel-push/boundary-sql.js +75 -0
- package/dist/channel-push/content-push.d.ts +60 -0
- package/dist/channel-push/content-push.d.ts.map +1 -0
- package/dist/channel-push/content-push.js +252 -0
- package/dist/channel-push/index.d.ts +15 -0
- package/dist/channel-push/index.d.ts.map +1 -0
- package/dist/channel-push/index.js +18 -0
- package/dist/channel-push/plugin.d.ts +18 -0
- package/dist/channel-push/plugin.d.ts.map +1 -0
- package/dist/channel-push/plugin.js +21 -0
- package/dist/channel-push/reconciler.d.ts +85 -0
- package/dist/channel-push/reconciler.d.ts.map +1 -0
- package/dist/channel-push/reconciler.js +179 -0
- package/dist/channel-push/subscriber.d.ts +40 -0
- package/dist/channel-push/subscriber.d.ts.map +1 -0
- package/dist/channel-push/subscriber.js +199 -0
- package/dist/channel-push/types.d.ts +43 -0
- package/dist/channel-push/types.d.ts.map +1 -0
- package/dist/channel-push/types.js +32 -0
- package/dist/channel-push/workflows.d.ts +56 -0
- package/dist/channel-push/workflows.d.ts.map +1 -0
- package/dist/channel-push/workflows.js +100 -0
- package/dist/external-refs/index.d.ts +11 -0
- package/dist/external-refs/index.d.ts.map +1 -0
- package/dist/external-refs/index.js +12 -0
- package/dist/external-refs/routes.d.ts +253 -0
- package/dist/external-refs/routes.d.ts.map +1 -0
- package/dist/external-refs/routes.js +52 -0
- package/dist/external-refs/schema.d.ts +251 -0
- package/dist/external-refs/schema.d.ts.map +1 -0
- package/dist/external-refs/schema.js +32 -0
- package/dist/external-refs/service.d.ts +82 -0
- package/dist/external-refs/service.d.ts.map +1 -0
- package/dist/external-refs/service.js +112 -0
- package/dist/external-refs/validation.d.ts +91 -0
- package/dist/external-refs/validation.d.ts.map +1 -0
- package/dist/external-refs/validation.js +40 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/interface-types.d.ts +128 -0
- package/dist/interface-types.d.ts.map +1 -0
- package/dist/interface-types.js +1 -0
- package/dist/interface.d.ts +10 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +286 -0
- package/dist/rate-limit.d.ts +69 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +135 -0
- package/dist/routes/batch.d.ts +200 -0
- package/dist/routes/batch.d.ts.map +1 -0
- package/dist/routes/batch.js +52 -0
- package/dist/routes/env.d.ts +8 -0
- package/dist/routes/env.d.ts.map +1 -0
- package/dist/routes/env.js +1 -0
- package/dist/routes/inventory.d.ts +604 -0
- package/dist/routes/inventory.d.ts.map +1 -0
- package/dist/routes/inventory.js +138 -0
- package/dist/routes/settlements.d.ts +1649 -0
- package/dist/routes/settlements.d.ts.map +1 -0
- package/dist/routes/settlements.js +265 -0
- package/dist/routes.d.ts +3909 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +323 -0
- package/dist/schema-automation.d.ts +680 -0
- package/dist/schema-automation.d.ts.map +1 -0
- package/dist/schema-automation.js +76 -0
- package/dist/schema-core.d.ts +1674 -0
- package/dist/schema-core.d.ts.map +1 -0
- package/dist/schema-core.js +227 -0
- package/dist/schema-finance.d.ts +1372 -0
- package/dist/schema-finance.d.ts.map +1 -0
- package/dist/schema-finance.js +153 -0
- package/dist/schema-inventory.d.ts +855 -0
- package/dist/schema-inventory.d.ts.map +1 -0
- package/dist/schema-inventory.js +102 -0
- package/dist/schema-push-intents.d.ts +387 -0
- package/dist/schema-push-intents.d.ts.map +1 -0
- package/dist/schema-push-intents.js +77 -0
- package/dist/schema-relations.d.ts +95 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +196 -0
- package/dist/schema-shared.d.ts +24 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +123 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +8 -0
- package/dist/service/channels.d.ts +167 -0
- package/dist/service/channels.d.ts.map +1 -0
- package/dist/service/channels.js +305 -0
- package/dist/service/commercial.d.ts +385 -0
- package/dist/service/commercial.d.ts.map +1 -0
- package/dist/service/commercial.js +248 -0
- package/dist/service/helpers.d.ts +10 -0
- package/dist/service/helpers.d.ts.map +1 -0
- package/dist/service/helpers.js +7 -0
- package/dist/service/inventory.d.ts +193 -0
- package/dist/service/inventory.d.ts.map +1 -0
- package/dist/service/inventory.js +154 -0
- package/dist/service/settlement-policies.d.ts +325 -0
- package/dist/service/settlement-policies.d.ts.map +1 -0
- package/dist/service/settlement-policies.js +272 -0
- package/dist/service/settlements.d.ts +357 -0
- package/dist/service/settlements.d.ts.map +1 -0
- package/dist/service/settlements.js +319 -0
- package/dist/service/types.d.ts +60 -0
- package/dist/service/types.d.ts.map +1 -0
- package/dist/service/types.js +1 -0
- package/dist/service.d.ts +1418 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +17 -0
- package/dist/suppliers/index.d.ts +15 -0
- package/dist/suppliers/index.d.ts.map +1 -0
- package/dist/suppliers/index.js +23 -0
- package/dist/suppliers/routes.d.ts +1202 -0
- package/dist/suppliers/routes.d.ts.map +1 -0
- package/dist/suppliers/routes.js +290 -0
- package/dist/suppliers/schema.d.ts +1272 -0
- package/dist/suppliers/schema.d.ts.map +1 -0
- package/dist/suppliers/schema.js +219 -0
- package/dist/suppliers/service-aggregates.d.ts +23 -0
- package/dist/suppliers/service-aggregates.d.ts.map +1 -0
- package/dist/suppliers/service-aggregates.js +51 -0
- package/dist/suppliers/service-core.d.ts +89 -0
- package/dist/suppliers/service-core.d.ts.map +1 -0
- package/dist/suppliers/service-core.js +164 -0
- package/dist/suppliers/service-identity.d.ts +162 -0
- package/dist/suppliers/service-identity.d.ts.map +1 -0
- package/dist/suppliers/service-identity.js +101 -0
- package/dist/suppliers/service-operations.d.ts +1500 -0
- package/dist/suppliers/service-operations.d.ts.map +1 -0
- package/dist/suppliers/service-operations.js +157 -0
- package/dist/suppliers/service-shared.d.ts +45 -0
- package/dist/suppliers/service-shared.d.ts.map +1 -0
- package/dist/suppliers/service-shared.js +294 -0
- package/dist/suppliers/service.d.ts +41 -0
- package/dist/suppliers/service.d.ts.map +1 -0
- package/dist/suppliers/service.js +40 -0
- package/dist/suppliers/validation.d.ts +2 -0
- package/dist/suppliers/validation.d.ts.map +1 -0
- package/dist/suppliers/validation.js +1 -0
- package/dist/validation.d.ts +1371 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +445 -0
- package/dist/webhook-deliveries.d.ts +86 -0
- package/dist/webhook-deliveries.d.ts.map +1 -0
- package/dist/webhook-deliveries.js +296 -0
- package/package.json +71 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-operations.d.ts","sourceRoot":"","sources":["../../src/suppliers/service-operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AASjE,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACvB,mB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B,kBAAkB,CACtC,EAAE,EAAE,kBAAkB,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,uBAAuB,EAAE;;;;;;;YAkBnC;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAMvE;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,mBAAmB;;;;;;;;;;;UAY1B;AAED,wBAAsB,cAAc,CAClC,EAAE,EAAE,kBAAkB,EACtB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,mBAAmB;;;;;;;;;;;UAQ1B;AAED,wBAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM;;UAM9E"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { and, asc, desc, eq, gte, lte } from "drizzle-orm";
|
|
2
|
+
import { supplierAvailability, supplierContracts, supplierNotes, supplierRates, supplierServices, } from "./schema.js";
|
|
3
|
+
import { ensureSupplierExists } from "./service-shared.js";
|
|
4
|
+
export function listServices(db, supplierId) {
|
|
5
|
+
return db
|
|
6
|
+
.select()
|
|
7
|
+
.from(supplierServices)
|
|
8
|
+
.where(eq(supplierServices.supplierId, supplierId))
|
|
9
|
+
.orderBy(supplierServices.createdAt);
|
|
10
|
+
}
|
|
11
|
+
export async function createService(db, supplierId, data) {
|
|
12
|
+
const supplier = await ensureSupplierExists(db, supplierId);
|
|
13
|
+
if (!supplier) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const [row] = await db
|
|
17
|
+
.insert(supplierServices)
|
|
18
|
+
.values({ ...data, supplierId })
|
|
19
|
+
.returning();
|
|
20
|
+
return row ?? null;
|
|
21
|
+
}
|
|
22
|
+
export async function updateService(db, serviceId, data) {
|
|
23
|
+
const [row] = await db
|
|
24
|
+
.update(supplierServices)
|
|
25
|
+
.set({ ...data, updatedAt: new Date() })
|
|
26
|
+
.where(eq(supplierServices.id, serviceId))
|
|
27
|
+
.returning();
|
|
28
|
+
return row ?? null;
|
|
29
|
+
}
|
|
30
|
+
export async function deleteService(db, serviceId) {
|
|
31
|
+
const [row] = await db
|
|
32
|
+
.delete(supplierServices)
|
|
33
|
+
.where(eq(supplierServices.id, serviceId))
|
|
34
|
+
.returning({ id: supplierServices.id });
|
|
35
|
+
return row ?? null;
|
|
36
|
+
}
|
|
37
|
+
export function listRates(db, serviceId) {
|
|
38
|
+
return db
|
|
39
|
+
.select()
|
|
40
|
+
.from(supplierRates)
|
|
41
|
+
.where(eq(supplierRates.serviceId, serviceId))
|
|
42
|
+
.orderBy(supplierRates.createdAt);
|
|
43
|
+
}
|
|
44
|
+
export async function createRate(db, serviceId, data) {
|
|
45
|
+
const [service] = await db
|
|
46
|
+
.select({ id: supplierServices.id })
|
|
47
|
+
.from(supplierServices)
|
|
48
|
+
.where(eq(supplierServices.id, serviceId))
|
|
49
|
+
.limit(1);
|
|
50
|
+
if (!service) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const [row] = await db
|
|
54
|
+
.insert(supplierRates)
|
|
55
|
+
.values({ ...data, serviceId })
|
|
56
|
+
.returning();
|
|
57
|
+
return row ?? null;
|
|
58
|
+
}
|
|
59
|
+
export async function updateRate(db, rateId, data) {
|
|
60
|
+
const [row] = await db
|
|
61
|
+
.update(supplierRates)
|
|
62
|
+
.set(data)
|
|
63
|
+
.where(eq(supplierRates.id, rateId))
|
|
64
|
+
.returning();
|
|
65
|
+
return row ?? null;
|
|
66
|
+
}
|
|
67
|
+
export async function deleteRate(db, rateId) {
|
|
68
|
+
const [row] = await db
|
|
69
|
+
.delete(supplierRates)
|
|
70
|
+
.where(eq(supplierRates.id, rateId))
|
|
71
|
+
.returning({ id: supplierRates.id });
|
|
72
|
+
return row ?? null;
|
|
73
|
+
}
|
|
74
|
+
export function listNotes(db, supplierId) {
|
|
75
|
+
return db
|
|
76
|
+
.select()
|
|
77
|
+
.from(supplierNotes)
|
|
78
|
+
.where(eq(supplierNotes.supplierId, supplierId))
|
|
79
|
+
.orderBy(supplierNotes.createdAt);
|
|
80
|
+
}
|
|
81
|
+
export async function createNote(db, supplierId, userId, data) {
|
|
82
|
+
const supplier = await ensureSupplierExists(db, supplierId);
|
|
83
|
+
if (!supplier) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const [row] = await db
|
|
87
|
+
.insert(supplierNotes)
|
|
88
|
+
.values({
|
|
89
|
+
supplierId,
|
|
90
|
+
authorId: userId,
|
|
91
|
+
content: data.content,
|
|
92
|
+
})
|
|
93
|
+
.returning();
|
|
94
|
+
return row ?? null;
|
|
95
|
+
}
|
|
96
|
+
export async function listAvailability(db, supplierId, query) {
|
|
97
|
+
const conditions = [eq(supplierAvailability.supplierId, supplierId)];
|
|
98
|
+
if (query.from) {
|
|
99
|
+
conditions.push(gte(supplierAvailability.date, query.from));
|
|
100
|
+
}
|
|
101
|
+
if (query.to) {
|
|
102
|
+
conditions.push(lte(supplierAvailability.date, query.to));
|
|
103
|
+
}
|
|
104
|
+
return db
|
|
105
|
+
.select()
|
|
106
|
+
.from(supplierAvailability)
|
|
107
|
+
.where(and(...conditions))
|
|
108
|
+
.orderBy(asc(supplierAvailability.date));
|
|
109
|
+
}
|
|
110
|
+
export async function createAvailability(db, supplierId, entries) {
|
|
111
|
+
const supplier = await ensureSupplierExists(db, supplierId);
|
|
112
|
+
if (!supplier) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
return db
|
|
116
|
+
.insert(supplierAvailability)
|
|
117
|
+
.values(entries.map((entry) => ({
|
|
118
|
+
supplierId,
|
|
119
|
+
date: entry.date,
|
|
120
|
+
available: entry.available,
|
|
121
|
+
notes: entry.notes ?? null,
|
|
122
|
+
})))
|
|
123
|
+
.returning();
|
|
124
|
+
}
|
|
125
|
+
export function listContracts(db, supplierId) {
|
|
126
|
+
return db
|
|
127
|
+
.select()
|
|
128
|
+
.from(supplierContracts)
|
|
129
|
+
.where(eq(supplierContracts.supplierId, supplierId))
|
|
130
|
+
.orderBy(desc(supplierContracts.createdAt));
|
|
131
|
+
}
|
|
132
|
+
export async function createContract(db, supplierId, data) {
|
|
133
|
+
const supplier = await ensureSupplierExists(db, supplierId);
|
|
134
|
+
if (!supplier) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
const [row] = await db
|
|
138
|
+
.insert(supplierContracts)
|
|
139
|
+
.values({ ...data, supplierId })
|
|
140
|
+
.returning();
|
|
141
|
+
return row ?? null;
|
|
142
|
+
}
|
|
143
|
+
export async function updateContract(db, contractId, data) {
|
|
144
|
+
const [row] = await db
|
|
145
|
+
.update(supplierContracts)
|
|
146
|
+
.set({ ...data, updatedAt: new Date() })
|
|
147
|
+
.where(eq(supplierContracts.id, contractId))
|
|
148
|
+
.returning();
|
|
149
|
+
return row ?? null;
|
|
150
|
+
}
|
|
151
|
+
export async function deleteContract(db, contractId) {
|
|
152
|
+
const [row] = await db
|
|
153
|
+
.delete(supplierContracts)
|
|
154
|
+
.where(eq(supplierContracts.id, contractId))
|
|
155
|
+
.returning({ id: supplierContracts.id });
|
|
156
|
+
return row ?? null;
|
|
157
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { Supplier } from "./schema.js";
|
|
4
|
+
import type { availabilityQuerySchema, insertAvailabilitySchema, insertContractSchema, insertRateSchema, insertServiceSchema, insertSupplierNoteSchema, insertSupplierSchema, supplierListQuerySchema, updateContractSchema, updateRateSchema, updateServiceSchema, updateSupplierSchema } from "./validation.js";
|
|
5
|
+
export type SupplierListQuery = z.infer<typeof supplierListQuerySchema>;
|
|
6
|
+
export type AvailabilityQuery = z.infer<typeof availabilityQuerySchema>;
|
|
7
|
+
export type CreateSupplierInput = z.infer<typeof insertSupplierSchema>;
|
|
8
|
+
export type UpdateSupplierInput = z.infer<typeof updateSupplierSchema>;
|
|
9
|
+
export type CreateServiceInput = z.infer<typeof insertServiceSchema>;
|
|
10
|
+
export type UpdateServiceInput = z.infer<typeof updateServiceSchema>;
|
|
11
|
+
export type CreateRateInput = z.infer<typeof insertRateSchema>;
|
|
12
|
+
export type UpdateRateInput = z.infer<typeof updateRateSchema>;
|
|
13
|
+
export type CreateSupplierNoteInput = z.infer<typeof insertSupplierNoteSchema>;
|
|
14
|
+
export type CreateAvailabilityInput = z.infer<typeof insertAvailabilitySchema>;
|
|
15
|
+
export type CreateContractInput = z.infer<typeof insertContractSchema>;
|
|
16
|
+
export type UpdateContractInput = z.infer<typeof updateContractSchema>;
|
|
17
|
+
export declare const supplierEntityType = "supplier";
|
|
18
|
+
export declare const supplierBaseIdentitySource = "suppliers.base";
|
|
19
|
+
export declare const supplierPrimaryNamedContactSource = "suppliers.primary_contact";
|
|
20
|
+
export type SupplierIdentityInput = Pick<CreateSupplierInput, "email" | "phone" | "website" | "address" | "city" | "country" | "contactName" | "contactEmail" | "contactPhone">;
|
|
21
|
+
export type SupplierHydratedFields = {
|
|
22
|
+
email: string | null;
|
|
23
|
+
phone: string | null;
|
|
24
|
+
website: string | null;
|
|
25
|
+
address: string | null;
|
|
26
|
+
city: string | null;
|
|
27
|
+
country: string | null;
|
|
28
|
+
contactName: string | null;
|
|
29
|
+
contactEmail: string | null;
|
|
30
|
+
contactPhone: string | null;
|
|
31
|
+
};
|
|
32
|
+
export type HydratedSupplier = Supplier & SupplierHydratedFields;
|
|
33
|
+
export declare function ensureSupplierExists(db: PostgresJsDatabase, supplierId: string): Promise<{
|
|
34
|
+
id: string;
|
|
35
|
+
} | null>;
|
|
36
|
+
export declare function rebuildSupplierDirectoryProjection(db: PostgresJsDatabase, supplierId: string): Promise<void>;
|
|
37
|
+
export declare function rebuildSupplierDirectoryProjections(db: PostgresJsDatabase, supplierIds: string[]): Promise<void>;
|
|
38
|
+
export declare function syncSupplierIdentity(db: PostgresJsDatabase, supplierId: string, data: SupplierIdentityInput): Promise<void>;
|
|
39
|
+
export declare function hydrateSuppliers<T extends {
|
|
40
|
+
id: string;
|
|
41
|
+
contactName?: string | null;
|
|
42
|
+
contactEmail?: string | null;
|
|
43
|
+
contactPhone?: string | null;
|
|
44
|
+
}>(db: PostgresJsDatabase, rows: T[]): Promise<Array<T & SupplierHydratedFields>>;
|
|
45
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../../src/suppliers/service-shared.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAExB,MAAM,MAAM,iBAAiB,GAAG,CAAC,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 @@
|
|
|
1
|
+
import { identityAddresses, identityContactPoints, identityNamedContacts, } from "@voyant-travel/identity/schema";
|
|
2
|
+
import { identityService } from "@voyant-travel/identity/service";
|
|
3
|
+
import { and, eq, inArray } from "drizzle-orm";
|
|
4
|
+
import { supplierDirectoryProjections, suppliers } from "./schema.js";
|
|
5
|
+
export const supplierEntityType = "supplier";
|
|
6
|
+
export const supplierBaseIdentitySource = "suppliers.base";
|
|
7
|
+
export const supplierPrimaryNamedContactSource = "suppliers.primary_contact";
|
|
8
|
+
function normalizeContactValue(kind, value) {
|
|
9
|
+
if (kind === "email" || kind === "website") {
|
|
10
|
+
return value.trim().toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
return value.trim();
|
|
13
|
+
}
|
|
14
|
+
function isManagedBySource(metadata, source) {
|
|
15
|
+
return metadata?.managedBy === source;
|
|
16
|
+
}
|
|
17
|
+
function toNullableTrimmed(value) {
|
|
18
|
+
const trimmed = value?.trim();
|
|
19
|
+
return trimmed ? trimmed : null;
|
|
20
|
+
}
|
|
21
|
+
function formatAddress(address) {
|
|
22
|
+
if (address.fullText) {
|
|
23
|
+
return address.fullText;
|
|
24
|
+
}
|
|
25
|
+
const parts = [
|
|
26
|
+
address.line1,
|
|
27
|
+
address.line2,
|
|
28
|
+
address.city,
|
|
29
|
+
address.region,
|
|
30
|
+
address.postalCode,
|
|
31
|
+
address.country,
|
|
32
|
+
].filter(Boolean);
|
|
33
|
+
return parts.length > 0 ? parts.join(", ") : null;
|
|
34
|
+
}
|
|
35
|
+
export async function ensureSupplierExists(db, supplierId) {
|
|
36
|
+
const [supplier] = await db
|
|
37
|
+
.select({ id: suppliers.id })
|
|
38
|
+
.from(suppliers)
|
|
39
|
+
.where(eq(suppliers.id, supplierId))
|
|
40
|
+
.limit(1);
|
|
41
|
+
return supplier ?? null;
|
|
42
|
+
}
|
|
43
|
+
function emptySupplierHydratedFields() {
|
|
44
|
+
return {
|
|
45
|
+
email: null,
|
|
46
|
+
phone: null,
|
|
47
|
+
website: null,
|
|
48
|
+
address: null,
|
|
49
|
+
city: null,
|
|
50
|
+
country: null,
|
|
51
|
+
contactName: null,
|
|
52
|
+
contactEmail: null,
|
|
53
|
+
contactPhone: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async function buildSupplierDirectoryProjectionRows(db, supplierIds) {
|
|
57
|
+
if (supplierIds.length === 0) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const ids = [...new Set(supplierIds)];
|
|
61
|
+
const [contactPoints, addresses, namedContacts] = await Promise.all([
|
|
62
|
+
db
|
|
63
|
+
.select()
|
|
64
|
+
.from(identityContactPoints)
|
|
65
|
+
.where(and(eq(identityContactPoints.entityType, supplierEntityType), inArray(identityContactPoints.entityId, ids))),
|
|
66
|
+
db
|
|
67
|
+
.select()
|
|
68
|
+
.from(identityAddresses)
|
|
69
|
+
.where(and(eq(identityAddresses.entityType, supplierEntityType), inArray(identityAddresses.entityId, ids))),
|
|
70
|
+
db
|
|
71
|
+
.select()
|
|
72
|
+
.from(identityNamedContacts)
|
|
73
|
+
.where(and(eq(identityNamedContacts.entityType, supplierEntityType), inArray(identityNamedContacts.entityId, ids))),
|
|
74
|
+
]);
|
|
75
|
+
const contactPointMap = new Map();
|
|
76
|
+
const addressMap = new Map();
|
|
77
|
+
const namedContactMap = new Map();
|
|
78
|
+
for (const point of contactPoints) {
|
|
79
|
+
const bucket = contactPointMap.get(point.entityId) ?? [];
|
|
80
|
+
bucket.push(point);
|
|
81
|
+
contactPointMap.set(point.entityId, bucket);
|
|
82
|
+
}
|
|
83
|
+
for (const address of addresses) {
|
|
84
|
+
const bucket = addressMap.get(address.entityId) ?? [];
|
|
85
|
+
bucket.push(address);
|
|
86
|
+
addressMap.set(address.entityId, bucket);
|
|
87
|
+
}
|
|
88
|
+
for (const contact of namedContacts) {
|
|
89
|
+
const bucket = namedContactMap.get(contact.entityId) ?? [];
|
|
90
|
+
bucket.push(contact);
|
|
91
|
+
namedContactMap.set(contact.entityId, bucket);
|
|
92
|
+
}
|
|
93
|
+
return ids.map((supplierId) => {
|
|
94
|
+
const entityContactPoints = contactPointMap.get(supplierId) ?? [];
|
|
95
|
+
const entityAddresses = addressMap.get(supplierId) ?? [];
|
|
96
|
+
const entityNamedContacts = namedContactMap.get(supplierId) ?? [];
|
|
97
|
+
const pickContactValue = (kind) => entityContactPoints.find((point) => point.kind === kind && point.isPrimary)?.value ??
|
|
98
|
+
entityContactPoints.find((point) => point.kind === kind)?.value ??
|
|
99
|
+
null;
|
|
100
|
+
const primaryAddress = entityAddresses.find((address) => address.isPrimary) ?? entityAddresses[0] ?? null;
|
|
101
|
+
const primaryContact = entityNamedContacts.find((contact) => contact.isPrimary) ?? entityNamedContacts[0] ?? null;
|
|
102
|
+
return {
|
|
103
|
+
supplierId,
|
|
104
|
+
email: pickContactValue("email"),
|
|
105
|
+
phone: pickContactValue("phone"),
|
|
106
|
+
website: pickContactValue("website"),
|
|
107
|
+
address: primaryAddress ? formatAddress(primaryAddress) : null,
|
|
108
|
+
city: primaryAddress?.city ?? null,
|
|
109
|
+
country: primaryAddress?.country ?? null,
|
|
110
|
+
contactName: primaryContact?.name ?? null,
|
|
111
|
+
contactEmail: primaryContact?.email ?? null,
|
|
112
|
+
contactPhone: primaryContact?.phone ?? null,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export async function rebuildSupplierDirectoryProjection(db, supplierId) {
|
|
117
|
+
return rebuildSupplierDirectoryProjections(db, [supplierId]);
|
|
118
|
+
}
|
|
119
|
+
export async function rebuildSupplierDirectoryProjections(db, supplierIds) {
|
|
120
|
+
const ids = [...new Set(supplierIds)];
|
|
121
|
+
if (ids.length === 0) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const rows = await buildSupplierDirectoryProjectionRows(db, ids);
|
|
125
|
+
await db
|
|
126
|
+
.delete(supplierDirectoryProjections)
|
|
127
|
+
.where(inArray(supplierDirectoryProjections.supplierId, ids));
|
|
128
|
+
await db.insert(supplierDirectoryProjections).values(rows);
|
|
129
|
+
}
|
|
130
|
+
async function ensureSupplierDirectoryProjectionMap(db, supplierIds) {
|
|
131
|
+
const ids = [...new Set(supplierIds)];
|
|
132
|
+
if (ids.length === 0) {
|
|
133
|
+
return new Map();
|
|
134
|
+
}
|
|
135
|
+
const existing = await db
|
|
136
|
+
.select()
|
|
137
|
+
.from(supplierDirectoryProjections)
|
|
138
|
+
.where(inArray(supplierDirectoryProjections.supplierId, ids));
|
|
139
|
+
const map = new Map();
|
|
140
|
+
for (const projection of existing) {
|
|
141
|
+
map.set(projection.supplierId, {
|
|
142
|
+
email: projection.email,
|
|
143
|
+
phone: projection.phone,
|
|
144
|
+
website: projection.website,
|
|
145
|
+
address: projection.address,
|
|
146
|
+
city: projection.city,
|
|
147
|
+
country: projection.country,
|
|
148
|
+
contactName: projection.contactName,
|
|
149
|
+
contactEmail: projection.contactEmail,
|
|
150
|
+
contactPhone: projection.contactPhone,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const missingIds = ids.filter((id) => !map.has(id));
|
|
154
|
+
if (missingIds.length > 0) {
|
|
155
|
+
await rebuildSupplierDirectoryProjections(db, missingIds);
|
|
156
|
+
const rebuilt = await db
|
|
157
|
+
.select()
|
|
158
|
+
.from(supplierDirectoryProjections)
|
|
159
|
+
.where(inArray(supplierDirectoryProjections.supplierId, missingIds));
|
|
160
|
+
for (const projection of rebuilt) {
|
|
161
|
+
map.set(projection.supplierId, {
|
|
162
|
+
email: projection.email,
|
|
163
|
+
phone: projection.phone,
|
|
164
|
+
website: projection.website,
|
|
165
|
+
address: projection.address,
|
|
166
|
+
city: projection.city,
|
|
167
|
+
country: projection.country,
|
|
168
|
+
contactName: projection.contactName,
|
|
169
|
+
contactEmail: projection.contactEmail,
|
|
170
|
+
contactPhone: projection.contactPhone,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const id of ids) {
|
|
175
|
+
if (!map.has(id)) {
|
|
176
|
+
map.set(id, emptySupplierHydratedFields());
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return map;
|
|
180
|
+
}
|
|
181
|
+
export async function syncSupplierIdentity(db, supplierId, data) {
|
|
182
|
+
const existingContactPoints = await identityService.listContactPointsForEntity(db, supplierEntityType, supplierId);
|
|
183
|
+
const existingAddresses = await identityService.listAddressesForEntity(db, supplierEntityType, supplierId);
|
|
184
|
+
const existingNamedContacts = await identityService.listNamedContactsForEntity(db, supplierEntityType, supplierId);
|
|
185
|
+
const managedContactPoints = existingContactPoints.filter((point) => isManagedBySource(point.metadata, supplierBaseIdentitySource));
|
|
186
|
+
const managedAddress = existingAddresses.find((address) => isManagedBySource(address.metadata, supplierBaseIdentitySource));
|
|
187
|
+
const managedPrimaryContact = existingNamedContacts.find((contact) => isManagedBySource(contact.metadata, supplierPrimaryNamedContactSource));
|
|
188
|
+
for (const [kind, rawValue] of Object.entries({
|
|
189
|
+
email: data.email,
|
|
190
|
+
phone: data.phone,
|
|
191
|
+
website: data.website,
|
|
192
|
+
})) {
|
|
193
|
+
const value = toNullableTrimmed(rawValue);
|
|
194
|
+
const existing = managedContactPoints.find((point) => point.kind === kind) ??
|
|
195
|
+
existingContactPoints.find((point) => point.kind === kind && point.isPrimary);
|
|
196
|
+
if (!value) {
|
|
197
|
+
if (existing) {
|
|
198
|
+
await identityService.deleteContactPoint(db, existing.id);
|
|
199
|
+
}
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const payload = {
|
|
203
|
+
entityType: supplierEntityType,
|
|
204
|
+
entityId: supplierId,
|
|
205
|
+
kind,
|
|
206
|
+
label: kind === "website" ? "website" : "primary",
|
|
207
|
+
value,
|
|
208
|
+
normalizedValue: normalizeContactValue(kind, value),
|
|
209
|
+
isPrimary: true,
|
|
210
|
+
metadata: {
|
|
211
|
+
managedBy: supplierBaseIdentitySource,
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
if (existing) {
|
|
215
|
+
await identityService.updateContactPoint(db, existing.id, payload);
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
await identityService.createContactPoint(db, payload);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const addressLine = toNullableTrimmed(data.address);
|
|
222
|
+
const city = toNullableTrimmed(data.city);
|
|
223
|
+
const country = toNullableTrimmed(data.country);
|
|
224
|
+
const hasAddress = Boolean(addressLine || city || country);
|
|
225
|
+
if (!hasAddress) {
|
|
226
|
+
if (managedAddress) {
|
|
227
|
+
await identityService.deleteAddress(db, managedAddress.id);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const addressPayload = {
|
|
232
|
+
entityType: supplierEntityType,
|
|
233
|
+
entityId: supplierId,
|
|
234
|
+
label: "primary",
|
|
235
|
+
fullText: addressLine,
|
|
236
|
+
line1: addressLine,
|
|
237
|
+
city,
|
|
238
|
+
country,
|
|
239
|
+
isPrimary: true,
|
|
240
|
+
metadata: {
|
|
241
|
+
managedBy: supplierBaseIdentitySource,
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
if (managedAddress) {
|
|
245
|
+
await identityService.updateAddress(db, managedAddress.id, addressPayload);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
await identityService.createAddress(db, addressPayload);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const contactName = toNullableTrimmed(data.contactName);
|
|
252
|
+
const contactEmail = toNullableTrimmed(data.contactEmail);
|
|
253
|
+
const contactPhone = toNullableTrimmed(data.contactPhone);
|
|
254
|
+
const hasPrimaryContact = Boolean(contactName || contactEmail || contactPhone);
|
|
255
|
+
if (!hasPrimaryContact) {
|
|
256
|
+
if (managedPrimaryContact) {
|
|
257
|
+
await identityService.deleteNamedContact(db, managedPrimaryContact.id);
|
|
258
|
+
}
|
|
259
|
+
await rebuildSupplierDirectoryProjection(db, supplierId);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const namedContactPayload = {
|
|
263
|
+
entityType: supplierEntityType,
|
|
264
|
+
entityId: supplierId,
|
|
265
|
+
role: "primary",
|
|
266
|
+
name: contactName ?? contactEmail ?? contactPhone ?? "Primary contact",
|
|
267
|
+
email: contactEmail,
|
|
268
|
+
phone: contactPhone,
|
|
269
|
+
isPrimary: true,
|
|
270
|
+
metadata: {
|
|
271
|
+
managedBy: supplierPrimaryNamedContactSource,
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
if (managedPrimaryContact) {
|
|
275
|
+
await identityService.updateNamedContact(db, managedPrimaryContact.id, namedContactPayload);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
await identityService.createNamedContact(db, namedContactPayload);
|
|
279
|
+
}
|
|
280
|
+
await rebuildSupplierDirectoryProjection(db, supplierId);
|
|
281
|
+
}
|
|
282
|
+
export async function hydrateSuppliers(db, rows) {
|
|
283
|
+
if (rows.length === 0) {
|
|
284
|
+
return rows.map((row) => ({ ...row, ...emptySupplierHydratedFields() }));
|
|
285
|
+
}
|
|
286
|
+
const ids = rows.map((row) => row.id);
|
|
287
|
+
const projectionMap = await ensureSupplierDirectoryProjectionMap(db, ids);
|
|
288
|
+
return rows.map((row) => {
|
|
289
|
+
return {
|
|
290
|
+
...row,
|
|
291
|
+
...(projectionMap.get(row.id) ?? emptySupplierHydratedFields()),
|
|
292
|
+
};
|
|
293
|
+
});
|
|
294
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getSupplierAggregates } from "./service-aggregates.js";
|
|
2
|
+
import { createSupplier, deleteSupplier, getSupplierById, listSuppliers, updateSupplier } from "./service-core.js";
|
|
3
|
+
import { createAddress, createContactPoint, createNamedContact, deleteAddress, deleteContactPoint, deleteNamedContact, listAddresses, listContactPoints, listNamedContacts, updateAddress, updateContactPoint, updateNamedContact } from "./service-identity.js";
|
|
4
|
+
import { createAvailability, createContract, createNote, createRate, createService, deleteContract, deleteRate, deleteService, listAvailability, listContracts, listNotes, listRates, listServices, updateContract, updateRate, updateService } from "./service-operations.js";
|
|
5
|
+
export declare const suppliersService: {
|
|
6
|
+
getSupplierAggregates: typeof getSupplierAggregates;
|
|
7
|
+
listSuppliers: typeof listSuppliers;
|
|
8
|
+
getSupplierById: typeof getSupplierById;
|
|
9
|
+
createSupplier: typeof createSupplier;
|
|
10
|
+
updateSupplier: typeof updateSupplier;
|
|
11
|
+
deleteSupplier: typeof deleteSupplier;
|
|
12
|
+
listContactPoints: typeof listContactPoints;
|
|
13
|
+
listNamedContacts: typeof listNamedContacts;
|
|
14
|
+
createNamedContact: typeof createNamedContact;
|
|
15
|
+
updateNamedContact: typeof updateNamedContact;
|
|
16
|
+
deleteNamedContact: typeof deleteNamedContact;
|
|
17
|
+
createContactPoint: typeof createContactPoint;
|
|
18
|
+
updateContactPoint: typeof updateContactPoint;
|
|
19
|
+
deleteContactPoint: typeof deleteContactPoint;
|
|
20
|
+
listAddresses: typeof listAddresses;
|
|
21
|
+
createAddress: typeof createAddress;
|
|
22
|
+
updateAddress: typeof updateAddress;
|
|
23
|
+
deleteAddress: typeof deleteAddress;
|
|
24
|
+
listServices: typeof listServices;
|
|
25
|
+
createService: typeof createService;
|
|
26
|
+
updateService: typeof updateService;
|
|
27
|
+
deleteService: typeof deleteService;
|
|
28
|
+
listRates: typeof listRates;
|
|
29
|
+
createRate: typeof createRate;
|
|
30
|
+
updateRate: typeof updateRate;
|
|
31
|
+
deleteRate: typeof deleteRate;
|
|
32
|
+
listNotes: typeof listNotes;
|
|
33
|
+
createNote: typeof createNote;
|
|
34
|
+
listAvailability: typeof listAvailability;
|
|
35
|
+
createAvailability: typeof createAvailability;
|
|
36
|
+
listContracts: typeof listContracts;
|
|
37
|
+
createContract: typeof createContract;
|
|
38
|
+
updateContract: typeof updateContract;
|
|
39
|
+
deleteContract: typeof deleteContract;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/suppliers/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EACL,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,cAAc,EACf,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,SAAS,EACT,YAAY,EACZ,cAAc,EACd,UAAU,EACV,aAAa,EACd,MAAM,yBAAyB,CAAA;AAEhC,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmC5B,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getSupplierAggregates } from "./service-aggregates.js";
|
|
2
|
+
import { createSupplier, deleteSupplier, getSupplierById, listSuppliers, updateSupplier, } from "./service-core.js";
|
|
3
|
+
import { createAddress, createContactPoint, createNamedContact, deleteAddress, deleteContactPoint, deleteNamedContact, listAddresses, listContactPoints, listNamedContacts, updateAddress, updateContactPoint, updateNamedContact, } from "./service-identity.js";
|
|
4
|
+
import { createAvailability, createContract, createNote, createRate, createService, deleteContract, deleteRate, deleteService, listAvailability, listContracts, listNotes, listRates, listServices, updateContract, updateRate, updateService, } from "./service-operations.js";
|
|
5
|
+
export const suppliersService = {
|
|
6
|
+
getSupplierAggregates,
|
|
7
|
+
listSuppliers,
|
|
8
|
+
getSupplierById,
|
|
9
|
+
createSupplier,
|
|
10
|
+
updateSupplier,
|
|
11
|
+
deleteSupplier,
|
|
12
|
+
listContactPoints,
|
|
13
|
+
listNamedContacts,
|
|
14
|
+
createNamedContact,
|
|
15
|
+
updateNamedContact,
|
|
16
|
+
deleteNamedContact,
|
|
17
|
+
createContactPoint,
|
|
18
|
+
updateContactPoint,
|
|
19
|
+
deleteContactPoint,
|
|
20
|
+
listAddresses,
|
|
21
|
+
createAddress,
|
|
22
|
+
updateAddress,
|
|
23
|
+
deleteAddress,
|
|
24
|
+
listServices,
|
|
25
|
+
createService,
|
|
26
|
+
updateService,
|
|
27
|
+
deleteService,
|
|
28
|
+
listRates,
|
|
29
|
+
createRate,
|
|
30
|
+
updateRate,
|
|
31
|
+
deleteRate,
|
|
32
|
+
listNotes,
|
|
33
|
+
createNote,
|
|
34
|
+
listAvailability,
|
|
35
|
+
createAvailability,
|
|
36
|
+
listContracts,
|
|
37
|
+
createContract,
|
|
38
|
+
updateContract,
|
|
39
|
+
deleteContract,
|
|
40
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/suppliers/validation.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@voyant-travel/suppliers-contracts";
|