feeef 0.5.38-dev.3 → 0.6.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/build/index.js CHANGED
@@ -55,12 +55,32 @@ var ModelRepository = class {
55
55
  }
56
56
  /**
57
57
  * Creates a new model.
58
- * @param options - The options for creating the model.
58
+ * Supports two call patterns:
59
+ * 1. `create(data, params?)` - Pass data directly with optional params
60
+ * 2. `create({ data, params })` - Pass options object
61
+ * @param dataOrOptions - The data to create or options object containing data and params
62
+ * @param params - Optional query parameters (only used when data is passed directly)
59
63
  * @returns A promise that resolves to the created model.
60
64
  */
61
- async create(options) {
62
- const { data, params } = options;
63
- const res = await this.client.post(`/${this.resource}`, data, { params });
65
+ async create(dataOrOptions, params) {
66
+ if (dataOrOptions && typeof dataOrOptions === "object" && "data" in dataOrOptions) {
67
+ const options2 = dataOrOptions;
68
+ const { data, params: optionsParams } = options2;
69
+ const requestParams = optionsParams || params;
70
+ const res2 = await this.client.post(`/${this.resource}`, data, {
71
+ params: requestParams
72
+ });
73
+ return res2.data;
74
+ }
75
+ const options = {
76
+ data: dataOrOptions
77
+ };
78
+ if (params) {
79
+ options.params = params;
80
+ }
81
+ const res = await this.client.post(`/${this.resource}`, options.data, {
82
+ params: options.params
83
+ });
64
84
  return res.data;
65
85
  }
66
86
  /**
@@ -190,9 +210,27 @@ var StoreRepository = class extends ModelRepository {
190
210
  // src/feeef/repositories/users.ts
191
211
  var UserRepository = class extends ModelRepository {
192
212
  /**
193
- * Represents the authentication response.
213
+ * Represents the current authentication response.
214
+ * Set automatically after signin, signup, or signinWithToken.
194
215
  */
195
- auth = null;
216
+ _auth = null;
217
+ /**
218
+ * Gets the current authentication response.
219
+ */
220
+ get auth() {
221
+ return this._auth;
222
+ }
223
+ /**
224
+ * Sets the authentication response and updates the Authorization header.
225
+ */
226
+ set auth(value) {
227
+ this._auth = value;
228
+ if (value?.token?.token) {
229
+ this.client.defaults.headers.common["Authorization"] = `Bearer ${value.token.token}`;
230
+ } else {
231
+ delete this.client.defaults.headers.common["Authorization"];
232
+ }
233
+ }
196
234
  /**
197
235
  * Constructs a new UserRepository instance.
198
236
  * @param client - The AxiosInstance used for making HTTP requests.
@@ -202,43 +240,264 @@ var UserRepository = class extends ModelRepository {
202
240
  }
203
241
  /**
204
242
  * Signs in a user with the provided credentials.
205
- * @param credentials - The user credentials.
243
+ * @param credentials - The user credentials (email, password, optional fcmToken).
206
244
  * @returns A promise that resolves to the authentication response.
207
245
  */
208
246
  async signin(credentials) {
209
- const output = credentials;
210
- const res = await this.client.post(`/${this.resource}/auth/signin`, output);
247
+ const res = await this.client.post(`/${this.resource}/auth/signin`, credentials);
211
248
  this.auth = res.data;
212
- return res.data;
249
+ return this.auth;
213
250
  }
214
251
  /**
215
252
  * Signs up a new user with the provided credentials.
216
- * @param credentials - The user credentials.
253
+ * @param credentials - The user signup credentials.
217
254
  * @returns A promise that resolves to the authentication response.
218
255
  */
219
256
  async signup(credentials) {
220
- const output = credentials;
221
- const res = await this.client.post(`/${this.resource}/auth/signup`, output);
257
+ const res = await this.client.post(`/${this.resource}/auth/signup`, credentials);
222
258
  this.auth = res.data;
223
- return res.data;
259
+ return this.auth;
260
+ }
261
+ /**
262
+ * Signs in a user with an existing token.
263
+ * Useful for restoring authentication state from localStorage.
264
+ * @param token - The authentication token.
265
+ * @param fcmToken - Optional FCM token for push notifications.
266
+ * @returns A promise that resolves to the authentication response.
267
+ */
268
+ async signinWithToken(token, fcmToken) {
269
+ this.client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
270
+ const res = await this.client.get(`/${this.resource}/auth`);
271
+ if (fcmToken) {
272
+ try {
273
+ await this.client.post(`/${this.resource}/auth/fcm-token`, { fcmToken });
274
+ } catch (e) {
275
+ console.warn("Failed to update FCM token:", e);
276
+ }
277
+ }
278
+ this.auth = {
279
+ user: res.data.user,
280
+ token: { ...res.data.token, token }
281
+ };
282
+ return this.auth;
224
283
  }
225
284
  /**
226
285
  * Signs out the currently authenticated user.
286
+ * Deletes the token on the server and clears local auth state.
227
287
  * @returns A promise that resolves when the user is signed out.
228
288
  */
229
289
  async signout() {
290
+ if (this.auth) {
291
+ try {
292
+ await this.client.post(`/${this.resource}/auth/signout`);
293
+ } catch (e) {
294
+ console.warn("Signout request failed:", e);
295
+ }
296
+ }
230
297
  this.auth = null;
231
298
  }
232
299
  /**
233
- * Updates the authenticated user's data.
300
+ * Gets the currently authenticated user.
301
+ * @returns A promise that resolves to the authentication response with current user.
302
+ */
303
+ async me() {
304
+ const res = await this.client.get(`/${this.resource}/auth`);
305
+ this.auth = res.data;
306
+ return this.auth;
307
+ }
308
+ /**
309
+ * Updates the authenticated user's profile.
234
310
  * @param data - The updated user data.
235
311
  * @returns A promise that resolves to the updated user entity.
236
312
  */
237
313
  async updateMe(data) {
238
- const output = data;
239
- const res = await this.client.put(`/${this.resource}/auth`, output);
314
+ const res = await this.client.put(`/${this.resource}/auth`, data);
315
+ if (this.auth) {
316
+ this.auth = {
317
+ ...this.auth,
318
+ user: res.data
319
+ };
320
+ }
321
+ return res.data;
322
+ }
323
+ /**
324
+ * Sends a password reset email to the user.
325
+ * @param email - The user's email address.
326
+ * @returns A promise that resolves when the email is sent.
327
+ */
328
+ async sendResetPasswordEmail(email) {
329
+ await this.client.post(`/${this.resource}/auth/reset-password`, null, {
330
+ params: { email }
331
+ });
332
+ }
333
+ /**
334
+ * Resets the password using a token from the reset email.
335
+ * @param uid - The user ID.
336
+ * @param token - The reset token from the email.
337
+ * @returns A promise that resolves when the password is reset.
338
+ */
339
+ async resetPasswordWithToken(uid, token) {
340
+ await this.client.get(`/${this.resource}/auth/reset-password`, {
341
+ params: { uid, token }
342
+ });
343
+ }
344
+ /**
345
+ * Gets all access tokens for the authenticated user.
346
+ * @returns A promise that resolves to an array of access tokens.
347
+ */
348
+ async tokens() {
349
+ const res = await this.client.get(`/${this.resource}/auth/tokens`);
350
+ return res.data;
351
+ }
352
+ /**
353
+ * Signs in with Google OAuth.
354
+ * @param options - The OAuth code and optional FCM token.
355
+ * @returns A promise that resolves to the authentication response.
356
+ */
357
+ async signinWithGoogle(options) {
358
+ const res = await this.client.post("/social/google/callback", {
359
+ code: options.code,
360
+ fcmToken: options.fcmToken
361
+ });
362
+ this.auth = res.data;
363
+ return this.auth;
364
+ }
365
+ /**
366
+ * Signs in with GitHub OAuth.
367
+ * @param options - The OAuth code and optional FCM token.
368
+ * @returns A promise that resolves to the authentication response.
369
+ */
370
+ async signinWithGitHub(options) {
371
+ const res = await this.client.post("/social/github/callback", {
372
+ code: options.code,
373
+ fcmToken: options.fcmToken
374
+ });
375
+ this.auth = res.data;
376
+ return this.auth;
377
+ }
378
+ /**
379
+ * Signs in with Apple OAuth.
380
+ * @param options - The OAuth code and optional FCM token.
381
+ * @returns A promise that resolves to the authentication response.
382
+ */
383
+ async signinWithApple(options) {
384
+ const res = await this.client.post("/social/apple/callback", {
385
+ code: options.code,
386
+ fcmToken: options.fcmToken
387
+ });
388
+ this.auth = res.data;
389
+ return this.auth;
390
+ }
391
+ /**
392
+ * Links a social account to the current user.
393
+ * @param options - The provider and OAuth code.
394
+ * @returns A promise that resolves to the updated user entity.
395
+ */
396
+ async linkSocialAccount(options) {
397
+ const res = await this.client.post(`/social/${options.provider}/link/callback`, {
398
+ code: options.code
399
+ });
400
+ if (this.auth && this.auth.user.id === res.data.user.id) {
401
+ this.auth = {
402
+ ...this.auth,
403
+ user: res.data.user
404
+ };
405
+ }
406
+ return res.data.user;
407
+ }
408
+ /**
409
+ * Unlinks a social account from the current user.
410
+ * @param provider - The social provider to unlink.
411
+ * @returns A promise that resolves to the updated user entity.
412
+ */
413
+ async unlinkSocialAccount(provider) {
414
+ const res = await this.client.post("/social/unlink", { provider });
415
+ if (this.auth && this.auth.user.id === res.data.user.id) {
416
+ this.auth = {
417
+ ...this.auth,
418
+ user: res.data.user
419
+ };
420
+ }
421
+ return res.data.user;
422
+ }
423
+ /**
424
+ * Transfers money from the authenticated user to another user.
425
+ * @param options - Transfer options including recipient and amount.
426
+ * @returns A promise that resolves to the transfer response with updated users.
427
+ */
428
+ async transferMoney(options) {
429
+ const res = await this.client.post(`/${this.resource}/auth/transfer`, options);
430
+ if (this.auth && this.auth.user.id === res.data.sender.id) {
431
+ this.auth = {
432
+ ...this.auth,
433
+ user: res.data.sender
434
+ };
435
+ }
240
436
  return res.data;
241
437
  }
438
+ /**
439
+ * Starts passkey registration.
440
+ * @param options - Optional device name for the passkey.
441
+ * @returns A promise that resolves to the registration challenge data.
442
+ */
443
+ async startPasskeyRegistration(options) {
444
+ const res = await this.client.post("/passkeys/register/start", {
445
+ deviceName: options?.deviceName
446
+ });
447
+ return res.data;
448
+ }
449
+ /**
450
+ * Finishes passkey registration.
451
+ * @param options - The registration response from the authenticator.
452
+ * @returns A promise that resolves to the authentication response.
453
+ */
454
+ async finishPasskeyRegistration(options) {
455
+ const res = await this.client.post("/passkeys/register/finish", {
456
+ response: options.registrationResponse,
457
+ deviceName: options.deviceName
458
+ });
459
+ this.auth = res.data;
460
+ return this.auth;
461
+ }
462
+ /**
463
+ * Starts passkey authentication.
464
+ * @param options - Optional email to identify the user.
465
+ * @returns A promise that resolves to the authentication challenge data.
466
+ */
467
+ async startPasskeyAuthentication(options) {
468
+ const res = await this.client.post("/passkeys/authenticate/start", {
469
+ email: options?.email
470
+ });
471
+ return res.data;
472
+ }
473
+ /**
474
+ * Finishes passkey authentication.
475
+ * @param options - The authentication response from the authenticator.
476
+ * @returns A promise that resolves to the authentication response.
477
+ */
478
+ async finishPasskeyAuthentication(options) {
479
+ const res = await this.client.post("/passkeys/authenticate/finish", {
480
+ response: options.authenticationResponse
481
+ });
482
+ this.auth = res.data;
483
+ return this.auth;
484
+ }
485
+ /**
486
+ * Lists all passkeys for the authenticated user.
487
+ * @returns A promise that resolves to an array of passkeys.
488
+ */
489
+ async listPasskeys() {
490
+ const res = await this.client.get("/passkeys");
491
+ return res.data.passkeys || [];
492
+ }
493
+ /**
494
+ * Deletes a passkey.
495
+ * @param passkeyId - The ID of the passkey to delete.
496
+ * @returns A promise that resolves when the passkey is deleted.
497
+ */
498
+ async deletePasskey(passkeyId) {
499
+ await this.client.delete(`/passkeys/${passkeyId}`);
500
+ }
242
501
  };
243
502
 
244
503
  // src/feeef/repositories/deposits.ts
@@ -250,6 +509,9 @@ var DepositRepository = class extends ModelRepository {
250
509
  constructor(client) {
251
510
  super("deposits", client);
252
511
  }
512
+ // The create method is inherited from ModelRepository and supports both:
513
+ // 1. create(data, params?) - Pass data directly
514
+ // 2. create({ data, params }) - Pass options object
253
515
  /**
254
516
  * Create a new deposit request
255
517
  * @param data - The deposit data
@@ -304,6 +566,20 @@ var DepositRepository = class extends ModelRepository {
304
566
  }
305
567
  };
306
568
 
569
+ // src/feeef/repositories/transfers.ts
570
+ var TransferRepository = class extends ModelRepository {
571
+ /**
572
+ * Constructs a new TransferRepository instance
573
+ * @param client - The AxiosInstance used for making HTTP requests
574
+ */
575
+ constructor(client) {
576
+ super("transfers", client);
577
+ }
578
+ // The create method is inherited from ModelRepository and supports both:
579
+ // 1. create(data, params?) - Pass data directly
580
+ // 2. create({ data, params }) - Pass options object
581
+ };
582
+
307
583
  // src/feeef/repositories/categories.ts
308
584
  var CategoryRepository = class extends ModelRepository {
309
585
  /**
@@ -557,6 +833,26 @@ var CityRepository = class extends ModelRepository {
557
833
  }
558
834
  };
559
835
 
836
+ // src/feeef/repositories/currencies.ts
837
+ var CurrencyRepository = class extends ModelRepository {
838
+ /**
839
+ * Constructs a new CurrencyRepository instance.
840
+ * @param client The AxiosInstance used for making HTTP requests.
841
+ */
842
+ constructor(client) {
843
+ super("currencies", client);
844
+ }
845
+ /**
846
+ * Finds a currency by its code (ID is the currency code).
847
+ * @param code - The currency code (ISO 4217, e.g., USD, EUR).
848
+ * @param params - Optional query parameters.
849
+ * @returns A Promise that resolves to the found Currency entity.
850
+ */
851
+ async findByCode(code, params) {
852
+ return this.find({ id: code.toUpperCase(), params });
853
+ }
854
+ };
855
+
560
856
  // src/feeef/repositories/shipping_prices.ts
561
857
  var ShippingPriceRepository = class extends ModelRepository {
562
858
  /**
@@ -1555,6 +1851,10 @@ var FeeeF = class {
1555
1851
  * The repository for managing deposits.
1556
1852
  */
1557
1853
  deposits;
1854
+ /**
1855
+ * The repository for managing transfers.
1856
+ */
1857
+ transfers;
1558
1858
  /**
1559
1859
  * The repository for managing categories.
1560
1860
  */
@@ -1571,6 +1871,10 @@ var FeeeF = class {
1571
1871
  * The repository for managing cities.
1572
1872
  */
1573
1873
  cities;
1874
+ /**
1875
+ * The repository for managing currencies.
1876
+ */
1877
+ currencies;
1574
1878
  /**
1575
1879
  * The repository for managing shipping prices.
1576
1880
  */
@@ -1602,10 +1906,12 @@ var FeeeF = class {
1602
1906
  this.users = new UserRepository(this.client);
1603
1907
  this.orders = new OrderRepository(this.client);
1604
1908
  this.deposits = new DepositRepository(this.client);
1909
+ this.transfers = new TransferRepository(this.client);
1605
1910
  this.categories = new CategoryRepository(this.client);
1606
1911
  this.countries = new CountryRepository(this.client);
1607
1912
  this.states = new StateRepository(this.client);
1608
1913
  this.cities = new CityRepository(this.client);
1914
+ this.currencies = new CurrencyRepository(this.client);
1609
1915
  this.shippingPrices = new ShippingPriceRepository(this.client);
1610
1916
  this.cart = new CartService();
1611
1917
  this.actions = new ActionsService(this.client);
@@ -1989,6 +2295,8 @@ export {
1989
2295
  StoreSubscriptionStatus,
1990
2296
  StoreSubscriptionType,
1991
2297
  TiktokPixelEvent,
2298
+ TransferRepository,
2299
+ UserRepository,
1992
2300
  VariantOptionType,
1993
2301
  WebhookEvent,
1994
2302
  convertDartColorToCssNumber,