@beesolve/iam-policy-ts 0.1.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 +144 -0
- package/dist/catalog.d.ts +472 -0
- package/dist/catalog.d.ts.map +1 -0
- package/dist/catalog.js +21692 -0
- package/dist/helpers.d.ts +17 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +12 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/render.d.ts +20 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +102 -0
- package/dist/schema.d.ts +269 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +103 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @beesolve/iam-policy-ts
|
|
2
|
+
|
|
3
|
+
Type-safe IAM policy helpers with an auto-generated action catalog from AWS.
|
|
4
|
+
|
|
5
|
+
Provides full autocomplete for all AWS IAM actions when writing inline policies in TypeScript.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @beesolve/iam-policy-ts
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### IAM Action Helpers
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { iam, iamAction } from "@beesolve/iam-policy-ts";
|
|
19
|
+
|
|
20
|
+
// Per-service helper with autocomplete
|
|
21
|
+
iam.s3("GetObject"); // "s3:GetObject"
|
|
22
|
+
iam.organizations("ListAccounts"); // "organizations:ListAccounts"
|
|
23
|
+
iam["sso-directory"]("SearchUsers"); // "sso-directory:SearchUsers"
|
|
24
|
+
|
|
25
|
+
// Lower-level function
|
|
26
|
+
iamAction("s3", "GetObject"); // "s3:GetObject"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Policy Validation
|
|
30
|
+
|
|
31
|
+
Two validation modes are available:
|
|
32
|
+
|
|
33
|
+
**Permissive (default)** — validates structural shape only (field types, allowed keys). Matches what AWS accepts at the JSON level without enforcing grammar rules like Action/NotAction exclusivity.
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import {
|
|
37
|
+
isIamPolicyDocument,
|
|
38
|
+
assertIamPolicyDocument,
|
|
39
|
+
iamPolicyDocumentSchema,
|
|
40
|
+
} from "@beesolve/iam-policy-ts";
|
|
41
|
+
|
|
42
|
+
// Type guard
|
|
43
|
+
if (isIamPolicyDocument(unknownValue)) {
|
|
44
|
+
// unknownValue is typed as IamPolicyDocument
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Assertion (throws on invalid input)
|
|
48
|
+
const policy = assertIamPolicyDocument(jsonInput);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Strict** — additionally enforces IAM grammar rules:
|
|
52
|
+
- Must have exactly one of `Action` or `NotAction`
|
|
53
|
+
- Cannot have both `Resource` and `NotResource`
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import {
|
|
57
|
+
isIamPolicyDocumentStrict,
|
|
58
|
+
assertIamPolicyDocumentStrict,
|
|
59
|
+
iamPolicyDocumentStrictSchema,
|
|
60
|
+
} from "@beesolve/iam-policy-ts";
|
|
61
|
+
|
|
62
|
+
// Rejects policies with both Action and NotAction, etc.
|
|
63
|
+
if (isIamPolicyDocumentStrict(unknownValue)) {
|
|
64
|
+
// Passes strict grammar checks
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Render Policy as TypeScript
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { policyToTypescript } from "@beesolve/iam-policy-ts";
|
|
72
|
+
|
|
73
|
+
const ts = policyToTypescript({
|
|
74
|
+
Version: "2012-10-17",
|
|
75
|
+
Statement: [{
|
|
76
|
+
Effect: "Allow",
|
|
77
|
+
Action: ["s3:GetObject", "s3:ListBucket"],
|
|
78
|
+
Resource: "*",
|
|
79
|
+
}],
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Output uses iam.* helpers for known actions:
|
|
83
|
+
// {
|
|
84
|
+
// Version: "2012-10-17",
|
|
85
|
+
// Statement: [
|
|
86
|
+
// {
|
|
87
|
+
// Effect: "Allow",
|
|
88
|
+
// Action: [
|
|
89
|
+
// iam.s3("GetObject"),
|
|
90
|
+
// iam.s3("ListBucket")
|
|
91
|
+
// ],
|
|
92
|
+
// Resource: "*"
|
|
93
|
+
// }
|
|
94
|
+
// ]
|
|
95
|
+
// }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Access the Raw Catalog
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import {
|
|
102
|
+
iamActionCatalog,
|
|
103
|
+
iamActionCatalogSourceSha256,
|
|
104
|
+
iamActionCatalogActionCount,
|
|
105
|
+
} from "@beesolve/iam-policy-ts";
|
|
106
|
+
|
|
107
|
+
// iamActionCatalog is a typed const object:
|
|
108
|
+
// { s3: ["AbortMultipartUpload", ...], kms: ["CancelKeyDeletion", ...], ... }
|
|
109
|
+
|
|
110
|
+
console.log(`${iamActionCatalogActionCount} actions across ${Object.keys(iamActionCatalog).length} services`);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Updating the Catalog
|
|
114
|
+
|
|
115
|
+
Run `npm run generate` to fetch the latest IAM action data from AWS and regenerate `src/catalog.ts`.
|
|
116
|
+
|
|
117
|
+
The plan is to automate this via a daily Lambda function that publishes new versions when the upstream data changes (see `extracting-package-plan.md` in the parent repo for details). That automation is not yet implemented.
|
|
118
|
+
|
|
119
|
+
## Versioning
|
|
120
|
+
|
|
121
|
+
Once automated publishing is set up, this package will use date-based versions (`YYYY-MM-DD`). A new version will be published daily only when the upstream AWS IAM action catalog changes.
|
|
122
|
+
|
|
123
|
+
Source: https://awspolicygen.s3.amazonaws.com/js/policies.js
|
|
124
|
+
|
|
125
|
+
## Types
|
|
126
|
+
|
|
127
|
+
All IAM policy types are exported:
|
|
128
|
+
|
|
129
|
+
- `IamPolicyDocument` / `IamPolicyDocumentStrict`
|
|
130
|
+
- `IamPolicyStatement` / `IamPolicyStatementStrict`
|
|
131
|
+
- `IamPolicyPrincipal`
|
|
132
|
+
- `IamPolicyPrincipalMap`
|
|
133
|
+
- `IamPolicyConditionBlock`
|
|
134
|
+
- `IamPolicyStringList`
|
|
135
|
+
- `IamPolicyScalar`
|
|
136
|
+
- `IamPolicyScalarList`
|
|
137
|
+
- `IamPolicyVersion`
|
|
138
|
+
- `IamPolicyServicePrefix`
|
|
139
|
+
- `IamPolicyActionNameByService<TService>`
|
|
140
|
+
- `IamPolicyActionForService<TService>`
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|