@riocrypto/common-server 1.0.2869 → 1.0.2870

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -135,6 +135,8 @@ export * from "./models/binance-rfq-trade";
135
135
  export * from "./models/static-bank-payment-reference";
136
136
  export * from "./models/indicative-quote-page";
137
137
  export * from "./models/indicative-quote-page-verification";
138
+ export * from "./models/information-request-link";
139
+ export * from "./models/information-request-verification";
138
140
  export * from "./models/cancelled-order-pnl-report";
139
141
  export * from "./models/banner-announcement";
140
142
  export * from "./clients/axios-with-logging";
package/build/index.js CHANGED
@@ -151,6 +151,8 @@ __exportStar(require("./models/binance-rfq-trade"), exports);
151
151
  __exportStar(require("./models/static-bank-payment-reference"), exports);
152
152
  __exportStar(require("./models/indicative-quote-page"), exports);
153
153
  __exportStar(require("./models/indicative-quote-page-verification"), exports);
154
+ __exportStar(require("./models/information-request-link"), exports);
155
+ __exportStar(require("./models/information-request-verification"), exports);
154
156
  __exportStar(require("./models/cancelled-order-pnl-report"), exports);
155
157
  __exportStar(require("./models/banner-announcement"), exports);
156
158
  __exportStar(require("./clients/axios-with-logging"), exports);
@@ -18,6 +18,10 @@ declare global {
18
18
  email: string;
19
19
  pageId: string;
20
20
  };
21
+ informationRequestAuth?: {
22
+ email: string;
23
+ linkToken: string;
24
+ };
21
25
  }
22
26
  }
23
27
  }
@@ -311,6 +311,36 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
311
311
  }))());
312
312
  }
313
313
  }
314
+ // Check for information request auth token - only if needed
315
+ if (authorizationTypes.includes(common_1.AuthorizationType.InformationRequestAuth)) {
316
+ const authHeader = req.header("Authorization");
317
+ const token = (authHeader === null || authHeader === void 0 ? void 0 : authHeader.startsWith("Bearer "))
318
+ ? authHeader.slice(7)
319
+ : null;
320
+ if (token) {
321
+ promises.push((() => __awaiter(void 0, void 0, void 0, function* () {
322
+ var _l;
323
+ try {
324
+ const INFORMATION_REQUEST_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("INFORMATION_REQUEST_TOKEN_SECRET");
325
+ if (!INFORMATION_REQUEST_TOKEN_SECRET) {
326
+ return;
327
+ }
328
+ const payload = jsonwebtoken_1.default.verify(token, INFORMATION_REQUEST_TOKEN_SECRET, { algorithms: ["HS256"] });
329
+ if (payload.email && payload.linkToken) {
330
+ req.informationRequestAuth = {
331
+ email: payload.email,
332
+ linkToken: payload.linkToken,
333
+ };
334
+ }
335
+ }
336
+ catch (err) {
337
+ (_l = logger_1.default.getLogger()) === null || _l === void 0 ? void 0 : _l.warn("Information request auth verification failed", {
338
+ ip: req.headers["cf-connecting-ip"] || req.ip,
339
+ });
340
+ }
341
+ }))());
342
+ }
343
+ }
314
344
  // Wait for all promises to complete
315
345
  yield Promise.all(promises);
316
346
  // Check authorization results and proceed if authorized
@@ -333,7 +363,9 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
333
363
  authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
334
364
  req.user) ||
335
365
  (authorizationTypes.includes(common_1.AuthorizationType.IndicativeQuoteAuth) &&
336
- req.indicativeQuoteAuth)) {
366
+ req.indicativeQuoteAuth) ||
367
+ (authorizationTypes.includes(common_1.AuthorizationType.InformationRequestAuth) &&
368
+ req.informationRequestAuth)) {
337
369
  next();
338
370
  return;
339
371
  }
@@ -0,0 +1,25 @@
1
+ import { InformationRequestUpload } from "@riocrypto/common";
2
+ import { Mongoose, Model, Document, HydratedDocument } from "mongoose";
3
+ interface InformationRequestLinkAttrs {
4
+ userId: string;
5
+ token: string;
6
+ allowedEmails: string[];
7
+ createdBy: string;
8
+ createdAt: Date;
9
+ updatedAt: Date;
10
+ }
11
+ interface InformationRequestLinkModel extends Model<InformationRequestLinkDoc> {
12
+ build(attrs: InformationRequestLinkAttrs): HydratedDocument<InformationRequestLinkDoc>;
13
+ }
14
+ interface InformationRequestLinkDoc extends Document {
15
+ userId: string;
16
+ token: string;
17
+ allowedEmails: string[];
18
+ revokedAt?: Date;
19
+ createdBy: string;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ uploads: InformationRequestUpload[];
23
+ }
24
+ declare const buildInformationRequestLink: (mongoose: Mongoose) => InformationRequestLinkModel;
25
+ export { buildInformationRequestLink, InformationRequestLinkDoc, InformationRequestLinkAttrs, };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildInformationRequestLink = void 0;
4
+ const buildInformationRequestLink = (mongoose) => {
5
+ if (mongoose.models.InformationRequestLink) {
6
+ return mongoose.model("InformationRequestLink");
7
+ }
8
+ const UploadSchema = new mongoose.Schema({
9
+ label: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ fileName: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ email: {
18
+ type: String,
19
+ required: true,
20
+ },
21
+ uploadedAt: {
22
+ type: Date,
23
+ required: true,
24
+ },
25
+ sizeBytes: {
26
+ type: Number,
27
+ required: true,
28
+ },
29
+ aipriseDocumentId: {
30
+ type: String,
31
+ },
32
+ }, { _id: false });
33
+ const InformationRequestLinkSchema = new mongoose.Schema({
34
+ userId: {
35
+ type: String,
36
+ required: true,
37
+ },
38
+ // Deliberately a random value rather than this document's own ObjectId,
39
+ // which is how indicative quote pages address themselves. An ObjectId is
40
+ // only partly unpredictable -- a 4-byte timestamp, a 5-byte value fixed
41
+ // per process, and a 3-byte counter -- so holding one link narrows the
42
+ // search for others minted by the same pod. The email allowlist and the
43
+ // one-time code are the real gate either way, but this link is permanent
44
+ // and tied to a single customer, so it is a standing target and the
45
+ // randomness is free.
46
+ token: {
47
+ type: String,
48
+ required: true,
49
+ },
50
+ allowedEmails: {
51
+ type: [String],
52
+ required: true,
53
+ },
54
+ revokedAt: {
55
+ type: Date,
56
+ },
57
+ createdBy: {
58
+ type: String,
59
+ required: true,
60
+ },
61
+ createdAt: {
62
+ type: Date,
63
+ required: true,
64
+ },
65
+ updatedAt: {
66
+ type: Date,
67
+ required: true,
68
+ },
69
+ uploads: {
70
+ type: [UploadSchema],
71
+ default: [],
72
+ },
73
+ }, {
74
+ toJSON: {
75
+ transform(doc, ret) {
76
+ ret.id = ret._id.valueOf();
77
+ delete ret._id;
78
+ delete ret.__v;
79
+ },
80
+ },
81
+ });
82
+ InformationRequestLinkSchema.index({ token: 1 }, { unique: true });
83
+ InformationRequestLinkSchema.index({ userId: 1 }, { unique: true });
84
+ InformationRequestLinkSchema.statics.build = (attrs) => {
85
+ return new InformationRequestLink(attrs);
86
+ };
87
+ const InformationRequestLink = mongoose.model("InformationRequestLink", InformationRequestLinkSchema);
88
+ return InformationRequestLink;
89
+ };
90
+ exports.buildInformationRequestLink = buildInformationRequestLink;
@@ -0,0 +1,22 @@
1
+ import { Mongoose, Model, Document } from "mongoose";
2
+ interface InformationRequestVerificationAttrs {
3
+ linkToken: string;
4
+ email: string;
5
+ verificationCode: string;
6
+ expiresAt: Date;
7
+ attempts: number;
8
+ createdAt: Date;
9
+ }
10
+ interface InformationRequestVerificationModel extends Model<InformationRequestVerificationDoc> {
11
+ build(attrs: InformationRequestVerificationAttrs): InformationRequestVerificationDoc;
12
+ }
13
+ interface InformationRequestVerificationDoc extends Document {
14
+ linkToken: string;
15
+ email: string;
16
+ verificationCode: string;
17
+ expiresAt: Date;
18
+ attempts: number;
19
+ createdAt: Date;
20
+ }
21
+ declare const buildInformationRequestVerification: (mongoose: Mongoose) => InformationRequestVerificationModel;
22
+ export { buildInformationRequestVerification, InformationRequestVerificationDoc, InformationRequestVerificationAttrs, };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildInformationRequestVerification = void 0;
4
+ const buildInformationRequestVerification = (mongoose) => {
5
+ if (mongoose.models.InformationRequestVerification) {
6
+ return mongoose.model("InformationRequestVerification");
7
+ }
8
+ const InformationRequestVerificationSchema = new mongoose.Schema({
9
+ linkToken: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+ email: {
14
+ type: String,
15
+ required: true,
16
+ },
17
+ verificationCode: {
18
+ type: String,
19
+ required: true,
20
+ },
21
+ expiresAt: {
22
+ type: Date,
23
+ required: true,
24
+ },
25
+ attempts: {
26
+ type: Number,
27
+ default: 0,
28
+ },
29
+ createdAt: {
30
+ type: Date,
31
+ required: true,
32
+ },
33
+ }, {
34
+ toJSON: {
35
+ transform(doc, ret) {
36
+ ret.id = ret._id.valueOf();
37
+ delete ret._id;
38
+ delete ret.__v;
39
+ },
40
+ },
41
+ });
42
+ InformationRequestVerificationSchema.index({ linkToken: 1, email: 1 }, { unique: true });
43
+ InformationRequestVerificationSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
44
+ InformationRequestVerificationSchema.statics.build = (attrs) => {
45
+ return new InformationRequestVerification(attrs);
46
+ };
47
+ const InformationRequestVerification = mongoose.model("InformationRequestVerification", InformationRequestVerificationSchema);
48
+ return InformationRequestVerification;
49
+ };
50
+ exports.buildInformationRequestVerification = buildInformationRequestVerification;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2869",
3
+ "version": "1.0.2870",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "@google-cloud/secret-manager": "^5.6.0",
29
29
  "@google-cloud/storage": "^7.19.0",
30
30
  "@hyperdx/node-opentelemetry": "^0.10.3",
31
- "@riocrypto/common": "1.0.2688",
31
+ "@riocrypto/common": "1.0.2691",
32
32
  "@slack/web-api": "^7.15.0",
33
33
  "@types/express": "^4.17.25",
34
34
  "axios": "1.16.0",