@absolutejs/auth 0.33.0 → 0.34.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/dist/fga/config.d.ts +3 -3
- package/dist/fga/redisCheckCache.d.ts +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -2
- package/dist/index.js.map +6 -5
- package/package.json +1 -1
package/dist/fga/config.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { FgaSchema, Warrant, WarrantStore } from './types';
|
|
2
2
|
export type FgaCache = {
|
|
3
|
-
clear: () => void
|
|
4
|
-
get: (key: string) => boolean | undefined
|
|
5
|
-
set: (key: string, value: boolean) => void
|
|
3
|
+
clear: () => void | Promise<void>;
|
|
4
|
+
get: (key: string) => boolean | undefined | Promise<boolean | undefined>;
|
|
5
|
+
set: (key: string, value: boolean) => void | Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
export type FgaConfig = {
|
|
8
8
|
cache?: FgaCache;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RedisLike } from '../stores/redis';
|
|
2
|
+
import type { FgaCache } from './config';
|
|
3
|
+
export type RedisFgaCacheClient = RedisLike & {
|
|
4
|
+
keys?: (pattern: string) => Promise<string[]>;
|
|
5
|
+
};
|
|
6
|
+
type CreateRedisFgaCacheOptions = {
|
|
7
|
+
keyPrefix?: string;
|
|
8
|
+
ttlMs?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const createRedisFgaCache: (redis: RedisFgaCacheClient, { keyPrefix, ttlMs }?: CreateRedisFgaCacheOptions) => FgaCache;
|
|
11
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -15140,6 +15140,7 @@ export * from './fga/config';
|
|
|
15140
15140
|
export * from './fga/schema';
|
|
15141
15141
|
export * from './fga/types';
|
|
15142
15142
|
export { createInMemoryWarrantStore, warrantKey } from './fga/inMemoryStores';
|
|
15143
|
+
export { createRedisFgaCache, type RedisFgaCacheClient } from './fga/redisCheckCache';
|
|
15143
15144
|
export { createNeonWarrantStore, createPostgresWarrantStore, warrantsTable } from './fga/postgresStores';
|
|
15144
15145
|
export { ssoDiscoveryRoute } from './sso/discoveryRoute';
|
|
15145
15146
|
export { oidcSsoRoutes } from './sso/oidcRoutes';
|
package/dist/index.js
CHANGED
|
@@ -22191,7 +22191,7 @@ var evaluate = async (context, resourceType, resourceId, relation, depth) => {
|
|
|
22191
22191
|
var cacheKey = (query) => `${query.resourceType}:${query.resourceId}#${query.relation}@${query.subjectType}:${query.subjectId}`;
|
|
22192
22192
|
var check = async (config, query) => {
|
|
22193
22193
|
const key = cacheKey(query);
|
|
22194
|
-
const cached = config.cache?.get(key);
|
|
22194
|
+
const cached = await config.cache?.get(key);
|
|
22195
22195
|
if (cached !== undefined)
|
|
22196
22196
|
return cached;
|
|
22197
22197
|
const context = {
|
|
@@ -22375,6 +22375,29 @@ var createInMemoryWarrantStore = () => {
|
|
|
22375
22375
|
};
|
|
22376
22376
|
};
|
|
22377
22377
|
var warrantKey = (warrant) => `${warrant.resourceType}:${warrant.resourceId}#${warrant.relation}@${warrant.subjectType}:${warrant.subjectId}#${warrant.subjectRelation ?? ""}`;
|
|
22378
|
+
// src/fga/redisCheckCache.ts
|
|
22379
|
+
var DEFAULT_TTL_MS = 5000;
|
|
22380
|
+
var DEFAULT_PREFIX2 = "auth:fga:";
|
|
22381
|
+
var parseBoolean = (raw) => {
|
|
22382
|
+
if (raw === "true")
|
|
22383
|
+
return true;
|
|
22384
|
+
if (raw === "false")
|
|
22385
|
+
return false;
|
|
22386
|
+
return;
|
|
22387
|
+
};
|
|
22388
|
+
var createRedisFgaCache = (redis, { keyPrefix = DEFAULT_PREFIX2, ttlMs = DEFAULT_TTL_MS } = {}) => ({
|
|
22389
|
+
clear: async () => {
|
|
22390
|
+
const enumerate = redis.keys;
|
|
22391
|
+
if (enumerate === undefined)
|
|
22392
|
+
return;
|
|
22393
|
+
const keys = await enumerate(`${keyPrefix}*`);
|
|
22394
|
+
await Promise.all(keys.map((key) => redis.del(key)));
|
|
22395
|
+
},
|
|
22396
|
+
get: async (key) => parseBoolean(await redis.get(keyPrefix + key)),
|
|
22397
|
+
set: async (key, value) => {
|
|
22398
|
+
await redis.set(keyPrefix + key, value ? "true" : "false", ttlMs);
|
|
22399
|
+
}
|
|
22400
|
+
});
|
|
22378
22401
|
// src/fga/postgresStores.ts
|
|
22379
22402
|
var ID_LENGTH9 = 255;
|
|
22380
22403
|
var warrantsTable = pgTable("auth_fga_warrants", {
|
|
@@ -23734,6 +23757,7 @@ export {
|
|
|
23734
23757
|
createScimToken,
|
|
23735
23758
|
createRiskEngine,
|
|
23736
23759
|
createRedisLockoutStore,
|
|
23760
|
+
createRedisFgaCache,
|
|
23737
23761
|
createRedisAuthSessionStore,
|
|
23738
23762
|
createPostgresWebhookDeliveryStore,
|
|
23739
23763
|
createPostgresWebAuthnCredentialStore,
|
|
@@ -23901,5 +23925,5 @@ export {
|
|
|
23901
23925
|
AuthIdentityConflictError
|
|
23902
23926
|
};
|
|
23903
23927
|
|
|
23904
|
-
//# debugId=
|
|
23928
|
+
//# debugId=0F54EE0288E37B6464756E2164756E21
|
|
23905
23929
|
//# sourceMappingURL=index.js.map
|