@memberjunction/core 6.2.0-edge.5 → 6.2.0-edge.7

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.
Files changed (148) hide show
  1. package/dist/generic/BaseEntitySaveQueue.d.ts +15 -0
  2. package/dist/generic/BaseEntitySaveQueue.d.ts.map +1 -1
  3. package/dist/generic/BaseEntitySaveQueue.js +21 -0
  4. package/dist/generic/BaseEntitySaveQueue.js.map +1 -1
  5. package/dist/generic/EntityFieldRules.d.ts.map +1 -1
  6. package/dist/generic/EntityFieldRules.js +1 -0
  7. package/dist/generic/EntityFieldRules.js.map +1 -1
  8. package/dist/generic/alternateBaseViews.d.ts +119 -0
  9. package/dist/generic/alternateBaseViews.d.ts.map +1 -0
  10. package/dist/generic/alternateBaseViews.js +223 -0
  11. package/dist/generic/alternateBaseViews.js.map +1 -0
  12. package/dist/generic/baseEngine.d.ts +171 -17
  13. package/dist/generic/baseEngine.d.ts.map +1 -1
  14. package/dist/generic/baseEngine.js +722 -117
  15. package/dist/generic/baseEngine.js.map +1 -1
  16. package/dist/generic/baseEngineRegistry.d.ts.map +1 -1
  17. package/dist/generic/baseEngineRegistry.js +2 -1
  18. package/dist/generic/baseEngineRegistry.js.map +1 -1
  19. package/dist/generic/baseEntity.d.ts +216 -21
  20. package/dist/generic/baseEntity.d.ts.map +1 -1
  21. package/dist/generic/baseEntity.js +969 -100
  22. package/dist/generic/baseEntity.js.map +1 -1
  23. package/dist/generic/baseRemotableOperation.d.ts +95 -6
  24. package/dist/generic/baseRemotableOperation.d.ts.map +1 -1
  25. package/dist/generic/baseRemotableOperation.js +112 -8
  26. package/dist/generic/baseRemotableOperation.js.map +1 -1
  27. package/dist/generic/contextTokens.d.ts +136 -0
  28. package/dist/generic/contextTokens.d.ts.map +1 -0
  29. package/dist/generic/contextTokens.js +319 -0
  30. package/dist/generic/contextTokens.js.map +1 -0
  31. package/dist/generic/databaseProviderBase.d.ts +103 -5
  32. package/dist/generic/databaseProviderBase.d.ts.map +1 -1
  33. package/dist/generic/databaseProviderBase.js +381 -52
  34. package/dist/generic/databaseProviderBase.js.map +1 -1
  35. package/dist/generic/embeddedRecord.d.ts +6 -0
  36. package/dist/generic/embeddedRecord.d.ts.map +1 -1
  37. package/dist/generic/embeddedRecord.js +15 -1
  38. package/dist/generic/embeddedRecord.js.map +1 -1
  39. package/dist/generic/entityCompanion.d.ts +7 -0
  40. package/dist/generic/entityCompanion.d.ts.map +1 -1
  41. package/dist/generic/entityCompanion.js +8 -0
  42. package/dist/generic/entityCompanion.js.map +1 -1
  43. package/dist/generic/entityInfo.d.ts +234 -9
  44. package/dist/generic/entityInfo.d.ts.map +1 -1
  45. package/dist/generic/entityInfo.js +592 -77
  46. package/dist/generic/entityInfo.js.map +1 -1
  47. package/dist/generic/entityValueFieldSecurity.d.ts +139 -0
  48. package/dist/generic/entityValueFieldSecurity.d.ts.map +1 -0
  49. package/dist/generic/entityValueFieldSecurity.js +250 -0
  50. package/dist/generic/entityValueFieldSecurity.js.map +1 -0
  51. package/dist/generic/externalDataSourceReadRouter.d.ts +10 -0
  52. package/dist/generic/externalDataSourceReadRouter.d.ts.map +1 -1
  53. package/dist/generic/externalDataSourceReadRouter.js +12 -0
  54. package/dist/generic/externalDataSourceReadRouter.js.map +1 -1
  55. package/dist/generic/fieldSecuritySQLGate.d.ts +359 -0
  56. package/dist/generic/fieldSecuritySQLGate.d.ts.map +1 -0
  57. package/dist/generic/fieldSecuritySQLGate.js +902 -0
  58. package/dist/generic/fieldSecuritySQLGate.js.map +1 -0
  59. package/dist/generic/indexRestrictedFields.d.ts +47 -0
  60. package/dist/generic/indexRestrictedFields.d.ts.map +1 -0
  61. package/dist/generic/indexRestrictedFields.js +129 -0
  62. package/dist/generic/indexRestrictedFields.js.map +1 -0
  63. package/dist/generic/interfaces.d.ts +64 -2
  64. package/dist/generic/interfaces.d.ts.map +1 -1
  65. package/dist/generic/interfaces.js.map +1 -1
  66. package/dist/generic/listMembershipFilter.d.ts +5 -0
  67. package/dist/generic/listMembershipFilter.d.ts.map +1 -0
  68. package/dist/generic/listMembershipFilter.js +23 -0
  69. package/dist/generic/listMembershipFilter.js.map +1 -0
  70. package/dist/generic/localCacheManager.d.ts +126 -14
  71. package/dist/generic/localCacheManager.d.ts.map +1 -1
  72. package/dist/generic/localCacheManager.js +348 -48
  73. package/dist/generic/localCacheManager.js.map +1 -1
  74. package/dist/generic/logging.d.ts.map +1 -1
  75. package/dist/generic/logging.js +7 -1
  76. package/dist/generic/logging.js.map +1 -1
  77. package/dist/generic/metadata.d.ts +3 -2
  78. package/dist/generic/metadata.d.ts.map +1 -1
  79. package/dist/generic/metadata.js +5 -2
  80. package/dist/generic/metadata.js.map +1 -1
  81. package/dist/generic/platformSQL.d.ts +54 -0
  82. package/dist/generic/platformSQL.d.ts.map +1 -1
  83. package/dist/generic/platformSQL.js +55 -0
  84. package/dist/generic/platformSQL.js.map +1 -1
  85. package/dist/generic/providerBase.d.ts +408 -57
  86. package/dist/generic/providerBase.d.ts.map +1 -1
  87. package/dist/generic/providerBase.js +1051 -310
  88. package/dist/generic/providerBase.js.map +1 -1
  89. package/dist/generic/queryInfo.d.ts +13 -0
  90. package/dist/generic/queryInfo.d.ts.map +1 -1
  91. package/dist/generic/queryInfo.js +13 -0
  92. package/dist/generic/queryInfo.js.map +1 -1
  93. package/dist/generic/queryInfoInterfaces.d.ts +8 -0
  94. package/dist/generic/queryInfoInterfaces.d.ts.map +1 -1
  95. package/dist/generic/queryTemplateContext.d.ts +49 -0
  96. package/dist/generic/queryTemplateContext.d.ts.map +1 -0
  97. package/dist/generic/queryTemplateContext.js +113 -0
  98. package/dist/generic/queryTemplateContext.js.map +1 -0
  99. package/dist/generic/recordChangeFieldSecurity.d.ts.map +1 -1
  100. package/dist/generic/recordChangeFieldSecurity.js +13 -2
  101. package/dist/generic/recordChangeFieldSecurity.js.map +1 -1
  102. package/dist/generic/relatedRecordCollection.d.ts +18 -0
  103. package/dist/generic/relatedRecordCollection.d.ts.map +1 -1
  104. package/dist/generic/relatedRecordCollection.js +55 -7
  105. package/dist/generic/relatedRecordCollection.js.map +1 -1
  106. package/dist/generic/remoteOperationDispatch.d.ts.map +1 -1
  107. package/dist/generic/remoteOperationDispatch.js +14 -2
  108. package/dist/generic/remoteOperationDispatch.js.map +1 -1
  109. package/dist/generic/runQuery.d.ts +42 -0
  110. package/dist/generic/runQuery.d.ts.map +1 -1
  111. package/dist/generic/runQuery.js +14 -0
  112. package/dist/generic/runQuery.js.map +1 -1
  113. package/dist/generic/runQuerySQLFilterImplementations.d.ts +33 -6
  114. package/dist/generic/runQuerySQLFilterImplementations.d.ts.map +1 -1
  115. package/dist/generic/runQuerySQLFilterImplementations.js +119 -29
  116. package/dist/generic/runQuerySQLFilterImplementations.js.map +1 -1
  117. package/dist/generic/saveEntityGraphOperation.d.ts.map +1 -1
  118. package/dist/generic/saveEntityGraphOperation.js +3 -0
  119. package/dist/generic/saveEntityGraphOperation.js.map +1 -1
  120. package/dist/generic/securityInfo.d.ts +11 -0
  121. package/dist/generic/securityInfo.d.ts.map +1 -1
  122. package/dist/generic/securityInfo.js +15 -0
  123. package/dist/generic/securityInfo.js.map +1 -1
  124. package/dist/generic/telemetryManager.d.ts +9 -0
  125. package/dist/generic/telemetryManager.d.ts.map +1 -1
  126. package/dist/generic/telemetryManager.js +5 -1
  127. package/dist/generic/telemetryManager.js.map +1 -1
  128. package/dist/generic/transportError.d.ts +41 -0
  129. package/dist/generic/transportError.d.ts.map +1 -0
  130. package/dist/generic/transportError.js +167 -0
  131. package/dist/generic/transportError.js.map +1 -0
  132. package/dist/generic/util.d.ts +12 -0
  133. package/dist/generic/util.d.ts.map +1 -1
  134. package/dist/generic/util.js +52 -3
  135. package/dist/generic/util.js.map +1 -1
  136. package/dist/index.d.ts +9 -0
  137. package/dist/index.d.ts.map +1 -1
  138. package/dist/index.js +9 -0
  139. package/dist/index.js.map +1 -1
  140. package/dist/views/runView.d.ts +102 -0
  141. package/dist/views/runView.d.ts.map +1 -1
  142. package/dist/views/runView.js +40 -0
  143. package/dist/views/runView.js.map +1 -1
  144. package/dist/views/viewProperties.d.ts +55 -0
  145. package/dist/views/viewProperties.d.ts.map +1 -0
  146. package/dist/views/viewProperties.js +258 -0
  147. package/dist/views/viewProperties.js.map +1 -0
  148. package/package.json +3 -3
@@ -1,9 +1,60 @@
1
1
  import { UserInfo } from "./securityInfo.js";
2
2
  import { IMetadataProvider, RemoteOpExecMode, RemoteOpInvokeOptions, RemoteOpProgress, RemoteOpResult } from "./interfaces.js";
3
+ /**
4
+ * Structured logical failure that a {@link BaseRemotableOperation.InternalExecute} or
5
+ * {@link BaseRemotableOperation.Authorize} implementation can throw to return a specific
6
+ * machine-readable {@link ResultCode} (instead of the generic `'EXECUTION_ERROR'`) without
7
+ * changing `InternalExecute`'s typed `TOutput` return signature.
8
+ */
9
+ export declare class RemoteOperationError extends Error {
10
+ /** Machine-readable outcome code surfaced on {@link RemoteOpResult.ResultCode}. */
11
+ readonly ResultCode: string;
12
+ constructor(resultCode: string, message: string);
13
+ }
14
+ /**
15
+ * Structural input/output contract fields used to compute a deterministic wire fingerprint for a
16
+ * Remote Operation (both at CodeGen emit time and at server runtime via `RemoteOperationEngineBase`).
17
+ */
18
+ export interface RemoteOperationContractSpec {
19
+ OperationKey: string;
20
+ ExecutionMode?: RemoteOpExecMode | string | null;
21
+ InputTypeName?: string | null;
22
+ InputTypeDefinition?: string | null;
23
+ InputTypeIsArray?: boolean | null;
24
+ OutputTypeName?: string | null;
25
+ OutputTypeDefinition?: string | null;
26
+ OutputTypeIsArray?: boolean | null;
27
+ }
28
+ /**
29
+ * Computes a deterministic, browser-safe 64-bit FNV-1a contract fingerprint (`ro_fp_<16-hex>`)
30
+ * from an operation's structural contract metadata. Whitespace runs inside type definitions are
31
+ * collapsed so CRLF vs LF formatting differences never trigger false mismatches.
32
+ */
33
+ export declare function ComputeRemoteOperationContractFingerprint(spec: RemoteOperationContractSpec): string;
34
+ /**
35
+ * JSON-Schema-compatible primitive/nested value type for opt-in Agent / MCP tool input schemas.
36
+ */
37
+ export type RemoteOpToolSchemaValue = string | number | boolean | null | RemoteOpToolSchemaValue[] | {
38
+ [key: string]: RemoteOpToolSchemaValue;
39
+ };
40
+ /**
41
+ * Descriptor returned by {@link BaseRemotableOperation.GetExposedToolOperations} for operations
42
+ * that opt into automatic AI Agent tool or MCP tool discovery.
43
+ */
44
+ export interface ExposedRemoteOperationToolDescriptor {
45
+ OperationKey: string;
46
+ ExposeAsAgentTool: boolean;
47
+ ExposeAsMCPTool: boolean;
48
+ Description?: string;
49
+ InputSchema?: Record<string, RemoteOpToolSchemaValue>;
50
+ RequiredScope?: string;
51
+ RequiresSystemUser?: boolean;
52
+ ExecutionMode: RemoteOpExecMode;
53
+ }
3
54
  /**
4
55
  * Server-side execution context handed to {@link BaseRemotableOperation.ExecuteServer} (and through
5
- * it to `InternalExecute`) when a Remote Operation runs in-process on the server. It carries
6
- * everything a server implementation needs without coupling the operation to any transport.
56
+ * it to `Authorize` and `InternalExecute`) when a Remote Operation runs in-process on the server.
57
+ * It carries everything a server implementation needs without coupling the operation to any transport.
7
58
  */
8
59
  export interface RemoteOpServerContext {
9
60
  /** The provider that owns this execution (use this for data access — never `new Metadata()`). */
@@ -14,6 +65,21 @@ export interface RemoteOpServerContext {
14
65
  emitProgress: (progress: RemoteOpProgress) => void;
15
66
  /** Opaque handle for the backing run (e.g. a `ProcessRunID`), when one has been created. */
16
67
  handle?: string;
68
+ /**
69
+ * Normalized HTTP `Origin` header (`scheme://host[:port]`, lowercased, no trailing slash)
70
+ * when the operation arrived over HTTP/GraphQL. Undefined for in-process calls or requests
71
+ * lacking an `Origin` header — origin allowlist checks must fail closed on `undefined`.
72
+ */
73
+ requestOrigin?: string;
74
+ /**
75
+ * Caller's network IP address (`req.ip`) when invoked over HTTP/GraphQL. Suitable for abuse
76
+ * rate-limiting and forensic audit logging; never use as an identity check.
77
+ */
78
+ clientIp?: string;
79
+ /** Caller's authenticated session ID when available from the server transport. */
80
+ sessionId?: string;
81
+ /** SHA-256 hash of the caller's MJ API key when invoked via `mj_sk_*` API key / MCP. */
82
+ apiKeyHash?: string;
17
83
  }
18
84
  /**
19
85
  * Base class for a **typed, provider-routed Remote Operation** — the typed peer of `BaseEntity`
@@ -49,6 +115,28 @@ export declare abstract class BaseRemotableOperation<TInput = unknown, TOutput =
49
115
  readonly RequiresSystemUser?: boolean;
50
116
  /** Whether this operation is a plain `Sync` request/response or a `LongRunning` run. */
51
117
  readonly ExecutionMode: RemoteOpExecMode;
118
+ /**
119
+ * Optional structural contract fingerprint emitted by CodeGen (or set by a hand-authored
120
+ * operation). Automatically forwarded on {@link Execute} when the caller didn't override
121
+ * `options.contractFingerprint`, allowing the server resolver to detect stale client bundles.
122
+ */
123
+ readonly ContractFingerprint?: string;
124
+ /** When true, exposes this operation for automatic discovery by MJ AI Agent tool adapters. */
125
+ readonly ExposeAsAgentTool?: boolean;
126
+ /** When true, exposes this operation for automatic discovery by MJ MCP server tool adapters. */
127
+ readonly ExposeAsMCPTool?: boolean;
128
+ /** Human/LLM-readable description when exposed as an Agent or MCP tool. */
129
+ readonly ToolDescription?: string;
130
+ /** Optional JSON-Schema object describing `TInput` when exposed as an Agent or MCP tool. */
131
+ readonly ToolInputSchema?: Record<string, RemoteOpToolSchemaValue>;
132
+ /**
133
+ * Discovers all ClassFactory-registered {@link BaseRemotableOperation} subclasses that opt into
134
+ * AI Agent (`ExposeAsAgentTool`) and/or MCP (`ExposeAsMCPTool`) tool exposure.
135
+ */
136
+ static GetExposedToolOperations(filter?: {
137
+ agentOnly?: boolean;
138
+ mcpOnly?: boolean;
139
+ }): ExposedRemoteOperationToolDescriptor[];
52
140
  /**
53
141
  * The universal entry point — identical on client and server. Routes the operation through the
54
142
  * active (or explicitly supplied) provider's {@link IRemoteOperationProvider.RouteOperation}.
@@ -65,7 +153,7 @@ export declare abstract class BaseRemotableOperation<TInput = unknown, TOutput =
65
153
  * and then {@link InternalExecute}, wrapping the outcome in a {@link RemoteOpResult}.
66
154
  *
67
155
  * @param input - The typed input payload.
68
- * @param context - The server execution context (provider, acting user, progress emitter).
156
+ * @param context - The server execution context (provider, acting user, progress emitter, HTTP metadata).
69
157
  * @returns The wrapped result; logical failures are returned, not thrown.
70
158
  */
71
159
  ExecuteServer(input: TInput, context: RemoteOpServerContext): Promise<RemoteOpResult<TOutput>>;
@@ -78,19 +166,20 @@ export declare abstract class BaseRemotableOperation<TInput = unknown, TOutput =
78
166
  * @param _input - The typed input payload.
79
167
  * @param _provider - The owning provider for data access.
80
168
  * @param _user - The acting user.
81
- * @param _context - The full server execution context (provider, user, progress emitter, handle).
169
+ * @param _context - The full server execution context (provider, user, progress emitter, handle, origin, IP).
82
170
  * @returns The typed output payload.
83
171
  */
84
172
  protected InternalExecute(_input: TInput, _provider: IMetadataProvider, _user: UserInfo, _context: RemoteOpServerContext): Promise<TOutput>;
85
173
  /**
86
174
  * Per-operation authorization hook, composed with (and applied after) the framework gates that
87
175
  * the server resolver runs. Returns true by default. Override to enforce operation-specific
88
- * rules against the input and acting user.
176
+ * rules against the input, acting user, and server transport context (e.g. `context.requestOrigin`).
89
177
  *
90
178
  * @param _input - The typed input payload.
91
179
  * @param _user - The acting user.
180
+ * @param _context - Optional server execution context (always supplied by {@link ExecuteServer}).
92
181
  * @returns True if the operation may proceed.
93
182
  */
94
- protected Authorize(_input: TInput, _user: UserInfo): Promise<boolean>;
183
+ protected Authorize(_input: TInput, _user: UserInfo, _context?: RemoteOpServerContext): Promise<boolean>;
95
184
  }
96
185
  //# sourceMappingURL=baseRemotableOperation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"baseRemotableOperation.d.ts","sourceRoot":"","sources":["../../src/generic/baseRemotableOperation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACH,iBAAiB,EAEjB,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,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AE,MAAM,CAAC;IAEzC,4FAA4F;IAC5F,SAAgB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;IAE1E;;;OAGG;WACW,wBAAwB,CAAC,MAAM,CAAC,EAAE;QAC5C,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,OAAO,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,oCAAoC,EAAE;IA+C1C;;;;;;;OAOG;IACU,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IA0B1G;;;;;;;;;OASG;IACU,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IA4B3G;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;IAO3I;;;;;;;;;OASG;cACa,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;CAGjH"}
@@ -1,4 +1,49 @@
1
+ import { MJGlobal } from "@memberjunction/global";
1
2
  import { Metadata } from "./metadata.js";
3
+ /**
4
+ * Structured logical failure that a {@link BaseRemotableOperation.InternalExecute} or
5
+ * {@link BaseRemotableOperation.Authorize} implementation can throw to return a specific
6
+ * machine-readable {@link ResultCode} (instead of the generic `'EXECUTION_ERROR'`) without
7
+ * changing `InternalExecute`'s typed `TOutput` return signature.
8
+ */
9
+ export class RemoteOperationError extends Error {
10
+ constructor(resultCode, message) {
11
+ super(message);
12
+ this.name = 'RemoteOperationError';
13
+ this.ResultCode = resultCode;
14
+ }
15
+ }
16
+ /**
17
+ * Computes a deterministic, browser-safe 64-bit FNV-1a contract fingerprint (`ro_fp_<16-hex>`)
18
+ * from an operation's structural contract metadata. Whitespace runs inside type definitions are
19
+ * collapsed so CRLF vs LF formatting differences never trigger false mismatches.
20
+ */
21
+ export function ComputeRemoteOperationContractFingerprint(spec) {
22
+ const collapseWs = (s) => (s ?? '').trim().replace(/\s+/g, ' ');
23
+ const canonical = [
24
+ (spec.OperationKey ?? '').trim(),
25
+ (spec.ExecutionMode ?? 'Sync').trim(),
26
+ (spec.InputTypeName ?? '').trim(),
27
+ spec.InputTypeIsArray ? '1' : '0',
28
+ collapseWs(spec.InputTypeDefinition),
29
+ (spec.OutputTypeName ?? '').trim(),
30
+ spec.OutputTypeIsArray ? '1' : '0',
31
+ collapseWs(spec.OutputTypeDefinition),
32
+ ].join('|');
33
+ // Dual 32-bit FNV-1a lanes combined into 16 hex digits (browser-safe, zero BigInt/crypto overhead).
34
+ let h1 = 0x811c9dc5;
35
+ let h2 = 0x01000193;
36
+ for (let i = 0; i < canonical.length; i++) {
37
+ const c = canonical.charCodeAt(i);
38
+ h1 ^= c;
39
+ h1 = Math.imul(h1, 0x01000193);
40
+ h2 ^= c ^ (i & 0xff);
41
+ h2 = Math.imul(h2, 0x811c9dc5);
42
+ }
43
+ const hex1 = (h1 >>> 0).toString(16).padStart(8, '0');
44
+ const hex2 = (h2 >>> 0).toString(16).padStart(8, '0');
45
+ return `ro_fp_${hex1}${hex2}`;
46
+ }
2
47
  /**
3
48
  * Base class for a **typed, provider-routed Remote Operation** — the typed peer of `BaseEntity`
4
49
  * (record CRUD) and `RunView` (set reads) for arbitrary server capabilities.
@@ -25,6 +70,50 @@ export class BaseRemotableOperation {
25
70
  /** Whether this operation is a plain `Sync` request/response or a `LongRunning` run. */
26
71
  this.ExecutionMode = 'Sync';
27
72
  }
73
+ /**
74
+ * Discovers all ClassFactory-registered {@link BaseRemotableOperation} subclasses that opt into
75
+ * AI Agent (`ExposeAsAgentTool`) and/or MCP (`ExposeAsMCPTool`) tool exposure.
76
+ */
77
+ static GetExposedToolOperations(filter) {
78
+ const registrations = MJGlobal.Instance.ClassFactory.GetAllRegistrations(BaseRemotableOperation);
79
+ const seenKeys = new Set();
80
+ const descriptors = [];
81
+ // Walk in reverse registration order so the highest-priority / latest subclass override wins per key.
82
+ for (let i = registrations.length - 1; i >= 0; i--) {
83
+ const reg = registrations[i];
84
+ const key = reg.Key;
85
+ if (!key || seenKeys.has(key)) {
86
+ continue;
87
+ }
88
+ seenKeys.add(key);
89
+ const instance = MJGlobal.Instance.ClassFactory.CreateInstance(BaseRemotableOperation, key);
90
+ if (!instance) {
91
+ continue;
92
+ }
93
+ const asAgent = instance.ExposeAsAgentTool === true;
94
+ const asMcp = instance.ExposeAsMCPTool === true;
95
+ if (!asAgent && !asMcp) {
96
+ continue;
97
+ }
98
+ if (filter?.agentOnly && !asAgent) {
99
+ continue;
100
+ }
101
+ if (filter?.mcpOnly && !asMcp) {
102
+ continue;
103
+ }
104
+ descriptors.push({
105
+ OperationKey: instance.OperationKey,
106
+ ExposeAsAgentTool: asAgent,
107
+ ExposeAsMCPTool: asMcp,
108
+ Description: instance.ToolDescription,
109
+ InputSchema: instance.ToolInputSchema,
110
+ RequiredScope: instance.RequiredScope,
111
+ RequiresSystemUser: instance.RequiresSystemUser,
112
+ ExecutionMode: instance.ExecutionMode,
113
+ });
114
+ }
115
+ return descriptors.sort((a, b) => (a.OperationKey < b.OperationKey ? -1 : a.OperationKey > b.OperationKey ? 1 : 0));
116
+ }
28
117
  /**
29
118
  * The universal entry point — identical on client and server. Routes the operation through the
30
119
  * active (or explicitly supplied) provider's {@link IRemoteOperationProvider.RouteOperation}.
@@ -35,12 +124,16 @@ export class BaseRemotableOperation {
35
124
  */
36
125
  async Execute(input, options = {}) {
37
126
  let provider;
127
+ let candidateProvider;
38
128
  try {
39
- provider = (options.provider ?? Metadata.Provider);
129
+ candidateProvider = options.provider ?? Metadata.Provider;
40
130
  }
41
131
  catch {
42
132
  // Metadata.Provider throws when no global provider has been configured — treat as "no provider".
43
- provider = undefined;
133
+ candidateProvider = undefined;
134
+ }
135
+ if (candidateProvider && 'RouteOperation' in candidateProvider) {
136
+ provider = candidateProvider;
44
137
  }
45
138
  if (!provider || typeof provider.RouteOperation !== 'function') {
46
139
  return {
@@ -49,7 +142,10 @@ export class BaseRemotableOperation {
49
142
  ErrorMessage: 'No remote-operation-capable provider is available to route this operation',
50
143
  };
51
144
  }
52
- return provider.RouteOperation(this.OperationKey, input, options);
145
+ const effectiveOptions = this.ContractFingerprint && options.contractFingerprint === undefined
146
+ ? { ...options, contractFingerprint: this.ContractFingerprint }
147
+ : options;
148
+ return provider.RouteOperation(this.OperationKey, input, effectiveOptions);
53
149
  }
54
150
  /**
55
151
  * Server-side execution entry point, invoked **in-process** by a server provider / resolver
@@ -58,12 +154,12 @@ export class BaseRemotableOperation {
58
154
  * and then {@link InternalExecute}, wrapping the outcome in a {@link RemoteOpResult}.
59
155
  *
60
156
  * @param input - The typed input payload.
61
- * @param context - The server execution context (provider, acting user, progress emitter).
157
+ * @param context - The server execution context (provider, acting user, progress emitter, HTTP metadata).
62
158
  * @returns The wrapped result; logical failures are returned, not thrown.
63
159
  */
64
160
  async ExecuteServer(input, context) {
65
161
  try {
66
- const authorized = await this.Authorize(input, context.user);
162
+ const authorized = await this.Authorize(input, context.user, context);
67
163
  if (!authorized) {
68
164
  return {
69
165
  Success: false,
@@ -75,6 +171,13 @@ export class BaseRemotableOperation {
75
171
  return { Success: true, ResultCode: 'SUCCESS', Output: output };
76
172
  }
77
173
  catch (e) {
174
+ if (e instanceof RemoteOperationError) {
175
+ return {
176
+ Success: false,
177
+ ResultCode: e.ResultCode,
178
+ ErrorMessage: e.message,
179
+ };
180
+ }
78
181
  return {
79
182
  Success: false,
80
183
  ResultCode: 'EXECUTION_ERROR',
@@ -91,7 +194,7 @@ export class BaseRemotableOperation {
91
194
  * @param _input - The typed input payload.
92
195
  * @param _provider - The owning provider for data access.
93
196
  * @param _user - The acting user.
94
- * @param _context - The full server execution context (provider, user, progress emitter, handle).
197
+ * @param _context - The full server execution context (provider, user, progress emitter, handle, origin, IP).
95
198
  * @returns The typed output payload.
96
199
  */
97
200
  InternalExecute(_input, _provider, _user, _context) {
@@ -101,13 +204,14 @@ export class BaseRemotableOperation {
101
204
  /**
102
205
  * Per-operation authorization hook, composed with (and applied after) the framework gates that
103
206
  * the server resolver runs. Returns true by default. Override to enforce operation-specific
104
- * rules against the input and acting user.
207
+ * rules against the input, acting user, and server transport context (e.g. `context.requestOrigin`).
105
208
  *
106
209
  * @param _input - The typed input payload.
107
210
  * @param _user - The acting user.
211
+ * @param _context - Optional server execution context (always supplied by {@link ExecuteServer}).
108
212
  * @returns True if the operation may proceed.
109
213
  */
110
- async Authorize(_input, _user) {
214
+ async Authorize(_input, _user, _context) {
111
215
  return true;
112
216
  }
113
217
  }
@@ -1 +1 @@
1
- {"version":3,"file":"baseRemotableOperation.js","sourceRoot":"","sources":["../../src/generic/baseRemotableOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA2BtC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAgB,sBAAsB;IAA5C;QAcI,wFAAwF;QACxE,kBAAa,GAAqB,MAAM,CAAC;IA0F7D,CAAC;IAxFG;;;;;;;OAOG;IACI,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,UAAiC,EAAE;QACnE,IAAI,QAA8C,CAAC;QACnD,IAAI,CAAC;YACD,QAAQ,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAoD,CAAC;QAC1G,CAAC;QAAC,MAAM,CAAC;YACL,iGAAiG;YACjG,QAAQ,GAAG,SAAS,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;YAC7D,OAAO;gBAC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8E,CACjF,CAAC;IACN,CAAC;IAED;;;;;;;;;OASG;IACO,KAAK,CAAC,SAAS,CAAC,MAAc,EAAE,KAAe,EAAE,QAAgC;QACvF,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Context tokens and property defaults.
3
+ *
4
+ * A property (a User View property, a dashboard property, a query's server-set variable) can
5
+ * default to a fixed value or to a context token: a name from a closed list, worked out from the
6
+ * context user and the clock alone. The same resolver runs in the browser and on the server, so
7
+ * the two can differ only in the time zone they are given.
8
+ *
9
+ * - User tokens (`Context.UserID`, `Context.UserEmail`, `Context.UserName`) need a context user;
10
+ * without one they throw rather than resolve to a blank.
11
+ * - **WARNING — SQL template escaping (`| sqlString`):** `Context.UserEmail` and `Context.UserName`
12
+ * resolve to raw, unescaped strings (for example `O'Brien`) and reach Nunjucks query templates with
13
+ * `autoescape: false`. Query templates **must** pipe them through `| sqlString`
14
+ * (e.g. `WHERE Email = {{ Context.UserEmail | sqlString }}` or
15
+ * `WHERE Name = {{ Context.UserName | sqlString }}`). Rendering `{{ Context.UserEmail }}` or
16
+ * `{{ Context.UserName }}` bare produces broken SQL on apostrophes and opens SQL injection.
17
+ * (User View properties are escaped automatically by `UserViewPropertyWhereClause`.)
18
+ * - Date tokens give a `YYYY-MM-DD` date in the given zone (`Context.Today`, `Context.StartOf*`),
19
+ * or an ISO 8601 instant (`Context.Now`). Only date tokens take an offset.
20
+ * - The zone is an IANA name, `'UTC'` when none is given. Weeks start on Monday (ISO 8601) unless
21
+ * the context says Sunday.
22
+ */
23
+ /** Every context token. The list is closed: an app's own context is a property value, never a token. */
24
+ export declare const CONTEXT_TOKENS: readonly ["Context.UserID", "Context.UserEmail", "Context.UserName", "Context.Now", "Context.Today", "Context.StartOfWeek", "Context.StartOfMonth", "Context.StartOfQuarter", "Context.StartOfYear"];
25
+ /** A context token: one of {@link CONTEXT_TOKENS}. */
26
+ export type ContextToken = typeof CONTEXT_TOKENS[number];
27
+ /**
28
+ * The version of what {@link CONTEXT_TOKENS} means. Approval fingerprints include it, so an approval
29
+ * given under one meaning is stale under another. Bump it whenever a token is added, removed or
30
+ * worked out differently (a new week start, a different date format, a different user field).
31
+ */
32
+ export declare const CONTEXT_TOKEN_CONTRACT_VERSION = 1;
33
+ /** The value types a property can declare. */
34
+ export declare const PROPERTY_VALUE_TYPES: readonly ["string", "number", "boolean", "date", "uuid"];
35
+ /** A property's value type: one of {@link PROPERTY_VALUE_TYPES}. */
36
+ export type PropertyValueType = typeof PROPERTY_VALUE_TYPES[number];
37
+ /** The units an offset can move a date token by. */
38
+ export declare const PROPERTY_OFFSET_UNITS: readonly ["day", "week", "month", "quarter", "year"];
39
+ /** An offset unit: one of {@link PROPERTY_OFFSET_UNITS}. */
40
+ export type PropertyOffsetUnit = typeof PROPERTY_OFFSET_UNITS[number];
41
+ /** Moves a date token: `{ Amount: -30, Unit: 'day' }` is thirty days earlier. */
42
+ export interface PropertyDefaultOffset {
43
+ /** A whole number; negative moves back. */
44
+ Amount: number;
45
+ Unit: PropertyOffsetUnit;
46
+ }
47
+ /** A property value, fixed or resolved. */
48
+ export type PropertyValue = string | number | boolean | null;
49
+ /**
50
+ * A property's default: a fixed value, or a token worked out when the value is used. Set exactly
51
+ * one of `Value` and `Token`. This is the shape the `MJ: User Views.Properties` JSON stores.
52
+ */
53
+ export interface PropertyDefault {
54
+ /** A fixed value. Set this or Token, not both. */
55
+ Value?: PropertyValue;
56
+ /** A context token. Set this or Value, not both. */
57
+ Token?: ContextToken;
58
+ /** Moves a date token; refused on a user token and on a fixed value. */
59
+ Offset?: PropertyDefaultOffset;
60
+ }
61
+ /** The comparison a User View property's value drives. */
62
+ export type UserViewPropertyOperator = '=' | '<>' | 'IN' | '>' | '>=' | '<' | '<=';
63
+ /** The field a User View property filters, and how. */
64
+ export interface UserViewPropertyTarget {
65
+ /** A field of the view's entity. */
66
+ Field: string;
67
+ Operator: UserViewPropertyOperator;
68
+ }
69
+ /**
70
+ * One declared property of a User View: a named, typed input that adds one predicate on its
71
+ * target field when a run gives it a value or it has a default. Stored as a JSON array in the
72
+ * `Properties` column of `MJ: User Views`.
73
+ */
74
+ export interface UserViewProperty {
75
+ /** Unique within the view. */
76
+ Name: string;
77
+ /** The value's type. A value of another type is refused. */
78
+ Type: PropertyValueType;
79
+ /** Shown to whoever sets the property. */
80
+ Description?: string;
81
+ /** Used when a run gives no value: a fixed value or a context token. */
82
+ Default?: PropertyDefault;
83
+ /** True: a run with no value and no default is refused. */
84
+ IsRequired?: boolean;
85
+ /** False: only server code may set it, and a client value is refused. Default true. */
86
+ AllowOverride?: boolean;
87
+ /** The predicate the value drives. */
88
+ Target: UserViewPropertyTarget;
89
+ }
90
+ /** What a token is worked out from. */
91
+ export interface PropertyResolutionContext {
92
+ /** The context user. Required by the user tokens. `UserInfo` fits. */
93
+ User?: {
94
+ ID: string;
95
+ Email?: string;
96
+ Name?: string;
97
+ };
98
+ /** The clock. Defaults to the current time. */
99
+ Now?: Date;
100
+ /** IANA time zone the date tokens are worked out in. Defaults to `'UTC'`. */
101
+ TimeZone?: string;
102
+ /** First day of the week for `Context.StartOfWeek`: 1 = Monday (default, ISO 8601), 0 = Sunday. */
103
+ WeekStartsOn?: 0 | 1;
104
+ }
105
+ /**
106
+ * The request header that carries the caller's IANA time zone. `GraphQLDataProvider` sends it;
107
+ * MJServer reads it into `UserPayload.TimeZone`.
108
+ */
109
+ export declare const TIME_ZONE_HEADER = "x-mj-timezone";
110
+ /** True when `name` is a time zone this runtime's `Intl` accepts (an IANA name such as `'Europe/Paris'`). */
111
+ export declare function IsValidTimeZone(name: string | null | undefined): boolean;
112
+ /** This runtime's own IANA time zone, or undefined where `Intl` gives none. */
113
+ export declare function GetLocalTimeZone(): string | undefined;
114
+ /** True when `token` is one of {@link CONTEXT_TOKENS}. */
115
+ export declare function IsContextToken(token: string | null | undefined): token is ContextToken;
116
+ /**
117
+ * Works out a property default: the fixed value, or the token resolved by {@link ResolveContextToken}.
118
+ * @throws when the default is malformed (see {@link ValidatePropertyDefault}) or the token cannot be resolved
119
+ */
120
+ export declare function ResolvePropertyDefault(def: PropertyDefault, ctx: PropertyResolutionContext): PropertyValue;
121
+ /**
122
+ * Works out one context token.
123
+ * @returns the user's ID, email or name; a `YYYY-MM-DD` date in the context's zone; or, for
124
+ * `Context.Now`, an ISO 8601 instant
125
+ * @throws on an unknown token, a bad offset, an offset on a user token, a user token with no
126
+ * context user, or an invalid time zone
127
+ */
128
+ export declare function ResolveContextToken(token: ContextToken, offset: PropertyDefaultOffset | undefined, ctx: PropertyResolutionContext): string;
129
+ /**
130
+ * Checks a property default against the property's type, as when the definition is saved.
131
+ * @returns the problems found; empty when the default is valid
132
+ */
133
+ export declare function ValidatePropertyDefault(def: PropertyDefault, type: PropertyValueType): string[];
134
+ /** True when a value fits the property type: a finite number, a boolean, a valid UUID or ISO date, or a string. Null fits every type. */
135
+ export declare function IsPropertyValueOfType(value: PropertyValue, type: PropertyValueType): boolean;
136
+ //# sourceMappingURL=contextTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextTokens.d.ts","sourceRoot":"","sources":["../../src/generic/contextTokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,wGAAwG;AACxG,eAAO,MAAM,cAAc,sMAUjB,CAAC;AAEX,sDAAsD;AACtD,MAAM,MAAM,YAAY,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,IAAI,CAAC;AAEhD,8CAA8C;AAC9C,eAAO,MAAM,oBAAoB,0DAA2D,CAAC;AAE7F,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG,OAAO,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAEpE,oDAAoD;AACpD,eAAO,MAAM,qBAAqB,sDAAuD,CAAC;AAE1F,4DAA4D;AAC5D,MAAM,MAAM,kBAAkB,GAAG,OAAO,qBAAqB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