iam-floyd 0.761.0 → 0.764.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/AGENTS.md CHANGED
@@ -10,138 +10,238 @@ IAM Floyd is an AWS IAM policy statement generator with a fluent interface. It g
10
10
 
11
11
  ### Generated Code Structure
12
12
 
13
- - `lib/generated/policy-statements/` - Contains generated TypeScript classes for each AWS service (400+ services)
14
- - `lib/generated/index.ts` - Main export file that re-exports all service classes
13
+ - `lib/generated/policy-statements/` - Generated TypeScript class per AWS service (460+ files)
14
+ - `lib/generated/index.ts` - Re-exports all service classes
15
15
  - `lib/generated/aws-managed-policies/` - Generated AWS managed policies
16
- - `lib/shared/` - Core shared classes like `PolicyStatement`, `All`, and `Operator`
17
- - `lib/collection/` - Predefined policy collections and utilities
16
+ - `lib/shared/` - Hand-written core: `PolicyStatement`, `All`, `Operator`, `AccessLevel`
17
+ - `lib/collection/` - Predefined policy collection utilities
18
+ - `lib/generator/` - Scrapes AWS docs and generates `lib/generated/` via `cheerio` + `ts-morph`
18
19
 
19
- ### Code Generation Pipeline
20
+ ### PolicyStatement Inheritance Chain
20
21
 
21
- The codebase uses a sophisticated generation system:
22
+ Built in 10 numbered layers (`lib/shared/policy-statement/`):
22
23
 
23
- 1. `bin/generate.ts` - Main generation entry point that orchestrates the process
24
- 2. `lib/generator/` - Contains the generation logic that scrapes AWS documentation
25
- 3. Generated files are created in TypeScript and compiled to JavaScript for distribution
24
+ ```
25
+ 1-base 2-conditions 3-actions 4-resources 5-effect
26
+ 6-arn-defaults 8-principals 10-final (PolicyStatement)
27
+ ```
28
+
29
+ Each `*.CDK.ts` file is the CDK variant of that layer (swapped in by `bin/mkcdk.ts`).
30
+
31
+ ### Dual Package Strategy
26
32
 
27
- ### Key Classes
33
+ One codebase produces two npm packages:
28
34
 
29
- - `PolicyStatement` - Base class for all policy statement builders
30
- - `All` - Global action provider for cross-service policies
31
- - Service-specific classes (e.g., `S3`, `EC2`, `Lambda`) - Each AWS service gets its own class with methods for actions, resources, and conditions
35
+ - `iam-floyd` - Standalone (uses built-in base class)
36
+ - `cdk-iam-floyd` - Extends `aws_iam.PolicyStatement` from AWS CDK
37
+
38
+ `bin/mkcdk.ts` transforms between variants by swapping `*.CDK.ts` files and rewriting constructors.
32
39
 
33
40
  ## Development Commands
34
41
 
35
- ### Building and Compilation
42
+ ### Build
36
43
 
37
44
  ```bash
38
- # Build the project (compiles TypeScript)
39
- make build
40
- # Convert project to CDK-variant
45
+ make build # tsc --build --force tsconfig.main.json
46
+ make package # build + npm pack
47
+ make clean # remove node_modules, *.js, *.d.ts
48
+ make install # clean + npm i
41
49
  ```
42
50
 
43
51
  ### Code Generation
44
52
 
45
53
  ```bash
46
- # Generate service classes from AWS documentation
47
- make generate
48
- # Force regeneration (ignores time-based cache)
49
- make generate-force
50
- # Generate AWS managed policies index
51
- make index-managed-policies
54
+ make generate # generate lib/generated/ from AWS docs (25hr cache)
55
+ make generate-force # NOCACHE=1 - ignores time-based cache
56
+ make index-managed-policies # regenerate AWS managed policies index
52
57
  ```
53
58
 
54
59
  ### Testing
55
60
 
61
+ The project has **no unit test framework**. Tests are integration-style: TypeScript examples are compiled, run, and their output is diffed against stored `.result` files.
62
+
56
63
  ```bash
57
- # Run main tests
58
- make test
59
- # Run CDK-specific tests
60
- make cdk-test
61
- # Convert package to CDK variant and run CDK-specific tests
62
- make cdk-all
64
+ make test # compile examples/ + diff against *.result files (standalone)
65
+ make test-typescript # same, via Test.TypeScript.Makefile
66
+ make cdk-test # CDK test: real deploy + destroy via AWS CDK
67
+ make cdk-all # cdk + install + build + cdk-test
63
68
  ```
64
69
 
65
- ### Linting and Code Quality
70
+ **Run a single example test manually:**
66
71
 
67
72
  ```bash
68
- # Run ESLint
69
- make eslint
70
- # ESLint is configured with TypeScript, Prettier, and deprecation rules
73
+ # 1. Compile a single example
74
+ npx tsc -p tsconfig.test-iam-floyd.json
75
+
76
+ # 2. Run and compare output
77
+ node examples/allow/allow.js > /tmp/out.txt
78
+ diff /tmp/out.txt examples/allow/allow.result
79
+
80
+ # Or run the integration test harness directly:
81
+ npx ts-node test/main.ts
71
82
  ```
72
83
 
73
- ### Package Management
84
+ **Regenerate expected results** (after intentional changes):
74
85
 
75
86
  ```bash
76
- # Create npm package
77
- make package
78
- # Clean all generated files and dependencies
79
- make clean
80
- # Reinstall dependencies
81
- make install
87
+ make regenerate-code-example-results
82
88
  ```
83
89
 
84
- ### CDK Variant Management
90
+ ### Linting
85
91
 
86
92
  ```bash
87
- # Convert to CDK variant (modifies package.json and lib structure)
88
- make cdk
89
- # Revert CDK changes
90
- make uncdk
93
+ make eslint # npx eslint .
91
94
  ```
92
95
 
93
- ## Project Structure Patterns
96
+ ### CDK Variant
94
97
 
95
- ### Dual Package Strategy
98
+ ```bash
99
+ make cdk # transforms codebase to CDK variant (modifies lib/shared, lib/generated, package.json)
100
+ make uncdk # reverts via git stash (lib/generated, lib/shared, package.json)
101
+ ```
102
+
103
+ ## Fixing AWS Documentation Errors (`lib/generator/fixes.ts`)
104
+
105
+ The generator scrapes live AWS docs, which sometimes contain errors or inconsistencies. `fixes.ts` is the central place to patch these before code is generated. **When the generator produces wrong output, add a fix here rather than editing generated files.**
106
+
107
+ ### `fixes` object (keyed by URL slug)
96
108
 
97
- The project maintains two npm packages from a single codebase:
109
+ Each top-level key is the URL slug of a service's IAM docs page (e.g. `ec2`, `ssm`, `'neptune-db'`). Supported sub-keys:
98
110
 
99
- - `iam-floyd` - Standalone IAM policy generator
100
- - `cdk-iam-floyd` - AWS CDK integration that extends `iam.PolicyStatement`
111
+ | Sub-key | Effect |
112
+ | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113
+ | `ignore: true` | Skip generating this service entirely (used for EOL services) |
114
+ | `name: 'slug'` | Override the generated filename and class name (needed when the same service prefix spans multiple doc pages, e.g. `pinpointemailservice` → `ses-pinpoint`) |
115
+ | `service: 'prefix'` | Override the IAM service prefix used in the generated code |
116
+ | `resourceTypes.<name>.arn` | Replace the ARN template for a resource type with a corrected one |
117
+ | `conditions.<key>.key` | Rewrite the condition key string (used when docs have a concrete example key like `RequestTag/tag-key` instead of the parametric form `RequestTag/${TagKey}`) |
118
+ | `conditions.<key>.methodName` | Override the generated `ifXxx()` method name for a condition |
119
+ | `conditions.<key>.operator.type` | Override the inferred operator type (e.g. force `date` instead of `string`) |
120
+ | `conditions.<key>.operator.override` | Set `typeOverride` on the condition (used for custom operator generation) |
101
121
 
102
- The `bin/mkcdk.ts` script transforms the codebase between variants by modifying imports and package configuration.
122
+ ### Exported fixer functions
103
123
 
104
- ### TypeScript Configuration
124
+ - **`conditionFixer(service, condition)`** — Normalises condition types (`ArrayOfString` → `string`, `long` → `numeric`, etc.) and applies any key/operator overrides from `fixes`. Logs yellow `[L1/L2 fix …]` messages to stdout.
125
+ - **`conditionKeyFixer(service, key)`** — Rewrites a raw condition key string using any `conditions.<key>.key` override defined in `fixes`.
126
+ - **`arnFixer(service, resource, arn)`** — Applies a cascade of ARN normalisation rules:
127
+ 1. Uppercases the first letter of every `${placeholder}` (L1)
128
+ 2. Replaces trailing `*` wildcards with `${ResourceName}` (L2)
129
+ 3. Deduplicates repeated placeholder names by appending a counter (L2, Rekognition workaround)
130
+ 4. Applies the hard-coded ARN override from `fixes` if present (L3)
131
+ After fixing, validates the result against the canonical ARN regex and warns if it doesn't match (with a known-good exception list).
132
+ - **`serviceFixer(service)`** — Rewrites the IAM service prefix if a `service` override is defined in `fixes`.
105
133
 
106
- - `tsconfig.json` - Main TypeScript configuration with strict settings
107
- - `tsconfig.main.json` - Production build configuration
108
- - `tsconfig.test-*.json` - Test-specific configurations
109
- - Uses SWC for faster compilation via ts-node
134
+ ### How to add a fix
110
135
 
111
- ### Generated Code Conventions
136
+ 1. Find the service's URL slug from its IAM docs URL (e.g. `https://…/list_amazons3.html` → slug is `s3`).
137
+ 2. Add an entry to the `fixes` object in `lib/generator/fixes.ts`.
138
+ 3. Run `make generate-force` to regenerate with the fix applied.
112
139
 
113
- - All generated classes follow the pattern: `export class ServiceName extends PolicyStatement`
114
- - Method names correspond to AWS IAM action names (e.g., `getObject()`, `listBuckets()`)
115
- - Resource and condition methods use fluent interface patterns
116
- - Generated files include comprehensive JSDoc comments from AWS documentation
140
+ ## File Modification Rules
117
141
 
118
- ## Important Notes
142
+ **CRITICAL: Never manually edit files in `lib/generated/`.**
143
+ They are auto-generated from AWS documentation and will be overwritten on next `make generate`.
119
144
 
120
- ### File Modification Rules
145
+ Allowed manual edits:
121
146
 
122
- - **Never manually edit files in `lib/generated/`** - These are auto-generated and will be overwritten
123
- - Generated code is created from AWS documentation and should only be updated via the generation process
124
- - Manual changes should only be made to files in `lib/shared/`, `lib/collection/`, and core infrastructure
147
+ - `lib/shared/` - Core shared classes
148
+ - `lib/collection/` - Predefined collections
149
+ - `lib/generator/` - Generation logic and fixes
150
+ - `bin/` - CLI scripts
151
+ - `test/` - Integration test scripts
152
+ - `examples/` - Example files and their `.result` counterparts
125
153
 
126
- ### Code Style
154
+ ## Code Style
127
155
 
128
- - ESLint enforces strict TypeScript rules with Prettier formatting
129
- - Single quotes for strings, except in YAML files
130
- - Comprehensive type checking with `noImplicitAny` and strict null checks
131
- - Generated files are excluded from linting (`lib/generated/*` in `.eslintrc`)
156
+ ### Formatting (Prettier + ESLint)
132
157
 
133
- ### Testing Strategy
158
+ - **Indentation**: 2 spaces (tabs only in Makefiles)
159
+ - **Quotes**: Single quotes in TypeScript/JS; double quotes in YAML/JSON
160
+ - **Trailing newline**: Required on all files
161
+ - **No trailing whitespace**
162
+ - Line endings: LF (`\n`)
134
163
 
135
- - Tests are located in the `test/` directory with its own Makefile
136
- - Supports both unit tests for the main package and CDK integration tests
137
- - CDK tests include actual deployment and destruction cycles for validation
164
+ Run `make eslint` to check; Prettier is enforced via `eslint-plugin-prettier`.
165
+
166
+ ### TypeScript
167
+
168
+ Strict settings enforced in `tsconfig.json`:
169
+
170
+ ```
171
+ strict: true
172
+ noImplicitAny: true
173
+ strictNullChecks: true
174
+ strictPropertyInitialization: true
175
+ noUnusedLocals: true
176
+ noUnusedParameters: true
177
+ noImplicitReturns: true
178
+ target: ES2020, module: CommonJS
179
+ ```
180
+
181
+ - **No `any`**: Prefer explicit types or generics.
182
+ - **Unused vars**: Prefix with `_` to suppress (`argsIgnorePattern: ^_`).
183
+ - **Naming conventions**: Enforced via `@typescript-eslint/naming-convention`. Use `camelCase` for variables/functions, `PascalCase` for classes/interfaces.
184
+ - **Template literals**: Prefer `` `${x}` `` over `'a' + x` (`prefer-template: error`).
185
+ - **Deprecated APIs**: `deprecation/deprecation` rule is set to `error` — do not use deprecated APIs.
186
+ - **No `require()`**: Use ES `import`/`export`.
187
+
188
+ ### Imports
189
+
190
+ - Use named imports where possible: `import { Foo } from './foo'`
191
+ - Relative imports within `lib/`; absolute for `node_modules`
192
+ - `lib/generated/` is excluded from ESLint entirely
193
+
194
+ ### Fluent Interface Pattern
195
+
196
+ All service classes return `this` to allow chaining:
197
+
198
+ ```typescript
199
+ new Statement.S3()
200
+ .allow()
201
+ .toGetObject()
202
+ .on('arn:aws:s3:::my-bucket/*')
203
+ .ifAwsSourceVpc('vpc-123');
204
+ ```
205
+
206
+ ### JSDoc
207
+
208
+ - All public methods in generated files have JSDoc with Access Level, conditions, resources, and an AWS docs URL
209
+ - In `lib/shared/`, document non-obvious public methods and parameters
210
+
211
+ ## Generated Code Conventions
212
+
213
+ - `export class ServiceName extends PolicyStatement`
214
+ - Action methods: `toXxx()` — e.g., `toGetObject()`, `toListBuckets()`
215
+ - Resource methods: `onXxx()` — e.g., `onBucket()`, `onObject()`
216
+ - Condition methods: `ifXxx()` — e.g., `ifAwsSourceIp()`, `ifS3Prefix()`
217
+ - All methods return `this` for chaining
218
+
219
+ ## TypeScript Compilation
220
+
221
+ - `tsconfig.json` - Dev/generation (includes all files, uses SWC via `ts-node`)
222
+ - `tsconfig.main.json` - Production build (excludes `bin/`, `lib/generator/`, `test/`, CDK files)
223
+ - `tsconfig.test-iam-floyd.json` - Compiles `examples/` excluding `.cdk.ts`
224
+ - `tsconfig.test-cdk-iam-floyd.json` - Compiles `examples/**/*.cdk.ts`
225
+
226
+ SWC is used for faster transpilation: `"ts-node": { "swc": true }` in `tsconfig.json`.
138
227
 
139
228
  ## Git Commit Conventions
140
229
 
141
- This project follows conventional commit patterns:
230
+ Follow conventional commits:
142
231
 
143
- - `chore(deps): description` - Dependency updates
144
232
  - `feat: description` - New features
145
233
  - `fix: description` - Bug fixes
234
+ - `chore(deps): description` - Dependency updates
146
235
  - `docs: description` - Documentation changes
147
- - Simple format: "Updates AWS managed policies" for automated policy updates
236
+ - `refactor: description` - Code refactoring
237
+ - Simple prose for automated updates: `"Updates AWS managed policies"`
238
+
239
+ **Never commit directly to `main`**. Use a feature branch. Commits may fail spell-checking; add missing words with `dict-add <word>`.
240
+
241
+ ## CI Workflows (`.github/workflows/`)
242
+
243
+ - `generate.yml` - Daily: scrapes AWS docs, bumps patch version, opens PR with `automerge` label
244
+ - `index-managed-policies.yml` - Daily: updates managed policies, opens PR with `automerge` label
245
+ - `test-and-publish.yml` - On PR/push to main: `make install test-typescript` + CDK deploy test + npm publish
246
+ - `automerge.yml` - Auto-merges PRs labeled `automerge` after tests pass
247
+ - `test-docs.yml` - Builds Sphinx docs on `docs/**` changes
package/README.md CHANGED
@@ -16,9 +16,9 @@
16
16
  Support for:
17
17
 
18
18
  - 445 Services
19
- - 20440 Actions
20
- - 2169 Resource Types
21
- - 2291 Condition keys
19
+ - 20450 Actions
20
+ - 2170 Resource Types
21
+ - 2298 Condition keys
22
22
  <!-- /stats -->
23
23
 
24
24
  ![EXPERIMENTAL](https://img.shields.io/badge/stability-experimantal-orange?style=for-the-badge)**<br>This is an early version of the package. The API will change while I implement new features. Therefore make sure you use an exact version in your `package.json` before it reaches 1.0.0.**
@@ -1604,6 +1604,14 @@ export declare class AwsManagedPolicy extends AwsManagedPolicyStatic {
1604
1604
  AWSElasticLoadBalancingClassicServiceRolePolicy(): aws_iam.IManagedPolicy;
1605
1605
  /** Service Linked Role Policy for AWS Elastic Load Balancing Control Plane */
1606
1606
  AWSElasticLoadBalancingServiceRolePolicy(): aws_iam.IManagedPolicy;
1607
+ /** Provides full access to create MediaConnect Gateway Bridges and all its associated sub-resources. */
1608
+ AWSElementalMediaConnectCreateBridge(): aws_iam.IManagedPolicy;
1609
+ /** Provides full access to create MediaConnect Flows and all its associated sub-resources. */
1610
+ AWSElementalMediaConnectCreateFlow(): aws_iam.IManagedPolicy;
1611
+ /** Provides full access to delete MediaConnect Gateway Bridges and all its associated sub-resources. */
1612
+ AWSElementalMediaConnectDeleteBridge(): aws_iam.IManagedPolicy;
1613
+ /** Provides full access to delete MediaConnect Flows and all its associated sub-resources. */
1614
+ AWSElementalMediaConnectDeleteFlow(): aws_iam.IManagedPolicy;
1607
1615
  /** Provides full access to AWS Elemental MediaConnect resources. */
1608
1616
  AWSElementalMediaConnectFullAccess(): aws_iam.IManagedPolicy;
1609
1617
  /** Provides read-only access to AWS Elemental MediaConnect resources. */
@@ -2024,6 +2032,12 @@ export declare class AwsManagedPolicy extends AwsManagedPolicyStatic {
2024
2032
  AWSPartnerCentralSellingResourceSnapshotJobExecutionRolePolicy(): aws_iam.IManagedPolicy;
2025
2033
  /** This policy can be used to grant read-only access to APIs that can read service metadata for services in your AWS account. You can use this policy to provide your partners in the Partner-Led Support Program with access to the services specified in the permissions details section below. */
2026
2034
  AWSPartnerLedSupportReadOnlyAccess(): aws_iam.IManagedPolicy;
2035
+ /** Provides full access to ProServe tools. */
2036
+ AWSPartnerProServeToolsFullAccess(): aws_iam.IManagedPolicy;
2037
+ /** Provides access to create and manage own assessments in ProServe tools. */
2038
+ AWSPartnerProServeToolsIndividualContributor(): aws_iam.IManagedPolicy;
2039
+ /** Provides read access to organizational assessments with ability to manage own assessments. */
2040
+ AWSPartnerProServeToolsOrganizationReaderIndividualContributor(): aws_iam.IManagedPolicy;
2027
2041
  /** Grants permission to AWS PCS compute nodes to connect to AWS PCS clusters. */
2028
2042
  AWSPCSComputeNodePolicy(): aws_iam.IManagedPolicy;
2029
2043
  /** Grants permissions to PCS to manage resources on your behalf. */