@onlineapps/conn-orch-api-mapper 1.0.30 → 1.0.31
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/package.json +1 -1
- package/src/ApiMapper.js +23 -7
package/package.json
CHANGED
package/src/ApiMapper.js
CHANGED
|
@@ -686,7 +686,7 @@ class ApiMapper {
|
|
|
686
686
|
* @private
|
|
687
687
|
* @param {Object} operation - Operation definition
|
|
688
688
|
* @param {Object} input - Resolved input
|
|
689
|
-
* @param {Object} context - Workflow context (must include _system.tenant_id + _system.
|
|
689
|
+
* @param {Object} context - Workflow context (must include _system.tenant_id + _system.default_workspace_id)
|
|
690
690
|
* @returns {Object} Request object
|
|
691
691
|
*/
|
|
692
692
|
_buildRequest(operation, input, context = {}) {
|
|
@@ -760,25 +760,40 @@ class ApiMapper {
|
|
|
760
760
|
const sys = context && typeof context === 'object' ? context._system : null;
|
|
761
761
|
if (!sys) {
|
|
762
762
|
throw new Error(
|
|
763
|
-
'[ApiMapper][TenantContext] Missing _system context - Expected context._system with tenant_id
|
|
764
|
-
'Fix: Gateway must set _system.tenant_id
|
|
763
|
+
'[ApiMapper][TenantContext] Missing _system context - Expected context._system with tenant_id. ' +
|
|
764
|
+
'Fix: Gateway must set _system.tenant_id.'
|
|
765
765
|
);
|
|
766
766
|
}
|
|
767
767
|
|
|
768
|
-
if (sys.tenant_id === undefined
|
|
768
|
+
if (sys.tenant_id === undefined) {
|
|
769
769
|
throw new Error(
|
|
770
|
-
'[ApiMapper][TenantContext] Missing tenant context - Expected _system.tenant_id
|
|
770
|
+
'[ApiMapper][TenantContext] Missing tenant context - Expected _system.tenant_id'
|
|
771
771
|
);
|
|
772
772
|
}
|
|
773
773
|
|
|
774
774
|
const tenantId = Number.parseInt(String(sys.tenant_id), 10);
|
|
775
|
-
const workspaceId = Number.parseInt(String(sys.workspace_id), 10);
|
|
776
775
|
if (!Number.isInteger(tenantId) || tenantId <= 0) {
|
|
777
776
|
throw new Error(`[ApiMapper][TenantContext] Invalid tenant_id - Expected positive integer, got: ${sys.tenant_id}`);
|
|
778
777
|
}
|
|
778
|
+
|
|
779
|
+
// workspace_id: per-step override → cookbook default → error
|
|
780
|
+
// See: .cursor/rules/workspace-architecture.mdc
|
|
781
|
+
const stepDef = context._pointer?.currentStep || operation;
|
|
782
|
+
const rawStepWs = stepDef?.workspace_id;
|
|
783
|
+
const rawDefaultWs = sys.default_workspace_id;
|
|
784
|
+
const rawWorkspaceId = rawStepWs !== undefined && rawStepWs !== null ? rawStepWs : rawDefaultWs;
|
|
785
|
+
|
|
786
|
+
if (rawWorkspaceId === undefined || rawWorkspaceId === null) {
|
|
787
|
+
throw new Error(
|
|
788
|
+
'[ApiMapper][TenantContext] Missing workspace_id - set per-step workspace_id or cookbook defaults.workspace_id'
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
const workspaceId = Number.parseInt(String(rawWorkspaceId), 10);
|
|
779
793
|
if (!Number.isInteger(workspaceId) || workspaceId <= 0) {
|
|
780
|
-
throw new Error(`[ApiMapper][TenantContext] Invalid workspace_id - Expected positive integer, got: ${
|
|
794
|
+
throw new Error(`[ApiMapper][TenantContext] Invalid workspace_id - Expected positive integer, got: ${rawWorkspaceId}`);
|
|
781
795
|
}
|
|
796
|
+
|
|
782
797
|
const personId = sys.person_id !== undefined && sys.person_id !== null
|
|
783
798
|
? Number.parseInt(String(sys.person_id), 10)
|
|
784
799
|
: undefined;
|
|
@@ -786,6 +801,7 @@ class ApiMapper {
|
|
|
786
801
|
throw new Error(`[ApiMapper][TenantContext] Invalid person_id - Expected positive integer, got: ${sys.person_id}`);
|
|
787
802
|
}
|
|
788
803
|
|
|
804
|
+
// See: docs/standards/tenant-context-contract.md (§3 Data Flow)
|
|
789
805
|
request.headers['x-tenant-id'] = String(tenantId);
|
|
790
806
|
request.headers['x-workspace-id'] = String(workspaceId);
|
|
791
807
|
request.headers['x-person-id'] = String(personId);
|