@agent-native/core 0.229.0 → 0.230.0-nightly-20261117004313
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/action.d.ts +23 -0
- package/dist/action.js +21 -0
- package/dist/agent/production-agent.d.ts +1 -0
- package/dist/agent/production-agent.js +28 -21
- package/dist/agent/types.d.ts +2 -0
- package/dist/app-config/deploy-cache.d.ts +2 -0
- package/dist/app-config/deploy-cache.js +8 -0
- package/dist/app-config/observability.d.ts +1 -0
- package/dist/app-config/observability.js +10 -0
- package/dist/app-config/schema.d.ts +3 -0
- package/dist/app-config/store.js +1 -0
- package/dist/cli/skills-content/design-remix-skill.d.ts +1 -1
- package/dist/cli/skills-content/design-remix-skill.js +193 -32
- package/dist/client/action-query-foreground.d.ts +4 -2
- package/dist/client/action-query-foreground.js +53 -6
- package/dist/client/hooks/index.d.ts +1 -0
- package/dist/client/hooks/index.js +1 -0
- package/dist/client/onboarding/first-run-status.js +4 -0
- package/dist/client/org/hooks.d.ts +12 -1
- package/dist/client/org/hooks.js +24 -2
- package/dist/client/sharing/useShareButtonController.d.ts +8 -1
- package/dist/client/sharing/useShareButtonController.js +20 -13
- package/dist/client/theme.d.ts +9 -1
- package/dist/client/theme.js +15 -2
- package/dist/client/ui/index.d.ts +1 -1
- package/dist/client/ui/index.js +1 -1
- package/dist/client/use-action.d.ts +8 -0
- package/dist/client/use-action.js +20 -3
- package/dist/collab/routes.d.ts +1 -1
- package/dist/db/create-get-db.d.ts +2 -1
- package/dist/db/create-get-db.js +99 -14
- package/dist/deploy/build-cache.js +10 -0
- package/dist/deploy/build.js +44 -5
- package/dist/deploy/workspace-deploy.js +46 -1
- package/dist/extensions/url-safety.d.ts +2 -0
- package/dist/extensions/url-safety.js +1 -0
- package/dist/framework-package-versions.json +7 -7
- package/dist/identity/offboard.d.ts +2 -0
- package/dist/identity/offboard.js +32 -0
- package/dist/org/auto-join-domain.js +11 -3
- package/dist/org/handlers.d.ts +16 -1
- package/dist/org/handlers.js +162 -42
- package/dist/org/index.d.ts +2 -1
- package/dist/org/index.js +1 -0
- package/dist/org/plugin.d.ts +2 -0
- package/dist/org/plugin.js +17 -1
- package/dist/org/types.d.ts +6 -0
- package/dist/provider-api/actions/custom-provider-registration.d.ts +16 -16
- package/dist/provider-api/actions/provider-api.d.ts +10 -10
- package/dist/resources/store.d.ts +5 -0
- package/dist/resources/store.js +54 -0
- package/dist/server/auth.js +3 -1
- package/dist/server/builder-browser.js +10 -1
- package/dist/server/document-build-id.d.ts +18 -0
- package/dist/server/document-build-id.js +43 -0
- package/dist/server/entry-server.js +3 -5
- package/dist/server/first-touch-route.d.ts +1 -1
- package/dist/server/onboarding-html.js +4 -3
- package/dist/server/workspace-provider-oauth.js +26 -6
- package/dist/sharing/actions/set-resource-visibility.js +36 -4
- package/dist/sharing/grant.js +10 -2
- package/dist/sharing/registry.d.ts +2 -0
- package/dist/templates/default/app/root.tsx +8 -2
- package/dist/triggers/dispatcher.d.ts +7 -0
- package/dist/triggers/dispatcher.js +13 -0
- package/dist/triggers/index.d.ts +1 -1
- package/dist/triggers/index.js +1 -1
- package/dist/user-profile/actions/update-user-profile.js +1 -1
- package/dist/vite/client.d.ts +2 -1
- package/dist/vite/client.js +5 -2
- package/dist/vitest-config.js +6 -0
- package/package.json +4 -4
- package/src/templates/default/app/root.tsx +8 -2
|
@@ -82,6 +82,12 @@ const BUILD_GENERATED_APP_DIRS = [
|
|
|
82
82
|
".deploy-tmp",
|
|
83
83
|
".react-router",
|
|
84
84
|
];
|
|
85
|
+
/**
|
|
86
|
+
* Files a deploy writes into the app after its build. A split build records
|
|
87
|
+
* the leg's build id here, so a persistent checkout would otherwise miss on
|
|
88
|
+
* every rebuild of an unchanged commit.
|
|
89
|
+
*/
|
|
90
|
+
const BUILD_GENERATED_APP_FILES = [".agent-native-app-build-id"];
|
|
85
91
|
/** Variables that differ between runs without ever reaching a build output. */
|
|
86
92
|
const VOLATILE_ENV_NAMES = new Set([
|
|
87
93
|
"_",
|
|
@@ -138,6 +144,9 @@ const VOLATILE_ENV_NAMES = new Set([
|
|
|
138
144
|
"LaunchInstanceID",
|
|
139
145
|
"Apple_PubSub_Socket_Render",
|
|
140
146
|
"AGENT_NATIVE_DEPLOY_CONCURRENCY",
|
|
147
|
+
// Split-build selectors choose which apps a leg builds; no app build reads them.
|
|
148
|
+
"AGENT_NATIVE_DEPLOY_ONLY_APPS",
|
|
149
|
+
"AGENT_NATIVE_DEPLOY_PREBUILT_APPS",
|
|
141
150
|
]);
|
|
142
151
|
// Lowercase, compared case-insensitively.
|
|
143
152
|
const VOLATILE_ENV_PREFIXES = [
|
|
@@ -254,6 +263,7 @@ function hashAppSource(workspaceRoot, appDirInput) {
|
|
|
254
263
|
const outputRoots = new Set([
|
|
255
264
|
...APP_BUILD_OUTPUT_PATHS.map((p) => p.split(path.sep)[0]),
|
|
256
265
|
...BUILD_GENERATED_APP_DIRS,
|
|
266
|
+
...BUILD_GENERATED_APP_FILES,
|
|
257
267
|
]);
|
|
258
268
|
const hash = crypto.createHash("sha256");
|
|
259
269
|
const files = gitListFiles(rootReal, [appRel]).filter((file) => {
|
package/dist/deploy/build.js
CHANGED
|
@@ -3650,11 +3650,48 @@ function hasBareYjsRuntimeImport(source) {
|
|
|
3650
3650
|
return /\b(?:from\s*|import\s*\(\s*|import\s*)["']yjs(?:\/[^"']*)?["']/.test(source);
|
|
3651
3651
|
}
|
|
3652
3652
|
function hasBareRuntimeImport(source, packageName) {
|
|
3653
|
+
return bareRuntimeImportSpecifiers(source, packageName).length > 0;
|
|
3654
|
+
}
|
|
3655
|
+
function bareRuntimeImportSpecifiers(source, packageName) {
|
|
3653
3656
|
const escapedPackageName = packageName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3654
3657
|
const quote = `["\'\\\`]`;
|
|
3655
|
-
const staticModuleReference = new RegExp(`(?:^|[;\\n])\\s*(?:import(?:[^;\\n]*?from\\s*|\\s*)|export\\s+[^;\\n]*?from\\s*)(${quote})${escapedPackageName}(?:/[^"\'\\\`]+)
|
|
3656
|
-
const dynamicImport = new RegExp(`\\bimport\\s*\\(\\s*(${quote})${escapedPackageName}(?:/[^"\'\\\`]+)
|
|
3657
|
-
return
|
|
3658
|
+
const staticModuleReference = new RegExp(`(?:^|[;\\n])\\s*(?:import(?:[^;\\n]*?from\\s*|\\s*)|export\\s+[^;\\n]*?from\\s*)(${quote})(${escapedPackageName}(?:/[^"\'\\\`]+)?)\\1`, "g");
|
|
3659
|
+
const dynamicImport = new RegExp(`\\bimport\\s*\\(\\s*(${quote})(${escapedPackageName}(?:/[^"\'\\\`]+)?)\\1`, "g");
|
|
3660
|
+
return [
|
|
3661
|
+
...source.matchAll(staticModuleReference),
|
|
3662
|
+
...source.matchAll(dynamicImport),
|
|
3663
|
+
]
|
|
3664
|
+
.map((match) => match.at(2))
|
|
3665
|
+
.filter((specifier) => specifier !== undefined);
|
|
3666
|
+
}
|
|
3667
|
+
/**
|
|
3668
|
+
* Whether a bare import resolves, from the importing file, to a file shipped
|
|
3669
|
+
* inside the server bundle. A missing dependency or one that resolves outside
|
|
3670
|
+
* the bundle is not shipped; any other resolution failure is thrown.
|
|
3671
|
+
*/
|
|
3672
|
+
function isShippedRuntimeImport(specifier, importingFile, serverDir) {
|
|
3673
|
+
try {
|
|
3674
|
+
const resolved = fs.realpathSync(createRequire(importingFile).resolve(specifier));
|
|
3675
|
+
const relative = path.relative(fs.realpathSync(serverDir), resolved);
|
|
3676
|
+
return (relative !== ".." &&
|
|
3677
|
+
!relative.startsWith(`..${path.sep}`) &&
|
|
3678
|
+
!path.isAbsolute(relative) &&
|
|
3679
|
+
fs.statSync(resolved).isFile());
|
|
3680
|
+
}
|
|
3681
|
+
catch (error) {
|
|
3682
|
+
if (error instanceof Error &&
|
|
3683
|
+
"code" in error &&
|
|
3684
|
+
typeof error.code === "string" &&
|
|
3685
|
+
[
|
|
3686
|
+
"MODULE_NOT_FOUND",
|
|
3687
|
+
"ERR_PACKAGE_PATH_NOT_EXPORTED",
|
|
3688
|
+
"ENOENT",
|
|
3689
|
+
"ENOTDIR",
|
|
3690
|
+
].includes(error.code)) {
|
|
3691
|
+
return false;
|
|
3692
|
+
}
|
|
3693
|
+
throw error;
|
|
3694
|
+
}
|
|
3658
3695
|
}
|
|
3659
3696
|
function hasBareRuntimeRequire(source, packageName) {
|
|
3660
3697
|
const escapedPackageName = packageName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -4108,8 +4145,10 @@ export function assertSingleTemplateNetlifyBuildOutput(projectCwd) {
|
|
|
4108
4145
|
walkServerJavaScriptFiles(serverDir, (filePath) => {
|
|
4109
4146
|
const source = fs.readFileSync(filePath, "utf-8");
|
|
4110
4147
|
for (const dependency of bundledIngestionPeers) {
|
|
4111
|
-
|
|
4112
|
-
|
|
4148
|
+
for (const specifier of bareRuntimeImportSpecifiers(source, dependency)) {
|
|
4149
|
+
if (!isShippedRuntimeImport(specifier, filePath, serverDir)) {
|
|
4150
|
+
bareIngestionImports.push(`${dependency} in ${path.relative(projectCwd, filePath)} (${specifier} is not shipped inside the server bundle)`);
|
|
4151
|
+
}
|
|
4113
4152
|
}
|
|
4114
4153
|
}
|
|
4115
4154
|
});
|
|
@@ -73,6 +73,9 @@ const WORKSPACE_APPS_MANIFEST_DIR = ".agent-native";
|
|
|
73
73
|
const WORKSPACE_APPS_MANIFEST_FILE = "workspace-apps.json";
|
|
74
74
|
const WORKSPACE_ROOT_GOOGLE_CALLBACK_PATH = "/_agent-native/google/callback";
|
|
75
75
|
const VERCEL_OUTPUT_DIR = ".vercel/output";
|
|
76
|
+
// A split leg's build id travels with its output; whatever moves a leg's
|
|
77
|
+
// output between machines must carry this path too.
|
|
78
|
+
const APP_BUILD_ID_FILE = ".agent-native-app-build-id";
|
|
76
79
|
function builtinAgentsEnvSnippet() {
|
|
77
80
|
const json = getAppConfig().workspace.builtinAgentsJson;
|
|
78
81
|
if (!json)
|
|
@@ -247,6 +250,8 @@ export async function runWorkspaceDeploy(opts = {}) {
|
|
|
247
250
|
const concurrency = workspaceBuildConcurrency();
|
|
248
251
|
const runBuild = opts.execFile ?? spawnBuild;
|
|
249
252
|
const cacheConfig = getAppConfig().deployCache;
|
|
253
|
+
const selection = workspaceBuildSelection(apps, cacheConfig);
|
|
254
|
+
const toBuild = selection.only ?? apps.filter((app) => !selection.prebuilt.has(app));
|
|
250
255
|
const cache = cacheConfig.enabled
|
|
251
256
|
? createDeployCacheRuntime({
|
|
252
257
|
dir: path.resolve(workspaceRoot, cacheConfig.dir ?? defaultDeployCacheDir(workspaceRoot)),
|
|
@@ -261,13 +266,25 @@ export async function runWorkspaceDeploy(opts = {}) {
|
|
|
261
266
|
}
|
|
262
267
|
const buildStartedAt = Date.now();
|
|
263
268
|
const appBuildIds = new Map();
|
|
264
|
-
await runWithConcurrency(
|
|
269
|
+
await runWithConcurrency(toBuild, concurrency, async (app) => {
|
|
265
270
|
appBuildIds.set(app, await buildOneApp(workspaceRoot, appsDir, app, preset, runBuild, workspaceApps, workspaceAuthMode, concurrency > 1 ? "pipe" : "inherit", cache));
|
|
266
271
|
});
|
|
272
|
+
if (selection.only) {
|
|
273
|
+
for (const app of selection.only) {
|
|
274
|
+
fs.writeFileSync(path.join(appsDir, app, APP_BUILD_ID_FILE), appBuildIdFor(appBuildIds, app));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
for (const app of selection.prebuilt) {
|
|
278
|
+
appBuildIds.set(app, readPrebuiltAppBuildId(appsDir, app));
|
|
279
|
+
}
|
|
267
280
|
if (cache) {
|
|
268
281
|
const { hits, misses, savedMs, verified } = cache.stats;
|
|
269
282
|
console.log(`[workspace-deploy] Build cache: ${hits} hit, ${misses} miss${verified ? `, ${verified} verified by rebuild` : ""}; build phase ${((Date.now() - buildStartedAt) / 1000).toFixed(1)}s, ~${(savedMs / 1000).toFixed(1)}s saved`);
|
|
270
283
|
}
|
|
284
|
+
if (selection.only) {
|
|
285
|
+
console.log(`[workspace-deploy] Built ${selection.only.join(", ")} only; packaging is left to the job that assembles the workspace`);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
271
288
|
opts.onProgress?.({ step: "package" });
|
|
272
289
|
// Copy in app order after all builds so shared outputs stay deterministic.
|
|
273
290
|
const sweepCrons = [];
|
|
@@ -396,6 +413,15 @@ async function buildOneApp(workspaceRoot, appsDir, app, preset, runBuild, worksp
|
|
|
396
413
|
});
|
|
397
414
|
return appBuildId;
|
|
398
415
|
}
|
|
416
|
+
/** The id a split leg recorded for its build; packaging a prebuilt app cannot recompute it. */
|
|
417
|
+
function readPrebuiltAppBuildId(appsDir, app) {
|
|
418
|
+
const file = path.join(appsDir, app, APP_BUILD_ID_FILE);
|
|
419
|
+
const id = fs.existsSync(file) ? fs.readFileSync(file, "utf8").trim() : "";
|
|
420
|
+
if (!id) {
|
|
421
|
+
throw new Error(`Expected ${APP_BUILD_ID_FILE} under ${path.join(appsDir, app)} but none existed. Build the app with AGENT_NATIVE_DEPLOY_ONLY_APPS so its build id is recorded.`);
|
|
422
|
+
}
|
|
423
|
+
return id;
|
|
424
|
+
}
|
|
399
425
|
function appBuildIdFor(appBuildIds, app) {
|
|
400
426
|
const id = appBuildIds.get(app);
|
|
401
427
|
if (!id)
|
|
@@ -412,6 +438,25 @@ function workspaceSourceRevision() {
|
|
|
412
438
|
const candidate = process.env.AGENT_NATIVE_BUILD_ID?.trim();
|
|
413
439
|
return /^[a-f0-9]{40}$/i.test(candidate ?? "") ? candidate : undefined;
|
|
414
440
|
}
|
|
441
|
+
/**
|
|
442
|
+
* A workspace deploy can be split across machines: `onlyApps` builds just those
|
|
443
|
+
* apps and stops before packaging, and `prebuiltApps` packages apps whose build
|
|
444
|
+
* output was put back into the app directory. An id that is not an app of this
|
|
445
|
+
* workspace is an error, never an empty selection.
|
|
446
|
+
*/
|
|
447
|
+
function workspaceBuildSelection(apps, config) {
|
|
448
|
+
const only = config.onlyApps?.length ? config.onlyApps : null;
|
|
449
|
+
const prebuilt = config.prebuiltApps ?? [];
|
|
450
|
+
if (only && prebuilt.length > 0) {
|
|
451
|
+
throw new Error("AGENT_NATIVE_DEPLOY_ONLY_APPS and AGENT_NATIVE_DEPLOY_PREBUILT_APPS cannot both be set");
|
|
452
|
+
}
|
|
453
|
+
const known = new Set(apps);
|
|
454
|
+
const unknown = [...(only ?? []), ...prebuilt].filter((id) => !known.has(id));
|
|
455
|
+
if (unknown.length > 0) {
|
|
456
|
+
throw new Error(`Deploy selection names ${unknown.map((id) => `"${id}"`).join(", ")}, which ${unknown.length === 1 ? "is" : "are"} not in this workspace (${apps.join(", ")})`);
|
|
457
|
+
}
|
|
458
|
+
return { only, prebuilt: new Set(prebuilt) };
|
|
459
|
+
}
|
|
415
460
|
function workspaceBuildConcurrency() {
|
|
416
461
|
const raw = process.env.AGENT_NATIVE_DEPLOY_CONCURRENCY?.trim();
|
|
417
462
|
if (raw) {
|
|
@@ -37,6 +37,8 @@ export declare function ssrfSafeFetch(url: string, init?: RequestInit, options?:
|
|
|
37
37
|
requireDispatcher?: boolean;
|
|
38
38
|
httpsOnly?: boolean;
|
|
39
39
|
assertUrlAllowed?: (url: string) => void | Promise<void>;
|
|
40
|
+
/** Synchronous policy recheck after DNS/dispatcher waits, at each dispatch. */
|
|
41
|
+
beforeDispatch?: (url: string) => void;
|
|
40
42
|
allowedPrivateOrigins?: readonly string[];
|
|
41
43
|
allowedLocalhostOrigin?: string;
|
|
42
44
|
}): Promise<Response>;
|
|
@@ -384,6 +384,7 @@ export async function ssrfSafeFetch(url, init = {}, options = {}) {
|
|
|
384
384
|
});
|
|
385
385
|
if (dispatcher)
|
|
386
386
|
fetchOpts.dispatcher = dispatcher;
|
|
387
|
+
options.beforeDispatch?.(currentUrl);
|
|
387
388
|
const response = await fetch(currentUrl, fetchOpts);
|
|
388
389
|
if (response.status >= 300 && response.status < 400) {
|
|
389
390
|
if (options.followRedirects === false)
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
"@agent-native/agentkit": "0.
|
|
2
|
+
"@agent-native/agentkit": "0.230.0-nightly-20261117004313",
|
|
3
3
|
"@agent-native/code-agents-ui": "0.1.75",
|
|
4
|
-
"@agent-native/core": "0.
|
|
5
|
-
"@agent-native/core-corpus": "0.
|
|
4
|
+
"@agent-native/core": "0.230.0-nightly-20261117004313",
|
|
5
|
+
"@agent-native/core-corpus": "0.230.0-nightly-20261117004313",
|
|
6
6
|
"@agent-native/creative-context": "0.8.73",
|
|
7
|
-
"@agent-native/dispatch": "0.42.
|
|
7
|
+
"@agent-native/dispatch": "0.42.9-nightly-20261117004313",
|
|
8
8
|
"@agent-native/embedding": "0.2.0",
|
|
9
9
|
"@agent-native/migrate": "0.0.7",
|
|
10
10
|
"@agent-native/otel": "0.1.40",
|
|
11
11
|
"@agent-native/pinpoint": "0.1.116",
|
|
12
12
|
"@agent-native/recap-cli": "0.5.104",
|
|
13
|
-
"@agent-native/scheduling": "0.3.
|
|
13
|
+
"@agent-native/scheduling": "0.3.1-nightly-20261117004313",
|
|
14
14
|
"@agent-native/shared-app-config": "0.1.2",
|
|
15
|
-
"@agent-native/skills": "0.4.
|
|
16
|
-
"@agent-native/toolkit": "0.
|
|
15
|
+
"@agent-native/skills": "0.4.9-nightly-20261117004313",
|
|
16
|
+
"@agent-native/toolkit": "0.230.0-nightly-20261117004313"
|
|
17
17
|
}
|
|
@@ -3,6 +3,8 @@ export type OffboardMemberOptions = {
|
|
|
3
3
|
transferTo: string;
|
|
4
4
|
orgId?: string | null;
|
|
5
5
|
actorEmail?: string;
|
|
6
|
+
/** Keep a Deactivated record of the org membership; requires `orgId`. */
|
|
7
|
+
deactivate?: boolean;
|
|
6
8
|
};
|
|
7
9
|
export type OffboardMemberResult = {
|
|
8
10
|
removedMemberships: number;
|
|
@@ -55,6 +55,8 @@ export async function offboardMember(db, email, options) {
|
|
|
55
55
|
const transferTo = options.transferTo.trim().toLowerCase();
|
|
56
56
|
if (!oldEmail || !transferTo || oldEmail === transferTo)
|
|
57
57
|
throw new Error("A different successor is required before offboarding a member");
|
|
58
|
+
if (options.deactivate && !options.orgId?.trim())
|
|
59
|
+
throw new Error("Deactivating a member requires an organization");
|
|
58
60
|
await ensureAuditTables();
|
|
59
61
|
const run = async (tx) => {
|
|
60
62
|
const orgId = options.orgId?.trim() || null;
|
|
@@ -310,6 +312,36 @@ export async function offboardMember(db, email, options) {
|
|
|
310
312
|
args: [oldEmail],
|
|
311
313
|
})
|
|
312
314
|
: { rowsAffected: 0 };
|
|
315
|
+
if (options.deactivate && orgId) {
|
|
316
|
+
// Every grant reads only 'pending' invitation rows, so this record confers nothing.
|
|
317
|
+
await tx.execute({
|
|
318
|
+
sql: `UPDATE org_invitations SET status = 'canceled'
|
|
319
|
+
WHERE org_id = ? AND LOWER(email) = ? AND status = 'pending'`,
|
|
320
|
+
args: [orgId, oldEmail],
|
|
321
|
+
});
|
|
322
|
+
// A repeated removal keeps the first record; replacing it would lose it once the
|
|
323
|
+
// membership row it is copied from is gone.
|
|
324
|
+
await tx.execute({
|
|
325
|
+
sql: `INSERT INTO org_invitations (id, org_id, email, invited_by, created_at, status, role)
|
|
326
|
+
SELECT ?, m.org_id, ?, ?, ?, 'deactivated', m.role FROM org_members m
|
|
327
|
+
WHERE m.org_id = ? AND LOWER(m.email) = ?
|
|
328
|
+
AND NOT EXISTS (
|
|
329
|
+
SELECT 1 FROM org_invitations d
|
|
330
|
+
WHERE d.org_id = m.org_id AND LOWER(d.email) = ?
|
|
331
|
+
AND d.status = 'deactivated'
|
|
332
|
+
)
|
|
333
|
+
LIMIT 1`,
|
|
334
|
+
args: [
|
|
335
|
+
randomUUID(),
|
|
336
|
+
oldEmail,
|
|
337
|
+
options.actorEmail ?? "system",
|
|
338
|
+
Date.now(),
|
|
339
|
+
orgId,
|
|
340
|
+
oldEmail,
|
|
341
|
+
oldEmail,
|
|
342
|
+
],
|
|
343
|
+
});
|
|
344
|
+
}
|
|
313
345
|
const memberships = await tx.execute({
|
|
314
346
|
sql: `DELETE FROM org_members WHERE LOWER(email) = ?${orgId ? " AND org_id = ?" : ""}`,
|
|
315
347
|
args: orgId ? [oldEmail, orgId] : [oldEmail],
|
|
@@ -69,17 +69,25 @@ export async function autoJoinDomainMatchingOrgs(rawEmail, options = {}) {
|
|
|
69
69
|
WHERE m.org_id = o.id
|
|
70
70
|
AND LOWER(m.email) = ?
|
|
71
71
|
AND m.federation_removal_pending_at IS NULL
|
|
72
|
-
) AS "isMember"
|
|
72
|
+
) AS "isMember",
|
|
73
|
+
EXISTS (
|
|
74
|
+
SELECT 1 FROM org_invitations i
|
|
75
|
+
WHERE i.org_id = o.id
|
|
76
|
+
AND LOWER(i.email) = ?
|
|
77
|
+
AND i.status = 'deactivated'
|
|
78
|
+
) AS "isDeactivated"
|
|
73
79
|
FROM organizations o
|
|
74
80
|
WHERE LOWER(o.allowed_domain) = ?
|
|
75
81
|
LIMIT 2`,
|
|
76
|
-
args: [email, domain],
|
|
82
|
+
args: [email, email, domain],
|
|
77
83
|
});
|
|
78
84
|
if (res.rows.length > 1)
|
|
79
85
|
return { joined: [], activeOrgId: null };
|
|
80
86
|
if (res.rows.length === 1) {
|
|
81
87
|
const row = res.rows[0];
|
|
82
|
-
|
|
88
|
+
// A deactivated member stays out until an admin re-invites them.
|
|
89
|
+
if (Boolean(row.isMember ?? row.is_member) ||
|
|
90
|
+
Boolean(row.isDeactivated ?? row.is_deactivated)) {
|
|
83
91
|
return { joined: [], activeOrgId: null };
|
|
84
92
|
}
|
|
85
93
|
matches = [
|
package/dist/org/handlers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type H3Event } from "h3";
|
|
2
|
-
import type { OrgRole, RequiredAuthProvider, WorkspaceAppDefaultVisibility } from "./types.js";
|
|
2
|
+
import type { OrgDeactivatedMember, OrgRole, RequiredAuthProvider, WorkspaceAppDefaultVisibility } from "./types.js";
|
|
3
3
|
export declare const getMyOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
4
4
|
email: string;
|
|
5
5
|
orgId: string | null;
|
|
@@ -86,6 +86,11 @@ export declare const retryPendingFederatedRemovalHandler: import("h3").EventHand
|
|
|
86
86
|
success: boolean;
|
|
87
87
|
orgId: any;
|
|
88
88
|
}>>;
|
|
89
|
+
export declare const leaveOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
orgId: string;
|
|
92
|
+
nextOrgId: string | null;
|
|
93
|
+
}>>;
|
|
89
94
|
export declare const setWorkspaceAppDefaultVisibilityHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
90
95
|
visibility: WorkspaceAppDefaultVisibility;
|
|
91
96
|
}>>;
|
|
@@ -135,6 +140,13 @@ export declare function inviteOne(ctx: {
|
|
|
135
140
|
orgName: string | null;
|
|
136
141
|
email: string;
|
|
137
142
|
}, rawEmail: string, role: "member" | "admin", event?: H3Event, appId?: string, appRoles?: string[]): Promise<SingleInviteResult>;
|
|
143
|
+
/** Sends the framework invitation email for an invite; throws when the send fails. */
|
|
144
|
+
export declare function sendOrgInvitationEmail(invite: {
|
|
145
|
+
orgId: string;
|
|
146
|
+
orgName: string | null;
|
|
147
|
+
inviter: string;
|
|
148
|
+
email: string;
|
|
149
|
+
}, event?: H3Event): Promise<void>;
|
|
138
150
|
export declare const createInvitationHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<SingleInviteResult | {
|
|
139
151
|
succeeded: SingleInviteResult[];
|
|
140
152
|
failed: SingleInviteFailure[];
|
|
@@ -167,6 +179,9 @@ export declare const acceptInvitationHandler: import("h3").EventHandlerWithFetch
|
|
|
167
179
|
export declare const removeMemberHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
168
180
|
success: boolean;
|
|
169
181
|
}>>;
|
|
182
|
+
export declare const listDeactivatedMembersHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
183
|
+
members: OrgDeactivatedMember[];
|
|
184
|
+
}>>;
|
|
170
185
|
export declare const changeMemberRoleHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
171
186
|
email: string;
|
|
172
187
|
role: string;
|
package/dist/org/handlers.js
CHANGED
|
@@ -383,21 +383,37 @@ export const retryPendingFederatedRemovalHandler = defineEventHandler(async (eve
|
|
|
383
383
|
message: "The organization owner cannot be removed",
|
|
384
384
|
});
|
|
385
385
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
386
|
+
await completeSelfRemoval(event, {
|
|
387
|
+
email,
|
|
388
|
+
orgId,
|
|
389
|
+
role,
|
|
390
|
+
requestedTransferTo,
|
|
391
|
+
reason: "completed pending organization removal",
|
|
392
|
+
});
|
|
393
|
+
return { success: true, orgId };
|
|
394
|
+
});
|
|
395
|
+
async function findSelfRemovalSuccessor(e, orgId, email) {
|
|
396
|
+
const successor = await e.execute({
|
|
397
|
+
sql: `SELECT email FROM org_members
|
|
398
|
+
WHERE org_id = ? AND LOWER(email) <> ?
|
|
399
|
+
AND federation_removal_pending_at IS NULL
|
|
400
|
+
AND role IN ('owner', 'admin', 'member')
|
|
401
|
+
ORDER BY CASE WHEN role = 'owner' THEN 0
|
|
402
|
+
WHEN role = 'admin' THEN 1 ELSE 2 END,
|
|
403
|
+
joined_at ASC, LOWER(email) ASC
|
|
404
|
+
LIMIT 1`,
|
|
405
|
+
args: [orgId, email],
|
|
406
|
+
});
|
|
407
|
+
return String(successor.rows[0]?.email ?? "").trim();
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Ends the caller's own membership, whose row is already marked
|
|
411
|
+
* `federation_removal_pending_at`, and moves only the caller's active org.
|
|
412
|
+
*/
|
|
413
|
+
async function completeSelfRemoval(event, input) {
|
|
414
|
+
const { email, orgId, role, requestedTransferTo } = input;
|
|
415
|
+
const e = await exec();
|
|
416
|
+
const transferTo = requestedTransferTo || (await findSelfRemovalSuccessor(e, orgId, email));
|
|
401
417
|
if (!transferTo) {
|
|
402
418
|
throw createError({
|
|
403
419
|
statusCode: 409,
|
|
@@ -440,17 +456,79 @@ export const retryPendingFederatedRemovalHandler = defineEventHandler(async (eve
|
|
|
440
456
|
}
|
|
441
457
|
const nextOrg = await e.execute({
|
|
442
458
|
sql: `SELECT org_id AS "orgId" FROM org_members
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
459
|
+
WHERE LOWER(email) = ?
|
|
460
|
+
AND federation_removal_pending_at IS NULL
|
|
461
|
+
ORDER BY joined_at ASC, org_id ASC
|
|
462
|
+
LIMIT 1`,
|
|
447
463
|
args: [email],
|
|
448
464
|
});
|
|
449
|
-
const
|
|
450
|
-
|
|
465
|
+
const nextOrgRow = nextOrg.rows[0];
|
|
466
|
+
const nextOrgId = nextOrgRow
|
|
467
|
+
? String(nextOrgRow.orgId ?? nextOrgRow.org_id)
|
|
451
468
|
: null;
|
|
452
|
-
await setActiveOrgId(email, nextOrgId,
|
|
453
|
-
return
|
|
469
|
+
await setActiveOrgId(email, nextOrgId, input.reason, event);
|
|
470
|
+
return nextOrgId;
|
|
471
|
+
}
|
|
472
|
+
export const leaveOrgHandler = defineEventHandler(async (event) => {
|
|
473
|
+
const ctx = await getOrgContext(event);
|
|
474
|
+
if (!ctx.orgId) {
|
|
475
|
+
throw createError({ statusCode: 400, message: "No active organization" });
|
|
476
|
+
}
|
|
477
|
+
const email = ctx.email.trim().toLowerCase();
|
|
478
|
+
const e = await exec();
|
|
479
|
+
const membership = await e.execute({
|
|
480
|
+
sql: `SELECT role FROM org_members
|
|
481
|
+
WHERE org_id = ? AND LOWER(email) = ?
|
|
482
|
+
AND federation_removal_pending_at IS NULL
|
|
483
|
+
LIMIT 1`,
|
|
484
|
+
args: [ctx.orgId, email],
|
|
485
|
+
});
|
|
486
|
+
const role = membership.rows[0]?.role;
|
|
487
|
+
if (!role) {
|
|
488
|
+
throw createError({ statusCode: 404, message: "Membership not found" });
|
|
489
|
+
}
|
|
490
|
+
if (role === "owner") {
|
|
491
|
+
throw createError({
|
|
492
|
+
statusCode: 403,
|
|
493
|
+
message: "The organization owner cannot leave it",
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
const otherMembership = await e.execute({
|
|
497
|
+
sql: `SELECT 1 FROM org_members
|
|
498
|
+
WHERE LOWER(email) = ? AND org_id <> ?
|
|
499
|
+
AND federation_removal_pending_at IS NULL
|
|
500
|
+
LIMIT 1`,
|
|
501
|
+
args: [email, ctx.orgId],
|
|
502
|
+
});
|
|
503
|
+
if (otherMembership.rows.length === 0) {
|
|
504
|
+
throw createError({
|
|
505
|
+
statusCode: 409,
|
|
506
|
+
message: "You can't leave your only organization",
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
// Resolved before the row is marked pending: a 409 afterwards would leave
|
|
510
|
+
// the caller locked out of an org they never left.
|
|
511
|
+
const successor = await findSelfRemovalSuccessor(e, ctx.orgId, email);
|
|
512
|
+
if (!successor) {
|
|
513
|
+
throw createError({
|
|
514
|
+
statusCode: 409,
|
|
515
|
+
message: "An active organization member is required as a successor",
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
await e.execute({
|
|
519
|
+
sql: `UPDATE org_members SET federation_removal_pending_at = ?
|
|
520
|
+
WHERE org_id = ? AND LOWER(email) = ?
|
|
521
|
+
AND federation_removal_pending_at IS NULL`,
|
|
522
|
+
args: [Date.now(), ctx.orgId, email],
|
|
523
|
+
});
|
|
524
|
+
const nextOrgId = await completeSelfRemoval(event, {
|
|
525
|
+
email,
|
|
526
|
+
orgId: ctx.orgId,
|
|
527
|
+
role,
|
|
528
|
+
requestedTransferTo: successor,
|
|
529
|
+
reason: "left organization",
|
|
530
|
+
});
|
|
531
|
+
return { success: true, orgId: ctx.orgId, nextOrgId };
|
|
454
532
|
});
|
|
455
533
|
export const setWorkspaceAppDefaultVisibilityHandler = defineEventHandler(async (event) => {
|
|
456
534
|
const ctx = await getOrgContext(event);
|
|
@@ -814,10 +892,24 @@ export async function inviteOne(ctx, rawEmail, role, event, appId, appRoles) {
|
|
|
814
892
|
[descriptor.appId]: [...new Set(appRoles)],
|
|
815
893
|
});
|
|
816
894
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
895
|
+
// An explicit admin invitation lifts a prior deactivation. Both writes commit together: a
|
|
896
|
+
// failed insert must leave the member excluded from domain auto-join, and a failed delete
|
|
897
|
+
// must not leave a pending invitation behind that makes a retry look like a duplicate.
|
|
898
|
+
const writeInvitation = async (tx) => {
|
|
899
|
+
await tx.execute({
|
|
900
|
+
sql: `INSERT INTO org_invitations (id, org_id, email, invited_by, created_at, status, role, app_roles_json) VALUES (?, ?, ?, ?, ?, 'pending', ?, ?)`,
|
|
901
|
+
args: [id, ctx.orgId, email, ctx.email, Date.now(), role, appRolesJson],
|
|
902
|
+
});
|
|
903
|
+
await tx.execute({
|
|
904
|
+
sql: `DELETE FROM org_invitations
|
|
905
|
+
WHERE org_id = ? AND LOWER(email) = ? AND status = 'deactivated'`,
|
|
906
|
+
args: [ctx.orgId, email],
|
|
907
|
+
});
|
|
908
|
+
};
|
|
909
|
+
if (e.transaction)
|
|
910
|
+
await e.transaction(writeInvitation);
|
|
911
|
+
else
|
|
912
|
+
await writeInvitation(e);
|
|
821
913
|
try {
|
|
822
914
|
const inviteSentPromise = import("../tracking/registry.js")
|
|
823
915
|
.then(async ({ track, flushTracking }) => {
|
|
@@ -836,21 +928,7 @@ export async function inviteOne(ctx, rawEmail, role, event, appId, appRoles) {
|
|
|
836
928
|
let emailError;
|
|
837
929
|
if (await isEmailConfigured()) {
|
|
838
930
|
try {
|
|
839
|
-
|
|
840
|
-
invitee: email,
|
|
841
|
-
orgName: ctx.orgName || "your team",
|
|
842
|
-
acceptUrl: getInviteAppUrl(event),
|
|
843
|
-
inviter: ctx.email,
|
|
844
|
-
});
|
|
845
|
-
await sendEmail({
|
|
846
|
-
to: email,
|
|
847
|
-
subject,
|
|
848
|
-
html,
|
|
849
|
-
text,
|
|
850
|
-
templateId: CORE_INVITE_EMAIL_ID,
|
|
851
|
-
orgId: ctx.orgId,
|
|
852
|
-
authCritical: true,
|
|
853
|
-
});
|
|
931
|
+
await sendOrgInvitationEmail({ orgId: ctx.orgId, orgName: ctx.orgName, inviter: ctx.email, email }, event);
|
|
854
932
|
emailSent = true;
|
|
855
933
|
}
|
|
856
934
|
catch (err) {
|
|
@@ -860,6 +938,24 @@ export async function inviteOne(ctx, rawEmail, role, event, appId, appRoles) {
|
|
|
860
938
|
}
|
|
861
939
|
return { id, email, role, status: "pending", emailSent, emailError };
|
|
862
940
|
}
|
|
941
|
+
/** Sends the framework invitation email for an invite; throws when the send fails. */
|
|
942
|
+
export async function sendOrgInvitationEmail(invite, event) {
|
|
943
|
+
const { subject, html, text } = await renderTransactionalEmail(CORE_INVITE_EMAIL_ID, {
|
|
944
|
+
invitee: invite.email,
|
|
945
|
+
orgName: invite.orgName || "your team",
|
|
946
|
+
acceptUrl: getInviteAppUrl(event),
|
|
947
|
+
inviter: invite.inviter,
|
|
948
|
+
});
|
|
949
|
+
await sendEmail({
|
|
950
|
+
to: invite.email,
|
|
951
|
+
subject,
|
|
952
|
+
html,
|
|
953
|
+
text,
|
|
954
|
+
templateId: CORE_INVITE_EMAIL_ID,
|
|
955
|
+
orgId: invite.orgId,
|
|
956
|
+
authCritical: true,
|
|
957
|
+
});
|
|
958
|
+
}
|
|
863
959
|
export const createInvitationHandler = defineEventHandler(async (event) => {
|
|
864
960
|
const ctx = await getOrgContext(event);
|
|
865
961
|
if (!ctx.orgId) {
|
|
@@ -1238,6 +1334,7 @@ export const removeMemberHandler = defineEventHandler(async (event) => {
|
|
|
1238
1334
|
transferTo,
|
|
1239
1335
|
orgId: ctx.orgId,
|
|
1240
1336
|
actorEmail: ctx.email,
|
|
1337
|
+
deactivate: body.deactivate === true,
|
|
1241
1338
|
});
|
|
1242
1339
|
}
|
|
1243
1340
|
catch (error) {
|
|
@@ -1254,6 +1351,29 @@ export const removeMemberHandler = defineEventHandler(async (event) => {
|
|
|
1254
1351
|
}
|
|
1255
1352
|
return { success: true };
|
|
1256
1353
|
});
|
|
1354
|
+
export const listDeactivatedMembersHandler = defineEventHandler(async (event) => {
|
|
1355
|
+
const ctx = await getOrgContext(event);
|
|
1356
|
+
if (!ctx.orgId)
|
|
1357
|
+
return { members: [] };
|
|
1358
|
+
const e = await exec();
|
|
1359
|
+
const { rows } = await e.execute({
|
|
1360
|
+
sql: `SELECT i.email, i.role, i.created_at AS "deactivatedAt"
|
|
1361
|
+
FROM org_invitations i
|
|
1362
|
+
WHERE i.org_id = ? AND i.status = 'deactivated'
|
|
1363
|
+
AND NOT EXISTS (
|
|
1364
|
+
SELECT 1 FROM org_members m
|
|
1365
|
+
WHERE m.org_id = i.org_id AND LOWER(m.email) = LOWER(i.email)
|
|
1366
|
+
)
|
|
1367
|
+
ORDER BY LOWER(i.email) ASC`,
|
|
1368
|
+
args: [ctx.orgId],
|
|
1369
|
+
});
|
|
1370
|
+
const members = rows.map((r) => ({
|
|
1371
|
+
email: String(r.email),
|
|
1372
|
+
role: String(r.role),
|
|
1373
|
+
deactivatedAt: Number(r.deactivatedAt ?? r.deactivated_at),
|
|
1374
|
+
}));
|
|
1375
|
+
return { members };
|
|
1376
|
+
});
|
|
1257
1377
|
export const changeMemberRoleHandler = defineEventHandler(async (event) => {
|
|
1258
1378
|
const ctx = await getOrgContext(event);
|
|
1259
1379
|
if (!ctx.orgId) {
|
package/dist/org/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DbExec } from "../db/client.js";
|
|
2
|
-
export type { OrgRole, OrgContext, OrgSummary, OrgInvitationSummary, OrgPendingRemoval, OrgInfo, OrgMember, OrgPendingInvitation, RequiredAuthProvider, WorkspaceAppDefaultVisibility, } from "./types.js";
|
|
2
|
+
export type { OrgRole, OrgContext, OrgSummary, OrgInvitationSummary, OrgPendingRemoval, OrgInfo, OrgMember, OrgDeactivatedMember, OrgPendingInvitation, RequiredAuthProvider, WorkspaceAppDefaultVisibility, } from "./types.js";
|
|
3
3
|
export { SIGN_IN_METHOD_ENV_VARS, type OrgSignInMethods, type SocialSignInMethod, } from "./sign-in-methods.js";
|
|
4
4
|
export { canInviteOrgMembers, canManageOrg, canManageOrgA2ASecret, canManageOrgDomain, orgRoleAtLeast, orgRoleRank, } from "./permissions.js";
|
|
5
5
|
export declare const getOrgContext: typeof import("./context.js").getOrgContext;
|
|
@@ -243,6 +243,7 @@ export declare const listInvitationsHandler: import("h3").EventHandlerWithFetch<
|
|
|
243
243
|
}>>;
|
|
244
244
|
export declare const createInvitationHandler: (typeof import("./handlers.js"))["createInvitationHandler"];
|
|
245
245
|
export declare const inviteOrganizationAdmin: (typeof import("./invite-organization-admin.js"))["inviteOrganizationAdmin"];
|
|
246
|
+
export declare const sendOrgInvitationEmail: (typeof import("./handlers.js"))["sendOrgInvitationEmail"];
|
|
246
247
|
export declare const acceptInvitationHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
|
|
247
248
|
orgId: string;
|
|
248
249
|
orgName: string;
|
package/dist/org/index.js
CHANGED
|
@@ -76,6 +76,7 @@ export const changeMemberRoleHandler = lazyFunction(loadOrgHandlers, "changeMemb
|
|
|
76
76
|
export const listInvitationsHandler = lazyFunction(loadOrgHandlers, "listInvitationsHandler");
|
|
77
77
|
export const createInvitationHandler = lazyFunction(loadOrgHandlers, "createInvitationHandler");
|
|
78
78
|
export const inviteOrganizationAdmin = lazyFunction(() => import("./invite-organization-admin.js"), "inviteOrganizationAdmin");
|
|
79
|
+
export const sendOrgInvitationEmail = lazyFunction(loadOrgHandlers, "sendOrgInvitationEmail");
|
|
79
80
|
export const acceptInvitationHandler = lazyFunction(loadOrgHandlers, "acceptInvitationHandler");
|
|
80
81
|
export const cancelInvitationHandler = lazyFunction(loadOrgHandlers, "cancelInvitationHandler");
|
|
81
82
|
export const setA2ASecretHandler = lazyFunction(loadOrgHandlers, "setA2ASecretHandler");
|
package/dist/org/plugin.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ type NitroPluginDef = (nitroApp: any) => void | Promise<void>;
|
|
|
9
9
|
* PATCH /_agent-native/org — rename organization (owner/admin)
|
|
10
10
|
* DELETE /_agent-native/org — delete organization (owner only)
|
|
11
11
|
* PUT /_agent-native/org/switch — switch active org
|
|
12
|
+
* POST /_agent-native/org/leave — leave the active org (not its owner)
|
|
12
13
|
* GET /_agent-native/org/members — list members of active org
|
|
14
|
+
* GET /_agent-native/org/members/deactivated — members removed with `deactivate`
|
|
13
15
|
* DELETE /_agent-native/org/members/:email — remove member (owner/admin only)
|
|
14
16
|
* POST /_agent-native/org/federation-removal/retry — retry the caller's pending self-cleanup
|
|
15
17
|
* GET /_agent-native/org/app-roles?appId=X — app role vocabulary + assignments
|