@agnostack/next-shopify 1.15.0-beta.9 → 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.
- package/CHANGELOG.md +189 -0
- package/README.md +9 -8
- package/dist/lib/handlers/api/auth.js +15 -11
- package/dist/lib/handlers/api/auth.js.map +1 -1
- package/dist/lib/handlers/api/billing.js +13 -9
- package/dist/lib/handlers/api/billing.js.map +1 -1
- package/dist/lib/handlers/api/callback.js +37 -33
- package/dist/lib/handlers/api/callback.js.map +1 -1
- package/dist/lib/handlers/api/index.js +25 -7
- package/dist/lib/handlers/api/index.js.map +1 -1
- package/dist/lib/handlers/api/uninstall.js +12 -8
- package/dist/lib/handlers/api/uninstall.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/appInstallation.js +11 -7
- package/dist/lib/handlers/api/verifiable/appInstallation.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/graph.js +26 -22
- package/dist/lib/handlers/api/verifiable/graph.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/index.js +21 -5
- package/dist/lib/handlers/api/verifiable/index.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/proxy.js +39 -32
- package/dist/lib/handlers/api/verifiable/proxy.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/rest.js +23 -19
- package/dist/lib/handlers/api/verifiable/rest.js.map +1 -1
- package/dist/lib/handlers/api/verifiable/token.js +27 -23
- package/dist/lib/handlers/api/verifiable/token.js.map +1 -1
- package/dist/lib/handlers/api/webhook.js +13 -9
- package/dist/lib/handlers/api/webhook.js.map +1 -1
- package/dist/lib/handlers/index.js +18 -2
- package/dist/lib/handlers/index.js.map +1 -1
- package/dist/lib/handlers/ssr/index.js +18 -2
- package/dist/lib/handlers/ssr/index.js.map +1 -1
- package/dist/lib/handlers/ssr/protect.js +24 -17
- package/dist/lib/handlers/ssr/protect.js.map +1 -1
- package/dist/lib/handlers/ssr/wrap.js +10 -6
- package/dist/lib/handlers/ssr/wrap.js.map +1 -1
- package/dist/lib/index.js +23 -4
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/utils/billing.js +23 -18
- package/dist/lib/utils/billing.js.map +1 -1
- package/dist/lib/utils/crypto.js +25 -15
- package/dist/lib/utils/crypto.js.map +1 -1
- package/dist/lib/utils/firebase.js +29 -17
- package/dist/lib/utils/firebase.js.map +1 -1
- package/dist/lib/utils/headers.js +13 -6
- package/dist/lib/utils/headers.js.map +1 -1
- package/dist/lib/utils/index.js +24 -8
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/session.js +64 -59
- package/dist/lib/utils/session.js.map +1 -1
- package/dist/lib/utils/shopify-api-js/oauth.js +23 -16
- package/dist/lib/utils/shopify-api-js/oauth.js.map +1 -1
- package/dist/lib/utils/shopify.js +37 -25
- package/dist/lib/utils/shopify.js.map +1 -1
- package/dist/lib/utils/token.js +15 -11
- package/dist/lib/utils/token.js.map +1 -1
- package/dist/plugins/index.js +18 -2
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/withShopify.js +83 -79
- package/dist/plugins/withShopify.js.map +1 -1
- package/dist/react/hooks/index.js +17 -1
- package/dist/react/hooks/index.js.map +1 -1
- package/dist/react/hooks/useVerification.d.ts +1 -1
- package/dist/react/hooks/useVerification.js +23 -7
- package/dist/react/hooks/useVerification.js.map +1 -1
- package/dist/react/index.js +18 -2
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/index.js +17 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/shared/WebCrypto.d.ts +55 -0
- package/dist/shared/WebCrypto.d.ts.map +1 -0
- package/dist/shared/WebCrypto.js +342 -0
- package/dist/shared/WebCrypto.js.map +1 -0
- package/dist/shared/constants.js +15 -11
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/datetime.js +110 -83
- package/dist/shared/datetime.js.map +1 -1
- package/dist/shared/display.js +231 -151
- package/dist/shared/display.js.map +1 -1
- package/dist/shared/errors.js +12 -5
- package/dist/shared/errors.js.map +1 -1
- package/dist/shared/graph.js +14 -11
- package/dist/shared/graph.js.map +1 -1
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +32 -11
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/match.js +25 -17
- package/dist/shared/match.js.map +1 -1
- package/dist/shared/request.js +19 -13
- package/dist/shared/request.js.map +1 -1
- package/dist/shared/shopify.js +31 -21
- package/dist/shared/shopify.js.map +1 -1
- package/dist/shared/uuid.js +8 -3
- package/dist/shared/uuid.js.map +1 -1
- package/dist/shared/verification.d.ts +12 -5
- package/dist/shared/verification.d.ts.map +1 -1
- package/dist/shared/verification.js +34 -22
- package/dist/shared/verification.js.map +1 -1
- package/dist/umd/{verification.js → verification/index.js} +714 -352
- package/dist/umd/verification/index.js.map +1 -0
- package/dist/umd/{react → verification/react}/hooks/useVerification.d.ts +1 -1
- package/dist/umd/verification/shared/WebCrypto.d.ts +55 -0
- package/dist/umd/verification/shared/WebCrypto.d.ts.map +1 -0
- package/dist/umd/{shared → verification/shared}/index.d.ts +1 -1
- package/dist/umd/{shared → verification/shared}/index.d.ts.map +1 -1
- package/dist/umd/{shared → verification/shared}/verification.d.ts +12 -5
- package/dist/umd/{shared → verification/shared}/verification.d.ts.map +1 -1
- package/dist/umd/verification/{index.d.ts → verification/index.d.ts} +1 -0
- package/dist/umd/verification/{index.d.ts.map → verification/index.d.ts.map} +1 -1
- package/dist/umd/verification/{utils → verification/utils}/rawbody.d.ts.map +1 -1
- package/dist/umd/verification/verification/verification.d.ts +10 -0
- package/dist/umd/verification/{verification.d.ts.map → verification/verification.d.ts.map} +1 -1
- package/dist/verification/index.d.ts +1 -0
- package/dist/verification/index.d.ts.map +1 -1
- package/dist/verification/index.js +19 -2
- package/dist/verification/index.js.map +1 -1
- package/dist/verification/utils/errors.js +5 -1
- package/dist/verification/utils/errors.js.map +1 -1
- package/dist/verification/utils/index.js +18 -2
- package/dist/verification/utils/index.js.map +1 -1
- package/dist/verification/utils/rawbody.d.ts.map +1 -1
- package/dist/verification/utils/rawbody.js +39 -36
- package/dist/verification/utils/rawbody.js.map +1 -1
- package/dist/verification/verification.d.ts +3 -1
- package/dist/verification/verification.d.ts.map +1 -1
- package/dist/verification/verification.js +71 -61
- package/dist/verification/verification.js.map +1 -1
- package/node_modules/bytes/History.md +97 -0
- package/node_modules/bytes/LICENSE +23 -0
- package/node_modules/bytes/Readme.md +152 -0
- package/node_modules/bytes/index.js +170 -0
- package/node_modules/bytes/package.json +42 -0
- package/node_modules/depd/History.md +103 -0
- package/node_modules/depd/LICENSE +22 -0
- package/node_modules/depd/Readme.md +280 -0
- package/node_modules/depd/index.js +538 -0
- package/node_modules/depd/lib/browser/index.js +77 -0
- package/node_modules/depd/package.json +45 -0
- package/node_modules/http-errors/HISTORY.md +180 -0
- package/node_modules/http-errors/LICENSE +23 -0
- package/node_modules/http-errors/README.md +169 -0
- package/node_modules/http-errors/index.js +289 -0
- package/node_modules/http-errors/package.json +50 -0
- package/node_modules/iconv-lite/Changelog.md +162 -0
- package/node_modules/iconv-lite/LICENSE +21 -0
- package/node_modules/iconv-lite/README.md +156 -0
- package/node_modules/iconv-lite/encodings/dbcs-codec.js +555 -0
- package/node_modules/iconv-lite/encodings/dbcs-data.js +176 -0
- package/node_modules/iconv-lite/encodings/index.js +22 -0
- package/node_modules/iconv-lite/encodings/internal.js +188 -0
- package/node_modules/iconv-lite/encodings/sbcs-codec.js +72 -0
- package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/node_modules/iconv-lite/encodings/sbcs-data.js +174 -0
- package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/node_modules/iconv-lite/encodings/tables/gbk-added.json +55 -0
- package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/node_modules/iconv-lite/encodings/utf16.js +177 -0
- package/node_modules/iconv-lite/encodings/utf7.js +290 -0
- package/node_modules/iconv-lite/lib/bom-handling.js +52 -0
- package/node_modules/iconv-lite/lib/extend-node.js +217 -0
- package/node_modules/iconv-lite/lib/index.d.ts +24 -0
- package/node_modules/iconv-lite/lib/index.js +153 -0
- package/node_modules/iconv-lite/lib/streams.js +121 -0
- package/node_modules/iconv-lite/package.json +46 -0
- package/node_modules/inherits/LICENSE +16 -0
- package/node_modules/inherits/README.md +42 -0
- package/node_modules/inherits/inherits.js +9 -0
- package/node_modules/inherits/inherits_browser.js +27 -0
- package/node_modules/inherits/package.json +29 -0
- package/node_modules/raw-body/HISTORY.md +308 -0
- package/node_modules/raw-body/LICENSE +22 -0
- package/node_modules/raw-body/README.md +223 -0
- package/node_modules/raw-body/SECURITY.md +24 -0
- package/node_modules/raw-body/index.d.ts +87 -0
- package/node_modules/raw-body/index.js +336 -0
- package/node_modules/raw-body/package.json +49 -0
- package/node_modules/safer-buffer/LICENSE +21 -0
- package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/node_modules/safer-buffer/Readme.md +156 -0
- package/node_modules/safer-buffer/dangerous.js +58 -0
- package/node_modules/safer-buffer/package.json +34 -0
- package/node_modules/safer-buffer/safer.js +77 -0
- package/node_modules/safer-buffer/tests.js +406 -0
- package/node_modules/setprototypeof/LICENSE +13 -0
- package/node_modules/setprototypeof/README.md +31 -0
- package/node_modules/setprototypeof/index.d.ts +2 -0
- package/node_modules/setprototypeof/index.js +17 -0
- package/node_modules/setprototypeof/package.json +38 -0
- package/node_modules/setprototypeof/test/index.js +24 -0
- package/node_modules/statuses/HISTORY.md +82 -0
- package/node_modules/statuses/LICENSE +23 -0
- package/node_modules/statuses/README.md +136 -0
- package/node_modules/statuses/codes.json +65 -0
- package/node_modules/statuses/index.js +146 -0
- package/node_modules/statuses/package.json +49 -0
- package/node_modules/toidentifier/HISTORY.md +9 -0
- package/node_modules/toidentifier/LICENSE +21 -0
- package/node_modules/toidentifier/README.md +61 -0
- package/node_modules/toidentifier/index.js +32 -0
- package/node_modules/toidentifier/package.json +38 -0
- package/node_modules/unpipe/HISTORY.md +4 -0
- package/node_modules/unpipe/LICENSE +22 -0
- package/node_modules/unpipe/README.md +43 -0
- package/node_modules/unpipe/index.js +69 -0
- package/node_modules/unpipe/package.json +27 -0
- package/package.json +15 -14
- package/dist/shared/subtlecrypto.d.ts +0 -41
- package/dist/shared/subtlecrypto.d.ts.map +0 -1
- package/dist/shared/subtlecrypto.js +0 -256
- package/dist/shared/subtlecrypto.js.map +0 -1
- package/dist/umd/shared/subtlecrypto.d.ts +0 -41
- package/dist/umd/shared/subtlecrypto.d.ts.map +0 -1
- package/dist/umd/verification/verification.d.ts +0 -8
- package/dist/umd/verification.js.map +0 -1
- /package/dist/umd/{lib → verification/lib}/handlers/api/auth.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/auth.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/billing.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/billing.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/callback.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/callback.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/types.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/types.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/uninstall.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/uninstall.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/appInstallation.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/appInstallation.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/graph.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/graph.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/proxy.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/proxy.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/rest.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/rest.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/token.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/verifiable/token.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/webhook.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/api/webhook.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/protect.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/protect.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/types.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/types.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/wrap.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/ssr/wrap.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/types.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/handlers/types.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/types.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/types.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/billing.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/billing.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/crypto.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/crypto.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/firebase.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/firebase.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/headers.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/headers.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/index.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/index.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/session.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/session.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/shopify-api-js/oauth.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/shopify-api-js/oauth.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/shopify.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/shopify.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/token.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/token.d.ts.map +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/types.d.ts +0 -0
- /package/dist/umd/{lib → verification/lib}/utils/types.d.ts.map +0 -0
- /package/dist/umd/{plugins → verification/plugins}/index.d.ts +0 -0
- /package/dist/umd/{plugins → verification/plugins}/index.d.ts.map +0 -0
- /package/dist/umd/{plugins → verification/plugins}/types.d.ts +0 -0
- /package/dist/umd/{plugins → verification/plugins}/types.d.ts.map +0 -0
- /package/dist/umd/{plugins → verification/plugins}/withShopify.d.ts +0 -0
- /package/dist/umd/{plugins → verification/plugins}/withShopify.d.ts.map +0 -0
- /package/dist/umd/{react → verification/react}/hooks/index.d.ts +0 -0
- /package/dist/umd/{react → verification/react}/hooks/index.d.ts.map +0 -0
- /package/dist/umd/{react → verification/react}/hooks/useVerification.d.ts.map +0 -0
- /package/dist/umd/{react → verification/react}/index.d.ts +0 -0
- /package/dist/umd/{react → verification/react}/index.d.ts.map +0 -0
- /package/dist/umd/{react → verification/react}/types.d.ts +0 -0
- /package/dist/umd/{react → verification/react}/types.d.ts.map +0 -0
- /package/dist/umd/{runtime → verification/runtime}/index.d.ts +0 -0
- /package/dist/umd/{runtime → verification/runtime}/index.d.ts.map +0 -0
- /package/dist/umd/{runtime → verification/runtime}/types.d.ts +0 -0
- /package/dist/umd/{runtime → verification/runtime}/types.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/constants.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/constants.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/datetime.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/datetime.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/display.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/display.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/errors.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/errors.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/graph.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/graph.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/match.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/match.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/request.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/request.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/shopify.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/shopify.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/types.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/types.d.ts.map +0 -0
- /package/dist/umd/{shared → verification/shared}/uuid.d.ts +0 -0
- /package/dist/umd/{shared → verification/shared}/uuid.d.ts.map +0 -0
- /package/dist/umd/verification/{types.d.ts → verification/types.d.ts} +0 -0
- /package/dist/umd/verification/{types.d.ts.map → verification/types.d.ts.map} +0 -0
- /package/dist/umd/verification/{utils → verification/utils}/errors.d.ts +0 -0
- /package/dist/umd/verification/{utils → verification/utils}/errors.d.ts.map +0 -0
- /package/dist/umd/verification/{utils → verification/utils}/index.d.ts +0 -0
- /package/dist/umd/verification/{utils → verification/utils}/index.d.ts.map +0 -0
- /package/dist/umd/verification/{utils → verification/utils}/rawbody.d.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@agnostack/next-shopify/
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@agnostack/next-shopify/verification"] = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const COLLECTION_ROOT = 'oauth-data';
|
|
@@ -227,11 +227,41 @@
|
|
|
227
227
|
ONLINE: 'online',
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
-
|
|
230
|
+
class VerificationError extends Error {
|
|
231
|
+
constructor(message, _data) {
|
|
232
|
+
super(message);
|
|
233
|
+
const { code = 500, ...data } = _data ?? {};
|
|
234
|
+
this.code = code;
|
|
235
|
+
this.data = data;
|
|
236
|
+
this.name = 'VerificationError';
|
|
237
|
+
Object.setPrototypeOf(this, VerificationError.prototype);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
231
240
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
241
|
+
const getChunkedRawBody = async (readable) => {
|
|
242
|
+
if (readable?.rawBody) {
|
|
243
|
+
return readable.rawBody
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// TODO: move to req.text() after next 13.5: https://github.com/vercel/next.js/discussions/13405
|
|
247
|
+
try {
|
|
248
|
+
const getRawBody = (await Promise.resolve().then(function () { return index; })).default;
|
|
249
|
+
return getRawBody(readable)
|
|
250
|
+
} catch (error) {
|
|
251
|
+
console.error(`Failed to import 'raw-body', please ensure the dependency is installed`);
|
|
252
|
+
throw error
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// TODO: explore returning mutated request object adding on req.rawBody??
|
|
257
|
+
const ensureRawBody = async (req) => (
|
|
258
|
+
getChunkedRawBody(req)
|
|
259
|
+
.then((_rawBody) => _rawBody.toString())
|
|
260
|
+
.catch((error) => {
|
|
261
|
+
console.error(`Error getting raw body for '${req?.url}'`, error);
|
|
262
|
+
throw error
|
|
263
|
+
})
|
|
264
|
+
);
|
|
235
265
|
|
|
236
266
|
/* eslint-disable no-use-before-define */
|
|
237
267
|
|
|
@@ -333,438 +363,429 @@
|
|
|
333
363
|
return ![...ensureArray(falsy), '', 'false'].includes(string)
|
|
334
364
|
};
|
|
335
365
|
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
const crypto = (await import('isomorphic-webcrypto')).default;
|
|
339
|
-
return crypto
|
|
340
|
-
} catch (error) {
|
|
341
|
-
console.error('Failed to import isomorphic-webcrypto', error);
|
|
342
|
-
throw error
|
|
343
|
-
}
|
|
344
|
-
};
|
|
366
|
+
const TEMP_HOSTNAME = 'xyz.com';
|
|
367
|
+
const REMOVABLE_KEYS = ['shop', 'host'];
|
|
345
368
|
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
return window.TextDecoder
|
|
349
|
-
}
|
|
369
|
+
const getRequestMethod = (body, _method) => {
|
|
370
|
+
const method = _method ?? (body ? 'POST' : 'GET');
|
|
350
371
|
|
|
351
|
-
|
|
352
|
-
const TextDecoder = (await import('util')).TextDecoder;
|
|
353
|
-
return TextDecoder
|
|
354
|
-
} catch (error) {
|
|
355
|
-
console.error('Failed to import utils.TextDecoder', error);
|
|
356
|
-
throw error
|
|
357
|
-
}
|
|
372
|
+
return uppercase(method)
|
|
358
373
|
};
|
|
359
374
|
|
|
360
|
-
const
|
|
361
|
-
if (
|
|
362
|
-
return
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
try {
|
|
366
|
-
const TextEncoder = (await import('util')).TextEncoder;
|
|
367
|
-
return TextEncoder
|
|
368
|
-
} catch (error) {
|
|
369
|
-
console.error('Failed to import utils.TextEncoder', error);
|
|
370
|
-
throw error
|
|
375
|
+
const convertToURL = (uri) => {
|
|
376
|
+
if (stringEmpty(uri)) {
|
|
377
|
+
return undefined
|
|
371
378
|
}
|
|
372
|
-
};
|
|
373
379
|
|
|
374
|
-
|
|
375
|
-
if (
|
|
376
|
-
(value1 == undefined) ||
|
|
377
|
-
(value2 == undefined) ||
|
|
378
|
-
(value1.length !== value2.length)
|
|
379
|
-
) {
|
|
380
|
-
return false
|
|
381
|
-
}
|
|
380
|
+
const protocolRegex = /^(https?:\/\/).+/i;
|
|
382
381
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
for (let i = 0; i < value1.length; i++) {
|
|
386
|
-
// eslint-disable-next-line no-bitwise
|
|
387
|
-
result |= value1[i] ^ value2[i];
|
|
382
|
+
if (!protocolRegex.test(uri)) {
|
|
383
|
+
return new URL(`https://${TEMP_HOSTNAME}${ensureLeadingSlash(uri)}`)
|
|
388
384
|
}
|
|
389
385
|
|
|
390
|
-
return (
|
|
386
|
+
return new URL(uri)
|
|
391
387
|
};
|
|
392
388
|
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
389
|
+
const normalizeURIParts = (uri) => {
|
|
390
|
+
const urlObject = convertToURL(uri);
|
|
391
|
+
if (!urlObject) {
|
|
392
|
+
return undefined
|
|
393
|
+
}
|
|
398
394
|
|
|
399
|
-
|
|
400
|
-
ensureArray(
|
|
401
|
-
ensureString(hexValue).match(/.{1,2}/g)
|
|
402
|
-
)
|
|
403
|
-
.map((byte) => String.fromCharCode(parseInt(byte, 16)))
|
|
404
|
-
.join('')
|
|
405
|
-
);
|
|
395
|
+
REMOVABLE_KEYS.forEach((key) => urlObject.searchParams.delete(key));
|
|
406
396
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
397
|
+
return {
|
|
398
|
+
...(urlObject.hostname !== TEMP_HOSTNAME) && {
|
|
399
|
+
origin: urlObject.origin,
|
|
400
|
+
},
|
|
401
|
+
pathname: urlObject.pathname,
|
|
402
|
+
search: urlObject.search,
|
|
403
|
+
}
|
|
411
404
|
};
|
|
412
405
|
|
|
413
|
-
|
|
414
|
-
(ArrayBuffer.from != undefined)
|
|
415
|
-
? ArrayBuffer.from(array)
|
|
416
|
-
: new Uint8Array(array).buffer
|
|
417
|
-
);
|
|
406
|
+
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};
|
|
418
407
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
: arrayToArrayBuffer(arrayOrArrayBuffer)
|
|
423
|
-
);
|
|
408
|
+
let win = global.window;
|
|
409
|
+
let exists = (variable) => !u(variable);
|
|
410
|
+
let window = typeof win !== "undefined" ? win : r;
|
|
424
411
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
{
|
|
429
|
-
|
|
430
|
-
namedCurve: 'P-256',
|
|
431
|
-
},
|
|
432
|
-
true,
|
|
433
|
-
['deriveKey']
|
|
434
|
-
);
|
|
412
|
+
class WebCrypto {
|
|
413
|
+
constructor({ crypto: _crypto, util: _util } = {}) {
|
|
414
|
+
this._crypto = _crypto ?? {};
|
|
415
|
+
this._util = _util ?? {};
|
|
416
|
+
}
|
|
435
417
|
|
|
436
|
-
|
|
437
|
-
|
|
418
|
+
get subtle() {
|
|
419
|
+
return this._crypto?.subtle
|
|
420
|
+
}
|
|
438
421
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
422
|
+
async getWebCrypto() {
|
|
423
|
+
if (!this._crypto?.subtle) {
|
|
424
|
+
try {
|
|
425
|
+
this._crypto = (await import('isomorphic-webcrypto')).default;
|
|
426
|
+
} catch (_ignore) {
|
|
427
|
+
console.info('Failed to import isomorphic-webcrypto, retrying w/ node crypto');
|
|
428
|
+
try {
|
|
429
|
+
this._crypto = (await import('crypto')).default;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
// eslint-disable-next-line max-len
|
|
432
|
+
console.error(`Failed to import node crypto, ensure 'isomorphic-webcrypto' (or node 'crypto') is installed and/or pass in implementation via 'new WebCrypto({ crypto })'`);
|
|
433
|
+
throw error
|
|
434
|
+
}
|
|
435
|
+
}
|
|
444
436
|
}
|
|
445
437
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
case 'sharedSecret': {
|
|
449
|
-
return ['encrypt', 'decrypt']
|
|
438
|
+
if (!this._crypto?.subtle) {
|
|
439
|
+
throw new Error('Invalid crypto, missing subtle')
|
|
450
440
|
}
|
|
451
441
|
|
|
452
|
-
|
|
453
|
-
return []
|
|
454
|
-
}
|
|
442
|
+
return this._crypto
|
|
455
443
|
}
|
|
456
|
-
};
|
|
457
444
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
case 'derived':
|
|
462
|
-
case 'secret':
|
|
463
|
-
case 'secretKey':
|
|
464
|
-
case 'sharedSecret': {
|
|
465
|
-
return {
|
|
466
|
-
name: 'AES-GCM',
|
|
467
|
-
}
|
|
445
|
+
async getTextDecoder() {
|
|
446
|
+
if (this._util?.TextDecoder) {
|
|
447
|
+
return this._util.TextDecoder
|
|
468
448
|
}
|
|
469
449
|
|
|
470
|
-
|
|
471
|
-
return
|
|
472
|
-
name: 'ECDH',
|
|
473
|
-
namedCurve: 'P-256',
|
|
474
|
-
}
|
|
450
|
+
if (exists(window) && typeof window?.TextDecoder === 'function') {
|
|
451
|
+
return window.TextDecoder
|
|
475
452
|
}
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
453
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
454
|
+
try {
|
|
455
|
+
const TextDecoder = (await import('util')).TextDecoder;
|
|
456
|
+
this._util.TextDecoder = TextDecoder;
|
|
483
457
|
|
|
484
|
-
|
|
485
|
-
|
|
458
|
+
return TextDecoder
|
|
459
|
+
} catch (error) {
|
|
460
|
+
console.error(`Failed to import 'utils.TextDecoder', ensure 'util' is available and/or pass in implementation via 'new WebCrypto({ util })'`);
|
|
461
|
+
throw error
|
|
462
|
+
}
|
|
463
|
+
}
|
|
486
464
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
);
|
|
465
|
+
async getTextEncoder() {
|
|
466
|
+
if (this._util?.TextEncoder) {
|
|
467
|
+
return this._util.TextEncoder
|
|
468
|
+
}
|
|
492
469
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
};
|
|
470
|
+
if (exists(window) && typeof window?.TextEncoder === 'function') {
|
|
471
|
+
return window.TextEncoder
|
|
472
|
+
}
|
|
497
473
|
|
|
498
|
-
|
|
499
|
-
|
|
474
|
+
try {
|
|
475
|
+
const TextEncoder = (await import('util')).TextEncoder;
|
|
476
|
+
this._util.TextEncoder = TextEncoder;
|
|
500
477
|
|
|
501
|
-
|
|
502
|
-
|
|
478
|
+
return TextEncoder
|
|
479
|
+
} catch (error) {
|
|
480
|
+
console.error(`Failed to import 'utils.TextEncoder', ensure 'util' is available and/or pass in implementation via 'new WebCrypto({ util })'`);
|
|
481
|
+
throw error
|
|
482
|
+
}
|
|
483
|
+
}
|
|
503
484
|
|
|
504
|
-
|
|
505
|
-
|
|
485
|
+
timingSafeEqual(value1, value2) {
|
|
486
|
+
if (
|
|
487
|
+
(value1 == undefined) ||
|
|
488
|
+
(value2 == undefined) ||
|
|
489
|
+
(value1.length !== value2.length)
|
|
490
|
+
) {
|
|
491
|
+
return false
|
|
492
|
+
}
|
|
506
493
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
494
|
+
let result = 0;
|
|
495
|
+
// eslint-disable-next-line no-plusplus
|
|
496
|
+
for (let i = 0; i < value1.length; i++) {
|
|
497
|
+
// eslint-disable-next-line no-bitwise
|
|
498
|
+
result |= value1[i] ^ value2[i];
|
|
499
|
+
}
|
|
510
500
|
|
|
511
|
-
|
|
512
|
-
if (!storableHex) {
|
|
513
|
-
return undefined
|
|
501
|
+
return (result === 0)
|
|
514
502
|
}
|
|
515
|
-
const crypto = await getWebCrypto();
|
|
516
503
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
504
|
+
stringToHex(stringValue) {
|
|
505
|
+
return (
|
|
506
|
+
Array.from(ensureString(stringValue), (char) => (
|
|
507
|
+
char.charCodeAt(0).toString(16).padStart(2, '0')
|
|
508
|
+
)).join('')
|
|
509
|
+
)
|
|
520
510
|
}
|
|
521
511
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
512
|
+
hexToString(hexValue) {
|
|
513
|
+
return (
|
|
514
|
+
ensureArray(
|
|
515
|
+
ensureString(hexValue).match(/.{1,2}/g)
|
|
516
|
+
)
|
|
517
|
+
.map((byte) => String.fromCharCode(parseInt(byte, 16)))
|
|
518
|
+
.join('')
|
|
519
|
+
)
|
|
520
|
+
}
|
|
530
521
|
|
|
531
|
-
|
|
532
|
-
|
|
522
|
+
async arrayBufferToString(arrayBuffer) {
|
|
523
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
524
|
+
const Decoder = await this.getTextDecoder();
|
|
525
|
+
return new Decoder().decode(uint8Array)
|
|
526
|
+
}
|
|
533
527
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
528
|
+
arrayToArrayBuffer(array) {
|
|
529
|
+
return (
|
|
530
|
+
(ArrayBuffer.from != undefined)
|
|
531
|
+
? ArrayBuffer.from(array)
|
|
532
|
+
: new Uint8Array(array).buffer
|
|
533
|
+
)
|
|
538
534
|
}
|
|
539
535
|
|
|
540
|
-
|
|
541
|
-
|
|
536
|
+
ensureArrayBuffer(arrayOrArrayBuffer) {
|
|
537
|
+
return (
|
|
538
|
+
(arrayOrArrayBuffer instanceof ArrayBuffer)
|
|
539
|
+
? arrayOrArrayBuffer
|
|
540
|
+
: this.arrayToArrayBuffer(arrayOrArrayBuffer)
|
|
541
|
+
)
|
|
542
|
+
}
|
|
542
543
|
|
|
543
|
-
|
|
544
|
-
|
|
544
|
+
async generateKeyPair() {
|
|
545
|
+
const crypto = await this.getWebCrypto();
|
|
546
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
547
|
+
{
|
|
548
|
+
name: 'ECDH',
|
|
549
|
+
namedCurve: 'P-256',
|
|
550
|
+
},
|
|
551
|
+
true,
|
|
552
|
+
['deriveKey']
|
|
553
|
+
);
|
|
545
554
|
|
|
546
|
-
|
|
547
|
-
for (const [keyType, key] of Object.entries(keyPair)) {
|
|
548
|
-
// eslint-disable-next-line no-await-in-loop
|
|
549
|
-
restoredKeys[keyType] = await restoreStorableKey(keyType, key);
|
|
555
|
+
return keyPair
|
|
550
556
|
}
|
|
551
557
|
|
|
552
|
-
|
|
553
|
-
|
|
558
|
+
getKeyOperations(keyType) {
|
|
559
|
+
switch (keyType) {
|
|
560
|
+
case 'private':
|
|
561
|
+
case 'privateKey': {
|
|
562
|
+
return ['deriveKey']
|
|
563
|
+
}
|
|
554
564
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
565
|
+
case 'secret':
|
|
566
|
+
case 'secretKey':
|
|
567
|
+
case 'sharedSecret': {
|
|
568
|
+
return ['encrypt', 'decrypt']
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
default: {
|
|
572
|
+
return []
|
|
573
|
+
}
|
|
574
|
+
}
|
|
558
575
|
}
|
|
559
576
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
true,
|
|
572
|
-
['encrypt', 'decrypt']
|
|
573
|
-
);
|
|
574
|
-
return derivedKey
|
|
575
|
-
};
|
|
577
|
+
getKeyAlgorythm(keyType) {
|
|
578
|
+
switch (keyType) {
|
|
579
|
+
case 'derivedKey':
|
|
580
|
+
case 'derived':
|
|
581
|
+
case 'secret':
|
|
582
|
+
case 'secretKey':
|
|
583
|
+
case 'sharedSecret': {
|
|
584
|
+
return {
|
|
585
|
+
name: 'AES-GCM',
|
|
586
|
+
}
|
|
587
|
+
}
|
|
576
588
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
589
|
+
default: {
|
|
590
|
+
return {
|
|
591
|
+
name: 'ECDH',
|
|
592
|
+
namedCurve: 'P-256',
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
580
596
|
}
|
|
581
597
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
public: publicKey,
|
|
587
|
-
},
|
|
588
|
-
privateKey,
|
|
589
|
-
{
|
|
590
|
-
name: 'HMAC',
|
|
591
|
-
hash: { name: 'SHA-256' },
|
|
592
|
-
length: 256, // Adjusted key length, e.g., 128 bits
|
|
593
|
-
},
|
|
594
|
-
true,
|
|
595
|
-
['sign', 'verify']
|
|
596
|
-
);
|
|
597
|
-
return derivedKey
|
|
598
|
-
};
|
|
598
|
+
async generateHMAC(message, derivedKey) {
|
|
599
|
+
if (!message || !derivedKey) {
|
|
600
|
+
return undefined
|
|
601
|
+
}
|
|
599
602
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
return {}
|
|
603
|
-
}
|
|
603
|
+
const crypto = await this.getWebCrypto();
|
|
604
|
+
const Encoder = await this.getTextEncoder();
|
|
604
605
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
606
|
+
const signature = await crypto.subtle.sign(
|
|
607
|
+
'HMAC',
|
|
608
|
+
derivedKey,
|
|
609
|
+
new Encoder().encode(message)
|
|
610
|
+
);
|
|
608
611
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
+
return this.stringToHex(
|
|
613
|
+
this.arrayBufferToString(signature)
|
|
614
|
+
)
|
|
612
615
|
}
|
|
613
|
-
};
|
|
614
616
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
617
|
+
async verifyHMAC(message, derivedKey, verifiableHMAC) {
|
|
618
|
+
const calculatedHMAC = await this.generateHMAC(message, derivedKey);
|
|
619
|
+
|
|
620
|
+
return this.timingSafeEqual(calculatedHMAC, verifiableHMAC)
|
|
618
621
|
}
|
|
619
622
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const Encoder = await getTextEncoder();
|
|
623
|
-
const encodedMessage = new Encoder().encode(decryptedMessage);
|
|
624
|
-
const ciphertext = await crypto.subtle.encrypt(
|
|
625
|
-
{
|
|
626
|
-
name: 'AES-GCM',
|
|
627
|
-
iv,
|
|
628
|
-
},
|
|
629
|
-
derivedKey,
|
|
630
|
-
encodedMessage
|
|
631
|
-
);
|
|
632
|
-
|
|
633
|
-
const encryptedMessage = new Uint8Array([
|
|
634
|
-
...iv,
|
|
635
|
-
...new Uint8Array(ciphertext)
|
|
636
|
-
]);
|
|
637
|
-
return Array.from(encryptedMessage)
|
|
638
|
-
};
|
|
623
|
+
async getStorableKey(key) {
|
|
624
|
+
const crypto = await this.getWebCrypto();
|
|
639
625
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
return undefined
|
|
626
|
+
const exportedJWK = await crypto.subtle.exportKey('jwk', key);
|
|
627
|
+
return this.stringToHex(JSON.stringify(exportedJWK))
|
|
643
628
|
}
|
|
644
629
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
630
|
+
async restoreStorableKey(keyType, storableHex) {
|
|
631
|
+
if (!storableHex) {
|
|
632
|
+
return undefined
|
|
633
|
+
}
|
|
634
|
+
const crypto = await this.getWebCrypto();
|
|
650
635
|
|
|
651
|
-
|
|
652
|
-
{
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
},
|
|
656
|
-
derivedKey,
|
|
657
|
-
ciphertext
|
|
658
|
-
);
|
|
636
|
+
const exportedJWK = JSON.parse(this.hexToString(storableHex) || '{}');
|
|
637
|
+
if (objectEmpty(exportedJWK)) {
|
|
638
|
+
return undefined
|
|
639
|
+
}
|
|
659
640
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
641
|
+
return crypto.subtle.importKey(
|
|
642
|
+
'jwk',
|
|
643
|
+
exportedJWK,
|
|
644
|
+
this.getKeyAlgorythm(keyType),
|
|
645
|
+
true,
|
|
646
|
+
this.getKeyOperations(keyType)
|
|
647
|
+
)
|
|
648
|
+
}
|
|
664
649
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
generateHMAC,
|
|
668
|
-
verifyHMAC,
|
|
669
|
-
getStorableKey,
|
|
670
|
-
getStorableKeyPair,
|
|
671
|
-
restoreStorableKeyPair,
|
|
672
|
-
deriveSharedKey,
|
|
673
|
-
deriveHMACKey,
|
|
674
|
-
getVerificationKeys,
|
|
675
|
-
encryptMessage,
|
|
676
|
-
decryptMessage,
|
|
677
|
-
};
|
|
650
|
+
async getStorableKeyPair(keyPair) {
|
|
651
|
+
const storableKeys = {};
|
|
678
652
|
|
|
679
|
-
|
|
680
|
-
|
|
653
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
654
|
+
for (const [keyType, key] of Object.entries(keyPair)) {
|
|
655
|
+
// eslint-disable-next-line no-await-in-loop
|
|
656
|
+
storableKeys[keyType] = await this.getStorableKey(key);
|
|
657
|
+
}
|
|
681
658
|
|
|
682
|
-
|
|
683
|
-
|
|
659
|
+
return storableKeys
|
|
660
|
+
}
|
|
684
661
|
|
|
685
|
-
|
|
686
|
-
|
|
662
|
+
async restoreStorableKeyPair(keyPair) {
|
|
663
|
+
const restoredKeys = {};
|
|
687
664
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
665
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
666
|
+
for (const [keyType, key] of Object.entries(keyPair)) {
|
|
667
|
+
// eslint-disable-next-line no-await-in-loop
|
|
668
|
+
restoredKeys[keyType] = await this.restoreStorableKey(keyType, key);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return restoredKeys
|
|
691
672
|
}
|
|
692
673
|
|
|
693
|
-
|
|
674
|
+
async deriveSharedKey({ publicKey, privateKey }) {
|
|
675
|
+
if (!publicKey || !privateKey) {
|
|
676
|
+
return undefined
|
|
677
|
+
}
|
|
694
678
|
|
|
695
|
-
|
|
696
|
-
|
|
679
|
+
const crypto = await this.getWebCrypto();
|
|
680
|
+
const derivedKey = await crypto.subtle.deriveKey(
|
|
681
|
+
{
|
|
682
|
+
name: 'ECDH',
|
|
683
|
+
public: publicKey,
|
|
684
|
+
},
|
|
685
|
+
privateKey,
|
|
686
|
+
{
|
|
687
|
+
name: 'AES-GCM',
|
|
688
|
+
length: 256,
|
|
689
|
+
},
|
|
690
|
+
true,
|
|
691
|
+
['encrypt', 'decrypt']
|
|
692
|
+
);
|
|
693
|
+
return derivedKey
|
|
697
694
|
}
|
|
698
695
|
|
|
699
|
-
|
|
700
|
-
|
|
696
|
+
async deriveHMACKey({ publicKey, privateKey }) {
|
|
697
|
+
if (!publicKey || !privateKey) {
|
|
698
|
+
return undefined
|
|
699
|
+
}
|
|
701
700
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
701
|
+
const crypto = await this.getWebCrypto();
|
|
702
|
+
const derivedKey = await crypto.subtle.deriveKey(
|
|
703
|
+
{
|
|
704
|
+
name: 'ECDH',
|
|
705
|
+
public: publicKey,
|
|
706
|
+
},
|
|
707
|
+
privateKey,
|
|
708
|
+
{
|
|
709
|
+
name: 'HMAC',
|
|
710
|
+
hash: { name: 'SHA-256' },
|
|
711
|
+
length: 256, // Adjusted key length, e.g., 128 bits
|
|
712
|
+
},
|
|
713
|
+
true,
|
|
714
|
+
['sign', 'verify']
|
|
715
|
+
);
|
|
716
|
+
return derivedKey
|
|
706
717
|
}
|
|
707
718
|
|
|
708
|
-
|
|
719
|
+
async getVerificationKeys({ publicKey, privateKey }) {
|
|
720
|
+
if (!publicKey || !privateKey) {
|
|
721
|
+
return {}
|
|
722
|
+
}
|
|
709
723
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
},
|
|
714
|
-
pathname: urlObject.pathname,
|
|
715
|
-
search: urlObject.search,
|
|
716
|
-
}
|
|
717
|
-
};
|
|
724
|
+
const sharedKeyPair = await this.restoreStorableKeyPair({ publicKey, privateKey });
|
|
725
|
+
const derivedHMACKey = await this.deriveHMACKey(sharedKeyPair);
|
|
726
|
+
const derivedSecretKey = await this.deriveSharedKey(sharedKeyPair);
|
|
718
727
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
this.code = code;
|
|
724
|
-
this.data = data;
|
|
725
|
-
this.name = 'VerificationError';
|
|
726
|
-
Object.setPrototypeOf(this, VerificationError.prototype);
|
|
728
|
+
return {
|
|
729
|
+
derivedSecretKey,
|
|
730
|
+
derivedHMACKey,
|
|
731
|
+
}
|
|
727
732
|
}
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// import getRawBody from 'raw-body'
|
|
731
|
-
// import * as getRawBody from 'raw-body'
|
|
732
733
|
|
|
733
|
-
|
|
734
|
-
|
|
734
|
+
async encryptMessage(decryptedMessage, derivedKey) {
|
|
735
|
+
if (!decryptedMessage || !derivedKey) {
|
|
736
|
+
return undefined
|
|
737
|
+
}
|
|
735
738
|
|
|
736
|
-
|
|
737
|
-
|
|
739
|
+
const crypto = await this.getWebCrypto();
|
|
740
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
741
|
+
const Encoder = await this.getTextEncoder();
|
|
742
|
+
const encodedMessage = new Encoder().encode(decryptedMessage);
|
|
743
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
744
|
+
{
|
|
745
|
+
name: 'AES-GCM',
|
|
746
|
+
iv,
|
|
747
|
+
},
|
|
748
|
+
derivedKey,
|
|
749
|
+
encodedMessage
|
|
750
|
+
);
|
|
751
|
+
|
|
752
|
+
const encryptedMessage = new Uint8Array([
|
|
753
|
+
...iv,
|
|
754
|
+
...new Uint8Array(ciphertext)
|
|
755
|
+
]);
|
|
756
|
+
return Array.from(encryptedMessage)
|
|
738
757
|
}
|
|
739
758
|
|
|
740
|
-
|
|
741
|
-
|
|
759
|
+
async decryptMessage(encryptedMessage, derivedKey) {
|
|
760
|
+
if (!encryptedMessage || !derivedKey) {
|
|
761
|
+
return undefined
|
|
762
|
+
}
|
|
742
763
|
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
.then((_rawBody) => _rawBody.toString())
|
|
749
|
-
.catch((error) => {
|
|
750
|
-
// NOTE: this is intended to ensure if getRawBody is called 2x w/in a route that it returns the already streamed body
|
|
751
|
-
if ((error?.type === 'stream.not.readable')) {
|
|
752
|
-
if (!req?.rawBody) {
|
|
753
|
-
// eslint-disable-next-line max-len
|
|
754
|
-
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).');
|
|
755
|
-
return req?.body
|
|
756
|
-
}
|
|
764
|
+
const crypto = await this.getWebCrypto();
|
|
765
|
+
// NOTE: this presumed an array or arrayBuffer coming in as encryptedMessage (will fail w/ IV error if its a string)
|
|
766
|
+
const encryptedArrayBuffer = this.ensureArrayBuffer(encryptedMessage);
|
|
767
|
+
const iv = encryptedArrayBuffer.slice(0, 12);
|
|
768
|
+
const ciphertext = encryptedArrayBuffer.slice(12);
|
|
757
769
|
|
|
758
|
-
|
|
759
|
-
|
|
770
|
+
const decryptedArrayBuffer = await crypto.subtle.decrypt(
|
|
771
|
+
{
|
|
772
|
+
name: 'AES-GCM',
|
|
773
|
+
iv,
|
|
774
|
+
},
|
|
775
|
+
derivedKey,
|
|
776
|
+
ciphertext
|
|
777
|
+
);
|
|
778
|
+
|
|
779
|
+
const Decoder = await this.getTextDecoder();
|
|
780
|
+
const decryptedMessage = new Decoder().decode(decryptedArrayBuffer);
|
|
781
|
+
return decryptedMessage
|
|
782
|
+
}
|
|
783
|
+
}
|
|
760
784
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
})
|
|
764
|
-
);
|
|
785
|
+
const getVerificationHelpers = ({ keyPairs, crypto: _crypto, util: _util } = {}) => {
|
|
786
|
+
const webCrypto = new WebCrypto({ crypto: _crypto, util: _util });
|
|
765
787
|
|
|
766
|
-
|
|
767
|
-
async (req, params) => {
|
|
788
|
+
return async (req, params) => {
|
|
768
789
|
const {
|
|
769
790
|
'x-public-key': apiKey,
|
|
770
791
|
'x-ephemeral-key': ephemeralPublicKey,
|
|
@@ -808,7 +829,7 @@
|
|
|
808
829
|
throw new VerificationError('Invalid or missing authorization', { code: 401 })
|
|
809
830
|
}
|
|
810
831
|
|
|
811
|
-
verificationKeys = await
|
|
832
|
+
verificationKeys = await webCrypto.getVerificationKeys({
|
|
812
833
|
publicKey: ephemeralPublicKey,
|
|
813
834
|
privateKey: keyPairs.shared.privateKey,
|
|
814
835
|
});
|
|
@@ -824,7 +845,7 @@
|
|
|
824
845
|
...normalizeURIParts(uri),
|
|
825
846
|
});
|
|
826
847
|
|
|
827
|
-
const isValid = await
|
|
848
|
+
const isValid = await webCrypto.verifyHMAC(
|
|
828
849
|
verificationPayload,
|
|
829
850
|
verificationKeys.derivedHMACKey,
|
|
830
851
|
authSignature
|
|
@@ -835,7 +856,7 @@
|
|
|
835
856
|
}
|
|
836
857
|
|
|
837
858
|
if (!disableRecryption && requestBody) {
|
|
838
|
-
const decryptedMessage = await
|
|
859
|
+
const decryptedMessage = await webCrypto.decryptMessage(requestBody, verificationKeys.derivedSecretKey);
|
|
839
860
|
requestBody = safeParse(decryptedMessage);
|
|
840
861
|
}
|
|
841
862
|
}
|
|
@@ -845,7 +866,7 @@
|
|
|
845
866
|
return response
|
|
846
867
|
}
|
|
847
868
|
|
|
848
|
-
return
|
|
869
|
+
return webCrypto.encryptMessage(JSON.stringify(response), verificationKeys.derivedSecretKey)
|
|
849
870
|
};
|
|
850
871
|
|
|
851
872
|
return { rawBody, requestBody, processResponse }
|
|
@@ -854,7 +875,346 @@
|
|
|
854
875
|
throw error
|
|
855
876
|
}
|
|
856
877
|
}
|
|
857
|
-
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
/*!
|
|
881
|
+
* raw-body
|
|
882
|
+
* Copyright(c) 2013-2014 Jonathan Ong
|
|
883
|
+
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
|
884
|
+
* MIT Licensed
|
|
885
|
+
*/
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Module dependencies.
|
|
889
|
+
* @private
|
|
890
|
+
*/
|
|
891
|
+
|
|
892
|
+
var asyncHooks = tryRequireAsyncHooks();
|
|
893
|
+
var bytes = require('bytes');
|
|
894
|
+
var createError = require('http-errors');
|
|
895
|
+
var iconv = require('iconv-lite');
|
|
896
|
+
var unpipe = require('unpipe');
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Module exports.
|
|
900
|
+
* @public
|
|
901
|
+
*/
|
|
902
|
+
|
|
903
|
+
module.exports = getRawBody;
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Module variables.
|
|
907
|
+
* @private
|
|
908
|
+
*/
|
|
909
|
+
|
|
910
|
+
var ICONV_ENCODING_MESSAGE_REGEXP = /^Encoding not recognized: /;
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Get the decoder for a given encoding.
|
|
914
|
+
*
|
|
915
|
+
* @param {string} encoding
|
|
916
|
+
* @private
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
function getDecoder (encoding) {
|
|
920
|
+
if (!encoding) return null
|
|
921
|
+
|
|
922
|
+
try {
|
|
923
|
+
return iconv.getDecoder(encoding)
|
|
924
|
+
} catch (e) {
|
|
925
|
+
// error getting decoder
|
|
926
|
+
if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e
|
|
927
|
+
|
|
928
|
+
// the encoding was not found
|
|
929
|
+
throw createError(415, 'specified encoding unsupported', {
|
|
930
|
+
encoding: encoding,
|
|
931
|
+
type: 'encoding.unsupported'
|
|
932
|
+
})
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Get the raw body of a stream (typically HTTP).
|
|
938
|
+
*
|
|
939
|
+
* @param {object} stream
|
|
940
|
+
* @param {object|string|function} [options]
|
|
941
|
+
* @param {function} [callback]
|
|
942
|
+
* @public
|
|
943
|
+
*/
|
|
944
|
+
|
|
945
|
+
function getRawBody (stream, options, callback) {
|
|
946
|
+
var done = callback;
|
|
947
|
+
var opts = options || {};
|
|
948
|
+
|
|
949
|
+
// light validation
|
|
950
|
+
if (stream === undefined) {
|
|
951
|
+
throw new TypeError('argument stream is required')
|
|
952
|
+
} else if (typeof stream !== 'object' || stream === null || typeof stream.on !== 'function') {
|
|
953
|
+
throw new TypeError('argument stream must be a stream')
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
if (options === true || typeof options === 'string') {
|
|
957
|
+
// short cut for encoding
|
|
958
|
+
opts = {
|
|
959
|
+
encoding: options
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
if (typeof options === 'function') {
|
|
964
|
+
done = options;
|
|
965
|
+
opts = {};
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// validate callback is a function, if provided
|
|
969
|
+
if (done !== undefined && typeof done !== 'function') {
|
|
970
|
+
throw new TypeError('argument callback must be a function')
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
// require the callback without promises
|
|
974
|
+
if (!done && !global.Promise) {
|
|
975
|
+
throw new TypeError('argument callback is required')
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
// get encoding
|
|
979
|
+
var encoding = opts.encoding !== true
|
|
980
|
+
? opts.encoding
|
|
981
|
+
: 'utf-8';
|
|
982
|
+
|
|
983
|
+
// convert the limit to an integer
|
|
984
|
+
var limit = bytes.parse(opts.limit);
|
|
985
|
+
|
|
986
|
+
// convert the expected length to an integer
|
|
987
|
+
var length = opts.length != null && !isNaN(opts.length)
|
|
988
|
+
? parseInt(opts.length, 10)
|
|
989
|
+
: null;
|
|
990
|
+
|
|
991
|
+
if (done) {
|
|
992
|
+
// classic callback style
|
|
993
|
+
return readStream(stream, encoding, length, limit, wrap(done))
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
return new Promise(function executor (resolve, reject) {
|
|
997
|
+
readStream(stream, encoding, length, limit, function onRead (err, buf) {
|
|
998
|
+
if (err) return reject(err)
|
|
999
|
+
resolve(buf);
|
|
1000
|
+
});
|
|
1001
|
+
})
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
* Halt a stream.
|
|
1006
|
+
*
|
|
1007
|
+
* @param {Object} stream
|
|
1008
|
+
* @private
|
|
1009
|
+
*/
|
|
1010
|
+
|
|
1011
|
+
function halt (stream) {
|
|
1012
|
+
// unpipe everything from the stream
|
|
1013
|
+
unpipe(stream);
|
|
1014
|
+
|
|
1015
|
+
// pause stream
|
|
1016
|
+
if (typeof stream.pause === 'function') {
|
|
1017
|
+
stream.pause();
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* Read the data from the stream.
|
|
1023
|
+
*
|
|
1024
|
+
* @param {object} stream
|
|
1025
|
+
* @param {string} encoding
|
|
1026
|
+
* @param {number} length
|
|
1027
|
+
* @param {number} limit
|
|
1028
|
+
* @param {function} callback
|
|
1029
|
+
* @public
|
|
1030
|
+
*/
|
|
1031
|
+
|
|
1032
|
+
function readStream (stream, encoding, length, limit, callback) {
|
|
1033
|
+
var complete = false;
|
|
1034
|
+
var sync = true;
|
|
1035
|
+
|
|
1036
|
+
// check the length and limit options.
|
|
1037
|
+
// note: we intentionally leave the stream paused,
|
|
1038
|
+
// so users should handle the stream themselves.
|
|
1039
|
+
if (limit !== null && length !== null && length > limit) {
|
|
1040
|
+
return done(createError(413, 'request entity too large', {
|
|
1041
|
+
expected: length,
|
|
1042
|
+
length: length,
|
|
1043
|
+
limit: limit,
|
|
1044
|
+
type: 'entity.too.large'
|
|
1045
|
+
}))
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// streams1: assert request encoding is buffer.
|
|
1049
|
+
// streams2+: assert the stream encoding is buffer.
|
|
1050
|
+
// stream._decoder: streams1
|
|
1051
|
+
// state.encoding: streams2
|
|
1052
|
+
// state.decoder: streams2, specifically < 0.10.6
|
|
1053
|
+
var state = stream._readableState;
|
|
1054
|
+
if (stream._decoder || (state && (state.encoding || state.decoder))) {
|
|
1055
|
+
// developer error
|
|
1056
|
+
return done(createError(500, 'stream encoding should not be set', {
|
|
1057
|
+
type: 'stream.encoding.set'
|
|
1058
|
+
}))
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (typeof stream.readable !== 'undefined' && !stream.readable) {
|
|
1062
|
+
return done(createError(500, 'stream is not readable', {
|
|
1063
|
+
type: 'stream.not.readable'
|
|
1064
|
+
}))
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
var received = 0;
|
|
1068
|
+
var decoder;
|
|
1069
|
+
|
|
1070
|
+
try {
|
|
1071
|
+
decoder = getDecoder(encoding);
|
|
1072
|
+
} catch (err) {
|
|
1073
|
+
return done(err)
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
var buffer = decoder
|
|
1077
|
+
? ''
|
|
1078
|
+
: [];
|
|
1079
|
+
|
|
1080
|
+
// attach listeners
|
|
1081
|
+
stream.on('aborted', onAborted);
|
|
1082
|
+
stream.on('close', cleanup);
|
|
1083
|
+
stream.on('data', onData);
|
|
1084
|
+
stream.on('end', onEnd);
|
|
1085
|
+
stream.on('error', onEnd);
|
|
1086
|
+
|
|
1087
|
+
// mark sync section complete
|
|
1088
|
+
sync = false;
|
|
1089
|
+
|
|
1090
|
+
function done () {
|
|
1091
|
+
var args = new Array(arguments.length);
|
|
1092
|
+
|
|
1093
|
+
// copy arguments
|
|
1094
|
+
for (var i = 0; i < args.length; i++) {
|
|
1095
|
+
args[i] = arguments[i];
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
// mark complete
|
|
1099
|
+
complete = true;
|
|
1100
|
+
|
|
1101
|
+
if (sync) {
|
|
1102
|
+
process.nextTick(invokeCallback);
|
|
1103
|
+
} else {
|
|
1104
|
+
invokeCallback();
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
function invokeCallback () {
|
|
1108
|
+
cleanup();
|
|
1109
|
+
|
|
1110
|
+
if (args[0]) {
|
|
1111
|
+
// halt the stream on error
|
|
1112
|
+
halt(stream);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
callback.apply(null, args);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function onAborted () {
|
|
1120
|
+
if (complete) return
|
|
1121
|
+
|
|
1122
|
+
done(createError(400, 'request aborted', {
|
|
1123
|
+
code: 'ECONNABORTED',
|
|
1124
|
+
expected: length,
|
|
1125
|
+
length: length,
|
|
1126
|
+
received: received,
|
|
1127
|
+
type: 'request.aborted'
|
|
1128
|
+
}));
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function onData (chunk) {
|
|
1132
|
+
if (complete) return
|
|
1133
|
+
|
|
1134
|
+
received += chunk.length;
|
|
1135
|
+
|
|
1136
|
+
if (limit !== null && received > limit) {
|
|
1137
|
+
done(createError(413, 'request entity too large', {
|
|
1138
|
+
limit: limit,
|
|
1139
|
+
received: received,
|
|
1140
|
+
type: 'entity.too.large'
|
|
1141
|
+
}));
|
|
1142
|
+
} else if (decoder) {
|
|
1143
|
+
buffer += decoder.write(chunk);
|
|
1144
|
+
} else {
|
|
1145
|
+
buffer.push(chunk);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
function onEnd (err) {
|
|
1150
|
+
if (complete) return
|
|
1151
|
+
if (err) return done(err)
|
|
1152
|
+
|
|
1153
|
+
if (length !== null && received !== length) {
|
|
1154
|
+
done(createError(400, 'request size did not match content length', {
|
|
1155
|
+
expected: length,
|
|
1156
|
+
length: length,
|
|
1157
|
+
received: received,
|
|
1158
|
+
type: 'request.size.invalid'
|
|
1159
|
+
}));
|
|
1160
|
+
} else {
|
|
1161
|
+
var string = decoder
|
|
1162
|
+
? buffer + (decoder.end() || '')
|
|
1163
|
+
: Buffer.concat(buffer);
|
|
1164
|
+
done(null, string);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function cleanup () {
|
|
1169
|
+
buffer = null;
|
|
1170
|
+
|
|
1171
|
+
stream.removeListener('aborted', onAborted);
|
|
1172
|
+
stream.removeListener('data', onData);
|
|
1173
|
+
stream.removeListener('end', onEnd);
|
|
1174
|
+
stream.removeListener('error', onEnd);
|
|
1175
|
+
stream.removeListener('close', cleanup);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* Try to require async_hooks
|
|
1181
|
+
* @private
|
|
1182
|
+
*/
|
|
1183
|
+
|
|
1184
|
+
function tryRequireAsyncHooks () {
|
|
1185
|
+
try {
|
|
1186
|
+
return require('async_hooks')
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
return {}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Wrap function with async resource, if possible.
|
|
1194
|
+
* AsyncResource.bind static method backported.
|
|
1195
|
+
* @private
|
|
1196
|
+
*/
|
|
1197
|
+
|
|
1198
|
+
function wrap (fn) {
|
|
1199
|
+
var res;
|
|
1200
|
+
|
|
1201
|
+
// create anonymous resource
|
|
1202
|
+
if (asyncHooks.AsyncResource) {
|
|
1203
|
+
res = new asyncHooks.AsyncResource(fn.name || 'bound-anonymous-fn');
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// incompatible node.js
|
|
1207
|
+
if (!res || !res.runInAsyncScope) {
|
|
1208
|
+
return fn
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// return bound function
|
|
1212
|
+
return res.runInAsyncScope.bind(res, fn, null)
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
1216
|
+
__proto__: null
|
|
1217
|
+
});
|
|
858
1218
|
|
|
859
1219
|
exports.API_ROUTE_NAMES = API_ROUTE_NAMES;
|
|
860
1220
|
exports.API_WEBHOOK_TOPICS = API_WEBHOOK_TOPICS;
|
|
@@ -863,10 +1223,12 @@
|
|
|
863
1223
|
exports.BILLING_INTERVALS = BILLING_INTERVALS;
|
|
864
1224
|
exports.COLLECTION_ROOT = COLLECTION_ROOT;
|
|
865
1225
|
exports.PAGE_ROUTE_NAMES = PAGE_ROUTE_NAMES;
|
|
1226
|
+
exports.VerificationError = VerificationError;
|
|
866
1227
|
exports.convertEventTopic = convertEventTopic;
|
|
1228
|
+
exports.ensureRawBody = ensureRawBody;
|
|
867
1229
|
exports.getVerificationHelpers = getVerificationHelpers;
|
|
868
1230
|
|
|
869
1231
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
870
1232
|
|
|
871
1233
|
}));
|
|
872
|
-
//# sourceMappingURL=
|
|
1234
|
+
//# sourceMappingURL=index.js.map
|