insite-common 2.3.5 → 2.5.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 +77 -4
  3. package/package.json +47 -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,86 @@
1
- # inSite common things
1
+ # insite-common
2
+
3
+ [![npm](https://img.shields.io/npm/v/insite-common)](https://www.npmjs.com/package/insite-common)
4
+
5
+ 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.
6
+
7
+ Part of [inSite](../../README.md) — used by all inSite packages.
2
8
 
3
9
  ## Installation
4
10
 
5
11
  ```sh
6
- $ npm install insite-common
12
+ npm install insite-common
7
13
  ```
8
14
 
9
- Or
15
+ Or:
10
16
 
11
17
  ```sh
12
- $ bun add insite-common
18
+ bun add insite-common
13
19
  ```
20
+
21
+ ## Entry Points
22
+
23
+ | Import | Use case |
24
+ |--------|----------|
25
+ | `insite-common` | Full access — types and backend utilities |
26
+ | `insite-common/frontend` | Client-side — types only |
27
+ | `insite-common/backend` | Server-side — types and server utilities |
28
+
29
+ ## Quick Start
30
+
31
+ ```ts
32
+ import type { AbilitiesSchema, Abilities } from "insite-common/frontend";
33
+
34
+ const abilities: AbilitiesSchema = [
35
+ { _id: "users", top: true, abilities: [{ _id: "edit" }, { _id: "view" }] }
36
+ ];
37
+ ```
38
+
39
+ ## API Reference
40
+
41
+ ### Exports
42
+
43
+ **Types** (from `insite-common`, `insite-common/frontend`, `insite-common/backend`):
44
+
45
+ | Export | Description |
46
+ |--------|-------------|
47
+ | `AbilityParamItemSchema` | Base schema for items in `items`-type parameter. Fields: `_id`, `title?`, `description?` |
48
+ | `AbilityParamSchema` | Union: Items (`type: "items"`, `items`, `isInheritable?`) or Number (`type: "number"`, `min?`, `max?`, `isInheritable?`) |
49
+ | `AbilitySchema` | Schema for single ability. Fields: `params?`, `abilities?`, `isInheritable?`, `top?` |
50
+ | `AbilitiesSchema` | `readonly AbilitySchema[]` |
51
+ | `ScanAbilitySchemas<AS, ForceTopLevel?>` | Builds `Partial` object from ability schemas |
52
+ | `Abilities<AS>` | Full abilities type; includes `login` and `inSite` plus your top-level abilities |
53
+
54
+ **Backend** (from `insite-common` or `insite-common/backend`):
55
+
56
+ | Export | Signature | Description |
57
+ |--------|-----------|-------------|
58
+ | `createServer` | `(options, port?) => http.Server \| https.Server \| Promise<...>` | Creates HTTP/HTTPS server. HTTPS when `key` and `cert` present |
59
+ | `showServerListeningMessage` | `(server: { icon, name, protocol, server }) => void` | Logs server address to console |
60
+ | `resolveSSL` | `(ssl?: { cert, key }) => { cert, key } \| undefined` | Resolves SSL from paths or env (`INSITE_SSL_CERT`, `INSITE_SSL_KEY`) |
61
+ | `getRemoteAddress` | `(request: IncomingMessage) => string` | Client IP from proxy headers or `socket.remoteAddress` |
62
+
63
+ ### createServer
64
+
65
+ | Parameter | Type | Description |
66
+ |-----------|------|-------------|
67
+ | `options` | `http.ServerOptions` \| `https.ServerOptions` | Node.js server options |
68
+ | `port` | `number` \| `string` | Optional. If provided, starts listening and returns Promise |
69
+
70
+ ### resolveSSL
71
+
72
+ | Parameter | Type | Description |
73
+ |-----------|------|-------------|
74
+ | `ssl` | `{ cert: Buffer \| string; key: Buffer \| string }` | Optional. Defaults to `INSITE_SSL_CERT` and `INSITE_SSL_KEY` env vars |
75
+
76
+ ### getRemoteAddress
77
+
78
+ Checks: `Forwarded`, `X-Forwarded-For`, `X-Real-IP`, `CF-Connecting-IP`, `True-Client-IP`. Falls back to `socket.remoteAddress`.
79
+
80
+ ## Related
81
+
82
+ - [insite-server](../server/README.md), [insite-users-server](../users-server/README.md), [insite-http](../http/README.md), and all inSite packages use insite-common
83
+
84
+ ## License
85
+
86
+ MIT
package/package.json CHANGED
@@ -1,38 +1,49 @@
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.5.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
+ "engines": {
47
+ "node": ">=20.0.0"
48
+ }
38
49
  }