@neetru/sdk 3.5.0 → 3.6.0
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/CHANGELOG.md +22 -1
- package/dist/ai.cjs +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/auth.cjs +103 -85
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.mjs +103 -85
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.cjs +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/checkout.cjs +1 -1
- package/dist/checkout.mjs +1 -1
- package/dist/db.cjs +1 -1
- package/dist/db.mjs +1 -1
- package/dist/index.cjs +104 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +104 -86
- package/dist/index.mjs.map +1 -1
- package/dist/mobile.cjs +515 -0
- package/dist/mobile.cjs.map +1 -0
- package/dist/mobile.d.cts +89 -0
- package/dist/mobile.d.ts +89 -0
- package/dist/mobile.mjs +513 -0
- package/dist/mobile.mjs.map +1 -0
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/support.cjs +1 -1
- package/dist/support.mjs +1 -1
- package/dist/telemetry.cjs +1 -1
- package/dist/telemetry.mjs +1 -1
- package/dist/usage.cjs +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.mjs +1 -1
- package/package.json +6 -1
package/dist/catalog.cjs
CHANGED
package/dist/catalog.mjs
CHANGED
package/dist/checkout.cjs
CHANGED
package/dist/checkout.mjs
CHANGED
package/dist/db.cjs
CHANGED
package/dist/db.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -83,7 +83,7 @@ function compareCalVer(a, b) {
|
|
|
83
83
|
}
|
|
84
84
|
function readInjectedSdkVersion() {
|
|
85
85
|
try {
|
|
86
|
-
return "3.
|
|
86
|
+
return "3.6.0";
|
|
87
87
|
} catch {
|
|
88
88
|
return void 0;
|
|
89
89
|
}
|
|
@@ -7402,6 +7402,94 @@ var MockAi = class {
|
|
|
7402
7402
|
}
|
|
7403
7403
|
};
|
|
7404
7404
|
|
|
7405
|
+
// src/auth-pkce-shared.ts
|
|
7406
|
+
init_errors();
|
|
7407
|
+
function getWebCrypto() {
|
|
7408
|
+
const c = globalThis.crypto;
|
|
7409
|
+
if (!c || typeof c.getRandomValues !== "function" || !c.subtle) {
|
|
7410
|
+
throw new exports.NeetruError(
|
|
7411
|
+
"runtime_unsupported",
|
|
7412
|
+
"auth.signIn requer WebCrypto (crypto.subtle) \u2014 indispon\xEDvel neste runtime. Use HTTPS (ou http://localhost) num browser moderno, ou instale um polyfill WebCrypto (ex: react-native-quick-crypto) em React Native."
|
|
7413
|
+
);
|
|
7414
|
+
}
|
|
7415
|
+
return c;
|
|
7416
|
+
}
|
|
7417
|
+
function base64UrlFromBytes(bytes) {
|
|
7418
|
+
let str = "";
|
|
7419
|
+
for (const b of bytes) str += String.fromCharCode(b);
|
|
7420
|
+
const b64 = typeof btoa === "function" ? btoa(str) : Buffer.from(str, "binary").toString("base64");
|
|
7421
|
+
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
7422
|
+
}
|
|
7423
|
+
function randomUrlSafe(crypto2, byteLen) {
|
|
7424
|
+
const bytes = new Uint8Array(byteLen);
|
|
7425
|
+
crypto2.getRandomValues(bytes);
|
|
7426
|
+
return base64UrlFromBytes(bytes);
|
|
7427
|
+
}
|
|
7428
|
+
async function pkceChallengeS256(crypto2, verifier) {
|
|
7429
|
+
const data = new TextEncoder().encode(verifier);
|
|
7430
|
+
const digest = await crypto2.subtle.digest("SHA-256", data);
|
|
7431
|
+
return base64UrlFromBytes(new Uint8Array(digest));
|
|
7432
|
+
}
|
|
7433
|
+
function resolveIdpOrigin(baseUrl) {
|
|
7434
|
+
const overrideAuthUrl = typeof globalThis.NEETRU_AUTH_URL === "string" ? globalThis.NEETRU_AUTH_URL : null;
|
|
7435
|
+
return overrideAuthUrl ?? baseUrl.replace(/^https?:\/\/api\./, "https://auth.");
|
|
7436
|
+
}
|
|
7437
|
+
function resolveOidcClientId(config) {
|
|
7438
|
+
let clientId = config.oidcClientId;
|
|
7439
|
+
if (!clientId && config.apiKey) {
|
|
7440
|
+
clientId = parseApiKey(config.apiKey).keyId;
|
|
7441
|
+
}
|
|
7442
|
+
if (!clientId) {
|
|
7443
|
+
throw new exports.NeetruError(
|
|
7444
|
+
"invalid_config",
|
|
7445
|
+
"auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
|
|
7446
|
+
);
|
|
7447
|
+
}
|
|
7448
|
+
return clientId;
|
|
7449
|
+
}
|
|
7450
|
+
function buildAuthorizeUrl(params) {
|
|
7451
|
+
const url = new URL("/api/v1/oauth/authorize", params.idpOrigin);
|
|
7452
|
+
url.searchParams.set("response_type", "code");
|
|
7453
|
+
url.searchParams.set("client_id", params.clientId);
|
|
7454
|
+
url.searchParams.set("redirect_uri", params.redirectUri);
|
|
7455
|
+
url.searchParams.set("scope", params.scope);
|
|
7456
|
+
url.searchParams.set("state", params.state);
|
|
7457
|
+
url.searchParams.set("nonce", params.nonce);
|
|
7458
|
+
url.searchParams.set("code_challenge", params.codeChallenge);
|
|
7459
|
+
url.searchParams.set("code_challenge_method", "S256");
|
|
7460
|
+
return url;
|
|
7461
|
+
}
|
|
7462
|
+
function decodeJwtPayload(token) {
|
|
7463
|
+
const parts = token.split(".");
|
|
7464
|
+
if (parts.length !== 3) return null;
|
|
7465
|
+
try {
|
|
7466
|
+
const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
7467
|
+
const pad = "=".repeat((4 - b64.length % 4) % 4);
|
|
7468
|
+
const decoded = typeof atob === "function" ? atob(b64 + pad) : Buffer.from(b64 + pad, "base64").toString("utf-8");
|
|
7469
|
+
return JSON.parse(decoded);
|
|
7470
|
+
} catch {
|
|
7471
|
+
return null;
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
function jwtToNeetruUser(token) {
|
|
7475
|
+
const payload = decodeJwtPayload(token);
|
|
7476
|
+
if (!payload || typeof payload.sub !== "string") return null;
|
|
7477
|
+
if (typeof payload.exp === "number" && payload.exp * 1e3 < Date.now()) {
|
|
7478
|
+
return null;
|
|
7479
|
+
}
|
|
7480
|
+
return {
|
|
7481
|
+
uid: payload.sub,
|
|
7482
|
+
email: typeof payload.email === "string" ? payload.email : "",
|
|
7483
|
+
emailVerified: typeof payload.email_verified === "boolean" ? payload.email_verified : void 0,
|
|
7484
|
+
displayName: typeof payload.name === "string" ? payload.name : void 0,
|
|
7485
|
+
photoURL: typeof payload.picture === "string" ? payload.picture : void 0,
|
|
7486
|
+
isStaff: payload.is_staff === true,
|
|
7487
|
+
isCustomer: payload.is_customer === true,
|
|
7488
|
+
tenantId: typeof payload.tenant_id === "string" ? payload.tenant_id : void 0,
|
|
7489
|
+
...payload
|
|
7490
|
+
};
|
|
7491
|
+
}
|
|
7492
|
+
|
|
7405
7493
|
// src/auth.ts
|
|
7406
7494
|
function readEnvApiKey() {
|
|
7407
7495
|
try {
|
|
@@ -7456,36 +7544,6 @@ function _jwtPayloadToUser(payload) {
|
|
|
7456
7544
|
};
|
|
7457
7545
|
}
|
|
7458
7546
|
var OIDC_TX_KEY = "neetru_oauth_tx";
|
|
7459
|
-
function resolveIdpOrigin(baseUrl) {
|
|
7460
|
-
const overrideAuthUrl = typeof globalThis.NEETRU_AUTH_URL === "string" ? globalThis.NEETRU_AUTH_URL : null;
|
|
7461
|
-
return overrideAuthUrl ?? baseUrl.replace(/^https?:\/\/api\./, "https://auth.");
|
|
7462
|
-
}
|
|
7463
|
-
function getWebCrypto() {
|
|
7464
|
-
const c = globalThis.crypto;
|
|
7465
|
-
if (!c || typeof c.getRandomValues !== "function" || !c.subtle) {
|
|
7466
|
-
throw new exports.NeetruError(
|
|
7467
|
-
"runtime_unsupported",
|
|
7468
|
-
"auth.signIn requer WebCrypto (crypto.subtle) \u2014 indispon\xEDvel neste runtime. Use HTTPS (ou http://localhost) num browser moderno."
|
|
7469
|
-
);
|
|
7470
|
-
}
|
|
7471
|
-
return c;
|
|
7472
|
-
}
|
|
7473
|
-
function base64UrlFromBytes(bytes) {
|
|
7474
|
-
let str = "";
|
|
7475
|
-
for (const b of bytes) str += String.fromCharCode(b);
|
|
7476
|
-
const b64 = typeof btoa === "function" ? btoa(str) : Buffer.from(str, "binary").toString("base64");
|
|
7477
|
-
return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
7478
|
-
}
|
|
7479
|
-
function randomUrlSafe(crypto2, byteLen) {
|
|
7480
|
-
const bytes = new Uint8Array(byteLen);
|
|
7481
|
-
crypto2.getRandomValues(bytes);
|
|
7482
|
-
return base64UrlFromBytes(bytes);
|
|
7483
|
-
}
|
|
7484
|
-
async function pkceChallengeS256(crypto2, verifier) {
|
|
7485
|
-
const data = new TextEncoder().encode(verifier);
|
|
7486
|
-
const digest = await crypto2.subtle.digest("SHA-256", data);
|
|
7487
|
-
return base64UrlFromBytes(new Uint8Array(digest));
|
|
7488
|
-
}
|
|
7489
7547
|
function cleanCallbackUrl(parsed) {
|
|
7490
7548
|
try {
|
|
7491
7549
|
const history = globalThis.history;
|
|
@@ -7519,36 +7577,6 @@ function createOidcAuthNamespace(config) {
|
|
|
7519
7577
|
return null;
|
|
7520
7578
|
}
|
|
7521
7579
|
}
|
|
7522
|
-
function decodeJwtPayload(token) {
|
|
7523
|
-
const parts = token.split(".");
|
|
7524
|
-
if (parts.length !== 3) return null;
|
|
7525
|
-
try {
|
|
7526
|
-
const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
|
7527
|
-
const pad = "=".repeat((4 - b64.length % 4) % 4);
|
|
7528
|
-
const decoded = typeof atob === "function" ? atob(b64 + pad) : Buffer.from(b64 + pad, "base64").toString("utf-8");
|
|
7529
|
-
return JSON.parse(decoded);
|
|
7530
|
-
} catch {
|
|
7531
|
-
return null;
|
|
7532
|
-
}
|
|
7533
|
-
}
|
|
7534
|
-
function tokenToUser(token) {
|
|
7535
|
-
const payload = decodeJwtPayload(token);
|
|
7536
|
-
if (!payload || typeof payload.sub !== "string") return null;
|
|
7537
|
-
if (typeof payload.exp === "number" && payload.exp * 1e3 < Date.now()) {
|
|
7538
|
-
return null;
|
|
7539
|
-
}
|
|
7540
|
-
return {
|
|
7541
|
-
uid: payload.sub,
|
|
7542
|
-
email: typeof payload.email === "string" ? payload.email : "",
|
|
7543
|
-
emailVerified: typeof payload.email_verified === "boolean" ? payload.email_verified : void 0,
|
|
7544
|
-
displayName: typeof payload.name === "string" ? payload.name : void 0,
|
|
7545
|
-
photoURL: typeof payload.picture === "string" ? payload.picture : void 0,
|
|
7546
|
-
isStaff: payload.is_staff === true,
|
|
7547
|
-
isCustomer: payload.is_customer === true,
|
|
7548
|
-
tenantId: typeof payload.tenant_id === "string" ? payload.tenant_id : void 0,
|
|
7549
|
-
...payload
|
|
7550
|
-
};
|
|
7551
|
-
}
|
|
7552
7580
|
function loadCachedUser() {
|
|
7553
7581
|
if (cachedUser) {
|
|
7554
7582
|
const exp = cachedUser.exp;
|
|
@@ -7569,7 +7597,7 @@ function createOidcAuthNamespace(config) {
|
|
|
7569
7597
|
attemptSilentRefresh();
|
|
7570
7598
|
return null;
|
|
7571
7599
|
}
|
|
7572
|
-
const user =
|
|
7600
|
+
const user = jwtToNeetruUser(token);
|
|
7573
7601
|
if (!user) {
|
|
7574
7602
|
storage.removeItem(STORAGE_KEY);
|
|
7575
7603
|
attemptSilentRefresh();
|
|
@@ -7640,7 +7668,7 @@ function createOidcAuthNamespace(config) {
|
|
|
7640
7668
|
if (!res.ok || typeof payload?.error === "string") return false;
|
|
7641
7669
|
const idToken = payload?.id_token;
|
|
7642
7670
|
if (typeof idToken !== "string" || idToken.length === 0) return false;
|
|
7643
|
-
const user =
|
|
7671
|
+
const user = jwtToNeetruUser(idToken);
|
|
7644
7672
|
if (!user) return false;
|
|
7645
7673
|
const storage = getStorage();
|
|
7646
7674
|
storage?.setItem(STORAGE_KEY, idToken);
|
|
@@ -7686,17 +7714,7 @@ function createOidcAuthNamespace(config) {
|
|
|
7686
7714
|
}, msUntilExpiry + 1);
|
|
7687
7715
|
}
|
|
7688
7716
|
function resolveClientId() {
|
|
7689
|
-
|
|
7690
|
-
if (!clientId && config.apiKey) {
|
|
7691
|
-
clientId = parseApiKey(config.apiKey).keyId;
|
|
7692
|
-
}
|
|
7693
|
-
if (!clientId) {
|
|
7694
|
-
throw new exports.NeetruError(
|
|
7695
|
-
"invalid_config",
|
|
7696
|
-
"auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
|
|
7697
|
-
);
|
|
7698
|
-
}
|
|
7699
|
-
return clientId;
|
|
7717
|
+
return resolveOidcClientId(config);
|
|
7700
7718
|
}
|
|
7701
7719
|
async function handleRedirectCallback(currentUrl) {
|
|
7702
7720
|
const href = currentUrl ?? (typeof globalThis.location !== "undefined" ? globalThis.location.href : void 0);
|
|
@@ -7814,7 +7832,7 @@ function createOidcAuthNamespace(config) {
|
|
|
7814
7832
|
"nonce do id_token n\xE3o confere com o da transa\xE7\xE3o OIDC (poss\xEDvel replay). Token descartado."
|
|
7815
7833
|
);
|
|
7816
7834
|
}
|
|
7817
|
-
const user =
|
|
7835
|
+
const user = jwtToNeetruUser(idToken);
|
|
7818
7836
|
if (!user) {
|
|
7819
7837
|
throw new exports.NeetruError(
|
|
7820
7838
|
"token_exchange_failed",
|
|
@@ -7859,15 +7877,15 @@ function createOidcAuthNamespace(config) {
|
|
|
7859
7877
|
};
|
|
7860
7878
|
session.setItem(OIDC_TX_KEY, JSON.stringify(tx));
|
|
7861
7879
|
const idpOrigin = resolveIdpOrigin(config.baseUrl);
|
|
7862
|
-
const url =
|
|
7863
|
-
|
|
7864
|
-
|
|
7865
|
-
|
|
7866
|
-
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7880
|
+
const url = buildAuthorizeUrl({
|
|
7881
|
+
idpOrigin,
|
|
7882
|
+
clientId,
|
|
7883
|
+
redirectUri,
|
|
7884
|
+
scope,
|
|
7885
|
+
state,
|
|
7886
|
+
nonce,
|
|
7887
|
+
codeChallenge
|
|
7888
|
+
});
|
|
7871
7889
|
globalThis.location.assign(url.toString());
|
|
7872
7890
|
return;
|
|
7873
7891
|
}
|
|
@@ -7882,7 +7900,7 @@ function createOidcAuthNamespace(config) {
|
|
|
7882
7900
|
const storage = getStorage();
|
|
7883
7901
|
const token = storage?.getItem(STORAGE_KEY) ?? null;
|
|
7884
7902
|
if (!token) return null;
|
|
7885
|
-
return
|
|
7903
|
+
return jwtToNeetruUser(token) ? token : null;
|
|
7886
7904
|
},
|
|
7887
7905
|
async signOut() {
|
|
7888
7906
|
const storage = getStorage();
|
|
@@ -8045,7 +8063,7 @@ function getServerNeetruClient(config = {}) {
|
|
|
8045
8063
|
init_errors();
|
|
8046
8064
|
init_db_errors();
|
|
8047
8065
|
init_http();
|
|
8048
|
-
var VERSION = "3.
|
|
8066
|
+
var VERSION = "3.6.0";
|
|
8049
8067
|
|
|
8050
8068
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
8051
8069
|
exports.DEV_FIXTURE_USER = DEV_FIXTURE_USER;
|