@uniformdev/redirect 19.35.2 → 19.35.3-alpha.82

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.
Files changed (2) hide show
  1. package/dist/index.d.mts +453 -0
  2. package/package.json +3 -3
@@ -0,0 +1,453 @@
1
+ import { ClientOptions, ApiClient } from '@uniformdev/context/api';
2
+
3
+ interface pathTrieReturn<T> {
4
+ data: T;
5
+ variables: {
6
+ key: string;
7
+ value: string;
8
+ }[];
9
+ }
10
+ declare class PathTrie<T> {
11
+ constructor(initialData?: PathTrieData<T>);
12
+ map: PathTrieData<T[]>;
13
+ convertManyInsert<P>(data: P[], key: (data: P) => string, value?: (data: P) => T): void;
14
+ insertMany(data: T[], key: (data: T) => string): void;
15
+ insert(path: string, data: T): void;
16
+ find(path: string, bestMatch?: boolean): pathTrieReturn<T>[] | undefined;
17
+ private splitUrl;
18
+ private clone;
19
+ }
20
+ declare class PathTrieData<T> {
21
+ [key: string]: PathTrieData<T> | T;
22
+ }
23
+
24
+ declare class Trie<T> {
25
+ constructor(initialData?: TrieData<T>);
26
+ map: TrieData<T[]>;
27
+ convertManyInsert<P>(data: P[], key: (data: P) => string, value?: (data: P) => T): void;
28
+ insertMany(data: T[], key: (data: T) => string): void;
29
+ insert(word: string, data: T): void;
30
+ find(word: string, bestMatch?: boolean): {
31
+ data: T;
32
+ variables: string[];
33
+ }[] | undefined;
34
+ processChar(char: string): string;
35
+ private clone;
36
+ }
37
+ declare class TrieData<T> {
38
+ [key: string]: TrieData<T> | T;
39
+ }
40
+
41
+ type RedirectClientCacheOptions = {
42
+ prePopulate?: boolean;
43
+ refreshRate?: number;
44
+ };
45
+ declare abstract class RedirectClientCache<RedirectClientCacheOptions> {
46
+ options: RedirectClientCacheOptions;
47
+ constructor(options: RedirectClientCacheOptions);
48
+ abstract get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
49
+ abstract set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>>, refresh: () => Promise<PathTrie<DirectionAwareRedirectDefinition>>): void;
50
+ abstract refresh(): Promise<void[]>;
51
+ }
52
+
53
+ type RedirectClientOptions = ClientOptions & {
54
+ /** Caching mechanism used to hold redirect data payload for rapid retrieval */
55
+ dataCache?: RedirectClientCache<RedirectClientCacheOptions>;
56
+ };
57
+ type RedirectOptions = {
58
+ /** 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 */
59
+ reverse?: boolean;
60
+ /** Includes a label highlighting all wildcard variables with HTML em tags */
61
+ label?: boolean;
62
+ };
63
+ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
64
+ constructor(options: RedirectClientOptions);
65
+ getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
66
+ getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
67
+ getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
68
+ redirect: {
69
+ id?: string | undefined;
70
+ sourceUrl: string;
71
+ targetUrl: string;
72
+ targetStatusCode: number;
73
+ sourceProjectMapNodeId?: string | undefined;
74
+ targetProjectMapNodeId?: string | undefined;
75
+ projectMapId?: string | undefined;
76
+ sourceRetainQuerystring?: boolean | undefined;
77
+ sourceMustMatchDomain?: boolean | undefined;
78
+ targetPreserveIncomingProtocol?: boolean | undefined;
79
+ targetPreserveIncomingDomain?: boolean | undefined;
80
+ stopExecutingAfter?: boolean | undefined;
81
+ targetMergeQuerystring?: boolean | undefined;
82
+ labelAsSystem?: boolean | undefined;
83
+ };
84
+ metadata: {
85
+ updatedAt?: string | undefined;
86
+ updatedBy?: string | undefined;
87
+ createdAt?: string | undefined;
88
+ createdBy?: string | undefined;
89
+ createdByName?: string | undefined;
90
+ };
91
+ total: number | undefined;
92
+ }, void, unknown>;
93
+ getRedirectTrie: (options?: {
94
+ bypassDataCache?: boolean;
95
+ }) => Promise<PathTrie<DirectionAwareRedirectDefinition>>;
96
+ resetRedirectTrieDataCache: () => Promise<void>;
97
+ upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
98
+ deleteRedirect: (id: string) => Promise<string>;
99
+ static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
100
+ processUrlBestMatch: (url: string, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
101
+ processUrlAllMatches: (url: string, options?: RedirectOptions) => Promise<RedirectResult[]>;
102
+ private static assembling;
103
+ private static assemblingPromise;
104
+ private assembleTrie;
105
+ private static processHops;
106
+ private static processHop;
107
+ /**
108
+ * Taking the url, found definition and variables and returning a redirect result object
109
+ * @param processedUrl - Propertly formatted url input
110
+ * @param definition - Redirect definition found to match the processed url
111
+ * @param variables - Wildcard variables found during definition discovery
112
+ * @param options - Different options available to the redirect engine
113
+ */
114
+ private static processDefinitionToResults;
115
+ static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
116
+ static getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
117
+ private static mergeQueryStrings;
118
+ private static getSourceVariables;
119
+ }
120
+ declare class UncachedRedirectClient extends RedirectClient {
121
+ constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
122
+ }
123
+
124
+ /**
125
+ * This file was auto-generated by openapi-typescript.
126
+ * Do not make direct changes to the file.
127
+ */
128
+ interface paths {
129
+ "/api/v1/redirect": {
130
+ /** Called to retrieve a list of redirects related to a project */
131
+ get: {
132
+ parameters: {
133
+ query: {
134
+ /** The project to fetch redirects for */
135
+ projectId: string;
136
+ /** Id of the redirect to retrieve */
137
+ id?: string;
138
+ /** Ids of the redirects to retrieve */
139
+ ids?: string[];
140
+ /** Source url to attempt to find redirects for */
141
+ sourceUrl?: string;
142
+ /** Id of the project map the source or target belongs to. */
143
+ projectMapId?: string;
144
+ /** Id of the project map node to find redirects for. */
145
+ sourceProjectMapNodeId?: string;
146
+ /** Id of the project map node to find redirects for. */
147
+ targetProjectMapNodeId?: string;
148
+ /** Column to order results by, only applicable if trie is not active. */
149
+ 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";
150
+ /** Limit the results to this number of results, ignored if using trie parameter. */
151
+ limit?: number;
152
+ /** Offset the results a certain amount, useful for pagination. */
153
+ offset?: number;
154
+ /** Search text to filter redirects by, filtering on the source and target urls */
155
+ search?: string;
156
+ };
157
+ };
158
+ responses: {
159
+ /** OK */
160
+ 200: {
161
+ content: {
162
+ "application/json": {
163
+ redirects: components["schemas"]["RedirectGetResponse"];
164
+ total?: number;
165
+ resultUrl?: string;
166
+ };
167
+ };
168
+ };
169
+ 400: external["swagger.yml"]["components"]["responses"]["BadRequestError"];
170
+ 401: external["swagger.yml"]["components"]["responses"]["UnauthorizedError"];
171
+ 403: external["swagger.yml"]["components"]["responses"]["ForbiddenError"];
172
+ 429: external["swagger.yml"]["components"]["responses"]["RateLimitError"];
173
+ 500: external["swagger.yml"]["components"]["responses"]["InternalServerError"];
174
+ };
175
+ };
176
+ put: {
177
+ responses: {
178
+ /** OK */
179
+ 200: {
180
+ content: {
181
+ "application/json": {
182
+ /**
183
+ * Format: uuid
184
+ * @description Id of the redirect
185
+ */
186
+ id: string;
187
+ };
188
+ };
189
+ };
190
+ /** OK */
191
+ 204: never;
192
+ 400: external["swagger.yml"]["components"]["responses"]["BadRequestError"];
193
+ 401: external["swagger.yml"]["components"]["responses"]["UnauthorizedError"];
194
+ 403: external["swagger.yml"]["components"]["responses"]["ForbiddenError"];
195
+ 429: external["swagger.yml"]["components"]["responses"]["RateLimitError"];
196
+ 500: external["swagger.yml"]["components"]["responses"]["InternalServerError"];
197
+ };
198
+ requestBody: {
199
+ content: {
200
+ "application/json": {
201
+ /** @description Redirect object to insert */
202
+ redirect: components["schemas"]["Redirect"];
203
+ /**
204
+ * Format: uuid
205
+ * @description Project id to insert the redirect into
206
+ */
207
+ projectId: string;
208
+ };
209
+ };
210
+ };
211
+ };
212
+ /** Called to delete a redirect */
213
+ delete: {
214
+ responses: {
215
+ /** OK */
216
+ 200: {
217
+ content: {
218
+ "application/json": {
219
+ /**
220
+ * Format: uuid
221
+ * @description Id of the redirect
222
+ */
223
+ id: string;
224
+ };
225
+ };
226
+ };
227
+ /** OK */
228
+ 204: never;
229
+ 400: external["swagger.yml"]["components"]["responses"]["BadRequestError"];
230
+ 401: external["swagger.yml"]["components"]["responses"]["UnauthorizedError"];
231
+ 403: external["swagger.yml"]["components"]["responses"]["ForbiddenError"];
232
+ 429: external["swagger.yml"]["components"]["responses"]["RateLimitError"];
233
+ 500: external["swagger.yml"]["components"]["responses"]["InternalServerError"];
234
+ };
235
+ requestBody: {
236
+ content: {
237
+ "application/json": {
238
+ /**
239
+ * Format: uuid
240
+ * @description Redirect id to be deleted.
241
+ */
242
+ id: string;
243
+ /**
244
+ * Format: uuid
245
+ * @description Project the redirect belongs to.
246
+ */
247
+ projectId: string;
248
+ };
249
+ };
250
+ };
251
+ };
252
+ /** Handles preflight requests. This endpoint allows CORS. */
253
+ options: {
254
+ responses: {
255
+ /** OK */
256
+ 204: never;
257
+ };
258
+ };
259
+ };
260
+ }
261
+ interface components {
262
+ schemas: {
263
+ RedirectGetResponse: {
264
+ redirect: components["schemas"]["Redirect"];
265
+ metadata: components["schemas"]["RedirectMetadata"];
266
+ }[];
267
+ RedirectMetadata: {
268
+ /** @description The last time the redirect was modified in UTC */
269
+ updatedAt?: string;
270
+ /** @description The last user who modified this redirect */
271
+ updatedBy?: string;
272
+ /** @description The time the redirect was created in UTC */
273
+ createdAt?: string;
274
+ /** @description The user who created this redirect */
275
+ createdBy?: string;
276
+ /** @description The user who created this redirect's name */
277
+ createdByName?: string;
278
+ };
279
+ Redirect: {
280
+ /**
281
+ * Format: uuid
282
+ * @description Id of the redirect.
283
+ */
284
+ id?: string;
285
+ /** @description Source meant to match a url that needs to be redirected. */
286
+ sourceUrl: string;
287
+ /** @description Target meant to be redirected to. */
288
+ targetUrl: string;
289
+ /** @description Redirect type to occur from this redirect. */
290
+ targetStatusCode: number;
291
+ /**
292
+ * Format: uuid
293
+ * @description Project map node related to the source this redirect.
294
+ */
295
+ sourceProjectMapNodeId?: string;
296
+ /**
297
+ * Format: uuid
298
+ * @description Project map node related to the target this redirect.
299
+ */
300
+ targetProjectMapNodeId?: string;
301
+ /**
302
+ * Format: uuid
303
+ * @description Project map related to this redirect.
304
+ */
305
+ projectMapId?: string;
306
+ /** @description Signals the redirect engine to retain query string parameters to the target url. */
307
+ sourceRetainQuerystring?: boolean;
308
+ /** @description Incoming requests must match the domain that's defined in the redirection source. */
309
+ sourceMustMatchDomain?: boolean;
310
+ /** @description Rewritten url should match the protocol (http / https) of the incoming request instead of whatever is defined in the redirection target. */
311
+ targetPreserveIncomingProtocol?: boolean;
312
+ /** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target. */
313
+ targetPreserveIncomingDomain?: boolean;
314
+ /** @description Stop running rules after this redirect rule gets executed. */
315
+ stopExecutingAfter?: boolean;
316
+ /** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible. */
317
+ targetMergeQuerystring?: boolean;
318
+ /** @description Label as system generated or user generated. */
319
+ labelAsSystem?: boolean;
320
+ };
321
+ };
322
+ }
323
+ interface external {
324
+ "swagger.yml": {
325
+ paths: {};
326
+ components: {
327
+ schemas: {
328
+ Error: {
329
+ /** @description Error message(s) that occurred while processing the request */
330
+ errorMessage?: string[] | string;
331
+ };
332
+ };
333
+ responses: {
334
+ /** Request input validation failed */
335
+ BadRequestError: {
336
+ content: {
337
+ "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
338
+ };
339
+ };
340
+ /** API key or token was not valid */
341
+ UnauthorizedError: {
342
+ content: {
343
+ "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
344
+ };
345
+ };
346
+ /** Permission was denied */
347
+ ForbiddenError: {
348
+ content: {
349
+ "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
350
+ };
351
+ };
352
+ /** Resource not found */
353
+ NotFoundError: {
354
+ content: {
355
+ "application/json": external["swagger.yml"]["components"]["schemas"]["Error"];
356
+ };
357
+ };
358
+ /** Too many requests in allowed time period */
359
+ RateLimitError: unknown;
360
+ /** Execution error occurred */
361
+ InternalServerError: unknown;
362
+ };
363
+ };
364
+ operations: {};
365
+ };
366
+ }
367
+
368
+ type RedirectUpsertRequest = paths['/api/v1/redirect']['put']['requestBody']['content']['application/json'];
369
+ type RedirectDeleteRequest = paths['/api/v1/redirect']['delete']['requestBody']['content']['application/json'];
370
+ type RedirectGetRequest = paths['/api/v1/redirect']['get']['parameters']['query'];
371
+ type RedirectUpsertResponse = paths['/api/v1/redirect']['put']['responses']['200']['content']['application/json'];
372
+ type RedirectDeleteResponse = paths['/api/v1/redirect']['delete']['responses']['200']['content']['application/json'];
373
+ type RedirectGetResponse = paths['/api/v1/redirect']['get']['responses']['200']['content']['application/json'];
374
+ type RedirectClientGetRequest = Omit<RedirectGetRequest, 'projectId'>;
375
+ type RedirectDefinition = RedirectGetResponse['redirects'][0];
376
+ type RedirectDefinitions = {
377
+ redirects: RedirectDefinition['redirect'][];
378
+ };
379
+ type DirectionAwareRedirectDefinition = RedirectDefinition & {
380
+ reverse: boolean;
381
+ };
382
+ type RedirectResult = {
383
+ url: string;
384
+ label?: string;
385
+ headers?: {
386
+ [key: string]: string;
387
+ };
388
+ definition?: RedirectDefinition;
389
+ lastHop?: RedirectResult;
390
+ };
391
+ type RedirectDataCache = {
392
+ get: (client: RedirectClient) => Promise<Trie<RedirectDefinition>>;
393
+ preload?: boolean;
394
+ };
395
+ type RedirectClientGetRedirect = Pick<RedirectClientGetRequest, 'id' | 'projectMapId' | 'sourceProjectMapNodeId' | 'targetProjectMapNodeId'>;
396
+ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search'>;
397
+
398
+ declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
399
+ private static refresher?;
400
+ constructor(options: RedirectClientCacheOptions);
401
+ private static trieCache;
402
+ get(key: string): Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined;
403
+ set(key: string, data: Promise<PathTrie<DirectionAwareRedirectDefinition>> | undefined, refresh: (() => Promise<PathTrie<DirectionAwareRedirectDefinition>>) | undefined): void;
404
+ refresh(): Promise<void[]>;
405
+ }
406
+
407
+ type Wildcard = {
408
+ pathSegment: string;
409
+ index: number;
410
+ };
411
+ type SourceAndTarget = {
412
+ sourceUrl: string;
413
+ targetUrl: string;
414
+ };
415
+ type SourceTargetAndWildcards = SourceAndTarget & {
416
+ sourceWildcards: Wildcard[];
417
+ targetWildcards: Wildcard[];
418
+ };
419
+ type RedirectFileConverterParams<T> = {
420
+ client?: RedirectClient;
421
+ redirectEntryObject: (redirect: RedirectDefinition) => T;
422
+ wildcardConverter?: (sourceTarget: SourceTargetAndWildcards) => SourceAndTarget;
423
+ writeFile: (redirects: T[]) => void;
424
+ };
425
+ declare function ExtractWildcards(url: string): Wildcard[];
426
+ declare function RedirectFileConverter<T>({ client, redirectEntryObject, wildcardConverter, writeFile, }: RedirectFileConverterParams<T>): Promise<void>;
427
+
428
+ /**
429
+ * @typedef {Object} ProcessedUrl
430
+ * @property {string} url - The full url used during processing
431
+ * @property {string} path - The path portion of the URL
432
+ * @property {string} domain - The domain of the URL
433
+ * @property {string} port - The port of the URL
434
+ * @property {string} query - The querystring of the URL
435
+ * @property {string} fragment - The fragment of the URL
436
+ * @property {string} protocol - The protocol of the URL
437
+ */
438
+ type ProcessedUrl = {
439
+ url: string;
440
+ path: string;
441
+ domain: string;
442
+ port: string;
443
+ query: string;
444
+ fragment: string;
445
+ protocol: string;
446
+ };
447
+ /**
448
+ * Breaks a url into the separate parts for processing
449
+ * @returns {ProcessedUrl} The url broken down into independent components
450
+ */
451
+ declare function processUrl(url: string): ProcessedUrl;
452
+
453
+ export { DirectionAwareRedirectDefinition, ExtractWildcards, PathTrie, PathTrieData, ProcessedUrl, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn, processUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "19.35.2",
3
+ "version": "19.35.3-alpha.82+4bc341093",
4
4
  "description": "Uniform redirect client",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -32,12 +32,12 @@
32
32
  "/dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@uniformdev/context": "19.35.2",
35
+ "@uniformdev/context": "19.35.3-alpha.82+4bc341093",
36
36
  "p-limit": "^3.1.0",
37
37
  "rfdc": "^1.3.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "64d3270175087c87cfaa29a283aa4a7b0a98fd2c"
42
+ "gitHead": "4bc341093bc946900df2646fe53eca4bcddc693c"
43
43
  }