insite-common 2.1.1 → 2.1.3

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.
Files changed (34) hide show
  1. package/{lib/backend/index.ts → dist/backend/index.d.ts} +1 -0
  2. package/dist/backend/index.d.ts.map +1 -0
  3. package/dist/backend/index.js +2 -0
  4. package/dist/backend/index.js.map +7 -0
  5. package/dist/backend/server/createServer.d.ts +7 -0
  6. package/dist/backend/server/createServer.d.ts.map +1 -0
  7. package/{lib/backend/server/index.ts → dist/backend/server/index.d.ts} +1 -0
  8. package/dist/backend/server/index.d.ts.map +1 -0
  9. package/dist/backend/server/resolveSSL.d.ts +8 -0
  10. package/dist/backend/server/resolveSSL.d.ts.map +1 -0
  11. package/dist/backend/server/showServerListeningMessage.d.ts +11 -0
  12. package/dist/backend/server/showServerListeningMessage.d.ts.map +1 -0
  13. package/dist/common/index.d.ts +2 -0
  14. package/dist/common/index.d.ts.map +1 -0
  15. package/dist/common/index.js +2 -0
  16. package/dist/common/index.js.map +7 -0
  17. package/dist/common/types/abilities.d.ts +57 -0
  18. package/dist/common/types/abilities.d.ts.map +1 -0
  19. package/dist/common/types/index.d.ts +2 -0
  20. package/dist/common/types/index.d.ts.map +1 -0
  21. package/dist/frontend/index.d.ts +2 -0
  22. package/dist/frontend/index.d.ts.map +1 -0
  23. package/dist/frontend/index.js +1 -0
  24. package/dist/frontend/index.js.map +7 -0
  25. package/{lib/index.ts → dist/index.d.ts} +1 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/package.json +13 -10
  28. package/lib/backend/server/createServer.ts +0 -23
  29. package/lib/backend/server/resolveSSL.ts +0 -26
  30. package/lib/backend/server/showServerListeningMessage.ts +0 -29
  31. package/lib/common/index.ts +0 -1
  32. package/lib/common/types/abilities.ts +0 -99
  33. package/lib/common/types/index.ts +0 -1
  34. package/lib/frontend/index.ts +0 -1
@@ -1,2 +1,3 @@
1
1
  export * from "../common";
2
2
  export * from "./server";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backend/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
@@ -0,0 +1,2 @@
1
+ import p from"node:http";import i from"node:https";function c(e,r){let t="key"in e&&"cert"in e?i.createServer(e):p.createServer(e);return r?new Promise(o=>{t.on("listening",()=>o(t)),t.listen(r)}):t}import{readFileSync as n}from"node:fs";function m(e={cert:process.env.INSITE_SSL_CERT,key:process.env.INSITE_SSL_KEY}){if(e.cert&&e.key)try{return typeof e.cert=="string"&&!/^-{3,}BEGIN/.test(e.cert)&&(e.cert=n(e.cert)),typeof e.key=="string"&&!/^-{3,}BEGIN/.test(e.key)&&(e.key=n(e.key)),e}catch(r){console.error("SSL resolve error:",r)}}function a(e){let{address:r,family:t,port:o}=e.server.address();console.info(`${e.icon} inSite ${e.name} Server is listening on`,`${e.protocol}://${t==="IPv4"?r:r.replace(/^::(?:ffff:)?/,"")||process.env.NODE_ENV==="development"?"localhost":"127.0.0.1"}:${o}`)}export{c as createServer,m as resolveSSL,a as showServerListeningMessage};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/backend/server/createServer.ts", "../../src/backend/server/resolveSSL.ts", "../../src/backend/server/showServerListeningMessage.ts"],
4
+ "sourcesContent": ["import http from \"node:http\";\nimport https from \"node:https\";\n\n\nexport function createServer(options: http.ServerOptions): http.Server;\nexport function createServer(options: https.ServerOptions): https.Server;\nexport function createServer(options: http.ServerOptions, port: number | string): Promise<http.Server>;\nexport function createServer(options: https.ServerOptions, port: number | string): Promise<https.Server>;\nexport function createServer(options: http.ServerOptions | https.ServerOptions, port?: number | string) {\n\t\n\tconst server =\n\t\t(\"key\" in options && \"cert\" in options) ?\n\t\t\thttps.createServer(options) :\n\t\t\thttp.createServer(options);\n\t\n\treturn port ?\n\t\tnew Promise(resolve => {\n\t\t\tserver.on(\"listening\", () => resolve(server));\n\t\t\tserver.listen(port);\n\t\t\t\n\t\t}) :\n\t\tserver;\n}\n", "import { readFileSync } from \"node:fs\";\n\n\nexport function resolveSSL(ssl: {\n\tcert: Buffer<ArrayBufferLike> | string;\n\tkey: Buffer<ArrayBufferLike> | string;\n} = {\n\tcert: process.env.INSITE_SSL_CERT!,\n\tkey: process.env.INSITE_SSL_KEY!\n}) {\n\tif (ssl.cert && ssl.key)\n\t\ttry {\n\t\t\tif (typeof ssl.cert == \"string\" && !/^-{3,}BEGIN/.test(ssl.cert))\n\t\t\t\tssl.cert = readFileSync(ssl.cert);\n\t\t\t\n\t\t\tif (typeof ssl.key == \"string\" && !/^-{3,}BEGIN/.test(ssl.key))\n\t\t\t\tssl.key = readFileSync(ssl.key);\n\t\t\t\n\t\t\treturn ssl;\n\t\t} catch (error) {\n\t\t\tconsole.error(\"SSL resolve error:\", error);\n\t\t}\n\t\n\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n}\n\n", "import type http from \"node:http\";\nimport type https from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\n\n\ntype Server = {\n\ticon: string;\n\tname: string;\n\tprotocol: string;\n\tserver: http.Server | https.Server;\n};\n\n\nexport function showServerListeningMessage(server: Server) {\n\t\n\tconst { address, family, port } = server.server.address() as AddressInfo;\n\t\n\tconsole.info(\n\t\t`${server.icon} inSite ${server.name} Server is listening on`,\n\t\t`${server.protocol}://${\n\t\t\tfamily === \"IPv4\" ?\n\t\t\t\taddress : (\n\t\t\t\t\taddress.replace(/^::(?:ffff:)?/, \"\") ||\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" ? \"localhost\" : \"127.0.0.1\"\n\t\t\t\t)\n\t\t}:${port}`\n\t);\n\t\n}\n"],
5
+ "mappings": "AAAA,OAAOA,MAAU,YACjB,OAAOC,MAAW,aAOX,SAASC,EAAaC,EAAmDC,EAAwB,CAEvG,IAAMC,EACJ,QAASF,GAAW,SAAUA,EAC9BF,EAAM,aAAaE,CAAO,EAC1BH,EAAK,aAAaG,CAAO,EAE3B,OAAOC,EACN,IAAI,QAAQE,GAAW,CACtBD,EAAO,GAAG,YAAa,IAAMC,EAAQD,CAAM,CAAC,EAC5CA,EAAO,OAAOD,CAAI,CAEnB,CAAC,EACDC,CACF,CCtBA,OAAS,gBAAAE,MAAoB,UAGtB,SAASC,EAAWC,EAGvB,CACH,KAAM,QAAQ,IAAI,gBAClB,IAAK,QAAQ,IAAI,cAClB,EAAG,CACF,GAAIA,EAAI,MAAQA,EAAI,IACnB,GAAI,CACH,OAAI,OAAOA,EAAI,MAAQ,UAAY,CAAC,cAAc,KAAKA,EAAI,IAAI,IAC9DA,EAAI,KAAOF,EAAaE,EAAI,IAAI,GAE7B,OAAOA,EAAI,KAAO,UAAY,CAAC,cAAc,KAAKA,EAAI,GAAG,IAC5DA,EAAI,IAAMF,EAAaE,EAAI,GAAG,GAExBA,CACR,OAASC,EAAO,CACf,QAAQ,MAAM,qBAAsBA,CAAK,CAC1C,CAGF,CCXO,SAASC,EAA2BC,EAAgB,CAE1D,GAAM,CAAE,QAAAC,EAAS,OAAAC,EAAQ,KAAAC,CAAK,EAAIH,EAAO,OAAO,QAAQ,EAExD,QAAQ,KACP,GAAGA,EAAO,IAAI,WAAWA,EAAO,IAAI,0BACpC,GAAGA,EAAO,QAAQ,MACjBE,IAAW,OACVD,EACCA,EAAQ,QAAQ,gBAAiB,EAAE,GACnC,QAAQ,IAAI,WAAa,cAAgB,YAAc,WAE1D,IAAIE,CAAI,EACT,CAED",
6
+ "names": ["http", "https", "createServer", "options", "port", "server", "resolve", "readFileSync", "resolveSSL", "ssl", "error", "showServerListeningMessage", "server", "address", "family", "port"]
7
+ }
@@ -0,0 +1,7 @@
1
+ import http from "node:http";
2
+ import https from "node:https";
3
+ export declare function createServer(options: http.ServerOptions): http.Server;
4
+ export declare function createServer(options: https.ServerOptions): https.Server;
5
+ export declare function createServer(options: http.ServerOptions, port: number | string): Promise<http.Server>;
6
+ export declare function createServer(options: https.ServerOptions, port: number | string): Promise<https.Server>;
7
+ //# sourceMappingURL=createServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../../../src/backend/server/createServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAG/B,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;AACvE,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC;AACzE,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvG,wBAAgB,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export * from "./createServer";
2
2
  export * from "./resolveSSL";
3
3
  export * from "./showServerListeningMessage";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/backend/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export declare function resolveSSL(ssl?: {
2
+ cert: Buffer<ArrayBufferLike> | string;
3
+ key: Buffer<ArrayBufferLike> | string;
4
+ }): {
5
+ cert: Buffer<ArrayBufferLike> | string;
6
+ key: Buffer<ArrayBufferLike> | string;
7
+ } | undefined;
8
+ //# sourceMappingURL=resolveSSL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveSSL.d.ts","sourceRoot":"","sources":["../../../src/backend/server/resolveSSL.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,CAAC,GAAG,GAAE;IAC/B,IAAI,EAAE,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;IACvC,GAAG,EAAE,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,CAAC;CAItC;UALM,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM;SACjC,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM;cAmBrC"}
@@ -0,0 +1,11 @@
1
+ import type http from "node:http";
2
+ import type https from "node:https";
3
+ type Server = {
4
+ icon: string;
5
+ name: string;
6
+ protocol: string;
7
+ server: http.Server | https.Server;
8
+ };
9
+ export declare function showServerListeningMessage(server: Server): void;
10
+ export {};
11
+ //# sourceMappingURL=showServerListeningMessage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"showServerListeningMessage.d.ts","sourceRoot":"","sources":["../../../src/backend/server/showServerListeningMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAIpC,KAAK,MAAM,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;CACnC,CAAC;AAGF,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,QAexD"}
@@ -0,0 +1,2 @@
1
+ export type * from "./types";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ import p from"node:http";import i from"node:https";function c(e,r){let t="key"in e&&"cert"in e?i.createServer(e):p.createServer(e);return r?new Promise(o=>{t.on("listening",()=>o(t)),t.listen(r)}):t}import{readFileSync as n}from"node:fs";function v(e={cert:process.env.INSITE_SSL_CERT,key:process.env.INSITE_SSL_KEY}){if(e.cert&&e.key)try{return typeof e.cert=="string"&&!/^-{3,}BEGIN/.test(e.cert)&&(e.cert=n(e.cert)),typeof e.key=="string"&&!/^-{3,}BEGIN/.test(e.key)&&(e.key=n(e.key)),e}catch(r){console.error("SSL resolve error:",r)}}function a(e){let{address:r,family:t,port:o}=e.server.address();console.info(`${e.icon} inSite ${e.name} Server is listening on`,`${e.protocol}://${t==="IPv4"?r:r.replace(/^::(?:ffff:)?/,"")||process.env.NODE_ENV==="development"?"localhost":"127.0.0.1"}:${o}`)}export{c as createServer,v as resolveSSL,a as showServerListeningMessage};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/backend/server/createServer.ts", "../../src/backend/server/resolveSSL.ts", "../../src/backend/server/showServerListeningMessage.ts"],
4
+ "sourcesContent": ["import http from \"node:http\";\nimport https from \"node:https\";\n\n\nexport function createServer(options: http.ServerOptions): http.Server;\nexport function createServer(options: https.ServerOptions): https.Server;\nexport function createServer(options: http.ServerOptions, port: number | string): Promise<http.Server>;\nexport function createServer(options: https.ServerOptions, port: number | string): Promise<https.Server>;\nexport function createServer(options: http.ServerOptions | https.ServerOptions, port?: number | string) {\n\t\n\tconst server =\n\t\t(\"key\" in options && \"cert\" in options) ?\n\t\t\thttps.createServer(options) :\n\t\t\thttp.createServer(options);\n\t\n\treturn port ?\n\t\tnew Promise(resolve => {\n\t\t\tserver.on(\"listening\", () => resolve(server));\n\t\t\tserver.listen(port);\n\t\t\t\n\t\t}) :\n\t\tserver;\n}\n", "import { readFileSync } from \"node:fs\";\n\n\nexport function resolveSSL(ssl: {\n\tcert: Buffer<ArrayBufferLike> | string;\n\tkey: Buffer<ArrayBufferLike> | string;\n} = {\n\tcert: process.env.INSITE_SSL_CERT!,\n\tkey: process.env.INSITE_SSL_KEY!\n}) {\n\tif (ssl.cert && ssl.key)\n\t\ttry {\n\t\t\tif (typeof ssl.cert == \"string\" && !/^-{3,}BEGIN/.test(ssl.cert))\n\t\t\t\tssl.cert = readFileSync(ssl.cert);\n\t\t\t\n\t\t\tif (typeof ssl.key == \"string\" && !/^-{3,}BEGIN/.test(ssl.key))\n\t\t\t\tssl.key = readFileSync(ssl.key);\n\t\t\t\n\t\t\treturn ssl;\n\t\t} catch (error) {\n\t\t\tconsole.error(\"SSL resolve error:\", error);\n\t\t}\n\t\n\treturn undefined;// eslint-disable-line unicorn/no-useless-undefined\n}\n\n", "import type http from \"node:http\";\nimport type https from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\n\n\ntype Server = {\n\ticon: string;\n\tname: string;\n\tprotocol: string;\n\tserver: http.Server | https.Server;\n};\n\n\nexport function showServerListeningMessage(server: Server) {\n\t\n\tconst { address, family, port } = server.server.address() as AddressInfo;\n\t\n\tconsole.info(\n\t\t`${server.icon} inSite ${server.name} Server is listening on`,\n\t\t`${server.protocol}://${\n\t\t\tfamily === \"IPv4\" ?\n\t\t\t\taddress : (\n\t\t\t\t\taddress.replace(/^::(?:ffff:)?/, \"\") ||\n\t\t\t\t\tprocess.env.NODE_ENV === \"development\" ? \"localhost\" : \"127.0.0.1\"\n\t\t\t\t)\n\t\t}:${port}`\n\t);\n\t\n}\n"],
5
+ "mappings": "AAAA,OAAOA,MAAU,YACjB,OAAOC,MAAW,aAOX,SAASC,EAAaC,EAAmDC,EAAwB,CAEvG,IAAMC,EACJ,QAASF,GAAW,SAAUA,EAC9BF,EAAM,aAAaE,CAAO,EAC1BH,EAAK,aAAaG,CAAO,EAE3B,OAAOC,EACN,IAAI,QAAQE,GAAW,CACtBD,EAAO,GAAG,YAAa,IAAMC,EAAQD,CAAM,CAAC,EAC5CA,EAAO,OAAOD,CAAI,CAEnB,CAAC,EACDC,CACF,CCtBA,OAAS,gBAAAE,MAAoB,UAGtB,SAASC,EAAWC,EAGvB,CACH,KAAM,QAAQ,IAAI,gBAClB,IAAK,QAAQ,IAAI,cAClB,EAAG,CACF,GAAIA,EAAI,MAAQA,EAAI,IACnB,GAAI,CACH,OAAI,OAAOA,EAAI,MAAQ,UAAY,CAAC,cAAc,KAAKA,EAAI,IAAI,IAC9DA,EAAI,KAAOF,EAAaE,EAAI,IAAI,GAE7B,OAAOA,EAAI,KAAO,UAAY,CAAC,cAAc,KAAKA,EAAI,GAAG,IAC5DA,EAAI,IAAMF,EAAaE,EAAI,GAAG,GAExBA,CACR,OAASC,EAAO,CACf,QAAQ,MAAM,qBAAsBA,CAAK,CAC1C,CAGF,CCXO,SAASC,EAA2BC,EAAgB,CAE1D,GAAM,CAAE,QAAAC,EAAS,OAAAC,EAAQ,KAAAC,CAAK,EAAIH,EAAO,OAAO,QAAQ,EAExD,QAAQ,KACP,GAAGA,EAAO,IAAI,WAAWA,EAAO,IAAI,0BACpC,GAAGA,EAAO,QAAQ,MACjBE,IAAW,OACVD,EACCA,EAAQ,QAAQ,gBAAiB,EAAE,GACnC,QAAQ,IAAI,WAAa,cAAgB,YAAc,WAE1D,IAAIE,CAAI,EACT,CAED",
6
+ "names": ["http", "https", "createServer", "options", "port", "server", "resolve", "readFileSync", "resolveSSL", "ssl", "error", "showServerListeningMessage", "server", "address", "family", "port"]
7
+ }
@@ -0,0 +1,57 @@
1
+ type CommonSchema = {
2
+ _id: string;
3
+ title?: string;
4
+ description?: string;
5
+ };
6
+ export type AbilityParamItemSchema = CommonSchema;
7
+ type AbilityParamItemsSchema = CommonSchema & {
8
+ type: "items";
9
+ items: readonly AbilityParamItemSchema[];
10
+ isInheritable?: boolean;
11
+ };
12
+ type AbilityParamNumberSchema = CommonSchema & {
13
+ type: "number";
14
+ min?: number;
15
+ max?: number;
16
+ isInheritable?: boolean;
17
+ };
18
+ export type AbilityParamSchema = AbilityParamItemsSchema | AbilityParamNumberSchema;
19
+ export type AbilitySchema = CommonSchema & {
20
+ params?: readonly AbilityParamSchema[];
21
+ abilities?: AbilitiesSchema;
22
+ isInheritable?: boolean;
23
+ top?: boolean;
24
+ };
25
+ export type AbilitiesSchema = readonly AbilitySchema[];
26
+ type SettleParam<PS extends AbilityParamSchema> = PS extends AbilityParamNumberSchema ? number : PS extends AbilityParamItemsSchema ? PS["items"][number]["_id"][] : never;
27
+ type SettleParams<A extends AbilitySchema> = A["params"] extends readonly AbilityParamSchema[] ? {
28
+ [P in A["params"][number] as P["_id"]]: SettleParam<P>;
29
+ } : never;
30
+ type SettleSubAbilities<A extends AbilitySchema> = A["abilities"] extends AbilitiesSchema ? Partial<{
31
+ [SA in A["abilities"][number] as SA["top"] extends true ? never : SA["_id"]]: SettleAbility<SA>;
32
+ }> : never;
33
+ type SettleAbility<A extends AbilitySchema> = A extends {
34
+ params: any;
35
+ } ? A extends {
36
+ abilities: any;
37
+ } ? SettleParams<A> & SettleSubAbilities<A> : SettleParams<A> : A extends {
38
+ abilities: any;
39
+ } ? SettleSubAbilities<A> : true;
40
+ type SettleTopLevelAbility<A extends AbilitySchema> = {
41
+ [K in A["_id"]]: SettleAbility<A>;
42
+ };
43
+ type TakeAbilitySchema<A extends AbilitySchema, ForceTopLevel = false> = (A["abilities"] extends AbilitiesSchema ? ScanAbilitySchemas<A["abilities"]> : object) & (ForceTopLevel extends true ? SettleTopLevelAbility<A> : A["top"] extends true ? SettleTopLevelAbility<A> : object);
44
+ export type ScanAbilitySchemas<AS extends AbilitiesSchema, ForceTopLevel = false> = Partial<AS extends readonly [infer Head extends AbilitySchema, ...infer Tail extends AbilitiesSchema] ? ScanAbilitySchemas<Tail, ForceTopLevel> & TakeAbilitySchema<Head, ForceTopLevel> : object>;
45
+ type BasisAbilities = {
46
+ login?: {
47
+ sessionsLimit: number;
48
+ };
49
+ inSite?: {
50
+ users?: {
51
+ roles?: true;
52
+ };
53
+ };
54
+ };
55
+ export type Abilities<AS extends AbilitiesSchema> = BasisAbilities & ScanAbilitySchemas<AS, true>;
56
+ export {};
57
+ //# sourceMappingURL=abilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abilities.d.ts","sourceRoot":"","sources":["../../../src/common/types/abilities.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ export type * from "./abilities";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "../common";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/frontend/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,3 +1,4 @@
1
1
  export * from "./backend";
2
2
  export * from "./common";
3
3
  export * from "./frontend";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "insite-common",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "description": "inSite common things",
5
5
  "type": "module",
6
- "main": "./lib/index.ts",
7
- "module": "./lib/index.ts",
6
+ "main": "./dist/common/index.js",
7
+ "module": "./dist/common/index.js",
8
8
  "exports": {
9
- ".": "./lib/common/index.ts",
10
- "./frontend": "./lib/frontend/index.ts",
11
- "./backend": "./lib/backend/index.ts"
9
+ ".": "./dist/common/index.js",
10
+ "./frontend": "./dist/frontend/index.js",
11
+ "./backend": "./dist/backend/index.js"
12
12
  },
13
13
  "packageManager": "bun@1.2.2",
14
14
  "scripts": {
15
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "test": "echo \"Error: no test specified\" && exit 1",
16
+ "build": "bun .conveyer.js",
17
+ "postbuild": "tsc -p ."
16
18
  },
17
19
  "repository": {
18
20
  "type": "git",
@@ -25,11 +27,12 @@
25
27
  "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
26
28
  "license": "MIT",
27
29
  "devDependencies": {
28
- "@nesvet/eslint-config": "^2.0.47",
30
+ "@nesvet/conveyer": "^2.4.3",
31
+ "@nesvet/eslint-config": "^2.0.48",
29
32
  "typescript": "^5.7.3"
30
33
  },
31
34
  "peerDependencies": {
32
- "insite-http": "^2.1.1",
33
- "insite-ws": "^2.1.1"
35
+ "insite-http": "^2.1.5",
36
+ "insite-ws": "^2.1.4"
34
37
  }
35
38
  }
@@ -1,23 +0,0 @@
1
- import http from "node:http";
2
- import https from "node:https";
3
-
4
-
5
- export function createServer(options: http.ServerOptions): http.Server;
6
- export function createServer(options: https.ServerOptions): https.Server;
7
- export function createServer(options: http.ServerOptions, port: number | string): Promise<http.Server>;
8
- export function createServer(options: https.ServerOptions, port: number | string): Promise<https.Server>;
9
- export function createServer(options: http.ServerOptions | https.ServerOptions, port?: number | string) {
10
-
11
- const server =
12
- ("key" in options && "cert" in options) ?
13
- https.createServer(options) :
14
- http.createServer(options);
15
-
16
- return port ?
17
- new Promise(resolve => {
18
- server.on("listening", () => resolve(server));
19
- server.listen(port);
20
-
21
- }) :
22
- server;
23
- }
@@ -1,26 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
-
3
-
4
- export function resolveSSL(ssl: {
5
- cert: Buffer<ArrayBufferLike> | string;
6
- key: Buffer<ArrayBufferLike> | string;
7
- } = {
8
- cert: process.env.INSITE_SSL_CERT!,
9
- key: process.env.INSITE_SSL_KEY!
10
- }) {
11
- if (ssl.cert && ssl.key)
12
- try {
13
- if (typeof ssl.cert == "string" && !/^-{3,}BEGIN/.test(ssl.cert))
14
- ssl.cert = readFileSync(ssl.cert);
15
-
16
- if (typeof ssl.key == "string" && !/^-{3,}BEGIN/.test(ssl.key))
17
- ssl.key = readFileSync(ssl.key);
18
-
19
- return ssl;
20
- } catch (error) {
21
- console.error("SSL resolve error:", error);
22
- }
23
-
24
- return undefined;// eslint-disable-line unicorn/no-useless-undefined
25
- }
26
-
@@ -1,29 +0,0 @@
1
- import type http from "node:http";
2
- import type https from "node:https";
3
- import type { AddressInfo } from "node:net";
4
-
5
-
6
- type Server = {
7
- icon: string;
8
- name: string;
9
- protocol: string;
10
- server: http.Server | https.Server;
11
- };
12
-
13
-
14
- export function showServerListeningMessage(server: Server) {
15
-
16
- const { address, family, port } = server.server.address() as AddressInfo;
17
-
18
- console.info(
19
- `${server.icon} inSite ${server.name} Server is listening on`,
20
- `${server.protocol}://${
21
- family === "IPv4" ?
22
- address : (
23
- address.replace(/^::(?:ffff:)?/, "") ||
24
- process.env.NODE_ENV === "development" ? "localhost" : "127.0.0.1"
25
- )
26
- }:${port}`
27
- );
28
-
29
- }
@@ -1 +0,0 @@
1
- export type * from "./types";
@@ -1,99 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
-
3
-
4
- type CommonSchema = {
5
- _id: string;
6
- title?: string;
7
- description?: string;
8
- };
9
-
10
- export type AbilityParamItemSchema = CommonSchema;
11
-
12
- type AbilityParamItemsSchema = CommonSchema & {
13
- type: "items";
14
- items: readonly AbilityParamItemSchema[];
15
- isInheritable?: boolean;
16
- };
17
-
18
- type AbilityParamNumberSchema = CommonSchema & {
19
- type: "number";
20
- min?: number;
21
- max?: number;
22
- isInheritable?: boolean;
23
- };
24
-
25
- export type AbilityParamSchema = AbilityParamItemsSchema | AbilityParamNumberSchema;
26
-
27
- export type AbilitySchema = CommonSchema & {
28
- params?: readonly AbilityParamSchema[];
29
- abilities?: AbilitiesSchema;
30
- isInheritable?: boolean;
31
- top?: boolean;
32
- };
33
-
34
- export type AbilitiesSchema = readonly AbilitySchema[];
35
-
36
-
37
- type SettleParam<PS extends AbilityParamSchema> =
38
- PS extends AbilityParamNumberSchema ?
39
- number :
40
- PS extends AbilityParamItemsSchema ?
41
- PS["items"][number]["_id"][] :
42
- never;
43
-
44
- type SettleParams<A extends AbilitySchema> =
45
- A["params"] extends readonly AbilityParamSchema[] ?
46
- { [P in A["params"][number] as P["_id"]]: SettleParam<P> } :
47
- never;
48
-
49
- type SettleSubAbilities<A extends AbilitySchema> =
50
- A["abilities"] extends AbilitiesSchema ?
51
- Partial<{ [SA in A["abilities"][number] as SA["top"] extends true ? never : SA["_id"]]: SettleAbility<SA> }> :
52
- never;
53
-
54
- type SettleAbility<A extends AbilitySchema> =
55
- A extends { params: any } ?
56
- A extends { abilities: any } ?
57
- SettleParams<A> & SettleSubAbilities<A> :
58
- SettleParams<A> :
59
- A extends { abilities: any } ?
60
- SettleSubAbilities<A> :
61
- true;
62
-
63
-
64
- type SettleTopLevelAbility<A extends AbilitySchema> = { [K in A["_id"]]: SettleAbility<A> };
65
-
66
- type TakeAbilitySchema<A extends AbilitySchema, ForceTopLevel = false> =
67
- (
68
- A["abilities"] extends AbilitiesSchema ?
69
- ScanAbilitySchemas<A["abilities"]> :
70
- object
71
- ) & (
72
- ForceTopLevel extends true ?
73
- SettleTopLevelAbility<A> :
74
- A["top"] extends true ?
75
- SettleTopLevelAbility<A> :
76
- object
77
- );
78
-
79
- export type ScanAbilitySchemas<AS extends AbilitiesSchema, ForceTopLevel = false> =
80
- Partial<
81
- AS extends readonly [ infer Head extends AbilitySchema, ...infer Tail extends AbilitiesSchema ] ?
82
- ScanAbilitySchemas<Tail, ForceTopLevel> & TakeAbilitySchema<Head, ForceTopLevel> :
83
- object
84
- >;
85
-
86
-
87
- type BasisAbilities = {
88
- login?: {
89
- sessionsLimit: number;
90
- };
91
- inSite?: {
92
- users?: {
93
- roles?: true;
94
- };
95
- };
96
- };
97
-
98
-
99
- export type Abilities<AS extends AbilitiesSchema> = BasisAbilities & ScanAbilitySchemas<AS, true>;
@@ -1 +0,0 @@
1
- export type * from "./abilities";
@@ -1 +0,0 @@
1
- export * from "../common";