@types/sap__approuter 14.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
sap__approuter/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -0,0 +1,15 @@
1
+ # Installation
2
+ > `npm install --save @types/sap__approuter`
3
+
4
+ # Summary
5
+ This package contains type definitions for @sap/approuter (https://www.npmjs.com/package/@sap/approuter).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sap__approuter.
9
+
10
+ ### Additional Details
11
+ * Last updated: Tue, 21 Nov 2023 10:39:42 GMT
12
+ * Dependencies: [@types/http-server](https://npmjs.com/package/@types/http-server), [@types/node](https://npmjs.com/package/@types/node), [@types/verror](https://npmjs.com/package/@types/verror)
13
+
14
+ # Credits
15
+ These definitions were written by [Nico Blum](https://github.com/nbblum), and [Laurens von Assel](https://github.com/biolauri).
@@ -0,0 +1,389 @@
1
+ /// <reference types="node" />
2
+
3
+ import { EventEmitter } from "events";
4
+ import { ClientRequest, IncomingMessage, ServerResponse } from "http";
5
+ import { ServerOptions } from "https";
6
+
7
+ import { ComSapXsappSchema_82 } from "./xs-app.schema";
8
+
9
+ declare namespace approuter {
10
+ interface AfterRequestHandlerContext {
11
+ /** The request sent from client to application router */
12
+ incomingRequest: IncomingMessage;
13
+ /** The response that will be sent from application router to client */
14
+ incomingResponse: ServerResponse;
15
+ /** The request sent from application router to backend application */
16
+ outgoingRequest: ClientRequest;
17
+ /** The response that was received in application router from backend application */
18
+ outgoingResponse: IncomingMessage;
19
+ }
20
+
21
+ interface AppRouterIncomingMessage extends IncomingMessage {
22
+ /**
23
+ * A function that can be added to the request object - for example in a "first" or "beforeRequestHandler" extension.
24
+ * If exists, this function will be called by the standard application router after the standard backend response handling is completed.
25
+ *
26
+ * Note that this function is called after standard application router headers processing. Data piping is not modified.
27
+ * If an error is passed to done callback it will be just logged, piping process will not be stopped.
28
+ * Note that also in case of error the incomingResponse object should be returned.
29
+ *
30
+ * @example
31
+ * var approuter = require('@sap/approuter');
32
+ * var ar = approuter();
33
+ * ar.first.use('/backend', function (req, res, next) {
34
+ * req.afterRequestHandler = function(ctx, done){
35
+ * if (ctx.outgoingResponse.statusCode === 200) {
36
+ * let incomingResponse = ctx.incomingResponse;
37
+ * incomingResponse.setHeader('header1', 'abc');
38
+ * done(null, incomingResponse);
39
+ * } else {
40
+ * done('An error occurred in backend, returned status ' + ctx.outgoingResponse.statusCode, ctx.incomingResponse);
41
+ * }
42
+ * };
43
+ * next();
44
+ * });
45
+ * ar.start();
46
+ * @param ctx - Context object for the request handler
47
+ * @param {AppRouterIncomingMessage~afterRequestHandlerCallback} done - A callback function that receives (optionally) and error and the modified incomingResponse
48
+ */
49
+ afterRequestHandler?: (
50
+ ctx: AfterRequestHandlerContext,
51
+ done: (error: Error | string | undefined | null, incomingResponse: ServerResponse) => void,
52
+ ) => void;
53
+
54
+ /**
55
+ * A function that can be added to the request object - for example in a "first" or "beforeRequestHandler" extension.
56
+ * If exists, this function will be called by the standard application router when a backend connection timeout occurs.
57
+ *
58
+ * @param req - the request object
59
+ * @param done - a callback function that doesn't return any parameter
60
+ */
61
+ backendTimeout?: (req: IncomingMessage, done: () => void) => void;
62
+
63
+ /**
64
+ * Callback for {@link afterRequestHandler}
65
+ *
66
+ * @param error - Error object in case of error
67
+ * @param incomingResponse - Modified incomingResponse
68
+ */
69
+ }
70
+
71
+ /**
72
+ * A handler for requests, called Middleware.
73
+ *
74
+ * @param request - Data of the incoming Request
75
+ * @param response - Object for the outgoing Response; can be manipulated to alter the response
76
+ * @param next - Call next to give control back to Application Router Middleware
77
+ */
78
+ type MiddlewareHandler = (request: AppRouterIncomingMessage, response: ServerResponse, next: () => void) => void;
79
+
80
+ interface Extensions {
81
+ /**
82
+ * Describes the middleware provided by this extension
83
+ * If a path is given, the handler is only invoked on these paths; otherwise it's invoked on all requests.
84
+ */
85
+ insertMiddleware: {
86
+ /** A MiddlewareSlot before the first application router middleware */
87
+ first?: Array<MiddlewareHandler | { path: string; handler: MiddlewareHandler }>;
88
+ /** A MiddlewareSlot before the standard application router request handling */
89
+ beforeRequestHandler?: Array<MiddlewareHandler | { path: string; handler: MiddlewareHandler }>;
90
+ /** A MiddlewareSlot before the standard application router error handling */
91
+ beforeErrorHandler?: Array<MiddlewareHandler | { path: string; handler: MiddlewareHandler }>;
92
+ };
93
+ }
94
+
95
+ type RouterConfig = unknown;
96
+
97
+ interface StartOptions {
98
+ /** A TCP port the application router will listen to */
99
+ port?: string;
100
+
101
+ /** The working directory for the application router, should contain the xs-app.json file */
102
+ workingDir?: string;
103
+
104
+ /** An array of extensions, each one is an object as defined in Application Router Extensions */
105
+ extensions?: Extensions[];
106
+
107
+ /** An object representing the content which is usually put in xs-app.json file. If this property is present it will take precedence over the content of xs-app.json. */
108
+ xsAppConfig?: ComSapXsappSchema_82;
109
+
110
+ /**
111
+ * Options similar to [https.createServer](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener).
112
+ * If this property is present, application router will be started as an https server.
113
+ */
114
+ httpsConfig?: ServerOptions;
115
+
116
+ /**
117
+ * Provide custom access token
118
+ *
119
+ * @param request - Node request object
120
+ * @param {StartOptions~getTokenCallback} callback - Test
121
+ */
122
+ getToken?: (
123
+ request: AppRouterIncomingMessage,
124
+ callback: (error: Error | undefined | null, token: string) => void,
125
+ ) => void;
126
+
127
+ /**
128
+ * Provide custom routing configuration
129
+ *
130
+ * **Note**: When approuter is bound to html5 repository, you cannot provide getRouterConfig function.
131
+ *
132
+ * @param request - Node request object
133
+ * @param {StartOptions~getRouterConfigCallback} callback
134
+ */
135
+ getRouterConfig?: (
136
+ request: AppRouterIncomingMessage,
137
+ callback: (error: Error | undefined | null, routerConfig: RouterConfig | null | undefined) => void,
138
+ ) => void;
139
+
140
+ /**
141
+ * returns the session secret to be used by the application router for the signing of the session cookies.
142
+ */
143
+ getSessionSecret?: () => string;
144
+ }
145
+
146
+ interface RouterConfigOptions {
147
+ /**
148
+ * Value to replace $XSAPPNAME placeholder in scope names.
149
+ *
150
+ * If not provided, it will be taken from UAA service binding.
151
+ */
152
+ xsappname?: string;
153
+
154
+ /**
155
+ * An object representing the content which is usually put in xs-app.json file.
156
+ *
157
+ * **Note:** Only the typed configurations are taken into account from this property (the rest are taken from the xs-app.json file).
158
+ */
159
+ xsappConfig: Pick<ComSapXsappSchema_82, "welcomeFile" | "logout" | "routes" | "websockets" | "errorPage">;
160
+
161
+ /**
162
+ * An array containing the configuration of the backend destinations.
163
+ *
164
+ * If not provided, it will be taken from `destinations` environment variable.
165
+ */
166
+ destinations?: Array<{
167
+ name: string;
168
+ url: string;
169
+ forwardAuthToken: boolean;
170
+ }>;
171
+ }
172
+
173
+ interface MiddlewareSlot {
174
+ /**
175
+ * Inserts a request handling middleware in the current slot.
176
+ *
177
+ * @param handler - a middleware function to invoke
178
+ */
179
+ use(handler: MiddlewareHandler): MiddlewareSlot;
180
+
181
+ /**
182
+ * Inserts a request handling middleware in the current slot for the given path.
183
+ *
184
+ * @param path - handle only requests starting with this path
185
+ * @param handler - a middleware function to invoke
186
+ */
187
+ use(path: string, handler: MiddlewareHandler): MiddlewareSlot;
188
+ }
189
+
190
+ /**
191
+ * The application router uses a memory store as a session repository to provide the best runtime performance.
192
+ * However, it is not persisted, and it is not shared across multiple instances of the application router.
193
+ *
194
+ * Events
195
+ * - update
196
+ * - destroy
197
+ * - timeout
198
+ */
199
+ interface MemoryStore extends EventEmitter {
200
+ /**
201
+ * returns the default session timeout in minutes.
202
+ */
203
+ getDefaultSessionTimeout(): number;
204
+
205
+ /**
206
+ * @param sessionId an unsigned session identifier
207
+ * @param callback function(error, session) a function that is called when the session object is retrieved from the internal session storage of the application router.
208
+ * error - an error object in case of an error, otherwise null
209
+ * timeout - time, in minutes, until the session times out
210
+ */
211
+ getSessionTimeout(sessionId: string, callback: (error: object | null, session: number) => void): void;
212
+
213
+ /**
214
+ * @param sessionId an unsigned session identifier
215
+ * @param callback a function that is called when the session object is retrieved from the internal session storage of the application router.
216
+ * error - an error object in case of an error, otherwise null
217
+ * session - the session object
218
+ * id - session identifier, immutable
219
+ */
220
+ get(sessionId: string, callback: (error: object | null, session: number) => void): void;
221
+
222
+ /**
223
+ * @param sessionId an unsigned session identifier
224
+ * @param sessionString a session object serialized to string
225
+ * @param timeout a timestamp in milliseconds, after which the session should be automatically invalidated
226
+ * @param callback a function that is called after the session is saved in the internal session storage of the application router
227
+ */
228
+ set(sessionId: string, sessionString: string, timeout: number, callback: () => void): void;
229
+
230
+ /**
231
+ * @param sessionId an unsigned session identifier
232
+ * @param callback function(currentSession) function, which returns session object. Callback function may modify and return current session object or create and return brand new session object
233
+ * currentSession - current session object
234
+ * @param resetTimeout a boolean that indicates whether to reset the session timeout
235
+ */
236
+ update(sessionId: string, callback: (currentSession: object) => void, resetTimeout: boolean): void;
237
+
238
+ /**
239
+ * @param sessionId an unsigned session identifier
240
+ * @param callback a function that is called after the session is destroyed in the internal session storage of the application router
241
+ */
242
+ destroy(sessionId: string, callback: () => void): void;
243
+
244
+ /**
245
+ * Emitted when a user session has been updated.
246
+ *
247
+ * @param event
248
+ */
249
+ on(event: "update", listener: (sessionId: string) => void): this;
250
+ }
251
+
252
+ type SessionStore = MemoryStore;
253
+
254
+ /**
255
+ * SAP Application Router
256
+ *
257
+ * For full help, please consult the README file in @sap/approuter (the source npm package) or
258
+ * https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/LATEST/en-US/050d87a61faa4fb88f687abd7bdf16ce.html
259
+ *
260
+ * These types (and their tests) are mostly extracted from the above mentioned README file and `doc/extending.md`
261
+ * in @sap/approuter (the source npm package). If some types are incorrect or missing, please open up an issue at
262
+ * {@link https://github.com/DefinitelyTyped/DefinitelyTyped}, or, even better, add them by yourself via a Pull Request.
263
+ *
264
+ * ## Command Parser
265
+ * The {@link cmdParser} property is set to a {@link Command} instance when instantiating an Approuter. It is possible
266
+ * to disable this feature by setting {@link cmdParser} to false. To do this typesafe, you have to use
267
+ * `Approuter<false>` as a type when creating the Approuter instance.
268
+ * @example
269
+ * const ar = new Approuter<false>();
270
+ * ar.cmdParser = false;
271
+ */
272
+ interface Approuter extends EventEmitter {
273
+ /**
274
+ * A {@link MiddlewareSlot} before the first application router middleware
275
+ */
276
+ first: MiddlewareSlot;
277
+
278
+ /**
279
+ * A {@link MiddlewareSlot} before the standard application router request handling
280
+ */
281
+ beforeRequestHandler: MiddlewareSlot;
282
+
283
+ /**
284
+ * A {@link MiddlewareSlot} before the standard application router error handling
285
+ */
286
+ beforeErrorHandler: MiddlewareSlot;
287
+
288
+ /**
289
+ * **Note**: the cmdParser is currently not typed, feel free to create a pr and add the missing types
290
+ *
291
+ * By default the application router handles its command line parameters, but you can customize that too.
292
+ *
293
+ * An _approuter_ instance provides the property `cmdParser` that is a [commander](https://github.com/tj/commander.js/) instance.
294
+ * It is configured with the standard application router command line options.
295
+ *
296
+ * To completely disable the command line option handling in the application router, reset the following property: `ar.cmdParser = false;`
297
+ *
298
+ * @example
299
+ * var approuter = require('@sap/approuter');
300
+ *
301
+ * var ar = approuter();
302
+ *
303
+ * var params = ar.cmdParser
304
+ * // add here custom command line options if needed
305
+ * .option('-d, --dummy', 'A dummy option')
306
+ * .parse(process.argv);
307
+ *
308
+ * console.log('Dummy option:', params.dummy);
309
+ */
310
+ cmdParser: never;
311
+
312
+ /**
313
+ * Starts the application router with the given options.
314
+ *
315
+ * @param options - Customize the Approuter with some configurations
316
+ * @param callback - Is invoked when the application router has started or an error has occurred. If not provided and an error occurs (e.g. the port is busy), the application will abort.
317
+ */
318
+ start(options?: StartOptions, callback?: (err: Error | undefined | null) => void): void;
319
+
320
+ /**
321
+ * Stops the application router.
322
+ *
323
+ * @param callback - Is invoked when the application router has stopped or an error has occurred.
324
+ */
325
+ close(callback?: (error: Error | undefined | null) => void): void;
326
+
327
+ /**
328
+ * Prepares the routing configuration to be used by the application router. As part of this, the application router validates the given options.
329
+ * This function can be used at any point in runtime to create additional routing configurations.
330
+ *
331
+ * **Note**: This function can be called only after {@link start} function.
332
+ *
333
+ * @param options - Router configurations
334
+ * @param {Approuter~createRouterConfigCallback} callback
335
+ */
336
+ createRouterConfig(
337
+ options: RouterConfigOptions,
338
+ callback: (error: Error | undefined | null, routerConfig: RouterConfig) => void,
339
+ ): void;
340
+
341
+ /**
342
+ * Calculates tenant-specific UAA configuration.
343
+ *
344
+ * @param request - node request object used to identify the tenant
345
+ * @param uaaOptions - UAA options as provided in service binding
346
+ * @param {Approuter~resolveUaaConfigCallback} callback
347
+ */
348
+ resolveUaaConfig(
349
+ request: AppRouterIncomingMessage,
350
+ uaaOptions: any,
351
+ callback: (error: Error | undefined | null, tenantUaaOptions: any) => void,
352
+ ): void;
353
+
354
+ /**
355
+ * returns SessionStore instance.
356
+ */
357
+ getSessionStore(): SessionStore;
358
+
359
+ /**
360
+ * Emitted when a new user session is created.
361
+ *
362
+ * @param event
363
+ * @param {Approuter~onLoginLogoutCallback} listener
364
+ */
365
+ on(event: "login", listener: (session: { id: string }) => void): this;
366
+
367
+ /**
368
+ * Emitted when a new user session has been updated.
369
+ *
370
+ * @param event
371
+ * @param {Approuter~onLoginLogoutCallback} listener
372
+ */
373
+ on(event: "update", listener: (sessionId: string, timeout: number) => void): this;
374
+
375
+ /**
376
+ * Emitted when a user session has expired or a user has requested to log out.
377
+ *
378
+ * @param event
379
+ * @param {Approuter~onLoginLogoutCallback} listener
380
+ */
381
+ // Disabled for better JSDocs
382
+ // tslint:disable-next-line:unified-signatures
383
+ on(event: "logout", listener: (session: { id: string }) => void): this;
384
+ }
385
+ }
386
+
387
+ declare function approuter(): approuter.Approuter;
388
+
389
+ export = approuter;
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@types/sap__approuter",
3
+ "version": "14.3.0",
4
+ "description": "TypeScript definitions for @sap/approuter",
5
+ "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/sap__approuter",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ {
9
+ "name": "Nico Blum",
10
+ "githubUsername": "nbblum",
11
+ "url": "https://github.com/nbblum"
12
+ },
13
+ {
14
+ "name": "Laurens von Assel",
15
+ "githubUsername": "biolauri",
16
+ "url": "https://github.com/biolauri"
17
+ }
18
+ ],
19
+ "main": "",
20
+ "types": "index.d.ts",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
24
+ "directory": "types/sap__approuter"
25
+ },
26
+ "scripts": {},
27
+ "dependencies": {
28
+ "@types/http-server": "*",
29
+ "@types/node": "*",
30
+ "@types/verror": "*"
31
+ },
32
+ "typesPublisherContentHash": "6e90fefa56f7582b3db68e3977022dbabc5b4038b85d7cf8178a5fd1f8d6d89c",
33
+ "typeScriptVersion": "4.5"
34
+ }
@@ -0,0 +1,100 @@
1
+ // Original file: https://json.schemastore.org/xs-app.json
2
+ // Online converter: https://bcherny.github.io/json-schema-to-typescript-browser/
3
+ /**
4
+ * This file was automatically generated by json-schema-to-typescript.
5
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
6
+ * and run json-schema-to-typescript to regenerate this file.
7
+ */
8
+
9
+ export type SourceSchema =
10
+ | string
11
+ | {
12
+ path: string;
13
+ matchCase?: boolean;
14
+ };
15
+ export type ScopesSchema =
16
+ | string
17
+ | [string, ...string[]]
18
+ | {
19
+ GET?: ScopeTemplate;
20
+ POST?: ScopeTemplate;
21
+ HEAD?: ScopeTemplate;
22
+ PUT?: ScopeTemplate;
23
+ DELETE?: ScopeTemplate;
24
+ TRACE?: ScopeTemplate;
25
+ PATCH?: ScopeTemplate;
26
+ OPTIONS?: ScopeTemplate;
27
+ CONNECT?: ScopeTemplate;
28
+ default?: ScopeTemplate;
29
+ };
30
+ export type ScopeTemplate = string | [string, ...string[]];
31
+
32
+ /**
33
+ * Application Router Configuration Schema
34
+ */
35
+ export interface ComSapXsappSchema_82 {
36
+ welcomeFile?: string;
37
+ authenticationMethod?: "none" | "route";
38
+ sessionTimeout?: number;
39
+ pluginMetadataEndpoint?: string;
40
+ routes?: Array<{
41
+ source: SourceSchema;
42
+ httpMethods?: [
43
+ "DELETE" | "GET" | "HEAD" | "OPTIONS" | "POST" | "PUT" | "TRACE" | "PATCH",
44
+ ...Array<"DELETE" | "GET" | "HEAD" | "OPTIONS" | "POST" | "PUT" | "TRACE" | "PATCH">,
45
+ ];
46
+ target?: string;
47
+ destination?: string;
48
+ localDir?: string;
49
+ csrfProtection?: boolean;
50
+ service?: string;
51
+ endpoint?: string;
52
+ authenticationType?: "xsuaa" | "basic" | "none";
53
+ identityProvider?: string;
54
+ scope?: ScopesSchema;
55
+ replace?: {
56
+ pathSuffixes: string[];
57
+ vars?: string[];
58
+ services?: {
59
+ [k: string]: unknown;
60
+ };
61
+ };
62
+ cacheControl?: string;
63
+ }>;
64
+ destinations?: {
65
+ [k: string]: {
66
+ logoutPath?: string;
67
+ logoutMethod?: "PUT" | "POST" | "GET";
68
+ };
69
+ };
70
+ services?: {
71
+ [k: string]: {
72
+ endpoint?: string;
73
+ logoutPath?: string;
74
+ logoutMethod?: "PUT" | "POST" | "GET";
75
+ };
76
+ };
77
+ logout?: {
78
+ logoutEndpoint?: string;
79
+ logoutPage?: string;
80
+ };
81
+ login?: {
82
+ callbackEndpoint: string;
83
+ };
84
+ whitelistService?: {
85
+ endpoint: string;
86
+ };
87
+ compression?: {
88
+ enabled?: boolean;
89
+ minSize?: number;
90
+ };
91
+ websockets?: {
92
+ enabled: boolean;
93
+ };
94
+ errorPage?: Array<{
95
+ status: number | [number, ...number[]];
96
+ file: string;
97
+ [k: string]: unknown;
98
+ }>;
99
+ [k: string]: unknown;
100
+ }