@absolutejs/auth 0.22.5 → 0.22.7
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/example/components/auth/AuthContainer.d.ts +1 -0
- package/dist/example/components/auth/OAuthButton.d.ts +7 -0
- package/dist/example/components/auth/OAuthButtons.d.ts +5 -0
- package/dist/example/components/hamburger/HamburgerDropdown.d.ts +10 -0
- package/dist/example/components/hamburger/HamburgerHeader.d.ts +5 -0
- package/dist/example/components/hamburger/HamburgerMenu.d.ts +14 -0
- package/dist/example/components/hamburger/HamburgerUserButtons.d.ts +8 -0
- package/dist/example/components/navbar/DropdownContainer.d.ts +17 -0
- package/dist/example/components/navbar/Navbar.d.ts +7 -0
- package/dist/example/components/navbar/NavbarDropdown.d.ts +10 -0
- package/dist/example/components/navbar/NavbarLink.d.ts +8 -0
- package/dist/example/components/navbar/NavbarLinks.d.ts +6 -0
- package/dist/example/components/navbar/NavbarUserButtons.d.ts +7 -0
- package/dist/example/components/page/Head.d.ts +6 -0
- package/dist/example/components/protected/AccountOverview.d.ts +6 -0
- package/dist/example/components/protected/DeleteAccountSection.d.ts +5 -0
- package/dist/example/components/protected/LinkedAuthIdentitiesPanel.d.ts +1 -0
- package/dist/example/components/protected/LinkedProvidersPanel.d.ts +1 -0
- package/dist/example/components/protected/ProviderButtons.d.ts +1 -0
- package/dist/example/components/protected/SettingsNoticeToast.d.ts +1 -0
- package/dist/example/components/protected/UserInfo.d.ts +7 -0
- package/dist/example/components/utils/AnimatedComponents.d.ts +1 -0
- package/dist/example/components/utils/Divider.d.ts +7 -0
- package/dist/example/components/utils/HighlightedJson.d.ts +5 -0
- package/dist/example/components/utils/JsonLine.d.ts +6 -0
- package/dist/example/components/utils/Modal.d.ts +9 -0
- package/dist/example/components/utils/ProfilePicture.d.ts +8 -0
- package/dist/example/components/utils/ProviderDropdown.d.ts +8 -0
- package/dist/example/components/utils/Toast.d.ts +14 -0
- package/dist/example/components/utils/ToastProvider.d.ts +30 -0
- package/dist/example/db/schema.d.ts +2570 -0
- package/dist/example/eden/treaty.d.ts +1 -0
- package/dist/example/handlers/userHandlers.d.ts +254 -0
- package/dist/example/hooks/useAuthIdentityPayload.d.ts +37 -0
- package/dist/example/hooks/useAuthStatus.d.ts +19 -0
- package/dist/example/hooks/useContainerQuery.d.ts +10 -0
- package/dist/example/hooks/useMediaQuery.d.ts +11 -0
- package/dist/example/linkedProviders/persistCallbackAuthorization.d.ts +30 -0
- package/dist/example/linkedProviders/resolver.d.ts +1 -0
- package/dist/example/linkedProviders/stores.d.ts +9 -0
- package/dist/example/pages/Connectors.d.ts +1 -0
- package/dist/example/pages/Home.d.ts +1 -0
- package/dist/example/pages/NotAuthorized.d.ts +1 -0
- package/dist/example/pages/Protected.d.ts +1 -0
- package/dist/example/pages/Settings.d.ts +1 -0
- package/dist/example/server.d.ts +902 -0
- package/dist/example/styles/authModalStyles.d.ts +22 -0
- package/dist/example/styles/navbarStyles.d.ts +15 -0
- package/dist/example/styles/styles.d.ts +15 -0
- package/dist/example/utils/absoluteAuthConfig.d.ts +4 -0
- package/dist/example/utils/constants.d.ts +1 -0
- package/dist/example/utils/navbarData.d.ts +2 -0
- package/dist/example/utils/providerData.d.ts +9 -0
- package/dist/example/utils/providersConfiguration.d.ts +1 -0
- package/dist/example/utils/typeGuards.d.ts +1 -0
- package/dist/example/utils/types.d.ts +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +729 -612
- package/dist/index.js.map +8 -7
- package/dist/src/index.d.ts +1 -0
- package/dist/src/neonAuthSessionStore.d.ts +563 -0
- package/package.json +86 -74
- package/.claude/settings.local.json +0 -5
- package/.env.example +0 -212
- package/.prettierignore +0 -4
- package/.prettierrc.json +0 -9
- package/CLAUDE.md +0 -91
- package/drizzle.config.ts +0 -14
- package/eslint.config.mjs +0 -251
package/dist/index.js
CHANGED
|
@@ -3192,19 +3192,22 @@ var signout = ({
|
|
|
3192
3192
|
userSessionId: user_session_id.value
|
|
3193
3193
|
});
|
|
3194
3194
|
const signoutSession = authSessionStore ? compatibilityLayer.session : session;
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
error
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3195
|
+
const currentSession = signoutSession[user_session_id.value];
|
|
3196
|
+
if (currentSession !== undefined) {
|
|
3197
|
+
try {
|
|
3198
|
+
await onSignOut?.({
|
|
3199
|
+
authProvider: auth_provider.value,
|
|
3200
|
+
session: signoutSession,
|
|
3201
|
+
userSessionId: user_session_id.value
|
|
3202
|
+
});
|
|
3203
|
+
} catch (err) {
|
|
3204
|
+
console.error("[signout] Sign out operation failed:", {
|
|
3205
|
+
authProvider: auth_provider.value,
|
|
3206
|
+
error: err instanceof Error ? err.message : err,
|
|
3207
|
+
stack: err instanceof Error ? err.stack : undefined
|
|
3208
|
+
});
|
|
3209
|
+
return status("Internal Server Error", "Sign out operation failed");
|
|
3210
|
+
}
|
|
3208
3211
|
}
|
|
3209
3212
|
delete signoutSession[user_session_id.value];
|
|
3210
3213
|
if (authSessionStore) {
|
|
@@ -3219,7 +3222,7 @@ var signout = ({
|
|
|
3219
3222
|
return new Response(null, { status: 204 });
|
|
3220
3223
|
}, {
|
|
3221
3224
|
cookie: t8.Cookie({
|
|
3222
|
-
auth_provider: authProviderOption,
|
|
3225
|
+
auth_provider: t8.Optional(authProviderOption),
|
|
3223
3226
|
user_session_id: t8.Optional(t8.TemplateLiteral("${string}-${string}-${string}-${string}-${string}"))
|
|
3224
3227
|
})
|
|
3225
3228
|
});
|
|
@@ -3289,399 +3292,154 @@ var createInMemoryAuthSessionStore = (input = {}) => {
|
|
|
3289
3292
|
listUnregisteredSessionIds: async () => [...unregisteredSessions.keys()]
|
|
3290
3293
|
};
|
|
3291
3294
|
};
|
|
3292
|
-
//
|
|
3293
|
-
var
|
|
3294
|
-
var
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3295
|
+
// node_modules/@neondatabase/serverless/index.mjs
|
|
3296
|
+
var vo = Object.create;
|
|
3297
|
+
var Te = Object.defineProperty;
|
|
3298
|
+
var xo = Object.getOwnPropertyDescriptor;
|
|
3299
|
+
var So = Object.getOwnPropertyNames;
|
|
3300
|
+
var Eo = Object.getPrototypeOf;
|
|
3301
|
+
var Ao = Object.prototype.hasOwnProperty;
|
|
3302
|
+
var Co = (r, e, t10) => (e in r) ? Te(r, e, { enumerable: true, configurable: true, writable: true, value: t10 }) : r[e] = t10;
|
|
3303
|
+
var a = (r, e) => Te(r, "name", { value: e, configurable: true });
|
|
3304
|
+
var z = (r, e) => () => (r && (e = r(r = 0)), e);
|
|
3305
|
+
var I = (r, e) => () => (e || r((e = { exports: {} }).exports, e), e.exports);
|
|
3306
|
+
var ne = (r, e) => {
|
|
3307
|
+
for (var t10 in e)
|
|
3308
|
+
Te(r, t10, {
|
|
3309
|
+
get: e[t10],
|
|
3310
|
+
enumerable: true
|
|
3311
|
+
});
|
|
3300
3312
|
};
|
|
3301
|
-
var
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
return true;
|
|
3307
|
-
if (lease.expiresAt === undefined)
|
|
3308
|
-
return false;
|
|
3309
|
-
return lease.expiresAt <= now + (minValidityMs ?? 0);
|
|
3313
|
+
var Mn = (r, e, t10, n) => {
|
|
3314
|
+
if (e && typeof e == "object" || typeof e == "function")
|
|
3315
|
+
for (let i of So(e))
|
|
3316
|
+
!Ao.call(r, i) && i !== t10 && Te(r, i, { get: () => e[i], enumerable: !(n = xo(e, i)) || n.enumerable });
|
|
3317
|
+
return r;
|
|
3310
3318
|
};
|
|
3311
|
-
var
|
|
3312
|
-
|
|
3313
|
-
|
|
3319
|
+
var xe = (r, e, t10) => (t10 = r != null ? vo(Eo(r)) : {}, Mn(e || !r || !r.__esModule ? Te(t10, "default", { value: r, enumerable: true }) : t10, r));
|
|
3320
|
+
var D = (r) => Mn(Te({}, "__esModule", { value: true }), r);
|
|
3321
|
+
var E = (r, e, t10) => Co(r, typeof e != "symbol" ? e + "" : e, t10);
|
|
3322
|
+
var On = I((ct) => {
|
|
3323
|
+
p();
|
|
3324
|
+
ct.byteLength = To;
|
|
3325
|
+
ct.toByteArray = Po;
|
|
3326
|
+
ct.fromByteArray = Lo;
|
|
3327
|
+
var ue = [], ee = [], _o = typeof Uint8Array < "u" ? Uint8Array : Array, Ut = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3328
|
+
for (Se = 0, Un = Ut.length;Se < Un; ++Se)
|
|
3329
|
+
ue[Se] = Ut[Se], ee[Ut.charCodeAt(Se)] = Se;
|
|
3330
|
+
var Se, Un;
|
|
3331
|
+
ee[45] = 62;
|
|
3332
|
+
ee[95] = 63;
|
|
3333
|
+
function Dn(r) {
|
|
3334
|
+
var e = r.length;
|
|
3335
|
+
if (e % 4 > 0)
|
|
3336
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
3337
|
+
var t10 = r.indexOf("=");
|
|
3338
|
+
t10 === -1 && (t10 = e);
|
|
3339
|
+
var n = t10 === e ? 0 : 4 - t10 % 4;
|
|
3340
|
+
return [t10, n];
|
|
3314
3341
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
return;
|
|
3319
|
-
if (lease.expiresAt <= now + (minValidityMs ?? 0)) {
|
|
3320
|
-
throw new Error("Linked provider access token lease does not satisfy minimum validity");
|
|
3342
|
+
a(Dn, "getLens");
|
|
3343
|
+
function To(r) {
|
|
3344
|
+
var e = Dn(r), t10 = e[0], n = e[1];
|
|
3345
|
+
return (t10 + n) * 3 / 4 - n;
|
|
3321
3346
|
}
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
grantId: grant.id,
|
|
3326
|
-
ownerRef: grant.ownerRef,
|
|
3327
|
-
connectorProvider: binding.connectorProvider,
|
|
3328
|
-
providerFamily: grant.providerFamily,
|
|
3329
|
-
authProviderKey: grant.authProviderKey,
|
|
3330
|
-
externalAccountId: binding.externalAccountId,
|
|
3331
|
-
externalAccountType: binding.externalAccountType,
|
|
3332
|
-
scopes: getEffectiveScopes(grant, binding),
|
|
3333
|
-
capabilities: binding.capabilities ? [...binding.capabilities] : undefined,
|
|
3334
|
-
label: binding.label,
|
|
3335
|
-
username: binding.username,
|
|
3336
|
-
email: binding.email,
|
|
3337
|
-
metadata: {
|
|
3338
|
-
...grant.metadata ?? {},
|
|
3339
|
-
...binding.metadata ?? {}
|
|
3347
|
+
a(To, "byteLength");
|
|
3348
|
+
function Io(r, e, t10) {
|
|
3349
|
+
return (e + t10) * 3 / 4 - t10;
|
|
3340
3350
|
}
|
|
3351
|
+
a(Io, "_byteLength");
|
|
3352
|
+
function Po(r) {
|
|
3353
|
+
var e, t10 = Dn(r), n = t10[0], i = t10[1], s = new _o(Io(r, n, i)), o = 0, u = i > 0 ? n - 4 : n, c;
|
|
3354
|
+
for (c = 0;c < u; c += 4)
|
|
3355
|
+
e = ee[r.charCodeAt(c)] << 18 | ee[r.charCodeAt(c + 1)] << 12 | ee[r.charCodeAt(c + 2)] << 6 | ee[r.charCodeAt(c + 3)], s[o++] = e >> 16 & 255, s[o++] = e >> 8 & 255, s[o++] = e & 255;
|
|
3356
|
+
return i === 2 && (e = ee[r.charCodeAt(c)] << 2 | ee[r.charCodeAt(c + 1)] >> 4, s[o++] = e & 255), i === 1 && (e = ee[r.charCodeAt(c)] << 10 | ee[r.charCodeAt(c + 1)] << 4 | ee[r.charCodeAt(c + 2)] >> 2, s[o++] = e >> 8 & 255, s[o++] = e & 255), s;
|
|
3357
|
+
}
|
|
3358
|
+
a(Po, "toByteArray");
|
|
3359
|
+
function Ro(r) {
|
|
3360
|
+
return ue[r >> 18 & 63] + ue[r >> 12 & 63] + ue[r >> 6 & 63] + ue[r & 63];
|
|
3361
|
+
}
|
|
3362
|
+
a(Ro, "tripletToBase64");
|
|
3363
|
+
function Bo(r, e, t10) {
|
|
3364
|
+
for (var n, i = [], s = e;s < t10; s += 3)
|
|
3365
|
+
n = (r[s] << 16 & 16711680) + (r[s + 1] << 8 & 65280) + (r[s + 2] & 255), i.push(Ro(n));
|
|
3366
|
+
return i.join("");
|
|
3367
|
+
}
|
|
3368
|
+
a(Bo, "encodeChunk");
|
|
3369
|
+
function Lo(r) {
|
|
3370
|
+
for (var e, t10 = r.length, n = t10 % 3, i = [], s = 16383, o = 0, u = t10 - n;o < u; o += s)
|
|
3371
|
+
i.push(Bo(r, o, o + s > u ? u : o + s));
|
|
3372
|
+
return n === 1 ? (e = r[t10 - 1], i.push(ue[e >> 2] + ue[e << 4 & 63] + "==")) : n === 2 && (e = (r[t10 - 2] << 8) + r[t10 - 1], i.push(ue[e >> 10] + ue[e >> 4 & 63] + ue[e << 2 & 63] + "=")), i.join("");
|
|
3373
|
+
}
|
|
3374
|
+
a(Lo, "fromByteArray");
|
|
3341
3375
|
});
|
|
3342
|
-
var
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
onReportFailure
|
|
3357
|
-
}) => ({
|
|
3358
|
-
listBindings: async ({ ownerRef, connectorProvider, status }) => sortNewestFirst(await bindingStore.listBindingsByOwner(ownerRef)).filter((binding) => (connectorProvider === undefined || binding.connectorProvider === connectorProvider) && (status === undefined || binding.status === status)),
|
|
3359
|
-
resolveCredential: async (input) => {
|
|
3360
|
-
const bindings = sortNewestFirst(await bindingStore.listBindingsByOwner(input.ownerRef)).filter((binding) => binding.connectorProvider === input.connectorProvider && isBindingUsable(binding) && (input.bindingId === undefined || binding.id === input.bindingId) && (input.externalAccountId === undefined || binding.externalAccountId === input.externalAccountId));
|
|
3361
|
-
for (const binding of bindings) {
|
|
3362
|
-
const grant = await grantStore.getGrant(binding.grantId);
|
|
3363
|
-
if (!grant || grant.ownerRef !== input.ownerRef || !isGrantUsable(grant)) {
|
|
3364
|
-
continue;
|
|
3365
|
-
}
|
|
3366
|
-
const effectiveScopes = getEffectiveScopes(grant, binding);
|
|
3367
|
-
if (!hasRequiredScopes(effectiveScopes, input.requiredScopes)) {
|
|
3368
|
-
continue;
|
|
3369
|
-
}
|
|
3370
|
-
return buildResolvedCredential(grant, binding);
|
|
3371
|
-
}
|
|
3372
|
-
return null;
|
|
3373
|
-
},
|
|
3374
|
-
getAccessToken: async (credential, input) => {
|
|
3375
|
-
const binding = await bindingStore.getBinding(credential.bindingId);
|
|
3376
|
-
if (!binding || !isBindingUsable(binding)) {
|
|
3377
|
-
throw new Error("Linked provider binding is unavailable");
|
|
3378
|
-
}
|
|
3379
|
-
const grant = await grantStore.getGrant(credential.grantId);
|
|
3380
|
-
if (!grant || !isGrantUsable(grant)) {
|
|
3381
|
-
throw new Error("Linked provider grant is unavailable");
|
|
3382
|
-
}
|
|
3383
|
-
const requiredScopes = input?.requiredScopes;
|
|
3384
|
-
const effectiveScopes = getEffectiveScopes(grant, binding);
|
|
3385
|
-
if (!hasRequiredScopes(effectiveScopes, requiredScopes)) {
|
|
3386
|
-
throw new Error("Linked provider credential is missing required scopes");
|
|
3376
|
+
var qn = I((Dt) => {
|
|
3377
|
+
p();
|
|
3378
|
+
Dt.read = function(r, e, t10, n, i) {
|
|
3379
|
+
var s, o, u = i * 8 - n - 1, c = (1 << u) - 1, l = c >> 1, f = -7, y = t10 ? i - 1 : 0, g = t10 ? -1 : 1, A = r[e + y];
|
|
3380
|
+
for (y += g, s = A & (1 << -f) - 1, A >>= -f, f += u;f > 0; s = s * 256 + r[e + y], y += g, f -= 8)
|
|
3381
|
+
;
|
|
3382
|
+
for (o = s & (1 << -f) - 1, s >>= -f, f += n;f > 0; o = o * 256 + r[e + y], y += g, f -= 8)
|
|
3383
|
+
;
|
|
3384
|
+
if (s === 0)
|
|
3385
|
+
s = 1 - l;
|
|
3386
|
+
else {
|
|
3387
|
+
if (s === c)
|
|
3388
|
+
return o ? NaN : (A ? -1 : 1) * (1 / 0);
|
|
3389
|
+
o = o + Math.pow(2, n), s = s - l;
|
|
3387
3390
|
}
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3391
|
+
return (A ? -1 : 1) * o * Math.pow(2, s - n);
|
|
3392
|
+
};
|
|
3393
|
+
Dt.write = function(r, e, t10, n, i, s) {
|
|
3394
|
+
var o, u, c, l = s * 8 - i - 1, f = (1 << l) - 1, y = f >> 1, g = i === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, A = n ? 0 : s - 1, C = n ? 1 : -1, Q = e < 0 || e === 0 && 1 / e < 0 ? 1 : 0;
|
|
3395
|
+
for (e = Math.abs(e), isNaN(e) || e === 1 / 0 ? (u = isNaN(e) ? 1 : 0, o = f) : (o = Math.floor(Math.log(e) / Math.LN2), e * (c = Math.pow(2, -o)) < 1 && (o--, c *= 2), o + y >= 1 ? e += g / c : e += g * Math.pow(2, 1 - y), e * c >= 2 && (o++, c /= 2), o + y >= f ? (u = 0, o = f) : o + y >= 1 ? (u = (e * c - 1) * Math.pow(2, i), o = o + y) : (u = e * Math.pow(2, y - 1) * Math.pow(2, i), o = 0));i >= 8; r[t10 + A] = u & 255, A += C, u /= 256, i -= 8)
|
|
3396
|
+
;
|
|
3397
|
+
for (o = o << i | u, l += i;l > 0; r[t10 + A] = o & 255, A += C, o /= 256, l -= 8)
|
|
3398
|
+
;
|
|
3399
|
+
r[t10 + A - C] |= Q * 128;
|
|
3400
|
+
};
|
|
3401
|
+
});
|
|
3402
|
+
var ri = I((Be) => {
|
|
3403
|
+
p();
|
|
3404
|
+
var Ot = On(), Pe = qn(), Qn = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
3405
|
+
Be.Buffer = h;
|
|
3406
|
+
Be.SlowBuffer = Oo;
|
|
3407
|
+
Be.INSPECT_MAX_BYTES = 50;
|
|
3408
|
+
var lt = 2147483647;
|
|
3409
|
+
Be.kMaxLength = lt;
|
|
3410
|
+
h.TYPED_ARRAY_SUPPORT = Fo();
|
|
3411
|
+
!h.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
|
|
3412
|
+
function Fo() {
|
|
3413
|
+
try {
|
|
3414
|
+
let r = new Uint8Array(1), e = { foo: a(function() {
|
|
3415
|
+
return 42;
|
|
3416
|
+
}, "foo") };
|
|
3417
|
+
return Object.setPrototypeOf(e, Uint8Array.prototype), Object.setPrototypeOf(r, e), r.foo() === 42;
|
|
3418
|
+
} catch {
|
|
3419
|
+
return false;
|
|
3400
3420
|
}
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
if (
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
}
|
|
3424
|
-
if (binding) {
|
|
3425
|
-
const nextBinding = {
|
|
3426
|
-
...binding,
|
|
3427
|
-
updatedAt: currentTime,
|
|
3428
|
-
metadata: annotateFailureMetadata(binding.metadata, report, currentTime)
|
|
3429
|
-
};
|
|
3430
|
-
if (report.code === "unauthorized" || report.code === "revoked") {
|
|
3431
|
-
nextBinding.status = "disconnected";
|
|
3432
|
-
} else if (report.code === "insufficient_scope") {
|
|
3433
|
-
nextBinding.status = "restricted";
|
|
3434
|
-
}
|
|
3435
|
-
await bindingStore.saveBinding(nextBinding);
|
|
3436
|
-
}
|
|
3437
|
-
await onReportFailure?.({
|
|
3438
|
-
credential,
|
|
3439
|
-
report,
|
|
3440
|
-
grant: grant ?? undefined,
|
|
3441
|
-
binding: binding ?? undefined
|
|
3442
|
-
});
|
|
3443
|
-
}
|
|
3444
|
-
});
|
|
3445
|
-
// src/oauthLinkedProviderResolver.ts
|
|
3446
|
-
var getGrantedScopes = (scopeValue, fallbackScopes) => {
|
|
3447
|
-
if (typeof scopeValue === "string" && scopeValue.trim().length > 0) {
|
|
3448
|
-
return [...new Set(scopeValue.split(/\s+/).filter(Boolean))];
|
|
3449
|
-
}
|
|
3450
|
-
return [...new Set(fallbackScopes.filter(Boolean))];
|
|
3451
|
-
};
|
|
3452
|
-
var getExpiresAt = (tokenResponse) => {
|
|
3453
|
-
const expiresIn = tokenResponse.expires_in;
|
|
3454
|
-
const expiresInSeconds = typeof expiresIn === "number" ? expiresIn : typeof expiresIn === "string" && expiresIn.trim().length > 0 ? Number(expiresIn) : Number.NaN;
|
|
3455
|
-
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
3456
|
-
return;
|
|
3457
|
-
}
|
|
3458
|
-
return Date.now() + expiresInSeconds * 1000;
|
|
3459
|
-
};
|
|
3460
|
-
var createOAuthLinkedProviderCredentialResolver = async ({
|
|
3461
|
-
bindingStore,
|
|
3462
|
-
grantStore,
|
|
3463
|
-
now,
|
|
3464
|
-
providersConfiguration
|
|
3465
|
-
}) => {
|
|
3466
|
-
const clientEntries = [];
|
|
3467
|
-
for (const [providerName, providerConfig] of Object.entries(providersConfiguration)) {
|
|
3468
|
-
if (!isValidProviderOption(providerName)) {
|
|
3469
|
-
continue;
|
|
3470
|
-
}
|
|
3471
|
-
const resolvedProviderClientConfiguration = resolveProviderClientConfiguration({
|
|
3472
|
-
providerName,
|
|
3473
|
-
providersConfiguration
|
|
3474
|
-
});
|
|
3475
|
-
if ("error" in resolvedProviderClientConfiguration || !resolvedProviderClientConfiguration.config) {
|
|
3476
|
-
continue;
|
|
3477
|
-
}
|
|
3478
|
-
clientEntries.push(createOAuth2Client(providerName, resolvedProviderClientConfiguration.config.credentials).then((providerInstance) => [providerName, providerInstance]));
|
|
3479
|
-
}
|
|
3480
|
-
const clients = new Map(await Promise.all(clientEntries));
|
|
3481
|
-
return createLinkedProviderCredentialResolver({
|
|
3482
|
-
bindingStore,
|
|
3483
|
-
grantStore,
|
|
3484
|
-
now,
|
|
3485
|
-
loadAccessTokenLease: async (grant) => grant.accessTokenCiphertext ? {
|
|
3486
|
-
accessToken: grant.accessTokenCiphertext,
|
|
3487
|
-
expiresAt: grant.expiresAt,
|
|
3488
|
-
grantedScopes: grant.grantedScopes,
|
|
3489
|
-
tokenType: grant.tokenType
|
|
3490
|
-
} : null,
|
|
3491
|
-
refreshAccessTokenLease: async (grant) => {
|
|
3492
|
-
if (!isValidProviderOption(grant.authProviderKey) || !grant.refreshTokenCiphertext) {
|
|
3493
|
-
return null;
|
|
3494
|
-
}
|
|
3495
|
-
const providerKey = grant.authProviderKey;
|
|
3496
|
-
const providerClientName = typeof grant.metadata?.providerClient === "string" && grant.metadata.providerClient.trim().length > 0 ? grant.metadata.providerClient.trim() : undefined;
|
|
3497
|
-
const resolvedProviderClientConfiguration = resolveProviderClientConfiguration({
|
|
3498
|
-
clientName: providerClientName,
|
|
3499
|
-
providerName: providerKey,
|
|
3500
|
-
providersConfiguration
|
|
3501
|
-
});
|
|
3502
|
-
if ("error" in resolvedProviderClientConfiguration || !resolvedProviderClientConfiguration.config) {
|
|
3503
|
-
return null;
|
|
3504
|
-
}
|
|
3505
|
-
const providerClient = await createOAuth2Client(providerKey, resolvedProviderClientConfiguration.config.credentials);
|
|
3506
|
-
if (!providerClient || !isRefreshableOAuth2Client(providerKey, providerClient)) {
|
|
3507
|
-
return null;
|
|
3508
|
-
}
|
|
3509
|
-
const tokenResponse = await providerClient.refreshAccessToken(grant.refreshTokenCiphertext);
|
|
3510
|
-
const refreshedAt = Date.now();
|
|
3511
|
-
const grantedScopes = getGrantedScopes(Reflect.get(tokenResponse, "scope"), grant.grantedScopes);
|
|
3512
|
-
const tokenType = Reflect.get(tokenResponse, "token_type");
|
|
3513
|
-
const refreshedGrant = {
|
|
3514
|
-
...grant,
|
|
3515
|
-
accessTokenCiphertext: tokenResponse.access_token,
|
|
3516
|
-
expiresAt: getExpiresAt(tokenResponse),
|
|
3517
|
-
grantedScopes,
|
|
3518
|
-
lastRefreshError: undefined,
|
|
3519
|
-
lastRefreshedAt: refreshedAt,
|
|
3520
|
-
refreshTokenCiphertext: tokenResponse.refresh_token ?? grant.refreshTokenCiphertext,
|
|
3521
|
-
status: "active",
|
|
3522
|
-
tokenType: typeof tokenType === "string" ? tokenType : grant.tokenType,
|
|
3523
|
-
updatedAt: refreshedAt
|
|
3524
|
-
};
|
|
3525
|
-
return {
|
|
3526
|
-
grant: refreshedGrant,
|
|
3527
|
-
lease: {
|
|
3528
|
-
accessToken: refreshedGrant.accessTokenCiphertext ?? "",
|
|
3529
|
-
expiresAt: refreshedGrant.expiresAt,
|
|
3530
|
-
grantedScopes: refreshedGrant.grantedScopes,
|
|
3531
|
-
tokenType: refreshedGrant.tokenType
|
|
3532
|
-
}
|
|
3533
|
-
};
|
|
3534
|
-
}
|
|
3535
|
-
});
|
|
3536
|
-
};
|
|
3537
|
-
// node_modules/@neondatabase/serverless/index.mjs
|
|
3538
|
-
var vo = Object.create;
|
|
3539
|
-
var Te = Object.defineProperty;
|
|
3540
|
-
var xo = Object.getOwnPropertyDescriptor;
|
|
3541
|
-
var So = Object.getOwnPropertyNames;
|
|
3542
|
-
var Eo = Object.getPrototypeOf;
|
|
3543
|
-
var Ao = Object.prototype.hasOwnProperty;
|
|
3544
|
-
var Co = (r, e, t10) => (e in r) ? Te(r, e, { enumerable: true, configurable: true, writable: true, value: t10 }) : r[e] = t10;
|
|
3545
|
-
var a = (r, e) => Te(r, "name", { value: e, configurable: true });
|
|
3546
|
-
var z = (r, e) => () => (r && (e = r(r = 0)), e);
|
|
3547
|
-
var I = (r, e) => () => (e || r((e = { exports: {} }).exports, e), e.exports);
|
|
3548
|
-
var ne = (r, e) => {
|
|
3549
|
-
for (var t10 in e)
|
|
3550
|
-
Te(r, t10, {
|
|
3551
|
-
get: e[t10],
|
|
3552
|
-
enumerable: true
|
|
3553
|
-
});
|
|
3554
|
-
};
|
|
3555
|
-
var Mn = (r, e, t10, n) => {
|
|
3556
|
-
if (e && typeof e == "object" || typeof e == "function")
|
|
3557
|
-
for (let i of So(e))
|
|
3558
|
-
!Ao.call(r, i) && i !== t10 && Te(r, i, { get: () => e[i], enumerable: !(n = xo(e, i)) || n.enumerable });
|
|
3559
|
-
return r;
|
|
3560
|
-
};
|
|
3561
|
-
var xe = (r, e, t10) => (t10 = r != null ? vo(Eo(r)) : {}, Mn(e || !r || !r.__esModule ? Te(t10, "default", { value: r, enumerable: true }) : t10, r));
|
|
3562
|
-
var D = (r) => Mn(Te({}, "__esModule", { value: true }), r);
|
|
3563
|
-
var E = (r, e, t10) => Co(r, typeof e != "symbol" ? e + "" : e, t10);
|
|
3564
|
-
var On = I((ct) => {
|
|
3565
|
-
p();
|
|
3566
|
-
ct.byteLength = To;
|
|
3567
|
-
ct.toByteArray = Po;
|
|
3568
|
-
ct.fromByteArray = Lo;
|
|
3569
|
-
var ue = [], ee = [], _o = typeof Uint8Array < "u" ? Uint8Array : Array, Ut = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3570
|
-
for (Se = 0, Un = Ut.length;Se < Un; ++Se)
|
|
3571
|
-
ue[Se] = Ut[Se], ee[Ut.charCodeAt(Se)] = Se;
|
|
3572
|
-
var Se, Un;
|
|
3573
|
-
ee[45] = 62;
|
|
3574
|
-
ee[95] = 63;
|
|
3575
|
-
function Dn(r) {
|
|
3576
|
-
var e = r.length;
|
|
3577
|
-
if (e % 4 > 0)
|
|
3578
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
3579
|
-
var t10 = r.indexOf("=");
|
|
3580
|
-
t10 === -1 && (t10 = e);
|
|
3581
|
-
var n = t10 === e ? 0 : 4 - t10 % 4;
|
|
3582
|
-
return [t10, n];
|
|
3583
|
-
}
|
|
3584
|
-
a(Dn, "getLens");
|
|
3585
|
-
function To(r) {
|
|
3586
|
-
var e = Dn(r), t10 = e[0], n = e[1];
|
|
3587
|
-
return (t10 + n) * 3 / 4 - n;
|
|
3588
|
-
}
|
|
3589
|
-
a(To, "byteLength");
|
|
3590
|
-
function Io(r, e, t10) {
|
|
3591
|
-
return (e + t10) * 3 / 4 - t10;
|
|
3592
|
-
}
|
|
3593
|
-
a(Io, "_byteLength");
|
|
3594
|
-
function Po(r) {
|
|
3595
|
-
var e, t10 = Dn(r), n = t10[0], i = t10[1], s = new _o(Io(r, n, i)), o = 0, u = i > 0 ? n - 4 : n, c;
|
|
3596
|
-
for (c = 0;c < u; c += 4)
|
|
3597
|
-
e = ee[r.charCodeAt(c)] << 18 | ee[r.charCodeAt(c + 1)] << 12 | ee[r.charCodeAt(c + 2)] << 6 | ee[r.charCodeAt(c + 3)], s[o++] = e >> 16 & 255, s[o++] = e >> 8 & 255, s[o++] = e & 255;
|
|
3598
|
-
return i === 2 && (e = ee[r.charCodeAt(c)] << 2 | ee[r.charCodeAt(c + 1)] >> 4, s[o++] = e & 255), i === 1 && (e = ee[r.charCodeAt(c)] << 10 | ee[r.charCodeAt(c + 1)] << 4 | ee[r.charCodeAt(c + 2)] >> 2, s[o++] = e >> 8 & 255, s[o++] = e & 255), s;
|
|
3599
|
-
}
|
|
3600
|
-
a(Po, "toByteArray");
|
|
3601
|
-
function Ro(r) {
|
|
3602
|
-
return ue[r >> 18 & 63] + ue[r >> 12 & 63] + ue[r >> 6 & 63] + ue[r & 63];
|
|
3603
|
-
}
|
|
3604
|
-
a(Ro, "tripletToBase64");
|
|
3605
|
-
function Bo(r, e, t10) {
|
|
3606
|
-
for (var n, i = [], s = e;s < t10; s += 3)
|
|
3607
|
-
n = (r[s] << 16 & 16711680) + (r[s + 1] << 8 & 65280) + (r[s + 2] & 255), i.push(Ro(n));
|
|
3608
|
-
return i.join("");
|
|
3609
|
-
}
|
|
3610
|
-
a(Bo, "encodeChunk");
|
|
3611
|
-
function Lo(r) {
|
|
3612
|
-
for (var e, t10 = r.length, n = t10 % 3, i = [], s = 16383, o = 0, u = t10 - n;o < u; o += s)
|
|
3613
|
-
i.push(Bo(r, o, o + s > u ? u : o + s));
|
|
3614
|
-
return n === 1 ? (e = r[t10 - 1], i.push(ue[e >> 2] + ue[e << 4 & 63] + "==")) : n === 2 && (e = (r[t10 - 2] << 8) + r[t10 - 1], i.push(ue[e >> 10] + ue[e >> 4 & 63] + ue[e << 2 & 63] + "=")), i.join("");
|
|
3615
|
-
}
|
|
3616
|
-
a(Lo, "fromByteArray");
|
|
3617
|
-
});
|
|
3618
|
-
var qn = I((Dt) => {
|
|
3619
|
-
p();
|
|
3620
|
-
Dt.read = function(r, e, t10, n, i) {
|
|
3621
|
-
var s, o, u = i * 8 - n - 1, c = (1 << u) - 1, l = c >> 1, f = -7, y = t10 ? i - 1 : 0, g = t10 ? -1 : 1, A = r[e + y];
|
|
3622
|
-
for (y += g, s = A & (1 << -f) - 1, A >>= -f, f += u;f > 0; s = s * 256 + r[e + y], y += g, f -= 8)
|
|
3623
|
-
;
|
|
3624
|
-
for (o = s & (1 << -f) - 1, s >>= -f, f += n;f > 0; o = o * 256 + r[e + y], y += g, f -= 8)
|
|
3625
|
-
;
|
|
3626
|
-
if (s === 0)
|
|
3627
|
-
s = 1 - l;
|
|
3628
|
-
else {
|
|
3629
|
-
if (s === c)
|
|
3630
|
-
return o ? NaN : (A ? -1 : 1) * (1 / 0);
|
|
3631
|
-
o = o + Math.pow(2, n), s = s - l;
|
|
3632
|
-
}
|
|
3633
|
-
return (A ? -1 : 1) * o * Math.pow(2, s - n);
|
|
3634
|
-
};
|
|
3635
|
-
Dt.write = function(r, e, t10, n, i, s) {
|
|
3636
|
-
var o, u, c, l = s * 8 - i - 1, f = (1 << l) - 1, y = f >> 1, g = i === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, A = n ? 0 : s - 1, C = n ? 1 : -1, Q = e < 0 || e === 0 && 1 / e < 0 ? 1 : 0;
|
|
3637
|
-
for (e = Math.abs(e), isNaN(e) || e === 1 / 0 ? (u = isNaN(e) ? 1 : 0, o = f) : (o = Math.floor(Math.log(e) / Math.LN2), e * (c = Math.pow(2, -o)) < 1 && (o--, c *= 2), o + y >= 1 ? e += g / c : e += g * Math.pow(2, 1 - y), e * c >= 2 && (o++, c /= 2), o + y >= f ? (u = 0, o = f) : o + y >= 1 ? (u = (e * c - 1) * Math.pow(2, i), o = o + y) : (u = e * Math.pow(2, y - 1) * Math.pow(2, i), o = 0));i >= 8; r[t10 + A] = u & 255, A += C, u /= 256, i -= 8)
|
|
3638
|
-
;
|
|
3639
|
-
for (o = o << i | u, l += i;l > 0; r[t10 + A] = o & 255, A += C, o /= 256, l -= 8)
|
|
3640
|
-
;
|
|
3641
|
-
r[t10 + A - C] |= Q * 128;
|
|
3642
|
-
};
|
|
3643
|
-
});
|
|
3644
|
-
var ri = I((Be) => {
|
|
3645
|
-
p();
|
|
3646
|
-
var Ot = On(), Pe = qn(), Qn = typeof Symbol == "function" && typeof Symbol.for == "function" ? Symbol.for("nodejs.util.inspect.custom") : null;
|
|
3647
|
-
Be.Buffer = h;
|
|
3648
|
-
Be.SlowBuffer = Oo;
|
|
3649
|
-
Be.INSPECT_MAX_BYTES = 50;
|
|
3650
|
-
var lt = 2147483647;
|
|
3651
|
-
Be.kMaxLength = lt;
|
|
3652
|
-
h.TYPED_ARRAY_SUPPORT = Fo();
|
|
3653
|
-
!h.TYPED_ARRAY_SUPPORT && typeof console < "u" && typeof console.error == "function" && console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");
|
|
3654
|
-
function Fo() {
|
|
3655
|
-
try {
|
|
3656
|
-
let r = new Uint8Array(1), e = { foo: a(function() {
|
|
3657
|
-
return 42;
|
|
3658
|
-
}, "foo") };
|
|
3659
|
-
return Object.setPrototypeOf(e, Uint8Array.prototype), Object.setPrototypeOf(r, e), r.foo() === 42;
|
|
3660
|
-
} catch {
|
|
3661
|
-
return false;
|
|
3662
|
-
}
|
|
3663
|
-
}
|
|
3664
|
-
a(Fo, "typedArraySupport");
|
|
3665
|
-
Object.defineProperty(h.prototype, "parent", { enumerable: true, get: a(function() {
|
|
3666
|
-
if (h.isBuffer(this))
|
|
3667
|
-
return this.buffer;
|
|
3668
|
-
}, "get") });
|
|
3669
|
-
Object.defineProperty(h.prototype, "offset", { enumerable: true, get: a(function() {
|
|
3670
|
-
if (h.isBuffer(this))
|
|
3671
|
-
return this.byteOffset;
|
|
3672
|
-
}, "get") });
|
|
3673
|
-
function pe(r) {
|
|
3674
|
-
if (r > lt)
|
|
3675
|
-
throw new RangeError('The value "' + r + '" is invalid for option "size"');
|
|
3676
|
-
let e = new Uint8Array(r);
|
|
3677
|
-
return Object.setPrototypeOf(e, h.prototype), e;
|
|
3678
|
-
}
|
|
3679
|
-
a(pe, "createBuffer");
|
|
3680
|
-
function h(r, e, t10) {
|
|
3681
|
-
if (typeof r == "number") {
|
|
3682
|
-
if (typeof e == "string")
|
|
3683
|
-
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
3684
|
-
return jt(r);
|
|
3421
|
+
}
|
|
3422
|
+
a(Fo, "typedArraySupport");
|
|
3423
|
+
Object.defineProperty(h.prototype, "parent", { enumerable: true, get: a(function() {
|
|
3424
|
+
if (h.isBuffer(this))
|
|
3425
|
+
return this.buffer;
|
|
3426
|
+
}, "get") });
|
|
3427
|
+
Object.defineProperty(h.prototype, "offset", { enumerable: true, get: a(function() {
|
|
3428
|
+
if (h.isBuffer(this))
|
|
3429
|
+
return this.byteOffset;
|
|
3430
|
+
}, "get") });
|
|
3431
|
+
function pe(r) {
|
|
3432
|
+
if (r > lt)
|
|
3433
|
+
throw new RangeError('The value "' + r + '" is invalid for option "size"');
|
|
3434
|
+
let e = new Uint8Array(r);
|
|
3435
|
+
return Object.setPrototypeOf(e, h.prototype), e;
|
|
3436
|
+
}
|
|
3437
|
+
a(pe, "createBuffer");
|
|
3438
|
+
function h(r, e, t10) {
|
|
3439
|
+
if (typeof r == "number") {
|
|
3440
|
+
if (typeof e == "string")
|
|
3441
|
+
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
3442
|
+
return jt(r);
|
|
3685
3443
|
}
|
|
3686
3444
|
return Hn(r, e, t10);
|
|
3687
3445
|
}
|
|
@@ -12994,239 +12752,597 @@ class PgSession {
|
|
|
12994
12752
|
return prepared.setToken(token).execute(undefined, token);
|
|
12995
12753
|
});
|
|
12996
12754
|
}
|
|
12997
|
-
all(query) {
|
|
12998
|
-
return this.prepareQuery(this.dialect.sqlToQuery(query), undefined, undefined, false).all();
|
|
12755
|
+
all(query) {
|
|
12756
|
+
return this.prepareQuery(this.dialect.sqlToQuery(query), undefined, undefined, false).all();
|
|
12757
|
+
}
|
|
12758
|
+
async count(sql2, token) {
|
|
12759
|
+
const res = await this.execute(sql2, token);
|
|
12760
|
+
return Number(res[0]["count"]);
|
|
12761
|
+
}
|
|
12762
|
+
}
|
|
12763
|
+
|
|
12764
|
+
// node_modules/drizzle-orm/neon-http/session.js
|
|
12765
|
+
var rawQueryConfig = {
|
|
12766
|
+
arrayMode: false,
|
|
12767
|
+
fullResults: true
|
|
12768
|
+
};
|
|
12769
|
+
var queryConfig = {
|
|
12770
|
+
arrayMode: true,
|
|
12771
|
+
fullResults: true
|
|
12772
|
+
};
|
|
12773
|
+
|
|
12774
|
+
class NeonHttpPreparedQuery extends PgPreparedQuery {
|
|
12775
|
+
constructor(client, query, logger, fields, _isResponseInArrayMode, customResultMapper) {
|
|
12776
|
+
super(query);
|
|
12777
|
+
this.client = client;
|
|
12778
|
+
this.logger = logger;
|
|
12779
|
+
this.fields = fields;
|
|
12780
|
+
this._isResponseInArrayMode = _isResponseInArrayMode;
|
|
12781
|
+
this.customResultMapper = customResultMapper;
|
|
12782
|
+
this.clientQuery = client.query ?? client;
|
|
12783
|
+
}
|
|
12784
|
+
static [entityKind] = "NeonHttpPreparedQuery";
|
|
12785
|
+
clientQuery;
|
|
12786
|
+
async execute(placeholderValues = {}, token = this.authToken) {
|
|
12787
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
12788
|
+
this.logger.logQuery(this.query.sql, params);
|
|
12789
|
+
const { fields, clientQuery, query, customResultMapper } = this;
|
|
12790
|
+
if (!fields && !customResultMapper) {
|
|
12791
|
+
return clientQuery(query.sql, params, token === undefined ? rawQueryConfig : {
|
|
12792
|
+
...rawQueryConfig,
|
|
12793
|
+
authToken: token
|
|
12794
|
+
});
|
|
12795
|
+
}
|
|
12796
|
+
const result = await clientQuery(query.sql, params, token === undefined ? queryConfig : {
|
|
12797
|
+
...queryConfig,
|
|
12798
|
+
authToken: token
|
|
12799
|
+
});
|
|
12800
|
+
return this.mapResult(result);
|
|
12801
|
+
}
|
|
12802
|
+
mapResult(result) {
|
|
12803
|
+
if (!this.fields && !this.customResultMapper) {
|
|
12804
|
+
return result;
|
|
12805
|
+
}
|
|
12806
|
+
const rows = result.rows;
|
|
12807
|
+
if (this.customResultMapper) {
|
|
12808
|
+
return this.customResultMapper(rows);
|
|
12809
|
+
}
|
|
12810
|
+
return rows.map((row) => mapResultRow(this.fields, row, this.joinsNotNullableMap));
|
|
12811
|
+
}
|
|
12812
|
+
all(placeholderValues = {}) {
|
|
12813
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
12814
|
+
this.logger.logQuery(this.query.sql, params);
|
|
12815
|
+
return this.clientQuery(this.query.sql, params, this.authToken === undefined ? rawQueryConfig : {
|
|
12816
|
+
...rawQueryConfig,
|
|
12817
|
+
authToken: this.authToken
|
|
12818
|
+
}).then((result) => result.rows);
|
|
12819
|
+
}
|
|
12820
|
+
values(placeholderValues = {}, token) {
|
|
12821
|
+
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
12822
|
+
this.logger.logQuery(this.query.sql, params);
|
|
12823
|
+
return this.clientQuery(this.query.sql, params, { arrayMode: true, fullResults: true, authToken: token }).then((result) => result.rows);
|
|
12824
|
+
}
|
|
12825
|
+
isResponseInArrayMode() {
|
|
12826
|
+
return this._isResponseInArrayMode;
|
|
12827
|
+
}
|
|
12828
|
+
}
|
|
12829
|
+
|
|
12830
|
+
class NeonHttpSession extends PgSession {
|
|
12831
|
+
constructor(client, dialect, schema, options = {}) {
|
|
12832
|
+
super(dialect);
|
|
12833
|
+
this.client = client;
|
|
12834
|
+
this.schema = schema;
|
|
12835
|
+
this.options = options;
|
|
12836
|
+
this.clientQuery = client.query ?? client;
|
|
12837
|
+
this.logger = options.logger ?? new NoopLogger;
|
|
12838
|
+
}
|
|
12839
|
+
static [entityKind] = "NeonHttpSession";
|
|
12840
|
+
clientQuery;
|
|
12841
|
+
logger;
|
|
12842
|
+
prepareQuery(query, fields, name, isResponseInArrayMode, customResultMapper) {
|
|
12843
|
+
return new NeonHttpPreparedQuery(this.client, query, this.logger, fields, isResponseInArrayMode, customResultMapper);
|
|
12844
|
+
}
|
|
12845
|
+
async batch(queries) {
|
|
12846
|
+
const preparedQueries = [];
|
|
12847
|
+
const builtQueries = [];
|
|
12848
|
+
for (const query of queries) {
|
|
12849
|
+
const preparedQuery = query._prepare();
|
|
12850
|
+
const builtQuery = preparedQuery.getQuery();
|
|
12851
|
+
preparedQueries.push(preparedQuery);
|
|
12852
|
+
builtQueries.push(this.clientQuery(builtQuery.sql, builtQuery.params, {
|
|
12853
|
+
fullResults: true,
|
|
12854
|
+
arrayMode: preparedQuery.isResponseInArrayMode()
|
|
12855
|
+
}));
|
|
12856
|
+
}
|
|
12857
|
+
const batchResults = await this.client.transaction(builtQueries, queryConfig);
|
|
12858
|
+
return batchResults.map((result, i) => preparedQueries[i].mapResult(result, true));
|
|
12859
|
+
}
|
|
12860
|
+
async query(query, params) {
|
|
12861
|
+
this.logger.logQuery(query, params);
|
|
12862
|
+
const result = await this.clientQuery(query, params, { arrayMode: true, fullResults: true });
|
|
12863
|
+
return result;
|
|
12864
|
+
}
|
|
12865
|
+
async queryObjects(query, params) {
|
|
12866
|
+
return this.clientQuery(query, params, { arrayMode: false, fullResults: true });
|
|
12867
|
+
}
|
|
12868
|
+
async count(sql2, token) {
|
|
12869
|
+
const res = await this.execute(sql2, token);
|
|
12870
|
+
return Number(res["rows"][0]["count"]);
|
|
12871
|
+
}
|
|
12872
|
+
async transaction(_transaction, _config = {}) {
|
|
12873
|
+
throw new Error("No transactions support in neon-http driver");
|
|
12874
|
+
}
|
|
12875
|
+
}
|
|
12876
|
+
|
|
12877
|
+
// node_modules/drizzle-orm/neon-http/driver.js
|
|
12878
|
+
class NeonHttpDriver {
|
|
12879
|
+
constructor(client, dialect, options = {}) {
|
|
12880
|
+
this.client = client;
|
|
12881
|
+
this.dialect = dialect;
|
|
12882
|
+
this.options = options;
|
|
12883
|
+
this.initMappers();
|
|
12884
|
+
}
|
|
12885
|
+
static [entityKind] = "NeonHttpDriver";
|
|
12886
|
+
createSession(schema) {
|
|
12887
|
+
return new NeonHttpSession(this.client, this.dialect, schema, { logger: this.options.logger });
|
|
12888
|
+
}
|
|
12889
|
+
initMappers() {
|
|
12890
|
+
export_types.setTypeParser(export_types.builtins.TIMESTAMPTZ, (val) => val);
|
|
12891
|
+
export_types.setTypeParser(export_types.builtins.TIMESTAMP, (val) => val);
|
|
12892
|
+
export_types.setTypeParser(export_types.builtins.DATE, (val) => val);
|
|
12893
|
+
export_types.setTypeParser(export_types.builtins.INTERVAL, (val) => val);
|
|
12894
|
+
export_types.setTypeParser(1231, (val) => val);
|
|
12895
|
+
export_types.setTypeParser(1115, (val) => val);
|
|
12896
|
+
export_types.setTypeParser(1185, (val) => val);
|
|
12897
|
+
export_types.setTypeParser(1187, (val) => val);
|
|
12898
|
+
export_types.setTypeParser(1182, (val) => val);
|
|
12899
|
+
}
|
|
12900
|
+
}
|
|
12901
|
+
function wrap(target, token, cb, deep) {
|
|
12902
|
+
return new Proxy(target, {
|
|
12903
|
+
get(target2, p2) {
|
|
12904
|
+
const element = target2[p2];
|
|
12905
|
+
if (typeof element !== "function" && (typeof element !== "object" || element === null))
|
|
12906
|
+
return element;
|
|
12907
|
+
if (deep)
|
|
12908
|
+
return wrap(element, token, cb);
|
|
12909
|
+
if (p2 === "query")
|
|
12910
|
+
return wrap(element, token, cb, true);
|
|
12911
|
+
return new Proxy(element, {
|
|
12912
|
+
apply(target3, thisArg, argArray) {
|
|
12913
|
+
const res = target3.call(thisArg, ...argArray);
|
|
12914
|
+
if (typeof res === "object" && res !== null && "setToken" in res && typeof res.setToken === "function") {
|
|
12915
|
+
res.setToken(token);
|
|
12916
|
+
}
|
|
12917
|
+
return cb(target3, p2, res);
|
|
12918
|
+
}
|
|
12919
|
+
});
|
|
12920
|
+
}
|
|
12921
|
+
});
|
|
12922
|
+
}
|
|
12923
|
+
|
|
12924
|
+
class NeonHttpDatabase extends PgDatabase {
|
|
12925
|
+
static [entityKind] = "NeonHttpDatabase";
|
|
12926
|
+
$withAuth(token) {
|
|
12927
|
+
this.authToken = token;
|
|
12928
|
+
return wrap(this, token, (target, p2, res) => {
|
|
12929
|
+
if (p2 === "with") {
|
|
12930
|
+
return wrap(res, token, (_, __, res2) => res2);
|
|
12931
|
+
}
|
|
12932
|
+
return res;
|
|
12933
|
+
});
|
|
12934
|
+
}
|
|
12935
|
+
async batch(batch) {
|
|
12936
|
+
return this.session.batch(batch);
|
|
12937
|
+
}
|
|
12938
|
+
}
|
|
12939
|
+
function construct(client, config = {}) {
|
|
12940
|
+
const dialect = new PgDialect({ casing: config.casing });
|
|
12941
|
+
let logger;
|
|
12942
|
+
if (config.logger === true) {
|
|
12943
|
+
logger = new DefaultLogger;
|
|
12944
|
+
} else if (config.logger !== false) {
|
|
12945
|
+
logger = config.logger;
|
|
12946
|
+
}
|
|
12947
|
+
let schema;
|
|
12948
|
+
if (config.schema) {
|
|
12949
|
+
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
12950
|
+
schema = {
|
|
12951
|
+
fullSchema: config.schema,
|
|
12952
|
+
schema: tablesConfig.tables,
|
|
12953
|
+
tableNamesMap: tablesConfig.tableNamesMap
|
|
12954
|
+
};
|
|
12955
|
+
}
|
|
12956
|
+
const driver = new NeonHttpDriver(client, dialect, { logger });
|
|
12957
|
+
const session = driver.createSession(schema);
|
|
12958
|
+
const db = new NeonHttpDatabase(dialect, session, schema);
|
|
12959
|
+
db.$client = client;
|
|
12960
|
+
return db;
|
|
12961
|
+
}
|
|
12962
|
+
function drizzle(...params) {
|
|
12963
|
+
if (typeof params[0] === "string") {
|
|
12964
|
+
const instance = as(params[0]);
|
|
12965
|
+
return construct(instance, params[1]);
|
|
12999
12966
|
}
|
|
13000
|
-
|
|
13001
|
-
const
|
|
13002
|
-
|
|
12967
|
+
if (isConfig(params[0])) {
|
|
12968
|
+
const { connection, client, ...drizzleConfig } = params[0];
|
|
12969
|
+
if (client)
|
|
12970
|
+
return construct(client, drizzleConfig);
|
|
12971
|
+
if (typeof connection === "object") {
|
|
12972
|
+
const { connectionString, ...options } = connection;
|
|
12973
|
+
const instance2 = as(connectionString, options);
|
|
12974
|
+
return construct(instance2, drizzleConfig);
|
|
12975
|
+
}
|
|
12976
|
+
const instance = as(connection);
|
|
12977
|
+
return construct(instance, drizzleConfig);
|
|
13003
12978
|
}
|
|
12979
|
+
return construct(params[0], params[1]);
|
|
13004
12980
|
}
|
|
12981
|
+
((drizzle2) => {
|
|
12982
|
+
function mock(config) {
|
|
12983
|
+
return construct({}, config);
|
|
12984
|
+
}
|
|
12985
|
+
drizzle2.mock = mock;
|
|
12986
|
+
})(drizzle || (drizzle = {}));
|
|
13005
12987
|
|
|
13006
|
-
//
|
|
13007
|
-
var
|
|
13008
|
-
|
|
13009
|
-
|
|
12988
|
+
// src/neonAuthSessionStore.ts
|
|
12989
|
+
var authSessionsTable = pgTable("auth_sessions", {
|
|
12990
|
+
id: varchar("id", { length: 255 }).primaryKey(),
|
|
12991
|
+
access_token: text("access_token").notNull(),
|
|
12992
|
+
refresh_token: text("refresh_token"),
|
|
12993
|
+
expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
|
|
12994
|
+
user_json: jsonb("user_json").$type().notNull(),
|
|
12995
|
+
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
12996
|
+
updated_at: timestamp("updated_at").notNull().defaultNow()
|
|
12997
|
+
});
|
|
12998
|
+
var authUnregisteredSessionsTable = pgTable("auth_unregistered_sessions", {
|
|
12999
|
+
id: varchar("id", { length: 255 }).primaryKey(),
|
|
13000
|
+
access_token: text("access_token"),
|
|
13001
|
+
refresh_token: text("refresh_token"),
|
|
13002
|
+
expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
|
|
13003
|
+
user_identity_json: jsonb("user_identity_json").$type(),
|
|
13004
|
+
session_information_json: jsonb("session_information_json").$type(),
|
|
13005
|
+
created_at: timestamp("created_at").notNull().defaultNow(),
|
|
13006
|
+
updated_at: timestamp("updated_at").notNull().defaultNow()
|
|
13007
|
+
});
|
|
13008
|
+
var authSessionSchema = {
|
|
13009
|
+
authSessions: authSessionsTable,
|
|
13010
|
+
authUnregisteredSessions: authUnregisteredSessionsTable
|
|
13010
13011
|
};
|
|
13011
|
-
var
|
|
13012
|
-
|
|
13013
|
-
|
|
13012
|
+
var cloneUser = (value) => {
|
|
13013
|
+
if (value === null || value === undefined)
|
|
13014
|
+
return value;
|
|
13015
|
+
return structuredClone(value);
|
|
13014
13016
|
};
|
|
13015
|
-
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
|
|
13028
|
-
|
|
13029
|
-
|
|
13030
|
-
|
|
13031
|
-
|
|
13032
|
-
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
|
|
13017
|
+
var cloneRecord = (value) => value ? structuredClone(value) : undefined;
|
|
13018
|
+
var toSessionData = (row) => ({
|
|
13019
|
+
accessToken: row.access_token,
|
|
13020
|
+
expiresAt: row.expires_at_ms,
|
|
13021
|
+
refreshToken: row.refresh_token ?? undefined,
|
|
13022
|
+
user: cloneUser(row.user_json)
|
|
13023
|
+
});
|
|
13024
|
+
var toUnregisteredSessionData = (row) => ({
|
|
13025
|
+
accessToken: row.access_token ?? undefined,
|
|
13026
|
+
expiresAt: row.expires_at_ms,
|
|
13027
|
+
refreshToken: row.refresh_token ?? undefined,
|
|
13028
|
+
sessionInformation: cloneRecord(row.session_information_json ?? undefined),
|
|
13029
|
+
userIdentity: cloneRecord(row.user_identity_json ?? undefined)
|
|
13030
|
+
});
|
|
13031
|
+
var createNeonAuthSessionStore = (databaseUrl) => {
|
|
13032
|
+
const sql2 = as(databaseUrl);
|
|
13033
|
+
const db = drizzle(sql2, {
|
|
13034
|
+
schema: authSessionSchema
|
|
13035
|
+
});
|
|
13036
|
+
return {
|
|
13037
|
+
getSession: async (id) => {
|
|
13038
|
+
const [row] = await db.select().from(authSessionsTable).where(eq(authSessionsTable.id, id)).limit(1);
|
|
13039
|
+
return row ? toSessionData(row) : undefined;
|
|
13040
|
+
},
|
|
13041
|
+
setSession: async (id, value) => {
|
|
13042
|
+
await db.insert(authSessionsTable).values({
|
|
13043
|
+
id,
|
|
13044
|
+
access_token: value.accessToken,
|
|
13045
|
+
refresh_token: value.refreshToken ?? null,
|
|
13046
|
+
expires_at_ms: value.expiresAt,
|
|
13047
|
+
user_json: value.user ?? {},
|
|
13048
|
+
updated_at: new Date
|
|
13049
|
+
}).onConflictDoUpdate({
|
|
13050
|
+
target: authSessionsTable.id,
|
|
13051
|
+
set: {
|
|
13052
|
+
access_token: value.accessToken,
|
|
13053
|
+
refresh_token: value.refreshToken ?? null,
|
|
13054
|
+
expires_at_ms: value.expiresAt,
|
|
13055
|
+
user_json: value.user ?? {},
|
|
13056
|
+
updated_at: new Date
|
|
13057
|
+
}
|
|
13036
13058
|
});
|
|
13059
|
+
},
|
|
13060
|
+
removeSession: async (id) => {
|
|
13061
|
+
await db.delete(authSessionsTable).where(eq(authSessionsTable.id, id));
|
|
13062
|
+
},
|
|
13063
|
+
getUnregisteredSession: async (id) => {
|
|
13064
|
+
const [row] = await db.select().from(authUnregisteredSessionsTable).where(eq(authUnregisteredSessionsTable.id, id)).limit(1);
|
|
13065
|
+
return row ? toUnregisteredSessionData(row) : undefined;
|
|
13066
|
+
},
|
|
13067
|
+
setUnregisteredSession: async (id, value) => {
|
|
13068
|
+
await db.insert(authUnregisteredSessionsTable).values({
|
|
13069
|
+
id,
|
|
13070
|
+
access_token: value.accessToken ?? null,
|
|
13071
|
+
refresh_token: value.refreshToken ?? null,
|
|
13072
|
+
expires_at_ms: value.expiresAt,
|
|
13073
|
+
user_identity_json: value.userIdentity ?? null,
|
|
13074
|
+
session_information_json: value.sessionInformation ?? null,
|
|
13075
|
+
updated_at: new Date
|
|
13076
|
+
}).onConflictDoUpdate({
|
|
13077
|
+
target: authUnregisteredSessionsTable.id,
|
|
13078
|
+
set: {
|
|
13079
|
+
access_token: value.accessToken ?? null,
|
|
13080
|
+
refresh_token: value.refreshToken ?? null,
|
|
13081
|
+
expires_at_ms: value.expiresAt,
|
|
13082
|
+
user_identity_json: value.userIdentity ?? null,
|
|
13083
|
+
session_information_json: value.sessionInformation ?? null,
|
|
13084
|
+
updated_at: new Date
|
|
13085
|
+
}
|
|
13086
|
+
});
|
|
13087
|
+
},
|
|
13088
|
+
removeUnregisteredSession: async (id) => {
|
|
13089
|
+
await db.delete(authUnregisteredSessionsTable).where(eq(authUnregisteredSessionsTable.id, id));
|
|
13090
|
+
},
|
|
13091
|
+
listSessionIds: async () => {
|
|
13092
|
+
const rows = await db.select({ id: authSessionsTable.id }).from(authSessionsTable);
|
|
13093
|
+
return rows.map((row) => row.id);
|
|
13094
|
+
},
|
|
13095
|
+
listUnregisteredSessionIds: async () => {
|
|
13096
|
+
const rows = await db.select({ id: authUnregisteredSessionsTable.id }).from(authUnregisteredSessionsTable);
|
|
13097
|
+
return rows.map((row) => row.id);
|
|
13037
13098
|
}
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
if (!this.fields && !this.customResultMapper) {
|
|
13046
|
-
return result;
|
|
13047
|
-
}
|
|
13048
|
-
const rows = result.rows;
|
|
13049
|
-
if (this.customResultMapper) {
|
|
13050
|
-
return this.customResultMapper(rows);
|
|
13051
|
-
}
|
|
13052
|
-
return rows.map((row) => mapResultRow(this.fields, row, this.joinsNotNullableMap));
|
|
13053
|
-
}
|
|
13054
|
-
all(placeholderValues = {}) {
|
|
13055
|
-
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
13056
|
-
this.logger.logQuery(this.query.sql, params);
|
|
13057
|
-
return this.clientQuery(this.query.sql, params, this.authToken === undefined ? rawQueryConfig : {
|
|
13058
|
-
...rawQueryConfig,
|
|
13059
|
-
authToken: this.authToken
|
|
13060
|
-
}).then((result) => result.rows);
|
|
13061
|
-
}
|
|
13062
|
-
values(placeholderValues = {}, token) {
|
|
13063
|
-
const params = fillPlaceholders(this.query.params, placeholderValues);
|
|
13064
|
-
this.logger.logQuery(this.query.sql, params);
|
|
13065
|
-
return this.clientQuery(this.query.sql, params, { arrayMode: true, fullResults: true, authToken: token }).then((result) => result.rows);
|
|
13099
|
+
};
|
|
13100
|
+
};
|
|
13101
|
+
// src/linkedProviderResolver.ts
|
|
13102
|
+
var uniqueStrings = (values) => [...new Set(values)];
|
|
13103
|
+
var getEffectiveScopes = (grant, binding) => {
|
|
13104
|
+
if (binding.availableScopes.length === 0) {
|
|
13105
|
+
return uniqueStrings(grant.grantedScopes);
|
|
13066
13106
|
}
|
|
13067
|
-
|
|
13068
|
-
|
|
13107
|
+
const bindingScopeSet = new Set(binding.availableScopes);
|
|
13108
|
+
return uniqueStrings(grant.grantedScopes.filter((scope) => bindingScopeSet.has(scope)));
|
|
13109
|
+
};
|
|
13110
|
+
var hasRequiredScopes = (availableScopes, requiredScopes) => (requiredScopes ?? []).every((scope) => availableScopes.includes(scope));
|
|
13111
|
+
var isGrantUsable = (grant) => grant.status === "active" || grant.status === "refresh_required";
|
|
13112
|
+
var isBindingUsable = (binding) => binding.status === "active";
|
|
13113
|
+
var needsRefresh = (lease, now, minValidityMs) => {
|
|
13114
|
+
if (!lease)
|
|
13115
|
+
return true;
|
|
13116
|
+
if (lease.expiresAt === undefined)
|
|
13117
|
+
return false;
|
|
13118
|
+
return lease.expiresAt <= now + (minValidityMs ?? 0);
|
|
13119
|
+
};
|
|
13120
|
+
var ensureLeaseScopes = (lease, requiredScopes) => {
|
|
13121
|
+
if (!hasRequiredScopes(lease.grantedScopes, requiredScopes)) {
|
|
13122
|
+
throw new Error("Linked provider access token lease is missing required scopes");
|
|
13069
13123
|
}
|
|
13070
|
-
}
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
this.schema = schema;
|
|
13077
|
-
this.options = options;
|
|
13078
|
-
this.clientQuery = client.query ?? client;
|
|
13079
|
-
this.logger = options.logger ?? new NoopLogger;
|
|
13124
|
+
};
|
|
13125
|
+
var ensureLeaseValidity = (lease, now, minValidityMs) => {
|
|
13126
|
+
if (lease.expiresAt === undefined)
|
|
13127
|
+
return;
|
|
13128
|
+
if (lease.expiresAt <= now + (minValidityMs ?? 0)) {
|
|
13129
|
+
throw new Error("Linked provider access token lease does not satisfy minimum validity");
|
|
13080
13130
|
}
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13131
|
+
};
|
|
13132
|
+
var buildResolvedCredential = (grant, binding) => ({
|
|
13133
|
+
bindingId: binding.id,
|
|
13134
|
+
grantId: grant.id,
|
|
13135
|
+
ownerRef: grant.ownerRef,
|
|
13136
|
+
connectorProvider: binding.connectorProvider,
|
|
13137
|
+
providerFamily: grant.providerFamily,
|
|
13138
|
+
authProviderKey: grant.authProviderKey,
|
|
13139
|
+
externalAccountId: binding.externalAccountId,
|
|
13140
|
+
externalAccountType: binding.externalAccountType,
|
|
13141
|
+
scopes: getEffectiveScopes(grant, binding),
|
|
13142
|
+
capabilities: binding.capabilities ? [...binding.capabilities] : undefined,
|
|
13143
|
+
label: binding.label,
|
|
13144
|
+
username: binding.username,
|
|
13145
|
+
email: binding.email,
|
|
13146
|
+
metadata: {
|
|
13147
|
+
...grant.metadata ?? {},
|
|
13148
|
+
...binding.metadata ?? {}
|
|
13086
13149
|
}
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
13096
|
-
|
|
13097
|
-
|
|
13150
|
+
});
|
|
13151
|
+
var annotateFailureMetadata = (metadata, report, now) => ({
|
|
13152
|
+
...metadata ?? {},
|
|
13153
|
+
lastCredentialFailureAt: now,
|
|
13154
|
+
lastCredentialFailureCode: report.code,
|
|
13155
|
+
lastCredentialFailureMessage: report.message,
|
|
13156
|
+
lastCredentialFailureRetryAt: report.retryAt
|
|
13157
|
+
});
|
|
13158
|
+
var sortNewestFirst = (items) => [...items].sort((left, right) => right.updatedAt - left.updatedAt);
|
|
13159
|
+
var createLinkedProviderCredentialResolver = ({
|
|
13160
|
+
grantStore,
|
|
13161
|
+
bindingStore,
|
|
13162
|
+
loadAccessTokenLease,
|
|
13163
|
+
refreshAccessTokenLease,
|
|
13164
|
+
now = () => Date.now(),
|
|
13165
|
+
onReportFailure
|
|
13166
|
+
}) => ({
|
|
13167
|
+
listBindings: async ({ ownerRef, connectorProvider, status }) => sortNewestFirst(await bindingStore.listBindingsByOwner(ownerRef)).filter((binding) => (connectorProvider === undefined || binding.connectorProvider === connectorProvider) && (status === undefined || binding.status === status)),
|
|
13168
|
+
resolveCredential: async (input) => {
|
|
13169
|
+
const bindings = sortNewestFirst(await bindingStore.listBindingsByOwner(input.ownerRef)).filter((binding) => binding.connectorProvider === input.connectorProvider && isBindingUsable(binding) && (input.bindingId === undefined || binding.id === input.bindingId) && (input.externalAccountId === undefined || binding.externalAccountId === input.externalAccountId));
|
|
13170
|
+
for (const binding of bindings) {
|
|
13171
|
+
const grant = await grantStore.getGrant(binding.grantId);
|
|
13172
|
+
if (!grant || grant.ownerRef !== input.ownerRef || !isGrantUsable(grant)) {
|
|
13173
|
+
continue;
|
|
13174
|
+
}
|
|
13175
|
+
const effectiveScopes = getEffectiveScopes(grant, binding);
|
|
13176
|
+
if (!hasRequiredScopes(effectiveScopes, input.requiredScopes)) {
|
|
13177
|
+
continue;
|
|
13178
|
+
}
|
|
13179
|
+
return buildResolvedCredential(grant, binding);
|
|
13180
|
+
}
|
|
13181
|
+
return null;
|
|
13182
|
+
},
|
|
13183
|
+
getAccessToken: async (credential, input) => {
|
|
13184
|
+
const binding = await bindingStore.getBinding(credential.bindingId);
|
|
13185
|
+
if (!binding || !isBindingUsable(binding)) {
|
|
13186
|
+
throw new Error("Linked provider binding is unavailable");
|
|
13187
|
+
}
|
|
13188
|
+
const grant = await grantStore.getGrant(credential.grantId);
|
|
13189
|
+
if (!grant || !isGrantUsable(grant)) {
|
|
13190
|
+
throw new Error("Linked provider grant is unavailable");
|
|
13191
|
+
}
|
|
13192
|
+
const requiredScopes = input?.requiredScopes;
|
|
13193
|
+
const effectiveScopes = getEffectiveScopes(grant, binding);
|
|
13194
|
+
if (!hasRequiredScopes(effectiveScopes, requiredScopes)) {
|
|
13195
|
+
throw new Error("Linked provider credential is missing required scopes");
|
|
13196
|
+
}
|
|
13197
|
+
const currentTime = now();
|
|
13198
|
+
let lease = await loadAccessTokenLease(grant);
|
|
13199
|
+
if (needsRefresh(lease, currentTime, input?.minValidityMs)) {
|
|
13200
|
+
if (!refreshAccessTokenLease) {
|
|
13201
|
+
throw new Error("Linked provider access token lease requires refresh");
|
|
13202
|
+
}
|
|
13203
|
+
const refreshed = await refreshAccessTokenLease(grant, input);
|
|
13204
|
+
if (!refreshed) {
|
|
13205
|
+
throw new Error("Linked provider access token refresh failed");
|
|
13206
|
+
}
|
|
13207
|
+
await grantStore.saveGrant(refreshed.grant);
|
|
13208
|
+
lease = refreshed.lease;
|
|
13098
13209
|
}
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
}
|
|
13102
|
-
async query(query, params) {
|
|
13103
|
-
this.logger.logQuery(query, params);
|
|
13104
|
-
const result = await this.clientQuery(query, params, { arrayMode: true, fullResults: true });
|
|
13105
|
-
return result;
|
|
13106
|
-
}
|
|
13107
|
-
async queryObjects(query, params) {
|
|
13108
|
-
return this.clientQuery(query, params, { arrayMode: false, fullResults: true });
|
|
13109
|
-
}
|
|
13110
|
-
async count(sql2, token) {
|
|
13111
|
-
const res = await this.execute(sql2, token);
|
|
13112
|
-
return Number(res["rows"][0]["count"]);
|
|
13113
|
-
}
|
|
13114
|
-
async transaction(_transaction, _config = {}) {
|
|
13115
|
-
throw new Error("No transactions support in neon-http driver");
|
|
13116
|
-
}
|
|
13117
|
-
}
|
|
13118
|
-
|
|
13119
|
-
// node_modules/drizzle-orm/neon-http/driver.js
|
|
13120
|
-
class NeonHttpDriver {
|
|
13121
|
-
constructor(client, dialect, options = {}) {
|
|
13122
|
-
this.client = client;
|
|
13123
|
-
this.dialect = dialect;
|
|
13124
|
-
this.options = options;
|
|
13125
|
-
this.initMappers();
|
|
13126
|
-
}
|
|
13127
|
-
static [entityKind] = "NeonHttpDriver";
|
|
13128
|
-
createSession(schema) {
|
|
13129
|
-
return new NeonHttpSession(this.client, this.dialect, schema, { logger: this.options.logger });
|
|
13130
|
-
}
|
|
13131
|
-
initMappers() {
|
|
13132
|
-
export_types.setTypeParser(export_types.builtins.TIMESTAMPTZ, (val) => val);
|
|
13133
|
-
export_types.setTypeParser(export_types.builtins.TIMESTAMP, (val) => val);
|
|
13134
|
-
export_types.setTypeParser(export_types.builtins.DATE, (val) => val);
|
|
13135
|
-
export_types.setTypeParser(export_types.builtins.INTERVAL, (val) => val);
|
|
13136
|
-
export_types.setTypeParser(1231, (val) => val);
|
|
13137
|
-
export_types.setTypeParser(1115, (val) => val);
|
|
13138
|
-
export_types.setTypeParser(1185, (val) => val);
|
|
13139
|
-
export_types.setTypeParser(1187, (val) => val);
|
|
13140
|
-
export_types.setTypeParser(1182, (val) => val);
|
|
13141
|
-
}
|
|
13142
|
-
}
|
|
13143
|
-
function wrap(target, token, cb, deep) {
|
|
13144
|
-
return new Proxy(target, {
|
|
13145
|
-
get(target2, p2) {
|
|
13146
|
-
const element = target2[p2];
|
|
13147
|
-
if (typeof element !== "function" && (typeof element !== "object" || element === null))
|
|
13148
|
-
return element;
|
|
13149
|
-
if (deep)
|
|
13150
|
-
return wrap(element, token, cb);
|
|
13151
|
-
if (p2 === "query")
|
|
13152
|
-
return wrap(element, token, cb, true);
|
|
13153
|
-
return new Proxy(element, {
|
|
13154
|
-
apply(target3, thisArg, argArray) {
|
|
13155
|
-
const res = target3.call(thisArg, ...argArray);
|
|
13156
|
-
if (typeof res === "object" && res !== null && "setToken" in res && typeof res.setToken === "function") {
|
|
13157
|
-
res.setToken(token);
|
|
13158
|
-
}
|
|
13159
|
-
return cb(target3, p2, res);
|
|
13160
|
-
}
|
|
13161
|
-
});
|
|
13210
|
+
if (!lease) {
|
|
13211
|
+
throw new Error("Linked provider access token lease is unavailable");
|
|
13162
13212
|
}
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13213
|
+
ensureLeaseScopes(lease, requiredScopes);
|
|
13214
|
+
ensureLeaseValidity(lease, currentTime, input?.minValidityMs);
|
|
13215
|
+
return lease;
|
|
13216
|
+
},
|
|
13217
|
+
reportFailure: async (credential, report) => {
|
|
13218
|
+
const currentTime = now();
|
|
13219
|
+
const grant = await grantStore.getGrant(credential.grantId);
|
|
13220
|
+
const binding = await bindingStore.getBinding(credential.bindingId);
|
|
13221
|
+
if (grant) {
|
|
13222
|
+
const nextGrant = {
|
|
13223
|
+
...grant,
|
|
13224
|
+
updatedAt: currentTime,
|
|
13225
|
+
lastRefreshError: report.message ?? report.code,
|
|
13226
|
+
metadata: annotateFailureMetadata(grant.metadata, report, currentTime)
|
|
13227
|
+
};
|
|
13228
|
+
if (report.code === "unauthorized" || report.code === "revoked") {
|
|
13229
|
+
nextGrant.status = "revoked";
|
|
13173
13230
|
}
|
|
13174
|
-
|
|
13231
|
+
await grantStore.saveGrant(nextGrant);
|
|
13232
|
+
}
|
|
13233
|
+
if (binding) {
|
|
13234
|
+
const nextBinding = {
|
|
13235
|
+
...binding,
|
|
13236
|
+
updatedAt: currentTime,
|
|
13237
|
+
metadata: annotateFailureMetadata(binding.metadata, report, currentTime)
|
|
13238
|
+
};
|
|
13239
|
+
if (report.code === "unauthorized" || report.code === "revoked") {
|
|
13240
|
+
nextBinding.status = "disconnected";
|
|
13241
|
+
} else if (report.code === "insufficient_scope") {
|
|
13242
|
+
nextBinding.status = "restricted";
|
|
13243
|
+
}
|
|
13244
|
+
await bindingStore.saveBinding(nextBinding);
|
|
13245
|
+
}
|
|
13246
|
+
await onReportFailure?.({
|
|
13247
|
+
credential,
|
|
13248
|
+
report,
|
|
13249
|
+
grant: grant ?? undefined,
|
|
13250
|
+
binding: binding ?? undefined
|
|
13175
13251
|
});
|
|
13176
13252
|
}
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
const dialect = new PgDialect({ casing: config.casing });
|
|
13183
|
-
let logger;
|
|
13184
|
-
if (config.logger === true) {
|
|
13185
|
-
logger = new DefaultLogger;
|
|
13186
|
-
} else if (config.logger !== false) {
|
|
13187
|
-
logger = config.logger;
|
|
13188
|
-
}
|
|
13189
|
-
let schema;
|
|
13190
|
-
if (config.schema) {
|
|
13191
|
-
const tablesConfig = extractTablesRelationalConfig(config.schema, createTableRelationsHelpers);
|
|
13192
|
-
schema = {
|
|
13193
|
-
fullSchema: config.schema,
|
|
13194
|
-
schema: tablesConfig.tables,
|
|
13195
|
-
tableNamesMap: tablesConfig.tableNamesMap
|
|
13196
|
-
};
|
|
13253
|
+
});
|
|
13254
|
+
// src/oauthLinkedProviderResolver.ts
|
|
13255
|
+
var getGrantedScopes = (scopeValue, fallbackScopes) => {
|
|
13256
|
+
if (typeof scopeValue === "string" && scopeValue.trim().length > 0) {
|
|
13257
|
+
return [...new Set(scopeValue.split(/\s+/).filter(Boolean))];
|
|
13197
13258
|
}
|
|
13198
|
-
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
if (typeof params[0] === "string") {
|
|
13206
|
-
const instance = as(params[0]);
|
|
13207
|
-
return construct(instance, params[1]);
|
|
13259
|
+
return [...new Set(fallbackScopes.filter(Boolean))];
|
|
13260
|
+
};
|
|
13261
|
+
var getExpiresAt = (tokenResponse) => {
|
|
13262
|
+
const expiresIn = tokenResponse.expires_in;
|
|
13263
|
+
const expiresInSeconds = typeof expiresIn === "number" ? expiresIn : typeof expiresIn === "string" && expiresIn.trim().length > 0 ? Number(expiresIn) : Number.NaN;
|
|
13264
|
+
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
13265
|
+
return;
|
|
13208
13266
|
}
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13216
|
-
|
|
13267
|
+
return Date.now() + expiresInSeconds * 1000;
|
|
13268
|
+
};
|
|
13269
|
+
var createOAuthLinkedProviderCredentialResolver = async ({
|
|
13270
|
+
bindingStore,
|
|
13271
|
+
grantStore,
|
|
13272
|
+
now,
|
|
13273
|
+
providersConfiguration
|
|
13274
|
+
}) => {
|
|
13275
|
+
const clientEntries = [];
|
|
13276
|
+
for (const [providerName, providerConfig] of Object.entries(providersConfiguration)) {
|
|
13277
|
+
if (!isValidProviderOption(providerName)) {
|
|
13278
|
+
continue;
|
|
13217
13279
|
}
|
|
13218
|
-
const
|
|
13219
|
-
|
|
13220
|
-
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
|
|
13224
|
-
|
|
13225
|
-
|
|
13280
|
+
const resolvedProviderClientConfiguration = resolveProviderClientConfiguration({
|
|
13281
|
+
providerName,
|
|
13282
|
+
providersConfiguration
|
|
13283
|
+
});
|
|
13284
|
+
if ("error" in resolvedProviderClientConfiguration || !resolvedProviderClientConfiguration.config) {
|
|
13285
|
+
continue;
|
|
13286
|
+
}
|
|
13287
|
+
clientEntries.push(createOAuth2Client(providerName, resolvedProviderClientConfiguration.config.credentials).then((providerInstance) => [providerName, providerInstance]));
|
|
13226
13288
|
}
|
|
13227
|
-
|
|
13228
|
-
|
|
13229
|
-
|
|
13289
|
+
const clients = new Map(await Promise.all(clientEntries));
|
|
13290
|
+
return createLinkedProviderCredentialResolver({
|
|
13291
|
+
bindingStore,
|
|
13292
|
+
grantStore,
|
|
13293
|
+
now,
|
|
13294
|
+
loadAccessTokenLease: async (grant) => grant.accessTokenCiphertext ? {
|
|
13295
|
+
accessToken: grant.accessTokenCiphertext,
|
|
13296
|
+
expiresAt: grant.expiresAt,
|
|
13297
|
+
grantedScopes: grant.grantedScopes,
|
|
13298
|
+
tokenType: grant.tokenType
|
|
13299
|
+
} : null,
|
|
13300
|
+
refreshAccessTokenLease: async (grant) => {
|
|
13301
|
+
if (!isValidProviderOption(grant.authProviderKey) || !grant.refreshTokenCiphertext) {
|
|
13302
|
+
return null;
|
|
13303
|
+
}
|
|
13304
|
+
const providerKey = grant.authProviderKey;
|
|
13305
|
+
const providerClientName = typeof grant.metadata?.providerClient === "string" && grant.metadata.providerClient.trim().length > 0 ? grant.metadata.providerClient.trim() : undefined;
|
|
13306
|
+
const resolvedProviderClientConfiguration = resolveProviderClientConfiguration({
|
|
13307
|
+
clientName: providerClientName,
|
|
13308
|
+
providerName: providerKey,
|
|
13309
|
+
providersConfiguration
|
|
13310
|
+
});
|
|
13311
|
+
if ("error" in resolvedProviderClientConfiguration || !resolvedProviderClientConfiguration.config) {
|
|
13312
|
+
return null;
|
|
13313
|
+
}
|
|
13314
|
+
const providerClient = await createOAuth2Client(providerKey, resolvedProviderClientConfiguration.config.credentials);
|
|
13315
|
+
if (!providerClient || !isRefreshableOAuth2Client(providerKey, providerClient)) {
|
|
13316
|
+
return null;
|
|
13317
|
+
}
|
|
13318
|
+
const tokenResponse = await providerClient.refreshAccessToken(grant.refreshTokenCiphertext);
|
|
13319
|
+
const refreshedAt = Date.now();
|
|
13320
|
+
const grantedScopes = getGrantedScopes(Reflect.get(tokenResponse, "scope"), grant.grantedScopes);
|
|
13321
|
+
const tokenType = Reflect.get(tokenResponse, "token_type");
|
|
13322
|
+
const refreshedGrant = {
|
|
13323
|
+
...grant,
|
|
13324
|
+
accessTokenCiphertext: tokenResponse.access_token,
|
|
13325
|
+
expiresAt: getExpiresAt(tokenResponse),
|
|
13326
|
+
grantedScopes,
|
|
13327
|
+
lastRefreshError: undefined,
|
|
13328
|
+
lastRefreshedAt: refreshedAt,
|
|
13329
|
+
refreshTokenCiphertext: tokenResponse.refresh_token ?? grant.refreshTokenCiphertext,
|
|
13330
|
+
status: "active",
|
|
13331
|
+
tokenType: typeof tokenType === "string" ? tokenType : grant.tokenType,
|
|
13332
|
+
updatedAt: refreshedAt
|
|
13333
|
+
};
|
|
13334
|
+
return {
|
|
13335
|
+
grant: refreshedGrant,
|
|
13336
|
+
lease: {
|
|
13337
|
+
accessToken: refreshedGrant.accessTokenCiphertext ?? "",
|
|
13338
|
+
expiresAt: refreshedGrant.expiresAt,
|
|
13339
|
+
grantedScopes: refreshedGrant.grantedScopes,
|
|
13340
|
+
tokenType: refreshedGrant.tokenType
|
|
13341
|
+
}
|
|
13342
|
+
};
|
|
13343
|
+
}
|
|
13344
|
+
});
|
|
13345
|
+
};
|
|
13230
13346
|
// src/neonLinkedProviders.ts
|
|
13231
13347
|
var linkedProviderGrantsTable = pgTable("linked_provider_grants", {
|
|
13232
13348
|
id: varchar("id", { length: 255 }).primaryKey(),
|
|
@@ -13753,6 +13869,7 @@ export {
|
|
|
13753
13869
|
createOAuthLinkedProviderCredentialResolver,
|
|
13754
13870
|
createNeonOAuthLinkedProviderCredentialResolver,
|
|
13755
13871
|
createNeonLinkedProviderStores,
|
|
13872
|
+
createNeonAuthSessionStore,
|
|
13756
13873
|
createLinkedProviderCredentialResolver,
|
|
13757
13874
|
createInMemoryLinkedProviderStores,
|
|
13758
13875
|
createInMemoryAuthSessionStore,
|
|
@@ -13765,5 +13882,5 @@ export {
|
|
|
13765
13882
|
AbsoluteAuthIdentityConflictError
|
|
13766
13883
|
};
|
|
13767
13884
|
|
|
13768
|
-
//# debugId=
|
|
13885
|
+
//# debugId=7F98E858A24BE38A64756E2164756E21
|
|
13769
13886
|
//# sourceMappingURL=index.js.map
|