feeef 0.5.38-dev.3 → 0.5.38-dev.4

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
@@ -190,9 +190,27 @@ var StoreRepository = class extends ModelRepository {
190
190
  // src/feeef/repositories/users.ts
191
191
  var UserRepository = class extends ModelRepository {
192
192
  /**
193
- * Represents the authentication response.
193
+ * Represents the current authentication response.
194
+ * Set automatically after signin, signup, or signinWithToken.
194
195
  */
195
- auth = null;
196
+ _auth = null;
197
+ /**
198
+ * Gets the current authentication response.
199
+ */
200
+ get auth() {
201
+ return this._auth;
202
+ }
203
+ /**
204
+ * Sets the authentication response and updates the Authorization header.
205
+ */
206
+ set auth(value) {
207
+ this._auth = value;
208
+ if (value?.token?.token) {
209
+ this.client.defaults.headers.common["Authorization"] = `Bearer ${value.token.token}`;
210
+ } else {
211
+ delete this.client.defaults.headers.common["Authorization"];
212
+ }
213
+ }
196
214
  /**
197
215
  * Constructs a new UserRepository instance.
198
216
  * @param client - The AxiosInstance used for making HTTP requests.
@@ -202,43 +220,264 @@ var UserRepository = class extends ModelRepository {
202
220
  }
203
221
  /**
204
222
  * Signs in a user with the provided credentials.
205
- * @param credentials - The user credentials.
223
+ * @param credentials - The user credentials (email, password, optional fcmToken).
206
224
  * @returns A promise that resolves to the authentication response.
207
225
  */
208
226
  async signin(credentials) {
209
- const output = credentials;
210
- const res = await this.client.post(`/${this.resource}/auth/signin`, output);
227
+ const res = await this.client.post(`/${this.resource}/auth/signin`, credentials);
211
228
  this.auth = res.data;
212
- return res.data;
229
+ return this.auth;
213
230
  }
214
231
  /**
215
232
  * Signs up a new user with the provided credentials.
216
- * @param credentials - The user credentials.
233
+ * @param credentials - The user signup credentials.
217
234
  * @returns A promise that resolves to the authentication response.
218
235
  */
219
236
  async signup(credentials) {
220
- const output = credentials;
221
- const res = await this.client.post(`/${this.resource}/auth/signup`, output);
237
+ const res = await this.client.post(`/${this.resource}/auth/signup`, credentials);
222
238
  this.auth = res.data;
223
- return res.data;
239
+ return this.auth;
240
+ }
241
+ /**
242
+ * Signs in a user with an existing token.
243
+ * Useful for restoring authentication state from localStorage.
244
+ * @param token - The authentication token.
245
+ * @param fcmToken - Optional FCM token for push notifications.
246
+ * @returns A promise that resolves to the authentication response.
247
+ */
248
+ async signinWithToken(token, fcmToken) {
249
+ this.client.defaults.headers.common["Authorization"] = `Bearer ${token}`;
250
+ const res = await this.client.get(`/${this.resource}/auth`);
251
+ if (fcmToken) {
252
+ try {
253
+ await this.client.post(`/${this.resource}/auth/fcm-token`, { fcmToken });
254
+ } catch (e) {
255
+ console.warn("Failed to update FCM token:", e);
256
+ }
257
+ }
258
+ this.auth = {
259
+ user: res.data.user,
260
+ token: { ...res.data.token, token }
261
+ };
262
+ return this.auth;
224
263
  }
225
264
  /**
226
265
  * Signs out the currently authenticated user.
266
+ * Deletes the token on the server and clears local auth state.
227
267
  * @returns A promise that resolves when the user is signed out.
228
268
  */
229
269
  async signout() {
270
+ if (this.auth) {
271
+ try {
272
+ await this.client.post(`/${this.resource}/auth/signout`);
273
+ } catch (e) {
274
+ console.warn("Signout request failed:", e);
275
+ }
276
+ }
230
277
  this.auth = null;
231
278
  }
232
279
  /**
233
- * Updates the authenticated user's data.
280
+ * Gets the currently authenticated user.
281
+ * @returns A promise that resolves to the authentication response with current user.
282
+ */
283
+ async me() {
284
+ const res = await this.client.get(`/${this.resource}/auth`);
285
+ this.auth = res.data;
286
+ return this.auth;
287
+ }
288
+ /**
289
+ * Updates the authenticated user's profile.
234
290
  * @param data - The updated user data.
235
291
  * @returns A promise that resolves to the updated user entity.
236
292
  */
237
293
  async updateMe(data) {
238
- const output = data;
239
- const res = await this.client.put(`/${this.resource}/auth`, output);
294
+ const res = await this.client.put(`/${this.resource}/auth`, data);
295
+ if (this.auth) {
296
+ this.auth = {
297
+ ...this.auth,
298
+ user: res.data
299
+ };
300
+ }
301
+ return res.data;
302
+ }
303
+ /**
304
+ * Sends a password reset email to the user.
305
+ * @param email - The user's email address.
306
+ * @returns A promise that resolves when the email is sent.
307
+ */
308
+ async sendResetPasswordEmail(email) {
309
+ await this.client.post(`/${this.resource}/auth/reset-password`, null, {
310
+ params: { email }
311
+ });
312
+ }
313
+ /**
314
+ * Resets the password using a token from the reset email.
315
+ * @param uid - The user ID.
316
+ * @param token - The reset token from the email.
317
+ * @returns A promise that resolves when the password is reset.
318
+ */
319
+ async resetPasswordWithToken(uid, token) {
320
+ await this.client.get(`/${this.resource}/auth/reset-password`, {
321
+ params: { uid, token }
322
+ });
323
+ }
324
+ /**
325
+ * Gets all access tokens for the authenticated user.
326
+ * @returns A promise that resolves to an array of access tokens.
327
+ */
328
+ async tokens() {
329
+ const res = await this.client.get(`/${this.resource}/auth/tokens`);
240
330
  return res.data;
241
331
  }
332
+ /**
333
+ * Signs in with Google OAuth.
334
+ * @param options - The OAuth code and optional FCM token.
335
+ * @returns A promise that resolves to the authentication response.
336
+ */
337
+ async signinWithGoogle(options) {
338
+ const res = await this.client.post("/social/google/callback", {
339
+ code: options.code,
340
+ fcmToken: options.fcmToken
341
+ });
342
+ this.auth = res.data;
343
+ return this.auth;
344
+ }
345
+ /**
346
+ * Signs in with GitHub OAuth.
347
+ * @param options - The OAuth code and optional FCM token.
348
+ * @returns A promise that resolves to the authentication response.
349
+ */
350
+ async signinWithGitHub(options) {
351
+ const res = await this.client.post("/social/github/callback", {
352
+ code: options.code,
353
+ fcmToken: options.fcmToken
354
+ });
355
+ this.auth = res.data;
356
+ return this.auth;
357
+ }
358
+ /**
359
+ * Signs in with Apple OAuth.
360
+ * @param options - The OAuth code and optional FCM token.
361
+ * @returns A promise that resolves to the authentication response.
362
+ */
363
+ async signinWithApple(options) {
364
+ const res = await this.client.post("/social/apple/callback", {
365
+ code: options.code,
366
+ fcmToken: options.fcmToken
367
+ });
368
+ this.auth = res.data;
369
+ return this.auth;
370
+ }
371
+ /**
372
+ * Links a social account to the current user.
373
+ * @param options - The provider and OAuth code.
374
+ * @returns A promise that resolves to the updated user entity.
375
+ */
376
+ async linkSocialAccount(options) {
377
+ const res = await this.client.post(`/social/${options.provider}/link/callback`, {
378
+ code: options.code
379
+ });
380
+ if (this.auth && this.auth.user.id === res.data.user.id) {
381
+ this.auth = {
382
+ ...this.auth,
383
+ user: res.data.user
384
+ };
385
+ }
386
+ return res.data.user;
387
+ }
388
+ /**
389
+ * Unlinks a social account from the current user.
390
+ * @param provider - The social provider to unlink.
391
+ * @returns A promise that resolves to the updated user entity.
392
+ */
393
+ async unlinkSocialAccount(provider) {
394
+ const res = await this.client.post("/social/unlink", { provider });
395
+ if (this.auth && this.auth.user.id === res.data.user.id) {
396
+ this.auth = {
397
+ ...this.auth,
398
+ user: res.data.user
399
+ };
400
+ }
401
+ return res.data.user;
402
+ }
403
+ /**
404
+ * Transfers money from the authenticated user to another user.
405
+ * @param options - Transfer options including recipient and amount.
406
+ * @returns A promise that resolves to the transfer response with updated users.
407
+ */
408
+ async transferMoney(options) {
409
+ const res = await this.client.post(`/${this.resource}/auth/transfer`, options);
410
+ if (this.auth && this.auth.user.id === res.data.sender.id) {
411
+ this.auth = {
412
+ ...this.auth,
413
+ user: res.data.sender
414
+ };
415
+ }
416
+ return res.data;
417
+ }
418
+ /**
419
+ * Starts passkey registration.
420
+ * @param options - Optional device name for the passkey.
421
+ * @returns A promise that resolves to the registration challenge data.
422
+ */
423
+ async startPasskeyRegistration(options) {
424
+ const res = await this.client.post("/passkeys/register/start", {
425
+ deviceName: options?.deviceName
426
+ });
427
+ return res.data;
428
+ }
429
+ /**
430
+ * Finishes passkey registration.
431
+ * @param options - The registration response from the authenticator.
432
+ * @returns A promise that resolves to the authentication response.
433
+ */
434
+ async finishPasskeyRegistration(options) {
435
+ const res = await this.client.post("/passkeys/register/finish", {
436
+ response: options.registrationResponse,
437
+ deviceName: options.deviceName
438
+ });
439
+ this.auth = res.data;
440
+ return this.auth;
441
+ }
442
+ /**
443
+ * Starts passkey authentication.
444
+ * @param options - Optional email to identify the user.
445
+ * @returns A promise that resolves to the authentication challenge data.
446
+ */
447
+ async startPasskeyAuthentication(options) {
448
+ const res = await this.client.post("/passkeys/authenticate/start", {
449
+ email: options?.email
450
+ });
451
+ return res.data;
452
+ }
453
+ /**
454
+ * Finishes passkey authentication.
455
+ * @param options - The authentication response from the authenticator.
456
+ * @returns A promise that resolves to the authentication response.
457
+ */
458
+ async finishPasskeyAuthentication(options) {
459
+ const res = await this.client.post("/passkeys/authenticate/finish", {
460
+ response: options.authenticationResponse
461
+ });
462
+ this.auth = res.data;
463
+ return this.auth;
464
+ }
465
+ /**
466
+ * Lists all passkeys for the authenticated user.
467
+ * @returns A promise that resolves to an array of passkeys.
468
+ */
469
+ async listPasskeys() {
470
+ const res = await this.client.get("/passkeys");
471
+ return res.data.passkeys || [];
472
+ }
473
+ /**
474
+ * Deletes a passkey.
475
+ * @param passkeyId - The ID of the passkey to delete.
476
+ * @returns A promise that resolves when the passkey is deleted.
477
+ */
478
+ async deletePasskey(passkeyId) {
479
+ await this.client.delete(`/passkeys/${passkeyId}`);
480
+ }
242
481
  };
243
482
 
244
483
  // src/feeef/repositories/deposits.ts
@@ -304,6 +543,17 @@ var DepositRepository = class extends ModelRepository {
304
543
  }
305
544
  };
306
545
 
546
+ // src/feeef/repositories/transfers.ts
547
+ var TransferRepository = class extends ModelRepository {
548
+ /**
549
+ * Constructs a new TransferRepository instance
550
+ * @param client - The AxiosInstance used for making HTTP requests
551
+ */
552
+ constructor(client) {
553
+ super("transfers", client);
554
+ }
555
+ };
556
+
307
557
  // src/feeef/repositories/categories.ts
308
558
  var CategoryRepository = class extends ModelRepository {
309
559
  /**
@@ -557,6 +807,26 @@ var CityRepository = class extends ModelRepository {
557
807
  }
558
808
  };
559
809
 
810
+ // src/feeef/repositories/currencies.ts
811
+ var CurrencyRepository = class extends ModelRepository {
812
+ /**
813
+ * Constructs a new CurrencyRepository instance.
814
+ * @param client The AxiosInstance used for making HTTP requests.
815
+ */
816
+ constructor(client) {
817
+ super("currencies", client);
818
+ }
819
+ /**
820
+ * Finds a currency by its code (ID is the currency code).
821
+ * @param code - The currency code (ISO 4217, e.g., USD, EUR).
822
+ * @param params - Optional query parameters.
823
+ * @returns A Promise that resolves to the found Currency entity.
824
+ */
825
+ async findByCode(code, params) {
826
+ return this.find({ id: code.toUpperCase(), params });
827
+ }
828
+ };
829
+
560
830
  // src/feeef/repositories/shipping_prices.ts
561
831
  var ShippingPriceRepository = class extends ModelRepository {
562
832
  /**
@@ -1555,6 +1825,10 @@ var FeeeF = class {
1555
1825
  * The repository for managing deposits.
1556
1826
  */
1557
1827
  deposits;
1828
+ /**
1829
+ * The repository for managing transfers.
1830
+ */
1831
+ transfers;
1558
1832
  /**
1559
1833
  * The repository for managing categories.
1560
1834
  */
@@ -1571,6 +1845,10 @@ var FeeeF = class {
1571
1845
  * The repository for managing cities.
1572
1846
  */
1573
1847
  cities;
1848
+ /**
1849
+ * The repository for managing currencies.
1850
+ */
1851
+ currencies;
1574
1852
  /**
1575
1853
  * The repository for managing shipping prices.
1576
1854
  */
@@ -1602,10 +1880,12 @@ var FeeeF = class {
1602
1880
  this.users = new UserRepository(this.client);
1603
1881
  this.orders = new OrderRepository(this.client);
1604
1882
  this.deposits = new DepositRepository(this.client);
1883
+ this.transfers = new TransferRepository(this.client);
1605
1884
  this.categories = new CategoryRepository(this.client);
1606
1885
  this.countries = new CountryRepository(this.client);
1607
1886
  this.states = new StateRepository(this.client);
1608
1887
  this.cities = new CityRepository(this.client);
1888
+ this.currencies = new CurrencyRepository(this.client);
1609
1889
  this.shippingPrices = new ShippingPriceRepository(this.client);
1610
1890
  this.cart = new CartService();
1611
1891
  this.actions = new ActionsService(this.client);
@@ -1989,6 +2269,8 @@ export {
1989
2269
  StoreSubscriptionStatus,
1990
2270
  StoreSubscriptionType,
1991
2271
  TiktokPixelEvent,
2272
+ TransferRepository,
2273
+ UserRepository,
1992
2274
  VariantOptionType,
1993
2275
  WebhookEvent,
1994
2276
  convertDartColorToCssNumber,