serverless-plugin-module-registry 1.0.9-alpha.0 → 1.0.10-alpha.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 CHANGED
@@ -540,6 +540,74 @@ Look for `[module-registry]` prefixed logs for plugin-specific information.
540
540
  - Policy ARNs resolved at deployment time
541
541
  - No runtime AWS API calls for policy management
542
542
 
543
+ ## 🔐 Tenant Role Creation
544
+
545
+ The module registry provides a utility function to create IAM roles for tenant onboarding with ABAC (Attribute-Based Access Control) tags.
546
+
547
+ ### Usage
548
+
549
+ ```typescript
550
+ import { createTenantRoles } from 'serverless-plugin-module-registry/tenant'
551
+
552
+ // During tenant onboarding
553
+ const roleArns = await createTenantRoles({
554
+ tenantId: 'acme',
555
+ identityPoolId: 'us-east-1:12345678-1234-1234-1234-123456789012',
556
+ modules: ['sign', 'workforce'], // Optional: filter to specific modules
557
+ config: {
558
+ tableName: 'ModuleRegistry',
559
+ region: 'us-east-1',
560
+ policyPrefix: 'api'
561
+ },
562
+ logger: {
563
+ info: (msg, data) => console.log(msg, data),
564
+ warning: (msg, data) => console.warn(msg, data),
565
+ error: (msg, err) => console.error(msg, err)
566
+ }
567
+ })
568
+
569
+ console.log(roleArns)
570
+ // {
571
+ // authenticated: "arn:aws:iam::123456789012:role/api-acme-authenticated",
572
+ // unauthenticated: "arn:aws:iam::123456789012:role/api-acme-unauthenticated"
573
+ // }
574
+ ```
575
+
576
+ ### What It Does
577
+
578
+ 1. **Discovers Roles**: Queries DynamoDB to find all role types (authenticated, unauthenticated, admin, etc.)
579
+ 2. **Collects Features**: For each role, gathers all module features and builds ABAC tags
580
+ 3. **Creates IAM Roles**: Creates roles with proper Cognito trust policies and ABAC tags
581
+ 4. **Attaches Policies**: Attaches module ManagedPolicies to roles
582
+ 5. **Registers with Cognito**: Attaches roles to the Cognito Identity Pool
583
+
584
+ ### Role Naming Convention
585
+
586
+ Roles follow the pattern: `{policyPrefix}-{tenantId}-{roleType}`
587
+
588
+ Examples:
589
+ - `api-acme-authenticated`
590
+ - `api-acme-unauthenticated`
591
+ - `api-acme-admin`
592
+
593
+ ### ABAC Tags
594
+
595
+ Each role is tagged with module features in the format:
596
+ ```
597
+ {moduleName}Features: "feature1:feature2:feature3"
598
+ ```
599
+
600
+ Example tags:
601
+ - `signFeatures`: `"7tmARMbS:BRUBT2SN:F8d3wY_v"`
602
+ - `workforceFeatures`: `"abc123:def456:ghi789"`
603
+
604
+ ### Idempotency
605
+
606
+ The function is idempotent - it can be called multiple times safely:
607
+ - Existing roles are updated with new tags and policies
608
+ - No duplicate roles are created
609
+ - Cognito attachment is updated if needed
610
+
543
611
  ## 🔒 Security Considerations
544
612
 
545
613
  ### IAM Policies
@@ -547,6 +615,7 @@ Look for `[module-registry]` prefixed logs for plugin-specific information.
547
615
  - Generated policies follow **least privilege** principle
548
616
  - Endpoint-specific resource ARNs (not wildcards)
549
617
  - Custom policies allow fine-grained permission control
618
+ - Tenant roles use Cognito Identity Pool trust policies
550
619
 
551
620
  ### Access Control
552
621
 
package/dist/index.d.ts CHANGED
@@ -155,7 +155,9 @@ declare function generateAbacTags(
155
155
  declare function getRequiredModulePolicyArns(
156
156
  selectedFeatures: SelectedFeature[],
157
157
  accountId: string,
158
- policyPrefix: string
158
+ service: string,
159
+ stage: string,
160
+ region: string
159
161
  ): Promise<string[]>
160
162
 
161
163
  /**
@@ -171,9 +173,9 @@ declare function createModuleRegistryLogger(context: string): {
171
173
  * AI-powered Registry Generation
172
174
  */
173
175
  interface Logger {
174
- info: (message: string) => void;
175
- warning: (message: string) => void;
176
- error: (message: string) => void;
176
+ info: (_message: string) => void;
177
+ warning: (_message: string) => void;
178
+ error: (_message: string) => void;
177
179
  }
178
180
  interface FunctionAnalysis {
179
181
  handler: string;
@@ -252,6 +254,43 @@ declare class AIRegistryGenerator {
252
254
  private cleanFeatureKey;
253
255
  }
254
256
 
257
+ /**
258
+ * Type definitions for Tenant Role Creation
259
+ */
260
+ interface RoleSpec {
261
+ roleName: string;
262
+ tags: Record<string, string>;
263
+ policyArns: string[];
264
+ }
265
+ interface CreateTenantRolesParams {
266
+ tenantId: string;
267
+ identityPoolId: string;
268
+ modules?: string[];
269
+ config: {
270
+ tableName: string;
271
+ region: string;
272
+ policyPrefix: string;
273
+ };
274
+ logger: {
275
+ info: (_message: string, _data?: any) => void;
276
+ warning: (_message: string, _data?: any) => void;
277
+ error: (_message: string, _error?: any) => void;
278
+ };
279
+ }
280
+ interface TenantRoleArns {
281
+ [roleName: string]: string;
282
+ }
283
+
284
+ /**
285
+ * Tenant Role Creator
286
+ * Creates IAM roles with ABAC tags and Cognito Identity Pool registration
287
+ */
288
+
289
+ /**
290
+ * Main function to create tenant IAM roles with ABAC tags
291
+ */
292
+ declare function createTenantRoles(params: CreateTenantRolesParams): Promise<TenantRoleArns>;
293
+
255
294
  /**
256
295
  * Serverless Module Registry Plugin
257
296
  * -------------------------------------------
@@ -413,6 +452,11 @@ declare class ServerlessModuleRegistryPlugin {
413
452
  * Ensure DynamoDB table exists using AWS SDK v3, then update registry data
414
453
  */
415
454
  private ensureTableAndUpdateData;
455
+ /**
456
+ * Deploy internal infrastructure (DynamoDB table, Streams, SQS, Lambda processors)
457
+ * Runs BEFORE main deployment to ensure table exists
458
+ */
459
+ private deployInternalInfrastructure;
416
460
  /**
417
461
  * Handler for the registryGenerate command
418
462
  */
@@ -423,4 +467,4 @@ declare class ServerlessModuleRegistryPlugin {
423
467
  private generateServicePackageCommand;
424
468
  }
425
469
 
426
- export { AIRegistryGenerator, ServerlessModuleRegistryPlugin, createCustomFeature, createModuleRegistryLogger, ServerlessModuleRegistryPlugin as default, generateAbacTags, generateAllModuleAbacPolicies, generateModuleAbacPolicy, getAllEndpoints, getFeatureById, getFeatureDetails, getModuleFeatures, getModuleMetadata, getNonCustomEndpoints, getRequiredModulePolicyArns, listAllModules };
470
+ export { AIRegistryGenerator, type CreateTenantRolesParams, type RoleSpec, ServerlessModuleRegistryPlugin, type TenantRoleArns, createCustomFeature, createModuleRegistryLogger, createTenantRoles, ServerlessModuleRegistryPlugin as default, generateAbacTags, generateAllModuleAbacPolicies, generateModuleAbacPolicy, getAllEndpoints, getFeatureById, getFeatureDetails, getModuleFeatures, getModuleMetadata, getNonCustomEndpoints, getRequiredModulePolicyArns, listAllModules };