@thebookingkit/server 0.1.1
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/.turbo/turbo-build.log +6 -0
- package/.turbo/turbo-test.log +20 -0
- package/CHANGELOG.md +9 -0
- package/dist/__tests__/api.test.d.ts +2 -0
- package/dist/__tests__/api.test.d.ts.map +1 -0
- package/dist/__tests__/api.test.js +280 -0
- package/dist/__tests__/api.test.js.map +1 -0
- package/dist/__tests__/auth.test.d.ts +2 -0
- package/dist/__tests__/auth.test.d.ts.map +1 -0
- package/dist/__tests__/auth.test.js +78 -0
- package/dist/__tests__/auth.test.js.map +1 -0
- package/dist/__tests__/concurrent-booking.test.d.ts +2 -0
- package/dist/__tests__/concurrent-booking.test.d.ts.map +1 -0
- package/dist/__tests__/concurrent-booking.test.js +111 -0
- package/dist/__tests__/concurrent-booking.test.js.map +1 -0
- package/dist/__tests__/multi-tenancy.test.d.ts +2 -0
- package/dist/__tests__/multi-tenancy.test.d.ts.map +1 -0
- package/dist/__tests__/multi-tenancy.test.js +196 -0
- package/dist/__tests__/multi-tenancy.test.js.map +1 -0
- package/dist/__tests__/serialization-retry.test.d.ts +2 -0
- package/dist/__tests__/serialization-retry.test.d.ts.map +1 -0
- package/dist/__tests__/serialization-retry.test.js +53 -0
- package/dist/__tests__/serialization-retry.test.js.map +1 -0
- package/dist/__tests__/webhooks.test.d.ts +2 -0
- package/dist/__tests__/webhooks.test.d.ts.map +1 -0
- package/dist/__tests__/webhooks.test.js +286 -0
- package/dist/__tests__/webhooks.test.js.map +1 -0
- package/dist/__tests__/workflows.test.d.ts +2 -0
- package/dist/__tests__/workflows.test.d.ts.map +1 -0
- package/dist/__tests__/workflows.test.js +299 -0
- package/dist/__tests__/workflows.test.js.map +1 -0
- 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/dist/adapters/storage-adapter.d.ts +12 -0
- 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/dist/email-templates.js +112 -0
- 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 +32 -0
- package/src/__tests__/api.test.ts +354 -0
- package/src/__tests__/auth.test.ts +111 -0
- package/src/__tests__/concurrent-booking.test.ts +170 -0
- package/src/__tests__/multi-tenancy.test.ts +267 -0
- package/src/__tests__/serialization-retry.test.ts +76 -0
- package/src/__tests__/webhooks.test.ts +412 -0
- package/src/__tests__/workflows.test.ts +422 -0
- package/src/adapters/calendar-adapter.ts +49 -0
- package/src/adapters/email-adapter.ts +108 -0
- package/src/adapters/index.ts +36 -0
- package/src/adapters/job-adapter.ts +26 -0
- package/src/adapters/payment-adapter.ts +118 -0
- package/src/adapters/sms-adapter.ts +35 -0
- package/src/adapters/storage-adapter.ts +11 -0
- package/src/api.ts +446 -0
- package/src/auth.ts +146 -0
- package/src/booking-tokens.ts +61 -0
- package/src/email-templates.ts +140 -0
- package/src/index.ts +192 -0
- package/src/multi-tenancy.ts +301 -0
- package/src/notification-jobs.ts +428 -0
- package/src/serialization-retry.ts +94 -0
- package/src/webhooks.ts +378 -0
- package/src/workflows.ts +441 -0
- package/tsconfig.json +9 -0
- package/vitest.config.ts +7 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract interface for payment processing.
|
|
3
|
+
*
|
|
4
|
+
* Default implementation: Stripe via `stripe` npm package.
|
|
5
|
+
* Alternatives: Square, PayPal, or mock for testing.
|
|
6
|
+
*/
|
|
7
|
+
/** Result of creating a payment intent */
|
|
8
|
+
export interface CreatePaymentIntentResult {
|
|
9
|
+
/** Stripe PaymentIntent ID (or equivalent) */
|
|
10
|
+
paymentIntentId: string;
|
|
11
|
+
/** Client secret for confirming payment on the frontend */
|
|
12
|
+
clientSecret: string;
|
|
13
|
+
/** Current status of the payment intent */
|
|
14
|
+
status: "requires_payment_method" | "requires_confirmation" | "requires_action" | "processing" | "succeeded" | "canceled";
|
|
15
|
+
}
|
|
16
|
+
/** Result of creating a setup intent for card authorization */
|
|
17
|
+
export interface CreateSetupIntentResult {
|
|
18
|
+
/** Stripe SetupIntent ID (or equivalent) */
|
|
19
|
+
setupIntentId: string;
|
|
20
|
+
/** Client secret for confirming setup on the frontend */
|
|
21
|
+
clientSecret: string;
|
|
22
|
+
}
|
|
23
|
+
/** Result of capturing a held payment */
|
|
24
|
+
export interface CaptureResult {
|
|
25
|
+
/** Whether the capture was successful */
|
|
26
|
+
captured: boolean;
|
|
27
|
+
/** The payment intent ID that was captured */
|
|
28
|
+
paymentIntentId: string;
|
|
29
|
+
}
|
|
30
|
+
/** Result of a refund operation */
|
|
31
|
+
export interface RefundResult {
|
|
32
|
+
/** Refund ID from the payment provider */
|
|
33
|
+
refundId: string;
|
|
34
|
+
/** Amount refunded in cents */
|
|
35
|
+
amountCents: number;
|
|
36
|
+
/** Status of the refund */
|
|
37
|
+
status: "succeeded" | "pending" | "failed";
|
|
38
|
+
}
|
|
39
|
+
/** Options for creating a payment intent */
|
|
40
|
+
export interface CreatePaymentIntentOptions {
|
|
41
|
+
/** Amount in smallest currency unit (e.g., cents for USD) */
|
|
42
|
+
amountCents: number;
|
|
43
|
+
/** ISO 4217 currency code */
|
|
44
|
+
currency: string;
|
|
45
|
+
/** Connected account ID (for Stripe Connect) */
|
|
46
|
+
connectedAccountId?: string;
|
|
47
|
+
/** Whether to use manual capture (for holds) */
|
|
48
|
+
captureMethod?: "automatic" | "manual";
|
|
49
|
+
/** Metadata to attach to the payment */
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
/** Customer email for receipt */
|
|
52
|
+
customerEmail?: string;
|
|
53
|
+
}
|
|
54
|
+
/** Options for creating a setup intent */
|
|
55
|
+
export interface CreateSetupIntentOptions {
|
|
56
|
+
/** Connected account ID (for Stripe Connect) */
|
|
57
|
+
connectedAccountId?: string;
|
|
58
|
+
/** Customer email */
|
|
59
|
+
customerEmail?: string;
|
|
60
|
+
/** Metadata */
|
|
61
|
+
metadata?: Record<string, string>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Payment processing adapter interface.
|
|
65
|
+
*
|
|
66
|
+
* Implementations handle creating payment intents, capturing holds,
|
|
67
|
+
* processing refunds, and managing Stripe Connect onboarding.
|
|
68
|
+
*/
|
|
69
|
+
export interface PaymentAdapter {
|
|
70
|
+
/**
|
|
71
|
+
* Create a payment intent for collecting payment.
|
|
72
|
+
* Use `captureMethod: 'manual'` for no-show fee holds.
|
|
73
|
+
*/
|
|
74
|
+
createPaymentIntent(options: CreatePaymentIntentOptions): Promise<CreatePaymentIntentResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Create a setup intent for authorizing a card without charging.
|
|
77
|
+
*/
|
|
78
|
+
createSetupIntent(options: CreateSetupIntentOptions): Promise<CreateSetupIntentResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Capture a previously authorized (manual capture) payment intent.
|
|
81
|
+
* Used when marking a booking as no-show.
|
|
82
|
+
*/
|
|
83
|
+
capturePaymentIntent(paymentIntentId: string, amountCents?: number): Promise<CaptureResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Cancel a payment intent (release a hold).
|
|
86
|
+
* Used when a booking completes normally and the no-show hold should be released.
|
|
87
|
+
*/
|
|
88
|
+
cancelPaymentIntent(paymentIntentId: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Refund a payment intent (full or partial).
|
|
91
|
+
*/
|
|
92
|
+
refund(paymentIntentId: string, amountCents?: number): Promise<RefundResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Generate a Stripe Connect onboarding URL for a provider.
|
|
95
|
+
* Returns the URL the provider should be redirected to.
|
|
96
|
+
*/
|
|
97
|
+
createConnectOnboardingUrl(options: {
|
|
98
|
+
returnUrl: string;
|
|
99
|
+
refreshUrl: string;
|
|
100
|
+
}): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Disconnect a Stripe Connect account.
|
|
103
|
+
*/
|
|
104
|
+
disconnectAccount(connectedAccountId: string): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=payment-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/payment-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,0CAA0C;AAC1C,MAAM,WAAW,yBAAyB;IACxC,8CAA8C;IAC9C,eAAe,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,YAAY,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,MAAM,EAAE,yBAAyB,GAAG,uBAAuB,GAAG,iBAAiB,GAAG,YAAY,GAAG,WAAW,GAAG,UAAU,CAAC;CAC3H;AAED,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC,4CAA4C;IAC5C,aAAa,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,mCAAmC;AACnC,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CA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AE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE7E;;;OAGG;IACH,0BAA0B,CAAC,OAAO,EAAE;QAClC,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpB;;OAEG;IACH,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-adapter.js","sourceRoot":"","sources":["../../src/adapters/payment-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract interface for SMS delivery.
|
|
3
|
+
*
|
|
4
|
+
* Default implementation: Twilio.
|
|
5
|
+
* Alternatives: AWS SNS, Vonage, or mock for testing.
|
|
6
|
+
*/
|
|
7
|
+
/** Options for sending an SMS */
|
|
8
|
+
export interface SendSmsOptions {
|
|
9
|
+
/** Recipient phone number (E.164 format) */
|
|
10
|
+
to: string;
|
|
11
|
+
/** SMS body text */
|
|
12
|
+
body: string;
|
|
13
|
+
/** Sender phone number or alphanumeric sender ID */
|
|
14
|
+
from?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Result of an SMS send operation */
|
|
17
|
+
export interface SmsResult {
|
|
18
|
+
/** Message ID from the SMS provider */
|
|
19
|
+
messageId: string;
|
|
20
|
+
/** Delivery status */
|
|
21
|
+
status: "queued" | "sent" | "delivered" | "failed";
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* SMS delivery adapter interface.
|
|
25
|
+
*
|
|
26
|
+
* Implementations handle sending SMS messages via a provider
|
|
27
|
+
* (e.g., Twilio, AWS SNS).
|
|
28
|
+
*/
|
|
29
|
+
export interface SmsAdapter {
|
|
30
|
+
/** Send an SMS message */
|
|
31
|
+
send(options: SendSmsOptions): Promise<SmsResult>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sms-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/sms-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iCAAiC;AACjC,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,sCAAsC;AACtC,MAAM,WAAW,SAAS;IACxB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;CACpD;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,0BAA0B;IAC1B,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms-adapter.js","sourceRoot":"","sources":["../../src/adapters/sms-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage/encryption adapter interface.
|
|
3
|
+
* Default implementation uses an environment variable encryption key.
|
|
4
|
+
* Swap to AWS KMS, GCP KMS, or HashiCorp Vault by implementing this interface.
|
|
5
|
+
*/
|
|
6
|
+
export interface StorageAdapter {
|
|
7
|
+
/** Encrypt a plaintext value */
|
|
8
|
+
encrypt(plaintext: string): Promise<string>;
|
|
9
|
+
/** Decrypt an encrypted value */
|
|
10
|
+
decrypt(ciphertext: string): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=storage-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/storage-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,iCAAiC;IACjC,OAAO,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-adapter.js","sourceRoot":"","sources":["../../src/adapters/storage-adapter.ts"],"names":[],"mappings":""}
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REST API utilities for SlotKit.
|
|
3
|
+
*
|
|
4
|
+
* Provides standardized response formatting, API key management,
|
|
5
|
+
* rate limiting, pagination, and request validation helpers
|
|
6
|
+
* for Next.js API routes.
|
|
7
|
+
*/
|
|
8
|
+
/** Standard API error */
|
|
9
|
+
export interface ApiError {
|
|
10
|
+
code: string;
|
|
11
|
+
message: string;
|
|
12
|
+
details?: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
/** Standard error response envelope */
|
|
15
|
+
export interface ApiErrorResponse {
|
|
16
|
+
error: ApiError;
|
|
17
|
+
}
|
|
18
|
+
/** Standard success response envelope */
|
|
19
|
+
export interface ApiSuccessResponse<T> {
|
|
20
|
+
data: T;
|
|
21
|
+
meta?: ApiMeta;
|
|
22
|
+
}
|
|
23
|
+
/** Pagination metadata */
|
|
24
|
+
export interface ApiMeta {
|
|
25
|
+
total?: number;
|
|
26
|
+
nextCursor?: string | null;
|
|
27
|
+
prevCursor?: string | null;
|
|
28
|
+
hasMore?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Paginated list response */
|
|
31
|
+
export interface PaginatedResponse<T> {
|
|
32
|
+
data: T[];
|
|
33
|
+
meta: {
|
|
34
|
+
nextCursor: string | null;
|
|
35
|
+
hasMore: boolean;
|
|
36
|
+
total?: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Standard API error codes */
|
|
40
|
+
export declare const API_ERROR_CODES: {
|
|
41
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
42
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
43
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
44
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
45
|
+
readonly CONFLICT: "CONFLICT";
|
|
46
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
47
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
48
|
+
readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
|
|
49
|
+
};
|
|
50
|
+
export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
|
|
51
|
+
/**
|
|
52
|
+
* Create a standardized API error response.
|
|
53
|
+
*
|
|
54
|
+
* @param code - Error code from API_ERROR_CODES
|
|
55
|
+
* @param message - Human-readable error message
|
|
56
|
+
* @param details - Optional additional details
|
|
57
|
+
* @returns Standardized error response object
|
|
58
|
+
*/
|
|
59
|
+
export declare function createErrorResponse(code: ApiErrorCode | string, message: string, details?: Record<string, unknown>): ApiErrorResponse;
|
|
60
|
+
/**
|
|
61
|
+
* Create a standardized API success response.
|
|
62
|
+
*
|
|
63
|
+
* @param data - The response data
|
|
64
|
+
* @param meta - Optional pagination metadata
|
|
65
|
+
* @returns Standardized success response object
|
|
66
|
+
*/
|
|
67
|
+
export declare function createSuccessResponse<T>(data: T, meta?: ApiMeta): ApiSuccessResponse<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a paginated list response.
|
|
70
|
+
*
|
|
71
|
+
* @param items - The page of items
|
|
72
|
+
* @param nextCursor - Cursor for the next page (null if last page)
|
|
73
|
+
* @param total - Optional total count
|
|
74
|
+
* @returns Paginated response
|
|
75
|
+
*/
|
|
76
|
+
export declare function createPaginatedResponse<T>(items: T[], nextCursor: string | null, total?: number): PaginatedResponse<T>;
|
|
77
|
+
/** An API key record */
|
|
78
|
+
export interface ApiKeyRecord {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
keyHash: string;
|
|
82
|
+
keyPrefix: string;
|
|
83
|
+
providerId?: string;
|
|
84
|
+
teamId?: string;
|
|
85
|
+
scopes: ApiKeyScope[];
|
|
86
|
+
rateLimit: number;
|
|
87
|
+
createdAt: Date;
|
|
88
|
+
expiresAt?: Date;
|
|
89
|
+
lastUsedAt?: Date;
|
|
90
|
+
}
|
|
91
|
+
/** API key scope */
|
|
92
|
+
export type ApiKeyScope = "read:bookings" | "write:bookings" | "read:availability" | "write:availability" | "read:event-types" | "write:event-types" | "read:webhooks" | "write:webhooks" | "read:analytics" | "admin";
|
|
93
|
+
/** Result of generating a new API key */
|
|
94
|
+
export interface GeneratedApiKey {
|
|
95
|
+
/** The full key (only shown once) */
|
|
96
|
+
key: string;
|
|
97
|
+
/** The prefix for display (e.g., "sk_live_abc123...") */
|
|
98
|
+
prefix: string;
|
|
99
|
+
/** The hash stored in the database */
|
|
100
|
+
hash: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Generate a new API key.
|
|
104
|
+
*
|
|
105
|
+
* The full key is only returned once and should be displayed to the user.
|
|
106
|
+
* Only the hash is stored in the database.
|
|
107
|
+
*
|
|
108
|
+
* @param prefix - Key prefix (e.g., "sk_live_" or "sk_test_")
|
|
109
|
+
* @returns Generated key with hash for storage
|
|
110
|
+
*/
|
|
111
|
+
export declare function generateApiKey(prefix?: string): GeneratedApiKey;
|
|
112
|
+
/**
|
|
113
|
+
* Hash an API key for secure storage.
|
|
114
|
+
*
|
|
115
|
+
* Uses HMAC-SHA256 with a secret from the SLOTKIT_API_KEY_SECRET
|
|
116
|
+
* environment variable. Throws if the secret is not configured.
|
|
117
|
+
*
|
|
118
|
+
* @param key - The full API key
|
|
119
|
+
* @param secret - Optional HMAC secret (defaults to SLOTKIT_API_KEY_SECRET env var)
|
|
120
|
+
* @returns The hex-encoded hash
|
|
121
|
+
*/
|
|
122
|
+
export declare function hashApiKey(key: string, secret?: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* Verify an API key against a stored hash.
|
|
125
|
+
*
|
|
126
|
+
* @param key - The key to verify
|
|
127
|
+
* @param storedHash - The hash stored in the database
|
|
128
|
+
* @returns Whether the key is valid
|
|
129
|
+
*/
|
|
130
|
+
export declare function verifyApiKey(key: string, storedHash: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Check if an API key has a required scope.
|
|
133
|
+
*
|
|
134
|
+
* Admin scope grants all permissions.
|
|
135
|
+
*
|
|
136
|
+
* @param keyScopes - The scopes granted to the API key
|
|
137
|
+
* @param requiredScope - The scope to check for
|
|
138
|
+
* @returns Whether the key has the required scope
|
|
139
|
+
*/
|
|
140
|
+
export declare function hasScope(keyScopes: ApiKeyScope[], requiredScope: ApiKeyScope): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Check if an API key has expired.
|
|
143
|
+
*
|
|
144
|
+
* @param expiresAt - Optional expiry timestamp
|
|
145
|
+
* @returns Whether the key is expired
|
|
146
|
+
*/
|
|
147
|
+
export declare function isKeyExpired(expiresAt: Date | undefined | null): boolean;
|
|
148
|
+
/** Rate limit state for a key */
|
|
149
|
+
export interface RateLimitState {
|
|
150
|
+
count: number;
|
|
151
|
+
windowStartMs: number;
|
|
152
|
+
}
|
|
153
|
+
/** Rate limit check result */
|
|
154
|
+
export interface RateLimitResult {
|
|
155
|
+
allowed: boolean;
|
|
156
|
+
remaining: number;
|
|
157
|
+
resetMs: number;
|
|
158
|
+
limit: number;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Check if a request should be allowed under rate limiting.
|
|
162
|
+
*
|
|
163
|
+
* Uses a fixed 1-minute window.
|
|
164
|
+
*
|
|
165
|
+
* @param state - Current rate limit state
|
|
166
|
+
* @param limit - Maximum requests per minute
|
|
167
|
+
* @param nowMs - Current timestamp in milliseconds
|
|
168
|
+
* @returns Rate limit check result
|
|
169
|
+
*/
|
|
170
|
+
export declare function checkRateLimit(state: RateLimitState | null, limit: number, nowMs?: number): {
|
|
171
|
+
result: RateLimitResult;
|
|
172
|
+
newState: RateLimitState;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Encode a cursor for pagination (base64 JSON).
|
|
176
|
+
*
|
|
177
|
+
* @param data - The cursor data to encode
|
|
178
|
+
* @returns Base64-encoded cursor string
|
|
179
|
+
*/
|
|
180
|
+
export declare function encodeCursor(data: Record<string, unknown>): string;
|
|
181
|
+
/**
|
|
182
|
+
* Decode a pagination cursor.
|
|
183
|
+
*
|
|
184
|
+
* @param cursor - The base64-encoded cursor string
|
|
185
|
+
* @returns The decoded cursor data, or null if invalid
|
|
186
|
+
*/
|
|
187
|
+
export declare function decodeCursor(cursor: string): Record<string, unknown> | null;
|
|
188
|
+
/** Validation error detail */
|
|
189
|
+
export interface ValidationDetail {
|
|
190
|
+
field: string;
|
|
191
|
+
message: string;
|
|
192
|
+
}
|
|
193
|
+
/** Result of input validation */
|
|
194
|
+
export interface ValidationResult {
|
|
195
|
+
valid: boolean;
|
|
196
|
+
errors: ValidationDetail[];
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Validate API request parameters for slot queries.
|
|
200
|
+
*
|
|
201
|
+
* @param params - Query parameters
|
|
202
|
+
* @returns Validation result
|
|
203
|
+
*/
|
|
204
|
+
export declare function validateSlotQueryParams(params: {
|
|
205
|
+
providerId?: string;
|
|
206
|
+
teamId?: string;
|
|
207
|
+
eventTypeId?: string;
|
|
208
|
+
start?: string;
|
|
209
|
+
end?: string;
|
|
210
|
+
timezone?: string;
|
|
211
|
+
}): ValidationResult;
|
|
212
|
+
/**
|
|
213
|
+
* Parse and validate a sort parameter.
|
|
214
|
+
*
|
|
215
|
+
* @param sortParam - Sort string (e.g., "-createdAt" or "startsAt")
|
|
216
|
+
* @param allowedFields - Fields that can be sorted by
|
|
217
|
+
* @returns Parsed sort field and direction
|
|
218
|
+
*/
|
|
219
|
+
export declare function parseSortParam(sortParam: string | undefined, allowedFields: string[]): {
|
|
220
|
+
field: string;
|
|
221
|
+
direction: "asc" | "desc";
|
|
222
|
+
} | null;
|
|
223
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,yBAAyB;AACzB,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED,yCAAyC;AACzC,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,0BAA0B;AAC1B,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,8BAA8B;AAC9B,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,EAAE;QACJ,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAMD,+BAA+B;AAC/B,e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