@classytic/arc 2.4.3 → 2.6.1
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 +22 -6
- package/dist/{BaseController-CkM5dUh_.mjs → BaseController-AbbRx3e0.mjs} +5 -2
- package/dist/adapters/index.d.mts +2 -2
- package/dist/adapters/index.mjs +1 -1
- package/dist/{adapters-DTC4Ug66.mjs → adapters-CTn28N4y.mjs} +72 -11
- package/dist/audit/index.d.mts +1 -1
- package/dist/audit/index.mjs +11 -1
- package/dist/audit/mongodb.d.mts +1 -1
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.mjs +2 -2
- package/dist/cli/commands/init.mjs +12 -9
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +2 -2
- package/dist/{createApp-CBgVaFyh.mjs → createApp-Bol7DLUf.mjs} +404 -279
- package/dist/{defineResource-B22gcNvn.mjs → defineResource-bVKHjQzE.mjs} +116 -19
- package/dist/discovery/index.mjs +1 -1
- package/dist/docs/index.d.mts +1 -1
- package/dist/dynamic/index.d.mts +1 -1
- package/dist/dynamic/index.mjs +2 -2
- package/dist/{elevation-Ca_yveIO.d.mts → elevation-C_taLQrM.d.mts} +27 -1
- package/dist/{errorHandler-DMbGdzBG.mjs → errorHandler-r2595m8T.mjs} +1 -1
- package/dist/{errors-CPpvPHT0.d.mts → errors-CcVbl1-T.d.mts} +17 -1
- package/dist/{errors-rxhfP7Hf.mjs → errors-NoQKsbAT.mjs} +23 -1
- package/dist/{eventPlugin-iGrSEmwJ.d.mts → eventPlugin-DW45v4V5.d.mts} +30 -2
- package/dist/events/index.d.mts +2 -2
- package/dist/events/index.mjs +40 -10
- package/dist/factory/index.d.mts +44 -23
- package/dist/factory/index.mjs +136 -2
- package/dist/hooks/index.d.mts +1 -1
- package/dist/idempotency/index.d.mts +3 -3
- package/dist/idempotency/mongodb.d.mts +1 -1
- package/dist/idempotency/redis.d.mts +1 -1
- package/dist/{index-yhxyjqNb.d.mts → index-BIsZ_su5.d.mts} +4 -8
- package/dist/{index-BL8CaQih.d.mts → index-Cb3gtbg7.d.mts} +2 -2
- package/dist/{index-Diqcm14c.d.mts → index-NGZksqM5.d.mts} +30 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.mjs +8 -7
- package/dist/integrations/event-gateway.mjs +1 -1
- package/dist/integrations/index.d.mts +1 -1
- package/dist/integrations/mcp/index.d.mts +4 -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-DGmPxakH.d.mts → interface-DDW43OmS.d.mts} +194 -13
- package/dist/{mongodb-CUpYfxfD.d.mts → mongodb-kltrBPa1.d.mts} +10 -0
- package/dist/{mongodb-bga9AbkD.d.mts → mongodb-pMvOlR5_.d.mts} +1 -1
- package/dist/org/index.d.mts +1 -1
- package/dist/org/index.mjs +1 -1
- package/dist/permissions/index.d.mts +2 -2
- package/dist/permissions/index.mjs +2 -2
- package/dist/{permissions-Jk5x3sxz.mjs → permissions-C8ImI8gC.mjs} +44 -2
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.mjs +3 -3
- package/dist/plugins/tracing-entry.mjs +1 -1
- package/dist/presets/index.d.mts +1 -1
- package/dist/presets/index.mjs +1 -1
- package/dist/presets/multiTenant.d.mts +1 -1
- package/dist/presets/multiTenant.mjs +1 -1
- package/dist/{presets-OMPaHMTY.mjs → presets-BMfdy34e.mjs} +2 -2
- package/dist/{redis-CQ5YxMC5.d.mts → redis-D0Qc-9EW.d.mts} +1 -1
- package/dist/registry/index.d.mts +1 -1
- package/dist/{resourceToTools-PMFE8HIv.mjs → resourceToTools-DH3c3e-T.mjs} +81 -7
- package/dist/scope/index.d.mts +2 -2
- package/dist/scope/index.mjs +2 -2
- package/dist/{sse-BkViJPlT.mjs → sse-BF7GR7IB.mjs} +1 -1
- package/dist/testing/index.d.mts +2 -2
- package/dist/testing/index.mjs +1 -1
- package/dist/types/index.d.mts +3 -3
- package/dist/types/index.mjs +23 -2
- package/dist/{types-C6TQjtdi.mjs → types-BhtYdxZU.mjs} +26 -1
- package/dist/{types-Dt0-AI6E.d.mts → types-D5hJ-k_3.d.mts} +189 -6
- package/dist/{types-BJmgxNbF.d.mts → types-D5rjsS_i.d.mts} +1 -1
- package/dist/utils/index.d.mts +2 -2
- package/dist/utils/index.mjs +1 -1
- package/package.json +6 -5
- package/skills/arc/SKILL.md +104 -4
- package/skills/arc/references/mcp.md +160 -2
- /package/dist/{interface-B4awm1RJ.d.mts → interface-gr-7qo9j.d.mts} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as RequestScope } from "./elevation-
|
|
1
|
+
import { s as RequestScope } from "./elevation-C_taLQrM.mjs";
|
|
2
2
|
import { n as FieldPermissionMap } from "./fields-DFwdaWCq.mjs";
|
|
3
3
|
import { i as UserBase, t as PermissionCheck } from "./types-BNUccdcf.mjs";
|
|
4
4
|
import { FastifyInstance, FastifyPluginAsync, FastifyReply, FastifyRequest, RouteHandlerMethod, RouteHandlerMethod as RouteHandlerMethod$1 } from "fastify";
|
|
@@ -474,6 +474,7 @@ declare class ResourceDefinition<TDoc = AnyRecord> {
|
|
|
474
474
|
readonly pipe?: PipelineConfig;
|
|
475
475
|
readonly fields?: FieldPermissionMap;
|
|
476
476
|
readonly cache?: ResourceCacheConfig;
|
|
477
|
+
readonly skipGlobalPrefix: boolean;
|
|
477
478
|
readonly tenantField?: string | false;
|
|
478
479
|
readonly idField?: string;
|
|
479
480
|
readonly queryParser?: QueryParserInterface;
|
|
@@ -1073,6 +1074,46 @@ declare module 'fastify' {
|
|
|
1073
1074
|
_ownershipCheck?: Record<string, unknown>;
|
|
1074
1075
|
}
|
|
1075
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Typed Fastify request with Arc decorations.
|
|
1079
|
+
*
|
|
1080
|
+
* Use this in `wrapHandler: false` handlers instead of `(req as any).user`.
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* ```typescript
|
|
1084
|
+
* import type { ArcRequest } from '@classytic/arc';
|
|
1085
|
+
*
|
|
1086
|
+
* handler: async (req: ArcRequest, reply: FastifyReply) => {
|
|
1087
|
+
* req.user?.id; // typed
|
|
1088
|
+
* req.scope.organizationId; // typed (when member)
|
|
1089
|
+
* req.signal; // AbortSignal (Fastify 5)
|
|
1090
|
+
* }
|
|
1091
|
+
* ```
|
|
1092
|
+
*/
|
|
1093
|
+
type ArcRequest = FastifyRequest & {
|
|
1094
|
+
scope: RequestScope;
|
|
1095
|
+
user: Record<string, unknown> | undefined;
|
|
1096
|
+
signal: AbortSignal;
|
|
1097
|
+
};
|
|
1098
|
+
/**
|
|
1099
|
+
* Response envelope helper — wraps data in Arc's standard `{ success, data }` format.
|
|
1100
|
+
*
|
|
1101
|
+
* @example
|
|
1102
|
+
* ```typescript
|
|
1103
|
+
* import { envelope } from '@classytic/arc';
|
|
1104
|
+
*
|
|
1105
|
+
* handler: async (req, reply) => {
|
|
1106
|
+
* const data = await getResults();
|
|
1107
|
+
* return envelope(data);
|
|
1108
|
+
* // → { success: true, data }
|
|
1109
|
+
* }
|
|
1110
|
+
* ```
|
|
1111
|
+
*/
|
|
1112
|
+
declare function envelope<T>(data: T, meta?: Record<string, unknown>): {
|
|
1113
|
+
success: true;
|
|
1114
|
+
data: T;
|
|
1115
|
+
[key: string]: unknown;
|
|
1116
|
+
};
|
|
1076
1117
|
type AnyRecord = Record<string, unknown>;
|
|
1077
1118
|
/** MongoDB ObjectId — accepts string or any object with a `toString()` (e.g. mongoose ObjectId). */
|
|
1078
1119
|
type ObjectId = string | {
|
|
@@ -1188,8 +1229,8 @@ interface LookupOption {
|
|
|
1188
1229
|
as?: string;
|
|
1189
1230
|
/** Return a single object instead of array (default: false) */
|
|
1190
1231
|
single?: boolean;
|
|
1191
|
-
/** Field selection on the joined collection (comma-separated) */
|
|
1192
|
-
select?: string
|
|
1232
|
+
/** Field selection on the joined collection (comma-separated string or projection object) */
|
|
1233
|
+
select?: string | Record<string, 0 | 1>;
|
|
1193
1234
|
}
|
|
1194
1235
|
/**
|
|
1195
1236
|
* Mongoose-compatible populate option for advanced field selection
|
|
@@ -1412,6 +1453,18 @@ interface ResourceConfig<TDoc = AnyRecord> {
|
|
|
1412
1453
|
displayName?: string;
|
|
1413
1454
|
tag?: string;
|
|
1414
1455
|
prefix?: string;
|
|
1456
|
+
/**
|
|
1457
|
+
* Skip the global `resourcePrefix` from `createApp()`.
|
|
1458
|
+
* The resource registers at its own `prefix` (or `/${name}s`) directly on root.
|
|
1459
|
+
* Useful for webhooks, health, admin routes that shouldn't be under `/api/v1`.
|
|
1460
|
+
*
|
|
1461
|
+
* @example
|
|
1462
|
+
* ```typescript
|
|
1463
|
+
* defineResource({ name: 'webhook', prefix: '/webhooks', skipGlobalPrefix: true })
|
|
1464
|
+
* // Registers at /webhooks even when createApp({ resourcePrefix: '/api/v1' })
|
|
1465
|
+
* ```
|
|
1466
|
+
*/
|
|
1467
|
+
skipGlobalPrefix?: boolean;
|
|
1415
1468
|
adapter?: DataAdapter<TDoc>;
|
|
1416
1469
|
/** Controller instance - accepts any object with CRUD methods */
|
|
1417
1470
|
controller?: IController<TDoc> | ControllerLike;
|
|
@@ -1475,6 +1528,22 @@ interface ResourceConfig<TDoc = AnyRecord> {
|
|
|
1475
1528
|
skipValidation?: boolean;
|
|
1476
1529
|
skipRegistry?: boolean;
|
|
1477
1530
|
_appliedPresets?: string[];
|
|
1531
|
+
/**
|
|
1532
|
+
* Called during plugin registration with the scoped Fastify instance.
|
|
1533
|
+
* Use for wiring singletons, reading decorators, or setting up resource-specific
|
|
1534
|
+
* services that need access to the Fastify instance.
|
|
1535
|
+
*
|
|
1536
|
+
* @example
|
|
1537
|
+
* ```typescript
|
|
1538
|
+
* defineResource({
|
|
1539
|
+
* name: 'notification',
|
|
1540
|
+
* onRegister: (fastify) => {
|
|
1541
|
+
* setSseManager(fastify.sseManager);
|
|
1542
|
+
* },
|
|
1543
|
+
* })
|
|
1544
|
+
* ```
|
|
1545
|
+
*/
|
|
1546
|
+
onRegister?: (fastify: FastifyInstance) => void | Promise<void>;
|
|
1478
1547
|
/** HTTP method for update routes. Default: 'PATCH' */
|
|
1479
1548
|
updateMethod?: 'PUT' | 'PATCH' | 'both';
|
|
1480
1549
|
/**
|
|
@@ -1501,13 +1570,53 @@ interface ResourcePermissions {
|
|
|
1501
1570
|
update?: PermissionCheck;
|
|
1502
1571
|
delete?: PermissionCheck;
|
|
1503
1572
|
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Hook context passed to resource-level hook handlers.
|
|
1575
|
+
* Mirrors HookSystem's HookContext but with a simpler API for inline use.
|
|
1576
|
+
*/
|
|
1577
|
+
interface ResourceHookContext {
|
|
1578
|
+
/** The document data (create/update body, or existing doc for delete) */
|
|
1579
|
+
data: AnyRecord;
|
|
1580
|
+
/** Authenticated user or null */
|
|
1581
|
+
user?: UserBase;
|
|
1582
|
+
/** Additional metadata (e.g. `{ id, existing }` for update/delete) */
|
|
1583
|
+
meta?: AnyRecord;
|
|
1584
|
+
}
|
|
1585
|
+
/**
|
|
1586
|
+
* Inline lifecycle hooks on a resource definition.
|
|
1587
|
+
* These are wired into the HookSystem automatically — same pipeline as presets and app-level hooks.
|
|
1588
|
+
*
|
|
1589
|
+
* @example
|
|
1590
|
+
* ```typescript
|
|
1591
|
+
* defineResource({
|
|
1592
|
+
* name: 'chat',
|
|
1593
|
+
* hooks: {
|
|
1594
|
+
* afterCreate: async (ctx) => {
|
|
1595
|
+
* analytics.track('chat.created', { chatId: ctx.data._id, userId: ctx.user?.id });
|
|
1596
|
+
* },
|
|
1597
|
+
* beforeDelete: async (ctx) => {
|
|
1598
|
+
* if (ctx.data.isProtected) throw new Error('Cannot delete protected chat');
|
|
1599
|
+
* },
|
|
1600
|
+
* afterDelete: async (ctx) => {
|
|
1601
|
+
* await notificationService.send('chat.deleted', { id: ctx.meta?.id });
|
|
1602
|
+
* },
|
|
1603
|
+
* },
|
|
1604
|
+
* });
|
|
1605
|
+
* ```
|
|
1606
|
+
*/
|
|
1504
1607
|
interface ResourceHooks {
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1608
|
+
/** Runs before create — can modify data by returning a new object */
|
|
1609
|
+
beforeCreate?: (ctx: ResourceHookContext) => Promise<AnyRecord | void> | AnyRecord | void;
|
|
1610
|
+
/** Runs after create — receives the created document */
|
|
1611
|
+
afterCreate?: (ctx: ResourceHookContext) => Promise<void> | void;
|
|
1612
|
+
/** Runs before update — ctx.meta.id has the resource ID, ctx.meta.existing has the current doc */
|
|
1613
|
+
beforeUpdate?: (ctx: ResourceHookContext) => Promise<AnyRecord | void> | AnyRecord | void;
|
|
1614
|
+
/** Runs after update — receives the updated document */
|
|
1615
|
+
afterUpdate?: (ctx: ResourceHookContext) => Promise<void> | void;
|
|
1616
|
+
/** Runs before delete — ctx.data is the existing doc, ctx.meta.id has the resource ID */
|
|
1617
|
+
beforeDelete?: (ctx: ResourceHookContext) => Promise<void> | void;
|
|
1618
|
+
/** Runs after delete — ctx.data is the deleted doc, ctx.meta.id has the resource ID */
|
|
1619
|
+
afterDelete?: (ctx: ResourceHookContext) => Promise<void> | void;
|
|
1511
1620
|
}
|
|
1512
1621
|
/**
|
|
1513
1622
|
* Additional route definition for custom endpoints
|
|
@@ -1518,10 +1627,16 @@ interface AdditionalRoute {
|
|
|
1518
1627
|
/** Route path (relative to resource prefix) */
|
|
1519
1628
|
path: string;
|
|
1520
1629
|
/**
|
|
1521
|
-
* Handler - string (controller method name) or function
|
|
1522
|
-
*
|
|
1630
|
+
* Handler - string (controller method name) or function.
|
|
1631
|
+
*
|
|
1632
|
+
* When `wrapHandler: true`:
|
|
1633
|
+
* - `string` — calls controller method by name (e.g., `'approve'`)
|
|
1634
|
+
* - `ControllerHandler` — receives `IRequestContext`, returns `IControllerResponse`
|
|
1635
|
+
*
|
|
1636
|
+
* When `wrapHandler: false`:
|
|
1637
|
+
* - Fastify handler `(request, reply) => unknown`
|
|
1523
1638
|
*/
|
|
1524
|
-
handler: string | RouteHandlerMethod | ((request: FastifyRequest<any>, reply: FastifyReply) => unknown);
|
|
1639
|
+
handler: string | ControllerHandler | RouteHandlerMethod | ((request: FastifyRequest<any>, reply: FastifyReply) => unknown);
|
|
1525
1640
|
/** Permission check - REQUIRED */
|
|
1526
1641
|
permissions: PermissionCheck;
|
|
1527
1642
|
/**
|
|
@@ -1556,6 +1671,41 @@ interface AdditionalRoute {
|
|
|
1556
1671
|
* preHandler: (fastify) => [fastify.customerContext({ required: true })]
|
|
1557
1672
|
*/
|
|
1558
1673
|
preHandler?: RouteHandlerMethod[] | ((fastify: FastifyInstance) => RouteHandlerMethod[]);
|
|
1674
|
+
/**
|
|
1675
|
+
* Pre-auth handlers — run BEFORE authentication middleware.
|
|
1676
|
+
* Use for promoting query params to headers (e.g., EventSource ?token= → Authorization).
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* ```typescript
|
|
1680
|
+
* preAuth: [(req) => {
|
|
1681
|
+
* const token = (req.query as Record<string, string>)?.token;
|
|
1682
|
+
* if (token) req.headers.authorization = `Bearer ${token}`;
|
|
1683
|
+
* }]
|
|
1684
|
+
* ```
|
|
1685
|
+
*/
|
|
1686
|
+
preAuth?: RouteHandlerMethod[];
|
|
1687
|
+
/**
|
|
1688
|
+
* Streaming response mode — designed for SSE and AI streaming routes.
|
|
1689
|
+
* When `true`:
|
|
1690
|
+
* - Forces `wrapHandler: false` (no `{ success, data }` wrapper)
|
|
1691
|
+
* - Sets SSE headers: `Content-Type: text/event-stream`, `Cache-Control: no-cache`, `Connection: keep-alive`
|
|
1692
|
+
* - `request.signal` (Fastify 5 built-in) is available for abort-on-disconnect
|
|
1693
|
+
*
|
|
1694
|
+
* @example
|
|
1695
|
+
* ```typescript
|
|
1696
|
+
* {
|
|
1697
|
+
* method: 'POST',
|
|
1698
|
+
* path: '/stream',
|
|
1699
|
+
* streamResponse: true,
|
|
1700
|
+
* permissions: requireAuth(),
|
|
1701
|
+
* handler: async (request, reply) => {
|
|
1702
|
+
* const { stream } = await generateStream({ abortSignal: request.signal });
|
|
1703
|
+
* return reply.send(stream);
|
|
1704
|
+
* },
|
|
1705
|
+
* }
|
|
1706
|
+
* ```
|
|
1707
|
+
*/
|
|
1708
|
+
streamResponse?: boolean;
|
|
1559
1709
|
/** Fastify route schema */
|
|
1560
1710
|
schema?: Record<string, unknown>;
|
|
1561
1711
|
/**
|
|
@@ -2126,12 +2276,43 @@ type TypedRepository<TDoc> = CrudRepository<TDoc>;
|
|
|
2126
2276
|
*
|
|
2127
2277
|
* CrudRepository<TDoc> and MongoKit Repository both satisfy this interface.
|
|
2128
2278
|
*/
|
|
2279
|
+
/**
|
|
2280
|
+
* Minimal repository interface for flexible adapter compatibility.
|
|
2281
|
+
* Any repository with these method signatures is accepted.
|
|
2282
|
+
*
|
|
2283
|
+
* **Required** — core CRUD (every resource needs these):
|
|
2284
|
+
* getAll, getById, create, update, delete
|
|
2285
|
+
*
|
|
2286
|
+
* **Recommended** — used by AccessControl for compound queries:
|
|
2287
|
+
* getOne
|
|
2288
|
+
*
|
|
2289
|
+
* **Optional** — enabled by presets, checked at runtime:
|
|
2290
|
+
* getBySlug — slugLookup preset
|
|
2291
|
+
* getDeleted — softDelete preset (list soft-deleted)
|
|
2292
|
+
* restore — softDelete preset (restore soft-deleted)
|
|
2293
|
+
* getTree — tree preset (hierarchical queries)
|
|
2294
|
+
* getChildren — tree preset (child nodes)
|
|
2295
|
+
* createMany — bulk preset (batch create)
|
|
2296
|
+
* updateMany — bulk preset (batch update by filter)
|
|
2297
|
+
* deleteMany — bulk preset (batch delete by filter)
|
|
2298
|
+
*/
|
|
2129
2299
|
interface RepositoryLike {
|
|
2130
2300
|
getAll(params?: unknown): Promise<unknown>;
|
|
2131
2301
|
getById(id: string, options?: unknown): Promise<unknown>;
|
|
2132
2302
|
create(data: unknown, options?: unknown): Promise<unknown>;
|
|
2133
2303
|
update(id: string, data: unknown, options?: unknown): Promise<unknown>;
|
|
2134
2304
|
delete(id: string, options?: unknown): Promise<unknown>;
|
|
2305
|
+
/** Find single doc by compound filter — used by AccessControl for idField + org/policy scoping.
|
|
2306
|
+
* Without this, Arc falls back to getById + post-fetch security checks. */
|
|
2307
|
+
getOne?(filter: Record<string, unknown>, options?: unknown): Promise<unknown>;
|
|
2308
|
+
getBySlug?(slug: string, options?: unknown): Promise<unknown>;
|
|
2309
|
+
getDeleted?(options?: unknown): Promise<unknown>;
|
|
2310
|
+
restore?(id: string): Promise<unknown>;
|
|
2311
|
+
getTree?(options?: unknown): Promise<unknown>;
|
|
2312
|
+
getChildren?(parentId: string, options?: unknown): Promise<unknown>;
|
|
2313
|
+
createMany?(items: unknown[], options?: unknown): Promise<unknown>;
|
|
2314
|
+
updateMany?(filter: Record<string, unknown>, data: unknown): Promise<unknown>;
|
|
2315
|
+
deleteMany?(filter: Record<string, unknown>): Promise<unknown>;
|
|
2135
2316
|
[key: string]: unknown;
|
|
2136
2317
|
}
|
|
2137
2318
|
interface DataAdapter<TDoc = unknown> {
|
|
@@ -2210,4 +2391,4 @@ interface ValidationResult {
|
|
|
2210
2391
|
}
|
|
2211
2392
|
type AdapterFactory<TDoc> = (config: unknown) => DataAdapter<TDoc>;
|
|
2212
2393
|
//#endregion
|
|
2213
|
-
export {
|
|
2394
|
+
export { RegistryEntry as $, PipelineStep as $t, GracefulShutdownOptions as A, AccessControlConfig as At, LookupOption as B, ResourceDefinition as Bt, CrudSchemas as C, BaseController as Ct, FastifyWithAuth as D, BodySanitizer as Dt, FastifyRequestExtras as E, QueryResolverConfig as Et, InferResourceDoc as F, IControllerResponse as Ft, OwnershipCheck as G, PaginationParams as Gt, MiddlewareHandler as H, CrudRepository as Ht, IntrospectionData as I, IRequestContext as It, PresetFunction as J, Interceptor as Jt, ParsedQuery as K, QueryOptions as Kt, IntrospectionPluginOptions as L, RouteHandler as Lt, HealthOptions as M, ControllerLike as Mt, InferAdapterDoc as N, FastifyHandler as Nt, FastifyWithDecorators as O, BodySanitizerConfig as Ot, InferDocType as P, IController as Pt, RateLimitConfig as Q, PipelineContext as Qt, JWTPayload as R, RegisterOptions as Rt, CrudRouterOptions as S, getUserId as St, EventsDecorator as T, QueryResolver as Tt, ObjectId as U, InferDoc as Ut, MiddlewareConfig as V, defineResource as Vt, OpenApiSchemas as W, PaginatedResult as Wt, PresetResult as X, OperationFilter as Xt, PresetHook as Y, NextFunction as Yt, QueryParserInterface as Z, PipelineConfig as Zt, AuthenticatorContext as _, UserLike as _t, RepositoryLike as a, HookPhase as an, ResourceConfig as at, CrudController as b, ValidationResult$1 as bt, AdditionalRoute as c, HookSystemOptions as cn, ResourceMetadata as ct, ArcDecorator as d, afterUpdate as dn, RouteSchemaOptions as dt, Transform as en, RegistryStats as et, ArcInternalMetadata as f, beforeCreate as fn, ServiceContext as ft, Authenticator as g, defineHook as gn, TypedResourceConfig as gt, AuthPluginOptions as h, createHookSystem as hn, TypedRepository as ht, RelationMetadata as i, HookOperation as in, ResourceCacheConfig as it, HealthCheck as j, ControllerHandler as jt, FieldRule as k, AccessControl as kt, AnyRecord as l, afterCreate as ln, ResourcePermissions as lt, AuthHelpers as m, beforeUpdate as mn, TypedController as mt, DataAdapter as n, HookContext as nn, RequestIdOptions as nt, SchemaMetadata as o, HookRegistration as on, ResourceHookContext as ot, ArcRequest as p, beforeDelete as pn, TokenPair as pt, PopulateOption as q, Guard as qt, FieldMetadata as r, HookHandler as rn, RequestWithExtras as rt, ValidationResult as s, HookSystem as sn, ResourceHooks as st, AdapterFactory as t, DefineHookOptions as tn, RequestContext as tt, ApiResponse as u, afterDelete as un, RouteHandlerMethod$1 as ut, ConfigError as v, UserOrganization as vt, EventDefinition as w, BaseControllerOptions as wt, CrudRouteKey as x, envelope as xt, ControllerQueryOptions as y, ValidateOptions as yt, JwtContext as z, ResourceRegistry as zt };
|
|
@@ -89,6 +89,16 @@ interface MongoAuditStoreOptions {
|
|
|
89
89
|
/** TTL in days (default: 90, 0 = no expiry) */
|
|
90
90
|
ttlDays?: number;
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Minimal MongoDB connection interface — DB-agnostic.
|
|
94
|
+
*
|
|
95
|
+
* Accepts:
|
|
96
|
+
* - Native MongoDB `Db` instance (has `.collection()`)
|
|
97
|
+
* - Mongoose `connection.db` (has `.collection()`)
|
|
98
|
+
* - Any object with `.collection(name)` method
|
|
99
|
+
*
|
|
100
|
+
* For Mongoose users: pass `mongoose.connection.db`, not `mongoose.connection`.
|
|
101
|
+
*/
|
|
92
102
|
interface MongoConnection {
|
|
93
103
|
collection: (name: string) => MongoCollection;
|
|
94
104
|
}
|
package/dist/org/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Lt as RouteHandler } from "../interface-DDW43OmS.mjs";
|
|
2
2
|
import { i as UserBase } from "../types-BNUccdcf.mjs";
|
|
3
3
|
import { InvitationAdapter, InvitationDoc, MemberDoc, OrgAdapter, OrgDoc, OrgPermissionStatement, OrgRole, OrganizationPluginOptions } from "./types.mjs";
|
|
4
4
|
import { FastifyPluginAsync, RouteHandlerMethod } from "fastify";
|
package/dist/org/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as getOrgRoles, d as isElevated, f as isMember, l as hasOrgAccess, n as PUBLIC_SCOPE } from "../types-BhtYdxZU.mjs";
|
|
2
2
|
import fp from "fastify-plugin";
|
|
3
3
|
//#region src/org/organizationPlugin.ts
|
|
4
4
|
const DEFAULT_ROLES = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
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-DFwdaWCq.mjs";
|
|
2
2
|
import { a as getUserRoles, i as UserBase, n as PermissionContext, o as normalizeRoles, r as PermissionResult, t as PermissionCheck } from "../types-BNUccdcf.mjs";
|
|
3
|
-
import { C as
|
|
4
|
-
export { ConnectEventsOptions, DynamicPermissionMatrix, DynamicPermissionMatrixConfig, FieldPermission, FieldPermissionMap, FieldPermissionType, PermissionCheck, PermissionContext, PermissionEventBus, PermissionResult, RoleHierarchy, UserBase, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizeRoles, ownerWithAdminBypass, presets_d_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireTeamMembership, resolveEffectiveRoles, when };
|
|
3
|
+
import { C as presets_d_exports, D as RoleHierarchy, E as readOnly, O as createRoleHierarchy, S as ownerWithAdminBypass, T as publicReadAdminWrite, _ as roles, a as allOf, b as authenticated, c as createDynamicPermissionMatrix, d as requireAuth, f as requireOrgMembership, g as requireTeamMembership, h as requireRoles, i as PermissionEventBus, l as createOrgPermissions, m as requireOwnership, n as DynamicPermissionMatrix, o as allowPublic, p as requireOrgRole, r as DynamicPermissionMatrixConfig, s as anyOf, t as ConnectEventsOptions, u as denyAll, v as when, w as publicRead, x as fullPublic, y as adminOnly } from "../index-NGZksqM5.mjs";
|
|
4
|
+
export { ConnectEventsOptions, DynamicPermissionMatrix, DynamicPermissionMatrixConfig, FieldPermission, FieldPermissionMap, FieldPermissionType, PermissionCheck, PermissionContext, PermissionEventBus, PermissionResult, RoleHierarchy, UserBase, adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizeRoles, ownerWithAdminBypass, presets_d_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireTeamMembership, resolveEffectiveRoles, roles, when };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { i as resolveEffectiveRoles, n as applyFieldWritePermissions, r as fields, t as applyFieldReadPermissions } from "../fields-ipsbIRPK.mjs";
|
|
2
2
|
import { n as normalizeRoles, t as getUserRoles } from "../types-ZUu_h0jp.mjs";
|
|
3
|
-
import {
|
|
4
|
-
export { adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizeRoles, ownerWithAdminBypass, presets_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireTeamMembership, resolveEffectiveRoles, when };
|
|
3
|
+
import { C as createRoleHierarchy, S as readOnly, _ as fullPublic, a as createOrgPermissions, b as publicRead, c as requireOrgMembership, d as requireRoles, f as requireTeamMembership, g as authenticated, h as adminOnly, i as createDynamicPermissionMatrix, l as requireOrgRole, m as when, n as allowPublic, o as denyAll, p as roles, r as anyOf, s as requireAuth, t as allOf, u as requireOwnership, v as ownerWithAdminBypass, x as publicReadAdminWrite, y as presets_exports } from "../permissions-C8ImI8gC.mjs";
|
|
4
|
+
export { adminOnly, allOf, allowPublic, anyOf, applyFieldReadPermissions, applyFieldWritePermissions, authenticated, createDynamicPermissionMatrix, createOrgPermissions, createRoleHierarchy, denyAll, fields, fullPublic, getUserRoles, normalizeRoles, ownerWithAdminBypass, presets_exports as permissions, publicRead, publicReadAdminWrite, readOnly, requireAuth, requireOrgMembership, requireOrgRole, requireOwnership, requireRoles, requireTeamMembership, resolveEffectiveRoles, roles, when };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { d as isElevated, f as isMember, n as PUBLIC_SCOPE, o as getTeamId, s as getUserId } from "./types-BhtYdxZU.mjs";
|
|
3
3
|
import { t as getUserRoles } from "./types-ZUu_h0jp.mjs";
|
|
4
4
|
import { t as MemoryCacheStore } from "./memory-BFAYkf8H.mjs";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
@@ -244,6 +244,10 @@ function requireRoles(roles, options) {
|
|
|
244
244
|
const userRoles = getUserRoles(ctx.user);
|
|
245
245
|
if (options?.bypassRoles?.some((r) => userRoles.includes(r))) return true;
|
|
246
246
|
if (roles.some((r) => userRoles.includes(r))) return true;
|
|
247
|
+
if (options?.includeOrgRoles) {
|
|
248
|
+
const scope = getScope(ctx.request);
|
|
249
|
+
if (isMember(scope) && roles.some((r) => scope.orgRoles.includes(r))) return true;
|
|
250
|
+
}
|
|
247
251
|
return {
|
|
248
252
|
granted: false,
|
|
249
253
|
reason: `Required roles: ${roles.join(", ")}`
|
|
@@ -253,6 +257,44 @@ function requireRoles(roles, options) {
|
|
|
253
257
|
return check;
|
|
254
258
|
}
|
|
255
259
|
/**
|
|
260
|
+
* Unified role check — checks both platform roles AND org roles.
|
|
261
|
+
*
|
|
262
|
+
* This is the recommended helper for Better Auth organization plugin users.
|
|
263
|
+
* It checks `user.role` (platform) first, then `scope.orgRoles` (org membership).
|
|
264
|
+
* Elevated scope always passes.
|
|
265
|
+
*
|
|
266
|
+
* For platform-only checks: use `requireRoles(['admin'])`
|
|
267
|
+
* For org-only checks: use `requireOrgRole('admin')`
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* permissions: {
|
|
272
|
+
* create: roles('admin', 'editor'), // passes if user has role at either level
|
|
273
|
+
* delete: roles('admin'),
|
|
274
|
+
* }
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
function roles(...args) {
|
|
278
|
+
const roleList = Array.isArray(args[0]) ? args[0] : args;
|
|
279
|
+
const check = (ctx) => {
|
|
280
|
+
if (!ctx.user) return {
|
|
281
|
+
granted: false,
|
|
282
|
+
reason: "Authentication required"
|
|
283
|
+
};
|
|
284
|
+
const userRoles = getUserRoles(ctx.user);
|
|
285
|
+
if (roleList.some((r) => userRoles.includes(r))) return true;
|
|
286
|
+
const scope = getScope(ctx.request);
|
|
287
|
+
if (isElevated(scope)) return true;
|
|
288
|
+
if (isMember(scope) && roleList.some((r) => scope.orgRoles.includes(r))) return true;
|
|
289
|
+
return {
|
|
290
|
+
granted: false,
|
|
291
|
+
reason: `Required roles: ${roleList.join(", ")}`
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
check._roles = roleList;
|
|
295
|
+
return check;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
256
298
|
* Require resource ownership
|
|
257
299
|
*
|
|
258
300
|
* Returns filters to scope queries to user's owned resources.
|
|
@@ -748,4 +790,4 @@ function requireTeamMembership() {
|
|
|
748
790
|
return check;
|
|
749
791
|
}
|
|
750
792
|
//#endregion
|
|
751
|
-
export { createRoleHierarchy as S,
|
|
793
|
+
export { createRoleHierarchy as C, readOnly as S, fullPublic as _, createOrgPermissions as a, publicRead as b, requireOrgMembership as c, requireRoles as d, requireTeamMembership as f, authenticated as g, adminOnly as h, createDynamicPermissionMatrix as i, requireOrgRole as l, when as m, allowPublic as n, denyAll as o, roles as p, anyOf as r, requireAuth as s, allOf as t, requireOwnership as u, ownerWithAdminBypass as v, publicReadAdminWrite as x, presets_exports as y };
|
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { V as MiddlewareConfig, Y as PresetHook, c as AdditionalRoute, dt as RouteSchemaOptions, l as AnyRecord, sn as HookSystem, zt as ResourceRegistry } from "../interface-DDW43OmS.mjs";
|
|
2
2
|
import { t as ExternalOpenApiPaths } from "../externalPaths-DpO-s7r8.mjs";
|
|
3
3
|
import { _ as cachingPlugin, a as versioningPlugin, c as MetricsOptions, d as SSEOptions, f as _default$6, g as _default$1, h as CachingRule, i as _default$7, l as _default$4, m as CachingOptions, n as errorHandlerPlugin, o as MetricEntry, p as ssePlugin, r as VersioningOptions, s as MetricsCollector, t as ErrorHandlerOptions, u as metricsPlugin } from "../errorHandler-Do4vVQ1f.mjs";
|
|
4
4
|
import { t as TracingOptions } from "../tracing-bz_U4EM1.mjs";
|
package/dist/plugins/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { p as MUTATION_OPERATIONS } from "../constants-Cxde4rpC.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { i as getOrgId } from "../types-BhtYdxZU.mjs";
|
|
3
3
|
import { t as requestContext } from "../requestContext-DYtmNpm5.mjs";
|
|
4
4
|
import { t as hasEvents } from "../typeGuards-Cj5Rgvlg.mjs";
|
|
5
5
|
import { t as HookSystem } from "../HookSystem-COkyWztM.mjs";
|
|
6
6
|
import { t as ResourceRegistry } from "../ResourceRegistry-DeCIFlix.mjs";
|
|
7
7
|
import { n as caching_default, t as cachingPlugin } from "../caching-BSXB-Xr7.mjs";
|
|
8
|
-
import { t as errorHandlerPlugin } from "../errorHandler-
|
|
8
|
+
import { t as errorHandlerPlugin } from "../errorHandler-r2595m8T.mjs";
|
|
9
9
|
import { n as metrics_default, t as metricsPlugin } from "../metrics-Csh4nsvv.mjs";
|
|
10
|
-
import { n as sse_default, t as ssePlugin } from "../sse-
|
|
10
|
+
import { n as sse_default, t as ssePlugin } from "../sse-BF7GR7IB.mjs";
|
|
11
11
|
import { n as versioning_default, t as versioningPlugin } from "../versioning-BzfeHmhj.mjs";
|
|
12
12
|
import { randomUUID } from "node:crypto";
|
|
13
13
|
import fp from "fastify-plugin";
|
|
@@ -44,7 +44,7 @@ try {
|
|
|
44
44
|
function createTracerProvider(options) {
|
|
45
45
|
if (!isAvailable) return null;
|
|
46
46
|
const { serviceName = "@classytic/arc", serviceVersion, exporterUrl = "http://localhost:4318/v1/traces" } = options;
|
|
47
|
-
const resolvedVersion = serviceVersion ?? "2.
|
|
47
|
+
const resolvedVersion = serviceVersion ?? "2.6.1";
|
|
48
48
|
const exporter = new OTLPTraceExporter({ url: exporterUrl });
|
|
49
49
|
const provider = new NodeTracerProvider({ resource: { attributes: {
|
|
50
50
|
"service.name": serviceName,
|
package/dist/presets/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ft as IControllerResponse, It as IRequestContext, Wt as PaginatedResult, X as PresetResult, at as ResourceConfig, l as AnyRecord } from "../interface-DDW43OmS.mjs";
|
|
2
2
|
import { MultiTenantOptions, multiTenantPreset } from "./multiTenant.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/presets/ownedByUser.d.ts
|
package/dist/presets/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { multiTenantPreset } from "./multiTenant.mjs";
|
|
2
|
-
import { a as registerPreset, c as auditedPreset, d as ownedByUserPreset, i as getPreset, l as softDeletePreset, n as flexibleMultiTenantPreset, o as treePreset, r as getAvailablePresets, s as bulkPreset, t as applyPresets, u as slugLookupPreset } from "../presets-
|
|
2
|
+
import { a as registerPreset, c as auditedPreset, d as ownedByUserPreset, i as getPreset, l as softDeletePreset, n as flexibleMultiTenantPreset, o as treePreset, r as getAvailablePresets, s as bulkPreset, t as applyPresets, u as slugLookupPreset } from "../presets-BMfdy34e.mjs";
|
|
3
3
|
export { applyPresets, auditedPreset, bulkPreset, flexibleMultiTenantPreset, getAvailablePresets, getPreset, multiTenantPreset, ownedByUserPreset, registerPreset, slugLookupPreset, softDeletePreset, treePreset };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { o as DEFAULT_TENANT_FIELD } from "../constants-Cxde4rpC.mjs";
|
|
2
|
-
import { d as
|
|
2
|
+
import { d as isElevated, f as isMember, i as getOrgId, n as PUBLIC_SCOPE } from "../types-BhtYdxZU.mjs";
|
|
3
3
|
//#region src/presets/multiTenant.ts
|
|
4
4
|
/** Read request.scope safely */
|
|
5
5
|
function getScope(request) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as isElevated, n as PUBLIC_SCOPE } from "./types-BhtYdxZU.mjs";
|
|
2
2
|
import { multiTenantPreset } from "./presets/multiTenant.mjs";
|
|
3
|
-
import { d as requireRoles, n as allowPublic, s as requireAuth } from "./permissions-
|
|
3
|
+
import { d as requireRoles, n as allowPublic, s as requireAuth } from "./permissions-C8ImI8gC.mjs";
|
|
4
4
|
//#region src/presets/ownedByUser.ts
|
|
5
5
|
/**
|
|
6
6
|
* Create ownership check middleware.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { L as IntrospectionPluginOptions, Rt as RegisterOptions, zt as ResourceRegistry } from "../interface-DDW43OmS.mjs";
|
|
2
2
|
import { FastifyPluginAsync } from "fastify";
|
|
3
3
|
|
|
4
4
|
//#region src/registry/introspectionPlugin.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as BaseController } from "./BaseController-
|
|
1
|
+
import { t as BaseController } from "./BaseController-AbbRx3e0.mjs";
|
|
2
2
|
import { t as pluralize } from "./pluralize-CcT6qF0a.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/integrations/mcp/createMcpServer.ts
|
|
@@ -148,16 +148,55 @@ function typeToZod(type) {
|
|
|
148
148
|
default: return z.string();
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
/**
|
|
151
|
+
/** Operators that apply to numeric/date fields */
|
|
152
|
+
const COMPARISON_OPS = new Set([
|
|
153
|
+
"gt",
|
|
154
|
+
"gte",
|
|
155
|
+
"lt",
|
|
156
|
+
"lte"
|
|
157
|
+
]);
|
|
158
|
+
/** Map operator to a human-readable description suffix */
|
|
159
|
+
function opDescription(op, fieldName) {
|
|
160
|
+
switch (op) {
|
|
161
|
+
case "gt": return `${fieldName} greater than`;
|
|
162
|
+
case "gte": return `${fieldName} greater than or equal`;
|
|
163
|
+
case "lt": return `${fieldName} less than`;
|
|
164
|
+
case "lte": return `${fieldName} less than or equal`;
|
|
165
|
+
case "ne": return `${fieldName} not equal to`;
|
|
166
|
+
case "in": return `${fieldName} in comma-separated list`;
|
|
167
|
+
case "nin": return `${fieldName} not in comma-separated list`;
|
|
168
|
+
case "exists": return `${fieldName} exists (true/false)`;
|
|
169
|
+
default: return `${fieldName} ${op}`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** Build list/query shape with filterable fields, operators, and pagination */
|
|
152
173
|
function buildListShape(fieldRules, options) {
|
|
153
|
-
const { filterableFields = [], hiddenFields = [], extraHideFields = [] } = options;
|
|
174
|
+
const { filterableFields = [], hiddenFields = [], extraHideFields = [], allowedOperators } = options;
|
|
154
175
|
const allHidden = new Set([...hiddenFields, ...extraHideFields]);
|
|
155
176
|
const shape = { ...PAGINATION_SHAPE };
|
|
156
|
-
if (fieldRules)
|
|
177
|
+
if (!fieldRules) return shape;
|
|
178
|
+
for (const name of filterableFields) {
|
|
157
179
|
if (allHidden.has(name)) continue;
|
|
158
180
|
const rule = fieldRules[name];
|
|
159
181
|
if (!rule) continue;
|
|
160
|
-
|
|
182
|
+
const filterField = buildFieldSchema(rule);
|
|
183
|
+
shape[name] = filterField.optional();
|
|
184
|
+
if (allowedOperators?.length) {
|
|
185
|
+
const isNumericOrDate = rule.type === "number" || rule.type === "date";
|
|
186
|
+
for (const op of allowedOperators) {
|
|
187
|
+
if (COMPARISON_OPS.has(op) && !isNumericOrDate) continue;
|
|
188
|
+
if (op === "eq") continue;
|
|
189
|
+
if (op === "exists") {
|
|
190
|
+
shape[`${name}_${op}`] = z.boolean().optional().describe(opDescription(op, name));
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
if (op === "in" || op === "nin") {
|
|
194
|
+
shape[`${name}_${op}`] = z.string().optional().describe(opDescription(op, name));
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
shape[`${name}_${op}`] = filterField.optional().describe(opDescription(op, name));
|
|
198
|
+
}
|
|
199
|
+
}
|
|
161
200
|
}
|
|
162
201
|
return shape;
|
|
163
202
|
}
|
|
@@ -193,7 +232,7 @@ function buildRequestContext(input, auth, operation, policyFilters) {
|
|
|
193
232
|
case "list": return {
|
|
194
233
|
...base,
|
|
195
234
|
params: {},
|
|
196
|
-
query:
|
|
235
|
+
query: expandOperatorKeys(input),
|
|
197
236
|
body: void 0
|
|
198
237
|
};
|
|
199
238
|
case "get": return {
|
|
@@ -225,6 +264,40 @@ function buildRequestContext(input, auth, operation, policyFilters) {
|
|
|
225
264
|
};
|
|
226
265
|
}
|
|
227
266
|
}
|
|
267
|
+
/** Convert MCP operator keys (`price_gt`) to MongoKit bracket notation (`price[gt]`). */
|
|
268
|
+
const OPERATOR_SUFFIXES = new Set([
|
|
269
|
+
"eq",
|
|
270
|
+
"ne",
|
|
271
|
+
"gt",
|
|
272
|
+
"gte",
|
|
273
|
+
"lt",
|
|
274
|
+
"lte",
|
|
275
|
+
"in",
|
|
276
|
+
"nin",
|
|
277
|
+
"exists"
|
|
278
|
+
]);
|
|
279
|
+
function expandOperatorKeys(input) {
|
|
280
|
+
const out = {};
|
|
281
|
+
for (const [key, value] of Object.entries(input)) {
|
|
282
|
+
const lastUnderscore = key.lastIndexOf("_");
|
|
283
|
+
if (lastUnderscore > 0) {
|
|
284
|
+
const op = key.slice(lastUnderscore + 1);
|
|
285
|
+
if (OPERATOR_SUFFIXES.has(op)) {
|
|
286
|
+
const field = key.slice(0, lastUnderscore);
|
|
287
|
+
const existing = out[field];
|
|
288
|
+
if (existing && typeof existing === "object" && existing !== null) existing[op] = value;
|
|
289
|
+
else if (existing === void 0) out[field] = { [op]: value };
|
|
290
|
+
else out[field] = {
|
|
291
|
+
eq: existing,
|
|
292
|
+
[op]: value
|
|
293
|
+
};
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
out[key] = value;
|
|
298
|
+
}
|
|
299
|
+
return out;
|
|
300
|
+
}
|
|
228
301
|
function buildScope(auth) {
|
|
229
302
|
if (!auth) return { kind: "public" };
|
|
230
303
|
if (auth.organizationId) return {
|
|
@@ -314,7 +387,8 @@ function resourceToTools(resource, config = {}) {
|
|
|
314
387
|
hiddenFields,
|
|
315
388
|
readonlyFields,
|
|
316
389
|
extraHideFields: config.hideFields,
|
|
317
|
-
filterableFields
|
|
390
|
+
filterableFields,
|
|
391
|
+
allowedOperators
|
|
318
392
|
}),
|
|
319
393
|
handler: createHandler(op, controller, resource.name, resource.permissions)
|
|
320
394
|
});
|