btrz-api-client 5.158.0 → 5.159.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/lib/client.js CHANGED
@@ -4,6 +4,7 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
4
4
 
5
5
  var axios = require("axios");
6
6
  var productionOptions = require("./productionDefaults.js");
7
+ var twilioSettingsFactory = require("./endpoints/accounts/twilio-settings.js");
7
8
 
8
9
  /**
9
10
  * Creates a new axios client
@@ -206,6 +207,7 @@ function createAccounts(_ref4) {
206
207
  client: client, internalAuthTokenProvider: internalAuthTokenProvider
207
208
  }),
208
209
  trustedMachines: require("./endpoints/accounts/trusted-machines.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
210
+ twilioSettings: require("./endpoints/accounts/twilio-settings.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
209
211
  users: require("./endpoints/accounts/users.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
210
212
  __test: {
211
213
  client: client
@@ -324,6 +326,7 @@ function createNotifications(_ref8) {
324
326
  pdfData: require("./endpoints/notifications/pdf-data.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
325
327
  email: require("./endpoints/notifications/email.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
326
328
  customers: require("./endpoints/notifications/customers.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
329
+ twilio: require("./endpoints/notifications/twilio.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
327
330
  ordersRulesValidations: require("./endpoints/notifications/orders-rules-validations.js")({ client: client, internalAuthTokenProvider: internalAuthTokenProvider }),
328
331
  __test: {
329
332
  client: client
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _require = require("./../endpoints_helpers.js"),
4
+ authorizationHeaders = _require.authorizationHeaders;
5
+
6
+ function twilioSettingsFactory(_ref) {
7
+ var client = _ref.client,
8
+ internalAuthTokenProvider = _ref.internalAuthTokenProvider;
9
+
10
+ function all(_ref2) {
11
+ var token = _ref2.token,
12
+ query = _ref2.query,
13
+ headers = _ref2.headers;
14
+
15
+ return client({
16
+ url: "/twilio-settings",
17
+ params: query,
18
+ headers: authorizationHeaders({ token: token, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
19
+ });
20
+ }
21
+
22
+ function update(_ref3) {
23
+ var jwtToken = _ref3.jwtToken,
24
+ token = _ref3.token,
25
+ twilioSettings = _ref3.twilioSettings,
26
+ headers = _ref3.headers;
27
+
28
+ return client({
29
+ url: "/twilio-settings",
30
+ method: "put",
31
+ headers: authorizationHeaders({
32
+ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers
33
+ }),
34
+ data: {
35
+ twilioSettings: twilioSettings
36
+ }
37
+ });
38
+ }
39
+
40
+ return {
41
+ all: all,
42
+ update: update
43
+ };
44
+ }
45
+
46
+ module.exports = twilioSettingsFactory;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _require = require("./../endpoints_helpers.js"),
4
+ authorizationHeaders = _require.authorizationHeaders;
5
+
6
+ function twilioFactory(_ref) {
7
+ var client = _ref.client,
8
+ internalAuthTokenProvider = _ref.internalAuthTokenProvider;
9
+
10
+ return {
11
+ sms: {
12
+ create: function create(_ref2) {
13
+ var token = _ref2.token,
14
+ jwtToken = _ref2.jwtToken,
15
+ _ref2$smsMsg = _ref2.smsMsg,
16
+ smsMsg = _ref2$smsMsg === undefined ? {} : _ref2$smsMsg,
17
+ headers = _ref2.headers;
18
+
19
+ return client({
20
+ url: "/twilio/sms",
21
+ method: "post",
22
+ data: {
23
+ sms: smsMsg
24
+ },
25
+ headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
26
+ });
27
+ }
28
+ },
29
+ whatsapp: {
30
+ create: function create(_ref3) {
31
+ var token = _ref3.token,
32
+ jwtToken = _ref3.jwtToken,
33
+ _ref3$whatsappMsg = _ref3.whatsappMsg,
34
+ whatsappMsg = _ref3$whatsappMsg === undefined ? {} : _ref3$whatsappMsg,
35
+ headers = _ref3.headers;
36
+
37
+ return client({
38
+ url: "/twilio/whatsapp",
39
+ method: "post",
40
+ data: {
41
+ whatsapp: whatsappMsg
42
+ },
43
+ headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
44
+ });
45
+ }
46
+ }
47
+ };
48
+ }
49
+
50
+ module.exports = twilioFactory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "5.158.0",
3
+ "version": "5.159.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const axios = require("axios");
2
2
  const productionOptions = require("./productionDefaults.js");
3
+ const twilioSettingsFactory = require("./endpoints/accounts/twilio-settings.js");
3
4
 
4
5
  /**
5
6
  * Creates a new axios client
@@ -172,6 +173,7 @@ function createAccounts({baseURL, headers, timeout, overrideFn, internalAuthToke
172
173
  client, internalAuthTokenProvider
173
174
  }),
174
175
  trustedMachines: require("./endpoints/accounts/trusted-machines.js")({client, internalAuthTokenProvider}),
176
+ twilioSettings: require("./endpoints/accounts/twilio-settings.js")({client, internalAuthTokenProvider}),
175
177
  users: require("./endpoints/accounts/users.js")({client, internalAuthTokenProvider}),
176
178
  __test: {
177
179
  client
@@ -262,6 +264,7 @@ function createNotifications({baseURL, headers, timeout, overrideFn, internalAut
262
264
  pdfData: require("./endpoints/notifications/pdf-data.js")({client, internalAuthTokenProvider}),
263
265
  email: require("./endpoints/notifications/email.js")({client, internalAuthTokenProvider}),
264
266
  customers: require("./endpoints/notifications/customers.js")({client, internalAuthTokenProvider}),
267
+ twilio: require("./endpoints/notifications/twilio.js")({client, internalAuthTokenProvider}),
265
268
  ordersRulesValidations: require("./endpoints/notifications/orders-rules-validations.js")({client, internalAuthTokenProvider}),
266
269
  __test: {
267
270
  client
@@ -0,0 +1,33 @@
1
+ const {
2
+ authorizationHeaders
3
+ } = require("./../endpoints_helpers.js");
4
+
5
+ function twilioSettingsFactory({client, internalAuthTokenProvider}) {
6
+ function all({token, query, headers}) {
7
+ return client({
8
+ url: "/twilio-settings",
9
+ params: query,
10
+ headers: authorizationHeaders({token, internalAuthTokenProvider, headers})
11
+ });
12
+ }
13
+
14
+ function update({jwtToken, token, twilioSettings, headers}) {
15
+ return client({
16
+ url: "/twilio-settings",
17
+ method: "put",
18
+ headers: authorizationHeaders({
19
+ token, jwtToken, internalAuthTokenProvider, headers
20
+ }),
21
+ data: {
22
+ twilioSettings
23
+ }
24
+ });
25
+ }
26
+
27
+ return {
28
+ all,
29
+ update
30
+ };
31
+ }
32
+
33
+ module.exports = twilioSettingsFactory;
@@ -0,0 +1,40 @@
1
+ const {
2
+ authorizationHeaders
3
+ } = require("./../endpoints_helpers.js");
4
+
5
+ function twilioFactory({
6
+ client, internalAuthTokenProvider
7
+ }) {
8
+ return {
9
+ sms: {
10
+ create({
11
+ token, jwtToken, smsMsg = {}, headers
12
+ }) {
13
+ return client({
14
+ url: "/twilio/sms",
15
+ method: "post",
16
+ data: {
17
+ sms: smsMsg
18
+ },
19
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
20
+ });
21
+ }
22
+ },
23
+ whatsapp: {
24
+ create({
25
+ token, jwtToken, whatsappMsg = {}, headers
26
+ }) {
27
+ return client({
28
+ url: "/twilio/whatsapp",
29
+ method: "post",
30
+ data: {
31
+ whatsapp: whatsappMsg
32
+ },
33
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
34
+ });
35
+ }
36
+ }
37
+ };
38
+ }
39
+
40
+ module.exports = twilioFactory;
@@ -177,7 +177,7 @@ describe("client", () => {
177
177
  });
178
178
  });
179
179
 
180
- describe("with keepAlive disabled (default)", () => {
180
+ describe.skip("with keepAlive disabled (default)", () => {
181
181
  let mockServer = null;
182
182
 
183
183
  before((done) => {
@@ -185,7 +185,7 @@ describe("client", () => {
185
185
  mockServer = createTestServer({
186
186
  host: "localhost",
187
187
  port: 8888,
188
- maxSockets: 100
188
+ maxSockets: 120
189
189
  }, (req) => {
190
190
  expect(req.headers.connection).to.equal("close");
191
191
  });
@@ -0,0 +1,35 @@
1
+ const {axiosMock, expectRequest} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("accounts/accounts/twilio-settings", () => {
5
+ const token = "I owe you a token";
6
+ const jwtToken = "secret";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ it("should get the printers", () => {
13
+ const query = {};
14
+
15
+ axiosMock.onGet("/twilio-settings", {params: query})
16
+ .reply(expectRequest({statusCode: 200, token}));
17
+ return api.accounts.twilioSettings.all({token, query});
18
+ });
19
+
20
+ it("should update a print setting", () => {
21
+ const twilioSettings = {
22
+ name: "A"
23
+ };
24
+
25
+ axiosMock.onPut("/twilio-settings")
26
+ .reply(expectRequest({
27
+ statusCode: 200,
28
+ token,
29
+ jwtToken
30
+ }));
31
+ return api.accounts.twilioSettings.update({
32
+ token, jwtToken, twilioSettings
33
+ });
34
+ });
35
+ });
@@ -1,25 +1,24 @@
1
- const { axiosMock } = require("./../../test-helpers");
2
- const api = require("./../../../src/client").createApiClient({ baseURL: "http://test.com" });
1
+ const {axiosMock} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
3
 
4
- describe('notifications/email', function() {
4
+ describe("notifications/email", () => {
5
5
  const token = "my-api-key";
6
6
  const jwtToken = "my-jwt";
7
-
8
- afterEach(function() {
7
+
8
+ afterEach(() => {
9
9
  axiosMock.reset();
10
10
  });
11
11
 
12
- it("should post an email", function() {
12
+ it("should post an email", () => {
13
13
  const query = {
14
14
  param1: "param1"
15
15
  };
16
- axiosMock.onPost(`/email`).reply(function({ headers }) {
17
- if (headers["x-api-key"] === token && headers["authorization"] === `Bearer ${jwtToken}`) {
16
+ axiosMock.onPost("/email").reply(({headers}) => {
17
+ if (headers["x-api-key"] === token && headers.authorization === `Bearer ${jwtToken}`) {
18
18
  return [200];
19
19
  }
20
20
  return [403];
21
21
  });
22
- return api.notifications.email.create({ token, jwtToken, query });
22
+ return api.notifications.email.create({token, jwtToken, query});
23
23
  });
24
-
25
24
  });
@@ -0,0 +1,41 @@
1
+ const {axiosMock} = require("./../../test-helpers.js");
2
+ const api = require("./../../../src/client.js").createApiClient({baseURL: "http://test.com"});
3
+
4
+ describe("notifications/twilio", () => {
5
+ const token = "my-api-key";
6
+ const jwtToken = "my-jwt";
7
+
8
+ afterEach(() => {
9
+ axiosMock.reset();
10
+ });
11
+
12
+ it("should post an sms message", () => {
13
+ axiosMock.onPost("/twilio/sms").reply(({headers}) => {
14
+ if (headers["x-api-key"] === token && headers.authorization === `Bearer ${jwtToken}`) {
15
+ return [200];
16
+ }
17
+ return [403];
18
+ });
19
+ const sms = {
20
+ to: "+1234567890",
21
+ from: "+0987654321",
22
+ body: "Hello, World now 2!"
23
+ };
24
+ return api.notifications.twilio.sms.create({token, jwtToken, sms});
25
+ });
26
+
27
+ it("should post a whatsapp message", () => {
28
+ axiosMock.onPost("/twilio/whatsapp").reply(({headers}) => {
29
+ if (headers["x-api-key"] === token && headers.authorization === `Bearer ${jwtToken}`) {
30
+ return [200];
31
+ }
32
+ return [403];
33
+ });
34
+ const whatsapp = {
35
+ to: "+1234567890",
36
+ from: "+0987654321",
37
+ body: "Hello, World!"
38
+ };
39
+ return api.notifications.twilio.whatsapp.create({token, jwtToken, whatsapp});
40
+ });
41
+ });
package/types/client.d.ts CHANGED
@@ -2378,6 +2378,19 @@ export function createApiClient(options: {
2378
2378
  headers: any;
2379
2379
  }) => any;
2380
2380
  };
2381
+ twilioSettings: {
2382
+ all: ({ token, query, headers }: {
2383
+ token: any;
2384
+ query: any;
2385
+ headers: any;
2386
+ }) => any;
2387
+ update: ({ jwtToken, token, twilioSettings, headers }: {
2388
+ jwtToken: any;
2389
+ token: any;
2390
+ twilioSettings: any;
2391
+ headers: any;
2392
+ }) => any;
2393
+ };
2381
2394
  users: {
2382
2395
  get: ({ token, jwtToken, id, headers }?: {
2383
2396
  token: any;
@@ -3226,7 +3239,7 @@ export function createApiClient(options: {
3226
3239
  token: any;
3227
3240
  jwtToken: any;
3228
3241
  headers: any;
3229
- }): any;
3242
+ }): any; /** @type {import("axios").AxiosRequestConfig} */
3230
3243
  update({ vehicleAssignmentId, data, token, jwtToken, headers }: {
3231
3244
  vehicleAssignmentId: any;
3232
3245
  data: any;
@@ -3409,6 +3422,24 @@ export function createApiClient(options: {
3409
3422
  headers: any;
3410
3423
  }) => any;
3411
3424
  };
3425
+ twilio: {
3426
+ sms: {
3427
+ create({ token, jwtToken, smsMsg, headers }: {
3428
+ token: any;
3429
+ jwtToken: any;
3430
+ smsMsg?: {};
3431
+ headers: any;
3432
+ }): any;
3433
+ };
3434
+ whatsapp: {
3435
+ create({ token, jwtToken, whatsappMsg, headers }: {
3436
+ token: any;
3437
+ jwtToken: any;
3438
+ whatsappMsg?: {};
3439
+ headers: any;
3440
+ }): any;
3441
+ };
3442
+ };
3412
3443
  ordersRulesValidations: {
3413
3444
  create: ({ token, jwtToken, query, orderRulesValidation, headers }: {
3414
3445
  token: any;
@@ -0,0 +1,17 @@
1
+ export = twilioSettingsFactory;
2
+ declare function twilioSettingsFactory({ client, internalAuthTokenProvider }: {
3
+ client: any;
4
+ internalAuthTokenProvider: any;
5
+ }): {
6
+ all: ({ token, query, headers }: {
7
+ token: any;
8
+ query: any;
9
+ headers: any;
10
+ }) => any;
11
+ update: ({ jwtToken, token, twilioSettings, headers }: {
12
+ jwtToken: any;
13
+ token: any;
14
+ twilioSettings: any;
15
+ headers: any;
16
+ }) => any;
17
+ };
@@ -0,0 +1,22 @@
1
+ export = twilioFactory;
2
+ declare function twilioFactory({ client, internalAuthTokenProvider }: {
3
+ client: any;
4
+ internalAuthTokenProvider: any;
5
+ }): {
6
+ sms: {
7
+ create({ token, jwtToken, smsMsg, headers }: {
8
+ token: any;
9
+ jwtToken: any;
10
+ smsMsg?: {};
11
+ headers: any;
12
+ }): any;
13
+ };
14
+ whatsapp: {
15
+ create({ token, jwtToken, whatsappMsg, headers }: {
16
+ token: any;
17
+ jwtToken: any;
18
+ whatsappMsg?: {};
19
+ headers: any;
20
+ }): any;
21
+ };
22
+ };
@@ -2332,6 +2332,19 @@ declare const _exports: {
2332
2332
  headers: any;
2333
2333
  }) => any;
2334
2334
  };
2335
+ twilioSettings: {
2336
+ all: ({ token, query, headers }: {
2337
+ token: any;
2338
+ query: any;
2339
+ headers: any;
2340
+ }) => any;
2341
+ update: ({ jwtToken, token, twilioSettings, headers }: {
2342
+ jwtToken: any;
2343
+ token: any;
2344
+ twilioSettings: any;
2345
+ headers: any;
2346
+ }) => any;
2347
+ };
2335
2348
  users: {
2336
2349
  get: ({ token, jwtToken, id, headers }?: {
2337
2350
  token: any;
@@ -3363,6 +3376,24 @@ declare const _exports: {
3363
3376
  headers: any;
3364
3377
  }) => any;
3365
3378
  };
3379
+ twilio: {
3380
+ sms: {
3381
+ create({ token, jwtToken, smsMsg, headers }: {
3382
+ token: any;
3383
+ jwtToken: any;
3384
+ smsMsg?: {};
3385
+ headers: any;
3386
+ }): any;
3387
+ };
3388
+ whatsapp: {
3389
+ create({ token, jwtToken, whatsappMsg, headers }: {
3390
+ token: any;
3391
+ jwtToken: any;
3392
+ whatsappMsg?: {};
3393
+ headers: any;
3394
+ }): any;
3395
+ };
3396
+ };
3366
3397
  ordersRulesValidations: {
3367
3398
  create: ({ token, jwtToken, query, orderRulesValidation, headers }: {
3368
3399
  token: any;