@braid-cloud/cli 0.1.19 → 0.1.20

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.js CHANGED
@@ -860,7 +860,7 @@ var init_device_auth = __esm({
860
860
 
861
861
  // src/lib/api.ts
862
862
  import { Data as Data3, Effect as Effect4, pipe as pipe4 } from "effect";
863
- var TRAILING_SLASH_REGEX, ALLOW_UNTRUSTED_SERVER_ENV, SESSION_TOKEN_PREFIX, isTruthy, isLocalHost, isConvexSiteHost, isTrustedApiServerUrl, isSessionApiServerUrl, REAUTH_REQUIRED_MESSAGE, RAW_AUTH_ERROR_PATTERN, normalizeAuthenticationErrorMessage, ApiError, AuthenticationError, NetworkError, resolveApiKey, resolveServerUrl, resolveApiRequestServerUrl, normalizeApiServerBaseUrl, readJsonResponseAsync, readJsonResponse, getApiErrorResponse, isAuthenticationErrorResponse, parseResponse, buildApiUrl, buildExportUrl, executeApiRequest, parseScopeOptionsResponse, fetchScopeOptions, buildLibraryOptionsUrl, fetchLibraryOptions, fetchSkills, runLifecycleCommand, DEFAULT_PUBLIC_SERVER_URL, NotFoundError, RateLimitedError, handlePublicApiResponse, fetchPublicMetadata, fetchPublicExport, fetchPublicMetadataAsync, fetchPublicExportAsync, validateApiKey, fetchSkillsAsync, validateApiKeyAsync, fetchScopeOptionsAsync, fetchLibraryOptionsAsync, runLifecycleCommandAsync;
863
+ var TRAILING_SLASH_REGEX, ALLOW_UNTRUSTED_SERVER_ENV, SESSION_TOKEN_PREFIX, isTruthy, isLocalHost, isConvexSiteHost, isTrustedApiServerUrl, isSessionApiServerUrl, REAUTH_REQUIRED_MESSAGE, RAW_AUTH_ERROR_PATTERN, normalizeAuthenticationErrorMessage, ApiError, AuthenticationError, NetworkError, resolveApiKey, resolveServerUrl, resolveApiRequestServerUrl, resolvePublicRequestServerUrl, normalizeApiServerBaseUrl, readJsonResponseAsync, readJsonResponse, getApiErrorResponse, isAuthenticationErrorResponse, parseResponse, buildApiUrl, buildExportUrl, executeApiRequest, parseScopeOptionsResponse, fetchScopeOptions, buildLibraryOptionsUrl, fetchLibraryOptions, fetchSkills, runLifecycleCommand, DEFAULT_PUBLIC_SERVER_URL, NotFoundError, RateLimitedError, handlePublicApiResponse, fetchPublicMetadata, fetchPublicExport, fetchPublicMetadataAsync, fetchPublicExportAsync, validateApiKey, fetchSkillsAsync, validateApiKeyAsync, fetchScopeOptionsAsync, fetchLibraryOptionsAsync, runLifecycleCommandAsync;
864
864
  var init_api = __esm({
865
865
  "src/lib/api.ts"() {
866
866
  "use strict";
@@ -989,6 +989,7 @@ var init_api = __esm({
989
989
  })
990
990
  );
991
991
  };
992
+ resolvePublicRequestServerUrl = (serverUrl, apiKey) => resolveApiRequestServerUrl(serverUrl, apiKey);
992
993
  normalizeApiServerBaseUrl = (serverUrl) => {
993
994
  const trimmed = serverUrl.replace(TRAILING_SLASH_REGEX, "");
994
995
  try {
@@ -1368,72 +1369,84 @@ var init_api = __esm({
1368
1369
  })
1369
1370
  );
1370
1371
  };
1371
- fetchPublicMetadata = (handle, slug, serverUrl, version) => {
1372
- const baseUrl = (serverUrl ?? DEFAULT_PUBLIC_SERVER_URL).replace(
1372
+ fetchPublicMetadata = (handle, slug, serverUrl, version, apiKey) => {
1373
+ const requestedBaseUrl = (serverUrl ?? DEFAULT_PUBLIC_SERVER_URL).replace(
1373
1374
  TRAILING_SLASH_REGEX,
1374
1375
  ""
1375
1376
  );
1376
- const url = new URL(`${baseUrl}/api/public/@${handle}/${slug}`);
1377
- if (version !== void 0) {
1378
- url.searchParams.set("version", String(version));
1379
- }
1380
1377
  return pipe4(
1381
- Effect4.tryPromise({
1382
- try: () => fetch(url.toString(), {
1383
- method: "GET",
1384
- headers: mergeAutomationHeaders()
1385
- }),
1386
- catch: (e) => new NetworkError({
1387
- message: `Failed to connect to ${baseUrl}`,
1388
- cause: e
1389
- })
1390
- }),
1391
- Effect4.flatMap(
1392
- (response) => pipe4(
1393
- readJsonResponse(response),
1378
+ resolvePublicRequestServerUrl(requestedBaseUrl, apiKey),
1379
+ Effect4.flatMap((baseUrl) => {
1380
+ const url = new URL(`${baseUrl}/api/public/@${handle}/${slug}`);
1381
+ if (version !== void 0) {
1382
+ url.searchParams.set("version", String(version));
1383
+ }
1384
+ return pipe4(
1385
+ Effect4.tryPromise({
1386
+ try: () => fetch(url.toString(), {
1387
+ method: "GET",
1388
+ headers: mergeAutomationHeaders()
1389
+ }),
1390
+ catch: (e) => new NetworkError({
1391
+ message: `Failed to connect to ${baseUrl}`,
1392
+ cause: e
1393
+ })
1394
+ }),
1394
1395
  Effect4.flatMap(
1395
- (json) => handlePublicApiResponse(response, json)
1396
+ (response) => pipe4(
1397
+ readJsonResponse(response),
1398
+ Effect4.flatMap(
1399
+ (json) => handlePublicApiResponse(response, json)
1400
+ )
1401
+ )
1396
1402
  )
1397
- )
1398
- )
1403
+ );
1404
+ })
1399
1405
  );
1400
1406
  };
1401
- fetchPublicExport = (handle, slug, ruleIds, serverUrl, version) => {
1402
- const baseUrl = (serverUrl ?? DEFAULT_PUBLIC_SERVER_URL).replace(
1407
+ fetchPublicExport = (handle, slug, ruleIds, serverUrl, version, apiKey) => {
1408
+ const requestedBaseUrl = (serverUrl ?? DEFAULT_PUBLIC_SERVER_URL).replace(
1403
1409
  TRAILING_SLASH_REGEX,
1404
1410
  ""
1405
1411
  );
1406
- const url = new URL(`${baseUrl}/api/public/@${handle}/${slug}/export`);
1407
- if (ruleIds && ruleIds.length > 0) {
1408
- url.searchParams.set("ruleIds", ruleIds.join(","));
1409
- }
1410
- if (version !== void 0) {
1411
- url.searchParams.set("version", String(version));
1412
- }
1413
1412
  return pipe4(
1414
- Effect4.tryPromise({
1415
- try: () => fetch(url.toString(), {
1416
- method: "GET",
1417
- headers: mergeAutomationHeaders()
1418
- }),
1419
- catch: (e) => new NetworkError({
1420
- message: `Failed to connect to ${baseUrl}`,
1421
- cause: e
1422
- })
1423
- }),
1424
- Effect4.flatMap(
1425
- (response) => pipe4(
1426
- readJsonResponse(response),
1413
+ resolvePublicRequestServerUrl(requestedBaseUrl, apiKey),
1414
+ Effect4.flatMap((baseUrl) => {
1415
+ const url = new URL(`${baseUrl}/api/public/@${handle}/${slug}/export`);
1416
+ if (ruleIds && ruleIds.length > 0) {
1417
+ url.searchParams.set("ruleIds", ruleIds.join(","));
1418
+ }
1419
+ if (version !== void 0) {
1420
+ url.searchParams.set("version", String(version));
1421
+ }
1422
+ return pipe4(
1423
+ Effect4.tryPromise({
1424
+ try: () => fetch(url.toString(), {
1425
+ method: "GET",
1426
+ headers: mergeAutomationHeaders()
1427
+ }),
1428
+ catch: (e) => new NetworkError({
1429
+ message: `Failed to connect to ${baseUrl}`,
1430
+ cause: e
1431
+ })
1432
+ }),
1427
1433
  Effect4.flatMap(
1428
- (json) => handlePublicApiResponse(response, json)
1434
+ (response) => pipe4(
1435
+ readJsonResponse(response),
1436
+ Effect4.flatMap(
1437
+ (json) => handlePublicApiResponse(response, json)
1438
+ )
1439
+ )
1429
1440
  )
1430
- )
1431
- )
1441
+ );
1442
+ })
1432
1443
  );
1433
1444
  };
1434
- fetchPublicMetadataAsync = (handle, slug, serverUrl, version) => Effect4.runPromise(fetchPublicMetadata(handle, slug, serverUrl, version));
1435
- fetchPublicExportAsync = (handle, slug, ruleIds, serverUrl, version) => Effect4.runPromise(
1436
- fetchPublicExport(handle, slug, ruleIds, serverUrl, version)
1445
+ fetchPublicMetadataAsync = (handle, slug, serverUrl, version, apiKey) => Effect4.runPromise(
1446
+ fetchPublicMetadata(handle, slug, serverUrl, version, apiKey)
1447
+ );
1448
+ fetchPublicExportAsync = (handle, slug, ruleIds, serverUrl, version, apiKey) => Effect4.runPromise(
1449
+ fetchPublicExport(handle, slug, ruleIds, serverUrl, version, apiKey)
1437
1450
  );
1438
1451
  validateApiKey = (apiKey, serverUrl) => pipe4(
1439
1452
  Effect4.try({
@@ -4620,7 +4633,7 @@ function showInstallOutro(totalWritten, totalErrors, suffix) {
4620
4633
  outro(`Successfully installed ${totalWritten} items${suffix}.`);
4621
4634
  }
4622
4635
  }
4623
- async function fetchPublicContent(handle, slug, version, lockedRuleIds, options, installSpinner) {
4636
+ async function fetchPublicContent(handle, slug, version, lockedRuleIds, apiKey, options, installSpinner) {
4624
4637
  if (version !== void 0 && lockedRuleIds) {
4625
4638
  installSpinner.stop(`Installing pinned version v${version}`);
4626
4639
  installSpinner.start("Downloading content...");
@@ -4630,7 +4643,8 @@ async function fetchPublicContent(handle, slug, version, lockedRuleIds, options,
4630
4643
  slug,
4631
4644
  lockedRuleIds,
4632
4645
  options.server,
4633
- version
4646
+ version,
4647
+ apiKey
4634
4648
  ),
4635
4649
  ruleIds: lockedRuleIds
4636
4650
  };
@@ -4639,7 +4653,8 @@ async function fetchPublicContent(handle, slug, version, lockedRuleIds, options,
4639
4653
  handle,
4640
4654
  slug,
4641
4655
  options.server,
4642
- version
4656
+ version,
4657
+ apiKey
4643
4658
  );
4644
4659
  installSpinner.stop("Found public content");
4645
4660
  displayPublicMetadata(metadata);
@@ -4651,7 +4666,8 @@ async function fetchPublicContent(handle, slug, version, lockedRuleIds, options,
4651
4666
  slug,
4652
4667
  ruleIds,
4653
4668
  options.server,
4654
- version
4669
+ version,
4670
+ apiKey
4655
4671
  ),
4656
4672
  ruleIds
4657
4673
  };
@@ -4734,6 +4750,7 @@ async function publicInstallCommand(source, options) {
4734
4750
  slug,
4735
4751
  version,
4736
4752
  lockedRuleIds,
4753
+ config.token,
4737
4754
  {
4738
4755
  ...options,
4739
4756
  server: serverUrl
@@ -7519,7 +7536,8 @@ async function findPreviousActiveVersion(args) {
7519
7536
  args.slug,
7520
7537
  args.ruleIds,
7521
7538
  args.server,
7522
- v
7539
+ v,
7540
+ args.apiKey
7523
7541
  );
7524
7542
  return { version: v, response };
7525
7543
  } catch (error) {
@@ -7599,7 +7617,8 @@ async function rollbackCommand(source, options) {
7599
7617
  slug: publicSource.slug,
7600
7618
  currentVersion: parsed.version,
7601
7619
  ruleIds: currentValue.ruleIds,
7602
- server: serverUrl
7620
+ server: serverUrl,
7621
+ apiKey: config.token
7603
7622
  });
7604
7623
  if (!result) {
7605
7624
  rollbackSpinner.stop("No active version found");