@ibertran/fortytwo-intra-client 3.1.4 → 3.2.0
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 +0 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +14 -9
- package/dist/lib/errors.d.ts +9 -0
- package/dist/lib/errors.js +31 -0
- package/dist/lib/logs.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,6 @@ interface FortytwoIntraClientConf {
|
|
|
44
44
|
maxRetry: number; // Max retry attempts (default: 5)
|
|
45
45
|
logLine: boolean; // Enable request logging (default: true)
|
|
46
46
|
errLogBody: boolean; // Log error response bodies (default: true)
|
|
47
|
-
throwOnError: boolean; // Throw errors instead of returning them (default: true)
|
|
48
47
|
}
|
|
49
48
|
```
|
|
50
49
|
|
|
@@ -57,7 +56,6 @@ const client = new FortytwoIntraClient('your_client_id', 'your_client_secret', {
|
|
|
57
56
|
maxRetry: 3, // Retry up to 3 times
|
|
58
57
|
logLine: false, // Disable logging
|
|
59
58
|
errLogBody: false, // Disable error body logging
|
|
60
|
-
throwOnError: false, // Return errors instead of throwing
|
|
61
59
|
scopes: ['public', 'projects'] // Extended scopes
|
|
62
60
|
});
|
|
63
61
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { inputOptions } from "./types";
|
|
2
|
+
import { FortytwoIntraClientError, isFortytwoIntraClientError } from "./lib/errors";
|
|
2
3
|
export interface FortytwoIntraClientConf {
|
|
3
4
|
redirect_uri: string | null;
|
|
4
5
|
base_url: string;
|
|
@@ -54,3 +55,4 @@ export declare class FortytwoIntraClient {
|
|
|
54
55
|
exchangeOAuthCode(code: string, redirect_uri?: string): Promise<any>;
|
|
55
56
|
tokenInfos(options?: Omit<inputOptions, "body" | "perPage" | "maxPage">): Promise<any>;
|
|
56
57
|
}
|
|
58
|
+
export { FortytwoIntraClientError, isFortytwoIntraClientError };
|
package/dist/index.js
CHANGED
|
@@ -3,11 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FortytwoIntraClient = void 0;
|
|
6
|
+
exports.isFortytwoIntraClientError = exports.FortytwoIntraClientError = exports.FortytwoIntraClient = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const axios_rate_limit_1 = __importDefault(require("axios-rate-limit"));
|
|
9
9
|
const pagination_1 = require("./lib/pagination");
|
|
10
10
|
const logs_1 = require("./lib/logs");
|
|
11
|
+
const errors_1 = require("./lib/errors");
|
|
12
|
+
Object.defineProperty(exports, "FortytwoIntraClientError", { enumerable: true, get: function () { return errors_1.FortytwoIntraClientError; } });
|
|
13
|
+
Object.defineProperty(exports, "isFortytwoIntraClientError", { enumerable: true, get: function () { return errors_1.isFortytwoIntraClientError; } });
|
|
11
14
|
const crypto_1 = __importDefault(require("crypto"));
|
|
12
15
|
const defaultConf = {
|
|
13
16
|
redirect_uri: null,
|
|
@@ -124,8 +127,11 @@ class FortytwoIntraClient {
|
|
|
124
127
|
return this.reqHandler(url, options);
|
|
125
128
|
}
|
|
126
129
|
else {
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
const clientError = (0, errors_1.simplifyAxiosError)(err);
|
|
131
|
+
if (this.throwOnError) {
|
|
132
|
+
throw clientError;
|
|
133
|
+
}
|
|
134
|
+
return clientError;
|
|
129
135
|
}
|
|
130
136
|
}
|
|
131
137
|
else {
|
|
@@ -229,7 +235,7 @@ class FortytwoIntraClient {
|
|
|
229
235
|
}
|
|
230
236
|
const perPage = options.perPage || 100;
|
|
231
237
|
let url = new URL(endpoint);
|
|
232
|
-
const
|
|
238
|
+
const firstPage = await this.reqHandler(url, {
|
|
233
239
|
method: "GET",
|
|
234
240
|
attempt: 0,
|
|
235
241
|
currpage: 1,
|
|
@@ -246,10 +252,10 @@ class FortytwoIntraClient {
|
|
|
246
252
|
});
|
|
247
253
|
let lastPage;
|
|
248
254
|
try {
|
|
249
|
-
lastPage = Math.min((0, pagination_1.getLastPage)(
|
|
255
|
+
lastPage = Math.min((0, pagination_1.getLastPage)(firstPage.headers["link"]), options.maxPages || Infinity);
|
|
250
256
|
}
|
|
251
257
|
catch (err) {
|
|
252
|
-
return
|
|
258
|
+
return firstPage?.data;
|
|
253
259
|
}
|
|
254
260
|
const promises = [];
|
|
255
261
|
for (let i = 2; i <= lastPage; i++) {
|
|
@@ -270,9 +276,8 @@ class FortytwoIntraClient {
|
|
|
270
276
|
}
|
|
271
277
|
}));
|
|
272
278
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
});
|
|
279
|
+
const followingPages = await Promise.all(promises);
|
|
280
|
+
return firstPage?.data.concat(...followingPages.map((value) => value.data));
|
|
276
281
|
}
|
|
277
282
|
URL(endpoint) {
|
|
278
283
|
return new URL(endpoint, this.base_url);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AxiosError } from "axios";
|
|
2
|
+
export declare class FortytwoIntraClientError extends Error {
|
|
3
|
+
statusCode: number | null;
|
|
4
|
+
statusText: string | null;
|
|
5
|
+
data: any;
|
|
6
|
+
constructor(error: AxiosError);
|
|
7
|
+
}
|
|
8
|
+
export declare function simplifyAxiosError(error: AxiosError): FortytwoIntraClientError;
|
|
9
|
+
export declare function isFortytwoIntraClientError(error: any): error is FortytwoIntraClientError;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FortytwoIntraClientError = void 0;
|
|
4
|
+
exports.simplifyAxiosError = simplifyAxiosError;
|
|
5
|
+
exports.isFortytwoIntraClientError = isFortytwoIntraClientError;
|
|
6
|
+
class FortytwoIntraClientError extends Error {
|
|
7
|
+
statusCode;
|
|
8
|
+
statusText;
|
|
9
|
+
data;
|
|
10
|
+
constructor(error) {
|
|
11
|
+
const method = error.config?.method?.toUpperCase() ?? null;
|
|
12
|
+
const route = error.config?.url ?? null;
|
|
13
|
+
const statusCode = error.response?.status ?? NaN;
|
|
14
|
+
const statusText = error.response?.statusText ?? "Unknown";
|
|
15
|
+
const message = method && route
|
|
16
|
+
? `${method} ${route} - HTTP ${statusCode} ${statusText}`
|
|
17
|
+
: error.message;
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "FortytwoIntraClientError";
|
|
20
|
+
this.statusCode = statusCode;
|
|
21
|
+
this.statusText = statusText;
|
|
22
|
+
this.data = error.response?.data;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.FortytwoIntraClientError = FortytwoIntraClientError;
|
|
26
|
+
function simplifyAxiosError(error) {
|
|
27
|
+
return new FortytwoIntraClientError(error);
|
|
28
|
+
}
|
|
29
|
+
function isFortytwoIntraClientError(error) {
|
|
30
|
+
return error instanceof FortytwoIntraClientError;
|
|
31
|
+
}
|
package/dist/lib/logs.js
CHANGED
|
@@ -5,7 +5,6 @@ exports.getErrorLogLine = getErrorLogLine;
|
|
|
5
5
|
const util_1 = require("util");
|
|
6
6
|
const green = "\x1b[42m";
|
|
7
7
|
const red = "\x1b[41m";
|
|
8
|
-
const yellow = "\x1b[43m";
|
|
9
8
|
const reset = "\x1b[0m";
|
|
10
9
|
function formatQueryParams(params) {
|
|
11
10
|
const { per_page, page, ...filteredParams } = params;
|