theauthapi 1.0.15 → 1.0.16

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/dist/index.d.ts CHANGED
@@ -1,180 +1,7 @@
1
- declare enum HttpMethod {
2
- GET = "GET",
3
- POST = "POST",
4
- DELETE = "DELETE",
5
- PATCH = "PATCH",
6
- PUT = "PUT"
7
- }
8
-
9
- interface ApiCall {
10
- request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
11
- }
12
-
13
- type Config = {
14
- host: string;
15
- accessKey: string;
16
- headers?: object;
17
- retryCount?: number;
18
- };
19
- declare class ApiRequest implements ApiCall {
20
- host: string;
21
- headers: object;
22
- accessKey: string;
23
- retryCount: number;
24
- constructor(config: Config);
25
- _init(): void;
26
- request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
27
- _generateDefaultHeaders(): {
28
- "user-agent": string;
29
- "x-api-key": string;
30
- "api-key": string;
31
- };
32
- _isErrorRetryable(error: any): boolean;
33
- }
34
-
35
- type ApiKey = {
36
- key: string;
37
- name: string;
38
- customMetaData: AnyJson;
39
- customAccountId: string;
40
- customUserId: string;
41
- env: Environment;
42
- createdAt: Date;
43
- updatedAt: Date;
44
- isActive: boolean;
45
- rateLimitConfigs: RateLimitConfiguration;
46
- expiry: Date;
47
- };
48
- type RateLimitConfiguration = {
49
- rateLimit: number;
50
- rateLimitTtl: number;
51
- };
52
- type ApiKeyInput = {
53
- name: string;
54
- projectId?: string;
55
- key?: string;
56
- customMetaData?: AnyJson;
57
- customAccountId?: string;
58
- customUserId?: string;
59
- rateLimitConfigs?: RateLimitConfiguration;
60
- expiry?: Date;
61
- };
62
- type ApiKeyFilter = {
63
- projectId?: string;
64
- name?: string;
65
- customAccountId?: string | null;
66
- customUserId?: string | null;
67
- isActive?: boolean;
68
- };
69
- type UpdateApiKeyInput = {
70
- name: string;
71
- key?: string;
72
- customMetaData?: AnyJson;
73
- customAccountId?: string;
74
- customUserId?: string;
75
- expiry?: Date | null;
76
- rateLimitConfigs?: RateLimitConfiguration | null;
77
- };
78
- declare enum AuthedEntityType {
79
- USER = "USER",
80
- ACCESS_KEY = "ACCESS_KEY"
81
- }
82
- type AuthBaseEntity = {
83
- isActive: boolean;
84
- createdBy: string;
85
- createdByType?: AuthedEntityType;
86
- createdIn: string;
87
- lastChangedBy: string;
88
- lastChangedByType?: AuthedEntityType;
89
- updatedAt: Date;
90
- createdAt: Date;
91
- };
92
- type Project = AuthBaseEntity & {
93
- id: string;
94
- name: string;
95
- accountId: string;
96
- env: Environment;
97
- };
98
- declare enum Environment {
99
- LIVE = "live",
100
- TEST = "test"
101
- }
102
- type CreateProjectInput = {
103
- name: string;
104
- accountId: string;
105
- env: Environment;
106
- };
107
- type UpdateProjectInput = {
108
- name: string;
109
- };
110
- type Account = AuthBaseEntity & {
111
- id: string;
112
- name: string;
113
- };
114
- type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
115
- type JsonMap = {
116
- [key: string]: AnyJson;
117
- };
118
- type JsonArray = Array<AnyJson>;
119
-
120
- interface ApiKeysInterface {
121
- isValidKey(apiKey: string): Promise<boolean>;
122
- getKey(apiKey: string): Promise<ApiKey>;
123
- authenticateKey(apiKey: string): Promise<ApiKey>;
124
- getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
125
- createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
126
- updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
127
- deleteKey(apiKey: string): Promise<boolean>;
128
- reactivateKey(apiKey: string): Promise<ApiKey>;
129
- rotateKey(apiKey: string): Promise<ApiKey>;
130
- }
131
-
132
- declare class ApiKeys implements ApiKeysInterface {
133
- api: ApiRequest;
134
- private readonly endpoint;
135
- constructor(apiService: ApiRequest);
136
- isValidKey(apikey: string): Promise<boolean>;
137
- authenticateKey(apikey: string): Promise<ApiKey>;
138
- getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
139
- getKey(apikey: string): Promise<ApiKey>;
140
- createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
141
- updateKey(apiKey: string, updatedKey: UpdateApiKeyInput): Promise<ApiKey>;
142
- deleteKey(apiKey: string): Promise<boolean>;
143
- reactivateKey(apiKey: string): Promise<ApiKey>;
144
- rotateKey(apiKey: string): Promise<ApiKey>;
145
- private getKeysFilterEndpoint;
146
- }
147
-
148
- interface ProjectsInterface {
149
- getProjects(accountId: string): Promise<Project[]>;
150
- getProject(projectId: string): Promise<Project>;
151
- deleteProject(projectId: string): Promise<boolean>;
152
- createProject(project: CreateProjectInput): Promise<Project>;
153
- updateProject(name: string, updateTo: UpdateProjectInput): Promise<Project>;
154
- }
155
-
156
- declare class Projects implements ProjectsInterface {
157
- api: ApiRequest;
158
- endpoint: string;
159
- constructor(apiService: ApiRequest);
160
- getProjects(accountId: string): Promise<Project[]>;
161
- getProject(projectId: string): Promise<Project>;
162
- deleteProject(projectId: string): Promise<boolean>;
163
- createProject(project: CreateProjectInput): Promise<Project>;
164
- updateProject(projectId: string, project: UpdateProjectInput): Promise<Project>;
165
- }
166
-
167
- interface AccountsInterface {
168
- getAccount(accountId: string): Promise<Account>;
169
- }
170
-
171
- declare class Accounts implements AccountsInterface {
172
- api: ApiRequest;
173
- endpoint: string;
174
- constructor(apiService: ApiRequest);
175
- getAccount(accountId: string): Promise<Account>;
176
- }
177
-
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';
178
5
  type Options = {
179
6
  host?: string;
180
7
  retryCount?: number;
@@ -195,6 +22,5 @@ declare class TheAuthAPI {
195
22
  */
196
23
  constructor(accessKey: string, options?: Options);
197
24
  authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
198
- }
199
-
200
- export { TheAuthAPI as default };
25
+ }
26
+ export default TheAuthAPI;
package/dist/index.js CHANGED
@@ -7,13 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
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";
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
17
  // eslint-disable-next-line @typescript-eslint/no-empty-function
18
18
  const noop = () => { };
19
19
  class TheAuthAPI {
@@ -27,7 +27,7 @@ class TheAuthAPI {
27
27
  var _a;
28
28
  assert(accessKey, "You must pass your project's write key.");
29
29
  this.accessKey = accessKey;
30
- this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || "https://api.theauthapi.com");
30
+ this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
31
31
  this.api = new ApiRequest({
32
32
  accessKey: this.accessKey,
33
33
  host: this.host,
@@ -52,7 +52,7 @@ class TheAuthAPI {
52
52
  sentAt: new Date().getTime(),
53
53
  };
54
54
  try {
55
- const key = yield this.api.request(HttpMethod.POST, "/auth/authenticate", data);
55
+ const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
56
56
  done(key);
57
57
  return key;
58
58
  }
package/dist/index.mjs CHANGED
@@ -30,7 +30,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
30
30
  });
31
31
  }
32
32
 
33
- const version = "1.0.11";
33
+ const version = '1.0.11';
34
34
 
35
35
  /**
36
36
  *
@@ -56,7 +56,7 @@ class ApiResponseError extends Error {
56
56
  constructor(statusCode, message) {
57
57
  super(`(${statusCode}): ${message}`);
58
58
  this.statusCode = statusCode;
59
- this.name = "ApiResponseError";
59
+ this.name = 'ApiResponseError';
60
60
  }
61
61
  }
62
62
 
@@ -76,10 +76,10 @@ class ApiRequest {
76
76
  var _a;
77
77
  const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
78
78
  function isIsoDateString(value) {
79
- return value && typeof value === "string" && isoDateFormat.test(value);
79
+ return value && typeof value === 'string' && isoDateFormat.test(value);
80
80
  }
81
81
  function handleDates(body) {
82
- if (body === null || body === undefined || typeof body !== "object") {
82
+ if (body === null || body === undefined || typeof body !== 'object') {
83
83
  return body;
84
84
  }
85
85
  for (const key of Object.keys(body)) {
@@ -87,7 +87,7 @@ class ApiRequest {
87
87
  if (isIsoDateString(value)) {
88
88
  body[key] = new Date(value);
89
89
  }
90
- else if (typeof value === "object") {
90
+ else if (typeof value === 'object') {
91
91
  handleDates(value);
92
92
  }
93
93
  }
@@ -130,9 +130,9 @@ class ApiRequest {
130
130
  }
131
131
  _generateDefaultHeaders() {
132
132
  return {
133
- "user-agent": `theauthapi-client-node/${version}`,
134
- "x-api-key": this.accessKey,
135
- "api-key": this.accessKey,
133
+ 'user-agent': `theauthapi-client-node/${version}`,
134
+ 'x-api-key': this.accessKey,
135
+ 'api-key': this.accessKey,
136
136
  };
137
137
  }
138
138
  _isErrorRetryable(error) {
@@ -168,7 +168,7 @@ var HttpMethod;
168
168
  class ApiKeys {
169
169
  constructor(apiService) {
170
170
  this.api = apiService;
171
- this.endpoint = "/api-keys/";
171
+ this.endpoint = '/api-keys/';
172
172
  }
173
173
  isValidKey(apikey) {
174
174
  return __awaiter(this, void 0, void 0, function* () {
@@ -202,7 +202,7 @@ class ApiKeys {
202
202
  }
203
203
  createKey(apiKey) {
204
204
  return __awaiter(this, void 0, void 0, function* () {
205
- return yield this.api.request(HttpMethod.POST, "/api-keys", apiKey);
205
+ return yield this.api.request(HttpMethod.POST, '/api-keys', apiKey);
206
206
  });
207
207
  }
208
208
  updateKey(apiKey, updatedKey) {
@@ -230,14 +230,14 @@ class ApiKeys {
230
230
  if (filter !== undefined) {
231
231
  filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
232
232
  }
233
- return `${this.endpoint}${filter !== undefined ? "?" : ""}${filters.join("&")}`;
233
+ return `${this.endpoint}${filter !== undefined ? '?' : ''}${filters.join('&')}`;
234
234
  }
235
235
  }
236
236
 
237
237
  class Projects {
238
238
  constructor(apiService) {
239
239
  this.api = apiService;
240
- this.endpoint = "/projects";
240
+ this.endpoint = '/projects';
241
241
  }
242
242
  getProjects(accountId) {
243
243
  return __awaiter(this, void 0, void 0, function* () {
@@ -269,7 +269,7 @@ class Projects {
269
269
  class Accounts {
270
270
  constructor(apiService) {
271
271
  this.api = apiService;
272
- this.endpoint = "/accounts";
272
+ this.endpoint = '/accounts';
273
273
  }
274
274
  getAccount(accountId) {
275
275
  return __awaiter(this, void 0, void 0, function* () {
@@ -291,7 +291,7 @@ class TheAuthAPI {
291
291
  var _a;
292
292
  assert(accessKey, "You must pass your project's write key.");
293
293
  this.accessKey = accessKey;
294
- this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || "https://api.theauthapi.com");
294
+ this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
295
295
  this.api = new ApiRequest({
296
296
  accessKey: this.accessKey,
297
297
  host: this.host,
@@ -316,7 +316,7 @@ class TheAuthAPI {
316
316
  sentAt: new Date().getTime(),
317
317
  };
318
318
  try {
319
- const key = yield this.api.request(HttpMethod.POST, "/auth/authenticate", data);
319
+ const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
320
320
  done(key);
321
321
  return key;
322
322
  }
@@ -1 +1 @@
1
- export const version = "1.0.11";
1
+ export const version = '1.0.11';
@@ -1,4 +1,4 @@
1
- import { HttpMethod } from "./HttpMethod";
1
+ import { HttpMethod } from './HttpMethod';
2
2
  interface ApiCall {
3
3
  request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
4
4
  }
@@ -1,5 +1,5 @@
1
- import { HttpMethod } from "./HttpMethod";
2
- import ApiCall from "./ApiCall";
1
+ import { HttpMethod } from './HttpMethod';
2
+ import ApiCall from './ApiCall';
3
3
  type Config = {
4
4
  host: string;
5
5
  accessKey: string;
@@ -15,9 +15,9 @@ declare class ApiRequest implements ApiCall {
15
15
  _init(): void;
16
16
  request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
17
17
  _generateDefaultHeaders(): {
18
- "user-agent": string;
19
- "x-api-key": string;
20
- "api-key": string;
18
+ 'user-agent': string;
19
+ 'x-api-key': string;
20
+ 'api-key': string;
21
21
  };
22
22
  _isErrorRetryable(error: any): boolean;
23
23
  }
@@ -7,11 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import axios from "axios";
11
- import { version } from "../../libraryMeta";
12
- import ApiRequestError from "./ApiRequestError";
13
- import axiosRetry from "axios-retry";
14
- import ApiResponseError from "./ApiResponseError";
10
+ import axios from 'axios';
11
+ import { version } from '../../libraryMeta';
12
+ import ApiRequestError from './ApiRequestError';
13
+ import axiosRetry from 'axios-retry';
14
+ import ApiResponseError from './ApiResponseError';
15
15
  class ApiRequest {
16
16
  constructor(config) {
17
17
  const { host, accessKey, headers, retryCount } = config;
@@ -28,10 +28,10 @@ class ApiRequest {
28
28
  var _a;
29
29
  const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
30
30
  function isIsoDateString(value) {
31
- return value && typeof value === "string" && isoDateFormat.test(value);
31
+ return value && typeof value === 'string' && isoDateFormat.test(value);
32
32
  }
33
33
  function handleDates(body) {
34
- if (body === null || body === undefined || typeof body !== "object") {
34
+ if (body === null || body === undefined || typeof body !== 'object') {
35
35
  return body;
36
36
  }
37
37
  for (const key of Object.keys(body)) {
@@ -39,7 +39,7 @@ class ApiRequest {
39
39
  if (isIsoDateString(value)) {
40
40
  body[key] = new Date(value);
41
41
  }
42
- else if (typeof value === "object") {
42
+ else if (typeof value === 'object') {
43
43
  handleDates(value);
44
44
  }
45
45
  }
@@ -82,9 +82,9 @@ class ApiRequest {
82
82
  }
83
83
  _generateDefaultHeaders() {
84
84
  return {
85
- "user-agent": `theauthapi-client-node/${version}`,
86
- "x-api-key": this.accessKey,
87
- "api-key": this.accessKey,
85
+ 'user-agent': `theauthapi-client-node/${version}`,
86
+ 'x-api-key': this.accessKey,
87
+ 'api-key': this.accessKey,
88
88
  };
89
89
  }
90
90
  _isErrorRetryable(error) {
@@ -9,7 +9,7 @@ class ApiResponseError extends Error {
9
9
  constructor(statusCode, message) {
10
10
  super(`(${statusCode}): ${message}`);
11
11
  this.statusCode = statusCode;
12
- this.name = "ApiResponseError";
12
+ this.name = 'ApiResponseError';
13
13
  }
14
14
  }
15
15
  export default ApiResponseError;
package/package.json CHANGED
@@ -1,10 +1,21 @@
1
1
  {
2
2
  "name": "theauthapi",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Client library for TheAuthAPI.com",
5
5
  "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
6
+ "types": "dist/index.d.cts",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "default": "./dist/index.cjs"
16
+ }
17
+ }
18
+ },
8
19
  "type": "module",
9
20
  "files": [
10
21
  "dist"
@@ -16,11 +27,16 @@
16
27
  "scripts": {
17
28
  "test": "jest --runInBand",
18
29
  "test:coverage": "jest --coverage --runInBand",
19
- "build": "rollup -c",
20
- "ci": "npm run build && npm run test",
30
+ "build": "npm run build:rollup && npm run fix-cts",
31
+ "build:rollup": "rollup -c",
32
+ "fix-cts": "node scripts/convert-cts.js",
33
+ "ci": "npm run build && npm run check-format && npm run check-exports && npm run test",
21
34
  "changeset": "npx changeset",
22
35
  "prepublishOnly": "npm run ci",
23
- "local-release": "changeset version && changeset publish"
36
+ "local-release": "npm run ci && changeset version && changeset publish",
37
+ "format": "prettier --write .",
38
+ "check-format": "prettier --check .",
39
+ "check-exports": "attw --pack ."
24
40
  },
25
41
  "repository": {
26
42
  "type": "git",
@@ -39,6 +55,7 @@
39
55
  "remove-trailing-slash": "^0.1.1"
40
56
  },
41
57
  "devDependencies": {
58
+ "@arethetypeswrong/cli": "^0.17.4",
42
59
  "@changesets/cli": "^2.28.1",
43
60
  "@rollup/plugin-commonjs": "^28.0.3",
44
61
  "@rollup/plugin-node-resolve": "^16.0.1",