libshv-js 3.22.2 → 3.23.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/utils.d.ts +2 -0
- package/dist/utils.js +10 -0
- package/dist/vue-shv.d.ts +7 -6
- package/dist/vue-shv.js +27 -16
- package/dist/ws-client.d.ts +3 -2
- package/dist/ws-client.js +5 -2
- package/package.json +2 -1
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveString = void 0;
|
|
4
|
+
const resolveString = (input) => {
|
|
5
|
+
if (typeof input === 'function') {
|
|
6
|
+
input = input();
|
|
7
|
+
}
|
|
8
|
+
return input;
|
|
9
|
+
};
|
|
10
|
+
exports.resolveString = resolveString;
|
package/dist/vue-shv.d.ts
CHANGED
|
@@ -4,15 +4,16 @@ import PKCE from 'js-pkce';
|
|
|
4
4
|
import * as z from './zod';
|
|
5
5
|
import { type shvMapType } from './rpcvalue';
|
|
6
6
|
import { RpcValue } from './rpcvalue';
|
|
7
|
+
import { StringGetter } from './utils';
|
|
7
8
|
type GlobalResourceOptions<ResourceType> = {
|
|
8
|
-
shvPath:
|
|
9
|
+
shvPath: StringGetter;
|
|
9
10
|
method: string;
|
|
10
11
|
validator: z.ZodType<ResourceType>;
|
|
11
12
|
signalName: string;
|
|
12
13
|
signalHandler: (param: RpcValue, resource: Ref<ResourceType | undefined>, reinit: () => void) => void;
|
|
13
14
|
};
|
|
14
15
|
type VueShvOptions = {
|
|
15
|
-
wsUri:
|
|
16
|
+
wsUri: StringGetter;
|
|
16
17
|
onRequest: WsClientOptionsLogin['onRequest'];
|
|
17
18
|
azureCodeRedirect?: string;
|
|
18
19
|
mountPoint?: string;
|
|
@@ -63,7 +64,7 @@ declare const makePkce: (oauthOptions: {
|
|
|
63
64
|
}) => PKCE;
|
|
64
65
|
export { makePkce as azure };
|
|
65
66
|
export declare function useShv(options: VueShvOptions): {
|
|
66
|
-
azureAuth: (redirectTo: string) => void
|
|
67
|
+
azureAuth: (redirectTo: string) => Promise<void>;
|
|
67
68
|
azureHandlerError: Ref<string, string>;
|
|
68
69
|
connected: Ref<"connected" | "connecting" | "disconnected", "connected" | "connecting" | "disconnected">;
|
|
69
70
|
displayEmail: Ref<string, string>;
|
|
@@ -81,9 +82,9 @@ export declare function useShv(options: VueShvOptions): {
|
|
|
81
82
|
default: ResourceType;
|
|
82
83
|
}): () => ComputedRef<ResourceType>;
|
|
83
84
|
};
|
|
84
|
-
makeRpcCall: <ResultType>(shvPath:
|
|
85
|
-
makeRpcCallParam: <ResultType, ParamType extends RpcValue>(shvPath:
|
|
86
|
-
rpcCall: (shvPath:
|
|
85
|
+
makeRpcCall: <ResultType>(shvPath: StringGetter, method: string, validator: z.ZodType<ResultType>) => () => Promise<Error | ResultType>;
|
|
86
|
+
makeRpcCallParam: <ResultType, ParamType extends RpcValue>(shvPath: StringGetter, method: string, _paramType: z.ZodType<ParamType>, validator: z.ZodType<ResultType>) => (param: ParamType) => Promise<Error | ResultType>;
|
|
87
|
+
rpcCall: (shvPath: StringGetter, method: string, params?: RpcValue) => Promise<Error | RpcValue>;
|
|
87
88
|
setShvCredentials: (userName: string, password: string) => void;
|
|
88
89
|
shvLocalStorage: import("@vueuse/shared").RemovableRef<ShvLocalStorage>;
|
|
89
90
|
shvLogout: () => void;
|
package/dist/vue-shv.js
CHANGED
|
@@ -43,6 +43,7 @@ const ws_client_1 = require("./ws-client");
|
|
|
43
43
|
const core_1 = require("@vueuse/core");
|
|
44
44
|
const js_pkce_1 = __importDefault(require("js-pkce"));
|
|
45
45
|
const z = __importStar(require("./zod"));
|
|
46
|
+
const utils_1 = require("./utils");
|
|
46
47
|
const OAuth2AzureWorkflowZod = z.map({
|
|
47
48
|
type: z.literal('oauth2-azure'),
|
|
48
49
|
authorizeUrl: z.string(),
|
|
@@ -133,7 +134,7 @@ function useShv(options) {
|
|
|
133
134
|
logContents.value = logContents.value + args.join(' ') + '\n';
|
|
134
135
|
console.debug(...args);
|
|
135
136
|
};
|
|
136
|
-
const azureAuth = (redirectTo) => {
|
|
137
|
+
const azureAuth = async (redirectTo) => {
|
|
137
138
|
if (options.azureCodeRedirect === undefined) {
|
|
138
139
|
throw new Error('Azure redirect URL not set');
|
|
139
140
|
}
|
|
@@ -147,7 +148,7 @@ function useShv(options) {
|
|
|
147
148
|
};
|
|
148
149
|
state.ws = new ws_client_1.WsClient({
|
|
149
150
|
logDebug: debug,
|
|
150
|
-
wsUri: options.wsUri,
|
|
151
|
+
wsUri: await (0, utils_1.resolveString)(options.wsUri),
|
|
151
152
|
onWorkflows(workflows) {
|
|
152
153
|
if (!Array.isArray(workflows)) {
|
|
153
154
|
noBrokerSupport();
|
|
@@ -174,10 +175,10 @@ function useShv(options) {
|
|
|
174
175
|
};
|
|
175
176
|
const rpcCall = async (shvPath, method, params) => {
|
|
176
177
|
const shv = await getConnection();
|
|
177
|
-
return shv.callRpcMethod(shvPath, method, params);
|
|
178
|
+
return shv.callRpcMethod(await (0, utils_1.resolveString)(shvPath), method, params);
|
|
178
179
|
};
|
|
179
180
|
const makeRpcCall = (shvPath, method, validator) => async () => {
|
|
180
|
-
const resultOrError = await rpcCall(shvPath, method);
|
|
181
|
+
const resultOrError = await rpcCall(await (0, utils_1.resolveString)(shvPath), method);
|
|
181
182
|
if (resultOrError instanceof Error) {
|
|
182
183
|
return resultOrError;
|
|
183
184
|
}
|
|
@@ -188,7 +189,7 @@ function useShv(options) {
|
|
|
188
189
|
return parsed.data;
|
|
189
190
|
};
|
|
190
191
|
const makeRpcCallParam = (shvPath, method, _paramType, validator) => async (param) => {
|
|
191
|
-
const resultOrError = await rpcCall(shvPath, method, param);
|
|
192
|
+
const resultOrError = await rpcCall(await (0, utils_1.resolveString)(shvPath), method, param);
|
|
192
193
|
if (resultOrError instanceof Error) {
|
|
193
194
|
return resultOrError;
|
|
194
195
|
}
|
|
@@ -226,8 +227,9 @@ function useShv(options) {
|
|
|
226
227
|
return;
|
|
227
228
|
}
|
|
228
229
|
connected.value = 'connecting';
|
|
229
|
-
const doConnect = (user, password, loginType) => {
|
|
230
|
-
|
|
230
|
+
const doConnect = async (user, password, loginType) => {
|
|
231
|
+
const wsUri = await (0, utils_1.resolveString)(options.wsUri);
|
|
232
|
+
console.log('Connecting to', wsUri);
|
|
231
233
|
const makeLoginOptions = () => {
|
|
232
234
|
switch (loginType) {
|
|
233
235
|
case 'PLAIN':
|
|
@@ -245,7 +247,7 @@ function useShv(options) {
|
|
|
245
247
|
};
|
|
246
248
|
state.ws = new ws_client_1.WsClient({
|
|
247
249
|
login: makeLoginOptions(),
|
|
248
|
-
wsUri
|
|
250
|
+
wsUri,
|
|
249
251
|
timeout: 120_000,
|
|
250
252
|
mountPoint: options.mountPoint,
|
|
251
253
|
logDebug: debug,
|
|
@@ -254,11 +256,11 @@ function useShv(options) {
|
|
|
254
256
|
waiter.resolve(state.ws);
|
|
255
257
|
}
|
|
256
258
|
waitingForSocket.length = 0;
|
|
257
|
-
console.log('Connected to',
|
|
259
|
+
console.log('Connected to', wsUri);
|
|
258
260
|
connected.value = 'connected';
|
|
259
261
|
},
|
|
260
262
|
onConnectionFailure(error) {
|
|
261
|
-
console.error(`Failed to connect to: ${
|
|
263
|
+
console.error(`Failed to connect to: ${wsUri}`, error);
|
|
262
264
|
shvLogout();
|
|
263
265
|
loginFailure.value = {
|
|
264
266
|
reason: LoginFailureReason.CouldntLogin,
|
|
@@ -269,7 +271,7 @@ function useShv(options) {
|
|
|
269
271
|
connected.value = 'disconnected';
|
|
270
272
|
const RECONNECT_INTERVAL = 3000;
|
|
271
273
|
if (shvLocalStorage.value.azureAccessToken !== undefined) {
|
|
272
|
-
console.log('Disconnected from',
|
|
274
|
+
console.log('Disconnected from', wsUri, 'reconnecting in', RECONNECT_INTERVAL, 'ms');
|
|
273
275
|
state.reconnectService = globalThis.setTimeout(async () => {
|
|
274
276
|
await getConnection();
|
|
275
277
|
}, RECONNECT_INTERVAL);
|
|
@@ -284,7 +286,10 @@ function useShv(options) {
|
|
|
284
286
|
displayName.value = shvUser;
|
|
285
287
|
displayShortName.value = shvUser[0];
|
|
286
288
|
displayFullName.value = shvUser;
|
|
287
|
-
doConnect(shvUser, shvPassword, 'PLAIN')
|
|
289
|
+
doConnect(shvUser, shvPassword, 'PLAIN')
|
|
290
|
+
.catch((error) => {
|
|
291
|
+
console.error('Unexpected failure in doConnect:', error);
|
|
292
|
+
});
|
|
288
293
|
return;
|
|
289
294
|
}
|
|
290
295
|
azureAvailable().then(isAzureAvailable => {
|
|
@@ -301,7 +306,10 @@ function useShv(options) {
|
|
|
301
306
|
}
|
|
302
307
|
const accessToken = shvLocalStorage.value.azureAccessToken;
|
|
303
308
|
if (accessToken !== undefined) {
|
|
304
|
-
doConnect('', accessToken, 'TOKEN')
|
|
309
|
+
doConnect('', accessToken, 'TOKEN')
|
|
310
|
+
.catch((error) => {
|
|
311
|
+
console.error('Unexpected failure in doConnect:', error);
|
|
312
|
+
});
|
|
305
313
|
}
|
|
306
314
|
}).catch((error) => {
|
|
307
315
|
console.error('Failed to fetch verify azure info, redirecting to the login page in 3 seconds', error);
|
|
@@ -316,7 +324,6 @@ function useShv(options) {
|
|
|
316
324
|
};
|
|
317
325
|
function makeGlobalResource(options) {
|
|
318
326
|
const resource = (0, vue_1.ref)();
|
|
319
|
-
const resIdentifier = `${options.shvPath}:${options.method}`;
|
|
320
327
|
const resourceCall = makeRpcCall(options.shvPath, options.method, options.validator);
|
|
321
328
|
const refreshValue = async () => {
|
|
322
329
|
const newResource = await resourceCall();
|
|
@@ -326,10 +333,12 @@ function useShv(options) {
|
|
|
326
333
|
resource.value = newResource;
|
|
327
334
|
};
|
|
328
335
|
const initialize = async () => {
|
|
336
|
+
const shvPath = await (0, utils_1.resolveString)(options.shvPath);
|
|
337
|
+
const resIdentifier = `${shvPath}:${options.method}`;
|
|
329
338
|
try {
|
|
330
339
|
await refreshValue();
|
|
331
340
|
const connection = await getConnection();
|
|
332
|
-
connection.subscribe(`Global-${resIdentifier}:`,
|
|
341
|
+
await connection.subscribe(`Global-${resIdentifier}:`, shvPath, options.signalName, (_path, _method, param) => {
|
|
333
342
|
options.signalHandler(param, resource, async () => refreshValue().catch((error) => {
|
|
334
343
|
console.error(`Failed to initialize ${resIdentifier}`, error);
|
|
335
344
|
}));
|
|
@@ -343,10 +352,12 @@ function useShv(options) {
|
|
|
343
352
|
return () => {
|
|
344
353
|
if (!initialized) {
|
|
345
354
|
initialized = true;
|
|
346
|
-
(0, vue_1.watchEffect)(() => {
|
|
355
|
+
(0, vue_1.watchEffect)(async () => {
|
|
347
356
|
if (connected.value !== 'connected') {
|
|
348
357
|
return;
|
|
349
358
|
}
|
|
359
|
+
const shvPath = await (0, utils_1.resolveString)(options.shvPath);
|
|
360
|
+
const resIdentifier = `${shvPath}:${options.method}`;
|
|
350
361
|
initialize().catch((error) => {
|
|
351
362
|
console.error(`Failed to initialize ${resIdentifier}`, error);
|
|
352
363
|
});
|
package/dist/ws-client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type RpcMessage, type ErrorMap } from './rpcmessage';
|
|
2
2
|
import { type RpcValue, type Null, type Int, type IMap, type ShvMap } from './rpcvalue';
|
|
3
|
+
import { StringGetter } from './utils';
|
|
3
4
|
import * as z from './zod';
|
|
4
5
|
type SubscriptionCallback = (path: string, method: string, param?: RpcValue) => void;
|
|
5
6
|
type ResultOrError<T = RpcValue> = T | Error;
|
|
@@ -220,8 +221,8 @@ declare class WsClient {
|
|
|
220
221
|
callRpcMethod(shvPath: string | undefined, method: 'ls', params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError<LsResult>>;
|
|
221
222
|
callRpcMethod(shvPath: string | undefined, method: string, params?: RpcValue, delayCallback?: (progress: number) => void): RpcRequestPromise<ResultOrError>;
|
|
222
223
|
sendRpcMessage(rpcMsg: RpcMessage): void;
|
|
223
|
-
subscribe(subscriber: string,
|
|
224
|
-
unsubscribe(subscriber: string,
|
|
224
|
+
subscribe(subscriber: string, pathGetter: StringGetter, method: string, callback: SubscriptionCallback): Promise<void>;
|
|
225
|
+
unsubscribe(subscriber: string, pathGetter: StringGetter, method: string): Promise<void>;
|
|
225
226
|
sendPing(): void;
|
|
226
227
|
accessGrantForMethodCall(path: string, method: string): RpcRequestPromise<ResultOrError<string>>;
|
|
227
228
|
close(): void;
|
package/dist/ws-client.js
CHANGED
|
@@ -39,6 +39,7 @@ const chainpack_1 = require("./chainpack");
|
|
|
39
39
|
const cpon_1 = require("./cpon");
|
|
40
40
|
const rpcmessage_1 = require("./rpcmessage");
|
|
41
41
|
const rpcvalue_1 = require("./rpcvalue");
|
|
42
|
+
const utils_1 = require("./utils");
|
|
42
43
|
const z = __importStar(require("./zod"));
|
|
43
44
|
const DEFAULT_TIMEOUT = 5000;
|
|
44
45
|
const DEFAULT_PING_INTERVAL = 30 * 1000;
|
|
@@ -445,11 +446,12 @@ class WsClient {
|
|
|
445
446
|
this.websocket.send(dgram.buffer);
|
|
446
447
|
}
|
|
447
448
|
}
|
|
448
|
-
subscribe(subscriber,
|
|
449
|
+
async subscribe(subscriber, pathGetter, method, callback) {
|
|
449
450
|
if (this.subscriptions.some(val => val.subscriber === subscriber && val.path === path && val.method === method)) {
|
|
450
451
|
this.logDebug(`Already subscribed {$path}:${method} for subscriber ${subscriber}`);
|
|
451
452
|
return;
|
|
452
453
|
}
|
|
454
|
+
const path = await (0, utils_1.resolveString)(pathGetter);
|
|
453
455
|
// If this path:method has not been subscribed on the broker, do it now
|
|
454
456
|
if (!this.subscriptions.some(val => val.path === path && val.method === method)) {
|
|
455
457
|
this.callRpcMethod('.broker/app', 'subscribe', (0, rpcvalue_1.makeMap)({
|
|
@@ -465,7 +467,8 @@ class WsClient {
|
|
|
465
467
|
callback,
|
|
466
468
|
});
|
|
467
469
|
}
|
|
468
|
-
unsubscribe(subscriber,
|
|
470
|
+
async unsubscribe(subscriber, pathGetter, method) {
|
|
471
|
+
const path = await (0, utils_1.resolveString)(pathGetter);
|
|
469
472
|
const idx = this.subscriptions.findIndex(val => val.subscriber === subscriber && val.path === path && val.method === method);
|
|
470
473
|
if (idx === -1) {
|
|
471
474
|
this.logDebug(`No such subscription ${path}:${method} for subscriber ${subscriber}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "libshv-js",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0",
|
|
4
4
|
"description": "Typescript implementation of libshv",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"./json": "./dist/json.js",
|
|
34
34
|
"./rpcmessage": "./dist/rpcmessage.js",
|
|
35
35
|
"./rpcvalue": "./dist/rpcvalue.js",
|
|
36
|
+
"./utils": "./dist/utils.js",
|
|
36
37
|
"./vue-shv": "./dist/vue-shv.js",
|
|
37
38
|
"./ws-client": "./dist/ws-client.js",
|
|
38
39
|
"./zod": "./dist/zod.js"
|