Skip to content

Commit 64e54f5

Browse files
authored
Close source sync, context commands & testing (#194)
2 parents 73dfdea + e29dd35 commit 64e54f5

452 files changed

Lines changed: 56251 additions & 14933 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/test.yml‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
node-version: [ '18', '20', '22', '24', 'latest' ]
15+
name: Node ${{ matrix.node-version }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: ${{ matrix.node-version }}
21+
# Native accelerators (zlib-sync, erlpack, ...) are optionalDependencies and may
22+
# fail to build on newer Node; that does not fail the install. sqlite3 is required
23+
# for the migration tests and builds here.
24+
- run: npm install
25+
- run: npm run test:unit

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/node_modules/
33
/config/
44
src/functions/scnx-integration.js
5+
instrument.js
56
/.vscode/
67
/.idea/

‎developer-docs/README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ Start here if you want to add a new feature as a module:
1212
- [**Slash commands**](./commands.md) - `config` / `run` / `subcommands` / `autocomplete`, registration, options.
1313
- [**Database models**](./database-models.md) - Sequelize `Model.init` pattern, `models-dir`, accessing models from
1414
events.
15+
- [**Field-level encryption**](./field-encryption.md) - the secure-storage serialization layer: which columns are
16+
protected and how to register a new sensitive field.
1517
- [**Localization**](./localization.md) - adding strings to `locales/en.json` and using `localize()`.
18+
- [**Nickname manager**](./nickname-manager.md) - the shared service for changing member nicknames without modules
19+
fighting each other.
1620

1721
## Configuration schema
1822

@@ -34,7 +38,7 @@ The string + embed format used in `allowEmbed` config fields. Canonical referenc
3438

3539
## Migration
3640

37-
- [**Migration**](./migration.md) - upgrading between major bot versions.
41+
- [**Migration**](./migration.md) - writing database migrations so schema changes reach existing installs.
3842

3943
## Validation
4044

‎developer-docs/database-models.md‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,13 @@ All standard Sequelize methods are available: `findOne`, `findAll`, `findOrCreat
6565

6666
## Migrations
6767

68-
The bot calls `sequelize.sync()` at startup, which creates missing tables and adds missing columns automatically. **It
69-
does not modify or remove existing columns.** If you change a column's type, rename it, or drop it, you have two
70-
options:
71-
72-
1. **Manual migration.** Use Sequelize's [umzug](https://github.com/sequelize/umzug) or write SQL by hand. Drop the
73-
bot's table or run `ALTER TABLE` against your database.
74-
2. **Bump the table name.** For breaking schema changes, rename `tableName` (e.g. `welcomer_User_v2`). The old table
75-
stays in place for safety; you migrate data on the side.
76-
77-
For non-trivial migrations across versions, the bot exposes `module.exports.migrationStart()` / `migrationEnd()` from
78-
`main.js` - call these around long-running migration code so SIGTERM/SIGINT defers shutdown until the migration
79-
finishes.
68+
The bot calls `sequelize.sync()` at startup, which creates missing **tables**. **It does not add columns to existing
69+
tables, nor modify or remove existing columns.** So whenever you add, rename, change, or drop a field on an existing
70+
model, ship a migration alongside it so existing installs pick up the schema change.
71+
72+
Migrations are file-based and run automatically on boot by an [Umzug](https://github.com/sequelize/umzug)-based runner -
73+
you drop a file into your module's `migrations/` directory and the runner discovers it, applies it once, tracks it, and
74+
backs up the affected tables first. See [migration.md](./migration.md) for the full guide.
8075

8176
## Associations
8277

‎developer-docs/field-encryption.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Field-level encryption (secure storage)
2+
3+
As part of our ongoing security and privacy work, the bot has an additional layer of protection for
4+
the most sensitive user data: field-level encryption. Selected database columns are encrypted at the
5+
application level, so sensitive fields stay protected even when someone has direct database access
6+
(for example, a technician reviewing a database for support or debugging). It is an extra safeguard
7+
layered on top of the broader security posture.
8+
9+
## What it means for the open-source build
10+
11+
In this repository the feature ships as a thin serialization wrapper with a passthrough crypto stub:
12+
13+
- Self-hosted instances and the test suite run with no key and no configuration. Nothing to set up.
14+
- The registered columns are declared `TEXT`. The hooks serialize their JSON and integer values into
15+
that text on write and parse them back on read, so your model code keeps working with plain objects
16+
and numbers.
17+
- The actual encryption is injected only on the managed backend. You never need a key locally, and the
18+
encryption is a safe no-op here.
19+
20+
The wrapper lives in `src/functions/secure-storage/`:
21+
22+
- `fields.js` lists every protected column (the source of truth for what is secured).
23+
- `hooks.js` registers the serialization hooks on each model.
24+
- `fieldCrypto.js` is the passthrough stub the managed backend replaces.
25+
26+
## Contributor rules
27+
28+
If you write or change a module:
29+
30+
- **Keep `TEXT` columns as `TEXT`.** The hooks serialize JSON and integers into them; changing the
31+
type breaks reads and writes.
32+
- **Adding a sensitive free-text or PII field?** Declare it `TEXT` and register it in
33+
`src/functions/secure-storage/fields.js` with its type (`string`, `json`, or `int`). Serialization
34+
then happens automatically and the encryption is a safe no-op locally.
35+
- **Do not register columns used in `WHERE`, `ORDER`, indexes, unique constraints, or aggregates.**
36+
Encrypting those would break lookups. IDs, foreign keys, enums, booleans, counters, timestamps, and
37+
external resource references stay as they are.
38+
- **You never need a key.** Encryption activates only on the managed backend.
39+
40+
We update the existing fields of community modules when this requirement changes, so you normally do
41+
not have to touch anything unless you are adding a new sensitive field.

0 commit comments

Comments
 (0)