next-action-plus 1.0.1 → 2.0.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/README.md +862 -280
- package/dist/auth/authjs.d.ts +23 -0
- package/dist/auth/authjs.js +18 -0
- package/dist/auth/better-auth.d.ts +34 -0
- package/dist/auth/better-auth.js +17 -0
- package/dist/auth/clerk.d.ts +20 -0
- package/dist/auth/clerk.js +17 -0
- package/dist/auth/iron-session.d.ts +21 -0
- package/dist/auth/iron-session.js +18 -0
- package/dist/auth/kinde.d.ts +25 -0
- package/dist/auth/kinde.js +19 -0
- package/dist/auth/supabase.d.ts +29 -0
- package/dist/auth/supabase.js +17 -0
- package/dist/auth/workos.d.ts +25 -0
- package/dist/auth/workos.js +17 -0
- package/dist/authorize/casl.d.ts +14 -0
- package/dist/authorize/casl.js +10 -0
- package/dist/authorize/cerbos.d.ts +26 -0
- package/dist/authorize/cerbos.js +10 -0
- package/dist/authorize/openfga.d.ts +20 -0
- package/dist/authorize/openfga.js +10 -0
- package/dist/authorize/oso.d.ts +20 -0
- package/dist/authorize/oso.js +10 -0
- package/dist/authorize/permit.d.ts +14 -0
- package/dist/authorize/permit.js +10 -0
- package/dist/authorize.d.ts +11 -0
- package/dist/authorize.js +2 -0
- package/dist/chunk-2INYDUJR.js +16 -0
- package/dist/chunk-A55FM7D6.js +53 -0
- package/dist/chunk-GFGIJNSY.js +19 -0
- package/dist/chunk-IFAKJ72B.js +16 -0
- package/dist/codemod/bin.js +169 -0
- package/dist/concurrency/lock/memory.d.ts +5 -0
- package/dist/concurrency/lock/memory.js +1 -0
- package/dist/concurrency/lock/postgres.d.ts +9 -0
- package/dist/concurrency/lock/postgres.js +45 -0
- package/dist/concurrency/lock/redis.d.ts +9 -0
- package/dist/concurrency/lock/redis.js +30 -0
- package/dist/concurrency.d.ts +21 -0
- package/dist/concurrency.js +48 -0
- package/dist/conformance.d.ts +29 -0
- package/dist/conformance.js +139 -0
- package/dist/gate.d.ts +17 -0
- package/dist/gate.js +2 -0
- package/dist/i18n/next-intl.d.ts +12 -0
- package/dist/i18n/next-intl.js +11 -0
- package/dist/idempotency.d.ts +12 -0
- package/dist/idempotency.js +28 -0
- package/dist/index-BSA9a_EW.d.ts +22 -0
- package/dist/index-C3Ra6AYj.d.ts +37 -0
- package/dist/index-CZFS0TSh.d.ts +53 -0
- package/dist/index-CuAEDv-H.d.ts +64 -0
- package/dist/index-DJ2Ox9am.d.ts +31 -0
- package/dist/index-DV3R2g7H.d.ts +41 -0
- package/dist/index.d.ts +196 -192
- package/dist/index.js +189 -276
- package/dist/kv/memory.d.ts +5 -0
- package/dist/kv/memory.js +27 -0
- package/dist/kv/redis.d.ts +9 -0
- package/dist/kv/redis.js +23 -0
- package/dist/queue/bullmq.d.ts +18 -0
- package/dist/queue/bullmq.js +14 -0
- package/dist/queue/inngest.d.ts +18 -0
- package/dist/queue/inngest.js +14 -0
- package/dist/queue/qstash.d.ts +19 -0
- package/dist/queue/qstash.js +14 -0
- package/dist/queue/trigger.d.ts +16 -0
- package/dist/queue/trigger.js +11 -0
- package/dist/rate/limit/arcjet.d.ts +19 -0
- package/dist/rate/limit/arcjet.js +15 -0
- package/dist/rate/limit/unkey.d.ts +25 -0
- package/dist/rate/limit/unkey.js +14 -0
- package/dist/rate/limit/upstash.d.ts +18 -0
- package/dist/rate/limit/upstash.js +15 -0
- package/dist/rate/limit.d.ts +12 -0
- package/dist/rate/limit.js +17 -0
- package/dist/react.d.ts +40 -0
- package/dist/react.js +110 -0
- package/dist/security/origin.d.ts +11 -0
- package/dist/security/origin.js +21 -0
- package/dist/security/redact.d.ts +9 -0
- package/dist/security/redact.js +15 -0
- package/dist/security/secret.d.ts +6 -0
- package/dist/security/secret.js +13 -0
- package/dist/spec.d.ts +6 -0
- package/dist/spec.js +1 -0
- package/dist/telemetry/otel.d.ts +11 -0
- package/dist/telemetry/otel.js +25 -0
- package/dist/telemetry/pino.d.ts +12 -0
- package/dist/telemetry/pino.js +18 -0
- package/dist/telemetry/sentry.d.ts +16 -0
- package/dist/telemetry/sentry.js +11 -0
- package/package.json +325 -72
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authAuthjs: <Session extends {
|
|
6
|
+
user?: {
|
|
7
|
+
id?: string | null;
|
|
8
|
+
email?: string | null;
|
|
9
|
+
} | null;
|
|
10
|
+
}>(props: Readonly<{
|
|
11
|
+
auth: () => Promise<Session | null>;
|
|
12
|
+
check?: TGateCheck<{
|
|
13
|
+
id: string;
|
|
14
|
+
session: Session;
|
|
15
|
+
}>;
|
|
16
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
17
|
+
user: {
|
|
18
|
+
id: string;
|
|
19
|
+
session: Session;
|
|
20
|
+
};
|
|
21
|
+
}, {}, true>;
|
|
22
|
+
|
|
23
|
+
export { authAuthjs };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/authjs.ts
|
|
5
|
+
var authAuthjs = (props) => {
|
|
6
|
+
const { auth, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:authjs",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const found = await auth();
|
|
12
|
+
const id = found?.user?.id ?? found?.user?.email;
|
|
13
|
+
return found && id ? { id, session: found } : null;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { authAuthjs };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authBetterAuth: <Session extends {
|
|
6
|
+
user: {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
session: unknown;
|
|
10
|
+
}>(props: Readonly<{
|
|
11
|
+
auth: {
|
|
12
|
+
api: {
|
|
13
|
+
getSession: (props: {
|
|
14
|
+
headers: Headers;
|
|
15
|
+
}) => Promise<Session | null>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
headers: () => Headers | Promise<Headers>;
|
|
19
|
+
check?: TGateCheck<{
|
|
20
|
+
id: string;
|
|
21
|
+
user: Session["user"];
|
|
22
|
+
session: Session["session"];
|
|
23
|
+
}>;
|
|
24
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
25
|
+
user: {
|
|
26
|
+
id: string;
|
|
27
|
+
user: {
|
|
28
|
+
id: string;
|
|
29
|
+
};
|
|
30
|
+
session: unknown;
|
|
31
|
+
};
|
|
32
|
+
}, {}, true>;
|
|
33
|
+
|
|
34
|
+
export { authBetterAuth };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/better-auth.ts
|
|
5
|
+
var authBetterAuth = (props) => {
|
|
6
|
+
const { auth, headers, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:better-auth",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const found = await auth.api.getSession({ headers: await headers() });
|
|
12
|
+
return found ? { id: found.user.id, user: found.user, session: found.session } : null;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { authBetterAuth };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authClerk: <Auth extends {
|
|
6
|
+
userId: string | null;
|
|
7
|
+
}>(props: Readonly<{
|
|
8
|
+
auth: () => Promise<Auth>;
|
|
9
|
+
check?: TGateCheck<{
|
|
10
|
+
id: string;
|
|
11
|
+
auth: Auth;
|
|
12
|
+
}>;
|
|
13
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
14
|
+
user: {
|
|
15
|
+
id: string;
|
|
16
|
+
auth: Auth;
|
|
17
|
+
};
|
|
18
|
+
}, {}, true>;
|
|
19
|
+
|
|
20
|
+
export { authClerk };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/clerk.ts
|
|
5
|
+
var authClerk = (props) => {
|
|
6
|
+
const { auth, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:clerk",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const found = await auth();
|
|
12
|
+
return found.userId ? { id: found.userId, auth: found } : null;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { authClerk };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authIronSession: <Session extends object>(props: Readonly<{
|
|
6
|
+
session: () => Promise<Session>;
|
|
7
|
+
id: (props: Readonly<{
|
|
8
|
+
session: Session;
|
|
9
|
+
}>) => string | undefined | null;
|
|
10
|
+
check?: TGateCheck<{
|
|
11
|
+
id: string;
|
|
12
|
+
session: Session;
|
|
13
|
+
}>;
|
|
14
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
15
|
+
user: {
|
|
16
|
+
id: string;
|
|
17
|
+
session: Awaited<Session>;
|
|
18
|
+
};
|
|
19
|
+
}, {}, true>;
|
|
20
|
+
|
|
21
|
+
export { authIronSession };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/iron-session.ts
|
|
5
|
+
var authIronSession = (props) => {
|
|
6
|
+
const { session, id, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:iron-session",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const current = await session();
|
|
12
|
+
const found = id({ session: current });
|
|
13
|
+
return found ? { id: found, session: current } : null;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { authIronSession };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authKinde: <User extends {
|
|
6
|
+
id: string;
|
|
7
|
+
}, Session extends {
|
|
8
|
+
isAuthenticated: () => Promise<boolean | null>;
|
|
9
|
+
getUser: () => Promise<User | null>;
|
|
10
|
+
}>(props: Readonly<{
|
|
11
|
+
session: () => Session;
|
|
12
|
+
check?: TGateCheck<{
|
|
13
|
+
id: string;
|
|
14
|
+
user: User;
|
|
15
|
+
session: Session;
|
|
16
|
+
}>;
|
|
17
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
18
|
+
user: {
|
|
19
|
+
id: string;
|
|
20
|
+
user: User;
|
|
21
|
+
session: Session;
|
|
22
|
+
};
|
|
23
|
+
}, {}, true>;
|
|
24
|
+
|
|
25
|
+
export { authKinde };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/kinde.ts
|
|
5
|
+
var authKinde = (props) => {
|
|
6
|
+
const { session, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:kinde",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const current = session();
|
|
12
|
+
if (!await current.isAuthenticated()) return null;
|
|
13
|
+
const user = await current.getUser();
|
|
14
|
+
return user ? { id: user.id, user, session: current } : null;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { authKinde };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authSupabase: <Claims extends {
|
|
6
|
+
sub: string;
|
|
7
|
+
}>(props: Readonly<{
|
|
8
|
+
client: () => Promise<{
|
|
9
|
+
auth: {
|
|
10
|
+
getClaims: () => Promise<{
|
|
11
|
+
data: {
|
|
12
|
+
claims: Claims;
|
|
13
|
+
} | null;
|
|
14
|
+
error: unknown;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
check?: TGateCheck<{
|
|
19
|
+
id: string;
|
|
20
|
+
claims: Claims;
|
|
21
|
+
}>;
|
|
22
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
23
|
+
user: {
|
|
24
|
+
id: string;
|
|
25
|
+
claims: Claims;
|
|
26
|
+
};
|
|
27
|
+
}, {}, true>;
|
|
28
|
+
|
|
29
|
+
export { authSupabase };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/supabase.ts
|
|
5
|
+
var authSupabase = (props) => {
|
|
6
|
+
const { client, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:supabase",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const { data, error } = await (await client()).auth.getClaims();
|
|
12
|
+
return !error && data?.claims?.sub ? { id: data.claims.sub, claims: data.claims } : null;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { authSupabase };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { T as TGateCheck, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authWorkos: <User extends {
|
|
6
|
+
id: string;
|
|
7
|
+
}>(props: Readonly<{
|
|
8
|
+
withAuth: () => Promise<{
|
|
9
|
+
user: User | null;
|
|
10
|
+
organizationId?: string | null;
|
|
11
|
+
}>;
|
|
12
|
+
check?: TGateCheck<{
|
|
13
|
+
id: string;
|
|
14
|
+
user: User;
|
|
15
|
+
organizationId: string | null;
|
|
16
|
+
}>;
|
|
17
|
+
}>) => TPlugin<TPluginShape<object>, {
|
|
18
|
+
user: {
|
|
19
|
+
id: string;
|
|
20
|
+
user: User;
|
|
21
|
+
organizationId: string | null;
|
|
22
|
+
};
|
|
23
|
+
}, {}, true>;
|
|
24
|
+
|
|
25
|
+
export { authWorkos };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { gateCreate } from '../chunk-GFGIJNSY.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/auth/workos.ts
|
|
5
|
+
var authWorkos = (props) => {
|
|
6
|
+
const { withAuth, check } = props;
|
|
7
|
+
return gateCreate({
|
|
8
|
+
name: "auth:workos",
|
|
9
|
+
check,
|
|
10
|
+
user: async () => {
|
|
11
|
+
const found = await withAuth();
|
|
12
|
+
return found.user ? { id: found.user.id, user: found.user, organizationId: found.organizationId ?? null } : null;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { authWorkos };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizeCasl: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
ability: TPluginRead<{
|
|
7
|
+
can: (action: string, subject: unknown, field?: string) => boolean;
|
|
8
|
+
}, TPluginShape<Ctx>>;
|
|
9
|
+
action: string;
|
|
10
|
+
subject: TPluginRead<unknown, TPluginShape<Ctx>>;
|
|
11
|
+
field?: string;
|
|
12
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
13
|
+
|
|
14
|
+
export { authorizeCasl };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authorizeCreate } from '../chunk-2INYDUJR.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/authorize/casl.ts
|
|
5
|
+
var authorizeCasl = (props) => {
|
|
6
|
+
const { ability, action, subject, field } = props;
|
|
7
|
+
return authorizeCreate({ name: "authorize:casl", can: async (call) => (await ability(call)).can(action, await subject(call), field) });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { authorizeCasl };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizeCerbos: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
cerbos: {
|
|
7
|
+
isAllowed: (props: {
|
|
8
|
+
principal: unknown;
|
|
9
|
+
resource: unknown;
|
|
10
|
+
action: string;
|
|
11
|
+
}) => Promise<boolean>;
|
|
12
|
+
};
|
|
13
|
+
principal: TPluginRead<{
|
|
14
|
+
id: string;
|
|
15
|
+
roles: string[];
|
|
16
|
+
attr?: Record<string, unknown>;
|
|
17
|
+
}, TPluginShape<Ctx>>;
|
|
18
|
+
resource: TPluginRead<{
|
|
19
|
+
kind: string;
|
|
20
|
+
id: string;
|
|
21
|
+
attr?: Record<string, unknown>;
|
|
22
|
+
}, TPluginShape<Ctx>>;
|
|
23
|
+
action: string;
|
|
24
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
25
|
+
|
|
26
|
+
export { authorizeCerbos };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authorizeCreate } from '../chunk-2INYDUJR.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/authorize/cerbos.ts
|
|
5
|
+
var authorizeCerbos = (props) => {
|
|
6
|
+
const { cerbos, principal, resource, action } = props;
|
|
7
|
+
return authorizeCreate({ name: "authorize:cerbos", can: async (call) => cerbos.isAllowed({ principal: await principal(call), resource: await resource(call), action }) });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { authorizeCerbos };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizeOpenfga: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
client: {
|
|
7
|
+
check: (props: {
|
|
8
|
+
user: string;
|
|
9
|
+
relation: string;
|
|
10
|
+
object: string;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
allowed?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
15
|
+
user: TPluginRead<string, TPluginShape<Ctx>>;
|
|
16
|
+
relation: string;
|
|
17
|
+
object: TPluginRead<string, TPluginShape<Ctx>>;
|
|
18
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
19
|
+
|
|
20
|
+
export { authorizeOpenfga };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authorizeCreate } from '../chunk-2INYDUJR.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/authorize/openfga.ts
|
|
5
|
+
var authorizeOpenfga = (props) => {
|
|
6
|
+
const { client, user, relation, object } = props;
|
|
7
|
+
return authorizeCreate({ name: "authorize:openfga", can: async (call) => (await client.check({ user: await user(call), relation, object: await object(call) })).allowed === true });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { authorizeOpenfga };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizeOso: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
oso: {
|
|
7
|
+
authorize: (actor: unknown, action: string, resource: unknown) => Promise<boolean>;
|
|
8
|
+
};
|
|
9
|
+
actor: TPluginRead<{
|
|
10
|
+
type: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}, TPluginShape<Ctx>>;
|
|
13
|
+
action: string;
|
|
14
|
+
resource: TPluginRead<{
|
|
15
|
+
type: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}, TPluginShape<Ctx>>;
|
|
18
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
19
|
+
|
|
20
|
+
export { authorizeOso };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authorizeCreate } from '../chunk-2INYDUJR.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/authorize/oso.ts
|
|
5
|
+
var authorizeOso = (props) => {
|
|
6
|
+
const { oso, actor, action, resource } = props;
|
|
7
|
+
return authorizeCreate({ name: "authorize:oso", can: async (call) => oso.authorize(await actor(call), action, await resource(call)) });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { authorizeOso };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { d as TPlugin } from '../index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from '../index-CZFS0TSh.js';
|
|
3
|
+
import '../index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizePermit: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
permit: {
|
|
7
|
+
check: (user: unknown, action: string, resource: unknown) => Promise<boolean>;
|
|
8
|
+
};
|
|
9
|
+
user: TPluginRead<unknown, TPluginShape<Ctx>>;
|
|
10
|
+
action: string;
|
|
11
|
+
resource: TPluginRead<unknown, TPluginShape<Ctx>>;
|
|
12
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
13
|
+
|
|
14
|
+
export { authorizePermit };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { authorizeCreate } from '../chunk-2INYDUJR.js';
|
|
2
|
+
import '../chunk-IFAKJ72B.js';
|
|
3
|
+
|
|
4
|
+
// src/authorize/permit.ts
|
|
5
|
+
var authorizePermit = (props) => {
|
|
6
|
+
const { permit, user, action, resource } = props;
|
|
7
|
+
return authorizeCreate({ name: "authorize:permit", can: async (call) => permit.check(await user(call), action, await resource(call)) });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { authorizePermit };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { d as TPlugin } from './index-DV3R2g7H.js';
|
|
2
|
+
import { b as TPluginRead, c as TPluginShape } from './index-CZFS0TSh.js';
|
|
3
|
+
import './index-CuAEDv-H.js';
|
|
4
|
+
|
|
5
|
+
declare const authorizeCreate: <Ctx extends object = object>(props: Readonly<{
|
|
6
|
+
name?: string;
|
|
7
|
+
can: TPluginRead<boolean, TPluginShape<Ctx>>;
|
|
8
|
+
message?: string;
|
|
9
|
+
}>) => TPlugin<TPluginShape<Ctx>>;
|
|
10
|
+
|
|
11
|
+
export { authorizeCreate };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { errorCreate } from './chunk-IFAKJ72B.js';
|
|
2
|
+
|
|
3
|
+
// src/authorize/create.ts
|
|
4
|
+
var authorizeCreate = (props) => {
|
|
5
|
+
const { name, can, message } = props;
|
|
6
|
+
return {
|
|
7
|
+
name: name ?? "authorize",
|
|
8
|
+
version: 1,
|
|
9
|
+
run: async (call) => {
|
|
10
|
+
if (!await can({ input: call.input, args: call.args, ctx: call.ctx, meta: call.meta })) throw errorCreate({ code: "FORBIDDEN", message: message ?? "You do not have access to this" });
|
|
11
|
+
return call.next();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { authorizeCreate };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/concurrency/lock/memory.ts
|
|
2
|
+
var lockMemory = () => {
|
|
3
|
+
const held = /* @__PURE__ */ new Map();
|
|
4
|
+
const generations = /* @__PURE__ */ new Map();
|
|
5
|
+
const waiters = /* @__PURE__ */ new Map();
|
|
6
|
+
let counter = 0;
|
|
7
|
+
const wake = (key) => {
|
|
8
|
+
for (const resolve of waiters.get(key) ?? []) resolve();
|
|
9
|
+
waiters.delete(key);
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
name: "memory",
|
|
13
|
+
version: 1,
|
|
14
|
+
acquire: async (props) => {
|
|
15
|
+
const { key, leaseMs, waitMs } = props;
|
|
16
|
+
const deadline = Date.now() + waitMs;
|
|
17
|
+
for (; ; ) {
|
|
18
|
+
const current = held.get(key);
|
|
19
|
+
if (!current || current.expiresAt <= Date.now()) {
|
|
20
|
+
const token = ++counter;
|
|
21
|
+
held.set(key, { token, expiresAt: Date.now() + leaseMs });
|
|
22
|
+
return {
|
|
23
|
+
token,
|
|
24
|
+
release: async () => {
|
|
25
|
+
if (held.get(key)?.token !== token) return;
|
|
26
|
+
held.delete(key);
|
|
27
|
+
wake(key);
|
|
28
|
+
},
|
|
29
|
+
extend: async (extendProps) => {
|
|
30
|
+
const now = held.get(key);
|
|
31
|
+
if (now?.token !== token || now.expiresAt <= Date.now()) return false;
|
|
32
|
+
now.expiresAt = Date.now() + extendProps.ms;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const remaining = deadline - Date.now();
|
|
38
|
+
if (remaining <= 0) return null;
|
|
39
|
+
await new Promise((resolve) => {
|
|
40
|
+
waiters.set(key, [...waiters.get(key) ?? [], resolve]);
|
|
41
|
+
setTimeout(resolve, Math.max(1, Math.min(remaining, current.expiresAt - Date.now())));
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
generation: async (props) => {
|
|
46
|
+
const next = (generations.get(props.key) ?? 0) + (props.bump ? 1 : 0);
|
|
47
|
+
generations.set(props.key, next);
|
|
48
|
+
return next;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { lockMemory };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { errorCreate } from './chunk-IFAKJ72B.js';
|
|
2
|
+
|
|
3
|
+
// src/gate/create.ts
|
|
4
|
+
var gateCreate = (props) => {
|
|
5
|
+
const { name, user, check, message } = props;
|
|
6
|
+
return {
|
|
7
|
+
name: name ?? "gate",
|
|
8
|
+
version: 1,
|
|
9
|
+
gate: true,
|
|
10
|
+
run: async (call) => {
|
|
11
|
+
const found = await user({ input: call.input, args: call.args, ctx: call.ctx, meta: call.meta });
|
|
12
|
+
if (found === null || found === void 0) throw errorCreate({ code: "UNAUTHORIZED", message: message?.unauthorized ?? "Sign in to continue" });
|
|
13
|
+
if (check && !await check({ user: found, ctx: call.ctx, meta: call.meta, input: call.input })) throw errorCreate({ code: "FORBIDDEN", message: message?.forbidden ?? "You do not have access to this" });
|
|
14
|
+
return call.next({ ctx: { user: found } });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { gateCreate };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/error/create.ts
|
|
2
|
+
var ERROR_BRAND = /* @__PURE__ */ Symbol.for("next-action-plus/error");
|
|
3
|
+
var ERROR_STATUS = { VALIDATION: 400, UNAUTHORIZED: 401, FORBIDDEN: 403, NOT_FOUND: 404, CONFLICT: 409, RATE_LIMITED: 429, DROPPED: 409, SUPERSEDED: 409, LOCK_TIMEOUT: 423, TIMEOUT: 504, ABORTED: 499, LIMIT: 413, STALE_ACTION: 410, INTERNAL: 500 };
|
|
4
|
+
var errorCreate = (props) => {
|
|
5
|
+
const { code, message, status, phase, issues, data, cause, expose, correlationId } = props;
|
|
6
|
+
const error = new Error(message ?? code, cause === void 0 ? void 0 : { cause });
|
|
7
|
+
error.name = "ActionError";
|
|
8
|
+
return Object.assign(error, { [ERROR_BRAND]: true, code, status: status ?? ERROR_STATUS[code] ?? 400, phase, issues: issues ?? [], data, correlationId, expose: expose ?? code !== "INTERNAL" });
|
|
9
|
+
};
|
|
10
|
+
var errorGet = (props) => {
|
|
11
|
+
const { error, code } = props;
|
|
12
|
+
if (typeof error !== "object" || error === null || error[ERROR_BRAND] !== true) return void 0;
|
|
13
|
+
return code === void 0 || error.code === code ? error : void 0;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { errorCreate, errorGet };
|