@classytic/arc 2.50.0 → 2.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{EventTransport-B18mcj_M.mjs → EventTransport-DeNze_-C.mjs} +2 -2
- package/dist/{HookSystem-FUBaLTRm.mjs → HookSystem-DTffXM1X.mjs} +2 -2
- package/dist/{ResourceRegistry-C5NM07fZ.mjs → ResourceRegistry-tlqXSZoK.mjs} +2 -2
- package/dist/{acquire-MHCnbDtH.mjs → acquire-7JKEkKnN.mjs} +1 -1
- package/dist/audit/index.mjs +4 -4
- package/dist/auth/audit.mjs +1 -1
- package/dist/auth/index.d.mts +30 -0
- package/dist/auth/index.mjs +172 -32
- package/dist/auth/redis-session.mjs +1 -1
- package/dist/auth/social/index.d.mts +42 -0
- package/dist/auth/social/index.mjs +311 -0
- package/dist/{authorizationDecision-BD8K4jdQ.mjs → authorizationDecision-DKmH4tZ-.mjs} +9 -7
- package/dist/{boundedMap-CuCwos_X.mjs → boundedMap-zxGBpXX0.mjs} +1 -1
- package/dist/{buildHandler-BttjNkTM.mjs → buildHandler-ZDV6LRZ_.mjs} +5 -5
- package/dist/cache/index.mjs +4 -4
- package/dist/{caching-CxUQLHfR.mjs → caching-DceUN9Xk.mjs} +2 -2
- package/dist/{claimed-CQ4ZpD8K.mjs → claimed-DsP5Hi_f.mjs} +1 -1
- package/dist/cleanup/index.mjs +4 -4
- package/dist/cli/commands/describe.mjs +3 -3
- package/dist/cli/commands/docs.mjs +3 -3
- package/dist/cli/commands/doctor.mjs +1 -1
- 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-BZFsZwJh.mjs → constants-Ca2IQFy2.mjs} +1 -1
- package/dist/context/index.mjs +5 -5
- package/dist/core/index.d.mts +1 -1
- package/dist/core/index.mjs +7 -7
- package/dist/{core-DWA1-5IE.mjs → core-M18RhMqi.mjs} +3 -3
- package/dist/{createActionRouter-fP3l2xVF.mjs → createActionRouter-zXlrwWVs.mjs} +5 -5
- package/dist/{createAggregationRouter-BJZeOmBa.mjs → createAggregationRouter-CN0Da9nC.mjs} +7 -7
- package/dist/{createApp-Db9JRumw.mjs → createApp-BC67ACu4.mjs} +29 -29
- package/dist/{defineAggregation-BskqRz8M.mjs → defineAggregation-DqAGb5oI.mjs} +1 -1
- package/dist/{defineResource-B2vTvKzW.mjs → defineResource-DC5UqkQv.mjs} +8 -8
- package/dist/discovery/index.mjs +1 -1
- package/dist/docs/index.mjs +3 -3
- package/dist/{elevation-XoY0C73T.mjs → elevation-DiXVg98q.mjs} +5 -5
- package/dist/encryption/index.d.mts +26 -1
- package/dist/encryption/index.mjs +56 -6
- package/dist/{errorHandler-BYI-JQMm.mjs → errorHandler-BUTm9P_f.mjs} +3 -3
- package/dist/{errors-3xaK0i9n.mjs → errors-DxpHZBlW.mjs} +1 -1
- package/dist/{eventPlugin-CVQ9ddnL.mjs → eventPlugin-ZsIQPRso.mjs} +8 -8
- package/dist/{eventTypes-UPYg7gW1.mjs → eventTypes-D-pFtqT1.mjs} +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 +4 -4
- package/dist/factory/index.mjs +7 -7
- package/dist/{fastify-augmentation-baQc3MaO.d.mts → fastify-augmentation-CPReFhZ1.d.mts} +1 -1
- package/dist/{fieldTypes-CxRvCaaZ.mjs → fieldTypes-f-3TZgR3.mjs} +2 -2
- package/dist/{fields-DLFcJiDe.mjs → fields-kCbIDTjA.mjs} +1 -1
- package/dist/{filter-merge-Bvjk_8dV.mjs → filter-merge-UJCgjbZR.mjs} +1 -1
- package/dist/{generate-0OpCUjUv.mjs → generate-CLpmzbJ_.mjs} +2 -2
- package/dist/{headers-BROW65-r.mjs → headers-Bh47h0XH.mjs} +2 -2
- package/dist/{health-Cy6aOg1i.mjs → health-CEpgVAl7.mjs} +1 -1
- package/dist/{health-Cfh-kYI_.mjs → health-W4S2yFBL.mjs} +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.mjs +7 -7
- package/dist/idempotency/redis.mjs +2 -2
- package/dist/{index-DexdFs1a.d.mts → index-CSbDhif4.d.mts} +19 -1
- package/dist/{index-DKM2p5w5.d.mts → index-DCH08eqQ.d.mts} +1 -1
- package/dist/{index-Dhrks-hM.d.mts → index-yXXCsKl7.d.mts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +11 -11
- package/dist/{init-D7PQcvvL.mjs → init-B43DXBpc.mjs} +22 -22
- package/dist/integrations/event-gateway.mjs +2 -2
- package/dist/integrations/index.mjs +1 -1
- package/dist/integrations/jobs/index.mjs +3 -3
- package/dist/integrations/mcp/index.mjs +2 -2
- package/dist/integrations/mcp/testing.mjs +2 -2
- package/dist/integrations/streamline.mjs +3 -3
- 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/{jsonBody-C0oREwUc.mjs → jsonBody-CkKs6dA_.mjs} +2 -2
- package/dist/{keys-CGlPoVSn.mjs → keys-DHrHnT0f.mjs} +1 -1
- package/dist/{loadResources-Oi47dogA.mjs → loadResources-CFdzAWQZ.mjs} +3 -3
- package/dist/{loadResourcesFromEntry-BW-LexBz.mjs → loadResourcesFromEntry-DkoSiJsI.mjs} +2 -2
- package/dist/logger/index.mjs +2 -2
- package/dist/{logger-BagW7_YA.mjs → logger-DJwz_-Pl.mjs} +1 -1
- package/dist/{mcpPlugin-C6-wFsOX.mjs → mcpPlugin-CA_MDFlS.mjs} +21 -21
- package/dist/{memory-Bl7kv6TS.mjs → memory-B9CFHbA_.mjs} +3 -3
- package/dist/{metrics-CqnMJKrJ.mjs → metrics-DSKv-T9K.mjs} +3 -3
- package/dist/middleware/index.mjs +3 -3
- package/dist/migrations/index.mjs +2 -2
- package/dist/{module-lbEbHUfI.mjs → module-C0JCsnO7.mjs} +17 -2
- package/dist/{multipartBody-CqNezaB3.mjs → multipartBody-Bxz-q6hI.mjs} +1 -1
- package/dist/{observeSend-BjilzlYl.mjs → observeSend-DfNkdGww.mjs} +1 -1
- package/dist/{openapi-DXNbadgd.mjs → openapi-Dmp7Ipsi.mjs} +6 -6
- package/dist/outbox-admin/index.mjs +5 -5
- package/dist/{outbox-module-k5rIszQ4.mjs → outbox-module-vT6PaThj.mjs} +7 -7
- package/dist/permissions/index.mjs +7 -7
- package/dist/{permissions-BJylQopQ.mjs → permissions-Cga6KBOX.mjs} +9 -9
- package/dist/{pipe-D1cq8hET.mjs → pipe-CqPweKdL.mjs} +2 -2
- package/dist/pipeline/index.mjs +2 -2
- package/dist/{plan-iEgaS5_H.mjs → plan-CbDTFbTj.mjs} +1 -1
- package/dist/{plugin-DsLr6L4O.mjs → plugin-8Z1khbAI.mjs} +24 -24
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.mjs +18 -18
- package/dist/plugins/response-cache.mjs +4 -4
- package/dist/plugins/tracing-entry.mjs +2 -2
- package/dist/{pluralize-CX4ZvwCa.mjs → pluralize-D4vcPLVs.mjs} +1 -1
- package/dist/presets/filesUpload.mjs +5 -5
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.mjs +5 -5
- package/dist/presets/search.mjs +2 -2
- package/dist/{presets-D_suT4OY.mjs → presets-D28IABZe.mjs} +4 -4
- package/dist/{projection-CmjGjFih.mjs → projection-aHCtDQQ9.mjs} +2 -2
- package/dist/{purger.types-CZwkTZ7B.mjs → purger.types-CNFmEtFu.mjs} +1 -1
- package/dist/{queryCachePlugin-BDOPEAmH.mjs → queryCachePlugin-CwpEjCwz.mjs} +6 -6
- package/dist/{rateLimitKey-igF1x64n.mjs → rateLimitKey-D9dl3FQn.mjs} +1 -1
- package/dist/{realtime-Cq_ugiWw.mjs → realtime-Dvu8ES2z.mjs} +11 -11
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +3 -3
- package/dist/{registry-DmF9Akvn.mjs → registry-DmxbzW7-.mjs} +2 -2
- package/dist/{relay-DA89IhFt.mjs → relay-CEaCmUfG.mjs} +5 -5
- package/dist/{renewingLease-DBtGUt8T.mjs → renewingLease-g2FjB3im.mjs} +1 -1
- package/dist/{replyHelpers-CUbeUc5q.mjs → replyHelpers-CSByAX_Z.mjs} +2 -2
- package/dist/{requestContext-DO9Qv0gw.mjs → requestContext-yc7MSgmq.mjs} +1 -1
- package/dist/{requirement-C3GaQmkR.mjs → requirement-Dm8njSoC.mjs} +1 -1
- package/dist/{resourceRateLimit-KKn-sFhb.mjs → resourceRateLimit-PQaY3HW1.mjs} +2 -2
- package/dist/{rolldown-runtime-Ck1Tj4Ax.mjs → rolldown-runtime-BBBkGgwA.mjs} +1 -1
- package/dist/{routeValidator-BF7n34xV.mjs → routeValidator-fuG51bQA.mjs} +1 -1
- package/dist/{runtimeCapabilities-D0A4kkrC.mjs → runtimeCapabilities-B8IT7xiQ.mjs} +1 -1
- package/dist/{schedules-CLrQRSTt.mjs → schedules-0-aS4jDV.mjs} +5 -5
- package/dist/{schemaConverter-JEmU21fu.mjs → schemaConverter-Cs3SwP4R.mjs} +2 -2
- package/dist/{schemaIR-wOffQlbq.mjs → schemaIR-By8XiNeE.mjs} +14 -14
- package/dist/schemas/index.mjs +1 -1
- package/dist/scim/index.mjs +2 -2
- package/dist/scope/index.mjs +5 -5
- package/dist/{scope-CcTMRd7s.mjs → scope-BWNAlBj0.mjs} +4 -4
- package/dist/{shutdown-BIR-QBYM.mjs → shutdown-Cf-27xsS.mjs} +1 -1
- package/dist/{simpleEqualityMatcher-DqqJqovq.mjs → simpleEqualityMatcher-e-dgJcUO.mjs} +1 -1
- package/dist/{sse-OEuPpgss.mjs → sse-C3bj5qWi.mjs} +7 -7
- package/dist/{sseStream-DknHE2K5.mjs → sseStream-BYZbpFDa.mjs} +2 -2
- package/dist/{store-helpers-D4vtEXt2.mjs → store-helpers-B9HierHY.mjs} +1 -1
- package/dist/{streaming-CcIpcx02.mjs → streaming-EN8NJWxr.mjs} +1 -1
- package/dist/{subscriberIdentity-PO6kimAl.mjs → subscriberIdentity-DSqCh38x.mjs} +1 -1
- package/dist/{tenancy-CH2Kuksc.mjs → tenancy-CAqjGQcQ.mjs} +2 -2
- package/dist/{tenantPreparation-BTGpblQW.mjs → tenantPreparation-CVBWarqs.mjs} +4 -4
- package/dist/testing/cleanupStoreContract.mjs +1 -1
- package/dist/testing/index.d.mts +2 -2
- package/dist/testing/index.mjs +11 -11
- package/dist/testing/outboxStoreContract.mjs +2 -2
- package/dist/testing/requiredPorts.mjs +2 -2
- package/dist/testing/storageContract.mjs +1 -1
- package/dist/{timing-Dii5X7AP.mjs → timing-CKI_Oyub.mjs} +1 -1
- package/dist/{transactionContext-DMPhYEOt.mjs → transactionContext-D0UZFoSy.mjs} +1 -1
- package/dist/{typeGuards-C1o_XEyp.mjs → typeGuards-CLYkmBLT.mjs} +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/storage.mjs +1 -1
- package/dist/{types-BuV_cFqT.mjs → types-Cunc4shv.mjs} +4 -4
- package/dist/usage/index.mjs +4 -4
- package/dist/{userHelpers-D4m_pLSC.mjs → userHelpers-cT5j1kgp.mjs} +1 -1
- package/dist/utils/index.mjs +12 -12
- package/dist/{utils-CxLMXGn5.mjs → utils-DlNkm1dI.mjs} +6 -6
- package/dist/{validate-CZ975J8N.mjs → validate-63QThRoS.mjs} +3 -3
- package/dist/{versioning-B2_8SBZo.mjs → versioning-f2YGmh4i.mjs} +3 -3
- package/dist/{workScope-B3W3r35s.mjs → workScope-DwspXz70.mjs} +2 -2
- package/package.json +17 -12
- package/skills/arc/references/auth-better-auth.md +27 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { r as workSeedFromEvent, t as runWorkScope } from "./workScope-
|
|
1
|
+
/*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
|
|
2
|
+
import { r as workSeedFromEvent, t as runWorkScope } from "./workScope-DwspXz70.mjs";
|
|
3
3
|
import { createEvent as createEvent$1, createEventRouter } from "@classytic/primitives/events";
|
|
4
4
|
// src/events/EventTransport.ts
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as buildRequestScopeProjection } from "./projection-
|
|
1
|
+
/*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as buildRequestScopeProjection } from "./projection-aHCtDQQ9.mjs";
|
|
3
3
|
// src/hooks/HookSystem.ts
|
|
4
4
|
/**
|
|
5
5
|
* Hook System
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
1
|
+
/*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
|
|
2
2
|
// src/idempotency/acquire.ts
|
|
3
3
|
async function acquireIdempotencyKey(store, key, requestId, lockTtlMs) {
|
|
4
4
|
if (typeof store.acquire === "function") return store.acquire(key, requestId, lockTtlMs);
|
package/dist/audit/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { t as transactionContext } from "../transactionContext-
|
|
3
|
-
import { g as getUserId, i as getClientId } from "../types-
|
|
4
|
-
import { n as declareRuntimeCapability } from "../runtimeCapabilities-
|
|
1
|
+
/*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
|
|
2
|
+
import { t as transactionContext } from "../transactionContext-D0UZFoSy.mjs";
|
|
3
|
+
import { g as getUserId, i as getClientId } from "../types-Cunc4shv.mjs";
|
|
4
|
+
import { n as declareRuntimeCapability } from "../runtimeCapabilities-B8IT7xiQ.mjs";
|
|
5
5
|
import { and, anyOf, eq, gte, lt, lte } from "@classytic/repo-core/filter";
|
|
6
6
|
import fp from "fastify-plugin";
|
|
7
7
|
// src/audit/repository-audit-adapter.ts
|
package/dist/auth/audit.mjs
CHANGED
package/dist/auth/index.d.mts
CHANGED
|
@@ -138,6 +138,14 @@ interface BetterAuthAdapterOptions {
|
|
|
138
138
|
max: number;
|
|
139
139
|
timeWindow: string | number;
|
|
140
140
|
} | false;
|
|
141
|
+
/**
|
|
142
|
+
* Route prefixes (`'/admin'`, `'/api/account'`) whose requests re-read the session from Better
|
|
143
|
+
* Auth's session store, bypassing the cookie cache, as Better Auth's `sensitiveSessionMiddleware`
|
|
144
|
+
* does: a revoked or expired session is a 401, a banned user a 403. Matched against the registered
|
|
145
|
+
* route URL on `/` boundaries. Costs one session-store read per matching request. Per route:
|
|
146
|
+
* `requireSensitiveSession`. See wiki/auth.md.
|
|
147
|
+
*/
|
|
148
|
+
sensitivePaths?: readonly string[];
|
|
141
149
|
}
|
|
142
150
|
interface BetterAuthAdapterResult {
|
|
143
151
|
/** Fastify plugin that registers catch-all auth routes */
|
|
@@ -146,6 +154,21 @@ interface BetterAuthAdapterResult {
|
|
|
146
154
|
authenticate: (request: FastifyRequest, reply: FastifyReply$1) => Promise<void | FastifyReply$1>;
|
|
147
155
|
/** Optional authenticate -- resolves session silently, continues as unauthenticated on failure */
|
|
148
156
|
optionalAuthenticate: (request: FastifyRequest, reply: FastifyReply$1) => Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* PreHandler for a sensitive route (account, security settings, admin, money): after
|
|
159
|
+
* `authenticate`, re-reads the session from storage, bypassing the cookie cache; revoked or
|
|
160
|
+
* expired → 401, banned → 403. One extra session-store read, skipped on a `sensitivePaths` route.
|
|
161
|
+
* Per resource: `routeGuards: [requireSensitiveSession]`.
|
|
162
|
+
*/
|
|
163
|
+
requireSensitiveSession: (request: FastifyRequest, reply: FastifyReply$1) => Promise<void | FastifyReply$1>;
|
|
164
|
+
/**
|
|
165
|
+
* PreHandler for a route that needs a RECENT sign-in (change password, add a passkey, delete the
|
|
166
|
+
* account), as Better Auth's `freshSessionMiddleware`: after `authenticate`, a session older than
|
|
167
|
+
* Better Auth's `session.freshAge` (default one day; `0` disables the check) is a 403
|
|
168
|
+
* "Session is not fresh", and the client re-authenticates. No session (a credential verifier, or
|
|
169
|
+
* no `authenticate` before it) is a 401. Per resource: `routeGuards: [requireFreshSession]`.
|
|
170
|
+
*/
|
|
171
|
+
requireFreshSession: (request: FastifyRequest, reply: FastifyReply$1) => Promise<void | FastifyReply$1>;
|
|
149
172
|
/** Permission helpers bound to this auth adapter (available when orgContext is enabled) */
|
|
150
173
|
permissions: {
|
|
151
174
|
requireOrgRole: (...roles: string[]) => PermissionCheck;
|
|
@@ -173,6 +196,13 @@ declare module "fastify" {
|
|
|
173
196
|
optionalAuthenticate: (request: FastifyRequest, reply: FastifyReply$1) => Promise<void>;
|
|
174
197
|
}
|
|
175
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Header arc sets on every request it hands Better Auth: Fastify's `request.ip` (so it honors
|
|
201
|
+
* arc's `trustProxy`), replacing any client-sent value. Better Auth keys rate limits on
|
|
202
|
+
* `X-Forwarded-For` by default, which a directly-connected client can forge; opt in with
|
|
203
|
+
* `advanced: { ipAddress: { ipAddressHeaders: [BETTER_AUTH_CLIENT_IP_HEADER] } }`.
|
|
204
|
+
*/
|
|
205
|
+
export declare const BETTER_AUTH_CLIENT_IP_HEADER = "x-arc-client-ip";
|
|
176
206
|
/**
|
|
177
207
|
* Create a Better Auth adapter for Arc/Fastify.
|
|
178
208
|
*
|
package/dist/auth/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/*! @classytic/arc v2.
|
|
2
|
-
import { n as getUserRoles, r as normalizeRoles } from "../userHelpers-
|
|
3
|
-
import { d as createDomainError, l as UnauthorizedError, p as isArcError, t as ArcError } from "../errors-
|
|
4
|
-
import { E as requireOrgRole, T as requireOrgMembership, k as requireTeamMembership } from "../permissions-
|
|
5
|
-
import { n as requireSingleHeaderValue } from "../headers-
|
|
6
|
-
import { o as toJsonSchema } from "../schemaConverter-
|
|
7
|
-
import { n as declareRuntimeCapability } from "../runtimeCapabilities-
|
|
1
|
+
/*! @classytic/arc v2.52.0 | MIT | https://classytic.com */
|
|
2
|
+
import { n as getUserRoles, r as normalizeRoles } from "../userHelpers-cT5j1kgp.mjs";
|
|
3
|
+
import { d as createDomainError, l as UnauthorizedError, p as isArcError, t as ArcError } from "../errors-DxpHZBlW.mjs";
|
|
4
|
+
import { E as requireOrgRole, T as requireOrgMembership, k as requireTeamMembership } from "../permissions-Cga6KBOX.mjs";
|
|
5
|
+
import { n as requireSingleHeaderValue } from "../headers-Bh47h0XH.mjs";
|
|
6
|
+
import { o as toJsonSchema } from "../schemaConverter-Cs3SwP4R.mjs";
|
|
7
|
+
import { n as declareRuntimeCapability } from "../runtimeCapabilities-B8IT7xiQ.mjs";
|
|
8
8
|
import { ARC_ERROR_CODES } from "@classytic/repo-core/errors";
|
|
9
9
|
import { isProductionEnv } from "@classytic/primitives/environment";
|
|
10
10
|
import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
|
|
@@ -562,19 +562,52 @@ function mergeUserFieldsIntoRequestBody(requestBody, userFields, endpointPath) {
|
|
|
562
562
|
* });
|
|
563
563
|
*/
|
|
564
564
|
/**
|
|
565
|
+
* Header arc sets on every request it hands Better Auth: Fastify's `request.ip` (so it honors
|
|
566
|
+
* arc's `trustProxy`), replacing any client-sent value. Better Auth keys rate limits on
|
|
567
|
+
* `X-Forwarded-For` by default, which a directly-connected client can forge; opt in with
|
|
568
|
+
* `advanced: { ipAddress: { ipAddressHeaders: [BETTER_AUTH_CLIENT_IP_HEADER] } }`.
|
|
569
|
+
*/
|
|
570
|
+
const BETTER_AUTH_CLIENT_IP_HEADER = "x-arc-client-ip";
|
|
571
|
+
/** Verbs Better Auth endpoints may declare that the catch-all will register. */
|
|
572
|
+
const ROUTABLE_METHODS = /* @__PURE__ */ new Set([
|
|
573
|
+
"GET",
|
|
574
|
+
"POST",
|
|
575
|
+
"PUT",
|
|
576
|
+
"PATCH",
|
|
577
|
+
"DELETE"
|
|
578
|
+
]);
|
|
579
|
+
/**
|
|
580
|
+
* The verbs Better Auth's router answers: GET and POST (core, and the official Fastify guide),
|
|
581
|
+
* plus any a plugin endpoint declares — `@better-auth/scim` uses PUT/PATCH/DELETE,
|
|
582
|
+
* `@better-auth/oauth-provider` PATCH/DELETE. Mirrors better-call's `createRouter`, which skips
|
|
583
|
+
* endpoints without a path or marked `metadata.SERVER_ONLY`. Never `all()`: that adds TRACE and
|
|
584
|
+
* QUERY to the auth surface.
|
|
585
|
+
*/
|
|
586
|
+
function betterAuthRouteMethods(api) {
|
|
587
|
+
const methods = /* @__PURE__ */ new Set(["GET", "POST"]);
|
|
588
|
+
for (const endpoint of Object.values(api ?? {})) {
|
|
589
|
+
if (!endpoint || typeof endpoint !== "function" && typeof endpoint !== "object") continue;
|
|
590
|
+
const { path, options } = endpoint;
|
|
591
|
+
if (typeof path !== "string" || !options || options.metadata?.SERVER_ONLY) continue;
|
|
592
|
+
for (const method of [options.method].flat()) {
|
|
593
|
+
if (typeof method !== "string") continue;
|
|
594
|
+
const verb = method.toUpperCase();
|
|
595
|
+
if (ROUTABLE_METHODS.has(verb)) methods.add(verb);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return [...methods];
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
565
601
|
* Convert a Fastify request into a Fetch API Request.
|
|
566
602
|
*
|
|
567
603
|
* Better Auth expects standard Web API Request objects.
|
|
568
604
|
* We reconstruct one from Fastify's request properties.
|
|
569
605
|
*/
|
|
570
606
|
function toFetchRequest(request) {
|
|
571
|
-
const url = `${request.protocol ?? "http"}://${request.
|
|
572
|
-
const headers =
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (Array.isArray(value)) for (const v of value) headers.append(key, v);
|
|
576
|
-
else headers.set(key, value);
|
|
577
|
-
}
|
|
607
|
+
const url = `${request.protocol ?? "http"}://${request.host || "localhost"}${request.url}`;
|
|
608
|
+
const headers = buildHeaders(request);
|
|
609
|
+
headers.delete(BETTER_AUTH_CLIENT_IP_HEADER);
|
|
610
|
+
if (request.ip) headers.set(BETTER_AUTH_CLIENT_IP_HEADER, request.ip);
|
|
578
611
|
const hasBody = request.method !== "GET" && request.method !== "HEAD";
|
|
579
612
|
let body;
|
|
580
613
|
if (hasBody && request.body != null) {
|
|
@@ -661,17 +694,39 @@ function withErrorEnvelope(text, status, contentType, correlationId) {
|
|
|
661
694
|
});
|
|
662
695
|
}
|
|
663
696
|
/**
|
|
697
|
+
* Whether sessions live in a server-side store (Better Auth's `isStateful`: `database` or
|
|
698
|
+
* `secondaryStorage`). Without one the signed cookie IS the session, so an authoritative read
|
|
699
|
+
* keeps the cookie cache. An instance without `options` (a stub) counts as stateful.
|
|
700
|
+
*/
|
|
701
|
+
function hasSessionStore(auth) {
|
|
702
|
+
const options = auth.options;
|
|
703
|
+
return !options || !!options.database || !!options.secondaryStorage;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Better Auth admin plugin's ban rule, as its session-create hook applies it: `banned`, unless
|
|
707
|
+
* `banExpires` has passed. Checked only on an authoritative read (a cached user is stale).
|
|
708
|
+
*/
|
|
709
|
+
function isBannedUser(user) {
|
|
710
|
+
if (user.banned !== true) return false;
|
|
711
|
+
if (!user.banExpires) return true;
|
|
712
|
+
return !(new Date(user.banExpires).getTime() < Date.now());
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
664
715
|
* Resolve the current session via `auth.api.getSession`. Throws
|
|
665
716
|
* `ArcError(BETTER_AUTH_API_MISSING)` when it is absent (a stub, not a real
|
|
666
|
-
* `betterAuth()` instance).
|
|
717
|
+
* `betterAuth()` instance). `authoritative` bypasses the cookie cache
|
|
718
|
+
* (`disableCookieCache`), so the session is read from storage.
|
|
667
719
|
*/
|
|
668
|
-
async function getSessionDirect(auth, headers) {
|
|
720
|
+
async function getSessionDirect(auth, headers, authoritative = false) {
|
|
669
721
|
const api = auth.api;
|
|
670
722
|
if (!api || typeof api.getSession !== "function") throw new ArcError("Better Auth instance is missing `api.getSession` — arc requires the in-process API map. Pass a real `betterAuth()` instance or supply an `api: { getSession }` stub.", {
|
|
671
723
|
code: ARC_ERROR_CODES.AUTH_MISCONFIGURED,
|
|
672
724
|
statusCode: 500
|
|
673
725
|
});
|
|
674
|
-
const result = await api.getSession(
|
|
726
|
+
const result = await api.getSession(authoritative ? {
|
|
727
|
+
headers,
|
|
728
|
+
query: { disableCookieCache: true }
|
|
729
|
+
} : { headers });
|
|
675
730
|
return result?.user ? result : null;
|
|
676
731
|
}
|
|
677
732
|
/**
|
|
@@ -778,7 +833,25 @@ async function resolveActiveTeamId(input) {
|
|
|
778
833
|
}
|
|
779
834
|
const AUTH_SCHEME = /^[A-Za-z][A-Za-z0-9!#$%&'*+.^_`|~-]*$/;
|
|
780
835
|
function createBetterAuthAdapter(options) {
|
|
781
|
-
const { auth, basePath = "/api/auth", orgContext: orgContextOpt = false, openapi: openapiOpt = true, userFields, exposeAuthErrors = false, resolveOrgRoles, memberLookup = "better-auth", credentials = {} } = options;
|
|
836
|
+
const { auth, basePath = "/api/auth", orgContext: orgContextOpt = false, openapi: openapiOpt = true, userFields, exposeAuthErrors = false, resolveOrgRoles, memberLookup = "better-auth", credentials = {}, sensitivePaths = [] } = options;
|
|
837
|
+
const sensitivePrefixes = sensitivePaths.map((prefix) => {
|
|
838
|
+
if (typeof prefix !== "string" || !prefix.startsWith("/")) throw new Error(`createBetterAuthAdapter: sensitivePaths entry ${JSON.stringify(prefix)} must start with "/".`);
|
|
839
|
+
return prefix.replace(/\/+$/, "");
|
|
840
|
+
});
|
|
841
|
+
/** The registered route URL (not the raw URL, which percent-encoding could disguise). */
|
|
842
|
+
const isSensitiveRoute = (request) => {
|
|
843
|
+
if (sensitivePrefixes.length === 0) return false;
|
|
844
|
+
const url = request.routeOptions?.url ?? request.url.split("?")[0] ?? "";
|
|
845
|
+
return sensitivePrefixes.some((prefix) => url === prefix || url.startsWith(`${prefix}/`));
|
|
846
|
+
};
|
|
847
|
+
const authoritativeRead = hasSessionStore(auth);
|
|
848
|
+
/** Requests whose principal was read authoritatively this request (store read, or a verifier). */
|
|
849
|
+
const verifiedFresh = /* @__PURE__ */ new WeakSet();
|
|
850
|
+
const bannedReply = (reply) => reply.code(403).send({
|
|
851
|
+
code: ARC_ERROR_CODES.FORBIDDEN,
|
|
852
|
+
message: "Account is banned",
|
|
853
|
+
status: 403
|
|
854
|
+
});
|
|
782
855
|
const verifiers = /* @__PURE__ */ new Map();
|
|
783
856
|
for (const [scheme, verify] of Object.entries(credentials)) {
|
|
784
857
|
if (!AUTH_SCHEME.test(scheme)) throw new Error(`createBetterAuthAdapter: "${scheme}" is not an auth scheme name.`);
|
|
@@ -861,11 +934,13 @@ function createBetterAuthAdapter(options) {
|
|
|
861
934
|
return reply;
|
|
862
935
|
}
|
|
863
936
|
request.scope = scope;
|
|
937
|
+
verifiedFresh.add(request);
|
|
864
938
|
return;
|
|
865
939
|
}
|
|
866
940
|
try {
|
|
867
941
|
const headers = buildHeaders(request);
|
|
868
|
-
const
|
|
942
|
+
const sensitive = isSensitiveRoute(request);
|
|
943
|
+
const sessionData = await getSessionDirect(auth, headers, sensitive && authoritativeRead);
|
|
869
944
|
if (!sessionData?.user) {
|
|
870
945
|
reply.code(401).send({
|
|
871
946
|
code: ARC_ERROR_CODES.UNAUTHORIZED,
|
|
@@ -874,6 +949,10 @@ function createBetterAuthAdapter(options) {
|
|
|
874
949
|
});
|
|
875
950
|
return reply;
|
|
876
951
|
}
|
|
952
|
+
if (sensitive) {
|
|
953
|
+
if (isBannedUser(sessionData.user)) return bannedReply(reply);
|
|
954
|
+
verifiedFresh.add(request);
|
|
955
|
+
}
|
|
877
956
|
const req = request;
|
|
878
957
|
req.user = sessionData.user;
|
|
879
958
|
req.session = sessionData.session;
|
|
@@ -912,13 +991,21 @@ function createBetterAuthAdapter(options) {
|
|
|
912
991
|
const presented = presentedCredential(request);
|
|
913
992
|
if (presented) {
|
|
914
993
|
const scope = await presented.verify(presented.value, request);
|
|
915
|
-
if (scope)
|
|
994
|
+
if (scope) {
|
|
995
|
+
request.scope = scope;
|
|
996
|
+
verifiedFresh.add(request);
|
|
997
|
+
}
|
|
916
998
|
return;
|
|
917
999
|
}
|
|
918
1000
|
try {
|
|
919
1001
|
const headers = buildHeaders(request);
|
|
920
|
-
const
|
|
1002
|
+
const sensitive = isSensitiveRoute(request);
|
|
1003
|
+
const sessionData = await getSessionDirect(auth, headers, sensitive && authoritativeRead);
|
|
921
1004
|
if (!sessionData?.user) return;
|
|
1005
|
+
if (sensitive) {
|
|
1006
|
+
if (isBannedUser(sessionData.user)) return;
|
|
1007
|
+
verifiedFresh.add(request);
|
|
1008
|
+
}
|
|
922
1009
|
const req = request;
|
|
923
1010
|
req.user = sessionData.user;
|
|
924
1011
|
req.session = sessionData.session;
|
|
@@ -938,6 +1025,52 @@ function createBetterAuthAdapter(options) {
|
|
|
938
1025
|
if (err instanceof ArcError) throw err;
|
|
939
1026
|
}
|
|
940
1027
|
};
|
|
1028
|
+
/**
|
|
1029
|
+
* Runs after `authenticate`: the session `request.user` came from must still exist in storage
|
|
1030
|
+
* for the same user. Skipped when this request already read authoritatively (a `sensitivePaths`
|
|
1031
|
+
* route, or a registered credential verifier, which arc never caches).
|
|
1032
|
+
*/
|
|
1033
|
+
const requireSensitiveSession = async (request, reply) => {
|
|
1034
|
+
if (verifiedFresh.has(request)) return;
|
|
1035
|
+
const unauthorized = (message) => reply.code(401).send({
|
|
1036
|
+
code: ARC_ERROR_CODES.UNAUTHORIZED,
|
|
1037
|
+
message,
|
|
1038
|
+
status: 401
|
|
1039
|
+
});
|
|
1040
|
+
const current = request.user;
|
|
1041
|
+
if (!current || presentedCredential(request)) return unauthorized("Authentication required");
|
|
1042
|
+
try {
|
|
1043
|
+
const sessionData = await getSessionDirect(auth, buildHeaders(request), authoritativeRead);
|
|
1044
|
+
const freshId = sessionData ? String(sessionData.user.id ?? sessionData.user._id ?? "") : "";
|
|
1045
|
+
if (!freshId || freshId !== String(current.id ?? current._id ?? "")) return unauthorized("Invalid or expired session");
|
|
1046
|
+
if (isBannedUser(sessionData?.user ?? {})) return bannedReply(reply);
|
|
1047
|
+
verifiedFresh.add(request);
|
|
1048
|
+
} catch (err) {
|
|
1049
|
+
if (err instanceof ArcError) throw err;
|
|
1050
|
+
return unauthorized(exposeAuthErrors && err instanceof Error ? err.message : "Authentication required");
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
/** Better Auth's default `session.freshAge` (seconds): one day. `0` turns the check off. */
|
|
1054
|
+
const DEFAULT_FRESH_AGE_S = 86400;
|
|
1055
|
+
const freshAgeSeconds = () => {
|
|
1056
|
+
const configured = auth.options?.session?.freshAge;
|
|
1057
|
+
return typeof configured === "number" && Number.isFinite(configured) && configured >= 0 ? configured : DEFAULT_FRESH_AGE_S;
|
|
1058
|
+
};
|
|
1059
|
+
const requireFreshSession = async (request, reply) => {
|
|
1060
|
+
const session = request.session;
|
|
1061
|
+
const createdAt = session ? new Date(session.createdAt).getTime() : NaN;
|
|
1062
|
+
if (!session || presentedCredential(request) || Number.isNaN(createdAt)) return reply.code(401).send({
|
|
1063
|
+
code: ARC_ERROR_CODES.UNAUTHORIZED,
|
|
1064
|
+
message: "Authentication required",
|
|
1065
|
+
status: 401
|
|
1066
|
+
});
|
|
1067
|
+
const freshAge = freshAgeSeconds();
|
|
1068
|
+
if (freshAge !== 0 && Date.now() - createdAt >= freshAge * 1e3) return reply.code(403).send({
|
|
1069
|
+
code: ARC_ERROR_CODES.FORBIDDEN,
|
|
1070
|
+
message: "Session is not fresh",
|
|
1071
|
+
status: 403
|
|
1072
|
+
});
|
|
1073
|
+
};
|
|
941
1074
|
let extractedOpenApi;
|
|
942
1075
|
if (openapiOpt === false) extractedOpenApi = void 0;
|
|
943
1076
|
else if (typeof openapiOpt === "object") extractedOpenApi = openapiOpt;
|
|
@@ -949,16 +1082,21 @@ function createBetterAuthAdapter(options) {
|
|
|
949
1082
|
});
|
|
950
1083
|
}
|
|
951
1084
|
const routeOpts = options.rateLimit && typeof options.rateLimit === "object" ? { config: { rateLimit: options.rateLimit } } : {};
|
|
952
|
-
fastify.
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1085
|
+
fastify.route({
|
|
1086
|
+
method: betterAuthRouteMethods(auth.api),
|
|
1087
|
+
url: `${normalizedBase}/*`,
|
|
1088
|
+
...routeOpts,
|
|
1089
|
+
handler: async (request, reply) => {
|
|
1090
|
+
try {
|
|
1091
|
+
const fetchRequest = toFetchRequest(request);
|
|
1092
|
+
await sendFetchResponse(await auth.handler(fetchRequest), reply, request);
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
throw new ArcError("Authentication service error", {
|
|
1095
|
+
code: ARC_ERROR_CODES.AUTH_SERVICE_ERROR,
|
|
1096
|
+
statusCode: 500,
|
|
1097
|
+
cause: err instanceof Error ? err : new Error(String(err))
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
962
1100
|
}
|
|
963
1101
|
});
|
|
964
1102
|
if (!fastify.hasDecorator("authenticate")) fastify.decorate("authenticate", authenticate);
|
|
@@ -982,6 +1120,8 @@ function createBetterAuthAdapter(options) {
|
|
|
982
1120
|
}),
|
|
983
1121
|
authenticate,
|
|
984
1122
|
optionalAuthenticate,
|
|
1123
|
+
requireSensitiveSession,
|
|
1124
|
+
requireFreshSession,
|
|
985
1125
|
permissions: {
|
|
986
1126
|
requireOrgRole: (...roles) => requireOrgRole(roles),
|
|
987
1127
|
requireOrgMembership: () => requireOrgMembership(),
|
|
@@ -1415,4 +1555,4 @@ function mirrorTrustedOriginsFromCors(options) {
|
|
|
1415
1555
|
if (!corsOrigins) return [canonicalUrl];
|
|
1416
1556
|
return Array.from(/* @__PURE__ */ new Set([canonicalUrl, ...corsOrigins]));
|
|
1417
1557
|
}
|
|
1418
|
-
export { MemorySessionStore, authPlugin_default as authPlugin, createBetterAuthAdapter, createSessionManager, extractBetterAuthOpenApi, mirrorTrustedOriginsFromCors };
|
|
1558
|
+
export { BETTER_AUTH_CLIENT_IP_HEADER, MemorySessionStore, authPlugin_default as authPlugin, createBetterAuthAdapter, createSessionManager, extractBetterAuthOpenApi, mirrorTrustedOriginsFromCors };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
import { SocialProviders } from "better-auth/social-providers";
|
|
3
|
+
import { BetterAuthPlugin } from "better-auth";
|
|
4
|
+
/** Provider ids with a preset. */
|
|
5
|
+
type SocialProviderId = "google" | "github" | "apple" | "facebook";
|
|
6
|
+
/** A provider as listed to clients: id plus display name. */
|
|
7
|
+
interface SocialProviderInfo {
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
interface DefineSocialProvidersOptions {
|
|
12
|
+
/** Providers to enable: an array or a comma list (`"google,github"`). Empty enables none. */
|
|
13
|
+
enabled: readonly string[] | string;
|
|
14
|
+
/** Where credentials are read. Default `process.env`. */
|
|
15
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
16
|
+
/** Better Auth provider options merged over each preset (shallow). */
|
|
17
|
+
overrides?: Partial<Record<SocialProviderId, Record<string, unknown>>>;
|
|
18
|
+
}
|
|
19
|
+
interface DefinedSocialProviders {
|
|
20
|
+
/** Pass to `betterAuth({ socialProviders })`. */
|
|
21
|
+
socialProviders: SocialProviders;
|
|
22
|
+
/** Enabled providers in `enabled` order; pass to `socialAuth({ providers })`. */
|
|
23
|
+
providers: SocialProviderInfo[];
|
|
24
|
+
/** Origins the enabled providers post back from (Apple's form_post). Add to `trustedOrigins`. */
|
|
25
|
+
trustedOrigins: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Better Auth `socialProviders`, the client-facing provider list and the extra trusted origins,
|
|
29
|
+
* for the providers `enabled` names. Throws on an unknown id, and on an enabled provider whose
|
|
30
|
+
* credentials are missing (the message names each missing variable).
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const social = defineSocialProviders({ enabled: process.env.SOCIAL_PROVIDERS ?? "" });
|
|
34
|
+
* betterAuth({ socialProviders: social.socialProviders, plugins: [socialAuth({ providers: social.providers })] });
|
|
35
|
+
*/
|
|
36
|
+
export declare function defineSocialProviders(options: DefineSocialProvidersOptions): DefinedSocialProviders;
|
|
37
|
+
interface SocialAuthOptions {
|
|
38
|
+
/** Display names for `/social/providers` (`defineSocialProviders().providers`). */
|
|
39
|
+
providers?: readonly SocialProviderInfo[];
|
|
40
|
+
}
|
|
41
|
+
export declare function socialAuth(options?: SocialAuthOptions): BetterAuthPlugin;
|
|
42
|
+
export type { DefineSocialProvidersOptions, DefinedSocialProviders, SocialAuthOptions, SocialProviderId, SocialProviderInfo };
|