autosync_backend2 1.2.103 → 1.2.104

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 CHANGED
@@ -14689,6 +14689,54 @@ export declare const app: Elysia<"", {
14689
14689
  };
14690
14690
  };
14691
14691
  };
14692
+ } & {
14693
+ channel: {
14694
+ ":id": {
14695
+ "auth-users": {
14696
+ get: {
14697
+ body: {};
14698
+ params: {
14699
+ id: string;
14700
+ };
14701
+ query: {};
14702
+ headers: {};
14703
+ response: {
14704
+ 200: {
14705
+ user: {
14706
+ id: string;
14707
+ name: string;
14708
+ email: string;
14709
+ emailVerified: boolean;
14710
+ image: string | null;
14711
+ createdAt: Date;
14712
+ updatedAt: Date;
14713
+ companyId: string;
14714
+ branchId: string;
14715
+ kind: "ADMIN" | "COMPANY_ADMIN" | "CUSTOMER" | "INSPECTION";
14716
+ employeeId: string | null;
14717
+ };
14718
+ channel_auth_user: {
14719
+ nmChannelId: string;
14720
+ authUserId: string;
14721
+ enabled: boolean;
14722
+ };
14723
+ }[];
14724
+ 401: "Токен олдсонгүй";
14725
+ 402: "Системийн төлбөр хийгдээгүй байна. 88046194";
14726
+ 422: {
14727
+ type: "validation";
14728
+ on: string;
14729
+ summary?: string;
14730
+ message?: string;
14731
+ found?: unknown;
14732
+ property?: string;
14733
+ expected?: string;
14734
+ };
14735
+ };
14736
+ };
14737
+ };
14738
+ };
14739
+ };
14692
14740
  } & {
14693
14741
  channel: {
14694
14742
  ":id": {
package/dist/index.js CHANGED
@@ -337100,7 +337100,7 @@ class Pocket {
337100
337100
  token = undefined;
337101
337101
  constructor(config5 = {}) {
337102
337102
  this.schema = config5.schema ?? "https";
337103
- this.oauthHost = config5.oauthHost ?? "sso.invescore.mn";
337103
+ this.oauthHost = config5.oauthHost ?? "sso-staging.invescore.mn";
337104
337104
  this.merchantHost = config5.merchantHost ?? "service.invescore.mn/merchant";
337105
337105
  this.realm = config5.realm ?? "invescore";
337106
337106
  this.terminalId = config5.terminalId ?? 82326876454013;
@@ -337112,6 +337112,13 @@ class Pocket {
337112
337112
  return `${this.schema}://${this.merchantHost}/${path}`;
337113
337113
  }
337114
337114
  async makeOAuthRequest(path, params) {
337115
+ logger2.debug({
337116
+ path,
337117
+ params,
337118
+ clientId: env_default.POCKET_CLIENT_ID,
337119
+ clientSecret: env_default.POCKET_CLIENT_SECRET,
337120
+ url: this.getOAuthUrl(path)
337121
+ }, "[Pocket] Making OAuth request");
337115
337122
  const response = await distribution_default.post(this.getOAuthUrl(path), {
337116
337123
  headers: {
337117
337124
  "Content-Type": "application/x-www-form-urlencoded"
@@ -337122,34 +337129,38 @@ class Pocket {
337122
337129
  ...params
337123
337130
  })
337124
337131
  }).json();
337132
+ logger2.debug({ response }, "[Pocket] OAuth response received");
337125
337133
  return response;
337126
337134
  }
337127
337135
  async checkLocalToken() {
337128
- console.log("[Pocket] Checking local token...");
337136
+ logger2.debug("[Pocket] Checking local token...");
337129
337137
  if (this.token) {
337130
- console.log("[Pocket] Token is present in instance.");
337138
+ logger2.debug("[Pocket] Token is present in instance.");
337131
337139
  return;
337132
337140
  }
337133
337141
  const raw = await redis_client_default.get(CACHE_KEY);
337134
- console.log("[Pocket] Fetched raw token from redis:", raw);
337142
+ logger2.debug({ raw }, "[Pocket] Fetched raw token from redis");
337135
337143
  const cached4 = raw ? JSON.parse(raw) : null;
337136
337144
  const isExpired = cached4 ? Date.now() >= cached4.expires_in * 1000 : true;
337137
- console.log(`[Pocket] Token cached: ${!!cached4}, expired: ${isExpired}`);
337145
+ logger2.debug({ hasCached: !!cached4, isExpired }, "[Pocket] Token cache status");
337138
337146
  if (cached4 && !isExpired) {
337139
337147
  this.token = cached4;
337140
- console.log("[Pocket] Using valid cached token.");
337148
+ logger2.debug("[Pocket] Using valid cached token.");
337141
337149
  return;
337142
337150
  }
337143
- console.log("[Pocket] No valid token available, requesting new token.");
337151
+ logger2.debug("[Pocket] No valid token available, requesting new token.");
337144
337152
  const newToken = await this.getToken();
337153
+ logger2.debug({ token: newToken }, "[Pocket] New token obtained");
337145
337154
  this.token = newToken;
337146
337155
  await redis_client_default.set(CACHE_KEY, JSON.stringify(newToken));
337147
- console.log("[Pocket] Obtained new token and updated cache.");
337156
+ logger2.debug({ token: newToken }, "[Pocket] Token set in redis and cache updated");
337148
337157
  }
337149
337158
  async getToken() {
337159
+ logger2.info("[Pocket] Requesting new token...");
337150
337160
  const response = await this.makeOAuthRequest("token", {
337151
337161
  grant_type: "client_credentials"
337152
337162
  });
337163
+ logger2.debug({ response }, "[Pocket] Token response received");
337153
337164
  this.token = response;
337154
337165
  return response;
337155
337166
  }
@@ -337175,13 +337186,13 @@ class Pocket {
337175
337186
  return response;
337176
337187
  }
337177
337188
  async createInvoice(input) {
337178
- console.log("[Pocket] Creating invoice with input:", input);
337189
+ logger2.info({ input }, "[Pocket] Creating invoice");
337179
337190
  await this.checkLocalToken();
337180
- console.log("[Pocket] Sending request to generate invoice:", {
337191
+ logger2.info({
337181
337192
  url: this.getMerchantUrl("v2/invoicing/generate-invoice"),
337182
337193
  token: this.token?.access_token ? "[hidden]" : undefined,
337183
337194
  terminalId: this.terminalId
337184
- });
337195
+ }, "[Pocket] Sending request to generate invoice");
337185
337196
  try {
337186
337197
  const response = await distribution_default.post(this.getMerchantUrl("v2/invoicing/generate-invoice"), {
337187
337198
  headers: {
@@ -337193,10 +337204,10 @@ class Pocket {
337193
337204
  channel: "pos"
337194
337205
  }
337195
337206
  }).json();
337196
- console.log("[Pocket] Generated invoice response:", response);
337207
+ logger2.info({ response }, "[Pocket] Generated invoice response");
337197
337208
  return response;
337198
337209
  } catch (error3) {
337199
- console.error("[Pocket] Error generating invoice:", error3);
337210
+ logger2.error({ error: error3 }, "[Pocket] Error generating invoice");
337200
337211
  throw error3;
337201
337212
  }
337202
337213
  }
@@ -337285,11 +337296,14 @@ class PocketGateway extends PaymentGateway {
337285
337296
  pocket;
337286
337297
  constructor() {
337287
337298
  super();
337288
- this.pocket = new Pocket;
337299
+ this.pocket = new Pocket({
337300
+ oauthHost: "sso-staging.invescore.mn",
337301
+ merchantHost: "service-staging.invescore.mn/merchant",
337302
+ terminalId: 78524356044986
337303
+ });
337289
337304
  }
337290
337305
  async createInvoice(input) {
337291
337306
  const randomKey = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
337292
- console.log(randomKey);
337293
337307
  const payment = await this.savePayment({
337294
337308
  ...input,
337295
337309
  state: "PENDING",
@@ -341499,6 +341513,10 @@ var NotificationChannelLogic;
341499
341513
  deletedAt: new Date().toISOString()
341500
341514
  }).where(eq(nmChannelTable.id, id));
341501
341515
  };
341516
+ NotificationChannelLogic.selectAuthUsers = async (id) => {
341517
+ const users = await db_default.select().from(nmChannelAuthUserTable).innerJoin(user, eq(user.id, nmChannelAuthUserTable.authUserId)).where(eq(nmChannelAuthUserTable.nmChannelId, id));
341518
+ return users;
341519
+ };
341502
341520
  })(NotificationChannelLogic ||= {});
341503
341521
  var logic_default48 = NotificationChannelLogic;
341504
341522
 
@@ -341531,7 +341549,7 @@ var channelRoutes = new Elysia({
341531
341549
  body: model_default46.create
341532
341550
  }).guard({
341533
341551
  params: IdSchema
341534
- }).put("/:id", async ({ params, body }) => logic_default48.update(params.id, body), {
341552
+ }).get("/:id/auth-users", async ({ params }) => logic_default48.selectAuthUsers(params.id)).put("/:id", async ({ params, body }) => logic_default48.update(params.id, body), {
341535
341553
  body: model_default46.update
341536
341554
  }).delete("/:id", async ({ params }) => logic_default48.remove(params.id));
341537
341555
  var channel_default = channelRoutes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autosync_backend2",
3
- "version": "1.2.103",
3
+ "version": "1.2.104",
4
4
  "module": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",