@twin.org/api-tenant-processor 0.0.3-next.40 → 0.0.3-next.42

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.
@@ -35,12 +35,11 @@ export class TenantService {
35
35
  */
36
36
  async runPerTenant(method) {
37
37
  let cursor;
38
- const contextIds = (await ContextIdStore.getContextIds()) ?? {};
38
+ const baseContextIds = (await ContextIdStore.getContextIds()) ?? {};
39
39
  do {
40
40
  const result = await this._entityStorageConnector.query(undefined, undefined, ["id"], cursor);
41
41
  for (const tenant of result.entities) {
42
- contextIds[ContextIdKeys.Tenant] = tenant.id;
43
- await ContextIdStore.run(contextIds, async () => {
42
+ await ContextIdStore.run({ ...baseContextIds, [ContextIdKeys.Tenant]: tenant.id }, async () => {
44
43
  await method();
45
44
  });
46
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tenantService.js","sourceRoot":"","sources":["../../src/tenantService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAKzC;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;OAEG;IACI,MAAM,CAAU,UAAU,mBAAmC;IAEpE;;;OAGG;IACc,uBAAuB,CAAkC;IAE1E;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IAAI,CAAC,uBAAuB,GAAG,6BAA6B,CAAC,GAAG,CAC/D,OAAO,EAAE,uBAAuB,IAAI,QAAQ,CAC5C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,aAAa,CAAC,UAAU,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAA2B;QACpD,IAAI,MAA0B,CAAC;QAE/B,MAAM,UAAU,GAAG,CAAC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC;QAEhE,GAAG,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;YAE9F,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACtC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC;gBAE7C,MAAM,cAAc,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;oBAC/C,MAAM,MAAM,EAAE,CAAC;gBAChB,CAAC,CAAC,CAAC;YACJ,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACxB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAClC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { Tenant } from \"./entities/tenant.js\";\nimport type { ITenantAdminServiceConstructorOptions } from \"./models/ITenantAdminServiceConstructorOptions.js\";\n\n/**\n * Service for performing tenant administration operations.\n */\nexport class TenantService implements ITenantComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TenantService>();\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnector: IEntityStorageConnector<Tenant>;\n\n\t/**\n\t * Create a new instance of TenantService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITenantAdminServiceConstructorOptions) {\n\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.tenantEntityStorageType ?? \"tenant\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TenantService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Run a per tenant operation.\n\t * @param method The method to run for each tenant.\n\t * @returns Nothing.\n\t */\n\tpublic async runPerTenant(method: () => Promise<void>): Promise<void> {\n\t\tlet cursor: string | undefined;\n\n\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\n\t\tdo {\n\t\t\tconst result = await this._entityStorageConnector.query(undefined, undefined, [\"id\"], cursor);\n\n\t\t\tfor (const tenant of result.entities) {\n\t\t\t\tcontextIds[ContextIdKeys.Tenant] = tenant.id;\n\n\t\t\t\tawait ContextIdStore.run(contextIds, async () => {\n\t\t\t\t\tawait method();\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tcursor = result.cursor;\n\t\t} while (Is.stringValue(cursor));\n\t}\n}\n"]}
1
+ {"version":3,"file":"tenantService.js","sourceRoot":"","sources":["../../src/tenantService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACpC,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AAKzC;;GAEG;AACH,MAAM,OAAO,aAAa;IACzB;;OAEG;IACI,MAAM,CAAU,UAAU,mBAAmC;IAEpE;;;OAGG;IACc,uBAAuB,CAAkC;IAE1E;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IAAI,CAAC,uBAAuB,GAAG,6BAA6B,CAAC,GAAG,CAC/D,OAAO,EAAE,uBAAuB,IAAI,QAAQ,CAC5C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,aAAa,CAAC,UAAU,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAA2B;QACpD,IAAI,MAA0B,CAAC;QAE/B,MAAM,cAAc,GAAG,CAAC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC;QAEpE,GAAG,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;YAE9F,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACtC,MAAM,cAAc,CAAC,GAAG,CACvB,EAAE,GAAG,cAAc,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,EAAE,EACxD,KAAK,IAAI,EAAE;oBACV,MAAM,MAAM,EAAE,CAAC;gBAChB,CAAC,CACD,CAAC;YACH,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACxB,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE;IAClC,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Is } from \"@twin.org/core\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { Tenant } from \"./entities/tenant.js\";\nimport type { ITenantAdminServiceConstructorOptions } from \"./models/ITenantAdminServiceConstructorOptions.js\";\n\n/**\n * Service for performing tenant administration operations.\n */\nexport class TenantService implements ITenantComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TenantService>();\n\n\t/**\n\t * Entity storage connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _entityStorageConnector: IEntityStorageConnector<Tenant>;\n\n\t/**\n\t * Create a new instance of TenantService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITenantAdminServiceConstructorOptions) {\n\t\tthis._entityStorageConnector = EntityStorageConnectorFactory.get(\n\t\t\toptions?.tenantEntityStorageType ?? \"tenant\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TenantService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Run a per tenant operation.\n\t * @param method The method to run for each tenant.\n\t * @returns Nothing.\n\t */\n\tpublic async runPerTenant(method: () => Promise<void>): Promise<void> {\n\t\tlet cursor: string | undefined;\n\n\t\tconst baseContextIds = (await ContextIdStore.getContextIds()) ?? {};\n\n\t\tdo {\n\t\t\tconst result = await this._entityStorageConnector.query(undefined, undefined, [\"id\"], cursor);\n\n\t\t\tfor (const tenant of result.entities) {\n\t\t\t\tawait ContextIdStore.run(\n\t\t\t\t\t{ ...baseContextIds, [ContextIdKeys.Tenant]: tenant.id },\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tawait method();\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tcursor = result.cursor;\n\t\t} while (Is.stringValue(cursor));\n\t}\n}\n"]}
package/docs/changelog.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.3-next.42](https://github.com/iotaledger/twin-api/compare/api-tenant-processor-v0.0.3-next.41...api-tenant-processor-v0.0.3-next.42) (2026-06-08)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * prevent runPerTenant from mutating the active request context ([#152](https://github.com/iotaledger/twin-api/issues/152)) ([6e2c88c](https://github.com/iotaledger/twin-api/commit/6e2c88cfeba046ba71a218e62c90eafafaea2713))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/api-models bumped from 0.0.3-next.41 to 0.0.3-next.42
16
+
17
+ ## [0.0.3-next.41](https://github.com/iotaledger/twin-api/compare/api-tenant-processor-v0.0.3-next.40...api-tenant-processor-v0.0.3-next.41) (2026-06-05)
18
+
19
+
20
+ ### Miscellaneous Chores
21
+
22
+ * **api-tenant-processor:** Synchronize repo versions
23
+
24
+
25
+ ### Dependencies
26
+
27
+ * The following workspace dependencies were updated
28
+ * dependencies
29
+ * @twin.org/api-models bumped from 0.0.3-next.40 to 0.0.3-next.41
30
+
3
31
  ## [0.0.3-next.40](https://github.com/iotaledger/twin-api/compare/api-tenant-processor-v0.0.3-next.39...api-tenant-processor-v0.0.3-next.40) (2026-06-04)
4
32
 
5
33
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-tenant-processor",
3
- "version": "0.0.3-next.40",
3
+ "version": "0.0.3-next.42",
4
4
  "description": "Tenant resolution services and route handlers that derive tenant context from API keys.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "0.0.3-next.40",
17
+ "@twin.org/api-models": "0.0.3-next.42",
18
18
  "@twin.org/context": "next",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/entity": "next",