@voyantjs/distribution-react 0.1.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.
- package/README.md +32 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +59 -0
- package/dist/constants.d.ts +100 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +47 -0
- package/dist/hooks/index.d.ts +12 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/use-booking-links.d.ts +20 -0
- package/dist/hooks/use-booking-links.d.ts.map +1 -0
- package/dist/hooks/use-booking-links.js +9 -0
- package/dist/hooks/use-bookings.d.ts +14 -0
- package/dist/hooks/use-bookings.d.ts.map +1 -0
- package/dist/hooks/use-bookings.js +9 -0
- package/dist/hooks/use-channel-mutation.d.ts +68 -0
- package/dist/hooks/use-channel-mutation.d.ts.map +1 -0
- package/dist/hooks/use-channel-mutation.js +49 -0
- package/dist/hooks/use-channel.d.ts +16 -0
- package/dist/hooks/use-channel.d.ts.map +1 -0
- package/dist/hooks/use-channel.js +13 -0
- package/dist/hooks/use-channels.d.ts +20 -0
- package/dist/hooks/use-channels.d.ts.map +1 -0
- package/dist/hooks/use-channels.js +9 -0
- package/dist/hooks/use-commission-rules.d.ts +23 -0
- package/dist/hooks/use-commission-rules.d.ts.map +1 -0
- package/dist/hooks/use-commission-rules.js +9 -0
- package/dist/hooks/use-contracts.d.ts +22 -0
- package/dist/hooks/use-contracts.d.ts.map +1 -0
- package/dist/hooks/use-contracts.js +9 -0
- package/dist/hooks/use-mappings.d.ts +19 -0
- package/dist/hooks/use-mappings.d.ts.map +1 -0
- package/dist/hooks/use-mappings.js +9 -0
- package/dist/hooks/use-products.d.ts +14 -0
- package/dist/hooks/use-products.d.ts.map +1 -0
- package/dist/hooks/use-products.js +9 -0
- package/dist/hooks/use-suppliers.d.ts +14 -0
- package/dist/hooks/use-suppliers.d.ts.map +1 -0
- package/dist/hooks/use-suppliers.js +9 -0
- package/dist/hooks/use-webhook-events.d.ts +21 -0
- package/dist/hooks/use-webhook-events.d.ts.map +1 -0
- package/dist/hooks/use-webhook-events.js +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/provider.d.ts +2 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +1 -0
- package/dist/query-keys.d.ts +61 -0
- package/dist/query-keys.d.ts.map +1 -0
- package/dist/query-keys.js +30 -0
- package/dist/query-options.d.ts +999 -0
- package/dist/query-options.d.ts.map +1 -0
- package/dist/query-options.js +219 -0
- package/dist/schemas.d.ts +610 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +143 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +44 -0
- package/package.json +79 -0
package/dist/schemas.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const paginatedEnvelope = (item) => z.object({
|
|
3
|
+
data: z.array(item),
|
|
4
|
+
total: z.number().int(),
|
|
5
|
+
limit: z.number().int(),
|
|
6
|
+
offset: z.number().int(),
|
|
7
|
+
});
|
|
8
|
+
export const singleEnvelope = (item) => z.object({ data: item });
|
|
9
|
+
export const successEnvelope = z.object({ success: z.boolean() });
|
|
10
|
+
export const supplierOptionSchema = z.object({
|
|
11
|
+
id: z.string(),
|
|
12
|
+
name: z.string(),
|
|
13
|
+
});
|
|
14
|
+
export const productOptionSchema = z.object({
|
|
15
|
+
id: z.string(),
|
|
16
|
+
name: z.string(),
|
|
17
|
+
});
|
|
18
|
+
export const bookingOptionSchema = z.object({
|
|
19
|
+
id: z.string(),
|
|
20
|
+
bookingNumber: z.string(),
|
|
21
|
+
});
|
|
22
|
+
export const channelKindSchema = z.enum([
|
|
23
|
+
"direct",
|
|
24
|
+
"affiliate",
|
|
25
|
+
"ota",
|
|
26
|
+
"reseller",
|
|
27
|
+
"marketplace",
|
|
28
|
+
"api_partner",
|
|
29
|
+
]);
|
|
30
|
+
export const channelStatusSchema = z.enum(["active", "inactive", "pending", "archived"]);
|
|
31
|
+
export const contractStatusSchema = z.enum(["draft", "active", "expired", "terminated"]);
|
|
32
|
+
export const paymentOwnerSchema = z.enum(["operator", "channel", "split"]);
|
|
33
|
+
export const cancellationOwnerSchema = z.enum(["operator", "channel", "mixed"]);
|
|
34
|
+
export const commissionScopeSchema = z.enum(["booking", "product", "rate", "category"]);
|
|
35
|
+
export const commissionTypeSchema = z.enum(["fixed", "percentage"]);
|
|
36
|
+
export const webhookStatusSchema = z.enum(["pending", "processed", "failed", "ignored"]);
|
|
37
|
+
export const channelRecordSchema = z.object({
|
|
38
|
+
id: z.string(),
|
|
39
|
+
name: z.string(),
|
|
40
|
+
kind: channelKindSchema,
|
|
41
|
+
status: channelStatusSchema,
|
|
42
|
+
website: z.string().nullable(),
|
|
43
|
+
contactName: z.string().nullable(),
|
|
44
|
+
contactEmail: z.string().nullable(),
|
|
45
|
+
metadata: z.record(z.string(), z.unknown()).nullable(),
|
|
46
|
+
});
|
|
47
|
+
export const channelDetailSchema = channelRecordSchema.extend({
|
|
48
|
+
createdAt: z.string(),
|
|
49
|
+
updatedAt: z.string(),
|
|
50
|
+
});
|
|
51
|
+
export const channelContractRecordSchema = z.object({
|
|
52
|
+
id: z.string(),
|
|
53
|
+
channelId: z.string(),
|
|
54
|
+
supplierId: z.string().nullable(),
|
|
55
|
+
status: contractStatusSchema,
|
|
56
|
+
startsAt: z.string(),
|
|
57
|
+
endsAt: z.string().nullable(),
|
|
58
|
+
paymentOwner: paymentOwnerSchema,
|
|
59
|
+
cancellationOwner: cancellationOwnerSchema,
|
|
60
|
+
settlementTerms: z.string().nullable(),
|
|
61
|
+
notes: z.string().nullable(),
|
|
62
|
+
});
|
|
63
|
+
export const channelContractDetailSchema = channelContractRecordSchema.extend({
|
|
64
|
+
createdAt: z.string(),
|
|
65
|
+
updatedAt: z.string(),
|
|
66
|
+
});
|
|
67
|
+
export const channelCommissionRuleRecordSchema = z.object({
|
|
68
|
+
id: z.string(),
|
|
69
|
+
contractId: z.string(),
|
|
70
|
+
scope: commissionScopeSchema,
|
|
71
|
+
productId: z.string().nullable(),
|
|
72
|
+
externalRateId: z.string().nullable(),
|
|
73
|
+
externalCategoryId: z.string().nullable(),
|
|
74
|
+
commissionType: commissionTypeSchema,
|
|
75
|
+
amountCents: z.number().int().nullable(),
|
|
76
|
+
percentBasisPoints: z.number().int().nullable(),
|
|
77
|
+
validFrom: z.string().nullable(),
|
|
78
|
+
validTo: z.string().nullable(),
|
|
79
|
+
});
|
|
80
|
+
export const channelCommissionRuleDetailSchema = channelCommissionRuleRecordSchema.extend({
|
|
81
|
+
createdAt: z.string(),
|
|
82
|
+
updatedAt: z.string(),
|
|
83
|
+
});
|
|
84
|
+
export const channelProductMappingRecordSchema = z.object({
|
|
85
|
+
id: z.string(),
|
|
86
|
+
channelId: z.string(),
|
|
87
|
+
productId: z.string(),
|
|
88
|
+
externalProductId: z.string(),
|
|
89
|
+
externalRateId: z.string().nullable(),
|
|
90
|
+
externalCategoryId: z.string().nullable(),
|
|
91
|
+
active: z.boolean(),
|
|
92
|
+
});
|
|
93
|
+
export const channelProductMappingDetailSchema = channelProductMappingRecordSchema.extend({
|
|
94
|
+
createdAt: z.string(),
|
|
95
|
+
updatedAt: z.string(),
|
|
96
|
+
});
|
|
97
|
+
export const channelBookingLinkRecordSchema = z.object({
|
|
98
|
+
id: z.string(),
|
|
99
|
+
channelId: z.string(),
|
|
100
|
+
bookingId: z.string(),
|
|
101
|
+
externalBookingId: z.string().nullable(),
|
|
102
|
+
externalReference: z.string().nullable(),
|
|
103
|
+
externalStatus: z.string().nullable(),
|
|
104
|
+
bookedAtExternal: z.string().nullable(),
|
|
105
|
+
lastSyncedAt: z.string().nullable(),
|
|
106
|
+
});
|
|
107
|
+
export const channelBookingLinkDetailSchema = channelBookingLinkRecordSchema.extend({
|
|
108
|
+
createdAt: z.string(),
|
|
109
|
+
updatedAt: z.string(),
|
|
110
|
+
});
|
|
111
|
+
export const channelWebhookEventRecordSchema = z.object({
|
|
112
|
+
id: z.string(),
|
|
113
|
+
channelId: z.string(),
|
|
114
|
+
eventType: z.string(),
|
|
115
|
+
externalEventId: z.string().nullable(),
|
|
116
|
+
payload: z.record(z.string(), z.unknown()),
|
|
117
|
+
receivedAt: z.string().nullable(),
|
|
118
|
+
processedAt: z.string().nullable(),
|
|
119
|
+
status: webhookStatusSchema,
|
|
120
|
+
errorMessage: z.string().nullable(),
|
|
121
|
+
});
|
|
122
|
+
export const channelWebhookEventDetailSchema = channelWebhookEventRecordSchema.extend({
|
|
123
|
+
createdAt: z.string(),
|
|
124
|
+
updatedAt: z.string(),
|
|
125
|
+
});
|
|
126
|
+
export const supplierListResponse = paginatedEnvelope(supplierOptionSchema);
|
|
127
|
+
export const productListResponse = paginatedEnvelope(productOptionSchema);
|
|
128
|
+
export const bookingListResponse = paginatedEnvelope(bookingOptionSchema);
|
|
129
|
+
export const channelListResponse = paginatedEnvelope(channelRecordSchema);
|
|
130
|
+
export const channelContractListResponse = paginatedEnvelope(channelContractRecordSchema);
|
|
131
|
+
export const channelCommissionRuleListResponse = paginatedEnvelope(channelCommissionRuleRecordSchema);
|
|
132
|
+
export const channelProductMappingListResponse = paginatedEnvelope(channelProductMappingRecordSchema);
|
|
133
|
+
export const channelBookingLinkListResponse = paginatedEnvelope(channelBookingLinkRecordSchema);
|
|
134
|
+
export const channelWebhookEventListResponse = paginatedEnvelope(channelWebhookEventRecordSchema);
|
|
135
|
+
export const supplierSingleResponse = singleEnvelope(supplierOptionSchema);
|
|
136
|
+
export const productSingleResponse = singleEnvelope(productOptionSchema);
|
|
137
|
+
export const bookingSingleResponse = singleEnvelope(bookingOptionSchema);
|
|
138
|
+
export const channelSingleResponse = singleEnvelope(channelDetailSchema);
|
|
139
|
+
export const channelContractSingleResponse = singleEnvelope(channelContractDetailSchema);
|
|
140
|
+
export const channelCommissionRuleSingleResponse = singleEnvelope(channelCommissionRuleDetailSchema);
|
|
141
|
+
export const channelProductMappingSingleResponse = singleEnvelope(channelProductMappingDetailSchema);
|
|
142
|
+
export const channelBookingLinkSingleResponse = singleEnvelope(channelBookingLinkDetailSchema);
|
|
143
|
+
export const channelWebhookEventSingleResponse = singleEnvelope(channelWebhookEventDetailSchema);
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BookingOption, ProductOption, SupplierOption } from "./schemas.js";
|
|
2
|
+
export declare function nullableString(value: string | null | undefined): string | null;
|
|
3
|
+
export declare function nullableNumber(value: string | null | undefined): number | null;
|
|
4
|
+
export declare function toLocalDateTimeInput(value: string | null | undefined): string;
|
|
5
|
+
export declare function toIsoDateTime(value: string | null | undefined): string | null;
|
|
6
|
+
export declare function formatDateTime(value: string | null): string;
|
|
7
|
+
export declare function labelById(options: Array<SupplierOption | ProductOption | BookingOption>, id: string | null): string;
|
|
8
|
+
export declare function parseJsonRecord(value: string | null | undefined): Record<string, unknown> | null;
|
|
9
|
+
export declare function formatSelectionLabel(count: number, singular: string, plural?: string): string;
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAEhF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,iBAG9D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,iBAG9D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,UAGpE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,iBAG7D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,UAElD;AAED,wBAAgB,SAAS,CACvB,OAAO,EAAE,KAAK,CAAC,cAAc,GAAG,aAAa,GAAG,aAAa,CAAC,EAC9D,EAAE,EAAE,MAAM,GAAG,IAAI,UAOlB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,kCAQ/D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAiB,UAE5F"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function nullableString(value) {
|
|
2
|
+
const trimmed = value?.trim() ?? "";
|
|
3
|
+
return trimmed ? trimmed : null;
|
|
4
|
+
}
|
|
5
|
+
export function nullableNumber(value) {
|
|
6
|
+
const trimmed = value?.trim() ?? "";
|
|
7
|
+
return trimmed ? Number(trimmed) : null;
|
|
8
|
+
}
|
|
9
|
+
export function toLocalDateTimeInput(value) {
|
|
10
|
+
if (!value)
|
|
11
|
+
return "";
|
|
12
|
+
return value.slice(0, 16);
|
|
13
|
+
}
|
|
14
|
+
export function toIsoDateTime(value) {
|
|
15
|
+
if (!value)
|
|
16
|
+
return null;
|
|
17
|
+
return new Date(value).toISOString();
|
|
18
|
+
}
|
|
19
|
+
export function formatDateTime(value) {
|
|
20
|
+
return value ? value.replace("T", " ").slice(0, 16) : "-";
|
|
21
|
+
}
|
|
22
|
+
export function labelById(options, id) {
|
|
23
|
+
if (!id)
|
|
24
|
+
return "-";
|
|
25
|
+
const match = options.find((option) => option.id === id);
|
|
26
|
+
if (!match)
|
|
27
|
+
return id;
|
|
28
|
+
if ("name" in match)
|
|
29
|
+
return match.name;
|
|
30
|
+
return match.bookingNumber;
|
|
31
|
+
}
|
|
32
|
+
export function parseJsonRecord(value) {
|
|
33
|
+
const trimmed = value?.trim() ?? "";
|
|
34
|
+
if (!trimmed)
|
|
35
|
+
return null;
|
|
36
|
+
const parsed = JSON.parse(trimmed);
|
|
37
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
38
|
+
throw new Error("Expected a JSON object");
|
|
39
|
+
}
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
export function formatSelectionLabel(count, singular, plural = `${singular}s`) {
|
|
43
|
+
return `${count} ${count === 1 ? singular : plural}`;
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyantjs/distribution-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/voyantjs/voyant.git",
|
|
8
|
+
"directory": "packages/distribution-react"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts",
|
|
13
|
+
"./provider": "./src/provider.tsx",
|
|
14
|
+
"./hooks": "./src/hooks/index.ts",
|
|
15
|
+
"./client": "./src/client.ts",
|
|
16
|
+
"./query-keys": "./src/query-keys.ts"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -p tsconfig.json",
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"prepack": "pnpm run build",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"lint": "biome check src/",
|
|
24
|
+
"test": "vitest run --passWithNoTests"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@voyantjs/distribution": "workspace:*",
|
|
28
|
+
"@tanstack/react-query": "^5.0.0",
|
|
29
|
+
"react": "^19.0.0",
|
|
30
|
+
"react-dom": "^19.0.0",
|
|
31
|
+
"zod": "^4.0.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@voyantjs/distribution": "workspace:*",
|
|
35
|
+
"@voyantjs/react": "workspace:*",
|
|
36
|
+
"@voyantjs/voyant-typescript-config": "workspace:*",
|
|
37
|
+
"@tanstack/react-query": "^5.96.2",
|
|
38
|
+
"@types/react": "^19.2.14",
|
|
39
|
+
"@types/react-dom": "^19.2.3",
|
|
40
|
+
"react": "^19.2.4",
|
|
41
|
+
"react-dom": "^19.2.4",
|
|
42
|
+
"typescript": "^6.0.2",
|
|
43
|
+
"vitest": "^4.1.2",
|
|
44
|
+
"zod": "^4.3.6"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@voyantjs/react": "workspace:*"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public",
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./dist/index.d.ts",
|
|
57
|
+
"import": "./dist/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./provider": {
|
|
60
|
+
"types": "./dist/provider.d.ts",
|
|
61
|
+
"import": "./dist/provider.js"
|
|
62
|
+
},
|
|
63
|
+
"./hooks": {
|
|
64
|
+
"types": "./dist/hooks/index.d.ts",
|
|
65
|
+
"import": "./dist/hooks/index.js"
|
|
66
|
+
},
|
|
67
|
+
"./client": {
|
|
68
|
+
"types": "./dist/client.d.ts",
|
|
69
|
+
"import": "./dist/client.js"
|
|
70
|
+
},
|
|
71
|
+
"./query-keys": {
|
|
72
|
+
"types": "./dist/query-keys.d.ts",
|
|
73
|
+
"import": "./dist/query-keys.js"
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"main": "./dist/index.js",
|
|
77
|
+
"types": "./dist/index.d.ts"
|
|
78
|
+
}
|
|
79
|
+
}
|