@cellaware/utils 4.0.1 → 4.1.0
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,4 +1,6 @@
|
|
|
1
1
|
import { Readable } from "stream";
|
|
2
|
+
export declare const AZURE_HEADER_FUNCTION_KEY = "x-functions-key";
|
|
3
|
+
export declare const AZURE_HEADER_PRINCIPAL = "x-ms-client-principal";
|
|
2
4
|
export declare function functionFetchJson(url: string, method: string, key: string, principal: string, body?: any): Promise<any>;
|
|
3
5
|
export declare function functionFetchText(url: string, method: string, key: string, principal: string, text: string): Promise<any>;
|
|
4
6
|
export declare function functionStreamJson(url: string, method: string, key: string, principal: string, body: any, errorBody: any): Promise<{
|
package/dist/azure/function.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Readable } from "stream";
|
|
2
2
|
import { sleep } from "../util.js";
|
|
3
|
+
export const AZURE_HEADER_FUNCTION_KEY = 'x-functions-key';
|
|
4
|
+
export const AZURE_HEADER_PRINCIPAL = 'x-ms-client-principal';
|
|
3
5
|
const STATUS_INTERNAL_SERVER_ERROR = 500;
|
|
4
6
|
const STATUS_SERVICE_UNAVAILABLE = 503;
|
|
5
7
|
const RETRY_SLEEP_MS = 3000;
|
package/dist/chatwms/user.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HttpRequest } from "@azure/functions";
|
|
1
2
|
export interface ChatWMSUserData {
|
|
2
3
|
userId: string;
|
|
3
4
|
userDetails: string;
|
|
@@ -5,6 +6,6 @@ export interface ChatWMSUserData {
|
|
|
5
6
|
}
|
|
6
7
|
export declare function chatwmsInitUserData(): ChatWMSUserData;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* NOTE: will throw error if empty principal or decode issue
|
|
9
10
|
*/
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function chatwmsExtractUserDataFromHeaders(request: HttpRequest): ChatWMSUserData;
|
package/dist/chatwms/user.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AZURE_HEADER_PRINCIPAL } from "../azure/function.js";
|
|
1
2
|
export function chatwmsInitUserData() {
|
|
2
3
|
return {
|
|
3
4
|
userId: '',
|
|
@@ -6,20 +7,21 @@ export function chatwmsInitUserData() {
|
|
|
6
7
|
};
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* NOTE: will throw error if empty principal or decode issue
|
|
10
11
|
*/
|
|
11
|
-
export function
|
|
12
|
+
export function chatwmsExtractUserDataFromHeaders(request) {
|
|
13
|
+
// https://learn.microsoft.com/en-us/azure/static-web-apps/user-information
|
|
14
|
+
const principal = request.headers.get(AZURE_HEADER_PRINCIPAL) ?? '';
|
|
12
15
|
if (principal !== '') {
|
|
13
16
|
try {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return decodedPrincipalObj;
|
|
17
|
+
const userData = JSON.parse(Buffer.from(principal, 'base64').toString('utf8'));
|
|
18
|
+
return userData;
|
|
17
19
|
}
|
|
18
20
|
catch (err) {
|
|
19
|
-
|
|
21
|
+
throw new Error(`Error decoding principal`);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
else {
|
|
23
|
-
|
|
25
|
+
throw new Error(`Principal is not present in request`);
|
|
24
26
|
}
|
|
25
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cellaware/utils",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Cellaware Utilities for Node.js",
|
|
5
5
|
"author": "Cellaware Technologies",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"homepage": "https://cellaware.com",
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@azure/cosmos": "^3.17.0",
|
|
20
|
+
"@azure/functions": "^4.5.1",
|
|
20
21
|
"@azure/storage-blob": "^12.16.0",
|
|
21
22
|
"langchain": "^0.0.170",
|
|
22
23
|
"dotenv": "^16.3.1"
|