@streamlayer/sdk-web-api 1.8.14 → 1.9.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/lib/grpc/queries/event.js +2 -2
- package/lib/grpc/queries/organization.d.ts +2 -0
- package/lib/grpc/queries/organization.js +1 -1
- package/lib/grpc/queries/user.d.ts +2 -3
- package/lib/grpc/queries/user.js +2 -2
- package/lib/grpc/subscription.d.ts +16 -9
- package/lib/grpc/transport.d.ts +10 -6
- package/lib/grpc/transport.js +5 -3
- package/lib/utils/grpc-stub.js +3 -3
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Events } from '@streamlayer/sl-eslib/sports/events/
|
|
2
|
-
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/
|
|
1
|
+
import { Events } from '@streamlayer/sl-eslib/sports/events/events_pb';
|
|
2
|
+
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
|
|
3
3
|
export const $retrieveEventId = ($providerStreamId, transport) => {
|
|
4
4
|
const { client, queryKey } = transport.createPromiseClient(Events, {
|
|
5
5
|
method: 'retrieveEventId',
|
|
@@ -3,6 +3,8 @@ import { Transport } from '../transport';
|
|
|
3
3
|
export { $user } from './user';
|
|
4
4
|
export declare const $organizationSettings: ($enabled: ReadableAtom<"on" | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<{
|
|
5
5
|
id: string;
|
|
6
|
+
$typeName?: "streamlayer.sdkSettings.OrganizationSettings" | undefined;
|
|
7
|
+
$unknown?: import("@bufbuild/protobuf").UnknownField[];
|
|
6
8
|
overlays?: import("@streamlayer/sl-eslib/sdkSettings/sdkSettings.common_pb").SdkOverlay[] | undefined;
|
|
7
9
|
buttonIcon?: string | undefined;
|
|
8
10
|
tinodeHost?: string | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/
|
|
1
|
+
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
|
|
2
2
|
export { $user } from './user';
|
|
3
3
|
export const $organizationSettings = ($enabled, transport) => {
|
|
4
4
|
const { client, queryKey } = transport.createPromiseClient(Client, { method: 'getOrganization', params: [$enabled] });
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ReadableAtom } from 'nanostores';
|
|
2
|
-
import type
|
|
3
|
-
import { PlainMessage } from '@bufbuild/protobuf';
|
|
2
|
+
import { type BypassAuthRequest } from '@streamlayer/sl-eslib/users/users_pb';
|
|
4
3
|
import { Transport } from '../transport';
|
|
5
4
|
export declare const $user: ($userToken: ReadableAtom<string | undefined>, transport: Transport) => import("@nanostores/query").FetcherStore<{
|
|
6
5
|
data: import("@streamlayer/sl-eslib/users/users_common_pb").User | undefined;
|
|
7
6
|
}, any>;
|
|
8
|
-
export declare const bypassLogin: (transport: Transport) => ({ userKey, schema, init, inviterKey }:
|
|
7
|
+
export declare const bypassLogin: (transport: Transport) => ({ userKey, schema, init, inviterKey }: Omit<BypassAuthRequest, "$typeName">) => Promise<import("@streamlayer/sl-eslib/users/users_pb").BypassAuthResponse>;
|
|
9
8
|
export declare const bypassAuth: (transport: Transport, params: {
|
|
10
9
|
userKey?: string;
|
|
11
10
|
schema?: string;
|
package/lib/grpc/queries/user.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Users } from '@streamlayer/sl-eslib/users/
|
|
2
|
-
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/
|
|
1
|
+
import { Users } from '@streamlayer/sl-eslib/users/users_pb';
|
|
2
|
+
import { Client } from '@streamlayer/sl-eslib/sdkSettings/client/client_pb';
|
|
3
3
|
// user query
|
|
4
4
|
// cache user
|
|
5
5
|
// invalidate token
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { Client } from '@connectrpc/connect';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import { PreinitializedWritableAtom } from 'nanostores';
|
|
3
|
+
import type { GenService, GenServiceMethods } from '@bufbuild/protobuf/codegenv1';
|
|
4
|
+
import type { DescMethodServerStreaming } from '@bufbuild/protobuf';
|
|
4
5
|
import { Transport } from './transport';
|
|
5
|
-
type
|
|
6
|
-
|
|
6
|
+
type ServiceType = GenService<GenServiceMethods>;
|
|
7
|
+
export type StreamMethodsDesc<T extends ServiceType> = {
|
|
8
|
+
[P in keyof T['method'] as T['method'][P] extends DescMethodServerStreaming ? P : never]: T['method'][P] extends DescMethodServerStreaming ? T['method'][P] : never;
|
|
7
9
|
};
|
|
8
|
-
type
|
|
10
|
+
export type StreamPromiseClient<T extends ServiceType> = {
|
|
11
|
+
[P in keyof T['method'] as T['method'][P] extends DescMethodServerStreaming ? P : never]: T['method'][P] extends DescMethodServerStreaming ? Client<T>[P] : never;
|
|
12
|
+
};
|
|
13
|
+
export type StreamMethods<T extends ServiceType> = {
|
|
9
14
|
[P in keyof StreamPromiseClient<T>]: P;
|
|
10
15
|
};
|
|
11
|
-
export type StreamMethod<T extends ServiceType> = StreamMethods<T>[keyof StreamMethods<T>] extends keyof StreamPromiseClient<T> ? StreamMethods<T>[keyof StreamMethods<T>] : never;
|
|
12
16
|
declare enum ServerStreamSubscriptionStatus {
|
|
13
17
|
Init = "init",
|
|
14
18
|
Ready = "ready",
|
|
@@ -26,8 +30,11 @@ export type ServerStreamSubscriptionOptions = {
|
|
|
26
30
|
reconnectMaxDelay?: number;
|
|
27
31
|
reconnectMaxAttempts?: number;
|
|
28
32
|
};
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
interface DataObj {
|
|
34
|
+
[k: string]: any;
|
|
35
|
+
}
|
|
36
|
+
export declare class ServerStreamSubscription<T extends ServiceType, Request extends DataObj, Response extends DataObj, M extends keyof StreamMethods<T> = keyof StreamMethods<T>, Method extends StreamPromiseClient<T>[M] = StreamPromiseClient<T>[M]> {
|
|
37
|
+
params: PreinitializedWritableAtom<Request> | Request;
|
|
31
38
|
private streamCancel?;
|
|
32
39
|
private method;
|
|
33
40
|
private options;
|
|
@@ -38,7 +45,7 @@ export declare class ServerStreamSubscription<T extends ServiceType, Request ext
|
|
|
38
45
|
private paramsListener?;
|
|
39
46
|
private reconnectTimeout?;
|
|
40
47
|
private attempt;
|
|
41
|
-
constructor(headers: Transport['$headers'], method: Method, params:
|
|
48
|
+
constructor(headers: Transport['$headers'], method: Method, params: PreinitializedWritableAtom<Request> | Request, options: ServerStreamSubscriptionOptions);
|
|
42
49
|
updateState: (status: ServerStreamSubscriptionStatus) => void;
|
|
43
50
|
addStateLog: (msg: string) => void;
|
|
44
51
|
addListener: (name: string, listener: (response: Response) => void) => (() => void);
|
package/lib/grpc/transport.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { MapStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
2
|
import { createRouterTransport, ConnectRouter, Interceptor, Client, UnaryRequest, StreamRequest } from '@connectrpc/connect';
|
|
3
|
-
import type { ServiceType, Message, PlainMessage } from '@bufbuild/protobuf';
|
|
4
3
|
import { createGrpcWebTransport } from '@connectrpc/connect-web';
|
|
5
4
|
import { type KeyInput, nanoquery } from '@nanostores/query';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { PreinitializedWritableAtom } from 'nanostores';
|
|
6
|
+
import { GenService, GenServiceMethods } from '@bufbuild/protobuf/codegenv1';
|
|
7
|
+
import { ServerStreamSubscription, StreamPromiseClient, type ServerStreamSubscriptionOptions } from './subscription';
|
|
8
|
+
type ServiceType = GenService<GenServiceMethods>;
|
|
8
9
|
type KnownHeaders = {
|
|
9
10
|
authorization?: string;
|
|
10
11
|
sdk?: string;
|
|
@@ -32,6 +33,9 @@ export declare const RequestOptionsKeys: {
|
|
|
32
33
|
};
|
|
33
34
|
type RequestOptionsKey = keyof typeof RequestOptionsKeys;
|
|
34
35
|
type RequestOptions = Partial<Record<RequestOptionsKey, (typeof RequestOptionsKeys)[RequestOptionsKey]['defaultValue']>>;
|
|
36
|
+
export interface DataObj {
|
|
37
|
+
[k: string]: any;
|
|
38
|
+
}
|
|
35
39
|
/**
|
|
36
40
|
* transport wrapper, initialize grpc transport, store headers and connect interceptors
|
|
37
41
|
*/
|
|
@@ -57,8 +61,8 @@ export declare class Transport {
|
|
|
57
61
|
refetchInterval?: number;
|
|
58
62
|
retryable?: boolean;
|
|
59
63
|
});
|
|
60
|
-
addSubscription: <T extends ServiceType, Req extends
|
|
61
|
-
removeSubscription: (subscription: ServerStreamSubscription<ServiceType,
|
|
64
|
+
addSubscription: <T extends ServiceType, Req extends Record<string, unknown>, Res extends Record<string, unknown>, M extends keyof StreamPromiseClient<T> = keyof StreamPromiseClient<T>>(method: StreamPromiseClient<T>[M], params: PreinitializedWritableAtom<Req> | Req, options: ServerStreamSubscriptionOptions) => ServerStreamSubscription<ServiceType, DataObj, DataObj, never, never> | ServerStreamSubscription<T, Req, Res, keyof StreamPromiseClient<T>, StreamPromiseClient<T>[keyof StreamPromiseClient<T>]>;
|
|
65
|
+
removeSubscription: (subscription: ServerStreamSubscription<ServiceType, DataObj, DataObj>) => void;
|
|
62
66
|
disconnect: () => void;
|
|
63
67
|
registerInterceptor: (interceptor: Interceptor) => void;
|
|
64
68
|
removeInterceptor: (interceptor: Interceptor) => void;
|
|
@@ -66,7 +70,7 @@ export declare class Transport {
|
|
|
66
70
|
getStreamClient: <T extends ServiceType>(service: T) => Client<T>;
|
|
67
71
|
createPromiseClient: <T extends ServiceType>(service: T, { params, method }: {
|
|
68
72
|
params?: KeyInput;
|
|
69
|
-
method: keyof T["
|
|
73
|
+
method: keyof T["method"];
|
|
70
74
|
}) => {
|
|
71
75
|
client: Client<T>;
|
|
72
76
|
createRequestOptions: (options: RequestOptions) => import("@connectrpc/connect").ContextValues;
|
package/lib/grpc/transport.js
CHANGED
|
@@ -85,8 +85,10 @@ export class Transport {
|
|
|
85
85
|
if (currentSubscription) {
|
|
86
86
|
return currentSubscription;
|
|
87
87
|
}
|
|
88
|
-
const subscription = new ServerStreamSubscription(this.$headers, method,
|
|
89
|
-
//
|
|
88
|
+
const subscription = new ServerStreamSubscription(this.$headers, method,
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
90
|
+
// @ts-ignore
|
|
91
|
+
params, options);
|
|
90
92
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
91
93
|
// @ts-ignore
|
|
92
94
|
this.subscriptions.set(params, subscription);
|
|
@@ -140,7 +142,7 @@ export class Transport {
|
|
|
140
142
|
// create unary client, used for query request
|
|
141
143
|
createPromiseClient = (service, { params = [], method }) => {
|
|
142
144
|
const client = this.getClient(service);
|
|
143
|
-
const methodName =
|
|
145
|
+
const methodName = method.toString();
|
|
144
146
|
const queryKey = [
|
|
145
147
|
service.typeName,
|
|
146
148
|
methodName.charAt(0).toLowerCase() + methodName.slice(1),
|
package/lib/utils/grpc-stub.js
CHANGED
|
@@ -5,15 +5,15 @@ export class GrpcStub {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
this.transport = new Transport(process.env.NX_GRPC_HOST || 'https://grpc-sdk.next.streamlayer.io:443');
|
|
7
7
|
this.stubs = new Map();
|
|
8
|
-
const stubbedUnary = (
|
|
9
|
-
const key = `${
|
|
8
|
+
const stubbedUnary = (method, signal, timeoutMs, header, input) => {
|
|
9
|
+
const key = `${method.name}`.toLowerCase();
|
|
10
10
|
console.log('grpc unary', { key, input });
|
|
11
11
|
for (const [stubKey, stubValue] of this.stubs) {
|
|
12
12
|
if (stubKey === key) {
|
|
13
13
|
return { message: stubValue };
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
throw new Error(JSON.stringify({ message: 'not stubbed correctly',
|
|
16
|
+
throw new Error(JSON.stringify({ message: 'not stubbed correctly', method, signal, timeoutMs, header, input }));
|
|
17
17
|
};
|
|
18
18
|
this.transport.transport.unary = stubbedUnary;
|
|
19
19
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamlayer/sdk-web-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@streamlayer/sdk-web-
|
|
25
|
-
"@streamlayer/sdk-web-
|
|
26
|
-
"@streamlayer/sdk-web-
|
|
24
|
+
"@streamlayer/sdk-web-logger": "^1.0.62",
|
|
25
|
+
"@streamlayer/sdk-web-storage": "^1.0.62",
|
|
26
|
+
"@streamlayer/sdk-web-interfaces": "^1.6.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@bufbuild/protobuf": "^
|
|
30
|
-
"@connectrpc/connect": "^
|
|
31
|
-
"@connectrpc/connect-web": "^
|
|
29
|
+
"@bufbuild/protobuf": "^2.2.2",
|
|
30
|
+
"@connectrpc/connect": "^2.0.0",
|
|
31
|
+
"@connectrpc/connect-web": "^2.0.0",
|
|
32
32
|
"@nanostores/query": "^0.2.10",
|
|
33
|
-
"@streamlayer/sl-eslib": "^5.
|
|
33
|
+
"@streamlayer/sl-eslib": "^5.163.2",
|
|
34
34
|
"@swc/helpers": "~0.5.15",
|
|
35
35
|
"nanostores": "^0.11.4",
|
|
36
36
|
"tslib": "^2.7.0",
|