glasswork 0.13.3 → 1.0.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 (218) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +6 -2
  3. package/dist/auth/abilities.d.ts +9 -6
  4. package/dist/auth/abilities.d.ts.map +1 -1
  5. package/dist/auth/abilities.js +15 -19
  6. package/dist/auth/abilities.js.map +1 -1
  7. package/dist/auth/assert.d.ts +3 -3
  8. package/dist/auth/assert.d.ts.map +1 -1
  9. package/dist/auth/casl-bridge.d.ts +19 -0
  10. package/dist/auth/casl-bridge.d.ts.map +1 -0
  11. package/dist/auth/casl-bridge.js +29 -0
  12. package/dist/auth/casl-bridge.js.map +1 -0
  13. package/dist/auth/index.d.ts +1 -0
  14. package/dist/auth/index.d.ts.map +1 -1
  15. package/dist/auth/index.js +1 -0
  16. package/dist/auth/index.js.map +1 -1
  17. package/dist/auth/middleware.d.ts +3 -3
  18. package/dist/auth/middleware.d.ts.map +1 -1
  19. package/dist/auth/middleware.js +2 -2
  20. package/dist/auth/middleware.js.map +1 -1
  21. package/dist/auth/types.d.ts +2 -2
  22. package/dist/auth/types.d.ts.map +1 -1
  23. package/dist/config/index.d.ts +1 -1
  24. package/dist/config/index.js +1 -1
  25. package/dist/core/bootstrap.d.ts +0 -17
  26. package/dist/core/bootstrap.d.ts.map +1 -1
  27. package/dist/core/bootstrap.js +4 -240
  28. package/dist/core/bootstrap.js.map +1 -1
  29. package/dist/core/index.d.ts +19 -0
  30. package/dist/core/index.d.ts.map +1 -0
  31. package/dist/core/index.js +15 -0
  32. package/dist/core/index.js.map +1 -0
  33. package/dist/core/lifecycle.d.ts +7 -0
  34. package/dist/core/lifecycle.d.ts.map +1 -0
  35. package/dist/core/lifecycle.js +28 -0
  36. package/dist/core/lifecycle.js.map +1 -0
  37. package/dist/core/module-graph.d.ts +21 -0
  38. package/dist/core/module-graph.d.ts.map +1 -0
  39. package/dist/core/module-graph.js +169 -0
  40. package/dist/core/module-graph.js.map +1 -0
  41. package/dist/core/route-factory.d.ts +20 -0
  42. package/dist/core/route-factory.d.ts.map +1 -0
  43. package/dist/core/route-factory.js +2 -0
  44. package/dist/core/route-factory.js.map +1 -0
  45. package/dist/core/types.d.ts +4 -14
  46. package/dist/core/types.d.ts.map +1 -1
  47. package/dist/email/compiler/compile-templates.d.ts +3 -8
  48. package/dist/email/compiler/compile-templates.d.ts.map +1 -1
  49. package/dist/email/compiler/compile-templates.js +3 -3
  50. package/dist/email/compiler/compile-templates.js.map +1 -1
  51. package/dist/email/compiler/compiler.d.ts +5 -2
  52. package/dist/email/compiler/compiler.d.ts.map +1 -1
  53. package/dist/email/compiler/compiler.js +2 -21
  54. package/dist/email/compiler/compiler.js.map +1 -1
  55. package/dist/email/transports/ses-transport.d.ts.map +1 -1
  56. package/dist/email/transports/ses-transport.js +11 -18
  57. package/dist/email/transports/ses-transport.js.map +1 -1
  58. package/dist/email/webhooks/handler-factory.d.ts +1 -1
  59. package/dist/email/webhooks/handler-factory.js +1 -1
  60. package/dist/email/webhooks/notification-parser.d.ts +1 -1
  61. package/dist/email/webhooks/notification-parser.js +1 -1
  62. package/dist/email/webhooks/signature-verification.d.ts +1 -1
  63. package/dist/email/webhooks/signature-verification.js +1 -1
  64. package/dist/email/webhooks/subscription-handler.d.ts +1 -1
  65. package/dist/email/webhooks/subscription-handler.js +1 -1
  66. package/dist/hono-context.d.ts +13 -0
  67. package/dist/hono-context.d.ts.map +1 -0
  68. package/dist/hono-context.js +2 -0
  69. package/dist/hono-context.js.map +1 -0
  70. package/dist/http/index.d.ts +18 -0
  71. package/dist/http/index.d.ts.map +1 -0
  72. package/dist/http/index.js +15 -0
  73. package/dist/http/index.js.map +1 -0
  74. package/dist/http/route-authorization.d.ts +9 -0
  75. package/dist/http/route-authorization.d.ts.map +1 -0
  76. package/dist/http/route-authorization.js +19 -0
  77. package/dist/http/route-authorization.js.map +1 -0
  78. package/dist/http/route-context.d.ts +8 -0
  79. package/dist/http/route-context.d.ts.map +1 -0
  80. package/dist/http/route-context.js +26 -0
  81. package/dist/http/route-context.js.map +1 -0
  82. package/dist/http/route-helpers.d.ts +6 -419
  83. package/dist/http/route-helpers.d.ts.map +1 -1
  84. package/dist/http/route-helpers.js +7 -462
  85. package/dist/http/route-helpers.js.map +1 -1
  86. package/dist/http/route-openapi-context.d.ts +27 -0
  87. package/dist/http/route-openapi-context.d.ts.map +1 -0
  88. package/dist/http/route-openapi-context.js +16 -0
  89. package/dist/http/route-openapi-context.js.map +1 -0
  90. package/dist/http/route-openapi.d.ts +5 -0
  91. package/dist/http/route-openapi.d.ts.map +1 -0
  92. package/dist/http/route-openapi.js +112 -0
  93. package/dist/http/route-openapi.js.map +1 -0
  94. package/dist/http/route-response.d.ts +5 -0
  95. package/dist/http/route-response.d.ts.map +1 -0
  96. package/dist/http/route-response.js +78 -0
  97. package/dist/http/route-response.js.map +1 -0
  98. package/dist/http/route-types.d.ts +93 -0
  99. package/dist/http/route-types.d.ts.map +1 -0
  100. package/dist/http/route-types.js +22 -0
  101. package/dist/http/route-types.js.map +1 -0
  102. package/dist/http/route-validation.d.ts +11 -0
  103. package/dist/http/route-validation.d.ts.map +1 -0
  104. package/dist/http/route-validation.js +24 -0
  105. package/dist/http/route-validation.js.map +1 -0
  106. package/dist/index.d.ts +7 -45
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +5 -65
  109. package/dist/index.js.map +1 -1
  110. package/dist/jobs/drivers/eventbridge-scheduler-driver.d.ts.map +1 -1
  111. package/dist/jobs/drivers/eventbridge-scheduler-driver.js +1 -3
  112. package/dist/jobs/drivers/eventbridge-scheduler-driver.js.map +1 -1
  113. package/dist/jobs/drivers/sqs-driver.d.ts +1 -1
  114. package/dist/jobs/drivers/sqs-driver.d.ts.map +1 -1
  115. package/dist/jobs/drivers/sqs-driver.js +1 -3
  116. package/dist/jobs/drivers/sqs-driver.js.map +1 -1
  117. package/dist/jobs/worker.d.ts.map +1 -1
  118. package/dist/jobs/worker.js +3 -14
  119. package/dist/jobs/worker.js.map +1 -1
  120. package/dist/list-query/builder.d.ts +26 -5
  121. package/dist/list-query/builder.d.ts.map +1 -1
  122. package/dist/list-query/builder.js +13 -9
  123. package/dist/list-query/builder.js.map +1 -1
  124. package/dist/list-query/casl.d.ts +20 -4
  125. package/dist/list-query/casl.d.ts.map +1 -1
  126. package/dist/list-query/casl.js +3 -12
  127. package/dist/list-query/casl.js.map +1 -1
  128. package/dist/list-query/index.d.ts +6 -1
  129. package/dist/list-query/index.d.ts.map +1 -1
  130. package/dist/list-query/index.js +4 -1
  131. package/dist/list-query/index.js.map +1 -1
  132. package/dist/list-query/list-params.d.ts +17 -0
  133. package/dist/list-query/list-params.d.ts.map +1 -0
  134. package/dist/list-query/list-params.js +2 -0
  135. package/dist/list-query/list-params.js.map +1 -0
  136. package/dist/list-query/prisma-executor.d.ts +63 -0
  137. package/dist/list-query/prisma-executor.d.ts.map +1 -0
  138. package/dist/list-query/prisma-executor.js +88 -0
  139. package/dist/list-query/prisma-executor.js.map +1 -0
  140. package/dist/list-query/schema-helpers.d.ts +20 -3
  141. package/dist/list-query/schema-helpers.d.ts.map +1 -1
  142. package/dist/list-query/schema-helpers.js +57 -4
  143. package/dist/list-query/schema-helpers.js.map +1 -1
  144. package/dist/list-query/sort-field-types.d.ts +21 -0
  145. package/dist/list-query/sort-field-types.d.ts.map +1 -0
  146. package/dist/list-query/sort-field-types.js +2 -0
  147. package/dist/list-query/sort-field-types.js.map +1 -0
  148. package/dist/list-query/unrestricted-schemas.d.ts +13 -0
  149. package/dist/list-query/unrestricted-schemas.d.ts.map +1 -0
  150. package/dist/list-query/unrestricted-schemas.js +9 -0
  151. package/dist/list-query/unrestricted-schemas.js.map +1 -0
  152. package/dist/list-query/validator.d.ts +2 -2
  153. package/dist/list-query/validator.d.ts.map +1 -1
  154. package/dist/observability/exception-tracking.d.ts +5 -4
  155. package/dist/observability/exception-tracking.d.ts.map +1 -1
  156. package/dist/observability/exception-tracking.js +4 -3
  157. package/dist/observability/exception-tracking.js.map +1 -1
  158. package/dist/observability/index.d.ts +8 -0
  159. package/dist/observability/index.d.ts.map +1 -0
  160. package/dist/observability/index.js +8 -0
  161. package/dist/observability/index.js.map +1 -0
  162. package/dist/observability/pino-logger.d.ts +3 -3
  163. package/dist/observability/pino-logger.js +3 -3
  164. package/dist/observability/request-context.d.ts +4 -4
  165. package/dist/observability/request-context.js +4 -4
  166. package/package.json +93 -53
  167. package/dist/authorization/ability-middleware.d.ts +0 -61
  168. package/dist/authorization/ability-middleware.d.ts.map +0 -1
  169. package/dist/authorization/ability-middleware.js +0 -74
  170. package/dist/authorization/ability-middleware.js.map +0 -1
  171. package/dist/authorization/index.d.ts +0 -46
  172. package/dist/authorization/index.d.ts.map +0 -1
  173. package/dist/authorization/index.js +0 -46
  174. package/dist/authorization/index.js.map +0 -1
  175. package/dist/authorization/route-helpers.d.ts +0 -106
  176. package/dist/authorization/route-helpers.d.ts.map +0 -1
  177. package/dist/authorization/route-helpers.js +0 -136
  178. package/dist/authorization/route-helpers.js.map +0 -1
  179. package/dist/authorization/service-proxy.d.ts +0 -59
  180. package/dist/authorization/service-proxy.d.ts.map +0 -1
  181. package/dist/authorization/service-proxy.js +0 -110
  182. package/dist/authorization/service-proxy.js.map +0 -1
  183. package/dist/authorization/types.d.ts +0 -58
  184. package/dist/authorization/types.d.ts.map +0 -1
  185. package/dist/authorization/types.js +0 -7
  186. package/dist/authorization/types.js.map +0 -1
  187. package/dist/hooks/authorization-hook.d.ts +0 -100
  188. package/dist/hooks/authorization-hook.d.ts.map +0 -1
  189. package/dist/hooks/authorization-hook.js +0 -93
  190. package/dist/hooks/authorization-hook.js.map +0 -1
  191. package/dist/hooks/index.d.ts +0 -54
  192. package/dist/hooks/index.d.ts.map +0 -1
  193. package/dist/hooks/index.js +0 -55
  194. package/dist/hooks/index.js.map +0 -1
  195. package/dist/hooks/service-hooks.d.ts +0 -82
  196. package/dist/hooks/service-hooks.d.ts.map +0 -1
  197. package/dist/hooks/service-hooks.js +0 -158
  198. package/dist/hooks/service-hooks.js.map +0 -1
  199. package/dist/hooks/types.d.ts +0 -151
  200. package/dist/hooks/types.d.ts.map +0 -1
  201. package/dist/hooks/types.js +0 -2
  202. package/dist/hooks/types.js.map +0 -1
  203. package/dist/openapi/hooks.d.ts +0 -14
  204. package/dist/openapi/hooks.d.ts.map +0 -1
  205. package/dist/openapi/hooks.js +0 -83
  206. package/dist/openapi/hooks.js.map +0 -1
  207. package/dist/openapi/openapi-transformer.d.ts +0 -13
  208. package/dist/openapi/openapi-transformer.d.ts.map +0 -1
  209. package/dist/openapi/openapi-transformer.js +0 -87
  210. package/dist/openapi/openapi-transformer.js.map +0 -1
  211. package/dist/utils/pagination.d.ts +0 -48
  212. package/dist/utils/pagination.d.ts.map +0 -1
  213. package/dist/utils/pagination.js +0 -42
  214. package/dist/utils/pagination.js.map +0 -1
  215. package/dist/utils/serialize-dates.d.ts +0 -27
  216. package/dist/utils/serialize-dates.d.ts.map +0 -1
  217. package/dist/utils/serialize-dates.js +0 -39
  218. package/dist/utils/serialize-dates.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glasswork",
3
- "version": "0.13.3",
3
+ "version": "1.0.0",
4
4
  "description": "A transparent, Lambda-optimized web framework for building OpenAPI-compliant REST APIs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,12 +11,53 @@
11
11
  "import": "./dist/index.js",
12
12
  "default": "./dist/index.js"
13
13
  },
14
+ "./core": {
15
+ "types": "./dist/core/index.d.ts",
16
+ "import": "./dist/core/index.js",
17
+ "default": "./dist/core/index.js"
18
+ },
19
+ "./http": {
20
+ "types": "./dist/http/index.d.ts",
21
+ "import": "./dist/http/index.js",
22
+ "default": "./dist/http/index.js"
23
+ },
24
+ "./auth": {
25
+ "types": "./dist/auth/index.d.ts",
26
+ "import": "./dist/auth/index.js",
27
+ "default": "./dist/auth/index.js"
28
+ },
29
+ "./list-query": {
30
+ "types": "./dist/list-query/index.d.ts",
31
+ "import": "./dist/list-query/index.js",
32
+ "default": "./dist/list-query/index.js"
33
+ },
34
+ "./jobs": {
35
+ "types": "./dist/jobs/index.d.ts",
36
+ "import": "./dist/jobs/index.js",
37
+ "default": "./dist/jobs/index.js"
38
+ },
39
+ "./email": {
40
+ "types": "./dist/email/index.d.ts",
41
+ "import": "./dist/email/index.js",
42
+ "default": "./dist/email/index.js"
43
+ },
44
+ "./uploads": {
45
+ "types": "./dist/uploads/index.d.ts",
46
+ "import": "./dist/uploads/index.js",
47
+ "default": "./dist/uploads/index.js"
48
+ },
49
+ "./observability": {
50
+ "types": "./dist/observability/index.d.ts",
51
+ "import": "./dist/observability/index.js",
52
+ "default": "./dist/observability/index.js"
53
+ },
14
54
  "./package.json": "./package.json"
15
55
  },
16
56
  "files": [
17
57
  "dist",
18
58
  "README.md",
19
- "LICENSE"
59
+ "LICENSE",
60
+ "CHANGELOG.md"
20
61
  ],
21
62
  "sideEffects": false,
22
63
  "engines": {
@@ -53,7 +94,10 @@
53
94
  "lint": "biome check . --write",
54
95
  "lint:ci": "biome check .",
55
96
  "typecheck": "tsc --noEmit",
56
- "prepublishOnly": "npm run build && npm test",
97
+ "typecheck:strict": "tsc --noEmit -p tsconfig.strict.json",
98
+ "smoke:pack": "node scripts/smoke-pack-consumer.mjs",
99
+ "verify": "pnpm run typecheck && pnpm run lint:ci && pnpm run build && pnpm run test && pnpm run smoke:pack",
100
+ "prepublishOnly": "npm run verify",
57
101
  "docs:dev": "vitepress dev docs",
58
102
  "docs:build": "vitepress build docs",
59
103
  "docs:preview": "vitepress preview docs"
@@ -62,25 +106,25 @@
62
106
  "access": "public"
63
107
  },
64
108
  "peerDependencies": {
65
- "@aws-sdk/client-cloudwatch": "^3.900.0",
66
- "@aws-sdk/client-dynamodb": "^3.900.0",
67
- "@aws-sdk/client-s3": "^3.900.0",
68
- "@aws-sdk/client-scheduler": "^3.900.0",
69
- "@aws-sdk/client-sesv2": "^3.900.0",
70
- "@aws-sdk/client-sqs": "^3.900.0",
71
- "@aws-sdk/client-ssm": "^3.900.0",
72
- "@aws-sdk/lib-dynamodb": "^3.900.0",
73
- "@aws-sdk/s3-request-presigner": "^3.900.0",
74
- "@casl/ability": "^6.7.3",
75
- "@casl/prisma": "^1.4.0",
76
- "@hono/swagger-ui": "^0.5.0",
77
- "@prisma/client": "^6.0.0",
78
- "awilix": "^12.0.0",
79
- "better-auth": "^1.0.0",
80
- "dotenv": "^16.0.0",
81
- "hono": "^4.9.0",
82
- "hono-openapi": "^1.0.0",
83
- "valibot": "^1.0.0"
109
+ "@aws-sdk/client-cloudwatch": "^3.1000.0",
110
+ "@aws-sdk/client-dynamodb": "^3.1000.0",
111
+ "@aws-sdk/client-s3": "^3.1000.0",
112
+ "@aws-sdk/client-scheduler": "^3.1000.0",
113
+ "@aws-sdk/client-sesv2": "^3.1000.0",
114
+ "@aws-sdk/client-sqs": "^3.1000.0",
115
+ "@aws-sdk/client-ssm": "^3.1000.0",
116
+ "@aws-sdk/lib-dynamodb": "^3.1000.0",
117
+ "@aws-sdk/s3-request-presigner": "^3.1000.0",
118
+ "@casl/ability": "^7.0.0",
119
+ "@casl/prisma": "^2.0.0",
120
+ "@hono/swagger-ui": "^0.6.0",
121
+ "@prisma/client": "^7.0.0",
122
+ "awilix": "^13.0.0",
123
+ "better-auth": "^1.6.0",
124
+ "dotenv": "^17.0.0",
125
+ "hono": "^4.12.0",
126
+ "hono-openapi": "^1.3.0",
127
+ "valibot": "^1.4.0"
84
128
  },
85
129
  "peerDependenciesMeta": {
86
130
  "@aws-sdk/client-scheduler": {
@@ -130,47 +174,43 @@
130
174
  }
131
175
  },
132
176
  "devDependencies": {
133
- "@aws-sdk/client-cloudwatch": "^3.1001.0",
134
- "@aws-sdk/client-dynamodb": "^3.1001.0",
135
- "@aws-sdk/client-s3": "^3.1001.0",
136
- "@aws-sdk/client-scheduler": "^3.1001.0",
137
- "@aws-sdk/client-sesv2": "^3.1001.0",
138
- "@aws-sdk/client-sqs": "^3.1001.0",
139
- "@aws-sdk/client-ssm": "^3.1001.0",
140
- "@aws-sdk/lib-dynamodb": "^3.1001.0",
141
- "@aws-sdk/s3-request-presigner": "^3.1001.0",
142
- "@biomejs/biome": "^2.4.5",
143
- "@casl/ability": "^6.8.0",
144
- "@casl/prisma": "^1.6.1",
145
- "@hono/swagger-ui": "^0.5.3",
146
- "@prisma/client": "^7.4.2",
147
- "@types/aws-lambda": "^8.10.161",
148
- "@types/html-to-text": "^9.0.4",
149
- "@types/node": "^22.19.1",
150
- "@vitest/coverage-v8": "^4.0.18",
177
+ "@aws-sdk/client-cloudwatch": "^3.1065.0",
178
+ "@aws-sdk/client-dynamodb": "^3.1065.0",
179
+ "@aws-sdk/client-s3": "^3.1065.0",
180
+ "@aws-sdk/client-scheduler": "^3.1064.0",
181
+ "@aws-sdk/client-sesv2": "^3.1064.0",
182
+ "@aws-sdk/client-sqs": "^3.1064.0",
183
+ "@aws-sdk/client-ssm": "^3.1064.0",
184
+ "@aws-sdk/lib-dynamodb": "^3.1065.0",
185
+ "@aws-sdk/s3-request-presigner": "^3.1065.0",
186
+ "@biomejs/biome": "^2.4.16",
187
+ "@casl/ability": "^7.0.0",
188
+ "@casl/prisma": "^2.0.1",
189
+ "@hono/swagger-ui": "^0.6.1",
190
+ "@prisma/client": "^7.8.0",
191
+ "@types/aws-lambda": "^8.10.162",
192
+ "@types/node": "^24.13.1",
193
+ "@vitest/coverage-v8": "^4.1.8",
151
194
  "awilix": "^13.0.3",
152
- "dotenv": "^17.3.1",
153
- "hono": "^4.12.5",
195
+ "dotenv": "^17.4.2",
196
+ "hono": "^4.12.25",
154
197
  "hono-openapi": "^1.3.0",
155
- "html-to-text": "^9.0.5",
156
- "mermaid": "^11.12.3",
157
- "mjml": "^4.18.0",
198
+ "mermaid": "^11.15.0",
199
+ "mjml": "^5.3.0",
158
200
  "typescript": "^5.9.3",
159
- "valibot": "^1.2.0",
201
+ "valibot": "^1.4.1",
160
202
  "vitepress": "^1.6.4",
161
- "vitepress-plugin-llms": "^1.11.0",
203
+ "vitepress-plugin-llms": "^1.13.1",
162
204
  "vitepress-plugin-mermaid": "^2.0.17",
163
- "vitest": "^4.0.18",
164
- "vue": "^3.5.29"
205
+ "vitest": "^4.1.8",
206
+ "vue": "^3.5.35"
165
207
  },
166
208
  "dependencies": {
167
209
  "@hono/standard-validator": "^0.2.2",
168
210
  "@hono/valibot-validator": "^0.6.1",
169
- "@standard-community/standard-json": "^0.3.5",
170
- "@standard-community/standard-openapi": "^0.2.9",
171
- "@valibot/to-json-schema": "^1.5.0",
211
+ "@valibot/to-json-schema": "^1.7.1",
172
212
  "deepmerge": "^4.3.1",
173
- "nanoid": "^5.1.6",
213
+ "nanoid": "^5.1.11",
174
214
  "openapi-types": "^12.1.3"
175
215
  }
176
216
  }
@@ -1,61 +0,0 @@
1
- import type { Context, MiddlewareHandler } from 'hono';
2
- import type { AbilityConfig, BaseAbility } from './types.js';
3
- /**
4
- * Creates Hono middleware that attaches a CASL ability to the request context.
5
- *
6
- * This middleware is transparent - it exposes the CASL ability directly in the
7
- * Hono context, making it accessible to route handlers. All CASL features
8
- * remain available.
9
- *
10
- * @param config - Ability configuration with factory function
11
- * @returns Hono middleware that creates and attaches the ability
12
- *
13
- * @example
14
- * ```typescript
15
- * import { createPrismaAbility } from '@casl/prisma';
16
- * import { AbilityBuilder } from '@casl/ability';
17
- *
18
- * const abilityMiddleware = withAbility({
19
- * factory: (c) => {
20
- * const user = c.get('user');
21
- * const { can, build } = new AbilityBuilder(createPrismaAbility);
22
- *
23
- * if (user.role === 'admin') {
24
- * can('manage', 'all');
25
- * } else {
26
- * can('read', 'User', { id: user.id });
27
- * }
28
- *
29
- * return build();
30
- * }
31
- * });
32
- *
33
- * app.use('*', abilityMiddleware);
34
- * ```
35
- */
36
- export declare function withAbility<T extends BaseAbility = BaseAbility>(config: AbilityConfig<T>): MiddlewareHandler;
37
- /**
38
- * Helper to retrieve the ability from Hono context.
39
- * This provides type-safe access to the CASL ability stored by `withAbility`.
40
- *
41
- * @param context - Hono context
42
- * @param contextKey - The key used to store the ability (default: 'ability')
43
- * @returns The CASL ability instance
44
- * @throws Error if ability is not found in context
45
- *
46
- * @example
47
- * ```typescript
48
- * router.get('/users', async (c) => {
49
- * const ability = getAbility(c);
50
- *
51
- * // Use CASL ability directly
52
- * if (ability.can('read', 'User')) {
53
- * return c.json(users);
54
- * }
55
- *
56
- * return c.json({ error: 'Forbidden' }, 403);
57
- * });
58
- * ```
59
- */
60
- export declare function getAbility<T extends BaseAbility = BaseAbility>(context: Context, contextKey?: string): T;
61
- //# sourceMappingURL=ability-middleware.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ability-middleware.d.ts","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC7D,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,iBAAiB,CAYnB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC5D,OAAO,EAAE,OAAO,EAChB,UAAU,SAAY,GACrB,CAAC,CAUH"}
@@ -1,74 +0,0 @@
1
- /**
2
- * Creates Hono middleware that attaches a CASL ability to the request context.
3
- *
4
- * This middleware is transparent - it exposes the CASL ability directly in the
5
- * Hono context, making it accessible to route handlers. All CASL features
6
- * remain available.
7
- *
8
- * @param config - Ability configuration with factory function
9
- * @returns Hono middleware that creates and attaches the ability
10
- *
11
- * @example
12
- * ```typescript
13
- * import { createPrismaAbility } from '@casl/prisma';
14
- * import { AbilityBuilder } from '@casl/ability';
15
- *
16
- * const abilityMiddleware = withAbility({
17
- * factory: (c) => {
18
- * const user = c.get('user');
19
- * const { can, build } = new AbilityBuilder(createPrismaAbility);
20
- *
21
- * if (user.role === 'admin') {
22
- * can('manage', 'all');
23
- * } else {
24
- * can('read', 'User', { id: user.id });
25
- * }
26
- *
27
- * return build();
28
- * }
29
- * });
30
- *
31
- * app.use('*', abilityMiddleware);
32
- * ```
33
- */
34
- export function withAbility(config) {
35
- const contextKey = config.contextKey || 'ability';
36
- return async (c, next) => {
37
- // Create ability using factory
38
- const ability = await config.factory(c);
39
- // Store in Hono context
40
- c.set(contextKey, ability);
41
- await next();
42
- };
43
- }
44
- /**
45
- * Helper to retrieve the ability from Hono context.
46
- * This provides type-safe access to the CASL ability stored by `withAbility`.
47
- *
48
- * @param context - Hono context
49
- * @param contextKey - The key used to store the ability (default: 'ability')
50
- * @returns The CASL ability instance
51
- * @throws Error if ability is not found in context
52
- *
53
- * @example
54
- * ```typescript
55
- * router.get('/users', async (c) => {
56
- * const ability = getAbility(c);
57
- *
58
- * // Use CASL ability directly
59
- * if (ability.can('read', 'User')) {
60
- * return c.json(users);
61
- * }
62
- *
63
- * return c.json({ error: 'Forbidden' }, 403);
64
- * });
65
- * ```
66
- */
67
- export function getAbility(context, contextKey = 'ability') {
68
- const ability = context.get(contextKey);
69
- if (!ability) {
70
- throw new Error(`Ability not found in context. Did you forget to use withAbility() middleware?`);
71
- }
72
- return ability;
73
- }
74
- //# sourceMappingURL=ability-middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ability-middleware.js","sourceRoot":"","sources":["../../src/authorization/ability-middleware.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,WAAW,CACzB,MAAwB;IAExB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,SAAS,CAAC;IAElD,OAAO,KAAK,EAAE,CAAU,EAAE,IAAI,EAAE,EAAE;QAChC,+BAA+B;QAC/B,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAExC,wBAAwB;QACxB,CAAC,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,UAAU,CACxB,OAAgB,EAChB,UAAU,GAAG,SAAS;IAEtB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IAED,OAAO,OAAY,CAAC;AACtB,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Authorization module for integrating CASL with Glasswork.
3
- *
4
- * This module provides transparent integration with CASL while maintaining framework principles.
5
- *
6
- * ## Recommended Approach: Service Hooks
7
- *
8
- * Configure authorization globally using the hooks system:
9
- *
10
- * ```typescript
11
- * import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
12
- *
13
- * const authServiceMeta = defineServiceMetadata({
14
- * deleteSession: { authorize: defineAuthorize('delete', 'Session') }
15
- * });
16
- *
17
- * bootstrap(AppModule, {
18
- * serviceHooks: [authorizationHook],
19
- * serviceMetadata: { authService: authServiceMeta }
20
- * });
21
- *
22
- * // In routes - authorization happens automatically!
23
- * await services.authService.deleteSession(token);
24
- * ```
25
- *
26
- * ## Alternative: Explicit Authorization
27
- *
28
- * For fine-grained control, use explicit authorize() calls:
29
- *
30
- * ```typescript
31
- * router.delete('/sessions/:id', async (c) => {
32
- * authorize(c, 'delete', 'Session', { id: c.req.param('id') });
33
- * await sessionService.delete(c.req.param('id'));
34
- * });
35
- * ```
36
- *
37
- * @module authorization
38
- * @see https://casl.js.org/ for CASL documentation
39
- * @see HOOKS_SYSTEM.md for hooks documentation
40
- */
41
- export type { PureAbility } from '@casl/ability';
42
- export { ForbiddenError, subject } from '@casl/ability';
43
- export { getAbility, withAbility } from './ability-middleware.js';
44
- export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
45
- export type { AbilityConfig, AbilityFactory, BaseAbility } from './types.js';
46
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE7E,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * Authorization module for integrating CASL with Glasswork.
3
- *
4
- * This module provides transparent integration with CASL while maintaining framework principles.
5
- *
6
- * ## Recommended Approach: Service Hooks
7
- *
8
- * Configure authorization globally using the hooks system:
9
- *
10
- * ```typescript
11
- * import { authorizationHook, defineServiceMetadata, defineAuthorize } from 'glasswork';
12
- *
13
- * const authServiceMeta = defineServiceMetadata({
14
- * deleteSession: { authorize: defineAuthorize('delete', 'Session') }
15
- * });
16
- *
17
- * bootstrap(AppModule, {
18
- * serviceHooks: [authorizationHook],
19
- * serviceMetadata: { authService: authServiceMeta }
20
- * });
21
- *
22
- * // In routes - authorization happens automatically!
23
- * await services.authService.deleteSession(token);
24
- * ```
25
- *
26
- * ## Alternative: Explicit Authorization
27
- *
28
- * For fine-grained control, use explicit authorize() calls:
29
- *
30
- * ```typescript
31
- * router.delete('/sessions/:id', async (c) => {
32
- * authorize(c, 'delete', 'Session', { id: c.req.param('id') });
33
- * await sessionService.delete(c.req.param('id'));
34
- * });
35
- * ```
36
- *
37
- * @module authorization
38
- * @see https://casl.js.org/ for CASL documentation
39
- * @see HOOKS_SYSTEM.md for hooks documentation
40
- */
41
- export { ForbiddenError, subject } from '@casl/ability';
42
- // Ability middleware (attaches CASL abilities to context)
43
- export { getAbility, withAbility } from './ability-middleware.js';
44
- // Route helpers (explicit authorization - recommended for fine-grained control)
45
- export { accessibleWhere, authorize, can, cannot } from './route-helpers.js';
46
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAIH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxD,0DAA0D;AAC1D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAClE,gFAAgF;AAChF,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,106 +0,0 @@
1
- import type { Context } from 'hono';
2
- import type { BaseAbility } from './types.js';
3
- /**
4
- * Authorizes an action on a subject using the CASL ability from context.
5
- * Throws ForbiddenError if the action is not permitted.
6
- *
7
- * This is a thin wrapper around CASL's authorize functionality, exposing
8
- * the native CASL API while providing convenient access to the ability
9
- * stored in Hono context.
10
- *
11
- * @param context - Hono context containing the ability
12
- * @param action - CASL action (e.g., 'create', 'read', 'update', 'delete')
13
- * @param subjectType - Subject type string (e.g., 'User', 'Post')
14
- * @param subjectData - Optional subject instance data
15
- * @throws ForbiddenError from CASL if action is not permitted
16
- *
17
- * @example
18
- * ```typescript
19
- * router.delete('/sessions/:id', async (c) => {
20
- * const sessionId = c.req.param('id');
21
- * const user = c.get('user');
22
- *
23
- * // Explicit authorization - clear and obvious
24
- * authorize(c, 'delete', 'Session', { userId: user.id, sessionId });
25
- *
26
- * await sessionService.delete(sessionId);
27
- * return c.json({ success: true });
28
- * });
29
- * ```
30
- */
31
- export declare function authorize<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): void;
32
- /**
33
- * Checks if an action is permitted without throwing an error.
34
- * Returns boolean indicating if the action is allowed.
35
- *
36
- * @param context - Hono context containing the ability
37
- * @param action - CASL action
38
- * @param subjectType - Subject type string
39
- * @param subjectData - Optional subject instance data
40
- * @returns True if action is permitted, false otherwise
41
- *
42
- * @example
43
- * ```typescript
44
- * router.get('/users', async (c) => {
45
- * if (!can(c, 'read', 'User')) {
46
- * return c.json({ error: 'Forbidden' }, 403);
47
- * }
48
- *
49
- * const users = await userService.findAll();
50
- * return c.json(users);
51
- * });
52
- * ```
53
- */
54
- export declare function can<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
55
- /**
56
- * Checks if an action is forbidden (opposite of can).
57
- *
58
- * @param context - Hono context containing the ability
59
- * @param action - CASL action
60
- * @param subjectType - Subject type string
61
- * @param subjectData - Optional subject instance data
62
- * @returns True if action is forbidden, false if permitted
63
- *
64
- * @example
65
- * ```typescript
66
- * router.post('/admin/users', async (c) => {
67
- * if (cannot(c, 'create', 'User')) {
68
- * return c.json({ error: 'Forbidden' }, 403);
69
- * }
70
- *
71
- * // ... create user
72
- * });
73
- * ```
74
- */
75
- export declare function cannot<T extends BaseAbility = BaseAbility>(context: Context, action: string, subjectType: string, subjectData?: object): boolean;
76
- /**
77
- * Creates a Prisma where clause using CASL's accessibleBy helper.
78
- * This is a transparent wrapper that exposes @casl/prisma functionality.
79
- *
80
- * Requires @casl/prisma to be installed as a peer dependency.
81
- *
82
- * @param context - Hono context containing the ability
83
- * @param subjectType - Prisma model name (e.g., 'User', 'Post')
84
- * @param additionalWhere - Optional additional where conditions to combine
85
- * @returns Prisma where clause that filters by ability permissions
86
- *
87
- * @example
88
- * ```typescript
89
- * import { accessibleBy } from '@casl/prisma';
90
- *
91
- * router.get('/posts', async (c) => {
92
- * const ability = getAbility(c);
93
- *
94
- * // Use CASL Prisma integration directly
95
- * const posts = await prisma.post.findMany({
96
- * where: accessibleBy(ability).Post
97
- * });
98
- *
99
- * return c.json(posts);
100
- * });
101
- * ```
102
- *
103
- * @see https://casl.js.org/v6/en/package/casl-prisma
104
- */
105
- export declare function accessibleWhere<T extends BaseAbility = BaseAbility>(context: Context, subjectType: string, additionalWhere?: object): object;
106
- //# sourceMappingURL=route-helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"route-helpers.d.ts","sourceRoot":"","sources":["../../src/authorization/route-helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEpC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC3D,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,IAAI,CAUN;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACrD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAKT;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACxD,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EACjE,OAAO,EAAE,OAAO,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAuBR"}