Skip to content

Commit

Permalink
Release 5.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldlineConnect committed Mar 25, 2024
1 parent 765704b commit badbb1c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: code
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '12.x'
cache: 'npm'
Expand All @@ -26,7 +26,7 @@ jobs:
run: npm ci && npm run build && npm run typedoc
working-directory: code
- name: Checkout pages
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: gh-pages
path: pages
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '12.x'
# sets up .npmrc file to publish to npm
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/v1/riskassessments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("riskassessments", () => {
}
};

const response = await client.v1.riskassessments.bankaccounts(config.merchantId, body, null);
const response = await client.v1.riskassessments.bankaccounts(config.merchantId, body);
expect(response.status).toBe(200);
expect(response.body).not.toBeNull();

Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/v1/tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("token", () => {
}
};

const createResponse = await client.v1.tokens.create(config.merchantId, body, null);
const createResponse = await client.v1.tokens.create(config.merchantId, body);
expect(createResponse.status).toBeGreaterThanOrEqual(200);
expect(createResponse.status).toBeLessThanOrEqual(201);
expect(createResponse.body).not.toBeNull();
Expand Down
9 changes: 9 additions & 0 deletions __tests__/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ describe("assertSuccess", () => {
};
const asserted = assertSuccess(response);
expect(asserted).toBe(response);
// check separate properties too, to ensure that the right type is returned
expect(asserted.status).toBe(response.status);
expect(asserted.isSuccess).toBe(true);
expect(asserted.body).toBe(response.body);
});

test("!isSuccess", () => {
Expand Down Expand Up @@ -55,6 +59,11 @@ describe("assertSuccess", () => {
};
const asserted = assertSuccess(response);
expect(asserted).toBe(response);
// check separate properties too, to ensure that the right type is returned
expect(asserted.status).toBe(response.status);
expect(asserted.isSuccess).toBe(true);
expect(asserted.body).toBe(response.body);
expect(asserted.file).toBe(response.file);
});

test("!isSuccess", () => {
Expand Down
2 changes: 1 addition & 1 deletion documentation/Migration Guide v4 to v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Modules for API clients and calls like `connect-sdk-nodejs/lib/v1/payments` or `
```typescript
import { create as createPayment } from "connect-sdk-nodejs/lib/v1/payments/create";
import { newPaymentsClient } from "connect-sdk-nodejs/lib/v1/payments";
import { CreatePaymentResponse} from "connect-sdk-nodejs/lib/v1/model/domain";
import { CreatePaymentResponse } from "connect-sdk-nodejs/lib/v1/model/domain";

const createResponse = await createPayment(sdkContext)(merchantId, body, paymentContext);
const responseBody = createResponse.body as CreatePaymentResponse;
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "connect-sdk-nodejs",
"version": "5.0.0",
"version": "5.1.0",
"description": "SDK to communicate with the Worldline Global Collect platform using the Worldline Connect Server API",
"homepage": "https://github.com/Worldline-Global-Collect/connect-sdk-nodejs#readme",
"bugs": {
Expand Down Expand Up @@ -30,6 +30,7 @@
"test:integration": "jest --group=integration"
},
"dependencies": {
"dateformat": "^4.6.3",
"form-data": "^4.0.0",
"jsonschema": "^1.4.1",
"lodash": "^4.17.21",
Expand All @@ -50,7 +51,6 @@
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"body-parser": "^1.20.2",
"dateformat": "^4.6.3",
"eslint": "^7.32.0",
"express": "^4.18.2",
"husky": "^4.3.8",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export const obfuscate: ObfuscationRules = {
};

/**
* Asserts that an {@link SdkResponse} is successful.
* Asserts that an {@link SdkBinaryResponse} is successful.
* @returns The response if it is successful.
* @throws {@link SdkApiError} if the response is not successful.
*/
export function assertSuccess<T, E>(response: SdkResponse<T, E>): SdkSuccessResponse<T>;
export function assertSuccess<E>(response: SdkBinaryResponse<E>): SdkBinarySuccessResponse;
/**
* Asserts that an {@link SdkBinaryResponse} is successful.
* Asserts that an {@link SdkResponse} is successful.
* @returns The response if it is successful.
* @throws {@link SdkApiError} if the response is not successful.
*/
export function assertSuccess<E>(response: SdkBinaryResponse<E>): SdkBinarySuccessResponse;
export function assertSuccess<T, E>(response: SdkResponse<T, E>): SdkSuccessResponse<T>;
export function assertSuccess<T, E>(response: SdkResponse<T, E> | SdkBinaryResponse<E>): SdkSuccessResponse<T> | SdkBinarySuccessResponse {
if (response.isSuccess) {
return response;
Expand Down
7 changes: 7 additions & 0 deletions src/model/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Readable } from "stream";
import { Agent } from "http";
import { ShoppingCartExtension } from "./domain";

export interface Authenticator {
Expand All @@ -22,6 +23,11 @@ export interface Configuration {
shoppingCartExtension?: ShoppingCartExtension;
obfuscationRules?: Record<string, ObfuscationRule>;
proxy?: ProxyConfiguration;
connectionOptions?: ConnectionOptions;
}

export interface ConnectionOptions {
agent?: Agent;
}

export interface FileMetadata {
Expand Down Expand Up @@ -99,6 +105,7 @@ export interface ProxyConfiguration {
export interface SdkContext {
getEndpoint(): HttpEndpoint;
getProxy(): ProxyConfiguration | undefined;
getConnectionOptions(): ConnectionOptions | undefined;
getAuthenticator(): Authenticator;
getLogger(): Logger;
setLogger(logger: Logger): void;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/communicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ async function prepareRequest(request: SdkRequest, sdkContext: SdkContext, optio
options.headers!["Proxy-Authorization"] = "Basic " + Buffer.from(proxy.credentials).toString("base64");
}
}

const connectionOptions = sdkContext.getConnectionOptions();
if (connectionOptions?.agent) {
options.agent = connectionOptions.agent;
}
}

function handleResponse(
Expand Down
8 changes: 7 additions & 1 deletion src/utils/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Authenticator, CommunicatorLogger, Configuration, HttpEndpoint, Logger, ObfuscationRule, ProxyConfiguration, SdkContext } from "../model";
import { Authenticator, CommunicatorLogger, Configuration, ConnectionOptions, HttpEndpoint, Logger, ObfuscationRule, ProxyConfiguration, SdkContext } from "../model";
import { ShoppingCartExtension } from "../model/domain";
import { V1HMACAuthenticator } from "./authentication";

Expand All @@ -15,6 +15,7 @@ function defaultPort(scheme: "http" | "https"): number {
class SdkContextImpl implements SdkContext {
private readonly endpoint: HttpEndpoint;
private readonly proxy?: ProxyConfiguration;
private readonly connectionOptions?: ConnectionOptions;
private readonly authenticator: Authenticator;
private readonly integrator: string;
private readonly shoppingCartExtension?: ShoppingCartExtension;
Expand All @@ -29,6 +30,7 @@ class SdkContextImpl implements SdkContext {
port: configuration.port ?? defaultPort(configuration.scheme ?? "https")
};
this.proxy = configuration.proxy;
this.connectionOptions = configuration.connectionOptions;
this.authenticator = new V1HMACAuthenticator(configuration.apiKeyId, configuration.secretApiKey);

this.logger = configuration.logger ? toLogger(configuration.logger) : consoleLogger;
Expand Down Expand Up @@ -59,6 +61,10 @@ class SdkContextImpl implements SdkContext {
return this.proxy;
}

getConnectionOptions(): ConnectionOptions | undefined {
return this.connectionOptions;
}

getAuthenticator(): Authenticator {
return this.authenticator;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ServerMetaInfo {
export function serverMetaInfo(sdkContext: SdkContext): Header {
const info: ServerMetaInfo = {
sdkCreator: "Worldline",
sdkIdentifier: "NodejsServerSDK/v5.0.0",
sdkIdentifier: "NodejsServerSDK/v5.1.0",
platformIdentifier: process.env["OS"] + " Node.js/" + process.versions.node,
integrator: sdkContext.getIntegrator()
};
Expand Down

0 comments on commit badbb1c

Please sign in to comment.