@riocrypto/common-server 1.0.2699 → 1.0.2701

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.
@@ -0,0 +1,3 @@
1
+ import { Mongoose } from "mongoose";
2
+ import { OrderDoc } from "../models/order";
3
+ export declare const getOrderFromStaticReference: (reference: string, amountFiat: number, mongoose: Mongoose) => Promise<OrderDoc | null>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getOrderFromStaticReference = void 0;
13
+ const order_1 = require("../models/order");
14
+ const common_1 = require("@riocrypto/common");
15
+ const static_bank_payment_reference_1 = require("../models/static-bank-payment-reference");
16
+ const user_1 = require("../models/user");
17
+ const getOrderFromStaticReference = (reference, amountFiat, mongoose) => __awaiter(void 0, void 0, void 0, function* () {
18
+ // Ensure reference is defined
19
+ if (!reference) {
20
+ throw new Error("Invalid reference. Reference cannot be empty.");
21
+ }
22
+ // Check if first 3 characters are SPR
23
+ if (!reference.startsWith("SPR")) {
24
+ throw new Error("Invalid reference. Reference must start with SPR.");
25
+ }
26
+ const StaticBankPaymentReference = (0, static_bank_payment_reference_1.buildStaticBankPaymentReference)(mongoose);
27
+ const staticBankPaymentReference = yield StaticBankPaymentReference.findOne({
28
+ reference: reference,
29
+ });
30
+ if (!staticBankPaymentReference) {
31
+ throw new Error("Static bank payment reference not found");
32
+ }
33
+ const User = (0, user_1.buildUser)(mongoose);
34
+ const user = yield User.findById(staticBankPaymentReference.userId);
35
+ if (!user) {
36
+ throw new Error("User not found");
37
+ }
38
+ const Order = (0, order_1.buildOrder)(mongoose);
39
+ // Find the oldest order that has status of OrderStatus.WaitingForPayment or OrderStatus.Processing, that has the same amountFiat and fiat as the static bank payment reference
40
+ const order = yield Order.findOne({
41
+ userId: user.id,
42
+ fiat: staticBankPaymentReference.fiat,
43
+ status: {
44
+ $in: [
45
+ common_1.OrderStatus.AwaitingPayment,
46
+ common_1.OrderStatus.AwaitingAsyncPayment,
47
+ common_1.OrderStatus.Processing,
48
+ ],
49
+ },
50
+ amountFiat: amountFiat,
51
+ }).sort({ createdAt: 1 });
52
+ if (!order) {
53
+ throw new Error("Order not found");
54
+ }
55
+ return order;
56
+ });
57
+ exports.getOrderFromStaticReference = getOrderFromStaticReference;
package/build/index.d.ts CHANGED
@@ -116,6 +116,7 @@ export * from "./models/compliance-session";
116
116
  export * from "./models/compliance-bot-chat";
117
117
  export * from "./models/compliance-bot-rule";
118
118
  export * from "./models/compliance-bot-rule-result";
119
+ export * from "./models/static-bank-payment-reference";
119
120
  export * from "./clients/axios-with-logging";
120
121
  export * from "./clients/slack-client";
121
122
  export * from "./clients/fireblocks-client";
@@ -153,3 +154,4 @@ export * from "./helpers/get-processor";
153
154
  export * from "./helpers/get-bulk-payment-from-reference";
154
155
  export * from "./helpers/extract-error-message";
155
156
  export * from "./helpers/get-exchange-rates-with-markups";
157
+ export * from "./helpers/get-order-from-static-reference";
package/build/index.js CHANGED
@@ -132,6 +132,7 @@ __exportStar(require("./models/compliance-session"), exports);
132
132
  __exportStar(require("./models/compliance-bot-chat"), exports);
133
133
  __exportStar(require("./models/compliance-bot-rule"), exports);
134
134
  __exportStar(require("./models/compliance-bot-rule-result"), exports);
135
+ __exportStar(require("./models/static-bank-payment-reference"), exports);
135
136
  __exportStar(require("./clients/axios-with-logging"), exports);
136
137
  __exportStar(require("./clients/slack-client"), exports);
137
138
  __exportStar(require("./clients/fireblocks-client"), exports);
@@ -169,3 +170,4 @@ __exportStar(require("./helpers/get-processor"), exports);
169
170
  __exportStar(require("./helpers/get-bulk-payment-from-reference"), exports);
170
171
  __exportStar(require("./helpers/extract-error-message"), exports);
171
172
  __exportStar(require("./helpers/get-exchange-rates-with-markups"), exports);
173
+ __exportStar(require("./helpers/get-order-from-static-reference"), exports);
@@ -0,0 +1,22 @@
1
+ import { Country } from "@riocrypto/common/build/types/country";
2
+ import { Fiat } from "@riocrypto/common/build/types/fiat";
3
+ import { Mongoose, Model, Document } from "mongoose";
4
+ interface StaticBankPaymentReferenceAttrs {
5
+ createdAt: Date;
6
+ userId: string;
7
+ country: Country;
8
+ fiat: Fiat;
9
+ reference?: string;
10
+ }
11
+ interface StaticBankPaymentReferenceDoc extends Document {
12
+ createdAt: Date;
13
+ userId: string;
14
+ country: Country;
15
+ fiat: Fiat;
16
+ reference: string;
17
+ }
18
+ interface StaticBankPaymentReferenceModel extends Model<StaticBankPaymentReferenceDoc> {
19
+ build(attrs: StaticBankPaymentReferenceAttrs): StaticBankPaymentReferenceDoc;
20
+ }
21
+ declare const buildStaticBankPaymentReference: (mongoose: Mongoose) => StaticBankPaymentReferenceModel;
22
+ export { buildStaticBankPaymentReference, StaticBankPaymentReferenceDoc, StaticBankPaymentReferenceAttrs };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildStaticBankPaymentReference = void 0;
4
+ const buildStaticBankPaymentReference = (mongoose) => {
5
+ // if model is already defined, return it
6
+ if (mongoose.models.StaticBankPaymentReference) {
7
+ return mongoose.model("StaticBankPaymentReference");
8
+ }
9
+ const StaticBankPaymentReferenceSchema = new mongoose.Schema({
10
+ userId: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ country: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ fiat: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ reference: {
23
+ type: String,
24
+ unique: true,
25
+ sparse: true,
26
+ },
27
+ createdAt: {
28
+ type: Date,
29
+ required: true,
30
+ },
31
+ }, {
32
+ toJSON: {
33
+ transform(doc, ret) {
34
+ ret.id = ret._id.valueOf();
35
+ delete ret._id;
36
+ delete ret.__v;
37
+ },
38
+ },
39
+ });
40
+ StaticBankPaymentReferenceSchema.statics.build = (attrs) => {
41
+ return new StaticBankPaymentReference(attrs);
42
+ };
43
+ const StaticBankPaymentReference = mongoose.model("StaticBankPaymentReference", StaticBankPaymentReferenceSchema);
44
+ return StaticBankPaymentReference;
45
+ };
46
+ exports.buildStaticBankPaymentReference = buildStaticBankPaymentReference;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.2699",
3
+ "version": "1.0.2701",
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.3.0",
29
29
  "@google-cloud/storage": "^6.9.5",
30
30
  "@hyperdx/node-opentelemetry": "^0.7.0",
31
- "@riocrypto/common": "^1.0.2498",
31
+ "@riocrypto/common": "^1.0.2502",
32
32
  "@types/express": "^4.17.13",
33
33
  "axios": "^1.7.4",
34
34
  "crypto-js": "^4.2.0",