@nmnmcc/ability 0.3.0 → 1.0.1
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 +199 -31
- package/dist/Authorizer.d.ts +64 -39
- package/dist/Authorizer.d.ts.map +1 -1
- package/dist/Authorizer.js +291 -6
- package/dist/Authorizer.js.map +1 -1
- package/dist/Condition.d.ts +444 -65
- package/dist/Condition.d.ts.map +1 -1
- package/dist/Condition.js +1007 -25
- package/dist/Condition.js.map +1 -1
- package/dist/Domain.d.ts +27 -17
- package/dist/Domain.d.ts.map +1 -1
- package/dist/Domain.js +52 -10
- package/dist/Domain.js.map +1 -1
- package/dist/HttpApi.d.ts +84 -40
- package/dist/HttpApi.d.ts.map +1 -1
- package/dist/HttpApi.js +103 -13
- package/dist/HttpApi.js.map +1 -1
- package/dist/Policy.d.ts +314 -56
- package/dist/Policy.d.ts.map +1 -1
- package/dist/Policy.js +1215 -38
- package/dist/Policy.js.map +1 -1
- package/dist/Principal.js +2 -2
- package/dist/Principal.js.map +1 -1
- package/dist/Resource.d.ts +171 -20
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +788 -15
- package/dist/Resource.js.map +1 -1
- package/dist/Rule.d.ts +115 -29
- package/dist/Rule.d.ts.map +1 -1
- package/dist/Rule.js +219 -12
- package/dist/Rule.js.map +1 -1
- package/dist/index.js +4 -4
- package/package.json +2 -2
- package/src/Authorizer.ts +625 -61
- package/src/Condition.ts +2403 -112
- package/src/Domain.ts +80 -23
- package/src/HttpApi.ts +225 -25
- package/src/Policy.ts +2836 -96
- package/src/Principal.ts +2 -2
- package/src/Resource.ts +1544 -29
- package/src/Rule.ts +463 -45
- package/dist/internal/authorizer.d.ts +0 -28
- package/dist/internal/authorizer.d.ts.map +0 -1
- package/dist/internal/authorizer.js +0 -153
- package/dist/internal/authorizer.js.map +0 -1
- package/dist/internal/condition.d.ts +0 -11
- package/dist/internal/condition.d.ts.map +0 -1
- package/dist/internal/condition.js +0 -393
- package/dist/internal/condition.js.map +0 -1
- package/dist/internal/domain.js +0 -34
- package/dist/internal/domain.js.map +0 -1
- package/dist/internal/httpApi.js +0 -41
- package/dist/internal/httpApi.js.map +0 -1
- package/dist/internal/policy.js +0 -524
- package/dist/internal/policy.js.map +0 -1
- package/dist/internal/resource.js +0 -66
- package/dist/internal/resource.js.map +0 -1
- package/dist/internal/rule.js +0 -131
- package/dist/internal/rule.js.map +0 -1
- package/src/internal/authorizer.ts +0 -271
- package/src/internal/condition.ts +0 -607
- package/src/internal/domain.ts +0 -56
- package/src/internal/httpApi.ts +0 -84
- package/src/internal/policy.ts +0 -815
- package/src/internal/resource.ts +0 -98
- package/src/internal/rule.ts +0 -203
package/src/internal/httpApi.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// A `load` function of a requirement is kept in an annotation, so its error
|
|
2
|
-
// type and its service type are erased to `unknown`. The language service
|
|
3
|
-
// check for `unknown` in an Effect is off here.
|
|
4
|
-
// @effect-diagnostics anyUnknownInErrorContext:off
|
|
5
|
-
import * as Context from "effect/Context"
|
|
6
|
-
import * as Effect from "effect/Effect"
|
|
7
|
-
import * as Layer from "effect/Layer"
|
|
8
|
-
import * as Option from "effect/Option"
|
|
9
|
-
import { HttpRouter } from "effect/http"
|
|
10
|
-
import type * as Authorizer from "../Authorizer.ts"
|
|
11
|
-
import type * as HttpApi from "../HttpApi.ts"
|
|
12
|
-
import { GroupRequired, Required } from "../HttpApi.ts"
|
|
13
|
-
|
|
14
|
-
/** @internal */
|
|
15
|
-
export const requires = (
|
|
16
|
-
_authorizer: unknown,
|
|
17
|
-
action: string,
|
|
18
|
-
kind: string,
|
|
19
|
-
load?: HttpApi.Requirement["load"],
|
|
20
|
-
): HttpApi.Requirement =>
|
|
21
|
-
Object.freeze(load === undefined ? { action, kind } : { action, kind, load })
|
|
22
|
-
|
|
23
|
-
/** @internal */
|
|
24
|
-
export const layer = (
|
|
25
|
-
middleware: Context.ServiceClass<any, string, any>,
|
|
26
|
-
authorizer: Authorizer.AnyServiceClass,
|
|
27
|
-
) =>
|
|
28
|
-
Layer.effect(
|
|
29
|
-
middleware,
|
|
30
|
-
Effect.gen(function* () {
|
|
31
|
-
const service = yield* authorizer
|
|
32
|
-
const services = yield* Effect.context<never>()
|
|
33
|
-
return Effect.fnUntraced(function* (
|
|
34
|
-
httpEffect: Effect.Effect<unknown, unknown, unknown>,
|
|
35
|
-
options: {
|
|
36
|
-
readonly endpoint: {
|
|
37
|
-
readonly name: string
|
|
38
|
-
readonly method: string
|
|
39
|
-
readonly annotations: Context.Context<never>
|
|
40
|
-
}
|
|
41
|
-
readonly group: {
|
|
42
|
-
readonly identifier: string
|
|
43
|
-
readonly annotations: Context.Context<never>
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
) {
|
|
47
|
-
const requirements = Option.orElse(
|
|
48
|
-
Context.getOption(options.endpoint.annotations, Required),
|
|
49
|
-
() =>
|
|
50
|
-
Option.map(
|
|
51
|
-
Context.getOption(options.group.annotations, GroupRequired),
|
|
52
|
-
(rules) =>
|
|
53
|
-
options.endpoint.method === "GET" ? rules.read : rules.write,
|
|
54
|
-
),
|
|
55
|
-
)
|
|
56
|
-
if (Option.isNone(requirements)) {
|
|
57
|
-
return yield* Effect.die(
|
|
58
|
-
new Error(
|
|
59
|
-
`The endpoint ${options.group.identifier}.${options.endpoint.name} does not say what it needs. Give it the HttpApi.Required annotation.`,
|
|
60
|
-
),
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
for (const requirement of requirements.value) {
|
|
64
|
-
if (requirement.load === undefined) {
|
|
65
|
-
yield* service.check({
|
|
66
|
-
action: requirement.action,
|
|
67
|
-
kind: requirement.kind,
|
|
68
|
-
} as never)
|
|
69
|
-
} else {
|
|
70
|
-
const params = yield* HttpRouter.params
|
|
71
|
-
const value = yield* Effect.provideContext(
|
|
72
|
-
requirement.load(params),
|
|
73
|
-
services,
|
|
74
|
-
)
|
|
75
|
-
yield* service.check({
|
|
76
|
-
action: requirement.action,
|
|
77
|
-
resource: value,
|
|
78
|
-
} as never)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return yield* httpEffect
|
|
82
|
-
})
|
|
83
|
-
}),
|
|
84
|
-
)
|