@rg-dev/stdlib 1.0.32 → 1.0.33

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.
@@ -24,6 +24,7 @@ __export(common_env_exports, {
24
24
  catchInline: () => catchInline,
25
25
  doSafe: () => doSafe,
26
26
  fetchHelperJSON: () => fetchHelperJSON,
27
+ fetchHelperPostJSON: () => fetchHelperPostJSON,
27
28
  fetchHelperText: () => fetchHelperText,
28
29
  isNonEmptyString: () => isNonEmptyString,
29
30
  isNumber: () => isNumber,
@@ -98,6 +99,18 @@ async function fetchHelperJSON(url, config) {
98
99
  throwIfNotJSONResponse(res);
99
100
  return await res.json();
100
101
  }
102
+ async function fetchHelperPostJSON(url, body, config) {
103
+ config = config || {};
104
+ config.method = "POST";
105
+ config.body = typeof body == "string" ? body : JSON.stringify(body);
106
+ config.headers["Content-Type"] = "application/json";
107
+ const res = await fetch(url, config);
108
+ if (!res.ok) {
109
+ const text = await res.text();
110
+ throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
111
+ }
112
+ return res;
113
+ }
101
114
  async function fetchHelperText(url, config) {
102
115
  const res = await fetch(url, config);
103
116
  if (!res.ok) {
@@ -42,6 +42,7 @@ declare class StringBuilder implements IStringBuilder {
42
42
  }
43
43
 
44
44
  declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
45
+ declare function fetchHelperPostJSON(url: string, body: any, config?: RequestInit): Promise<Response>;
45
46
  declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
46
47
 
47
48
  type MyFn<T extends Record<string, (...args: any[]) => any>> = {
@@ -73,4 +74,4 @@ declare function isRunningOnServer(): boolean;
73
74
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
74
75
  declare function isNonEmptyString(str?: string): boolean;
75
76
 
76
- export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
77
+ export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
@@ -42,6 +42,7 @@ declare class StringBuilder implements IStringBuilder {
42
42
  }
43
43
 
44
44
  declare function fetchHelperJSON<T extends Record<string, any>>(url: string, config?: RequestInit): Promise<T>;
45
+ declare function fetchHelperPostJSON(url: string, body: any, config?: RequestInit): Promise<Response>;
45
46
  declare function fetchHelperText(url: string, config?: RequestInit): Promise<string>;
46
47
 
47
48
  type MyFn<T extends Record<string, (...args: any[]) => any>> = {
@@ -73,4 +74,4 @@ declare function isRunningOnServer(): boolean;
73
74
  declare function useServer(fn: () => (Promise<any> | void), onError?: (err: Error) => void): Promise<any>;
74
75
  declare function isNonEmptyString(str?: string): boolean;
75
76
 
76
- export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
77
+ export { type AsyncReturnType, type MaybeFunction, type MyFn, Optional, StringBuilder, catchInline, doSafe, fetchHelperJSON, fetchHelperPostJSON, fetchHelperText, isNonEmptyString, isNumber, isRunningOnServer, promiseRetry, promiseWithTimeout, sleep, useServer };
package/lib/common-env.js CHANGED
@@ -61,6 +61,18 @@ async function fetchHelperJSON(url, config) {
61
61
  throwIfNotJSONResponse(res);
62
62
  return await res.json();
63
63
  }
64
+ async function fetchHelperPostJSON(url, body, config) {
65
+ config = config || {};
66
+ config.method = "POST";
67
+ config.body = typeof body == "string" ? body : JSON.stringify(body);
68
+ config.headers["Content-Type"] = "application/json";
69
+ const res = await fetch(url, config);
70
+ if (!res.ok) {
71
+ const text = await res.text();
72
+ throw new Error(`Error ${text || "No content"} Status: ${res.status} Request URL: ${url}`);
73
+ }
74
+ return res;
75
+ }
64
76
  async function fetchHelperText(url, config) {
65
77
  const res = await fetch(url, config);
66
78
  if (!res.ok) {
@@ -188,6 +200,7 @@ export {
188
200
  catchInline,
189
201
  doSafe,
190
202
  fetchHelperJSON,
203
+ fetchHelperPostJSON,
191
204
  fetchHelperText,
192
205
  isNonEmptyString,
193
206
  isNumber,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rg-dev/stdlib",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",