feeef 0.8.2 → 0.8.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
@@ -318,6 +318,65 @@ var ProductRepository = class extends ModelRepository {
318
318
  }
319
319
  };
320
320
 
321
+ // src/feeef/repositories/store_invites_repository.ts
322
+ var StoreInvitesRepository = class {
323
+ constructor(client, resource) {
324
+ this.client = client;
325
+ this.resource = resource;
326
+ }
327
+ /**
328
+ * Lists invites for a store.
329
+ * @param storeId - The store ID.
330
+ * @param params - Optional filters (e.g. status).
331
+ * @returns A Promise that resolves to the list of invites.
332
+ */
333
+ async list(storeId, params) {
334
+ const res = await this.client.get(`/${this.resource}/${storeId}/invites`, { params });
335
+ return res.data;
336
+ }
337
+ /**
338
+ * Creates a store invite (sends email to invitee).
339
+ * @param storeId - The store ID.
340
+ * @param data - The invite data.
341
+ * @returns A Promise that resolves to the created invite.
342
+ */
343
+ async create(storeId, data) {
344
+ const res = await this.client.post(`/${this.resource}/${storeId}/invites`, data);
345
+ return res.data;
346
+ }
347
+ /**
348
+ * Gets invite details (public or full if authorized).
349
+ * @param storeId - The store ID.
350
+ * @param inviteId - The invite ID.
351
+ * @returns A Promise that resolves to the invite.
352
+ */
353
+ async get(storeId, inviteId) {
354
+ const res = await this.client.get(`/${this.resource}/${storeId}/invites/${inviteId}`);
355
+ return res.data;
356
+ }
357
+ /**
358
+ * Revokes a pending invite.
359
+ * @param storeId - The store ID.
360
+ * @param inviteId - The invite ID.
361
+ */
362
+ async revoke(storeId, inviteId) {
363
+ await this.client.delete(`/${this.resource}/${storeId}/invites/${inviteId}`);
364
+ }
365
+ /**
366
+ * Accepts an invite (authenticated user's email must match invite email).
367
+ * @param storeId - The store ID.
368
+ * @param inviteId - The invite ID.
369
+ * @param token - The invite token from the email link.
370
+ * @returns A Promise that resolves to the created store member.
371
+ */
372
+ async accept(storeId, inviteId, token) {
373
+ const res = await this.client.post(`/${this.resource}/${storeId}/invites/${inviteId}/accept`, {
374
+ token
375
+ });
376
+ return res.data;
377
+ }
378
+ };
379
+
321
380
  // src/feeef/repositories/stores.ts
322
381
  var StoreRepository = class extends ModelRepository {
323
382
  /**
@@ -410,67 +469,24 @@ var StoreRepository = class extends ModelRepository {
410
469
  await this.client.delete(`/${this.resource}/${storeId}/members/${memberId}`);
411
470
  }
412
471
  /**
413
- * Creates a store invite (sends email to invitee).
414
- * @param storeId - The store ID.
415
- * @param data - The invite data.
416
- * @returns A Promise that resolves to the created invite.
417
- */
418
- async createInvite(storeId, data) {
419
- const res = await this.client.post(`/${this.resource}/${storeId}/invites`, data);
420
- return res.data;
421
- }
422
- /**
423
- * Lists invites for a store.
424
- * @param storeId - The store ID.
425
- * @param params - Optional filters (e.g. status).
426
- * @returns A Promise that resolves to the list of invites.
427
- */
428
- async listInvites(storeId, params) {
429
- const res = await this.client.get(`/${this.resource}/${storeId}/invites`, { params });
430
- return res.data;
431
- }
432
- /**
433
- * Revokes a pending invite.
434
- * @param storeId - The store ID.
435
- * @param inviteId - The invite ID.
436
- */
437
- async revokeInvite(storeId, inviteId) {
438
- await this.client.delete(`/${this.resource}/${storeId}/invites/${inviteId}`);
439
- }
440
- /**
441
- * Gets invite details (public or full if authorized).
442
- * @param storeId - The store ID.
443
- * @param inviteId - The invite ID.
444
- * @returns A Promise that resolves to the invite.
445
- */
446
- async getInvite(storeId, inviteId) {
447
- const res = await this.client.get(`/${this.resource}/${storeId}/invites/${inviteId}`);
448
- return res.data;
449
- }
450
- /**
451
- * Accepts an invite (authenticated user's email must match invite email).
452
- * @param storeId - The store ID.
453
- * @param inviteId - The invite ID.
454
- * @param token - The invite token from the email link.
455
- * @returns A Promise that resolves to the created store member.
472
+ * Repository for store invites. Use e.g. `ff.stores.invites.list(storeId)`, `ff.stores.invites.create(storeId, data)`.
456
473
  */
457
- async acceptInvite(storeId, inviteId, token) {
458
- const res = await this.client.post(`/${this.resource}/${storeId}/invites/${inviteId}/accept`, {
459
- token
460
- });
461
- return res.data;
474
+ get invites() {
475
+ return new StoreInvitesRepository(this.client, this.resource);
462
476
  }
463
477
  /**
464
478
  * Upgrades or renews a store's subscription plan.
465
479
  * @param id - The store ID.
466
480
  * @param plan - The plan type to upgrade to.
467
481
  * @param months - The number of months (1-12).
468
- * @returns A Promise that resolves when the upgrade is complete.
482
+ * @param code - Optional promo code.
469
483
  */
470
- async upgrade(id, plan, months) {
484
+ async upgrade(id, plan, months, options) {
471
485
  await this.client.post(`/${this.resource}/${id}/subscription/upgrade`, {
472
486
  plan,
473
- months
487
+ months,
488
+ // eslint-disable-next-line eqeqeq
489
+ ...options?.code != null && options.code !== "" && { code: options.code }
474
490
  });
475
491
  }
476
492
  /**
@@ -791,6 +807,68 @@ var UserRepository = class extends ModelRepository {
791
807
  }
792
808
  };
793
809
 
810
+ // src/feeef/repositories/apps.ts
811
+ var AppRepository = class extends ModelRepository {
812
+ constructor(client) {
813
+ super("apps", client);
814
+ }
815
+ /**
816
+ * Lists apps with optional pagination and filterator.
817
+ * @param options - Page, limit, filterator, q, and extra params forwarded to the API.
818
+ */
819
+ async list(options) {
820
+ const params = { ...options?.params };
821
+ if (options) {
822
+ if (options.page !== void 0) params.page = options.page;
823
+ if (options.limit !== void 0) params.limit = options.limit;
824
+ if (options.q !== void 0) params.q = options.q;
825
+ if (options.filterator !== void 0) params.filterator = options.filterator;
826
+ if (options.userId !== void 0) params.userId = options.userId;
827
+ if (options.active !== void 0) params.active = options.active;
828
+ }
829
+ return super.list({ page: options?.page, limit: options?.limit, params });
830
+ }
831
+ /**
832
+ * Regenerates the client secret for the app. Returns the app with
833
+ * clientSecret set once; store it securely.
834
+ *
835
+ * @param id - The app id.
836
+ * @returns The app including clientSecret.
837
+ */
838
+ async regenerateSecret(id) {
839
+ const res = await this.client.post(`/${this.resource}/${id}/regenerate-secret`);
840
+ return res.data;
841
+ }
842
+ /**
843
+ * Builds the OAuth authorize URL to which the user should be redirected.
844
+ *
845
+ * @param params - Parameters for the authorize URL.
846
+ * @param params.baseUrl - API base URL (e.g. https://api.feeef.org/api/v1).
847
+ * @param params.clientId - The app client id.
848
+ * @param params.redirectUri - Redirect URI registered for the app.
849
+ * @param params.responseType - Must be 'code' for authorization code flow.
850
+ * @param params.scope - Optional list of scopes (space-separated in URL).
851
+ * @param params.state - Optional state for CSRF protection.
852
+ * @param params.codeChallenge - Optional PKCE code challenge.
853
+ * @param params.codeChallengeMethod - Optional 'S256' or 'plain'.
854
+ * @returns The full authorize URL.
855
+ */
856
+ static buildAuthorizeUrl(params) {
857
+ const base = params.baseUrl.endsWith("/") ? params.baseUrl : `${params.baseUrl}/`;
858
+ const url = new URL("oauth/authorize", base);
859
+ url.searchParams.set("client_id", params.clientId);
860
+ url.searchParams.set("redirect_uri", params.redirectUri);
861
+ url.searchParams.set("response_type", params.responseType);
862
+ if (params.scope?.length) url.searchParams.set("scope", params.scope.join(" "));
863
+ if (params.state) url.searchParams.set("state", params.state);
864
+ if (params.codeChallenge) url.searchParams.set("code_challenge", params.codeChallenge);
865
+ if (params.codeChallengeMethod) {
866
+ url.searchParams.set("code_challenge_method", params.codeChallengeMethod);
867
+ }
868
+ return url.toString();
869
+ }
870
+ };
871
+
794
872
  // src/feeef/repositories/deposits.ts
795
873
  var DepositRepository = class extends ModelRepository {
796
874
  /**
@@ -926,6 +1004,41 @@ var DepositRepository = class extends ModelRepository {
926
1004
  }
927
1005
  };
928
1006
 
1007
+ // src/feeef/repositories/promos.ts
1008
+ var PromoRepository = class {
1009
+ constructor(client) {
1010
+ this.client = client;
1011
+ }
1012
+ /**
1013
+ * Lists promos with optional pagination and validNow filter.
1014
+ */
1015
+ async list(params) {
1016
+ const query = {};
1017
+ if (params?.page != null) query.page = params.page;
1018
+ if (params?.limit != null) query.limit = params.limit;
1019
+ if (params?.validNow === true) query.validNow = "1";
1020
+ const res = await this.client.get("/promos", { params: query });
1021
+ return res.data;
1022
+ }
1023
+ /**
1024
+ * Validates a promo code. Returns validation result with discount info or reason.
1025
+ */
1026
+ async validate(params) {
1027
+ const res = await this.client.post("/promos/validate", {
1028
+ code: params.code,
1029
+ storeId: params.storeId
1030
+ });
1031
+ return res.data;
1032
+ }
1033
+ /**
1034
+ * Creates a promo (admin). Returns the created promo.
1035
+ */
1036
+ async create(data) {
1037
+ const res = await this.client.post("/promos", data);
1038
+ return res.data;
1039
+ }
1040
+ };
1041
+
929
1042
  // src/feeef/repositories/transfers.ts
930
1043
  var TransferRepository = class extends ModelRepository {
931
1044
  /**
@@ -3396,6 +3509,10 @@ var FeeeF = class {
3396
3509
  * The repository for managing users.
3397
3510
  */
3398
3511
  users;
3512
+ /**
3513
+ * The repository for managing developer-registered apps (OAuth clients).
3514
+ */
3515
+ apps;
3399
3516
  /**
3400
3517
  * The repository for managing orders.
3401
3518
  */
@@ -3408,6 +3525,10 @@ var FeeeF = class {
3408
3525
  * The repository for managing transfers.
3409
3526
  */
3410
3527
  transfers;
3528
+ /**
3529
+ * The repository for managing promo codes (list, validate, create).
3530
+ */
3531
+ promos;
3411
3532
  /**
3412
3533
  * The repository for managing categories.
3413
3534
  */
@@ -3482,9 +3603,11 @@ var FeeeF = class {
3482
3603
  this.imagePromptTemplates = new ImagePromptTemplatesRepository(this.client);
3483
3604
  this.imageGenerations = new ImageGenerationsRepository(this.client);
3484
3605
  this.users = new UserRepository(this.client);
3606
+ this.apps = new AppRepository(this.client);
3485
3607
  this.orders = new OrderRepository(this.client);
3486
3608
  this.deposits = new DepositRepository(this.client);
3487
3609
  this.transfers = new TransferRepository(this.client);
3610
+ this.promos = new PromoRepository(this.client);
3488
3611
  this.categories = new CategoryRepository(this.client);
3489
3612
  this.countries = new CountryRepository(this.client);
3490
3613
  this.states = new StateRepository(this.client);
@@ -3920,6 +4043,7 @@ function validatePhoneNumber(phone) {
3920
4043
  export {
3921
4044
  ATTACHMENT_TYPES,
3922
4045
  ActionsService,
4046
+ AppRepository,
3923
4047
  CartService,
3924
4048
  CategoryRepository,
3925
4049
  CityRepository,
@@ -3952,6 +4076,7 @@ export {
3952
4076
  ProductStatus,
3953
4077
  ProductType,
3954
4078
  ProductVariantView,
4079
+ PromoRepository,
3955
4080
  ShippingMethodPolicy,
3956
4081
  ShippingMethodRepository,
3957
4082
  ShippingMethodStatus,
@@ -3962,6 +4087,7 @@ export {
3962
4087
  StorageService,
3963
4088
  StoreActionType,
3964
4089
  StoreInviteStatus,
4090
+ StoreInvitesRepository,
3965
4091
  StoreMemberRole,
3966
4092
  StoreRepository,
3967
4093
  StoreSubscriptionStatus,