mp-front-cli 0.0.89 → 0.0.91

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.
@@ -1,31 +1,67 @@
1
- import { C as Z } from "./custom-redis-bee66564.js";
2
- import { u as $ } from "./stringify-788d71a0.js";
1
+ var W = Object.defineProperty;
2
+ var Y = (a, s, r) => s in a ? W(a, s, { enumerable: !0, configurable: !0, writable: !0, value: r }) : a[s] = r;
3
+ var A = (a, s, r) => (Y(a, typeof s != "symbol" ? s + "" : s, r), r);
4
+ import { C as R, a as ee } from "./custom-cache-8c806250.js";
5
+ import { CustomEncrypter as te } from "./mp-front-cli-encrypter.es.js";
6
+ import { u as ne, a as se } from "./v5-cbd101aa.js";
3
7
  import "ioredis";
4
- let x;
5
- const v = new Uint8Array(16);
6
- function C() {
7
- if (!x && (x = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !x))
8
+ import "node-jose";
9
+ import "crypto";
10
+ import "./mp-front-cli-encoder.es.js";
11
+ import "./mp-front-cli-logger.es.js";
12
+ let K;
13
+ const re = new Uint8Array(16);
14
+ function ie() {
15
+ if (!K && (K = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !K))
8
16
  throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
9
- return x(v);
17
+ return K(re);
10
18
  }
11
- const G = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), A = {
12
- randomUUID: G
19
+ const ae = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), B = {
20
+ randomUUID: ae
13
21
  };
14
- function H(c, s, r) {
15
- if (A.randomUUID && !s && !c)
16
- return A.randomUUID();
17
- c = c || {};
18
- const i = c.random || (c.rng || C)();
22
+ function oe(a, s, r) {
23
+ if (B.randomUUID && !s && !a)
24
+ return B.randomUUID();
25
+ a = a || {};
26
+ const i = a.random || (a.rng || ie)();
19
27
  if (i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, s) {
20
28
  r = r || 0;
21
- for (let u = 0; u < 16; ++u)
22
- s[r + u] = i[u];
29
+ for (let y = 0; y < 16; ++y)
30
+ s[r + y] = i[y];
23
31
  return s;
24
32
  }
25
- return $(i);
33
+ return ne(i);
26
34
  }
27
- const L = process.env.PREFIX_LOGIN, B = process.env.TIMEOUT_SESSION_MINUTES, q = {
28
- baseKeyPrefix: `${L}:`,
35
+ const ce = process.env.TIMEOUT_SESSION_MINUTES, ue = "619abad7-0dea-46c5-aa49-fc1ec872a684", de = "PF:TERMINAL:", O = "TERMINAL";
36
+ class ye extends te {
37
+ constructor() {
38
+ super(...arguments);
39
+ A(this, "redisCacheHandler", new R());
40
+ A(this, "getIdApi", (r) => {
41
+ const i = se(r, ue);
42
+ return `${de}${i}`;
43
+ });
44
+ }
45
+ async saveTerminalData(r, i) {
46
+ return this.redisCacheHandler.setRedisState({
47
+ idApi: this.getIdApi(r),
48
+ idData: O,
49
+ body: i,
50
+ expire: ce
51
+ });
52
+ }
53
+ async getTerminalData(r) {
54
+ return this.redisCacheHandler.getRedisState(this.getIdApi(r), O).then(({ data: i }) => (this.logDebug("getTerminal", JSON.stringify(i)), i)).catch((i) => (this.logError("Error getTerminal", JSON.stringify(i)), null));
55
+ }
56
+ async deleteTerminalData(r) {
57
+ return this.redisCacheHandler.deleteRedisState(
58
+ this.getIdApi(r),
59
+ O
60
+ );
61
+ }
62
+ }
63
+ const d = process.env.PREFIX_LOGIN, b = process.env.TIMEOUT_SESSION_MINUTES, c = new R(), le = {
64
+ baseKeyPrefix: `${d}:`,
29
65
  userKeyPrefix: "user:",
30
66
  accountKeyPrefix: "account:",
31
67
  accountByUserIdPrefix: "account:user:",
@@ -33,142 +69,153 @@ const L = process.env.PREFIX_LOGIN, B = process.env.TIMEOUT_SESSION_MINUTES, q =
33
69
  sessionByUserIdPrefix: "session:user:",
34
70
  userByEmailKeyPrefix: "user:email:",
35
71
  verificationKeyPrefix: "verification:",
36
- expire: B * 60
37
- }, z = (c) => {
38
- for (const s in c)
72
+ expire: b * 60
73
+ }, fe = (a) => {
74
+ for (const s in a)
39
75
  return !1;
40
76
  return !0;
41
- }, J = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/, Q = (c) => c && J.test(c) && !Number.isNaN(Date.parse(c));
42
- function te(c = { expire: B * 60 }) {
43
- const s = Z, r = {
44
- ...q,
45
- ...c
46
- }, i = r.baseKeyPrefix || "", u = i + r.userKeyPrefix, b = i + r.userByEmailKeyPrefix, k = i + r.accountKeyPrefix, T = i + r.accountByUserIdPrefix, D = i + r.sessionKeyPrefix, V = i + r.sessionByUserIdPrefix, j = i + r.verificationKeyPrefix, U = (e) => b + e, p = (e) => u + e, K = (e) => k + e, f = (e) => T + e, m = (e, t) => `${t}:${e}`, I = (e) => D + e, l = (e) => V + e, g = (e) => j + e, w = async (e, t) => {
47
- const n = Object.entries(t).reduce((o, [S, a]) => (o[S] = a instanceof Date ? a.toISOString() : a, o), {});
77
+ }, we = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/, me = (a) => a && we.test(a) && !Number.isNaN(Date.parse(a));
78
+ function he(a = { expire: b * 60 }) {
79
+ const s = ee, r = {
80
+ ...le,
81
+ ...a
82
+ }, i = r.baseKeyPrefix || "", y = i + r.userKeyPrefix, k = i + r.userByEmailKeyPrefix, C = i + r.accountKeyPrefix, M = i + r.accountByUserIdPrefix, V = i + r.sessionKeyPrefix, _ = i + r.sessionByUserIdPrefix, j = i + r.verificationKeyPrefix, U = (e) => k + e, x = (e) => y + e, S = (e) => C + e, I = (e) => M + e, w = (e, t) => `${t}:${e}`, E = (e) => V + e, g = (e) => _ + e, P = (e) => j + e, p = async (e, t) => {
83
+ const n = Object.entries(t).reduce((o, [f, u]) => (o[f] = u instanceof Date ? u.toISOString() : u, o), {});
48
84
  await s.hset(e, n), await s.expire(e, r.expire);
49
- }, y = async (e) => {
85
+ }, m = async (e) => {
50
86
  const t = await s.hgetall(e);
51
- return !t || z(t) ? null : Object.entries(t).reduce((o, [S, a]) => (o[S] = Q(a) ? new Date(a) : a, o), {});
52
- }, E = async (e, t) => (await w(p(e), t), t.email && await s.set(
87
+ return !t || fe(t) ? null : Object.entries(t).reduce((o, [f, u]) => (o[f] = me(u) ? new Date(u) : u, o), {});
88
+ }, D = async (e, t) => (await p(x(e), t), t.email && await s.set(
53
89
  U(t.email),
54
90
  e,
55
91
  "EX",
56
92
  r.expire
57
- ), t), d = async (e) => {
58
- const t = await y(p(e));
93
+ ), t), l = async (e) => {
94
+ const t = await m(x(e));
59
95
  return t ? { ...t } : null;
60
- }, N = async (e, t) => {
61
- const n = K(e);
62
- await w(n, t), await s.set(
63
- f(t.userId),
96
+ }, H = async (e, t) => {
97
+ const n = S(e);
98
+ await p(n, t), await s.set(
99
+ I(t.userId),
64
100
  n,
65
101
  "EX",
66
102
  r.expire
67
103
  );
68
- }, R = async (e) => {
69
- const t = await y(K(e));
104
+ }, T = async (e) => {
105
+ const t = await m(S(e));
70
106
  return t ? { ...t } : null;
71
- }, h = async (e) => {
72
- const t = K(e), n = await y(t);
107
+ }, G = async (e) => {
108
+ const t = S(e), n = await m(t);
73
109
  if (!n)
74
110
  return null;
75
- await s.hdel(t), await s.del(f(n.userId));
76
- }, O = async (e, t) => {
77
- const n = I(e);
78
- return await w(n, t), await s.set(
79
- l(t.userId),
111
+ await s.hdel(t), await s.del(I(n.userId));
112
+ }, N = async (e, t) => {
113
+ const n = E(e);
114
+ return await p(n, t), await s.set(
115
+ g(t.userId),
80
116
  n,
81
117
  "EX",
82
118
  r.expire
83
119
  ), t;
84
- }, P = async (e) => {
85
- const t = await y(I(e));
120
+ }, h = async (e) => {
121
+ const t = await m(E(e));
86
122
  return t ? {
87
123
  id: t.id,
88
124
  ...t
89
125
  } : null;
90
- }, _ = async (e) => {
91
- const t = await P(e);
126
+ }, X = async (e) => {
127
+ const t = await h(e);
92
128
  if (!t)
93
129
  return null;
94
- const n = I(e);
95
- await s.del(n), await s.del(l(t.userId));
96
- }, X = async (e, t) => {
97
- const n = g(e);
98
- return await w(n, t), t;
99
- }, M = async (e) => {
100
- const t = g(e), n = await y(t);
130
+ const n = E(e);
131
+ await s.del(n), await s.del(g(t.userId));
132
+ }, F = async (e, t) => {
133
+ const n = P(e);
134
+ return await p(n, t), t;
135
+ }, L = async (e) => {
136
+ const t = P(e), n = await m(t);
101
137
  return n ? { identifier: n.identifier, ...n } : null;
102
- }, F = async (e) => {
103
- const t = g(e);
138
+ }, Z = async (e) => {
139
+ const t = P(e);
104
140
  await s.del(t);
141
+ }, v = async (e, t) => {
142
+ const n = await T(w(e, t)), o = await c.simpleGet(
143
+ `${d}:account:user:${n == null ? void 0 : n.userId}`
144
+ ) ?? "", f = `${d}:user:${n == null ? void 0 : n.userId}`, u = await c.simpleHGet(f, "email") ?? "", $ = await c.simpleHGet(o, "cveUsuario") ?? "", J = `${d}:account:user:${n == null ? void 0 : n.userId}`, z = `${d}:session:user:${n == null ? void 0 : n.userId}`, q = await c.simpleGet(
145
+ `${d}:session:user:${n == null ? void 0 : n.userId}`
146
+ ) ?? "", Q = `${d}:user:email:${u}`;
147
+ await c.deleteKey(o), await c.deleteKey(J), await c.deleteKey(z), await c.deleteKey(q), await c.deleteKey(Q), await c.deleteKey(f), await c.deleteKey($), await new ye().deleteTerminalData($);
105
148
  };
106
149
  return {
107
150
  async createUser(e) {
108
- const t = H();
109
- return await E(t, { ...e, id: t });
151
+ const t = oe();
152
+ return await D(t, { ...e, id: t });
110
153
  },
111
- getUser: d,
154
+ getUser: l,
112
155
  async getUserByEmail(e) {
113
156
  const t = await s.get(U(e));
114
- return t ? await d(t) : null;
157
+ return t ? await l(t) : null;
115
158
  },
116
159
  async getUserByAccount({ providerAccountId: e, provider: t }) {
117
- const n = await R(
118
- m(e, t)
160
+ const n = await T(
161
+ w(e, t)
119
162
  );
120
- return n ? await d(n.userId) : null;
163
+ console.log("🚀 ~ getUserByAccount ~ account:", n), n && await v(e, t);
164
+ const o = await T(
165
+ w(e, t)
166
+ );
167
+ return console.log("🚀 ~ getUserByAccount ~ account:", o), o ? await l(o.userId) : null;
121
168
  },
122
169
  async updateUser(e) {
123
- const t = e.id, n = await d(t);
124
- return await E(t, { ...n, ...e });
170
+ const t = e.id, n = await l(t);
171
+ return await D(t, { ...n, ...e });
125
172
  },
126
173
  async deleteUser(e) {
127
- const t = await d(e);
174
+ const t = await l(e);
128
175
  if (!t)
129
176
  return null;
130
- const n = await s.get(f(e)), o = await s.get(l(e));
177
+ const n = await s.get(I(e)), o = await s.get(g(e));
131
178
  await s.del(
132
179
  U(t.email),
133
- f(e),
134
- l(e)
135
- ), o && await s.del(o), n && await s.del(n), await s.del(p(e));
180
+ I(e),
181
+ g(e)
182
+ ), o && await s.del(o), n && await s.del(n), await s.del(x(e));
136
183
  },
137
184
  async linkAccount(e) {
138
- const t = m(e.providerAccountId, e.provider);
139
- return await N(t, { ...e, id: t });
185
+ const t = w(e.providerAccountId, e.provider);
186
+ return await H(t, { ...e, id: t });
140
187
  },
141
188
  async unlinkAccount({ providerAccountId: e, provider: t }) {
142
- const n = m(e, t);
143
- await h(n);
189
+ const n = w(e, t);
190
+ await G(n);
144
191
  },
145
192
  async createSession(e) {
146
193
  const t = e.sessionToken;
147
- return await O(t, { ...e, id: t });
194
+ return await N(t, { ...e, id: t });
148
195
  },
149
196
  async getSessionAndUser(e) {
150
- const n = await P(e);
197
+ const n = await h(e);
151
198
  if (!n)
152
199
  return null;
153
- const o = await d(n.userId);
200
+ const o = await l(n.userId);
154
201
  return o ? { session: n, user: o } : null;
155
202
  },
156
203
  async updateSession(e) {
157
- const t = e.sessionToken, n = await P(t);
158
- return n ? await O(t, { ...n, ...e }) : null;
204
+ const t = e.sessionToken, n = await h(t);
205
+ return n ? await N(t, { ...n, ...e }) : null;
159
206
  },
160
- deleteSession: _,
207
+ deleteSession: X,
161
208
  async createVerificationToken(e) {
162
209
  const t = e.identifier;
163
- return await X(t, e), e;
210
+ return await F(t, e), e;
164
211
  },
165
212
  async useVerificationToken(e) {
166
- const t = e.identifier, n = await M(t);
167
- return !n || e.token !== n.token ? null : (await F(t), n);
213
+ const t = e.identifier, n = await L(t);
214
+ return !n || e.token !== n.token ? null : (await Z(t), n);
168
215
  }
169
216
  };
170
217
  }
171
218
  export {
172
- te as IORedisAdapter,
173
- q as defaultOptions
219
+ he as IORedisAdapter,
220
+ le as defaultOptions
174
221
  };
@@ -1,5 +1,6 @@
1
- import { ApiMiddleware as n, ErrorCatalog as x, FetchServiceBE as E, FetchServiceFE as F } from "./mp-front-cli-core.es.js";
2
- import { LoadingHandler as S, MessageHandler as f, RxSubjectManager as h } from "./mp-front-cli-utils-rxjs.es.js";
1
+ import { ApiMiddleware as g, ErrorCatalog as l, FetchServiceBE as x, FetchServiceFE as f } from "./mp-front-cli-core.es.js";
2
+ import { LoadingHandler as v, MessageHandler as E, RxSubjectManager as F } from "./mp-front-cli-utils-rxjs.es.js";
3
+ import { S as h } from "./index-def0b487.js";
3
4
  import "i18next";
4
5
  import "./index-d4f88744.js";
5
6
  import "./mp-front-cli-logger.es.js";
@@ -8,14 +9,15 @@ import "./mp-front-cli-encrypter.es.js";
8
9
  import "node-jose";
9
10
  import "crypto";
10
11
  import "./mp-front-cli-encoder.es.js";
11
- import "./custom-header-b6432556.js";
12
- import "./stringify-788d71a0.js";
12
+ import "./mp-front-cli-header.es.js";
13
+ import "./v5-cbd101aa.js";
13
14
  export {
14
- n as ApiMiddleware,
15
- x as ErrorCatalog,
16
- E as FetchServiceBE,
17
- F as FetchServiceFE,
18
- S as LoadingHandler,
19
- f as MessageHandler,
20
- h as RxSubjectManager
15
+ g as ApiMiddleware,
16
+ l as ErrorCatalog,
17
+ x as FetchServiceBE,
18
+ f as FetchServiceFE,
19
+ v as LoadingHandler,
20
+ E as MessageHandler,
21
+ F as RxSubjectManager,
22
+ h as ServiceToken
21
23
  };
@@ -1,87 +1,11 @@
1
- var p = Object.defineProperty;
2
- var S = (n, r, t) => r in n ? p(n, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[r] = t;
3
- var E = (n, r, t) => (S(n, typeof r != "symbol" ? r + "" : r, t), t);
4
- import { CustomEncrypter as m } from "./mp-front-cli-encrypter.es.js";
5
- import { C as R } from "./custom-redis-bee66564.js";
1
+ import "./mp-front-cli-encrypter.es.js";
2
+ import { C as s, R as C } from "./custom-cache-8c806250.js";
6
3
  import "node-jose";
7
4
  import "crypto";
8
5
  import "./mp-front-cli-encoder.es.js";
9
6
  import "./mp-front-cli-logger.es.js";
10
7
  import "ioredis";
11
- const a = process.env.TIMEOUT_SESSION_MINUTES;
12
- var d = /* @__PURE__ */ ((n) => (n.NOT_REFRESH = "NOT_REFRESH", n.REFRESH = "REFRESH", n))(d || {});
13
- class O extends m {
14
- constructor() {
15
- super(...arguments);
16
- E(this, "initClient", R);
17
- }
18
- getRootNode(t) {
19
- return this.initClient.get(t);
20
- }
21
- async getEntryPoint(t) {
22
- try {
23
- return await this.getRootNode(t);
24
- } catch {
25
- throw new Error("Not found entry point");
26
- }
27
- }
28
- setEntryPoint(t, i, e) {
29
- const s = typeof i == "string" ? i : JSON.stringify(i);
30
- this.initClient.set(t, s, "EX", 60 * e);
31
- }
32
- async getRedisState(t, i) {
33
- const e = `${t}:${this.generateSHA(i)}`, s = await this.getEntryPoint(e), c = await this.isEncrypted(s) ? await this.decrypt(s ?? "") : JSON.parse(s), o = Number(c == null ? void 0 : c.expires_in);
34
- return o > 0 && this.ttl(e, o * 60), { sha: e, data: c };
35
- }
36
- async deleteRedisState(t, i) {
37
- const e = `${t}:${this.generateSHA(i)}`;
38
- this.initClient.del(e);
39
- }
40
- async setRedisState({
41
- idApi: t,
42
- idData: i,
43
- body: e,
44
- expire: s,
45
- encrypted: h = !1,
46
- refresh: c = "REFRESH"
47
- /* REFRESH */
48
- }) {
49
- const o = `${t}:${this.generateSHA(i)}`, l = { expires_in: c === "REFRESH" ? s : 0, ...e };
50
- if (h) {
51
- const y = await this.encrypt(l);
52
- return this.setEntryPoint(o, y, s), o;
53
- }
54
- return this.setEntryPoint(o, l, s), o;
55
- }
56
- async statusHost() {
57
- return new Promise((t, i) => {
58
- this.initClient.on("error", (e) => {
59
- this.killRedis(), i(e);
60
- }), this.initClient.on("connect", () => {
61
- t("success");
62
- });
63
- });
64
- }
65
- killRedis() {
66
- this.initClient.disconnect();
67
- }
68
- deleteKey(t) {
69
- this.initClient.del(t);
70
- }
71
- ttl(t, i) {
72
- this.initClient.expire(t, i);
73
- }
74
- simpleGet(t) {
75
- return this.ttl(t, a * 60), this.initClient.get(t);
76
- }
77
- simpleHGet(t, i) {
78
- return this.ttl(t, a * 60), this.initClient.hget(t, i);
79
- }
80
- simpleHSet(t, i, e) {
81
- return this.initClient.hset(t, i, e);
82
- }
83
- }
84
8
  export {
85
- O as CustomCache,
86
- d as RefreshState
9
+ s as CustomCache,
10
+ C as RefreshState
87
11
  };