@cap-ts/soap-adapter 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +135 -60
- package/index.cds +8 -9
- package/package.json +1 -1
- package/src/_license/index.js +1 -1
- package/src/index.js +1 -1
- package/src/lib/_base/index.js +1 -1
- package/src/lib/_builder/index.js +1 -1
- package/src/lib/_client/index.js +1 -1
- package/src/lib/_loader/index.js +1 -1
- package/src/lib/_log/index.js +1 -1
- package/src/lib/_orchestrator/index.js +1 -1
- package/src/lib/_read/index.js +1 -1
- package/src/lib/_request/index.js +1 -1
- package/src/lib/_util/entity.js +1 -1
- package/src/lib/index.js +1 -1
- package/types/index.d.ts +8 -9
- package/types/lib/index.d.ts +69 -183
package/types/lib/index.d.ts
CHANGED
|
@@ -2,37 +2,24 @@
|
|
|
2
2
|
* @module @cap-ts/soap-adapter/lib
|
|
3
3
|
* @description Public API surface of the `@cap-ts/soap-adapter` library.
|
|
4
4
|
*
|
|
5
|
-
* Exports {@link
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* `
|
|
5
|
+
* Exports {@link Service} — the CAP service class that every SOAP adapter
|
|
6
|
+
* extends — along with {@link FORBIDDEN_SOAP_HEADERS} and a set of re-exported
|
|
7
|
+
* utilities (`createRequest`, `getEntityKeyFields`, `dedupByKeys`,
|
|
8
|
+
* `isSoapService`, `read`).
|
|
9
9
|
*
|
|
10
|
-
* The loader (`_loader/index`)
|
|
11
|
-
*
|
|
12
|
-
* (
|
|
10
|
+
* The loader (`_loader/index`) resolves the subclass of a SOAP service
|
|
11
|
+
* (`@Soap.adapter`, `cds.requires.<Service>.impl` or the file convention),
|
|
12
|
+
* constructs it once as the CAP service and awaits its `init()`.
|
|
13
13
|
*
|
|
14
|
-
* @see {@link
|
|
14
|
+
* @see {@link Service}
|
|
15
15
|
* @see {@link FORBIDDEN_SOAP_HEADERS}
|
|
16
16
|
*/
|
|
17
|
-
import type { Request } from '@sap/cds';
|
|
17
|
+
import type { Request, Service as CdsService } from '@sap/cds';
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* reconstruct the context from the raw CAP request.
|
|
22
|
-
*
|
|
23
|
-
* @interface TraceContext
|
|
24
|
-
* @property {string} correlationId - Platform-level correlation ID (e.g.
|
|
25
|
-
* `x-vcap-request-id` or `x-correlation-id` from the inbound request).
|
|
26
|
-
* @property {string} user - The authenticated user identifier, typically
|
|
27
|
-
* `req.user.id` as resolved by CAP's authentication middleware.
|
|
28
|
-
* @property {string} timestamp - ISO-8601 timestamp captured at the start
|
|
29
|
-
* of the request, used for log ordering and latency calculations.
|
|
19
|
+
* The internal CAP service that runs the READ pipeline (`_base`). Typed as `cds.Service` so the published
|
|
20
|
+
* declarations stay self-contained.
|
|
30
21
|
*/
|
|
31
|
-
|
|
32
|
-
correlationId: string;
|
|
33
|
-
user: string;
|
|
34
|
-
timestamp: string;
|
|
35
|
-
}
|
|
22
|
+
declare const BaseService: typeof CdsService;
|
|
36
23
|
/**
|
|
37
24
|
* Minimal shape of a CAP CSN entity reflection object as seen at runtime.
|
|
38
25
|
* The full `cds.linked` entity carries many more fields; only the subset
|
|
@@ -40,13 +27,13 @@ export interface TraceContext {
|
|
|
40
27
|
*
|
|
41
28
|
* @interface CdsEntity
|
|
42
29
|
* @property {string} name - Fully qualified entity name, e.g.
|
|
43
|
-
* `'ext.
|
|
30
|
+
* `'ext.BusinessPartners'`.
|
|
44
31
|
* @property {Record<string, CdsEntityElement>} elements - Map of element
|
|
45
32
|
* (field) name → element descriptor.
|
|
46
33
|
* @property {SoapBindingConfig} [@Soap.binding] - Optional SOAP binding
|
|
47
34
|
* annotation placed on the entity in the `.cds` model.
|
|
48
35
|
* @property {{ name: string }} parent - The parent service or namespace
|
|
49
|
-
* object
|
|
36
|
+
* object.
|
|
50
37
|
*/
|
|
51
38
|
export interface CdsEntity {
|
|
52
39
|
name: string;
|
|
@@ -72,15 +59,12 @@ export interface CdsEntityElement {
|
|
|
72
59
|
[key: string]: unknown;
|
|
73
60
|
}
|
|
74
61
|
/**
|
|
75
|
-
* Value of the `@Soap.binding` annotation on a CDS entity
|
|
76
|
-
*
|
|
62
|
+
* Value of the `@Soap.binding` annotation on a CDS entity, as the loader
|
|
63
|
+
* assembles it when the service starts.
|
|
77
64
|
*
|
|
78
65
|
* @interface SoapBindingConfig
|
|
79
66
|
* @property {string} operation - SOAP operation name (WSDL `<operation>`),
|
|
80
67
|
* e.g. `'GetBusinessPartnerCollection'`.
|
|
81
|
-
* @property {new (entity: CdsEntity, req: Request, trace: TraceContext) => BaseAdapterInstance} [resolvedAdapterClass]
|
|
82
|
-
* - The adapter subclass constructor resolved by the loader. Absent until
|
|
83
|
-
* the loader has completed its discovery pass.
|
|
84
68
|
* @property {string} [rootRequest] - Optional XPath root element to wrap
|
|
85
69
|
* the outbound SOAP request payload in.
|
|
86
70
|
* @property {string} [rootResponse] - Optional XPath root element to unwrap
|
|
@@ -88,10 +72,16 @@ export interface CdsEntityElement {
|
|
|
88
72
|
*/
|
|
89
73
|
export interface SoapBindingConfig {
|
|
90
74
|
operation: string;
|
|
91
|
-
resolvedAdapterClass?: new (entity: CdsEntity, req: Request, trace: TraceContext) => BaseAdapterInstance;
|
|
92
75
|
rootRequest?: string;
|
|
93
76
|
rootResponse?: string;
|
|
94
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* The entity a hook is registered for: its name, qualified (`'ext.BusinessPartner'`) or not (`'BusinessPartner'`), or
|
|
80
|
+
* any object with a `name`, such as an entity of `this.entities` (CAP's entity type) or a {@link CdsEntity}.
|
|
81
|
+
*/
|
|
82
|
+
export type HookTarget = string | {
|
|
83
|
+
name: string;
|
|
84
|
+
};
|
|
95
85
|
/**
|
|
96
86
|
* A single SOAP header entry. Either a static object passed directly to
|
|
97
87
|
* `header()` or the resolved return value of a `SoapHeaderEvaluator`
|
|
@@ -111,30 +101,6 @@ export interface SoapHeaderObject {
|
|
|
111
101
|
xmlns?: string;
|
|
112
102
|
[key: string]: unknown;
|
|
113
103
|
}
|
|
114
|
-
/**
|
|
115
|
-
* Minimal structural contract that every `ApplicationService` instance must
|
|
116
|
-
* satisfy so the orchestrator can dispatch hooks without knowing the
|
|
117
|
-
* concrete subclass.
|
|
118
|
-
*
|
|
119
|
-
* @interface BaseAdapterInstance
|
|
120
|
-
* @property {Record<string, Array<Function>>} _requestHandlers - Per-entity
|
|
121
|
-
* ordered list of outbound payload transformers registered via
|
|
122
|
-
* {@link ApplicationService#request}.
|
|
123
|
-
* @property {Record<string, Function>} _mockHandlers - Per-entity mock
|
|
124
|
-
* replacements registered via {@link ApplicationService#mock}. Only one
|
|
125
|
-
* mock per entity; the last registration wins.
|
|
126
|
-
* @property {Record<string, Array<SoapHeaderObject|Function>>} _headerHandlers
|
|
127
|
-
* - Per-entity header providers registered via {@link ApplicationService#header}.
|
|
128
|
-
* @property {Record<string, Array<Function>>} _responseHandlers - Per-entity
|
|
129
|
-
* ordered list of response mappers registered via
|
|
130
|
-
* {@link ApplicationService#response}.
|
|
131
|
-
*/
|
|
132
|
-
export interface BaseAdapterInstance {
|
|
133
|
-
_requestHandlers: Record<string, Array<(req: Request, payload: unknown) => Promise<unknown> | unknown>>;
|
|
134
|
-
_mockHandlers: Record<string, (req: Request, payload: unknown) => Promise<unknown>>;
|
|
135
|
-
_headerHandlers: Record<string, Array<SoapHeaderObject | ((req: Request, payload: unknown) => Promise<SoapHeaderObject> | SoapHeaderObject)>>;
|
|
136
|
-
_responseHandlers: Record<string, Array<(req: Request, rows: object[]) => Promise<object[]> | object[]>>;
|
|
137
|
-
}
|
|
138
104
|
/**
|
|
139
105
|
* Frozen, read-only list of HTTP header names that must **never** flow from
|
|
140
106
|
* an inbound CAP request into an outbound SOAP call.
|
|
@@ -151,105 +117,82 @@ export interface BaseAdapterInstance {
|
|
|
151
117
|
* - **Security tokens**: `x-csrf-token`, `sec-websocket-key`,
|
|
152
118
|
* `sec-websocket-accept`.
|
|
153
119
|
*
|
|
154
|
-
* The list is exposed as `
|
|
120
|
+
* The list is exposed as `Service.FORBIDDEN_SOAP_HEADERS` so
|
|
155
121
|
* consumers can inspect it. It is frozen; mutating it will throw in strict
|
|
156
122
|
* mode. To extend it, clone the array and add your own entries.
|
|
157
123
|
*
|
|
158
|
-
* @see {@link
|
|
124
|
+
* @see {@link Service.stripSensitiveHeaders}
|
|
159
125
|
*/
|
|
160
126
|
declare const FORBIDDEN_SOAP_HEADERS: readonly string[];
|
|
161
127
|
/**
|
|
162
|
-
*
|
|
128
|
+
* The CAP service of a SOAP web service (`cds.requires.<Service>.kind: 'soap'`).
|
|
163
129
|
*
|
|
164
|
-
* Consumers subclass
|
|
165
|
-
*
|
|
166
|
-
* {@link
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* the service's `.cds`
|
|
130
|
+
* Consumers subclass it once per SOAP service, register their hooks
|
|
131
|
+
* ({@link Service#header}, {@link Service#request}, {@link Service#mock},
|
|
132
|
+
* {@link Service#response}) in `init()` and end `init()` with
|
|
133
|
+
* `await super.init()`, which registers the READ pipeline. The class is found
|
|
134
|
+
* through `@Soap.adapter` on the service, `cds.requires.<Service>.impl`, or the
|
|
135
|
+
* file `<Service>.js` / `<Service>.ts` in the folder of the service's `.cds`
|
|
136
|
+
* file, its `lib/` or its `handlers/` sub-folder.
|
|
170
137
|
*
|
|
171
138
|
* **Contract:**
|
|
172
|
-
* - **One instance per
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
* -
|
|
176
|
-
*
|
|
139
|
+
* - **One instance per service**, constructed by the plugin (or by CAP) like
|
|
140
|
+
* any CAP service: `new (name, model, options)`, then `await init()`. Keep no
|
|
141
|
+
* request state on `this`; every hook gets the current request as `req`.
|
|
142
|
+
* - **CAP handlers work as usual**: `this.before`, `this.on` and `this.after`
|
|
143
|
+
* registered before `await super.init()` run around (or instead of) the SOAP
|
|
144
|
+
* READ pipeline; call `next()` in an `on` handler to reach it.
|
|
177
145
|
* - **Hooks are dispatched by unqualified entity short-name** (e.g.
|
|
178
|
-
* `'BusinessPartner'`, not `'ext.BusinessPartner'`).
|
|
146
|
+
* `'BusinessPartner'`, not `'ext.BusinessPartner'`). The `targets`
|
|
179
147
|
* parameter of each registration method accepts strings, CSN entity
|
|
180
148
|
* objects, arrays of either, or comma-separated strings.
|
|
181
149
|
*
|
|
182
|
-
* @abstract
|
|
183
150
|
* @example
|
|
184
|
-
* //
|
|
185
|
-
* class
|
|
186
|
-
* init() {
|
|
187
|
-
* this.request('
|
|
151
|
+
* // srv/external/lib/BusinessPartnerService.js
|
|
152
|
+
* class BusinessPartnerService extends soap.Service {
|
|
153
|
+
* async init() {
|
|
154
|
+
* this.request('Products', async (req) => ({
|
|
188
155
|
* ProductID: req.data.ID,
|
|
189
156
|
* }));
|
|
190
|
-
* this.response('
|
|
157
|
+
* this.response('Products', (req, rows) =>
|
|
191
158
|
* rows.map(r => ({ ...r, _source: 'soap' }))
|
|
192
159
|
* );
|
|
160
|
+
* await super.init();
|
|
193
161
|
* }
|
|
194
162
|
* }
|
|
195
|
-
* module.exports =
|
|
163
|
+
* module.exports = BusinessPartnerService;
|
|
196
164
|
*/
|
|
197
|
-
declare class
|
|
165
|
+
declare class Service extends BaseService {
|
|
198
166
|
/**
|
|
199
167
|
* Frozen array of HTTP header names that must never be forwarded to a
|
|
200
|
-
* SOAP backend. Used by {@link
|
|
168
|
+
* SOAP backend. Used by {@link Service.stripSensitiveHeaders}.
|
|
201
169
|
* @static
|
|
202
170
|
* @readonly
|
|
203
171
|
* @public
|
|
204
172
|
*/
|
|
205
173
|
static readonly FORBIDDEN_SOAP_HEADERS: readonly string[];
|
|
206
|
-
/**
|
|
207
|
-
* CSN entity reflection object for the entity this adapter instance
|
|
208
|
-
* serves. Populated by the constructor before `init()` is called.
|
|
209
|
-
* @public
|
|
210
|
-
*/
|
|
211
|
-
entity: CdsEntity;
|
|
212
|
-
/**
|
|
213
|
-
* The current CAP request. Available as `this.req` inside all hooks.
|
|
214
|
-
* @public
|
|
215
|
-
*/
|
|
216
|
-
req: Request;
|
|
217
|
-
/**
|
|
218
|
-
* Correlation / tracing identifiers forwarded from the orchestrator.
|
|
219
|
-
* Forwarded to every hook invocation for structured logging.
|
|
220
|
-
* @public
|
|
221
|
-
*/
|
|
222
|
-
traceContext: TraceContext;
|
|
223
|
-
/**
|
|
224
|
-
* All entities exposed by the parent CAP service, keyed by unqualified
|
|
225
|
-
* short-name. Populated automatically from `cds.services[parentName].entities`
|
|
226
|
-
* in the constructor. Empty object `{}` when the parent service cannot
|
|
227
|
-
* be resolved (e.g. in unit tests that do not boot a full CAP server).
|
|
228
|
-
* @public
|
|
229
|
-
*/
|
|
230
|
-
entities: Record<string, CdsEntity>;
|
|
231
174
|
/**
|
|
232
175
|
* Per-entity ordered list of outbound payload transformer functions
|
|
233
|
-
* registered via {@link
|
|
176
|
+
* registered via {@link Service#request}.
|
|
234
177
|
* @protected
|
|
235
178
|
*/
|
|
236
179
|
protected _requestHandlers: Record<string, Array<(req: Request, payload: unknown) => Promise<unknown> | unknown>>;
|
|
237
180
|
/**
|
|
238
181
|
* Per-entity ordered list of response mapper functions registered via
|
|
239
|
-
* {@link
|
|
182
|
+
* {@link Service#response}.
|
|
240
183
|
* @protected
|
|
241
184
|
*/
|
|
242
185
|
protected _responseHandlers: Record<string, Array<(req: Request, rows: object[]) => Promise<object[]> | object[]>>;
|
|
243
186
|
/**
|
|
244
187
|
* Per-entity mock replacement functions registered via
|
|
245
|
-
* {@link
|
|
188
|
+
* {@link Service#mock}. Only one mock per entity; the last
|
|
246
189
|
* registration wins.
|
|
247
190
|
* @protected
|
|
248
191
|
*/
|
|
249
192
|
protected _mockHandlers: Record<string, (req: Request, payload: unknown) => Promise<unknown>>;
|
|
250
193
|
/**
|
|
251
194
|
* Per-entity header providers (static objects or evaluator functions)
|
|
252
|
-
* registered via {@link
|
|
195
|
+
* registered via {@link Service#header}.
|
|
253
196
|
* @protected
|
|
254
197
|
*/
|
|
255
198
|
protected _headerHandlers: Record<string, Array<SoapHeaderObject | ((req: Request, payload: unknown) => Promise<SoapHeaderObject> | SoapHeaderObject)>>;
|
|
@@ -262,7 +205,7 @@ declare class ApplicationService {
|
|
|
262
205
|
* throwing, so callers can safely pass `req.headers ?? {}` without a
|
|
263
206
|
* guard.
|
|
264
207
|
*
|
|
265
|
-
* The allowlist is exposed as `
|
|
208
|
+
* The allowlist is exposed as `Service.FORBIDDEN_SOAP_HEADERS`
|
|
266
209
|
* (frozen). Consumers can extend it by cloning the array and adding
|
|
267
210
|
* extra entries; mutating the exported constant throws in strict mode.
|
|
268
211
|
*
|
|
@@ -273,69 +216,12 @@ declare class ApplicationService {
|
|
|
273
216
|
* @example
|
|
274
217
|
* // Inside a header() hook:
|
|
275
218
|
* this.header(Entity, (req) =>
|
|
276
|
-
*
|
|
219
|
+
* soap.Service.stripSensitiveHeaders(req.headers ?? {})
|
|
277
220
|
* );
|
|
278
221
|
* @static
|
|
279
222
|
* @public
|
|
280
223
|
*/
|
|
281
224
|
static stripSensitiveHeaders(headers: Record<string, unknown>): Record<string, unknown>;
|
|
282
|
-
/**
|
|
283
|
-
* Initialise the adapter instance for a single CAP request.
|
|
284
|
-
*
|
|
285
|
-
* Performs the following steps in order:
|
|
286
|
-
* 1. Guards against direct instantiation (abstract-class enforcement).
|
|
287
|
-
* 2. Stores `entity`, `req`, and `traceContext` on `this`.
|
|
288
|
-
* 3. Initialises the four empty handler registries
|
|
289
|
-
* (`_requestHandlers`, `_responseHandlers`, `_mockHandlers`,
|
|
290
|
-
* `_headerHandlers`).
|
|
291
|
-
* 4. Resolves the parent service name from the entity reflection and
|
|
292
|
-
* binds `this.entities` from `cds.services[parentName].entities`.
|
|
293
|
-
* 5. Calls `_superInit()` (framework extension point, currently a no-op).
|
|
294
|
-
* 6. Calls `init()` so the subclass can register its hooks.
|
|
295
|
-
*
|
|
296
|
-
* @param {CdsEntity} entity - CSN entity reflection for the entity this
|
|
297
|
-
* adapter serves (e.g. `srv.entities.CustomerSet`).
|
|
298
|
-
* @param {Request} req - The current CAP request. Available as
|
|
299
|
-
* `this.req` inside all hook callbacks.
|
|
300
|
-
* @param {TraceContext} traceContext - Correlation IDs for structured
|
|
301
|
-
* logs; forwarded to every hook invocation.
|
|
302
|
-
* @throws {TypeError} If instantiated directly (i.e. `new.target ===
|
|
303
|
-
* ApplicationService`) instead of via a concrete subclass.
|
|
304
|
-
* @public
|
|
305
|
-
*/
|
|
306
|
-
constructor(entity: CdsEntity, req: Request, traceContext: TraceContext);
|
|
307
|
-
/**
|
|
308
|
-
* Framework extension point called by the constructor immediately before
|
|
309
|
-
* {@link ApplicationService#init}. Currently a no-op; reserved for
|
|
310
|
-
* future default initialisation steps (e.g. injecting framework-level
|
|
311
|
-
* hooks or populating shared metadata).
|
|
312
|
-
*
|
|
313
|
-
* Subclasses **may** call `super._superInit()` from their own `init()`
|
|
314
|
-
* for forward-compatibility, but nothing depends on it today.
|
|
315
|
-
*
|
|
316
|
-
* Visibility is `protected` (not `private`) because the documented
|
|
317
|
-
* override contract via `super._superInit()` requires subclass access.
|
|
318
|
-
*
|
|
319
|
-
* @returns {void}
|
|
320
|
-
* @protected
|
|
321
|
-
*/
|
|
322
|
-
protected _superInit(): void;
|
|
323
|
-
/**
|
|
324
|
-
* Lifecycle hook called once from the constructor after all instance
|
|
325
|
-
* fields are populated. Subclasses **must** override this method and
|
|
326
|
-
* use it to register their SOAP hooks via `header()`, `request()`,
|
|
327
|
-
* `mock()`, and/or `response()`.
|
|
328
|
-
*
|
|
329
|
-
* The base implementation throws unconditionally so that a missing
|
|
330
|
-
* override is caught at instantiation time rather than silently
|
|
331
|
-
* producing a no-op adapter.
|
|
332
|
-
*
|
|
333
|
-
* @abstract
|
|
334
|
-
* @throws {Error} Always — subclasses must override this method.
|
|
335
|
-
* @returns {void}
|
|
336
|
-
* @public
|
|
337
|
-
*/
|
|
338
|
-
init(): void;
|
|
339
225
|
/**
|
|
340
226
|
* Normalise a `targets` argument into a flat, deduplicated list of
|
|
341
227
|
* unqualified entity short-names used as internal dispatch keys.
|
|
@@ -350,7 +236,7 @@ declare class ApplicationService {
|
|
|
350
236
|
* - **Array** of any of the above → recursively flattened.
|
|
351
237
|
* - `null` / `undefined` / empty string → returns `[]`.
|
|
352
238
|
*
|
|
353
|
-
* @param {
|
|
239
|
+
* @param {HookTarget|HookTarget[]|null|undefined} targets
|
|
354
240
|
* - One or more entity references to normalise.
|
|
355
241
|
* @returns {string[]} Zero or more unqualified entity short-names.
|
|
356
242
|
* @private
|
|
@@ -372,9 +258,9 @@ declare class ApplicationService {
|
|
|
372
258
|
*
|
|
373
259
|
* Common use: strip sensitive inbound HTTP headers before forwarding
|
|
374
260
|
* them to the SOAP backend — see
|
|
375
|
-
* {@link
|
|
261
|
+
* {@link Service.stripSensitiveHeaders}.
|
|
376
262
|
*
|
|
377
|
-
* @param {
|
|
263
|
+
* @param {HookTarget|HookTarget[]} targets - One or
|
|
378
264
|
* more entity references that this header provider applies to.
|
|
379
265
|
* @param {SoapHeaderObject|((req: Request, payload: *) => Promise<SoapHeaderObject>|SoapHeaderObject)} handler
|
|
380
266
|
* - Static header object or evaluator function.
|
|
@@ -382,7 +268,7 @@ declare class ApplicationService {
|
|
|
382
268
|
* @returns {void}
|
|
383
269
|
* @public
|
|
384
270
|
*/
|
|
385
|
-
header(targets:
|
|
271
|
+
header(targets: HookTarget | HookTarget[], handler: SoapHeaderObject | ((req: Request, payload: unknown) => Promise<SoapHeaderObject> | SoapHeaderObject)): void;
|
|
386
272
|
/**
|
|
387
273
|
* Register a hook that shapes the outbound SOAP payload for one or more
|
|
388
274
|
* entities.
|
|
@@ -393,7 +279,7 @@ declare class ApplicationService {
|
|
|
393
279
|
* invocation receives the output of the previous stage. The same
|
|
394
280
|
* handler reference passed twice is de-duplicated.
|
|
395
281
|
*
|
|
396
|
-
* @param {
|
|
282
|
+
* @param {HookTarget|HookTarget[]} targets - One or
|
|
397
283
|
* more entity references that this request transformer applies to.
|
|
398
284
|
* @param {(req: Request, payload: *) => Promise<*>|*} handler - A
|
|
399
285
|
* function that receives the CAP request and the current payload, and
|
|
@@ -402,7 +288,7 @@ declare class ApplicationService {
|
|
|
402
288
|
* @returns {void}
|
|
403
289
|
* @public
|
|
404
290
|
*/
|
|
405
|
-
request(targets:
|
|
291
|
+
request(targets: HookTarget | HookTarget[], handler: (req: Request, payload: unknown) => Promise<unknown> | unknown): void;
|
|
406
292
|
/**
|
|
407
293
|
* Register a mock that fully replaces the SOAP round-trip for the given
|
|
408
294
|
* entity/entities.
|
|
@@ -415,7 +301,7 @@ declare class ApplicationService {
|
|
|
415
301
|
* Intended for unit tests. Not subject to error sanitisation — any
|
|
416
302
|
* exception thrown by the mock is surfaced as-is to the caller.
|
|
417
303
|
*
|
|
418
|
-
* @param {
|
|
304
|
+
* @param {HookTarget|HookTarget[]} targets - One or
|
|
419
305
|
* more entity references to mock.
|
|
420
306
|
* @param {(req: Request, payload: *) => Promise<*>|*} handler - A
|
|
421
307
|
* function that receives the CAP request and the current payload, and
|
|
@@ -424,7 +310,7 @@ declare class ApplicationService {
|
|
|
424
310
|
* @returns {void}
|
|
425
311
|
* @public
|
|
426
312
|
*/
|
|
427
|
-
mock(targets:
|
|
313
|
+
mock(targets: HookTarget | HookTarget[], handler: (req: Request, payload: unknown) => Promise<unknown>): void;
|
|
428
314
|
/**
|
|
429
315
|
* Register a hook that maps the raw SOAP response array into the flat
|
|
430
316
|
* row shape that CAP expects for the target entity.
|
|
@@ -434,7 +320,7 @@ declare class ApplicationService {
|
|
|
434
320
|
* `header` and `request`, this hook is **not** de-duplicated —
|
|
435
321
|
* registering the same handler reference twice causes it to run twice.
|
|
436
322
|
*
|
|
437
|
-
* @param {
|
|
323
|
+
* @param {HookTarget|HookTarget[]} targets - One or
|
|
438
324
|
* more entity references that this response mapper applies to.
|
|
439
325
|
* @param {(req: Request, rows: object[]) => Promise<object[]>|object[]} handler
|
|
440
326
|
* - A function that receives the CAP request and the current row
|
|
@@ -443,7 +329,7 @@ declare class ApplicationService {
|
|
|
443
329
|
* @returns {void}
|
|
444
330
|
* @public
|
|
445
331
|
*/
|
|
446
|
-
response(targets:
|
|
332
|
+
response(targets: HookTarget | HookTarget[], handler: (req: Request, rows: object[]) => Promise<object[]> | object[]): void;
|
|
447
333
|
}
|
|
448
334
|
/** Options accepted by {@link createRequest}. */
|
|
449
335
|
export interface CreateRequestOptions {
|
|
@@ -485,7 +371,7 @@ export interface CsnEntityDefinition {
|
|
|
485
371
|
}
|
|
486
372
|
/**
|
|
487
373
|
* Minimal structural shape of a CDS entity definition accepted by
|
|
488
|
-
* {@link read} (for example `srv.entities.
|
|
374
|
+
* {@link read} (for example `srv.entities.BusinessPartners`).
|
|
489
375
|
*/
|
|
490
376
|
export interface CdsEntityDef {
|
|
491
377
|
name?: string;
|
|
@@ -530,7 +416,7 @@ export interface ReadOptions {
|
|
|
530
416
|
* @example
|
|
531
417
|
* const req = soap.createRequest({
|
|
532
418
|
* event: 'READ',
|
|
533
|
-
* query: SELECT.from('ext.
|
|
419
|
+
* query: SELECT.from('ext.BusinessPartners'),
|
|
534
420
|
* headers: { 'accept-language': 'en' },
|
|
535
421
|
* user: inboundReq.user,
|
|
536
422
|
* });
|
|
@@ -585,7 +471,7 @@ declare const isSoapService: (serviceName: string) => boolean;
|
|
|
585
471
|
* One-shot SOAP read: assemble headers, build a real `cds.Request`, dispatch,
|
|
586
472
|
* and deduplicate the result by entity key fields.
|
|
587
473
|
*
|
|
588
|
-
* @param {SoapService} srv - The SOAP `
|
|
474
|
+
* @param {SoapService} srv - The SOAP service (`cds.services[<name>]`).
|
|
589
475
|
* @param {string} entity - Key into `srv.entities`; used for key-field resolution and as the request target.
|
|
590
476
|
* @param {Request} req - Inbound CAP request (source of user, params, headers).
|
|
591
477
|
* @param {object} query - CQN SELECT query passed to `createRequest`.
|
|
@@ -593,5 +479,5 @@ declare const isSoapService: (serviceName: string) => boolean;
|
|
|
593
479
|
* @returns {Promise<any[]>} Always an array; `[]` when dispatch returns nothing.
|
|
594
480
|
*/
|
|
595
481
|
declare const read: (srv: SoapService, entity: string, req: Request, query: unknown, opts?: ReadOptions) => Promise<unknown[]>;
|
|
596
|
-
export {
|
|
482
|
+
export { Service, FORBIDDEN_SOAP_HEADERS, createRequest, getEntityKeyFields, dedupByKeys, isSoapService, read, };
|
|
597
483
|
//# sourceMappingURL=index.d.ts.map
|