@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,641 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@agnostack/next-shopify/umd-verification"] = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- var n,r=((n=function(){return r}).toString=n.toLocaleString=n[Symbol.toPrimitive]=function(){return ""},n.valueOf=function(){return !1},new Proxy(Object.freeze(n),{get:function(n,t){return n.hasOwnProperty(t)?n[t]:r}})),u=function(n){return n===r};
8
-
9
- let win = global.window;
10
- let exists = (variable) => !u(variable);
11
- let window = typeof win !== "undefined" ? win : r;
12
-
13
- /* eslint-disable no-use-before-define */
14
-
15
- const isType = (value, type) => (
16
- // eslint-disable-next-line eqeqeq, valid-typeof
17
- (value != undefined) && (typeof value === type)
18
- );
19
-
20
- const safeTrim = (value) => {
21
- if (isType(value, 'string')) {
22
- // eslint-disable-next-line no-param-reassign
23
- value = value.trim();
24
- }
25
-
26
- return value
27
- };
28
-
29
- const safeParse = (value, trim) => {
30
- if (isType(value, 'string')) {
31
- if (trim) {
32
- // eslint-disable-next-line no-param-reassign
33
- value = safeTrim(value);
34
- }
35
-
36
- if (value.startsWith('{') || value.startsWith('[') || value.startsWith('"')) {
37
- // eslint-disable-next-line no-param-reassign
38
- value = JSON.parse(value);
39
- }
40
- }
41
-
42
- // TODO: should this be value ?? {}
43
- return value
44
- };
45
-
46
- const ensureString = (string) => (
47
- string ? `${string}` : ''
48
- );
49
-
50
- const ensureArray = (array = []) => (
51
- // eslint-disable-next-line no-nested-ternary
52
- !array ? [] : Array.isArray(array) ? array : [array]
53
- );
54
-
55
- const ensureObject = (object) => (
56
- object ?? {}
57
- );
58
-
59
- // NOTE: this does not ensure !isType(string)
60
- const objectEmpty = (object) => (
61
- !object || !Object.keys(object).length
62
- );
63
-
64
- const stringNotEmpty = (stringable) => {
65
- const string = ensureString(stringable);
66
- return ((string.length > 0) && !['null', 'undefined'].includes(string))
67
- };
68
-
69
- const stringEmpty = (stringable) => (
70
- !stringNotEmpty(stringable)
71
- );
72
-
73
- const compareString = (string1, string2) => {
74
- if (stringEmpty(string1)) {
75
- return 1
76
- }
77
-
78
- if (stringEmpty(string2)) {
79
- return -1
80
- }
81
-
82
- return ensureString(string1).localeCompare(string2)
83
- };
84
-
85
- const compareEntryKeys = ([string1], [string2]) => (
86
- compareString(string1, string2)
87
- );
88
-
89
- const objectToSortedString = (object, separator = '') => (
90
- Object.entries(ensureObject(object))
91
- .sort(compareEntryKeys)
92
- .map(([key, value]) => `${key}=${value}`)
93
- .join(separator)
94
- );
95
-
96
- const uppercase = (string) => (
97
- ensureString(string).toUpperCase()
98
- );
99
-
100
- const removeLeadingSlash = (string) => (
101
- ensureString(string).replace(/^\//, '')
102
- );
103
-
104
- const ensureLeadingSlash = (string) => (
105
- `/${removeLeadingSlash(string)}`
106
- );
107
-
108
- const isTrue = (value, falsy) => {
109
- const string = ensureString(value);
110
- return ![...ensureArray(falsy), '', 'false'].includes(string)
111
- };
112
-
113
- const getWebCrypto = async () => {
114
- try {
115
- const crypto = (await import('isomorphic-webcrypto')).default;
116
- return crypto
117
- } catch (error) {
118
- console.error('Failed to import isomorphic-webcrypto', error);
119
- throw error
120
- }
121
- };
122
-
123
- const getTextDecoder = async () => {
124
- if (exists(window) && (typeof window?.TextDecoder === 'function')) {
125
- return window.TextDecoder
126
- }
127
-
128
- try {
129
- const TextDecoder = (await import('util')).TextDecoder;
130
- return TextDecoder
131
- } catch (error) {
132
- console.error('Failed to import utils.TextDecoder', error);
133
- throw error
134
- }
135
- };
136
-
137
- const getTextEncoder = async () => {
138
- if (exists(window) && (typeof window?.TextEncoder === 'function')) {
139
- return window.TextEncoder
140
- }
141
-
142
- try {
143
- const TextEncoder = (await import('util')).TextEncoder;
144
- return TextEncoder
145
- } catch (error) {
146
- console.error('Failed to import utils.TextEncoder', error);
147
- throw error
148
- }
149
- };
150
-
151
- const timingSafeEqual = (value1, value2) => {
152
- if (
153
- (value1 == undefined) ||
154
- (value2 == undefined) ||
155
- (value1.length !== value2.length)
156
- ) {
157
- return false
158
- }
159
-
160
- let result = 0;
161
- // eslint-disable-next-line no-plusplus
162
- for (let i = 0; i < value1.length; i++) {
163
- // eslint-disable-next-line no-bitwise
164
- result |= value1[i] ^ value2[i];
165
- }
166
-
167
- return (result === 0)
168
- };
169
-
170
- const stringToHex = (stringValue) => (
171
- Array.from(ensureString(stringValue), (char) => (
172
- char.charCodeAt(0).toString(16).padStart(2, '0')
173
- )).join('')
174
- );
175
-
176
- const hexToString = (hexValue) => (
177
- ensureArray(
178
- ensureString(hexValue).match(/.{1,2}/g)
179
- )
180
- .map((byte) => String.fromCharCode(parseInt(byte, 16)))
181
- .join('')
182
- );
183
-
184
- const arrayBufferToString = async (arrayBuffer) => {
185
- const uint8Array = new Uint8Array(arrayBuffer);
186
- const Decoder = await getTextDecoder();
187
- return new Decoder().decode(uint8Array)
188
- };
189
-
190
- const arrayToArrayBuffer = (array) => (
191
- (ArrayBuffer.from != undefined)
192
- ? ArrayBuffer.from(array)
193
- : new Uint8Array(array).buffer
194
- );
195
-
196
- const ensureArrayBuffer = (arrayOrArrayBuffer) => (
197
- (arrayOrArrayBuffer instanceof ArrayBuffer)
198
- ? arrayOrArrayBuffer
199
- : arrayToArrayBuffer(arrayOrArrayBuffer)
200
- );
201
-
202
- const generateKeyPair = async () => {
203
- const crypto = await getWebCrypto();
204
- const keyPair = await crypto.subtle.generateKey(
205
- {
206
- name: 'ECDH',
207
- namedCurve: 'P-256',
208
- },
209
- true,
210
- ['deriveKey']
211
- );
212
-
213
- return keyPair
214
- };
215
-
216
- const getKeyOperations = (keyType) => {
217
- switch (keyType) {
218
- case 'private':
219
- case 'privateKey': {
220
- return ['deriveKey']
221
- }
222
-
223
- case 'secret':
224
- case 'secretKey':
225
- case 'sharedSecret': {
226
- return ['encrypt', 'decrypt']
227
- }
228
-
229
- default: {
230
- return []
231
- }
232
- }
233
- };
234
-
235
- const getKeyAlgorythm = (keyType) => {
236
- switch (keyType) {
237
- case 'derivedKey':
238
- case 'derived':
239
- case 'secret':
240
- case 'secretKey':
241
- case 'sharedSecret': {
242
- return {
243
- name: 'AES-GCM',
244
- }
245
- }
246
-
247
- default: {
248
- return {
249
- name: 'ECDH',
250
- namedCurve: 'P-256',
251
- }
252
- }
253
- }
254
- };
255
-
256
- const generateHMAC = async (message, derivedKey) => {
257
- if (!message || !derivedKey) {
258
- return undefined
259
- }
260
-
261
- const crypto = await getWebCrypto();
262
- const Encoder = await getTextEncoder();
263
-
264
- const signature = await crypto.subtle.sign(
265
- 'HMAC',
266
- derivedKey,
267
- new Encoder().encode(message)
268
- );
269
-
270
- return stringToHex(
271
- arrayBufferToString(signature)
272
- )
273
- };
274
-
275
- const verifyHMAC = async (message, derivedKey, verifiableHMAC) => {
276
- const calculatedHMAC = await generateHMAC(message, derivedKey);
277
-
278
- return timingSafeEqual(calculatedHMAC, verifiableHMAC)
279
- };
280
-
281
- const getStorableKey = async (key) => {
282
- const crypto = await getWebCrypto();
283
-
284
- const exportedJWK = await crypto.subtle.exportKey('jwk', key);
285
- return stringToHex(JSON.stringify(exportedJWK))
286
- };
287
-
288
- const restoreStorableKey = async (keyType, storableHex) => {
289
- if (!storableHex) {
290
- return undefined
291
- }
292
- const crypto = await getWebCrypto();
293
-
294
- const exportedJWK = JSON.parse(hexToString(storableHex) || '{}');
295
- if (objectEmpty(exportedJWK)) {
296
- return undefined
297
- }
298
-
299
- return crypto.subtle.importKey(
300
- 'jwk',
301
- exportedJWK,
302
- getKeyAlgorythm(keyType),
303
- true,
304
- getKeyOperations(keyType)
305
- )
306
- };
307
-
308
- const getStorableKeyPair = async (keyPair) => {
309
- const storableKeys = {};
310
-
311
- // eslint-disable-next-line no-restricted-syntax
312
- for (const [keyType, key] of Object.entries(keyPair)) {
313
- // eslint-disable-next-line no-await-in-loop
314
- storableKeys[keyType] = await getStorableKey(key);
315
- }
316
-
317
- return storableKeys
318
- };
319
-
320
- const restoreStorableKeyPair = async (keyPair) => {
321
- const restoredKeys = {};
322
-
323
- // eslint-disable-next-line no-restricted-syntax
324
- for (const [keyType, key] of Object.entries(keyPair)) {
325
- // eslint-disable-next-line no-await-in-loop
326
- restoredKeys[keyType] = await restoreStorableKey(keyType, key);
327
- }
328
-
329
- return restoredKeys
330
- };
331
-
332
- const deriveSharedKey = async ({ publicKey, privateKey }) => {
333
- if (!publicKey || !privateKey) {
334
- return undefined
335
- }
336
-
337
- const crypto = await getWebCrypto();
338
- const derivedKey = await crypto.subtle.deriveKey(
339
- {
340
- name: 'ECDH',
341
- public: publicKey,
342
- },
343
- privateKey,
344
- {
345
- name: 'AES-GCM',
346
- length: 256,
347
- },
348
- true,
349
- ['encrypt', 'decrypt']
350
- );
351
- return derivedKey
352
- };
353
-
354
- const deriveHMACKey = async ({ publicKey, privateKey }) => {
355
- if (!publicKey || !privateKey) {
356
- return undefined
357
- }
358
-
359
- const crypto = await getWebCrypto();
360
- const derivedKey = await crypto.subtle.deriveKey(
361
- {
362
- name: 'ECDH',
363
- public: publicKey,
364
- },
365
- privateKey,
366
- {
367
- name: 'HMAC',
368
- hash: { name: 'SHA-256' },
369
- length: 256, // Adjusted key length, e.g., 128 bits
370
- },
371
- true,
372
- ['sign', 'verify']
373
- );
374
- return derivedKey
375
- };
376
-
377
- const getVerificationKeys = async ({ publicKey, privateKey }) => {
378
- if (!publicKey || !privateKey) {
379
- return {}
380
- }
381
-
382
- const sharedKeyPair = await restoreStorableKeyPair({ publicKey, privateKey });
383
- const derivedHMACKey = await deriveHMACKey(sharedKeyPair);
384
- const derivedSecretKey = await deriveSharedKey(sharedKeyPair);
385
-
386
- return {
387
- derivedSecretKey,
388
- derivedHMACKey,
389
- }
390
- };
391
-
392
- const encryptMessage = async (decryptedMessage, derivedKey) => {
393
- if (!decryptedMessage || !derivedKey) {
394
- return undefined
395
- }
396
-
397
- const crypto = await getWebCrypto();
398
- const iv = crypto.getRandomValues(new Uint8Array(12));
399
- const Encoder = await getTextEncoder();
400
- const encodedMessage = new Encoder().encode(decryptedMessage);
401
- const ciphertext = await crypto.subtle.encrypt(
402
- {
403
- name: 'AES-GCM',
404
- iv,
405
- },
406
- derivedKey,
407
- encodedMessage
408
- );
409
-
410
- const encryptedMessage = new Uint8Array([
411
- ...iv,
412
- ...new Uint8Array(ciphertext)
413
- ]);
414
- return Array.from(encryptedMessage)
415
- };
416
-
417
- const decryptMessage = async (encryptedMessage, derivedKey) => {
418
- if (!encryptedMessage || !derivedKey) {
419
- return undefined
420
- }
421
-
422
- const crypto = await getWebCrypto();
423
- // NOTE: this presumed an array or arrayBuffer coming in as encryptedMessage (will fail w/ IV error if its a string)
424
- const encryptedArrayBuffer = ensureArrayBuffer(encryptedMessage);
425
- const iv = encryptedArrayBuffer.slice(0, 12);
426
- const ciphertext = encryptedArrayBuffer.slice(12);
427
-
428
- const decryptedArrayBuffer = await crypto.subtle.decrypt(
429
- {
430
- name: 'AES-GCM',
431
- iv,
432
- },
433
- derivedKey,
434
- ciphertext
435
- );
436
-
437
- const Decoder = await getTextDecoder();
438
- const decryptedMessage = new Decoder().decode(decryptedArrayBuffer);
439
- return decryptedMessage
440
- };
441
-
442
- const subtle = {
443
- generateKeyPair,
444
- generateHMAC,
445
- verifyHMAC,
446
- getStorableKey,
447
- getStorableKeyPair,
448
- restoreStorableKeyPair,
449
- deriveSharedKey,
450
- deriveHMACKey,
451
- getVerificationKeys,
452
- encryptMessage,
453
- decryptMessage,
454
- };
455
-
456
- const TEMP_HOSTNAME = 'xyz.com';
457
- const REMOVABLE_KEYS = ['shop', 'host'];
458
-
459
- const getRequestMethod = (body, _method) => {
460
- const method = _method ?? (body ? 'POST' : 'GET');
461
-
462
- return uppercase(method)
463
- };
464
-
465
- const convertToURL = (uri) => {
466
- if (stringEmpty(uri)) {
467
- return undefined
468
- }
469
-
470
- const protocolRegex = /^(https?:\/\/).+/i;
471
-
472
- if (!protocolRegex.test(uri)) {
473
- return new URL(`https://${TEMP_HOSTNAME}${ensureLeadingSlash(uri)}`)
474
- }
475
-
476
- return new URL(uri)
477
- };
478
-
479
- const normalizeURIParts = (uri) => {
480
- const urlObject = convertToURL(uri);
481
- if (!urlObject) {
482
- return undefined
483
- }
484
-
485
- REMOVABLE_KEYS.forEach((key) => urlObject.searchParams.delete(key));
486
-
487
- return {
488
- ...(urlObject.hostname !== TEMP_HOSTNAME) && {
489
- origin: urlObject.origin,
490
- },
491
- pathname: urlObject.pathname,
492
- search: urlObject.search,
493
- }
494
- };
495
-
496
- class VerificationError extends Error {
497
- constructor(message, _data) {
498
- super(message);
499
- const { code = 500, ...data } = _data ?? {};
500
- this.code = code;
501
- this.data = data;
502
- this.name = 'VerificationError';
503
- Object.setPrototypeOf(this, VerificationError.prototype);
504
- }
505
- }
506
-
507
- // import getRawBody from 'raw-body'
508
- // import * as getRawBody from 'raw-body'
509
-
510
- const getChunkedRawBody = async (readable) => {
511
- const chunks = [];
512
-
513
- for await (const chunk of readable) {
514
- chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
515
- }
516
-
517
- return Buffer.concat(chunks)
518
- };
519
-
520
- // TODO: explore returning mutated request object adding on req.rawBody??
521
- // TODO: move to req.text() after next 13.5: https://github.com/vercel/next.js/discussions/13405
522
- const ensureRawBody = async (req) => (
523
- getChunkedRawBody(req)
524
- // getRawBody(req)
525
- .then((_rawBody) => _rawBody.toString())
526
- .catch((error) => {
527
- // NOTE: this is intended to ensure if getRawBody is called 2x w/in a route that it returns the already streamed body
528
- if ((error?.type === 'stream.not.readable')) {
529
- if (!req?.rawBody) {
530
- // eslint-disable-next-line max-len
531
- console.info('Ignoring error reading raw requst body. This can occur if the body is attempted to be read twice in a single request. If intentional, please mutate the request to add the result of this call as req.rawBody (to prevent this warning).');
532
- return req?.body
533
- }
534
-
535
- return req?.rawBody
536
- }
537
-
538
- console.error(`Error getting raw body for '${req?.url}'`, error);
539
- throw error
540
- })
541
- );
542
-
543
- const getVerificationHelpers = ({ keyPairs }) => (
544
- async (req, params) => {
545
- const {
546
- 'x-public-key': apiKey,
547
- 'x-ephemeral-key': ephemeralPublicKey,
548
- 'x-authorization-timestamp': customAuthTimestamp,
549
- 'x-authorization': customAuth,
550
- } = req.headers ?? {};
551
-
552
- const { uri: _uri, disableRecryption: _disableRecryption } = params ?? {};
553
- const uri = _uri ?? req.url;
554
- const disableRecryption = isTrue(_disableRecryption);
555
-
556
- let isVerifiable;
557
- try {
558
- const [authProtocol, authSignature] = ensureString(customAuth).split(' ');
559
- isVerifiable = isTrue(
560
- apiKey &&
561
- ephemeralPublicKey &&
562
- keyPairs?.shared &&
563
- customAuthTimestamp &&
564
- authSignature &&
565
- (authProtocol === 'HMAC-SHA256')
566
- );
567
-
568
- let verificationKeys;
569
- const rawBody = await ensureRawBody(req);
570
-
571
- // NOTE: requestBody should be wind up decrypted when isVerifiable (unless disableRecryption, then will pass through)
572
- let requestBody = safeParse(rawBody);
573
-
574
- // TEMP!!! remove isVerifiable check once webwidget moved to react
575
- if (isVerifiable) {
576
- if (
577
- !apiKey ||
578
- !ephemeralPublicKey ||
579
- !customAuthTimestamp ||
580
- !authSignature ||
581
- !keyPairs?.shared ||
582
- (apiKey !== keyPairs.shared.publicKey) ||
583
- (authProtocol !== 'HMAC-SHA256')
584
- ) {
585
- throw new VerificationError('Invalid or missing authorization', { code: 401 })
586
- }
587
-
588
- verificationKeys = await subtle.getVerificationKeys({
589
- publicKey: ephemeralPublicKey,
590
- privateKey: keyPairs.shared.privateKey,
591
- });
592
-
593
- if (!verificationKeys) {
594
- throw new VerificationError('Invalid or missing verification', { code: 412 })
595
- }
596
-
597
- const verificationPayload = objectToSortedString({
598
- method: getRequestMethod(rawBody, req.method),
599
- timestamp: customAuthTimestamp,
600
- body: requestBody, // NOTE: requestBody should be encrypted when isVerifiable
601
- ...normalizeURIParts(uri),
602
- });
603
-
604
- const isValid = await subtle.verifyHMAC(
605
- verificationPayload,
606
- verificationKeys.derivedHMACKey,
607
- authSignature
608
- );
609
-
610
- if (!isValid) {
611
- throw new VerificationError('Invalid or missing verification', { code: 412 })
612
- }
613
-
614
- if (!disableRecryption && requestBody) {
615
- const decryptedMessage = await subtle.decryptMessage(requestBody, verificationKeys.derivedSecretKey);
616
- requestBody = safeParse(decryptedMessage);
617
- }
618
- }
619
-
620
- const processResponse = async (response) => {
621
- if (!response || disableRecryption || !isVerifiable || !verificationKeys?.derivedSecretKey) {
622
- return response
623
- }
624
-
625
- return subtle.encryptMessage(JSON.stringify(response), verificationKeys.derivedSecretKey)
626
- };
627
-
628
- return { rawBody, requestBody, processResponse }
629
- } catch (error) {
630
- console.error(`Error handling request verification for '${uri}'`, { error, isVerifiable, disableRecryption });
631
- throw error
632
- }
633
- }
634
- );
635
-
636
- exports.getVerificationHelpers = getVerificationHelpers;
637
-
638
- Object.defineProperty(exports, '__esModule', { value: true });
639
-
640
- }));
641
- //# sourceMappingURL=verification.js.map