@pipe2-ai/sdk 0.1.1 → 0.2.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.
@@ -4,5 +4,5 @@ export type Pipe2SDK = ReturnType<typeof getSdk>;
4
4
  * Create a Pipe2.ai SDK client with full support for queries, mutations,
5
5
  * and real-time WebSocket subscriptions.
6
6
  */
7
- export declare function createClient(token: string, endpoint?: string): Pipe2SDK;
7
+ export declare function createClient(token: string, endpoint?: string, wsEndpoint?: string): Pipe2SDK;
8
8
  export * from '../generated/sdk.js';
package/dist/src/index.js CHANGED
@@ -1,28 +1,31 @@
1
1
  import { GraphQLClient } from 'graphql-request';
2
2
  import { createClient as createWsClient } from 'graphql-ws';
3
3
  import { print } from 'graphql';
4
- import WebSocket from 'ws';
5
4
  import { getSdk } from '../generated/sdk.js';
6
5
  /**
7
6
  * Create a Pipe2.ai SDK client with full support for queries, mutations,
8
7
  * and real-time WebSocket subscriptions.
9
8
  */
10
- export function createClient(token, endpoint = 'https://api.pipe2.ai/v1/graphql') {
9
+ export function createClient(token, endpoint = 'https://api.pipe2.ai/v1/graphql', wsEndpoint) {
11
10
  const headers = {};
12
11
  if (token) {
13
12
  headers.Authorization = `Bearer ${token}`;
14
13
  }
15
14
  // HTTP client for queries and mutations
16
15
  const httpClient = new GraphQLClient(endpoint, { headers });
17
- // WebSocket client for subscriptions (lazy — connects on first subscription)
18
- const wsEndpoint = endpoint.replace(/^http/, 'ws');
16
+ // WebSocket client for subscriptions (lazy — connects on first subscription).
17
+ // wsEndpoint overrides the derived URL — needed in dev because Astro's
18
+ // dev-server doesn't proxy WS upgrades through Vite, so subscriptions must
19
+ // bypass the same-origin proxy and dial Hasura directly.
20
+ const wsEndpointResolved = wsEndpoint || endpoint.replace(/^http/, 'ws');
19
21
  let wsClient = null;
20
22
  const getWsClient = () => {
21
23
  if (!wsClient) {
22
24
  wsClient = createWsClient({
23
- url: wsEndpoint,
25
+ url: wsEndpointResolved,
24
26
  connectionParams: { headers },
25
- webSocketImpl: WebSocket,
27
+ // Browsers have native WebSocket; only Node.js needs the 'ws' polyfill.
28
+ // graphql-ws uses globalThis.WebSocket by default when webSocketImpl is omitted.
26
29
  });
27
30
  }
28
31
  return wsClient;
package/package.json CHANGED
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "name": "@pipe2-ai/sdk",
3
- "version": "0.1.1",
4
- "main": "dist/src/index.js",
5
- "types": "dist/src/index.d.ts",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/src/index.js",
6
+ "types": "./dist/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/src/index.d.ts",
10
+ "import": "./dist/src/index.js",
11
+ "default": "./dist/src/index.js"
12
+ }
13
+ },
6
14
  "files": [
7
15
  "dist"
8
16
  ],