@magda/utils 3.0.2-alpha.1 → 3.0.3

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/README.md +77 -38
  2. package/package.json +2 -2
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
- ): any;
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 function forEachAsync<T>(
50
- page: AsyncPage<T[]>,
51
- maxConcurrency: number,
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
- export declare function formatServiceError(
56
- baseMessage: string,
57
- e: any,
58
- retriesLeft: number
59
- ): string;
55
+ declare interface CreateAsyncPage<T> {
56
+ (): Promise<AsyncPage<T>>;
57
+ }
60
58
 
61
- export declare function getMinikubeIP(): string;
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
- export declare const isUuid: (id: any) => boolean;
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
- // deprecated. Please use fetchRequest instead
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 getDefaultRequestInitOptions(): RequestInit;
87
- export declare function setDefaultRequestInitOptions(
88
- options: RequestInit
89
- ): void;
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 getRequest<T = any, CT = string>(
92
- url: string,
93
- noCache?: boolean,
94
- extraFetchOptions?: RequestInit
95
- ): Promise<T>;
115
+ export declare function formatServiceError(
116
+ baseMessage: string,
117
+ e: any,
118
+ retriesLeft: number
119
+ ): string;
96
120
 
97
- export declare function getRequestNoCache<T = any, CT = string>(
98
- url: string,
99
- extraFetchOptions?: RequestInit
100
- ): Promise<T>;
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/utils",
3
3
  "description": "MAGDA Common Utils",
4
- "version": "3.0.2-alpha.1",
4
+ "version": "3.0.3",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -26,7 +26,7 @@
26
26
  "module": "dist/index.js",
27
27
  "browser": "dist/index-web.js",
28
28
  "devDependencies": {
29
- "@magda/typescript-common": "^3.0.2-alpha.1",
29
+ "@magda/typescript-common": "^3.0.3",
30
30
  "@microsoft/api-extractor": "~7.39.0",
31
31
  "esbuild": "^0.19.10",
32
32
  "ts-loader": "^9.5.1",