theauthapi 1.0.16 → 1.0.18

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.
Files changed (36) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +2 -0
  3. package/dist/index.cjs +285 -283
  4. package/dist/index.d.cts +178 -178
  5. package/dist/index.d.mts +177 -177
  6. package/dist/index.mjs +285 -283
  7. package/dist/{types/index.d.ts → types.d.cts} +87 -85
  8. package/dist/types.d.ts +87 -0
  9. package/package.json +11 -2
  10. package/dist/endpoints/Accounts/Accounts.d.ts +0 -10
  11. package/dist/endpoints/Accounts/Accounts.js +0 -22
  12. package/dist/endpoints/Accounts/AccountsInterface.d.ts +0 -4
  13. package/dist/endpoints/Accounts/AccountsInterface.js +0 -1
  14. package/dist/endpoints/ApiKeys/ApiKeys.d.ts +0 -19
  15. package/dist/endpoints/ApiKeys/ApiKeys.js +0 -80
  16. package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +0 -12
  17. package/dist/endpoints/ApiKeys/ApiKeysInterface.js +0 -1
  18. package/dist/endpoints/Projects/Projects.d.ts +0 -14
  19. package/dist/endpoints/Projects/Projects.js +0 -42
  20. package/dist/endpoints/Projects/ProjectsInterface.d.ts +0 -8
  21. package/dist/endpoints/Projects/ProjectsInterface.js +0 -1
  22. package/dist/index.d.ts +0 -26
  23. package/dist/index.js +0 -69
  24. package/dist/libraryMeta.d.ts +0 -1
  25. package/dist/libraryMeta.js +0 -1
  26. package/dist/services/ApiRequest/ApiCall.d.ts +0 -5
  27. package/dist/services/ApiRequest/ApiCall.js +0 -1
  28. package/dist/services/ApiRequest/ApiRequest.d.ts +0 -24
  29. package/dist/services/ApiRequest/ApiRequest.js +0 -110
  30. package/dist/services/ApiRequest/ApiRequestError.d.ts +0 -10
  31. package/dist/services/ApiRequest/ApiRequestError.js +0 -13
  32. package/dist/services/ApiRequest/ApiResponseError.d.ts +0 -12
  33. package/dist/services/ApiRequest/ApiResponseError.js +0 -15
  34. package/dist/services/ApiRequest/HttpMethod.d.ts +0 -7
  35. package/dist/services/ApiRequest/HttpMethod.js +0 -8
  36. package/dist/types/index.js +0 -10
@@ -1,85 +1,87 @@
1
- export type ApiKey = {
2
- key: string;
3
- name: string;
4
- customMetaData: AnyJson;
5
- customAccountId: string;
6
- customUserId: string;
7
- env: Environment;
8
- createdAt: Date;
9
- updatedAt: Date;
10
- isActive: boolean;
11
- rateLimitConfigs: RateLimitConfiguration;
12
- expiry: Date;
13
- };
14
- export type RateLimitConfiguration = {
15
- rateLimit: number;
16
- rateLimitTtl: number;
17
- };
18
- export type ApiKeyInput = {
19
- name: string;
20
- projectId?: string;
21
- key?: string;
22
- customMetaData?: AnyJson;
23
- customAccountId?: string;
24
- customUserId?: string;
25
- rateLimitConfigs?: RateLimitConfiguration;
26
- expiry?: Date;
27
- };
28
- export type ApiKeyFilter = {
29
- projectId?: string;
30
- name?: string;
31
- customAccountId?: string | null;
32
- customUserId?: string | null;
33
- isActive?: boolean;
34
- };
35
- export type UpdateApiKeyInput = {
36
- name: string;
37
- key?: string;
38
- customMetaData?: AnyJson;
39
- customAccountId?: string;
40
- customUserId?: string;
41
- expiry?: Date | null;
42
- rateLimitConfigs?: RateLimitConfiguration | null;
43
- };
44
- export declare enum AuthedEntityType {
45
- USER = "USER",
46
- ACCESS_KEY = "ACCESS_KEY"
47
- }
48
- export type AuthBaseEntity = {
49
- isActive: boolean;
50
- createdBy: string;
51
- createdByType?: AuthedEntityType;
52
- createdIn: string;
53
- lastChangedBy: string;
54
- lastChangedByType?: AuthedEntityType;
55
- updatedAt: Date;
56
- createdAt: Date;
57
- };
58
- export type Project = AuthBaseEntity & {
59
- id: string;
60
- name: string;
61
- accountId: string;
62
- env: Environment;
63
- };
64
- export declare enum Environment {
65
- LIVE = "live",
66
- TEST = "test"
67
- }
68
- export type CreateProjectInput = {
69
- name: string;
70
- accountId: string;
71
- env: Environment;
72
- };
73
- export type UpdateProjectInput = {
74
- name: string;
75
- };
76
- export type Account = AuthBaseEntity & {
77
- id: string;
78
- name: string;
79
- };
80
- type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
81
- type JsonMap = {
82
- [key: string]: AnyJson;
83
- };
84
- type JsonArray = Array<AnyJson>;
85
- export {};
1
+ type ApiKey = {
2
+ key: string;
3
+ name: string;
4
+ customMetaData: AnyJson;
5
+ customAccountId: string;
6
+ customUserId: string;
7
+ env: Environment;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ isActive: boolean;
11
+ rateLimitConfigs: RateLimitConfiguration;
12
+ expiry: Date;
13
+ };
14
+ type RateLimitConfiguration = {
15
+ rateLimit: number;
16
+ rateLimitTtl: number;
17
+ };
18
+ type ApiKeyInput = {
19
+ name: string;
20
+ projectId?: string;
21
+ key?: string;
22
+ customMetaData?: AnyJson;
23
+ customAccountId?: string;
24
+ customUserId?: string;
25
+ rateLimitConfigs?: RateLimitConfiguration;
26
+ expiry?: Date;
27
+ };
28
+ type ApiKeyFilter = {
29
+ projectId?: string;
30
+ name?: string;
31
+ customAccountId?: string | null;
32
+ customUserId?: string | null;
33
+ isActive?: boolean;
34
+ };
35
+ type UpdateApiKeyInput = {
36
+ name: string;
37
+ key?: string;
38
+ customMetaData?: AnyJson;
39
+ customAccountId?: string;
40
+ customUserId?: string;
41
+ expiry?: Date | null;
42
+ rateLimitConfigs?: RateLimitConfiguration | null;
43
+ };
44
+ declare enum AuthedEntityType {
45
+ USER = "USER",
46
+ ACCESS_KEY = "ACCESS_KEY"
47
+ }
48
+ type AuthBaseEntity = {
49
+ isActive: boolean;
50
+ createdBy: string;
51
+ createdByType?: AuthedEntityType;
52
+ createdIn: string;
53
+ lastChangedBy: string;
54
+ lastChangedByType?: AuthedEntityType;
55
+ updatedAt: Date;
56
+ createdAt: Date;
57
+ };
58
+ type Project = AuthBaseEntity & {
59
+ id: string;
60
+ name: string;
61
+ accountId: string;
62
+ env: Environment;
63
+ };
64
+ declare enum Environment {
65
+ LIVE = "live",
66
+ TEST = "test"
67
+ }
68
+ type CreateProjectInput = {
69
+ name: string;
70
+ accountId: string;
71
+ env: Environment;
72
+ };
73
+ type UpdateProjectInput = {
74
+ name: string;
75
+ };
76
+ type Account = AuthBaseEntity & {
77
+ id: string;
78
+ name: string;
79
+ };
80
+ type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
81
+ type JsonMap = {
82
+ [key: string]: AnyJson;
83
+ };
84
+ type JsonArray = Array<AnyJson>;
85
+
86
+ export { AuthedEntityType, Environment };
87
+ export type { Account, ApiKey, ApiKeyFilter, ApiKeyInput, AuthBaseEntity, CreateProjectInput, Project, RateLimitConfiguration, UpdateApiKeyInput, UpdateProjectInput };
@@ -0,0 +1,87 @@
1
+ type ApiKey = {
2
+ key: string;
3
+ name: string;
4
+ customMetaData: AnyJson;
5
+ customAccountId: string;
6
+ customUserId: string;
7
+ env: Environment;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ isActive: boolean;
11
+ rateLimitConfigs: RateLimitConfiguration;
12
+ expiry: Date;
13
+ };
14
+ type RateLimitConfiguration = {
15
+ rateLimit: number;
16
+ rateLimitTtl: number;
17
+ };
18
+ type ApiKeyInput = {
19
+ name: string;
20
+ projectId?: string;
21
+ key?: string;
22
+ customMetaData?: AnyJson;
23
+ customAccountId?: string;
24
+ customUserId?: string;
25
+ rateLimitConfigs?: RateLimitConfiguration;
26
+ expiry?: Date;
27
+ };
28
+ type ApiKeyFilter = {
29
+ projectId?: string;
30
+ name?: string;
31
+ customAccountId?: string | null;
32
+ customUserId?: string | null;
33
+ isActive?: boolean;
34
+ };
35
+ type UpdateApiKeyInput = {
36
+ name: string;
37
+ key?: string;
38
+ customMetaData?: AnyJson;
39
+ customAccountId?: string;
40
+ customUserId?: string;
41
+ expiry?: Date | null;
42
+ rateLimitConfigs?: RateLimitConfiguration | null;
43
+ };
44
+ declare enum AuthedEntityType {
45
+ USER = "USER",
46
+ ACCESS_KEY = "ACCESS_KEY"
47
+ }
48
+ type AuthBaseEntity = {
49
+ isActive: boolean;
50
+ createdBy: string;
51
+ createdByType?: AuthedEntityType;
52
+ createdIn: string;
53
+ lastChangedBy: string;
54
+ lastChangedByType?: AuthedEntityType;
55
+ updatedAt: Date;
56
+ createdAt: Date;
57
+ };
58
+ type Project = AuthBaseEntity & {
59
+ id: string;
60
+ name: string;
61
+ accountId: string;
62
+ env: Environment;
63
+ };
64
+ declare enum Environment {
65
+ LIVE = "live",
66
+ TEST = "test"
67
+ }
68
+ type CreateProjectInput = {
69
+ name: string;
70
+ accountId: string;
71
+ env: Environment;
72
+ };
73
+ type UpdateProjectInput = {
74
+ name: string;
75
+ };
76
+ type Account = AuthBaseEntity & {
77
+ id: string;
78
+ name: string;
79
+ };
80
+ type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
81
+ type JsonMap = {
82
+ [key: string]: AnyJson;
83
+ };
84
+ type JsonArray = Array<AnyJson>;
85
+
86
+ export { AuthedEntityType, Environment };
87
+ export type { Account, ApiKey, ApiKeyFilter, ApiKeyInput, AuthBaseEntity, CreateProjectInput, Project, RateLimitConfiguration, UpdateApiKeyInput, UpdateProjectInput };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theauthapi",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Client library for TheAuthAPI.com",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.cts",
@@ -14,6 +14,10 @@
14
14
  "types": "./dist/index.d.cts",
15
15
  "default": "./dist/index.cjs"
16
16
  }
17
+ },
18
+ "./types": {
19
+ "require": "./dist/types.d.cts",
20
+ "types": "./dist/types.d.ts"
17
21
  }
18
22
  },
19
23
  "type": "module",
@@ -36,7 +40,9 @@
36
40
  "local-release": "npm run ci && changeset version && changeset publish",
37
41
  "format": "prettier --write .",
38
42
  "check-format": "prettier --check .",
39
- "check-exports": "attw --pack ."
43
+ "check-exports": "npm run check-exports:all && npm run check-exports:types",
44
+ "check-exports:all": "npx attw --pack . --exclude-entrypoints ./types",
45
+ "check-exports:types": "npx attw --pack . --entrypoints ./types --profile node16"
40
46
  },
41
47
  "repository": {
42
48
  "type": "git",
@@ -78,5 +84,8 @@
78
84
  "rollup-plugin-dts": "^6.2.1",
79
85
  "ts-jest": "^29.1.1",
80
86
  "typescript": "^4.9.5"
87
+ },
88
+ "optionalDependencies": {
89
+ "@rollup/rollup-darwin-arm64": "^4.62.2"
81
90
  }
82
91
  }
@@ -1,10 +0,0 @@
1
- import { AccountsInterface } from './AccountsInterface';
2
- import ApiRequest from '../../services/ApiRequest/ApiRequest';
3
- import { Account } from '../../types';
4
- declare class Accounts implements AccountsInterface {
5
- api: ApiRequest;
6
- endpoint: string;
7
- constructor(apiService: ApiRequest);
8
- getAccount(accountId: string): Promise<Account>;
9
- }
10
- export default Accounts;
@@ -1,22 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
11
- class Accounts {
12
- constructor(apiService) {
13
- this.api = apiService;
14
- this.endpoint = '/accounts';
15
- }
16
- getAccount(accountId) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${accountId}`);
19
- });
20
- }
21
- }
22
- export default Accounts;
@@ -1,4 +0,0 @@
1
- import { Account } from '../../types';
2
- export interface AccountsInterface {
3
- getAccount(accountId: string): Promise<Account>;
4
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import ApiRequest from '../../services/ApiRequest/ApiRequest';
2
- import { ApiKey, ApiKeyFilter, ApiKeyInput, UpdateApiKeyInput } from '../../types';
3
- import { ApiKeysInterface } from './ApiKeysInterface';
4
- declare class ApiKeys implements ApiKeysInterface {
5
- api: ApiRequest;
6
- private readonly endpoint;
7
- constructor(apiService: ApiRequest);
8
- isValidKey(apikey: string): Promise<boolean>;
9
- authenticateKey(apikey: string): Promise<ApiKey>;
10
- getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
11
- getKey(apikey: string): Promise<ApiKey>;
12
- createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
13
- updateKey(apiKey: string, updatedKey: UpdateApiKeyInput): Promise<ApiKey>;
14
- deleteKey(apiKey: string): Promise<boolean>;
15
- reactivateKey(apiKey: string): Promise<ApiKey>;
16
- rotateKey(apiKey: string): Promise<ApiKey>;
17
- private getKeysFilterEndpoint;
18
- }
19
- export default ApiKeys;
@@ -1,80 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
11
- import ApiResponseError from '../../services/ApiRequest/ApiResponseError';
12
- class ApiKeys {
13
- constructor(apiService) {
14
- this.api = apiService;
15
- this.endpoint = '/api-keys/';
16
- }
17
- isValidKey(apikey) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- const key = yield this.authenticateKey(apikey);
21
- return key.key !== undefined;
22
- }
23
- catch (error) {
24
- if (error instanceof ApiResponseError && error.statusCode === 404) {
25
- return false;
26
- }
27
- throw error;
28
- }
29
- });
30
- }
31
- authenticateKey(apikey) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return yield this.api.request(HttpMethod.POST, `/api-keys/auth/${apikey}`);
34
- });
35
- }
36
- getKeys(filter) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const endpoint = this.getKeysFilterEndpoint(filter);
39
- return yield this.api.request(HttpMethod.GET, endpoint);
40
- });
41
- }
42
- getKey(apikey) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- return yield this.api.request(HttpMethod.GET, `/api-keys/${apikey}`);
45
- });
46
- }
47
- createKey(apiKey) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- return yield this.api.request(HttpMethod.POST, '/api-keys', apiKey);
50
- });
51
- }
52
- updateKey(apiKey, updatedKey) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
55
- });
56
- }
57
- deleteKey(apiKey) {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- return yield this.api.request(HttpMethod.DELETE, `/api-keys/${apiKey}`);
60
- });
61
- }
62
- reactivateKey(apiKey) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
65
- });
66
- }
67
- rotateKey(apiKey) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- return yield this.api.request(HttpMethod.POST, `/api-keys/${apiKey}/rotate`);
70
- });
71
- }
72
- getKeysFilterEndpoint(filter) {
73
- let filters = [];
74
- if (filter !== undefined) {
75
- filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
76
- }
77
- return `${this.endpoint}${filter !== undefined ? '?' : ''}${filters.join('&')}`;
78
- }
79
- }
80
- export default ApiKeys;
@@ -1,12 +0,0 @@
1
- import { ApiKey, ApiKeyFilter, ApiKeyInput, UpdateApiKeyInput } from '../../types';
2
- export interface ApiKeysInterface {
3
- isValidKey(apiKey: string): Promise<boolean>;
4
- getKey(apiKey: string): Promise<ApiKey>;
5
- authenticateKey(apiKey: string): Promise<ApiKey>;
6
- getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
7
- createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
8
- updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
9
- deleteKey(apiKey: string): Promise<boolean>;
10
- reactivateKey(apiKey: string): Promise<ApiKey>;
11
- rotateKey(apiKey: string): Promise<ApiKey>;
12
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import ApiRequest from '../../services/ApiRequest/ApiRequest';
2
- import { CreateProjectInput, Project, UpdateProjectInput } from '../../types';
3
- import { ProjectsInterface } from './ProjectsInterface';
4
- declare class Projects implements ProjectsInterface {
5
- api: ApiRequest;
6
- endpoint: string;
7
- constructor(apiService: ApiRequest);
8
- getProjects(accountId: string): Promise<Project[]>;
9
- getProject(projectId: string): Promise<Project>;
10
- deleteProject(projectId: string): Promise<boolean>;
11
- createProject(project: CreateProjectInput): Promise<Project>;
12
- updateProject(projectId: string, project: UpdateProjectInput): Promise<Project>;
13
- }
14
- export default Projects;
@@ -1,42 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
11
- class Projects {
12
- constructor(apiService) {
13
- this.api = apiService;
14
- this.endpoint = '/projects';
15
- }
16
- getProjects(accountId) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- return yield this.api.request(HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
19
- });
20
- }
21
- getProject(projectId) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${projectId}`);
24
- });
25
- }
26
- deleteProject(projectId) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return yield this.api.request(HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
29
- });
30
- }
31
- createProject(project) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return yield this.api.request(HttpMethod.POST, this.endpoint, project);
34
- });
35
- }
36
- updateProject(projectId, project) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- return this.api.request(HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
39
- });
40
- }
41
- }
42
- export default Projects;
@@ -1,8 +0,0 @@
1
- import { CreateProjectInput, Project, UpdateProjectInput } from '../../types';
2
- export interface ProjectsInterface {
3
- getProjects(accountId: string): Promise<Project[]>;
4
- getProject(projectId: string): Promise<Project>;
5
- deleteProject(projectId: string): Promise<boolean>;
6
- createProject(project: CreateProjectInput): Promise<Project>;
7
- updateProject(name: string, updateTo: UpdateProjectInput): Promise<Project>;
8
- }
@@ -1 +0,0 @@
1
- export {};
package/dist/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import ApiRequest from './services/ApiRequest/ApiRequest';
2
- import ApiKeys from './endpoints/ApiKeys/ApiKeys';
3
- import Projects from './endpoints/Projects/Projects';
4
- import Accounts from './endpoints/Accounts/Accounts';
5
- type Options = {
6
- host?: string;
7
- retryCount?: number;
8
- };
9
- declare class TheAuthAPI {
10
- accessKey: string;
11
- host: string;
12
- timeout: number | string | undefined;
13
- api: ApiRequest;
14
- apiKeys: ApiKeys;
15
- projects: Projects;
16
- accounts: Accounts;
17
- /**
18
- * @param {String} accessKey
19
- * @param {Object} [options] (optional)
20
- * @property {String} host (default: 'https://api.segment.io')
21
- * @property {number} retryCount (default: 3)
22
- */
23
- constructor(accessKey: string, options?: Options);
24
- authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
25
- }
26
- export default TheAuthAPI;
package/dist/index.js DELETED
@@ -1,69 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import assert from 'assert';
11
- import removeSlash from 'remove-trailing-slash';
12
- import ApiRequest from './services/ApiRequest/ApiRequest';
13
- import ApiKeys from './endpoints/ApiKeys/ApiKeys';
14
- import { HttpMethod } from './services/ApiRequest/HttpMethod';
15
- import Projects from './endpoints/Projects/Projects';
16
- import Accounts from './endpoints/Accounts/Accounts';
17
- // eslint-disable-next-line @typescript-eslint/no-empty-function
18
- const noop = () => { };
19
- class TheAuthAPI {
20
- /**
21
- * @param {String} accessKey
22
- * @param {Object} [options] (optional)
23
- * @property {String} host (default: 'https://api.segment.io')
24
- * @property {number} retryCount (default: 3)
25
- */
26
- constructor(accessKey, options) {
27
- var _a;
28
- assert(accessKey, "You must pass your project's write key.");
29
- this.accessKey = accessKey;
30
- this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
31
- this.api = new ApiRequest({
32
- accessKey: this.accessKey,
33
- host: this.host,
34
- retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
35
- });
36
- this.apiKeys = new ApiKeys(this.api);
37
- this.projects = new Projects(this.api);
38
- this.accounts = new Accounts(this.api);
39
- }
40
- /*
41
- @deprecated
42
- */
43
- authenticateAPIKey(key, callback) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const cb = callback || noop;
46
- const done = (err) => {
47
- cb(err, data);
48
- };
49
- const data = {
50
- credentials: { api_key: key },
51
- timestamp: new Date().getTime(),
52
- sentAt: new Date().getTime(),
53
- };
54
- try {
55
- const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
56
- done(key);
57
- return key;
58
- }
59
- catch (err) {
60
- if (err.response) {
61
- const error = new Error(err.response.statusText);
62
- return done(error);
63
- }
64
- done(err);
65
- }
66
- });
67
- }
68
- }
69
- export default TheAuthAPI;
@@ -1 +0,0 @@
1
- export declare const version = "1.0.11";
@@ -1 +0,0 @@
1
- export const version = '1.0.11';
@@ -1,5 +0,0 @@
1
- import { HttpMethod } from './HttpMethod';
2
- interface ApiCall {
3
- request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
4
- }
5
- export default ApiCall;
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- import { HttpMethod } from './HttpMethod';
2
- import ApiCall from './ApiCall';
3
- type Config = {
4
- host: string;
5
- accessKey: string;
6
- headers?: object;
7
- retryCount?: number;
8
- };
9
- declare class ApiRequest implements ApiCall {
10
- host: string;
11
- headers: object;
12
- accessKey: string;
13
- retryCount: number;
14
- constructor(config: Config);
15
- _init(): void;
16
- request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
17
- _generateDefaultHeaders(): {
18
- 'user-agent': string;
19
- 'x-api-key': string;
20
- 'api-key': string;
21
- };
22
- _isErrorRetryable(error: any): boolean;
23
- }
24
- export default ApiRequest;