@abyss-project/probe 1.0.0 → 2.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.
Files changed (145) hide show
  1. package/.eslintrc.js +32 -0
  2. package/.prettierrc +5 -0
  3. package/README.md +4 -14
  4. package/dist/api/index.d.ts +4 -0
  5. package/dist/api/index.js +4 -0
  6. package/dist/api/index.js.map +1 -1
  7. package/dist/api/probe-scan.api.d.ts +4 -6
  8. package/dist/api/probe-scan.api.js +34 -30
  9. package/dist/api/probe-scan.api.js.map +1 -1
  10. package/dist/api/probe-scan.api.test.js +27 -7
  11. package/dist/api/probe-scan.api.test.js.map +1 -1
  12. package/dist/api/probe-scan.application.api.d.ts +7 -0
  13. package/dist/api/probe-scan.application.api.js +40 -0
  14. package/dist/api/probe-scan.application.api.js.map +1 -0
  15. package/dist/api/probe-scan.application.api.test.d.ts +1 -0
  16. package/dist/api/probe-scan.application.api.test.js +51 -0
  17. package/dist/api/probe-scan.application.api.test.js.map +1 -0
  18. package/dist/api/probe-usage.api.d.ts +2 -0
  19. package/dist/api/probe-usage.api.js +24 -0
  20. package/dist/api/probe-usage.api.js.map +1 -0
  21. package/dist/api/probe-usage.application.api.d.ts +2 -0
  22. package/dist/api/probe-usage.application.api.js +12 -0
  23. package/dist/api/probe-usage.application.api.js.map +1 -0
  24. package/dist/api/probe-webhook.api.d.ts +3 -1
  25. package/dist/api/probe-webhook.api.js +28 -8
  26. package/dist/api/probe-webhook.api.js.map +1 -1
  27. package/dist/api/probe-webhook.api.test.js +17 -7
  28. package/dist/api/probe-webhook.api.test.js.map +1 -1
  29. package/dist/api/probe-webhook.application.api.d.ts +6 -0
  30. package/dist/api/probe-webhook.application.api.js +27 -0
  31. package/dist/api/probe-webhook.application.api.js.map +1 -0
  32. package/dist/api/probe-webhook.application.api.test.d.ts +1 -0
  33. package/dist/api/probe-webhook.application.api.test.js +43 -0
  34. package/dist/api/probe-webhook.application.api.test.js.map +1 -0
  35. package/dist/constants/index.d.ts +1 -0
  36. package/dist/{types/interface/models/probe-scan.model.js → constants/index.js} +1 -1
  37. package/dist/constants/index.js.map +1 -0
  38. package/dist/index.d.ts +42 -9
  39. package/dist/index.js +65 -20
  40. package/dist/index.js.map +1 -1
  41. package/dist/types/enum/api-error.enum.d.ts +15 -1
  42. package/dist/types/enum/api-error.enum.js +14 -0
  43. package/dist/types/enum/api-error.enum.js.map +1 -1
  44. package/dist/types/index.d.ts +1 -1
  45. package/dist/types/index.js +1 -1
  46. package/dist/types/index.js.map +1 -1
  47. package/dist/types/interface/api/requests/index.d.ts +1 -0
  48. package/dist/types/interface/api/requests/index.js +1 -0
  49. package/dist/types/interface/api/requests/index.js.map +1 -1
  50. package/dist/types/interface/api/requests/probe-usage.request.d.ts +3 -0
  51. package/dist/types/interface/{models/probe-webhook.model.js → api/requests/probe-usage.request.js} +1 -1
  52. package/dist/types/interface/api/requests/probe-usage.request.js.map +1 -0
  53. package/dist/types/interface/api/requests/probe-webhook.request.d.ts +8 -0
  54. package/dist/types/interface/api/responses/index.d.ts +1 -0
  55. package/dist/types/interface/api/responses/index.js +1 -0
  56. package/dist/types/interface/api/responses/index.js.map +1 -1
  57. package/dist/types/interface/api/responses/probe-scan.response.d.ts +1 -0
  58. package/dist/types/interface/api/responses/probe-usage.response.d.ts +7 -0
  59. package/dist/types/interface/api/responses/probe-usage.response.js +3 -0
  60. package/dist/types/interface/api/responses/probe-usage.response.js.map +1 -0
  61. package/dist/types/interface/api/responses/probe-webhook.response.d.ts +5 -2
  62. package/dist/types/interface/index.d.ts +0 -1
  63. package/dist/types/interface/index.js +0 -1
  64. package/dist/types/interface/index.js.map +1 -1
  65. package/dist/types/interface/models/index.d.ts +3 -2
  66. package/dist/types/interface/models/index.js +3 -2
  67. package/dist/types/interface/models/index.js.map +1 -1
  68. package/dist/types/interface/models/{probe-scan.model.d.ts → probe-scan.dto.d.ts} +8 -0
  69. package/dist/types/interface/models/probe-scan.dto.js +3 -0
  70. package/dist/types/interface/models/probe-scan.dto.js.map +1 -0
  71. package/dist/types/interface/models/probe-webhook-delivery.dto.d.ts +19 -0
  72. package/dist/types/interface/models/probe-webhook-delivery.dto.js.map +1 -0
  73. package/dist/types/interface/models/{probe-webhook.model.d.ts → probe-webhook.dto.d.ts} +1 -3
  74. package/dist/types/interface/models/probe-webhook.dto.js +3 -0
  75. package/dist/types/interface/models/probe-webhook.dto.js.map +1 -0
  76. package/dist/types/tests/probe.dto.test.js +39 -2
  77. package/dist/types/tests/probe.dto.test.js.map +1 -1
  78. package/dist/utils/enum.utils.d.ts +1 -0
  79. package/dist/utils/enum.utils.js +3 -0
  80. package/dist/utils/enum.utils.js.map +1 -0
  81. package/dist/utils/error.utils.d.ts +15 -0
  82. package/dist/utils/error.utils.js +25 -0
  83. package/dist/utils/error.utils.js.map +1 -0
  84. package/dist/utils/index.d.ts +3 -1
  85. package/dist/utils/index.js +3 -1
  86. package/dist/utils/index.js.map +1 -1
  87. package/dist/utils/probe-scan-cost.utils.d.ts +5 -0
  88. package/dist/utils/probe-scan-cost.utils.js +21 -0
  89. package/dist/utils/probe-scan-cost.utils.js.map +1 -0
  90. package/dist/utils/probe-webhook-signature.utils.d.ts +0 -2
  91. package/dist/utils/probe-webhook-signature.utils.js +1 -2
  92. package/dist/utils/probe-webhook-signature.utils.js.map +1 -1
  93. package/package.json +24 -14
  94. package/src/api/index.ts +6 -0
  95. package/src/api/probe-scan.api.test.ts +47 -0
  96. package/src/api/probe-scan.api.ts +203 -0
  97. package/src/api/probe-scan.application.api.test.ts +35 -0
  98. package/src/api/probe-scan.application.api.ts +157 -0
  99. package/src/api/probe-usage.api.ts +47 -0
  100. package/src/api/probe-usage.application.api.ts +25 -0
  101. package/src/api/probe-webhook.api.test.ts +17 -0
  102. package/src/api/probe-webhook.api.ts +119 -0
  103. package/src/api/probe-webhook.application.api.test.ts +18 -0
  104. package/src/api/probe-webhook.application.api.ts +141 -0
  105. package/src/constants/index.ts +1 -0
  106. package/src/index.ts +205 -0
  107. package/src/types/enum/api-error.enum.ts +33 -0
  108. package/src/types/enum/index.ts +2 -0
  109. package/src/types/enum/probe-scan.enum.ts +44 -0
  110. package/src/types/index.ts +2 -0
  111. package/src/types/interface/api/index.ts +5 -0
  112. package/src/types/interface/api/requests/index.ts +3 -0
  113. package/src/types/interface/api/requests/probe-scan.request.ts +54 -0
  114. package/src/types/interface/api/requests/probe-usage.request.ts +7 -0
  115. package/src/types/interface/api/requests/probe-webhook.request.ts +33 -0
  116. package/src/types/interface/api/responses/index.ts +3 -0
  117. package/src/types/interface/api/responses/probe-scan.response.ts +45 -0
  118. package/src/types/interface/api/responses/probe-usage.response.ts +25 -0
  119. package/src/types/interface/api/responses/probe-webhook.response.ts +24 -0
  120. package/src/types/interface/api/type-message/api-error.ts +7 -0
  121. package/src/types/interface/api/type-message/base-paginate.ts +11 -0
  122. package/src/types/interface/api/type-message/response.ts +6 -0
  123. package/src/types/interface/index.ts +2 -0
  124. package/src/types/interface/models/index.ts +3 -0
  125. package/src/types/interface/models/probe-scan.dto.ts +67 -0
  126. package/src/types/interface/models/probe-webhook-delivery.dto.ts +73 -0
  127. package/src/types/interface/models/probe-webhook.dto.ts +29 -0
  128. package/src/types/tests/probe.dto.test.ts +156 -0
  129. package/src/utils/enum.utils.ts +1 -0
  130. package/src/utils/error.utils.ts +30 -0
  131. package/src/utils/index.ts +4 -0
  132. package/src/utils/probe-scan-cost.utils.ts +101 -0
  133. package/src/utils/probe-webhook-signature.utils.ts +56 -0
  134. package/tsconfig.check.json +15 -0
  135. package/dist/types/interface/dto/index.d.ts +0 -1
  136. package/dist/types/interface/dto/index.js +0 -18
  137. package/dist/types/interface/dto/index.js.map +0 -1
  138. package/dist/types/interface/dto/probe-webhook-delivery.dto.d.ts +0 -7
  139. package/dist/types/interface/dto/probe-webhook-delivery.dto.js.map +0 -1
  140. package/dist/types/interface/models/probe-scan.model.js.map +0 -1
  141. package/dist/types/interface/models/probe-webhook.model.js.map +0 -1
  142. package/dist/utils/http.utils.d.ts +0 -3
  143. package/dist/utils/http.utils.js +0 -20
  144. package/dist/utils/http.utils.js.map +0 -1
  145. /package/dist/types/interface/{dto → models}/probe-webhook-delivery.dto.js +0 -0
@@ -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` (the global `FormData` + `Blob`,
12
+ // one code path for the browser and for Node — see that file's header for what
13
+ // a Node caller passes) 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 { AbyssProbeCore, 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 = buildScanForm(file, options);
83
+ return (
84
+ await AbyssProbeCore.axios.post<IScanResponse>(`application/${applicationId}/scan`, form, {
85
+ params: serializeProbeQuery({ mode: options.mode }),
86
+ 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 AbyssProbeCore.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 AbyssProbeCore.axios.get<IPaginateScanResponse>(`application/${applicationId}/scan`, {
154
+ params: serializeProbeQuery(query),
155
+ headers: authHeaderApplication(applicationApiKey),
156
+ })
157
+ ).data;
@@ -0,0 +1,47 @@
1
+ // ──────────────────────────────────────────────
2
+ // AbyssProbe usage API — WS5-3 (AbyssProbe UX rework). `GET /usage`: current
3
+ // ACCOUNT_AV_SCAN_UNITS ("tokens") used/limit/remaining for the caller's
4
+ // scope, via the same billing check the quota gate itself already uses (see
5
+ // apps/api/src/utils/probe-scan-billing.util.ts#getProbeScanUsage). Mirrors
6
+ // apps/api/src/api/controllers/probe-usage.controller.ts EXACTLY. No
7
+ // `probe/` path prefix — `@Controller({ prefixPath: '/usage' })` mounts
8
+ // directly at `usage`.
9
+ //
10
+ // See probe-usage.application.api.ts for the application/API-key-auth
11
+ // counterpart (`/application/:applicationId/usage`, Phase 3a).
12
+ // ──────────────────────────────────────────────
13
+
14
+ import { AbyssProbeCore } from '..';
15
+ import type { IProbeUsageScopeQuery, IProbeUsageResponse } from '../types';
16
+
17
+ const DEFAULT_API_KEY_HEADER = 'abyss-api-key';
18
+
19
+ function authHeader(apiKey?: string): Record<string, string> {
20
+ return apiKey ? { [DEFAULT_API_KEY_HEADER]: apiKey } : {};
21
+ }
22
+
23
+ /** Renames `organizationId` to the wire's `organization_id` (see probe-scan.api.ts). */
24
+ function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
25
+ const out: Record<string, unknown> = {};
26
+ for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
27
+ if (value === undefined || value === null) continue;
28
+ const wireKey = key === 'organizationId' ? 'organization_id' : key;
29
+ out[wireKey] = value;
30
+ }
31
+ return out;
32
+ }
33
+
34
+ /**
35
+ * `GET /usage` — current ACCOUNT_AV_SCAN_UNITS consumption for the caller's
36
+ * scope (personal by default, `organizationId` for an organization scope).
37
+ */
38
+ export const getProbeUsage = async (
39
+ scope: IProbeUsageScopeQuery = {},
40
+ apiKey?: string,
41
+ ): Promise<IProbeUsageResponse> =>
42
+ (
43
+ await AbyssProbeCore.axios.get<IProbeUsageResponse>('usage', {
44
+ params: serializeProbeQuery(scope),
45
+ headers: authHeader(apiKey),
46
+ })
47
+ ).data;
@@ -0,0 +1,25 @@
1
+ // ──────────────────────────────────────────────
2
+ // AbyssProbe APPLICATION usage API — WS5-3 (AbyssProbe UX rework). `GET
3
+ // /application/:applicationId/usage`: current ACCOUNT_AV_SCAN_UNITS
4
+ // consumption for the calling application's resolved billing organization.
5
+ // Mirrors apps/api/src/api/controllers/probe-usage-application.controller.ts
6
+ // EXACTLY — the application counterpart of probe-usage.api.ts.
7
+ // ──────────────────────────────────────────────
8
+
9
+ import { AbyssProbeCore, API_KEY_APPLICATION_HEADER } from '..';
10
+ import type { IProbeUsageResponse } from '../types';
11
+
12
+ function authHeaderApplication(applicationApiKey?: string): Record<string, string> {
13
+ return applicationApiKey ? { [API_KEY_APPLICATION_HEADER]: applicationApiKey } : {};
14
+ }
15
+
16
+ /** `GET /application/:applicationId/usage` — current ACCOUNT_AV_SCAN_UNITS consumption for the calling application. */
17
+ export const getProbeUsageApplication = async (
18
+ applicationId: string,
19
+ applicationApiKey?: string,
20
+ ): Promise<IProbeUsageResponse> =>
21
+ (
22
+ await AbyssProbeCore.axios.get<IProbeUsageResponse>(`application/${applicationId}/usage`, {
23
+ headers: authHeaderApplication(applicationApiKey),
24
+ })
25
+ ).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_probe_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,119 @@
1
+ // ──────────────────────────────────────────────
2
+ // AbyssProbe webhook subscription API — CRUD over registered `probe_webhooks`
3
+ // (create / list / delete / update, + paginated delivery history — mirrors
4
+ // apps/api/src/api/controllers/probe-webhook.controller.ts EXACTLY, see that
5
+ // file's header comment). No `probe/` path prefix — `@Controller({
6
+ // prefixPath: '/webhook' })` mounts directly at `webhook`.
7
+ //
8
+ // See probe-webhook.application.api.ts for the application/API-key-auth
9
+ // counterpart of this client (`/application/:applicationId/webhook...`,
10
+ // Phase 3a) — it reuses every request/response type verbatim; only the URL
11
+ // prefix, the extra `applicationId` argument, and the auth header differ.
12
+ // ──────────────────────────────────────────────
13
+
14
+ import { AbyssProbeCore } from '..';
15
+ import type {
16
+ ICreateProbeWebhookBody,
17
+ IUpdateProbeWebhookBody,
18
+ IProbeWebhookScopeQuery,
19
+ IListProbeWebhookDeliveriesQuery,
20
+ ICreateProbeWebhookResponse,
21
+ IListProbeWebhookResponse,
22
+ IDeleteProbeWebhookResponse,
23
+ IUpdateProbeWebhookResponse,
24
+ IListProbeWebhookDeliveriesResponse,
25
+ } from '../types';
26
+
27
+ const DEFAULT_API_KEY_HEADER = 'abyss-api-key';
28
+
29
+ function authHeader(apiKey?: string): Record<string, string> {
30
+ return apiKey ? { [DEFAULT_API_KEY_HEADER]: apiKey } : {};
31
+ }
32
+
33
+ /** Renames `organizationId` to the wire's `organization_id` (see probe-scan.api.ts). */
34
+ function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
35
+ const out: Record<string, unknown> = {};
36
+ for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
37
+ if (value === undefined || value === null) continue;
38
+ const wireKey = key === 'organizationId' ? 'organization_id' : key;
39
+ out[wireKey] = value instanceof Date ? value.toISOString() : value;
40
+ }
41
+ return out;
42
+ }
43
+
44
+ /**
45
+ * `POST /webhook` — register a callbackUrl for the caller's scope. The
46
+ * response's `secret` field (HMAC signing secret) is returned ONLY here —
47
+ * store it immediately, it cannot be re-revealed later.
48
+ */
49
+ export const createProbeWebhook = async (
50
+ body: ICreateProbeWebhookBody,
51
+ scope: IProbeWebhookScopeQuery = {},
52
+ apiKey?: string,
53
+ ): Promise<ICreateProbeWebhookResponse> =>
54
+ (
55
+ await AbyssProbeCore.axios.post<ICreateProbeWebhookResponse>('webhook', body, {
56
+ params: serializeProbeQuery(scope),
57
+ headers: authHeader(apiKey),
58
+ })
59
+ ).data;
60
+
61
+ /** `GET /webhook` — flat, scope-filtered list (not paginated — bounded by WEBHOOK_MAX_PER_SCOPE server-side). */
62
+ export const listProbeWebhook = async (
63
+ scope: IProbeWebhookScopeQuery = {},
64
+ apiKey?: string,
65
+ ): Promise<IListProbeWebhookResponse> =>
66
+ (
67
+ await AbyssProbeCore.axios.get<IListProbeWebhookResponse>('webhook', {
68
+ params: serializeProbeQuery(scope),
69
+ headers: authHeader(apiKey),
70
+ })
71
+ ).data;
72
+
73
+ /** `DELETE /webhook/:webhookId`. */
74
+ export const deleteProbeWebhook = async (
75
+ webhookId: string,
76
+ scope: IProbeWebhookScopeQuery = {},
77
+ apiKey?: string,
78
+ ): Promise<IDeleteProbeWebhookResponse> =>
79
+ (
80
+ await AbyssProbeCore.axios.delete<IDeleteProbeWebhookResponse>(`webhook/${webhookId}`, {
81
+ params: serializeProbeQuery(scope),
82
+ headers: authHeader(apiKey),
83
+ })
84
+ ).data;
85
+
86
+ /**
87
+ * `PATCH /webhook/:webhookId` (WS5-5) — edit `callbackUrl` and/or `active`.
88
+ * At least one field is required. Scoped like {@link deleteProbeWebhook}
89
+ * (404, never 403, for a webhookId outside the resolved scope). The response
90
+ * includes `secret` — re-displayable now, see {@link IProbeWebhook}.
91
+ */
92
+ export const updateProbeWebhook = async (
93
+ webhookId: string,
94
+ body: IUpdateProbeWebhookBody,
95
+ scope: IProbeWebhookScopeQuery = {},
96
+ apiKey?: string,
97
+ ): Promise<IUpdateProbeWebhookResponse> =>
98
+ (
99
+ await AbyssProbeCore.axios.patch<IUpdateProbeWebhookResponse>(`webhook/${webhookId}`, body, {
100
+ params: serializeProbeQuery(scope),
101
+ headers: authHeader(apiKey),
102
+ })
103
+ ).data;
104
+
105
+ /**
106
+ * `GET /webhook/:webhookId/deliveries` (WS5-6) — paginated delivery-attempt
107
+ * history for one registered webhook. Scoped like {@link deleteProbeWebhook}.
108
+ */
109
+ export const listProbeWebhookDeliveries = async (
110
+ webhookId: string,
111
+ query: IListProbeWebhookDeliveriesQuery = {},
112
+ apiKey?: string,
113
+ ): Promise<IListProbeWebhookDeliveriesResponse> =>
114
+ (
115
+ await AbyssProbeCore.axios.get<IListProbeWebhookDeliveriesResponse>(
116
+ `webhook/${webhookId}/deliveries`,
117
+ { params: serializeProbeQuery(query), headers: authHeader(apiKey) },
118
+ )
119
+ ).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_probe_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,141 @@
1
+ // ──────────────────────────────────────────────
2
+ // AbyssProbe APPLICATION webhook subscription API — CRUD over registered
3
+ // `probe_webhooks` owned by a calling application (create / list / delete /
4
+ // update, + paginated delivery history — same surface as the personal/org
5
+ // 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`, `IUpdateProbeWebhookBody`,
14
+ // `IUpdateProbeWebhookResponse`, `IListProbeWebhookDeliveriesQuery`,
15
+ // `IListProbeWebhookDeliveriesResponse`) — never redefined here. No scope
16
+ // argument/query on any of these calls (unlike the personal/org client's
17
+ // `IProbeWebhookScopeQuery`) — an application caller's scope is entirely its
18
+ // `:applicationId` URL segment, resolved server-side by
19
+ // ProbeApplicationMiddleware; there is nothing to select between.
20
+ //
21
+ // `authHeaderApplication` is kept LOCAL and unexported, same convention as
22
+ // the personal/org client's own `authHeader` — it sends
23
+ // `API_KEY_APPLICATION_HEADER` (`abyss-api-key-application`, imported from
24
+ // this package's root) instead of the personal `abyss-api-key` header.
25
+ // ──────────────────────────────────────────────
26
+
27
+ import { AbyssProbeCore, API_KEY_APPLICATION_HEADER } from '..';
28
+ import type {
29
+ ICreateProbeWebhookBody,
30
+ IUpdateProbeWebhookBody,
31
+ IListProbeWebhookDeliveriesQuery,
32
+ ICreateProbeWebhookResponse,
33
+ IListProbeWebhookResponse,
34
+ IDeleteProbeWebhookResponse,
35
+ IUpdateProbeWebhookResponse,
36
+ IListProbeWebhookDeliveriesResponse,
37
+ } from '../types';
38
+
39
+ function authHeaderApplication(applicationApiKey?: string): Record<string, string> {
40
+ return applicationApiKey ? { [API_KEY_APPLICATION_HEADER]: applicationApiKey } : {};
41
+ }
42
+
43
+ /** Renames nothing (no `organizationId` ever travels on an application call) — drops undefined/null and ISO-stringifies `Date`s, mirroring probe-scan.application.api.ts's own local helper. */
44
+ function serializeProbeQuery<T extends object>(query: T): Record<string, unknown> {
45
+ const out: Record<string, unknown> = {};
46
+ for (const [key, value] of Object.entries(query as Record<string, unknown>)) {
47
+ if (value === undefined || value === null) continue;
48
+ out[key] = value instanceof Date ? value.toISOString() : value;
49
+ }
50
+ return out;
51
+ }
52
+
53
+ /**
54
+ * `POST /application/:applicationId/webhook` — register a callbackUrl owned
55
+ * by the calling application. The response's `secret` field (HMAC signing
56
+ * secret) is returned ONLY here — store it immediately, it cannot be
57
+ * re-revealed later.
58
+ */
59
+ export const createProbeWebhookApplication = async (
60
+ applicationId: string,
61
+ body: ICreateProbeWebhookBody,
62
+ applicationApiKey?: string,
63
+ ): Promise<ICreateProbeWebhookResponse> =>
64
+ (
65
+ await AbyssProbeCore.axios.post<ICreateProbeWebhookResponse>(
66
+ `application/${applicationId}/webhook`,
67
+ body,
68
+ { headers: authHeaderApplication(applicationApiKey) },
69
+ )
70
+ ).data;
71
+
72
+ /**
73
+ * `GET /application/:applicationId/webhook` — flat list of the calling
74
+ * application's own webhooks (not paginated — bounded by
75
+ * WEBHOOK_MAX_PER_SCOPE server-side).
76
+ */
77
+ export const listProbeWebhookApplication = async (
78
+ applicationId: string,
79
+ applicationApiKey?: string,
80
+ ): Promise<IListProbeWebhookResponse> =>
81
+ (
82
+ await AbyssProbeCore.axios.get<IListProbeWebhookResponse>(
83
+ `application/${applicationId}/webhook`,
84
+ { headers: authHeaderApplication(applicationApiKey) },
85
+ )
86
+ ).data;
87
+
88
+ /**
89
+ * `DELETE /application/:applicationId/webhook/:webhookId` — cross-tenant
90
+ * guarded server-side by a direct `applicationId` comparison (404, never
91
+ * 403).
92
+ */
93
+ export const deleteProbeWebhookApplication = async (
94
+ applicationId: string,
95
+ webhookId: string,
96
+ applicationApiKey?: string,
97
+ ): Promise<IDeleteProbeWebhookResponse> =>
98
+ (
99
+ await AbyssProbeCore.axios.delete<IDeleteProbeWebhookResponse>(
100
+ `application/${applicationId}/webhook/${webhookId}`,
101
+ { headers: authHeaderApplication(applicationApiKey) },
102
+ )
103
+ ).data;
104
+
105
+ /**
106
+ * `PATCH /application/:applicationId/webhook/:webhookId` (WS5-5) — edit
107
+ * `callbackUrl` and/or `active` on a webhook owned by the calling
108
+ * application. Cross-tenant guarded server-side (404, never 403). The
109
+ * response includes `secret` — re-displayable now, see {@link IProbeWebhook}.
110
+ */
111
+ export const updateProbeWebhookApplication = async (
112
+ applicationId: string,
113
+ webhookId: string,
114
+ body: IUpdateProbeWebhookBody,
115
+ applicationApiKey?: string,
116
+ ): Promise<IUpdateProbeWebhookResponse> =>
117
+ (
118
+ await AbyssProbeCore.axios.patch<IUpdateProbeWebhookResponse>(
119
+ `application/${applicationId}/webhook/${webhookId}`,
120
+ body,
121
+ { headers: authHeaderApplication(applicationApiKey) },
122
+ )
123
+ ).data;
124
+
125
+ /**
126
+ * `GET /application/:applicationId/webhook/:webhookId/deliveries` (WS5-6) —
127
+ * paginated delivery-attempt history for one webhook owned by the calling
128
+ * application. Cross-tenant guarded server-side (404, never 403).
129
+ */
130
+ export const listProbeWebhookDeliveriesApplication = async (
131
+ applicationId: string,
132
+ webhookId: string,
133
+ query: Omit<IListProbeWebhookDeliveriesQuery, 'organizationId'> = {},
134
+ applicationApiKey?: string,
135
+ ): Promise<IListProbeWebhookDeliveriesResponse> =>
136
+ (
137
+ await AbyssProbeCore.axios.get<IListProbeWebhookDeliveriesResponse>(
138
+ `application/${applicationId}/webhook/${webhookId}/deliveries`,
139
+ { params: serializeProbeQuery(query), headers: authHeaderApplication(applicationApiKey) },
140
+ )
141
+ ).data;
@@ -0,0 +1 @@
1
+ export {};