serverless-spy 0.0.8 → 0.0.11

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.
Files changed (352) hide show
  1. package/.jsii +17 -14
  2. package/cli/cli.ts +1 -1
  3. package/cli/node_modules/ws/LICENSE +19 -0
  4. package/cli/node_modules/ws/README.md +495 -0
  5. package/cli/node_modules/ws/browser.js +8 -0
  6. package/cli/node_modules/ws/index.js +13 -0
  7. package/cli/node_modules/ws/lib/buffer-util.js +127 -0
  8. package/cli/node_modules/ws/lib/constants.js +12 -0
  9. package/cli/node_modules/ws/lib/event-target.js +266 -0
  10. package/cli/node_modules/ws/lib/extension.js +203 -0
  11. package/cli/node_modules/ws/lib/limiter.js +55 -0
  12. package/cli/node_modules/ws/lib/permessage-deflate.js +511 -0
  13. package/cli/node_modules/ws/lib/receiver.js +618 -0
  14. package/cli/node_modules/ws/lib/sender.js +478 -0
  15. package/cli/node_modules/ws/lib/stream.js +159 -0
  16. package/cli/node_modules/ws/lib/subprotocol.js +62 -0
  17. package/cli/node_modules/ws/lib/validation.js +125 -0
  18. package/cli/node_modules/ws/lib/websocket-server.js +535 -0
  19. package/cli/node_modules/ws/lib/websocket.js +1305 -0
  20. package/cli/node_modules/ws/package.json +61 -0
  21. package/cli/node_modules/ws/wrapper.mjs +8 -0
  22. package/cli/ws.ts +1 -1
  23. package/lib/cjs/cli/cli.d.ts +1 -0
  24. package/lib/cjs/cli/cli.js +87 -0
  25. package/lib/cjs/cli/ws.d.ts +1 -0
  26. package/lib/cjs/cli/ws.js +68 -0
  27. package/lib/cjs/common/getWebSocketUrl.d.ts +2 -0
  28. package/lib/cjs/common/getWebSocketUrl.js +57 -0
  29. package/lib/cjs/index.d.ts +2 -0
  30. package/lib/cjs/index.js +19 -0
  31. package/lib/cjs/listener/PrettifyForDisplay.d.ts +3 -0
  32. package/lib/cjs/listener/PrettifyForDisplay.js +3 -0
  33. package/lib/cjs/listener/RecursivePartial.d.ts +4 -0
  34. package/lib/cjs/listener/RecursivePartial.js +3 -0
  35. package/lib/cjs/listener/SpyHandlers.ts.d.ts +109 -0
  36. package/lib/cjs/listener/SpyHandlers.ts.js +3 -0
  37. package/lib/cjs/listener/SpyListener.d.ts +40 -0
  38. package/lib/cjs/listener/SpyListener.js +3 -0
  39. package/lib/cjs/listener/createServerlessSpyListener.d.ts +13 -0
  40. package/lib/cjs/listener/createServerlessSpyListener.js +167 -0
  41. package/lib/cjs/listener/index.d.ts +2 -0
  42. package/lib/cjs/listener/index.js +19 -0
  43. package/lib/cjs/listener/matchers.d.ts +0 -0
  44. package/lib/cjs/listener/matchers.js +55 -0
  45. package/lib/cjs/listener/setup.d.ts +0 -0
  46. package/lib/cjs/listener/setup.js +21 -0
  47. package/lib/{ServerlessSpy.d.ts → cjs/src/ServerlessSpy.d.ts} +0 -0
  48. package/lib/{ServerlessSpy.js → cjs/src/ServerlessSpy.js} +1 -1
  49. package/lib/{index.d.ts → cjs/src/index.d.ts} +0 -0
  50. package/lib/{index.js → cjs/src/index.js} +0 -0
  51. package/lib/mjs/cli/cli.d.ts +1 -0
  52. package/lib/mjs/cli/cli.js +85 -0
  53. package/lib/mjs/cli/ws.d.ts +1 -0
  54. package/lib/mjs/cli/ws.js +66 -0
  55. package/lib/mjs/common/getWebSocketUrl.d.ts +2 -0
  56. package/lib/mjs/common/getWebSocketUrl.js +53 -0
  57. package/lib/mjs/index.d.ts +2 -0
  58. package/lib/mjs/index.js +3 -0
  59. package/lib/mjs/listener/PrettifyForDisplay.d.ts +3 -0
  60. package/lib/mjs/listener/PrettifyForDisplay.js +2 -0
  61. package/lib/mjs/listener/RecursivePartial.d.ts +4 -0
  62. package/lib/mjs/listener/RecursivePartial.js +2 -0
  63. package/lib/mjs/listener/SpyHandlers.ts.d.ts +109 -0
  64. package/lib/mjs/listener/SpyHandlers.ts.js +2 -0
  65. package/lib/mjs/listener/SpyListener.d.ts +40 -0
  66. package/lib/mjs/listener/SpyListener.js +2 -0
  67. package/lib/mjs/listener/createServerlessSpyListener.d.ts +13 -0
  68. package/lib/mjs/listener/createServerlessSpyListener.js +163 -0
  69. package/lib/mjs/listener/index.d.ts +2 -0
  70. package/lib/mjs/listener/index.js +3 -0
  71. package/lib/mjs/listener/matchers.d.ts +0 -0
  72. package/lib/mjs/listener/matchers.js +55 -0
  73. package/lib/mjs/listener/setup.d.ts +0 -0
  74. package/lib/mjs/listener/setup.js +21 -0
  75. package/lib/mjs/src/ServerlessSpy.d.ts +27 -0
  76. package/lib/mjs/src/ServerlessSpy.js +293 -0
  77. package/lib/mjs/src/index.d.ts +1 -0
  78. package/lib/mjs/src/index.js +2 -0
  79. package/listener/node_modules/ws/LICENSE +19 -0
  80. package/listener/node_modules/ws/README.md +495 -0
  81. package/listener/node_modules/ws/browser.js +8 -0
  82. package/listener/node_modules/ws/index.js +13 -0
  83. package/listener/node_modules/ws/lib/buffer-util.js +127 -0
  84. package/listener/node_modules/ws/lib/constants.js +12 -0
  85. package/listener/node_modules/ws/lib/event-target.js +266 -0
  86. package/listener/node_modules/ws/lib/extension.js +203 -0
  87. package/listener/node_modules/ws/lib/limiter.js +55 -0
  88. package/listener/node_modules/ws/lib/permessage-deflate.js +511 -0
  89. package/listener/node_modules/ws/lib/receiver.js +618 -0
  90. package/listener/node_modules/ws/lib/sender.js +478 -0
  91. package/listener/node_modules/ws/lib/stream.js +159 -0
  92. package/listener/node_modules/ws/lib/subprotocol.js +62 -0
  93. package/listener/node_modules/ws/lib/validation.js +125 -0
  94. package/listener/node_modules/ws/lib/websocket-server.js +535 -0
  95. package/listener/node_modules/ws/lib/websocket.js +1305 -0
  96. package/listener/node_modules/ws/package.json +61 -0
  97. package/listener/node_modules/ws/wrapper.mjs +8 -0
  98. package/node_modules/@aws-crypto/crc32/node_modules/tslib/package.json +1 -5
  99. package/node_modules/@aws-crypto/crc32/package.json +1 -5
  100. package/node_modules/@aws-crypto/crc32c/node_modules/tslib/package.json +1 -5
  101. package/node_modules/@aws-crypto/crc32c/package.json +1 -5
  102. package/node_modules/@aws-crypto/ie11-detection/node_modules/tslib/package.json +1 -5
  103. package/node_modules/@aws-crypto/ie11-detection/package.json +1 -5
  104. package/node_modules/@aws-crypto/sha1-browser/node_modules/tslib/package.json +1 -5
  105. package/node_modules/@aws-crypto/sha1-browser/package.json +1 -5
  106. package/node_modules/@aws-crypto/sha256-browser/node_modules/tslib/package.json +1 -5
  107. package/node_modules/@aws-crypto/sha256-browser/package.json +1 -5
  108. package/node_modules/@aws-crypto/sha256-js/node_modules/tslib/package.json +1 -5
  109. package/node_modules/@aws-crypto/sha256-js/package.json +1 -5
  110. package/node_modules/@aws-crypto/supports-web-crypto/node_modules/tslib/package.json +1 -5
  111. package/node_modules/@aws-crypto/supports-web-crypto/package.json +1 -5
  112. package/node_modules/@aws-crypto/util/node_modules/tslib/package.json +1 -5
  113. package/node_modules/@aws-crypto/util/package.json +1 -5
  114. package/node_modules/@aws-sdk/abort-controller/package.json +1 -5
  115. package/node_modules/@aws-sdk/chunked-blob-reader/package.json +1 -5
  116. package/node_modules/@aws-sdk/chunked-blob-reader-native/package.json +1 -5
  117. package/node_modules/@aws-sdk/client-apigatewaymanagementapi/package.json +1 -5
  118. package/node_modules/@aws-sdk/client-cognito-identity/CHANGELOG.md +8 -0
  119. package/node_modules/@aws-sdk/client-cognito-identity/package.json +3 -7
  120. package/node_modules/@aws-sdk/client-dynamodb/package.json +1 -5
  121. package/node_modules/@aws-sdk/client-eventbridge/package.json +1 -5
  122. package/node_modules/@aws-sdk/client-lambda/package.json +1 -5
  123. package/node_modules/@aws-sdk/client-s3/CHANGELOG.md +8 -0
  124. package/node_modules/@aws-sdk/client-s3/node_modules/entities/package.json +1 -5
  125. package/node_modules/@aws-sdk/client-s3/package.json +2 -6
  126. package/node_modules/@aws-sdk/client-sns/node_modules/entities/package.json +1 -5
  127. package/node_modules/@aws-sdk/client-sns/package.json +1 -5
  128. package/node_modules/@aws-sdk/client-sqs/node_modules/entities/package.json +1 -5
  129. package/node_modules/@aws-sdk/client-sqs/package.json +1 -5
  130. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/abort-controller/package.json +1 -5
  131. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sso/package.json +1 -5
  132. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/client-sts/package.json +1 -5
  133. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/config-resolver/package.json +1 -5
  134. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-env/package.json +1 -5
  135. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-imds/package.json +1 -5
  136. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-ini/package.json +1 -5
  137. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-node/package.json +1 -5
  138. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-process/package.json +1 -5
  139. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-sso/package.json +1 -5
  140. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/credential-provider-web-identity/package.json +1 -5
  141. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/fetch-http-handler/package.json +1 -5
  142. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/hash-node/package.json +1 -5
  143. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/invalid-dependency/package.json +1 -5
  144. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/is-array-buffer/package.json +1 -5
  145. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-content-length/package.json +1 -5
  146. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-host-header/package.json +1 -5
  147. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-logger/package.json +1 -5
  148. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-retry/package.json +1 -5
  149. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-sdk-sts/package.json +1 -5
  150. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-serde/package.json +1 -5
  151. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-signing/package.json +1 -5
  152. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-stack/package.json +1 -5
  153. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/middleware-user-agent/package.json +1 -5
  154. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/node-config-provider/package.json +1 -5
  155. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/node-http-handler/package.json +1 -5
  156. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/property-provider/package.json +1 -5
  157. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/protocol-http/package.json +1 -5
  158. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/querystring-builder/package.json +1 -5
  159. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/querystring-parser/package.json +1 -5
  160. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/service-error-classification/package.json +1 -5
  161. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  162. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/signature-v4/package.json +1 -5
  163. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/smithy-client/package.json +1 -5
  164. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/types/package.json +1 -5
  165. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/url-parser/package.json +1 -5
  166. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-base64-browser/package.json +1 -5
  167. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-base64-node/package.json +1 -5
  168. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-body-length-browser/package.json +1 -5
  169. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-body-length-node/package.json +1 -5
  170. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-buffer-from/package.json +1 -5
  171. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-config-provider/package.json +1 -5
  172. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-hex-encoding/package.json +1 -5
  173. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-uri-escape/package.json +1 -5
  174. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-user-agent-browser/package.json +1 -5
  175. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-user-agent-node/package.json +1 -5
  176. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-utf8-browser/package.json +1 -5
  177. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-utf8-node/package.json +1 -5
  178. package/node_modules/@aws-sdk/client-ssm/node_modules/@aws-sdk/util-waiter/package.json +1 -5
  179. package/node_modules/@aws-sdk/client-ssm/node_modules/entities/package.json +1 -5
  180. package/node_modules/@aws-sdk/client-ssm/package.json +1 -5
  181. package/node_modules/@aws-sdk/client-sso/package.json +1 -5
  182. package/node_modules/@aws-sdk/client-sts/node_modules/entities/package.json +1 -5
  183. package/node_modules/@aws-sdk/client-sts/package.json +1 -5
  184. package/node_modules/@aws-sdk/config-resolver/package.json +1 -5
  185. package/node_modules/@aws-sdk/credential-provider-cognito-identity/CHANGELOG.md +8 -0
  186. package/node_modules/@aws-sdk/credential-provider-cognito-identity/package.json +3 -7
  187. package/node_modules/@aws-sdk/credential-provider-env/package.json +1 -5
  188. package/node_modules/@aws-sdk/credential-provider-imds/package.json +1 -5
  189. package/node_modules/@aws-sdk/credential-provider-ini/package.json +1 -5
  190. package/node_modules/@aws-sdk/credential-provider-node/package.json +1 -5
  191. package/node_modules/@aws-sdk/credential-provider-process/package.json +1 -5
  192. package/node_modules/@aws-sdk/credential-provider-sso/package.json +1 -5
  193. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +1 -5
  194. package/node_modules/@aws-sdk/credential-providers/CHANGELOG.md +8 -0
  195. package/node_modules/@aws-sdk/credential-providers/package.json +4 -8
  196. package/node_modules/@aws-sdk/endpoint-cache/package.json +1 -5
  197. package/node_modules/@aws-sdk/eventstream-codec/package.json +1 -5
  198. package/node_modules/@aws-sdk/eventstream-serde-browser/package.json +1 -5
  199. package/node_modules/@aws-sdk/eventstream-serde-config-resolver/package.json +1 -5
  200. package/node_modules/@aws-sdk/eventstream-serde-node/package.json +1 -5
  201. package/node_modules/@aws-sdk/eventstream-serde-universal/package.json +1 -5
  202. package/node_modules/@aws-sdk/fetch-http-handler/package.json +1 -5
  203. package/node_modules/@aws-sdk/hash-blob-browser/package.json +1 -5
  204. package/node_modules/@aws-sdk/hash-node/package.json +1 -5
  205. package/node_modules/@aws-sdk/hash-stream-node/package.json +1 -5
  206. package/node_modules/@aws-sdk/invalid-dependency/package.json +1 -5
  207. package/node_modules/@aws-sdk/is-array-buffer/package.json +1 -5
  208. package/node_modules/@aws-sdk/lib-dynamodb/package.json +1 -5
  209. package/node_modules/@aws-sdk/md5-js/package.json +1 -5
  210. package/node_modules/@aws-sdk/middleware-bucket-endpoint/package.json +1 -5
  211. package/node_modules/@aws-sdk/middleware-content-length/package.json +1 -5
  212. package/node_modules/@aws-sdk/middleware-endpoint-discovery/package.json +1 -5
  213. package/node_modules/@aws-sdk/middleware-expect-continue/package.json +1 -5
  214. package/node_modules/@aws-sdk/middleware-flexible-checksums/package.json +1 -5
  215. package/node_modules/@aws-sdk/middleware-host-header/package.json +1 -5
  216. package/node_modules/@aws-sdk/middleware-location-constraint/package.json +1 -5
  217. package/node_modules/@aws-sdk/middleware-logger/package.json +1 -5
  218. package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +1 -5
  219. package/node_modules/@aws-sdk/middleware-retry/package.json +1 -5
  220. package/node_modules/@aws-sdk/middleware-sdk-eventbridge/package.json +1 -5
  221. package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +1 -5
  222. package/node_modules/@aws-sdk/middleware-sdk-sqs/package.json +1 -5
  223. package/node_modules/@aws-sdk/middleware-sdk-sts/package.json +1 -5
  224. package/node_modules/@aws-sdk/middleware-serde/package.json +1 -5
  225. package/node_modules/@aws-sdk/middleware-signing/package.json +1 -5
  226. package/node_modules/@aws-sdk/middleware-ssec/package.json +1 -5
  227. package/node_modules/@aws-sdk/middleware-stack/package.json +1 -5
  228. package/node_modules/@aws-sdk/middleware-user-agent/package.json +1 -5
  229. package/node_modules/@aws-sdk/node-config-provider/package.json +1 -5
  230. package/node_modules/@aws-sdk/node-http-handler/package.json +1 -5
  231. package/node_modules/@aws-sdk/property-provider/package.json +1 -5
  232. package/node_modules/@aws-sdk/protocol-http/package.json +1 -5
  233. package/node_modules/@aws-sdk/querystring-builder/package.json +1 -5
  234. package/node_modules/@aws-sdk/querystring-parser/package.json +1 -5
  235. package/node_modules/@aws-sdk/service-error-classification/package.json +1 -5
  236. package/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  237. package/node_modules/@aws-sdk/signature-v4/package.json +1 -5
  238. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -5
  239. package/node_modules/@aws-sdk/smithy-client/package.json +1 -5
  240. package/node_modules/@aws-sdk/types/package.json +1 -5
  241. package/node_modules/@aws-sdk/url-parser/package.json +1 -5
  242. package/node_modules/@aws-sdk/util-arn-parser/package.json +1 -5
  243. package/node_modules/@aws-sdk/util-base64-browser/package.json +1 -5
  244. package/node_modules/@aws-sdk/util-base64-node/package.json +1 -5
  245. package/node_modules/@aws-sdk/util-body-length-browser/package.json +1 -5
  246. package/node_modules/@aws-sdk/util-body-length-node/package.json +1 -5
  247. package/node_modules/@aws-sdk/util-buffer-from/package.json +1 -5
  248. package/node_modules/@aws-sdk/util-config-provider/package.json +1 -5
  249. package/node_modules/@aws-sdk/util-credentials/node_modules/@aws-sdk/shared-ini-file-loader/package.json +1 -5
  250. package/node_modules/@aws-sdk/util-credentials/package.json +1 -5
  251. package/node_modules/@aws-sdk/util-defaults-mode-browser/package.json +1 -5
  252. package/node_modules/@aws-sdk/util-defaults-mode-node/package.json +1 -5
  253. package/node_modules/@aws-sdk/util-dynamodb/package.json +1 -5
  254. package/node_modules/@aws-sdk/util-hex-encoding/package.json +1 -5
  255. package/node_modules/@aws-sdk/util-locate-window/package.json +1 -5
  256. package/node_modules/@aws-sdk/util-middleware/package.json +1 -5
  257. package/node_modules/@aws-sdk/util-stream-browser/package.json +1 -5
  258. package/node_modules/@aws-sdk/util-stream-node/package.json +1 -5
  259. package/node_modules/@aws-sdk/util-uri-escape/package.json +1 -5
  260. package/node_modules/@aws-sdk/util-user-agent-browser/package.json +1 -5
  261. package/node_modules/@aws-sdk/util-user-agent-node/package.json +1 -5
  262. package/node_modules/@aws-sdk/util-utf8-browser/package.json +1 -5
  263. package/node_modules/@aws-sdk/util-utf8-node/package.json +1 -5
  264. package/node_modules/@aws-sdk/util-waiter/package.json +1 -5
  265. package/node_modules/@aws-sdk/xml-builder/package.json +1 -5
  266. package/node_modules/@graphql-tools/merge/package.json +0 -4
  267. package/node_modules/@graphql-tools/schema/package.json +0 -4
  268. package/node_modules/@graphql-tools/utils/package.json +0 -4
  269. package/node_modules/@serverless-stack/node/.turbo/turbo-build.log +1 -1
  270. package/node_modules/@serverless-stack/node/CHANGELOG.md +2 -0
  271. package/node_modules/@serverless-stack/node/package.json +2 -6
  272. package/node_modules/@tsconfig/node14/package.json +1 -5
  273. package/node_modules/available-typed-arrays/package.json +1 -5
  274. package/node_modules/aws-jwt-verify/package.json +1 -5
  275. package/node_modules/aws-lambda/node_modules/argparse/package.json +1 -5
  276. package/node_modules/aws-lambda/node_modules/commander/package.json +1 -5
  277. package/node_modules/aws-lambda/node_modules/js-yaml/package.json +1 -5
  278. package/node_modules/aws-lambda/package.json +1 -5
  279. package/node_modules/aws-sdk/node_modules/uuid/package.json +1 -5
  280. package/node_modules/aws-sdk/package.json +0 -4
  281. package/node_modules/aws4/package.json +1 -5
  282. package/node_modules/base64-js/package.json +1 -5
  283. package/node_modules/bowser/package.json +1 -5
  284. package/node_modules/buffer/package.json +1 -5
  285. package/node_modules/call-bind/package.json +1 -5
  286. package/node_modules/define-properties/package.json +1 -5
  287. package/node_modules/es-abstract/package.json +1 -5
  288. package/node_modules/es-to-primitive/package.json +1 -5
  289. package/node_modules/esprima/package.json +1 -5
  290. package/node_modules/events/package.json +0 -4
  291. package/node_modules/fast-xml-parser/package.json +1 -5
  292. package/node_modules/for-each/package.json +1 -5
  293. package/node_modules/function-bind/package.json +1 -5
  294. package/node_modules/function.prototype.name/package.json +1 -5
  295. package/node_modules/functions-have-names/package.json +1 -5
  296. package/node_modules/get-intrinsic/package.json +1 -5
  297. package/node_modules/get-symbol-description/package.json +1 -5
  298. package/node_modules/glob-to-regexp/package.json +1 -5
  299. package/node_modules/graceful-fs/package.json +1 -5
  300. package/node_modules/graphql/package.json +1 -5
  301. package/node_modules/graphql-helix/package.json +1 -5
  302. package/node_modules/has/package.json +1 -5
  303. package/node_modules/has-bigints/package.json +1 -5
  304. package/node_modules/has-property-descriptors/package.json +1 -5
  305. package/node_modules/has-symbols/package.json +1 -5
  306. package/node_modules/has-tostringtag/package.json +1 -5
  307. package/node_modules/ieee754/package.json +1 -5
  308. package/node_modules/inherits/package.json +1 -5
  309. package/node_modules/internal-slot/package.json +1 -5
  310. package/node_modules/is-arguments/package.json +1 -5
  311. package/node_modules/is-bigint/package.json +1 -5
  312. package/node_modules/is-boolean-object/package.json +1 -5
  313. package/node_modules/is-callable/package.json +1 -5
  314. package/node_modules/is-date-object/package.json +1 -5
  315. package/node_modules/is-generator-function/package.json +1 -5
  316. package/node_modules/is-negative-zero/package.json +1 -5
  317. package/node_modules/is-number-object/package.json +1 -5
  318. package/node_modules/is-regex/package.json +1 -5
  319. package/node_modules/is-shared-array-buffer/package.json +1 -5
  320. package/node_modules/is-string/package.json +1 -5
  321. package/node_modules/is-symbol/package.json +1 -5
  322. package/node_modules/is-typed-array/package.json +1 -5
  323. package/node_modules/is-weakref/package.json +1 -5
  324. package/node_modules/isarray/package.json +1 -5
  325. package/node_modules/jmespath/package.json +1 -5
  326. package/node_modules/mnemonist/package.json +1 -5
  327. package/node_modules/object-inspect/package.json +1 -5
  328. package/node_modules/object-keys/package.json +1 -5
  329. package/node_modules/object.assign/package.json +1 -5
  330. package/node_modules/obliterator/package.json +1 -5
  331. package/node_modules/querystring/package.json +1 -5
  332. package/node_modules/regexp.prototype.flags/package.json +1 -5
  333. package/node_modules/safe-buffer/package.json +1 -5
  334. package/node_modules/sax/package.json +1 -5
  335. package/node_modules/side-channel/package.json +1 -5
  336. package/node_modules/sprintf-js/package.json +1 -5
  337. package/node_modules/string.prototype.trimend/package.json +1 -5
  338. package/node_modules/string.prototype.trimstart/package.json +1 -5
  339. package/node_modules/tslib/package.json +1 -5
  340. package/node_modules/unbox-primitive/package.json +1 -5
  341. package/node_modules/url/node_modules/punycode/package.json +1 -5
  342. package/node_modules/url/package.json +1 -5
  343. package/node_modules/util/package.json +1 -5
  344. package/node_modules/uuid/package.json +1 -5
  345. package/node_modules/value-or-promise/package.json +1 -5
  346. package/node_modules/watchpack/package.json +1 -5
  347. package/node_modules/which-boxed-primitive/package.json +1 -5
  348. package/node_modules/which-typed-array/package.json +1 -5
  349. package/node_modules/xml2js/node_modules/xmlbuilder/package.json +1 -5
  350. package/node_modules/xml2js/package.json +1 -5
  351. package/package.json +35 -27
  352. package/tsconfig.npm.json +50 -0
@@ -0,0 +1,478 @@
1
+ /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls$" }] */
2
+
3
+ 'use strict';
4
+
5
+ const net = require('net');
6
+ const tls = require('tls');
7
+ const { randomFillSync } = require('crypto');
8
+
9
+ const PerMessageDeflate = require('./permessage-deflate');
10
+ const { EMPTY_BUFFER } = require('./constants');
11
+ const { isValidStatusCode } = require('./validation');
12
+ const { mask: applyMask, toBuffer } = require('./buffer-util');
13
+
14
+ const kByteLength = Symbol('kByteLength');
15
+ const maskBuffer = Buffer.alloc(4);
16
+
17
+ /**
18
+ * HyBi Sender implementation.
19
+ */
20
+ class Sender {
21
+ /**
22
+ * Creates a Sender instance.
23
+ *
24
+ * @param {(net.Socket|tls.Socket)} socket The connection socket
25
+ * @param {Object} [extensions] An object containing the negotiated extensions
26
+ * @param {Function} [generateMask] The function used to generate the masking
27
+ * key
28
+ */
29
+ constructor(socket, extensions, generateMask) {
30
+ this._extensions = extensions || {};
31
+
32
+ if (generateMask) {
33
+ this._generateMask = generateMask;
34
+ this._maskBuffer = Buffer.alloc(4);
35
+ }
36
+
37
+ this._socket = socket;
38
+
39
+ this._firstFragment = true;
40
+ this._compress = false;
41
+
42
+ this._bufferedBytes = 0;
43
+ this._deflating = false;
44
+ this._queue = [];
45
+ }
46
+
47
+ /**
48
+ * Frames a piece of data according to the HyBi WebSocket protocol.
49
+ *
50
+ * @param {(Buffer|String)} data The data to frame
51
+ * @param {Object} options Options object
52
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
53
+ * FIN bit
54
+ * @param {Function} [options.generateMask] The function used to generate the
55
+ * masking key
56
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
57
+ * `data`
58
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
59
+ * key
60
+ * @param {Number} options.opcode The opcode
61
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
62
+ * modified
63
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
64
+ * RSV1 bit
65
+ * @return {(Buffer|String)[]} The framed data
66
+ * @public
67
+ */
68
+ static frame(data, options) {
69
+ let mask;
70
+ let merge = false;
71
+ let offset = 2;
72
+ let skipMasking = false;
73
+
74
+ if (options.mask) {
75
+ mask = options.maskBuffer || maskBuffer;
76
+
77
+ if (options.generateMask) {
78
+ options.generateMask(mask);
79
+ } else {
80
+ randomFillSync(mask, 0, 4);
81
+ }
82
+
83
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
84
+ offset = 6;
85
+ }
86
+
87
+ let dataLength;
88
+
89
+ if (typeof data === 'string') {
90
+ if (
91
+ (!options.mask || skipMasking) &&
92
+ options[kByteLength] !== undefined
93
+ ) {
94
+ dataLength = options[kByteLength];
95
+ } else {
96
+ data = Buffer.from(data);
97
+ dataLength = data.length;
98
+ }
99
+ } else {
100
+ dataLength = data.length;
101
+ merge = options.mask && options.readOnly && !skipMasking;
102
+ }
103
+
104
+ let payloadLength = dataLength;
105
+
106
+ if (dataLength >= 65536) {
107
+ offset += 8;
108
+ payloadLength = 127;
109
+ } else if (dataLength > 125) {
110
+ offset += 2;
111
+ payloadLength = 126;
112
+ }
113
+
114
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
115
+
116
+ target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
117
+ if (options.rsv1) target[0] |= 0x40;
118
+
119
+ target[1] = payloadLength;
120
+
121
+ if (payloadLength === 126) {
122
+ target.writeUInt16BE(dataLength, 2);
123
+ } else if (payloadLength === 127) {
124
+ target[2] = target[3] = 0;
125
+ target.writeUIntBE(dataLength, 4, 6);
126
+ }
127
+
128
+ if (!options.mask) return [target, data];
129
+
130
+ target[1] |= 0x80;
131
+ target[offset - 4] = mask[0];
132
+ target[offset - 3] = mask[1];
133
+ target[offset - 2] = mask[2];
134
+ target[offset - 1] = mask[3];
135
+
136
+ if (skipMasking) return [target, data];
137
+
138
+ if (merge) {
139
+ applyMask(data, mask, target, offset, dataLength);
140
+ return [target];
141
+ }
142
+
143
+ applyMask(data, mask, data, 0, dataLength);
144
+ return [target, data];
145
+ }
146
+
147
+ /**
148
+ * Sends a close message to the other peer.
149
+ *
150
+ * @param {Number} [code] The status code component of the body
151
+ * @param {(String|Buffer)} [data] The message component of the body
152
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
153
+ * @param {Function} [cb] Callback
154
+ * @public
155
+ */
156
+ close(code, data, mask, cb) {
157
+ let buf;
158
+
159
+ if (code === undefined) {
160
+ buf = EMPTY_BUFFER;
161
+ } else if (typeof code !== 'number' || !isValidStatusCode(code)) {
162
+ throw new TypeError('First argument must be a valid error code number');
163
+ } else if (data === undefined || !data.length) {
164
+ buf = Buffer.allocUnsafe(2);
165
+ buf.writeUInt16BE(code, 0);
166
+ } else {
167
+ const length = Buffer.byteLength(data);
168
+
169
+ if (length > 123) {
170
+ throw new RangeError('The message must not be greater than 123 bytes');
171
+ }
172
+
173
+ buf = Buffer.allocUnsafe(2 + length);
174
+ buf.writeUInt16BE(code, 0);
175
+
176
+ if (typeof data === 'string') {
177
+ buf.write(data, 2);
178
+ } else {
179
+ buf.set(data, 2);
180
+ }
181
+ }
182
+
183
+ const options = {
184
+ [kByteLength]: buf.length,
185
+ fin: true,
186
+ generateMask: this._generateMask,
187
+ mask,
188
+ maskBuffer: this._maskBuffer,
189
+ opcode: 0x08,
190
+ readOnly: false,
191
+ rsv1: false
192
+ };
193
+
194
+ if (this._deflating) {
195
+ this.enqueue([this.dispatch, buf, false, options, cb]);
196
+ } else {
197
+ this.sendFrame(Sender.frame(buf, options), cb);
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Sends a ping message to the other peer.
203
+ *
204
+ * @param {*} data The message to send
205
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
206
+ * @param {Function} [cb] Callback
207
+ * @public
208
+ */
209
+ ping(data, mask, cb) {
210
+ let byteLength;
211
+ let readOnly;
212
+
213
+ if (typeof data === 'string') {
214
+ byteLength = Buffer.byteLength(data);
215
+ readOnly = false;
216
+ } else {
217
+ data = toBuffer(data);
218
+ byteLength = data.length;
219
+ readOnly = toBuffer.readOnly;
220
+ }
221
+
222
+ if (byteLength > 125) {
223
+ throw new RangeError('The data size must not be greater than 125 bytes');
224
+ }
225
+
226
+ const options = {
227
+ [kByteLength]: byteLength,
228
+ fin: true,
229
+ generateMask: this._generateMask,
230
+ mask,
231
+ maskBuffer: this._maskBuffer,
232
+ opcode: 0x09,
233
+ readOnly,
234
+ rsv1: false
235
+ };
236
+
237
+ if (this._deflating) {
238
+ this.enqueue([this.dispatch, data, false, options, cb]);
239
+ } else {
240
+ this.sendFrame(Sender.frame(data, options), cb);
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Sends a pong message to the other peer.
246
+ *
247
+ * @param {*} data The message to send
248
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
249
+ * @param {Function} [cb] Callback
250
+ * @public
251
+ */
252
+ pong(data, mask, cb) {
253
+ let byteLength;
254
+ let readOnly;
255
+
256
+ if (typeof data === 'string') {
257
+ byteLength = Buffer.byteLength(data);
258
+ readOnly = false;
259
+ } else {
260
+ data = toBuffer(data);
261
+ byteLength = data.length;
262
+ readOnly = toBuffer.readOnly;
263
+ }
264
+
265
+ if (byteLength > 125) {
266
+ throw new RangeError('The data size must not be greater than 125 bytes');
267
+ }
268
+
269
+ const options = {
270
+ [kByteLength]: byteLength,
271
+ fin: true,
272
+ generateMask: this._generateMask,
273
+ mask,
274
+ maskBuffer: this._maskBuffer,
275
+ opcode: 0x0a,
276
+ readOnly,
277
+ rsv1: false
278
+ };
279
+
280
+ if (this._deflating) {
281
+ this.enqueue([this.dispatch, data, false, options, cb]);
282
+ } else {
283
+ this.sendFrame(Sender.frame(data, options), cb);
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Sends a data message to the other peer.
289
+ *
290
+ * @param {*} data The message to send
291
+ * @param {Object} options Options object
292
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
293
+ * or text
294
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
295
+ * compress `data`
296
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
297
+ * last one
298
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
299
+ * `data`
300
+ * @param {Function} [cb] Callback
301
+ * @public
302
+ */
303
+ send(data, options, cb) {
304
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
305
+ let opcode = options.binary ? 2 : 1;
306
+ let rsv1 = options.compress;
307
+
308
+ let byteLength;
309
+ let readOnly;
310
+
311
+ if (typeof data === 'string') {
312
+ byteLength = Buffer.byteLength(data);
313
+ readOnly = false;
314
+ } else {
315
+ data = toBuffer(data);
316
+ byteLength = data.length;
317
+ readOnly = toBuffer.readOnly;
318
+ }
319
+
320
+ if (this._firstFragment) {
321
+ this._firstFragment = false;
322
+ if (
323
+ rsv1 &&
324
+ perMessageDeflate &&
325
+ perMessageDeflate.params[
326
+ perMessageDeflate._isServer
327
+ ? 'server_no_context_takeover'
328
+ : 'client_no_context_takeover'
329
+ ]
330
+ ) {
331
+ rsv1 = byteLength >= perMessageDeflate._threshold;
332
+ }
333
+ this._compress = rsv1;
334
+ } else {
335
+ rsv1 = false;
336
+ opcode = 0;
337
+ }
338
+
339
+ if (options.fin) this._firstFragment = true;
340
+
341
+ if (perMessageDeflate) {
342
+ const opts = {
343
+ [kByteLength]: byteLength,
344
+ fin: options.fin,
345
+ generateMask: this._generateMask,
346
+ mask: options.mask,
347
+ maskBuffer: this._maskBuffer,
348
+ opcode,
349
+ readOnly,
350
+ rsv1
351
+ };
352
+
353
+ if (this._deflating) {
354
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
355
+ } else {
356
+ this.dispatch(data, this._compress, opts, cb);
357
+ }
358
+ } else {
359
+ this.sendFrame(
360
+ Sender.frame(data, {
361
+ [kByteLength]: byteLength,
362
+ fin: options.fin,
363
+ generateMask: this._generateMask,
364
+ mask: options.mask,
365
+ maskBuffer: this._maskBuffer,
366
+ opcode,
367
+ readOnly,
368
+ rsv1: false
369
+ }),
370
+ cb
371
+ );
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Dispatches a message.
377
+ *
378
+ * @param {(Buffer|String)} data The message to send
379
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
380
+ * `data`
381
+ * @param {Object} options Options object
382
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
383
+ * FIN bit
384
+ * @param {Function} [options.generateMask] The function used to generate the
385
+ * masking key
386
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
387
+ * `data`
388
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
389
+ * key
390
+ * @param {Number} options.opcode The opcode
391
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
392
+ * modified
393
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
394
+ * RSV1 bit
395
+ * @param {Function} [cb] Callback
396
+ * @private
397
+ */
398
+ dispatch(data, compress, options, cb) {
399
+ if (!compress) {
400
+ this.sendFrame(Sender.frame(data, options), cb);
401
+ return;
402
+ }
403
+
404
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
405
+
406
+ this._bufferedBytes += options[kByteLength];
407
+ this._deflating = true;
408
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
409
+ if (this._socket.destroyed) {
410
+ const err = new Error(
411
+ 'The socket was closed while data was being compressed'
412
+ );
413
+
414
+ if (typeof cb === 'function') cb(err);
415
+
416
+ for (let i = 0; i < this._queue.length; i++) {
417
+ const params = this._queue[i];
418
+ const callback = params[params.length - 1];
419
+
420
+ if (typeof callback === 'function') callback(err);
421
+ }
422
+
423
+ return;
424
+ }
425
+
426
+ this._bufferedBytes -= options[kByteLength];
427
+ this._deflating = false;
428
+ options.readOnly = false;
429
+ this.sendFrame(Sender.frame(buf, options), cb);
430
+ this.dequeue();
431
+ });
432
+ }
433
+
434
+ /**
435
+ * Executes queued send operations.
436
+ *
437
+ * @private
438
+ */
439
+ dequeue() {
440
+ while (!this._deflating && this._queue.length) {
441
+ const params = this._queue.shift();
442
+
443
+ this._bufferedBytes -= params[3][kByteLength];
444
+ Reflect.apply(params[0], this, params.slice(1));
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Enqueues a send operation.
450
+ *
451
+ * @param {Array} params Send operation parameters.
452
+ * @private
453
+ */
454
+ enqueue(params) {
455
+ this._bufferedBytes += params[3][kByteLength];
456
+ this._queue.push(params);
457
+ }
458
+
459
+ /**
460
+ * Sends a frame.
461
+ *
462
+ * @param {Buffer[]} list The frame to send
463
+ * @param {Function} [cb] Callback
464
+ * @private
465
+ */
466
+ sendFrame(list, cb) {
467
+ if (list.length === 2) {
468
+ this._socket.cork();
469
+ this._socket.write(list[0]);
470
+ this._socket.write(list[1], cb);
471
+ this._socket.uncork();
472
+ } else {
473
+ this._socket.write(list[0], cb);
474
+ }
475
+ }
476
+ }
477
+
478
+ module.exports = Sender;
@@ -0,0 +1,159 @@
1
+ 'use strict';
2
+
3
+ const { Duplex } = require('stream');
4
+
5
+ /**
6
+ * Emits the `'close'` event on a stream.
7
+ *
8
+ * @param {Duplex} stream The stream.
9
+ * @private
10
+ */
11
+ function emitClose(stream) {
12
+ stream.emit('close');
13
+ }
14
+
15
+ /**
16
+ * The listener of the `'end'` event.
17
+ *
18
+ * @private
19
+ */
20
+ function duplexOnEnd() {
21
+ if (!this.destroyed && this._writableState.finished) {
22
+ this.destroy();
23
+ }
24
+ }
25
+
26
+ /**
27
+ * The listener of the `'error'` event.
28
+ *
29
+ * @param {Error} err The error
30
+ * @private
31
+ */
32
+ function duplexOnError(err) {
33
+ this.removeListener('error', duplexOnError);
34
+ this.destroy();
35
+ if (this.listenerCount('error') === 0) {
36
+ // Do not suppress the throwing behavior.
37
+ this.emit('error', err);
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Wraps a `WebSocket` in a duplex stream.
43
+ *
44
+ * @param {WebSocket} ws The `WebSocket` to wrap
45
+ * @param {Object} [options] The options for the `Duplex` constructor
46
+ * @return {Duplex} The duplex stream
47
+ * @public
48
+ */
49
+ function createWebSocketStream(ws, options) {
50
+ let terminateOnDestroy = true;
51
+
52
+ const duplex = new Duplex({
53
+ ...options,
54
+ autoDestroy: false,
55
+ emitClose: false,
56
+ objectMode: false,
57
+ writableObjectMode: false
58
+ });
59
+
60
+ ws.on('message', function message(msg, isBinary) {
61
+ const data =
62
+ !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
63
+
64
+ if (!duplex.push(data)) ws.pause();
65
+ });
66
+
67
+ ws.once('error', function error(err) {
68
+ if (duplex.destroyed) return;
69
+
70
+ // Prevent `ws.terminate()` from being called by `duplex._destroy()`.
71
+ //
72
+ // - If the `'error'` event is emitted before the `'open'` event, then
73
+ // `ws.terminate()` is a noop as no socket is assigned.
74
+ // - Otherwise, the error is re-emitted by the listener of the `'error'`
75
+ // event of the `Receiver` object. The listener already closes the
76
+ // connection by calling `ws.close()`. This allows a close frame to be
77
+ // sent to the other peer. If `ws.terminate()` is called right after this,
78
+ // then the close frame might not be sent.
79
+ terminateOnDestroy = false;
80
+ duplex.destroy(err);
81
+ });
82
+
83
+ ws.once('close', function close() {
84
+ if (duplex.destroyed) return;
85
+
86
+ duplex.push(null);
87
+ });
88
+
89
+ duplex._destroy = function (err, callback) {
90
+ if (ws.readyState === ws.CLOSED) {
91
+ callback(err);
92
+ process.nextTick(emitClose, duplex);
93
+ return;
94
+ }
95
+
96
+ let called = false;
97
+
98
+ ws.once('error', function error(err) {
99
+ called = true;
100
+ callback(err);
101
+ });
102
+
103
+ ws.once('close', function close() {
104
+ if (!called) callback(err);
105
+ process.nextTick(emitClose, duplex);
106
+ });
107
+
108
+ if (terminateOnDestroy) ws.terminate();
109
+ };
110
+
111
+ duplex._final = function (callback) {
112
+ if (ws.readyState === ws.CONNECTING) {
113
+ ws.once('open', function open() {
114
+ duplex._final(callback);
115
+ });
116
+ return;
117
+ }
118
+
119
+ // If the value of the `_socket` property is `null` it means that `ws` is a
120
+ // client websocket and the handshake failed. In fact, when this happens, a
121
+ // socket is never assigned to the websocket. Wait for the `'error'` event
122
+ // that will be emitted by the websocket.
123
+ if (ws._socket === null) return;
124
+
125
+ if (ws._socket._writableState.finished) {
126
+ callback();
127
+ if (duplex._readableState.endEmitted) duplex.destroy();
128
+ } else {
129
+ ws._socket.once('finish', function finish() {
130
+ // `duplex` is not destroyed here because the `'end'` event will be
131
+ // emitted on `duplex` after this `'finish'` event. The EOF signaling
132
+ // `null` chunk is, in fact, pushed when the websocket emits `'close'`.
133
+ callback();
134
+ });
135
+ ws.close();
136
+ }
137
+ };
138
+
139
+ duplex._read = function () {
140
+ if (ws.isPaused) ws.resume();
141
+ };
142
+
143
+ duplex._write = function (chunk, encoding, callback) {
144
+ if (ws.readyState === ws.CONNECTING) {
145
+ ws.once('open', function open() {
146
+ duplex._write(chunk, encoding, callback);
147
+ });
148
+ return;
149
+ }
150
+
151
+ ws.send(chunk, callback);
152
+ };
153
+
154
+ duplex.on('end', duplexOnEnd);
155
+ duplex.on('error', duplexOnError);
156
+ return duplex;
157
+ }
158
+
159
+ module.exports = createWebSocketStream;
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const { tokenChars } = require('./validation');
4
+
5
+ /**
6
+ * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
7
+ *
8
+ * @param {String} header The field value of the header
9
+ * @return {Set} The subprotocol names
10
+ * @public
11
+ */
12
+ function parse(header) {
13
+ const protocols = new Set();
14
+ let start = -1;
15
+ let end = -1;
16
+ let i = 0;
17
+
18
+ for (i; i < header.length; i++) {
19
+ const code = header.charCodeAt(i);
20
+
21
+ if (end === -1 && tokenChars[code] === 1) {
22
+ if (start === -1) start = i;
23
+ } else if (
24
+ i !== 0 &&
25
+ (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
26
+ ) {
27
+ if (end === -1 && start !== -1) end = i;
28
+ } else if (code === 0x2c /* ',' */) {
29
+ if (start === -1) {
30
+ throw new SyntaxError(`Unexpected character at index ${i}`);
31
+ }
32
+
33
+ if (end === -1) end = i;
34
+
35
+ const protocol = header.slice(start, end);
36
+
37
+ if (protocols.has(protocol)) {
38
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
39
+ }
40
+
41
+ protocols.add(protocol);
42
+ start = end = -1;
43
+ } else {
44
+ throw new SyntaxError(`Unexpected character at index ${i}`);
45
+ }
46
+ }
47
+
48
+ if (start === -1 || end !== -1) {
49
+ throw new SyntaxError('Unexpected end of input');
50
+ }
51
+
52
+ const protocol = header.slice(start, i);
53
+
54
+ if (protocols.has(protocol)) {
55
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
56
+ }
57
+
58
+ protocols.add(protocol);
59
+ return protocols;
60
+ }
61
+
62
+ module.exports = { parse };