@kurbo/dkit 0.4.0 → 0.5.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/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command6 } from "commander";
4
+ import { Command as Command7 } from "commander";
5
5
 
6
6
  // src/commands/init.ts
7
7
  import { Command } from "commander";
@@ -186,7 +186,7 @@ var DkitProjectConfigSchema = z2.object({
186
186
  * Prefer env `DKIT_LICENSE_KEY` in CI; do not commit secrets.
187
187
  */
188
188
  licenseKey: z2.string().min(1).optional(),
189
- /** Authenticated premium registry API base (default https://api.dkit.run) */
189
+ /** Authenticated premium registry API base (default https://dkit.run/api) */
190
190
  registryApi: z2.string().url().optional(),
191
191
  tailwind: z2.boolean().default(true),
192
192
  /**
@@ -257,16 +257,16 @@ function normalizeCollectionPrefix(raw) {
257
257
  }
258
258
  var UNPREFIXED_COLLECTIONS = /* @__PURE__ */ new Set(["languages"]);
259
259
  function prefixedCollection(logicalName, prefix) {
260
- const p4 = normalizeCollectionPrefix(prefix);
261
- if (!p4)
260
+ const p5 = normalizeCollectionPrefix(prefix);
261
+ if (!p5)
262
262
  return logicalName;
263
263
  if (logicalName.startsWith("directus_"))
264
264
  return logicalName;
265
265
  if (UNPREFIXED_COLLECTIONS.has(logicalName))
266
266
  return logicalName;
267
- if (logicalName.startsWith(p4))
267
+ if (logicalName.startsWith(p5))
268
268
  return logicalName;
269
- return `${p4}${logicalName}`;
269
+ return `${p5}${logicalName}`;
270
270
  }
271
271
 
272
272
  // ../shared/dist/semver.js
@@ -286,7 +286,7 @@ function majorVersion(version2) {
286
286
  }
287
287
  function parse(version2) {
288
288
  const cleaned = version2.replace(/^v/i, "").split("-")[0] ?? "0.0.0";
289
- const parts = cleaned.split(".").map((p4) => Number.parseInt(p4, 10) || 0);
289
+ const parts = cleaned.split(".").map((p5) => Number.parseInt(p5, 10) || 0);
290
290
  return [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0];
291
291
  }
292
292
 
@@ -2594,8 +2594,8 @@ function formatDirectusPayload(err) {
2594
2594
  return null;
2595
2595
  }
2596
2596
  function isCustomPermissionRulesRestricted(err) {
2597
- const text4 = toError(err).message;
2598
- return text4.includes("custom_permission_rules_enabled") || text4.includes("RESOURCE_RESTRICTED");
2597
+ const text5 = toError(err).message;
2598
+ return text5.includes("custom_permission_rules_enabled") || text5.includes("RESOURCE_RESTRICTED");
2599
2599
  }
2600
2600
  function toCoreFlatPermission(perm) {
2601
2601
  return {
@@ -2745,7 +2745,7 @@ function isRestSchema(value) {
2745
2745
  return typeof value === "object" && value !== null && value.format === "dkit.rest";
2746
2746
  }
2747
2747
  async function applyRestSchema(client, schema, options) {
2748
- const log4 = options.onLog ?? (() => void 0);
2748
+ const log5 = options.onLog ?? (() => void 0);
2749
2749
  const lines = [];
2750
2750
  const prepared = expandRestSchemaTranslations(schema);
2751
2751
  const existing = await listCollections(client);
@@ -2769,12 +2769,12 @@ async function applyRestSchema(client, schema, options) {
2769
2769
  });
2770
2770
  for (const col of ordered) {
2771
2771
  if (existingSet.has(col.collection)) {
2772
- log4(`\u2192 Updating collection meta ${col.collection}\u2026`);
2772
+ log5(`\u2192 Updating collection meta ${col.collection}\u2026`);
2773
2773
  await updateCollectionMeta(client, col);
2774
- await upsertFields(client, col, log4, { aliases: false });
2774
+ await upsertFields(client, col, log5, { aliases: false });
2775
2775
  continue;
2776
2776
  }
2777
- log4(`\u2192 Creating collection ${col.collection}\u2026`);
2777
+ log5(`\u2192 Creating collection ${col.collection}\u2026`);
2778
2778
  const { fields, ...rest2 } = col;
2779
2779
  await http(client, {
2780
2780
  path: "/collections",
@@ -2790,11 +2790,11 @@ async function applyRestSchema(client, schema, options) {
2790
2790
  for (const rel of prepared.relations ?? []) {
2791
2791
  const key = `${rel.collection}.${rel.field}`;
2792
2792
  if (existingRelations.has(key)) {
2793
- log4(`\u2192 Updating relation meta ${key}\u2026`);
2793
+ log5(`\u2192 Updating relation meta ${key}\u2026`);
2794
2794
  await updateRelationMeta(client, rel);
2795
2795
  continue;
2796
2796
  }
2797
- log4(`\u2192 Creating relation ${rel.collection}.${rel.field}\u2026`);
2797
+ log5(`\u2192 Creating relation ${rel.collection}.${rel.field}\u2026`);
2798
2798
  await http(client, {
2799
2799
  path: "/relations",
2800
2800
  method: "POST",
@@ -2804,9 +2804,9 @@ async function applyRestSchema(client, schema, options) {
2804
2804
  for (const col of ordered) {
2805
2805
  if (!col.fields?.some(isAliasField))
2806
2806
  continue;
2807
- await upsertFields(client, col, log4, { aliases: true });
2807
+ await upsertFields(client, col, log5, { aliases: true });
2808
2808
  }
2809
- log4("\u2713 REST schema applied");
2809
+ log5("\u2713 REST schema applied");
2810
2810
  return lines;
2811
2811
  }
2812
2812
  function isAliasField(field) {
@@ -2839,7 +2839,7 @@ async function updateCollectionMeta(client, col) {
2839
2839
  body: { meta: col.meta }
2840
2840
  });
2841
2841
  }
2842
- async function upsertFields(client, col, log4, opts) {
2842
+ async function upsertFields(client, col, log5, opts) {
2843
2843
  if (!col.fields?.length)
2844
2844
  return;
2845
2845
  const existingFields = await listFieldNames(client, col.collection);
@@ -2847,7 +2847,7 @@ async function upsertFields(client, col, log4, opts) {
2847
2847
  if (isAliasField(field) !== opts.aliases)
2848
2848
  continue;
2849
2849
  if (existingFields.has(field.field)) {
2850
- log4(`\u2192 Updating field ${col.collection}.${field.field}\u2026`);
2850
+ log5(`\u2192 Updating field ${col.collection}.${field.field}\u2026`);
2851
2851
  await http(client, {
2852
2852
  path: `/fields/${col.collection}/${field.field}`,
2853
2853
  method: "PATCH",
@@ -2857,7 +2857,7 @@ async function upsertFields(client, col, log4, opts) {
2857
2857
  }
2858
2858
  });
2859
2859
  } else {
2860
- log4(`\u2192 Creating field ${col.collection}.${field.field}\u2026`);
2860
+ log5(`\u2192 Creating field ${col.collection}.${field.field}\u2026`);
2861
2861
  await http(client, {
2862
2862
  path: `/fields/${col.collection}`,
2863
2863
  method: "POST",
@@ -2909,7 +2909,7 @@ async function listRelationKeys(client) {
2909
2909
 
2910
2910
  // ../schema/dist/apply.js
2911
2911
  async function applyModule(client, url, payload, options = {}) {
2912
- const log4 = options.onLog ?? (() => void 0);
2912
+ const log5 = options.onLog ?? (() => void 0);
2913
2913
  const warnings = [];
2914
2914
  const dryRunPlan = [];
2915
2915
  const result = {
@@ -2927,39 +2927,39 @@ async function applyModule(client, url, payload, options = {}) {
2927
2927
  if (!versionInfo.supportsMergeMode) {
2928
2928
  const msg = `Directus ${versionInfo.version} lacks schema diff mode=merge (needs 12.2+). Using safer strip-deletes fallback.`;
2929
2929
  warnings.push(msg);
2930
- log4(`\u26A0 ${msg}`);
2930
+ log5(`\u26A0 ${msg}`);
2931
2931
  if (!options.dryRun && !options.confirmReducedSafety) {
2932
2932
  throw new Error(`${msg} Re-run with --yes to continue on this version.`);
2933
2933
  }
2934
2934
  } else {
2935
- log4(`\u2713 Directus ${versionInfo.version} (merge-mode schema apply)`);
2935
+ log5(`\u2713 Directus ${versionInfo.version} (merge-mode schema apply)`);
2936
2936
  }
2937
2937
  if (payload.snapshot) {
2938
2938
  if (isRestSchema(payload.snapshot)) {
2939
2939
  const lines = await applyRestSchema(client, payload.snapshot, {
2940
2940
  dryRun: options.dryRun,
2941
- onLog: log4
2941
+ onLog: log5
2942
2942
  });
2943
2943
  dryRunPlan.push(...lines);
2944
2944
  result.schemaApplied = !options.dryRun && lines.length > 0;
2945
2945
  } else {
2946
- const plan = await planAndApplySchema(client, payload.snapshot, versionInfo.supportsMergeMode, options, log4);
2946
+ const plan = await planAndApplySchema(client, payload.snapshot, versionInfo.supportsMergeMode, options, log5);
2947
2947
  dryRunPlan.push(...plan.lines);
2948
2948
  result.schemaApplied = plan.applied;
2949
2949
  }
2950
2950
  }
2951
2951
  if (payload.access) {
2952
- const plan = await applyAccess(client, payload.access, options, log4);
2952
+ const plan = await applyAccess(client, payload.access, options, log5);
2953
2953
  dryRunPlan.push(...plan.lines);
2954
2954
  result.policiesApplied = plan.applied;
2955
2955
  }
2956
2956
  if (payload.flows?.flows?.length) {
2957
- const plan = await applyFlows(client, payload.flows, options, log4);
2957
+ const plan = await applyFlows(client, payload.flows, options, log5);
2958
2958
  dryRunPlan.push(...plan.lines);
2959
2959
  result.flowsApplied = plan.applied;
2960
2960
  }
2961
2961
  if (options.seed && payload.seed && ((payload.seed.files?.length ?? 0) > 0 || Object.keys(payload.seed.items ?? {}).length > 0)) {
2962
- const plan = await applySeed(client, url, payload.seed, options, log4, singletonCollectionsFromSnapshot(payload.snapshot));
2962
+ const plan = await applySeed(client, url, payload.seed, options, log5, singletonCollectionsFromSnapshot(payload.snapshot));
2963
2963
  dryRunPlan.push(...plan.lines);
2964
2964
  result.seedApplied = plan.applied;
2965
2965
  }
@@ -2975,9 +2975,9 @@ function singletonCollectionsFromSnapshot(snapshot) {
2975
2975
  }
2976
2976
  return out;
2977
2977
  }
2978
- async function planAndApplySchema(client, snapshot, supportsMerge, options, log4) {
2978
+ async function planAndApplySchema(client, snapshot, supportsMerge, options, log5) {
2979
2979
  const lines = [];
2980
- log4("\u2192 Diffing schema\u2026");
2980
+ log5("\u2192 Diffing schema\u2026");
2981
2981
  const diffBody = await http(client, {
2982
2982
  path: "/schema/diff",
2983
2983
  method: "POST",
@@ -2991,23 +2991,23 @@ async function planAndApplySchema(client, snapshot, supportsMerge, options, log4
2991
2991
  const summary = summarizeDiff(diffPayload);
2992
2992
  if (summary.length === 0 || summary.length === 1 && summary[0] === "No schema diff") {
2993
2993
  lines.push("schema: no changes");
2994
- log4("\u2713 Schema already up to date");
2994
+ log5("\u2713 Schema already up to date");
2995
2995
  return { applied: false, lines };
2996
2996
  }
2997
2997
  lines.push(...summary.map((s) => `schema: ${s}`));
2998
2998
  if (options.dryRun)
2999
2999
  return { applied: false, lines };
3000
- log4("\u2192 Applying schema\u2026");
3000
+ log5("\u2192 Applying schema\u2026");
3001
3001
  await http(client, {
3002
3002
  path: "/schema/apply",
3003
3003
  method: "POST",
3004
3004
  params: options.forceSchema ? { force: true } : {},
3005
3005
  body: diffPayload
3006
3006
  });
3007
- log4("\u2713 Schema applied");
3007
+ log5("\u2713 Schema applied");
3008
3008
  return { applied: true, lines };
3009
3009
  }
3010
- async function applyAccess(client, access, options, log4) {
3010
+ async function applyAccess(client, access, options, log5) {
3011
3011
  const lines = [];
3012
3012
  const policies = access.policies ?? [];
3013
3013
  const permissions = access.permissions ?? [];
@@ -3025,16 +3025,16 @@ async function applyAccess(client, access, options, log4) {
3025
3025
  params: { limit: -1, fields: "id,name" }
3026
3026
  });
3027
3027
  const list = Array.isArray(existing) ? existing : existing.data ?? [];
3028
- const byName = new Map(list.map((p4) => [p4.name, p4.id]));
3028
+ const byName = new Map(list.map((p5) => [p5.name, p5.id]));
3029
3029
  const policyIds = /* @__PURE__ */ new Map();
3030
3030
  for (const policy of policies) {
3031
3031
  const existingId = byName.get(policy.name);
3032
3032
  if (existingId) {
3033
- log4(`\u2192 Reusing existing policy ${policy.name}`);
3033
+ log5(`\u2192 Reusing existing policy ${policy.name}`);
3034
3034
  policyIds.set(policy.name, existingId);
3035
3035
  continue;
3036
3036
  }
3037
- log4(`\u2192 Creating policy ${policy.name}\u2026`);
3037
+ log5(`\u2192 Creating policy ${policy.name}\u2026`);
3038
3038
  const created = await http(client, {
3039
3039
  path: "/policies",
3040
3040
  method: "POST",
@@ -3064,7 +3064,7 @@ async function applyAccess(client, access, options, log4) {
3064
3064
  } catch (err) {
3065
3065
  if (isCustomPermissionRulesRestricted(err) || permissionHasCustomRules(rest2)) {
3066
3066
  if (!warnedCoreFlat) {
3067
- log4("\u26A0 Directus Core blocks custom permission rules (row filters / field subsets). Using flat fields:['*'] \u2014 UI should filter published status. Add a Directus license for server-side filters.");
3067
+ log5("\u26A0 Directus Core blocks custom permission rules (row filters / field subsets). Using flat fields:['*'] \u2014 UI should filter published status. Add a Directus license for server-side filters.");
3068
3068
  warnedCoreFlat = true;
3069
3069
  }
3070
3070
  try {
@@ -3094,16 +3094,16 @@ async function applyAccess(client, access, options, log4) {
3094
3094
  } catch (err) {
3095
3095
  const msg = toError(err).message.toLowerCase();
3096
3096
  if (msg.includes("unique") || msg.includes("already")) {
3097
- log4(`\u2192 Access link already exists for ${row.policy}`);
3097
+ log5(`\u2192 Access link already exists for ${row.policy}`);
3098
3098
  continue;
3099
3099
  }
3100
3100
  throw toError(err, `Failed to link access for policy ${row.policy}`);
3101
3101
  }
3102
3102
  }
3103
- log4("\u2713 Access policies applied");
3103
+ log5("\u2713 Access policies applied");
3104
3104
  return { applied: true, lines };
3105
3105
  }
3106
- async function applyFlows(client, flows, options, log4) {
3106
+ async function applyFlows(client, flows, options, log5) {
3107
3107
  const lines = [];
3108
3108
  for (const flow of flows.flows ?? []) {
3109
3109
  lines.push(`flow: create ${flow.name}`);
@@ -3119,7 +3119,7 @@ async function applyFlows(client, flows, options, log4) {
3119
3119
  const byName = new Map(list.map((f) => [f.name, f.id]));
3120
3120
  for (const flow of flows.flows ?? []) {
3121
3121
  if (byName.has(flow.name)) {
3122
- log4(`\u2192 Reusing existing flow ${flow.name}`);
3122
+ log5(`\u2192 Reusing existing flow ${flow.name}`);
3123
3123
  continue;
3124
3124
  }
3125
3125
  const { id: _id, ...rest2 } = flow;
@@ -3128,10 +3128,10 @@ async function applyFlows(client, flows, options, log4) {
3128
3128
  for (const op of flows.operations ?? []) {
3129
3129
  await http(client, { path: "/operations", method: "POST", body: op });
3130
3130
  }
3131
- log4("\u2713 Flows applied");
3131
+ log5("\u2713 Flows applied");
3132
3132
  return { applied: true, lines };
3133
3133
  }
3134
- async function applySeed(client, url, seed, options, log4, singletons = /* @__PURE__ */ new Set()) {
3134
+ async function applySeed(client, url, seed, options, log5, singletons = /* @__PURE__ */ new Set()) {
3135
3135
  const lines = [];
3136
3136
  if (seed.files?.length) {
3137
3137
  lines.push(`seed: ${seed.files.length} file(s)`);
@@ -3147,9 +3147,9 @@ async function applySeed(client, url, seed, options, log4, singletons = /* @__PU
3147
3147
  const { id: actualId, created } = await upsertSeedFile(client, url, file);
3148
3148
  fileIdMap.set(file.id, actualId);
3149
3149
  if (created) {
3150
- log4(actualId === file.id ? `\u2192 Seed uploaded file ${actualId}` : `\u2192 Seed uploaded file ${file.filename_download} \u2192 ${actualId}`);
3150
+ log5(actualId === file.id ? `\u2192 Seed uploaded file ${actualId}` : `\u2192 Seed uploaded file ${file.filename_download} \u2192 ${actualId}`);
3151
3151
  } else {
3152
- log4(`\u2192 Seed reused file ${actualId}`);
3152
+ log5(`\u2192 Seed reused file ${actualId}`);
3153
3153
  }
3154
3154
  } catch (err) {
3155
3155
  throw wrapSeedError(`upload file ${file.filename_download}`, err);
@@ -3162,17 +3162,17 @@ async function applySeed(client, url, seed, options, log4, singletons = /* @__PU
3162
3162
  try {
3163
3163
  const outcome = singletons.has(collection) ? await upsertSeedSingleton(client, collection, remapped) : await upsertSeedItem(client, collection, remapped);
3164
3164
  if (outcome === "created")
3165
- log4(`\u2192 Seed created ${label}`);
3165
+ log5(`\u2192 Seed created ${label}`);
3166
3166
  else if (outcome === "updated")
3167
- log4(`\u2192 Seed updated ${label}`);
3167
+ log5(`\u2192 Seed updated ${label}`);
3168
3168
  else
3169
- log4(`\u2192 Seed skipped ${label} (already exists)`);
3169
+ log5(`\u2192 Seed skipped ${label} (already exists)`);
3170
3170
  } catch (err) {
3171
3171
  throw wrapSeedError(`upsert ${label}`, err);
3172
3172
  }
3173
3173
  }
3174
3174
  }
3175
- log4("\u2713 Seed data applied");
3175
+ log5("\u2713 Seed data applied");
3176
3176
  return { applied: true, lines };
3177
3177
  }
3178
3178
  function wrapSeedError(step, err) {
@@ -3219,8 +3219,8 @@ async function upsertSeedFile(client, url, file) {
3219
3219
  body: form
3220
3220
  });
3221
3221
  if (!res.ok) {
3222
- const text4 = await res.text();
3223
- throw new Error(`Seed file upload failed (${res.status}): ${text4}`);
3222
+ const text5 = await res.text();
3223
+ throw new Error(`Seed file upload failed (${res.status}): ${text5}`);
3224
3224
  }
3225
3225
  const payload = await res.json();
3226
3226
  const actualId = payload.data?.id ?? payload.id;
@@ -3592,10 +3592,10 @@ function isUniqueViolation(err) {
3592
3592
 
3593
3593
  // ../schema/dist/prefix.js
3594
3594
  function applyCollectionPrefixToRestSchema(schema, prefix) {
3595
- const p4 = normalizeCollectionPrefix(prefix);
3596
- if (!p4)
3595
+ const p5 = normalizeCollectionPrefix(prefix);
3596
+ if (!p5)
3597
3597
  return schema;
3598
- const rename = (name) => prefixedCollection(name, p4);
3598
+ const rename = (name) => prefixedCollection(name, p5);
3599
3599
  return {
3600
3600
  ...schema,
3601
3601
  collections: schema.collections.map((col) => ({
@@ -3625,10 +3625,10 @@ function applyCollectionPrefixToRestSchema(schema, prefix) {
3625
3625
  };
3626
3626
  }
3627
3627
  function applyCollectionPrefixToAccess(access, prefix) {
3628
- const p4 = normalizeCollectionPrefix(prefix);
3629
- if (!p4)
3628
+ const p5 = normalizeCollectionPrefix(prefix);
3629
+ if (!p5)
3630
3630
  return access;
3631
- const rename = (name) => prefixedCollection(name, p4);
3631
+ const rename = (name) => prefixedCollection(name, p5);
3632
3632
  return {
3633
3633
  ...access,
3634
3634
  permissions: (access.permissions ?? []).map((perm) => ({
@@ -3638,10 +3638,10 @@ function applyCollectionPrefixToAccess(access, prefix) {
3638
3638
  };
3639
3639
  }
3640
3640
  function applyCollectionPrefixToFlows(flows, prefix) {
3641
- const p4 = normalizeCollectionPrefix(prefix);
3642
- if (!p4)
3641
+ const p5 = normalizeCollectionPrefix(prefix);
3642
+ if (!p5)
3643
3643
  return flows;
3644
- const rename = (name) => prefixedCollection(name, p4);
3644
+ const rename = (name) => prefixedCollection(name, p5);
3645
3645
  return {
3646
3646
  ...flows,
3647
3647
  flows: (flows.flows ?? []).map((flow) => {
@@ -3654,10 +3654,10 @@ function applyCollectionPrefixToFlows(flows, prefix) {
3654
3654
  };
3655
3655
  }
3656
3656
  function applyCollectionPrefixToSeed(seed, prefix) {
3657
- const p4 = normalizeCollectionPrefix(prefix);
3658
- if (!p4)
3657
+ const p5 = normalizeCollectionPrefix(prefix);
3658
+ if (!p5)
3659
3659
  return seed;
3660
- const rename = (name) => prefixedCollection(name, p4);
3660
+ const rename = (name) => prefixedCollection(name, p5);
3661
3661
  const logicalNames = new Set(Object.keys(seed.items ?? {}));
3662
3662
  const items = {};
3663
3663
  for (const [collection, rows] of Object.entries(seed.items ?? {})) {
@@ -3685,10 +3685,10 @@ function remapSeedCollectionField(row, rename, logicalNames) {
3685
3685
  return out;
3686
3686
  }
3687
3687
  function buildCollectionMap(logicalNames, prefix) {
3688
- const p4 = normalizeCollectionPrefix(prefix);
3688
+ const p5 = normalizeCollectionPrefix(prefix);
3689
3689
  const map = {};
3690
3690
  for (const name of logicalNames) {
3691
- map[name] = prefixedCollection(name, p4);
3691
+ map[name] = prefixedCollection(name, p5);
3692
3692
  }
3693
3693
  return map;
3694
3694
  }
@@ -4694,7 +4694,7 @@ shadcn-vue requires Node.js >= ${SHADCN_VUE_MIN_NODE} (current ${process.version
4694
4694
  }
4695
4695
  return `${base} Install shadcn manually, then re-run.`;
4696
4696
  }
4697
- function ensureShadcnComponents(projectRoot, framework, needed, log4) {
4697
+ function ensureShadcnComponents(projectRoot, framework, needed, log5) {
4698
4698
  const unique = [...new Set(needed.map((c) => c.trim()).filter(Boolean))];
4699
4699
  if (!unique.length) return { ok: true };
4700
4700
  if (framework !== "next" && framework !== "nuxt") {
@@ -4710,7 +4710,7 @@ function ensureShadcnComponents(projectRoot, framework, needed, log4) {
4710
4710
  };
4711
4711
  }
4712
4712
  if (!hasShadcnConfig(projectRoot)) {
4713
- log4(
4713
+ log5(
4714
4714
  framework === "nuxt" ? "shadcn-vue not found \u2014 running init --defaults\u2026" : "shadcn/ui not found \u2014 running init --defaults\u2026"
4715
4715
  );
4716
4716
  const init = runShadcn(projectRoot, framework, [
@@ -4728,12 +4728,12 @@ function ensureShadcnComponents(projectRoot, framework, needed, log4) {
4728
4728
  const installed = listInstalledShadcnComponents(projectRoot);
4729
4729
  const missing = unique.filter((c) => !installed.has(c));
4730
4730
  if (!missing.length) {
4731
- log4(
4731
+ log5(
4732
4732
  `shadcn components ok (${unique.join(", ")}; ${detectShadcnPrimitiveBase(projectRoot)})`
4733
4733
  );
4734
4734
  return { ok: true };
4735
4735
  }
4736
- log4(`Adding shadcn components: ${missing.join(", ")}`);
4736
+ log5(`Adding shadcn components: ${missing.join(", ")}`);
4737
4737
  const add = runShadcn(projectRoot, framework, [
4738
4738
  "add",
4739
4739
  ...missing,
@@ -5761,12 +5761,31 @@ import fs17 from "fs";
5761
5761
  import os2 from "os";
5762
5762
  import path18 from "path";
5763
5763
  import { execFileSync } from "child_process";
5764
+ import { fileURLToPath as fileURLToPath3 } from "url";
5764
5765
 
5765
5766
  // src/lib/license.ts
5766
5767
  import fs16 from "fs";
5767
5768
  import os from "os";
5768
5769
  import path17 from "path";
5769
- var DEFAULT_REGISTRY_API = "https://api.dkit.run";
5770
+ import { fileURLToPath as fileURLToPath2 } from "url";
5771
+ var DEFAULT_REGISTRY_API = "https://dkit.run/api";
5772
+ var LOCAL_REGISTRY_API = "http://localhost:3000/api";
5773
+ function isLocalMonorepoCli() {
5774
+ const here = path17.dirname(fileURLToPath2(import.meta.url));
5775
+ const roots = [
5776
+ path17.resolve(here, ".."),
5777
+ // packages/cli (dist/)
5778
+ path17.resolve(here, "../.."),
5779
+ // packages/cli (src/lib via tsx)
5780
+ path17.resolve(here, "../../..")
5781
+ ];
5782
+ for (const root of roots) {
5783
+ if (fs16.existsSync(path17.join(root, "apps/www/package.json")) && fs16.existsSync(path17.join(root, "packages/cli/package.json"))) {
5784
+ return true;
5785
+ }
5786
+ }
5787
+ return false;
5788
+ }
5770
5789
  function credentialsPath() {
5771
5790
  const override = process.env.DKIT_CONFIG_DIR;
5772
5791
  const dir = override ? path17.resolve(override) : path17.join(os.homedir(), ".config", "dkit");
@@ -5784,8 +5803,10 @@ function readCredentials() {
5784
5803
  function writeCredentials(next) {
5785
5804
  const file = credentialsPath();
5786
5805
  fs16.mkdirSync(path17.dirname(file), { recursive: true });
5787
- const merged = { ...readCredentials(), ...next };
5788
- fs16.writeFileSync(file, JSON.stringify(merged, null, 2) + "\n", {
5806
+ const licenseKey = next.licenseKey?.trim() || readCredentials().licenseKey;
5807
+ const out = {};
5808
+ if (licenseKey) out.licenseKey = licenseKey;
5809
+ fs16.writeFileSync(file, JSON.stringify(out, null, 2) + "\n", {
5789
5810
  mode: 384
5790
5811
  });
5791
5812
  }
@@ -5797,14 +5818,52 @@ function resolveLicenseKey(config) {
5797
5818
  return process.env.DKIT_LICENSE_KEY?.trim() || config?.licenseKey?.trim() || readCredentials().licenseKey?.trim() || void 0;
5798
5819
  }
5799
5820
  function resolveRegistryApi(config) {
5800
- const raw = process.env.DKIT_REGISTRY_API?.trim() || config?.registryApi?.trim() || readCredentials().registryApi?.trim() || DEFAULT_REGISTRY_API;
5801
- return raw.replace(/\/$/, "");
5821
+ const fromEnv = process.env.DKIT_REGISTRY_API?.trim();
5822
+ if (fromEnv) return fromEnv.replace(/\/$/, "");
5823
+ const fromConfig = config?.registryApi?.trim();
5824
+ if (fromConfig) return fromConfig.replace(/\/$/, "");
5825
+ if (isLocalMonorepoCli()) return LOCAL_REGISTRY_API;
5826
+ return DEFAULT_REGISTRY_API;
5802
5827
  }
5803
5828
  var BUY_PAGE_BUILDER_URL = "https://dkit.run/docs/modules/page-builder/";
5829
+ async function verifyLicenseKey(key, registryApi) {
5830
+ const api = (registryApi ?? resolveRegistryApi()).replace(/\/$/, "");
5831
+ const url = `${api}/registry/v1/me`;
5832
+ let res;
5833
+ try {
5834
+ res = await fetch(url, {
5835
+ headers: { Authorization: `Bearer ${key}` }
5836
+ });
5837
+ } catch (err) {
5838
+ const detail = err instanceof Error ? err.message : String(err);
5839
+ throw new Error(
5840
+ `Could not reach registry API at ${api} (${detail}). Is it running? Set DKIT_REGISTRY_API if needed.`
5841
+ );
5842
+ }
5843
+ if (res.status === 401) {
5844
+ throw new Error(
5845
+ `Invalid license key. Buy at ${BUY_PAGE_BUILDER_URL} then run \`dkit login\` with the key from checkout.`
5846
+ );
5847
+ }
5848
+ if (!res.ok) {
5849
+ throw new Error(
5850
+ `License verification failed (HTTP ${res.status}) at ${url}`
5851
+ );
5852
+ }
5853
+ const body = await res.json();
5854
+ return {
5855
+ email: body.email ?? "",
5856
+ products: body.products ?? [],
5857
+ createdAt: body.createdAt
5858
+ };
5859
+ }
5804
5860
 
5805
5861
  // src/lib/premium-fetch.ts
5806
5862
  function localPremiumItemDir(id) {
5863
+ const here = path18.dirname(fileURLToPath3(import.meta.url));
5807
5864
  const candidates = [
5865
+ // Monorepo checkout (works even when cwd is a temp fixture)
5866
+ path18.resolve(here, "../../../registry-premium"),
5808
5867
  path18.resolve(process.cwd(), "packages/registry-premium"),
5809
5868
  path18.resolve(process.cwd(), "../../packages/registry-premium")
5810
5869
  ];
@@ -5825,22 +5884,62 @@ function localPremiumItemDir(id) {
5825
5884
  }
5826
5885
  return null;
5827
5886
  }
5887
+ function allowLocalPremium() {
5888
+ const v = process.env.DKIT_ALLOW_LOCAL_PREMIUM?.trim().toLowerCase();
5889
+ return v === "1" || v === "true" || v === "yes";
5890
+ }
5828
5891
  function needsPremiumFetch(entry) {
5829
5892
  return entry.remote === true || isPremiumAccess(entry.access);
5830
5893
  }
5894
+ async function ensurePremiumAccess(entry, config) {
5895
+ if (!needsPremiumFetch(entry)) return;
5896
+ if (allowLocalPremium() && localPremiumItemDir(entry.id)) return;
5897
+ const license = resolveLicenseKey(config);
5898
+ if (!license) {
5899
+ throw new Error(
5900
+ `"${entry.id}" is a premium module. Buy it at ${BUY_PAGE_BUILDER_URL} then run \`dkit login\`, or set DKIT_LICENSE_KEY.` + (localPremiumItemDir(entry.id) ? ` (monorepo tip: DKIT_ALLOW_LOCAL_PREMIUM=1 to use packages/registry-premium)` : "")
5901
+ );
5902
+ }
5903
+ const me = await verifyLicenseKey(license, resolveRegistryApi(config));
5904
+ const product = entry.access?.product;
5905
+ if (product && !me.products.includes(product)) {
5906
+ throw new Error(
5907
+ `License does not include "${product}" (have: ${me.products.join(", ") || "none"}). Buy at ${BUY_PAGE_BUILDER_URL}`
5908
+ );
5909
+ }
5910
+ }
5911
+ async function ensurePremiumAccessForIds(ids, index, config) {
5912
+ const seen = /* @__PURE__ */ new Set();
5913
+ for (const id of ids) {
5914
+ if (seen.has(id)) continue;
5915
+ seen.add(id);
5916
+ const entry = index.items.find((i) => i.id === id);
5917
+ if (entry) await ensurePremiumAccess(entry, config);
5918
+ }
5919
+ }
5831
5920
  async function resolvePremiumItemDir(entry, config) {
5832
- const local = localPremiumItemDir(entry.id);
5833
- if (local) return local;
5921
+ if (allowLocalPremium()) {
5922
+ const local = localPremiumItemDir(entry.id);
5923
+ if (local) return local;
5924
+ }
5834
5925
  const license = resolveLicenseKey(config);
5835
5926
  if (!license) {
5836
5927
  throw new Error(
5837
- `"${entry.id}" is a premium module. Buy it at ${BUY_PAGE_BUILDER_URL} then run \`dkit login\`, or set DKIT_LICENSE_KEY.`
5928
+ `"${entry.id}" is a premium module. Buy it at ${BUY_PAGE_BUILDER_URL} then run \`dkit login\`, or set DKIT_LICENSE_KEY.` + (localPremiumItemDir(entry.id) ? ` (monorepo tip: DKIT_ALLOW_LOCAL_PREMIUM=1 to use packages/registry-premium)` : "")
5838
5929
  );
5839
5930
  }
5840
5931
  const api = resolveRegistryApi(config);
5841
- const res = await fetch(`${api}/registry/v1/items/${encodeURIComponent(entry.id)}`, {
5842
- headers: { Authorization: `Bearer ${license}` }
5843
- });
5932
+ let res;
5933
+ try {
5934
+ res = await fetch(`${api}/registry/v1/items/${encodeURIComponent(entry.id)}`, {
5935
+ headers: { Authorization: `Bearer ${license}` }
5936
+ });
5937
+ } catch (err) {
5938
+ const detail = err instanceof Error ? err.message : String(err);
5939
+ throw new Error(
5940
+ `Could not download "${entry.id}" from ${api} (${detail}). Is the registry API running?`
5941
+ );
5942
+ }
5844
5943
  if (res.status === 401 || res.status === 403) {
5845
5944
  const body = await res.json().catch(() => ({}));
5846
5945
  throw new Error(
@@ -5970,11 +6069,11 @@ function groupBlockIdsBySlot(blockIds, index) {
5970
6069
  return out;
5971
6070
  }
5972
6071
  function pickDefaultSlotPrimary(slot, candidates, opts) {
6072
+ const override = opts.templateOverrides?.[slot];
6073
+ if (override && candidates.includes(override)) return override;
5973
6074
  if (opts.existing && candidates.includes(opts.existing)) {
5974
6075
  return opts.existing;
5975
6076
  }
5976
- const override = opts.templateOverrides?.[slot];
5977
- if (override && candidates.includes(override)) return override;
5978
6077
  const meta = readModuleTemplateManifest(
5979
6078
  opts.moduleId,
5980
6079
  opts.index,
@@ -6285,7 +6384,7 @@ function routeConflictPaths(projectRoot, framework, basePath, config) {
6285
6384
  path21.join(projectRoot, "app", "pages", ...segments)
6286
6385
  );
6287
6386
  }
6288
- return candidates.filter((p4) => fs20.existsSync(p4));
6387
+ return candidates.filter((p5) => fs20.existsSync(p5));
6289
6388
  }
6290
6389
  function normalizeBasePath(input) {
6291
6390
  let v = input.trim() || "/";
@@ -6464,7 +6563,7 @@ function routeExportsFromBlocks(blocks, slotPrimaries) {
6464
6563
  }
6465
6564
  function joinModulePath(basePath, ...parts) {
6466
6565
  const base = !basePath || basePath === "/" ? "" : basePath.replace(/\/$/, "");
6467
- const rest2 = parts.map((p4) => p4.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
6566
+ const rest2 = parts.map((p5) => p5.replace(/^\/+|\/+$/g, "")).filter(Boolean).join("/");
6468
6567
  const joined = `${base}/${rest2}`.replace(/\/{2,}/g, "/");
6469
6568
  return joined.startsWith("/") ? joined : `/${joined}`;
6470
6569
  }
@@ -6729,7 +6828,7 @@ ${withSetLocale ? ` setRequestLocale(${localeParam});
6729
6828
  `;
6730
6829
  }
6731
6830
  function humanizeModuleId(moduleId) {
6732
- return moduleId.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((p4) => p4.charAt(0).toUpperCase() + p4.slice(1)).join(" ");
6831
+ return moduleId.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((p5) => p5.charAt(0).toUpperCase() + p5.slice(1)).join(" ");
6733
6832
  }
6734
6833
  function formPageHeading(moduleId) {
6735
6834
  return humanizeModuleId(moduleId).replace(/\s+Form$/i, "") || "Contact";
@@ -7015,6 +7114,12 @@ function addCommand() {
7015
7114
  process.exit(1);
7016
7115
  }
7017
7116
  const primaryIsBlock = registryEntry.type === "dkit:block";
7117
+ try {
7118
+ await ensurePremiumAccess(registryEntry, config);
7119
+ } catch (e) {
7120
+ p2.cancel(e instanceof Error ? e.message : String(e));
7121
+ process.exit(1);
7122
+ }
7018
7123
  let withBlocks = opts.with ? opts.with.split(",").map((s) => s.trim()).filter(Boolean) : void 0;
7019
7124
  const templateOverrides = parseTemplateFlag(opts.template);
7020
7125
  const hasTemplateOverrides = Object.keys(templateOverrides).length > 0;
@@ -7043,6 +7148,16 @@ function addCommand() {
7043
7148
  withBlocks,
7044
7149
  templateOverrides
7045
7150
  });
7151
+ try {
7152
+ await ensurePremiumAccessForIds(
7153
+ [...plan.modules, ...plan.blocks],
7154
+ index,
7155
+ config
7156
+ );
7157
+ } catch (e) {
7158
+ p2.cancel(e instanceof Error ? e.message : String(e));
7159
+ process.exit(1);
7160
+ }
7046
7161
  p2.log.info(
7047
7162
  `Plan: modules [${plan.modules.join(", ") || "\u2014"}] \xB7 components [${plan.blocks.join(", ") || "\u2014"}] \xB7 framework ${framework} \xB7 ui kit ${config.uiAdapter}`
7048
7163
  );
@@ -7785,43 +7900,80 @@ function loginCommand() {
7785
7900
  }
7786
7901
  key = String(answer).trim();
7787
7902
  }
7788
- const registryApi = opts.registryApi?.trim() || process.env.DKIT_REGISTRY_API?.trim() || readCredentials().registryApi || resolveRegistryApi();
7903
+ const registryApi = opts.registryApi?.trim() || resolveRegistryApi();
7789
7904
  try {
7790
- const res = await fetch(`${registryApi.replace(/\/$/, "")}/registry/v1/me`, {
7791
- headers: { Authorization: `Bearer ${key}` }
7792
- });
7793
- if (res.ok) {
7794
- const me = await res.json();
7795
- p3.log.success(
7796
- `Licensed${me.email ? ` \xB7 ${me.email}` : ""}${me.products?.length ? ` \xB7 ${me.products.join(", ")}` : ""}`
7797
- );
7798
- } else if (res.status === 401) {
7799
- p3.cancel("Invalid license key");
7800
- process.exit(1);
7801
- } else {
7802
- p3.log.warn(
7803
- `Could not verify license (HTTP ${res.status}) \u2014 saving key anyway`
7804
- );
7805
- }
7806
- } catch {
7807
- p3.log.warn(
7808
- `Registry API unreachable at ${registryApi} \u2014 saving key for offline use`
7905
+ const me = await verifyLicenseKey(key, registryApi);
7906
+ p3.log.success(
7907
+ `Licensed${me.email ? ` \xB7 ${me.email}` : ""}${me.products.length ? ` \xB7 ${me.products.join(", ")}` : ""}`
7809
7908
  );
7909
+ p3.log.info(`Registry ${registryApi}`);
7910
+ } catch (e) {
7911
+ p3.cancel(e instanceof Error ? e.message : String(e));
7912
+ process.exit(1);
7810
7913
  }
7811
- writeCredentials({ licenseKey: key, registryApi });
7812
- p3.log.info(`Saved ${credentialsPath()}`);
7914
+ writeCredentials({ licenseKey: key });
7915
+ p3.log.info(`Saved ${credentialsPath()} (key only)`);
7813
7916
  p3.log.info(`Buy / manage: ${BUY_PAGE_BUILDER_URL}`);
7814
7917
  p3.outro("Ready \u2014 try: dkit add page-builder");
7815
7918
  });
7816
7919
  }
7817
7920
 
7818
- // src/commands/doctor.ts
7921
+ // src/commands/license.ts
7819
7922
  import { Command as Command5 } from "commander";
7923
+ import * as p4 from "@clack/prompts";
7820
7924
  import pc5 from "picocolors";
7925
+ function licenseCommand() {
7926
+ const cmd = new Command5("license").description(
7927
+ "Manage your dkit premium license"
7928
+ );
7929
+ cmd.command("recover").description(
7930
+ "Email your license key to the address used at checkout (key is never printed)"
7931
+ ).option("--email <email>", "Checkout email").option("--registry-api <url>", "Premium registry API base URL").action(async (opts) => {
7932
+ p4.intro(pc5.bgCyan(pc5.black(" dkit license recover ")));
7933
+ let email = opts.email?.trim();
7934
+ if (!email) {
7935
+ const answer = await p4.text({
7936
+ message: "Checkout email",
7937
+ placeholder: "you@company.com",
7938
+ validate: (v) => !v?.trim() || !v.includes("@") ? "Valid email required" : void 0
7939
+ });
7940
+ if (p4.isCancel(answer)) {
7941
+ p4.cancel("Cancelled");
7942
+ process.exit(1);
7943
+ }
7944
+ email = String(answer).trim();
7945
+ }
7946
+ const api = (opts.registryApi?.trim() || process.env.DKIT_REGISTRY_API?.trim() || resolveRegistryApi()).replace(/\/$/, "");
7947
+ try {
7948
+ const res = await fetch(`${api}/registry/v1/recover`, {
7949
+ method: "POST",
7950
+ headers: { "Content-Type": "application/json" },
7951
+ body: JSON.stringify({ email })
7952
+ });
7953
+ const data = await res.json().catch(() => ({}));
7954
+ if (!res.ok) {
7955
+ throw new Error(data.error || `Recover failed (HTTP ${res.status})`);
7956
+ }
7957
+ p4.log.success(
7958
+ data.message || "If a license exists for that email, we sent the key. Check your inbox."
7959
+ );
7960
+ p4.log.info("Then: dkit login --key <key-from-email>");
7961
+ p4.outro("Done");
7962
+ } catch (e) {
7963
+ p4.cancel(e instanceof Error ? e.message : String(e));
7964
+ process.exit(1);
7965
+ }
7966
+ });
7967
+ return cmd;
7968
+ }
7969
+
7970
+ // src/commands/doctor.ts
7971
+ import { Command as Command6 } from "commander";
7972
+ import pc6 from "picocolors";
7821
7973
  import path29 from "path";
7822
7974
  import fs28 from "fs";
7823
7975
  function doctorCommand() {
7824
- return new Command5("doctor").description("Check project + Directus connectivity").action(async () => {
7976
+ return new Command6("doctor").description("Check project + Directus connectivity").action(async () => {
7825
7977
  const projectRoot = findProjectRoot();
7826
7978
  const checks = [];
7827
7979
  checks.push({
@@ -7896,10 +8048,10 @@ function doctorCommand() {
7896
8048
  label: "Tip: pnpm directus:up (in the dkit repo) starts a local Directus on :8010 (v11 \u2192 :8011)"
7897
8049
  });
7898
8050
  }
7899
- console.log(pc5.bold("\ndkit doctor\n"));
8051
+ console.log(pc6.bold("\ndkit doctor\n"));
7900
8052
  for (const c of checks) {
7901
8053
  console.log(
7902
- `${c.ok ? pc5.green("\u2713") : pc5.red("\u2717")} ${c.label}`
8054
+ `${c.ok ? pc6.green("\u2713") : pc6.red("\u2717")} ${c.label}`
7903
8055
  );
7904
8056
  }
7905
8057
  console.log();
@@ -8002,7 +8154,7 @@ var require2 = createRequire(import.meta.url);
8002
8154
  var { version } = require2("../package.json");
8003
8155
  async function run(argv) {
8004
8156
  installTelemetryExitFlush();
8005
- const program = new Command6();
8157
+ const program = new Command7();
8006
8158
  program.name("dkit").description(
8007
8159
  "Install Directus modules \u2014 schema, permissions, flows, and frontend code you own"
8008
8160
  ).version(version).option(
@@ -8013,6 +8165,7 @@ async function run(argv) {
8013
8165
  program.addCommand(addCommand());
8014
8166
  program.addCommand(listCommand());
8015
8167
  program.addCommand(loginCommand());
8168
+ program.addCommand(licenseCommand());
8016
8169
  program.addCommand(doctorCommand());
8017
8170
  program.hook("preAction", (_thisCommand, actionCommand) => {
8018
8171
  const rootOpts = program.opts();