ai 1.0.0 → 2.0.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.
Files changed (340) hide show
  1. package/LICENSE +10 -24
  2. package/dist/ai-stream.d.ts +18 -0
  3. package/dist/ai-stream.js +132 -0
  4. package/dist/ai-stream.mjs +13 -0
  5. package/dist/anthropic-stream.d.ts +5 -0
  6. package/dist/anthropic-stream.js +133 -0
  7. package/dist/anthropic-stream.mjs +8 -0
  8. package/dist/chunk-265FSSO4.mjs +91 -0
  9. package/dist/chunk-2L3ZO4UM.mjs +45 -0
  10. package/dist/chunk-EZJ7FC5E.mjs +33 -0
  11. package/dist/chunk-JGDC3BXD.mjs +22 -0
  12. package/dist/chunk-NK2CVBLI.mjs +38 -0
  13. package/dist/chunk-PEYAHBDF.mjs +43 -0
  14. package/dist/chunk-TJMME6CL.mjs +24 -0
  15. package/dist/huggingface-stream.d.ts +5 -0
  16. package/dist/huggingface-stream.js +121 -0
  17. package/dist/huggingface-stream.mjs +8 -0
  18. package/dist/index.d.ts +131 -0
  19. package/dist/index.js +278 -0
  20. package/dist/index.mjs +35 -0
  21. package/dist/index.test.d.ts +2 -0
  22. package/dist/index.test.js +12 -0
  23. package/dist/index.test.mjs +10 -0
  24. package/dist/langchain-stream.d.ts +12 -0
  25. package/dist/langchain-stream.js +102 -0
  26. package/dist/langchain-stream.mjs +8 -0
  27. package/dist/openai-stream.d.ts +5 -0
  28. package/dist/openai-stream.js +144 -0
  29. package/dist/openai-stream.mjs +8 -0
  30. package/dist/streaming-text-response.d.ts +17 -0
  31. package/dist/streaming-text-response.js +75 -0
  32. package/dist/streaming-text-response.mjs +9 -0
  33. package/package.json +78 -29
  34. package/react/dist/chunk-5PP6W52J.mjs +202 -0
  35. package/react/dist/chunk-6EH3SWMP.mjs +55 -0
  36. package/react/dist/chunk-PW6HSU2N.mjs +154 -0
  37. package/react/dist/index.d.ts +3 -0
  38. package/react/dist/index.js +424 -0
  39. package/react/dist/index.mjs +12 -0
  40. package/react/dist/types-f862f74a.d.ts +123 -0
  41. package/react/dist/use-chat.d.ts +42 -0
  42. package/react/dist/use-chat.js +276 -0
  43. package/react/dist/use-chat.mjs +8 -0
  44. package/react/dist/use-completion.d.ts +47 -0
  45. package/react/dist/use-completion.js +229 -0
  46. package/react/dist/use-completion.mjs +8 -0
  47. package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
  48. package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
  49. package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
  50. package/svelte/dist/index.d.ts +4 -0
  51. package/svelte/dist/index.js +808 -0
  52. package/svelte/dist/index.mjs +11 -0
  53. package/svelte/dist/types-f862f74a.d.ts +123 -0
  54. package/svelte/dist/use-chat.d.ts +39 -0
  55. package/svelte/dist/use-chat.js +680 -0
  56. package/svelte/dist/use-chat.mjs +7 -0
  57. package/svelte/dist/use-completion.d.ts +38 -0
  58. package/svelte/dist/use-completion.js +640 -0
  59. package/svelte/dist/use-completion.mjs +7 -0
  60. package/.npmignore +0 -15
  61. package/.travis.yml +0 -4
  62. package/README.md +0 -21
  63. package/bin/ai.js +0 -22
  64. package/index.js +0 -32
  65. package/node_modules/request/.npmignore +0 -2
  66. package/node_modules/request/.travis.yml +0 -12
  67. package/node_modules/request/CHANGELOG.md +0 -954
  68. package/node_modules/request/LICENSE +0 -55
  69. package/node_modules/request/README.md +0 -421
  70. package/node_modules/request/index.js +0 -166
  71. package/node_modules/request/lib/cookies.js +0 -40
  72. package/node_modules/request/lib/copy.js +0 -8
  73. package/node_modules/request/lib/debug.js +0 -7
  74. package/node_modules/request/lib/getSafe.js +0 -34
  75. package/node_modules/request/lib/optional.js +0 -5
  76. package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
  77. package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
  78. package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
  79. package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
  80. package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
  81. package/node_modules/request/node_modules/forever-agent/README.md +0 -4
  82. package/node_modules/request/node_modules/forever-agent/index.js +0 -119
  83. package/node_modules/request/node_modules/forever-agent/package.json +0 -46
  84. package/node_modules/request/node_modules/form-data/License +0 -19
  85. package/node_modules/request/node_modules/form-data/Readme.md +0 -175
  86. package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
  87. package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
  88. package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
  89. package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
  90. package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
  91. package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
  92. package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
  93. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
  94. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
  95. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
  96. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
  97. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
  98. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
  99. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
  100. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
  101. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
  102. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
  103. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-http-upload.js +0 -38
  104. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-auto-pause.js +0 -21
  105. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream-pause.js +0 -14
  106. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
  107. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-handle-source-errors.js +0 -15
  108. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-max-data-size.js +0 -18
  109. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
  110. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
  111. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
  112. package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
  113. package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
  114. package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
  115. package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
  116. package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
  117. package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
  118. package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
  119. package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
  120. package/node_modules/request/node_modules/form-data/package.json +0 -80
  121. package/node_modules/request/node_modules/hawk/.npmignore +0 -18
  122. package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
  123. package/node_modules/request/node_modules/hawk/LICENSE +0 -24
  124. package/node_modules/request/node_modules/hawk/Makefile +0 -10
  125. package/node_modules/request/node_modules/hawk/README.md +0 -625
  126. package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
  127. package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
  128. package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
  129. package/node_modules/request/node_modules/hawk/index.js +0 -1
  130. package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
  131. package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
  132. package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
  133. package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
  134. package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
  135. package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
  136. package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
  137. package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
  138. package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
  139. package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
  140. package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
  141. package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
  142. package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
  143. package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
  144. package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
  145. package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
  146. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
  147. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
  148. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
  149. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
  150. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
  151. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
  152. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
  153. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
  154. package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
  155. package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
  156. package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
  157. package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
  158. package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
  159. package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
  160. package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
  161. package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
  162. package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
  163. package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
  164. package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
  165. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
  166. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
  167. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
  168. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
  169. package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
  170. package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
  171. package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
  172. package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
  173. package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
  174. package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
  175. package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
  176. package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
  177. package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
  178. package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
  179. package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
  180. package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
  181. package/node_modules/request/node_modules/hawk/package.json +0 -70
  182. package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
  183. package/node_modules/request/node_modules/hawk/test/client.js +0 -206
  184. package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
  185. package/node_modules/request/node_modules/hawk/test/index.js +0 -316
  186. package/node_modules/request/node_modules/hawk/test/message.js +0 -246
  187. package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
  188. package/node_modules/request/node_modules/hawk/test/server.js +0 -686
  189. package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
  190. package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
  191. package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
  192. package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
  193. package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
  194. package/node_modules/request/node_modules/http-signature/README.md +0 -75
  195. package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
  196. package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
  197. package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
  198. package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
  199. package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
  200. package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
  201. package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
  202. package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
  203. package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
  204. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
  205. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
  206. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
  207. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
  208. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
  209. package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
  210. package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
  211. package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
  212. package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
  213. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
  214. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
  215. package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
  216. package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
  217. package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
  218. package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
  219. package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
  220. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
  221. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
  222. package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
  223. package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
  224. package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
  225. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
  226. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
  227. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
  228. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
  229. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
  230. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
  231. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
  232. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
  233. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
  234. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
  235. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
  236. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
  237. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
  238. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
  239. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
  240. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
  241. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
  242. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
  243. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
  244. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
  245. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
  246. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
  247. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
  248. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
  249. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
  250. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
  251. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
  252. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
  253. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
  254. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
  255. package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
  256. package/node_modules/request/node_modules/http-signature/package.json +0 -54
  257. package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
  258. package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
  259. package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
  260. package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
  261. package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
  262. package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
  263. package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
  264. package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
  265. package/node_modules/request/node_modules/mime-types/Makefile +0 -9
  266. package/node_modules/request/node_modules/mime-types/README.md +0 -101
  267. package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
  268. package/node_modules/request/node_modules/mime-types/component.json +0 -16
  269. package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
  270. package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
  271. package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
  272. package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
  273. package/node_modules/request/node_modules/mime-types/package.json +0 -69
  274. package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
  275. package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
  276. package/node_modules/request/node_modules/node-uuid/README.md +0 -207
  277. package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
  278. package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
  279. package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
  280. package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
  281. package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
  282. package/node_modules/request/node_modules/node-uuid/component.json +0 -18
  283. package/node_modules/request/node_modules/node-uuid/package.json +0 -54
  284. package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
  285. package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
  286. package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
  287. package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
  288. package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
  289. package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
  290. package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
  291. package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
  292. package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
  293. package/node_modules/request/node_modules/qs/.jshintignore +0 -1
  294. package/node_modules/request/node_modules/qs/.jshintrc +0 -10
  295. package/node_modules/request/node_modules/qs/.npmignore +0 -18
  296. package/node_modules/request/node_modules/qs/.travis.yml +0 -4
  297. package/node_modules/request/node_modules/qs/LICENSE +0 -28
  298. package/node_modules/request/node_modules/qs/Makefile +0 -8
  299. package/node_modules/request/node_modules/qs/Readme.md +0 -120
  300. package/node_modules/request/node_modules/qs/index.js +0 -1
  301. package/node_modules/request/node_modules/qs/lib/index.js +0 -15
  302. package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
  303. package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
  304. package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
  305. package/node_modules/request/node_modules/qs/package.json +0 -61
  306. package/node_modules/request/node_modules/qs/test/parse.js +0 -236
  307. package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
  308. package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
  309. package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
  310. package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
  311. package/node_modules/request/node_modules/stringstream/README.md +0 -38
  312. package/node_modules/request/node_modules/stringstream/example.js +0 -27
  313. package/node_modules/request/node_modules/stringstream/package.json +0 -48
  314. package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
  315. package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
  316. package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
  317. package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
  318. package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
  319. package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
  320. package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
  321. package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
  322. package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
  323. package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
  324. package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
  325. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
  326. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
  327. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
  328. package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
  329. package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
  330. package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
  331. package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
  332. package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
  333. package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
  334. package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
  335. package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
  336. package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
  337. package/node_modules/request/package.json +0 -77
  338. package/node_modules/request/request.js +0 -1428
  339. package/test/fixtures/github-response.json +0 -1367
  340. package/test/index.js +0 -55
@@ -1,1107 +0,0 @@
1
- /*
2
- * Copyright GoInstant, Inc. and other contributors. All rights reserved.
3
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4
- * of this software and associated documentation files (the "Software"), to
5
- * deal in the Software without restriction, including without limitation the
6
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
- * sell copies of the Software, and to permit persons to whom the Software is
8
- * furnished to do so, subject to the following conditions:
9
- *
10
- * The above copyright notice and this permission notice shall be included in
11
- * all copies or substantial portions of the Software.
12
- *
13
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
- * IN THE SOFTWARE.
20
- */
21
-
22
- 'use strict';
23
- var net = require('net');
24
- var urlParse = require('url').parse;
25
- var pubsuffix = require('./pubsuffix');
26
- var Store = require('./store').Store;
27
-
28
- var punycode;
29
- try {
30
- punycode = require('punycode');
31
- } catch(e) {
32
- console.warn("cookie: can't load punycode; won't use punycode for domain normalization");
33
- }
34
-
35
- var DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/;
36
-
37
- // From RFC2616 S2.2:
38
- var TOKEN = /[\x21\x23-\x26\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]/;
39
-
40
- // From RFC6265 S4.1.1
41
- // note that it excludes \x3B ";"
42
- var COOKIE_OCTET = /[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]/;
43
- var COOKIE_OCTETS = new RegExp('^'+COOKIE_OCTET.source+'$');
44
-
45
- // The name/key cannot be empty but the value can (S5.2):
46
- var COOKIE_PAIR_STRICT = new RegExp('^('+TOKEN.source+'+)=("?)('+COOKIE_OCTET.source+'*)\\2$');
47
- var COOKIE_PAIR = /^([^=\s]+)\s*=\s*("?)\s*(.*)\s*\2\s*$/;
48
-
49
- // RFC6265 S4.1.1 defines extension-av as 'any CHAR except CTLs or ";"'
50
- // Note ';' is \x3B
51
- var NON_CTL_SEMICOLON = /[\x20-\x3A\x3C-\x7E]+/;
52
- var EXTENSION_AV = NON_CTL_SEMICOLON;
53
- var PATH_VALUE = NON_CTL_SEMICOLON;
54
-
55
- // Used for checking whether or not there is a trailing semi-colon
56
- var TRAILING_SEMICOLON = /;+$/;
57
-
58
- /* RFC6265 S5.1.1.5:
59
- * [fail if] the day-of-month-value is less than 1 or greater than 31
60
- */
61
- var DAY_OF_MONTH = /^(0?[1-9]|[12][0-9]|3[01])$/;
62
-
63
- /* RFC6265 S5.1.1.5:
64
- * [fail if]
65
- * * the hour-value is greater than 23,
66
- * * the minute-value is greater than 59, or
67
- * * the second-value is greater than 59.
68
- */
69
- var TIME = /(0?[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/;
70
- var STRICT_TIME = /^(0?[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
71
-
72
- var MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/i;
73
- var MONTH_TO_NUM = {
74
- jan:0, feb:1, mar:2, apr:3, may:4, jun:5,
75
- jul:6, aug:7, sep:8, oct:9, nov:10, dec:11
76
- };
77
- var NUM_TO_MONTH = [
78
- 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'
79
- ];
80
- var NUM_TO_DAY = [
81
- 'Sun','Mon','Tue','Wed','Thu','Fri','Sat'
82
- ];
83
-
84
- var YEAR = /^([1-9][0-9]{1,3})$/; // 2 to 4 digits
85
-
86
- var MAX_TIME = 2147483647000; // 31-bit max
87
- var MIN_TIME = 0; // 31-bit min
88
-
89
-
90
- // RFC6265 S5.1.1 date parser:
91
- function parseDate(str,strict) {
92
- if (!str) {
93
- return;
94
- }
95
- var found_time, found_dom, found_month, found_year;
96
-
97
- /* RFC6265 S5.1.1:
98
- * 2. Process each date-token sequentially in the order the date-tokens
99
- * appear in the cookie-date
100
- */
101
- var tokens = str.split(DATE_DELIM);
102
- if (!tokens) {
103
- return;
104
- }
105
-
106
- var date = new Date();
107
- date.setMilliseconds(0);
108
-
109
- for (var i=0; i<tokens.length; i++) {
110
- var token = tokens[i].trim();
111
- if (!token.length) {
112
- continue;
113
- }
114
-
115
- var result;
116
-
117
- /* 2.1. If the found-time flag is not set and the token matches the time
118
- * production, set the found-time flag and set the hour- value,
119
- * minute-value, and second-value to the numbers denoted by the digits in
120
- * the date-token, respectively. Skip the remaining sub-steps and continue
121
- * to the next date-token.
122
- */
123
- if (!found_time) {
124
- result = (strict ? STRICT_TIME : TIME).exec(token);
125
- if (result) {
126
- found_time = true;
127
- date.setUTCHours(result[1]);
128
- date.setUTCMinutes(result[2]);
129
- date.setUTCSeconds(result[3]);
130
- continue;
131
- }
132
- }
133
-
134
- /* 2.2. If the found-day-of-month flag is not set and the date-token matches
135
- * the day-of-month production, set the found-day-of- month flag and set
136
- * the day-of-month-value to the number denoted by the date-token. Skip
137
- * the remaining sub-steps and continue to the next date-token.
138
- */
139
- if (!found_dom) {
140
- result = DAY_OF_MONTH.exec(token);
141
- if (result) {
142
- found_dom = true;
143
- date.setUTCDate(result[1]);
144
- continue;
145
- }
146
- }
147
-
148
- /* 2.3. If the found-month flag is not set and the date-token matches the
149
- * month production, set the found-month flag and set the month-value to
150
- * the month denoted by the date-token. Skip the remaining sub-steps and
151
- * continue to the next date-token.
152
- */
153
- if (!found_month) {
154
- result = MONTH.exec(token);
155
- if (result) {
156
- found_month = true;
157
- date.setUTCMonth(MONTH_TO_NUM[result[1].toLowerCase()]);
158
- continue;
159
- }
160
- }
161
-
162
- /* 2.4. If the found-year flag is not set and the date-token matches the year
163
- * production, set the found-year flag and set the year-value to the number
164
- * denoted by the date-token. Skip the remaining sub-steps and continue to
165
- * the next date-token.
166
- */
167
- if (!found_year) {
168
- result = YEAR.exec(token);
169
- if (result) {
170
- var year = result[0];
171
- /* From S5.1.1:
172
- * 3. If the year-value is greater than or equal to 70 and less
173
- * than or equal to 99, increment the year-value by 1900.
174
- * 4. If the year-value is greater than or equal to 0 and less
175
- * than or equal to 69, increment the year-value by 2000.
176
- */
177
- if (70 <= year && year <= 99) {
178
- year += 1900;
179
- } else if (0 <= year && year <= 69) {
180
- year += 2000;
181
- }
182
-
183
- if (year < 1601) {
184
- return; // 5. ... the year-value is less than 1601
185
- }
186
-
187
- found_year = true;
188
- date.setUTCFullYear(year);
189
- continue;
190
- }
191
- }
192
- }
193
-
194
- if (!(found_time && found_dom && found_month && found_year)) {
195
- return; // 5. ... at least one of the found-day-of-month, found-month, found-
196
- // year, or found-time flags is not set,
197
- }
198
-
199
- return date;
200
- }
201
-
202
- function formatDate(date) {
203
- var d = date.getUTCDate(); d = d >= 10 ? d : '0'+d;
204
- var h = date.getUTCHours(); h = h >= 10 ? h : '0'+h;
205
- var m = date.getUTCMinutes(); m = m >= 10 ? m : '0'+m;
206
- var s = date.getUTCSeconds(); s = s >= 10 ? s : '0'+s;
207
- return NUM_TO_DAY[date.getUTCDay()] + ', ' +
208
- d+' '+ NUM_TO_MONTH[date.getUTCMonth()] +' '+ date.getUTCFullYear() +' '+
209
- h+':'+m+':'+s+' GMT';
210
- }
211
-
212
- // S5.1.2 Canonicalized Host Names
213
- function canonicalDomain(str) {
214
- if (str == null) {
215
- return null;
216
- }
217
- str = str.trim().replace(/^\./,''); // S4.1.2.3 & S5.2.3: ignore leading .
218
-
219
- // convert to IDN if any non-ASCII characters
220
- if (punycode && /[^\u0001-\u007f]/.test(str)) {
221
- str = punycode.toASCII(str);
222
- }
223
-
224
- return str.toLowerCase();
225
- }
226
-
227
- // S5.1.3 Domain Matching
228
- function domainMatch(str, domStr, canonicalize) {
229
- if (str == null || domStr == null) {
230
- return null;
231
- }
232
- if (canonicalize !== false) {
233
- str = canonicalDomain(str);
234
- domStr = canonicalDomain(domStr);
235
- }
236
-
237
- /*
238
- * "The domain string and the string are identical. (Note that both the
239
- * domain string and the string will have been canonicalized to lower case at
240
- * this point)"
241
- */
242
- if (str == domStr) {
243
- return true;
244
- }
245
-
246
- /* "All of the following [three] conditions hold:" (order adjusted from the RFC) */
247
-
248
- /* "* The string is a host name (i.e., not an IP address)." */
249
- if (net.isIP(str)) {
250
- return false;
251
- }
252
-
253
- /* "* The domain string is a suffix of the string" */
254
- var idx = str.indexOf(domStr);
255
- if (idx <= 0) {
256
- return false; // it's a non-match (-1) or prefix (0)
257
- }
258
-
259
- // e.g "a.b.c".indexOf("b.c") === 2
260
- // 5 === 3+2
261
- if (str.length !== domStr.length + idx) { // it's not a suffix
262
- return false;
263
- }
264
-
265
- /* "* The last character of the string that is not included in the domain
266
- * string is a %x2E (".") character." */
267
- if (str.substr(idx-1,1) !== '.') {
268
- return false;
269
- }
270
-
271
- return true;
272
- }
273
-
274
-
275
- // RFC6265 S5.1.4 Paths and Path-Match
276
-
277
- /*
278
- * "The user agent MUST use an algorithm equivalent to the following algorithm
279
- * to compute the default-path of a cookie:"
280
- *
281
- * Assumption: the path (and not query part or absolute uri) is passed in.
282
- */
283
- function defaultPath(path) {
284
- // "2. If the uri-path is empty or if the first character of the uri-path is not
285
- // a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.
286
- if (!path || path.substr(0,1) !== "/") {
287
- return "/";
288
- }
289
-
290
- // "3. If the uri-path contains no more than one %x2F ("/") character, output
291
- // %x2F ("/") and skip the remaining step."
292
- if (path === "/") {
293
- return path;
294
- }
295
-
296
- var rightSlash = path.lastIndexOf("/");
297
- if (rightSlash === 0) {
298
- return "/";
299
- }
300
-
301
- // "4. Output the characters of the uri-path from the first character up to,
302
- // but not including, the right-most %x2F ("/")."
303
- return path.slice(0, rightSlash);
304
- }
305
-
306
- /*
307
- * "A request-path path-matches a given cookie-path if at least one of the
308
- * following conditions holds:"
309
- */
310
- function pathMatch(reqPath,cookiePath) {
311
- // "o The cookie-path and the request-path are identical."
312
- if (cookiePath === reqPath) {
313
- return true;
314
- }
315
-
316
- var idx = reqPath.indexOf(cookiePath);
317
- if (idx === 0) {
318
- // "o The cookie-path is a prefix of the request-path, and the last
319
- // character of the cookie-path is %x2F ("/")."
320
- if (cookiePath.substr(-1) === "/") {
321
- return true;
322
- }
323
-
324
- // " o The cookie-path is a prefix of the request-path, and the first
325
- // character of the request-path that is not included in the cookie- path
326
- // is a %x2F ("/") character."
327
- if (reqPath.substr(cookiePath.length,1) === "/") {
328
- return true;
329
- }
330
- }
331
-
332
- return false;
333
- }
334
-
335
- function parse(str, strict) {
336
- str = str.trim();
337
-
338
- // S4.1.1 Trailing semi-colons are not part of the specification.
339
- // If we are not in strict mode we remove the trailing semi-colons.
340
- var semiColonCheck = TRAILING_SEMICOLON.exec(str);
341
- if (semiColonCheck) {
342
- if (strict) {
343
- return;
344
- }
345
- str = str.slice(0, semiColonCheck.index);
346
- }
347
-
348
- // We use a regex to parse the "name-value-pair" part of S5.2
349
- var firstSemi = str.indexOf(';'); // S5.2 step 1
350
- var pairRx = strict ? COOKIE_PAIR_STRICT : COOKIE_PAIR;
351
- var result = pairRx.exec(firstSemi === -1 ? str : str.substr(0,firstSemi));
352
-
353
- // Rx satisfies the "the name string is empty" and "lacks a %x3D ("=")"
354
- // constraints as well as trimming any whitespace.
355
- if (!result) {
356
- return;
357
- }
358
-
359
- var c = new Cookie();
360
- c.key = result[1]; // the regexp should trim() already
361
- c.value = result[3]; // [2] is quotes or empty-string
362
-
363
- if (firstSemi === -1) {
364
- return c;
365
- }
366
-
367
- // S5.2.3 "unparsed-attributes consist of the remainder of the set-cookie-string
368
- // (including the %x3B (";") in question)." plus later on in the same section
369
- // "discard the first ";" and trim".
370
- var unparsed = str.slice(firstSemi).replace(/^\s*;\s*/,'').trim();
371
-
372
- // "If the unparsed-attributes string is empty, skip the rest of these
373
- // steps."
374
- if (unparsed.length === 0) {
375
- return c;
376
- }
377
-
378
- /*
379
- * S5.2 says that when looping over the items "[p]rocess the attribute-name
380
- * and attribute-value according to the requirements in the following
381
- * subsections" for every item. Plus, for many of the individual attributes
382
- * in S5.3 it says to use the "attribute-value of the last attribute in the
383
- * cookie-attribute-list". Therefore, in this implementation, we overwrite
384
- * the previous value.
385
- */
386
- var cookie_avs = unparsed.split(/\s*;\s*/);
387
- while (cookie_avs.length) {
388
- var av = cookie_avs.shift();
389
-
390
- if (strict && !EXTENSION_AV.test(av)) {
391
- return;
392
- }
393
-
394
- var av_sep = av.indexOf('=');
395
- var av_key, av_value;
396
- if (av_sep === -1) {
397
- av_key = av;
398
- av_value = null;
399
- } else {
400
- av_key = av.substr(0,av_sep);
401
- av_value = av.substr(av_sep+1);
402
- }
403
-
404
- av_key = av_key.trim().toLowerCase();
405
- if (av_value) {
406
- av_value = av_value.trim();
407
- }
408
-
409
- switch(av_key) {
410
- case 'expires': // S5.2.1
411
- if (!av_value) {if(strict){return;}else{break;} }
412
- var exp = parseDate(av_value,strict);
413
- // "If the attribute-value failed to parse as a cookie date, ignore the
414
- // cookie-av."
415
- if (exp == null) { if(strict){return;}else{break;} }
416
- c.expires = exp;
417
- // over and underflow not realistically a concern: V8's getTime() seems to
418
- // store something larger than a 32-bit time_t (even with 32-bit node)
419
- break;
420
-
421
- case 'max-age': // S5.2.2
422
- if (!av_value) { if(strict){return;}else{break;} }
423
- // "If the first character of the attribute-value is not a DIGIT or a "-"
424
- // character ...[or]... If the remainder of attribute-value contains a
425
- // non-DIGIT character, ignore the cookie-av."
426
- if (!/^-?[0-9]+$/.test(av_value)) { if(strict){return;}else{break;} }
427
- var delta = parseInt(av_value,10);
428
- if (strict && delta <= 0) {
429
- return; // S4.1.1
430
- }
431
- // "If delta-seconds is less than or equal to zero (0), let expiry-time
432
- // be the earliest representable date and time."
433
- c.setMaxAge(delta);
434
- break;
435
-
436
- case 'domain': // S5.2.3
437
- // "If the attribute-value is empty, the behavior is undefined. However,
438
- // the user agent SHOULD ignore the cookie-av entirely."
439
- if (!av_value) { if(strict){return;}else{break;} }
440
- // S5.2.3 "Let cookie-domain be the attribute-value without the leading %x2E
441
- // (".") character."
442
- var domain = av_value.trim().replace(/^\./,'');
443
- if (!domain) { if(strict){return;}else{break;} } // see "is empty" above
444
- // "Convert the cookie-domain to lower case."
445
- c.domain = domain.toLowerCase();
446
- break;
447
-
448
- case 'path': // S5.2.4
449
- /*
450
- * "If the attribute-value is empty or if the first character of the
451
- * attribute-value is not %x2F ("/"):
452
- * Let cookie-path be the default-path.
453
- * Otherwise:
454
- * Let cookie-path be the attribute-value."
455
- *
456
- * We'll represent the default-path as null since it depends on the
457
- * context of the parsing.
458
- */
459
- if (!av_value || av_value.substr(0,1) != "/") {
460
- if(strict){return;}else{break;}
461
- }
462
- c.path = av_value;
463
- break;
464
-
465
- case 'secure': // S5.2.5
466
- /*
467
- * "If the attribute-name case-insensitively matches the string "Secure",
468
- * the user agent MUST append an attribute to the cookie-attribute-list
469
- * with an attribute-name of Secure and an empty attribute-value."
470
- */
471
- if (av_value != null) { if(strict){return;} }
472
- c.secure = true;
473
- break;
474
-
475
- case 'httponly': // S5.2.6 -- effectively the same as 'secure'
476
- if (av_value != null) { if(strict){return;} }
477
- c.httpOnly = true;
478
- break;
479
-
480
- default:
481
- c.extensions = c.extensions || [];
482
- c.extensions.push(av);
483
- break;
484
- }
485
- }
486
-
487
- // ensure a default date for sorting:
488
- c.creation = new Date();
489
- return c;
490
- }
491
-
492
- function fromJSON(str) {
493
- if (!str) {
494
- return null;
495
- }
496
-
497
- var obj;
498
- try {
499
- obj = JSON.parse(str);
500
- } catch (e) {
501
- return null;
502
- }
503
-
504
- var c = new Cookie();
505
- for (var i=0; i<numCookieProperties; i++) {
506
- var prop = cookieProperties[i];
507
- if (obj[prop] == null) {
508
- continue;
509
- }
510
- if (prop === 'expires' ||
511
- prop === 'creation' ||
512
- prop === 'lastAccessed')
513
- {
514
- c[prop] = obj[prop] == "Infinity" ? "Infinity" : new Date(obj[prop]);
515
- } else {
516
- c[prop] = obj[prop];
517
- }
518
- }
519
-
520
-
521
- // ensure a default date for sorting:
522
- c.creation = c.creation || new Date();
523
-
524
- return c;
525
- }
526
-
527
- /* Section 5.4 part 2:
528
- * "* Cookies with longer paths are listed before cookies with
529
- * shorter paths.
530
- *
531
- * * Among cookies that have equal-length path fields, cookies with
532
- * earlier creation-times are listed before cookies with later
533
- * creation-times."
534
- */
535
-
536
- function cookieCompare(a,b) {
537
- // descending for length: b CMP a
538
- var deltaLen = (b.path ? b.path.length : 0) - (a.path ? a.path.length : 0);
539
- if (deltaLen !== 0) {
540
- return deltaLen;
541
- }
542
- // ascending for time: a CMP b
543
- return (a.creation ? a.creation.getTime() : MAX_TIME) -
544
- (b.creation ? b.creation.getTime() : MAX_TIME);
545
- }
546
-
547
- // Gives the permutation of all possible domainMatch()es of a given domain. The
548
- // array is in shortest-to-longest order. Handy for indexing.
549
- function permuteDomain(domain) {
550
- var pubSuf = pubsuffix.getPublicSuffix(domain);
551
- if (!pubSuf) {
552
- return null;
553
- }
554
- if (pubSuf == domain) {
555
- return [domain];
556
- }
557
-
558
- var prefix = domain.slice(0,-(pubSuf.length+1)); // ".example.com"
559
- var parts = prefix.split('.').reverse();
560
- var cur = pubSuf;
561
- var permutations = [cur];
562
- while (parts.length) {
563
- cur = parts.shift()+'.'+cur;
564
- permutations.push(cur);
565
- }
566
- return permutations;
567
- }
568
-
569
- // Gives the permutation of all possible pathMatch()es of a given path. The
570
- // array is in longest-to-shortest order. Handy for indexing.
571
- function permutePath(path) {
572
- if (path === '/') {
573
- return ['/'];
574
- }
575
- if (path.lastIndexOf('/') === path.length-1) {
576
- path = path.substr(0,path.length-1);
577
- }
578
- var permutations = [path];
579
- while (path.length > 1) {
580
- var lindex = path.lastIndexOf('/');
581
- if (lindex === 0) {
582
- break;
583
- }
584
- path = path.substr(0,lindex);
585
- permutations.push(path);
586
- }
587
- permutations.push('/');
588
- return permutations;
589
- }
590
-
591
-
592
- function Cookie (opts) {
593
- if (typeof opts !== "object") {
594
- return;
595
- }
596
- Object.keys(opts).forEach(function (key) {
597
- if (Cookie.prototype.hasOwnProperty(key)) {
598
- this[key] = opts[key] || Cookie.prototype[key];
599
- }
600
- }.bind(this));
601
- }
602
-
603
- Cookie.parse = parse;
604
- Cookie.fromJSON = fromJSON;
605
-
606
- Cookie.prototype.key = "";
607
- Cookie.prototype.value = "";
608
-
609
- // the order in which the RFC has them:
610
- Cookie.prototype.expires = "Infinity"; // coerces to literal Infinity
611
- Cookie.prototype.maxAge = null; // takes precedence over expires for TTL
612
- Cookie.prototype.domain = null;
613
- Cookie.prototype.path = null;
614
- Cookie.prototype.secure = false;
615
- Cookie.prototype.httpOnly = false;
616
- Cookie.prototype.extensions = null;
617
-
618
- // set by the CookieJar:
619
- Cookie.prototype.hostOnly = null; // boolean when set
620
- Cookie.prototype.pathIsDefault = null; // boolean when set
621
- Cookie.prototype.creation = null; // Date when set; defaulted by Cookie.parse
622
- Cookie.prototype.lastAccessed = null; // Date when set
623
-
624
- var cookieProperties = Object.freeze(Object.keys(Cookie.prototype).map(function(p) {
625
- if (p instanceof Function) {
626
- return;
627
- }
628
- return p;
629
- }));
630
- var numCookieProperties = cookieProperties.length;
631
-
632
- Cookie.prototype.inspect = function inspect() {
633
- var now = Date.now();
634
- return 'Cookie="'+this.toString() +
635
- '; hostOnly='+(this.hostOnly != null ? this.hostOnly : '?') +
636
- '; aAge='+(this.lastAccessed ? (now-this.lastAccessed.getTime())+'ms' : '?') +
637
- '; cAge='+(this.creation ? (now-this.creation.getTime())+'ms' : '?') +
638
- '"';
639
- };
640
-
641
- Cookie.prototype.validate = function validate() {
642
- if (!COOKIE_OCTETS.test(this.value)) {
643
- return false;
644
- }
645
- if (this.expires != Infinity && !(this.expires instanceof Date) && !parseDate(this.expires,true)) {
646
- return false;
647
- }
648
- if (this.maxAge != null && this.maxAge <= 0) {
649
- return false; // "Max-Age=" non-zero-digit *DIGIT
650
- }
651
- if (this.path != null && !PATH_VALUE.test(this.path)) {
652
- return false;
653
- }
654
-
655
- var cdomain = this.cdomain();
656
- if (cdomain) {
657
- if (cdomain.match(/\.$/)) {
658
- return false; // S4.1.2.3 suggests that this is bad. domainMatch() tests confirm this
659
- }
660
- var suffix = pubsuffix.getPublicSuffix(cdomain);
661
- if (suffix == null) { // it's a public suffix
662
- return false;
663
- }
664
- }
665
- return true;
666
- };
667
-
668
- Cookie.prototype.setExpires = function setExpires(exp) {
669
- if (exp instanceof Date) {
670
- this.expires = exp;
671
- } else {
672
- this.expires = parseDate(exp) || "Infinity";
673
- }
674
- };
675
-
676
- Cookie.prototype.setMaxAge = function setMaxAge(age) {
677
- if (age === Infinity || age === -Infinity) {
678
- this.maxAge = age.toString(); // so JSON.stringify() works
679
- } else {
680
- this.maxAge = age;
681
- }
682
- };
683
-
684
- // gives Cookie header format
685
- Cookie.prototype.cookieString = function cookieString() {
686
- var val = this.value;
687
- if (val == null) {
688
- val = '';
689
- }
690
- return this.key+'='+val;
691
- };
692
-
693
- // gives Set-Cookie header format
694
- Cookie.prototype.toString = function toString() {
695
- var str = this.cookieString();
696
-
697
- if (this.expires != Infinity) {
698
- if (this.expires instanceof Date) {
699
- str += '; Expires='+formatDate(this.expires);
700
- } else {
701
- str += '; Expires='+this.expires;
702
- }
703
- }
704
-
705
- if (this.maxAge != null && this.maxAge != Infinity) {
706
- str += '; Max-Age='+this.maxAge;
707
- }
708
-
709
- if (this.domain && !this.hostOnly) {
710
- str += '; Domain='+this.domain;
711
- }
712
- if (this.path) {
713
- str += '; Path='+this.path;
714
- }
715
-
716
- if (this.secure) {
717
- str += '; Secure';
718
- }
719
- if (this.httpOnly) {
720
- str += '; HttpOnly';
721
- }
722
- if (this.extensions) {
723
- this.extensions.forEach(function(ext) {
724
- str += '; '+ext;
725
- });
726
- }
727
-
728
- return str;
729
- };
730
-
731
- // TTL() partially replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
732
- // elsewhere)
733
- // S5.3 says to give the "latest representable date" for which we use Infinity
734
- // For "expired" we use 0
735
- Cookie.prototype.TTL = function TTL(now) {
736
- /* RFC6265 S4.1.2.2 If a cookie has both the Max-Age and the Expires
737
- * attribute, the Max-Age attribute has precedence and controls the
738
- * expiration date of the cookie.
739
- * (Concurs with S5.3 step 3)
740
- */
741
- if (this.maxAge != null) {
742
- return this.maxAge<=0 ? 0 : this.maxAge*1000;
743
- }
744
-
745
- var expires = this.expires;
746
- if (expires != Infinity) {
747
- if (!(expires instanceof Date)) {
748
- expires = parseDate(expires) || Infinity;
749
- }
750
-
751
- if (expires == Infinity) {
752
- return Infinity;
753
- }
754
-
755
- return expires.getTime() - (now || Date.now());
756
- }
757
-
758
- return Infinity;
759
- };
760
-
761
- // expiryTime() replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
762
- // elsewhere)
763
- Cookie.prototype.expiryTime = function expiryTime(now) {
764
- if (this.maxAge != null) {
765
- var relativeTo = this.creation || now || new Date();
766
- var age = (this.maxAge <= 0) ? -Infinity : this.maxAge*1000;
767
- return relativeTo.getTime() + age;
768
- }
769
-
770
- if (this.expires == Infinity) {
771
- return Infinity;
772
- }
773
- return this.expires.getTime();
774
- };
775
-
776
- // expiryDate() replaces the "expiry-time" parts of S5.3 step 3 (setCookie()
777
- // elsewhere), except it returns a Date
778
- Cookie.prototype.expiryDate = function expiryDate(now) {
779
- var millisec = this.expiryTime(now);
780
- if (millisec == Infinity) {
781
- return new Date(MAX_TIME);
782
- } else if (millisec == -Infinity) {
783
- return new Date(MIN_TIME);
784
- } else {
785
- return new Date(millisec);
786
- }
787
- };
788
-
789
- // This replaces the "persistent-flag" parts of S5.3 step 3
790
- Cookie.prototype.isPersistent = function isPersistent() {
791
- return (this.maxAge != null || this.expires != Infinity);
792
- };
793
-
794
- // Mostly S5.1.2 and S5.2.3:
795
- Cookie.prototype.cdomain =
796
- Cookie.prototype.canonicalizedDomain = function canonicalizedDomain() {
797
- if (this.domain == null) {
798
- return null;
799
- }
800
- return canonicalDomain(this.domain);
801
- };
802
-
803
-
804
- var memstore;
805
- function CookieJar(store, rejectPublicSuffixes) {
806
- if (rejectPublicSuffixes != null) {
807
- this.rejectPublicSuffixes = rejectPublicSuffixes;
808
- }
809
-
810
- if (!store) {
811
- memstore = memstore || require('./memstore');
812
- store = new memstore.MemoryCookieStore();
813
- }
814
- this.store = store;
815
- }
816
- CookieJar.prototype.store = null;
817
- CookieJar.prototype.rejectPublicSuffixes = true;
818
- var CAN_BE_SYNC = [];
819
-
820
- CAN_BE_SYNC.push('setCookie');
821
- CookieJar.prototype.setCookie = function(cookie, url, options, cb) {
822
- var err;
823
- var context = (url instanceof Object) ? url : urlParse(url);
824
- if (options instanceof Function) {
825
- cb = options;
826
- options = {};
827
- }
828
-
829
- var host = canonicalDomain(context.hostname);
830
-
831
- // S5.3 step 1
832
- if (!(cookie instanceof Cookie)) {
833
- cookie = Cookie.parse(cookie, options.strict === true);
834
- }
835
- if (!cookie) {
836
- err = new Error("Cookie failed to parse");
837
- return cb(options.ignoreError ? null : err);
838
- }
839
-
840
- // S5.3 step 2
841
- var now = options.now || new Date(); // will assign later to save effort in the face of errors
842
-
843
- // S5.3 step 3: NOOP; persistent-flag and expiry-time is handled by getCookie()
844
-
845
- // S5.3 step 4: NOOP; domain is null by default
846
-
847
- // S5.3 step 5: public suffixes
848
- if (this.rejectPublicSuffixes && cookie.domain) {
849
- var suffix = pubsuffix.getPublicSuffix(cookie.cdomain());
850
- if (suffix == null) { // e.g. "com"
851
- err = new Error("Cookie has domain set to a public suffix");
852
- return cb(options.ignoreError ? null : err);
853
- }
854
- }
855
-
856
- // S5.3 step 6:
857
- if (cookie.domain) {
858
- if (!domainMatch(host, cookie.cdomain(), false)) {
859
- err = new Error("Cookie not in this host's domain. Cookie:"+cookie.cdomain()+" Request:"+host);
860
- return cb(options.ignoreError ? null : err);
861
- }
862
-
863
- if (cookie.hostOnly == null) { // don't reset if already set
864
- cookie.hostOnly = false;
865
- }
866
-
867
- } else {
868
- cookie.hostOnly = true;
869
- cookie.domain = host;
870
- }
871
-
872
- // S5.3 step 7: "Otherwise, set the cookie's path to the default-path of the
873
- // request-uri"
874
- if (!cookie.path) {
875
- cookie.path = defaultPath(context.pathname);
876
- cookie.pathIsDefault = true;
877
- } else {
878
- if (cookie.path.length > 1 && cookie.path.substr(-1) == '/') {
879
- cookie.path = cookie.path.slice(0,-1);
880
- }
881
- }
882
-
883
- // S5.3 step 8: NOOP; secure attribute
884
- // S5.3 step 9: NOOP; httpOnly attribute
885
-
886
- // S5.3 step 10
887
- if (options.http === false && cookie.httpOnly) {
888
- err = new Error("Cookie is HttpOnly and this isn't an HTTP API");
889
- return cb(options.ignoreError ? null : err);
890
- }
891
-
892
- var store = this.store;
893
-
894
- if (!store.updateCookie) {
895
- store.updateCookie = function(oldCookie, newCookie, cb) {
896
- this.putCookie(newCookie, cb);
897
- };
898
- }
899
-
900
- function withCookie(err, oldCookie) {
901
- if (err) {
902
- return cb(err);
903
- }
904
-
905
- var next = function(err) {
906
- if (err) {
907
- return cb(err);
908
- } else {
909
- cb(null, cookie);
910
- }
911
- };
912
-
913
- if (oldCookie) {
914
- // S5.3 step 11 - "If the cookie store contains a cookie with the same name,
915
- // domain, and path as the newly created cookie:"
916
- if (options.http === false && oldCookie.httpOnly) { // step 11.2
917
- err = new Error("old Cookie is HttpOnly and this isn't an HTTP API");
918
- return cb(options.ignoreError ? null : err);
919
- }
920
- cookie.creation = oldCookie.creation; // step 11.3
921
- cookie.lastAccessed = now;
922
- // Step 11.4 (delete cookie) is implied by just setting the new one:
923
- store.updateCookie(oldCookie, cookie, next); // step 12
924
-
925
- } else {
926
- cookie.creation = cookie.lastAccessed = now;
927
- store.putCookie(cookie, next); // step 12
928
- }
929
- }
930
-
931
- store.findCookie(cookie.domain, cookie.path, cookie.key, withCookie);
932
- };
933
-
934
- // RFC6365 S5.4
935
- CAN_BE_SYNC.push('getCookies');
936
- CookieJar.prototype.getCookies = function(url, options, cb) {
937
- var context = (url instanceof Object) ? url : urlParse(url);
938
- if (options instanceof Function) {
939
- cb = options;
940
- options = {};
941
- }
942
-
943
- var host = canonicalDomain(context.hostname);
944
- var path = context.pathname || '/';
945
-
946
- var secure = options.secure;
947
- if (secure == null && context.protocol &&
948
- (context.protocol == 'https:' || context.protocol == 'wss:'))
949
- {
950
- secure = true;
951
- }
952
-
953
- var http = options.http;
954
- if (http == null) {
955
- http = true;
956
- }
957
-
958
- var now = options.now || Date.now();
959
- var expireCheck = options.expire !== false;
960
- var allPaths = !!options.allPaths;
961
- var store = this.store;
962
-
963
- function matchingCookie(c) {
964
- // "Either:
965
- // The cookie's host-only-flag is true and the canonicalized
966
- // request-host is identical to the cookie's domain.
967
- // Or:
968
- // The cookie's host-only-flag is false and the canonicalized
969
- // request-host domain-matches the cookie's domain."
970
- if (c.hostOnly) {
971
- if (c.domain != host) {
972
- return false;
973
- }
974
- } else {
975
- if (!domainMatch(host, c.domain, false)) {
976
- return false;
977
- }
978
- }
979
-
980
- // "The request-uri's path path-matches the cookie's path."
981
- if (!allPaths && !pathMatch(path, c.path)) {
982
- return false;
983
- }
984
-
985
- // "If the cookie's secure-only-flag is true, then the request-uri's
986
- // scheme must denote a "secure" protocol"
987
- if (c.secure && !secure) {
988
- return false;
989
- }
990
-
991
- // "If the cookie's http-only-flag is true, then exclude the cookie if the
992
- // cookie-string is being generated for a "non-HTTP" API"
993
- if (c.httpOnly && !http) {
994
- return false;
995
- }
996
-
997
- // deferred from S5.3
998
- // non-RFC: allow retention of expired cookies by choice
999
- if (expireCheck && c.expiryTime() <= now) {
1000
- store.removeCookie(c.domain, c.path, c.key, function(){}); // result ignored
1001
- return false;
1002
- }
1003
-
1004
- return true;
1005
- }
1006
-
1007
- store.findCookies(host, allPaths ? null : path, function(err,cookies) {
1008
- if (err) {
1009
- return cb(err);
1010
- }
1011
-
1012
- cookies = cookies.filter(matchingCookie);
1013
-
1014
- // sorting of S5.4 part 2
1015
- if (options.sort !== false) {
1016
- cookies = cookies.sort(cookieCompare);
1017
- }
1018
-
1019
- // S5.4 part 3
1020
- var now = new Date();
1021
- cookies.forEach(function(c) {
1022
- c.lastAccessed = now;
1023
- });
1024
- // TODO persist lastAccessed
1025
-
1026
- cb(null,cookies);
1027
- });
1028
- };
1029
-
1030
- CAN_BE_SYNC.push('getCookieString');
1031
- CookieJar.prototype.getCookieString = function(/*..., cb*/) {
1032
- var args = Array.prototype.slice.call(arguments,0);
1033
- var cb = args.pop();
1034
- var next = function(err,cookies) {
1035
- if (err) {
1036
- cb(err);
1037
- } else {
1038
- cb(null, cookies.map(function(c){
1039
- return c.cookieString();
1040
- }).join('; '));
1041
- }
1042
- };
1043
- args.push(next);
1044
- this.getCookies.apply(this,args);
1045
- };
1046
-
1047
- CAN_BE_SYNC.push('getSetCookieStrings');
1048
- CookieJar.prototype.getSetCookieStrings = function(/*..., cb*/) {
1049
- var args = Array.prototype.slice.call(arguments,0);
1050
- var cb = args.pop();
1051
- var next = function(err,cookies) {
1052
- if (err) {
1053
- cb(err);
1054
- } else {
1055
- cb(null, cookies.map(function(c){
1056
- return c.toString();
1057
- }));
1058
- }
1059
- };
1060
- args.push(next);
1061
- this.getCookies.apply(this,args);
1062
- };
1063
-
1064
- // Use a closure to provide a true imperative API for synchronous stores.
1065
- function syncWrap(method) {
1066
- return function() {
1067
- if (!this.store.synchronous) {
1068
- throw new Error('CookieJar store is not synchronous; use async API instead.');
1069
- }
1070
-
1071
- var args = Array.prototype.slice.call(arguments);
1072
- var syncErr, syncResult;
1073
- args.push(function syncCb(err, result) {
1074
- syncErr = err;
1075
- syncResult = result;
1076
- });
1077
- this[method].apply(this, args);
1078
-
1079
- if (syncErr) {
1080
- throw syncErr;
1081
- }
1082
- return syncResult;
1083
- };
1084
- }
1085
-
1086
- // wrap all declared CAN_BE_SYNC methods in the sync wrapper
1087
- CAN_BE_SYNC.forEach(function(method) {
1088
- CookieJar.prototype[method+'Sync'] = syncWrap(method);
1089
- });
1090
-
1091
- module.exports = {
1092
- CookieJar: CookieJar,
1093
- Cookie: Cookie,
1094
- Store: Store,
1095
- parseDate: parseDate,
1096
- formatDate: formatDate,
1097
- parse: parse,
1098
- fromJSON: fromJSON,
1099
- domainMatch: domainMatch,
1100
- defaultPath: defaultPath,
1101
- pathMatch: pathMatch,
1102
- getPublicSuffix: pubsuffix.getPublicSuffix,
1103
- cookieCompare: cookieCompare,
1104
- permuteDomain: permuteDomain,
1105
- permutePath: permutePath,
1106
- canonicalDomain: canonicalDomain,
1107
- };