@maxzima/wa-communicator 1.0.37 → 1.0.39

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.
@@ -3,7 +3,9 @@ declare const enum CommunicatorFAPIEndpointEnum {
3
3
  USER = "user",
4
4
  REGISTRATION = "clients/registration",
5
5
  STORAGE = "storage",
6
- RESTRICTED_COUNTRIES = "access-control/restricted-countries"
6
+ RESTRICTED_COUNTRIES = "access-control/restricted-countries",
7
+ ASSIGNED_PRODUCTS = "assigned-products",
8
+ PROFILE_ASSIGN = "users/profiles"
7
9
  }
8
10
  declare const enum CommunicatorAuthAPIEndpointEnum {
9
11
  SIGN_IN = "sign-in",
@@ -1,4 +1,4 @@
1
- import { TCreateSessionRequestData, TEmailUpdateRequestData, TGetCurrentUserProfileRequestData, TRegistrationRequestData, TResponse, TSetupChallengeRequestData, TSignInByMobileRequestData, TSignUpByMobileRequestData, TVerifyChallengeRequestData, TStorageRequestData, TGetRestrictedCountriesData, TSetupSSERequestData, TSignInByAppRequestData } from "@root/types";
1
+ import { TCreateSessionRequestData, TEmailUpdateRequestData, TGetCurrentUserProfileRequestData, TRegistrationRequestData, TResponse, TSetupChallengeRequestData, TSignInByMobileRequestData, TSignUpByMobileRequestData, TVerifyChallengeRequestData, TStorageRequestData, TGetRestrictedCountriesData, TSetupSSERequestData, TSignInByAppRequestData, TGetAssignedProductsRequestData, TProfileAssignRequestData } from "@root/types";
2
2
  export declare class Communicator {
3
3
  private props;
4
4
  private sseAuth;
@@ -16,6 +16,8 @@ export declare class Communicator {
16
16
  registration(data: TRegistrationRequestData): Promise<TResponse>;
17
17
  setStorageValues(data: TStorageRequestData): Promise<TResponse>;
18
18
  getRestrictedCountries(data?: TGetRestrictedCountriesData): Promise<TResponse>;
19
+ getAssignedProducts(data: TGetAssignedProductsRequestData): Promise<TResponse>;
20
+ profileAssign(data: TProfileAssignRequestData): Promise<TResponse>;
19
21
  private send;
20
22
  private getHeaders;
21
23
  private getMeta;
@@ -242,6 +242,26 @@ export class Communicator {
242
242
  return yield this.send(Object.assign({ method: 'GET', url: `${this.props.clientFAPIBaseUrl}${"access-control/restricted-countries"}`, headers }, ((data === null || data === void 0 ? void 0 : data.entityType) && { queryParams: { entity_type: data.entityType } })));
243
243
  });
244
244
  }
245
+ getAssignedProducts(data) {
246
+ return __awaiter(this, void 0, void 0, function* () {
247
+ const headers = this.getHeaders(data.accessToken);
248
+ return yield this.send({
249
+ method: 'GET',
250
+ url: `${this.props.clientFAPIBaseUrl}${"assigned-products"}`,
251
+ headers,
252
+ });
253
+ });
254
+ }
255
+ profileAssign(data) {
256
+ return __awaiter(this, void 0, void 0, function* () {
257
+ const headers = this.getHeaders(data.accessToken);
258
+ return yield this.send({
259
+ method: 'POST',
260
+ url: `${this.props.clientFAPIBaseUrl}${"users/profiles"}/${data.profileId}/assign`,
261
+ headers,
262
+ });
263
+ });
264
+ }
245
265
  send(requestInitProps) {
246
266
  return __awaiter(this, void 0, void 0, function* () {
247
267
  let url = requestInitProps.url;
@@ -170,4 +170,38 @@ declare type TStorageRequestData = {
170
170
  declare type TGetRestrictedCountriesData = {
171
171
  entityType?: import('@root/enums').CountryTypeEnum;
172
172
  };
173
- export { TRegistrationRequestBodySourceDeviceType, TChallenge, TAuditSource, TRequestProps, TRequestQueryParams, TResponse, TSignInStartRequestBody, TSignInAppRequestBody, TAccountMeta, TAccountBrowserData, TSignInByMobileRequestData, TSignInByAppRequestData, TSignInByMobileResponse, TSignInBySSEResponse, TSignUpStartRequestBody, TSignUpByMobileRequestData, TSetupChallengeRequestData, TSetupSSERequestData, TSSEResponseData, TSetupChallengeResponse, TVerifyChallengeRequestBody, TVerifyChallengeRequestData, TVerifyChallengeResponse, TEmailUpdateRequestData, TCreateSessionRequestData, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, TGetCurrentUserProfileRequestData, TRegistrationRequestData, TStorageRequestData, TGetRestrictedCountriesData, };
173
+ declare type TGetAssignedProductsRequestData = {
174
+ accessToken: string;
175
+ };
176
+ declare type TAssignedProduct = {
177
+ id: string;
178
+ client_id: string;
179
+ name: string;
180
+ pricing_plan_subscription_started_at: string;
181
+ product_type: string;
182
+ is_frozen: boolean;
183
+ code?: string;
184
+ description?: string;
185
+ icon?: string;
186
+ client_name?: string;
187
+ pricing_plan_id?: string;
188
+ currency_code?: string;
189
+ deleted_at?: string | null;
190
+ next_pricing_plan_type?: string;
191
+ pricing_plan_selected_at?: string;
192
+ pricing_plan_type?: string;
193
+ pricing_plan_type_id?: string;
194
+ product_additional_info?: any;
195
+ updated_at?: string;
196
+ };
197
+ declare type TGetAssignedProductsResponse = {
198
+ products: TAssignedProduct[];
199
+ };
200
+ declare type TProfileAssignRequestData = {
201
+ accessToken: string;
202
+ profileId: string;
203
+ };
204
+ declare type TProfileAssignResponse = {
205
+ profile_permission_ids: string[];
206
+ };
207
+ export { TRegistrationRequestBodySourceDeviceType, TChallenge, TAuditSource, TRequestProps, TRequestQueryParams, TResponse, TSignInStartRequestBody, TSignInAppRequestBody, TAccountMeta, TAccountBrowserData, TSignInByMobileRequestData, TSignInByAppRequestData, TSignInByMobileResponse, TSignInBySSEResponse, TSignUpStartRequestBody, TSignUpByMobileRequestData, TSetupChallengeRequestData, TSetupSSERequestData, TSSEResponseData, TSetupChallengeResponse, TVerifyChallengeRequestBody, TVerifyChallengeRequestData, TVerifyChallengeResponse, TEmailUpdateRequestData, TCreateSessionRequestData, TCreateSessionResponse, TGetCurrentUserProfileResponseUser, TGetCurrentUserProfileRequestData, TRegistrationRequestData, TStorageRequestData, TGetRestrictedCountriesData, TGetAssignedProductsRequestData, TAssignedProduct, TGetAssignedProductsResponse, TProfileAssignRequestData, TProfileAssignResponse, };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.37",
2
+ "version": "1.0.39",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -4,6 +4,8 @@ const enum CommunicatorFAPIEndpointEnum {
4
4
  REGISTRATION = 'clients/registration',
5
5
  STORAGE = 'storage',
6
6
  RESTRICTED_COUNTRIES = 'access-control/restricted-countries',
7
+ ASSIGNED_PRODUCTS = 'assigned-products',
8
+ PROFILE_ASSIGN = 'users/profiles',
7
9
  }
8
10
 
9
11
  const enum CommunicatorAuthAPIEndpointEnum {
@@ -22,6 +22,8 @@ import {
22
22
  TSignInByAppRequestData,
23
23
  TSignInBySSEResponse,
24
24
  TSSEResponseData,
25
+ TGetAssignedProductsRequestData,
26
+ TProfileAssignRequestData,
25
27
  } from "@root/types";
26
28
  import {CommunicatorDefaultRequestData} from "./../Constants/Communicator";
27
29
  import {jsonParse} from "./../Utils/jsonParseSafe";
@@ -47,7 +49,7 @@ export class Communicator {
47
49
  mobile: data.phoneNumber,
48
50
  } as TSignInStartRequestBody);
49
51
 
50
- const queryParams = {}
52
+ const queryParams = {};
51
53
  if (data.outOfBandAllowed) {
52
54
  // TODO: temporary
53
55
  queryParams['out_of_band_allowed'] = true;
@@ -115,7 +117,7 @@ export class Communicator {
115
117
  const params: TSignInBySSEResponse = {
116
118
  request_id: data.requestId,
117
119
  mobile: data.phoneNumber,
118
- }
120
+ };
119
121
  const url = `${this.props.clientAuthSSEBaseUrl}${CommunicatorAuthAPIEndpointEnum.SSE_AUTH}`;
120
122
  this.sseAuth = new EventSource(new URL(`${url}?${this.processingQueryParams(params)}`));
121
123
  if (this.sseAuth) {
@@ -258,6 +260,26 @@ export class Communicator {
258
260
  });
259
261
  }
260
262
 
263
+ public async getAssignedProducts(data: TGetAssignedProductsRequestData): Promise<TResponse> {
264
+ const headers = this.getHeaders(data.accessToken);
265
+
266
+ return await this.send({
267
+ method: 'GET',
268
+ url: `${this.props.clientFAPIBaseUrl}${CommunicatorFAPIEndpointEnum.ASSIGNED_PRODUCTS}`,
269
+ headers,
270
+ });
271
+ }
272
+
273
+ public async profileAssign(data: TProfileAssignRequestData): Promise<TResponse> {
274
+ const headers = this.getHeaders(data.accessToken);
275
+
276
+ return await this.send({
277
+ method: 'POST',
278
+ url: `${this.props.clientFAPIBaseUrl}${CommunicatorFAPIEndpointEnum.PROFILE_ASSIGN}/${data.profileId}/assign`,
279
+ headers,
280
+ });
281
+ }
282
+
261
283
  private async send(requestInitProps: TRequestProps): Promise<TResponse> {
262
284
  let url = requestInitProps.url;
263
285
 
@@ -230,6 +230,49 @@ type TGetRestrictedCountriesData = {
230
230
  }
231
231
  /* endregion getRestrictedCountries */
232
232
 
233
+ /* region getAssignedProducts */
234
+ type TGetAssignedProductsRequestData = {
235
+ accessToken: string;
236
+ }
237
+
238
+ type TAssignedProduct = {
239
+ id: string;
240
+ client_id: string;
241
+ name: string;
242
+ pricing_plan_subscription_started_at: string;
243
+ product_type: string;
244
+ is_frozen: boolean;
245
+ code?: string;
246
+ description?: string;
247
+ icon?: string;
248
+ client_name?: string;
249
+ pricing_plan_id?: string;
250
+ currency_code?: string;
251
+ deleted_at?: string | null;
252
+ next_pricing_plan_type?: string;
253
+ pricing_plan_selected_at?: string;
254
+ pricing_plan_type?: string;
255
+ pricing_plan_type_id?: string;
256
+ product_additional_info?: any;
257
+ updated_at?: string;
258
+ }
259
+
260
+ type TGetAssignedProductsResponse = {
261
+ products: TAssignedProduct[];
262
+ }
263
+ /* endregion getAssignedProducts */
264
+
265
+ /* region profileAssign */
266
+ type TProfileAssignRequestData = {
267
+ accessToken: string;
268
+ profileId: string;
269
+ }
270
+
271
+ type TProfileAssignResponse = {
272
+ profile_permission_ids: string[];
273
+ }
274
+ /* endregion profileAssign */
275
+
233
276
  export {
234
277
  TRegistrationRequestBodySourceDeviceType,
235
278
  TChallenge,
@@ -262,4 +305,9 @@ export {
262
305
  TRegistrationRequestData,
263
306
  TStorageRequestData,
264
307
  TGetRestrictedCountriesData,
308
+ TGetAssignedProductsRequestData,
309
+ TAssignedProduct,
310
+ TGetAssignedProductsResponse,
311
+ TProfileAssignRequestData,
312
+ TProfileAssignResponse,
265
313
  };
@@ -56,6 +56,18 @@ Object {
56
56
  }
57
57
  `;
58
58
 
59
+ exports[`Communicator requests getAssignedProducts 1`] = `
60
+ Object {
61
+ "headers": Object {
62
+ "Accept": "application/json, text/plain, */*",
63
+ "Authorization": "Bearer _accessToken_",
64
+ "Content-Type": "application/json",
65
+ },
66
+ "method": "GET",
67
+ "url": "https://google.com/assigned-products",
68
+ }
69
+ `;
70
+
59
71
  exports[`Communicator requests getCurrentUserProfile 1`] = `
60
72
  Object {
61
73
  "headers": Object {
@@ -82,6 +94,18 @@ Object {
82
94
  }
83
95
  `;
84
96
 
97
+ exports[`Communicator requests profileAssign 1`] = `
98
+ Object {
99
+ "headers": Object {
100
+ "Accept": "application/json, text/plain, */*",
101
+ "Authorization": "Bearer _accessToken_",
102
+ "Content-Type": "application/json",
103
+ },
104
+ "method": "POST",
105
+ "url": "https://google.com/users/profiles/test-profile-id-123/assign",
106
+ }
107
+ `;
108
+
85
109
  exports[`Communicator requests registration 1`] = `
86
110
  Object {
87
111
  "body": "{\\"name\\":\\"_companyName_\\",\\"country_code\\":\\"CAN\\",\\"source\\":{\\"hash\\":\\"_hash_\\",\\"device_type\\":\\"mobile\\",\\"ga_id\\":\\"_gaId_\\",\\"origin\\":\\"_origin_\\",\\"gc_id\\":\\"_gcId_\\",\\"utm_source\\":\\"_utmSource_\\",\\"utm_medium\\":\\"_utmMedium_\\",\\"utm_campaign\\":\\"_utmCampaign_\\",\\"utm_term\\":\\"_utmTerm_\\"}}",
@@ -16,6 +16,8 @@ import {
16
16
  verifyChallengeData,
17
17
  setStorageValuesData,
18
18
  getRestrictedCountriesData,
19
+ getAssignedProductsData,
20
+ profileAssignData,
19
21
  } from "./testunits/communicator/requests";
20
22
  import {communicatorTestData} from "./testunits/communicator/general";
21
23
 
@@ -114,4 +116,14 @@ describe('Communicator requests', () => {
114
116
  const getRestrictedCountriesRequestData = await communicator.getRestrictedCountries(getRestrictedCountriesData);
115
117
  expect(getRestrictedCountriesRequestData).toMatchSnapshot();
116
118
  });
119
+
120
+ test('getAssignedProducts', async () => {
121
+ const getAssignedProductsRequestData = await communicator.getAssignedProducts(getAssignedProductsData);
122
+ expect(getAssignedProductsRequestData).toMatchSnapshot();
123
+ });
124
+
125
+ test('profileAssign', async () => {
126
+ const profileAssignRequestData = await communicator.profileAssign(profileAssignData);
127
+ expect(profileAssignRequestData).toMatchSnapshot();
128
+ });
117
129
  });
@@ -10,6 +10,8 @@ import type {
10
10
  TSignUpByMobileRequestData,
11
11
  TStorageRequestData,
12
12
  TVerifyChallengeRequestData,
13
+ TGetAssignedProductsRequestData,
14
+ TProfileAssignRequestData,
13
15
  } from "../../../src/types";
14
16
  import {communicatorTestData} from "./general";
15
17
  import {CountryTypeEnum} from "../../../src/enums";
@@ -81,6 +83,15 @@ const getRestrictedCountriesData: TGetRestrictedCountriesData = {
81
83
  entityType: CountryTypeEnum.GLOBAL
82
84
  };
83
85
 
86
+ const getAssignedProductsData: TGetAssignedProductsRequestData = {
87
+ accessToken: communicatorTestData.accessToken,
88
+ };
89
+
90
+ const profileAssignData: TProfileAssignRequestData = {
91
+ accessToken: communicatorTestData.accessToken,
92
+ profileId: 'test-profile-id-123',
93
+ };
94
+
84
95
  export {
85
96
  signInData,
86
97
  signInByAppData,
@@ -93,4 +104,6 @@ export {
93
104
  registrationData,
94
105
  setStorageValuesData,
95
106
  getRestrictedCountriesData,
107
+ profileAssignData,
108
+ getAssignedProductsData
96
109
  };