@happyvertical/smrt-cli 0.53.4 → 0.53.6
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/AGENTS.md +2 -0
- package/README.md +24 -0
- package/agents/app-commands.md +28 -3
- package/dist/{ApiKey-BZmbOTnL-DPPF6Swn.js → ApiKey-BZmbOTnL-BbZupUZ3.js} +2 -2
- package/dist/ApiKeyCollection-Bfb_nw81-DYAZwx0O.js +87 -0
- package/dist/AuditLogCollection-B1YonCAP-Crf-dCr_.js +193 -0
- package/dist/{NostrIdentity-n70E0vck-D60BSg6H.js → NostrIdentity-n70E0vck-Di3_eNCq.js} +4 -4
- package/dist/NostrIdentityCollection-Ca74dkaL-DvjOg9Xy.js +127 -0
- package/dist/{OidcIdentity-Cb1bxreM-B2eV2ahq.js → OidcIdentity-Cb1bxreM-B6XDawZQ.js} +2 -2
- package/dist/OidcIdentityCollection-TV8VdK69-ZwKF9iwf.js +86 -0
- package/dist/ProfileAssetCollection-B9hacUJa-BS8VMInH.js +101 -0
- package/dist/{ProfileCollection-DuJT7Mum-B3Uhqphs.js → ProfileCollection-DuJT7Mum-CCKEl9oT.js} +31 -31
- package/dist/ProfileLinkCollection-4uNURz32-Vo7wyan6.js +233 -0
- package/dist/ProfileMetadataCollection-DQhbfEfa-OvHyg4k0.js +108 -0
- package/dist/ProfileMetafieldCollection-CoBuM_5G-KUHXgANZ.js +145 -0
- package/dist/ProfileRelationshipCollection-DUVgaIqf-CedyrKgX.js +161 -0
- package/dist/ProfileRelationshipTermCollection-DtA9OM23-BoGhQBSQ.js +107 -0
- package/dist/{ProfileRelationshipType-BRiRka6t-Ci-qvFhm.js → ProfileRelationshipType-BRiRka6t-Dezjv5jP.js} +1 -1
- package/dist/ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js +57 -0
- package/dist/app/cli.d.ts +7 -0
- package/dist/app/cli.d.ts.map +1 -1
- package/dist/app/errors.d.ts +34 -1
- package/dist/app/errors.d.ts.map +1 -1
- package/dist/app/index.d.ts +4 -3
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/launchers.d.ts +11 -0
- package/dist/app/launchers.d.ts.map +1 -1
- package/dist/app/operations.d.ts +2 -0
- package/dist/app/operations.d.ts.map +1 -1
- package/dist/app/runtime.d.ts +17 -2
- package/dist/app/runtime.d.ts.map +1 -1
- package/dist/app/tokens.d.ts +21 -0
- package/dist/app/tokens.d.ts.map +1 -0
- package/dist/app.js +3 -3
- package/dist/{cli-BRFsobey.js → cli-OZsH5cdL.js} +403 -76
- package/dist/cli-generator.d.ts.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/utilities.d.ts.map +1 -1
- package/dist/{commands-dFz1e9A6.js → commands-C8SM-WRo.js} +35 -51
- package/dist/database-environment-D_Gk1Brf.js +20 -0
- package/dist/database-environment.d.ts +43 -0
- package/dist/database-environment.d.ts.map +1 -0
- package/dist/dist-BbDBCq3u.js +20 -0
- package/dist/{dist-D4BNILLN.js → dist-BcPl3hiD.js} +3 -3
- package/dist/{dist-Berwe80z.js → dist-BdrRmnpP.js} +4 -4
- package/dist/{dist-EJ63xUEp.js → dist-DbMWqynv.js} +2 -2
- package/dist/{dist-C2BqYVu7.js → dist-VNy6NiC_.js} +1654 -1748
- package/dist/index.js +15 -10
- package/dist/{oidcProvisioningPrimitives-D9OYu5-F-B-kYsBTM.js → oidcProvisioningPrimitives-D9OYu5-F-Cc2KYoAb.js} +5 -5
- package/dist/{portability-DmQWSSXA.js → portability-CES1YC2m.js} +1 -1
- package/dist/resolveIdentity-B-PK6RwU-JMNQ4YZ7.js +269 -0
- package/package.json +15 -15
- package/dist/ApiKeyCollection-Bfb_nw81-B1-2YKj8.js +0 -2
- package/dist/AuditLogCollection-B1YonCAP-DP4PCCw-.js +0 -2
- package/dist/NostrIdentityCollection-Ca74dkaL-C-v57o9N.js +0 -2
- package/dist/OidcIdentityCollection-TV8VdK69-BodvOtPJ.js +0 -2
- package/dist/ProfileAssetCollection-B9hacUJa-B7PLe0ld.js +0 -2
- package/dist/ProfileLinkCollection-4uNURz32-CLY1cBnn.js +0 -2
- package/dist/ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js +0 -2
- package/dist/ProfileMetafieldCollection-CoBuM_5G-D-VqQuY1.js +0 -2
- package/dist/ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js +0 -2
- package/dist/ProfileRelationshipTermCollection-DtA9OM23-DI_awdol.js +0 -2
- package/dist/ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js +0 -2
- package/dist/resolveIdentity-B-PK6RwU-BmAU1Kse.js +0 -2
package/dist/index.js
CHANGED
|
@@ -49,63 +49,63 @@ var _playgroundCommands = null;
|
|
|
49
49
|
var _workbenchCommands = null;
|
|
50
50
|
async function getGnodeCommands() {
|
|
51
51
|
if (!_gnodeCommands) {
|
|
52
|
-
const { gnodeCommands } = await import("./commands-
|
|
52
|
+
const { gnodeCommands } = await import("./commands-C8SM-WRo.js");
|
|
53
53
|
_gnodeCommands = gnodeCommands;
|
|
54
54
|
}
|
|
55
55
|
return _gnodeCommands;
|
|
56
56
|
}
|
|
57
57
|
async function getGitCommands() {
|
|
58
58
|
if (!_gitCommands) {
|
|
59
|
-
const { gitCommands } = await import("./commands-
|
|
59
|
+
const { gitCommands } = await import("./commands-C8SM-WRo.js");
|
|
60
60
|
_gitCommands = gitCommands;
|
|
61
61
|
}
|
|
62
62
|
return _gitCommands;
|
|
63
63
|
}
|
|
64
64
|
async function getGenerateCommands() {
|
|
65
65
|
if (!_generateCommands) {
|
|
66
|
-
const { generateCommands } = await import("./commands-
|
|
66
|
+
const { generateCommands } = await import("./commands-C8SM-WRo.js");
|
|
67
67
|
_generateCommands = generateCommands;
|
|
68
68
|
}
|
|
69
69
|
return _generateCommands;
|
|
70
70
|
}
|
|
71
71
|
async function getInitCommands() {
|
|
72
72
|
if (!_initCommands) {
|
|
73
|
-
const { initCommands } = await import("./commands-
|
|
73
|
+
const { initCommands } = await import("./commands-C8SM-WRo.js");
|
|
74
74
|
_initCommands = initCommands;
|
|
75
75
|
}
|
|
76
76
|
return _initCommands;
|
|
77
77
|
}
|
|
78
78
|
async function getUtilityCommands() {
|
|
79
79
|
if (!_utilityCommands) {
|
|
80
|
-
const { utilityCommands } = await import("./commands-
|
|
80
|
+
const { utilityCommands } = await import("./commands-C8SM-WRo.js");
|
|
81
81
|
_utilityCommands = utilityCommands;
|
|
82
82
|
}
|
|
83
83
|
return _utilityCommands;
|
|
84
84
|
}
|
|
85
85
|
async function getDispatchCommands() {
|
|
86
86
|
if (!_dispatchCommands) {
|
|
87
|
-
const { dispatchCommands } = await import("./commands-
|
|
87
|
+
const { dispatchCommands } = await import("./commands-C8SM-WRo.js");
|
|
88
88
|
_dispatchCommands = dispatchCommands;
|
|
89
89
|
}
|
|
90
90
|
return _dispatchCommands;
|
|
91
91
|
}
|
|
92
92
|
async function getDocsCommands() {
|
|
93
93
|
if (!_docsCommands) {
|
|
94
|
-
const { docsCommands } = await import("./commands-
|
|
94
|
+
const { docsCommands } = await import("./commands-C8SM-WRo.js");
|
|
95
95
|
_docsCommands = docsCommands;
|
|
96
96
|
}
|
|
97
97
|
return _docsCommands;
|
|
98
98
|
}
|
|
99
99
|
async function getPlaygroundCommands() {
|
|
100
100
|
if (!_playgroundCommands) {
|
|
101
|
-
const { playgroundCommands } = await import("./commands-
|
|
101
|
+
const { playgroundCommands } = await import("./commands-C8SM-WRo.js");
|
|
102
102
|
_playgroundCommands = playgroundCommands;
|
|
103
103
|
}
|
|
104
104
|
return _playgroundCommands;
|
|
105
105
|
}
|
|
106
106
|
async function getWorkbenchCommands() {
|
|
107
107
|
if (!_workbenchCommands) {
|
|
108
|
-
const { workbenchCommands } = await import("./commands-
|
|
108
|
+
const { workbenchCommands } = await import("./commands-C8SM-WRo.js");
|
|
109
109
|
_workbenchCommands = workbenchCommands;
|
|
110
110
|
}
|
|
111
111
|
return _workbenchCommands;
|
|
@@ -1566,7 +1566,7 @@ var CLIGenerator = class {
|
|
|
1566
1566
|
async function main() {
|
|
1567
1567
|
const args = process.argv.slice(2);
|
|
1568
1568
|
if (args[0] === "app") {
|
|
1569
|
-
const { runAppCommand } = await import("./cli-
|
|
1569
|
+
const { runAppCommand } = await import("./cli-OZsH5cdL.js").then((n) => n.r);
|
|
1570
1570
|
process.exitCode = await runAppCommand(args.slice(1));
|
|
1571
1571
|
return;
|
|
1572
1572
|
}
|
|
@@ -1580,6 +1580,9 @@ async function main() {
|
|
|
1580
1580
|
"smrt.config.js",
|
|
1581
1581
|
"smrt.config.mjs",
|
|
1582
1582
|
"smrt.config.cjs",
|
|
1583
|
+
"smrt.config.ts",
|
|
1584
|
+
"smrt.config.mts",
|
|
1585
|
+
"smrt.config.cts",
|
|
1583
1586
|
"smrt.config.json"
|
|
1584
1587
|
];
|
|
1585
1588
|
let dir = process.cwd();
|
|
@@ -1598,6 +1601,8 @@ async function main() {
|
|
|
1598
1601
|
const configStart = timingEnabled ? performance.now() : 0;
|
|
1599
1602
|
const { loadConfig } = await import("@happyvertical/smrt-config");
|
|
1600
1603
|
await loadConfig({ cache: true });
|
|
1604
|
+
const { applyDatabaseEnvironment } = await import("./database-environment-D_Gk1Brf.js");
|
|
1605
|
+
await applyDatabaseEnvironment();
|
|
1601
1606
|
if (timingEnabled) timing.config = performance.now() - configStart;
|
|
1602
1607
|
const handler = new CLIGenerator({
|
|
1603
1608
|
name: "smrt",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
-
import { c as isSystemContext } from "./dist-
|
|
3
|
-
import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-
|
|
4
|
-
import { t as OidcIdentity } from "./OidcIdentity-Cb1bxreM-
|
|
5
|
-
import {
|
|
2
|
+
import { c as isSystemContext } from "./dist-DbMWqynv.js";
|
|
3
|
+
import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
|
|
4
|
+
import { t as OidcIdentity } from "./OidcIdentity-Cb1bxreM-B6XDawZQ.js";
|
|
5
|
+
import { a as ProfileCollection, f as saveOidcRaceArbiter, i as Profile, s as ProfileType } from "./ProfileCollection-DuJT7Mum-CCKEl9oT.js";
|
|
6
6
|
import { SmrtCollection, smrt } from "@happyvertical/smrt-core";
|
|
7
7
|
//#region ../profiles/dist/chunks/oidcProvisioningPrimitives-D9OYu5-F.js
|
|
8
8
|
var oidcProvisioningPrimitives_D9OYu5_F_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -158,4 +158,4 @@ function requireProvisioningId(value, label) {
|
|
|
158
158
|
return value;
|
|
159
159
|
}
|
|
160
160
|
//#endregion
|
|
161
|
-
export {
|
|
161
|
+
export { createOidcProvisioningPerson as a, ProfileTypeCollection as i, Organization as n, insertOidcProvisioningIdentity as o, Person as r, oidcProvisioningPrimitives_D9OYu5_F_exports as s, Bot as t };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
-
import {
|
|
2
|
+
import { A as assertExternalArtifactPath, L as errorCode } from "./cli-OZsH5cdL.js";
|
|
3
3
|
import { closeSync, constants, existsSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
|
|
2
|
+
import { l as withSystemContext } from "./dist-DbMWqynv.js";
|
|
3
|
+
import { n as __exportAll$1, t as NostrIdentity, u as verifyAuthEvent } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
|
|
4
|
+
import { t as ApiKey } from "./ApiKey-BZmbOTnL-BbZupUZ3.js";
|
|
5
|
+
import { t as OidcIdentity } from "./OidcIdentity-Cb1bxreM-B6XDawZQ.js";
|
|
6
|
+
import { c as coordinateOidcProvisioning, l as isOidcProvisioningRaceConflict, u as normalizeIdentityEmail } from "./ProfileCollection-DuJT7Mum-CCKEl9oT.js";
|
|
7
|
+
import { a as createOidcProvisioningPerson, o as insertOidcProvisioningIdentity } from "./oidcProvisioningPrimitives-D9OYu5-F-Cc2KYoAb.js";
|
|
8
|
+
import { resolveDatabase } from "@happyvertical/smrt-core";
|
|
9
|
+
//#region ../profiles/dist/chunks/resolveIdentity-B-PK6RwU.js
|
|
10
|
+
var resolveIdentity_B_PK6RwU_exports = /* @__PURE__ */ __exportAll({
|
|
11
|
+
i: () => resolveIdentity_exports,
|
|
12
|
+
n: () => createProfileFromOidc,
|
|
13
|
+
r: () => resolveIdentity,
|
|
14
|
+
t: () => createProfileFromNostr
|
|
15
|
+
});
|
|
16
|
+
var resolveIdentity_exports = /* @__PURE__ */ __exportAll$1({
|
|
17
|
+
createProfileFromNostr: () => createProfileFromNostr,
|
|
18
|
+
createProfileFromOidc: () => createProfileFromOidc,
|
|
19
|
+
resolveIdentity: () => resolveIdentity,
|
|
20
|
+
reuseExistingOidcIdentityForProfile: () => reuseExistingOidcIdentityForProfile
|
|
21
|
+
});
|
|
22
|
+
async function resolveIdentity(context) {
|
|
23
|
+
const options = { db: context.db };
|
|
24
|
+
if (context.apiKey) {
|
|
25
|
+
const apiKey = await ApiKey.verify(context.apiKey, options);
|
|
26
|
+
if (apiKey) {
|
|
27
|
+
const profile = await apiKey.getProfile();
|
|
28
|
+
if (profile) return {
|
|
29
|
+
profile,
|
|
30
|
+
source: "api_key",
|
|
31
|
+
apiKey
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (context.oidcSession?.sub && context.oidcSession?.iss) {
|
|
36
|
+
const oidcIdentity = await OidcIdentity.findBySubject(context.oidcSession.iss, context.oidcSession.sub, options);
|
|
37
|
+
if (oidcIdentity) {
|
|
38
|
+
await oidcIdentity.recordUsage();
|
|
39
|
+
const profile = await oidcIdentity.getProfile();
|
|
40
|
+
if (profile) return {
|
|
41
|
+
profile,
|
|
42
|
+
source: "oidc",
|
|
43
|
+
oidcIdentity
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (context.nostrAuth?.event && context.nostrAuth?.challenge) {
|
|
48
|
+
const { event, challenge } = context.nostrAuth;
|
|
49
|
+
if (verifyAuthEvent(event, challenge).valid) {
|
|
50
|
+
const nostrIdentity = await NostrIdentity.findByPubkey(event.pubkey, options);
|
|
51
|
+
if (nostrIdentity) {
|
|
52
|
+
await nostrIdentity.recordUsage();
|
|
53
|
+
const profile = await nostrIdentity.getProfile();
|
|
54
|
+
if (profile) return {
|
|
55
|
+
profile,
|
|
56
|
+
source: "nostr",
|
|
57
|
+
nostrIdentity
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (context.actor) {
|
|
63
|
+
const profile = await findProfileByExternalId("github", context.actor, options);
|
|
64
|
+
if (profile) return {
|
|
65
|
+
profile,
|
|
66
|
+
source: "actor"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
profile: null,
|
|
71
|
+
source: "none"
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function findProfileByExternalId(provider, externalId, options) {
|
|
75
|
+
const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-ZwKF9iwf.js").then((n) => n.r).then((n) => n.r);
|
|
76
|
+
const identities = await (await OidcIdentityCollection.create(options)).findByProvider(provider);
|
|
77
|
+
for (const identity of identities) if (identity.subject === externalId || identity.email?.includes(externalId)) {
|
|
78
|
+
const profile = await identity.getProfile();
|
|
79
|
+
if (profile) return profile;
|
|
80
|
+
}
|
|
81
|
+
const { ProfileCollection } = await import("./ProfileCollection-DuJT7Mum-CCKEl9oT.js").then((n) => n.o).then((n) => n.r);
|
|
82
|
+
const profiles = await (await ProfileCollection.create(options)).list({
|
|
83
|
+
where: { email: `${externalId}@users.noreply.github.com` },
|
|
84
|
+
limit: 1
|
|
85
|
+
});
|
|
86
|
+
if (profiles.length > 0) return profiles[0];
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
async function createProfileFromOidc(claims, provider, options) {
|
|
90
|
+
return coordinateProfileOidcProvisioning(claims, provider, options);
|
|
91
|
+
}
|
|
92
|
+
async function reuseExistingOidcIdentityForProfile(profileId, claims, provider, options) {
|
|
93
|
+
const normalizedClaims = normalizeOidcProfileClaims(claims);
|
|
94
|
+
return coordinateOidcProvisioning({
|
|
95
|
+
db: await resolveOidcProfileDatabase(options.db),
|
|
96
|
+
lockKeys: [`identity:${OidcIdentity.buildIdentityKey(normalizedClaims.iss, normalizedClaims.sub)}`],
|
|
97
|
+
isRaceConflict: isOidcProvisioningRaceConflict,
|
|
98
|
+
createTransactionError: (message, cause) => new Error(message, cause === void 0 ? void 0 : { cause }),
|
|
99
|
+
createConcurrencyError: (cause) => new Error("Concurrent exact OIDC identity reuse did not converge.", cause === void 0 ? void 0 : { cause }),
|
|
100
|
+
rebindRootResult: rebindOidcProfileResult,
|
|
101
|
+
provision: (tx) => withSystemContext(async () => {
|
|
102
|
+
const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-ZwKF9iwf.js").then((n) => n.r).then((n) => n.r);
|
|
103
|
+
const identity = await (await OidcIdentityCollection.create({ db: tx })).findBySubject(normalizedClaims.iss, normalizedClaims.sub);
|
|
104
|
+
if (!identity) throw new Error("OidcIdentity.findOrCreate() no longer creates authentication links; use UserCollection.getOrCreateFromOidc() or createProfileFromOidc().");
|
|
105
|
+
if (identity.profileId !== profileId) throw new Error(`OIDC identity ${normalizedClaims.iss} subject ${normalizedClaims.sub} belongs to a different Profile.`);
|
|
106
|
+
const profile = await identity.getProfile();
|
|
107
|
+
if (!profile) throw new Error("The exact OIDC identity has no linked Profile.");
|
|
108
|
+
identity.provider = provider;
|
|
109
|
+
if (normalizedClaims.email) identity.email = normalizedClaims.email;
|
|
110
|
+
identity.lastUsedAt = /* @__PURE__ */ new Date();
|
|
111
|
+
await identity.save();
|
|
112
|
+
return {
|
|
113
|
+
profile,
|
|
114
|
+
oidcIdentity: identity,
|
|
115
|
+
created: false
|
|
116
|
+
};
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async function coordinateProfileOidcProvisioning(claims, provider, options) {
|
|
121
|
+
const normalizedClaims = normalizeOidcProfileClaims(claims);
|
|
122
|
+
return coordinateOidcProvisioning({
|
|
123
|
+
db: await resolveOidcProfileDatabase(options.db),
|
|
124
|
+
lockKeys: [`identity:${OidcIdentity.buildIdentityKey(normalizedClaims.iss, normalizedClaims.sub)}`, ...normalizedClaims.email ? [`email:${normalizedClaims.email}`] : []],
|
|
125
|
+
isRaceConflict: isOidcProvisioningRaceConflict,
|
|
126
|
+
createTransactionError: (message, cause) => new Error(message, cause === void 0 ? void 0 : { cause }),
|
|
127
|
+
createConcurrencyError: (cause) => new Error("Concurrent OIDC Profile provisioning did not converge.", cause === void 0 ? void 0 : { cause }),
|
|
128
|
+
rebindRootResult: rebindOidcProfileResult,
|
|
129
|
+
provision: (tx) => withSystemContext(() => provisionOidcProfile(normalizedClaims, provider, {
|
|
130
|
+
...options,
|
|
131
|
+
db: tx
|
|
132
|
+
}))
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async function provisionOidcProfile(claims, provider, options) {
|
|
136
|
+
const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-ZwKF9iwf.js").then((n) => n.r).then((n) => n.r);
|
|
137
|
+
const existingIdentity = await (await OidcIdentityCollection.create(options)).findBySubject(claims.iss, claims.sub);
|
|
138
|
+
if (existingIdentity) {
|
|
139
|
+
const profile2 = await existingIdentity.getProfile();
|
|
140
|
+
if (!profile2) throw new Error("The exact OIDC identity has no linked Profile.");
|
|
141
|
+
profile2.id = requireOidcProfileId(existingIdentity.profileId);
|
|
142
|
+
if (claims.email) existingIdentity.email = claims.email;
|
|
143
|
+
existingIdentity.lastUsedAt = /* @__PURE__ */ new Date();
|
|
144
|
+
await existingIdentity.save();
|
|
145
|
+
return {
|
|
146
|
+
profile: profile2,
|
|
147
|
+
oidcIdentity: existingIdentity,
|
|
148
|
+
created: false
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const { ProfileCollection } = await import("./ProfileCollection-DuJT7Mum-CCKEl9oT.js").then((n) => n.o).then((n) => n.r);
|
|
152
|
+
const profileCollection = await ProfileCollection.create(options);
|
|
153
|
+
if (claims.email) {
|
|
154
|
+
if (await profileCollection.findUniqueGlobalPersonByEmail(claims.email)) {
|
|
155
|
+
if (claims.email_verified !== true) throw new Error(`OIDC email ${claims.email} is not verified and already belongs to a Profile.`);
|
|
156
|
+
throw new Error(`OIDC email ${claims.email} already belongs to a Profile; createProfileFromOidc() cannot prove that Profile is unowned. Use UserCollection.getOrCreateFromOidc() for owner-aware linking.`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const profile = await createOidcProvisioningPerson(options.db, {
|
|
160
|
+
email: claims.email ?? "",
|
|
161
|
+
name: claims.name,
|
|
162
|
+
preferredUsername: claims.preferred_username,
|
|
163
|
+
subject: claims.sub
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
profile,
|
|
167
|
+
oidcIdentity: await insertOidcProvisioningIdentity(options.db, {
|
|
168
|
+
email: claims.email,
|
|
169
|
+
issuer: claims.iss,
|
|
170
|
+
profileId: requireOidcProfileId(profile.id),
|
|
171
|
+
provider,
|
|
172
|
+
subject: claims.sub
|
|
173
|
+
}),
|
|
174
|
+
created: true
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async function rebindOidcProfileResult(result, rootDb) {
|
|
178
|
+
const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-ZwKF9iwf.js").then((n) => n.r).then((n) => n.r);
|
|
179
|
+
const { ProfileCollection } = await import("./ProfileCollection-DuJT7Mum-CCKEl9oT.js").then((n) => n.o).then((n) => n.r);
|
|
180
|
+
const profileId = requireOidcProfileId(result.profile.id);
|
|
181
|
+
const identityId = requireOidcProfileId(result.oidcIdentity.id);
|
|
182
|
+
const [profile, oidcIdentity] = await withSystemContext(async () => {
|
|
183
|
+
const profiles = await ProfileCollection.create({ db: rootDb });
|
|
184
|
+
const identities = await OidcIdentityCollection.create({ db: rootDb });
|
|
185
|
+
return [await profiles.get({ id: profileId }), await identities.get({ id: identityId })];
|
|
186
|
+
});
|
|
187
|
+
if (!profile || !oidcIdentity) throw new Error("Committed OIDC Profile provisioning result was not found.");
|
|
188
|
+
profile.id = profileId;
|
|
189
|
+
oidcIdentity.id = identityId;
|
|
190
|
+
oidcIdentity.profileId = profileId;
|
|
191
|
+
return {
|
|
192
|
+
...result,
|
|
193
|
+
profile,
|
|
194
|
+
oidcIdentity
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function normalizeOidcProfileClaims(claims) {
|
|
198
|
+
const sub = claims?.sub;
|
|
199
|
+
const iss = claims?.iss;
|
|
200
|
+
if (typeof sub !== "string" || sub.trim().length === 0 || typeof iss !== "string" || iss.trim().length === 0) throw new Error("Invalid OIDC claims: both \"sub\" and \"iss\" must be non-empty strings.");
|
|
201
|
+
const suppliedEmail = claims.email;
|
|
202
|
+
return {
|
|
203
|
+
...claims,
|
|
204
|
+
sub,
|
|
205
|
+
iss,
|
|
206
|
+
email: typeof suppliedEmail === "string" && suppliedEmail.trim() ? normalizeIdentityEmail(suppliedEmail) : void 0
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function requireOidcProfileId(value) {
|
|
210
|
+
if (typeof value !== "string" || !value) throw new Error("OIDC Profile provisioning did not produce an id.");
|
|
211
|
+
return value;
|
|
212
|
+
}
|
|
213
|
+
async function resolveOidcProfileDatabase(db) {
|
|
214
|
+
if (!db) throw new Error("OIDC Profile provisioning requires an initialized database.");
|
|
215
|
+
return resolveDatabase(db);
|
|
216
|
+
}
|
|
217
|
+
async function createProfileFromNostr(email, nostrData, options) {
|
|
218
|
+
const normalizedEmail = normalizeIdentityEmail(email);
|
|
219
|
+
const existingIdentity = await NostrIdentity.findByEmail(normalizedEmail, options);
|
|
220
|
+
if (existingIdentity) {
|
|
221
|
+
const profile2 = await existingIdentity.getProfile();
|
|
222
|
+
if (profile2) return {
|
|
223
|
+
profile: profile2,
|
|
224
|
+
nostrIdentity: existingIdentity,
|
|
225
|
+
created: false
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const { Person } = await import("./oidcProvisioningPrimitives-D9OYu5-F-Cc2KYoAb.js").then((n) => n.s).then((n) => n.o);
|
|
229
|
+
const { ProfileTypeCollection } = await import("./oidcProvisioningPrimitives-D9OYu5-F-Cc2KYoAb.js").then((n) => n.s).then((n) => n.c);
|
|
230
|
+
let personType = await (await ProfileTypeCollection.create(options)).getBySlug("person");
|
|
231
|
+
if (!personType) {
|
|
232
|
+
const { ProfileType } = await import("./ProfileCollection-DuJT7Mum-CCKEl9oT.js").then((n) => n.o).then((n) => n.h);
|
|
233
|
+
personType = new ProfileType({
|
|
234
|
+
...options,
|
|
235
|
+
slug: "person",
|
|
236
|
+
name: "Person",
|
|
237
|
+
description: "Individual person profile"
|
|
238
|
+
});
|
|
239
|
+
await personType.initialize();
|
|
240
|
+
await personType.save();
|
|
241
|
+
}
|
|
242
|
+
const profile = new Person({
|
|
243
|
+
...options,
|
|
244
|
+
typeId: personType.id,
|
|
245
|
+
email: normalizedEmail,
|
|
246
|
+
name: normalizedEmail.split("@")[0]
|
|
247
|
+
});
|
|
248
|
+
await profile.initialize();
|
|
249
|
+
await profile.save();
|
|
250
|
+
const nostrIdentity = new NostrIdentity({
|
|
251
|
+
...options,
|
|
252
|
+
profileId: profile.id,
|
|
253
|
+
pubkey: nostrData.pubkey,
|
|
254
|
+
encryptedPrivkey: nostrData.encryptedPrivkey,
|
|
255
|
+
encryptionIv: nostrData.encryptionIv,
|
|
256
|
+
encryptionTag: nostrData.encryptionTag,
|
|
257
|
+
email: normalizedEmail,
|
|
258
|
+
nip05Username: nostrData.nip05Username?.toLowerCase() || normalizedEmail.split("@")[0]
|
|
259
|
+
});
|
|
260
|
+
await nostrIdentity.initialize();
|
|
261
|
+
await nostrIdentity.save();
|
|
262
|
+
return {
|
|
263
|
+
profile,
|
|
264
|
+
nostrIdentity,
|
|
265
|
+
created: true
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
export { resolveIdentity_B_PK6RwU_exports as i, createProfileFromOidc as n, resolveIdentity as r, createProfileFromNostr as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-cli",
|
|
3
|
-
"version": "0.53.
|
|
3
|
+
"version": "0.53.6",
|
|
4
4
|
"description": "Developer CLI for SMRT framework - introspection, testing, and project management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,20 +29,20 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@happyvertical/ai": "^0.
|
|
33
|
-
"@happyvertical/files": "^0.
|
|
34
|
-
"@happyvertical/logger": "^0.
|
|
35
|
-
"@happyvertical/smrt-agents": "0.53.
|
|
36
|
-
"@happyvertical/smrt-app-runtime": "0.53.
|
|
37
|
-
"@happyvertical/smrt-config": "0.53.
|
|
38
|
-
"@happyvertical/smrt-core": "0.53.
|
|
39
|
-
"@happyvertical/smrt-dev-mcp": "0.53.
|
|
40
|
-
"@happyvertical/smrt-ledgers": "0.53.
|
|
41
|
-
"@happyvertical/smrt-playground": "0.53.
|
|
42
|
-
"@happyvertical/smrt-types": "0.53.
|
|
43
|
-
"@happyvertical/smrt-users": "0.53.
|
|
44
|
-
"@happyvertical/sql": "^0.
|
|
45
|
-
"@happyvertical/utils": "^0.
|
|
32
|
+
"@happyvertical/ai": "^0.100.3",
|
|
33
|
+
"@happyvertical/files": "^0.100.3",
|
|
34
|
+
"@happyvertical/logger": "^0.100.3",
|
|
35
|
+
"@happyvertical/smrt-agents": "0.53.6",
|
|
36
|
+
"@happyvertical/smrt-app-runtime": "0.53.6",
|
|
37
|
+
"@happyvertical/smrt-config": "0.53.6",
|
|
38
|
+
"@happyvertical/smrt-core": "0.53.6",
|
|
39
|
+
"@happyvertical/smrt-dev-mcp": "0.53.6",
|
|
40
|
+
"@happyvertical/smrt-ledgers": "0.53.6",
|
|
41
|
+
"@happyvertical/smrt-playground": "0.53.6",
|
|
42
|
+
"@happyvertical/smrt-types": "0.53.6",
|
|
43
|
+
"@happyvertical/smrt-users": "0.53.6",
|
|
44
|
+
"@happyvertical/sql": "^0.100.3",
|
|
45
|
+
"@happyvertical/utils": "^0.100.3",
|
|
46
46
|
"acorn": "^8.18.0",
|
|
47
47
|
"fast-glob": "3.3.3",
|
|
48
48
|
"tar": "^7.5.22",
|