@facesignai/api 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +29 -0
- package/build/package.json +51 -0
- package/build/src/api-endpoints.d.ts +110 -0
- package/build/src/api-endpoints.d.ts.map +1 -0
- package/build/src/api-endpoints.js +59 -0
- package/build/src/client.d.ts +33 -0
- package/build/src/client.d.ts.map +1 -0
- package/build/src/client.js +165 -0
- package/build/src/errors.d.ts +5 -0
- package/build/src/errors.d.ts.map +1 -0
- package/build/src/errors.js +8 -0
- package/build/src/helpers.d.ts +2 -0
- package/build/src/helpers.d.ts.map +1 -0
- package/build/src/helpers.js +16 -0
- package/build/src/index.d.ts +4 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +22 -0
- package/build/src/utils.d.ts +4 -0
- package/build/src/utils.d.ts.map +1 -0
- package/build/src/utils.js +8 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2021 Notion Labs, Inc.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>Facesign SDK for Node JS</h1>
|
|
3
|
+
<p>
|
|
4
|
+
<b>A simple and easy to use client for the <a href="https://docs.facesign.ai">Facesign API</a></b>
|
|
5
|
+
</p>
|
|
6
|
+
<br>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @facesign/api
|
|
13
|
+
yarn add @facesign/api
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Import and initialize a client using an **integration token**
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const { Client } = require('@facesignai/api')
|
|
22
|
+
|
|
23
|
+
// Initializing a client
|
|
24
|
+
const facesignClient = new Client({
|
|
25
|
+
auth: process.env.FACESIGN_TOKEN,
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Make a request to any Facesign API endpoint.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@facesignai/api",
|
|
3
|
+
"package-name": "@facesignai/api",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "Facesign API wrapper",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@github.com/facesignai/facesign-api.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Facesign <support@facesign.ai> (https://facesign.ai/)",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"private": false,
|
|
13
|
+
"main": "./build/src/index.js",
|
|
14
|
+
"types": "./build/src/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"build/src/package.json",
|
|
17
|
+
"build/**"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepare": "npm run build",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"prettier": "prettier --write .",
|
|
26
|
+
"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
|
|
27
|
+
"test": "jest ./test",
|
|
28
|
+
"prebuild": "npm run clean",
|
|
29
|
+
"clean": "rm -rf ./build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@types/node-fetch": "^2.5.10",
|
|
33
|
+
"loglevel": "^1.9.1",
|
|
34
|
+
"node-fetch": "^2.6.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^28.1.4",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.39.0",
|
|
40
|
+
"cspell": "^5.4.1",
|
|
41
|
+
"eslint": "^7.24.0",
|
|
42
|
+
"jest": "^28.1.2",
|
|
43
|
+
"prettier": "^2.8.8",
|
|
44
|
+
"ts-jest": "^28.0.5",
|
|
45
|
+
"typescript": "^4.8.4"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/facesignai/facesign-api/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/facesignai/facesign-api#readme"
|
|
51
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
export declare enum ILogLevel {
|
|
2
|
+
TRACE = "TRACE",
|
|
3
|
+
DEBUG = " DEBUG",
|
|
4
|
+
INFO = "INFO",
|
|
5
|
+
WARN = "WARN",
|
|
6
|
+
ERROR = "ERROR",
|
|
7
|
+
OFF = "OFF"
|
|
8
|
+
}
|
|
9
|
+
export interface ClientOptions {
|
|
10
|
+
auth?: string;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
logLevel?: ILogLevel;
|
|
13
|
+
serverUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare enum Method {
|
|
16
|
+
GET = "get",
|
|
17
|
+
POST = "post",
|
|
18
|
+
PATCH = "patch",
|
|
19
|
+
DELTE = "delete"
|
|
20
|
+
}
|
|
21
|
+
export type AvatarType = 'heygen' | 'azure' | 'custom';
|
|
22
|
+
export interface RequestedData {
|
|
23
|
+
key: string;
|
|
24
|
+
isRequired?: boolean;
|
|
25
|
+
description?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface GetSessionParameters {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CreateClientSecretParameters {
|
|
31
|
+
sessionId: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Phrase {
|
|
34
|
+
id: string;
|
|
35
|
+
createdAt: number;
|
|
36
|
+
text: string;
|
|
37
|
+
isAvatar: boolean;
|
|
38
|
+
}
|
|
39
|
+
export declare enum SessionStatus {
|
|
40
|
+
RequiresInput = "requiresInput",
|
|
41
|
+
Processing = "processing",
|
|
42
|
+
Canceled = "canceled",
|
|
43
|
+
Complete = "complete"
|
|
44
|
+
}
|
|
45
|
+
export interface ClientSecret {
|
|
46
|
+
secret: string;
|
|
47
|
+
createdAt: number;
|
|
48
|
+
expireAt: number;
|
|
49
|
+
url: string;
|
|
50
|
+
}
|
|
51
|
+
export interface Session {
|
|
52
|
+
id: string;
|
|
53
|
+
createdAt: number;
|
|
54
|
+
startedAt?: number;
|
|
55
|
+
finishedAt?: number;
|
|
56
|
+
transcript: Phrase[];
|
|
57
|
+
status: SessionStatus;
|
|
58
|
+
settings: SessionSettings;
|
|
59
|
+
version?: string;
|
|
60
|
+
data: Record<string, string>;
|
|
61
|
+
}
|
|
62
|
+
export interface GetSessionResponse {
|
|
63
|
+
session: Session;
|
|
64
|
+
clientSecret: ClientSecret;
|
|
65
|
+
}
|
|
66
|
+
export type Lang = 'en' | 'fr' | 'de' | 'es';
|
|
67
|
+
export type Zone = 'es' | 'eu';
|
|
68
|
+
export interface SessionSettings {
|
|
69
|
+
clientReferenceId: string;
|
|
70
|
+
metadata: object;
|
|
71
|
+
requestedData: RequestedData[];
|
|
72
|
+
avatar?: AvatarType;
|
|
73
|
+
initialPhrase?: string;
|
|
74
|
+
finalPhrase?: string;
|
|
75
|
+
providedData?: Record<string, string>;
|
|
76
|
+
avatarId?: string;
|
|
77
|
+
voiceId?: string;
|
|
78
|
+
lang?: Lang;
|
|
79
|
+
zone?: Zone;
|
|
80
|
+
}
|
|
81
|
+
export interface CreateSessionResponse {
|
|
82
|
+
session: Session;
|
|
83
|
+
clientSecret: ClientSecret;
|
|
84
|
+
}
|
|
85
|
+
export declare const createSessionEndpoint: {
|
|
86
|
+
readonly method: Method.POST;
|
|
87
|
+
readonly pathParams: readonly [];
|
|
88
|
+
readonly queryParams: readonly [];
|
|
89
|
+
readonly bodyParams: readonly ["clientReferenceId", "metadata", "requestedData", "avatar", "initialPhrase", "finalPhrase", "providedData", "avatarId", "voiceId", "lang", "zone"];
|
|
90
|
+
readonly path: () => string;
|
|
91
|
+
};
|
|
92
|
+
type GetSessionPathParameters = {
|
|
93
|
+
sessionId: string;
|
|
94
|
+
};
|
|
95
|
+
export declare const getSessionEndpoint: {
|
|
96
|
+
readonly method: Method.GET;
|
|
97
|
+
readonly pathParams: readonly ["sessionId"];
|
|
98
|
+
readonly queryParams: readonly [];
|
|
99
|
+
readonly bodyParams: readonly [];
|
|
100
|
+
readonly path: (p: GetSessionPathParameters) => string;
|
|
101
|
+
};
|
|
102
|
+
export declare const createClientSecretEndpoint: {
|
|
103
|
+
readonly method: Method.GET;
|
|
104
|
+
readonly pathParams: readonly ["sessionId"];
|
|
105
|
+
readonly queryParams: readonly [];
|
|
106
|
+
readonly bodyParams: readonly [];
|
|
107
|
+
readonly path: (p: GetSessionPathParameters) => string;
|
|
108
|
+
};
|
|
109
|
+
export {};
|
|
110
|
+
//# sourceMappingURL=api-endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":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;;;;uBAKnB,wBAAwB,KAAG,MAAM;CACnC,CAAA;AAEV,eAAO,MAAM,0BAA0B;;;;;uBAK3B,wBAAwB,KAAG,MAAM;CAEnC,CAAA"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClientSecretEndpoint = exports.getSessionEndpoint = exports.createSessionEndpoint = exports.SessionStatus = exports.Method = exports.ILogLevel = void 0;
|
|
4
|
+
var ILogLevel;
|
|
5
|
+
(function (ILogLevel) {
|
|
6
|
+
ILogLevel["TRACE"] = "TRACE";
|
|
7
|
+
ILogLevel["DEBUG"] = " DEBUG";
|
|
8
|
+
ILogLevel["INFO"] = "INFO";
|
|
9
|
+
ILogLevel["WARN"] = "WARN";
|
|
10
|
+
ILogLevel["ERROR"] = "ERROR";
|
|
11
|
+
ILogLevel["OFF"] = "OFF";
|
|
12
|
+
})(ILogLevel = exports.ILogLevel || (exports.ILogLevel = {}));
|
|
13
|
+
var Method;
|
|
14
|
+
(function (Method) {
|
|
15
|
+
Method["GET"] = "get";
|
|
16
|
+
Method["POST"] = "post";
|
|
17
|
+
Method["PATCH"] = "patch";
|
|
18
|
+
Method["DELTE"] = "delete";
|
|
19
|
+
})(Method = exports.Method || (exports.Method = {}));
|
|
20
|
+
var SessionStatus;
|
|
21
|
+
(function (SessionStatus) {
|
|
22
|
+
SessionStatus["RequiresInput"] = "requiresInput";
|
|
23
|
+
SessionStatus["Processing"] = "processing";
|
|
24
|
+
SessionStatus["Canceled"] = "canceled";
|
|
25
|
+
SessionStatus["Complete"] = "complete";
|
|
26
|
+
})(SessionStatus = exports.SessionStatus || (exports.SessionStatus = {}));
|
|
27
|
+
exports.createSessionEndpoint = {
|
|
28
|
+
method: Method.POST,
|
|
29
|
+
pathParams: [],
|
|
30
|
+
queryParams: [],
|
|
31
|
+
bodyParams: [
|
|
32
|
+
'clientReferenceId',
|
|
33
|
+
'metadata',
|
|
34
|
+
'requestedData',
|
|
35
|
+
'avatar',
|
|
36
|
+
'initialPhrase',
|
|
37
|
+
'finalPhrase',
|
|
38
|
+
'providedData',
|
|
39
|
+
'avatarId',
|
|
40
|
+
'voiceId',
|
|
41
|
+
'lang',
|
|
42
|
+
'zone',
|
|
43
|
+
],
|
|
44
|
+
path: () => '/sessions',
|
|
45
|
+
};
|
|
46
|
+
exports.getSessionEndpoint = {
|
|
47
|
+
method: Method.GET,
|
|
48
|
+
pathParams: ['sessionId'],
|
|
49
|
+
queryParams: [],
|
|
50
|
+
bodyParams: [],
|
|
51
|
+
path: (p) => `/sessions/${p.sessionId}`,
|
|
52
|
+
};
|
|
53
|
+
exports.createClientSecretEndpoint = {
|
|
54
|
+
method: Method.GET,
|
|
55
|
+
pathParams: ['sessionId'],
|
|
56
|
+
queryParams: [],
|
|
57
|
+
bodyParams: [],
|
|
58
|
+
path: (p) => `/sessions/${p.sessionId}/refresh`,
|
|
59
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { SessionSettings, CreateSessionResponse, Method, ClientOptions, GetSessionParameters, GetSessionResponse, CreateClientSecretParameters, ClientSecret } from './api-endpoints';
|
|
3
|
+
type QueryParams = Record<string, string | number | string[]> | URLSearchParams;
|
|
4
|
+
export interface RequestParameters {
|
|
5
|
+
path: string;
|
|
6
|
+
method: Method;
|
|
7
|
+
query?: QueryParams;
|
|
8
|
+
body?: Record<string, unknown>;
|
|
9
|
+
auth?: string;
|
|
10
|
+
}
|
|
11
|
+
declare class Client {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options?: ClientOptions);
|
|
14
|
+
private setLogLevel;
|
|
15
|
+
private request;
|
|
16
|
+
readonly session: {
|
|
17
|
+
/**
|
|
18
|
+
* Create an identity verification session
|
|
19
|
+
*/
|
|
20
|
+
create: (args: SessionSettings) => Promise<CreateSessionResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve the identity verification session
|
|
23
|
+
*/
|
|
24
|
+
retrieve: (args: GetSessionParameters) => Promise<GetSessionResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Generate client secret for the specified session
|
|
27
|
+
*/
|
|
28
|
+
createClientSecret: (args: CreateClientSecretParameters) => Promise<ClientSecret>;
|
|
29
|
+
apiVersion: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export default Client;
|
|
33
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";AAGA,OAAO,EAEL,eAAe,EACf,qBAAqB,EACrB,MAAM,EAEN,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,4BAA4B,EAE5B,YAAY,EAEb,MAAM,iBAAiB,CAAA;AAIxB,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,eAAe,CAAA;AAE/E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,WAAW,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,cAAM,MAAM;;gBAOU,OAAO,CAAC,EAAE,aAAa;IAe3C,OAAO,CAAC,WAAW;YA6BL,OAAO;IA2ErB,SAAgB,OAAO;QACrB;;WAEG;uBACY,eAAe,KAAG,QAAQ,qBAAqB,CAAC;QAQ/D;;WAEG;yBACc,oBAAoB,KAAG,QAAQ,kBAAkB,CAAC;QAQnE;;WAEG;mCACwB,4BAA4B;;MASxD;CACF;AAED,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _Client_auth, _Client_timeoutMs, _Client_facesignVersion, _Client_fetch, _Client_serverUrl;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const loglevel_1 = __importDefault(require("loglevel"));
|
|
19
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
20
|
+
const helpers_1 = require("./helpers");
|
|
21
|
+
const api_endpoints_1 = require("./api-endpoints");
|
|
22
|
+
const utils_1 = require("./utils");
|
|
23
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
24
|
+
class Client {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
var _a;
|
|
27
|
+
_Client_auth.set(this, void 0);
|
|
28
|
+
_Client_timeoutMs.set(this, 10000);
|
|
29
|
+
_Client_facesignVersion.set(this, '2024-10-11');
|
|
30
|
+
_Client_fetch.set(this, node_fetch_1.default);
|
|
31
|
+
_Client_serverUrl.set(this, 'https://api.facesign.ai');
|
|
32
|
+
this.session = {
|
|
33
|
+
/**
|
|
34
|
+
* Create an identity verification session
|
|
35
|
+
*/
|
|
36
|
+
create: (args) => {
|
|
37
|
+
return this.request({
|
|
38
|
+
path: api_endpoints_1.createSessionEndpoint.path(),
|
|
39
|
+
method: api_endpoints_1.createSessionEndpoint.method,
|
|
40
|
+
query: (0, utils_1.pick)(args, api_endpoints_1.createSessionEndpoint.queryParams),
|
|
41
|
+
body: (0, utils_1.pick)(args, api_endpoints_1.createSessionEndpoint.bodyParams),
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve the identity verification session
|
|
46
|
+
*/
|
|
47
|
+
retrieve: (args) => {
|
|
48
|
+
return this.request({
|
|
49
|
+
path: api_endpoints_1.getSessionEndpoint.path(args),
|
|
50
|
+
method: api_endpoints_1.getSessionEndpoint.method,
|
|
51
|
+
query: (0, utils_1.pick)(args, api_endpoints_1.getSessionEndpoint.queryParams),
|
|
52
|
+
body: (0, utils_1.pick)(args, api_endpoints_1.getSessionEndpoint.bodyParams),
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Generate client secret for the specified session
|
|
57
|
+
*/
|
|
58
|
+
createClientSecret: (args) => {
|
|
59
|
+
return this.request({
|
|
60
|
+
path: api_endpoints_1.createClientSecretEndpoint.path(args),
|
|
61
|
+
method: api_endpoints_1.createClientSecretEndpoint.method,
|
|
62
|
+
query: (0, utils_1.pick)(args, api_endpoints_1.createClientSecretEndpoint.queryParams),
|
|
63
|
+
body: (0, utils_1.pick)(args, api_endpoints_1.createClientSecretEndpoint.bodyParams),
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
apiVersion: package_json_1.default.version,
|
|
67
|
+
};
|
|
68
|
+
__classPrivateFieldSet(this, _Client_auth, options === null || options === void 0 ? void 0 : options.auth, "f");
|
|
69
|
+
__classPrivateFieldSet(this, _Client_timeoutMs, (_a = options === null || options === void 0 ? void 0 : options.timeoutMs) !== null && _a !== void 0 ? _a : 10000, "f");
|
|
70
|
+
if (options === null || options === void 0 ? void 0 : options.serverUrl) {
|
|
71
|
+
__classPrivateFieldSet(this, _Client_serverUrl, options.serverUrl, "f");
|
|
72
|
+
}
|
|
73
|
+
if (options && options.logLevel) {
|
|
74
|
+
this.setLogLevel(options.logLevel);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
loglevel_1.default.disableAll();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
setLogLevel(logLevel) {
|
|
81
|
+
switch (logLevel) {
|
|
82
|
+
case api_endpoints_1.ILogLevel.DEBUG: {
|
|
83
|
+
loglevel_1.default.setLevel(loglevel_1.default.levels.DEBUG);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case api_endpoints_1.ILogLevel.TRACE: {
|
|
87
|
+
loglevel_1.default.setLevel(loglevel_1.default.levels.TRACE);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
case api_endpoints_1.ILogLevel.INFO: {
|
|
91
|
+
loglevel_1.default.setLevel(loglevel_1.default.levels.INFO);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case api_endpoints_1.ILogLevel.WARN: {
|
|
95
|
+
loglevel_1.default.setLevel(loglevel_1.default.levels.WARN);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case api_endpoints_1.ILogLevel.ERROR: {
|
|
99
|
+
loglevel_1.default.setLevel(loglevel_1.default.levels.ERROR);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case api_endpoints_1.ILogLevel.OFF: {
|
|
103
|
+
loglevel_1.default.disableAll();
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async request({ path, method, query, body, }) {
|
|
109
|
+
loglevel_1.default.debug('request start', { method, path });
|
|
110
|
+
const bodyAsJsonString = !body || Object.entries(body).length === 0
|
|
111
|
+
? undefined
|
|
112
|
+
: JSON.stringify(body);
|
|
113
|
+
const url = new URL(`${__classPrivateFieldGet(this, _Client_serverUrl, "f")}${path}`);
|
|
114
|
+
loglevel_1.default.debug('endpoint url', url);
|
|
115
|
+
if (query) {
|
|
116
|
+
for (const [key, value] of Object.entries(query)) {
|
|
117
|
+
if (value !== undefined) {
|
|
118
|
+
if (Array.isArray(value)) {
|
|
119
|
+
value.forEach(val => url.searchParams.append(key, decodeURIComponent(val)));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
url.searchParams.append(key, String(value));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const headers = {
|
|
128
|
+
'Facesign-Version': __classPrivateFieldGet(this, _Client_facesignVersion, "f"),
|
|
129
|
+
};
|
|
130
|
+
if (__classPrivateFieldGet(this, _Client_auth, "f")) {
|
|
131
|
+
headers['authorization'] = `Bearer ${__classPrivateFieldGet(this, _Client_auth, "f")}`;
|
|
132
|
+
}
|
|
133
|
+
if (bodyAsJsonString !== undefined) {
|
|
134
|
+
headers['content-type'] = 'application/json';
|
|
135
|
+
}
|
|
136
|
+
headers['x-facesign-api-version'] = package_json_1.default.version;
|
|
137
|
+
try {
|
|
138
|
+
const response = await (0, helpers_1.rejectAfterTimeout)(__classPrivateFieldGet(this, _Client_fetch, "f").call(this, url.toString(), {
|
|
139
|
+
method: method.toUpperCase(),
|
|
140
|
+
headers,
|
|
141
|
+
body: bodyAsJsonString,
|
|
142
|
+
}), __classPrivateFieldGet(this, _Client_timeoutMs, "f"));
|
|
143
|
+
const responseText = await response.text();
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
loglevel_1.default.error('request error', {
|
|
146
|
+
status: response.status,
|
|
147
|
+
statusText: response.statusText,
|
|
148
|
+
responseText,
|
|
149
|
+
});
|
|
150
|
+
throw new Error(responseText);
|
|
151
|
+
}
|
|
152
|
+
const responseJson = JSON.parse(responseText);
|
|
153
|
+
loglevel_1.default.debug('request success', { method, path });
|
|
154
|
+
return responseJson;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
loglevel_1.default.warn('request fail', {
|
|
158
|
+
error,
|
|
159
|
+
});
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
_Client_auth = new WeakMap(), _Client_timeoutMs = new WeakMap(), _Client_facesignVersion = new WeakMap(), _Client_fetch = new WeakMap(), _Client_serverUrl = new WeakMap();
|
|
165
|
+
exports.default = Client;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,cAAc,oCAAoC;IAClD,aAAa,mCAAmC;CACjD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientErrorCode = void 0;
|
|
4
|
+
var ClientErrorCode;
|
|
5
|
+
(function (ClientErrorCode) {
|
|
6
|
+
ClientErrorCode["RequestTimeout"] = "facesign_client_request_timeout";
|
|
7
|
+
ClientErrorCode["ResponseError"] = "facesign_client_response_error";
|
|
8
|
+
})(ClientErrorCode = exports.ClientErrorCode || (exports.ClientErrorCode = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,sCAElB,MAAM,eAYlB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rejectAfterTimeout = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const rejectAfterTimeout = (promise, timeoutMS) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const timeoutId = setTimeout(() => {
|
|
8
|
+
reject(errors_1.ClientErrorCode.RequestTimeout);
|
|
9
|
+
}, timeoutMS);
|
|
10
|
+
promise
|
|
11
|
+
.then(resolve)
|
|
12
|
+
.catch(reject)
|
|
13
|
+
.then(() => clearTimeout(timeoutId));
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.rejectAfterTimeout = rejectAfterTimeout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,UAAU,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,eAAe,MAAM,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
const client_1 = __importDefault(require("./client"));
|
|
21
|
+
__exportStar(require("./api-endpoints"), exports);
|
|
22
|
+
exports.default = client_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,MAAM,CAAC,GAAG,KAAK,CAAA;AAErD,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAC1C,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,SAAS,CAAC,EAAE,GACjB,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAGZ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pick = void 0;
|
|
4
|
+
function pick(base, keys) {
|
|
5
|
+
const entries = keys.map(key => [key, base === null || base === void 0 ? void 0 : base[key]]);
|
|
6
|
+
return Object.fromEntries(entries);
|
|
7
|
+
}
|
|
8
|
+
exports.pick = pick;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@facesignai/api",
|
|
3
|
+
"package-name": "@facesignai/api",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "Facesign API wrapper",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@github.com/facesignai/facesign-api.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Facesign <support@facesign.ai> (https://facesign.ai/)",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"private": false,
|
|
13
|
+
"main": "./build/src/index.js",
|
|
14
|
+
"types": "./build/src/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"build/src/package.json",
|
|
17
|
+
"build/**"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=12"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"prepare": "npm run build",
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"prettier": "prettier --write .",
|
|
26
|
+
"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
|
|
27
|
+
"test": "jest ./test",
|
|
28
|
+
"prebuild": "npm run clean",
|
|
29
|
+
"clean": "rm -rf ./build"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@types/node-fetch": "^2.5.10",
|
|
33
|
+
"loglevel": "^1.9.1",
|
|
34
|
+
"node-fetch": "^2.6.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^28.1.4",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^5.39.0",
|
|
39
|
+
"@typescript-eslint/parser": "^5.39.0",
|
|
40
|
+
"cspell": "^5.4.1",
|
|
41
|
+
"eslint": "^7.24.0",
|
|
42
|
+
"jest": "^28.1.2",
|
|
43
|
+
"prettier": "^2.8.8",
|
|
44
|
+
"ts-jest": "^28.0.5",
|
|
45
|
+
"typescript": "^4.8.4"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/facesignai/facesign-api/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/facesignai/facesign-api#readme"
|
|
51
|
+
}
|