@objectstack/cloud-connection 9.11.0 → 10.2.0

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/index.cjs CHANGED
@@ -561,14 +561,26 @@ var ConnectionCredentialStore = class {
561
561
 
562
562
  // src/marketplace-install-local-plugin.ts
563
563
  var ROUTE_BASE = "/api/v1/marketplace/install-local";
564
+ function manifestIdOf(p) {
565
+ return p?.manifest?.id ?? p?.id ?? p?.manifest?.name ?? void 0;
566
+ }
564
567
  var MarketplaceInstallLocalPlugin = class {
565
568
  constructor(config = {}) {
566
569
  this.name = "com.objectstack.runtime.marketplace-install-local";
567
570
  this.version = "1.0.0";
571
+ /**
572
+ * Manifest ids already present in the engine registry at `kernel:ready`,
573
+ * BEFORE this plugin rehydrates its own ledger. These are genuine
574
+ * user/config-defined apps (AppPlugin from objectstack.config.ts). Used by
575
+ * findConflict to tell real local code apart from an orphaned marketplace
576
+ * install whose ledger entry went missing.
577
+ */
578
+ this.bootUserCodeIds = /* @__PURE__ */ new Set();
568
579
  this.init = async (_ctx) => {
569
580
  };
570
581
  this.start = async (ctx) => {
571
582
  ctx.hook("kernel:ready", async () => {
583
+ this.captureBootUserCodeIds(ctx);
572
584
  try {
573
585
  const manifest = ctx.getService("manifest");
574
586
  manifest?.register?.(MARKETPLACE_INSTALLED_UI_BUNDLE);
@@ -866,17 +878,35 @@ var MarketplaceInstallLocalPlugin = class {
866
878
  if (this.ledger.has(manifestId)) {
867
879
  return "marketplace";
868
880
  }
881
+ if (this.bootUserCodeIds.has(manifestId)) {
882
+ return "user-code";
883
+ }
869
884
  try {
870
885
  const ql = ctx.getService("objectql");
871
886
  const packages = ql?.registry?.getAllPackages?.() ?? [];
872
- const hit = packages.find(
873
- (p) => (p?.manifest?.id ?? p?.id ?? p?.manifest?.name) === manifestId
874
- );
875
- if (hit) return "user-code";
887
+ if (packages.some((p) => manifestIdOf(p) === manifestId)) {
888
+ return "marketplace";
889
+ }
876
890
  } catch {
877
891
  }
878
892
  return "none";
879
893
  };
894
+ /**
895
+ * Record the manifest ids the engine registry already holds, called once at
896
+ * `kernel:ready` before rehydrate. Best-effort: a missing/empty registry
897
+ * just yields an empty snapshot (every later install is treated as fresh).
898
+ */
899
+ this.captureBootUserCodeIds = (ctx) => {
900
+ try {
901
+ const ql = ctx.getService("objectql");
902
+ const packages = ql?.registry?.getAllPackages?.() ?? [];
903
+ for (const p of packages) {
904
+ const id = manifestIdOf(p);
905
+ if (id) this.bootUserCodeIds.add(id);
906
+ }
907
+ } catch {
908
+ }
909
+ };
880
910
  /**
881
911
  * Pull a userId out of the request's better-auth session, if any.
882
912
  * Returns null when there is no signed-in user. v1 does not check
@@ -922,6 +952,20 @@ var MarketplaceInstallLocalPlugin = class {
922
952
  }
923
953
  }, 400);
924
954
  }
955
+ const inserted = summary.seeded.inserted ?? 0;
956
+ const updated = summary.seeded.updated ?? 0;
957
+ const errors = summary.seeded.errors ?? 0;
958
+ const wrote = inserted + updated > 0;
959
+ if (!wrote) {
960
+ return c.json({
961
+ success: false,
962
+ error: {
963
+ code: "reseed_no_rows",
964
+ message: errors > 0 ? `Reseed wrote no rows (${errors} error${errors === 1 ? "" : "s"}).${summary.seeded.errorSample ? ` First error: ${summary.seeded.errorSample}` : ""}` : "Reseed wrote no rows. The package declares no seedable records for this runtime.",
965
+ details: { inserted, updated, errors }
966
+ }
967
+ }, 422);
968
+ }
925
969
  try {
926
970
  entry.withSampleData = true;
927
971
  this.ledger.write(entry);
@@ -931,9 +975,9 @@ var MarketplaceInstallLocalPlugin = class {
931
975
  success: true,
932
976
  data: {
933
977
  manifestId,
934
- inserted: summary.seeded.inserted ?? 0,
935
- updated: summary.seeded.updated ?? 0,
936
- errors: summary.seeded.errors ?? 0,
978
+ inserted,
979
+ updated,
980
+ errors,
937
981
  withSampleData: true
938
982
  }
939
983
  }, 200);
@@ -1146,7 +1190,12 @@ var MarketplaceInstallLocalPlugin = class {
1146
1190
  mode: "inline",
1147
1191
  inserted: result.summary.totalInserted,
1148
1192
  updated: result.summary.totalUpdated,
1149
- errors: result.errors.length
1193
+ errors: result.errors.length,
1194
+ // Surface the first write/resolution failure so the
1195
+ // caller can report WHY nothing landed (e.g. a locked
1196
+ // DB, a missing table, a failed validation) instead of
1197
+ // a bare "0 rows".
1198
+ errorSample: result.errors[0]?.message
1150
1199
  };
1151
1200
  ctx.logger?.info?.(`[MarketplaceInstallLocal] inline seed for ${appId}${organizationId ? ` (org=${organizationId})` : ""}: inserted=${seedSummary.inserted} updated=${seedSummary.updated} errors=${seedSummary.errors}`);
1152
1201
  }