@classytic/arc 1.0.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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +900 -0
  3. package/bin/arc.js +344 -0
  4. package/dist/adapters/index.d.ts +237 -0
  5. package/dist/adapters/index.js +668 -0
  6. package/dist/arcCorePlugin-DTPWXcZN.d.ts +273 -0
  7. package/dist/audit/index.d.ts +195 -0
  8. package/dist/audit/index.js +319 -0
  9. package/dist/auth/index.d.ts +47 -0
  10. package/dist/auth/index.js +174 -0
  11. package/dist/cli/commands/docs.d.ts +11 -0
  12. package/dist/cli/commands/docs.js +474 -0
  13. package/dist/cli/commands/introspect.d.ts +8 -0
  14. package/dist/cli/commands/introspect.js +338 -0
  15. package/dist/cli/index.d.ts +43 -0
  16. package/dist/cli/index.js +520 -0
  17. package/dist/createApp-pzUAkzbz.d.ts +77 -0
  18. package/dist/docs/index.d.ts +166 -0
  19. package/dist/docs/index.js +650 -0
  20. package/dist/errors-8WIxGS_6.d.ts +122 -0
  21. package/dist/events/index.d.ts +117 -0
  22. package/dist/events/index.js +89 -0
  23. package/dist/factory/index.d.ts +38 -0
  24. package/dist/factory/index.js +1664 -0
  25. package/dist/hooks/index.d.ts +4 -0
  26. package/dist/hooks/index.js +199 -0
  27. package/dist/idempotency/index.d.ts +323 -0
  28. package/dist/idempotency/index.js +500 -0
  29. package/dist/index-DkAW8BXh.d.ts +1302 -0
  30. package/dist/index.d.ts +331 -0
  31. package/dist/index.js +4734 -0
  32. package/dist/migrations/index.d.ts +185 -0
  33. package/dist/migrations/index.js +274 -0
  34. package/dist/org/index.d.ts +129 -0
  35. package/dist/org/index.js +220 -0
  36. package/dist/permissions/index.d.ts +144 -0
  37. package/dist/permissions/index.js +100 -0
  38. package/dist/plugins/index.d.ts +46 -0
  39. package/dist/plugins/index.js +1069 -0
  40. package/dist/policies/index.d.ts +398 -0
  41. package/dist/policies/index.js +196 -0
  42. package/dist/presets/index.d.ts +336 -0
  43. package/dist/presets/index.js +382 -0
  44. package/dist/presets/multiTenant.d.ts +39 -0
  45. package/dist/presets/multiTenant.js +112 -0
  46. package/dist/registry/index.d.ts +16 -0
  47. package/dist/registry/index.js +253 -0
  48. package/dist/testing/index.d.ts +618 -0
  49. package/dist/testing/index.js +48032 -0
  50. package/dist/types/index.d.ts +4 -0
  51. package/dist/types/index.js +8 -0
  52. package/dist/types-0IPhH_NR.d.ts +143 -0
  53. package/dist/types-B99TBmFV.d.ts +76 -0
  54. package/dist/utils/index.d.ts +655 -0
  55. package/dist/utils/index.js +905 -0
  56. package/package.json +227 -0
@@ -0,0 +1,4 @@
1
+ export { K as AdditionalRoute, d as AnyRecord, u as ApiResponse, ak as ArcDecorator, A as AuthHelpers, a as AuthPluginOptions, ar as Authenticator, aq as AuthenticatorContext, au as BaseControllerOptions, a4 as ConfigError, ax as ControllerHandler, v as ControllerLike, k as ControllerQueryOptions, B as CrudController, f as CrudRepository, C as CrudRouteKey, _ as CrudRouterOptions, G as CrudSchemas, N as EventDefinition, al as EventsDecorator, ay as FastifyHandler, w as FastifyRequestExtras, x as FastifyWithAuth, y as FastifyWithDecorators, E as FieldRule, a9 as GracefulShutdownOptions, a7 as HealthCheck, a8 as HealthOptions, e as IController, m as IControllerResponse, j as IRequestContext, aw as InferDoc, $ as InferDocType, a0 as InferResourceDoc, Y as IntrospectionData, I as IntrospectionPluginOptions, J as JWTPayload, ap as JwtContext, M as MiddlewareConfig, ao as MiddlewareHandler, ah as ObjectId, af as OpenApiSchemas, Z as OrgScopeOptions, O as OwnershipCheck, n as PaginatedResult, av as PaginationParams, ae as ParsedQuery, L as PresetFunction, at as PresetHook, P as PresetResult, Q as QueryOptions, h as QueryParserInterface, W as RegistryEntry, X as RegistryStats, l as RequestContext, aa as RequestIdOptions, R as RequestWithExtras, o as ResourceConfig, an as ResourceHooks, T as ResourceMetadata, am as ResourcePermissions, z as RouteHandler, g as RouteSchemaOptions, S as ServiceContext, as as TokenPair, a2 as TypedController, a3 as TypedRepository, a1 as TypedResourceConfig, ai as UserLike, U as UserOrganization, a6 as ValidateOptions, a5 as ValidationResult, aj as getUserId } from '../index-DkAW8BXh.js';
2
+ export { RouteHandlerMethod } from 'fastify';
3
+ export { Document, Model } from 'mongoose';
4
+ export { P as PermissionCheck, a as PermissionContext, b as PermissionResult, U as UserBase } from '../types-B99TBmFV.js';
@@ -0,0 +1,8 @@
1
+ // src/types/index.ts
2
+ function getUserId(user) {
3
+ if (!user) return void 0;
4
+ const id = user.id ?? user._id;
5
+ return id ? String(id) : void 0;
6
+ }
7
+
8
+ export { getUserId };
@@ -0,0 +1,143 @@
1
+ import { FastifyServerOptions } from 'fastify';
2
+ import { FastifyCorsOptions } from '@fastify/cors';
3
+ import { FastifyHelmetOptions } from '@fastify/helmet';
4
+ import { RateLimitOptions } from '@fastify/rate-limit';
5
+ import { a as AuthPluginOptions } from './index-DkAW8BXh.js';
6
+
7
+ /**
8
+ * Types for createApp factory
9
+ */
10
+
11
+ /**
12
+ * CreateApp Options
13
+ *
14
+ * Configuration for creating an Arc application.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Minimal setup
19
+ * const app = await createApp({
20
+ * preset: 'development',
21
+ * auth: {
22
+ * jwt: { secret: process.env.JWT_SECRET },
23
+ * },
24
+ * });
25
+ *
26
+ * // With custom authenticator
27
+ * const app = await createApp({
28
+ * preset: 'production',
29
+ * auth: {
30
+ * jwt: { secret: process.env.JWT_SECRET },
31
+ * authenticate: async (request, { jwt }) => {
32
+ * // Check API key first
33
+ * const apiKey = request.headers['x-api-key'];
34
+ * if (apiKey) {
35
+ * const result = await apiKeyService.verify(apiKey);
36
+ * if (result) return { _id: result.userId, isApiKey: true };
37
+ * }
38
+ * // Then check JWT
39
+ * const token = request.headers.authorization?.split(' ')[1];
40
+ * if (token) {
41
+ * const decoded = jwt.verify(token);
42
+ * return userRepo.findById(decoded.id);
43
+ * }
44
+ * return null;
45
+ * },
46
+ * },
47
+ * });
48
+ * ```
49
+ */
50
+ interface CreateAppOptions {
51
+ /** Environment preset: 'production', 'development', or 'testing' */
52
+ preset?: 'production' | 'development' | 'testing';
53
+ /** Fastify logger configuration */
54
+ logger?: FastifyServerOptions['logger'];
55
+ /** Trust proxy headers (X-Forwarded-For, etc.) */
56
+ trustProxy?: boolean;
57
+ /**
58
+ * Auth configuration
59
+ *
60
+ * Set to false to disable authentication entirely.
61
+ * Provide AuthPluginOptions for full control.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Disable auth
66
+ * auth: false,
67
+ *
68
+ * // Simple JWT (uses default jwtVerify)
69
+ * auth: {
70
+ * jwt: { secret: process.env.JWT_SECRET },
71
+ * },
72
+ *
73
+ * // Custom authenticator
74
+ * auth: {
75
+ * jwt: { secret: process.env.JWT_SECRET },
76
+ * authenticate: async (request, { jwt }) => {
77
+ * const token = request.headers.authorization?.split(' ')[1];
78
+ * if (!token) return null;
79
+ * const decoded = jwt.verify(token);
80
+ * return userRepo.findById(decoded.id);
81
+ * },
82
+ * },
83
+ *
84
+ * // Completely custom auth plugin
85
+ * auth: {
86
+ * plugin: async (fastify) => {
87
+ * // Your custom auth setup
88
+ * },
89
+ * },
90
+ * ```
91
+ */
92
+ auth?: false | AuthPluginOptions | {
93
+ /** Replace Arc auth with your own plugin */
94
+ plugin?: (fastify: any) => Promise<void>;
95
+ };
96
+ /** Helmet security headers. Set to false to disable. */
97
+ helmet?: FastifyHelmetOptions | false;
98
+ /** CORS configuration. Set to false to disable. */
99
+ cors?: FastifyCorsOptions | false;
100
+ /** Rate limiting. Set to false to disable. */
101
+ rateLimit?: RateLimitOptions | false;
102
+ /** Under pressure health monitoring. Set to false to disable. */
103
+ underPressure?: UnderPressureOptions | false;
104
+ /** @fastify/sensible (HTTP helpers). Set to false to disable. */
105
+ sensible?: boolean | false;
106
+ /** @fastify/multipart (file uploads). Set to false to disable. */
107
+ multipart?: MultipartOptions | false;
108
+ /** Raw body parsing (for webhooks). Set to false to disable. */
109
+ rawBody?: RawBodyOptions | false;
110
+ /** Enable Arc plugins (requestId, health, gracefulShutdown) */
111
+ arcPlugins?: {
112
+ /** Request ID tracking (default: true) */
113
+ requestId?: boolean;
114
+ /** Health endpoints (default: true) */
115
+ health?: boolean;
116
+ /** Graceful shutdown handling (default: true) */
117
+ gracefulShutdown?: boolean;
118
+ /** Emit events for CRUD operations (default: true) */
119
+ emitEvents?: boolean;
120
+ };
121
+ /** Custom plugin registration function */
122
+ plugins?: (fastify: any) => Promise<void>;
123
+ }
124
+ interface UnderPressureOptions {
125
+ exposeStatusRoute?: boolean;
126
+ maxEventLoopDelay?: number;
127
+ maxHeapUsedBytes?: number;
128
+ maxRssBytes?: number;
129
+ }
130
+ interface MultipartOptions {
131
+ limits?: {
132
+ fileSize?: number;
133
+ files?: number;
134
+ };
135
+ }
136
+ interface RawBodyOptions {
137
+ field?: string;
138
+ global?: boolean;
139
+ encoding?: string;
140
+ runFirst?: boolean;
141
+ }
142
+
143
+ export type { CreateAppOptions as C, MultipartOptions as M, RawBodyOptions as R, UnderPressureOptions as U };
@@ -0,0 +1,76 @@
1
+ import { FastifyRequest } from 'fastify';
2
+
3
+ /**
4
+ * Permission Types - Core Type Definitions
5
+ *
6
+ * PermissionCheck is THE ONLY way to define permissions in Arc.
7
+ * No string arrays, no alternative patterns.
8
+ */
9
+
10
+ /**
11
+ * User base interface - minimal shape Arc expects
12
+ * Your actual User can have any additional fields
13
+ */
14
+ interface UserBase {
15
+ id?: string;
16
+ _id?: string;
17
+ roles?: string[];
18
+ [key: string]: unknown;
19
+ }
20
+ /**
21
+ * Context passed to permission check functions
22
+ */
23
+ interface PermissionContext {
24
+ /** Authenticated user or null if unauthenticated */
25
+ user: UserBase | null;
26
+ /** Fastify request object */
27
+ request: FastifyRequest;
28
+ /** Resource name being accessed */
29
+ resource: string;
30
+ /** Action being performed (list, get, create, update, delete) */
31
+ action: string;
32
+ /** Resource ID for single-resource operations */
33
+ resourceId?: string;
34
+ /** Organization context for multi-tenant apps */
35
+ organizationId?: string;
36
+ /** Request body data */
37
+ data?: Record<string, unknown>;
38
+ }
39
+ /**
40
+ * Result from permission check
41
+ */
42
+ interface PermissionResult {
43
+ /** Whether access is granted */
44
+ granted: boolean;
45
+ /** Reason for denial (for error messages) */
46
+ reason?: string;
47
+ /** Query filters to apply (for ownership patterns) */
48
+ filters?: Record<string, unknown>;
49
+ }
50
+ /**
51
+ * Permission Check Function
52
+ *
53
+ * THE ONLY way to define permissions in Arc.
54
+ * Returns boolean, PermissionResult, or Promise of either.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * // Simple boolean return
59
+ * const isAdmin: PermissionCheck = (ctx) => ctx.user?.roles?.includes('admin') ?? false;
60
+ *
61
+ * // With filters for ownership
62
+ * const ownedByUser: PermissionCheck = (ctx) => ({
63
+ * granted: true,
64
+ * filters: { userId: ctx.user?.id }
65
+ * });
66
+ *
67
+ * // Async check
68
+ * const canAccessOrg: PermissionCheck = async (ctx) => {
69
+ * const isMember = await checkMembership(ctx.user?.id, ctx.organizationId);
70
+ * return { granted: isMember, reason: isMember ? undefined : 'Not a member' };
71
+ * };
72
+ * ```
73
+ */
74
+ type PermissionCheck = (context: PermissionContext) => boolean | PermissionResult | Promise<boolean | PermissionResult>;
75
+
76
+ export type { PermissionCheck as P, UserBase as U, PermissionContext as a, PermissionResult as b };