Skip to content

Commit

Permalink
feat(package): move from javascript to typescript
Browse files Browse the repository at this point in the history
EME-5329

BREAKING CHANGE: Typescript implementation

Co-authored-by: Gabor Nemeth <gabor.nemeth@emarsys.com>
  • Loading branch information
2 people authored and ngabor84 committed Sep 2, 2022
1 parent 852d0e7 commit 97a3597
Show file tree
Hide file tree
Showing 17 changed files with 467 additions and 288 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mocha": true,
"es6": true
},
"parser": "babel-eslint",
"globals": {
"expect": true
},
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
logs
*.log
.nyc_output
dist

# Runtime data
pids
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
*.spec.js
mocha.opts
.nyc_output
src

.idea

Expand All @@ -28,4 +29,4 @@ coverage
build/Release

# Users Environment Variables
.lock-wscript
.lock-wscript
120 changes: 0 additions & 120 deletions lib/request.js

This file was deleted.

21 changes: 0 additions & 21 deletions lib/requestError.js

This file was deleted.

20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "escher-suiteapi-js",
"description": "Escher Suite Api js",
"description": "Escher Request",
"scripts": {
"test": "NODE_ENV=test mocha --recursive ./lib",
"code-style": "eslint $(find . -name \"*.js\" -not -path \"./node_modules/*\")",
"test": "mocha --require ts-node/register ./src/ --recursive",
"lint": "eslint $(find ./src -name \"*.js\" -not -path \"./node_modules/*\")",
"build": "rm -rf dist && tsc --project ./tsconfig.json",
"semantic-release": "CI=true semantic-release"
},
"main": "lib/request.js",
"publishConfig": {
"access": "public"
},
"main": "dist/request.js",
"repository": {
"type": "git",
"url": "git+https://github.com/emartech/escher-suiteapi-js.git"
Expand All @@ -24,11 +28,13 @@
"node": ">=14.0.0"
},
"dependencies": {
"@emartech/json-logger": "4.0.1",
"@emartech/json-logger": "5.0.2",
"axios": "0.27.2",
"escher-auth": "3.2.4"
},
"devDependencies": {
"@types/node": "18.7.8",
"babel-eslint": "10.1.0",
"chai": "4.3.6",
"chai-subset": "1.6.0",
"eslint": "7.21.0",
Expand All @@ -38,6 +44,8 @@
"mocha": "10.0.0",
"semantic-release": "17.4.7",
"sinon": "14.0.0",
"sinon-chai": "3.7.0"
"sinon-chai": "3.7.0",
"ts-node": "10.9.1",
"typescript": "4.7.4"
}
}
34 changes: 34 additions & 0 deletions src/escher-auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
declare module 'escher-auth' {
export type KeyDB = (key: string) => string;

export type EscherRequest = {
method: string;
host: string;
port: number;
url: string;
body?: string | Buffer;
headers?: string[][]; // [["Date","Fri, 09 Sep 2011 23:36:00 GMT"],["Host","host.foo.com"]
};

export type Config = {
algoPrefix?: string;
vendorKey?: string;
hashAlgo?: 'SHA256' | 'SHA512';
credentialScope?: string;
accessKeyId?: string;
apiSecret?: string;
authHeaderName?: string;
dateHeaderName?: string;
clockSkew?: number;
} & Record<string, unknown>;

export default class Escher {
constructor(configToMerge?: Config);
static create(configToMerge?: Config): Escher;
public preSignUrl(url: string, expirationInSec: number): string;
public signRequest(requestOptions: ExtendedRequestOption, body?: string | Buffer, headersToSign?: string[]): EscherRequest;
public authenticate(request: EscherRequest, keyDb: KeyDB, mandatorySignedHeaders?: string[]): string;
public validateRequest(request: EscherRequest, body?: string | Buffer): void;
public validateMandatorySignedHeaders(mandatorySignedHeaders?: string[]): void;
}
}
Loading

0 comments on commit 97a3597

Please sign in to comment.