@granular-software/sdk 0.4.10 → 0.4.11
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/README.md +2 -0
- package/dist/cli/index.js +31 -9
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5294,6 +5294,7 @@ var JobImplementation = class {
|
|
|
5294
5294
|
// src/endpoints.ts
|
|
5295
5295
|
var LOCAL_API_URL = "ws://localhost:8787/granular";
|
|
5296
5296
|
var PRODUCTION_API_URL = "wss://cf-api-gateway.arthur6084.workers.dev/granular";
|
|
5297
|
+
var DEFAULT_LOCAL_API_KEY = "gn_sk_tenant_default_principal_local_e2e_00000000";
|
|
5297
5298
|
function readEnv(name) {
|
|
5298
5299
|
if (typeof process === "undefined" || !process.env) return void 0;
|
|
5299
5300
|
return process.env[name];
|
|
@@ -5311,6 +5312,21 @@ function isTruthy(value) {
|
|
|
5311
5312
|
const normalized = value.trim().toLowerCase();
|
|
5312
5313
|
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
5313
5314
|
}
|
|
5315
|
+
function isLocalApiUrl(url) {
|
|
5316
|
+
try {
|
|
5317
|
+
const parsed = new URL(url);
|
|
5318
|
+
return parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
|
|
5319
|
+
} catch {
|
|
5320
|
+
return false;
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5323
|
+
function resolveAuthTokenForApiUrl(authToken, apiUrl) {
|
|
5324
|
+
if (!authToken.startsWith("sk_") || !isLocalApiUrl(apiUrl) || isTruthy(readEnv("GRANULAR_DISABLE_LOCAL_API_KEY_FALLBACK"))) {
|
|
5325
|
+
return authToken;
|
|
5326
|
+
}
|
|
5327
|
+
const override = readEnv("GRANULAR_LOCAL_API_KEY")?.trim();
|
|
5328
|
+
return override || DEFAULT_LOCAL_API_KEY;
|
|
5329
|
+
}
|
|
5314
5330
|
function resolveEndpointMode(explicitMode) {
|
|
5315
5331
|
const explicit = normalizeMode(explicitMode);
|
|
5316
5332
|
if (explicit === "local" || explicit === "production") {
|
|
@@ -6229,8 +6245,8 @@ var Granular = class {
|
|
|
6229
6245
|
if (!auth) {
|
|
6230
6246
|
throw new Error("Granular client requires either apiKey or token. Set GRANULAR_API_KEY or GRANULAR_TOKEN, or pass one in options.");
|
|
6231
6247
|
}
|
|
6232
|
-
this.apiKey = auth;
|
|
6233
6248
|
this.apiUrl = resolveApiUrl(options.apiUrl, options.endpointMode);
|
|
6249
|
+
this.apiKey = resolveAuthTokenForApiUrl(auth, this.apiUrl);
|
|
6234
6250
|
this.tokenProvider = options.tokenProvider;
|
|
6235
6251
|
this.WebSocketCtor = options.WebSocketCtor;
|
|
6236
6252
|
this.onUnexpectedClose = options.onUnexpectedClose;
|