@riverbankcms/sdk 0.5.1 → 0.5.3

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/README.md CHANGED
@@ -2266,27 +2266,28 @@ The SDK includes a CLI for syncing your local config to the dashboard.
2266
2266
  Push content types, custom blocks, and block field extensions to your CMS dashboard:
2267
2267
 
2268
2268
  ```bash
2269
- npx riverbankcms push-config --api-key <key> --dashboard <url>
2269
+ npx riverbankcms push-config --dashboard <url>
2270
2270
  ```
2271
2271
 
2272
2272
  **Options:**
2273
2273
 
2274
2274
  | Option | Description |
2275
2275
  |--------|-------------|
2276
- | `--api-key <key>` | Dashboard API key (required) |
2277
- | `--dashboard <url>` | Dashboard URL, or set `NEXT_PUBLIC_DASHBOARD_URL` env var |
2276
+ | `--api-key <key>` | Management API key (or set `RIVERBANK_*_MGMT_API_KEY`) |
2277
+ | `--dashboard <url>` | Dashboard URL (or set `RIVERBANK_*_DASHBOARD_URL`) |
2278
2278
  | `--config <path>` | Path to config file (default: `./riverbank.config.ts`) |
2279
2279
 
2280
2280
  **Example:**
2281
2281
 
2282
2282
  ```bash
2283
- # Using environment variables
2284
- export NEXT_PUBLIC_DASHBOARD_URL=https://www.riverbankcms.com
2285
- npx riverbankcms push-config --api-key $RIVERBANK_API_KEY
2283
+ # Using environment variables (local)
2284
+ export RIVERBANK_LOCAL_DASHBOARD_URL=https://www.riverbankcms.com
2285
+ export RIVERBANK_LOCAL_MGMT_API_KEY=bld_mgmt_sk_...
2286
+ npx riverbankcms push-config
2286
2287
 
2287
- # Or inline
2288
+ # Or inline (remote)
2288
2289
  npx riverbankcms push-config \
2289
- --api-key abc123 \
2290
+ --api-key bld_mgmt_sk_... \
2290
2291
  --dashboard https://www.riverbankcms.com
2291
2292
  ```
2292
2293
 
package/dist/cli/index.js CHANGED
@@ -5400,7 +5400,7 @@ async function pushToDashboard(dashboardUrl, siteId, apiKey, config3) {
5400
5400
  method: "POST",
5401
5401
  headers: {
5402
5402
  "Content-Type": "application/json",
5403
- "X-API-Key": apiKey
5403
+ "Authorization": `Bearer ${apiKey}`
5404
5404
  },
5405
5405
  body: JSON.stringify({ config: config3 }),
5406
5406
  signal: AbortSignal.timeout(3e4)
@@ -5445,28 +5445,40 @@ async function pushConfigAction(options) {
5445
5445
  process.exit(1);
5446
5446
  }
5447
5447
  const { siteId } = parseResult.data;
5448
- await pushToDashboard(
5449
- options.dashboard,
5450
- siteId,
5451
- options.apiKey,
5452
- parseResult.data
5453
- );
5448
+ const apiKey = resolveManagementApiKey(options.apiKey, options.isRemote);
5449
+ await pushToDashboard(options.dashboard, siteId, apiKey, parseResult.data);
5454
5450
  console.log("Config pushed successfully!");
5455
5451
  } catch (error) {
5456
5452
  console.error("Error:", error instanceof Error ? error.message : error);
5457
5453
  process.exit(1);
5458
5454
  }
5459
5455
  }
5460
- function resolveDashboardUrl(cliOption) {
5461
- const url = cliOption || process.env.NEXT_PUBLIC_DASHBOARD_URL;
5456
+ function resolveDashboardUrl(cliOption, isRemote) {
5457
+ const envVar = isRemote ? "RIVERBANK_REMOTE_DASHBOARD_URL" : "RIVERBANK_LOCAL_DASHBOARD_URL";
5458
+ const url = cliOption || process.env[envVar];
5462
5459
  if (!url) {
5463
5460
  console.error("Error: Dashboard URL is required.");
5464
- console.error("Provide --dashboard <url> or set NEXT_PUBLIC_DASHBOARD_URL environment variable.");
5461
+ console.error(`Provide --dashboard <url> or set ${envVar} environment variable.`);
5465
5462
  process.exit(1);
5466
5463
  }
5467
5464
  return url;
5468
5465
  }
5469
- var pushConfigCommand = new commander.Command("push-config").description("Push SDK config to dashboard").requiredOption("--api-key <key>", "Dashboard API key (required)").option("--dashboard <url>", "Dashboard URL (or set NEXT_PUBLIC_DASHBOARD_URL env var)").option("--config <path>", "Path to config file (default: ./riverbank.config.ts)").addHelpText("after", `
5466
+ function resolveManagementApiKey(cliOption, isRemote) {
5467
+ const envVar = isRemote ? "RIVERBANK_REMOTE_MGMT_API_KEY" : "RIVERBANK_LOCAL_MGMT_API_KEY";
5468
+ const apiKey = cliOption || process.env[envVar];
5469
+ if (!apiKey) {
5470
+ console.error("Error: Management API key is required.");
5471
+ console.error(`Provide --api-key <key> or set ${envVar} environment variable.`);
5472
+ process.exit(1);
5473
+ }
5474
+ if (!apiKey.startsWith("bld_mgmt_sk_")) {
5475
+ console.error(`Error: Invalid management API key format for ${envVar}.`);
5476
+ console.error("Expected key starting with bld_mgmt_sk_.");
5477
+ process.exit(1);
5478
+ }
5479
+ return apiKey;
5480
+ }
5481
+ var pushConfigCommand = new commander.Command("push-config").description("Push SDK config to dashboard").option("--api-key <key>", "Management API key (or set RIVERBANK_*_MGMT_API_KEY)").option("--dashboard <url>", "Dashboard URL (or set RIVERBANK_*_DASHBOARD_URL env var)").option("--config <path>", "Path to config file (default: ./riverbank.config.ts)").addHelpText("after", `
5470
5482
  Description:
5471
5483
  Syncs your local riverbank.config.ts to the CMS dashboard, including:
5472
5484
  - Custom blocks
@@ -5475,12 +5487,14 @@ Description:
5475
5487
  - Content types, pages, entries, and navigation
5476
5488
 
5477
5489
  Examples:
5478
- $ npx riverbankcms push-config --api-key $RIVERBANK_API_KEY
5479
- $ npx riverbankcms push-config --api-key abc123 --dashboard https://www.riverbankcms.com
5480
- $ npx riverbankcms push-config --api-key $API_KEY --config ./src/riverbank.config.ts
5481
- `).action((options) => {
5482
- const dashboard = resolveDashboardUrl(options.dashboard);
5483
- return pushConfigAction({ ...options, dashboard });
5490
+ $ npx riverbankcms push-config
5491
+ $ npx riverbankcms push-config --api-key bld_mgmt_sk_... --dashboard https://www.riverbankcms.com
5492
+ $ npx riverbankcms push-config --config ./src/riverbank.config.ts
5493
+ `).action((options, command) => {
5494
+ const globalOpts = command.optsWithGlobals();
5495
+ const isRemote = globalOpts.remote ?? false;
5496
+ const dashboard = resolveDashboardUrl(options.dashboard, isRemote);
5497
+ return pushConfigAction({ ...options, dashboard, isRemote });
5484
5498
  });
5485
5499
 
5486
5500
  // src/client/management/http.ts
@@ -5798,8 +5812,7 @@ function createPreviewOperations(http) {
5798
5812
  function createIdentifiersOperations(http) {
5799
5813
  return {
5800
5814
  async backfill() {
5801
- const response = await http.post("/identifiers/backfill");
5802
- return response.data;
5815
+ return http.post("/identifiers/backfill");
5803
5816
  }
5804
5817
  };
5805
5818
  }
@@ -6248,6 +6261,29 @@ function createListCommand(config3) {
6248
6261
  );
6249
6262
  }
6250
6263
 
6264
+ // src/cli/sync/mapper.ts
6265
+ function stripNavigationItemIds(items) {
6266
+ return items.map((item) => {
6267
+ const result = {
6268
+ label: item.label,
6269
+ url: item.url
6270
+ };
6271
+ if (item.children && item.children.length > 0) {
6272
+ result.children = stripNavigationItemIds(item.children);
6273
+ }
6274
+ return result;
6275
+ });
6276
+ }
6277
+ function convertPulledNavigationToLocal(remoteMenus) {
6278
+ return {
6279
+ menus: remoteMenus.map((menu) => ({
6280
+ identifier: menu.identifier,
6281
+ name: menu.name,
6282
+ items: stripNavigationItemIds(menu.items)
6283
+ }))
6284
+ };
6285
+ }
6286
+
6251
6287
  // src/cli/content/writer.ts
6252
6288
  async function ensureDir(dirPath) {
6253
6289
  try {
@@ -6306,9 +6342,8 @@ async function writeNavigation(contentDir, pulledNavigation) {
6306
6342
  await ensureDir(contentDir);
6307
6343
  await ensureDir(metaDir);
6308
6344
  const filePath = path9__namespace.join(contentDir, "navigation.json");
6309
- await writeJsonFile(filePath, {
6310
- menus: pulledNavigation.menus
6311
- });
6345
+ const localNavigation = convertPulledNavigationToLocal(pulledNavigation.menus);
6346
+ await writeJsonFile(filePath, localNavigation);
6312
6347
  const menusMeta = {};
6313
6348
  for (const menu of pulledNavigation.menus) {
6314
6349
  menusMeta[menu.name] = {
@@ -6709,22 +6744,6 @@ async function loadCliConfig(configPath) {
6709
6744
  throw error;
6710
6745
  }
6711
6746
  }
6712
-
6713
- // src/cli/sync/mapper.ts
6714
- function stripNavigationItemIds(items) {
6715
- return items.map((item) => {
6716
- const result = {
6717
- label: item.label,
6718
- url: item.url
6719
- };
6720
- if (item.children && item.children.length > 0) {
6721
- result.children = stripNavigationItemIds(item.children);
6722
- }
6723
- return result;
6724
- });
6725
- }
6726
-
6727
- // src/cli/sync/diff.ts
6728
6747
  function findChangedFields(local, remote, prefix = "") {
6729
6748
  const changes = [];
6730
6749
  const allKeys = /* @__PURE__ */ new Set([...Object.keys(local), ...Object.keys(remote)]);
@@ -8726,7 +8745,7 @@ Environment Variables:
8726
8745
  RIVERBANK_REMOTE_MGMT_API_KEY Management API key (bld_mgmt_sk_...)
8727
8746
 
8728
8747
  Examples:
8729
- $ riverbankcms push-config --api-key $RIVERBANK_API_KEY
8748
+ $ riverbankcms push-config
8730
8749
  $ riverbankcms pull # Pull all content from local
8731
8750
  $ riverbankcms pull --remote # Pull all content from production
8732
8751
  $ riverbankcms pull entries blog-post # Pull specific content type