insite-common 2.3.5 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +75 -4
  3. package/package.json +48 -36
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Eugene Nesvetaev
3
+ Copyright (c) 2026 Eugene Nesvetaev
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,13 +1,84 @@
1
- # inSite common things
1
+ # insite-common
2
+
3
+ Shared types and backend utilities for the inSite ecosystem. Defines ability schema for RBAC and configuration, plus server helpers for HTTP(S), SSL, and client IP resolution.
4
+
5
+ Part of [inSite](../../README.md) — used by all inSite packages.
2
6
 
3
7
  ## Installation
4
8
 
5
9
  ```sh
6
- $ npm install insite-common
10
+ npm install insite-common
7
11
  ```
8
12
 
9
- Or
13
+ Or:
10
14
 
11
15
  ```sh
12
- $ bun add insite-common
16
+ bun add insite-common
17
+ ```
18
+
19
+ ## Entry Points
20
+
21
+ | Import | Use case |
22
+ |--------|----------|
23
+ | `insite-common` | Full access — types and backend utilities |
24
+ | `insite-common/frontend` | Client-side — types only |
25
+ | `insite-common/backend` | Server-side — types and server utilities |
26
+
27
+ ## Quick Start
28
+
29
+ ```ts
30
+ import type { AbilitiesSchema, Abilities } from "insite-common/frontend";
31
+
32
+ const abilities: AbilitiesSchema = [
33
+ { _id: "users", top: true, abilities: [{ _id: "edit" }, { _id: "view" }] }
34
+ ];
13
35
  ```
36
+
37
+ ## API Reference
38
+
39
+ ### Exports
40
+
41
+ **Types** (from `insite-common`, `insite-common/frontend`, `insite-common/backend`):
42
+
43
+ | Export | Description |
44
+ |--------|-------------|
45
+ | `AbilityParamItemSchema` | Base schema for items in `items`-type parameter. Fields: `_id`, `title?`, `description?` |
46
+ | `AbilityParamSchema` | Union: Items (`type: "items"`, `items`, `isInheritable?`) or Number (`type: "number"`, `min?`, `max?`, `isInheritable?`) |
47
+ | `AbilitySchema` | Schema for single ability. Fields: `params?`, `abilities?`, `isInheritable?`, `top?` |
48
+ | `AbilitiesSchema` | `readonly AbilitySchema[]` |
49
+ | `ScanAbilitySchemas<AS, ForceTopLevel?>` | Builds `Partial` object from ability schemas |
50
+ | `Abilities<AS>` | Full abilities type; includes `login` and `inSite` plus your top-level abilities |
51
+
52
+ **Backend** (from `insite-common` or `insite-common/backend`):
53
+
54
+ | Export | Signature | Description |
55
+ |--------|-----------|-------------|
56
+ | `createServer` | `(options, port?) => http.Server \| https.Server \| Promise<...>` | Creates HTTP/HTTPS server. HTTPS when `key` and `cert` present |
57
+ | `showServerListeningMessage` | `(server: { icon, name, protocol, server }) => void` | Logs server address to console |
58
+ | `resolveSSL` | `(ssl?: { cert, key }) => { cert, key } \| undefined` | Resolves SSL from paths or env (`INSITE_SSL_CERT`, `INSITE_SSL_KEY`) |
59
+ | `getRemoteAddress` | `(request: IncomingMessage) => string` | Client IP from proxy headers or `socket.remoteAddress` |
60
+
61
+ ### createServer
62
+
63
+ | Parameter | Type | Description |
64
+ |-----------|------|-------------|
65
+ | `options` | `http.ServerOptions` \| `https.ServerOptions` | Node.js server options |
66
+ | `port` | `number` \| `string` | Optional. If provided, starts listening and returns Promise |
67
+
68
+ ### resolveSSL
69
+
70
+ | Parameter | Type | Description |
71
+ |-----------|------|-------------|
72
+ | `ssl` | `{ cert: Buffer \| string; key: Buffer \| string }` | Optional. Defaults to `INSITE_SSL_CERT` and `INSITE_SSL_KEY` env vars |
73
+
74
+ ### getRemoteAddress
75
+
76
+ Checks: `Forwarded`, `X-Forwarded-For`, `X-Real-IP`, `CF-Connecting-IP`, `True-Client-IP`. Falls back to `socket.remoteAddress`.
77
+
78
+ ## Related
79
+
80
+ - [insite-server](../server/README.md), [insite-users-server](../users-server/README.md), [insite-http](../http/README.md), and all inSite packages use insite-common
81
+
82
+ ## License
83
+
84
+ MIT
package/package.json CHANGED
@@ -1,38 +1,50 @@
1
1
  {
2
- "name": "insite-common",
3
- "version": "2.3.5",
4
- "description": "inSite common things",
5
- "type": "module",
6
- "main": "./dist/common/index.js",
7
- "module": "./dist/common/index.js",
8
- "exports": {
9
- ".": "./dist/common/index.js",
10
- "./frontend": "./dist/frontend/index.js",
11
- "./backend": "./dist/backend/index.js"
12
- },
13
- "packageManager": "bun@1.2.21",
14
- "scripts": {
15
- "test": "echo \"Error: no test specified\" && exit 1",
16
- "build": "bun .conveyer.js",
17
- "postbuild": "tsc -p ."
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/nesvet/insite-common.git"
22
- },
23
- "keywords": [
24
- "insite",
25
- "common"
26
- ],
27
- "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
28
- "license": "MIT",
29
- "devDependencies": {
30
- "@nesvet/eslint-config": "^2.1.2",
31
- "cnvr": "^2.7.2",
32
- "typescript": "^5.9.2"
33
- },
34
- "peerDependencies": {
35
- "insite-http": "^2.3.5",
36
- "insite-ws": "^2.3.5"
37
- }
2
+ "name": "insite-common",
3
+ "version": "2.4.0",
4
+ "description": "Shared types, utilities, and schemas for inSite stack",
5
+ "keywords": [
6
+ "insite",
7
+ "common",
8
+ "types",
9
+ "utilities"
10
+ ],
11
+ "homepage": "https://github.com/nesvet/insite#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/nesvet/insite/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/nesvet/insite.git",
18
+ "directory": "packages/common"
19
+ },
20
+ "funding": {
21
+ "type": "patreon",
22
+ "url": "https://www.patreon.com/nesvet"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
26
+ "type": "module",
27
+ "exports": {
28
+ ".": "./dist/common/index.js",
29
+ "./frontend": "./dist/frontend/index.js",
30
+ "./backend": "./dist/backend/index.js"
31
+ },
32
+ "main": "./dist/common/index.js",
33
+ "module": "./dist/common/index.js",
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "scripts": {
40
+ "build": "bun .conveyer.js",
41
+ "postbuild": "tsc -p .",
42
+ "clean": "rm -rf dist",
43
+ "test": "echo \"Error: no test specified\" && exit 1",
44
+ "typecheck": "tsc --noEmit"
45
+ },
46
+ "packageManager": "bun@1.3.9",
47
+ "engines": {
48
+ "node": ">=20.0.0"
49
+ }
38
50
  }