Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
fix: build + run prettier fix (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
einaralex authored Apr 25, 2023
1 parent c0ced3b commit 162d4b5
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 181 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build

on:
push:
branches-ignore:
- main
jobs:
build-test:
name: "Build & test"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# these if statements ensure that a publication only occurs when
# a new release is created:
- run: yarn install --immutable --immutable-cache
# for security reasons, use --check-cache if accepting PRs from third-parties.
- run: yarn prepublish
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pnp.cjs
.pnp.loader.mjs
*.md
2 changes: 1 addition & 1 deletion configs/commitlint.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
module.exports = { extends: ['@commitlint/config-conventional'] };
4 changes: 2 additions & 2 deletions configs/dts-bundle-generator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const config = {
entries: [
{
filePath: "../src/index.ts",
outFile: "../dist/index.d.ts",
filePath: '../src/index.ts',
outFile: '../dist/index.d.ts',
noCheck: false,
},
],
Expand Down
12 changes: 6 additions & 6 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Config } from "jest";
import type { Config } from 'jest';

const config: Config = {
transform: {
"^.+\\.(t|j)s$": "ts-jest",
'^.+\\.(t|j)s$': 'ts-jest',
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(t|j)s$",
moduleFileExtensions: ["ts", "js", "json", "node"],
preset: "ts-jest",
testEnvironment: "node",
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(t|j)s$',
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
preset: 'ts-jest',
testEnvironment: 'node',
};
export default config;
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
"dist"
],
"engines": {
"node": "18.x"
"node": ">= 17.5"
},
"scripts": {
"build": "tsc && vite build && dts-bundle-generator --config ./configs/dts-bundle-generator.ts",
"build": "NODE_OPTIONS=--experimental-fetch yarn build:main",
"build:main": "tsc && vite build && dts-bundle-generator --config ./configs/dts-bundle-generator.ts",
"clean": "rm -rf dist && rm -rf node_modules",
"docs": "typedoc --options configs/typedoc.json",
"docs:watch": "yarn docs --watch",
Expand All @@ -29,7 +30,8 @@
"prepare": "husky install",
"prepublish": "yarn build && yarn lint && yarn format && yarn test",
"start": "vite --host --open",
"test": "jest",
"test": "NODE_OPTIONS=--experimental-fetch yarn test:main",
"test:main": "jest",
"test:coverage": "jest --coverage",
"watch": "tsc && vite build --watch"
},
Expand Down
76 changes: 38 additions & 38 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import encodeBase64Url from "crypto-js/enc-base64url";
import SHA256 from "crypto-js/sha256";
import { generateRandomString } from "./utils";
import { MONERIUM_CONFIG } from "./config";
import encodeBase64Url from 'crypto-js/enc-base64url';
import SHA256 from 'crypto-js/sha256';
import { generateRandomString } from './utils';
import { MONERIUM_CONFIG } from './config';
import type {
AuthArgs,
AuthCode,
Expand All @@ -20,7 +20,7 @@ import type {
RefreshToken,
SupportingDoc,
Token,
} from "./types";
} from './types';
// import pjson from "../package.json";

export class MoneriumClient {
Expand All @@ -31,7 +31,7 @@ export class MoneriumClient {
codeVerifier?: string;
bearerProfile?: BearerProfile;

constructor(env: "production" | "sandbox" = "sandbox") {
constructor(env: 'production' | 'sandbox' = 'sandbox') {
this.#env = MONERIUM_CONFIG.environments[env];
}

Expand All @@ -41,20 +41,20 @@ export class MoneriumClient {
let params: AuthCode | RefreshToken | ClientCredentials;

if (this.#isAuthCode(args)) {
params = { ...args, grant_type: "authorization_code" };
params = { ...args, grant_type: 'authorization_code' };
} else if (this.#isRefreshToken(args)) {
params = { ...args, grant_type: "refresh_token" };
params = { ...args, grant_type: 'refresh_token' };
} else if (this.#isClientCredentials(args)) {
params = { ...args, grant_type: "client_credentials" };
params = { ...args, grant_type: 'client_credentials' };
} else {
throw new Error("Authentication method could not be detected.");
throw new Error('Authentication method could not be detected.');
}

this.bearerProfile = (await this.#api(
"post",
'post',
`auth/token`,
new URLSearchParams(params as unknown as Record<string, string>),
true
true,
)) as BearerProfile;

this.#authPayload = `Bearer ${this.bearerProfile.access_token}`;
Expand All @@ -72,15 +72,15 @@ export class MoneriumClient {
// `Error: Native crypto module could not be used to get secure random number.`
this.codeVerifier = generateRandomString();
const challenge = encodeBase64Url.stringify(
SHA256(this.codeVerifier as string)
SHA256(this.codeVerifier as string),
);

const params: PKCERequest = {
...args,
client_id: args?.client_id,
code_challenge: challenge,
code_challenge_method: "S256",
response_type: "code",
code_challenge_method: 'S256',
response_type: 'code',
};

return `${this.#env.api}/auth?${new URLSearchParams(params)}`;
Expand All @@ -94,14 +94,14 @@ export class MoneriumClient {
// -- Read Methods

getAuthContext(): Promise<AuthContext> {
return this.#api("get", `auth/context`) as Promise<AuthContext>;
return this.#api('get', `auth/context`) as Promise<AuthContext>;
}

/**
* @param {string} profileId - the id of the profile to fetch.
*/
getProfile(profileId: string): Promise<Profile> {
return this.#api("get", `profiles/${profileId}`) as Promise<Profile>;
return this.#api('get', `profiles/${profileId}`) as Promise<Profile>;
}

/**
Expand All @@ -110,66 +110,66 @@ export class MoneriumClient {
getBalances(profileId?: string): Promise<Balances> | Promise<Balances[]> {
if (profileId) {
return this.#api(
"get",
`profiles/${profileId}/balances`
'get',
`profiles/${profileId}/balances`,
) as Promise<Balances>;
} else {
return this.#api("get", `balances`) as Promise<Balances[]>;
return this.#api('get', `balances`) as Promise<Balances[]>;
}
}

getOrders(filter?: OrderFilter): Promise<Order[]> {
const searchParams = new URLSearchParams(
filter as unknown as Record<string, string>
filter as unknown as Record<string, string>,
);

return this.#api("get", `orders?${searchParams}`) as Promise<Order[]>;
return this.#api('get', `orders?${searchParams}`) as Promise<Order[]>;
}

getOrder(orderId: string): Promise<Order> {
return this.#api("get", `orders/${orderId}`) as Promise<Order>;
return this.#api('get', `orders/${orderId}`) as Promise<Order>;
}

getTokens(): Promise<Token[]> {
return this.#api("get", "tokens") as Promise<Token[]>;
return this.#api('get', 'tokens') as Promise<Token[]>;
}

// -- Write Methods

linkAddress(profileId: string, body: LinkAddress) {
return this.#api(
"post",
'post',
`profiles/${profileId}/addresses`,
JSON.stringify(body)
JSON.stringify(body),
);
}

placeOrder(order: NewOrder, profileId?: string): Promise<Order> {
if (profileId) {
return this.#api(
"post",
'post',
`profiles/${profileId}/orders`,
JSON.stringify(order)
JSON.stringify(order),
) as Promise<Order>;
} else {
return this.#api(
"post",
'post',
`orders`,
JSON.stringify(order)
JSON.stringify(order),
) as Promise<Order>;
}
}

uploadSupportingDocument(document: File): Promise<SupportingDoc> {
const searchParams = new URLSearchParams(
document as unknown as Record<string, string>
document as unknown as Record<string, string>,
);

return this.#api(
"post",
"files/supporting-document",
'post',
'files/supporting-document',
searchParams,
true
true,
) as Promise<SupportingDoc>;
}

Expand All @@ -179,15 +179,15 @@ export class MoneriumClient {
method: string,
resource: string,
body?: BodyInit,
isFormEncoded?: boolean
isFormEncoded?: boolean,
) {
const res = await fetch(`${this.#env.api}/${resource}`, {
method,
headers: {
"Content-Type": `application/${
isFormEncoded ? "x-www-form-urlencoded" : "json"
'Content-Type': `application/${
isFormEncoded ? 'x-www-form-urlencoded' : 'json'
}`,
Authorization: this.#authPayload || "",
Authorization: this.#authPayload || '',
// "User-Agent": "sdk/" + pjson.version,
},
body,
Expand Down
10 changes: 5 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Config } from "./types";
import type { Config } from './types';

const MONERIUM_CONFIG: Config = {
environments: {
production: {
api: "https://api.monerium.app",
web: "https://monerium.app",
api: 'https://api.monerium.app',
web: 'https://monerium.app',
},
sandbox: {
api: "https://api.monerium.dev",
web: "https://sandbox.monerium.dev",
api: 'https://api.monerium.dev',
web: 'https://sandbox.monerium.dev',
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { MoneriumClient } from "./client";
export * from "./types";
export { MoneriumClient } from './client';
export * from './types';
Loading

0 comments on commit 162d4b5

Please sign in to comment.