theauthapi 1.0.10 → 1.0.11

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 CHANGED
@@ -33,7 +33,7 @@ yarn add theauthapi
33
33
 
34
34
  You'll need to configure the library with your `access key` and `account id`, you can grab these from [TheAuthAPI](https://app.theauthapi.com) dashboard.
35
35
 
36
- For further instructions on creating an account, check out our [how to guides](https://thatapicompany.notion.site/The-Auth-API-Knowledge-Base-21660cee84e640729714fad43d9ce546).
36
+ For further instructions on creating an account, check out our [how to guides](https://support.theauthapi.com/).
37
37
 
38
38
  ### Imports
39
39
 
@@ -59,7 +59,6 @@ You can also provide custom options:
59
59
 
60
60
  ```javascript
61
61
  const theAuthAPI = new TheAuthAPI("YOUR_ACCESS_KEY", {
62
- timeout: 3600,
63
62
  retryCount: 2,
64
63
  });
65
64
  ```
@@ -70,8 +69,6 @@ const theAuthAPI = new TheAuthAPI("YOUR_ACCESS_KEY", {
70
69
  type Options = {
71
70
  // server url
72
71
  host?: string;
73
- // request timeout in ms
74
- timeout?: string | number;
75
72
  // number of retries before failing
76
73
  retryCount?: number;
77
74
  };
@@ -165,10 +162,12 @@ try {
165
162
  ```typescript
166
163
  type ApiKeyFilter = {
167
164
  projectId?: string;
168
- customAccountId?: string;
169
- customUserId?: string;
165
+ name?: string;
166
+ customAccountId?: string | null;
167
+ customUserId?: string | null;
170
168
  isActive?: boolean;
171
169
  };
170
+
172
171
  ```
173
172
 
174
173
  **Example**: filtering api-keys with a specific `projectId` where the keys are not active
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
13
- const util_1 = require("../../util");
14
13
  class Accounts {
15
14
  constructor(apiService) {
16
15
  this.api = apiService;
@@ -18,7 +17,6 @@ class Accounts {
18
17
  }
19
18
  getAccount(accountId) {
20
19
  return __awaiter(this, void 0, void 0, function* () {
21
- (0, util_1.validateString)("accountId", accountId);
22
20
  return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}/${accountId}`);
23
21
  });
24
22
  }
@@ -12,9 +12,7 @@ declare class ApiKeys implements ApiKeysInterface {
12
12
  createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
13
13
  updateKey(apiKey: string, updatedKey: UpdateApiKeyInput): Promise<ApiKey>;
14
14
  deleteKey(apiKey: string): Promise<boolean>;
15
- private validateCreateKeyInput;
16
- private validateUpdateKeyInput;
17
- private validateFiltersInput;
15
+ reactivateKey(apiKey: string): Promise<ApiKey>;
18
16
  private getKeysFilterEndpoint;
19
17
  }
20
18
  export default ApiKeys;
@@ -13,8 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
16
- const lodash_omit_1 = __importDefault(require("lodash.omit"));
17
- const util_1 = require("../../util");
18
16
  const ApiResponseError_1 = __importDefault(require("../../services/ApiRequest/ApiResponseError"));
19
17
  class ApiKeys {
20
18
  constructor(apiService) {
@@ -23,9 +21,8 @@ class ApiKeys {
23
21
  }
24
22
  isValidKey(apikey) {
25
23
  return __awaiter(this, void 0, void 0, function* () {
26
- (0, util_1.validateString)("apikey", apikey);
27
24
  try {
28
- const key = yield this.api.request(HttpMethod_1.HttpMethod.GET, `/api-keys/auth/${apikey}`);
25
+ const key = yield this.authenticateKey(apikey);
29
26
  return key.key !== undefined;
30
27
  }
31
28
  catch (error) {
@@ -38,8 +35,7 @@ class ApiKeys {
38
35
  }
39
36
  authenticateKey(apikey) {
40
37
  return __awaiter(this, void 0, void 0, function* () {
41
- (0, util_1.validateString)("apikey", apikey);
42
- return yield this.api.request(HttpMethod_1.HttpMethod.GET, `/api-keys/auth/${apikey}`);
38
+ return yield this.api.request(HttpMethod_1.HttpMethod.POST, `/api-keys/auth/${apikey}`);
43
39
  });
44
40
  }
45
41
  getKeys(filter) {
@@ -50,67 +46,35 @@ class ApiKeys {
50
46
  }
51
47
  getKey(apikey) {
52
48
  return __awaiter(this, void 0, void 0, function* () {
53
- (0, util_1.validateString)("apikey", apikey);
54
49
  return yield this.api.request(HttpMethod_1.HttpMethod.GET, `/api-keys/${apikey}`);
55
50
  });
56
51
  }
57
52
  createKey(apiKey) {
58
53
  return __awaiter(this, void 0, void 0, function* () {
59
- this.validateCreateKeyInput(apiKey);
60
54
  return yield this.api.request(HttpMethod_1.HttpMethod.POST, "/api-keys", apiKey);
61
55
  });
62
56
  }
63
57
  updateKey(apiKey, updatedKey) {
64
58
  return __awaiter(this, void 0, void 0, function* () {
65
- this.validateUpdateKeyInput(apiKey, updatedKey);
66
59
  return yield this.api.request(HttpMethod_1.HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
67
60
  });
68
61
  }
69
62
  deleteKey(apiKey) {
70
63
  return __awaiter(this, void 0, void 0, function* () {
71
- (0, util_1.validateString)("apiKey", apiKey);
72
64
  return yield this.api.request(HttpMethod_1.HttpMethod.DELETE, `/api-keys/${apiKey}`);
73
65
  });
74
66
  }
75
- validateCreateKeyInput(apiKey) {
76
- if (!apiKey) {
77
- throw new TypeError("apiKey must be an object");
78
- }
79
- if (!apiKey.name) {
80
- throw TypeError("apiKey object must contain the property name");
81
- }
82
- // validate string properties only
83
- for (const [key, value] of Object.entries((0, lodash_omit_1.default)(apiKey, ["customMetaData", "rateLimitConfigs"]))) {
84
- (0, util_1.validateString)(key, value);
85
- }
86
- }
87
- validateUpdateKeyInput(apiKey, updatedKey) {
88
- if (!updatedKey) {
89
- throw new TypeError("updatedKey must be an object");
90
- }
91
- if (!updatedKey.name) {
92
- throw TypeError("updatedKey object must contain the property [name]");
93
- }
94
- (0, util_1.validateString)("apiKey", apiKey);
95
- (0, util_1.validateString)("name", updatedKey.name);
96
- }
97
- validateFiltersInput(filter) {
98
- if (filter) {
99
- if (filter.isActive && typeof filter.isActive !== "boolean") {
100
- throw TypeError("isActive must be a boolean");
101
- }
102
- Object.entries((0, lodash_omit_1.default)(filter, "isActive")).forEach(([key, value]) => {
103
- (0, util_1.validateString)(key, value);
104
- });
105
- }
67
+ reactivateKey(apiKey) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return yield this.api.request(HttpMethod_1.HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
70
+ });
106
71
  }
107
72
  getKeysFilterEndpoint(filter) {
108
- this.validateFiltersInput(filter);
109
73
  let filters = [];
110
- if (filter) {
74
+ if (filter !== undefined) {
111
75
  filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
112
76
  }
113
- return `${this.endpoint}${filter ? "?" : ""}${filters.join("&")}`;
77
+ return `${this.endpoint}${filter !== undefined ? "?" : ""}${filters.join("&")}`;
114
78
  }
115
79
  }
116
80
  exports.default = ApiKeys;
@@ -7,4 +7,5 @@ export interface ApiKeysInterface {
7
7
  createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
8
8
  updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
9
9
  deleteKey(apiKey: string): Promise<boolean>;
10
+ reactivateKey(apiKey: string): Promise<ApiKey>;
10
11
  }
@@ -10,7 +10,5 @@ declare class Projects implements ProjectsInterface {
10
10
  deleteProject(projectId: string): Promise<boolean>;
11
11
  createProject(project: CreateProjectInput): Promise<Project>;
12
12
  updateProject(projectId: string, project: UpdateProjectInput): Promise<Project>;
13
- private validateCreateProjectInput;
14
- private validateUpdateProjectInput;
15
13
  }
16
14
  export default Projects;
@@ -9,9 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const types_1 = require("../../types");
13
12
  const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
14
- const util_1 = require("../../util");
15
13
  class Projects {
16
14
  constructor(apiService) {
17
15
  this.api = apiService;
@@ -19,50 +17,28 @@ class Projects {
19
17
  }
20
18
  getProjects(accountId) {
21
19
  return __awaiter(this, void 0, void 0, function* () {
22
- (0, util_1.validateString)("accountId", accountId);
23
20
  return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
24
21
  });
25
22
  }
26
23
  getProject(projectId) {
27
24
  return __awaiter(this, void 0, void 0, function* () {
28
- (0, util_1.validateString)("projectId", projectId);
29
25
  return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}/${projectId}`);
30
26
  });
31
27
  }
32
28
  deleteProject(projectId) {
33
29
  return __awaiter(this, void 0, void 0, function* () {
34
- (0, util_1.validateString)("projectId", projectId);
35
30
  return yield this.api.request(HttpMethod_1.HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
36
31
  });
37
32
  }
38
33
  createProject(project) {
39
34
  return __awaiter(this, void 0, void 0, function* () {
40
- this.validateCreateProjectInput(project);
41
35
  return yield this.api.request(HttpMethod_1.HttpMethod.POST, this.endpoint, project);
42
36
  });
43
37
  }
44
38
  updateProject(projectId, project) {
45
39
  return __awaiter(this, void 0, void 0, function* () {
46
- this.validateUpdateProjectInput(projectId, project);
47
40
  return this.api.request(HttpMethod_1.HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
48
41
  });
49
42
  }
50
- validateCreateProjectInput(project) {
51
- if (!project) {
52
- throw new TypeError("project must be an object");
53
- }
54
- (0, util_1.validateString)("name", project.name);
55
- (0, util_1.validateString)("accountId", project.accountId);
56
- if (!Object.values(types_1.Environment).includes(project.env)) {
57
- throw TypeError(`expected env to be one of [${Object.values(types_1.Environment).map((v) => `"${v}"`)}], got: ${project.env}`);
58
- }
59
- }
60
- validateUpdateProjectInput(projectId, project) {
61
- if (!project) {
62
- throw new TypeError("project must be an object");
63
- }
64
- (0, util_1.validateString)("projectId", projectId);
65
- (0, util_1.validateString)("name", project.name);
66
- }
67
43
  }
68
44
  exports.default = Projects;
package/dist/index.d.ts CHANGED
@@ -4,31 +4,21 @@ import Projects from "./endpoints/Projects/Projects";
4
4
  import Accounts from "./endpoints/Accounts/Accounts";
5
5
  declare type Options = {
6
6
  host?: string;
7
- timeout?: string | number;
8
- cacheTTL?: number;
9
- enable?: boolean;
10
7
  retryCount?: number;
11
8
  };
12
9
  declare class TheAuthAPI {
13
- queue: [];
14
10
  accessKey: string;
15
11
  host: string;
16
12
  timeout: number | string | undefined;
17
- cacheTTL: number;
18
13
  api: ApiRequest;
19
14
  apiKeys: ApiKeys;
20
15
  projects: Projects;
21
16
  accounts: Accounts;
22
17
  /**
23
- * Initialize a new `Analytics` with your Segment project's `writeKey` and an
24
- * optional dictionary of `options`.
25
- *
26
18
  * @param {String} accessKey
27
19
  * @param {Object} [options] (optional)
28
- * @property {Number} flushAt (default: 20)
29
- * @property {Number} flushInterval (default: 10000)
30
20
  * @property {String} host (default: 'https://api.segment.io')
31
- * @property {Boolean} enable (default: true)
21
+ * @property {number} retryCount (default: 3)
32
22
  */
33
23
  constructor(accessKey: string, options?: Options);
34
24
  authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
package/dist/index.js CHANGED
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const assert_1 = __importDefault(require("assert"));
16
16
  const remove_trailing_slash_1 = __importDefault(require("remove-trailing-slash"));
17
17
  const ApiRequest_1 = __importDefault(require("./services/ApiRequest/ApiRequest"));
18
- const util_1 = require("./util");
19
18
  const ApiKeys_1 = __importDefault(require("./endpoints/ApiKeys/ApiKeys"));
20
19
  const HttpMethod_1 = require("./services/ApiRequest/HttpMethod");
21
20
  const Projects_1 = __importDefault(require("./endpoints/Projects/Projects"));
@@ -24,44 +23,30 @@ const Accounts_1 = __importDefault(require("./endpoints/Accounts/Accounts"));
24
23
  const noop = () => { };
25
24
  class TheAuthAPI {
26
25
  /**
27
- * Initialize a new `Analytics` with your Segment project's `writeKey` and an
28
- * optional dictionary of `options`.
29
- *
30
26
  * @param {String} accessKey
31
27
  * @param {Object} [options] (optional)
32
- * @property {Number} flushAt (default: 20)
33
- * @property {Number} flushInterval (default: 10000)
34
28
  * @property {String} host (default: 'https://api.segment.io')
35
- * @property {Boolean} enable (default: true)
29
+ * @property {number} retryCount (default: 3)
36
30
  */
37
31
  constructor(accessKey, options) {
38
32
  var _a;
39
33
  (0, assert_1.default)(accessKey, "You must pass your project's write key.");
40
- this.queue = [];
41
34
  this.accessKey = accessKey;
42
35
  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
36
  this.api = new ApiRequest_1.default({
46
37
  accessKey: this.accessKey,
47
38
  host: this.host,
39
+ retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
48
40
  });
49
41
  this.apiKeys = new ApiKeys_1.default(this.api);
50
42
  this.projects = new Projects_1.default(this.api);
51
43
  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
44
  }
59
45
  /*
60
46
  @deprecated
61
47
  */
62
48
  authenticateAPIKey(key, callback) {
63
49
  return __awaiter(this, void 0, void 0, function* () {
64
- (0, util_1.validateString)("key", key);
65
50
  const cb = callback || noop;
66
51
  const done = (err) => {
67
52
  cb(err, data);
@@ -1 +1 @@
1
- export declare const version = "1.0.10";
1
+ export declare const version = "1.0.11";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = "1.0.10";
4
+ exports.version = "1.0.11";
@@ -5,13 +5,11 @@ declare type Config = {
5
5
  accessKey: string;
6
6
  headers?: object;
7
7
  retryCount?: number;
8
- timeout?: number | string;
9
8
  };
10
9
  declare class ApiRequest implements ApiCall {
11
10
  host: string;
12
11
  headers: object;
13
12
  accessKey: string;
14
- timeout: number;
15
13
  retryCount: number;
16
14
  constructor(config: Config);
17
15
  _init(): void;
@@ -16,15 +16,13 @@ const axios_1 = __importDefault(require("axios"));
16
16
  const libraryMeta_1 = require("../../libraryMeta");
17
17
  const ApiRequestError_1 = __importDefault(require("./ApiRequestError"));
18
18
  const axios_retry_1 = __importDefault(require("axios-retry"));
19
- const ms_1 = __importDefault(require("ms"));
20
19
  const ApiResponseError_1 = __importDefault(require("./ApiResponseError"));
21
20
  class ApiRequest {
22
21
  constructor(config) {
23
- const { host, accessKey, headers, retryCount, timeout } = config;
22
+ const { host, accessKey, headers, retryCount } = config;
24
23
  this.host = host;
25
24
  this.accessKey = accessKey;
26
25
  this.headers = this._generateDefaultHeaders();
27
- this.timeout = timeout ? (typeof timeout === "string" ? (0, ms_1.default)(timeout) : timeout) : 0;
28
26
  this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
29
27
  if (headers) {
30
28
  this.headers = Object.assign(Object.assign({}, this.headers), { headers });
@@ -1,17 +1,17 @@
1
1
  export declare type ApiKey = {
2
2
  key: string;
3
3
  name: string;
4
- customMetaData: object;
4
+ customMetaData: AnyJson;
5
5
  customAccountId: string;
6
6
  customUserId: string;
7
7
  env: Environment;
8
8
  createdAt: Date;
9
9
  updatedAt: Date;
10
10
  isActive: boolean;
11
+ rateLimitConfigs: RateLimitConfiguration;
12
+ expiry: Date;
11
13
  };
12
14
  export declare type RateLimitConfiguration = {
13
- rateLimitedEntity?: string;
14
- ratelimitedEnitityId?: string;
15
15
  rateLimit: number;
16
16
  rateLimitTtl: number;
17
17
  };
@@ -19,21 +19,27 @@ export declare type ApiKeyInput = {
19
19
  name: string;
20
20
  projectId?: string;
21
21
  key?: string;
22
- customMetaData?: object;
22
+ customMetaData?: AnyJson;
23
23
  customAccountId?: string;
24
24
  customUserId?: string;
25
25
  rateLimitConfigs?: RateLimitConfiguration;
26
+ expiry?: Date;
26
27
  };
27
28
  export declare type ApiKeyFilter = {
28
29
  projectId?: string;
29
- customAccountId?: string;
30
- customUserId?: string;
30
+ name?: string;
31
+ customAccountId?: string | null;
32
+ customUserId?: string | null;
31
33
  isActive?: boolean;
32
34
  };
33
35
  export declare type UpdateApiKeyInput = {
34
36
  name: string;
35
- customMetaData?: object;
37
+ key?: string;
38
+ customMetaData?: AnyJson;
36
39
  customAccountId?: string;
40
+ customUserId?: string;
41
+ expiry?: Date | null;
42
+ rateLimitConfigs?: RateLimitConfiguration | null;
37
43
  };
38
44
  export declare enum AuthedEntityType {
39
45
  USER = "USER",
@@ -71,3 +77,9 @@ export declare type Account = AuthBaseEntity & {
71
77
  id: string;
72
78
  name: string;
73
79
  };
80
+ declare type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
81
+ declare type JsonMap = {
82
+ [key: string]: AnyJson;
83
+ };
84
+ declare type JsonArray = Array<AnyJson>;
85
+ export {};
package/dist/usage.js ADDED
@@ -0,0 +1,20 @@
1
+ const TheAuthAPI = require("./index").default;
2
+
3
+ const accessKey = "live_access_tXhV0mDbN81n7dGRuBPAVvfwsv5N4pmlaGLCELXOtFoWU2EGV6cN5UA3LhjrUg9B";
4
+ const theAuthAPI = new TheAuthAPI(accessKey, {
5
+ host: "http://localhost:8080",
6
+ });
7
+
8
+ async function getKeys() {
9
+ const keys = await theAuthAPI.apiKeys.getKeys();
10
+ return keys.map((k) => k.key);
11
+ }
12
+
13
+ const apikey =
14
+ "test_DdRU9zW8LSHGjzuDDHYqPcDm4ocacFJl6I6wtzBGKevgnAzy8GvqFEuZIj3ykqzS";
15
+ (async () => {
16
+ console.log(await theAuthAPI.apiKeys.createKey({
17
+ name: "Sheesh",
18
+ expiry: new Date("Sheesh"),
19
+ }));
20
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "theauthapi",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "Client library for TheAuthAPI.com",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,14 +31,11 @@
31
31
  "assert": "^2.0.0",
32
32
  "axios": "^0.21.4",
33
33
  "axios-retry": "^3.1.9",
34
- "lodash.isstring": "^4.0.1",
35
- "lodash.omit": "^4.5.0",
36
- "ms": "^2.1.3",
37
34
  "remove-trailing-slash": "^0.1.1"
38
35
  },
39
36
  "devDependencies": {
40
37
  "@types/express": "^4.17.13",
41
- "@types/jest": "^27.4.1",
38
+ "@types/jest": "^27.5.2",
42
39
  "@types/lodash.isstring": "^4.0.6",
43
40
  "@types/lodash.omit": "^4.5.6",
44
41
  "@types/ms": "^0.7.31",
@@ -51,6 +48,7 @@
51
48
  "express": "^4.15.2",
52
49
  "jest": "^27.5.1",
53
50
  "prettier": "2.6.2",
51
+ "ts-jest": "^28.0.8",
54
52
  "typescript": "^4.6.3"
55
53
  }
56
54
  }