spaps-sdk 1.2.1 → 1.4.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/dist/index.d.mts +86 -3
- package/dist/index.d.ts +86 -3
- package/dist/index.js +85 -0
- package/dist/index.mjs +85 -0
- package/package.json +6 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as spaps_types from 'spaps-types';
|
|
2
|
-
import { CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, Subscription, UsageBalance, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
-
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AuthResponse, CheckoutSession, CreateCryptoInvoiceRequest, CreatePriceRequest, CreateProductRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, Price, Product, ProductSyncResult, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateProductRequest, UsageBalance, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, createSecureMessageRequestSchema, secureMessageMetadataSchema, secureMessageSchema } from 'spaps-types';
|
|
2
|
+
import { CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, DayrateAvailabilityResponse, DayrateBookingRequest, DayrateBookingResponse, DayrateMultiBookingRequest, DayrateMultiBookingResponse, Subscription, UsageBalance, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
+
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AuthResponse, CheckoutSession, CreateCryptoInvoiceRequest, CreatePriceRequest, CreateProductRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, DayrateAvailabilityResponse, DayrateAvailableSlot, DayrateBookingRequest, DayrateBookingResponse, DayrateDayOfWeek, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayratePriceBreakdown, DayrateSlotType, Price, Product, ProductSyncResult, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateProductRequest, UsageBalance, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, createSecureMessageRequestSchema, secureMessageMetadataSchema, secureMessageSchema } from 'spaps-types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Permission checking utilities for SPAPS SDK
|
|
@@ -132,6 +132,46 @@ interface CreateCheckoutSessionPayload {
|
|
|
132
132
|
require_legal_consent?: boolean;
|
|
133
133
|
legal_consent_text?: string;
|
|
134
134
|
}
|
|
135
|
+
interface EmailSendOptions {
|
|
136
|
+
templateKey: string;
|
|
137
|
+
to: string;
|
|
138
|
+
context: Record<string, string | number | boolean>;
|
|
139
|
+
userId?: string;
|
|
140
|
+
}
|
|
141
|
+
interface EmailSendResult {
|
|
142
|
+
success: boolean;
|
|
143
|
+
messageId?: string;
|
|
144
|
+
error?: string;
|
|
145
|
+
}
|
|
146
|
+
interface TemplateVariable {
|
|
147
|
+
name: string;
|
|
148
|
+
required?: boolean;
|
|
149
|
+
description?: string;
|
|
150
|
+
}
|
|
151
|
+
interface EmailTemplate {
|
|
152
|
+
id: string;
|
|
153
|
+
applicationId?: string;
|
|
154
|
+
templateKey: string;
|
|
155
|
+
name: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
subject: string;
|
|
158
|
+
htmlBody?: string;
|
|
159
|
+
textBody?: string;
|
|
160
|
+
fromEmail?: string;
|
|
161
|
+
fromName?: string;
|
|
162
|
+
replyTo?: string;
|
|
163
|
+
variables?: TemplateVariable[];
|
|
164
|
+
sampleContext?: Record<string, unknown>;
|
|
165
|
+
category?: string;
|
|
166
|
+
isActive?: boolean;
|
|
167
|
+
createdAt?: string;
|
|
168
|
+
updatedAt?: string;
|
|
169
|
+
}
|
|
170
|
+
interface EmailTemplatePreview {
|
|
171
|
+
subject: string;
|
|
172
|
+
html: string;
|
|
173
|
+
text?: string;
|
|
174
|
+
}
|
|
135
175
|
|
|
136
176
|
declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Record<string, any>> {
|
|
137
177
|
private client;
|
|
@@ -180,6 +220,12 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
180
220
|
create: (payload: CreateSecureMessageRequest<SecureMessageMetadata>) => Promise<SecureMessage<SecureMessageMetadata>>;
|
|
181
221
|
list: () => Promise<SecureMessage<SecureMessageMetadata>[]>;
|
|
182
222
|
};
|
|
223
|
+
email: {
|
|
224
|
+
send: (options: EmailSendOptions) => Promise<EmailSendResult>;
|
|
225
|
+
listTemplates: () => Promise<EmailTemplate[]>;
|
|
226
|
+
getTemplate: (templateKey: string) => Promise<EmailTemplate>;
|
|
227
|
+
previewTemplate: (templateKey: string, context?: Record<string, unknown>) => Promise<EmailTemplatePreview>;
|
|
228
|
+
};
|
|
183
229
|
constructor(config?: SPAPSConfig);
|
|
184
230
|
/** Raw API request helper that returns an ApiResponse-like shape */
|
|
185
231
|
request<T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', url: string, data?: any, requiresAuth?: boolean): Promise<{
|
|
@@ -446,6 +492,27 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
446
492
|
message: string;
|
|
447
493
|
}>;
|
|
448
494
|
};
|
|
495
|
+
/**
|
|
496
|
+
* DayRate (Dynamic Scheduling) namespace
|
|
497
|
+
* For booking half-day sessions with dynamic pricing
|
|
498
|
+
*/
|
|
499
|
+
dayrate: {
|
|
500
|
+
/**
|
|
501
|
+
* Get available slots with current pricing
|
|
502
|
+
* Public endpoint - no authentication required
|
|
503
|
+
*/
|
|
504
|
+
getAvailability: () => Promise<DayrateAvailabilityResponse>;
|
|
505
|
+
/**
|
|
506
|
+
* Create a single-slot booking and get Stripe checkout URL
|
|
507
|
+
* Returns a 10-minute reservation with checkout link
|
|
508
|
+
*/
|
|
509
|
+
createBooking: (payload: DayrateBookingRequest) => Promise<DayrateBookingResponse>;
|
|
510
|
+
/**
|
|
511
|
+
* Create a multi-slot booking and get Stripe checkout URL
|
|
512
|
+
* Reserves multiple slots with a single checkout session
|
|
513
|
+
*/
|
|
514
|
+
createMultiBooking: (payload: DayrateMultiBookingRequest) => Promise<DayrateMultiBookingResponse>;
|
|
515
|
+
};
|
|
449
516
|
createCheckoutSession(priceId: string, successUrl: string, cancelUrl?: string): Promise<{
|
|
450
517
|
data: CheckoutSession;
|
|
451
518
|
}>;
|
|
@@ -459,6 +526,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
459
526
|
recordUsage(feature: string, amount: number): Promise<void>;
|
|
460
527
|
private createSecureMessage;
|
|
461
528
|
private listSecureMessages;
|
|
529
|
+
/**
|
|
530
|
+
* Send an email using a template
|
|
531
|
+
*/
|
|
532
|
+
private sendEmail;
|
|
533
|
+
/**
|
|
534
|
+
* List all email templates for the application
|
|
535
|
+
*/
|
|
536
|
+
private listEmailTemplates;
|
|
537
|
+
/**
|
|
538
|
+
* Get a single email template by key
|
|
539
|
+
*/
|
|
540
|
+
private getEmailTemplate;
|
|
541
|
+
/**
|
|
542
|
+
* Preview a rendered email template
|
|
543
|
+
*/
|
|
544
|
+
private previewEmailTemplate;
|
|
462
545
|
/**
|
|
463
546
|
* Create a new Stripe product (Admin required)
|
|
464
547
|
*/
|
|
@@ -598,4 +681,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
|
|
|
598
681
|
*/
|
|
599
682
|
declare function detectKeyType(key: string): ApiKeyType | null;
|
|
600
683
|
|
|
601
|
-
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, DEFAULT_ADMIN_ACCOUNTS, type PermissionCheckResult, PermissionChecker, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, TokenManager, WalletUtils, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, verifyCryptoWebhookSignature };
|
|
684
|
+
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, DEFAULT_ADMIN_ACCOUNTS, type EmailSendOptions, type EmailSendResult, type EmailTemplate, type EmailTemplatePreview, type PermissionCheckResult, PermissionChecker, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, type TemplateVariable, TokenManager, WalletUtils, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, verifyCryptoWebhookSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as spaps_types from 'spaps-types';
|
|
2
|
-
import { CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, Subscription, UsageBalance, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
-
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AuthResponse, CheckoutSession, CreateCryptoInvoiceRequest, CreatePriceRequest, CreateProductRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, Price, Product, ProductSyncResult, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateProductRequest, UsageBalance, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, createSecureMessageRequestSchema, secureMessageMetadataSchema, secureMessageSchema } from 'spaps-types';
|
|
2
|
+
import { CreateProductRequest, Product, UpdateProductRequest, CreatePriceRequest, Price, ProductSyncResult, CryptoReconcileRequest, CreateSecureMessageRequest, SecureMessage, AuthResponse, User as User$1, CreateCryptoInvoiceRequest, CryptoInvoiceStatusSnapshot, CheckoutSession, DayrateAvailabilityResponse, DayrateBookingRequest, DayrateBookingResponse, DayrateMultiBookingRequest, DayrateMultiBookingResponse, Subscription, UsageBalance, VerifyCryptoWebhookSignatureOptions } from 'spaps-types';
|
|
3
|
+
export { AdminPermission, AdminRole, AdminUser, ApiResponse, AuthResponse, CheckoutSession, CreateCryptoInvoiceRequest, CreatePriceRequest, CreateProductRequest, CreateSecureMessageInput, CreateSecureMessageRequest, CryptoInvoice, CryptoInvoiceResponse, CryptoInvoiceStatusSnapshot, CryptoReconcileRequest, DayrateAvailabilityResponse, DayrateAvailableSlot, DayrateBookingRequest, DayrateBookingResponse, DayrateDayOfWeek, DayrateMultiBookingRequest, DayrateMultiBookingResponse, DayratePriceBreakdown, DayrateSlotType, Price, Product, ProductSyncResult, SecureMessage, SecureMessageOutput, Subscription, TokenPair, UpdateProductRequest, UsageBalance, User, UserProfile, UserRole, UserWallet, VerifyCryptoWebhookSignatureOptions, createSecureMessageRequestSchema, secureMessageMetadataSchema, secureMessageSchema } from 'spaps-types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Permission checking utilities for SPAPS SDK
|
|
@@ -132,6 +132,46 @@ interface CreateCheckoutSessionPayload {
|
|
|
132
132
|
require_legal_consent?: boolean;
|
|
133
133
|
legal_consent_text?: string;
|
|
134
134
|
}
|
|
135
|
+
interface EmailSendOptions {
|
|
136
|
+
templateKey: string;
|
|
137
|
+
to: string;
|
|
138
|
+
context: Record<string, string | number | boolean>;
|
|
139
|
+
userId?: string;
|
|
140
|
+
}
|
|
141
|
+
interface EmailSendResult {
|
|
142
|
+
success: boolean;
|
|
143
|
+
messageId?: string;
|
|
144
|
+
error?: string;
|
|
145
|
+
}
|
|
146
|
+
interface TemplateVariable {
|
|
147
|
+
name: string;
|
|
148
|
+
required?: boolean;
|
|
149
|
+
description?: string;
|
|
150
|
+
}
|
|
151
|
+
interface EmailTemplate {
|
|
152
|
+
id: string;
|
|
153
|
+
applicationId?: string;
|
|
154
|
+
templateKey: string;
|
|
155
|
+
name: string;
|
|
156
|
+
description?: string;
|
|
157
|
+
subject: string;
|
|
158
|
+
htmlBody?: string;
|
|
159
|
+
textBody?: string;
|
|
160
|
+
fromEmail?: string;
|
|
161
|
+
fromName?: string;
|
|
162
|
+
replyTo?: string;
|
|
163
|
+
variables?: TemplateVariable[];
|
|
164
|
+
sampleContext?: Record<string, unknown>;
|
|
165
|
+
category?: string;
|
|
166
|
+
isActive?: boolean;
|
|
167
|
+
createdAt?: string;
|
|
168
|
+
updatedAt?: string;
|
|
169
|
+
}
|
|
170
|
+
interface EmailTemplatePreview {
|
|
171
|
+
subject: string;
|
|
172
|
+
html: string;
|
|
173
|
+
text?: string;
|
|
174
|
+
}
|
|
135
175
|
|
|
136
176
|
declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Record<string, any>> {
|
|
137
177
|
private client;
|
|
@@ -180,6 +220,12 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
180
220
|
create: (payload: CreateSecureMessageRequest<SecureMessageMetadata>) => Promise<SecureMessage<SecureMessageMetadata>>;
|
|
181
221
|
list: () => Promise<SecureMessage<SecureMessageMetadata>[]>;
|
|
182
222
|
};
|
|
223
|
+
email: {
|
|
224
|
+
send: (options: EmailSendOptions) => Promise<EmailSendResult>;
|
|
225
|
+
listTemplates: () => Promise<EmailTemplate[]>;
|
|
226
|
+
getTemplate: (templateKey: string) => Promise<EmailTemplate>;
|
|
227
|
+
previewTemplate: (templateKey: string, context?: Record<string, unknown>) => Promise<EmailTemplatePreview>;
|
|
228
|
+
};
|
|
183
229
|
constructor(config?: SPAPSConfig);
|
|
184
230
|
/** Raw API request helper that returns an ApiResponse-like shape */
|
|
185
231
|
request<T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', url: string, data?: any, requiresAuth?: boolean): Promise<{
|
|
@@ -446,6 +492,27 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
446
492
|
message: string;
|
|
447
493
|
}>;
|
|
448
494
|
};
|
|
495
|
+
/**
|
|
496
|
+
* DayRate (Dynamic Scheduling) namespace
|
|
497
|
+
* For booking half-day sessions with dynamic pricing
|
|
498
|
+
*/
|
|
499
|
+
dayrate: {
|
|
500
|
+
/**
|
|
501
|
+
* Get available slots with current pricing
|
|
502
|
+
* Public endpoint - no authentication required
|
|
503
|
+
*/
|
|
504
|
+
getAvailability: () => Promise<DayrateAvailabilityResponse>;
|
|
505
|
+
/**
|
|
506
|
+
* Create a single-slot booking and get Stripe checkout URL
|
|
507
|
+
* Returns a 10-minute reservation with checkout link
|
|
508
|
+
*/
|
|
509
|
+
createBooking: (payload: DayrateBookingRequest) => Promise<DayrateBookingResponse>;
|
|
510
|
+
/**
|
|
511
|
+
* Create a multi-slot booking and get Stripe checkout URL
|
|
512
|
+
* Reserves multiple slots with a single checkout session
|
|
513
|
+
*/
|
|
514
|
+
createMultiBooking: (payload: DayrateMultiBookingRequest) => Promise<DayrateMultiBookingResponse>;
|
|
515
|
+
};
|
|
449
516
|
createCheckoutSession(priceId: string, successUrl: string, cancelUrl?: string): Promise<{
|
|
450
517
|
data: CheckoutSession;
|
|
451
518
|
}>;
|
|
@@ -459,6 +526,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
459
526
|
recordUsage(feature: string, amount: number): Promise<void>;
|
|
460
527
|
private createSecureMessage;
|
|
461
528
|
private listSecureMessages;
|
|
529
|
+
/**
|
|
530
|
+
* Send an email using a template
|
|
531
|
+
*/
|
|
532
|
+
private sendEmail;
|
|
533
|
+
/**
|
|
534
|
+
* List all email templates for the application
|
|
535
|
+
*/
|
|
536
|
+
private listEmailTemplates;
|
|
537
|
+
/**
|
|
538
|
+
* Get a single email template by key
|
|
539
|
+
*/
|
|
540
|
+
private getEmailTemplate;
|
|
541
|
+
/**
|
|
542
|
+
* Preview a rendered email template
|
|
543
|
+
*/
|
|
544
|
+
private previewEmailTemplate;
|
|
462
545
|
/**
|
|
463
546
|
* Create a new Stripe product (Admin required)
|
|
464
547
|
*/
|
|
@@ -598,4 +681,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
|
|
|
598
681
|
*/
|
|
599
682
|
declare function detectKeyType(key: string): ApiKeyType | null;
|
|
600
683
|
|
|
601
|
-
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, DEFAULT_ADMIN_ACCOUNTS, type PermissionCheckResult, PermissionChecker, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, TokenManager, WalletUtils, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, verifyCryptoWebhookSignature };
|
|
684
|
+
export { type AdminConfig, type ApiKeyType, type CheckoutLineItem, type CheckoutLineItemPriceData, type CreateCheckoutSessionPayload, DEFAULT_ADMIN_ACCOUNTS, type EmailSendOptions, type EmailSendResult, type EmailTemplate, type EmailTemplatePreview, type PermissionCheckResult, PermissionChecker, SPAPSClient as SPAPS, SPAPSClient, type SPAPSConfig, type TemplateVariable, TokenManager, WalletUtils, canAccessAdmin, createBrowserClient, createPermissionChecker, createServerClient, SPAPSClient as default, defaultPermissionChecker, detectKeyType, getRoleAwareErrorMessage, getUserDisplay, getUserRole, hasPermission, isAdminAccount, verifyCryptoWebhookSignature };
|
package/dist/index.js
CHANGED
|
@@ -280,6 +280,12 @@ var SPAPSClient = class {
|
|
|
280
280
|
create: (payload) => this.createSecureMessage(payload),
|
|
281
281
|
list: () => this.listSecureMessages()
|
|
282
282
|
};
|
|
283
|
+
email = {
|
|
284
|
+
send: (options) => this.sendEmail(options),
|
|
285
|
+
listTemplates: () => this.listEmailTemplates(),
|
|
286
|
+
getTemplate: (templateKey) => this.getEmailTemplate(templateKey),
|
|
287
|
+
previewTemplate: (templateKey, context) => this.previewEmailTemplate(templateKey, context)
|
|
288
|
+
};
|
|
283
289
|
constructor(config = {}) {
|
|
284
290
|
const apiUrl = config.apiUrl || process.env.SPAPS_API_URL || process.env.NEXT_PUBLIC_SPAPS_API_URL;
|
|
285
291
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -837,6 +843,36 @@ var SPAPSClient = class {
|
|
|
837
843
|
return this.unwrapApiResponse(res, "Failed to disconnect");
|
|
838
844
|
}
|
|
839
845
|
};
|
|
846
|
+
/**
|
|
847
|
+
* DayRate (Dynamic Scheduling) namespace
|
|
848
|
+
* For booking half-day sessions with dynamic pricing
|
|
849
|
+
*/
|
|
850
|
+
dayrate = {
|
|
851
|
+
/**
|
|
852
|
+
* Get available slots with current pricing
|
|
853
|
+
* Public endpoint - no authentication required
|
|
854
|
+
*/
|
|
855
|
+
getAvailability: async () => {
|
|
856
|
+
const res = await this.client.get("/api/dayrate/availability");
|
|
857
|
+
return this.unwrapApiResponse(res, "Failed to get availability");
|
|
858
|
+
},
|
|
859
|
+
/**
|
|
860
|
+
* Create a single-slot booking and get Stripe checkout URL
|
|
861
|
+
* Returns a 10-minute reservation with checkout link
|
|
862
|
+
*/
|
|
863
|
+
createBooking: async (payload) => {
|
|
864
|
+
const res = await this.client.post("/api/dayrate/book", payload);
|
|
865
|
+
return this.unwrapApiResponse(res, "Failed to create booking");
|
|
866
|
+
},
|
|
867
|
+
/**
|
|
868
|
+
* Create a multi-slot booking and get Stripe checkout URL
|
|
869
|
+
* Reserves multiple slots with a single checkout session
|
|
870
|
+
*/
|
|
871
|
+
createMultiBooking: async (payload) => {
|
|
872
|
+
const res = await this.client.post("/api/dayrate/book-multi", payload);
|
|
873
|
+
return this.unwrapApiResponse(res, "Failed to create multi-booking");
|
|
874
|
+
}
|
|
875
|
+
};
|
|
840
876
|
// Stripe Methods
|
|
841
877
|
async createCheckoutSession(priceId, successUrl, cancelUrl) {
|
|
842
878
|
return this.client.post("/api/stripe/create-checkout-session", {
|
|
@@ -874,6 +910,55 @@ var SPAPSClient = class {
|
|
|
874
910
|
}
|
|
875
911
|
return payload;
|
|
876
912
|
}
|
|
913
|
+
// Email Methods
|
|
914
|
+
/**
|
|
915
|
+
* Send an email using a template
|
|
916
|
+
*/
|
|
917
|
+
async sendEmail(options) {
|
|
918
|
+
const response = await this.client.post("/api/email/send", {
|
|
919
|
+
template_key: options.templateKey,
|
|
920
|
+
to: options.to,
|
|
921
|
+
context: options.context,
|
|
922
|
+
...options.userId && { user_id: options.userId }
|
|
923
|
+
});
|
|
924
|
+
return this.unwrapApiResponse(response, "Failed to send email");
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* List all email templates for the application
|
|
928
|
+
*/
|
|
929
|
+
async listEmailTemplates() {
|
|
930
|
+
const response = await this.client.get("/api/email/templates");
|
|
931
|
+
const payload = this.unwrapApiResponse(
|
|
932
|
+
response,
|
|
933
|
+
"Failed to list email templates"
|
|
934
|
+
);
|
|
935
|
+
if (payload && Array.isArray(payload.templates)) {
|
|
936
|
+
return payload.templates;
|
|
937
|
+
}
|
|
938
|
+
return payload;
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get a single email template by key
|
|
942
|
+
*/
|
|
943
|
+
async getEmailTemplate(templateKey) {
|
|
944
|
+
const response = await this.client.get(`/api/email/templates/${templateKey}`);
|
|
945
|
+
return this.unwrapApiResponse(response, "Failed to get email template");
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Preview a rendered email template
|
|
949
|
+
*/
|
|
950
|
+
async previewEmailTemplate(templateKey, context) {
|
|
951
|
+
if (context) {
|
|
952
|
+
const response = await this.client.post(
|
|
953
|
+
`/api/email/templates/${templateKey}/preview`,
|
|
954
|
+
{ context }
|
|
955
|
+
);
|
|
956
|
+
return this.unwrapApiResponse(response, "Failed to preview email template");
|
|
957
|
+
} else {
|
|
958
|
+
const response = await this.client.get(`/api/email/templates/${templateKey}/preview`);
|
|
959
|
+
return this.unwrapApiResponse(response, "Failed to preview email template");
|
|
960
|
+
}
|
|
961
|
+
}
|
|
877
962
|
// Admin Methods (Require admin privileges)
|
|
878
963
|
/**
|
|
879
964
|
* Create a new Stripe product (Admin required)
|
package/dist/index.mjs
CHANGED
|
@@ -253,6 +253,12 @@ var SPAPSClient = class {
|
|
|
253
253
|
create: (payload) => this.createSecureMessage(payload),
|
|
254
254
|
list: () => this.listSecureMessages()
|
|
255
255
|
};
|
|
256
|
+
email = {
|
|
257
|
+
send: (options) => this.sendEmail(options),
|
|
258
|
+
listTemplates: () => this.listEmailTemplates(),
|
|
259
|
+
getTemplate: (templateKey) => this.getEmailTemplate(templateKey),
|
|
260
|
+
previewTemplate: (templateKey, context) => this.previewEmailTemplate(templateKey, context)
|
|
261
|
+
};
|
|
256
262
|
constructor(config = {}) {
|
|
257
263
|
const apiUrl = config.apiUrl || process.env.SPAPS_API_URL || process.env.NEXT_PUBLIC_SPAPS_API_URL;
|
|
258
264
|
const isBrowser = typeof window !== "undefined";
|
|
@@ -810,6 +816,36 @@ var SPAPSClient = class {
|
|
|
810
816
|
return this.unwrapApiResponse(res, "Failed to disconnect");
|
|
811
817
|
}
|
|
812
818
|
};
|
|
819
|
+
/**
|
|
820
|
+
* DayRate (Dynamic Scheduling) namespace
|
|
821
|
+
* For booking half-day sessions with dynamic pricing
|
|
822
|
+
*/
|
|
823
|
+
dayrate = {
|
|
824
|
+
/**
|
|
825
|
+
* Get available slots with current pricing
|
|
826
|
+
* Public endpoint - no authentication required
|
|
827
|
+
*/
|
|
828
|
+
getAvailability: async () => {
|
|
829
|
+
const res = await this.client.get("/api/dayrate/availability");
|
|
830
|
+
return this.unwrapApiResponse(res, "Failed to get availability");
|
|
831
|
+
},
|
|
832
|
+
/**
|
|
833
|
+
* Create a single-slot booking and get Stripe checkout URL
|
|
834
|
+
* Returns a 10-minute reservation with checkout link
|
|
835
|
+
*/
|
|
836
|
+
createBooking: async (payload) => {
|
|
837
|
+
const res = await this.client.post("/api/dayrate/book", payload);
|
|
838
|
+
return this.unwrapApiResponse(res, "Failed to create booking");
|
|
839
|
+
},
|
|
840
|
+
/**
|
|
841
|
+
* Create a multi-slot booking and get Stripe checkout URL
|
|
842
|
+
* Reserves multiple slots with a single checkout session
|
|
843
|
+
*/
|
|
844
|
+
createMultiBooking: async (payload) => {
|
|
845
|
+
const res = await this.client.post("/api/dayrate/book-multi", payload);
|
|
846
|
+
return this.unwrapApiResponse(res, "Failed to create multi-booking");
|
|
847
|
+
}
|
|
848
|
+
};
|
|
813
849
|
// Stripe Methods
|
|
814
850
|
async createCheckoutSession(priceId, successUrl, cancelUrl) {
|
|
815
851
|
return this.client.post("/api/stripe/create-checkout-session", {
|
|
@@ -847,6 +883,55 @@ var SPAPSClient = class {
|
|
|
847
883
|
}
|
|
848
884
|
return payload;
|
|
849
885
|
}
|
|
886
|
+
// Email Methods
|
|
887
|
+
/**
|
|
888
|
+
* Send an email using a template
|
|
889
|
+
*/
|
|
890
|
+
async sendEmail(options) {
|
|
891
|
+
const response = await this.client.post("/api/email/send", {
|
|
892
|
+
template_key: options.templateKey,
|
|
893
|
+
to: options.to,
|
|
894
|
+
context: options.context,
|
|
895
|
+
...options.userId && { user_id: options.userId }
|
|
896
|
+
});
|
|
897
|
+
return this.unwrapApiResponse(response, "Failed to send email");
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* List all email templates for the application
|
|
901
|
+
*/
|
|
902
|
+
async listEmailTemplates() {
|
|
903
|
+
const response = await this.client.get("/api/email/templates");
|
|
904
|
+
const payload = this.unwrapApiResponse(
|
|
905
|
+
response,
|
|
906
|
+
"Failed to list email templates"
|
|
907
|
+
);
|
|
908
|
+
if (payload && Array.isArray(payload.templates)) {
|
|
909
|
+
return payload.templates;
|
|
910
|
+
}
|
|
911
|
+
return payload;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Get a single email template by key
|
|
915
|
+
*/
|
|
916
|
+
async getEmailTemplate(templateKey) {
|
|
917
|
+
const response = await this.client.get(`/api/email/templates/${templateKey}`);
|
|
918
|
+
return this.unwrapApiResponse(response, "Failed to get email template");
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Preview a rendered email template
|
|
922
|
+
*/
|
|
923
|
+
async previewEmailTemplate(templateKey, context) {
|
|
924
|
+
if (context) {
|
|
925
|
+
const response = await this.client.post(
|
|
926
|
+
`/api/email/templates/${templateKey}/preview`,
|
|
927
|
+
{ context }
|
|
928
|
+
);
|
|
929
|
+
return this.unwrapApiResponse(response, "Failed to preview email template");
|
|
930
|
+
} else {
|
|
931
|
+
const response = await this.client.get(`/api/email/templates/${templateKey}/preview`);
|
|
932
|
+
return this.unwrapApiResponse(response, "Failed to preview email template");
|
|
933
|
+
}
|
|
934
|
+
}
|
|
850
935
|
// Admin Methods (Require admin privileges)
|
|
851
936
|
/**
|
|
852
937
|
* Create a new Stripe product (Admin required)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spaps-sdk",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Sweet Potato Authentication & Payment Service SDK - Zero-config client with built-in permission checking
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Sweet Potato Authentication & Payment Service SDK - Zero-config client with built-in permission checking, role-based access control, and dayrate scheduling",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"sdk",
|
|
32
32
|
"client",
|
|
33
33
|
"sweet-potato",
|
|
34
|
-
"wallet-auth"
|
|
34
|
+
"wallet-auth",
|
|
35
|
+
"dayrate",
|
|
36
|
+
"scheduling"
|
|
35
37
|
],
|
|
36
38
|
"author": "buildooor",
|
|
37
39
|
"license": "UNLICENSED",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"email": "buildooor@gmail.com"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
|
-
"spaps-types": "^1.0.
|
|
49
|
+
"spaps-types": "^1.0.60",
|
|
48
50
|
"axios": "^1.6.0",
|
|
49
51
|
"cross-fetch": "^4.0.0"
|
|
50
52
|
},
|