autosync_backend2 1.2.105 → 1.2.106
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/dist/index.d.ts +66 -18
- package/dist/index.js +37 -25
- package/package.json +1 -1
- package/dist/test.d.ts +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -6047,28 +6047,77 @@ export declare const app: Elysia<"", {
|
|
|
6047
6047
|
params: {};
|
|
6048
6048
|
query: {};
|
|
6049
6049
|
headers: {};
|
|
6050
|
+
response: {
|
|
6051
|
+
200: {};
|
|
6052
|
+
401: "Токен олдсонгүй";
|
|
6053
|
+
402: "Системийн төлбөр хийгдээгүй байна. 88046194";
|
|
6054
|
+
422: {
|
|
6055
|
+
type: "validation";
|
|
6056
|
+
on: string;
|
|
6057
|
+
summary?: string;
|
|
6058
|
+
message?: string;
|
|
6059
|
+
found?: unknown;
|
|
6060
|
+
property?: string;
|
|
6061
|
+
expected?: string;
|
|
6062
|
+
};
|
|
6063
|
+
};
|
|
6064
|
+
};
|
|
6065
|
+
};
|
|
6066
|
+
};
|
|
6067
|
+
} & {
|
|
6068
|
+
payment: {
|
|
6069
|
+
"cabpay-data": {
|
|
6070
|
+
get: {
|
|
6071
|
+
body: {};
|
|
6072
|
+
params: {};
|
|
6073
|
+
query: {
|
|
6074
|
+
date?: string | undefined;
|
|
6075
|
+
companyId?: string | undefined;
|
|
6076
|
+
};
|
|
6077
|
+
headers: {};
|
|
6050
6078
|
response: {
|
|
6051
6079
|
200: {
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6080
|
+
payments: {
|
|
6081
|
+
cp_order: {
|
|
6082
|
+
companyId: string;
|
|
6083
|
+
companyBranchId: string;
|
|
6084
|
+
customerId: string | null;
|
|
6085
|
+
vehicleId: string | null;
|
|
6086
|
+
orderId: string;
|
|
6087
|
+
state: "CREATED" | "PROGRESSING" | "COMPLETE";
|
|
6088
|
+
isNoat: boolean | null;
|
|
6089
|
+
timeCompleted: string | null;
|
|
6090
|
+
km: number;
|
|
6091
|
+
type: "Service" | "ProductSell";
|
|
6092
|
+
description: string | null;
|
|
6093
|
+
id: string;
|
|
6094
|
+
createdAt: string;
|
|
6095
|
+
updatedAt: string;
|
|
6096
|
+
deletedAt: string | null;
|
|
6097
|
+
oldId: number | null;
|
|
6098
|
+
};
|
|
6099
|
+
cp_order_payment: {
|
|
6100
|
+
cpOrderId: string;
|
|
6101
|
+
paymentPackageId: string | null;
|
|
6102
|
+
paymentMethod: "CASH" | "BANK_TRANSFER" | "POS_TERMINAL" | "PAYMENT_PACKAGE" | "CARD";
|
|
6103
|
+
paymentChannel: string;
|
|
6104
|
+
amount: number;
|
|
6105
|
+
state: "PENDING" | "EXPIRED" | "PAID" | "FAILED" | "REFUNDED" | "NOT_PAID" | "DECLINED" | "CANCELED" | "REFUNDING";
|
|
6106
|
+
invoiceNumber: string | null;
|
|
6107
|
+
description: string | null;
|
|
6108
|
+
pocketOrderNumber: string | null;
|
|
6109
|
+
id: string;
|
|
6110
|
+
createdAt: string;
|
|
6111
|
+
updatedAt: string;
|
|
6112
|
+
deletedAt: string | null;
|
|
6113
|
+
oldId: number | null;
|
|
6114
|
+
};
|
|
6115
|
+
}[];
|
|
6116
|
+
totalAmount: string | number;
|
|
6068
6117
|
};
|
|
6069
|
-
400: string;
|
|
6070
6118
|
401: "Токен олдсонгүй";
|
|
6071
6119
|
402: "Системийн төлбөр хийгдээгүй байна. 88046194";
|
|
6120
|
+
403: "Хандах эрхгүй байна.";
|
|
6072
6121
|
422: {
|
|
6073
6122
|
type: "validation";
|
|
6074
6123
|
on: string;
|
|
@@ -6078,7 +6127,6 @@ export declare const app: Elysia<"", {
|
|
|
6078
6127
|
property?: string;
|
|
6079
6128
|
expected?: string;
|
|
6080
6129
|
};
|
|
6081
|
-
500: "Сервер алдаа гарлаа";
|
|
6082
6130
|
};
|
|
6083
6131
|
};
|
|
6084
6132
|
};
|
package/dist/index.js
CHANGED
|
@@ -338365,19 +338365,12 @@ class Pocket {
|
|
|
338365
338365
|
this.terminalId = config5.terminalId ?? 82326876454013;
|
|
338366
338366
|
}
|
|
338367
338367
|
getOAuthUrl(path) {
|
|
338368
|
-
return `${this.schema}://${this.oauthHost}/
|
|
338368
|
+
return `${this.schema}://${this.oauthHost}/realms/${this.realm}/protocol/openid-connect/${path}`;
|
|
338369
338369
|
}
|
|
338370
338370
|
getMerchantUrl(path) {
|
|
338371
338371
|
return `${this.schema}://${this.merchantHost}/${path}`;
|
|
338372
338372
|
}
|
|
338373
338373
|
async makeOAuthRequest(path, params) {
|
|
338374
|
-
logger2.debug({
|
|
338375
|
-
path,
|
|
338376
|
-
params,
|
|
338377
|
-
clientId: env_default.POCKET_CLIENT_ID,
|
|
338378
|
-
clientSecret: env_default.POCKET_CLIENT_SECRET,
|
|
338379
|
-
url: this.getOAuthUrl(path)
|
|
338380
|
-
}, "[Pocket] Making OAuth request");
|
|
338381
338374
|
const response = await distribution_default.post(this.getOAuthUrl(path), {
|
|
338382
338375
|
headers: {
|
|
338383
338376
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -338392,27 +338385,24 @@ class Pocket {
|
|
|
338392
338385
|
return response;
|
|
338393
338386
|
}
|
|
338394
338387
|
async checkLocalToken() {
|
|
338395
|
-
logger2.debug("[Pocket] Checking local token...");
|
|
338396
338388
|
if (this.token) {
|
|
338397
|
-
logger2.debug("[Pocket] Token is present in instance.");
|
|
338398
338389
|
return;
|
|
338399
338390
|
}
|
|
338400
338391
|
const raw = await redis_client_default.get(CACHE_KEY);
|
|
338401
|
-
logger2.debug({ raw }, "[Pocket] Fetched raw token from redis");
|
|
338402
338392
|
const cached4 = raw ? JSON.parse(raw) : null;
|
|
338403
|
-
|
|
338404
|
-
|
|
338393
|
+
let isExpired = true;
|
|
338394
|
+
if (cached4) {
|
|
338395
|
+
const payload = JSON.parse(Buffer.from(cached4.access_token.split(".")[1], "base64").toString());
|
|
338396
|
+
const now = Math.floor(Date.now() / 1000);
|
|
338397
|
+
isExpired = payload.exp <= now;
|
|
338398
|
+
}
|
|
338405
338399
|
if (cached4 && !isExpired) {
|
|
338406
338400
|
this.token = cached4;
|
|
338407
|
-
logger2.debug("[Pocket] Using valid cached token.");
|
|
338408
338401
|
return;
|
|
338409
338402
|
}
|
|
338410
|
-
logger2.debug("[Pocket] No valid token available, requesting new token.");
|
|
338411
338403
|
const newToken = await this.getToken();
|
|
338412
|
-
logger2.debug({ token: newToken }, "[Pocket] New token obtained");
|
|
338413
338404
|
this.token = newToken;
|
|
338414
338405
|
await redis_client_default.set(CACHE_KEY, JSON.stringify(newToken));
|
|
338415
|
-
logger2.debug({ token: newToken }, "[Pocket] Token set in redis and cache updated");
|
|
338416
338406
|
}
|
|
338417
338407
|
async getToken() {
|
|
338418
338408
|
logger2.info("[Pocket] Requesting new token...");
|
|
@@ -338447,10 +338437,10 @@ class Pocket {
|
|
|
338447
338437
|
async createInvoice(input) {
|
|
338448
338438
|
logger2.info({ input }, "[Pocket] Creating invoice");
|
|
338449
338439
|
await this.checkLocalToken();
|
|
338450
|
-
logger2.
|
|
338451
|
-
|
|
338452
|
-
|
|
338453
|
-
|
|
338440
|
+
logger2.debug({ token: this.token?.access_token }, "[Pocket] Token");
|
|
338441
|
+
logger2.debug({ terminalId: this.terminalId }, "[Pocket] Terminal ID");
|
|
338442
|
+
logger2.debug({
|
|
338443
|
+
url: this.getMerchantUrl("v2/invoicing/generate-invoice")
|
|
338454
338444
|
}, "[Pocket] Sending request to generate invoice");
|
|
338455
338445
|
try {
|
|
338456
338446
|
const response = await distribution_default.post(this.getMerchantUrl("v2/invoicing/generate-invoice"), {
|
|
@@ -338466,7 +338456,10 @@ class Pocket {
|
|
|
338466
338456
|
logger2.info({ response }, "[Pocket] Generated invoice response");
|
|
338467
338457
|
return response;
|
|
338468
338458
|
} catch (error3) {
|
|
338469
|
-
|
|
338459
|
+
if (isHTTPError(error3)) {
|
|
338460
|
+
logger2.error({ error: error3 }, "[Pocket] Error generating invoice");
|
|
338461
|
+
throw status(error3.response.status, error3.message);
|
|
338462
|
+
}
|
|
338470
338463
|
throw error3;
|
|
338471
338464
|
}
|
|
338472
338465
|
}
|
|
@@ -338556,9 +338549,9 @@ class PocketGateway extends PaymentGateway {
|
|
|
338556
338549
|
constructor() {
|
|
338557
338550
|
super();
|
|
338558
338551
|
this.pocket = new Pocket({
|
|
338559
|
-
oauthHost: "
|
|
338552
|
+
oauthHost: "sso25-staging.invescore.mn",
|
|
338560
338553
|
merchantHost: "service-staging.invescore.mn/merchant",
|
|
338561
|
-
terminalId:
|
|
338554
|
+
terminalId: 82760328141709
|
|
338562
338555
|
});
|
|
338563
338556
|
}
|
|
338564
338557
|
async createInvoice(input) {
|
|
@@ -339243,6 +339236,10 @@ var CrmCpOrderPaymentLogic;
|
|
|
339243
339236
|
if (err2 instanceof Error) {
|
|
339244
339237
|
return status("Bad Request", err2.message);
|
|
339245
339238
|
}
|
|
339239
|
+
logger2.error({ err: err2 }, "[Pocket] Error creating invoice");
|
|
339240
|
+
if (err2 instanceof status) {
|
|
339241
|
+
return err2;
|
|
339242
|
+
}
|
|
339246
339243
|
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
339247
339244
|
}
|
|
339248
339245
|
};
|
|
@@ -339257,6 +339254,19 @@ var CrmCpOrderPaymentLogic;
|
|
|
339257
339254
|
return status("Internal Server Error", "\u0421\u0435\u0440\u0432\u0435\u0440 \u0430\u043B\u0434\u0430\u0430 \u0433\u0430\u0440\u043B\u0430\u0430");
|
|
339258
339255
|
}
|
|
339259
339256
|
};
|
|
339257
|
+
CrmCpOrderPaymentLogic.getUbPayData = async (query) => {
|
|
339258
|
+
const filter = and(eq(crmCpOrderTable.companyId, query.companyId), eq(crmCpOrderPaymentTable.state, "PAID"), eq(crmCpOrderPaymentTable.paymentChannel, "UBPAY"));
|
|
339259
|
+
const [payments, total] = await Promise.all([
|
|
339260
|
+
db_default.select().from(crmCpOrderPaymentTable).innerJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderPaymentTable.cpOrderId)).where(filter),
|
|
339261
|
+
db_default.select({
|
|
339262
|
+
total: sum(crmCpOrderPaymentTable.amount)
|
|
339263
|
+
}).from(crmCpOrderPaymentTable).innerJoin(crmCpOrderTable, eq(crmCpOrderTable.id, crmCpOrderPaymentTable.cpOrderId)).where(filter)
|
|
339264
|
+
]);
|
|
339265
|
+
return {
|
|
339266
|
+
payments,
|
|
339267
|
+
totalAmount: total[0]?.total ?? 0
|
|
339268
|
+
};
|
|
339269
|
+
};
|
|
339260
339270
|
CrmCpOrderPaymentLogic.getPocketData = async (query) => {
|
|
339261
339271
|
const filter = and(eq(crmCpOrderTable.companyId, query.companyId).if(query.companyId), eq(crmCpOrderPaymentTable.state, "PAID"), eq(sql3`DATE(${crmCpOrderPaymentTable.createdAt})`, query.date).if(query.date), eq(crmCpOrderPaymentTable.paymentChannel, "POCKET"));
|
|
339262
339272
|
const [payments, total] = await Promise.all([
|
|
@@ -340131,6 +340141,8 @@ var paymentRoutes2 = new Elysia({
|
|
|
340131
340141
|
auth: true
|
|
340132
340142
|
}).guard({
|
|
340133
340143
|
userKind: "ADMIN"
|
|
340144
|
+
}).get("/cabpay-data", async ({ query }) => logic_default22.getUbPayData(query), {
|
|
340145
|
+
query: model_default20.getPocketData
|
|
340134
340146
|
}).get("/pocket-data", async ({ query }) => logic_default22.getPocketData(query), {
|
|
340135
340147
|
query: model_default20.getPocketData
|
|
340136
340148
|
}).get("/info", async () => logic_default22.selectPaymentInfo()).post("/info", async ({ body }) => logic_default22.createPaymentInfo(body), {
|
|
@@ -340165,7 +340177,7 @@ var cpOrderRoutes = new Elysia({
|
|
|
340165
340177
|
body: model_default19.createSell
|
|
340166
340178
|
}).post("/package", async ({ body, user: user2 }) => logic_default24.addPackage(body, user2), {
|
|
340167
340179
|
body: model_default19.addPackage
|
|
340168
|
-
}).delete("package/:id", async ({ params: { id }, user: user2 }) => logic_default24.removePackage(id, user2), {
|
|
340180
|
+
}).delete("/package/:id", async ({ params: { id }, user: user2 }) => logic_default24.removePackage(id, user2), {
|
|
340169
340181
|
params: IdSchema
|
|
340170
340182
|
}).post("/complete", async ({ user: user2, body }) => logic_default24.complete(body, user2), {
|
|
340171
340183
|
body: model_default19.complete
|
package/package.json
CHANGED
package/dist/test.d.ts
DELETED
|
File without changes
|