insite-client 2.3.3 → 2.4.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Eugene Nesvetaev
3
+ Copyright (c) 2026 Eugene Nesvetaev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,208 @@
1
- # Client-side inSite app
1
+ # insite-client
2
+
3
+ Client-side inSite SDK — WebSocket, auth, subscriptions, file transfers. Single entry point for connecting to an inSite server.
4
+
5
+ Part of [inSite](../../README.md) — built on [insite-ws](../ws/README.md), [insite-cookie](../cookie/README.md), [insite-users-client](../users-client/README.md), [insite-subscriptions-client](../subscriptions-client/README.md), [insite-ws-transfers](../ws-transfers/README.md).
2
6
 
3
7
  ## Installation
4
8
 
5
9
  ```sh
6
- $ npm install insite-client
10
+ npm install insite-client
7
11
  ```
8
12
 
9
- Or
13
+ Or:
10
14
 
11
15
  ```sh
12
- $ bun add insite-client
16
+ bun add insite-client
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ```ts
22
+ import { InSite } from "insite-client";
23
+
24
+ // Sync — returns InSite immediately, init runs in background
25
+ const inSite = InSite.init({
26
+ ws: { url: "wss://your-server.example.com" }
27
+ });
28
+
29
+ inSite.on("ready", () => {
30
+ console.log("Connected");
31
+ });
32
+
33
+ // Async — returns Promise that resolves when ready
34
+ const inSite = await InSite.init(
35
+ { ws: { url: "wss://your-server.example.com" } },
36
+ true
37
+ );
38
+ ```
39
+
40
+ ## API Reference
41
+
42
+ ### Exports
43
+
44
+ | Export | Type | Description |
45
+ |--------|------|-------------|
46
+ | `InSite` | class | Main facade class |
47
+ | `Options<AS>` | type | Client options |
48
+ | `AbilitiesSchema`, `AbilitySchema`, `AbilityParamSchema`, `Abilities`, `ScanAbilitySchemas` | type | From [insite-common](../common/README.md) |
49
+ | `CookieSetter`, `CookieOptions` | class/type | From [insite-cookie](../cookie/README.md) |
50
+ | `Subscription`, `SubscriptionGroup`, `SubscriptionGroupItem`, `SubscriptionArray`, `SubscriptionMap`, `SubscriptionObject`, `SubscriptionMapWithSubscription`, `SubscriptionObjectWithSubscription` | class | From [insite-subscriptions-client](../subscriptions-client/README.md) |
51
+ | `Updated`, `Definition`, `SubscriptionType`, `SubscriptionGroupOptions`, `SubscriptionGroupTarget` | type | From [insite-subscriptions-client](../subscriptions-client/README.md) |
52
+ | `UsersSubscriptionGroup`, `UsersSubscriptionGroupOptions` | class/type | From [insite-users-client](../users-client/README.md) |
53
+ | `CurrentUser`, `Org`, `Orgs`, `OrgsExtended`, `Role`, `Roles`, `User`, `Users`, `UsersExtended` | type | From [insite-users-client](../users-client/README.md) |
54
+ | `IncomingTransport`, `OutgoingTransport`, `IncomingTransfer`, `OutgoingTransfer`, `WithTransfer`, `WithOnTransfer`, `IncomingTransportOptions`, `arrayBufferToBase64` | — | From [insite-ws-transfers](../ws-transfers/README.md) |
55
+ | `WS`, `WSOptions` | class/type | From [insite-ws](../ws/README.md) |
56
+
57
+ ### InSite
58
+
59
+ | Member | Description |
60
+ |--------|-------------|
61
+ | `new InSite(options?)` | Constructor, optionally calls `init` |
62
+ | `InSite.init(options?, asPromise?)` | Static factory, returns `InSite` or `Promise<InSite>` |
63
+ | `ws` | WS instance (with `transfer`/`onTransfer` when transports enabled) |
64
+ | `incomingTransport` | IncomingTransport (when `ws.incomingTransport: true`) |
65
+ | `outgoingTransport` | OutgoingTransport (when `ws.outgoingTransport: true`) |
66
+ | `cookie` | CookieSetter (when `cookie` not null) |
67
+ | `usersSubscriptionGroup` | UsersSubscriptionGroup (when `users` + not `public`) |
68
+ | `user` | `CurrentUser \| null` (when `users`) |
69
+ | `users` | `Users \| UsersExtended` |
70
+ | `orgs` | `Orgs \| OrgsExtended` |
71
+ | `roles` | `Roles` |
72
+ | `isLoggedIn` | `boolean` |
73
+ | `login(email, password)` | `Promise` (when `users`) |
74
+ | `logout()` | `Promise` (when `users`) |
75
+ | `isReady` | `boolean` |
76
+ | `whenReady()` | `StatefulPromise<this>` |
77
+ | Events | `ready`, `login`, `logout` |
78
+
79
+ ### Options
80
+
81
+ `Options<AS>` where `AS extends AbilitiesSchema`.
82
+
83
+ | Property | Type | Description |
84
+ |----------|------|-------------|
85
+ | `ws` | `WSOptions & { subscriptions?, incomingTransport?, outgoingTransport? }` | WebSocket config. Set `subscriptions: true` for pub/sub. Set `incomingTransport` / `outgoingTransport` for file transfers. |
86
+ | `cookie` | `CookieOptions \| null` | Cookie auth. Use `{}` to enable, `null` to disable. |
87
+ | `users` | `{ abilities?: AS } \| null` | Users/orgs/roles. Use `{}` to enable, `null` to disable. |
88
+ | `public` | `boolean` | When `true` with `users`, only `user` is loaded (no orgs, roles, users list). |
89
+
90
+ ### WS
91
+
92
+ WebSocket client with auto-reconnect and request/response.
93
+
94
+ **Properties:** `url`, `name`, `protocols`, `reconnectAfter`, `signal`, `connectionQuality`, `webSocket`, `state`, `isConnecting`, `isOpen`, `isClosed`, `closedWith`
95
+
96
+ **Methods:** `open()`, `close()`, `send()`, `sendMessage()`, `sendRequest()`, `addRequestListener()`, `removeRequestListener()`, `destroy()`
97
+
98
+ **Events:** `connecting`, `open`, `close`, `message`, `message:${kind}`, `error`, `connection-quality-change`, `server-change`, `responsive`, `unresponsive`, `destroy`
99
+
100
+ ### CookieSetter
101
+
102
+ Sets auth cookie via XHR when server sends a token.
103
+
104
+ ```ts
105
+ constructor(ws: WS, options?: {
106
+ method?: "GET" | "POST";
107
+ url?: string;
108
+ onload?: (this: XMLHttpRequest, event: ProgressEvent) => unknown;
109
+ onerror?: (this: XMLHttpRequest, event: ProgressEvent) => unknown;
110
+ })
111
+ ```
112
+
113
+ ### Subscription
114
+
115
+ Low-level subscription to server publications. Use `Subscription.bindTo(ws)` before creating instances.
116
+
117
+ ```ts
118
+ Subscription.bindTo(ws);
119
+
120
+ const sub = new Subscription(
121
+ "object", // type: "array" | "map" | "object"
122
+ "user", // publicationName
123
+ [ true ], // args
124
+ (user) => { ... }, // handler
125
+ true // immediately (default: true)
126
+ );
127
+
128
+ sub.start(); // (re)subscribe
129
+ sub.cancel(); // unsubscribe
130
+ ```
131
+
132
+ ### IncomingTransport
133
+
134
+ Handles incoming file/data transfers. Adds `onTransfer()` and `onceTransfer()` to WS when enabled.
135
+
136
+ **Properties:** `sizeLimit`
137
+
138
+ **Methods:** `on()`, `once()`, `off()`, `addTransferListener()`, `removeTransferListener()`
139
+
140
+ ### OutgoingTransport
141
+
142
+ Handles outgoing file/data transfers. Adds `transfer()` to WS when enabled.
143
+
144
+ ```ts
145
+ ws.transfer("avatar", {
146
+ data: file,
147
+ onProgress: (transfer) => { ... },
148
+ onEnd: (transfer) => { ... }
149
+ });
150
+ ```
151
+
152
+ ### UsersSubscriptionGroup
153
+
154
+ Subscription group for users, orgs, roles. Extends `SubscriptionGroup`.
155
+
156
+ **Methods:** `extend()` — load roles and extended user/org data; `unextend()` — detach extended subscriptions
157
+
158
+ ## Usage Examples
159
+
160
+ **Minimal — WebSocket only:**
161
+
162
+ ```ts
163
+ InSite.init({ ws: { url: "wss://..." } });
164
+ ```
165
+
166
+ **With auth (public portal — current user only):**
167
+
168
+ ```ts
169
+ InSite.init({
170
+ ws: { url: "wss://...", subscriptions: true },
171
+ cookie: {},
172
+ users: {},
173
+ public: true
174
+ });
13
175
  ```
176
+
177
+ **With auth (admin — full users/orgs/roles):**
178
+
179
+ ```ts
180
+ InSite.init({
181
+ ws: { url: "wss://...", subscriptions: true },
182
+ cookie: {},
183
+ users: {}
184
+ });
185
+ ```
186
+
187
+ **With file transfers:**
188
+
189
+ ```ts
190
+ InSite.init({
191
+ ws: {
192
+ url: "wss://...",
193
+ incomingTransport: true,
194
+ outgoingTransport: true
195
+ }
196
+ });
197
+ ```
198
+
199
+ **Use cases:** Public portal — `public: true`, `user` only. Admin panel — `users: {}`, full `UsersSubscriptionGroup`. File uploads — `outgoingTransport: true`, `ws.transfer(kind, props)`.
200
+
201
+ ## Related
202
+
203
+ - [insite-server](../server/README.md) — backend this client connects to
204
+ - [insite-ws](../ws/README.md), [insite-cookie](../cookie/README.md), [insite-users-client](../users-client/README.md), [insite-subscriptions-client](../subscriptions-client/README.md), [insite-ws-transfers](../ws-transfers/README.md), [insite-common](../common/README.md)
205
+
206
+ ## License
207
+
208
+ MIT
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var R=Object.defineProperty;var k=t=>{throw TypeError(t)};var W=(t,o,e)=>o in t?R(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e;var i=(t,o,e)=>W(t,typeof o!="symbol"?o+"":o,e),L=(t,o,e)=>o.has(t)||k("Cannot "+e);var b=(t,o,e)=>(L(t,o,"read from private field"),e?e.call(t):o.get(t)),E=(t,o,e)=>o.has(t)?k("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(t):o.set(t,e);import D from"eventemitter3";function m(){}var g=new WeakMap,h=class t extends Promise{constructor(e,r){let n,u;super((s,c)=>{n=s,u=c});i(this,"isPending",!0);i(this,"isFulfilled",!1);i(this,"isRejected",!1);i(this,"state","pending");i(this,"result");i(this,"resolve",e=>{if(this.isPending){this.isPending=!1,this.isFulfilled=!0,this.state="fulfilled",this.result=e;let r=g.get(this);r&&(r.resolve.call(this,e),g.delete(this))}});i(this,"reject",e=>{if(this.isPending){this.isPending=!1,this.isRejected=!0,this.state="rejected",this.result=e;let r=g.get(this);r&&(r.reject.call(this,e),g.delete(this))}});if(g.set(this,{resolve:n,reject:u}),r?.signal)if(r.signal.aborted)this.reject(new DOMException("Aborted","AbortError"));else{let s=()=>this.reject(new DOMException("Aborted","AbortError"));r.signal.addEventListener("abort",s),this.finally(()=>r.signal?.removeEventListener("abort",s))}if(typeof r?.timeout=="number"&&Number.isFinite(r.timeout)){let s=setTimeout(()=>this.reject(new DOMException("Timeout exceeded","TimeoutError")),r.timeout);this.finally(()=>clearTimeout(s))}e?.(this.resolve,this.reject)}static resolved(e){return new t(r=>r(e))}static rejected(e){return new t((r,n)=>n(e))}};function C(t,o=0,e={}){let{leading:r=!1,trailing:n=!0}=e,{maxWait:u=1/0}=e,s,c,d,w,O,l,f,S,$=async()=>{let p=Date.now();p>=d?(s=void 0,d=void 0,clearTimeout(c),c=void 0,typeof f=="function"&&await f(),a.resolve(S),l=r):(clearTimeout(s),s=setTimeout($,d-p))},I=Number.isFinite(u)?()=>{f===x&&(f=!1),x(),c=setTimeout(I,u)}:null;async function x(){try{return S=await t.apply(w,O),S}catch(p){throw a.reject(p),p}}r&&typeof r=="boolean"&&(r=x),l=r,n&&typeof n=="boolean"&&(n=x),f=n;let a=Object.assign(function(...p){return O=p,w=this,d=Date.now()+o,f=n,a.promise.isPending||(a.promise=new h((P,A)=>{a.resolve=P,a.reject=A,typeof l=="function"&&(l(),l=!1,f===x&&(f=!1)),s||(s=setTimeout($,o),I&&(c=setTimeout(I,u)))})),a.promise},{callback:t,promise:h.resolved(void 0),resolve:m,reject:m,run:x,clear:async p=>{clearTimeout(s),s=void 0,clearTimeout(c),c=void 0,a.resolve(p?await x():S)}});return a}C.noop=Object.assign(()=>{},{callback:m,promise:h.resolved(void 0),resolve:m,reject:m,run:m,clear:m});function T(t,o,e,r,n=!0){return Array.isArray(t)&&(t=t.length),typeof r!="string"&&(n=r??!0,r=e),(n?`${t}\xA0`:"")+T.raw(t,o,e,r)}T.raw=(t,o,e,r=e)=>{t=Math.abs(t);let n=t%10,u=t%100;return n===1&&u!==11?o:n>=2&&n<=4&&!(u>=12&&u<=15)?e:r};import{CookieSetter as N}from"insite-cookie/client";import{Subscription as v}from"insite-subscriptions-client";import{UsersSubscriptionGroup as B}from"insite-users-client";import{IncomingTransport as F,OutgoingTransport as U}from"insite-ws-transfers/browser";import{WS as _}from"insite-ws/client";function G(t,o){return this.ws.sendRequest("login",t,o)}function q(){return this.ws.sendRequest("logout")}var y,j=class j extends D{constructor(e){super();i(this,"ws");i(this,"incomingTransport");i(this,"outgoingTransport");i(this,"cookie");i(this,"usersSubscriptionGroup");i(this,"user");i(this,"users");i(this,"orgs");i(this,"roles");i(this,"isLoggedIn",!1);i(this,"login");i(this,"logout");i(this,"isReady",!1);E(this,y,new h);e&&this.init(e)}async init(e){if(!this.isReady){let{ws:r={},cookie:n,users:u,public:s}=e??{},{subscriptions:c,incomingTransport:d,outgoingTransport:w,...O}=r;this.ws=new _(O),c!==null&&v.bindTo(this.ws),d&&(this.incomingTransport=new F(this.ws,typeof d=="object"?d:{})),w&&(this.outgoingTransport=new U(this.ws)),n!==null&&(this.cookie=new N(this.ws,n)),u!==null&&c!==null&&n!==null&&(this.user=null,this.login=G,this.logout=q,s?await new Promise(l=>{new v("object","user",[!0],f=>{this.user=f,this.user?this.isLoggedIn||(this.isLoggedIn=!0,this.emit("login",!0)):this.isLoggedIn&&(this.isLoggedIn=!1,this.emit("logout",!1)),this.isReady||l()})}):(this.usersSubscriptionGroup=new B({target:this}),await new Promise(l=>{this.usersSubscriptionGroup.once("init",()=>{this.isLoggedIn=!!this.user,this.usersSubscriptionGroup.on("update.user",f=>{f.valueOf()?this.isLoggedIn||(this.isLoggedIn=!0,this.emit("login",!0)):this.isLoggedIn&&(this.isLoggedIn=!1,this.emit("logout",!1))}),l(),this.isLoggedIn&&this.emit("login",!0)})}))),this.isReady=!0,this.emit("ready",!0),b(this,y).resolve(this)}}whenReady(){return b(this,y)}static init(e,r=!1){let n=new j(e);return r?n.whenReady():n}};y=new WeakMap;var M=j;export*from"insite-common/frontend";export*from"insite-cookie/client";export*from"insite-subscriptions-client";export*from"insite-users-client";export*from"insite-ws-transfers/browser";export*from"insite-ws/client";export{M as InSite};
1
+ var x=Object.defineProperty;var m=i=>{throw TypeError(i)};var w=(i,t,s)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[t]=s;var e=(i,t,s)=>w(i,typeof t!="symbol"?t+"":t,s),b=(i,t,s)=>t.has(i)||m("Cannot "+s);var a=(i,t,s)=>(b(i,t,"read from private field"),s?s.call(i):t.get(i)),d=(i,t,s)=>t.has(i)?m("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(i):t.set(i,s);import R from"eventemitter3";import{StatefulPromise as L}from"@nesvet/n";import{CookieSetter as P}from"insite-cookie/client";import{Subscription as O}from"insite-subscriptions-client";import{UsersSubscriptionGroup as T}from"insite-users-client";import{IncomingTransport as A,OutgoingTransport as U}from"insite-ws-transfers/browser";import{WS as W}from"insite-ws/client";function k(i,t){return this.ws.sendRequest("login",i,t)}function v(){return this.ws.sendRequest("logout")}var n,l=class l extends R{constructor(s){super();e(this,"ws");e(this,"incomingTransport");e(this,"outgoingTransport");e(this,"cookie");e(this,"usersSubscriptionGroup");e(this,"user");e(this,"users");e(this,"orgs");e(this,"roles");e(this,"isLoggedIn",!1);e(this,"login");e(this,"logout");e(this,"isReady",!1);d(this,n,new L);s&&this.init(s)}async init(s){if(!this.isReady){let{ws:r={},cookie:o,users:c,public:I}=s??{},{subscriptions:h,incomingTransport:p,outgoingTransport:y,...S}=r;this.ws=new W(S),h!==null&&O.bindTo(this.ws),p&&(this.incomingTransport=new A(this.ws,typeof p=="object"?p:{})),y&&(this.outgoingTransport=new U(this.ws)),o!==null&&(this.cookie=new P(this.ws,o)),c!==null&&h!==null&&o!==null&&(this.user=null,this.login=k,this.logout=v,I?await new Promise(u=>{new O("object","user",[!0],g=>{this.user=g,this.user?this.isLoggedIn||(this.isLoggedIn=!0,this.emit("login",!0)):this.isLoggedIn&&(this.isLoggedIn=!1,this.emit("logout",!1)),this.isReady||u()})}):(this.usersSubscriptionGroup=new T({target:this}),await new Promise(u=>{this.usersSubscriptionGroup.once("init",()=>{this.isLoggedIn=!!this.user,this.usersSubscriptionGroup.on("update.user",g=>{g.valueOf()?this.isLoggedIn||(this.isLoggedIn=!0,this.emit("login",!0)):this.isLoggedIn&&(this.isLoggedIn=!1,this.emit("logout",!1))}),u(),this.isLoggedIn&&this.emit("login",!0)})}))),this.isReady=!0,this.emit("ready",!0),a(this,n).resolve(this)}}whenReady(){return a(this,n)}static init(s,r=!1){let o=new l(s);return r?o.whenReady():o}};n=new WeakMap;var f=l;export*from"insite-common/frontend";export*from"insite-cookie/client";export*from"insite-subscriptions-client";export*from"insite-users-client";export*from"insite-ws-transfers/browser";export*from"insite-ws/client";export{f as InSite};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/InSite.ts", "../../../../@nesvet/npm/n/src/noop.ts", "../../../../@nesvet/npm/n/src/StatefulPromise.ts", "../../../../@nesvet/npm/n/src/debounce.ts", "../../../../@nesvet/npm/n/src/howmuch.ts", "../src/index.ts"],
4
- "sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { StatefulPromise } from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport { CookieSetter } from \"insite-cookie/client\";\nimport { Subscription } from \"insite-subscriptions-client\";\nimport {\n\tUsersSubscriptionGroup,\n\ttype CurrentUser,\n\ttype Orgs,\n\ttype OrgsExtended,\n\ttype Roles,\n\ttype Users,\n\ttype UsersExtended\n} from \"insite-users-client\";\nimport { IncomingTransport, OutgoingTransport } from \"insite-ws-transfers/browser\";\nimport { WS } from \"insite-ws/client\";\nimport type { OmitRedundant, Options, WSWithActualProps } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\n/** @this InSite */\nfunction login<O extends Options<any>>(this: InSite<O>, email: string, password: string) {\n\treturn this.ws.sendRequest(\"login\", email, password);\n}\n\n/** @this InSite */\nfunction logout<O extends Options<any>>(this: InSite<O>) {\n\treturn this.ws.sendRequest(\"logout\");\n}\n\n\nexport class InSite<\n\tO extends Options<any>,\n\tAS extends AbilitiesSchema = O extends Options<infer A> ? A : never\n> extends EventEmitter {\n\tconstructor(options?: O) {\n\t\tsuper();\n\t\t\n\t\tif (options)\n\t\t\tvoid this.init(options);\n\t\t\n\t}\n\t\n\tws!: WSWithActualProps<O>;\n\tincomingTransport!: IncomingTransport;\n\toutgoingTransport!: OutgoingTransport;\n\tcookie!: CookieSetter;\n\tusersSubscriptionGroup!: UsersSubscriptionGroup;\n\tuser!: CurrentUser<AS> | null;\n\tusers!: Users | UsersExtended;\n\torgs!: Orgs | OrgsExtended;\n\troles!: Roles;\n\tisLoggedIn = false;\n\t\n\tlogin!: typeof login<O>;\n\tlogout!: typeof logout<O>;\n\t\n\tisReady = false;\n\t\n\tprotected async init(options?: O) {\n\t\t\n\t\tif (!this.isReady) {\n\t\t\tconst {\n\t\t\t\tws: wsWithOtherOptions = {},\n\t\t\t\tcookie: cookieOptions,\n\t\t\t\tusers,\n\t\t\t\tpublic: isPublic\n\t\t\t} = options ?? {};\n\t\t\t\n\t\t\tconst {\n\t\t\t\tsubscriptions,\n\t\t\t\tincomingTransport,\n\t\t\t\toutgoingTransport,\n\t\t\t\t...wsOptions\n\t\t\t} = wsWithOtherOptions;\n\t\t\t\n\t\t\tthis.ws = new WS(wsOptions) as WSWithActualProps<O>;\n\t\t\t\n\t\t\tif (subscriptions !== null)\n\t\t\t\tSubscription.bindTo(this.ws);\n\t\t\t\n\t\t\tif (incomingTransport)\n\t\t\t\tthis.incomingTransport = new IncomingTransport(this.ws, typeof incomingTransport == \"object\" ? incomingTransport : {});\n\t\t\t\n\t\t\tif (outgoingTransport)\n\t\t\t\tthis.outgoingTransport = new OutgoingTransport(this.ws);\n\t\t\t\n\t\t\tif (cookieOptions !== null)\n\t\t\t\tthis.cookie = new CookieSetter(this.ws, cookieOptions);\n\t\t\t\n\t\t\tif (users !== null && subscriptions !== null && cookieOptions !== null) {\n\t\t\t\tthis.user = null;\n\t\t\t\tthis.login = login<O>;\n\t\t\t\tthis.logout = logout<O>;\n\t\t\t\t\n\t\t\t\tif (isPublic)\n\t\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\t\t\n\t\t\t\t\t\tnew Subscription(\"object\", \"user\", [ true ], user => {\n\t\t\t\t\t\t\tthis.user = user;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (this.user) {\n\t\t\t\t\t\t\t\tif (!this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\tthis.isLoggedIn = true;\n\t\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (this.isLoggedIn) {\n\t\t\t\t\t\t\t\tthis.isLoggedIn = false;\n\t\t\t\t\t\t\t\tthis.emit(\"logout\", false);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (!this.isReady)\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t\telse {\n\t\t\t\t\tthis.usersSubscriptionGroup = new UsersSubscriptionGroup({ target: this });\n\t\t\t\t\t\n\t\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.usersSubscriptionGroup.once(\"init\", () => {\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tthis.isLoggedIn = !!this.user;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tthis.usersSubscriptionGroup.on(\"update.user\", (user: CurrentUser) => {\n\t\t\t\t\t\t\t\tif (user.valueOf()) {\n\t\t\t\t\t\t\t\t\tif (!this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\t\tthis.isLoggedIn = true;\n\t\t\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\tthis.isLoggedIn = false;\n\t\t\t\t\t\t\t\t\tthis.emit(\"logout\", false);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (this.isLoggedIn)\n\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tthis.isReady = true;\n\t\t\tthis.emit(\"ready\", true);\n\t\t\t\n\t\t\tthis.#initPromise.resolve(this);\n\t\t}\n\t\t\n\t}\n\t\n\t#initPromise = new StatefulPromise<this>();\n\t\n\twhenReady() {\n\t\treturn this.#initPromise;\n\t}\n\t\n\t\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options: IO, asPromise: true): Promise<OmitRedundant<IS, IO>>;\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options?: IO, asPromise?: false): OmitRedundant<IS, IO>;\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options?: IO, asPromise = false) {\n\t\tconst inSite = new InSite(options) as IS;\n\t\t\n\t\treturn asPromise ?\n\t\t\tinSite.whenReady() :\n\t\t\tinSite;\n\t}\n\t\n}\n", "export function noop() { /**/ }\n", "/* eslint-disable @typescript-eslint/no-explicit-any */\n\ntype Value<T> = PromiseLike<T> | T;\ntype Resolve<T> = (value: Value<T>) => void;\ntype Reject = (reason?: any) => void;\n\ntype Options = {\n\tsignal?: AbortSignal;\n\ttimeout?: number;\n};\n\nconst nativesMap = new WeakMap<StatefulPromise<any>, { resolve: Resolve<any>; reject: Reject }>();\n\n\nexport class StatefulPromise<T> extends Promise<T> {\n\tconstructor(\n\t\texecutor?: (resolve: Resolve<T>, reject: Reject) => void,\n\t\toptions?: Options\n\t) {\n\t\tlet nativeResolve: Resolve<T>;\n\t\tlet nativeReject: Reject;\n\t\t\n\t\tsuper((resolve, reject) => {\n\t\t\tnativeResolve = resolve;\n\t\t\tnativeReject = reject;\n\t\t\t\n\t\t});\n\t\t\n\t\tnativesMap.set(this, { resolve: nativeResolve!, reject: nativeReject! });\n\t\t\n\t\tif (options?.signal)\n\t\t\tif (options.signal.aborted)\n\t\t\t\tthis.reject(new DOMException(\"Aborted\", \"AbortError\"));\n\t\t\telse {\n\t\t\t\tconst abortListener = () => this.reject(new DOMException(\"Aborted\", \"AbortError\"));\n\t\t\t\t\n\t\t\t\toptions.signal.addEventListener(\"abort\", abortListener);\n\t\t\t\t\n\t\t\t\tthis.finally(() => options.signal?.removeEventListener(\"abort\", abortListener));\n\t\t\t}\n\t\t\n\t\tif (typeof options?.timeout === \"number\" && Number.isFinite(options.timeout)) {\n\t\t\tconst timeout = setTimeout(() => this.reject(new DOMException(\"Timeout exceeded\", \"TimeoutError\")), options.timeout);\n\t\t\t\n\t\t\tthis.finally(() => clearTimeout(timeout));\n\t\t}\n\t\t\n\t\texecutor?.(this.resolve, this.reject);\n\t\t\n\t}\n\t\n\tisPending = true;\n\tisFulfilled = false;\n\tisRejected = false;\n\t\n\tstate: \"fulfilled\" | \"pending\" | \"rejected\" = \"pending\";\n\t\n\tresult?: T | unknown;\n\t\n\treadonly resolve = (value: Value<T>) => {\n\t\t\n\t\tif (this.isPending) {\n\t\t\tthis.isPending = false;\n\t\t\tthis.isFulfilled = true;\n\t\t\tthis.state = \"fulfilled\";\n\t\t\tthis.result = value;\n\t\t\t\n\t\t\tconst native = nativesMap.get(this);\n\t\t\t\n\t\t\tif (native) {\n\t\t\t\tnative.resolve.call(this, value);\n\t\t\t\tnativesMap.delete(this);\n\t\t\t}\n\t\t}\n\t\t\n\t};\n\t\n\treadonly reject = (reason?: any) => {\n\t\t\n\t\tif (this.isPending) {\n\t\t\tthis.isPending = false;\n\t\t\tthis.isRejected = true;\n\t\t\tthis.state = \"rejected\";\n\t\t\tthis.result = reason;\n\t\t\t\n\t\t\tconst native = nativesMap.get(this);\n\t\t\t\n\t\t\tif (native) {\n\t\t\t\tnative.reject.call(this, reason);\n\t\t\t\tnativesMap.delete(this);\n\t\t\t}\n\t\t}\n\t\t\n\t};\n\t\n\t\n\tstatic resolved<U>(value: U): StatefulPromise<U> {\n\t\treturn new StatefulPromise<U>(resolve => resolve(value));\n\t}\n\t\n\tstatic rejected(reason: unknown): StatefulPromise<never> {\n\t\treturn new StatefulPromise((_, reject) => reject(reason));\n\t}\n\t\n}\n", "import { noop } from \"./noop.js\";\nimport { StatefulPromise } from \"./StatefulPromise.js\";\n\n\ntype Callback = (...args: any[]) => unknown;// eslint-disable-line @typescript-eslint/no-explicit-any\ntype FunctionOrBoolean = (() => unknown) | boolean;\ntype Options = { leading?: FunctionOrBoolean; maxWait?: number; trailing?: FunctionOrBoolean };\n\ntype DebouncedFunction<C extends Callback> = {\n\t(this: ThisParameterType<C>, ...args: Parameters<C>): Promise<Awaited<ReturnType<C>>>;\n};\n\nexport type Debounced<C extends Callback, R extends ReturnType<C>> = DebouncedFunction<C> & {\n\tcallback: C;\n\tpromise: StatefulPromise<R>;\n\tresolve: (value: R) => void;\n\treject: (reason?: unknown) => void;\n\trun(): Promise<R>;\n\tclear(shouldRun?: boolean): Promise<void>;\n};\n\n\nexport function debounce<C extends Callback, R extends ReturnType<C>>(callback: C, limit = 0, options: Options = {}) {\n\tlet { leading = false, trailing = true } = options;\n\tconst { maxWait = Infinity } = options;\n\t\n\tlet timeout: ReturnType<typeof setTimeout> | undefined;\n\tlet maxWaitTimeout: ReturnType<typeof setTimeout> | undefined;\n\tlet end: number | undefined;\n\tlet context: ThisParameterType<C>;\n\tlet args: unknown[];\n\tlet initial: FunctionOrBoolean;\n\tlet final: FunctionOrBoolean;\n\tlet result: R;\n\t\n\tconst expired = async () => {\n\t\t\n\t\tconst n = Date.now();\n\t\t\n\t\tif (n >= end!) {\n\t\t\ttimeout = undefined;\n\t\t\tend = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tmaxWaitTimeout = undefined;\n\t\t\t\n\t\t\tif (typeof final == \"function\")\n\t\t\t\tawait final();\n\t\t\t\n\t\t\tdebounced.resolve(result);\n\t\t\t\n\t\t\tinitial = leading;\n\t\t} else {\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = setTimeout(expired, end! - n);\n\t\t}\n\t\t\n\t};\n\t\n\tconst maxWaitExpired = Number.isFinite(maxWait) ? () => {\n\t\t\n\t\tif (final === run)\n\t\t\tfinal = false;\n\t\t\n\t\trun();\n\t\t\n\t\tmaxWaitTimeout = setTimeout(maxWaitExpired as TimerHandler, maxWait);\n\t\t\n\t} : null;\n\t\n\tasync function run() {\n\t\ttry {\n\t\t\tresult = await callback.apply(context, args) as R;\n\t\t\t\n\t\t\treturn result;\n\t\t} catch (error) {\n\t\t\tdebounced.reject(error);\n\t\t\t\n\t\t\tthrow error;\n\t\t}\n\t}\n\t\n\tif (leading && typeof leading == \"boolean\")\n\t\tleading = run;\n\tinitial = leading;\n\t\n\tif (trailing && typeof trailing == \"boolean\")\n\t\ttrailing = run;\n\tfinal = trailing;\n\t\n\tconst debounced: Debounced<C, R> = Object.assign(function (..._args) {\n\t\targs = _args;\n\t\tcontext = this;// eslint-disable-line no-invalid-this\n\t\t\n\t\tend = Date.now() + limit;\n\t\tfinal = trailing;\n\t\t\n\t\tif (!debounced.promise.isPending)\n\t\t\tdebounced.promise = new StatefulPromise<R>((resolve, reject) => {\n\t\t\t\tdebounced.resolve = resolve;\n\t\t\t\tdebounced.reject = reject;\n\t\t\t\t\n\t\t\t\tif (typeof initial == \"function\") {\n\t\t\t\t\tinitial();\n\t\t\t\t\t\n\t\t\t\t\tinitial = false;\n\t\t\t\t\t\n\t\t\t\t\tif (final === run)\n\t\t\t\t\t\tfinal = false;\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (!timeout) {\n\t\t\t\t\ttimeout = setTimeout(expired, limit);\n\t\t\t\t\t\n\t\t\t\t\tif (maxWaitExpired)\n\t\t\t\t\t\tmaxWaitTimeout = setTimeout(maxWaitExpired, maxWait);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t});\n\t\t\n\t\treturn debounced.promise;\n\t} as DebouncedFunction<C>, {\n\t\tcallback,\n\t\tpromise: StatefulPromise.resolved(undefined as unknown as R),\n\t\tresolve: noop,\n\t\treject: noop,\n\t\trun,\n\t\tclear: async (shouldRun?: boolean) => {\n\t\t\t\n\t\t\tclearTimeout(timeout);\n\t\t\ttimeout = undefined;\n\t\t\t\n\t\t\tclearTimeout(maxWaitTimeout);\n\t\t\tmaxWaitTimeout = undefined;\n\t\t\t\n\t\t\tdebounced.resolve(shouldRun ? await run() : result);\n\t\t\t\n\t\t}\n\t});\n\t\n\treturn debounced;\n}\n\n\ndebounce.noop = Object.assign(() => { /**/ }, {\n\tcallback: noop,\n\tpromise: StatefulPromise.resolved(undefined), // eslint-disable-line unicorn/no-useless-undefined\n\tresolve: noop,\n\treject: noop,\n\trun: noop,\n\tclear: noop\n}) as Debounced<() => void, void>;\n\n\nexport function throttle(callback: Callback, limit?: number, options?: Options) {\n\treturn debounce(callback, limit, {\n\t\tmaxWait: limit,\n\t\tleading: true,\n\t\ttrailing: true,\n\t\t...options\n\t});\n}\n", "export function howmuch(number: [] | number, one: string, two: string, five: boolean | string, shouldPrintNumber = true) {\n\tif (Array.isArray(number))\n\t\tnumber = number.length;\n\t\n\tif (typeof five != \"string\") {\n\t\tshouldPrintNumber = five ?? true;\n\t\tfive = two;\n\t}\n\t\n\t\n\treturn (shouldPrintNumber ? `${number}\u00A0` : \"\") + howmuch.raw(number, one, two, five);\n}\n\nhowmuch.raw = (number: number, one: string, two: string, five = two) => {\n\tnumber = Math.abs(number);\n\tconst u = number % 10;\n\tconst d = number % 100;\n\t\n\treturn (\n\t\t(u === 1 && d !== 11) ?\n\t\t\tone :\n\t\t\t((u >= 2 && u <= 4) && !(d >= 12 && d <= 15)) ?\n\t\t\t\ttwo :\n\t\t\t\tfive\n\t);\n};\n", "export * from \"./InSite\";\nexport type { Options } from \"./types\";\nexport * from \"insite-common/frontend\";\nexport type { Options as CookieOptions } from \"insite-cookie/client\";\nexport * from \"insite-cookie/client\";\nexport * from \"insite-subscriptions-client\";\nexport * from \"insite-users-client\";\nexport * from \"insite-ws-transfers/browser\";\nexport type { Options as WSOptions } from \"insite-ws/client\";\nexport * from \"insite-ws/client\";\n"],
5
- "mappings": "iaAAA,OAAOA,MAAkB,gBCAnB,SAAUC,GAAI,CAAU,CCW9B,IAAMC,EAAa,IAAI,QAGVC,EAAP,MAAOC,UAA2B,OAAU,CACjD,YACCC,EACAC,EAAiB,CAEjB,IAAIC,EACAC,EAEJ,MAAM,CAACC,EAASC,IAAU,CACzBH,EAAgBE,EAChBD,EAAeE,CAEhB,CAAC,EAyBFC,EAAA,iBAAY,IACZA,EAAA,mBAAc,IACdA,EAAA,kBAAa,IAEbA,EAAA,aAA8C,WAE9CA,EAAA,eAESA,EAAA,eAAWC,GAAmB,CAEtC,GAAI,KAAK,UAAW,CACnB,KAAK,UAAY,GACjB,KAAK,YAAc,GACnB,KAAK,MAAQ,YACb,KAAK,OAASA,EAEd,IAAMC,EAASX,EAAW,IAAI,IAAI,EAE9BW,IACHA,EAAO,QAAQ,KAAK,KAAMD,CAAK,EAC/BV,EAAW,OAAO,IAAI,EAExB,CAED,GAESS,EAAA,cAAUG,GAAgB,CAElC,GAAI,KAAK,UAAW,CACnB,KAAK,UAAY,GACjB,KAAK,WAAa,GAClB,KAAK,MAAQ,WACb,KAAK,OAASA,EAEd,IAAMD,EAASX,EAAW,IAAI,IAAI,EAE9BW,IACHA,EAAO,OAAO,KAAK,KAAMC,CAAM,EAC/BZ,EAAW,OAAO,IAAI,EAExB,CAED,GAjEC,GAAAA,EAAW,IAAI,KAAM,CAAE,QAASK,EAAgB,OAAQC,CAAa,CAAE,EAEnEF,GAAS,OACZ,GAAIA,EAAQ,OAAO,QAClB,KAAK,OAAO,IAAI,aAAa,UAAW,YAAY,CAAC,MACjD,CACJ,IAAMS,EAAgB,IAAM,KAAK,OAAO,IAAI,aAAa,UAAW,YAAY,CAAC,EAEjFT,EAAQ,OAAO,iBAAiB,QAASS,CAAa,EAEtD,K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B,EACb,CAKA,OAAO,KAAqDG,EAAcqB,EAAY,GAAO,CAC5F,IAAMC,EAAS,IAAIxB,EAAOE,CAAO,EAEjC,OAAOqB,EACNC,EAAO,UAAU,EACjBA,CACF,CAED,EAjBCzB,EAAA,YA/HM,IAAM0B,EAANzB,EK/BP,WAAc,yBAEd,WAAc,uBACd,WAAc,8BACd,WAAc,sBACd,WAAc,8BAEd,WAAc",
6
- "names": ["EventEmitter", "noop", "nativesMap", "StatefulPromise", "_StatefulPromise", "executor", "options", "nativeResolve", "nativeReject", "resolve", "reject", "__publicField", "value", "native", "reason", "abortListener", "timeout", "_", "debounce", "callback", "limit", "options", "leading", "trailing", "maxWait", "timeout", "maxWaitTimeout", "end", "context", "args", "initial", "final", "result", "expired", "n", "debounced", "maxWaitExpired", "run", "error", "_args", "StatefulPromise", "resolve", "reject", "noop", "shouldRun", "howmuch", "number", "one", "two", "five", "shouldPrintNumber", "u", "d", "CookieSetter", "Subscription", "UsersSubscriptionGroup", "IncomingTransport", "OutgoingTransport", "WS", "login", "email", "password", "logout", "_initPromise", "_InSite", "EventEmitter", "options", "__publicField", "__privateAdd", "StatefulPromise", "wsWithOtherOptions", "cookieOptions", "users", "isPublic", "subscriptions", "incomingTransport", "outgoingTransport", "wsOptions", "WS", "Subscription", "IncomingTransport", "OutgoingTransport", "CookieSetter", "resolve", "user", "UsersSubscriptionGroup", "__privateGet", "asPromise", "inSite", "InSite"]
3
+ "sources": ["../src/InSite.ts", "../src/index.ts"],
4
+ "sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { StatefulPromise } from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport { CookieSetter } from \"insite-cookie/client\";\nimport { Subscription } from \"insite-subscriptions-client\";\nimport {\n\tUsersSubscriptionGroup,\n\ttype CurrentUser,\n\ttype Orgs,\n\ttype OrgsExtended,\n\ttype Roles,\n\ttype Users,\n\ttype UsersExtended\n} from \"insite-users-client\";\nimport { IncomingTransport, OutgoingTransport } from \"insite-ws-transfers/browser\";\nimport { WS } from \"insite-ws/client\";\nimport type { OmitRedundant, Options, WSWithActualProps } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\n/** @this InSite */\nfunction login<O extends Options<any>>(this: InSite<O>, email: string, password: string) {\n\treturn this.ws.sendRequest(\"login\", email, password);\n}\n\n/** @this InSite */\nfunction logout<O extends Options<any>>(this: InSite<O>) {\n\treturn this.ws.sendRequest(\"logout\");\n}\n\n\nexport class InSite<\n\tO extends Options<any>,\n\tAS extends AbilitiesSchema = O extends Options<infer A> ? A : never\n> extends EventEmitter {\n\tconstructor(options?: O) {\n\t\tsuper();\n\t\t\n\t\tif (options)\n\t\t\tvoid this.init(options);\n\t\t\n\t}\n\t\n\tws!: WSWithActualProps<O>;\n\tincomingTransport!: IncomingTransport;\n\toutgoingTransport!: OutgoingTransport;\n\tcookie!: CookieSetter;\n\tusersSubscriptionGroup!: UsersSubscriptionGroup;\n\tuser!: CurrentUser<AS> | null;\n\tusers!: Users | UsersExtended;\n\torgs!: Orgs | OrgsExtended;\n\troles!: Roles;\n\tisLoggedIn = false;\n\t\n\tlogin!: typeof login<O>;\n\tlogout!: typeof logout<O>;\n\t\n\tisReady = false;\n\t\n\tprotected async init(options?: O) {\n\t\t\n\t\tif (!this.isReady) {\n\t\t\tconst {\n\t\t\t\tws: wsWithOtherOptions = {},\n\t\t\t\tcookie: cookieOptions,\n\t\t\t\tusers,\n\t\t\t\tpublic: isPublic\n\t\t\t} = options ?? {};\n\t\t\t\n\t\t\tconst {\n\t\t\t\tsubscriptions,\n\t\t\t\tincomingTransport,\n\t\t\t\toutgoingTransport,\n\t\t\t\t...wsOptions\n\t\t\t} = wsWithOtherOptions;\n\t\t\t\n\t\t\tthis.ws = new WS(wsOptions) as WSWithActualProps<O>;\n\t\t\t\n\t\t\tif (subscriptions !== null)\n\t\t\t\tSubscription.bindTo(this.ws);\n\t\t\t\n\t\t\tif (incomingTransport)\n\t\t\t\tthis.incomingTransport = new IncomingTransport(this.ws, typeof incomingTransport == \"object\" ? incomingTransport : {});\n\t\t\t\n\t\t\tif (outgoingTransport)\n\t\t\t\tthis.outgoingTransport = new OutgoingTransport(this.ws);\n\t\t\t\n\t\t\tif (cookieOptions !== null)\n\t\t\t\tthis.cookie = new CookieSetter(this.ws, cookieOptions);\n\t\t\t\n\t\t\tif (users !== null && subscriptions !== null && cookieOptions !== null) {\n\t\t\t\tthis.user = null;\n\t\t\t\tthis.login = login<O>;\n\t\t\t\tthis.logout = logout<O>;\n\t\t\t\t\n\t\t\t\tif (isPublic)\n\t\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\t\t\n\t\t\t\t\t\tnew Subscription(\"object\", \"user\", [ true ], user => {\n\t\t\t\t\t\t\tthis.user = user;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (this.user) {\n\t\t\t\t\t\t\t\tif (!this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\tthis.isLoggedIn = true;\n\t\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else if (this.isLoggedIn) {\n\t\t\t\t\t\t\t\tthis.isLoggedIn = false;\n\t\t\t\t\t\t\t\tthis.emit(\"logout\", false);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (!this.isReady)\n\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t\telse {\n\t\t\t\t\tthis.usersSubscriptionGroup = new UsersSubscriptionGroup({ target: this });\n\t\t\t\t\t\n\t\t\t\t\tawait new Promise<void>(resolve => {\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.usersSubscriptionGroup.once(\"init\", () => {\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tthis.isLoggedIn = !!this.user;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tthis.usersSubscriptionGroup.on(\"update.user\", (user: CurrentUser) => {\n\t\t\t\t\t\t\t\tif (user.valueOf()) {\n\t\t\t\t\t\t\t\t\tif (!this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\t\tthis.isLoggedIn = true;\n\t\t\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else if (this.isLoggedIn) {\n\t\t\t\t\t\t\t\t\tthis.isLoggedIn = false;\n\t\t\t\t\t\t\t\t\tthis.emit(\"logout\", false);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif (this.isLoggedIn)\n\t\t\t\t\t\t\t\tthis.emit(\"login\", true);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tthis.isReady = true;\n\t\t\tthis.emit(\"ready\", true);\n\t\t\t\n\t\t\tthis.#initPromise.resolve(this);\n\t\t}\n\t\t\n\t}\n\t\n\t#initPromise = new StatefulPromise<this>();\n\t\n\twhenReady() {\n\t\treturn this.#initPromise;\n\t}\n\t\n\t\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options: IO, asPromise: true): Promise<OmitRedundant<IS, IO>>;\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options?: IO, asPromise?: false): OmitRedundant<IS, IO>;\n\tstatic init<IO extends Options<any>, IS extends InSite<IO>>(options?: IO, asPromise = false) {\n\t\tconst inSite = new InSite(options) as IS;\n\t\t\n\t\treturn asPromise ?\n\t\t\tinSite.whenReady() :\n\t\t\tinSite;\n\t}\n\t\n}\n", "export * from \"./InSite\";\nexport type { Options } from \"./types\";\nexport * from \"insite-common/frontend\";\nexport type { Options as CookieOptions } from \"insite-cookie/client\";\nexport * from \"insite-cookie/client\";\nexport * from \"insite-subscriptions-client\";\nexport * from \"insite-users-client\";\nexport * from \"insite-ws-transfers/browser\";\nexport type { Options as WSOptions } from \"insite-ws/client\";\nexport * from \"insite-ws/client\";\n"],
5
+ "mappings": "iaAAA,OAAOA,MAAkB,gBACzB,OAAS,mBAAAC,MAAuB,YAEhC,OAAS,gBAAAC,MAAoB,uBAC7B,OAAS,gBAAAC,MAAoB,8BAC7B,OACC,0BAAAC,MAOM,sBACP,OAAS,qBAAAC,EAAmB,qBAAAC,MAAyB,8BACrD,OAAS,MAAAC,MAAU,mBAQnB,SAASC,EAA+CC,EAAeC,EAAkB,CACxF,OAAO,KAAK,GAAG,YAAY,QAASD,EAAOC,CAAQ,CACpD,CAGA,SAASC,GAAgD,CACxD,OAAO,KAAK,GAAG,YAAY,QAAQ,CACpC,CA9BA,IAAAC,EAiCaC,EAAN,MAAMA,UAGHC,CAAa,CACtB,YAAYC,EAAa,CACxB,MAAM,EAOPC,EAAA,WACAA,EAAA,0BACAA,EAAA,0BACAA,EAAA,eACAA,EAAA,+BACAA,EAAA,aACAA,EAAA,cACAA,EAAA,aACAA,EAAA,cACAA,EAAA,kBAAa,IAEbA,EAAA,cACAA,EAAA,eAEAA,EAAA,eAAU,IAqGVC,EAAA,KAAAL,EAAe,IAAIM,GAxHdH,GACE,KAAK,KAAKA,CAAO,CAExB,CAkBA,MAAgB,KAAKA,EAAa,CAEjC,GAAI,CAAC,KAAK,QAAS,CAClB,GAAM,CACL,GAAII,EAAqB,CAAC,EAC1B,OAAQC,EACR,MAAAC,EACA,OAAQC,CACT,EAAIP,GAAW,CAAC,EAEV,CACL,cAAAQ,EACA,kBAAAC,EACA,kBAAAC,EACA,GAAGC,CACJ,EAAIP,EAEJ,KAAK,GAAK,IAAIQ,EAAGD,CAAS,EAEtBH,IAAkB,MACrBK,EAAa,OAAO,KAAK,EAAE,EAExBJ,IACH,KAAK,kBAAoB,IAAIK,EAAkB,KAAK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EAEjC,OAAOqB,EACNC,EAAO,UAAU,EACjBA,CACF,CAED,EAjBCzB,EAAA,YA/HM,IAAM0B,EAANzB,EC/BP,WAAc,yBAEd,WAAc,uBACd,WAAc,8BACd,WAAc,sBACd,WAAc,8BAEd,WAAc",
6
+ "names": ["EventEmitter", "StatefulPromise", "CookieSetter", "Subscription", "UsersSubscriptionGroup", "IncomingTransport", "OutgoingTransport", "WS", "login", "email", "password", "logout", "_initPromise", "_InSite", "EventEmitter", "options", "__publicField", "__privateAdd", "StatefulPromise", "wsWithOtherOptions", "cookieOptions", "users", "isPublic", "subscriptions", "incomingTransport", "outgoingTransport", "wsOptions", "WS", "Subscription", "IncomingTransport", "OutgoingTransport", "CookieSetter", "resolve", "user", "UsersSubscriptionGroup", "__privateGet", "asPromise", "inSite", "InSite"]
7
7
  }
package/package.json CHANGED
@@ -1,40 +1,57 @@
1
1
  {
2
- "name": "insite-client",
3
- "version": "2.3.3",
4
- "description": "Client-side inSite app",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.js",
8
- "packageManager": "bun@1.2.18",
9
- "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1",
11
- "build": "bun .conveyer.js",
12
- "postbuild": "tsc -p ."
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "git+https://github.com/nesvet/insite-client.git"
17
- },
18
- "keywords": [
19
- "insite",
20
- "client",
21
- "app"
22
- ],
23
- "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
24
- "license": "MIT",
25
- "dependencies": {
26
- "@nesvet/n": "^1.2.1",
27
- "eventemitter3": "^5.0.1",
28
- "insite-common": "^2.3.3",
29
- "insite-cookie": "^2.3.3",
30
- "insite-subscriptions-client": "^2.3.3",
31
- "insite-users-client": "^2.3.3",
32
- "insite-ws": "^2.3.3",
33
- "insite-ws-transfers": "^2.3.3"
34
- },
35
- "devDependencies": {
36
- "@nesvet/conveyer": "^2.6.1",
37
- "@nesvet/eslint-config": "^2.1.2",
38
- "typescript": "^5.8.3"
39
- }
2
+ "name": "insite-client",
3
+ "version": "2.4.0",
4
+ "description": "Client-side inSite SDK — WebSocket, auth, subscriptions, file transfers",
5
+ "keywords": [
6
+ "insite",
7
+ "sdk",
8
+ "client",
9
+ "websocket",
10
+ "auth",
11
+ "subscriptions"
12
+ ],
13
+ "homepage": "https://github.com/nesvet/insite#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/nesvet/insite/issues"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/nesvet/insite.git",
20
+ "directory": "packages/client"
21
+ },
22
+ "funding": {
23
+ "type": "patreon",
24
+ "url": "https://www.patreon.com/nesvet"
25
+ },
26
+ "license": "MIT",
27
+ "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
28
+ "type": "module",
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.js",
31
+ "files": [
32
+ "dist",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "bun .conveyer.js",
38
+ "postbuild": "tsc -p .",
39
+ "clean": "rm -rf dist",
40
+ "test": "echo \"Error: no test specified\" && exit 1",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "dependencies": {
44
+ "@nesvet/n": "^1.2.1",
45
+ "eventemitter3": "^5.0.4",
46
+ "insite-common": "^2.4.0",
47
+ "insite-cookie": "^2.4.0",
48
+ "insite-subscriptions-client": "^2.4.0",
49
+ "insite-users-client": "^2.4.0",
50
+ "insite-ws": "^2.4.0",
51
+ "insite-ws-transfers": "^2.4.0"
52
+ },
53
+ "packageManager": "bun@1.3.9",
54
+ "engines": {
55
+ "node": ">=20.0.0"
56
+ }
40
57
  }