theauthapi 1.0.4 → 1.0.7
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/README.md +284 -2
- package/dist/endpoints/Accounts/Accounts.d.ts +10 -0
- package/dist/endpoints/Accounts/Accounts.js +26 -0
- package/dist/endpoints/Accounts/AccountsInterface.d.ts +4 -0
- package/dist/endpoints/Accounts/AccountsInterface.js +2 -0
- package/dist/endpoints/ApiKeys/ApiKeys.d.ts +16 -0
- package/dist/endpoints/ApiKeys/ApiKeys.js +91 -0
- package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +9 -0
- package/dist/endpoints/ApiKeys/ApiKeysInterface.js +2 -0
- package/dist/endpoints/Projects/Projects.d.ts +16 -0
- package/dist/endpoints/Projects/Projects.js +68 -0
- package/dist/endpoints/Projects/ProjectsInterface.d.ts +8 -0
- package/dist/endpoints/Projects/ProjectsInterface.js +2 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +89 -0
- package/dist/libraryMeta.d.ts +1 -0
- package/dist/libraryMeta.js +4 -0
- package/dist/services/ApiRequest/ApiCall.d.ts +5 -0
- package/dist/services/ApiRequest/ApiCall.js +2 -0
- package/dist/services/ApiRequest/ApiRequest.d.ts +26 -0
- package/dist/services/ApiRequest/ApiRequest.js +117 -0
- package/dist/services/ApiRequest/ApiRequestError.d.ts +10 -0
- package/dist/services/ApiRequest/ApiRequestError.js +15 -0
- package/dist/services/ApiRequest/ApiResponseError.d.ts +12 -0
- package/dist/services/ApiRequest/ApiResponseError.js +17 -0
- package/dist/services/ApiRequest/HttpMethod.d.ts +7 -0
- package/dist/services/ApiRequest/HttpMethod.js +11 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types/index.js +13 -0
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +13 -0
- package/package.json +4 -9
- package/.eslintrc.js +0 -15
- package/.prettierrc.json +0 -1
- package/jest.config.js +0 -5
- package/jest.setup.ts +0 -0
- package/src/endpoints/ApiKeys/ApiKeys.ts +0 -68
- package/src/endpoints/ApiKeys/ApiKeysInterface.ts +0 -11
- package/src/endpoints/Projects/Projects.ts +0 -62
- package/src/endpoints/Projects/ProjectsInterface.ts +0 -9
- package/src/index.ts +0 -103
- package/src/libraryMeta.ts +0 -1
- package/src/services/ApiRequest/ApiCall.ts +0 -7
- package/src/services/ApiRequest/ApiRequest.ts +0 -132
- package/src/services/ApiRequest/ApiRequestError.ts +0 -7
- package/src/services/ApiRequest/HttpMethod.ts +0 -7
- package/src/tests/endpoints/apiKeys.spec.ts +0 -102
- package/src/tests/endpoints/projects.spec.ts +0 -105
- package/src/tests/index.spec.ts +0 -35
- package/src/tests/testServer/middleware/middleware.ts +0 -17
- package/src/tests/testServer/routes/apiKeys.ts +0 -89
- package/src/tests/testServer/routes/auth.ts +0 -24
- package/src/tests/testServer/routes/projects.ts +0 -87
- package/src/tests/testServer/server.ts +0 -16
- package/src/types/index.ts +0 -59
- package/src/util/index.ts +0 -7
- package/tsconfig.json +0 -102
package/dist/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const assert_1 = __importDefault(require("assert"));
|
|
16
|
+
const remove_trailing_slash_1 = __importDefault(require("remove-trailing-slash"));
|
|
17
|
+
const ApiRequest_1 = __importDefault(require("./services/ApiRequest/ApiRequest"));
|
|
18
|
+
const util_1 = require("./util");
|
|
19
|
+
const ApiKeys_1 = __importDefault(require("./endpoints/ApiKeys/ApiKeys"));
|
|
20
|
+
const HttpMethod_1 = require("./services/ApiRequest/HttpMethod");
|
|
21
|
+
const Projects_1 = __importDefault(require("./endpoints/Projects/Projects"));
|
|
22
|
+
const Accounts_1 = __importDefault(require("./endpoints/Accounts/Accounts"));
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
24
|
+
const noop = () => { };
|
|
25
|
+
class TheAuthAPI {
|
|
26
|
+
/**
|
|
27
|
+
* Initialize a new `Analytics` with your Segment project's `writeKey` and an
|
|
28
|
+
* optional dictionary of `options`.
|
|
29
|
+
*
|
|
30
|
+
* @param {String} accessKey
|
|
31
|
+
* @param {Object} [options] (optional)
|
|
32
|
+
* @property {Number} flushAt (default: 20)
|
|
33
|
+
* @property {Number} flushInterval (default: 10000)
|
|
34
|
+
* @property {String} host (default: 'https://api.segment.io')
|
|
35
|
+
* @property {Boolean} enable (default: true)
|
|
36
|
+
*/
|
|
37
|
+
constructor(accessKey, options) {
|
|
38
|
+
var _a;
|
|
39
|
+
(0, assert_1.default)(accessKey, "You must pass your project's write key.");
|
|
40
|
+
this.queue = [];
|
|
41
|
+
this.accessKey = accessKey;
|
|
42
|
+
this.host = (0, remove_trailing_slash_1.default)((options === null || options === void 0 ? void 0 : options.host) || "https://api.theauthapi.com");
|
|
43
|
+
this.timeout = options === null || options === void 0 ? void 0 : options.timeout;
|
|
44
|
+
this.cacheTTL = (_a = options === null || options === void 0 ? void 0 : options.cacheTTL) !== null && _a !== void 0 ? _a : 60;
|
|
45
|
+
this.api = new ApiRequest_1.default({
|
|
46
|
+
accessKey: this.accessKey,
|
|
47
|
+
host: this.host,
|
|
48
|
+
});
|
|
49
|
+
this.apiKeys = new ApiKeys_1.default(this.api);
|
|
50
|
+
this.projects = new Projects_1.default(this.api);
|
|
51
|
+
this.accounts = new Accounts_1.default(this.api);
|
|
52
|
+
Object.defineProperty(this, "enable", {
|
|
53
|
+
configurable: false,
|
|
54
|
+
writable: false,
|
|
55
|
+
enumerable: true,
|
|
56
|
+
value: typeof (options === null || options === void 0 ? void 0 : options.enable) === "boolean" ? options.enable : true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
/*
|
|
60
|
+
@deprecated
|
|
61
|
+
*/
|
|
62
|
+
authenticateAPIKey(key, callback) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
(0, util_1.validateString)("key", key);
|
|
65
|
+
const cb = callback || noop;
|
|
66
|
+
const done = (err) => {
|
|
67
|
+
cb(err, data);
|
|
68
|
+
};
|
|
69
|
+
const data = {
|
|
70
|
+
credentials: { api_key: key },
|
|
71
|
+
timestamp: new Date().getTime(),
|
|
72
|
+
sentAt: new Date().getTime(),
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
const key = yield this.api.request(HttpMethod_1.HttpMethod.POST, "/auth/authenticate", data);
|
|
76
|
+
done(key);
|
|
77
|
+
return key;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
if (err.response) {
|
|
81
|
+
const error = new Error(err.response.statusText);
|
|
82
|
+
return done(error);
|
|
83
|
+
}
|
|
84
|
+
done(err);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.default = TheAuthAPI;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.0.6";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HttpMethod } from "./HttpMethod";
|
|
2
|
+
import ApiCall from "./ApiCall";
|
|
3
|
+
declare type Config = {
|
|
4
|
+
host: string;
|
|
5
|
+
accessKey: string;
|
|
6
|
+
headers?: object;
|
|
7
|
+
retryCount?: number;
|
|
8
|
+
timeout?: number | string;
|
|
9
|
+
};
|
|
10
|
+
declare class ApiRequest implements ApiCall {
|
|
11
|
+
host: string;
|
|
12
|
+
headers: object;
|
|
13
|
+
accessKey: string;
|
|
14
|
+
timeout: number;
|
|
15
|
+
retryCount: number;
|
|
16
|
+
constructor(config: Config);
|
|
17
|
+
_init(): void;
|
|
18
|
+
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
19
|
+
_generateDefaultHeaders(): {
|
|
20
|
+
"user-agent": string;
|
|
21
|
+
"x-api-key": string;
|
|
22
|
+
"api-key": string;
|
|
23
|
+
};
|
|
24
|
+
_isErrorRetryable(error: any): boolean;
|
|
25
|
+
}
|
|
26
|
+
export default ApiRequest;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const libraryMeta_1 = require("../../libraryMeta");
|
|
17
|
+
const ApiRequestError_1 = __importDefault(require("./ApiRequestError"));
|
|
18
|
+
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
19
|
+
const ms_1 = __importDefault(require("ms"));
|
|
20
|
+
const ApiResponseError_1 = __importDefault(require("./ApiResponseError"));
|
|
21
|
+
class ApiRequest {
|
|
22
|
+
constructor(config) {
|
|
23
|
+
const { host, accessKey, headers, retryCount, timeout } = config;
|
|
24
|
+
this.host = host;
|
|
25
|
+
this.accessKey = accessKey;
|
|
26
|
+
this.headers = this._generateDefaultHeaders();
|
|
27
|
+
this.timeout = timeout ? (typeof timeout === "string" ? (0, ms_1.default)(timeout) : timeout) : 0;
|
|
28
|
+
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
29
|
+
if (headers) {
|
|
30
|
+
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
31
|
+
}
|
|
32
|
+
this._init();
|
|
33
|
+
}
|
|
34
|
+
_init() {
|
|
35
|
+
var _a;
|
|
36
|
+
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
37
|
+
function isIsoDateString(value) {
|
|
38
|
+
return value && typeof value === "string" && isoDateFormat.test(value);
|
|
39
|
+
}
|
|
40
|
+
function handleDates(body) {
|
|
41
|
+
if (body === null || body === undefined || typeof body !== "object") {
|
|
42
|
+
return body;
|
|
43
|
+
}
|
|
44
|
+
for (const key of Object.keys(body)) {
|
|
45
|
+
const value = body[key];
|
|
46
|
+
if (isIsoDateString(value)) {
|
|
47
|
+
body[key] = new Date(value);
|
|
48
|
+
}
|
|
49
|
+
else if (typeof value === "object") {
|
|
50
|
+
handleDates(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
axios_1.default.interceptors.response.use((response) => {
|
|
55
|
+
handleDates(response.data);
|
|
56
|
+
return response;
|
|
57
|
+
});
|
|
58
|
+
(0, axios_retry_1.default)(axios_1.default, {
|
|
59
|
+
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
60
|
+
retryCondition: this._isErrorRetryable,
|
|
61
|
+
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
request(method, endpoint, payload) {
|
|
65
|
+
var _a;
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
try {
|
|
68
|
+
const response = yield axios_1.default.request({
|
|
69
|
+
baseURL: this.host,
|
|
70
|
+
method: method,
|
|
71
|
+
url: endpoint,
|
|
72
|
+
data: payload,
|
|
73
|
+
headers: this.headers,
|
|
74
|
+
});
|
|
75
|
+
return response.data;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
79
|
+
if (error.response) {
|
|
80
|
+
throw new ApiResponseError_1.default(error.response.status, (_a = error.response.data.message) !== null && _a !== void 0 ? _a : error.response.statusText);
|
|
81
|
+
}
|
|
82
|
+
else if (error.request) {
|
|
83
|
+
throw new ApiRequestError_1.default(error.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
_generateDefaultHeaders() {
|
|
91
|
+
return {
|
|
92
|
+
"user-agent": `theauthapi-client-node/${libraryMeta_1.version}`,
|
|
93
|
+
"x-api-key": this.accessKey,
|
|
94
|
+
"api-key": this.accessKey,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
_isErrorRetryable(error) {
|
|
98
|
+
// Retry Network Errors.
|
|
99
|
+
if (axios_retry_1.default.isNetworkError(error)) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
if (!error.response) {
|
|
103
|
+
// Cannot determine if the request can be retried
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
// Retry Server Errors (5xx).
|
|
107
|
+
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
// Retry if rate limited.
|
|
111
|
+
if (error.response.status === 429) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = ApiRequest;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Throws when no response was received from the server
|
|
6
|
+
* @param message - error message
|
|
7
|
+
*
|
|
8
|
+
* */
|
|
9
|
+
class ApiRequestError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = 'ApiRequestError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.default = ApiRequestError;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
4
|
+
* @param statusCode - HTTP status code the server responded with
|
|
5
|
+
* @param message - error message
|
|
6
|
+
*
|
|
7
|
+
* */
|
|
8
|
+
declare class ApiResponseError extends Error {
|
|
9
|
+
statusCode: number;
|
|
10
|
+
constructor(statusCode: number, message: string);
|
|
11
|
+
}
|
|
12
|
+
export default ApiResponseError;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
6
|
+
* @param statusCode - HTTP status code the server responded with
|
|
7
|
+
* @param message - error message
|
|
8
|
+
*
|
|
9
|
+
* */
|
|
10
|
+
class ApiResponseError extends Error {
|
|
11
|
+
constructor(statusCode, message) {
|
|
12
|
+
super(`(${statusCode}): ${message}`);
|
|
13
|
+
this.statusCode = statusCode;
|
|
14
|
+
this.name = "ApiResponseError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.default = ApiResponseError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpMethod = void 0;
|
|
4
|
+
var HttpMethod;
|
|
5
|
+
(function (HttpMethod) {
|
|
6
|
+
HttpMethod["GET"] = "GET";
|
|
7
|
+
HttpMethod["POST"] = "POST";
|
|
8
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
9
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
10
|
+
HttpMethod["PUT"] = "PUT";
|
|
11
|
+
})(HttpMethod = exports.HttpMethod || (exports.HttpMethod = {}));
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export declare type ApiKey = {
|
|
2
|
+
key: string;
|
|
3
|
+
name: string;
|
|
4
|
+
customMetaData: string;
|
|
5
|
+
customAccountId: string;
|
|
6
|
+
env: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
};
|
|
10
|
+
export declare type RateLimitConfiguration = {
|
|
11
|
+
rateLimitedEntity?: string;
|
|
12
|
+
ratelimitedEnitityId?: any;
|
|
13
|
+
rateLimit: number;
|
|
14
|
+
rateLimitTtl: number;
|
|
15
|
+
};
|
|
16
|
+
export declare type ApiKeyInput = {
|
|
17
|
+
name: string;
|
|
18
|
+
projectId: string;
|
|
19
|
+
key?: string;
|
|
20
|
+
customMetaData?: object;
|
|
21
|
+
customAccountId?: string;
|
|
22
|
+
rateLimitConfigs?: RateLimitConfiguration;
|
|
23
|
+
customUserId?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type UpdateApiKeyInput = {
|
|
26
|
+
name: string;
|
|
27
|
+
customMetaData?: object;
|
|
28
|
+
customAccountId?: string;
|
|
29
|
+
};
|
|
30
|
+
export declare enum AuthedEntityType {
|
|
31
|
+
USER = "USER",
|
|
32
|
+
ACCESS_KEY = "ACCESS_KEY"
|
|
33
|
+
}
|
|
34
|
+
export declare type AuthBaseEntity = {
|
|
35
|
+
isActive: boolean;
|
|
36
|
+
createdBy: string;
|
|
37
|
+
createdByType?: AuthedEntityType;
|
|
38
|
+
createdIn: string;
|
|
39
|
+
lastChangedBy: string;
|
|
40
|
+
lastChangedByType?: AuthedEntityType;
|
|
41
|
+
updatedAt: Date;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
};
|
|
44
|
+
export declare type Project = AuthBaseEntity & {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
accountId: string;
|
|
48
|
+
env: string;
|
|
49
|
+
};
|
|
50
|
+
export declare enum Environment {
|
|
51
|
+
LIVE = "live",
|
|
52
|
+
TEST = "test"
|
|
53
|
+
}
|
|
54
|
+
export declare type CreateProjectInput = {
|
|
55
|
+
name: string;
|
|
56
|
+
accountId: string;
|
|
57
|
+
env: Environment;
|
|
58
|
+
};
|
|
59
|
+
export declare type UpdateProjectInput = {
|
|
60
|
+
name: string;
|
|
61
|
+
};
|
|
62
|
+
export declare type Account = AuthBaseEntity & {
|
|
63
|
+
id: string;
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Environment = exports.AuthedEntityType = void 0;
|
|
4
|
+
var AuthedEntityType;
|
|
5
|
+
(function (AuthedEntityType) {
|
|
6
|
+
AuthedEntityType["USER"] = "USER";
|
|
7
|
+
AuthedEntityType["ACCESS_KEY"] = "ACCESS_KEY";
|
|
8
|
+
})(AuthedEntityType = exports.AuthedEntityType || (exports.AuthedEntityType = {}));
|
|
9
|
+
var Environment;
|
|
10
|
+
(function (Environment) {
|
|
11
|
+
Environment["LIVE"] = "live";
|
|
12
|
+
Environment["TEST"] = "test";
|
|
13
|
+
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function validateString(variableName: string, value: string): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateString = void 0;
|
|
7
|
+
const lodash_isstring_1 = __importDefault(require("lodash.isstring"));
|
|
8
|
+
function validateString(variableName, value) {
|
|
9
|
+
if (!value || !(0, lodash_isstring_1.default)(value)) {
|
|
10
|
+
throw new TypeError(`${variableName} must be a string, got: ${value}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.validateString = validateString;
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theauthapi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Client library for TheAuthAPI.com",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "jest --runInBand",
|
|
9
12
|
"test:coverage": "jest --coverage --runInBand",
|
|
@@ -52,13 +55,5 @@
|
|
|
52
55
|
"ts-jest": "^27.1.4",
|
|
53
56
|
"ts-node": "^10.7.0",
|
|
54
57
|
"typescript": "^4.6.3"
|
|
55
|
-
},
|
|
56
|
-
"ava": {
|
|
57
|
-
"extensions": [
|
|
58
|
-
"ts"
|
|
59
|
-
],
|
|
60
|
-
"require": [
|
|
61
|
-
"ts-node/register"
|
|
62
|
-
]
|
|
63
58
|
}
|
|
64
59
|
}
|
package/.eslintrc.js
DELETED
package/.prettierrc.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{}
|
package/jest.config.js
DELETED
package/jest.setup.ts
DELETED
|
File without changes
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { HttpMethod } from "../../services/ApiRequest/HttpMethod";
|
|
2
|
-
import omit from "lodash.omit";
|
|
3
|
-
import ApiRequest from "../../services/ApiRequest/ApiRequest";
|
|
4
|
-
import {ApiKey, ApiKeyInput, UpdateApiKeyInput} from "../../types";
|
|
5
|
-
import { validateString } from "../../util";
|
|
6
|
-
import ApiKeysInterface from "./ApiKeysInterface";
|
|
7
|
-
|
|
8
|
-
class ApiKeys implements ApiKeysInterface {
|
|
9
|
-
api: ApiRequest;
|
|
10
|
-
|
|
11
|
-
constructor(apiService: ApiRequest) {
|
|
12
|
-
this.api = apiService;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async authenticateKey(apikey: string) {
|
|
16
|
-
validateString("apikey", apikey);
|
|
17
|
-
return await this.api.request<ApiKey>(
|
|
18
|
-
HttpMethod.GET,
|
|
19
|
-
`/api-keys/${apikey}`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async getKeys(projectId: string) {
|
|
24
|
-
validateString("projectId", projectId);
|
|
25
|
-
return await this.api.request<ApiKey[]>(
|
|
26
|
-
HttpMethod.GET,
|
|
27
|
-
`/api-keys/?projectId=${projectId}`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async createKey(apiKey: ApiKeyInput) {
|
|
32
|
-
// validate string properties only
|
|
33
|
-
for (const [key, value] of Object.entries(
|
|
34
|
-
omit(apiKey, ["customMetaData", "rateLimitConfigs"])
|
|
35
|
-
)) {
|
|
36
|
-
validateString(key, value);
|
|
37
|
-
}
|
|
38
|
-
return await this.api.request<ApiKey>(
|
|
39
|
-
HttpMethod.POST,
|
|
40
|
-
"/api-keys",
|
|
41
|
-
apiKey
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async updateKey(apiKey: string, updateTo: UpdateApiKeyInput) {
|
|
46
|
-
validateString("apiKey", apiKey);
|
|
47
|
-
for (const [key, value] of Object.entries(
|
|
48
|
-
omit(updateTo, "customMetaData")
|
|
49
|
-
)) {
|
|
50
|
-
validateString(key, value);
|
|
51
|
-
}
|
|
52
|
-
return await this.api.request<ApiKey>(
|
|
53
|
-
HttpMethod.PATCH,
|
|
54
|
-
`/api-keys/${apiKey}`,
|
|
55
|
-
updateTo
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async deleteKey(apiKey: string) {
|
|
60
|
-
validateString("apiKey", apiKey);
|
|
61
|
-
return await this.api.request<boolean>(
|
|
62
|
-
HttpMethod.DELETE,
|
|
63
|
-
`/api-keys/${apiKey}`
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export = ApiKeys;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApiKey, ApiKeyInput, UpdateApiKeyInput } from "../../types";
|
|
2
|
-
|
|
3
|
-
interface ApiKeysInterface {
|
|
4
|
-
authenticateKey(apiKey: string): Promise<ApiKey>;
|
|
5
|
-
getKeys(projectId: string): Promise<ApiKey[]>;
|
|
6
|
-
createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
|
|
7
|
-
updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
|
|
8
|
-
deleteKey(apiKey: string): Promise<boolean>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export = ApiKeysInterface;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import ApiRequest from "../../services/ApiRequest/ApiRequest";
|
|
2
|
-
import { Project, UpdateProjectInput } from "../../types";
|
|
3
|
-
import { HttpMethod } from "../../services/ApiRequest/HttpMethod";
|
|
4
|
-
import { validateString } from "../../util";
|
|
5
|
-
import { ProjectsInterface } from "./ProjectsInterface";
|
|
6
|
-
|
|
7
|
-
class Projects implements ProjectsInterface {
|
|
8
|
-
api: ApiRequest;
|
|
9
|
-
endpoint: string;
|
|
10
|
-
|
|
11
|
-
constructor(apiService: ApiRequest) {
|
|
12
|
-
this.api = apiService;
|
|
13
|
-
this.endpoint = "/projects";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async getProjects(accountId: string): Promise<Project[]> {
|
|
17
|
-
validateString("accountId", accountId);
|
|
18
|
-
return await this.api.request<Project[]>(
|
|
19
|
-
HttpMethod.GET,
|
|
20
|
-
`${this.endpoint}?accountId=${accountId}`
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async getProject(projectId: string): Promise<Project> {
|
|
25
|
-
validateString("projectId", projectId);
|
|
26
|
-
return await this.api.request<Project>(
|
|
27
|
-
HttpMethod.GET,
|
|
28
|
-
`${this.endpoint}/${projectId}`
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async deleteProject(projectId: string): Promise<boolean> {
|
|
33
|
-
validateString("projectId", projectId);
|
|
34
|
-
return await this.api.request<boolean>(
|
|
35
|
-
HttpMethod.DELETE,
|
|
36
|
-
`${this.endpoint}/${projectId}`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async createProject(name: string, accountId: string): Promise<Project> {
|
|
41
|
-
validateString("name", name);
|
|
42
|
-
validateString("accountId", accountId);
|
|
43
|
-
return await this.api.request<Project>(HttpMethod.POST, this.endpoint, {
|
|
44
|
-
name,
|
|
45
|
-
accountId,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async updateProject(
|
|
50
|
-
projectId: string,
|
|
51
|
-
updateTo: UpdateProjectInput
|
|
52
|
-
): Promise<Project> {
|
|
53
|
-
validateString("projectId", projectId);
|
|
54
|
-
return this.api.request<Project>(
|
|
55
|
-
HttpMethod.PATCH,
|
|
56
|
-
`${this.endpoint}/${projectId}`,
|
|
57
|
-
updateTo
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default Projects;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {Project, UpdateProjectInput} from "../../types";
|
|
2
|
-
|
|
3
|
-
export interface ProjectsInterface {
|
|
4
|
-
getProjects(accountId: string): Promise<Project[]>;
|
|
5
|
-
getProject(projectId: string): Promise<Project>;
|
|
6
|
-
deleteProject(projectId: string): Promise<boolean>;
|
|
7
|
-
createProject(name: string, accountId: string): Promise<Project>;
|
|
8
|
-
updateProject(name: string, updateTo: UpdateProjectInput): Promise<Project>;
|
|
9
|
-
}
|