@uniformdev/redirect 19.135.1-alpha.10 → 19.135.1-alpha.12
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/dist/index.d.mts +81 -101
- package/dist/index.d.ts +81 -101
- package/dist/index.esm.js +25 -40
- package/dist/index.js +25 -40
- package/dist/index.mjs +25 -40
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -37,85 +37,6 @@ declare class TrieData<T> {
|
|
|
37
37
|
[key: string]: TrieData<T> | T;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
type RedirectClientCacheOptions = {
|
|
41
|
-
prePopulate?: boolean;
|
|
42
|
-
refreshRate?: number;
|
|
43
|
-
};
|
|
44
|
-
declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
|
|
45
|
-
options: RedirectClientCacheOptions;
|
|
46
|
-
constructor(options: RedirectClientCacheOptions);
|
|
47
|
-
abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
|
|
48
|
-
abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
|
|
49
|
-
abstract refresh(): Promise<void[]>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type RedirectClientOptions = ClientOptions & {
|
|
53
|
-
/** Caching mechanism used to hold redirect data payload for rapid retrieval */
|
|
54
|
-
dataCache?: RedirectClientCache<RedirectClientCacheOptions>;
|
|
55
|
-
};
|
|
56
|
-
type RedirectOptions = {
|
|
57
|
-
/** Reverse flips the direction of the search, instead of redirecting a source to a target you will be finding the source that could have produced a given target */
|
|
58
|
-
reverse?: boolean;
|
|
59
|
-
/** Includes a label highlighting all wildcard variables with HTML em tags */
|
|
60
|
-
label?: boolean;
|
|
61
|
-
};
|
|
62
|
-
declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
63
|
-
constructor(options: RedirectClientOptions);
|
|
64
|
-
getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
|
|
65
|
-
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
|
|
66
|
-
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
|
|
67
|
-
redirect: {
|
|
68
|
-
id?: string | undefined;
|
|
69
|
-
sourceUrl: string;
|
|
70
|
-
targetUrl: string;
|
|
71
|
-
targetStatusCode: number;
|
|
72
|
-
sourceProjectMapNodeId?: string | undefined;
|
|
73
|
-
targetProjectMapNodeId?: string | undefined;
|
|
74
|
-
projectMapId?: string | undefined;
|
|
75
|
-
sourceRetainQuerystring?: boolean | undefined;
|
|
76
|
-
sourceMustMatchDomain?: boolean | undefined;
|
|
77
|
-
targetPreserveIncomingProtocol?: boolean | undefined;
|
|
78
|
-
targetPreserveIncomingDomain?: boolean | undefined;
|
|
79
|
-
targetMergeQuerystring?: boolean | undefined;
|
|
80
|
-
labelAsSystem?: boolean | undefined;
|
|
81
|
-
};
|
|
82
|
-
metadata: {
|
|
83
|
-
updatedAt?: string | undefined;
|
|
84
|
-
updatedBy?: string | undefined;
|
|
85
|
-
createdAt?: string | undefined;
|
|
86
|
-
createdBy?: string | undefined;
|
|
87
|
-
createdByName?: string | undefined;
|
|
88
|
-
};
|
|
89
|
-
total: number | undefined;
|
|
90
|
-
}, void, unknown>;
|
|
91
|
-
getRedirectTrie: (options?: {
|
|
92
|
-
bypassDataCache?: boolean;
|
|
93
|
-
}) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
|
|
94
|
-
resetRedirectTrieDataCache: () => Promise<void>;
|
|
95
|
-
upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
|
|
96
|
-
deleteRedirect: (id: string) => Promise<string>;
|
|
97
|
-
static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
|
|
98
|
-
processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
|
|
99
|
-
processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
|
|
100
|
-
private static assembling;
|
|
101
|
-
private static assemblingPromise;
|
|
102
|
-
private assembleTrie;
|
|
103
|
-
private static processHops;
|
|
104
|
-
private static processHop;
|
|
105
|
-
/**
|
|
106
|
-
* Taking the url, found definition and variables and returning a redirect result object
|
|
107
|
-
* @param processedUrl - Propertly formatted url input
|
|
108
|
-
* @param definition - Redirect definition found to match the processed url
|
|
109
|
-
* @param variables - Wildcard variables found during definition discovery
|
|
110
|
-
* @param options - Different options available to the redirect engine
|
|
111
|
-
*/
|
|
112
|
-
private static processDefinitionToResults;
|
|
113
|
-
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
114
|
-
}
|
|
115
|
-
declare class UncachedRedirectClient extends RedirectClient {
|
|
116
|
-
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
40
|
/**
|
|
120
41
|
* This file was auto-generated by openapi-typescript.
|
|
121
42
|
* Do not make direct changes to the file.
|
|
@@ -136,17 +57,17 @@ interface paths {
|
|
|
136
57
|
sourceUrl?: string;
|
|
137
58
|
/** Find redirects that could redirect to this url */
|
|
138
59
|
targetUrl?: string;
|
|
139
|
-
/** Id of the project map the source or target belongs to
|
|
60
|
+
/** Id of the project map the source or target belongs to */
|
|
140
61
|
projectMapId?: string;
|
|
141
|
-
/** Id of the project map node to find redirects for
|
|
62
|
+
/** Id of the project map node to find redirects for */
|
|
142
63
|
sourceProjectMapNodeId?: string;
|
|
143
|
-
/** Id of the project map node to find redirects for
|
|
64
|
+
/** Id of the project map node to find redirects for */
|
|
144
65
|
targetProjectMapNodeId?: string;
|
|
145
|
-
/** Column to order results by, only applicable if trie is not active
|
|
66
|
+
/** Column to order results by, only applicable if trie is not active */
|
|
146
67
|
orderBy?: "updated_at asc" | "updated_at desc" | "source_url asc" | "source_url desc" | "target_url asc" | "target_url desc" | "created_by asc" | "created_by desc";
|
|
147
|
-
/** Limit the results to this number of results, ignored if using trie parameter
|
|
68
|
+
/** Limit the results to this number of results, ignored if using trie parameter */
|
|
148
69
|
limit?: number;
|
|
149
|
-
/** Offset the results a certain amount, useful for pagination
|
|
70
|
+
/** Offset the results a certain amount, useful for pagination */
|
|
150
71
|
offset?: number;
|
|
151
72
|
/** Search text to filter redirects by, filtering on the source and target urls */
|
|
152
73
|
search?: string;
|
|
@@ -233,19 +154,19 @@ interface paths {
|
|
|
233
154
|
"application/json": {
|
|
234
155
|
/**
|
|
235
156
|
* Format: uuid
|
|
236
|
-
* @description Redirect id to be deleted
|
|
157
|
+
* @description Redirect id to be deleted
|
|
237
158
|
*/
|
|
238
159
|
id: string;
|
|
239
160
|
/**
|
|
240
161
|
* Format: uuid
|
|
241
|
-
* @description Project the redirect belongs to
|
|
162
|
+
* @description Project the redirect belongs to
|
|
242
163
|
*/
|
|
243
164
|
projectId: string;
|
|
244
165
|
};
|
|
245
166
|
};
|
|
246
167
|
};
|
|
247
168
|
};
|
|
248
|
-
/** Handles preflight requests. This endpoint allows CORS
|
|
169
|
+
/** Handles preflight requests. This endpoint allows CORS */
|
|
249
170
|
options: {
|
|
250
171
|
responses: {
|
|
251
172
|
/** OK */
|
|
@@ -275,41 +196,41 @@ interface components {
|
|
|
275
196
|
Redirect: {
|
|
276
197
|
/**
|
|
277
198
|
* Format: uuid
|
|
278
|
-
* @description Id of the redirect
|
|
199
|
+
* @description Id of the redirect
|
|
279
200
|
*/
|
|
280
201
|
id?: string;
|
|
281
|
-
/** @description Source meant to match a url that needs to be redirected
|
|
202
|
+
/** @description Source meant to match a url that needs to be redirected */
|
|
282
203
|
sourceUrl: string;
|
|
283
|
-
/** @description Target meant to be redirected to
|
|
204
|
+
/** @description Target meant to be redirected to */
|
|
284
205
|
targetUrl: string;
|
|
285
|
-
/** @description Redirect type to occur from this redirect
|
|
206
|
+
/** @description Redirect type to occur from this redirect */
|
|
286
207
|
targetStatusCode: number;
|
|
287
208
|
/**
|
|
288
209
|
* Format: uuid
|
|
289
|
-
* @description Project map node related to the source this redirect
|
|
210
|
+
* @description Project map node related to the source this redirect
|
|
290
211
|
*/
|
|
291
212
|
sourceProjectMapNodeId?: string;
|
|
292
213
|
/**
|
|
293
214
|
* Format: uuid
|
|
294
|
-
* @description Project map node related to the target this redirect
|
|
215
|
+
* @description Project map node related to the target this redirect
|
|
295
216
|
*/
|
|
296
217
|
targetProjectMapNodeId?: string;
|
|
297
218
|
/**
|
|
298
219
|
* Format: uuid
|
|
299
|
-
* @description Project map related to this redirect
|
|
220
|
+
* @description Project map related to this redirect
|
|
300
221
|
*/
|
|
301
222
|
projectMapId?: string;
|
|
302
|
-
/** @description Signals the redirect engine to retain query string parameters to the target url
|
|
223
|
+
/** @description Signals the redirect engine to retain query string parameters to the target url */
|
|
303
224
|
sourceRetainQuerystring?: boolean;
|
|
304
|
-
/** @description Incoming requests must match the domain that's defined in the redirection source
|
|
225
|
+
/** @description Incoming requests must match the domain that's defined in the redirection source */
|
|
305
226
|
sourceMustMatchDomain?: boolean;
|
|
306
|
-
/** @description Rewritten url should match the protocol (http / https) of the incoming request instead of whatever is defined in the redirection target
|
|
227
|
+
/** @description Rewritten url should match the protocol (http / https) of the incoming request instead of whatever is defined in the redirection target */
|
|
307
228
|
targetPreserveIncomingProtocol?: boolean;
|
|
308
|
-
/** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target
|
|
229
|
+
/** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target */
|
|
309
230
|
targetPreserveIncomingDomain?: boolean;
|
|
310
|
-
/** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible
|
|
231
|
+
/** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible */
|
|
311
232
|
targetMergeQuerystring?: boolean;
|
|
312
|
-
/** @description Label as system generated or user generated
|
|
233
|
+
/** @description Label as system generated or user generated */
|
|
313
234
|
labelAsSystem?: boolean;
|
|
314
235
|
};
|
|
315
236
|
};
|
|
@@ -359,6 +280,65 @@ interface external {
|
|
|
359
280
|
};
|
|
360
281
|
}
|
|
361
282
|
|
|
283
|
+
type RedirectClientCacheOptions = {
|
|
284
|
+
prePopulate?: boolean;
|
|
285
|
+
refreshRate?: number;
|
|
286
|
+
};
|
|
287
|
+
declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
|
|
288
|
+
options: RedirectClientCacheOptions;
|
|
289
|
+
constructor(options: RedirectClientCacheOptions);
|
|
290
|
+
abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
|
|
291
|
+
abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
|
|
292
|
+
abstract refresh(): Promise<void[]>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
type RedirectClientOptions = ClientOptions & {
|
|
296
|
+
/** Caching mechanism used to hold redirect data payload for rapid retrieval */
|
|
297
|
+
dataCache?: RedirectClientCache<RedirectClientCacheOptions>;
|
|
298
|
+
};
|
|
299
|
+
type RedirectOptions = {
|
|
300
|
+
/** Reverse flips the direction of the search, instead of redirecting a source to a target you will be finding the source that could have produced a given target */
|
|
301
|
+
reverse?: boolean;
|
|
302
|
+
/** Includes a label highlighting all wildcard variables with HTML em tags */
|
|
303
|
+
label?: boolean;
|
|
304
|
+
};
|
|
305
|
+
declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
306
|
+
constructor(options: RedirectClientOptions);
|
|
307
|
+
getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
|
|
308
|
+
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
|
|
309
|
+
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
|
|
310
|
+
redirect: components["schemas"]["Redirect"];
|
|
311
|
+
metadata: components["schemas"]["RedirectMetadata"];
|
|
312
|
+
total: number | undefined;
|
|
313
|
+
}, void, unknown>;
|
|
314
|
+
getRedirectTrie: (options?: {
|
|
315
|
+
bypassDataCache?: boolean;
|
|
316
|
+
}) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
|
|
317
|
+
resetRedirectTrieDataCache: () => Promise<void>;
|
|
318
|
+
upsertRedirect: (redirect: RedirectUpsertRequest["redirect"]) => Promise<string>;
|
|
319
|
+
deleteRedirect: (id: string) => Promise<string>;
|
|
320
|
+
static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
|
|
321
|
+
processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
|
|
322
|
+
processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
|
|
323
|
+
private static assembling;
|
|
324
|
+
private static assemblingPromise;
|
|
325
|
+
private assembleTrie;
|
|
326
|
+
private static processHops;
|
|
327
|
+
private static processHop;
|
|
328
|
+
/**
|
|
329
|
+
* Taking the url, found definition and variables and returning a redirect result object
|
|
330
|
+
* @param processedUrl - Propertly formatted url input
|
|
331
|
+
* @param definition - Redirect definition found to match the processed url
|
|
332
|
+
* @param variables - Wildcard variables found during definition discovery
|
|
333
|
+
* @param options - Different options available to the redirect engine
|
|
334
|
+
*/
|
|
335
|
+
private static processDefinitionToResults;
|
|
336
|
+
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
337
|
+
}
|
|
338
|
+
declare class UncachedRedirectClient extends RedirectClient {
|
|
339
|
+
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
340
|
+
}
|
|
341
|
+
|
|
362
342
|
type RedirectUpsertRequest = paths['/api/v1/redirect']['put']['requestBody']['content']['application/json'];
|
|
363
343
|
type RedirectDeleteRequest = paths['/api/v1/redirect']['delete']['requestBody']['content']['application/json'];
|
|
364
344
|
type RedirectGetRequest = paths['/api/v1/redirect']['get']['parameters']['query'];
|
package/dist/index.d.ts
CHANGED
|
@@ -37,85 +37,6 @@ declare class TrieData<T> {
|
|
|
37
37
|
[key: string]: TrieData<T> | T;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
type RedirectClientCacheOptions = {
|
|
41
|
-
prePopulate?: boolean;
|
|
42
|
-
refreshRate?: number;
|
|
43
|
-
};
|
|
44
|
-
declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
|
|
45
|
-
options: RedirectClientCacheOptions;
|
|
46
|
-
constructor(options: RedirectClientCacheOptions);
|
|
47
|
-
abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
|
|
48
|
-
abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
|
|
49
|
-
abstract refresh(): Promise<void[]>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type RedirectClientOptions = ClientOptions & {
|
|
53
|
-
/** Caching mechanism used to hold redirect data payload for rapid retrieval */
|
|
54
|
-
dataCache?: RedirectClientCache<RedirectClientCacheOptions>;
|
|
55
|
-
};
|
|
56
|
-
type RedirectOptions = {
|
|
57
|
-
/** Reverse flips the direction of the search, instead of redirecting a source to a target you will be finding the source that could have produced a given target */
|
|
58
|
-
reverse?: boolean;
|
|
59
|
-
/** Includes a label highlighting all wildcard variables with HTML em tags */
|
|
60
|
-
label?: boolean;
|
|
61
|
-
};
|
|
62
|
-
declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
63
|
-
constructor(options: RedirectClientOptions);
|
|
64
|
-
getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
|
|
65
|
-
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
|
|
66
|
-
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
|
|
67
|
-
redirect: {
|
|
68
|
-
id?: string | undefined;
|
|
69
|
-
sourceUrl: string;
|
|
70
|
-
targetUrl: string;
|
|
71
|
-
targetStatusCode: number;
|
|
72
|
-
sourceProjectMapNodeId?: string | undefined;
|
|
73
|
-
targetProjectMapNodeId?: string | undefined;
|
|
74
|
-
projectMapId?: string | undefined;
|
|
75
|
-
sourceRetainQuerystring?: boolean | undefined;
|
|
76
|
-
sourceMustMatchDomain?: boolean | undefined;
|
|
77
|
-
targetPreserveIncomingProtocol?: boolean | undefined;
|
|
78
|
-
targetPreserveIncomingDomain?: boolean | undefined;
|
|
79
|
-
targetMergeQuerystring?: boolean | undefined;
|
|
80
|
-
labelAsSystem?: boolean | undefined;
|
|
81
|
-
};
|
|
82
|
-
metadata: {
|
|
83
|
-
updatedAt?: string | undefined;
|
|
84
|
-
updatedBy?: string | undefined;
|
|
85
|
-
createdAt?: string | undefined;
|
|
86
|
-
createdBy?: string | undefined;
|
|
87
|
-
createdByName?: string | undefined;
|
|
88
|
-
};
|
|
89
|
-
total: number | undefined;
|
|
90
|
-
}, void, unknown>;
|
|
91
|
-
getRedirectTrie: (options?: {
|
|
92
|
-
bypassDataCache?: boolean;
|
|
93
|
-
}) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
|
|
94
|
-
resetRedirectTrieDataCache: () => Promise<void>;
|
|
95
|
-
upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
|
|
96
|
-
deleteRedirect: (id: string) => Promise<string>;
|
|
97
|
-
static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
|
|
98
|
-
processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
|
|
99
|
-
processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
|
|
100
|
-
private static assembling;
|
|
101
|
-
private static assemblingPromise;
|
|
102
|
-
private assembleTrie;
|
|
103
|
-
private static processHops;
|
|
104
|
-
private static processHop;
|
|
105
|
-
/**
|
|
106
|
-
* Taking the url, found definition and variables and returning a redirect result object
|
|
107
|
-
* @param processedUrl - Propertly formatted url input
|
|
108
|
-
* @param definition - Redirect definition found to match the processed url
|
|
109
|
-
* @param variables - Wildcard variables found during definition discovery
|
|
110
|
-
* @param options - Different options available to the redirect engine
|
|
111
|
-
*/
|
|
112
|
-
private static processDefinitionToResults;
|
|
113
|
-
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
114
|
-
}
|
|
115
|
-
declare class UncachedRedirectClient extends RedirectClient {
|
|
116
|
-
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
40
|
/**
|
|
120
41
|
* This file was auto-generated by openapi-typescript.
|
|
121
42
|
* Do not make direct changes to the file.
|
|
@@ -136,17 +57,17 @@ interface paths {
|
|
|
136
57
|
sourceUrl?: string;
|
|
137
58
|
/** Find redirects that could redirect to this url */
|
|
138
59
|
targetUrl?: string;
|
|
139
|
-
/** Id of the project map the source or target belongs to
|
|
60
|
+
/** Id of the project map the source or target belongs to */
|
|
140
61
|
projectMapId?: string;
|
|
141
|
-
/** Id of the project map node to find redirects for
|
|
62
|
+
/** Id of the project map node to find redirects for */
|
|
142
63
|
sourceProjectMapNodeId?: string;
|
|
143
|
-
/** Id of the project map node to find redirects for
|
|
64
|
+
/** Id of the project map node to find redirects for */
|
|
144
65
|
targetProjectMapNodeId?: string;
|
|
145
|
-
/** Column to order results by, only applicable if trie is not active
|
|
66
|
+
/** Column to order results by, only applicable if trie is not active */
|
|
146
67
|
orderBy?: "updated_at asc" | "updated_at desc" | "source_url asc" | "source_url desc" | "target_url asc" | "target_url desc" | "created_by asc" | "created_by desc";
|
|
147
|
-
/** Limit the results to this number of results, ignored if using trie parameter
|
|
68
|
+
/** Limit the results to this number of results, ignored if using trie parameter */
|
|
148
69
|
limit?: number;
|
|
149
|
-
/** Offset the results a certain amount, useful for pagination
|
|
70
|
+
/** Offset the results a certain amount, useful for pagination */
|
|
150
71
|
offset?: number;
|
|
151
72
|
/** Search text to filter redirects by, filtering on the source and target urls */
|
|
152
73
|
search?: string;
|
|
@@ -233,19 +154,19 @@ interface paths {
|
|
|
233
154
|
"application/json": {
|
|
234
155
|
/**
|
|
235
156
|
* Format: uuid
|
|
236
|
-
* @description Redirect id to be deleted
|
|
157
|
+
* @description Redirect id to be deleted
|
|
237
158
|
*/
|
|
238
159
|
id: string;
|
|
239
160
|
/**
|
|
240
161
|
* Format: uuid
|
|
241
|
-
* @description Project the redirect belongs to
|
|
162
|
+
* @description Project the redirect belongs to
|
|
242
163
|
*/
|
|
243
164
|
projectId: string;
|
|
244
165
|
};
|
|
245
166
|
};
|
|
246
167
|
};
|
|
247
168
|
};
|
|
248
|
-
/** Handles preflight requests. This endpoint allows CORS
|
|
169
|
+
/** Handles preflight requests. This endpoint allows CORS */
|
|
249
170
|
options: {
|
|
250
171
|
responses: {
|
|
251
172
|
/** OK */
|
|
@@ -275,41 +196,41 @@ interface components {
|
|
|
275
196
|
Redirect: {
|
|
276
197
|
/**
|
|
277
198
|
* Format: uuid
|
|
278
|
-
* @description Id of the redirect
|
|
199
|
+
* @description Id of the redirect
|
|
279
200
|
*/
|
|
280
201
|
id?: string;
|
|
281
|
-
/** @description Source meant to match a url that needs to be redirected
|
|
202
|
+
/** @description Source meant to match a url that needs to be redirected */
|
|
282
203
|
sourceUrl: string;
|
|
283
|
-
/** @description Target meant to be redirected to
|
|
204
|
+
/** @description Target meant to be redirected to */
|
|
284
205
|
targetUrl: string;
|
|
285
|
-
/** @description Redirect type to occur from this redirect
|
|
206
|
+
/** @description Redirect type to occur from this redirect */
|
|
286
207
|
targetStatusCode: number;
|
|
287
208
|
/**
|
|
288
209
|
* Format: uuid
|
|
289
|
-
* @description Project map node related to the source this redirect
|
|
210
|
+
* @description Project map node related to the source this redirect
|
|
290
211
|
*/
|
|
291
212
|
sourceProjectMapNodeId?: string;
|
|
292
213
|
/**
|
|
293
214
|
* Format: uuid
|
|
294
|
-
* @description Project map node related to the target this redirect
|
|
215
|
+
* @description Project map node related to the target this redirect
|
|
295
216
|
*/
|
|
296
217
|
targetProjectMapNodeId?: string;
|
|
297
218
|
/**
|
|
298
219
|
* Format: uuid
|
|
299
|
-
* @description Project map related to this redirect
|
|
220
|
+
* @description Project map related to this redirect
|
|
300
221
|
*/
|
|
301
222
|
projectMapId?: string;
|
|
302
|
-
/** @description Signals the redirect engine to retain query string parameters to the target url
|
|
223
|
+
/** @description Signals the redirect engine to retain query string parameters to the target url */
|
|
303
224
|
sourceRetainQuerystring?: boolean;
|
|
304
|
-
/** @description Incoming requests must match the domain that's defined in the redirection source
|
|
225
|
+
/** @description Incoming requests must match the domain that's defined in the redirection source */
|
|
305
226
|
sourceMustMatchDomain?: boolean;
|
|
306
|
-
/** @description Rewritten url should match the protocol (http / https) of the incoming request instead of whatever is defined in the redirection target
|
|
227
|
+
/** @description Rewritten url should match the protocol (http / https) of the incoming request instead of whatever is defined in the redirection target */
|
|
307
228
|
targetPreserveIncomingProtocol?: boolean;
|
|
308
|
-
/** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target
|
|
229
|
+
/** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target */
|
|
309
230
|
targetPreserveIncomingDomain?: boolean;
|
|
310
|
-
/** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible
|
|
231
|
+
/** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible */
|
|
311
232
|
targetMergeQuerystring?: boolean;
|
|
312
|
-
/** @description Label as system generated or user generated
|
|
233
|
+
/** @description Label as system generated or user generated */
|
|
313
234
|
labelAsSystem?: boolean;
|
|
314
235
|
};
|
|
315
236
|
};
|
|
@@ -359,6 +280,65 @@ interface external {
|
|
|
359
280
|
};
|
|
360
281
|
}
|
|
361
282
|
|
|
283
|
+
type RedirectClientCacheOptions = {
|
|
284
|
+
prePopulate?: boolean;
|
|
285
|
+
refreshRate?: number;
|
|
286
|
+
};
|
|
287
|
+
declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
|
|
288
|
+
options: RedirectClientCacheOptions;
|
|
289
|
+
constructor(options: RedirectClientCacheOptions);
|
|
290
|
+
abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
|
|
291
|
+
abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
|
|
292
|
+
abstract refresh(): Promise<void[]>;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
type RedirectClientOptions = ClientOptions & {
|
|
296
|
+
/** Caching mechanism used to hold redirect data payload for rapid retrieval */
|
|
297
|
+
dataCache?: RedirectClientCache<RedirectClientCacheOptions>;
|
|
298
|
+
};
|
|
299
|
+
type RedirectOptions = {
|
|
300
|
+
/** Reverse flips the direction of the search, instead of redirecting a source to a target you will be finding the source that could have produced a given target */
|
|
301
|
+
reverse?: boolean;
|
|
302
|
+
/** Includes a label highlighting all wildcard variables with HTML em tags */
|
|
303
|
+
label?: boolean;
|
|
304
|
+
};
|
|
305
|
+
declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
306
|
+
constructor(options: RedirectClientOptions);
|
|
307
|
+
getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
|
|
308
|
+
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
|
|
309
|
+
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
|
|
310
|
+
redirect: components["schemas"]["Redirect"];
|
|
311
|
+
metadata: components["schemas"]["RedirectMetadata"];
|
|
312
|
+
total: number | undefined;
|
|
313
|
+
}, void, unknown>;
|
|
314
|
+
getRedirectTrie: (options?: {
|
|
315
|
+
bypassDataCache?: boolean;
|
|
316
|
+
}) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
|
|
317
|
+
resetRedirectTrieDataCache: () => Promise<void>;
|
|
318
|
+
upsertRedirect: (redirect: RedirectUpsertRequest["redirect"]) => Promise<string>;
|
|
319
|
+
deleteRedirect: (id: string) => Promise<string>;
|
|
320
|
+
static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
|
|
321
|
+
processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
|
|
322
|
+
processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
|
|
323
|
+
private static assembling;
|
|
324
|
+
private static assemblingPromise;
|
|
325
|
+
private assembleTrie;
|
|
326
|
+
private static processHops;
|
|
327
|
+
private static processHop;
|
|
328
|
+
/**
|
|
329
|
+
* Taking the url, found definition and variables and returning a redirect result object
|
|
330
|
+
* @param processedUrl - Propertly formatted url input
|
|
331
|
+
* @param definition - Redirect definition found to match the processed url
|
|
332
|
+
* @param variables - Wildcard variables found during definition discovery
|
|
333
|
+
* @param options - Different options available to the redirect engine
|
|
334
|
+
*/
|
|
335
|
+
private static processDefinitionToResults;
|
|
336
|
+
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
337
|
+
}
|
|
338
|
+
declare class UncachedRedirectClient extends RedirectClient {
|
|
339
|
+
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
340
|
+
}
|
|
341
|
+
|
|
362
342
|
type RedirectUpsertRequest = paths['/api/v1/redirect']['put']['requestBody']['content']['application/json'];
|
|
363
343
|
type RedirectDeleteRequest = paths['/api/v1/redirect']['delete']['requestBody']['content']['application/json'];
|
|
364
344
|
type RedirectGetRequest = paths['/api/v1/redirect']['get']['parameters']['query'];
|
package/dist/index.esm.js
CHANGED
|
@@ -64,8 +64,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
64
64
|
/* Set new data to the cache and reset the refresh method */
|
|
65
65
|
set(key, data, refresh) {
|
|
66
66
|
var _a;
|
|
67
|
-
if (!data)
|
|
68
|
-
return;
|
|
67
|
+
if (!data) return;
|
|
69
68
|
const setCache = () => {
|
|
70
69
|
_WithMemoryCache.trieCache[key] = {
|
|
71
70
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -142,8 +141,7 @@ var PathTrie = class {
|
|
|
142
141
|
const segments = this.splitUrl(path);
|
|
143
142
|
for (let i = 0; i < segments.length; i++) {
|
|
144
143
|
const segment = segments[i];
|
|
145
|
-
if (i === 0 && segment === "")
|
|
146
|
-
continue;
|
|
144
|
+
if (i === 0 && segment === "") continue;
|
|
147
145
|
if (!Object.hasOwn(cur, segment)) {
|
|
148
146
|
cur[segment] = new PathTrieData();
|
|
149
147
|
}
|
|
@@ -164,10 +162,13 @@ var PathTrie = class {
|
|
|
164
162
|
const splats = [];
|
|
165
163
|
const processed = /* @__PURE__ */ new Set();
|
|
166
164
|
const getVariables = () => {
|
|
167
|
-
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
168
|
-
variables
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
166
|
+
(variables, wildcard) => {
|
|
167
|
+
variables[wildcard.name] = segments[wildcard.start];
|
|
168
|
+
return variables;
|
|
169
|
+
},
|
|
170
|
+
new Object()
|
|
171
|
+
);
|
|
171
172
|
};
|
|
172
173
|
const getPropsStartingWithColon = (obj) => {
|
|
173
174
|
const result = [];
|
|
@@ -183,8 +184,7 @@ var PathTrie = class {
|
|
|
183
184
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
184
185
|
wildcard = wildcards.pop();
|
|
185
186
|
}
|
|
186
|
-
if (!wildcard || wildcard.active)
|
|
187
|
-
return void 0;
|
|
187
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
188
188
|
wildcard.active = true;
|
|
189
189
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
190
190
|
wildcards.push(wildcard);
|
|
@@ -225,28 +225,23 @@ var PathTrie = class {
|
|
|
225
225
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
226
226
|
} else {
|
|
227
227
|
const more = scanWildcards();
|
|
228
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
229
|
-
return [...ret, ...splats];
|
|
228
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
230
229
|
i = more;
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
} else {
|
|
234
233
|
const more = scanWildcards();
|
|
235
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
236
|
-
return [...ret, ...splats];
|
|
234
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
237
235
|
i = more;
|
|
238
|
-
if (ret.length > 0 && bestMatch)
|
|
239
|
-
return [...ret, ...splats];
|
|
236
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
240
237
|
continue;
|
|
241
238
|
}
|
|
242
239
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
243
240
|
const more = scanWildcards();
|
|
244
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
245
|
-
return [...ret, ...splats];
|
|
241
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
246
242
|
i = more;
|
|
247
243
|
}
|
|
248
|
-
if (ret.length > 0 && bestMatch)
|
|
249
|
-
return [...ret, ...splats];
|
|
244
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
250
245
|
}
|
|
251
246
|
return [...ret, ...splats];
|
|
252
247
|
}
|
|
@@ -322,8 +317,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
322
317
|
const params1 = new URLSearchParams(qs1);
|
|
323
318
|
const params2 = new URLSearchParams(qs2);
|
|
324
319
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
325
|
-
if (merged.length > 0)
|
|
326
|
-
return (fragment ? "#" : "?") + merged;
|
|
320
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
327
321
|
return "";
|
|
328
322
|
}
|
|
329
323
|
|
|
@@ -354,8 +348,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
354
348
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
355
349
|
if (cachePromise) {
|
|
356
350
|
const result = await cachePromise;
|
|
357
|
-
if (result)
|
|
358
|
-
return result;
|
|
351
|
+
if (result) return result;
|
|
359
352
|
}
|
|
360
353
|
const ret = this.assembleTrie();
|
|
361
354
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -423,8 +416,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
423
416
|
);
|
|
424
417
|
const processedUrl = processUrl(sanitizedUrl);
|
|
425
418
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
426
|
-
if (!redirect)
|
|
427
|
-
return void 0;
|
|
419
|
+
if (!redirect) return void 0;
|
|
428
420
|
return _RedirectClient.processDefinitionToResults(
|
|
429
421
|
processedUrl,
|
|
430
422
|
redirect,
|
|
@@ -527,17 +519,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
527
519
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
528
520
|
const isCycle = (id, result) => {
|
|
529
521
|
var _a;
|
|
530
|
-
if (!id || !result.lastHop)
|
|
531
|
-
return false;
|
|
522
|
+
if (!id || !result.lastHop) return false;
|
|
532
523
|
const set = /* @__PURE__ */ new Set([id]);
|
|
533
524
|
const cycleStack = [result];
|
|
534
525
|
while (cycleStack.length > 0) {
|
|
535
526
|
const cur = cycleStack.pop();
|
|
536
527
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
537
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
538
|
-
|
|
539
|
-
if (set.has(redirect.id))
|
|
540
|
-
return true;
|
|
528
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
529
|
+
if (set.has(redirect.id)) return true;
|
|
541
530
|
set.add(redirect.id);
|
|
542
531
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
543
532
|
cycleStack.push(cur.lastHop);
|
|
@@ -549,8 +538,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
549
538
|
const ret = [];
|
|
550
539
|
while (stack.length > 0) {
|
|
551
540
|
const result = stack.pop();
|
|
552
|
-
if (!(result == null ? void 0 : result.url))
|
|
553
|
-
continue;
|
|
541
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
554
542
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
555
543
|
(h) => {
|
|
556
544
|
var _a, _b;
|
|
@@ -589,8 +577,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
589
577
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
590
578
|
const processedResult = processUrl(resultUrl);
|
|
591
579
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
592
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
593
|
-
return void 0;
|
|
580
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
594
581
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
595
582
|
return {
|
|
596
583
|
url: finalUrl,
|
|
@@ -605,14 +592,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
605
592
|
const processedUrl = processUrl(url);
|
|
606
593
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
607
594
|
return false;
|
|
608
|
-
if (processedSource.query && !processedUrl.query)
|
|
609
|
-
return false;
|
|
595
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
610
596
|
if (processedSource.query && processedUrl.query) {
|
|
611
597
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
612
598
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
613
599
|
for (const [key] of sourceqs) {
|
|
614
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
615
|
-
return false;
|
|
600
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
616
601
|
}
|
|
617
602
|
}
|
|
618
603
|
return true;
|
package/dist/index.js
CHANGED
|
@@ -110,8 +110,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
110
110
|
/* Set new data to the cache and reset the refresh method */
|
|
111
111
|
set(key, data, refresh) {
|
|
112
112
|
var _a;
|
|
113
|
-
if (!data)
|
|
114
|
-
return;
|
|
113
|
+
if (!data) return;
|
|
115
114
|
const setCache = () => {
|
|
116
115
|
_WithMemoryCache.trieCache[key] = {
|
|
117
116
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -188,8 +187,7 @@ var PathTrie = class {
|
|
|
188
187
|
const segments = this.splitUrl(path);
|
|
189
188
|
for (let i = 0; i < segments.length; i++) {
|
|
190
189
|
const segment = segments[i];
|
|
191
|
-
if (i === 0 && segment === "")
|
|
192
|
-
continue;
|
|
190
|
+
if (i === 0 && segment === "") continue;
|
|
193
191
|
if (!Object.hasOwn(cur, segment)) {
|
|
194
192
|
cur[segment] = new PathTrieData();
|
|
195
193
|
}
|
|
@@ -210,10 +208,13 @@ var PathTrie = class {
|
|
|
210
208
|
const splats = [];
|
|
211
209
|
const processed = /* @__PURE__ */ new Set();
|
|
212
210
|
const getVariables = () => {
|
|
213
|
-
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
214
|
-
variables
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
212
|
+
(variables, wildcard) => {
|
|
213
|
+
variables[wildcard.name] = segments[wildcard.start];
|
|
214
|
+
return variables;
|
|
215
|
+
},
|
|
216
|
+
new Object()
|
|
217
|
+
);
|
|
217
218
|
};
|
|
218
219
|
const getPropsStartingWithColon = (obj) => {
|
|
219
220
|
const result = [];
|
|
@@ -229,8 +230,7 @@ var PathTrie = class {
|
|
|
229
230
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
230
231
|
wildcard = wildcards.pop();
|
|
231
232
|
}
|
|
232
|
-
if (!wildcard || wildcard.active)
|
|
233
|
-
return void 0;
|
|
233
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
234
234
|
wildcard.active = true;
|
|
235
235
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
236
236
|
wildcards.push(wildcard);
|
|
@@ -271,28 +271,23 @@ var PathTrie = class {
|
|
|
271
271
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
272
272
|
} else {
|
|
273
273
|
const more = scanWildcards();
|
|
274
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
275
|
-
return [...ret, ...splats];
|
|
274
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
276
275
|
i = more;
|
|
277
276
|
}
|
|
278
277
|
}
|
|
279
278
|
} else {
|
|
280
279
|
const more = scanWildcards();
|
|
281
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
282
|
-
return [...ret, ...splats];
|
|
280
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
283
281
|
i = more;
|
|
284
|
-
if (ret.length > 0 && bestMatch)
|
|
285
|
-
return [...ret, ...splats];
|
|
282
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
286
283
|
continue;
|
|
287
284
|
}
|
|
288
285
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
289
286
|
const more = scanWildcards();
|
|
290
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
291
|
-
return [...ret, ...splats];
|
|
287
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
292
288
|
i = more;
|
|
293
289
|
}
|
|
294
|
-
if (ret.length > 0 && bestMatch)
|
|
295
|
-
return [...ret, ...splats];
|
|
290
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
296
291
|
}
|
|
297
292
|
return [...ret, ...splats];
|
|
298
293
|
}
|
|
@@ -368,8 +363,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
368
363
|
const params1 = new URLSearchParams(qs1);
|
|
369
364
|
const params2 = new URLSearchParams(qs2);
|
|
370
365
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
371
|
-
if (merged.length > 0)
|
|
372
|
-
return (fragment ? "#" : "?") + merged;
|
|
366
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
373
367
|
return "";
|
|
374
368
|
}
|
|
375
369
|
|
|
@@ -400,8 +394,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
400
394
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
401
395
|
if (cachePromise) {
|
|
402
396
|
const result = await cachePromise;
|
|
403
|
-
if (result)
|
|
404
|
-
return result;
|
|
397
|
+
if (result) return result;
|
|
405
398
|
}
|
|
406
399
|
const ret = this.assembleTrie();
|
|
407
400
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -469,8 +462,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
469
462
|
);
|
|
470
463
|
const processedUrl = processUrl(sanitizedUrl);
|
|
471
464
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
472
|
-
if (!redirect)
|
|
473
|
-
return void 0;
|
|
465
|
+
if (!redirect) return void 0;
|
|
474
466
|
return _RedirectClient.processDefinitionToResults(
|
|
475
467
|
processedUrl,
|
|
476
468
|
redirect,
|
|
@@ -573,17 +565,14 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
573
565
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
574
566
|
const isCycle = (id, result) => {
|
|
575
567
|
var _a;
|
|
576
|
-
if (!id || !result.lastHop)
|
|
577
|
-
return false;
|
|
568
|
+
if (!id || !result.lastHop) return false;
|
|
578
569
|
const set = /* @__PURE__ */ new Set([id]);
|
|
579
570
|
const cycleStack = [result];
|
|
580
571
|
while (cycleStack.length > 0) {
|
|
581
572
|
const cur = cycleStack.pop();
|
|
582
573
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
583
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
584
|
-
|
|
585
|
-
if (set.has(redirect.id))
|
|
586
|
-
return true;
|
|
574
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
575
|
+
if (set.has(redirect.id)) return true;
|
|
587
576
|
set.add(redirect.id);
|
|
588
577
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
589
578
|
cycleStack.push(cur.lastHop);
|
|
@@ -595,8 +584,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
595
584
|
const ret = [];
|
|
596
585
|
while (stack.length > 0) {
|
|
597
586
|
const result = stack.pop();
|
|
598
|
-
if (!(result == null ? void 0 : result.url))
|
|
599
|
-
continue;
|
|
587
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
600
588
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
601
589
|
(h) => {
|
|
602
590
|
var _a, _b;
|
|
@@ -635,8 +623,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
635
623
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
636
624
|
const processedResult = processUrl(resultUrl);
|
|
637
625
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
638
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
639
|
-
return void 0;
|
|
626
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
640
627
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
641
628
|
return {
|
|
642
629
|
url: finalUrl,
|
|
@@ -651,14 +638,12 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
651
638
|
const processedUrl = processUrl(url);
|
|
652
639
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
653
640
|
return false;
|
|
654
|
-
if (processedSource.query && !processedUrl.query)
|
|
655
|
-
return false;
|
|
641
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
656
642
|
if (processedSource.query && processedUrl.query) {
|
|
657
643
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
658
644
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
659
645
|
for (const [key] of sourceqs) {
|
|
660
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
661
|
-
return false;
|
|
646
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
662
647
|
}
|
|
663
648
|
}
|
|
664
649
|
return true;
|
package/dist/index.mjs
CHANGED
|
@@ -64,8 +64,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
64
64
|
/* Set new data to the cache and reset the refresh method */
|
|
65
65
|
set(key, data, refresh) {
|
|
66
66
|
var _a;
|
|
67
|
-
if (!data)
|
|
68
|
-
return;
|
|
67
|
+
if (!data) return;
|
|
69
68
|
const setCache = () => {
|
|
70
69
|
_WithMemoryCache.trieCache[key] = {
|
|
71
70
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -142,8 +141,7 @@ var PathTrie = class {
|
|
|
142
141
|
const segments = this.splitUrl(path);
|
|
143
142
|
for (let i = 0; i < segments.length; i++) {
|
|
144
143
|
const segment = segments[i];
|
|
145
|
-
if (i === 0 && segment === "")
|
|
146
|
-
continue;
|
|
144
|
+
if (i === 0 && segment === "") continue;
|
|
147
145
|
if (!Object.hasOwn(cur, segment)) {
|
|
148
146
|
cur[segment] = new PathTrieData();
|
|
149
147
|
}
|
|
@@ -164,10 +162,13 @@ var PathTrie = class {
|
|
|
164
162
|
const splats = [];
|
|
165
163
|
const processed = /* @__PURE__ */ new Set();
|
|
166
164
|
const getVariables = () => {
|
|
167
|
-
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
168
|
-
variables
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce(
|
|
166
|
+
(variables, wildcard) => {
|
|
167
|
+
variables[wildcard.name] = segments[wildcard.start];
|
|
168
|
+
return variables;
|
|
169
|
+
},
|
|
170
|
+
new Object()
|
|
171
|
+
);
|
|
171
172
|
};
|
|
172
173
|
const getPropsStartingWithColon = (obj) => {
|
|
173
174
|
const result = [];
|
|
@@ -183,8 +184,7 @@ var PathTrie = class {
|
|
|
183
184
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
184
185
|
wildcard = wildcards.pop();
|
|
185
186
|
}
|
|
186
|
-
if (!wildcard || wildcard.active)
|
|
187
|
-
return void 0;
|
|
187
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
188
188
|
wildcard.active = true;
|
|
189
189
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
190
190
|
wildcards.push(wildcard);
|
|
@@ -225,28 +225,23 @@ var PathTrie = class {
|
|
|
225
225
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
226
226
|
} else {
|
|
227
227
|
const more = scanWildcards();
|
|
228
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
229
|
-
return [...ret, ...splats];
|
|
228
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
230
229
|
i = more;
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
} else {
|
|
234
233
|
const more = scanWildcards();
|
|
235
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
236
|
-
return [...ret, ...splats];
|
|
234
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
237
235
|
i = more;
|
|
238
|
-
if (ret.length > 0 && bestMatch)
|
|
239
|
-
return [...ret, ...splats];
|
|
236
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
240
237
|
continue;
|
|
241
238
|
}
|
|
242
239
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
243
240
|
const more = scanWildcards();
|
|
244
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
245
|
-
return [...ret, ...splats];
|
|
241
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
246
242
|
i = more;
|
|
247
243
|
}
|
|
248
|
-
if (ret.length > 0 && bestMatch)
|
|
249
|
-
return [...ret, ...splats];
|
|
244
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
250
245
|
}
|
|
251
246
|
return [...ret, ...splats];
|
|
252
247
|
}
|
|
@@ -322,8 +317,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
322
317
|
const params1 = new URLSearchParams(qs1);
|
|
323
318
|
const params2 = new URLSearchParams(qs2);
|
|
324
319
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
325
|
-
if (merged.length > 0)
|
|
326
|
-
return (fragment ? "#" : "?") + merged;
|
|
320
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
327
321
|
return "";
|
|
328
322
|
}
|
|
329
323
|
|
|
@@ -354,8 +348,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
354
348
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
355
349
|
if (cachePromise) {
|
|
356
350
|
const result = await cachePromise;
|
|
357
|
-
if (result)
|
|
358
|
-
return result;
|
|
351
|
+
if (result) return result;
|
|
359
352
|
}
|
|
360
353
|
const ret = this.assembleTrie();
|
|
361
354
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -423,8 +416,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
423
416
|
);
|
|
424
417
|
const processedUrl = processUrl(sanitizedUrl);
|
|
425
418
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
426
|
-
if (!redirect)
|
|
427
|
-
return void 0;
|
|
419
|
+
if (!redirect) return void 0;
|
|
428
420
|
return _RedirectClient.processDefinitionToResults(
|
|
429
421
|
processedUrl,
|
|
430
422
|
redirect,
|
|
@@ -527,17 +519,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
527
519
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
528
520
|
const isCycle = (id, result) => {
|
|
529
521
|
var _a;
|
|
530
|
-
if (!id || !result.lastHop)
|
|
531
|
-
return false;
|
|
522
|
+
if (!id || !result.lastHop) return false;
|
|
532
523
|
const set = /* @__PURE__ */ new Set([id]);
|
|
533
524
|
const cycleStack = [result];
|
|
534
525
|
while (cycleStack.length > 0) {
|
|
535
526
|
const cur = cycleStack.pop();
|
|
536
527
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
537
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
538
|
-
|
|
539
|
-
if (set.has(redirect.id))
|
|
540
|
-
return true;
|
|
528
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
529
|
+
if (set.has(redirect.id)) return true;
|
|
541
530
|
set.add(redirect.id);
|
|
542
531
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
543
532
|
cycleStack.push(cur.lastHop);
|
|
@@ -549,8 +538,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
549
538
|
const ret = [];
|
|
550
539
|
while (stack.length > 0) {
|
|
551
540
|
const result = stack.pop();
|
|
552
|
-
if (!(result == null ? void 0 : result.url))
|
|
553
|
-
continue;
|
|
541
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
554
542
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
555
543
|
(h) => {
|
|
556
544
|
var _a, _b;
|
|
@@ -589,8 +577,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
589
577
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
590
578
|
const processedResult = processUrl(resultUrl);
|
|
591
579
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
592
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
593
|
-
return void 0;
|
|
580
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
594
581
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
595
582
|
return {
|
|
596
583
|
url: finalUrl,
|
|
@@ -605,14 +592,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
605
592
|
const processedUrl = processUrl(url);
|
|
606
593
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
607
594
|
return false;
|
|
608
|
-
if (processedSource.query && !processedUrl.query)
|
|
609
|
-
return false;
|
|
595
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
610
596
|
if (processedSource.query && processedUrl.query) {
|
|
611
597
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
612
598
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
613
599
|
for (const [key] of sourceqs) {
|
|
614
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
615
|
-
return false;
|
|
600
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
616
601
|
}
|
|
617
602
|
}
|
|
618
603
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.135.1-alpha.
|
|
3
|
+
"version": "19.135.1-alpha.12+5743153a1e",
|
|
4
4
|
"description": "Uniform redirect client",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"/dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@uniformdev/context": "19.135.1-alpha.
|
|
36
|
+
"@uniformdev/context": "19.135.1-alpha.12+5743153a1e",
|
|
37
37
|
"p-limit": "^3.1.0",
|
|
38
38
|
"rfdc": "^1.3.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "5743153a1e4308de3dfe7c0812eb493154421a71"
|
|
44
44
|
}
|