@geenius/tools 0.1.0 → 0.3.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/package.json +62 -3
- package/packages/convex/shared/README.md +1 -1
- package/packages/devtools/dist/index.d.ts +204 -0
- package/packages/devtools/dist/index.js +186 -0
- package/packages/devtools/dist/index.js.map +1 -0
- package/packages/devtools/react/README.md +1 -1
- package/packages/devtools/solidjs/README.md +1 -1
- package/packages/devtools/solidjs/dist/index.js +1830 -0
- package/packages/devtools/solidjs/dist/index.js.map +1 -0
- package/packages/env/dist/index.d.ts +151 -0
- package/packages/env/dist/index.js +93 -0
- package/packages/env/dist/index.js.map +1 -0
- package/packages/errors/dist/index.d.ts +177 -0
- package/packages/errors/dist/index.js +187 -0
- package/packages/errors/dist/index.js.map +1 -0
- package/packages/errors/react/README.md +1 -1
- package/packages/errors/solidjs/README.md +1 -1
- package/packages/logger/dist/index.d.ts +171 -0
- package/packages/logger/dist/index.js +216 -0
- package/packages/logger/dist/index.js.map +1 -0
- package/packages/logger/react/README.md +1 -1
- package/packages/logger/solidjs/README.md +1 -1
- package/packages/perf/dist/index.d.ts +168 -0
- package/packages/perf/dist/index.js +265 -0
- package/packages/perf/dist/index.js.map +1 -0
- package/packages/perf/react/README.md +1 -1
- package/packages/perf/solidjs/README.md +1 -1
- package/packages/shared/dist/index.d.ts +253 -0
- package/packages/shared/dist/index.js +278 -0
- package/packages/shared/dist/index.js.map +1 -0
- package/.changeset/config.json +0 -11
- package/.env.example +0 -2
- package/.github/CODEOWNERS +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -16
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -11
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -10
- package/.github/dependabot.yml +0 -11
- package/.github/workflows/ci.yml +0 -23
- package/.github/workflows/release.yml +0 -29
- package/.node-version +0 -1
- package/.nvmrc +0 -1
- package/.prettierrc +0 -7
- package/.project/ACCOUNT.yaml +0 -4
- package/.project/IDEAS.yaml +0 -7
- package/.project/PROJECT.yaml +0 -11
- package/.project/ROADMAP.yaml +0 -15
- package/CODE_OF_CONDUCT.md +0 -26
- package/CONTRIBUTING.md +0 -69
- package/SECURITY.md +0 -18
- package/SUPPORT.md +0 -14
- package/packages/convex/shared/package.json +0 -42
- package/packages/convex/shared/src/audit/index.ts +0 -5
- package/packages/convex/shared/src/audit/presets.ts +0 -165
- package/packages/convex/shared/src/audit/schema.ts +0 -85
- package/packages/convex/shared/src/audit/write.ts +0 -102
- package/packages/convex/shared/src/extract.ts +0 -75
- package/packages/convex/shared/src/index.ts +0 -41
- package/packages/convex/shared/src/messages.ts +0 -45
- package/packages/convex/shared/src/security.ts +0 -112
- package/packages/convex/shared/src/throw.ts +0 -184
- package/packages/convex/shared/src/types.ts +0 -57
- package/packages/convex/shared/src/utils.ts +0 -58
- package/packages/convex/shared/tsconfig.json +0 -28
- package/packages/convex/shared/tsup.config.ts +0 -12
- package/packages/devtools/package.json +0 -27
- package/packages/devtools/react/package.json +0 -53
- package/packages/devtools/react/src/components/DesignPreview.tsx +0 -59
- package/packages/devtools/react/src/components/DesignSwitcherDropdown.tsx +0 -99
- package/packages/devtools/react/src/components/DevSidebar.tsx +0 -247
- package/packages/devtools/react/src/components/DevToolbar.tsx +0 -242
- package/packages/devtools/react/src/components/GitHubIssueDialog.tsx +0 -402
- package/packages/devtools/react/src/components/InspectorOverlay.tsx +0 -312
- package/packages/devtools/react/src/components/PageLoadWaterfall.tsx +0 -144
- package/packages/devtools/react/src/components/PerformancePanel.tsx +0 -330
- package/packages/devtools/react/src/context/DevModeContext.tsx +0 -226
- package/packages/devtools/react/src/context/PerformanceContext.tsx +0 -143
- package/packages/devtools/react/src/data/designs.ts +0 -13
- package/packages/devtools/react/src/hooks/useGitHubLabels.ts +0 -47
- package/packages/devtools/react/src/hooks/useVirtualList.ts +0 -124
- package/packages/devtools/react/src/index.ts +0 -77
- package/packages/devtools/react/src/panels/ConvexSpy.tsx +0 -130
- package/packages/devtools/react/src/panels/DatabaseSeeder.tsx +0 -116
- package/packages/devtools/react/src/panels/DevModePhase2.tsx +0 -191
- package/packages/devtools/react/src/panels/DevModePhase3.tsx +0 -234
- package/packages/devtools/react/src/panels/FeatureFlagsToggle.tsx +0 -104
- package/packages/devtools/react/src/panels/QuickRouteJump.tsx +0 -152
- package/packages/devtools/react/src/services/github-service.ts +0 -247
- package/packages/devtools/react/tsconfig.json +0 -31
- package/packages/devtools/react/tsup.config.ts +0 -18
- package/packages/devtools/solidjs/package.json +0 -49
- package/packages/devtools/solidjs/src/components/DesignPreview.tsx +0 -51
- package/packages/devtools/solidjs/src/components/DesignSwitcherDropdown.tsx +0 -95
- package/packages/devtools/solidjs/src/components/DevSidebar.tsx +0 -247
- package/packages/devtools/solidjs/src/components/DevToolbar.tsx +0 -242
- package/packages/devtools/solidjs/src/components/GitHubIssueDialog.tsx +0 -400
- package/packages/devtools/solidjs/src/components/InspectorOverlay.tsx +0 -311
- package/packages/devtools/solidjs/src/components/PageLoadWaterfall.tsx +0 -144
- package/packages/devtools/solidjs/src/components/PerformancePanel.tsx +0 -330
- package/packages/devtools/solidjs/src/context/DevModeContext.tsx +0 -216
- package/packages/devtools/solidjs/src/context/PerformanceContext.tsx +0 -135
- package/packages/devtools/solidjs/src/data/designs.ts +0 -13
- package/packages/devtools/solidjs/src/hooks/createGitHubLabels.ts +0 -47
- package/packages/devtools/solidjs/src/index.ts +0 -64
- package/packages/devtools/solidjs/src/services/github-service.ts +0 -247
- package/packages/devtools/solidjs/tsconfig.json +0 -21
- package/packages/devtools/src/index.ts +0 -377
- package/packages/devtools/tsup.config.ts +0 -12
- package/packages/env/package.json +0 -30
- package/packages/env/src/index.ts +0 -264
- package/packages/env/tsup.config.ts +0 -12
- package/packages/errors/package.json +0 -27
- package/packages/errors/react/package.json +0 -72
- package/packages/errors/react/src/analytics.ts +0 -16
- package/packages/errors/react/src/components/ErrorBoundary.tsx +0 -248
- package/packages/errors/react/src/components/ErrorDisplay.tsx +0 -328
- package/packages/errors/react/src/components/ValidationErrors.tsx +0 -102
- package/packages/errors/react/src/config.ts +0 -199
- package/packages/errors/react/src/constants.ts +0 -74
- package/packages/errors/react/src/hooks/useErrorBoundary.ts +0 -92
- package/packages/errors/react/src/hooks/useErrorHandler.ts +0 -87
- package/packages/errors/react/src/index.ts +0 -96
- package/packages/errors/react/src/types.ts +0 -102
- package/packages/errors/react/src/utils/errorMessages.ts +0 -35
- package/packages/errors/react/src/utils/errorPolicy.ts +0 -139
- package/packages/errors/react/src/utils/extractAppError.ts +0 -174
- package/packages/errors/react/src/utils/formatError.ts +0 -112
- package/packages/errors/react/tsconfig.json +0 -25
- package/packages/errors/react/tsup.config.ts +0 -24
- package/packages/errors/solidjs/package.json +0 -46
- package/packages/errors/solidjs/src/components/ErrorDisplay.tsx +0 -179
- package/packages/errors/solidjs/src/config.ts +0 -98
- package/packages/errors/solidjs/src/hooks/createErrorHandler.ts +0 -107
- package/packages/errors/solidjs/src/index.ts +0 -61
- package/packages/errors/solidjs/src/types.ts +0 -34
- package/packages/errors/solidjs/src/utils/errorPolicy.ts +0 -56
- package/packages/errors/solidjs/src/utils/extractAppError.ts +0 -94
- package/packages/errors/solidjs/src/utils/formatError.ts +0 -33
- package/packages/errors/solidjs/tsconfig.json +0 -26
- package/packages/errors/solidjs/tsup.config.ts +0 -21
- package/packages/errors/src/index.ts +0 -320
- package/packages/errors/tsup.config.ts +0 -12
- package/packages/logger/package.json +0 -27
- package/packages/logger/react/package.json +0 -46
- package/packages/logger/react/src/index.ts +0 -4
- package/packages/logger/react/src/useMetrics.ts +0 -42
- package/packages/logger/react/src/usePerformanceLog.ts +0 -61
- package/packages/logger/react/tsconfig.json +0 -31
- package/packages/logger/react/tsup.config.ts +0 -12
- package/packages/logger/solidjs/package.json +0 -45
- package/packages/logger/solidjs/src/createMetrics.ts +0 -37
- package/packages/logger/solidjs/src/createPerformanceLog.ts +0 -58
- package/packages/logger/solidjs/src/index.ts +0 -4
- package/packages/logger/solidjs/tsconfig.json +0 -32
- package/packages/logger/solidjs/tsup.config.ts +0 -12
- package/packages/logger/src/index.ts +0 -363
- package/packages/logger/tsup.config.ts +0 -12
- package/packages/perf/package.json +0 -27
- package/packages/perf/react/package.json +0 -59
- package/packages/perf/react/src/components/PerformanceDashboard.tsx +0 -257
- package/packages/perf/react/src/hooks/useMonitoredQuery.ts +0 -89
- package/packages/perf/react/src/hooks/usePerformanceMetrics.ts +0 -78
- package/packages/perf/react/src/index.ts +0 -33
- package/packages/perf/react/src/services/PerformanceMonitor.ts +0 -313
- package/packages/perf/react/src/types.ts +0 -77
- package/packages/perf/react/tsconfig.json +0 -25
- package/packages/perf/react/tsup.config.ts +0 -19
- package/packages/perf/solidjs/package.json +0 -41
- package/packages/perf/solidjs/src/components/PerformanceDashboard.tsx +0 -207
- package/packages/perf/solidjs/src/hooks/createPerformanceMetrics.ts +0 -73
- package/packages/perf/solidjs/src/index.ts +0 -31
- package/packages/perf/solidjs/src/services/PerformanceMonitor.ts +0 -134
- package/packages/perf/solidjs/src/types.ts +0 -78
- package/packages/perf/solidjs/tsconfig.json +0 -26
- package/packages/perf/solidjs/tsup.config.ts +0 -14
- package/packages/perf/src/index.ts +0 -410
- package/packages/perf/tsup.config.ts +0 -12
- package/pnpm-workspace.yaml +0 -2
package/.github/dependabot.yml
DELETED
package/.github/workflows/ci.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
on:
|
|
3
|
-
pull_request:
|
|
4
|
-
branches: [main]
|
|
5
|
-
push:
|
|
6
|
-
branches: [main]
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
check:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v4
|
|
13
|
-
- uses: pnpm/action-setup@v4
|
|
14
|
-
with:
|
|
15
|
-
version: 10
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version-file: '.nvmrc'
|
|
19
|
-
cache: 'pnpm'
|
|
20
|
-
- run: pnpm install --frozen-lockfile
|
|
21
|
-
- run: pnpm build
|
|
22
|
-
- run: pnpm lint
|
|
23
|
-
- run: pnpm test
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [main]
|
|
5
|
-
|
|
6
|
-
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
release:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
steps:
|
|
12
|
-
- uses: actions/checkout@v4
|
|
13
|
-
- uses: pnpm/action-setup@v4
|
|
14
|
-
with:
|
|
15
|
-
version: 10
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version-file: '.nvmrc'
|
|
19
|
-
cache: 'pnpm'
|
|
20
|
-
registry-url: 'https://registry.npmjs.org'
|
|
21
|
-
- run: pnpm install --frozen-lockfile
|
|
22
|
-
- run: pnpm build
|
|
23
|
-
- uses: changesets/action@v1
|
|
24
|
-
with:
|
|
25
|
-
publish: pnpm changeset publish
|
|
26
|
-
version: pnpm changeset version
|
|
27
|
-
env:
|
|
28
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
29
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.node-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
20
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
22
|
package/.prettierrc
DELETED
package/.project/ACCOUNT.yaml
DELETED
package/.project/IDEAS.yaml
DELETED
package/.project/PROJECT.yaml
DELETED
package/.project/ROADMAP.yaml
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
version: "0.1"
|
|
2
|
-
milestones:
|
|
3
|
-
- name: "v0.1.0 — Initial Release"
|
|
4
|
-
status: in-progress
|
|
5
|
-
items:
|
|
6
|
-
- "Core shared types and logic"
|
|
7
|
-
- "React hooks and components"
|
|
8
|
-
- "SolidJS primitives"
|
|
9
|
-
- "npm publishing via Changesets"
|
|
10
|
-
- name: "v0.2.0 — Stability"
|
|
11
|
-
status: planned
|
|
12
|
-
items:
|
|
13
|
-
- "Test coverage ≥ 50%"
|
|
14
|
-
- "API documentation"
|
|
15
|
-
- "Convex adapter"
|
package/CODE_OF_CONDUCT.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
|
2
|
-
|
|
3
|
-
## Our Pledge
|
|
4
|
-
|
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
6
|
-
|
|
7
|
-
## Our Standards
|
|
8
|
-
|
|
9
|
-
Examples of behavior that contributes to a positive environment:
|
|
10
|
-
- Using welcoming and inclusive language
|
|
11
|
-
- Being respectful of differing viewpoints and experiences
|
|
12
|
-
- Gracefully accepting constructive criticism
|
|
13
|
-
- Focusing on what is best for the community
|
|
14
|
-
|
|
15
|
-
Examples of unacceptable behavior:
|
|
16
|
-
- Trolling, insulting/derogatory comments, and personal or political attacks
|
|
17
|
-
- Public or private harassment
|
|
18
|
-
- Publishing others' private information without explicit permission
|
|
19
|
-
|
|
20
|
-
## Enforcement
|
|
21
|
-
|
|
22
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the project maintainers at support@geenius.app. All complaints will be reviewed and investigated.
|
|
23
|
-
|
|
24
|
-
## Attribution
|
|
25
|
-
|
|
26
|
-
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1.
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
# Contributing to @geenius-tools
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing! This guide will help you get started.
|
|
4
|
-
|
|
5
|
-
## Development Setup
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Clone the repository
|
|
9
|
-
git clone https://github.com/mxn2020/geenius-tools.git
|
|
10
|
-
cd geenius-tools
|
|
11
|
-
|
|
12
|
-
# Install dependencies
|
|
13
|
-
pnpm install
|
|
14
|
-
|
|
15
|
-
# Build all packages
|
|
16
|
-
pnpm build
|
|
17
|
-
|
|
18
|
-
# Run tests
|
|
19
|
-
pnpm test
|
|
20
|
-
|
|
21
|
-
# Lint
|
|
22
|
-
pnpm lint
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Project Structure
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
packages/
|
|
29
|
-
convex-errors/ — Convex error handling utilities
|
|
30
|
-
convex-wrappers/ — Convex function wrappers
|
|
31
|
-
devtools-react/ — React developer tools panel
|
|
32
|
-
env/ — Environment variable utilities
|
|
33
|
-
errors-react/ — React error boundaries and displays
|
|
34
|
-
errors-solidjs/ — SolidJS error handling
|
|
35
|
-
logger/ — Structured logging
|
|
36
|
-
logger-react/ — React logging hooks
|
|
37
|
-
logger-solid/ — SolidJS logging hooks
|
|
38
|
-
perf-react/ — React performance monitoring
|
|
39
|
-
perf-solidjs/ — SolidJS performance monitoring
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Contribution Workflow
|
|
43
|
-
|
|
44
|
-
1. **Fork** the repository
|
|
45
|
-
2. **Create a branch** for your change: `git checkout -b feat/my-feature`
|
|
46
|
-
3. **Make your changes** and add tests
|
|
47
|
-
4. **Ensure checks pass**: `pnpm lint && pnpm test && pnpm build`
|
|
48
|
-
5. **Commit** with a conventional message: `feat: add metrics collector`
|
|
49
|
-
6. **Push** and open a Pull Request
|
|
50
|
-
|
|
51
|
-
## Commit Convention
|
|
52
|
-
|
|
53
|
-
We follow [Conventional Commits](https://www.conventionalcommits.org/):
|
|
54
|
-
- `feat:` — New feature or utility
|
|
55
|
-
- `fix:` — Bug fix
|
|
56
|
-
- `docs:` — Documentation only
|
|
57
|
-
- `refactor:` — Code change that neither fixes a bug nor adds a feature
|
|
58
|
-
- `test:` — Adding or updating tests
|
|
59
|
-
- `chore:` — Tooling, CI, dependencies
|
|
60
|
-
|
|
61
|
-
## Code Style
|
|
62
|
-
|
|
63
|
-
- TypeScript strict mode
|
|
64
|
-
- Prettier for formatting
|
|
65
|
-
- ESLint for linting
|
|
66
|
-
|
|
67
|
-
## Questions?
|
|
68
|
-
|
|
69
|
-
Open an issue or reach out at support@geenius.app.
|
package/SECURITY.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Supported Versions
|
|
4
|
-
|
|
5
|
-
| Version | Supported |
|
|
6
|
-
|---------|-------------------|
|
|
7
|
-
| 0.0.x | ✅ Yes |
|
|
8
|
-
|
|
9
|
-
## Reporting a Vulnerability
|
|
10
|
-
|
|
11
|
-
If you discover a security vulnerability, please report it responsibly:
|
|
12
|
-
|
|
13
|
-
1. **Do NOT** open a public GitHub issue
|
|
14
|
-
2. **Email** security@geenius.app with details
|
|
15
|
-
3. Include steps to reproduce, impact assessment, and any suggested fix
|
|
16
|
-
4. You will receive a response within **48 hours**
|
|
17
|
-
|
|
18
|
-
We will coordinate disclosure and credit you (if desired) once the issue is resolved.
|
package/SUPPORT.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Support
|
|
2
|
-
|
|
3
|
-
## Getting Help
|
|
4
|
-
|
|
5
|
-
- **Documentation**: See the [README](./README.md) for usage and API reference
|
|
6
|
-
- **Issues**: [Open a GitHub issue](https://github.com/mxn2020/geenius-tools/issues) for bugs or feature requests
|
|
7
|
-
- **Discussions**: Use [GitHub Discussions](https://github.com/mxn2020/geenius-tools/discussions) for questions and community support
|
|
8
|
-
- **Email**: support@geenius.app for private inquiries
|
|
9
|
-
|
|
10
|
-
## Response Times
|
|
11
|
-
|
|
12
|
-
- **Bug reports**: Within 48 hours
|
|
13
|
-
- **Feature requests**: Reviewed weekly
|
|
14
|
-
- **Security issues**: Within 24 hours (see [SECURITY.md](./SECURITY.md))
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@geenius-tools/convex",
|
|
3
|
-
"version": "0.1.0",
|
|
4
|
-
"private": false,
|
|
5
|
-
"type": "module",
|
|
6
|
-
"description": "Typed error system for Convex applications",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"publishConfig": {
|
|
9
|
-
"access": "public"
|
|
10
|
-
},
|
|
11
|
-
"main": "./dist/index.js",
|
|
12
|
-
"module": "./dist/index.js",
|
|
13
|
-
"types": "./dist/index.d.ts",
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/index.js"
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"src"
|
|
23
|
-
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "tsup",
|
|
26
|
-
"clean": "rm -rf dist",
|
|
27
|
-
"type-check": "tsc --noEmit",
|
|
28
|
-
"prepublishOnly": "pnpm clean && pnpm build"
|
|
29
|
-
},
|
|
30
|
-
"peerDependencies": {
|
|
31
|
-
"convex": ">=1.0.0"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"convex": "^1.34.0",
|
|
35
|
-
"tsup": "^8.5.1",
|
|
36
|
-
"typescript": "~5.9.3"
|
|
37
|
-
},
|
|
38
|
-
"author": "Antigravity HQ",
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=20.0.0"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// @geenius-tools/convex-wrappers — src/audit/presets.ts
|
|
2
|
-
|
|
3
|
-
import type { AuditLogEntry } from '../types'
|
|
4
|
-
import { computeDiff } from './write'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Audit log presets — reusable patterns for common mutation audit scenarios.
|
|
8
|
-
*
|
|
9
|
-
* These return factory functions compatible with the mutation wrapper's
|
|
10
|
-
* `.audit()` builder, producing `AuditLogEntry` payloads automatically.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // In your Convex mutation:
|
|
15
|
-
* import { auditPreset } from '@geenius-tools/convex-wrappers'
|
|
16
|
-
*
|
|
17
|
-
* export const updateOrderStatus = authedMutation()
|
|
18
|
-
* .name('orders.updateStatus')
|
|
19
|
-
* .args({ orderId: v.id('orders'), status: v.string() })
|
|
20
|
-
* .audit(auditPreset.entityStatus({
|
|
21
|
-
* entityTable: 'orders',
|
|
22
|
-
* entityId: (args) => args.orderId,
|
|
23
|
-
* action: 'update_status',
|
|
24
|
-
* before: async (ctx, args) => {
|
|
25
|
-
* const order = await ctx.db.get(args.orderId)
|
|
26
|
-
* return order?.status
|
|
27
|
-
* },
|
|
28
|
-
* after: (args) => args.status,
|
|
29
|
-
* }))
|
|
30
|
-
* .handler(async (ctx, args) => { ... })
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export const auditPreset = {
|
|
34
|
-
/**
|
|
35
|
-
* Preset for status changes (before → after).
|
|
36
|
-
* Generates a diff showing `{ status: { from, to } }`.
|
|
37
|
-
*/
|
|
38
|
-
entityStatus<TArgs, TResult = unknown>(params: {
|
|
39
|
-
entityTable: string
|
|
40
|
-
entityId: (args: TArgs) => string
|
|
41
|
-
action: string
|
|
42
|
-
before?: (ctx: any, args: TArgs) => Promise<unknown> | unknown
|
|
43
|
-
after: ((args: TArgs, result: TResult) => unknown) | unknown
|
|
44
|
-
reason?: (args: TArgs) => string | undefined
|
|
45
|
-
}) {
|
|
46
|
-
return (args: TArgs) => ({
|
|
47
|
-
onSuccess: async (callParams: {
|
|
48
|
-
ctx: any
|
|
49
|
-
args: TArgs
|
|
50
|
-
result: TResult
|
|
51
|
-
requestId: string
|
|
52
|
-
userId?: string
|
|
53
|
-
user?: any
|
|
54
|
-
flags: Record<string, boolean>
|
|
55
|
-
}): Promise<Omit<AuditLogEntry, 'createdAt'> | null> => {
|
|
56
|
-
const { ctx, result, requestId, user } = callParams
|
|
57
|
-
|
|
58
|
-
const beforeVal = params.before
|
|
59
|
-
? await params.before(ctx, args)
|
|
60
|
-
: undefined
|
|
61
|
-
|
|
62
|
-
const afterVal =
|
|
63
|
-
typeof params.after === 'function'
|
|
64
|
-
? (params.after as (args: TArgs, result: TResult) => unknown)(args, result)
|
|
65
|
-
: params.after
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
actorId: user?._id,
|
|
69
|
-
role: user?.role ?? 'system',
|
|
70
|
-
actorRoles: user?.roles ?? (user?.role ? [user.role] : undefined),
|
|
71
|
-
action: params.action,
|
|
72
|
-
entityTable: params.entityTable,
|
|
73
|
-
entityId: params.entityId(args),
|
|
74
|
-
beforeJson: beforeVal === undefined ? undefined : JSON.stringify(beforeVal),
|
|
75
|
-
afterJson: afterVal === undefined ? undefined : JSON.stringify(afterVal),
|
|
76
|
-
diffJson: JSON.stringify({ status: { from: beforeVal, to: afterVal } }),
|
|
77
|
-
reason: params.reason ? params.reason(args) : undefined,
|
|
78
|
-
requestId,
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Preset for entity patches (partial updates with full before/after + diff).
|
|
86
|
-
*/
|
|
87
|
-
entityPatch<TArgs, TResult = unknown>(params: {
|
|
88
|
-
entityTable: string
|
|
89
|
-
entityId: (args: TArgs) => string
|
|
90
|
-
action: string
|
|
91
|
-
before: (ctx: any, args: TArgs) => Promise<Record<string, unknown>>
|
|
92
|
-
patch: (args: TArgs, result: TResult) => Record<string, unknown>
|
|
93
|
-
reason?: (args: TArgs) => string | undefined
|
|
94
|
-
}) {
|
|
95
|
-
return (args: TArgs) => ({
|
|
96
|
-
onSuccess: async (callParams: {
|
|
97
|
-
ctx: any
|
|
98
|
-
args: TArgs
|
|
99
|
-
result: TResult
|
|
100
|
-
requestId: string
|
|
101
|
-
userId?: string
|
|
102
|
-
user?: any
|
|
103
|
-
flags: Record<string, boolean>
|
|
104
|
-
}): Promise<Omit<AuditLogEntry, 'createdAt'> | null> => {
|
|
105
|
-
const { ctx, result, requestId, user } = callParams
|
|
106
|
-
|
|
107
|
-
const beforeObj = await params.before(ctx, args)
|
|
108
|
-
const patchObj = params.patch(args, result)
|
|
109
|
-
const afterObj = { ...beforeObj, ...patchObj }
|
|
110
|
-
const diff = computeDiff(beforeObj, afterObj)
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
actorId: user?._id,
|
|
114
|
-
role: user?.role ?? 'system',
|
|
115
|
-
actorRoles: user?.roles ?? (user?.role ? [user.role] : undefined),
|
|
116
|
-
action: params.action,
|
|
117
|
-
entityTable: params.entityTable,
|
|
118
|
-
entityId: params.entityId(args),
|
|
119
|
-
beforeJson: JSON.stringify(beforeObj),
|
|
120
|
-
afterJson: JSON.stringify(afterObj),
|
|
121
|
-
diffJson: JSON.stringify(diff),
|
|
122
|
-
reason: params.reason?.(args),
|
|
123
|
-
requestId,
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
})
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Preset for simple create/delete actions (no before/after diff needed).
|
|
131
|
-
*/
|
|
132
|
-
entityAction<TArgs>(params: {
|
|
133
|
-
entityTable: string
|
|
134
|
-
entityId: (args: TArgs) => string
|
|
135
|
-
action: string
|
|
136
|
-
description?: (args: TArgs) => string | undefined
|
|
137
|
-
reason?: (args: TArgs) => string | undefined
|
|
138
|
-
}) {
|
|
139
|
-
return (_args: TArgs) => ({
|
|
140
|
-
onSuccess: async (callParams: {
|
|
141
|
-
ctx: any
|
|
142
|
-
args: TArgs
|
|
143
|
-
result: unknown
|
|
144
|
-
requestId: string
|
|
145
|
-
userId?: string
|
|
146
|
-
user?: any
|
|
147
|
-
flags: Record<string, boolean>
|
|
148
|
-
}): Promise<Omit<AuditLogEntry, 'createdAt'> | null> => {
|
|
149
|
-
const { args, requestId, user } = callParams
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
actorId: user?._id,
|
|
153
|
-
role: user?.role ?? 'system',
|
|
154
|
-
actorRoles: user?.roles ?? (user?.role ? [user.role] : undefined),
|
|
155
|
-
action: params.action,
|
|
156
|
-
entityTable: params.entityTable,
|
|
157
|
-
entityId: params.entityId(args),
|
|
158
|
-
description: params.description?.(args),
|
|
159
|
-
reason: params.reason?.(args),
|
|
160
|
-
requestId,
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
})
|
|
164
|
-
},
|
|
165
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// @geenius-tools/convex-wrappers — src/audit/schema.ts
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Audit log table schema definition for Convex.
|
|
5
|
-
*
|
|
6
|
-
* Usage: Import and spread into your Convex schema definition.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* // convex/schema.ts
|
|
11
|
-
* import { defineSchema, defineTable } from 'convex/server'
|
|
12
|
-
* import { auditLogFields, auditLogIndexes } from '@geenius-tools/convex-wrappers/audit'
|
|
13
|
-
*
|
|
14
|
-
* export default defineSchema({
|
|
15
|
-
* auditLogs: defineTable(auditLogFields)
|
|
16
|
-
* .index('by_entity', auditLogIndexes.by_entity)
|
|
17
|
-
* .index('by_entityTable', auditLogIndexes.by_entityTable)
|
|
18
|
-
* .index('by_action', auditLogIndexes.by_action)
|
|
19
|
-
* .index('by_createdAt', auditLogIndexes.by_createdAt)
|
|
20
|
-
* .searchIndex('search_auditLogs', auditLogIndexes.search),
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { v } from 'convex/values'
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Field validators for the auditLogs table.
|
|
29
|
-
*/
|
|
30
|
-
export const auditLogFields = {
|
|
31
|
-
/** The user who performed the action */
|
|
32
|
-
actorId: v.optional(v.id('users')),
|
|
33
|
-
/** Role of the actor (e.g., 'admin', 'user', 'system') */
|
|
34
|
-
role: v.string(),
|
|
35
|
-
/** Array of roles the actor had at time of action */
|
|
36
|
-
actorRoles: v.optional(v.array(v.string())),
|
|
37
|
-
|
|
38
|
-
/** Action that was performed (e.g., 'create', 'update', 'delete') */
|
|
39
|
-
action: v.string(),
|
|
40
|
-
|
|
41
|
-
/** Table the entity belongs to */
|
|
42
|
-
entityTable: v.string(),
|
|
43
|
-
/** ID of the affected entity */
|
|
44
|
-
entityId: v.optional(v.string()),
|
|
45
|
-
/** Type classification of the entity */
|
|
46
|
-
entityType: v.optional(v.string()),
|
|
47
|
-
/** Human-readable title of the entity */
|
|
48
|
-
entityTitle: v.optional(v.string()),
|
|
49
|
-
|
|
50
|
-
/** JSON snapshot of the entity before the action */
|
|
51
|
-
beforeJson: v.optional(v.string()),
|
|
52
|
-
/** JSON snapshot of the entity after the action */
|
|
53
|
-
afterJson: v.optional(v.string()),
|
|
54
|
-
/** JSON diff of changes */
|
|
55
|
-
diffJson: v.optional(v.string()),
|
|
56
|
-
|
|
57
|
-
/** Reason for the action (e.g., admin note) */
|
|
58
|
-
reason: v.optional(v.string()),
|
|
59
|
-
/** Human-readable description */
|
|
60
|
-
description: v.optional(v.string()),
|
|
61
|
-
/** Request tracing ID */
|
|
62
|
-
requestId: v.optional(v.string()),
|
|
63
|
-
|
|
64
|
-
/** Additional context-specific metadata */
|
|
65
|
-
metadata: v.optional(v.any()),
|
|
66
|
-
|
|
67
|
-
/** ISO timestamp of when the action occurred */
|
|
68
|
-
createdAt: v.string(),
|
|
69
|
-
/** Concatenated searchable text for full-text search */
|
|
70
|
-
searchableText: v.optional(v.string()),
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Recommended indexes for the auditLogs table.
|
|
75
|
-
*/
|
|
76
|
-
export const auditLogIndexes = {
|
|
77
|
-
by_entity: ['entityTable', 'entityId'] as const,
|
|
78
|
-
by_entityTable: ['entityTable'] as const,
|
|
79
|
-
by_action: ['action'] as const,
|
|
80
|
-
by_createdAt: ['createdAt'] as const,
|
|
81
|
-
search: {
|
|
82
|
-
searchField: 'searchableText' as const,
|
|
83
|
-
filterFields: ['entityTable', 'action'] as const,
|
|
84
|
-
},
|
|
85
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// @geenius-tools/convex-wrappers — src/audit/write.ts
|
|
2
|
-
|
|
3
|
-
import type { AuditLogEntry } from '../types'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generate searchable text from an audit log entry.
|
|
7
|
-
* Concatenates key fields for full-text search indexing.
|
|
8
|
-
*/
|
|
9
|
-
export function generateSearchableText(params: {
|
|
10
|
-
action?: string
|
|
11
|
-
table?: string
|
|
12
|
-
id?: string
|
|
13
|
-
title?: string
|
|
14
|
-
description?: string
|
|
15
|
-
reason?: string
|
|
16
|
-
actorName?: string
|
|
17
|
-
[key: string]: unknown
|
|
18
|
-
}): string {
|
|
19
|
-
return [
|
|
20
|
-
params.action,
|
|
21
|
-
params.table,
|
|
22
|
-
params.id,
|
|
23
|
-
params.title,
|
|
24
|
-
params.description,
|
|
25
|
-
params.reason,
|
|
26
|
-
params.actorName,
|
|
27
|
-
]
|
|
28
|
-
.filter(Boolean)
|
|
29
|
-
.join(' ')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Write an audit log entry to the database.
|
|
34
|
-
*
|
|
35
|
-
* This is a generic helper — you pass in your Convex MutationCtx.
|
|
36
|
-
* It auto-generates `createdAt` and `searchableText` if not provided.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* import { writeAudit } from '@geenius-tools/convex-wrappers'
|
|
41
|
-
*
|
|
42
|
-
* // Inside a Convex mutation:
|
|
43
|
-
* await writeAudit(ctx, {
|
|
44
|
-
* actorId: user._id,
|
|
45
|
-
* role: 'admin',
|
|
46
|
-
* action: 'update',
|
|
47
|
-
* entityTable: 'orders',
|
|
48
|
-
* entityId: orderId,
|
|
49
|
-
* entityTitle: 'Order #123',
|
|
50
|
-
* beforeJson: JSON.stringify(before),
|
|
51
|
-
* afterJson: JSON.stringify(after),
|
|
52
|
-
* })
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export async function writeAudit(
|
|
56
|
-
ctx: { db: { insert: (table: string, doc: Record<string, unknown>) => Promise<unknown> } },
|
|
57
|
-
entry: Omit<AuditLogEntry, 'createdAt'> & { createdAt?: string; searchableText?: string },
|
|
58
|
-
): Promise<void> {
|
|
59
|
-
const createdAt = entry.createdAt ?? new Date().toISOString()
|
|
60
|
-
|
|
61
|
-
const searchableText =
|
|
62
|
-
entry.searchableText ??
|
|
63
|
-
generateSearchableText({
|
|
64
|
-
action: entry.action,
|
|
65
|
-
table: entry.entityTable,
|
|
66
|
-
id: entry.entityId,
|
|
67
|
-
title: entry.entityTitle,
|
|
68
|
-
description: entry.description,
|
|
69
|
-
reason: entry.reason,
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
await ctx.db.insert('auditLogs', {
|
|
73
|
-
...entry,
|
|
74
|
-
createdAt,
|
|
75
|
-
searchableText,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Compute a JSON diff between before and after objects.
|
|
81
|
-
* Returns an object with only the changed fields.
|
|
82
|
-
*/
|
|
83
|
-
export function computeDiff(
|
|
84
|
-
before: Record<string, unknown> | null | undefined,
|
|
85
|
-
after: Record<string, unknown> | null | undefined,
|
|
86
|
-
): Record<string, { from: unknown; to: unknown }> {
|
|
87
|
-
const diff: Record<string, { from: unknown; to: unknown }> = {}
|
|
88
|
-
const allKeys = new Set([
|
|
89
|
-
...Object.keys(before ?? {}),
|
|
90
|
-
...Object.keys(after ?? {}),
|
|
91
|
-
])
|
|
92
|
-
|
|
93
|
-
for (const key of allKeys) {
|
|
94
|
-
const fromVal = (before as Record<string, unknown>)?.[key]
|
|
95
|
-
const toVal = (after as Record<string, unknown>)?.[key]
|
|
96
|
-
if (JSON.stringify(fromVal) !== JSON.stringify(toVal)) {
|
|
97
|
-
diff[key] = { from: fromVal, to: toVal }
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return diff
|
|
102
|
-
}
|