@abyss-project/tools 2.1.0 → 2.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/dist/api/index.d.ts +4 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/probe-scan.api.d.ts +15 -0
- package/dist/api/probe-scan.api.js +74 -0
- package/dist/api/probe-scan.api.js.map +1 -0
- package/dist/api/probe-scan.api.test.d.ts +1 -0
- package/dist/api/probe-scan.api.test.js +37 -0
- package/dist/api/probe-scan.api.test.js.map +1 -0
- package/dist/api/probe-scan.application.api.d.ts +7 -0
- package/dist/api/probe-scan.application.api.js +40 -0
- package/dist/api/probe-scan.application.api.js.map +1 -0
- package/dist/api/probe-scan.application.api.test.d.ts +1 -0
- package/dist/api/probe-scan.application.api.test.js +37 -0
- package/dist/api/probe-scan.application.api.test.js.map +1 -0
- package/dist/api/probe-webhook.api.d.ts +4 -0
- package/dist/api/probe-webhook.api.js +34 -0
- package/dist/api/probe-webhook.api.js.map +1 -0
- package/dist/api/probe-webhook.api.test.d.ts +1 -0
- package/dist/api/probe-webhook.api.test.js +33 -0
- package/dist/api/probe-webhook.api.test.js.map +1 -0
- package/dist/api/probe-webhook.application.api.d.ts +4 -0
- package/dist/api/probe-webhook.application.api.js +14 -0
- package/dist/api/probe-webhook.application.api.js.map +1 -0
- package/dist/api/probe-webhook.application.api.test.d.ts +1 -0
- package/dist/api/probe-webhook.application.api.test.js +33 -0
- package/dist/api/probe-webhook.application.api.test.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +32 -1
- package/dist/index.js.map +1 -1
- package/dist/types/enum/api-error.enum.d.ts +1 -5
- package/dist/types/enum/api-error.enum.js +0 -4
- package/dist/types/enum/api-error.enum.js.map +1 -1
- package/dist/types/enum/index.d.ts +1 -1
- package/dist/types/enum/index.js +1 -1
- package/dist/types/enum/index.js.map +1 -1
- package/dist/types/enum/probe-scan.enum.d.ts +14 -0
- package/dist/types/enum/probe-scan.enum.js +21 -0
- package/dist/types/enum/probe-scan.enum.js.map +1 -0
- package/dist/types/interface/api/requests/index.d.ts +2 -0
- package/dist/types/interface/api/requests/index.js +2 -0
- package/dist/types/interface/api/requests/index.js.map +1 -1
- package/dist/types/interface/api/requests/probe-scan.request.d.ts +22 -0
- package/dist/types/interface/api/{responses/file-scan.response.js → requests/probe-scan.request.js} +1 -1
- package/dist/types/interface/api/requests/probe-scan.request.js.map +1 -0
- package/dist/types/interface/api/requests/probe-webhook.request.d.ts +6 -0
- package/dist/types/{enum/file-scan-status.enum.js → interface/api/requests/probe-webhook.request.js} +1 -1
- package/dist/types/interface/api/requests/probe-webhook.request.js.map +1 -0
- package/dist/types/interface/api/responses/beam.response.d.ts +1 -3
- package/dist/types/interface/api/responses/index.d.ts +2 -0
- package/dist/types/interface/api/responses/index.js +2 -0
- package/dist/types/interface/api/responses/index.js.map +1 -1
- package/dist/types/interface/api/responses/probe-scan.response.d.ts +18 -0
- package/dist/types/interface/api/responses/probe-scan.response.js +3 -0
- package/dist/types/interface/api/responses/probe-scan.response.js.map +1 -0
- package/dist/types/interface/api/responses/probe-webhook.response.d.ts +10 -0
- package/dist/types/interface/api/responses/probe-webhook.response.js +3 -0
- package/dist/types/interface/api/responses/probe-webhook.response.js.map +1 -0
- package/dist/types/interface/models/atlas-document.dto.d.ts +0 -3
- package/dist/types/interface/models/beam.dto.d.ts +0 -3
- package/dist/types/interface/models/board-card-document.dto.d.ts +0 -3
- package/dist/types/interface/models/extraction.dto.d.ts +0 -2
- package/dist/types/interface/models/extraction.dto.js.map +1 -1
- package/dist/types/interface/models/index.d.ts +3 -0
- package/dist/types/interface/models/index.js +3 -0
- package/dist/types/interface/models/index.js.map +1 -1
- package/dist/types/interface/models/probe-scan.dto.d.ts +22 -0
- package/dist/types/interface/models/{file-scan.dto.js → probe-scan.dto.js} +1 -1
- package/dist/types/interface/models/probe-scan.dto.js.map +1 -0
- package/dist/types/interface/models/probe-webhook-delivery.dto.d.ts +7 -0
- package/dist/types/interface/models/probe-webhook-delivery.dto.js +3 -0
- package/dist/types/interface/models/probe-webhook-delivery.dto.js.map +1 -0
- package/dist/types/interface/models/probe-webhook.dto.d.ts +9 -0
- package/dist/types/interface/{api/requests/file-scan.request.js → models/probe-webhook.dto.js} +1 -1
- package/dist/types/interface/models/probe-webhook.dto.js.map +1 -0
- package/dist/types/tests/probe.dto.test.d.ts +1 -0
- package/dist/types/tests/probe.dto.test.js +62 -0
- package/dist/types/tests/probe.dto.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/probe-webhook-signature.utils.d.ts +8 -0
- package/dist/utils/probe-webhook-signature.utils.js +22 -0
- package/dist/utils/probe-webhook-signature.utils.js.map +1 -0
- package/package.json +1 -1
- package/src/api/index.ts +6 -0
- package/src/api/probe-scan.api.test.ts +21 -0
- package/src/api/probe-scan.api.ts +191 -0
- package/src/api/probe-scan.application.api.test.ts +21 -0
- package/src/api/probe-scan.application.api.ts +157 -0
- package/src/api/probe-webhook.api.test.ts +17 -0
- package/src/api/probe-webhook.api.ts +81 -0
- package/src/api/probe-webhook.application.api.test.ts +18 -0
- package/src/api/probe-webhook.application.api.ts +87 -0
- package/src/index.ts +86 -0
- package/src/types/enum/api-error.enum.ts +0 -25
- package/src/types/enum/index.ts +1 -1
- package/src/types/enum/probe-scan.enum.ts +44 -0
- package/src/types/interface/api/requests/index.ts +2 -0
- package/src/types/interface/api/requests/probe-scan.request.ts +50 -0
- package/src/types/interface/api/requests/probe-webhook.request.ts +12 -0
- package/src/types/interface/api/responses/beam.response.ts +1 -15
- package/src/types/interface/api/responses/index.ts +2 -0
- package/src/types/interface/api/responses/probe-scan.response.ts +38 -0
- package/src/types/interface/api/responses/probe-webhook.response.ts +17 -0
- package/src/types/interface/models/atlas-document.dto.ts +0 -18
- package/src/types/interface/models/beam.dto.ts +0 -22
- package/src/types/interface/models/board-card-document.dto.ts +0 -18
- package/src/types/interface/models/extraction.dto.ts +0 -17
- package/src/types/interface/models/index.ts +3 -0
- package/src/types/interface/models/probe-scan.dto.ts +48 -0
- package/src/types/interface/models/probe-webhook-delivery.dto.ts +26 -0
- package/src/types/interface/models/probe-webhook.dto.ts +25 -0
- package/src/types/tests/beam.dto.spec.ts +0 -2
- package/src/types/tests/probe.dto.test.ts +97 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/probe-webhook-signature.utils.ts +56 -0
- package/dist/api/file-scan.api.d.ts +0 -5
- package/dist/api/file-scan.api.js +0 -49
- package/dist/api/file-scan.api.js.map +0 -1
- package/dist/types/enum/analysis-status.enum.d.ts +0 -7
- package/dist/types/enum/analysis-status.enum.js +0 -12
- package/dist/types/enum/analysis-status.enum.js.map +0 -1
- package/dist/types/enum/file-scan-status.enum.d.ts +0 -1
- package/dist/types/enum/file-scan-status.enum.js.map +0 -1
- package/dist/types/interface/api/requests/file-scan.request.d.ts +0 -3
- package/dist/types/interface/api/requests/file-scan.request.js.map +0 -1
- package/dist/types/interface/api/responses/file-scan.response.d.ts +0 -7
- package/dist/types/interface/api/responses/file-scan.response.js.map +0 -1
- package/dist/types/interface/models/file-scan.dto.d.ts +0 -11
- package/dist/types/interface/models/file-scan.dto.js.map +0 -1
- package/src/types/enum/file-scan-status.enum.ts +0 -23
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe scan API — POST /scan (sync + async), GET /scan/:scanId (poll),
|
|
3
|
+
// GET /scan (history/search). Mirrors
|
|
4
|
+
// apps/api/src/api/controllers/probe-scan.controller.ts EXACTLY (see that
|
|
5
|
+
// file for the full contract this client targets). AbyssProbe's controllers
|
|
6
|
+
// add no extra path segment (`@Controller({ prefixPath: '/scan' })`), so
|
|
7
|
+
// these calls hit `scan`/`scan/:id` directly — no `probe/` prefix.
|
|
8
|
+
//
|
|
9
|
+
// File-upload dual environment handling (browser `FormData`/`Blob` vs Node
|
|
10
|
+
// `Buffer`/stream + the `form-data` package) mirrors this package's own
|
|
11
|
+
// extraction.api.ts (`detect`/`postExtract`): AbyssProbe is meant to be
|
|
12
|
+
// called from the abyss-main UI (a browser) as well as from Node services
|
|
13
|
+
// (abyss-storage, external integrators). `form-data` is lazy-`require`d
|
|
14
|
+
// (never statically imported) so a browser bundle never tries to resolve
|
|
15
|
+
// the Node-only package.
|
|
16
|
+
//
|
|
17
|
+
// `authHeader`/`serializeProbeQuery` are kept LOCAL and unexported (not a
|
|
18
|
+
// shared utils file) — same convention as every other extract/*.api.ts file
|
|
19
|
+
// in this package (each redefines its own tiny per-call apiKey helper; see
|
|
20
|
+
// extraction.api.ts / extraction-settings.api.ts / extraction-plan-preset.api.ts).
|
|
21
|
+
//
|
|
22
|
+
// See probe-scan.application.api.ts for the application/API-key-auth
|
|
23
|
+
// counterpart of this client (`/application/:applicationId/scan...`, Phase
|
|
24
|
+
// 3a) — it reuses this file's `buildScanForm` and every request/response
|
|
25
|
+
// type verbatim; only the URL prefix, the extra `applicationId` argument,
|
|
26
|
+
// and the auth header differ.
|
|
27
|
+
// ──────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
import { AbyssToolsCore } from '..';
|
|
30
|
+
import { ProbeScanMode } from '../types';
|
|
31
|
+
import type {
|
|
32
|
+
IScanOptions,
|
|
33
|
+
IListScansQuery,
|
|
34
|
+
IScanResponse,
|
|
35
|
+
IScanSyncResponse,
|
|
36
|
+
IScanAsyncResponse,
|
|
37
|
+
IGetScanResponse,
|
|
38
|
+
IPaginateScanResponse,
|
|
39
|
+
} from '../types';
|
|
40
|
+
|
|
41
|
+
const DEFAULT_API_KEY_HEADER = 'abyss-api-key';
|
|
42
|
+
|
|
43
|
+
function authHeader(apiKey?: string): Record<string, string> {
|
|
44
|
+
return apiKey ? { [DEFAULT_API_KEY_HEADER]: apiKey } : {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Turn a request/query options object into axios `params`: drops
|
|
49
|
+
* undefined/null, ISO-stringifies `Date`s, and renames `organizationId` to
|
|
50
|
+
* the wire's `organization_id` (the one snake_case key AbyssProbe's own
|
|
51
|
+
* controllers actually expect — see probe-scope.helper.ts#readOrganizationId
|
|
52
|
+
* — every other field name is already camelCase on both sides).
|
|
53
|
+
*/
|
|
54
|
+
function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
|
|
55
|
+
const out: Record<string, unknown> = {};
|
|
56
|
+
for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
|
|
57
|
+
if (value === undefined || value === null) continue;
|
|
58
|
+
const wireKey = key === 'organizationId' ? 'organization_id' : key;
|
|
59
|
+
out[wireKey] = value instanceof Date ? value.toISOString() : value;
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Anything `sdk.probe.scan` accepts as the file to submit. */
|
|
65
|
+
export type ProbeScanFileInput = Buffer | Uint8Array | NodeJS.ReadableStream | Blob;
|
|
66
|
+
|
|
67
|
+
function isBrowserEnv(): boolean {
|
|
68
|
+
return typeof window !== 'undefined' && typeof FormData !== 'undefined';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function loadNodeFormData(): Promise<any> {
|
|
72
|
+
// Indirect eval so bundlers (esbuild/vite/webpack) do not try to resolve
|
|
73
|
+
// the Node-only "form-data" package when this file is included in a
|
|
74
|
+
// browser bundle. The require only ever runs at runtime on Node.
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func
|
|
76
|
+
const nodeRequire: NodeRequire = new Function('return require')();
|
|
77
|
+
return nodeRequire('form-data');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface BuiltScanForm {
|
|
81
|
+
form: unknown;
|
|
82
|
+
headers: Record<string, string>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Exported (not just this file's own `scan` internals) so
|
|
87
|
+
* probe-scan.application.api.ts reuses this EXACT multipart-building logic
|
|
88
|
+
* (browser `FormData`/`Blob` vs Node `Buffer`/stream + lazy-required
|
|
89
|
+
* `form-data`) rather than duplicating it — the file-upload contract is
|
|
90
|
+
* identical for a personal/org caller and an application caller; only the
|
|
91
|
+
* URL/auth differ (see that file's header comment).
|
|
92
|
+
*/
|
|
93
|
+
export async function buildScanForm(
|
|
94
|
+
file: ProbeScanFileInput,
|
|
95
|
+
options: IScanOptions,
|
|
96
|
+
): Promise<BuiltScanForm> {
|
|
97
|
+
const filename = options.filename ?? 'file';
|
|
98
|
+
|
|
99
|
+
if (isBrowserEnv()) {
|
|
100
|
+
const form = new FormData();
|
|
101
|
+
const blob =
|
|
102
|
+
file instanceof Blob ? file : new Blob([file as BlobPart], { type: options.mimeType });
|
|
103
|
+
form.append('file', blob, filename);
|
|
104
|
+
if (options.context) form.append('context', JSON.stringify(options.context));
|
|
105
|
+
if (options.callbackUrl) form.append('callbackUrl', options.callbackUrl);
|
|
106
|
+
return { form, headers: {} };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const FormDataCtor = await loadNodeFormData();
|
|
110
|
+
const form = new FormDataCtor();
|
|
111
|
+
const filePart =
|
|
112
|
+
Buffer.isBuffer(file) || file instanceof Uint8Array ? Buffer.from(file as Uint8Array) : file;
|
|
113
|
+
form.append('file', filePart, { filename, contentType: options.mimeType });
|
|
114
|
+
if (options.context) form.append('context', JSON.stringify(options.context));
|
|
115
|
+
if (options.callbackUrl) form.append('callbackUrl', options.callbackUrl);
|
|
116
|
+
const headers = typeof form.getHeaders === 'function' ? form.getHeaders() : {};
|
|
117
|
+
return { form, headers };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* `POST /scan` — SYNC by default, ASYNC when `options.mode = ProbeScanMode.ASYNC`
|
|
122
|
+
* (same endpoint, query-param-selected — see the controller's doc comment).
|
|
123
|
+
* `mode` and `organizationId` travel as query params; `context`
|
|
124
|
+
* (JSON-encoded) and `callbackUrl` travel as multipart text fields alongside
|
|
125
|
+
* the file.
|
|
126
|
+
*
|
|
127
|
+
* Returns the SYNC (200, verdict inline) or ASYNC (202, `{ scanId, status:
|
|
128
|
+
* 'queued' }`) shape depending on `options.mode` — see {@link IScanResponse}.
|
|
129
|
+
* Prefer {@link scanSync} / {@link scanAsync} for a precisely-typed return
|
|
130
|
+
* instead of the union.
|
|
131
|
+
*/
|
|
132
|
+
export const scan = async (
|
|
133
|
+
file: ProbeScanFileInput,
|
|
134
|
+
options: IScanOptions = {},
|
|
135
|
+
apiKey?: string,
|
|
136
|
+
): Promise<IScanResponse> => {
|
|
137
|
+
const { form, headers } = await buildScanForm(file, options);
|
|
138
|
+
return (
|
|
139
|
+
await AbyssToolsCore.axios.post<IScanResponse>('scan', form, {
|
|
140
|
+
params: serializeProbeQuery({ mode: options.mode, organizationId: options.organizationId }),
|
|
141
|
+
headers: { ...headers, ...authHeader(apiKey) },
|
|
142
|
+
maxBodyLength: Infinity,
|
|
143
|
+
maxContentLength: Infinity,
|
|
144
|
+
})
|
|
145
|
+
).data;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/** {@link scan}, forced to `mode: sync` — HTTP 200, verdict returned inline. */
|
|
149
|
+
export const scanSync = async (
|
|
150
|
+
file: ProbeScanFileInput,
|
|
151
|
+
options: Omit<IScanOptions, 'mode' | 'callbackUrl'> = {},
|
|
152
|
+
apiKey?: string,
|
|
153
|
+
): Promise<IScanSyncResponse> =>
|
|
154
|
+
scan(file, { ...options, mode: ProbeScanMode.SYNC }, apiKey) as Promise<IScanSyncResponse>;
|
|
155
|
+
|
|
156
|
+
/** {@link scan}, forced to `mode: async` — HTTP 202, job queued. */
|
|
157
|
+
export const scanAsync = async (
|
|
158
|
+
file: ProbeScanFileInput,
|
|
159
|
+
options: Omit<IScanOptions, 'mode'> = {},
|
|
160
|
+
apiKey?: string,
|
|
161
|
+
): Promise<IScanAsyncResponse> =>
|
|
162
|
+
scan(file, { ...options, mode: ProbeScanMode.ASYNC }, apiKey) as Promise<IScanAsyncResponse>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* `GET /scan/:scanId` — poll the queued -> scanning -> done/error
|
|
166
|
+
* progression of an ASYNC scan (also answers for a SYNC scan's row). Cross-
|
|
167
|
+
* tenant guarded server-side (404, never 403) — needs no scope query param,
|
|
168
|
+
* the scanId alone determines it.
|
|
169
|
+
*/
|
|
170
|
+
export const getScan = async (scanId: string, apiKey?: string): Promise<IGetScanResponse> =>
|
|
171
|
+
(
|
|
172
|
+
await AbyssToolsCore.axios.get<IGetScanResponse>(`scan/${scanId}`, {
|
|
173
|
+
headers: authHeader(apiKey),
|
|
174
|
+
})
|
|
175
|
+
).data;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* `GET /scan` — paginated scan history/search for the caller's scope
|
|
179
|
+
* (personal by default, `organizationId` for an organization scope), newest
|
|
180
|
+
* first. See {@link IListScansQuery} for the available filters.
|
|
181
|
+
*/
|
|
182
|
+
export const listScans = async (
|
|
183
|
+
query: IListScansQuery = {},
|
|
184
|
+
apiKey?: string,
|
|
185
|
+
): Promise<IPaginateScanResponse> =>
|
|
186
|
+
(
|
|
187
|
+
await AbyssToolsCore.axios.get<IPaginateScanResponse>('scan', {
|
|
188
|
+
params: serializeProbeQuery(query),
|
|
189
|
+
headers: authHeader(apiKey),
|
|
190
|
+
})
|
|
191
|
+
).data;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Type-level compile test for the probe-scan APPLICATION api surface.
|
|
2
|
+
// No jest runner in this SDK package; compile guard only (mirrors
|
|
3
|
+
// probe-scan.api.test.ts).
|
|
4
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core), or `npm run build`.
|
|
5
|
+
|
|
6
|
+
import * as api from './probe-scan.application.api';
|
|
7
|
+
|
|
8
|
+
// All five functions must be exported with these exact signatures.
|
|
9
|
+
const _scan: typeof api.scanApplication = api.scanApplication;
|
|
10
|
+
const _scanSync: typeof api.scanSyncApplication = api.scanSyncApplication;
|
|
11
|
+
const _scanAsync: typeof api.scanAsyncApplication = api.scanAsyncApplication;
|
|
12
|
+
const _getScan: typeof api.getScanApplication = api.getScanApplication;
|
|
13
|
+
const _listScans: typeof api.listScansApplication = api.listScansApplication;
|
|
14
|
+
|
|
15
|
+
void _scan;
|
|
16
|
+
void _scanSync;
|
|
17
|
+
void _scanAsync;
|
|
18
|
+
void _getScan;
|
|
19
|
+
void _listScans;
|
|
20
|
+
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe APPLICATION scan API — POST /application/:applicationId/scan
|
|
3
|
+
// (sync + async), GET /application/:applicationId/scan/:scanId (poll),
|
|
4
|
+
// GET /application/:applicationId/scan (history/search). Mirrors
|
|
5
|
+
// apps/api/src/api/controllers/probe-scan-application.controller.ts EXACTLY
|
|
6
|
+
// (see that file for the full contract this client targets) — the
|
|
7
|
+
// application counterpart of probe-scan.api.ts, for inter-service callers
|
|
8
|
+
// (abyss-storage, external integrations) authenticating with a project API
|
|
9
|
+
// key instead of a personal/org session.
|
|
10
|
+
//
|
|
11
|
+
// Reuses probe-scan.api.ts's `buildScanForm` (same dual-environment
|
|
12
|
+
// multipart handling — browser `FormData`/`Blob` vs Node `Buffer`/stream +
|
|
13
|
+
// lazy-required `form-data`) and every request/response TYPE verbatim
|
|
14
|
+
// (`IScanOptions`, `IListScansQuery`, `IScanResponse`, `IScanSyncResponse`,
|
|
15
|
+
// `IScanAsyncResponse`, `IGetScanResponse`, `IPaginateScanResponse`) — never
|
|
16
|
+
// redefined here. `organizationId` is `Omit`'d from every option/query type
|
|
17
|
+
// below: unlike the personal/org route's `?organization_id=` override, an
|
|
18
|
+
// application caller's scope is entirely its `:applicationId` URL segment,
|
|
19
|
+
// resolved server-side by ProbeApplicationMiddleware (round-trips to
|
|
20
|
+
// abyss-main) — there is no scope query param to send.
|
|
21
|
+
//
|
|
22
|
+
// `authHeaderApplication` is kept LOCAL and unexported, same convention as
|
|
23
|
+
// the personal/org client's own `authHeader` (see probe-scan.api.ts's header
|
|
24
|
+
// comment) — it sends `API_KEY_APPLICATION_HEADER` (`abyss-api-key-
|
|
25
|
+
// application`, imported from this package's root) instead of the personal
|
|
26
|
+
// `abyss-api-key` header.
|
|
27
|
+
// ──────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
import { AbyssToolsCore, API_KEY_APPLICATION_HEADER } from '..';
|
|
30
|
+
import { ProbeScanMode } from '../types';
|
|
31
|
+
import type {
|
|
32
|
+
IScanOptions,
|
|
33
|
+
IListScansQuery,
|
|
34
|
+
IScanResponse,
|
|
35
|
+
IScanSyncResponse,
|
|
36
|
+
IScanAsyncResponse,
|
|
37
|
+
IGetScanResponse,
|
|
38
|
+
IPaginateScanResponse,
|
|
39
|
+
} from '../types';
|
|
40
|
+
import { buildScanForm } from './probe-scan.api';
|
|
41
|
+
import type { ProbeScanFileInput } from './probe-scan.api';
|
|
42
|
+
|
|
43
|
+
function authHeaderApplication(applicationApiKey?: string): Record<string, string> {
|
|
44
|
+
return applicationApiKey ? { [API_KEY_APPLICATION_HEADER]: applicationApiKey } : {};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Turn a request/query options object into axios `params`: drops
|
|
49
|
+
* undefined/null and ISO-stringifies `Date`s. No key-renaming here (unlike
|
|
50
|
+
* probe-scan.api.ts#serializeProbeQuery's `organizationId` -> `organization_id`
|
|
51
|
+
* rename) — an application call never carries `organizationId` (`Omit`'d
|
|
52
|
+
* from every option/query type in this file), so there is nothing to rename.
|
|
53
|
+
*/
|
|
54
|
+
function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
|
|
55
|
+
const out: Record<string, unknown> = {};
|
|
56
|
+
for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
|
|
57
|
+
if (value === undefined || value === null) continue;
|
|
58
|
+
out[key] = value instanceof Date ? value.toISOString() : value;
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* `POST /application/:applicationId/scan` — SYNC by default, ASYNC when
|
|
65
|
+
* `options.mode = ProbeScanMode.ASYNC` (identical contract to {@link
|
|
66
|
+
* ../probe-scan.api.scan | the personal/org `scan`} — see that function's
|
|
67
|
+
* doc comment for the full sequence). `mode` travels as a query param;
|
|
68
|
+
* `context` (JSON-encoded) and `callbackUrl` travel as multipart text fields
|
|
69
|
+
* alongside the file.
|
|
70
|
+
*
|
|
71
|
+
* Returns the SYNC (200, verdict inline) or ASYNC (202, `{ scanId, status:
|
|
72
|
+
* 'queued' }`) shape depending on `options.mode` — see {@link IScanResponse}.
|
|
73
|
+
* Prefer {@link scanSyncApplication} / {@link scanAsyncApplication} for a
|
|
74
|
+
* precisely-typed return instead of the union.
|
|
75
|
+
*/
|
|
76
|
+
export const scanApplication = async (
|
|
77
|
+
applicationId: string,
|
|
78
|
+
file: ProbeScanFileInput,
|
|
79
|
+
options: Omit<IScanOptions, 'organizationId'> = {},
|
|
80
|
+
applicationApiKey?: string,
|
|
81
|
+
): Promise<IScanResponse> => {
|
|
82
|
+
const { form, headers } = await buildScanForm(file, options);
|
|
83
|
+
return (
|
|
84
|
+
await AbyssToolsCore.axios.post<IScanResponse>(`application/${applicationId}/scan`, form, {
|
|
85
|
+
params: serializeProbeQuery({ mode: options.mode }),
|
|
86
|
+
headers: { ...headers, ...authHeaderApplication(applicationApiKey) },
|
|
87
|
+
maxBodyLength: Infinity,
|
|
88
|
+
maxContentLength: Infinity,
|
|
89
|
+
})
|
|
90
|
+
).data;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** {@link scanApplication}, forced to `mode: sync` — HTTP 200, verdict returned inline. */
|
|
94
|
+
export const scanSyncApplication = async (
|
|
95
|
+
applicationId: string,
|
|
96
|
+
file: ProbeScanFileInput,
|
|
97
|
+
options: Omit<IScanOptions, 'organizationId' | 'mode' | 'callbackUrl'> = {},
|
|
98
|
+
applicationApiKey?: string,
|
|
99
|
+
): Promise<IScanSyncResponse> =>
|
|
100
|
+
scanApplication(
|
|
101
|
+
applicationId,
|
|
102
|
+
file,
|
|
103
|
+
{ ...options, mode: ProbeScanMode.SYNC },
|
|
104
|
+
applicationApiKey,
|
|
105
|
+
) as Promise<IScanSyncResponse>;
|
|
106
|
+
|
|
107
|
+
/** {@link scanApplication}, forced to `mode: async` — HTTP 202, job queued. */
|
|
108
|
+
export const scanAsyncApplication = async (
|
|
109
|
+
applicationId: string,
|
|
110
|
+
file: ProbeScanFileInput,
|
|
111
|
+
options: Omit<IScanOptions, 'organizationId' | 'mode'> = {},
|
|
112
|
+
applicationApiKey?: string,
|
|
113
|
+
): Promise<IScanAsyncResponse> =>
|
|
114
|
+
scanApplication(
|
|
115
|
+
applicationId,
|
|
116
|
+
file,
|
|
117
|
+
{ ...options, mode: ProbeScanMode.ASYNC },
|
|
118
|
+
applicationApiKey,
|
|
119
|
+
) as Promise<IScanAsyncResponse>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* `GET /application/:applicationId/scan/:scanId` — poll the queued ->
|
|
123
|
+
* scanning -> done/error progression of an ASYNC scan (also answers for a
|
|
124
|
+
* SYNC scan's row). Cross-tenant guarded server-side by a direct
|
|
125
|
+
* `applicationId` column comparison (404, never 403) — needs no scope
|
|
126
|
+
* argument beyond `applicationId` itself, the scanId alone determines the
|
|
127
|
+
* rest.
|
|
128
|
+
*/
|
|
129
|
+
export const getScanApplication = async (
|
|
130
|
+
applicationId: string,
|
|
131
|
+
scanId: string,
|
|
132
|
+
applicationApiKey?: string,
|
|
133
|
+
): Promise<IGetScanResponse> =>
|
|
134
|
+
(
|
|
135
|
+
await AbyssToolsCore.axios.get<IGetScanResponse>(
|
|
136
|
+
`application/${applicationId}/scan/${scanId}`,
|
|
137
|
+
{ headers: authHeaderApplication(applicationApiKey) },
|
|
138
|
+
)
|
|
139
|
+
).data;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* `GET /application/:applicationId/scan` — paginated scan history/search for
|
|
143
|
+
* the calling application, newest first. Same filters as the personal/org
|
|
144
|
+
* `GET /scan` minus `organizationId` (see {@link IListScansQuery}) — the
|
|
145
|
+
* `:applicationId` URL segment is already the entire scope.
|
|
146
|
+
*/
|
|
147
|
+
export const listScansApplication = async (
|
|
148
|
+
applicationId: string,
|
|
149
|
+
query: Omit<IListScansQuery, 'organizationId'> = {},
|
|
150
|
+
applicationApiKey?: string,
|
|
151
|
+
): Promise<IPaginateScanResponse> =>
|
|
152
|
+
(
|
|
153
|
+
await AbyssToolsCore.axios.get<IPaginateScanResponse>(`application/${applicationId}/scan`, {
|
|
154
|
+
params: serializeProbeQuery(query),
|
|
155
|
+
headers: authHeaderApplication(applicationApiKey),
|
|
156
|
+
})
|
|
157
|
+
).data;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Type-level compile test for the probe-webhook api surface.
|
|
2
|
+
// No jest runner in this SDK package; compile guard only.
|
|
3
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core), or `npm run build`.
|
|
4
|
+
|
|
5
|
+
import * as api from './probe-webhook.api';
|
|
6
|
+
|
|
7
|
+
// All three functions must be exported — deliberately no update/reset-secret
|
|
8
|
+
// (see probe-webhook.controller.ts's header comment on the small CRUD surface).
|
|
9
|
+
const _create: typeof api.createProbeWebhook = api.createProbeWebhook;
|
|
10
|
+
const _list: typeof api.listProbeWebhook = api.listProbeWebhook;
|
|
11
|
+
const _delete: typeof api.deleteProbeWebhook = api.deleteProbeWebhook;
|
|
12
|
+
|
|
13
|
+
void _create;
|
|
14
|
+
void _list;
|
|
15
|
+
void _delete;
|
|
16
|
+
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe webhook subscription API — CRUD over registered `probe_webhooks`
|
|
3
|
+
// (create / list / delete only — no update, no reset-secret: mirrors
|
|
4
|
+
// apps/api/src/api/controllers/probe-webhook.controller.ts's deliberately
|
|
5
|
+
// small surface EXACTLY, see that file's header comment). No `probe/` path
|
|
6
|
+
// prefix — `@Controller({ prefixPath: '/webhook' })` mounts directly at
|
|
7
|
+
// `webhook`.
|
|
8
|
+
//
|
|
9
|
+
// See probe-webhook.application.api.ts for the application/API-key-auth
|
|
10
|
+
// counterpart of this client (`/application/:applicationId/webhook...`,
|
|
11
|
+
// Phase 3a) — it reuses every request/response type verbatim; only the URL
|
|
12
|
+
// prefix, the extra `applicationId` argument, and the auth header differ.
|
|
13
|
+
// ──────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
import { AbyssToolsCore } from '..';
|
|
16
|
+
import type {
|
|
17
|
+
ICreateProbeWebhookBody,
|
|
18
|
+
IProbeWebhookScopeQuery,
|
|
19
|
+
ICreateProbeWebhookResponse,
|
|
20
|
+
IListProbeWebhookResponse,
|
|
21
|
+
IDeleteProbeWebhookResponse,
|
|
22
|
+
} from '../types';
|
|
23
|
+
|
|
24
|
+
const DEFAULT_API_KEY_HEADER = 'abyss-api-key';
|
|
25
|
+
|
|
26
|
+
function authHeader(apiKey?: string): Record<string, string> {
|
|
27
|
+
return apiKey ? { [DEFAULT_API_KEY_HEADER]: apiKey } : {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Renames `organizationId` to the wire's `organization_id` (see probe-scan.api.ts). */
|
|
31
|
+
function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
|
|
32
|
+
const out: Record<string, unknown> = {};
|
|
33
|
+
for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
|
|
34
|
+
if (value === undefined || value === null) continue;
|
|
35
|
+
const wireKey = key === 'organizationId' ? 'organization_id' : key;
|
|
36
|
+
out[wireKey] = value instanceof Date ? value.toISOString() : value;
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* `POST /webhook` — register a callbackUrl for the caller's scope. The
|
|
43
|
+
* response's `secret` field (HMAC signing secret) is returned ONLY here —
|
|
44
|
+
* store it immediately, it cannot be re-revealed later.
|
|
45
|
+
*/
|
|
46
|
+
export const createProbeWebhook = async (
|
|
47
|
+
body: ICreateProbeWebhookBody,
|
|
48
|
+
scope: IProbeWebhookScopeQuery = {},
|
|
49
|
+
apiKey?: string,
|
|
50
|
+
): Promise<ICreateProbeWebhookResponse> =>
|
|
51
|
+
(
|
|
52
|
+
await AbyssToolsCore.axios.post<ICreateProbeWebhookResponse>('webhook', body, {
|
|
53
|
+
params: serializeProbeQuery(scope),
|
|
54
|
+
headers: authHeader(apiKey),
|
|
55
|
+
})
|
|
56
|
+
).data;
|
|
57
|
+
|
|
58
|
+
/** `GET /webhook` — flat, scope-filtered list (not paginated — bounded by WEBHOOK_MAX_PER_SCOPE server-side). */
|
|
59
|
+
export const listProbeWebhook = async (
|
|
60
|
+
scope: IProbeWebhookScopeQuery = {},
|
|
61
|
+
apiKey?: string,
|
|
62
|
+
): Promise<IListProbeWebhookResponse> =>
|
|
63
|
+
(
|
|
64
|
+
await AbyssToolsCore.axios.get<IListProbeWebhookResponse>('webhook', {
|
|
65
|
+
params: serializeProbeQuery(scope),
|
|
66
|
+
headers: authHeader(apiKey),
|
|
67
|
+
})
|
|
68
|
+
).data;
|
|
69
|
+
|
|
70
|
+
/** `DELETE /webhook/:webhookId`. */
|
|
71
|
+
export const deleteProbeWebhook = async (
|
|
72
|
+
webhookId: string,
|
|
73
|
+
scope: IProbeWebhookScopeQuery = {},
|
|
74
|
+
apiKey?: string,
|
|
75
|
+
): Promise<IDeleteProbeWebhookResponse> =>
|
|
76
|
+
(
|
|
77
|
+
await AbyssToolsCore.axios.delete<IDeleteProbeWebhookResponse>(`webhook/${webhookId}`, {
|
|
78
|
+
params: serializeProbeQuery(scope),
|
|
79
|
+
headers: authHeader(apiKey),
|
|
80
|
+
})
|
|
81
|
+
).data;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Type-level compile test for the probe-webhook APPLICATION api surface.
|
|
2
|
+
// No jest runner in this SDK package; compile guard only (mirrors
|
|
3
|
+
// probe-webhook.api.test.ts).
|
|
4
|
+
// Run: npx tsc --noEmit (from packages/abyss_tools_core), or `npm run build`.
|
|
5
|
+
|
|
6
|
+
import * as api from './probe-webhook.application.api';
|
|
7
|
+
|
|
8
|
+
// All three functions must be exported — deliberately no update/reset-secret
|
|
9
|
+
// (see probe-webhook.api.ts's header comment on the small CRUD surface).
|
|
10
|
+
const _create: typeof api.createProbeWebhookApplication = api.createProbeWebhookApplication;
|
|
11
|
+
const _list: typeof api.listProbeWebhookApplication = api.listProbeWebhookApplication;
|
|
12
|
+
const _delete: typeof api.deleteProbeWebhookApplication = api.deleteProbeWebhookApplication;
|
|
13
|
+
|
|
14
|
+
void _create;
|
|
15
|
+
void _list;
|
|
16
|
+
void _delete;
|
|
17
|
+
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// ──────────────────────────────────────────────
|
|
2
|
+
// AbyssProbe APPLICATION webhook subscription API — CRUD over registered
|
|
3
|
+
// `probe_webhooks` owned by a calling application (create / list / delete
|
|
4
|
+
// only — no update, no reset-secret: same deliberately small surface as the
|
|
5
|
+
// personal/org client, see probe-webhook.api.ts's header comment). Mirrors
|
|
6
|
+
// apps/api/src/api/controllers/probe-webhook-application.controller.ts
|
|
7
|
+
// EXACTLY — the application counterpart of probe-webhook.api.ts, for
|
|
8
|
+
// inter-service callers (abyss-storage, external integrations)
|
|
9
|
+
// authenticating with a project API key instead of a personal/org session.
|
|
10
|
+
//
|
|
11
|
+
// Reuses every request/response TYPE verbatim (`ICreateProbeWebhookBody`,
|
|
12
|
+
// `ICreateProbeWebhookResponse`, `IListProbeWebhookResponse`,
|
|
13
|
+
// `IDeleteProbeWebhookResponse`) — never redefined here. No scope
|
|
14
|
+
// argument/query on any of these calls (unlike the personal/org client's
|
|
15
|
+
// `IProbeWebhookScopeQuery`) — an application caller's scope is entirely its
|
|
16
|
+
// `:applicationId` URL segment, resolved server-side by
|
|
17
|
+
// ProbeApplicationMiddleware; there is nothing to select between.
|
|
18
|
+
//
|
|
19
|
+
// `authHeaderApplication` is kept LOCAL and unexported, same convention as
|
|
20
|
+
// the personal/org client's own `authHeader` — it sends
|
|
21
|
+
// `API_KEY_APPLICATION_HEADER` (`abyss-api-key-application`, imported from
|
|
22
|
+
// this package's root) instead of the personal `abyss-api-key` header.
|
|
23
|
+
// ──────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
import { AbyssToolsCore, API_KEY_APPLICATION_HEADER } from '..';
|
|
26
|
+
import type {
|
|
27
|
+
ICreateProbeWebhookBody,
|
|
28
|
+
ICreateProbeWebhookResponse,
|
|
29
|
+
IListProbeWebhookResponse,
|
|
30
|
+
IDeleteProbeWebhookResponse,
|
|
31
|
+
} from '../types';
|
|
32
|
+
|
|
33
|
+
function authHeaderApplication(applicationApiKey?: string): Record<string, string> {
|
|
34
|
+
return applicationApiKey ? { [API_KEY_APPLICATION_HEADER]: applicationApiKey } : {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `POST /application/:applicationId/webhook` — register a callbackUrl owned
|
|
39
|
+
* by the calling application. The response's `secret` field (HMAC signing
|
|
40
|
+
* secret) is returned ONLY here — store it immediately, it cannot be
|
|
41
|
+
* re-revealed later.
|
|
42
|
+
*/
|
|
43
|
+
export const createProbeWebhookApplication = async (
|
|
44
|
+
applicationId: string,
|
|
45
|
+
body: ICreateProbeWebhookBody,
|
|
46
|
+
applicationApiKey?: string,
|
|
47
|
+
): Promise<ICreateProbeWebhookResponse> =>
|
|
48
|
+
(
|
|
49
|
+
await AbyssToolsCore.axios.post<ICreateProbeWebhookResponse>(
|
|
50
|
+
`application/${applicationId}/webhook`,
|
|
51
|
+
body,
|
|
52
|
+
{ headers: authHeaderApplication(applicationApiKey) },
|
|
53
|
+
)
|
|
54
|
+
).data;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* `GET /application/:applicationId/webhook` — flat list of the calling
|
|
58
|
+
* application's own webhooks (not paginated — bounded by
|
|
59
|
+
* WEBHOOK_MAX_PER_SCOPE server-side).
|
|
60
|
+
*/
|
|
61
|
+
export const listProbeWebhookApplication = async (
|
|
62
|
+
applicationId: string,
|
|
63
|
+
applicationApiKey?: string,
|
|
64
|
+
): Promise<IListProbeWebhookResponse> =>
|
|
65
|
+
(
|
|
66
|
+
await AbyssToolsCore.axios.get<IListProbeWebhookResponse>(
|
|
67
|
+
`application/${applicationId}/webhook`,
|
|
68
|
+
{ headers: authHeaderApplication(applicationApiKey) },
|
|
69
|
+
)
|
|
70
|
+
).data;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `DELETE /application/:applicationId/webhook/:webhookId` — cross-tenant
|
|
74
|
+
* guarded server-side by a direct `applicationId` comparison (404, never
|
|
75
|
+
* 403).
|
|
76
|
+
*/
|
|
77
|
+
export const deleteProbeWebhookApplication = async (
|
|
78
|
+
applicationId: string,
|
|
79
|
+
webhookId: string,
|
|
80
|
+
applicationApiKey?: string,
|
|
81
|
+
): Promise<IDeleteProbeWebhookResponse> =>
|
|
82
|
+
(
|
|
83
|
+
await AbyssToolsCore.axios.delete<IDeleteProbeWebhookResponse>(
|
|
84
|
+
`application/${applicationId}/webhook/${webhookId}`,
|
|
85
|
+
{ headers: authHeaderApplication(applicationApiKey) },
|
|
86
|
+
)
|
|
87
|
+
).data;
|