@owlmeans/server-api 0.1.18-rc.5 → 0.1.18-rc.51

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 (129) hide show
  1. package/README.md +203 -46
  2. package/agent-meta/manifest.json +2 -2
  3. package/agent-meta/skills/server-api/SKILL.md +128 -22
  4. package/build/consts.local.d.ts +2 -0
  5. package/build/consts.local.d.ts.map +1 -0
  6. package/build/consts.local.js +2 -0
  7. package/build/consts.local.js.map +1 -0
  8. package/build/errors.d.ts +12 -0
  9. package/build/errors.d.ts.map +1 -1
  10. package/build/errors.js +16 -0
  11. package/build/errors.js.map +1 -1
  12. package/build/helper.d.ts +3 -6
  13. package/build/helper.d.ts.map +1 -1
  14. package/build/helper.js +10 -1
  15. package/build/helper.js.map +1 -1
  16. package/build/hold.d.ts +35 -0
  17. package/build/hold.d.ts.map +1 -0
  18. package/build/hold.js +57 -0
  19. package/build/hold.js.map +1 -0
  20. package/build/index.d.ts +2 -0
  21. package/build/index.d.ts.map +1 -1
  22. package/build/index.js +2 -0
  23. package/build/index.js.map +1 -1
  24. package/build/protocol.d.ts +18 -0
  25. package/build/protocol.d.ts.map +1 -0
  26. package/build/protocol.js +87 -0
  27. package/build/protocol.js.map +1 -0
  28. package/build/server.d.ts +2 -3
  29. package/build/server.d.ts.map +1 -1
  30. package/build/server.js +39 -34
  31. package/build/server.js.map +1 -1
  32. package/build/types.d.ts +31 -2
  33. package/build/types.d.ts.map +1 -1
  34. package/build/types.local.d.ts +38 -0
  35. package/build/types.local.d.ts.map +1 -0
  36. package/build/types.local.js +2 -0
  37. package/build/types.local.js.map +1 -0
  38. package/build/utils/consts.d.ts +2 -0
  39. package/build/utils/consts.d.ts.map +1 -0
  40. package/build/utils/consts.js +2 -0
  41. package/build/utils/consts.js.map +1 -0
  42. package/build/utils/consts.local.d.ts +5 -0
  43. package/build/utils/consts.local.d.ts.map +1 -0
  44. package/build/utils/consts.local.js +5 -0
  45. package/build/utils/consts.local.js.map +1 -0
  46. package/build/utils/context/types.d.ts +13 -0
  47. package/build/utils/context/types.d.ts.map +1 -0
  48. package/build/utils/context/types.js +2 -0
  49. package/build/utils/context/types.js.map +1 -0
  50. package/build/utils/context.d.ts +3 -3
  51. package/build/utils/context.d.ts.map +1 -1
  52. package/build/utils/context.js +5 -2
  53. package/build/utils/context.js.map +1 -1
  54. package/build/utils/error/types.d.ts +52 -0
  55. package/build/utils/error/types.d.ts.map +1 -0
  56. package/build/utils/error/types.js +2 -0
  57. package/build/utils/error/types.js.map +1 -0
  58. package/build/utils/error.d.ts +5 -2
  59. package/build/utils/error.d.ts.map +1 -1
  60. package/build/utils/error.js +163 -13
  61. package/build/utils/error.js.map +1 -1
  62. package/build/utils/guards.d.ts +1 -5
  63. package/build/utils/guards.d.ts.map +1 -1
  64. package/build/utils/guards.js +15 -19
  65. package/build/utils/guards.js.map +1 -1
  66. package/build/utils/index.d.ts +6 -1
  67. package/build/utils/index.d.ts.map +1 -1
  68. package/build/utils/index.js +2 -1
  69. package/build/utils/index.js.map +1 -1
  70. package/build/utils/log.d.ts +11 -0
  71. package/build/utils/log.d.ts.map +1 -0
  72. package/build/utils/log.js +57 -0
  73. package/build/utils/log.js.map +1 -0
  74. package/build/utils/payload/types.d.ts +18 -0
  75. package/build/utils/payload/types.d.ts.map +1 -0
  76. package/build/utils/payload/types.js +2 -0
  77. package/build/utils/payload/types.js.map +1 -0
  78. package/build/utils/payload.d.ts +3 -15
  79. package/build/utils/payload.d.ts.map +1 -1
  80. package/build/utils/payload.js +41 -57
  81. package/build/utils/payload.js.map +1 -1
  82. package/build/utils/schema.d.ts +7 -0
  83. package/build/utils/schema.d.ts.map +1 -0
  84. package/build/utils/schema.js +20 -0
  85. package/build/utils/schema.js.map +1 -0
  86. package/build/utils/server.d.ts +3 -6
  87. package/build/utils/server.d.ts.map +1 -1
  88. package/build/utils/server.js +12 -13
  89. package/build/utils/server.js.map +1 -1
  90. package/build/utils/types.d.ts +18 -0
  91. package/build/utils/types.d.ts.map +1 -0
  92. package/build/utils/types.js +2 -0
  93. package/build/utils/types.js.map +1 -0
  94. package/build/utils/types.local.d.ts +9 -0
  95. package/build/utils/types.local.d.ts.map +1 -0
  96. package/build/utils/types.local.js +2 -0
  97. package/build/utils/types.local.js.map +1 -0
  98. package/package.json +22 -18
  99. package/src/consts.local.ts +1 -0
  100. package/src/errors.ts +18 -0
  101. package/src/helper.ts +13 -8
  102. package/src/hold.ts +66 -0
  103. package/src/index.ts +2 -0
  104. package/src/protocol.ts +149 -0
  105. package/src/server.ts +69 -69
  106. package/src/types.local.ts +44 -0
  107. package/src/types.ts +38 -4
  108. package/src/utils/consts.local.ts +7 -0
  109. package/src/utils/consts.ts +1 -0
  110. package/src/utils/context/types.ts +13 -0
  111. package/src/utils/context.ts +9 -4
  112. package/src/utils/error/types.ts +52 -0
  113. package/src/utils/error.ts +184 -12
  114. package/src/utils/guards.ts +16 -26
  115. package/src/utils/index.ts +6 -1
  116. package/src/utils/log.ts +62 -0
  117. package/src/utils/payload/types.ts +18 -0
  118. package/src/utils/payload.ts +42 -60
  119. package/src/utils/schema.ts +23 -0
  120. package/src/utils/server.ts +16 -21
  121. package/src/utils/types.local.ts +12 -0
  122. package/src/utils/types.ts +18 -0
  123. package/tests/error-status.spec.ts +349 -0
  124. package/tests/handlers.spec.ts +83 -0
  125. package/tests/json-body.spec.ts +72 -0
  126. package/tests/log-adapter.spec.ts +52 -0
  127. package/tests/tsconfig.json +12 -0
  128. package/tsconfig.json +1 -0
  129. package/build/.gitkeep +0 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/context/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import type { Config, Context, Request } from '../types.js';
2
- export declare const populateContext: <C extends Config, T extends Context<C>>(req: Request, context: T) => void;
3
- export declare const extractContext: <C extends Config, T extends Context<C>>(req: Request, ctx?: T, location?: string) => T;
1
+ import type { Request } from '../types.js';
2
+ import type { RequestContextHelper } from './context/types.js';
3
+ export declare const makeRequestContextHelper: (req: Request) => RequestContextHelper;
4
4
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAG3D,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,WAAW,CAAC,KAAG,IAC/D,CAAA;AAEpC,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAAO,OAAO,QAAQ,CAAC,aAAa,MAAM,KAAG,CACxC,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,OAAO,EAAE,MAAM,aAAa,CAAA;AAE3D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,eAAO,MAAM,wBAAwB,QAAS,OAAO,KAAG,oBAQvD,CAAA"}
@@ -1,5 +1,8 @@
1
1
  import { assertContext } from '@owlmeans/context';
2
2
  import { DEFAULT_ALIAS } from '../consts.js';
3
- export const populateContext = (req, context) => void (req._ctx = context);
4
- export const extractContext = (req, ctx, location) => assertContext(req._ctx ?? ctx, location ?? DEFAULT_ALIAS);
3
+ export const makeRequestContextHelper = (req) => {
4
+ const populateContext = (context) => void (req._ctx = context);
5
+ const extractContext = (ctx, location) => assertContext(req._ctx ?? ctx, location ?? DEFAULT_ALIAS);
6
+ return { populateContext, extractContext };
7
+ };
5
8
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAyC,GAAY,EAAE,OAAU,EAAQ,EAAE,CACxG,KAAK,CAAE,GAAW,CAAC,IAAI,GAAG,OAAO,CAAC,CAAA;AAEpC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAyC,GAAY,EAAE,GAAO,EAAE,QAAiB,EAAK,EAAE,CACpH,aAAa,CAAQ,GAAW,CAAC,IAAI,IAAI,GAAG,EAAE,QAAQ,IAAI,aAAa,CAAC,CAAA"}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAG5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAY,EAAwB,EAAE;IAC7E,MAAM,eAAe,GAAG,CAAyC,OAAU,EAAQ,EAAE,CACnF,KAAK,CAAE,GAAW,CAAC,IAAI,GAAG,OAAO,CAAC,CAAA;IAEpC,MAAM,cAAc,GAAG,CAAyC,GAAO,EAAE,QAAiB,EAAK,EAAE,CAC/F,aAAa,CAAQ,GAAW,CAAC,IAAI,IAAI,GAAG,EAAE,QAAQ,IAAI,aAAa,CAAC,CAAA;IAE1E,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,CAAA;AAC5C,CAAC,CAAA"}
@@ -0,0 +1,52 @@
1
+ import type { FastifyReply } from 'fastify';
2
+ import type { Config, HttpErrorExposure } from '../../types.js';
3
+ import type { SerializedHttpError } from '../types.js';
4
+ /** How the HTTP boundary answers a thrown error: its status, its wire body, its headers and its log entry. */
5
+ export interface HttpErrorHelper {
6
+ /**
7
+ * The HTTP status an error's class declares, or `null` when it declares none that may be honoured.
8
+ *
9
+ * Read through the constructor chain — a static property is inherited, so a subclass answers what
10
+ * its nearest declaring ancestor says, and redeclares to change it. An integer 4xx is honoured
11
+ * directly. A 5xx is honoured only with `allowServerErrorStatus = true`, so a domain class must
12
+ * explicitly opt in to exposing a precise availability response. The read is structural, so a
13
+ * class from a duplicate module copy declares exactly what the imported one does.
14
+ */
15
+ declaredErrorStatus: (error: unknown) => number | null;
16
+ /**
17
+ * The HTTP status an error is answered with, read off the error exactly as given.
18
+ *
19
+ * Two families reach here and both must be recognised. `AuthFailedError` / `AccessError` are this
20
+ * package's own, raised by the request pipeline itself. `AuthorizationError` / `AuthForbidden`
21
+ * come from `@owlmeans/auth` and are what the guards and gates actually throw — an unrecognised
22
+ * one answers 500, which reports a refused request as a crashed server: the client cannot tell
23
+ * "sign in again" from "the service is broken", and a consumer watching statuses concludes the
24
+ * application fell over. A family member is recognised by class OR by registered type name, so a
25
+ * class from a duplicate module copy answers the same status.
26
+ *
27
+ * **Order matters.** `AuthForbidden extends AuthorizationError`, so the 403 branch has to be
28
+ * tested first or every refusal of a permission is reported as a failure to authenticate. Both
29
+ * auth branches come before a class's own declaration, so an auth refusal can never be restated
30
+ * as something else. Everything that is neither an auth error nor a class declaring an allowed
31
+ * {@link HttpErrorHelper.declaredErrorStatus} answers 500.
32
+ */
33
+ errorStatus: (error: unknown) => number;
34
+ /** Invalid or absent configuration always resolves to the production-safe policy. */
35
+ errorExposure: (config?: Pick<Config, 'http'>) => HttpErrorExposure;
36
+ /** One central wire shape for every server error. */
37
+ serializeError: (error: Error, exposure?: HttpErrorExposure) => SerializedHttpError;
38
+ /** Apply safe response metadata carried by an error without coupling its package to Fastify. */
39
+ applyErrorHeaders: (error: unknown, reply: FastifyReply) => void;
40
+ /**
41
+ * Answer a thrown error: a status, and the marshalled `ResilientError` as the body.
42
+ *
43
+ * The status is resolved in two steps. The error AS THROWN comes first: it is the one object whose
44
+ * class is certainly the class that was raised, while `ResilientError.ensure` rebuilds through the
45
+ * registry of whichever `@owlmeans/error` copy this module loaded — under duplicate module copies
46
+ * that turns a perfectly recognisable auth refusal into a plain `ResilientError` answering 500.
47
+ * Only when the thrown error answers 500 is the ENSURED error asked, because the rebuild is what
48
+ * gives a status to a marshalled error that crossed a hop as a plain `Error`.
49
+ */
50
+ handleError: (error: Error, reply: FastifyReply, exposure?: HttpErrorExposure) => void;
51
+ }
52
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/error/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAC/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEtD,8GAA8G;AAC9G,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,IAAI,CAAA;IACtD;;;;;;;;;;;;;;;;OAgBG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;IACvC,qFAAqF;IACrF,aAAa,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,iBAAiB,CAAA;IACnE,qDAAqD;IACrD,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,iBAAiB,KAAK,mBAAmB,CAAA;IACnF,gGAAgG;IAChG,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,KAAK,IAAI,CAAA;IAChE;;;;;;;;;OASG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAA;CACvF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/error/types.ts"],"names":[],"mappings":""}
@@ -1,3 +1,6 @@
1
- import type { FastifyReply } from 'fastify';
2
- export declare const handleError: (error: Error, reply: FastifyReply) => void;
1
+ import type { HttpErrorHelper } from './error/types.js';
2
+ export declare const createHttpErrorHelper: () => HttpErrorHelper;
3
+ export declare const httpErrorHelper: HttpErrorHelper;
4
+ /** @deprecated compat:factory-refactor — use `httpErrorHelper.errorStatus(…)` */
5
+ export declare const errorStatus: (error: unknown) => number;
3
6
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAI3C,eAAO,MAAM,WAAW,UAAW,KAAK,SAAS,YAAY,SAY5D,CAAA"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD,eAAO,MAAM,qBAAqB,QAAO,eAyKxC,CAAA;AAED,eAAO,MAAM,eAAe,iBAA0B,CAAA;AAEtD,iFAAiF;AACjF,eAAO,MAAM,WAAW,UAAW,OAAO,KAAG,MAA4C,CAAA"}
@@ -1,16 +1,166 @@
1
- import { FORBIDDEN_ERROR, SERVER_ERROR, UNAUTHORIZED_ERROR } from '@owlmeans/api';
1
+ import { FORBIDDEN_ERROR, SERVER_ERROR, UNAUTHORIZED_ERROR, DENIAL_KIND_HEADER, ACCESS_DENIED_KIND, } from '@owlmeans/api';
2
2
  import { AccessError, AuthFailedError } from '../errors.js';
3
- import { ResilientError } from '@owlmeans/error';
4
- export const handleError = (error, reply) => {
5
- let code = SERVER_ERROR;
6
- if (error instanceof AuthFailedError) {
7
- code = UNAUTHORIZED_ERROR;
8
- }
9
- else if (error instanceof AccessError) {
10
- code = FORBIDDEN_ERROR;
11
- }
12
- if (!reply.sent) {
13
- reply.code(code).send(ResilientError.marshal(ResilientError.ensure(error)).message);
14
- }
3
+ import { AuthForbidden, AuthorizationError } from '@owlmeans/auth';
4
+ import { isResilientError, ResilientError, SEPARATOR } from '@owlmeans/error';
5
+ import { randomUUID } from 'node:crypto';
6
+ import { logger } from '@owlmeans/log';
7
+ import { CLIENT_ERROR_FIRST, CLIENT_ERROR_LAST, SERVER_ERROR_FIRST, SERVER_ERROR_LAST } from './consts.local.js';
8
+ import { INCIDENT_ID_HEADER } from './consts.js';
9
+ export const createHttpErrorHelper = () => {
10
+ const declaredErrorStatus = (error) => {
11
+ if (error == null || typeof error !== 'object') {
12
+ return null;
13
+ }
14
+ const declaration = error.constructor;
15
+ const status = declaration?.httpStatus;
16
+ if (typeof status !== 'number' || !Number.isInteger(status)) {
17
+ return null;
18
+ }
19
+ if (status >= CLIENT_ERROR_FIRST && status <= CLIENT_ERROR_LAST)
20
+ return status;
21
+ if (status >= SERVER_ERROR_FIRST && status <= SERVER_ERROR_LAST
22
+ && declaration?.allowServerErrorStatus === true)
23
+ return status;
24
+ return null;
25
+ };
26
+ /**
27
+ * The registered type names an error carries: its own `type`, and the static `typeName` of every
28
+ * class on its constructor chain.
29
+ *
30
+ * This is how a class is recognised when `instanceof` cannot see it. A process that loads a package
31
+ * twice — `bun --preserve-symlinks` over a linked workspace resolves one package through several
32
+ * `node_modules` paths — holds several copies of every error class, and an error built by one copy
33
+ * is not an instance of another. The registered names are the same in every copy. A subclass's
34
+ * `typeName` does not reliably embed its parent's (`EntitlementRefusal` extends `AuthForbidden`), so
35
+ * a family is recognised by walking the chain and matching names exactly, never by a substring.
36
+ */
37
+ const typeNamesOf = (error) => {
38
+ const names = new Set();
39
+ const type = error.type;
40
+ if (typeof type === 'string') {
41
+ names.add(type);
42
+ }
43
+ let ctor = error.constructor;
44
+ while (typeof ctor === 'function') {
45
+ const name = ctor.typeName;
46
+ if (typeof name === 'string') {
47
+ names.add(name);
48
+ }
49
+ ctor = Object.getPrototypeOf(ctor);
50
+ }
51
+ return names;
52
+ };
53
+ const isOfFamily = (names, family) => family.some(typeName => names.has(typeName));
54
+ const errorStatus = (error) => {
55
+ if (error == null || typeof error !== 'object') {
56
+ return SERVER_ERROR;
57
+ }
58
+ const names = typeNamesOf(error);
59
+ if (error instanceof AuthForbidden || error instanceof AccessError
60
+ || isOfFamily(names, [AuthForbidden.typeName, AccessError.typeName])) {
61
+ // An established identity that lacks the permission. Re-authenticating changes nothing.
62
+ return FORBIDDEN_ERROR;
63
+ }
64
+ if (error instanceof AuthorizationError || error instanceof AuthFailedError
65
+ || isOfFamily(names, [AuthorizationError.typeName, AuthFailedError.typeName])) {
66
+ // No usable credential — absent, expired, revoked, or naming a session this server no longer
67
+ // holds. The caller is told to sign in, not that signing in would not help.
68
+ return UNAUTHORIZED_ERROR;
69
+ }
70
+ return declaredErrorStatus(error) ?? SERVER_ERROR;
71
+ };
72
+ const errorExposure = (config) => config?.http?.errors?.exposure === 'development' ? 'development' : 'production';
73
+ /**
74
+ * Preserve a typed/marshalled error when possible without asking `ensure` to convert a plain
75
+ * error. In particular, `ensure` deliberately rethrows SyntaxError; an HTTP boundary still has
76
+ * to serialize it safely and let the incident log retain the original object.
77
+ */
78
+ const normalizeForWire = (error) => {
79
+ if (error instanceof SyntaxError || isResilientError(error)) {
80
+ return error;
81
+ }
82
+ if (error.message.includes(SEPARATOR)) {
83
+ const ensured = ResilientError.ensure(error);
84
+ // The catch-all converter's legacy constructor shape shifts an ordinary error's fields.
85
+ // Only keep `ensure`'s result when a registered wire prefix actually rebuilt something.
86
+ if (ensured.type !== error.message || ensured.message !== error.stack) {
87
+ return ensured;
88
+ }
89
+ }
90
+ return error;
91
+ };
92
+ const serializeError = (error, exposure = 'production') => {
93
+ const normalized = normalizeForWire(error);
94
+ const thrown = errorStatus(error);
95
+ const status = thrown !== SERVER_ERROR ? thrown : errorStatus(normalized);
96
+ const incidentId = randomUUID();
97
+ // The server log owns every diagnostic. Production callers receive only its correlation key;
98
+ // development keeps the typed wire form so local clients can retain their usual error details.
99
+ Object.assign(error, { incidentId });
100
+ if (isResilientError(normalized))
101
+ normalized.incidentId = incidentId;
102
+ const body = exposure === 'production'
103
+ ? incidentId
104
+ : ResilientError.marshal(normalized, { includeStack: true, incidentId }).message;
105
+ return { status, body, incidentId };
106
+ };
107
+ const applyErrorHeaders = (error, reply) => {
108
+ if (error == null || typeof error !== 'object') {
109
+ return;
110
+ }
111
+ const retryAfter = error.retryAfter;
112
+ if (typeof retryAfter === 'number' && Number.isFinite(retryAfter) && retryAfter > 0) {
113
+ reply.header('Retry-After', String(Math.ceil(retryAfter)));
114
+ }
115
+ // Match exact registered types. EntitlementRefusal also extends AuthForbidden but is a plan
116
+ // decision, not a person's IAM permission denial.
117
+ const type = error.type;
118
+ if (type === AuthForbidden.typeName || type === AccessError.typeName) {
119
+ reply.header(DENIAL_KIND_HEADER, ACCESS_DENIED_KIND);
120
+ }
121
+ };
122
+ const http = logger('http');
123
+ /**
124
+ * The one log entry of a failed request, by what the failure means:
125
+ *
126
+ * | Status | Level | Why |
127
+ * |---|---|---|
128
+ * | 5xx | error | a fault — the one entry that owns type, message and stack, keyed by the incident id |
129
+ * | 403 | warn, `access.forbidden` | an established identity was refused; worth an operator's eye |
130
+ * | 401 | debug, `auth.refused` | an absent or expired credential is the ordinary shape of a sign-in |
131
+ * | other 4xx | debug | the caller's mistake, not the server's |
132
+ *
133
+ * The method and path are logged; the query string is not — it can carry a token.
134
+ */
135
+ const logFailure = (error, reply, status, incidentId) => {
136
+ const request = reply.request;
137
+ const where = { method: request?.method, path: request?.url?.split('?')[0], status, incidentId };
138
+ if (status >= SERVER_ERROR) {
139
+ http.error('Request failed', { err: error, ...where });
140
+ }
141
+ else if (status === FORBIDDEN_ERROR) {
142
+ http.warn('Access forbidden', { type: error.type, message: error.message, ...where }, { event: 'access.forbidden' });
143
+ }
144
+ else if (status === UNAUTHORIZED_ERROR) {
145
+ http.debug('Authentication refused', { message: error.message, ...where }, { event: 'auth.refused' });
146
+ }
147
+ else {
148
+ http.debug('Request refused', { message: error.message, ...where });
149
+ }
150
+ };
151
+ const handleError = (error, reply, exposure = 'production') => {
152
+ if (!reply.sent) {
153
+ const serialized = serializeError(error, exposure);
154
+ applyErrorHeaders(error, reply);
155
+ logFailure(error, reply, serialized.status, serialized.incidentId);
156
+ reply.header(INCIDENT_ID_HEADER, serialized.incidentId)
157
+ .code(serialized.status)
158
+ .send(serialized.body);
159
+ }
160
+ };
161
+ return { declaredErrorStatus, errorStatus, errorExposure, serializeError, applyErrorHeaders, handleError };
15
162
  };
163
+ export const httpErrorHelper = createHttpErrorHelper();
164
+ /** @deprecated compat:factory-refactor — use `httpErrorHelper.errorStatus(…)` */
165
+ export const errorStatus = (error) => httpErrorHelper.errorStatus(error);
16
166
  //# sourceMappingURL=error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAEjF,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAY,EAAE,KAAmB,EAAE,EAAE;IAC/D,IAAI,IAAI,GAAW,YAAY,CAAA;IAC/B,IAAI,KAAK,YAAY,eAAe,EAAE,CAAC;QACrC,IAAI,GAAG,kBAAkB,CAAA;IAC3B,CAAC;SAAM,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;QACxC,IAAI,GAAG,eAAe,CAAA;IACxB,CAAC;IACD,IAAI,CAAC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rypoint';
3
- import type { ServerConfig, ServerContext } from '@owlmeans/server-context';
4
- type Config = ServerConfig;
5
- interface Context<C extends Config = Config> extends ServerContext<C> {
6
- }
3
+ import type { Config, Context } from './types.local.js';
7
4
  export declare const authorize: <C extends Config, T extends Context<C>>(context: T, module: ServerEntrypoint<FastifyRequest>, req: FastifyRequest, reply: FastifyReply) => Promise<[T, ServerEntrypoint<FastifyRequest>]>;
8
- export {};
9
5
  //# sourceMappingURL=guards.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAGnE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAK3E,KAAK,MAAM,GAAG,YAAY,CAAA;AAC1B,UAAU,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,aAAa,CAAC,CAAC,CAAC;CAAI;AAEzE,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAC3D,CAAC,UAAU,gBAAgB,CAAC,cAAc,CAAC,OAC/C,cAAc,SAAS,YAAY,KACvC,OAAO,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC,CA0D/C,CAAA"}
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAKnE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAIvD,eAAO,MAAM,SAAS,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAC3D,CAAC,UAAU,gBAAgB,CAAC,cAAc,CAAC,OAC/C,cAAc,SAAS,YAAY,KACvC,OAAO,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAmD/C,CAAA"}
@@ -1,19 +1,19 @@
1
- import { isContextWithoutIds, Layer } from '@owlmeans/context';
2
1
  import { provideResponse } from '@owlmeans/entrypoint';
3
- import { executeResponse, provideRequest } from './payload.js';
2
+ import { payloadHelper } from './payload.js';
4
3
  import { AuthFailedError } from '../errors.js';
4
+ import { makeEntityScope } from '@owlmeans/auth-common';
5
5
  export const authorize = async (context, module, req, reply) => {
6
6
  const guards = module.getGuards();
7
7
  if (guards.length > 0) {
8
8
  const response = provideResponse(reply);
9
- const request = provideRequest(module.alias, req);
9
+ const request = payloadHelper.provideRequest(module.alias, req);
10
10
  let guard = undefined;
11
11
  for (const alias of guards) {
12
12
  const _guard = context.service(alias);
13
13
  if (await _guard.match(request, response)) {
14
14
  guard = _guard;
15
15
  }
16
- executeResponse(response, reply, true);
16
+ payloadHelper.executeResponse(response, reply, true);
17
17
  if (guard != null) {
18
18
  break;
19
19
  }
@@ -25,7 +25,7 @@ export const authorize = async (context, module, req, reply) => {
25
25
  if (!await guard.handle(request, authResponse)) {
26
26
  throw new AuthFailedError(guard.alias);
27
27
  }
28
- executeResponse(authResponse, reply, true);
28
+ payloadHelper.executeResponse(authResponse, reply, true);
29
29
  // Guard that returns true and does not provide an error is an optional guard
30
30
  // if (authResponse.value == null) {
31
31
  // throw SyntaxError(`Guard that returns true and does not provide an error, should provide authorization`)
@@ -34,20 +34,16 @@ export const authorize = async (context, module, req, reply) => {
34
34
  if (request.auth != null) {
35
35
  req._auth = request.auth;
36
36
  }
37
- if (request.auth?.entityId != null) {
38
- // @TODO Probably we need to downgrade context in this case
39
- if (!isContextWithoutIds(context)) {
40
- throw SyntaxError(`Context should be without ids during authorization ${context.cfg.layer}:${context.cfg.layerId}`);
41
- }
42
- if (isContextWithoutIds(context) && context.cfg.layer !== Layer.Service) {
43
- context = await context.updateContext(undefined, Layer.Service);
44
- await context.waitForInitialized();
45
- }
46
- context = await context.updateContext(request.auth.entityId, Layer.Entity);
47
- await context.waitForInitialized();
48
- // We elevate module to the context level if it was changed
49
- module = context.entrypoint(module.alias);
50
- await module.resolve();
37
+ // The token names the organization by slug; everything downstream — grants, records, minted
38
+ // infrastructure names — keys on the entity's stable id. Resolving here, once, is what keeps a
39
+ // rename from being a sweep of every handler: the id arrives on the request, and a slug that
40
+ // has since been retired still resolves to the entity that retired it.
41
+ const entity = await makeEntityScope(request).attachEntity(context);
42
+ if (entity != null) {
43
+ // Carried on the raw request the same way `_auth` is, so the request the handler is given
44
+ // later — a different object, built after this runs — sees the same resolution.
45
+ ;
46
+ req._entity = entity;
51
47
  }
52
48
  }
53
49
  // Update context in request object
@@ -1 +1 @@
1
- {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAI9D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAM9C,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,OAAU,EAAE,MAAwC,EACpD,GAAmB,EAAE,KAAmB,EACQ,EAAE;IAClD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,QAAQ,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;QACvC,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,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F,+FAA+F;QAC/F,6FAA6F;QAC7F,uEAAuE;QACvE,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QACnE,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,0FAA0F;YAC1F,gFAAgF;YAChF,CAAC;YAAC,GAAW,CAAC,OAAO,GAAG,MAAM,CAAA;QAChC,CAAC;IACH,CAAC;IACD,mCAAmC;IAClC,GAAW,CAAC,IAAI,GAAG,OAAO,CAAA;IAE3B,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAC1B,CAAC,CAAA"}
@@ -1,7 +1,12 @@
1
1
  export * from './error.js';
2
+ export * from './consts.js';
3
+ export type * from './types.js';
4
+ export type * from './error/types.js';
5
+ export type * from './payload/types.js';
6
+ export type * from './context/types.js';
2
7
  export * from './server.js';
3
8
  export * from './payload.js';
4
- export * from './server.js';
9
+ export * from './schema.js';
5
10
  export * from './guards.js';
6
11
  export * from './context.js';
7
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,kBAAkB,CAAA;AACrC,mBAAmB,oBAAoB,CAAA;AACvC,mBAAmB,oBAAoB,CAAA;AACvC,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
@@ -1,7 +1,8 @@
1
1
  export * from './error.js';
2
+ export * from './consts.js';
2
3
  export * from './server.js';
3
4
  export * from './payload.js';
4
- export * from './server.js';
5
+ export * from './schema.js';
5
6
  export * from './guards.js';
6
7
  export * from './context.js';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAK3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { FastifyBaseLogger } from 'fastify';
2
+ import { type Logger } from '@owlmeans/log';
3
+ /**
4
+ * A pino-shaped logger over `@owlmeans/log`, handed to Fastify as its `loggerInstance`.
5
+ *
6
+ * Fastify then logs through the process's own level, format and plugins instead of a second pino
7
+ * instance that ignores them. `(object, message)` and `(message)` are the two shapes Fastify and
8
+ * its plugins call with; an `err` in the object travels as the record's error.
9
+ */
10
+ export declare const fastifyLogger: (log?: Logger, bindings?: Record<string, unknown>) => FastifyBaseLogger;
11
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,eAAe,CAAA;AA0BlE;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,SAAS,MAAM,aAA8B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,iBAsBhG,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { logger } from '@owlmeans/log';
2
+ /**
3
+ * What Fastify says about itself, mapped to what an operator needs at each level.
4
+ *
5
+ * Fastify writes a pair of `info` lines for EVERY request and one for each unknown route, and
6
+ * announces its own listening address. The server writes one `debug` record per request itself
7
+ * (`onResponse`), a failed request is classified once in `handleError`, and the listening line is
8
+ * `server.listening` — so these are dropped or lowered here, by their fixed wording, rather than by
9
+ * a Fastify option (`disableRequestLogging` is deprecated from 5.12, `logController` does not exist
10
+ * before it).
11
+ */
12
+ const levelOf = (level, message) => {
13
+ if (typeof message !== 'string' || level !== 'info') {
14
+ return level;
15
+ }
16
+ if (message === 'incoming request' || message === 'request completed') {
17
+ return undefined;
18
+ }
19
+ if (message.startsWith('Server listening at') || /^Route .* not found$/.test(message)) {
20
+ return 'debug';
21
+ }
22
+ return level;
23
+ };
24
+ /**
25
+ * A pino-shaped logger over `@owlmeans/log`, handed to Fastify as its `loggerInstance`.
26
+ *
27
+ * Fastify then logs through the process's own level, format and plugins instead of a second pino
28
+ * instance that ignores them. `(object, message)` and `(message)` are the two shapes Fastify and
29
+ * its plugins call with; an `err` in the object travels as the record's error.
30
+ */
31
+ export const fastifyLogger = (log = logger('http'), bindings) => {
32
+ const call = (requested) => (first, second) => {
33
+ const [object, message] = typeof first === 'string' || first instanceof Error
34
+ ? [undefined, first] : [first, second];
35
+ const level = levelOf(requested, message);
36
+ if (level == null) {
37
+ return;
38
+ }
39
+ const data = bindings != null && Object.keys(bindings).length > 0
40
+ ? { ...bindings, ...(object != null && typeof object === 'object' ? object : {}) } : object;
41
+ log[level](message == null ? '' : message instanceof Error ? message : String(message), data);
42
+ };
43
+ const adapter = {
44
+ get level() { return levelName(log); },
45
+ set level(_value) { },
46
+ fatal: call('error'), error: call('error'), warn: call('warn'),
47
+ info: call('info'), debug: call('debug'), trace: call('debug'),
48
+ silent: () => undefined,
49
+ child: (extra) => fastifyLogger(log, { ...bindings, ...extra }),
50
+ };
51
+ return adapter;
52
+ };
53
+ const levelName = (log) => {
54
+ const order = ['debug', 'info', 'warn', 'error'];
55
+ return order.find(level => log.enabled(level)) ?? 'silent';
56
+ };
57
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/utils/log.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAA8B,MAAM,eAAe,CAAA;AAGlE;;;;;;;;;GASG;AACH,MAAM,OAAO,GAAG,CAAC,KAAe,EAAE,OAAgB,EAAwB,EAAE;IAC1E,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACpD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,IAAI,OAAO,KAAK,kBAAkB,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;QACtE,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,OAAO,CAAC,UAAU,CAAC,qBAAqB,CAAC,IAAI,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACtF,OAAO,OAAO,CAAA;IAChB,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAG,GAAW,MAAM,CAAC,MAAM,CAAC,EAAE,QAAkC,EAAqB,EAAE;IACnH,MAAM,IAAI,GAAG,CAAC,SAAmB,EAAE,EAAE,CAAC,CAAC,KAAc,EAAE,MAAgB,EAAQ,EAAE;QAC/E,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,KAAK;YAC3E,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CA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E,GAAG,QAAQ,EAAE,GAAG,KAAK,EAAE,CAAC;KACzF,CAAA;IACD,OAAO,OAAuC,CAAA;AAChD,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE;IACxC,MAAM,KAAK,GAAe,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAC5D,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,QAAQ,CAAA;AAC5D,CAAC,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { AbstractRequest, AbstractResponse } from '@owlmeans/entrypoint';
2
+ import type { Request, Response } from '../../types.js';
3
+ /** Moves an exchange between Fastify and the entrypoint shapes: the request in, the response out. */
4
+ export interface PayloadHelper {
5
+ /** The entrypoint request of a Fastify request; `provision` keeps the original on it. */
6
+ provideRequest: (alias: string, req: Request, provision?: boolean) => AbstractRequest;
7
+ /**
8
+ * Emits the response onto the fastify reply if the handler produced an
9
+ * error or an outcome. Returns `true` when something was actually sent so
10
+ * callers don't rely on `reply.sent`, which in fastify v5 only flips once
11
+ * the raw socket finishes writing (asynchronously) and therefore reads
12
+ * `false` synchronously right after `reply.send()`.
13
+ *
14
+ * @throws {Error}
15
+ */
16
+ executeResponse: <T>(response: AbstractResponse<T>, reply: Response, throwOnError?: boolean) => boolean;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/payload/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEvD,qGAAqG;AACrG,MAAM,WAAW,aAAa;IAC5B,yFAAyF;IACzF,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,KAAK,eAAe,CAAA;IACrF;;;;;;;;OAQG;IACH,eAAe,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,OAAO,KAAK,OAAO,CAAA;CACxG"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/payload/types.ts"],"names":[],"mappings":""}
@@ -1,16 +1,4 @@
1
- import type { AbstractResponse, AbstractRequest } from '@owlmeans/entrypoint';
2
- import type { Request, Response } from '../types.js';
3
- import type { AnySchemaObject } from 'ajv';
4
- export declare const provideRequest: (alias: string, req: Request, provision?: boolean) => AbstractRequest;
5
- /**
6
- * Emits the response onto the fastify reply if the handler produced an
7
- * error or an outcome. Returns `true` when something was actually sent so
8
- * callers don't rely on `reply.sent`, which in fastify v5 only flips once
9
- * the raw socket finishes writing (asynchronously) and therefore reads
10
- * `false` synchronously right after `reply.send()`.
11
- *
12
- * @throws {Error}
13
- */
14
- export declare const executeResponse: <T>(response: AbstractResponse<T>, reply: Response, throwOnError?: boolean) => boolean;
15
- export declare const fixFormatDates: (schema: AnySchemaObject) => AnySchemaObject;
1
+ import type { PayloadHelper } from './payload/types.js';
2
+ export declare const createPayloadHelper: () => PayloadHelper;
3
+ export declare const payloadHelper: PayloadHelper;
16
4
  //# sourceMappingURL=payload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/utils/payload.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC7E,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,KAAK,CAAA;AAE1C,eAAO,MAAM,cAAc,UAAW,MAAM,OAAO,OAAO,cAAc,OAAO,KAAG,eAYjF,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC,SAAS,QAAQ,iBAAiB,OAAO,KAAG,OAuB3G,CAAA;AAGD,eAAO,MAAM,cAAc,WAAY,eAAe,oBAgBrD,CAAA"}
1
+ {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/utils/payload.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD,eAAO,MAAM,mBAAmB,QAAO,aA4CtC,CAAA;AAED,eAAO,MAAM,aAAa,eAAwB,CAAA"}