From 243437711c3bcd98b668b98fb0f65d2306823aae Mon Sep 17 00:00:00 2001 From: rodrigojara-cko Date: Thu, 5 Nov 2026 13:12:20 +0100 Subject: [PATCH 1/2] fix(client): security hardening Input validation for request building. Values placed in request paths are percent-encoded per segment, and undefined, empty, "." and ".." path values throw ValueError before any request is sent. Query strings are built with the shared buildQueryParams helper, so their values are percent-encoded too. Values without special characters, such as resource ids, go out unchanged. --- src/api/apm-specific/baloto.js | 7 +- src/api/apm-specific/boleto.js | 7 +- src/api/apm-specific/fawry.js | 7 +- src/api/apm-specific/klarna.js | 16 +- src/api/apm-specific/oxxo.js | 7 +- src/api/apm-specific/pagofacil.js | 7 +- src/api/apm-specific/rapipago.js | 7 +- src/api/apm-specific/sepa.js | 21 +- src/api/balances/balances.js | 23 +- .../compliance-requests.js | 7 +- src/api/customers/customers.js | 10 +- src/api/disputes/disputes.js | 37 +- src/api/events/events.js | 30 +- src/api/files/files.js | 4 +- src/api/financial/financial.js | 10 +- src/api/forward/forward.js | 10 +- src/api/google-pay/google-pay.js | 10 +- src/api/hosted-payments/hosted-payments.js | 4 +- .../address-document-verifications.js | 23 +- src/api/identities/aml-screenings.js | 4 +- src/api/identities/applicants.js | 10 +- src/api/identities/face-authentications.js | 20 +- .../identities/id-document-verifications.js | 23 +- src/api/identities/identity-verifications.js | 23 +- src/api/instruments/instruments.js | 16 +- src/api/inventory/inventory.js | 25 +- src/api/issuing/cardholders.js | 10 +- src/api/issuing/cards.js | 32 +- src/api/issuing/control-groups.js | 8 +- src/api/issuing/control-profiles.js | 17 +- src/api/issuing/controls.js | 11 +- src/api/issuing/digital-cards.js | 4 +- src/api/issuing/disputes.js | 16 +- src/api/issuing/simulate.js | 13 +- src/api/issuing/transactions.js | 5 +- src/api/network-tokens/network-tokens.js | 10 +- .../onboarding-simulator.js | 10 +- src/api/payment-contexts/payment-contexts.js | 4 +- src/api/payment-methods/payment-methods.js | 3 +- src/api/payment-sessions/payment-sessions.js | 4 +- src/api/payment-setups/payment-setups.js | 10 +- src/api/payments-links/payments-links.js | 4 +- src/api/payments/payments.js | 34 +- src/api/platforms/entity-requirements.js | 10 +- src/api/platforms/files.js | 7 +- src/api/platforms/payment-instruments.js | 19 +- src/api/platforms/payout-schedules.js | 7 +- src/api/platforms/reserve-rules.js | 13 +- src/api/platforms/subentity.js | 13 +- src/api/reconciliation/reconciliation.js | 58 +-- src/api/reports/reports.js | 16 +- src/api/sessions/sessions.js | 13 +- src/api/tokens/tokens.js | 4 +- src/api/transfers/transfers.js | 4 +- src/api/webhooks/webhooks.js | 13 +- src/api/workflows/workflows.js | 52 ++- src/services/utils.js | 24 ++ test/balances/balances-balances-at-unit.js | 3 +- test/balances/balances-unit.js | 53 +++ test/disputes/disputes-unit.js | 29 ++ test/events/events.js | 41 +++ test/financial/financial.js | 31 +- test/payment-methods/payment-methods-unit.js | 29 ++ test/payments/getPaymentList.js | 29 ++ .../payment-instruments-unit.js | 40 +++ test/reconciliation/reconciliation-unit.js | 77 ++++ test/reports/reports-unit.js | 29 ++ test/services/path-segments-unit.js | 338 ++++++++++++++++++ test/services/utils.js | 36 +- 69 files changed, 1242 insertions(+), 309 deletions(-) create mode 100644 test/services/path-segments-unit.js diff --git a/src/api/apm-specific/baloto.js b/src/api/apm-specific/baloto.js index 7f83fe01..f1f916f4 100644 --- a/src/api/apm-specific/baloto.js +++ b/src/api/apm-specific/baloto.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APMS_PATH = 'apms'; @@ -27,12 +28,13 @@ export default class Baloto { * @param {string} id Payment id. * @memberof Baloto * @return {Promise} A promise to the Baloto response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async succeed(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`, + `${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class Baloto { * @param {string} id Payment id. * @memberof Baloto * @return {Promise} A promise to the Baloto response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async expire(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`, + `${this.config.host}/${APMS_PATH}/${BALOTO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/boleto.js b/src/api/apm-specific/boleto.js index 4e080680..4396320e 100644 --- a/src/api/apm-specific/boleto.js +++ b/src/api/apm-specific/boleto.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APMS_PATH = 'apms'; @@ -27,12 +28,13 @@ export default class Boleto { * @param {string} id Payment id. * @memberof Boleto * @return {Promise} A promise to the Boleto response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async succeed(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`, + `${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class Boleto { * @param {string} id Payment id. * @memberof Boleto * @return {Promise} A promise to the Boleto response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async expire(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`, + `${this.config.host}/${APMS_PATH}/${BOLETO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/fawry.js b/src/api/apm-specific/fawry.js index eaf3e9cf..775abc4c 100644 --- a/src/api/apm-specific/fawry.js +++ b/src/api/apm-specific/fawry.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APPROVAL_PATH = 'approval'; @@ -27,12 +28,13 @@ export default class Fawry { * @param {string} reference Reference. * @memberof Fawry * @return {Promise} A promise to the Fawry response. + * @throws {ValueError} If reference is undefined, empty, "." or "..". */ async approve(reference) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${reference}/${APPROVAL_PATH}`, + `${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${encodePathSegment(reference, 'reference')}/${APPROVAL_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class Fawry { * @param {string} reference Reference. * @memberof Fawry * @return {Promise} A promise to the Fawry response. + * @throws {ValueError} If reference is undefined, empty, "." or "..". */ async cancel(reference) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${reference}/${CANCELLATION_PATH}`, + `${this.config.host}/${FAWRY_PATH}/${PAYMENTS_PATH}/${encodePathSegment(reference, 'reference')}/${CANCELLATION_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/klarna.js b/src/api/apm-specific/klarna.js index 2601d493..34398294 100644 --- a/src/api/apm-specific/klarna.js +++ b/src/api/apm-specific/klarna.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CAPTURES_PATH = 'captures'; @@ -49,11 +50,12 @@ export default class Klarna { * * @param {string} id Session id. * @return {Promise} A promise to the Klarna response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getSession(id) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${CREDIT_SESSIONS_PATH}/${id}` - : `${this.config.host}/${KLARNA_PATH}/${CREDIT_SESSIONS_PATH}/${id}`; + ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${CREDIT_SESSIONS_PATH}/${encodePathSegment(id, 'id')}` + : `${this.config.host}/${KLARNA_PATH}/${CREDIT_SESSIONS_PATH}/${encodePathSegment(id, 'id')}`; try { const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -68,11 +70,12 @@ export default class Klarna { * @param {string} id Payment id. * @param {Object} body Capture details. * @return {Promise} A promise to the Klarna response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async capture(id, body) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${id}/${CAPTURES_PATH}` - : `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${id}/${CAPTURES_PATH}`; + ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${CAPTURES_PATH}` + : `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${CAPTURES_PATH}`; try { const response = await post( this.config.httpClient, @@ -93,11 +96,12 @@ export default class Klarna { * @param {string} id Payment id. * @param {Object} [body] Void details. * @return {Promise} A promise to the Klarna response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async void(id, body) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${id}/${VOIDS_PATH}` - : `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${id}/${VOIDS_PATH}`; + ? `${this.config.host}/${KLARNA_EXTERNAL_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${VOIDS_PATH}` + : `${this.config.host}/${KLARNA_PATH}/${ORDERS_PATH}/${encodePathSegment(id, 'id')}/${VOIDS_PATH}`; try { const response = await post( this.config.httpClient, diff --git a/src/api/apm-specific/oxxo.js b/src/api/apm-specific/oxxo.js index c67d9566..08f997af 100644 --- a/src/api/apm-specific/oxxo.js +++ b/src/api/apm-specific/oxxo.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APMS_PATH = 'apms'; @@ -27,12 +28,13 @@ export default class Oxxo { * @param {string} id Payment id. * @memberof Oxxo * @return {Promise} A promise to the Oxxo response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async succeed(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`, + `${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class Oxxo { * @param {string} id Payment id. * @memberof Oxxo * @return {Promise} A promise to the Oxxo response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async expire(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`, + `${this.config.host}/${APMS_PATH}/${OXXO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/pagofacil.js b/src/api/apm-specific/pagofacil.js index 366fc852..5542c4aa 100644 --- a/src/api/apm-specific/pagofacil.js +++ b/src/api/apm-specific/pagofacil.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APMS_PATH = 'apms'; @@ -27,12 +28,13 @@ export default class PagoFacil { * @param {string} id Payment id. * @memberof PagoFacil * @return {Promise} A promise to the PagoFacil response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async succeed(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`, + `${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class PagoFacil { * @param {string} id Payment id. * @memberof PagoFacil * @return {Promise} A promise to the PagoFacil response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async expire(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`, + `${this.config.host}/${APMS_PATH}/${PAGOFACIL_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/rapipago.js b/src/api/apm-specific/rapipago.js index 7694f49a..aeaf27a4 100644 --- a/src/api/apm-specific/rapipago.js +++ b/src/api/apm-specific/rapipago.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const APMS_PATH = 'apms'; @@ -27,12 +28,13 @@ export default class Rapipago { * @param {string} id Payment id. * @memberof Rapipago * @return {Promise} A promise to the Rapipago response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async succeed(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${id}/${SUCCEED_PATH}`, + `${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${SUCCEED_PATH}`, this.config, this.config.sk ); @@ -49,12 +51,13 @@ export default class Rapipago { * @param {string} id Payment id. * @memberof Rapipago * @return {Promise} A promise to the Rapipago response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async expire(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${id}/${EXPIRE_PATH}`, + `${this.config.host}/${APMS_PATH}/${RAPIPAGO_PATH}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${EXPIRE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/apm-specific/sepa.js b/src/api/apm-specific/sepa.js index 93bf24ba..2fea2555 100644 --- a/src/api/apm-specific/sepa.js +++ b/src/api/apm-specific/sepa.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CANCEL_PATH = 'cancel'; @@ -24,11 +25,12 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getMandate(id) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}` - : `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${id}`; + ? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}` + : `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`; try { const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -42,11 +44,12 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async cancelMandate(id) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}` - : `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`; + ? `${this.config.host}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}` + : `${this.config.host}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`; try { const response = await post(this.config.httpClient, url, this.config, this.config.sk); @@ -61,11 +64,12 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getPPROMandate(id) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}` - : `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${id}`; + ? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}` + : `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}`; try { const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -79,11 +83,12 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async cancelPPROMandate(id) { const url = this.config.host.includes('sandbox') - ? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}` - : `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${id}/${CANCEL_PATH}`; + ? `${this.config.host}/${PPRO_PATH}/${SEPA_EXTERNAL_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}` + : `${this.config.host}/${PPRO_PATH}/${SEPA_PATH}/${MANDATES_PATH}/${encodePathSegment(id, 'id')}/${CANCEL_PATH}`; try { const response = await post(this.config.httpClient, url, this.config, this.config.sk); diff --git a/src/api/balances/balances.js b/src/api/balances/balances.js index 0975c55f..c98af199 100644 --- a/src/api/balances/balances.js +++ b/src/api/balances/balances.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the balances host root (config.balancesUrl). const BALANCES_PATH = 'balances'; @@ -37,31 +38,34 @@ export default class Balances { * that point in time. Forwarded verbatim as the `balancesAt` (camelCase) * query parameter, as defined in swagger. * @return {Promise} A promise to the balances response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async retrieve(id, options) { try { - const queryParams = []; + const queryParams = {}; // Backward compatibility: if options is a string, treat it as currency if (typeof options === 'string') { - queryParams.push(`query=currency:${options}`); + queryParams.query = `currency:${options}`; } else if (typeof options === 'object' && options !== null) { // New object-based API if (options.query) { - queryParams.push(`query=${options.query}`); + queryParams.query = options.query; } if (options.withCurrencyAccountId !== undefined) { - queryParams.push(`withCurrencyAccountId=${options.withCurrencyAccountId}`); + queryParams.withCurrencyAccountId = options.withCurrencyAccountId; } if (options.balancesAt) { // Swagger defines the query parameter as `balancesAt` (camelCase), // not snake_case. Keep this exact name or the API silently ignores it. - queryParams.push(`balancesAt=${encodeURIComponent(options.balancesAt)}`); + queryParams.balancesAt = options.balancesAt; } } - const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : ''; - const url = `${this.config.balancesUrl}/${BALANCES_PATH}/${id}${queryString}`; + const url = buildQueryParams( + `${this.config.balancesUrl}/${BALANCES_PATH}/${encodePathSegment(id, 'id')}`, + queryParams + ); const response = await get( this.config.httpClient, @@ -109,12 +113,13 @@ export default class Balances { * @param {string} currencyAccountId The ID of the sub-account to retrieve top-up * instructions for. * @return {Promise} A promise to the top-up instructions response. + * @throws {ValueError} If entityId or currencyAccountId is undefined, empty, "." or "..". */ async retrieveTopUpInstructions(entityId, currencyAccountId) { try { const url = - `${this.config.balancesUrl}/${ENTITIES_PATH}/${entityId}` + - `/${CURRENCY_ACCOUNTS_PATH}/${currencyAccountId}/${TOP_UP_INSTRUCTIONS_PATH}`; + `${this.config.balancesUrl}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}` + + `/${CURRENCY_ACCOUNTS_PATH}/${encodePathSegment(currencyAccountId, 'currencyAccountId')}/${TOP_UP_INSTRUCTIONS_PATH}`; const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; diff --git a/src/api/compliance-requests/compliance-requests.js b/src/api/compliance-requests/compliance-requests.js index 0595b640..d140c89a 100644 --- a/src/api/compliance-requests/compliance-requests.js +++ b/src/api/compliance-requests/compliance-requests.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const COMPLIANCE_REQUESTS_PATH = 'compliance-requests'; @@ -21,12 +22,13 @@ export default class ComplianceRequests { * @memberof ComplianceRequests * @param {string} paymentId The payment id whose compliance request to fetch. * @return {Promise} A promise to the compliance request response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async getComplianceRequest(paymentId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${COMPLIANCE_REQUESTS_PATH}/${paymentId}`, + `${this.config.host}/${COMPLIANCE_REQUESTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}`, this.config, this.config.sk ); @@ -47,12 +49,13 @@ export default class ComplianceRequests { * @param {string} paymentId The payment id whose compliance request to respond to. * @param {Object} body Compliance response body. * @return {Promise} A promise to the response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async respondToComplianceRequest(paymentId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${COMPLIANCE_REQUESTS_PATH}/${paymentId}`, + `${this.config.host}/${COMPLIANCE_REQUESTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}`, this.config, this.config.sk, body diff --git a/src/api/customers/customers.js b/src/api/customers/customers.js index 550123db..681a3995 100644 --- a/src/api/customers/customers.js +++ b/src/api/customers/customers.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { _delete, get, patch, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CUSTOMERS_PATH = 'customers'; @@ -43,12 +44,13 @@ export default class Customers { * @memberof Customers * @param {string} id Customer id. * @return {Promise} A promise to the customer details response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${CUSTOMERS_PATH}/${id}`, + `${this.config.host}/${CUSTOMERS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -65,12 +67,13 @@ export default class Customers { * @param {string} id Customer id. * @param {Object} body Customer object body. * @return {Promise} A promise to the request customer response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async update(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${CUSTOMERS_PATH}/${id}`, + `${this.config.host}/${CUSTOMERS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -91,12 +94,13 @@ export default class Customers { * @memberof Customers * @param {string} id Customer id. * @return {Promise} A promise to the customer response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async delete(id) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${CUSTOMERS_PATH}/${id}`, + `${this.config.host}/${CUSTOMERS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/disputes/disputes.js b/src/api/disputes/disputes.js index ce9f8a4e..3e81ee42 100644 --- a/src/api/disputes/disputes.js +++ b/src/api/disputes/disputes.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post, put } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCEPT_PATH = 'accept'; @@ -32,14 +33,7 @@ export default class Disputes { */ async get(body) { try { - let url = `${this.config.host}/${DISPUTES_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${DISPUTES_PATH}`, body); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; } catch (err) { @@ -53,12 +47,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getDetails(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}`, this.config, this.config.sk ); @@ -74,12 +69,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async accept(disputeId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${ACCEPT_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${ACCEPT_PATH}`, this.config, this.config.sk ); @@ -102,12 +98,13 @@ export default class Disputes { * @param {string} disputeId Dispute id. * @param {Object} body Evidence * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async provideEvidence(disputeId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}`, this.config, this.config.sk, body @@ -124,12 +121,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getEvidence(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}`, this.config, this.config.sk ); @@ -147,12 +145,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async submit(disputeId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}`, this.config, this.config.sk ); @@ -170,12 +169,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the compiled submitted evidence response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getCompiledSubmittedEvidence(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}/${SUBMITTED_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}/${SUBMITTED_PATH}`, this.config, this.config.sk ); @@ -192,12 +192,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute scheme files response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getDisputeSchemeFiles(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${SCHEMEFILES_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${SCHEMEFILES_PATH}`, this.config, this.config.sk ); @@ -215,12 +216,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise that resolves when evidence is submitted successfully (204 No Content). + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async submitArbitrationEvidence(disputeId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}/${ARBITRATION_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}/${ARBITRATION_PATH}`, this.config, this.config.sk ); @@ -242,12 +244,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the compiled submitted arbitration evidence response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getCompiledSubmittedArbitrationEvidence(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${DISPUTES_PATH}/${disputeId}/${EVIDENCE_PATH}/${ARBITRATION_PATH}/${SUBMITTED_PATH}`, + `${this.config.host}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${EVIDENCE_PATH}/${ARBITRATION_PATH}/${SUBMITTED_PATH}`, this.config, this.config.sk ); diff --git a/src/api/events/events.js b/src/api/events/events.js index 7ac7d8c4..0c55dac7 100644 --- a/src/api/events/events.js +++ b/src/api/events/events.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const EVENTS_PATH = 'events'; @@ -32,10 +33,10 @@ export default class Events { */ async retrieveEventTypes(version) { try { - let url = `${this.config.host}/${EVENT_TYPES_PATH}`; - if (version) { - url += `?version=${version}`; - } + const url = buildQueryParams( + `${this.config.host}/${EVENT_TYPES_PATH}`, + version ? { version } : undefined + ); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; } catch (err) { @@ -54,14 +55,7 @@ export default class Events { */ async retrieveEvents(body) { try { - let url = `${this.config.host}/${EVENTS_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${EVENTS_PATH}`, body); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -78,12 +72,13 @@ export default class Events { * @memberof Events * @param {string} eventId Event id. * @return {Promise} A promise to the request event response. + * @throws {ValueError} If eventId is undefined, empty, "." or "..". */ async retrieveEvent(eventId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${EVENTS_PATH}/${eventId}`, + `${this.config.host}/${EVENTS_PATH}/${encodePathSegment(eventId, 'eventId')}`, this.config, this.config.sk ); @@ -100,12 +95,13 @@ export default class Events { * @memberof Events * @param {Object} body Event request body. * @return {Promise} A promise to the request event notifications response. + * @throws {ValueError} If body.eventId or body.notificationId is undefined, empty, "." or "..". */ async retrieveEventNotification(body) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${EVENTS_PATH}/${body.eventId}/${NOTIFICATIONS_PATH}/${body.notificationId}`, + `${this.config.host}/${EVENTS_PATH}/${encodePathSegment(body.eventId, 'eventId')}/${NOTIFICATIONS_PATH}/${encodePathSegment(body.notificationId, 'notificationId')}`, this.config, this.config.sk ); @@ -122,12 +118,13 @@ export default class Events { * @memberof Events * @param {Object} body Event request body. * @return {Promise} A promise to the retry event response. + * @throws {ValueError} If body.eventId or body.webhookId is undefined, empty, "." or "..". */ async retry(body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${EVENTS_PATH}/${body.eventId}/${WEBHOOKS_PATH}/${body.webhookId}/${RETRY_PATH}`, + `${this.config.host}/${EVENTS_PATH}/${encodePathSegment(body.eventId, 'eventId')}/${WEBHOOKS_PATH}/${encodePathSegment(body.webhookId, 'webhookId')}/${RETRY_PATH}`, this.config, this.config.sk ); @@ -144,12 +141,13 @@ export default class Events { * @memberof Events * @param {string} eventId Event id. * @return {Promise} A promise to the retry events response. + * @throws {ValueError} If eventId is undefined, empty, "." or "..". */ async retryAll(eventId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${EVENTS_PATH}/${eventId}/${WEBHOOKS_PATH}/${RETRY_PATH}`, + `${this.config.host}/${EVENTS_PATH}/${encodePathSegment(eventId, 'eventId')}/${WEBHOOKS_PATH}/${RETRY_PATH}`, this.config, this.config.sk ); diff --git a/src/api/files/files.js b/src/api/files/files.js index 15d32e11..2b89f8c6 100644 --- a/src/api/files/files.js +++ b/src/api/files/files.js @@ -2,6 +2,7 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; import FormData from 'form-data'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const FILES_PATH = 'files'; @@ -63,12 +64,13 @@ export default class Files { * @memberof Files * @param {string} fileId Files id. * @return {Promise} A promise to the files response. + * @throws {ValueError} If fileId is undefined, empty, "." or "..". */ async getFile(fileId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${FILES_PATH}/${fileId}`, + `${this.config.host}/${FILES_PATH}/${encodePathSegment(fileId, 'fileId')}`, this.config, this.config.sk ); diff --git a/src/api/financial/financial.js b/src/api/financial/financial.js index 915ac501..b6810b1e 100644 --- a/src/api/financial/financial.js +++ b/src/api/financial/financial.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get } from '../../services/http.js'; +import { buildQueryParams } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const FINANCIAL_ACTIONS_PATH = 'financial-actions'; @@ -24,14 +25,7 @@ export default class Financial { */ async query(parameters) { try { - let url = `${this.config.host}/${FINANCIAL_ACTIONS_PATH}`; - - if (parameters) { - const queryString = Object.keys(parameters) - .map((key) => `${key}=${parameters[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${FINANCIAL_ACTIONS_PATH}`, parameters); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; diff --git a/src/api/forward/forward.js b/src/api/forward/forward.js index d9f7b1af..b21eb374 100644 --- a/src/api/forward/forward.js +++ b/src/api/forward/forward.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { _delete, get, patch, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the forward host root (config.forwardUrl). const FORWARD_PATH = 'forward'; @@ -47,12 +48,13 @@ export default class Forward { * @memberof Forward * @param {string} id The unique identifier of the forward request * @return {Promise} A promise to the forward request details + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.forwardUrl}/${FORWARD_PATH}/${id}`, + `${this.config.forwardUrl}/${FORWARD_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -120,12 +122,13 @@ export default class Forward { * @param {string} name The secret name * @param {Object} body Update body with value and/or entity_id * @return {Promise} A promise to the updated secret metadata with incremented version + * @throws {ValueError} If name is undefined, empty, "." or "..". */ async updateSecret(name, body) { try { const response = await patch( this.config.httpClient, - `${this.config.forwardUrl}/${SECRETS_PATH}/${name}`, + `${this.config.forwardUrl}/${SECRETS_PATH}/${encodePathSegment(name, 'name')}`, this.config, this.config.sk, body @@ -142,12 +145,13 @@ export default class Forward { * @memberof Forward * @param {string} name The secret name to delete * @return {Promise} A promise to the deletion response + * @throws {ValueError} If name is undefined, empty, "." or "..". */ async deleteSecret(name) { try { const response = await _delete( this.config.httpClient, - `${this.config.forwardUrl}/${SECRETS_PATH}/${name}`, + `${this.config.forwardUrl}/${SECRETS_PATH}/${encodePathSegment(name, 'name')}`, this.config, this.config.sk ); diff --git a/src/api/google-pay/google-pay.js b/src/api/google-pay/google-pay.js index 1a3f8b5a..b13e9a16 100644 --- a/src/api/google-pay/google-pay.js +++ b/src/api/google-pay/google-pay.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const DOMAINS_PATH = 'domains'; @@ -53,12 +54,13 @@ export default class GooglePay { * @param {string} entityId The enrolled entity id. * @param {Object} body { web_domain: string } per swagger `GooglePayRegisterDomainRequest`. * @return {Promise} A promise that resolves on success. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async registerDomain(entityId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${entityId}/${DOMAIN_PATH}`, + `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${encodePathSegment(entityId, 'entityId')}/${DOMAIN_PATH}`, this.config, this.config.sk, body @@ -75,12 +77,13 @@ export default class GooglePay { * @memberof GooglePay * @param {string} entityId The enrolled entity id. * @return {Promise} A promise to the registered-domains response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async getRegisteredDomains(entityId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${entityId}/${DOMAINS_PATH}`, + `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${encodePathSegment(entityId, 'entityId')}/${DOMAINS_PATH}`, this.config, this.config.sk ); @@ -96,12 +99,13 @@ export default class GooglePay { * @memberof GooglePay * @param {string} entityId The enrolled entity id. * @return {Promise} A promise to the enrollment-state response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async getEnrollmentState(entityId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${entityId}/${STATE_PATH}`, + `${this.config.host}/${GOOGLEPAY_PATH}/${ENROLLMENTS_PATH}/${encodePathSegment(entityId, 'entityId')}/${STATE_PATH}`, this.config, this.config.sk ); diff --git a/src/api/hosted-payments/hosted-payments.js b/src/api/hosted-payments/hosted-payments.js index ba190525..b9eb32e2 100644 --- a/src/api/hosted-payments/hosted-payments.js +++ b/src/api/hosted-payments/hosted-payments.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const HOSTED_PAYMENTS_PATH = 'hosted-payments'; @@ -76,12 +77,13 @@ export default class HostedPayments { * @memberof HostedPayments * @param {string} id - Hosted payment id * @return {Promise} A promise to the Hosted Payment response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${HOSTED_PAYMENTS_PATH}/${id}`, + `${this.config.host}/${HOSTED_PAYMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/identities/address-document-verifications.js b/src/api/identities/address-document-verifications.js index b8879424..681aa9b8 100644 --- a/src/api/identities/address-document-verifications.js +++ b/src/api/identities/address-document-verifications.js @@ -1,5 +1,5 @@ import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; import { get, post } from '../../services/http.js'; // Path segments appended to the API base (config.identityVerificationUrl). @@ -51,10 +51,11 @@ export default class AddressDocumentVerifications { * @method getAddressDocumentVerification * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Get an address document verification response + * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". */ async getAddressDocumentVerification(address_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}`; + const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}`; const response = await get( this.config.httpClient, url, @@ -77,11 +78,12 @@ export default class AddressDocumentVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get address document verification attempts response + * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". */ async listAttempts(address_document_verification_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${ATTEMPTS_PATH}`, + `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${ATTEMPTS_PATH}`, params ); const response = await get( @@ -104,10 +106,11 @@ export default class AddressDocumentVerifications { * @param {string} address_document_verification_id - The address document verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an address document verification attempt response + * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttempt(address_document_verification_id, attempt_id) { try { - const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${ATTEMPTS_PATH}/${attempt_id}`; + const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}`; const response = await get( this.config.httpClient, url, @@ -127,10 +130,11 @@ export default class AddressDocumentVerifications { * @method anonymizeAddressDocumentVerification * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Anonymize an address document verification response + * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". */ async anonymizeAddressDocumentVerification(address_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${ANONYMIZE_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${ANONYMIZE_PATH}`; const response = await post( this.config.httpClient, url, @@ -151,10 +155,11 @@ export default class AddressDocumentVerifications { * @param {string} address_document_verification_id - The address document verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an address document verification attempt response + * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". */ async createAttempt(address_document_verification_id, body) { try { - const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${ATTEMPTS_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${ATTEMPTS_PATH}`; const response = await post( this.config.httpClient, url, @@ -175,10 +180,11 @@ export default class AddressDocumentVerifications { * @method getPDFReport * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Get address document verification report response + * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". */ async getPDFReport(address_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${PDF_REPORT_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${PDF_REPORT_PATH}`; const response = await get( this.config.httpClient, url, @@ -203,11 +209,12 @@ export default class AddressDocumentVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get address document verification attempt assets response + * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttemptAssets(address_document_verification_id, attempt_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${address_document_verification_id}/${ATTEMPTS_PATH}/${attempt_id}/${ASSETS_PATH}`, + `${this.config.identityVerificationUrl}/${ADDRESS_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(address_document_verification_id, 'address_document_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}/${ASSETS_PATH}`, params ); diff --git a/src/api/identities/aml-screenings.js b/src/api/identities/aml-screenings.js index ed172c0a..34fb21c5 100644 --- a/src/api/identities/aml-screenings.js +++ b/src/api/identities/aml-screenings.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.identityVerificationUrl). const AML_VERIFICATIONS_PATH = 'aml-verifications'; @@ -45,10 +46,11 @@ export default class AMLScreenings { * @method getAMLScreening * @param {string} aml_screening_id - The AML screening's unique identifier * @returns {Promise} A promise to the Get an AML screening response + * @throws {ValueError} If aml_screening_id is undefined, empty, "." or "..". */ async getAMLScreening(aml_screening_id) { try { - const url = `${this.config.identityVerificationUrl}/${AML_VERIFICATIONS_PATH}/${aml_screening_id}`; + const url = `${this.config.identityVerificationUrl}/${AML_VERIFICATIONS_PATH}/${encodePathSegment(aml_screening_id, 'aml_screening_id')}`; const response = await get( this.config.httpClient, url, diff --git a/src/api/identities/applicants.js b/src/api/identities/applicants.js index 21fdbc72..6d116fff 100644 --- a/src/api/identities/applicants.js +++ b/src/api/identities/applicants.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post, patch } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.identityVerificationUrl). const ANONYMIZE_PATH = 'anonymize'; @@ -45,10 +46,11 @@ export default class Applicants { * @method getApplicant * @param {string} applicantId - The applicant profile's unique identifier * @returns {Promise} A promise to the Get an applicant response + * @throws {ValueError} If applicantId is undefined, empty, "." or "..". */ async getApplicant(applicantId) { try { - const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${applicantId}`; + const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${encodePathSegment(applicantId, 'applicantId')}`; const response = await get( this.config.httpClient, url, @@ -68,10 +70,11 @@ export default class Applicants { * @param {string} applicantId - The applicant profile's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Update an applicant response + * @throws {ValueError} If applicantId is undefined, empty, "." or "..". */ async updateApplicant(applicantId, body) { try { - const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${applicantId}`; + const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${encodePathSegment(applicantId, 'applicantId')}`; const response = await patch( this.config.httpClient, url, @@ -91,10 +94,11 @@ export default class Applicants { * @method anonymizeApplicant * @param {string} applicantId - The applicant profile's unique identifier * @returns {Promise} A promise to the Anonymize an applicant response + * @throws {ValueError} If applicantId is undefined, empty, "." or "..". */ async anonymizeApplicant(applicantId) { try { - const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${applicantId}/${ANONYMIZE_PATH}`; + const url = `${this.config.identityVerificationUrl}/${APPLICANTS_PATH}/${encodePathSegment(applicantId, 'applicantId')}/${ANONYMIZE_PATH}`; const response = await post( this.config.httpClient, url, diff --git a/src/api/identities/face-authentications.js b/src/api/identities/face-authentications.js index c79988eb..c398de68 100644 --- a/src/api/identities/face-authentications.js +++ b/src/api/identities/face-authentications.js @@ -1,6 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.identityVerificationUrl). const ANONYMIZE_PATH = 'anonymize'; @@ -50,10 +50,11 @@ export default class FaceAuthentications { * @method getFaceAuthentication * @param {string} face_authentication_id - The face authentication's unique identifier * @returns {Promise} A promise to the Get a face authentication response + * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". */ async getFaceAuthentication(face_authentication_id) { try { - const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}`; + const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}`; const response = await get( this.config.httpClient, url, @@ -76,11 +77,12 @@ export default class FaceAuthentications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get face authentication attempts response + * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". */ async listAttempts(face_authentication_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}/${ATTEMPTS_PATH}`, + `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}/${ATTEMPTS_PATH}`, params ); const response = await get( @@ -103,10 +105,11 @@ export default class FaceAuthentications { * @param {string} face_authentication_id - The face authentication's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get a face authentication attempt response + * @throws {ValueError} If face_authentication_id or attempt_id is undefined, empty, "." or "..". */ async getAttempt(face_authentication_id, attempt_id) { try { - const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}/${ATTEMPTS_PATH}/${attempt_id}`; + const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}`; const response = await get( this.config.httpClient, url, @@ -130,11 +133,12 @@ export default class FaceAuthentications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get face authentication attempt assets response + * @throws {ValueError} If face_authentication_id or attempt_id is undefined, empty, "." or "..". */ async getAttemptAssets(face_authentication_id, attempt_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}/${ATTEMPTS_PATH}/${attempt_id}/${ASSETS_PATH}`, + `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}/${ASSETS_PATH}`, params ); @@ -158,10 +162,11 @@ export default class FaceAuthentications { * @param {string} face_authentication_id - The face authentication's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create a face authentication attempt response + * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". */ async createAttempt(face_authentication_id, body) { try { - const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}/${ATTEMPTS_PATH}`; + const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}/${ATTEMPTS_PATH}`; const response = await post( this.config.httpClient, url, @@ -182,10 +187,11 @@ export default class FaceAuthentications { * @method anonymizeFaceAuthentication * @param {string} face_authentication_id - The face authentication's unique identifier * @returns {Promise} A promise to the Anonymize a face authentication response + * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". */ async anonymizeFaceAuthentication(face_authentication_id) { try { - const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${face_authentication_id}/${ANONYMIZE_PATH}`; + const url = `${this.config.identityVerificationUrl}/${FACE_AUTHENTICATIONS_PATH}/${encodePathSegment(face_authentication_id, 'face_authentication_id')}/${ANONYMIZE_PATH}`; const response = await post( this.config.httpClient, url, diff --git a/src/api/identities/id-document-verifications.js b/src/api/identities/id-document-verifications.js index a5305e9e..cb441d4e 100644 --- a/src/api/identities/id-document-verifications.js +++ b/src/api/identities/id-document-verifications.js @@ -1,5 +1,5 @@ import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; import { get, post } from '../../services/http.js'; // Path segments appended to the API base (config.identityVerificationUrl). @@ -51,10 +51,11 @@ export default class IDDocumentVerifications { * @method getIDDocumentVerification * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Get an ID document verification response + * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". */ async getIDDocumentVerification(id_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}`; + const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}`; const response = await get( this.config.httpClient, url, @@ -77,11 +78,12 @@ export default class IDDocumentVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get ID document verification attempts response + * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". */ async listAttempts(id_document_verification_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${ATTEMPTS_PATH}`, + `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${ATTEMPTS_PATH}`, params ); const response = await get( @@ -104,10 +106,11 @@ export default class IDDocumentVerifications { * @param {string} id_document_verification_id - The ID document verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an ID document verification attempt response + * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttempt(id_document_verification_id, attempt_id) { try { - const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${ATTEMPTS_PATH}/${attempt_id}`; + const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}`; const response = await get( this.config.httpClient, url, @@ -127,10 +130,11 @@ export default class IDDocumentVerifications { * @method anonymizeIDDocumentVerification * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Anonymize an ID document verification response + * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". */ async anonymizeIDDocumentVerification(id_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${ANONYMIZE_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${ANONYMIZE_PATH}`; const response = await post( this.config.httpClient, url, @@ -152,10 +156,11 @@ export default class IDDocumentVerifications { * @param {string} id_document_verification_id - The ID document verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an ID document verification attempt response + * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". */ async createAttempt(id_document_verification_id, body) { try { - const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${ATTEMPTS_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${ATTEMPTS_PATH}`; const response = await post( this.config.httpClient, url, @@ -177,10 +182,11 @@ export default class IDDocumentVerifications { * @method getPDFReport * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Get ID document verification report response + * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". */ async getPDFReport(id_document_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${PDF_REPORT_PATH}`; + const url = `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${PDF_REPORT_PATH}`; const response = await get( this.config.httpClient, url, @@ -205,11 +211,12 @@ export default class IDDocumentVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get ID document verification attempt assets response + * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttemptAssets(id_document_verification_id, attempt_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${id_document_verification_id}/${ATTEMPTS_PATH}/${attempt_id}/${ASSETS_PATH}`, + `${this.config.identityVerificationUrl}/${ID_DOCUMENT_VERIFICATIONS_PATH}/${encodePathSegment(id_document_verification_id, 'id_document_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}/${ASSETS_PATH}`, params ); diff --git a/src/api/identities/identity-verifications.js b/src/api/identities/identity-verifications.js index 8bd8322e..8cc0b2fa 100644 --- a/src/api/identities/identity-verifications.js +++ b/src/api/identities/identity-verifications.js @@ -1,6 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.identityVerificationUrl). const ANONYMIZE_PATH = 'anonymize'; @@ -76,10 +76,11 @@ export default class IdentityVerifications { * @method getIdentityVerification * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Get an identity verification response + * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". */ async getIdentityVerification(identity_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}`; + const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}`; const response = await get( this.config.httpClient, url, @@ -99,10 +100,11 @@ export default class IdentityVerifications { * @method anonymizeIdentityVerification * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Anonymize an identity verification response + * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". */ async anonymizeIdentityVerification(identity_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${ANONYMIZE_PATH}`; + const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${ANONYMIZE_PATH}`; const response = await post( this.config.httpClient, url, @@ -123,10 +125,11 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an identity verification attempt response + * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". */ async createAttempt(identity_verification_id, body) { try { - const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${ATTEMPTS_PATH}`; + const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${ATTEMPTS_PATH}`; const response = await post( this.config.httpClient, url, @@ -150,11 +153,12 @@ export default class IdentityVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get identity verification attempts response + * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". */ async listAttempts(identity_verification_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${ATTEMPTS_PATH}`, + `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${ATTEMPTS_PATH}`, params ); const response = await get( @@ -177,10 +181,11 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an identity verification attempt response + * @throws {ValueError} If identity_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttempt(identity_verification_id, attempt_id) { try { - const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${ATTEMPTS_PATH}/${attempt_id}`; + const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}`; const response = await get( this.config.httpClient, url, @@ -205,11 +210,12 @@ export default class IdentityVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get identity verification attempt assets response + * @throws {ValueError} If identity_verification_id or attempt_id is undefined, empty, "." or "..". */ async getAttemptAssets(identity_verification_id, attempt_id, params) { try { const url = buildQueryParams( - `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${ATTEMPTS_PATH}/${attempt_id}/${ASSETS_PATH}`, + `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${ATTEMPTS_PATH}/${encodePathSegment(attempt_id, 'attempt_id')}/${ASSETS_PATH}`, params ); @@ -234,10 +240,11 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Get identity verification report response, * carrying `pdf_report`, the pre-signed URL to the PDF + * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". */ async getPDFReport(identity_verification_id) { try { - const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${identity_verification_id}/${PDF_REPORT_PATH}`; + const url = `${this.config.identityVerificationUrl}/${IDENTITY_VERIFICATIONS_PATH}/${encodePathSegment(identity_verification_id, 'identity_verification_id')}/${PDF_REPORT_PATH}`; const response = await get( this.config.httpClient, url, diff --git a/src/api/instruments/instruments.js b/src/api/instruments/instruments.js index d44b555b..2c51a6c1 100644 --- a/src/api/instruments/instruments.js +++ b/src/api/instruments/instruments.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { _delete, get, patch, post } from '../../services/http.js'; import { setInstrumentType } from '../../services/validation.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const BANK_ACCOUNTS_PATH = 'bank-accounts'; @@ -128,12 +129,13 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id. * @return {Promise} A promise to the instrument response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${INSTRUMENTS_PATH}/${id}`, + `${this.config.host}/${INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -177,12 +179,13 @@ export default class Instruments { * @param {string} id Instrument id. * @param {Object} body Instruments request body. * @return {Promise} A promise to the instrument response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async update(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${INSTRUMENTS_PATH}/${id}`, + `${this.config.host}/${INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -199,12 +202,13 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id. * @return {Promise} A promise to the instrument response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async delete(id) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${INSTRUMENTS_PATH}/${id}`, + `${this.config.host}/${INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -226,12 +230,13 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id (pattern: ^(src_)[a-z0-9]{26}$). * @return {Promise} A promise to the revoke response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async revoke(id) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${INSTRUMENTS_PATH}/${id}/${REVOKE_PATH}`, + `${this.config.host}/${INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}/${REVOKE_PATH}`, this.config, this.config.sk ); @@ -263,6 +268,7 @@ export default class Instruments { * @param {string} [query.accountHolderType] individual | corporate | government. * @param {string} [query.paymentNetwork] local | sepa | fps | ach | fedwire | swift. * @return {Promise} A promise to the bank account field response. + * @throws {ValueError} If country or currency is undefined, empty, "." or "..". */ async getBankAccountFieldFormatting(country, currency, query) { try { @@ -287,7 +293,7 @@ export default class Instruments { const response = await get( this.config.httpClient, - `${this.config.host}/${VALIDATION_PATH}/${BANK_ACCOUNTS_PATH}/${country}/${currency}${queryString}`, + `${this.config.host}/${VALIDATION_PATH}/${BANK_ACCOUNTS_PATH}/${encodePathSegment(country, 'country')}/${encodePathSegment(currency, 'currency')}${queryString}`, this.config, this.config.sk ); diff --git a/src/api/inventory/inventory.js b/src/api/inventory/inventory.js index f7b5b844..1364c4b2 100644 --- a/src/api/inventory/inventory.js +++ b/src/api/inventory/inventory.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post, put, _delete } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const INVENTORY_PATH = 'inventory'; @@ -133,12 +134,13 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getInventoryReservation(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${id}`, + `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -155,12 +157,13 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async commitInventoryReservation(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${id}/${COMMIT_PATH}`, + `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${encodePathSegment(id, 'id')}/${COMMIT_PATH}`, this.config, this.config.sk ); @@ -177,12 +180,13 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async releaseInventoryReservation(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${id}/${RELEASE_PATH}`, + `${this.config.host}/${INVENTORY_PATH}/${RESERVATIONS_PATH}/${encodePathSegment(id, 'id')}/${RELEASE_PATH}`, this.config, this.config.sk ); @@ -209,6 +213,7 @@ export default class Inventory { * @param {string} [options.expand] Set to `'product'` to embed the variant's * product knowledge in the response. * @return {Promise} A promise to the InventoryLevels response. + * @throws {ValueError} If variantId is undefined, empty, "." or "..". */ async getInventoryLevels(variantId, options) { try { @@ -220,7 +225,7 @@ export default class Inventory { const response = await get( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${variantId}${query}`, + `${this.config.host}/${INVENTORY_PATH}/${encodePathSegment(variantId, 'variantId')}${query}`, this.config, this.config.sk ); @@ -246,12 +251,13 @@ export default class Inventory { * @param {number} [body.safety_stock] Buffer withheld from sale. * @param {string} [body.reason] Free-text reason for the ledger. * @return {Promise} A promise to the InventoryLevels response. + * @throws {ValueError} If variantId is undefined, empty, "." or "..". */ async setInventoryLevels(variantId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${variantId}`, + `${this.config.host}/${INVENTORY_PATH}/${encodePathSegment(variantId, 'variantId')}`, this.config, this.config.sk, body @@ -285,12 +291,13 @@ export default class Inventory { * @memberof Inventory * @param {string} variantId Variant id (max 128 chars). * @return {Promise} A promise to the InventoryProductKnowledge response. + * @throws {ValueError} If variantId is undefined, empty, "." or "..". */ async getInventoryProduct(variantId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${variantId}/${PRODUCT_PATH}`, + `${this.config.host}/${INVENTORY_PATH}/${encodePathSegment(variantId, 'variantId')}/${PRODUCT_PATH}`, this.config, this.config.sk ); @@ -320,12 +327,13 @@ export default class Inventory { * @param {string} body.product_url Product page URL. [Required] max 2048 chars. * @param {string} body.image_url Product image URL. [Required] max 2048 chars. * @return {Promise} A promise to the InventoryProductKnowledge response. + * @throws {ValueError} If variantId is undefined, empty, "." or "..". */ async setInventoryProduct(variantId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${variantId}/${PRODUCT_PATH}`, + `${this.config.host}/${INVENTORY_PATH}/${encodePathSegment(variantId, 'variantId')}/${PRODUCT_PATH}`, this.config, this.config.sk, body @@ -343,12 +351,13 @@ export default class Inventory { * @memberof Inventory * @param {string} variantId Variant id (max 128 chars). * @return {Promise} A promise that resolves to an empty object on success. + * @throws {ValueError} If variantId is undefined, empty, "." or "..". */ async deleteInventoryProduct(variantId) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${INVENTORY_PATH}/${variantId}/${PRODUCT_PATH}`, + `${this.config.host}/${INVENTORY_PATH}/${encodePathSegment(variantId, 'variantId')}/${PRODUCT_PATH}`, this.config, this.config.sk ); diff --git a/src/api/issuing/cardholders.js b/src/api/issuing/cardholders.js index 67a200b5..b7e6b6b3 100644 --- a/src/api/issuing/cardholders.js +++ b/src/api/issuing/cardholders.js @@ -1,5 +1,6 @@ import { get, patch, post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CARDHOLDERS_PATH = 'cardholders'; @@ -45,12 +46,13 @@ export default class Cardholders { * @memberof Cardholders * @param {string} id Cardholder id. * @return {Promise} A promise to the cardholder details response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getCardholder(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -67,12 +69,13 @@ export default class Cardholders { * @param {string} id Cardholder id. * @param {Object} body Cardholder params to update. * @return {Promise} A promise to the cardholder update response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateCardholder(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -89,12 +92,13 @@ export default class Cardholders { * @memberof Cardholders * @param {string} id Cardholder id. * @return {Promise} A promise to the cardholder details response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getCardholderCards(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${id}/${CARDS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDHOLDERS_PATH}/${encodePathSegment(id, 'id')}/${CARDS_PATH}`, this.config, this.config.sk ); diff --git a/src/api/issuing/cards.js b/src/api/issuing/cards.js index 216c9fa6..a4469e02 100644 --- a/src/api/issuing/cards.js +++ b/src/api/issuing/cards.js @@ -1,6 +1,6 @@ import { get, patch, post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACTIVATE_PATH = 'activate'; @@ -65,12 +65,13 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card details response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getCardDetails(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -125,6 +126,7 @@ export default class Cards { * `scheduled_revocation_date`), `scheduled_activation_date`, `last_activated_on`, * `root_card_id`, `parent_card_id`, `scheme`, `created_date`, `last_modified_date`, `_links` * and, for virtual cards only (`type` is `virtual`), `is_single_use`. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateCard(id, body, headers) { try { @@ -134,7 +136,7 @@ export default class Cards { const response = await patch( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}`, config, this.config.sk, body @@ -152,12 +154,13 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body 3DS enrollment params. * @return {Promise} A promise to the card response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async enrollThreeDS(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${THREE_DS_ENROLLMENT_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${THREE_DS_ENROLLMENT_PATH}`, this.config, this.config.sk, body @@ -175,12 +178,13 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body 3DS enrollment params. * @return {Promise} A promise to the card response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateThreeDS(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${THREE_DS_ENROLLMENT_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${THREE_DS_ENROLLMENT_PATH}`, this.config, this.config.sk, body @@ -197,12 +201,13 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getThreeDSDetails(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${THREE_DS_ENROLLMENT_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${THREE_DS_ENROLLMENT_PATH}`, this.config, this.config.sk ); @@ -221,12 +226,13 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async activateCard(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${ACTIVATE_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${ACTIVATE_PATH}`, this.config, this.config.sk ); @@ -243,11 +249,12 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body Card params. * @return {Promise} A promise to the card response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getCardCredentials(id, body) { try { const url = buildQueryParams( - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${CREDENTIALS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${CREDENTIALS_PATH}`, body ); @@ -265,12 +272,13 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body Card renewal params. * @return {Promise} A promise to the card renewal response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async renewCard(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${RENEW_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${RENEW_PATH}`, this.config, this.config.sk, body @@ -290,12 +298,13 @@ export default class Cards { * without a body. * @param {string} [body.reason] Optional reason: `expired`, `reported_lost` or `reported_stolen`. * @return {Promise} A promise to the revoke-card response, carrying `_links`. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async revokeCard(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${REVOKE_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${REVOKE_PATH}`, this.config, this.config.sk, body @@ -315,12 +324,13 @@ export default class Cards { * without a body. * @param {string} [body.reason] Optional reason: `suspected_lost` or `suspected_stolen`. * @return {Promise} A promise to the suspend-card response, carrying `_links`. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async suspendCard(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${id}/${SUSPEND_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${CARDS_PATH}/${encodePathSegment(id, 'id')}/${SUSPEND_PATH}`, this.config, this.config.sk, body diff --git a/src/api/issuing/control-groups.js b/src/api/issuing/control-groups.js index 31e16b45..054fa089 100644 --- a/src/api/issuing/control-groups.js +++ b/src/api/issuing/control-groups.js @@ -1,6 +1,6 @@ import { _delete, get, post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CONTROLS_PATH = 'controls'; @@ -66,12 +66,13 @@ export default class ControlGroups { * @memberof ControlGroups * @param {string} controlGroupId The control group ID. * @return {Promise} A promise to the control group details. + * @throws {ValueError} If controlGroupId is undefined, empty, "." or "..". */ async getControlGroup(controlGroupId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_GROUPS_PATH}/${controlGroupId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_GROUPS_PATH}/${encodePathSegment(controlGroupId, 'controlGroupId')}`, this.config, this.config.sk ); @@ -89,12 +90,13 @@ export default class ControlGroups { * @memberof ControlGroups * @param {string} controlGroupId The control group ID. * @return {Promise} A promise to the deletion response. + * @throws {ValueError} If controlGroupId is undefined, empty, "." or "..". */ async deleteControlGroup(controlGroupId) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_GROUPS_PATH}/${controlGroupId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_GROUPS_PATH}/${encodePathSegment(controlGroupId, 'controlGroupId')}`, this.config, this.config.sk ); diff --git a/src/api/issuing/control-profiles.js b/src/api/issuing/control-profiles.js index 70250002..88cdd9a5 100644 --- a/src/api/issuing/control-profiles.js +++ b/src/api/issuing/control-profiles.js @@ -1,6 +1,6 @@ import { _delete, get, patch, post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ADD_PATH = 'add'; @@ -68,12 +68,13 @@ export default class ControlProfiles { * @memberof ControlProfiles * @param {string} controlProfileId The control profile ID. * @return {Promise} A promise to the control profile details. + * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". */ async getControlProfile(controlProfileId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${controlProfileId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${encodePathSegment(controlProfileId, 'controlProfileId')}`, this.config, this.config.sk ); @@ -91,12 +92,13 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {Object} body Control profile update params. * @return {Promise} A promise to the control profile response. + * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". */ async updateControlProfile(controlProfileId, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${controlProfileId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${encodePathSegment(controlProfileId, 'controlProfileId')}`, this.config, this.config.sk, body @@ -114,12 +116,13 @@ export default class ControlProfiles { * @memberof ControlProfiles * @param {string} controlProfileId The control profile ID. * @return {Promise} A promise to the deletion response. + * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". */ async deleteControlProfile(controlProfileId) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${controlProfileId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${encodePathSegment(controlProfileId, 'controlProfileId')}`, this.config, this.config.sk ); @@ -137,12 +140,13 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {string} targetId The target ID to add to control profile. * @return {Promise} A promise to the response. + * @throws {ValueError} If controlProfileId or targetId is undefined, empty, "." or "..". */ async addTargetToControlProfile(controlProfileId, targetId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${controlProfileId}/${ADD_PATH}/${targetId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${encodePathSegment(controlProfileId, 'controlProfileId')}/${ADD_PATH}/${encodePathSegment(targetId, 'targetId')}`, this.config, this.config.sk ); @@ -160,12 +164,13 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {string} targetId The target ID to remove from control profile. * @return {Promise} A promise to the response. + * @throws {ValueError} If controlProfileId or targetId is undefined, empty, "." or "..". */ async removeTargetFromControlProfile(controlProfileId, targetId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${controlProfileId}/${REMOVE_PATH}/${targetId}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${CONTROL_PROFILES_PATH}/${encodePathSegment(controlProfileId, 'controlProfileId')}/${REMOVE_PATH}/${encodePathSegment(targetId, 'targetId')}`, this.config, this.config.sk ); diff --git a/src/api/issuing/controls.js b/src/api/issuing/controls.js index 9679d0ed..7309cc16 100644 --- a/src/api/issuing/controls.js +++ b/src/api/issuing/controls.js @@ -1,6 +1,6 @@ import { _delete, get, post, put } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CONTROLS_PATH = 'controls'; @@ -138,12 +138,13 @@ export default class Controls { * @memberof Controls * @param {string} id Card control id. * @return {Promise} A promise to the control details. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getCardControlDetails(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -160,12 +161,13 @@ export default class Controls { * @param {string} id Card control id. * @param {Object} body Card control params. * @return {Promise} A promise to the updated control. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateCardControl(id, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -182,12 +184,13 @@ export default class Controls { * @memberof Controls * @param {string} id Card control id. * @return {Promise} A promise to the removed control id. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async deleteCardControl(id) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${id}`, + `${this.config.host}/${ISSUING_PATH}/${CONTROLS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/issuing/digital-cards.js b/src/api/issuing/digital-cards.js index 09de918e..d899dda1 100644 --- a/src/api/issuing/digital-cards.js +++ b/src/api/issuing/digital-cards.js @@ -1,5 +1,6 @@ import { get } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const DIGITAL_CARDS_PATH = 'digital-cards'; @@ -23,12 +24,13 @@ export default class DigitalCards { * @memberof DigitalCards * @param {string} digitalCardId The digital card ID. * @return {Promise} A promise to the digital card details. + * @throws {ValueError} If digitalCardId is undefined, empty, "." or "..". */ async getDigitalCard(digitalCardId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DIGITAL_CARDS_PATH}/${digitalCardId}`, + `${this.config.host}/${ISSUING_PATH}/${DIGITAL_CARDS_PATH}/${encodePathSegment(digitalCardId, 'digitalCardId')}`, this.config, this.config.sk ); diff --git a/src/api/issuing/disputes.js b/src/api/issuing/disputes.js index 2c66b709..11279528 100644 --- a/src/api/issuing/disputes.js +++ b/src/api/issuing/disputes.js @@ -1,5 +1,6 @@ import { get, post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const AMEND_PATH = 'amend'; @@ -55,12 +56,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId The dispute ID. * @return {Promise} A promise to the dispute details. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async getDispute(disputeId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${disputeId}`, + `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}`, this.config, this.config.sk ); @@ -78,12 +80,13 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId The dispute ID. * @return {Promise} A promise to the cancellation response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async cancelDispute(disputeId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${disputeId}/${CANCEL_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${CANCEL_PATH}`, this.config, this.config.sk ); @@ -102,12 +105,13 @@ export default class Disputes { * @param {Object} [body] Escalation request params. Provide `fraud_details` * when the dispute reason code is fraud-related. * @return {Promise} A promise to the escalation response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async escalateDispute(disputeId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${disputeId}/${ESCALATE_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${ESCALATE_PATH}`, this.config, this.config.sk, body @@ -130,12 +134,13 @@ export default class Disputes { * `evidence`, `fraud_details`, `reason_change_justification`, * `action_response`). * @return {Promise} A promise to the dispute response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async amendDispute(disputeId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${disputeId}/${AMEND_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${AMEND_PATH}`, this.config, this.config.sk, body @@ -157,12 +162,13 @@ export default class Disputes { * @param {string} disputeId The dispute ID. * @param {Object} [body] Submission request params. * @return {Promise} A promise to the submission response. + * @throws {ValueError} If disputeId is undefined, empty, "." or "..". */ async submitDispute(disputeId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${disputeId}/${SUBMIT_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${DISPUTES_PATH}/${encodePathSegment(disputeId, 'disputeId')}/${SUBMIT_PATH}`, this.config, this.config.sk, body diff --git a/src/api/issuing/simulate.js b/src/api/issuing/simulate.js index afb3f48e..b1756d8c 100644 --- a/src/api/issuing/simulate.js +++ b/src/api/issuing/simulate.js @@ -1,5 +1,6 @@ import { post } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const AUTHENTICATION_PATH = 'authentication'; @@ -51,12 +52,13 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async simulateIncrement(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${id}/${AUTHORIZATIONS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${encodePathSegment(id, 'id')}/${AUTHORIZATIONS_PATH}`, this.config, this.config.sk, body @@ -74,12 +76,13 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async simulateClearing(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${id}/${PRESENTMENTS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${encodePathSegment(id, 'id')}/${PRESENTMENTS_PATH}`, this.config, this.config.sk, body @@ -97,12 +100,13 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Refund amount and params. * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async simulateRefund(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${id}/${REFUNDS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${encodePathSegment(id, 'id')}/${REFUNDS_PATH}`, this.config, this.config.sk, body @@ -120,12 +124,13 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async simulateReversal(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${id}/${REVERSALS_PATH}`, + `${this.config.host}/${ISSUING_PATH}/${SIMULATE_PATH}/${AUTHORIZATIONS_PATH}/${encodePathSegment(id, 'id')}/${REVERSALS_PATH}`, this.config, this.config.sk, body diff --git a/src/api/issuing/transactions.js b/src/api/issuing/transactions.js index d111dc33..b56541b4 100644 --- a/src/api/issuing/transactions.js +++ b/src/api/issuing/transactions.js @@ -1,6 +1,6 @@ import { get } from '../../services/http.js'; import { determineError } from '../../services/errors.js'; -import { buildQueryParams } from '../../services/utils.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ISSUING_PATH = 'issuing'; @@ -43,12 +43,13 @@ export default class Transactions { * @memberof Transactions * @param {string} transactionId The transaction ID. * @return {Promise} A promise to the transaction details. + * @throws {ValueError} If transactionId is undefined, empty, "." or "..". */ async getTransactionById(transactionId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ISSUING_PATH}/${TRANSACTIONS_PATH}/${transactionId}`, + `${this.config.host}/${ISSUING_PATH}/${TRANSACTIONS_PATH}/${encodePathSegment(transactionId, 'transactionId')}`, this.config, this.config.sk ); diff --git a/src/api/network-tokens/network-tokens.js b/src/api/network-tokens/network-tokens.js index c382ffa3..e42031c1 100644 --- a/src/api/network-tokens/network-tokens.js +++ b/src/api/network-tokens/network-tokens.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, patch, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CRYPTOGRAMS_PATH = 'cryptograms'; @@ -48,10 +49,11 @@ export default class NetworkTokens { * @memberof NetworkTokens * @param {string} network_token_id - The network token ID * @returns {Promise} A promise to the Get Network Token response + * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". */ async getNetworkToken(network_token_id) { try { - const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${network_token_id}`; + const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${encodePathSegment(network_token_id, 'network_token_id')}`; const response = await get( this.config.httpClient, url, @@ -72,10 +74,11 @@ export default class NetworkTokens { * @param {string} network_token_id - The network token ID * @param {Object} body - Request body containing transaction_type * @returns {Promise} A promise to the Request a cryptogram response + * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". */ async provisionCryptogram(network_token_id, body) { try { - const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${network_token_id}/${CRYPTOGRAMS_PATH}`; + const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${encodePathSegment(network_token_id, 'network_token_id')}/${CRYPTOGRAMS_PATH}`; const response = await post( this.config.httpClient, url, @@ -97,10 +100,11 @@ export default class NetworkTokens { * @memberof NetworkTokens * @param {string} network_token_id - Unique token ID assigned by Checkout.com for each token * @returns {Promise} A promise to the Delete Network Token response + * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". */ async deleteNetworkToken(network_token_id) { try { - const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${network_token_id}/${DELETE_PATH}`; + const url = `${this.config.host}/${NETWORK_TOKENS_PATH}/${encodePathSegment(network_token_id, 'network_token_id')}/${DELETE_PATH}`; const response = await patch( this.config.httpClient, url, diff --git a/src/api/onboarding-simulator/onboarding-simulator.js b/src/api/onboarding-simulator/onboarding-simulator.js index 583fae16..0729168e 100644 --- a/src/api/onboarding-simulator/onboarding-simulator.js +++ b/src/api/onboarding-simulator/onboarding-simulator.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ENTITIES_PATH = 'entities'; @@ -66,12 +67,13 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {Object} body { field_names: string[] } * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async setRequirementsDue(entityId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${entityId}/${REQUIREMENTS_DUE_PATH}`, + `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${REQUIREMENTS_DUE_PATH}`, this.config, this.config.sk, body @@ -89,12 +91,13 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {string} scenarioId The scenario id to execute. * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If entityId or scenarioId is undefined, empty, "." or "..". */ async runScenario(entityId, scenarioId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${entityId}/${SCENARIOS_PATH}/${scenarioId}`, + `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${SCENARIOS_PATH}/${encodePathSegment(scenarioId, 'scenarioId')}`, this.config, this.config.sk ); @@ -111,12 +114,13 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {Object} body { status: string, ... } (see swagger SimulatorSetStatusRequest). * @return {Promise} A promise to the simulation response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async setEntityStatus(entityId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${entityId}/${STATUS_PATH}`, + `${this.config.host}/${SIMULATE_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${STATUS_PATH}`, this.config, this.config.sk, body diff --git a/src/api/payment-contexts/payment-contexts.js b/src/api/payment-contexts/payment-contexts.js index bae5dc14..954c8d69 100644 --- a/src/api/payment-contexts/payment-contexts.js +++ b/src/api/payment-contexts/payment-contexts.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; import { validatePayment } from '../../services/validation.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const PAYMENT_CONTEXTS_PATH = 'payment-contexts'; @@ -86,12 +87,13 @@ export default class PaymentContexts { * @memberof PaymentContexts * @param {string} id /^(pay|sid)_(\w{26})$/ The payment or payment session identifier. * @return {Promise} A promise to the get payment context response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${PAYMENT_CONTEXTS_PATH}/${id}`, + `${this.config.host}/${PAYMENT_CONTEXTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/payment-methods/payment-methods.js b/src/api/payment-methods/payment-methods.js index 06434851..ff3308b3 100644 --- a/src/api/payment-methods/payment-methods.js +++ b/src/api/payment-methods/payment-methods.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get } from '../../services/http.js'; +import { buildQueryParams } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const PAYMENT_METHODS_PATH = 'payment-methods'; @@ -25,7 +26,7 @@ export default class PaymentMethods { */ async getPaymentMethods(processing_channel_id) { try { - const url = `${this.config.host}/${PAYMENT_METHODS_PATH}?processing_channel_id=${processing_channel_id}`; + const url = buildQueryParams(`${this.config.host}/${PAYMENT_METHODS_PATH}`, { processing_channel_id }); const response = await get( this.config.httpClient, url, diff --git a/src/api/payment-sessions/payment-sessions.js b/src/api/payment-sessions/payment-sessions.js index f6eedc09..3095002d 100644 --- a/src/api/payment-sessions/payment-sessions.js +++ b/src/api/payment-sessions/payment-sessions.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { post } from '../../services/http.js'; import { validatePayment } from '../../services/validation.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const COMPLETE_PATH = 'complete'; @@ -91,12 +92,13 @@ export default class PaymentSessions { * @param {string} id The payment session ID. * @param {object} body PaymentSessions Request body. * @return {Promise} A promise to payment context response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async submit(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENT_SESSIONS_PATH}/${id}/${SUBMIT_PATH}`, + `${this.config.host}/${PAYMENT_SESSIONS_PATH}/${encodePathSegment(id, 'id')}/${SUBMIT_PATH}`, this.config, this.config.sk, body diff --git a/src/api/payment-setups/payment-setups.js b/src/api/payment-setups/payment-setups.js index 42eb7af7..279fcdf5 100644 --- a/src/api/payment-setups/payment-setups.js +++ b/src/api/payment-setups/payment-setups.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, post, put } from '../../services/http.js'; import { validatePayment } from '../../services/validation.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const CONFIRM_PATH = 'confirm'; @@ -197,11 +198,12 @@ export default class PaymentSetups { * @param {string} id - The unique identifier of the Payment Setup to update. * @param {Object} body - Request body * @returns {Promise} A promise to the Update a Payment Setup response + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateAPaymentSetup(id, body) { try { validatePayment(body); - const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${id}`; + const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${encodePathSegment(id, 'id')}`; const response = await put( this.config.httpClient, url, @@ -291,10 +293,11 @@ export default class PaymentSetups { * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup to retrieve. * @returns {Promise} A promise to the Get a Payment Setup response + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getAPaymentSetup(id) { try { - const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${id}`; + const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${encodePathSegment(id, 'id')}`; const response = await get( this.config.httpClient, url, @@ -340,10 +343,11 @@ export default class PaymentSetups { * @param {string} id - The unique identifier of the Payment Setup. * @param {string} payment_method_name - The name of the payment method to process the payment with (e.g. "tabby", "klarna", "card", "cashapp"). * @returns {Promise} A promise to the Confirm a Payment Setup response + * @throws {ValueError} If id or payment_method_name is undefined, empty, "." or "..". */ async confirmAPaymentSetup(id, payment_method_name) { try { - const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${id}/${CONFIRM_PATH}/${payment_method_name}`; + const url = `${this.config.host}/${PAYMENTS_PATH}/${SETUPS_PATH}/${encodePathSegment(id, 'id')}/${CONFIRM_PATH}/${encodePathSegment(payment_method_name, 'payment_method_name')}`; const response = await post( this.config.httpClient, url, diff --git a/src/api/payments-links/payments-links.js b/src/api/payments-links/payments-links.js index cbc9ff16..0a1f4810 100644 --- a/src/api/payments-links/payments-links.js +++ b/src/api/payments-links/payments-links.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const PAYMENT_LINKS_PATH = 'payment-links'; @@ -77,12 +78,13 @@ export default class PaymentLinks { * @memberof PaymentLinks * @param {string} id * @return {Promise} A promise to the Payment Link response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${PAYMENT_LINKS_PATH}/${id}`, + `${this.config.host}/${PAYMENT_LINKS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/payments/payments.js b/src/api/payments/payments.js index ceb19c8f..e962d34c 100644 --- a/src/api/payments/payments.js +++ b/src/api/payments/payments.js @@ -2,6 +2,7 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; import { setSourceOrDestinationType, validatePayment } from '../../services/validation.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACTIONS_PATH = 'actions'; @@ -175,14 +176,7 @@ export default class Payments { * @return {Promise} A promise to the get payment response. */ async getPaymentList(body) { - let url = `${this.config.host}/${PAYMENTS_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${PAYMENTS_PATH}`, body); try { const response = await get(this.config.httpClient, url, this.config, this.config.sk); @@ -230,12 +224,13 @@ export default class Payments { * @memberof Payments * @param {string} id /^(pay|sid)_(\w{26})$/ The payment or payment session identifier. * @return {Promise} A promise to the get payment response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${id}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -252,12 +247,13 @@ export default class Payments { * @memberof Payments * @param {string} id /^(pay)_(\w{26})$/ The payment identifier. * @return {Promise} A promise to the getActions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getActions(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${id}/${ACTIONS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${ACTIONS_PATH}`, this.config, this.config.sk ); @@ -276,12 +272,13 @@ export default class Payments { * @param {Object} body Payment Request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the getActions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async increment(id, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${id}/${AUTHORIZATIONS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${AUTHORIZATIONS_PATH}`, this.config, this.config.sk, body, @@ -302,12 +299,13 @@ export default class Payments { * @param {Object} body Payment Request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the getActions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async cancelScheduledRetry(id, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${id}/${CANCELLATIONS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(id, 'id')}/${CANCELLATIONS_PATH}`, this.config, this.config.sk, body, @@ -327,12 +325,13 @@ export default class Payments { * @param {Object} [body] Capture request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the capture response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async capture(paymentId, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${paymentId}/${CAPTURES_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}/${CAPTURES_PATH}`, this.config, this.config.sk, body, @@ -352,12 +351,13 @@ export default class Payments { * @param {Object} [body] Refund request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the refund response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async refund(paymentId, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${paymentId}/${REFUNDS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}/${REFUNDS_PATH}`, this.config, this.config.sk, body, @@ -380,12 +380,13 @@ export default class Payments { * @param {Object} [body] Reverse request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the reverse response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async reverse(paymentId, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${paymentId}/${REVERSALS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}/${REVERSALS_PATH}`, this.config, this.config.sk, body, @@ -406,12 +407,13 @@ export default class Payments { * @param {number} [body.amount] The amount to void, in the minor currency unit (min 0, max 9999999999). If not specified, the full payment amount is voided. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the void response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async void(paymentId, body, idempotencyKey) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${PAYMENTS_PATH}/${paymentId}/${VOIDS_PATH}`, + `${this.config.host}/${PAYMENTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}/${VOIDS_PATH}`, this.config, this.config.sk, body, diff --git a/src/api/platforms/entity-requirements.js b/src/api/platforms/entity-requirements.js index 3e3c0e1f..92e75c21 100644 --- a/src/api/platforms/entity-requirements.js +++ b/src/api/platforms/entity-requirements.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, put } from '../../services/http.js'; import { getConfigWithAcceptHeader } from './accept-header.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCOUNTS_PATH = 'accounts'; @@ -25,12 +26,13 @@ export default class EntityRequirements { * @param {string} entityId The sub-entity id. * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the requirements list response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async getEntityRequirements(entityId, schemaVersion) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${REQUIREMENTS_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${REQUIREMENTS_PATH}`, getConfigWithAcceptHeader(this.config, schemaVersion), this.config.sk ); @@ -47,12 +49,13 @@ export default class EntityRequirements { * @param {string} entityId The sub-entity id. * @param {string} requirementId The requirement id. * @return {Promise} A promise to the requirement details response. + * @throws {ValueError} If entityId or requirementId is undefined, empty, "." or "..". */ async getEntityRequirementDetails(entityId, requirementId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${REQUIREMENTS_PATH}/${requirementId}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${REQUIREMENTS_PATH}/${encodePathSegment(requirementId, 'requirementId')}`, this.config, this.config.sk ); @@ -71,12 +74,13 @@ export default class EntityRequirements { * @param {Object} body { value: ... } — concrete shape defined by the * requirement's `_schema` returned from {@link getEntityRequirementDetails}. * @return {Promise} A promise to the update response. + * @throws {ValueError} If entityId or requirementId is undefined, empty, "." or "..". */ async updateEntityRequirement(entityId, requirementId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${REQUIREMENTS_PATH}/${requirementId}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${REQUIREMENTS_PATH}/${encodePathSegment(requirementId, 'requirementId')}`, this.config, this.config.sk, body diff --git a/src/api/platforms/files.js b/src/api/platforms/files.js index 4be2fc1e..cee9dd35 100644 --- a/src/api/platforms/files.js +++ b/src/api/platforms/files.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; import FormData from 'form-data'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ENTITIES_PATH = 'entities'; @@ -71,12 +72,13 @@ export default class PlatformFiles { * @param {Object} body The body; body.purpose is the purpose of the file upload, one of the * values above. * @returns {Promise} A promise to the file id and upload link. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async uploadAFile(entityId, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ENTITIES_PATH}/${entityId}/${FILES_PATH}`, + `${this.config.host}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${FILES_PATH}`, this.config, this.config.sk, body @@ -96,12 +98,13 @@ export default class PlatformFiles { * @returns {Promise} A promise to the file's id, status, status_reasons, size, * mime_type, uploaded_on, purpose and _links (download, the link to fetch the content, and * self). + * @throws {ValueError} If entityId or fileId is undefined, empty, "." or "..". */ async retrieveAFile(entityId, fileId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ENTITIES_PATH}/${entityId}/${FILES_PATH}/${fileId}`, + `${this.config.host}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${FILES_PATH}/${encodePathSegment(fileId, 'fileId')}`, this.config, this.config.sk ); diff --git a/src/api/platforms/payment-instruments.js b/src/api/platforms/payment-instruments.js index 443e886e..ed6589e5 100644 --- a/src/api/platforms/payment-instruments.js +++ b/src/api/platforms/payment-instruments.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, patch, post } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCOUNTS_PATH = 'accounts'; @@ -24,12 +25,13 @@ export default class PaymentInstruments { * @param {string} entityId The sub-entity's ID. * @param {string} id The payment instrument's ID. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". */ async getPaymentInstrumentDetails(entityId, id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${PAYMENT_INSTRUMENTS_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${PAYMENT_INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -57,12 +59,13 @@ export default class PaymentInstruments { * @param {string} id Payment instrument's id. * @param {Object} body The update, as described above. * @return {Promise} A promise to the Platforms response: the instrument id and _links. + * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". */ async updatePaymentInstrumentDetails(entityId, id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${PAYMENT_INSTRUMENTS_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${PAYMENT_INSTRUMENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -80,12 +83,13 @@ export default class PaymentInstruments { * @param {string} id Sub-entity id. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async createPaymentInstrument(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${INSTRUMENTS_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${INSTRUMENTS_PATH}`, this.config, this.config.sk, body @@ -112,12 +116,13 @@ export default class PaymentInstruments { * @param {string} id Sub-entity id. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async addPaymentInstrument(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${PAYMENT_INSTRUMENTS_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${PAYMENT_INSTRUMENTS_PATH}`, this.config, this.config.sk, body @@ -134,10 +139,14 @@ export default class PaymentInstruments { * @param {string} id The sub-entity's ID. * @param {string} [status] The status of your sub-entity's payment instrument. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async queryPaymentInstruments(id, status) { try { - const url = `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${PAYMENT_INSTRUMENTS_PATH}${status ? `?status=${status}` : ''}`; + const url = buildQueryParams( + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${PAYMENT_INSTRUMENTS_PATH}`, + status ? { status } : undefined + ); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; } catch (err) { diff --git a/src/api/platforms/payout-schedules.js b/src/api/platforms/payout-schedules.js index a4c6c870..fdbb64ef 100644 --- a/src/api/platforms/payout-schedules.js +++ b/src/api/platforms/payout-schedules.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCOUNTS_PATH = 'accounts'; @@ -33,12 +34,13 @@ export default class PayoutSchedules { * * @param {string} id The sub-entity's ID. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async retrieveSubEntityPayoutSchedule(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${PAYOUT_SCHEDULES_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${PAYOUT_SCHEDULES_PATH}`, this.config, this.config.sk ); @@ -67,12 +69,13 @@ export default class PayoutSchedules { * @param {string} id The sub-entity's ID. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateSubEntityPayoutSchedule(id, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${PAYOUT_SCHEDULES_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${PAYOUT_SCHEDULES_PATH}`, this.config, this.config.sk, body diff --git a/src/api/platforms/reserve-rules.js b/src/api/platforms/reserve-rules.js index 1b622d1d..b4b299fa 100644 --- a/src/api/platforms/reserve-rules.js +++ b/src/api/platforms/reserve-rules.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post, put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCOUNTS_PATH = 'accounts'; @@ -23,12 +24,13 @@ export default class ReserveRules { * @param {string} entityId The sub-entity's ID. * @param {string} id The reserve rule ID. * @return {Promise} A promise to the Platforms response (includes headers for ETag). + * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". */ async getReserveRuleDetails(entityId, id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${RESERVE_RULES_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${RESERVE_RULES_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -50,6 +52,7 @@ export default class ReserveRules { * @param {Object} body The body to be sent. * @param {string} ifMatch Identifies a specific version of a reserve rule to update (e.g. Y3Y9MCZydj0w). * @return {Promise} A promise to the Platforms response (includes headers for ETag). + * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". */ async updateReserveRule(entityId, id, body, ifMatch) { try { @@ -63,7 +66,7 @@ export default class ReserveRules { const response = await put( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${RESERVE_RULES_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${RESERVE_RULES_PATH}/${encodePathSegment(id, 'id')}`, config, this.config.sk, body @@ -84,12 +87,13 @@ export default class ReserveRules { * @param {string} id The sub-entity's ID. * @param {Object} body The body of the reserve rule to be added. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async addReserveRule(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${RESERVE_RULES_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${RESERVE_RULES_PATH}`, this.config, this.config.sk, body @@ -105,12 +109,13 @@ export default class ReserveRules { * * @param {string} id The sub-entity's ID. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async queryReserveRules(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}/${RESERVE_RULES_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}/${RESERVE_RULES_PATH}`, this.config, this.config.sk ); diff --git a/src/api/platforms/subentity.js b/src/api/platforms/subentity.js index 304bce27..f5c27b56 100644 --- a/src/api/platforms/subentity.js +++ b/src/api/platforms/subentity.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, post, put } from '../../services/http.js'; import { getConfigWithAcceptHeader } from './accept-header.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACCOUNTS_PATH = 'accounts'; @@ -145,12 +146,13 @@ export default class Subentity { * @param {string} id Sub-entity id. * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getSubEntityDetails(id, schemaVersion) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}`, getConfigWithAcceptHeader(this.config, schemaVersion), this.config.sk ); @@ -171,12 +173,13 @@ export default class Subentity { * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the Platforms response, the same shape as the * onboardSubEntity response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateSubEntityDetails(id, body, schemaVersion) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${id}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(id, 'id')}`, getConfigWithAcceptHeader(this.config, schemaVersion), this.config.sk, body @@ -192,12 +195,13 @@ export default class Subentity { * * @param {string} entityId Sub-entity id. * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If entityId is undefined, empty, "." or "..". */ async getSubEntityMembers(entityId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${MEMBERS_PATH}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${MEMBERS_PATH}`, this.config, this.config.sk ); @@ -214,12 +218,13 @@ export default class Subentity { * @param {string} userId The ID of the invited user. * @param {Object} body The body (Reinvite sub-entity member). * @return {Promise} A promise to the Platforms response. + * @throws {ValueError} If entityId or userId is undefined, empty, "." or "..". */ async reinviteSubEntityMember(entityId, userId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${entityId}/${MEMBERS_PATH}/${userId}`, + `${this.config.host}/${ACCOUNTS_PATH}/${ENTITIES_PATH}/${encodePathSegment(entityId, 'entityId')}/${MEMBERS_PATH}/${encodePathSegment(userId, 'userId')}`, this.config, this.config.sk, body diff --git a/src/api/reconciliation/reconciliation.js b/src/api/reconciliation/reconciliation.js index 49c142e2..034dd587 100644 --- a/src/api/reconciliation/reconciliation.js +++ b/src/api/reconciliation/reconciliation.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACTIONS_PATH = 'actions'; @@ -29,14 +30,7 @@ export default class Reconciliation { */ async getPayments(body) { try { - let url = `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}`, body); const response = await get(this.config.httpClient, url, this.config, this.config.sk); const res = await response.json; @@ -59,12 +53,13 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} paymentId Payment id. * @return {Promise} A promise to the request reconciliation response. + * @throws {ValueError} If paymentId is undefined, empty, "." or "..". */ async getPayment(paymentId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${paymentId}`, + `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${encodePathSegment(paymentId, 'paymentId')}`, this.config, this.config.sk ); @@ -83,14 +78,7 @@ export default class Reconciliation { */ async getPaymentsCsv(body) { try { - let url = `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${DOWNLOAD_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${DOWNLOAD_PATH}`, body); const response = await get( this.config.httpClient, url, @@ -113,14 +101,7 @@ export default class Reconciliation { */ async getStatements(body) { try { - let url = `${this.config.host}/${REPORTING_PATH}/${STATEMENTS_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTING_PATH}/${STATEMENTS_PATH}`, body); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; } catch (err) { @@ -135,12 +116,13 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} statementId Statement id. * @return {Promise} A promise to the request reconciliation response. + * @throws {ValueError} If statementId is undefined, empty, "." or "..". */ async getStatementCsv(statementId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTING_PATH}/${STATEMENTS_PATH}/${statementId}/${PAYMENTS_PATH}/${DOWNLOAD_PATH}`, + `${this.config.host}/${REPORTING_PATH}/${STATEMENTS_PATH}/${encodePathSegment(statementId, 'statementId')}/${PAYMENTS_PATH}/${DOWNLOAD_PATH}`, { ...this.config, csv: true }, this.config.sk ); @@ -159,14 +141,7 @@ export default class Reconciliation { */ async getPaymentsActions(body) { try { - let url = `${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}`, body); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -181,12 +156,13 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} actionsId Action id. * @return {Promise} A promise to the request reconciliation response. + * @throws {ValueError} If actionsId is undefined, empty, "." or "..". */ async getPaymentsAction(actionsId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${ACTIONS_PATH}/${actionsId}`, + `${this.config.host}/${REPORTING_PATH}/${PAYMENTS_PATH}/${ACTIONS_PATH}/${encodePathSegment(actionsId, 'actionsId')}`, this.config, this.config.sk ); @@ -205,14 +181,7 @@ export default class Reconciliation { */ async getPaymentsActionsCsv(body) { try { - let url = `${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}/${DOWNLOAD_PATH}`; - - if (body) { - const queryString = Object.keys(body) - .map((key) => `${key}=${body[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}/${DOWNLOAD_PATH}`, body); const response = await get( this.config.httpClient, url, @@ -231,12 +200,13 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} actionId Action id. * @return {Promise} A promise to the request reconciliation response. + * @throws {ValueError} If actionId is undefined, empty, "." or "..". */ async getAction(actionId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}/${actionId}`, + `${this.config.host}/${REPORTING_PATH}/${ACTIONS_PATH}/${encodePathSegment(actionId, 'actionId')}`, this.config, this.config.sk ); diff --git a/src/api/reports/reports.js b/src/api/reports/reports.js index fa8dbe3a..76769c13 100644 --- a/src/api/reports/reports.js +++ b/src/api/reports/reports.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get } from '../../services/http.js'; +import { buildQueryParams, encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const FILES_PATH = 'files'; @@ -25,14 +26,7 @@ export default class Reports { */ async getAllReports(parameters) { try { - let url = `${this.config.host}/${REPORTS_PATH}`; - - if (parameters) { - const queryString = Object.keys(parameters) - .map((key) => `${key}=${parameters[key]}`) - .join('&'); - url += `?${queryString}`; - } + const url = buildQueryParams(`${this.config.host}/${REPORTS_PATH}`, parameters); const response = await get(this.config.httpClient, url, this.config, this.config.sk); return await response.json; @@ -47,12 +41,13 @@ export default class Reports { * @memberof Reports * @param {string} id The ID of the report to retrieve. * @return {Promise} A promise to the Reports response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getReportDetails(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTS_PATH}/${id}`, + `${this.config.host}/${REPORTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -69,12 +64,13 @@ export default class Reports { * @param {string} id The ID of the report that the file belongs to. * @param {Object} fileId The ID of the file to retrieve. * @return {Promise} A promise to the Reports response. + * @throws {ValueError} If id or fileId is undefined, empty, "." or "..". */ async getReportFile(id, fileId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${REPORTS_PATH}/${id}/${FILES_PATH}/${fileId}`, + `${this.config.host}/${REPORTS_PATH}/${encodePathSegment(id, 'id')}/${FILES_PATH}/${encodePathSegment(fileId, 'fileId')}`, { ...this.config, csv: true }, this.config.sk ); diff --git a/src/api/sessions/sessions.js b/src/api/sessions/sessions.js index 30761413..13725e17 100644 --- a/src/api/sessions/sessions.js +++ b/src/api/sessions/sessions.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post, put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const COLLECT_DATA_PATH = 'collect-data'; @@ -61,6 +62,7 @@ export default class Sessions { * @param {string} id Sessions id. * @param {string} channel Type of channnel. * @return {Promise} A promise to the sessions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id, channel) { try { @@ -70,7 +72,7 @@ export default class Sessions { const response = await get( this.config.httpClient, - `${this.config.host}/${SESSIONS_PATH}/${id}`, + `${this.config.host}/${SESSIONS_PATH}/${encodePathSegment(id, 'id')}`, config, this.config.sk ); @@ -87,12 +89,13 @@ export default class Sessions { * @param {string} id Sessions id. * @param {Object} body Sessions request body. * @return {Promise} A promise to the sessions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async update(id, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${SESSIONS_PATH}/${id}/${COLLECT_DATA_PATH}`, + `${this.config.host}/${SESSIONS_PATH}/${encodePathSegment(id, 'id')}/${COLLECT_DATA_PATH}`, this.config, this.config.sk, body @@ -110,12 +113,13 @@ export default class Sessions { * @memberof Sessions * @param {string} id Sessions id. * @return {Promise} A promise to the sessions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async complete(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${SESSIONS_PATH}/${id}/${COMPLETE_PATH}`, + `${this.config.host}/${SESSIONS_PATH}/${encodePathSegment(id, 'id')}/${COMPLETE_PATH}`, this.config, this.config.sk ); @@ -133,6 +137,7 @@ export default class Sessions { * @param {string} id Sessions id. * @param {string} threeDsMethodCompletion 3DS Method completion indicator * @return {Promise} A promise to the sessions response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async update3DSMethodCompletionIndicator(id, threeDsMethodCompletion) { try { @@ -142,7 +147,7 @@ export default class Sessions { const response = await put( this.config.httpClient, - `${this.config.host}/${SESSIONS_PATH}/${id}/${ISSUER_FINGERPRINT_PATH}`, + `${this.config.host}/${SESSIONS_PATH}/${encodePathSegment(id, 'id')}/${ISSUER_FINGERPRINT_PATH}`, this.config, this.config.sk, body diff --git a/src/api/tokens/tokens.js b/src/api/tokens/tokens.js index e4df3794..7f981bd9 100644 --- a/src/api/tokens/tokens.js +++ b/src/api/tokens/tokens.js @@ -1,6 +1,7 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; import { setTokenType } from '../../services/validation.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const METADATA_PATH = 'metadata'; @@ -47,12 +48,13 @@ export default class Tokens { * @memberof Tokens * @param {string} tokenId The token id (e.g., "tok_..."). * @return {Promise} A promise to the token metadata response. + * @throws {ValueError} If tokenId is undefined, empty, "." or "..". */ async getTokenMetadata(tokenId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${TOKENS_PATH}/${tokenId}/${METADATA_PATH}`, + `${this.config.host}/${TOKENS_PATH}/${encodePathSegment(tokenId, 'tokenId')}/${METADATA_PATH}`, this.config, this.config.sk ); diff --git a/src/api/transfers/transfers.js b/src/api/transfers/transfers.js index 933a66a5..ad9a1a49 100644 --- a/src/api/transfers/transfers.js +++ b/src/api/transfers/transfers.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { get, post } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; /** * Class dealing with the /transfers endpoint @@ -44,10 +45,11 @@ export default class Transfers { * @memberof Transfers * @param {string} id tra_XXX The transfer identifier. * @return {Promise} A promise to the transfer response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async retrieve(id) { try { - const url = `${this.config.transfersUrl}/${id}`; + const url = `${this.config.transfersUrl}/${encodePathSegment(id, 'id')}`; const response = await get( this.config.httpClient, diff --git a/src/api/webhooks/webhooks.js b/src/api/webhooks/webhooks.js index 27ea92fd..4fd25206 100644 --- a/src/api/webhooks/webhooks.js +++ b/src/api/webhooks/webhooks.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { _delete, get, patch, post, put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const WEBHOOKS_PATH = 'webhooks'; @@ -64,12 +65,13 @@ export default class Webhooks { * @memberof Webhooks * @param {string} id The webhook identifier. * @return {Promise} A promise to the retrieve webhook response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async retrieveWebhook(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${WEBHOOKS_PATH}/${id}`, + `${this.config.host}/${WEBHOOKS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -86,12 +88,13 @@ export default class Webhooks { * @param {string} id The webhook identifier. * @param {Object} body Webhook update body. * @return {Promise} A promise to the update webhook response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async updateWebhook(id, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${WEBHOOKS_PATH}/${id}`, + `${this.config.host}/${WEBHOOKS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -109,12 +112,13 @@ export default class Webhooks { * @param {string} id The webhook identifier. * @param {Object} body Webhook partial-update body. * @return {Promise} A promise to the update webhook response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async partiallyUpdateWebhook(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${WEBHOOKS_PATH}/${id}`, + `${this.config.host}/${WEBHOOKS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -131,12 +135,13 @@ export default class Webhooks { * @memberof Webhooks * @param {string} id The webhook identifier. * @return {Promise} A promise to the remove webhook response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async removeWebhook(id) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${WEBHOOKS_PATH}/${id}`, + `${this.config.host}/${WEBHOOKS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); diff --git a/src/api/workflows/workflows.js b/src/api/workflows/workflows.js index 078daeb4..e7a7d153 100644 --- a/src/api/workflows/workflows.js +++ b/src/api/workflows/workflows.js @@ -1,5 +1,6 @@ import { determineError } from '../../services/errors.js'; import { _delete, get, patch, post, put } from '../../services/http.js'; +import { encodePathSegment } from '../../services/utils.js'; // Path segments appended to the API base (config.host). const ACTIONS_PATH = 'actions'; @@ -71,12 +72,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id Workflow id. * @return {Promise} A promise to the workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async get(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -93,12 +95,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id Workflow id. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async remove(id) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -115,12 +118,13 @@ export default class Workflows { * @param {string} id Workflow id. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async patch(id, body) { try { const response = await patch( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk, body @@ -143,12 +147,13 @@ export default class Workflows { * @param {string} id Workflow Id. * @param {Object} body Workflows action request body. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async addAction(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}/${ACTIONS_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}/${ACTIONS_PATH}`, this.config, this.config.sk, body @@ -167,12 +172,13 @@ export default class Workflows { * @param {string} workflowActionId Workflow action ID. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If workflowId or workflowActionId is undefined, empty, "." or "..". */ async updateAction(workflowId, workflowActionId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${workflowId}/${ACTIONS_PATH}/${workflowActionId}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${ACTIONS_PATH}/${encodePathSegment(workflowActionId, 'workflowActionId')}`, this.config, this.config.sk, body @@ -190,12 +196,13 @@ export default class Workflows { * @param {string} workflowId Workflow id. * @param {string} workflowActionId Workflow action Id. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If workflowId or workflowActionId is undefined, empty, "." or "..". */ async removeAction(workflowId, workflowActionId) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${workflowId}/${ACTIONS_PATH}/${workflowActionId}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${ACTIONS_PATH}/${encodePathSegment(workflowActionId, 'workflowActionId')}`, this.config, this.config.sk ); @@ -212,12 +219,13 @@ export default class Workflows { * @param {string} id Workflow Id. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async addCondition(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}/${CONDITIONS_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}/${CONDITIONS_PATH}`, this.config, this.config.sk, body @@ -236,12 +244,13 @@ export default class Workflows { * @param {string} workflowConditionId Workflow condition ID. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If workflowId or workflowConditionId is undefined, empty, "." or "..". */ async updateCondition(workflowId, workflowConditionId, body) { try { const response = await put( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${workflowId}/${CONDITIONS_PATH}/${workflowConditionId}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${CONDITIONS_PATH}/${encodePathSegment(workflowConditionId, 'workflowConditionId')}`, this.config, this.config.sk, body @@ -259,12 +268,13 @@ export default class Workflows { * @param {string} workflowId Workflow id. * @param {string} workflowConditionId Workflow condition Id. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If workflowId or workflowConditionId is undefined, empty, "." or "..". */ async removeCondition(workflowId, workflowConditionId) { try { const response = await _delete( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${workflowId}/${CONDITIONS_PATH}/${workflowConditionId}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${CONDITIONS_PATH}/${encodePathSegment(workflowConditionId, 'workflowConditionId')}`, this.config, this.config.sk ); @@ -281,12 +291,13 @@ export default class Workflows { * @param {string} id Workflow id. * @param {Object} body Event types for which the workflow will execute. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async test(id, body) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${id}/${TEST_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${encodePathSegment(id, 'id')}/${TEST_PATH}`, this.config, this.config.sk, body @@ -323,12 +334,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id Event ID. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getEvent(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${id}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -345,12 +357,13 @@ export default class Workflows { * @param {string} eventId Event ID. * @param {string} workflowActionId Workflow Action ID. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If eventId or workflowActionId is undefined, empty, "." or "..". */ async getActionInvocations(eventId, workflowActionId) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${eventId}/${ACTIONS_PATH}/${workflowActionId}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${encodePathSegment(eventId, 'eventId')}/${ACTIONS_PATH}/${encodePathSegment(workflowActionId, 'workflowActionId')}`, this.config, this.config.sk ); @@ -366,12 +379,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id Event ID. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async reflowByEvent(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${id}/${REFLOW_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${encodePathSegment(id, 'id')}/${REFLOW_PATH}`, this.config, this.config.sk ); @@ -390,12 +404,13 @@ export default class Workflows { * @param {string} eventId Event ID. * @param {string} workflowId Workflow ID. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If eventId or workflowId is undefined, empty, "." or "..". */ async reflowByEventAndWorkflow(eventId, workflowId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${eventId}/${WORKFLOW_PATH}/${workflowId}/${REFLOW_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${encodePathSegment(eventId, 'eventId')}/${WORKFLOW_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${REFLOW_PATH}`, this.config, this.config.sk ); @@ -463,12 +478,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id The event identifier. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async getSubjectEvents(id) { try { const response = await get( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${id}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${encodePathSegment(id, 'id')}`, this.config, this.config.sk ); @@ -484,12 +500,13 @@ export default class Workflows { * @memberof Workflows * @param {string} id The subject identifier (for example, a payment ID or a dispute ID). * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If id is undefined, empty, "." or "..". */ async reflowBySubject(id) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${id}/${REFLOW_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${encodePathSegment(id, 'id')}/${REFLOW_PATH}`, this.config, this.config.sk ); @@ -506,12 +523,13 @@ export default class Workflows { * @param {string} subjectId Subject ID. * @param {string} workflowId Workflow ID. * @return {Promise} A promise to the Workflows response. + * @throws {ValueError} If subjectId or workflowId is undefined, empty, "." or "..". */ async reflowBySubjectAndWorkflow(subjectId, workflowId) { try { const response = await post( this.config.httpClient, - `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${subjectId}/${WORKFLOW_PATH}/${workflowId}/${REFLOW_PATH}`, + `${this.config.host}/${WORKFLOWS_PATH}/${EVENTS_PATH}/${SUBJECT_PATH}/${encodePathSegment(subjectId, 'subjectId')}/${WORKFLOW_PATH}/${encodePathSegment(workflowId, 'workflowId')}/${REFLOW_PATH}`, this.config, this.config.sk ); diff --git a/src/services/utils.js b/src/services/utils.js index 02ae8dad..6b9a28e8 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -1,3 +1,5 @@ +import { ValueError } from './errors.js'; + /** * Append params to a path as a query string. * @@ -25,3 +27,25 @@ export const buildQueryParams = (path, params) => { return queryString ? `${path}?${queryString}` : path; }; + +/** + * Encode a caller-supplied value as a single path segment. + * + * The value is converted to a string and encoded with encodeURIComponent, so characters such as + * "/", "?", "#", "%" and "\" are percent-encoded. Values that encoding leaves unchanged and that + * are not valid segments ("." and "..") are rejected, as are undefined and empty values. + * + * @param {*} value The value to place in the path, such as an id. + * @param {string} name The parameter name, used in the error message. + * @return {string} The encoded segment. + * @throws {ValueError} If the value is undefined, empty, "." or "..". + */ +export const encodePathSegment = (value, name) => { + const segment = value === undefined ? '' : String(value); + + if (segment === '' || segment === '.' || segment === '..') { + throw new ValueError(`Invalid ${name}: must not be undefined, empty, "." or "..".`); + } + + return encodeURIComponent(segment); +}; diff --git a/test/balances/balances-balances-at-unit.js b/test/balances/balances-balances-at-unit.js index 1d3e407a..6bbb20a4 100644 --- a/test/balances/balances-balances-at-unit.js +++ b/test/balances/balances-balances-at-unit.js @@ -24,7 +24,8 @@ describe('Balances.retrieve — balancesAt query support', () => { // Swagger declares the query param name as `balancesAt` (camelCase). expect(capturedUrl).to.include('balancesAt=2026-01-01T00%3A00%3A00Z'); - expect(capturedUrl).to.include('query=currency:EUR'); + // The colon is percent-encoded like any other query value; Balances reads both forms the same. + expect(capturedUrl).to.include('query=currency%3AEUR'); }); it('omits balancesAt when not provided', async () => { diff --git a/test/balances/balances-unit.js b/test/balances/balances-unit.js index 509a6cb5..b6fc1915 100644 --- a/test/balances/balances-unit.js +++ b/test/balances/balances-unit.js @@ -230,3 +230,56 @@ describe('Balances', () => { expect(balance.data[0]).to.have.property('balances'); }); }); + +// Query values are percent-encoded by the SDK. +describe('Balances - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://balances.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'USD', 'USD'], + ['encodes & and =', 'USD&b=c', 'USD%26b%3Dc'], + ['encodes #', 'USD#x', 'USD%23x'], + ].forEach(([title, value, encoded]) => { + it(`retrieve with a currency ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.balances.retrieve('ent_1', value); + expect(capturedUrl).to.equal(`/balances/ent_1?query=currency%3A${encoded}`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`retrieve with a query ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.balances.retrieve('ent_1', { query: value }); + expect(capturedUrl).to.equal(`/balances/ent_1?query=${encoded}`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`retrieve with withCurrencyAccountId ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.balances.retrieve('ent_1', { withCurrencyAccountId: value }); + expect(capturedUrl).to.equal(`/balances/ent_1?withCurrencyAccountId=${encoded}`); + }); + }); +}); diff --git a/test/disputes/disputes-unit.js b/test/disputes/disputes-unit.js index 406fc55f..926fb4d7 100644 --- a/test/disputes/disputes-unit.js +++ b/test/disputes/disputes-unit.js @@ -820,3 +820,32 @@ describe('Disputes', () => { }); }); + +// Query values are percent-encoded by the SDK. +describe('Disputes - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`get ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.disputes.get({ payment_reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/disputes?payment_reference=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/events/events.js b/test/events/events.js index 67f564a3..9640949f 100644 --- a/test/events/events.js +++ b/test/events/events.js @@ -475,3 +475,44 @@ describe('Events', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Events - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`retrieveEventTypes ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.events.retrieveEventTypes(value); + expect(capturedUrl).to.equal(`/event-types?version=${encoded}`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`retrieveEvents ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.events.retrieveEvents({ payment_id: value, limit: 10 }); + expect(capturedUrl).to.equal(`/events?payment_id=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/financial/financial.js b/test/financial/financial.js index 0b1ccbaf..61acd2c8 100644 --- a/test/financial/financial.js +++ b/test/financial/financial.js @@ -89,4 +89,33 @@ describe('Financial', () => { expect(err).to.be.instanceOf(AuthenticationError); } }); -}); \ No newline at end of file +}); + +// Query values are percent-encoded by the SDK. +describe('Financial - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`query ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.financial.query({ payment_id: value, limit: 10 }); + expect(capturedUrl).to.equal(`/financial-actions?payment_id=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/payment-methods/payment-methods-unit.js b/test/payment-methods/payment-methods-unit.js index 671ef77a..8c6bbd87 100644 --- a/test/payment-methods/payment-methods-unit.js +++ b/test/payment-methods/payment-methods-unit.js @@ -47,3 +47,32 @@ describe('Payment Methods', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Payment methods - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPaymentMethods ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.paymentMethods.getPaymentMethods(value); + expect(capturedUrl).to.equal(`/payment-methods?processing_channel_id=${encoded}`); + }); + }); +}); diff --git a/test/payments/getPaymentList.js b/test/payments/getPaymentList.js index 8330a847..0c40b68b 100644 --- a/test/payments/getPaymentList.js +++ b/test/payments/getPaymentList.js @@ -98,3 +98,32 @@ describe('Get payment list', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Payments - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPaymentList ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.payments.getPaymentList({ reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/payments?reference=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/platforms/payment-instruments/payment-instruments-unit.js b/test/platforms/payment-instruments/payment-instruments-unit.js index f7aaf35c..817b2570 100644 --- a/test/platforms/payment-instruments/payment-instruments-unit.js +++ b/test/platforms/payment-instruments/payment-instruments-unit.js @@ -513,3 +513,43 @@ describe('Platforms - Payment Instruments', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Platforms - Payment Instruments - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.access.sandbox.checkout.com').post('/connect/token').reply(201, { + access_token: '1234', + expires_in: 3600, + token_type: 'Bearer', + scope: 'accounts', + }); + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`queryPaymentInstruments ${title}`, async () => { + const cko = new Checkout(platforms_secret, { + client: platforms_ack, + scope: ['accounts'], + environment: 'sandbox', + subdomain: '123456789', + }); + await cko.platforms.queryPaymentInstruments('ent_1', value); + expect(capturedUrl).to.equal(`/accounts/entities/ent_1/payment-instruments?status=${encoded}`); + }); + }); +}); diff --git a/test/reconciliation/reconciliation-unit.js b/test/reconciliation/reconciliation-unit.js index 36e68a3c..3815df7a 100644 --- a/test/reconciliation/reconciliation-unit.js +++ b/test/reconciliation/reconciliation-unit.js @@ -574,3 +574,80 @@ describe('Reconciliation', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Reconciliation - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPayments ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reconciliation.getPayments({ reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reporting/payments?reference=${encoded}&limit=10`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPaymentsCsv ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reconciliation.getPaymentsCsv({ reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reporting/payments/download?reference=${encoded}&limit=10`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getStatements ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reconciliation.getStatements({ payout_id: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reporting/statements?payout_id=${encoded}&limit=10`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPaymentsActions ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reconciliation.getPaymentsActions({ reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reporting/actions?reference=${encoded}&limit=10`); + }); + }); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getPaymentsActionsCsv ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reconciliation.getPaymentsActionsCsv({ reference: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reporting/actions/download?reference=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/reports/reports-unit.js b/test/reports/reports-unit.js index 3be26704..94176597 100644 --- a/test/reports/reports-unit.js +++ b/test/reports/reports-unit.js @@ -164,3 +164,32 @@ describe('Reports', () => { } }); }); + +// Query values are percent-encoded by the SDK. +describe('Reports - query values', () => { + let capturedUrl; + + beforeEach(() => { + capturedUrl = undefined; + nock('https://123456789.api.sandbox.checkout.com') + .get(/.*/) + .reply(function (uri) { + capturedUrl = uri; + return [200, {}]; + }); + }); + + afterEach(() => nock.cleanAll()); + + [ + ['sends a plain value unchanged', 'ORD-123', 'ORD-123'], + ['encodes & and =', 'a&b=c', 'a%26b%3Dc'], + ['encodes #', 'INV#42', 'INV%2342'], + ].forEach(([title, value, encoded]) => { + it(`getAllReports ${title}`, async () => { + const cko = new Checkout(SK, { subdomain: '123456789' }); + await cko.reports.getAllReports({ entity_id: value, limit: 10 }); + expect(capturedUrl).to.equal(`/reports?entity_id=${encoded}&limit=10`); + }); + }); +}); diff --git a/test/services/path-segments-unit.js b/test/services/path-segments-unit.js new file mode 100644 index 00000000..55558a59 --- /dev/null +++ b/test/services/path-segments-unit.js @@ -0,0 +1,338 @@ +import { expect } from 'chai'; +import nock from 'nock'; +import { Checkout } from '../../src/index.js'; +import { ValueError } from '../../src/services/errors.js'; +import ApmSpecificBaloto from '../../src/api/apm-specific/baloto.js'; +import ApmSpecificBoleto from '../../src/api/apm-specific/boleto.js'; +import ApmSpecificFawry from '../../src/api/apm-specific/fawry.js'; +import ApmSpecificKlarna from '../../src/api/apm-specific/klarna.js'; +import ApmSpecificOxxo from '../../src/api/apm-specific/oxxo.js'; +import ApmSpecificPagofacil from '../../src/api/apm-specific/pagofacil.js'; +import ApmSpecificRapipago from '../../src/api/apm-specific/rapipago.js'; +import ApmSpecificSepa from '../../src/api/apm-specific/sepa.js'; +import BalancesBalances from '../../src/api/balances/balances.js'; +import ComplianceRequestsComplianceRequests from '../../src/api/compliance-requests/compliance-requests.js'; +import CustomersCustomers from '../../src/api/customers/customers.js'; +import DisputesDisputes from '../../src/api/disputes/disputes.js'; +import EventsEvents from '../../src/api/events/events.js'; +import FilesFiles from '../../src/api/files/files.js'; +import ForwardForward from '../../src/api/forward/forward.js'; +import GooglePayGooglePay from '../../src/api/google-pay/google-pay.js'; +import HostedPaymentsHostedPayments from '../../src/api/hosted-payments/hosted-payments.js'; +import IdentitiesAddressDocumentVerifications from '../../src/api/identities/address-document-verifications.js'; +import IdentitiesAmlScreenings from '../../src/api/identities/aml-screenings.js'; +import IdentitiesApplicants from '../../src/api/identities/applicants.js'; +import IdentitiesFaceAuthentications from '../../src/api/identities/face-authentications.js'; +import IdentitiesIdDocumentVerifications from '../../src/api/identities/id-document-verifications.js'; +import IdentitiesIdentityVerifications from '../../src/api/identities/identity-verifications.js'; +import InstrumentsInstruments from '../../src/api/instruments/instruments.js'; +import InventoryInventory from '../../src/api/inventory/inventory.js'; +import IssuingCardholders from '../../src/api/issuing/cardholders.js'; +import IssuingCards from '../../src/api/issuing/cards.js'; +import IssuingControlGroups from '../../src/api/issuing/control-groups.js'; +import IssuingControlProfiles from '../../src/api/issuing/control-profiles.js'; +import IssuingControls from '../../src/api/issuing/controls.js'; +import IssuingDigitalCards from '../../src/api/issuing/digital-cards.js'; +import IssuingDisputes from '../../src/api/issuing/disputes.js'; +import IssuingSimulate from '../../src/api/issuing/simulate.js'; +import IssuingTransactions from '../../src/api/issuing/transactions.js'; +import NetworkTokensNetworkTokens from '../../src/api/network-tokens/network-tokens.js'; +import OnboardingSimulatorOnboardingSimulator from '../../src/api/onboarding-simulator/onboarding-simulator.js'; +import PaymentContextsPaymentContexts from '../../src/api/payment-contexts/payment-contexts.js'; +import PaymentSessionsPaymentSessions from '../../src/api/payment-sessions/payment-sessions.js'; +import PaymentSetupsPaymentSetups from '../../src/api/payment-setups/payment-setups.js'; +import PaymentsLinksPaymentsLinks from '../../src/api/payments-links/payments-links.js'; +import PaymentsPayments from '../../src/api/payments/payments.js'; +import PlatformsEntityRequirements from '../../src/api/platforms/entity-requirements.js'; +import PlatformsFiles from '../../src/api/platforms/files.js'; +import PlatformsPaymentInstruments from '../../src/api/platforms/payment-instruments.js'; +import PlatformsPayoutSchedules from '../../src/api/platforms/payout-schedules.js'; +import PlatformsReserveRules from '../../src/api/platforms/reserve-rules.js'; +import PlatformsSubentity from '../../src/api/platforms/subentity.js'; +import ReconciliationReconciliation from '../../src/api/reconciliation/reconciliation.js'; +import ReportsReports from '../../src/api/reports/reports.js'; +import SessionsSessions from '../../src/api/sessions/sessions.js'; +import TokensTokens from '../../src/api/tokens/tokens.js'; +import TransfersTransfers from '../../src/api/transfers/transfers.js'; +import WebhooksWebhooks from '../../src/api/webhooks/webhooks.js'; +import WorkflowsWorkflows from '../../src/api/workflows/workflows.js'; + +const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; +const VALID = 'abc_123'; + +// Values with reserved characters, which the SDK percent-encodes. +const RESERVED = ['../x', '%2e%2e/x', '..\\x', 'a?b', 'a#b']; + +// encodeURIComponent leaves "." and ".." unchanged, so these are rejected before any request is sent. +const REJECTED = ['..', '.', '', undefined]; + +// One row per SDK method that puts a caller value in the request path: the endpoint class, the +// method, the arguments with every path value set to v, and the path sent for a valid id. +const METHODS = [ + [ApmSpecificBaloto, 'succeed', (v) => [v], '/apms/baloto/payments/abc_123/succeed'], + [ApmSpecificBaloto, 'expire', (v) => [v], '/apms/baloto/payments/abc_123/expire'], + [ApmSpecificBoleto, 'succeed', (v) => [v], '/apms/boleto/payments/abc_123/succeed'], + [ApmSpecificBoleto, 'expire', (v) => [v], '/apms/boleto/payments/abc_123/expire'], + [ApmSpecificFawry, 'approve', (v) => [v], '/fawry/payments/abc_123/approval'], + [ApmSpecificFawry, 'cancel', (v) => [v], '/fawry/payments/abc_123/cancellation'], + [ApmSpecificKlarna, 'getSession', (v) => [v], '/klarna-external/credit-sessions/abc_123'], + [ApmSpecificKlarna, 'capture', (v) => [v, {}], '/klarna-external/orders/abc_123/captures'], + [ApmSpecificKlarna, 'void', (v) => [v, {}], '/klarna-external/orders/abc_123/voids'], + [ApmSpecificOxxo, 'succeed', (v) => [v], '/apms/oxxo/payments/abc_123/succeed'], + [ApmSpecificOxxo, 'expire', (v) => [v], '/apms/oxxo/payments/abc_123/expire'], + [ApmSpecificPagofacil, 'succeed', (v) => [v], '/apms/pagofacil/payments/abc_123/succeed'], + [ApmSpecificPagofacil, 'expire', (v) => [v], '/apms/pagofacil/payments/abc_123/expire'], + [ApmSpecificRapipago, 'succeed', (v) => [v], '/apms/rapipago/payments/abc_123/succeed'], + [ApmSpecificRapipago, 'expire', (v) => [v], '/apms/rapipago/payments/abc_123/expire'], + [ApmSpecificSepa, 'getMandate', (v) => [v], '/sepa-external/mandates/abc_123'], + [ApmSpecificSepa, 'cancelMandate', (v) => [v], '/sepa-external/mandates/abc_123/cancel'], + [ApmSpecificSepa, 'getPPROMandate', (v) => [v], '/ppro/sepa-external/mandates/abc_123'], + [ApmSpecificSepa, 'cancelPPROMandate', (v) => [v], '/ppro/sepa-external/mandates/abc_123/cancel'], + [BalancesBalances, 'retrieve', (v) => [v, {}], '/balances/abc_123'], + [BalancesBalances, 'retrieveTopUpInstructions', (v) => [v, v], '/entities/abc_123/currency-accounts/abc_123/top-up-instructions'], + [ComplianceRequestsComplianceRequests, 'getComplianceRequest', (v) => [v], '/compliance-requests/abc_123'], + [ComplianceRequestsComplianceRequests, 'respondToComplianceRequest', (v) => [v, {}], '/compliance-requests/abc_123'], + [CustomersCustomers, 'get', (v) => [v], '/customers/abc_123'], + [CustomersCustomers, 'update', (v) => [v, {}], '/customers/abc_123'], + [CustomersCustomers, 'delete', (v) => [v], '/customers/abc_123'], + [DisputesDisputes, 'getDetails', (v) => [v], '/disputes/abc_123'], + [DisputesDisputes, 'accept', (v) => [v], '/disputes/abc_123/accept'], + [DisputesDisputes, 'provideEvidence', (v) => [v, {}], '/disputes/abc_123/evidence'], + [DisputesDisputes, 'getEvidence', (v) => [v], '/disputes/abc_123/evidence'], + [DisputesDisputes, 'submit', (v) => [v], '/disputes/abc_123/evidence'], + [DisputesDisputes, 'getCompiledSubmittedEvidence', (v) => [v], '/disputes/abc_123/evidence/submitted'], + [DisputesDisputes, 'getDisputeSchemeFiles', (v) => [v], '/disputes/abc_123/schemefiles'], + [DisputesDisputes, 'submitArbitrationEvidence', (v) => [v], '/disputes/abc_123/evidence/arbitration'], + [DisputesDisputes, 'getCompiledSubmittedArbitrationEvidence', (v) => [v], '/disputes/abc_123/evidence/arbitration/submitted'], + [EventsEvents, 'retrieveEvent', (v) => [v], '/events/abc_123'], + [EventsEvents, 'retrieveEventNotification', (v) => [{ eventId: v, notificationId: v }], '/events/abc_123/notifications/abc_123'], + [EventsEvents, 'retry', (v) => [{ eventId: v, webhookId: v }], '/events/abc_123/webhooks/abc_123/retry'], + [EventsEvents, 'retryAll', (v) => [v], '/events/abc_123/webhooks/retry'], + [FilesFiles, 'getFile', (v) => [v], '/files/abc_123'], + [ForwardForward, 'get', (v) => [v], '/forward/abc_123'], + [ForwardForward, 'updateSecret', (v) => [v, {}], '/secrets/abc_123'], + [ForwardForward, 'deleteSecret', (v) => [v], '/secrets/abc_123'], + [GooglePayGooglePay, 'registerDomain', (v) => [v, {}], '/googlepay/enrollments/abc_123/domain'], + [GooglePayGooglePay, 'getRegisteredDomains', (v) => [v], '/googlepay/enrollments/abc_123/domains'], + [GooglePayGooglePay, 'getEnrollmentState', (v) => [v], '/googlepay/enrollments/abc_123/state'], + [HostedPaymentsHostedPayments, 'get', (v) => [v], '/hosted-payments/abc_123'], + [IdentitiesAddressDocumentVerifications, 'getAddressDocumentVerification', (v) => [v], '/address-document-verifications/abc_123'], + [IdentitiesAddressDocumentVerifications, 'listAttempts', (v) => [v, {}], '/address-document-verifications/abc_123/attempts'], + [IdentitiesAddressDocumentVerifications, 'getAttempt', (v) => [v, v], '/address-document-verifications/abc_123/attempts/abc_123'], + [IdentitiesAddressDocumentVerifications, 'anonymizeAddressDocumentVerification', (v) => [v], '/address-document-verifications/abc_123/anonymize'], + [IdentitiesAddressDocumentVerifications, 'createAttempt', (v) => [v, {}], '/address-document-verifications/abc_123/attempts'], + [IdentitiesAddressDocumentVerifications, 'getPDFReport', (v) => [v], '/address-document-verifications/abc_123/pdf-report'], + [IdentitiesAddressDocumentVerifications, 'getAttemptAssets', (v) => [v, v, {}], '/address-document-verifications/abc_123/attempts/abc_123/assets'], + [IdentitiesAmlScreenings, 'getAMLScreening', (v) => [v], '/aml-verifications/abc_123'], + [IdentitiesApplicants, 'getApplicant', (v) => [v], '/applicants/abc_123'], + [IdentitiesApplicants, 'updateApplicant', (v) => [v, {}], '/applicants/abc_123'], + [IdentitiesApplicants, 'anonymizeApplicant', (v) => [v], '/applicants/abc_123/anonymize'], + [IdentitiesFaceAuthentications, 'getFaceAuthentication', (v) => [v], '/face-authentications/abc_123'], + [IdentitiesFaceAuthentications, 'listAttempts', (v) => [v, {}], '/face-authentications/abc_123/attempts'], + [IdentitiesFaceAuthentications, 'getAttempt', (v) => [v, v], '/face-authentications/abc_123/attempts/abc_123'], + [IdentitiesFaceAuthentications, 'getAttemptAssets', (v) => [v, v, {}], '/face-authentications/abc_123/attempts/abc_123/assets'], + [IdentitiesFaceAuthentications, 'createAttempt', (v) => [v, {}], '/face-authentications/abc_123/attempts'], + [IdentitiesFaceAuthentications, 'anonymizeFaceAuthentication', (v) => [v], '/face-authentications/abc_123/anonymize'], + [IdentitiesIdDocumentVerifications, 'getIDDocumentVerification', (v) => [v], '/id-document-verifications/abc_123'], + [IdentitiesIdDocumentVerifications, 'listAttempts', (v) => [v, {}], '/id-document-verifications/abc_123/attempts'], + [IdentitiesIdDocumentVerifications, 'getAttempt', (v) => [v, v], '/id-document-verifications/abc_123/attempts/abc_123'], + [IdentitiesIdDocumentVerifications, 'anonymizeIDDocumentVerification', (v) => [v], '/id-document-verifications/abc_123/anonymize'], + [IdentitiesIdDocumentVerifications, 'createAttempt', (v) => [v, {}], '/id-document-verifications/abc_123/attempts'], + [IdentitiesIdDocumentVerifications, 'getPDFReport', (v) => [v], '/id-document-verifications/abc_123/pdf-report'], + [IdentitiesIdDocumentVerifications, 'getAttemptAssets', (v) => [v, v, {}], '/id-document-verifications/abc_123/attempts/abc_123/assets'], + [IdentitiesIdentityVerifications, 'getIdentityVerification', (v) => [v], '/identity-verifications/abc_123'], + [IdentitiesIdentityVerifications, 'anonymizeIdentityVerification', (v) => [v], '/identity-verifications/abc_123/anonymize'], + [IdentitiesIdentityVerifications, 'createAttempt', (v) => [v, {}], '/identity-verifications/abc_123/attempts'], + [IdentitiesIdentityVerifications, 'listAttempts', (v) => [v, {}], '/identity-verifications/abc_123/attempts'], + [IdentitiesIdentityVerifications, 'getAttempt', (v) => [v, v], '/identity-verifications/abc_123/attempts/abc_123'], + [IdentitiesIdentityVerifications, 'getAttemptAssets', (v) => [v, v, {}], '/identity-verifications/abc_123/attempts/abc_123/assets'], + [IdentitiesIdentityVerifications, 'getPDFReport', (v) => [v], '/identity-verifications/abc_123/pdf-report'], + [InstrumentsInstruments, 'get', (v) => [v], '/instruments/abc_123'], + [InstrumentsInstruments, 'update', (v) => [v, {}], '/instruments/abc_123'], + [InstrumentsInstruments, 'delete', (v) => [v], '/instruments/abc_123'], + [InstrumentsInstruments, 'revoke', (v) => [v], '/instruments/abc_123/revoke'], + [InstrumentsInstruments, 'getBankAccountFieldFormatting', (v) => [v, v, {}], '/validation/bank-accounts/abc_123/abc_123'], + [InventoryInventory, 'getInventoryReservation', (v) => [v], '/inventory/reservations/abc_123'], + [InventoryInventory, 'commitInventoryReservation', (v) => [v], '/inventory/reservations/abc_123/commit'], + [InventoryInventory, 'releaseInventoryReservation', (v) => [v], '/inventory/reservations/abc_123/release'], + [InventoryInventory, 'getInventoryLevels', (v) => [v, {}], '/inventory/abc_123'], + [InventoryInventory, 'setInventoryLevels', (v) => [v, {}], '/inventory/abc_123'], + [InventoryInventory, 'getInventoryProduct', (v) => [v], '/inventory/abc_123/product'], + [InventoryInventory, 'setInventoryProduct', (v) => [v, {}], '/inventory/abc_123/product'], + [InventoryInventory, 'deleteInventoryProduct', (v) => [v], '/inventory/abc_123/product'], + [IssuingCardholders, 'getCardholder', (v) => [v], '/issuing/cardholders/abc_123'], + [IssuingCardholders, 'updateCardholder', (v) => [v, {}], '/issuing/cardholders/abc_123'], + [IssuingCardholders, 'getCardholderCards', (v) => [v], '/issuing/cardholders/abc_123/cards'], + [IssuingCards, 'getCardDetails', (v) => [v], '/issuing/cards/abc_123'], + [IssuingCards, 'updateCard', (v) => [v, {}, {}], '/issuing/cards/abc_123'], + [IssuingCards, 'enrollThreeDS', (v) => [v, {}], '/issuing/cards/abc_123/3ds-enrollment'], + [IssuingCards, 'updateThreeDS', (v) => [v, {}], '/issuing/cards/abc_123/3ds-enrollment'], + [IssuingCards, 'getThreeDSDetails', (v) => [v], '/issuing/cards/abc_123/3ds-enrollment'], + [IssuingCards, 'activateCard', (v) => [v], '/issuing/cards/abc_123/activate'], + [IssuingCards, 'getCardCredentials', (v) => [v, {}], '/issuing/cards/abc_123/credentials'], + [IssuingCards, 'renewCard', (v) => [v, {}], '/issuing/cards/abc_123/renew'], + [IssuingCards, 'revokeCard', (v) => [v, {}], '/issuing/cards/abc_123/revoke'], + [IssuingCards, 'suspendCard', (v) => [v, {}], '/issuing/cards/abc_123/suspend'], + [IssuingControlGroups, 'getControlGroup', (v) => [v], '/issuing/controls/control-groups/abc_123'], + [IssuingControlGroups, 'deleteControlGroup', (v) => [v], '/issuing/controls/control-groups/abc_123'], + [IssuingControlProfiles, 'getControlProfile', (v) => [v], '/issuing/controls/control-profiles/abc_123'], + [IssuingControlProfiles, 'updateControlProfile', (v) => [v, {}], '/issuing/controls/control-profiles/abc_123'], + [IssuingControlProfiles, 'deleteControlProfile', (v) => [v], '/issuing/controls/control-profiles/abc_123'], + [IssuingControlProfiles, 'addTargetToControlProfile', (v) => [v, v], '/issuing/controls/control-profiles/abc_123/add/abc_123'], + [IssuingControlProfiles, 'removeTargetFromControlProfile', (v) => [v, v], '/issuing/controls/control-profiles/abc_123/remove/abc_123'], + [IssuingControls, 'getCardControlDetails', (v) => [v], '/issuing/controls/abc_123'], + [IssuingControls, 'updateCardControl', (v) => [v, {}], '/issuing/controls/abc_123'], + [IssuingControls, 'deleteCardControl', (v) => [v], '/issuing/controls/abc_123'], + [IssuingDigitalCards, 'getDigitalCard', (v) => [v], '/issuing/digital-cards/abc_123'], + [IssuingDisputes, 'getDispute', (v) => [v], '/issuing/disputes/abc_123'], + [IssuingDisputes, 'cancelDispute', (v) => [v], '/issuing/disputes/abc_123/cancel'], + [IssuingDisputes, 'escalateDispute', (v) => [v, {}], '/issuing/disputes/abc_123/escalate'], + [IssuingDisputes, 'amendDispute', (v) => [v, {}], '/issuing/disputes/abc_123/amend'], + [IssuingDisputes, 'submitDispute', (v) => [v, {}], '/issuing/disputes/abc_123/submit'], + [IssuingSimulate, 'simulateIncrement', (v) => [v, {}], '/issuing/simulate/authorizations/abc_123/authorizations'], + [IssuingSimulate, 'simulateClearing', (v) => [v, {}], '/issuing/simulate/authorizations/abc_123/presentments'], + [IssuingSimulate, 'simulateRefund', (v) => [v, {}], '/issuing/simulate/authorizations/abc_123/refunds'], + [IssuingSimulate, 'simulateReversal', (v) => [v, {}], '/issuing/simulate/authorizations/abc_123/reversals'], + [IssuingTransactions, 'getTransactionById', (v) => [v], '/issuing/transactions/abc_123'], + [NetworkTokensNetworkTokens, 'getNetworkToken', (v) => [v], '/network-tokens/abc_123'], + [NetworkTokensNetworkTokens, 'provisionCryptogram', (v) => [v, {}], '/network-tokens/abc_123/cryptograms'], + [NetworkTokensNetworkTokens, 'deleteNetworkToken', (v) => [v], '/network-tokens/abc_123/delete'], + [OnboardingSimulatorOnboardingSimulator, 'setRequirementsDue', (v) => [v, {}], '/simulate/entities/abc_123/requirements-due'], + [OnboardingSimulatorOnboardingSimulator, 'runScenario', (v) => [v, v], '/simulate/entities/abc_123/scenarios/abc_123'], + [OnboardingSimulatorOnboardingSimulator, 'setEntityStatus', (v) => [v, {}], '/simulate/entities/abc_123/status'], + [PaymentContextsPaymentContexts, 'get', (v) => [v], '/payment-contexts/abc_123'], + [PaymentSessionsPaymentSessions, 'submit', (v) => [v, {}], '/payment-sessions/abc_123/submit'], + [PaymentSetupsPaymentSetups, 'updateAPaymentSetup', (v) => [v, { amount: 1000, currency: 'GBP' }], '/payments/setups/abc_123'], + [PaymentSetupsPaymentSetups, 'getAPaymentSetup', (v) => [v], '/payments/setups/abc_123'], + [PaymentSetupsPaymentSetups, 'confirmAPaymentSetup', (v) => [v, v], '/payments/setups/abc_123/confirm/abc_123'], + [PaymentsLinksPaymentsLinks, 'get', (v) => [v], '/payment-links/abc_123'], + [PaymentsPayments, 'get', (v) => [v], '/payments/abc_123'], + [PaymentsPayments, 'getActions', (v) => [v], '/payments/abc_123/actions'], + [PaymentsPayments, 'increment', (v) => [v, {}, {}], '/payments/abc_123/authorizations'], + [PaymentsPayments, 'cancelScheduledRetry', (v) => [v, {}, {}], '/payments/abc_123/cancellations'], + [PaymentsPayments, 'capture', (v) => [v, {}, {}], '/payments/abc_123/captures'], + [PaymentsPayments, 'refund', (v) => [v, {}, {}], '/payments/abc_123/refunds'], + [PaymentsPayments, 'reverse', (v) => [v, {}, {}], '/payments/abc_123/reversals'], + [PaymentsPayments, 'void', (v) => [v, {}, {}], '/payments/abc_123/voids'], + [PlatformsEntityRequirements, 'getEntityRequirements', (v) => [v], '/accounts/entities/abc_123/requirements'], + [PlatformsEntityRequirements, 'getEntityRequirementDetails', (v) => [v, v], '/accounts/entities/abc_123/requirements/abc_123'], + [PlatformsEntityRequirements, 'updateEntityRequirement', (v) => [v, v, {}], '/accounts/entities/abc_123/requirements/abc_123'], + [PlatformsFiles, 'uploadAFile', (v) => [v, {}], '/entities/abc_123/files'], + [PlatformsFiles, 'retrieveAFile', (v) => [v, v], '/entities/abc_123/files/abc_123'], + [PlatformsPaymentInstruments, 'getPaymentInstrumentDetails', (v) => [v, v], '/accounts/entities/abc_123/payment-instruments/abc_123'], + [PlatformsPaymentInstruments, 'updatePaymentInstrumentDetails', (v) => [v, v, {}], '/accounts/entities/abc_123/payment-instruments/abc_123'], + [PlatformsPaymentInstruments, 'createPaymentInstrument', (v) => [v, {}], '/accounts/entities/abc_123/instruments'], + [PlatformsPaymentInstruments, 'addPaymentInstrument', (v) => [v, {}], '/accounts/entities/abc_123/payment-instruments'], + [PlatformsPaymentInstruments, 'queryPaymentInstruments', (v) => [v], '/accounts/entities/abc_123/payment-instruments'], + [PlatformsPayoutSchedules, 'retrieveSubEntityPayoutSchedule', (v) => [v], '/accounts/entities/abc_123/payout-schedules'], + [PlatformsPayoutSchedules, 'updateSubEntityPayoutSchedule', (v) => [v, {}], '/accounts/entities/abc_123/payout-schedules'], + [PlatformsReserveRules, 'getReserveRuleDetails', (v) => [v, v], '/accounts/entities/abc_123/reserve-rules/abc_123'], + [PlatformsReserveRules, 'updateReserveRule', (v) => [v, v, {}, {}], '/accounts/entities/abc_123/reserve-rules/abc_123'], + [PlatformsReserveRules, 'addReserveRule', (v) => [v, {}], '/accounts/entities/abc_123/reserve-rules'], + [PlatformsReserveRules, 'queryReserveRules', (v) => [v], '/accounts/entities/abc_123/reserve-rules'], + [PlatformsSubentity, 'getSubEntityDetails', (v) => [v], '/accounts/entities/abc_123'], + [PlatformsSubentity, 'updateSubEntityDetails', (v) => [v, {}], '/accounts/entities/abc_123'], + [PlatformsSubentity, 'getSubEntityMembers', (v) => [v], '/accounts/entities/abc_123/members'], + [PlatformsSubentity, 'reinviteSubEntityMember', (v) => [v, v, {}], '/accounts/entities/abc_123/members/abc_123'], + [ReconciliationReconciliation, 'getPayment', (v) => [v], '/reporting/payments/abc_123'], + [ReconciliationReconciliation, 'getStatementCsv', (v) => [v], '/reporting/statements/abc_123/payments/download'], + [ReconciliationReconciliation, 'getPaymentsAction', (v) => [v], '/reporting/payments/actions/abc_123'], + [ReconciliationReconciliation, 'getAction', (v) => [v], '/reporting/actions/abc_123'], + [ReportsReports, 'getReportDetails', (v) => [v], '/reports/abc_123'], + [ReportsReports, 'getReportFile', (v) => [v, v], '/reports/abc_123/files/abc_123'], + [SessionsSessions, 'get', (v) => [v, {}], '/sessions/abc_123'], + [SessionsSessions, 'update', (v) => [v, {}], '/sessions/abc_123/collect-data'], + [SessionsSessions, 'complete', (v) => [v], '/sessions/abc_123/complete'], + [SessionsSessions, 'update3DSMethodCompletionIndicator', (v) => [v, {}], '/sessions/abc_123/issuer-fingerprint'], + [TokensTokens, 'getTokenMetadata', (v) => [v], '/tokens/abc_123/metadata'], + [TransfersTransfers, 'retrieve', (v) => [v], '/transfers/abc_123'], + [WebhooksWebhooks, 'retrieveWebhook', (v) => [v], '/webhooks/abc_123'], + [WebhooksWebhooks, 'updateWebhook', (v) => [v, {}], '/webhooks/abc_123'], + [WebhooksWebhooks, 'partiallyUpdateWebhook', (v) => [v, {}], '/webhooks/abc_123'], + [WebhooksWebhooks, 'removeWebhook', (v) => [v], '/webhooks/abc_123'], + [WorkflowsWorkflows, 'get', (v) => [v], '/workflows/abc_123'], + [WorkflowsWorkflows, 'remove', (v) => [v], '/workflows/abc_123'], + [WorkflowsWorkflows, 'patch', (v) => [v, {}], '/workflows/abc_123'], + [WorkflowsWorkflows, 'addAction', (v) => [v, {}], '/workflows/abc_123/actions'], + [WorkflowsWorkflows, 'updateAction', (v) => [v, v, {}], '/workflows/abc_123/actions/abc_123'], + [WorkflowsWorkflows, 'removeAction', (v) => [v, v], '/workflows/abc_123/actions/abc_123'], + [WorkflowsWorkflows, 'addCondition', (v) => [v, {}], '/workflows/abc_123/conditions'], + [WorkflowsWorkflows, 'updateCondition', (v) => [v, v, {}], '/workflows/abc_123/conditions/abc_123'], + [WorkflowsWorkflows, 'removeCondition', (v) => [v, v], '/workflows/abc_123/conditions/abc_123'], + [WorkflowsWorkflows, 'test', (v) => [v, {}], '/workflows/abc_123/test'], + [WorkflowsWorkflows, 'getEvent', (v) => [v], '/workflows/events/abc_123'], + [WorkflowsWorkflows, 'getActionInvocations', (v) => [v, v], '/workflows/events/abc_123/actions/abc_123'], + [WorkflowsWorkflows, 'reflowByEvent', (v) => [v], '/workflows/events/abc_123/reflow'], + [WorkflowsWorkflows, 'reflowByEventAndWorkflow', (v) => [v, v], '/workflows/events/abc_123/workflow/abc_123/reflow'], + [WorkflowsWorkflows, 'getSubjectEvents', (v) => [v], '/workflows/events/subject/abc_123'], + [WorkflowsWorkflows, 'reflowBySubject', (v) => [v], '/workflows/events/subject/abc_123/reflow'], + [WorkflowsWorkflows, 'reflowBySubjectAndWorkflow', (v) => [v, v], '/workflows/events/subject/abc_123/workflow/abc_123/reflow'], +]; + +describe('Path segments - caller values are encoded', () => { + const { config } = new Checkout(SK, { subdomain: '123456789' }); + let captured; + + beforeEach(() => { + nock.disableNetConnect(); + ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].forEach((verb) => { + nock(/.*/) + .persist() + .intercept(/.*/, verb) + .reply(function (uri) { + captured.push(uri); + return [200, {}]; + }); + }); + }); + + afterEach(() => { + nock.cleanAll(); + nock.enableNetConnect(); + }); + + // Returns the path of the request the method sent. Errors other than ValueError come from + // reading the stubbed response and do not matter here: the request has already gone out. + const send = async (Endpoint, method, args, value) => { + captured = []; + try { + await new Endpoint(config)[method](...args(value)); + } catch (err) { + if (err instanceof ValueError) { + throw err; + } + } + return captured[captured.length - 1]; + }; + + METHODS.forEach(([Endpoint, method, args, validPath]) => { + const label = `${Endpoint.name}.${method}`; + + it(`${label} sends a valid id unchanged`, async () => { + const path = await send(Endpoint, method, args, VALID); + expect(path, label).to.equal(validPath); + }); + + it(`${label} encodes values with reserved characters`, async () => { + for (const value of RESERVED) { + const path = await send(Endpoint, method, args, value); + expect(path, `${label} with ${value}`).to.equal( + validPath.split(VALID).join(encodeURIComponent(value)) + ); + } + }); + + it(`${label} rejects ., .., empty and undefined without sending a request`, async () => { + for (const value of REJECTED) { + let error; + try { + await send(Endpoint, method, args, value); + } catch (err) { + error = err; + } + expect(error, `${label} with ${JSON.stringify(value)}`).to.be.instanceOf(ValueError); + expect(captured, `${label} with ${JSON.stringify(value)}`).to.be.empty; + } + }); + }); +}); diff --git a/test/services/utils.js b/test/services/utils.js index ba08b13c..efe30e17 100644 --- a/test/services/utils.js +++ b/test/services/utils.js @@ -1,5 +1,6 @@ import { expect } from 'chai'; -import { buildQueryParams } from '../../src/services/utils.js'; +import { ValueError } from '../../src/services/errors.js'; +import { buildQueryParams, encodePathSegment } from '../../src/services/utils.js'; describe('Service Utils - buildQueryParams', () => { it('appends the params as a query string', () => { @@ -26,3 +27,36 @@ describe('Service Utils - buildQueryParams', () => { expect(buildQueryParams('u', { 'a b': 'c&d' })).to.equal('u?a%20b=c%26d'); }); }); + +describe('Service Utils - encodePathSegment', () => { + it('keeps a valid id unchanged', () => { + expect(encodePathSegment('pay_abc123', 'id')).to.equal('pay_abc123'); + }); + + it('turns a number into its string form', () => { + expect(encodePathSegment(123, 'id')).to.equal('123'); + }); + + // Values with reserved characters, which the SDK percent-encodes. + [ + ['../x', '..%2Fx'], + ['%2e%2e/x', '%252e%252e%2Fx'], + ['..\\x', '..%5Cx'], + ['a?b', 'a%3Fb'], + ['a#b', 'a%23b'], + ].forEach(([value, expected]) => { + it(`encodes ${value}`, () => { + expect(encodePathSegment(value, 'id')).to.equal(expected); + }); + }); + + // encodeURIComponent leaves "." and ".." unchanged, so they are rejected. + [undefined, '', '.', '..'].forEach((value) => { + it(`rejects ${JSON.stringify(value) ?? 'undefined'}`, () => { + expect(() => encodePathSegment(value, 'id')).to.throw( + ValueError, + 'Invalid id: must not be undefined, empty, "." or "..".' + ); + }); + }); +}); From 8ff1e69321d18847b4baf54703a58d525dc6934c Mon Sep 17 00:00:00 2001 From: rodrigojara-cko Date: Thu, 5 Nov 2026 15:22:08 +0100 Subject: [PATCH 2/2] fix(client): security hardening --- src/api/apm-specific/baloto.js | 4 +-- src/api/apm-specific/boleto.js | 4 +-- src/api/apm-specific/fawry.js | 4 +-- src/api/apm-specific/klarna.js | 6 ++-- src/api/apm-specific/oxxo.js | 4 +-- src/api/apm-specific/pagofacil.js | 4 +-- src/api/apm-specific/rapipago.js | 4 +-- src/api/apm-specific/sepa.js | 8 ++--- src/api/balances/balances.js | 4 +-- .../compliance-requests.js | 4 +-- src/api/customers/customers.js | 6 ++-- src/api/disputes/disputes.js | 18 +++++----- src/api/events/events.js | 8 ++--- src/api/files/files.js | 2 +- src/api/forward/forward.js | 6 ++-- src/api/google-pay/google-pay.js | 6 ++-- src/api/hosted-payments/hosted-payments.js | 2 +- .../address-document-verifications.js | 14 ++++---- src/api/identities/aml-screenings.js | 2 +- src/api/identities/applicants.js | 6 ++-- src/api/identities/face-authentications.js | 12 +++---- .../identities/id-document-verifications.js | 14 ++++---- src/api/identities/identity-verifications.js | 14 ++++---- src/api/instruments/instruments.js | 10 +++--- src/api/inventory/inventory.js | 16 ++++----- src/api/issuing/cardholders.js | 6 ++-- src/api/issuing/cards.js | 20 +++++------ src/api/issuing/control-groups.js | 4 +-- src/api/issuing/control-profiles.js | 10 +++--- src/api/issuing/controls.js | 6 ++-- src/api/issuing/digital-cards.js | 2 +- src/api/issuing/disputes.js | 10 +++--- src/api/issuing/simulate.js | 8 ++--- src/api/issuing/transactions.js | 2 +- src/api/network-tokens/network-tokens.js | 6 ++-- .../onboarding-simulator.js | 6 ++-- src/api/payment-contexts/payment-contexts.js | 2 +- src/api/payment-sessions/payment-sessions.js | 2 +- src/api/payment-setups/payment-setups.js | 6 ++-- src/api/payments-links/payments-links.js | 2 +- src/api/payments/payments.js | 16 ++++----- src/api/platforms/entity-requirements.js | 6 ++-- src/api/platforms/files.js | 4 +-- src/api/platforms/payment-instruments.js | 10 +++--- src/api/platforms/payout-schedules.js | 4 +-- src/api/platforms/reserve-rules.js | 8 ++--- src/api/platforms/subentity.js | 8 ++--- src/api/reconciliation/reconciliation.js | 8 ++--- src/api/reports/reports.js | 4 +-- src/api/sessions/sessions.js | 8 ++--- src/api/tokens/tokens.js | 2 +- src/api/transfers/transfers.js | 2 +- src/api/webhooks/webhooks.js | 8 ++--- src/api/workflows/workflows.js | 34 +++++++++---------- src/services/utils.js | 8 ++--- test/services/path-segments-unit.js | 4 +-- test/services/utils.js | 4 +-- 57 files changed, 206 insertions(+), 206 deletions(-) diff --git a/src/api/apm-specific/baloto.js b/src/api/apm-specific/baloto.js index f1f916f4..1ed9af0c 100644 --- a/src/api/apm-specific/baloto.js +++ b/src/api/apm-specific/baloto.js @@ -28,7 +28,7 @@ export default class Baloto { * @param {string} id Payment id. * @memberof Baloto * @return {Promise} A promise to the Baloto response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async succeed(id) { try { @@ -51,7 +51,7 @@ export default class Baloto { * @param {string} id Payment id. * @memberof Baloto * @return {Promise} A promise to the Baloto response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async expire(id) { try { diff --git a/src/api/apm-specific/boleto.js b/src/api/apm-specific/boleto.js index 4396320e..713eab3a 100644 --- a/src/api/apm-specific/boleto.js +++ b/src/api/apm-specific/boleto.js @@ -28,7 +28,7 @@ export default class Boleto { * @param {string} id Payment id. * @memberof Boleto * @return {Promise} A promise to the Boleto response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async succeed(id) { try { @@ -51,7 +51,7 @@ export default class Boleto { * @param {string} id Payment id. * @memberof Boleto * @return {Promise} A promise to the Boleto response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async expire(id) { try { diff --git a/src/api/apm-specific/fawry.js b/src/api/apm-specific/fawry.js index 775abc4c..73dc3899 100644 --- a/src/api/apm-specific/fawry.js +++ b/src/api/apm-specific/fawry.js @@ -28,7 +28,7 @@ export default class Fawry { * @param {string} reference Reference. * @memberof Fawry * @return {Promise} A promise to the Fawry response. - * @throws {ValueError} If reference is undefined, empty, "." or "..". + * @throws {ValueError} If reference is undefined, null, empty, "." or "..". */ async approve(reference) { try { @@ -51,7 +51,7 @@ export default class Fawry { * @param {string} reference Reference. * @memberof Fawry * @return {Promise} A promise to the Fawry response. - * @throws {ValueError} If reference is undefined, empty, "." or "..". + * @throws {ValueError} If reference is undefined, null, empty, "." or "..". */ async cancel(reference) { try { diff --git a/src/api/apm-specific/klarna.js b/src/api/apm-specific/klarna.js index 34398294..4370a1cf 100644 --- a/src/api/apm-specific/klarna.js +++ b/src/api/apm-specific/klarna.js @@ -50,7 +50,7 @@ export default class Klarna { * * @param {string} id Session id. * @return {Promise} A promise to the Klarna response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getSession(id) { const url = this.config.host.includes('sandbox') @@ -70,7 +70,7 @@ export default class Klarna { * @param {string} id Payment id. * @param {Object} body Capture details. * @return {Promise} A promise to the Klarna response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async capture(id, body) { const url = this.config.host.includes('sandbox') @@ -96,7 +96,7 @@ export default class Klarna { * @param {string} id Payment id. * @param {Object} [body] Void details. * @return {Promise} A promise to the Klarna response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async void(id, body) { const url = this.config.host.includes('sandbox') diff --git a/src/api/apm-specific/oxxo.js b/src/api/apm-specific/oxxo.js index 08f997af..c57468a7 100644 --- a/src/api/apm-specific/oxxo.js +++ b/src/api/apm-specific/oxxo.js @@ -28,7 +28,7 @@ export default class Oxxo { * @param {string} id Payment id. * @memberof Oxxo * @return {Promise} A promise to the Oxxo response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async succeed(id) { try { @@ -51,7 +51,7 @@ export default class Oxxo { * @param {string} id Payment id. * @memberof Oxxo * @return {Promise} A promise to the Oxxo response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async expire(id) { try { diff --git a/src/api/apm-specific/pagofacil.js b/src/api/apm-specific/pagofacil.js index 5542c4aa..d6fc72ff 100644 --- a/src/api/apm-specific/pagofacil.js +++ b/src/api/apm-specific/pagofacil.js @@ -28,7 +28,7 @@ export default class PagoFacil { * @param {string} id Payment id. * @memberof PagoFacil * @return {Promise} A promise to the PagoFacil response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async succeed(id) { try { @@ -51,7 +51,7 @@ export default class PagoFacil { * @param {string} id Payment id. * @memberof PagoFacil * @return {Promise} A promise to the PagoFacil response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async expire(id) { try { diff --git a/src/api/apm-specific/rapipago.js b/src/api/apm-specific/rapipago.js index aeaf27a4..bd76b9e9 100644 --- a/src/api/apm-specific/rapipago.js +++ b/src/api/apm-specific/rapipago.js @@ -28,7 +28,7 @@ export default class Rapipago { * @param {string} id Payment id. * @memberof Rapipago * @return {Promise} A promise to the Rapipago response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async succeed(id) { try { @@ -51,7 +51,7 @@ export default class Rapipago { * @param {string} id Payment id. * @memberof Rapipago * @return {Promise} A promise to the Rapipago response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async expire(id) { try { diff --git a/src/api/apm-specific/sepa.js b/src/api/apm-specific/sepa.js index 2fea2555..a9674dea 100644 --- a/src/api/apm-specific/sepa.js +++ b/src/api/apm-specific/sepa.js @@ -25,7 +25,7 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getMandate(id) { const url = this.config.host.includes('sandbox') @@ -44,7 +44,7 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async cancelMandate(id) { const url = this.config.host.includes('sandbox') @@ -64,7 +64,7 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getPPROMandate(id) { const url = this.config.host.includes('sandbox') @@ -83,7 +83,7 @@ export default class Sepa { * * @param {string} id Source id * @return {Promise} A promise to the Sepa response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async cancelPPROMandate(id) { const url = this.config.host.includes('sandbox') diff --git a/src/api/balances/balances.js b/src/api/balances/balances.js index c98af199..8dd35f5c 100644 --- a/src/api/balances/balances.js +++ b/src/api/balances/balances.js @@ -38,7 +38,7 @@ export default class Balances { * that point in time. Forwarded verbatim as the `balancesAt` (camelCase) * query parameter, as defined in swagger. * @return {Promise} A promise to the balances response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async retrieve(id, options) { try { @@ -113,7 +113,7 @@ export default class Balances { * @param {string} currencyAccountId The ID of the sub-account to retrieve top-up * instructions for. * @return {Promise} A promise to the top-up instructions response. - * @throws {ValueError} If entityId or currencyAccountId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or currencyAccountId is undefined, null, empty, "." or "..". */ async retrieveTopUpInstructions(entityId, currencyAccountId) { try { diff --git a/src/api/compliance-requests/compliance-requests.js b/src/api/compliance-requests/compliance-requests.js index d140c89a..806821bd 100644 --- a/src/api/compliance-requests/compliance-requests.js +++ b/src/api/compliance-requests/compliance-requests.js @@ -22,7 +22,7 @@ export default class ComplianceRequests { * @memberof ComplianceRequests * @param {string} paymentId The payment id whose compliance request to fetch. * @return {Promise} A promise to the compliance request response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async getComplianceRequest(paymentId) { try { @@ -49,7 +49,7 @@ export default class ComplianceRequests { * @param {string} paymentId The payment id whose compliance request to respond to. * @param {Object} body Compliance response body. * @return {Promise} A promise to the response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async respondToComplianceRequest(paymentId, body) { try { diff --git a/src/api/customers/customers.js b/src/api/customers/customers.js index 681a3995..614bd966 100644 --- a/src/api/customers/customers.js +++ b/src/api/customers/customers.js @@ -44,7 +44,7 @@ export default class Customers { * @memberof Customers * @param {string} id Customer id. * @return {Promise} A promise to the customer details response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { @@ -67,7 +67,7 @@ export default class Customers { * @param {string} id Customer id. * @param {Object} body Customer object body. * @return {Promise} A promise to the request customer response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async update(id, body) { try { @@ -94,7 +94,7 @@ export default class Customers { * @memberof Customers * @param {string} id Customer id. * @return {Promise} A promise to the customer response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async delete(id) { try { diff --git a/src/api/disputes/disputes.js b/src/api/disputes/disputes.js index 3e81ee42..ea7e86d4 100644 --- a/src/api/disputes/disputes.js +++ b/src/api/disputes/disputes.js @@ -47,7 +47,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getDetails(disputeId) { try { @@ -69,7 +69,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async accept(disputeId) { try { @@ -98,7 +98,7 @@ export default class Disputes { * @param {string} disputeId Dispute id. * @param {Object} body Evidence * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async provideEvidence(disputeId, body) { try { @@ -121,7 +121,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getEvidence(disputeId) { try { @@ -145,7 +145,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async submit(disputeId) { try { @@ -169,7 +169,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the compiled submitted evidence response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getCompiledSubmittedEvidence(disputeId) { try { @@ -192,7 +192,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the dispute scheme files response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getDisputeSchemeFiles(disputeId) { try { @@ -216,7 +216,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise that resolves when evidence is submitted successfully (204 No Content). - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async submitArbitrationEvidence(disputeId) { try { @@ -244,7 +244,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId Dispute id. * @return {Promise} A promise to the compiled submitted arbitration evidence response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getCompiledSubmittedArbitrationEvidence(disputeId) { try { diff --git a/src/api/events/events.js b/src/api/events/events.js index 0c55dac7..d001989f 100644 --- a/src/api/events/events.js +++ b/src/api/events/events.js @@ -72,7 +72,7 @@ export default class Events { * @memberof Events * @param {string} eventId Event id. * @return {Promise} A promise to the request event response. - * @throws {ValueError} If eventId is undefined, empty, "." or "..". + * @throws {ValueError} If eventId is undefined, null, empty, "." or "..". */ async retrieveEvent(eventId) { try { @@ -95,7 +95,7 @@ export default class Events { * @memberof Events * @param {Object} body Event request body. * @return {Promise} A promise to the request event notifications response. - * @throws {ValueError} If body.eventId or body.notificationId is undefined, empty, "." or "..". + * @throws {ValueError} If body.eventId or body.notificationId is undefined, null, empty, "." or "..". */ async retrieveEventNotification(body) { try { @@ -118,7 +118,7 @@ export default class Events { * @memberof Events * @param {Object} body Event request body. * @return {Promise} A promise to the retry event response. - * @throws {ValueError} If body.eventId or body.webhookId is undefined, empty, "." or "..". + * @throws {ValueError} If body.eventId or body.webhookId is undefined, null, empty, "." or "..". */ async retry(body) { try { @@ -141,7 +141,7 @@ export default class Events { * @memberof Events * @param {string} eventId Event id. * @return {Promise} A promise to the retry events response. - * @throws {ValueError} If eventId is undefined, empty, "." or "..". + * @throws {ValueError} If eventId is undefined, null, empty, "." or "..". */ async retryAll(eventId) { try { diff --git a/src/api/files/files.js b/src/api/files/files.js index 2b89f8c6..a346cbb3 100644 --- a/src/api/files/files.js +++ b/src/api/files/files.js @@ -64,7 +64,7 @@ export default class Files { * @memberof Files * @param {string} fileId Files id. * @return {Promise} A promise to the files response. - * @throws {ValueError} If fileId is undefined, empty, "." or "..". + * @throws {ValueError} If fileId is undefined, null, empty, "." or "..". */ async getFile(fileId) { try { diff --git a/src/api/forward/forward.js b/src/api/forward/forward.js index b21eb374..4b7b749a 100644 --- a/src/api/forward/forward.js +++ b/src/api/forward/forward.js @@ -48,7 +48,7 @@ export default class Forward { * @memberof Forward * @param {string} id The unique identifier of the forward request * @return {Promise} A promise to the forward request details - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { @@ -122,7 +122,7 @@ export default class Forward { * @param {string} name The secret name * @param {Object} body Update body with value and/or entity_id * @return {Promise} A promise to the updated secret metadata with incremented version - * @throws {ValueError} If name is undefined, empty, "." or "..". + * @throws {ValueError} If name is undefined, null, empty, "." or "..". */ async updateSecret(name, body) { try { @@ -145,7 +145,7 @@ export default class Forward { * @memberof Forward * @param {string} name The secret name to delete * @return {Promise} A promise to the deletion response - * @throws {ValueError} If name is undefined, empty, "." or "..". + * @throws {ValueError} If name is undefined, null, empty, "." or "..". */ async deleteSecret(name) { try { diff --git a/src/api/google-pay/google-pay.js b/src/api/google-pay/google-pay.js index b13e9a16..ee89e581 100644 --- a/src/api/google-pay/google-pay.js +++ b/src/api/google-pay/google-pay.js @@ -54,7 +54,7 @@ export default class GooglePay { * @param {string} entityId The enrolled entity id. * @param {Object} body { web_domain: string } per swagger `GooglePayRegisterDomainRequest`. * @return {Promise} A promise that resolves on success. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async registerDomain(entityId, body) { try { @@ -77,7 +77,7 @@ export default class GooglePay { * @memberof GooglePay * @param {string} entityId The enrolled entity id. * @return {Promise} A promise to the registered-domains response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async getRegisteredDomains(entityId) { try { @@ -99,7 +99,7 @@ export default class GooglePay { * @memberof GooglePay * @param {string} entityId The enrolled entity id. * @return {Promise} A promise to the enrollment-state response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async getEnrollmentState(entityId) { try { diff --git a/src/api/hosted-payments/hosted-payments.js b/src/api/hosted-payments/hosted-payments.js index b9eb32e2..748de9fe 100644 --- a/src/api/hosted-payments/hosted-payments.js +++ b/src/api/hosted-payments/hosted-payments.js @@ -77,7 +77,7 @@ export default class HostedPayments { * @memberof HostedPayments * @param {string} id - Hosted payment id * @return {Promise} A promise to the Hosted Payment response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { diff --git a/src/api/identities/address-document-verifications.js b/src/api/identities/address-document-verifications.js index 681aa9b8..c203fb29 100644 --- a/src/api/identities/address-document-verifications.js +++ b/src/api/identities/address-document-verifications.js @@ -51,7 +51,7 @@ export default class AddressDocumentVerifications { * @method getAddressDocumentVerification * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Get an address document verification response - * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id is undefined, null, empty, "." or "..". */ async getAddressDocumentVerification(address_document_verification_id) { try { @@ -78,7 +78,7 @@ export default class AddressDocumentVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get address document verification attempts response - * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id is undefined, null, empty, "." or "..". */ async listAttempts(address_document_verification_id, params) { try { @@ -106,7 +106,7 @@ export default class AddressDocumentVerifications { * @param {string} address_document_verification_id - The address document verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an address document verification attempt response - * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttempt(address_document_verification_id, attempt_id) { try { @@ -130,7 +130,7 @@ export default class AddressDocumentVerifications { * @method anonymizeAddressDocumentVerification * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Anonymize an address document verification response - * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id is undefined, null, empty, "." or "..". */ async anonymizeAddressDocumentVerification(address_document_verification_id) { try { @@ -155,7 +155,7 @@ export default class AddressDocumentVerifications { * @param {string} address_document_verification_id - The address document verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an address document verification attempt response - * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id is undefined, null, empty, "." or "..". */ async createAttempt(address_document_verification_id, body) { try { @@ -180,7 +180,7 @@ export default class AddressDocumentVerifications { * @method getPDFReport * @param {string} address_document_verification_id - The address document verification's unique identifier * @returns {Promise} A promise to the Get address document verification report response - * @throws {ValueError} If address_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id is undefined, null, empty, "." or "..". */ async getPDFReport(address_document_verification_id) { try { @@ -209,7 +209,7 @@ export default class AddressDocumentVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get address document verification attempt assets response - * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If address_document_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttemptAssets(address_document_verification_id, attempt_id, params) { try { diff --git a/src/api/identities/aml-screenings.js b/src/api/identities/aml-screenings.js index 34fb21c5..b45085b5 100644 --- a/src/api/identities/aml-screenings.js +++ b/src/api/identities/aml-screenings.js @@ -46,7 +46,7 @@ export default class AMLScreenings { * @method getAMLScreening * @param {string} aml_screening_id - The AML screening's unique identifier * @returns {Promise} A promise to the Get an AML screening response - * @throws {ValueError} If aml_screening_id is undefined, empty, "." or "..". + * @throws {ValueError} If aml_screening_id is undefined, null, empty, "." or "..". */ async getAMLScreening(aml_screening_id) { try { diff --git a/src/api/identities/applicants.js b/src/api/identities/applicants.js index 6d116fff..5083d9ab 100644 --- a/src/api/identities/applicants.js +++ b/src/api/identities/applicants.js @@ -46,7 +46,7 @@ export default class Applicants { * @method getApplicant * @param {string} applicantId - The applicant profile's unique identifier * @returns {Promise} A promise to the Get an applicant response - * @throws {ValueError} If applicantId is undefined, empty, "." or "..". + * @throws {ValueError} If applicantId is undefined, null, empty, "." or "..". */ async getApplicant(applicantId) { try { @@ -70,7 +70,7 @@ export default class Applicants { * @param {string} applicantId - The applicant profile's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Update an applicant response - * @throws {ValueError} If applicantId is undefined, empty, "." or "..". + * @throws {ValueError} If applicantId is undefined, null, empty, "." or "..". */ async updateApplicant(applicantId, body) { try { @@ -94,7 +94,7 @@ export default class Applicants { * @method anonymizeApplicant * @param {string} applicantId - The applicant profile's unique identifier * @returns {Promise} A promise to the Anonymize an applicant response - * @throws {ValueError} If applicantId is undefined, empty, "." or "..". + * @throws {ValueError} If applicantId is undefined, null, empty, "." or "..". */ async anonymizeApplicant(applicantId) { try { diff --git a/src/api/identities/face-authentications.js b/src/api/identities/face-authentications.js index c398de68..c9a09218 100644 --- a/src/api/identities/face-authentications.js +++ b/src/api/identities/face-authentications.js @@ -50,7 +50,7 @@ export default class FaceAuthentications { * @method getFaceAuthentication * @param {string} face_authentication_id - The face authentication's unique identifier * @returns {Promise} A promise to the Get a face authentication response - * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id is undefined, null, empty, "." or "..". */ async getFaceAuthentication(face_authentication_id) { try { @@ -77,7 +77,7 @@ export default class FaceAuthentications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get face authentication attempts response - * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id is undefined, null, empty, "." or "..". */ async listAttempts(face_authentication_id, params) { try { @@ -105,7 +105,7 @@ export default class FaceAuthentications { * @param {string} face_authentication_id - The face authentication's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get a face authentication attempt response - * @throws {ValueError} If face_authentication_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttempt(face_authentication_id, attempt_id) { try { @@ -133,7 +133,7 @@ export default class FaceAuthentications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get face authentication attempt assets response - * @throws {ValueError} If face_authentication_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttemptAssets(face_authentication_id, attempt_id, params) { try { @@ -162,7 +162,7 @@ export default class FaceAuthentications { * @param {string} face_authentication_id - The face authentication's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create a face authentication attempt response - * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id is undefined, null, empty, "." or "..". */ async createAttempt(face_authentication_id, body) { try { @@ -187,7 +187,7 @@ export default class FaceAuthentications { * @method anonymizeFaceAuthentication * @param {string} face_authentication_id - The face authentication's unique identifier * @returns {Promise} A promise to the Anonymize a face authentication response - * @throws {ValueError} If face_authentication_id is undefined, empty, "." or "..". + * @throws {ValueError} If face_authentication_id is undefined, null, empty, "." or "..". */ async anonymizeFaceAuthentication(face_authentication_id) { try { diff --git a/src/api/identities/id-document-verifications.js b/src/api/identities/id-document-verifications.js index cb441d4e..3c8ee4f3 100644 --- a/src/api/identities/id-document-verifications.js +++ b/src/api/identities/id-document-verifications.js @@ -51,7 +51,7 @@ export default class IDDocumentVerifications { * @method getIDDocumentVerification * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Get an ID document verification response - * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id is undefined, null, empty, "." or "..". */ async getIDDocumentVerification(id_document_verification_id) { try { @@ -78,7 +78,7 @@ export default class IDDocumentVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get ID document verification attempts response - * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id is undefined, null, empty, "." or "..". */ async listAttempts(id_document_verification_id, params) { try { @@ -106,7 +106,7 @@ export default class IDDocumentVerifications { * @param {string} id_document_verification_id - The ID document verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an ID document verification attempt response - * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttempt(id_document_verification_id, attempt_id) { try { @@ -130,7 +130,7 @@ export default class IDDocumentVerifications { * @method anonymizeIDDocumentVerification * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Anonymize an ID document verification response - * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id is undefined, null, empty, "." or "..". */ async anonymizeIDDocumentVerification(id_document_verification_id) { try { @@ -156,7 +156,7 @@ export default class IDDocumentVerifications { * @param {string} id_document_verification_id - The ID document verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an ID document verification attempt response - * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id is undefined, null, empty, "." or "..". */ async createAttempt(id_document_verification_id, body) { try { @@ -182,7 +182,7 @@ export default class IDDocumentVerifications { * @method getPDFReport * @param {string} id_document_verification_id - The ID document verification's unique identifier * @returns {Promise} A promise to the Get ID document verification report response - * @throws {ValueError} If id_document_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id is undefined, null, empty, "." or "..". */ async getPDFReport(id_document_verification_id) { try { @@ -211,7 +211,7 @@ export default class IDDocumentVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get ID document verification attempt assets response - * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If id_document_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttemptAssets(id_document_verification_id, attempt_id, params) { try { diff --git a/src/api/identities/identity-verifications.js b/src/api/identities/identity-verifications.js index 8cc0b2fa..24c9345d 100644 --- a/src/api/identities/identity-verifications.js +++ b/src/api/identities/identity-verifications.js @@ -76,7 +76,7 @@ export default class IdentityVerifications { * @method getIdentityVerification * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Get an identity verification response - * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id is undefined, null, empty, "." or "..". */ async getIdentityVerification(identity_verification_id) { try { @@ -100,7 +100,7 @@ export default class IdentityVerifications { * @method anonymizeIdentityVerification * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Anonymize an identity verification response - * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id is undefined, null, empty, "." or "..". */ async anonymizeIdentityVerification(identity_verification_id) { try { @@ -125,7 +125,7 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @param {Object} body - Request body * @returns {Promise} A promise to the Create an identity verification attempt response - * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id is undefined, null, empty, "." or "..". */ async createAttempt(identity_verification_id, body) { try { @@ -153,7 +153,7 @@ export default class IdentityVerifications { * @param {number} [params.skip] - The number of attempts to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of attempts to return. Defaults to 10 * @returns {Promise} A promise to the Get identity verification attempts response - * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id is undefined, null, empty, "." or "..". */ async listAttempts(identity_verification_id, params) { try { @@ -181,7 +181,7 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @param {string} attempt_id - The attempt's unique identifier * @returns {Promise} A promise to the Get an identity verification attempt response - * @throws {ValueError} If identity_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttempt(identity_verification_id, attempt_id) { try { @@ -210,7 +210,7 @@ export default class IdentityVerifications { * @param {number} [params.skip] - The number of assets to skip. Defaults to 0 * @param {number} [params.limit] - The maximum number of assets to return. Defaults to 10 * @returns {Promise} A promise to the Get identity verification attempt assets response - * @throws {ValueError} If identity_verification_id or attempt_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id or attempt_id is undefined, null, empty, "." or "..". */ async getAttemptAssets(identity_verification_id, attempt_id, params) { try { @@ -240,7 +240,7 @@ export default class IdentityVerifications { * @param {string} identity_verification_id - The identity verification's unique identifier * @returns {Promise} A promise to the Get identity verification report response, * carrying `pdf_report`, the pre-signed URL to the PDF - * @throws {ValueError} If identity_verification_id is undefined, empty, "." or "..". + * @throws {ValueError} If identity_verification_id is undefined, null, empty, "." or "..". */ async getPDFReport(identity_verification_id) { try { diff --git a/src/api/instruments/instruments.js b/src/api/instruments/instruments.js index 2c51a6c1..8339b6d7 100644 --- a/src/api/instruments/instruments.js +++ b/src/api/instruments/instruments.js @@ -129,7 +129,7 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id. * @return {Promise} A promise to the instrument response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { @@ -179,7 +179,7 @@ export default class Instruments { * @param {string} id Instrument id. * @param {Object} body Instruments request body. * @return {Promise} A promise to the instrument response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async update(id, body) { try { @@ -202,7 +202,7 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id. * @return {Promise} A promise to the instrument response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async delete(id) { try { @@ -230,7 +230,7 @@ export default class Instruments { * @memberof Instruments * @param {string} id Instrument id (pattern: ^(src_)[a-z0-9]{26}$). * @return {Promise} A promise to the revoke response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async revoke(id) { try { @@ -268,7 +268,7 @@ export default class Instruments { * @param {string} [query.accountHolderType] individual | corporate | government. * @param {string} [query.paymentNetwork] local | sepa | fps | ach | fedwire | swift. * @return {Promise} A promise to the bank account field response. - * @throws {ValueError} If country or currency is undefined, empty, "." or "..". + * @throws {ValueError} If country or currency is undefined, null, empty, "." or "..". */ async getBankAccountFieldFormatting(country, currency, query) { try { diff --git a/src/api/inventory/inventory.js b/src/api/inventory/inventory.js index 1364c4b2..79b9fc38 100644 --- a/src/api/inventory/inventory.js +++ b/src/api/inventory/inventory.js @@ -134,7 +134,7 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getInventoryReservation(id) { try { @@ -157,7 +157,7 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async commitInventoryReservation(id) { try { @@ -180,7 +180,7 @@ export default class Inventory { * @memberof Inventory * @param {string} id Reservation id. * @return {Promise} A promise to the InventoryReservation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async releaseInventoryReservation(id) { try { @@ -213,7 +213,7 @@ export default class Inventory { * @param {string} [options.expand] Set to `'product'` to embed the variant's * product knowledge in the response. * @return {Promise} A promise to the InventoryLevels response. - * @throws {ValueError} If variantId is undefined, empty, "." or "..". + * @throws {ValueError} If variantId is undefined, null, empty, "." or "..". */ async getInventoryLevels(variantId, options) { try { @@ -251,7 +251,7 @@ export default class Inventory { * @param {number} [body.safety_stock] Buffer withheld from sale. * @param {string} [body.reason] Free-text reason for the ledger. * @return {Promise} A promise to the InventoryLevels response. - * @throws {ValueError} If variantId is undefined, empty, "." or "..". + * @throws {ValueError} If variantId is undefined, null, empty, "." or "..". */ async setInventoryLevels(variantId, body) { try { @@ -291,7 +291,7 @@ export default class Inventory { * @memberof Inventory * @param {string} variantId Variant id (max 128 chars). * @return {Promise} A promise to the InventoryProductKnowledge response. - * @throws {ValueError} If variantId is undefined, empty, "." or "..". + * @throws {ValueError} If variantId is undefined, null, empty, "." or "..". */ async getInventoryProduct(variantId) { try { @@ -327,7 +327,7 @@ export default class Inventory { * @param {string} body.product_url Product page URL. [Required] max 2048 chars. * @param {string} body.image_url Product image URL. [Required] max 2048 chars. * @return {Promise} A promise to the InventoryProductKnowledge response. - * @throws {ValueError} If variantId is undefined, empty, "." or "..". + * @throws {ValueError} If variantId is undefined, null, empty, "." or "..". */ async setInventoryProduct(variantId, body) { try { @@ -351,7 +351,7 @@ export default class Inventory { * @memberof Inventory * @param {string} variantId Variant id (max 128 chars). * @return {Promise} A promise that resolves to an empty object on success. - * @throws {ValueError} If variantId is undefined, empty, "." or "..". + * @throws {ValueError} If variantId is undefined, null, empty, "." or "..". */ async deleteInventoryProduct(variantId) { try { diff --git a/src/api/issuing/cardholders.js b/src/api/issuing/cardholders.js index b7e6b6b3..98b0258c 100644 --- a/src/api/issuing/cardholders.js +++ b/src/api/issuing/cardholders.js @@ -46,7 +46,7 @@ export default class Cardholders { * @memberof Cardholders * @param {string} id Cardholder id. * @return {Promise} A promise to the cardholder details response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getCardholder(id) { try { @@ -69,7 +69,7 @@ export default class Cardholders { * @param {string} id Cardholder id. * @param {Object} body Cardholder params to update. * @return {Promise} A promise to the cardholder update response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateCardholder(id, body) { try { @@ -92,7 +92,7 @@ export default class Cardholders { * @memberof Cardholders * @param {string} id Cardholder id. * @return {Promise} A promise to the cardholder details response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getCardholderCards(id) { try { diff --git a/src/api/issuing/cards.js b/src/api/issuing/cards.js index a4469e02..66e5cf4a 100644 --- a/src/api/issuing/cards.js +++ b/src/api/issuing/cards.js @@ -65,7 +65,7 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card details response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getCardDetails(id) { try { @@ -126,7 +126,7 @@ export default class Cards { * `scheduled_revocation_date`), `scheduled_activation_date`, `last_activated_on`, * `root_card_id`, `parent_card_id`, `scheme`, `created_date`, `last_modified_date`, `_links` * and, for virtual cards only (`type` is `virtual`), `is_single_use`. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateCard(id, body, headers) { try { @@ -154,7 +154,7 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body 3DS enrollment params. * @return {Promise} A promise to the card response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async enrollThreeDS(id, body) { try { @@ -178,7 +178,7 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body 3DS enrollment params. * @return {Promise} A promise to the card response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateThreeDS(id, body) { try { @@ -201,7 +201,7 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getThreeDSDetails(id) { try { @@ -226,7 +226,7 @@ export default class Cards { * @memberof Cards * @param {string} id Card id. * @return {Promise} A promise to the card response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async activateCard(id) { try { @@ -249,7 +249,7 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body Card params. * @return {Promise} A promise to the card response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getCardCredentials(id, body) { try { @@ -272,7 +272,7 @@ export default class Cards { * @param {string} id Card id. * @param {Object} body Card renewal params. * @return {Promise} A promise to the card renewal response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async renewCard(id, body) { try { @@ -298,7 +298,7 @@ export default class Cards { * without a body. * @param {string} [body.reason] Optional reason: `expired`, `reported_lost` or `reported_stolen`. * @return {Promise} A promise to the revoke-card response, carrying `_links`. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async revokeCard(id, body) { try { @@ -324,7 +324,7 @@ export default class Cards { * without a body. * @param {string} [body.reason] Optional reason: `suspected_lost` or `suspected_stolen`. * @return {Promise} A promise to the suspend-card response, carrying `_links`. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async suspendCard(id, body) { try { diff --git a/src/api/issuing/control-groups.js b/src/api/issuing/control-groups.js index 054fa089..a60ad13c 100644 --- a/src/api/issuing/control-groups.js +++ b/src/api/issuing/control-groups.js @@ -66,7 +66,7 @@ export default class ControlGroups { * @memberof ControlGroups * @param {string} controlGroupId The control group ID. * @return {Promise} A promise to the control group details. - * @throws {ValueError} If controlGroupId is undefined, empty, "." or "..". + * @throws {ValueError} If controlGroupId is undefined, null, empty, "." or "..". */ async getControlGroup(controlGroupId) { try { @@ -90,7 +90,7 @@ export default class ControlGroups { * @memberof ControlGroups * @param {string} controlGroupId The control group ID. * @return {Promise} A promise to the deletion response. - * @throws {ValueError} If controlGroupId is undefined, empty, "." or "..". + * @throws {ValueError} If controlGroupId is undefined, null, empty, "." or "..". */ async deleteControlGroup(controlGroupId) { try { diff --git a/src/api/issuing/control-profiles.js b/src/api/issuing/control-profiles.js index 88cdd9a5..8d6af341 100644 --- a/src/api/issuing/control-profiles.js +++ b/src/api/issuing/control-profiles.js @@ -68,7 +68,7 @@ export default class ControlProfiles { * @memberof ControlProfiles * @param {string} controlProfileId The control profile ID. * @return {Promise} A promise to the control profile details. - * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". + * @throws {ValueError} If controlProfileId is undefined, null, empty, "." or "..". */ async getControlProfile(controlProfileId) { try { @@ -92,7 +92,7 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {Object} body Control profile update params. * @return {Promise} A promise to the control profile response. - * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". + * @throws {ValueError} If controlProfileId is undefined, null, empty, "." or "..". */ async updateControlProfile(controlProfileId, body) { try { @@ -116,7 +116,7 @@ export default class ControlProfiles { * @memberof ControlProfiles * @param {string} controlProfileId The control profile ID. * @return {Promise} A promise to the deletion response. - * @throws {ValueError} If controlProfileId is undefined, empty, "." or "..". + * @throws {ValueError} If controlProfileId is undefined, null, empty, "." or "..". */ async deleteControlProfile(controlProfileId) { try { @@ -140,7 +140,7 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {string} targetId The target ID to add to control profile. * @return {Promise} A promise to the response. - * @throws {ValueError} If controlProfileId or targetId is undefined, empty, "." or "..". + * @throws {ValueError} If controlProfileId or targetId is undefined, null, empty, "." or "..". */ async addTargetToControlProfile(controlProfileId, targetId) { try { @@ -164,7 +164,7 @@ export default class ControlProfiles { * @param {string} controlProfileId The control profile ID. * @param {string} targetId The target ID to remove from control profile. * @return {Promise} A promise to the response. - * @throws {ValueError} If controlProfileId or targetId is undefined, empty, "." or "..". + * @throws {ValueError} If controlProfileId or targetId is undefined, null, empty, "." or "..". */ async removeTargetFromControlProfile(controlProfileId, targetId) { try { diff --git a/src/api/issuing/controls.js b/src/api/issuing/controls.js index 7309cc16..543f3a3c 100644 --- a/src/api/issuing/controls.js +++ b/src/api/issuing/controls.js @@ -138,7 +138,7 @@ export default class Controls { * @memberof Controls * @param {string} id Card control id. * @return {Promise} A promise to the control details. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getCardControlDetails(id) { try { @@ -161,7 +161,7 @@ export default class Controls { * @param {string} id Card control id. * @param {Object} body Card control params. * @return {Promise} A promise to the updated control. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateCardControl(id, body) { try { @@ -184,7 +184,7 @@ export default class Controls { * @memberof Controls * @param {string} id Card control id. * @return {Promise} A promise to the removed control id. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async deleteCardControl(id) { try { diff --git a/src/api/issuing/digital-cards.js b/src/api/issuing/digital-cards.js index d899dda1..05603e3e 100644 --- a/src/api/issuing/digital-cards.js +++ b/src/api/issuing/digital-cards.js @@ -24,7 +24,7 @@ export default class DigitalCards { * @memberof DigitalCards * @param {string} digitalCardId The digital card ID. * @return {Promise} A promise to the digital card details. - * @throws {ValueError} If digitalCardId is undefined, empty, "." or "..". + * @throws {ValueError} If digitalCardId is undefined, null, empty, "." or "..". */ async getDigitalCard(digitalCardId) { try { diff --git a/src/api/issuing/disputes.js b/src/api/issuing/disputes.js index 11279528..558cdbbf 100644 --- a/src/api/issuing/disputes.js +++ b/src/api/issuing/disputes.js @@ -56,7 +56,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId The dispute ID. * @return {Promise} A promise to the dispute details. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async getDispute(disputeId) { try { @@ -80,7 +80,7 @@ export default class Disputes { * @memberof Disputes * @param {string} disputeId The dispute ID. * @return {Promise} A promise to the cancellation response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async cancelDispute(disputeId) { try { @@ -105,7 +105,7 @@ export default class Disputes { * @param {Object} [body] Escalation request params. Provide `fraud_details` * when the dispute reason code is fraud-related. * @return {Promise} A promise to the escalation response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async escalateDispute(disputeId, body) { try { @@ -134,7 +134,7 @@ export default class Disputes { * `evidence`, `fraud_details`, `reason_change_justification`, * `action_response`). * @return {Promise} A promise to the dispute response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async amendDispute(disputeId, body) { try { @@ -162,7 +162,7 @@ export default class Disputes { * @param {string} disputeId The dispute ID. * @param {Object} [body] Submission request params. * @return {Promise} A promise to the submission response. - * @throws {ValueError} If disputeId is undefined, empty, "." or "..". + * @throws {ValueError} If disputeId is undefined, null, empty, "." or "..". */ async submitDispute(disputeId, body) { try { diff --git a/src/api/issuing/simulate.js b/src/api/issuing/simulate.js index b1756d8c..f207df63 100644 --- a/src/api/issuing/simulate.js +++ b/src/api/issuing/simulate.js @@ -52,7 +52,7 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async simulateIncrement(id, body) { try { @@ -76,7 +76,7 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async simulateClearing(id, body) { try { @@ -100,7 +100,7 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Refund amount and params. * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async simulateRefund(id, body) { try { @@ -124,7 +124,7 @@ export default class Simulate { * @param {String} id transaction ID. * @param {Object} body Amount. * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async simulateReversal(id, body) { try { diff --git a/src/api/issuing/transactions.js b/src/api/issuing/transactions.js index b56541b4..9f1e7852 100644 --- a/src/api/issuing/transactions.js +++ b/src/api/issuing/transactions.js @@ -43,7 +43,7 @@ export default class Transactions { * @memberof Transactions * @param {string} transactionId The transaction ID. * @return {Promise} A promise to the transaction details. - * @throws {ValueError} If transactionId is undefined, empty, "." or "..". + * @throws {ValueError} If transactionId is undefined, null, empty, "." or "..". */ async getTransactionById(transactionId) { try { diff --git a/src/api/network-tokens/network-tokens.js b/src/api/network-tokens/network-tokens.js index e42031c1..eb1c5586 100644 --- a/src/api/network-tokens/network-tokens.js +++ b/src/api/network-tokens/network-tokens.js @@ -49,7 +49,7 @@ export default class NetworkTokens { * @memberof NetworkTokens * @param {string} network_token_id - The network token ID * @returns {Promise} A promise to the Get Network Token response - * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". + * @throws {ValueError} If network_token_id is undefined, null, empty, "." or "..". */ async getNetworkToken(network_token_id) { try { @@ -74,7 +74,7 @@ export default class NetworkTokens { * @param {string} network_token_id - The network token ID * @param {Object} body - Request body containing transaction_type * @returns {Promise} A promise to the Request a cryptogram response - * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". + * @throws {ValueError} If network_token_id is undefined, null, empty, "." or "..". */ async provisionCryptogram(network_token_id, body) { try { @@ -100,7 +100,7 @@ export default class NetworkTokens { * @memberof NetworkTokens * @param {string} network_token_id - Unique token ID assigned by Checkout.com for each token * @returns {Promise} A promise to the Delete Network Token response - * @throws {ValueError} If network_token_id is undefined, empty, "." or "..". + * @throws {ValueError} If network_token_id is undefined, null, empty, "." or "..". */ async deleteNetworkToken(network_token_id) { try { diff --git a/src/api/onboarding-simulator/onboarding-simulator.js b/src/api/onboarding-simulator/onboarding-simulator.js index 0729168e..5a82ce55 100644 --- a/src/api/onboarding-simulator/onboarding-simulator.js +++ b/src/api/onboarding-simulator/onboarding-simulator.js @@ -67,7 +67,7 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {Object} body { field_names: string[] } * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async setRequirementsDue(entityId, body) { try { @@ -91,7 +91,7 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {string} scenarioId The scenario id to execute. * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If entityId or scenarioId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or scenarioId is undefined, null, empty, "." or "..". */ async runScenario(entityId, scenarioId) { try { @@ -114,7 +114,7 @@ export default class OnboardingSimulator { * @param {string} entityId The sub-entity id. * @param {Object} body { status: string, ... } (see swagger SimulatorSetStatusRequest). * @return {Promise} A promise to the simulation response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async setEntityStatus(entityId, body) { try { diff --git a/src/api/payment-contexts/payment-contexts.js b/src/api/payment-contexts/payment-contexts.js index 954c8d69..06bb79bd 100644 --- a/src/api/payment-contexts/payment-contexts.js +++ b/src/api/payment-contexts/payment-contexts.js @@ -87,7 +87,7 @@ export default class PaymentContexts { * @memberof PaymentContexts * @param {string} id /^(pay|sid)_(\w{26})$/ The payment or payment session identifier. * @return {Promise} A promise to the get payment context response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { diff --git a/src/api/payment-sessions/payment-sessions.js b/src/api/payment-sessions/payment-sessions.js index 3095002d..cfc412c0 100644 --- a/src/api/payment-sessions/payment-sessions.js +++ b/src/api/payment-sessions/payment-sessions.js @@ -92,7 +92,7 @@ export default class PaymentSessions { * @param {string} id The payment session ID. * @param {object} body PaymentSessions Request body. * @return {Promise} A promise to payment context response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async submit(id, body) { try { diff --git a/src/api/payment-setups/payment-setups.js b/src/api/payment-setups/payment-setups.js index 279fcdf5..5927b6bb 100644 --- a/src/api/payment-setups/payment-setups.js +++ b/src/api/payment-setups/payment-setups.js @@ -198,7 +198,7 @@ export default class PaymentSetups { * @param {string} id - The unique identifier of the Payment Setup to update. * @param {Object} body - Request body * @returns {Promise} A promise to the Update a Payment Setup response - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateAPaymentSetup(id, body) { try { @@ -293,7 +293,7 @@ export default class PaymentSetups { * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup to retrieve. * @returns {Promise} A promise to the Get a Payment Setup response - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getAPaymentSetup(id) { try { @@ -343,7 +343,7 @@ export default class PaymentSetups { * @param {string} id - The unique identifier of the Payment Setup. * @param {string} payment_method_name - The name of the payment method to process the payment with (e.g. "tabby", "klarna", "card", "cashapp"). * @returns {Promise} A promise to the Confirm a Payment Setup response - * @throws {ValueError} If id or payment_method_name is undefined, empty, "." or "..". + * @throws {ValueError} If id or payment_method_name is undefined, null, empty, "." or "..". */ async confirmAPaymentSetup(id, payment_method_name) { try { diff --git a/src/api/payments-links/payments-links.js b/src/api/payments-links/payments-links.js index 0a1f4810..20091366 100644 --- a/src/api/payments-links/payments-links.js +++ b/src/api/payments-links/payments-links.js @@ -78,7 +78,7 @@ export default class PaymentLinks { * @memberof PaymentLinks * @param {string} id * @return {Promise} A promise to the Payment Link response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { diff --git a/src/api/payments/payments.js b/src/api/payments/payments.js index e962d34c..008c0008 100644 --- a/src/api/payments/payments.js +++ b/src/api/payments/payments.js @@ -224,7 +224,7 @@ export default class Payments { * @memberof Payments * @param {string} id /^(pay|sid)_(\w{26})$/ The payment or payment session identifier. * @return {Promise} A promise to the get payment response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { @@ -247,7 +247,7 @@ export default class Payments { * @memberof Payments * @param {string} id /^(pay)_(\w{26})$/ The payment identifier. * @return {Promise} A promise to the getActions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getActions(id) { try { @@ -272,7 +272,7 @@ export default class Payments { * @param {Object} body Payment Request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the getActions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async increment(id, body, idempotencyKey) { try { @@ -299,7 +299,7 @@ export default class Payments { * @param {Object} body Payment Request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the getActions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async cancelScheduledRetry(id, body, idempotencyKey) { try { @@ -325,7 +325,7 @@ export default class Payments { * @param {Object} [body] Capture request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the capture response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async capture(paymentId, body, idempotencyKey) { try { @@ -351,7 +351,7 @@ export default class Payments { * @param {Object} [body] Refund request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the refund response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async refund(paymentId, body, idempotencyKey) { try { @@ -380,7 +380,7 @@ export default class Payments { * @param {Object} [body] Reverse request body. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the reverse response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async reverse(paymentId, body, idempotencyKey) { try { @@ -407,7 +407,7 @@ export default class Payments { * @param {number} [body.amount] The amount to void, in the minor currency unit (min 0, max 9999999999). If not specified, the full payment amount is voided. * @param {string} [idempotencyKey] Idempotency Key. * @return {Promise} A promise to the void response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async void(paymentId, body, idempotencyKey) { try { diff --git a/src/api/platforms/entity-requirements.js b/src/api/platforms/entity-requirements.js index 92e75c21..7b44aa68 100644 --- a/src/api/platforms/entity-requirements.js +++ b/src/api/platforms/entity-requirements.js @@ -26,7 +26,7 @@ export default class EntityRequirements { * @param {string} entityId The sub-entity id. * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the requirements list response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async getEntityRequirements(entityId, schemaVersion) { try { @@ -49,7 +49,7 @@ export default class EntityRequirements { * @param {string} entityId The sub-entity id. * @param {string} requirementId The requirement id. * @return {Promise} A promise to the requirement details response. - * @throws {ValueError} If entityId or requirementId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or requirementId is undefined, null, empty, "." or "..". */ async getEntityRequirementDetails(entityId, requirementId) { try { @@ -74,7 +74,7 @@ export default class EntityRequirements { * @param {Object} body { value: ... } — concrete shape defined by the * requirement's `_schema` returned from {@link getEntityRequirementDetails}. * @return {Promise} A promise to the update response. - * @throws {ValueError} If entityId or requirementId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or requirementId is undefined, null, empty, "." or "..". */ async updateEntityRequirement(entityId, requirementId, body) { try { diff --git a/src/api/platforms/files.js b/src/api/platforms/files.js index cee9dd35..4173e251 100644 --- a/src/api/platforms/files.js +++ b/src/api/platforms/files.js @@ -72,7 +72,7 @@ export default class PlatformFiles { * @param {Object} body The body; body.purpose is the purpose of the file upload, one of the * values above. * @returns {Promise} A promise to the file id and upload link. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async uploadAFile(entityId, body) { try { @@ -98,7 +98,7 @@ export default class PlatformFiles { * @returns {Promise} A promise to the file's id, status, status_reasons, size, * mime_type, uploaded_on, purpose and _links (download, the link to fetch the content, and * self). - * @throws {ValueError} If entityId or fileId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or fileId is undefined, null, empty, "." or "..". */ async retrieveAFile(entityId, fileId) { try { diff --git a/src/api/platforms/payment-instruments.js b/src/api/platforms/payment-instruments.js index ed6589e5..7f8f0a8b 100644 --- a/src/api/platforms/payment-instruments.js +++ b/src/api/platforms/payment-instruments.js @@ -25,7 +25,7 @@ export default class PaymentInstruments { * @param {string} entityId The sub-entity's ID. * @param {string} id The payment instrument's ID. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or id is undefined, null, empty, "." or "..". */ async getPaymentInstrumentDetails(entityId, id) { try { @@ -59,7 +59,7 @@ export default class PaymentInstruments { * @param {string} id Payment instrument's id. * @param {Object} body The update, as described above. * @return {Promise} A promise to the Platforms response: the instrument id and _links. - * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or id is undefined, null, empty, "." or "..". */ async updatePaymentInstrumentDetails(entityId, id, body) { try { @@ -83,7 +83,7 @@ export default class PaymentInstruments { * @param {string} id Sub-entity id. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async createPaymentInstrument(id, body) { try { @@ -116,7 +116,7 @@ export default class PaymentInstruments { * @param {string} id Sub-entity id. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async addPaymentInstrument(id, body) { try { @@ -139,7 +139,7 @@ export default class PaymentInstruments { * @param {string} id The sub-entity's ID. * @param {string} [status] The status of your sub-entity's payment instrument. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async queryPaymentInstruments(id, status) { try { diff --git a/src/api/platforms/payout-schedules.js b/src/api/platforms/payout-schedules.js index fdbb64ef..04658309 100644 --- a/src/api/platforms/payout-schedules.js +++ b/src/api/platforms/payout-schedules.js @@ -34,7 +34,7 @@ export default class PayoutSchedules { * * @param {string} id The sub-entity's ID. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async retrieveSubEntityPayoutSchedule(id) { try { @@ -69,7 +69,7 @@ export default class PayoutSchedules { * @param {string} id The sub-entity's ID. * @param {Object} body Platforms request body. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateSubEntityPayoutSchedule(id, body) { try { diff --git a/src/api/platforms/reserve-rules.js b/src/api/platforms/reserve-rules.js index b4b299fa..1045e5a2 100644 --- a/src/api/platforms/reserve-rules.js +++ b/src/api/platforms/reserve-rules.js @@ -24,7 +24,7 @@ export default class ReserveRules { * @param {string} entityId The sub-entity's ID. * @param {string} id The reserve rule ID. * @return {Promise} A promise to the Platforms response (includes headers for ETag). - * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or id is undefined, null, empty, "." or "..". */ async getReserveRuleDetails(entityId, id) { try { @@ -52,7 +52,7 @@ export default class ReserveRules { * @param {Object} body The body to be sent. * @param {string} ifMatch Identifies a specific version of a reserve rule to update (e.g. Y3Y9MCZydj0w). * @return {Promise} A promise to the Platforms response (includes headers for ETag). - * @throws {ValueError} If entityId or id is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or id is undefined, null, empty, "." or "..". */ async updateReserveRule(entityId, id, body, ifMatch) { try { @@ -87,7 +87,7 @@ export default class ReserveRules { * @param {string} id The sub-entity's ID. * @param {Object} body The body of the reserve rule to be added. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async addReserveRule(id, body) { try { @@ -109,7 +109,7 @@ export default class ReserveRules { * * @param {string} id The sub-entity's ID. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async queryReserveRules(id) { try { diff --git a/src/api/platforms/subentity.js b/src/api/platforms/subentity.js index f5c27b56..c5bf8508 100644 --- a/src/api/platforms/subentity.js +++ b/src/api/platforms/subentity.js @@ -146,7 +146,7 @@ export default class Subentity { * @param {string} id Sub-entity id. * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getSubEntityDetails(id, schemaVersion) { try { @@ -173,7 +173,7 @@ export default class Subentity { * @param {string} [schemaVersion='3.0'] Schema version to use (1.0, 2.0, or 3.0). * @return {Promise} A promise to the Platforms response, the same shape as the * onboardSubEntity response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateSubEntityDetails(id, body, schemaVersion) { try { @@ -195,7 +195,7 @@ export default class Subentity { * * @param {string} entityId Sub-entity id. * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If entityId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId is undefined, null, empty, "." or "..". */ async getSubEntityMembers(entityId) { try { @@ -218,7 +218,7 @@ export default class Subentity { * @param {string} userId The ID of the invited user. * @param {Object} body The body (Reinvite sub-entity member). * @return {Promise} A promise to the Platforms response. - * @throws {ValueError} If entityId or userId is undefined, empty, "." or "..". + * @throws {ValueError} If entityId or userId is undefined, null, empty, "." or "..". */ async reinviteSubEntityMember(entityId, userId, body) { try { diff --git a/src/api/reconciliation/reconciliation.js b/src/api/reconciliation/reconciliation.js index 034dd587..8abf2c65 100644 --- a/src/api/reconciliation/reconciliation.js +++ b/src/api/reconciliation/reconciliation.js @@ -53,7 +53,7 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} paymentId Payment id. * @return {Promise} A promise to the request reconciliation response. - * @throws {ValueError} If paymentId is undefined, empty, "." or "..". + * @throws {ValueError} If paymentId is undefined, null, empty, "." or "..". */ async getPayment(paymentId) { try { @@ -116,7 +116,7 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} statementId Statement id. * @return {Promise} A promise to the request reconciliation response. - * @throws {ValueError} If statementId is undefined, empty, "." or "..". + * @throws {ValueError} If statementId is undefined, null, empty, "." or "..". */ async getStatementCsv(statementId) { try { @@ -156,7 +156,7 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} actionsId Action id. * @return {Promise} A promise to the request reconciliation response. - * @throws {ValueError} If actionsId is undefined, empty, "." or "..". + * @throws {ValueError} If actionsId is undefined, null, empty, "." or "..". */ async getPaymentsAction(actionsId) { try { @@ -200,7 +200,7 @@ export default class Reconciliation { * @memberof Reconciliation * @param {string} actionId Action id. * @return {Promise} A promise to the request reconciliation response. - * @throws {ValueError} If actionId is undefined, empty, "." or "..". + * @throws {ValueError} If actionId is undefined, null, empty, "." or "..". */ async getAction(actionId) { try { diff --git a/src/api/reports/reports.js b/src/api/reports/reports.js index 76769c13..2a15aa16 100644 --- a/src/api/reports/reports.js +++ b/src/api/reports/reports.js @@ -41,7 +41,7 @@ export default class Reports { * @memberof Reports * @param {string} id The ID of the report to retrieve. * @return {Promise} A promise to the Reports response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getReportDetails(id) { try { @@ -64,7 +64,7 @@ export default class Reports { * @param {string} id The ID of the report that the file belongs to. * @param {Object} fileId The ID of the file to retrieve. * @return {Promise} A promise to the Reports response. - * @throws {ValueError} If id or fileId is undefined, empty, "." or "..". + * @throws {ValueError} If id or fileId is undefined, null, empty, "." or "..". */ async getReportFile(id, fileId) { try { diff --git a/src/api/sessions/sessions.js b/src/api/sessions/sessions.js index 13725e17..a295df35 100644 --- a/src/api/sessions/sessions.js +++ b/src/api/sessions/sessions.js @@ -62,7 +62,7 @@ export default class Sessions { * @param {string} id Sessions id. * @param {string} channel Type of channnel. * @return {Promise} A promise to the sessions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id, channel) { try { @@ -89,7 +89,7 @@ export default class Sessions { * @param {string} id Sessions id. * @param {Object} body Sessions request body. * @return {Promise} A promise to the sessions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async update(id, body) { try { @@ -113,7 +113,7 @@ export default class Sessions { * @memberof Sessions * @param {string} id Sessions id. * @return {Promise} A promise to the sessions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async complete(id) { try { @@ -137,7 +137,7 @@ export default class Sessions { * @param {string} id Sessions id. * @param {string} threeDsMethodCompletion 3DS Method completion indicator * @return {Promise} A promise to the sessions response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async update3DSMethodCompletionIndicator(id, threeDsMethodCompletion) { try { diff --git a/src/api/tokens/tokens.js b/src/api/tokens/tokens.js index 7f981bd9..971ee38f 100644 --- a/src/api/tokens/tokens.js +++ b/src/api/tokens/tokens.js @@ -48,7 +48,7 @@ export default class Tokens { * @memberof Tokens * @param {string} tokenId The token id (e.g., "tok_..."). * @return {Promise} A promise to the token metadata response. - * @throws {ValueError} If tokenId is undefined, empty, "." or "..". + * @throws {ValueError} If tokenId is undefined, null, empty, "." or "..". */ async getTokenMetadata(tokenId) { try { diff --git a/src/api/transfers/transfers.js b/src/api/transfers/transfers.js index ad9a1a49..c8cb0700 100644 --- a/src/api/transfers/transfers.js +++ b/src/api/transfers/transfers.js @@ -45,7 +45,7 @@ export default class Transfers { * @memberof Transfers * @param {string} id tra_XXX The transfer identifier. * @return {Promise} A promise to the transfer response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async retrieve(id) { try { diff --git a/src/api/webhooks/webhooks.js b/src/api/webhooks/webhooks.js index 4fd25206..7233cc5f 100644 --- a/src/api/webhooks/webhooks.js +++ b/src/api/webhooks/webhooks.js @@ -65,7 +65,7 @@ export default class Webhooks { * @memberof Webhooks * @param {string} id The webhook identifier. * @return {Promise} A promise to the retrieve webhook response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async retrieveWebhook(id) { try { @@ -88,7 +88,7 @@ export default class Webhooks { * @param {string} id The webhook identifier. * @param {Object} body Webhook update body. * @return {Promise} A promise to the update webhook response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async updateWebhook(id, body) { try { @@ -112,7 +112,7 @@ export default class Webhooks { * @param {string} id The webhook identifier. * @param {Object} body Webhook partial-update body. * @return {Promise} A promise to the update webhook response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async partiallyUpdateWebhook(id, body) { try { @@ -135,7 +135,7 @@ export default class Webhooks { * @memberof Webhooks * @param {string} id The webhook identifier. * @return {Promise} A promise to the remove webhook response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async removeWebhook(id) { try { diff --git a/src/api/workflows/workflows.js b/src/api/workflows/workflows.js index e7a7d153..174cb133 100644 --- a/src/api/workflows/workflows.js +++ b/src/api/workflows/workflows.js @@ -72,7 +72,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id Workflow id. * @return {Promise} A promise to the workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async get(id) { try { @@ -95,7 +95,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id Workflow id. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async remove(id) { try { @@ -118,7 +118,7 @@ export default class Workflows { * @param {string} id Workflow id. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async patch(id, body) { try { @@ -147,7 +147,7 @@ export default class Workflows { * @param {string} id Workflow Id. * @param {Object} body Workflows action request body. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async addAction(id, body) { try { @@ -172,7 +172,7 @@ export default class Workflows { * @param {string} workflowActionId Workflow action ID. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If workflowId or workflowActionId is undefined, empty, "." or "..". + * @throws {ValueError} If workflowId or workflowActionId is undefined, null, empty, "." or "..". */ async updateAction(workflowId, workflowActionId, body) { try { @@ -196,7 +196,7 @@ export default class Workflows { * @param {string} workflowId Workflow id. * @param {string} workflowActionId Workflow action Id. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If workflowId or workflowActionId is undefined, empty, "." or "..". + * @throws {ValueError} If workflowId or workflowActionId is undefined, null, empty, "." or "..". */ async removeAction(workflowId, workflowActionId) { try { @@ -219,7 +219,7 @@ export default class Workflows { * @param {string} id Workflow Id. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async addCondition(id, body) { try { @@ -244,7 +244,7 @@ export default class Workflows { * @param {string} workflowConditionId Workflow condition ID. * @param {Object} body Workflows request body. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If workflowId or workflowConditionId is undefined, empty, "." or "..". + * @throws {ValueError} If workflowId or workflowConditionId is undefined, null, empty, "." or "..". */ async updateCondition(workflowId, workflowConditionId, body) { try { @@ -268,7 +268,7 @@ export default class Workflows { * @param {string} workflowId Workflow id. * @param {string} workflowConditionId Workflow condition Id. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If workflowId or workflowConditionId is undefined, empty, "." or "..". + * @throws {ValueError} If workflowId or workflowConditionId is undefined, null, empty, "." or "..". */ async removeCondition(workflowId, workflowConditionId) { try { @@ -291,7 +291,7 @@ export default class Workflows { * @param {string} id Workflow id. * @param {Object} body Event types for which the workflow will execute. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async test(id, body) { try { @@ -334,7 +334,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id Event ID. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getEvent(id) { try { @@ -357,7 +357,7 @@ export default class Workflows { * @param {string} eventId Event ID. * @param {string} workflowActionId Workflow Action ID. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If eventId or workflowActionId is undefined, empty, "." or "..". + * @throws {ValueError} If eventId or workflowActionId is undefined, null, empty, "." or "..". */ async getActionInvocations(eventId, workflowActionId) { try { @@ -379,7 +379,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id Event ID. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async reflowByEvent(id) { try { @@ -404,7 +404,7 @@ export default class Workflows { * @param {string} eventId Event ID. * @param {string} workflowId Workflow ID. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If eventId or workflowId is undefined, empty, "." or "..". + * @throws {ValueError} If eventId or workflowId is undefined, null, empty, "." or "..". */ async reflowByEventAndWorkflow(eventId, workflowId) { try { @@ -478,7 +478,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id The event identifier. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async getSubjectEvents(id) { try { @@ -500,7 +500,7 @@ export default class Workflows { * @memberof Workflows * @param {string} id The subject identifier (for example, a payment ID or a dispute ID). * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If id is undefined, empty, "." or "..". + * @throws {ValueError} If id is undefined, null, empty, "." or "..". */ async reflowBySubject(id) { try { @@ -523,7 +523,7 @@ export default class Workflows { * @param {string} subjectId Subject ID. * @param {string} workflowId Workflow ID. * @return {Promise} A promise to the Workflows response. - * @throws {ValueError} If subjectId or workflowId is undefined, empty, "." or "..". + * @throws {ValueError} If subjectId or workflowId is undefined, null, empty, "." or "..". */ async reflowBySubjectAndWorkflow(subjectId, workflowId) { try { diff --git a/src/services/utils.js b/src/services/utils.js index 6b9a28e8..9d6864d8 100644 --- a/src/services/utils.js +++ b/src/services/utils.js @@ -33,18 +33,18 @@ export const buildQueryParams = (path, params) => { * * The value is converted to a string and encoded with encodeURIComponent, so characters such as * "/", "?", "#", "%" and "\" are percent-encoded. Values that encoding leaves unchanged and that - * are not valid segments ("." and "..") are rejected, as are undefined and empty values. + * are not valid segments ("." and "..") are rejected, as are undefined, null and empty values. * * @param {*} value The value to place in the path, such as an id. * @param {string} name The parameter name, used in the error message. * @return {string} The encoded segment. - * @throws {ValueError} If the value is undefined, empty, "." or "..". + * @throws {ValueError} If the value is undefined, null, empty, "." or "..". */ export const encodePathSegment = (value, name) => { - const segment = value === undefined ? '' : String(value); + const segment = value === undefined || value === null ? '' : String(value); if (segment === '' || segment === '.' || segment === '..') { - throw new ValueError(`Invalid ${name}: must not be undefined, empty, "." or "..".`); + throw new ValueError(`Invalid ${name}: must not be undefined, null, empty, "." or "..".`); } return encodeURIComponent(segment); diff --git a/test/services/path-segments-unit.js b/test/services/path-segments-unit.js index 55558a59..b30036fa 100644 --- a/test/services/path-segments-unit.js +++ b/test/services/path-segments-unit.js @@ -64,7 +64,7 @@ const VALID = 'abc_123'; const RESERVED = ['../x', '%2e%2e/x', '..\\x', 'a?b', 'a#b']; // encodeURIComponent leaves "." and ".." unchanged, so these are rejected before any request is sent. -const REJECTED = ['..', '.', '', undefined]; +const REJECTED = ['..', '.', '', undefined, null]; // One row per SDK method that puts a caller value in the request path: the endpoint class, the // method, the arguments with every path value set to v, and the path sent for a valid id. @@ -322,7 +322,7 @@ describe('Path segments - caller values are encoded', () => { } }); - it(`${label} rejects ., .., empty and undefined without sending a request`, async () => { + it(`${label} rejects ., .., empty, undefined and null without sending a request`, async () => { for (const value of REJECTED) { let error; try { diff --git a/test/services/utils.js b/test/services/utils.js index efe30e17..378d1c61 100644 --- a/test/services/utils.js +++ b/test/services/utils.js @@ -51,11 +51,11 @@ describe('Service Utils - encodePathSegment', () => { }); // encodeURIComponent leaves "." and ".." unchanged, so they are rejected. - [undefined, '', '.', '..'].forEach((value) => { + [undefined, null, '', '.', '..'].forEach((value) => { it(`rejects ${JSON.stringify(value) ?? 'undefined'}`, () => { expect(() => encodePathSegment(value, 'id')).to.throw( ValueError, - 'Invalid id: must not be undefined, empty, "." or "..".' + 'Invalid id: must not be undefined, null, empty, "." or "..".' ); }); });