Skip to content

Commit 83fa470

Browse files
authored
feat: add tenant id (#6)
1 parent d20855f commit 83fa470

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

.changeset/lovely-rats-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws/lambda-invoke-store": minor
3+
---
4+
5+
Add support for tenantId

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,7 @@ dist
109109
!.yarn/plugins
110110
!.yarn/releases
111111
!.yarn/sdks
112-
!.yarn/versions
112+
!.yarn/versions
113+
114+
# Yarn is preferred in this package
115+
package-lock.json

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ Convenience method to get the current request ID.
9999
const requestId = InvokeStore.getRequestId(); // Returns '-' if outside context
100100
```
101101

102+
### InvokeStore.getTenantId()
103+
104+
Convenience method to get the tenant ID.
105+
106+
```typescript
107+
const requestId = InvokeStore.getTenantId();
108+
```
109+
102110
### InvokeStore.getXRayTraceId()
103111

104112
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.

src/invoke-store.global.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ describe("InvokeStore Global Singleton", () => {
7575
it("should maintain singleton behavior with dynamic imports", async () => {
7676
// GIVEN
7777
const testRequestId = "dynamic-import-test";
78+
const testTenantId = "dynamic-import-tenant-id-test";
7879
const testKey = "dynamic-key";
7980
const testValue = "dynamic-value";
8081

8182
// WHEN - Set up context with original import
8283
await OriginalImport.run(
83-
{ [OriginalImport.PROTECTED_KEYS.REQUEST_ID]: testRequestId },
84+
{
85+
[OriginalImport.PROTECTED_KEYS.REQUEST_ID]: testRequestId,
86+
[OriginalImport.PROTECTED_KEYS.TENANT_ID]: testTenantId,
87+
},
8488
async () => {
8589
OriginalImport.set(testKey, testValue);
8690

@@ -91,6 +95,7 @@ describe("InvokeStore Global Singleton", () => {
9195
// THEN - Dynamically imported instance should see the same context
9296
expect(DynamicImport).toBe(OriginalImport); // Same instance
9397
expect(DynamicImport.getRequestId()).toBe(testRequestId);
98+
expect(DynamicImport.getTenantId()).toBe(testTenantId);
9499
expect(DynamicImport.get(testKey)).toBe(testValue);
95100

96101
// WHEN - Set a new value using dynamic import
@@ -132,6 +137,7 @@ describe("InvokeStore Existing Instance", () => {
132137
set: vi.fn(),
133138
getRequestId: vi.fn().mockReturnValue("mock-request-id"),
134139
getXRayTraceId: vi.fn(),
140+
getTenantId: vi.fn().mockReturnValue("my-test-tenant-id"),
135141
hasContext: vi.fn(),
136142
};
137143

@@ -144,6 +150,7 @@ describe("InvokeStore Existing Instance", () => {
144150
// THEN
145151
expect(ReimportedStore).toBe(mockInstance);
146152
expect(ReimportedStore.getRequestId()).toBe("mock-request-id");
153+
expect(ReimportedStore.getTenantId()).toBe("my-test-tenant-id");
147154
});
148155
});
149156

src/invoke-store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if (!noGlobalAwsLambda) {
1212
const PROTECTED_KEYS = {
1313
REQUEST_ID: Symbol("_AWS_LAMBDA_REQUEST_ID"),
1414
X_RAY_TRACE_ID: Symbol("_AWS_LAMBDA_X_RAY_TRACE_ID"),
15+
TENANT_ID: Symbol("_AWS_LAMBDA_TENANT_ID"),
1516
} as const;
1617

1718
/**
@@ -85,6 +86,13 @@ class InvokeStoreImpl {
8586
return this.get<string>(this.PROTECTED_KEYS.X_RAY_TRACE_ID);
8687
}
8788

89+
/**
90+
* Get the current tenant ID
91+
*/
92+
public static getTenantId(): string | undefined {
93+
return this.get<string>(this.PROTECTED_KEYS.TENANT_ID);
94+
}
95+
8896
/**
8997
* Check if we're currently within an invoke context
9098
*/

0 commit comments

Comments
 (0)