spaps-sdk 1.3.0 → 1.5.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 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<{
@@ -239,6 +285,17 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
239
285
  token: string;
240
286
  new_password: string;
241
287
  }) => Promise<void>;
288
+ /**
289
+ * Set or change password for authenticated users.
290
+ * For magic link / wallet users setting their first password, only new_password is required.
291
+ * For users changing an existing password, current_password is also required.
292
+ */
293
+ setPassword: (payload: {
294
+ current_password?: string;
295
+ new_password: string;
296
+ }) => Promise<{
297
+ message: string;
298
+ }>;
242
299
  register: (payload: {
243
300
  email: string;
244
301
  password: string;
@@ -480,6 +537,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
480
537
  recordUsage(feature: string, amount: number): Promise<void>;
481
538
  private createSecureMessage;
482
539
  private listSecureMessages;
540
+ /**
541
+ * Send an email using a template
542
+ */
543
+ private sendEmail;
544
+ /**
545
+ * List all email templates for the application
546
+ */
547
+ private listEmailTemplates;
548
+ /**
549
+ * Get a single email template by key
550
+ */
551
+ private getEmailTemplate;
552
+ /**
553
+ * Preview a rendered email template
554
+ */
555
+ private previewEmailTemplate;
483
556
  /**
484
557
  * Create a new Stripe product (Admin required)
485
558
  */
@@ -619,4 +692,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
619
692
  */
620
693
  declare function detectKeyType(key: string): ApiKeyType | null;
621
694
 
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 };
695
+ 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<{
@@ -239,6 +285,17 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
239
285
  token: string;
240
286
  new_password: string;
241
287
  }) => Promise<void>;
288
+ /**
289
+ * Set or change password for authenticated users.
290
+ * For magic link / wallet users setting their first password, only new_password is required.
291
+ * For users changing an existing password, current_password is also required.
292
+ */
293
+ setPassword: (payload: {
294
+ current_password?: string;
295
+ new_password: string;
296
+ }) => Promise<{
297
+ message: string;
298
+ }>;
242
299
  register: (payload: {
243
300
  email: string;
244
301
  password: string;
@@ -480,6 +537,22 @@ declare class SPAPSClient<SecureMessageMetadata extends Record<string, any> = Re
480
537
  recordUsage(feature: string, amount: number): Promise<void>;
481
538
  private createSecureMessage;
482
539
  private listSecureMessages;
540
+ /**
541
+ * Send an email using a template
542
+ */
543
+ private sendEmail;
544
+ /**
545
+ * List all email templates for the application
546
+ */
547
+ private listEmailTemplates;
548
+ /**
549
+ * Get a single email template by key
550
+ */
551
+ private getEmailTemplate;
552
+ /**
553
+ * Preview a rendered email template
554
+ */
555
+ private previewEmailTemplate;
483
556
  /**
484
557
  * Create a new Stripe product (Admin required)
485
558
  */
@@ -619,4 +692,4 @@ declare function createServerClient(secretKey: string, options?: Omit<SPAPSConfi
619
692
  */
620
693
  declare function detectKeyType(key: string): ApiKeyType | null;
621
694
 
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 };
695
+ 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";
@@ -460,6 +466,17 @@ var SPAPSClient = class {
460
466
  confirmPasswordReset: async (payload) => {
461
467
  await this.client.post("/api/auth/reset-password-confirm", payload);
462
468
  },
469
+ /**
470
+ * Set or change password for authenticated users.
471
+ * For magic link / wallet users setting their first password, only new_password is required.
472
+ * For users changing an existing password, current_password is also required.
473
+ */
474
+ setPassword: async (payload) => {
475
+ const res = await this.client.post("/api/auth/set-password", payload);
476
+ const body = res.data;
477
+ if (body?.success === false) throw new Error(body?.error?.message || "Set password failed");
478
+ return { message: body?.message || "Password updated successfully" };
479
+ },
463
480
  register: async (payload) => {
464
481
  const res = await this.client.post("/api/auth/register", payload);
465
482
  const body = res.data;
@@ -904,6 +921,55 @@ var SPAPSClient = class {
904
921
  }
905
922
  return payload;
906
923
  }
924
+ // Email Methods
925
+ /**
926
+ * Send an email using a template
927
+ */
928
+ async sendEmail(options) {
929
+ const response = await this.client.post("/api/email/send", {
930
+ template_key: options.templateKey,
931
+ to: options.to,
932
+ context: options.context,
933
+ ...options.userId && { user_id: options.userId }
934
+ });
935
+ return this.unwrapApiResponse(response, "Failed to send email");
936
+ }
937
+ /**
938
+ * List all email templates for the application
939
+ */
940
+ async listEmailTemplates() {
941
+ const response = await this.client.get("/api/email/templates");
942
+ const payload = this.unwrapApiResponse(
943
+ response,
944
+ "Failed to list email templates"
945
+ );
946
+ if (payload && Array.isArray(payload.templates)) {
947
+ return payload.templates;
948
+ }
949
+ return payload;
950
+ }
951
+ /**
952
+ * Get a single email template by key
953
+ */
954
+ async getEmailTemplate(templateKey) {
955
+ const response = await this.client.get(`/api/email/templates/${templateKey}`);
956
+ return this.unwrapApiResponse(response, "Failed to get email template");
957
+ }
958
+ /**
959
+ * Preview a rendered email template
960
+ */
961
+ async previewEmailTemplate(templateKey, context) {
962
+ if (context) {
963
+ const response = await this.client.post(
964
+ `/api/email/templates/${templateKey}/preview`,
965
+ { context }
966
+ );
967
+ return this.unwrapApiResponse(response, "Failed to preview email template");
968
+ } else {
969
+ const response = await this.client.get(`/api/email/templates/${templateKey}/preview`);
970
+ return this.unwrapApiResponse(response, "Failed to preview email template");
971
+ }
972
+ }
907
973
  // Admin Methods (Require admin privileges)
908
974
  /**
909
975
  * 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";
@@ -433,6 +439,17 @@ var SPAPSClient = class {
433
439
  confirmPasswordReset: async (payload) => {
434
440
  await this.client.post("/api/auth/reset-password-confirm", payload);
435
441
  },
442
+ /**
443
+ * Set or change password for authenticated users.
444
+ * For magic link / wallet users setting their first password, only new_password is required.
445
+ * For users changing an existing password, current_password is also required.
446
+ */
447
+ setPassword: async (payload) => {
448
+ const res = await this.client.post("/api/auth/set-password", payload);
449
+ const body = res.data;
450
+ if (body?.success === false) throw new Error(body?.error?.message || "Set password failed");
451
+ return { message: body?.message || "Password updated successfully" };
452
+ },
436
453
  register: async (payload) => {
437
454
  const res = await this.client.post("/api/auth/register", payload);
438
455
  const body = res.data;
@@ -877,6 +894,55 @@ var SPAPSClient = class {
877
894
  }
878
895
  return payload;
879
896
  }
897
+ // Email Methods
898
+ /**
899
+ * Send an email using a template
900
+ */
901
+ async sendEmail(options) {
902
+ const response = await this.client.post("/api/email/send", {
903
+ template_key: options.templateKey,
904
+ to: options.to,
905
+ context: options.context,
906
+ ...options.userId && { user_id: options.userId }
907
+ });
908
+ return this.unwrapApiResponse(response, "Failed to send email");
909
+ }
910
+ /**
911
+ * List all email templates for the application
912
+ */
913
+ async listEmailTemplates() {
914
+ const response = await this.client.get("/api/email/templates");
915
+ const payload = this.unwrapApiResponse(
916
+ response,
917
+ "Failed to list email templates"
918
+ );
919
+ if (payload && Array.isArray(payload.templates)) {
920
+ return payload.templates;
921
+ }
922
+ return payload;
923
+ }
924
+ /**
925
+ * Get a single email template by key
926
+ */
927
+ async getEmailTemplate(templateKey) {
928
+ const response = await this.client.get(`/api/email/templates/${templateKey}`);
929
+ return this.unwrapApiResponse(response, "Failed to get email template");
930
+ }
931
+ /**
932
+ * Preview a rendered email template
933
+ */
934
+ async previewEmailTemplate(templateKey, context) {
935
+ if (context) {
936
+ const response = await this.client.post(
937
+ `/api/email/templates/${templateKey}/preview`,
938
+ { context }
939
+ );
940
+ return this.unwrapApiResponse(response, "Failed to preview email template");
941
+ } else {
942
+ const response = await this.client.get(`/api/email/templates/${templateKey}/preview`);
943
+ return this.unwrapApiResponse(response, "Failed to preview email template");
944
+ }
945
+ }
880
946
  // Admin Methods (Require admin privileges)
881
947
  /**
882
948
  * 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.0",
3
+ "version": "1.5.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.59",
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
+ }