@agnostack/next-shopify 1.15.0-beta.8 → 1.15.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 (333) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/README.md +9 -8
  3. package/dist/lib/handlers/api/auth.js +15 -11
  4. package/dist/lib/handlers/api/auth.js.map +1 -1
  5. package/dist/lib/handlers/api/billing.js +13 -9
  6. package/dist/lib/handlers/api/billing.js.map +1 -1
  7. package/dist/lib/handlers/api/callback.js +37 -33
  8. package/dist/lib/handlers/api/callback.js.map +1 -1
  9. package/dist/lib/handlers/api/index.js +25 -7
  10. package/dist/lib/handlers/api/index.js.map +1 -1
  11. package/dist/lib/handlers/api/uninstall.js +12 -8
  12. package/dist/lib/handlers/api/uninstall.js.map +1 -1
  13. package/dist/lib/handlers/api/verifiable/appInstallation.js +11 -7
  14. package/dist/lib/handlers/api/verifiable/appInstallation.js.map +1 -1
  15. package/dist/lib/handlers/api/verifiable/graph.js +26 -22
  16. package/dist/lib/handlers/api/verifiable/graph.js.map +1 -1
  17. package/dist/lib/handlers/api/verifiable/index.js +21 -5
  18. package/dist/lib/handlers/api/verifiable/index.js.map +1 -1
  19. package/dist/lib/handlers/api/verifiable/proxy.js +39 -32
  20. package/dist/lib/handlers/api/verifiable/proxy.js.map +1 -1
  21. package/dist/lib/handlers/api/verifiable/rest.js +23 -19
  22. package/dist/lib/handlers/api/verifiable/rest.js.map +1 -1
  23. package/dist/lib/handlers/api/verifiable/token.js +27 -23
  24. package/dist/lib/handlers/api/verifiable/token.js.map +1 -1
  25. package/dist/lib/handlers/api/webhook.js +13 -9
  26. package/dist/lib/handlers/api/webhook.js.map +1 -1
  27. package/dist/lib/handlers/index.js +18 -2
  28. package/dist/lib/handlers/index.js.map +1 -1
  29. package/dist/lib/handlers/ssr/index.js +18 -2
  30. package/dist/lib/handlers/ssr/index.js.map +1 -1
  31. package/dist/lib/handlers/ssr/protect.js +24 -17
  32. package/dist/lib/handlers/ssr/protect.js.map +1 -1
  33. package/dist/lib/handlers/ssr/wrap.js +10 -6
  34. package/dist/lib/handlers/ssr/wrap.js.map +1 -1
  35. package/dist/lib/index.js +23 -4
  36. package/dist/lib/index.js.map +1 -1
  37. package/dist/lib/utils/billing.js +23 -18
  38. package/dist/lib/utils/billing.js.map +1 -1
  39. package/dist/lib/utils/crypto.js +25 -15
  40. package/dist/lib/utils/crypto.js.map +1 -1
  41. package/dist/lib/utils/firebase.js +29 -17
  42. package/dist/lib/utils/firebase.js.map +1 -1
  43. package/dist/lib/utils/headers.js +13 -6
  44. package/dist/lib/utils/headers.js.map +1 -1
  45. package/dist/lib/utils/index.js +24 -8
  46. package/dist/lib/utils/index.js.map +1 -1
  47. package/dist/lib/utils/session.js +64 -59
  48. package/dist/lib/utils/session.js.map +1 -1
  49. package/dist/lib/utils/shopify-api-js/oauth.js +23 -16
  50. package/dist/lib/utils/shopify-api-js/oauth.js.map +1 -1
  51. package/dist/lib/utils/shopify.js +37 -25
  52. package/dist/lib/utils/shopify.js.map +1 -1
  53. package/dist/lib/utils/token.js +15 -11
  54. package/dist/lib/utils/token.js.map +1 -1
  55. package/dist/plugins/index.d.ts +1 -0
  56. package/dist/plugins/index.d.ts.map +1 -1
  57. package/dist/plugins/index.js +18 -1
  58. package/dist/plugins/index.js.map +1 -1
  59. package/dist/plugins/withShopify.js +83 -77
  60. package/dist/plugins/withShopify.js.map +1 -1
  61. package/dist/react/hooks/index.js +17 -1
  62. package/dist/react/hooks/index.js.map +1 -1
  63. package/dist/react/hooks/useVerification.d.ts +1 -1
  64. package/dist/react/hooks/useVerification.js +23 -7
  65. package/dist/react/hooks/useVerification.js.map +1 -1
  66. package/dist/react/index.d.ts +1 -0
  67. package/dist/react/index.d.ts.map +1 -1
  68. package/dist/react/index.js +18 -1
  69. package/dist/react/index.js.map +1 -1
  70. package/dist/runtime/index.js +17 -1
  71. package/dist/runtime/index.js.map +1 -1
  72. package/dist/shared/WebCrypto.d.ts +55 -0
  73. package/dist/shared/WebCrypto.d.ts.map +1 -0
  74. package/dist/shared/WebCrypto.js +342 -0
  75. package/dist/shared/WebCrypto.js.map +1 -0
  76. package/dist/shared/constants.js +15 -11
  77. package/dist/shared/constants.js.map +1 -1
  78. package/dist/shared/datetime.js +110 -83
  79. package/dist/shared/datetime.js.map +1 -1
  80. package/dist/shared/display.js +231 -151
  81. package/dist/shared/display.js.map +1 -1
  82. package/dist/shared/errors.js +12 -5
  83. package/dist/shared/errors.js.map +1 -1
  84. package/dist/shared/graph.js +14 -11
  85. package/dist/shared/graph.js.map +1 -1
  86. package/dist/shared/index.d.ts +1 -1
  87. package/dist/shared/index.d.ts.map +1 -1
  88. package/dist/shared/index.js +32 -11
  89. package/dist/shared/index.js.map +1 -1
  90. package/dist/shared/match.js +25 -17
  91. package/dist/shared/match.js.map +1 -1
  92. package/dist/shared/request.js +19 -13
  93. package/dist/shared/request.js.map +1 -1
  94. package/dist/shared/shopify.js +31 -21
  95. package/dist/shared/shopify.js.map +1 -1
  96. package/dist/shared/uuid.js +8 -3
  97. package/dist/shared/uuid.js.map +1 -1
  98. package/dist/shared/verification.d.ts +12 -5
  99. package/dist/shared/verification.d.ts.map +1 -1
  100. package/dist/shared/verification.js +34 -22
  101. package/dist/shared/verification.js.map +1 -1
  102. package/dist/umd/verification/index.js +1234 -0
  103. package/dist/umd/verification/index.js.map +1 -0
  104. package/dist/umd/verification/plugins/index.d.ts +3 -0
  105. package/dist/umd/{plugins → verification/plugins}/index.d.ts.map +1 -1
  106. package/dist/umd/{react → verification/react}/hooks/useVerification.d.ts +1 -1
  107. package/dist/umd/verification/react/index.d.ts +3 -0
  108. package/dist/umd/verification/react/index.d.ts.map +1 -0
  109. package/dist/umd/verification/shared/WebCrypto.d.ts +55 -0
  110. package/dist/umd/verification/shared/WebCrypto.d.ts.map +1 -0
  111. package/dist/umd/{shared → verification/shared}/index.d.ts +1 -1
  112. package/dist/umd/{shared → verification/shared}/index.d.ts.map +1 -1
  113. package/dist/umd/{shared → verification/shared}/verification.d.ts +12 -5
  114. package/dist/umd/{shared → verification/shared}/verification.d.ts.map +1 -1
  115. package/dist/umd/verification/verification/index.d.ts +4 -0
  116. package/dist/umd/verification/{index.d.ts.map → verification/index.d.ts.map} +1 -1
  117. package/dist/umd/verification/{utils → verification/utils}/rawbody.d.ts.map +1 -1
  118. package/dist/umd/verification/verification/verification.d.ts +10 -0
  119. package/dist/umd/verification/{verification.d.ts.map → verification/verification.d.ts.map} +1 -1
  120. package/dist/verification/index.d.ts +2 -0
  121. package/dist/verification/index.d.ts.map +1 -1
  122. package/dist/verification/index.js +19 -1
  123. package/dist/verification/index.js.map +1 -1
  124. package/dist/verification/utils/errors.js +5 -1
  125. package/dist/verification/utils/errors.js.map +1 -1
  126. package/dist/verification/utils/index.js +18 -2
  127. package/dist/verification/utils/index.js.map +1 -1
  128. package/dist/verification/utils/rawbody.d.ts.map +1 -1
  129. package/dist/verification/utils/rawbody.js +39 -36
  130. package/dist/verification/utils/rawbody.js.map +1 -1
  131. package/dist/verification/verification.d.ts +3 -1
  132. package/dist/verification/verification.d.ts.map +1 -1
  133. package/dist/verification/verification.js +71 -61
  134. package/dist/verification/verification.js.map +1 -1
  135. package/node_modules/bytes/History.md +97 -0
  136. package/node_modules/bytes/LICENSE +23 -0
  137. package/node_modules/bytes/Readme.md +152 -0
  138. package/node_modules/bytes/index.js +170 -0
  139. package/node_modules/bytes/package.json +42 -0
  140. package/node_modules/depd/History.md +103 -0
  141. package/node_modules/depd/LICENSE +22 -0
  142. package/node_modules/depd/Readme.md +280 -0
  143. package/node_modules/depd/index.js +538 -0
  144. package/node_modules/depd/lib/browser/index.js +77 -0
  145. package/node_modules/depd/package.json +45 -0
  146. package/node_modules/http-errors/HISTORY.md +180 -0
  147. package/node_modules/http-errors/LICENSE +23 -0
  148. package/node_modules/http-errors/README.md +169 -0
  149. package/node_modules/http-errors/index.js +289 -0
  150. package/node_modules/http-errors/package.json +50 -0
  151. package/node_modules/iconv-lite/Changelog.md +162 -0
  152. package/node_modules/iconv-lite/LICENSE +21 -0
  153. package/node_modules/iconv-lite/README.md +156 -0
  154. package/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
  155. package/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
  156. package/node_modules/iconv-lite/encodings/index.js +22 -0
  157. package/node_modules/iconv-lite/encodings/internal.js +188 -0
  158. package/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
  159. package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
  160. package/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
  161. package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
  162. package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
  163. package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
  164. package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
  165. package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
  166. package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
  167. package/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
  168. package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
  169. package/node_modules/iconv-lite/encodings/utf16.js +177 -0
  170. package/node_modules/iconv-lite/encodings/utf7.js +290 -0
  171. package/node_modules/iconv-lite/lib/bom-handling.js +52 -0
  172. package/node_modules/iconv-lite/lib/extend-node.js +217 -0
  173. package/node_modules/iconv-lite/lib/index.d.ts +24 -0
  174. package/node_modules/iconv-lite/lib/index.js +153 -0
  175. package/node_modules/iconv-lite/lib/streams.js +121 -0
  176. package/node_modules/iconv-lite/package.json +46 -0
  177. package/node_modules/inherits/LICENSE +16 -0
  178. package/node_modules/inherits/README.md +42 -0
  179. package/node_modules/inherits/inherits.js +9 -0
  180. package/node_modules/inherits/inherits_browser.js +27 -0
  181. package/node_modules/inherits/package.json +29 -0
  182. package/node_modules/raw-body/HISTORY.md +308 -0
  183. package/node_modules/raw-body/LICENSE +22 -0
  184. package/node_modules/raw-body/README.md +223 -0
  185. package/node_modules/raw-body/SECURITY.md +24 -0
  186. package/node_modules/raw-body/index.d.ts +87 -0
  187. package/node_modules/raw-body/index.js +336 -0
  188. package/node_modules/raw-body/package.json +49 -0
  189. package/node_modules/safer-buffer/LICENSE +21 -0
  190. package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
  191. package/node_modules/safer-buffer/Readme.md +156 -0
  192. package/node_modules/safer-buffer/dangerous.js +58 -0
  193. package/node_modules/safer-buffer/package.json +34 -0
  194. package/node_modules/safer-buffer/safer.js +77 -0
  195. package/node_modules/safer-buffer/tests.js +406 -0
  196. package/node_modules/setprototypeof/LICENSE +13 -0
  197. package/node_modules/setprototypeof/README.md +31 -0
  198. package/node_modules/setprototypeof/index.d.ts +2 -0
  199. package/node_modules/setprototypeof/index.js +17 -0
  200. package/node_modules/setprototypeof/package.json +38 -0
  201. package/node_modules/setprototypeof/test/index.js +24 -0
  202. package/node_modules/statuses/HISTORY.md +82 -0
  203. package/node_modules/statuses/LICENSE +23 -0
  204. package/node_modules/statuses/README.md +136 -0
  205. package/node_modules/statuses/codes.json +65 -0
  206. package/node_modules/statuses/index.js +146 -0
  207. package/node_modules/statuses/package.json +49 -0
  208. package/node_modules/toidentifier/HISTORY.md +9 -0
  209. package/node_modules/toidentifier/LICENSE +21 -0
  210. package/node_modules/toidentifier/README.md +61 -0
  211. package/node_modules/toidentifier/index.js +32 -0
  212. package/node_modules/toidentifier/package.json +38 -0
  213. package/node_modules/unpipe/HISTORY.md +4 -0
  214. package/node_modules/unpipe/LICENSE +22 -0
  215. package/node_modules/unpipe/README.md +43 -0
  216. package/node_modules/unpipe/index.js +69 -0
  217. package/node_modules/unpipe/package.json +27 -0
  218. package/package.json +15 -14
  219. package/dist/shared/subtlecrypto.d.ts +0 -41
  220. package/dist/shared/subtlecrypto.d.ts.map +0 -1
  221. package/dist/shared/subtlecrypto.js +0 -256
  222. package/dist/shared/subtlecrypto.js.map +0 -1
  223. package/dist/umd/plugins/index.d.ts +0 -2
  224. package/dist/umd/react/index.d.ts +0 -2
  225. package/dist/umd/react/index.d.ts.map +0 -1
  226. package/dist/umd/shared/subtlecrypto.d.ts +0 -41
  227. package/dist/umd/shared/subtlecrypto.d.ts.map +0 -1
  228. package/dist/umd/verification/index.d.ts +0 -2
  229. package/dist/umd/verification/verification.d.ts +0 -8
  230. package/dist/umd/verification.js +0 -641
  231. package/dist/umd/verification.js.map +0 -1
  232. /package/dist/umd/{lib → verification/lib}/handlers/api/auth.d.ts +0 -0
  233. /package/dist/umd/{lib → verification/lib}/handlers/api/auth.d.ts.map +0 -0
  234. /package/dist/umd/{lib → verification/lib}/handlers/api/billing.d.ts +0 -0
  235. /package/dist/umd/{lib → verification/lib}/handlers/api/billing.d.ts.map +0 -0
  236. /package/dist/umd/{lib → verification/lib}/handlers/api/callback.d.ts +0 -0
  237. /package/dist/umd/{lib → verification/lib}/handlers/api/callback.d.ts.map +0 -0
  238. /package/dist/umd/{lib → verification/lib}/handlers/api/index.d.ts +0 -0
  239. /package/dist/umd/{lib → verification/lib}/handlers/api/index.d.ts.map +0 -0
  240. /package/dist/umd/{lib → verification/lib}/handlers/api/types.d.ts +0 -0
  241. /package/dist/umd/{lib → verification/lib}/handlers/api/types.d.ts.map +0 -0
  242. /package/dist/umd/{lib → verification/lib}/handlers/api/uninstall.d.ts +0 -0
  243. /package/dist/umd/{lib → verification/lib}/handlers/api/uninstall.d.ts.map +0 -0
  244. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/appInstallation.d.ts +0 -0
  245. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/appInstallation.d.ts.map +0 -0
  246. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/graph.d.ts +0 -0
  247. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/graph.d.ts.map +0 -0
  248. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/index.d.ts +0 -0
  249. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/index.d.ts.map +0 -0
  250. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/proxy.d.ts +0 -0
  251. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/proxy.d.ts.map +0 -0
  252. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/rest.d.ts +0 -0
  253. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/rest.d.ts.map +0 -0
  254. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/token.d.ts +0 -0
  255. /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/token.d.ts.map +0 -0
  256. /package/dist/umd/{lib → verification/lib}/handlers/api/webhook.d.ts +0 -0
  257. /package/dist/umd/{lib → verification/lib}/handlers/api/webhook.d.ts.map +0 -0
  258. /package/dist/umd/{lib → verification/lib}/handlers/index.d.ts +0 -0
  259. /package/dist/umd/{lib → verification/lib}/handlers/index.d.ts.map +0 -0
  260. /package/dist/umd/{lib → verification/lib}/handlers/ssr/index.d.ts +0 -0
  261. /package/dist/umd/{lib → verification/lib}/handlers/ssr/index.d.ts.map +0 -0
  262. /package/dist/umd/{lib → verification/lib}/handlers/ssr/protect.d.ts +0 -0
  263. /package/dist/umd/{lib → verification/lib}/handlers/ssr/protect.d.ts.map +0 -0
  264. /package/dist/umd/{lib → verification/lib}/handlers/ssr/types.d.ts +0 -0
  265. /package/dist/umd/{lib → verification/lib}/handlers/ssr/types.d.ts.map +0 -0
  266. /package/dist/umd/{lib → verification/lib}/handlers/ssr/wrap.d.ts +0 -0
  267. /package/dist/umd/{lib → verification/lib}/handlers/ssr/wrap.d.ts.map +0 -0
  268. /package/dist/umd/{lib → verification/lib}/handlers/types.d.ts +0 -0
  269. /package/dist/umd/{lib → verification/lib}/handlers/types.d.ts.map +0 -0
  270. /package/dist/umd/{lib → verification/lib}/index.d.ts +0 -0
  271. /package/dist/umd/{lib → verification/lib}/index.d.ts.map +0 -0
  272. /package/dist/umd/{lib → verification/lib}/types.d.ts +0 -0
  273. /package/dist/umd/{lib → verification/lib}/types.d.ts.map +0 -0
  274. /package/dist/umd/{lib → verification/lib}/utils/billing.d.ts +0 -0
  275. /package/dist/umd/{lib → verification/lib}/utils/billing.d.ts.map +0 -0
  276. /package/dist/umd/{lib → verification/lib}/utils/crypto.d.ts +0 -0
  277. /package/dist/umd/{lib → verification/lib}/utils/crypto.d.ts.map +0 -0
  278. /package/dist/umd/{lib → verification/lib}/utils/firebase.d.ts +0 -0
  279. /package/dist/umd/{lib → verification/lib}/utils/firebase.d.ts.map +0 -0
  280. /package/dist/umd/{lib → verification/lib}/utils/headers.d.ts +0 -0
  281. /package/dist/umd/{lib → verification/lib}/utils/headers.d.ts.map +0 -0
  282. /package/dist/umd/{lib → verification/lib}/utils/index.d.ts +0 -0
  283. /package/dist/umd/{lib → verification/lib}/utils/index.d.ts.map +0 -0
  284. /package/dist/umd/{lib → verification/lib}/utils/session.d.ts +0 -0
  285. /package/dist/umd/{lib → verification/lib}/utils/session.d.ts.map +0 -0
  286. /package/dist/umd/{lib → verification/lib}/utils/shopify-api-js/oauth.d.ts +0 -0
  287. /package/dist/umd/{lib → verification/lib}/utils/shopify-api-js/oauth.d.ts.map +0 -0
  288. /package/dist/umd/{lib → verification/lib}/utils/shopify.d.ts +0 -0
  289. /package/dist/umd/{lib → verification/lib}/utils/shopify.d.ts.map +0 -0
  290. /package/dist/umd/{lib → verification/lib}/utils/token.d.ts +0 -0
  291. /package/dist/umd/{lib → verification/lib}/utils/token.d.ts.map +0 -0
  292. /package/dist/umd/{lib → verification/lib}/utils/types.d.ts +0 -0
  293. /package/dist/umd/{lib → verification/lib}/utils/types.d.ts.map +0 -0
  294. /package/dist/umd/{plugins → verification/plugins}/types.d.ts +0 -0
  295. /package/dist/umd/{plugins → verification/plugins}/types.d.ts.map +0 -0
  296. /package/dist/umd/{plugins → verification/plugins}/withShopify.d.ts +0 -0
  297. /package/dist/umd/{plugins → verification/plugins}/withShopify.d.ts.map +0 -0
  298. /package/dist/umd/{react → verification/react}/hooks/index.d.ts +0 -0
  299. /package/dist/umd/{react → verification/react}/hooks/index.d.ts.map +0 -0
  300. /package/dist/umd/{react → verification/react}/hooks/useVerification.d.ts.map +0 -0
  301. /package/dist/umd/{react → verification/react}/types.d.ts +0 -0
  302. /package/dist/umd/{react → verification/react}/types.d.ts.map +0 -0
  303. /package/dist/umd/{runtime → verification/runtime}/index.d.ts +0 -0
  304. /package/dist/umd/{runtime → verification/runtime}/index.d.ts.map +0 -0
  305. /package/dist/umd/{runtime → verification/runtime}/types.d.ts +0 -0
  306. /package/dist/umd/{runtime → verification/runtime}/types.d.ts.map +0 -0
  307. /package/dist/umd/{shared → verification/shared}/constants.d.ts +0 -0
  308. /package/dist/umd/{shared → verification/shared}/constants.d.ts.map +0 -0
  309. /package/dist/umd/{shared → verification/shared}/datetime.d.ts +0 -0
  310. /package/dist/umd/{shared → verification/shared}/datetime.d.ts.map +0 -0
  311. /package/dist/umd/{shared → verification/shared}/display.d.ts +0 -0
  312. /package/dist/umd/{shared → verification/shared}/display.d.ts.map +0 -0
  313. /package/dist/umd/{shared → verification/shared}/errors.d.ts +0 -0
  314. /package/dist/umd/{shared → verification/shared}/errors.d.ts.map +0 -0
  315. /package/dist/umd/{shared → verification/shared}/graph.d.ts +0 -0
  316. /package/dist/umd/{shared → verification/shared}/graph.d.ts.map +0 -0
  317. /package/dist/umd/{shared → verification/shared}/match.d.ts +0 -0
  318. /package/dist/umd/{shared → verification/shared}/match.d.ts.map +0 -0
  319. /package/dist/umd/{shared → verification/shared}/request.d.ts +0 -0
  320. /package/dist/umd/{shared → verification/shared}/request.d.ts.map +0 -0
  321. /package/dist/umd/{shared → verification/shared}/shopify.d.ts +0 -0
  322. /package/dist/umd/{shared → verification/shared}/shopify.d.ts.map +0 -0
  323. /package/dist/umd/{shared → verification/shared}/types.d.ts +0 -0
  324. /package/dist/umd/{shared → verification/shared}/types.d.ts.map +0 -0
  325. /package/dist/umd/{shared → verification/shared}/uuid.d.ts +0 -0
  326. /package/dist/umd/{shared → verification/shared}/uuid.d.ts.map +0 -0
  327. /package/dist/umd/verification/{types.d.ts → verification/types.d.ts} +0 -0
  328. /package/dist/umd/verification/{types.d.ts.map → verification/types.d.ts.map} +0 -0
  329. /package/dist/umd/verification/{utils → verification/utils}/errors.d.ts +0 -0
  330. /package/dist/umd/verification/{utils → verification/utils}/errors.d.ts.map +0 -0
  331. /package/dist/umd/verification/{utils → verification/utils}/index.d.ts +0 -0
  332. /package/dist/umd/verification/{utils → verification/utils}/index.d.ts.map +0 -0
  333. /package/dist/umd/verification/{utils → verification/utils}/rawbody.d.ts +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/verification/verification.js"],"names":[],"mappings":"AAgBO;;;;;;GA2FN"}
1
+ {"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/verification/verification.js"],"names":[],"mappings":"AAgBO;;;;;;;;GA6FN"}
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,68 +8,77 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
- import { subtle } from '../shared/subtlecrypto';
11
- import { objectToSortedString, ensureString, safeParse, isTrue, } from '../shared/display';
12
- import { getRequestMethod, normalizeURIParts, } from '../shared/request';
13
- import { ensureRawBody, VerificationError, } from './utils';
14
- export const getVerificationHelpers = ({ keyPairs }) => ((req, params) => __awaiter(void 0, void 0, void 0, function* () {
15
- var _a;
16
- const { 'x-public-key': apiKey, 'x-ephemeral-key': ephemeralPublicKey, 'x-authorization-timestamp': customAuthTimestamp, 'x-authorization': customAuth, } = (_a = req.headers) !== null && _a !== void 0 ? _a : {};
17
- const { uri: _uri, disableRecryption: _disableRecryption } = params !== null && params !== void 0 ? params : {};
18
- const uri = _uri !== null && _uri !== void 0 ? _uri : req.url;
19
- const disableRecryption = isTrue(_disableRecryption);
20
- let isVerifiable;
21
- try {
22
- const [authProtocol, authSignature] = ensureString(customAuth).split(' ');
23
- isVerifiable = isTrue(apiKey &&
24
- ephemeralPublicKey &&
25
- (keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) &&
26
- customAuthTimestamp &&
27
- authSignature &&
28
- (authProtocol === 'HMAC-SHA256'));
29
- let verificationKeys;
30
- const rawBody = yield ensureRawBody(req);
31
- // NOTE: requestBody should be wind up decrypted when isVerifiable (unless disableRecryption, then will pass through)
32
- let requestBody = safeParse(rawBody);
33
- // TEMP!!! remove isVerifiable check once webwidget moved to react
34
- if (isVerifiable) {
35
- if (!apiKey ||
36
- !ephemeralPublicKey ||
37
- !customAuthTimestamp ||
38
- !authSignature ||
39
- !(keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) ||
40
- (apiKey !== keyPairs.shared.publicKey) ||
41
- (authProtocol !== 'HMAC-SHA256')) {
42
- throw new VerificationError('Invalid or missing authorization', { code: 401 });
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getVerificationHelpers = void 0;
16
+ const display_1 = require("../shared/display");
17
+ const request_1 = require("../shared/request");
18
+ const WebCrypto_1 = __importDefault(require("../shared/WebCrypto"));
19
+ const utils_1 = require("./utils");
20
+ const getVerificationHelpers = ({ keyPairs, crypto: _crypto, util: _util } = {}) => {
21
+ const webCrypto = new WebCrypto_1.default({ crypto: _crypto, util: _util });
22
+ return (req, params) => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a;
24
+ const { 'x-public-key': apiKey, 'x-ephemeral-key': ephemeralPublicKey, 'x-authorization-timestamp': customAuthTimestamp, 'x-authorization': customAuth, } = (_a = req.headers) !== null && _a !== void 0 ? _a : {};
25
+ const { uri: _uri, disableRecryption: _disableRecryption } = params !== null && params !== void 0 ? params : {};
26
+ const uri = _uri !== null && _uri !== void 0 ? _uri : req.url;
27
+ const disableRecryption = (0, display_1.isTrue)(_disableRecryption);
28
+ let isVerifiable;
29
+ try {
30
+ const [authProtocol, authSignature] = (0, display_1.ensureString)(customAuth).split(' ');
31
+ isVerifiable = (0, display_1.isTrue)(apiKey &&
32
+ ephemeralPublicKey &&
33
+ (keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) &&
34
+ customAuthTimestamp &&
35
+ authSignature &&
36
+ (authProtocol === 'HMAC-SHA256'));
37
+ let verificationKeys;
38
+ const rawBody = yield (0, utils_1.ensureRawBody)(req);
39
+ // NOTE: requestBody should be wind up decrypted when isVerifiable (unless disableRecryption, then will pass through)
40
+ let requestBody = (0, display_1.safeParse)(rawBody);
41
+ // TEMP!!! remove isVerifiable check once webwidget moved to react
42
+ if (isVerifiable) {
43
+ if (!apiKey ||
44
+ !ephemeralPublicKey ||
45
+ !customAuthTimestamp ||
46
+ !authSignature ||
47
+ !(keyPairs === null || keyPairs === void 0 ? void 0 : keyPairs.shared) ||
48
+ (apiKey !== keyPairs.shared.publicKey) ||
49
+ (authProtocol !== 'HMAC-SHA256')) {
50
+ throw new utils_1.VerificationError('Invalid or missing authorization', { code: 401 });
51
+ }
52
+ verificationKeys = yield webCrypto.getVerificationKeys({
53
+ publicKey: ephemeralPublicKey,
54
+ privateKey: keyPairs.shared.privateKey,
55
+ });
56
+ if (!verificationKeys) {
57
+ throw new utils_1.VerificationError('Invalid or missing verification', { code: 412 });
58
+ }
59
+ const verificationPayload = (0, display_1.objectToSortedString)(Object.assign({ method: (0, request_1.getRequestMethod)(rawBody, req.method), timestamp: customAuthTimestamp, body: requestBody }, (0, request_1.normalizeURIParts)(uri)));
60
+ const isValid = yield webCrypto.verifyHMAC(verificationPayload, verificationKeys.derivedHMACKey, authSignature);
61
+ if (!isValid) {
62
+ throw new utils_1.VerificationError('Invalid or missing verification', { code: 412 });
63
+ }
64
+ if (!disableRecryption && requestBody) {
65
+ const decryptedMessage = yield webCrypto.decryptMessage(requestBody, verificationKeys.derivedSecretKey);
66
+ requestBody = (0, display_1.safeParse)(decryptedMessage);
67
+ }
43
68
  }
44
- verificationKeys = yield subtle.getVerificationKeys({
45
- publicKey: ephemeralPublicKey,
46
- privateKey: keyPairs.shared.privateKey,
69
+ const processResponse = (response) => __awaiter(void 0, void 0, void 0, function* () {
70
+ if (!response || disableRecryption || !isVerifiable || !(verificationKeys === null || verificationKeys === void 0 ? void 0 : verificationKeys.derivedSecretKey)) {
71
+ return response;
72
+ }
73
+ return webCrypto.encryptMessage(JSON.stringify(response), verificationKeys.derivedSecretKey);
47
74
  });
48
- if (!verificationKeys) {
49
- throw new VerificationError('Invalid or missing verification', { code: 412 });
50
- }
51
- const verificationPayload = objectToSortedString(Object.assign({ method: getRequestMethod(rawBody, req.method), timestamp: customAuthTimestamp, body: requestBody }, normalizeURIParts(uri)));
52
- const isValid = yield subtle.verifyHMAC(verificationPayload, verificationKeys.derivedHMACKey, authSignature);
53
- if (!isValid) {
54
- throw new VerificationError('Invalid or missing verification', { code: 412 });
55
- }
56
- if (!disableRecryption && requestBody) {
57
- const decryptedMessage = yield subtle.decryptMessage(requestBody, verificationKeys.derivedSecretKey);
58
- requestBody = safeParse(decryptedMessage);
59
- }
75
+ return { rawBody, requestBody, processResponse };
60
76
  }
61
- const processResponse = (response) => __awaiter(void 0, void 0, void 0, function* () {
62
- if (!response || disableRecryption || !isVerifiable || !(verificationKeys === null || verificationKeys === void 0 ? void 0 : verificationKeys.derivedSecretKey)) {
63
- return response;
64
- }
65
- return subtle.encryptMessage(JSON.stringify(response), verificationKeys.derivedSecretKey);
66
- });
67
- return { rawBody, requestBody, processResponse };
68
- }
69
- catch (error) {
70
- console.error(`Error handling request verification for '${uri}'`, { error, isVerifiable, disableRecryption });
71
- throw error;
72
- }
73
- }));
77
+ catch (error) {
78
+ console.error(`Error handling request verification for '${uri}'`, { error, isVerifiable, disableRecryption });
79
+ throw error;
80
+ }
81
+ });
82
+ };
83
+ exports.getVerificationHelpers = getVerificationHelpers;
74
84
  //# sourceMappingURL=verification.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/verification/verification.js"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,SAAS,EACT,MAAM,GACP,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,aAAa,EACb,iBAAiB,GAClB,MAAM,SAAS,CAAA;AAEhB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CACtD,CAAO,GAAG,EAAE,MAAM,EAAE,EAAE;;IACpB,MAAM,EACJ,cAAc,EAAE,MAAM,EACtB,iBAAiB,EAAE,kBAAkB,EACrC,2BAA2B,EAAE,mBAAmB,EAChD,iBAAiB,EAAE,UAAU,GAC9B,GAAG,MAAA,GAAG,CAAC,OAAO,mCAAI,EAAE,CAAA;IAErB,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;IACzE,MAAM,GAAG,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,GAAG,CAAC,GAAG,CAAA;IAC3B,MAAM,iBAAiB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAEpD,IAAI,YAAY,CAAA;IAChB,IAAI;QACF,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,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AAC,cAAc,CAAC,WAAW,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;oBACvG,WAAW,GAAG,IAAA,mBAAS,EAAC,gBAAgB,CAAC,CAAA;iBAC1C;aACF;YAED,MAAM,eAAe,GAAG,CAAO,QAAQ,EAAE,EAAE;gBACzC,IAAI,CAAC,QAAQ,IAAI,iBAAiB,IAAI,CAAC,YAAY,IAAI,CAAC,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,gBAAgB,CAAA,EAAE;oBAC1F,OAAO,QAAQ,CAAA;iBAChB;gBAED,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAA;YAC9F,CAAC,CAAA,CAAA;YAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,CAAA;SACjD;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,4CAA4C,GAAG,GAAG,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC,CAAA;YAC7G,MAAM,KAAK,CAAA;SACZ;IACH,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AA7FY,QAAA,sBAAsB,0BA6FlC"}
@@ -0,0 +1,97 @@
1
+ 3.1.2 / 2022-01-27
2
+ ==================
3
+
4
+ * Fix return value for un-parsable strings
5
+
6
+ 3.1.1 / 2021-11-15
7
+ ==================
8
+
9
+ * Fix "thousandsSeparator" incorrecting formatting fractional part
10
+
11
+ 3.1.0 / 2019-01-22
12
+ ==================
13
+
14
+ * Add petabyte (`pb`) support
15
+
16
+ 3.0.0 / 2017-08-31
17
+ ==================
18
+
19
+ * Change "kB" to "KB" in format output
20
+ * Remove support for Node.js 0.6
21
+ * Remove support for ComponentJS
22
+
23
+ 2.5.0 / 2017-03-24
24
+ ==================
25
+
26
+ * Add option "unit"
27
+
28
+ 2.4.0 / 2016-06-01
29
+ ==================
30
+
31
+ * Add option "unitSeparator"
32
+
33
+ 2.3.0 / 2016-02-15
34
+ ==================
35
+
36
+ * Drop partial bytes on all parsed units
37
+ * Fix non-finite numbers to `.format` to return `null`
38
+ * Fix parsing byte string that looks like hex
39
+ * perf: hoist regular expressions
40
+
41
+ 2.2.0 / 2015-11-13
42
+ ==================
43
+
44
+ * add option "decimalPlaces"
45
+ * add option "fixedDecimals"
46
+
47
+ 2.1.0 / 2015-05-21
48
+ ==================
49
+
50
+ * add `.format` export
51
+ * add `.parse` export
52
+
53
+ 2.0.2 / 2015-05-20
54
+ ==================
55
+
56
+ * remove map recreation
57
+ * remove unnecessary object construction
58
+
59
+ 2.0.1 / 2015-05-07
60
+ ==================
61
+
62
+ * fix browserify require
63
+ * remove node.extend dependency
64
+
65
+ 2.0.0 / 2015-04-12
66
+ ==================
67
+
68
+ * add option "case"
69
+ * add option "thousandsSeparator"
70
+ * return "null" on invalid parse input
71
+ * support proper round-trip: bytes(bytes(num)) === num
72
+ * units no longer case sensitive when parsing
73
+
74
+ 1.0.0 / 2014-05-05
75
+ ==================
76
+
77
+ * add negative support. fixes #6
78
+
79
+ 0.3.0 / 2014-03-19
80
+ ==================
81
+
82
+ * added terabyte support
83
+
84
+ 0.2.1 / 2013-04-01
85
+ ==================
86
+
87
+ * add .component
88
+
89
+ 0.2.0 / 2012-10-28
90
+ ==================
91
+
92
+ * bytes(200).should.eql('200b')
93
+
94
+ 0.1.0 / 2012-07-04
95
+ ==================
96
+
97
+ * add bytes to string conversion [yields]
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2012-2014 TJ Holowaychuk <tj@vision-media.ca>
4
+ Copyright (c) 2015 Jed Watson <jed.watson@me.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ 'Software'), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,152 @@
1
+ # Bytes utility
2
+
3
+ [![NPM Version][npm-image]][npm-url]
4
+ [![NPM Downloads][downloads-image]][downloads-url]
5
+ [![Build Status][ci-image]][ci-url]
6
+ [![Test Coverage][coveralls-image]][coveralls-url]
7
+
8
+ Utility to parse a string bytes (ex: `1TB`) to bytes (`1099511627776`) and vice-versa.
9
+
10
+ ## Installation
11
+
12
+ This is a [Node.js](https://nodejs.org/en/) module available through the
13
+ [npm registry](https://www.npmjs.com/). Installation is done using the
14
+ [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
15
+
16
+ ```bash
17
+ $ npm install bytes
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```js
23
+ var bytes = require('bytes');
24
+ ```
25
+
26
+ #### bytes(number|string value, [options]): number|string|null
27
+
28
+ Default export function. Delegates to either `bytes.format` or `bytes.parse` based on the type of `value`.
29
+
30
+ **Arguments**
31
+
32
+ | Name | Type | Description |
33
+ |---------|----------|--------------------|
34
+ | value | `number`|`string` | Number value to format or string value to parse |
35
+ | options | `Object` | Conversion options for `format` |
36
+
37
+ **Returns**
38
+
39
+ | Name | Type | Description |
40
+ |---------|------------------|-------------------------------------------------|
41
+ | results | `string`|`number`|`null` | Return null upon error. Numeric value in bytes, or string value otherwise. |
42
+
43
+ **Example**
44
+
45
+ ```js
46
+ bytes(1024);
47
+ // output: '1KB'
48
+
49
+ bytes('1KB');
50
+ // output: 1024
51
+ ```
52
+
53
+ #### bytes.format(number value, [options]): string|null
54
+
55
+ Format the given value in bytes into a string. If the value is negative, it is kept as such. If it is a float, it is
56
+ rounded.
57
+
58
+ **Arguments**
59
+
60
+ | Name | Type | Description |
61
+ |---------|----------|--------------------|
62
+ | value | `number` | Value in bytes |
63
+ | options | `Object` | Conversion options |
64
+
65
+ **Options**
66
+
67
+ | Property | Type | Description |
68
+ |-------------------|--------|-----------------------------------------------------------------------------------------|
69
+ | decimalPlaces | `number`|`null` | Maximum number of decimal places to include in output. Default value to `2`. |
70
+ | fixedDecimals | `boolean`|`null` | Whether to always display the maximum number of decimal places. Default value to `false` |
71
+ | thousandsSeparator | `string`|`null` | Example of values: `' '`, `','` and `'.'`... Default value to `''`. |
72
+ | unit | `string`|`null` | The unit in which the result will be returned (B/KB/MB/GB/TB). Default value to `''` (which means auto detect). |
73
+ | unitSeparator | `string`|`null` | Separator to use between number and unit. Default value to `''`. |
74
+
75
+ **Returns**
76
+
77
+ | Name | Type | Description |
78
+ |---------|------------------|-------------------------------------------------|
79
+ | results | `string`|`null` | Return null upon error. String value otherwise. |
80
+
81
+ **Example**
82
+
83
+ ```js
84
+ bytes.format(1024);
85
+ // output: '1KB'
86
+
87
+ bytes.format(1000);
88
+ // output: '1000B'
89
+
90
+ bytes.format(1000, {thousandsSeparator: ' '});
91
+ // output: '1 000B'
92
+
93
+ bytes.format(1024 * 1.7, {decimalPlaces: 0});
94
+ // output: '2KB'
95
+
96
+ bytes.format(1024, {unitSeparator: ' '});
97
+ // output: '1 KB'
98
+ ```
99
+
100
+ #### bytes.parse(string|number value): number|null
101
+
102
+ Parse the string value into an integer in bytes. If no unit is given, or `value`
103
+ is a number, it is assumed the value is in bytes.
104
+
105
+ Supported units and abbreviations are as follows and are case-insensitive:
106
+
107
+ * `b` for bytes
108
+ * `kb` for kilobytes
109
+ * `mb` for megabytes
110
+ * `gb` for gigabytes
111
+ * `tb` for terabytes
112
+ * `pb` for petabytes
113
+
114
+ The units are in powers of two, not ten. This means 1kb = 1024b according to this parser.
115
+
116
+ **Arguments**
117
+
118
+ | Name | Type | Description |
119
+ |---------------|--------|--------------------|
120
+ | value | `string`|`number` | String to parse, or number in bytes. |
121
+
122
+ **Returns**
123
+
124
+ | Name | Type | Description |
125
+ |---------|-------------|-------------------------|
126
+ | results | `number`|`null` | Return null upon error. Value in bytes otherwise. |
127
+
128
+ **Example**
129
+
130
+ ```js
131
+ bytes.parse('1KB');
132
+ // output: 1024
133
+
134
+ bytes.parse('1024');
135
+ // output: 1024
136
+
137
+ bytes.parse(1024);
138
+ // output: 1024
139
+ ```
140
+
141
+ ## License
142
+
143
+ [MIT](LICENSE)
144
+
145
+ [ci-image]: https://badgen.net/github/checks/visionmedia/bytes.js/master?label=ci
146
+ [ci-url]: https://github.com/visionmedia/bytes.js/actions?query=workflow%3Aci
147
+ [coveralls-image]: https://badgen.net/coveralls/c/github/visionmedia/bytes.js/master
148
+ [coveralls-url]: https://coveralls.io/r/visionmedia/bytes.js?branch=master
149
+ [downloads-image]: https://badgen.net/npm/dm/bytes
150
+ [downloads-url]: https://npmjs.org/package/bytes
151
+ [npm-image]: https://badgen.net/npm/v/bytes
152
+ [npm-url]: https://npmjs.org/package/bytes
@@ -0,0 +1,170 @@
1
+ /*!
2
+ * bytes
3
+ * Copyright(c) 2012-2014 TJ Holowaychuk
4
+ * Copyright(c) 2015 Jed Watson
5
+ * MIT Licensed
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ /**
11
+ * Module exports.
12
+ * @public
13
+ */
14
+
15
+ module.exports = bytes;
16
+ module.exports.format = format;
17
+ module.exports.parse = parse;
18
+
19
+ /**
20
+ * Module variables.
21
+ * @private
22
+ */
23
+
24
+ var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g;
25
+
26
+ var formatDecimalsRegExp = /(?:\.0*|(\.[^0]+)0+)$/;
27
+
28
+ var map = {
29
+ b: 1,
30
+ kb: 1 << 10,
31
+ mb: 1 << 20,
32
+ gb: 1 << 30,
33
+ tb: Math.pow(1024, 4),
34
+ pb: Math.pow(1024, 5),
35
+ };
36
+
37
+ var parseRegExp = /^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|pb)$/i;
38
+
39
+ /**
40
+ * Convert the given value in bytes into a string or parse to string to an integer in bytes.
41
+ *
42
+ * @param {string|number} value
43
+ * @param {{
44
+ * case: [string],
45
+ * decimalPlaces: [number]
46
+ * fixedDecimals: [boolean]
47
+ * thousandsSeparator: [string]
48
+ * unitSeparator: [string]
49
+ * }} [options] bytes options.
50
+ *
51
+ * @returns {string|number|null}
52
+ */
53
+
54
+ function bytes(value, options) {
55
+ if (typeof value === 'string') {
56
+ return parse(value);
57
+ }
58
+
59
+ if (typeof value === 'number') {
60
+ return format(value, options);
61
+ }
62
+
63
+ return null;
64
+ }
65
+
66
+ /**
67
+ * Format the given value in bytes into a string.
68
+ *
69
+ * If the value is negative, it is kept as such. If it is a float,
70
+ * it is rounded.
71
+ *
72
+ * @param {number} value
73
+ * @param {object} [options]
74
+ * @param {number} [options.decimalPlaces=2]
75
+ * @param {number} [options.fixedDecimals=false]
76
+ * @param {string} [options.thousandsSeparator=]
77
+ * @param {string} [options.unit=]
78
+ * @param {string} [options.unitSeparator=]
79
+ *
80
+ * @returns {string|null}
81
+ * @public
82
+ */
83
+
84
+ function format(value, options) {
85
+ if (!Number.isFinite(value)) {
86
+ return null;
87
+ }
88
+
89
+ var mag = Math.abs(value);
90
+ var thousandsSeparator = (options && options.thousandsSeparator) || '';
91
+ var unitSeparator = (options && options.unitSeparator) || '';
92
+ var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2;
93
+ var fixedDecimals = Boolean(options && options.fixedDecimals);
94
+ var unit = (options && options.unit) || '';
95
+
96
+ if (!unit || !map[unit.toLowerCase()]) {
97
+ if (mag >= map.pb) {
98
+ unit = 'PB';
99
+ } else if (mag >= map.tb) {
100
+ unit = 'TB';
101
+ } else if (mag >= map.gb) {
102
+ unit = 'GB';
103
+ } else if (mag >= map.mb) {
104
+ unit = 'MB';
105
+ } else if (mag >= map.kb) {
106
+ unit = 'KB';
107
+ } else {
108
+ unit = 'B';
109
+ }
110
+ }
111
+
112
+ var val = value / map[unit.toLowerCase()];
113
+ var str = val.toFixed(decimalPlaces);
114
+
115
+ if (!fixedDecimals) {
116
+ str = str.replace(formatDecimalsRegExp, '$1');
117
+ }
118
+
119
+ if (thousandsSeparator) {
120
+ str = str.split('.').map(function (s, i) {
121
+ return i === 0
122
+ ? s.replace(formatThousandsRegExp, thousandsSeparator)
123
+ : s
124
+ }).join('.');
125
+ }
126
+
127
+ return str + unitSeparator + unit;
128
+ }
129
+
130
+ /**
131
+ * Parse the string value into an integer in bytes.
132
+ *
133
+ * If no unit is given, it is assumed the value is in bytes.
134
+ *
135
+ * @param {number|string} val
136
+ *
137
+ * @returns {number|null}
138
+ * @public
139
+ */
140
+
141
+ function parse(val) {
142
+ if (typeof val === 'number' && !isNaN(val)) {
143
+ return val;
144
+ }
145
+
146
+ if (typeof val !== 'string') {
147
+ return null;
148
+ }
149
+
150
+ // Test if the string passed is valid
151
+ var results = parseRegExp.exec(val);
152
+ var floatValue;
153
+ var unit = 'b';
154
+
155
+ if (!results) {
156
+ // Nothing could be extracted from the given string
157
+ floatValue = parseInt(val, 10);
158
+ unit = 'b'
159
+ } else {
160
+ // Retrieve the value and the unit
161
+ floatValue = parseFloat(results[1]);
162
+ unit = results[4].toLowerCase();
163
+ }
164
+
165
+ if (isNaN(floatValue)) {
166
+ return null;
167
+ }
168
+
169
+ return Math.floor(map[unit] * floatValue);
170
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "bytes",
3
+ "description": "Utility to parse a string bytes to bytes and vice-versa",
4
+ "version": "3.1.2",
5
+ "author": "TJ Holowaychuk <tj@vision-media.ca> (http://tjholowaychuk.com)",
6
+ "contributors": [
7
+ "Jed Watson <jed.watson@me.com>",
8
+ "Théo FIDRY <theo.fidry@gmail.com>"
9
+ ],
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "byte",
13
+ "bytes",
14
+ "utility",
15
+ "parse",
16
+ "parser",
17
+ "convert",
18
+ "converter"
19
+ ],
20
+ "repository": "visionmedia/bytes.js",
21
+ "devDependencies": {
22
+ "eslint": "7.32.0",
23
+ "eslint-plugin-markdown": "2.2.1",
24
+ "mocha": "9.2.0",
25
+ "nyc": "15.1.0"
26
+ },
27
+ "files": [
28
+ "History.md",
29
+ "LICENSE",
30
+ "Readme.md",
31
+ "index.js"
32
+ ],
33
+ "engines": {
34
+ "node": ">= 0.8"
35
+ },
36
+ "scripts": {
37
+ "lint": "eslint .",
38
+ "test": "mocha --check-leaks --reporter spec",
39
+ "test-ci": "nyc --reporter=lcov --reporter=text npm test",
40
+ "test-cov": "nyc --reporter=html --reporter=text npm test"
41
+ }
42
+ }