@motiadev/stream-client-browser 0.12.1-beta.158 → 0.13.0-beta.160

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/README.md CHANGED
@@ -27,7 +27,10 @@ npm install @motiadev/stream-client-browser
27
27
  ```typescript
28
28
  import { Stream } from '@motiadev/stream-client-browser'
29
29
 
30
- const stream = new Stream('wss://your-stream-server')
30
+ const token = window.sessionStorage.getItem('motia.streamToken') ?? undefined
31
+ const protocols = token ? ['Authorization', token] : undefined
32
+
33
+ const stream = new Stream('wss://your-stream-server', { protocols })
31
34
  ```
32
35
 
33
36
  ### 2. Subscribing to an Item Stream
@@ -69,10 +72,10 @@ stream.close()
69
72
 
70
73
  ### `Stream`
71
74
 
72
- - **constructor(address: string, onReady: () => void)**
75
+ - **constructor(address: string, options?: { protocols?: string | string[] })**
73
76
 
74
77
  - Establishes a WebSocket connection to the given address.
75
- - Calls `onReady` when the connection is open.
78
+ - Passes any `protocols` directly to the underlying `WebSocket` constructor (useful for sending `Sec-WebSocket-Protocol: Authorization,<token>`).
76
79
 
77
80
  - **subscribeItem<T>(streamName: string, id: string): StreamItemSubscription<T>**
78
81
 
@@ -161,7 +164,10 @@ All types are exported from `stream.types.ts` for advanced usage and type safety
161
164
  ```typescript
162
165
  import { Stream } from '@motiadev/stream-client-browser'
163
166
 
164
- const stream = new Stream('wss://example.com')
167
+ const token = window.sessionStorage.getItem('motia.streamToken') ?? undefined
168
+ const protocols = token ? ['Authorization', token] : undefined
169
+
170
+ const stream = new Stream('wss://example.com', { protocols })
165
171
  const userSub = stream.subscribeItem<{ id: string; name: string }>('users', 'user-1')
166
172
 
167
173
  userSub.addChangeListener((user) => {
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { StreamGroupSubscription, StreamItemSubscription, StreamSubscription } from '@motiadev/stream-client';
2
+ export type { BrowserStreamOptions } from './src/stream';
2
3
  export { Stream } from './src/stream';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC7G,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA"}
@@ -5,7 +5,7 @@ export declare class StreamSocketAdapter implements SocketAdapter {
5
5
  private onMessageListeners;
6
6
  private onOpenListeners;
7
7
  private onCloseListeners;
8
- constructor(address: string);
8
+ constructor(address: string, protocols?: string | string[] | undefined);
9
9
  connect(): void;
10
10
  send(message: string): void;
11
11
  onMessage(callback: (message: string) => void): void;
@@ -14,3 +14,4 @@ export declare class StreamSocketAdapter implements SocketAdapter {
14
14
  close(): void;
15
15
  isOpen(): boolean;
16
16
  }
17
+ //# sourceMappingURL=stream-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-adapter.d.ts","sourceRoot":"","sources":["../../src/stream-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D,qBAAa,mBAAoB,YAAW,aAAa;IAQrD,OAAO,CAAC,OAAO;IAPjB,OAAO,CAAC,EAAE,CAAW;IAErB,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,gBAAgB,CAAqB;gBAGnC,OAAO,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS;IAK3C,OAAO,IAAI,IAAI;IAEf,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAI3B,SAAS,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAOpD,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAKlC,OAAO,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAKnC,KAAK,IAAI,IAAI;IAOb,MAAM,IAAI,OAAO;CAGlB"}
@@ -1,10 +1,10 @@
1
1
  export class StreamSocketAdapter {
2
- constructor(address) {
2
+ constructor(address, protocols) {
3
3
  this.address = address;
4
4
  this.onMessageListeners = [];
5
5
  this.onOpenListeners = [];
6
6
  this.onCloseListeners = [];
7
- this.ws = new WebSocket(this.address);
7
+ this.ws = new WebSocket(this.address, protocols);
8
8
  }
9
9
  connect() { }
10
10
  send(message) {
@@ -1,4 +1,8 @@
1
1
  import { Stream as StreamClient } from '@motiadev/stream-client';
2
+ export type BrowserStreamOptions = {
3
+ protocols?: string | string[] | undefined;
4
+ };
2
5
  export declare class Stream extends StreamClient {
3
- constructor(address: string);
6
+ constructor(address: string, options?: BrowserStreamOptions);
4
7
  }
8
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAGhE,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAA;CAC1C,CAAA;AAED,qBAAa,MAAO,SAAQ,YAAY;gBAC1B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB;CAG5D"}
@@ -1,7 +1,7 @@
1
1
  import { Stream as StreamClient } from '@motiadev/stream-client';
2
2
  import { StreamSocketAdapter } from './stream-adapter';
3
3
  export class Stream extends StreamClient {
4
- constructor(address) {
5
- super(() => new StreamSocketAdapter(address));
4
+ constructor(address, options) {
5
+ super(() => new StreamSocketAdapter(address, options?.protocols));
6
6
  }
7
7
  }
package/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { StreamGroupSubscription, StreamItemSubscription, StreamSubscription } from '@motiadev/stream-client'
2
+ export type { BrowserStreamOptions } from './src/stream'
2
3
  export { Stream } from './src/stream'
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@motiadev/stream-client-browser",
3
3
  "description": "Motia Stream Client Package – Responsible for managing streams of data.",
4
- "version": "0.12.1-beta.158",
4
+ "version": "0.13.0-beta.160",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "dependencies": {
9
9
  "uuid": "^11.1.0",
10
- "@motiadev/stream-client": "0.12.1-beta.158"
10
+ "@motiadev/stream-client": "0.13.0-beta.160"
11
11
  },
12
12
  "devDependencies": {
13
13
  "@types/jest": "^29.5.14",