@cellaware/utils 3.2.13 → 3.2.15
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/azure/function.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
2
|
+
export declare function functionStream(url: string, req: any, errorBody: any): Promise<{
|
|
3
|
+
body: Readable;
|
|
4
|
+
}>;
|
|
1
5
|
export declare function functionFetchJson(url: string, method: string, key: string, body?: any): Promise<any>;
|
|
2
6
|
export declare function functionFetchText(url: string, method: string, key: string, text: string): Promise<any>;
|
|
7
|
+
export declare function functionStreamJson(url: string, method: string, key: string, body: any, errorBody: any): Promise<{
|
|
8
|
+
body: Readable;
|
|
9
|
+
}>;
|
package/dist/azure/function.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
1
2
|
import { sleep } from "../util.js";
|
|
2
3
|
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
|
3
4
|
const STATUS_SERVICE_UNAVAILABLE = 503;
|
|
@@ -26,6 +27,32 @@ async function functionFetch(url, req) {
|
|
|
26
27
|
(status === STATUS_INTERNAL_SERVER_ERROR || status === STATUS_SERVICE_UNAVAILABLE));
|
|
27
28
|
return res;
|
|
28
29
|
}
|
|
30
|
+
export async function functionStream(url, req, errorBody) {
|
|
31
|
+
let stream = new Readable();
|
|
32
|
+
stream._read = () => { };
|
|
33
|
+
fetch(url, req)
|
|
34
|
+
.then(async (res) => {
|
|
35
|
+
const body = res.body;
|
|
36
|
+
if (!!body) {
|
|
37
|
+
const reader = body.getReader();
|
|
38
|
+
let streamDone = false;
|
|
39
|
+
while (!streamDone) {
|
|
40
|
+
const { value, done } = await reader.read();
|
|
41
|
+
streamDone = done;
|
|
42
|
+
if (!!value) {
|
|
43
|
+
const buf = Buffer.from(value);
|
|
44
|
+
stream.push(buf.toString());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
stream.push(null);
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.catch(err => {
|
|
51
|
+
stream.push(JSON.stringify(errorBody));
|
|
52
|
+
stream.push(null);
|
|
53
|
+
});
|
|
54
|
+
return { body: stream };
|
|
55
|
+
}
|
|
29
56
|
export async function functionFetchJson(url, method, key, body) {
|
|
30
57
|
const headers = {
|
|
31
58
|
'Content-Type': 'application/json',
|
|
@@ -54,3 +81,18 @@ export async function functionFetchText(url, method, key, text) {
|
|
|
54
81
|
};
|
|
55
82
|
return functionFetch(url, req);
|
|
56
83
|
}
|
|
84
|
+
export async function functionStreamJson(url, method, key, body, errorBody) {
|
|
85
|
+
const headers = {
|
|
86
|
+
'Content-Type': 'application/octet-stream',
|
|
87
|
+
'Transfer-Encoding': 'chunked',
|
|
88
|
+
'x-functions-key': key
|
|
89
|
+
};
|
|
90
|
+
let req = {
|
|
91
|
+
method,
|
|
92
|
+
headers
|
|
93
|
+
};
|
|
94
|
+
if (body != null) {
|
|
95
|
+
req.body = JSON.stringify(body);
|
|
96
|
+
}
|
|
97
|
+
return functionStream(url, req, errorBody);
|
|
98
|
+
}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
export declare function chatwmsFunctionFetch(path: string, method: string, body?: any): Promise<any>;
|
|
2
2
|
export declare function chatwmsFunctionQuery(path: string, method: string, query: string): Promise<any>;
|
|
3
|
+
export declare function chatwmsFunctionStream(path: string, method: string, body?: any): Promise<{
|
|
4
|
+
body: import("stream").Readable;
|
|
5
|
+
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { functionFetchJson, functionFetchText } from "../../azure/function.js";
|
|
1
|
+
import { functionFetchJson, functionFetchText, functionStreamJson } from "../../azure/function.js";
|
|
2
2
|
export function chatwmsFunctionFetch(path, method, body) {
|
|
3
3
|
const url = `${process.env['CHATWMS_URL']}/${path}`;
|
|
4
4
|
return functionFetchJson(url, method, process.env['CHATWMS_KEY'] ?? '', body);
|
|
@@ -7,3 +7,11 @@ export function chatwmsFunctionQuery(path, method, query) {
|
|
|
7
7
|
const url = `${process.env['CHATWMS_URL']}/${path}`;
|
|
8
8
|
return functionFetchText(url, method, process.env['CHATWMS_KEY'] ?? '', query);
|
|
9
9
|
}
|
|
10
|
+
export function chatwmsFunctionStream(path, method, body) {
|
|
11
|
+
const url = `${process.env['CHATWMS_URL']}/${path}`;
|
|
12
|
+
const errorBody = {
|
|
13
|
+
answer: 'chatwms-unavailable-error',
|
|
14
|
+
error: 'chatwms-unavailable-error'
|
|
15
|
+
};
|
|
16
|
+
return functionStreamJson(url, method, process.env['CHATWMS_KEY'] ?? '', body, errorBody);
|
|
17
|
+
}
|