@friggframework/core 2.0.0-next.127 → 2.0.0-next.129
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/CLAUDE.md +166 -7
- package/core/CLAUDE.md +57 -1
- package/core/Worker.js +420 -9
- package/core/create-handler.js +20 -0
- package/core/index.js +6 -0
- package/core/invocation-deadline.js +91 -0
- package/core/invocation-scope.js +30 -24
- package/core/rate-limited-response.js +27 -0
- package/database/encryption/field-encryption-service.js +42 -0
- package/database/encryption/prisma-encryption-extension.js +6 -9
- package/encrypt/Cryptor.js +90 -38
- package/errors/fetch-error.js +10 -6
- package/errors/index.js +2 -0
- package/errors/rate-limit-error.js +46 -0
- package/generated/prisma-mongodb/edge.js +6 -2
- package/generated/prisma-mongodb/index.js +10 -2
- package/generated/prisma-mongodb/libquery_engine-linux-arm64-openssl-3.0.x.so.node +0 -0
- package/generated/prisma-mongodb/package.json +1 -1
- package/generated/prisma-mongodb/schema.prisma +1 -1
- package/generated/prisma-mongodb/wasm.js +6 -2
- package/generated/prisma-postgresql/edge.js +6 -2
- package/generated/prisma-postgresql/index.js +10 -2
- package/generated/prisma-postgresql/libquery_engine-linux-arm64-openssl-3.0.x.so.node +0 -0
- package/generated/prisma-postgresql/package.json +1 -1
- package/generated/prisma-postgresql/schema.prisma +1 -1
- package/generated/prisma-postgresql/wasm.js +6 -2
- package/handlers/app-handler-helpers.js +15 -0
- package/handlers/backend-utils.js +75 -1
- package/handlers/workers/integration-defined-workers.js +2 -0
- package/index.js +18 -0
- package/infrastructure/scheduler/eventbridge-scheduler-adapter.js +2 -0
- package/integrations/repositories/integration-repository-documentdb.js +59 -10
- package/integrations/repositories/integration-repository-interface.js +50 -7
- package/integrations/repositories/integration-repository-mongo.js +88 -16
- package/integrations/repositories/integration-repository-postgres.js +89 -16
- package/integrations/repositories/message-item-shared.js +17 -0
- package/integrations/tests/doubles/prisma-message-row.js +24 -0
- package/integrations/tests/doubles/test-integration-repository.js +32 -2
- package/integrations/use-cases/clear-rate-limit-wait.js +28 -0
- package/integrations/use-cases/index.js +7 -1
- package/integrations/use-cases/record-rate-limit-message.js +104 -0
- package/integrations/use-cases/record-rate-limit-wait.js +36 -0
- package/integrations/use-cases/update-integration-messages.js +28 -9
- package/logs/serialize.js +15 -0
- package/modules/requester/oauth-2.js +8 -0
- package/modules/requester/rate-limit/index.js +4 -0
- package/modules/requester/rate-limit/parsers.js +249 -0
- package/modules/requester/rate-limit/policy.js +321 -0
- package/modules/requester/requester.js +187 -9
- package/package.json +7 -6
- package/prisma-mongodb/schema.prisma +1 -1
- package/prisma-postgresql/schema.prisma +1 -1
- package/queues/queue-deferral.js +80 -0
- package/queues/queue-delivery.js +1 -0
- package/queues/queuer-util.js +1 -1
- package/telemetry/otel-telemetry.js +76 -3
- package/telemetry/telemetry-config.js +16 -5
- package/telemetry/telemetry-runtime.js +14 -1
- package/types/core/consumer.fixture.ts +12 -0
- package/types/core/index.d.ts +84 -0
- package/types/errors/index.d.ts +47 -0
- package/types/integrations/index.d.ts +25 -4
- package/types/module-plugin/index.d.ts +45 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const isValidDate = (value) =>
|
|
2
|
+
value instanceof Date && !Number.isNaN(value.getTime());
|
|
3
|
+
|
|
4
|
+
function rateLimitedResponse(error, now = Date.now()) {
|
|
5
|
+
if (error?.isRateLimited !== true) return null;
|
|
6
|
+
if (!isValidDate(error.retryAt)) {
|
|
7
|
+
return {
|
|
8
|
+
statusCode: 429,
|
|
9
|
+
headers: {},
|
|
10
|
+
body: { error: 'Too Many Requests' },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const retryAfterSeconds = Math.max(
|
|
14
|
+
0,
|
|
15
|
+
Math.ceil((error.retryAt.getTime() - now) / 1000)
|
|
16
|
+
);
|
|
17
|
+
return {
|
|
18
|
+
statusCode: 429,
|
|
19
|
+
headers: { 'Retry-After': String(retryAfterSeconds) },
|
|
20
|
+
body: {
|
|
21
|
+
error: 'Too Many Requests',
|
|
22
|
+
retryAt: error.retryAt.toISOString(),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { rateLimitedResponse };
|
|
@@ -83,6 +83,48 @@ class FieldEncryptionService {
|
|
|
83
83
|
return encrypted;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
async encryptUpsert(modelName, { create, update }) {
|
|
87
|
+
const fields = this._getWriteFields(modelName);
|
|
88
|
+
if (fields.length === 0) {
|
|
89
|
+
return { create, update };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const encryptedCreate = await this.encryptFields(modelName, create);
|
|
93
|
+
const pathsOverlap = fields.some((outer) =>
|
|
94
|
+
fields.some((inner) => inner.startsWith(`${outer}.`))
|
|
95
|
+
);
|
|
96
|
+
if (!create || !update || pathsOverlap) {
|
|
97
|
+
return {
|
|
98
|
+
create: encryptedCreate,
|
|
99
|
+
update: await this.encryptFields(modelName, update),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const reusing = this._deepClone(update);
|
|
104
|
+
for (const fieldPath of fields) {
|
|
105
|
+
const value = this._getNestedValue(update, fieldPath);
|
|
106
|
+
const createCiphertext = this._getNestedValue(
|
|
107
|
+
encryptedCreate,
|
|
108
|
+
fieldPath
|
|
109
|
+
);
|
|
110
|
+
if (
|
|
111
|
+
this._shouldEncrypt(value) &&
|
|
112
|
+
this._isEncrypted(createCiphertext) &&
|
|
113
|
+
this._serializeForEncryption(value) ===
|
|
114
|
+
this._serializeForEncryption(
|
|
115
|
+
this._getNestedValue(create, fieldPath)
|
|
116
|
+
)
|
|
117
|
+
) {
|
|
118
|
+
this._setNestedValue(reusing, fieldPath, createCiphertext);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
create: encryptedCreate,
|
|
124
|
+
update: await this.encryptFields(modelName, reusing),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
86
128
|
async decryptFields(modelName, document) {
|
|
87
129
|
if (!document || typeof document !== 'object') {
|
|
88
130
|
return document;
|
|
@@ -114,18 +114,15 @@ function createEncryptionExtension({ cryptor, enabled = true }) {
|
|
|
114
114
|
},
|
|
115
115
|
|
|
116
116
|
async upsert({ model, args, query }) {
|
|
117
|
+
const encrypted = await encryptionService.encryptUpsert(
|
|
118
|
+
model,
|
|
119
|
+
args
|
|
120
|
+
);
|
|
117
121
|
if (args.create) {
|
|
118
|
-
args.create =
|
|
119
|
-
model,
|
|
120
|
-
args.create
|
|
121
|
-
);
|
|
122
|
+
args.create = encrypted.create;
|
|
122
123
|
}
|
|
123
|
-
|
|
124
124
|
if (args.update) {
|
|
125
|
-
args.update =
|
|
126
|
-
model,
|
|
127
|
-
args.update
|
|
128
|
-
);
|
|
125
|
+
args.update = encrypted.update;
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
const result = await query(args);
|
package/encrypt/Cryptor.js
CHANGED
|
@@ -20,26 +20,86 @@ const crypto = require('crypto');
|
|
|
20
20
|
const { KMSClient, GenerateDataKeyCommand, DecryptCommand } = require('@aws-sdk/client-kms');
|
|
21
21
|
const aes = require('./aes');
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
const DATA_KEY_TTL_MS = 60 * 60 * 1000;
|
|
24
|
+
const DATA_KEY_CACHE_MAX_ENTRIES = 10000;
|
|
25
|
+
|
|
26
|
+
function createKmsDataKeys() {
|
|
27
|
+
let client = null;
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
|
|
30
|
+
const getClient = () => {
|
|
31
|
+
client = client || new KMSClient({});
|
|
32
|
+
return client;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const remember = (encryptedKeyB64, promise) => {
|
|
36
|
+
cache.delete(encryptedKeyB64);
|
|
37
|
+
if (cache.size >= DATA_KEY_CACHE_MAX_ENTRIES) {
|
|
38
|
+
cache.delete(cache.keys().next().value);
|
|
39
|
+
}
|
|
40
|
+
cache.set(encryptedKeyB64, {
|
|
41
|
+
promise,
|
|
42
|
+
expiresAt: Date.now() + DATA_KEY_TTL_MS,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const lookup = (encryptedKeyB64) => {
|
|
47
|
+
const entry = cache.get(encryptedKeyB64);
|
|
48
|
+
if (!entry) {
|
|
49
|
+
return undefined;
|
|
41
50
|
}
|
|
51
|
+
cache.delete(encryptedKeyB64);
|
|
52
|
+
if (entry.expiresAt <= Date.now()) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
cache.set(encryptedKeyB64, entry);
|
|
56
|
+
return entry.promise;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
async generate() {
|
|
61
|
+
const dataKey = await getClient().send(
|
|
62
|
+
new GenerateDataKeyCommand({
|
|
63
|
+
KeyId: process.env.KMS_KEY_ARN,
|
|
64
|
+
KeySpec: 'AES_256',
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
const encryptedKey = Buffer.from(dataKey.CiphertextBlob).toString('base64');
|
|
68
|
+
remember(encryptedKey, Promise.resolve(dataKey.Plaintext));
|
|
69
|
+
return {
|
|
70
|
+
keyId: Buffer.from(dataKey.KeyId).toString('base64'),
|
|
71
|
+
encryptedKey,
|
|
72
|
+
plaintext: dataKey.Plaintext,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
async decrypt(keyId, encryptedKeyB64) {
|
|
77
|
+
const cached = lookup(encryptedKeyB64);
|
|
78
|
+
if (cached) {
|
|
79
|
+
return cached;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const pending = getClient()
|
|
83
|
+
.send(
|
|
84
|
+
new DecryptCommand({
|
|
85
|
+
KeyId: keyId,
|
|
86
|
+
CiphertextBlob: Buffer.from(encryptedKeyB64, 'base64'),
|
|
87
|
+
})
|
|
88
|
+
)
|
|
89
|
+
.then((dataKey) => dataKey.Plaintext);
|
|
90
|
+
remember(encryptedKeyB64, pending);
|
|
91
|
+
pending.catch(() => {
|
|
92
|
+
if (cache.get(encryptedKeyB64)?.promise === pending) {
|
|
93
|
+
cache.delete(encryptedKeyB64);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return pending;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
42
100
|
|
|
101
|
+
const localDataKeys = {
|
|
102
|
+
async generate() {
|
|
43
103
|
const { AES_KEY, AES_KEY_ID } = process.env;
|
|
44
104
|
const randomKey = crypto.randomBytes(32).toString('hex').slice(0, 32);
|
|
45
105
|
|
|
@@ -50,9 +110,9 @@ class Cryptor {
|
|
|
50
110
|
),
|
|
51
111
|
plaintext: randomKey,
|
|
52
112
|
};
|
|
53
|
-
}
|
|
113
|
+
},
|
|
54
114
|
|
|
55
|
-
|
|
115
|
+
async decrypt(keyId, encryptedKeyB64) {
|
|
56
116
|
const availableKeys = {
|
|
57
117
|
[process.env.AES_KEY_ID]: process.env.AES_KEY,
|
|
58
118
|
[process.env.DEPRECATED_AES_KEY_ID]: process.env.DEPRECATED_AES_KEY,
|
|
@@ -64,27 +124,20 @@ class Cryptor {
|
|
|
64
124
|
throw new Error('Encryption key not found');
|
|
65
125
|
}
|
|
66
126
|
|
|
67
|
-
return key;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async decryptDataKey(keyId, encryptedKey) {
|
|
71
|
-
if (this.shouldUseAws) {
|
|
72
|
-
const kmsClient = new KMSClient({});
|
|
73
|
-
const command = new DecryptCommand({
|
|
74
|
-
KeyId: keyId,
|
|
75
|
-
CiphertextBlob: encryptedKey,
|
|
76
|
-
});
|
|
77
|
-
const dataKey = await kmsClient.send(command);
|
|
127
|
+
return aes.decrypt(Buffer.from(encryptedKeyB64, 'base64'), key);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
78
130
|
|
|
79
|
-
|
|
80
|
-
}
|
|
131
|
+
const kmsDataKeys = createKmsDataKeys();
|
|
81
132
|
|
|
82
|
-
|
|
83
|
-
|
|
133
|
+
class Cryptor {
|
|
134
|
+
constructor({ shouldUseAws }) {
|
|
135
|
+
this.shouldUseAws = shouldUseAws;
|
|
136
|
+
this.dataKeys = shouldUseAws ? kmsDataKeys : localDataKeys;
|
|
84
137
|
}
|
|
85
138
|
|
|
86
139
|
async encrypt(text) {
|
|
87
|
-
const { keyId, encryptedKey, plaintext } = await this.
|
|
140
|
+
const { keyId, encryptedKey, plaintext } = await this.dataKeys.generate();
|
|
88
141
|
const encryptedText = aes.encrypt(text, plaintext);
|
|
89
142
|
return `${keyId}:${encryptedText}:${encryptedKey}`;
|
|
90
143
|
}
|
|
@@ -93,8 +146,7 @@ class Cryptor {
|
|
|
93
146
|
const split = text.split(':');
|
|
94
147
|
const keyId = Buffer.from(split[0], 'base64').toString();
|
|
95
148
|
const encryptedText = `${split[1]}:${split[2]}`;
|
|
96
|
-
const
|
|
97
|
-
const plaintext = await this.decryptDataKey(keyId, encryptedKey);
|
|
149
|
+
const plaintext = await this.dataKeys.decrypt(keyId, split[3]);
|
|
98
150
|
return aes.decrypt(encryptedText, plaintext);
|
|
99
151
|
}
|
|
100
152
|
}
|
package/errors/fetch-error.js
CHANGED
|
@@ -66,12 +66,16 @@ class FetchError extends BaseError {
|
|
|
66
66
|
|
|
67
67
|
static async create(options = {}) {
|
|
68
68
|
const { response } = options;
|
|
69
|
-
let responseBody =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
let { responseBody } = options;
|
|
70
|
+
if (responseBody === undefined || responseBody === null) {
|
|
71
|
+
const canRead =
|
|
72
|
+
response &&
|
|
73
|
+
!response.bodyUsed &&
|
|
74
|
+
typeof response.text === 'function';
|
|
75
|
+
responseBody = (canRead && (await response.text())) || options.body;
|
|
76
|
+
}
|
|
77
|
+
const ErrorClass = typeof this === 'function' ? this : FetchError;
|
|
78
|
+
return new ErrorClass({ ...options, responseBody });
|
|
75
79
|
}
|
|
76
80
|
}
|
|
77
81
|
|
package/errors/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { BaseError } = require('./base-error');
|
|
2
2
|
const { FetchError } = require('./fetch-error');
|
|
3
3
|
const { HaltError } = require('./halt-error');
|
|
4
|
+
const { RateLimitError } = require('./rate-limit-error');
|
|
4
5
|
const {
|
|
5
6
|
RequiredPropertyError,
|
|
6
7
|
ParameterTypeError,
|
|
@@ -14,6 +15,7 @@ module.exports = {
|
|
|
14
15
|
BaseError,
|
|
15
16
|
FetchError,
|
|
16
17
|
HaltError,
|
|
18
|
+
RateLimitError,
|
|
17
19
|
RequiredPropertyError,
|
|
18
20
|
ParameterTypeError,
|
|
19
21
|
ClientSafeError,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { FetchError } = require('./fetch-error');
|
|
2
|
+
|
|
3
|
+
function resolveTiming({ hint, waitMs, now }) {
|
|
4
|
+
if (waitMs !== undefined) {
|
|
5
|
+
return { waitMs, retryAt: new Date(now + waitMs) };
|
|
6
|
+
}
|
|
7
|
+
if (hint?.retryAt) {
|
|
8
|
+
const retryAt = new Date(hint.retryAt);
|
|
9
|
+
if (!Number.isNaN(retryAt.getTime())) {
|
|
10
|
+
return { waitMs: Math.max(0, retryAt.getTime() - now), retryAt };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (hint?.waitMs !== undefined) {
|
|
14
|
+
return {
|
|
15
|
+
waitMs: hint.waitMs,
|
|
16
|
+
retryAt: new Date(now + hint.waitMs),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return { waitMs: undefined, retryAt: undefined };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
class RateLimitError extends FetchError {
|
|
23
|
+
constructor({
|
|
24
|
+
hint,
|
|
25
|
+
waitMs,
|
|
26
|
+
module,
|
|
27
|
+
scopeKey,
|
|
28
|
+
now = Date.now(),
|
|
29
|
+
...fetchErrorArgs
|
|
30
|
+
} = {}) {
|
|
31
|
+
super(fetchErrorArgs);
|
|
32
|
+
|
|
33
|
+
const timing = resolveTiming({ hint, waitMs, now });
|
|
34
|
+
this.statusCode ??= fetchErrorArgs.cause?.statusCode;
|
|
35
|
+
this.isRateLimited = true;
|
|
36
|
+
this.waitMs = timing.waitMs;
|
|
37
|
+
this.retryAt = timing.retryAt;
|
|
38
|
+
this.reason = hint?.reason ?? 'unknown';
|
|
39
|
+
this.policy = hint?.policy;
|
|
40
|
+
this.source = hint?.source ?? 'unknown';
|
|
41
|
+
this.module = module;
|
|
42
|
+
this.scopeKey = scopeKey;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { RateLimitError };
|
|
@@ -333,6 +333,10 @@ const config = {
|
|
|
333
333
|
{
|
|
334
334
|
"fromEnvVar": null,
|
|
335
335
|
"value": "rhel-openssl-3.0.x"
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
"fromEnvVar": null,
|
|
339
|
+
"value": "linux-arm64-openssl-3.0.x"
|
|
336
340
|
}
|
|
337
341
|
],
|
|
338
342
|
"previewFeatures": [],
|
|
@@ -359,8 +363,8 @@ const config = {
|
|
|
359
363
|
}
|
|
360
364
|
}
|
|
361
365
|
},
|
|
362
|
-
"inlineSchema": "// Frigg Framework - Prisma Schema\n// MongoDB database schema for enterprise integration platform\n// Migration from Mongoose ODM to Prisma ORM\n\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"../generated/prisma-mongodb\"\n binaryTargets = [\"native\", \"rhel-openssl-3.0.x\"] // native for local dev, rhel for Lambda deployment\n // Library engine (default since Prisma 3.x): Rust query engine loads as a\n // Node-API addon inside the same process. The binary engine forks a child\n // query-engine subprocess and communicates over a local HTTP/IPC pipe with\n // NO client-side timeout — a zombied child wedges the Node process until\n // Lambda's 900s cap. Switching to library eliminates that entire class of\n // silent hangs. See friggframework/frigg#580 for the investigation.\n engineType = \"library\"\n}\n\ndatasource db {\n provider = \"mongodb\"\n url = env(\"DATABASE_URL\")\n}\n\n// ============================================================================\n// USER MODELS\n// ============================================================================\n\n/// User model with discriminator pattern support\n/// Replaces Mongoose discriminators (IndividualUser, OrganizationUser)\nmodel User {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n type UserType\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // IndividualUser fields (nullable for organizations)\n email String?\n username String?\n hashword String? // Bcrypt hashed password (handled in application layer)\n appUserId String?\n organizationId String? @db.ObjectId\n\n // Self-referential relation for organization membership\n organization User? @relation(\"OrgMembers\", fields: [organizationId], references: [id], onDelete: NoAction, onUpdate: NoAction)\n members User[] @relation(\"OrgMembers\")\n\n // OrganizationUser fields (nullable for individuals)\n appOrgId String?\n name String?\n\n // Relations\n tokens Token[]\n credentials Credential[]\n entities Entity[]\n integrations Integration[]\n processes Process[]\n\n @@unique([username, appUserId])\n @@index([type])\n @@index([appUserId])\n @@index([organizationId])\n @@map(\"User\")\n}\n\nenum UserType {\n INDIVIDUAL\n ORGANIZATION\n}\n\n// ============================================================================\n// AUTHENTICATION MODELS\n// ============================================================================\n\n/// Authentication tokens with expiration\n/// Bcrypt hashed tokens stored (handled in application layer)\nmodel Token {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n token String // Bcrypt hashed\n created DateTime @default(now())\n expires DateTime?\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n @@index([userId])\n @@index([expires])\n @@map(\"Token\")\n}\n\n// ============================================================================\n// CREDENTIAL & ENTITY MODELS\n// ============================================================================\n\n/// OAuth credentials and API tokens\n/// All sensitive data encrypted with KMS at rest\nmodel Credential {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n authIsValid Boolean?\n externalId String?\n\n // Dynamic OAuth fields stored as JSON (encrypted via Prisma middleware)\n // Contains: access_token, refresh_token, domain, expires_in, token_type, etc.\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n entities Entity[]\n\n @@index([userId])\n @@index([externalId])\n @@map(\"Credential\")\n}\n\n/// External service entities (API connections)\nmodel Entity {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n credentialId String? @db.ObjectId\n credential Credential? @relation(fields: [credentialId], references: [id], onDelete: SetNull)\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n name String?\n moduleName String?\n externalId String?\n\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations - many-to-many with scalar lists\n integrations Integration[] @relation(\"IntegrationEntities\", fields: [integrationIds], references: [id])\n integrationIds String[] @db.ObjectId\n\n syncs Sync[] @relation(\"SyncEntities\", fields: [syncIds], references: [id])\n syncIds String[] @db.ObjectId\n\n dataIdentifiers DataIdentifier[]\n associationObjects AssociationObject[]\n\n @@index([userId])\n @@index([externalId])\n @@index([moduleName])\n @@index([credentialId])\n @@map(\"Entity\")\n}\n\n// ============================================================================\n// INTEGRATION MODELS\n// ============================================================================\n\n/// Main integration configuration and state\nmodel Integration {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n status IntegrationStatus @default(IN_CREATION)\n\n // Configuration and version\n config Json? // Integration configuration object\n version String?\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"IntegrationEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n // Message arrays (stored as JSON)\n errors Json @default(\"[]\")\n warnings Json @default(\"[]\")\n info Json @default(\"[]\")\n logs Json @default(\"[]\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n associations Association[]\n syncs Sync[]\n mappings IntegrationMapping[]\n processes Process[]\n\n @@index([userId])\n @@index([status])\n @@map(\"Integration\")\n}\n\nenum IntegrationStatus {\n ENABLED\n NEEDS_CONFIG\n PROCESSING\n DISABLED\n ERROR\n IN_CREATION\n IN_DELETION\n}\n\n/// Integration-specific data mappings\n/// All mapping data encrypted with KMS\nmodel IntegrationMapping {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n sourceId String?\n\n // Encrypted mapping data (handled via Prisma middleware)\n mapping Json?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, sourceId])\n @@index([integrationId])\n @@index([sourceId])\n @@map(\"IntegrationMapping\")\n}\n\n// ============================================================================\n// PROCESS MODELS\n// ============================================================================\n\n/// Generic Process Model - tracks any long-running operation\n/// Used for: CRM syncs, data migrations, bulk operations, etc.\nmodel Process {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n // Core references\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Process identification\n name String // e.g., \"zoho-crm-contact-sync\", \"pipedrive-lead-sync\"\n type String // e.g., \"CRM_SYNC\", \"DATA_MIGRATION\", \"BULK_OPERATION\"\n\n // State machine\n state String // Current state (integration-defined states)\n\n // Flexible storage\n context Json @default(\"{}\") // Process-specific data (pagination, metadata, etc.)\n results Json @default(\"{}\") // Process results and metrics\n\n // Hierarchy support\n childProcesses String[] @db.ObjectId\n parentProcessId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([userId])\n @@index([integrationId])\n @@index([type])\n @@index([state])\n @@index([name])\n @@map(\"Process\")\n}\n\n// ============================================================================\n// SYNC MODELS\n// ============================================================================\n\n/// Bidirectional data synchronization tracking\nmodel Sync {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String? @db.ObjectId\n integration Integration? @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"SyncEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n hash String\n name String\n\n // Data identifiers (extracted to separate model)\n dataIdentifiers DataIdentifier[]\n\n @@index([integrationId])\n @@index([hash])\n @@index([name])\n @@map(\"Sync\")\n}\n\n/// Data identifier for sync operations\n/// Replaces nested array structure in Mongoose\nmodel DataIdentifier {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n syncId String? @db.ObjectId\n sync Sync? @relation(fields: [syncId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n\n // Identifier data (can be any structure)\n idData Json\n\n hash String\n\n @@index([syncId])\n @@index([entityId])\n @@index([hash])\n @@map(\"DataIdentifier\")\n}\n\n// ============================================================================\n// ASSOCIATION MODELS\n// ============================================================================\n\n/// Entity associations with cardinality tracking\nmodel Association {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n name String\n type AssociationType\n primaryObject String\n\n // Associated objects (extracted to separate model)\n objects AssociationObject[]\n\n @@index([integrationId])\n @@index([name])\n @@map(\"Association\")\n}\n\n/// Association object entry\n/// Replaces nested array structure in Mongoose\nmodel AssociationObject {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n associationId String @db.ObjectId\n association Association @relation(fields: [associationId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n objectType String\n objId String\n metadata Json? // Optional metadata\n\n @@index([associationId])\n @@index([entityId])\n @@map(\"AssociationObject\")\n}\n\nenum AssociationType {\n ONE_TO_MANY\n ONE_TO_ONE\n MANY_TO_ONE\n}\n\n// ============================================================================\n// UTILITY MODELS\n// ============================================================================\n\n/// Generic state storage\nmodel State {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n state Json?\n\n @@map(\"State\")\n}\n\n/// AWS API Gateway WebSocket connection tracking\nmodel WebsocketConnection {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n connectionId String?\n\n @@index([connectionId])\n @@map(\"WebsocketConnection\")\n}\n\n// ============================================================================\n// ADMIN PROCESS MODELS\n// ============================================================================\n\n/// Admin process state machine\nenum AdminScriptExecutionState {\n PENDING\n RUNNING\n COMPLETED\n FAILED\n}\n\n/// Admin process tracking (like Process but without user/integration FK)\n/// Used for: admin scripts, db migrations, system maintenance tasks\nmodel AdminScriptExecution {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n name String // e.g., \"oauth-token-refresh\", \"db-migration-xyz\"\n type String // e.g., \"ADMIN_SCRIPT\", \"DB_MIGRATION\"\n\n // State machine\n state AdminScriptExecutionState @default(PENDING)\n\n // Flexible storage (mirrors Process model pattern)\n context Json @default(\"{}\") // input, trigger, audit info, script version\n results Json @default(\"{}\") // output, logs, metrics, errors\n\n // Hierarchy support\n childExecutions String[] @db.ObjectId\n parentExecutionId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([name, createdAt(sort: Desc)])\n @@index([state])\n @@index([type])\n @@map(\"AdminScriptExecution\")\n}\n\n/// Script scheduling configuration for hybrid scheduling (SQS + EventBridge)\nmodel ScriptSchedule {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n scriptName String @unique\n enabled Boolean @default(false)\n cronExpression String?\n timezone String @default(\"UTC\")\n lastTriggeredAt DateTime?\n nextTriggerAt DateTime?\n\n // External Scheduler (e.g., AWS EventBridge Scheduler)\n externalScheduleId String?\n externalScheduleName String?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([enabled])\n @@map(\"ScriptSchedule\")\n}\n\n/// Durable usage counters, deliberately isolated: no userId and no foreign key\n/// to Integration, so a user-scoped query can never return a usage row and usage\n/// history survives integration deletion.\nmodel UsageCounter {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n integrationId String\n integrationType String\n metric String\n window String // e.g. \"day:2026-07-05\" or \"hour:2026-07-05T14\"\n value BigInt @default(0) // BigInt: a busy day/hour counter can exceed 32-bit\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, integrationType, metric, window])\n // Covers totals() (metric + window prefix/range, no integrationType filter).\n @@index([metric, window])\n // Covers series() (metric + integrationType + window range).\n @@index([metric, integrationType, window])\n @@map(\"UsageCounter\")\n}\n",
|
|
363
|
-
"inlineSchemaHash": "
|
|
366
|
+
"inlineSchema": "// Frigg Framework - Prisma Schema\n// MongoDB database schema for enterprise integration platform\n// Migration from Mongoose ODM to Prisma ORM\n\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"../generated/prisma-mongodb\"\n binaryTargets = [\"native\", \"rhel-openssl-3.0.x\", \"linux-arm64-openssl-3.0.x\"] // native for local dev, rhel for x86_64 Lambda, linux-arm64 for arm64 Lambda\n // Library engine (default since Prisma 3.x): Rust query engine loads as a\n // Node-API addon inside the same process. The binary engine forks a child\n // query-engine subprocess and communicates over a local HTTP/IPC pipe with\n // NO client-side timeout — a zombied child wedges the Node process until\n // Lambda's 900s cap. Switching to library eliminates that entire class of\n // silent hangs. See friggframework/frigg#580 for the investigation.\n engineType = \"library\"\n}\n\ndatasource db {\n provider = \"mongodb\"\n url = env(\"DATABASE_URL\")\n}\n\n// ============================================================================\n// USER MODELS\n// ============================================================================\n\n/// User model with discriminator pattern support\n/// Replaces Mongoose discriminators (IndividualUser, OrganizationUser)\nmodel User {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n type UserType\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // IndividualUser fields (nullable for organizations)\n email String?\n username String?\n hashword String? // Bcrypt hashed password (handled in application layer)\n appUserId String?\n organizationId String? @db.ObjectId\n\n // Self-referential relation for organization membership\n organization User? @relation(\"OrgMembers\", fields: [organizationId], references: [id], onDelete: NoAction, onUpdate: NoAction)\n members User[] @relation(\"OrgMembers\")\n\n // OrganizationUser fields (nullable for individuals)\n appOrgId String?\n name String?\n\n // Relations\n tokens Token[]\n credentials Credential[]\n entities Entity[]\n integrations Integration[]\n processes Process[]\n\n @@unique([username, appUserId])\n @@index([type])\n @@index([appUserId])\n @@index([organizationId])\n @@map(\"User\")\n}\n\nenum UserType {\n INDIVIDUAL\n ORGANIZATION\n}\n\n// ============================================================================\n// AUTHENTICATION MODELS\n// ============================================================================\n\n/// Authentication tokens with expiration\n/// Bcrypt hashed tokens stored (handled in application layer)\nmodel Token {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n token String // Bcrypt hashed\n created DateTime @default(now())\n expires DateTime?\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n @@index([userId])\n @@index([expires])\n @@map(\"Token\")\n}\n\n// ============================================================================\n// CREDENTIAL & ENTITY MODELS\n// ============================================================================\n\n/// OAuth credentials and API tokens\n/// All sensitive data encrypted with KMS at rest\nmodel Credential {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n authIsValid Boolean?\n externalId String?\n\n // Dynamic OAuth fields stored as JSON (encrypted via Prisma middleware)\n // Contains: access_token, refresh_token, domain, expires_in, token_type, etc.\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n entities Entity[]\n\n @@index([userId])\n @@index([externalId])\n @@map(\"Credential\")\n}\n\n/// External service entities (API connections)\nmodel Entity {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n credentialId String? @db.ObjectId\n credential Credential? @relation(fields: [credentialId], references: [id], onDelete: SetNull)\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n name String?\n moduleName String?\n externalId String?\n\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations - many-to-many with scalar lists\n integrations Integration[] @relation(\"IntegrationEntities\", fields: [integrationIds], references: [id])\n integrationIds String[] @db.ObjectId\n\n syncs Sync[] @relation(\"SyncEntities\", fields: [syncIds], references: [id])\n syncIds String[] @db.ObjectId\n\n dataIdentifiers DataIdentifier[]\n associationObjects AssociationObject[]\n\n @@index([userId])\n @@index([externalId])\n @@index([moduleName])\n @@index([credentialId])\n @@map(\"Entity\")\n}\n\n// ============================================================================\n// INTEGRATION MODELS\n// ============================================================================\n\n/// Main integration configuration and state\nmodel Integration {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n status IntegrationStatus @default(IN_CREATION)\n\n // Configuration and version\n config Json? // Integration configuration object\n version String?\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"IntegrationEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n // Message arrays (stored as JSON)\n errors Json @default(\"[]\")\n warnings Json @default(\"[]\")\n info Json @default(\"[]\")\n logs Json @default(\"[]\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n associations Association[]\n syncs Sync[]\n mappings IntegrationMapping[]\n processes Process[]\n\n @@index([userId])\n @@index([status])\n @@map(\"Integration\")\n}\n\nenum IntegrationStatus {\n ENABLED\n NEEDS_CONFIG\n PROCESSING\n DISABLED\n ERROR\n IN_CREATION\n IN_DELETION\n}\n\n/// Integration-specific data mappings\n/// All mapping data encrypted with KMS\nmodel IntegrationMapping {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n sourceId String?\n\n // Encrypted mapping data (handled via Prisma middleware)\n mapping Json?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, sourceId])\n @@index([integrationId])\n @@index([sourceId])\n @@map(\"IntegrationMapping\")\n}\n\n// ============================================================================\n// PROCESS MODELS\n// ============================================================================\n\n/// Generic Process Model - tracks any long-running operation\n/// Used for: CRM syncs, data migrations, bulk operations, etc.\nmodel Process {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n // Core references\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Process identification\n name String // e.g., \"zoho-crm-contact-sync\", \"pipedrive-lead-sync\"\n type String // e.g., \"CRM_SYNC\", \"DATA_MIGRATION\", \"BULK_OPERATION\"\n\n // State machine\n state String // Current state (integration-defined states)\n\n // Flexible storage\n context Json @default(\"{}\") // Process-specific data (pagination, metadata, etc.)\n results Json @default(\"{}\") // Process results and metrics\n\n // Hierarchy support\n childProcesses String[] @db.ObjectId\n parentProcessId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([userId])\n @@index([integrationId])\n @@index([type])\n @@index([state])\n @@index([name])\n @@map(\"Process\")\n}\n\n// ============================================================================\n// SYNC MODELS\n// ============================================================================\n\n/// Bidirectional data synchronization tracking\nmodel Sync {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String? @db.ObjectId\n integration Integration? @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"SyncEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n hash String\n name String\n\n // Data identifiers (extracted to separate model)\n dataIdentifiers DataIdentifier[]\n\n @@index([integrationId])\n @@index([hash])\n @@index([name])\n @@map(\"Sync\")\n}\n\n/// Data identifier for sync operations\n/// Replaces nested array structure in Mongoose\nmodel DataIdentifier {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n syncId String? @db.ObjectId\n sync Sync? @relation(fields: [syncId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n\n // Identifier data (can be any structure)\n idData Json\n\n hash String\n\n @@index([syncId])\n @@index([entityId])\n @@index([hash])\n @@map(\"DataIdentifier\")\n}\n\n// ============================================================================\n// ASSOCIATION MODELS\n// ============================================================================\n\n/// Entity associations with cardinality tracking\nmodel Association {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n name String\n type AssociationType\n primaryObject String\n\n // Associated objects (extracted to separate model)\n objects AssociationObject[]\n\n @@index([integrationId])\n @@index([name])\n @@map(\"Association\")\n}\n\n/// Association object entry\n/// Replaces nested array structure in Mongoose\nmodel AssociationObject {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n associationId String @db.ObjectId\n association Association @relation(fields: [associationId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n objectType String\n objId String\n metadata Json? // Optional metadata\n\n @@index([associationId])\n @@index([entityId])\n @@map(\"AssociationObject\")\n}\n\nenum AssociationType {\n ONE_TO_MANY\n ONE_TO_ONE\n MANY_TO_ONE\n}\n\n// ============================================================================\n// UTILITY MODELS\n// ============================================================================\n\n/// Generic state storage\nmodel State {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n state Json?\n\n @@map(\"State\")\n}\n\n/// AWS API Gateway WebSocket connection tracking\nmodel WebsocketConnection {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n connectionId String?\n\n @@index([connectionId])\n @@map(\"WebsocketConnection\")\n}\n\n// ============================================================================\n// ADMIN PROCESS MODELS\n// ============================================================================\n\n/// Admin process state machine\nenum AdminScriptExecutionState {\n PENDING\n RUNNING\n COMPLETED\n FAILED\n}\n\n/// Admin process tracking (like Process but without user/integration FK)\n/// Used for: admin scripts, db migrations, system maintenance tasks\nmodel AdminScriptExecution {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n name String // e.g., \"oauth-token-refresh\", \"db-migration-xyz\"\n type String // e.g., \"ADMIN_SCRIPT\", \"DB_MIGRATION\"\n\n // State machine\n state AdminScriptExecutionState @default(PENDING)\n\n // Flexible storage (mirrors Process model pattern)\n context Json @default(\"{}\") // input, trigger, audit info, script version\n results Json @default(\"{}\") // output, logs, metrics, errors\n\n // Hierarchy support\n childExecutions String[] @db.ObjectId\n parentExecutionId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([name, createdAt(sort: Desc)])\n @@index([state])\n @@index([type])\n @@map(\"AdminScriptExecution\")\n}\n\n/// Script scheduling configuration for hybrid scheduling (SQS + EventBridge)\nmodel ScriptSchedule {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n scriptName String @unique\n enabled Boolean @default(false)\n cronExpression String?\n timezone String @default(\"UTC\")\n lastTriggeredAt DateTime?\n nextTriggerAt DateTime?\n\n // External Scheduler (e.g., AWS EventBridge Scheduler)\n externalScheduleId String?\n externalScheduleName String?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([enabled])\n @@map(\"ScriptSchedule\")\n}\n\n/// Durable usage counters, deliberately isolated: no userId and no foreign key\n/// to Integration, so a user-scoped query can never return a usage row and usage\n/// history survives integration deletion.\nmodel UsageCounter {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n integrationId String\n integrationType String\n metric String\n window String // e.g. \"day:2026-07-05\" or \"hour:2026-07-05T14\"\n value BigInt @default(0) // BigInt: a busy day/hour counter can exceed 32-bit\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, integrationType, metric, window])\n // Covers totals() (metric + window prefix/range, no integrationType filter).\n @@index([metric, window])\n // Covers series() (metric + integrationType + window range).\n @@index([metric, integrationType, window])\n @@map(\"UsageCounter\")\n}\n",
|
|
367
|
+
"inlineSchemaHash": "8ea47fb22642cea1c5ae56f5c08b37672beac94aa6763081f0412d7b30179804",
|
|
364
368
|
"copyEngine": true
|
|
365
369
|
}
|
|
366
370
|
config.dirname = '/'
|
|
@@ -334,6 +334,10 @@ const config = {
|
|
|
334
334
|
{
|
|
335
335
|
"fromEnvVar": null,
|
|
336
336
|
"value": "rhel-openssl-3.0.x"
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"fromEnvVar": null,
|
|
340
|
+
"value": "linux-arm64-openssl-3.0.x"
|
|
337
341
|
}
|
|
338
342
|
],
|
|
339
343
|
"previewFeatures": [],
|
|
@@ -360,8 +364,8 @@ const config = {
|
|
|
360
364
|
}
|
|
361
365
|
}
|
|
362
366
|
},
|
|
363
|
-
"inlineSchema": "// Frigg Framework - Prisma Schema\n// MongoDB database schema for enterprise integration platform\n// Migration from Mongoose ODM to Prisma ORM\n\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"../generated/prisma-mongodb\"\n binaryTargets = [\"native\", \"rhel-openssl-3.0.x\"] // native for local dev, rhel for Lambda deployment\n // Library engine (default since Prisma 3.x): Rust query engine loads as a\n // Node-API addon inside the same process. The binary engine forks a child\n // query-engine subprocess and communicates over a local HTTP/IPC pipe with\n // NO client-side timeout — a zombied child wedges the Node process until\n // Lambda's 900s cap. Switching to library eliminates that entire class of\n // silent hangs. See friggframework/frigg#580 for the investigation.\n engineType = \"library\"\n}\n\ndatasource db {\n provider = \"mongodb\"\n url = env(\"DATABASE_URL\")\n}\n\n// ============================================================================\n// USER MODELS\n// ============================================================================\n\n/// User model with discriminator pattern support\n/// Replaces Mongoose discriminators (IndividualUser, OrganizationUser)\nmodel User {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n type UserType\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // IndividualUser fields (nullable for organizations)\n email String?\n username String?\n hashword String? // Bcrypt hashed password (handled in application layer)\n appUserId String?\n organizationId String? @db.ObjectId\n\n // Self-referential relation for organization membership\n organization User? @relation(\"OrgMembers\", fields: [organizationId], references: [id], onDelete: NoAction, onUpdate: NoAction)\n members User[] @relation(\"OrgMembers\")\n\n // OrganizationUser fields (nullable for individuals)\n appOrgId String?\n name String?\n\n // Relations\n tokens Token[]\n credentials Credential[]\n entities Entity[]\n integrations Integration[]\n processes Process[]\n\n @@unique([username, appUserId])\n @@index([type])\n @@index([appUserId])\n @@index([organizationId])\n @@map(\"User\")\n}\n\nenum UserType {\n INDIVIDUAL\n ORGANIZATION\n}\n\n// ============================================================================\n// AUTHENTICATION MODELS\n// ============================================================================\n\n/// Authentication tokens with expiration\n/// Bcrypt hashed tokens stored (handled in application layer)\nmodel Token {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n token String // Bcrypt hashed\n created DateTime @default(now())\n expires DateTime?\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n @@index([userId])\n @@index([expires])\n @@map(\"Token\")\n}\n\n// ============================================================================\n// CREDENTIAL & ENTITY MODELS\n// ============================================================================\n\n/// OAuth credentials and API tokens\n/// All sensitive data encrypted with KMS at rest\nmodel Credential {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n authIsValid Boolean?\n externalId String?\n\n // Dynamic OAuth fields stored as JSON (encrypted via Prisma middleware)\n // Contains: access_token, refresh_token, domain, expires_in, token_type, etc.\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n entities Entity[]\n\n @@index([userId])\n @@index([externalId])\n @@map(\"Credential\")\n}\n\n/// External service entities (API connections)\nmodel Entity {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n credentialId String? @db.ObjectId\n credential Credential? @relation(fields: [credentialId], references: [id], onDelete: SetNull)\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n name String?\n moduleName String?\n externalId String?\n\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations - many-to-many with scalar lists\n integrations Integration[] @relation(\"IntegrationEntities\", fields: [integrationIds], references: [id])\n integrationIds String[] @db.ObjectId\n\n syncs Sync[] @relation(\"SyncEntities\", fields: [syncIds], references: [id])\n syncIds String[] @db.ObjectId\n\n dataIdentifiers DataIdentifier[]\n associationObjects AssociationObject[]\n\n @@index([userId])\n @@index([externalId])\n @@index([moduleName])\n @@index([credentialId])\n @@map(\"Entity\")\n}\n\n// ============================================================================\n// INTEGRATION MODELS\n// ============================================================================\n\n/// Main integration configuration and state\nmodel Integration {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n status IntegrationStatus @default(IN_CREATION)\n\n // Configuration and version\n config Json? // Integration configuration object\n version String?\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"IntegrationEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n // Message arrays (stored as JSON)\n errors Json @default(\"[]\")\n warnings Json @default(\"[]\")\n info Json @default(\"[]\")\n logs Json @default(\"[]\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n associations Association[]\n syncs Sync[]\n mappings IntegrationMapping[]\n processes Process[]\n\n @@index([userId])\n @@index([status])\n @@map(\"Integration\")\n}\n\nenum IntegrationStatus {\n ENABLED\n NEEDS_CONFIG\n PROCESSING\n DISABLED\n ERROR\n IN_CREATION\n IN_DELETION\n}\n\n/// Integration-specific data mappings\n/// All mapping data encrypted with KMS\nmodel IntegrationMapping {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n sourceId String?\n\n // Encrypted mapping data (handled via Prisma middleware)\n mapping Json?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, sourceId])\n @@index([integrationId])\n @@index([sourceId])\n @@map(\"IntegrationMapping\")\n}\n\n// ============================================================================\n// PROCESS MODELS\n// ============================================================================\n\n/// Generic Process Model - tracks any long-running operation\n/// Used for: CRM syncs, data migrations, bulk operations, etc.\nmodel Process {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n // Core references\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Process identification\n name String // e.g., \"zoho-crm-contact-sync\", \"pipedrive-lead-sync\"\n type String // e.g., \"CRM_SYNC\", \"DATA_MIGRATION\", \"BULK_OPERATION\"\n\n // State machine\n state String // Current state (integration-defined states)\n\n // Flexible storage\n context Json @default(\"{}\") // Process-specific data (pagination, metadata, etc.)\n results Json @default(\"{}\") // Process results and metrics\n\n // Hierarchy support\n childProcesses String[] @db.ObjectId\n parentProcessId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([userId])\n @@index([integrationId])\n @@index([type])\n @@index([state])\n @@index([name])\n @@map(\"Process\")\n}\n\n// ============================================================================\n// SYNC MODELS\n// ============================================================================\n\n/// Bidirectional data synchronization tracking\nmodel Sync {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String? @db.ObjectId\n integration Integration? @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"SyncEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n hash String\n name String\n\n // Data identifiers (extracted to separate model)\n dataIdentifiers DataIdentifier[]\n\n @@index([integrationId])\n @@index([hash])\n @@index([name])\n @@map(\"Sync\")\n}\n\n/// Data identifier for sync operations\n/// Replaces nested array structure in Mongoose\nmodel DataIdentifier {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n syncId String? @db.ObjectId\n sync Sync? @relation(fields: [syncId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n\n // Identifier data (can be any structure)\n idData Json\n\n hash String\n\n @@index([syncId])\n @@index([entityId])\n @@index([hash])\n @@map(\"DataIdentifier\")\n}\n\n// ============================================================================\n// ASSOCIATION MODELS\n// ============================================================================\n\n/// Entity associations with cardinality tracking\nmodel Association {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n name String\n type AssociationType\n primaryObject String\n\n // Associated objects (extracted to separate model)\n objects AssociationObject[]\n\n @@index([integrationId])\n @@index([name])\n @@map(\"Association\")\n}\n\n/// Association object entry\n/// Replaces nested array structure in Mongoose\nmodel AssociationObject {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n associationId String @db.ObjectId\n association Association @relation(fields: [associationId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n objectType String\n objId String\n metadata Json? // Optional metadata\n\n @@index([associationId])\n @@index([entityId])\n @@map(\"AssociationObject\")\n}\n\nenum AssociationType {\n ONE_TO_MANY\n ONE_TO_ONE\n MANY_TO_ONE\n}\n\n// ============================================================================\n// UTILITY MODELS\n// ============================================================================\n\n/// Generic state storage\nmodel State {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n state Json?\n\n @@map(\"State\")\n}\n\n/// AWS API Gateway WebSocket connection tracking\nmodel WebsocketConnection {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n connectionId String?\n\n @@index([connectionId])\n @@map(\"WebsocketConnection\")\n}\n\n// ============================================================================\n// ADMIN PROCESS MODELS\n// ============================================================================\n\n/// Admin process state machine\nenum AdminScriptExecutionState {\n PENDING\n RUNNING\n COMPLETED\n FAILED\n}\n\n/// Admin process tracking (like Process but without user/integration FK)\n/// Used for: admin scripts, db migrations, system maintenance tasks\nmodel AdminScriptExecution {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n name String // e.g., \"oauth-token-refresh\", \"db-migration-xyz\"\n type String // e.g., \"ADMIN_SCRIPT\", \"DB_MIGRATION\"\n\n // State machine\n state AdminScriptExecutionState @default(PENDING)\n\n // Flexible storage (mirrors Process model pattern)\n context Json @default(\"{}\") // input, trigger, audit info, script version\n results Json @default(\"{}\") // output, logs, metrics, errors\n\n // Hierarchy support\n childExecutions String[] @db.ObjectId\n parentExecutionId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([name, createdAt(sort: Desc)])\n @@index([state])\n @@index([type])\n @@map(\"AdminScriptExecution\")\n}\n\n/// Script scheduling configuration for hybrid scheduling (SQS + EventBridge)\nmodel ScriptSchedule {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n scriptName String @unique\n enabled Boolean @default(false)\n cronExpression String?\n timezone String @default(\"UTC\")\n lastTriggeredAt DateTime?\n nextTriggerAt DateTime?\n\n // External Scheduler (e.g., AWS EventBridge Scheduler)\n externalScheduleId String?\n externalScheduleName String?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([enabled])\n @@map(\"ScriptSchedule\")\n}\n\n/// Durable usage counters, deliberately isolated: no userId and no foreign key\n/// to Integration, so a user-scoped query can never return a usage row and usage\n/// history survives integration deletion.\nmodel UsageCounter {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n integrationId String\n integrationType String\n metric String\n window String // e.g. \"day:2026-07-05\" or \"hour:2026-07-05T14\"\n value BigInt @default(0) // BigInt: a busy day/hour counter can exceed 32-bit\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, integrationType, metric, window])\n // Covers totals() (metric + window prefix/range, no integrationType filter).\n @@index([metric, window])\n // Covers series() (metric + integrationType + window range).\n @@index([metric, integrationType, window])\n @@map(\"UsageCounter\")\n}\n",
|
|
364
|
-
"inlineSchemaHash": "
|
|
367
|
+
"inlineSchema": "// Frigg Framework - Prisma Schema\n// MongoDB database schema for enterprise integration platform\n// Migration from Mongoose ODM to Prisma ORM\n\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"../generated/prisma-mongodb\"\n binaryTargets = [\"native\", \"rhel-openssl-3.0.x\", \"linux-arm64-openssl-3.0.x\"] // native for local dev, rhel for x86_64 Lambda, linux-arm64 for arm64 Lambda\n // Library engine (default since Prisma 3.x): Rust query engine loads as a\n // Node-API addon inside the same process. The binary engine forks a child\n // query-engine subprocess and communicates over a local HTTP/IPC pipe with\n // NO client-side timeout — a zombied child wedges the Node process until\n // Lambda's 900s cap. Switching to library eliminates that entire class of\n // silent hangs. See friggframework/frigg#580 for the investigation.\n engineType = \"library\"\n}\n\ndatasource db {\n provider = \"mongodb\"\n url = env(\"DATABASE_URL\")\n}\n\n// ============================================================================\n// USER MODELS\n// ============================================================================\n\n/// User model with discriminator pattern support\n/// Replaces Mongoose discriminators (IndividualUser, OrganizationUser)\nmodel User {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n type UserType\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // IndividualUser fields (nullable for organizations)\n email String?\n username String?\n hashword String? // Bcrypt hashed password (handled in application layer)\n appUserId String?\n organizationId String? @db.ObjectId\n\n // Self-referential relation for organization membership\n organization User? @relation(\"OrgMembers\", fields: [organizationId], references: [id], onDelete: NoAction, onUpdate: NoAction)\n members User[] @relation(\"OrgMembers\")\n\n // OrganizationUser fields (nullable for individuals)\n appOrgId String?\n name String?\n\n // Relations\n tokens Token[]\n credentials Credential[]\n entities Entity[]\n integrations Integration[]\n processes Process[]\n\n @@unique([username, appUserId])\n @@index([type])\n @@index([appUserId])\n @@index([organizationId])\n @@map(\"User\")\n}\n\nenum UserType {\n INDIVIDUAL\n ORGANIZATION\n}\n\n// ============================================================================\n// AUTHENTICATION MODELS\n// ============================================================================\n\n/// Authentication tokens with expiration\n/// Bcrypt hashed tokens stored (handled in application layer)\nmodel Token {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n token String // Bcrypt hashed\n created DateTime @default(now())\n expires DateTime?\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n\n @@index([userId])\n @@index([expires])\n @@map(\"Token\")\n}\n\n// ============================================================================\n// CREDENTIAL & ENTITY MODELS\n// ============================================================================\n\n/// OAuth credentials and API tokens\n/// All sensitive data encrypted with KMS at rest\nmodel Credential {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n authIsValid Boolean?\n externalId String?\n\n // Dynamic OAuth fields stored as JSON (encrypted via Prisma middleware)\n // Contains: access_token, refresh_token, domain, expires_in, token_type, etc.\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n entities Entity[]\n\n @@index([userId])\n @@index([externalId])\n @@map(\"Credential\")\n}\n\n/// External service entities (API connections)\nmodel Entity {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n credentialId String? @db.ObjectId\n credential Credential? @relation(fields: [credentialId], references: [id], onDelete: SetNull)\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n name String?\n moduleName String?\n externalId String?\n\n data Json @default(\"{}\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations - many-to-many with scalar lists\n integrations Integration[] @relation(\"IntegrationEntities\", fields: [integrationIds], references: [id])\n integrationIds String[] @db.ObjectId\n\n syncs Sync[] @relation(\"SyncEntities\", fields: [syncIds], references: [id])\n syncIds String[] @db.ObjectId\n\n dataIdentifiers DataIdentifier[]\n associationObjects AssociationObject[]\n\n @@index([userId])\n @@index([externalId])\n @@index([moduleName])\n @@index([credentialId])\n @@map(\"Entity\")\n}\n\n// ============================================================================\n// INTEGRATION MODELS\n// ============================================================================\n\n/// Main integration configuration and state\nmodel Integration {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n userId String? @db.ObjectId\n user User? @relation(fields: [userId], references: [id], onDelete: Cascade)\n status IntegrationStatus @default(IN_CREATION)\n\n // Configuration and version\n config Json? // Integration configuration object\n version String?\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"IntegrationEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n // Message arrays (stored as JSON)\n errors Json @default(\"[]\")\n warnings Json @default(\"[]\")\n info Json @default(\"[]\")\n logs Json @default(\"[]\")\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n // Relations\n associations Association[]\n syncs Sync[]\n mappings IntegrationMapping[]\n processes Process[]\n\n @@index([userId])\n @@index([status])\n @@map(\"Integration\")\n}\n\nenum IntegrationStatus {\n ENABLED\n NEEDS_CONFIG\n PROCESSING\n DISABLED\n ERROR\n IN_CREATION\n IN_DELETION\n}\n\n/// Integration-specific data mappings\n/// All mapping data encrypted with KMS\nmodel IntegrationMapping {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n sourceId String?\n\n // Encrypted mapping data (handled via Prisma middleware)\n mapping Json?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, sourceId])\n @@index([integrationId])\n @@index([sourceId])\n @@map(\"IntegrationMapping\")\n}\n\n// ============================================================================\n// PROCESS MODELS\n// ============================================================================\n\n/// Generic Process Model - tracks any long-running operation\n/// Used for: CRM syncs, data migrations, bulk operations, etc.\nmodel Process {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n // Core references\n userId String @db.ObjectId\n user User @relation(fields: [userId], references: [id], onDelete: Cascade)\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Process identification\n name String // e.g., \"zoho-crm-contact-sync\", \"pipedrive-lead-sync\"\n type String // e.g., \"CRM_SYNC\", \"DATA_MIGRATION\", \"BULK_OPERATION\"\n\n // State machine\n state String // Current state (integration-defined states)\n\n // Flexible storage\n context Json @default(\"{}\") // Process-specific data (pagination, metadata, etc.)\n results Json @default(\"{}\") // Process results and metrics\n\n // Hierarchy support\n childProcesses String[] @db.ObjectId\n parentProcessId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([userId])\n @@index([integrationId])\n @@index([type])\n @@index([state])\n @@index([name])\n @@map(\"Process\")\n}\n\n// ============================================================================\n// SYNC MODELS\n// ============================================================================\n\n/// Bidirectional data synchronization tracking\nmodel Sync {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String? @db.ObjectId\n integration Integration? @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n\n // Entity references (many-to-many via explicit scalar list)\n entities Entity[] @relation(\"SyncEntities\", fields: [entityIds], references: [id])\n entityIds String[] @db.ObjectId\n\n hash String\n name String\n\n // Data identifiers (extracted to separate model)\n dataIdentifiers DataIdentifier[]\n\n @@index([integrationId])\n @@index([hash])\n @@index([name])\n @@map(\"Sync\")\n}\n\n/// Data identifier for sync operations\n/// Replaces nested array structure in Mongoose\nmodel DataIdentifier {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n syncId String? @db.ObjectId\n sync Sync? @relation(fields: [syncId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n\n // Identifier data (can be any structure)\n idData Json\n\n hash String\n\n @@index([syncId])\n @@index([entityId])\n @@index([hash])\n @@map(\"DataIdentifier\")\n}\n\n// ============================================================================\n// ASSOCIATION MODELS\n// ============================================================================\n\n/// Entity associations with cardinality tracking\nmodel Association {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n integrationId String @db.ObjectId\n integration Integration @relation(fields: [integrationId], references: [id], onDelete: Cascade)\n name String\n type AssociationType\n primaryObject String\n\n // Associated objects (extracted to separate model)\n objects AssociationObject[]\n\n @@index([integrationId])\n @@index([name])\n @@map(\"Association\")\n}\n\n/// Association object entry\n/// Replaces nested array structure in Mongoose\nmodel AssociationObject {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n associationId String @db.ObjectId\n association Association @relation(fields: [associationId], references: [id], onDelete: Cascade)\n entityId String @db.ObjectId\n entity Entity @relation(fields: [entityId], references: [id], onDelete: Cascade)\n objectType String\n objId String\n metadata Json? // Optional metadata\n\n @@index([associationId])\n @@index([entityId])\n @@map(\"AssociationObject\")\n}\n\nenum AssociationType {\n ONE_TO_MANY\n ONE_TO_ONE\n MANY_TO_ONE\n}\n\n// ============================================================================\n// UTILITY MODELS\n// ============================================================================\n\n/// Generic state storage\nmodel State {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n state Json?\n\n @@map(\"State\")\n}\n\n/// AWS API Gateway WebSocket connection tracking\nmodel WebsocketConnection {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n connectionId String?\n\n @@index([connectionId])\n @@map(\"WebsocketConnection\")\n}\n\n// ============================================================================\n// ADMIN PROCESS MODELS\n// ============================================================================\n\n/// Admin process state machine\nenum AdminScriptExecutionState {\n PENDING\n RUNNING\n COMPLETED\n FAILED\n}\n\n/// Admin process tracking (like Process but without user/integration FK)\n/// Used for: admin scripts, db migrations, system maintenance tasks\nmodel AdminScriptExecution {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n name String // e.g., \"oauth-token-refresh\", \"db-migration-xyz\"\n type String // e.g., \"ADMIN_SCRIPT\", \"DB_MIGRATION\"\n\n // State machine\n state AdminScriptExecutionState @default(PENDING)\n\n // Flexible storage (mirrors Process model pattern)\n context Json @default(\"{}\") // input, trigger, audit info, script version\n results Json @default(\"{}\") // output, logs, metrics, errors\n\n // Hierarchy support\n childExecutions String[] @db.ObjectId\n parentExecutionId String? @db.ObjectId\n\n // Timestamps\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([name, createdAt(sort: Desc)])\n @@index([state])\n @@index([type])\n @@map(\"AdminScriptExecution\")\n}\n\n/// Script scheduling configuration for hybrid scheduling (SQS + EventBridge)\nmodel ScriptSchedule {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n scriptName String @unique\n enabled Boolean @default(false)\n cronExpression String?\n timezone String @default(\"UTC\")\n lastTriggeredAt DateTime?\n nextTriggerAt DateTime?\n\n // External Scheduler (e.g., AWS EventBridge Scheduler)\n externalScheduleId String?\n externalScheduleName String?\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@index([enabled])\n @@map(\"ScriptSchedule\")\n}\n\n/// Durable usage counters, deliberately isolated: no userId and no foreign key\n/// to Integration, so a user-scoped query can never return a usage row and usage\n/// history survives integration deletion.\nmodel UsageCounter {\n id String @id @default(auto()) @map(\"_id\") @db.ObjectId\n\n integrationId String\n integrationType String\n metric String\n window String // e.g. \"day:2026-07-05\" or \"hour:2026-07-05T14\"\n value BigInt @default(0) // BigInt: a busy day/hour counter can exceed 32-bit\n\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([integrationId, integrationType, metric, window])\n // Covers totals() (metric + window prefix/range, no integrationType filter).\n @@index([metric, window])\n // Covers series() (metric + integrationType + window range).\n @@index([metric, integrationType, window])\n @@map(\"UsageCounter\")\n}\n",
|
|
368
|
+
"inlineSchemaHash": "8ea47fb22642cea1c5ae56f5c08b37672beac94aa6763081f0412d7b30179804",
|
|
365
369
|
"copyEngine": true
|
|
366
370
|
}
|
|
367
371
|
|
|
@@ -406,6 +410,10 @@ path.join(process.cwd(), "generated/prisma-mongodb/libquery_engine-debian-openss
|
|
|
406
410
|
// file annotations for bundling tools to include these files
|
|
407
411
|
path.join(__dirname, "libquery_engine-rhel-openssl-3.0.x.so.node");
|
|
408
412
|
path.join(process.cwd(), "generated/prisma-mongodb/libquery_engine-rhel-openssl-3.0.x.so.node")
|
|
413
|
+
|
|
414
|
+
// file annotations for bundling tools to include these files
|
|
415
|
+
path.join(__dirname, "libquery_engine-linux-arm64-openssl-3.0.x.so.node");
|
|
416
|
+
path.join(process.cwd(), "generated/prisma-mongodb/libquery_engine-linux-arm64-openssl-3.0.x.so.node")
|
|
409
417
|
// file annotations for bundling tools to include these files
|
|
410
418
|
path.join(__dirname, "schema.prisma");
|
|
411
419
|
path.join(process.cwd(), "generated/prisma-mongodb/schema.prisma")
|
|
Binary file
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
generator client {
|
|
6
6
|
provider = "prisma-client-js"
|
|
7
7
|
output = "../generated/prisma-mongodb"
|
|
8
|
-
binaryTargets = ["native", "rhel-openssl-3.0.x"] // native for local dev, rhel for Lambda
|
|
8
|
+
binaryTargets = ["native", "rhel-openssl-3.0.x", "linux-arm64-openssl-3.0.x"] // native for local dev, rhel for x86_64 Lambda, linux-arm64 for arm64 Lambda
|
|
9
9
|
// Library engine (default since Prisma 3.x): Rust query engine loads as a
|
|
10
10
|
// Node-API addon inside the same process. The binary engine forks a child
|
|
11
11
|
// query-engine subprocess and communicates over a local HTTP/IPC pipe with
|