permdock 0.0.0 → 0.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/README.md +327 -1
- package/dist/a2a/index.d.ts +169 -0
- package/dist/a2a/index.js +232 -0
- package/dist/adapter-context-mlWsVGGg.js +23 -0
- package/dist/ai-sdk/index.d.ts +95 -0
- package/dist/ai-sdk/index.js +154 -0
- package/dist/approval-required-TzNB9oQA.js +6 -0
- package/dist/approvals/index.d.ts +3 -0
- package/dist/approvals/index.js +5 -0
- package/dist/approvals-DbYAuNkG.js +224 -0
- package/dist/approvers-DT4AVyIg.js +52 -0
- package/dist/arazzo-BAgw9ap6.js +70 -0
- package/dist/arazzo-cmvX2jDe.js +54 -0
- package/dist/authzen/index.d.ts +39 -0
- package/dist/authzen/index.js +302 -0
- package/dist/better-auth/index.d.ts +109 -0
- package/dist/better-auth/index.js +344 -0
- package/dist/better-supabase/index.d.ts +206 -0
- package/dist/better-supabase/index.js +620 -0
- package/dist/bind-CVy3Espv.d.ts +25 -0
- package/dist/bind-VnYn2HKq.js +97 -0
- package/dist/boundary-BM8a_P6E.js +13 -0
- package/dist/boundary-BmHxVH1J.d.ts +15 -0
- package/dist/budget-JqcRqyhK.d.ts +11 -0
- package/dist/budget-NbEtbJC_.js +11 -0
- package/dist/canonical-json-DemiK4Vp.js +26 -0
- package/dist/capability-4qPdO9gk.js +173 -0
- package/dist/capability-Dq43tT1u.d.ts +99 -0
- package/dist/catalog/index.d.ts +12 -0
- package/dist/catalog/index.js +2 -0
- package/dist/catalog-BjZSovXQ.js +2 -0
- package/dist/catalog-doc-Dsc9y7sd.js +309 -0
- package/dist/catalog-h2tlKFkq.js +48 -0
- package/dist/catalog-path-CnI0XTFK.js +12 -0
- package/dist/catalog-z8q6bi_r.js +55 -0
- package/dist/claude-agent/index.d.ts +72 -0
- package/dist/claude-agent/index.js +77 -0
- package/dist/clerk/index.d.ts +65 -0
- package/dist/clerk/index.js +301 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +20 -0
- package/dist/cli/index.d.ts +46 -0
- package/dist/cli/index.js +5 -0
- package/dist/clients-C7zLFuWT.d.ts +12 -0
- package/dist/clients-DjU5ABMy.js +23 -0
- package/dist/cloud/index.d.ts +90 -0
- package/dist/cloud/index.js +404 -0
- package/dist/cloud-BGhHS-lY.js +50 -0
- package/dist/cloud-Bo3e9Ak3.js +118 -0
- package/dist/collect-DDDv_ESs.js +502 -0
- package/dist/collect-DLlujdHC.js +83 -0
- package/dist/collect-rG2IQ3t0.js +2 -0
- package/dist/commands-DWOrSQic.js +97 -0
- package/dist/compact-y6vfu2_f.js +19 -0
- package/dist/compare-pfyVnBjE.js +12 -0
- package/dist/compile/index.d.ts +3 -0
- package/dist/compile/index.js +2 -0
- package/dist/compile-Ba4blROR.js +613 -0
- package/dist/compile-CNnl6uIt.d.ts +94 -0
- package/dist/config-BJiM-xAm.js +157 -0
- package/dist/config-Bn00Z3ks.js +36 -0
- package/dist/config-report-Dw_JcUqT.js +44 -0
- package/dist/connection-CU8MQxRi.js +194 -0
- package/dist/context-Ttp0ekMT.js +82 -0
- package/dist/convex/index.d.ts +45 -0
- package/dist/convex/index.js +65 -0
- package/dist/create-BWyx3jua.d.ts +245 -0
- package/dist/create-CPhDL6qx.js +253 -0
- package/dist/credential-8P81ff4u.js +306 -0
- package/dist/delegation-D8pUEuce.js +103 -0
- package/dist/describe-B_gVZEVi.js +94 -0
- package/dist/describe-PdoqESvg.d.ts +36 -0
- package/dist/diff-B8Tunc3o.js +451 -0
- package/dist/diff-CzqLxZ77.js +48 -0
- package/dist/digest-B3kc_PgQ.d.ts +19 -0
- package/dist/digest-BI-6aa6d.js +27 -0
- package/dist/doctor-WpvG6p4k.js +1194 -0
- package/dist/doctor-collect-ByfYlNv1.js +664 -0
- package/dist/doctor-rOr-4ZfS.js +53 -0
- package/dist/drizzle/index.d.ts +73 -0
- package/dist/drizzle/index.js +160 -0
- package/dist/duration-xK2jGFVc.js +25 -0
- package/dist/elysia/index.d.ts +49 -0
- package/dist/elysia/index.js +59 -0
- package/dist/errors-CWfoNg9N.js +47 -0
- package/dist/errors-Cz5zn0mW.js +123 -0
- package/dist/errors-DAqevpNk.d.ts +125 -0
- package/dist/errors-DRnGZHzF.js +30 -0
- package/dist/evaluation-items-CfCCejQd.js +40 -0
- package/dist/evaluations-tz6D9A2G.js +461 -0
- package/dist/eve/index.d.ts +86 -0
- package/dist/eve/index.js +176 -0
- package/dist/expiry-BoBJ8Tvc.js +7 -0
- package/dist/express/index.d.ts +23 -0
- package/dist/express/index.js +78 -0
- package/dist/fastify/index.d.ts +33 -0
- package/dist/fastify/index.js +92 -0
- package/dist/fields-BMl1RxoX.js +26 -0
- package/dist/files-DWUN9PzI.js +125 -0
- package/dist/fixtures-ht28Cplr.js +67 -0
- package/dist/freeze-CrU8nQeX.js +60 -0
- package/dist/from-snapshot-C3sHpZNS.js +569 -0
- package/dist/generate-CH7ThJ14.js +173 -0
- package/dist/grantee-Cv5Sogfv.js +602 -0
- package/dist/graph-sql-B-dsAT6j.d.ts +29 -0
- package/dist/headers-BZSDieNT.js +6 -0
- package/dist/headers-Cf-zWvsO.d.ts +6 -0
- package/dist/helpers-H_KARDVC.js +421 -0
- package/dist/hono/index.d.ts +48 -0
- package/dist/hono/index.js +99 -0
- package/dist/hosted-DJQw46hn.js +266 -0
- package/dist/http-BIhmLfCc.js +95 -0
- package/dist/http-DPuDaChb.d.ts +13 -0
- package/dist/http-SO7qGttf.js +44 -0
- package/dist/ids-DC4V4CFu.js +18 -0
- package/dist/index-A0YNL8jZ.d.ts +177 -0
- package/dist/index-CtE07CBF.d.ts +6 -0
- package/dist/index-D3vbkoSI.d.ts +483 -0
- package/dist/index-D6_cSa1z.d.ts +201 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +26 -0
- package/dist/instance-options-BK_rNOSC.d.ts +11 -0
- package/dist/instance-options-Dhhcnm3y.js +22 -0
- package/dist/json-schema-BsAflUGW.js +106 -0
- package/dist/jwt/index.d.ts +91 -0
- package/dist/jwt/index.js +590 -0
- package/dist/kernel-GSQnMz3O.js +208 -0
- package/dist/kysely/index.d.ts +78 -0
- package/dist/kysely/index.js +129 -0
- package/dist/live-options-H2eG8dfJ.js +60 -0
- package/dist/load-DhWEB9P1.js +75 -0
- package/dist/load-DwJUafYN.js +2 -0
- package/dist/load-jose-BL6LH4bL.js +11 -0
- package/dist/lru-8q4WZjBV.js +28 -0
- package/dist/manifest-iaoBXHKc.js +783 -0
- package/dist/manifest-uDS9y5de.d.ts +206 -0
- package/dist/map-AcxK9o_D.js +147 -0
- package/dist/map-claims-Z4QZOiFF.js +369 -0
- package/dist/map-error-pgUWNNtG.js +23 -0
- package/dist/markers-B0hYLvMD.js +60 -0
- package/dist/may-use-DndQ5tQ-.js +77 -0
- package/dist/mcp/index.d.ts +159 -0
- package/dist/mcp/index.js +603 -0
- package/dist/nest/index.d.ts +75 -0
- package/dist/nest/index.js +261 -0
- package/dist/next/client.d.ts +23 -0
- package/dist/next/client.js +33 -0
- package/dist/next/index.d.ts +93 -0
- package/dist/next/index.js +180 -0
- package/dist/next/plugin.d.ts +14 -0
- package/dist/next/plugin.js +33 -0
- package/dist/node/index.d.ts +24 -0
- package/dist/node/index.js +34 -0
- package/dist/openai/index.d.ts +62 -0
- package/dist/openai/index.js +92 -0
- package/dist/openapi/index.d.ts +176 -0
- package/dist/openapi/index.js +3 -0
- package/dist/openapi-Bbg4wGVL.js +164 -0
- package/dist/openapi-BqRBvAng.js +538 -0
- package/dist/openapi-CqqEbHsL.js +250 -0
- package/dist/openapi-import-cmwetbzw.js +5959 -0
- package/dist/openapi-schema--ARjyfQr.js +6902 -0
- package/dist/orpc/index.d.ts +51 -0
- package/dist/orpc/index.js +145 -0
- package/dist/otel/index.d.ts +13 -0
- package/dist/otel/index.js +202 -0
- package/dist/package-root-zGkxO3oN.js +30 -0
- package/dist/parse-BuyjxhZV.js +53 -0
- package/dist/parse-local-manifest-BkGQNzAh.d.ts +10 -0
- package/dist/parse-local-manifest-BrMozJCo.js +36 -0
- package/dist/pdp/index.d.ts +22 -0
- package/dist/pdp/index.js +682 -0
- package/dist/peer-BOr_kJE1.js +31 -0
- package/dist/permdock-CzqXjCpU.js +3471 -0
- package/dist/permissions-CDgvKG5L.d.ts +52 -0
- package/dist/permissions-CpZrivYv.js +142 -0
- package/dist/permissions-DVoF6dMt.js +662 -0
- package/dist/permissions-DttnqqxC.d.ts +214 -0
- package/dist/pins-8ILTftC9.js +12 -0
- package/dist/policy-CFZAr_Al.d.ts +2252 -0
- package/dist/policy-D8UFyERw.d.ts +20 -0
- package/dist/policy-xyWg7QdR.js +1122 -0
- package/dist/powersync-A8x_Yyvh.js +2 -0
- package/dist/powersync-C7kLglqX.js +540 -0
- package/dist/powersync-yW1UUFzp.js +62 -0
- package/dist/prisma/index.d.ts +136 -0
- package/dist/prisma/index.js +455 -0
- package/dist/problem-B43ztKIm.js +191 -0
- package/dist/problem-details-CkL50EEf.d.ts +7 -0
- package/dist/problem-details-_AMOYz-w.js +144 -0
- package/dist/prompt-CXYhLfsS.js +32 -0
- package/dist/protected-CNsMzrVd.d.ts +27 -0
- package/dist/protected-Cs6kTaHo.js +100 -0
- package/dist/protected-bZs6rbT1.d.ts +40 -0
- package/dist/provider-Cjr62YMV.d.ts +6 -0
- package/dist/provider-DLzpb2Xz.js +52 -0
- package/dist/provider-store-DNyC1y48.js +43 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.js +7 -0
- package/dist/react/provider-client.d.ts +2 -0
- package/dist/react/provider-client.js +3 -0
- package/dist/react-native/index.d.ts +198 -0
- package/dist/react-native/index.js +696 -0
- package/dist/refs-KYb4ntaz.js +91 -0
- package/dist/relations-cjOL01hZ.js +505 -0
- package/dist/replay-BsOyTrdV.js +28 -0
- package/dist/replay-sqBGMnNs.d.ts +5 -0
- package/dist/resource-ref-CaS9yVPi.js +20 -0
- package/dist/revocations-Bhr0aMIC.js +27 -0
- package/dist/revocations-Cy06JNx2.d.ts +21 -0
- package/dist/rls-BMNydpHk.js +2521 -0
- package/dist/rls-CEvs64Kj.js +238 -0
- package/dist/rls-fields-BMasREhR.js +3502 -0
- package/dist/rls-graph-pc9fuXYm.js +435 -0
- package/dist/rls-import-D8F7j35Q.js +943 -0
- package/dist/rls-migrate-7wikfrVI.js +367 -0
- package/dist/rls-ownership-B5Lkq62W.js +843 -0
- package/dist/rls-shared-aOQ4hGTO.js +493 -0
- package/dist/rls-verify-D8B7dOTh.js +745 -0
- package/dist/row-check-Dt35czLy.d.ts +40 -0
- package/dist/rpc-DOK54_CS.js +89 -0
- package/dist/run-YXCJDNYk.js +174 -0
- package/dist/runtime-CB8gQFvS.js +11 -0
- package/dist/saas-Bj_FFkjN.js +1203 -0
- package/dist/schema-D3MnDMxa.js +300 -0
- package/dist/scim/index.d.ts +2 -0
- package/dist/scim/index.js +2 -0
- package/dist/scim-BFGBBAqR.js +1445 -0
- package/dist/scopes-CVdPrWN-.js +239 -0
- package/dist/server/index.d.ts +134 -0
- package/dist/server/index.js +11 -0
- package/dist/server-DlZ28Oz5.js +268 -0
- package/dist/sha256-BO0swRXL.js +150 -0
- package/dist/shared-DRu8VFVM.js +123 -0
- package/dist/sink-Bd9PSyfq.js +141 -0
- package/dist/sink-Gs6TTVa-.d.ts +104 -0
- package/dist/skills-Biq5uup3.js +192 -0
- package/dist/skills-JaymNCdK.js +56 -0
- package/dist/snapshot-Enxd0n-s.js +975 -0
- package/dist/snapshot-cache-D6jLelln.js +44 -0
- package/dist/snapshot-cache-DwQH8ufx.d.ts +45 -0
- package/dist/solid/index.d.ts +93 -0
- package/dist/solid/index.js +188 -0
- package/dist/sources-B0UvrJ21.js +534 -0
- package/dist/sources-BcJgw0lt.d.ts +192 -0
- package/dist/sql-xdg5f4Fi.js +27 -0
- package/dist/src-CSbUiozF.js +568 -0
- package/dist/ssf/index.d.ts +4 -0
- package/dist/ssf/index.js +596 -0
- package/dist/store-DMAWwAJV.js +371 -0
- package/dist/store-D_pjn91-.d.ts +36 -0
- package/dist/store-options-yO0V6gRn.js +716 -0
- package/dist/stores-4_sqiOA1.js +87 -0
- package/dist/stores-DVR5NHLE.d.ts +52 -0
- package/dist/stream-DDpvynSB.js +66 -0
- package/dist/stream-DlvG2hs-.d.ts +12 -0
- package/dist/style-CTm1AXDT.js +22 -0
- package/dist/subject-C6dLxqHU.js +24 -0
- package/dist/subject-settings-BwBmCdTR.js +128 -0
- package/dist/supabase/index.d.ts +183 -0
- package/dist/supabase/index.js +5 -0
- package/dist/supabase/middleware.d.ts +82 -0
- package/dist/supabase/middleware.js +102 -0
- package/dist/supabase-CwafwxxF.js +83 -0
- package/dist/supabase-DTBaC20O.js +774 -0
- package/dist/supabase-config-Bs44dare.js +472 -0
- package/dist/supabase-hook-BuxLQLpU.js +1814 -0
- package/dist/supabase-hook-D5qVd_D8.js +2 -0
- package/dist/supautils-DYZnzRWV.js +91 -0
- package/dist/svelte/PermissionBoundary.svelte +37 -0
- package/dist/svelte/Protected.svelte +40 -0
- package/dist/svelte/index.d.ts +13 -0
- package/dist/svelte/index.js +107 -0
- package/dist/svelte/runtime.d.ts +7 -0
- package/dist/svelte/runtime.js +4 -0
- package/dist/svelte/source.d.ts +13 -0
- package/dist/svelte/source.js +11 -0
- package/dist/terminal/index.d.ts +163 -0
- package/dist/terminal/index.js +833 -0
- package/dist/testing/index.d.ts +745 -0
- package/dist/testing/index.js +3672 -0
- package/dist/testing/saas/index.d.ts +194 -0
- package/dist/testing/saas/index.js +3 -0
- package/dist/testing/saas/permissions.d.ts +2 -0
- package/dist/testing/saas/permissions.js +2 -0
- package/dist/text-diff-BdkkYSbi.js +15 -0
- package/dist/thenable-okc2xDsj.js +10 -0
- package/dist/timeout-D51niuQP.js +8 -0
- package/dist/token-CIWxJOCh.js +50 -0
- package/dist/trpc/index.d.ts +61 -0
- package/dist/trpc/index.js +122 -0
- package/dist/types-9AWO9EGt.d.ts +197 -0
- package/dist/types-BPxgszlT.d.ts +550 -0
- package/dist/types-BVyImy5I.d.ts +120 -0
- package/dist/types-Bvc4oWT6.d.ts +9 -0
- package/dist/types-C3s9xVJG.d.ts +48 -0
- package/dist/types-Dnemwd77.d.ts +183 -0
- package/dist/types-kxznc7cn.d.ts +52 -0
- package/dist/types-vKyAMtcX.d.ts +157 -0
- package/dist/types-vNSDF7Dq.d.ts +66 -0
- package/dist/types-yF5LmQVD.d.ts +306 -0
- package/dist/unplugin/index.d.ts +7 -0
- package/dist/unplugin/index.js +31 -0
- package/dist/usage-D07N9QJ3.js +42 -0
- package/dist/usage-D82l1CwK.js +2 -0
- package/dist/usage-DG1oeCca.js +693 -0
- package/dist/validation-error-CnjZ4t92.js +33 -0
- package/dist/validation-error-CtF23SrC.d.ts +26 -0
- package/dist/validity-uOp8UpYn.js +245 -0
- package/dist/verifier-BxBo6I44.js +466 -0
- package/dist/version-BvacVTZR.js +17 -0
- package/dist/views-Soe7bGSC.js +95 -0
- package/dist/vocabulary-DA8a8zif.d.ts +56 -0
- package/dist/vue/index.d.ts +79 -0
- package/dist/vue/index.js +196 -0
- package/dist/watch-Etoa_Mvr.js +2 -0
- package/dist/watch-UihESpsJ.js +128 -0
- package/dist/webmcp/index.d.ts +75 -0
- package/dist/webmcp/index.js +307 -0
- package/package.json +450 -5
- package/rulesets/permdock.yaml +29 -0
- package/schemas/approval-request-v1.json +175 -0
- package/schemas/catalog-v1.json +535 -0
- package/schemas/openapi/oas-3.1.json +1298 -0
- package/schemas/openapi/oas-3.2.json +1516 -0
- package/schemas/openapi/overlay-1.1.json +79 -0
- package/schemas/supabase-claims-v1.json +144 -0
- package/schemas/supabase-manifest-v1.json +361 -0
- package/skills/permdock/SKILL.md +66 -0
- package/skills/permdock-agents/SKILL.md +77 -0
- package/skills/permdock-agents/references/runtimes.md +213 -0
- package/skills/permdock-approvals/SKILL.md +80 -0
- package/skills/permdock-approvals/references/stores-and-resume.md +94 -0
- package/skills/permdock-audit/SKILL.md +67 -0
- package/skills/permdock-credentials/SKILL.md +55 -0
- package/skills/permdock-credentials/references/tokens-keys-links.md +132 -0
- package/skills/permdock-data/SKILL.md +57 -0
- package/skills/permdock-data/references/queries-and-rls.md +62 -0
- package/skills/permdock-data/references/relationships.md +67 -0
- package/skills/permdock-tenancy/SKILL.md +80 -0
- package/skills/permdock-tenancy/references/ownership-and-custom-roles.md +89 -0
- package/skills/permdock-wire/SKILL.md +116 -0
- package/skills/permdock-wire/references/adapters.md +492 -0
- package/skills/permdock-wire/references/policy-options.md +45 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { C as Policy, D as PolicyVocabulary, Nr as Principal, kr as Delegation, ln as PermDock } from "../policy-CFZAr_Al.js";
|
|
2
|
+
import { f as Permission } from "../permissions-DttnqqxC.js";
|
|
3
|
+
import { c as ApprovalRequest, f as ApprovalStore } from "../types-vKyAMtcX.js";
|
|
4
|
+
import { t as InstanceOptions } from "../instance-options-BK_rNOSC.js";
|
|
5
|
+
import { t as ToolMap } from "../types-Bvc4oWT6.js";
|
|
6
|
+
//#region src/eve/create.d.ts
|
|
7
|
+
/** Structural `SessionAuthContext` from `eve`. */
|
|
8
|
+
type EvePrincipal = {
|
|
9
|
+
readonly principalId: string;
|
|
10
|
+
readonly principalType?: string;
|
|
11
|
+
readonly authenticator?: string;
|
|
12
|
+
readonly issuer?: string;
|
|
13
|
+
readonly subject?: string;
|
|
14
|
+
readonly attributes?: Readonly<Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
/** Structural `ApprovalContext` from `eve/tools/approval`. */
|
|
17
|
+
type EveApprovalContext = {
|
|
18
|
+
readonly session?: {
|
|
19
|
+
readonly id?: string;
|
|
20
|
+
readonly auth?: {
|
|
21
|
+
readonly initiator?: EvePrincipal | null;
|
|
22
|
+
readonly current?: EvePrincipal | null;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
readonly callId?: string;
|
|
26
|
+
readonly toolName: string;
|
|
27
|
+
readonly toolInput?: unknown;
|
|
28
|
+
};
|
|
29
|
+
/** Structural `ApprovalResponseContext` from `eve/tools/approval`. */
|
|
30
|
+
type EveResponseContext = {
|
|
31
|
+
readonly request: {
|
|
32
|
+
readonly callId: string;
|
|
33
|
+
readonly requestId?: string;
|
|
34
|
+
readonly toolName: string;
|
|
35
|
+
readonly toolInput?: unknown;
|
|
36
|
+
};
|
|
37
|
+
/** Who answered and how; eve settles the request only on `allowed`. */
|
|
38
|
+
readonly response: {
|
|
39
|
+
readonly decision: "approve" | "cancel";
|
|
40
|
+
readonly principal: EvePrincipal;
|
|
41
|
+
};
|
|
42
|
+
readonly session: {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly initiator: EvePrincipal | null;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** What `subject`, `actor` and `tenant` receive. */
|
|
48
|
+
type EveContext = Pick<EveApprovalContext, "session" | "callId">;
|
|
49
|
+
type EveApprovers = {
|
|
50
|
+
readonly roles: readonly string[];
|
|
51
|
+
} | ((responder: EvePrincipal, request: ApprovalRequest) => boolean);
|
|
52
|
+
type EvePermDockOptions<TUser = unknown> = InstanceOptions & {
|
|
53
|
+
readonly subject?: (context: EveContext) => TUser | Promise<TUser>;
|
|
54
|
+
readonly actor?: (context: EveContext) => unknown;
|
|
55
|
+
readonly delegation?: (context: EveContext) => Delegation | undefined | Promise<Delegation | undefined>;
|
|
56
|
+
readonly tenant?: string | ((context: EveContext) => string | undefined | Promise<string | undefined>);
|
|
57
|
+
readonly tools: ToolMap;
|
|
58
|
+
readonly approvers?: EveApprovers;
|
|
59
|
+
readonly store?: ApprovalStore;
|
|
60
|
+
};
|
|
61
|
+
type EveRequestResult = "not-applicable" | "user-approval" | {
|
|
62
|
+
readonly type: "denied";
|
|
63
|
+
readonly reason: string;
|
|
64
|
+
};
|
|
65
|
+
type EveResponseResult = {
|
|
66
|
+
readonly status: "allowed";
|
|
67
|
+
} | {
|
|
68
|
+
readonly status: "rejected";
|
|
69
|
+
readonly reason: string;
|
|
70
|
+
};
|
|
71
|
+
/** An eve `ApprovalConfiguration`: pass it as a tool's `approval`. */
|
|
72
|
+
type EveApprovalPair = {
|
|
73
|
+
readonly request: (ctx: EveApprovalContext) => Promise<EveRequestResult>;
|
|
74
|
+
readonly response: (ctx: EveResponseContext) => Promise<EveResponseResult>;
|
|
75
|
+
};
|
|
76
|
+
type EvePermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
|
|
77
|
+
readonly approval: EveApprovalPair;
|
|
78
|
+
readonly approvalFor: (permission: Permission, data?: (input: unknown) => unknown) => EveApprovalPair;
|
|
79
|
+
readonly permdock: (ctx: EveContext) => Promise<PermDock<V>>;
|
|
80
|
+
};
|
|
81
|
+
export declare function rolesOf(principal: EvePrincipal | null | undefined): string[];
|
|
82
|
+
export declare function subjectFromSession(context: EveContext): unknown;
|
|
83
|
+
export declare function actorFromSession(context: EveContext): unknown;
|
|
84
|
+
export declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: EvePermDockOptions<TUser>): EvePermDock<V>;
|
|
85
|
+
//#endregion
|
|
86
|
+
export type { EveApprovalContext, EveApprovalPair, EveApprovers, EveContext, EvePermDock, EvePermDockOptions, EvePrincipal, EveRequestResult, EveResponseContext, EveResponseResult };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { t as compact } from "../compact-y6vfu2_f.js";
|
|
2
|
+
import { n as isApprovalError } from "../errors-DRnGZHzF.js";
|
|
3
|
+
import { r as memoryApprovalStore } from "../store-DMAWwAJV.js";
|
|
4
|
+
import { o as resolveApproval } from "../helpers-H_KARDVC.js";
|
|
5
|
+
import { t as instanceOptions } from "../instance-options-Dhhcnm3y.js";
|
|
6
|
+
import { n as createAgentKernel } from "../kernel-GSQnMz3O.js";
|
|
7
|
+
import { t as boundedMap } from "../lru-8q4WZjBV.js";
|
|
8
|
+
//#region src/eve/create.ts
|
|
9
|
+
const TOKENS_PER_PROCESS = 1e3;
|
|
10
|
+
function rolesOf(principal) {
|
|
11
|
+
const roles = principal?.attributes?.["roles"];
|
|
12
|
+
if (typeof roles === "string") return [roles];
|
|
13
|
+
if (!Array.isArray(roles)) return [];
|
|
14
|
+
return roles.filter((role) => typeof role === "string");
|
|
15
|
+
}
|
|
16
|
+
function subjectFromSession(context) {
|
|
17
|
+
const initiator = context.session?.auth?.initiator;
|
|
18
|
+
if (initiator === void 0 || initiator === null) return null;
|
|
19
|
+
return {
|
|
20
|
+
id: initiator.principalId,
|
|
21
|
+
roles: rolesOf(initiator)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function actorFromSession(context) {
|
|
25
|
+
const auth = context.session?.auth;
|
|
26
|
+
const initiator = auth?.initiator;
|
|
27
|
+
const current = auth?.current;
|
|
28
|
+
if (current !== void 0 && current !== null && initiator !== void 0 && initiator !== null && current.principalId !== initiator.principalId) return {
|
|
29
|
+
id: current.principalId,
|
|
30
|
+
kind: "eve"
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
id: "eve:app",
|
|
34
|
+
kind: "eve"
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function mapVerdict(verdict) {
|
|
38
|
+
if (verdict.outcome === "granted") return "not-applicable";
|
|
39
|
+
if (verdict.outcome === "approval-required") return "user-approval";
|
|
40
|
+
return {
|
|
41
|
+
type: "denied",
|
|
42
|
+
reason: verdict.reason
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function mayApprove(approvers, responder, request) {
|
|
46
|
+
if (approvers === void 0) return true;
|
|
47
|
+
if (typeof approvers === "function") return approvers(responder, request);
|
|
48
|
+
const held = new Set(rolesOf(responder));
|
|
49
|
+
return approvers.roles.some((role) => held.has(role));
|
|
50
|
+
}
|
|
51
|
+
function callKey(sessionId, callId) {
|
|
52
|
+
return JSON.stringify([sessionId ?? null, callId]);
|
|
53
|
+
}
|
|
54
|
+
function createPermDock(policy, options) {
|
|
55
|
+
const store = options.store ?? memoryApprovalStore();
|
|
56
|
+
const tokensByCall = boundedMap(TOKENS_PER_PROCESS);
|
|
57
|
+
const kernel = createAgentKernel(policy, {
|
|
58
|
+
...compact({
|
|
59
|
+
tenant: options.tenant,
|
|
60
|
+
delegation: options.delegation
|
|
61
|
+
}),
|
|
62
|
+
...instanceOptions(options),
|
|
63
|
+
subject: options.subject ?? subjectFromSession,
|
|
64
|
+
actor: options.actor ?? actorFromSession,
|
|
65
|
+
tools: options.tools,
|
|
66
|
+
store,
|
|
67
|
+
adapter: "eve"
|
|
68
|
+
});
|
|
69
|
+
const approverOf = async (responder, sessionId) => {
|
|
70
|
+
try {
|
|
71
|
+
return (await kernel.instance({ session: {
|
|
72
|
+
id: sessionId,
|
|
73
|
+
auth: {
|
|
74
|
+
initiator: responder,
|
|
75
|
+
current: responder
|
|
76
|
+
}
|
|
77
|
+
} })).subject.principal ?? null;
|
|
78
|
+
} catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const pairFor = (bindingFor) => {
|
|
83
|
+
const request = async (ctx) => {
|
|
84
|
+
const binding = bindingFor(ctx.toolName);
|
|
85
|
+
const verdict = binding === void 0 ? await kernel.decideTool(ctx.toolName, ctx.toolInput, ctx) : await kernel.evaluate(binding, ctx.toolName, ctx.toolInput, ctx, { denyPending: true });
|
|
86
|
+
if (verdict.outcome === "approval-required" && ctx.callId !== void 0) tokensByCall.set(callKey(ctx.session?.id, ctx.callId), verdict.token);
|
|
87
|
+
return mapVerdict(verdict);
|
|
88
|
+
};
|
|
89
|
+
const tokenOf = (ctx) => {
|
|
90
|
+
const cached = tokensByCall.get(callKey(ctx.session.id, ctx.request.callId));
|
|
91
|
+
if (cached !== void 0) return Promise.resolve(cached);
|
|
92
|
+
const binding = bindingFor(ctx.request.toolName);
|
|
93
|
+
if (binding === void 0) return Promise.resolve(void 0);
|
|
94
|
+
const initiator = ctx.session.initiator;
|
|
95
|
+
return kernel.tokenFor(binding, ctx.request.toolInput, {
|
|
96
|
+
session: {
|
|
97
|
+
id: ctx.session.id,
|
|
98
|
+
auth: {
|
|
99
|
+
initiator,
|
|
100
|
+
current: initiator
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
callId: ctx.request.callId
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const response = async (ctx) => {
|
|
107
|
+
const token = await tokenOf(ctx);
|
|
108
|
+
if (token === void 0) return {
|
|
109
|
+
status: "rejected",
|
|
110
|
+
reason: "approval-not-found"
|
|
111
|
+
};
|
|
112
|
+
let current;
|
|
113
|
+
try {
|
|
114
|
+
current = await store.get(token);
|
|
115
|
+
} catch {
|
|
116
|
+
current = null;
|
|
117
|
+
}
|
|
118
|
+
if (current === null) return {
|
|
119
|
+
status: "rejected",
|
|
120
|
+
reason: "approval-not-found"
|
|
121
|
+
};
|
|
122
|
+
const responder = ctx.response.principal;
|
|
123
|
+
if (current.subject.actor?.id === responder.principalId) return {
|
|
124
|
+
status: "rejected",
|
|
125
|
+
reason: "approver is the actor of this request"
|
|
126
|
+
};
|
|
127
|
+
if (!mayApprove(options.approvers, responder, current)) return {
|
|
128
|
+
status: "rejected",
|
|
129
|
+
reason: "approver is not eligible"
|
|
130
|
+
};
|
|
131
|
+
const approver = await approverOf(responder, ctx.session.id);
|
|
132
|
+
if (approver === null) return {
|
|
133
|
+
status: "rejected",
|
|
134
|
+
reason: "approver is not eligible"
|
|
135
|
+
};
|
|
136
|
+
try {
|
|
137
|
+
await resolveApproval(store, token, {
|
|
138
|
+
status: ctx.response.decision === "approve" ? "approved" : "rejected",
|
|
139
|
+
by: {
|
|
140
|
+
principal: approver,
|
|
141
|
+
context: {}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return { status: "allowed" };
|
|
145
|
+
} catch (error) {
|
|
146
|
+
if (isApprovalError(error)) return {
|
|
147
|
+
status: "rejected",
|
|
148
|
+
reason: error.message
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
status: "rejected",
|
|
152
|
+
reason: "approval-not-found"
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
request,
|
|
158
|
+
response
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const approval = pairFor((toolName) => Object.hasOwn(options.tools, toolName) ? options.tools[toolName] : void 0);
|
|
162
|
+
const approvalFor = (permission, data) => {
|
|
163
|
+
const binding = compact({
|
|
164
|
+
permission,
|
|
165
|
+
data
|
|
166
|
+
});
|
|
167
|
+
return pairFor(() => binding);
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
approval,
|
|
171
|
+
approvalFor,
|
|
172
|
+
permdock: (ctx) => kernel.instance(ctx)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
export { actorFromSession, createPermDock, rolesOf, subjectFromSession };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { C as Policy, D as PolicyVocabulary, Nr as Principal, ln as PermDock } from "../policy-CFZAr_Al.js";
|
|
2
|
+
import { f as Permission } from "../permissions-DttnqqxC.js";
|
|
3
|
+
import { h as InvalidSignatureError, i as ProtectOptions, n as OpenApiHooks, w as verifyWebBotAuth, x as discoverViaSignatureAgent } from "../create-BWyx3jua.js";
|
|
4
|
+
import { t as ServerAdapterOptions } from "../bind-CVy3Espv.js";
|
|
5
|
+
import { a as toRequest, i as sendResponse } from "../http-DPuDaChb.js";
|
|
6
|
+
import { ErrorRequestHandler, Request, RequestHandler, Response, Router } from "express";
|
|
7
|
+
//#region src/express/create.d.ts
|
|
8
|
+
type ExpressPermDockOptions<TUser = unknown> = ServerAdapterOptions<Request, TUser>;
|
|
9
|
+
type PermDockRequest<T = unknown, V extends PolicyVocabulary = PolicyVocabulary> = Request & {
|
|
10
|
+
permdock: PermDock<V>;
|
|
11
|
+
permdockData?: T;
|
|
12
|
+
};
|
|
13
|
+
type ExpressPermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
|
|
14
|
+
readonly permdock: () => RequestHandler;
|
|
15
|
+
readonly protect: (permission: Permission | null, loadData?: (req: Request) => unknown, protectOptions?: ProtectOptions) => RequestHandler;
|
|
16
|
+
readonly errorHandler: () => ErrorRequestHandler;
|
|
17
|
+
readonly permdockHandler: () => Router;
|
|
18
|
+
readonly withPermDock: (fn: (req: PermDockRequest<unknown, V>, res: Response) => unknown) => RequestHandler;
|
|
19
|
+
readonly openapi: OpenApiHooks;
|
|
20
|
+
};
|
|
21
|
+
export declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: ExpressPermDockOptions<TUser>): ExpressPermDock<V>;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { type ExpressPermDock, type ExpressPermDockOptions, InvalidSignatureError, type PermDockRequest, discoverViaSignatureAgent, sendResponse, toRequest, verifyWebBotAuth };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { i as discoverViaSignatureAgent, r as InvalidSignatureError, s as verifyWebBotAuth } from "../evaluations-tz6D9A2G.js";
|
|
2
|
+
import { t as problemFromError } from "../map-error-pgUWNNtG.js";
|
|
3
|
+
import { i as decorate, r as bindKernel } from "../bind-VnYn2HKq.js";
|
|
4
|
+
import { i as toRequest, r as sendResponse } from "../http-BIhmLfCc.js";
|
|
5
|
+
import express from "express";
|
|
6
|
+
//#region src/express/create.ts
|
|
7
|
+
function run(work, next) {
|
|
8
|
+
work().catch(next);
|
|
9
|
+
}
|
|
10
|
+
function sendProblem(err, req, res, next) {
|
|
11
|
+
const problem = problemFromError(err, { credentials: req.headers.authorization !== void 0 });
|
|
12
|
+
if (problem === void 0) {
|
|
13
|
+
next(err);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
run(async () => {
|
|
17
|
+
await sendResponse(res, problem);
|
|
18
|
+
}, next);
|
|
19
|
+
}
|
|
20
|
+
/** Answers a PermDock error with Problem Details; anything else reaches the app's error middleware. */
|
|
21
|
+
function respond(req, res, next, work) {
|
|
22
|
+
work().catch((err) => {
|
|
23
|
+
sendProblem(err, req, res, next);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const errorHandler = () => (err, req, res, next) => {
|
|
27
|
+
sendProblem(err, req, res, next);
|
|
28
|
+
};
|
|
29
|
+
const withPermDock = (fn) => (req, res, next) => {
|
|
30
|
+
run(async () => {
|
|
31
|
+
await fn(req, res);
|
|
32
|
+
}, next);
|
|
33
|
+
};
|
|
34
|
+
function createPermDock(policy, options) {
|
|
35
|
+
const { kernel, bind, rebind, scopeOf, handlerScope } = bindKernel(policy, options, "express", toRequest);
|
|
36
|
+
const permdock = () => (req, res, next) => {
|
|
37
|
+
respond(req, res, next, async () => {
|
|
38
|
+
decorate(req, await kernel.permdock(bind(req), await scopeOf(req)));
|
|
39
|
+
next();
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
const protect = (permission, loadData, protectOptions) => (req, res, next) => {
|
|
43
|
+
respond(req, res, next, async () => {
|
|
44
|
+
const guard = await kernel.protect(permission, loadData === void 0 ? void 0 : () => loadData(req), protectOptions)(bind(req), await scopeOf(req));
|
|
45
|
+
if (!guard.ok) {
|
|
46
|
+
await sendResponse(res, guard.response);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
decorate(req, guard.permdock, guard.data);
|
|
50
|
+
next();
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const permdockHandler = () => {
|
|
54
|
+
const { POST, GET } = kernel.permdockHandler(handlerScope);
|
|
55
|
+
const router = express.Router({ mergeParams: true });
|
|
56
|
+
router.post("/", (req, res, next) => {
|
|
57
|
+
respond(req, res, next, async () => {
|
|
58
|
+
await sendResponse(res, await POST(rebind(req)));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
router.get("/", (req, res, next) => {
|
|
62
|
+
respond(req, res, next, async () => {
|
|
63
|
+
await sendResponse(res, await GET(bind(req)));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
return router;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
permdock,
|
|
70
|
+
protect,
|
|
71
|
+
errorHandler,
|
|
72
|
+
permdockHandler,
|
|
73
|
+
withPermDock,
|
|
74
|
+
openapi: kernel.openapi
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { InvalidSignatureError, createPermDock, discoverViaSignatureAgent, sendResponse, toRequest, verifyWebBotAuth };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { C as Policy, D as PolicyVocabulary, Nr as Principal, ln as PermDock } from "../policy-CFZAr_Al.js";
|
|
2
|
+
import { f as Permission } from "../permissions-DttnqqxC.js";
|
|
3
|
+
import { h as InvalidSignatureError, i as ProtectOptions, n as OpenApiHooks, w as verifyWebBotAuth, x as discoverViaSignatureAgent } from "../create-BWyx3jua.js";
|
|
4
|
+
import { t as ServerAdapterOptions } from "../bind-CVy3Espv.js";
|
|
5
|
+
import { FastifyPluginAsync, FastifyReply, FastifyRequest, FastifySchema, FastifyTypeProvider, FastifyTypeProviderDefault, RawRequestDefaultExpression, RawServerDefault, RouteGenericInterface } from "fastify";
|
|
6
|
+
//#region src/fastify/create.d.ts
|
|
7
|
+
type FastifyPermDockOptions<TUser = unknown> = ServerAdapterOptions<FastifyRequest, TUser>;
|
|
8
|
+
type PermDockRequest<Route extends RouteGenericInterface = RouteGenericInterface, V extends PolicyVocabulary = PolicyVocabulary> = FastifyRequest<Route> & {
|
|
9
|
+
permdock: PermDock<V>;
|
|
10
|
+
permdockData?: unknown;
|
|
11
|
+
};
|
|
12
|
+
/** A request typed by the route, its schema and the app's type provider. */
|
|
13
|
+
type ProtectRequest<Route extends RouteGenericInterface = RouteGenericInterface, Schema extends FastifySchema = FastifySchema, Provider extends FastifyTypeProvider = FastifyTypeProviderDefault> = FastifyRequest<Route, RawServerDefault, RawRequestDefaultExpression, Schema, Provider>;
|
|
14
|
+
/**
|
|
15
|
+
* Generic over the route, schema and type provider so a `preHandler` slot
|
|
16
|
+
* infers them: `loadData` sees the same typed `request.body` as the handler.
|
|
17
|
+
*/
|
|
18
|
+
type FastifyProtect = <Route extends RouteGenericInterface = RouteGenericInterface, Schema extends FastifySchema = FastifySchema, Provider extends FastifyTypeProvider = FastifyTypeProviderDefault>(permission: Permission | null, loadData?: (request: ProtectRequest<Route, Schema, Provider>) => unknown, protectOptions?: ProtectOptions) => (request: ProtectRequest<Route, Schema, Provider>, reply: FastifyReply) => Promise<void>;
|
|
19
|
+
type FastifyPermDock<V extends PolicyVocabulary = PolicyVocabulary> = {
|
|
20
|
+
readonly permdock: FastifyPluginAsync;
|
|
21
|
+
readonly protect: FastifyProtect;
|
|
22
|
+
readonly permdockHandler: FastifyPluginAsync;
|
|
23
|
+
/** Types `request.permdock` for a route registered after `permdock` or `protect`. */
|
|
24
|
+
readonly withPermDock: <Route extends RouteGenericInterface = RouteGenericInterface>(fn: (request: PermDockRequest<Route, V>, reply: FastifyReply) => unknown) => (request: FastifyRequest<Route>, reply: FastifyReply) => unknown;
|
|
25
|
+
readonly openapi: OpenApiHooks;
|
|
26
|
+
};
|
|
27
|
+
export declare function createPermDock<TUser, TPrincipal extends Principal = Principal, V extends PolicyVocabulary = PolicyVocabulary>(policy: Policy<TUser, TPrincipal, V>, options: FastifyPermDockOptions<TUser>): FastifyPermDock<V>;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/fastify/http.d.ts
|
|
30
|
+
export declare function toRequest(request: FastifyRequest): Request;
|
|
31
|
+
export declare function sendReply(reply: FastifyReply, response: Response): Promise<void>;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { type FastifyPermDock, type FastifyPermDockOptions, type FastifyProtect, InvalidSignatureError, type PermDockRequest, discoverViaSignatureAgent, verifyWebBotAuth };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { i as parsedBody, r as headersFrom, t as firstHeader } from "../http-SO7qGttf.js";
|
|
2
|
+
import { i as discoverViaSignatureAgent, r as InvalidSignatureError, s as verifyWebBotAuth } from "../evaluations-tz6D9A2G.js";
|
|
3
|
+
import { t as problemFromError } from "../map-error-pgUWNNtG.js";
|
|
4
|
+
import { i as decorate, r as bindKernel } from "../bind-VnYn2HKq.js";
|
|
5
|
+
//#region src/fastify/http.ts
|
|
6
|
+
function toRequest(request) {
|
|
7
|
+
const host = firstHeader(request.headers.host) ?? "localhost";
|
|
8
|
+
const url = `${request.protocol}://${host}${request.url}`;
|
|
9
|
+
const headers = headersFrom(request.headers);
|
|
10
|
+
const method = request.method;
|
|
11
|
+
if (method === "GET" || method === "HEAD") return new Request(url, {
|
|
12
|
+
method,
|
|
13
|
+
headers
|
|
14
|
+
});
|
|
15
|
+
const body = parsedBody(request.body, headers);
|
|
16
|
+
if (body === void 0) return new Request(url, {
|
|
17
|
+
method,
|
|
18
|
+
headers
|
|
19
|
+
});
|
|
20
|
+
return new Request(url, {
|
|
21
|
+
method,
|
|
22
|
+
headers,
|
|
23
|
+
body
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async function sendReply(reply, response) {
|
|
27
|
+
reply.code(response.status);
|
|
28
|
+
for (const [key, value] of response.headers.entries()) reply.header(key, value);
|
|
29
|
+
await reply.send(await response.text());
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/fastify/create.ts
|
|
33
|
+
const SKIP_OVERRIDE = Symbol.for("skip-override");
|
|
34
|
+
function breakEncapsulation(plugin) {
|
|
35
|
+
Object.defineProperty(plugin, SKIP_OVERRIDE, { value: true });
|
|
36
|
+
return plugin;
|
|
37
|
+
}
|
|
38
|
+
/** A route registered with `config: { permdock: false }`, such as a health check, gets no instance. */
|
|
39
|
+
function skipped(request) {
|
|
40
|
+
const config = request.routeOptions.config;
|
|
41
|
+
return typeof config === "object" && config !== null && Reflect.get(config, "permdock") === false;
|
|
42
|
+
}
|
|
43
|
+
function createPermDock(policy, options) {
|
|
44
|
+
const { kernel, bind, rebind, scopeOf, handlerScope } = bindKernel(policy, options, "fastify", toRequest);
|
|
45
|
+
const permdock = breakEncapsulation((app) => {
|
|
46
|
+
app.decorateRequest("permdock", null);
|
|
47
|
+
app.decorateRequest("permdockData", null);
|
|
48
|
+
app.addHook("onRequest", async (request) => {
|
|
49
|
+
if (skipped(request)) return;
|
|
50
|
+
decorate(request, await kernel.permdock(bind(request), await scopeOf(request)));
|
|
51
|
+
});
|
|
52
|
+
const previous = app.errorHandler;
|
|
53
|
+
app.setErrorHandler(async function permdockErrors(err, request, reply) {
|
|
54
|
+
const problem = problemFromError(err, { credentials: request.headers.authorization !== void 0 });
|
|
55
|
+
if (problem === void 0) {
|
|
56
|
+
await previous.call(this, err, request, reply);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
await sendReply(reply, problem);
|
|
60
|
+
});
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
});
|
|
63
|
+
const protect = (permission, loadData, protectOptions) => async (request, reply) => {
|
|
64
|
+
const plain = request;
|
|
65
|
+
const guard = await kernel.protect(permission, loadData === void 0 ? void 0 : () => loadData(request), protectOptions)(bind(plain), await scopeOf(plain));
|
|
66
|
+
if (!guard.ok) {
|
|
67
|
+
await sendReply(reply, guard.response);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
decorate(plain, guard.permdock, guard.data);
|
|
71
|
+
};
|
|
72
|
+
const permdockHandler = (app) => {
|
|
73
|
+
const { POST, GET } = kernel.permdockHandler(handlerScope);
|
|
74
|
+
app.post("/", async (request, reply) => {
|
|
75
|
+
await sendReply(reply, await POST(rebind(request)));
|
|
76
|
+
});
|
|
77
|
+
app.get("/", async (request, reply) => {
|
|
78
|
+
await sendReply(reply, await GET(bind(request)));
|
|
79
|
+
});
|
|
80
|
+
return Promise.resolve();
|
|
81
|
+
};
|
|
82
|
+
const withPermDock = (fn) => (request, reply) => fn(request, reply);
|
|
83
|
+
return {
|
|
84
|
+
permdock,
|
|
85
|
+
protect,
|
|
86
|
+
permdockHandler,
|
|
87
|
+
withPermDock,
|
|
88
|
+
openapi: kernel.openapi
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
export { InvalidSignatureError, createPermDock, discoverViaSignatureAgent, sendReply, toRequest, verifyWebBotAuth };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { n as freezeDeep } from "./freeze-CrU8nQeX.js";
|
|
2
|
+
import { D as ownKeys, E as ownGet, T as isForbiddenKey } from "./permissions-DVoF6dMt.js";
|
|
3
|
+
//#region src/core/fields.ts
|
|
4
|
+
function sanitizeFields(fields) {
|
|
5
|
+
if (fields === void 0) return;
|
|
6
|
+
return fields.filter((field) => field.length > 0 && !isForbiddenKey(field));
|
|
7
|
+
}
|
|
8
|
+
function grantCoversField(fields, field, effect) {
|
|
9
|
+
if (fields === void 0) return true;
|
|
10
|
+
if (fields.length === 0) return false;
|
|
11
|
+
if (field === void 0) return effect === "allow";
|
|
12
|
+
return fields.includes(field);
|
|
13
|
+
}
|
|
14
|
+
function pickVisible(row, canField) {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const key of ownKeys(row)) if (canField(key)) out[key] = ownGet(row, key);
|
|
17
|
+
return freezeDeep(out);
|
|
18
|
+
}
|
|
19
|
+
function sanitizeContext(value) {
|
|
20
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return {};
|
|
21
|
+
const out = {};
|
|
22
|
+
for (const key of ownKeys(value)) out[key] = ownGet(value, key);
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { sanitizeFields as i, pickVisible as n, sanitizeContext as r, grantCoversField as t };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { existsSync, globSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, extname, join, relative, resolve } from "node:path";
|
|
3
|
+
//#region src/cli/files.ts
|
|
4
|
+
const SOURCE_EXT = /* @__PURE__ */ new Set([
|
|
5
|
+
".ts",
|
|
6
|
+
".tsx",
|
|
7
|
+
".js",
|
|
8
|
+
".jsx",
|
|
9
|
+
".mts",
|
|
10
|
+
".cts"
|
|
11
|
+
]);
|
|
12
|
+
const SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
13
|
+
"node_modules",
|
|
14
|
+
"dist",
|
|
15
|
+
".next",
|
|
16
|
+
".turbo",
|
|
17
|
+
"coverage",
|
|
18
|
+
".git"
|
|
19
|
+
]);
|
|
20
|
+
const PACKAGE_SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git"]);
|
|
21
|
+
function listSourceFiles(cwd, srcPath) {
|
|
22
|
+
const out = /* @__PURE__ */ new Set();
|
|
23
|
+
for (const entry of srcPath) {
|
|
24
|
+
if (/[*?[{]/u.test(entry)) {
|
|
25
|
+
collectGlob(cwd, entry, out);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
collectRoot(resolve(cwd, entry), out, skipDirsFor(entry));
|
|
29
|
+
}
|
|
30
|
+
const byRealPath = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const file of [...out].toSorted()) {
|
|
32
|
+
const real = realPath(file);
|
|
33
|
+
if (!byRealPath.has(real)) byRealPath.set(real, file);
|
|
34
|
+
}
|
|
35
|
+
return [...byRealPath.values()].toSorted();
|
|
36
|
+
}
|
|
37
|
+
function segments(path) {
|
|
38
|
+
return path.split(/[\\/]/u).filter((part) => part !== "" && part !== ".");
|
|
39
|
+
}
|
|
40
|
+
/** Installed packages often ship only `dist`; their own dependencies are never walked. */
|
|
41
|
+
function skipDirsFor(path) {
|
|
42
|
+
return segments(path).includes("node_modules") ? PACKAGE_SKIP_DIRS : SKIP_DIRS;
|
|
43
|
+
}
|
|
44
|
+
function realPath(file) {
|
|
45
|
+
try {
|
|
46
|
+
return realpathSync(file);
|
|
47
|
+
} catch {
|
|
48
|
+
return file;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function collectGlob(cwd, pattern, out) {
|
|
52
|
+
const literal = segments(pattern);
|
|
53
|
+
const matches = globSync(pattern, {
|
|
54
|
+
cwd,
|
|
55
|
+
exclude: (path) => {
|
|
56
|
+
const parts = segments(path);
|
|
57
|
+
const name = basename(path);
|
|
58
|
+
return SKIP_DIRS.has(name) && literal[parts.length - 1] !== name;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
for (const match of matches) collectRoot(resolve(cwd, match), out, skipDirsFor(match));
|
|
62
|
+
}
|
|
63
|
+
function collectRoot(root, out, skip) {
|
|
64
|
+
if (!existsSync(root)) return;
|
|
65
|
+
if (statSync(root).isFile()) {
|
|
66
|
+
if (SOURCE_EXT.has(extname(root))) out.add(root);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
walkDir(root, out, skip);
|
|
70
|
+
}
|
|
71
|
+
function walkDir(dir, out, skip) {
|
|
72
|
+
for (const name of readdirSync(dir)) {
|
|
73
|
+
if (name.startsWith(".") && name !== ".agents") continue;
|
|
74
|
+
if (skip.has(name)) continue;
|
|
75
|
+
const full = join(dir, name);
|
|
76
|
+
const stats = statSync(full, { throwIfNoEntry: false });
|
|
77
|
+
if (stats === void 0) continue;
|
|
78
|
+
if (stats.isDirectory()) {
|
|
79
|
+
walkDir(full, out, skip);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (SOURCE_EXT.has(extname(name)) && !name.endsWith(".generated.ts")) out.add(full);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The `.sql` files under each entry: a glob, a file, or a directory searched
|
|
87
|
+
* recursively. `order: 'entry'` keeps each entry's matches together in entry
|
|
88
|
+
* order (how `supabase db diff` reads `schema_paths`); the default sorts all paths.
|
|
89
|
+
*/
|
|
90
|
+
function sqlFiles(cwd, entries, options = {}) {
|
|
91
|
+
const seen = /* @__PURE__ */ new Set();
|
|
92
|
+
const ordered = [];
|
|
93
|
+
for (const entry of entries) {
|
|
94
|
+
const abs = resolve(cwd, entry);
|
|
95
|
+
const isGlob = /[*?[{]/u.test(entry);
|
|
96
|
+
if (!isGlob && statSync(abs, { throwIfNoEntry: false })?.isFile()) {
|
|
97
|
+
if (!seen.has(abs)) {
|
|
98
|
+
seen.add(abs);
|
|
99
|
+
ordered.push(abs);
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const pattern = isGlob ? entry : `${entry}/**/*.sql`;
|
|
104
|
+
for (const match of globSync(pattern, { cwd }).toSorted()) {
|
|
105
|
+
const path = resolve(cwd, match);
|
|
106
|
+
if (path.endsWith(".sql") && !seen.has(path)) {
|
|
107
|
+
seen.add(path);
|
|
108
|
+
ordered.push(path);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return options.order === "entry" ? ordered : ordered.toSorted();
|
|
113
|
+
}
|
|
114
|
+
function rel(cwd, abs) {
|
|
115
|
+
return relative(cwd, abs).split("\\").join("/");
|
|
116
|
+
}
|
|
117
|
+
function defaultSrcPath() {
|
|
118
|
+
return ["./src"];
|
|
119
|
+
}
|
|
120
|
+
/** Where `doctor` reads source files: `doctor.srcPath`, else `collect.srcPath`, else `./src`. */
|
|
121
|
+
function doctorSrcPath(config) {
|
|
122
|
+
return config.doctor?.srcPath ?? config.collect?.srcPath ?? defaultSrcPath();
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { sqlFiles as a, rel as i, doctorSrcPath as n, listSourceFiles as r, defaultSrcPath as t };
|