@code.store/arcxp-sdk-ts 5.1.3 → 5.1.7

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.
@@ -7,6 +7,7 @@ export type ArcAbstractAPIOptions = {
7
7
  };
8
8
  apiPath: string;
9
9
  maxRPS?: number;
10
+ maxRetries?: number;
10
11
  };
11
12
  export type ArcAPIOptions = Omit<ArcAbstractAPIOptions, 'apiPath'>;
12
13
  export declare abstract class ArcAbstractAPI {
@@ -1,10 +1,12 @@
1
1
  import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api.js';
2
- import type { CreateEnterpriseGroupPayload, CreateEnterpriseGroupResponse, MigrateBatchSubscriptionsParams, MigrateBatchSubscriptionsPayload, MigrateBatchSubscriptionsResponse } from './types.js';
2
+ import type { CreateEnterpriseGroupParams, CreateEnterpriseGroupPayload, CreateEnterpriseGroupResponse, CreateNonceResponse, MigrateBatchSubscriptionsParams, MigrateBatchSubscriptionsPayload, MigrateBatchSubscriptionsResponse } from './types.js';
3
3
  export declare class ArcSales extends ArcAbstractAPI {
4
4
  constructor(options: ArcAPIOptions);
5
5
  migrate(params: MigrateBatchSubscriptionsParams, payload: MigrateBatchSubscriptionsPayload): Promise<MigrateBatchSubscriptionsResponse>;
6
6
  }
7
7
  export declare class ArcSalesV2 extends ArcAbstractAPI {
8
8
  constructor(options: ArcAPIOptions);
9
- createEnterpriseGroup(payload: CreateEnterpriseGroupPayload): Promise<CreateEnterpriseGroupResponse>;
9
+ getEnterpriseGroups(params: CreateEnterpriseGroupParams): Promise<CreateEnterpriseGroupResponse>;
10
+ createEnterpriseGroup(params: CreateEnterpriseGroupParams, payload: CreateEnterpriseGroupPayload): Promise<CreateEnterpriseGroupResponse>;
11
+ createNonce(website: string, enterpriseGroupId: number): Promise<CreateNonceResponse>;
10
12
  }
@@ -1,5 +1,5 @@
1
- import type { UserAttribute } from '../identity/types';
2
1
  import type { Website } from '../../types/ans-types';
2
+ import type { UserAttribute } from '../identity/types';
3
3
  export type MigrateBatchSubscriptionsPayload = {
4
4
  subscriptions: (PaidSubscription | FreeSubscription | SharedSubscription | LinkedSubscription)[];
5
5
  payments: PaymentInfo[];
@@ -83,6 +83,9 @@ export type Refund = {
83
83
  tax: number;
84
84
  providerReference?: string;
85
85
  };
86
+ export type CreateEnterpriseGroupParams = {
87
+ site: string;
88
+ };
86
89
  export type CreateEnterpriseGroupPayload = {
87
90
  name: string;
88
91
  sku: string;
@@ -93,4 +96,8 @@ export type CreateEnterpriseGroupResponse = {
93
96
  nonceExpirationInDays: number;
94
97
  id: number;
95
98
  };
99
+ export type CreateNonceResponse = {
100
+ nonce: string;
101
+ expires: string;
102
+ };
96
103
  export {};
package/dist/index.cjs CHANGED
@@ -5,8 +5,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var axios = require('axios');
6
6
  var rateLimit = require('axios-rate-limit');
7
7
  var axiosRetry = require('axios-retry');
8
- var ws = require('ws');
8
+ var fs = require('node:fs');
9
+ var path = require('node:path');
9
10
  var FormData = require('form-data');
11
+ var ws = require('ws');
10
12
  var encode = require('base32-encode');
11
13
  var uuid = require('uuid');
12
14
  var assert = require('node:assert');
@@ -91,7 +93,7 @@ class ArcAbstractAPI {
91
93
  // apply retry
92
94
  const retry = typeof axiosRetry === 'function' ? axiosRetry : axiosRetry.default;
93
95
  retry(this.client, {
94
- retries: 5,
96
+ retries: options.maxRetries || 10,
95
97
  retryDelay: axiosRetry.exponentialDelay,
96
98
  retryCondition: (err) => this.retryCondition(err),
97
99
  });
@@ -296,12 +298,10 @@ class ArcIdentity extends ArcAbstractAPI {
296
298
  }
297
299
  }
298
300
 
299
- const importNodeModule = async (moduleId) => await import(moduleId);
300
301
  const modules = {
301
- // make it like that so static analyzer of webpack won't bundle it
302
- fs: () => importNodeModule('node:fs'),
303
- path: () => importNodeModule('node:path'),
304
- form_data: () => importNodeModule('form-data'),
302
+ fs: () => Promise.resolve(fs),
303
+ path: () => Promise.resolve(path),
304
+ form_data: () => Promise.resolve(FormData),
305
305
  };
306
306
 
307
307
  var platform = {
@@ -711,6 +711,7 @@ class ArcSales extends ArcAbstractAPI {
711
711
  super({ ...options, apiPath: 'sales/api/v1' });
712
712
  }
713
713
  async migrate(params, payload) {
714
+ const FormData = await platform.form_data();
714
715
  const form = new FormData();
715
716
  form.append('file', JSON.stringify(payload), { filename: 'subs.json', contentType: 'application/json' });
716
717
  const { data } = await this.client.post('/migrate', form, {
@@ -726,8 +727,26 @@ class ArcSalesV2 extends ArcAbstractAPI {
726
727
  constructor(options) {
727
728
  super({ ...options, apiPath: 'sales/api/v2' });
728
729
  }
729
- async createEnterpriseGroup(payload) {
730
- const { data } = await this.client.post('/subscriptions/enterprise', payload);
730
+ async getEnterpriseGroups(params) {
731
+ const { data } = await this.client.get('/subscriptions/enterprise', {
732
+ params: {
733
+ 'arc-site': params.site,
734
+ },
735
+ });
736
+ return data;
737
+ }
738
+ async createEnterpriseGroup(params, payload) {
739
+ const { data } = await this.client.post('/subscriptions/enterprise', payload, {
740
+ params: {
741
+ 'arc-site': params.site,
742
+ },
743
+ });
744
+ return data;
745
+ }
746
+ async createNonce(website, enterpriseGroupId) {
747
+ const { data } = await this.client.get(`/subscriptions/enterprise/${enterpriseGroupId}`, {
748
+ params: { 'arc-site': website },
749
+ });
731
750
  return data;
732
751
  }
733
752
  }