@guren/server 2.10.0 → 2.10.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.
Files changed (90) hide show
  1. package/dist/DocsViewerServiceProvider-qFCaeiUv.js +77 -0
  2. package/dist/Hash-CzrwKeDp.js +133 -0
  3. package/dist/HttpException-BkS3euNG.js +161 -0
  4. package/dist/Job-BVT813DO.js +441 -0
  5. package/dist/McpServiceProvider-BoAN-UcD.js +367 -0
  6. package/dist/MessageSigner-Bd25ZJAV.js +93 -0
  7. package/dist/Random-DbIJ22KQ.js +191 -0
  8. package/dist/address-D0Iq-XIH.js +20 -0
  9. package/dist/auth/index.js +2 -122
  10. package/dist/auth-C7sVmYgc.js +1954 -0
  11. package/dist/authorization/index.js +2 -38
  12. package/dist/authorization-Dbcuc5ZK.js +610 -0
  13. package/dist/broadcasting/index.js +2 -26
  14. package/dist/broadcasting-Dw-FhyjN.js +1055 -0
  15. package/dist/cache/index.js +2 -17
  16. package/dist/cache/types.d.ts +4 -4
  17. package/dist/cache-BYnZf2FR.js +812 -0
  18. package/dist/client-Dd7vLcqp.js +27 -0
  19. package/dist/console/Output.d.ts +18 -18
  20. package/dist/encryption/index.js +5 -96
  21. package/dist/encryption-fOWQaKqX.js +250 -0
  22. package/dist/endpoint-D-20PiHY.js +46 -0
  23. package/dist/endpoint-D6GIqOpe.js +31 -0
  24. package/dist/errors-quJOkkCn.js +81 -0
  25. package/dist/events/index.js +2 -28
  26. package/dist/events-aIH_bWRx.js +410 -0
  27. package/dist/health/index.js +2 -24
  28. package/dist/health-VWdWXRwh.js +345 -0
  29. package/dist/hot-disposables-WsTX2ySN.js +281 -0
  30. package/dist/hot-reload/testing.d.ts +1 -1
  31. package/dist/i18n/index.js +2 -30
  32. package/dist/i18n-mcWi7LCd.js +617 -0
  33. package/dist/index.js +7495 -7276
  34. package/dist/lambda/index.js +114 -71
  35. package/dist/logging/index.js +2 -24
  36. package/dist/logging-CPaRMuPP.js +518 -0
  37. package/dist/loopback-guard-D0Kc7-xc.js +224 -0
  38. package/dist/mail/index.js +2 -27
  39. package/dist/mail-DfEfSQEr.js +699 -0
  40. package/dist/mcp/index.js +2 -10
  41. package/dist/notifications/index.js +2 -33
  42. package/dist/notifications-BGqmUNZ8.js +759 -0
  43. package/dist/queue/index.js +3 -42
  44. package/dist/queue-CXrRK85G.js +948 -0
  45. package/dist/redis/index.js +672 -642
  46. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  47. package/dist/runtime/index.js +472 -616
  48. package/dist/scheduling/index.js +2 -29
  49. package/dist/scheduling-CPiEdtQd.js +839 -0
  50. package/dist/storage/index.js +2 -15
  51. package/dist/storage-tWHMv2H_.js +841 -0
  52. package/dist/support/expiry.js +69 -12
  53. package/dist/trim-slashes-ZJ_VsY5s.js +25 -0
  54. package/dist/vite/index.js +118 -181
  55. package/dist/vite/plugin.d.ts +1 -1
  56. package/dist/vite-dev-server-CpCUqmiC.js +131 -0
  57. package/package.json +6 -5
  58. package/dist/DocsViewerServiceProvider-RUYDFBMW.js +0 -75
  59. package/dist/McpServiceProvider-SL7DUZ4G.js +0 -8
  60. package/dist/chunk-2SC566CD.js +0 -376
  61. package/dist/chunk-2V3YID4H.js +0 -20
  62. package/dist/chunk-3KV5X2FL.js +0 -31
  63. package/dist/chunk-63SKW5PS.js +0 -457
  64. package/dist/chunk-6J6B5KOB.js +0 -425
  65. package/dist/chunk-A5JJ7XTH.js +0 -24
  66. package/dist/chunk-AZOYI43J.js +0 -18
  67. package/dist/chunk-B5E5VBDI.js +0 -115
  68. package/dist/chunk-DAQKYKLH.js +0 -182
  69. package/dist/chunk-DRNPVBAA.js +0 -1002
  70. package/dist/chunk-EI5GYMAT.js +0 -853
  71. package/dist/chunk-H3B23O6T.js +0 -271
  72. package/dist/chunk-HPET6XY5.js +0 -853
  73. package/dist/chunk-HR2KZ3WL.js +0 -616
  74. package/dist/chunk-IOTWFHZU.js +0 -558
  75. package/dist/chunk-K6CUBJX6.js +0 -642
  76. package/dist/chunk-KTNJG7R7.js +0 -911
  77. package/dist/chunk-LAJQCSSF.js +0 -355
  78. package/dist/chunk-LHR6OHI7.js +0 -189
  79. package/dist/chunk-N7PLD7MB.js +0 -729
  80. package/dist/chunk-Q2P6YLRR.js +0 -24
  81. package/dist/chunk-QQKTH5KX.js +0 -114
  82. package/dist/chunk-SFQP6O52.js +0 -126
  83. package/dist/chunk-SQR7277M.js +0 -911
  84. package/dist/chunk-T2FFUU6J.js +0 -484
  85. package/dist/chunk-TVV5YNEC.js +0 -1842
  86. package/dist/chunk-UY3AZSYL.js +0 -14
  87. package/dist/chunk-V4DNC2ER.js +0 -114
  88. package/dist/chunk-VSA3QY5Q.js +0 -274
  89. package/dist/chunk-YSOJKAAU.js +0 -427
  90. package/dist/errors-PUNHAFL2.js +0 -34
@@ -1,484 +0,0 @@
1
- import {
2
- AuthorizationException
3
- } from "./chunk-63SKW5PS.js";
4
- import {
5
- HttpException
6
- } from "./chunk-DAQKYKLH.js";
7
-
8
- // src/authorization/Gate.ts
9
- var Response = {
10
- allow(message) {
11
- return { allowed: true, message };
12
- },
13
- deny(message, code) {
14
- return { allowed: false, message: message ?? "This action is unauthorized.", code };
15
- },
16
- denyWithStatus(status, message) {
17
- return { allowed: false, message: message ?? "This action is unauthorized.", status };
18
- },
19
- denyAsNotFound(message) {
20
- return { allowed: false, message: message ?? "Not found.", status: 404 };
21
- }
22
- };
23
- function isAuthorizationResponse(value) {
24
- return typeof value === "object" && value !== null && typeof value.allowed === "boolean";
25
- }
26
- function toAuthorizationResponse(value) {
27
- if (isAuthorizationResponse(value)) {
28
- return value;
29
- }
30
- return value === true ? Response.allow() : Response.deny();
31
- }
32
- function denialToException(response) {
33
- const message = response.message ?? "This action is unauthorized.";
34
- const status = response.status;
35
- if (typeof status === "number" && status !== 403) {
36
- return new HttpException(status, message);
37
- }
38
- return new AuthorizationException(message);
39
- }
40
- var Gate = class {
41
- /**
42
- * Defined gates.
43
- */
44
- gates = /* @__PURE__ */ new Map();
45
- /**
46
- * Registered policies.
47
- */
48
- policies = /* @__PURE__ */ new Map();
49
- /**
50
- * Policy instances cache.
51
- */
52
- policyInstances = /* @__PURE__ */ new Map();
53
- /**
54
- * Before callbacks.
55
- */
56
- beforeCallbacks = [];
57
- /**
58
- * After callbacks.
59
- */
60
- afterCallbacks = [];
61
- /**
62
- * User resolver function.
63
- */
64
- userResolver;
65
- /**
66
- * Current user for checks.
67
- */
68
- currentUser = null;
69
- constructor(options = {}) {
70
- this.userResolver = options.userResolver;
71
- }
72
- /**
73
- * Define a new gate.
74
- */
75
- define(ability, callback) {
76
- this.gates.set(ability, { callback });
77
- return this;
78
- }
79
- /**
80
- * Register a policy for a model class.
81
- */
82
- policy(modelClass, policyClass) {
83
- this.policies.set(modelClass, policyClass);
84
- return this;
85
- }
86
- /**
87
- * Register a before callback.
88
- * Return true to allow, false to deny, undefined to continue.
89
- */
90
- before(callback) {
91
- this.beforeCallbacks.push(callback);
92
- return this;
93
- }
94
- /**
95
- * Register an after callback.
96
- */
97
- after(callback) {
98
- this.afterCallbacks.push(callback);
99
- return this;
100
- }
101
- /**
102
- * Set the current user for authorization checks.
103
- */
104
- forUser(user) {
105
- const clone = Object.assign(
106
- Object.create(Object.getPrototypeOf(this)),
107
- this
108
- );
109
- clone.currentUser = user;
110
- return clone;
111
- }
112
- /**
113
- * Resolve the user from context.
114
- */
115
- async resolveUser(ctx) {
116
- if (this.currentUser !== null) {
117
- return this.currentUser;
118
- }
119
- if (this.userResolver) {
120
- return this.userResolver(ctx);
121
- }
122
- const user = ctx.get("user");
123
- return user ?? null;
124
- }
125
- /**
126
- * Check if the user has the given ability.
127
- */
128
- async allows(ability, ...args) {
129
- return this.check(ability, this.currentUser, ...args);
130
- }
131
- /**
132
- * Check if the user doesn't have the given ability.
133
- */
134
- async denies(ability, ...args) {
135
- return !await this.allows(ability, ...args);
136
- }
137
- /**
138
- * Check if the user has any of the given abilities.
139
- */
140
- async any(abilities, ...args) {
141
- for (const ability of abilities) {
142
- if (await this.allows(ability, ...args)) {
143
- return true;
144
- }
145
- }
146
- return false;
147
- }
148
- /**
149
- * Check if the user has all of the given abilities.
150
- */
151
- async all(abilities, ...args) {
152
- for (const ability of abilities) {
153
- if (!await this.allows(ability, ...args)) {
154
- return false;
155
- }
156
- }
157
- return true;
158
- }
159
- /**
160
- * Check if the user has none of the given abilities.
161
- */
162
- async none(abilities, ...args) {
163
- return !await this.any(abilities, ...args);
164
- }
165
- /**
166
- * Authorize the ability or throw an exception.
167
- */
168
- async authorize(ability, ...args) {
169
- const response = await this.checkResponse(ability, this.currentUser, ...args);
170
- if (!response.allowed) {
171
- throw denialToException(response);
172
- }
173
- }
174
- /**
175
- * Get the authorization response.
176
- */
177
- async inspect(ability, ...args) {
178
- return this.checkResponse(ability, this.currentUser, ...args);
179
- }
180
- /**
181
- * Check the ability with a specific user.
182
- */
183
- async check(ability, user, ...args) {
184
- const response = await this.checkResponse(ability, user, ...args);
185
- return response.allowed;
186
- }
187
- /**
188
- * Check the ability with a specific user and keep the full response.
189
- *
190
- * Policies may answer with a boolean or with a `Response` object. Both
191
- * shapes are normalized here so no caller has to truthy-test a
192
- * `{ allowed: false }` object.
193
- */
194
- async checkResponse(ability, user, ...args) {
195
- for (const beforeCallback of this.beforeCallbacks) {
196
- const result = await beforeCallback(user, ability, ...args);
197
- if (result !== void 0) {
198
- return this.settle(user, ability, toAuthorizationResponse(result), args);
199
- }
200
- }
201
- const model = args[0];
202
- if (model !== void 0 && model !== null) {
203
- const policyResult = await this.checkPolicy(ability, user, model, args.slice(1));
204
- if (policyResult !== void 0) {
205
- return this.settle(user, ability, toAuthorizationResponse(policyResult), args);
206
- }
207
- }
208
- const gate = this.gates.get(ability);
209
- if (gate) {
210
- const result = await gate.callback(user, ...args);
211
- return this.settle(user, ability, toAuthorizationResponse(result), args);
212
- }
213
- return this.settle(user, ability, Response.deny(), args);
214
- }
215
- async settle(user, ability, response, args) {
216
- await this.runAfterCallbacks(user, ability, response.allowed, args);
217
- return response;
218
- }
219
- /**
220
- * Check a policy for the given ability.
221
- *
222
- * The subject may be a class instance (policy resolved via its constructor)
223
- * or a `[ModelClass, record]` / `['key', record]` tuple. The tuple form is
224
- * required for plain records returned by the ORM, which carry no constructor
225
- * information.
226
- */
227
- async checkPolicy(ability, user, model, additionalArgs) {
228
- let policyKey;
229
- let subject = model;
230
- let hasSubject = true;
231
- if (Array.isArray(model) && model.length === 2 && (typeof model[0] === "function" || typeof model[0] === "string")) {
232
- policyKey = model[0];
233
- subject = model[1];
234
- } else if (typeof model === "function") {
235
- policyKey = model;
236
- hasSubject = false;
237
- } else {
238
- policyKey = model?.constructor;
239
- }
240
- if (!policyKey) {
241
- return void 0;
242
- }
243
- const policyClass = this.policies.get(policyKey);
244
- if (!policyClass) {
245
- return void 0;
246
- }
247
- const policy = this.getPolicyInstance(policyClass);
248
- if (policy.before) {
249
- const beforeResult = await policy.before(user, ability);
250
- if (beforeResult !== void 0) {
251
- return beforeResult;
252
- }
253
- }
254
- const method = policy[ability];
255
- if (typeof method === "function") {
256
- return hasSubject ? method.call(policy, user, subject, ...additionalArgs) : method.call(policy, user, ...additionalArgs);
257
- }
258
- return void 0;
259
- }
260
- /**
261
- * Get or create a policy instance.
262
- */
263
- getPolicyInstance(policyClass) {
264
- let instance = this.policyInstances.get(policyClass);
265
- if (!instance) {
266
- instance = new policyClass();
267
- this.policyInstances.set(policyClass, instance);
268
- }
269
- return instance;
270
- }
271
- /**
272
- * Run after callbacks.
273
- */
274
- async runAfterCallbacks(user, ability, result, args) {
275
- for (const afterCallback of this.afterCallbacks) {
276
- await afterCallback(user, ability, result, args);
277
- }
278
- }
279
- /**
280
- * Get all defined abilities.
281
- */
282
- abilities() {
283
- return Array.from(this.gates.keys());
284
- }
285
- /**
286
- * Check if an ability is defined.
287
- */
288
- has(ability) {
289
- return this.gates.has(ability);
290
- }
291
- /**
292
- * Get the policy for a model.
293
- */
294
- getPolicyFor(model) {
295
- const modelConstructor = model?.constructor;
296
- if (!modelConstructor) {
297
- return void 0;
298
- }
299
- const policyClass = this.policies.get(modelConstructor);
300
- if (!policyClass) {
301
- return void 0;
302
- }
303
- return this.getPolicyInstance(policyClass);
304
- }
305
- };
306
- var globalGate = null;
307
- function createGate(options) {
308
- return new Gate(options);
309
- }
310
- function setGate(gate) {
311
- globalGate = gate;
312
- }
313
- function getGate() {
314
- if (!globalGate) {
315
- throw new Error("Gate not initialized. Call setGate() first.");
316
- }
317
- return globalGate;
318
- }
319
- function defineGate(ability, callback) {
320
- getGate().define(ability, callback);
321
- }
322
- async function can(ability, ...args) {
323
- return getGate().allows(ability, ...args);
324
- }
325
- async function cannot(ability, ...args) {
326
- return getGate().denies(ability, ...args);
327
- }
328
- async function authorize(ability, ...args) {
329
- return getGate().authorize(ability, ...args);
330
- }
331
-
332
- // src/authorization/Policy.ts
333
- var Policy = class {
334
- /**
335
- * Allow the action.
336
- */
337
- allow(message) {
338
- return Response.allow(message);
339
- }
340
- /**
341
- * Deny the action.
342
- */
343
- deny(message, code) {
344
- return Response.deny(message, code);
345
- }
346
- /**
347
- * Deny with a specific HTTP status.
348
- */
349
- denyWithStatus(status, message) {
350
- return Response.denyWithStatus(status, message);
351
- }
352
- /**
353
- * Deny as not found (404).
354
- */
355
- denyAsNotFound(message) {
356
- return Response.denyAsNotFound(message);
357
- }
358
- };
359
- function definePolicy(definition) {
360
- return class extends Policy {
361
- before = definition.before;
362
- viewAny(user) {
363
- return definition.viewAny?.(user) ?? false;
364
- }
365
- view(user, model) {
366
- return definition.view?.(user, model) ?? false;
367
- }
368
- create(user) {
369
- return definition.create?.(user) ?? false;
370
- }
371
- update(user, model) {
372
- return definition.update?.(user, model) ?? false;
373
- }
374
- delete(user, model) {
375
- return definition.delete?.(user, model) ?? false;
376
- }
377
- restore(user, model) {
378
- return definition.restore?.(user, model) ?? false;
379
- }
380
- forceDelete(user, model) {
381
- return definition.forceDelete?.(user, model) ?? false;
382
- }
383
- };
384
- }
385
-
386
- // src/authorization/middleware.ts
387
- function authorizeMiddleware(ability, modelResolver, options = {}) {
388
- return async (ctx, next) => {
389
- const gate = getGate();
390
- const user = await gate.resolveUser(ctx);
391
- const gateForUser = gate.forUser(user);
392
- const abilities = Array.isArray(ability) ? ability : [ability];
393
- const model = modelResolver ? await modelResolver(ctx) : void 0;
394
- if (Array.isArray(ability)) {
395
- if (!await gateForUser.any(abilities, model)) {
396
- throw new AuthorizationException(options.message ?? "This action is unauthorized.");
397
- }
398
- } else {
399
- const response = await gateForUser.checkResponse(ability, user, model);
400
- if (!response.allowed) {
401
- throw denialToException(options.message ? { ...response, message: options.message } : response);
402
- }
403
- }
404
- await next();
405
- };
406
- }
407
- function authorizeAllMiddleware(abilities, modelResolver, options = {}) {
408
- return async (ctx, next) => {
409
- const gate = getGate();
410
- const user = await gate.resolveUser(ctx);
411
- const gateForUser = gate.forUser(user);
412
- const model = modelResolver ? await modelResolver(ctx) : void 0;
413
- const authorized = await gateForUser.all(abilities, model);
414
- if (!authorized) {
415
- throw new AuthorizationException(
416
- options.message ?? "This action is unauthorized."
417
- );
418
- }
419
- await next();
420
- };
421
- }
422
- var RESOURCE_ABILITY_BY_METHOD = {
423
- GET: "view",
424
- HEAD: "view",
425
- QUERY: "view",
426
- POST: "create",
427
- PUT: "update",
428
- PATCH: "update",
429
- DELETE: "delete"
430
- };
431
- function authorizeResourceMiddleware(modelResolver, options = {}) {
432
- return async (ctx, next) => {
433
- const method = ctx.req.method.toUpperCase();
434
- const ability = options.abilityFor?.(method) ?? RESOURCE_ABILITY_BY_METHOD[method];
435
- if (ability === void 0) {
436
- throw new AuthorizationException(options.message ?? "This action is unauthorized.");
437
- }
438
- const gate = getGate();
439
- const user = await gate.resolveUser(ctx);
440
- const gateForUser = gate.forUser(user);
441
- const model = await modelResolver(ctx);
442
- const response = await gateForUser.checkResponse(ability, user, model);
443
- if (!response.allowed) {
444
- throw denialToException(options.message ? { ...response, message: options.message } : response);
445
- }
446
- await next();
447
- };
448
- }
449
- function withAuthorization(gate) {
450
- return async (ctx, next) => {
451
- const user = await gate.resolveUser(ctx);
452
- const gateForUser = gate.forUser(user);
453
- ctx.set("gate", gateForUser);
454
- ctx.set("can", async (ability, ...args) => {
455
- return gateForUser.allows(ability, ...args);
456
- });
457
- ctx.set("cannot", async (ability, ...args) => {
458
- return gateForUser.denies(ability, ...args);
459
- });
460
- ctx.set("authorize", async (ability, ...args) => {
461
- return gateForUser.authorize(ability, ...args);
462
- });
463
- await next();
464
- };
465
- }
466
-
467
- export {
468
- Response,
469
- isAuthorizationResponse,
470
- Gate,
471
- createGate,
472
- setGate,
473
- getGate,
474
- defineGate,
475
- can,
476
- cannot,
477
- authorize,
478
- Policy,
479
- definePolicy,
480
- authorizeMiddleware,
481
- authorizeAllMiddleware,
482
- authorizeResourceMiddleware,
483
- withAuthorization
484
- };