btrz-api-client 8.53.0 → 8.54.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.
@@ -3,12 +3,27 @@
3
3
  var _require = require("../endpoints_helpers.js"),
4
4
  authorizationHeaders = _require.authorizationHeaders;
5
5
 
6
+ /**
7
+ * Body for PUT /external-wallets/saldo-max/:walletId/movements (ExternalWalletMovementData).
8
+ * @typedef {Object} ExternalWalletMovementData
9
+ * @property {number} amount
10
+ * @property {'purchase'|'refund'} type - `purchase` withdraws balance; `refund` adds balance (ADO)
11
+ * @property {string|number} nip - Four-digit NIP; prefer string to preserve leading zeros (e.g. "0202")
12
+ * @property {string} transactionId - Betterez transaction id; sent to ADO as erpcoOperationId
13
+ * @property {boolean} [sendMail] - Optional; ADO receipt email on success
14
+ */
15
+
6
16
  /**
7
17
  * Factory for external-wallets API (btrz-api-inventory). SaldoMax external wallets only.
8
18
  * @param {Object} deps
9
19
  * @param {import("axios").AxiosInstance} deps.client
10
20
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
11
- * @returns {{ saldoMax: { all: function, get: function, create: function, update: function, movements: { create: function } } }}
21
+ * @returns {{
22
+ * saldoMax: {
23
+ * all: function, get: function, create: function, update: function,
24
+ * nip: object, authorization: { create: function }, movements: { create: function }
25
+ * }
26
+ * }}
12
27
  */
13
28
 
14
29
 
@@ -16,7 +31,12 @@ function externalWalletsFactory(_ref) {
16
31
  var client = _ref.client,
17
32
  internalAuthTokenProvider = _ref.internalAuthTokenProvider;
18
33
 
19
- /** @type {{ all: function, create: function, get: function, update: function, movements: object }} */
34
+ /**
35
+ * @type {{
36
+ * all: function, create: function, get: function, update: function,
37
+ * nip: object, authorization: { create: function }, movements: object
38
+ * }}
39
+ */
20
40
  var saldoMax = {
21
41
  /**
22
42
  * GET /external-wallets/saldo-max - list SaldoMax external wallets (paginated).
@@ -144,25 +164,60 @@ function externalWalletsFactory(_ref) {
144
164
  }
145
165
  },
146
166
  /** @type {{ create: function }} */
147
- movements: {
167
+ authorization: {
148
168
  /**
149
- * PUT /external-wallets/saldo-max/:walletId/movements - add movement to wallet.
169
+ * POST /external-wallets/saldo-max/:walletId/authorization Validate NIP with ADO Saldo Max (authorize wallet).
170
+ * Typical: `authorization.create({ walletId, nip, token, jwtToken, headers })` — body sent as `{ nip }`.
171
+ * Alternate body: pass `nipAuthorization` instead of `nip` (wrapper form per API).
150
172
  * @param {Object} opts
151
173
  * @param {string} [opts.token] - API key
152
174
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
153
- * @param {string} opts.walletId - Wallet id
154
- * @param {Object} opts.movement - Movement payload (amount, type: payment|refund|manual, reason, nip)
175
+ * @param {string} opts.walletId - Saldo Max wallet id (idWallet)
176
+ * @param {string|number} [opts.nip] - Four-digit NIP (use with `token`/`jwtToken` as above, or use nipAuthorization)
177
+ * @param {{ nip: string|number }} [opts.nipAuthorization] - Wrapped NIP payload instead of `nip`
155
178
  * @param {Object} [opts.headers] - Optional headers
156
- * @returns {Promise<import("axios").AxiosResponse<{ externalWallet: Object }>>}
157
- * @throws When response is 4xx/5xx (400, 401, 403 INVALID_NIP/WALLET_BLOCKED/WALLET_NOT_ACTIVE, 404, 500)
179
+ * @returns {Promise<import("axios").AxiosResponse<{ valid: boolean }>>}
180
+ * @throws When response is 4xx/5xx (400 WRONG_DATA, INVALID_WALLET_ID, VALIDATE_NIP_WALLET_MISMATCH;
181
+ * 401; 403 incorrect NIP; 404; 502; 503; 500)
158
182
  */
159
183
  create: function create(_ref7) {
160
184
  var token = _ref7.token,
161
185
  jwtToken = _ref7.jwtToken,
162
186
  walletId = _ref7.walletId,
163
- movement = _ref7.movement,
187
+ nip = _ref7.nip,
188
+ nipAuthorization = _ref7.nipAuthorization,
164
189
  headers = _ref7.headers;
165
190
 
191
+ var data = nipAuthorization != null ? { nipAuthorization: nipAuthorization } : { nip: nip };
192
+ return client({
193
+ url: "/external-wallets/saldo-max/" + walletId + "/authorization",
194
+ method: "post",
195
+ headers: authorizationHeaders({ token: token, jwtToken: jwtToken, internalAuthTokenProvider: internalAuthTokenProvider, headers: headers }),
196
+ data: data
197
+ });
198
+ }
199
+ },
200
+ /** @type {{ create: function }} */
201
+ movements: {
202
+ /**
203
+ * PUT /external-wallets/saldo-max/:walletId/movements — Validate NIP, balance, then apply movement in ADO.
204
+ * @param {Object} opts
205
+ * @param {string} [opts.token] - API key
206
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
207
+ * @param {string} opts.walletId - Saldo Max wallet id (idWallet)
208
+ * @param {ExternalWalletMovementData} opts.movement
209
+ * @param {Object} [opts.headers] - Optional headers
210
+ * @returns {Promise<import("axios").AxiosResponse<{ result: { operationId?: string, region?: string } }>>}
211
+ * @throws When response is 4xx/5xx (400 WRONG_DATA, INVALID_MOVEMENT_*, INSUFFICIENT_FUNDS,
212
+ * VALIDATE_NIP_WALLET_MISMATCH; 401; 403 INVALID_NIP, WALLET_NOT_ACTIVE; 404; 502; 503; 500)
213
+ */
214
+ create: function create(_ref8) {
215
+ var token = _ref8.token,
216
+ jwtToken = _ref8.jwtToken,
217
+ walletId = _ref8.walletId,
218
+ movement = _ref8.movement,
219
+ headers = _ref8.headers;
220
+
166
221
  return client({
167
222
  url: "/external-wallets/saldo-max/" + walletId + "/movements",
168
223
  method: "put",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "btrz-api-client",
3
- "version": "8.53.0",
3
+ "version": "8.54.0",
4
4
  "description": "Api client for Betterez endpoints",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,15 +2,35 @@ const {
2
2
  authorizationHeaders
3
3
  } = require("../endpoints_helpers.js");
4
4
 
5
+ /**
6
+ * Body for PUT /external-wallets/saldo-max/:walletId/movements (ExternalWalletMovementData).
7
+ * @typedef {Object} ExternalWalletMovementData
8
+ * @property {number} amount
9
+ * @property {'purchase'|'refund'} type - `purchase` withdraws balance; `refund` adds balance (ADO)
10
+ * @property {string|number} nip - Four-digit NIP; prefer string to preserve leading zeros (e.g. "0202")
11
+ * @property {string} transactionId - Betterez transaction id; sent to ADO as erpcoOperationId
12
+ * @property {boolean} [sendMail] - Optional; ADO receipt email on success
13
+ */
14
+
5
15
  /**
6
16
  * Factory for external-wallets API (btrz-api-inventory). SaldoMax external wallets only.
7
17
  * @param {Object} deps
8
18
  * @param {import("axios").AxiosInstance} deps.client
9
19
  * @param {{ getToken: function(): string }} [deps.internalAuthTokenProvider]
10
- * @returns {{ saldoMax: { all: function, get: function, create: function, update: function, movements: { create: function } } }}
20
+ * @returns {{
21
+ * saldoMax: {
22
+ * all: function, get: function, create: function, update: function,
23
+ * nip: object, authorization: { create: function }, movements: { create: function }
24
+ * }
25
+ * }}
11
26
  */
12
27
  function externalWalletsFactory({client, internalAuthTokenProvider}) {
13
- /** @type {{ all: function, create: function, get: function, update: function, movements: object }} */
28
+ /**
29
+ * @type {{
30
+ * all: function, create: function, get: function, update: function,
31
+ * nip: object, authorization: { create: function }, movements: object
32
+ * }}
33
+ */
14
34
  const saldoMax = {
15
35
  /**
16
36
  * GET /external-wallets/saldo-max - list SaldoMax external wallets (paginated).
@@ -111,17 +131,45 @@ function externalWalletsFactory({client, internalAuthTokenProvider}) {
111
131
  }
112
132
  },
113
133
  /** @type {{ create: function }} */
134
+ authorization: {
135
+ /**
136
+ * POST /external-wallets/saldo-max/:walletId/authorization — Validate NIP with ADO Saldo Max (authorize wallet).
137
+ * Typical: `authorization.create({ walletId, nip, token, jwtToken, headers })` — body sent as `{ nip }`.
138
+ * Alternate body: pass `nipAuthorization` instead of `nip` (wrapper form per API).
139
+ * @param {Object} opts
140
+ * @param {string} [opts.token] - API key
141
+ * @param {string} [opts.jwtToken] - JWT or internal auth symbol
142
+ * @param {string} opts.walletId - Saldo Max wallet id (idWallet)
143
+ * @param {string|number} [opts.nip] - Four-digit NIP (use with `token`/`jwtToken` as above, or use nipAuthorization)
144
+ * @param {{ nip: string|number }} [opts.nipAuthorization] - Wrapped NIP payload instead of `nip`
145
+ * @param {Object} [opts.headers] - Optional headers
146
+ * @returns {Promise<import("axios").AxiosResponse<{ valid: boolean }>>}
147
+ * @throws When response is 4xx/5xx (400 WRONG_DATA, INVALID_WALLET_ID, VALIDATE_NIP_WALLET_MISMATCH;
148
+ * 401; 403 incorrect NIP; 404; 502; 503; 500)
149
+ */
150
+ create: ({token, jwtToken, walletId, nip, nipAuthorization, headers}) => {
151
+ const data = nipAuthorization != null ? {nipAuthorization} : {nip};
152
+ return client({
153
+ url: `/external-wallets/saldo-max/${walletId}/authorization`,
154
+ method: "post",
155
+ headers: authorizationHeaders({token, jwtToken, internalAuthTokenProvider, headers}),
156
+ data
157
+ });
158
+ }
159
+ },
160
+ /** @type {{ create: function }} */
114
161
  movements: {
115
162
  /**
116
- * PUT /external-wallets/saldo-max/:walletId/movements - add movement to wallet.
163
+ * PUT /external-wallets/saldo-max/:walletId/movements Validate NIP, balance, then apply movement in ADO.
117
164
  * @param {Object} opts
118
165
  * @param {string} [opts.token] - API key
119
166
  * @param {string} [opts.jwtToken] - JWT or internal auth symbol
120
- * @param {string} opts.walletId - Wallet id
121
- * @param {Object} opts.movement - Movement payload (amount, type: payment|refund|manual, reason, nip)
167
+ * @param {string} opts.walletId - Saldo Max wallet id (idWallet)
168
+ * @param {ExternalWalletMovementData} opts.movement
122
169
  * @param {Object} [opts.headers] - Optional headers
123
- * @returns {Promise<import("axios").AxiosResponse<{ externalWallet: Object }>>}
124
- * @throws When response is 4xx/5xx (400, 401, 403 INVALID_NIP/WALLET_BLOCKED/WALLET_NOT_ACTIVE, 404, 500)
170
+ * @returns {Promise<import("axios").AxiosResponse<{ result: { operationId?: string, region?: string } }>>}
171
+ * @throws When response is 4xx/5xx (400 WRONG_DATA, INVALID_MOVEMENT_*, INSUFFICIENT_FUNDS,
172
+ * VALIDATE_NIP_WALLET_MISMATCH; 401; 403 INVALID_NIP, WALLET_NOT_ACTIVE; 404; 502; 503; 500)
125
173
  */
126
174
  create: ({token, jwtToken, walletId, movement, headers}) => {
127
175
  return client({
@@ -98,9 +98,9 @@ describe("inventory/external-wallets", () => {
98
98
  const walletId = "wallet-id-123";
99
99
  const movement = {
100
100
  amount: 100,
101
- type: "credit",
102
- reason: "refund",
103
- nip: "1234"
101
+ type: "refund",
102
+ nip: "1234",
103
+ transactionId: "txn-refund-001"
104
104
  };
105
105
 
106
106
  axiosMock.onPut(`/external-wallets/saldo-max/${walletId}/movements`).reply(expectRequest({
@@ -115,13 +115,45 @@ describe("inventory/external-wallets", () => {
115
115
  });
116
116
  });
117
117
 
118
- it("should create a debit movement for a Saldo Max wallet", async () => {
118
+ it("should authorize NIP for a Saldo Max wallet (root nip body)", async () => {
119
+ const walletId = "749";
120
+ const nip = "1357";
121
+
122
+ axiosMock.onPost(`/external-wallets/saldo-max/${walletId}/authorization`).reply(expectRequest({
123
+ statusCode: 200, token, jwtToken, body: {nip}
124
+ }));
125
+
126
+ return api.inventory.externalWallets.saldoMax.authorization.create({
127
+ walletId,
128
+ nip,
129
+ token,
130
+ jwtToken
131
+ });
132
+ });
133
+
134
+ it("should authorize NIP for a Saldo Max wallet (nipAuthorization wrapper)", async () => {
135
+ const walletId = "749";
136
+ const nipAuthorization = {nip: "2468"};
137
+
138
+ axiosMock.onPost(`/external-wallets/saldo-max/${walletId}/authorization`).reply(expectRequest({
139
+ statusCode: 200, token, jwtToken, body: {nipAuthorization}
140
+ }));
141
+
142
+ return api.inventory.externalWallets.saldoMax.authorization.create({
143
+ jwtToken,
144
+ token,
145
+ walletId,
146
+ nipAuthorization
147
+ });
148
+ });
149
+
150
+ it("should create a purchase (withdraw) movement for a Saldo Max wallet", async () => {
119
151
  const walletId = "wallet-id-456";
120
152
  const movement = {
121
153
  amount: 50.75,
122
- type: "debit",
123
- reason: "purchase",
124
- nip: "9876"
154
+ type: "purchase",
155
+ nip: "9876",
156
+ transactionId: "txn-purchase-002"
125
157
  };
126
158
 
127
159
  axiosMock.onPut(`/external-wallets/saldo-max/${walletId}/movements`).reply(expectRequest({
@@ -140,9 +172,9 @@ describe("inventory/external-wallets", () => {
140
172
  const walletId = "wallet-id-789";
141
173
  const movement = {
142
174
  amount: 0,
143
- type: "adjustment",
144
- reason: "correction",
145
- nip: "0000"
175
+ type: "purchase",
176
+ nip: "0000",
177
+ transactionId: "txn-zero-003"
146
178
  };
147
179
 
148
180
  axiosMock.onPut(`/external-wallets/saldo-max/${walletId}/movements`).reply(expectRequest({