veryfront 0.1.1092 → 0.1.1093

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/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.1092",
3
+ "version": "0.1.1093",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": {
@@ -6,7 +6,8 @@
6
6
  /**
7
7
  * Fetch environment variables for a project from the Veryfront API.
8
8
  *
9
- * Calls: GET {apiBaseUrl}/projects/{projectSlug}/environment-variables?environment_id={environmentId}&limit=100
9
+ * Hosted runtimes call the internal Basic-auth endpoint first. Older API deployments
10
+ * without that endpoint fall back to the bearer-auth management endpoint.
10
11
  * Response: { data: [{ key: string, value: string }] }
11
12
  */
12
13
  export declare function fetchProjectEnvVars(apiBaseUrl: string, projectSlug: string, environmentId: string, token: string): Promise<Record<string, string>>;
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../../src/src/server/project-env/fetcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgEjC"}
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../../../src/src/server/project-env/fetcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgDH;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA2EjC"}
@@ -5,25 +5,24 @@
5
5
  */
6
6
  import { getBaseLogger } from "../../utils/index.js";
7
7
  import { NETWORK_ERROR } from "../../errors/index.js";
8
+ import { getHostEnv } from "../../platform/compat/process.js";
8
9
  const baseLogger = getBaseLogger("PROJECT-ENV");
9
10
  const logger = baseLogger.component("project-env");
10
11
  /** Max env vars per request. API enforces a hard cap of 100. */
11
12
  const ENV_VARS_FETCH_LIMIT = 100;
12
- /**
13
- * Fetch environment variables for a project from the Veryfront API.
14
- *
15
- * Calls: GET {apiBaseUrl}/projects/{projectSlug}/environment-variables?environment_id={environmentId}&limit=100
16
- * Response: { data: [{ key: string, value: string }] }
17
- */
18
- export async function fetchProjectEnvVars(apiBaseUrl, projectSlug, environmentId, token) {
19
- const url = `${apiBaseUrl}/projects/${encodeURIComponent(projectSlug)}/environment-variables?environment_id=${encodeURIComponent(environmentId)}&limit=${ENV_VARS_FETCH_LIMIT}`;
20
- // Separate try-catch blocks eliminate the need to re-detect "our own" thrown errors
21
- // by message string matching. Each catch handles a distinct failure mode.
22
- let response;
13
+ const MASKED_ENV_VALUE = "********";
14
+ function getInternalAuthorization() {
15
+ const username = getHostEnv("VERYFRONT_API_INTERNAL_USER");
16
+ const password = getHostEnv("VERYFRONT_API_INTERNAL_PASS");
17
+ if (!username || !password)
18
+ return undefined;
19
+ return `Basic ${globalThis.btoa(`${username}:${password}`)}`;
20
+ }
21
+ async function fetchEnvironmentVariables(url, authorization, projectSlug, environmentId) {
23
22
  try {
24
- response = await fetch(url, {
23
+ return await fetch(url, {
25
24
  headers: {
26
- Authorization: `Bearer ${token}`,
25
+ Authorization: authorization,
27
26
  Accept: "application/json",
28
27
  },
29
28
  });
@@ -36,6 +35,25 @@ export async function fetchProjectEnvVars(apiBaseUrl, projectSlug, environmentId
36
35
  });
37
36
  throw error;
38
37
  }
38
+ }
39
+ /**
40
+ * Fetch environment variables for a project from the Veryfront API.
41
+ *
42
+ * Hosted runtimes call the internal Basic-auth endpoint first. Older API deployments
43
+ * without that endpoint fall back to the bearer-auth management endpoint.
44
+ * Response: { data: [{ key: string, value: string }] }
45
+ */
46
+ export async function fetchProjectEnvVars(apiBaseUrl, projectSlug, environmentId, token) {
47
+ const managementUrl = `${apiBaseUrl}/projects/${encodeURIComponent(projectSlug)}/environment-variables?environment_id=${encodeURIComponent(environmentId)}&limit=${ENV_VARS_FETCH_LIMIT}`;
48
+ const internalUrl = `${apiBaseUrl}/internal/project-environment-variables?environment_id=${encodeURIComponent(environmentId)}`;
49
+ const internalAuthorization = getInternalAuthorization();
50
+ let response = internalAuthorization
51
+ ? await fetchEnvironmentVariables(internalUrl, internalAuthorization, projectSlug, environmentId)
52
+ : await fetchEnvironmentVariables(managementUrl, `Bearer ${token}`, projectSlug, environmentId);
53
+ if (internalAuthorization && response.status === 404) {
54
+ await response.body?.cancel();
55
+ response = await fetchEnvironmentVariables(managementUrl, `Bearer ${token}`, projectSlug, environmentId);
56
+ }
39
57
  if (!response.ok) {
40
58
  await response.body?.cancel();
41
59
  logger.warn("Failed to fetch env vars", {
@@ -50,6 +68,11 @@ export async function fetchProjectEnvVars(apiBaseUrl, projectSlug, environmentId
50
68
  const result = {};
51
69
  if (body.data) {
52
70
  for (const entry of body.data) {
71
+ if (entry.value === MASKED_ENV_VALUE) {
72
+ throw NETWORK_ERROR.create({
73
+ detail: "Refusing masked environment variable response",
74
+ });
75
+ }
53
76
  result[entry.key] = entry.value;
54
77
  }
55
78
  }
@@ -1,3 +1,3 @@
1
1
  /** Shared version value. */
2
- export declare const VERSION = "0.1.1092";
2
+ export declare const VERSION = "0.1.1093";
3
3
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
3
  /** Shared version value. */
4
- export const VERSION = "0.1.1092";
4
+ export const VERSION = "0.1.1093";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.1092",
3
+ "version": "0.1.1093",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",
@@ -328,10 +328,10 @@
328
328
  "@types/react": "19.2.14",
329
329
  "@types/react-dom": "19.2.3",
330
330
  "ws": "8.21.0",
331
- "@veryfront/ext-bundler-esbuild": "0.1.1092",
332
- "@veryfront/ext-content-mdx": "0.1.1092",
333
- "@veryfront/ext-css-tailwind": "0.1.1092",
334
- "@veryfront/ext-parser-babel": "0.1.1092"
331
+ "@veryfront/ext-bundler-esbuild": "0.1.1093",
332
+ "@veryfront/ext-content-mdx": "0.1.1093",
333
+ "@veryfront/ext-css-tailwind": "0.1.1093",
334
+ "@veryfront/ext-parser-babel": "0.1.1093"
335
335
  },
336
336
  "devDependencies": {
337
337
  "@types/node": "20.9.0"