@getmagical/cli 0.14.1 → 0.14.2

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
@@ -23735,11 +23735,28 @@ function applyAuthenticationHeaders({
23735
23735
  headers.set(OTTO_AUTHORIZATION_HEADER_NAME, `Bearer ${accessToken}`);
23736
23736
  headers.set("x-organization-id", organizationId);
23737
23737
  }
23738
+ var UPDATE_AVAILABLE_HEADER = "x-magical-client-update-available";
23739
+ var SEMVER_PATTERN = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+[\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*)?$/u;
23740
+ function createUpdateAvailableNotifier(notify) {
23741
+ const state = { notified: false };
23742
+ return (response) => {
23743
+ const latestVersion = response.headers.get(UPDATE_AVAILABLE_HEADER);
23744
+ if (notify === void 0 || state.notified || latestVersion === null || !SEMVER_PATTERN.test(latestVersion)) {
23745
+ return;
23746
+ }
23747
+ state.notified = true;
23748
+ notify(
23749
+ `mgcl ${latestVersion} is available (you have ${CLI_VERSION}). Run \`mgcl update\` to upgrade.`
23750
+ );
23751
+ };
23752
+ }
23738
23753
  function createFetchJson({
23739
23754
  apiBaseUrl,
23740
- fetchFn
23755
+ fetchFn,
23756
+ onUpdateAvailable
23741
23757
  }) {
23742
23758
  const resolveApiBaseUrl = typeof apiBaseUrl === "string" ? () => apiBaseUrl : apiBaseUrl;
23759
+ const checkUpdateAvailable = createUpdateAvailableNotifier(onUpdateAvailable);
23743
23760
  return async function fetchJson({
23744
23761
  accessToken,
23745
23762
  impersonatedOrganizationId,
@@ -23776,6 +23793,7 @@ function createFetchJson({
23776
23793
  { statusCode: response.status }
23777
23794
  );
23778
23795
  }
23796
+ checkUpdateAvailable(response);
23779
23797
  const retryAfterMs = getRetryAfterMs(response);
23780
23798
  const errorOptions = {
23781
23799
  ...retryAfterMs === void 0 ? {} : { retryAfterMs },
@@ -23999,9 +24017,10 @@ function createPathwayCoverageClient(fetchJson) {
23999
24017
  }
24000
24018
  function createMagicalApiClient({
24001
24019
  apiBaseUrl,
24002
- fetchFn = fetch
24020
+ fetchFn = fetch,
24021
+ onUpdateAvailable
24003
24022
  }) {
24004
- const fetchJson = createFetchJson({ apiBaseUrl, fetchFn });
24023
+ const fetchJson = createFetchJson({ apiBaseUrl, fetchFn, onUpdateAvailable });
24005
24024
  const resolveApiBaseUrl = typeof apiBaseUrl === "string" ? () => apiBaseUrl : apiBaseUrl;
24006
24025
  return {
24007
24026
  ...createUserApiKeyManagementClient(fetchJson),
@@ -34616,15 +34635,19 @@ function createDefaultDependencies() {
34616
34635
  ...runtimeConfig.cliDistTag ? { distTag: runtimeConfig.cliDistTag } : {},
34617
34636
  ...runtimeConfig.npmRegistryUrl ? { registryUrl: runtimeConfig.npmRegistryUrl } : {}
34618
34637
  };
34638
+ const io = createConsoleIo();
34619
34639
  return {
34620
34640
  apiClient: createMagicalApiClient({
34621
- apiBaseUrl: resolveApiBaseUrl
34641
+ apiBaseUrl: resolveApiBaseUrl,
34642
+ onUpdateAvailable: (notice) => {
34643
+ io.error(notice);
34644
+ }
34622
34645
  }),
34623
34646
  authClient: createWorkosAuthClient({
34624
34647
  workosApiUrl: () => deploymentTargetContext.get().workosApiUrl
34625
34648
  }),
34626
34649
  deploymentTargetContext,
34627
- io: createConsoleIo(),
34650
+ io,
34628
34651
  openExternalUrl,
34629
34652
  orgPreferencesStore: createFileOrgPreferencesStore(
34630
34653
  path23.join(