zinkee 0.1.2 → 0.1.4
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 +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config.test.ts +45 -0
- package/src/config.ts +1 -0
- package/src/runtime-context.ts +2 -1
package/package.json
CHANGED
package/src/config.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
DEFAULT_PRODUCTION_BASE_URL,
|
|
4
5
|
ENV_API_KEY,
|
|
5
6
|
ENV_BASE_URL,
|
|
6
7
|
ENV_PROFILE,
|
|
@@ -176,6 +177,50 @@ describe("resolveRuntimeContext", () => {
|
|
|
176
177
|
}
|
|
177
178
|
});
|
|
178
179
|
|
|
180
|
+
it("falls back to the production base URL when the resolved profile has no base URL", () => {
|
|
181
|
+
expect(
|
|
182
|
+
resolveRuntimeContext({
|
|
183
|
+
defaultProfile: "prod",
|
|
184
|
+
profiles: {
|
|
185
|
+
prod: { apiKey: "prod-token" },
|
|
186
|
+
},
|
|
187
|
+
}, {}),
|
|
188
|
+
).toEqual({
|
|
189
|
+
profile: "prod",
|
|
190
|
+
baseUrl: DEFAULT_PRODUCTION_BASE_URL,
|
|
191
|
+
apiKey: "prod-token",
|
|
192
|
+
readOnly: false,
|
|
193
|
+
json: false,
|
|
194
|
+
profileSource: "config",
|
|
195
|
+
baseUrlSource: "config",
|
|
196
|
+
apiKeySource: "config",
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("still prefers an explicit base URL override over the production fallback", () => {
|
|
201
|
+
expect(
|
|
202
|
+
resolveRuntimeContext({
|
|
203
|
+
defaultProfile: "prod",
|
|
204
|
+
profiles: {
|
|
205
|
+
prod: { apiKey: "prod-token" },
|
|
206
|
+
},
|
|
207
|
+
}, {
|
|
208
|
+
profile: "prod",
|
|
209
|
+
baseUrl: "http://localhost:8088",
|
|
210
|
+
apiKey: "override-token",
|
|
211
|
+
}),
|
|
212
|
+
).toEqual({
|
|
213
|
+
profile: "prod",
|
|
214
|
+
baseUrl: "http://localhost:8088",
|
|
215
|
+
apiKey: "override-token",
|
|
216
|
+
readOnly: false,
|
|
217
|
+
json: false,
|
|
218
|
+
profileSource: "flag",
|
|
219
|
+
baseUrlSource: "flag",
|
|
220
|
+
apiKeySource: "flag",
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
179
224
|
it("throws a clear error when runtime api key is provided without base url", () => {
|
|
180
225
|
const previousApiKey = process.env[ENV_API_KEY];
|
|
181
226
|
const previousBaseUrl = process.env[ENV_BASE_URL];
|
package/src/config.ts
CHANGED
|
@@ -11,6 +11,7 @@ export const redactedSecretMask = "********";
|
|
|
11
11
|
export const ENV_API_KEY = "ZINKEE_API_KEY";
|
|
12
12
|
export const ENV_BASE_URL = "ZINKEE_API_BASE_URL";
|
|
13
13
|
export const ENV_PROFILE = "ZINKEE_PROFILE";
|
|
14
|
+
export const DEFAULT_PRODUCTION_BASE_URL = "https://api-z2.zinkee.com";
|
|
14
15
|
|
|
15
16
|
export class ProfileResolutionError extends Error {
|
|
16
17
|
override name = "ProfileResolutionError";
|
package/src/runtime-context.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AppConfig, RuntimeContext, RuntimeOverrides } from "./types.js";
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
DEFAULT_PRODUCTION_BASE_URL,
|
|
4
5
|
ENV_API_KEY,
|
|
5
6
|
ENV_BASE_URL,
|
|
6
7
|
readEnvApiKey,
|
|
@@ -70,7 +71,7 @@ export function resolveRuntimeContext(
|
|
|
70
71
|
|
|
71
72
|
return {
|
|
72
73
|
profile: profile.name,
|
|
73
|
-
baseUrl: baseUrlOverride ?? profile.baseUrl,
|
|
74
|
+
baseUrl: baseUrlOverride ?? profile.baseUrl ?? DEFAULT_PRODUCTION_BASE_URL,
|
|
74
75
|
apiKey: apiKeyOverride ?? profile.apiKey,
|
|
75
76
|
readOnly: overrides.readOnly ?? false,
|
|
76
77
|
json: overrides.json ?? false,
|