@skmtc/core 0.16.1 → 0.16.2

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.
@@ -2,6 +2,8 @@ import "../../_dnt.polyfills.js";
2
2
  import type { Method } from '../../types/Method.js';
3
3
  import type { OasPathItem } from '../pathItem/PathItem.js';
4
4
  import type { OasParameter } from '../parameter/Parameter.js';
5
+ import type { OasParameterLocation } from '../parameter/parameter-types.js';
6
+ import type { OasSchema } from '../schema/Schema.js';
5
7
  import type { OasRequestBody } from '../requestBody/RequestBody.js';
6
8
  import type { OasResponse } from '../response/Response.js';
7
9
  import type { OasRef } from '../ref/Ref.js';
@@ -63,9 +65,12 @@ export type WebhookFields = {
63
65
  * receive one: webhook code generation is a *receiver/handler* concern,
64
66
  * not a client-call concern.
65
67
  *
66
- * This is intentionally a parse-only data class. Webhook-semantic helpers
67
- * (payload schema, ack response, signature verification) accrue when a
68
- * webhook generator needs them (Phase 4), not preemptively.
68
+ * Carries webhook-semantic accessors named for the RECEIVER
69
+ * `toPayload`/`toPayloadSchema` (the received payload), `toParams` (inbound
70
+ * params), `toAckResponse`/`toAckResponseCode` (the ack the handler returns).
71
+ * These deliberately avoid the client-framed {@link OasOperation} names
72
+ * (`toRequestBody`, `toSuccessResponse`) so the inversion stays explicit in
73
+ * generator code. (Signature-verification helpers still accrue on demand.)
69
74
  */
70
75
  export declare class OasWebhook extends OasBase {
71
76
  /** Type identifier for OAS webhook objects */
@@ -101,6 +106,38 @@ export declare class OasWebhook extends OasBase {
101
106
  /** Servers for this webhook */
102
107
  servers: OasServer[] | undefined;
103
108
  constructor(fields: WebhookFields, context?: ParseContextType);
109
+ /**
110
+ * The received-payload body — the request body the API delivers TO the
111
+ * consumer's handler. Webhook semantics are inverted: this is what the
112
+ * handler RECEIVES, not what a client sends. A `$ref` body is resolved.
113
+ */
114
+ toPayload(): OasRequestBody | undefined;
115
+ /**
116
+ * The schema of the received payload for `mediaType` (default
117
+ * `application/json`) — the inbound body shape a handler generator emits a
118
+ * type for. `undefined` when there is no body or no schema for that media
119
+ * type.
120
+ */
121
+ toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
122
+ /**
123
+ * Resolve the inbound parameters (e.g. the signature/headers a handler
124
+ * receives), optionally filtered by location. Mirrors
125
+ * {@link OasOperation.toParams}; the parameters carry the same shape, only
126
+ * their direction is inbound.
127
+ */
128
+ toParams(filter?: OasParameterLocation[]): OasParameter[];
129
+ /**
130
+ * The status code of the primary acknowledgement response — the lowest 2xx
131
+ * the handler returns to ack the delivery, falling back to `default`. Named
132
+ * for the receiver: a webhook's `responses` are what the handler RETURNS,
133
+ * not what a client receives (cf. {@link OasOperation.toSuccessResponseCode}).
134
+ */
135
+ toAckResponseCode(): string | undefined;
136
+ /**
137
+ * The primary acknowledgement response definition (the body/headers the
138
+ * handler returns), or `undefined` when none is declared.
139
+ */
140
+ toAckResponse(): OasResponse | OasRef<'response'> | undefined;
104
141
  /**
105
142
  * Serializes the webhook to a plain JavaScript object.
106
143
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Webhook.d.ts","sourceRoot":"","sources":["../../../src/oas/webhook/Webhook.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAA;AAC3F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAA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} from '../../types/OasBase.js';
9
9
  * receive one: webhook code generation is a *receiver/handler* concern,
10
10
  * not a client-call concern.
11
11
  *
12
- * This is intentionally a parse-only data class. Webhook-semantic helpers
13
- * (payload schema, ack response, signature verification) accrue when a
14
- * webhook generator needs them (Phase 4), not preemptively.
12
+ * Carries webhook-semantic accessors named for the RECEIVER
13
+ * `toPayload`/`toPayloadSchema` (the received payload), `toParams` (inbound
14
+ * params), `toAckResponse`/`toAckResponseCode` (the ack the handler returns).
15
+ * These deliberately avoid the client-framed {@link OasOperation} names
16
+ * (`toRequestBody`, `toSuccessResponse`) so the inversion stays explicit in
17
+ * generator code. (Signature-verification helpers still accrue on demand.)
15
18
  */
16
19
  export class OasWebhook extends OasBase {
17
20
  constructor(fields, context) {
@@ -144,6 +147,61 @@ export class OasWebhook extends OasBase {
144
147
  this.extensionFields = fields.extensionFields;
145
148
  this.servers = fields.servers;
146
149
  }
150
+ /**
151
+ * The received-payload body — the request body the API delivers TO the
152
+ * consumer's handler. Webhook semantics are inverted: this is what the
153
+ * handler RECEIVES, not what a client sends. A `$ref` body is resolved.
154
+ */
155
+ toPayload() {
156
+ return this.requestBody?.resolve();
157
+ }
158
+ /**
159
+ * The schema of the received payload for `mediaType` (default
160
+ * `application/json`) — the inbound body shape a handler generator emits a
161
+ * type for. `undefined` when there is no body or no schema for that media
162
+ * type.
163
+ */
164
+ toPayloadSchema(mediaType = 'application/json') {
165
+ return this.toPayload()?.content[mediaType]?.schema;
166
+ }
167
+ /**
168
+ * Resolve the inbound parameters (e.g. the signature/headers a handler
169
+ * receives), optionally filtered by location. Mirrors
170
+ * {@link OasOperation.toParams}; the parameters carry the same shape, only
171
+ * their direction is inbound.
172
+ */
173
+ toParams(filter) {
174
+ return (this.parameters
175
+ ?.map(param => param.resolve())
176
+ .filter(param => (filter?.length ? filter.includes(param.location) : true)) ?? []);
177
+ }
178
+ /**
179
+ * The status code of the primary acknowledgement response — the lowest 2xx
180
+ * the handler returns to ack the delivery, falling back to `default`. Named
181
+ * for the receiver: a webhook's `responses` are what the handler RETURNS,
182
+ * not what a client receives (cf. {@link OasOperation.toSuccessResponseCode}).
183
+ */
184
+ toAckResponseCode() {
185
+ const ackCode = Object.keys(this.responses)
186
+ .map(httpCode => parseInt(httpCode))
187
+ .sort((a, b) => a - b)
188
+ .find(httpCode => httpCode >= 200 && httpCode < 300);
189
+ if (ackCode) {
190
+ return ackCode.toString();
191
+ }
192
+ if (this.responses.default) {
193
+ return 'default';
194
+ }
195
+ return undefined;
196
+ }
197
+ /**
198
+ * The primary acknowledgement response definition (the body/headers the
199
+ * handler returns), or `undefined` when none is declared.
200
+ */
201
+ toAckResponse() {
202
+ const ackCode = this.toAckResponseCode();
203
+ return ackCode ? this.responses[ackCode] : undefined;
204
+ }
147
205
  /**
148
206
  * Serializes the webhook to a plain JavaScript object.
149
207
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -2,6 +2,8 @@ import "../../_dnt.polyfills.js";
2
2
  import type { Method } from '../../types/Method.js';
3
3
  import type { OasPathItem } from '../pathItem/PathItem.js';
4
4
  import type { OasParameter } from '../parameter/Parameter.js';
5
+ import type { OasParameterLocation } from '../parameter/parameter-types.js';
6
+ import type { OasSchema } from '../schema/Schema.js';
5
7
  import type { OasRequestBody } from '../requestBody/RequestBody.js';
6
8
  import type { OasResponse } from '../response/Response.js';
7
9
  import type { OasRef } from '../ref/Ref.js';
@@ -63,9 +65,12 @@ export type WebhookFields = {
63
65
  * receive one: webhook code generation is a *receiver/handler* concern,
64
66
  * not a client-call concern.
65
67
  *
66
- * This is intentionally a parse-only data class. Webhook-semantic helpers
67
- * (payload schema, ack response, signature verification) accrue when a
68
- * webhook generator needs them (Phase 4), not preemptively.
68
+ * Carries webhook-semantic accessors named for the RECEIVER
69
+ * `toPayload`/`toPayloadSchema` (the received payload), `toParams` (inbound
70
+ * params), `toAckResponse`/`toAckResponseCode` (the ack the handler returns).
71
+ * These deliberately avoid the client-framed {@link OasOperation} names
72
+ * (`toRequestBody`, `toSuccessResponse`) so the inversion stays explicit in
73
+ * generator code. (Signature-verification helpers still accrue on demand.)
69
74
  */
70
75
  export declare class OasWebhook extends OasBase {
71
76
  /** Type identifier for OAS webhook objects */
@@ -101,6 +106,38 @@ export declare class OasWebhook extends OasBase {
101
106
  /** Servers for this webhook */
102
107
  servers: OasServer[] | undefined;
103
108
  constructor(fields: WebhookFields, context?: ParseContextType);
109
+ /**
110
+ * The received-payload body — the request body the API delivers TO the
111
+ * consumer's handler. Webhook semantics are inverted: this is what the
112
+ * handler RECEIVES, not what a client sends. A `$ref` body is resolved.
113
+ */
114
+ toPayload(): OasRequestBody | undefined;
115
+ /**
116
+ * The schema of the received payload for `mediaType` (default
117
+ * `application/json`) — the inbound body shape a handler generator emits a
118
+ * type for. `undefined` when there is no body or no schema for that media
119
+ * type.
120
+ */
121
+ toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
122
+ /**
123
+ * Resolve the inbound parameters (e.g. the signature/headers a handler
124
+ * receives), optionally filtered by location. Mirrors
125
+ * {@link OasOperation.toParams}; the parameters carry the same shape, only
126
+ * their direction is inbound.
127
+ */
128
+ toParams(filter?: OasParameterLocation[]): OasParameter[];
129
+ /**
130
+ * The status code of the primary acknowledgement response — the lowest 2xx
131
+ * the handler returns to ack the delivery, falling back to `default`. Named
132
+ * for the receiver: a webhook's `responses` are what the handler RETURNS,
133
+ * not what a client receives (cf. {@link OasOperation.toSuccessResponseCode}).
134
+ */
135
+ toAckResponseCode(): string | undefined;
136
+ /**
137
+ * The primary acknowledgement response definition (the body/headers the
138
+ * handler returns), or `undefined` when none is declared.
139
+ */
140
+ toAckResponse(): OasResponse | OasRef<'response'> | undefined;
104
141
  /**
105
142
  * Serializes the webhook to a plain JavaScript object.
106
143
  */
@@ -1 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,+BAA+B;IAC/B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;gBAEpB,MAAM,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAmB7D;;;;OAIG;IACH,SAAS,IAAI,cAAc,GAAG,SAAS;IAIvC;;;;;OAKG;IACH,eAAe,CAAC,SAAS,SAAqB,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAIzF;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,oBAAoB,EAAE,GAAG,YAAY,EAAE;IAQzD;;;;;OAKG;IACH,iBAAiB,IAAI,MAAM,GAAG,SAAS;IAiBvC;;;OAGG;IACH,aAAa,IAAI,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,SAAS;IAM7D;;OAEG;IACH,MAAM,IAAI,MAAM;CAgBjB"}
@@ -12,9 +12,12 @@ const OasBase_js_1 = require("../../types/OasBase.js");
12
12
  * receive one: webhook code generation is a *receiver/handler* concern,
13
13
  * not a client-call concern.
14
14
  *
15
- * This is intentionally a parse-only data class. Webhook-semantic helpers
16
- * (payload schema, ack response, signature verification) accrue when a
17
- * webhook generator needs them (Phase 4), not preemptively.
15
+ * Carries webhook-semantic accessors named for the RECEIVER
16
+ * `toPayload`/`toPayloadSchema` (the received payload), `toParams` (inbound
17
+ * params), `toAckResponse`/`toAckResponseCode` (the ack the handler returns).
18
+ * These deliberately avoid the client-framed {@link OasOperation} names
19
+ * (`toRequestBody`, `toSuccessResponse`) so the inversion stays explicit in
20
+ * generator code. (Signature-verification helpers still accrue on demand.)
18
21
  */
19
22
  class OasWebhook extends OasBase_js_1.OasBase {
20
23
  constructor(fields, context) {
@@ -147,6 +150,61 @@ class OasWebhook extends OasBase_js_1.OasBase {
147
150
  this.extensionFields = fields.extensionFields;
148
151
  this.servers = fields.servers;
149
152
  }
153
+ /**
154
+ * The received-payload body — the request body the API delivers TO the
155
+ * consumer's handler. Webhook semantics are inverted: this is what the
156
+ * handler RECEIVES, not what a client sends. A `$ref` body is resolved.
157
+ */
158
+ toPayload() {
159
+ return this.requestBody?.resolve();
160
+ }
161
+ /**
162
+ * The schema of the received payload for `mediaType` (default
163
+ * `application/json`) — the inbound body shape a handler generator emits a
164
+ * type for. `undefined` when there is no body or no schema for that media
165
+ * type.
166
+ */
167
+ toPayloadSchema(mediaType = 'application/json') {
168
+ return this.toPayload()?.content[mediaType]?.schema;
169
+ }
170
+ /**
171
+ * Resolve the inbound parameters (e.g. the signature/headers a handler
172
+ * receives), optionally filtered by location. Mirrors
173
+ * {@link OasOperation.toParams}; the parameters carry the same shape, only
174
+ * their direction is inbound.
175
+ */
176
+ toParams(filter) {
177
+ return (this.parameters
178
+ ?.map(param => param.resolve())
179
+ .filter(param => (filter?.length ? filter.includes(param.location) : true)) ?? []);
180
+ }
181
+ /**
182
+ * The status code of the primary acknowledgement response — the lowest 2xx
183
+ * the handler returns to ack the delivery, falling back to `default`. Named
184
+ * for the receiver: a webhook's `responses` are what the handler RETURNS,
185
+ * not what a client receives (cf. {@link OasOperation.toSuccessResponseCode}).
186
+ */
187
+ toAckResponseCode() {
188
+ const ackCode = Object.keys(this.responses)
189
+ .map(httpCode => parseInt(httpCode))
190
+ .sort((a, b) => a - b)
191
+ .find(httpCode => httpCode >= 200 && httpCode < 300);
192
+ if (ackCode) {
193
+ return ackCode.toString();
194
+ }
195
+ if (this.responses.default) {
196
+ return 'default';
197
+ }
198
+ return undefined;
199
+ }
200
+ /**
201
+ * The primary acknowledgement response definition (the body/headers the
202
+ * handler returns), or `undefined` when none is declared.
203
+ */
204
+ toAckResponse() {
205
+ const ackCode = this.toAckResponseCode();
206
+ return ackCode ? this.responses[ackCode] : undefined;
207
+ }
150
208
  /**
151
209
  * Serializes the webhook to a plain JavaScript object.
152
210
  */