@riocrypto/common-server 1.0.2820 → 1.0.2823

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.
@@ -11,6 +11,8 @@ interface ComplianceRuleResultAttrs {
11
11
  data: string;
12
12
  details: string;
13
13
  outcome?: ComplianceRuleOutcome;
14
+ tag?: string;
15
+ renderMarkdown?: boolean;
14
16
  }
15
17
  interface ComplianceRuleResultDoc extends mongoose.Document {
16
18
  id: string;
@@ -23,6 +25,8 @@ interface ComplianceRuleResultDoc extends mongoose.Document {
23
25
  data: string;
24
26
  details: string;
25
27
  outcome?: ComplianceRuleOutcome;
28
+ tag?: string;
29
+ renderMarkdown?: boolean;
26
30
  }
27
31
  interface ComplianceRuleResultModel extends mongoose.Model<ComplianceRuleResultDoc> {
28
32
  build(attrs: ComplianceRuleResultAttrs): HydratedDocument<ComplianceRuleResultDoc>;
@@ -44,6 +44,22 @@ const buildComplianceRuleResult = (mongoose) => {
44
44
  type: String,
45
45
  required: false,
46
46
  },
47
+ // Snapshot of the parent rule's tag at run time. Snapshotted
48
+ // (not joined back through ruleId) so historical reports
49
+ // continue to group correctly when rules are renamed,
50
+ // retagged, or deleted after a session has run.
51
+ tag: {
52
+ type: String,
53
+ required: false,
54
+ },
55
+ // Snapshot of the parent rule's renderMarkdown flag at run
56
+ // time, so the PDF report knows to format this result as
57
+ // Markdown even if the rule is later changed.
58
+ renderMarkdown: {
59
+ type: Boolean,
60
+ required: false,
61
+ default: false,
62
+ },
47
63
  }, {
48
64
  toJSON: {
49
65
  transform(doc, ret) {
@@ -7,6 +7,8 @@ interface ComplianceRuleAttrs {
7
7
  ruleType: string;
8
8
  stepType: ComplianceStepType;
9
9
  ruleSetId?: string;
10
+ tag?: string;
11
+ renderMarkdown?: boolean;
10
12
  }
11
13
  interface ComplianceRuleDoc extends mongoose.Document {
12
14
  id: string;
@@ -16,6 +18,8 @@ interface ComplianceRuleDoc extends mongoose.Document {
16
18
  ruleType: string;
17
19
  stepType: ComplianceStepType;
18
20
  ruleSetId?: string;
21
+ tag?: string;
22
+ renderMarkdown?: boolean;
19
23
  }
20
24
  interface ComplianceRuleModel extends mongoose.Model<ComplianceRuleDoc> {
21
25
  build(attrs: ComplianceRuleAttrs): HydratedDocument<ComplianceRuleDoc>;
@@ -39,6 +39,22 @@ const buildComplianceRule = (mongoose) => {
39
39
  type: String,
40
40
  required: false,
41
41
  },
42
+ // Free-text grouping tag used by the PDF report to render
43
+ // related rules in a shared table. Trimmed by the API layer
44
+ // before it lands here; an empty/undefined value means
45
+ // "untagged" (the rule renders on its own in the report).
46
+ tag: {
47
+ type: String,
48
+ required: false,
49
+ },
50
+ // When true, the rule's result is authored in Markdown and
51
+ // the PDF report renders it as formatted content (GFM
52
+ // tables, headings, lists) instead of plain text.
53
+ renderMarkdown: {
54
+ type: Boolean,
55
+ required: false,
56
+ default: false,
57
+ },
42
58
  }, {
43
59
  toJSON: {
44
60
  transform(doc, ret) {
@@ -50,6 +66,10 @@ const buildComplianceRule = (mongoose) => {
50
66
  });
51
67
  ComplianceRuleSchema.index({ country: 1 });
52
68
  ComplianceRuleSchema.index({ ruleSetId: 1 });
69
+ // Compound index supports the tag-autocomplete query that powers
70
+ // the "tag" field in the rule editor: distinct(tag) scoped to a
71
+ // ruleSet, including only rules that actually carry a tag.
72
+ ComplianceRuleSchema.index({ ruleSetId: 1, tag: 1 });
53
73
  ComplianceRuleSchema.statics.build = (attrs) => {
54
74
  return new ComplianceRule(attrs);
55
75
  };
@@ -386,6 +386,19 @@ const buildOrder = (mongoose) => {
386
386
  orderSchema.index({ brokerId: 1, "TWAP.sessionId": 1, createdAt: 1 });
387
387
  orderSchema.index({ clientReferenceId: 1 }, { sparse: true });
388
388
  orderSchema.index({ "paymentsReceived.blockchainTxId": 1 }, { sparse: true });
389
+ // At most one order per real quoteId. Imported orders use quoteId "" and are
390
+ // excluded by the partial filter (which also serves the createOrder lookup).
391
+ orderSchema.index({ quoteId: 1 }, { unique: true, partialFilterExpression: { quoteId: { $gt: "" } } });
392
+ // At most one order per (broker family, clientReferenceId). rootUserId is
393
+ // brokerId || userId; orders without a clientReferenceId (or, defensively,
394
+ // without rootUserId) are excluded from the constraint.
395
+ orderSchema.index({ rootUserId: 1, clientReferenceId: 1 }, {
396
+ unique: true,
397
+ partialFilterExpression: {
398
+ clientReferenceId: { $type: "string" },
399
+ rootUserId: { $type: "string" },
400
+ },
401
+ });
389
402
  orderSchema.pre("validate", function (next) {
390
403
  this.rootUserId = this.brokerId || this.userId;
391
404
  next();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2820",
3
+ "version": "1.0.2823",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",