glasswork 0.13.3 → 1.0.1
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/CHANGELOG.md +80 -0
- package/README.md +6 -2
- package/dist/auth/abilities.d.ts +9 -6
- package/dist/auth/abilities.d.ts.map +1 -1
- package/dist/auth/abilities.js +15 -19
- package/dist/auth/abilities.js.map +1 -1
- package/dist/auth/assert.d.ts +3 -3
- package/dist/auth/assert.d.ts.map +1 -1
- package/dist/auth/casl-bridge.d.ts +19 -0
- package/dist/auth/casl-bridge.d.ts.map +1 -0
- package/dist/auth/casl-bridge.js +29 -0
- package/dist/auth/casl-bridge.js.map +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/middleware.d.ts +3 -3
- package/dist/auth/middleware.d.ts.map +1 -1
- package/dist/auth/middleware.js +2 -2
- package/dist/auth/middleware.js.map +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/core/bootstrap.d.ts +0 -17
- package/dist/core/bootstrap.d.ts.map +1 -1
- package/dist/core/bootstrap.js +4 -240
- package/dist/core/bootstrap.js.map +1 -1
- package/dist/core/index.d.ts +19 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +15 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lifecycle.d.ts +7 -0
- package/dist/core/lifecycle.d.ts.map +1 -0
- package/dist/core/lifecycle.js +28 -0
- package/dist/core/lifecycle.js.map +1 -0
- package/dist/core/module-graph.d.ts +21 -0
- package/dist/core/module-graph.d.ts.map +1 -0
- package/dist/core/module-graph.js +169 -0
- package/dist/core/module-graph.js.map +1 -0
- package/dist/core/route-factory.d.ts +20 -0
- package/dist/core/route-factory.d.ts.map +1 -0
- package/dist/core/route-factory.js +2 -0
- package/dist/core/route-factory.js.map +1 -0
- package/dist/core/types.d.ts +4 -14
- package/dist/core/types.d.ts.map +1 -1
- package/dist/email/compiler/compile-templates.d.ts +3 -8
- package/dist/email/compiler/compile-templates.d.ts.map +1 -1
- package/dist/email/compiler/compile-templates.js +3 -3
- package/dist/email/compiler/compile-templates.js.map +1 -1
- package/dist/email/compiler/compiler.d.ts +5 -2
- package/dist/email/compiler/compiler.d.ts.map +1 -1
- package/dist/email/compiler/compiler.js +2 -21
- package/dist/email/compiler/compiler.js.map +1 -1
- package/dist/email/transports/ses-transport.d.ts.map +1 -1
- package/dist/email/transports/ses-transport.js +11 -18
- package/dist/email/transports/ses-transport.js.map +1 -1
- package/dist/email/webhooks/handler-factory.d.ts +1 -1
- package/dist/email/webhooks/handler-factory.js +1 -1
- package/dist/email/webhooks/notification-parser.d.ts +1 -1
- package/dist/email/webhooks/notification-parser.js +1 -1
- package/dist/email/webhooks/signature-verification.d.ts +1 -1
- package/dist/email/webhooks/signature-verification.js +1 -1
- package/dist/email/webhooks/subscription-handler.d.ts +1 -1
- package/dist/email/webhooks/subscription-handler.js +1 -1
- package/dist/hono-context.d.ts +13 -0
- package/dist/hono-context.d.ts.map +1 -0
- package/dist/hono-context.js +2 -0
- package/dist/hono-context.js.map +1 -0
- package/dist/http/index.d.ts +18 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +15 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/route-authorization.d.ts +9 -0
- package/dist/http/route-authorization.d.ts.map +1 -0
- package/dist/http/route-authorization.js +19 -0
- package/dist/http/route-authorization.js.map +1 -0
- package/dist/http/route-context.d.ts +8 -0
- package/dist/http/route-context.d.ts.map +1 -0
- package/dist/http/route-context.js +26 -0
- package/dist/http/route-context.js.map +1 -0
- package/dist/http/route-helpers.d.ts +6 -419
- package/dist/http/route-helpers.d.ts.map +1 -1
- package/dist/http/route-helpers.js +7 -462
- package/dist/http/route-helpers.js.map +1 -1
- package/dist/http/route-openapi-context.d.ts +27 -0
- package/dist/http/route-openapi-context.d.ts.map +1 -0
- package/dist/http/route-openapi-context.js +16 -0
- package/dist/http/route-openapi-context.js.map +1 -0
- package/dist/http/route-openapi.d.ts +5 -0
- package/dist/http/route-openapi.d.ts.map +1 -0
- package/dist/http/route-openapi.js +112 -0
- package/dist/http/route-openapi.js.map +1 -0
- package/dist/http/route-response.d.ts +5 -0
- package/dist/http/route-response.d.ts.map +1 -0
- package/dist/http/route-response.js +78 -0
- package/dist/http/route-response.js.map +1 -0
- package/dist/http/route-types.d.ts +93 -0
- package/dist/http/route-types.d.ts.map +1 -0
- package/dist/http/route-types.js +22 -0
- package/dist/http/route-types.js.map +1 -0
- package/dist/http/route-validation.d.ts +11 -0
- package/dist/http/route-validation.d.ts.map +1 -0
- package/dist/http/route-validation.js +24 -0
- package/dist/http/route-validation.js.map +1 -0
- package/dist/index.d.ts +7 -45
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -65
- package/dist/index.js.map +1 -1
- package/dist/jobs/drivers/eventbridge-scheduler-driver.d.ts.map +1 -1
- package/dist/jobs/drivers/eventbridge-scheduler-driver.js +1 -3
- package/dist/jobs/drivers/eventbridge-scheduler-driver.js.map +1 -1
- package/dist/jobs/drivers/sqs-driver.d.ts +1 -1
- package/dist/jobs/drivers/sqs-driver.d.ts.map +1 -1
- package/dist/jobs/drivers/sqs-driver.js +1 -3
- package/dist/jobs/drivers/sqs-driver.js.map +1 -1
- package/dist/jobs/worker.d.ts.map +1 -1
- package/dist/jobs/worker.js +3 -14
- package/dist/jobs/worker.js.map +1 -1
- package/dist/list-query/builder.d.ts +26 -5
- package/dist/list-query/builder.d.ts.map +1 -1
- package/dist/list-query/builder.js +18 -10
- package/dist/list-query/builder.js.map +1 -1
- package/dist/list-query/casl.d.ts +20 -4
- package/dist/list-query/casl.d.ts.map +1 -1
- package/dist/list-query/casl.js +3 -12
- package/dist/list-query/casl.js.map +1 -1
- package/dist/list-query/filter-value-schemas.d.ts +16 -0
- package/dist/list-query/filter-value-schemas.d.ts.map +1 -0
- package/dist/list-query/filter-value-schemas.js +46 -0
- package/dist/list-query/filter-value-schemas.js.map +1 -0
- package/dist/list-query/index.d.ts +7 -1
- package/dist/list-query/index.d.ts.map +1 -1
- package/dist/list-query/index.js +6 -2
- package/dist/list-query/index.js.map +1 -1
- package/dist/list-query/list-params.d.ts +17 -0
- package/dist/list-query/list-params.d.ts.map +1 -0
- package/dist/list-query/list-params.js +2 -0
- package/dist/list-query/list-params.js.map +1 -0
- package/dist/list-query/parse-filter-values.d.ts +21 -0
- package/dist/list-query/parse-filter-values.d.ts.map +1 -0
- package/dist/list-query/parse-filter-values.js +177 -0
- package/dist/list-query/parse-filter-values.js.map +1 -0
- package/dist/list-query/prisma-builder.d.ts.map +1 -1
- package/dist/list-query/prisma-builder.js +3 -50
- package/dist/list-query/prisma-builder.js.map +1 -1
- package/dist/list-query/prisma-executor.d.ts +63 -0
- package/dist/list-query/prisma-executor.d.ts.map +1 -0
- package/dist/list-query/prisma-executor.js +88 -0
- package/dist/list-query/prisma-executor.js.map +1 -0
- package/dist/list-query/schema-helpers.d.ts +37 -17
- package/dist/list-query/schema-helpers.d.ts.map +1 -1
- package/dist/list-query/schema-helpers.js +87 -24
- package/dist/list-query/schema-helpers.js.map +1 -1
- package/dist/list-query/sort-field-types.d.ts +21 -0
- package/dist/list-query/sort-field-types.d.ts.map +1 -0
- package/dist/list-query/sort-field-types.js +2 -0
- package/dist/list-query/sort-field-types.js.map +1 -0
- package/dist/list-query/unrestricted-schemas.d.ts +13 -0
- package/dist/list-query/unrestricted-schemas.d.ts.map +1 -0
- package/dist/list-query/unrestricted-schemas.js +9 -0
- package/dist/list-query/unrestricted-schemas.js.map +1 -0
- package/dist/list-query/validator.d.ts +2 -2
- package/dist/list-query/validator.d.ts.map +1 -1
- package/dist/observability/exception-tracking.d.ts +5 -4
- package/dist/observability/exception-tracking.d.ts.map +1 -1
- package/dist/observability/exception-tracking.js +4 -3
- package/dist/observability/exception-tracking.js.map +1 -1
- package/dist/observability/index.d.ts +8 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +8 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/pino-logger.d.ts +3 -3
- package/dist/observability/pino-logger.js +3 -3
- package/dist/observability/request-context.d.ts +4 -4
- package/dist/observability/request-context.js +4 -4
- package/package.json +93 -53
- package/dist/authorization/ability-middleware.d.ts +0 -61
- package/dist/authorization/ability-middleware.d.ts.map +0 -1
- package/dist/authorization/ability-middleware.js +0 -74
- package/dist/authorization/ability-middleware.js.map +0 -1
- package/dist/authorization/index.d.ts +0 -46
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js +0 -46
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/route-helpers.d.ts +0 -106
- package/dist/authorization/route-helpers.d.ts.map +0 -1
- package/dist/authorization/route-helpers.js +0 -136
- package/dist/authorization/route-helpers.js.map +0 -1
- package/dist/authorization/service-proxy.d.ts +0 -59
- package/dist/authorization/service-proxy.d.ts.map +0 -1
- package/dist/authorization/service-proxy.js +0 -110
- package/dist/authorization/service-proxy.js.map +0 -1
- package/dist/authorization/types.d.ts +0 -58
- package/dist/authorization/types.d.ts.map +0 -1
- package/dist/authorization/types.js +0 -7
- package/dist/authorization/types.js.map +0 -1
- package/dist/hooks/authorization-hook.d.ts +0 -100
- package/dist/hooks/authorization-hook.d.ts.map +0 -1
- package/dist/hooks/authorization-hook.js +0 -93
- package/dist/hooks/authorization-hook.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -54
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -55
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/service-hooks.d.ts +0 -82
- package/dist/hooks/service-hooks.d.ts.map +0 -1
- package/dist/hooks/service-hooks.js +0 -158
- package/dist/hooks/service-hooks.js.map +0 -1
- package/dist/hooks/types.d.ts +0 -151
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -2
- package/dist/hooks/types.js.map +0 -1
- package/dist/openapi/hooks.d.ts +0 -14
- package/dist/openapi/hooks.d.ts.map +0 -1
- package/dist/openapi/hooks.js +0 -83
- package/dist/openapi/hooks.js.map +0 -1
- package/dist/openapi/openapi-transformer.d.ts +0 -13
- package/dist/openapi/openapi-transformer.d.ts.map +0 -1
- package/dist/openapi/openapi-transformer.js +0 -87
- package/dist/openapi/openapi-transformer.js.map +0 -1
- package/dist/utils/pagination.d.ts +0 -48
- package/dist/utils/pagination.d.ts.map +0 -1
- package/dist/utils/pagination.js +0 -42
- package/dist/utils/pagination.js.map +0 -1
- package/dist/utils/serialize-dates.d.ts +0 -27
- package/dist/utils/serialize-dates.d.ts.map +0 -1
- package/dist/utils/serialize-dates.js +0 -39
- package/dist/utils/serialize-dates.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to Glasswork are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`parseFilterLiteral`**, **`parseFilterValue`**, **`parseWhereFilterValues`** — centralized filter value parsing for query params and Prisma `where` clauses
|
|
13
|
+
- **`filter-value-schemas`** — Valibot operand schemas with transforms for typed Prisma filters
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Typed filter schemas (`dateFilterSchema`, `intFilterSchema`, `numberFilterSchema`, `booleanFilterSchema`) parse string operands to Prisma types via Valibot transforms
|
|
18
|
+
- `parseWhereFilterValues` reuses those schemas with `parse()` instead of custom coercion logic
|
|
19
|
+
- List-query `where` deep copy uses `structuredClone` so parsed `Date` values are preserved
|
|
20
|
+
|
|
21
|
+
## [1.0.0] - 2026-06-10
|
|
22
|
+
|
|
23
|
+
Major release: subpath exports, dependency upgrades (CASL 7, MJML 5, Valibot 1.4, Prisma 7), Prisma list-query helpers, and internal refactors. Breaking changes when upgrading from 0.x.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **Subpath exports:** `glasswork/core`, `glasswork/http`, `glasswork/auth`, `glasswork/list-query`, `glasswork/jobs`, `glasswork/email`, `glasswork/uploads`, `glasswork/observability`
|
|
28
|
+
- **`registerAuthCasl({ createPrismaAbility })`** — register the app's Prisma ability factory at startup (same pattern as `registerCasl()` in list-query)
|
|
29
|
+
- **`RouteBinder`** and `core/route-factory.ts` — typed route-factory contract
|
|
30
|
+
- **`createPrismaListExecutor`**, **`bindPrismaListDelegate`**, **`runGroupByAggregations`**, **`resolveOrderBy`** — Prisma list-query execution helpers
|
|
31
|
+
- **`defaultOrderBy`** on `createListQuery` config — applied when the request omits `sorts`
|
|
32
|
+
- **`InferListParams`** — infer typed list params from filter/sort Valibot schemas
|
|
33
|
+
- **`intFilterSchema`** and **`unrestrictedWhereSchema`** — additional list-query schema helpers
|
|
34
|
+
- **`createSortSchema`** dot-notation — nested relation sorts (e.g. `'organization.name'`)
|
|
35
|
+
- Shared test helpers under `test/helpers/` (`createTestRouter`, `buildSqsEvent`, `cradleOf`)
|
|
36
|
+
- Pack consumer smoke test (`smoke:pack`) wired into `verify`
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- **Root entry (`glasswork`)** re-exports **core + http only**; optional subsystems require explicit subpaths
|
|
41
|
+
- **Peer dependencies** tightened to tested ranges (`valibot` ^1.4, `@prisma/client` ^7, `@casl/ability` ^7, `@casl/prisma` ^2, and others — see `package.json`)
|
|
42
|
+
- **MJML 5** — template compilation is async; `compileTemplates()` API updated accordingly
|
|
43
|
+
- **CASL 7 / `@casl/prisma` 2** — `PureAbility` replaced by `Ability` / `AnyAbility`; use `accessibleBy().ofType()` for list-query scopes
|
|
44
|
+
- **Prisma CASL extension** — `createCaslExtension()` on `PrismaService` for consumer apps
|
|
45
|
+
- **Bootstrap internals** — module graph and lifecycle extracted from `bootstrap.ts`; jobs worker no longer imports bootstrap
|
|
46
|
+
- **HTTP internals** — `route-helpers.ts` split into focused modules; public `route()` / `createRoutes()` API unchanged
|
|
47
|
+
- **API reference docs** — labeled as manually curated (not TypeDoc-generated)
|
|
48
|
+
- **CI coverage job** — build `dist/` before coverage; limit coverage to TypeScript sources
|
|
49
|
+
|
|
50
|
+
### Removed
|
|
51
|
+
|
|
52
|
+
- **`html-to-text`** dependency (email plain-text generation uses a lighter path)
|
|
53
|
+
- Monolithic optional exports from the root `glasswork` barrel
|
|
54
|
+
- Redundant direct `standard-openapi` / `standard-json` dependencies (provided via `hono-openapi`)
|
|
55
|
+
|
|
56
|
+
### Migration from 0.x
|
|
57
|
+
|
|
58
|
+
1. Replace root imports with subpaths (see [Package Exports](https://glasswork.dev/getting-started/package-exports)):
|
|
59
|
+
- `defineModule`, `bootstrap`, `createConfig` → `glasswork/core`
|
|
60
|
+
- `createRoutes`, `route`, `*Exception` → `glasswork/http`
|
|
61
|
+
- Auth, jobs, email, uploads, list-query, observability → respective subpaths
|
|
62
|
+
2. At application startup:
|
|
63
|
+
```typescript
|
|
64
|
+
import { accessibleBy, createPrismaAbility } from '@casl/prisma';
|
|
65
|
+
import { registerAuthCasl } from 'glasswork/auth';
|
|
66
|
+
import { registerCasl } from 'glasswork/list-query';
|
|
67
|
+
|
|
68
|
+
registerCasl({ accessibleBy });
|
|
69
|
+
registerAuthCasl({ createPrismaAbility });
|
|
70
|
+
```
|
|
71
|
+
3. Upgrade CASL/MJML/Valibot/Prisma peers to the ranges in `package.json`
|
|
72
|
+
4. Rebuild (`pnpm build`) after install — the package ships compiled `dist/`
|
|
73
|
+
|
|
74
|
+
## [0.13.3] - 2026-05-28
|
|
75
|
+
|
|
76
|
+
Last 0.x release before the 1.0 breaking changes. Earlier 0.x history is available on [GitHub releases](https://github.com/rolandboon/glasswork/releases).
|
|
77
|
+
|
|
78
|
+
[Unreleased]: https://github.com/rolandboon/glasswork/compare/v1.0.0...HEAD
|
|
79
|
+
[1.0.0]: https://github.com/rolandboon/glasswork/compare/v0.13.3...v1.0.0
|
|
80
|
+
[0.13.3]: https://github.com/rolandboon/glasswork/compare/v0.13.2...v0.13.3
|
package/README.md
CHANGED
|
@@ -53,6 +53,8 @@ Glasswork combines the best patterns from NestJS (modules, DI, OpenAPI) with the
|
|
|
53
53
|
npm install glasswork hono awilix valibot hono-openapi
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
Glasswork 1.0 uses **subpath exports** (`glasswork/core`, `glasswork/http`, `glasswork/auth`, …). The root `glasswork` import covers core and HTTP only; optional subsystems use their own subpath. See [Package Exports](https://glasswork.dev/getting-started/package-exports).
|
|
57
|
+
|
|
56
58
|
## Quick Start
|
|
57
59
|
|
|
58
60
|
### 1. Define Your DTOs (Valibot Schemas)
|
|
@@ -75,7 +77,7 @@ export const SessionDto = object({
|
|
|
75
77
|
### 2. Create Type-Safe Routes
|
|
76
78
|
|
|
77
79
|
```typescript
|
|
78
|
-
import { createRoutes, route } from 'glasswork';
|
|
80
|
+
import { createRoutes, route } from 'glasswork/http';
|
|
79
81
|
|
|
80
82
|
export const authRoutes = createRoutes<{ authService: AuthService }>(
|
|
81
83
|
(router, { authService }) => {
|
|
@@ -99,6 +101,8 @@ export const authRoutes = createRoutes<{ authService: AuthService }>(
|
|
|
99
101
|
### 3. Write Framework-Agnostic Services
|
|
100
102
|
|
|
101
103
|
```typescript
|
|
104
|
+
import { NotFoundException } from 'glasswork/http';
|
|
105
|
+
|
|
102
106
|
// Services have zero framework coupling
|
|
103
107
|
export class AuthService {
|
|
104
108
|
constructor({ prismaService, hashService }: {
|
|
@@ -131,7 +135,7 @@ export const AuthModule = defineModule({
|
|
|
131
135
|
});
|
|
132
136
|
|
|
133
137
|
// app.ts
|
|
134
|
-
import { bootstrap } from 'glasswork';
|
|
138
|
+
import { bootstrap } from 'glasswork/core';
|
|
135
139
|
|
|
136
140
|
const { app } = bootstrap(AppModule, {
|
|
137
141
|
openapi: {
|
package/dist/auth/abilities.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { AbilityBuilder, type ForcedSubject
|
|
2
|
-
import {
|
|
1
|
+
import { AbilityBuilder, type ForcedSubject } from '@casl/ability';
|
|
2
|
+
import type { PrismaAbility } from '@casl/prisma';
|
|
3
3
|
import type { AuthUser } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Extended ability type with authorize method
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type AuthorizedAbility<TActions extends string, TSubjects extends string> = PrismaAbility<[
|
|
8
|
+
TActions,
|
|
9
|
+
TSubjects | ForcedSubject<TSubjects>
|
|
10
|
+
]> & {
|
|
8
11
|
authorize: (action: TActions, subject: TSubjects | ForcedSubject<TSubjects>, message?: string) => void;
|
|
9
|
-
}
|
|
12
|
+
};
|
|
10
13
|
/**
|
|
11
14
|
* Create a type-safe ability factory for your application.
|
|
12
15
|
*
|
|
@@ -26,8 +29,8 @@ export declare function createAbilityFactory<TSubjects extends string, TActions
|
|
|
26
29
|
* Define abilities using a declarative role-based configuration.
|
|
27
30
|
*/
|
|
28
31
|
export declare function defineRoleAbilities<TSubjects extends string, TActions extends string, TRoles extends string>(config: Record<TRoles, (ctx: {
|
|
29
|
-
can: AbilityBuilder<
|
|
30
|
-
cannot: AbilityBuilder<
|
|
32
|
+
can: AbilityBuilder<PrismaAbility<[TActions, TSubjects | ForcedSubject<TSubjects>]>>['can'];
|
|
33
|
+
cannot: AbilityBuilder<PrismaAbility<[TActions, TSubjects | ForcedSubject<TSubjects>]>>['cannot'];
|
|
31
34
|
user: AuthUser;
|
|
32
35
|
}) => void>): {
|
|
33
36
|
for(user: AuthUser): AuthorizedAbility<TActions, TSubjects>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abilities.d.ts","sourceRoot":"","sources":["../../src/auth/abilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"abilities.d.ts","sourceRoot":"","sources":["../../src/auth/abilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAAC,QAAQ,SAAS,MAAM,EAAE,SAAS,SAAS,MAAM,IAAI,aAAa,CAC9F;IAAC,QAAQ;IAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC;CAAC,CACjD,GAAG;IACF,SAAS,EAAE,CACT,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,EAC7C,OAAO,CAAC,EAAE,MAAM,KACb,IAAI,CAAC;CACX,CAAC;AAqBF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,MAAM,EACxB,QAAQ,SAAS,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,MAK1E,QAAQ,CACN,GAAG,EAAE,cAAc,wCAAY,CAAC,KAAK,CAAC,EACtC,MAAM,EAAE,cAAc,wCAAY,CAAC,QAAQ,CAAC,EAC5C,IAAI,EAAE,QAAQ,KACX,IAAI,MAED,MAAM,QAAQ,4CAOzB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,SAAS,MAAM,EACxB,QAAQ,SAAS,MAAM,EACvB,MAAM,SAAS,MAAM,EAErB,MAAM,EAAE,MAAM,CACZ,MAAM,EACN,CAAC,GAAG,EAAE;IACJ,GAAG,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAC5F,MAAM,EAAE,cAAc,CACpB,aAAa,CAAC,CAAC,QAAQ,EAAE,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAChE,CAAC,QAAQ,CAAC,CAAC;IACZ,IAAI,EAAE,QAAQ,CAAC;CAChB,KAAK,IAAI,CACX;cAKW,QAAQ;IAelB,4DAA4D;kBAC9C,MAAM,SAAQ,OAAO,CAAC,QAAQ,CAAC;EAIhD;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
package/dist/auth/abilities.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { AbilityBuilder } from '@casl/ability';
|
|
2
|
-
import { createPrismaAbility } from '@casl/prisma';
|
|
3
2
|
import { ForbiddenException } from '../http/errors.js';
|
|
3
|
+
import { getPrismaAbilityFactory } from './casl-bridge.js';
|
|
4
|
+
function attachAuthorize(ability) {
|
|
5
|
+
return Object.assign(ability, {
|
|
6
|
+
authorize(action, subject, message) {
|
|
7
|
+
// biome-ignore lint/suspicious/noExplicitAny: CASL can() accepts partial subjects; method must keep ability as `this`
|
|
8
|
+
if (!ability.can(action, subject)) {
|
|
9
|
+
throw new ForbiddenException(message ?? `You don't have permission to ${action} this resource`);
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
4
14
|
/**
|
|
5
15
|
* Create a type-safe ability factory for your application.
|
|
6
16
|
*
|
|
@@ -18,17 +28,10 @@ import { ForbiddenException } from '../http/errors.js';
|
|
|
18
28
|
export function createAbilityFactory() {
|
|
19
29
|
return function defineAbility(define) {
|
|
20
30
|
return (user) => {
|
|
31
|
+
const createPrismaAbility = getPrismaAbilityFactory();
|
|
21
32
|
const { can, cannot, build } = new AbilityBuilder(createPrismaAbility);
|
|
22
33
|
define(can, cannot, user);
|
|
23
|
-
|
|
24
|
-
return Object.assign(ability, {
|
|
25
|
-
authorize(action, subject, message) {
|
|
26
|
-
// biome-ignore lint/suspicious/noExplicitAny: CASL's can() accepts partial subjects but TypeScript types are strict
|
|
27
|
-
if (!ability.can(action, subject)) {
|
|
28
|
-
throw new ForbiddenException(message ?? `You don't have permission to ${action} this resource`);
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
});
|
|
34
|
+
return attachAuthorize(build());
|
|
32
35
|
};
|
|
33
36
|
};
|
|
34
37
|
}
|
|
@@ -38,20 +41,13 @@ export function createAbilityFactory() {
|
|
|
38
41
|
export function defineRoleAbilities(config) {
|
|
39
42
|
return {
|
|
40
43
|
for(user) {
|
|
44
|
+
const createPrismaAbility = getPrismaAbilityFactory();
|
|
41
45
|
const { can, cannot, build } = new AbilityBuilder(createPrismaAbility);
|
|
42
46
|
const roleConfig = config[user.role];
|
|
43
47
|
if (roleConfig) {
|
|
44
48
|
roleConfig({ can, cannot, user });
|
|
45
49
|
}
|
|
46
|
-
|
|
47
|
-
return Object.assign(ability, {
|
|
48
|
-
authorize(action, subject, message) {
|
|
49
|
-
// biome-ignore lint/suspicious/noExplicitAny: CASL's can() accepts partial subjects but TypeScript types are strict
|
|
50
|
-
if (!ability.can(action, subject)) {
|
|
51
|
-
throw new ForbiddenException(message ?? `You don't have permission to ${action} this resource`);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
});
|
|
50
|
+
return attachAuthorize(build());
|
|
55
51
|
},
|
|
56
52
|
/** Get ability for a specific role (useful for testing). */
|
|
57
53
|
forRole(role, user = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abilities.js","sourceRoot":"","sources":["../../src/auth/abilities.ts"],"names":[],"mappings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,EAAE,GAAG,IAAI,cAAc,CAE/C,mBAAmB,CAAC,CAAC;YAEvB,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAc,CAAC,CAAC;YAE/C,IAAI,UAAU,EAAE,CAAC;gBACf,UAAU,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC;QAClC,CAAC;QAED,4DAA4D;QAC5D,OAAO,CAAC,IAAY,EAAE,OAA0B,EAAE;YAChD,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,IAAI,EAAc,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/auth/assert.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyAbility } from '@casl/ability';
|
|
2
2
|
import { subject as caslSubject } from '@casl/ability';
|
|
3
3
|
type AuthorizableSubject = string | {
|
|
4
4
|
__caslSubjectType__?: string;
|
|
@@ -7,7 +7,7 @@ type AuthorizableSubject = string | {
|
|
|
7
7
|
* Assert that an action can be performed on a subject.
|
|
8
8
|
* Throws ForbiddenException (or Unauthorized when user missing) if not allowed.
|
|
9
9
|
*/
|
|
10
|
-
export declare function assertCan<TAbility extends
|
|
10
|
+
export declare function assertCan<TAbility extends AnyAbility>(ability: TAbility | undefined, action: string, subject: AuthorizableSubject, opts?: {
|
|
11
11
|
unauthorizedMessage?: string;
|
|
12
12
|
forbiddenMessage?: string;
|
|
13
13
|
isAuthenticated?: boolean;
|
|
@@ -15,6 +15,6 @@ export declare function assertCan<TAbility extends PureAbility>(ability: TAbilit
|
|
|
15
15
|
/**
|
|
16
16
|
* Check if an action can be performed (without throwing).
|
|
17
17
|
*/
|
|
18
|
-
export declare function can<TAbility extends
|
|
18
|
+
export declare function can<TAbility extends AnyAbility>(ability: TAbility | undefined, action: string, subject: AuthorizableSubject): boolean;
|
|
19
19
|
export { caslSubject as subject };
|
|
20
20
|
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/auth/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/auth/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AAGvD,KAAK,mBAAmB,GAAG,MAAM,GAAG;IAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,SAAS,UAAU,EACnD,OAAO,EAAE,QAAQ,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,EAC5B,IAAI,CAAC,EAAE;IAAE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5F,IAAI,CAgBN;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,QAAQ,SAAS,UAAU,EAC7C,OAAO,EAAE,QAAQ,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAGT;AAED,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { createPrismaAbility } from '@casl/prisma';
|
|
2
|
+
export type PrismaAbilityFactory = typeof createPrismaAbility;
|
|
3
|
+
/**
|
|
4
|
+
* Register CASL Prisma ability factory for auth helpers.
|
|
5
|
+
* Must be called at application startup (mirrors {@link registerCasl} in list-query).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createPrismaAbility } from '@casl/prisma';
|
|
10
|
+
* import { registerAuthCasl } from 'glasswork/auth';
|
|
11
|
+
*
|
|
12
|
+
* registerAuthCasl({ createPrismaAbility });
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerAuthCasl(options: {
|
|
16
|
+
createPrismaAbility: PrismaAbilityFactory | ((...args: never[]) => unknown);
|
|
17
|
+
}): void;
|
|
18
|
+
export declare function getPrismaAbilityFactory(): PrismaAbilityFactory;
|
|
19
|
+
//# sourceMappingURL=casl-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"casl-bridge.d.ts","sourceRoot":"","sources":["../../src/auth/casl-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,OAAO,mBAAmB,CAAC;AAM9D;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IACxC,mBAAmB,EAAE,oBAAoB,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC,CAAC;CAC7E,QAEA;AAED,wBAAgB,uBAAuB,IAAI,oBAAoB,CAW9D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const config = {
|
|
2
|
+
createPrismaAbility: null,
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Register CASL Prisma ability factory for auth helpers.
|
|
6
|
+
* Must be called at application startup (mirrors {@link registerCasl} in list-query).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createPrismaAbility } from '@casl/prisma';
|
|
11
|
+
* import { registerAuthCasl } from 'glasswork/auth';
|
|
12
|
+
*
|
|
13
|
+
* registerAuthCasl({ createPrismaAbility });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function registerAuthCasl(options) {
|
|
17
|
+
config.createPrismaAbility = options.createPrismaAbility;
|
|
18
|
+
}
|
|
19
|
+
export function getPrismaAbilityFactory() {
|
|
20
|
+
if (!config.createPrismaAbility) {
|
|
21
|
+
throw new Error('Auth CASL integration not configured. Call registerAuthCasl({ createPrismaAbility }) at application startup.\n' +
|
|
22
|
+
'Example:\n' +
|
|
23
|
+
" import { createPrismaAbility } from '@casl/prisma';\n" +
|
|
24
|
+
" import { registerAuthCasl } from 'glasswork/auth';\n" +
|
|
25
|
+
' registerAuthCasl({ createPrismaAbility });');
|
|
26
|
+
}
|
|
27
|
+
return config.createPrismaAbility;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=casl-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"casl-bridge.js","sourceRoot":"","sources":["../../src/auth/casl-bridge.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,GAAyD;IACnE,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAEhC;IACC,MAAM,CAAC,mBAAmB,GAAG,OAAO,CAAC,mBAA2C,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,gHAAgH;YAC9G,YAAY;YACZ,yDAAyD;YACzD,wDAAwD;YACxD,8CAA8C,CACjD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,mBAAmB,CAAC;AACpC,CAAC"}
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { createAbilityFactory, defineRoleAbilities, type InferAbility, } from './abilities.js';
|
|
2
2
|
export { assertCan, can, subject } from './assert.js';
|
|
3
3
|
export { type BetterAuthClient, type BetterAuthProviderConfig, createBetterAuthProvider, } from './better-auth-provider.js';
|
|
4
|
+
export { type PrismaAbilityFactory, registerAuthCasl } from './casl-bridge.js';
|
|
4
5
|
export { type AuthMiddlewareConfig, createAuthMiddleware, } from './middleware.js';
|
|
5
6
|
export type { AuthContext, AuthProvider, AuthSession, AuthUser } from './types.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,KAAK,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EACL,KAAK,oBAAoB,EACzB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/auth/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createAbilityFactory, defineRoleAbilities, } from './abilities.js';
|
|
2
2
|
export { assertCan, can, subject } from './assert.js';
|
|
3
3
|
export { createBetterAuthProvider, } from './better-auth-provider.js';
|
|
4
|
+
export { registerAuthCasl } from './casl-bridge.js';
|
|
4
5
|
export { createAuthMiddleware, } from './middleware.js';
|
|
5
6
|
//# sourceMappingURL=index.js.map
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAGL,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GAEpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAGL,wBAAwB,GACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAA6B,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EAEL,oBAAoB,GACrB,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyAbility } from '@casl/ability';
|
|
2
2
|
import type { Context, MiddlewareHandler } from 'hono';
|
|
3
3
|
import type { AuthProvider, AuthSession, AuthUser } from './types.js';
|
|
4
|
-
export interface AuthMiddlewareConfig<TUser extends AuthUser = AuthUser, TAbility extends
|
|
4
|
+
export interface AuthMiddlewareConfig<TUser extends AuthUser = AuthUser, TAbility extends AnyAbility = AnyAbility, TSession extends AuthSession = AuthSession> {
|
|
5
5
|
/** Auth provider instance. */
|
|
6
6
|
provider: AuthProvider<TUser, TSession>;
|
|
7
7
|
/** Function to build ability from user. */
|
|
@@ -26,6 +26,6 @@ type AuthorizeConfig = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Create auth middleware that validates sessions and builds abilities.
|
|
28
28
|
*/
|
|
29
|
-
export declare function createAuthMiddleware<TUser extends AuthUser = AuthUser, TAbility extends
|
|
29
|
+
export declare function createAuthMiddleware<TUser extends AuthUser = AuthUser, TAbility extends AnyAbility = AnyAbility, TSession extends AuthSession = AuthSession>(config: AuthMiddlewareConfig<TUser, TAbility, TSession>): (authorize?: AuthorizeConfig) => MiddlewareHandler;
|
|
30
30
|
export {};
|
|
31
31
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/auth/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/auth/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAQ,MAAM,MAAM,CAAC;AAG7D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtE,MAAM,WAAW,oBAAoB,CACnC,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,QAAQ,SAAS,UAAU,GAAG,UAAU,EACxC,QAAQ,SAAS,WAAW,GAAG,WAAW;IAE1C,8BAA8B;IAC9B,QAAQ,EAAE,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,2CAA2C;IAC3C,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,QAAQ,CAAC;IACxC,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qCAAqC;IACrC,YAAY,CAAC,EAAE,MAAM,QAAQ,CAAC;IAC9B,8CAA8C;IAC9C,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,GAAG;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,QAAQ,SAAS,UAAU,GAAG,UAAU,EACxC,QAAQ,SAAS,WAAW,GAAG,WAAW,EAC1C,MAAM,EAAE,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAWxB,YAAY,eAAe,KAAG,iBAAiB,CAwB/E"}
|
package/dist/auth/middleware.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ability } from '@casl/ability';
|
|
2
2
|
import { deleteCookie, getCookie } from 'hono/cookie';
|
|
3
3
|
import { ForbiddenException, UnauthorizedException } from '../http/errors.js';
|
|
4
4
|
/**
|
|
@@ -87,6 +87,6 @@ function extractBearerToken(c, headerName) {
|
|
|
87
87
|
return null;
|
|
88
88
|
}
|
|
89
89
|
function createEmptyAbility() {
|
|
90
|
-
return new
|
|
90
|
+
return new Ability([]);
|
|
91
91
|
}
|
|
92
92
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/auth/middleware.ts"],"names":[],"mappings":"
|
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ated user context available in handlers.
|
|
4
4
|
*/
|
|
@@ -45,7 +45,7 @@ export interface AuthProvider<TUser extends AuthUser = AuthUser, TSession extend
|
|
|
45
45
|
/**
|
|
46
46
|
* Auth context available in Hono handlers.
|
|
47
47
|
*/
|
|
48
|
-
export interface AuthContext<TUser extends AuthUser = AuthUser, TSession extends AuthSession = AuthSession, TAbility extends
|
|
48
|
+
export interface AuthContext<TUser extends AuthUser = AuthUser, TSession extends AuthSession = AuthSession, TAbility extends AnyAbility = AnyAbility> {
|
|
49
49
|
user: TUser | null;
|
|
50
50
|
session: TSession | null;
|
|
51
51
|
ability: TAbility;
|
package/dist/auth/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAC3B,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,QAAQ,SAAS,WAAW,GAAG,WAAW;IAE1C,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;QACtC,OAAO,EAAE,QAAQ,CAAC;QAClB,IAAI,EAAE,KAAK,CAAC;KACb,GAAG,IAAI,CAAC,CAAC;IAEV;;OAEG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD;;OAEG;IACH,cAAc,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAC1B,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,QAAQ,SAAS,WAAW,GAAG,WAAW,EAC1C,QAAQ,SAAS,UAAU,GAAG,UAAU;IAExC,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC;IACnB,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,QAAQ,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;CAC1B"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { object, string, number } from 'valibot';
|
|
13
|
-
* import { createConfig, dotenvProvider, envProvider } from 'glasswork';
|
|
13
|
+
* import { createConfig, dotenvProvider, envProvider } from 'glasswork/core';
|
|
14
14
|
*
|
|
15
15
|
* // Define schema
|
|
16
16
|
* const configSchema = object({
|
package/dist/config/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* @example
|
|
11
11
|
* ```typescript
|
|
12
12
|
* import { object, string, number } from 'valibot';
|
|
13
|
-
* import { createConfig, dotenvProvider, envProvider } from 'glasswork';
|
|
13
|
+
* import { createConfig, dotenvProvider, envProvider } from 'glasswork/core';
|
|
14
14
|
*
|
|
15
15
|
* // Define schema
|
|
16
16
|
* const configSchema = object({
|
package/dist/core/bootstrap.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AwilixContainer } from 'awilix';
|
|
2
1
|
import type { BootstrapOptions, BootstrapResult, ModuleConfig } from './types.js';
|
|
3
2
|
/**
|
|
4
3
|
* Bootstrap the application with modules.
|
|
@@ -37,20 +36,4 @@ import type { BootstrapOptions, BootstrapResult, ModuleConfig } from './types.js
|
|
|
37
36
|
* ```
|
|
38
37
|
*/
|
|
39
38
|
export declare function bootstrap(rootModule: ModuleConfig, options?: BootstrapOptions): Promise<BootstrapResult>;
|
|
40
|
-
/**
|
|
41
|
-
* Collect all modules (flatten imports recursively)
|
|
42
|
-
* @internal - exported for testing utilities
|
|
43
|
-
*/
|
|
44
|
-
export declare function collectModules(rootModule: ModuleConfig): ModuleConfig[];
|
|
45
|
-
/**
|
|
46
|
-
* Validate no circular dependencies between modules
|
|
47
|
-
* @internal - exported for testing utilities
|
|
48
|
-
*/
|
|
49
|
-
export declare function validateNoCycles(modules: ModuleConfig[]): void;
|
|
50
|
-
/**
|
|
51
|
-
* Register module providers with Awilix container
|
|
52
|
-
* @internal - exported for testing utilities
|
|
53
|
-
* @returns Array of async factory provider names that need to be resolved
|
|
54
|
-
*/
|
|
55
|
-
export declare function registerModuleProviders(module: ModuleConfig, container: AwilixContainer, logger: import('../utils/logger.js').Logger): string[];
|
|
56
39
|
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/core/bootstrap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/core/bootstrap.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAIf,YAAY,EAKb,MAAM,YAAY,CAAC;AAwBpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,SAAS,CAC7B,UAAU,EAAE,YAAY,EACxB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAgH1B"}
|