@hautechai/sdk 0.0.21 → 0.0.22
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/sdk/api.d.ts +0 -5
- package/dist/sdk/api.js +0 -23
- package/dist/sdk/index.d.ts +0 -8
- package/dist/sdk/operations/index.d.ts +0 -8
- package/dist/sdk/operations/index.js +0 -12
- package/package.json +2 -3
- package/dist/sdk/operations/updater.d.ts +0 -11
- package/dist/sdk/operations/updater.js +0 -23
package/dist/sdk/api.d.ts
CHANGED
|
@@ -16,8 +16,3 @@ export declare const useAutogeneratedAPI: <T extends BaseAPI>(baseProps: {
|
|
|
16
16
|
transform?: (response: ResponseEntity) => ReturnType_1;
|
|
17
17
|
}) => Promise<ReturnType_1 | undefined>;
|
|
18
18
|
};
|
|
19
|
-
export declare const createWebsocket: (props: {
|
|
20
|
-
callback: (data: any) => void;
|
|
21
|
-
options: SDKOptions;
|
|
22
|
-
topic: string;
|
|
23
|
-
}) => Promise<void>;
|
package/dist/sdk/api.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { WebsocketApi } from '../autogenerated';
|
|
2
|
-
import Pusher from 'pusher-js';
|
|
3
1
|
const getBaseUrl = (options) => options.endpoint ?? 'https://api.hautech.ai';
|
|
4
2
|
export const useAutogeneratedAPI = (baseProps) => {
|
|
5
3
|
const getAPI = async () => {
|
|
@@ -32,24 +30,3 @@ export const useAutogeneratedAPI = (baseProps) => {
|
|
|
32
30
|
callWithReturningUndefinedOn404,
|
|
33
31
|
};
|
|
34
32
|
};
|
|
35
|
-
export const createWebsocket = async (props) => {
|
|
36
|
-
const api = useAutogeneratedAPI({ API: WebsocketApi, options: props.options });
|
|
37
|
-
const baseUrl = getBaseUrl(props.options);
|
|
38
|
-
const pusherSettings = (await api.call({ run: (api) => api.websocketControllerGetSettingsV1() }));
|
|
39
|
-
const pusher = new Pusher(pusherSettings.key, {
|
|
40
|
-
channelAuthorization: {
|
|
41
|
-
endpoint: `${baseUrl}/v1/websocket/auth`,
|
|
42
|
-
headers: {
|
|
43
|
-
'Access-Control-Allow-Origin': '*',
|
|
44
|
-
Authorization: `Bearer ${await props.options.authToken()}`,
|
|
45
|
-
},
|
|
46
|
-
transport: 'ajax',
|
|
47
|
-
},
|
|
48
|
-
cluster: pusherSettings.cluster,
|
|
49
|
-
forceTLS: true,
|
|
50
|
-
});
|
|
51
|
-
const channel = pusher.subscribe(`private-user-${pusherSettings.userId?.replace('|', '_')}`);
|
|
52
|
-
channel.bind('pusher:subscription_succeeded', () => console.log(`Subscribed to ${props.topic} updates`));
|
|
53
|
-
channel.bind('pusher:subscription_error', (data) => console.error(data));
|
|
54
|
-
channel.bind(props.topic, (data) => props.callback(data));
|
|
55
|
-
};
|
package/dist/sdk/index.d.ts
CHANGED
|
@@ -191,14 +191,6 @@ export declare const createSDK: (options: SDKOptions) => {
|
|
|
191
191
|
id: string;
|
|
192
192
|
metadata?: any;
|
|
193
193
|
}) => Promise<void>;
|
|
194
|
-
updates: {
|
|
195
|
-
subscribe: (props: {
|
|
196
|
-
callback: (operation: import("../types").OperationEntity) => void;
|
|
197
|
-
}) => void;
|
|
198
|
-
unsubscribe: (props: {
|
|
199
|
-
callback: (operation: import("../types").OperationEntity) => void;
|
|
200
|
-
}) => void;
|
|
201
|
-
};
|
|
202
194
|
wait: (props: {
|
|
203
195
|
id: string;
|
|
204
196
|
timeoutInSeconds?: number;
|
|
@@ -100,14 +100,6 @@ declare const operations: (options: SDKOptions) => {
|
|
|
100
100
|
id: string;
|
|
101
101
|
metadata?: any;
|
|
102
102
|
}) => Promise<void>;
|
|
103
|
-
updates: {
|
|
104
|
-
subscribe: (props: {
|
|
105
|
-
callback: (operation: OperationEntity) => void;
|
|
106
|
-
}) => void;
|
|
107
|
-
unsubscribe: (props: {
|
|
108
|
-
callback: (operation: OperationEntity) => void;
|
|
109
|
-
}) => void;
|
|
110
|
-
};
|
|
111
103
|
wait: (props: {
|
|
112
104
|
id: string;
|
|
113
105
|
timeoutInSeconds?: number;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import createOperationUpdater from './updater';
|
|
2
1
|
import { OperationsApi, } from '../../autogenerated';
|
|
3
2
|
import { useAutogeneratedAPI } from '../api';
|
|
4
3
|
import { transformToListResponse } from '../transformers';
|
|
5
4
|
const operations = (options) => {
|
|
6
5
|
const api = useAutogeneratedAPI({ API: OperationsApi, options });
|
|
7
|
-
const updates = createOperationUpdater(options);
|
|
8
6
|
const createOperation = (callMethod) => (props) => api.call({ run: (methods) => callMethod(methods, props) });
|
|
9
7
|
return {
|
|
10
8
|
create: {
|
|
@@ -69,18 +67,9 @@ const operations = (options) => {
|
|
|
69
67
|
updateMetadata: async (props) => api.call({
|
|
70
68
|
run: (methods) => methods.operationsControllerUpdateMetadataV1(props.id, { overwrite: props.metadata }),
|
|
71
69
|
}),
|
|
72
|
-
updates,
|
|
73
70
|
wait: async (props) => new Promise((resolve, reject) => {
|
|
74
71
|
const initialDelay = 5000;
|
|
75
72
|
const delay = 2000;
|
|
76
|
-
const listenToOperation = (operation) => {
|
|
77
|
-
if (operation.id === props.id) {
|
|
78
|
-
clearTimeout(timeoutId);
|
|
79
|
-
resolve(operation);
|
|
80
|
-
updates.unsubscribe({ callback: listenToOperation });
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
updates.subscribe({ callback: listenToOperation });
|
|
84
73
|
let timeoutId;
|
|
85
74
|
const poll = async () => {
|
|
86
75
|
const operation = await api.call({
|
|
@@ -89,7 +78,6 @@ const operations = (options) => {
|
|
|
89
78
|
if (operation.status !== 'pending')
|
|
90
79
|
return resolve(operation);
|
|
91
80
|
timeoutId = setTimeout(poll, delay);
|
|
92
|
-
updates.unsubscribe({ callback: listenToOperation });
|
|
93
81
|
};
|
|
94
82
|
timeoutId = setTimeout(poll, initialDelay);
|
|
95
83
|
}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hautechai/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@hautechai/pipelines": "0.1.0",
|
|
21
21
|
"axios": "1.6.1",
|
|
22
|
-
"jose": "5.9.6"
|
|
23
|
-
"pusher-js": "8.4.0-rc2"
|
|
22
|
+
"jose": "5.9.6"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@openapitools/openapi-generator-cli": "2.15.3",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SDKOptions } from '../../types';
|
|
2
|
-
import { OperationEntity } from '../../autogenerated';
|
|
3
|
-
declare const createOperationUpdater: (options: SDKOptions) => {
|
|
4
|
-
subscribe: (props: {
|
|
5
|
-
callback: (operation: OperationEntity) => void;
|
|
6
|
-
}) => void;
|
|
7
|
-
unsubscribe: (props: {
|
|
8
|
-
callback: (operation: OperationEntity) => void;
|
|
9
|
-
}) => void;
|
|
10
|
-
};
|
|
11
|
-
export default createOperationUpdater;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createWebsocket } from '../api';
|
|
2
|
-
const createOperationUpdater = (options) => {
|
|
3
|
-
const eventListeners = [];
|
|
4
|
-
const eventListener = (operation) => {
|
|
5
|
-
eventListeners.forEach((listener) => listener(operation));
|
|
6
|
-
};
|
|
7
|
-
let websocketInited = false;
|
|
8
|
-
const initWebsocket = () => {
|
|
9
|
-
createWebsocket({ callback: eventListener, options, topic: 'operation' });
|
|
10
|
-
websocketInited = true;
|
|
11
|
-
};
|
|
12
|
-
return {
|
|
13
|
-
subscribe: (props) => {
|
|
14
|
-
eventListeners.push(props.callback);
|
|
15
|
-
if (!websocketInited)
|
|
16
|
-
initWebsocket();
|
|
17
|
-
},
|
|
18
|
-
unsubscribe: (props) => {
|
|
19
|
-
eventListeners.splice(eventListeners.indexOf(props.callback), 1);
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
export default createOperationUpdater;
|