@anvil-works/anvil-cli 0.8.0-canary.17 → 0.8.0-canary.18

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/cli.js CHANGED
@@ -23712,33 +23712,95 @@ print(json.dumps({"issues": issues}))
23712
23712
  async function ensureEnvironmentUrl(appId, envPid, options = {}) {
23713
23713
  const anvilUrl = options.anvilUrl ?? await resolveAuthAnvilUrl();
23714
23714
  const token = await auth_getValidAuthToken(anvilUrl);
23715
- const response = await fetch(`${anvilUrl}/ide/api/_/apps/${encodeURIComponent(appId)}/environments/${encodeURIComponent(envPid)}/ensure-url`, {
23715
+ const response = await fetch(`${anvilUrl}/ide/api/_/apps/${encodeURIComponent(appId)}/environments/${encodeURIComponent(envPid)}/temporary-url`, {
23716
23716
  method: "POST",
23717
23717
  headers: {
23718
23718
  Authorization: `Bearer ${token}`
23719
23719
  }
23720
23720
  });
23721
23721
  if (!response.ok) throw new Error(formatHttpError("Failed to get environment URL", response.status, await response.text()));
23722
- const result = await response.json();
23723
- return result.url;
23722
+ const { url, expires_at } = await response.json();
23723
+ return {
23724
+ url,
23725
+ expires_at
23726
+ };
23727
+ }
23728
+ async function getTemporaryUplinkKey(appId, envPid, options = {}) {
23729
+ const anvilUrl = options.anvilUrl ?? await resolveAuthAnvilUrl();
23730
+ const token = await auth_getValidAuthToken(anvilUrl);
23731
+ const response = await fetch(`${anvilUrl}/ide/api/_/apps/${encodeURIComponent(appId)}/environments/${encodeURIComponent(envPid)}/temporary-uplink-key`, {
23732
+ method: "POST",
23733
+ headers: {
23734
+ Authorization: `Bearer ${token}`
23735
+ }
23736
+ });
23737
+ if (!response.ok) throw new Error(formatHttpError("Failed to get temporary uplink key", response.status, await response.text()));
23738
+ const { key, url, expires_at } = await response.json();
23739
+ return {
23740
+ key,
23741
+ url,
23742
+ expires_at
23743
+ };
23744
+ }
23745
+ async function resolveEnvironmentContext() {
23746
+ const projectRoot = process.cwd();
23747
+ const envPid = await readEnvironmentPid(projectRoot);
23748
+ if (!envPid) throw new Error("No app environment associated with the current directory.");
23749
+ auth_setRepoContext(projectRoot);
23750
+ const anvilUrl = await resolveAuthAnvilUrl();
23751
+ const appId = await resolvePrimaryAppId(projectRoot, anvilUrl);
23752
+ if (!appId) throw new Error("No Anvil app found in current directory. Make sure you're in a directory with an Anvil app git remote.");
23753
+ return {
23754
+ envPid,
23755
+ anvilUrl,
23756
+ appId
23757
+ };
23724
23758
  }
23725
23759
  function registerEnvCommand(program) {
23726
23760
  if ("1" !== process.env.ANVIL_AGENT_HOST) return;
23727
23761
  const env = program.command("env").description("Manage app environments");
23728
- env.command("url").description("Get a private app URL for the current environment, creating one if necessary").action(async ()=>{
23762
+ env.command("url").description("Get a temporary private app URL for the current environment").action(async ()=>{
23729
23763
  try {
23730
- const projectRoot = process.cwd();
23731
- const envPid = await readEnvironmentPid(projectRoot);
23732
- if (!envPid) throw new Error("No app environment associated with the current directory.");
23733
- auth_setRepoContext(projectRoot);
23734
- const anvilUrl = await resolveAuthAnvilUrl();
23735
- const appId = await resolvePrimaryAppId(projectRoot, anvilUrl);
23736
- if (!appId) throw new Error("No Anvil app found in current directory. Make sure you're in a directory with an Anvil app git remote.");
23737
- logger_logger.info(await ensureEnvironmentUrl(appId, envPid, {
23764
+ const { appId, envPid, anvilUrl } = await resolveEnvironmentContext();
23765
+ const { url, expires_at } = await ensureEnvironmentUrl(appId, envPid, {
23738
23766
  anvilUrl
23739
- }));
23767
+ });
23768
+ if (getGlobalOutputConfig().jsonMode) logJsonResult(true, {
23769
+ data: {
23770
+ url,
23771
+ expires_at
23772
+ }
23773
+ });
23774
+ else logger_logger.info(`URL: ${url}\nExpires at: ${expires_at}`);
23740
23775
  } catch (error) {
23741
- logger_logger.error(errors_getErrorMessage(error));
23776
+ const message = errors_getErrorMessage(error);
23777
+ if (getGlobalOutputConfig().jsonMode) logJsonResult(false, {
23778
+ error: message
23779
+ });
23780
+ else logger_logger.error(message);
23781
+ process.exit(1);
23782
+ }
23783
+ });
23784
+ env.command("uplink").description("Get a temporary uplink key for the current environment").action(async ()=>{
23785
+ try {
23786
+ const { appId, envPid, anvilUrl } = await resolveEnvironmentContext();
23787
+ const { key, url, expires_at } = await getTemporaryUplinkKey(appId, envPid, {
23788
+ anvilUrl
23789
+ });
23790
+ if (getGlobalOutputConfig().jsonMode) logJsonResult(true, {
23791
+ data: {
23792
+ key,
23793
+ url,
23794
+ expires_at
23795
+ }
23796
+ });
23797
+ else logger_logger.info(`Key: ${key}\nURL: ${url}\nExpires at: ${expires_at}`);
23798
+ } catch (error) {
23799
+ const message = errors_getErrorMessage(error);
23800
+ if (getGlobalOutputConfig().jsonMode) logJsonResult(false, {
23801
+ error: message
23802
+ });
23803
+ else logger_logger.error(message);
23742
23804
  process.exit(1);
23743
23805
  }
23744
23806
  });
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgCzD"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/commands/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0BpC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAoDzD"}
@@ -1,5 +1,16 @@
1
1
  export interface EnsureEnvironmentUrlOptions {
2
2
  anvilUrl?: string;
3
3
  }
4
- export declare function ensureEnvironmentUrl(appId: string, envPid: string, options?: EnsureEnvironmentUrlOptions): Promise<string>;
4
+ export declare function ensureEnvironmentUrl(appId: string, envPid: string, options?: EnsureEnvironmentUrlOptions): Promise<{
5
+ url: string;
6
+ expires_at: string;
7
+ }>;
8
+ export interface GetTemporaryUplinkKeyOptions {
9
+ anvilUrl?: string;
10
+ }
11
+ export declare function getTemporaryUplinkKey(appId: string, envPid: string, options?: GetTemporaryUplinkKeyOptions): Promise<{
12
+ key: string;
13
+ url: string;
14
+ expires_at: string;
15
+ }>;
5
16
  //# sourceMappingURL=environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/services/environment.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,2BAA2B;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,oBAAoB,CACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAAgC,GAC1C,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
1
+ {"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/services/environment.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,2BAA2B;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,oBAAoB,CACtC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,2BAAgC,GAC1C,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAiB9C;AAED,MAAM,WAAW,4BAA4B;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAsB,qBAAqB,CACvC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,4BAAiC,GAC3C,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAiB3D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anvil-works/anvil-cli",
3
- "version": "0.8.0-canary.17",
3
+ "version": "0.8.0-canary.18",
4
4
  "description": "CLI tool for developing Anvil apps locally",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/api.d.ts",