btrz-api-client 8.55.0 → 8.57.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.
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4
+
3
5
  var _require = require("./../endpoints_helpers.js"),
4
6
  authorizationHeaders = _require.authorizationHeaders;
5
7
 
@@ -9,6 +11,12 @@ var _require = require("./../endpoints_helpers.js"),
9
11
  * @property {string} [providerIds] - Comma-separated provider IDs to get document types for
10
12
  */
11
13
 
14
+ /**
15
+ * Query params for GET /document-types/:documenttypeId (btrz-api-inventory). See get-by-id-handler getSpec().
16
+ * @typedef {Object} DocumentTypeGetByIdQuery
17
+ * @property {string} [providerId] - When passed via opts.providerId it is merged here (same pattern as people-lookups / dynamic-forms)
18
+ */
19
+
12
20
  /**
13
21
  * Factory for document-types API (btrz-api-inventory).
14
22
  * @param {Object} deps
@@ -53,6 +61,8 @@ function documentTypesFactory(_ref) {
53
61
  * @param {string} [opts.token] - API key
54
62
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
55
63
  * @param {string} opts.id - Document type id (24 hex characters)
64
+ * @param {DocumentTypeGetByIdQuery} [opts.query] - Optional query params (merged with providerId when opts.providerId is set)
65
+ * @param {string} [opts.providerId] - Provider id (ObjectId); merged into query for provider context (same as peopleLookups.getById / dynamicForms.get)
56
66
  * @param {Object} [opts.headers] - Optional headers
57
67
  * @returns {Promise<import("axios").AxiosResponse<{ documenttype: Object }>>}
58
68
  * @throws When response is 4xx/5xx (400, 401, 404 DOCUMENTTYPE_NOT_FOUND, 500)
@@ -61,11 +71,16 @@ function documentTypesFactory(_ref) {
61
71
  var token = _ref3.token,
62
72
  jwtToken = _ref3.jwtToken,
63
73
  id = _ref3.id,
64
- headers = _ref3.headers;
74
+ _ref3$query = _ref3.query,
75
+ query = _ref3$query === undefined ? {} : _ref3$query,
76
+ headers = _ref3.headers,
77
+ providerId = _ref3.providerId;
65
78
 
79
+ var query_ = providerId ? _extends({}, query, { providerId: providerId }) : query;
66
80
  return client({
67
81
  url: "/document-types/" + id,
68
82
  method: "get",
83
+ params: query_,
69
84
  headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers })
70
85
  });
71
86
  }
@@ -134,7 +134,8 @@ function transactionsFactory(_ref) {
134
134
  * @param {Object} opts
135
135
  * @param {string} [opts.token] - API key
136
136
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
137
- * @param {string} opts.transactionId - Transaction id
137
+ * @param {string} [opts.transactionId] - Transaction id
138
+ * @param {boolean} [opts.allEligibleTransactions] - When true, omit transactionIds to let backend expire all eligible transactions
138
139
  * @param {boolean} [opts.avoidEmail] - Whether to avoid sending email
139
140
  * @param {Object} [opts.headers] - Optional headers
140
141
  * @returns {Promise<import("axios").AxiosResponse>}
@@ -142,21 +143,28 @@ function transactionsFactory(_ref) {
142
143
  function expireAll(_ref7) {
143
144
  var jwtToken = _ref7.jwtToken,
144
145
  transactionId = _ref7.transactionId,
146
+ allEligibleTransactions = _ref7.allEligibleTransactions,
145
147
  avoidEmail = _ref7.avoidEmail,
146
148
  token = _ref7.token,
147
149
  headers = _ref7.headers;
148
150
 
151
+ var operation = {
152
+ name: "expire_payment",
153
+ avoidEmail: avoidEmail,
154
+ transactionIds: [transactionId]
155
+ };
156
+
157
+ if (allEligibleTransactions) {
158
+ delete operation.transactionIds;
159
+ }
160
+
149
161
  return client({
150
162
  url: "/transactions/status",
151
163
  method: "patch",
152
164
  params: {},
153
165
  headers: authorizationHeaders({ internalAuthTokenProvider: internalAuthTokenProvider, jwtToken: jwtToken, token: token, headers: headers }),
154
166
  data: {
155
- operation: {
156
- name: "expire_payment",
157
- transactionIds: [transactionId],
158
- avoidEmail: avoidEmail
159
- }
167
+ operation: operation
160
168
  }
161
169
  });
162
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "8.55.0",
3
+ "version": "8.57.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,6 +6,12 @@ const {authorizationHeaders} = require("./../endpoints_helpers.js");
6
6
  * @property {string} [providerIds] - Comma-separated provider IDs to get document types for
7
7
  */
8
8
 
9
+ /**
10
+ * Query params for GET /document-types/:documenttypeId (btrz-api-inventory). See get-by-id-handler getSpec().
11
+ * @typedef {Object} DocumentTypeGetByIdQuery
12
+ * @property {string} [providerId] - When passed via opts.providerId it is merged here (same pattern as people-lookups / dynamic-forms)
13
+ */
14
+
9
15
  /**
10
16
  * Factory for document-types API (btrz-api-inventory).
11
17
  * @param {Object} deps
@@ -39,14 +45,18 @@ function documentTypesFactory({client, internalAuthTokenProvider}) {
39
45
  * @param {string} [opts.token] - API key
40
46
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
41
47
  * @param {string} opts.id - Document type id (24 hex characters)
48
+ * @param {DocumentTypeGetByIdQuery} [opts.query] - Optional query params (merged with providerId when opts.providerId is set)
49
+ * @param {string} [opts.providerId] - Provider id (ObjectId); merged into query for provider context (same as peopleLookups.getById / dynamicForms.get)
42
50
  * @param {Object} [opts.headers] - Optional headers
43
51
  * @returns {Promise<import("axios").AxiosResponse<{ documenttype: Object }>>}
44
52
  * @throws When response is 4xx/5xx (400, 401, 404 DOCUMENTTYPE_NOT_FOUND, 500)
45
53
  */
46
- function get({token, jwtToken, id, headers}) {
54
+ function get({token, jwtToken, id, query = {}, headers, providerId}) {
55
+ const query_ = providerId ? {...query, providerId} : query;
47
56
  return client({
48
57
  url: `/document-types/${id}`,
49
58
  method: "get",
59
+ params: query_,
50
60
  headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers})
51
61
  });
52
62
  }
@@ -99,23 +99,30 @@ function transactionsFactory({client, internalAuthTokenProvider}) {
99
99
  * @param {Object} opts
100
100
  * @param {string} [opts.token] - API key
101
101
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
102
- * @param {string} opts.transactionId - Transaction id
102
+ * @param {string} [opts.transactionId] - Transaction id
103
+ * @param {boolean} [opts.allEligibleTransactions] - When true, omit transactionIds to let backend expire all eligible transactions
103
104
  * @param {boolean} [opts.avoidEmail] - Whether to avoid sending email
104
105
  * @param {Object} [opts.headers] - Optional headers
105
106
  * @returns {Promise<import("axios").AxiosResponse>}
106
107
  */
107
- function expireAll({jwtToken, transactionId, avoidEmail, token, headers}) {
108
+ function expireAll({jwtToken, transactionId, allEligibleTransactions, avoidEmail, token, headers}) {
109
+ const operation = {
110
+ name: "expire_payment",
111
+ avoidEmail,
112
+ transactionIds: [transactionId]
113
+ };
114
+
115
+ if (allEligibleTransactions) {
116
+ delete operation.transactionIds;
117
+ }
118
+
108
119
  return client({
109
120
  url: "/transactions/status",
110
121
  method: "patch",
111
122
  params: {},
112
123
  headers: authorizationHeaders({internalAuthTokenProvider, jwtToken, token, headers}),
113
124
  data: {
114
- operation: {
115
- name: "expire_payment",
116
- transactionIds: [transactionId],
117
- avoidEmail
118
- }
125
+ operation
119
126
  }
120
127
  });
121
128
  }
@@ -37,4 +37,21 @@ describe("inventory/document-types", () => {
37
37
  axiosMock.onPut(`/document-types/${documentTypesId}`).reply(expectRequest({statusCode: 200, token, jwtToken}));
38
38
  return api.inventory.documentTypes.update({jwtToken, token, id: documentTypesId, data});
39
39
  });
40
+
41
+ it("should get a document-type by id without providerId query", () => {
42
+ const documentTypesId = "507f1f77bcf86cd799439011";
43
+ const params = {};
44
+ axiosMock.onGet(`/document-types/${documentTypesId}`, {params})
45
+ .reply(expectRequest({statusCode: 200, token, jwtToken, query: params}));
46
+ return api.inventory.documentTypes.get({token, jwtToken, id: documentTypesId});
47
+ });
48
+
49
+ it("should get a document-type by id with providerId in query params", () => {
50
+ const documentTypesId = "507f1f77bcf86cd799439011";
51
+ const providerId = "6750984c6d6aac054165fd9a";
52
+ const params = {providerId};
53
+ axiosMock.onGet(`/document-types/${documentTypesId}`, {params})
54
+ .reply(expectRequest({statusCode: 200, token, jwtToken, query: params}));
55
+ return api.inventory.documentTypes.get({token, jwtToken, id: documentTypesId, providerId});
56
+ });
40
57
  });
@@ -113,7 +113,13 @@ describe("operations/transactions", function () {
113
113
  statusCode: 200,
114
114
  internalAuthTokenProvider,
115
115
  withoutApiKey: true,
116
- jwtToken: "internal_auth_token"
116
+ jwtToken: "internal_auth_token",
117
+ body: {
118
+ operation: {
119
+ name: "expire_payment",
120
+ transactionIds: [transactionId]
121
+ }
122
+ }
117
123
  }));
118
124
  return api.operations.transactions.expireAll({
119
125
  transactionId,
@@ -121,6 +127,42 @@ describe("operations/transactions", function () {
121
127
  });
122
128
  });
123
129
 
130
+ it("should keep existing payload behavior when transactionId is not provided", () => {
131
+ axiosMock.onPatch("/transactions/status").reply(expectRequest({
132
+ statusCode: 200,
133
+ internalAuthTokenProvider,
134
+ withoutApiKey: true,
135
+ jwtToken: "internal_auth_token",
136
+ body: {
137
+ operation: {
138
+ name: "expire_payment",
139
+ transactionIds: [null]
140
+ }
141
+ }
142
+ }));
143
+ return api.operations.transactions.expireAll({
144
+ jwtToken: "internal_auth_token"
145
+ });
146
+ });
147
+
148
+ it("should expire all eligible transactions only when explicitly requested", () => {
149
+ axiosMock.onPatch("/transactions/status").reply(expectRequest({
150
+ statusCode: 200,
151
+ internalAuthTokenProvider,
152
+ withoutApiKey: true,
153
+ jwtToken: "internal_auth_token",
154
+ body: {
155
+ operation: {
156
+ name: "expire_payment"
157
+ }
158
+ }
159
+ }));
160
+ return api.operations.transactions.expireAll({
161
+ jwtToken: "internal_auth_token",
162
+ allEligibleTransactions: true
163
+ });
164
+ });
165
+
124
166
 
125
167
  it("should add transaction invoice informations", function () {
126
168
  const transactionId = "transactionId2";