@classytic/arc 1.1.0 → 2.1.3

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 (200) hide show
  1. package/README.md +247 -794
  2. package/bin/arc.js +91 -52
  3. package/dist/EventTransport-BkUDYZEb.d.mts +99 -0
  4. package/dist/HookSystem-BsGV-j2l.mjs +404 -0
  5. package/dist/ResourceRegistry-7Ic20ZMw.mjs +249 -0
  6. package/dist/adapters/index.d.mts +5 -0
  7. package/dist/adapters/index.mjs +3 -0
  8. package/dist/audit/index.d.mts +81 -0
  9. package/dist/audit/index.mjs +275 -0
  10. package/dist/audit/mongodb.d.mts +5 -0
  11. package/dist/audit/mongodb.mjs +3 -0
  12. package/dist/audited-CGdLiSlE.mjs +140 -0
  13. package/dist/auth/index.d.mts +188 -0
  14. package/dist/auth/index.mjs +1096 -0
  15. package/dist/auth/redis-session.d.mts +43 -0
  16. package/dist/auth/redis-session.mjs +75 -0
  17. package/dist/betterAuthOpenApi-DjWDddNc.mjs +249 -0
  18. package/dist/cache/index.d.mts +145 -0
  19. package/dist/cache/index.mjs +91 -0
  20. package/dist/caching-GSDJcA6-.mjs +93 -0
  21. package/dist/chunk-C7Uep-_p.mjs +20 -0
  22. package/dist/circuitBreaker-DYhWBW_D.mjs +1096 -0
  23. package/dist/cli/commands/describe.d.mts +18 -0
  24. package/dist/cli/commands/describe.mjs +238 -0
  25. package/dist/cli/commands/docs.d.mts +13 -0
  26. package/dist/cli/commands/docs.mjs +52 -0
  27. package/dist/cli/commands/{generate.d.ts → generate.d.mts} +3 -2
  28. package/dist/cli/commands/generate.mjs +357 -0
  29. package/dist/cli/commands/{init.d.ts → init.d.mts} +11 -8
  30. package/dist/cli/commands/{init.js → init.mjs} +807 -617
  31. package/dist/cli/commands/introspect.d.mts +10 -0
  32. package/dist/cli/commands/introspect.mjs +75 -0
  33. package/dist/cli/index.d.mts +16 -0
  34. package/dist/cli/index.mjs +156 -0
  35. package/dist/constants-DdXFXQtN.mjs +84 -0
  36. package/dist/core/index.d.mts +5 -0
  37. package/dist/core/index.mjs +4 -0
  38. package/dist/createApp-D2D5XXaV.mjs +559 -0
  39. package/dist/defineResource-PXzSJ15_.mjs +2197 -0
  40. package/dist/discovery/index.d.mts +46 -0
  41. package/dist/discovery/index.mjs +109 -0
  42. package/dist/docs/index.d.mts +162 -0
  43. package/dist/docs/index.mjs +74 -0
  44. package/dist/elevation-DGo5shaX.d.mts +87 -0
  45. package/dist/elevation-DSTbVvYj.mjs +113 -0
  46. package/dist/errorHandler-C3GY3_ow.mjs +108 -0
  47. package/dist/errorHandler-CW3OOeYq.d.mts +72 -0
  48. package/dist/errors-DAWRdiYP.d.mts +124 -0
  49. package/dist/errors-DBANPbGr.mjs +211 -0
  50. package/dist/eventPlugin-BEOvaDqo.mjs +229 -0
  51. package/dist/eventPlugin-H6wDDjGO.d.mts +124 -0
  52. package/dist/events/index.d.mts +53 -0
  53. package/dist/events/index.mjs +51 -0
  54. package/dist/events/transports/redis-stream-entry.d.mts +2 -0
  55. package/dist/events/transports/redis-stream-entry.mjs +177 -0
  56. package/dist/events/transports/redis.d.mts +76 -0
  57. package/dist/events/transports/redis.mjs +124 -0
  58. package/dist/externalPaths-SyPF2tgK.d.mts +50 -0
  59. package/dist/factory/index.d.mts +63 -0
  60. package/dist/factory/index.mjs +3 -0
  61. package/dist/fastifyAdapter-C8DlE0YH.d.mts +216 -0
  62. package/dist/fields-Bi_AVKSo.d.mts +109 -0
  63. package/dist/fields-CTd_CrKr.mjs +114 -0
  64. package/dist/hooks/index.d.mts +4 -0
  65. package/dist/hooks/index.mjs +3 -0
  66. package/dist/idempotency/index.d.mts +96 -0
  67. package/dist/idempotency/index.mjs +319 -0
  68. package/dist/idempotency/mongodb.d.mts +2 -0
  69. package/dist/idempotency/mongodb.mjs +114 -0
  70. package/dist/idempotency/redis.d.mts +2 -0
  71. package/dist/idempotency/redis.mjs +103 -0
  72. package/dist/index.d.mts +260 -0
  73. package/dist/index.mjs +104 -0
  74. package/dist/integrations/event-gateway.d.mts +46 -0
  75. package/dist/integrations/event-gateway.mjs +43 -0
  76. package/dist/integrations/index.d.mts +5 -0
  77. package/dist/integrations/index.mjs +1 -0
  78. package/dist/integrations/jobs.d.mts +103 -0
  79. package/dist/integrations/jobs.mjs +123 -0
  80. package/dist/integrations/streamline.d.mts +60 -0
  81. package/dist/integrations/streamline.mjs +125 -0
  82. package/dist/integrations/websocket.d.mts +82 -0
  83. package/dist/integrations/websocket.mjs +288 -0
  84. package/dist/interface-CSNjltAc.d.mts +77 -0
  85. package/dist/interface-DTbsvIWe.d.mts +54 -0
  86. package/dist/interface-e9XfSsUV.d.mts +1097 -0
  87. package/dist/introspectionPlugin-B3JkrjwU.mjs +53 -0
  88. package/dist/keys-DhqDRxv3.mjs +42 -0
  89. package/dist/logger-ByrvQWZO.mjs +78 -0
  90. package/dist/memory-B2v7KrCB.mjs +143 -0
  91. package/dist/migrations/index.d.mts +156 -0
  92. package/dist/migrations/index.mjs +260 -0
  93. package/dist/mongodb-ClykrfGo.d.mts +118 -0
  94. package/dist/mongodb-DNKEExbf.mjs +93 -0
  95. package/dist/mongodb-Dg8O_gvd.d.mts +71 -0
  96. package/dist/openapi-9nB_kiuR.mjs +525 -0
  97. package/dist/org/index.d.mts +68 -0
  98. package/dist/org/index.mjs +513 -0
  99. package/dist/org/types.d.mts +82 -0
  100. package/dist/org/types.mjs +1 -0
  101. package/dist/permissions/index.d.mts +278 -0
  102. package/dist/permissions/index.mjs +579 -0
  103. package/dist/plugins/index.d.mts +172 -0
  104. package/dist/plugins/index.mjs +522 -0
  105. package/dist/plugins/response-cache.d.mts +87 -0
  106. package/dist/plugins/response-cache.mjs +283 -0
  107. package/dist/plugins/tracing-entry.d.mts +2 -0
  108. package/dist/plugins/tracing-entry.mjs +185 -0
  109. package/dist/pluralize-CM-jZg7p.mjs +86 -0
  110. package/dist/policies/{index.d.ts → index.d.mts} +204 -170
  111. package/dist/policies/index.mjs +321 -0
  112. package/dist/presets/{index.d.ts → index.d.mts} +62 -131
  113. package/dist/presets/index.mjs +143 -0
  114. package/dist/presets/multiTenant.d.mts +24 -0
  115. package/dist/presets/multiTenant.mjs +113 -0
  116. package/dist/presets-BTeYbw7h.d.mts +57 -0
  117. package/dist/presets-CeFtfDR8.mjs +119 -0
  118. package/dist/prisma-C3iornoK.d.mts +274 -0
  119. package/dist/prisma-DJbMt3yf.mjs +627 -0
  120. package/dist/queryCachePlugin-B6R0d4av.mjs +138 -0
  121. package/dist/queryCachePlugin-Q6SYuHZ6.d.mts +71 -0
  122. package/dist/redis-UwjEp8Ea.d.mts +49 -0
  123. package/dist/redis-stream-CBg0upHI.d.mts +103 -0
  124. package/dist/registry/index.d.mts +11 -0
  125. package/dist/registry/index.mjs +4 -0
  126. package/dist/requestContext-xi6OKBL-.mjs +55 -0
  127. package/dist/schemaConverter-Dtg0Kt9T.mjs +98 -0
  128. package/dist/schemas/index.d.mts +63 -0
  129. package/dist/schemas/index.mjs +82 -0
  130. package/dist/scope/index.d.mts +21 -0
  131. package/dist/scope/index.mjs +65 -0
  132. package/dist/sessionManager-D_iEHjQl.d.mts +186 -0
  133. package/dist/sse-DkqQ1uxb.mjs +123 -0
  134. package/dist/testing/index.d.mts +907 -0
  135. package/dist/testing/index.mjs +1976 -0
  136. package/dist/tracing-8CEbhF0w.d.mts +70 -0
  137. package/dist/typeGuards-DwxA1t_L.mjs +9 -0
  138. package/dist/types/index.d.mts +946 -0
  139. package/dist/types/index.mjs +14 -0
  140. package/dist/types-B0dhNrnd.d.mts +445 -0
  141. package/dist/types-Beqn1Un7.mjs +38 -0
  142. package/dist/types-DelU6kln.mjs +25 -0
  143. package/dist/types-RLkFVgaw.d.mts +101 -0
  144. package/dist/utils/index.d.mts +747 -0
  145. package/dist/utils/index.mjs +6 -0
  146. package/package.json +194 -68
  147. package/dist/BaseController-DVAiHxEQ.d.ts +0 -233
  148. package/dist/adapters/index.d.ts +0 -237
  149. package/dist/adapters/index.js +0 -668
  150. package/dist/arcCorePlugin-CsShQdyP.d.ts +0 -273
  151. package/dist/audit/index.d.ts +0 -195
  152. package/dist/audit/index.js +0 -319
  153. package/dist/auth/index.d.ts +0 -47
  154. package/dist/auth/index.js +0 -174
  155. package/dist/cli/commands/docs.d.ts +0 -11
  156. package/dist/cli/commands/docs.js +0 -474
  157. package/dist/cli/commands/generate.js +0 -334
  158. package/dist/cli/commands/introspect.d.ts +0 -8
  159. package/dist/cli/commands/introspect.js +0 -338
  160. package/dist/cli/index.d.ts +0 -4
  161. package/dist/cli/index.js +0 -3269
  162. package/dist/core/index.d.ts +0 -220
  163. package/dist/core/index.js +0 -2786
  164. package/dist/createApp-Ce9wl8W9.d.ts +0 -77
  165. package/dist/docs/index.d.ts +0 -166
  166. package/dist/docs/index.js +0 -658
  167. package/dist/errors-8WIxGS_6.d.ts +0 -122
  168. package/dist/events/index.d.ts +0 -117
  169. package/dist/events/index.js +0 -89
  170. package/dist/factory/index.d.ts +0 -38
  171. package/dist/factory/index.js +0 -1652
  172. package/dist/hooks/index.d.ts +0 -4
  173. package/dist/hooks/index.js +0 -199
  174. package/dist/idempotency/index.d.ts +0 -323
  175. package/dist/idempotency/index.js +0 -500
  176. package/dist/index-B4t03KQ0.d.ts +0 -1366
  177. package/dist/index.d.ts +0 -135
  178. package/dist/index.js +0 -4756
  179. package/dist/migrations/index.d.ts +0 -185
  180. package/dist/migrations/index.js +0 -274
  181. package/dist/org/index.d.ts +0 -129
  182. package/dist/org/index.js +0 -220
  183. package/dist/permissions/index.d.ts +0 -144
  184. package/dist/permissions/index.js +0 -103
  185. package/dist/plugins/index.d.ts +0 -46
  186. package/dist/plugins/index.js +0 -1069
  187. package/dist/policies/index.js +0 -196
  188. package/dist/presets/index.js +0 -384
  189. package/dist/presets/multiTenant.d.ts +0 -39
  190. package/dist/presets/multiTenant.js +0 -112
  191. package/dist/registry/index.d.ts +0 -16
  192. package/dist/registry/index.js +0 -253
  193. package/dist/testing/index.d.ts +0 -618
  194. package/dist/testing/index.js +0 -48020
  195. package/dist/types/index.d.ts +0 -4
  196. package/dist/types/index.js +0 -8
  197. package/dist/types-B99TBmFV.d.ts +0 -76
  198. package/dist/types-BvckRbs2.d.ts +0 -143
  199. package/dist/utils/index.d.ts +0 -679
  200. package/dist/utils/index.js +0 -931
@@ -0,0 +1,260 @@
1
+ import mongoose from "mongoose";
2
+
3
+ //#region src/migrations/index.ts
4
+ /**
5
+ * Define a migration
6
+ */
7
+ function defineMigration(migration) {
8
+ return migration;
9
+ }
10
+ /**
11
+ * Migration Runner
12
+ *
13
+ * Manages execution of migrations with tracking and rollback support.
14
+ */
15
+ var MigrationRunner = class {
16
+ collectionName = "_migrations";
17
+ db;
18
+ constructor(db) {
19
+ this.db = db;
20
+ }
21
+ /**
22
+ * Run all pending migrations
23
+ */
24
+ async up(migrations) {
25
+ const applied = await this.getAppliedMigrations();
26
+ const appliedVersions = new Set(applied.map((m) => `${m.resource}:${m.version}`));
27
+ const pending = migrations.filter((m) => !appliedVersions.has(`${m.resource}:${m.version}`)).sort((a, b) => a.version - b.version);
28
+ if (pending.length === 0) {
29
+ console.log("No pending migrations");
30
+ return;
31
+ }
32
+ console.log(`Running ${pending.length} migration(s)...\n`);
33
+ for (const migration of pending) await this.runMigration(migration, "up");
34
+ console.log("\nAll migrations completed successfully");
35
+ }
36
+ /**
37
+ * Rollback last migration
38
+ */
39
+ async down(migrations) {
40
+ const applied = await this.getAppliedMigrations();
41
+ if (applied.length === 0) {
42
+ console.log("No migrations to rollback");
43
+ return;
44
+ }
45
+ const last = applied[applied.length - 1];
46
+ if (!last) {
47
+ console.log("No migrations to rollback");
48
+ return;
49
+ }
50
+ const migration = migrations.find((m) => m.resource === last.resource && m.version === last.version);
51
+ if (!migration) throw new Error(`Migration ${last.resource}:${last.version} not found in migration files`);
52
+ console.log(`Rolling back ${migration.resource} v${migration.version}...`);
53
+ await this.runMigration(migration, "down", true);
54
+ console.log("Rollback completed");
55
+ }
56
+ /**
57
+ * Rollback to specific version
58
+ */
59
+ async downTo(migrations, targetVersion) {
60
+ const toRollback = (await this.getAppliedMigrations()).filter((m) => m.version > targetVersion).reverse();
61
+ if (toRollback.length === 0) {
62
+ console.log(`Already at or below version ${targetVersion}`);
63
+ return;
64
+ }
65
+ console.log(`Rolling back ${toRollback.length} migration(s)...\n`);
66
+ for (const record of toRollback) {
67
+ const migration = migrations.find((m) => m.resource === record.resource && m.version === record.version);
68
+ if (!migration) throw new Error(`Migration ${record.resource}:${record.version} not found`);
69
+ await this.runMigration(migration, "down", true);
70
+ }
71
+ console.log("\nRollback completed");
72
+ }
73
+ /**
74
+ * Get all applied migrations
75
+ */
76
+ async getAppliedMigrations() {
77
+ return await this.db.collection(this.collectionName).find({}).sort({ appliedAt: 1 }).toArray();
78
+ }
79
+ /**
80
+ * Get pending migrations
81
+ */
82
+ async getPendingMigrations(migrations) {
83
+ const applied = await this.getAppliedMigrations();
84
+ const appliedVersions = new Set(applied.map((m) => `${m.resource}:${m.version}`));
85
+ return migrations.filter((m) => !appliedVersions.has(`${m.resource}:${m.version}`));
86
+ }
87
+ /**
88
+ * Check if migrations are up to date
89
+ */
90
+ async isUpToDate(migrations) {
91
+ return (await this.getPendingMigrations(migrations)).length === 0;
92
+ }
93
+ /**
94
+ * Run a single migration
95
+ */
96
+ async runMigration(migration, direction, isRollback = false) {
97
+ const start = Date.now();
98
+ const action = direction === "up" ? "Applying" : "Rolling back";
99
+ console.log(`${action} ${migration.resource} v${migration.version}${migration.description ? `: ${migration.description}` : ""}...`);
100
+ try {
101
+ if (direction === "up") {
102
+ await migration.up(this.db);
103
+ if (migration.validate) {
104
+ if (!await migration.validate(this.db)) throw new Error("Migration validation failed");
105
+ }
106
+ await this.recordMigration(migration, Date.now() - start);
107
+ } else {
108
+ await migration.down(this.db);
109
+ if (isRollback) await this.removeMigration(migration);
110
+ }
111
+ const duration = Date.now() - start;
112
+ console.log(`✅ ${migration.resource} v${migration.version} (${duration}ms)`);
113
+ } catch (error) {
114
+ console.error(`❌ ${migration.resource} v${migration.version} failed:`, error.message);
115
+ throw error;
116
+ }
117
+ }
118
+ /**
119
+ * Record a completed migration
120
+ */
121
+ async recordMigration(migration, executionTime) {
122
+ await this.db.collection(this.collectionName).insertOne({
123
+ version: migration.version,
124
+ resource: migration.resource,
125
+ description: migration.description,
126
+ appliedAt: /* @__PURE__ */ new Date(),
127
+ executionTime
128
+ });
129
+ }
130
+ /**
131
+ * Remove a migration record
132
+ */
133
+ async removeMigration(migration) {
134
+ await this.db.collection(this.collectionName).deleteOne({
135
+ version: migration.version,
136
+ resource: migration.resource
137
+ });
138
+ }
139
+ };
140
+ /**
141
+ * Add versioning to resource definition
142
+ *
143
+ * @example
144
+ * export default defineResource({
145
+ * name: 'product',
146
+ * version: 2,
147
+ * migrations: [productV1ToV2Migration],
148
+ * // ... rest of resource definition
149
+ * });
150
+ */
151
+ function withSchemaVersion(version, migrations) {
152
+ return {
153
+ version,
154
+ migrations
155
+ };
156
+ }
157
+ /**
158
+ * Global migration registry
159
+ */
160
+ var MigrationRegistry = class {
161
+ migrations = /* @__PURE__ */ new Map();
162
+ /**
163
+ * Register a migration
164
+ */
165
+ register(migration) {
166
+ const existing = this.migrations.get(migration.resource) || [];
167
+ existing.push(migration);
168
+ existing.sort((a, b) => a.version - b.version);
169
+ this.migrations.set(migration.resource, existing);
170
+ }
171
+ /**
172
+ * Register multiple migrations
173
+ */
174
+ registerMany(migrations) {
175
+ for (const migration of migrations) this.register(migration);
176
+ }
177
+ /**
178
+ * Get all migrations for a resource
179
+ */
180
+ getForResource(resource) {
181
+ return this.migrations.get(resource) || [];
182
+ }
183
+ /**
184
+ * Get all migrations
185
+ */
186
+ getAll() {
187
+ const all = [];
188
+ for (const migrations of this.migrations.values()) all.push(...migrations);
189
+ return all.sort((a, b) => a.version - b.version);
190
+ }
191
+ /**
192
+ * Get migration by resource and version
193
+ */
194
+ get(resource, version) {
195
+ return (this.migrations.get(resource) || []).find((m) => m.version === version);
196
+ }
197
+ /**
198
+ * Clear all registrations
199
+ */
200
+ clear() {
201
+ this.migrations.clear();
202
+ }
203
+ };
204
+ /**
205
+ * Global migration registry instance
206
+ */
207
+ const migrationRegistry = new MigrationRegistry();
208
+ /**
209
+ * Common migration helpers
210
+ */
211
+ const migrationHelpers = {
212
+ renameField: (collection, oldName, newName) => defineMigration({
213
+ version: 0,
214
+ resource: collection,
215
+ description: `Rename ${oldName} to ${newName}`,
216
+ up: async (db) => {
217
+ await db.collection(collection).updateMany({}, { $rename: { [oldName]: newName } });
218
+ },
219
+ down: async (db) => {
220
+ await db.collection(collection).updateMany({}, { $rename: { [newName]: oldName } });
221
+ }
222
+ }),
223
+ addField: (collection, fieldName, defaultValue) => defineMigration({
224
+ version: 0,
225
+ resource: collection,
226
+ description: `Add ${fieldName} field`,
227
+ up: async (db) => {
228
+ await db.collection(collection).updateMany({ [fieldName]: { $exists: false } }, { $set: { [fieldName]: defaultValue } });
229
+ },
230
+ down: async (db) => {
231
+ await db.collection(collection).updateMany({}, { $unset: { [fieldName]: "" } });
232
+ }
233
+ }),
234
+ removeField: (collection, fieldName) => defineMigration({
235
+ version: 0,
236
+ resource: collection,
237
+ description: `Remove ${fieldName} field`,
238
+ up: async (db) => {
239
+ await db.collection(collection).updateMany({}, { $unset: { [fieldName]: "" } });
240
+ },
241
+ down: async (db) => {
242
+ console.warn(`Cannot restore ${fieldName} field - data was deleted`);
243
+ }
244
+ }),
245
+ createIndex: (collection, fields, options) => defineMigration({
246
+ version: 0,
247
+ resource: collection,
248
+ description: `Create index on ${Object.keys(fields).join(", ")}`,
249
+ up: async (db) => {
250
+ await db.collection(collection).createIndex(fields, options);
251
+ },
252
+ down: async (db) => {
253
+ const indexName = typeof options?.name === "string" ? options.name : Object.keys(fields).join("_");
254
+ await db.collection(collection).dropIndex(indexName);
255
+ }
256
+ })
257
+ };
258
+
259
+ //#endregion
260
+ export { MigrationRegistry, MigrationRunner, defineMigration, migrationHelpers, migrationRegistry, withSchemaVersion };
@@ -0,0 +1,118 @@
1
+ import { i as UserBase } from "./types-RLkFVgaw.mjs";
2
+
3
+ //#region src/audit/stores/interface.d.ts
4
+ type AuditAction = 'create' | 'update' | 'delete' | 'restore' | 'custom';
5
+ interface AuditEntry {
6
+ /** Unique audit log ID */
7
+ id: string;
8
+ /** Resource name (e.g., 'product', 'user') */
9
+ resource: string;
10
+ /** Document/entity ID */
11
+ documentId: string;
12
+ /** Action performed */
13
+ action: AuditAction;
14
+ /** User who performed the action */
15
+ userId?: string;
16
+ /** Organization context */
17
+ organizationId?: string;
18
+ /** Previous state (for updates) */
19
+ before?: Record<string, unknown>;
20
+ /** New state (for creates/updates) */
21
+ after?: Record<string, unknown>;
22
+ /** Changed fields (for updates) */
23
+ changes?: string[];
24
+ /** Request ID for tracing */
25
+ requestId?: string;
26
+ /** IP address */
27
+ ipAddress?: string;
28
+ /** User agent */
29
+ userAgent?: string;
30
+ /** Custom metadata */
31
+ metadata?: Record<string, unknown>;
32
+ /** When the action occurred */
33
+ timestamp: Date;
34
+ }
35
+ interface AuditContext {
36
+ user?: UserBase;
37
+ organizationId?: string;
38
+ requestId?: string;
39
+ ipAddress?: string;
40
+ userAgent?: string;
41
+ /** HTTP method + route pattern (e.g., 'PATCH /api/products/:id') */
42
+ endpoint?: string;
43
+ /** Request duration in milliseconds */
44
+ duration?: number;
45
+ }
46
+ interface AuditStoreOptions {
47
+ /** Store name for logging */
48
+ name: string;
49
+ }
50
+ /**
51
+ * Abstract audit store interface
52
+ */
53
+ interface AuditStore {
54
+ /** Store name */
55
+ readonly name: string;
56
+ /** Log an audit entry */
57
+ log(entry: AuditEntry): Promise<void>;
58
+ /** Query audit logs (optional - not all stores support querying) */
59
+ query?(options: AuditQueryOptions): Promise<AuditEntry[]>;
60
+ /** Close/cleanup (optional) */
61
+ close?(): Promise<void>;
62
+ }
63
+ interface AuditQueryOptions {
64
+ resource?: string;
65
+ documentId?: string;
66
+ userId?: string;
67
+ organizationId?: string;
68
+ action?: AuditAction | AuditAction[];
69
+ from?: Date;
70
+ to?: Date;
71
+ limit?: number;
72
+ offset?: number;
73
+ }
74
+ /**
75
+ * Create audit entry from context
76
+ */
77
+ declare function createAuditEntry(resource: string, documentId: string, action: AuditAction, context: AuditContext, data?: {
78
+ before?: Record<string, unknown>;
79
+ after?: Record<string, unknown>;
80
+ metadata?: Record<string, unknown>;
81
+ }): AuditEntry;
82
+ //#endregion
83
+ //#region src/audit/stores/mongodb.d.ts
84
+ interface MongoAuditStoreOptions {
85
+ /** MongoDB connection or mongoose instance */
86
+ connection: MongoConnection;
87
+ /** Collection name (default: 'audit_logs') */
88
+ collection?: string;
89
+ /** TTL in days (default: 90, 0 = no expiry) */
90
+ ttlDays?: number;
91
+ }
92
+ interface MongoConnection {
93
+ collection: (name: string) => MongoCollection;
94
+ }
95
+ interface MongoCollection {
96
+ insertOne: (doc: Record<string, unknown>) => Promise<unknown>;
97
+ find: (query: Record<string, unknown>) => MongoCursor;
98
+ createIndex: (spec: Record<string, unknown>, options?: Record<string, unknown>) => Promise<unknown>;
99
+ }
100
+ interface MongoCursor {
101
+ sort: (spec: Record<string, unknown>) => MongoCursor;
102
+ skip: (n: number) => MongoCursor;
103
+ limit: (n: number) => MongoCursor;
104
+ toArray: () => Promise<Record<string, unknown>[]>;
105
+ }
106
+ declare class MongoAuditStore implements AuditStore {
107
+ readonly name = "mongodb";
108
+ private collection;
109
+ private initialized;
110
+ private ttlDays;
111
+ private options;
112
+ constructor(options: MongoAuditStoreOptions);
113
+ private ensureIndexes;
114
+ log(entry: AuditEntry): Promise<void>;
115
+ query(options?: AuditQueryOptions): Promise<AuditEntry[]>;
116
+ }
117
+ //#endregion
118
+ export { AuditContext as a, AuditStore as c, AuditAction as i, AuditStoreOptions as l, MongoAuditStoreOptions as n, AuditEntry as o, MongoConnection as r, AuditQueryOptions as s, MongoAuditStore as t, createAuditEntry as u };
@@ -0,0 +1,93 @@
1
+ //#region src/audit/stores/mongodb.ts
2
+ var MongoAuditStore = class {
3
+ name = "mongodb";
4
+ collection;
5
+ initialized = false;
6
+ ttlDays;
7
+ options;
8
+ constructor(options) {
9
+ this.options = options;
10
+ const collectionName = options.collection ?? "audit_logs";
11
+ this.collection = options.connection.collection(collectionName);
12
+ this.ttlDays = options.ttlDays ?? 90;
13
+ }
14
+ async ensureIndexes() {
15
+ if (this.initialized) return;
16
+ try {
17
+ await this.collection.createIndex({
18
+ resource: 1,
19
+ documentId: 1,
20
+ timestamp: -1
21
+ });
22
+ await this.collection.createIndex({
23
+ userId: 1,
24
+ timestamp: -1
25
+ });
26
+ await this.collection.createIndex({
27
+ organizationId: 1,
28
+ timestamp: -1
29
+ });
30
+ if (this.ttlDays > 0) await this.collection.createIndex({ timestamp: 1 }, { expireAfterSeconds: this.ttlDays * 24 * 60 * 60 });
31
+ this.initialized = true;
32
+ } catch {
33
+ this.initialized = true;
34
+ }
35
+ }
36
+ async log(entry) {
37
+ await this.ensureIndexes();
38
+ await this.collection.insertOne({
39
+ _id: entry.id,
40
+ resource: entry.resource,
41
+ documentId: entry.documentId,
42
+ action: entry.action,
43
+ userId: entry.userId,
44
+ organizationId: entry.organizationId,
45
+ before: entry.before,
46
+ after: entry.after,
47
+ changes: entry.changes,
48
+ requestId: entry.requestId,
49
+ ipAddress: entry.ipAddress,
50
+ userAgent: entry.userAgent,
51
+ metadata: entry.metadata,
52
+ timestamp: entry.timestamp
53
+ });
54
+ }
55
+ async query(options = {}) {
56
+ await this.ensureIndexes();
57
+ const query = {};
58
+ if (options.resource) query.resource = options.resource;
59
+ if (options.documentId) query.documentId = options.documentId;
60
+ if (options.userId) query.userId = options.userId;
61
+ if (options.organizationId) query.organizationId = options.organizationId;
62
+ if (options.action) {
63
+ const actions = Array.isArray(options.action) ? options.action : [options.action];
64
+ query.action = actions.length === 1 ? actions[0] : { $in: actions };
65
+ }
66
+ if (options.from || options.to) {
67
+ query.timestamp = {};
68
+ if (options.from) query.timestamp.$gte = options.from;
69
+ if (options.to) query.timestamp.$lte = options.to;
70
+ }
71
+ const offset = options.offset ?? 0;
72
+ const limit = options.limit ?? 100;
73
+ return (await this.collection.find(query).sort({ timestamp: -1 }).skip(offset).limit(limit).toArray()).map((doc) => ({
74
+ id: String(doc._id),
75
+ resource: doc.resource,
76
+ documentId: doc.documentId,
77
+ action: doc.action,
78
+ userId: doc.userId,
79
+ organizationId: doc.organizationId,
80
+ before: doc.before,
81
+ after: doc.after,
82
+ changes: doc.changes,
83
+ requestId: doc.requestId,
84
+ ipAddress: doc.ipAddress,
85
+ userAgent: doc.userAgent,
86
+ metadata: doc.metadata,
87
+ timestamp: doc.timestamp
88
+ }));
89
+ }
90
+ };
91
+
92
+ //#endregion
93
+ export { MongoAuditStore as t };
@@ -0,0 +1,71 @@
1
+ import { n as IdempotencyResult, r as IdempotencyStore } from "./interface-CSNjltAc.mjs";
2
+
3
+ //#region src/idempotency/stores/mongodb.d.ts
4
+ interface MongoConnection {
5
+ db: {
6
+ collection(name: string): MongoCollection;
7
+ };
8
+ }
9
+ interface MongoCollection {
10
+ findOne(filter: object): Promise<IdempotencyDocument | null>;
11
+ insertOne(doc: object): Promise<{
12
+ acknowledged: boolean;
13
+ }>;
14
+ updateOne(filter: object, update: object, options?: object): Promise<{
15
+ acknowledged: boolean;
16
+ matchedCount: number;
17
+ modifiedCount: number;
18
+ }>;
19
+ deleteOne(filter: object): Promise<{
20
+ deletedCount: number;
21
+ }>;
22
+ deleteMany(filter: object): Promise<{
23
+ deletedCount: number;
24
+ }>;
25
+ createIndex(spec: object, options?: object): Promise<string>;
26
+ }
27
+ interface IdempotencyDocument {
28
+ _id: string;
29
+ result?: {
30
+ statusCode: number;
31
+ headers: Record<string, string>;
32
+ body: unknown;
33
+ };
34
+ lock?: {
35
+ requestId: string;
36
+ expiresAt: Date;
37
+ };
38
+ createdAt: Date;
39
+ expiresAt: Date;
40
+ }
41
+ interface MongoIdempotencyStoreOptions {
42
+ /** Mongoose connection or MongoDB connection object */
43
+ connection: MongoConnection;
44
+ /** Collection name (default: 'arc_idempotency') */
45
+ collection?: string;
46
+ /** Create TTL index on startup (default: true) */
47
+ createIndex?: boolean;
48
+ /** Default TTL in ms (default: 86400000 = 24 hours) */
49
+ ttlMs?: number;
50
+ }
51
+ declare class MongoIdempotencyStore implements IdempotencyStore {
52
+ readonly name = "mongodb";
53
+ private connection;
54
+ private collectionName;
55
+ private ttlMs;
56
+ private indexCreated;
57
+ constructor(options: MongoIdempotencyStoreOptions);
58
+ private get collection();
59
+ private ensureIndex;
60
+ get(key: string): Promise<IdempotencyResult | undefined>;
61
+ set(key: string, result: Omit<IdempotencyResult, 'key'>): Promise<void>;
62
+ tryLock(key: string, requestId: string, ttlMs: number): Promise<boolean>;
63
+ unlock(key: string, requestId: string): Promise<void>;
64
+ isLocked(key: string): Promise<boolean>;
65
+ delete(key: string): Promise<void>;
66
+ deleteByPrefix(prefix: string): Promise<number>;
67
+ findByPrefix(prefix: string): Promise<IdempotencyResult | undefined>;
68
+ close(): Promise<void>;
69
+ }
70
+ //#endregion
71
+ export { MongoIdempotencyStoreOptions as n, MongoIdempotencyStore as t };