@trycompai/db 2.1.2 → 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.
package/dist/client.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  import { PrismaClient } from '@prisma/client';
2
+ export type { SslConfig } from './ssl-config';
3
+ export { resolveSslConfig } from './ssl-config';
2
4
  export declare const db: PrismaClient<import("@prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/client").DefaultArgs>;
3
5
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA6B9C,eAAO,MAAM,EAAE,+HAAiD,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,YAAY,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgChD,eAAO,MAAM,EAAE,+HAMb,CAAC"}
package/dist/client.js CHANGED
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.db = void 0;
3
+ exports.db = exports.resolveSslConfig = void 0;
4
4
  const client_1 = require("@prisma/client");
5
5
  const adapter_pg_1 = require("@prisma/adapter-pg");
6
+ const ssl_config_1 = require("./ssl-config");
7
+ var ssl_config_2 = require("./ssl-config");
8
+ Object.defineProperty(exports, "resolveSslConfig", { enumerable: true, get: function () { return ssl_config_2.resolveSslConfig; } });
6
9
  const globalForPrisma = global;
7
10
  function stripSslMode(connectionString) {
8
11
  const url = new URL(connectionString);
@@ -11,21 +14,28 @@ function stripSslMode(connectionString) {
11
14
  }
12
15
  function createPrismaClient() {
13
16
  const rawUrl = process.env.DATABASE_URL;
14
- const isLocalhost = /localhost|127\.0\.0\.1|::1/.test(rawUrl);
15
- // Use verified SSL when NODE_EXTRA_CA_CERTS is set (Docker with RDS CA bundle),
16
- // otherwise fall back to unverified SSL (Trigger.dev, Vercel, other environments).
17
- const hasCABundle = !!process.env.NODE_EXTRA_CA_CERTS;
18
- const ssl = isLocalhost ? undefined : hasCABundle ? true : { rejectUnauthorized: false };
19
- // Strip sslmode from the connection string to avoid conflicts with the explicit ssl option
17
+ const ssl = (0, ssl_config_1.resolveSslConfig)(rawUrl);
20
18
  const url = ssl !== undefined ? stripSslMode(rawUrl) : rawUrl;
21
19
  const adapter = new adapter_pg_1.PrismaPg({ connectionString: url, ssl });
22
20
  return new client_1.PrismaClient({
23
21
  adapter,
24
- transactionOptions: {
25
- timeout: 60000,
26
- },
22
+ transactionOptions: { timeout: 60000 },
27
23
  });
28
24
  }
29
- exports.db = globalForPrisma.prisma || createPrismaClient();
30
- if (process.env.NODE_ENV !== 'production')
31
- globalForPrisma.prisma = exports.db;
25
+ // Lazy initialization. Importing this module does NOT construct a Prisma client
26
+ // that only happens on first property access on `db`. Critical so that
27
+ // Next.js `next build` (which imports every route handler to analyze it) does
28
+ // not trigger the strict TLS check at build time when no actual queries run.
29
+ function getClient() {
30
+ if (!globalForPrisma.prisma) {
31
+ globalForPrisma.prisma = createPrismaClient();
32
+ }
33
+ return globalForPrisma.prisma;
34
+ }
35
+ exports.db = new Proxy({}, {
36
+ get(_target, prop, _receiver) {
37
+ const client = getClient();
38
+ const value = Reflect.get(client, prop, client);
39
+ return typeof value === 'function' ? value.bind(client) : value;
40
+ },
41
+ });
@@ -2284,7 +2284,28 @@ model Risk {
2284
2284
  residualLikelihood Likelihood @default(very_unlikely)
2285
2285
  residualImpact Impact @default(insignificant)
2286
2286
  treatmentStrategyDescription String?
2287
- treatmentStrategy RiskTreatmentType @default(accept)
2287
+ // Mitigate is the workhorse — the AI mitigation generator writes a
2288
+ // mitigation plan for every new risk, and the plan is stored under
2289
+ // the active strategy. Defaulting to anything other than mitigate
2290
+ // would put the AI plan under the wrong slot.
2291
+ treatmentStrategy RiskTreatmentType @default(mitigate)
2292
+ // Per-strategy text store. When the user switches strategies, the current
2293
+ // `treatmentStrategyDescription` is moved into this map under the OLD
2294
+ // strategy key, and the NEW strategy's saved value is loaded back into the
2295
+ // active field. Lets users keep an independent Mitigate plan + Accept
2296
+ // rationale + Transfer rationale on the same risk.
2297
+ // Shape: { mitigate?: string, accept?: string, transfer?: string, avoid?: string }
2298
+ strategyDescriptions Json?
2299
+
2300
+ // Active auto-link suggestion run (trigger.dev). Set when the user kicks
2301
+ // off an AI suggest scan; cleared when the user applies or discards. Lets
2302
+ // the UI resume an in-flight or completed-but-unreviewed scan after a
2303
+ // page reload so progress isn't lost.
2304
+ autoLinkRunId String?
2305
+ autoLinkRunStartedAt DateTime?
2306
+
2307
+ // See Task.embeddingHash — skip-if-unchanged guard for re-embedding.
2308
+ embeddingHash String?
2288
2309
 
2289
2310
  // Dates
2290
2311
  createdAt DateTime @default(now())
@@ -2780,6 +2801,12 @@ model Task {
2780
2801
  // Sync-driven archive — see Control.archivedAt.
2781
2802
  archivedAt DateTime?
2782
2803
 
2804
+ // Skip-if-unchanged guard for the auto-linkage embedding pipeline. Holds
2805
+ // a hash of (text + model + dims + department) — when re-running linkage
2806
+ // we skip OpenAI embed + Upstash upsert for any task whose hash matches.
2807
+ // Null means "never embedded" so the next linkage run will embed.
2808
+ embeddingHash String?
2809
+
2783
2810
  @@index([organizationId, archivedAt])
2784
2811
  }
2785
2812
 
@@ -2956,8 +2983,6 @@ model Trust {
2956
2983
  hipaa Boolean @default(false)
2957
2984
  pci_dss Boolean @default(false)
2958
2985
  iso9001 Boolean @default(false)
2959
- pipeda Boolean @default(false)
2960
- ccpa Boolean @default(false)
2961
2986
 
2962
2987
  soc2_status FrameworkStatus @default(started)
2963
2988
  soc2type1_status FrameworkStatus @default(started)
@@ -2970,8 +2995,6 @@ model Trust {
2970
2995
  hipaa_status FrameworkStatus @default(started)
2971
2996
  pci_dss_status FrameworkStatus @default(started)
2972
2997
  iso9001_status FrameworkStatus @default(started)
2973
- pipeda_status FrameworkStatus @default(started)
2974
- ccpa_status FrameworkStatus @default(started)
2975
2998
 
2976
2999
  // Overview section for public trust portal
2977
3000
  overviewTitle String?
@@ -3199,6 +3222,12 @@ model Vendor {
3199
3222
  inherentImpact Impact @default(insignificant)
3200
3223
  residualProbability Likelihood @default(very_unlikely)
3201
3224
  residualImpact Impact @default(insignificant)
3225
+ // See Risk.treatmentStrategy — default mitigate so AI plans land in
3226
+ // the right slot.
3227
+ treatmentStrategy RiskTreatmentType @default(mitigate)
3228
+ treatmentStrategyDescription String?
3229
+ // See `Risk.strategyDescriptions`.
3230
+ strategyDescriptions Json?
3202
3231
  website String?
3203
3232
  isSubProcessor Boolean @default(false)
3204
3233
 
@@ -3208,6 +3237,14 @@ model Vendor {
3208
3237
  trustPortalOrder Int?
3209
3238
  complianceBadges Json? // Array of { type: 'soc2' | 'iso27001' | etc, verified: boolean }
3210
3239
 
3240
+ // Active auto-link suggestion run (trigger.dev). Same semantics as
3241
+ // Risk.autoLinkRunId — lets the UI resume an in-flight scan on reload.
3242
+ autoLinkRunId String?
3243
+ autoLinkRunStartedAt DateTime?
3244
+
3245
+ // See Task.embeddingHash — skip-if-unchanged guard for re-embedding.
3246
+ embeddingHash String?
3247
+
3211
3248
  createdAt DateTime @default(now())
3212
3249
  updatedAt DateTime @updatedAt
3213
3250
 
@@ -0,0 +1,7 @@
1
+ export type SslConfig = undefined | {
2
+ checkServerIdentity: () => undefined;
3
+ } | {
4
+ rejectUnauthorized: false;
5
+ };
6
+ export declare function resolveSslConfig(databaseUrl: string, env?: Partial<NodeJS.ProcessEnv>): SslConfig;
7
+ //# sourceMappingURL=ssl-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssl-config.d.ts","sourceRoot":"","sources":["../src/ssl-config.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,SAAS,GACT;IAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;CAAE,GACxC;IAAE,kBAAkB,EAAE,KAAK,CAAA;CAAE,CAAC;AAgBlC,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,GAAG,GAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAe,GAC5C,SAAS,CAeX"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSslConfig = resolveSslConfig;
4
+ const LOCAL_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1']);
5
+ function isLocalhostUrl(connectionString) {
6
+ try {
7
+ const { hostname } = new URL(connectionString);
8
+ const stripped = hostname.replace(/^\[/, '').replace(/\]$/, '');
9
+ return LOCAL_HOSTNAMES.has(stripped);
10
+ }
11
+ catch {
12
+ // Malformed URL — be conservative and treat as remote so we don't
13
+ // accidentally disable TLS verification.
14
+ return false;
15
+ }
16
+ }
17
+ function resolveSslConfig(databaseUrl, env = process.env) {
18
+ const isLocalhost = isLocalhostUrl(databaseUrl);
19
+ const hasCABundle = !!env.NODE_EXTRA_CA_CERTS;
20
+ const allowInsecure = env.PRISMA_ALLOW_INSECURE_TLS === '1';
21
+ if (isLocalhost)
22
+ return undefined;
23
+ // Verified TLS: rely on Node's TLS context (NODE_EXTRA_CA_CERTS adds the AWS
24
+ // RDS CA to the trust store). Skip hostname check because connections may
25
+ // traverse an AWS NLB whose hostname isn't in the RDS Proxy cert's SAN list.
26
+ // The chain check still rejects forged or wrong-CA certs.
27
+ if (hasCABundle)
28
+ return { checkServerIdentity: () => undefined };
29
+ if (allowInsecure)
30
+ return { rejectUnauthorized: false };
31
+ throw new Error('Refusing to connect to a non-local Postgres without TLS verification. Set NODE_EXTRA_CA_CERTS to a CA bundle, or set PRISMA_ALLOW_INSECURE_TLS=1 if you intentionally want unverified TLS.');
32
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trycompai/db",
3
3
  "description": "Database package with Prisma client and schema for Comp AI",
4
- "version": "2.1.2",
4
+ "version": "2.1.3",
5
5
  "dependencies": {
6
6
  "@prisma/adapter-pg": "7.6.0",
7
7
  "@prisma/client": "7.6.0",
@@ -21,9 +21,14 @@
21
21
  "default": "./dist/index.js"
22
22
  },
23
23
  "./postinstall": {
24
- "import": "./dist/postinstall.js",
25
24
  "types": "./src/postinstall.ts",
25
+ "import": "./dist/postinstall.js",
26
26
  "default": "./dist/postinstall.js"
27
+ },
28
+ "./ssl-config": {
29
+ "types": "./dist/ssl-config.d.ts",
30
+ "import": "./dist/ssl-config.js",
31
+ "default": "./dist/ssl-config.js"
27
32
  }
28
33
  },
29
34
  "bin": {
@@ -31,6 +36,7 @@
31
36
  },
32
37
  "files": [
33
38
  "dist",
39
+ "certs",
34
40
  "README.md",
35
41
  "INTEGRATION_GUIDE.md"
36
42
  ],