@memberjunction/core-entities-server 6.3.0-edge.2 → 6.3.0-edge.3

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 (171) hide show
  1. package/README.md +13 -0
  2. package/dist/custom/ArtifactSecurityHookHelpers.d.ts.map +1 -1
  3. package/dist/custom/ArtifactSecurityHookHelpers.js +50 -0
  4. package/dist/custom/ArtifactSecurityHookHelpers.js.map +1 -1
  5. package/dist/custom/GraphConceptReadSecurityHook.d.ts +75 -0
  6. package/dist/custom/GraphConceptReadSecurityHook.d.ts.map +1 -0
  7. package/dist/custom/GraphConceptReadSecurityHook.js +574 -0
  8. package/dist/custom/GraphConceptReadSecurityHook.js.map +1 -0
  9. package/dist/custom/GraphRecordChangesReadSecurityHook.d.ts +45 -0
  10. package/dist/custom/GraphRecordChangesReadSecurityHook.d.ts.map +1 -0
  11. package/dist/custom/GraphRecordChangesReadSecurityHook.js +744 -0
  12. package/dist/custom/GraphRecordChangesReadSecurityHook.js.map +1 -0
  13. package/dist/custom/MJAIAgentActionEntityServer.server.d.ts +13 -0
  14. package/dist/custom/MJAIAgentActionEntityServer.server.d.ts.map +1 -0
  15. package/dist/custom/MJAIAgentActionEntityServer.server.js +52 -0
  16. package/dist/custom/MJAIAgentActionEntityServer.server.js.map +1 -0
  17. package/dist/custom/MJAIAgentCategoryEntityServer.server.d.ts +30 -0
  18. package/dist/custom/MJAIAgentCategoryEntityServer.server.d.ts.map +1 -0
  19. package/dist/custom/MJAIAgentCategoryEntityServer.server.js +127 -0
  20. package/dist/custom/MJAIAgentCategoryEntityServer.server.js.map +1 -0
  21. package/dist/custom/MJAIAgentClientToolEntityServer.server.d.ts +12 -0
  22. package/dist/custom/MJAIAgentClientToolEntityServer.server.d.ts.map +1 -0
  23. package/dist/custom/MJAIAgentClientToolEntityServer.server.js +46 -0
  24. package/dist/custom/MJAIAgentClientToolEntityServer.server.js.map +1 -0
  25. package/dist/custom/MJAIAgentEntityServer.server.d.ts +113 -7
  26. package/dist/custom/MJAIAgentEntityServer.server.d.ts.map +1 -1
  27. package/dist/custom/MJAIAgentEntityServer.server.js +1946 -96
  28. package/dist/custom/MJAIAgentEntityServer.server.js.map +1 -1
  29. package/dist/custom/MJAIAgentModalityEntityServer.server.d.ts +13 -0
  30. package/dist/custom/MJAIAgentModalityEntityServer.server.d.ts.map +1 -0
  31. package/dist/custom/MJAIAgentModalityEntityServer.server.js +52 -0
  32. package/dist/custom/MJAIAgentModalityEntityServer.server.js.map +1 -0
  33. package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts +64 -8
  34. package/dist/custom/MJAIAgentNoteEntityServer.server.d.ts.map +1 -1
  35. package/dist/custom/MJAIAgentNoteEntityServer.server.js +263 -9
  36. package/dist/custom/MJAIAgentNoteEntityServer.server.js.map +1 -1
  37. package/dist/custom/MJAIAgentPersonaEntityServer.server.d.ts +2 -2
  38. package/dist/custom/MJAIAgentPersonaEntityServer.server.d.ts.map +1 -1
  39. package/dist/custom/MJAIAgentPersonaEntityServer.server.js +10 -8
  40. package/dist/custom/MJAIAgentPersonaEntityServer.server.js.map +1 -1
  41. package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts +5 -2
  42. package/dist/custom/MJAIAgentRelationshipEntityServer.server.d.ts.map +1 -1
  43. package/dist/custom/MJAIAgentRelationshipEntityServer.server.js +25 -2
  44. package/dist/custom/MJAIAgentRelationshipEntityServer.server.js.map +1 -1
  45. package/dist/custom/MJAIAgentSkillEntityServer.server.d.ts +12 -0
  46. package/dist/custom/MJAIAgentSkillEntityServer.server.d.ts.map +1 -0
  47. package/dist/custom/MJAIAgentSkillEntityServer.server.js +46 -0
  48. package/dist/custom/MJAIAgentSkillEntityServer.server.js.map +1 -0
  49. package/dist/custom/MJAIAgentStepTypeEntityServer.server.d.ts +28 -0
  50. package/dist/custom/MJAIAgentStepTypeEntityServer.server.d.ts.map +1 -0
  51. package/dist/custom/MJAIAgentStepTypeEntityServer.server.js +117 -0
  52. package/dist/custom/MJAIAgentStepTypeEntityServer.server.js.map +1 -0
  53. package/dist/custom/MJAIAgentTypeEntityServer.server.d.ts +34 -0
  54. package/dist/custom/MJAIAgentTypeEntityServer.server.d.ts.map +1 -0
  55. package/dist/custom/MJAIAgentTypeEntityServer.server.js +231 -0
  56. package/dist/custom/MJAIAgentTypeEntityServer.server.js.map +1 -0
  57. package/dist/custom/MJActionEntityServer.server.d.ts +37 -0
  58. package/dist/custom/MJActionEntityServer.server.d.ts.map +1 -1
  59. package/dist/custom/MJActionEntityServer.server.js +208 -3
  60. package/dist/custom/MJActionEntityServer.server.js.map +1 -1
  61. package/dist/custom/MJComponentEntityServer.server.d.ts +6 -0
  62. package/dist/custom/MJComponentEntityServer.server.d.ts.map +1 -1
  63. package/dist/custom/MJComponentEntityServer.server.js +20 -2
  64. package/dist/custom/MJComponentEntityServer.server.js.map +1 -1
  65. package/dist/custom/MJContentSourceEntityServer.server.d.ts +28 -0
  66. package/dist/custom/MJContentSourceEntityServer.server.d.ts.map +1 -0
  67. package/dist/custom/MJContentSourceEntityServer.server.js +73 -0
  68. package/dist/custom/MJContentSourceEntityServer.server.js.map +1 -0
  69. package/dist/custom/MJContentSourceTypeEntityServer.server.d.ts +25 -0
  70. package/dist/custom/MJContentSourceTypeEntityServer.server.d.ts.map +1 -0
  71. package/dist/custom/MJContentSourceTypeEntityServer.server.js +73 -0
  72. package/dist/custom/MJContentSourceTypeEntityServer.server.js.map +1 -0
  73. package/dist/custom/MJDashboardEntityServer.server.d.ts +6 -0
  74. package/dist/custom/MJDashboardEntityServer.server.d.ts.map +1 -1
  75. package/dist/custom/MJDashboardEntityServer.server.js +24 -2
  76. package/dist/custom/MJDashboardEntityServer.server.js.map +1 -1
  77. package/dist/custom/MJGraphConceptEntityServer.server.d.ts +175 -23
  78. package/dist/custom/MJGraphConceptEntityServer.server.d.ts.map +1 -1
  79. package/dist/custom/MJGraphConceptEntityServer.server.js +584 -41
  80. package/dist/custom/MJGraphConceptEntityServer.server.js.map +1 -1
  81. package/dist/custom/MJGraphEdgeEntityServer.server.d.ts +38 -11
  82. package/dist/custom/MJGraphEdgeEntityServer.server.d.ts.map +1 -1
  83. package/dist/custom/MJGraphEdgeEntityServer.server.js +249 -39
  84. package/dist/custom/MJGraphEdgeEntityServer.server.js.map +1 -1
  85. package/dist/custom/MJGraphEntityServer.server.d.ts +58 -0
  86. package/dist/custom/MJGraphEntityServer.server.d.ts.map +1 -0
  87. package/dist/custom/MJGraphEntityServer.server.js +357 -0
  88. package/dist/custom/MJGraphEntityServer.server.js.map +1 -0
  89. package/dist/custom/MJGraphLinkEntityServer.server.d.ts +98 -0
  90. package/dist/custom/MJGraphLinkEntityServer.server.d.ts.map +1 -0
  91. package/dist/custom/MJGraphLinkEntityServer.server.js +375 -0
  92. package/dist/custom/MJGraphLinkEntityServer.server.js.map +1 -0
  93. package/dist/custom/MJGraphPermissionEntityServer.server.d.ts +29 -0
  94. package/dist/custom/MJGraphPermissionEntityServer.server.d.ts.map +1 -0
  95. package/dist/custom/MJGraphPermissionEntityServer.server.js +141 -0
  96. package/dist/custom/MJGraphPermissionEntityServer.server.js.map +1 -0
  97. package/dist/custom/MJListDetailEntityServer.server.d.ts +4 -4
  98. package/dist/custom/MJListDetailEntityServer.server.js +4 -4
  99. package/dist/custom/MJListEntityServer.server.d.ts +2 -1
  100. package/dist/custom/MJListEntityServer.server.d.ts.map +1 -1
  101. package/dist/custom/MJListEntityServer.server.js +5 -2
  102. package/dist/custom/MJListEntityServer.server.js.map +1 -1
  103. package/dist/custom/MJQueryEntityServer.server.d.ts +51 -3
  104. package/dist/custom/MJQueryEntityServer.server.d.ts.map +1 -1
  105. package/dist/custom/MJQueryEntityServer.server.js +142 -28
  106. package/dist/custom/MJQueryEntityServer.server.js.map +1 -1
  107. package/dist/custom/MJQueryParameterEntityServer.server.d.ts +37 -0
  108. package/dist/custom/MJQueryParameterEntityServer.server.d.ts.map +1 -0
  109. package/dist/custom/MJQueryParameterEntityServer.server.js +160 -0
  110. package/dist/custom/MJQueryParameterEntityServer.server.js.map +1 -0
  111. package/dist/custom/MJQuerySQLEntityServer.server.d.ts +23 -0
  112. package/dist/custom/MJQuerySQLEntityServer.server.d.ts.map +1 -1
  113. package/dist/custom/MJQuerySQLEntityServer.server.js +106 -9
  114. package/dist/custom/MJQuerySQLEntityServer.server.js.map +1 -1
  115. package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.d.ts +1 -1
  116. package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.d.ts.map +1 -1
  117. package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.js +8 -5
  118. package/dist/custom/MJRowLevelSecurityFilterEntityServer.server.js.map +1 -1
  119. package/dist/custom/MJUserRoleEntityServer.server.d.ts.map +1 -1
  120. package/dist/custom/MJUserRoleEntityServer.server.js +9 -0
  121. package/dist/custom/MJUserRoleEntityServer.server.js.map +1 -1
  122. package/dist/custom/MJUserViewEntityServer.server.d.ts +9 -0
  123. package/dist/custom/MJUserViewEntityServer.server.d.ts.map +1 -1
  124. package/dist/custom/MJUserViewEntityServer.server.js +59 -3
  125. package/dist/custom/MJUserViewEntityServer.server.js.map +1 -1
  126. package/dist/custom/agentRelationalGrantGuard.d.ts +73 -0
  127. package/dist/custom/agentRelationalGrantGuard.d.ts.map +1 -0
  128. package/dist/custom/agentRelationalGrantGuard.js +375 -0
  129. package/dist/custom/agentRelationalGrantGuard.js.map +1 -0
  130. package/dist/custom/approvalStamp.d.ts +68 -4
  131. package/dist/custom/approvalStamp.d.ts.map +1 -1
  132. package/dist/custom/approvalStamp.js +107 -13
  133. package/dist/custom/approvalStamp.js.map +1 -1
  134. package/dist/custom/canon/CanonFingerprintRecorderServer.d.ts +20 -0
  135. package/dist/custom/canon/CanonFingerprintRecorderServer.d.ts.map +1 -0
  136. package/dist/custom/canon/CanonFingerprintRecorderServer.js +148 -0
  137. package/dist/custom/canon/CanonFingerprintRecorderServer.js.map +1 -0
  138. package/dist/custom/canon/index.d.ts +2 -0
  139. package/dist/custom/canon/index.d.ts.map +1 -0
  140. package/dist/custom/canon/index.js +2 -0
  141. package/dist/custom/canon/index.js.map +1 -0
  142. package/dist/custom/graph/GraphFindPathServerOperation.d.ts +7 -5
  143. package/dist/custom/graph/GraphFindPathServerOperation.d.ts.map +1 -1
  144. package/dist/custom/graph/GraphFindPathServerOperation.js +41 -12
  145. package/dist/custom/graph/GraphFindPathServerOperation.js.map +1 -1
  146. package/dist/custom/graphPermissionGuard.d.ts +69 -0
  147. package/dist/custom/graphPermissionGuard.d.ts.map +1 -0
  148. package/dist/custom/graphPermissionGuard.js +229 -0
  149. package/dist/custom/graphPermissionGuard.js.map +1 -0
  150. package/dist/custom/graphRlsCacheInvalidation.d.ts +38 -0
  151. package/dist/custom/graphRlsCacheInvalidation.d.ts.map +1 -0
  152. package/dist/custom/graphRlsCacheInvalidation.js +111 -0
  153. package/dist/custom/graphRlsCacheInvalidation.js.map +1 -0
  154. package/dist/custom/queryParentFingerprint.d.ts +36 -0
  155. package/dist/custom/queryParentFingerprint.d.ts.map +1 -0
  156. package/dist/custom/queryParentFingerprint.js +159 -0
  157. package/dist/custom/queryParentFingerprint.js.map +1 -0
  158. package/dist/custom/queryParentSaveChain.d.ts +5 -0
  159. package/dist/custom/queryParentSaveChain.d.ts.map +1 -0
  160. package/dist/custom/queryParentSaveChain.js +25 -0
  161. package/dist/custom/queryParentSaveChain.js.map +1 -0
  162. package/dist/custom/seededMetadataPush.d.ts +7 -0
  163. package/dist/custom/seededMetadataPush.d.ts.map +1 -0
  164. package/dist/custom/seededMetadataPush.js +23 -0
  165. package/dist/custom/seededMetadataPush.js.map +1 -0
  166. package/dist/index.d.ts +19 -0
  167. package/dist/index.d.ts.map +1 -1
  168. package/dist/index.js +19 -0
  169. package/dist/index.js.map +1 -1
  170. package/dist/tsconfig.tsbuildinfo +1 -1
  171. package/package.json +31 -31
@@ -8,7 +8,7 @@
8
8
  * caller passes an {@link ApproverRule} that narrows it (queries need the `Queries: Approve`
9
9
  * authorization).
10
10
  */
11
- import { BaseEntity, BaseEntityResult } from '@memberjunction/core';
11
+ import { BaseEntity, BaseEntityResult, EntitySaveOptions } from '@memberjunction/core';
12
12
  import type { UserInfo } from '@memberjunction/core';
13
13
  /** The approval columns every approvable entity carries. */
14
14
  export interface ApprovalColumns {
@@ -26,6 +26,26 @@ export interface ApproverRule {
26
26
  }
27
27
  /** The status column that carries the approval: `Status` on queries, `ApprovalStatus` on the others. */
28
28
  export type ApprovalStatusField = 'Status' | 'ApprovalStatus';
29
+ /** The stored approval, as the database holds it. */
30
+ export type StoredApprovalRow = Partial<Record<ApprovalStatusField, string | null>> & {
31
+ ApprovedByUserID: string | null;
32
+ ApprovedAt: Date | string | null;
33
+ ApprovedFingerprint: string | null;
34
+ };
35
+ /**
36
+ * D55 / Finding 62: options allowing {@link ApplyApprovalRulesAsync} to detect a non-approving
37
+ * definition edit against a stored `Approved` row lacking an `ApprovedFingerprint`, and record the
38
+ * pre-write stored definition's marked fingerprint before the edit is persisted so the edited row
39
+ * evaluates `Stale`.
40
+ */
41
+ export interface PreEditFingerprintOptions<TStored extends StoredApprovalRow = StoredApprovalRow> {
42
+ /** Extra definition/deriving columns to read alongside the approval columns from the database. */
43
+ readonly StoredFields: ReadonlyArray<Extract<keyof TStored, string>>;
44
+ /** True when the save changes or will derive/mutate any definition field compared to `stored`. */
45
+ readonly HasDefinitionChange: (stored: TStored) => boolean;
46
+ /** Computes the fingerprint of the pre-write stored definition from `stored` (and any child rows). */
47
+ readonly ComputeStoredFingerprint: (stored: TStored) => Promise<string>;
48
+ }
29
49
  /**
30
50
  * Applies the approval rules to a record about to be saved, and says whether this save approves it.
31
51
  *
@@ -35,6 +55,12 @@ export type ApprovalStatusField = 'Status' | 'ApprovalStatus';
35
55
  * - On any other save the three columns keep their stored values (none on a create), so values a
36
56
  * client sent are ignored. Moving away from Approved clears nothing: the approval stays as history
37
57
  * and stops being current because the status is no longer Approved.
58
+ * - Finding 62 (D55): on a non-approving save that changes a definition field of an `Approved`
59
+ * stored row with no fingerprint on record, first computes the marked fingerprint of the stored
60
+ * pre-write definition read from the database so the edited row evaluates `Stale`. Not inside a
61
+ * metadata push (`IsMetadataPushInProgress`): pushed content is seeded, not edited.
62
+ * - Finding 70: the stored row is read as the system user, and a row missing a requested column
63
+ * (field security drops denied columns silently) refuses the save instead of reading as "none".
38
64
  *
39
65
  * The stored values are read from the database rather than the record's old values, which a client
40
66
  * can supply on an update.
@@ -47,7 +73,45 @@ export type ApprovalStatusField = 'Status' | 'ApprovalStatus';
47
73
  * @throws when the stored row cannot be read, when approving with no context user, or when the
48
74
  * context user fails the `approverRule`
49
75
  */
50
- export declare function ApplyApprovalRulesAsync(record: BaseEntity & ApprovalColumns, statusField: ApprovalStatusField, newStatus: string | null, approverRule?: ApproverRule): Promise<boolean>;
51
- /** A failed save result for a save refused before anything was written. */
52
- export declare function ApprovalRefusalResult(record: BaseEntity, error: unknown): BaseEntityResult;
76
+ export declare function ApplyApprovalRulesAsync<TStored extends StoredApprovalRow = StoredApprovalRow>(record: BaseEntity & ApprovalColumns, statusField: ApprovalStatusField, newStatus: string | null, approverRule?: ApproverRule, preEditOptions?: PreEditFingerprintOptions<TStored>): Promise<boolean>;
77
+ /**
78
+ * D55: records the fingerprint of an item that is Approved with none on record, taking the definition
79
+ * as it is stored now as the approved one and marking the value as recorded after the fact.
80
+ *
81
+ * Only for an unedited, stored row, and only inside {@link CANON_RECORD_APPROVED_FINGERPRINT_OPERATION}
82
+ * (a client save never reaches it). The stored row is read again first, so an item approved since, or
83
+ * recorded by another evaluation, is left alone. The approver and the approval time are not touched,
84
+ * so the write is not a new approval. `computeFingerprint` works from the record's stored definition;
85
+ * `writeRow` writes the row without the server class's own approval rules, with the options given.
86
+ *
87
+ * Finding 74: the write is conditional. Between the read and the write, a client's child edit can
88
+ * record the pre-edit fingerprint and then change the definition this computation reads. The save
89
+ * therefore runs the provider's locked concurrency check against a baseline of "no fingerprint"
90
+ * (`RecordedFingerprintWriteOptions`): it reads the stored `ApprovedFingerprint` under the save's own
91
+ * row lock and refuses the write when one is on record by then, so a recorded value is never replaced.
92
+ *
93
+ * @returns true when the fingerprint was written
94
+ */
95
+ export declare function RecordMissingApprovedFingerprintAsync(record: BaseEntity & ApprovalColumns, statusField: ApprovalStatusField, computeFingerprint: () => Promise<string>, writeRow: (options: EntitySaveOptions) => Promise<boolean>): Promise<boolean>;
96
+ /**
97
+ * Save options for the D55 recording write (Finding 74): the provider's locked concurrency check in
98
+ * `'enforce'` mode, with the baseline that no fingerprint is on record. The save reads the stored
99
+ * `ApprovedFingerprint` under its own row lock and is refused when a fingerprint was recorded after
100
+ * this recording read the row.
101
+ */
102
+ export declare function RecordedFingerprintWriteOptions(): EntitySaveOptions;
103
+ /** A failed save (or delete) result for an operation refused before anything was written. */
104
+ export declare function ApprovalRefusalResult(record: BaseEntity, error: unknown, type?: BaseEntityResult['Type']): BaseEntityResult;
105
+ /**
106
+ * The user a stored approval or definition row is read as: the system user, so field security never
107
+ * narrows the row (Finding 70); the given user only when no system user is loaded, in which case
108
+ * {@link AssertStoredColumnsPresent} refuses a narrowed row.
109
+ */
110
+ export declare function StoredRowReadUser(fallback: UserInfo | undefined): UserInfo | undefined;
111
+ /**
112
+ * Throws when a stored row read with a field list lacks one of the requested columns. Field security
113
+ * drops a denied column from the row silently, and a missing `ApprovedFingerprint` would then read as
114
+ * "none on record" (Finding 70): a row that could not be read in full is never taken as read.
115
+ */
116
+ export declare function AssertStoredColumnsPresent(row: object, fields: ReadonlyArray<string>, what: string): void;
53
117
  //# sourceMappingURL=approvalStamp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"approvalStamp.d.ts","sourceRoot":"","sources":["../../src/custom/approvalStamp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC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AmB,EAChC,kBAAkB,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACzC,QAAQ,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,OAAO,CAAC,GAC3D,OAAO,CAAC,OAAO,CAAC,CAclB;AAED;;;;;GAKG;AACH,wBAAgB,+BAA+B,IAAI,iBAAiB,CAKnE;AAED,6FAA6F;AAC7F,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAQ3H;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAEtF;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAKzG"}
@@ -8,7 +8,10 @@
8
8
  * caller passes an {@link ApproverRule} that narrows it (queries need the `Queries: Approve`
9
9
  * authorization).
10
10
  */
11
- import { BaseEntityResult } from '@memberjunction/core';
11
+ import { BaseEntityResult, EntitySaveOptions, ServerOperationScopeManager } from '@memberjunction/core';
12
+ import { UserCache } from '@memberjunction/generic-database-provider';
13
+ import { IsMetadataPushInProgress } from './seededMetadataPush.js';
14
+ import { CANON_RECORD_APPROVED_FINGERPRINT_OPERATION, IsApprovedFingerprintMissing, MarkFingerprintRecordedAfterApproval, } from '@memberjunction/core-entities';
12
15
  /**
13
16
  * Applies the approval rules to a record about to be saved, and says whether this save approves it.
14
17
  *
@@ -18,6 +21,12 @@ import { BaseEntityResult } from '@memberjunction/core';
18
21
  * - On any other save the three columns keep their stored values (none on a create), so values a
19
22
  * client sent are ignored. Moving away from Approved clears nothing: the approval stays as history
20
23
  * and stops being current because the status is no longer Approved.
24
+ * - Finding 62 (D55): on a non-approving save that changes a definition field of an `Approved`
25
+ * stored row with no fingerprint on record, first computes the marked fingerprint of the stored
26
+ * pre-write definition read from the database so the edited row evaluates `Stale`. Not inside a
27
+ * metadata push (`IsMetadataPushInProgress`): pushed content is seeded, not edited.
28
+ * - Finding 70: the stored row is read as the system user, and a row missing a requested column
29
+ * (field security drops denied columns silently) refuses the save instead of reading as "none".
21
30
  *
22
31
  * The stored values are read from the database rather than the record's old values, which a client
23
32
  * can supply on an update.
@@ -30,8 +39,10 @@ import { BaseEntityResult } from '@memberjunction/core';
30
39
  * @throws when the stored row cannot be read, when approving with no context user, or when the
31
40
  * context user fails the `approverRule`
32
41
  */
33
- export async function ApplyApprovalRulesAsync(record, statusField, newStatus, approverRule) {
34
- const stored = record.IsSaved ? await readStoredApproval(record, statusField) : null;
42
+ export async function ApplyApprovalRulesAsync(record, statusField, newStatus, approverRule, preEditOptions) {
43
+ const stored = record.IsSaved
44
+ ? await readStoredApproval(record, statusField, preEditOptions?.StoredFields)
45
+ : null;
35
46
  if (newStatus === 'Approved' && stored?.[statusField] !== 'Approved') {
36
47
  const user = record.ContextCurrentUser;
37
48
  if (!user?.ID) {
@@ -47,31 +58,114 @@ export async function ApplyApprovalRulesAsync(record, statusField, newStatus, ap
47
58
  }
48
59
  record.ApprovedByUserID = stored?.ApprovedByUserID ?? null;
49
60
  record.ApprovedAt = stored?.ApprovedAt ? new Date(stored.ApprovedAt) : null;
50
- record.ApprovedFingerprint = stored?.ApprovedFingerprint ?? null;
61
+ if (stored &&
62
+ stored[statusField] === 'Approved' &&
63
+ IsApprovedFingerprintMissing(stored.ApprovedFingerprint) &&
64
+ // A metadata push writes seeded content, not an edit: the run gate records the pushed definition.
65
+ !IsMetadataPushInProgress() &&
66
+ preEditOptions?.HasDefinitionChange(stored)) {
67
+ const preEditFingerprint = await preEditOptions.ComputeStoredFingerprint(stored);
68
+ record.ApprovedFingerprint = MarkFingerprintRecordedAfterApproval(preEditFingerprint);
69
+ }
70
+ else {
71
+ record.ApprovedFingerprint = stored?.ApprovedFingerprint ?? null;
72
+ }
51
73
  return false;
52
74
  }
53
- /** A failed save result for a save refused before anything was written. */
54
- export function ApprovalRefusalResult(record, error) {
75
+ /**
76
+ * D55: records the fingerprint of an item that is Approved with none on record, taking the definition
77
+ * as it is stored now as the approved one and marking the value as recorded after the fact.
78
+ *
79
+ * Only for an unedited, stored row, and only inside {@link CANON_RECORD_APPROVED_FINGERPRINT_OPERATION}
80
+ * (a client save never reaches it). The stored row is read again first, so an item approved since, or
81
+ * recorded by another evaluation, is left alone. The approver and the approval time are not touched,
82
+ * so the write is not a new approval. `computeFingerprint` works from the record's stored definition;
83
+ * `writeRow` writes the row without the server class's own approval rules, with the options given.
84
+ *
85
+ * Finding 74: the write is conditional. Between the read and the write, a client's child edit can
86
+ * record the pre-edit fingerprint and then change the definition this computation reads. The save
87
+ * therefore runs the provider's locked concurrency check against a baseline of "no fingerprint"
88
+ * (`RecordedFingerprintWriteOptions`): it reads the stored `ApprovedFingerprint` under the save's own
89
+ * row lock and refuses the write when one is on record by then, so a recorded value is never replaced.
90
+ *
91
+ * @returns true when the fingerprint was written
92
+ */
93
+ export async function RecordMissingApprovedFingerprintAsync(record, statusField, computeFingerprint, writeRow) {
94
+ if (!record.IsSaved || record.Dirty) {
95
+ return false;
96
+ }
97
+ const scope = ServerOperationScopeManager.Instance;
98
+ if (!scope.IsOperationActive([CANON_RECORD_APPROVED_FINGERPRINT_OPERATION], record.EntityInfo.Name, record.ContextCurrentUser)) {
99
+ return false;
100
+ }
101
+ const stored = await readStoredApproval(record, statusField);
102
+ if (stored[statusField] !== 'Approved' || !IsApprovedFingerprintMissing(stored.ApprovedFingerprint)) {
103
+ return false;
104
+ }
105
+ record.ApprovedFingerprint = MarkFingerprintRecordedAfterApproval(await computeFingerprint());
106
+ return writeRow(RecordedFingerprintWriteOptions());
107
+ }
108
+ /**
109
+ * Save options for the D55 recording write (Finding 74): the provider's locked concurrency check in
110
+ * `'enforce'` mode, with the baseline that no fingerprint is on record. The save reads the stored
111
+ * `ApprovedFingerprint` under its own row lock and is refused when a fingerprint was recorded after
112
+ * this recording read the row.
113
+ */
114
+ export function RecordedFingerprintWriteOptions() {
115
+ const options = new EntitySaveOptions();
116
+ options.ConcurrencyCheck = 'enforce';
117
+ options.ConcurrencyBaseline = { ApprovedFingerprint: null };
118
+ return options;
119
+ }
120
+ /** A failed save (or delete) result for an operation refused before anything was written. */
121
+ export function ApprovalRefusalResult(record, error, type) {
55
122
  const result = new BaseEntityResult();
56
123
  result.Success = false;
57
- result.Type = record.IsSaved ? 'update' : 'create';
124
+ result.Type = type ?? (record.IsSaved ? 'update' : 'create');
58
125
  result.Message = error instanceof Error ? error.message : String(error);
59
126
  result.StartedAt = new Date();
60
127
  result.EndedAt = new Date();
61
128
  return result;
62
129
  }
63
- /** Reads the stored status and approval columns, bypassing every cache. */
64
- async function readStoredApproval(record, statusField) {
130
+ /**
131
+ * The user a stored approval or definition row is read as: the system user, so field security never
132
+ * narrows the row (Finding 70); the given user only when no system user is loaded, in which case
133
+ * {@link AssertStoredColumnsPresent} refuses a narrowed row.
134
+ */
135
+ export function StoredRowReadUser(fallback) {
136
+ return UserCache.Instance?.GetSystemUser?.() ?? fallback;
137
+ }
138
+ /**
139
+ * Throws when a stored row read with a field list lacks one of the requested columns. Field security
140
+ * drops a denied column from the row silently, and a missing `ApprovedFingerprint` would then read as
141
+ * "none on record" (Finding 70): a row that could not be read in full is never taken as read.
142
+ */
143
+ export function AssertStoredColumnsPresent(row, fields, what) {
144
+ const absent = fields.filter(f => !Object.prototype.hasOwnProperty.call(row, f));
145
+ if (absent.length > 0) {
146
+ throw new Error(`Could not read the stored ${what}: column(s) ${absent.join(', ')} were not returned, so it cannot be checked.`);
147
+ }
148
+ }
149
+ /**
150
+ * Reads the stored status and approval columns (plus optional extra fields), bypassing every cache,
151
+ * as the system user, and throws unless every requested column came back.
152
+ */
153
+ async function readStoredApproval(record, statusField, extraFields) {
154
+ const baseFields = [statusField, 'ApprovedByUserID', 'ApprovedAt', 'ApprovedFingerprint'];
155
+ const fields = extraFields?.length ? Array.from(new Set([...baseFields, ...extraFields])) : baseFields;
156
+ const what = `approval of ${record.EntityInfo.Name} ${record.PrimaryKey.ToString()}`;
65
157
  const result = await record.RunViewProviderToUse.RunView({
66
158
  EntityName: record.EntityInfo.Name,
67
159
  ExtraFilter: record.PrimaryKey.ToWhereClause(),
68
- Fields: [statusField, 'ApprovedByUserID', 'ApprovedAt', 'ApprovedFingerprint'],
160
+ Fields: fields,
69
161
  ResultType: 'simple',
70
162
  BypassCache: true
71
- }, record.ContextCurrentUser);
163
+ }, StoredRowReadUser(record.ContextCurrentUser));
72
164
  if (!result.Success || !result.Results?.length) {
73
- throw new Error(`Could not read the stored approval of ${record.EntityInfo.Name} ${record.PrimaryKey.ToString()}: ${result.ErrorMessage || 'record not found'}`);
165
+ throw new Error(`Could not read the stored ${what}: ${result.ErrorMessage || 'record not found'}`);
74
166
  }
75
- return result.Results[0];
167
+ const row = result.Results[0];
168
+ AssertStoredColumnsPresent(row, fields, what);
169
+ return row;
76
170
  }
77
171
  //# sourceMappingURL=approvalStamp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"approvalStamp.js","sourceRoot":"","sources":["../../src/custom/approvalStamp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAc,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AA6BpE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,MAAoC,EACpC,WAAgC,EAChC,SAAwB,EACxB,YAA2B;IAE3B,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrF,IAAI,SAAS,KAAK,UAAU,IAAI,MAAM,EAAE,CAAC,WAAW,CAAC,KAAK,UAAU,EAAE,CAA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AG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9C,OAAO,GAAG,CAAC;AACf,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { BaseCanonFingerprintRecorder, type CanonFingerprintRecordRequest } from '@memberjunction/core-entities';
2
+ export declare class CanonFingerprintRecorderServer extends BaseCanonFingerprintRecorder {
3
+ private static readonly MAX_CONCURRENT_WRITES;
4
+ private static activeWrites;
5
+ /** Background recordings waiting for a slot, first in, first out. `Resolve(true)` hands over a slot; `Resolve(false)` starts it outside the cap. */
6
+ private static readonly writeWaiters;
7
+ /** The same key `CanonFingerprintRecording` uses for the item (`NormalizeUUID`), so the two cannot drift. */
8
+ private static keyOf;
9
+ /**
10
+ * Waits for a write slot. A foreground recording (a caller waits for it, Finding 78) never waits
11
+ * and takes no slot; the cap applies to background recordings only.
12
+ * @returns whether the caller holds a slot it must release
13
+ */
14
+ private static acquireWriteSlot;
15
+ private static releaseWriteSlot;
16
+ /** A caller now waits for a queued background recording of this item: start it now, outside the cap (Finding 78). */
17
+ Prioritize(entityName: string, recordId: string): void;
18
+ RecordMissingFingerprint(request: CanonFingerprintRecordRequest): Promise<boolean>;
19
+ }
20
+ //# sourceMappingURL=CanonFingerprintRecorderServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CanonFingerprintRecorderServer.d.ts","sourceRoot":"","sources":["../../../src/custom/canon/CanonFingerprintRecorderServer.ts"],"names":[],"mappings":"AAmBA,OAAO,EACH,4BAA4B,EAE5B,KAAK,6BAA6B,EACrC,MAAM,+BAA+B,CAAC;AA6BvC,qBACa,8BAA+B,SAAQ,4BAA4B;IAC5E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAK;IAClD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAK;IAChC,oJAAoJ;IACpJ,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAqE;IAEzG,6GAA6G;IAC7G,OAAO,CAAC,MAAM,CAAC,KAAK;IAIpB;;;;OAIG;mBACkB,gBAAgB;IAarC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAY/B,qHAAqH;IACrG,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAShD,wBAAwB,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,OAAO,CAAC;CA2D3G"}
@@ -0,0 +1,148 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var CanonFingerprintRecorderServer_1;
8
+ /**
9
+ * D55: the server's recorder for the fingerprint of an approved item that has none.
10
+ *
11
+ * `CanonFingerprintRecording` (in `@memberjunction/core-entities`) calls this the first time the
12
+ * server evaluates a query, component, user view or dashboard that is Approved with no fingerprint on
13
+ * record. It loads the record as the system user and asks the entity's server class to record the
14
+ * fingerprint inside {@link CANON_RECORD_APPROVED_FINGERPRINT_OPERATION}; the server class recomputes
15
+ * the fingerprint from the stored definition and leaves the approver and the approval time alone.
16
+ *
17
+ * Finding 76: the recording runs on a provider instance no other unit of work shares. Its write is
18
+ * transactional (the locked concurrency check of Finding 74), and the recording is started without
19
+ * being awaited, so on a shared instance its transaction would join, or be rolled back with, whatever
20
+ * unit of work is open there. Each recording therefore gets its own
21
+ * `CreateIndependentInstance()` of the evaluation's provider (the server's provider when the
22
+ * evaluation's cannot make one): same database and pool, its own transaction stack. It is released
23
+ * when the recording settles. With no provider that can make one, nothing is recorded: it never falls
24
+ * back to a shared instance.
25
+ */
26
+ import { CompositeKey, LogError, Metadata, ServerOperationScopeManager } from '@memberjunction/core';
27
+ import { BaseCanonFingerprintRecorder, CANON_RECORD_APPROVED_FINGERPRINT_OPERATION, } from '@memberjunction/core-entities';
28
+ import { UserCache } from '@memberjunction/generic-database-provider';
29
+ import { NormalizeUUID, RegisterClass } from '@memberjunction/global';
30
+ import { MJComponentEntityServer } from '../MJComponentEntityServer.server.js';
31
+ import { MJDashboardEntityServer } from '../MJDashboardEntityServer.server.js';
32
+ import { MJQueryEntityServer } from '../MJQueryEntityServer.server.js';
33
+ import { MJUserViewEntityServer } from '../MJUserViewEntityServer.server.js';
34
+ function canCreateIndependentInstance(provider) {
35
+ return !!provider && 'CreateIndependentInstance' in provider && typeof provider.CreateIndependentInstance === 'function';
36
+ }
37
+ function isReleasableInstance(provider) {
38
+ return 'ReleaseIndependentInstance' in provider && typeof provider.ReleaseIndependentInstance === 'function';
39
+ }
40
+ /** The four fingerprinted kinds D55 covers. */
41
+ const FINGERPRINTED_ENTITIES = new Set(['mj: queries', 'mj: components', 'mj: user views', 'mj: dashboards']);
42
+ let CanonFingerprintRecorderServer = class CanonFingerprintRecorderServer extends BaseCanonFingerprintRecorder {
43
+ static { CanonFingerprintRecorderServer_1 = this; }
44
+ static { this.MAX_CONCURRENT_WRITES = 4; } // Cap parallel background D55 fingerprint writes on cold start so a graph load of many unrecorded rows never exhausts the DB connection pool
45
+ static { this.activeWrites = 0; }
46
+ /** Background recordings waiting for a slot, first in, first out. `Resolve(true)` hands over a slot; `Resolve(false)` starts it outside the cap. */
47
+ static { this.writeWaiters = []; }
48
+ /** The same key `CanonFingerprintRecording` uses for the item (`NormalizeUUID`), so the two cannot drift. */
49
+ static keyOf(entityName, recordId) {
50
+ return `${entityName.trim().toLowerCase()}|${NormalizeUUID(recordId.trim())}`;
51
+ }
52
+ /**
53
+ * Waits for a write slot. A foreground recording (a caller waits for it, Finding 78) never waits
54
+ * and takes no slot; the cap applies to background recordings only.
55
+ * @returns whether the caller holds a slot it must release
56
+ */
57
+ static async acquireWriteSlot(key, foreground) {
58
+ if (foreground) {
59
+ return false;
60
+ }
61
+ if (CanonFingerprintRecorderServer_1.activeWrites < CanonFingerprintRecorderServer_1.MAX_CONCURRENT_WRITES) {
62
+ CanonFingerprintRecorderServer_1.activeWrites++;
63
+ return true;
64
+ }
65
+ return new Promise((resolve) => {
66
+ CanonFingerprintRecorderServer_1.writeWaiters.push({ Key: key, Resolve: resolve });
67
+ });
68
+ }
69
+ static releaseWriteSlot(holdsSlot) {
70
+ if (!holdsSlot) {
71
+ return;
72
+ }
73
+ const next = CanonFingerprintRecorderServer_1.writeWaiters.shift();
74
+ if (next) {
75
+ next.Resolve(true);
76
+ }
77
+ else {
78
+ CanonFingerprintRecorderServer_1.activeWrites = Math.max(0, CanonFingerprintRecorderServer_1.activeWrites - 1);
79
+ }
80
+ }
81
+ /** A caller now waits for a queued background recording of this item: start it now, outside the cap (Finding 78). */
82
+ Prioritize(entityName, recordId) {
83
+ const key = CanonFingerprintRecorderServer_1.keyOf(entityName, recordId);
84
+ const index = CanonFingerprintRecorderServer_1.writeWaiters.findIndex((w) => w.Key === key);
85
+ if (index >= 0) {
86
+ const [waiter] = CanonFingerprintRecorderServer_1.writeWaiters.splice(index, 1);
87
+ waiter.Resolve(false);
88
+ }
89
+ }
90
+ async RecordMissingFingerprint(request) {
91
+ if (!FINGERPRINTED_ENTITIES.has(request.EntityName.trim().toLowerCase())) {
92
+ return false;
93
+ }
94
+ const systemUser = UserCache.Instance.GetSystemUser();
95
+ // The evaluation's provider first (same database as the item), then the server's; only ever an
96
+ // independent instance of it, never the instance itself (Finding 76).
97
+ const source = [request.Provider, Metadata.Provider].find(canCreateIndependentInstance); // global-provider-ok: only its CreateIndependentInstance() is used, which borrows the pool and metadata, never its transaction state
98
+ if (!systemUser || !source) {
99
+ LogError(`Canon: cannot record the fingerprint of ${request.EntityName} ${request.RecordID}: ${!systemUser ? 'no system user' : 'no provider can make an independent instance, and recording never writes on a shared one'}.`);
100
+ return false;
101
+ }
102
+ const holdsSlot = await CanonFingerprintRecorderServer_1.acquireWriteSlot(CanonFingerprintRecorderServer_1.keyOf(request.EntityName, request.RecordID), request.Foreground === true);
103
+ let provider = null;
104
+ try {
105
+ try {
106
+ provider = await source.CreateIndependentInstance();
107
+ }
108
+ catch (e) {
109
+ LogError(`Canon: cannot record the fingerprint of ${request.EntityName} ${request.RecordID}: no independent provider instance (${e instanceof Error ? e.message : String(e)}).`);
110
+ return false;
111
+ }
112
+ const isolated = provider;
113
+ return await ServerOperationScopeManager.Instance.RunWithAuthority({
114
+ operationKey: CANON_RECORD_APPROVED_FINGERPRINT_OPERATION,
115
+ source: 'ServerEngine',
116
+ allowedEntities: [request.EntityName],
117
+ userId: systemUser.ID,
118
+ }, async () => {
119
+ const record = await isolated.GetEntityObject(request.EntityName, CompositeKey.FromID(request.RecordID), systemUser); // first-pk-ok: the four fingerprinted kinds (queries, components, user views, dashboards) have the single key ID
120
+ if (!record?.IsSaved) {
121
+ return false;
122
+ }
123
+ if (record instanceof MJQueryEntityServer ||
124
+ record instanceof MJComponentEntityServer ||
125
+ record instanceof MJUserViewEntityServer ||
126
+ record instanceof MJDashboardEntityServer) {
127
+ const written = await record.RecordMissingApprovedFingerprintAsync();
128
+ if (!written && record.LatestResult && !record.LatestResult.Success) {
129
+ LogError(`Canon: recording the fingerprint of ${request.EntityName} ${request.RecordID} failed: ${record.LatestResult.CompleteMessage}`);
130
+ }
131
+ return written;
132
+ }
133
+ return false;
134
+ });
135
+ }
136
+ finally {
137
+ if (provider && isReleasableInstance(provider)) {
138
+ await provider.ReleaseIndependentInstance().catch((e) => LogError(`Canon: releasing the recording's provider instance failed: ${e.message}`));
139
+ }
140
+ CanonFingerprintRecorderServer_1.releaseWriteSlot(holdsSlot);
141
+ }
142
+ }
143
+ };
144
+ CanonFingerprintRecorderServer = CanonFingerprintRecorderServer_1 = __decorate([
145
+ RegisterClass(BaseCanonFingerprintRecorder, 'Server')
146
+ ], CanonFingerprintRecorderServer);
147
+ export { CanonFingerprintRecorderServer };
148
+ //# sourceMappingURL=CanonFingerprintRecorderServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CanonFingerprintRecorderServer.js","sourceRoot":"","sources":["../../../src/custom/canon/CanonFingerprintRecorderServer.ts"],"names":[],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAc,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,2BAA2B,EAA0B,MAAM,sBAAsB,CAAC;AACzI,OAAO,EACH,4BAA4B,EAC5B,2CAA2C,GAE9C,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAY1E,SAAS,4BAA4B,CAAC,QAA8C;IAChF,OAAO,CAAC,CAAC,QAAQ,IAAI,2BAA2B,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,yBAAyB,KAAK,UAAU,CAAC;AAC7H,CAAC;AAED,SAAS,oBAAoB,CAAC,QAA2B;IACrD,OAAO,4BAA4B,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,0BAA0B,KAAK,UAAU,CAAC;AACjH,CAAC;AAED,+CAA+C;AAC/C,MAAM,sBAAsB,GAAwB,IAAI,GAAG,CAAC,CAAC,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAG5H,IAAM,8BAA8B,GAApC,MAAM,8BAA+B,SAAQ,4BAA4B;;aACpD,0BAAqB,GAAG,CAAC,AAAJ,CAAK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AAI,MAAM,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;wBAClE,QAAQ,CAAC,uCAAuC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,QAAQ,YAAY,MAAM,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC,CAAC;oBAC7I,CAAC;oBACD,OAAO,OAAO,CAAC;gBACnB,CAAC;gBACD,OAAO,KAAK,CAAC;YACjB,CAAC,CACJ,CAAC;QACN,CAAC;gBAAS,CAAC;YACP,IAAI,QAAQ,IAAI,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7C,MAAM,QAAQ,CAAC,0BAA0B,EAAE,CAAC,KAAK,CAAC,CAAC,CAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,8DAA8D,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACzJ,CAAC;YACD,gCAA8B,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC/D,CAAC;IACL,CAAC;;AA7GQ,8BAA8B;IAD1C,aAAa,CAAC,4BAA4B,EAAE,QAAQ,CAAC;GACzC,8BAA8B,CA8G1C"}
@@ -0,0 +1,2 @@
1
+ export * from './CanonFingerprintRecorderServer.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/custom/canon/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './CanonFingerprintRecorderServer.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/custom/canon/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"}
@@ -3,12 +3,14 @@ import { GraphFindPathOperation } from '@memberjunction/core-entities';
3
3
  import type { GraphFindPathEndpoint, GraphFindPathInput, GraphFindPathOutput, GraphPathRequestResult, GraphTraversalOptions } from '@memberjunction/core-entities';
4
4
  /**
5
5
  * Server implementation of the `Graph.FindPath` remote operation: the fewest-hop path between two
6
- * nodes of a semantic graph that the caller may see, through `CanonGraphEngine.FindPathBetween`
7
- * (the same code the `Find Graph Path` action runs).
6
+ * nodes of a semantic graph that the caller may see, through `CanonGraphEngine.FindPathAcrossGraphs`
7
+ * (the same code the `Find Graph Path` action runs). With no `GraphName` every active Canon graph the
8
+ * caller can read is searched and a name found in more than one comes back `AmbiguousEndpoint` (D52);
9
+ * there is no default graph. A present-but-blank `GraphName` fails closed with `GraphNotFound`.
8
10
  *
9
- * No `Authorize` override: the operation is read-only, and every node is checked as the caller
10
- * during the search, so a caller gets only what they could already read. A record the caller cannot
11
- * see gives the same `NoPath` answer as an unconnected one.
11
+ * No `Authorize` override: the operation is read-only, and every graph and node is checked as the
12
+ * caller during the search, so a caller gets only what they could already read. A record the caller
13
+ * cannot see gives the same `NoPath` answer as an unconnected one.
12
14
  */
13
15
  export declare class GraphFindPathServerOperation extends GraphFindPathOperation {
14
16
  protected InternalExecute(input: GraphFindPathInput, provider: IMetadataProvider, user: UserInfo): Promise<GraphFindPathOutput>;
@@ -1 +1 @@
1
- {"version":3,"file":"GraphFindPathServerOperation.d.ts","sourceRoot":"","sources":["../../../src/custom/graph/GraphFindPathServerOperation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAiC,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACtG,OAAO,KAAK,EAGR,qBAAqB,EACrB,kBAAkB,EAElB,mBAAmB,EAEnB,sBAAsB,EACtB,qBAAqB,EACxB,MAAM,+BAA+B,CAAC;AAKvC;;;;;;;;GAQG;AACH,qBACa,4BAA6B,SAAQ,sBAAsB;cACpD,eAAe,CAAC,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,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uBD,6FAA6F;AAC7F,wBAAgB,gCAAgC,IAAI,IAAI,CAEvD"}
@@ -7,23 +7,35 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { BaseRemotableOperation } from '@memberjunction/core';
8
8
  import { CanonGraphEngine, GraphEngine, GraphFindPathOperation } from '@memberjunction/core-entities';
9
9
  import { RegisterClass } from '@memberjunction/global';
10
- const DEFAULT_GRAPH_NAME = 'MJ Canon';
11
10
  /**
12
11
  * Server implementation of the `Graph.FindPath` remote operation: the fewest-hop path between two
13
- * nodes of a semantic graph that the caller may see, through `CanonGraphEngine.FindPathBetween`
14
- * (the same code the `Find Graph Path` action runs).
12
+ * nodes of a semantic graph that the caller may see, through `CanonGraphEngine.FindPathAcrossGraphs`
13
+ * (the same code the `Find Graph Path` action runs). With no `GraphName` every active Canon graph the
14
+ * caller can read is searched and a name found in more than one comes back `AmbiguousEndpoint` (D52);
15
+ * there is no default graph. A present-but-blank `GraphName` fails closed with `GraphNotFound`.
15
16
  *
16
- * No `Authorize` override: the operation is read-only, and every node is checked as the caller
17
- * during the search, so a caller gets only what they could already read. A record the caller cannot
18
- * see gives the same `NoPath` answer as an unconnected one.
17
+ * No `Authorize` override: the operation is read-only, and every graph and node is checked as the
18
+ * caller during the search, so a caller gets only what they could already read. A record the caller
19
+ * cannot see gives the same `NoPath` answer as an unconnected one.
19
20
  */
20
21
  let GraphFindPathServerOperation = class GraphFindPathServerOperation extends GraphFindPathOperation {
21
22
  async InternalExecute(input, provider, user) {
22
23
  if (!HasEndpoint(input?.From) || !HasEndpoint(input?.To)) {
23
24
  throw new Error('From and To are required: each is { EntityName, RecordID } or { Concept }.');
24
25
  }
25
- const graphName = input.GraphName?.trim() || DEFAULT_GRAPH_NAME;
26
- const result = await CanonGraphEngine.Instance.FindPathBetween(graphName, input.From, input.To, TraversalOptionsOf(input), user, provider);
26
+ let requestedGraphs;
27
+ if (input.GraphName !== undefined && input.GraphName !== null) {
28
+ const trimmedGraphName = input.GraphName.trim();
29
+ if (trimmedGraphName.length === 0) {
30
+ return FindPathOutputOf({
31
+ Status: 'GraphNotFound',
32
+ Path: { Found: false, Nodes: [], Edges: [], PathWeight: 0, Message: 'No active graph name was provided.' },
33
+ Candidates: [],
34
+ }, provider);
35
+ }
36
+ requestedGraphs = [trimmedGraphName];
37
+ }
38
+ const result = await CanonGraphEngine.Instance.FindPathAcrossGraphs(requestedGraphs, input.From, input.To, TraversalOptionsOf(input), user, provider);
27
39
  return FindPathOutputOf(result, provider);
28
40
  }
29
41
  };
@@ -52,15 +64,31 @@ export function TraversalOptionsOf(input) {
52
64
  }
53
65
  /** The wire form of an engine path result. */
54
66
  export function FindPathOutputOf(result, provider) {
67
+ if (result.Status === 'InvalidParameter') {
68
+ throw new Error(result.Path.Message ?? 'Invalid graph path search parameters.');
69
+ }
70
+ const wireStatus = result.Status === 'NodeLimitReached' || result.Status === 'EndpointUnavailable'
71
+ ? 'NoPath'
72
+ : result.Status;
55
73
  return {
56
- Status: result.Status,
74
+ Status: wireStatus,
57
75
  Nodes: result.Path.Nodes.map(nodeOf),
58
76
  Edges: result.Path.Edges.map(edgeOf),
59
77
  PathWeight: result.Path.PathWeight,
60
- PromptText: result.Status === 'Found' || result.Status === 'NoPath' ? GraphEngine.Instance.DescribePathForPrompt(result.Path, provider) : '',
78
+ PromptText: wireStatus === 'Found' || wireStatus === 'NoPath' ? GraphEngine.Instance.DescribePathForPrompt(result.Path, provider) : '',
61
79
  Endpoint: result.Endpoint,
62
- Candidates: result.Candidates.map((c) => ({ Name: c.Node.Label, RecordID: c.Node.RecordID, Description: c.Node.Description, Score: c.Score })),
80
+ Candidates: result.Candidates.map((c) => ({
81
+ Name: c.Node.Label,
82
+ RecordID: c.Node.RecordID,
83
+ ...(c.GraphName ? { GraphName: c.GraphName } : {}),
84
+ ...(c.GraphID ? { GraphID: c.GraphID } : {}),
85
+ ...(c.Status ? { Status: c.Status } : {}),
86
+ Description: c.Node.Description,
87
+ Score: c.Score,
88
+ })),
63
89
  Message: result.Path.Message,
90
+ ...(result.Status === 'NodeLimitReached' || result.Path.LimitReached === true ? { LimitReached: true } : {}),
91
+ ...(result.Status === 'EndpointUnavailable' ? { EndpointUnavailable: true } : {}),
64
92
  };
65
93
  }
66
94
  function nodeOf(node) {
@@ -78,7 +106,8 @@ function edgeOf(edge) {
78
106
  Weight: edge.Weight,
79
107
  Description: edge.Description,
80
108
  Origin: edge.Origin,
81
- Status: edge.Status,
109
+ // Map Provisional edges onto Proposed on the existing wire contract until Wave 5.3 extends GraphFindPathEdge.
110
+ Status: edge.Status === 'Provisional' ? 'Proposed' : edge.Status,
82
111
  };
83
112
  }
84
113
  /** Tree-shaking anchor — referenced so bundlers retain the `@RegisterClass` registration. */