@neetru/sdk 3.1.13 → 3.1.14
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/ai.cjs.map +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs.map +1 -1
- package/dist/auth.cjs +106 -9
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +106 -9
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs.map +1 -1
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs.map +1 -1
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs.map +1 -1
- package/dist/entitlements.cjs.map +1 -1
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs.map +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.mjs.map +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +107 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +107 -10
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs.map +1 -1
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/support.cjs.map +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs.map +1 -1
- package/dist/telemetry.cjs.map +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs.map +1 -1
- package/dist/{types-DJAGWjf0.d.cts → types-PzHvWMbV.d.cts} +6 -3
- package/dist/{types-BtQv-s0m.d.ts → types-iLDjiqqk.d.ts} +6 -3
- package/dist/usage.cjs.map +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs.map +1 -1
- package/dist/webhooks.cjs.map +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/package.json +1 -1
package/dist/auth.cjs
CHANGED
|
@@ -755,6 +755,7 @@ function isInsecureBypassActive() {
|
|
|
755
755
|
|
|
756
756
|
// src/types.ts
|
|
757
757
|
var DEFAULT_BASE_URL = "https://api.neetru.com";
|
|
758
|
+
var DEV_LOCAL_BASE_URL = "http://localhost:9003";
|
|
758
759
|
|
|
759
760
|
// src/catalog.ts
|
|
760
761
|
init_errors();
|
|
@@ -6089,7 +6090,7 @@ function resolveEnv(configEnv) {
|
|
|
6089
6090
|
try {
|
|
6090
6091
|
const proc = globalThis.process;
|
|
6091
6092
|
const val = proc?.env?.NEETRU_ENV;
|
|
6092
|
-
if (val === "dev" || val === "workspace" || val === "prod") return val;
|
|
6093
|
+
if (val === "dev" || val === "workspace" || val === "prod" || val === "dev-local") return val;
|
|
6093
6094
|
} catch {
|
|
6094
6095
|
}
|
|
6095
6096
|
try {
|
|
@@ -6175,9 +6176,11 @@ function cleanCallbackUrl(parsed) {
|
|
|
6175
6176
|
}
|
|
6176
6177
|
function createOidcAuthNamespace(config) {
|
|
6177
6178
|
const STORAGE_KEY = "neetru_id_token";
|
|
6179
|
+
const REFRESH_STORAGE_KEY = "neetru_refresh_token";
|
|
6178
6180
|
const listeners = /* @__PURE__ */ new Set();
|
|
6179
6181
|
let cachedUser = null;
|
|
6180
6182
|
let _expiryTimerId = null;
|
|
6183
|
+
let _refreshInFlight = null;
|
|
6181
6184
|
function getStorage() {
|
|
6182
6185
|
try {
|
|
6183
6186
|
return typeof globalThis.localStorage !== "undefined" ? globalThis.localStorage : null;
|
|
@@ -6230,6 +6233,7 @@ function createOidcAuthNamespace(config) {
|
|
|
6230
6233
|
const storage2 = getStorage();
|
|
6231
6234
|
storage2?.removeItem(STORAGE_KEY);
|
|
6232
6235
|
notify();
|
|
6236
|
+
attemptSilentRefresh();
|
|
6233
6237
|
return null;
|
|
6234
6238
|
}
|
|
6235
6239
|
return cachedUser;
|
|
@@ -6237,14 +6241,18 @@ function createOidcAuthNamespace(config) {
|
|
|
6237
6241
|
const storage = getStorage();
|
|
6238
6242
|
if (!storage) return null;
|
|
6239
6243
|
const token = storage.getItem(STORAGE_KEY);
|
|
6240
|
-
if (!token)
|
|
6244
|
+
if (!token) {
|
|
6245
|
+
attemptSilentRefresh();
|
|
6246
|
+
return null;
|
|
6247
|
+
}
|
|
6241
6248
|
const user = tokenToUser(token);
|
|
6242
6249
|
if (!user) {
|
|
6243
6250
|
storage.removeItem(STORAGE_KEY);
|
|
6251
|
+
attemptSilentRefresh();
|
|
6244
6252
|
return null;
|
|
6245
6253
|
}
|
|
6246
6254
|
cachedUser = user;
|
|
6247
|
-
|
|
6255
|
+
scheduleTokenRefresh(user);
|
|
6248
6256
|
return cachedUser;
|
|
6249
6257
|
}
|
|
6250
6258
|
function notify() {
|
|
@@ -6261,12 +6269,93 @@ function createOidcAuthNamespace(config) {
|
|
|
6261
6269
|
_expiryTimerId = null;
|
|
6262
6270
|
}
|
|
6263
6271
|
}
|
|
6264
|
-
function
|
|
6272
|
+
function getRefreshToken() {
|
|
6273
|
+
return getStorage()?.getItem(REFRESH_STORAGE_KEY) ?? null;
|
|
6274
|
+
}
|
|
6275
|
+
function clearSession() {
|
|
6276
|
+
cachedUser = null;
|
|
6277
|
+
const storage = getStorage();
|
|
6278
|
+
storage?.removeItem(STORAGE_KEY);
|
|
6279
|
+
storage?.removeItem(REFRESH_STORAGE_KEY);
|
|
6280
|
+
notify();
|
|
6281
|
+
}
|
|
6282
|
+
function refreshTokens() {
|
|
6283
|
+
if (_refreshInFlight) return _refreshInFlight;
|
|
6284
|
+
_refreshInFlight = (async () => {
|
|
6285
|
+
const refreshToken = getRefreshToken();
|
|
6286
|
+
if (!refreshToken) return false;
|
|
6287
|
+
let clientId;
|
|
6288
|
+
try {
|
|
6289
|
+
clientId = resolveClientId();
|
|
6290
|
+
} catch {
|
|
6291
|
+
return false;
|
|
6292
|
+
}
|
|
6293
|
+
const idpOrigin = resolveIdpOrigin(config.baseUrl);
|
|
6294
|
+
const tokenUrl = `${idpOrigin}/api/v1/oauth/token`;
|
|
6295
|
+
const form = new URLSearchParams({
|
|
6296
|
+
grant_type: "refresh_token",
|
|
6297
|
+
refresh_token: refreshToken,
|
|
6298
|
+
client_id: clientId
|
|
6299
|
+
});
|
|
6300
|
+
let res;
|
|
6301
|
+
try {
|
|
6302
|
+
res = await config.fetch(tokenUrl, {
|
|
6303
|
+
method: "POST",
|
|
6304
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
6305
|
+
body: form.toString()
|
|
6306
|
+
});
|
|
6307
|
+
} catch {
|
|
6308
|
+
return false;
|
|
6309
|
+
}
|
|
6310
|
+
let payload = null;
|
|
6311
|
+
try {
|
|
6312
|
+
payload = await res.json();
|
|
6313
|
+
} catch {
|
|
6314
|
+
payload = null;
|
|
6315
|
+
}
|
|
6316
|
+
if (!res.ok || typeof payload?.error === "string") return false;
|
|
6317
|
+
const idToken = payload?.id_token;
|
|
6318
|
+
if (typeof idToken !== "string" || idToken.length === 0) return false;
|
|
6319
|
+
const user = tokenToUser(idToken);
|
|
6320
|
+
if (!user) return false;
|
|
6321
|
+
const storage = getStorage();
|
|
6322
|
+
storage?.setItem(STORAGE_KEY, idToken);
|
|
6323
|
+
const rotated = payload?.refresh_token;
|
|
6324
|
+
if (typeof rotated === "string" && rotated.length > 0) {
|
|
6325
|
+
storage?.setItem(REFRESH_STORAGE_KEY, rotated);
|
|
6326
|
+
}
|
|
6327
|
+
cachedUser = user;
|
|
6328
|
+
scheduleTokenRefresh(user);
|
|
6329
|
+
notify();
|
|
6330
|
+
return true;
|
|
6331
|
+
})().finally(() => {
|
|
6332
|
+
_refreshInFlight = null;
|
|
6333
|
+
});
|
|
6334
|
+
return _refreshInFlight;
|
|
6335
|
+
}
|
|
6336
|
+
function attemptSilentRefresh() {
|
|
6337
|
+
if (!getRefreshToken()) return;
|
|
6338
|
+
void refreshTokens().then((ok) => {
|
|
6339
|
+
if (!ok) clearSession();
|
|
6340
|
+
});
|
|
6341
|
+
}
|
|
6342
|
+
function scheduleTokenRefresh(user) {
|
|
6265
6343
|
cancelExpiryTimer();
|
|
6266
6344
|
const exp = user.exp;
|
|
6267
6345
|
if (typeof exp !== "number") return;
|
|
6268
6346
|
const msUntilExpiry = exp * 1e3 - Date.now();
|
|
6269
6347
|
if (msUntilExpiry <= 0) return;
|
|
6348
|
+
if (getRefreshToken()) {
|
|
6349
|
+
const lead = Math.min(msUntilExpiry, Math.max(3e4, msUntilExpiry * 0.2));
|
|
6350
|
+
const delay = Math.max(1, msUntilExpiry - lead);
|
|
6351
|
+
_expiryTimerId = setTimeout(() => {
|
|
6352
|
+
_expiryTimerId = null;
|
|
6353
|
+
void refreshTokens().then((ok) => {
|
|
6354
|
+
if (!ok) clearSession();
|
|
6355
|
+
});
|
|
6356
|
+
}, delay);
|
|
6357
|
+
return;
|
|
6358
|
+
}
|
|
6270
6359
|
_expiryTimerId = setTimeout(() => {
|
|
6271
6360
|
_expiryTimerId = null;
|
|
6272
6361
|
loadCachedUser();
|
|
@@ -6408,9 +6497,14 @@ function createOidcAuthNamespace(config) {
|
|
|
6408
6497
|
"id_token retornado pelo /token n\xE3o tem `sub` ou j\xE1 est\xE1 expirado."
|
|
6409
6498
|
);
|
|
6410
6499
|
}
|
|
6411
|
-
getStorage()
|
|
6500
|
+
const storage = getStorage();
|
|
6501
|
+
storage?.setItem(STORAGE_KEY, idToken);
|
|
6502
|
+
const refreshToken = payload?.refresh_token;
|
|
6503
|
+
if (typeof refreshToken === "string" && refreshToken.length > 0) {
|
|
6504
|
+
storage?.setItem(REFRESH_STORAGE_KEY, refreshToken);
|
|
6505
|
+
}
|
|
6412
6506
|
cachedUser = user;
|
|
6413
|
-
|
|
6507
|
+
scheduleTokenRefresh(user);
|
|
6414
6508
|
notify();
|
|
6415
6509
|
return { user, postLoginRedirect: tx.postLoginRedirect };
|
|
6416
6510
|
}
|
|
@@ -6469,7 +6563,10 @@ function createOidcAuthNamespace(config) {
|
|
|
6469
6563
|
async signOut() {
|
|
6470
6564
|
const storage = getStorage();
|
|
6471
6565
|
const storedToken = storage?.getItem(STORAGE_KEY) ?? null;
|
|
6472
|
-
if (storage)
|
|
6566
|
+
if (storage) {
|
|
6567
|
+
storage.removeItem(STORAGE_KEY);
|
|
6568
|
+
storage.removeItem(REFRESH_STORAGE_KEY);
|
|
6569
|
+
}
|
|
6473
6570
|
cancelExpiryTimer();
|
|
6474
6571
|
cachedUser = null;
|
|
6475
6572
|
const overrideAuthUrl = typeof globalThis.NEETRU_AUTH_URL === "string" ? globalThis.NEETRU_AUTH_URL : null;
|
|
@@ -6573,10 +6670,10 @@ function createNeetruClient(config = {}) {
|
|
|
6573
6670
|
"fetch is not available in this runtime. Pass `fetch` explicitly to createNeetruClient."
|
|
6574
6671
|
);
|
|
6575
6672
|
}
|
|
6576
|
-
const rawBaseUrl = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
6577
|
-
const baseUrl = validateBaseUrl(rawBaseUrl, config.allowedHosts ?? []);
|
|
6578
6673
|
const apiKey = config.apiKey ?? readEnvApiKey();
|
|
6579
6674
|
const env = resolveEnv(config.env);
|
|
6675
|
+
const rawBaseUrl = config.baseUrl ?? (env === "dev-local" ? DEV_LOCAL_BASE_URL : DEFAULT_BASE_URL);
|
|
6676
|
+
const baseUrl = validateBaseUrl(rawBaseUrl, config.allowedHosts ?? []);
|
|
6580
6677
|
const resolved = Object.freeze({
|
|
6581
6678
|
apiKey,
|
|
6582
6679
|
oidcClientId: config.oidcClientId,
|