From 59c4cbd0c6029d5e63194368c9e82d4eaef5e597 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Thu, 11 Sep 2025 16:35:54 +0000 Subject: [PATCH 1/3] feat: add tenant id --- .gitignore | 5 ++++- src/invoke-store.global.spec.ts | 9 ++++++++- src/invoke-store.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f9087d7..6a9c39a 100644 --- a/.gitignore +++ b/.gitignore @@ -109,4 +109,7 @@ dist !.yarn/plugins !.yarn/releases !.yarn/sdks -!.yarn/versions \ No newline at end of file +!.yarn/versions + +# Yarn is preferred in this package +package-lock.json \ No newline at end of file diff --git a/src/invoke-store.global.spec.ts b/src/invoke-store.global.spec.ts index d2a2f8e..251351f 100644 --- a/src/invoke-store.global.spec.ts +++ b/src/invoke-store.global.spec.ts @@ -75,12 +75,16 @@ describe("InvokeStore Global Singleton", () => { it("should maintain singleton behavior with dynamic imports", async () => { // GIVEN const testRequestId = "dynamic-import-test"; + const testTenantId = "dynamic-import-tenant-id-test"; const testKey = "dynamic-key"; const testValue = "dynamic-value"; // WHEN - Set up context with original import await OriginalImport.run( - { [OriginalImport.PROTECTED_KEYS.REQUEST_ID]: testRequestId }, + { + [OriginalImport.PROTECTED_KEYS.REQUEST_ID]: testRequestId, + [OriginalImport.PROTECTED_KEYS.TENANT_ID]: testTenantId, + }, async () => { OriginalImport.set(testKey, testValue); @@ -91,6 +95,7 @@ describe("InvokeStore Global Singleton", () => { // THEN - Dynamically imported instance should see the same context expect(DynamicImport).toBe(OriginalImport); // Same instance expect(DynamicImport.getRequestId()).toBe(testRequestId); + expect(DynamicImport.getTenantId()).toBe(testTenantId); expect(DynamicImport.get(testKey)).toBe(testValue); // WHEN - Set a new value using dynamic import @@ -132,6 +137,7 @@ describe("InvokeStore Existing Instance", () => { set: vi.fn(), getRequestId: vi.fn().mockReturnValue("mock-request-id"), getXRayTraceId: vi.fn(), + getTenantId: vi.fn().mockReturnValue("my-test-tenant-id"), hasContext: vi.fn(), }; @@ -144,6 +150,7 @@ describe("InvokeStore Existing Instance", () => { // THEN expect(ReimportedStore).toBe(mockInstance); expect(ReimportedStore.getRequestId()).toBe("mock-request-id"); + expect(ReimportedStore.getTenantId()).toBe("my-test-tenant-id"); }); }); diff --git a/src/invoke-store.ts b/src/invoke-store.ts index 3f681aa..9cda776 100644 --- a/src/invoke-store.ts +++ b/src/invoke-store.ts @@ -12,6 +12,7 @@ if (!noGlobalAwsLambda) { const PROTECTED_KEYS = { REQUEST_ID: Symbol("_AWS_LAMBDA_REQUEST_ID"), X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID"), + TENANT_ID: Symbol("_AWS_LAMBDA_TENANT_ID"), } as const; /** @@ -85,6 +86,13 @@ class InvokeStoreImpl { return this.get(this.PROTECTED_KEYS.X_RAY_TRACE_ID); } + /** + * Get the current tenant ID + */ + public static getTenantId(): string | undefined { + return this.get(this.PROTECTED_KEYS.TENANT_ID); + } + /** * Check if we're currently within an invoke context */ From 58f4e40e179c44db7314d910ce4093e8dc817d60 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Thu, 11 Sep 2025 16:58:49 +0000 Subject: [PATCH 2/3] fix: add changeset --- .changeset/lovely-rats-throw.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-rats-throw.md diff --git a/.changeset/lovely-rats-throw.md b/.changeset/lovely-rats-throw.md new file mode 100644 index 0000000..90c6052 --- /dev/null +++ b/.changeset/lovely-rats-throw.md @@ -0,0 +1,5 @@ +--- +"@aws/lambda-invoke-store": minor +--- + +Add support for tenantId From c0029caf43444aa26a669be3ad2d7fd608657a88 Mon Sep 17 00:00:00 2001 From: Maxime David Date: Thu, 11 Sep 2025 17:00:59 +0000 Subject: [PATCH 3/3] fix: update readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 4b0ee31..47f15e7 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,14 @@ Convenience method to get the current request ID. const requestId = InvokeStore.getRequestId(); // Returns '-' if outside context ``` +### InvokeStore.getTenantId() + +Convenience method to get the tenant ID. + +```typescript +const requestId = InvokeStore.getTenantId(); +``` + ### InvokeStore.getXRayTraceId() Convenience method to get the current [X-Ray trace ID](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-traces). This ID is used for distributed tracing across AWS services.