@abyss-project/probe 2.0.0 → 3.0.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/.eslintrc.js +32 -32
- package/.prettierrc +5 -5
- package/README.md +22 -22
- package/dist/api/index.d.ts +2 -1
- package/dist/api/index.js +2 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/probe-delivery-subscription.api.d.ts +11 -0
- package/dist/api/probe-delivery-subscription.api.js +42 -0
- package/dist/api/probe-delivery-subscription.api.js.map +1 -0
- package/dist/api/probe-delivery-subscription.application.api.d.ts +11 -0
- package/dist/api/probe-delivery-subscription.application.api.js +38 -0
- package/dist/api/probe-delivery-subscription.application.api.js.map +1 -0
- package/dist/api/probe-webhook.application.api.d.ts +1 -1
- package/dist/api/probe-webhook.application.api.js.map +1 -1
- package/dist/index.d.ts +29 -7
- package/dist/index.js +29 -7
- package/dist/index.js.map +1 -1
- package/dist/types/enum/api-error.enum.d.ts +2 -1
- package/dist/types/enum/api-error.enum.js +1 -0
- package/dist/types/enum/api-error.enum.js.map +1 -1
- package/dist/types/enum/probe-scan.enum.js.map +1 -1
- package/dist/types/interface/api/requests/index.d.ts +1 -0
- package/dist/types/interface/api/requests/index.js +1 -0
- package/dist/types/interface/api/requests/index.js.map +1 -1
- package/dist/types/interface/api/requests/probe-delivery-subscription.request.d.ts +23 -0
- package/dist/types/interface/api/requests/probe-delivery-subscription.request.js +3 -0
- package/dist/types/interface/api/requests/probe-delivery-subscription.request.js.map +1 -0
- package/dist/types/interface/api/requests/probe-webhook.request.d.ts +1 -4
- package/dist/types/interface/api/responses/index.d.ts +1 -0
- package/dist/types/interface/api/responses/index.js +1 -0
- package/dist/types/interface/api/responses/index.js.map +1 -1
- package/dist/types/interface/api/responses/probe-delivery-subscription.response.d.ts +10 -0
- package/dist/types/interface/api/responses/probe-delivery-subscription.response.js +3 -0
- package/dist/types/interface/api/responses/probe-delivery-subscription.response.js.map +1 -0
- package/dist/types/tests/probe.dto.test.js +22 -0
- package/dist/types/tests/probe.dto.test.js.map +1 -1
- package/dist/utils/probe-webhook-signature.utils.js.map +1 -1
- package/package.json +19 -15
- package/src/api/index.ts +2 -1
- package/src/api/probe-delivery-subscription.api.ts +183 -0
- package/src/api/probe-delivery-subscription.application.api.ts +186 -0
- 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.application.api.test.ts +18 -18
- package/src/api/probe-webhook.application.api.ts +10 -23
- package/src/constants/index.ts +1 -1
- package/src/index.ts +73 -16
- package/src/types/enum/api-error.enum.ts +2 -0
- package/src/types/enum/index.ts +2 -2
- package/src/types/enum/probe-scan.enum.ts +3 -2
- package/src/types/index.ts +2 -2
- package/src/types/interface/api/index.ts +5 -5
- package/src/types/interface/api/requests/index.ts +1 -0
- package/src/types/interface/api/requests/probe-delivery-subscription.request.ts +42 -0
- 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 +9 -11
- package/src/types/interface/api/responses/index.ts +1 -0
- package/src/types/interface/api/responses/probe-delivery-subscription.response.ts +27 -0
- 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 +11 -14
- package/src/types/interface/models/probe-webhook.dto.ts +29 -29
- package/src/types/tests/probe.dto.test.ts +40 -4
- 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 +4 -3
- package/tsconfig.check.json +15 -15
- package/tsconfig.json +36 -36
- package/dist/api/probe-webhook.api.d.ts +0 -6
- package/dist/api/probe-webhook.api.js +0 -41
- package/dist/api/probe-webhook.api.js.map +0 -1
- package/dist/api/probe-webhook.api.test.d.ts +0 -1
- package/dist/api/probe-webhook.api.test.js +0 -43
- package/dist/api/probe-webhook.api.test.js.map +0 -1
- package/src/api/probe-webhook.api.test.ts +0 -17
- package/src/api/probe-webhook.api.ts +0 -119
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export interface BasePaginate<T> {
|
|
2
|
-
maxPages: number;
|
|
3
|
-
currentPage: number;
|
|
4
|
-
data: T[];
|
|
5
|
-
totalItems: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface QueryPaginate {
|
|
9
|
-
page?: number;
|
|
10
|
-
limit?: number;
|
|
11
|
-
}
|
|
1
|
+
export interface BasePaginate<T> {
|
|
2
|
+
maxPages: number;
|
|
3
|
+
currentPage: number;
|
|
4
|
+
data: T[];
|
|
5
|
+
totalItems: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface QueryPaginate {
|
|
9
|
+
page?: number;
|
|
10
|
+
limit?: number;
|
|
11
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IApiError } from './api-error';
|
|
2
|
-
|
|
3
|
-
export interface IResponse<T> {
|
|
4
|
-
data: T;
|
|
5
|
-
error?: IApiError | Error;
|
|
6
|
-
}
|
|
1
|
+
import { IApiError } from './api-error';
|
|
2
|
+
|
|
3
|
+
export interface IResponse<T> {
|
|
4
|
+
data: T;
|
|
5
|
+
error?: IApiError | Error;
|
|
6
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './models';
|
|
2
|
-
export * from './api';
|
|
1
|
+
export * from './models';
|
|
2
|
+
export * from './api';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './probe-scan.dto';
|
|
2
|
-
export * from './probe-webhook.dto';
|
|
3
|
-
export * from './probe-webhook-delivery.dto';
|
|
1
|
+
export * from './probe-scan.dto';
|
|
2
|
+
export * from './probe-webhook.dto';
|
|
3
|
+
export * from './probe-webhook-delivery.dto';
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import { ProbeScanMode, ProbeScanStatus, ProbeScanVerdict } from '../../enum';
|
|
2
|
-
|
|
3
|
-
// Mirrors apps/api/src/api/controllers/probe-scan.controller.ts's local
|
|
4
|
-
// response interfaces. AbyssProbe deliberately returns TWO different scan
|
|
5
|
-
// shapes depending on the endpoint — never the raw `probe_scans` row, and
|
|
6
|
-
// never a single one-size-fits-all model — so this file mirrors that with
|
|
7
|
-
// two distinct interfaces rather than forcing one canonical "IProbeScan".
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* `GET /scan/:scanId` shape (poll the queued -> scanning -> done/error
|
|
11
|
-
* progression). WS5-4 (AbyssProbe UX rework) widened this to full metadata
|
|
12
|
-
* parity with {@link IProbeScanHistoryItem} (fileName/fileSize/mimeType/
|
|
13
|
-
* mode/startedAt/finishedAt/costUnits) — the scanner UI's "Détails" section
|
|
14
|
-
* needs the same info whether it got there via the list or via a direct
|
|
15
|
-
* poll — still never echoing internal ownership columns (userId,
|
|
16
|
-
* organizationId, callbackUrl) — a caller polling by id already knows what
|
|
17
|
-
* it submitted.
|
|
18
|
-
*/
|
|
19
|
-
export interface IProbeScanDetail {
|
|
20
|
-
scanId: string;
|
|
21
|
-
status: ProbeScanStatus;
|
|
22
|
-
/** null until `status` is DONE. */
|
|
23
|
-
verdict: ProbeScanVerdict | null;
|
|
24
|
-
/** null until `status` is DONE; [] when DONE and clean. */
|
|
25
|
-
viruses: string[] | null;
|
|
26
|
-
/** Free-form caller reference echoed back verbatim (see IProbeScanHistoryItem#context). */
|
|
27
|
-
context: Record<string, unknown> | null;
|
|
28
|
-
fileName: string;
|
|
29
|
-
fileSize: number;
|
|
30
|
-
mimeType: string;
|
|
31
|
-
mode: ProbeScanMode;
|
|
32
|
-
/** Set the moment the engine call starts (SYNC: row-creation time; ASYNC: when a worker picks the job off the queue). */
|
|
33
|
-
startedAt: Date;
|
|
34
|
-
/** Set once the engine call returns. null while status is not DONE. */
|
|
35
|
-
finishedAt: Date | null;
|
|
36
|
-
/**
|
|
37
|
-
* `ACCOUNT_AV_SCAN_UNITS` this scan consumed (see `estimateProbeScanCost`
|
|
38
|
-
* — this package's own shared pure cost model). null until `status` is
|
|
39
|
-
* DONE; stays null forever for a scan that errors out (no verdict was ever
|
|
40
|
-
* reached, so nothing was ever billed).
|
|
41
|
-
*/
|
|
42
|
-
costUnits: number | null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* One row of `GET /scan`'s paginated history/search list. Never echoes
|
|
47
|
-
* internal ownership columns (userId, organizationId, callbackUrl) — a
|
|
48
|
-
* caller already knows their own scope from the request they made.
|
|
49
|
-
*/
|
|
50
|
-
export interface IProbeScanHistoryItem {
|
|
51
|
-
scanId: string;
|
|
52
|
-
fileName: string;
|
|
53
|
-
fileSize: number;
|
|
54
|
-
mimeType: string;
|
|
55
|
-
verdict: ProbeScanVerdict | null;
|
|
56
|
-
viruses: string[] | null;
|
|
57
|
-
mode: ProbeScanMode;
|
|
58
|
-
status: ProbeScanStatus;
|
|
59
|
-
context: Record<string, unknown> | null;
|
|
60
|
-
/** Set the moment the engine call starts (SYNC: row-creation time; ASYNC: when a worker picks the job off the queue). */
|
|
61
|
-
startedAt: Date;
|
|
62
|
-
/** Set once the engine call returns. null while status is not DONE. */
|
|
63
|
-
finishedAt: Date | null;
|
|
64
|
-
/** See {@link IProbeScanDetail#costUnits}. */
|
|
65
|
-
costUnits: number | null;
|
|
66
|
-
createdAt: Date;
|
|
67
|
-
}
|
|
1
|
+
import { ProbeScanMode, ProbeScanStatus, ProbeScanVerdict } from '../../enum';
|
|
2
|
+
|
|
3
|
+
// Mirrors apps/api/src/api/controllers/probe-scan.controller.ts's local
|
|
4
|
+
// response interfaces. AbyssProbe deliberately returns TWO different scan
|
|
5
|
+
// shapes depending on the endpoint — never the raw `probe_scans` row, and
|
|
6
|
+
// never a single one-size-fits-all model — so this file mirrors that with
|
|
7
|
+
// two distinct interfaces rather than forcing one canonical "IProbeScan".
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `GET /scan/:scanId` shape (poll the queued -> scanning -> done/error
|
|
11
|
+
* progression). WS5-4 (AbyssProbe UX rework) widened this to full metadata
|
|
12
|
+
* parity with {@link IProbeScanHistoryItem} (fileName/fileSize/mimeType/
|
|
13
|
+
* mode/startedAt/finishedAt/costUnits) — the scanner UI's "Détails" section
|
|
14
|
+
* needs the same info whether it got there via the list or via a direct
|
|
15
|
+
* poll — still never echoing internal ownership columns (userId,
|
|
16
|
+
* organizationId, callbackUrl) — a caller polling by id already knows what
|
|
17
|
+
* it submitted.
|
|
18
|
+
*/
|
|
19
|
+
export interface IProbeScanDetail {
|
|
20
|
+
scanId: string;
|
|
21
|
+
status: ProbeScanStatus;
|
|
22
|
+
/** null until `status` is DONE. */
|
|
23
|
+
verdict: ProbeScanVerdict | null;
|
|
24
|
+
/** null until `status` is DONE; [] when DONE and clean. */
|
|
25
|
+
viruses: string[] | null;
|
|
26
|
+
/** Free-form caller reference echoed back verbatim (see IProbeScanHistoryItem#context). */
|
|
27
|
+
context: Record<string, unknown> | null;
|
|
28
|
+
fileName: string;
|
|
29
|
+
fileSize: number;
|
|
30
|
+
mimeType: string;
|
|
31
|
+
mode: ProbeScanMode;
|
|
32
|
+
/** Set the moment the engine call starts (SYNC: row-creation time; ASYNC: when a worker picks the job off the queue). */
|
|
33
|
+
startedAt: Date;
|
|
34
|
+
/** Set once the engine call returns. null while status is not DONE. */
|
|
35
|
+
finishedAt: Date | null;
|
|
36
|
+
/**
|
|
37
|
+
* `ACCOUNT_AV_SCAN_UNITS` this scan consumed (see `estimateProbeScanCost`
|
|
38
|
+
* — this package's own shared pure cost model). null until `status` is
|
|
39
|
+
* DONE; stays null forever for a scan that errors out (no verdict was ever
|
|
40
|
+
* reached, so nothing was ever billed).
|
|
41
|
+
*/
|
|
42
|
+
costUnits: number | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* One row of `GET /scan`'s paginated history/search list. Never echoes
|
|
47
|
+
* internal ownership columns (userId, organizationId, callbackUrl) — a
|
|
48
|
+
* caller already knows their own scope from the request they made.
|
|
49
|
+
*/
|
|
50
|
+
export interface IProbeScanHistoryItem {
|
|
51
|
+
scanId: string;
|
|
52
|
+
fileName: string;
|
|
53
|
+
fileSize: number;
|
|
54
|
+
mimeType: string;
|
|
55
|
+
verdict: ProbeScanVerdict | null;
|
|
56
|
+
viruses: string[] | null;
|
|
57
|
+
mode: ProbeScanMode;
|
|
58
|
+
status: ProbeScanStatus;
|
|
59
|
+
context: Record<string, unknown> | null;
|
|
60
|
+
/** Set the moment the engine call starts (SYNC: row-creation time; ASYNC: when a worker picks the job off the queue). */
|
|
61
|
+
startedAt: Date;
|
|
62
|
+
/** Set once the engine call returns. null while status is not DONE. */
|
|
63
|
+
finishedAt: Date | null;
|
|
64
|
+
/** See {@link IProbeScanDetail#costUnits}. */
|
|
65
|
+
costUnits: number | null;
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { ProbeScanVerdict } from '../../enum';
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// scan reaches a verdict (`status: DONE`).
|
|
3
|
+
// What AbyssProbe announces once a scan reaches a verdict (`status: DONE`): the `data` of the
|
|
4
|
+
// `PROBE_SCAN_COMPLETED` event that Flow delivers to a client's delivery subscription (Flow's
|
|
5
|
+
// envelope `{ deliveryId, eventType, source, occurredAt, data }`), and the JSON body of the
|
|
6
|
+
// internal webhook AbyssStorage still receives until L2. Mirrors
|
|
7
|
+
// apps/api/src/services/probe-webhook-delivery.service.ts's ProbeWebhookPayload EXACTLY.
|
|
9
8
|
//
|
|
10
9
|
// `verdict` is typed as the concrete enum here (not `string` like the
|
|
11
10
|
// server's internal type) because delivery only ever happens on a DONE scan,
|
|
12
11
|
// where the verdict is always set — see dispatchProbeScanWebhooks's guard.
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
|
-
*
|
|
16
|
-
* `
|
|
14
|
+
* Payload of a finished scan. Flow signs the deliveries of a client's subscription (see
|
|
15
|
+
* `@abyss-project/flow`); the internal webhook is signed via HMAC-SHA256 of
|
|
16
|
+
* `JSON.stringify(payload)` — {@link PROBE_WEBHOOK_SIGNATURE_HEADER} and
|
|
17
17
|
* {@link verifyProbeWebhookSignature} (this package's root / utils).
|
|
18
18
|
*/
|
|
19
19
|
export interface IProbeWebhookDeliveryPayload {
|
|
@@ -49,12 +49,9 @@ export interface IProbeWebhookDeliveryPayload {
|
|
|
49
49
|
export interface IProbeWebhookDelivery {
|
|
50
50
|
id: string;
|
|
51
51
|
/**
|
|
52
|
-
* The registered webhook this delivery targeted.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* reachable via this webhook-scoped endpoint in practice (there is no
|
|
56
|
-
* webhookId to query it under), but the field stays nullable to mirror the
|
|
57
|
-
* server column's real type.
|
|
52
|
+
* The registered webhook this delivery targeted. Always set today (a scan's
|
|
53
|
+
* `callbackUrl` is delivered by Flow, not by this history); the field stays
|
|
54
|
+
* nullable to mirror the server column's real type.
|
|
58
55
|
*/
|
|
59
56
|
webhookId: string | null;
|
|
60
57
|
/** The scan whose verdict this delivery carried. */
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
// Mirrors apps/api/src/api/controllers/probe-webhook.controller.ts's local
|
|
2
|
-
// WebhookResponseData. Public shape of a registered `probe_webhooks` row —
|
|
3
|
-
// never echoes the internal ownership columns
|
|
4
|
-
// (userId/organizationId/applicationId), same discipline as the scan models.
|
|
5
|
-
//
|
|
6
|
-
// WS5-7 (AbyssProbe UX rework): `secret` is ALWAYS re-displayable now —
|
|
7
|
-
// returned on every read (GET /webhook list, and PATCH /webhook/:id), not
|
|
8
|
-
// just once on create. Mirrors how AbyssExtract's own webhook model
|
|
9
|
-
// (`IExtractionWebhookDelivery`'s sibling `ExtractionWebhook` — see
|
|
10
|
-
// apps/api/src/database/models/extraction-webhook.model.ts /
|
|
11
|
-
// extraction-webhook.controller.ts) has always exposed its
|
|
12
|
-
// `webhookSecret` column on every response, never a once-only reveal. This
|
|
13
|
-
// lets a consumer (e.g. abyss-storage's own webhook registration) read its
|
|
14
|
-
// secret back at any time instead of relying on a log-once bootstrap.
|
|
15
|
-
|
|
16
|
-
export interface IProbeWebhook {
|
|
17
|
-
id: string;
|
|
18
|
-
/** HTTPS endpoint the verdict is POSTed to. */
|
|
19
|
-
callbackUrl: string;
|
|
20
|
-
/**
|
|
21
|
-
* Server-generated HMAC-SHA256 signing secret. Re-displayable: returned on
|
|
22
|
-
* every read (list/create/update), not once-only — see this interface's
|
|
23
|
-
* own header note (WS5-7).
|
|
24
|
-
*/
|
|
25
|
-
secret: string;
|
|
26
|
-
/** Disabled webhooks are skipped by dispatch (soft-off, not deleted). */
|
|
27
|
-
active: boolean;
|
|
28
|
-
createdAt: Date;
|
|
29
|
-
}
|
|
1
|
+
// Mirrors apps/api/src/api/controllers/probe-webhook.controller.ts's local
|
|
2
|
+
// WebhookResponseData. Public shape of a registered `probe_webhooks` row —
|
|
3
|
+
// never echoes the internal ownership columns
|
|
4
|
+
// (userId/organizationId/applicationId), same discipline as the scan models.
|
|
5
|
+
//
|
|
6
|
+
// WS5-7 (AbyssProbe UX rework): `secret` is ALWAYS re-displayable now —
|
|
7
|
+
// returned on every read (GET /webhook list, and PATCH /webhook/:id), not
|
|
8
|
+
// just once on create. Mirrors how AbyssExtract's own webhook model
|
|
9
|
+
// (`IExtractionWebhookDelivery`'s sibling `ExtractionWebhook` — see
|
|
10
|
+
// apps/api/src/database/models/extraction-webhook.model.ts /
|
|
11
|
+
// extraction-webhook.controller.ts) has always exposed its
|
|
12
|
+
// `webhookSecret` column on every response, never a once-only reveal. This
|
|
13
|
+
// lets a consumer (e.g. abyss-storage's own webhook registration) read its
|
|
14
|
+
// secret back at any time instead of relying on a log-once bootstrap.
|
|
15
|
+
|
|
16
|
+
export interface IProbeWebhook {
|
|
17
|
+
id: string;
|
|
18
|
+
/** HTTPS endpoint the verdict is POSTed to. */
|
|
19
|
+
callbackUrl: string;
|
|
20
|
+
/**
|
|
21
|
+
* Server-generated HMAC-SHA256 signing secret. Re-displayable: returned on
|
|
22
|
+
* every read (list/create/update), not once-only — see this interface's
|
|
23
|
+
* own header note (WS5-7).
|
|
24
|
+
*/
|
|
25
|
+
secret: string;
|
|
26
|
+
/** Disabled webhooks are skipped by dispatch (soft-off, not deleted). */
|
|
27
|
+
active: boolean;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Type-level compile test for AbyssProbe's DTO/response shapes — asserts
|
|
2
2
|
// they match the server contract (probe-scan.controller.ts /
|
|
3
|
-
// probe-webhook.controller.ts / probe-usage.controller.ts /
|
|
3
|
+
// probe-webhook-application.controller.ts / probe-usage.controller.ts /
|
|
4
4
|
// probe-webhook-delivery.service.ts) at compile time: any incompatible
|
|
5
5
|
// rename/removal on either side fails `npm run build` here. No jest runner
|
|
6
6
|
// in this SDK package; compile guard only (mirrors
|
|
@@ -19,6 +19,13 @@ import {
|
|
|
19
19
|
IScanAsyncData,
|
|
20
20
|
IUpdateProbeWebhookBody,
|
|
21
21
|
IProbeUsageData,
|
|
22
|
+
ICreateProbeDeliverySubscriptionBody,
|
|
23
|
+
IUpdateProbeDeliverySubscriptionBody,
|
|
24
|
+
IPaginateProbeDeliveryQuery,
|
|
25
|
+
IPaginateProbeDeliverySubscriptionQuery,
|
|
26
|
+
ICreateProbeDeliverySubscriptionResponse,
|
|
27
|
+
IGetProbeDeliverySubscriptionResponse,
|
|
28
|
+
Code,
|
|
22
29
|
} from '..';
|
|
23
30
|
// estimateProbeScanCost lives in src/utils/ (a SIBLING of src/types/, not
|
|
24
31
|
// re-exported by the types barrel this file otherwise imports from) — see
|
|
@@ -92,7 +99,7 @@ const _webhook: IProbeWebhook = {
|
|
|
92
99
|
createdAt: new Date(),
|
|
93
100
|
};
|
|
94
101
|
|
|
95
|
-
// PATCH /webhook/:webhookId body (WS5-5) — every field optional (at least one required server-side).
|
|
102
|
+
// PATCH /application/:applicationId/webhook/:webhookId body (WS5-5) — every field optional (at least one required server-side).
|
|
96
103
|
const _updateBody: IUpdateProbeWebhookBody = { active: false };
|
|
97
104
|
const _updateBody2: IUpdateProbeWebhookBody = { callbackUrl: 'https://example.com/hook2' };
|
|
98
105
|
|
|
@@ -106,7 +113,7 @@ const _deliveryPayload: IProbeWebhookDeliveryPayload = {
|
|
|
106
113
|
costUnits: 5,
|
|
107
114
|
};
|
|
108
115
|
|
|
109
|
-
// GET /webhook/:webhookId/deliveries row (WS5-6) — a persisted delivery-attempt.
|
|
116
|
+
// GET /application/:applicationId/webhook/:webhookId/deliveries row (WS5-6) — a persisted delivery-attempt.
|
|
110
117
|
const _deliveryRecord: IProbeWebhookDelivery = {
|
|
111
118
|
id: 'd1',
|
|
112
119
|
webhookId: 'w1',
|
|
@@ -118,9 +125,31 @@ const _deliveryRecord: IProbeWebhookDelivery = {
|
|
|
118
125
|
error: null,
|
|
119
126
|
createdAt: new Date(),
|
|
120
127
|
};
|
|
121
|
-
// webhookId
|
|
128
|
+
// webhookId stays nullable: it mirrors the column's real type.
|
|
122
129
|
const _deliveryRecordAdHoc: IProbeWebhookDelivery = { ..._deliveryRecord, webhookId: null };
|
|
123
130
|
|
|
131
|
+
// Delivery subscriptions (P5 #792) — the client's subscriptions live in Flow; the body names the
|
|
132
|
+
// one event and the URL, the scope is the caller (or `organizationId`, or the application).
|
|
133
|
+
const _createSubscription: ICreateProbeDeliverySubscriptionBody = {
|
|
134
|
+
eventTypes: ['PROBE_SCAN_COMPLETED'],
|
|
135
|
+
url: 'https://example.com/hook',
|
|
136
|
+
};
|
|
137
|
+
const _updateSubscription: IUpdateProbeDeliverySubscriptionBody = { isEnabled: false };
|
|
138
|
+
const _subscriptionQuery: IPaginateProbeDeliverySubscriptionQuery = {
|
|
139
|
+
organizationId: 'o1',
|
|
140
|
+
isEnabled: true,
|
|
141
|
+
page: 1,
|
|
142
|
+
limit: 20,
|
|
143
|
+
};
|
|
144
|
+
const _deliveryQuery: IPaginateProbeDeliveryQuery = { organizationId: 'o1', page: 2 };
|
|
145
|
+
// The secret is on the creation answer only.
|
|
146
|
+
declare const created: ICreateProbeDeliverySubscriptionResponse;
|
|
147
|
+
declare const read: IGetProbeDeliverySubscriptionResponse;
|
|
148
|
+
const _secret: string = created.data.secret;
|
|
149
|
+
// @ts-expect-error a read never carries the secret
|
|
150
|
+
const _noSecret: string = read.data.secret;
|
|
151
|
+
const _callbackCode: Code = Code.probeCallbackRequiresSubscription;
|
|
152
|
+
|
|
124
153
|
// GET /usage data shape (WS5-3).
|
|
125
154
|
const _usage: IProbeUsageData = { used: 10, limit: 1000, remaining: 990 };
|
|
126
155
|
// -1 is the established "unlimited" sentinel (see estimateProbeScanCost's
|
|
@@ -145,6 +174,13 @@ void _historyItem;
|
|
|
145
174
|
void _scanSyncData;
|
|
146
175
|
void _scanAsyncData;
|
|
147
176
|
void _webhook;
|
|
177
|
+
void _createSubscription;
|
|
178
|
+
void _updateSubscription;
|
|
179
|
+
void _subscriptionQuery;
|
|
180
|
+
void _deliveryQuery;
|
|
181
|
+
void _secret;
|
|
182
|
+
void _noSecret;
|
|
183
|
+
void _callbackCode;
|
|
148
184
|
void _updateBody;
|
|
149
185
|
void _updateBody2;
|
|
150
186
|
void _deliveryPayload;
|
package/src/utils/enum.utils.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export type ValueOf<T> = T[keyof T];
|
|
1
|
+
export type ValueOf<T> = T[keyof T];
|
package/src/utils/error.utils.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import { Code, ErrorType } from '../types';
|
|
2
|
-
|
|
3
|
-
type ErrorParams = { code: Code; type: ErrorType; message?: string };
|
|
4
|
-
|
|
5
|
-
export class ServiceException extends Error {
|
|
6
|
-
private readonly code: Code;
|
|
7
|
-
|
|
8
|
-
private readonly type: ErrorType;
|
|
9
|
-
|
|
10
|
-
getCode(): Code {
|
|
11
|
-
return this.code;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
getType(): ErrorType {
|
|
15
|
-
return this.type;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(params: ErrorParams) {
|
|
19
|
-
super(params.message);
|
|
20
|
-
this.code = params.code;
|
|
21
|
-
this.type = params.type;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const handleError = (error: Error | ErrorParams, _params?: ErrorParams): Error => {
|
|
26
|
-
if (error instanceof Error) {
|
|
27
|
-
return error;
|
|
28
|
-
}
|
|
29
|
-
return new ServiceException(error);
|
|
30
|
-
};
|
|
1
|
+
import { Code, ErrorType } from '../types';
|
|
2
|
+
|
|
3
|
+
type ErrorParams = { code: Code; type: ErrorType; message?: string };
|
|
4
|
+
|
|
5
|
+
export class ServiceException extends Error {
|
|
6
|
+
private readonly code: Code;
|
|
7
|
+
|
|
8
|
+
private readonly type: ErrorType;
|
|
9
|
+
|
|
10
|
+
getCode(): Code {
|
|
11
|
+
return this.code;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getType(): ErrorType {
|
|
15
|
+
return this.type;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(params: ErrorParams) {
|
|
19
|
+
super(params.message);
|
|
20
|
+
this.code = params.code;
|
|
21
|
+
this.type = params.type;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const handleError = (error: Error | ErrorParams, _params?: ErrorParams): Error => {
|
|
26
|
+
if (error instanceof Error) {
|
|
27
|
+
return error;
|
|
28
|
+
}
|
|
29
|
+
return new ServiceException(error);
|
|
30
|
+
};
|
package/src/utils/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './error.utils';
|
|
2
|
-
export * from './enum.utils';
|
|
3
|
-
export * from './probe-webhook-signature.utils';
|
|
4
|
-
export * from './probe-scan-cost.utils';
|
|
1
|
+
export * from './error.utils';
|
|
2
|
+
export * from './enum.utils';
|
|
3
|
+
export * from './probe-webhook-signature.utils';
|
|
4
|
+
export * from './probe-scan-cost.utils';
|