{"_id":"sse-z","_rev":"168648","name":"sse-z","description":"A slim, easy-to-use wrapper around SSE.","dist-tags":{"latest":"0.3.0"},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"time":{"modified":"2021-06-03T11:49:15.000Z","created":"2020-11-07T20:37:47.866Z","0.3.0":"2020-11-08T01:58:22.234Z","0.2.3":"2020-11-08T01:36:52.548Z","0.2.2":"2020-11-08T01:18:49.613Z","0.2.1":"2020-11-08T01:15:44.114Z","0.2.0":"2020-11-08T01:11:52.762Z","0.1.0":"2020-11-07T20:37:47.866Z"},"users":{},"author":{"name":"Daniel Rearden"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"versions":{"0.3.0":{"name":"sse-z","version":"0.3.0","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/index.js","unpkg":"dist/sse-z.min.js","jsdelivr":"dist/sse-z.min.js","module":"dist/index.mjs","types":"dist/index.d.ts","scripts":{"build":"del-cli dist && rollup -c","lint":"prettier --check . && tsc --noEmit","prepublishOnly":"npm run build","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.29.0","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"gitHead":"9dd70cb843e924cb66de84af480843819f8892da","_id":"sse-z@0.3.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"e215db7c303d6c4a4199d80cb63811cc28fa55b9","size":4428,"noattachment":false,"key":"/sse-z/-/sse-z-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.3.0.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.3.0_1604800702130_0.06728770965931163"},"_hasShrinkwrap":false,"publish_time":1604800702234,"_cnpm_publish_time":1604800702234},"0.2.3":{"name":"sse-z","version":"0.2.3","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/index.js","unpkg":"dist/sse-z.min.js","jsdelivr":"dist/sse-z.min.js","module":"dist/index.mjs","types":"dist/index.d.ts","scripts":{"build":"del-cli dist && rollup -c","lint":"prettier --check . && tsc --noEmit","prepublishOnly":"npm run build","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.29.0","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"gitHead":"b3d7d75a10b2c960a7487c1b1293bb63164aa44d","_id":"sse-z@0.2.3","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"7eb946a27690d18e667f103056522a04874def86","size":4433,"noattachment":false,"key":"/sse-z/-/sse-z-0.2.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.2.3.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.2.3_1604799412383_0.8974652400145315"},"_hasShrinkwrap":false,"publish_time":1604799412548,"_cnpm_publish_time":1604799412548},"0.2.2":{"name":"sse-z","version":"0.2.2","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/index.js","unpkg":"dist/sse-z.min.js","jsdelivr":"dist/sse-z.min.js","module":"dist/index.mjs","types":"dist/index.d.ts","scripts":{"build":"del-cli dist && rollup -c","lint":"prettier --check . && tsc --noEmit","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.29.0","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"gitHead":"fd1e22a8bf56bf3dc6645880ed9eef55241642ea","_id":"sse-z@0.2.2","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"747168a172747120f5068220d7ba550d9a7b0013","size":4308,"noattachment":false,"key":"/sse-z/-/sse-z-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.2.2.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.2.2_1604798329471_0.9882185378053225"},"_hasShrinkwrap":false,"publish_time":1604798329613,"_cnpm_publish_time":1604798329613},"0.2.1":{"name":"sse-z","version":"0.2.1","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/index.js","unpkg":"dist/index.min.js","jsdelivr":"dist/index.min.js","module":"dist/index.mjs","types":"dist/index.d.ts","scripts":{"build":"del-cli dist && rollup -c","lint":"prettier --check . && tsc --noEmit","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.29.0","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"gitHead":"27ce6035accaafe4cc59e62c0578c38ec031b35e","_id":"sse-z@0.2.1","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"569a087fb235ebae56f74cf2201ac1841368ad71","size":4307,"noattachment":false,"key":"/sse-z/-/sse-z-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.2.1.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.2.1_1604798143990_0.3073952612373816"},"_hasShrinkwrap":false,"publish_time":1604798144114,"_cnpm_publish_time":1604798144114},"0.2.0":{"name":"sse-z","version":"0.2.0","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/index.js","unpkg":"dist/index.min.js","module":"dist/index.mjs","types":"dist/index.d.ts","scripts":{"build":"del-cli dist && rollup -c","lint":"prettier --check . && tsc --noEmit","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","rollup-plugin-terser":"^7.0.2","rollup-plugin-typescript2":"^0.29.0","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"gitHead":"cc01c715bfd1c4279380e6f7f322cbfe823ec8c2","_id":"sse-z@0.2.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"7ccc7659fd837183d85d8da0df34ea2c8f6e9770","size":4302,"noattachment":false,"key":"/sse-z/-/sse-z-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.2.0.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.2.0_1604797912614_0.534568307033982"},"_hasShrinkwrap":false,"publish_time":1604797912762,"_cnpm_publish_time":1604797912762},"0.1.0":{"name":"sse-z","version":"0.1.0","description":"A slim, easy-to-use wrapper around SSE.","keywords":["sse","eventsource","server sent events"],"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"repository":{"type":"git","url":"git+https://github.com/contrawork/sse-z.git"},"license":"MIT","author":{"name":"Daniel Rearden"},"main":"dist/esm/index.js","typings":"dist/esm/index.d.ts","dependencies":{},"devDependencies":{"@types/eventsource":"^1.1.4","@types/express":"^4.17.8","@types/jest":"^26.0.15","del-cli":"^3.0.1","eventsource":"^1.0.7","express":"^4.17.1","get-port":"^5.1.1","husky":"^4.3.0","jest":"^26.6.1","lint-staged":"^10.5.1","prettier":"^2.1.2","rollup":"^2.33.1","terser":"^5.3.8","ts-jest":"^26.4.2","ts-node":"^9.0.0","typescript":"^4.0.3"},"scripts":{"build":"del-cli dist && npm run build-esm && npm run build-umd && npm run build-umd:min","build-esm":"tsc","build-umd":"rollup dist/esm/index.js --format=umd --name=SSEZ --file dist/umd/sse-z.js","build-umd:min":"cd dist/umd && terser sse-z.js -cmo sse-z.min.js","lint":"prettier --check .","test":"jest"},"husky":{"hooks":{"pre-commit":"lint-staged"}},"lint-staged":{"*.{js,ts}":"prettier --write"},"gitHead":"c3d0bcfdd660ad46226281047337a7e59f694dce","_id":"sse-z@0.1.0","_nodeVersion":"14.5.0","_npmVersion":"6.14.8","dist":{"shasum":"accf838b67239779edb1fb4337e4d5df1332063f","size":4167,"noattachment":false,"key":"/sse-z/-/sse-z-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/sse-z/download/sse-z-0.1.0.tgz"},"_npmUser":{"name":"danielrearden","email":"danielrearden@gmail.com"},"directories":{},"maintainers":[{"name":"danielrearden","email":"danielrearden@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/sse-z_0.1.0_1604781467729_0.3251859142708591"},"_hasShrinkwrap":false,"publish_time":1604781467866,"_cnpm_publish_time":1604781467866}},"readme":"# SSE-Z\n\n> A slim, easy-to-use wrapper around SSE.\n\n## Installation\n\n```\nnpm install sse-z\n```\n\n## Usage\n\n```ts\nimport { SSESubscription } from \"sse-z\";\n\nconst subscription = new SSESubscription({\n  url: \"http://localhost:8080/sse\",\n  searchParams: {\n    foo: \"bar\",\n  },\n  onNext: (type: string, data: string) => {\n    console.log(type, data);\n  },\n});\n\n// stop the subscription\nsubscription.unsubscribe();\n```\n\n## Types\n\n```ts\nclass SSESubscription {\n  eventSource: EventSource;\n\n  constructor(options: SSESubscriptionOptions);\n\n  unsubscribe(): void;\n}\n\ninterface SSESubscriptionOptions {\n  // Additional options to pass to the constructor of the underlying EventSource instance.\n  eventSourceOptions?: {\n    withCredentials?: boolean;\n    [key: string]: any;\n  };\n\n  // Indicates the subscription should expect keep alive events to be sent by the server.\n  // If an event is not received inside the provided interval, a reconnection attempt will be made.\n  // The provided interval should be greater than the actual frequency at which the server sends\n  // the events to allow for network latency.\n  keepAlive?: {\n    // Defaults to \"keepAlive\";\n    eventType?: string;\n    intervalMs: number;\n  };\n\n  // Called when the connection is terminated by calling unsubscribe.\n  onComplete?: () => void;\n\n  // Called when an error occurs. Note that this callback will be called each time the connection\n  // is lost, so it should not be used to indicate a critical error occurred.\n  onError?: (error: Error) => void;\n\n  // Callback called whenever an event is pushed.\n  onNext?: (type: string, data: string) => void;\n\n  // Any URL query parameters to attach to the URL.\n  searchParams?: {\n    [key: string]: string;\n  };\n\n  // The URL of the endpoint to fetch requests from.\n  url: string;\n}\n```\n\n### Integration with GraphQL Clients\n\n#### Relay\n\n```ts\nimport {\n  Environment,\n  Network,\n  Observable,\n  SubscribeFunction,\n} from \"relay-runtime\";\nimport { SSESubscription } from \"sse-z\";\n\nconst subscribe: SubscribeFunction = (operation, variables) => {\n  return Observable.create((sink) => {\n    return new SSESubscription({\n      url: 'http://localhost:8080/graphql',\n      searchParams: {\n        operationName: operation.name,\n        query: operation.text,\n        variables: JSON.stringify(variables),\n      },\n      eventSourceOptions: {\n        // Ensure cookies are included with the request\n        withCredentials: true,\n      },\n      onNext: (type, data) => {\n        // Note: the actual type may vary by server\n        if (type === 'event') {\n          sink.next(JSON.parse(data));\n        }\n      },\n    });\n  });\n};\n\nconst environment = new Environment({\n  ...\n  network: Network.create(fetchQuery, subscribe),\n});\n```\n\n#### Apollo Client\n\n```ts\nimport { ApolloLink, Operation, FetchResult, Observable } from \"@apollo/client\";\nimport { print } from \"graphql\";\nimport { SSESubscription, SSESubscriptionOptions } from \"sse-z\";\n\nclass SSELink extends ApolloLink {\n  options: SSESubscriptionOptions;\n\n  constructor(options: SSESubscriptionOptions) {\n    super();\n    this.options = options;\n  }\n\n  public request({\n    query,\n    variables,\n    operationName,\n  }: Operation): Observable<FetchResult> {\n    return new Observable((sink) => {\n      const subscription = new SSESubscription({\n        ...options,\n        searchParams: {\n          query: print(operation.query),\n          variables: JSON.stringify(variables),\n          operationName,\n        },\n        onNext: (type, data) => {\n          // Note: the actual type may vary by server\n          if (type === \"event\") {\n            sink.next(JSON.parse(data));\n          }\n        },\n      });\n\n      return () => subscription.unsubscribe();\n    });\n  }\n}\n\nconst link = new SSELink({\n  url: \"http://localhost:8080/graphql\",\n  eventSourceOptions: {\n    // Ensure cookies are included with the request\n    withCredentials: true,\n  },\n});\n```\n","_attachments":{},"homepage":"https://github.com/contrawork/sse-z","bugs":{"url":"https://github.com/contrawork/sse-z/issues"},"license":"MIT"}