@edifice.io/session-nest-client 0.0.0-stage → 0.1.0
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 +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +58 -0
- package/dist/index.umd.cjs +1 -0
- package/dist/nats/client.d.ts +23 -0
- package/dist/nats/client.d.ts.map +1 -0
- package/package.json +55 -3
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var l = Object.defineProperty;
|
|
2
|
+
var c = (s, e, r) => e in s ? l(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
|
|
3
|
+
var g = (s, e, r) => (c(s, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
+
import { Injectable as u, Logger as h } from "@nestjs/common";
|
|
5
|
+
import { firstValueFrom as i } from "rxjs";
|
|
6
|
+
var w = Object.getOwnPropertyDescriptor, v = (s, e, r, t) => {
|
|
7
|
+
for (var n = t > 1 ? void 0 : t ? w(e, r) : e, o = s.length - 1, d; o >= 0; o--)
|
|
8
|
+
(d = s[o]) && (n = d(n) || n);
|
|
9
|
+
return n;
|
|
10
|
+
};
|
|
11
|
+
let a = class {
|
|
12
|
+
constructor(s) {
|
|
13
|
+
g(this, "logger", new h(a.name));
|
|
14
|
+
this.natsClient = s, this.logger.log("Creating events service SessionNatsServiceClient");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Finds a session from its id (or from the cookies / headers / params of the request).
|
|
18
|
+
* Fails if an error occurs while processing the request or if the session is not found.
|
|
19
|
+
*/
|
|
20
|
+
async findSession(s) {
|
|
21
|
+
const e = "session.find";
|
|
22
|
+
this.logger.debug({ messageAddress: e }, "Sending request to NATS subject");
|
|
23
|
+
const r = Date.now(), t = await i(this.natsClient.send(e, s)), n = Date.now() - r;
|
|
24
|
+
if (this.logger.debug({ brokerAddress: e, duration: n }, "[nats][mttr]"), !t)
|
|
25
|
+
throw this.logger.warn({ messageAddress: e }, "No reply received for subject"), new Error("No reply received");
|
|
26
|
+
return t;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Refreshes (recreates) every active session of a given user, without needing to know any of their sessionId
|
|
30
|
+
* in advance. Useful when the caller is not the target user (e.g. an admin granting rights to another,
|
|
31
|
+
* already connected, user).
|
|
32
|
+
*/
|
|
33
|
+
async refreshAllSessions(s) {
|
|
34
|
+
const e = "session.refreshAll";
|
|
35
|
+
this.logger.debug({ messageAddress: e }, "Sending request to NATS subject");
|
|
36
|
+
const r = Date.now(), t = await i(this.natsClient.send(e, s)), n = Date.now() - r;
|
|
37
|
+
if (this.logger.debug({ brokerAddress: e, duration: n }, "[nats][mttr]"), !t)
|
|
38
|
+
throw this.logger.warn({ messageAddress: e }, "No reply received for subject"), new Error("No reply received");
|
|
39
|
+
return t;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Refreshes (recreates) a session.
|
|
43
|
+
*/
|
|
44
|
+
async refreshSession(s) {
|
|
45
|
+
const e = "session.refresh";
|
|
46
|
+
this.logger.debug({ messageAddress: e }, "Sending request to NATS subject");
|
|
47
|
+
const r = Date.now(), t = await i(this.natsClient.send(e, s)), n = Date.now() - r;
|
|
48
|
+
if (this.logger.debug({ brokerAddress: e, duration: n }, "[nats][mttr]"), !t)
|
|
49
|
+
throw this.logger.warn({ messageAddress: e }, "No reply received for subject"), new Error("No reply received");
|
|
50
|
+
return t;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
a = v([
|
|
54
|
+
u()
|
|
55
|
+
], a);
|
|
56
|
+
export {
|
|
57
|
+
a as SessionNatsServiceClient
|
|
58
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@nestjs/common"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@nestjs/common","rxjs"],t):(e=typeof globalThis<"u"?globalThis:e||self,t((e["@edifice"]=e["@edifice"]||{},e["@edifice"]["io/session-nest-client"]={}),e.NestjsCommon,e.rxjs))})(this,function(e,t,i){"use strict";var f=Object.defineProperty;var h=(e,t,i)=>t in e?f(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var g=(e,t,i)=>(h(e,typeof t!="symbol"?t+"":t,i),i);var l=Object.getOwnPropertyDescriptor,u=(a,n,s,d)=>{for(var r=d>1?void 0:d?l(n,s):n,o=a.length-1,c;o>=0;o--)(c=a[o])&&(r=c(r)||r);return r};e.SessionNatsServiceClient=class{constructor(n){g(this,"logger",new t.Logger(e.SessionNatsServiceClient.name));this.natsClient=n,this.logger.log("Creating events service SessionNatsServiceClient")}async findSession(n){const s="session.find";this.logger.debug({messageAddress:s},"Sending request to NATS subject");const d=Date.now(),r=await i.firstValueFrom(this.natsClient.send(s,n)),o=Date.now()-d;if(this.logger.debug({brokerAddress:s,duration:o},"[nats][mttr]"),!r)throw this.logger.warn({messageAddress:s},"No reply received for subject"),new Error("No reply received");return r}async refreshAllSessions(n){const s="session.refreshAll";this.logger.debug({messageAddress:s},"Sending request to NATS subject");const d=Date.now(),r=await i.firstValueFrom(this.natsClient.send(s,n)),o=Date.now()-d;if(this.logger.debug({brokerAddress:s,duration:o},"[nats][mttr]"),!r)throw this.logger.warn({messageAddress:s},"No reply received for subject"),new Error("No reply received");return r}async refreshSession(n){const s="session.refresh";this.logger.debug({messageAddress:s},"Sending request to NATS subject");const d=Date.now(),r=await i.firstValueFrom(this.natsClient.send(s,n)),o=Date.now()-d;if(this.logger.debug({brokerAddress:s,duration:o},"[nats][mttr]"),!r)throw this.logger.warn({messageAddress:s},"No reply received for subject"),new Error("No reply received");return r}},e.SessionNatsServiceClient=u([t.Injectable()],e.SessionNatsServiceClient),Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ClientProxy } from '@nestjs/microservices';
|
|
2
|
+
import { FindSessionRequest, FindSessionResponse, RefreshAllSessionsRequest, RefreshAllSessionsResponse, RefreshSessionRequest, RefreshSessionResponse } from '@edifice.io/session-nest-api';
|
|
3
|
+
export declare class SessionNatsServiceClient {
|
|
4
|
+
private readonly natsClient;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(natsClient: ClientProxy);
|
|
7
|
+
/**
|
|
8
|
+
* Finds a session from its id (or from the cookies / headers / params of the request).
|
|
9
|
+
* Fails if an error occurs while processing the request or if the session is not found.
|
|
10
|
+
*/
|
|
11
|
+
findSession(request: FindSessionRequest): Promise<FindSessionResponse>;
|
|
12
|
+
/**
|
|
13
|
+
* Refreshes (recreates) every active session of a given user, without needing to know any of their sessionId
|
|
14
|
+
* in advance. Useful when the caller is not the target user (e.g. an admin granting rights to another,
|
|
15
|
+
* already connected, user).
|
|
16
|
+
*/
|
|
17
|
+
refreshAllSessions(request: RefreshAllSessionsRequest): Promise<RefreshAllSessionsResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Refreshes (recreates) a session.
|
|
20
|
+
*/
|
|
21
|
+
refreshSession(request: RefreshSessionRequest): Promise<RefreshSessionResponse>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/nats/client.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAExE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE/E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAG3E,qBACa,wBAAwB;IAIvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAFvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6C;gBAEvC,UAAU,EAAE,WAAW;IAMpD;;;OAGG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgB5E;;;;OAIG;IACG,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAgBjG;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAgBtF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edifice.io/session-nest-client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Clients to interact with session-nats-service",
|
|
5
|
+
"private": false,
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "Edifice",
|
|
11
|
+
"license": "AGPL-3.0",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": "22"
|
|
14
|
+
},
|
|
15
|
+
"engineStrict": true,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"require": "./dist/index.umd.cjs",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.umd.cjs",
|
|
25
|
+
"module": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@edifice.io/session-nest-api": "0.1.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"husky": "9.0.11",
|
|
35
|
+
"prettier": "3.2.5",
|
|
36
|
+
"semantic-release": "23.0.2",
|
|
37
|
+
"typescript": "5.2.2",
|
|
38
|
+
"vite": "5.1.4",
|
|
39
|
+
"vite-plugin-dts": "4.3.0",
|
|
40
|
+
"rxjs": "7.8.1",
|
|
41
|
+
"@nestjs/common": "11.0.20",
|
|
42
|
+
"@nestjs/microservices": "11.0.20"
|
|
43
|
+
},
|
|
44
|
+
"lint-staged": {
|
|
45
|
+
"*.{js,ts,jsx,tsx,json,css,md}": "pnpm format"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"dev": "vite",
|
|
49
|
+
"build": "tsc && vite build",
|
|
50
|
+
"build:types": "tsc --build",
|
|
51
|
+
"preview": "vite preview",
|
|
52
|
+
"clean": "rm -Rf dist",
|
|
53
|
+
"format": "pnpm run format:write && pnpm run format:check",
|
|
54
|
+
"format:check": "npx prettier --check \"src/**/*.ts\"",
|
|
55
|
+
"format:write": "npx prettier --write \"src/**/*.ts\"",
|
|
56
|
+
"pre-commit": "pnpm run format"
|
|
57
|
+
}
|
|
6
58
|
}
|
package/README.md
DELETED