Skip to content

Commit

Permalink
Release 5.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldlineConnect committed Mar 19, 2024
1 parent 3b7337c commit c3435bf
Show file tree
Hide file tree
Showing 179 changed files with 22,986 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
/docs
/lib
/schemas
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gitattributes export-ignore
.gitignore export-ignore

* text eol=lf
58 changes: 58 additions & 0 deletions .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: API docs

on:
push:
tags: ['[0-9]+.[0-9]+*']

permissions:
contents: write

jobs:
api-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
path: code
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '12.x'
cache: 'npm'
cache-dependency-path: code/package-lock.json
- name: Build API docs
run: npm ci && npm run build && npm run typedoc
working-directory: code
- name: Checkout pages
uses: actions/checkout@v3
with:
ref: gh-pages
path: pages
- name: Deploy pages
run: |
SDK_VERSION_FOLDER=`echo "$SDK_VERSION" | awk --field-separator '.' '{print $1".x";}'`
# Create .nojekyll if it doesn't exist yet
touch .nojekyll
mkdir -p "$SDK_VERSION_FOLDER"
rsync --quiet --archive --checksum --delete --exclude .git ../code/docs/ "$SDK_VERSION_FOLDER/"
# Remove .nojekyll generated by TypeDoc
if [ -f "$SDK_VERSION_FOLDER/.nojekyll" ]; then rm "$SDK_VERSION_FOLDER/.nojekyll"; fi
if [ -e latest ]; then rm -r latest; fi
ln -s "$SDK_VERSION_FOLDER" latest
git config user.email "$USER_EMAIL"
git config user.name "$USER_NAME"
git add --all .
# Only commit when there are changes
git diff --quiet && git diff --staged --quiet || git commit --message "Generated API docs for version ${SDK_VERSION}"
git push
shell: bash
working-directory: pages
env:
SDK_VERSION: ${{ github.ref_name }}
USER_EMAIL: ${{ github.event.pusher.email }}
USER_NAME: ${{ github.event.pusher.name }}
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy

on:
push:
tags: ['[0-9]+.[0-9]+*']

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '12.x'
# sets up .npmrc file to publish to npm
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Build
run: npm ci && npm run build
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_modules
/lib
/docs
logfile.txt
.vscode
.idea

# For testing
__tests__/config.json
junit*.xml
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
/docs
/lib
/schemas
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Worldlline Connect Node.js SDK

## Introduction

The Node.js SDK helps you to communicate with the [Worldline Connect](https://docs.connect.worldline-solutions.com/) Server API. Its primary features are:

* convenient JavaScript wrapper around the API calls,
* authentication of all calls
* logging support by proxying log calls to a custom user defined logger instance
* validation of input and
* a logfile obfuscater

See the [Worldline Connect Developer Hub](https://docs.connect.worldline-solutions.com/documentation/sdk/server/nodejs/) for more information on how to use the API.

## Structure of this repository

This repository consists out of three main components:

1. The source code of the SDK itself: `/src`
2. The JSON schemas used to validate requests: `/schemas`
3. Unit and integration tests: `/__tests__`

## Requirements

Node.js 8 or higher is required.

## Installation

From the folder where your `package.json` is located, run the following command to install the SDK:

npm i connect-sdk-nodejs

## Building the repository

From the root of the project install all dependencies, then compile the code:

npm install
npm run build

## Testing

There are two types of tests:

1. Unit tests. These will work out-of-the-box.
Run these tests as follows:

```
npm run test:unit
```
2. Integration tests. Before you can run these, you first need to copy file `__tests__/config.json.dist` to `__tests__/config.json` and replace all values as needed. If needed, a `proxy` property can be added with nested properties `host`, `scheme` (defaults to `http`), `port` (defaults to 3128) and `credentials` (optional, in the format `<username>:<password>`).
Run these tests as follows:
```
npm run test:integration
```
You can also run both types of tests together as follows:
npm run test
13 changes: 13 additions & 0 deletions __tests__/config.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"merchantId": "MERCHANT_ID",
"apiKeyId": "API_KEY_ID",
"secretApiKey": "API_SECRET",
"apiEndpoint": {
"host": "API_ENDPOINT_HOST",
"scheme": "https",
"port": 443
},
"integrator": "INTEGRATOR",
"enableLogging": false,
"httpBinUrl": "http://httpbin.org"
}
19 changes: 19 additions & 0 deletions __tests__/integration/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as connectSdk from "../../src";

// eslint-disable-next-line @typescript-eslint/no-var-requires
export const config = require("../config.json");

jest.setTimeout(60 * 1000);

const client = connectSdk.init({
host: config.apiEndpoint.host,
scheme: config.apiEndpoint.scheme,
port: config.apiEndpoint.port,
enableLogging: config.enableLogging, // defaults to false
apiKeyId: config.apiKeyId,
secretApiKey: config.secretApiKey,
integrator: config.integrator,
proxy: config.proxy
});

export default client;
100 changes: 100 additions & 0 deletions __tests__/integration/multipart.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */

import { Readable } from "stream";
import { URL } from "url";
import * as communicator from "../../src/utils/communicator";
import { newSdkContext } from "../../src/utils/context";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require("../config.json");

const httpBinUrl = new URL(config.httpBinUrl || "http://httpbin.org");
const scheme = httpBinUrl.protocol === "http:" ? "http" : "https";
const port = httpBinUrl.port ? parseInt(httpBinUrl.port) : httpBinUrl.protocol === "http:" ? 80 : 443;

const sdkContext = newSdkContext({
host: httpBinUrl.hostname,
scheme,
port,
enableLogging: config.enableLogging, // defaults to false
apiKeyId: config.apiKeyId,
secretApiKey: config.secretApiKey,
integrator: "Integration tests"
});

jest.setTimeout(60 * 1000);

function toReadable(str: string): Readable {
const result = new Readable();
result.push(str);
result.push(null);
return result;
}

interface HttpBinResponse {
form: { [key: string]: string | undefined };
files: { [key: string]: string | undefined };
}

/**
* @group integration
*/
describe("multipart", () => {
test("POST", async () => {
const body = {
value: "Hello World",
file: {
content: toReadable("This is the contents of a file"),
fileName: "file.txt",
contentType: "text/plain"
}
};

const response = await communicator.multipart(
{
method: "POST",
modulePath: "/post",
body: body,
paymentContext: null
},
sdkContext
);
expect(response.status).toBe(200);
expect(response.body).not.toBeNull();

const responseBody = response.body as HttpBinResponse;
expect(responseBody.files).not.toBeNull();
expect(responseBody.files.file).toBe("This is the contents of a file");
expect(responseBody.form).not.toBeNull();
expect(responseBody.form.value).toBe("Hello World");
});

test("PUT", async () => {
const body = {
value: "Hello World",
file: {
content: toReadable("This is the contents of a file"),
fileName: "file.txt",
contentType: "text/plain"
}
};

const response = await communicator.multipart(
{
method: "PUT",
modulePath: "/put",
body: body,
paymentContext: null
},
sdkContext
);
expect(response.status).toBe(200);
expect(response.body).not.toBeNull();

const responseBody = response.body as HttpBinResponse;
expect(responseBody.files).not.toBeNull();
expect(responseBody.files.file).toBe("This is the contents of a file");
expect(responseBody.form).not.toBeNull();
expect(responseBody.form.value).toBe("Hello World");
});
});
24 changes: 24 additions & 0 deletions __tests__/integration/v1/convertAmount.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */

import { assertSuccess } from "../../../src";
import client, { config } from "../init";

/**
* @group integration
*/
describe("convertAmount", () => {
test("called successfully", async () => {
const query = {
source: "EUR",
target: "USD",
amount: 100
};

const response = await client.v1.services.convertAmount(config.merchantId, query);
expect(response.status).toBe(200);
expect(response.body).not.toBeNull();

const responseBody = assertSuccess(response).body;
expect(responseBody.convertedAmount).not.toBeNull();
});
});
Loading

0 comments on commit c3435bf

Please sign in to comment.