@granular-software/sdk 0.4.9 → 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 +10 -0
- package/dist/cli/index.js +927 -254
- 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.js
CHANGED
|
@@ -5316,6 +5316,7 @@ var JobImplementation = class {
|
|
|
5316
5316
|
// src/endpoints.ts
|
|
5317
5317
|
var LOCAL_API_URL = "ws://localhost:8787/granular";
|
|
5318
5318
|
var PRODUCTION_API_URL = "wss://cf-api-gateway.arthur6084.workers.dev/granular";
|
|
5319
|
+
var DEFAULT_LOCAL_API_KEY = "gn_sk_tenant_default_principal_local_e2e_00000000";
|
|
5319
5320
|
function readEnv(name) {
|
|
5320
5321
|
if (typeof process === "undefined" || !process.env) return void 0;
|
|
5321
5322
|
return process.env[name];
|
|
@@ -5333,6 +5334,21 @@ function isTruthy(value) {
|
|
|
5333
5334
|
const normalized = value.trim().toLowerCase();
|
|
5334
5335
|
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
5335
5336
|
}
|
|
5337
|
+
function isLocalApiUrl(url) {
|
|
5338
|
+
try {
|
|
5339
|
+
const parsed = new URL(url);
|
|
5340
|
+
return parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1";
|
|
5341
|
+
} catch {
|
|
5342
|
+
return false;
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
function resolveAuthTokenForApiUrl(authToken, apiUrl) {
|
|
5346
|
+
if (!authToken.startsWith("sk_") || !isLocalApiUrl(apiUrl) || isTruthy(readEnv("GRANULAR_DISABLE_LOCAL_API_KEY_FALLBACK"))) {
|
|
5347
|
+
return authToken;
|
|
5348
|
+
}
|
|
5349
|
+
const override = readEnv("GRANULAR_LOCAL_API_KEY")?.trim();
|
|
5350
|
+
return override || DEFAULT_LOCAL_API_KEY;
|
|
5351
|
+
}
|
|
5336
5352
|
function resolveEndpointMode(explicitMode) {
|
|
5337
5353
|
const explicit = normalizeMode(explicitMode);
|
|
5338
5354
|
if (explicit === "local" || explicit === "production") {
|
|
@@ -6251,8 +6267,8 @@ var Granular = class {
|
|
|
6251
6267
|
if (!auth) {
|
|
6252
6268
|
throw new Error("Granular client requires either apiKey or token. Set GRANULAR_API_KEY or GRANULAR_TOKEN, or pass one in options.");
|
|
6253
6269
|
}
|
|
6254
|
-
this.apiKey = auth;
|
|
6255
6270
|
this.apiUrl = resolveApiUrl(options.apiUrl, options.endpointMode);
|
|
6271
|
+
this.apiKey = resolveAuthTokenForApiUrl(auth, this.apiUrl);
|
|
6256
6272
|
this.tokenProvider = options.tokenProvider;
|
|
6257
6273
|
this.WebSocketCtor = options.WebSocketCtor;
|
|
6258
6274
|
this.onUnexpectedClose = options.onUnexpectedClose;
|