@classytic/arc 2.51.0 → 2.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/{EventTransport-K7Q9WPjm.mjs → EventTransport-B3jTKMQH.mjs} +2 -2
- package/dist/{HookSystem-DBAu9uNT.mjs → HookSystem-DNwxV463.mjs} +2 -2
- package/dist/{ResourceRegistry-BelzCRMy.mjs → ResourceRegistry-Ck7RFodL.mjs} +2 -2
- package/dist/{acquire-B0zhfGSm.mjs → acquire-DkLruwhL.mjs} +1 -1
- package/dist/audit/index.d.mts +1 -1
- package/dist/audit/index.mjs +4 -4
- package/dist/auth/audit.mjs +1 -1
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/auth/redis-session.mjs +1 -1
- package/dist/auth/social/index.mjs +1 -1
- package/dist/{authorizationDecision-Dxj_cy6N.mjs → authorizationDecision-gB5-bHDp.mjs} +9 -7
- package/dist/bootError-BT3z3cvX.mjs +38 -0
- package/dist/{boundedMap-DOBai-H3.mjs → boundedMap-Ddw2yGb2.mjs} +1 -1
- package/dist/{buildHandler-Dyl8P9j0.mjs → buildHandler-B8IDGmhD.mjs} +5 -5
- package/dist/cache/index.mjs +4 -4
- package/dist/{caching-CUmaNL8Y.mjs → caching-BitJDAY0.mjs} +2 -2
- package/dist/{claimed-DJPk4VZr.mjs → claimed-CM_-lFHX.mjs} +1 -1
- package/dist/cleanup/index.d.mts +2 -2
- package/dist/cleanup/index.mjs +4 -4
- package/dist/cli/commands/describe.d.mts +18 -1
- package/dist/cli/commands/describe.mjs +39 -7
- package/dist/cli/commands/docs.mjs +3 -3
- package/dist/cli/commands/doctor.d.mts +3 -1
- package/dist/cli/commands/doctor.mjs +135 -22
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/commands/init.mjs +2 -2
- package/dist/cli/commands/introspect.mjs +2 -2
- package/dist/cli/index.mjs +3 -3
- package/dist/{constants-DH41jnNT.mjs → constants-D9EiaO5s.mjs} +1 -1
- package/dist/context/index.d.mts +5 -2
- package/dist/context/index.mjs +5 -5
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +7 -7
- package/dist/{core-DPmRWlpx.mjs → core-B_06Fcn0.mjs} +3 -3
- package/dist/{createActionRouter-B1xhER6i.mjs → createActionRouter-DtxUXOCI.mjs} +5 -5
- package/dist/{createAggregationRouter-CNntJL-z.mjs → createAggregationRouter-BMiKyDoW.mjs} +7 -7
- package/dist/{createApp-DpG26bCu.mjs → createApp-CEdGZtkP.mjs} +207 -44
- package/dist/{createMcpServer-CS2KOVP6.d.mts → createMcpServer-Bk3ls5jS.d.mts} +1 -1
- package/dist/{defineAggregation-rI3EbZUg.mjs → defineAggregation-DUsrGcsm.mjs} +1 -1
- package/dist/{defineResource-5DcG_wlI.mjs → defineResource-q8TsJpOm.mjs} +92 -36
- package/dist/deprecation-DX625dth.mjs +27 -0
- package/dist/discovery/index.mjs +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +3 -3
- package/dist/{elevation-XFu7J3aj.mjs → elevation-NJ3908pJ.mjs} +5 -5
- package/dist/encryption/index.d.mts +26 -1
- package/dist/encryption/index.mjs +56 -6
- package/dist/{errorHandler-xDVUWOMu.mjs → errorHandler-Ke6PGvF7.mjs} +7 -4
- package/dist/{errors-KBZ3tQk5.mjs → errors-Ukhmfmmx.mjs} +1 -1
- package/dist/{eventPlugin-BY38F6yK.d.mts → eventPlugin-BeJasppx.d.mts} +7 -18
- package/dist/{eventPlugin-C4lNj2Dw.mjs → eventPlugin-DTKAgSvb.mjs} +10 -8
- package/dist/{eventTypes-DZRoUAdk.mjs → eventTypes-DpDQtyR6.mjs} +2 -2
- package/dist/events/index.d.mts +2 -2
- package/dist/events/index.mjs +8 -8
- package/dist/events/transports/redis-stream-entry.mjs +4 -4
- package/dist/events/transports/redis.mjs +2 -2
- package/dist/factory/index.d.mts +28 -5
- package/dist/factory/index.mjs +12 -7
- package/dist/{fastify-augmentation-baQc3MaO.d.mts → fastify-augmentation-DjxuSRG4.d.mts} +4 -3
- package/dist/{fieldTypes-DrXUW1jc.mjs → fieldTypes-BtFpQO6I.mjs} +2 -2
- package/dist/{fields-C5J8WTd2.mjs → fields-B7fuROWK.mjs} +1 -1
- package/dist/{filter-merge-DTjYoDrj.mjs → filter-merge-BuzZ-r9z.mjs} +1 -1
- package/dist/{generate-SA8oMlLB.mjs → generate-c4F39pk1.mjs} +4 -4
- package/dist/{headers-D5wrBLOk.mjs → headers-Ib7BDgRI.mjs} +2 -2
- package/dist/{health-BLal039H.mjs → health-22T82HAa.mjs} +1 -1
- package/dist/health-skjSwNaC.d.mts +36 -0
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.mjs +2 -2
- package/dist/http-cache/index.mjs +4 -4
- package/dist/http-cache/purgers/cloudflare.mjs +2 -2
- package/dist/http-cache/purgers/fastly.mjs +2 -2
- package/dist/http-cache/testing/index.mjs +1 -1
- package/dist/idempotency/index.d.mts +7 -1
- package/dist/idempotency/index.mjs +9 -7
- package/dist/idempotency/redis.mjs +2 -2
- package/dist/{index-CMNpMBtW.d.mts → index-BzUyno-u.d.mts} +14 -5
- package/dist/{index-Dhrks-hM.d.mts → index-CXqYFGoH.d.mts} +13 -4
- package/dist/{index-DexdFs1a.d.mts → index-CaBFPmnu.d.mts} +29 -7
- package/dist/{index-DKM2p5w5.d.mts → index-DWn0o4U7.d.mts} +2 -2
- package/dist/{index-DLCcLUQT.d.mts → index-DtHACefu.d.mts} +109 -116
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +12 -12
- package/dist/{init-DeKHaNZn.mjs → init-XY5slyuS.mjs} +3 -3
- package/dist/integrations/event-gateway.mjs +2 -2
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/index.mjs +1 -1
- package/dist/integrations/jobs/index.mjs +3 -3
- package/dist/integrations/mcp/index.d.mts +9 -4
- package/dist/integrations/mcp/index.mjs +2 -2
- package/dist/integrations/mcp/testing.d.mts +2 -2
- package/dist/integrations/mcp/testing.mjs +2 -2
- package/dist/integrations/streamline.mjs +3 -3
- package/dist/integrations/webhooks.d.mts +1 -1
- package/dist/integrations/webhooks.mjs +4 -4
- package/dist/integrations/websocket-pushref-redis.mjs +1 -1
- package/dist/integrations/websocket-redis.mjs +1 -1
- package/dist/integrations/websocket.mjs +2 -2
- package/dist/invariants-COekUeoh.mjs +120 -0
- package/dist/{jsonBody-rDPGT5A9.mjs → jsonBody-BNlcGUnb.mjs} +2 -2
- package/dist/{keys-t7i-lJ2r.mjs → keys-DwvXJwUX.mjs} +1 -1
- package/dist/{loadResources-CcupAVJH.mjs → loadResources-izEeQLO_.mjs} +3 -3
- package/dist/{loadResourcesFromEntry-BpjYlaoj.mjs → loadResourcesFromEntry-CijqjbHE.mjs} +2 -2
- package/dist/logger/index.mjs +2 -2
- package/dist/{logger-IL7Btm-N.mjs → logger-DdMS0XC_.mjs} +1 -1
- package/dist/{mcpPlugin-BsdH7Vot.mjs → mcpPlugin-D0tSZqKk.mjs} +24 -22
- package/dist/{memory-Dkp6ZD3F.mjs → memory-Ay0haw9n.mjs} +3 -3
- package/dist/{metrics-CDPqgdKr.mjs → metrics-Bpgf4UL6.mjs} +3 -3
- package/dist/middleware/index.d.mts +1 -1
- package/dist/middleware/index.mjs +3 -3
- package/dist/migrations/index.mjs +2 -2
- package/dist/{module-KFxT1Iuk.mjs → module-BLrTmMyk.mjs} +17 -2
- package/dist/{multiTenant-QtDzxx_K.d.mts → multiTenant-Cf0Ye-Wu.d.mts} +1 -1
- package/dist/{multipartBody-BHktuarE.mjs → multipartBody-L2gr96df.mjs} +1 -1
- package/dist/{observeSend-CY-sLanc.mjs → observeSend-B7FEdk_g.mjs} +1 -1
- package/dist/{openapi-DbeXiy2v.mjs → openapi-COrL_33P.mjs} +6 -6
- package/dist/outbox-admin/index.d.mts +1 -1
- package/dist/outbox-admin/index.mjs +6 -6
- package/dist/{outbox-module-BWqkTE8-.mjs → outbox-module-BY2HtnjU.mjs} +7 -7
- package/dist/{outbox-module-DzW6zwWJ.d.mts → outbox-module-C1QWMloZ.d.mts} +5 -8
- package/dist/permissions/index.d.mts +2 -2
- package/dist/permissions/index.mjs +8 -8
- package/dist/{permissions-e5YMrFbm.mjs → permissions-CEyeDHtT.mjs} +36 -17
- package/dist/{pipe-CMnKfdF4.mjs → pipe-DIAr91at.mjs} +2 -2
- package/dist/pipeline/index.d.mts +1 -1
- package/dist/pipeline/index.mjs +2 -2
- package/dist/{plan-BvLJGm3U.mjs → plan-BhKHIkFl.mjs} +75 -20
- package/dist/{plugin-DYmu8uT4.mjs → plugin-D6hrdx-j.mjs} +72 -38
- package/dist/plugins/index.d.mts +4 -3
- package/dist/plugins/index.mjs +18 -18
- package/dist/plugins/response-cache.mjs +4 -4
- package/dist/plugins/tracing-entry.mjs +177 -85
- package/dist/{pluralize-ClwfBdIx.mjs → pluralize-CJKgYkVc.mjs} +1 -1
- package/dist/presetPermission-2pcRVYRG.mjs +23 -0
- package/dist/presets/filesUpload.d.mts +4 -2
- package/dist/presets/filesUpload.mjs +11 -6
- package/dist/presets/index.d.mts +6 -4
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +5 -5
- package/dist/presets/search.d.mts +2 -2
- package/dist/presets/search.mjs +54 -38
- package/dist/{presets-DX_lPabi.mjs → presets-st11ePNn.mjs} +150 -41
- package/dist/{projection-DnZiFPPE.mjs → projection-B4rqiJTi.mjs} +2 -2
- package/dist/{purger.types-BEzTVDOU.mjs → purger.types-BcHeAhY_.mjs} +1 -1
- package/dist/{queryCachePlugin-C57-Nj-g.mjs → queryCachePlugin-BgSc2bga.mjs} +6 -6
- package/dist/rateLimitKey-DLGdeFd2.mjs +138 -0
- package/dist/{realtime-C-VIoXMg.mjs → realtime-CpYpIFsm.mjs} +11 -11
- package/dist/registry/index.d.mts +2 -2
- package/dist/registry/index.mjs +3 -3
- package/dist/{registry-DbQvODPH.mjs → registry-BQsdAlZ_.mjs} +2 -2
- package/dist/{relay-B61seKq1.mjs → relay-CmT3gtkP.mjs} +11 -12
- package/dist/{renewingLease-Dp7wmzNN.mjs → renewingLease-DaoP0K-e.mjs} +1 -1
- package/dist/{replyHelpers-CHii_jIO.mjs → replyHelpers-SiLr1wK4.mjs} +2 -2
- package/dist/{requestContext-C_mbAm8o.mjs → requestContext-B-TjFpWt.mjs} +8 -3
- package/dist/{health-vEo3fni4.mjs → requestId-ClcKoWLq.mjs} +154 -116
- package/dist/{requirement-C8OsWLYp.mjs → requirement-BygDzjDS.mjs} +1 -1
- package/dist/{resourceRateLimit-DhbQZjE2.mjs → resourceRateLimit-DdIYis3m.mjs} +2 -2
- package/dist/{rolldown-runtime-HTi8KV7V.mjs → rolldown-runtime-Cy6j0m8_.mjs} +1 -1
- package/dist/{routeValidator-DnQ2BGnH.mjs → routeValidator-Bn-x2gaJ.mjs} +1 -1
- package/dist/{runtimeCapabilities-G9QXHov1.mjs → runtimeCapabilities-DY20Pibh.mjs} +7 -2
- package/dist/{schedules-DAthT5O3.mjs → schedules-CwqC0Mp0.mjs} +5 -5
- package/dist/{schemaConverter-BOt_ed78.mjs → schemaConverter-XoLKVpzG.mjs} +2 -2
- package/dist/{schemaIR-MZVVj6Cw.mjs → schemaIR-DP7mMj7c.mjs} +16 -16
- package/dist/schemas/index.mjs +1 -1
- package/dist/scim/index.mjs +2 -2
- package/dist/scope/index.d.mts +6 -2
- package/dist/scope/index.mjs +5 -5
- package/dist/{scope-btg-225w.mjs → scope-B0vgM2Zw.mjs} +4 -4
- package/dist/{shutdown-Dfy8La90.mjs → shutdown-C76Hn-Th.mjs} +1 -1
- package/dist/{simpleEqualityMatcher-D5dOqbbj.mjs → simpleEqualityMatcher-Qbl-11cE.mjs} +1 -1
- package/dist/{sse-DivxX1m6.mjs → sse-eyb8lNuI.mjs} +7 -7
- package/dist/{sseStream-hQxQjvre.mjs → sseStream-BsBesrfw.mjs} +2 -2
- package/dist/{store-helpers-DfqfssAw.mjs → store-helpers-D1yIVa91.mjs} +1 -1
- package/dist/{streaming-CQiOktsh.mjs → streaming-DKziqs1Z.mjs} +1 -1
- package/dist/{subscriberIdentity-Bf8VLqA7.mjs → subscriberIdentity-DpdSQMQq.mjs} +1 -1
- package/dist/{tenancy-Btmaf1MB.mjs → tenancy-YuRYsOPr.mjs} +2 -2
- package/dist/{tenantPreparation-4e3qyb6q.mjs → tenantPreparation-Bk8ouRB3.mjs} +17 -5
- package/dist/testing/cleanupStoreContract.mjs +1 -1
- package/dist/testing/index.d.mts +4 -4
- package/dist/testing/index.mjs +11 -11
- package/dist/testing/outboxStoreContract.mjs +2 -2
- package/dist/testing/requiredPorts.d.mts +1 -1
- package/dist/testing/requiredPorts.mjs +2 -2
- package/dist/testing/storageContract.mjs +1 -1
- package/dist/{timing-DXx0IWyi.mjs → timing-BtIDIdQz.mjs} +1 -1
- package/dist/{transactionContext-DperjON1.mjs → transactionContext-BsQ5ortM.mjs} +1 -1
- package/dist/{typeGuards-eoQLIOh6.mjs → typeGuards-Cr2_zEW0.mjs} +1 -1
- package/dist/types/index.d.mts +2 -2
- package/dist/types/index.mjs +1 -1
- package/dist/types/storage.mjs +1 -1
- package/dist/{types-BeEJm-DV.d.mts → types-CQhHTZXs.d.mts} +48 -35
- package/dist/{types-B4E0sc6D.d.mts → types-DWFgq8EP.d.mts} +1 -1
- package/dist/{types-CcpISJe8.mjs → types-ZvdR7MVa.mjs} +4 -4
- package/dist/usage/index.mjs +4 -4
- package/dist/{userHelpers-Cp5zqlEN.mjs → userHelpers-CwpEK36a.mjs} +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.mjs +12 -12
- package/dist/{utils-dKN-_315.mjs → utils-CnrfcYMq.mjs} +6 -6
- package/dist/{validate-BZHaAdgy.mjs → validate-BTQBh-Dr.mjs} +3 -3
- package/dist/{versioning-CPLP0VbB.mjs → versioning-DiLykI6U.mjs} +3 -3
- package/dist/{workScope-BI72KXsI.mjs → workScope-C3tPz_Gt.mjs} +2 -2
- package/package.json +34 -9
- package/skills/arc/SKILL.md +5 -5
- package/skills/arc/references/api-reference.md +1 -1
- package/skills/arc/references/boot.md +17 -2
- package/skills/arc/references/events.md +0 -1
- package/skills/arc/references/mcp-setup.md +3 -2
- package/skills/arc/references/multi-tenancy.md +1 -1
- package/skills/arc/references/production-api.md +19 -12
- package/skills/arc/references/production-audit.md +1 -1
- package/skills/arc/references/production-boot.md +3 -3
- package/skills/arc/references/production-idempotency.md +2 -2
- package/skills/arc/references/production-observability.md +14 -2
- package/skills/arc/references/production-reliability.md +1 -1
- package/skills/arc/references/querying.md +1 -2
- package/skills/arc/references/resources.md +8 -6
- package/skills/arc/references/testing.md +1 -1
- package/skills/arc-code-review/references/arc-cheatsheet.md +1 -1
- package/skills/arc-code-review/references/recipe-scope-permissions.md +1 -1
- package/skills/arc-module-publishing/references/resource-assembly.md +2 -2
- package/dist/rateLimitKey-B1RxyGt3.mjs +0 -40
|
@@ -1,132 +1,227 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fp from "fastify-plugin";
|
|
4
4
|
// src/plugins/tracing.ts
|
|
5
5
|
/**
|
|
6
6
|
* OpenTelemetry Distributed Tracing Plugin
|
|
7
7
|
*
|
|
8
|
-
* Traces HTTP requests
|
|
9
|
-
*
|
|
8
|
+
* Traces HTTP requests and the spans your code adds (`createSpan`, `traced`).
|
|
9
|
+
* Explicit opt-in: nothing is traced until a host registers this plugin.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* import { tracingPlugin } from '@classytic/arc/plugins';
|
|
12
|
+
* import { tracingPlugin } from '@classytic/arc/plugins/tracing';
|
|
13
13
|
*
|
|
14
14
|
* await fastify.register(tracingPlugin, {
|
|
15
15
|
* serviceName: 'my-api',
|
|
16
16
|
* exporterUrl: 'http://localhost:4318/v1/traces', // OTLP endpoint
|
|
17
17
|
* });
|
|
18
18
|
*
|
|
19
|
-
* ##
|
|
19
|
+
* ## What it needs (OpenTelemetry JS SDK 3.x line)
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* (`trace.getTracer`, `context.with`, etc.) go through the optional-require
|
|
25
|
-
* path; everything downstream keeps its shape through the plugin.
|
|
21
|
+
* CORE — without any of these the plugin is a no-op with one warning:
|
|
22
|
+
* `@opentelemetry/api`, `@opentelemetry/sdk-trace` (`TracerProvider`),
|
|
23
|
+
* `@opentelemetry/resources`, `@opentelemetry/semantic-conventions`.
|
|
26
24
|
*
|
|
27
|
-
*
|
|
28
|
-
* `
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
25
|
+
* OPTIONAL — each loads on its own; a missing one is named once and tracing continues:
|
|
26
|
+
* - `@opentelemetry/exporter-trace-otlp-http` — where spans go (warning: not exported).
|
|
27
|
+
* - `@opentelemetry/context-async-hooks` — keeps the request span active across
|
|
28
|
+
* `await`, so instrumentations parent their spans to it (warning).
|
|
29
|
+
* - `@opentelemetry/core` — W3C `traceparent` / baggage propagation (warning).
|
|
30
|
+
* - instrumentations: `@opentelemetry/auto-instrumentations-node`, else
|
|
31
|
+
* `@opentelemetry/instrumentation-http` / `@opentelemetry/instrumentation-mongodb`
|
|
32
|
+
* singly (debug line).
|
|
33
|
+
*
|
|
34
|
+
* A global provider, context manager or propagator the host already registered (for
|
|
35
|
+
* example with `NodeSDK`) is kept: arc then uses it instead of its own.
|
|
36
|
+
*
|
|
37
|
+
* ## Span shape (stable OpenTelemetry HTTP semantic conventions)
|
|
38
|
+
*
|
|
39
|
+
* Name: `{METHOD} {route template}` (`GET /products/:id`), or `{METHOD}` alone when no
|
|
40
|
+
* route matched; never the raw URL, whose ids and query strings make names unbounded.
|
|
41
|
+
* The query string is not recorded (it can carry tokens).
|
|
32
42
|
*/
|
|
33
43
|
const require = createRequire(import.meta.url);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
const PKG = {
|
|
45
|
+
api: "@opentelemetry/api",
|
|
46
|
+
sdk: "@opentelemetry/sdk-trace",
|
|
47
|
+
resources: "@opentelemetry/resources",
|
|
48
|
+
semconv: "@opentelemetry/semantic-conventions",
|
|
49
|
+
exporter: "@opentelemetry/exporter-trace-otlp-http",
|
|
50
|
+
contextManager: "@opentelemetry/context-async-hooks",
|
|
51
|
+
core: "@opentelemetry/core",
|
|
52
|
+
auto: "@opentelemetry/auto-instrumentations-node"
|
|
53
|
+
};
|
|
54
|
+
const CORE_PACKAGES = [
|
|
55
|
+
PKG.api,
|
|
56
|
+
PKG.sdk,
|
|
57
|
+
PKG.resources,
|
|
58
|
+
PKG.semconv
|
|
59
|
+
];
|
|
60
|
+
const SINGLE_INSTRUMENTATIONS = [{
|
|
61
|
+
pkg: "@opentelemetry/instrumentation-http",
|
|
62
|
+
exportName: "HttpInstrumentation"
|
|
63
|
+
}, {
|
|
64
|
+
pkg: "@opentelemetry/instrumentation-mongodb",
|
|
65
|
+
exportName: "MongoDBInstrumentation"
|
|
66
|
+
}];
|
|
67
|
+
/** Load each OpenTelemetry package on its own, so one absence never hides the rest. */
|
|
68
|
+
function loadOtel() {
|
|
69
|
+
const missing = [];
|
|
70
|
+
const load = (pkg, has) => {
|
|
71
|
+
try {
|
|
72
|
+
const mod = require(pkg);
|
|
73
|
+
if (has(mod)) return mod;
|
|
74
|
+
} catch {}
|
|
75
|
+
missing.push(pkg);
|
|
76
|
+
};
|
|
77
|
+
const bindings = {
|
|
78
|
+
api: load(PKG.api, (m) => typeof m.trace === "object"),
|
|
79
|
+
sdk: load(PKG.sdk, (m) => typeof m.TracerProvider === "function"),
|
|
80
|
+
resources: load(PKG.resources, (m) => typeof m.resourceFromAttributes === "function"),
|
|
81
|
+
semconv: load(PKG.semconv, (m) => typeof m.ATTR_HTTP_REQUEST_METHOD === "string"),
|
|
82
|
+
exporter: load(PKG.exporter, (m) => typeof m.OTLPTraceExporter === "function"),
|
|
83
|
+
contextManager: load(PKG.contextManager, (m) => typeof m.AsyncLocalStorageContextManager === "function"),
|
|
84
|
+
core: load(PKG.core, (m) => typeof m.W3CTraceContextPropagator === "function"),
|
|
85
|
+
instrumentations: [],
|
|
86
|
+
missing
|
|
87
|
+
};
|
|
88
|
+
const auto = load(PKG.auto, (m) => typeof m.getNodeAutoInstrumentations === "function");
|
|
89
|
+
if (auto) bindings.getNodeAutoInstrumentations = auto.getNodeAutoInstrumentations;
|
|
90
|
+
else for (const { pkg, exportName } of SINGLE_INSTRUMENTATIONS) {
|
|
91
|
+
const ctor = load(pkg, (m) => typeof m[exportName] === "function")?.[exportName];
|
|
92
|
+
if (ctor) bindings.instrumentations.push({
|
|
93
|
+
pkg,
|
|
94
|
+
ctor
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return bindings;
|
|
98
|
+
}
|
|
99
|
+
const otel = loadOtel();
|
|
100
|
+
const isAvailable = Boolean(otel.api && otel.sdk && otel.resources && otel.semconv);
|
|
101
|
+
const trace = otel.api?.trace;
|
|
102
|
+
const context = otel.api?.context;
|
|
103
|
+
const SpanStatusCode = otel.api?.SpanStatusCode;
|
|
104
|
+
const semconv = otel.semconv;
|
|
56
105
|
/**
|
|
57
|
-
*
|
|
106
|
+
* Build the SDK `TracerProvider` and register it globally, together with an async
|
|
107
|
+
* context manager and W3C propagators when those packages are present. Anything the
|
|
108
|
+
* host registered first stays; arc's copy is then shut down unused. Returns the
|
|
109
|
+
* provider arc owns (to flush on close), or `undefined` when the host's is in use.
|
|
58
110
|
*/
|
|
59
|
-
function
|
|
60
|
-
|
|
111
|
+
function setupGlobals(api, options, log) {
|
|
112
|
+
const { sdk, resources, semconv: sc } = otel;
|
|
113
|
+
if (!sdk || !resources || !sc) return void 0;
|
|
61
114
|
const { serviceName = "@classytic/arc", serviceVersion, exporterUrl = "http://localhost:4318/v1/traces" } = options;
|
|
62
|
-
const resolvedVersion = serviceVersion ?? "2.
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
115
|
+
const resolvedVersion = serviceVersion ?? "2.53.0";
|
|
116
|
+
const spanProcessors = [];
|
|
117
|
+
if (otel.exporter) spanProcessors.push(new sdk.BatchSpanProcessor({ exporter: new otel.exporter.OTLPTraceExporter({ url: exporterUrl }) }));
|
|
118
|
+
else log.warn(`[arc] tracing: ${PKG.exporter} not installed — spans are created but not exported. Install it to send spans to ${exporterUrl}.`);
|
|
119
|
+
const provider = new sdk.TracerProvider({
|
|
120
|
+
resource: resources.resourceFromAttributes({
|
|
121
|
+
[sc.ATTR_SERVICE_NAME]: serviceName,
|
|
122
|
+
[sc.ATTR_SERVICE_VERSION]: resolvedVersion
|
|
123
|
+
}),
|
|
124
|
+
spanProcessors
|
|
125
|
+
});
|
|
126
|
+
if (otel.contextManager) {
|
|
127
|
+
const manager = new otel.contextManager.AsyncLocalStorageContextManager();
|
|
128
|
+
if (!api.context.setGlobalContextManager(manager.enable())) manager.disable();
|
|
129
|
+
} else log.warn(`[arc] tracing: ${PKG.contextManager} not installed — the request span is not active across await, so instrumented calls start their own traces.`);
|
|
130
|
+
if (otel.core) {
|
|
131
|
+
const { CompositePropagator, W3CTraceContextPropagator, W3CBaggagePropagator } = otel.core;
|
|
132
|
+
api.propagation.setGlobalPropagator(new CompositePropagator({ propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()] }));
|
|
133
|
+
} else log.warn(`[arc] tracing: ${PKG.core} not installed — incoming traceparent headers are not joined.`);
|
|
134
|
+
if (!api.trace.setGlobalTracerProvider(provider)) {
|
|
135
|
+
log.info("[arc] tracing: a global tracer provider is already registered — using it");
|
|
136
|
+
provider.shutdown();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
70
139
|
return provider;
|
|
71
140
|
}
|
|
141
|
+
/** Enable the instrumentations that are installed; name each one that is not. */
|
|
142
|
+
function enableInstrumentations(log) {
|
|
143
|
+
if (otel.getNodeAutoInstrumentations) {
|
|
144
|
+
const instrumentations = otel.getNodeAutoInstrumentations({
|
|
145
|
+
"@opentelemetry/instrumentation-http": { enabled: true },
|
|
146
|
+
"@opentelemetry/instrumentation-mongodb": { enabled: true }
|
|
147
|
+
});
|
|
148
|
+
for (const instrumentation of instrumentations) instrumentation.enable();
|
|
149
|
+
log.debug("OpenTelemetry auto-instrumentation enabled");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
for (const pkg of otel.missing) if (pkg === PKG.auto || SINGLE_INSTRUMENTATIONS.some((i) => i.pkg === pkg)) log.debug(`[arc] tracing: ${pkg} not installed — skipped; tracing continues without it`);
|
|
153
|
+
for (const { pkg, ctor } of otel.instrumentations) try {
|
|
154
|
+
new ctor().enable();
|
|
155
|
+
log.debug(`[arc] tracing: ${pkg} enabled`);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
log.warn({ err }, `[arc] tracing: ${pkg} failed to start — skipped`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/** `{METHOD} {route template}`, or `{METHOD}` when no route matched — never the raw URL. */
|
|
161
|
+
function spanName(request) {
|
|
162
|
+
const route = request.routeOptions?.url;
|
|
163
|
+
return route ? `${request.method} ${route}` : request.method;
|
|
164
|
+
}
|
|
165
|
+
/** Path without the query string — the query can carry tokens, so it is never recorded. */
|
|
166
|
+
function urlPath(url) {
|
|
167
|
+
const q = url.indexOf("?");
|
|
168
|
+
return q === -1 ? url : url.slice(0, q);
|
|
169
|
+
}
|
|
72
170
|
/**
|
|
73
171
|
* OpenTelemetry Distributed Tracing Plugin
|
|
74
172
|
*/
|
|
75
173
|
async function tracingPlugin(fastify, options = {}) {
|
|
76
174
|
const { serviceName = "@classytic/arc", autoInstrumentation = true, sampleRate = 1 } = options;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
175
|
+
const api = otel.api;
|
|
176
|
+
const sc = otel.semconv;
|
|
177
|
+
if (!isAvailable || !api || !sc) {
|
|
178
|
+
const core = otel.missing.filter((p) => CORE_PACKAGES.includes(p));
|
|
179
|
+
fastify.log.warn(`OpenTelemetry not installed (${core.join(", ")}). Tracing disabled.`);
|
|
180
|
+
fastify.log.warn(`Install: npm install ${CORE_PACKAGES.join(" ")}`);
|
|
80
181
|
return;
|
|
81
182
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const instrumentations = getNodeAutoInstrumentations({
|
|
88
|
-
"@opentelemetry/instrumentation-http": { enabled: true },
|
|
89
|
-
"@opentelemetry/instrumentation-mongodb": { enabled: true }
|
|
90
|
-
});
|
|
91
|
-
for (const instrumentation of instrumentations) instrumentation.enable();
|
|
92
|
-
fastify.log.debug("OpenTelemetry auto-instrumentation enabled");
|
|
93
|
-
}
|
|
94
|
-
const tracer = otelTrace.getTracer(serviceName);
|
|
183
|
+
const provider = setupGlobals(api, options, fastify.log);
|
|
184
|
+
if (provider) fastify.addHook("onClose", async () => provider.shutdown());
|
|
185
|
+
if (autoInstrumentation) enableInstrumentations(fastify.log);
|
|
186
|
+
const tracer = api.trace.getTracer(serviceName);
|
|
187
|
+
const { SpanStatusCode: status, SpanKind } = api;
|
|
95
188
|
fastify.decorateRequest("tracer", void 0);
|
|
96
189
|
fastify.addHook("onRequest", (request, _reply, done) => {
|
|
97
190
|
if (Math.random() > sampleRate) {
|
|
98
191
|
done();
|
|
99
192
|
return;
|
|
100
193
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
194
|
+
const parent = api.propagation.extract(api.context.active(), request.headers);
|
|
195
|
+
const route = request.routeOptions?.url;
|
|
196
|
+
const span = tracer.startSpan(spanName(request), {
|
|
197
|
+
kind: SpanKind.SERVER,
|
|
103
198
|
attributes: {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
199
|
+
[sc.ATTR_HTTP_REQUEST_METHOD]: request.method,
|
|
200
|
+
...route ? { [sc.ATTR_HTTP_ROUTE]: route } : {},
|
|
201
|
+
[sc.ATTR_URL_PATH]: urlPath(request.url),
|
|
202
|
+
[sc.ATTR_URL_SCHEME]: request.protocol,
|
|
203
|
+
[sc.ATTR_SERVER_ADDRESS]: request.hostname,
|
|
204
|
+
[sc.ATTR_USER_AGENT_ORIGINAL]: request.headers["user-agent"]
|
|
110
205
|
}
|
|
111
|
-
});
|
|
206
|
+
}, parent);
|
|
112
207
|
request.tracer = {
|
|
113
208
|
tracer,
|
|
114
209
|
currentSpan: span
|
|
115
210
|
};
|
|
116
|
-
|
|
211
|
+
api.context.with(api.trace.setSpan(parent, span), done);
|
|
117
212
|
});
|
|
118
213
|
fastify.addHook("onResponse", async (request, reply) => {
|
|
119
214
|
if (!request.tracer?.currentSpan) return;
|
|
120
215
|
const span = request.tracer.currentSpan;
|
|
121
216
|
span.setAttributes({
|
|
122
|
-
|
|
123
|
-
|
|
217
|
+
[sc.ATTR_HTTP_RESPONSE_STATUS_CODE]: reply.statusCode,
|
|
218
|
+
...reply.statusCode >= 500 ? { [sc.ATTR_ERROR_TYPE]: String(reply.statusCode) } : {}
|
|
124
219
|
});
|
|
125
|
-
const
|
|
126
|
-
code:
|
|
220
|
+
const spanStatus = reply.statusCode >= 500 ? {
|
|
221
|
+
code: status.ERROR,
|
|
127
222
|
message: `HTTP ${reply.statusCode}`
|
|
128
|
-
} : { code:
|
|
129
|
-
span.setStatus(
|
|
223
|
+
} : { code: status.OK };
|
|
224
|
+
span.setStatus(spanStatus);
|
|
130
225
|
span.end();
|
|
131
226
|
});
|
|
132
227
|
fastify.addHook("onError", async (request, _reply, error) => {
|
|
@@ -134,7 +229,7 @@ async function tracingPlugin(fastify, options = {}) {
|
|
|
134
229
|
const span = request.tracer.currentSpan;
|
|
135
230
|
span.recordException(error);
|
|
136
231
|
span.setStatus({
|
|
137
|
-
code:
|
|
232
|
+
code: status.ERROR,
|
|
138
233
|
message: error.message
|
|
139
234
|
});
|
|
140
235
|
});
|
|
@@ -196,10 +291,7 @@ function traced(spanName) {
|
|
|
196
291
|
const request = args.find((arg) => !!(arg && typeof arg === "object" && "tracer" in arg && arg.tracer));
|
|
197
292
|
if (!request?.tracer) return originalMethod.apply(this, args);
|
|
198
293
|
return createSpan(request, spanName ?? `${target.constructor.name}.${propertyKey}`, async (span) => {
|
|
199
|
-
if (span)
|
|
200
|
-
span.setAttribute("db.operation", propertyKey);
|
|
201
|
-
span.setAttribute("db.system", "mongodb");
|
|
202
|
-
}
|
|
294
|
+
if (span && semconv) span.setAttribute(semconv.ATTR_DB_OPERATION_NAME, propertyKey);
|
|
203
295
|
return originalMethod.apply(this, args);
|
|
204
296
|
});
|
|
205
297
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { R as denyAll } from "./permissions-CEyeDHtT.mjs";
|
|
3
|
+
// src/presets/presetPermission.ts
|
|
4
|
+
/**
|
|
5
|
+
* A preset route's permission: the preset's own option, else the resource permission it
|
|
6
|
+
* maps to. With neither, the route carries an UNRESOLVED marker, never a silent
|
|
7
|
+
* `allowPublic()`: `defineResource` fails boot under `strictPermissions`
|
|
8
|
+
* (`preset-route-public-by-omission`) and otherwise mounts the route public with an info
|
|
9
|
+
* diagnostic, the same ladder as an ungated CRUD read. Outside `defineResource` (a direct
|
|
10
|
+
* `applyPresets` caller) the marker denies.
|
|
11
|
+
*/
|
|
12
|
+
const UNRESOLVED = Symbol.for("arc.presetPermissionUnresolved");
|
|
13
|
+
function presetPermission(check, unresolved) {
|
|
14
|
+
if (check) return check;
|
|
15
|
+
const marker = denyAll(`Preset '${unresolved.preset}' route has no permission (permissions.${unresolved.inherits} is not set)`);
|
|
16
|
+
Object.defineProperty(marker, UNRESOLVED, { value: unresolved });
|
|
17
|
+
return marker;
|
|
18
|
+
}
|
|
19
|
+
function unresolvedPresetPermission(check) {
|
|
20
|
+
if (typeof check !== "function") return void 0;
|
|
21
|
+
return Reflect.get(check, UNRESOLVED);
|
|
22
|
+
}
|
|
23
|
+
export { unresolvedPresetPermission as n, presetPermission as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { i as RequestScope } from "../types-DnkIALZ8.mjs";
|
|
3
3
|
import { l as PermissionCheck } from "../base-HXNgPQww.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { G as PresetResult } from "../index-DtHACefu.mjs";
|
|
5
5
|
import { a as StorageReadResult, i as StorageReadRange, n as StorageContext, o as StorageUploadInput, r as StorageFile, t as Storage } from "../storage-odC5MNKN.mjs";
|
|
6
6
|
export interface FilesUploadPresetRoutes {
|
|
7
7
|
upload?: boolean;
|
|
@@ -46,7 +46,9 @@ export interface FilesUploadPresetOptions {
|
|
|
46
46
|
sanitizeFilename?: FilenamePolicy;
|
|
47
47
|
/**
|
|
48
48
|
* Per-route permissions.
|
|
49
|
-
* Defaults: upload → `
|
|
49
|
+
* Defaults: upload → `permissions.create`, else `requireAuth()`; delete → `permissions.delete`,
|
|
50
|
+
* else `requireAuth()`; read → `permissions.get`, else NONE: boot fails under strict
|
|
51
|
+
* permissions (`allowPublic()` here makes downloads public on purpose).
|
|
50
52
|
*/
|
|
51
53
|
permissions?: FilesUploadPresetPermissions;
|
|
52
54
|
/** Opt out of individual routes. Default: all three enabled. */
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as multipartBody } from "../multipartBody-
|
|
3
|
-
import { B as requireAuth
|
|
4
|
-
import { c as getOrgId, g as getUserId } from "../types-
|
|
5
|
-
import { i as NotFoundError, u as ValidationError } from "../errors-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as multipartBody } from "../multipartBody-L2gr96df.mjs";
|
|
3
|
+
import { B as requireAuth } from "../permissions-CEyeDHtT.mjs";
|
|
4
|
+
import { c as getOrgId, g as getUserId } from "../types-ZvdR7MVa.mjs";
|
|
5
|
+
import { i as NotFoundError, u as ValidationError } from "../errors-Ukhmfmmx.mjs";
|
|
6
|
+
import { t as presetPermission } from "../presetPermission-2pcRVYRG.mjs";
|
|
6
7
|
// src/presets/filesUpload.ts
|
|
7
8
|
const DEFAULT_FIELD_NAME = "file";
|
|
8
9
|
const DEFAULT_MAX_FILE_SIZE = 10485760;
|
|
@@ -231,7 +232,11 @@ function filesUploadPreset(options) {
|
|
|
231
232
|
operation: "filesUpload.read",
|
|
232
233
|
summary: "Download a file",
|
|
233
234
|
description: "Streams the stored bytes. Supports single-range `Range: bytes=start-end`.",
|
|
234
|
-
permissions: options.permissions?.read ?? permissions.get
|
|
235
|
+
permissions: presetPermission(options.permissions?.read ?? permissions.get, {
|
|
236
|
+
preset: "filesUpload",
|
|
237
|
+
inherits: "get",
|
|
238
|
+
option: "filesUploadPreset({ permissions: { read } })"
|
|
239
|
+
}),
|
|
235
240
|
rawHandler: makeReadHandler(deps),
|
|
236
241
|
mcp: false
|
|
237
242
|
});
|
package/dist/presets/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import { t as AnyRecord } from "../base-HXNgPQww.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { G as PresetResult, Gn as IRequestContext, H as PresetController, L as ResourceConfig, Wn as IControllerResponse, i as PaginationResult } from "../index-DtHACefu.mjs";
|
|
4
4
|
import { FilesUploadPresetOptions, FilesUploadPresetPermissions, FilesUploadPresetRoutes, filesUploadPreset } from "./filesUpload.mjs";
|
|
5
|
-
import { n as multiTenantPreset, r as TenantFieldSpec, t as MultiTenantOptions } from "../multiTenant-
|
|
5
|
+
import { n as multiTenantPreset, r as TenantFieldSpec, t as MultiTenantOptions } from "../multiTenant-Cf0Ye-Wu.mjs";
|
|
6
6
|
import { SearchHandler, SearchPresetOptions, SearchRouteConfig, searchPreset } from "./search.mjs";
|
|
7
7
|
interface AuditedPresetOptions {
|
|
8
8
|
/** Field name for creator (default: 'createdBy') */
|
|
@@ -276,7 +276,9 @@ export type PresetInput = string | PresetResult | {
|
|
|
276
276
|
};
|
|
277
277
|
/**
|
|
278
278
|
* Apply presets to resource config.
|
|
279
|
-
* Validates preset combinations for conflicts before merging.
|
|
279
|
+
* Validates preset combinations for conflicts before merging. `controller` is
|
|
280
|
+
* what function-form `routes(permissions, controller)` receives; `defineResource`
|
|
281
|
+
* passes a handle bound to the resolved controller.
|
|
280
282
|
*/
|
|
281
|
-
export declare function applyPresets<TDoc = AnyRecord>(config: ResourceConfig<TDoc>, presets?: PresetInput[]): ResourceConfig<TDoc>;
|
|
283
|
+
export declare function applyPresets<TDoc = AnyRecord>(config: ResourceConfig<TDoc>, presets?: PresetInput[], controller?: PresetController): ResourceConfig<TDoc>;
|
|
282
284
|
export { type AuditedPresetOptions, type BulkOperation, type BulkPresetOptions, type FilesUploadPresetOptions, type FilesUploadPresetPermissions, type FilesUploadPresetRoutes, type IAuditedPreset, type IMultiTenantPreset, type IOwnedByUserPreset, type IPresetController, type ISlugLookupController, type ISoftDeleteController, type ITreeController, type MultiTenantOptions, type OwnedByUserOptions, type SearchHandler, type SearchPresetOptions, type SearchRouteConfig, type SlugLookupOptions, type TenantFieldSpec, type TreeOptions, filesUploadPreset, multiTenantPreset, searchPreset };
|
package/dist/presets/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { a as treePreset, c as ownedByUserPreset, i as registerPreset, l as bulkPreset, n as getAvailablePresets, o as softDeletePreset, r as getPreset, s as slugLookupPreset, t as applyPresets, u as auditedPreset } from "../presets-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { a as treePreset, c as ownedByUserPreset, i as registerPreset, l as bulkPreset, n as getAvailablePresets, o as softDeletePreset, r as getPreset, s as slugLookupPreset, t as applyPresets, u as auditedPreset } from "../presets-st11ePNn.mjs";
|
|
3
3
|
import { filesUploadPreset } from "./filesUpload.mjs";
|
|
4
4
|
import { multiTenantPreset } from "./multiTenant.mjs";
|
|
5
5
|
import { searchPreset } from "./search.mjs";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
|
|
2
|
-
import { n as multiTenantPreset, r as TenantFieldSpec, t as MultiTenantOptions } from "../multiTenant-
|
|
2
|
+
import { n as multiTenantPreset, r as TenantFieldSpec, t as MultiTenantOptions } from "../multiTenant-Cf0Ye-Wu.mjs";
|
|
3
3
|
export { MultiTenantOptions, type TenantFieldSpec, multiTenantPreset };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import "../constants-
|
|
3
|
-
import {
|
|
4
|
-
import { u as getRequestScope } from "../types-
|
|
5
|
-
import { t as ArcError } from "../errors-
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import "../constants-D9EiaO5s.mjs";
|
|
3
|
+
import { a as tagTenantPreparation, t as applyTenantPreparation } from "../tenantPreparation-Bk8ouRB3.mjs";
|
|
4
|
+
import { u as getRequestScope } from "../types-ZvdR7MVa.mjs";
|
|
5
|
+
import { t as ArcError } from "../errors-Ukhmfmmx.mjs";
|
|
6
6
|
// src/presets/multiTenant.ts
|
|
7
7
|
function createTenantMiddleware(specs, mode) {
|
|
8
8
|
const preparation = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { l as PermissionCheck } from "../base-HXNgPQww.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { At as RouteMcpConfig, Bn as ControllerHandler, G as PresetResult, kt as RouteDefinition } from "../index-DtHACefu.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* Search Preset — backend-agnostic search / vector / embed routes
|
|
6
6
|
*
|
|
@@ -68,7 +68,7 @@ export interface SearchRouteConfig {
|
|
|
68
68
|
path?: string;
|
|
69
69
|
/** HTTP method. Default: `POST`. */
|
|
70
70
|
method?: "GET" | "POST";
|
|
71
|
-
/** Permission check. Defaults: search/similar
|
|
71
|
+
/** Permission check. Defaults: search/similar inherit `permissions.list` (unset: boot error under strict permissions); embed → `requireAuth()`. */
|
|
72
72
|
permissions?: PermissionCheck;
|
|
73
73
|
/** Fastify/AJV route schema (body/querystring/params/headers/response). */
|
|
74
74
|
schema?: RouteDefinition["schema"];
|
package/dist/presets/search.mjs
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import {
|
|
1
|
+
/*! @classytic/arc v2.53.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as conjoinPolicyFilters } from "../filter-merge-BuzZ-r9z.mjs";
|
|
3
|
+
import { B as requireAuth } from "../permissions-CEyeDHtT.mjs";
|
|
4
|
+
import { t as presetPermission } from "../presetPermission-2pcRVYRG.mjs";
|
|
3
5
|
// src/presets/search.ts
|
|
4
6
|
const BUILTINS = [
|
|
5
7
|
{
|
|
6
8
|
key: "search",
|
|
7
9
|
defaultPath: "/search",
|
|
8
10
|
defaultOperation: "search",
|
|
11
|
+
tenantSlot: "list",
|
|
9
12
|
defaultSummary: "Search",
|
|
10
13
|
defaultDescription: "Full-text / engine-backed search. Delegates to the configured backend.",
|
|
11
|
-
permissionFallback: (p) => p.list
|
|
14
|
+
permissionFallback: (p) => presetPermission(p.list, {
|
|
15
|
+
preset: "search",
|
|
16
|
+
inherits: "list",
|
|
17
|
+
option: "searchPreset({ search: { permissions } })"
|
|
18
|
+
})
|
|
12
19
|
},
|
|
13
20
|
{
|
|
14
21
|
key: "similar",
|
|
15
22
|
defaultPath: "/search-similar",
|
|
16
23
|
defaultOperation: "searchSimilar",
|
|
24
|
+
tenantSlot: "list",
|
|
17
25
|
defaultSummary: "Semantic search",
|
|
18
26
|
defaultDescription: "Vector / similarity search. Delegates to the configured backend.",
|
|
19
|
-
permissionFallback: (p) => p.list
|
|
27
|
+
permissionFallback: (p) => presetPermission(p.list, {
|
|
28
|
+
preset: "search",
|
|
29
|
+
inherits: "list",
|
|
30
|
+
option: "searchPreset({ similar: { permissions } })"
|
|
31
|
+
})
|
|
20
32
|
},
|
|
21
33
|
{
|
|
22
34
|
key: "embed",
|
|
@@ -50,47 +62,45 @@ function normaliseSection(value) {
|
|
|
50
62
|
if (value === true) return {};
|
|
51
63
|
return value;
|
|
52
64
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* carries `query` (vector, text, or multimodal), `limit`, `filter`,
|
|
69
|
-
* `numCandidates`, `exact`, `field`, `minScore`, etc. Arc passes `body`
|
|
70
|
-
* directly so the shapes align. Passing positional args here would
|
|
71
|
-
* silently break (first arg becomes the whole `params`, second arg
|
|
72
|
-
* is ignored).
|
|
73
|
-
*
|
|
74
|
-
* - **`embed`** (mongokit `vectorPlugin`):
|
|
75
|
-
* `embed(input: string | EmbeddingInput)` — single arg. Arc passes
|
|
76
|
-
* `body.input ?? body`, so callers may wrap as `{ input: "…" }` or send
|
|
77
|
-
* the `EmbeddingInput` shape directly.
|
|
78
|
-
*/
|
|
79
|
-
function autoHandlerFor(repo, method) {
|
|
65
|
+
function postFilter(result, allows) {
|
|
66
|
+
if (Array.isArray(result)) return result.filter(allows);
|
|
67
|
+
if (result !== null && typeof result === "object" && Array.isArray(result.data)) {
|
|
68
|
+
const page = result;
|
|
69
|
+
const data = page.data.filter(allows);
|
|
70
|
+
const removed = page.data.length - data.length;
|
|
71
|
+
return {
|
|
72
|
+
...page,
|
|
73
|
+
data,
|
|
74
|
+
...typeof page.total === "number" ? { total: Math.max(0, page.total - removed) } : {}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function autoHandlerFor(repo, method, scopeOf) {
|
|
80
80
|
if (!repo) return void 0;
|
|
81
81
|
const fn = repo[method];
|
|
82
82
|
if (typeof fn !== "function") return void 0;
|
|
83
83
|
if (method === "embed") return async (req) => {
|
|
84
84
|
const body = req.body ?? {};
|
|
85
|
-
return fn(body.input ?? body);
|
|
85
|
+
return fn.call(repo, body.input ?? body);
|
|
86
86
|
};
|
|
87
|
+
const scope = scopeOf();
|
|
87
88
|
if (method === "searchSimilar") return async (req) => {
|
|
88
|
-
const body = req.body ?? {};
|
|
89
|
-
|
|
89
|
+
const { filter: callerFilter, ...body } = req.body ?? {};
|
|
90
|
+
const { filter, options } = await scope(req);
|
|
91
|
+
return fn.call(repo, {
|
|
92
|
+
...body,
|
|
93
|
+
filter: conjoinPolicyFilters(callerFilter, filter),
|
|
94
|
+
...options
|
|
95
|
+
});
|
|
90
96
|
};
|
|
91
97
|
return async (req) => {
|
|
92
98
|
const body = req.body ?? {};
|
|
93
|
-
|
|
99
|
+
const { options, allows } = await scope(req);
|
|
100
|
+
return postFilter(await fn.call(repo, body.query, {
|
|
101
|
+
...body,
|
|
102
|
+
...options
|
|
103
|
+
}), allows);
|
|
94
104
|
};
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
@@ -120,12 +130,17 @@ function searchPreset(options = {}) {
|
|
|
120
130
|
};
|
|
121
131
|
return {
|
|
122
132
|
name: "search",
|
|
123
|
-
routes: (permissions) => {
|
|
133
|
+
routes: (permissions, controller) => {
|
|
124
134
|
const mounted = [];
|
|
135
|
+
let listScope;
|
|
136
|
+
const scopeOf = () => {
|
|
137
|
+
listScope ??= controller.listScope;
|
|
138
|
+
return listScope;
|
|
139
|
+
};
|
|
125
140
|
for (const spec of BUILTINS) {
|
|
126
141
|
const cfg = sections[spec.key];
|
|
127
142
|
if (!cfg) continue;
|
|
128
|
-
const handler = cfg.handler ?? autoHandlerFor(options.repository, repoMethodFor[spec.key]);
|
|
143
|
+
const handler = cfg.handler ?? autoHandlerFor(options.repository, repoMethodFor[spec.key], scopeOf);
|
|
129
144
|
if (!handler) continue;
|
|
130
145
|
const route = {
|
|
131
146
|
method: cfg.method ?? "POST",
|
|
@@ -137,7 +152,8 @@ function searchPreset(options = {}) {
|
|
|
137
152
|
permissions: cfg.permissions ?? spec.permissionFallback(permissions),
|
|
138
153
|
schema: cfg.schema,
|
|
139
154
|
mcp: cfg.mcp,
|
|
140
|
-
handler: wrapEnvelope(handler)
|
|
155
|
+
handler: wrapEnvelope(handler),
|
|
156
|
+
...spec.tenantSlot ? { _tenantSlot: spec.tenantSlot } : {}
|
|
141
157
|
};
|
|
142
158
|
mounted.push(route);
|
|
143
159
|
}
|