@wowsql/sdk 3.6.0 → 3.7.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/auth.d.ts +68 -0
- package/dist/auth.js +139 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +97 -0
- package/package.json +1 -1
package/dist/auth.d.ts
CHANGED
|
@@ -146,6 +146,74 @@ export declare class ProjectAuthClient {
|
|
|
146
146
|
success: boolean;
|
|
147
147
|
message: string;
|
|
148
148
|
}>;
|
|
149
|
+
/**
|
|
150
|
+
* Send OTP code to user's email.
|
|
151
|
+
*
|
|
152
|
+
* Supports login, signup, and password_reset purposes.
|
|
153
|
+
*
|
|
154
|
+
* @param email - User's email address
|
|
155
|
+
* @param purpose - Purpose of OTP - 'login', 'signup', or 'password_reset' (default: 'login')
|
|
156
|
+
* @returns Object with success status and message
|
|
157
|
+
*/
|
|
158
|
+
sendOtp(email: string, purpose?: 'login' | 'signup' | 'password_reset'): Promise<{
|
|
159
|
+
success: boolean;
|
|
160
|
+
message: string;
|
|
161
|
+
}>;
|
|
162
|
+
/**
|
|
163
|
+
* Verify OTP and complete authentication.
|
|
164
|
+
*
|
|
165
|
+
* For signup: Creates new user if doesn't exist
|
|
166
|
+
* For login: Authenticates existing user
|
|
167
|
+
* For password_reset: Updates password if newPassword provided
|
|
168
|
+
*
|
|
169
|
+
* @param email - User's email address
|
|
170
|
+
* @param otp - 6-digit OTP code
|
|
171
|
+
* @param purpose - Purpose of OTP - 'login', 'signup', or 'password_reset' (default: 'login')
|
|
172
|
+
* @param newPassword - Required for password_reset purpose, new password (minimum 8 characters)
|
|
173
|
+
* @returns AuthResponse with session tokens and user info (for login/signup) or success message (for password_reset)
|
|
174
|
+
*/
|
|
175
|
+
verifyOtp(email: string, otp: string, purpose?: 'login' | 'signup' | 'password_reset', newPassword?: string): Promise<AuthResponse | {
|
|
176
|
+
success: boolean;
|
|
177
|
+
message: string;
|
|
178
|
+
}>;
|
|
179
|
+
/**
|
|
180
|
+
* Send magic link to user's email.
|
|
181
|
+
*
|
|
182
|
+
* Supports login, signup, and email_verification purposes.
|
|
183
|
+
*
|
|
184
|
+
* @param email - User's email address
|
|
185
|
+
* @param purpose - Purpose of magic link - 'login', 'signup', or 'email_verification' (default: 'login')
|
|
186
|
+
* @returns Object with success status and message
|
|
187
|
+
*/
|
|
188
|
+
sendMagicLink(email: string, purpose?: 'login' | 'signup' | 'email_verification'): Promise<{
|
|
189
|
+
success: boolean;
|
|
190
|
+
message: string;
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Verify email using token (from magic link or OTP verification).
|
|
194
|
+
*
|
|
195
|
+
* Marks email as verified and sends welcome email.
|
|
196
|
+
*
|
|
197
|
+
* @param token - Verification token from email
|
|
198
|
+
* @returns Object with success status, message, and user info
|
|
199
|
+
*/
|
|
200
|
+
verifyEmail(token: string): Promise<{
|
|
201
|
+
success: boolean;
|
|
202
|
+
message: string;
|
|
203
|
+
user?: AuthUser;
|
|
204
|
+
}>;
|
|
205
|
+
/**
|
|
206
|
+
* Resend verification email.
|
|
207
|
+
*
|
|
208
|
+
* Always returns success to prevent email enumeration.
|
|
209
|
+
*
|
|
210
|
+
* @param email - User's email address
|
|
211
|
+
* @returns Object with success status and message
|
|
212
|
+
*/
|
|
213
|
+
resendVerification(email: string): Promise<{
|
|
214
|
+
success: boolean;
|
|
215
|
+
message: string;
|
|
216
|
+
}>;
|
|
149
217
|
/**
|
|
150
218
|
* Get the current session tokens.
|
|
151
219
|
*/
|
package/dist/auth.js
CHANGED
|
@@ -216,6 +216,145 @@ class ProjectAuthClient {
|
|
|
216
216
|
throw this.toWowError(error);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* Send OTP code to user's email.
|
|
221
|
+
*
|
|
222
|
+
* Supports login, signup, and password_reset purposes.
|
|
223
|
+
*
|
|
224
|
+
* @param email - User's email address
|
|
225
|
+
* @param purpose - Purpose of OTP - 'login', 'signup', or 'password_reset' (default: 'login')
|
|
226
|
+
* @returns Object with success status and message
|
|
227
|
+
*/
|
|
228
|
+
async sendOtp(email, purpose = 'login') {
|
|
229
|
+
if (!['login', 'signup', 'password_reset'].includes(purpose)) {
|
|
230
|
+
throw new errors_1.WOWSQLError("Purpose must be 'login', 'signup', or 'password_reset'");
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
const response = await this.client.post('/otp/send', {
|
|
234
|
+
email,
|
|
235
|
+
purpose
|
|
236
|
+
});
|
|
237
|
+
return {
|
|
238
|
+
success: response.data.success ?? true,
|
|
239
|
+
message: response.data.message ?? 'If that email exists, an OTP code has been sent'
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
throw this.toWowError(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Verify OTP and complete authentication.
|
|
248
|
+
*
|
|
249
|
+
* For signup: Creates new user if doesn't exist
|
|
250
|
+
* For login: Authenticates existing user
|
|
251
|
+
* For password_reset: Updates password if newPassword provided
|
|
252
|
+
*
|
|
253
|
+
* @param email - User's email address
|
|
254
|
+
* @param otp - 6-digit OTP code
|
|
255
|
+
* @param purpose - Purpose of OTP - 'login', 'signup', or 'password_reset' (default: 'login')
|
|
256
|
+
* @param newPassword - Required for password_reset purpose, new password (minimum 8 characters)
|
|
257
|
+
* @returns AuthResponse with session tokens and user info (for login/signup) or success message (for password_reset)
|
|
258
|
+
*/
|
|
259
|
+
async verifyOtp(email, otp, purpose = 'login', newPassword) {
|
|
260
|
+
if (!['login', 'signup', 'password_reset'].includes(purpose)) {
|
|
261
|
+
throw new errors_1.WOWSQLError("Purpose must be 'login', 'signup', or 'password_reset'");
|
|
262
|
+
}
|
|
263
|
+
if (purpose === 'password_reset' && !newPassword) {
|
|
264
|
+
throw new errors_1.WOWSQLError("newPassword is required for password_reset purpose");
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
const payload = {
|
|
268
|
+
email,
|
|
269
|
+
otp,
|
|
270
|
+
purpose
|
|
271
|
+
};
|
|
272
|
+
if (newPassword) {
|
|
273
|
+
payload.new_password = newPassword;
|
|
274
|
+
}
|
|
275
|
+
const response = await this.client.post('/otp/verify', payload);
|
|
276
|
+
if (purpose === 'password_reset') {
|
|
277
|
+
return {
|
|
278
|
+
success: response.data.success ?? true,
|
|
279
|
+
message: response.data.message ?? 'Password reset successfully! You can now login with your new password'
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const session = this.persistSession(response.data);
|
|
283
|
+
const user = response.data.user ? mapUser(response.data.user) : undefined;
|
|
284
|
+
return { user, session };
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
throw this.toWowError(error);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Send magic link to user's email.
|
|
292
|
+
*
|
|
293
|
+
* Supports login, signup, and email_verification purposes.
|
|
294
|
+
*
|
|
295
|
+
* @param email - User's email address
|
|
296
|
+
* @param purpose - Purpose of magic link - 'login', 'signup', or 'email_verification' (default: 'login')
|
|
297
|
+
* @returns Object with success status and message
|
|
298
|
+
*/
|
|
299
|
+
async sendMagicLink(email, purpose = 'login') {
|
|
300
|
+
if (!['login', 'signup', 'email_verification'].includes(purpose)) {
|
|
301
|
+
throw new errors_1.WOWSQLError("Purpose must be 'login', 'signup', or 'email_verification'");
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
const response = await this.client.post('/magic-link/send', {
|
|
305
|
+
email,
|
|
306
|
+
purpose
|
|
307
|
+
});
|
|
308
|
+
return {
|
|
309
|
+
success: response.data.success ?? true,
|
|
310
|
+
message: response.data.message ?? 'If that email exists, a magic link has been sent'
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
throw this.toWowError(error);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Verify email using token (from magic link or OTP verification).
|
|
319
|
+
*
|
|
320
|
+
* Marks email as verified and sends welcome email.
|
|
321
|
+
*
|
|
322
|
+
* @param token - Verification token from email
|
|
323
|
+
* @returns Object with success status, message, and user info
|
|
324
|
+
*/
|
|
325
|
+
async verifyEmail(token) {
|
|
326
|
+
try {
|
|
327
|
+
const response = await this.client.post('/verify-email', { token });
|
|
328
|
+
return {
|
|
329
|
+
success: response.data.success ?? true,
|
|
330
|
+
message: response.data.message ?? 'Email verified successfully!',
|
|
331
|
+
user: response.data.user ? mapUser(response.data.user) : undefined
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
throw this.toWowError(error);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Resend verification email.
|
|
340
|
+
*
|
|
341
|
+
* Always returns success to prevent email enumeration.
|
|
342
|
+
*
|
|
343
|
+
* @param email - User's email address
|
|
344
|
+
* @returns Object with success status and message
|
|
345
|
+
*/
|
|
346
|
+
async resendVerification(email) {
|
|
347
|
+
try {
|
|
348
|
+
const response = await this.client.post('/resend-verification', { email });
|
|
349
|
+
return {
|
|
350
|
+
success: response.data.success ?? true,
|
|
351
|
+
message: response.data.message ?? 'If that email exists, a verification email has been sent'
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
throw this.toWowError(error);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
219
358
|
/**
|
|
220
359
|
* Get the current session tokens.
|
|
221
360
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -144,6 +144,10 @@ export declare class Table<T = any> {
|
|
|
144
144
|
* Create a new record
|
|
145
145
|
*/
|
|
146
146
|
create(data: Partial<T>): Promise<CreateResponse>;
|
|
147
|
+
/**
|
|
148
|
+
* Insert a new record (alias for create)
|
|
149
|
+
*/
|
|
150
|
+
insert(data: Partial<T>): Promise<CreateResponse>;
|
|
147
151
|
/**
|
|
148
152
|
* Update a record by ID
|
|
149
153
|
*/
|
|
@@ -202,10 +206,70 @@ export declare class QueryBuilder<T = any> {
|
|
|
202
206
|
* Skip records (pagination)
|
|
203
207
|
*/
|
|
204
208
|
offset(offset: number): this;
|
|
209
|
+
/**
|
|
210
|
+
* Filter where column equals value
|
|
211
|
+
*/
|
|
212
|
+
eq(column: string, value: any): this;
|
|
213
|
+
/**
|
|
214
|
+
* Filter where column does not equal value
|
|
215
|
+
*/
|
|
216
|
+
neq(column: string, value: any): this;
|
|
217
|
+
/**
|
|
218
|
+
* Filter where column is greater than value
|
|
219
|
+
*/
|
|
220
|
+
gt(column: string, value: any): this;
|
|
221
|
+
/**
|
|
222
|
+
* Filter where column is greater than or equal to value
|
|
223
|
+
*/
|
|
224
|
+
gte(column: string, value: any): this;
|
|
225
|
+
/**
|
|
226
|
+
* Filter where column is less than value
|
|
227
|
+
*/
|
|
228
|
+
lt(column: string, value: any): this;
|
|
229
|
+
/**
|
|
230
|
+
* Filter where column is less than or equal to value
|
|
231
|
+
*/
|
|
232
|
+
lte(column: string, value: any): this;
|
|
233
|
+
/**
|
|
234
|
+
* Filter where column matches pattern (SQL LIKE)
|
|
235
|
+
*/
|
|
236
|
+
like(column: string, value: string): this;
|
|
237
|
+
/**
|
|
238
|
+
* Filter where column IS NULL
|
|
239
|
+
*/
|
|
240
|
+
isNull(column: string): this;
|
|
241
|
+
/**
|
|
242
|
+
* Filter where column IS NOT NULL
|
|
243
|
+
*/
|
|
244
|
+
isNotNull(column: string): this;
|
|
245
|
+
/**
|
|
246
|
+
* Filter where column is in list of values
|
|
247
|
+
*/
|
|
248
|
+
in(column: string, values: any[]): this;
|
|
249
|
+
/**
|
|
250
|
+
* Filter where column is not in list of values
|
|
251
|
+
*/
|
|
252
|
+
notIn(column: string, values: any[]): this;
|
|
253
|
+
/**
|
|
254
|
+
* Filter where column is between min and max values
|
|
255
|
+
*/
|
|
256
|
+
between(column: string, minValue: any, maxValue: any): this;
|
|
257
|
+
/**
|
|
258
|
+
* Filter where column is not between min and max values
|
|
259
|
+
*/
|
|
260
|
+
notBetween(column: string, minValue: any, maxValue: any): this;
|
|
261
|
+
/**
|
|
262
|
+
* Add an OR filter condition
|
|
263
|
+
*/
|
|
264
|
+
or(column: string, operator: FilterExpression['operator'], value: any): this;
|
|
205
265
|
/**
|
|
206
266
|
* Execute query - uses POST /{table}/query for advanced features, GET for simple queries
|
|
207
267
|
*/
|
|
208
268
|
get(additionalOptions?: QueryOptions): Promise<QueryResponse<T>>;
|
|
269
|
+
/**
|
|
270
|
+
* Execute the query (alias for get)
|
|
271
|
+
*/
|
|
272
|
+
execute(additionalOptions?: QueryOptions): Promise<QueryResponse<T>>;
|
|
209
273
|
/**
|
|
210
274
|
* Get first record
|
|
211
275
|
*/
|
package/dist/index.js
CHANGED
|
@@ -148,6 +148,12 @@ class Table {
|
|
|
148
148
|
const response = await this.client.post(`/${this.tableName}`, data);
|
|
149
149
|
return response.data;
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Insert a new record (alias for create)
|
|
153
|
+
*/
|
|
154
|
+
async insert(data) {
|
|
155
|
+
return this.create(data);
|
|
156
|
+
}
|
|
151
157
|
/**
|
|
152
158
|
* Update a record by ID
|
|
153
159
|
*/
|
|
@@ -272,6 +278,91 @@ class QueryBuilder {
|
|
|
272
278
|
this.options.offset = offset;
|
|
273
279
|
return this;
|
|
274
280
|
}
|
|
281
|
+
// ==================== Convenience Methods ====================
|
|
282
|
+
/**
|
|
283
|
+
* Filter where column equals value
|
|
284
|
+
*/
|
|
285
|
+
eq(column, value) {
|
|
286
|
+
return this.filter(column, 'eq', value);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Filter where column does not equal value
|
|
290
|
+
*/
|
|
291
|
+
neq(column, value) {
|
|
292
|
+
return this.filter(column, 'neq', value);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Filter where column is greater than value
|
|
296
|
+
*/
|
|
297
|
+
gt(column, value) {
|
|
298
|
+
return this.filter(column, 'gt', value);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Filter where column is greater than or equal to value
|
|
302
|
+
*/
|
|
303
|
+
gte(column, value) {
|
|
304
|
+
return this.filter(column, 'gte', value);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Filter where column is less than value
|
|
308
|
+
*/
|
|
309
|
+
lt(column, value) {
|
|
310
|
+
return this.filter(column, 'lt', value);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Filter where column is less than or equal to value
|
|
314
|
+
*/
|
|
315
|
+
lte(column, value) {
|
|
316
|
+
return this.filter(column, 'lte', value);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Filter where column matches pattern (SQL LIKE)
|
|
320
|
+
*/
|
|
321
|
+
like(column, value) {
|
|
322
|
+
return this.filter(column, 'like', value);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Filter where column IS NULL
|
|
326
|
+
*/
|
|
327
|
+
isNull(column) {
|
|
328
|
+
return this.filter(column, 'is', null);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Filter where column IS NOT NULL
|
|
332
|
+
*/
|
|
333
|
+
isNotNull(column) {
|
|
334
|
+
return this.filter(column, 'is_not', null);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Filter where column is in list of values
|
|
338
|
+
*/
|
|
339
|
+
in(column, values) {
|
|
340
|
+
return this.filter(column, 'in', values);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Filter where column is not in list of values
|
|
344
|
+
*/
|
|
345
|
+
notIn(column, values) {
|
|
346
|
+
return this.filter(column, 'not_in', values);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Filter where column is between min and max values
|
|
350
|
+
*/
|
|
351
|
+
between(column, minValue, maxValue) {
|
|
352
|
+
return this.filter(column, 'between', [minValue, maxValue]);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Filter where column is not between min and max values
|
|
356
|
+
*/
|
|
357
|
+
notBetween(column, minValue, maxValue) {
|
|
358
|
+
return this.filter(column, 'not_between', [minValue, maxValue]);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Add an OR filter condition
|
|
362
|
+
*/
|
|
363
|
+
or(column, operator, value) {
|
|
364
|
+
return this.filter(column, operator, value, 'OR');
|
|
365
|
+
}
|
|
275
366
|
/**
|
|
276
367
|
* Execute query - uses POST /{table}/query for advanced features, GET for simple queries
|
|
277
368
|
*/
|
|
@@ -366,6 +457,12 @@ class QueryBuilder {
|
|
|
366
457
|
return response.data;
|
|
367
458
|
}
|
|
368
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Execute the query (alias for get)
|
|
462
|
+
*/
|
|
463
|
+
async execute(additionalOptions) {
|
|
464
|
+
return this.get(additionalOptions);
|
|
465
|
+
}
|
|
369
466
|
/**
|
|
370
467
|
* Get first record
|
|
371
468
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wowsql/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Official TypeScript/JavaScript SDK for WowSQL - MySQL Backend-as-a-Service with S3 Storage, type-safe queries and fluent API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|