diff --git a/package.json b/package.json index 1a91860..ea5b535 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,21 @@ "url": "git+https://github.com/juspay/zephyr-sdk-react.git" }, "main": "dist/index.js", + "files": [ + "dist", + "!dist/**/*.test.*", + "!dist/**/*.spec.*", + "scripts/postinstall.js" + ], + "exports": { + ".": { + "import": "./dist/index.js", + "require": "./dist/index.js" + } + }, "scripts": { "dev": "npx tsc --watch", - "build": "rollup --config rollup.config.js", + "build": "tsc --build", "format:all": "npx prettier --write .", "lint:all": "eslint . --ext .ts" }, @@ -29,7 +41,6 @@ "@commitlint/cli": "^18.4.2", "@commitlint/config-conventional": "^18.4.2", "@digitalroute/cz-conventional-changelog-for-jira": "^8.0.1", - "@rollup/plugin-typescript": "^11.1.6", "@types/react": "^18.2.48", "@typescript-eslint/eslint-plugin": "^6.11.0", "@typescript-eslint/parser": "^6.11.0", @@ -45,9 +56,8 @@ "react": "^18.2.0", "react-native": "^0.73.2", "react-native-webview": "^13.6.4", - "rollup": "^4.9.6", "tslib": "^2.6.2", - "type-decoder": "^1.2.0", + "type-decoder": "^2.0.1", "typescript": "^5.2.2" }, "peerDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2b5dd48..a273847 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,16 +7,13 @@ settings: devDependencies: '@commitlint/cli': specifier: ^18.4.2 - version: 18.6.0(@types/node@20.11.8)(typescript@5.3.3) + version: 18.6.0(@types/node@20.11.9)(typescript@5.3.3) '@commitlint/config-conventional': specifier: ^18.4.2 version: 18.6.0 '@digitalroute/cz-conventional-changelog-for-jira': specifier: ^8.0.1 - version: 8.0.1(@types/node@20.11.8)(typescript@5.3.3) - '@rollup/plugin-typescript': - specifier: ^11.1.6 - version: 11.1.6(rollup@4.9.6)(tslib@2.6.2)(typescript@5.3.3) + version: 8.0.1(@types/node@20.11.9)(typescript@5.3.3) '@types/react': specifier: ^18.2.48 version: 18.2.48 @@ -28,7 +25,7 @@ devDependencies: version: 6.19.1(eslint@8.56.0)(typescript@5.3.3) commitizen: specifier: ^4.3.0 - version: 4.3.0(@types/node@20.11.8)(typescript@5.3.3) + version: 4.3.0(@types/node@20.11.9)(typescript@5.3.3) commitlint-config-jira: specifier: ^1.6.4 version: 1.6.4 @@ -62,15 +59,12 @@ devDependencies: react-native-webview: specifier: ^13.6.4 version: 13.6.4(react-native@0.73.2)(react@18.2.0) - rollup: - specifier: ^4.9.6 - version: 4.9.6 tslib: specifier: ^2.6.2 version: 2.6.2 type-decoder: - specifier: ^1.2.0 - version: 1.2.0 + specifier: ^2.0.1 + version: 2.0.1 typescript: specifier: ^5.2.2 version: 5.3.3 @@ -1913,7 +1907,7 @@ packages: to-fast-properties: 2.0.0 dev: true - /@commitlint/cli@18.6.0(@types/node@20.11.8)(typescript@5.3.3): + /@commitlint/cli@18.6.0(@types/node@20.11.9)(typescript@5.3.3): resolution: { integrity: sha512-FiH23cr9QG8VdfbmvJJZmdfHGVMCouOOAzoXZ3Cd7czGC52RbycwNt8YCI7SA69pAl+t30vh8LMaO/N+kcel6w== @@ -1923,7 +1917,7 @@ packages: dependencies: '@commitlint/format': 18.6.0 '@commitlint/lint': 18.6.0 - '@commitlint/load': 18.6.0(@types/node@20.11.8)(typescript@5.3.3) + '@commitlint/load': 18.6.0(@types/node@20.11.9)(typescript@5.3.3) '@commitlint/read': 18.6.0 '@commitlint/types': 18.6.0 execa: 5.1.1 @@ -2015,7 +2009,7 @@ packages: '@commitlint/types': 18.6.0 dev: true - /@commitlint/load@18.6.0(@types/node@20.11.8)(typescript@5.3.3): + /@commitlint/load@18.6.0(@types/node@20.11.9)(typescript@5.3.3): resolution: { integrity: sha512-RRssj7TmzT0bowoEKlgwg8uQ7ORXWkw7lYLsZZBMi9aInsJuGNLNWcMxJxRZbwxG3jkCidGUg85WmqJvRjsaDA== @@ -2028,7 +2022,7 @@ packages: '@commitlint/types': 18.6.0 chalk: 4.1.2 cosmiconfig: 8.3.6(typescript@5.3.3) - cosmiconfig-typescript-loader: 5.0.0(@types/node@20.11.8)(cosmiconfig@8.3.6)(typescript@5.3.3) + cosmiconfig-typescript-loader: 5.0.0(@types/node@20.11.9)(cosmiconfig@8.3.6)(typescript@5.3.3) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -2128,7 +2122,7 @@ packages: chalk: 4.1.2 dev: true - /@digitalroute/cz-conventional-changelog-for-jira@8.0.1(@types/node@20.11.8)(typescript@5.3.3): + /@digitalroute/cz-conventional-changelog-for-jira@8.0.1(@types/node@20.11.9)(typescript@5.3.3): resolution: { integrity: sha512-I7uNQ2R5LnDYVhQ01sfNvaxqe1PutXyDl8Kltj4L8uDa1LTYqQgWWp3yEj3XYDNjhUjsAheHW0lsmF1oiAjWVg== @@ -2137,15 +2131,15 @@ packages: dependencies: boxen: 5.1.2 chalk: 2.4.2 - commitizen: 4.3.0(@types/node@20.11.8)(typescript@5.3.3) - cz-conventional-changelog: 3.3.0(@types/node@20.11.8)(typescript@5.3.3) + commitizen: 4.3.0(@types/node@20.11.9)(typescript@5.3.3) + cz-conventional-changelog: 3.3.0(@types/node@20.11.9)(typescript@5.3.3) inquirer: 8.2.6 lodash.map: 4.6.0 longest: 2.0.1 right-pad: 1.0.1 word-wrap: 1.2.5 optionalDependencies: - '@commitlint/load': 18.6.0(@types/node@20.11.8)(typescript@5.3.3) + '@commitlint/load': 18.6.0(@types/node@20.11.9)(typescript@5.3.3) transitivePeerDependencies: - '@types/node' - typescript @@ -2272,7 +2266,7 @@ packages: dependencies: '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.8 + '@types/node': 20.11.9 jest-mock: 29.7.0 dev: true @@ -2285,7 +2279,7 @@ packages: dependencies: '@jest/types': 29.6.3 '@sinonjs/fake-timers': 10.3.0 - '@types/node': 20.11.8 + '@types/node': 20.11.9 jest-message-util: 29.7.0 jest-mock: 29.7.0 jest-util: 29.7.0 @@ -2310,7 +2304,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.6 '@types/istanbul-reports': 3.0.4 - '@types/node': 20.11.8 + '@types/node': 20.11.9 '@types/yargs': 15.0.19 chalk: 4.1.2 dev: true @@ -2325,7 +2319,7 @@ packages: '@jest/schemas': 29.6.3 '@types/istanbul-lib-coverage': 2.0.6 '@types/istanbul-reports': 3.0.4 - '@types/node': 20.11.8 + '@types/node': 20.11.9 '@types/yargs': 17.0.32 chalk: 4.1.2 dev: true @@ -2830,190 +2824,6 @@ packages: react-native: 0.73.2(@babel/core@7.23.9)(@babel/preset-env@7.23.9)(react@18.2.0) dev: true - /@rollup/plugin-typescript@11.1.6(rollup@4.9.6)(tslib@2.6.2)(typescript@5.3.3): - resolution: - { - integrity: sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA== - } - engines: { node: '>=14.0.0' } - peerDependencies: - rollup: ^2.14.0||^3.0.0||^4.0.0 - tslib: '*' - typescript: '>=3.7.0' - peerDependenciesMeta: - rollup: - optional: true - tslib: - optional: true - dependencies: - '@rollup/pluginutils': 5.1.0(rollup@4.9.6) - resolve: 1.22.8 - rollup: 4.9.6 - tslib: 2.6.2 - typescript: 5.3.3 - dev: true - - /@rollup/pluginutils@5.1.0(rollup@4.9.6): - resolution: - { - integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g== - } - engines: { node: '>=14.0.0' } - peerDependencies: - rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 - peerDependenciesMeta: - rollup: - optional: true - dependencies: - '@types/estree': 1.0.5 - estree-walker: 2.0.2 - picomatch: 2.3.1 - rollup: 4.9.6 - dev: true - - /@rollup/rollup-android-arm-eabi@4.9.6: - resolution: - { - integrity: sha512-MVNXSSYN6QXOulbHpLMKYi60ppyO13W9my1qogeiAqtjb2yR4LSmfU2+POvDkLzhjYLXz9Rf9+9a3zFHW1Lecg== - } - cpu: [arm] - os: [android] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-android-arm64@4.9.6: - resolution: - { - integrity: sha512-T14aNLpqJ5wzKNf5jEDpv5zgyIqcpn1MlwCrUXLrwoADr2RkWA0vOWP4XxbO9aiO3dvMCQICZdKeDrFl7UMClw== - } - cpu: [arm64] - os: [android] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-darwin-arm64@4.9.6: - resolution: - { - integrity: sha512-CqNNAyhRkTbo8VVZ5R85X73H3R5NX9ONnKbXuHisGWC0qRbTTxnF1U4V9NafzJbgGM0sHZpdO83pLPzq8uOZFw== - } - cpu: [arm64] - os: [darwin] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-darwin-x64@4.9.6: - resolution: - { - integrity: sha512-zRDtdJuRvA1dc9Mp6BWYqAsU5oeLixdfUvkTHuiYOHwqYuQ4YgSmi6+/lPvSsqc/I0Omw3DdICx4Tfacdzmhog== - } - cpu: [x64] - os: [darwin] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-arm-gnueabihf@4.9.6: - resolution: - { - integrity: sha512-oNk8YXDDnNyG4qlNb6is1ojTOGL/tRhbbKeE/YuccItzerEZT68Z9gHrY3ROh7axDc974+zYAPxK5SH0j/G+QQ== - } - cpu: [arm] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-arm64-gnu@4.9.6: - resolution: - { - integrity: sha512-Z3O60yxPtuCYobrtzjo0wlmvDdx2qZfeAWTyfOjEDqd08kthDKexLpV97KfAeUXPosENKd8uyJMRDfFMxcYkDQ== - } - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-arm64-musl@4.9.6: - resolution: - { - integrity: sha512-gpiG0qQJNdYEVad+1iAsGAbgAnZ8j07FapmnIAQgODKcOTjLEWM9sRb+MbQyVsYCnA0Im6M6QIq6ax7liws6eQ== - } - cpu: [arm64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-riscv64-gnu@4.9.6: - resolution: - { - integrity: sha512-+uCOcvVmFUYvVDr27aiyun9WgZk0tXe7ThuzoUTAukZJOwS5MrGbmSlNOhx1j80GdpqbOty05XqSl5w4dQvcOA== - } - cpu: [riscv64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-x64-gnu@4.9.6: - resolution: - { - integrity: sha512-HUNqM32dGzfBKuaDUBqFB7tP6VMN74eLZ33Q9Y1TBqRDn+qDonkAUyKWwF9BR9unV7QUzffLnz9GrnKvMqC/fw== - } - cpu: [x64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-linux-x64-musl@4.9.6: - resolution: - { - integrity: sha512-ch7M+9Tr5R4FK40FHQk8VnML0Szi2KRujUgHXd/HjuH9ifH72GUmw6lStZBo3c3GB82vHa0ZoUfjfcM7JiiMrQ== - } - cpu: [x64] - os: [linux] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-win32-arm64-msvc@4.9.6: - resolution: - { - integrity: sha512-VD6qnR99dhmTQ1mJhIzXsRcTBvTjbfbGGwKAHcu+52cVl15AC/kplkhxzW/uT0Xl62Y/meBKDZvoJSJN+vTeGA== - } - cpu: [arm64] - os: [win32] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-win32-ia32-msvc@4.9.6: - resolution: - { - integrity: sha512-J9AFDq/xiRI58eR2NIDfyVmTYGyIZmRcvcAoJ48oDld/NTR8wyiPUu2X/v1navJ+N/FGg68LEbX3Ejd6l8B7MQ== - } - cpu: [ia32] - os: [win32] - requiresBuild: true - dev: true - optional: true - - /@rollup/rollup-win32-x64-msvc@4.9.6: - resolution: - { - integrity: sha512-jqzNLhNDvIZOrt69Ce4UjGRpXJBzhUBzawMwnaDAwyHriki3XollsewxWzOzz+4yOFDkuJHtTsZFwMxhYJWmLQ== - } - cpu: [x64] - os: [win32] - requiresBuild: true - dev: true - optional: true - /@sideway/address@4.1.4: resolution: { @@ -3062,13 +2872,6 @@ packages: '@sinonjs/commons': 3.0.1 dev: true - /@types/estree@1.0.5: - resolution: - { - integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== - } - dev: true - /@types/istanbul-lib-coverage@2.0.6: resolution: { @@ -3115,10 +2918,10 @@ packages: } dev: true - /@types/node@20.11.8: + /@types/node@20.11.9: resolution: { - integrity: sha512-i7omyekpPTNdv4Jb/Rgqg0RU8YqLcNsI12quKSDkRXNfx7Wxdm6HhK1awT3xTgEkgxPn3bvnSpiEAc7a7Lpyow== + integrity: sha512-CQXNuMoS/VcoAMISe5pm4JnEd1Br5jildbQEToEMQvutmv+EaQr90ry9raiudgpyDuqFiV9e4rnjSfLNq12M5w== } dependencies: undici-types: 5.26.5 @@ -3846,7 +3649,7 @@ packages: engines: { node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7 } hasBin: true dependencies: - caniuse-lite: 1.0.30001580 + caniuse-lite: 1.0.30001581 electron-to-chromium: 1.4.648 node-releases: 2.0.14 update-browserslist-db: 1.0.13(browserslist@4.22.3) @@ -3986,10 +3789,10 @@ packages: engines: { node: '>=10' } dev: true - /caniuse-lite@1.0.30001580: + /caniuse-lite@1.0.30001581: resolution: { - integrity: sha512-mtj5ur2FFPZcCEpXFy8ADXbDACuNFXg6mxVDqp7tqooX6l3zwm+d8EPoeOSIFRDvHs8qu7/SLFOGniULkcH2iA== + integrity: sha512-whlTkwhqV2tUmP3oYhtNfaWGYHDdS3JYFQBKXxcUR9qqPWsRhFHhoISO2Xnl/g0xyKzht9mI1LZpiNWfMzHixQ== } dev: true @@ -4031,7 +3834,7 @@ packages: engines: { node: '>=12.13.0' } hasBin: true dependencies: - '@types/node': 20.11.8 + '@types/node': 20.11.9 escape-string-regexp: 4.0.0 is-wsl: 2.2.0 lighthouse-logger: 1.4.2 @@ -4045,7 +3848,7 @@ packages: integrity: sha512-pgtgjNKZ7i5U++1g1PWv75umkHvhVTDOQIZ+sjeUX9483S7Y6MUvO0lrd7ShGlQlFHMN4SwKTCq/X8hWrbv2KA== } dependencies: - '@types/node': 20.11.8 + '@types/node': 20.11.9 escape-string-regexp: 4.0.0 is-wsl: 2.2.0 lighthouse-logger: 1.4.2 @@ -4209,7 +4012,7 @@ packages: engines: { node: ^12.20.0 || >=14 } dev: true - /commitizen@4.3.0(@types/node@20.11.8)(typescript@5.3.3): + /commitizen@4.3.0(@types/node@20.11.9)(typescript@5.3.3): resolution: { integrity: sha512-H0iNtClNEhT0fotHvGV3E9tDejDeS04sN1veIebsKYGMuGscFaswRoYJKmT3eW85eIJAs0F28bG2+a/9wCOfPw== @@ -4218,7 +4021,7 @@ packages: hasBin: true dependencies: cachedir: 2.3.0 - cz-conventional-changelog: 3.3.0(@types/node@20.11.8)(typescript@5.3.3) + cz-conventional-changelog: 3.3.0(@types/node@20.11.9)(typescript@5.3.3) dedent: 0.7.0 detect-indent: 6.1.0 find-node-modules: 2.1.3 @@ -4397,7 +4200,7 @@ packages: } dev: true - /cosmiconfig-typescript-loader@5.0.0(@types/node@20.11.8)(cosmiconfig@8.3.6)(typescript@5.3.3): + /cosmiconfig-typescript-loader@5.0.0(@types/node@20.11.9)(cosmiconfig@8.3.6)(typescript@5.3.3): resolution: { integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA== @@ -4408,7 +4211,7 @@ packages: cosmiconfig: '>=8.2' typescript: '>=4' dependencies: - '@types/node': 20.11.8 + '@types/node': 20.11.9 cosmiconfig: 8.3.6(typescript@5.3.3) jiti: 1.21.0 typescript: 5.3.3 @@ -4465,7 +4268,7 @@ packages: } dev: true - /cz-conventional-changelog@3.3.0(@types/node@20.11.8)(typescript@5.3.3): + /cz-conventional-changelog@3.3.0(@types/node@20.11.9)(typescript@5.3.3): resolution: { integrity: sha512-U466fIzU5U22eES5lTNiNbZ+d8dfcHcssH4o7QsdWaCcRs/feIPCxKYSWkYBNs5mny7MvEfwpTLWjvbm94hecw== @@ -4473,13 +4276,13 @@ packages: engines: { node: '>= 10' } dependencies: chalk: 2.4.2 - commitizen: 4.3.0(@types/node@20.11.8)(typescript@5.3.3) + commitizen: 4.3.0(@types/node@20.11.9)(typescript@5.3.3) conventional-commit-types: 3.0.0 lodash.map: 4.6.0 longest: 2.0.1 word-wrap: 1.2.5 optionalDependencies: - '@commitlint/load': 18.6.0(@types/node@20.11.8)(typescript@5.3.3) + '@commitlint/load': 18.6.0(@types/node@20.11.9)(typescript@5.3.3) transitivePeerDependencies: - '@types/node' - typescript @@ -5213,13 +5016,6 @@ packages: engines: { node: '>=4.0' } dev: true - /estree-walker@2.0.2: - resolution: - { - integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== - } - dev: true - /esutils@2.0.3: resolution: { @@ -6522,7 +6318,7 @@ packages: '@jest/environment': 29.7.0 '@jest/fake-timers': 29.7.0 '@jest/types': 29.6.3 - '@types/node': 20.11.8 + '@types/node': 20.11.9 jest-mock: 29.7.0 jest-util: 29.7.0 dev: true @@ -6561,7 +6357,7 @@ packages: engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } dependencies: '@jest/types': 29.6.3 - '@types/node': 20.11.8 + '@types/node': 20.11.9 jest-util: 29.7.0 dev: true @@ -6573,7 +6369,7 @@ packages: engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } dependencies: '@jest/types': 29.6.3 - '@types/node': 20.11.8 + '@types/node': 20.11.9 chalk: 4.1.2 ci-info: 3.9.0 graceful-fs: 4.2.11 @@ -6602,7 +6398,7 @@ packages: } engines: { node: ^14.15.0 || ^16.10.0 || >=18.0.0 } dependencies: - '@types/node': 20.11.8 + '@types/node': 20.11.9 jest-util: 29.7.0 merge-stream: 2.0.0 supports-color: 8.1.1 @@ -8711,32 +8507,6 @@ packages: glob: 7.2.3 dev: true - /rollup@4.9.6: - resolution: - { - integrity: sha512-05lzkCS2uASX0CiLFybYfVkwNbKZG5NFQ6Go0VWyogFTXXbR039UVsegViTntkk4OglHBdF54ccApXRRuXRbsg== - } - engines: { node: '>=18.0.0', npm: '>=8.0.0' } - hasBin: true - dependencies: - '@types/estree': 1.0.5 - optionalDependencies: - '@rollup/rollup-android-arm-eabi': 4.9.6 - '@rollup/rollup-android-arm64': 4.9.6 - '@rollup/rollup-darwin-arm64': 4.9.6 - '@rollup/rollup-darwin-x64': 4.9.6 - '@rollup/rollup-linux-arm-gnueabihf': 4.9.6 - '@rollup/rollup-linux-arm64-gnu': 4.9.6 - '@rollup/rollup-linux-arm64-musl': 4.9.6 - '@rollup/rollup-linux-riscv64-gnu': 4.9.6 - '@rollup/rollup-linux-x64-gnu': 4.9.6 - '@rollup/rollup-linux-x64-musl': 4.9.6 - '@rollup/rollup-win32-arm64-msvc': 4.9.6 - '@rollup/rollup-win32-ia32-msvc': 4.9.6 - '@rollup/rollup-win32-x64-msvc': 4.9.6 - fsevents: 2.3.3 - dev: true - /run-async@2.4.1: resolution: { @@ -9514,10 +9284,10 @@ packages: prelude-ls: 1.2.1 dev: true - /type-decoder@1.2.0: + /type-decoder@2.0.1: resolution: { - integrity: sha512-hBeqgSqL0ZOruOZVh7kIoP6+aRSdQaYf07ZE5lNTv9GWiJGLqoOT0U1oIpJCcM5xDERV6x/AAmOTv80AuXW3yg== + integrity: sha512-Z0sjr8RZAUSPh7+C5PSFKnRgxN4Qn1GOMUJZTF8Z1BZNULBk+UhagcryuGfAVf5RPKvu4MATAplwPD9feitknw== } dev: true diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index a8b5be2..0000000 --- a/rollup.config.js +++ /dev/null @@ -1,17 +0,0 @@ -import typescript from '@rollup/plugin-typescript'; - -export default [ - { - input: 'src/index.ts', - output: { - file: 'dist/index.js', - format: 'esm', - sourcemap: false - }, - plugins: [ - typescript({ - tsconfig: './tsconfig.json' - }) - ] - } -]; diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index c04739a..0000000 --- a/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** - * @description Place holder - */ diff --git a/src/index.tsx b/src/index.tsx new file mode 100644 index 0000000..b8c70ee --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,150 @@ +import React, { forwardRef, useImperativeHandle } from 'react'; +import WebView, { type WebViewMessageEvent } from 'react-native-webview'; +import { safeParseJSON } from './utils'; +import { isJSON } from 'type-decoder'; +import type { ZephyrProps, ZephyrRef, ZephyrViewStyle } from './types'; +import { Dimensions, Linking } from 'react-native'; + +export const Zephyr = forwardRef((props: ZephyrProps, ref) => { + let checkoutWebView: WebView | null; + let isWebViewReady: boolean = false; + let consumingBackPress: boolean = false; + let pendingMessages: string[] = []; + const appEndpoint: URL = new URL( + props.configuration.environment === 'beta' + ? 'https://app.beta.breeze.in' + : 'https://app.breeze.in' + ); + appEndpoint.searchParams.append('iplat', 'ReactNative'); + appEndpoint.searchParams.append('merchantId', props.configuration.merchantId); + + const windowDimensions = Dimensions.get('window'); + const webViewStyle: ZephyrViewStyle = props.style ?? { + height: windowDimensions.height, + width: windowDimensions.width + }; + + const sendMessageToWebView = (message: string) => { + if (isWebViewReady && checkoutWebView !== null) { + checkoutWebView.postMessage(message); + } else { + pendingMessages.push(message); + } + }; + + const setPlatformData = { + eventName: 'set-platform-store-data', + shopUrl: props.configuration.shopUrl, + platform: props.configuration.shopPlatform, + offerCode: null, + checkoutHidden: false, + shopDomain: null + }; + + const setCartDataPayload = { + eventName: 'set-cart-data', + cart: props.checkoutPayload.cart + }; + + const startCheckoutPayload = { + eventName: 'start-checkout' + }; + + sendMessageToWebView(JSON.stringify(setPlatformData)); + sendMessageToWebView(JSON.stringify(setCartDataPayload)); + sendMessageToWebView(JSON.stringify(startCheckoutPayload)); + + const handleWebViewMessage = async (event: WebViewMessageEvent) => { + const parsedEventData = safeParseJSON(event.nativeEvent.data); + if (isJSON(parsedEventData)) { + const eventData = parsedEventData; + const parsedEventPayload = safeParseJSON(eventData.payload); + if (eventData === null) { + return; + } + if (eventData.source === 'breeze') { + if (eventData.message === 'app-ready') { + isWebViewReady = true; + flushPendingMessages(); + } + if (eventData.message === 'consuming-back-press' && parsedEventPayload !== null) { + consumingBackPress = + typeof parsedEventPayload.consuming === 'boolean' + ? parsedEventPayload.consuming + : false; + } + if (eventData.message === 'checkout-complete') { + const orderId = + typeof parsedEventPayload?.orderId === 'string' ? parsedEventPayload?.orderId : ''; + const checkoutId = + typeof parsedEventPayload?.checkoutId === 'string' + ? parsedEventPayload?.checkoutId + : ''; + const platformOrderId = + typeof parsedEventPayload?.platformOrderId === 'string' + ? parsedEventPayload?.platformOrderId + : ''; + props.callbacks.onComplete({ + zephyrOrderId: orderId, + zephyrCheckoutId: checkoutId, + platformOrderId + }); + } + if (eventData.message === 'close-app') { + props.callbacks.onClose(); + } + + if (eventData.message === 'hide-loader') { + props.callbacks.onEvent({ eventName: 'hide-loader' }); + } + + if (eventData.message === 'error') { + props.callbacks.onError({ error: 'error' }); + } + + if (eventData.message === 'open-app') { + const intentUrl = parsedEventPayload?.url; + if (typeof intentUrl === 'string') { + const isIntentSupported = await Linking.canOpenURL(intentUrl); + if (isIntentSupported) { + await Linking.openURL(intentUrl); + } + } + } + } + } + }; + + const flushPendingMessages = (): void => { + pendingMessages.forEach((msg) => { + sendMessageToWebView(msg); + }); + pendingMessages = []; + }; + + useImperativeHandle(ref, () => ({ + handleBackPress: () => { + if (consumingBackPress) { + checkoutWebView?.goBack(); + return false; + } + return true; + } + })); + + return ( + + (checkoutWebView = webViewRef)} + onMessage={handleWebViewMessage} + originWhitelist={['*']} + sharedCookiesEnabled={true} + domStorageEnabled={true} + source={{ uri: appEndpoint.href }} + style={webViewStyle} + /> + + ); +}); + +export * from './types'; diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..a305b10 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,291 @@ +/** + * @description Zephyr Configuration + * @description Basic configuration required for starting 1 Click Checkout + * @typedef {Object} ZephyrConfiguration + * @property {string} merchantId - Zephyr Merchant ID + * @property {string} shopUrl - Shop URL + * @property {string} shopPlatform - Shop Platform + * @property {string} environment - Zephyr Environment + * @example + * { + * merchantId: 'zephyr-merchant-id', + * shopUrl: 'https://shop-url.com', + * shopPlatform: 'shopify', + * environment: 'production' + * } + */ +export type ZephyrConfiguration = { + merchantId: string; + shopUrl: string; + shopPlatform: 'shopify'; + environment: ZephyrEnvironment; +}; + +/** + * @description Zephyr Environment + * @description Environment for running starting checkout. Always use `production` for production environment. + */ +export type ZephyrEnvironment = 'beta' | 'production'; + +/** + * @description Zephyr Event + * @description Event emitted by Zephyr SDK during the checkout journey + * @typedef {Object} ZephyrEvent + * @property {string} eventName - Name of the event + * @property {Object} [eventData] - Event data + * @example + * { + * eventName: 'hide-loader', + * } + */ +export type ZephyrEvent = { + eventName: string; + eventData?: Record; +}; + +/** + * @description Zephyr On Event Callback + * @description Callback for handling events emitted by Zephyr SDK + * @typedef {function} ZephyrOnEventCallback + * @param {ZephyrEvent} event - Event emitted by Zephyr SDK + * @example + * (event) => { + * console.log(event); + * } + */ +export type ZephyrOnEventCallback = (event: ZephyrEvent) => void; + +/** + * @description Zephyr Checkout Success Event + * @description Event emitted by Zephyr SDK when checkout is successful + * @typedef {Object} ZephyrCheckoutSuccessEvent + * @property {string} zephyrOrderId - Zephyr Order ID + * @property {string} zephyrCheckoutId - Zephyr Checkout ID + * @property {string} platformOrderId - Platform Order ID + * @example + * { + * zephyrOrderId: 'zephyr-order-id', + * zephyrCheckoutId: 'zephyr-checkout-id', + * platformOrderId: 'platform-order-id' + * } + */ +export type ZephyrCheckoutSuccessEvent = { + zephyrOrderId: string; + zephyrCheckoutId: string; + platformOrderId: string; +}; + +/** + * @description Zephyr On Success Callback + * @description Callback for handling successful checkout + * @typedef {function} ZephyrOnSuccessCallback + * @param {ZephyrCheckoutSuccessEvent} event - Event emitted by Zephyr SDK + * @example + * (event) => { + * console.log(event); + * } + */ +export type ZephyrOnSuccessCallback = (event: ZephyrCheckoutSuccessEvent) => void; + +/** + * @description Zephyr On Close Callback + * @description Callback for handling close of Zephyr Checkout + * @typedef {function} ZephyrOnCloseCallback + * @example + * () => { + * console.log('Zephyr Checkout closed'); + * } + */ +export type ZephyrOnCloseCallback = () => void; + +/** + * @description Zephyr On Error Event + * @description Event emitted by Zephyr SDK when error occurs during checkout + * @typedef {Object} ZephyrOnErrorEvent + * @property {string} error - Error code + * @property {string} [message] - Error message + * @example + * { + * error: 'error-code', + * message: 'error-message' + * } + */ +export type ZephyrOnErrorEvent = { + error: string; + message?: string; +}; + +/** + * @description Zephyr On Error Callback + * @description Callback for handling errors during checkout + * @typedef {function} ZephyrOnErrorCallback + * @param {Object} event - Event emitted by Zephyr SDK + * @param {string} event.error - Error code + * @param {string} [event.message] - Error message + * @example + * (event) => { + * console.log(event); + * } + */ +export type ZephyrOnErrorCallback = (event: ZephyrOnErrorEvent) => void; + +/** + * @description Zephyr Callbacks + * @description Callbacks for handling events emitted by Zephyr SDK + * @typedef {Object} ZephyrCallbacks + * @property {function} onEvent - Callback for handling events emitted by Zephyr SDK + * @property {function} onComplete - Callback for handling successful checkout + * @property {function} onError - Callback for handling errors during checkout + * @property {function} onClose - Callback for handling close of Zephyr Checkout + * @example + * { + * onEvent: (event) => { + * console.log(event); + * }, + * onComplete: (event) => { + * console.log(event); + * }, + * onError: (event) => { + * console.log(event); + * }, + * onClose: () => { + * console.log('Zephyr Checkout closed'); + * } + * } + */ +export type ZephyrCallbacks = { + onEvent: ZephyrOnEventCallback; + onComplete: ZephyrOnSuccessCallback; + onError: ZephyrOnErrorCallback; + onClose: ZephyrOnCloseCallback; +}; + +/** + * @description Zephyr View Style + * @description Style for Zephyr Checkout View + * @typedef {Object} ZephyrViewStyle + * @property {number} height - Height of Zephyr Checkout View + * @property {number} width - Width of Zephyr Checkout View + * @example + * { + * height: 500, + * width: 500 + * } + * @example + * { + * height: Dimensions.get('window').height, + * width: Dimensions.get('window').width + * } + * @example + * { + * height: '100%', + * width: '100%' + * } + */ +export type ZephyrViewStyle = { + height: number; + width: number; +}; + +/** + * @description Zephyr Start Checkout Payload + * @description Payload for starting Zephyr Checkout + * @description Cart object must be obtained from the platform + * @typedef {Object} ZephyrStartCheckoutPayload + * @property {Object} cart - Cart object + * @example + * { + * cart: { + * items: [ + * { + * id: 'item-id', + * name: 'item-name', + * price: 100, + * quantity: 1, + * imageUrl: 'https://item-image-url.com', + * url: 'https://item-url.com' + * } + * ], + * currency: 'INR', + * total: 100 + * } + * } + */ +export type ZephyrStartCheckoutPayload = { + cart: Record; +}; + +/** + * @description Zephyr Props + * @description Props for Zephyr Checkout View + * @typedef {Object} ZephyrProps + * @property {ZephyrStartCheckoutPayload} checkoutPayload - Payload for starting Zephyr Checkout + * @property {ZephyrConfiguration} configuration - Configuration for starting Zephyr Checkout + * @property {ZephyrCallbacks} callbacks - Callbacks for handling events emitted by Zephyr SDK + * @property {ZephyrViewStyle} [style] - Style for Zephyr Checkout View + * @example + * { + * checkoutPayload: { + * cart: { + * items: [ + * { + * id: 'item-id', + * name: 'item-name', + * price: 100, + * quantity: 1, + * imageUrl: 'https://item-image-url.com', + * url: 'https://item-url.com' + * } + * ], + * currency: 'INR', + * total: 100 + * } + * }, + * configuration: { + * merchantId: 'zephyr-merchant-id', + * shopUrl: 'https://shop-url.com', + * shopPlatform: 'shopify', + * environment: 'production' + * }, + * callbacks: { + * onEvent: (event) => { + * console.log(event); + * }, + * onComplete: (event) => { + * console.log(event); + * }, + * onError: (event) => { + * console.log(event); + * }, + * onClose: () => { + * console.log('Zephyr Checkout closed'); + * } + * }, + * style: { + * height: 500, + * width: 500 + * } + * } + */ +export type ZephyrProps = { + checkoutPayload: ZephyrStartCheckoutPayload; + configuration: ZephyrConfiguration; + callbacks: ZephyrCallbacks; + style?: ZephyrViewStyle; +}; + +/** + * @description Zephyr Ref + * @description Ref for Zephyr Checkout View + * @typedef {Object} ZephyrRef + * @property {function} handleBackPress - Function for handling back press on Zephyr Checkout View, returns true if you are supposed to handle the backPress + * @example + * { + * handleBackPress: () => { + * console.log('Back pressed'); + * } + * } + */ +export type ZephyrRef = { + handleBackPress: () => boolean; +}; diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..93e93c0 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,10 @@ +export function safeParseJSON(rawData: unknown): Record | null { + try { + if (typeof rawData === 'string') { + return JSON.parse(rawData); + } + } catch (error) { + console.error('Failed to parse JSON: ', error); + } + return null; +} diff --git a/tsconfig.json b/tsconfig.json index 2d0e7fd..0bf9508 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "jsx": "react-native", /* Language and Environment */ "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,