@classytic/arc 2.9.1 → 2.10.8
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 +20 -91
- package/dist/{BaseController-Vu2yc56T.mjs → BaseController-DVNKvoX4.mjs} +154 -170
- package/dist/{ResourceRegistry-Dq3_zBQP.mjs → ResourceRegistry-CcN2LVrc.mjs} +1 -1
- package/dist/actionPermissions-TUVR3uiZ.mjs +22 -0
- package/dist/adapters/index.d.mts +3 -3
- package/dist/adapters/index.mjs +2 -2
- package/dist/{adapters-BBqAVvPK.mjs → adapters-BXY4i-hw.mjs} +210 -41
- package/dist/audit/index.d.mts +38 -3
- package/dist/audit/index.mjs +54 -22
- package/dist/auth/index.d.mts +2 -2
- package/dist/auth/index.mjs +3 -3
- package/dist/cache/index.d.mts +17 -15
- package/dist/cache/index.mjs +16 -15
- package/dist/{caching-CjybdRwx.mjs → caching-3h93rkJM.mjs} +8 -3
- package/dist/cli/commands/describe.mjs +1 -1
- package/dist/cli/commands/docs.mjs +2 -2
- package/dist/cli/commands/init.mjs +1 -1
- package/dist/cli/commands/introspect.mjs +1 -1
- package/dist/context/index.d.mts +58 -0
- package/dist/context/index.mjs +2 -0
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +3 -4
- package/dist/{defineResource-C__jkwvs.mjs → core-3MWJosCH.mjs} +174 -94
- package/dist/{createActionRouter-DH1YFL9m.mjs → createActionRouter-C8UUB3Px.mjs} +1 -1
- package/dist/{createApp-CBJUJKGP.mjs → createApp-BwnEAO2h.mjs} +53 -19
- package/dist/docs/index.d.mts +1 -1
- package/dist/docs/index.mjs +2 -2
- package/dist/{elevation-DxQ6ACbt.mjs → elevation-Dci0AYLT.mjs} +2 -2
- package/dist/errorHandler-2ii4RIYr.d.mts +114 -0
- package/dist/{errorHandler-CZDW4EXS.mjs → errorHandler-CSxe7KIM.mjs} +1 -1
- package/dist/{eventPlugin-Dl7MoVWH.mjs → eventPlugin-ByU4Cv0e.mjs} +1 -1
- package/dist/{eventPlugin-BxvaCIZF.d.mts → eventPlugin-D1ThQ1Pp.d.mts} +1 -1
- package/dist/events/index.d.mts +8 -5
- package/dist/events/index.mjs +87 -52
- package/dist/events/transports/redis-stream-entry.d.mts +1 -1
- package/dist/events/transports/redis.d.mts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/{types-DZi1aYhm.d.mts → fields-C8Y0XLAu.d.mts} +122 -2
- package/dist/hooks/index.d.mts +1 -1
- package/dist/idempotency/index.d.mts +5 -2
- package/dist/idempotency/index.mjs +46 -37
- package/dist/{interface-YrWsmKqE.d.mts → index-BGbpGVyM.d.mts} +2107 -2756
- package/dist/{index-CtGKT0lf.d.mts → index-BziRPS4H.d.mts} +81 -7
- package/dist/{index-C-xjcA6F.d.mts → index-C_Noptz-.d.mts} +284 -409
- package/dist/{index-Cibkchnx.d.mts → index-EqQN6p0W.d.mts} +3 -3
- package/dist/index.d.mts +6 -219
- package/dist/index.mjs +10 -131
- package/dist/integrations/event-gateway.d.mts +1 -1
- package/dist/integrations/event-gateway.mjs +1 -1
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/mcp/index.d.mts +2 -2
- package/dist/integrations/mcp/index.mjs +1 -1
- package/dist/integrations/mcp/testing.d.mts +1 -1
- package/dist/integrations/mcp/testing.mjs +1 -1
- package/dist/interface-yhyb_pLY.d.mts +77 -0
- package/dist/logger/index.d.mts +81 -0
- package/dist/{logger-CDjpjySd.mjs → logger/index.mjs} +1 -6
- package/dist/{memory-BFAYkf8H.mjs → memory-DqI-449b.mjs} +23 -8
- package/dist/middleware/index.d.mts +109 -0
- package/dist/middleware/index.mjs +70 -0
- package/dist/multipartBody-CUQGVlM_.mjs +123 -0
- package/dist/{openapi-CXuTG1M9.mjs → openapi-DpNpqBmo.mjs} +9 -7
- package/dist/org/index.d.mts +2 -2
- package/dist/permissions/index.d.mts +3 -4
- package/dist/permissions/index.mjs +5 -5
- package/dist/{permissions-oNZawnkR.mjs → permissions-wkqRwicB.mjs} +315 -397
- package/dist/pipe-CGJxqDGx.mjs +62 -0
- package/dist/pipeline/index.d.mts +62 -0
- package/dist/pipeline/index.mjs +53 -0
- package/dist/plugins/index.d.mts +23 -3
- package/dist/plugins/index.mjs +9 -11
- package/dist/plugins/response-cache.mjs +1 -1
- package/dist/plugins/tracing-entry.mjs +1 -1
- package/dist/presets/filesUpload.d.mts +3 -3
- package/dist/presets/filesUpload.mjs +255 -1
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +2 -2
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +43 -9
- package/dist/presets/search.d.mts +91 -4
- package/dist/presets/search.mjs +1 -1
- package/dist/{presets-hM4WhNWY.mjs → presets-CrwOvuXI.mjs} +1 -1
- package/dist/{queryCachePlugin-DbUVroUG.mjs → queryCachePlugin-ChLNZvFT.mjs} +9 -9
- package/dist/{queryCachePlugin-CnTZZTC5.d.mts → queryCachePlugin-Dumka73q.d.mts} +1 -1
- package/dist/{queryParser-Cs-6SHQK.mjs → queryParser-NR__Qiju.mjs} +69 -2
- package/dist/{redis-stream-Bz-4q96t.d.mts → redis-stream-bkO88VHx.d.mts} +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/registry/index.mjs +1 -1
- package/dist/{requestContext-DYtmNpm5.mjs → requestContext-C38GskNt.mjs} +1 -1
- package/dist/{resourceToTools-C3cWymnW.mjs → resourceToTools-BhF3JV5p.mjs} +8 -3
- package/dist/scope/index.d.mts +2 -2
- package/dist/scope/index.mjs +2 -2
- package/dist/{sse-CJpt7LGI.mjs → sse-D8UeDwis.mjs} +1 -1
- package/dist/{store-helpers-DFiZl5TL.mjs → store-helpers-DYYUQbQN.mjs} +4 -0
- package/dist/testing/index.d.mts +6 -5
- package/dist/testing/index.mjs +17 -10
- package/dist/types/index.d.mts +5 -5
- package/dist/types/index.mjs +1 -31
- package/dist/types-CDnTEpga.mjs +27 -0
- package/dist/{types-CoSzA-s-.d.mts → types-CVKBssX5.d.mts} +1 -1
- package/dist/{types-CunEX4UX.d.mts → types-CVdgPXBW.d.mts} +20 -7
- package/dist/utils/index.d.mts +277 -3
- package/dist/utils/index.mjs +4 -5
- package/dist/{utils-B7FuRr9w.mjs → utils-LMwVidKy.mjs} +303 -2
- package/dist/{versioning-Cm8qoFDg.mjs → versioning-B6mimogM.mjs} +3 -5
- package/dist/versioning-CeUXHfjw.d.mts +117 -0
- package/package.json +31 -18
- package/skills/arc/SKILL.md +8 -12
- package/skills/arc/references/production.md +0 -41
- package/dist/circuitBreaker-CvXkjfrW.d.mts +0 -206
- package/dist/circuitBreaker-l18oRgL5.mjs +0 -284
- package/dist/core-DNncu0xF.mjs +0 -34
- package/dist/dynamic/index.d.mts +0 -93
- package/dist/dynamic/index.mjs +0 -122
- package/dist/errorHandler-DixGcttC.d.mts +0 -218
- package/dist/fields-BC7zcmI9.d.mts +0 -121
- package/dist/filesUpload-q8oHt--L.mjs +0 -377
- package/dist/interface-DplgQO2e.d.mts +0 -54
- package/dist/policies/index.d.mts +0 -425
- package/dist/policies/index.mjs +0 -318
- package/dist/rpc/index.d.mts +0 -90
- package/dist/rpc/index.mjs +0 -248
- /package/dist/{EventTransport-CqZ8FyM_.d.mts → EventTransport-CfVEGaEl.d.mts} +0 -0
- /package/dist/{applyPermissionResult-bqGpo9ML.mjs → applyPermissionResult-QhV1Pa-g.mjs} +0 -0
- /package/dist/{constants-Cxde4rpC.mjs → constants-BhY1OHoH.mjs} +0 -0
- /package/dist/{elevation-B6S5csVA.d.mts → elevation-s5ykdNHr.d.mts} +0 -0
- /package/dist/{errors-CqWnSqM-.mjs → errors-BqdUDja_.mjs} +0 -0
- /package/dist/{fields-CU6FlaDV.mjs → fields-CTMWOUDt.mjs} +0 -0
- /package/dist/{keys-qcD-TVJl.mjs → keys-nWQGUTu1.mjs} +0 -0
- /package/dist/{types-ZUu_h0jp.mjs → types-D57iXYb8.mjs} +0 -0
- /package/dist/{types-BD85MlEK.d.mts → types-tgR4Pt8F.d.mts} +0 -0
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
|
|
2
1
|
//#region src/logger/index.ts
|
|
3
|
-
var logger_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
-
arcLog: () => arcLog,
|
|
5
|
-
configureArcLogger: () => configureArcLogger
|
|
6
|
-
});
|
|
7
2
|
let globalOptions = {};
|
|
8
3
|
/**
|
|
9
4
|
* Configure the Arc logger globally.
|
|
@@ -73,4 +68,4 @@ function isSuppressed() {
|
|
|
73
68
|
return env === "1" || env === "true";
|
|
74
69
|
}
|
|
75
70
|
//#endregion
|
|
76
|
-
export {
|
|
71
|
+
export { arcLog, configureArcLogger };
|
|
@@ -11,7 +11,7 @@ var memory_exports = /* @__PURE__ */ __exportAll({ MemoryCacheStore: () => Memor
|
|
|
11
11
|
var MemoryCacheStore = class {
|
|
12
12
|
name = "memory-cache";
|
|
13
13
|
cache = /* @__PURE__ */ new Map();
|
|
14
|
-
|
|
14
|
+
defaultTtlSeconds;
|
|
15
15
|
maxEntries;
|
|
16
16
|
maxEntryBytes;
|
|
17
17
|
maxMemoryBytes;
|
|
@@ -23,7 +23,7 @@ var MemoryCacheStore = class {
|
|
|
23
23
|
_misses = 0;
|
|
24
24
|
_evictions = 0;
|
|
25
25
|
constructor(options = {}) {
|
|
26
|
-
this.
|
|
26
|
+
this.defaultTtlSeconds = options.defaultTtlSeconds ?? 60;
|
|
27
27
|
this.maxEntries = clamp(options.maxEntries ?? 1e3, 1, 1e5);
|
|
28
28
|
this.maxEntryBytes = clamp(options.maxEntryBytes ?? 256 * 1024, 1024, 10 * 1024 * 1024);
|
|
29
29
|
this.maxMemoryBytes = options.maxMemoryBytes ?? 50 * 1024 * 1024;
|
|
@@ -49,9 +49,10 @@ var MemoryCacheStore = class {
|
|
|
49
49
|
this._hits++;
|
|
50
50
|
return entry.value;
|
|
51
51
|
}
|
|
52
|
-
async set(key, value,
|
|
53
|
-
const
|
|
54
|
-
if (!Number.isFinite(
|
|
52
|
+
async set(key, value, ttlSeconds) {
|
|
53
|
+
const effectiveTtlSeconds = ttlSeconds ?? this.defaultTtlSeconds;
|
|
54
|
+
if (!Number.isFinite(effectiveTtlSeconds) || effectiveTtlSeconds <= 0) return;
|
|
55
|
+
const ttlMs = effectiveTtlSeconds * 1e3;
|
|
55
56
|
const size = this.estimateSize(value);
|
|
56
57
|
if (size > this.maxEntryBytes) {
|
|
57
58
|
this.logger.warn(`[MemoryCacheStore] Skipping oversized entry for key '${key}' (${size} bytes > ${this.maxEntryBytes} bytes)`);
|
|
@@ -75,9 +76,14 @@ var MemoryCacheStore = class {
|
|
|
75
76
|
const entry = this.cache.get(key);
|
|
76
77
|
if (entry) this.removeEntry(key, entry);
|
|
77
78
|
}
|
|
78
|
-
async clear() {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
async clear(pattern) {
|
|
80
|
+
if (pattern === void 0) {
|
|
81
|
+
this.cache.clear();
|
|
82
|
+
this.currentBytes = 0;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const regex = globToRegExp(pattern);
|
|
86
|
+
for (const [key, entry] of this.cache) if (regex.test(key)) this.removeEntry(key, entry);
|
|
81
87
|
}
|
|
82
88
|
async close() {
|
|
83
89
|
clearInterval(this.cleanupTimer);
|
|
@@ -134,5 +140,14 @@ var MemoryCacheStore = class {
|
|
|
134
140
|
function clamp(value, min, max) {
|
|
135
141
|
return Math.min(max, Math.max(min, value));
|
|
136
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Translate a glob pattern (`prefix:*`, `*:tag:v`) into a regex. Only `*`
|
|
145
|
+
* is honoured; other regex metachars are escaped so patterns can't inject
|
|
146
|
+
* alternation/lookahead.
|
|
147
|
+
*/
|
|
148
|
+
function globToRegExp(pattern) {
|
|
149
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
150
|
+
return new RegExp(`^${escaped}$`);
|
|
151
|
+
}
|
|
137
152
|
//#endregion
|
|
138
153
|
export { memory_exports as n, MemoryCacheStore as t };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { I as MiddlewareHandler, L as RequestWithExtras, pt as MiddlewareConfig } from "../index-BGbpGVyM.mjs";
|
|
2
|
+
import { RouteHandlerMethod } from "fastify";
|
|
3
|
+
|
|
4
|
+
//#region src/middleware/middleware.d.ts
|
|
5
|
+
interface NamedMiddleware {
|
|
6
|
+
/** Unique name for debugging/introspection */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** Operations this middleware applies to (default: all) */
|
|
9
|
+
readonly operations?: Array<"list" | "get" | "create" | "update" | "delete" | string>;
|
|
10
|
+
/** Priority — lower numbers run first (default: 10) */
|
|
11
|
+
readonly priority: number;
|
|
12
|
+
/** Conditional execution — return true to run, false to skip */
|
|
13
|
+
readonly when?: (request: RequestWithExtras) => boolean | Promise<boolean>;
|
|
14
|
+
/** The middleware handler */
|
|
15
|
+
readonly handler: MiddlewareHandler;
|
|
16
|
+
}
|
|
17
|
+
interface MiddlewareOptions {
|
|
18
|
+
operations?: NamedMiddleware["operations"];
|
|
19
|
+
priority?: number;
|
|
20
|
+
when?: NamedMiddleware["when"];
|
|
21
|
+
handler: MiddlewareHandler;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a named middleware with priority and conditions.
|
|
25
|
+
*/
|
|
26
|
+
declare function middleware(name: string, options: MiddlewareOptions): NamedMiddleware;
|
|
27
|
+
/**
|
|
28
|
+
* Sort named middlewares by priority (ascending — lower runs first).
|
|
29
|
+
* Returns a MiddlewareConfig map keyed by operation, ready to pass to `defineResource()`.
|
|
30
|
+
*/
|
|
31
|
+
declare function sortMiddlewares(middlewares: NamedMiddleware[]): MiddlewareConfig;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/middleware/multipartBody.d.ts
|
|
34
|
+
/** Parsed file from multipart form-data */
|
|
35
|
+
interface ParsedFile {
|
|
36
|
+
/** Original filename */
|
|
37
|
+
filename: string;
|
|
38
|
+
/** MIME type */
|
|
39
|
+
mimetype: string;
|
|
40
|
+
/** File contents as Buffer */
|
|
41
|
+
buffer: Buffer;
|
|
42
|
+
/** File size in bytes */
|
|
43
|
+
size: number;
|
|
44
|
+
/** Form field name */
|
|
45
|
+
fieldname: string;
|
|
46
|
+
}
|
|
47
|
+
interface MultipartBodyOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Maximum file size in bytes (default: 10MB).
|
|
50
|
+
* Files exceeding this are rejected with 413.
|
|
51
|
+
*/
|
|
52
|
+
maxFileSize?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Maximum number of files (default: 5).
|
|
55
|
+
* Extra files are silently ignored.
|
|
56
|
+
*/
|
|
57
|
+
maxFiles?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Allowed MIME types (default: all).
|
|
60
|
+
* Files with disallowed types are rejected with 415.
|
|
61
|
+
*
|
|
62
|
+
* Supports three forms in a single list:
|
|
63
|
+
* - Exact: `image/png`
|
|
64
|
+
* - Subtype wildcard: `image/\*` — any `image/…`
|
|
65
|
+
* - Any: `\*` or `\*\/\*` — equivalent to omitting the option
|
|
66
|
+
*
|
|
67
|
+
* @example ['image/jpeg', 'image/png', 'application/pdf']
|
|
68
|
+
* @example ['image/*', 'application/pdf']
|
|
69
|
+
* @example ['*'] // accept any type explicitly
|
|
70
|
+
*/
|
|
71
|
+
allowedMimeTypes?: string[];
|
|
72
|
+
/**
|
|
73
|
+
* Key on `req.body` where parsed files are attached (default: '_files').
|
|
74
|
+
* Set to a custom key if '_files' conflicts with your schema.
|
|
75
|
+
*
|
|
76
|
+
* Note: this is the **destination** key — it controls where parsed files
|
|
77
|
+
* land on `req.body`, not which form fields are required. To enforce that
|
|
78
|
+
* a specific file field must be present in the request, use `requiredFields`.
|
|
79
|
+
*/
|
|
80
|
+
filesKey?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Multipart form field names that MUST be present in the request.
|
|
83
|
+
* Returns 400 with `{ success: false, error, code: 'MISSING_FILE_FIELDS' }`
|
|
84
|
+
* when any listed field is absent from the uploaded files.
|
|
85
|
+
*
|
|
86
|
+
* Only enforced when the request IS multipart — JSON requests still pass
|
|
87
|
+
* through as no-ops so the same middleware stays safe to add to shared
|
|
88
|
+
* create/update routes that accept both content types.
|
|
89
|
+
*
|
|
90
|
+
* @example ['file'] // single-field upload (OCR, classify)
|
|
91
|
+
* @example ['avatar', 'cover'] // multi-field upload (profile editor)
|
|
92
|
+
*/
|
|
93
|
+
requiredFields?: string[];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a multipart body parsing middleware.
|
|
97
|
+
*
|
|
98
|
+
* When a request has `content-type: multipart/form-data`, this middleware:
|
|
99
|
+
* 1. Reads all parts (fields + files)
|
|
100
|
+
* 2. Sets text fields on `req.body` as a plain object
|
|
101
|
+
* 3. Attaches file buffers to `req.body[filesKey]` (default: `req.body._files`)
|
|
102
|
+
*
|
|
103
|
+
* For non-multipart requests (regular JSON), this is a no-op — the request
|
|
104
|
+
* passes through unchanged. This makes it safe to add to create/update
|
|
105
|
+
* middlewares without breaking JSON clients.
|
|
106
|
+
*/
|
|
107
|
+
declare function multipartBody(options?: MultipartBodyOptions): RouteHandlerMethod;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { type MultipartBodyOptions, type NamedMiddleware, type ParsedFile, middleware, multipartBody, sortMiddlewares };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { t as CRUD_OPERATIONS } from "../constants-BhY1OHoH.mjs";
|
|
2
|
+
import { t as multipartBody } from "../multipartBody-CUQGVlM_.mjs";
|
|
3
|
+
//#region src/middleware/middleware.ts
|
|
4
|
+
/**
|
|
5
|
+
* Named Middleware — Priority-based, conditional middleware execution.
|
|
6
|
+
*
|
|
7
|
+
* Named middleware replaces flat arrays with structured, inspectable middleware
|
|
8
|
+
* that runs in priority order and supports conditional execution.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { middleware } from '@classytic/arc/middleware';
|
|
13
|
+
*
|
|
14
|
+
* const verifyEmail = middleware('verifyEmail', {
|
|
15
|
+
* operations: ['create', 'update'],
|
|
16
|
+
* priority: 5,
|
|
17
|
+
* when: (req) => !req.user?.emailVerified,
|
|
18
|
+
* handler: async (req, reply) => {
|
|
19
|
+
* reply.code(403).send({ error: 'Email verification required' });
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const rateLimit = middleware('rateLimit', {
|
|
24
|
+
* priority: 1,
|
|
25
|
+
* handler: async (req, reply) => {
|
|
26
|
+
* // rate limit logic
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const productResource = defineResource({
|
|
31
|
+
* name: 'product',
|
|
32
|
+
* adapter,
|
|
33
|
+
* middlewares: sortMiddlewares([verifyEmail, rateLimit]),
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Create a named middleware with priority and conditions.
|
|
39
|
+
*/
|
|
40
|
+
function middleware(name, options) {
|
|
41
|
+
return {
|
|
42
|
+
name,
|
|
43
|
+
operations: options.operations,
|
|
44
|
+
priority: options.priority ?? 10,
|
|
45
|
+
when: options.when,
|
|
46
|
+
handler: options.handler
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sort named middlewares by priority (ascending — lower runs first).
|
|
51
|
+
* Returns a MiddlewareConfig map keyed by operation, ready to pass to `defineResource()`.
|
|
52
|
+
*/
|
|
53
|
+
function sortMiddlewares(middlewares) {
|
|
54
|
+
const sorted = [...middlewares].sort((a, b) => a.priority - b.priority);
|
|
55
|
+
const operations = CRUD_OPERATIONS;
|
|
56
|
+
const result = {};
|
|
57
|
+
for (const op of operations) {
|
|
58
|
+
const applicable = sorted.filter((m) => !m.operations || m.operations.length === 0 || m.operations.includes(op));
|
|
59
|
+
if (applicable.length > 0) result[op] = applicable.map((m) => {
|
|
60
|
+
if (!m.when) return m.handler;
|
|
61
|
+
const wrapped = async (request, reply) => {
|
|
62
|
+
if (await m.when?.(request)) return m.handler(request, reply);
|
|
63
|
+
};
|
|
64
|
+
return wrapped;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { middleware, multipartBody, sortMiddlewares };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//#region src/middleware/multipartBody.ts
|
|
2
|
+
const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
3
|
+
const DEFAULT_MAX_FILES = 5;
|
|
4
|
+
const DEFAULT_FILES_KEY = "_files";
|
|
5
|
+
/**
|
|
6
|
+
* Build a matcher for MIME allow-lists that supports exact (e.g. `image/png`),
|
|
7
|
+
* subtype wildcards (e.g. `image/\*`), and total wildcards (`\*` or `\*\/\*`).
|
|
8
|
+
*
|
|
9
|
+
* Returns `undefined` when no filter is needed — either because the option
|
|
10
|
+
* was omitted or because a total wildcard was present.
|
|
11
|
+
*/
|
|
12
|
+
function buildMimeMatcher(allowed) {
|
|
13
|
+
if (!allowed || allowed.length === 0) return void 0;
|
|
14
|
+
const exact = /* @__PURE__ */ new Set();
|
|
15
|
+
const prefixes = [];
|
|
16
|
+
for (const entry of allowed) {
|
|
17
|
+
const value = entry.trim().toLowerCase();
|
|
18
|
+
if (!value) continue;
|
|
19
|
+
if (value === "*" || value === "*/*") return void 0;
|
|
20
|
+
if (value.endsWith("/*")) prefixes.push(value.slice(0, -1));
|
|
21
|
+
else exact.add(value);
|
|
22
|
+
}
|
|
23
|
+
if (exact.size === 0 && prefixes.length === 0) return void 0;
|
|
24
|
+
return {
|
|
25
|
+
matches(mime) {
|
|
26
|
+
const m = mime.toLowerCase();
|
|
27
|
+
if (exact.has(m)) return true;
|
|
28
|
+
for (const p of prefixes) if (m.startsWith(p)) return true;
|
|
29
|
+
return false;
|
|
30
|
+
},
|
|
31
|
+
describe() {
|
|
32
|
+
return [...exact, ...prefixes.map((p) => `${p}*`)].join(", ");
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a multipart body parsing middleware.
|
|
38
|
+
*
|
|
39
|
+
* When a request has `content-type: multipart/form-data`, this middleware:
|
|
40
|
+
* 1. Reads all parts (fields + files)
|
|
41
|
+
* 2. Sets text fields on `req.body` as a plain object
|
|
42
|
+
* 3. Attaches file buffers to `req.body[filesKey]` (default: `req.body._files`)
|
|
43
|
+
*
|
|
44
|
+
* For non-multipart requests (regular JSON), this is a no-op — the request
|
|
45
|
+
* passes through unchanged. This makes it safe to add to create/update
|
|
46
|
+
* middlewares without breaking JSON clients.
|
|
47
|
+
*/
|
|
48
|
+
function multipartBody(options = {}) {
|
|
49
|
+
const maxFileSize = options.maxFileSize ?? DEFAULT_MAX_FILE_SIZE;
|
|
50
|
+
const maxFiles = options.maxFiles ?? DEFAULT_MAX_FILES;
|
|
51
|
+
const mimeMatcher = buildMimeMatcher(options.allowedMimeTypes);
|
|
52
|
+
const filesKey = options.filesKey ?? DEFAULT_FILES_KEY;
|
|
53
|
+
const requiredFields = options.requiredFields && options.requiredFields.length > 0 ? options.requiredFields : void 0;
|
|
54
|
+
return async function parseMultipartBody(request, reply) {
|
|
55
|
+
if (!(request.headers["content-type"] ?? "").includes("multipart/form-data")) return;
|
|
56
|
+
if (typeof request.parts !== "function") {
|
|
57
|
+
request.log.warn("multipartBody middleware: @fastify/multipart not registered. Ensure createApp() has multipart enabled (default) or install @fastify/multipart.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const body = {};
|
|
61
|
+
const files = {};
|
|
62
|
+
let fileCount = 0;
|
|
63
|
+
try {
|
|
64
|
+
const parts = request.parts();
|
|
65
|
+
for await (const part of parts) if (part.type === "file") {
|
|
66
|
+
if (fileCount >= maxFiles) continue;
|
|
67
|
+
if (mimeMatcher && !mimeMatcher.matches(part.mimetype)) return reply.code(415).send({
|
|
68
|
+
success: false,
|
|
69
|
+
error: `File type '${part.mimetype}' not allowed. Accepted: ${mimeMatcher.describe()}`
|
|
70
|
+
});
|
|
71
|
+
const buffer = await part.toBuffer();
|
|
72
|
+
if (buffer.length > maxFileSize) return reply.code(413).send({
|
|
73
|
+
success: false,
|
|
74
|
+
error: `File '${part.filename}' exceeds maximum size of ${Math.round(maxFileSize / 1024 / 1024)}MB`
|
|
75
|
+
});
|
|
76
|
+
files[part.fieldname] = {
|
|
77
|
+
filename: part.filename,
|
|
78
|
+
mimetype: part.mimetype,
|
|
79
|
+
buffer,
|
|
80
|
+
size: buffer.length,
|
|
81
|
+
fieldname: part.fieldname
|
|
82
|
+
};
|
|
83
|
+
fileCount++;
|
|
84
|
+
} else body[part.fieldname] = tryParseValue(part.value);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
request.log.error({ err }, "multipartBody: failed to parse multipart form");
|
|
87
|
+
return reply.code(400).send({
|
|
88
|
+
success: false,
|
|
89
|
+
error: "Failed to parse multipart form data"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (requiredFields) {
|
|
93
|
+
const missing = requiredFields.filter((name) => !(name in files));
|
|
94
|
+
if (missing.length > 0) return reply.code(400).send({
|
|
95
|
+
success: false,
|
|
96
|
+
error: `Missing required file field${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}`,
|
|
97
|
+
code: "MISSING_FILE_FIELDS",
|
|
98
|
+
details: { missing }
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (fileCount > 0) body[filesKey] = files;
|
|
102
|
+
request.body = body;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Try to parse a form field value as JSON, number, or boolean.
|
|
107
|
+
* Falls back to the raw string if parsing fails.
|
|
108
|
+
*/
|
|
109
|
+
function tryParseValue(value) {
|
|
110
|
+
if (value === "true") return true;
|
|
111
|
+
if (value === "false") return false;
|
|
112
|
+
if (value === "null") return null;
|
|
113
|
+
if (/^-?\d+(\.\d+)?$/.test(value) && value.length < 16) {
|
|
114
|
+
const num = Number(value);
|
|
115
|
+
if (Number.isFinite(num)) return num;
|
|
116
|
+
}
|
|
117
|
+
if (value.startsWith("{") && value.endsWith("}") || value.startsWith("[") && value.endsWith("]")) try {
|
|
118
|
+
return JSON.parse(value);
|
|
119
|
+
} catch {}
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { multipartBody as t };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { t as getUserRoles } from "./types-
|
|
1
|
+
import { t as getUserRoles } from "./types-D57iXYb8.mjs";
|
|
2
2
|
import { n as convertRouteSchema } from "./schemaConverter-BxFDdtXu.mjs";
|
|
3
|
-
import { t as
|
|
3
|
+
import { t as resolveActionPermission } from "./actionPermissions-TUVR3uiZ.mjs";
|
|
4
|
+
import { t as buildActionBodySchema } from "./createActionRouter-C8UUB3Px.mjs";
|
|
4
5
|
import fp from "fastify-plugin";
|
|
5
6
|
//#region src/docs/openapi.ts
|
|
6
7
|
const openApiPlugin = async (fastify, opts = {}) => {
|
|
@@ -327,12 +328,13 @@ function generateResourcePaths(resource, apiPrefix = "", additionalSecurity = []
|
|
|
327
328
|
const descStr = a.description ? ` — ${a.description}` : "";
|
|
328
329
|
descLines.push(`- \`${a.name}\`${roleStr}${descStr}`);
|
|
329
330
|
}
|
|
330
|
-
const fallbackPerm = resource.actionPermissions;
|
|
331
|
-
const fallbackRequiresAuth = typeof fallbackPerm === "function" && !fallbackPerm._isPublic;
|
|
332
331
|
const anyAuthRequired = resource.actions.some((a) => {
|
|
333
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
const effective = resolveActionPermission({
|
|
333
|
+
action: { permissions: a.permissions },
|
|
334
|
+
resourcePermissions: resource.permissions,
|
|
335
|
+
resourceActionPermissions: resource.actionPermissions
|
|
336
|
+
});
|
|
337
|
+
return typeof effective === "function" && !effective._isPublic;
|
|
336
338
|
});
|
|
337
339
|
if (!paths[actionPath]) paths[actionPath] = {};
|
|
338
340
|
paths[actionPath].post = createOperation(resource, "action", `Perform action (${actionEnum.join(" / ")})`, {
|
package/dist/org/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Pt as RouteHandler } from "../index-BGbpGVyM.mjs";
|
|
2
|
+
import { d as UserBase } from "../fields-C8Y0XLAu.mjs";
|
|
3
3
|
import { InvitationAdapter, InvitationDoc, MemberDoc, OrgAdapter, OrgDoc, OrgPermissionStatement, OrgRole, OrganizationPluginOptions } from "./types.mjs";
|
|
4
4
|
import { FastifyPluginAsync, RouteHandlerMethod } from "fastify";
|
|
5
5
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { a as applyFieldWritePermissions, i as applyFieldReadPermissions, n as FieldPermissionMap, o as fields, r as FieldPermissionType, s as resolveEffectiveRoles, t as FieldPermission } from "../fields-
|
|
2
|
-
import { a as
|
|
3
|
-
|
|
4
|
-
export { ConnectEventsOptions, DynamicPermissionMatrix, DynamicPermissionMatrixConfig, FieldPermission, FieldPermissionMap, FieldPermissionType, PermissionCheck, PermissionContext, PermissionEventBus, PermissionResult, RoleHierarchy, UserBase, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, applyPermissionResult, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizePermissionResult, normalizeRoles, ownerWithAdminBypass, presets_d_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, resolveEffectiveRoles, roles, when };
|
|
1
|
+
import { a as applyFieldWritePermissions, c as PermissionCheck, d as UserBase, f as getUserRoles, i as applyFieldReadPermissions, l as PermissionContext, n as FieldPermissionMap, o as fields, p as normalizeRoles, r as FieldPermissionType, s as resolveEffectiveRoles, t as FieldPermission, u as PermissionResult } from "../fields-C8Y0XLAu.mjs";
|
|
2
|
+
import { A as requireRoles, C as allOf, D as not, E as denyAll, M as when, N as applyPermissionResult, O as requireAuth, P as normalizePermissionResult, S as createOrgPermissions, T as anyOf, _ as ConnectEventsOptions, a as presets_d_exports, b as PermissionEventBus, c as readOnly, d as requireOrgRole, f as requireScopeContext, g as createRoleHierarchy, h as RoleHierarchy, i as ownerWithAdminBypass, j as roles, k as requireOwnership, l as requireOrgInScope, m as requireTeamMembership, n as authenticated, o as publicRead, p as requireServiceScope, r as fullPublic, s as publicReadAdminWrite, t as adminOnly, u as requireOrgMembership, v as DynamicPermissionMatrix, w as allowPublic, x as createDynamicPermissionMatrix, y as DynamicPermissionMatrixConfig } from "../index-C_Noptz-.mjs";
|
|
3
|
+
export { ConnectEventsOptions, DynamicPermissionMatrix, DynamicPermissionMatrixConfig, FieldPermission, FieldPermissionMap, FieldPermissionType, PermissionCheck, PermissionContext, PermissionEventBus, PermissionResult, RoleHierarchy, UserBase, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, applyPermissionResult, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizePermissionResult, normalizeRoles, not, ownerWithAdminBypass, presets_d_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, resolveEffectiveRoles, roles, when };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as resolveEffectiveRoles, n as applyFieldWritePermissions, r as fields, t as applyFieldReadPermissions } from "../fields-
|
|
2
|
-
import { n as normalizeRoles, t as getUserRoles } from "../types-
|
|
3
|
-
import { n as normalizePermissionResult, t as applyPermissionResult } from "../applyPermissionResult-
|
|
4
|
-
import { C as
|
|
5
|
-
export { adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, applyPermissionResult, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizePermissionResult, normalizeRoles, ownerWithAdminBypass, presets_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, resolveEffectiveRoles, roles, when };
|
|
1
|
+
import { i as resolveEffectiveRoles, n as applyFieldWritePermissions, r as fields, t as applyFieldReadPermissions } from "../fields-CTMWOUDt.mjs";
|
|
2
|
+
import { n as normalizeRoles, t as getUserRoles } from "../types-D57iXYb8.mjs";
|
|
3
|
+
import { n as normalizePermissionResult, t as applyPermissionResult } from "../applyPermissionResult-QhV1Pa-g.mjs";
|
|
4
|
+
import { C as requireAuth, D as when, E as roles, S as not, T as requireRoles, _ as requireTeamMembership, a as presets_exports, b as anyOf, c as readOnly, d as createOrgPermissions, f as requireOrgInScope, g as requireServiceScope, h as requireScopeContext, i as ownerWithAdminBypass, l as createRoleHierarchy, m as requireOrgRole, n as authenticated, o as publicRead, p as requireOrgMembership, r as fullPublic, s as publicReadAdminWrite, t as adminOnly, u as createDynamicPermissionMatrix, v as allOf, w as requireOwnership, x as denyAll, y as allowPublic } from "../permissions-wkqRwicB.mjs";
|
|
5
|
+
export { adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, applyPermissionResult, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizePermissionResult, normalizeRoles, not, ownerWithAdminBypass, presets_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgInScope, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireScopeContext, requireServiceScope, requireTeamMembership, resolveEffectiveRoles, roles, when };
|