@forgerock/sdk-request-middleware 0.0.0-beta-20251124184351 → 0.0.0-beta-20251222204813
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/CHANGELOG.md +7 -1
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +5 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/index.ts.html +94 -0
- package/coverage/src/lib/index.html +146 -0
- package/coverage/src/lib/request-mware.derived.ts.html +181 -0
- package/coverage/src/lib/request-mware.effects.ts.html +370 -0
- package/coverage/src/lib/request-mware.types.ts.html +220 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/lib/request-mware.derived.d.ts +20 -0
- package/dist/src/lib/request-mware.derived.d.ts.map +1 -0
- package/dist/src/lib/request-mware.derived.js +26 -0
- package/dist/src/lib/request-mware.effects.d.ts +27 -0
- package/dist/src/lib/request-mware.effects.d.ts.map +1 -0
- package/dist/src/lib/request-mware.effects.js +65 -0
- package/dist/src/lib/request-mware.mock.d.ts +5 -0
- package/dist/src/lib/request-mware.mock.d.ts.map +1 -0
- package/dist/src/lib/request-mware.mock.js +96 -0
- package/dist/src/lib/request-mware.types.d.ts +20 -0
- package/dist/src/lib/request-mware.types.d.ts.map +1 -0
- package/dist/src/lib/request-mware.types.js +7 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/out-tsc/vitest/src/lib/request-mware.test.d.ts +2 -0
- package/out-tsc/vitest/src/lib/request-mware.test.d.ts.map +1 -0
- package/out-tsc/vitest/tsconfig.spec.tsbuildinfo +1 -0
- package/out-tsc/vitest/vite.config.d.ts +3 -0
- package/out-tsc/vitest/vite.config.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for src/lib/request-mware.types.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="../../prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="../../base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(../../sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="../../index.html">All files</a> / <a href="index.html">src/lib</a> request-mware.types.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">0% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>0/0</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">0% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>1/1</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">0% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>1/1</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">0% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>0/0</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line low'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a>
|
|
75
|
+
<a name='L10'></a><a href='#L10'>10</a>
|
|
76
|
+
<a name='L11'></a><a href='#L11'>11</a>
|
|
77
|
+
<a name='L12'></a><a href='#L12'>12</a>
|
|
78
|
+
<a name='L13'></a><a href='#L13'>13</a>
|
|
79
|
+
<a name='L14'></a><a href='#L14'>14</a>
|
|
80
|
+
<a name='L15'></a><a href='#L15'>15</a>
|
|
81
|
+
<a name='L16'></a><a href='#L16'>16</a>
|
|
82
|
+
<a name='L17'></a><a href='#L17'>17</a>
|
|
83
|
+
<a name='L18'></a><a href='#L18'>18</a>
|
|
84
|
+
<a name='L19'></a><a href='#L19'>19</a>
|
|
85
|
+
<a name='L20'></a><a href='#L20'>20</a>
|
|
86
|
+
<a name='L21'></a><a href='#L21'>21</a>
|
|
87
|
+
<a name='L22'></a><a href='#L22'>22</a>
|
|
88
|
+
<a name='L23'></a><a href='#L23'>23</a>
|
|
89
|
+
<a name='L24'></a><a href='#L24'>24</a>
|
|
90
|
+
<a name='L25'></a><a href='#L25'>25</a>
|
|
91
|
+
<a name='L26'></a><a href='#L26'>26</a>
|
|
92
|
+
<a name='L27'></a><a href='#L27'>27</a>
|
|
93
|
+
<a name='L28'></a><a href='#L28'>28</a>
|
|
94
|
+
<a name='L29'></a><a href='#L29'>29</a>
|
|
95
|
+
<a name='L30'></a><a href='#L30'>30</a>
|
|
96
|
+
<a name='L31'></a><a href='#L31'>31</a>
|
|
97
|
+
<a name='L32'></a><a href='#L32'>32</a>
|
|
98
|
+
<a name='L33'></a><a href='#L33'>33</a>
|
|
99
|
+
<a name='L34'></a><a href='#L34'>34</a>
|
|
100
|
+
<a name='L35'></a><a href='#L35'>35</a>
|
|
101
|
+
<a name='L36'></a><a href='#L36'>36</a>
|
|
102
|
+
<a name='L37'></a><a href='#L37'>37</a>
|
|
103
|
+
<a name='L38'></a><a href='#L38'>38</a>
|
|
104
|
+
<a name='L39'></a><a href='#L39'>39</a>
|
|
105
|
+
<a name='L40'></a><a href='#L40'>40</a>
|
|
106
|
+
<a name='L41'></a><a href='#L41'>41</a>
|
|
107
|
+
<a name='L42'></a><a href='#L42'>42</a>
|
|
108
|
+
<a name='L43'></a><a href='#L43'>43</a>
|
|
109
|
+
<a name='L44'></a><a href='#L44'>44</a>
|
|
110
|
+
<a name='L45'></a><a href='#L45'>45</a>
|
|
111
|
+
<a name='L46'></a><a href='#L46'>46</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
112
|
+
<span class="cline-any cline-neutral"> </span>
|
|
113
|
+
<span class="cline-any cline-neutral"> </span>
|
|
114
|
+
<span class="cline-any cline-neutral"> </span>
|
|
115
|
+
<span class="cline-any cline-neutral"> </span>
|
|
116
|
+
<span class="cline-any cline-neutral"> </span>
|
|
117
|
+
<span class="cline-any cline-neutral"> </span>
|
|
118
|
+
<span class="cline-any cline-neutral"> </span>
|
|
119
|
+
<span class="cline-any cline-neutral"> </span>
|
|
120
|
+
<span class="cline-any cline-neutral"> </span>
|
|
121
|
+
<span class="cline-any cline-neutral"> </span>
|
|
122
|
+
<span class="cline-any cline-neutral"> </span>
|
|
123
|
+
<span class="cline-any cline-neutral"> </span>
|
|
124
|
+
<span class="cline-any cline-neutral"> </span>
|
|
125
|
+
<span class="cline-any cline-neutral"> </span>
|
|
126
|
+
<span class="cline-any cline-neutral"> </span>
|
|
127
|
+
<span class="cline-any cline-neutral"> </span>
|
|
128
|
+
<span class="cline-any cline-neutral"> </span>
|
|
129
|
+
<span class="cline-any cline-neutral"> </span>
|
|
130
|
+
<span class="cline-any cline-neutral"> </span>
|
|
131
|
+
<span class="cline-any cline-neutral"> </span>
|
|
132
|
+
<span class="cline-any cline-neutral"> </span>
|
|
133
|
+
<span class="cline-any cline-neutral"> </span>
|
|
134
|
+
<span class="cline-any cline-neutral"> </span>
|
|
135
|
+
<span class="cline-any cline-neutral"> </span>
|
|
136
|
+
<span class="cline-any cline-neutral"> </span>
|
|
137
|
+
<span class="cline-any cline-neutral"> </span>
|
|
138
|
+
<span class="cline-any cline-neutral"> </span>
|
|
139
|
+
<span class="cline-any cline-neutral"> </span>
|
|
140
|
+
<span class="cline-any cline-neutral"> </span>
|
|
141
|
+
<span class="cline-any cline-neutral"> </span>
|
|
142
|
+
<span class="cline-any cline-neutral"> </span>
|
|
143
|
+
<span class="cline-any cline-neutral"> </span>
|
|
144
|
+
<span class="cline-any cline-neutral"> </span>
|
|
145
|
+
<span class="cline-any cline-neutral"> </span>
|
|
146
|
+
<span class="cline-any cline-neutral"> </span>
|
|
147
|
+
<span class="cline-any cline-neutral"> </span>
|
|
148
|
+
<span class="cline-any cline-neutral"> </span>
|
|
149
|
+
<span class="cline-any cline-neutral"> </span>
|
|
150
|
+
<span class="cline-any cline-neutral"> </span>
|
|
151
|
+
<span class="cline-any cline-neutral"> </span>
|
|
152
|
+
<span class="cline-any cline-neutral"> </span>
|
|
153
|
+
<span class="cline-any cline-neutral"> </span>
|
|
154
|
+
<span class="cline-any cline-neutral"> </span>
|
|
155
|
+
<span class="cline-any cline-neutral"> </span>
|
|
156
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/*
|
|
157
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
158
|
+
*
|
|
159
|
+
* This software may be modified and distributed under the terms
|
|
160
|
+
* of the MIT license. See the LICENSE file for details.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
import {
|
|
164
|
+
FetchArgs,
|
|
165
|
+
FetchBaseQueryError,
|
|
166
|
+
FetchBaseQueryMeta,
|
|
167
|
+
QueryReturnValue,
|
|
168
|
+
} from '@reduxjs/toolkit/query';
|
|
169
|
+
|
|
170
|
+
import { ActionTypes } from './request-mware.derived.js';
|
|
171
|
+
|
|
172
|
+
export type RequestMiddleware<Type extends ActionTypes = ActionTypes, Payload = unknown> = (
|
|
173
|
+
req: ModifiedFetchArgs,
|
|
174
|
+
action: Action<Type, Payload>,
|
|
175
|
+
next: () => ModifiedFetchArgs,
|
|
176
|
+
) => void;
|
|
177
|
+
|
|
178
|
+
export interface QueryApi<Type extends ActionTypes = ActionTypes, Payload = unknown> {
|
|
179
|
+
applyMiddleware(middleware: RequestMiddleware<Type, Payload>[]): QueryApi<ActionTypes, unknown>;
|
|
180
|
+
applyQuery(
|
|
181
|
+
callback: (
|
|
182
|
+
request: FetchArgs,
|
|
183
|
+
) => Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>,
|
|
184
|
+
): Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface Action<Type extends ActionTypes = ActionTypes, Payload = unknown> {
|
|
188
|
+
type: Type;
|
|
189
|
+
payload: Payload;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface ModifiedFetchArgs extends Omit<FetchArgs, 'url'> {
|
|
193
|
+
url: URL;
|
|
194
|
+
headers?: Headers;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface RequestObj {
|
|
198
|
+
url: URL;
|
|
199
|
+
init: RequestInit;
|
|
200
|
+
}
|
|
201
|
+
</pre></td></tr></table></pre>
|
|
202
|
+
|
|
203
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
204
|
+
</div><!-- /wrapper -->
|
|
205
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
206
|
+
Code coverage generated by
|
|
207
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
208
|
+
at 2025-10-28T21:16:32.635Z
|
|
209
|
+
</div>
|
|
210
|
+
<script src="../../prettify.js"></script>
|
|
211
|
+
<script>
|
|
212
|
+
window.onload = function () {
|
|
213
|
+
prettyPrint();
|
|
214
|
+
};
|
|
215
|
+
</script>
|
|
216
|
+
<script src="../../sorter.js"></script>
|
|
217
|
+
<script src="../../block-navigation.js"></script>
|
|
218
|
+
</body>
|
|
219
|
+
</html>
|
|
220
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const actionTypes: {
|
|
2
|
+
readonly begin: "JOURNEY_START";
|
|
3
|
+
readonly continue: "JOURNEY_NEXT";
|
|
4
|
+
readonly terminate: "JOURNEY_TERMINATE";
|
|
5
|
+
readonly start: "DAVINCI_START";
|
|
6
|
+
readonly next: "DAVINCI_NEXT";
|
|
7
|
+
readonly flow: "DAVINCI_FLOW";
|
|
8
|
+
readonly success: "DAVINCI_SUCCESS";
|
|
9
|
+
readonly error: "DAVINCI_ERROR";
|
|
10
|
+
readonly failure: "DAVINCI_FAILURE";
|
|
11
|
+
readonly resume: "DAVINCI_RESUME";
|
|
12
|
+
readonly authorize: "AUTHORIZE";
|
|
13
|
+
readonly tokenExchange: "TOKEN_EXCHANGE";
|
|
14
|
+
readonly revoke: "REVOKE";
|
|
15
|
+
readonly userInfo: "USER_INFO";
|
|
16
|
+
readonly endSession: "END_SESSION";
|
|
17
|
+
};
|
|
18
|
+
export type ActionTypes = (typeof actionTypes)[keyof typeof actionTypes];
|
|
19
|
+
export type EndpointTypes = keyof typeof actionTypes;
|
|
20
|
+
//# sourceMappingURL=request-mware.derived.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-mware.derived.d.ts","sourceRoot":"","sources":["../../../src/lib/request-mware.derived.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;CAqBd,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AACzE,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,WAAW,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
export const actionTypes = {
|
|
8
|
+
// Journey
|
|
9
|
+
begin: 'JOURNEY_START',
|
|
10
|
+
continue: 'JOURNEY_NEXT',
|
|
11
|
+
terminate: 'JOURNEY_TERMINATE',
|
|
12
|
+
// DaVinci
|
|
13
|
+
start: 'DAVINCI_START',
|
|
14
|
+
next: 'DAVINCI_NEXT',
|
|
15
|
+
flow: 'DAVINCI_FLOW',
|
|
16
|
+
success: 'DAVINCI_SUCCESS',
|
|
17
|
+
error: 'DAVINCI_ERROR',
|
|
18
|
+
failure: 'DAVINCI_FAILURE',
|
|
19
|
+
resume: 'DAVINCI_RESUME',
|
|
20
|
+
// OIDC
|
|
21
|
+
authorize: 'AUTHORIZE',
|
|
22
|
+
tokenExchange: 'TOKEN_EXCHANGE',
|
|
23
|
+
revoke: 'REVOKE',
|
|
24
|
+
userInfo: 'USER_INFO',
|
|
25
|
+
endSession: 'END_SESSION',
|
|
26
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FetchArgs, FetchBaseQueryError, FetchBaseQueryMeta, QueryReturnValue } from '@reduxjs/toolkit/query';
|
|
2
|
+
import type { ActionTypes, EndpointTypes } from './request-mware.derived.js';
|
|
3
|
+
import type { ModifiedFetchArgs, RequestMiddleware } from './request-mware.types.js';
|
|
4
|
+
/**
|
|
5
|
+
* @function middlewareWrapper - A "Node" and "Redux" style middleware that is called just before
|
|
6
|
+
* the request is made from the SDK. This allows you access to the request for modification.
|
|
7
|
+
* @param request - A request object container of the URL and the Request Init object
|
|
8
|
+
* @param action - The action object that is passed into the middleware communicating intent
|
|
9
|
+
* @param action.type - A "Redux" style type that contains the serialized action
|
|
10
|
+
* @param action.payload - The payload of the action that can contain metadata
|
|
11
|
+
* @returns {function} - Function that takes middleware parameter & runs middleware against request
|
|
12
|
+
*/
|
|
13
|
+
export declare function middlewareWrapper(request: ModifiedFetchArgs, { type, payload }: {
|
|
14
|
+
type: ActionTypes;
|
|
15
|
+
payload?: any;
|
|
16
|
+
}): (middleware: RequestMiddleware<typeof type, typeof payload>[] | undefined) => ModifiedFetchArgs;
|
|
17
|
+
/**
|
|
18
|
+
* @function initQuery - Initializes a query object with the provided request object
|
|
19
|
+
* @param {FetchArgs} fetchArgs - The request object to initialize the query with
|
|
20
|
+
* @param {string} endpoint - The endpoint to be used for the query
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare function initQuery(fetchArgs: FetchArgs, endpoint: EndpointTypes, payload?: Record<string, unknown>): {
|
|
24
|
+
applyMiddleware(middleware: RequestMiddleware<ActionTypes, ModifiedFetchArgs["body"]>[] | undefined): /*elided*/ any;
|
|
25
|
+
applyQuery(callback: (request: FetchArgs) => Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>): Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=request-mware.effects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-mware.effects.d.ts","sourceRoot":"","sources":["../../../src/lib/request-mware.effects.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAErF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,iBAAiB,EAE1B,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,CAAC,EAAE,GAAG,CAAA;CAAE,GACtD,CAAC,UAAU,EAAE,iBAAiB,CAAC,OAAO,IAAI,EAAE,OAAO,OAAO,CAAC,EAAE,GAAG,SAAS,KAAK,iBAAiB,CAoBjG;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,aAAa,EACvB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gCASjB,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,SAAS;yBAazE,CACR,OAAO,EAAE,SAAS,KACf,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;EAOrF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
import { actionTypes } from './request-mware.derived.js';
|
|
8
|
+
/**
|
|
9
|
+
* @function middlewareWrapper - A "Node" and "Redux" style middleware that is called just before
|
|
10
|
+
* the request is made from the SDK. This allows you access to the request for modification.
|
|
11
|
+
* @param request - A request object container of the URL and the Request Init object
|
|
12
|
+
* @param action - The action object that is passed into the middleware communicating intent
|
|
13
|
+
* @param action.type - A "Redux" style type that contains the serialized action
|
|
14
|
+
* @param action.payload - The payload of the action that can contain metadata
|
|
15
|
+
* @returns {function} - Function that takes middleware parameter & runs middleware against request
|
|
16
|
+
*/
|
|
17
|
+
export function middlewareWrapper(request,
|
|
18
|
+
// eslint-disable-next-line
|
|
19
|
+
{ type, payload }) {
|
|
20
|
+
// no mutation and no reassignment
|
|
21
|
+
const actionCopy = Object.freeze({ type, payload });
|
|
22
|
+
return (middleware) => {
|
|
23
|
+
if (!Array.isArray(middleware)) {
|
|
24
|
+
return request;
|
|
25
|
+
}
|
|
26
|
+
// Copy middleware so the `shift` below doesn't mutate source
|
|
27
|
+
const mwareCopy = middleware.map((fn) => fn);
|
|
28
|
+
function iterator() {
|
|
29
|
+
const nextMiddlewareToBeCalled = mwareCopy.shift();
|
|
30
|
+
if (nextMiddlewareToBeCalled)
|
|
31
|
+
nextMiddlewareToBeCalled(request, actionCopy, iterator);
|
|
32
|
+
return request;
|
|
33
|
+
}
|
|
34
|
+
return iterator();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @function initQuery - Initializes a query object with the provided request object
|
|
39
|
+
* @param {FetchArgs} fetchArgs - The request object to initialize the query with
|
|
40
|
+
* @param {string} endpoint - The endpoint to be used for the query
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
export function initQuery(fetchArgs, endpoint, payload) {
|
|
44
|
+
let modifiedRequest = {
|
|
45
|
+
...fetchArgs,
|
|
46
|
+
url: new URL(fetchArgs.url),
|
|
47
|
+
headers: new Headers(fetchArgs.headers),
|
|
48
|
+
};
|
|
49
|
+
const queryApi = {
|
|
50
|
+
applyMiddleware(middleware) {
|
|
51
|
+
// Iterates and executes provided middleware functions
|
|
52
|
+
// Allow middleware to mutate `request` argument
|
|
53
|
+
const runMiddleware = middlewareWrapper(modifiedRequest, {
|
|
54
|
+
type: actionTypes[endpoint],
|
|
55
|
+
payload: payload || {},
|
|
56
|
+
});
|
|
57
|
+
modifiedRequest = runMiddleware(middleware);
|
|
58
|
+
return queryApi;
|
|
59
|
+
},
|
|
60
|
+
async applyQuery(callback) {
|
|
61
|
+
return await callback({ ...modifiedRequest, url: modifiedRequest.url.toString() });
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return queryApi;
|
|
65
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ActionTypes } from './request-mware.derived.js';
|
|
2
|
+
import type { RequestMiddleware } from './request-mware.types.js';
|
|
3
|
+
declare const middleware: RequestMiddleware<ActionTypes>[];
|
|
4
|
+
export default middleware;
|
|
5
|
+
//# sourceMappingURL=request-mware.mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-mware.mock.d.ts","sourceRoot":"","sources":["../../../src/lib/request-mware.mock.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAA6B,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAY7F,QAAA,MAAM,UAAU,EAAE,iBAAiB,CAAC,WAAW,CAAC,EA2E/C,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* This software may be modified and distributed under the terms
|
|
5
|
+
* of the MIT license. See the LICENSE file for details.
|
|
6
|
+
*/
|
|
7
|
+
const a = 'a';
|
|
8
|
+
const b = 'b';
|
|
9
|
+
const one = '1';
|
|
10
|
+
const two = '2';
|
|
11
|
+
const add = 'ADD';
|
|
12
|
+
const reassignment = 'REASSIGNMENT';
|
|
13
|
+
const mutateAction = 'MUTATE-ACTION';
|
|
14
|
+
const middleware = [
|
|
15
|
+
(req, action, next) => {
|
|
16
|
+
switch (action.type) {
|
|
17
|
+
case a:
|
|
18
|
+
case b:
|
|
19
|
+
req.url.searchParams.set('letter', 'true');
|
|
20
|
+
if (req.headers)
|
|
21
|
+
req.headers.set('x-letter', 'true');
|
|
22
|
+
break;
|
|
23
|
+
case one:
|
|
24
|
+
case two:
|
|
25
|
+
req.url.searchParams.set('letter', 'false');
|
|
26
|
+
if (req.headers)
|
|
27
|
+
req.headers.set('x-letter', 'false');
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
next();
|
|
31
|
+
},
|
|
32
|
+
(req, action, next) => {
|
|
33
|
+
switch (action.type) {
|
|
34
|
+
case a:
|
|
35
|
+
req.url.searchParams.set('char', 'a');
|
|
36
|
+
if (req.headers)
|
|
37
|
+
req.headers.set('x-char', 'a');
|
|
38
|
+
break;
|
|
39
|
+
case b:
|
|
40
|
+
req.url.searchParams.set('char', 'b');
|
|
41
|
+
if (req.headers)
|
|
42
|
+
req.headers.set('x-char', 'b');
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
next();
|
|
46
|
+
},
|
|
47
|
+
(req, action, next) => {
|
|
48
|
+
switch (action.type) {
|
|
49
|
+
case one:
|
|
50
|
+
req.url.searchParams.set('char', '1');
|
|
51
|
+
if (req.headers)
|
|
52
|
+
req.headers.set('x-char', '1');
|
|
53
|
+
break;
|
|
54
|
+
case two:
|
|
55
|
+
req.url.searchParams.set('char', '2');
|
|
56
|
+
if (req.headers)
|
|
57
|
+
req.headers.set('x-char', '2');
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
next();
|
|
61
|
+
},
|
|
62
|
+
(req, action, next) => {
|
|
63
|
+
switch (action.type) {
|
|
64
|
+
case add:
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
req.headers?.set('x-char', 'a,' + action.payload);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
next();
|
|
71
|
+
},
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
(req, action, next) => {
|
|
75
|
+
switch (action.type) {
|
|
76
|
+
case reassignment:
|
|
77
|
+
req = {
|
|
78
|
+
url: new URL('https://bad.com'),
|
|
79
|
+
headers: new Headers({ 'x-bad': 'true' }),
|
|
80
|
+
};
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
next();
|
|
84
|
+
},
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
(req, action, next) => {
|
|
88
|
+
switch (action.type) {
|
|
89
|
+
case mutateAction:
|
|
90
|
+
action.type = 'hello';
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
next();
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
export default middleware;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FetchArgs, FetchBaseQueryError, FetchBaseQueryMeta, QueryReturnValue } from '@reduxjs/toolkit/query';
|
|
2
|
+
import { ActionTypes } from './request-mware.derived.js';
|
|
3
|
+
export type RequestMiddleware<Type extends ActionTypes = ActionTypes, Payload = unknown> = (req: ModifiedFetchArgs, action: Action<Type, Payload>, next: () => ModifiedFetchArgs) => void;
|
|
4
|
+
export interface QueryApi<Type extends ActionTypes = ActionTypes, Payload = unknown> {
|
|
5
|
+
applyMiddleware(middleware: RequestMiddleware<Type, Payload>[]): QueryApi<ActionTypes, unknown>;
|
|
6
|
+
applyQuery(callback: (request: FetchArgs) => Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>): Promise<QueryReturnValue<unknown, FetchBaseQueryError, FetchBaseQueryMeta>>;
|
|
7
|
+
}
|
|
8
|
+
export interface Action<Type extends ActionTypes = ActionTypes, Payload = unknown> {
|
|
9
|
+
type: Type;
|
|
10
|
+
payload: Payload;
|
|
11
|
+
}
|
|
12
|
+
export interface ModifiedFetchArgs extends Omit<FetchArgs, 'url'> {
|
|
13
|
+
url: URL;
|
|
14
|
+
headers: Headers;
|
|
15
|
+
}
|
|
16
|
+
export interface RequestObj {
|
|
17
|
+
url: URL;
|
|
18
|
+
init: RequestInit;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=request-mware.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-mware.types.d.ts","sourceRoot":"","sources":["../../../src/lib/request-mware.types.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD,MAAM,MAAM,iBAAiB,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,OAAO,GAAG,OAAO,IAAI,CACzF,GAAG,EAAE,iBAAiB,EACtB,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,MAAM,iBAAiB,KAC1B,IAAI,CAAC;AAEV,MAAM,WAAW,QAAQ,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,OAAO,GAAG,OAAO;IACjF,eAAe,CAAC,UAAU,EAAE,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAChG,UAAU,CACR,QAAQ,EAAE,CACR,OAAO,EAAE,SAAS,KACf,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,GAC/E,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAChF;AAED,MAAM,WAAW,MAAM,CAAC,IAAI,SAAS,WAAW,GAAG,WAAW,EAAE,OAAO,GAAG,OAAO;IAC/E,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;IAC/D,GAAG,EAAE,GAAG,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,WAAW,CAAC;CACnB"}
|