@mp-front/common 0.0.1
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/README.md +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/redis-adapter.d.ts +15 -0
- package/dist/adapters/redis-adapter.d.ts.map +1 -0
- package/dist/auth/authorization-service.d.ts +11 -0
- package/dist/auth/authorization-service.d.ts.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/authorization-service-DE-hoYji.js +48 -0
- package/dist/authorization-service-DkLS18Us.cjs +1 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/session-handler/constants/index.d.ts +6 -0
- package/dist/cache/session-handler/constants/index.d.ts.map +1 -0
- package/dist/cache/session-handler/index.d.ts +2 -0
- package/dist/cache/session-handler/index.d.ts.map +1 -0
- package/dist/cache/session-handler/session-cache.d.ts +52 -0
- package/dist/cache/session-handler/session-cache.d.ts.map +1 -0
- package/dist/cache/session-handler/types/index.d.ts +37 -0
- package/dist/cache/session-handler/types/index.d.ts.map +1 -0
- package/dist/cache/terminal-handler/constants/environments.d.ts +3 -0
- package/dist/cache/terminal-handler/constants/environments.d.ts.map +1 -0
- package/dist/cache/terminal-handler/constants/identifier.d.ts +3 -0
- package/dist/cache/terminal-handler/constants/identifier.d.ts.map +1 -0
- package/dist/cache/terminal-handler/constants/index.d.ts +3 -0
- package/dist/cache/terminal-handler/constants/index.d.ts.map +1 -0
- package/dist/cache/terminal-handler/index.d.ts +2 -0
- package/dist/cache/terminal-handler/index.d.ts.map +1 -0
- package/dist/cache/terminal-handler/terminal.d.ts +11 -0
- package/dist/cache/terminal-handler/terminal.d.ts.map +1 -0
- package/dist/cache/terminal-handler/types/index.d.ts +2 -0
- package/dist/cache/terminal-handler/types/index.d.ts.map +1 -0
- package/dist/cache/terminal-handler/types/terminal.d.ts +7 -0
- package/dist/cache/terminal-handler/types/terminal.d.ts.map +1 -0
- package/dist/cache-providers/index.d.ts +2 -0
- package/dist/cache-providers/index.d.ts.map +1 -0
- package/dist/cache-providers/redis/index.d.ts +2 -0
- package/dist/cache-providers/redis/index.d.ts.map +1 -0
- package/dist/cache-providers/redis/ioredis-instance.d.ts +3 -0
- package/dist/cache-providers/redis/ioredis-instance.d.ts.map +1 -0
- package/dist/cache-providers/redis/redis-cache.d.ts +23 -0
- package/dist/cache-providers/redis/redis-cache.d.ts.map +1 -0
- package/dist/cache-providers/redis/types/index.d.ts +37 -0
- package/dist/cache-providers/redis/types/index.d.ts.map +1 -0
- package/dist/client-Btua9wfS.js +230 -0
- package/dist/client-Bv9OflsW.cjs +1 -0
- package/dist/default-errors-DiEIEEE2.cjs +1 -0
- package/dist/default-errors-DsKmUZbG.js +59 -0
- package/dist/encoder-BEp9qfLf.cjs +1 -0
- package/dist/encoder-CXAlLf5T.js +39 -0
- package/dist/encrypter-CgZLhLnj.cjs +1 -0
- package/dist/encrypter-ZTjrp3uD.js +54 -0
- package/dist/engine/auth-engine.d.ts +29 -0
- package/dist/engine/auth-engine.d.ts.map +1 -0
- package/dist/engine/entra-id.d.ts +12 -0
- package/dist/engine/entra-id.d.ts.map +1 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/types/index.d.ts +51 -0
- package/dist/engine/types/index.d.ts.map +1 -0
- package/dist/errors/default-errors.d.ts +31 -0
- package/dist/errors/default-errors.d.ts.map +1 -0
- package/dist/errors/error-handler.d.ts +8 -0
- package/dist/errors/error-handler.d.ts.map +1 -0
- package/dist/errors/i18n.d.ts +30 -0
- package/dist/errors/i18n.d.ts.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/runtime-error-code.d.ts +16 -0
- package/dist/errors/runtime-error-code.d.ts.map +1 -0
- package/dist/errors/runtime-error.d.ts +6 -0
- package/dist/errors/runtime-error.d.ts.map +1 -0
- package/dist/fetch-BZP9DZLg.cjs +3 -0
- package/dist/fetch-CUIb9XhZ.js +761 -0
- package/dist/helpers/encoder.d.ts +8 -0
- package/dist/helpers/encoder.d.ts.map +1 -0
- package/dist/helpers/encrypter.d.ts +10 -0
- package/dist/helpers/encrypter.d.ts.map +1 -0
- package/dist/helpers/escape-unicode.d.ts +2 -0
- package/dist/helpers/escape-unicode.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/logger.d.ts +16 -0
- package/dist/helpers/logger.d.ts.map +1 -0
- package/dist/http/backend.d.ts +18 -0
- package/dist/http/backend.d.ts.map +1 -0
- package/dist/http/client.d.ts +20 -0
- package/dist/http/client.d.ts.map +1 -0
- package/dist/http/headers.d.ts +9 -0
- package/dist/http/headers.d.ts.map +1 -0
- package/dist/http/index.d.ts +4 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/types/http-options.d.ts +13 -0
- package/dist/http/types/http-options.d.ts.map +1 -0
- package/dist/http/types/index.d.ts +5 -0
- package/dist/http/types/index.d.ts.map +1 -0
- package/dist/http/types/method.d.ts +2 -0
- package/dist/http/types/method.d.ts.map +1 -0
- package/dist/http/types/request-config.d.ts +10 -0
- package/dist/http/types/request-config.d.ts.map +1 -0
- package/dist/http/types/response.d.ts +39 -0
- package/dist/http/types/response.d.ts.map +1 -0
- package/dist/i18n-CEBemBIX.js +31 -0
- package/dist/i18n-vIm9wuAG.cjs +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/ioredis-instance-BaXfqmqC.js +11 -0
- package/dist/ioredis-instance-PenLE7vi.cjs +1 -0
- package/dist/loading-handler-BrN0O37N.cjs +1 -0
- package/dist/loading-handler-ivYFmS_V.js +17 -0
- package/dist/lodash-DNCgFYS7.cjs +27 -0
- package/dist/lodash-QjAkD17S.js +3677 -0
- package/dist/logger-BMbeDoGU.cjs +1 -0
- package/dist/logger-DtlFWyFO.js +60 -0
- package/dist/middleware/api-middleware.d.ts +22 -0
- package/dist/middleware/api-middleware.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/types/index.d.ts +2 -0
- package/dist/middleware/types/index.d.ts.map +1 -0
- package/dist/mp-front-common-adapters.cjs +1 -0
- package/dist/mp-front-common-adapters.js +169 -0
- package/dist/mp-front-common-all.cjs +1 -0
- package/dist/mp-front-common-all.js +126 -0
- package/dist/mp-front-common-auth.cjs +1 -0
- package/dist/mp-front-common-auth.js +4 -0
- package/dist/mp-front-common-cache.cjs +1 -0
- package/dist/mp-front-common-cache.js +132 -0
- package/dist/mp-front-common-cacheProviders.cjs +1 -0
- package/dist/mp-front-common-cacheProviders.js +4 -0
- package/dist/mp-front-common-engine.cjs +1 -0
- package/dist/mp-front-common-engine.js +185 -0
- package/dist/mp-front-common-errors.cjs +1 -0
- package/dist/mp-front-common-errors.js +9 -0
- package/dist/mp-front-common-helpers.cjs +1 -0
- package/dist/mp-front-common-helpers.js +9 -0
- package/dist/mp-front-common-http.cjs +1 -0
- package/dist/mp-front-common-http.js +6 -0
- package/dist/mp-front-common-rxjs.cjs +1 -0
- package/dist/mp-front-common-rxjs.js +4 -0
- package/dist/redis-cache-BoKAFYQi.js +83 -0
- package/dist/redis-cache-DjKTqllz.cjs +1 -0
- package/dist/rx-subject-manager-ZC9CWBWH.cjs +1 -0
- package/dist/rx-subject-manager-_4urHn8A.js +24 -0
- package/dist/rxjs/index.d.ts +2 -0
- package/dist/rxjs/index.d.ts.map +1 -0
- package/dist/rxjs/loading-handler.d.ts +7 -0
- package/dist/rxjs/loading-handler.d.ts.map +1 -0
- package/dist/rxjs/rx-subject-manager.d.ts +9 -0
- package/dist/rxjs/rx-subject-manager.d.ts.map +1 -0
- package/dist/stringify-93tp0umt.js +9 -0
- package/dist/stringify-BN6t_WDt.cjs +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/v5-BTqP79vV.cjs +1 -0
- package/dist/v5-Cu1sjPlx.js +91 -0
- package/package.json +107 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var l=(r,o,s)=>o in r?n(r,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[o]=s;var t=(r,o,s)=>l(r,typeof o!="symbol"?o+"":o,s);var g=(r=>(r[r.error=0]="error",r[r.warn=1]="warn",r[r.info=2]="info",r[r.http=3]="http",r[r.verbose=4]="verbose",r[r.debug=5]="debug",r[r.silly=6]="silly",r))(g||{});const a={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[34m",http:"\x1B[35m",verbose:"\x1B[32m",debug:"\x1B[37m",silly:"\x1B[37m"};class e{constructor(){t(this,"appName");t(this,"logsLevel");t(this,"silentLogs");this.appName=process.env.NEXT_PUBLIC_APP_LOGS_NAME,this.logsLevel=process.env.NEXT_PUBLIC_LOGS_LEVEL,this.silentLogs=process.env.NEXT_PUBLIC_SILENT_LOGS==="true"}consoleFormat(o,s){try{return`${a[o]} ${this.appName} [${new Date().toISOString()}] [${o.toUpperCase()}]: ${s.toString()} \x1B[37m`}catch{return s}}log(o,s){if(o<=g[this.logsLevel]&&!this.silentLogs)try{console.log(this.consoleFormat(g[o],s))}catch(i){console.error("Fail to parse log",i)}}logError(...o){this.log(0,o)}logWarn(...o){this.log(1,o)}logInfo(...o){this.log(2,o)}logHttp(...o){this.log(3,o)}logVerbose(...o){this.log(4,o)}logDebug(...o){this.log(5,o)}logSilly(...o){this.log(6,o)}}exports.Logger=e;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var n = Object.defineProperty;
|
|
2
|
+
var l = (r, o, s) => o in r ? n(r, o, { enumerable: !0, configurable: !0, writable: !0, value: s }) : r[o] = s;
|
|
3
|
+
var t = (r, o, s) => l(r, typeof o != "symbol" ? o + "" : o, s);
|
|
4
|
+
var g = /* @__PURE__ */ ((r) => (r[r.error = 0] = "error", r[r.warn = 1] = "warn", r[r.info = 2] = "info", r[r.http = 3] = "http", r[r.verbose = 4] = "verbose", r[r.debug = 5] = "debug", r[r.silly = 6] = "silly", r))(g || {});
|
|
5
|
+
const a = {
|
|
6
|
+
error: "\x1B[31m",
|
|
7
|
+
warn: "\x1B[33m",
|
|
8
|
+
info: "\x1B[34m",
|
|
9
|
+
http: "\x1B[35m",
|
|
10
|
+
verbose: "\x1B[32m",
|
|
11
|
+
debug: "\x1B[37m",
|
|
12
|
+
silly: "\x1B[37m"
|
|
13
|
+
};
|
|
14
|
+
class e {
|
|
15
|
+
constructor() {
|
|
16
|
+
t(this, "appName");
|
|
17
|
+
t(this, "logsLevel");
|
|
18
|
+
t(this, "silentLogs");
|
|
19
|
+
this.appName = process.env.NEXT_PUBLIC_APP_LOGS_NAME, this.logsLevel = process.env.NEXT_PUBLIC_LOGS_LEVEL, this.silentLogs = process.env.NEXT_PUBLIC_SILENT_LOGS === "true";
|
|
20
|
+
}
|
|
21
|
+
consoleFormat(o, s) {
|
|
22
|
+
try {
|
|
23
|
+
return `${a[o]} ${this.appName} [${(/* @__PURE__ */ new Date()).toISOString()}] [${o.toUpperCase()}]: ${s.toString()} \x1B[37m`;
|
|
24
|
+
} catch {
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
log(o, s) {
|
|
29
|
+
if (o <= g[this.logsLevel] && !this.silentLogs)
|
|
30
|
+
try {
|
|
31
|
+
console.log(this.consoleFormat(g[o], s));
|
|
32
|
+
} catch (i) {
|
|
33
|
+
console.error("Fail to parse log", i);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
logError(...o) {
|
|
37
|
+
this.log(0, o);
|
|
38
|
+
}
|
|
39
|
+
logWarn(...o) {
|
|
40
|
+
this.log(1, o);
|
|
41
|
+
}
|
|
42
|
+
logInfo(...o) {
|
|
43
|
+
this.log(2, o);
|
|
44
|
+
}
|
|
45
|
+
logHttp(...o) {
|
|
46
|
+
this.log(3, o);
|
|
47
|
+
}
|
|
48
|
+
logVerbose(...o) {
|
|
49
|
+
this.log(4, o);
|
|
50
|
+
}
|
|
51
|
+
logDebug(...o) {
|
|
52
|
+
this.log(5, o);
|
|
53
|
+
}
|
|
54
|
+
logSilly(...o) {
|
|
55
|
+
this.log(6, o);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
e as L
|
|
60
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { Session } from 'next-auth';
|
|
3
|
+
import { RuntimeError } from '../errors';
|
|
4
|
+
interface IAdditionalParams {
|
|
5
|
+
requestID: string;
|
|
6
|
+
headers: Headers;
|
|
7
|
+
}
|
|
8
|
+
export declare class ApiMiddleware {
|
|
9
|
+
private readonly encoder;
|
|
10
|
+
private readonly logger;
|
|
11
|
+
protected requestID: string;
|
|
12
|
+
private session;
|
|
13
|
+
setSession(session: Session): void;
|
|
14
|
+
getSession(): Session;
|
|
15
|
+
protected returnData<ApiMiddlewareResponse>(response: ApiMiddlewareResponse, requestID?: string): Response;
|
|
16
|
+
protected returnError(error: RuntimeError): Response;
|
|
17
|
+
private getBody;
|
|
18
|
+
get<ApiMiddlewareRequest, ApiMiddlewareResponse = ApiMiddlewareRequest>(handle: (params: ApiMiddlewareRequest, additionalParams: IAdditionalParams) => Observable<ApiMiddlewareResponse>): (req: Request) => Promise<Response>;
|
|
19
|
+
getFile<ApiMiddlewareResponse>(handle: (file: File) => Observable<ApiMiddlewareResponse>): (req: Request) => Promise<Response>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=api-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/api-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,OAAO,EAAE,YAAY,EAAoB,MAAM,UAAU,CAAA;AAEzD,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IAEtC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAK;IAChC,OAAO,CAAC,OAAO,CAAuB;IAE/B,UAAU,CAAC,OAAO,EAAE,OAAO;IAI3B,UAAU;IASjB,SAAS,CAAC,UAAU,CAAC,qBAAqB,EACxC,QAAQ,EAAE,qBAAqB,EAC/B,SAAS,CAAC,EAAE,MAAM,GACjB,QAAQ;IAKX,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,YAAY;YAI3B,OAAO;IAsBrB,GAAG,CAAC,oBAAoB,EAAE,qBAAqB,GAAG,oBAAoB,EACpE,MAAM,EAAE,CACN,MAAM,EAAE,oBAAoB,EAC5B,gBAAgB,EAAE,iBAAiB,KAChC,UAAU,CAAC,qBAAqB,CAAC,SAInB,OAAO;IA8C5B,OAAO,CAAC,qBAAqB,EAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,qBAAqB,CAAC,SAItC,OAAO;CA4B7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Z=require("./ioredis-instance-PenLE7vi.cjs"),$=require("./stringify-BN6t_WDt.cjs");let w;const q=new Uint8Array(16);function G(){if(!w&&(w=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!w))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return w(q)}const H=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),E={randomUUID:H};function L(r,s,i){if(E.randomUUID&&!r)return E.randomUUID();r=r||{};const c=r.random||(r.rng||G)();return c[6]=c[6]&15|64,c[8]=c[8]&63|128,$.unsafeStringify(c)}const z=process.env.PREFIX_LOGIN,b=process.env.TIMEOUT_SESSION_MINUTES,A={baseKeyPrefix:`${z}:`,userKeyPrefix:"user:",accountKeyPrefix:"account:",accountByUserIdPrefix:"account:user:",sessionKeyPrefix:"session:",sessionByUserIdPrefix:"session:user:",userByEmailKeyPrefix:"user:email:",verificationKeyPrefix:"verification:",expire:b*60},C=r=>{for(const s in r)return!1;return!0},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=r=>r&&J.test(r)&&!Number.isNaN(Date.parse(r));function W(r={expire:b*60}){const s=Z.ioredisInstance,i={...A,...r},c=i.baseKeyPrefix||"",B=c+i.userKeyPrefix,T=c+i.userByEmailKeyPrefix,k=c+i.accountKeyPrefix,j=c+i.accountByUserIdPrefix,D=c+i.sessionKeyPrefix,V=c+i.sessionByUserIdPrefix,N=c+i.verificationKeyPrefix,x=e=>T+e,I=e=>B+e,U=e=>k+e,y=e=>j+e,g=(e,t)=>`${t}:${e}`,K=e=>D+e,f=e=>V+e,p=e=>N+e,l=async(e,t)=>{const n=Object.entries(t).reduce((o,[m,a])=>(o[m]=a instanceof Date?a.toISOString():a,o),{});await s.hset(e,n),await s.expire(e,i.expire)},d=async e=>{const t=await s.hgetall(e);return!t||C(t)?null:Object.entries(t).reduce((o,[m,a])=>(o[m]=Q(a)?new Date(a):a,o),{})},S=async(e,t)=>(await l(I(e),t),t.email&&await s.set(x(t.email),e,"EX",i.expire),t),u=async e=>{const t=await d(I(e));return t?{...t}:null},R=async(e,t)=>{const n=U(e);await l(n,t),await s.set(y(t.userId),n,"EX",i.expire)},h=async e=>{const t=await d(U(e));return t?{...t}:null},_=async e=>{const t=U(e),n=await d(t);if(!n)return null;await s.hdel(t),await s.del(y(n.userId))},O=async(e,t)=>{const n=K(e);return await l(n,t),await s.set(f(t.userId),n,"EX",i.expire),t},P=async e=>{const t=await d(K(e));return t?{id:t.id,...t}:null},M=async e=>{const t=await P(e);if(!t)return null;const n=K(e);await s.del(n),await s.del(f(t.userId))},X=async(e,t)=>{const n=p(e);return await l(n,t),t},v=async e=>{const t=p(e),n=await d(t);return n?{identifier:n.identifier,...n}:null},F=async e=>{const t=p(e);await s.del(t)};return{async createUser(e){const t=L();return await S(t,{...e,id:t})},getUser:u,async getUserByEmail(e){const t=await s.get(x(e));return t?await u(t):null},async getUserByAccount({providerAccountId:e,provider:t}){const n=await h(g(e,t));return n?await u(n.userId):null},async updateUser(e){const t=e.id,n=await u(t);return await S(t,{...n,...e})},async deleteUser(e){const t=await u(e);if(!t)return null;const n=await s.get(y(e)),o=await s.get(f(e));await s.del(x(t.email),y(e),f(e)),o&&await s.del(o),n&&await s.del(n),await s.del(I(e))},async linkAccount(e){const t=g(e.providerAccountId,e.provider);return await R(t,{...e,id:t})},async unlinkAccount({providerAccountId:e,provider:t}){const n=g(e,t);await _(n)},async createSession(e){const t=e.sessionToken;return await O(t,{...e,id:t})},async getSessionAndUser(e){const n=await P(e);if(!n)return null;const o=await u(n.userId);return o?{session:n,user:o}:null},async updateSession(e){const t=e.sessionToken,n=await P(t);return n?await O(t,{...n,...e}):null},deleteSession:M,async createVerificationToken(e){const t=e.identifier;return await X(t,e),e},async useVerificationToken(e){const t=e.identifier,n=await v(t);return!n||e.token!==n.token?null:(await F(t),n)}}}exports.IORedisAdapter=W;exports.defaultOptions=A;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { i as Z } from "./ioredis-instance-BaXfqmqC.js";
|
|
2
|
+
import { u as $ } from "./stringify-93tp0umt.js";
|
|
3
|
+
let w;
|
|
4
|
+
const v = new Uint8Array(16);
|
|
5
|
+
function G() {
|
|
6
|
+
if (!w && (w = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !w))
|
|
7
|
+
throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
|
|
8
|
+
return w(v);
|
|
9
|
+
}
|
|
10
|
+
const H = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), O = {
|
|
11
|
+
randomUUID: H
|
|
12
|
+
};
|
|
13
|
+
function L(r, s, i) {
|
|
14
|
+
if (O.randomUUID && !r)
|
|
15
|
+
return O.randomUUID();
|
|
16
|
+
r = r || {};
|
|
17
|
+
const c = r.random || (r.rng || G)();
|
|
18
|
+
return c[6] = c[6] & 15 | 64, c[8] = c[8] & 63 | 128, $(c);
|
|
19
|
+
}
|
|
20
|
+
const q = process.env.PREFIX_LOGIN, b = process.env.TIMEOUT_SESSION_MINUTES, z = {
|
|
21
|
+
baseKeyPrefix: `${q}:`,
|
|
22
|
+
userKeyPrefix: "user:",
|
|
23
|
+
accountKeyPrefix: "account:",
|
|
24
|
+
accountByUserIdPrefix: "account:user:",
|
|
25
|
+
sessionKeyPrefix: "session:",
|
|
26
|
+
sessionByUserIdPrefix: "session:user:",
|
|
27
|
+
userByEmailKeyPrefix: "user:email:",
|
|
28
|
+
verificationKeyPrefix: "verification:",
|
|
29
|
+
expire: b * 60
|
|
30
|
+
}, C = (r) => {
|
|
31
|
+
for (const s in r)
|
|
32
|
+
return !1;
|
|
33
|
+
return !0;
|
|
34
|
+
}, 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 = (r) => r && J.test(r) && !Number.isNaN(Date.parse(r));
|
|
35
|
+
function ee(r = { expire: b * 60 }) {
|
|
36
|
+
const s = Z, i = {
|
|
37
|
+
...z,
|
|
38
|
+
...r
|
|
39
|
+
}, c = i.baseKeyPrefix || "", A = c + i.userKeyPrefix, B = c + i.userByEmailKeyPrefix, k = c + i.accountKeyPrefix, T = c + i.accountByUserIdPrefix, D = c + i.sessionKeyPrefix, V = c + i.sessionByUserIdPrefix, j = c + i.verificationKeyPrefix, x = (e) => B + e, U = (e) => A + e, K = (e) => k + e, y = (e) => T + e, p = (e, t) => `${t}:${e}`, I = (e) => D + e, f = (e) => V + e, g = (e) => j + e, l = async (e, t) => {
|
|
40
|
+
const n = Object.entries(t).reduce((o, [P, a]) => (o[P] = a instanceof Date ? a.toISOString() : a, o), {});
|
|
41
|
+
await s.hset(e, n), await s.expire(e, i.expire);
|
|
42
|
+
}, d = async (e) => {
|
|
43
|
+
const t = await s.hgetall(e);
|
|
44
|
+
return !t || C(t) ? null : Object.entries(t).reduce((o, [P, a]) => (o[P] = Q(a) ? new Date(a) : a, o), {});
|
|
45
|
+
}, S = async (e, t) => (await l(U(e), t), t.email && await s.set(
|
|
46
|
+
x(t.email),
|
|
47
|
+
e,
|
|
48
|
+
"EX",
|
|
49
|
+
i.expire
|
|
50
|
+
), t), u = async (e) => {
|
|
51
|
+
const t = await d(U(e));
|
|
52
|
+
return t ? { ...t } : null;
|
|
53
|
+
}, N = async (e, t) => {
|
|
54
|
+
const n = K(e);
|
|
55
|
+
await l(n, t), await s.set(
|
|
56
|
+
y(t.userId),
|
|
57
|
+
n,
|
|
58
|
+
"EX",
|
|
59
|
+
i.expire
|
|
60
|
+
);
|
|
61
|
+
}, h = async (e) => {
|
|
62
|
+
const t = await d(K(e));
|
|
63
|
+
return t ? { ...t } : null;
|
|
64
|
+
}, R = async (e) => {
|
|
65
|
+
const t = K(e), n = await d(t);
|
|
66
|
+
if (!n) return null;
|
|
67
|
+
await s.hdel(t), await s.del(y(n.userId));
|
|
68
|
+
}, E = async (e, t) => {
|
|
69
|
+
const n = I(e);
|
|
70
|
+
return await l(n, t), await s.set(
|
|
71
|
+
f(t.userId),
|
|
72
|
+
n,
|
|
73
|
+
"EX",
|
|
74
|
+
i.expire
|
|
75
|
+
), t;
|
|
76
|
+
}, m = async (e) => {
|
|
77
|
+
const t = await d(I(e));
|
|
78
|
+
return t ? {
|
|
79
|
+
id: t.id,
|
|
80
|
+
...t
|
|
81
|
+
} : null;
|
|
82
|
+
}, _ = async (e) => {
|
|
83
|
+
const t = await m(e);
|
|
84
|
+
if (!t) return null;
|
|
85
|
+
const n = I(e);
|
|
86
|
+
await s.del(n), await s.del(f(t.userId));
|
|
87
|
+
}, X = async (e, t) => {
|
|
88
|
+
const n = g(e);
|
|
89
|
+
return await l(n, t), t;
|
|
90
|
+
}, M = async (e) => {
|
|
91
|
+
const t = g(e), n = await d(t);
|
|
92
|
+
return n ? { identifier: n.identifier, ...n } : null;
|
|
93
|
+
}, F = async (e) => {
|
|
94
|
+
const t = g(e);
|
|
95
|
+
await s.del(t);
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
async createUser(e) {
|
|
99
|
+
const t = L();
|
|
100
|
+
return await S(t, { ...e, id: t });
|
|
101
|
+
},
|
|
102
|
+
getUser: u,
|
|
103
|
+
async getUserByEmail(e) {
|
|
104
|
+
const t = await s.get(x(e));
|
|
105
|
+
return t ? await u(t) : null;
|
|
106
|
+
},
|
|
107
|
+
async getUserByAccount({ providerAccountId: e, provider: t }) {
|
|
108
|
+
const n = await h(
|
|
109
|
+
p(e, t)
|
|
110
|
+
);
|
|
111
|
+
return n ? await u(n.userId) : null;
|
|
112
|
+
},
|
|
113
|
+
async updateUser(e) {
|
|
114
|
+
const t = e.id, n = await u(t);
|
|
115
|
+
return await S(t, { ...n, ...e });
|
|
116
|
+
},
|
|
117
|
+
async deleteUser(e) {
|
|
118
|
+
const t = await u(e);
|
|
119
|
+
if (!t) return null;
|
|
120
|
+
const n = await s.get(y(e)), o = await s.get(f(e));
|
|
121
|
+
await s.del(
|
|
122
|
+
x(t.email),
|
|
123
|
+
y(e),
|
|
124
|
+
f(e)
|
|
125
|
+
), o && await s.del(o), n && await s.del(n), await s.del(U(e));
|
|
126
|
+
},
|
|
127
|
+
async linkAccount(e) {
|
|
128
|
+
const t = p(e.providerAccountId, e.provider);
|
|
129
|
+
return await N(t, { ...e, id: t });
|
|
130
|
+
},
|
|
131
|
+
async unlinkAccount({
|
|
132
|
+
providerAccountId: e,
|
|
133
|
+
provider: t
|
|
134
|
+
}) {
|
|
135
|
+
const n = p(e, t);
|
|
136
|
+
await R(n);
|
|
137
|
+
},
|
|
138
|
+
async createSession(e) {
|
|
139
|
+
const t = e.sessionToken;
|
|
140
|
+
return await E(t, {
|
|
141
|
+
...e,
|
|
142
|
+
id: t
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
async getSessionAndUser(e) {
|
|
146
|
+
const n = await m(e);
|
|
147
|
+
if (!n) return null;
|
|
148
|
+
const o = await u(n.userId);
|
|
149
|
+
return o ? { session: n, user: o } : null;
|
|
150
|
+
},
|
|
151
|
+
async updateSession(e) {
|
|
152
|
+
const t = e.sessionToken, n = await m(t);
|
|
153
|
+
return n ? await E(t, { ...n, ...e }) : null;
|
|
154
|
+
},
|
|
155
|
+
deleteSession: _,
|
|
156
|
+
async createVerificationToken(e) {
|
|
157
|
+
const t = e.identifier;
|
|
158
|
+
return await X(t, e), e;
|
|
159
|
+
},
|
|
160
|
+
async useVerificationToken(e) {
|
|
161
|
+
const t = e.identifier, n = await M(t);
|
|
162
|
+
return !n || e.token !== n.token ? null : (await F(t), n);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
ee as IORedisAdapter,
|
|
168
|
+
z as defaultOptions
|
|
169
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var h=Object.defineProperty;var E=(a,r,e)=>r in a?h(a,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[r]=e;var l=(a,r,e)=>E(a,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./default-errors-DiEIEEE2.cjs"),f=require("./i18n-vIm9wuAG.cjs"),c=require("./client-Bv9OflsW.cjs"),t=require("rxjs"),R=require("./logger-BMbeDoGU.cjs"),m=require("./encoder-BEp9qfLf.cjs");require("node-jose");require("crypto");class S{constructor(){l(this,"encoder",new m.Encoder);l(this,"logger",new R.Logger);l(this,"requestID","");l(this,"session",null)}setSession(r){this.session=r}getSession(){if(!this.session)throw new g.RuntimeError(g.RuntimeErrorCode.AUTHENTICATION_ERROR,this.requestID);return this.session}returnData(r,e){const s=this.encoder.encode(r,e);return new Response(s,{status:200})}returnError(r){return new Response(JSON.stringify(r),{status:520})}async getBody(r){if(r.method==="GET"){const{searchParams:n}=new URL(r.url);if(n!=null&&n.entries()){const i=[...n.entries()].reduce((u,[d,D])=>(u[d]=D,u),{}),o=i.requestID??"";return{data:i,requestID:o}}return{data:{},requestID:""}}const e=await r.json(),s=(e==null?void 0:e.requestID)??"";return{data:e,requestID:s}}get(r){return this.logger.logDebug("get ApiMiddleware"),async e=>{const{data:s,requestID:n}=await this.getBody(e);this.logger.logDebug("return ApiMiddleware",JSON.stringify(s)),this.requestID=n;try{const i=await t.firstValueFrom(t.of(e).pipe(t.switchMap(o=>t.forkJoin({params:t.of(this.encoder.decode(s)),headers:t.of(o.headers)})),t.switchMap(({params:o,headers:u})=>t.forkJoin({response:r(o,{requestID:this.requestID,headers:u}),headers:t.of(u),params:t.of(o)})),t.switchMap(({params:o,response:u,headers:d})=>(this.logger.logDebug(`ApiMiddleware \x1B[37m <URL>: \x1B[33m ${e.url} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(d)} \x1B[37m <REQUEST ID> \x1B[33m ${this.requestID} \x1B[37m <PARAMS> \x1B[33m ${JSON.stringify(o)} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(u)}`),t.of(u)))));return this.logger.logDebug("ApiMiddleware subscribe next",JSON.stringify(i)),this.returnData(i,this.requestID)}catch(i){return this.logger.logError(`ApiMiddleware <URL>: ${e==null?void 0:e.url} <HEADERS>: ${JSON.stringify(e==null?void 0:e.headers)} <REQUEST ID> ${this.requestID} <PARAMS> ${JSON.stringify(e==null?void 0:e.body)} <ERROR>: ${JSON.stringify(i)}`),this.returnError({...i,requestID:this.requestID})}}}getFile(r){return this.logger.logDebug("get File ApiMiddleware"),async e=>{try{const s=await e.formData(),n=s.get("file");this.requestID=s.get("requestID");const i=await t.firstValueFrom(r(n).pipe(t.switchMap(o=>(this.logger.logDebug(`ApiMiddleware \x1B[37m <URL>: \x1B[33m ${e.url} \x1B[37m <REQUEST ID> \x1B[33m ${this.requestID} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(o)}`),t.of(o)))));return this.logger.logDebug("ApiMiddleware File subscribe next",JSON.stringify(i)),this.returnData(i,this.requestID)}catch(s){return this.logger.logError(`ApiMiddleware <URL>: ${e==null?void 0:e.url} <HEADERS>: ${JSON.stringify(e==null?void 0:e.headers)} <REQUEST ID> ${this.requestID} <PARAMS> ${JSON.stringify(e==null?void 0:e.body)} <ERROR>: ${JSON.stringify(s)}`),this.returnError({...s,requestID:this.requestID})}}}}exports.ErrorHandler=g.ErrorHandler;exports.RuntimeError=g.RuntimeError;exports.RuntimeErrorCode=g.RuntimeErrorCode;exports.commonErrors=g.commonErrors;exports.errorTranslations=f.translation;exports.HttpBackend=c.HttpBackend;exports.HttpClient=c.HttpClient;exports.HttpHeaders=c.HttpHeaders;exports.ApiMiddleware=S;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var p = (u, e, t) => e in u ? E(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
|
|
3
|
+
var g = (u, e, t) => p(u, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { R as c, a as f } from "./default-errors-DsKmUZbG.js";
|
|
5
|
+
import { E as J, c as M } from "./default-errors-DsKmUZbG.js";
|
|
6
|
+
import { t as U } from "./i18n-CEBemBIX.js";
|
|
7
|
+
import { a as L, b as F, H as P } from "./client-Btua9wfS.js";
|
|
8
|
+
import { firstValueFrom as D, of as a, switchMap as l, forkJoin as h } from "rxjs";
|
|
9
|
+
import { L as R } from "./logger-DtlFWyFO.js";
|
|
10
|
+
import { E as I } from "./encoder-CXAlLf5T.js";
|
|
11
|
+
import "node-jose";
|
|
12
|
+
import "crypto";
|
|
13
|
+
class N {
|
|
14
|
+
constructor() {
|
|
15
|
+
g(this, "encoder", new I());
|
|
16
|
+
g(this, "logger", new R());
|
|
17
|
+
g(this, "requestID", "");
|
|
18
|
+
g(this, "session", null);
|
|
19
|
+
}
|
|
20
|
+
setSession(e) {
|
|
21
|
+
this.session = e;
|
|
22
|
+
}
|
|
23
|
+
getSession() {
|
|
24
|
+
if (!this.session)
|
|
25
|
+
throw new c(
|
|
26
|
+
f.AUTHENTICATION_ERROR,
|
|
27
|
+
this.requestID
|
|
28
|
+
);
|
|
29
|
+
return this.session;
|
|
30
|
+
}
|
|
31
|
+
returnData(e, t) {
|
|
32
|
+
const r = this.encoder.encode(e, t);
|
|
33
|
+
return new Response(r, { status: 200 });
|
|
34
|
+
}
|
|
35
|
+
returnError(e) {
|
|
36
|
+
return new Response(JSON.stringify(e), { status: 520 });
|
|
37
|
+
}
|
|
38
|
+
async getBody(e) {
|
|
39
|
+
if (e.method === "GET") {
|
|
40
|
+
const { searchParams: o } = new URL(e.url);
|
|
41
|
+
if (o != null && o.entries()) {
|
|
42
|
+
const s = [...o.entries()].reduce(
|
|
43
|
+
(n, [d, m]) => (n[d] = m, n),
|
|
44
|
+
{}
|
|
45
|
+
), i = s.requestID ?? "";
|
|
46
|
+
return { data: s, requestID: i };
|
|
47
|
+
}
|
|
48
|
+
return { data: {}, requestID: "" };
|
|
49
|
+
}
|
|
50
|
+
const t = await e.json(), r = (t == null ? void 0 : t.requestID) ?? "";
|
|
51
|
+
return { data: t, requestID: r };
|
|
52
|
+
}
|
|
53
|
+
get(e) {
|
|
54
|
+
return this.logger.logDebug("get ApiMiddleware"), async (t) => {
|
|
55
|
+
const { data: r, requestID: o } = await this.getBody(t);
|
|
56
|
+
this.logger.logDebug("return ApiMiddleware", JSON.stringify(r)), this.requestID = o;
|
|
57
|
+
try {
|
|
58
|
+
const s = await D(
|
|
59
|
+
a(t).pipe(
|
|
60
|
+
l(
|
|
61
|
+
(i) => h({
|
|
62
|
+
params: a(this.encoder.decode(r)),
|
|
63
|
+
headers: a(i.headers)
|
|
64
|
+
})
|
|
65
|
+
),
|
|
66
|
+
l(
|
|
67
|
+
({ params: i, headers: n }) => h({
|
|
68
|
+
response: e(i, {
|
|
69
|
+
requestID: this.requestID,
|
|
70
|
+
headers: n
|
|
71
|
+
}),
|
|
72
|
+
headers: a(n),
|
|
73
|
+
params: a(i)
|
|
74
|
+
})
|
|
75
|
+
),
|
|
76
|
+
l(({ params: i, response: n, headers: d }) => (this.logger.logDebug(
|
|
77
|
+
`ApiMiddleware \x1B[37m <URL>: \x1B[33m ${t.url} \x1B[37m <HEADERS>: \x1B[33m ${JSON.stringify(d)} \x1B[37m <REQUEST ID> \x1B[33m ${this.requestID} \x1B[37m <PARAMS> \x1B[33m ${JSON.stringify(i)} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(n)}`
|
|
78
|
+
), a(n)))
|
|
79
|
+
)
|
|
80
|
+
);
|
|
81
|
+
return this.logger.logDebug(
|
|
82
|
+
"ApiMiddleware subscribe next",
|
|
83
|
+
JSON.stringify(s)
|
|
84
|
+
), this.returnData(s, this.requestID);
|
|
85
|
+
} catch (s) {
|
|
86
|
+
return this.logger.logError(
|
|
87
|
+
`ApiMiddleware <URL>: ${t == null ? void 0 : t.url} <HEADERS>: ${JSON.stringify(t == null ? void 0 : t.headers)} <REQUEST ID> ${this.requestID} <PARAMS> ${JSON.stringify(t == null ? void 0 : t.body)} <ERROR>: ${JSON.stringify(s)}`
|
|
88
|
+
), this.returnError({ ...s, requestID: this.requestID });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
getFile(e) {
|
|
93
|
+
return this.logger.logDebug("get File ApiMiddleware"), async (t) => {
|
|
94
|
+
try {
|
|
95
|
+
const r = await t.formData(), o = r.get("file");
|
|
96
|
+
this.requestID = r.get("requestID");
|
|
97
|
+
const s = await D(
|
|
98
|
+
e(o).pipe(
|
|
99
|
+
l((i) => (this.logger.logDebug(
|
|
100
|
+
`ApiMiddleware \x1B[37m <URL>: \x1B[33m ${t.url} \x1B[37m <REQUEST ID> \x1B[33m ${this.requestID} \x1B[37m <RESPONSE>: \x1B[33m ${JSON.stringify(i)}`
|
|
101
|
+
), a(i)))
|
|
102
|
+
)
|
|
103
|
+
);
|
|
104
|
+
return this.logger.logDebug(
|
|
105
|
+
"ApiMiddleware File subscribe next",
|
|
106
|
+
JSON.stringify(s)
|
|
107
|
+
), this.returnData(s, this.requestID);
|
|
108
|
+
} catch (r) {
|
|
109
|
+
return this.logger.logError(
|
|
110
|
+
`ApiMiddleware <URL>: ${t == null ? void 0 : t.url} <HEADERS>: ${JSON.stringify(t == null ? void 0 : t.headers)} <REQUEST ID> ${this.requestID} <PARAMS> ${JSON.stringify(t == null ? void 0 : t.body)} <ERROR>: ${JSON.stringify(r)}`
|
|
111
|
+
), this.returnError({ ...r, requestID: this.requestID });
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export {
|
|
117
|
+
N as ApiMiddleware,
|
|
118
|
+
J as ErrorHandler,
|
|
119
|
+
L as HttpBackend,
|
|
120
|
+
F as HttpClient,
|
|
121
|
+
P as HttpHeaders,
|
|
122
|
+
c as RuntimeError,
|
|
123
|
+
f as RuntimeErrorCode,
|
|
124
|
+
M as commonErrors,
|
|
125
|
+
U as errorTranslations
|
|
126
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./authorization-service-DkLS18Us.cjs");exports.AuthorizationService=e.AuthorizationService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.defineProperty;var C=(t,e,s)=>e in t?T(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>C(t,typeof e!="symbol"?e+"":e,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./redis-cache-DjKTqllz.cjs"),_=require("./logger-BMbeDoGU.cjs");require("./lodash-DNCgFYS7.cjs");require("node-jose");require("crypto");const R=require("./v5-BTqP79vV.cjs"),A=process.env.TIMEOUT_SESSION_MINUTES,G=process.env.PREFIX_TERMINAL||"PF:TERMINAL:",N="619abad7-0dea-46c5-aa49-fc1ec872a684",u="TERMINAL";class ${constructor(){n(this,"logger",new _.Logger);n(this,"redisCache",new l.RedisCache)}getIdApi(e){const s=R.v5(e,N);return`${G}${s}`}async set(e,s){return this.redisCache.setRedisState({idApi:this.getIdApi(e),idData:u,body:s,expire:A})}async get(e){return this.redisCache.getRedisState(this.getIdApi(e),u).then(({data:s})=>(this.logger.logDebug("getTerminal",JSON.stringify(s)),s)).catch(s=>(this.logger.logError("Error getTerminal",JSON.stringify(s)),null))}async delete(e){return this.redisCache.deleteRedisState(this.getIdApi(e),u)}}const{TIMEOUT_SESSION_MINUTES:w}=process.env,{PREFIX_LOGIN:r}=process.env,O=process.env.REDIS_GET_USER_DATA_SESSION??"",U=`${r}:${O}`;`${process.env.APP_LOGS_NAME}${process.env.REDIS_GET_USER_APPS_PERMISSIONS}`;class M{constructor(e){n(this,"redisCache",new l.RedisCache);n(this,"userId","");n(this,"accountId","");this.userId=e}async updateSessionTimeout(e,s,a){if(!e)return;const i=new Date,c=w*6e4,o=new Date(i.getTime()+c);this.redisCache.simpleHSet(s,a,o.toISOString())}async getBasicSession(){const e="expires",s=await this.redisCache.simpleGet(`${r}:session:user:${this.userId}`)??"",a=await this.redisCache.simpleHGet(s,"sessionToken"),d=await this.redisCache.simpleHGet(`${r}:user:${this.userId}`,"email")??"",i=await this.redisCache.simpleGet(`${r}:account:user:${this.userId}`)??"",c=await this.redisCache.simpleHGet(i,"providerAccountId")??"",o=await this.redisCache.simpleHGet(s,e);if(this.updateSessionTimeout(o,s,e),this.accountId=c,a&&d&&i&&c){const S=await this.redisCache.simpleHGet(`${r}:user:${this.userId}`,"name"),I=await this.redisCache.simpleHGet(`${r}:user:${this.userId}`,"email")??"",p=await this.redisCache.simpleHGet(`${r}:user:${this.userId}`,"image"),m=await this.redisCache.simpleHGet(`${i}`,"cveUsuario"),h=await this.redisCache.simpleHGet(`${i}`,"appGroups"),E=await this.redisCache.simpleHGet(`${i}`,"rol"),g=h?JSON.parse(h):[];return{user:{name:S,email:I,image:p,cveUsuario:m,rol:E,appGroups:g}}}return{user:{name:null,email:null,image:null},expires:null}}async getUserAndShoppingStore(){var a;const e=await this.getBasicSession();if(e.user.image===null)return e;const s=await this.redisCache.getRedisState(U,this.accountId);return s.data.data?{user:{...e.user,...(a=s==null?void 0:s.data)==null?void 0:a.data}}:{user:{name:null,email:null,image:null},expires:null}}}exports.SessionCache=M;exports.Terminal=$;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var T = Object.defineProperty;
|
|
2
|
+
var _ = (t, e, s) => e in t ? T(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
|
+
var n = (t, e, s) => _(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
+
import { R as d } from "./redis-cache-BoKAFYQi.js";
|
|
5
|
+
import { L as C } from "./logger-DtlFWyFO.js";
|
|
6
|
+
import "./lodash-QjAkD17S.js";
|
|
7
|
+
import "node-jose";
|
|
8
|
+
import "crypto";
|
|
9
|
+
import { v as R } from "./v5-Cu1sjPlx.js";
|
|
10
|
+
const A = process.env.TIMEOUT_SESSION_MINUTES, G = process.env.PREFIX_TERMINAL || "PF:TERMINAL:", N = "619abad7-0dea-46c5-aa49-fc1ec872a684", u = "TERMINAL";
|
|
11
|
+
class f {
|
|
12
|
+
constructor() {
|
|
13
|
+
n(this, "logger", new C());
|
|
14
|
+
n(this, "redisCache", new d());
|
|
15
|
+
}
|
|
16
|
+
getIdApi(e) {
|
|
17
|
+
const s = R(e, N);
|
|
18
|
+
return `${G}${s}`;
|
|
19
|
+
}
|
|
20
|
+
async set(e, s) {
|
|
21
|
+
return this.redisCache.setRedisState({
|
|
22
|
+
idApi: this.getIdApi(e),
|
|
23
|
+
idData: u,
|
|
24
|
+
body: s,
|
|
25
|
+
expire: A
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async get(e) {
|
|
29
|
+
return this.redisCache.getRedisState(this.getIdApi(e), u).then(({ data: s }) => (this.logger.logDebug("getTerminal", JSON.stringify(s)), s)).catch((s) => (this.logger.logError("Error getTerminal", JSON.stringify(s)), null));
|
|
30
|
+
}
|
|
31
|
+
async delete(e) {
|
|
32
|
+
return this.redisCache.deleteRedisState(this.getIdApi(e), u);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const { TIMEOUT_SESSION_MINUTES: $ } = process.env, { PREFIX_LOGIN: r } = process.env, w = process.env.REDIS_GET_USER_DATA_SESSION ?? "", O = `${r}:${w}`;
|
|
36
|
+
`${process.env.APP_LOGS_NAME}${process.env.REDIS_GET_USER_APPS_PERMISSIONS}`;
|
|
37
|
+
class y {
|
|
38
|
+
constructor(e) {
|
|
39
|
+
n(this, "redisCache", new d());
|
|
40
|
+
n(this, "userId", "");
|
|
41
|
+
n(this, "accountId", "");
|
|
42
|
+
this.userId = e;
|
|
43
|
+
}
|
|
44
|
+
async updateSessionTimeout(e, s, a) {
|
|
45
|
+
if (!e) return;
|
|
46
|
+
const i = /* @__PURE__ */ new Date(), o = $ * 6e4, c = new Date(i.getTime() + o);
|
|
47
|
+
this.redisCache.simpleHSet(
|
|
48
|
+
s,
|
|
49
|
+
a,
|
|
50
|
+
c.toISOString()
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
async getBasicSession() {
|
|
54
|
+
const e = "expires", s = await this.redisCache.simpleGet(
|
|
55
|
+
`${r}:session:user:${this.userId}`
|
|
56
|
+
) ?? "", a = await this.redisCache.simpleHGet(
|
|
57
|
+
s,
|
|
58
|
+
"sessionToken"
|
|
59
|
+
), h = await this.redisCache.simpleHGet(
|
|
60
|
+
`${r}:user:${this.userId}`,
|
|
61
|
+
"email"
|
|
62
|
+
) ?? "", i = await this.redisCache.simpleGet(
|
|
63
|
+
`${r}:account:user:${this.userId}`
|
|
64
|
+
) ?? "", o = await this.redisCache.simpleHGet(i, "providerAccountId") ?? "", c = await this.redisCache.simpleHGet(
|
|
65
|
+
s,
|
|
66
|
+
e
|
|
67
|
+
);
|
|
68
|
+
if (this.updateSessionTimeout(c, s, e), this.accountId = o, a && h && i && o) {
|
|
69
|
+
const l = await this.redisCache.simpleHGet(
|
|
70
|
+
`${r}:user:${this.userId}`,
|
|
71
|
+
"name"
|
|
72
|
+
), p = await this.redisCache.simpleHGet(
|
|
73
|
+
`${r}:user:${this.userId}`,
|
|
74
|
+
"email"
|
|
75
|
+
) ?? "", m = await this.redisCache.simpleHGet(
|
|
76
|
+
`${r}:user:${this.userId}`,
|
|
77
|
+
"image"
|
|
78
|
+
), I = await this.redisCache.simpleHGet(
|
|
79
|
+
`${i}`,
|
|
80
|
+
"cveUsuario"
|
|
81
|
+
), S = await this.redisCache.simpleHGet(
|
|
82
|
+
`${i}`,
|
|
83
|
+
"appGroups"
|
|
84
|
+
), E = await this.redisCache.simpleHGet(`${i}`, "rol"), g = S ? JSON.parse(S) : [];
|
|
85
|
+
return {
|
|
86
|
+
user: {
|
|
87
|
+
name: l,
|
|
88
|
+
email: p,
|
|
89
|
+
image: m,
|
|
90
|
+
cveUsuario: I,
|
|
91
|
+
rol: E,
|
|
92
|
+
appGroups: g
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
user: {
|
|
98
|
+
name: null,
|
|
99
|
+
email: null,
|
|
100
|
+
image: null
|
|
101
|
+
},
|
|
102
|
+
expires: null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async getUserAndShoppingStore() {
|
|
106
|
+
var a;
|
|
107
|
+
const e = await this.getBasicSession();
|
|
108
|
+
if (e.user.image === null)
|
|
109
|
+
return e;
|
|
110
|
+
const s = await this.redisCache.getRedisState(
|
|
111
|
+
O,
|
|
112
|
+
this.accountId
|
|
113
|
+
);
|
|
114
|
+
return s.data.data ? {
|
|
115
|
+
user: {
|
|
116
|
+
...e.user,
|
|
117
|
+
...(a = s == null ? void 0 : s.data) == null ? void 0 : a.data
|
|
118
|
+
}
|
|
119
|
+
} : {
|
|
120
|
+
user: {
|
|
121
|
+
name: null,
|
|
122
|
+
email: null,
|
|
123
|
+
image: null
|
|
124
|
+
},
|
|
125
|
+
expires: null
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
y as SessionCache,
|
|
131
|
+
f as Terminal
|
|
132
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./redis-cache-DjKTqllz.cjs");exports.RedisCache=e.RedisCache;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.defineProperty;var G=(a,r,s)=>r in a?T(a,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[r]=s;var c=(a,r,s)=>G(a,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("rxjs"),E=require("./lodash-DNCgFYS7.cjs"),P=require("./logger-BMbeDoGU.cjs");require("node-jose");require("crypto");const g=require("./fetch-BZP9DZLg.cjs"),n={client_id:process.env.AZURE_AD_CLIENT_ID,client_secret:process.env.AZURE_AD_CLIENT_SECRET,resource:process.env.AZURE_AD_CLIENT_RESOURCE,grant_type:process.env.AZURE_AD_CLIENT_GRANT_TYPE},m=process.env.AZURE_AD_GRAPH_URL_TOKEN,U=process.env.AZURE_AD_TENANT_ID;class f{constructor(){c(this,"logger",new P.Logger)}getHeaders(){const r=Object.keys(n).some(e=>E.lodashExports.isEmpty(n[e]));if(E.lodashExports.isEmpty(m)||E.lodashExports.isEmpty(U))throw this.logger.logError("AZURE_AD_GRAPH_URL_TOKEN or AZURE_AD_TENANT_ID are empty or missing"),new Error("AZURE_AD_GRAPH_URL_TOKEN or AZURE_AD_TENANT_ID are empty or missing");if(r)throw this.logger.logError("Some variables are empty or missing, check AZURE_AD_CLIENT_ID, AZURE_AD_CLIENT_SECRET, AZURE_AD_CLIENT_RESOURCE, AZURE_AD_CLIENT_GRANT_TYPE"),new Error("some variables are empty or missing");const s=m.replace("AZURE_AD_TENANT_ID",U);return g.fromFetch(s,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams(n),selector:e=>e.json()}).pipe(o.switchMap(e=>(this.logger.logDebug("response from API new_url_365_graph_token",JSON.stringify(e)),o.of({headers:{Authorization:`Bearer ${e==null?void 0:e.access_token}`,responseType:"json"}}))))}}const d=process.env.AZURE_AD_GRAPH_GET_APP_ROLES,D=process.env.AZURE_AD_GRAPH_GET_USER_BY_EMAIL,u=process.env.AZURE_AD_GRAPH_GROUPS;class N extends f{getAppRoles(r){if(E.lodashExports.isEmpty(d))throw this.logger.logError("AZURE_AD_GRAPH_GET_APP_ROLES URL is empty or missing"),new Error("AZURE_AD_GRAPH_GET_APP_ROLES URL is empty or missing");const s=d.replace("{id-obj}",`${r}`);return this.getHeaders().pipe(o.switchMap(e=>g.fromFetch(s,{method:"GET",headers:e==null?void 0:e.headers,selector:t=>t.json()}).pipe(o.switchMap(t=>o.of({roles:t==null?void 0:t.value})))))}getAppRoleAssignments(r){if(E.lodashExports.isEmpty(D))throw this.logger.logError("AZURE_AD_GRAPH_GET_USER_BY_EMAIL URL is empty or missing"),new Error("AZURE_AD_GRAPH_GET_USER_BY_EMAIL URL is empty or missing");const e=`${D.replace("{user-mail}",`${r}/appRoleAssignments`)}?$select=appRoleId,resourceDisplayName`;return this.getHeaders().pipe(o.switchMap(t=>g.fromFetch(e,{method:"GET",headers:t==null?void 0:t.headers,selector:_=>_.json()})))}userRolesByApp(r,s){return o.forkJoin({appRoles:this.getAppRoles(s),appRoleAssignments:this.getAppRoleAssignments(r)}).pipe(o.switchMap(({appRoles:e,appRoleAssignments:t})=>{var p;const _=(p=t==null?void 0:t.value)==null?void 0:p.map(A=>{var h,l,R;return(R=(l=(h=e==null?void 0:e.roles)==null?void 0:h.filter(i=>(i==null?void 0:i.id)===(A==null?void 0:A.appRoleId)))==null?void 0:l.filter(i=>i==null?void 0:i.isEnabled))==null?void 0:R.map(i=>({appRoleId:A==null?void 0:A.appRoleId,displayName:i==null?void 0:i.displayName,value:i==null?void 0:i.value}))}).flat(),y=_==null?void 0:_.map(A=>A==null?void 0:A.appRoleId);return o.of({roles:y})}))}getRolesFromApi(r,s){return this.userRolesByApp(r,s).pipe(o.switchMap(e=>o.of(e)))}getRoles(r,s){return this.getRolesFromApi(r,s)}getGroupsFromApi(r){if(this.logger.logDebug("getGroupsFromApi by email: ",JSON.stringify(r)),E.lodashExports.isEmpty(u))throw this.logger.logError("AZURE_AD_GRAPH_GROUPS URL is empty or missing"),new Error("AZURE_AD_GRAPH_GROUPS URL is empty or missing");const s=`${u.replace("idUser",r)}?$select=id,description,displayName`;return this.logger.logDebug("URL base: ",s),this.getHeaders().pipe(o.switchMap(e=>g.fromFetch(s,{method:"GET",headers:e==null?void 0:e.headers,selector:t=>t.json()}).pipe(o.switchMap(t=>(this.logger.logDebug("response from API: ",JSON.stringify(t)),o.of(t))))))}getUserGroups(r){return this.getGroupsFromApi(r)}inGroup(r,s){return this.logger.logDebug("Check inGroup params: ",JSON.stringify({email:r,idGroup:s})),E.lodashExports.isEmpty(r)||E.lodashExports.isEmpty(s)?(this.logger.logError("inGroup method error"),this.logger.logError("email or idGroup are empty or missing"),o.of(!1)):this.getUserGroups(r).pipe(o.switchMap(e=>{var t;return o.of((t=e==null?void 0:e.value)==null?void 0:t.some(_=>(_==null?void 0:_.id)===s))}))}inRole(r,s,e){return this.logger.logDebug("Check inRole params: ",JSON.stringify({email:r,idRole:s,idObjApp:e})),E.lodashExports.isEmpty(r)||E.lodashExports.isEmpty(s)||E.lodashExports.isEmpty(e)?(this.logger.logError("inRole method error"),this.logger.logError("email or idRole or idObjApp are empty or missing"),o.of(!1)):this.getRoles(r,e).pipe(o.switchMap(t=>{var _;return o.of((_=t==null?void 0:t.roles)==null?void 0:_.includes(s))}))}}exports.AuthEngine=N;
|