@quatronic/sdk 0.8.0-rc.12 → 0.8.0-rc.14

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 (77) hide show
  1. package/dist/{chunk-2AYDFLKR.js → chunk-F3NHTHFO.js} +6 -104
  2. package/dist/chunk-F3NHTHFO.js.map +1 -0
  3. package/dist/chunk-P7HNHLW7.js +65 -0
  4. package/dist/chunk-P7HNHLW7.js.map +1 -0
  5. package/dist/chunk-QMOZDE3U.js +158 -0
  6. package/dist/chunk-QMOZDE3U.js.map +1 -0
  7. package/dist/chunk-TOBGX4CZ.js +109 -0
  8. package/dist/chunk-TOBGX4CZ.js.map +1 -0
  9. package/dist/chunk-WU7N4PET.js +20 -0
  10. package/dist/chunk-WU7N4PET.js.map +1 -0
  11. package/dist/cli/legacy/qdc-sourcemaps.js +16 -6
  12. package/dist/cli/sourcemaps.js +16 -6
  13. package/dist/integrations/index.d.ts +3 -75
  14. package/dist/integrations/index.js +6 -4
  15. package/dist/mail/index.d.ts +9 -0
  16. package/dist/mail/index.js +26 -0
  17. package/dist/mail/index.js.map +1 -0
  18. package/dist/next/auth/index.js +3 -152
  19. package/dist/next/auth/index.js.map +1 -1
  20. package/dist/next/boot/index.d.ts +33 -0
  21. package/dist/next/boot/index.js +21 -0
  22. package/dist/next/boot/index.js.map +1 -0
  23. package/dist/next/db/index.d.ts +18 -1
  24. package/dist/next/db/index.js +25 -0
  25. package/dist/next/db/index.js.map +1 -1
  26. package/dist/next/global-error/index.d.ts +9 -0
  27. package/dist/next/global-error/index.js +17 -0
  28. package/dist/next/global-error/index.js.map +1 -0
  29. package/dist/next/integrations/index.d.ts +2 -1
  30. package/dist/next/integrations/index.js +6 -4
  31. package/dist/next/platform/index.d.ts +19 -0
  32. package/dist/next/platform/index.js +44 -0
  33. package/dist/next/platform/index.js.map +1 -0
  34. package/dist/next/security/index.d.ts +23 -1
  35. package/dist/next/security/index.js +39 -56
  36. package/dist/next/security/index.js.map +1 -1
  37. package/dist/next/security/testing.js +10 -1
  38. package/dist/next/security/testing.js.map +1 -1
  39. package/dist/next/sentry/register.js +5 -13
  40. package/dist/next/sentry/register.js.map +1 -1
  41. package/dist/node/boot/index.d.ts +9 -0
  42. package/dist/node/boot/index.js +13 -0
  43. package/dist/node/boot/index.js.map +1 -0
  44. package/dist/node/integrations/index.d.ts +2 -1
  45. package/dist/node/integrations/index.js +6 -4
  46. package/dist/node-Z7ERWJDZ.js +46 -0
  47. package/dist/node-Z7ERWJDZ.js.map +1 -0
  48. package/dist/types-CAwj03sM.d.ts +75 -0
  49. package/migrations/bootstrap-qore-env/codemod.mjs +77 -0
  50. package/migrations/bootstrap-qore-env/instructions.md +28 -0
  51. package/migrations/bootstrap-qore-env/meta.json +7 -0
  52. package/migrations/global-error/codemod.mjs +28 -0
  53. package/migrations/global-error/instructions.md +26 -0
  54. package/migrations/global-error/meta.json +7 -0
  55. package/migrations/local-db-port/codemod.mjs +61 -0
  56. package/migrations/local-db-port/instructions.md +45 -0
  57. package/migrations/local-db-port/meta.json +7 -0
  58. package/migrations/mail-reexport/codemod.mjs +64 -0
  59. package/migrations/mail-reexport/instructions.md +27 -0
  60. package/migrations/mail-reexport/meta.json +7 -0
  61. package/migrations/no-raw-fetch/meta.json +1 -1
  62. package/migrations/platform-routes/codemod.mjs +45 -0
  63. package/migrations/platform-routes/instructions.md +30 -0
  64. package/migrations/platform-routes/meta.json +7 -0
  65. package/migrations/qore-boot/codemod.mjs +263 -0
  66. package/migrations/qore-boot/instructions.md +74 -0
  67. package/migrations/qore-boot/meta.json +7 -0
  68. package/migrations/qore-proxy/codemod.mjs +88 -0
  69. package/migrations/qore-proxy/instructions.md +56 -0
  70. package/migrations/qore-proxy/meta.json +7 -0
  71. package/migrations/run.mjs +334 -0
  72. package/migrations/sourcemaps-finalize/codemod.mjs +63 -0
  73. package/migrations/sourcemaps-finalize/instructions.md +56 -0
  74. package/migrations/sourcemaps-finalize/meta.json +7 -0
  75. package/package.json +23 -2
  76. package/workspace-requirements.json +4 -0
  77. package/dist/chunk-2AYDFLKR.js.map +0 -1
@@ -23,13 +23,14 @@ var BUNDLE = /^[a-z0-9][a-z0-9-]{0,31}$/;
23
23
  var SCRIPT = /\.(js|mjs|cjs)$/;
24
24
  var MAPPING_URL = /^\/\/# sourceMappingURL=(\S+)[ \t]*$/gm;
25
25
  var STANDALONE_SERVER = "standalone/.next/server/";
26
+ var isCommand = (cmd) => cmd === "upload" || cmd === "finalize";
26
27
  function parseArgs(argv) {
27
28
  const [cmd, dir, ...rest] = argv;
28
- if (cmd !== "upload" || !dir) return { error: "usage: qore-sourcemaps upload <dir> [--bundle <name>]" };
29
+ if (!isCommand(cmd) || !dir) return { error: "usage: qore-sourcemaps upload|finalize <dir> [--bundle <name>]" };
29
30
  let bundle = "app";
30
31
  if (rest[0] === "--bundle") bundle = rest[1] ?? "";
31
32
  if (!BUNDLE.test(bundle)) return { error: `invalid bundle name: ${bundle}` };
32
- return { dir, bundle };
33
+ return { cmd, dir, bundle };
33
34
  }
34
35
  function nextRoots(has) {
35
36
  if (!has("BUILD_ID") || !has("server")) return null;
@@ -122,11 +123,11 @@ async function runCommand(cmd, args) {
122
123
  env: { ...process.env, COPYFILE_DISABLE: "1" }
123
124
  });
124
125
  }
125
- function walkDir(dir, prefix = "") {
126
+ function walkDir(dir, prefix = "", modules = false) {
126
127
  const out = [];
127
128
  for (const d of readdirSync(join(dir, prefix), { withFileTypes: true })) {
128
129
  const rel = prefix ? `${prefix}/${d.name}` : d.name;
129
- if (d.isDirectory() && d.name !== "node_modules") out.push(...walkDir(dir, rel));
130
+ if (d.isDirectory() && (modules || d.name !== "node_modules")) out.push(...walkDir(dir, rel, modules));
130
131
  else if (d.isFile()) out.push(rel);
131
132
  }
132
133
  return out;
@@ -134,6 +135,7 @@ function walkDir(dir, prefix = "") {
134
135
  var defaultIo = () => ({
135
136
  env: process.env,
136
137
  walk: (dir) => walkDir(dir),
138
+ walkAll: (dir) => walkDir(dir, "", true),
137
139
  exists: existsSync,
138
140
  readText: (p) => readFileSync(p, "utf8"),
139
141
  writeText: (p, t) => writeFileSync(p, t),
@@ -154,11 +156,18 @@ function tryRemove(io, path) {
154
156
  } catch {
155
157
  }
156
158
  }
159
+ function removeAllMaps(io, dir) {
160
+ try {
161
+ for (const p of io.walkAll(dir)) if (p.endsWith(".map")) tryRemove(io, join(dir, p));
162
+ } catch (err) {
163
+ console.warn(`qore-sourcemaps: cleanup skipped: ${describe(err, io.env.QORE_BUILD_UPLOAD_TOKEN)}`);
164
+ }
165
+ }
157
166
  async function main(argv = process.argv.slice(2), io = defaultIo()) {
158
167
  const args = parseArgs(argv);
159
168
  if ("error" in args) {
160
169
  console.warn(`qore-sourcemaps: ${args.error}`);
161
- const dir2 = argv[0] === "upload" ? argv[1] : void 0;
170
+ const dir2 = isCommand(argv[0]) ? argv[1] : void 0;
162
171
  if (dir2 && !dir2.startsWith("-")) {
163
172
  try {
164
173
  for (const m of listMaps(io.walk(dir2))) tryRemove(io, join(dir2, m));
@@ -168,7 +177,7 @@ async function main(argv = process.argv.slice(2), io = defaultIo()) {
168
177
  }
169
178
  return;
170
179
  }
171
- const { dir, bundle } = args;
180
+ const { cmd, dir, bundle } = args;
172
181
  const at = (rel) => join(dir, rel);
173
182
  let maps = [];
174
183
  const scratch = [];
@@ -222,6 +231,7 @@ async function main(argv = process.argv.slice(2), io = defaultIo()) {
222
231
  } finally {
223
232
  for (const m of maps) tryRemove(io, at(m));
224
233
  for (const s of scratch) tryRemove(io, s);
234
+ if (cmd === "finalize") removeAllMaps(io, dir);
225
235
  }
226
236
  }
227
237
  function isMainModule() {
@@ -15,13 +15,14 @@ var BUNDLE = /^[a-z0-9][a-z0-9-]{0,31}$/;
15
15
  var SCRIPT = /\.(js|mjs|cjs)$/;
16
16
  var MAPPING_URL = /^\/\/# sourceMappingURL=(\S+)[ \t]*$/gm;
17
17
  var STANDALONE_SERVER = "standalone/.next/server/";
18
+ var isCommand = (cmd) => cmd === "upload" || cmd === "finalize";
18
19
  function parseArgs(argv) {
19
20
  const [cmd, dir, ...rest] = argv;
20
- if (cmd !== "upload" || !dir) return { error: "usage: qore-sourcemaps upload <dir> [--bundle <name>]" };
21
+ if (!isCommand(cmd) || !dir) return { error: "usage: qore-sourcemaps upload|finalize <dir> [--bundle <name>]" };
21
22
  let bundle = "app";
22
23
  if (rest[0] === "--bundle") bundle = rest[1] ?? "";
23
24
  if (!BUNDLE.test(bundle)) return { error: `invalid bundle name: ${bundle}` };
24
- return { dir, bundle };
25
+ return { cmd, dir, bundle };
25
26
  }
26
27
  function nextRoots(has) {
27
28
  if (!has("BUILD_ID") || !has("server")) return null;
@@ -114,11 +115,11 @@ async function runCommand(cmd, args) {
114
115
  env: { ...process.env, COPYFILE_DISABLE: "1" }
115
116
  });
116
117
  }
117
- function walkDir(dir, prefix = "") {
118
+ function walkDir(dir, prefix = "", modules = false) {
118
119
  const out = [];
119
120
  for (const d of readdirSync(join(dir, prefix), { withFileTypes: true })) {
120
121
  const rel = prefix ? `${prefix}/${d.name}` : d.name;
121
- if (d.isDirectory() && d.name !== "node_modules") out.push(...walkDir(dir, rel));
122
+ if (d.isDirectory() && (modules || d.name !== "node_modules")) out.push(...walkDir(dir, rel, modules));
122
123
  else if (d.isFile()) out.push(rel);
123
124
  }
124
125
  return out;
@@ -126,6 +127,7 @@ function walkDir(dir, prefix = "") {
126
127
  var defaultIo = () => ({
127
128
  env: process.env,
128
129
  walk: (dir) => walkDir(dir),
130
+ walkAll: (dir) => walkDir(dir, "", true),
129
131
  exists: existsSync,
130
132
  readText: (p) => readFileSync(p, "utf8"),
131
133
  writeText: (p, t) => writeFileSync(p, t),
@@ -146,11 +148,18 @@ function tryRemove(io, path) {
146
148
  } catch {
147
149
  }
148
150
  }
151
+ function removeAllMaps(io, dir) {
152
+ try {
153
+ for (const p of io.walkAll(dir)) if (p.endsWith(".map")) tryRemove(io, join(dir, p));
154
+ } catch (err) {
155
+ console.warn(`qore-sourcemaps: cleanup skipped: ${describe(err, io.env.QORE_BUILD_UPLOAD_TOKEN)}`);
156
+ }
157
+ }
149
158
  async function main(argv = process.argv.slice(2), io = defaultIo()) {
150
159
  const args = parseArgs(argv);
151
160
  if ("error" in args) {
152
161
  console.warn(`qore-sourcemaps: ${args.error}`);
153
- const dir2 = argv[0] === "upload" ? argv[1] : void 0;
162
+ const dir2 = isCommand(argv[0]) ? argv[1] : void 0;
154
163
  if (dir2 && !dir2.startsWith("-")) {
155
164
  try {
156
165
  for (const m of listMaps(io.walk(dir2))) tryRemove(io, join(dir2, m));
@@ -160,7 +169,7 @@ async function main(argv = process.argv.slice(2), io = defaultIo()) {
160
169
  }
161
170
  return;
162
171
  }
163
- const { dir, bundle } = args;
172
+ const { cmd, dir, bundle } = args;
164
173
  const at = (rel) => join(dir, rel);
165
174
  let maps = [];
166
175
  const scratch = [];
@@ -214,6 +223,7 @@ async function main(argv = process.argv.slice(2), io = defaultIo()) {
214
223
  } finally {
215
224
  for (const m of maps) tryRemove(io, at(m));
216
225
  for (const s of scratch) tryRemove(io, s);
226
+ if (cmd === "finalize") removeAllMaps(io, dir);
217
227
  }
218
228
  }
219
229
  function isMainModule() {
@@ -1,79 +1,7 @@
1
+ import { I as IntegrationMap, a as IntegrationDefinition, E as EnvRef } from '../types-CAwj03sM.js';
2
+ export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, e as IntegrationAuth, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../types-CAwj03sM.js';
1
3
  import { E as Env } from '../env-R-bci5RU.js';
2
4
 
3
- /**
4
- * How an integration authenticates. Every field except `header` and
5
- * `credentialsIn` names an **env key** — the SDK reads the value from the
6
- * environment at call time, never from the declaration — so a declaration can
7
- * sit in source control and carry no secret.
8
- */
9
- type AuthKind = "none" | "api_key_header" | "bearer_static" | "basic" | "oauth2_client_credentials";
10
- /** What the API speaks. Informational for the portal; the client sends bytes either way. */
11
- type Protocol = "rest" | "odata" | "soap" | "graphql";
12
- /** The name of an env var, e.g. `SAP_BASE_URL`. */
13
- type EnvKey = string;
14
- /**
15
- * A reference to an env var. The short form is required; the object form can
16
- * be optional and carry a default the app falls back on when the key is unset.
17
- */
18
- type EnvRef = EnvKey | {
19
- key: EnvKey;
20
- optional?: boolean;
21
- default?: string | number | boolean;
22
- };
23
- type IntegrationAuth = {
24
- kind: "none";
25
- } | {
26
- kind: "api_key_header";
27
- header: string;
28
- apiKey: EnvKey;
29
- } | {
30
- kind: "bearer_static";
31
- token: EnvKey;
32
- } | {
33
- kind: "basic";
34
- username: EnvKey;
35
- password: EnvKey;
36
- } | {
37
- kind: "oauth2_client_credentials";
38
- tokenUrl: EnvKey;
39
- clientId: EnvKey;
40
- clientSecret: EnvKey;
41
- scope?: EnvKey;
42
- audience?: EnvKey;
43
- /** Where the client credentials go on the token request. Default `"header"`. */
44
- credentialsIn?: "header" | "body";
45
- };
46
- interface IntegrationDefinition {
47
- /** Human name shown in the portal, e.g. "SAP S/4HANA Cloud". */
48
- label: string;
49
- protocol: Protocol;
50
- /** Env key holding the base URL for this environment. */
51
- baseUrl: EnvKey;
52
- auth: IntegrationAuth;
53
- /** Further env the app reads for this integration, by logical name. */
54
- config?: Record<string, EnvRef>;
55
- }
56
- type IntegrationMap = Record<string, IntegrationDefinition>;
57
- /**
58
- * Identity function that pins the literal types of the map, so an alias typo
59
- * at a call site is a compile error (`keyof M`) rather than a runtime
60
- * `not_declared`. Same shape as `definePermissions` in `auth-core`.
61
- */
62
- declare function defineIntegrations<const M extends IntegrationMap>(map: M): M;
63
- /**
64
- * Which fields of each auth kind name an env key. Shared with the manifest
65
- * extractor and the portal, which derive the required-env list from a
66
- * declaration without evaluating app code.
67
- */
68
- declare const AUTH_ENV_FIELDS: Record<AuthKind, readonly string[]>;
69
- /** Auth fields whose env value is a secret, so the portal masks it. */
70
- declare const AUTH_SECRET_FIELDS: readonly ["apiKey", "token", "password", "clientSecret"];
71
- /**
72
- * Env keys under this prefix belong to the platform
73
- * (`QORE_INTEGRATION_<ALIAS>_LOGGING` today). A declaration may not claim one.
74
- */
75
- declare const RESERVED_KEY_PREFIX = "QORE_INTEGRATION_";
76
-
77
5
  interface IntegrationProblem {
78
6
  alias: string;
79
7
  key: string;
@@ -213,4 +141,4 @@ declare const INTEGRATION_SPAN_TYPE_ATTR = "qore.span.type";
213
141
  /** A cached OAuth2 token is refreshed this long before it expires. */
214
142
  declare const OAUTH_REFRESH_SKEW_MS = 30000;
215
143
 
216
- export { AUTH_ENV_FIELDS, AUTH_SECRET_FIELDS, type AuthKind, DEFAULT_INTEGRATION_TIMEOUT_MS, type EnvKey, type EnvRef, INTEGRATION_ALIAS_ATTR, INTEGRATION_SPAN_TYPE, INTEGRATION_SPAN_TYPE_ATTR, type IntegrationAuth, type IntegrationClient, type IntegrationConfig, type IntegrationDefinition, IntegrationError, type IntegrationErrorCode, type IntegrationHandle, type IntegrationMap, type IntegrationProblem, type IntegrationRequest, OAUTH_REFRESH_SKEW_MS, PLATFORM_MANAGED_HOSTS, type ParamValue, type Protocol, RESERVED_KEY_PREFIX, allKeys, assertIntegrations, createIntegrationClient, defineIntegrations, isPlatformManagedHost, loggingEnabled, loggingKey, readRef, requiredKeys };
144
+ export { DEFAULT_INTEGRATION_TIMEOUT_MS, EnvRef, INTEGRATION_ALIAS_ATTR, INTEGRATION_SPAN_TYPE, INTEGRATION_SPAN_TYPE_ATTR, type IntegrationClient, type IntegrationConfig, IntegrationDefinition, IntegrationError, type IntegrationErrorCode, type IntegrationHandle, IntegrationMap, type IntegrationProblem, type IntegrationRequest, OAUTH_REFRESH_SKEW_MS, PLATFORM_MANAGED_HOSTS, type ParamValue, allKeys, assertIntegrations, createIntegrationClient, isPlatformManagedHost, loggingEnabled, loggingKey, readRef, requiredKeys };
@@ -1,22 +1,24 @@
1
1
  import {
2
- AUTH_ENV_FIELDS,
3
- AUTH_SECRET_FIELDS,
4
2
  DEFAULT_INTEGRATION_TIMEOUT_MS,
5
3
  INTEGRATION_ALIAS_ATTR,
6
4
  INTEGRATION_SPAN_TYPE,
7
5
  INTEGRATION_SPAN_TYPE_ATTR,
8
6
  IntegrationError,
9
7
  OAUTH_REFRESH_SKEW_MS,
8
+ createIntegrationClient
9
+ } from "../chunk-F3NHTHFO.js";
10
+ import {
11
+ AUTH_ENV_FIELDS,
12
+ AUTH_SECRET_FIELDS,
10
13
  RESERVED_KEY_PREFIX,
11
14
  allKeys,
12
15
  assertIntegrations,
13
- createIntegrationClient,
14
16
  defineIntegrations,
15
17
  loggingEnabled,
16
18
  loggingKey,
17
19
  readRef,
18
20
  requiredKeys
19
- } from "../chunk-2AYDFLKR.js";
21
+ } from "../chunk-TOBGX4CZ.js";
20
22
  import {
21
23
  PLATFORM_MANAGED_HOSTS,
22
24
  isPlatformManagedHost
@@ -0,0 +1,9 @@
1
+ type Mail = {
2
+ to: string;
3
+ subject: string;
4
+ html: string;
5
+ text: string;
6
+ };
7
+ declare function sendMail(mail: Mail): Promise<void>;
8
+
9
+ export { type Mail, sendMail };
@@ -0,0 +1,26 @@
1
+ import {
2
+ getLogger
3
+ } from "../chunk-MET4SIMB.js";
4
+
5
+ // src/mail/index.ts
6
+ async function sendMail(mail) {
7
+ const apiKey = process.env.MAIL_API_KEY;
8
+ if (!apiKey) {
9
+ getLogger().warn({}, "mail skipped: no MAIL_API_KEY");
10
+ return;
11
+ }
12
+ const from = process.env.MAIL_FROM;
13
+ if (!from) {
14
+ throw new Error("sendMail: MAIL_API_KEY is set but MAIL_FROM is missing");
15
+ }
16
+ const res = await fetch("https://api.resend.com/emails", {
17
+ method: "POST",
18
+ headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
19
+ body: JSON.stringify({ from, to: mail.to, subject: mail.subject, html: mail.html, text: mail.text })
20
+ });
21
+ if (!res.ok) throw new Error(`sendMail failed: ${res.status} ${await res.text()}`);
22
+ }
23
+ export {
24
+ sendMail
25
+ };
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mail/index.ts"],"sourcesContent":["// Mail transport for Next and Node apps alike. Sends over Resend when\n// MAIL_API_KEY is set, otherwise skips with a warning, so an app without a mail\n// provider still runs. Runtime-neutral and Sentry-free: the warning goes through\n// the SDK log.\nimport { getLogger } from \"../telemetry-hooks\"\n\nexport type Mail = { to: string; subject: string; html: string; text: string }\n\nexport async function sendMail(mail: Mail): Promise<void> {\n const apiKey = process.env.MAIL_API_KEY\n if (!apiKey) {\n getLogger().warn({}, \"mail skipped: no MAIL_API_KEY\")\n return\n }\n const from = process.env.MAIL_FROM\n if (!from) {\n throw new Error(\"sendMail: MAIL_API_KEY is set but MAIL_FROM is missing\")\n }\n const res = await fetch(\"https://api.resend.com/emails\", {\n method: \"POST\",\n headers: { Authorization: `Bearer ${apiKey}`, \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ from, to: mail.to, subject: mail.subject, html: mail.html, text: mail.text }),\n })\n if (!res.ok) throw new Error(`sendMail failed: ${res.status} ${await res.text()}`)\n}\n"],"mappings":";;;;;AAQA,eAAsB,SAAS,MAA2B;AACxD,QAAM,SAAS,QAAQ,IAAI;AAC3B,MAAI,CAAC,QAAQ;AACX,cAAU,EAAE,KAAK,CAAC,GAAG,+BAA+B;AACpD;AAAA,EACF;AACA,QAAM,OAAO,QAAQ,IAAI;AACzB,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AACA,QAAM,MAAM,MAAM,MAAM,iCAAiC;AAAA,IACvD,QAAQ;AAAA,IACR,SAAS,EAAE,eAAe,UAAU,MAAM,IAAI,gBAAgB,mBAAmB;AAAA,IACjF,MAAM,KAAK,UAAU,EAAE,MAAM,IAAI,KAAK,IAAI,SAAS,KAAK,SAAS,MAAM,KAAK,MAAM,MAAM,KAAK,KAAK,CAAC;AAAA,EACrG,CAAC;AACD,MAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,oBAAoB,IAAI,MAAM,IAAI,MAAM,IAAI,KAAK,CAAC,EAAE;AACnF;","names":[]}
@@ -1,6 +1,7 @@
1
1
  import {
2
- grantRuntimeDefaultPrivileges
3
- } from "../../chunk-BJN7YE63.js";
2
+ runAuthMigrations
3
+ } from "../../chunk-QMOZDE3U.js";
4
+ import "../../chunk-BJN7YE63.js";
4
5
  import "../../chunk-4MBB2UQW.js";
5
6
  import {
6
7
  getLogger,
@@ -1623,156 +1624,6 @@ async function requireAccessTokenFor(opts) {
1623
1624
  return requireAccessToken(await buildDeps(opts));
1624
1625
  }
1625
1626
 
1626
- // src/auth-core/migrate.ts
1627
- import { sql } from "drizzle-orm";
1628
- var MIGRATION_0001_SCHEMA = `
1629
- CREATE SCHEMA IF NOT EXISTS auth;
1630
- `;
1631
- var MIGRATION_0001_TABLES = `
1632
- CREATE TABLE IF NOT EXISTS auth.sessions (
1633
- id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
1634
- user_sub varchar(64) NOT NULL,
1635
- user_email varchar(320),
1636
- organization_id varchar(64),
1637
- organization_alias varchar(255),
1638
- access_token text NOT NULL,
1639
- access_expires_at timestamptz NOT NULL,
1640
- refresh_ct bytea NOT NULL,
1641
- refresh_iv bytea NOT NULL,
1642
- refresh_expires_at timestamptz NOT NULL,
1643
- created_at timestamptz NOT NULL DEFAULT now(),
1644
- updated_at timestamptz NOT NULL DEFAULT now(),
1645
- revoked_at timestamptz
1646
- );
1647
-
1648
- CREATE INDEX IF NOT EXISTS ix_auth_sessions_user_sub
1649
- ON auth.sessions(user_sub) WHERE revoked_at IS NULL;
1650
-
1651
- CREATE TABLE IF NOT EXISTS auth.login_state (
1652
- state varchar(128) PRIMARY KEY,
1653
- code_verifier varchar(255) NOT NULL,
1654
- redirect_path text NOT NULL DEFAULT '/',
1655
- created_at timestamptz NOT NULL DEFAULT now(),
1656
- expires_at timestamptz NOT NULL
1657
- );
1658
-
1659
- CREATE INDEX IF NOT EXISTS ix_auth_login_state_expires
1660
- ON auth.login_state(expires_at);
1661
- `;
1662
- var MIGRATION_0002_ID_TOKEN = `
1663
- ALTER TABLE auth.sessions ADD COLUMN IF NOT EXISTS id_token text;
1664
- `;
1665
- var MIGRATION_0003_FORCED_REAUTH = `
1666
- ALTER TABLE auth.login_state ADD COLUMN IF NOT EXISTS forced_reauth boolean NOT NULL DEFAULT false;
1667
- `;
1668
- var MIGRATION_0004_NONCE = `
1669
- ALTER TABLE auth.login_state ADD COLUMN IF NOT EXISTS nonce varchar(128);
1670
- `;
1671
- var MIGRATION_0005_RETRIED = `
1672
- ALTER TABLE auth.login_state ADD COLUMN IF NOT EXISTS retried boolean NOT NULL DEFAULT false;
1673
- `;
1674
- var MIGRATION_0006_PENDING_CONFIRM = `
1675
- ALTER TABLE auth.sessions
1676
- ADD COLUMN IF NOT EXISTS pending_identity_confirm boolean NOT NULL DEFAULT false;
1677
- `;
1678
- var MIGRATION_0007_EXPECTED_IDENTITY = `
1679
- ALTER TABLE auth.login_state ADD COLUMN IF NOT EXISTS expected_sub varchar(64);
1680
- ALTER TABLE auth.login_state ADD COLUMN IF NOT EXISTS expected_email varchar(320);
1681
- `;
1682
- async function probe(db, expression) {
1683
- const result = await db.execute(
1684
- sql.raw(`SELECT (${expression}) AS "applied"`)
1685
- );
1686
- return result.rows[0]?.applied === true;
1687
- }
1688
- var schemaExists = (schema) => (db) => probe(db, `EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = '${schema}')`);
1689
- var relationsExist = (...relations) => (db) => {
1690
- const tuples = relations.map(([schema, name]) => `('${schema}','${name}')`).join(", ");
1691
- return probe(
1692
- db,
1693
- `(SELECT count(*) FROM pg_class c
1694
- JOIN pg_namespace n ON n.oid = c.relnamespace
1695
- WHERE (n.nspname, c.relname) IN (${tuples})) = ${relations.length}`
1696
- );
1697
- };
1698
- var columnsExist = (...columns) => (db) => {
1699
- const tuples = columns.map(([schema, table, column]) => `('${schema}','${table}','${column}')`).join(", ");
1700
- return probe(
1701
- db,
1702
- `(SELECT count(*) FROM pg_attribute a
1703
- JOIN pg_class c ON c.oid = a.attrelid
1704
- JOIN pg_namespace n ON n.oid = c.relnamespace
1705
- WHERE a.attnum > 0 AND NOT a.attisdropped
1706
- AND (n.nspname, c.relname, a.attname) IN (${tuples})) = ${columns.length}`
1707
- );
1708
- };
1709
- var MIGRATIONS = [
1710
- {
1711
- name: "0001_init:schema",
1712
- sql: MIGRATION_0001_SCHEMA,
1713
- isApplied: schemaExists("auth")
1714
- },
1715
- {
1716
- name: "0001_init:tables",
1717
- sql: MIGRATION_0001_TABLES,
1718
- isApplied: relationsExist(
1719
- ["auth", "sessions"],
1720
- ["auth", "ix_auth_sessions_user_sub"],
1721
- ["auth", "login_state"],
1722
- ["auth", "ix_auth_login_state_expires"]
1723
- )
1724
- },
1725
- {
1726
- name: "0002_id_token",
1727
- sql: MIGRATION_0002_ID_TOKEN,
1728
- isApplied: columnsExist(["auth", "sessions", "id_token"])
1729
- },
1730
- {
1731
- name: "0003_forced_reauth",
1732
- sql: MIGRATION_0003_FORCED_REAUTH,
1733
- isApplied: columnsExist(["auth", "login_state", "forced_reauth"])
1734
- },
1735
- {
1736
- name: "0004_nonce",
1737
- sql: MIGRATION_0004_NONCE,
1738
- isApplied: columnsExist(["auth", "login_state", "nonce"])
1739
- },
1740
- {
1741
- name: "0005_retried",
1742
- sql: MIGRATION_0005_RETRIED,
1743
- isApplied: columnsExist(["auth", "login_state", "retried"])
1744
- },
1745
- {
1746
- name: "0006_pending_confirm",
1747
- sql: MIGRATION_0006_PENDING_CONFIRM,
1748
- isApplied: columnsExist(["auth", "sessions", "pending_identity_confirm"])
1749
- },
1750
- {
1751
- name: "0007_expected_identity",
1752
- sql: MIGRATION_0007_EXPECTED_IDENTITY,
1753
- isApplied: columnsExist(
1754
- ["auth", "login_state", "expected_sub"],
1755
- ["auth", "login_state", "expected_email"]
1756
- )
1757
- }
1758
- ];
1759
- async function runAuthMigrations(db, opts = {}) {
1760
- for (const migration of MIGRATIONS) {
1761
- try {
1762
- if (await migration.isApplied(db)) {
1763
- continue;
1764
- }
1765
- await db.execute(sql.raw(migration.sql));
1766
- } catch (err) {
1767
- const message = err instanceof Error ? err.message : String(err);
1768
- throw new Error(`auth migration "${migration.name}" failed: ${message}`, { cause: err });
1769
- }
1770
- }
1771
- if (opts.runtimeRole) {
1772
- await grantRuntimeDefaultPrivileges(db, "auth", opts.runtimeRole);
1773
- }
1774
- }
1775
-
1776
1627
  // src/next/auth/permissionGuards.ts
1777
1628
  import { NextResponse as NextResponse2 } from "next/server";
1778
1629
  function makeGuards(map, getPermissions, requireUser = async () => {