@happyvertical/smrt-cli 0.53.4 → 0.53.5

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 (64) hide show
  1. package/AGENTS.md +2 -0
  2. package/README.md +24 -0
  3. package/agents/app-commands.md +28 -3
  4. package/dist/{ApiKey-BZmbOTnL-DPPF6Swn.js → ApiKey-BZmbOTnL-BbZupUZ3.js} +2 -2
  5. package/dist/ApiKeyCollection-Bfb_nw81-DYAZwx0O.js +87 -0
  6. package/dist/AuditLogCollection-B1YonCAP-Bkj2Ezon.js +193 -0
  7. package/dist/{NostrIdentity-n70E0vck-D60BSg6H.js → NostrIdentity-n70E0vck-Di3_eNCq.js} +4 -4
  8. package/dist/NostrIdentityCollection-Ca74dkaL-DvjOg9Xy.js +127 -0
  9. package/dist/{OidcIdentity-Cb1bxreM-B2eV2ahq.js → OidcIdentity-Cb1bxreM-LXmC7uAf.js} +2 -2
  10. package/dist/OidcIdentityCollection-TV8VdK69-Cv1ZTeuk.js +86 -0
  11. package/dist/ProfileAssetCollection-B9hacUJa-CPuaWLk4.js +101 -0
  12. package/dist/{ProfileCollection-DuJT7Mum-B3Uhqphs.js → ProfileCollection-DuJT7Mum-nXbHrPpX.js} +31 -31
  13. package/dist/ProfileLinkCollection-4uNURz32-CbKZYmYm.js +233 -0
  14. package/dist/ProfileMetadataCollection-DQhbfEfa-_1rQCLTR.js +108 -0
  15. package/dist/ProfileMetafieldCollection-CoBuM_5G-CPjW3l5r.js +145 -0
  16. package/dist/ProfileRelationshipCollection-DUVgaIqf-RCDqYz6O.js +161 -0
  17. package/dist/ProfileRelationshipTermCollection-DtA9OM23-BoGhQBSQ.js +107 -0
  18. package/dist/{ProfileRelationshipType-BRiRka6t-Ci-qvFhm.js → ProfileRelationshipType-BRiRka6t-Dezjv5jP.js} +1 -1
  19. package/dist/ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js +57 -0
  20. package/dist/app/cli.d.ts +7 -0
  21. package/dist/app/cli.d.ts.map +1 -1
  22. package/dist/app/errors.d.ts +34 -1
  23. package/dist/app/errors.d.ts.map +1 -1
  24. package/dist/app/index.d.ts +4 -3
  25. package/dist/app/index.d.ts.map +1 -1
  26. package/dist/app/launchers.d.ts +11 -0
  27. package/dist/app/launchers.d.ts.map +1 -1
  28. package/dist/app/operations.d.ts +2 -0
  29. package/dist/app/operations.d.ts.map +1 -1
  30. package/dist/app/runtime.d.ts +17 -2
  31. package/dist/app/runtime.d.ts.map +1 -1
  32. package/dist/app/tokens.d.ts +21 -0
  33. package/dist/app/tokens.d.ts.map +1 -0
  34. package/dist/app.js +3 -3
  35. package/dist/{cli-BRFsobey.js → cli-OZsH5cdL.js} +403 -76
  36. package/dist/cli-generator.d.ts.map +1 -1
  37. package/dist/commands/init.d.ts.map +1 -1
  38. package/dist/commands/utilities.d.ts.map +1 -1
  39. package/dist/{commands-dFz1e9A6.js → commands-UXK2F_0j.js} +35 -51
  40. package/dist/database-environment-D_Gk1Brf.js +20 -0
  41. package/dist/database-environment.d.ts +43 -0
  42. package/dist/database-environment.d.ts.map +1 -0
  43. package/dist/dist-BVjJWjT-.js +20 -0
  44. package/dist/{dist-EJ63xUEp.js → dist-C87Ib9Vx.js} +2 -2
  45. package/dist/{dist-C2BqYVu7.js → dist-DLw_E34G.js} +1654 -1748
  46. package/dist/{dist-Berwe80z.js → dist-GIaWaUho.js} +4 -4
  47. package/dist/{dist-D4BNILLN.js → dist-RSE5hCY4.js} +3 -3
  48. package/dist/index.js +15 -10
  49. package/dist/{oidcProvisioningPrimitives-D9OYu5-F-B-kYsBTM.js → oidcProvisioningPrimitives-D9OYu5-F-T9KkkDCd.js} +5 -5
  50. package/dist/{portability-DmQWSSXA.js → portability-CES1YC2m.js} +1 -1
  51. package/dist/resolveIdentity-B-PK6RwU-C9ogf8YG.js +269 -0
  52. package/package.json +15 -15
  53. package/dist/ApiKeyCollection-Bfb_nw81-B1-2YKj8.js +0 -2
  54. package/dist/AuditLogCollection-B1YonCAP-DP4PCCw-.js +0 -2
  55. package/dist/NostrIdentityCollection-Ca74dkaL-C-v57o9N.js +0 -2
  56. package/dist/OidcIdentityCollection-TV8VdK69-BodvOtPJ.js +0 -2
  57. package/dist/ProfileAssetCollection-B9hacUJa-B7PLe0ld.js +0 -2
  58. package/dist/ProfileLinkCollection-4uNURz32-CLY1cBnn.js +0 -2
  59. package/dist/ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js +0 -2
  60. package/dist/ProfileMetafieldCollection-CoBuM_5G-D-VqQuY1.js +0 -2
  61. package/dist/ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js +0 -2
  62. package/dist/ProfileRelationshipTermCollection-DtA9OM23-DI_awdol.js +0 -2
  63. package/dist/ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js +0 -2
  64. package/dist/resolveIdentity-B-PK6RwU-BmAU1Kse.js +0 -2
@@ -0,0 +1,101 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-C87Ib9Vx.js";
3
+ import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
4
+ import { a as getOwnedAssetsFromCollection, o as removeOwnedAssetFromCollection, t as addOwnedAssetFromCollection } from "./dist-RSE5hCY4.js";
5
+ import { SmrtJunction, SmrtObject, crossPackageRef, field, foreignKey, smrt } from "@happyvertical/smrt-core";
6
+ //#region ../profiles/dist/chunks/ProfileAssetCollection-B9hacUJa.js
7
+ var ProfileAssetCollection_B9hacUJa_exports = /* @__PURE__ */ __exportAll({
8
+ n: () => ProfileAssetCollection_exports,
9
+ r: () => ProfileAsset,
10
+ t: () => ProfileAssetCollection
11
+ });
12
+ var __defProp$1 = Object.defineProperty;
13
+ var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
14
+ var __decorateClass$1 = (decorators, target, key, kind) => {
15
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
16
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
17
+ if (kind && result) __defProp$1(target, key, result);
18
+ return result;
19
+ };
20
+ var ProfileAsset = class extends SmrtObject {
21
+ tenantId = null;
22
+ profileId = "";
23
+ assetId = "";
24
+ relationship = "attachment";
25
+ sortOrder = 0;
26
+ constructor(options = {}) {
27
+ super(options);
28
+ if (options.profileId) this.profileId = options.profileId;
29
+ if (options.assetId) this.assetId = options.assetId;
30
+ if (options.relationship) this.relationship = options.relationship;
31
+ if (options.sortOrder !== void 0) this.sortOrder = options.sortOrder;
32
+ if (options.tenantId !== void 0) this.tenantId = options.tenantId;
33
+ }
34
+ };
35
+ __decorateClass$1([tenantId({ nullable: true })], ProfileAsset.prototype, "tenantId", 2);
36
+ __decorateClass$1([foreignKey("Profile", {
37
+ required: true,
38
+ onDelete: "CASCADE"
39
+ })], ProfileAsset.prototype, "profileId", 2);
40
+ __decorateClass$1([crossPackageRef("@happyvertical/smrt-assets:Asset", {
41
+ required: true,
42
+ onDelete: "CASCADE"
43
+ })], ProfileAsset.prototype, "assetId", 2);
44
+ __decorateClass$1([field({ required: true })], ProfileAsset.prototype, "relationship", 2);
45
+ __decorateClass$1([field()], ProfileAsset.prototype, "sortOrder", 2);
46
+ ProfileAsset = __decorateClass$1([TenantScoped({ mode: "optional" }), smrt({
47
+ tableName: "profile_assets",
48
+ conflictColumns: [
49
+ "profile_id",
50
+ "asset_id",
51
+ "relationship"
52
+ ],
53
+ api: false,
54
+ mcp: false,
55
+ cli: false
56
+ })], ProfileAsset);
57
+ var ProfileAssetCollection_exports = /* @__PURE__ */ __exportAll$1({ ProfileAssetCollection: () => ProfileAssetCollection });
58
+ var __defProp = Object.defineProperty;
59
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
60
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value
65
+ }) : obj[key] = value;
66
+ var __decorateClass = (decorators, target, key, kind) => {
67
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
68
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
69
+ if (kind && result) __defProp(target, key, result);
70
+ return result;
71
+ };
72
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
73
+ var ProfileAssetCollection = class extends SmrtJunction {
74
+ leftField = "profileId";
75
+ rightField = "assetId";
76
+ profileCollectionPromise = null;
77
+ async getProfileCollection() {
78
+ if (!this.profileCollectionPromise) {
79
+ const { ProfileCollection } = await import("./ProfileCollection-DuJT7Mum-nXbHrPpX.js").then((n) => n.o).then((n) => n.r);
80
+ this.profileCollectionPromise = ProfileCollection.create({ db: this.db });
81
+ }
82
+ return this.profileCollectionPromise;
83
+ }
84
+ async getAssets(profileId, relationship) {
85
+ return getOwnedAssetsFromCollection(await this.getProfileCollection(), profileId, relationship);
86
+ }
87
+ async addAsset(profileId, asset, relationship = "attachment", sortOrder = 0) {
88
+ await addOwnedAssetFromCollection(await this.getProfileCollection(), "Profile", profileId, asset, relationship, sortOrder);
89
+ }
90
+ async removeAsset(profileId, assetId, relationship) {
91
+ await removeOwnedAssetFromCollection(await this.getProfileCollection(), "Profile", profileId, assetId, relationship);
92
+ }
93
+ };
94
+ __publicField(ProfileAssetCollection, "_itemClass", ProfileAsset);
95
+ ProfileAssetCollection = __decorateClass([smrt({
96
+ api: false,
97
+ mcp: false,
98
+ cli: false
99
+ })], ProfileAssetCollection);
100
+ //#endregion
101
+ export { ProfileAssetCollection as n, ProfileAssetCollection_B9hacUJa_exports as r, ProfileAsset as t };
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
- import { a as queryGlobal, i as tenantId, l as withSystemContext, n as resolvePrompt, o as queryWithGlobals, r as TenantScoped, s as getTenantId, t as definePrompt } from "./dist-EJ63xUEp.js";
3
- import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-D60BSg6H.js";
4
- import { a as getOwnedAssetsFromCollection, i as assertValidOwnedAssetSortOrder, n as assertAssetLinkable, o as removeOwnedAssetFromCollection, r as assertValidOwnedAssetRelationship, s as resolveOwnedAssetsById, t as addOwnedAssetFromCollection } from "./dist-D4BNILLN.js";
2
+ import { a as queryGlobal, i as tenantId, l as withSystemContext, n as resolvePrompt, o as queryWithGlobals, r as TenantScoped, s as getTenantId, t as definePrompt } from "./dist-C87Ib9Vx.js";
3
+ import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
4
+ import { a as getOwnedAssetsFromCollection, i as assertValidOwnedAssetSortOrder, n as assertAssetLinkable, o as removeOwnedAssetFromCollection, r as assertValidOwnedAssetRelationship, s as resolveOwnedAssetsById, t as addOwnedAssetFromCollection } from "./dist-RSE5hCY4.js";
5
5
  import { RuntimeError, SmrtCollection, SmrtObject, ValidationError, field, foreignKey, isAbortedTransactionError, oneToMany, smrt } from "@happyvertical/smrt-core";
6
6
  import { BackfillTableUnavailableError, BackfillTracker } from "@happyvertical/smrt-core/migrations";
7
7
  //#region ../profiles/dist/chunks/ProfileCollection-DuJT7Mum.js
@@ -134,7 +134,7 @@ async function coordinateOidcProvisioning(options) {
134
134
  });
135
135
  }
136
136
  async function withProvisioningLocks(db, lockKeys, callback) {
137
- const keys = [.../* @__PURE__ */ new Set([...!isPostgresDatabase(db) || typeof db.beginTransaction !== "function" ? ["adapter-transaction"] : [], ...lockKeys])].sort();
137
+ const keys = [.../* @__PURE__ */ new Set([...!isPostgresDatabase$1(db) || typeof db.beginTransaction !== "function" ? ["adapter-transaction"] : [], ...lockKeys])].sort();
138
138
  const acquire = (index) => index >= keys.length ? callback() : withProvisioningLock(db, keys[index], () => acquire(index + 1));
139
139
  return acquire(0);
140
140
  }
@@ -198,10 +198,10 @@ async function withProvisioningLock(db, lockKey, callback) {
198
198
  }
199
199
  function getDatabaseLockKey(db) {
200
200
  const url = db.url;
201
- if (isPostgresDatabase(db) && typeof db.beginTransaction !== "function" && db.client !== null && (typeof db.client === "object" || typeof db.client === "function")) return db.client;
202
- return url && !isPostgresDatabase(db) ? url : db;
201
+ if (isPostgresDatabase$1(db) && typeof db.beginTransaction !== "function" && db.client !== null && (typeof db.client === "object" || typeof db.client === "function")) return db.client;
202
+ return url && !isPostgresDatabase$1(db) ? url : db;
203
203
  }
204
- function isPostgresDatabase(db) {
204
+ function isPostgresDatabase$1(db) {
205
205
  return /^postgres(?:ql)?:/iu.test(db.url ?? "");
206
206
  }
207
207
  async function retryProvisioning(options, callback) {
@@ -430,8 +430,8 @@ var Profile = class extends SmrtObject {
430
430
  * @param value - The value to set
431
431
  */
432
432
  async addMetadata(metafieldSlug, value) {
433
- const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-CoBuM_5G-D-VqQuY1.js").then((n) => n.n);
434
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js").then((n) => n.n);
433
+ const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-CoBuM_5G-CPjW3l5r.js").then((n) => n.r).then((n) => n.n);
434
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-_1rQCLTR.js").then((n) => n.r).then((n) => n.n);
435
435
  const metafield = await this.resolveMetafield(await ProfileMetafieldCollection.create(this.options), metafieldSlug);
436
436
  if (!metafield) throw new Error(`Metafield '${metafieldSlug}' not found`);
437
437
  await metafield.validateValue(value);
@@ -464,7 +464,7 @@ var Profile = class extends SmrtObject {
464
464
  * @returns Object with metafield slugs as keys
465
465
  */
466
466
  async getMetadata() {
467
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js").then((n) => n.n);
467
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-_1rQCLTR.js").then((n) => n.r).then((n) => n.n);
468
468
  return await (await ProfileMetadataCollection.create(this.options)).getMetadataObject(this.id);
469
469
  }
470
470
  /**
@@ -481,8 +481,8 @@ var Profile = class extends SmrtObject {
481
481
  * @param metafieldSlug - The slug of the metafield to remove
482
482
  */
483
483
  async removeMetadata(metafieldSlug) {
484
- const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-CoBuM_5G-D-VqQuY1.js").then((n) => n.n);
485
- const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-Bzv-E4ep.js").then((n) => n.n);
484
+ const { ProfileMetafieldCollection } = await import("./ProfileMetafieldCollection-CoBuM_5G-CPjW3l5r.js").then((n) => n.r).then((n) => n.n);
485
+ const { ProfileMetadataCollection } = await import("./ProfileMetadataCollection-DQhbfEfa-_1rQCLTR.js").then((n) => n.r).then((n) => n.n);
486
486
  const metafield = await this.resolveMetafield(await ProfileMetafieldCollection.create(this.options), metafieldSlug);
487
487
  if (!metafield) throw new Error(`Metafield '${metafieldSlug}' not found`);
488
488
  const existing = await (await ProfileMetadataCollection.create(this.options)).list({
@@ -507,7 +507,7 @@ var Profile = class extends SmrtObject {
507
507
  return candidates.find((candidate) => ownerTenantId && candidate.tenantId === ownerTenantId) ?? candidates.find((candidate) => !candidate.tenantId) ?? null;
508
508
  }
509
509
  async getProfileLinkCollection() {
510
- const { ProfileLinkCollection } = await import("./ProfileLinkCollection-4uNURz32-CLY1cBnn.js").then((n) => n.r);
510
+ const { ProfileLinkCollection } = await import("./ProfileLinkCollection-4uNURz32-CbKZYmYm.js").then((n) => n.i).then((n) => n.r);
511
511
  return ProfileLinkCollection.create({ db: this.db });
512
512
  }
513
513
  /** This profile's web links in display order. */
@@ -524,7 +524,7 @@ var Profile = class extends SmrtObject {
524
524
  return (await this.getProfileLinkCollection()).replaceForProfile(this.id, links);
525
525
  }
526
526
  async getProfileAssetCollection() {
527
- const { ProfileAssetCollection } = await import("./ProfileAssetCollection-B9hacUJa-B7PLe0ld.js").then((n) => n.n);
527
+ const { ProfileAssetCollection } = await import("./ProfileAssetCollection-B9hacUJa-CPuaWLk4.js").then((n) => n.r).then((n) => n.n);
528
528
  return ProfileAssetCollection.create({ db: this.db });
529
529
  }
530
530
  async getAssets(relationship) {
@@ -555,9 +555,9 @@ var Profile = class extends SmrtObject {
555
555
  * @param contextProfile - Optional context profile for tertiary relationships
556
556
  */
557
557
  async addRelationship(toProfile, relationshipSlug, contextProfile) {
558
- const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js").then((n) => n.n);
559
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js").then((n) => n.n);
560
- const { ProfileRelationshipType } = await import("./ProfileRelationshipType-BRiRka6t-Ci-qvFhm.js").then((n) => n.n).then((n) => n.n);
558
+ const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js").then((n) => n.n).then((n) => n.n);
559
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-RCDqYz6O.js").then((n) => n.r).then((n) => n.n);
560
+ const { ProfileRelationshipType } = await import("./ProfileRelationshipType-BRiRka6t-Dezjv5jP.js").then((n) => n.n).then((n) => n.n);
561
561
  const relationshipType = await (await ProfileRelationshipTypeCollection.create(this.options)).getBySlug(relationshipSlug);
562
562
  if (!relationshipType) throw new Error(`Relationship type '${relationshipSlug}' not found`);
563
563
  const relationshipCollection = await ProfileRelationshipCollection.create(this.options);
@@ -581,8 +581,8 @@ var Profile = class extends SmrtObject {
581
581
  * @returns Array of ProfileRelationship instances
582
582
  */
583
583
  async getRelationships(options) {
584
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js").then((n) => n.n);
585
- const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js").then((n) => n.n);
584
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-RCDqYz6O.js").then((n) => n.r).then((n) => n.n);
585
+ const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js").then((n) => n.n).then((n) => n.n);
586
586
  const relationshipCollection = await ProfileRelationshipCollection.create(this.options);
587
587
  const direction = options?.direction || "all";
588
588
  let typeId;
@@ -625,8 +625,8 @@ var Profile = class extends SmrtObject {
625
625
  * @param relationshipSlug - The type of relationship to remove
626
626
  */
627
627
  async removeRelationship(toProfile, relationshipSlug) {
628
- const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-CaQMLH9f.js").then((n) => n.n);
629
- const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-gEkDBmkh.js").then((n) => n.n);
628
+ const { ProfileRelationshipTypeCollection } = await import("./ProfileRelationshipTypeCollection-BdXwd7Kf-HoTmV1q-.js").then((n) => n.n).then((n) => n.n);
629
+ const { ProfileRelationshipCollection } = await import("./ProfileRelationshipCollection-DUVgaIqf-RCDqYz6O.js").then((n) => n.r).then((n) => n.n);
630
630
  const relationshipType = await (await ProfileRelationshipTypeCollection.create(this.options)).getBySlug(relationshipSlug);
631
631
  if (!relationshipType) throw new Error(`Relationship type '${relationshipSlug}' not found`);
632
632
  const relationshipCollection = await ProfileRelationshipCollection.create(this.options);
@@ -719,7 +719,7 @@ var Profile = class extends SmrtObject {
719
719
  * @returns Array of API keys
720
720
  */
721
721
  async getApiKeys() {
722
- const { ApiKeyCollection } = await import("./ApiKeyCollection-Bfb_nw81-B1-2YKj8.js").then((n) => n.n);
722
+ const { ApiKeyCollection } = await import("./ApiKeyCollection-Bfb_nw81-DYAZwx0O.js").then((n) => n.n).then((n) => n.n);
723
723
  return await (await ApiKeyCollection.create(this.options)).findByProfile(this.id);
724
724
  }
725
725
  /**
@@ -728,7 +728,7 @@ var Profile = class extends SmrtObject {
728
728
  * @returns Array of active API keys
729
729
  */
730
730
  async getActiveApiKeys() {
731
- const { ApiKeyCollection } = await import("./ApiKeyCollection-Bfb_nw81-B1-2YKj8.js").then((n) => n.n);
731
+ const { ApiKeyCollection } = await import("./ApiKeyCollection-Bfb_nw81-DYAZwx0O.js").then((n) => n.n).then((n) => n.n);
732
732
  return await (await ApiKeyCollection.create(this.options)).findActiveByProfile(this.id);
733
733
  }
734
734
  /**
@@ -738,7 +738,7 @@ var Profile = class extends SmrtObject {
738
738
  * @returns The generated key (plaintext) and ApiKey record
739
739
  */
740
740
  async generateApiKey(options) {
741
- const { ApiKey } = await import("./ApiKey-BZmbOTnL-DPPF6Swn.js").then((n) => n.n).then((n) => n.n);
741
+ const { ApiKey } = await import("./ApiKey-BZmbOTnL-BbZupUZ3.js").then((n) => n.n).then((n) => n.n);
742
742
  return await ApiKey.generate(this, {
743
743
  ...options,
744
744
  db: this.options?.db
@@ -750,7 +750,7 @@ var Profile = class extends SmrtObject {
750
750
  * @returns Array of OIDC identity records
751
751
  */
752
752
  async getOidcIdentities() {
753
- const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-BodvOtPJ.js").then((n) => n.r);
753
+ const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-Cv1ZTeuk.js").then((n) => n.r).then((n) => n.r);
754
754
  return await (await OidcIdentityCollection.create(this.options)).findByProfile(this.id);
755
755
  }
756
756
  /**
@@ -763,7 +763,7 @@ var Profile = class extends SmrtObject {
763
763
  * type, but refuses to create or rebind authority.
764
764
  */
765
765
  async linkOidcIdentity(oidcData) {
766
- const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-BodvOtPJ.js").then((n) => n.r);
766
+ const { OidcIdentityCollection } = await import("./OidcIdentityCollection-TV8VdK69-Cv1ZTeuk.js").then((n) => n.r).then((n) => n.r);
767
767
  return await (await OidcIdentityCollection.create(this.options)).linkToProfile(this, oidcData);
768
768
  }
769
769
  /**
@@ -772,7 +772,7 @@ var Profile = class extends SmrtObject {
772
772
  * @returns Array of Nostr identity records
773
773
  */
774
774
  async getNostrIdentities() {
775
- const { NostrIdentityCollection } = await import("./NostrIdentityCollection-Ca74dkaL-C-v57o9N.js").then((n) => n.n);
775
+ const { NostrIdentityCollection } = await import("./NostrIdentityCollection-Ca74dkaL-DvjOg9Xy.js").then((n) => n.n).then((n) => n.n);
776
776
  return await (await NostrIdentityCollection.create(this.options)).findByProfile(this.id);
777
777
  }
778
778
  /**
@@ -782,7 +782,7 @@ var Profile = class extends SmrtObject {
782
782
  * @returns The linked Nostr identity record
783
783
  */
784
784
  async linkNostrIdentity(nostrData) {
785
- const { NostrIdentityCollection } = await import("./NostrIdentityCollection-Ca74dkaL-C-v57o9N.js").then((n) => n.n);
785
+ const { NostrIdentityCollection } = await import("./NostrIdentityCollection-Ca74dkaL-DvjOg9Xy.js").then((n) => n.n).then((n) => n.n);
786
786
  return await (await NostrIdentityCollection.create(this.options)).linkToProfile(this, nostrData);
787
787
  }
788
788
  /**
@@ -792,7 +792,7 @@ var Profile = class extends SmrtObject {
792
792
  * @returns Array of audit log entries
793
793
  */
794
794
  async getAuditLogs(limit = 50) {
795
- const { AuditLogCollection } = await import("./AuditLogCollection-B1YonCAP-DP4PCCw-.js").then((n) => n.n);
795
+ const { AuditLogCollection } = await import("./AuditLogCollection-B1YonCAP-Bkj2Ezon.js").then((n) => n.r).then((n) => n.n);
796
796
  return await (await AuditLogCollection.create(this.options)).getRecentActivity(this.id, limit);
797
797
  }
798
798
  /**
@@ -802,7 +802,7 @@ var Profile = class extends SmrtObject {
802
802
  * @returns The created audit log entry
803
803
  */
804
804
  async recordAction(options) {
805
- const { AuditLogCollection } = await import("./AuditLogCollection-B1YonCAP-DP4PCCw-.js").then((n) => n.n);
805
+ const { AuditLogCollection } = await import("./AuditLogCollection-B1YonCAP-Bkj2Ezon.js").then((n) => n.r).then((n) => n.n);
806
806
  return await (await AuditLogCollection.create(this.options)).record({
807
807
  profile: this,
808
808
  ...options
@@ -1165,4 +1165,4 @@ function readRequiredString(row, key) {
1165
1165
  return value;
1166
1166
  }
1167
1167
  //#endregion
1168
- export { coordinateOidcProvisioning as a, saveOidcRaceArbiter as c, ProfileType as i, ProfileCollection as n, isOidcProvisioningRaceConflict as o, ProfileCollection_DuJT7Mum_exports as r, normalizeIdentityEmail as s, Profile as t };
1168
+ export { ProfileCollection as a, coordinateOidcProvisioning as c, promptMessageOptions as d, saveOidcRaceArbiter as f, Profile as i, isOidcProvisioningRaceConflict as l, OidcProfileEmailReservation as n, ProfileCollection_DuJT7Mum_exports as o, smrtProfilesGenerateBioPrompt as p, OidcProfileEmailReservationCollection as r, ProfileType as s, CanonicalPersonProfileError as t, normalizeIdentityEmail as u };
@@ -0,0 +1,233 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-C87Ib9Vx.js";
3
+ import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
4
+ import { SmrtCollection, SmrtObject, field, foreignKey, isEmbeddedDatabase, smrt, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
5
+ //#region ../profiles/dist/chunks/ProfileLinkCollection-4uNURz32.js
6
+ var ProfileLinkCollection_4uNURz32_exports = /* @__PURE__ */ __exportAll({
7
+ a: () => PROFILE_LINK_MAX_URL_LENGTH,
8
+ c: () => isProfileLinkPlatform,
9
+ i: () => 200,
10
+ l: () => normalizeProfileLinkUrl,
11
+ n: () => ProfileLinkCollection,
12
+ o: () => PROFILE_LINK_PLATFORMS,
13
+ r: () => ProfileLinkCollection_exports,
14
+ s: () => ProfileLink,
15
+ t: () => 50
16
+ });
17
+ var __defProp = Object.defineProperty;
18
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
19
+ var __decorateClass = (decorators, target, key, kind) => {
20
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
21
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
22
+ if (kind && result) __defProp(target, key, result);
23
+ return result;
24
+ };
25
+ var PROFILE_LINK_PLATFORMS = [
26
+ "facebook",
27
+ "instagram",
28
+ "x",
29
+ "linkedin",
30
+ "youtube",
31
+ "tiktok",
32
+ "website",
33
+ "other"
34
+ ];
35
+ function isProfileLinkPlatform(value) {
36
+ return typeof value === "string" && PROFILE_LINK_PLATFORMS.includes(value);
37
+ }
38
+ function normalizeProfileLinkUrl(raw) {
39
+ const text = String(raw ?? "").trim();
40
+ if (!text) throw new Error("A profile link needs a web address");
41
+ if (text.length > 2048 || /\s/.test(text)) throw new Error("A profile link must be a single web address");
42
+ let url;
43
+ try {
44
+ url = new URL(text);
45
+ } catch {
46
+ throw new Error(`Not a web address: ${text}`);
47
+ }
48
+ if (url.protocol !== "https:" && url.protocol !== "http:") throw new Error("A profile link must start with http:// or https://");
49
+ if (url.username || url.password) throw new Error("A profile link cannot carry a user name or password");
50
+ if (!url.hostname) throw new Error(`Not a web address: ${text}`);
51
+ return url.toString();
52
+ }
53
+ var ProfileLink = class extends SmrtObject {
54
+ tenantId = null;
55
+ profileId = "";
56
+ platform = "website";
57
+ url = "";
58
+ label = null;
59
+ sortOrder = 0;
60
+ constructor(options = {}) {
61
+ super(options);
62
+ if (options.profileId) this.profileId = options.profileId;
63
+ if (options.platform) this.platform = options.platform;
64
+ if (options.url) this.url = options.url;
65
+ if (options.label !== void 0) this.label = options.label;
66
+ if (options.sortOrder !== void 0) this.sortOrder = options.sortOrder;
67
+ if (options.tenantId !== void 0) this.tenantId = options.tenantId;
68
+ }
69
+ /**
70
+ * A link's address and label are not its identity: two people can link the
71
+ * same page, and one person can relabel a link. Without an explicit slug
72
+ * the default (label-derived) slug would make a new link adopt another row
73
+ * through the (tenant, slug, context) natural key, so a link's default slug
74
+ * is its id.
75
+ */
76
+ async getSlug() {
77
+ if (!this.slug && this.id) this.slug = String(this.id);
78
+ return super.getSlug();
79
+ }
80
+ /** Validates and normalizes the link before it is written. */
81
+ async save(...args) {
82
+ if (!this.profileId) throw new Error("A profile link needs a profile");
83
+ if (!isProfileLinkPlatform(this.platform)) throw new Error(`Unknown profile link platform: ${this.platform}`);
84
+ this.url = normalizeProfileLinkUrl(this.url);
85
+ const label = this.label?.trim() ?? "";
86
+ if (label.length > 200) throw new Error("A profile link label is too long");
87
+ this.label = label || null;
88
+ if (!Number.isInteger(this.sortOrder) || this.sortOrder < 0) throw new Error("A profile link sortOrder must be a whole number ≥ 0");
89
+ return super.save(...args);
90
+ }
91
+ };
92
+ __decorateClass([tenantId({ nullable: true })], ProfileLink.prototype, "tenantId", 2);
93
+ __decorateClass([foreignKey("Profile", {
94
+ required: true,
95
+ onDelete: "CASCADE"
96
+ })], ProfileLink.prototype, "profileId", 2);
97
+ __decorateClass([field({
98
+ required: true,
99
+ maxLength: 32
100
+ })], ProfileLink.prototype, "platform", 2);
101
+ __decorateClass([field({
102
+ required: true,
103
+ maxLength: 2048
104
+ })], ProfileLink.prototype, "url", 2);
105
+ __decorateClass([field({
106
+ nullable: true,
107
+ maxLength: 200
108
+ })], ProfileLink.prototype, "label", 2);
109
+ __decorateClass([field()], ProfileLink.prototype, "sortOrder", 2);
110
+ ProfileLink = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
111
+ tableName: "profile_links",
112
+ api: false,
113
+ mcp: false,
114
+ cli: false
115
+ })], ProfileLink);
116
+ var ProfileLinkCollection_exports = /* @__PURE__ */ __exportAll$1({
117
+ PROFILE_LINK_LIMIT: () => 50,
118
+ ProfileLinkCollection: () => ProfileLinkCollection
119
+ });
120
+ var ProfileLinkCollection = class ProfileLinkCollection extends SmrtCollection {
121
+ static _itemClass = ProfileLink;
122
+ /** The profile's links in display order (sortOrder, then age). */
123
+ async listForProfile(profileId) {
124
+ if (!profileId) return [];
125
+ return (await this.list({ where: { profileId } })).sort(compareLinks);
126
+ }
127
+ /**
128
+ * Makes the profile's links exactly `links`, in that order, in one
129
+ * transaction: a link whose address is already on the profile keeps its row
130
+ * (and id), new addresses are added, and links left out are removed. The
131
+ * same address given twice is kept once, at its first position. New links
132
+ * take the profile's tenant. Throws, changing nothing, when the profile is
133
+ * not visible in the current tenant context or a link is invalid.
134
+ */
135
+ async replaceForProfile(profileId, links) {
136
+ const wanted = normalizeInputs(links);
137
+ return this.inTransaction(async (bound) => {
138
+ const tenantId = await bound.requireProfileTenant(profileId);
139
+ const existing = await bound.listForProfile(profileId);
140
+ const byUrl = /* @__PURE__ */ new Map();
141
+ for (const link of existing) if (!byUrl.has(link.url)) byUrl.set(link.url, link);
142
+ const kept = /* @__PURE__ */ new Set();
143
+ const result = [];
144
+ for (const [index, input] of wanted.entries()) {
145
+ const current = byUrl.get(input.url);
146
+ if (current) {
147
+ kept.add(current);
148
+ const changed = current.platform !== input.platform || (current.label ?? null) !== input.label || current.sortOrder !== index || !current.tenantId && tenantId !== null;
149
+ current.platform = input.platform;
150
+ current.label = input.label;
151
+ current.sortOrder = index;
152
+ if (!current.tenantId && tenantId) current.tenantId = tenantId;
153
+ if (changed) await current.save();
154
+ result.push(current);
155
+ continue;
156
+ }
157
+ const created = await bound.create({
158
+ profileId,
159
+ platform: input.platform,
160
+ url: input.url,
161
+ label: input.label,
162
+ sortOrder: index,
163
+ ...tenantId ? { tenantId } : {}
164
+ });
165
+ result.push(created);
166
+ }
167
+ for (const link of existing) if (!kept.has(link)) await link.delete();
168
+ return result;
169
+ });
170
+ }
171
+ /**
172
+ * Puts the profile's links in the order of `linkIds`, which must name every
173
+ * link on the profile exactly once. One transaction; throws, changing
174
+ * nothing, on a missing, extra or repeated id.
175
+ */
176
+ async reorder(profileId, linkIds) {
177
+ return this.inTransaction(async (bound) => {
178
+ await bound.requireProfileTenant(profileId);
179
+ const existing = await bound.listForProfile(profileId);
180
+ const byId = new Map(existing.map((link) => [String(link.id), link]));
181
+ const ids = linkIds.map(String);
182
+ if (ids.length !== existing.length || new Set(ids).size !== ids.length || ids.some((id) => !byId.has(id))) throw new Error("Reorder must list every link on the profile exactly once");
183
+ const ordered = [];
184
+ for (const [index, id] of ids.entries()) {
185
+ const link = byId.get(id);
186
+ if (link.sortOrder !== index) {
187
+ link.sortOrder = index;
188
+ await link.save();
189
+ }
190
+ ordered.push(link);
191
+ }
192
+ return ordered;
193
+ });
194
+ }
195
+ /** The profile's tenant; throws when the profile is not visible here. */
196
+ async requireProfileTenant(profileId) {
197
+ if (!profileId) throw new Error("A profile link needs a profile");
198
+ const { ProfileCollection } = await import("./ProfileCollection-DuJT7Mum-nXbHrPpX.js").then((n) => n.o).then((n) => n.r);
199
+ const profile = await (await ProfileCollection.create({ db: this.db })).get({ id: profileId });
200
+ if (!profile) throw new Error(`Profile '${profileId}' not found`);
201
+ return profile.tenantId ?? null;
202
+ }
203
+ async inTransaction(work) {
204
+ const db = this.db;
205
+ return withEmbeddedWriteTransaction(db, isEmbeddedDatabase(db), async (transaction) => work(await ProfileLinkCollection.create({ db: transaction })));
206
+ }
207
+ };
208
+ function compareLinks(a, b) {
209
+ if (a.sortOrder !== b.sortOrder) return a.sortOrder - b.sortOrder;
210
+ const aTime = new Date(a.created_at ?? 0).getTime();
211
+ const bTime = new Date(b.created_at ?? 0).getTime();
212
+ if (aTime !== bTime) return aTime - bTime;
213
+ return String(a.id).localeCompare(String(b.id));
214
+ }
215
+ function normalizeInputs(links) {
216
+ if (links.length > 50) throw new Error(`A profile can hold at most 50 links (got ${links.length})`);
217
+ const seen = /* @__PURE__ */ new Set();
218
+ const out = [];
219
+ for (const link of links) {
220
+ if (!isProfileLinkPlatform(link.platform)) throw new Error(`Unknown profile link platform: ${link.platform}`);
221
+ const url = normalizeProfileLinkUrl(link.url);
222
+ if (seen.has(url)) continue;
223
+ seen.add(url);
224
+ out.push({
225
+ platform: link.platform,
226
+ url,
227
+ label: link.label?.trim() ? link.label.trim() : null
228
+ });
229
+ }
230
+ return out;
231
+ }
232
+ //#endregion
233
+ export { isProfileLinkPlatform as a, ProfileLinkCollection_4uNURz32_exports as i, ProfileLink as n, normalizeProfileLinkUrl as o, ProfileLinkCollection as r, PROFILE_LINK_PLATFORMS as t };
@@ -0,0 +1,108 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.js";
2
+ import { i as tenantId, r as TenantScoped } from "./dist-C87Ib9Vx.js";
3
+ import { n as __exportAll$1 } from "./NostrIdentity-n70E0vck-Di3_eNCq.js";
4
+ import { SmrtCollection, SmrtObject, field, foreignKey, smrt } from "@happyvertical/smrt-core";
5
+ //#region ../profiles/dist/chunks/ProfileMetadataCollection-DQhbfEfa.js
6
+ var ProfileMetadataCollection_DQhbfEfa_exports = /* @__PURE__ */ __exportAll({
7
+ n: () => ProfileMetadataCollection_exports,
8
+ r: () => ProfileMetadata,
9
+ t: () => ProfileMetadataCollection
10
+ });
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __decorateClass = (decorators, target, key, kind) => {
14
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
15
+ for (var i = decorators.length - 1, decorator; i >= 0; i--) if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
16
+ if (kind && result) __defProp(target, key, result);
17
+ return result;
18
+ };
19
+ var ProfileMetadata = class extends SmrtObject {
20
+ tenantId = null;
21
+ profileId;
22
+ metafieldId;
23
+ value = "";
24
+ constructor(options = {}) {
25
+ super(options);
26
+ if (options.profileId !== void 0) this.profileId = options.profileId;
27
+ if (options.metafieldId !== void 0) this.metafieldId = options.metafieldId;
28
+ if (options.value) this.value = options.value;
29
+ if (options.tenantId !== void 0) this.tenantId = options.tenantId;
30
+ }
31
+ /**
32
+ * Validate this metadata value against the metafield's validation schema
33
+ *
34
+ * @returns True if valid, throws error if invalid
35
+ */
36
+ async validate() {
37
+ const metafield = await this.loadRelated("metafieldId");
38
+ if (!metafield) throw new Error("Metafield not found");
39
+ return await metafield.validateValue(this.value);
40
+ }
41
+ /**
42
+ * Get the metafield slug for this metadata
43
+ *
44
+ * @returns The slug of the metafield
45
+ */
46
+ async getMetafieldSlug() {
47
+ return (await this.loadRelated("metafieldId"))?.slug || "";
48
+ }
49
+ };
50
+ __decorateClass([tenantId({ nullable: true })], ProfileMetadata.prototype, "tenantId", 2);
51
+ __decorateClass([foreignKey("Profile", { required: true })], ProfileMetadata.prototype, "profileId", 2);
52
+ __decorateClass([foreignKey("ProfileMetafield", { required: true })], ProfileMetadata.prototype, "metafieldId", 2);
53
+ __decorateClass([field({ required: true })], ProfileMetadata.prototype, "value", 2);
54
+ ProfileMetadata = __decorateClass([TenantScoped({ mode: "optional" }), smrt({
55
+ tableStrategy: "sti",
56
+ api: { include: [
57
+ "list",
58
+ "get",
59
+ "create",
60
+ "update",
61
+ "delete"
62
+ ] },
63
+ mcp: { include: ["list", "get"] },
64
+ cli: { skipApiCheck: true }
65
+ })], ProfileMetadata);
66
+ var ProfileMetadataCollection_exports = /* @__PURE__ */ __exportAll$1({ ProfileMetadataCollection: () => ProfileMetadataCollection });
67
+ var ProfileMetadataCollection = class extends SmrtCollection {
68
+ static _itemClass = ProfileMetadata;
69
+ /**
70
+ * Get all metadata for a profile
71
+ *
72
+ * @param profileId - The profile UUID
73
+ * @returns Array of ProfileMetadata instances
74
+ */
75
+ async getByProfile(profileId) {
76
+ return await this.list({ where: { profileId } });
77
+ }
78
+ /**
79
+ * Get metadata as key-value object for a profile
80
+ *
81
+ * @param profileId - The profile UUID
82
+ * @returns Object with metafield slugs as keys
83
+ */
84
+ async getMetadataObject(profileId) {
85
+ const metadata = await this.getByProfile(profileId);
86
+ const result = {};
87
+ for (const item of metadata) {
88
+ const slug = await item.getMetafieldSlug();
89
+ if (slug) result[slug] = item.value;
90
+ }
91
+ return result;
92
+ }
93
+ /**
94
+ * Find all profiles with a specific metadata key-value pair
95
+ *
96
+ * @param metafieldId - The metafield UUID
97
+ * @param value - The value to match
98
+ * @returns Array of profile UUIDs
99
+ */
100
+ async findProfilesByMetadata(metafieldId, value) {
101
+ return (await this.list({ where: {
102
+ metafieldId,
103
+ value: String(value)
104
+ } })).map((m) => m.profileId).filter((id) => typeof id === "string");
105
+ }
106
+ };
107
+ //#endregion
108
+ export { ProfileMetadataCollection as n, ProfileMetadataCollection_DQhbfEfa_exports as r, ProfileMetadata as t };