@magda/utils 3.0.2-alpha.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -38
- package/dist/index.d.ts +12 -0
- package/dist/index.js +2501 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
This package includes the following common utilities that may help magda miniors / connectors development:
|
|
4
4
|
|
|
5
5
|
```typescript
|
|
6
|
+
/**
|
|
7
|
+
* Checks to see whether the passed argv has a jwtSecret object. If not,
|
|
8
|
+
* tries to add one by looking at the JWT_SECRET env var and failing that,
|
|
9
|
+
* the jwtSecret value in package.json config.
|
|
10
|
+
*
|
|
11
|
+
* If it can't find one and required is true (or unprovided), this will
|
|
12
|
+
* throw an Error.
|
|
13
|
+
*/
|
|
6
14
|
export declare function addJwtSecretFromEnvVar<T>(
|
|
7
15
|
argv: {
|
|
8
16
|
[key in keyof Arguments<T>]: Arguments<T>[key];
|
|
@@ -38,38 +46,53 @@ export declare function buildJwt(
|
|
|
38
46
|
jwtSecret: string,
|
|
39
47
|
userId: string,
|
|
40
48
|
session?: any
|
|
41
|
-
):
|
|
42
|
-
|
|
43
|
-
export declare const coerceJson: (param: string) => (json?: string) => any;
|
|
44
|
-
|
|
45
|
-
export declare function createServiceError(e: any): Error;
|
|
46
|
-
|
|
47
|
-
export declare function encodeURIComponentWithApost(string: string): string;
|
|
49
|
+
): string;
|
|
48
50
|
|
|
49
|
-
export declare
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
callbackFn: (data: T) => Promise<void>
|
|
53
|
-
): Promise<void>;
|
|
51
|
+
export declare const coerceJson: (
|
|
52
|
+
param: string
|
|
53
|
+
) => (json?: string | object | any[]) => any;
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
retriesLeft: number
|
|
59
|
-
): string;
|
|
55
|
+
declare interface CreateAsyncPage<T> {
|
|
56
|
+
(): Promise<AsyncPage<T>>;
|
|
57
|
+
}
|
|
60
58
|
|
|
61
|
-
export declare function
|
|
59
|
+
export declare function createNoCacheFetchOptions(
|
|
60
|
+
fetchOptions?: RequestInit
|
|
61
|
+
): {
|
|
62
|
+
body?: BodyInit;
|
|
63
|
+
cache?: RequestCache;
|
|
64
|
+
credentials?: RequestCredentials;
|
|
65
|
+
headers?: HeadersInit;
|
|
66
|
+
integrity?: string;
|
|
67
|
+
keepalive?: boolean;
|
|
68
|
+
method?: string;
|
|
69
|
+
mode?: RequestMode;
|
|
70
|
+
redirect?: RequestRedirect;
|
|
71
|
+
referrer?: string;
|
|
72
|
+
referrerPolicy?: ReferrerPolicy;
|
|
73
|
+
signal?: AbortSignal;
|
|
74
|
+
window?: null;
|
|
75
|
+
};
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Creates a {@link ServiceError} from the result of a failed call to an API generated
|
|
79
|
+
* by swagger-codegen. The result typically includes `response` (with a status code) and
|
|
80
|
+
* a `body` (the JSON the server returned with the error), but may be other things if,
|
|
81
|
+
* e.g., an exception occurred while attempting to invoke the service.
|
|
82
|
+
*
|
|
83
|
+
* @export
|
|
84
|
+
* @param {*} e The result of the failed call.
|
|
85
|
+
* @returns {Error} An Error created from the failed result.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createServiceError(e: any): Error;
|
|
64
88
|
|
|
65
|
-
|
|
66
|
-
export declare const request: any;
|
|
89
|
+
export declare function encodeURIComponentWithApost(string: string): string;
|
|
67
90
|
|
|
68
91
|
export declare function fetchRequest<T = any, CT = string>(
|
|
69
92
|
method: string,
|
|
70
93
|
url: string,
|
|
71
94
|
body?: any,
|
|
72
|
-
contentType?: CT | RequestContentType | undefined,
|
|
95
|
+
contentType?: CT | RequestContentType | undefined | null,
|
|
73
96
|
returnHeaders?: false,
|
|
74
97
|
extraRequestOptions?: RequestInit
|
|
75
98
|
): Promise<T>;
|
|
@@ -78,28 +101,44 @@ export declare function fetchRequest<T = any, CT = string>(
|
|
|
78
101
|
method: string,
|
|
79
102
|
url: string,
|
|
80
103
|
body?: any,
|
|
81
|
-
contentType?: CT | RequestContentType | undefined,
|
|
104
|
+
contentType?: CT | RequestContentType | undefined | null,
|
|
82
105
|
returnHeaders?: true,
|
|
83
106
|
extraRequestOptions?: RequestInit
|
|
84
107
|
): Promise<[T, Headers]>;
|
|
85
108
|
|
|
86
|
-
export declare function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
export declare function forEachAsync<T>(
|
|
110
|
+
page: AsyncPage<T[]>,
|
|
111
|
+
maxConcurrency: number,
|
|
112
|
+
callbackFn: (data: T) => Promise<void>
|
|
113
|
+
): Promise<void>;
|
|
90
114
|
|
|
91
|
-
export declare function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
):
|
|
115
|
+
export declare function formatServiceError(
|
|
116
|
+
baseMessage: string,
|
|
117
|
+
e: any,
|
|
118
|
+
retriesLeft: number
|
|
119
|
+
): string;
|
|
96
120
|
|
|
97
|
-
export declare function
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
)
|
|
121
|
+
export declare function getMinikubeIP(): string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
|
|
125
|
+
* If the input url is not a pseudo storage api resource URL, return the input url directly
|
|
126
|
+
*
|
|
127
|
+
* @export
|
|
128
|
+
* @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
|
|
129
|
+
* @param {string} storageApiBaseUrl storage api base url
|
|
130
|
+
* @param {string} datasetsBucket datasets storage bucket name
|
|
131
|
+
* @return {*}
|
|
132
|
+
*/
|
|
133
|
+
export declare function getStorageApiResourceAccessUrl(
|
|
134
|
+
resourceUrl: string,
|
|
135
|
+
storageApiBaseUrl: string,
|
|
136
|
+
datasetsBucket: string
|
|
137
|
+
): string;
|
|
138
|
+
|
|
139
|
+
export declare const isUuid: (id: any) => boolean;
|
|
101
140
|
|
|
102
|
-
export declare function retry<T>(
|
|
141
|
+
export declare function retry<T = any>(
|
|
103
142
|
op: () => Promise<T>,
|
|
104
143
|
delaySeconds: number,
|
|
105
144
|
retries: number,
|
|
@@ -125,5 +164,5 @@ export declare class ServiceError extends Error {
|
|
|
125
164
|
constructor(message: string, e: any);
|
|
126
165
|
}
|
|
127
166
|
|
|
128
|
-
export declare function unionToThrowable<T>(input: T | Error): T;
|
|
167
|
+
export declare function unionToThrowable<T>(input: T | Error | ServerError): T;
|
|
129
168
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -115,6 +115,18 @@ export declare function getRequest<T = any, CT = string>(url: string, noCache?:
|
|
|
115
115
|
|
|
116
116
|
export declare function getRequestNoCache<T = any, CT = string>(url: string, extraFetchOptions?: RequestInit): Promise<T>;
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
|
|
120
|
+
* If the input url is not a pseudo storage api resource URL, return the input url directly
|
|
121
|
+
*
|
|
122
|
+
* @export
|
|
123
|
+
* @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
|
|
124
|
+
* @param {string} storageApiBaseUrl storage api base url
|
|
125
|
+
* @param {string} datasetsBucket datasets storage bucket name
|
|
126
|
+
* @return {*}
|
|
127
|
+
*/
|
|
128
|
+
export declare function getStorageApiResourceAccessUrl(resourceUrl: string, storageApiBaseUrl: string, datasetsBucket: string): string;
|
|
129
|
+
|
|
118
130
|
export declare const isUuid: (id: any) => boolean;
|
|
119
131
|
|
|
120
132
|
declare class Maybe<T> implements Monad<T>, Functor<T>, Eq<Maybe<T>> {
|