Socket
Socket
Sign inDemoInstall

graphql-ws

Package Overview
Dependencies
1
Maintainers
1
Versions
103
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.14.1 to 5.14.2

2

lib/client.js

@@ -544,3 +544,3 @@ "use strict";

1013,
1013, // Bad Gateway
1014, // Bad Gateway
].includes(code))

@@ -547,0 +547,0 @@ return false;

@@ -13,3 +13,3 @@ /**

*
* Mainly used because TypeScript collapes unions
* Mainly used because TypeScript collapses unions
* with `any` or `unknown` to `any` or `unknown`. So,

@@ -171,3 +171,3 @@ * we use a custom type to allow definitions such as

* In comparison to `onDisconnect`, this callback will ALWAYS
* be called, regardless if the user succesfully went through
* be called, regardless if the user successfully went through
* the connection initialisation or not. `onConnect` might not

@@ -209,3 +209,3 @@ * called before the `onClose`.

* Executed after the operation call resolves. For streaming
* operations, triggering this callback does not necessarely
* operations, triggering this callback does not necessarily
* mean that there is already a result available - it means

@@ -230,3 +230,3 @@ * that the subscription process for the stream has resolved

/**
* Executed after an error occured right before it
* Executed after an error occurred right before it
* has been dispatched to the client.

@@ -289,3 +289,3 @@ *

/**
* New socket has beeen established. The lib will validate
* New socket has been established. The lib will validate
* the protocol and use the socket accordingly. Returned promise

@@ -309,3 +309,3 @@ * will resolve after the socket closes.

* The subprotocol of the WebSocket. Will be used
* to validate agains the supported ones.
* to validate against the supported ones.
*/

@@ -354,3 +354,3 @@ readonly protocol: string;

* If this listener is implemented, the server will NOT automatically reply
* to any pings from the client. Implementing it makes it your resposibility
* to any pings from the client. Implementing it makes it your responsibility
* to decide how and when to respond.

@@ -401,3 +401,3 @@ */

/**
* Makes a Protocol complient WebSocket GraphQL server. The server
* Makes a Protocol compliant WebSocket GraphQL server. The server
* is actually an API which is to be used with your favourite WebSocket

@@ -404,0 +404,0 @@ * server library!

@@ -20,3 +20,3 @@ "use strict";

/**
* Makes a Protocol complient WebSocket GraphQL server. The server
* Makes a Protocol compliant WebSocket GraphQL server. The server
* is actually an API which is to be used with your favourite WebSocket

@@ -181,3 +181,3 @@ * server library!

]);
// if `onSubscribe` didnt specify a rootValue, inject one
// if `onSubscribe` didn't specify a rootValue, inject one
if (!('rootValue' in execArgs))

@@ -236,3 +236,3 @@ execArgs.rootValue = roots === null || roots === void 0 ? void 0 : roots[operationAST.operation];

// lack of subscription at this point indicates that the client
// completed the subscription, he doesnt need to be reminded
// completed the subscription, he doesn't need to be reminded
await emit.complete(id in ctx.subscriptions);

@@ -239,0 +239,0 @@ }

@@ -31,3 +31,3 @@ import type * as http from 'http';

/**
* The timout between dispatched keep-alive messages. Internally uses the [ws Ping and Pongs]((https://developer.mozilla.org/en-US/docs/Web/API/wss_API/Writing_ws_servers#Pings_and_Pongs_The_Heartbeat_of_wss))
* The timeout between dispatched keep-alive messages. Internally uses the [ws Ping and Pongs]((https://developer.mozilla.org/en-US/docs/Web/API/wss_API/Writing_ws_servers#Pings_and_Pongs_The_Heartbeat_of_wss))
* to check that the link between the clients and the server is operating and to prevent the link

@@ -34,0 +34,0 @@ * from being broken due to idling.

@@ -15,3 +15,3 @@ "use strict";

/**
* The timout between dispatched keep-alive messages. Internally uses the [ws Ping and Pongs]((https://developer.mozilla.org/en-US/docs/Web/API/wss_API/Writing_ws_servers#Pings_and_Pongs_The_Heartbeat_of_wss))
* The timeout between dispatched keep-alive messages. Internally uses the [ws Ping and Pongs]((https://developer.mozilla.org/en-US/docs/Web/API/wss_API/Writing_ws_servers#Pings_and_Pongs_The_Heartbeat_of_wss))
* to check that the link between the clients and the server is operating and to prevent the link

@@ -18,0 +18,0 @@ * from being broken due to idling.

{
"name": "graphql-ws",
"version": "5.14.1",
"version": "5.14.2",
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,3 +0,1 @@

[![GraphQL Conf 2023](/GraphQLConf-2023-Banner.png)](https://graphql.org/conf/)
<div align="center">

@@ -4,0 +2,0 @@ <br />

@@ -759,3 +759,3 @@ (function (global, factory) {

1013,
1013, // Bad Gateway
1014, // Bad Gateway
].includes(code))

@@ -762,0 +762,0 @@ return false;

@@ -1,1 +0,1 @@

!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";function o(e){return this instanceof o?(this.v=e,this):new o(e)}function t(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(e,t||[]),s=[];return n={},a("next"),a("throw"),a("return"),n[Symbol.asyncIterator]=function(){return this},n;function a(e){i[e]&&(n[e]=function(o){return new Promise((function(t,r){s.push([e,o,t,r])>1||l(e,o)}))})}function l(e,t){try{(r=i[e](t)).value instanceof o?Promise.resolve(r.value.v).then(c,p):d(s[0][2],r)}catch(e){d(s[0][3],e)}var r}function c(e){l("next",e)}function p(e){l("throw",e)}function d(e,o){e(o),s.shift(),s.length&&l(s[0][0],s[0][1])}}function r(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function n(e){return"object"===r(e)}function i(e,o){return e.length<124?e:o}const s="graphql-transport-ws";var a,l;function c(o){if(!n(o))throw new Error(`Message is expected to be an object, but got ${r(o)}`);if(!o.type)throw new Error("Message is missing the 'type' property");if("string"!=typeof o.type)throw new Error(`Message is expects the 'type' property to be a string, but got ${r(o.type)}`);switch(o.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:if(null!=o.payload&&!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${o.payload}"`);break;case e.MessageType.Subscribe:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);if("string"!=typeof o.payload.query)throw new Error(`"${o.type}" message payload expects the 'query' property to be a string, but got ${r(o.payload.query)}`);if(null!=o.payload.variables&&!n(o.payload.variables))throw new Error(`"${o.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${r(o.payload.variables)}`);if(null!=o.payload.operationName&&"string"!==r(o.payload.operationName))throw new Error(`"${o.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${r(o.payload.operationName)}`);if(null!=o.payload.extensions&&!n(o.payload.extensions))throw new Error(`"${o.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${r(o.payload.extensions)}`);break;case e.MessageType.Next:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);break;case e.MessageType.Error:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(t=o.payload,!(Array.isArray(t)&&t.length>0&&t.every((e=>"message"in e))))throw new Error(`"${o.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(o.payload)}`);break;case e.MessageType.Complete:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);break;default:throw new Error(`Invalid message 'type' property "${o.type}"`)}var t;return o}function p(e,o){return c("string"==typeof e?JSON.parse(e,o):e)}function d(e,o){return c(e),JSON.stringify(e,o)}function y(e){return n(e)&&"code"in e&&"reason"in e}e.CloseCode=void 0,(a=e.CloseCode||(e.CloseCode={}))[a.InternalServerError=4500]="InternalServerError",a[a.InternalClientError=4005]="InternalClientError",a[a.BadRequest=4400]="BadRequest",a[a.BadResponse=4004]="BadResponse",a[a.Unauthorized=4401]="Unauthorized",a[a.Forbidden=4403]="Forbidden",a[a.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",a[a.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",a[a.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",a[a.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",a[a.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e.MessageType=void 0,(l=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",l.ConnectionAck="connection_ack",l.Ping="ping",l.Pong="pong",l.Subscribe="subscribe",l.Next="next",l.Error="error",l.Complete="complete",e.DEPRECATED_GRAPHQL_WS_PROTOCOL="graphql-ws",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=s,e.createClient=function(r){const{url:n,connectionParams:a,lazy:l=!0,onNonLazyError:c=console.error,lazyCloseTimeout:u=0,keepAlive:g=0,disablePong:f,connectionAckWaitTimeout:m=0,retryAttempts:b=5,retryWait:h=async function(e){let o=1e3;for(let t=0;t<e;t++)o*=2;await new Promise((e=>setTimeout(e,o+Math.floor(2700*Math.random()+300))))},shouldRetry:w=y,isFatalConnectionProblem:x,on:C,webSocketImpl:v,generateID:E=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const o=16*Math.random()|0;return("x"==e?o:3&o|8).toString(16)}))},jsonMessageReplacer:T,jsonMessageReviver:S}=r;let M;if(v){if(!("function"==typeof($=v)&&"constructor"in $&&"CLOSED"in $&&"CLOSING"in $&&"CONNECTING"in $&&"OPEN"in $))throw new Error("Invalid WebSocket implementation provided");M=v}else"undefined"!=typeof WebSocket?M=WebSocket:"undefined"!=typeof global?M=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(M=window.WebSocket||window.MozWebSocket);var $;if(!M)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const P=M,I=(()=>{const e=(()=>{const e={};return{on:(o,t)=>(e[o]=t,()=>{delete e[o]}),emit(o){var t;"id"in o&&(null===(t=e[o.id])||void 0===t||t.call(e,o))}}})(),o={connecting:(null==C?void 0:C.connecting)?[C.connecting]:[],opened:(null==C?void 0:C.opened)?[C.opened]:[],connected:(null==C?void 0:C.connected)?[C.connected]:[],ping:(null==C?void 0:C.ping)?[C.ping]:[],pong:(null==C?void 0:C.pong)?[C.pong]:[],message:(null==C?void 0:C.message)?[e.emit,C.message]:[e.emit],closed:(null==C?void 0:C.closed)?[C.closed]:[],error:(null==C?void 0:C.error)?[C.error]:[]};return{onMessage:e.on,on(e,t){const r=o[e];return r.push(t),()=>{r.splice(r.indexOf(t),1)}},emit(e,...t){for(const r of[...o[e]])r(...t)}}})();function N(e){const o=[I.on("error",(t=>{o.forEach((e=>e())),e(t)})),I.on("closed",(t=>{o.forEach((e=>e())),e(t)}))]}let k,A,O=0,R=!1,q=0,W=!1;async function j(){clearTimeout(A);const[o,t]=await(null!=k?k:k=new Promise(((o,t)=>(async()=>{if(R){if(await h(q),!O)return k=void 0,t({code:1e3,reason:"All Subscriptions Gone"});q++}I.emit("connecting");const r=new P("function"==typeof n?await n():n,s);let l,c;function u(){isFinite(g)&&g>0&&(clearTimeout(c),c=setTimeout((()=>{r.readyState===P.OPEN&&(r.send(d({type:e.MessageType.Ping})),I.emit("ping",!1,void 0))}),g))}N((e=>{k=void 0,clearTimeout(l),clearTimeout(c),t(e),y(e)&&4499===e.code&&(r.close(4499,"Terminated"),r.onerror=null,r.onclose=null)})),r.onerror=e=>I.emit("error",e),r.onclose=e=>I.emit("closed",e),r.onopen=async()=>{try{I.emit("opened",r);const o="function"==typeof a?await a():a;if(r.readyState!==P.OPEN)return;r.send(d(o?{type:e.MessageType.ConnectionInit,payload:o}:{type:e.MessageType.ConnectionInit},T)),isFinite(m)&&m>0&&(l=setTimeout((()=>{r.close(e.CloseCode.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")}),m)),u()}catch(o){I.emit("error",o),r.close(e.CloseCode.InternalClientError,i(o instanceof Error?o.message:new Error(o).message,"Internal client error"))}};let b=!1;r.onmessage=({data:t})=>{try{const n=p(t,S);if(I.emit("message",n),"ping"===n.type||"pong"===n.type)return I.emit(n.type,!0,n.payload),void("pong"===n.type?u():f||(r.send(d(n.payload?{type:e.MessageType.Pong,payload:n.payload}:{type:e.MessageType.Pong})),I.emit("pong",!1,n.payload)));if(b)return;if(n.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${n.type}`);clearTimeout(l),b=!0,I.emit("connected",r,n.payload),R=!1,q=0,o([r,new Promise(((e,o)=>N(o)))])}catch(o){r.onmessage=null,I.emit("error",o),r.close(e.CloseCode.BadResponse,i(o instanceof Error?o.message:new Error(o).message,"Bad response"))}}})())));o.readyState===P.CLOSING&&await t;let r=()=>{};const l=new Promise((e=>r=e));return[o,r,Promise.race([l.then((()=>{if(!O){const e=()=>o.close(1e3,"Normal Closure");isFinite(u)&&u>0?A=setTimeout((()=>{o.readyState===P.OPEN&&e()}),u):e()}})),t])]}function L(o){if(y(o)&&(t=o.code,![1e3,1001,1006,1005,1012,1013,1013].includes(t)&&t>=1e3&&t<=1999||[e.CloseCode.InternalServerError,e.CloseCode.InternalClientError,e.CloseCode.BadRequest,e.CloseCode.BadResponse,e.CloseCode.Unauthorized,e.CloseCode.SubprotocolNotAcceptable,e.CloseCode.SubscriberAlreadyExists,e.CloseCode.TooManyInitialisationRequests].includes(o.code)))throw o;var t;if(W)return!1;if(y(o)&&1e3===o.code)return O>0;if(!b||q>=b)throw o;if(!w(o))throw o;if(null==x?void 0:x(o))throw o;return R=!0}return l||(async()=>{for(O++;;)try{const[,,e]=await j();await e}catch(e){try{if(!L(e))return}catch(e){return null==c?void 0:c(e)}}})(),{on:I.on,subscribe(o,t){const r=E(o);let n=!1,i=!1,s=()=>{O--,n=!0};return(async()=>{for(O++;;)try{const[a,l,c]=await j();if(n)return l();const p=I.onMessage(r,(o=>{switch(o.type){case e.MessageType.Next:return void t.next(o.payload);case e.MessageType.Error:return i=!0,n=!0,t.error(o.payload),void s();case e.MessageType.Complete:return n=!0,void s()}}));return a.send(d({id:r,type:e.MessageType.Subscribe,payload:o},T)),s=()=>{n||a.readyState!==P.OPEN||a.send(d({id:r,type:e.MessageType.Complete},T)),O--,n=!0,l()},void await c.finally(p)}catch(e){if(!L(e))return}})().then((()=>{i||t.complete()})).catch((e=>{t.error(e)})),()=>{n||s()}},iterate(e){const r=[],n={done:!1,error:null,resolve:()=>{}},i=this.subscribe(e,{next(e){r.push(e),n.resolve()},error(e){n.done=!0,n.error=e,n.resolve()},complete(){n.done=!0,n.resolve()}}),s=function(){return t(this,arguments,(function*(){for(;;){for(r.length||(yield o(new Promise((e=>n.resolve=e))));r.length;)yield yield o(r.shift());if(n.error)throw n.error;if(n.done)return yield o(void 0)}}))}();return s.throw=async e=>(n.done||(n.done=!0,n.error=e,n.resolve()),{done:!0,value:void 0}),s.return=async()=>(i(),{done:!0,value:void 0}),s},async dispose(){if(W=!0,k){const[e]=await k;e.close(1e3,"Normal Closure")}},terminate(){k&&I.emit("closed",{code:4499,reason:"Terminated",wasClean:!1})}}},e.isMessage=function(e){try{return c(e),!0}catch(e){return!1}},e.parseMessage=p,e.stringifyMessage=d,e.validateMessage=c}));
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self).graphqlWs={})}(this,(function(e){"use strict";function o(e){return this instanceof o?(this.v=e,this):new o(e)}function t(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,i=r.apply(e,t||[]),s=[];return n={},a("next"),a("throw"),a("return"),n[Symbol.asyncIterator]=function(){return this},n;function a(e){i[e]&&(n[e]=function(o){return new Promise((function(t,r){s.push([e,o,t,r])>1||l(e,o)}))})}function l(e,t){try{(r=i[e](t)).value instanceof o?Promise.resolve(r.value.v).then(c,p):d(s[0][2],r)}catch(e){d(s[0][3],e)}var r}function c(e){l("next",e)}function p(e){l("throw",e)}function d(e,o){e(o),s.shift(),s.length&&l(s[0][0],s[0][1])}}function r(e){return null===e?"null":Array.isArray(e)?"array":typeof e}function n(e){return"object"===r(e)}function i(e,o){return e.length<124?e:o}const s="graphql-transport-ws";var a,l;function c(o){if(!n(o))throw new Error(`Message is expected to be an object, but got ${r(o)}`);if(!o.type)throw new Error("Message is missing the 'type' property");if("string"!=typeof o.type)throw new Error(`Message is expects the 'type' property to be a string, but got ${r(o.type)}`);switch(o.type){case e.MessageType.ConnectionInit:case e.MessageType.ConnectionAck:case e.MessageType.Ping:case e.MessageType.Pong:if(null!=o.payload&&!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object or nullish or missing, but got "${o.payload}"`);break;case e.MessageType.Subscribe:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);if("string"!=typeof o.payload.query)throw new Error(`"${o.type}" message payload expects the 'query' property to be a string, but got ${r(o.payload.query)}`);if(null!=o.payload.variables&&!n(o.payload.variables))throw new Error(`"${o.type}" message payload expects the 'variables' property to be a an object or nullish or missing, but got ${r(o.payload.variables)}`);if(null!=o.payload.operationName&&"string"!==r(o.payload.operationName))throw new Error(`"${o.type}" message payload expects the 'operationName' property to be a string or nullish or missing, but got ${r(o.payload.operationName)}`);if(null!=o.payload.extensions&&!n(o.payload.extensions))throw new Error(`"${o.type}" message payload expects the 'extensions' property to be a an object or nullish or missing, but got ${r(o.payload.extensions)}`);break;case e.MessageType.Next:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(!n(o.payload))throw new Error(`"${o.type}" message expects the 'payload' property to be an object, but got ${r(o.payload)}`);break;case e.MessageType.Error:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);if(t=o.payload,!(Array.isArray(t)&&t.length>0&&t.every((e=>"message"in e))))throw new Error(`"${o.type}" message expects the 'payload' property to be an array of GraphQL errors, but got ${JSON.stringify(o.payload)}`);break;case e.MessageType.Complete:if("string"!=typeof o.id)throw new Error(`"${o.type}" message expects the 'id' property to be a string, but got ${r(o.id)}`);if(!o.id)throw new Error(`"${o.type}" message requires a non-empty 'id' property`);break;default:throw new Error(`Invalid message 'type' property "${o.type}"`)}var t;return o}function p(e,o){return c("string"==typeof e?JSON.parse(e,o):e)}function d(e,o){return c(e),JSON.stringify(e,o)}function y(e){return n(e)&&"code"in e&&"reason"in e}e.CloseCode=void 0,(a=e.CloseCode||(e.CloseCode={}))[a.InternalServerError=4500]="InternalServerError",a[a.InternalClientError=4005]="InternalClientError",a[a.BadRequest=4400]="BadRequest",a[a.BadResponse=4004]="BadResponse",a[a.Unauthorized=4401]="Unauthorized",a[a.Forbidden=4403]="Forbidden",a[a.SubprotocolNotAcceptable=4406]="SubprotocolNotAcceptable",a[a.ConnectionInitialisationTimeout=4408]="ConnectionInitialisationTimeout",a[a.ConnectionAcknowledgementTimeout=4504]="ConnectionAcknowledgementTimeout",a[a.SubscriberAlreadyExists=4409]="SubscriberAlreadyExists",a[a.TooManyInitialisationRequests=4429]="TooManyInitialisationRequests",e.MessageType=void 0,(l=e.MessageType||(e.MessageType={})).ConnectionInit="connection_init",l.ConnectionAck="connection_ack",l.Ping="ping",l.Pong="pong",l.Subscribe="subscribe",l.Next="next",l.Error="error",l.Complete="complete",e.DEPRECATED_GRAPHQL_WS_PROTOCOL="graphql-ws",e.GRAPHQL_TRANSPORT_WS_PROTOCOL=s,e.createClient=function(r){const{url:n,connectionParams:a,lazy:l=!0,onNonLazyError:c=console.error,lazyCloseTimeout:u=0,keepAlive:g=0,disablePong:f,connectionAckWaitTimeout:m=0,retryAttempts:b=5,retryWait:h=async function(e){let o=1e3;for(let t=0;t<e;t++)o*=2;await new Promise((e=>setTimeout(e,o+Math.floor(2700*Math.random()+300))))},shouldRetry:w=y,isFatalConnectionProblem:x,on:C,webSocketImpl:v,generateID:E=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const o=16*Math.random()|0;return("x"==e?o:3&o|8).toString(16)}))},jsonMessageReplacer:T,jsonMessageReviver:S}=r;let M;if(v){if(!("function"==typeof($=v)&&"constructor"in $&&"CLOSED"in $&&"CLOSING"in $&&"CONNECTING"in $&&"OPEN"in $))throw new Error("Invalid WebSocket implementation provided");M=v}else"undefined"!=typeof WebSocket?M=WebSocket:"undefined"!=typeof global?M=global.WebSocket||global.MozWebSocket:"undefined"!=typeof window&&(M=window.WebSocket||window.MozWebSocket);var $;if(!M)throw new Error("WebSocket implementation missing; on Node you can `import WebSocket from 'ws';` and pass `webSocketImpl: WebSocket` to `createClient`");const P=M,I=(()=>{const e=(()=>{const e={};return{on:(o,t)=>(e[o]=t,()=>{delete e[o]}),emit(o){var t;"id"in o&&(null===(t=e[o.id])||void 0===t||t.call(e,o))}}})(),o={connecting:(null==C?void 0:C.connecting)?[C.connecting]:[],opened:(null==C?void 0:C.opened)?[C.opened]:[],connected:(null==C?void 0:C.connected)?[C.connected]:[],ping:(null==C?void 0:C.ping)?[C.ping]:[],pong:(null==C?void 0:C.pong)?[C.pong]:[],message:(null==C?void 0:C.message)?[e.emit,C.message]:[e.emit],closed:(null==C?void 0:C.closed)?[C.closed]:[],error:(null==C?void 0:C.error)?[C.error]:[]};return{onMessage:e.on,on(e,t){const r=o[e];return r.push(t),()=>{r.splice(r.indexOf(t),1)}},emit(e,...t){for(const r of[...o[e]])r(...t)}}})();function N(e){const o=[I.on("error",(t=>{o.forEach((e=>e())),e(t)})),I.on("closed",(t=>{o.forEach((e=>e())),e(t)}))]}let k,A,O=0,R=!1,q=0,W=!1;async function j(){clearTimeout(A);const[o,t]=await(null!=k?k:k=new Promise(((o,t)=>(async()=>{if(R){if(await h(q),!O)return k=void 0,t({code:1e3,reason:"All Subscriptions Gone"});q++}I.emit("connecting");const r=new P("function"==typeof n?await n():n,s);let l,c;function u(){isFinite(g)&&g>0&&(clearTimeout(c),c=setTimeout((()=>{r.readyState===P.OPEN&&(r.send(d({type:e.MessageType.Ping})),I.emit("ping",!1,void 0))}),g))}N((e=>{k=void 0,clearTimeout(l),clearTimeout(c),t(e),y(e)&&4499===e.code&&(r.close(4499,"Terminated"),r.onerror=null,r.onclose=null)})),r.onerror=e=>I.emit("error",e),r.onclose=e=>I.emit("closed",e),r.onopen=async()=>{try{I.emit("opened",r);const o="function"==typeof a?await a():a;if(r.readyState!==P.OPEN)return;r.send(d(o?{type:e.MessageType.ConnectionInit,payload:o}:{type:e.MessageType.ConnectionInit},T)),isFinite(m)&&m>0&&(l=setTimeout((()=>{r.close(e.CloseCode.ConnectionAcknowledgementTimeout,"Connection acknowledgement timeout")}),m)),u()}catch(o){I.emit("error",o),r.close(e.CloseCode.InternalClientError,i(o instanceof Error?o.message:new Error(o).message,"Internal client error"))}};let b=!1;r.onmessage=({data:t})=>{try{const n=p(t,S);if(I.emit("message",n),"ping"===n.type||"pong"===n.type)return I.emit(n.type,!0,n.payload),void("pong"===n.type?u():f||(r.send(d(n.payload?{type:e.MessageType.Pong,payload:n.payload}:{type:e.MessageType.Pong})),I.emit("pong",!1,n.payload)));if(b)return;if(n.type!==e.MessageType.ConnectionAck)throw new Error(`First message cannot be of type ${n.type}`);clearTimeout(l),b=!0,I.emit("connected",r,n.payload),R=!1,q=0,o([r,new Promise(((e,o)=>N(o)))])}catch(o){r.onmessage=null,I.emit("error",o),r.close(e.CloseCode.BadResponse,i(o instanceof Error?o.message:new Error(o).message,"Bad response"))}}})())));o.readyState===P.CLOSING&&await t;let r=()=>{};const l=new Promise((e=>r=e));return[o,r,Promise.race([l.then((()=>{if(!O){const e=()=>o.close(1e3,"Normal Closure");isFinite(u)&&u>0?A=setTimeout((()=>{o.readyState===P.OPEN&&e()}),u):e()}})),t])]}function L(o){if(y(o)&&(t=o.code,![1e3,1001,1006,1005,1012,1013,1014].includes(t)&&t>=1e3&&t<=1999||[e.CloseCode.InternalServerError,e.CloseCode.InternalClientError,e.CloseCode.BadRequest,e.CloseCode.BadResponse,e.CloseCode.Unauthorized,e.CloseCode.SubprotocolNotAcceptable,e.CloseCode.SubscriberAlreadyExists,e.CloseCode.TooManyInitialisationRequests].includes(o.code)))throw o;var t;if(W)return!1;if(y(o)&&1e3===o.code)return O>0;if(!b||q>=b)throw o;if(!w(o))throw o;if(null==x?void 0:x(o))throw o;return R=!0}return l||(async()=>{for(O++;;)try{const[,,e]=await j();await e}catch(e){try{if(!L(e))return}catch(e){return null==c?void 0:c(e)}}})(),{on:I.on,subscribe(o,t){const r=E(o);let n=!1,i=!1,s=()=>{O--,n=!0};return(async()=>{for(O++;;)try{const[a,l,c]=await j();if(n)return l();const p=I.onMessage(r,(o=>{switch(o.type){case e.MessageType.Next:return void t.next(o.payload);case e.MessageType.Error:return i=!0,n=!0,t.error(o.payload),void s();case e.MessageType.Complete:return n=!0,void s()}}));return a.send(d({id:r,type:e.MessageType.Subscribe,payload:o},T)),s=()=>{n||a.readyState!==P.OPEN||a.send(d({id:r,type:e.MessageType.Complete},T)),O--,n=!0,l()},void await c.finally(p)}catch(e){if(!L(e))return}})().then((()=>{i||t.complete()})).catch((e=>{t.error(e)})),()=>{n||s()}},iterate(e){const r=[],n={done:!1,error:null,resolve:()=>{}},i=this.subscribe(e,{next(e){r.push(e),n.resolve()},error(e){n.done=!0,n.error=e,n.resolve()},complete(){n.done=!0,n.resolve()}}),s=function(){return t(this,arguments,(function*(){for(;;){for(r.length||(yield o(new Promise((e=>n.resolve=e))));r.length;)yield yield o(r.shift());if(n.error)throw n.error;if(n.done)return yield o(void 0)}}))}();return s.throw=async e=>(n.done||(n.done=!0,n.error=e,n.resolve()),{done:!0,value:void 0}),s.return=async()=>(i(),{done:!0,value:void 0}),s},async dispose(){if(W=!0,k){const[e]=await k;e.close(1e3,"Normal Closure")}},terminate(){k&&I.emit("closed",{code:4499,reason:"Terminated",wasClean:!1})}}},e.isMessage=function(e){try{return c(e),!0}catch(e){return!1}},e.parseMessage=p,e.stringifyMessage=d,e.validateMessage=c}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc