ai 1.1.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.
- package/LICENSE +10 -24
- package/dist/ai-stream.d.ts +18 -0
- package/dist/ai-stream.js +132 -0
- package/dist/ai-stream.mjs +13 -0
- package/dist/anthropic-stream.d.ts +5 -0
- package/dist/anthropic-stream.js +133 -0
- package/dist/anthropic-stream.mjs +8 -0
- package/dist/chunk-265FSSO4.mjs +91 -0
- package/dist/chunk-2L3ZO4UM.mjs +45 -0
- package/dist/chunk-EZJ7FC5E.mjs +33 -0
- package/dist/chunk-JGDC3BXD.mjs +22 -0
- package/dist/chunk-NK2CVBLI.mjs +38 -0
- package/dist/chunk-PEYAHBDF.mjs +43 -0
- package/dist/chunk-TJMME6CL.mjs +24 -0
- package/dist/huggingface-stream.d.ts +5 -0
- package/dist/huggingface-stream.js +121 -0
- package/dist/huggingface-stream.mjs +8 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.js +278 -0
- package/dist/index.mjs +35 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.js +12 -0
- package/dist/index.test.mjs +10 -0
- package/dist/langchain-stream.d.ts +12 -0
- package/dist/langchain-stream.js +102 -0
- package/dist/langchain-stream.mjs +8 -0
- package/dist/openai-stream.d.ts +5 -0
- package/dist/openai-stream.js +144 -0
- package/dist/openai-stream.mjs +8 -0
- package/dist/streaming-text-response.d.ts +17 -0
- package/dist/streaming-text-response.js +75 -0
- package/dist/streaming-text-response.mjs +9 -0
- package/package.json +78 -29
- package/react/dist/chunk-5PP6W52J.mjs +202 -0
- package/react/dist/chunk-6EH3SWMP.mjs +55 -0
- package/react/dist/chunk-PW6HSU2N.mjs +154 -0
- package/react/dist/index.d.ts +3 -0
- package/react/dist/index.js +424 -0
- package/react/dist/index.mjs +12 -0
- package/react/dist/types-f862f74a.d.ts +123 -0
- package/react/dist/use-chat.d.ts +42 -0
- package/react/dist/use-chat.js +276 -0
- package/react/dist/use-chat.mjs +8 -0
- package/react/dist/use-completion.d.ts +47 -0
- package/react/dist/use-completion.js +229 -0
- package/react/dist/use-completion.mjs +8 -0
- package/svelte/dist/chunk-6USBQIV6.mjs +177 -0
- package/svelte/dist/chunk-BQ64GHZ3.mjs +136 -0
- package/svelte/dist/chunk-CENOSGDG.mjs +493 -0
- package/svelte/dist/index.d.ts +4 -0
- package/svelte/dist/index.js +808 -0
- package/svelte/dist/index.mjs +11 -0
- package/svelte/dist/types-f862f74a.d.ts +123 -0
- package/svelte/dist/use-chat.d.ts +39 -0
- package/svelte/dist/use-chat.js +680 -0
- package/svelte/dist/use-chat.mjs +7 -0
- package/svelte/dist/use-completion.d.ts +38 -0
- package/svelte/dist/use-completion.js +640 -0
- package/svelte/dist/use-completion.mjs +7 -0
- package/.npmignore +0 -15
- package/.travis.yml +0 -4
- package/README.md +0 -21
- package/bin/ai.js +0 -22
- package/index.js +0 -37
- package/node_modules/request/.npmignore +0 -2
- package/node_modules/request/.travis.yml +0 -12
- package/node_modules/request/CHANGELOG.md +0 -954
- package/node_modules/request/LICENSE +0 -55
- package/node_modules/request/README.md +0 -421
- package/node_modules/request/index.js +0 -166
- package/node_modules/request/lib/cookies.js +0 -40
- package/node_modules/request/lib/copy.js +0 -8
- package/node_modules/request/lib/debug.js +0 -7
- package/node_modules/request/lib/getSafe.js +0 -34
- package/node_modules/request/lib/optional.js +0 -5
- package/node_modules/request/node_modules/aws-sign2/LICENSE +0 -55
- package/node_modules/request/node_modules/aws-sign2/README.md +0 -4
- package/node_modules/request/node_modules/aws-sign2/index.js +0 -202
- package/node_modules/request/node_modules/aws-sign2/package.json +0 -47
- package/node_modules/request/node_modules/forever-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/forever-agent/README.md +0 -4
- package/node_modules/request/node_modules/forever-agent/index.js +0 -119
- package/node_modules/request/node_modules/forever-agent/package.json +0 -46
- package/node_modules/request/node_modules/form-data/License +0 -19
- package/node_modules/request/node_modules/form-data/Readme.md +0 -175
- package/node_modules/request/node_modules/form-data/lib/form_data.js +0 -351
- package/node_modules/request/node_modules/form-data/node_modules/async/.travis.yml +0 -3
- package/node_modules/request/node_modules/form-data/node_modules/async/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/async/README.md +0 -1646
- package/node_modules/request/node_modules/form-data/node_modules/async/component.json +0 -11
- package/node_modules/request/node_modules/form-data/node_modules/async/lib/async.js +0 -1123
- package/node_modules/request/node_modules/form-data/node_modules/async/package.json +0 -60
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/Readme.md +0 -132
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/lib/combined_stream.js +0 -186
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/.npmignore +0 -2
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/License +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Makefile +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/Readme.md +0 -154
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js +0 -99
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/package.json +0 -42
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/common.js +0 -6
- 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
- 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
- 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
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-delayed-stream.js +0 -48
- 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
- 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
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-pipe-resumes.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/integration/test-proxy-readable.js +0 -13
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/node_modules/delayed-stream/test/run.js +0 -7
- package/node_modules/request/node_modules/form-data/node_modules/combined-stream/package.json +0 -61
- package/node_modules/request/node_modules/form-data/node_modules/mime/LICENSE +0 -19
- package/node_modules/request/node_modules/form-data/node_modules/mime/README.md +0 -66
- package/node_modules/request/node_modules/form-data/node_modules/mime/mime.js +0 -114
- package/node_modules/request/node_modules/form-data/node_modules/mime/package.json +0 -59
- package/node_modules/request/node_modules/form-data/node_modules/mime/test.js +0 -84
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/mime.types +0 -1588
- package/node_modules/request/node_modules/form-data/node_modules/mime/types/node.types +0 -77
- package/node_modules/request/node_modules/form-data/package.json +0 -80
- package/node_modules/request/node_modules/hawk/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/README.md +0 -625
- package/node_modules/request/node_modules/hawk/example/usage.js +0 -78
- package/node_modules/request/node_modules/hawk/images/hawk.png +0 -0
- package/node_modules/request/node_modules/hawk/images/logo.png +0 -0
- package/node_modules/request/node_modules/hawk/index.js +0 -1
- package/node_modules/request/node_modules/hawk/lib/browser.js +0 -507
- package/node_modules/request/node_modules/hawk/lib/client.js +0 -371
- package/node_modules/request/node_modules/hawk/lib/crypto.js +0 -118
- package/node_modules/request/node_modules/hawk/lib/index.js +0 -15
- package/node_modules/request/node_modules/hawk/lib/server.js +0 -523
- package/node_modules/request/node_modules/hawk/lib/utils.js +0 -183
- package/node_modules/request/node_modules/hawk/node_modules/boom/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/boom/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/boom/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/boom/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/boom/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/boom/images/boom.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/boom/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/boom/lib/index.js +0 -207
- package/node_modules/request/node_modules/hawk/node_modules/boom/package.json +0 -64
- package/node_modules/request/node_modules/hawk/node_modules/boom/test/index.js +0 -245
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/README.md +0 -6
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/lib/index.js +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/cryptiles/test/index.js +0 -101
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/hoek/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/hoek/LICENSE +0 -33
- package/node_modules/request/node_modules/hawk/node_modules/hoek/Makefile +0 -10
- package/node_modules/request/node_modules/hawk/node_modules/hoek/README.md +0 -436
- package/node_modules/request/node_modules/hawk/node_modules/hoek/images/hoek.png +0 -0
- package/node_modules/request/node_modules/hawk/node_modules/hoek/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/escape.js +0 -132
- package/node_modules/request/node_modules/hawk/node_modules/hoek/lib/index.js +0 -585
- package/node_modules/request/node_modules/hawk/node_modules/hoek/package.json +0 -70
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/escaper.js +0 -86
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/index.js +0 -1078
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test1.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test2.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/hoek/test/modules/test3.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.npmignore +0 -18
- package/node_modules/request/node_modules/hawk/node_modules/sntp/.travis.yml +0 -5
- package/node_modules/request/node_modules/hawk/node_modules/sntp/LICENSE +0 -24
- package/node_modules/request/node_modules/hawk/node_modules/sntp/Makefile +0 -11
- package/node_modules/request/node_modules/hawk/node_modules/sntp/README.md +0 -68
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/offset.js +0 -16
- package/node_modules/request/node_modules/hawk/node_modules/sntp/examples/time.js +0 -25
- package/node_modules/request/node_modules/hawk/node_modules/sntp/index.js +0 -1
- package/node_modules/request/node_modules/hawk/node_modules/sntp/lib/index.js +0 -409
- package/node_modules/request/node_modules/hawk/node_modules/sntp/package.json +0 -65
- package/node_modules/request/node_modules/hawk/node_modules/sntp/test/index.js +0 -359
- package/node_modules/request/node_modules/hawk/package.json +0 -70
- package/node_modules/request/node_modules/hawk/test/browser.js +0 -817
- package/node_modules/request/node_modules/hawk/test/client.js +0 -206
- package/node_modules/request/node_modules/hawk/test/crypto.js +0 -86
- package/node_modules/request/node_modules/hawk/test/index.js +0 -316
- package/node_modules/request/node_modules/hawk/test/message.js +0 -246
- package/node_modules/request/node_modules/hawk/test/readme.js +0 -98
- package/node_modules/request/node_modules/hawk/test/server.js +0 -686
- package/node_modules/request/node_modules/hawk/test/uri.js +0 -456
- package/node_modules/request/node_modules/hawk/test/utils.js +0 -120
- package/node_modules/request/node_modules/http-signature/.dir-locals.el +0 -6
- package/node_modules/request/node_modules/http-signature/.npmignore +0 -7
- package/node_modules/request/node_modules/http-signature/LICENSE +0 -18
- package/node_modules/request/node_modules/http-signature/README.md +0 -75
- package/node_modules/request/node_modules/http-signature/http_signing.md +0 -296
- package/node_modules/request/node_modules/http-signature/lib/index.js +0 -25
- package/node_modules/request/node_modules/http-signature/lib/parser.js +0 -304
- package/node_modules/request/node_modules/http-signature/lib/signer.js +0 -179
- package/node_modules/request/node_modules/http-signature/lib/util.js +0 -249
- package/node_modules/request/node_modules/http-signature/lib/verify.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/.npmignore +0 -2
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/LICENSE +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/README.md +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/errors.js +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/index.js +0 -27
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/reader.js +0 -267
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/types.js +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/ber/writer.js +0 -317
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/lib/index.js +0 -20
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/package.json +0 -63
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/reader.test.js +0 -172
- package/node_modules/request/node_modules/http-signature/node_modules/asn1/tst/ber/writer.test.js +0 -296
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/README.md +0 -126
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/assert.js +0 -196
- package/node_modules/request/node_modules/http-signature/node_modules/assert-plus/package.json +0 -38
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/CHANGELOG +0 -71
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/LICENSE +0 -24
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README +0 -82
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/README.old +0 -298
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctf.js +0 -245
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctio.js +0 -1485
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/ctype.js +0 -944
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/man/man3ctype/ctio.3ctype +0 -241
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/package.json +0 -36
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsl.conf +0 -129
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tools/jsstyle +0 -839
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/float.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/int.json +0 -13
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/psinfo.json +0 -104
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/struct.json +0 -19
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.fail.js +0 -39
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.float.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.int.js +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.psinfo.js +0 -17
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.struct.js +0 -18
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/tst.typedef.js +0 -15
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctf/typedef.json +0 -14
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.rfloat.js +0 -767
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/float/tst.wfloat.js +0 -753
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.64.js +0 -638
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.rint.js +0 -101
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wbounds.js +0 -53
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/int/tst.wint.js +0 -92
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.64.js +0 -451
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.roundtrip.js +0 -81
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.ruint.js +0 -95
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctio/uint/tst.wuint.js +0 -156
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicr.js +0 -50
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.basicw.js +0 -44
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.char.js +0 -42
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.endian.js +0 -45
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.oldwrite.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.readSize.js +0 -128
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.structw.js +0 -28
- package/node_modules/request/node_modules/http-signature/node_modules/ctype/tst/ctype/tst.writeStruct.js +0 -31
- package/node_modules/request/node_modules/http-signature/package.json +0 -54
- package/node_modules/request/node_modules/json-stringify-safe/LICENSE +0 -27
- package/node_modules/request/node_modules/json-stringify-safe/README.md +0 -49
- package/node_modules/request/node_modules/json-stringify-safe/package.json +0 -51
- package/node_modules/request/node_modules/json-stringify-safe/stringify.js +0 -39
- package/node_modules/request/node_modules/json-stringify-safe/test.js +0 -128
- package/node_modules/request/node_modules/mime-types/.npmignore +0 -14
- package/node_modules/request/node_modules/mime-types/.travis.yml +0 -12
- package/node_modules/request/node_modules/mime-types/LICENSE +0 -22
- package/node_modules/request/node_modules/mime-types/Makefile +0 -9
- package/node_modules/request/node_modules/mime-types/README.md +0 -101
- package/node_modules/request/node_modules/mime-types/SOURCES.md +0 -17
- package/node_modules/request/node_modules/mime-types/component.json +0 -16
- package/node_modules/request/node_modules/mime-types/lib/custom.json +0 -27
- package/node_modules/request/node_modules/mime-types/lib/index.js +0 -75
- package/node_modules/request/node_modules/mime-types/lib/mime.json +0 -3317
- package/node_modules/request/node_modules/mime-types/lib/node.json +0 -55
- package/node_modules/request/node_modules/mime-types/package.json +0 -69
- package/node_modules/request/node_modules/node-uuid/.npmignore +0 -2
- package/node_modules/request/node_modules/node-uuid/LICENSE.md +0 -2
- package/node_modules/request/node_modules/node-uuid/README.md +0 -207
- package/node_modules/request/node_modules/node-uuid/benchmark/README.md +0 -53
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.gnu +0 -174
- package/node_modules/request/node_modules/node-uuid/benchmark/bench.sh +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark-native.c +0 -34
- package/node_modules/request/node_modules/node-uuid/benchmark/benchmark.js +0 -84
- package/node_modules/request/node_modules/node-uuid/component.json +0 -18
- package/node_modules/request/node_modules/node-uuid/package.json +0 -54
- package/node_modules/request/node_modules/node-uuid/test/compare_v1.js +0 -63
- package/node_modules/request/node_modules/node-uuid/test/test.html +0 -17
- package/node_modules/request/node_modules/node-uuid/test/test.js +0 -228
- package/node_modules/request/node_modules/node-uuid/uuid.js +0 -245
- package/node_modules/request/node_modules/oauth-sign/LICENSE +0 -55
- package/node_modules/request/node_modules/oauth-sign/README.md +0 -4
- package/node_modules/request/node_modules/oauth-sign/index.js +0 -43
- package/node_modules/request/node_modules/oauth-sign/package.json +0 -49
- package/node_modules/request/node_modules/oauth-sign/test.js +0 -49
- package/node_modules/request/node_modules/qs/.jshintignore +0 -1
- package/node_modules/request/node_modules/qs/.jshintrc +0 -10
- package/node_modules/request/node_modules/qs/.npmignore +0 -18
- package/node_modules/request/node_modules/qs/.travis.yml +0 -4
- package/node_modules/request/node_modules/qs/LICENSE +0 -28
- package/node_modules/request/node_modules/qs/Makefile +0 -8
- package/node_modules/request/node_modules/qs/Readme.md +0 -120
- package/node_modules/request/node_modules/qs/index.js +0 -1
- package/node_modules/request/node_modules/qs/lib/index.js +0 -15
- package/node_modules/request/node_modules/qs/lib/parse.js +0 -151
- package/node_modules/request/node_modules/qs/lib/stringify.js +0 -52
- package/node_modules/request/node_modules/qs/lib/utils.js +0 -131
- package/node_modules/request/node_modules/qs/package.json +0 -61
- package/node_modules/request/node_modules/qs/test/parse.js +0 -236
- package/node_modules/request/node_modules/qs/test/stringify.js +0 -123
- package/node_modules/request/node_modules/stringstream/.npmignore +0 -15
- package/node_modules/request/node_modules/stringstream/.travis.yml +0 -4
- package/node_modules/request/node_modules/stringstream/LICENSE.txt +0 -4
- package/node_modules/request/node_modules/stringstream/README.md +0 -38
- package/node_modules/request/node_modules/stringstream/example.js +0 -27
- package/node_modules/request/node_modules/stringstream/package.json +0 -48
- package/node_modules/request/node_modules/stringstream/stringstream.js +0 -102
- package/node_modules/request/node_modules/tough-cookie/.jshintrc +0 -70
- package/node_modules/request/node_modules/tough-cookie/.npmignore +0 -3
- package/node_modules/request/node_modules/tough-cookie/.travis.yml +0 -8
- package/node_modules/request/node_modules/tough-cookie/LICENSE +0 -78
- package/node_modules/request/node_modules/tough-cookie/README.md +0 -412
- package/node_modules/request/node_modules/tough-cookie/generate-pubsuffix.js +0 -239
- package/node_modules/request/node_modules/tough-cookie/lib/cookie.js +0 -1107
- package/node_modules/request/node_modules/tough-cookie/lib/memstore.js +0 -123
- package/node_modules/request/node_modules/tough-cookie/lib/pubsuffix.js +0 -69
- package/node_modules/request/node_modules/tough-cookie/lib/store.js +0 -37
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/LICENSE-MIT.txt +0 -20
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/README.md +0 -176
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/package.json +0 -87
- package/node_modules/request/node_modules/tough-cookie/node_modules/punycode/punycode.js +0 -528
- package/node_modules/request/node_modules/tough-cookie/package.json +0 -67
- package/node_modules/request/node_modules/tough-cookie/public-suffix.txt +0 -5229
- package/node_modules/request/node_modules/tough-cookie/test.js +0 -1625
- package/node_modules/request/node_modules/tunnel-agent/.jshintrc +0 -5
- package/node_modules/request/node_modules/tunnel-agent/LICENSE +0 -55
- package/node_modules/request/node_modules/tunnel-agent/README.md +0 -4
- package/node_modules/request/node_modules/tunnel-agent/index.js +0 -236
- package/node_modules/request/node_modules/tunnel-agent/package.json +0 -46
- package/node_modules/request/package.json +0 -77
- package/node_modules/request/request.js +0 -1428
- package/test/fixtures/github-response.json +0 -1367
- package/test/index.js +0 -55
@@ -1 +0,0 @@
|
|
1
|
-
exports.x = 1;
|
@@ -1 +0,0 @@
|
|
1
|
-
exports.y = 2;
|
@@ -1 +0,0 @@
|
|
1
|
-
exports.z = 3;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
Copyright (c) 2012-2013, Eran Hammer.
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
6
|
-
* Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
8
|
-
* Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
11
|
-
* Neither the name of Eran Hammer nor the
|
12
|
-
names of its contributors may be used to endorse or promote products
|
13
|
-
derived from this software without specific prior written permission.
|
14
|
-
|
15
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
-
DISCLAIMED. IN NO EVENT SHALL ERAN HAMMER BE LIABLE FOR ANY
|
19
|
-
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
-
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -1,11 +0,0 @@
|
|
1
|
-
test:
|
2
|
-
@./node_modules/.bin/lab
|
3
|
-
test-cov:
|
4
|
-
@./node_modules/.bin/lab -r threshold -t 100
|
5
|
-
test-cov-html:
|
6
|
-
@./node_modules/.bin/lab -r html -o coverage.html
|
7
|
-
complexity:
|
8
|
-
@./node_modules/.bin/cr -o complexity.md -f markdown lib
|
9
|
-
|
10
|
-
.PHONY: test test-cov test-cov-html complexity
|
11
|
-
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# sntp
|
2
|
-
|
3
|
-
An SNTP v4 client (RFC4330) for node. Simpy connects to the NTP or SNTP server requested and returns the server time
|
4
|
-
along with the roundtrip duration and clock offset. To adjust the local time to the NTP time, add the returned `t` offset
|
5
|
-
to the local time.
|
6
|
-
|
7
|
-
[](http://travis-ci.org/hueniverse/sntp)
|
8
|
-
|
9
|
-
# Usage
|
10
|
-
|
11
|
-
```javascript
|
12
|
-
var Sntp = require('sntp');
|
13
|
-
|
14
|
-
// All options are optional
|
15
|
-
|
16
|
-
var options = {
|
17
|
-
host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org
|
18
|
-
port: 123, // Defaults to 123 (NTP)
|
19
|
-
resolveReference: true, // Default to false (not resolving)
|
20
|
-
timeout: 1000 // Defaults to zero (no timeout)
|
21
|
-
};
|
22
|
-
|
23
|
-
// Request server time
|
24
|
-
|
25
|
-
Sntp.time(options, function (err, time) {
|
26
|
-
|
27
|
-
if (err) {
|
28
|
-
console.log('Failed: ' + err.message);
|
29
|
-
process.exit(1);
|
30
|
-
}
|
31
|
-
|
32
|
-
console.log('Local clock is off by: ' + time.t + ' milliseconds');
|
33
|
-
process.exit(0);
|
34
|
-
});
|
35
|
-
```
|
36
|
-
|
37
|
-
If an application needs to maintain continuous time synchronization, the module provides a stateful method for
|
38
|
-
querying the current offset only when the last one is too old (defaults to daily).
|
39
|
-
|
40
|
-
```javascript
|
41
|
-
// Request offset once
|
42
|
-
|
43
|
-
Sntp.offset(function (err, offset) {
|
44
|
-
|
45
|
-
console.log(offset); // New (served fresh)
|
46
|
-
|
47
|
-
// Request offset again
|
48
|
-
|
49
|
-
Sntp.offset(function (err, offset) {
|
50
|
-
|
51
|
-
console.log(offset); // Identical (served from cache)
|
52
|
-
});
|
53
|
-
});
|
54
|
-
```
|
55
|
-
|
56
|
-
To set a background offset refresh, start the interval and use the provided now() method. If for any reason the
|
57
|
-
client fails to obtain an up-to-date offset, the current system clock is used.
|
58
|
-
|
59
|
-
```javascript
|
60
|
-
var before = Sntp.now(); // System time without offset
|
61
|
-
|
62
|
-
Sntp.start(function () {
|
63
|
-
|
64
|
-
var now = Sntp.now(); // With offset
|
65
|
-
Sntp.stop();
|
66
|
-
});
|
67
|
-
```
|
68
|
-
|
@@ -1,16 +0,0 @@
|
|
1
|
-
var Sntp = require('../lib');
|
2
|
-
|
3
|
-
// Request offset once
|
4
|
-
|
5
|
-
Sntp.offset(function (err, offset) {
|
6
|
-
|
7
|
-
console.log(offset); // New (served fresh)
|
8
|
-
|
9
|
-
// Request offset again
|
10
|
-
|
11
|
-
Sntp.offset(function (err, offset) {
|
12
|
-
|
13
|
-
console.log(offset); // Identical (served from cache)
|
14
|
-
});
|
15
|
-
});
|
16
|
-
|
@@ -1,25 +0,0 @@
|
|
1
|
-
var Sntp = require('../lib');
|
2
|
-
|
3
|
-
// All options are optional
|
4
|
-
|
5
|
-
var options = {
|
6
|
-
host: 'nist1-sj.ustiming.org', // Defaults to pool.ntp.org
|
7
|
-
port: 123, // Defaults to 123 (NTP)
|
8
|
-
resolveReference: true, // Default to false (not resolving)
|
9
|
-
timeout: 1000 // Defaults to zero (no timeout)
|
10
|
-
};
|
11
|
-
|
12
|
-
// Request server time
|
13
|
-
|
14
|
-
Sntp.time(options, function (err, time) {
|
15
|
-
|
16
|
-
if (err) {
|
17
|
-
console.log('Failed: ' + err.message);
|
18
|
-
process.exit(1);
|
19
|
-
}
|
20
|
-
|
21
|
-
console.log(time);
|
22
|
-
console.log('Local clock is off by: ' + time.t + ' milliseconds');
|
23
|
-
process.exit(0);
|
24
|
-
});
|
25
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
module.exports = require('./lib');
|
@@ -1,409 +0,0 @@
|
|
1
|
-
// Load modules
|
2
|
-
|
3
|
-
var Dgram = require('dgram');
|
4
|
-
var Dns = require('dns');
|
5
|
-
var Hoek = require('hoek');
|
6
|
-
|
7
|
-
|
8
|
-
// Declare internals
|
9
|
-
|
10
|
-
var internals = {};
|
11
|
-
|
12
|
-
|
13
|
-
exports.time = function (options, callback) {
|
14
|
-
|
15
|
-
if (arguments.length !== 2) {
|
16
|
-
callback = arguments[0];
|
17
|
-
options = {};
|
18
|
-
}
|
19
|
-
|
20
|
-
var settings = Hoek.clone(options);
|
21
|
-
settings.host = settings.host || 'pool.ntp.org';
|
22
|
-
settings.port = settings.port || 123;
|
23
|
-
settings.resolveReference = settings.resolveReference || false;
|
24
|
-
|
25
|
-
// Declare variables used by callback
|
26
|
-
|
27
|
-
var timeoutId = 0;
|
28
|
-
var sent = 0;
|
29
|
-
|
30
|
-
// Ensure callback is only called once
|
31
|
-
|
32
|
-
var isFinished = false;
|
33
|
-
var finish = function (err, result) {
|
34
|
-
|
35
|
-
if (timeoutId) {
|
36
|
-
clearTimeout(timeoutId);
|
37
|
-
timeoutId = 0;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (!isFinished) {
|
41
|
-
isFinished = true;
|
42
|
-
socket.removeAllListeners();
|
43
|
-
socket.close();
|
44
|
-
return callback(err, result);
|
45
|
-
}
|
46
|
-
};
|
47
|
-
|
48
|
-
// Create UDP socket
|
49
|
-
|
50
|
-
var socket = Dgram.createSocket('udp4');
|
51
|
-
|
52
|
-
socket.once('error', function (err) {
|
53
|
-
|
54
|
-
return finish(err);
|
55
|
-
});
|
56
|
-
|
57
|
-
// Listen to incoming messages
|
58
|
-
|
59
|
-
socket.on('message', function (buffer, rinfo) {
|
60
|
-
|
61
|
-
var received = Date.now();
|
62
|
-
|
63
|
-
var message = new internals.NtpMessage(buffer);
|
64
|
-
if (!message.isValid) {
|
65
|
-
return finish(new Error('Invalid server response'), message);
|
66
|
-
}
|
67
|
-
|
68
|
-
if (message.originateTimestamp !== sent) {
|
69
|
-
return finish(new Error('Wrong originate timestamp'), message);
|
70
|
-
}
|
71
|
-
|
72
|
-
// Timestamp Name ID When Generated
|
73
|
-
// ------------------------------------------------------------
|
74
|
-
// Originate Timestamp T1 time request sent by client
|
75
|
-
// Receive Timestamp T2 time request received by server
|
76
|
-
// Transmit Timestamp T3 time reply sent by server
|
77
|
-
// Destination Timestamp T4 time reply received by client
|
78
|
-
//
|
79
|
-
// The roundtrip delay d and system clock offset t are defined as:
|
80
|
-
//
|
81
|
-
// d = (T4 - T1) - (T3 - T2) t = ((T2 - T1) + (T3 - T4)) / 2
|
82
|
-
|
83
|
-
var T1 = message.originateTimestamp;
|
84
|
-
var T2 = message.receiveTimestamp;
|
85
|
-
var T3 = message.transmitTimestamp;
|
86
|
-
var T4 = received;
|
87
|
-
|
88
|
-
message.d = (T4 - T1) - (T3 - T2);
|
89
|
-
message.t = ((T2 - T1) + (T3 - T4)) / 2;
|
90
|
-
message.receivedLocally = received;
|
91
|
-
|
92
|
-
if (!settings.resolveReference ||
|
93
|
-
message.stratum !== 'secondary') {
|
94
|
-
|
95
|
-
return finish(null, message);
|
96
|
-
}
|
97
|
-
|
98
|
-
// Resolve reference IP address
|
99
|
-
|
100
|
-
Dns.reverse(message.referenceId, function (err, domains) {
|
101
|
-
|
102
|
-
if (!err) {
|
103
|
-
message.referenceHost = domains[0];
|
104
|
-
}
|
105
|
-
|
106
|
-
return finish(null, message);
|
107
|
-
});
|
108
|
-
});
|
109
|
-
|
110
|
-
// Set timeout
|
111
|
-
|
112
|
-
if (settings.timeout) {
|
113
|
-
timeoutId = setTimeout(function () {
|
114
|
-
|
115
|
-
timeoutId = 0;
|
116
|
-
return finish(new Error('Timeout'));
|
117
|
-
}, settings.timeout);
|
118
|
-
}
|
119
|
-
|
120
|
-
// Construct NTP message
|
121
|
-
|
122
|
-
var message = new Buffer(48);
|
123
|
-
for (var i = 0; i < 48; i++) { // Zero message
|
124
|
-
message[i] = 0;
|
125
|
-
}
|
126
|
-
|
127
|
-
message[0] = (0 << 6) + (4 << 3) + (3 << 0) // Set version number to 4 and Mode to 3 (client)
|
128
|
-
sent = Date.now();
|
129
|
-
internals.fromMsecs(sent, message, 40); // Set transmit timestamp (returns as originate)
|
130
|
-
|
131
|
-
// Send NTP request
|
132
|
-
|
133
|
-
socket.send(message, 0, message.length, settings.port, settings.host, function (err, bytes) {
|
134
|
-
|
135
|
-
if (err ||
|
136
|
-
bytes !== 48) {
|
137
|
-
|
138
|
-
return finish(err || new Error('Could not send entire message'));
|
139
|
-
}
|
140
|
-
});
|
141
|
-
};
|
142
|
-
|
143
|
-
|
144
|
-
internals.NtpMessage = function (buffer) {
|
145
|
-
|
146
|
-
this.isValid = false;
|
147
|
-
|
148
|
-
// Validate
|
149
|
-
|
150
|
-
if (buffer.length !== 48) {
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
|
154
|
-
// Leap indicator
|
155
|
-
|
156
|
-
var li = (buffer[0] >> 6);
|
157
|
-
switch (li) {
|
158
|
-
case 0: this.leapIndicator = 'no-warning'; break;
|
159
|
-
case 1: this.leapIndicator = 'last-minute-61'; break;
|
160
|
-
case 2: this.leapIndicator = 'last-minute-59'; break;
|
161
|
-
case 3: this.leapIndicator = 'alarm'; break;
|
162
|
-
}
|
163
|
-
|
164
|
-
// Version
|
165
|
-
|
166
|
-
var vn = ((buffer[0] & 0x38) >> 3);
|
167
|
-
this.version = vn;
|
168
|
-
|
169
|
-
// Mode
|
170
|
-
|
171
|
-
var mode = (buffer[0] & 0x7);
|
172
|
-
switch (mode) {
|
173
|
-
case 1: this.mode = 'symmetric-active'; break;
|
174
|
-
case 2: this.mode = 'symmetric-passive'; break;
|
175
|
-
case 3: this.mode = 'client'; break;
|
176
|
-
case 4: this.mode = 'server'; break;
|
177
|
-
case 5: this.mode = 'broadcast'; break;
|
178
|
-
case 0:
|
179
|
-
case 6:
|
180
|
-
case 7: this.mode = 'reserved'; break;
|
181
|
-
}
|
182
|
-
|
183
|
-
// Stratum
|
184
|
-
|
185
|
-
var stratum = buffer[1];
|
186
|
-
if (stratum === 0) {
|
187
|
-
this.stratum = 'death';
|
188
|
-
}
|
189
|
-
else if (stratum === 1) {
|
190
|
-
this.stratum = 'primary';
|
191
|
-
}
|
192
|
-
else if (stratum <= 15) {
|
193
|
-
this.stratum = 'secondary';
|
194
|
-
}
|
195
|
-
else {
|
196
|
-
this.stratum = 'reserved';
|
197
|
-
}
|
198
|
-
|
199
|
-
// Poll interval (msec)
|
200
|
-
|
201
|
-
this.pollInterval = Math.round(Math.pow(2, buffer[2])) * 1000;
|
202
|
-
|
203
|
-
// Precision (msecs)
|
204
|
-
|
205
|
-
this.precision = Math.pow(2, buffer[3]) * 1000;
|
206
|
-
|
207
|
-
// Root delay (msecs)
|
208
|
-
|
209
|
-
var rootDelay = 256 * (256 * (256 * buffer[4] + buffer[5]) + buffer[6]) + buffer[7];
|
210
|
-
this.rootDelay = 1000 * (rootDelay / 0x10000);
|
211
|
-
|
212
|
-
// Root dispersion (msecs)
|
213
|
-
|
214
|
-
this.rootDispersion = ((buffer[8] << 8) + buffer[9] + ((buffer[10] << 8) + buffer[11]) / Math.pow(2, 16)) * 1000;
|
215
|
-
|
216
|
-
// Reference identifier
|
217
|
-
|
218
|
-
this.referenceId = '';
|
219
|
-
switch (this.stratum) {
|
220
|
-
case 'death':
|
221
|
-
case 'primary':
|
222
|
-
this.referenceId = String.fromCharCode(buffer[12]) + String.fromCharCode(buffer[13]) + String.fromCharCode(buffer[14]) + String.fromCharCode(buffer[15]);
|
223
|
-
break;
|
224
|
-
case 'secondary':
|
225
|
-
this.referenceId = '' + buffer[12] + '.' + buffer[13] + '.' + buffer[14] + '.' + buffer[15];
|
226
|
-
break;
|
227
|
-
}
|
228
|
-
|
229
|
-
// Reference timestamp
|
230
|
-
|
231
|
-
this.referenceTimestamp = internals.toMsecs(buffer, 16);
|
232
|
-
|
233
|
-
// Originate timestamp
|
234
|
-
|
235
|
-
this.originateTimestamp = internals.toMsecs(buffer, 24);
|
236
|
-
|
237
|
-
// Receive timestamp
|
238
|
-
|
239
|
-
this.receiveTimestamp = internals.toMsecs(buffer, 32);
|
240
|
-
|
241
|
-
// Transmit timestamp
|
242
|
-
|
243
|
-
this.transmitTimestamp = internals.toMsecs(buffer, 40);
|
244
|
-
|
245
|
-
// Validate
|
246
|
-
|
247
|
-
if (this.version === 4 &&
|
248
|
-
this.stratum !== 'reserved' &&
|
249
|
-
this.mode === 'server' &&
|
250
|
-
this.originateTimestamp &&
|
251
|
-
this.receiveTimestamp &&
|
252
|
-
this.transmitTimestamp) {
|
253
|
-
|
254
|
-
this.isValid = true;
|
255
|
-
}
|
256
|
-
|
257
|
-
return this;
|
258
|
-
};
|
259
|
-
|
260
|
-
|
261
|
-
internals.toMsecs = function (buffer, offset) {
|
262
|
-
|
263
|
-
var seconds = 0;
|
264
|
-
var fraction = 0;
|
265
|
-
|
266
|
-
for (var i = 0; i < 4; ++i) {
|
267
|
-
seconds = (seconds * 256) + buffer[offset + i];
|
268
|
-
}
|
269
|
-
|
270
|
-
for (i = 4; i < 8; ++i) {
|
271
|
-
fraction = (fraction * 256) + buffer[offset + i];
|
272
|
-
}
|
273
|
-
|
274
|
-
return ((seconds - 2208988800 + (fraction / Math.pow(2, 32))) * 1000);
|
275
|
-
};
|
276
|
-
|
277
|
-
|
278
|
-
internals.fromMsecs = function (ts, buffer, offset) {
|
279
|
-
|
280
|
-
var seconds = Math.floor(ts / 1000) + 2208988800;
|
281
|
-
var fraction = Math.round((ts % 1000) / 1000 * Math.pow(2, 32));
|
282
|
-
|
283
|
-
buffer[offset + 0] = (seconds & 0xFF000000) >> 24;
|
284
|
-
buffer[offset + 1] = (seconds & 0x00FF0000) >> 16;
|
285
|
-
buffer[offset + 2] = (seconds & 0x0000FF00) >> 8;
|
286
|
-
buffer[offset + 3] = (seconds & 0x000000FF);
|
287
|
-
|
288
|
-
buffer[offset + 4] = (fraction & 0xFF000000) >> 24;
|
289
|
-
buffer[offset + 5] = (fraction & 0x00FF0000) >> 16;
|
290
|
-
buffer[offset + 6] = (fraction & 0x0000FF00) >> 8;
|
291
|
-
buffer[offset + 7] = (fraction & 0x000000FF);
|
292
|
-
};
|
293
|
-
|
294
|
-
|
295
|
-
// Offset singleton
|
296
|
-
|
297
|
-
internals.last = {
|
298
|
-
offset: 0,
|
299
|
-
expires: 0,
|
300
|
-
host: '',
|
301
|
-
port: 0
|
302
|
-
};
|
303
|
-
|
304
|
-
|
305
|
-
exports.offset = function (options, callback) {
|
306
|
-
|
307
|
-
if (arguments.length !== 2) {
|
308
|
-
callback = arguments[0];
|
309
|
-
options = {};
|
310
|
-
}
|
311
|
-
|
312
|
-
var now = Date.now();
|
313
|
-
var clockSyncRefresh = options.clockSyncRefresh || 24 * 60 * 60 * 1000; // Daily
|
314
|
-
|
315
|
-
if (internals.last.offset &&
|
316
|
-
internals.last.host === options.host &&
|
317
|
-
internals.last.port === options.port &&
|
318
|
-
now < internals.last.expires) {
|
319
|
-
|
320
|
-
process.nextTick(function () {
|
321
|
-
|
322
|
-
callback(null, internals.last.offset);
|
323
|
-
});
|
324
|
-
|
325
|
-
return;
|
326
|
-
}
|
327
|
-
|
328
|
-
exports.time(options, function (err, time) {
|
329
|
-
|
330
|
-
if (err) {
|
331
|
-
return callback(err, 0);
|
332
|
-
}
|
333
|
-
|
334
|
-
internals.last = {
|
335
|
-
offset: Math.round(time.t),
|
336
|
-
expires: now + clockSyncRefresh,
|
337
|
-
host: options.host,
|
338
|
-
port: options.port
|
339
|
-
};
|
340
|
-
|
341
|
-
return callback(null, internals.last.offset);
|
342
|
-
});
|
343
|
-
};
|
344
|
-
|
345
|
-
|
346
|
-
// Now singleton
|
347
|
-
|
348
|
-
internals.now = {
|
349
|
-
intervalId: 0
|
350
|
-
};
|
351
|
-
|
352
|
-
|
353
|
-
exports.start = function (options, callback) {
|
354
|
-
|
355
|
-
if (arguments.length !== 2) {
|
356
|
-
callback = arguments[0];
|
357
|
-
options = {};
|
358
|
-
}
|
359
|
-
|
360
|
-
if (internals.now.intervalId) {
|
361
|
-
process.nextTick(function () {
|
362
|
-
|
363
|
-
callback();
|
364
|
-
});
|
365
|
-
|
366
|
-
return;
|
367
|
-
}
|
368
|
-
|
369
|
-
exports.offset(options, function (err, offset) {
|
370
|
-
|
371
|
-
internals.now.intervalId = setInterval(function () {
|
372
|
-
|
373
|
-
exports.offset(options, function () { });
|
374
|
-
}, options.clockSyncRefresh || 24 * 60 * 60 * 1000); // Daily
|
375
|
-
|
376
|
-
return callback();
|
377
|
-
});
|
378
|
-
};
|
379
|
-
|
380
|
-
|
381
|
-
exports.stop = function () {
|
382
|
-
|
383
|
-
if (!internals.now.intervalId) {
|
384
|
-
return;
|
385
|
-
}
|
386
|
-
|
387
|
-
clearInterval(internals.now.intervalId);
|
388
|
-
internals.now.intervalId = 0;
|
389
|
-
};
|
390
|
-
|
391
|
-
|
392
|
-
exports.isLive = function () {
|
393
|
-
|
394
|
-
return !!internals.now.intervalId;
|
395
|
-
};
|
396
|
-
|
397
|
-
|
398
|
-
exports.now = function () {
|
399
|
-
|
400
|
-
var now = Date.now();
|
401
|
-
if (!exports.isLive() ||
|
402
|
-
now >= internals.last.expires) {
|
403
|
-
|
404
|
-
return now;
|
405
|
-
}
|
406
|
-
|
407
|
-
return now + internals.last.offset;
|
408
|
-
};
|
409
|
-
|
@@ -1,65 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "sntp",
|
3
|
-
"description": "SNTP Client",
|
4
|
-
"version": "0.2.4",
|
5
|
-
"author": {
|
6
|
-
"name": "Eran Hammer",
|
7
|
-
"email": "eran@hueniverse.com",
|
8
|
-
"url": "http://hueniverse.com"
|
9
|
-
},
|
10
|
-
"contributors": [],
|
11
|
-
"repository": {
|
12
|
-
"type": "git",
|
13
|
-
"url": "git://github.com/hueniverse/sntp"
|
14
|
-
},
|
15
|
-
"main": "index",
|
16
|
-
"keywords": [
|
17
|
-
"sntp",
|
18
|
-
"ntp",
|
19
|
-
"time"
|
20
|
-
],
|
21
|
-
"engines": {
|
22
|
-
"node": ">=0.8.0"
|
23
|
-
},
|
24
|
-
"dependencies": {
|
25
|
-
"hoek": "0.9.x"
|
26
|
-
},
|
27
|
-
"devDependencies": {
|
28
|
-
"lab": "0.1.x",
|
29
|
-
"complexity-report": "0.x.x"
|
30
|
-
},
|
31
|
-
"scripts": {
|
32
|
-
"test": "make test-cov"
|
33
|
-
},
|
34
|
-
"licenses": [
|
35
|
-
{
|
36
|
-
"type": "BSD",
|
37
|
-
"url": "http://github.com/hueniverse/sntp/raw/master/LICENSE"
|
38
|
-
}
|
39
|
-
],
|
40
|
-
"_id": "sntp@0.2.4",
|
41
|
-
"dist": {
|
42
|
-
"shasum": "fb885f18b0f3aad189f824862536bceeec750900",
|
43
|
-
"tarball": "http://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz"
|
44
|
-
},
|
45
|
-
"_from": "sntp@0.2.x",
|
46
|
-
"_npmVersion": "1.2.18",
|
47
|
-
"_npmUser": {
|
48
|
-
"name": "hueniverse",
|
49
|
-
"email": "eran@hueniverse.com"
|
50
|
-
},
|
51
|
-
"maintainers": [
|
52
|
-
{
|
53
|
-
"name": "hueniverse",
|
54
|
-
"email": "eran@hueniverse.com"
|
55
|
-
}
|
56
|
-
],
|
57
|
-
"directories": {},
|
58
|
-
"_shasum": "fb885f18b0f3aad189f824862536bceeec750900",
|
59
|
-
"_resolved": "https://registry.npmjs.org/sntp/-/sntp-0.2.4.tgz",
|
60
|
-
"bugs": {
|
61
|
-
"url": "https://github.com/hueniverse/sntp/issues"
|
62
|
-
},
|
63
|
-
"readme": "ERROR: No README data found!",
|
64
|
-
"homepage": "https://github.com/hueniverse/sntp"
|
65
|
-
}
|