@thebookingkit/server 0.1.2 → 0.1.3
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 +2 -2
- package/dist/adapters/calendar-adapter.d.ts +47 -0
- package/dist/adapters/calendar-adapter.d.ts.map +1 -0
- package/dist/adapters/calendar-adapter.js +2 -0
- package/dist/adapters/calendar-adapter.js.map +1 -0
- package/dist/adapters/email-adapter.d.ts +65 -0
- package/dist/adapters/email-adapter.d.ts.map +1 -0
- package/dist/adapters/email-adapter.js +40 -0
- package/dist/adapters/email-adapter.js.map +1 -0
- package/dist/adapters/index.d.ts +9 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +3 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/job-adapter.d.ts +26 -0
- package/dist/adapters/job-adapter.d.ts.map +1 -0
- package/dist/adapters/job-adapter.js +13 -0
- package/dist/adapters/job-adapter.js.map +1 -0
- package/dist/adapters/payment-adapter.d.ts +106 -0
- package/dist/adapters/payment-adapter.d.ts.map +1 -0
- package/dist/adapters/payment-adapter.js +8 -0
- package/dist/adapters/payment-adapter.js.map +1 -0
- package/dist/adapters/sms-adapter.d.ts +33 -0
- package/dist/adapters/sms-adapter.d.ts.map +1 -0
- package/dist/adapters/sms-adapter.js +8 -0
- package/dist/adapters/sms-adapter.js.map +1 -0
- package/{src/adapters/storage-adapter.ts → dist/adapters/storage-adapter.d.ts} +5 -4
- package/dist/adapters/storage-adapter.d.ts.map +1 -0
- package/dist/adapters/storage-adapter.js +2 -0
- package/dist/adapters/storage-adapter.js.map +1 -0
- package/dist/api.d.ts +223 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +271 -0
- package/dist/api.js.map +1 -0
- package/dist/auth.d.ts +71 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +81 -0
- package/dist/auth.js.map +1 -0
- package/dist/booking-tokens.d.ts +23 -0
- package/dist/booking-tokens.d.ts.map +1 -0
- package/dist/booking-tokens.js +52 -0
- package/dist/booking-tokens.js.map +1 -0
- package/dist/email-templates.d.ts +36 -0
- package/dist/email-templates.d.ts.map +1 -0
- package/{src/email-templates.ts → dist/email-templates.js} +6 -34
- package/dist/email-templates.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/multi-tenancy.d.ts +132 -0
- package/dist/multi-tenancy.d.ts.map +1 -0
- package/dist/multi-tenancy.js +188 -0
- package/dist/multi-tenancy.js.map +1 -0
- package/dist/notification-jobs.d.ts +143 -0
- package/dist/notification-jobs.d.ts.map +1 -0
- package/dist/notification-jobs.js +278 -0
- package/dist/notification-jobs.js.map +1 -0
- package/dist/serialization-retry.d.ts +28 -0
- package/dist/serialization-retry.d.ts.map +1 -0
- package/dist/serialization-retry.js +71 -0
- package/dist/serialization-retry.js.map +1 -0
- package/dist/webhooks.d.ts +164 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +228 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/workflows.d.ts +169 -0
- package/dist/workflows.d.ts.map +1 -0
- package/dist/workflows.js +251 -0
- package/dist/workflows.js.map +1 -0
- package/package.json +21 -2
- package/CHANGELOG.md +0 -9
- package/src/__tests__/api.test.ts +0 -354
- package/src/__tests__/auth.test.ts +0 -111
- package/src/__tests__/concurrent-booking.test.ts +0 -170
- package/src/__tests__/multi-tenancy.test.ts +0 -267
- package/src/__tests__/serialization-retry.test.ts +0 -76
- package/src/__tests__/webhooks.test.ts +0 -412
- package/src/__tests__/workflows.test.ts +0 -422
- package/src/adapters/calendar-adapter.ts +0 -49
- package/src/adapters/email-adapter.ts +0 -108
- package/src/adapters/index.ts +0 -36
- package/src/adapters/job-adapter.ts +0 -26
- package/src/adapters/payment-adapter.ts +0 -118
- package/src/adapters/sms-adapter.ts +0 -35
- package/src/api.ts +0 -446
- package/src/auth.ts +0 -146
- package/src/booking-tokens.ts +0 -61
- package/src/index.ts +0 -192
- package/src/multi-tenancy.ts +0 -301
- package/src/notification-jobs.ts +0 -428
- package/src/serialization-retry.ts +0 -94
- package/src/webhooks.ts +0 -378
- package/src/workflows.ts +0 -441
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -7
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a signed booking management token.
|
|
3
|
+
*
|
|
4
|
+
* The token is a signed payload containing the booking ID and expiry time.
|
|
5
|
+
* It allows customers to view/manage their booking without authentication.
|
|
6
|
+
*
|
|
7
|
+
* @param bookingId - The booking UUID
|
|
8
|
+
* @param expiresAt - When the token expires
|
|
9
|
+
* @param secret - HMAC signing secret
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateBookingToken(bookingId: string, expiresAt: Date, secret: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Verify and decode a booking management token.
|
|
14
|
+
*
|
|
15
|
+
* @param token - The base64url-encoded token
|
|
16
|
+
* @param secret - HMAC signing secret (must match generation)
|
|
17
|
+
* @returns The booking ID if valid, null if invalid or expired
|
|
18
|
+
*/
|
|
19
|
+
export declare function verifyBookingToken(token: string, secret: string): {
|
|
20
|
+
bookingId: string;
|
|
21
|
+
expiresAt: Date;
|
|
22
|
+
} | null;
|
|
23
|
+
//# sourceMappingURL=booking-tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"booking-tokens.d.ts","sourceRoot":"","sources":["../src/booking-tokens.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,IAAI,EACf,MAAM,EAAE,MAAM,GACb,MAAM,CAOR;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,IAAI,CAAA;CAAE,GAAG,IAAI,CAyB/C"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createHmac } from "crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a signed booking management token.
|
|
4
|
+
*
|
|
5
|
+
* The token is a signed payload containing the booking ID and expiry time.
|
|
6
|
+
* It allows customers to view/manage their booking without authentication.
|
|
7
|
+
*
|
|
8
|
+
* @param bookingId - The booking UUID
|
|
9
|
+
* @param expiresAt - When the token expires
|
|
10
|
+
* @param secret - HMAC signing secret
|
|
11
|
+
*/
|
|
12
|
+
export function generateBookingToken(bookingId, expiresAt, secret) {
|
|
13
|
+
const payload = `${bookingId}:${expiresAt.getTime()}`;
|
|
14
|
+
const signature = createHmac("sha256", secret)
|
|
15
|
+
.update(payload)
|
|
16
|
+
.digest("hex")
|
|
17
|
+
.slice(0, 16);
|
|
18
|
+
return Buffer.from(`${payload}:${signature}`).toString("base64url");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Verify and decode a booking management token.
|
|
22
|
+
*
|
|
23
|
+
* @param token - The base64url-encoded token
|
|
24
|
+
* @param secret - HMAC signing secret (must match generation)
|
|
25
|
+
* @returns The booking ID if valid, null if invalid or expired
|
|
26
|
+
*/
|
|
27
|
+
export function verifyBookingToken(token, secret) {
|
|
28
|
+
try {
|
|
29
|
+
const decoded = Buffer.from(token, "base64url").toString("utf-8");
|
|
30
|
+
const parts = decoded.split(":");
|
|
31
|
+
if (parts.length !== 3)
|
|
32
|
+
return null;
|
|
33
|
+
const [bookingId, expiresAtStr, signature] = parts;
|
|
34
|
+
const expiresAt = new Date(Number(expiresAtStr));
|
|
35
|
+
// Check expiry
|
|
36
|
+
if (expiresAt < new Date())
|
|
37
|
+
return null;
|
|
38
|
+
// Verify signature
|
|
39
|
+
const payload = `${bookingId}:${expiresAtStr}`;
|
|
40
|
+
const expectedSig = createHmac("sha256", secret)
|
|
41
|
+
.update(payload)
|
|
42
|
+
.digest("hex")
|
|
43
|
+
.slice(0, 16);
|
|
44
|
+
if (signature !== expectedSig)
|
|
45
|
+
return null;
|
|
46
|
+
return { bookingId, expiresAt };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=booking-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"booking-tokens.js","sourceRoot":"","sources":["../src/booking-tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,SAAe,EACf,MAAc;IAEd,MAAM,OAAO,GAAG,GAAG,SAAS,IAAI,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;IACtD,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;SAC3C,MAAM,CAAC,OAAO,CAAC;SACf,MAAM,CAAC,KAAK,CAAC;SACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,IAAI,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACtE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAa,EACb,MAAc;IAEd,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;QACnD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;QAEjD,eAAe;QACf,IAAI,SAAS,GAAG,IAAI,IAAI,EAAE;YAAE,OAAO,IAAI,CAAC;QAExC,mBAAmB;QACnB,MAAM,OAAO,GAAG,GAAG,SAAS,IAAI,YAAY,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;aAC7C,MAAM,CAAC,OAAO,CAAC;aACf,MAAM,CAAC,KAAK,CAAC;aACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAEhB,IAAI,SAAS,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAE3C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;IAClC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Variables available in email templates */
|
|
2
|
+
export interface EmailTemplateVars {
|
|
3
|
+
bookingId: string;
|
|
4
|
+
eventTitle: string;
|
|
5
|
+
providerName: string;
|
|
6
|
+
customerName: string;
|
|
7
|
+
customerEmail: string;
|
|
8
|
+
date: string;
|
|
9
|
+
time: string;
|
|
10
|
+
duration: string;
|
|
11
|
+
timezone: string;
|
|
12
|
+
location?: string;
|
|
13
|
+
managementUrl?: string;
|
|
14
|
+
unsubscribeUrl?: string;
|
|
15
|
+
cancelReason?: string;
|
|
16
|
+
oldDate?: string;
|
|
17
|
+
oldTime?: string;
|
|
18
|
+
newDate?: string;
|
|
19
|
+
newTime?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Interpolate template variables into a template string.
|
|
23
|
+
* Variables use the format `{variableName}`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function interpolateTemplate(template: string, vars: EmailTemplateVars): string;
|
|
26
|
+
/** Default booking confirmation email template (HTML) */
|
|
27
|
+
export declare const CONFIRMATION_EMAIL_HTML: string;
|
|
28
|
+
/** Default booking confirmation email (plain text) */
|
|
29
|
+
export declare const CONFIRMATION_EMAIL_TEXT: string;
|
|
30
|
+
/** Default reminder email template */
|
|
31
|
+
export declare const REMINDER_EMAIL_HTML: string;
|
|
32
|
+
/** Default cancellation email template */
|
|
33
|
+
export declare const CANCELLATION_EMAIL_HTML: string;
|
|
34
|
+
/** Default reschedule email template */
|
|
35
|
+
export declare const RESCHEDULE_EMAIL_HTML: string;
|
|
36
|
+
//# sourceMappingURL=email-templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-templates.d.ts","sourceRoot":"","sources":["../src/email-templates.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,iBAAiB,GACtB,MAAM,CAKR;AAED,yDAAyD;AACzD,eAAO,MAAM,uBAAuB,QAqB5B,CAAC;AAET,sDAAsD;AACtD,eAAO,MAAM,uBAAuB,QAgB5B,CAAC;AAET,sCAAsC;AACtC,eAAO,MAAM,mBAAmB,QAoBxB,CAAC;AAET,0CAA0C;AAC1C,eAAO,MAAM,uBAAuB,QAc5B,CAAC;AAET,wCAAwC;AACxC,eAAO,MAAM,qBAAqB,QAoB1B,CAAC"}
|
|
@@ -1,38 +1,13 @@
|
|
|
1
|
-
/** Variables available in email templates */
|
|
2
|
-
export interface EmailTemplateVars {
|
|
3
|
-
bookingId: string;
|
|
4
|
-
eventTitle: string;
|
|
5
|
-
providerName: string;
|
|
6
|
-
customerName: string;
|
|
7
|
-
customerEmail: string;
|
|
8
|
-
date: string;
|
|
9
|
-
time: string;
|
|
10
|
-
duration: string;
|
|
11
|
-
timezone: string;
|
|
12
|
-
location?: string;
|
|
13
|
-
managementUrl?: string;
|
|
14
|
-
unsubscribeUrl?: string;
|
|
15
|
-
cancelReason?: string;
|
|
16
|
-
oldDate?: string;
|
|
17
|
-
oldTime?: string;
|
|
18
|
-
newDate?: string;
|
|
19
|
-
newTime?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
1
|
/**
|
|
23
2
|
* Interpolate template variables into a template string.
|
|
24
3
|
* Variables use the format `{variableName}`.
|
|
25
4
|
*/
|
|
26
|
-
export function interpolateTemplate(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const value = (vars as unknown as Record<string, string | undefined>)[key];
|
|
32
|
-
return value ?? match;
|
|
33
|
-
});
|
|
5
|
+
export function interpolateTemplate(template, vars) {
|
|
6
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
7
|
+
const value = vars[key];
|
|
8
|
+
return value ?? match;
|
|
9
|
+
});
|
|
34
10
|
}
|
|
35
|
-
|
|
36
11
|
/** Default booking confirmation email template (HTML) */
|
|
37
12
|
export const CONFIRMATION_EMAIL_HTML = `
|
|
38
13
|
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
|
|
@@ -56,7 +31,6 @@ export const CONFIRMATION_EMAIL_HTML = `
|
|
|
56
31
|
</p>
|
|
57
32
|
</div>
|
|
58
33
|
`.trim();
|
|
59
|
-
|
|
60
34
|
/** Default booking confirmation email (plain text) */
|
|
61
35
|
export const CONFIRMATION_EMAIL_TEXT = `
|
|
62
36
|
Booking Confirmed
|
|
@@ -75,7 +49,6 @@ Manage your booking: {managementUrl}
|
|
|
75
49
|
|
|
76
50
|
To unsubscribe: {unsubscribeUrl}
|
|
77
51
|
`.trim();
|
|
78
|
-
|
|
79
52
|
/** Default reminder email template */
|
|
80
53
|
export const REMINDER_EMAIL_HTML = `
|
|
81
54
|
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
|
|
@@ -98,7 +71,6 @@ export const REMINDER_EMAIL_HTML = `
|
|
|
98
71
|
</p>
|
|
99
72
|
</div>
|
|
100
73
|
`.trim();
|
|
101
|
-
|
|
102
74
|
/** Default cancellation email template */
|
|
103
75
|
export const CANCELLATION_EMAIL_HTML = `
|
|
104
76
|
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
|
|
@@ -115,7 +87,6 @@ export const CANCELLATION_EMAIL_HTML = `
|
|
|
115
87
|
</p>
|
|
116
88
|
</div>
|
|
117
89
|
`.trim();
|
|
118
|
-
|
|
119
90
|
/** Default reschedule email template */
|
|
120
91
|
export const RESCHEDULE_EMAIL_HTML = `
|
|
121
92
|
<div style="font-family: sans-serif; max-width: 600px; margin: 0 auto;">
|
|
@@ -138,3 +109,4 @@ export const RESCHEDULE_EMAIL_HTML = `
|
|
|
138
109
|
</p>
|
|
139
110
|
</div>
|
|
140
111
|
`.trim();
|
|
112
|
+
//# sourceMappingURL=email-templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-templates.js","sourceRoot":"","sources":["../src/email-templates.ts"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,IAAuB;IAEvB,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACnD,MAAM,KAAK,GAAI,IAAsD,CAAC,GAAG,CAAC,CAAC;QAC3E,OAAO,KAAK,IAAI,KAAK,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,yDAAyD;AACzD,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;CAqBtC,CAAC,IAAI,EAAE,CAAC;AAET,sDAAsD;AACtD,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;CAgBtC,CAAC,IAAI,EAAE,CAAC;AAET,sCAAsC;AACtC,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;CAoBlC,CAAC,IAAI,EAAE,CAAC;AAET,0CAA0C;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;CActC,CAAC,IAAI,EAAE,CAAC;AAET,wCAAwC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;CAoBpC,CAAC,IAAI,EAAE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { BookingConflictError, SerializationRetryExhaustedError, UnauthorizedError, ForbiddenError, } from "@thebookingkit/core";
|
|
2
|
+
export { withSerializableRetry, type SerializableRetryOptions, } from "./serialization-retry.js";
|
|
3
|
+
export { withAuth, assertProviderOwnership, assertCustomerAccess, type AuthUser, type AuthSession, type AuthAdapter, type AuthenticatedRequest, type WithAuthOptions, } from "./auth.js";
|
|
4
|
+
export type { EmailAdapter, SendEmailOptions, EmailResult, EmailDeliveryStatus, EmailAttachment, CalendarAdapter, CalendarEventOptions, CalendarEventResult, CalendarConflict, JobAdapter, StorageAdapter, SmsAdapter, SendSmsOptions, SmsResult, PaymentAdapter, CreatePaymentIntentOptions, CreatePaymentIntentResult, CreateSetupIntentOptions, CreateSetupIntentResult, CaptureResult, RefundResult, } from "./adapters/index.js";
|
|
5
|
+
export { generateICSAttachment, JOB_NAMES } from "./adapters/index.js";
|
|
6
|
+
export { generateBookingToken, verifyBookingToken, } from "./booking-tokens.js";
|
|
7
|
+
export { sendConfirmationEmail, sendReminderEmail, sendCancellationEmail, sendRescheduleEmail, scheduleAutoReject, syncBookingToCalendar, deleteBookingFromCalendar, formatDateTimeForEmail, formatDurationForEmail, type NotificationBookingData, type ConfirmationEmailPayload, type ReminderEmailPayload, type CancellationEmailPayload, type RescheduleEmailPayload, type CalendarSyncPayload, type CalendarDeletePayload, type AutoRejectPendingPayload, } from "./notification-jobs.js";
|
|
8
|
+
export { interpolateTemplate, CONFIRMATION_EMAIL_HTML, CONFIRMATION_EMAIL_TEXT, REMINDER_EMAIL_HTML, CANCELLATION_EMAIL_HTML, RESCHEDULE_EMAIL_HTML, type EmailTemplateVars, } from "./email-templates.js";
|
|
9
|
+
export { resolveTemplateVariables, evaluateConditions, validateWorkflow, matchWorkflows, DEFAULT_TEMPLATES, TEMPLATE_VARIABLES, WorkflowValidationError, type WorkflowTrigger, type WorkflowActionType, type ConditionOperator, type WorkflowCondition, type EmailActionConfig, type SmsActionConfig, type WebhookActionConfig, type StatusUpdateActionConfig, type CalendarEventActionConfig, type WorkflowAction, type WorkflowDefinition, type WorkflowContext, type WorkflowLogEntry, } from "./workflows.js";
|
|
10
|
+
export { signWebhookPayload, verifyWebhookSignature, createWebhookEnvelope, resolvePayloadTemplate, matchWebhookSubscriptions, getRetryDelay, isSuccessResponse, validateWebhookSubscription, WebhookValidationError, DEFAULT_RETRY_CONFIG, WEBHOOK_TRIGGERS, SIGNATURE_HEADER, TIMESTAMP_HEADER, DEFAULT_TOLERANCE_SECONDS, type WebhookTrigger, type WebhookAttendee, type WebhookPayload, type WebhookEnvelope, type WebhookSubscription, type WebhookDeliveryResult, type WebhookRetryConfig, type WebhookVerificationResult, } from "./webhooks.js";
|
|
11
|
+
export { createErrorResponse, createSuccessResponse, createPaginatedResponse, generateApiKey, hashApiKey, verifyApiKey, hasScope, isKeyExpired, checkRateLimit, encodeCursor, decodeCursor, validateSlotQueryParams, parseSortParam, API_ERROR_CODES, type ApiError, type ApiErrorResponse, type ApiSuccessResponse, type ApiMeta, type PaginatedResponse, type ApiErrorCode, type ApiKeyRecord, type ApiKeyScope, type GeneratedApiKey, type RateLimitState, type RateLimitResult, type ValidationDetail, type ValidationResult, } from "./api.js";
|
|
12
|
+
export { resolveEffectiveSettings, getRolePermissions, roleHasPermission, assertOrgPermission, assertTenantScope, buildOrgBookingUrl, parseOrgBookingPath, TenantAuthorizationError, GLOBAL_DEFAULTS, type OrgRole, type OrgMember, type OrgBranding, type OrgSettings, type ProviderSettings, type EventTypeSettings, type GlobalDefaults, type ResolvedSettings, type OrgPermission, } from "./multi-tenancy.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,iBAAiB,EACjB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,qBAAqB,EACrB,KAAK,wBAAwB,GAC9B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,UAAU,EACV,cAAc,EACd,SAAS,EACT,cAAc,EACd,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,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AAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,cAAc,EACd,eAAe,EACf,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,OAAO,EACZ,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,EACf,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,aAAa,GACnB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Re-export core errors used by server modules
|
|
2
|
+
export { BookingConflictError, SerializationRetryExhaustedError, UnauthorizedError, ForbiddenError, } from "@thebookingkit/core";
|
|
3
|
+
// Serialization retry utility
|
|
4
|
+
export { withSerializableRetry, } from "./serialization-retry.js";
|
|
5
|
+
// Auth middleware & adapters
|
|
6
|
+
export { withAuth, assertProviderOwnership, assertCustomerAccess, } from "./auth.js";
|
|
7
|
+
export { generateICSAttachment, JOB_NAMES } from "./adapters/index.js";
|
|
8
|
+
// Booking Tokens
|
|
9
|
+
export { generateBookingToken, verifyBookingToken, } from "./booking-tokens.js";
|
|
10
|
+
// Notification Jobs
|
|
11
|
+
export { sendConfirmationEmail, sendReminderEmail, sendCancellationEmail, sendRescheduleEmail, scheduleAutoReject, syncBookingToCalendar, deleteBookingFromCalendar, formatDateTimeForEmail, formatDurationForEmail, } from "./notification-jobs.js";
|
|
12
|
+
// Email Templates
|
|
13
|
+
export { interpolateTemplate, CONFIRMATION_EMAIL_HTML, CONFIRMATION_EMAIL_TEXT, REMINDER_EMAIL_HTML, CANCELLATION_EMAIL_HTML, RESCHEDULE_EMAIL_HTML, } from "./email-templates.js";
|
|
14
|
+
// Workflows
|
|
15
|
+
export { resolveTemplateVariables, evaluateConditions, validateWorkflow, matchWorkflows, DEFAULT_TEMPLATES, TEMPLATE_VARIABLES, WorkflowValidationError, } from "./workflows.js";
|
|
16
|
+
// Webhooks
|
|
17
|
+
export { signWebhookPayload, verifyWebhookSignature, createWebhookEnvelope, resolvePayloadTemplate, matchWebhookSubscriptions, getRetryDelay, isSuccessResponse, validateWebhookSubscription, WebhookValidationError, DEFAULT_RETRY_CONFIG, WEBHOOK_TRIGGERS, SIGNATURE_HEADER, TIMESTAMP_HEADER, DEFAULT_TOLERANCE_SECONDS, } from "./webhooks.js";
|
|
18
|
+
// REST API Utilities
|
|
19
|
+
export { createErrorResponse, createSuccessResponse, createPaginatedResponse, generateApiKey, hashApiKey, verifyApiKey, hasScope, isKeyExpired, checkRateLimit, encodeCursor, decodeCursor, validateSlotQueryParams, parseSortParam, API_ERROR_CODES, } from "./api.js";
|
|
20
|
+
// Multi-Tenancy
|
|
21
|
+
export { resolveEffectiveSettings, getRolePermissions, roleHasPermission, assertOrgPermission, assertTenantScope, buildOrgBookingUrl, parseOrgBookingPath, TenantAuthorizationError, GLOBAL_DEFAULTS, } from "./multi-tenancy.js";
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EACL,oBAAoB,EACpB,gCAAgC,EAChC,iBAAiB,EACjB,cAAc,GACf,MAAM,qBAAqB,CAAC;AAE7B,8BAA8B;AAC9B,OAAO,EACL,qBAAqB,GAEtB,MAAM,0BAA0B,CAAC;AAElC,6BAA6B;AAC7B,OAAO,EACL,QAAQ,EACR,uBAAuB,EACvB,oBAAoB,GAMrB,MAAM,WAAW,CAAC;AA0BnB,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvE,iBAAiB;AACjB,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAE7B,oBAAoB;AACpB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,yBAAyB,EACzB,sBAAsB,EACtB,sBAAsB,GASvB,MAAM,wBAAwB,CAAC;AAEhC,kBAAkB;AAClB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,GAEtB,MAAM,sBAAsB,CAAC;AAE9B,YAAY;AACZ,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,uBAAuB,GAcxB,MAAM,gBAAgB,CAAC;AAExB,WAAW;AACX,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EACzB,aAAa,EACb,iBAAiB,EACjB,2BAA2B,EAC3B,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,GAS1B,MAAM,eAAe,CAAC;AAEvB,qBAAqB;AACrB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,cAAc,EACd,eAAe,GAchB,MAAM,UAAU,CAAC;AAElB,gBAAgB;AAChB,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,GAUhB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-tenancy utilities for organization-scoped deployments.
|
|
3
|
+
*
|
|
4
|
+
* Provides organization settings resolution, cascading defaults,
|
|
5
|
+
* role-based access control, and tenant authorization helpers.
|
|
6
|
+
*/
|
|
7
|
+
/** Organization member role */
|
|
8
|
+
export type OrgRole = "owner" | "admin" | "member";
|
|
9
|
+
/** Organization member */
|
|
10
|
+
export interface OrgMember {
|
|
11
|
+
userId: string;
|
|
12
|
+
organizationId: string;
|
|
13
|
+
role: OrgRole;
|
|
14
|
+
}
|
|
15
|
+
/** Organization branding */
|
|
16
|
+
export interface OrgBranding {
|
|
17
|
+
logoUrl?: string;
|
|
18
|
+
primaryColor?: string;
|
|
19
|
+
accentColor?: string;
|
|
20
|
+
fontFamily?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Organization-level settings */
|
|
23
|
+
export interface OrgSettings {
|
|
24
|
+
defaultTimezone?: string;
|
|
25
|
+
defaultCurrency?: string;
|
|
26
|
+
branding?: OrgBranding;
|
|
27
|
+
defaultBufferMinutes?: number;
|
|
28
|
+
defaultBookingLimits?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/** Provider-level settings that can override org defaults */
|
|
31
|
+
export interface ProviderSettings {
|
|
32
|
+
timezone?: string;
|
|
33
|
+
currency?: string;
|
|
34
|
+
branding?: Partial<OrgBranding>;
|
|
35
|
+
bufferMinutes?: number;
|
|
36
|
+
bookingLimits?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/** Event type settings that can override provider defaults */
|
|
39
|
+
export interface EventTypeSettings {
|
|
40
|
+
timezone?: string;
|
|
41
|
+
currency?: string;
|
|
42
|
+
bufferBefore?: number;
|
|
43
|
+
bufferAfter?: number;
|
|
44
|
+
bookingLimits?: Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/** Global SlotKit defaults */
|
|
47
|
+
export interface GlobalDefaults {
|
|
48
|
+
timezone: string;
|
|
49
|
+
currency: string;
|
|
50
|
+
bufferMinutes: number;
|
|
51
|
+
}
|
|
52
|
+
/** Resolved effective settings after cascading resolution */
|
|
53
|
+
export interface ResolvedSettings {
|
|
54
|
+
timezone: string;
|
|
55
|
+
currency: string;
|
|
56
|
+
bufferMinutes: number;
|
|
57
|
+
branding: OrgBranding;
|
|
58
|
+
bookingLimits: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/** Permissions available in the system */
|
|
61
|
+
export type OrgPermission = "manage:members" | "manage:teams" | "manage:event-types" | "view:all-bookings" | "view:own-bookings" | "manage:own-availability" | "view:analytics" | "manage:organization";
|
|
62
|
+
/** Error thrown for multi-tenancy authorization violations */
|
|
63
|
+
export declare class TenantAuthorizationError extends Error {
|
|
64
|
+
constructor(message: string);
|
|
65
|
+
}
|
|
66
|
+
/** System-wide defaults used as the base for cascading resolution */
|
|
67
|
+
export declare const GLOBAL_DEFAULTS: GlobalDefaults;
|
|
68
|
+
/**
|
|
69
|
+
* Resolve effective settings via the cascade:
|
|
70
|
+
* `event_type > provider > organization > global defaults`
|
|
71
|
+
*
|
|
72
|
+
* @param orgSettings - Organization-level settings
|
|
73
|
+
* @param providerSettings - Provider-level settings (overrides org)
|
|
74
|
+
* @param eventTypeSettings - Event type settings (overrides provider)
|
|
75
|
+
* @returns Fully resolved effective settings
|
|
76
|
+
*/
|
|
77
|
+
export declare function resolveEffectiveSettings(orgSettings?: OrgSettings | null, providerSettings?: ProviderSettings | null, eventTypeSettings?: EventTypeSettings | null): ResolvedSettings;
|
|
78
|
+
/**
|
|
79
|
+
* Get all permissions granted to a role.
|
|
80
|
+
*
|
|
81
|
+
* @param role - The organization role
|
|
82
|
+
* @returns Array of permissions
|
|
83
|
+
*/
|
|
84
|
+
export declare function getRolePermissions(role: OrgRole): OrgPermission[];
|
|
85
|
+
/**
|
|
86
|
+
* Check if a role has a specific permission.
|
|
87
|
+
*
|
|
88
|
+
* @param role - The organization role
|
|
89
|
+
* @param permission - The permission to check
|
|
90
|
+
* @returns Whether the role has the permission
|
|
91
|
+
*/
|
|
92
|
+
export declare function roleHasPermission(role: OrgRole, permission: OrgPermission): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Assert that an org member has a required permission.
|
|
95
|
+
*
|
|
96
|
+
* @param member - The org member
|
|
97
|
+
* @param permission - The required permission
|
|
98
|
+
* @throws {TenantAuthorizationError} If the member lacks the permission
|
|
99
|
+
*/
|
|
100
|
+
export declare function assertOrgPermission(member: OrgMember, permission: OrgPermission): void;
|
|
101
|
+
/**
|
|
102
|
+
* Validate that a resource belongs to the expected organization.
|
|
103
|
+
*
|
|
104
|
+
* @param resourceOrgId - Organization ID on the resource
|
|
105
|
+
* @param expectedOrgId - The org ID from the authenticated context
|
|
106
|
+
* @throws {TenantAuthorizationError} If there is a tenant mismatch
|
|
107
|
+
*/
|
|
108
|
+
export declare function assertTenantScope(resourceOrgId: string | null | undefined, expectedOrgId: string): void;
|
|
109
|
+
/**
|
|
110
|
+
* Generate the public booking URL for an organization's provider/event type.
|
|
111
|
+
*
|
|
112
|
+
* @param orgSlug - Organization slug
|
|
113
|
+
* @param providerSlug - Provider slug or ID
|
|
114
|
+
* @param eventTypeSlug - Event type slug
|
|
115
|
+
* @param baseUrl - Base URL of the application
|
|
116
|
+
* @returns Full booking URL
|
|
117
|
+
*/
|
|
118
|
+
export declare function buildOrgBookingUrl(orgSlug: string, providerSlug: string, eventTypeSlug: string, baseUrl: string): string;
|
|
119
|
+
/**
|
|
120
|
+
* Parse an organization slug from a booking URL path.
|
|
121
|
+
*
|
|
122
|
+
* Expected format: `/{orgSlug}/{providerSlug}/{eventTypeSlug}`
|
|
123
|
+
*
|
|
124
|
+
* @param pathname - URL pathname
|
|
125
|
+
* @returns Parsed segments, or null if format is invalid
|
|
126
|
+
*/
|
|
127
|
+
export declare function parseOrgBookingPath(pathname: string): {
|
|
128
|
+
orgSlug: string;
|
|
129
|
+
providerSlug: string;
|
|
130
|
+
eventTypeSlug: string;
|
|
131
|
+
} | null;
|
|
132
|
+
//# sourceMappingURL=multi-tenancy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-tenancy.d.ts","sourceRoot":"","sources":["../src/multi-tenancy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,+BAA+B;AAC/B,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEnD,0BAA0B;AAC1B,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,4BAA4B;AAC5B,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,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AAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAMD,qEAAqE;AACrE,eAAO,MAAM,eAAe,EAAE,cAI7B,CAAC;AAMF;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,CAAC,EAAE,WAAW,GAAG,IAAI,EAChC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,EAC1C,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,GAC3C,gBAAgB,CA0ClB;AAgCD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,EAAE,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,aAAa,GACxB,OAAO,CAET;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,aAAa,GACxB,IAAI,CAMN;AAMD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACxC,aAAa,EAAE,MAAM,GACpB,IAAI,CAMN;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,IAAI,CASP"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-tenancy utilities for organization-scoped deployments.
|
|
3
|
+
*
|
|
4
|
+
* Provides organization settings resolution, cascading defaults,
|
|
5
|
+
* role-based access control, and tenant authorization helpers.
|
|
6
|
+
*/
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Errors
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
/** Error thrown for multi-tenancy authorization violations */
|
|
11
|
+
export class TenantAuthorizationError extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "TenantAuthorizationError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Global Defaults
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/** System-wide defaults used as the base for cascading resolution */
|
|
21
|
+
export const GLOBAL_DEFAULTS = {
|
|
22
|
+
timezone: "UTC",
|
|
23
|
+
currency: "USD",
|
|
24
|
+
bufferMinutes: 0,
|
|
25
|
+
};
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
// Settings Resolution
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
/**
|
|
30
|
+
* Resolve effective settings via the cascade:
|
|
31
|
+
* `event_type > provider > organization > global defaults`
|
|
32
|
+
*
|
|
33
|
+
* @param orgSettings - Organization-level settings
|
|
34
|
+
* @param providerSettings - Provider-level settings (overrides org)
|
|
35
|
+
* @param eventTypeSettings - Event type settings (overrides provider)
|
|
36
|
+
* @returns Fully resolved effective settings
|
|
37
|
+
*/
|
|
38
|
+
export function resolveEffectiveSettings(orgSettings, providerSettings, eventTypeSettings) {
|
|
39
|
+
// Start with global defaults
|
|
40
|
+
let timezone = GLOBAL_DEFAULTS.timezone;
|
|
41
|
+
let currency = GLOBAL_DEFAULTS.currency;
|
|
42
|
+
let bufferMinutes = GLOBAL_DEFAULTS.bufferMinutes;
|
|
43
|
+
let branding = {};
|
|
44
|
+
let bookingLimits = {};
|
|
45
|
+
// Apply org settings
|
|
46
|
+
if (orgSettings) {
|
|
47
|
+
if (orgSettings.defaultTimezone)
|
|
48
|
+
timezone = orgSettings.defaultTimezone;
|
|
49
|
+
if (orgSettings.defaultCurrency)
|
|
50
|
+
currency = orgSettings.defaultCurrency;
|
|
51
|
+
if (orgSettings.defaultBufferMinutes !== undefined)
|
|
52
|
+
bufferMinutes = orgSettings.defaultBufferMinutes;
|
|
53
|
+
if (orgSettings.branding)
|
|
54
|
+
branding = { ...branding, ...orgSettings.branding };
|
|
55
|
+
if (orgSettings.defaultBookingLimits)
|
|
56
|
+
bookingLimits = { ...orgSettings.defaultBookingLimits };
|
|
57
|
+
}
|
|
58
|
+
// Apply provider settings (override org)
|
|
59
|
+
if (providerSettings) {
|
|
60
|
+
if (providerSettings.timezone)
|
|
61
|
+
timezone = providerSettings.timezone;
|
|
62
|
+
if (providerSettings.currency)
|
|
63
|
+
currency = providerSettings.currency;
|
|
64
|
+
if (providerSettings.bufferMinutes !== undefined)
|
|
65
|
+
bufferMinutes = providerSettings.bufferMinutes;
|
|
66
|
+
if (providerSettings.branding)
|
|
67
|
+
branding = { ...branding, ...providerSettings.branding };
|
|
68
|
+
if (providerSettings.bookingLimits)
|
|
69
|
+
bookingLimits = { ...bookingLimits, ...providerSettings.bookingLimits };
|
|
70
|
+
}
|
|
71
|
+
// Apply event type settings (override provider)
|
|
72
|
+
if (eventTypeSettings) {
|
|
73
|
+
if (eventTypeSettings.timezone)
|
|
74
|
+
timezone = eventTypeSettings.timezone;
|
|
75
|
+
if (eventTypeSettings.currency)
|
|
76
|
+
currency = eventTypeSettings.currency;
|
|
77
|
+
if (eventTypeSettings.bufferBefore !== undefined)
|
|
78
|
+
bufferMinutes = eventTypeSettings.bufferBefore;
|
|
79
|
+
if (eventTypeSettings.bookingLimits)
|
|
80
|
+
bookingLimits = { ...bookingLimits, ...eventTypeSettings.bookingLimits };
|
|
81
|
+
}
|
|
82
|
+
return { timezone, currency, bufferMinutes, branding, bookingLimits };
|
|
83
|
+
}
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Role-Based Access Control
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
/** Permissions granted to each role */
|
|
88
|
+
const ROLE_PERMISSIONS = {
|
|
89
|
+
owner: [
|
|
90
|
+
"manage:members",
|
|
91
|
+
"manage:teams",
|
|
92
|
+
"manage:event-types",
|
|
93
|
+
"view:all-bookings",
|
|
94
|
+
"view:own-bookings",
|
|
95
|
+
"manage:own-availability",
|
|
96
|
+
"view:analytics",
|
|
97
|
+
"manage:organization",
|
|
98
|
+
],
|
|
99
|
+
admin: [
|
|
100
|
+
"manage:teams",
|
|
101
|
+
"manage:event-types",
|
|
102
|
+
"view:all-bookings",
|
|
103
|
+
"view:own-bookings",
|
|
104
|
+
"manage:own-availability",
|
|
105
|
+
"view:analytics",
|
|
106
|
+
],
|
|
107
|
+
member: [
|
|
108
|
+
"view:own-bookings",
|
|
109
|
+
"manage:own-availability",
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Get all permissions granted to a role.
|
|
114
|
+
*
|
|
115
|
+
* @param role - The organization role
|
|
116
|
+
* @returns Array of permissions
|
|
117
|
+
*/
|
|
118
|
+
export function getRolePermissions(role) {
|
|
119
|
+
return ROLE_PERMISSIONS[role] ?? [];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Check if a role has a specific permission.
|
|
123
|
+
*
|
|
124
|
+
* @param role - The organization role
|
|
125
|
+
* @param permission - The permission to check
|
|
126
|
+
* @returns Whether the role has the permission
|
|
127
|
+
*/
|
|
128
|
+
export function roleHasPermission(role, permission) {
|
|
129
|
+
return getRolePermissions(role).includes(permission);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Assert that an org member has a required permission.
|
|
133
|
+
*
|
|
134
|
+
* @param member - The org member
|
|
135
|
+
* @param permission - The required permission
|
|
136
|
+
* @throws {TenantAuthorizationError} If the member lacks the permission
|
|
137
|
+
*/
|
|
138
|
+
export function assertOrgPermission(member, permission) {
|
|
139
|
+
if (!roleHasPermission(member.role, permission)) {
|
|
140
|
+
throw new TenantAuthorizationError(`Role "${member.role}" does not have permission: "${permission}"`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
// Tenant Scoping
|
|
145
|
+
// ---------------------------------------------------------------------------
|
|
146
|
+
/**
|
|
147
|
+
* Validate that a resource belongs to the expected organization.
|
|
148
|
+
*
|
|
149
|
+
* @param resourceOrgId - Organization ID on the resource
|
|
150
|
+
* @param expectedOrgId - The org ID from the authenticated context
|
|
151
|
+
* @throws {TenantAuthorizationError} If there is a tenant mismatch
|
|
152
|
+
*/
|
|
153
|
+
export function assertTenantScope(resourceOrgId, expectedOrgId) {
|
|
154
|
+
if (resourceOrgId && resourceOrgId !== expectedOrgId) {
|
|
155
|
+
throw new TenantAuthorizationError("Resource does not belong to the current organization");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Generate the public booking URL for an organization's provider/event type.
|
|
160
|
+
*
|
|
161
|
+
* @param orgSlug - Organization slug
|
|
162
|
+
* @param providerSlug - Provider slug or ID
|
|
163
|
+
* @param eventTypeSlug - Event type slug
|
|
164
|
+
* @param baseUrl - Base URL of the application
|
|
165
|
+
* @returns Full booking URL
|
|
166
|
+
*/
|
|
167
|
+
export function buildOrgBookingUrl(orgSlug, providerSlug, eventTypeSlug, baseUrl) {
|
|
168
|
+
return `${baseUrl}/${orgSlug}/${providerSlug}/${eventTypeSlug}`;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Parse an organization slug from a booking URL path.
|
|
172
|
+
*
|
|
173
|
+
* Expected format: `/{orgSlug}/{providerSlug}/{eventTypeSlug}`
|
|
174
|
+
*
|
|
175
|
+
* @param pathname - URL pathname
|
|
176
|
+
* @returns Parsed segments, or null if format is invalid
|
|
177
|
+
*/
|
|
178
|
+
export function parseOrgBookingPath(pathname) {
|
|
179
|
+
const match = pathname.match(/^\/([^/]+)\/([^/]+)\/([^/]+)$/);
|
|
180
|
+
if (!match)
|
|
181
|
+
return null;
|
|
182
|
+
return {
|
|
183
|
+
orgSlug: match[1],
|
|
184
|
+
providerSlug: match[2],
|
|
185
|
+
eventTypeSlug: match[3],
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=multi-tenancy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-tenancy.js","sourceRoot":"","sources":["../src/multi-tenancy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8EH,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,8DAA8D;AAC9D,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAmB;IAC7C,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,KAAK;IACf,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,WAAgC,EAChC,gBAA0C,EAC1C,iBAA4C;IAE5C,6BAA6B;IAC7B,IAAI,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IACxC,IAAI,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;IACxC,IAAI,aAAa,GAAG,eAAe,CAAC,aAAa,CAAC;IAClD,IAAI,QAAQ,GAAgB,EAAE,CAAC;IAC/B,IAAI,aAAa,GAA4B,EAAE,CAAC;IAEhD,qBAAqB;IACrB,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,WAAW,CAAC,eAAe;YAAE,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC;QACxE,IAAI,WAAW,CAAC,eA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