insite-users-server 2.4.0 → 2.6.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/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# insite-users-server
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/insite-users-server)
|
|
4
|
+
|
|
3
5
|
Server-side core for users, organizations, roles, sessions, and avatars in the inSite stack. In-memory domain models backed by MongoDB with change streams for real-time sync, role-based abilities, and hierarchical org structure.
|
|
4
6
|
|
|
5
7
|
Part of [inSite](../../README.md) — uses [insite-db](../db/README.md) and [insite-common](../common/README.md). WebSocket integration via [insite-users-server-ws](../users-server-ws/README.md).
|
|
@@ -89,7 +91,7 @@ class Users<AS extends AbilitiesSchema> extends Map<string, User<AS>>
|
|
|
89
91
|
| `whenReady()` | Returns `Promise<Users>` for init completion |
|
|
90
92
|
| `load(userDoc)` | Loads user from doc into map |
|
|
91
93
|
| `create(newUser)` | Creates user, returns `_id` |
|
|
92
|
-
| `updateUser(_id, updates, byUser?)` | Updates user; `byUser` restricts role changes by subordination |
|
|
94
|
+
| `updateUser(_id, updates, byUser?)` | Updates user; `byUser` restricts role changes by subordination. A non-argon2 `password` is hashed in the same `$set`. Sessions are deleted only when that hash differs from the stored one |
|
|
93
95
|
| `changePassword(_id, newPassword)` | Hashes and updates password, invalidates sessions |
|
|
94
96
|
| `login(email, password, sessionProps)` | Verifies credentials, creates session |
|
|
95
97
|
| `logout(session)` | Deletes session |
|
|
@@ -141,7 +143,7 @@ class User<AS extends AbilitiesSchema>
|
|
|
141
143
|
| `slaves` | `Set<Org<AS> \| User<AS>>` | Union of slaveOrgs and slaveUsers |
|
|
142
144
|
| `slaveIds` | `string[]` | Ids of slaves |
|
|
143
145
|
| `permissiveIds` | `string[]` | Ids user can act on (org, self, slaves) |
|
|
144
|
-
| `sessions` | `Set<Session<AS>>` | Active sessions |
|
|
146
|
+
| `sessions` | `Set<Session<AS>>` | Active sessions. A missing `login.sessionsLimit` does not delete them; an explicit `0` does |
|
|
145
147
|
| `isOnline` | `boolean` | Has at least one online session |
|
|
146
148
|
| `isRoot` | `boolean` | Has root role |
|
|
147
149
|
|
|
@@ -270,7 +272,7 @@ class Session<AS extends AbilitiesSchema>
|
|
|
270
272
|
| `user` | `User<AS>` | User |
|
|
271
273
|
| `isOnline` | `boolean` | Online flag |
|
|
272
274
|
| `userAgent` | `string` | User agent |
|
|
273
|
-
| `remoteAddress` | `string` |
|
|
275
|
+
| `remoteAddress` | `string` | IPv4, or IPv6 without a zone id |
|
|
274
276
|
| `createdAt` | `number` | Timestamp |
|
|
275
277
|
| `prolongedAt` | `number` | Last prolong timestamp |
|
|
276
278
|
| `expiresAt` | `Date` | Expiry |
|
|
@@ -292,7 +294,7 @@ class Avatars
|
|
|
292
294
|
|
|
293
295
|
| Method | Description |
|
|
294
296
|
|--------|-------------|
|
|
295
|
-
| `save(_id, type, data)` | Saves base64
|
|
297
|
+
| `save(_id, type, data)` | Saves base64 webp up to 512 KiB and updates user.avatar. Another type or a larger body throws |
|
|
296
298
|
| `deleteAvatar(_id)` | Deletes avatar, clears user.avatar |
|
|
297
299
|
|
|
298
300
|
| Property | Type | Description |
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Err as
|
|
2
|
-
`);r!==U.get(this)&&(U.set(this,r),this.#e.users.isInited&&this.#e.update())}}delete(){this.#e.delete(this._id),U.delete(this),this.#e.update()}};var c={_id:/^[\dA-Fa-f]{24}$/,email:/^[^\s@]{1,63}@[^\s@]{1,63}\.[^\s@]{1,63}$/,argon2:/^\$argon2(?:i|d|id)\$v=\d+\$m=\d+,t=\d+,p=\d+(?:\$[\d+/A-Za-z]+){2}$/,sessionId:/^(?:[\dA-Fa-f]{16,32}\$[\dA-Fa-f]{16,32}|[0-9a-f]{24}~[A-Za-z0-9_-]{43})$/,role:/^[\d_a-z-]{1,64}$/,ip:/^(?:\d{1,3}\.){3}\d{1,3}$/};var u={required:["_id","involves","abilities","title","description","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c.role.source,not:{enum:["root"]}},involves:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c.role.source,not:{enum:["root"]}},additionalItems:!1},abilities:{bsonType:"object"},title:{bsonType:"string",maxLength:256},description:{bsonType:"string",maxLength:10240},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};var ue=[[{involves:1}]];function J(){throw new Error("Direct usage of roles collection.deleteOne or .deleteMany is forbidden. Use roles.deleteRole instead.")}var w=class extends Map{constructor(e,t={}){super();let{root:i,...s}=t;this.users=e,this.collections=e.collections,this.abilities=e.abilities,this.root=new m(this,{...i,_id:"root",involves:[],abilities:this.abilities.getDefaultAbilities(),title:"Root",description:"Root",meta:{},createdAt:Date.now()}),this.initOptions=s}users;collections;collection;abilities;root;initOptions;async init(){if(!this.users.isInited){let{schema:e,indexes:t,collection:i}=this.initOptions;e&&(e.required&&T(e.required,u.required),e.properties&&H(e,Object.keys(u.properties)));let s={...u,...e,required:[...u.required,...e?.required??[]],properties:{...u.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("roles",{...i,schema:s}),{deleteOne:J,deleteMany:J}),await this.collection.ensureIndexes([...ue,...t??[]]),await this.#e();for await(let o of this.collection.find())this.abilities.adjust(o.abilities)&&await this.collection.updateOne({_id:o._id},{$set:{abilities:o.abilities}}),this.load(o);this.update(),this.collection.onChange(this.#t),delete this.initOptions}}async#e(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}#t=e=>{switch(e.operationType){case"insert":{new m(this,e.fullDocument);break}case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};load(e){new m(this,e)}resolve(e,t){t=[e,...t];for(let i of e.ownInvolveIds){let s=this.get(i);if(s){for(let o of t)me(o.involves,s),this.abilities.merge(o.inheritedAbilities,s.abilities);s!==e&&this.resolve(s,t)}}}sorted=[];#i(e,t){return t.involves.size-e.involves.size||(e.title&&t.title?e.title>t.title?1:e.title<t.title?-1:0:e.title?-1:t.title||e._id>t._id?1:e._id<t._id?-1:0)}update(){let e=[...this.values()];this.root.ownInvolveIds=[];for(let s of e)s!==this.root&&!e.some(o=>o.ownInvolveIds.includes(s._id))&&this.root.ownInvolveIds.push(s._id),s.involves.clear(),s.abilities=structuredClone(s.ownAbilities),s.inheritedAbilities={};this.root.involves.add(this.root),this.resolve(this.root,[]);for(let s of e)s.ownInvolves=Z(this,s.ownInvolveIds,!0).sort(this.#i).reverse();let t=[this.root];for(let s=0;s<t.length;s++){let o=t[s];for(let r of o.ownInvolves){let a=t.indexOf(r);~a&&(t.splice(a,1),s--),t.splice(s+1,0,r)}}let i=0;for(let s of t)this.abilities.merge(s.abilities,s.inheritedAbilities),s._o=i++;this.sorted=t,this.users.isInited&&this.users.update(!0)}async create({_id:e,involves:t,title:i,description:s,...o}){return await this.collection.insertOne({_id:e,involves:t||[],abilities:{},title:i??"",description:s??"",meta:{},...H(o,["abilities"]),createdAt:Date.now()}),e}async updateRole(e,t){let i=this.get(e);if(!i)return!1;if(t.involves){T(t.involves,[e]);for(let s of t.involves)this.get(s)?.involves.has(i)&&T(t.involves,[s]);t.involves=this.cleanUpIds(t.involves)}return await this.collection.updateOne({_id:e},{$set:t}),!0}deleteRole(e){let t=typeof e=="string"?e:e._id;return this.collection.bulkWrite([{updateMany:{filter:{involves:t},update:{$pullAll:{involves:[t]}}}},{deleteOne:{filter:{_id:t}}}])}cleanUpIds(e){let t=he(this.sorted,Z(this,e,!0)),i=[];for(let s of t)t.every(o=>o===s||!o.involves.has(s))&&i.push(s._id);return i}async setAbility(e,t,i){let s=this.get(e);return s?(await this.collection.updateOne({_id:e},{$set:{abilities:i?this.abilities.setAbility(s.ownAbilities,t):this.abilities.unsetAbility(s.ownAbilities,t)}}),!0):!1}async setAbilityParam(e,t,i,s){let o=this.get(e);return o?(await this.collection.updateOne({_id:e},{$set:{abilities:this.abilities.setParam(o.ownAbilities,t,i,s)}}),!0):!1}};import{Err as E}from"@nesvet/n";var C=class extends E{constructor(e){super("Unauthorized","unauthorized",e)}name="UnauthorizedError"},j=class extends E{constructor(e,t,i){switch(arguments.length){case 1:i=e,e=void 0;break;case 2:i=t,t=void 0}super("Insubordination attempt","subordination",{...e&&{type:e},...t&&{ids:Array.isArray(t)?t:[t]},...i})}name="SubordinationError"},$=class extends E{constructor(e){super("Insufficient permissions","permissions",e)}name="PermissionError"};import{hash as te,verify as je}from"@node-rs/argon2";import $e from"eventemitter3";import{_ids as Ee,deleteProps as ie,removeAll as Me,StatefulPromise as ke,without as qe}from"@nesvet/n";import{newObjectIdString as Ge}from"insite-db";import{_ids as fe,deleteProps as X,EmptyArray as be,EmptySet as k,removeAll as ye,sort as ge,union as Ae,without as Y}from"@nesvet/n";import{newObjectIdString as Se}from"insite-db";var M=new WeakMap,p=class{constructor(e,t){this.orgs=e,this._id=t._id,e.set(this._id,this),this.update(t)}_id;title="";initials="";displayLabel="";_o=0;orgs;isOrg=!0;ownerOrgs=new Set;ownerUsers=new Set;users=new Set;slaveOrgs=new Set;ownerIds=[];update({_id:e,title:t,owners:i,...s}){if(Object.assign(this,s),t!==void 0&&(this.title=t,this.initials=t?.[0]?.toUpperCase()??"",this.displayLabel=t),i){this.ownerIds=i;let o=this.ownerIds.join(",");o!==M.get(this)&&(M.set(this,o),this.orgs.users.isInited&&this.orgs.update())}}async delete(){this.orgs.delete(this._id),M.delete(this),await this.orgs.replace(this._id),this.orgs.update()}};var f={required:["_id","title","note","owners","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c._id.source},title:{bsonType:"string",maxLength:512},note:{bsonType:"string",maxLength:131072},owners:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c._id.source},additionalItems:!1},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};var we=[[{owners:1}]];function Q(){throw new Error("Direct usage of orgs collection.deleteOne or .deleteMany is forbidden. Use orgs.deleteOrg instead.")}var v=class extends Map{constructor(e,t={}){super(),this.users=e,this.collections=e.collections,this.preinitOptions=t}users;collections;preinitOptions;collection;null;#e=!1;async preinit(){if(!this.#e){this.#e=!0;let{schema:e,indexes:t,null:i,collection:s}=this.preinitOptions;e&&(e.required&&ye(e.required,f.required),e.properties&&X(e,Object.keys(f.properties)));let o={...f,...e,required:[...f.required,...e?.required??[]],properties:{...f.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("orgs",{...s,schema:o}),{deleteOne:Q,deleteMany:Q}),await this.collection.ensureIndexes([...we,...t??[]]),this.null=Object.assign(new p(this,{...i,_id:"",title:"",note:"",owners:[],meta:{},createdAt:Date.now()}),{_id:null,ownerIds:new be,ownerOrgs:new k,ownerUsers:new k,slaveOrgs:new k}),await this.#t();for await(let r of this.collection.find())this.load(r);delete this.preinitOptions}}async#t(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}init(){this.users.isInited||(this.update(),this.collection.onChange(this.#i))}#i=e=>{switch(e.operationType){case"insert":{new p(this,e.fullDocument);break}case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};load(e){new p(this,e)}#o(e,t){t=[e,...t];for(let i of e.ownerOrgs){this.#o(i,t);for(let s of t)i.slaveOrgs.add(s)}}sorted=[];update(){let e=[...this.values()],t=[];for(let i of e){i.ownerOrgs.clear(),i.ownerUsers.clear(),i.slaveOrgs.clear();for(let s of i.ownerIds){let o=this.get(s);if(o)i.ownerOrgs.add(o);else{let r=this.users.get(s);r&&i.ownerUsers.add(r)}}!i.ownerOrgs.size&&i._id&&t.push(i)}for(let i of e)e.some(s=>s.ownerOrgs.has(i))||this.#o(i,[]);t.sort(this.#s);for(let i of e)ge(i.slaveOrgs,this.#s);for(let i=0;i<t.length;i++){let s=t[i];for(let o of[...s.slaveOrgs].reverse())if(o.ownerOrgs.has(s)){let r=t.indexOf(o);~r&&(t.splice(r,1),i--),t.splice(i+1,0,o)}}for(let i=0,{length:s}=t;i<s;)t[i]._o=i++;this.sorted=t,this.users.isInited&&this.users.update()}#s(e,t){return t.slaveOrgs.size-e.slaveOrgs.size||(e.title>t.title?1:e.title<t.title?-1:0)}async create({title:e,note:t,...i}){let s=Se();return await this.collection.insertOne({_id:s,title:e??"",note:t??"",meta:{},...X(i,["_id"]),createdAt:Date.now()}),s}async updateOrg(e,t,i){let s=this.get(e);return s?(t.owners&&(t.owners=this.users.sortIds(Ae(i?Y(s.ownerIds,i.slaveIds):[],Y(t.owners,[e,...fe(s.slaveOrgs)])))),await this.collection.updateOne({_id:e},{$set:t}),!0):!1}deleteOrg(e){let t=typeof e=="string"?e:e._id;return this.collection.bulkWrite([{updateMany:{filter:{owners:t},update:{$pullAll:{owners:[t]}}}},{deleteOne:{filter:{_id:t}}}])}replaceMap=new Map;replaceHandlers=new Set;async replace(e){let t=this.replaceMap.get(e)??null;t&&this.replaceMap.delete(e);for(let i of this.replaceHandlers)await i(e,t)}};import{randomBytes as ve}from"node:crypto";import{deleteProps as Oe,removeAll as _e}from"@nesvet/n";import{newObjectIdString as Pe}from"insite-db";var b={required:["_id","user","remoteAddress","isOnline","meta","createdAt","prolongedAt","expiresAt"],properties:{_id:{bsonType:"string",pattern:c.sessionId.source},user:{bsonType:"string",pattern:c._id.source},userAgent:{bsonType:"string",maxLength:4096},remoteAddress:{bsonType:"string",pattern:c.ip.source},isOnline:{bsonType:"bool"},meta:{bsonType:"object"},createdAt:{bsonType:"number"},prolongedAt:{bsonType:"number"},expiresAt:{bsonType:"date"}}};var y=class{constructor(e,t){let i=e.users.get(t.user);i?(this.#e=e,this._id=t._id,this.#e.set(this._id,this),this.user=i,this.user.sessions.add(this),this.#e.users.bySessionId.set(this._id,this.user),this.update(t)):e.collection.deleteOne({_id:t._id})}_id;user;isOnline=!1;userAgent;remoteAddress;createdAt;prolongedAt;expiresAt;#e;update({_id:e,user:t,isOnline:i,...s}){i!==void 0&&this.isOnline!==i&&(this.isOnline=i,this.#e.users.isInited&&this.user.isOnline!==this.isOnline&&this.user.updateIsOnlineDebounced()),Object.assign(this,s)}prolong({_id:e,user:t,...i}){let s=Date.now();return i.prolongedAt=s,i.expiresAt=new Date(s+this.#e.collection.expireAfterSeconds*1e3),this.update(i),this.#e.collection.updateOne({_id:this._id},{$set:i})}async online(){if(!this.isOnline){let e={isOnline:!0};this.update(e),await this.#e.collection.updateOne({_id:this._id},{$set:e})}}async offline(){if(this.isOnline){let e={isOnline:!1};this.update(e),await this.#e.collection.updateOne({_id:this._id},{$set:e})}}delete(){this.#e.delete(this._id),this.user.sessions.delete(this),this.#e.users.bySessionId.delete(this._id),this.#e.users.emit("session-delete",this),this.isOnline&&this.user.updateIsOnline()}};var q=3600*24*7,xe=[[{user:1}],[{expiresAt:1},{expireAfterSeconds:q}]],O=class extends Map{constructor(e,t={}){super(),this.users=e,this.collections=e.collections,this.initOptions=t}users;collections;initOptions;collection;async init(){if(!this.users.isInited){let{schema:e,indexes:t,collection:i}=this.initOptions;e&&(e.required&&_e(e.required,b.required),e.properties&&Oe(e,Object.keys(b.properties)));let s={...b,...e,required:[...b.required,...e?.required??[]],properties:{...b.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("sessions",{...i,schema:s}),{expireAfterSeconds:q}),await this.collection.ensureIndexes([...xe,...t??[]]),await this.#e();for await(let o of this.collection.find())this.load(o);this.collection.onChange(this.#t),delete this.initOptions}}async#e(){await this.collection.bulkWrite([{updateMany:{filter:{meta:{$exists:!1}},update:{$set:{meta:{}}}}},{updateMany:{filter:{isOnline:!0},update:{$set:{isOnline:!1}}}}])}#t=e=>{switch(e.operationType){case"insert":this.has(e.documentKey._id)||new y(this,e.fullDocument),this.users.get(e.fullDocument.user)?.trimSessions();break;case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};uid(){return`${Pe()}~${ve(32).toString("base64url")}`}load(e){new y(this,e)}async create(e,t){let i=Date.now(),s={userAgent:"",remoteAddress:"127.0.0.1",isOnline:!0,...t,_id:this.uid(),user:e._id,meta:{},createdAt:i,prolongedAt:i,expiresAt:new Date(i+q*1e3)},o=new y(this,s);return await this.collection.insertOne(s),o}async destroySession(e){let{deletedCount:t}=await this.collection.deleteOne({_id:e});return!!t}};import{Binary as De}from"insite-db";var V={required:["_id","type","size","ts","data","meta"],properties:{_id:{bsonType:"string",pattern:c._id.source},type:{bsonType:"string",maxLength:256},size:{bsonType:"number"},ts:{bsonType:"string",maxLength:10},data:{bsonType:"binData"},meta:{bsonType:"object"}},additionalProperties:!1};var _=class{constructor(e,t={}){this.#e=e,this.collections=e.collections,this.initOptions=t}TYPES_ACCEPTED=["image/webp"];MAX_SIZE=1024*512;#e;collections;collection;initOptions;async init(){if(!this.#e.isInited){let{collection:e}=this.initOptions;this.collection=await this.collections.ensure("users.avatars",{...e,schema:V}),await this.#t()}}async#t(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}async save(e,t,i){let s=De.createFromBase64(i.slice(i.indexOf(","))),o=Date.now().toString(36);await Promise.all([this.collection.replaceOne({_id:e},{type:t,size:s.length(),ts:o,data:s,meta:{}},{upsert:!0}),this.#e.collection.updateOne({_id:e},{$set:{avatar:o}})])}async deleteAvatar(e){let[{deletedCount:t}]=await Promise.all([this.collection.deleteOne({_id:e}),this.#e.collection.updateOne({_id:e},{$set:{avatar:null}})]);return!!t}};var g={required:["_id","email","password","roles","name","org","job","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c._id.source},email:{bsonType:"string",pattern:c.email.source},password:{bsonType:"string",pattern:c.argon2.source},roles:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c.role.source},additionalItems:!1},name:{bsonType:"object",required:["first","middle","last"],properties:{first:{bsonType:"string",maxLength:512},middle:{bsonType:"string",maxLength:512},last:{bsonType:"string",maxLength:512}},additionalProperties:!1},org:{oneOf:[{bsonType:"string",pattern:c._id.source},{bsonType:"null"}]},job:{bsonType:"string",maxLength:512},avatar:{oneOf:[{bsonType:"string",maxLength:10},{bsonType:"null"}]},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};import{_ids as ee,debounce as Ie,empty as Re,hasAny as Ue,removeOne as Te}from"@nesvet/n";var G=new WeakMap,N=new WeakMap,Ce=process.env.INSITE_STATIC_URL??"",h=class{constructor(e,t){this.#e=e,this._id=t._id,e.set(this._id,this),this.update(t),e.isInited&&e.emit("user-create",this)}_id;email;name={first:"",middle:"",last:""};initials="";displayLabel="";org;job="";avatar=null;avatarUrl=null;#e;isUser=!0;isRoot;roles=new Set;ownRoles=[];ownRoleIds=[];slaveRoles=new Set;slaveRoleIds=[];abilities={};slaveOrgs=new Set;slaveUsers=new Set;slaves=new Set;slaveIds=[];permissiveIds=[];sessions=new Set;isOnline=!1;update({_id:e,name:t,email:i,roles:s,org:o,avatar:r,...a}){Object.assign(this,a);let n;i&&this.email!==i&&(this.#e.byEmail.delete(this.email),this.email=i,this.#e.byEmail.set(i,this),n=!0);let d,A;t&&(this.name.first!==t.first||this.name.middle!==t.middle||this.name.last!==t.last)&&(A=this.name.last!==t.last,this.name={first:t.first??"",middle:t.middle??"",last:t.last??""},this.initials=((t.first?.[0]??"")+(t.last?.[0]??"")||this.email[0]).toUpperCase(),d=!0),(n||d)&&(this.displayLabel=`${this.name.first} ${this.name.last}`.trim()||this.name.middle||this.email);let W;if(s){this.ownRoleIds=s;let K=this.ownRoleIds.join(",");K!==G.get(this)&&(G.set(this,K),this.#e.isInited&&(this.updateRoles(),W=!0))}let z;o!==void 0&&this.org?._id!==o&&(this.org?.users.delete(this),this.org=o&&this.#e.orgs.get(o)||this.#e.orgs.null,this.org.users.add(this),z=!0),r!==void 0&&this.avatar!==r&&(this.avatar=r,this.avatarUrl=r&&`${Ce}/avatars/${this._id}-${r}.webp`),this.#e.isInited&&(W||z?(this.updatePermissions(),A&&(this.#e.isSortRequired=!0),this.#e.update()):A&&this.#e.sort())}updateRoles(){this.ownRoles=[],this.roles.clear(),this.slaveRoles.clear(),Re(this.abilities);for(let e of this.ownRoleIds){let t=this.#e.roles.get(e);if(t){this.ownRoles.push(t),this.roles.add(t);for(let i of t.involves)this.roles.add(i),this.slaveRoles.add(i);this.slaveRoleIds=ee(this.slaveRoles),this.#e.abilities.merge(this.abilities,t.abilities)}}this.roles.has(this.#e.roles.root)&&(this.isRoot=!0),this.trimSessions()}updatePermissions(){this.slaveOrgs.clear(),this.slaveUsers.clear(),this.slaves.clear();let e=new Set;for(let s of this.#e.orgs.sorted)if((s.ownerUsers.has(this)||this.isRoot)&&!this.slaveOrgs.has(s)){this.slaveOrgs.add(s),this.slaves.add(s),e.add(s._id);for(let o of s.slaveOrgs)this.slaveOrgs.add(o),this.slaves.add(o),e.add(o._id)}for(let s of new Set([this.org,...this.slaveOrgs,this.#e.orgs.null]))for(let o of s.users)o!==this&&(Ue(this.slaveRoles,o.ownRoles)||!o.ownRoles.length)&&(this.slaveUsers.add(o),this.slaves.add(o),e.add(o._id));this.slaveIds=[...e];let t=[];if(this.org._id){t.push(this.org._id);for(let s of this.org.slaveOrgs)this.slaveOrgs.has(s)||t.push(s._id)}this.permissiveIds=[...t,this._id,...e];let i=[this.permissiveIds.join(","),this.ownRoleIds.join(","),JSON.stringify(this.abilities),this.slaveRoleIds.join(",")].join(`
|
|
3
|
-
`);
|
|
1
|
+
import{Err as oe}from"@nesvet/n";var x=class extends oe{constructor(e,i){typeof e=="object"&&(i=e,e=void 0),super("User lacks ability","lacksability",{...e&&{ability:e},...i})}name="AbilityError"};import{add as re,assignPath as ne,deletePath as ae,empty as le,getPath as B,intersection as ce,pick as de,setPath as pe}from"@nesvet/n";function D(l){return typeof l=="object"}function I(l){return typeof l=="number"}function R(l){return Array.isArray(l)}var H=new Map,S=class extends Map{constructor(e){super();for(let i of e)delete i.top,this.#e.push(i);(function i(t,s,o){for(let r of t){if(H.set(r,s),r.level=o,!s||r.top){if(r.longId=r._id,this.has(r._id))throw new Error(`Top-level ability duplicate: ${r._id}`);this.set(r._id,r)}else r.longId=s?`${s.longId}.${r._id}`:r._id;r.abilities&&i.call(this,r.abilities,r,o+1)}}).call(this,e,null,0)}#e=[];get(e,i){let t=e.split("."),s=i??super.get(t.shift());if(s&&t.length){for(let o of t)if(s=s?.abilities?.find(({_id:r,top:a})=>!a&&r===o),!s)break}return s}getSchema=this.get;getParamSchema(e,i){return this.get(e)?.params?.find(({_id:t})=>t===i)}getDefaultParam(e,i,t){(i===void 0||typeof i=="boolean")&&(t=i);let s=typeof e=="string"?this.getParamSchema(e,i):e;if(s)switch(s.type){case"number":return t?s.max??1/0:s.min??0;case"items":return t?s.items.map(({_id:o})=>o):[]}}getDefaultAbility(e,i=!e){if(typeof e=="string"&&(e=this.get(e)),e){if(e.abilities||e.params){let t={};if(e.params)for(let s of e.params)t[s._id]=this.getDefaultParam(s,i);if(i&&e.abilities)for(let s of e.abilities)s.top||(t[s._id]=this.getDefaultAbility(s,i));return t}return!0}}getDefaultAbilities(e,i=!e){let t=(e?(Array.isArray(e)?e:[e]).map(o=>typeof o=="string"?this.get(o):o).filter(Boolean):[...this.values()]).sort((o,r)=>o.level-r.level),s=new Map;for(let o of t)(function r(a){let n=H.get(a);n&&(r(n),s.has(n)||s.set(n,!1))})(o),i?(function r(a){if(s.has(a)||s.set(a,!0),a.abilities)for(let n of a.abilities)n.top&&r(n)})(o):s.has(o)||s.set(o,!1);return ne({},Object.fromEntries([...s].map(([o,r])=>[o.longId,this.getDefaultAbility(o,r)])))}getSchemeFor(e){return e=this.adjust(structuredClone(e)),(function i(t,s){for(let o=0;o<t.length;o++){let r=t[o],a=r.top?e[r._id]:s[r._id];if(a){if(r.params)for(let n of r.params){let d=a[n._id];switch(n.type){case"number":n.max=d;break;case"items":n.items=n.items.filter(({_id:A})=>d.includes(A))}}r.abilities&&(i(r.abilities,a),r.abilities.length||delete r.abilities)}else t.splice(o--,1)}return t})(structuredClone(this.#e),e)}getParam(e,i,t){if(this.getParamSchema(i,t)){let s=B(e,`${i}.${t}`);return this.isParamFits(i,t,s)?s:this.getDefaultParam(i,t)}}setParam(e,i,t,s){let o=this.getParamSchema(i,t);if(!o)throw new Error(`No such ability param: ${i}.${t}`);return pe(e,`${i}.${t}`,this.adjustParam(o,s)),e}isParamFits(e,i,t,s){if(t!==void 0){let o=this.getParamSchema(e,i);if(o)switch(o.type){case"number":return I(t)&&(o.min===void 0||t>=o.min)&&(s===void 0?o.max===void 0||t<=o.max:t<=s);case"items":return R(t)&&t.length===new Set(t).size&&(s===void 0?t.every(r=>o.items.find(({_id:a})=>a===r)):t.every(r=>s.includes(r)))}}return!1}adjustParam(e,i){return e.type==="number"?I(i)?Math.max(Math.min(i,e.max??1/0),e.min??0):e.min??0:R(i)?ce(e.items.map(t=>t._id),i):[]}adjust(e,i){let t={};for(let[s,o]of Object.entries(e)){let r=this.get(s,i);if(r)if(r.params||r.abilities){let a={};if(r.params)if(D(o))for(let n of r.params)a[n._id]=this.adjustParam(n,o[n._id]);else for(let n of r.params)a[n._id]=this.getDefaultParam(n);r.abilities&&D(o)&&Object.assign(a,this.adjust(de(o,r.abilities.filter(n=>!n.top).map(n=>n._id)),r)),t[s]=a}else t[s]=!0}return Object.assign(le(e),t)}merge(e,i,t){t||(this.adjust(e),i=this.adjust(structuredClone(i)));for(let[s,o]of Object.entries(i)){let r=this.get(s,t);if(r&&r.isInheritable!==!1)if(s in e&&(r.params||r.abilities)){let a=e[s],n=o;if(r.params){for(let d of r.params)if(d.isInheritable!==!1)switch(d.type){case"number":a[d._id]=Math.max(a[d._id],n[d._id]);break;case"items":re(a[d._id],...n[d._id])}}r.abilities&&this.merge(a,n,r)}else e[s]=o}return e}hasAbility(e,i){return!!B(e,i)}setAbility(e,i){let t=typeof i=="string"?this.get(i):i;if(!t)throw new Error(`No such ability: ${i}`);return this.merge(e,this.getDefaultAbilities(t)),e}unsetAbility(e,i){let t=typeof i=="string"?this.get(i):i;if(!t)throw new Error(`No such ability: ${i}`);return(function s(o){if(ae(e,o.longId),o.abilities)for(let r of o.abilities)s(r)})(t),e}};import{Err as he}from"@nesvet/n";var U=class extends he{constructor(e,i){super(`User lacks role${Array.isArray(e)?"s":""}`,"lacksroles",{roles:Array.isArray(e)?e:[e],...i})}name="RolesError"};import{deleteProps as Z,getAll as J,intersection as me,reAdd as ue,removeAll as C}from"@nesvet/n";var T=new WeakMap,m=class{constructor(e,i){this.#e=e,this._id=i._id,e.set(this._id,this),this.update(i)}#e;_id;ownInvolveIds;ownAbilities;title="";displayTitle="";_o=0;ownInvolves=[];involves=new Set;abilities={};inheritedAbilities={};update({_id:e,involves:i,abilities:t,title:s,...o}){if(Object.assign(this,o),i&&(this.ownInvolveIds=i),t&&(this.ownAbilities=typeof t=="object"?this.#e.abilities.adjust(t):t),s!==void 0&&(this.title=s,this.displayTitle=s||this._id),i||t){let r=[this.ownInvolveIds.join(","),JSON.stringify(this.ownAbilities)].join(`
|
|
2
|
+
`);r!==T.get(this)&&(T.set(this,r),this.#e.users.isInited&&this.#e.update())}}delete(){this.#e.delete(this._id),T.delete(this),this.#e.update()}};var c={_id:/^[\dA-Fa-f]{24}$/,email:/^[^\s@]{1,63}@[^\s@]{1,63}\.[^\s@]{1,63}$/,argon2:/^\$argon2(?:i|d|id)\$v=\d+\$m=\d+,t=\d+,p=\d+(?:\$[\d+/A-Za-z]+){2}$/,sessionId:/^(?:[\dA-Fa-f]{16,32}\$[\dA-Fa-f]{16,32}|[0-9a-f]{24}~[A-Za-z0-9_-]{43})$/,role:/^[\d_a-z-]{1,64}$/,ip:/^(?:(?:\d{1,3}\.){3}\d{1,3}|(?:[\dA-Fa-f]{0,4}:){2,7}[\dA-Fa-f]{0,4})$/};var u={required:["_id","involves","abilities","title","description","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c.role.source,not:{enum:["root"]}},involves:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c.role.source,not:{enum:["root"]}},additionalItems:!1},abilities:{bsonType:"object"},title:{bsonType:"string",maxLength:256},description:{bsonType:"string",maxLength:10240},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};var fe=[[{involves:1}]];function X(){throw new Error("Direct usage of roles collection.deleteOne or .deleteMany is forbidden. Use roles.deleteRole instead.")}var w=class extends Map{constructor(e,i={}){super();let{root:t,...s}=i;this.users=e,this.collections=e.collections,this.abilities=e.abilities,this.root=new m(this,{...t,_id:"root",involves:[],abilities:this.abilities.getDefaultAbilities(),title:"Root",description:"Root",meta:{},createdAt:Date.now()}),this.initOptions=s}users;collections;collection;abilities;root;initOptions;async init(){if(!this.users.isInited){let{schema:e,indexes:i,collection:t}=this.initOptions;e&&(e.required&&C(e.required,u.required),e.properties&&Z(e,Object.keys(u.properties)));let s={...u,...e,required:[...u.required,...e?.required??[]],properties:{...u.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("roles",{...t,schema:s}),{deleteOne:X,deleteMany:X}),await this.collection.ensureIndexes([...fe,...i??[]]),await this.#e();for await(let o of this.collection.find())this.abilities.adjust(o.abilities)&&await this.collection.updateOne({_id:o._id},{$set:{abilities:o.abilities}}),this.load(o);this.update(),this.collection.onChange(this.#i),delete this.initOptions}}async#e(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}#i=e=>{switch(e.operationType){case"insert":{new m(this,e.fullDocument);break}case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};load(e){new m(this,e)}resolve(e,i){i=[e,...i];for(let t of e.ownInvolveIds){let s=this.get(t);if(s){for(let o of i)ue(o.involves,s),this.abilities.merge(o.inheritedAbilities,s.abilities);s!==e&&this.resolve(s,i)}}}sorted=[];#t(e,i){return i.involves.size-e.involves.size||(e.title&&i.title?e.title>i.title?1:e.title<i.title?-1:0:e.title?-1:i.title||e._id>i._id?1:e._id<i._id?-1:0)}update(){let e=[...this.values()];this.root.ownInvolveIds=[];for(let s of e)s!==this.root&&!e.some(o=>o.ownInvolveIds.includes(s._id))&&this.root.ownInvolveIds.push(s._id),s.involves.clear(),s.abilities=structuredClone(s.ownAbilities),s.inheritedAbilities={};this.root.involves.add(this.root),this.resolve(this.root,[]);for(let s of e)s.ownInvolves=J(this,s.ownInvolveIds,!0).sort(this.#t).reverse();let i=[this.root];for(let s=0;s<i.length;s++){let o=i[s];for(let r of o.ownInvolves){let a=i.indexOf(r);~a&&(i.splice(a,1),s--),i.splice(s+1,0,r)}}let t=0;for(let s of i)this.abilities.merge(s.abilities,s.inheritedAbilities),s._o=t++;this.sorted=i,this.users.isInited&&this.users.update(!0)}async create({_id:e,involves:i,title:t,description:s,...o}){return await this.collection.insertOne({_id:e,involves:i||[],abilities:{},title:t??"",description:s??"",meta:{},...Z(o,["abilities"]),createdAt:Date.now()}),e}async updateRole(e,i){let t=this.get(e);if(!t)return!1;if(i.involves){C(i.involves,[e]);for(let o of i.involves)this.get(o)?.involves.has(t)&&C(i.involves,[o]);i.involves=this.cleanUpIds(i.involves)}let{abilities:s}=i;return s&&typeof s=="object"&&(i.abilities=this.abilities.adjust(s)),await this.collection.updateOne({_id:e},{$set:i}),!0}deleteRole(e){let i=typeof e=="string"?e:e._id;return this.collection.bulkWrite([{updateMany:{filter:{involves:i},update:{$pullAll:{involves:[i]}}}},{deleteOne:{filter:{_id:i}}}])}cleanUpIds(e){let i=me(this.sorted,J(this,e,!0)),t=[];for(let s of i)i.every(o=>o===s||!o.involves.has(s))&&t.push(s._id);return t}async setAbility(e,i,t){let s=this.get(e);return s?(await this.collection.updateOne({_id:e},{$set:{abilities:t?this.abilities.setAbility(s.ownAbilities,i):this.abilities.unsetAbility(s.ownAbilities,i)}}),!0):!1}async setAbilityParam(e,i,t,s){let o=this.get(e);return o?(await this.collection.updateOne({_id:e},{$set:{abilities:this.abilities.setParam(o.ownAbilities,i,t,s)}}),!0):!1}};import{Err as M}from"@nesvet/n";var j=class extends M{constructor(e){super("Unauthorized","unauthorized",e)}name="UnauthorizedError"},$=class extends M{constructor(e,i,t){switch(arguments.length){case 1:t=e,e=void 0;break;case 2:t=i,i=void 0}super("Insubordination attempt","subordination",{...e&&{type:e},...i&&{ids:Array.isArray(i)?i:[i]},...t})}name="SubordinationError"},E=class extends M{constructor(e){super("Insufficient permissions","permissions",e)}name="PermissionError"};import{hash as _,verify as te}from"@node-rs/argon2";import $e from"eventemitter3";import{_ids as Ee,deleteProps as se,removeAll as Me,StatefulPromise as ke,without as qe}from"@nesvet/n";import{newObjectIdString as Ge}from"insite-db";import{_ids as be,deleteProps as Y,EmptyArray as ye,EmptySet as q,removeAll as ge,sort as Ae,union as Se,without as Q}from"@nesvet/n";import{newObjectIdString as we}from"insite-db";var k=new WeakMap,p=class{constructor(e,i){this.orgs=e,this._id=i._id,e.set(this._id,this),this.update(i)}_id;title="";initials="";displayLabel="";_o=0;orgs;isOrg=!0;ownerOrgs=new Set;ownerUsers=new Set;users=new Set;slaveOrgs=new Set;ownerIds=[];update({_id:e,title:i,owners:t,...s}){if(Object.assign(this,s),i!==void 0&&(this.title=i,this.initials=i?.[0]?.toUpperCase()??"",this.displayLabel=i),t){this.ownerIds=t;let o=this.ownerIds.join(",");o!==k.get(this)&&(k.set(this,o),this.orgs.users.isInited&&this.orgs.update())}}async delete(){this.orgs.delete(this._id),k.delete(this),await this.orgs.replace(this._id),this.orgs.update()}};var f={required:["_id","title","note","owners","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c._id.source},title:{bsonType:"string",maxLength:512},note:{bsonType:"string",maxLength:131072},owners:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c._id.source},additionalItems:!1},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};var ve=[[{owners:1}]];function V(){throw new Error("Direct usage of orgs collection.deleteOne or .deleteMany is forbidden. Use orgs.deleteOrg instead.")}var v=class extends Map{constructor(e,i={}){super(),this.users=e,this.collections=e.collections,this.preinitOptions=i}users;collections;preinitOptions;collection;null;#e=!1;async preinit(){if(!this.#e){this.#e=!0;let{schema:e,indexes:i,null:t,collection:s}=this.preinitOptions;e&&(e.required&&ge(e.required,f.required),e.properties&&Y(e,Object.keys(f.properties)));let o={...f,...e,required:[...f.required,...e?.required??[]],properties:{...f.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("orgs",{...s,schema:o}),{deleteOne:V,deleteMany:V}),await this.collection.ensureIndexes([...ve,...i??[]]),this.null=Object.assign(new p(this,{...t,_id:"",title:"",note:"",owners:[],meta:{},createdAt:Date.now()}),{_id:null,ownerIds:new ye,ownerOrgs:new q,ownerUsers:new q,slaveOrgs:new q}),await this.#i();for await(let r of this.collection.find())this.load(r);delete this.preinitOptions}}async#i(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}init(){this.users.isInited||(this.update(),this.collection.onChange(this.#t))}#t=e=>{switch(e.operationType){case"insert":{new p(this,e.fullDocument);break}case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};load(e){new p(this,e)}#o(e,i){i=[e,...i];for(let t of e.ownerOrgs){this.#o(t,i);for(let s of i)t.slaveOrgs.add(s)}}sorted=[];update(){let e=[...this.values()],i=[];for(let t of e){t.ownerOrgs.clear(),t.ownerUsers.clear(),t.slaveOrgs.clear();for(let s of t.ownerIds){let o=this.get(s);if(o)t.ownerOrgs.add(o);else{let r=this.users.get(s);r&&t.ownerUsers.add(r)}}!t.ownerOrgs.size&&t._id&&i.push(t)}for(let t of e)e.some(s=>s.ownerOrgs.has(t))||this.#o(t,[]);i.sort(this.#s);for(let t of e)Ae(t.slaveOrgs,this.#s);for(let t=0;t<i.length;t++){let s=i[t];for(let o of[...s.slaveOrgs].reverse())if(o.ownerOrgs.has(s)){let r=i.indexOf(o);~r&&(i.splice(r,1),t--),i.splice(t+1,0,o)}}for(let t=0,{length:s}=i;t<s;)i[t]._o=t++;this.sorted=i,this.users.isInited&&this.users.update()}#s(e,i){return i.slaveOrgs.size-e.slaveOrgs.size||(e.title>i.title?1:e.title<i.title?-1:0)}async create({title:e,note:i,...t}){let s=we();return await this.collection.insertOne({_id:s,title:e??"",note:i??"",meta:{},...Y(t,["_id"]),createdAt:Date.now()}),s}async updateOrg(e,i,t){let s=this.get(e);return s?(i.owners&&(i.owners=this.users.sortIds(Se(t?Q(s.ownerIds,t.slaveIds):[],Q(i.owners,[e,...be(s.slaveOrgs)])))),await this.collection.updateOne({_id:e},{$set:i}),!0):!1}deleteOrg(e){let i=typeof e=="string"?e:e._id;return this.collection.bulkWrite([{updateMany:{filter:{owners:i},update:{$pullAll:{owners:[i]}}}},{deleteOne:{filter:{_id:i}}}])}replaceMap=new Map;replaceHandlers=new Set;async replace(e){let i=this.replaceMap.get(e)??null;i&&this.replaceMap.delete(e);for(let t of this.replaceHandlers)await t(e,i)}};import{randomBytes as Oe}from"node:crypto";import{deleteProps as Pe,removeAll as _e}from"@nesvet/n";import{newObjectIdString as xe}from"insite-db";var b={required:["_id","user","remoteAddress","isOnline","meta","createdAt","prolongedAt","expiresAt"],properties:{_id:{bsonType:"string",pattern:c.sessionId.source},user:{bsonType:"string",pattern:c._id.source},userAgent:{bsonType:"string",maxLength:4096},remoteAddress:{bsonType:"string",pattern:c.ip.source},isOnline:{bsonType:"bool"},meta:{bsonType:"object"},createdAt:{bsonType:"number"},prolongedAt:{bsonType:"number"},expiresAt:{bsonType:"date"}}};var y=class{constructor(e,i){let t=e.users.get(i.user);t?(this.#e=e,this._id=i._id,this.#e.set(this._id,this),this.user=t,this.user.sessions.add(this),this.#e.users.bySessionId.set(this._id,this.user),this.update(i)):e.collection.deleteOne({_id:i._id})}_id;user;isOnline=!1;userAgent;remoteAddress;createdAt;prolongedAt;expiresAt;#e;update({_id:e,user:i,isOnline:t,...s}){t!==void 0&&this.isOnline!==t&&(this.isOnline=t,this.#e.users.isInited&&this.user.isOnline!==this.isOnline&&this.user.updateIsOnlineDebounced()),Object.assign(this,s)}prolong({_id:e,user:i,...t}){let s=Date.now();return t.prolongedAt=s,t.expiresAt=new Date(s+this.#e.collection.expireAfterSeconds*1e3),this.update(t),this.#e.collection.updateOne({_id:this._id},{$set:t})}async online(){if(!this.isOnline){let e={isOnline:!0};this.update(e),await this.#e.collection.updateOne({_id:this._id},{$set:e})}}async offline(){if(this.isOnline){let e={isOnline:!1};this.update(e),await this.#e.collection.updateOne({_id:this._id},{$set:e})}}delete(){this.#e.delete(this._id),this.user.sessions.delete(this),this.#e.users.bySessionId.delete(this._id),this.#e.users.emit("session-delete",this),this.isOnline&&this.user.updateIsOnline()}};var G=3600*24*7,De=[[{user:1}],[{expiresAt:1},{expireAfterSeconds:G}]],O=class extends Map{constructor(e,i={}){super(),this.users=e,this.collections=e.collections,this.initOptions=i}users;collections;initOptions;collection;async init(){if(!this.users.isInited){let{schema:e,indexes:i,collection:t}=this.initOptions;e&&(e.required&&_e(e.required,b.required),e.properties&&Pe(e,Object.keys(b.properties)));let s={...b,...e,required:[...b.required,...e?.required??[]],properties:{...b.properties,...e?.properties}};this.collection=Object.assign(await this.collections.ensure("sessions",{...t,schema:s}),{expireAfterSeconds:G}),await this.collection.ensureIndexes([...De,...i??[]]),await this.#e();for await(let o of this.collection.find())this.load(o);this.collection.onChange(this.#i),delete this.initOptions}}async#e(){await this.collection.bulkWrite([{updateMany:{filter:{meta:{$exists:!1}},update:{$set:{meta:{}}}}},{updateMany:{filter:{isOnline:!0},update:{$set:{isOnline:!1}}}}])}#i=e=>{switch(e.operationType){case"insert":this.has(e.documentKey._id)||new y(this,e.fullDocument),this.users.get(e.fullDocument.user)?.trimSessions();break;case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};uid(){return`${xe()}~${Oe(32).toString("base64url")}`}load(e){new y(this,e)}async create(e,i){let t=Date.now(),s={userAgent:"",remoteAddress:"127.0.0.1",isOnline:!0,...i,_id:this.uid(),user:e._id,meta:{},createdAt:t,prolongedAt:t,expiresAt:new Date(t+G*1e3)},o=new y(this,s);return await this.collection.insertOne(s),o}async destroySession(e){let{deletedCount:i}=await this.collection.deleteOne({_id:e});return!!i}};import{Binary as Ie}from"insite-db";var ee={required:["_id","type","size","ts","data","meta"],properties:{_id:{bsonType:"string",pattern:c._id.source},type:{bsonType:"string",maxLength:256},size:{bsonType:"number"},ts:{bsonType:"string",maxLength:10},data:{bsonType:"binData"},meta:{bsonType:"object"}},additionalProperties:!1};var P=class{constructor(e,i={}){this.#e=e,this.collections=e.collections,this.initOptions=i}TYPES_ACCEPTED=["image/webp"];MAX_SIZE=1024*512;#e;collections;collection;initOptions;async init(){if(!this.#e.isInited){let{collection:e}=this.initOptions;this.collection=await this.collections.ensure("users.avatars",{...e,schema:ee}),await this.#i()}}async#i(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}async save(e,i,t){let s=Ie.createFromBase64(t.slice(t.indexOf(",")));if(!this.TYPES_ACCEPTED.includes(i))throw new Error("avatar.unacceptable-format");if(s.length()>this.MAX_SIZE)throw new Error("avatar.size-exceeds-limit");let o=Date.now().toString(36);await Promise.all([this.collection.replaceOne({_id:e},{type:i,size:s.length(),ts:o,data:s,meta:{}},{upsert:!0}),this.#e.collection.updateOne({_id:e},{$set:{avatar:o}})])}async deleteAvatar(e){let[{deletedCount:i}]=await Promise.all([this.collection.deleteOne({_id:e}),this.#e.collection.updateOne({_id:e},{$set:{avatar:null}})]);return!!i}};var g={required:["_id","email","password","roles","name","org","job","meta","createdAt"],properties:{_id:{bsonType:"string",pattern:c._id.source},email:{bsonType:"string",pattern:c.email.source},password:{bsonType:"string",pattern:c.argon2.source},roles:{bsonType:"array",uniqueItems:!0,items:{bsonType:"string",pattern:c.role.source},additionalItems:!1},name:{bsonType:"object",required:["first","middle","last"],properties:{first:{bsonType:"string",maxLength:512},middle:{bsonType:"string",maxLength:512},last:{bsonType:"string",maxLength:512}},additionalProperties:!1},org:{oneOf:[{bsonType:"string",pattern:c._id.source},{bsonType:"null"}]},job:{bsonType:"string",maxLength:512},avatar:{oneOf:[{bsonType:"string",maxLength:10},{bsonType:"null"}]},meta:{bsonType:"object"},createdAt:{bsonType:"number"}},additionalProperties:!1};import{_ids as ie,debounce as Re,empty as Ue,hasAny as Te,removeOne as Ce}from"@nesvet/n";var N=new WeakMap,L=new WeakMap,je=process.env.INSITE_STATIC_URL??"",h=class{constructor(e,i){this.#e=e,this._id=i._id,e.set(this._id,this),this.update(i),e.isInited&&e.emit("user-create",this)}_id;email;name={first:"",middle:"",last:""};initials="";displayLabel="";org;job="";avatar=null;avatarUrl=null;#e;isUser=!0;isRoot;roles=new Set;ownRoles=[];ownRoleIds=[];slaveRoles=new Set;slaveRoleIds=[];abilities={};slaveOrgs=new Set;slaveUsers=new Set;slaves=new Set;slaveIds=[];permissiveIds=[];sessions=new Set;isOnline=!1;update({_id:e,name:i,email:t,roles:s,org:o,avatar:r,...a}){Object.assign(this,a);let n;t&&this.email!==t&&(this.#e.byEmail.delete(this.email),this.email=t,this.#e.byEmail.set(t,this),n=!0);let d,A;i&&(this.name.first!==i.first||this.name.middle!==i.middle||this.name.last!==i.last)&&(A=this.name.last!==i.last,this.name={first:i.first??"",middle:i.middle??"",last:i.last??""},this.initials=((i.first?.[0]??"")+(i.last?.[0]??"")||this.email[0]).toUpperCase(),d=!0),(n||d)&&(this.displayLabel=`${this.name.first} ${this.name.last}`.trim()||this.name.middle||this.email);let z;if(s){this.ownRoleIds=s;let K=this.ownRoleIds.join(",");K!==N.get(this)&&(N.set(this,K),this.#e.isInited&&(this.updateRoles(),z=!0))}let F;o!==void 0&&this.org?._id!==o&&(this.org?.users.delete(this),this.org=o&&this.#e.orgs.get(o)||this.#e.orgs.null,this.org.users.add(this),F=!0),r!==void 0&&this.avatar!==r&&(this.avatar=r,this.avatarUrl=r&&`${je}/avatars/${this._id}-${r}.webp`),this.#e.isInited&&(z||F?(this.updatePermissions(),A&&(this.#e.isSortRequired=!0),this.#e.update()):A&&this.#e.sort())}updateRoles(){this.ownRoles=[],this.roles.clear(),this.slaveRoles.clear(),Ue(this.abilities);for(let e of this.ownRoleIds){let i=this.#e.roles.get(e);if(i){this.ownRoles.push(i),this.roles.add(i);for(let t of i.involves)this.roles.add(t),this.slaveRoles.add(t);this.slaveRoleIds=ie(this.slaveRoles),this.#e.abilities.merge(this.abilities,i.abilities)}}this.roles.has(this.#e.roles.root)&&(this.isRoot=!0),this.trimSessions()}updatePermissions(){this.slaveOrgs.clear(),this.slaveUsers.clear(),this.slaves.clear();let e=new Set;for(let s of this.#e.orgs.sorted)if((s.ownerUsers.has(this)||this.isRoot)&&!this.slaveOrgs.has(s)){this.slaveOrgs.add(s),this.slaves.add(s),e.add(s._id);for(let o of s.slaveOrgs)this.slaveOrgs.add(o),this.slaves.add(o),e.add(o._id)}for(let s of new Set([this.org,...this.slaveOrgs,this.#e.orgs.null]))for(let o of s.users)o!==this&&(Te(this.slaveRoles,o.ownRoles)||!o.ownRoles.length)&&(this.slaveUsers.add(o),this.slaves.add(o),e.add(o._id));this.slaveIds=[...e];let i=[];if(this.org._id){i.push(this.org._id);for(let s of this.org.slaveOrgs)this.slaveOrgs.has(s)||i.push(s._id)}this.permissiveIds=[...i,this._id,...e];let t=[this.permissiveIds.join(","),this.ownRoleIds.join(","),JSON.stringify(this.abilities),this.slaveRoleIds.join(",")].join(`
|
|
3
|
+
`);t!==L.get(this)&&(L.set(this,t),this.#e.isInited&&this.#e.emit("user-permissions-change",this))}trimSessions(){let e=this.abilities.login?.sessionsLimit;if(typeof e=="number"&&this.sessions.size>e)return this.#e.sessions.collection.deleteMany({_id:{$in:ie([...this.sessions].sort((i,t)=>i.expiresAt.valueOf()-t.expiresAt.valueOf()).slice(0,this.sessions.size-e))}})}updateIsOnline(){let e=!1;for(let i of this.sessions)if(i.isOnline){e=!0;break}this.isOnline!==e&&(this.isOnline=e,this.#e.emit("user-is-online",this))}updateIsOnlineDebounced=Re(()=>this.updateIsOnline(),500);async delete(){this.org.users.delete(this),this.#e.delete(this._id),this.#e.byEmail.delete(this.email),Ce(this.#e.sorted,this),N.delete(this),L.delete(this),await this.#e.replace(this._id),this.#e.update()}};var Ne=[[{email:1},{unique:!0}],[{org:1}]],Le,W=class l extends Map{constructor(e,i){super();let t=new $e;this.#e=t,this._events=t._events,this._eventsCount=t._eventsCount,this.emit=t.emit,this.on=t.on,this.once=t.once,this.addListener=t.addListener,this.off=t.off,this.removeListener=t.removeListener,this.collections=e,this.abilities=new S(i.abilities),this.initOptions=i,this.init()}#e;_events;_eventsCount;emit;on(e,i,t){return this.#e.on(e,i,t),this}once;addListener;off;removeListener;initOptions;collections;abilities;collection;roles;sessions;orgs;avatars;byEmail=new Map;bySessionId=new Map;sorted=[];isSortRequired=!0;#i=!1;async preinit(){if(!this.#i){this.#i=!0;let{indexes:e,schema:i,initialRoot:t,collection:s}=this.initOptions;i&&(i.required&&Me(i.required,g.required),i.properties&&se(i,Object.keys(g.properties)));let o={...g,...i,required:[...g.required,...i?.required??[]],properties:{...g.properties,...i?.properties}};this.collection=await this.collections.ensure("users",{...s,schema:o}),await this.collection.ensureIndexes([...Ne,...e??[]]),await this.collection.countDocuments({roles:"root"})||await this.create({email:process.env.INSITE_ROOT_EMAIL??"insite@root.email",password:process.env.INSITE_ROOT_PASSWORD??"inSiteRootPassword",name:{first:"Root"},job:"Root",...t,roles:["root"],org:null,meta:{}}),await this.#t();for await(let r of this.collection.find())this.load(r)}}async#t(){await this.collection.updateMany({meta:{$exists:!1}},{$set:{meta:{}}})}isInited=!1;async init(){if(!this.isInited){let{roles:e,orgs:i,sessions:t,avatars:s,collection:{quiet:o}={}}=this.initOptions;this.roles=new w(this,{...e,collection:{quiet:o,...e?.collection}}),this.orgs=new v(this,{...i,collection:{quiet:o,...i?.collection}}),this.sessions=new O(this,{...t,collection:{quiet:o,...t?.collection}}),this.avatars=new P(this,{...s,collection:{quiet:o,...s?.collection}}),await this.roles.init(),await this.orgs.preinit(),await this.preinit(),this.orgs.init(),await this.avatars.init(),this.update(!0),this.collection.onChange(this.#o),await this.sessions.init(),delete this.initOptions,this.isInited=!0,this.#s.resolve(this)}}#o=e=>{switch(e.operationType){case"insert":new h(this,e.fullDocument);break;case"replace":this.get(e.documentKey._id)?.update(e.fullDocument);break;case"update":this.get(e.documentKey._id)?.update(e.updateDescription.updatedFields);break;case"delete":this.get(e.documentKey._id)?.delete()}};load(e){new h(this,e)}sort(){this.isSortRequired=!1,this.sorted=[...this.values()].sort((e,i)=>e.name.last>i.name.last?1:e.name.last<i.name.last?-1:0)}update(e){if(e)for(let i of this.values())i.updateRoles();for(let i of this.values())i.updatePermissions();this.isSortRequired&&this.sort()}#s=new ke;whenReady(){return this.#s}async create({email:e,password:i,roles:t,name:s,org:o,job:r,...a}){if(this.byEmail.has(e))throw new Error("User exists");let n=Ge();return await this.collection.insertOne({_id:n,email:e,password:await _(i),roles:this.isInited?this.roles.cleanUpIds(t):t,name:{first:s.first??"",middle:s.middle??"",last:s.last??""},org:o??null,job:r??"",meta:{},...se(a,["_id"]),createdAt:Date.now()}),n}async updateUser(e,i,t){let s=this.get(e);if(!s)return!1;i.roles&&(i.roles=s.isRoot?["root"]:this.roles.cleanUpIds(t?qe(s.ownRoleIds,t.slaveRoleIds).concat(i.roles):i.roles));let o;if(i.password!==void 0){if(typeof i.password!="string"||i.password==="")throw new Error("emptypasswordisnotallowed");o=c.argon2.test(i.password)?i.password:await _(i.password),i={...i,password:o}}let r=[this.collection.updateOne({_id:e},{$set:i})];return o!==void 0&&o!==s.password&&r.push(this.sessions.collection.deleteMany({user:e})),await Promise.all(r),!0}async changePassword(e,i){if(!this.has(e))throw new Error("usernotfound");if(!i)throw new Error("emptypasswordisnotallowed");await Promise.all([this.collection.updateOne({_id:e},{$set:{password:await _(i)}}),this.sessions.collection.deleteMany({user:e})])}async login(e,i,t){let s=this.byEmail.get(e);if(!s){try{await te(await(Le??=_("insite-unknown-user")),i)}catch{}throw new Error("usernotfound")}if(!await te(s.password,i))throw new Error("incorrectpassword");if(!s.abilities.login)throw new Error("userisnotabletologin");return this.sessions.create(s,t)}logout(e){return e.delete(),this.sessions.collection.deleteOne({_id:e._id})}#r(e,i){return e instanceof h&&i instanceof h?e.name.last&&i.name.last?e.name.last>i.name.last?1:e.name.last<i.name.last?-1:0:!e.name.last&&!i.name.last?e.displayLabel>i.displayLabel?1:e.displayLabel<i.displayLabel?-1:0:e.name.last?-1:1:e instanceof p&&i instanceof p?e.title>i.title?1:e.title<i.title?-1:0:e instanceof p?-1:1}sortIds(e){return Ee(e.map(i=>this.get(i)||this.orgs.get(i)).filter(Boolean).sort(this.#r))}replaceMap=new Map;replaceHandlers=new Set;async replace(e){let i=this.replaceMap.get(e)??null;i&&this.replaceMap.delete(e);for(let t of this.replaceHandlers)await t(e,i)}async deleteUser(e){let{deletedCount:i}=await this.collection.deleteOne({_id:e});return!!i}static init(e,i){return new l(e,i).whenReady()}};export{x as AbilityError,E as PermissionError,U as RolesError,$ as SubordinationError,j as UnauthorizedError,W as Users};
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/abilities/Error.ts", "../src/abilities/Map.ts", "../src/abilities/types.ts", "../src/roles/Error.ts", "../src/roles/Roles.ts", "../src/roles/Role.ts", "../src/lib/regexps.ts", "../src/roles/schema.ts", "../src/users/errors.ts", "../src/users/Users.ts", "../src/orgs/Orgs.ts", "../src/orgs/Org.ts", "../src/orgs/schema.ts", "../src/sessions/Sessions.ts", "../src/sessions/schema.ts", "../src/sessions/Session.ts", "../src/users/avatars/Avatars.ts", "../src/users/avatars/schema.ts", "../src/users/schema.ts", "../src/users/User.ts"],
|
|
4
|
-
"sourcesContent": ["import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class AbilityError extends Err {\n\tconstructor(payload?: Payload);\n\tconstructor(longId: string, payload?: Payload);\n\tconstructor(longId?: Payload | string, payload?: Payload) {\n\t\tif (typeof longId == \"object\") {\n\t\t\tpayload = longId;\n\t\t\tlongId = undefined;\n\t\t}\n\t\t\n\t\tsuper(\"User lacks ability\", \"lacksability\", {\n\t\t\t...longId && { ability: longId },\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"AbilityError\";\n\t\n}\n", "import {\n\tadd,\n\tassignPath,\n\tdeletePath,\n\tempty,\n\tgetPath,\n\tintersection,\n\tpick,\n\tsetPath\n} from \"@nesvet/n\";\nimport type { Abilities, AbilitiesSchema, AbilityParamSchema } from \"insite-common\";\nimport {\n\tisAbilityObject,\n\tisAbilityParamItems,\n\tisAbilityParamNumber,\n\ttype Ability,\n\ttype AbilityObject,\n\ttype AbilityParam,\n\ttype AbilityParamItems,\n\ttype AbilityParamNumber,\n\ttype AbilitySchema,\n\ttype GenericAbilities\n} from \"./types\";\n\n\nconst schemaParentMap = new Map<AbilitySchema, AbilitySchema | null>();\n\n\nexport class AbilitiesMap<AS extends AbilitiesSchema> extends Map<string, AbilitySchema> {\n\tconstructor(abilitiesSchema: AS) {\n\t\tsuper();\n\t\t\n\t\tfor (const subSchema of abilitiesSchema) {\n\t\t\tdelete subSchema.top;/* The first level is always top */\n\t\t\t\n\t\t\tthis.#hierarchical.push(subSchema as AbilitySchema);\n\t\t}\n\t\t\n\t\t(function parse(this: AbilitiesMap<AS>, schemas: AbilitiesSchema, parent: AbilitySchema | null, level: number) {\n\t\t\tfor (const schema of schemas as AbilitySchema[]) {\n\t\t\t\tschemaParentMap.set(schema, parent);\n\t\t\t\t\n\t\t\t\tschema.level = level;\n\t\t\t\t\n\t\t\t\tif (!parent || schema.top) {\n\t\t\t\t\tschema.longId = schema._id;\n\t\t\t\t\t\n\t\t\t\t\tif (this.has(schema._id))\n\t\t\t\t\t\tthrow new Error(`Top-level ability duplicate: ${schema._id}`);\n\t\t\t\t\t\n\t\t\t\t\tthis.set(schema._id, schema);\n\t\t\t\t} else\n\t\t\t\t\tschema.longId = parent ? `${parent.longId}.${schema._id}` : schema._id;\n\t\t\t\t\n\t\t\t\tif (schema.abilities)\n\t\t\t\t\tparse.call(this, schema.abilities, schema, level + 1);\n\t\t\t}\n\t\t\t\n\t\t}).call(this, abilitiesSchema, null, 0);\n\t\t\n\t}\n\t\n\t#hierarchical: AbilitySchema[] = [];\n\t\n\tget(longId: string, parent?: AbilitySchema | null) {\n\t\tconst subIds = longId.split(\".\");\n\t\tlet schema = parent ?? super.get(subIds.shift()!);\n\t\t\n\t\tif (schema && subIds.length)\n\t\t\tfor (const subId of subIds) {\n\t\t\t\tschema = schema?.abilities?.find(({ _id, top }) => !top && _id === subId);\n\t\t\t\tif (!schema)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\n\t\treturn schema;\n\t}\n\t\n\tgetSchema = this.get;\n\t\n\tgetParamSchema(longId: string, paramId: string) {\n\t\treturn this.get(longId)?.params?.find(({ _id }) => _id === paramId);\n\t}\n\t\n\tgetDefaultParam(longId: string, paramId: string, max?: boolean): AbilityParam | undefined;\n\tgetDefaultParam(schema: AbilityParamSchema, max?: boolean): AbilityParam;\n\tgetDefaultParam(schemaOrLongId: AbilityParamSchema | string, paramIdOrMax?: boolean | string, max?: boolean) {\n\t\tif (paramIdOrMax === undefined || typeof paramIdOrMax == \"boolean\")\n\t\t\tmax = paramIdOrMax;\n\t\t\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.getParamSchema(schemaOrLongId, paramIdOrMax as string) : schemaOrLongId;\n\t\t\n\t\tif (schema)\n\t\t\tswitch (schema.type) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn max ?\n\t\t\t\t\t\t(schema.max ?? Infinity) :\n\t\t\t\t\t\t(schema.min ?? 0);\n\t\t\t\t\n\t\t\t\tcase \"items\":\n\t\t\t\t\treturn max ?\n\t\t\t\t\t\tschema.items.map(({ _id }) => _id) :\n\t\t\t\t\t\t[];\n\t\t\t}\n\t\t\n\t\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n\t}\n\t\n\tgetDefaultAbility(schema: string, max?: boolean): Ability | undefined;\n\tgetDefaultAbility(schema: AbilitySchema, max?: boolean): Ability;\n\tgetDefaultAbility(schema: AbilitySchema | string, max: boolean = !schema): Ability | undefined {\n\t\tif (typeof schema == \"string\")\n\t\t\tschema = this.get(schema)!;\n\t\t\n\t\tif (schema) {\n\t\t\tif (schema.abilities || schema.params) {\n\t\t\t\tconst ability = {} as AbilityObject;\n\t\t\t\t\n\t\t\t\tif (schema.params)\n\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\tability[paramSchema._id] = this.getDefaultParam(paramSchema, max);\n\t\t\t\t\n\t\t\t\tif (max && schema.abilities)\n\t\t\t\t\tfor (const subSchema of schema.abilities)\n\t\t\t\t\t\tif (!subSchema.top)\n\t\t\t\t\t\t\tability[subSchema._id] = this.getDefaultAbility(subSchema, max);\n\t\t\t\t\n\t\t\t\treturn ability;\n\t\t\t}\n\t\t\t\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn undefined;\n\t}\n\t\n\tgetDefaultAbilities(): Abilities<AS>;\n\tgetDefaultAbilities(schemas: AbilitySchema[], max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(schema: AbilitySchema, max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(longIds: string[], max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(longId: string, max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(schemasOrIds?: (AbilitySchema | string)[] | AbilitySchema | string, max: boolean = !schemasOrIds) {\n\t\t\n\t\tconst schemas = (\n\t\t\tschemasOrIds ?\n\t\t\t\t(Array.isArray(schemasOrIds) ? schemasOrIds : [ schemasOrIds ])\n\t\t\t\t\t.map(schema => (typeof schema == \"string\" ? this.get(schema) : schema))\n\t\t\t\t\t.filter(Boolean) as AbilitySchema[] :\n\t\t\t\t[ ...this.values() ]\n\t\t).sort((a, b) => a.level - b.level);\n\t\t\n\t\tconst schemaMaxMap = new Map<AbilitySchema, boolean>();\n\t\t\n\t\tfor (const schema of schemas) {\n\t\t\t(function resolve(_schema) {\n\t\t\t\tconst parentSchema = schemaParentMap.get(_schema);\n\t\t\t\t\n\t\t\t\tif (parentSchema) {\n\t\t\t\t\tresolve(parentSchema);\n\t\t\t\t\t\n\t\t\t\t\tif (!schemaMaxMap.has(parentSchema))\n\t\t\t\t\t\tschemaMaxMap.set(parentSchema, false);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t})(schema);\n\t\t\t\n\t\t\tif (max)\n\t\t\t\t(function resolve(_schema) {\n\t\t\t\t\tif (!schemaMaxMap.has(_schema))\n\t\t\t\t\t\tschemaMaxMap.set(_schema, true);\n\t\t\t\t\t\n\t\t\t\t\tif (_schema.abilities)\n\t\t\t\t\t\tfor (const subSchema of _schema.abilities)\n\t\t\t\t\t\t\tif (subSchema.top)\n\t\t\t\t\t\t\t\tresolve(subSchema);\n\t\t\t\t\t\n\t\t\t\t})(schema);\n\t\t\telse\n\t\t\t\tif (!schemaMaxMap.has(schema))\n\t\t\t\t\tschemaMaxMap.set(schema, false);\n\t\t}\n\t\t\n\t\treturn assignPath(\n\t\t\t{},\n\t\t\tObject.fromEntries(\n\t\t\t\t[ ...schemaMaxMap ]\n\t\t\t\t\t.map(([ schema, _max ]) => [ schema.longId, this.getDefaultAbility(schema, _max) ])\n\t\t\t)\n\t\t);\n\t}\n\t\n\tgetSchemeFor(abilities: GenericAbilities) {\n\t\tabilities = this.adjust(structuredClone(abilities));\n\t\t\n\t\treturn (function resolve(subSchemas: AbilitySchema[], subAbilities: GenericAbilities) {\n\t\t\tfor (let i = 0; i < subSchemas.length; i++) {\n\t\t\t\tconst schema = subSchemas[i];\n\t\t\t\tconst ability = schema.top ? abilities[schema._id] : subAbilities[schema._id];\n\t\t\t\t\n\t\t\t\tif (ability) {\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tfor (const paramSchema of schema.params) {\n\t\t\t\t\t\t\tconst abilityParam = (ability as AbilityObject)[paramSchema._id];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\t\t\tparamSchema.max = abilityParam as AbilityParamNumber;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\t\t\t\tparamSchema.items = paramSchema.items.filter(({ _id }) => (abilityParam as AbilityParamItems).includes(_id));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities) {\n\t\t\t\t\t\tresolve(schema.abilities, ability as GenericAbilities);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (!schema.abilities.length)\n\t\t\t\t\t\t\tdelete schema.abilities;\n\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t\tsubSchemas.splice(i--, 1);\n\t\t\t}\n\t\t\t\n\t\t\treturn subSchemas;\n\t\t})(structuredClone(this.#hierarchical), abilities);\n\t}\n\t\n\tgetParam(abilities: GenericAbilities, longId: string, paramId: string) {\n\t\tif (this.getParamSchema(longId, paramId)) {\n\t\t\tconst value = getPath(abilities, `${longId}.${paramId}`) as AbilityParam;\n\t\t\t\n\t\t\tif (this.isParamFits(longId, paramId, value))\n\t\t\t\treturn value;\n\t\t\t\n\t\t\treturn this.getDefaultParam(longId, paramId)!;\n\t\t}\n\t\t\n\t\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n\t}\n\t\n\tsetParam(abilities: GenericAbilities, longId: string, paramId: string, value: AbilityParam): Abilities<AS> {\n\t\tconst schema = this.getParamSchema(longId, paramId);\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability param: ${longId}.${paramId}`);\n\t\t\n\t\tsetPath(abilities, `${longId}.${paramId}`, this.adjustParam(schema, value));\n\t\t\n\t\treturn abilities as Abilities<AS>;\n\t}\n\t\n\tisParamFits(longId: string, paramId: string, value: AbilityParam, referenceValue?: AbilityParam) {\n\t\tif (value !== undefined) {\n\t\t\tconst paramSchema = this.getParamSchema(longId, paramId);\n\t\t\t\n\t\t\tif (paramSchema)\n\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tisAbilityParamNumber(value) &&\n\t\t\t\t\t\t\t(paramSchema.min === undefined || value >= paramSchema.min) && (\n\t\t\t\t\t\t\t\treferenceValue === undefined ?\n\t\t\t\t\t\t\t\t\t(paramSchema.max === undefined || value <= paramSchema.max) :\n\t\t\t\t\t\t\t\t\tvalue <= (referenceValue as AbilityParamNumber)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\n\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tisAbilityParamItems(value) &&\n\t\t\t\t\t\t\tvalue.length === new Set(value).size && (\n\t\t\t\t\t\t\t\treferenceValue === undefined ?\n\t\t\t\t\t\t\t\t\tvalue.every(itemId => paramSchema.items.find(({ _id }) => _id === itemId)) :\n\t\t\t\t\t\t\t\t\tvalue.every(itemId => (referenceValue as AbilityParamItems).includes(itemId))\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tadjustParam(paramSchema: AbilityParamSchema, value: AbilityParam) {\n\t\tswitch (paramSchema.type) {\n\t\t\tcase \"number\":\n\t\t\t\treturn (\n\t\t\t\t\tisAbilityParamNumber(value) ?\n\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\tMath.min(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tparamSchema.max ?? Infinity\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tparamSchema.min ?? 0\n\t\t\t\t\t\t) :\n\t\t\t\t\t\tparamSchema.min ?? 0\n\t\t\t\t);\n\t\t\t\n\t\t\tdefault/* paramSchema.type === \"items\" */:\n\t\t\t\treturn (\n\t\t\t\t\tisAbilityParamItems(value) ?\n\t\t\t\t\t\tintersection(paramSchema.items.map(item => item._id), value) :\n\t\t\t\t\t\t[]\n\t\t\t\t) as AbilityParamItems;\n\t\t}\n\t\t\n\t}\n\t\n\tadjust(abilities: GenericAbilities, parent?: AbilitySchema | null): Abilities<AS> {\n\t\tconst adjustedAbilities: GenericAbilities = {};\n\t\t\n\t\tfor (const [ _id, ability ] of Object.entries(abilities)) {\n\t\t\tconst schema = this.get(_id, parent);\n\t\t\t\n\t\t\tif (schema)\n\t\t\t\tif (schema.params || schema.abilities) {\n\t\t\t\t\tconst adjustedAbility: AbilityObject = {};\n\t\t\t\t\t\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tif (isAbilityObject(ability))\n\t\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\t\tadjustedAbility[paramSchema._id] = this.adjustParam(paramSchema, ability[paramSchema._id] as AbilityParam);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\t\tadjustedAbility[paramSchema._id] = this.getDefaultParam(paramSchema);\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities && isAbilityObject(ability))\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tadjustedAbility,\n\t\t\t\t\t\t\tthis.adjust(\n\t\t\t\t\t\t\t\tpick(\n\t\t\t\t\t\t\t\t\tability,\n\t\t\t\t\t\t\t\t\tschema.abilities\n\t\t\t\t\t\t\t\t\t\t.filter(subSchema => !subSchema.top)\n\t\t\t\t\t\t\t\t\t\t.map(subSchema => subSchema._id)\n\t\t\t\t\t\t\t\t) as GenericAbilities,\n\t\t\t\t\t\t\t\tschema\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\n\t\t\t\t\tadjustedAbilities[_id] = adjustedAbility;\n\t\t\t\t} else\n\t\t\t\t\tadjustedAbilities[_id] = true;\n\t\t}\n\t\t\n\t\treturn Object.assign(empty(abilities), adjustedAbilities) as Abilities<AS>;\n\t}\n\t\n\tmerge(target: GenericAbilities, source: GenericAbilities, parent?: AbilitySchema | null): Abilities<AS> {\n\t\tif (!parent) {\n\t\t\tthis.adjust(target);\n\t\t\tsource = this.adjust(structuredClone(source));\n\t\t}\n\t\t\n\t\tfor (const [ _id, ability ] of Object.entries(source)) {\n\t\t\tconst schema = this.get(_id, parent);\n\t\t\t\n\t\t\tif (schema && schema.isInheritable !== false)\n\t\t\t\tif (_id in target && (schema.params || schema.abilities)) {\n\t\t\t\t\tconst targetAbility = target[_id] as AbilityObject;\n\t\t\t\t\tconst sourceAbility = ability as AbilityObject;\n\t\t\t\t\t\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\tif (paramSchema.isInheritable !== false)\n\t\t\t\t\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] =\n\t\t\t\t\t\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] as AbilityParamNumber,\n\t\t\t\t\t\t\t\t\t\t\t\tsourceAbility[paramSchema._id] as AbilityParamNumber\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\t\t\t\t\tadd(\n\t\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] as AbilityParamItems,\n\t\t\t\t\t\t\t\t\t\t\t...sourceAbility[paramSchema._id] as AbilityParamItems\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities)\n\t\t\t\t\t\tthis.merge(targetAbility as GenericAbilities, sourceAbility as GenericAbilities, schema);\n\t\t\t\t} else\n\t\t\t\t\ttarget[_id] = ability;\n\t\t}\n\t\t\n\t\treturn target as Abilities<AS>;\n\t}\n\t\n\thasAbility(abilities: GenericAbilities, longId: string) {\n\t\treturn Boolean(getPath(abilities, longId));\n\t}\n\t\n\tsetAbility(target: GenericAbilities, schema: AbilitySchema): Abilities<AS>;\n\tsetAbility(target: GenericAbilities, longId: string): Abilities<AS>;\n\tsetAbility(target: GenericAbilities, schemaOrLongId: AbilitySchema | string) {\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.get(schemaOrLongId) : schemaOrLongId;\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability: ${schemaOrLongId as string}`);\n\t\t\n\t\tthis.merge(target, this.getDefaultAbilities(schema));\n\t\t\n\t\treturn target as Abilities<AS>;\n\t}\n\t\n\tunsetAbility(target: GenericAbilities, schema: AbilitySchema): Abilities<AS>;\n\tunsetAbility(target: GenericAbilities, longId: string): Abilities<AS>;\n\tunsetAbility(target: GenericAbilities, schemaOrLongId: AbilitySchema | string) {\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.get(schemaOrLongId) : schemaOrLongId;\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability: ${schemaOrLongId as string}`);\n\t\t\n\t\t(function resolve(_schema) {\n\t\t\tdeletePath(target, _schema.longId);\n\t\t\t\n\t\t\tif (_schema.abilities)\n\t\t\t\tfor (const subSchema of _schema.abilities)\n\t\t\t\t\tresolve(subSchema);\n\t\t\t\n\t\t})(schema);\n\t\t\n\t\treturn target;\n\t}\n\t\n}\n", "import type { Prettify } from \"@nesvet/n\";\nimport type { AbilitySchema as OriginalAbilitySchema } from \"insite-common\";\n\n\ntype AbilityParamItem = string;\nexport type AbilityParamItems = AbilityParamItem[];\nexport type AbilityParamNumber = number;\nexport type AbilityParam = AbilityParamItems | AbilityParamNumber;\n\nexport type AbilityWithParams = Record<string, AbilityParam>;\nexport type AbilityObject = Record<string, Ability | AbilityParam>;\nexport type AbilityBoolean = true;\nexport type Ability = AbilityBoolean | { [key: string]: Ability | AbilityParam };\n\nexport type AbilitySchema = Prettify<\n\tOmit<OriginalAbilitySchema, \"abilities\"> & {\n\t\tlevel: number;\n\t\tlongId: string;\n\t\tabilities?: AbilitySchema[];\n\t}\n>;\n\nexport type GenericAbilities = Record<string, Ability>;\n\nexport function isAbilityObject(value: Ability): value is AbilityObject {\n\treturn typeof value == \"object\";\n}\n\nexport function isAbilityParamNumber(value: AbilityParam): value is AbilityParamNumber {\n\treturn typeof value == \"number\";\n}\n\nexport function isAbilityParamItems(value: AbilityParam): value is AbilityParamItems {\n\treturn Array.isArray(value);\n}\n", "import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class RolesError extends Err {\n\tconstructor(roleId: string, payload?: Payload);\n\tconstructor(roleIds: string[], payload?: Payload);\n\tconstructor(stringOrArray: Payload | string[] | string, payload?: Payload) {\n\t\tsuper(`User lacks role${Array.isArray(stringOrArray) ? \"s\" : \"\"}`, \"lacksroles\", {\n\t\t\troles: Array.isArray(stringOrArray) ? stringOrArray : [ stringOrArray ],\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"RolesError\";\n\t\n}\n", "import {\n\tdeleteProps,\n\tgetAll,\n\tintersection,\n\treAdd,\n\tremoveAll\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport type { ChangeStreamDocument, CollectionIndexes, WatchedCollection } from \"insite-db\";\nimport type { AbilityParam, GenericAbilities } from \"../abilities/types\";\nimport type { Users } from \"../users\";\nimport { Role } from \"./Role\";\nimport { basisSchema } from \"./schema\";\nimport type { NewRole, RoleDoc, RolesOptions } from \"./types\";\n\n\nconst indexes: CollectionIndexes = [\n\t[ { involves: 1 } ]\n];\n\nfunction preventDirectDelete() {\n\tthrow new Error(\"Direct usage of roles collection.deleteOne or .deleteMany is forbidden. Use roles.deleteRole instead.\");\n}\n\n\nexport class Roles<AS extends AbilitiesSchema> extends Map<string, Role<AS>> {\n\tconstructor(users: Users<AS>, options: RolesOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tconst {\n\t\t\troot: rootProps,\n\t\t\t...initOptions\n\t\t} = options;\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\tthis.abilities = users.abilities;\n\t\t\n\t\tthis.root = new Role<AS>(this, {\n\t\t\t...rootProps,\n\t\t\t_id: \"root\",\n\t\t\tinvolves: [],\n\t\t\tabilities: this.abilities.getDefaultAbilities(),\n\t\t\ttitle: \"Root\",\n\t\t\tdescription: \"Root\",\n\t\t\tmeta: {},\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\tthis.initOptions = initOptions;\n\t\t\n\t}\n\t\n\tusers;\n\tcollections;\n\tcollection!: WatchedCollection<RoleDoc> & {\n\t\t/** @deprecated Direct usage of roles collection.deleteOne is forbidden. Use roles.deleteRole instead. */\n\t\tdeleteOne: typeof preventDirectDelete;\n\t\t\n\t\t/** @deprecated Direct usage of roles collection.deleteMany is forbidden. Use roles.deleteRole instead. */\n\t\tdeleteMany: typeof preventDirectDelete;\n\t};\n\t\n\tabilities;\n\troot;\n\tprivate initOptions?;\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<RoleDoc>(\"roles\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\tdeleteOne: preventDirectDelete,\n\t\t\t\t\tdeleteMany: preventDirectDelete\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const roleDoc of this.collection.find()) {\n\t\t\t\tif (this.abilities.adjust(roleDoc.abilities))\n\t\t\t\t\tawait this.collection.updateOne({ _id: roleDoc._id }, { $set: { abilities: roleDoc.abilities } });\n\t\t\t\t\n\t\t\t\tthis.load(roleDoc);\n\t\t\t}\n\t\t\t\n\t\t\tthis.update();\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<RoleDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\": {\n\t\t\t\tnew Role<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tload(roleDoc: RoleDoc) {\n\t\tnew Role<AS>(this, roleDoc);\n\t\t\n\t}\n\t\n\tresolve(role: Role<AS>, involvedBy: Role<AS>[]) {\n\t\tinvolvedBy = [ role, ...involvedBy ];\n\t\t\n\t\tfor (const involvedRoleId of role.ownInvolveIds) {\n\t\t\tconst involvedRole = this.get(involvedRoleId);\n\t\t\tif (involvedRole) {\n\t\t\t\tfor (const involvedByRole of involvedBy) {\n\t\t\t\t\treAdd(involvedByRole.involves, involvedRole);\n\t\t\t\t\tthis.abilities.merge(involvedByRole.inheritedAbilities as GenericAbilities, involvedRole.abilities as GenericAbilities);\n\t\t\t\t}\n\t\t\t\tif (involvedRole !== role)\n\t\t\t\t\tthis.resolve(involvedRole, involvedBy);\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tsorted: Role<AS>[] = [];\n\t\n\t#sortRoles(a: Role<AS>, b: Role<AS>) {\n\t\treturn (\n\t\t\t(b.involves.size - a.involves.size) || (\n\t\t\t\t(a.title && b.title) ?\n\t\t\t\t\ta.title > b.title ? 1 : a.title < b.title ? -1 : 0 :\n\t\t\t\t\ta.title ?\n\t\t\t\t\t\t-1 :\n\t\t\t\t\t\tb.title ?\n\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\ta._id > b._id ?\n\t\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\t\ta._id < b._id ?\n\t\t\t\t\t\t\t\t\t-1 :\n\t\t\t\t\t\t\t\t\t0\n\t\t\t)\n\t\t);\n\t}\n\t\n\tupdate() {\n\t\t\n\t\tconst array = [ ...this.values() ];\n\t\t\n\t\tthis.root.ownInvolveIds = [];\n\t\tfor (const role of array) {\n\t\t\tif (role !== this.root && !array.some(anotherRole => anotherRole.ownInvolveIds.includes(role._id)))\n\t\t\t\tthis.root.ownInvolveIds.push(role._id);\n\t\t\trole.involves.clear();\n\t\t\trole.abilities = structuredClone(role.ownAbilities);\n\t\t\trole.inheritedAbilities = {};\n\t\t}\n\t\t\n\t\tthis.root.involves.add(this.root);\n\t\tthis.resolve(this.root, []);\n\t\t\n\t\tfor (const role of array)\n\t\t\trole.ownInvolves = getAll(this, role.ownInvolveIds, true).sort(this.#sortRoles).reverse();\n\t\t\n\t\tconst sorted = [ this.root ];\n\t\t\n\t\tfor (let i = 0; i < sorted.length; i++) {\n\t\t\tconst role = sorted[i];\n\t\t\tfor (const involvedRole of role.ownInvolves) {\n\t\t\t\tconst involvedRoleIndex = sorted.indexOf(involvedRole);\n\t\t\t\tif (~involvedRoleIndex) {\n\t\t\t\t\tsorted.splice(involvedRoleIndex, 1);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\tsorted.splice(i + 1, 0, involvedRole);\n\t\t\t}\n\t\t}\n\t\t\n\t\tlet _o = 0;\n\t\tfor (const role of sorted) {\n\t\t\tthis.abilities.merge(role.abilities as GenericAbilities, role.inheritedAbilities as GenericAbilities);\n\t\t\trole._o = _o++;\n\t\t}\n\t\t\n\t\tthis.sorted = sorted;\n\t\t\n\t\tif (this.users.isInited)\n\t\t\tthis.users.update(true);\n\t\t\n\t}\n\t\n\tasync create({ _id, involves, title, description, ...restProps }: NewRole) {\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\tinvolves: involves || [],\n\t\t\tabilities: {},\n\t\t\ttitle: title ?? \"\",\n\t\t\tdescription: description ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"abilities\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateRole(roleId: string, updates: Omit<RoleDoc, \"abilities\" | \"createdAt\">) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.involves) {\n\t\t\tremoveAll(updates.involves, [ roleId ]);\n\t\t\t\n\t\t\tfor (const involvedRoleId of updates.involves)\n\t\t\t\tif (this.get(involvedRoleId)?.involves.has(role))\n\t\t\t\t\tremoveAll(updates.involves, [ involvedRoleId ]);\n\t\t\t\n\t\t\tupdates.involves = this.cleanUpIds(updates.involves);\n\t\t}\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: updates });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tdeleteRole(role: Role<AS> | string) {\n\t\tconst _id = typeof role == \"string\" ? role : role._id;\n\t\t\n\t\treturn this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { involves: _id }, update: { $pullAll: { involves: [ _id ] } } } },\n\t\t\t{ deleteOne: { filter: { _id } } }\n\t\t]);\n\t}\n\t\n\tcleanUpIds(ids: string[]) {\n\t\tconst roles = intersection(this.sorted, getAll(this, ids, true));\n\t\t\n\t\tconst cleanedUpIds = [];\n\t\t\n\t\tfor (const role of roles)\n\t\t\tif (roles.every(anotherRole => anotherRole === role || !anotherRole.involves.has(role)))\n\t\t\t\tcleanedUpIds.push(role._id);\n\t\t\n\t\treturn cleanedUpIds;\n\t}\n\t\n\tasync setAbility(roleId: string, abilityLongId: string, set: boolean) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: {\n\t\t\tabilities:\n\t\t\t\tset ?\n\t\t\t\t\tthis.abilities.setAbility(role.ownAbilities, abilityLongId) :\n\t\t\t\t\tthis.abilities.unsetAbility(role.ownAbilities, abilityLongId)\n\t\t} });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tasync setAbilityParam(roleId: string, abilityLongId: string, paramId: string, value: AbilityParam) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: {\n\t\t\tabilities: this.abilities.setParam(role.ownAbilities, abilityLongId, paramId, value)\n\t\t} });\n\t\t\n\t\treturn true;\n\t}\n\t\n}\n", "import type { Abilities, AbilitiesSchema } from \"insite-common\";\nimport { Roles } from \"./Roles\";\nimport { RoleDoc } from \"./types\";\n\n\nconst snapshots = new WeakMap();\n\n\nexport class Role<AS extends AbilitiesSchema> {\n\tconstructor(roles: Roles<AS>, roleDoc: RoleDoc) {\n\t\tthis.#roles = roles;\n\t\t\n\t\tthis._id = roleDoc._id;\n\t\troles.set(this._id, this);\n\t\t\n\t\tvoid this.update(roleDoc);\n\t\t\n\t}\n\t\n\t#roles;\n\t\n\t_id;\n\townInvolveIds!: string[];\n\townAbilities!: Abilities<AS>;\n\ttitle = \"\";\n\tdisplayTitle = \"\";\n\t_o = 0;\n\t\n\townInvolves: Role<AS>[] = [];\n\tinvolves = new Set<Role<AS>>();\n\tabilities: Abilities<AS> = {};\n\tinheritedAbilities: Abilities<AS> = {};\n\t\n\tupdate({ _id, involves: ownInvolveIds, abilities: ownAbilities, title, ...restProps }: Partial<RoleDoc>) {\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tif (ownInvolveIds)\n\t\t\tthis.ownInvolveIds = ownInvolveIds;\n\t\t\n\t\tif (ownAbilities)\n\t\t\tthis.ownAbilities = ownAbilities as Abilities<AS>;\n\t\t\n\t\tif (title !== undefined) {\n\t\t\tthis.title = title;\n\t\t\tthis.displayTitle = title || this._id;\n\t\t}\n\t\t\n\t\tif (ownInvolveIds || ownAbilities) {\n\t\t\tconst snapshot = [\n\t\t\t\tthis.ownInvolveIds.join(\",\"),\n\t\t\t\tJSON.stringify(this.ownAbilities)\n\t\t\t].join(\"\\n\");\n\t\t\t\n\t\t\tif (snapshot !== snapshots.get(this)) {\n\t\t\t\tsnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.#roles.users.isInited)\n\t\t\t\t\tthis.#roles.update();\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tdelete() {\n\t\t\n\t\tthis.#roles.delete(this._id);\n\t\t\n\t\tsnapshots.delete(this);\n\t\t\n\t\tthis.#roles.update();\n\t\t\n\t}\n\t\n}\n", "export const regexps = {\n\t_id: /^[\\dA-Fa-f]{24}$/,\n\temail: /^[^\\s@]{1,63}@[^\\s@]{1,63}\\.[^\\s@]{1,63}$/,\n\targon2: /^\\$argon2(?:i|d|id)\\$v=\\d+\\$m=\\d+,t=\\d+,p=\\d+(?:\\$[\\d+/A-Za-z]+){2}$/,\n\t// eslint-disable-next-line unicorn/better-regex\n\tsessionId: /^(?:[\\dA-Fa-f]{16,32}\\$[\\dA-Fa-f]{16,32}|[0-9a-f]{24}~[A-Za-z0-9_-]{43})$/, // (?:old_format|new_format) - leave just the new after some time\n\trole: /^[\\d_a-z-]{1,64}$/,\n\tip: /^(?:\\d{1,3}\\.){3}\\d{1,3}$/\n};\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"involves\",\n\t\t\"abilities\",\n\t\t\"title\",\n\t\t\"description\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.role.source,\n\t\t\tnot: { enum: [ \"root\" ] }\n\t\t},\n\t\tinvolves: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps.role.source,\n\t\t\t\tnot: { enum: [ \"root\" ] }\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tabilities: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\ttitle: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 256\n\t\t},\n\t\tdescription: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 10240\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class UnauthorizedError extends Err {\n\tconstructor(payload?: Payload) {\n\t\tsuper(\"Unauthorized\", \"unauthorized\", payload);\n\t\t\n\t}\n\t\n\tname = \"UnauthorizedError\";\n\t\n}\n\n\ntype SubordinationType = \"_id\" | \"permissiveIds\" | \"slaveIds\";\n\nexport class SubordinationError extends Err {\n\tconstructor(payload?: Payload);\n\tconstructor(type: SubordinationType, payload?: Payload);\n\tconstructor(type: SubordinationType, ids: string[] | string, payload?: Payload);\n\tconstructor(type?: Payload | SubordinationType, ids?: Payload | string[] | string, payload?: Payload) {\n\t\tswitch (arguments.length) {\n\t\t\tcase 1:\n\t\t\t\tpayload = type as Payload;\n\t\t\t\ttype = undefined;\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase 2:\n\t\t\t\tpayload = ids as Payload;\n\t\t\t\tids = undefined;\n\t\t}\n\t\t\n\t\tsuper(\"Insubordination attempt\", \"subordination\", {\n\t\t\t...type && { type },\n\t\t\t...ids && { ids: Array.isArray(ids) ? ids : [ ids ] },\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"SubordinationError\";\n\t\n}\n\n\nexport class PermissionError extends Err {\n\tconstructor(payload?: Payload) {\n\t\tsuper(\"Insufficient permissions\", \"permissions\", payload);\n\t\t\n\t}\n\t\n\tname = \"PermissionError\";\n\t\n}\n", "import { hash, verify } from \"@node-rs/argon2\";\nimport EventEmitter from \"eventemitter3\";\nimport {\n\t_ids,\n\tdeleteProps,\n\tremoveAll,\n\tStatefulPromise,\n\twithout\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tCollections,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport { AbilitiesMap } from \"../abilities\";\nimport { Orgs } from \"../orgs\";\nimport { Org } from \"../orgs/Org\";\nimport { Roles } from \"../roles\";\nimport { Sessions } from \"../sessions\";\nimport { Session } from \"../sessions/Session\";\nimport type { SessionDoc } from \"../sessions/types\";\nimport { Avatars } from \"./avatars\";\nimport { basisSchema } from \"./schema\";\nimport { User } from \"./User\";\nimport type { NewUser, Options, UserDoc } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nconst indexes: CollectionIndexes = [\n\t[ { email: 1 }, { unique: true } ],\n\t[ { org: 1 } ]\n];\n\n\nexport class Users<AS extends AbilitiesSchema> extends Map<string, User<AS>> {\n\tconstructor(collections: Collections, options: Options<AS>) {\n\t\tsuper();\n\t\t\n\t\tconst eventEmitter = new EventEmitter() as EventEmitter & {\n\t\t\t_events: Record<string, object>;\n\t\t\t_eventsCount: number;\n\t\t};\n\t\tthis.#eventEmitter = eventEmitter;\n\t\tthis._events = eventEmitter._events;\n\t\tthis._eventsCount = eventEmitter._eventsCount;\n\t\tthis.emit = eventEmitter.emit;\n\t\tthis.on = eventEmitter.on as unknown as (...args: any[]) => this;\n\t\tthis.once = eventEmitter.once;\n\t\tthis.addListener = eventEmitter.addListener;\n\t\tthis.off = eventEmitter.off;\n\t\tthis.removeListener = eventEmitter.removeListener;\n\t\t\n\t\tthis.collections = collections;\n\t\t\n\t\tthis.abilities = new AbilitiesMap<AS>(options.abilities);\n\t\t\n\t\tthis.initOptions = options;\n\t\t\n\t\tvoid this.init();\n\t\t\n\t}\n\t\n\t#eventEmitter;\n\t_events;\n\t_eventsCount;\n\temit;\n\t\n\ton(event: \"user-create\" | \"user-is-online\" | \"user-permissions-change\", callback: (user: User<AS>) => void): this;\n\ton(event: \"session-delete\", callback: (session: Session<AS>) => void): this;\n\ton<T extends string | symbol>(event: T, callback: (...args: any[]) => void, context?: any) {\n\t\tthis.#eventEmitter.on(event, callback, context);\n\t\t\n\t\treturn this;\n\t}\n\t\n\tonce;\n\taddListener;\n\toff;\n\tremoveListener;\n\t\n\tprivate initOptions?;\n\t\n\tcollections;\n\tabilities;\n\t\n\tcollection!: WatchedCollection<UserDoc>;\n\troles!: Roles<AS>;\n\tsessions!: Sessions<AS>;\n\torgs!: Orgs<AS>;\n\tavatars!: Avatars;\n\t\n\tbyEmail = new Map();\n\tbySessionId = new Map();\n\tsorted: User<AS>[] = [];\n\t\n\tisSortRequired = true;\n\t\n\t#isPreinited = false;\n\t\n\tasync preinit() {\n\t\t\n\t\tif (!this.#isPreinited) {\n\t\t\tthis.#isPreinited = true;\n\t\t\t\n\t\t\tconst {\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tschema: customSchema,\n\t\t\t\tinitialRoot: initialRootProps,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string [], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = await this.collections.ensure<UserDoc>(\"users\", { ...collectionOptions, schema });\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tif (!await this.collection.countDocuments({ roles: \"root\" }))\n\t\t\t\tawait this.create({\n\t\t\t\t\temail: process.env.INSITE_ROOT_EMAIL ?? \"insite@root.email\",\n\t\t\t\t\tpassword: process.env.INSITE_ROOT_PASSWORD ?? \"inSiteRootPassword\",\n\t\t\t\t\tname: { first: \"Root\" },\n\t\t\t\t\tjob: \"Root\",\n\t\t\t\t\t...initialRootProps,\n\t\t\t\t\troles: [ \"root\" ],\n\t\t\t\t\torg: null,\n\t\t\t\t\tmeta: {}\n\t\t\t\t});\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const userDoc of this.collection.find())\n\t\t\t\tthis.load(userDoc);\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tisInited = false;\n\t\n\tprotected async init() {\n\t\t\n\t\tif (!this.isInited) {\n\t\t\tconst {\n\t\t\t\troles: rolesOptions,\n\t\t\t\torgs: orgsOptions,\n\t\t\t\tsessions: sessionsOptions,\n\t\t\t\tavatars: avatarsOptions,\n\t\t\t\tcollection: { quiet } = {}\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tthis.roles = new Roles<AS>(this, { ...rolesOptions, collection: { quiet, ...rolesOptions?.collection } });\n\t\t\tthis.orgs = new Orgs<AS>(this, { ...orgsOptions, collection: { quiet, ...orgsOptions?.collection } });\n\t\t\tthis.sessions = new Sessions<AS>(this, { ...sessionsOptions, collection: { quiet, ...sessionsOptions?.collection } });\n\t\t\tthis.avatars = new Avatars(this, { ...avatarsOptions, collection: { quiet, ...avatarsOptions?.collection } });\n\t\t\t\n\t\t\tawait this.roles.init();\n\t\t\tawait this.orgs.preinit();\n\t\t\tawait this.preinit();\n\t\t\tthis.orgs.init();\n\t\t\tawait this.avatars.init();\n\t\t\t\n\t\t\tthis.update(true);\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tawait this.sessions.init();\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t\t\n\t\t\tthis.isInited = true;\n\t\t\t\n\t\t\tthis.#initPromise.resolve(this);\n\t\t}\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<UserDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\":\n\t\t\t\tnew User<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\t\n\tload(userDoc: UserDoc) {\n\t\tnew User<AS>(this, userDoc);\n\t\t\n\t}\n\t\n\tsort() {\n\t\t\n\t\tthis.isSortRequired = false;\n\t\t\n\t\tthis.sorted = [ ...this.values() ].sort((a, b) => a.name.last > b.name.last ? 1 : a.name.last < b.name.last ? -1 : 0);\n\t\t\n\t}\n\t\n\tupdate(shouldUpdateRoles?: boolean) {\n\t\tif (shouldUpdateRoles)\n\t\t\tfor (const user of this.values())\n\t\t\t\tuser.updateRoles();\n\t\t\n\t\tfor (const user of this.values())\n\t\t\tuser.updatePermissions();\n\t\t\n\t\tif (this.isSortRequired)\n\t\t\tthis.sort();\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\tasync create({ email, password, roles, name, org, job, ...restProps }: NewUser) {\n\t\tif (this.byEmail.has(email))\n\t\t\tthrow new Error(\"User exists\");\n\t\t\n\t\tconst _id = newObjectIdString();\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\temail,\n\t\t\tpassword: await hash(password),\n\t\t\troles: this.isInited ? this.roles.cleanUpIds(roles) : roles,\n\t\t\tname: {\n\t\t\t\tfirst: name.first ?? \"\",\n\t\t\t\tmiddle: name.middle ?? \"\",\n\t\t\t\tlast: name.last ?? \"\"\n\t\t\t},\n\t\t\torg: org ?? null,\n\t\t\tjob: job ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"_id\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateUser(_id: string, updates: Omit<UserDoc, \"_id\" | \"createdAt\">, byUser?: User<AS>) {\n\t\tconst user = this.get(_id)!;\n\t\t\n\t\tif (!user)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.roles)\n\t\t\tupdates.roles =\n\t\t\t\tuser.isRoot ?\n\t\t\t\t\t[ \"root\" ] :\n\t\t\t\t\tthis.roles.cleanUpIds(\n\t\t\t\t\t\tbyUser ?\n\t\t\t\t\t\t\twithout(user.ownRoleIds, byUser.slaveRoleIds).concat(updates.roles) :\n\t\t\t\t\t\t\tupdates.roles\n\t\t\t\t\t);\n\t\t\n\t\tawait this.collection.updateOne({ _id }, { $set: updates });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tasync changePassword(_id: string, newPassword: string) {\n\t\tif (!this.has(_id))\n\t\t\tthrow new Error(\"usernotfound\");\n\t\t\n\t\tif (!newPassword)\n\t\t\tthrow new Error(\"emptypasswordisnotallowed\");\n\t\t\n\t\tawait Promise.all([\n\t\t\tthis.collection.updateOne({ _id }, { $set: { password: await hash(newPassword) } }),\n\t\t\tthis.sessions.collection.deleteMany({ user: _id })\n\t\t]);\n\t\t\n\t}\n\t\n\tasync login(email: string, password: string, sessionProps: Partial<SessionDoc>) {\n\t\tconst user = this.byEmail.get(email);\n\t\t\n\t\tif (!user)\n\t\t\tthrow new Error(\"usernotfound\");\n\t\t\n\t\tif (!await verify(user.password, password))\n\t\t\tthrow new Error(\"incorrectpassword\");\n\t\t\n\t\tif (!user.abilities.login)\n\t\t\tthrow new Error(\"userisnotabletologin\");\n\t\t\n\t\treturn this.sessions.create(user, sessionProps);\n\t}\n\t\n\tlogout(session: Session<AS>) {\n\t\tsession.delete();\n\t\t\n\t\treturn this.sessions.collection.deleteOne({ _id: session._id });\n\t}\n\t\n\t#sortUsersAndOrgs(a: Org<AS> | User<AS>, b: Org<AS> | User<AS>) {\n\t\treturn (\n\t\t\t(a instanceof User && b instanceof User) ?\n\t\t\t\t(a.name.last && b.name.last) ?\n\t\t\t\t\ta.name.last > b.name.last ?\n\t\t\t\t\t\t1 :\n\t\t\t\t\t\ta.name.last < b.name.last ? -1 : 0 :\n\t\t\t\t\t(!a.name.last && !b.name.last) ?\n\t\t\t\t\t\ta.displayLabel > b.displayLabel ?\n\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\ta.displayLabel < b.displayLabel ? -1 : 0 :\n\t\t\t\t\t\ta.name.last ? -1 : 1 :\n\t\t\t\t(a instanceof Org && b instanceof Org) ?\n\t\t\t\t\ta.title > b.title ?\n\t\t\t\t\t\t1 :\n\t\t\t\t\t\ta.title < b.title ? -1 : 0 :\n\t\t\t\t\ta instanceof Org ? -1 : 1\n\t\t);\n\t}\n\t\n\tsortIds(ids: string[]) {\n\t\treturn _ids((\n\t\t\tids\n\t\t\t\t.map(_id => this.get(_id) || this.orgs.get(_id))\n\t\t\t\t.filter(Boolean) as (Org<AS> | User<AS>)[]\n\t\t).sort(this.#sortUsersAndOrgs));\n\t}\n\t\n\treplaceMap = new Map<string, string>();\n\t\n\treplaceHandlers = new Set<(fromId: string, toId: string | null) => Promise<void> | void>();\n\t\n\tasync replace(fromId: string) {\n\t\tconst toId = this.replaceMap.get(fromId) ?? null;\n\t\tif (toId)\n\t\t\tthis.replaceMap.delete(fromId);\n\t\t\n\t\tfor (const handler of this.replaceHandlers)\n\t\t\tawait handler(fromId, toId);\n\t\t\n\t}\n\t\n\tasync deleteUser(_id: string) {\n\t\tconst { deletedCount } = await this.collection.deleteOne({ _id });\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n\t\n\tstatic init<IAS extends AbilitiesSchema>(collections: Collections, options: Options<IAS>) {\n\t\tconst users = new Users(collections, options);\n\t\t\n\t\treturn users.whenReady();\n\t}\n\t\n}\n", "import {\n\t_ids,\n\tdeleteProps,\n\tEmptyArray,\n\tEmptySet,\n\tremoveAll,\n\tsort,\n\tunion,\n\twithout\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport type { User, Users } from \"../users\";\nimport { Org } from \"./Org\";\nimport { basisSchema } from \"./schema\";\nimport type { NewOrg, OrgDoc, OrgsOptions } from \"./types\";\n\n\nconst indexes: CollectionIndexes = [\n\t[ { owners: 1 } ]\n];\n\nfunction preventDirectDelete() {\n\tthrow new Error(\"Direct usage of orgs collection.deleteOne or .deleteMany is forbidden. Use orgs.deleteOrg instead.\");\n}\n\n\nexport class Orgs<AS extends AbilitiesSchema> extends Map<string, Org<AS>> {\n\tconstructor(users: Users<AS>, options: OrgsOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.preinitOptions = options;\n\t\t\n\t}\n\t\n\tusers;\n\tcollections;\n\tprivate preinitOptions?;\n\t\n\tcollection!: WatchedCollection<OrgDoc> & {\n\t\t/** @deprecated Direct usage of roles collection.deleteOne is forbidden. Use orgs.deleteOrg instead. */\n\t\tdeleteOne: typeof preventDirectDelete;\n\t\t\n\t\t/** @deprecated Direct usage of roles collection.deleteMany is forbidden. Use orgs.deleteOrg instead. */\n\t\tdeleteMany: typeof preventDirectDelete;\n\t};\n\t\n\tnull!: Org<AS> & { _id: null };\n\t\n\t#isPreinited = false;\n\t\n\tasync preinit() {\n\t\t\n\t\tif (!this.#isPreinited) {\n\t\t\tthis.#isPreinited = true;\n\t\t\t\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tnull: nullProps,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.preinitOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string [], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<OrgDoc>(\"orgs\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\tdeleteOne: preventDirectDelete,\n\t\t\t\t\tdeleteMany: preventDirectDelete\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\t// TODO: customIndexes should be moved to collectionOptions\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tthis.null = Object.assign(\n\t\t\t\tnew Org<AS>(this, {\n\t\t\t\t\t...nullProps,\n\t\t\t\t\t_id: \"\",\n\t\t\t\t\ttitle: \"\",\n\t\t\t\t\tnote: \"\",\n\t\t\t\t\towners: [],\n\t\t\t\t\tmeta: {},\n\t\t\t\t\tcreatedAt: Date.now()\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t_id: null,\n\t\t\t\t\townerIds: new EmptyArray(),\n\t\t\t\t\townerOrgs: new EmptySet(),\n\t\t\t\t\townerUsers: new EmptySet(),\n\t\t\t\t\tslaveOrgs: new EmptySet()\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const orgDoc of this.collection.find())\n\t\t\t\tthis.load(orgDoc);\n\t\t\t\n\t\t\tdelete this.preinitOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tinit() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tthis.update();\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t}\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<OrgDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\": {\n\t\t\t\tnew Org<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tload(orgDoc: OrgDoc) {\n\t\tnew Org<AS>(this, orgDoc);\n\t\t\n\t}\n\t\n\t#resolve(org: Org<AS>, slaveOrgs: Org<AS>[]) {\n\t\tslaveOrgs = [ org, ...slaveOrgs ];\n\t\t\n\t\tfor (const ownerOrg of org.ownerOrgs) {\n\t\t\tthis.#resolve(ownerOrg, slaveOrgs);\n\t\t\tfor (const slaveOrg of slaveOrgs)\n\t\t\t\townerOrg.slaveOrgs.add(slaveOrg);\n\t\t}\n\t\t\n\t}\n\t\n\tsorted: Org<AS>[] = [];\n\t\n\tupdate() {\n\t\t\n\t\tconst array = [ ...this.values() ];\n\t\tconst sorted = [];\n\t\t\n\t\tfor (const org of array) {\n\t\t\torg.ownerOrgs.clear();\n\t\t\torg.ownerUsers.clear();\n\t\t\torg.slaveOrgs.clear();\n\t\t\t\n\t\t\tfor (const ownerId of org.ownerIds) {\n\t\t\t\tconst ownerOrg = this.get(ownerId);\n\t\t\t\tif (ownerOrg)\n\t\t\t\t\torg.ownerOrgs.add(ownerOrg);\n\t\t\t\telse {\n\t\t\t\t\tconst ownerUser = this.users.get(ownerId);\n\t\t\t\t\tif (ownerUser)\n\t\t\t\t\t\torg.ownerUsers.add(ownerUser);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (!org.ownerOrgs.size && org._id)\n\t\t\t\tsorted.push(org);\n\t\t}\n\t\t\n\t\tfor (const org of array)\n\t\t\tif (!array.some(anotherOrg => anotherOrg.ownerOrgs.has(org)))\n\t\t\t\tthis.#resolve(org, []);\n\t\t\n\t\tsorted.sort(this.#sortOrgs);\n\t\tfor (const org of array)\n\t\t\tsort(org.slaveOrgs, this.#sortOrgs);\n\t\t\n\t\tfor (let i = 0; i < sorted.length; i++) {\n\t\t\tconst org = sorted[i];\n\t\t\tfor (const slaveOrg of [ ...org.slaveOrgs ].reverse())\n\t\t\t\tif (slaveOrg.ownerOrgs.has(org)) {\n\t\t\t\t\tconst slaveOrgIndex = sorted.indexOf(slaveOrg);\n\t\t\t\t\tif (~slaveOrgIndex) {\n\t\t\t\t\t\tsorted.splice(slaveOrgIndex, 1);\n\t\t\t\t\t\ti--;\n\t\t\t\t\t}\n\t\t\t\t\tsorted.splice(i + 1, 0, slaveOrg);\n\t\t\t\t}\n\t\t}\n\t\tfor (let o = 0, { length } = sorted; o < length;)\n\t\t\tsorted[o]._o = o++;\n\t\t\n\t\tthis.sorted = sorted;\n\t\t\n\t\tif (this.users.isInited)\n\t\t\tthis.users.update();\n\t\t\n\t}\n\t\n\t#sortOrgs(a: Org<AS>, b: Org<AS>) {\n\t\treturn (\n\t\t\t(b.slaveOrgs.size - a.slaveOrgs.size) || (\n\t\t\t\ta.title > b.title ?\n\t\t\t\t\t1 :\n\t\t\t\t\ta.title < b.title ?\n\t\t\t\t\t\t-1 :\n\t\t\t\t\t\t0\n\t\t\t)\n\t\t);\n\t}\n\t\n\tasync create({ title, note, ...restProps }: NewOrg) {\n\t\t\n\t\tconst _id = newObjectIdString();\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\ttitle: title ?? \"\",\n\t\t\tnote: note ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"_id\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateOrg(_id: string, updates: Omit<OrgDoc, \"_id\" | \"createdAt\">, byUser?: User<AS>) {\n\t\tconst org = this.get(_id)!;\n\t\t\n\t\tif (!org)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.owners)\n\t\t\tupdates.owners =\n\t\t\t\tthis.users.sortIds(\n\t\t\t\t\tunion(\n\t\t\t\t\t\tbyUser ?\n\t\t\t\t\t\t\twithout(org.ownerIds, byUser.slaveIds) :\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\twithout(updates.owners, [ _id, ..._ids(org.slaveOrgs) ])\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\n\t\tawait this.collection.updateOne({ _id }, { $set: updates });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tdeleteOrg(org: Org<AS> | string) {\n\t\tconst _id = typeof org == \"string\" ? org : org._id;\n\t\t\n\t\treturn this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { owners: _id }, update: { $pullAll: { owners: [ _id ] } } } },\n\t\t\t{ deleteOne: { filter: { _id } } }\n\t\t]);\n\t}\n\t\n\treplaceMap = new Map<string, string>();\n\t\n\treplaceHandlers = new Set<(fromId: string, toId: string | null) => Promise<void> | void>();\n\t\n\tasync replace(fromId: string) {\n\t\tconst toId = this.replaceMap.get(fromId) ?? null;\n\t\tif (toId)\n\t\t\tthis.replaceMap.delete(fromId);\n\t\t\n\t\tfor (const handler of this.replaceHandlers)\n\t\t\tawait handler(fromId, toId);\n\t\t\n\t}\n\t\n}\n", "import type { AbilitiesSchema } from \"insite-common\";\nimport { User } from \"../users/User\";\nimport type { Orgs } from \"./Orgs\";\nimport type { OrgDoc } from \"./types\";\n\n\nconst snapshots = new WeakMap();\n\n\nexport class Org<AS extends AbilitiesSchema> {\n\tconstructor(orgs: Orgs<AS>, orgDoc: OrgDoc) {\n\t\tthis.orgs = orgs;\n\t\t\n\t\tthis._id = orgDoc._id;\n\t\torgs.set(this._id, this);\n\t\t\n\t\tvoid this.update(orgDoc);\n\t\t\n\t}\n\t\n\t_id;\n\ttitle = \"\";\n\tinitials = \"\";\n\tdisplayLabel = \"\";\n\t\n\t_o = 0;\n\t\n\torgs;\n\t\n\tisOrg = true;\n\t\n\townerOrgs = new Set<Org<AS>>();\n\townerUsers = new Set<User<AS>>();\n\t\n\tusers = new Set<User<AS>>();\n\t\n\tslaveOrgs = new Set<Org<AS>>();\n\t\n\townerIds: string[] = [];\n\t\n\tupdate({ _id, title, owners: ownerIds, ...restProps }: Partial<OrgDoc>) {\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tif (title !== undefined) {\n\t\t\tthis.title = title;\n\t\t\tthis.initials = title?.[0]?.toUpperCase() ?? \"\";\n\t\t\tthis.displayLabel = title;\n\t\t}\n\t\t\n\t\tif (ownerIds) {\n\t\t\tthis.ownerIds = ownerIds;\n\t\t\t\n\t\t\tconst snapshot = this.ownerIds.join(\",\");\n\t\t\t\n\t\t\tif (snapshot !== snapshots.get(this)) {\n\t\t\t\tsnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.orgs.users.isInited)\n\t\t\t\t\tthis.orgs.update();\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tasync delete() {\n\t\t\n\t\tthis.orgs.delete(this._id);\n\t\t\n\t\tsnapshots.delete(this);\n\t\t\n\t\tawait this.orgs.replace(this._id);\n\t\t\n\t\tthis.orgs.update();\n\t\t\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"title\",\n\t\t\"note\",\n\t\t\"owners\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\ttitle: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 512\n\t\t},\n\t\tnote: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 131072\n\t\t},\n\t\towners: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps._id.source\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { randomBytes } from \"node:crypto\";\nimport { deleteProps, removeAll } from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport { User } from \"../users/User\";\nimport type { Users } from \"../users\";\nimport { basisSchema } from \"./schema\";\nimport { Session } from \"./Session\";\nimport { SessionDoc, SessionsOptions } from \"./types\";\n\n\nconst expireAfterSeconds = 3600 * 24 * 7;\n\nconst indexes: CollectionIndexes = [\n\t[ { user: 1 } ],\n\t[ { expiresAt: 1 }, { expireAfterSeconds } ]\n];\n\n\nexport class Sessions<AS extends AbilitiesSchema> extends Map<string, Session<AS>> {\n\tconstructor(users: Users<AS>, options: SessionsOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.initOptions = options;\n\t}\n\t\n\tusers;\n\tcollections;\n\t\n\tprivate initOptions?;\n\t\n\tcollection!: WatchedCollection<SessionDoc> & {\n\t\texpireAfterSeconds: number;\n\t};\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<SessionDoc>(\"sessions\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\texpireAfterSeconds\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const sessionDoc of this.collection.find())\n\t\t\t\tthis.load(sessionDoc);\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { meta: { $exists: false } }, update: { $set: { meta: {} } } } },\n\t\t\t{ updateMany: { filter: { isOnline: true }, update: { $set: { isOnline: false } } } }\n\t\t]);\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<SessionDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\":\n\t\t\t\tif (!this.has(next.documentKey._id))\n\t\t\t\t\tnew Session<AS>(this, next.fullDocument);\n\t\t\t\t\n\t\t\t\tvoid this.users.get(next.fullDocument.user)?.trimSessions();\n\t\t\t\t\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tthis.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tthis.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tthis.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tuid() {\n\t\treturn `${newObjectIdString()}~${randomBytes(32).toString(\"base64url\")}`;\n\t}\n\t\n\tload(sessionDoc: SessionDoc) {\n\t\tnew Session<AS>(this, sessionDoc);\n\t\t\n\t}\n\t\n\tasync create(user: User<AS>, props: Partial<SessionDoc>) {\n\t\t\n\t\tconst ts = Date.now();\n\t\t\n\t\tconst sessionDoc: SessionDoc = {\n\t\t\tuserAgent: \"\",\n\t\t\tremoteAddress: \"127.0.0.1\",\n\t\t\tisOnline: true,\n\t\t\t...props,\n\t\t\t_id: this.uid(),\n\t\t\tuser: user._id,\n\t\t\tmeta: {},\n\t\t\tcreatedAt: ts,\n\t\t\tprolongedAt: ts,\n\t\t\texpiresAt: new Date(ts + (expireAfterSeconds * 1000))\n\t\t};\n\t\t\n\t\t/* new Session(\u2026) before await insertOne(\u2026) for avoid changeStream insert event to come earlier and create the session duplicate */\n\t\tconst session = new Session<AS>(this, sessionDoc);\n\t\t\n\t\tawait this.collection.insertOne(sessionDoc);\n\t\t\n\t\treturn session;\n\t}\n\t\n\tasync destroySession(_id: string) {\n\t\tconst { deletedCount } = await this.collection.deleteOne({ _id });\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"user\",\n\t\t\"remoteAddress\",\n\t\t\"isOnline\",\n\t\t\"meta\",\n\t\t\"createdAt\",\n\t\t\"prolongedAt\",\n\t\t\"expiresAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.sessionId.source\n\t\t},\n\t\tuser: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\tuserAgent: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 4096\n\t\t},\n\t\tremoteAddress: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.ip.source\n\t\t},\n\t\tisOnline: {\n\t\t\tbsonType: \"bool\"\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\tprolongedAt: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\texpiresAt: {\n\t\t\tbsonType: \"date\"\n\t\t}\n\t}\n\t// TODO: Restrict additional properties (not needed with meta)\n};\n", "import type { AbilitiesSchema } from \"insite-common\";\nimport type { User } from \"../users/User\";\nimport type { Sessions } from \"./Sessions\";\nimport type { SessionDoc } from \"./types\";\n\n\nexport class Session<AS extends AbilitiesSchema> {\n\tconstructor(sessions: Sessions<AS>, sessionDoc: SessionDoc) {\n\t\tconst user = sessions.users.get(sessionDoc.user);\n\t\t\n\t\tif (user) {\n\t\t\tthis.#sessions = sessions;\n\t\t\t\n\t\t\tthis._id = sessionDoc._id;\n\t\t\tthis.#sessions.set(this._id, this);\n\t\t\t\n\t\t\tthis.user = user;\n\t\t\tthis.user.sessions.add(this);\n\t\t\t\n\t\t\tthis.#sessions.users.bySessionId.set(this._id, this.user);\n\t\t\t\n\t\t\tthis.update(sessionDoc);\n\t\t} else\n\t\t\tvoid sessions.collection.deleteOne({ _id: sessionDoc._id });\n\t\t\n\t}\n\t\n\t_id!: string;\n\tuser!: User<AS>;\n\tisOnline = false;\n\t\n\tuserAgent!: string;\n\tremoteAddress!: string;\n\tcreatedAt!: number;\n\tprolongedAt!: number;\n\texpiresAt!: Date;\n\t\n\t#sessions!: Sessions<AS>;\n\t\n\tupdate({ _id, user, isOnline, ...restProps }: Partial<SessionDoc>) {\n\t\t\n\t\tif (isOnline !== undefined && this.isOnline !== isOnline) {\n\t\t\tthis.isOnline = isOnline;\n\t\t\t\n\t\t\tif (this.#sessions.users.isInited && this.user.isOnline !== this.isOnline)\n\t\t\t\tvoid this.user.updateIsOnlineDebounced();\n\t\t}\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t}\n\t\n\tprolong({ _id, user, ...updates }: Partial<SessionDoc>) {\n\t\t\n\t\tconst ts = Date.now();\n\t\t\n\t\tupdates.prolongedAt = ts;\n\t\tupdates.expiresAt = new Date(ts + (this.#sessions.collection.expireAfterSeconds * 1000));\n\t\t\n\t\tthis.update(updates);\n\t\t\n\t\treturn this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t}\n\t\n\tasync online() {\n\t\t\n\t\tif (!this.isOnline) {\n\t\t\tconst updates = { isOnline: true };\n\t\t\t\n\t\t\tthis.update(updates);\n\t\t\t\n\t\t\tawait this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t\t}\n\t\t\n\t}\n\t\n\tasync offline() {\n\t\t\n\t\tif (this.isOnline) {\n\t\t\tconst updates = { isOnline: false };\n\t\t\t\n\t\t\tthis.update(updates);\n\t\t\t\n\t\t\tawait this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t\t}\n\t\t\n\t}\n\t\n\tdelete() {\n\t\t\n\t\tthis.#sessions.delete(this._id);\n\t\tthis.user.sessions.delete(this);\n\t\tthis.#sessions.users.bySessionId.delete(this._id);\n\t\t\n\t\tthis.#sessions.users.emit(\"session-delete\", this);\n\t\t\n\t\tif (this.isOnline)\n\t\t\tthis.user.updateIsOnline();\n\t\t\n\t}\n\t\n}\n", "import { Binary, type WatchedCollection } from \"insite-db\";\nimport type { Users } from \"../Users\";\nimport { schema } from \"./schema\";\nimport type { AvatarDoc, AvatarsOptions } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class Avatars {\n\tconstructor(users: Users<any>, options: AvatarsOptions = {}) {\n\t\tthis.#users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.initOptions = options;\n\t\t\n\t}\n\t\n\treadonly TYPES_ACCEPTED = [ \"image/webp\" ];\n\treadonly MAX_SIZE = 1024 * 512;\n\t\n\t#users;\n\tcollections;\n\t\n\tcollection!: WatchedCollection<AvatarDoc>;\n\t\n\tprivate initOptions?;\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.#users.isInited) {\n\t\t\tconst {\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tthis.collection = await this.collections.ensure<AvatarDoc>(\"users.avatars\", { ...collectionOptions, schema });\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tasync save(_id: string, type: string, data: string) {\n\t\tconst binaryData = Binary.createFromBase64(data.slice(data.indexOf(\",\")));\n\t\t\n\t\tconst ts = Date.now().toString(36);\n\t\t\n\t\tawait Promise.all([\n\t\t\tthis.collection.replaceOne({ _id }, {\n\t\t\t\ttype,\n\t\t\t\tsize: binaryData.length(),\n\t\t\t\tts,\n\t\t\t\tdata: binaryData,\n\t\t\t\tmeta: {}\n\t\t\t}, { upsert: true }),\n\t\t\tthis.#users.collection.updateOne({ _id }, { $set: { avatar: ts } })\n\t\t]);\n\t\t\n\t}\n\t\n\tasync deleteAvatar(_id: string) {\n\t\t\n\t\tconst [ { deletedCount } ] = await Promise.all([\n\t\t\tthis.collection.deleteOne({ _id }),\n\t\t\tthis.#users.collection.updateOne({ _id }, { $set: { avatar: null } })\n\t\t]);\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../../lib\";\n\n\nexport const schema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"type\",\n\t\t\"size\",\n\t\t\"ts\",\n\t\t\"data\",\n\t\t\"meta\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\ttype: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 256\n\t\t},\n\t\tsize: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\tts: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 10\n\t\t},\n\t\tdata: {\n\t\t\tbsonType: \"binData\"\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"email\",\n\t\t\"password\",\n\t\t\"roles\",\n\t\t\"name\",\n\t\t\"org\",\n\t\t\"job\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\temail: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.email.source\n\t\t},\n\t\tpassword: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.argon2.source\n\t\t},\n\t\troles: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps.role.source\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tname: {\n\t\t\tbsonType: \"object\",\n\t\t\trequired: [\n\t\t\t\t\"first\",\n\t\t\t\t\"middle\",\n\t\t\t\t\"last\"\n\t\t\t],\n\t\t\tproperties: {\n\t\t\t\tfirst: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t},\n\t\t\t\tmiddle: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t},\n\t\t\t\tlast: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t}\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\torg: {\n\t\t\toneOf: [\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tpattern: regexps._id.source\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"null\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tjob: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 512\n\t\t},\n\t\tavatar: {\n\t\t\toneOf: [\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 10\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"null\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import {\n\t_ids,\n\tdebounce,\n\tempty,\n\thasAny,\n\tremoveOne\n} from \"@nesvet/n\";\nimport type { Abilities, AbilitiesSchema } from \"insite-common\";\nimport type { GenericAbilities } from \"../abilities/types\";\nimport type { Org } from \"../orgs/Org\";\nimport type { Role } from \"../roles/Role\";\nimport type { Session } from \"../sessions/Session\";\nimport type { UserDoc } from \"./types\";\nimport type { Users } from \"./Users\";\n\n\nconst rolesSnapshots = new WeakMap();\nconst permissionsSnapshots = new WeakMap();\n\nconst staticUrl = process.env.INSITE_STATIC_URL ?? \"\";\n\n\nexport class User<AS extends AbilitiesSchema> {\n\tconstructor(users: Users<AS>, userDoc: UserDoc) {\n\t\tthis.#users = users;\n\t\t\n\t\tthis._id = userDoc._id;\n\t\tusers.set(this._id, this);\n\t\t\n\t\tvoid this.update(userDoc);\n\t\t\n\t\tif (users.isInited)\n\t\t\tusers.emit(\"user-create\", this);\n\t\t\n\t}\n\t\n\t_id;\n\temail!: string;\n\tname = {\n\t\tfirst: \"\",\n\t\tmiddle: \"\",\n\t\tlast: \"\"\n\t};\n\t\n\tinitials = \"\";\n\tdisplayLabel = \"\";\n\torg!: Org<AS>;\n\tjob: string = \"\";\n\tavatar: string | null = null;\n\tavatarUrl: string | null = null;\n\t\n\t#users;\n\t\n\tisUser = true;\n\tisRoot?: boolean;\n\t\n\troles = new Set<Role<AS>>();\n\townRoles: Role<AS>[] = [];\n\townRoleIds: string[] = [];\n\tslaveRoles = new Set<Role<AS>>();\n\tslaveRoleIds: string[] = [];\n\tabilities: Abilities<AS> = {};\n\t\n\tslaveOrgs = new Set<Org<AS>>();\n\tslaveUsers = new Set<User<AS>>();\n\tslaves = new Set<Org<AS> | User<AS>>();\n\t\n\tslaveIds: string[] = [];\n\tpermissiveIds: string[] = [];\n\t\n\tsessions = new Set<Session<AS>>();\n\t\n\tisOnline = false;\n\t\n\tupdate({ _id, name, email, roles: ownRoleIds, org: orgId, avatar, ...restProps }: Partial<UserDoc>) {\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tlet isEmailUpdated;\n\t\tif (email && this.email !== email) {\n\t\t\tthis.#users.byEmail.delete(this.email);\n\t\t\tthis.email = email;\n\t\t\tthis.#users.byEmail.set(email, this);\n\t\t\tisEmailUpdated = true;\n\t\t}\n\t\t\n\t\tlet isNameUpdated;\n\t\tlet isLastNameUpdated;\n\t\tif (name && (this.name.first !== name.first || this.name.middle !== name.middle || this.name.last !== name.last)) {\n\t\t\tisLastNameUpdated = this.name.last !== name.last;\n\t\t\tthis.name = {\n\t\t\t\tfirst: name.first ?? \"\",\n\t\t\t\tmiddle: name.middle ?? \"\",\n\t\t\t\tlast: name.last ?? \"\"\n\t\t\t};\n\t\t\tthis.initials = (((name.first?.[0] ?? \"\") + (name.last?.[0] ?? \"\")) || this.email[0]).toUpperCase();\n\t\t\tisNameUpdated = true;\n\t\t}\n\t\t\n\t\tif (isEmailUpdated || isNameUpdated)\n\t\t\tthis.displayLabel = `${this.name.first} ${this.name.last}`.trim() || this.name.middle || this.email;\n\t\t\n\t\tlet isRolesUpdated;\n\t\tif (ownRoleIds) {\n\t\t\tthis.ownRoleIds = ownRoleIds;\n\t\t\t\n\t\t\tconst snapshot = this.ownRoleIds.join(\",\");\n\t\t\t\n\t\t\tif (snapshot !== rolesSnapshots.get(this)) {\n\t\t\t\trolesSnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.#users.isInited) {\n\t\t\t\t\tthis.updateRoles();\n\t\t\t\t\tisRolesUpdated = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlet isOrgUpdated;\n\t\tif (orgId !== undefined && this.org?._id !== orgId) {\n\t\t\tthis.org?.users.delete(this);\n\t\t\tthis.org = orgId && this.#users.orgs.get(orgId) || this.#users.orgs.null;// eslint-disable-line @stylistic/no-mixed-operators\n\t\t\tthis.org.users.add(this);\n\t\t\tisOrgUpdated = true;\n\t\t}\n\t\t\n\t\tif (avatar !== undefined && this.avatar !== avatar) {\n\t\t\tthis.avatar = avatar;\n\t\t\tthis.avatarUrl = avatar && `${staticUrl}/avatars/${this._id}-${avatar}.webp`;\n\t\t}\n\t\t\n\t\tif (this.#users.isInited)\n\t\t\tif (isRolesUpdated || isOrgUpdated) {\n\t\t\t\tthis.updatePermissions();\n\t\t\t\t\n\t\t\t\tif (isLastNameUpdated)\n\t\t\t\t\tthis.#users.isSortRequired = true;\n\t\t\t\t\n\t\t\t\tthis.#users.update();\n\t\t\t} else if (isLastNameUpdated)\n\t\t\t\tthis.#users.sort();\n\t\t\n\t}\n\t\n\tupdateRoles() {\n\t\t\n\t\tthis.ownRoles = [];\n\t\tthis.roles.clear();\n\t\tthis.slaveRoles.clear();\n\t\tempty(this.abilities);\n\t\t\n\t\tfor (const roleId of this.ownRoleIds) {\n\t\t\tconst role = this.#users.roles.get(roleId);\n\t\t\tif (role) {\n\t\t\t\t\n\t\t\t\tthis.ownRoles.push(role);\n\t\t\t\tthis.roles.add(role);\n\t\t\t\tfor (const involvedRole of role.involves) {\n\t\t\t\t\tthis.roles.add(involvedRole);\n\t\t\t\t\tthis.slaveRoles.add(involvedRole);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tthis.slaveRoleIds = _ids(this.slaveRoles);\n\t\t\t\t\n\t\t\t\tthis.#users.abilities.merge(this.abilities as GenericAbilities, role.abilities as GenericAbilities);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (this.roles.has(this.#users.roles.root))\n\t\t\tthis.isRoot = true;\n\t\t\n\t\tvoid this.trimSessions();\n\t\t\n\t}\n\t\n\tupdatePermissions() {\n\t\t\n\t\tthis.slaveOrgs.clear();\n\t\tthis.slaveUsers.clear();\n\t\tthis.slaves.clear();\n\t\tconst slaveIds = new Set<string>();\n\t\t\n\t\tfor (const org of this.#users.orgs.sorted)\n\t\t\tif ((org.ownerUsers.has(this) || this.isRoot) && !this.slaveOrgs.has(org)) {\n\t\t\t\tthis.slaveOrgs.add(org);\n\t\t\t\tthis.slaves.add(org);\n\t\t\t\tslaveIds.add(org._id);\n\t\t\t\tfor (const slaveOrg of org.slaveOrgs) {\n\t\t\t\t\tthis.slaveOrgs.add(slaveOrg);\n\t\t\t\t\tthis.slaves.add(slaveOrg);\n\t\t\t\t\tslaveIds.add(slaveOrg._id);\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\tfor (const org of new Set([ this.org, ...this.slaveOrgs, this.#users.orgs.null ]))\n\t\t\tfor (const user of org.users)\n\t\t\t\tif (user !== this && (hasAny(this.slaveRoles, user.ownRoles) || !user.ownRoles.length)) {\n\t\t\t\t\tthis.slaveUsers.add(user);\n\t\t\t\t\tthis.slaves.add(user);\n\t\t\t\t\tslaveIds.add(user._id);\n\t\t\t\t}\n\t\t\n\t\tthis.slaveIds = [ ...slaveIds ];\n\t\t\n\t\tconst permissiveOrgIds = [];\n\t\tif (this.org._id) {\n\t\t\tpermissiveOrgIds.push(this.org._id);\n\t\t\tfor (const slaveOrg of this.org.slaveOrgs)\n\t\t\t\tif (!this.slaveOrgs.has(slaveOrg))\n\t\t\t\t\tpermissiveOrgIds.push(slaveOrg._id);\n\t\t}\n\t\t\n\t\tthis.permissiveIds = [ ...permissiveOrgIds, this._id, ...slaveIds ];\n\t\t\n\t\t\n\t\tconst snapshot = [\n\t\t\tthis.permissiveIds.join(\",\"),\n\t\t\tthis.ownRoleIds.join(\",\"),\n\t\t\tJSON.stringify(this.abilities),\n\t\t\tthis.slaveRoleIds.join(\",\")\n\t\t].join(\"\\n\");\n\t\t\n\t\tif (snapshot !== permissionsSnapshots.get(this)) {\n\t\t\tpermissionsSnapshots.set(this, snapshot);\n\t\t\t\n\t\t\tif (this.#users.isInited)\n\t\t\t\tthis.#users.emit(\"user-permissions-change\", this);\n\t\t}\n\t\t\n\t}\n\t\n\ttrimSessions() {\n\t\t\n\t\tconst sessionsLimit = this.abilities.login?.sessionsLimit ?? 0;\n\t\t\n\t\tif (this.sessions.size > sessionsLimit)\n\t\t\treturn this.#users.sessions.collection.deleteMany({\n\t\t\t\t_id: {\n\t\t\t\t\t$in: _ids(\n\t\t\t\t\t\t[ ...this.sessions ]\n\t\t\t\t\t\t\t.sort((a, b) => a.expiresAt.valueOf() - b.expiresAt.valueOf())\n\t\t\t\t\t\t\t.slice(0, this.sessions.size - sessionsLimit)\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t});\n\t\t\n\t}\n\t\n\tupdateIsOnline() {\n\t\t\n\t\tlet isOnline = false;\n\t\t\n\t\tfor (const session of this.sessions)\n\t\t\tif (session.isOnline) {\n\t\t\t\tisOnline = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\n\t\tif (this.isOnline !== isOnline) {\n\t\t\tthis.isOnline = isOnline;\n\t\t\tthis.#users.emit(\"user-is-online\", this);\n\t\t}\n\t\t\n\t}\n\t\n\tupdateIsOnlineDebounced = debounce(() => this.updateIsOnline(), 500);\n\t\n\tasync delete() {\n\t\t\n\t\tthis.org.users.delete(this);\n\t\t\n\t\tthis.#users.delete(this._id);\n\t\tthis.#users.byEmail.delete(this.email);\n\t\tremoveOne(this.#users.sorted, this);\n\t\t\n\t\trolesSnapshots.delete(this);\n\t\tpermissionsSnapshots.delete(this);\n\t\t\n\t\tawait this.#users.replace(this._id);\n\t\t\n\t\tthis.#users.update();\n\t\t\n\t}\n\t\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,OAAAA,OAAW,YAMb,IAAMC,EAAN,cAA2BD,EAAI,CAGrC,YAAYE,EAA2BC,EAAmB,CACrD,OAAOD,GAAU,WACpBC,EAAUD,EACVA,EAAS,QAGV,MAAM,qBAAsB,eAAgB,CAC3C,GAAGA,GAAU,CAAE,QAASA,CAAO,EAC/B,GAAGC,CACJ,CAAC,CAEF,CAEA,KAAO,cAER,ECxBA,OACC,OAAAC,GACA,cAAAC,GACA,cAAAC,GACA,SAAAC,GACA,WAAAC,EACA,gBAAAC,GACA,QAAAC,GACA,WAAAC,OACM,YCeA,SAASC,EAAgBC,EAAwC,CACvE,OAAO,OAAOA,GAAS,QACxB,CAEO,SAASC,EAAqBD,EAAkD,CACtF,OAAO,OAAOA,GAAS,QACxB,CAEO,SAASE,EAAoBF,EAAiD,CACpF,OAAO,MAAM,QAAQA,CAAK,CAC3B,CDTA,IAAMG,EAAkB,IAAI,IAGfC,EAAN,cAAuD,GAA2B,CACxF,YAAYC,EAAqB,CAChC,MAAM,EAEN,QAAWC,KAAaD,EACvB,OAAOC,EAAU,IAEjB,KAAKC,GAAc,KAAKD,CAA0B,GAGlD,SAASE,EAA8BC,EAA0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IA,CAAG,GAAK,KAAK,KAAK,IAAIA,CAAG,CAAC,EAC9C,OAAO,OAAO,EACf,KAAK,KAAKU,EAAiB,CAAC,CAC/B,CAEA,WAAa,IAAI,IAEjB,gBAAkB,IAAI,IAEtB,MAAM,QAAQI,EAAgB,CAC7B,IAAMC,EAAO,KAAK,WAAW,IAAID,CAAM,GAAK,KACxCC,GACH,KAAK,WAAW,OAAOD,CAAM,EAE9B,QAAWE,KAAW,KAAK,gBAC1B,MAAMA,EAAQF,EAAQC,CAAI,CAE5B,CAEA,MAAM,WAAWf,EAAa,CAC7B,GAAM,CAAE,aAAAiB,CAAa,EAAI,MAAM,KAAK,WAAW,UAAU,CAAE,IAAAjB,CAAI,CAAC,EAEhE,MAAO,EAAQiB,CAChB,CAGA,OAAO,KAAkC9D,EAA0BC,EAAuB,CAGzF,OAFc,IAAIF,EAAMC,EAAaC,CAAO,EAE/B,UAAU,CACxB,CAED",
|
|
6
|
-
"names": ["Err", "AbilityError", "longId", "payload", "add", "assignPath", "deletePath", "empty", "getPath", "intersection", "pick", "setPath", "isAbilityObject", "value", "isAbilityParamNumber", "isAbilityParamItems", "schemaParentMap", "AbilitiesMap", "abilitiesSchema", "subSchema", "#hierarchical", "parse", "schemas", "parent", "level", "schema", "longId", "subIds", "subId", "_id", "top", "paramId", "schemaOrLongId", "paramIdOrMax", "max", "ability", "paramSchema", "schemasOrIds", "a", "b", "schemaMaxMap", "resolve", "_schema", "parentSchema", "assignPath", "_max", "abilities", "subSchemas", "subAbilities", "i", "abilityParam", "value", "getPath", "setPath", "referenceValue", "isAbilityParamNumber", "isAbilityParamItems", "itemId", "intersection", "item", "adjustedAbilities", "adjustedAbility", "isAbilityObject", "pick", "empty", "target", "source", "targetAbility", "sourceAbility", "add", "deletePath", "Err", "RolesError", "stringOrArray", "payload", "deleteProps", "getAll", "intersection", "reAdd", "removeAll", "snapshots", "Role", "roles", "roleDoc", "#roles", "_id", "ownInvolveIds", "ownAbilities", "title", "restProps", "snapshot", "regexps", "basisSchema", "regexps", "indexes", "preventDirectDelete", "Roles", "users", "options", "rootProps", "initOptions", "Role", "customSchema", "customIndexes", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "roleDoc", "#handleCollectionChange", "next", "role", "involvedBy", "involvedRoleId", "involvedRole", "involvedByRole", "reAdd", "#sortRoles", "a", "b", "array", "anotherRole", "getAll", "sorted", "i", "involvedRoleIndex", "_o", "_id", "involves", "title", "description", "restProps", "roleId", "updates", "ids", "roles", "intersection", "cleanedUpIds", "abilityLongId", "set", "paramId", "value", "Err", "UnauthorizedError", "payload", "SubordinationError", "type", "ids", "PermissionError", "hash", "verify", "EventEmitter", "_ids", "deleteProps", "removeAll", "StatefulPromise", "without", "newObjectIdString", "_ids", "deleteProps", "EmptyArray", "EmptySet", "removeAll", "sort", "union", "without", "newObjectIdString", "snapshots", "Org", "orgs", "orgDoc", "_id", "title", "ownerIds", "restProps", "snapshot", "basisSchema", "regexps", "indexes", "preventDirectDelete", "Orgs", "users", "options", "#isPreinited", "customSchema", "customIndexes", "nullProps", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "Org", "EmptyArray", "EmptySet", "#maintain", "orgDoc", "#handleCollectionChange", "next", "#resolve", "org", "slaveOrgs", "ownerOrg", "slaveOrg", "array", "sorted", "ownerId", "ownerUser", "anotherOrg", "#sortOrgs", "sort", "slaveOrgIndex", "o", "length", "a", "b", "title", "note", "restProps", "_id", "newObjectIdString", "updates", "byUser", "union", "without", "_ids", "fromId", "toId", "handler", "randomBytes", "deleteProps", "removeAll", "newObjectIdString", "basisSchema", "regexps", "Session", "sessions", "sessionDoc", "user", "#sessions", "_id", "isOnline", "restProps", "updates", "ts", "expireAfterSeconds", "indexes", "Sessions", "users", "options", "customSchema", "customIndexes", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "sessionDoc", "#handleCollectionChange", "next", "Session", "newObjectIdString", "randomBytes", "user", "props", "ts", "session", "_id", "deletedCount", "Binary", "schema", "regexps", "Avatars", "users", "options", "#users", "collectionOptions", "schema", "#maintain", "_id", "type", "data", "binaryData", "Binary", "ts", "deletedCount", "basisSchema", "regexps", "_ids", "debounce", "empty", "hasAny", "removeOne", "rolesSnapshots", "permissionsSnapshots", "staticUrl", "User", "users", "userDoc", "#users", "_id", "name", "email", "ownRoleIds", "orgId", "avatar", "restProps", "isEmailUpdated", "isNameUpdated", "isLastNameUpdated", "isRolesUpdated", "snapshot", "isOrgUpdated", "roleId", "role", "involvedRole", "slaveIds", "org", "slaveOrg", "user", "permissiveOrgIds", "sessionsLimit", "a", "b", "isOnline", "session", "indexes", "Users", "_Users", "collections", "options", "eventEmitter", "EventEmitter", "#eventEmitter", "AbilitiesMap", "event", "callback", "context", "#isPreinited", "customIndexes", "customSchema", "initialRootProps", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "userDoc", "rolesOptions", "orgsOptions", "sessionsOptions", "avatarsOptions", "quiet", "Roles", "Orgs", "Sessions", "Avatars", "#handleCollectionChange", "#initPromise", "next", "User", "a", "b", "shouldUpdateRoles", "user", "StatefulPromise", "email", "password", "roles", "name", "org", "job", "restProps", "_id", "newObjectIdString", "hash", "updates", "byUser", "without", "newPassword", "sessionProps", "verify", "session", "#sortUsersAndOrgs", "Org", "ids", "_ids", "fromId", "toId", "handler", "deletedCount"]
|
|
4
|
+
"sourcesContent": ["import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class AbilityError extends Err {\n\tconstructor(payload?: Payload);\n\tconstructor(longId: string, payload?: Payload);\n\tconstructor(longId?: Payload | string, payload?: Payload) {\n\t\tif (typeof longId == \"object\") {\n\t\t\tpayload = longId;\n\t\t\tlongId = undefined;\n\t\t}\n\t\t\n\t\tsuper(\"User lacks ability\", \"lacksability\", {\n\t\t\t...longId && { ability: longId },\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"AbilityError\";\n\t\n}\n", "import {\n\tadd,\n\tassignPath,\n\tdeletePath,\n\tempty,\n\tgetPath,\n\tintersection,\n\tpick,\n\tsetPath\n} from \"@nesvet/n\";\nimport type { Abilities, AbilitiesSchema, AbilityParamSchema } from \"insite-common\";\nimport {\n\tisAbilityObject,\n\tisAbilityParamItems,\n\tisAbilityParamNumber,\n\ttype Ability,\n\ttype AbilityObject,\n\ttype AbilityParam,\n\ttype AbilityParamItems,\n\ttype AbilityParamNumber,\n\ttype AbilitySchema,\n\ttype GenericAbilities\n} from \"./types\";\n\n\nconst schemaParentMap = new Map<AbilitySchema, AbilitySchema | null>();\n\n\nexport class AbilitiesMap<AS extends AbilitiesSchema> extends Map<string, AbilitySchema> {\n\tconstructor(abilitiesSchema: AS) {\n\t\tsuper();\n\t\t\n\t\tfor (const subSchema of abilitiesSchema) {\n\t\t\tdelete subSchema.top;/* The first level is always top */\n\t\t\t\n\t\t\tthis.#hierarchical.push(subSchema as AbilitySchema);\n\t\t}\n\t\t\n\t\t(function parse(this: AbilitiesMap<AS>, schemas: AbilitiesSchema, parent: AbilitySchema | null, level: number) {\n\t\t\tfor (const schema of schemas as AbilitySchema[]) {\n\t\t\t\tschemaParentMap.set(schema, parent);\n\t\t\t\t\n\t\t\t\tschema.level = level;\n\t\t\t\t\n\t\t\t\tif (!parent || schema.top) {\n\t\t\t\t\tschema.longId = schema._id;\n\t\t\t\t\t\n\t\t\t\t\tif (this.has(schema._id))\n\t\t\t\t\t\tthrow new Error(`Top-level ability duplicate: ${schema._id}`);\n\t\t\t\t\t\n\t\t\t\t\tthis.set(schema._id, schema);\n\t\t\t\t} else\n\t\t\t\t\tschema.longId = parent ? `${parent.longId}.${schema._id}` : schema._id;\n\t\t\t\t\n\t\t\t\tif (schema.abilities)\n\t\t\t\t\tparse.call(this, schema.abilities, schema, level + 1);\n\t\t\t}\n\t\t\t\n\t\t}).call(this, abilitiesSchema, null, 0);\n\t\t\n\t}\n\t\n\t#hierarchical: AbilitySchema[] = [];\n\t\n\tget(longId: string, parent?: AbilitySchema | null) {\n\t\tconst subIds = longId.split(\".\");\n\t\tlet schema = parent ?? super.get(subIds.shift()!);\n\t\t\n\t\tif (schema && subIds.length)\n\t\t\tfor (const subId of subIds) {\n\t\t\t\tschema = schema?.abilities?.find(({ _id, top }) => !top && _id === subId);\n\t\t\t\tif (!schema)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\n\t\treturn schema;\n\t}\n\t\n\tgetSchema = this.get;\n\t\n\tgetParamSchema(longId: string, paramId: string) {\n\t\treturn this.get(longId)?.params?.find(({ _id }) => _id === paramId);\n\t}\n\t\n\tgetDefaultParam(longId: string, paramId: string, max?: boolean): AbilityParam | undefined;\n\tgetDefaultParam(schema: AbilityParamSchema, max?: boolean): AbilityParam;\n\tgetDefaultParam(schemaOrLongId: AbilityParamSchema | string, paramIdOrMax?: boolean | string, max?: boolean) {\n\t\tif (paramIdOrMax === undefined || typeof paramIdOrMax == \"boolean\")\n\t\t\tmax = paramIdOrMax;\n\t\t\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.getParamSchema(schemaOrLongId, paramIdOrMax as string) : schemaOrLongId;\n\t\t\n\t\tif (schema)\n\t\t\tswitch (schema.type) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn max ?\n\t\t\t\t\t\t(schema.max ?? Infinity) :\n\t\t\t\t\t\t(schema.min ?? 0);\n\t\t\t\t\n\t\t\t\tcase \"items\":\n\t\t\t\t\treturn max ?\n\t\t\t\t\t\tschema.items.map(({ _id }) => _id) :\n\t\t\t\t\t\t[];\n\t\t\t}\n\t\t\n\t\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n\t}\n\t\n\tgetDefaultAbility(schema: string, max?: boolean): Ability | undefined;\n\tgetDefaultAbility(schema: AbilitySchema, max?: boolean): Ability;\n\tgetDefaultAbility(schema: AbilitySchema | string, max: boolean = !schema): Ability | undefined {\n\t\tif (typeof schema == \"string\")\n\t\t\tschema = this.get(schema)!;\n\t\t\n\t\tif (schema) {\n\t\t\tif (schema.abilities || schema.params) {\n\t\t\t\tconst ability = {} as AbilityObject;\n\t\t\t\t\n\t\t\t\tif (schema.params)\n\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\tability[paramSchema._id] = this.getDefaultParam(paramSchema, max);\n\t\t\t\t\n\t\t\t\tif (max && schema.abilities)\n\t\t\t\t\tfor (const subSchema of schema.abilities)\n\t\t\t\t\t\tif (!subSchema.top)\n\t\t\t\t\t\t\tability[subSchema._id] = this.getDefaultAbility(subSchema, max);\n\t\t\t\t\n\t\t\t\treturn ability;\n\t\t\t}\n\t\t\t\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn undefined;\n\t}\n\t\n\tgetDefaultAbilities(): Abilities<AS>;\n\tgetDefaultAbilities(schemas: AbilitySchema[], max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(schema: AbilitySchema, max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(longIds: string[], max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(longId: string, max?: boolean): Abilities<AS>;\n\tgetDefaultAbilities(schemasOrIds?: (AbilitySchema | string)[] | AbilitySchema | string, max: boolean = !schemasOrIds) {\n\t\t\n\t\tconst schemas = (\n\t\t\tschemasOrIds ?\n\t\t\t\t(Array.isArray(schemasOrIds) ? schemasOrIds : [ schemasOrIds ])\n\t\t\t\t\t.map(schema => (typeof schema == \"string\" ? this.get(schema) : schema))\n\t\t\t\t\t.filter(Boolean) as AbilitySchema[] :\n\t\t\t\t[ ...this.values() ]\n\t\t).sort((a, b) => a.level - b.level);\n\t\t\n\t\tconst schemaMaxMap = new Map<AbilitySchema, boolean>();\n\t\t\n\t\tfor (const schema of schemas) {\n\t\t\t(function resolve(_schema) {\n\t\t\t\tconst parentSchema = schemaParentMap.get(_schema);\n\t\t\t\t\n\t\t\t\tif (parentSchema) {\n\t\t\t\t\tresolve(parentSchema);\n\t\t\t\t\t\n\t\t\t\t\tif (!schemaMaxMap.has(parentSchema))\n\t\t\t\t\t\tschemaMaxMap.set(parentSchema, false);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t})(schema);\n\t\t\t\n\t\t\tif (max)\n\t\t\t\t(function resolve(_schema) {\n\t\t\t\t\tif (!schemaMaxMap.has(_schema))\n\t\t\t\t\t\tschemaMaxMap.set(_schema, true);\n\t\t\t\t\t\n\t\t\t\t\tif (_schema.abilities)\n\t\t\t\t\t\tfor (const subSchema of _schema.abilities)\n\t\t\t\t\t\t\tif (subSchema.top)\n\t\t\t\t\t\t\t\tresolve(subSchema);\n\t\t\t\t\t\n\t\t\t\t})(schema);\n\t\t\telse\n\t\t\t\tif (!schemaMaxMap.has(schema))\n\t\t\t\t\tschemaMaxMap.set(schema, false);\n\t\t}\n\t\t\n\t\treturn assignPath(\n\t\t\t{},\n\t\t\tObject.fromEntries(\n\t\t\t\t[ ...schemaMaxMap ]\n\t\t\t\t\t.map(([ schema, _max ]) => [ schema.longId, this.getDefaultAbility(schema, _max) ])\n\t\t\t)\n\t\t);\n\t}\n\t\n\tgetSchemeFor(abilities: GenericAbilities) {\n\t\tabilities = this.adjust(structuredClone(abilities));\n\t\t\n\t\treturn (function resolve(subSchemas: AbilitySchema[], subAbilities: GenericAbilities) {\n\t\t\tfor (let i = 0; i < subSchemas.length; i++) {\n\t\t\t\tconst schema = subSchemas[i];\n\t\t\t\tconst ability = schema.top ? abilities[schema._id] : subAbilities[schema._id];\n\t\t\t\t\n\t\t\t\tif (ability) {\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tfor (const paramSchema of schema.params) {\n\t\t\t\t\t\t\tconst abilityParam = (ability as AbilityObject)[paramSchema._id];\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\t\t\tparamSchema.max = abilityParam as AbilityParamNumber;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\t\t\t\tparamSchema.items = paramSchema.items.filter(({ _id }) => (abilityParam as AbilityParamItems).includes(_id));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities) {\n\t\t\t\t\t\tresolve(schema.abilities, ability as GenericAbilities);\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (!schema.abilities.length)\n\t\t\t\t\t\t\tdelete schema.abilities;\n\t\t\t\t\t}\n\t\t\t\t} else\n\t\t\t\t\tsubSchemas.splice(i--, 1);\n\t\t\t}\n\t\t\t\n\t\t\treturn subSchemas;\n\t\t})(structuredClone(this.#hierarchical), abilities);\n\t}\n\t\n\tgetParam(abilities: GenericAbilities, longId: string, paramId: string) {\n\t\tif (this.getParamSchema(longId, paramId)) {\n\t\t\tconst value = getPath(abilities, `${longId}.${paramId}`) as AbilityParam;\n\t\t\t\n\t\t\tif (this.isParamFits(longId, paramId, value))\n\t\t\t\treturn value;\n\t\t\t\n\t\t\treturn this.getDefaultParam(longId, paramId)!;\n\t\t}\n\t\t\n\t\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n\t}\n\t\n\tsetParam(abilities: GenericAbilities, longId: string, paramId: string, value: AbilityParam): Abilities<AS> {\n\t\tconst schema = this.getParamSchema(longId, paramId);\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability param: ${longId}.${paramId}`);\n\t\t\n\t\tsetPath(abilities, `${longId}.${paramId}`, this.adjustParam(schema, value));\n\t\t\n\t\treturn abilities as Abilities<AS>;\n\t}\n\t\n\tisParamFits(longId: string, paramId: string, value: AbilityParam, referenceValue?: AbilityParam) {\n\t\tif (value !== undefined) {\n\t\t\tconst paramSchema = this.getParamSchema(longId, paramId);\n\t\t\t\n\t\t\tif (paramSchema)\n\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tisAbilityParamNumber(value) &&\n\t\t\t\t\t\t\t(paramSchema.min === undefined || value >= paramSchema.min) && (\n\t\t\t\t\t\t\t\treferenceValue === undefined ?\n\t\t\t\t\t\t\t\t\t(paramSchema.max === undefined || value <= paramSchema.max) :\n\t\t\t\t\t\t\t\t\tvalue <= (referenceValue as AbilityParamNumber)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\n\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tisAbilityParamItems(value) &&\n\t\t\t\t\t\t\tvalue.length === new Set(value).size && (\n\t\t\t\t\t\t\t\treferenceValue === undefined ?\n\t\t\t\t\t\t\t\t\tvalue.every(itemId => paramSchema.items.find(({ _id }) => _id === itemId)) :\n\t\t\t\t\t\t\t\t\tvalue.every(itemId => (referenceValue as AbilityParamItems).includes(itemId))\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t}\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n\t\n\tadjustParam(paramSchema: AbilityParamSchema, value: AbilityParam) {\n\t\tswitch (paramSchema.type) {\n\t\t\tcase \"number\":\n\t\t\t\treturn (\n\t\t\t\t\tisAbilityParamNumber(value) ?\n\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\tMath.min(\n\t\t\t\t\t\t\t\tvalue,\n\t\t\t\t\t\t\t\tparamSchema.max ?? Infinity\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tparamSchema.min ?? 0\n\t\t\t\t\t\t) :\n\t\t\t\t\t\tparamSchema.min ?? 0\n\t\t\t\t);\n\t\t\t\n\t\t\tdefault/* paramSchema.type === \"items\" */:\n\t\t\t\treturn (\n\t\t\t\t\tisAbilityParamItems(value) ?\n\t\t\t\t\t\tintersection(paramSchema.items.map(item => item._id), value) :\n\t\t\t\t\t\t[]\n\t\t\t\t) as AbilityParamItems;\n\t\t}\n\t\t\n\t}\n\t\n\tadjust(abilities: GenericAbilities, parent?: AbilitySchema | null): Abilities<AS> {\n\t\tconst adjustedAbilities: GenericAbilities = {};\n\t\t\n\t\tfor (const [ _id, ability ] of Object.entries(abilities)) {\n\t\t\tconst schema = this.get(_id, parent);\n\t\t\t\n\t\t\tif (schema)\n\t\t\t\tif (schema.params || schema.abilities) {\n\t\t\t\t\tconst adjustedAbility: AbilityObject = {};\n\t\t\t\t\t\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tif (isAbilityObject(ability))\n\t\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\t\tadjustedAbility[paramSchema._id] = this.adjustParam(paramSchema, ability[paramSchema._id] as AbilityParam);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\t\tadjustedAbility[paramSchema._id] = this.getDefaultParam(paramSchema);\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities && isAbilityObject(ability))\n\t\t\t\t\t\tObject.assign(\n\t\t\t\t\t\t\tadjustedAbility,\n\t\t\t\t\t\t\tthis.adjust(\n\t\t\t\t\t\t\t\tpick(\n\t\t\t\t\t\t\t\t\tability,\n\t\t\t\t\t\t\t\t\tschema.abilities\n\t\t\t\t\t\t\t\t\t\t.filter(subSchema => !subSchema.top)\n\t\t\t\t\t\t\t\t\t\t.map(subSchema => subSchema._id)\n\t\t\t\t\t\t\t\t) as GenericAbilities,\n\t\t\t\t\t\t\t\tschema\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\n\t\t\t\t\tadjustedAbilities[_id] = adjustedAbility;\n\t\t\t\t} else\n\t\t\t\t\tadjustedAbilities[_id] = true;\n\t\t}\n\t\t\n\t\treturn Object.assign(empty(abilities), adjustedAbilities) as Abilities<AS>;\n\t}\n\t\n\tmerge(target: GenericAbilities, source: GenericAbilities, parent?: AbilitySchema | null): Abilities<AS> {\n\t\tif (!parent) {\n\t\t\tthis.adjust(target);\n\t\t\tsource = this.adjust(structuredClone(source));\n\t\t}\n\t\t\n\t\tfor (const [ _id, ability ] of Object.entries(source)) {\n\t\t\tconst schema = this.get(_id, parent);\n\t\t\t\n\t\t\tif (schema && schema.isInheritable !== false)\n\t\t\t\tif (_id in target && (schema.params || schema.abilities)) {\n\t\t\t\t\tconst targetAbility = target[_id] as AbilityObject;\n\t\t\t\t\tconst sourceAbility = ability as AbilityObject;\n\t\t\t\t\t\n\t\t\t\t\tif (schema.params)\n\t\t\t\t\t\tfor (const paramSchema of schema.params)\n\t\t\t\t\t\t\tif (paramSchema.isInheritable !== false)\n\t\t\t\t\t\t\t\tswitch (paramSchema.type) {\n\t\t\t\t\t\t\t\t\tcase \"number\":\n\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] =\n\t\t\t\t\t\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] as AbilityParamNumber,\n\t\t\t\t\t\t\t\t\t\t\t\tsourceAbility[paramSchema._id] as AbilityParamNumber\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tcase \"items\":\n\t\t\t\t\t\t\t\t\t\tadd(\n\t\t\t\t\t\t\t\t\t\t\ttargetAbility[paramSchema._id] as AbilityParamItems,\n\t\t\t\t\t\t\t\t\t\t\t...sourceAbility[paramSchema._id] as AbilityParamItems\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (schema.abilities)\n\t\t\t\t\t\tthis.merge(targetAbility as GenericAbilities, sourceAbility as GenericAbilities, schema);\n\t\t\t\t} else\n\t\t\t\t\ttarget[_id] = ability;\n\t\t}\n\t\t\n\t\treturn target as Abilities<AS>;\n\t}\n\t\n\thasAbility(abilities: GenericAbilities, longId: string) {\n\t\treturn Boolean(getPath(abilities, longId));\n\t}\n\t\n\tsetAbility(target: GenericAbilities, schema: AbilitySchema): Abilities<AS>;\n\tsetAbility(target: GenericAbilities, longId: string): Abilities<AS>;\n\tsetAbility(target: GenericAbilities, schemaOrLongId: AbilitySchema | string) {\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.get(schemaOrLongId) : schemaOrLongId;\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability: ${schemaOrLongId as string}`);\n\t\t\n\t\tthis.merge(target, this.getDefaultAbilities(schema));\n\t\t\n\t\treturn target as Abilities<AS>;\n\t}\n\t\n\tunsetAbility(target: GenericAbilities, schema: AbilitySchema): Abilities<AS>;\n\tunsetAbility(target: GenericAbilities, longId: string): Abilities<AS>;\n\tunsetAbility(target: GenericAbilities, schemaOrLongId: AbilitySchema | string) {\n\t\tconst schema = typeof schemaOrLongId == \"string\" ? this.get(schemaOrLongId) : schemaOrLongId;\n\t\t\n\t\tif (!schema)\n\t\t\tthrow new Error(`No such ability: ${schemaOrLongId as string}`);\n\t\t\n\t\t(function resolve(_schema) {\n\t\t\tdeletePath(target, _schema.longId);\n\t\t\t\n\t\t\tif (_schema.abilities)\n\t\t\t\tfor (const subSchema of _schema.abilities)\n\t\t\t\t\tresolve(subSchema);\n\t\t\t\n\t\t})(schema);\n\t\t\n\t\treturn target;\n\t}\n\t\n}\n", "import type { Prettify } from \"@nesvet/n\";\nimport type { AbilitySchema as OriginalAbilitySchema } from \"insite-common\";\n\n\ntype AbilityParamItem = string;\nexport type AbilityParamItems = AbilityParamItem[];\nexport type AbilityParamNumber = number;\nexport type AbilityParam = AbilityParamItems | AbilityParamNumber;\n\nexport type AbilityWithParams = Record<string, AbilityParam>;\nexport type AbilityObject = Record<string, Ability | AbilityParam>;\nexport type AbilityBoolean = true;\nexport type Ability = AbilityBoolean | { [key: string]: Ability | AbilityParam };\n\nexport type AbilitySchema = Prettify<\n\tOmit<OriginalAbilitySchema, \"abilities\"> & {\n\t\tlevel: number;\n\t\tlongId: string;\n\t\tabilities?: AbilitySchema[];\n\t}\n>;\n\nexport type GenericAbilities = Record<string, Ability>;\n\nexport function isAbilityObject(value: Ability): value is AbilityObject {\n\treturn typeof value == \"object\";\n}\n\nexport function isAbilityParamNumber(value: AbilityParam): value is AbilityParamNumber {\n\treturn typeof value == \"number\";\n}\n\nexport function isAbilityParamItems(value: AbilityParam): value is AbilityParamItems {\n\treturn Array.isArray(value);\n}\n", "import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class RolesError extends Err {\n\tconstructor(roleId: string, payload?: Payload);\n\tconstructor(roleIds: string[], payload?: Payload);\n\tconstructor(stringOrArray: Payload | string[] | string, payload?: Payload) {\n\t\tsuper(`User lacks role${Array.isArray(stringOrArray) ? \"s\" : \"\"}`, \"lacksroles\", {\n\t\t\troles: Array.isArray(stringOrArray) ? stringOrArray : [ stringOrArray ],\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"RolesError\";\n\t\n}\n", "import {\n\tdeleteProps,\n\tgetAll,\n\tintersection,\n\treAdd,\n\tremoveAll\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport type { ChangeStreamDocument, CollectionIndexes, WatchedCollection } from \"insite-db\";\nimport type { AbilityParam, GenericAbilities } from \"../abilities/types\";\nimport type { Users } from \"../users\";\nimport { Role } from \"./Role\";\nimport { basisSchema } from \"./schema\";\nimport type { NewRole, RoleDoc, RolesOptions } from \"./types\";\n\n\nconst indexes: CollectionIndexes = [\n\t[ { involves: 1 } ]\n];\n\nfunction preventDirectDelete() {\n\tthrow new Error(\"Direct usage of roles collection.deleteOne or .deleteMany is forbidden. Use roles.deleteRole instead.\");\n}\n\n\nexport class Roles<AS extends AbilitiesSchema> extends Map<string, Role<AS>> {\n\tconstructor(users: Users<AS>, options: RolesOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tconst {\n\t\t\troot: rootProps,\n\t\t\t...initOptions\n\t\t} = options;\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\tthis.abilities = users.abilities;\n\t\t\n\t\tthis.root = new Role<AS>(this, {\n\t\t\t...rootProps,\n\t\t\t_id: \"root\",\n\t\t\tinvolves: [],\n\t\t\tabilities: this.abilities.getDefaultAbilities(),\n\t\t\ttitle: \"Root\",\n\t\t\tdescription: \"Root\",\n\t\t\tmeta: {},\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\tthis.initOptions = initOptions;\n\t\t\n\t}\n\t\n\tusers;\n\tcollections;\n\tcollection!: WatchedCollection<RoleDoc> & {\n\t\t/** @deprecated Direct usage of roles collection.deleteOne is forbidden. Use roles.deleteRole instead. */\n\t\tdeleteOne: typeof preventDirectDelete;\n\t\t\n\t\t/** @deprecated Direct usage of roles collection.deleteMany is forbidden. Use roles.deleteRole instead. */\n\t\tdeleteMany: typeof preventDirectDelete;\n\t};\n\t\n\tabilities;\n\troot;\n\tprivate initOptions?;\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<RoleDoc>(\"roles\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\tdeleteOne: preventDirectDelete,\n\t\t\t\t\tdeleteMany: preventDirectDelete\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const roleDoc of this.collection.find()) {\n\t\t\t\tif (this.abilities.adjust(roleDoc.abilities))\n\t\t\t\t\tawait this.collection.updateOne({ _id: roleDoc._id }, { $set: { abilities: roleDoc.abilities } });\n\t\t\t\t\n\t\t\t\tthis.load(roleDoc);\n\t\t\t}\n\t\t\t\n\t\t\tthis.update();\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<RoleDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\": {\n\t\t\t\tnew Role<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tload(roleDoc: RoleDoc) {\n\t\tnew Role<AS>(this, roleDoc);\n\t\t\n\t}\n\t\n\tresolve(role: Role<AS>, involvedBy: Role<AS>[]) {\n\t\tinvolvedBy = [ role, ...involvedBy ];\n\t\t\n\t\tfor (const involvedRoleId of role.ownInvolveIds) {\n\t\t\tconst involvedRole = this.get(involvedRoleId);\n\t\t\tif (involvedRole) {\n\t\t\t\tfor (const involvedByRole of involvedBy) {\n\t\t\t\t\treAdd(involvedByRole.involves, involvedRole);\n\t\t\t\t\tthis.abilities.merge(involvedByRole.inheritedAbilities as GenericAbilities, involvedRole.abilities as GenericAbilities);\n\t\t\t\t}\n\t\t\t\tif (involvedRole !== role)\n\t\t\t\t\tthis.resolve(involvedRole, involvedBy);\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tsorted: Role<AS>[] = [];\n\t\n\t#sortRoles(a: Role<AS>, b: Role<AS>) {\n\t\treturn (\n\t\t\t(b.involves.size - a.involves.size) || (\n\t\t\t\t(a.title && b.title) ?\n\t\t\t\t\ta.title > b.title ? 1 : a.title < b.title ? -1 : 0 :\n\t\t\t\t\ta.title ?\n\t\t\t\t\t\t-1 :\n\t\t\t\t\t\tb.title ?\n\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\ta._id > b._id ?\n\t\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\t\ta._id < b._id ?\n\t\t\t\t\t\t\t\t\t-1 :\n\t\t\t\t\t\t\t\t\t0\n\t\t\t)\n\t\t);\n\t}\n\t\n\tupdate() {\n\t\t\n\t\tconst array = [ ...this.values() ];\n\t\t\n\t\tthis.root.ownInvolveIds = [];\n\t\tfor (const role of array) {\n\t\t\tif (role !== this.root && !array.some(anotherRole => anotherRole.ownInvolveIds.includes(role._id)))\n\t\t\t\tthis.root.ownInvolveIds.push(role._id);\n\t\t\trole.involves.clear();\n\t\t\trole.abilities = structuredClone(role.ownAbilities);\n\t\t\trole.inheritedAbilities = {};\n\t\t}\n\t\t\n\t\tthis.root.involves.add(this.root);\n\t\tthis.resolve(this.root, []);\n\t\t\n\t\tfor (const role of array)\n\t\t\trole.ownInvolves = getAll(this, role.ownInvolveIds, true).sort(this.#sortRoles).reverse();\n\t\t\n\t\tconst sorted = [ this.root ];\n\t\t\n\t\tfor (let i = 0; i < sorted.length; i++) {\n\t\t\tconst role = sorted[i];\n\t\t\tfor (const involvedRole of role.ownInvolves) {\n\t\t\t\tconst involvedRoleIndex = sorted.indexOf(involvedRole);\n\t\t\t\tif (~involvedRoleIndex) {\n\t\t\t\t\tsorted.splice(involvedRoleIndex, 1);\n\t\t\t\t\ti--;\n\t\t\t\t}\n\t\t\t\tsorted.splice(i + 1, 0, involvedRole);\n\t\t\t}\n\t\t}\n\t\t\n\t\tlet _o = 0;\n\t\tfor (const role of sorted) {\n\t\t\tthis.abilities.merge(role.abilities as GenericAbilities, role.inheritedAbilities as GenericAbilities);\n\t\t\trole._o = _o++;\n\t\t}\n\t\t\n\t\tthis.sorted = sorted;\n\t\t\n\t\tif (this.users.isInited)\n\t\t\tthis.users.update(true);\n\t\t\n\t}\n\t\n\tasync create({ _id, involves, title, description, ...restProps }: NewRole) {\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\tinvolves: involves || [],\n\t\t\tabilities: {},\n\t\t\ttitle: title ?? \"\",\n\t\t\tdescription: description ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"abilities\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateRole(roleId: string, updates: Omit<RoleDoc, \"abilities\" | \"createdAt\">) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.involves) {\n\t\t\tremoveAll(updates.involves, [ roleId ]);\n\t\t\t\n\t\t\tfor (const involvedRoleId of updates.involves)\n\t\t\t\tif (this.get(involvedRoleId)?.involves.has(role))\n\t\t\t\t\tremoveAll(updates.involves, [ involvedRoleId ]);\n\t\t\t\n\t\t\tupdates.involves = this.cleanUpIds(updates.involves);\n\t\t}\n\t\t\n\t\tconst { abilities } = updates as unknown as { abilities?: GenericAbilities };\n\t\t\n\t\tif (abilities && typeof abilities == \"object\")\n\t\t\t(updates as unknown as { abilities: GenericAbilities }).abilities = this.abilities.adjust(abilities);\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: updates });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tdeleteRole(role: Role<AS> | string) {\n\t\tconst _id = typeof role == \"string\" ? role : role._id;\n\t\t\n\t\treturn this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { involves: _id }, update: { $pullAll: { involves: [ _id ] } } } },\n\t\t\t{ deleteOne: { filter: { _id } } }\n\t\t]);\n\t}\n\t\n\tcleanUpIds(ids: string[]) {\n\t\tconst roles = intersection(this.sorted, getAll(this, ids, true));\n\t\t\n\t\tconst cleanedUpIds = [];\n\t\t\n\t\tfor (const role of roles)\n\t\t\tif (roles.every(anotherRole => anotherRole === role || !anotherRole.involves.has(role)))\n\t\t\t\tcleanedUpIds.push(role._id);\n\t\t\n\t\treturn cleanedUpIds;\n\t}\n\t\n\tasync setAbility(roleId: string, abilityLongId: string, set: boolean) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: {\n\t\t\tabilities:\n\t\t\t\tset ?\n\t\t\t\t\tthis.abilities.setAbility(role.ownAbilities, abilityLongId) :\n\t\t\t\t\tthis.abilities.unsetAbility(role.ownAbilities, abilityLongId)\n\t\t} });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tasync setAbilityParam(roleId: string, abilityLongId: string, paramId: string, value: AbilityParam) {\n\t\tconst role = this.get(roleId);\n\t\t\n\t\tif (!role)\n\t\t\treturn false;\n\t\t\n\t\tawait this.collection.updateOne({ _id: roleId }, { $set: {\n\t\t\tabilities: this.abilities.setParam(role.ownAbilities, abilityLongId, paramId, value)\n\t\t} });\n\t\t\n\t\treturn true;\n\t}\n\t\n}\n", "import type { Abilities, AbilitiesSchema } from \"insite-common\";\nimport { Roles } from \"./Roles\";\nimport { RoleDoc } from \"./types\";\n\n\nconst snapshots = new WeakMap();\n\n\nexport class Role<AS extends AbilitiesSchema> {\n\tconstructor(roles: Roles<AS>, roleDoc: RoleDoc) {\n\t\tthis.#roles = roles;\n\t\t\n\t\tthis._id = roleDoc._id;\n\t\troles.set(this._id, this);\n\t\t\n\t\tvoid this.update(roleDoc);\n\t\t\n\t}\n\t\n\t#roles;\n\t\n\t_id;\n\townInvolveIds!: string[];\n\townAbilities!: Abilities<AS>;\n\ttitle = \"\";\n\tdisplayTitle = \"\";\n\t_o = 0;\n\t\n\townInvolves: Role<AS>[] = [];\n\tinvolves = new Set<Role<AS>>();\n\tabilities: Abilities<AS> = {};\n\tinheritedAbilities: Abilities<AS> = {};\n\t\n\tupdate({ _id, involves: ownInvolveIds, abilities: ownAbilities, title, ...restProps }: Partial<RoleDoc>) {\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tif (ownInvolveIds)\n\t\t\tthis.ownInvolveIds = ownInvolveIds;\n\t\t\n\t\tif (ownAbilities)\n\t\t\tthis.ownAbilities = typeof ownAbilities == \"object\" ?\n\t\t\t\tthis.#roles.abilities.adjust(ownAbilities) :\n\t\t\t\townAbilities as Abilities<AS>;\n\t\t\n\t\tif (title !== undefined) {\n\t\t\tthis.title = title;\n\t\t\tthis.displayTitle = title || this._id;\n\t\t}\n\t\t\n\t\tif (ownInvolveIds || ownAbilities) {\n\t\t\tconst snapshot = [\n\t\t\t\tthis.ownInvolveIds.join(\",\"),\n\t\t\t\tJSON.stringify(this.ownAbilities)\n\t\t\t].join(\"\\n\");\n\t\t\t\n\t\t\tif (snapshot !== snapshots.get(this)) {\n\t\t\t\tsnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.#roles.users.isInited)\n\t\t\t\t\tthis.#roles.update();\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tdelete() {\n\t\t\n\t\tthis.#roles.delete(this._id);\n\t\t\n\t\tsnapshots.delete(this);\n\t\t\n\t\tthis.#roles.update();\n\t\t\n\t}\n\t\n}\n", "export const regexps = {\n\t_id: /^[\\dA-Fa-f]{24}$/,\n\temail: /^[^\\s@]{1,63}@[^\\s@]{1,63}\\.[^\\s@]{1,63}$/,\n\targon2: /^\\$argon2(?:i|d|id)\\$v=\\d+\\$m=\\d+,t=\\d+,p=\\d+(?:\\$[\\d+/A-Za-z]+){2}$/,\n\t// eslint-disable-next-line unicorn/better-regex\n\tsessionId: /^(?:[\\dA-Fa-f]{16,32}\\$[\\dA-Fa-f]{16,32}|[0-9a-f]{24}~[A-Za-z0-9_-]{43})$/, // (?:old_format|new_format) - leave just the new after some time\n\trole: /^[\\d_a-z-]{1,64}$/,\n\tip: /^(?:(?:\\d{1,3}\\.){3}\\d{1,3}|(?:[\\dA-Fa-f]{0,4}:){2,7}[\\dA-Fa-f]{0,4})$/\n};\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"involves\",\n\t\t\"abilities\",\n\t\t\"title\",\n\t\t\"description\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.role.source,\n\t\t\tnot: { enum: [ \"root\" ] }\n\t\t},\n\t\tinvolves: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps.role.source,\n\t\t\t\tnot: { enum: [ \"root\" ] }\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tabilities: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\ttitle: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 256\n\t\t},\n\t\tdescription: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 10240\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { Err } from \"@nesvet/n\";\n\n\ntype Payload = Record<string, unknown>;\n\n\nexport class UnauthorizedError extends Err {\n\tconstructor(payload?: Payload) {\n\t\tsuper(\"Unauthorized\", \"unauthorized\", payload);\n\t\t\n\t}\n\t\n\tname = \"UnauthorizedError\";\n\t\n}\n\n\ntype SubordinationType = \"_id\" | \"permissiveIds\" | \"slaveIds\";\n\nexport class SubordinationError extends Err {\n\tconstructor(payload?: Payload);\n\tconstructor(type: SubordinationType, payload?: Payload);\n\tconstructor(type: SubordinationType, ids: string[] | string, payload?: Payload);\n\tconstructor(type?: Payload | SubordinationType, ids?: Payload | string[] | string, payload?: Payload) {\n\t\tswitch (arguments.length) {\n\t\t\tcase 1:\n\t\t\t\tpayload = type as Payload;\n\t\t\t\ttype = undefined;\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase 2:\n\t\t\t\tpayload = ids as Payload;\n\t\t\t\tids = undefined;\n\t\t}\n\t\t\n\t\tsuper(\"Insubordination attempt\", \"subordination\", {\n\t\t\t...type && { type },\n\t\t\t...ids && { ids: Array.isArray(ids) ? ids : [ ids ] },\n\t\t\t...payload\n\t\t});\n\t\t\n\t}\n\t\n\tname = \"SubordinationError\";\n\t\n}\n\n\nexport class PermissionError extends Err {\n\tconstructor(payload?: Payload) {\n\t\tsuper(\"Insufficient permissions\", \"permissions\", payload);\n\t\t\n\t}\n\t\n\tname = \"PermissionError\";\n\t\n}\n", "import { hash, verify } from \"@node-rs/argon2\";\nimport EventEmitter from \"eventemitter3\";\nimport {\n\t_ids,\n\tdeleteProps,\n\tremoveAll,\n\tStatefulPromise,\n\twithout\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tCollections,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport { AbilitiesMap } from \"../abilities\";\nimport { regexps } from \"../lib\";\nimport { Orgs } from \"../orgs\";\nimport { Org } from \"../orgs/Org\";\nimport { Roles } from \"../roles\";\nimport { Sessions } from \"../sessions\";\nimport { Session } from \"../sessions/Session\";\nimport type { SessionDoc } from \"../sessions/types\";\nimport { Avatars } from \"./avatars\";\nimport { basisSchema } from \"./schema\";\nimport { User } from \"./User\";\nimport type { NewUser, Options, UserDoc } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nconst indexes: CollectionIndexes = [\n\t[ { email: 1 }, { unique: true } ],\n\t[ { org: 1 } ]\n];\n\nlet unknownUserPasswordHash: Promise<string> | undefined;\n\n\nexport class Users<AS extends AbilitiesSchema> extends Map<string, User<AS>> {\n\tconstructor(collections: Collections, options: Options<AS>) {\n\t\tsuper();\n\t\t\n\t\tconst eventEmitter = new EventEmitter() as EventEmitter & {\n\t\t\t_events: Record<string, object>;\n\t\t\t_eventsCount: number;\n\t\t};\n\t\tthis.#eventEmitter = eventEmitter;\n\t\tthis._events = eventEmitter._events;\n\t\tthis._eventsCount = eventEmitter._eventsCount;\n\t\tthis.emit = eventEmitter.emit;\n\t\tthis.on = eventEmitter.on as unknown as (...args: any[]) => this;\n\t\tthis.once = eventEmitter.once;\n\t\tthis.addListener = eventEmitter.addListener;\n\t\tthis.off = eventEmitter.off;\n\t\tthis.removeListener = eventEmitter.removeListener;\n\t\t\n\t\tthis.collections = collections;\n\t\t\n\t\tthis.abilities = new AbilitiesMap<AS>(options.abilities);\n\t\t\n\t\tthis.initOptions = options;\n\t\t\n\t\tvoid this.init();\n\t\t\n\t}\n\t\n\t#eventEmitter;\n\t_events;\n\t_eventsCount;\n\temit;\n\t\n\ton(event: \"user-create\" | \"user-is-online\" | \"user-permissions-change\", callback: (user: User<AS>) => void): this;\n\ton(event: \"session-delete\", callback: (session: Session<AS>) => void): this;\n\ton<T extends string | symbol>(event: T, callback: (...args: any[]) => void, context?: any) {\n\t\tthis.#eventEmitter.on(event, callback, context);\n\t\t\n\t\treturn this;\n\t}\n\t\n\tonce;\n\taddListener;\n\toff;\n\tremoveListener;\n\t\n\tprivate initOptions?;\n\t\n\tcollections;\n\tabilities;\n\t\n\tcollection!: WatchedCollection<UserDoc>;\n\troles!: Roles<AS>;\n\tsessions!: Sessions<AS>;\n\torgs!: Orgs<AS>;\n\tavatars!: Avatars;\n\t\n\tbyEmail = new Map();\n\tbySessionId = new Map();\n\tsorted: User<AS>[] = [];\n\t\n\tisSortRequired = true;\n\t\n\t#isPreinited = false;\n\t\n\tasync preinit() {\n\t\t\n\t\tif (!this.#isPreinited) {\n\t\t\tthis.#isPreinited = true;\n\t\t\t\n\t\t\tconst {\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tschema: customSchema,\n\t\t\t\tinitialRoot: initialRootProps,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string [], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = await this.collections.ensure<UserDoc>(\"users\", { ...collectionOptions, schema });\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tif (!await this.collection.countDocuments({ roles: \"root\" }))\n\t\t\t\tawait this.create({\n\t\t\t\t\temail: process.env.INSITE_ROOT_EMAIL ?? \"insite@root.email\",\n\t\t\t\t\tpassword: process.env.INSITE_ROOT_PASSWORD ?? \"inSiteRootPassword\",\n\t\t\t\t\tname: { first: \"Root\" },\n\t\t\t\t\tjob: \"Root\",\n\t\t\t\t\t...initialRootProps,\n\t\t\t\t\troles: [ \"root\" ],\n\t\t\t\t\torg: null,\n\t\t\t\t\tmeta: {}\n\t\t\t\t});\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const userDoc of this.collection.find())\n\t\t\t\tthis.load(userDoc);\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tisInited = false;\n\t\n\tprotected async init() {\n\t\t\n\t\tif (!this.isInited) {\n\t\t\tconst {\n\t\t\t\troles: rolesOptions,\n\t\t\t\torgs: orgsOptions,\n\t\t\t\tsessions: sessionsOptions,\n\t\t\t\tavatars: avatarsOptions,\n\t\t\t\tcollection: { quiet } = {}\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tthis.roles = new Roles<AS>(this, { ...rolesOptions, collection: { quiet, ...rolesOptions?.collection } });\n\t\t\tthis.orgs = new Orgs<AS>(this, { ...orgsOptions, collection: { quiet, ...orgsOptions?.collection } });\n\t\t\tthis.sessions = new Sessions<AS>(this, { ...sessionsOptions, collection: { quiet, ...sessionsOptions?.collection } });\n\t\t\tthis.avatars = new Avatars(this, { ...avatarsOptions, collection: { quiet, ...avatarsOptions?.collection } });\n\t\t\t\n\t\t\tawait this.roles.init();\n\t\t\tawait this.orgs.preinit();\n\t\t\tawait this.preinit();\n\t\t\tthis.orgs.init();\n\t\t\tawait this.avatars.init();\n\t\t\t\n\t\t\tthis.update(true);\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tawait this.sessions.init();\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t\t\n\t\t\tthis.isInited = true;\n\t\t\t\n\t\t\tthis.#initPromise.resolve(this);\n\t\t}\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<UserDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\":\n\t\t\t\tnew User<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\t\n\tload(userDoc: UserDoc) {\n\t\tnew User<AS>(this, userDoc);\n\t\t\n\t}\n\t\n\tsort() {\n\t\t\n\t\tthis.isSortRequired = false;\n\t\t\n\t\tthis.sorted = [ ...this.values() ].sort((a, b) => a.name.last > b.name.last ? 1 : a.name.last < b.name.last ? -1 : 0);\n\t\t\n\t}\n\t\n\tupdate(shouldUpdateRoles?: boolean) {\n\t\tif (shouldUpdateRoles)\n\t\t\tfor (const user of this.values())\n\t\t\t\tuser.updateRoles();\n\t\t\n\t\tfor (const user of this.values())\n\t\t\tuser.updatePermissions();\n\t\t\n\t\tif (this.isSortRequired)\n\t\t\tthis.sort();\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\tasync create({ email, password, roles, name, org, job, ...restProps }: NewUser) {\n\t\tif (this.byEmail.has(email))\n\t\t\tthrow new Error(\"User exists\");\n\t\t\n\t\tconst _id = newObjectIdString();\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\temail,\n\t\t\tpassword: await hash(password),\n\t\t\troles: this.isInited ? this.roles.cleanUpIds(roles) : roles,\n\t\t\tname: {\n\t\t\t\tfirst: name.first ?? \"\",\n\t\t\t\tmiddle: name.middle ?? \"\",\n\t\t\t\tlast: name.last ?? \"\"\n\t\t\t},\n\t\t\torg: org ?? null,\n\t\t\tjob: job ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"_id\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateUser(_id: string, updates: Omit<UserDoc, \"_id\" | \"createdAt\">, byUser?: User<AS>) {\n\t\tconst user = this.get(_id)!;\n\t\t\n\t\tif (!user)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.roles)\n\t\t\tupdates.roles =\n\t\t\t\tuser.isRoot ?\n\t\t\t\t\t[ \"root\" ] :\n\t\t\t\t\tthis.roles.cleanUpIds(\n\t\t\t\t\t\tbyUser ?\n\t\t\t\t\t\t\twithout(user.ownRoleIds, byUser.slaveRoleIds).concat(updates.roles) :\n\t\t\t\t\t\t\tupdates.roles\n\t\t\t\t\t);\n\t\t\n\t\tlet nextPassword: string | undefined;\n\t\t\n\t\tif (updates.password !== undefined) {\n\t\t\tif (typeof updates.password != \"string\" || updates.password === \"\")\n\t\t\t\tthrow new Error(\"emptypasswordisnotallowed\");\n\t\t\t\n\t\t\tnextPassword = regexps.argon2.test(updates.password) ? updates.password : await hash(updates.password);\n\t\t\tupdates = { ...updates, password: nextPassword };\n\t\t}\n\t\t\n\t\tconst writes: Promise<unknown>[] = [\n\t\t\tthis.collection.updateOne({ _id }, { $set: updates })\n\t\t];\n\t\t\n\t\tif (nextPassword !== undefined && nextPassword !== (user as { password?: string }).password)\n\t\t\twrites.push(this.sessions.collection.deleteMany({ user: _id }));\n\t\t\n\t\tawait Promise.all(writes);\n\t\t\n\t\treturn true;\n\t}\n\t\n\tasync changePassword(_id: string, newPassword: string) {\n\t\tif (!this.has(_id))\n\t\t\tthrow new Error(\"usernotfound\");\n\t\t\n\t\tif (!newPassword)\n\t\t\tthrow new Error(\"emptypasswordisnotallowed\");\n\t\t\n\t\tawait Promise.all([\n\t\t\tthis.collection.updateOne({ _id }, { $set: { password: await hash(newPassword) } }),\n\t\t\tthis.sessions.collection.deleteMany({ user: _id })\n\t\t]);\n\t\t\n\t}\n\t\n\tasync login(email: string, password: string, sessionProps: Partial<SessionDoc>) {\n\t\tconst user = this.byEmail.get(email);\n\t\t\n\t\tif (!user) {\n\t\t\ttry {\n\t\t\t\tawait verify(await (unknownUserPasswordHash ??= hash(\"insite-unknown-user\")), password);\n\t\t\t} catch {\n\t\t\t\t// verify may reject; the response is still usernotfound\n\t\t\t}\n\t\t\t\n\t\t\tthrow new Error(\"usernotfound\");\n\t\t}\n\t\t\n\t\tif (!await verify(user.password, password))\n\t\t\tthrow new Error(\"incorrectpassword\");\n\t\t\n\t\tif (!user.abilities.login)\n\t\t\tthrow new Error(\"userisnotabletologin\");\n\t\t\n\t\treturn this.sessions.create(user, sessionProps);\n\t}\n\t\n\tlogout(session: Session<AS>) {\n\t\tsession.delete();\n\t\t\n\t\treturn this.sessions.collection.deleteOne({ _id: session._id });\n\t}\n\t\n\t#sortUsersAndOrgs(a: Org<AS> | User<AS>, b: Org<AS> | User<AS>) {\n\t\treturn (\n\t\t\t(a instanceof User && b instanceof User) ?\n\t\t\t\t(a.name.last && b.name.last) ?\n\t\t\t\t\ta.name.last > b.name.last ?\n\t\t\t\t\t\t1 :\n\t\t\t\t\t\ta.name.last < b.name.last ? -1 : 0 :\n\t\t\t\t\t(!a.name.last && !b.name.last) ?\n\t\t\t\t\t\ta.displayLabel > b.displayLabel ?\n\t\t\t\t\t\t\t1 :\n\t\t\t\t\t\t\ta.displayLabel < b.displayLabel ? -1 : 0 :\n\t\t\t\t\t\ta.name.last ? -1 : 1 :\n\t\t\t\t(a instanceof Org && b instanceof Org) ?\n\t\t\t\t\ta.title > b.title ?\n\t\t\t\t\t\t1 :\n\t\t\t\t\t\ta.title < b.title ? -1 : 0 :\n\t\t\t\t\ta instanceof Org ? -1 : 1\n\t\t);\n\t}\n\t\n\tsortIds(ids: string[]) {\n\t\treturn _ids((\n\t\t\tids\n\t\t\t\t.map(_id => this.get(_id) || this.orgs.get(_id))\n\t\t\t\t.filter(Boolean) as (Org<AS> | User<AS>)[]\n\t\t).sort(this.#sortUsersAndOrgs));\n\t}\n\t\n\treplaceMap = new Map<string, string>();\n\t\n\treplaceHandlers = new Set<(fromId: string, toId: string | null) => Promise<void> | void>();\n\t\n\tasync replace(fromId: string) {\n\t\tconst toId = this.replaceMap.get(fromId) ?? null;\n\t\tif (toId)\n\t\t\tthis.replaceMap.delete(fromId);\n\t\t\n\t\tfor (const handler of this.replaceHandlers)\n\t\t\tawait handler(fromId, toId);\n\t\t\n\t}\n\t\n\tasync deleteUser(_id: string) {\n\t\tconst { deletedCount } = await this.collection.deleteOne({ _id });\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n\t\n\tstatic init<IAS extends AbilitiesSchema>(collections: Collections, options: Options<IAS>) {\n\t\tconst users = new Users(collections, options);\n\t\t\n\t\treturn users.whenReady();\n\t}\n\t\n}\n", "import {\n\t_ids,\n\tdeleteProps,\n\tEmptyArray,\n\tEmptySet,\n\tremoveAll,\n\tsort,\n\tunion,\n\twithout\n} from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport type { User, Users } from \"../users\";\nimport { Org } from \"./Org\";\nimport { basisSchema } from \"./schema\";\nimport type { NewOrg, OrgDoc, OrgsOptions } from \"./types\";\n\n\nconst indexes: CollectionIndexes = [\n\t[ { owners: 1 } ]\n];\n\nfunction preventDirectDelete() {\n\tthrow new Error(\"Direct usage of orgs collection.deleteOne or .deleteMany is forbidden. Use orgs.deleteOrg instead.\");\n}\n\n\nexport class Orgs<AS extends AbilitiesSchema> extends Map<string, Org<AS>> {\n\tconstructor(users: Users<AS>, options: OrgsOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.preinitOptions = options;\n\t\t\n\t}\n\t\n\tusers;\n\tcollections;\n\tprivate preinitOptions?;\n\t\n\tcollection!: WatchedCollection<OrgDoc> & {\n\t\t/** @deprecated Direct usage of roles collection.deleteOne is forbidden. Use orgs.deleteOrg instead. */\n\t\tdeleteOne: typeof preventDirectDelete;\n\t\t\n\t\t/** @deprecated Direct usage of roles collection.deleteMany is forbidden. Use orgs.deleteOrg instead. */\n\t\tdeleteMany: typeof preventDirectDelete;\n\t};\n\t\n\tnull!: Org<AS> & { _id: null };\n\t\n\t#isPreinited = false;\n\t\n\tasync preinit() {\n\t\t\n\t\tif (!this.#isPreinited) {\n\t\t\tthis.#isPreinited = true;\n\t\t\t\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tnull: nullProps,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.preinitOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string [], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<OrgDoc>(\"orgs\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\tdeleteOne: preventDirectDelete,\n\t\t\t\t\tdeleteMany: preventDirectDelete\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\t// TODO: customIndexes should be moved to collectionOptions\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tthis.null = Object.assign(\n\t\t\t\tnew Org<AS>(this, {\n\t\t\t\t\t...nullProps,\n\t\t\t\t\t_id: \"\",\n\t\t\t\t\ttitle: \"\",\n\t\t\t\t\tnote: \"\",\n\t\t\t\t\towners: [],\n\t\t\t\t\tmeta: {},\n\t\t\t\t\tcreatedAt: Date.now()\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t_id: null,\n\t\t\t\t\townerIds: new EmptyArray(),\n\t\t\t\t\townerOrgs: new EmptySet(),\n\t\t\t\t\townerUsers: new EmptySet(),\n\t\t\t\t\tslaveOrgs: new EmptySet()\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const orgDoc of this.collection.find())\n\t\t\t\tthis.load(orgDoc);\n\t\t\t\n\t\t\tdelete this.preinitOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tinit() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tthis.update();\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t}\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<OrgDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\": {\n\t\t\t\tnew Org<AS>(this, next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tvoid this.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tload(orgDoc: OrgDoc) {\n\t\tnew Org<AS>(this, orgDoc);\n\t\t\n\t}\n\t\n\t#resolve(org: Org<AS>, slaveOrgs: Org<AS>[]) {\n\t\tslaveOrgs = [ org, ...slaveOrgs ];\n\t\t\n\t\tfor (const ownerOrg of org.ownerOrgs) {\n\t\t\tthis.#resolve(ownerOrg, slaveOrgs);\n\t\t\tfor (const slaveOrg of slaveOrgs)\n\t\t\t\townerOrg.slaveOrgs.add(slaveOrg);\n\t\t}\n\t\t\n\t}\n\t\n\tsorted: Org<AS>[] = [];\n\t\n\tupdate() {\n\t\t\n\t\tconst array = [ ...this.values() ];\n\t\tconst sorted = [];\n\t\t\n\t\tfor (const org of array) {\n\t\t\torg.ownerOrgs.clear();\n\t\t\torg.ownerUsers.clear();\n\t\t\torg.slaveOrgs.clear();\n\t\t\t\n\t\t\tfor (const ownerId of org.ownerIds) {\n\t\t\t\tconst ownerOrg = this.get(ownerId);\n\t\t\t\tif (ownerOrg)\n\t\t\t\t\torg.ownerOrgs.add(ownerOrg);\n\t\t\t\telse {\n\t\t\t\t\tconst ownerUser = this.users.get(ownerId);\n\t\t\t\t\tif (ownerUser)\n\t\t\t\t\t\torg.ownerUsers.add(ownerUser);\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif (!org.ownerOrgs.size && org._id)\n\t\t\t\tsorted.push(org);\n\t\t}\n\t\t\n\t\tfor (const org of array)\n\t\t\tif (!array.some(anotherOrg => anotherOrg.ownerOrgs.has(org)))\n\t\t\t\tthis.#resolve(org, []);\n\t\t\n\t\tsorted.sort(this.#sortOrgs);\n\t\tfor (const org of array)\n\t\t\tsort(org.slaveOrgs, this.#sortOrgs);\n\t\t\n\t\tfor (let i = 0; i < sorted.length; i++) {\n\t\t\tconst org = sorted[i];\n\t\t\tfor (const slaveOrg of [ ...org.slaveOrgs ].reverse())\n\t\t\t\tif (slaveOrg.ownerOrgs.has(org)) {\n\t\t\t\t\tconst slaveOrgIndex = sorted.indexOf(slaveOrg);\n\t\t\t\t\tif (~slaveOrgIndex) {\n\t\t\t\t\t\tsorted.splice(slaveOrgIndex, 1);\n\t\t\t\t\t\ti--;\n\t\t\t\t\t}\n\t\t\t\t\tsorted.splice(i + 1, 0, slaveOrg);\n\t\t\t\t}\n\t\t}\n\t\tfor (let o = 0, { length } = sorted; o < length;)\n\t\t\tsorted[o]._o = o++;\n\t\t\n\t\tthis.sorted = sorted;\n\t\t\n\t\tif (this.users.isInited)\n\t\t\tthis.users.update();\n\t\t\n\t}\n\t\n\t#sortOrgs(a: Org<AS>, b: Org<AS>) {\n\t\treturn (\n\t\t\t(b.slaveOrgs.size - a.slaveOrgs.size) || (\n\t\t\t\ta.title > b.title ?\n\t\t\t\t\t1 :\n\t\t\t\t\ta.title < b.title ?\n\t\t\t\t\t\t-1 :\n\t\t\t\t\t\t0\n\t\t\t)\n\t\t);\n\t}\n\t\n\tasync create({ title, note, ...restProps }: NewOrg) {\n\t\t\n\t\tconst _id = newObjectIdString();\n\t\t\n\t\tawait this.collection.insertOne({\n\t\t\t_id,\n\t\t\ttitle: title ?? \"\",\n\t\t\tnote: note ?? \"\",\n\t\t\tmeta: {},\n\t\t\t...deleteProps(restProps, [ \"_id\" ]),\n\t\t\tcreatedAt: Date.now()\n\t\t});\n\t\t\n\t\treturn _id;\n\t}\n\t\n\tasync updateOrg(_id: string, updates: Omit<OrgDoc, \"_id\" | \"createdAt\">, byUser?: User<AS>) {\n\t\tconst org = this.get(_id)!;\n\t\t\n\t\tif (!org)\n\t\t\treturn false;\n\t\t\n\t\tif (updates.owners)\n\t\t\tupdates.owners =\n\t\t\t\tthis.users.sortIds(\n\t\t\t\t\tunion(\n\t\t\t\t\t\tbyUser ?\n\t\t\t\t\t\t\twithout(org.ownerIds, byUser.slaveIds) :\n\t\t\t\t\t\t\t[],\n\t\t\t\t\t\twithout(updates.owners, [ _id, ..._ids(org.slaveOrgs) ])\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\n\t\tawait this.collection.updateOne({ _id }, { $set: updates });\n\t\t\n\t\treturn true;\n\t}\n\t\n\tdeleteOrg(org: Org<AS> | string) {\n\t\tconst _id = typeof org == \"string\" ? org : org._id;\n\t\t\n\t\treturn this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { owners: _id }, update: { $pullAll: { owners: [ _id ] } } } },\n\t\t\t{ deleteOne: { filter: { _id } } }\n\t\t]);\n\t}\n\t\n\treplaceMap = new Map<string, string>();\n\t\n\treplaceHandlers = new Set<(fromId: string, toId: string | null) => Promise<void> | void>();\n\t\n\tasync replace(fromId: string) {\n\t\tconst toId = this.replaceMap.get(fromId) ?? null;\n\t\tif (toId)\n\t\t\tthis.replaceMap.delete(fromId);\n\t\t\n\t\tfor (const handler of this.replaceHandlers)\n\t\t\tawait handler(fromId, toId);\n\t\t\n\t}\n\t\n}\n", "import type { AbilitiesSchema } from \"insite-common\";\nimport { User } from \"../users/User\";\nimport type { Orgs } from \"./Orgs\";\nimport type { OrgDoc } from \"./types\";\n\n\nconst snapshots = new WeakMap();\n\n\nexport class Org<AS extends AbilitiesSchema> {\n\tconstructor(orgs: Orgs<AS>, orgDoc: OrgDoc) {\n\t\tthis.orgs = orgs;\n\t\t\n\t\tthis._id = orgDoc._id;\n\t\torgs.set(this._id, this);\n\t\t\n\t\tvoid this.update(orgDoc);\n\t\t\n\t}\n\t\n\t_id;\n\ttitle = \"\";\n\tinitials = \"\";\n\tdisplayLabel = \"\";\n\t\n\t_o = 0;\n\t\n\torgs;\n\t\n\tisOrg = true;\n\t\n\townerOrgs = new Set<Org<AS>>();\n\townerUsers = new Set<User<AS>>();\n\t\n\tusers = new Set<User<AS>>();\n\t\n\tslaveOrgs = new Set<Org<AS>>();\n\t\n\townerIds: string[] = [];\n\t\n\tupdate({ _id, title, owners: ownerIds, ...restProps }: Partial<OrgDoc>) {\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tif (title !== undefined) {\n\t\t\tthis.title = title;\n\t\t\tthis.initials = title?.[0]?.toUpperCase() ?? \"\";\n\t\t\tthis.displayLabel = title;\n\t\t}\n\t\t\n\t\tif (ownerIds) {\n\t\t\tthis.ownerIds = ownerIds;\n\t\t\t\n\t\t\tconst snapshot = this.ownerIds.join(\",\");\n\t\t\t\n\t\t\tif (snapshot !== snapshots.get(this)) {\n\t\t\t\tsnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.orgs.users.isInited)\n\t\t\t\t\tthis.orgs.update();\n\t\t\t}\n\t\t}\n\t\t\n\t}\n\t\n\tasync delete() {\n\t\t\n\t\tthis.orgs.delete(this._id);\n\t\t\n\t\tsnapshots.delete(this);\n\t\t\n\t\tawait this.orgs.replace(this._id);\n\t\t\n\t\tthis.orgs.update();\n\t\t\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"title\",\n\t\t\"note\",\n\t\t\"owners\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\ttitle: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 512\n\t\t},\n\t\tnote: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 131072\n\t\t},\n\t\towners: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps._id.source\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { randomBytes } from \"node:crypto\";\nimport { deleteProps, removeAll } from \"@nesvet/n\";\nimport type { AbilitiesSchema } from \"insite-common\";\nimport {\n\tChangeStreamDocument,\n\tCollectionIndexes,\n\tnewObjectIdString,\n\tWatchedCollection\n} from \"insite-db\";\nimport { User } from \"../users/User\";\nimport type { Users } from \"../users\";\nimport { basisSchema } from \"./schema\";\nimport { Session } from \"./Session\";\nimport { SessionDoc, SessionsOptions } from \"./types\";\n\n\nconst expireAfterSeconds = 3600 * 24 * 7;\n\nconst indexes: CollectionIndexes = [\n\t[ { user: 1 } ],\n\t[ { expiresAt: 1 }, { expireAfterSeconds } ]\n];\n\n\nexport class Sessions<AS extends AbilitiesSchema> extends Map<string, Session<AS>> {\n\tconstructor(users: Users<AS>, options: SessionsOptions = {}) {\n\t\tsuper();\n\t\t\n\t\tthis.users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.initOptions = options;\n\t}\n\t\n\tusers;\n\tcollections;\n\t\n\tprivate initOptions?;\n\t\n\tcollection!: WatchedCollection<SessionDoc> & {\n\t\texpireAfterSeconds: number;\n\t};\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.users.isInited) {\n\t\t\tconst {\n\t\t\t\tschema: customSchema,\n\t\t\t\tindexes: customIndexes,\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tif (customSchema) {\n\t\t\t\tif (customSchema.required)\n\t\t\t\t\tremoveAll(customSchema.required as string[], basisSchema.required as string[]);\n\t\t\t\tif (customSchema.properties)\n\t\t\t\t\tdeleteProps(customSchema, Object.keys(basisSchema.properties!));\n\t\t\t}\n\t\t\t\n\t\t\tconst schema = {\n\t\t\t\t...basisSchema,\n\t\t\t\t...customSchema,\n\t\t\t\trequired: [ ...basisSchema.required as string[], ...customSchema?.required as string[] ?? [] ],\n\t\t\t\tproperties: { ...basisSchema.properties, ...customSchema?.properties }\n\t\t\t};\n\t\t\t\n\t\t\tthis.collection = Object.assign(\n\t\t\t\tawait this.collections.ensure<SessionDoc>(\"sessions\", { ...collectionOptions, schema }),\n\t\t\t\t{\n\t\t\t\t\texpireAfterSeconds\n\t\t\t\t}\n\t\t\t);\n\t\t\t\n\t\t\tawait this.collection.ensureIndexes([ ...indexes, ...customIndexes ?? [] ]);\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t\t\n\t\t\tfor await (const sessionDoc of this.collection.find())\n\t\t\t\tthis.load(sessionDoc);\n\t\t\t\n\t\t\tthis.collection.onChange(this.#handleCollectionChange);\n\t\t\t\n\t\t\tdelete this.initOptions;\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.bulkWrite([\n\t\t\t{ updateMany: { filter: { meta: { $exists: false } }, update: { $set: { meta: {} } } } },\n\t\t\t{ updateMany: { filter: { isOnline: true }, update: { $set: { isOnline: false } } } }\n\t\t]);\n\t\t\n\t}\n\t\n\t#handleCollectionChange = (next: ChangeStreamDocument<SessionDoc>) => {\n\t\tswitch (next.operationType) {\n\t\t\tcase \"insert\":\n\t\t\t\tif (!this.has(next.documentKey._id))\n\t\t\t\t\tnew Session<AS>(this, next.fullDocument);\n\t\t\t\t\n\t\t\t\tvoid this.users.get(next.fullDocument.user)?.trimSessions();\n\t\t\t\t\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"replace\":\n\t\t\t\tthis.get(next.documentKey._id)?.update(next.fullDocument);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"update\":\n\t\t\t\tthis.get(next.documentKey._id)?.update(next.updateDescription.updatedFields!);\n\t\t\t\tbreak;\n\t\t\t\n\t\t\tcase \"delete\":\n\t\t\t\tthis.get(next.documentKey._id)?.delete();\n\t\t}\n\t\t\n\t};\n\t\n\tuid() {\n\t\treturn `${newObjectIdString()}~${randomBytes(32).toString(\"base64url\")}`;\n\t}\n\t\n\tload(sessionDoc: SessionDoc) {\n\t\tnew Session<AS>(this, sessionDoc);\n\t\t\n\t}\n\t\n\tasync create(user: User<AS>, props: Partial<SessionDoc>) {\n\t\t\n\t\tconst ts = Date.now();\n\t\t\n\t\tconst sessionDoc: SessionDoc = {\n\t\t\tuserAgent: \"\",\n\t\t\tremoteAddress: \"127.0.0.1\",\n\t\t\tisOnline: true,\n\t\t\t...props,\n\t\t\t_id: this.uid(),\n\t\t\tuser: user._id,\n\t\t\tmeta: {},\n\t\t\tcreatedAt: ts,\n\t\t\tprolongedAt: ts,\n\t\t\texpiresAt: new Date(ts + (expireAfterSeconds * 1000))\n\t\t};\n\t\t\n\t\t/* new Session(\u2026) before await insertOne(\u2026) for avoid changeStream insert event to come earlier and create the session duplicate */\n\t\tconst session = new Session<AS>(this, sessionDoc);\n\t\t\n\t\tawait this.collection.insertOne(sessionDoc);\n\t\t\n\t\treturn session;\n\t}\n\t\n\tasync destroySession(_id: string) {\n\t\tconst { deletedCount } = await this.collection.deleteOne({ _id });\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"user\",\n\t\t\"remoteAddress\",\n\t\t\"isOnline\",\n\t\t\"meta\",\n\t\t\"createdAt\",\n\t\t\"prolongedAt\",\n\t\t\"expiresAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.sessionId.source\n\t\t},\n\t\tuser: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\tuserAgent: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 4096\n\t\t},\n\t\tremoteAddress: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.ip.source\n\t\t},\n\t\tisOnline: {\n\t\t\tbsonType: \"bool\"\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\tprolongedAt: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\texpiresAt: {\n\t\t\tbsonType: \"date\"\n\t\t}\n\t}\n\t// TODO: Restrict additional properties (not needed with meta)\n};\n", "import type { AbilitiesSchema } from \"insite-common\";\nimport type { User } from \"../users/User\";\nimport type { Sessions } from \"./Sessions\";\nimport type { SessionDoc } from \"./types\";\n\n\nexport class Session<AS extends AbilitiesSchema> {\n\tconstructor(sessions: Sessions<AS>, sessionDoc: SessionDoc) {\n\t\tconst user = sessions.users.get(sessionDoc.user);\n\t\t\n\t\tif (user) {\n\t\t\tthis.#sessions = sessions;\n\t\t\t\n\t\t\tthis._id = sessionDoc._id;\n\t\t\tthis.#sessions.set(this._id, this);\n\t\t\t\n\t\t\tthis.user = user;\n\t\t\tthis.user.sessions.add(this);\n\t\t\t\n\t\t\tthis.#sessions.users.bySessionId.set(this._id, this.user);\n\t\t\t\n\t\t\tthis.update(sessionDoc);\n\t\t} else\n\t\t\tvoid sessions.collection.deleteOne({ _id: sessionDoc._id });\n\t\t\n\t}\n\t\n\t_id!: string;\n\tuser!: User<AS>;\n\tisOnline = false;\n\t\n\tuserAgent!: string;\n\tremoteAddress!: string;\n\tcreatedAt!: number;\n\tprolongedAt!: number;\n\texpiresAt!: Date;\n\t\n\t#sessions!: Sessions<AS>;\n\t\n\tupdate({ _id, user, isOnline, ...restProps }: Partial<SessionDoc>) {\n\t\t\n\t\tif (isOnline !== undefined && this.isOnline !== isOnline) {\n\t\t\tthis.isOnline = isOnline;\n\t\t\t\n\t\t\tif (this.#sessions.users.isInited && this.user.isOnline !== this.isOnline)\n\t\t\t\tvoid this.user.updateIsOnlineDebounced();\n\t\t}\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t}\n\t\n\tprolong({ _id, user, ...updates }: Partial<SessionDoc>) {\n\t\t\n\t\tconst ts = Date.now();\n\t\t\n\t\tupdates.prolongedAt = ts;\n\t\tupdates.expiresAt = new Date(ts + (this.#sessions.collection.expireAfterSeconds * 1000));\n\t\t\n\t\tthis.update(updates);\n\t\t\n\t\treturn this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t}\n\t\n\tasync online() {\n\t\t\n\t\tif (!this.isOnline) {\n\t\t\tconst updates = { isOnline: true };\n\t\t\t\n\t\t\tthis.update(updates);\n\t\t\t\n\t\t\tawait this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t\t}\n\t\t\n\t}\n\t\n\tasync offline() {\n\t\t\n\t\tif (this.isOnline) {\n\t\t\tconst updates = { isOnline: false };\n\t\t\t\n\t\t\tthis.update(updates);\n\t\t\t\n\t\t\tawait this.#sessions.collection.updateOne({ _id: this._id }, { $set: updates });\n\t\t}\n\t\t\n\t}\n\t\n\tdelete() {\n\t\t\n\t\tthis.#sessions.delete(this._id);\n\t\tthis.user.sessions.delete(this);\n\t\tthis.#sessions.users.bySessionId.delete(this._id);\n\t\t\n\t\tthis.#sessions.users.emit(\"session-delete\", this);\n\t\t\n\t\tif (this.isOnline)\n\t\t\tthis.user.updateIsOnline();\n\t\t\n\t}\n\t\n}\n", "import { Binary, type WatchedCollection } from \"insite-db\";\nimport type { Users } from \"../Users\";\nimport { schema } from \"./schema\";\nimport type { AvatarDoc, AvatarsOptions } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class Avatars {\n\tconstructor(users: Users<any>, options: AvatarsOptions = {}) {\n\t\tthis.#users = users;\n\t\tthis.collections = users.collections;\n\t\t\n\t\tthis.initOptions = options;\n\t\t\n\t}\n\t\n\treadonly TYPES_ACCEPTED = [ \"image/webp\" ];\n\treadonly MAX_SIZE = 1024 * 512;\n\t\n\t#users;\n\tcollections;\n\t\n\tcollection!: WatchedCollection<AvatarDoc>;\n\t\n\tprivate initOptions?;\n\t\n\tasync init() {\n\t\t\n\t\tif (!this.#users.isInited) {\n\t\t\tconst {\n\t\t\t\tcollection: collectionOptions\n\t\t\t} = this.initOptions!;\n\t\t\t\n\t\t\tthis.collection = await this.collections.ensure<AvatarDoc>(\"users.avatars\", { ...collectionOptions, schema });\n\t\t\t\n\t\t\tawait this.#maintain();\n\t\t}\n\t\t\n\t}\n\t\n\tasync #maintain() {\n\t\t\n\t\tawait this.collection.updateMany({ meta: { $exists: false } }, { $set: { meta: {} } });\n\t\t\n\t}\n\t\n\tasync save(_id: string, type: string, data: string) {\n\t\tconst binaryData = Binary.createFromBase64(data.slice(data.indexOf(\",\")));\n\t\t\n\t\tif (!this.TYPES_ACCEPTED.includes(type))\n\t\t\tthrow new Error(\"avatar.unacceptable-format\");\n\t\t\n\t\tif (binaryData.length() > this.MAX_SIZE)\n\t\t\tthrow new Error(\"avatar.size-exceeds-limit\");\n\t\t\n\t\tconst ts = Date.now().toString(36);\n\t\t\n\t\tawait Promise.all([\n\t\t\tthis.collection.replaceOne({ _id }, {\n\t\t\t\ttype,\n\t\t\t\tsize: binaryData.length(),\n\t\t\t\tts,\n\t\t\t\tdata: binaryData,\n\t\t\t\tmeta: {}\n\t\t\t}, { upsert: true }),\n\t\t\tthis.#users.collection.updateOne({ _id }, { $set: { avatar: ts } })\n\t\t]);\n\t\t\n\t}\n\t\n\tasync deleteAvatar(_id: string) {\n\t\t\n\t\tconst [ { deletedCount } ] = await Promise.all([\n\t\t\tthis.collection.deleteOne({ _id }),\n\t\t\tthis.#users.collection.updateOne({ _id }, { $set: { avatar: null } })\n\t\t]);\n\t\t\n\t\treturn Boolean(deletedCount);\n\t}\n\t\n}\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../../lib\";\n\n\nexport const schema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"type\",\n\t\t\"size\",\n\t\t\"ts\",\n\t\t\"data\",\n\t\t\"meta\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\ttype: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 256\n\t\t},\n\t\tsize: {\n\t\t\tbsonType: \"number\"\n\t\t},\n\t\tts: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 10\n\t\t},\n\t\tdata: {\n\t\t\tbsonType: \"binData\"\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import { CollectionSchema } from \"insite-db\";\nimport { regexps } from \"../lib\";\n\n\nexport const basisSchema: CollectionSchema = {\n\trequired: [\n\t\t\"_id\",\n\t\t\"email\",\n\t\t\"password\",\n\t\t\"roles\",\n\t\t\"name\",\n\t\t\"org\",\n\t\t\"job\",\n\t\t\"meta\",\n\t\t\"createdAt\"\n\t],\n\tproperties: {\n\t\t_id: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps._id.source\n\t\t},\n\t\temail: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.email.source\n\t\t},\n\t\tpassword: {\n\t\t\tbsonType: \"string\",\n\t\t\tpattern: regexps.argon2.source\n\t\t},\n\t\troles: {\n\t\t\tbsonType: \"array\",\n\t\t\tuniqueItems: true,\n\t\t\titems: {\n\t\t\t\tbsonType: \"string\",\n\t\t\t\tpattern: regexps.role.source\n\t\t\t},\n\t\t\tadditionalItems: false\n\t\t},\n\t\tname: {\n\t\t\tbsonType: \"object\",\n\t\t\trequired: [\n\t\t\t\t\"first\",\n\t\t\t\t\"middle\",\n\t\t\t\t\"last\"\n\t\t\t],\n\t\t\tproperties: {\n\t\t\t\tfirst: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t},\n\t\t\t\tmiddle: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t},\n\t\t\t\tlast: {\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 512\n\t\t\t\t}\n\t\t\t},\n\t\t\tadditionalProperties: false\n\t\t},\n\t\torg: {\n\t\t\toneOf: [\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tpattern: regexps._id.source\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"null\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tjob: {\n\t\t\tbsonType: \"string\",\n\t\t\tmaxLength: 512\n\t\t},\n\t\tavatar: {\n\t\t\toneOf: [\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"string\",\n\t\t\t\t\tmaxLength: 10\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tbsonType: \"null\"\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tmeta: {\n\t\t\tbsonType: \"object\"\n\t\t},\n\t\tcreatedAt: {\n\t\t\tbsonType: \"number\"\n\t\t}\n\t},\n\tadditionalProperties: false\n};\n", "import {\n\t_ids,\n\tdebounce,\n\tempty,\n\thasAny,\n\tremoveOne\n} from \"@nesvet/n\";\nimport type { Abilities, AbilitiesSchema } from \"insite-common\";\nimport type { GenericAbilities } from \"../abilities/types\";\nimport type { Org } from \"../orgs/Org\";\nimport type { Role } from \"../roles/Role\";\nimport type { Session } from \"../sessions/Session\";\nimport type { UserDoc } from \"./types\";\nimport type { Users } from \"./Users\";\n\n\nconst rolesSnapshots = new WeakMap();\nconst permissionsSnapshots = new WeakMap();\n\nconst staticUrl = process.env.INSITE_STATIC_URL ?? \"\";\n\n\nexport class User<AS extends AbilitiesSchema> {\n\tconstructor(users: Users<AS>, userDoc: UserDoc) {\n\t\tthis.#users = users;\n\t\t\n\t\tthis._id = userDoc._id;\n\t\tusers.set(this._id, this);\n\t\t\n\t\tvoid this.update(userDoc);\n\t\t\n\t\tif (users.isInited)\n\t\t\tusers.emit(\"user-create\", this);\n\t\t\n\t}\n\t\n\t_id;\n\temail!: string;\n\tname = {\n\t\tfirst: \"\",\n\t\tmiddle: \"\",\n\t\tlast: \"\"\n\t};\n\t\n\tinitials = \"\";\n\tdisplayLabel = \"\";\n\torg!: Org<AS>;\n\tjob: string = \"\";\n\tavatar: string | null = null;\n\tavatarUrl: string | null = null;\n\t\n\t#users;\n\t\n\tisUser = true;\n\tisRoot?: boolean;\n\t\n\troles = new Set<Role<AS>>();\n\townRoles: Role<AS>[] = [];\n\townRoleIds: string[] = [];\n\tslaveRoles = new Set<Role<AS>>();\n\tslaveRoleIds: string[] = [];\n\tabilities: Abilities<AS> = {};\n\t\n\tslaveOrgs = new Set<Org<AS>>();\n\tslaveUsers = new Set<User<AS>>();\n\tslaves = new Set<Org<AS> | User<AS>>();\n\t\n\tslaveIds: string[] = [];\n\tpermissiveIds: string[] = [];\n\t\n\tsessions = new Set<Session<AS>>();\n\t\n\tisOnline = false;\n\t\n\tupdate({ _id, name, email, roles: ownRoleIds, org: orgId, avatar, ...restProps }: Partial<UserDoc>) {\n\t\t\n\t\tObject.assign(this, restProps);\n\t\t\n\t\tlet isEmailUpdated;\n\t\tif (email && this.email !== email) {\n\t\t\tthis.#users.byEmail.delete(this.email);\n\t\t\tthis.email = email;\n\t\t\tthis.#users.byEmail.set(email, this);\n\t\t\tisEmailUpdated = true;\n\t\t}\n\t\t\n\t\tlet isNameUpdated;\n\t\tlet isLastNameUpdated;\n\t\tif (name && (this.name.first !== name.first || this.name.middle !== name.middle || this.name.last !== name.last)) {\n\t\t\tisLastNameUpdated = this.name.last !== name.last;\n\t\t\tthis.name = {\n\t\t\t\tfirst: name.first ?? \"\",\n\t\t\t\tmiddle: name.middle ?? \"\",\n\t\t\t\tlast: name.last ?? \"\"\n\t\t\t};\n\t\t\tthis.initials = (((name.first?.[0] ?? \"\") + (name.last?.[0] ?? \"\")) || this.email[0]).toUpperCase();\n\t\t\tisNameUpdated = true;\n\t\t}\n\t\t\n\t\tif (isEmailUpdated || isNameUpdated)\n\t\t\tthis.displayLabel = `${this.name.first} ${this.name.last}`.trim() || this.name.middle || this.email;\n\t\t\n\t\tlet isRolesUpdated;\n\t\tif (ownRoleIds) {\n\t\t\tthis.ownRoleIds = ownRoleIds;\n\t\t\t\n\t\t\tconst snapshot = this.ownRoleIds.join(\",\");\n\t\t\t\n\t\t\tif (snapshot !== rolesSnapshots.get(this)) {\n\t\t\t\trolesSnapshots.set(this, snapshot);\n\t\t\t\t\n\t\t\t\tif (this.#users.isInited) {\n\t\t\t\t\tthis.updateRoles();\n\t\t\t\t\tisRolesUpdated = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\tlet isOrgUpdated;\n\t\tif (orgId !== undefined && this.org?._id !== orgId) {\n\t\t\tthis.org?.users.delete(this);\n\t\t\tthis.org = orgId && this.#users.orgs.get(orgId) || this.#users.orgs.null;// eslint-disable-line @stylistic/no-mixed-operators\n\t\t\tthis.org.users.add(this);\n\t\t\tisOrgUpdated = true;\n\t\t}\n\t\t\n\t\tif (avatar !== undefined && this.avatar !== avatar) {\n\t\t\tthis.avatar = avatar;\n\t\t\tthis.avatarUrl = avatar && `${staticUrl}/avatars/${this._id}-${avatar}.webp`;\n\t\t}\n\t\t\n\t\tif (this.#users.isInited)\n\t\t\tif (isRolesUpdated || isOrgUpdated) {\n\t\t\t\tthis.updatePermissions();\n\t\t\t\t\n\t\t\t\tif (isLastNameUpdated)\n\t\t\t\t\tthis.#users.isSortRequired = true;\n\t\t\t\t\n\t\t\t\tthis.#users.update();\n\t\t\t} else if (isLastNameUpdated)\n\t\t\t\tthis.#users.sort();\n\t\t\n\t}\n\t\n\tupdateRoles() {\n\t\t\n\t\tthis.ownRoles = [];\n\t\tthis.roles.clear();\n\t\tthis.slaveRoles.clear();\n\t\tempty(this.abilities);\n\t\t\n\t\tfor (const roleId of this.ownRoleIds) {\n\t\t\tconst role = this.#users.roles.get(roleId);\n\t\t\tif (role) {\n\t\t\t\t\n\t\t\t\tthis.ownRoles.push(role);\n\t\t\t\tthis.roles.add(role);\n\t\t\t\tfor (const involvedRole of role.involves) {\n\t\t\t\t\tthis.roles.add(involvedRole);\n\t\t\t\t\tthis.slaveRoles.add(involvedRole);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tthis.slaveRoleIds = _ids(this.slaveRoles);\n\t\t\t\t\n\t\t\t\tthis.#users.abilities.merge(this.abilities as GenericAbilities, role.abilities as GenericAbilities);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (this.roles.has(this.#users.roles.root))\n\t\t\tthis.isRoot = true;\n\t\t\n\t\tvoid this.trimSessions();\n\t\t\n\t}\n\t\n\tupdatePermissions() {\n\t\t\n\t\tthis.slaveOrgs.clear();\n\t\tthis.slaveUsers.clear();\n\t\tthis.slaves.clear();\n\t\tconst slaveIds = new Set<string>();\n\t\t\n\t\tfor (const org of this.#users.orgs.sorted)\n\t\t\tif ((org.ownerUsers.has(this) || this.isRoot) && !this.slaveOrgs.has(org)) {\n\t\t\t\tthis.slaveOrgs.add(org);\n\t\t\t\tthis.slaves.add(org);\n\t\t\t\tslaveIds.add(org._id);\n\t\t\t\tfor (const slaveOrg of org.slaveOrgs) {\n\t\t\t\t\tthis.slaveOrgs.add(slaveOrg);\n\t\t\t\t\tthis.slaves.add(slaveOrg);\n\t\t\t\t\tslaveIds.add(slaveOrg._id);\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\tfor (const org of new Set([ this.org, ...this.slaveOrgs, this.#users.orgs.null ]))\n\t\t\tfor (const user of org.users)\n\t\t\t\tif (user !== this && (hasAny(this.slaveRoles, user.ownRoles) || !user.ownRoles.length)) {\n\t\t\t\t\tthis.slaveUsers.add(user);\n\t\t\t\t\tthis.slaves.add(user);\n\t\t\t\t\tslaveIds.add(user._id);\n\t\t\t\t}\n\t\t\n\t\tthis.slaveIds = [ ...slaveIds ];\n\t\t\n\t\tconst permissiveOrgIds = [];\n\t\tif (this.org._id) {\n\t\t\tpermissiveOrgIds.push(this.org._id);\n\t\t\tfor (const slaveOrg of this.org.slaveOrgs)\n\t\t\t\tif (!this.slaveOrgs.has(slaveOrg))\n\t\t\t\t\tpermissiveOrgIds.push(slaveOrg._id);\n\t\t}\n\t\t\n\t\tthis.permissiveIds = [ ...permissiveOrgIds, this._id, ...slaveIds ];\n\t\t\n\t\t\n\t\tconst snapshot = [\n\t\t\tthis.permissiveIds.join(\",\"),\n\t\t\tthis.ownRoleIds.join(\",\"),\n\t\t\tJSON.stringify(this.abilities),\n\t\t\tthis.slaveRoleIds.join(\",\")\n\t\t].join(\"\\n\");\n\t\t\n\t\tif (snapshot !== permissionsSnapshots.get(this)) {\n\t\t\tpermissionsSnapshots.set(this, snapshot);\n\t\t\t\n\t\t\tif (this.#users.isInited)\n\t\t\t\tthis.#users.emit(\"user-permissions-change\", this);\n\t\t}\n\t\t\n\t}\n\t\n\ttrimSessions() {\n\t\t\n\t\tconst sessionsLimit = this.abilities.login?.sessionsLimit;\n\t\t\n\t\tif (typeof sessionsLimit == \"number\" && this.sessions.size > sessionsLimit)\n\t\t\treturn this.#users.sessions.collection.deleteMany({\n\t\t\t\t_id: {\n\t\t\t\t\t$in: _ids(\n\t\t\t\t\t\t[ ...this.sessions ]\n\t\t\t\t\t\t\t.sort((a, b) => a.expiresAt.valueOf() - b.expiresAt.valueOf())\n\t\t\t\t\t\t\t.slice(0, this.sessions.size - sessionsLimit)\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t});\n\t\t\n\t}\n\t\n\tupdateIsOnline() {\n\t\t\n\t\tlet isOnline = false;\n\t\t\n\t\tfor (const session of this.sessions)\n\t\t\tif (session.isOnline) {\n\t\t\t\tisOnline = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\n\t\tif (this.isOnline !== isOnline) {\n\t\t\tthis.isOnline = isOnline;\n\t\t\tthis.#users.emit(\"user-is-online\", this);\n\t\t}\n\t\t\n\t}\n\t\n\tupdateIsOnlineDebounced = debounce(() => this.updateIsOnline(), 500);\n\t\n\tasync delete() {\n\t\t\n\t\tthis.org.users.delete(this);\n\t\t\n\t\tthis.#users.delete(this._id);\n\t\tthis.#users.byEmail.delete(this.email);\n\t\tremoveOne(this.#users.sorted, this);\n\t\t\n\t\trolesSnapshots.delete(this);\n\t\tpermissionsSnapshots.delete(this);\n\t\t\n\t\tawait this.#users.replace(this._id);\n\t\t\n\t\tthis.#users.update();\n\t\t\n\t}\n\t\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,OAAAA,OAAW,YAMb,IAAMC,EAAN,cAA2BD,EAAI,CAGrC,YAAYE,EAA2BC,EAAmB,CACrD,OAAOD,GAAU,WACpBC,EAAUD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ACC,EAAE,KAAK,KACxBD,EAAE,aAAeC,EAAE,aAClB,EACAD,EAAE,aAAeC,EAAE,aAAe,GAAK,EACxCD,EAAE,KAAK,KAAO,GAAK,EACpBA,aAAa0B,GAAOzB,aAAayB,EACjC1B,EAAE,MAAQC,EAAE,MACX,EACAD,EAAE,MAAQC,EAAE,MAAQ,GAAK,EAC1BD,aAAa0B,EAAM,GAAK,CAE5B,CAEA,QAAQC,EAAe,CACtB,OAAOC,GACND,EACE,IAAIf,GAAO,KAAK,IAAIA,CAAG,GAAK,KAAK,KAAK,IAAIA,CAAG,CAAC,EAC9C,OAAO,OAAO,EACf,KAAK,KAAKa,EAAiB,CAAC,CAC/B,CAEA,WAAa,IAAI,IAEjB,gBAAkB,IAAI,IAEtB,MAAM,QAAQI,EAAgB,CAC7B,IAAMC,EAAO,KAAK,WAAW,IAAID,CAAM,GAAK,KACxCC,GACH,KAAK,WAAW,OAAOD,CAAM,EAE9B,QAAWE,KAAW,KAAK,gBAC1B,MAAMA,EAAQF,EAAQC,CAAI,CAE5B,CAEA,MAAM,WAAWlB,EAAa,CAC7B,GAAM,CAAE,aAAAoB,CAAa,EAAI,MAAM,KAAK,WAAW,UAAU,CAAE,IAAApB,CAAI,CAAC,EAEhE,MAAO,EAAQoB,CAChB,CAGA,OAAO,KAAkCjE,EAA0BC,EAAuB,CAGzF,OAFc,IAAIF,EAAMC,EAAaC,CAAO,EAE/B,UAAU,CACxB,CAED",
|
|
6
|
+
"names": ["Err", "AbilityError", "longId", "payload", "add", "assignPath", "deletePath", "empty", "getPath", "intersection", "pick", "setPath", "isAbilityObject", "value", "isAbilityParamNumber", "isAbilityParamItems", "schemaParentMap", "AbilitiesMap", "abilitiesSchema", "subSchema", "#hierarchical", "parse", "schemas", "parent", "level", "schema", "longId", "subIds", "subId", "_id", "top", "paramId", "schemaOrLongId", "paramIdOrMax", "max", "ability", "paramSchema", "schemasOrIds", "a", "b", "schemaMaxMap", "resolve", "_schema", "parentSchema", "assignPath", "_max", "abilities", "subSchemas", "subAbilities", "i", "abilityParam", "value", "getPath", "setPath", "referenceValue", "isAbilityParamNumber", "isAbilityParamItems", "itemId", "intersection", "item", "adjustedAbilities", "adjustedAbility", "isAbilityObject", "pick", "empty", "target", "source", "targetAbility", "sourceAbility", "add", "deletePath", "Err", "RolesError", "stringOrArray", "payload", "deleteProps", "getAll", "intersection", "reAdd", "removeAll", "snapshots", "Role", "roles", "roleDoc", "#roles", "_id", "ownInvolveIds", "ownAbilities", "title", "restProps", "snapshot", "regexps", "basisSchema", "regexps", "indexes", "preventDirectDelete", "Roles", "users", "options", "rootProps", "initOptions", "Role", "customSchema", "customIndexes", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "roleDoc", "#handleCollectionChange", "next", "role", "involvedBy", "involvedRoleId", "involvedRole", "involvedByRole", "reAdd", "#sortRoles", "a", "b", "array", "anotherRole", "getAll", "sorted", "i", "involvedRoleIndex", "_o", "_id", "involves", "title", "description", "restProps", "roleId", "updates", "abilities", "ids", "roles", "intersection", "cleanedUpIds", "abilityLongId", "set", "paramId", "value", "Err", "UnauthorizedError", "payload", "SubordinationError", "type", "ids", "PermissionError", "hash", "verify", "EventEmitter", "_ids", "deleteProps", "removeAll", "StatefulPromise", "without", "newObjectIdString", "_ids", "deleteProps", "EmptyArray", "EmptySet", "removeAll", "sort", "union", "without", "newObjectIdString", "snapshots", "Org", "orgs", "orgDoc", "_id", "title", "ownerIds", "restProps", "snapshot", "basisSchema", "regexps", "indexes", "preventDirectDelete", "Orgs", "users", "options", "#isPreinited", "customSchema", "customIndexes", "nullProps", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "Org", "EmptyArray", "EmptySet", "#maintain", "orgDoc", "#handleCollectionChange", "next", "#resolve", "org", "slaveOrgs", "ownerOrg", "slaveOrg", "array", "sorted", "ownerId", "ownerUser", "anotherOrg", "#sortOrgs", "sort", "i", "slaveOrgIndex", "o", "length", "a", "b", "title", "note", "restProps", "_id", "newObjectIdString", "updates", "byUser", "union", "without", "_ids", "fromId", "toId", "handler", "randomBytes", "deleteProps", "removeAll", "newObjectIdString", "basisSchema", "regexps", "Session", "sessions", "sessionDoc", "user", "#sessions", "_id", "isOnline", "restProps", "updates", "ts", "expireAfterSeconds", "indexes", "Sessions", "users", "options", "customSchema", "customIndexes", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "sessionDoc", "#handleCollectionChange", "next", "Session", "newObjectIdString", "randomBytes", "user", "props", "ts", "session", "_id", "deletedCount", "Binary", "schema", "regexps", "Avatars", "users", "options", "#users", "collectionOptions", "schema", "#maintain", "_id", "type", "data", "binaryData", "Binary", "ts", "deletedCount", "basisSchema", "regexps", "_ids", "debounce", "empty", "hasAny", "removeOne", "rolesSnapshots", "permissionsSnapshots", "staticUrl", "User", "users", "userDoc", "#users", "_id", "name", "email", "ownRoleIds", "orgId", "avatar", "restProps", "isEmailUpdated", "isNameUpdated", "isLastNameUpdated", "isRolesUpdated", "snapshot", "isOrgUpdated", "roleId", "role", "involvedRole", "slaveIds", "org", "slaveOrg", "user", "permissiveOrgIds", "sessionsLimit", "a", "b", "isOnline", "session", "indexes", "unknownUserPasswordHash", "Users", "_Users", "collections", "options", "eventEmitter", "EventEmitter", "#eventEmitter", "AbilitiesMap", "event", "callback", "context", "#isPreinited", "customIndexes", "customSchema", "initialRootProps", "collectionOptions", "removeAll", "basisSchema", "deleteProps", "schema", "#maintain", "userDoc", "rolesOptions", "orgsOptions", "sessionsOptions", "avatarsOptions", "quiet", "Roles", "Orgs", "Sessions", "Avatars", "#handleCollectionChange", "#initPromise", "next", "User", "a", "b", "shouldUpdateRoles", "user", "StatefulPromise", "email", "password", "roles", "name", "org", "job", "restProps", "_id", "newObjectIdString", "hash", "updates", "byUser", "without", "nextPassword", "regexps", "writes", "newPassword", "sessionProps", "verify", "session", "#sortUsersAndOrgs", "Org", "ids", "_ids", "fromId", "toId", "handler", "deletedCount"]
|
|
7
7
|
}
|
package/dist/roles/Role.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Role.d.ts","sourceRoot":"","sources":["../../src/roles/Role.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlC,qBAAa,IAAI,CAAC,EAAE,SAAS,eAAe;;gBAC/B,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO;IAY9C,GAAG,SAAC;IACJ,aAAa,EAAG,MAAM,EAAE,CAAC;IACzB,YAAY,EAAG,SAAS,CAAC,EAAE,CAAC,CAAC;IAC7B,KAAK,SAAM;IACX,YAAY,SAAM;IAClB,EAAE,SAAK;IAEP,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAM;IAC7B,QAAQ,gBAAuB;IAC/B,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAM;IAC9B,kBAAkB,EAAE,SAAS,CAAC,EAAE,CAAC,CAAM;IAEvC,MAAM,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Role.d.ts","sourceRoot":"","sources":["../../src/roles/Role.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlC,qBAAa,IAAI,CAAC,EAAE,SAAS,eAAe;;gBAC/B,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO;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AAC;IAEZ,UAAU,EAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE1C,OAAO,CAAC,WAAW,CAAC,CAAC;IAEf,IAAI;IAoBJ,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"Avatars.d.ts","sourceRoot":"","sources":["../../../src/users/avatars/Avatars.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMzD,qBAAa,OAAO;;gBACP,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,GAAE,cAAmB;IAQ3D,QAAQ,CAAC,cAAc,WAAoB;IAC3C,QAAQ,CAAC,QAAQ,SAAc;IAG/B,WAAW,kCAAC;IAEZ,UAAU,EAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAE1C,OAAO,CAAC,WAAW,CAAC,CAAC;IAEf,IAAI;IAoBJ,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAwB5C,YAAY,CAAC,GAAG,EAAE,MAAM;CAU9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-users-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "Server-side users, orgs, roles, sessions for inSite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"insite",
|
|
@@ -47,11 +47,11 @@
|
|
|
47
47
|
"@nesvet/n": "^1.2.1",
|
|
48
48
|
"@node-rs/argon2": "^2.0.2",
|
|
49
49
|
"eventemitter3": "^5.0.4",
|
|
50
|
-
"insite-common": "^2.
|
|
51
|
-
"insite-db": "^2.
|
|
50
|
+
"insite-common": "^2.6.0",
|
|
51
|
+
"insite-db": "^2.6.0"
|
|
52
52
|
},
|
|
53
|
-
"packageManager": "bun@1.3.9",
|
|
54
53
|
"engines": {
|
|
55
|
-
"
|
|
54
|
+
"bun": ">=1.4.4",
|
|
55
|
+
"node": ">=22.0.0"
|
|
56
56
|
}
|
|
57
57
|
}
|