@abyss-project/probe 2.0.0 → 2.0.1
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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +22 -22
- package/package.json +10 -15
- package/src/api/index.ts +6 -6
- package/src/api/probe-scan.api.test.ts +47 -47
- package/src/api/probe-scan.api.ts +203 -203
- package/src/api/probe-scan.application.api.test.ts +35 -35
- package/src/api/probe-scan.application.api.ts +157 -157
- package/src/api/probe-usage.api.ts +47 -47
- package/src/api/probe-usage.application.api.ts +25 -25
- package/src/api/probe-webhook.api.test.ts +17 -17
- package/src/api/probe-webhook.api.ts +119 -119
- package/src/api/probe-webhook.application.api.test.ts +18 -18
- package/src/api/probe-webhook.application.api.ts +141 -141
- package/src/constants/index.ts +1 -1
- package/src/index.ts +205 -205
- package/src/types/enum/api-error.enum.ts +33 -33
- package/src/types/enum/index.ts +2 -2
- package/src/types/enum/probe-scan.enum.ts +44 -44
- package/src/types/index.ts +2 -2
- package/src/types/interface/api/index.ts +5 -5
- package/src/types/interface/api/requests/index.ts +3 -3
- package/src/types/interface/api/requests/probe-scan.request.ts +54 -54
- package/src/types/interface/api/requests/probe-usage.request.ts +7 -7
- package/src/types/interface/api/requests/probe-webhook.request.ts +33 -33
- package/src/types/interface/api/responses/index.ts +3 -3
- package/src/types/interface/api/responses/probe-scan.response.ts +45 -45
- package/src/types/interface/api/responses/probe-usage.response.ts +25 -25
- package/src/types/interface/api/responses/probe-webhook.response.ts +24 -24
- package/src/types/interface/api/type-message/api-error.ts +7 -7
- package/src/types/interface/api/type-message/base-paginate.ts +11 -11
- package/src/types/interface/api/type-message/response.ts +6 -6
- package/src/types/interface/index.ts +2 -2
- package/src/types/interface/models/index.ts +3 -3
- package/src/types/interface/models/probe-scan.dto.ts +67 -67
- package/src/types/interface/models/probe-webhook-delivery.dto.ts +73 -73
- package/src/types/interface/models/probe-webhook.dto.ts +29 -29
- package/src/types/tests/probe.dto.test.ts +156 -156
- package/src/utils/enum.utils.ts +1 -1
- package/src/utils/error.utils.ts +30 -30
- package/src/utils/index.ts +4 -4
- package/src/utils/probe-scan-cost.utils.ts +101 -101
- package/src/utils/probe-webhook-signature.utils.ts +56 -56
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +36 -36
package/src/index.ts
CHANGED
|
@@ -1,205 +1,205 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import axiosRetry, { IAxiosRetryConfig, isNetworkOrIdempotentRequestError } from 'axios-retry';
|
|
3
|
-
import * as probeScanApi from './api/probe-scan.api';
|
|
4
|
-
import * as probeWebhookApi from './api/probe-webhook.api';
|
|
5
|
-
import * as probeScanApplicationApi from './api/probe-scan.application.api';
|
|
6
|
-
import * as probeWebhookApplicationApi from './api/probe-webhook.application.api';
|
|
7
|
-
import * as probeUsageApi from './api/probe-usage.api';
|
|
8
|
-
import * as probeUsageApplicationApi from './api/probe-usage.application.api';
|
|
9
|
-
|
|
10
|
-
export * from './api';
|
|
11
|
-
export * from './types';
|
|
12
|
-
export * from './utils';
|
|
13
|
-
export * from './constants';
|
|
14
|
-
|
|
15
|
-
const DEFAULT_BASE_URL = 'https://probe-api.abyss-project.fr/api/';
|
|
16
|
-
|
|
17
|
-
export const API_KEY_HEADER = 'abyss-api-key';
|
|
18
|
-
/**
|
|
19
|
-
* Application-level API key header (AbyssProbe application/API-key
|
|
20
|
-
* authentication). Same literal value every other Abyss service's own core
|
|
21
|
-
* package independently declares for its `ApplicationMiddleware`.
|
|
22
|
-
*/
|
|
23
|
-
export const API_KEY_APPLICATION_HEADER = 'abyss-api-key-application';
|
|
24
|
-
export const ADMIN_TOKEN_HEADER = 'abyss-admin-token';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Header carrying the HMAC-SHA256 signature of a probe webhook delivery's
|
|
28
|
-
* raw JSON body. Verify it with {@link verifyProbeWebhookSignature}
|
|
29
|
-
* (re-exported from './utils').
|
|
30
|
-
*/
|
|
31
|
-
export const PROBE_WEBHOOK_SIGNATURE_HEADER = 'x-probe-signature';
|
|
32
|
-
export const PROBE_WEBHOOK_SIGNATURE_ALGORITHM = 'sha256';
|
|
33
|
-
|
|
34
|
-
const NUMBER_RETRY_API = 10;
|
|
35
|
-
const BASE_DELAY_BETWEEN_RETRY = 5000;
|
|
36
|
-
const RETRY_CODES = [
|
|
37
|
-
502, // Bad Gateway
|
|
38
|
-
503, // Service Unavailable
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
type CoreConfig = {
|
|
42
|
-
token?: string;
|
|
43
|
-
apiKey?: string;
|
|
44
|
-
adminToken?: string;
|
|
45
|
-
baseURL?: string;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
type AbyssProbeCoreSDK = {
|
|
49
|
-
probe: {
|
|
50
|
-
/** `POST /scan` — sync (default) or async depending on `options.mode`. */
|
|
51
|
-
scan: typeof probeScanApi.scan;
|
|
52
|
-
/** `POST /scan` forced to `mode: sync` — precisely-typed 200 response. */
|
|
53
|
-
scanSync: typeof probeScanApi.scanSync;
|
|
54
|
-
/** `POST /scan?mode=async` — precisely-typed 202 response. */
|
|
55
|
-
scanAsync: typeof probeScanApi.scanAsync;
|
|
56
|
-
/** `GET /scan/:scanId` — poll a scan's status/verdict. */
|
|
57
|
-
getScan: typeof probeScanApi.getScan;
|
|
58
|
-
/** `GET /scan` — paginated history/search. */
|
|
59
|
-
listScans: typeof probeScanApi.listScans;
|
|
60
|
-
/** `GET /usage` — current ACCOUNT_AV_SCAN_UNITS used/limit/remaining for the caller's scope. */
|
|
61
|
-
usage: {
|
|
62
|
-
get: typeof probeUsageApi.getProbeUsage;
|
|
63
|
-
};
|
|
64
|
-
webhook: {
|
|
65
|
-
create: typeof probeWebhookApi.createProbeWebhook;
|
|
66
|
-
list: typeof probeWebhookApi.listProbeWebhook;
|
|
67
|
-
delete: typeof probeWebhookApi.deleteProbeWebhook;
|
|
68
|
-
/** `PATCH /webhook/:webhookId` — edit callbackUrl and/or active. */
|
|
69
|
-
update: typeof probeWebhookApi.updateProbeWebhook;
|
|
70
|
-
/** `GET /webhook/:webhookId/deliveries` — paginated delivery-attempt history. */
|
|
71
|
-
listDeliveries: typeof probeWebhookApi.listProbeWebhookDeliveries;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Application/API-key-auth counterpart (Phase 3a) — for inter-service
|
|
75
|
-
* callers (abyss-storage, external integrations) instead of a
|
|
76
|
-
* personal/org session. Same request/response contracts as the methods
|
|
77
|
-
* above, hitting `/application/:applicationId/...` and authenticated
|
|
78
|
-
* with the `abyss-api-key-application` header ({@link
|
|
79
|
-
* API_KEY_APPLICATION_HEADER}) instead of the personal `abyss-api-key`.
|
|
80
|
-
*/
|
|
81
|
-
application: {
|
|
82
|
-
/** `POST /application/:applicationId/scan` — sync (default) or async depending on `options.mode`. */
|
|
83
|
-
scan: typeof probeScanApplicationApi.scanApplication;
|
|
84
|
-
/** `POST /application/:applicationId/scan` forced to `mode: sync` — precisely-typed 200 response. */
|
|
85
|
-
scanSync: typeof probeScanApplicationApi.scanSyncApplication;
|
|
86
|
-
/** `POST /application/:applicationId/scan?mode=async` — precisely-typed 202 response. */
|
|
87
|
-
scanAsync: typeof probeScanApplicationApi.scanAsyncApplication;
|
|
88
|
-
/** `GET /application/:applicationId/scan/:scanId` — poll a scan's status/verdict. */
|
|
89
|
-
getScan: typeof probeScanApplicationApi.getScanApplication;
|
|
90
|
-
/** `GET /application/:applicationId/scan` — paginated history/search. */
|
|
91
|
-
listScans: typeof probeScanApplicationApi.listScansApplication;
|
|
92
|
-
/** `GET /application/:applicationId/usage` — current ACCOUNT_AV_SCAN_UNITS used/limit/remaining for the calling application. */
|
|
93
|
-
usage: {
|
|
94
|
-
get: typeof probeUsageApplicationApi.getProbeUsageApplication;
|
|
95
|
-
};
|
|
96
|
-
webhook: {
|
|
97
|
-
create: typeof probeWebhookApplicationApi.createProbeWebhookApplication;
|
|
98
|
-
list: typeof probeWebhookApplicationApi.listProbeWebhookApplication;
|
|
99
|
-
delete: typeof probeWebhookApplicationApi.deleteProbeWebhookApplication;
|
|
100
|
-
/** `PATCH /application/:applicationId/webhook/:webhookId` — edit callbackUrl and/or active. */
|
|
101
|
-
update: typeof probeWebhookApplicationApi.updateProbeWebhookApplication;
|
|
102
|
-
/** `GET /application/:applicationId/webhook/:webhookId/deliveries` — paginated delivery-attempt history. */
|
|
103
|
-
listDeliveries: typeof probeWebhookApplicationApi.listProbeWebhookDeliveriesApplication;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export class AbyssProbeCore {
|
|
110
|
-
private static config = {
|
|
111
|
-
token: '',
|
|
112
|
-
apiKey: '',
|
|
113
|
-
adminToken: '',
|
|
114
|
-
baseURL: DEFAULT_BASE_URL,
|
|
115
|
-
};
|
|
116
|
-
static axios = axios.create({
|
|
117
|
-
baseURL: this.config.baseURL,
|
|
118
|
-
withCredentials: true,
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
private static _sdk: AbyssProbeCoreSDK | null = null;
|
|
122
|
-
|
|
123
|
-
public static get sdk(): AbyssProbeCoreSDK {
|
|
124
|
-
if (!AbyssProbeCore._sdk) {
|
|
125
|
-
AbyssProbeCore._sdk = AbyssProbeCore.buildSDK();
|
|
126
|
-
}
|
|
127
|
-
return AbyssProbeCore._sdk;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private static buildSDK(): AbyssProbeCoreSDK {
|
|
131
|
-
return {
|
|
132
|
-
probe: {
|
|
133
|
-
scan: probeScanApi.scan,
|
|
134
|
-
scanSync: probeScanApi.scanSync,
|
|
135
|
-
scanAsync: probeScanApi.scanAsync,
|
|
136
|
-
getScan: probeScanApi.getScan,
|
|
137
|
-
listScans: probeScanApi.listScans,
|
|
138
|
-
usage: {
|
|
139
|
-
get: probeUsageApi.getProbeUsage,
|
|
140
|
-
},
|
|
141
|
-
webhook: {
|
|
142
|
-
create: probeWebhookApi.createProbeWebhook,
|
|
143
|
-
list: probeWebhookApi.listProbeWebhook,
|
|
144
|
-
delete: probeWebhookApi.deleteProbeWebhook,
|
|
145
|
-
update: probeWebhookApi.updateProbeWebhook,
|
|
146
|
-
listDeliveries: probeWebhookApi.listProbeWebhookDeliveries,
|
|
147
|
-
},
|
|
148
|
-
application: {
|
|
149
|
-
scan: probeScanApplicationApi.scanApplication,
|
|
150
|
-
scanSync: probeScanApplicationApi.scanSyncApplication,
|
|
151
|
-
scanAsync: probeScanApplicationApi.scanAsyncApplication,
|
|
152
|
-
getScan: probeScanApplicationApi.getScanApplication,
|
|
153
|
-
listScans: probeScanApplicationApi.listScansApplication,
|
|
154
|
-
usage: {
|
|
155
|
-
get: probeUsageApplicationApi.getProbeUsageApplication,
|
|
156
|
-
},
|
|
157
|
-
webhook: {
|
|
158
|
-
create: probeWebhookApplicationApi.createProbeWebhookApplication,
|
|
159
|
-
list: probeWebhookApplicationApi.listProbeWebhookApplication,
|
|
160
|
-
delete: probeWebhookApplicationApi.deleteProbeWebhookApplication,
|
|
161
|
-
update: probeWebhookApplicationApi.updateProbeWebhookApplication,
|
|
162
|
-
listDeliveries: probeWebhookApplicationApi.listProbeWebhookDeliveriesApplication,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
public static enableAxiosRetry(axiosRetryConfig?: IAxiosRetryConfig): void {
|
|
170
|
-
axiosRetry(AbyssProbeCore.axios, {
|
|
171
|
-
retries: NUMBER_RETRY_API,
|
|
172
|
-
retryDelay: (retryCount) => retryCount * BASE_DELAY_BETWEEN_RETRY,
|
|
173
|
-
retryCondition: (error) =>
|
|
174
|
-
isNetworkOrIdempotentRequestError(error) ||
|
|
175
|
-
RETRY_CODES.includes(error.response?.status || 502),
|
|
176
|
-
...axiosRetryConfig,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public static setConfig(config: CoreConfig): void {
|
|
181
|
-
AbyssProbeCore._sdk = null;
|
|
182
|
-
|
|
183
|
-
AbyssProbeCore.config = { ...AbyssProbeCore.config, ...config };
|
|
184
|
-
|
|
185
|
-
if (config.baseURL) {
|
|
186
|
-
AbyssProbeCore.axios.defaults.baseURL = config.baseURL;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (config.token) {
|
|
190
|
-
AbyssProbeCore.axios.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (config.apiKey) {
|
|
194
|
-
AbyssProbeCore.axios.defaults.headers.common[API_KEY_HEADER] = `${config.apiKey}`;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (config.adminToken) {
|
|
198
|
-
AbyssProbeCore.axios.defaults.headers.common[ADMIN_TOKEN_HEADER] = `${config.adminToken}`;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
public static getConfig(): CoreConfig {
|
|
203
|
-
return AbyssProbeCore.config;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import axiosRetry, { IAxiosRetryConfig, isNetworkOrIdempotentRequestError } from 'axios-retry';
|
|
3
|
+
import * as probeScanApi from './api/probe-scan.api';
|
|
4
|
+
import * as probeWebhookApi from './api/probe-webhook.api';
|
|
5
|
+
import * as probeScanApplicationApi from './api/probe-scan.application.api';
|
|
6
|
+
import * as probeWebhookApplicationApi from './api/probe-webhook.application.api';
|
|
7
|
+
import * as probeUsageApi from './api/probe-usage.api';
|
|
8
|
+
import * as probeUsageApplicationApi from './api/probe-usage.application.api';
|
|
9
|
+
|
|
10
|
+
export * from './api';
|
|
11
|
+
export * from './types';
|
|
12
|
+
export * from './utils';
|
|
13
|
+
export * from './constants';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_BASE_URL = 'https://probe-api.abyss-project.fr/api/';
|
|
16
|
+
|
|
17
|
+
export const API_KEY_HEADER = 'abyss-api-key';
|
|
18
|
+
/**
|
|
19
|
+
* Application-level API key header (AbyssProbe application/API-key
|
|
20
|
+
* authentication). Same literal value every other Abyss service's own core
|
|
21
|
+
* package independently declares for its `ApplicationMiddleware`.
|
|
22
|
+
*/
|
|
23
|
+
export const API_KEY_APPLICATION_HEADER = 'abyss-api-key-application';
|
|
24
|
+
export const ADMIN_TOKEN_HEADER = 'abyss-admin-token';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Header carrying the HMAC-SHA256 signature of a probe webhook delivery's
|
|
28
|
+
* raw JSON body. Verify it with {@link verifyProbeWebhookSignature}
|
|
29
|
+
* (re-exported from './utils').
|
|
30
|
+
*/
|
|
31
|
+
export const PROBE_WEBHOOK_SIGNATURE_HEADER = 'x-probe-signature';
|
|
32
|
+
export const PROBE_WEBHOOK_SIGNATURE_ALGORITHM = 'sha256';
|
|
33
|
+
|
|
34
|
+
const NUMBER_RETRY_API = 10;
|
|
35
|
+
const BASE_DELAY_BETWEEN_RETRY = 5000;
|
|
36
|
+
const RETRY_CODES = [
|
|
37
|
+
502, // Bad Gateway
|
|
38
|
+
503, // Service Unavailable
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
type CoreConfig = {
|
|
42
|
+
token?: string;
|
|
43
|
+
apiKey?: string;
|
|
44
|
+
adminToken?: string;
|
|
45
|
+
baseURL?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type AbyssProbeCoreSDK = {
|
|
49
|
+
probe: {
|
|
50
|
+
/** `POST /scan` — sync (default) or async depending on `options.mode`. */
|
|
51
|
+
scan: typeof probeScanApi.scan;
|
|
52
|
+
/** `POST /scan` forced to `mode: sync` — precisely-typed 200 response. */
|
|
53
|
+
scanSync: typeof probeScanApi.scanSync;
|
|
54
|
+
/** `POST /scan?mode=async` — precisely-typed 202 response. */
|
|
55
|
+
scanAsync: typeof probeScanApi.scanAsync;
|
|
56
|
+
/** `GET /scan/:scanId` — poll a scan's status/verdict. */
|
|
57
|
+
getScan: typeof probeScanApi.getScan;
|
|
58
|
+
/** `GET /scan` — paginated history/search. */
|
|
59
|
+
listScans: typeof probeScanApi.listScans;
|
|
60
|
+
/** `GET /usage` — current ACCOUNT_AV_SCAN_UNITS used/limit/remaining for the caller's scope. */
|
|
61
|
+
usage: {
|
|
62
|
+
get: typeof probeUsageApi.getProbeUsage;
|
|
63
|
+
};
|
|
64
|
+
webhook: {
|
|
65
|
+
create: typeof probeWebhookApi.createProbeWebhook;
|
|
66
|
+
list: typeof probeWebhookApi.listProbeWebhook;
|
|
67
|
+
delete: typeof probeWebhookApi.deleteProbeWebhook;
|
|
68
|
+
/** `PATCH /webhook/:webhookId` — edit callbackUrl and/or active. */
|
|
69
|
+
update: typeof probeWebhookApi.updateProbeWebhook;
|
|
70
|
+
/** `GET /webhook/:webhookId/deliveries` — paginated delivery-attempt history. */
|
|
71
|
+
listDeliveries: typeof probeWebhookApi.listProbeWebhookDeliveries;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Application/API-key-auth counterpart (Phase 3a) — for inter-service
|
|
75
|
+
* callers (abyss-storage, external integrations) instead of a
|
|
76
|
+
* personal/org session. Same request/response contracts as the methods
|
|
77
|
+
* above, hitting `/application/:applicationId/...` and authenticated
|
|
78
|
+
* with the `abyss-api-key-application` header ({@link
|
|
79
|
+
* API_KEY_APPLICATION_HEADER}) instead of the personal `abyss-api-key`.
|
|
80
|
+
*/
|
|
81
|
+
application: {
|
|
82
|
+
/** `POST /application/:applicationId/scan` — sync (default) or async depending on `options.mode`. */
|
|
83
|
+
scan: typeof probeScanApplicationApi.scanApplication;
|
|
84
|
+
/** `POST /application/:applicationId/scan` forced to `mode: sync` — precisely-typed 200 response. */
|
|
85
|
+
scanSync: typeof probeScanApplicationApi.scanSyncApplication;
|
|
86
|
+
/** `POST /application/:applicationId/scan?mode=async` — precisely-typed 202 response. */
|
|
87
|
+
scanAsync: typeof probeScanApplicationApi.scanAsyncApplication;
|
|
88
|
+
/** `GET /application/:applicationId/scan/:scanId` — poll a scan's status/verdict. */
|
|
89
|
+
getScan: typeof probeScanApplicationApi.getScanApplication;
|
|
90
|
+
/** `GET /application/:applicationId/scan` — paginated history/search. */
|
|
91
|
+
listScans: typeof probeScanApplicationApi.listScansApplication;
|
|
92
|
+
/** `GET /application/:applicationId/usage` — current ACCOUNT_AV_SCAN_UNITS used/limit/remaining for the calling application. */
|
|
93
|
+
usage: {
|
|
94
|
+
get: typeof probeUsageApplicationApi.getProbeUsageApplication;
|
|
95
|
+
};
|
|
96
|
+
webhook: {
|
|
97
|
+
create: typeof probeWebhookApplicationApi.createProbeWebhookApplication;
|
|
98
|
+
list: typeof probeWebhookApplicationApi.listProbeWebhookApplication;
|
|
99
|
+
delete: typeof probeWebhookApplicationApi.deleteProbeWebhookApplication;
|
|
100
|
+
/** `PATCH /application/:applicationId/webhook/:webhookId` — edit callbackUrl and/or active. */
|
|
101
|
+
update: typeof probeWebhookApplicationApi.updateProbeWebhookApplication;
|
|
102
|
+
/** `GET /application/:applicationId/webhook/:webhookId/deliveries` — paginated delivery-attempt history. */
|
|
103
|
+
listDeliveries: typeof probeWebhookApplicationApi.listProbeWebhookDeliveriesApplication;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export class AbyssProbeCore {
|
|
110
|
+
private static config = {
|
|
111
|
+
token: '',
|
|
112
|
+
apiKey: '',
|
|
113
|
+
adminToken: '',
|
|
114
|
+
baseURL: DEFAULT_BASE_URL,
|
|
115
|
+
};
|
|
116
|
+
static axios = axios.create({
|
|
117
|
+
baseURL: this.config.baseURL,
|
|
118
|
+
withCredentials: true,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
private static _sdk: AbyssProbeCoreSDK | null = null;
|
|
122
|
+
|
|
123
|
+
public static get sdk(): AbyssProbeCoreSDK {
|
|
124
|
+
if (!AbyssProbeCore._sdk) {
|
|
125
|
+
AbyssProbeCore._sdk = AbyssProbeCore.buildSDK();
|
|
126
|
+
}
|
|
127
|
+
return AbyssProbeCore._sdk;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private static buildSDK(): AbyssProbeCoreSDK {
|
|
131
|
+
return {
|
|
132
|
+
probe: {
|
|
133
|
+
scan: probeScanApi.scan,
|
|
134
|
+
scanSync: probeScanApi.scanSync,
|
|
135
|
+
scanAsync: probeScanApi.scanAsync,
|
|
136
|
+
getScan: probeScanApi.getScan,
|
|
137
|
+
listScans: probeScanApi.listScans,
|
|
138
|
+
usage: {
|
|
139
|
+
get: probeUsageApi.getProbeUsage,
|
|
140
|
+
},
|
|
141
|
+
webhook: {
|
|
142
|
+
create: probeWebhookApi.createProbeWebhook,
|
|
143
|
+
list: probeWebhookApi.listProbeWebhook,
|
|
144
|
+
delete: probeWebhookApi.deleteProbeWebhook,
|
|
145
|
+
update: probeWebhookApi.updateProbeWebhook,
|
|
146
|
+
listDeliveries: probeWebhookApi.listProbeWebhookDeliveries,
|
|
147
|
+
},
|
|
148
|
+
application: {
|
|
149
|
+
scan: probeScanApplicationApi.scanApplication,
|
|
150
|
+
scanSync: probeScanApplicationApi.scanSyncApplication,
|
|
151
|
+
scanAsync: probeScanApplicationApi.scanAsyncApplication,
|
|
152
|
+
getScan: probeScanApplicationApi.getScanApplication,
|
|
153
|
+
listScans: probeScanApplicationApi.listScansApplication,
|
|
154
|
+
usage: {
|
|
155
|
+
get: probeUsageApplicationApi.getProbeUsageApplication,
|
|
156
|
+
},
|
|
157
|
+
webhook: {
|
|
158
|
+
create: probeWebhookApplicationApi.createProbeWebhookApplication,
|
|
159
|
+
list: probeWebhookApplicationApi.listProbeWebhookApplication,
|
|
160
|
+
delete: probeWebhookApplicationApi.deleteProbeWebhookApplication,
|
|
161
|
+
update: probeWebhookApplicationApi.updateProbeWebhookApplication,
|
|
162
|
+
listDeliveries: probeWebhookApplicationApi.listProbeWebhookDeliveriesApplication,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public static enableAxiosRetry(axiosRetryConfig?: IAxiosRetryConfig): void {
|
|
170
|
+
axiosRetry(AbyssProbeCore.axios, {
|
|
171
|
+
retries: NUMBER_RETRY_API,
|
|
172
|
+
retryDelay: (retryCount) => retryCount * BASE_DELAY_BETWEEN_RETRY,
|
|
173
|
+
retryCondition: (error) =>
|
|
174
|
+
isNetworkOrIdempotentRequestError(error) ||
|
|
175
|
+
RETRY_CODES.includes(error.response?.status || 502),
|
|
176
|
+
...axiosRetryConfig,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public static setConfig(config: CoreConfig): void {
|
|
181
|
+
AbyssProbeCore._sdk = null;
|
|
182
|
+
|
|
183
|
+
AbyssProbeCore.config = { ...AbyssProbeCore.config, ...config };
|
|
184
|
+
|
|
185
|
+
if (config.baseURL) {
|
|
186
|
+
AbyssProbeCore.axios.defaults.baseURL = config.baseURL;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (config.token) {
|
|
190
|
+
AbyssProbeCore.axios.defaults.headers.common.Authorization = `Bearer ${config.token}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (config.apiKey) {
|
|
194
|
+
AbyssProbeCore.axios.defaults.headers.common[API_KEY_HEADER] = `${config.apiKey}`;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (config.adminToken) {
|
|
198
|
+
AbyssProbeCore.axios.defaults.headers.common[ADMIN_TOKEN_HEADER] = `${config.adminToken}`;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public static getConfig(): CoreConfig {
|
|
203
|
+
return AbyssProbeCore.config;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
export enum ErrorType {
|
|
2
|
-
apiError = 'api_error',
|
|
3
|
-
authError = 'authentication_error',
|
|
4
|
-
resourceError = 'resource_error',
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export enum Code {
|
|
8
|
-
// HTTP Error
|
|
9
|
-
tokenFailure = 'token_authentication_failure',
|
|
10
|
-
authenticationFailure = 'authentication_credentials_failure',
|
|
11
|
-
accessNotAllowed = 'access_not_allowed',
|
|
12
|
-
notFound = 'not_found',
|
|
13
|
-
validationError = 'resource_validation_error',
|
|
14
|
-
constraintError = 'resource_constraint_error',
|
|
15
|
-
internalServerError = 'internal_server_error',
|
|
16
|
-
serviceUnavailable = 'service_unavailable',
|
|
17
|
-
invalidData = 'invalid_data',
|
|
18
|
-
notImplemented = 'not_implemented',
|
|
19
|
-
retrospectiveCannotBeModifiedWhenCompleted = 'retrospective_cannot_be_modified_when_completed',
|
|
20
|
-
retrospectiveActionNotAllowedInPhase = 'retrospective_action_not_allowed_in_phase',
|
|
21
|
-
retrospectiveVoteBudgetExhausted = 'retrospective_vote_budget_exhausted',
|
|
22
|
-
retrospectiveActionLimitReached = 'retrospective_action_limit_reached',
|
|
23
|
-
atlasDocumentLimitReached = 'atlas_document_limit_reached',
|
|
24
|
-
boardCardDocumentLimitReached = 'board_card_document_limit_reached',
|
|
25
|
-
boardCardMoveInvalidDestination = 'board_card_move_invalid_destination',
|
|
26
|
-
boardCardLinkLimitReached = 'board_card_link_limit_reached',
|
|
27
|
-
boardCardLinkAlreadyExists = 'board_card_link_already_exists',
|
|
28
|
-
boardCardLinkToSelf = 'board_card_link_to_self',
|
|
29
|
-
shortLinkProtected = 'short_link_protected',
|
|
30
|
-
drawImageLimitReached = 'draw_image_limit_reached',
|
|
31
|
-
drawImageOwnerRequired = 'draw_image_owner_required',
|
|
32
|
-
drawImageNotInDraw = 'draw_image_not_in_draw',
|
|
33
|
-
}
|
|
1
|
+
export enum ErrorType {
|
|
2
|
+
apiError = 'api_error',
|
|
3
|
+
authError = 'authentication_error',
|
|
4
|
+
resourceError = 'resource_error',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum Code {
|
|
8
|
+
// HTTP Error
|
|
9
|
+
tokenFailure = 'token_authentication_failure',
|
|
10
|
+
authenticationFailure = 'authentication_credentials_failure',
|
|
11
|
+
accessNotAllowed = 'access_not_allowed',
|
|
12
|
+
notFound = 'not_found',
|
|
13
|
+
validationError = 'resource_validation_error',
|
|
14
|
+
constraintError = 'resource_constraint_error',
|
|
15
|
+
internalServerError = 'internal_server_error',
|
|
16
|
+
serviceUnavailable = 'service_unavailable',
|
|
17
|
+
invalidData = 'invalid_data',
|
|
18
|
+
notImplemented = 'not_implemented',
|
|
19
|
+
retrospectiveCannotBeModifiedWhenCompleted = 'retrospective_cannot_be_modified_when_completed',
|
|
20
|
+
retrospectiveActionNotAllowedInPhase = 'retrospective_action_not_allowed_in_phase',
|
|
21
|
+
retrospectiveVoteBudgetExhausted = 'retrospective_vote_budget_exhausted',
|
|
22
|
+
retrospectiveActionLimitReached = 'retrospective_action_limit_reached',
|
|
23
|
+
atlasDocumentLimitReached = 'atlas_document_limit_reached',
|
|
24
|
+
boardCardDocumentLimitReached = 'board_card_document_limit_reached',
|
|
25
|
+
boardCardMoveInvalidDestination = 'board_card_move_invalid_destination',
|
|
26
|
+
boardCardLinkLimitReached = 'board_card_link_limit_reached',
|
|
27
|
+
boardCardLinkAlreadyExists = 'board_card_link_already_exists',
|
|
28
|
+
boardCardLinkToSelf = 'board_card_link_to_self',
|
|
29
|
+
shortLinkProtected = 'short_link_protected',
|
|
30
|
+
drawImageLimitReached = 'draw_image_limit_reached',
|
|
31
|
+
drawImageOwnerRequired = 'draw_image_owner_required',
|
|
32
|
+
drawImageNotInDraw = 'draw_image_not_in_draw',
|
|
33
|
+
}
|
package/src/types/enum/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './api-error.enum';
|
|
2
|
-
export * from './probe-scan.enum';
|
|
1
|
+
export * from './api-error.enum';
|
|
2
|
+
export * from './probe-scan.enum';
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
// Mirrors apps/api/src/database/probe-scan.enum.ts EXACTLY (same string
|
|
2
|
-
// values — this SDK talks to that API over the wire, so the values must
|
|
3
|
-
// match byte-for-byte). Kept as a single file here too, on purpose: the
|
|
4
|
-
// server groups all three enums in one file for the same reason (they are
|
|
5
|
-
// one cohesive scan vocabulary), see that file's header comment.
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Antivirus scan verdict. `null` on the wire while the scan has not reached
|
|
9
|
-
* `DONE` yet (see {@link ProbeScanStatus}) — a scan that never completes
|
|
10
|
-
* (e.g. the engine throws) is left at its last real status with no
|
|
11
|
-
* fabricated verdict.
|
|
12
|
-
*/
|
|
13
|
-
export enum ProbeScanVerdict {
|
|
14
|
-
CLEAN = 'clean',
|
|
15
|
-
INFECTED = 'infected',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* How the scan was (or will be) run: `SYNC` blocks the request until the
|
|
20
|
-
* engine returns the verdict inline; `ASYNC` queues the job and delivers the
|
|
21
|
-
* verdict later via a registered webhook and/or the per-request
|
|
22
|
-
* `callbackUrl`, and/or by polling `GET /scan/:scanId`.
|
|
23
|
-
*/
|
|
24
|
-
export enum ProbeScanMode {
|
|
25
|
-
SYNC = 'sync',
|
|
26
|
-
ASYNC = 'async',
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Scan lifecycle. A SYNC scan skips `QUEUED` entirely (created directly at
|
|
31
|
-
* `SCANNING`). An ASYNC scan is created at `QUEUED`, flipped to `SCANNING`
|
|
32
|
-
* once a worker picks the job off the queue, then to `DONE` or `ERROR`.
|
|
33
|
-
*
|
|
34
|
-
* `ERROR` (async-only) is a TERMINAL, no-verdict state — there is no
|
|
35
|
-
* automatic requeue/retry (the uploaded bytes are deleted the moment the job
|
|
36
|
-
* ends, success or failure). A caller that wants to retry submits a brand
|
|
37
|
-
* new `POST /scan?mode=async`.
|
|
38
|
-
*/
|
|
39
|
-
export enum ProbeScanStatus {
|
|
40
|
-
QUEUED = 'queued',
|
|
41
|
-
SCANNING = 'scanning',
|
|
42
|
-
DONE = 'done',
|
|
43
|
-
ERROR = 'error',
|
|
44
|
-
}
|
|
1
|
+
// Mirrors apps/api/src/database/probe-scan.enum.ts EXACTLY (same string
|
|
2
|
+
// values — this SDK talks to that API over the wire, so the values must
|
|
3
|
+
// match byte-for-byte). Kept as a single file here too, on purpose: the
|
|
4
|
+
// server groups all three enums in one file for the same reason (they are
|
|
5
|
+
// one cohesive scan vocabulary), see that file's header comment.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Antivirus scan verdict. `null` on the wire while the scan has not reached
|
|
9
|
+
* `DONE` yet (see {@link ProbeScanStatus}) — a scan that never completes
|
|
10
|
+
* (e.g. the engine throws) is left at its last real status with no
|
|
11
|
+
* fabricated verdict.
|
|
12
|
+
*/
|
|
13
|
+
export enum ProbeScanVerdict {
|
|
14
|
+
CLEAN = 'clean',
|
|
15
|
+
INFECTED = 'infected',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How the scan was (or will be) run: `SYNC` blocks the request until the
|
|
20
|
+
* engine returns the verdict inline; `ASYNC` queues the job and delivers the
|
|
21
|
+
* verdict later via a registered webhook and/or the per-request
|
|
22
|
+
* `callbackUrl`, and/or by polling `GET /scan/:scanId`.
|
|
23
|
+
*/
|
|
24
|
+
export enum ProbeScanMode {
|
|
25
|
+
SYNC = 'sync',
|
|
26
|
+
ASYNC = 'async',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Scan lifecycle. A SYNC scan skips `QUEUED` entirely (created directly at
|
|
31
|
+
* `SCANNING`). An ASYNC scan is created at `QUEUED`, flipped to `SCANNING`
|
|
32
|
+
* once a worker picks the job off the queue, then to `DONE` or `ERROR`.
|
|
33
|
+
*
|
|
34
|
+
* `ERROR` (async-only) is a TERMINAL, no-verdict state — there is no
|
|
35
|
+
* automatic requeue/retry (the uploaded bytes are deleted the moment the job
|
|
36
|
+
* ends, success or failure). A caller that wants to retry submits a brand
|
|
37
|
+
* new `POST /scan?mode=async`.
|
|
38
|
+
*/
|
|
39
|
+
export enum ProbeScanStatus {
|
|
40
|
+
QUEUED = 'queued',
|
|
41
|
+
SCANNING = 'scanning',
|
|
42
|
+
DONE = 'done',
|
|
43
|
+
ERROR = 'error',
|
|
44
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './enum';
|
|
2
|
-
export * from './interface';
|
|
1
|
+
export * from './enum';
|
|
2
|
+
export * from './interface';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './requests';
|
|
2
|
-
export * from './responses';
|
|
3
|
-
export * from './type-message/response';
|
|
4
|
-
export * from './type-message/api-error';
|
|
5
|
-
export * from './type-message/base-paginate';
|
|
1
|
+
export * from './requests';
|
|
2
|
+
export * from './responses';
|
|
3
|
+
export * from './type-message/response';
|
|
4
|
+
export * from './type-message/api-error';
|
|
5
|
+
export * from './type-message/base-paginate';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './probe-scan.request';
|
|
2
|
-
export * from './probe-usage.request';
|
|
3
|
-
export * from './probe-webhook.request';
|
|
1
|
+
export * from './probe-scan.request';
|
|
2
|
+
export * from './probe-usage.request';
|
|
3
|
+
export * from './probe-webhook.request';
|