spaps-sdk 1.3.0 → 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 +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +55 -0
- package/dist/index.mjs +55 -0
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -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<{
|
|
@@ -480,6 +526,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
480
526
|
recordUsage(feature: string, amount: number): Promise<void>;
|
|
481
527
|
private createSecureMessage;
|
|
482
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;
|
|
483
545
|
/**
|
|
484
546
|
* Create a new Stripe product (Admin required)
|
|
485
547
|
*/
|
|
@@ -619,4 +681,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
|
|
|
619
681
|
*/
|
|
620
682
|
declare function detectKeyType(key: string): ApiKeyType | null;
|
|
621
683
|
|
|
622
|
-
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
|
@@ -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<{
|
|
@@ -480,6 +526,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
|
|
|
480
526
|
recordUsage(feature: string, amount: number): Promise<void>;
|
|
481
527
|
private createSecureMessage;
|
|
482
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;
|
|
483
545
|
/**
|
|
484
546
|
* Create a new Stripe product (Admin required)
|
|
485
547
|
*/
|
|
@@ -619,4 +681,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
|
|
|
619
681
|
*/
|
|
620
682
|
declare function detectKeyType(key: string): ApiKeyType | null;
|
|
621
683
|
|
|
622
|
-
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";
|
|
@@ -904,6 +910,55 @@ var SPAPSClient = class {
|
|
|
904
910
|
}
|
|
905
911
|
return payload;
|
|
906
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
|
+
}
|
|
907
962
|
// Admin Methods (Require admin privileges)
|
|
908
963
|
/**
|
|
909
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";
|
|
@@ -877,6 +883,55 @@ var SPAPSClient = class {
|
|
|
877
883
|
}
|
|
878
884
|
return payload;
|
|
879
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
|
+
}
|
|
880
935
|
// Admin Methods (Require admin privileges)
|
|
881
936
|
/**
|
|
882
937
|
* Create a new Stripe product (Admin required)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spaps-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
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",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"email": "buildooor@gmail.com"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"spaps-types": "^1.0.
|
|
49
|
+
"spaps-types": "^1.0.60",
|
|
50
50
|
"axios": "^1.6.0",
|
|
51
51
|
"cross-fetch": "^4.0.0"
|
|
52
52
|
},
|
|
@@ -74,4 +74,4 @@
|
|
|
74
74
|
"engines": {
|
|
75
75
|
"node": ">=14.0.0"
|
|
76
76
|
}
|
|
77
|
-
}
|
|
77
|
+
}
|