diff --git a/.github/workflows/action_deploy-prod.yml b/.github/workflows/action_deploy-prod.yml index e29fb61a70..f92ab8a003 100644 --- a/.github/workflows/action_deploy-prod.yml +++ b/.github/workflows/action_deploy-prod.yml @@ -102,7 +102,7 @@ jobs: - name: Deploy to npm run: | npm publish --workspace packages/interfaces - npm publish --workspace packages/client + cd packages/client/lib && npm publish roll-firestore: runs-on: ubuntu-latest diff --git a/.github/workflows/action_deploy-wen.yml b/.github/workflows/action_deploy-wen.yml index c1e460dc8e..291db98700 100644 --- a/.github/workflows/action_deploy-wen.yml +++ b/.github/workflows/action_deploy-wen.yml @@ -63,7 +63,7 @@ jobs: - name: Deploy to npm as "upcoming" package run: | npm publish --workspace packages/interfaces --tag next - npm publish --workspace packages/client --tag next + cd packages/client/lib && npm publish --tag next deploy_functions: runs-on: ubuntu-latest environment: staging diff --git a/package-lock.json b/package-lock.json index 99f69f48a5..8c8b21e61b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -186,21 +186,21 @@ } }, "node_modules/@babel/core": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.5.tgz", - "integrity": "sha512-Cwc2XjUrG4ilcfOw4wBAK+enbdgwAcAJCfGUItPBKR7Mjw4aEfAFYrLxeRp4jWgtNIKn3n2AlBOfwwafl+42/g==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.6.tgz", + "integrity": "sha512-FxpRyGjrMJXh7X3wGLGhNDCRiwpWEF74sKjTLDJSG5Kyvow3QZaG0Adbqzi9ZrVjTWpsX+2cxWXD71NMg93kdw==", "dev": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.23.5", - "@babel/generator": "^7.23.5", - "@babel/helper-compilation-targets": "^7.22.15", + "@babel/generator": "^7.23.6", + "@babel/helper-compilation-targets": "^7.23.6", "@babel/helper-module-transforms": "^7.23.3", - "@babel/helpers": "^7.23.5", - "@babel/parser": "^7.23.5", + "@babel/helpers": "^7.23.6", + "@babel/parser": "^7.23.6", "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.5", - "@babel/types": "^7.23.5", + "@babel/traverse": "^7.23.6", + "@babel/types": "^7.23.6", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -216,12 +216,12 @@ } }, "node_modules/@babel/generator": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.5.tgz", - "integrity": "sha512-BPssCHrBD+0YrxviOa3QzpqwhNIXKEtOa2jQrm4FlmkC2apYgRnQcmPWiGZDlGxiNtltnUFolMe8497Esry+jA==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", + "integrity": "sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==", "dev": true, "dependencies": { - "@babel/types": "^7.23.5", + "@babel/types": "^7.23.6", "@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" @@ -243,14 +243,14 @@ } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.15.tgz", - "integrity": "sha512-y6EEzULok0Qvz8yyLkCvVX+02ic+By2UdOhylwUOvOn9dvYc9mKICJuuU1n1XBI02YWsNsnrY1kc6DVbjcXbtw==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", + "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", "dev": true, "dependencies": { - "@babel/compat-data": "^7.22.9", - "@babel/helper-validator-option": "^7.22.15", - "browserslist": "^4.21.9", + "@babel/compat-data": "^7.23.5", + "@babel/helper-validator-option": "^7.23.5", + "browserslist": "^4.22.2", "lru-cache": "^5.1.1", "semver": "^6.3.1" }, @@ -259,9 +259,9 @@ } }, "node_modules/@babel/helper-create-class-features-plugin": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.23.5.tgz", - "integrity": "sha512-QELlRWxSpgdwdJzSJn4WAhKC+hvw/AtHbbrIoncKHkhKKR/luAlKkgBDcri1EzWAo8f8VvYVryEHN4tax/V67A==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.23.6.tgz", + "integrity": "sha512-cBXU1vZni/CpGF29iTu4YRbOZt3Wat6zCoMDxRF1MayiEc4URxOj31tT65HUM0CRpMowA3HCJaAOVOUnMf96cw==", "dev": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.22.5", @@ -459,14 +459,14 @@ } }, "node_modules/@babel/helpers": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.5.tgz", - "integrity": "sha512-oO7us8FzTEsG3U6ag9MfdF1iA/7Z6dz+MtFhifZk8C8o453rGJFFWUP1t+ULM9TUIAzC9uxXEiXjOiVMyd7QPg==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.6.tgz", + "integrity": "sha512-wCfsbN4nBidDRhpDhvcKlzHWCTlgJYUUdSJfzXb2NuBssDSIjc3xcb+znA7l+zYsFljAcGM0aFkN40cR3lXiGA==", "dev": true, "dependencies": { "@babel/template": "^7.22.15", - "@babel/traverse": "^7.23.5", - "@babel/types": "^7.23.5" + "@babel/traverse": "^7.23.6", + "@babel/types": "^7.23.6" }, "engines": { "node": ">=6.9.0" @@ -486,9 +486,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.5.tgz", - "integrity": "sha512-hOOqoiNXrmGdFbhgCzu6GiURxUgM27Xwd/aPuu8RfHEZPBzL1Z54okAHAQjXfcQNwvrlkAmAp4SlRTZ45vlthQ==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.6.tgz", + "integrity": "sha512-Z2uID7YJ7oNvAI20O9X0bblw7Qqs8Q2hFy0R9tAfnfLkp5MW0UH9eUvnDSnFwKZ0AvgS1ucqR4KzvVHgnke1VQ==", "devOptional": true, "bin": { "parser": "bin/babel-parser.js" @@ -692,13 +692,13 @@ } }, "node_modules/@babel/plugin-transform-typescript": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.23.5.tgz", - "integrity": "sha512-2fMkXEJkrmwgu2Bsv1Saxgj30IXZdJ+84lQcKKI7sm719oXs0BBw2ZENKdJdR1PjWndgLCEBNXJOri0fk7RYQA==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.23.6.tgz", + "integrity": "sha512-6cBG5mBvUu4VUD04OHKnYzbuHNP8huDsD3EDqqpIpsswTDoqHCjLoHb6+QgsV1WsT2nipRqCPgxD3LXnEO7XfA==", "dev": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-create-class-features-plugin": "^7.23.5", + "@babel/helper-create-class-features-plugin": "^7.23.6", "@babel/helper-plugin-utils": "^7.22.5", "@babel/plugin-syntax-typescript": "^7.23.3" }, @@ -743,20 +743,20 @@ } }, "node_modules/@babel/traverse": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.5.tgz", - "integrity": "sha512-czx7Xy5a6sapWWRx61m1Ke1Ra4vczu1mCTtJam5zRTBOonfdJ+S/B6HYmGYu3fJtr8GGET3si6IhgWVBhJ/m8w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.6.tgz", + "integrity": "sha512-czastdK1e8YByZqezMPFiZ8ahwVMh/ESl9vPgvgdB9AmFMGP5jfpFax74AQgl5zj4XHzqeYAg2l8PuUeRS1MgQ==", "dev": true, "dependencies": { "@babel/code-frame": "^7.23.5", - "@babel/generator": "^7.23.5", + "@babel/generator": "^7.23.6", "@babel/helper-environment-visitor": "^7.22.20", "@babel/helper-function-name": "^7.23.0", "@babel/helper-hoist-variables": "^7.22.5", "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.23.5", - "@babel/types": "^7.23.5", - "debug": "^4.1.0", + "@babel/parser": "^7.23.6", + "@babel/types": "^7.23.6", + "debug": "^4.3.1", "globals": "^11.1.0" }, "engines": { @@ -764,9 +764,9 @@ } }, "node_modules/@babel/types": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.5.tgz", - "integrity": "sha512-ON5kSOJwVO6xXVRTvOI0eOnWe7VdUcIpsovGo9U/Br4Ie4UVFQTboO2cYnDhAGU6Fp+UxSiT+pMft0SMHfuq6w==", + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.6.tgz", + "integrity": "sha512-+uarb83brBzPKN38NX1MkB6vb6+mwvR6amUulqAE7ccQw1pEl+bCia9TbdG1lsnFP7lZySvUn37CHyXQdfTwzg==", "dev": true, "dependencies": { "@babel/helper-string-parser": "^7.23.4", @@ -926,9 +926,9 @@ "dev": true }, "node_modules/@eslint/eslintrc/node_modules/globals": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", - "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -1419,6 +1419,15 @@ "node": ">=12" } }, + "node_modules/@google-cloud/storage/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "optional": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@grpc/grpc-js": { "version": "1.8.21", "resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.8.21.tgz", @@ -2466,9 +2475,9 @@ } }, "node_modules/@libp2p/interface": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@libp2p/interface/-/interface-1.0.1.tgz", - "integrity": "sha512-TRo1YxJ+AVjt5ms+mTOp8xcoCis5HAUMzv0XfCvxtIw77Bog6TPR5VdkGutlEQOKUMzXtLP0lW88fTQBeiiOnA==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@libp2p/interface/-/interface-1.0.2.tgz", + "integrity": "sha512-z/3Yyg+7cVyzRXwzdrDkJd7YmNaLE9iZjQaixo5luI/n9uk5OFFjb9ulAsNqpq8V1xylCo2DXIC7f94KClwzVw==", "dependencies": { "@multiformats/multiaddr": "^12.1.10", "it-pushable": "^3.2.1", @@ -4700,9 +4709,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001566", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001566.tgz", - "integrity": "sha512-ggIhCsTxmITBAMmK8yZjEhCO5/47jKXPu6Dha/wuCS4JePVL+3uiDEBuhu2aIoT+bqTOR8L76Ip1ARL9xYsEJA==", + "version": "1.0.30001568", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001568.tgz", + "integrity": "sha512-vSUkH84HontZJ88MiNrOau1EBrCqEQYgkC5gIySiDlpsm8sGVrhU7Kx4V6h0tnqaHzIHZv08HlJIwPbL4XL9+A==", "dev": true, "funding": [ { @@ -4876,6 +4885,14 @@ "node": ">=16 <=20" } }, + "node_modules/cloudevents/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -5649,9 +5666,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.607", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.607.tgz", - "integrity": "sha512-YUlnPwE6eYxzwBnFmawA8LiLRfm70R2aJRIUv0n03uHt/cUzzYACOogmvk8M2+hVzt/kB80KJXx7d5f5JofPvQ==", + "version": "1.4.610", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.610.tgz", + "integrity": "sha512-mqi2oL1mfeHYtOdCxbPQYV/PL7YrQlxbvFEZ0Ee8GbDdShimqt2/S6z2RWqysuvlwdOrQdqvE0KZrBTipAeJzg==", "dev": true }, "node_modules/emittery": { @@ -6401,9 +6418,9 @@ } }, "node_modules/eslint/node_modules/globals": { - "version": "13.23.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.23.0.tgz", - "integrity": "sha512-XAmF0RjlrjY23MA51q3HltdlGxUpXPvg0GioKiD9X6HD28iMjo2dKC8Vqwm7lne4GNr78+RHTfliktR6ZH09wA==", + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { "type-fest": "^0.20.2" @@ -7062,18 +7079,6 @@ "@google-cloud/storage": "^6.9.5" } }, - "node_modules/firebase-admin/node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/firebase-functions": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.5.0.tgz", @@ -9810,6 +9815,15 @@ "node": ">=10.12.0" } }, + "node_modules/jest-junit/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/jest-leak-detector": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-29.7.0.tgz", @@ -13209,9 +13223,9 @@ } }, "node_modules/reflect-metadata": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + "version": "0.1.14", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.14.tgz", + "integrity": "sha512-ZhYeb6nRaXCfhnndflDK8qI6ZQ/YcWZCISRAWICW9XYqMUwjZM9Z0DveWX/ABN01oxSHwVxKQmxeYZSsm0jh5A==" }, "node_modules/regexp.prototype.flags": { "version": "1.5.1", @@ -13966,9 +13980,9 @@ } }, "node_modules/streamx": { - "version": "2.15.5", - "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.5.tgz", - "integrity": "sha512-9thPGMkKC2GctCzyCUjME3yR03x2xNo0GPKGkRw2UMYN+gqWa9uqpyNWhmsNCutU5zHmkUum0LsCRQTXUgUCAg==", + "version": "2.15.6", + "resolved": "https://registry.npmjs.org/streamx/-/streamx-2.15.6.tgz", + "integrity": "sha512-q+vQL4AAz+FdfT137VF69Cc/APqUbxy+MDOImRrMvchJpigHj9GksgDU2LYbO9rx7RX6osWgxJB2WxhYv4SZAw==", "dependencies": { "fast-fifo": "^1.1.0", "queue-tick": "^1.0.1" @@ -14242,19 +14256,6 @@ "node": ">=12" } }, - "node_modules/teeny-request/node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "optional": true, - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -14908,9 +14909,13 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -15365,7 +15370,6 @@ "version": "0.0.0", "dependencies": { "@build-5/interfaces": "*", - "@iota/sdk": "1.1.4", "axios": "^1.6.2", "bip39": "3.1.0", "form-data": "^4.0.0", @@ -15399,18 +15403,6 @@ "typescript": "5.2.2" } }, - "packages/client/node_modules/uuid": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", - "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "bin": { - "uuid": "dist/bin/uuid" - } - }, "packages/database": { "name": "@build-5/database", "version": "0.0.0", diff --git a/packages/client/package.json b/packages/client/package.json index 057f860461..c82b6fead5 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -9,11 +9,11 @@ "serve": "run-p \"run:search\" \"run:functions\"", "lint": "eslint --ext .js,.ts src", "build": "tsc", + "postbuild": "cp package.json ./lib", "test": "jest" }, "dependencies": { "@build-5/interfaces": "*", - "@iota/sdk": "1.1.4", "axios": "^1.6.2", "bip39": "3.1.0", "form-data": "^4.0.0", diff --git a/packages/client/src/https/datasets/TransactionDataset.ts b/packages/client/src/https/datasets/TransactionDataset.ts index 8b5e954287..6c95d2ea08 100644 --- a/packages/client/src/https/datasets/TransactionDataset.ts +++ b/packages/client/src/https/datasets/TransactionDataset.ts @@ -11,7 +11,7 @@ import { TransactionType, WEN_FUNC, } from '@build-5/interfaces'; -import { toQueryParams, wrappedFetch } from '../fetch.utils'; +import { toQueryParams } from '../fetch.utils'; import { fetchLive } from '../get/observable'; import { DatasetClass } from './Dataset'; @@ -156,17 +156,14 @@ export class TransactionDataset extends DatasetClass(this.apiKey, url); }; - getBySourceTransaction = async (sourceTransaction: string) => { + getBySourceTransactionLive = (sourceTransaction: string) => { const params: GetManyAdvancedRequest = { dataset: this.dataset, - fieldName: ['payload.sourceTransaction'], - fieldValue: [sourceTransaction], - operator: [Opr.ARRAY_CONTAINS], + fieldName: ['payload.sourceTransaction', 'payload.walletReference.confirmed'], + fieldValue: [sourceTransaction, true], + operator: [Opr.ARRAY_CONTAINS, Opr.EQUAL], }; - return await wrappedFetch( - this.apiKey, - this.origin + ApiRoutes.GET_MANY_ADVANCED, - { ...params }, - ); + const url = this.origin + ApiRoutes.GET_MANY_ADVANCED + toQueryParams({ ...params }); + return fetchLive(this.apiKey, url); }; } diff --git a/packages/client/src/https/https.ts b/packages/client/src/https/https.ts index 0a662267a1..2c32e85dac 100644 --- a/packages/client/src/https/https.ts +++ b/packages/client/src/https/https.ts @@ -24,6 +24,7 @@ import { AirdropDataset } from './datasets/token/AirdropDataset'; import { TokenDataset } from './datasets/token/TokenDataset'; import { TokenMarketDataset } from './datasets/token/TokenMarketDataset'; import { TokenPurchaseDataset } from './datasets/token/TokenPurchaseDataset'; +import { Observable } from './tag.tracker'; export class ProjectWrapper { constructor( @@ -84,6 +85,8 @@ export class ProjectWrapper { } } + trackByTag = (tag: string) => new Observable(this.origin, tag); + uploadFile = async (pathToFile: string, member: string, uid: string) => { const isLocal = !Object.values(Build5).includes(this.origin); const url = this.origin + `/${isLocal ? 'https-' : ''}` + WEN_FUNC.uploadFile; diff --git a/packages/client/src/https/tag.tracker.ts b/packages/client/src/https/tag.tracker.ts new file mode 100644 index 0000000000..485a465c3d --- /dev/null +++ b/packages/client/src/https/tag.tracker.ts @@ -0,0 +1,78 @@ +import { Dataset, TangleResponse, Transaction, TransactionType } from '@build-5/interfaces'; +import { Observable as RxjsObservable, Subscriber, Subscription } from 'rxjs'; +import { API_KEY, Build5, https } from '../https'; +import { TransactionDataset } from '../https/datasets/TransactionDataset'; + +export interface TagTrackResult extends TangleResponse { + chainReference?: string; +} + +export class Observable extends RxjsObservable { + private observer: Subscriber | undefined; + private dataset: TransactionDataset | undefined; + private transactionIds: string[] = []; + private subs: { [key: string]: Subscription } = {}; + + constructor(origin: Build5, tag: string) { + super((observer) => { + this.observer = observer; + + this.dataset = https(origin).project(API_KEY[origin]).dataset(Dataset.TRANSACTION); + this.observer.next({ status: 'waiting for payment' }); + + this.subs['payment'] = this.dataset + .getPaymentByTagLive(tag.startsWith('0x') ? tag : toHex(tag)) + .subscribe(async (payments) => { + payments.sort((a, b) => a.createdOn?.seconds! - b.createdOn?.seconds!); + for (const payment of payments) { + if (!this.transactionIds.includes(payment.uid)) { + this.transactionIds.push(payment.uid); + this.observer?.next({ + status: 'payment received', + chainReference: payment.payload.chainReference || '', + }); + this.getResponseForPayment(payment); + } + } + }); + + return this.closeConnection; + }); + } + + private getResponseForPayment = (payment: Transaction) => { + const obs = this.dataset!.getBySourceTransactionLive(payment.uid); + this.subs[payment.uid] = obs.subscribe((transactions) => { + for (const tran of transactions) { + if (!this.transactionIds.includes(tran.uid)) { + this.transactionIds.push(tran.uid); + + if (tran.type === TransactionType.CREDIT_TANGLE_REQUEST) { + this.observer?.next({ + ...tran.payload.response, + chainReference: tran.payload.walletReference?.chainReference || '', + }); + return; + } + + if (tran.type === TransactionType.UNLOCK) { + this.observer?.next({ status: 'Success' }); + return; + } + } + } + }); + }; + + private closeConnection = () => { + Object.values(this.subs).forEach((subs) => subs.unsubscribe()); + this.observer?.complete(); + }; +} + +const toHex = (stringToConvert: string) => + '0x' + + stringToConvert + .split('') + .map((c) => c.charCodeAt(0).toString(16).padStart(2, '0')) + .join(''); diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 5ef290b6a7..e7735f3045 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -1,3 +1,2 @@ export { https } from './https'; export { otr } from './otr'; -export { createWallet } from './wallet'; diff --git a/packages/client/src/otr/datasets/common.ts b/packages/client/src/otr/datasets/common.ts index cac0ff4dc0..3fd66d37d3 100644 --- a/packages/client/src/otr/datasets/common.ts +++ b/packages/client/src/otr/datasets/common.ts @@ -1,4 +1,4 @@ -import { Dataset, MIN_IOTA_AMOUNT, Network } from '@build-5/interfaces'; +import { Dataset, Network } from '@build-5/interfaces'; import { v4 as uuid } from 'uuid'; import { MemberOtrDataset } from './MemberOtrDataset'; import { ProposalOtrDataset } from './ProposalOtrDataset'; @@ -32,25 +32,22 @@ export class OtrRequest { public readonly nativeToken?: INativeToken, ) {} - getMetadata = () => { - const data = { - targetAddress: this.otrAddress, - amount: this.amount, - metadata: { request: this.metadata }, - nativeToken: this.nativeToken, - tag: this.generateTag(), - }; - return { ...data, amount: Math.max(MIN_IOTA_AMOUNT / 2, this.amount || 0) }; - }; + getMetadata = () => ({ + targetAddress: this.otrAddress, + metadata: { request: this.metadata }, + nativeToken: this.nativeToken, + tag: this.generateTag(), + amount: this.amount, + }); getFireflyDeepLink = () => { - const { amount, metadata, nativeToken, tag } = this.getMetadata(); + const { metadata, nativeToken, tag } = this.getMetadata(); const walletType = getFireflyWalletType(this.otrAddress); return ( walletType + `://wallet/sendConfirmation?address=${this.otrAddress}` + '&disableToggleGift=true&disableChangeExpiration=true' + - `&amount=${nativeToken ? nativeToken.amount : amount}` + + `&amount=${nativeToken ? nativeToken.amount : this.amount || 0}` + `&tag=${tag}&giftStorageDeposit=true` + `&metadata=${JSON.stringify(metadata)}` + (nativeToken ? `&assetId=${nativeToken?.id}` : '') @@ -58,11 +55,10 @@ export class OtrRequest { }; getBloomDeepLink = () => { - const { amount, metadata, nativeToken, tag } = this.getMetadata(); - + const { metadata, nativeToken, tag, amount } = this.getMetadata(); const parameters = { address: this.otrAddress, - baseCoinAmount: Number(amount).toFixed(0), + baseCoinAmount: Number(amount || 0).toFixed(0), tokenId: nativeToken?.id, tokenAmount: nativeToken ? Number(nativeToken.amount).toFixed(0) : undefined, tag, @@ -103,3 +99,12 @@ const getFireflyWalletType = (otrAddress: string) => { } throw Error('Invalid otr address, ono firefly wallet type found'); }; + +export const otrAddressToNetwork = (address: string): Network => { + for (const network of Object.values(Network)) { + if (address.startsWith(network)) { + return network as Network; + } + } + throw Error('Invalid otr address'); +}; diff --git a/packages/client/src/otr/otr.ts b/packages/client/src/otr/otr.ts index 525209d685..1b20461316 100644 --- a/packages/client/src/otr/otr.ts +++ b/packages/client/src/otr/otr.ts @@ -1,13 +1,4 @@ -import { - Dataset, - Network, - TangleResponse, - Transaction, - TransactionType, -} from '@build-5/interfaces'; -import { Observable as RxjsObservable, Subscriber, Subscription } from 'rxjs'; -import { API_KEY, Build5, https } from '../https'; -import { TransactionDataset } from '../https/datasets/TransactionDataset'; +import { Dataset } from '@build-5/interfaces'; import { AuctionOtrDataset } from './datasets/AuctionOtrDataset'; import { AwardOtrDataset } from './datasets/AwardOtrDataset'; import { MemberOtrDataset } from './datasets/MemberOtrDataset'; @@ -40,70 +31,4 @@ export class OtrWrapper { throw Error('invalid dataset name'); } } - - trackByTag = (tag: string) => { - const origin = this.otrAddress.startsWith(Network.SMR) ? Build5.PROD : Build5.TEST; - return new Observable(origin, tag); - }; -} - -class Observable extends RxjsObservable { - private observer: Subscriber | undefined; - private paymentsSubs: Subscription | undefined; - private payments: string[] = []; - private dataset: TransactionDataset | undefined; - - constructor(origin: Build5, tag: string) { - super((observer) => { - this.observer = observer; - - this.dataset = https(origin).project(API_KEY[origin]).dataset(Dataset.TRANSACTION); - this.observer.next({ status: 'waiting for payment' }); - - this.paymentsSubs = this.dataset - .getPaymentByTagLive(tag.startsWith('0x') ? tag : toHex(tag)) - .subscribe(async (payments) => { - payments.sort((a, b) => a.createdOn?.seconds! - b.createdOn?.seconds!); - for (const payment of payments) { - await this.getResponseForPayment(payment); - } - }); - - return this.closeConnection; - }); - } - - private getResponseForPayment = async (payment: Transaction) => { - if (this.payments.includes(payment.uid)) { - return; - } - this.payments.push(payment.uid); - - for (let i = 0; i < 10; ++i) { - const result = await this.dataset!.getBySourceTransaction(payment.uid); - const credit = result.find((t) => t.type === TransactionType.CREDIT_TANGLE_REQUEST); - if (credit) { - this.observer?.next(credit.payload.response); - return; - } - const transfer = result.find((t) => t.type === TransactionType.UNLOCK); - if (transfer) { - this.observer?.next({ status: 'success' }); - return; - } - await new Promise((resolve) => setTimeout(resolve, 1000)); - } - }; - - private closeConnection = () => { - this.paymentsSubs?.unsubscribe(); - this.observer?.complete(); - }; } - -const toHex = (stringToConvert: string) => - '0x' + - stringToConvert - .split('') - .map((c) => c.charCodeAt(0).toString(16).padStart(2, '0')) - .join(''); diff --git a/packages/client/src/wallet/client.ts b/packages/client/src/wallet/client.ts deleted file mode 100644 index 6accb4bee3..0000000000 --- a/packages/client/src/wallet/client.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Network } from '@build-5/interfaces'; -import { Client, SecretManager } from '@iota/sdk'; -import { mnemonicToSeedSync } from 'bip39'; - -export const getClient = async (address: string, customNodeUrl = '') => { - const nodeUrl = customNodeUrl || getNodeUrl(address); - const client = new Client({ nodes: [nodeUrl] }); - const info = await client.getInfo(); - if (info.nodeInfo.status.isHealthy) { - return { client, info: info.nodeInfo, nodeUrl }; - } - throw Error(`Could not connect to client: ${nodeUrl}`); -}; - -export const getSecretManager = (mnemonic: string) => { - const seed = mnemonicToSeedSync(mnemonic); - const hexSeed = '0x' + seed.toString('hex'); - return new SecretManager({ hexSeed }); -}; - -const NODE_URLS: { [key: string]: string } = { - [Network.IOTA]: 'https://iota.soonaverse.org', - [Network.SMR]: 'https://smr.soonaverse.org', -}; - -const getNodeUrl = (address: string) => { - if (address.startsWith(Network.SMR)) { - return NODE_URLS[Network.SMR]; - } - if (address.startsWith(Network.RMS)) { - // TODO - get rms node url - return 'https://rms1.svrs.io/'; - } - if (address.startsWith('iota')) { - return NODE_URLS[Network.IOTA]; - } - throw Error('Invalid otr address. Node url not found'); -}; diff --git a/packages/client/src/wallet/common.ts b/packages/client/src/wallet/common.ts deleted file mode 100644 index 6cddfd85e3..0000000000 --- a/packages/client/src/wallet/common.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { INativeToken } from '@iota/sdk'; - -export interface AddressDetails { - bech32: string; - hex: string; - mnemonic: string; -} - -export interface WalletPrams { - targetAddress: string; - amount?: number; - nativeTokens?: INativeToken; - metadata: Record; - tag: string; -} diff --git a/packages/client/src/wallet/index.ts b/packages/client/src/wallet/index.ts deleted file mode 100644 index e22622f3db..0000000000 --- a/packages/client/src/wallet/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { getClient } from './client'; -import { Wallet } from './wallet'; - -export const createWallet = async (mnemonic: string, otrAddress: string, customNodeUrl = '') => { - const { client, info } = await getClient(otrAddress, customNodeUrl); - return new Wallet(mnemonic, client, info); -}; diff --git a/packages/client/src/wallet/output.ts b/packages/client/src/wallet/output.ts deleted file mode 100644 index 03837736c3..0000000000 --- a/packages/client/src/wallet/output.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - AddressUnlockCondition, - BasicOutputBuilderParams, - Client, - MetadataFeature, - TagFeature, - Utils, - utf8ToHex, -} from '@iota/sdk'; -import bigInt from 'big-integer'; -import { WalletPrams } from './common'; - -export const packBasicOutput = async ( - client: Client, - { targetAddress, nativeTokens, amount, metadata, tag }: WalletPrams, -) => { - const params: BasicOutputBuilderParams = { - unlockConditions: [new AddressUnlockCondition(Utils.parseBech32Address(targetAddress))], - features: [ - new TagFeature(utf8ToHex(tag)), - new MetadataFeature(utf8ToHex(JSON.stringify(metadata))), - ], - }; - - if (nativeTokens) { - params.nativeTokens = [nativeTokens]; - } - - const output = await client.buildBasicOutput(params); - const rent = (await client.getInfo()).nodeInfo.protocol.rentStructure; - const storageDeposit = Utils.computeStorageDeposit(output, rent); - params.amount = bigInt.max(bigInt(amount || 0), storageDeposit).toString(); - - return await client.buildBasicOutput(params); -}; diff --git a/packages/client/src/wallet/wallet.ts b/packages/client/src/wallet/wallet.ts deleted file mode 100644 index 0e1e8ed9de..0000000000 --- a/packages/client/src/wallet/wallet.ts +++ /dev/null @@ -1,141 +0,0 @@ -import { - BasicOutput, - BasicOutputBuilderParams, - Client, - CoinType, - INativeToken, - INodeInfo, - ReferenceUnlock, - RegularTransactionEssence, - TaggedDataPayload, - TransactionEssence, - TransactionPayload, - UTXOInput, - UnlockConditionType, - Utils, - utf8ToHex, -} from '@iota/sdk'; -import { isEmpty } from 'lodash'; -import { OtrRequest } from '../otr/datasets/common'; -import { getSecretManager } from './client'; -import { AddressDetails } from './common'; -import { packBasicOutput } from './output'; - -export class Wallet { - constructor( - private readonly mnemonic: string, - private readonly client: Client, - private readonly info: INodeInfo, - ) {} - - public send = async (request: OtrRequest): Promise => { - const params = { - targetAddress: request.otrAddress, - metadata: { request: request.metadata }, - amount: request.amount, - nativeTokens: request.nativeToken, - tag: request.generateTag(), - }; - const sourceAddress = await this.getAddressDetails(this.info, this.mnemonic); - - const output = await packBasicOutput(this.client, params); - - const consumedOutputs = await this.getOutputs(this.client, sourceAddress.bech32); - - const remainder = createRemainder( - Object.values(consumedOutputs), - output.amount, - params.nativeTokens, - ); - - const outputs: BasicOutput[] = [output]; - if (!isEmpty(remainder.nativeTokens) || Number(remainder.amount) > 0) { - outputs.push(await this.client.buildBasicOutput(remainder)); - } - - const inputs = Object.keys(consumedOutputs).map(UTXOInput.fromOutputId); - const inputsCommitment = Utils.computeInputsCommitment(Object.values(consumedOutputs)); - - const essence = new RegularTransactionEssence( - await this.client.getNetworkId(), - inputsCommitment, - inputs, - outputs, - new TaggedDataPayload(utf8ToHex(params.tag), ''), - ); - - const fromUnlock = await createUnlock(essence, sourceAddress); - const unlocks = Object.values(consumedOutputs).map((_, i) => - i ? new ReferenceUnlock(0) : fromUnlock, - ); - - return (await this.client.postBlockPayload(new TransactionPayload(essence, unlocks)))[0]; - }; - - private getAddressDetails = async ( - info: INodeInfo, - mnemonic: string, - ): Promise => { - const secretManager = getSecretManager(mnemonic); - const addresses = await secretManager.generateEd25519Addresses({ - coinType: CoinType.IOTA, - range: { start: 0, end: 1 }, - bech32Hrp: info.protocol.bech32Hrp, - }); - - const hex = Utils.bech32ToHex(addresses[0]); - return { mnemonic, hex, bech32: addresses[0] }; - }; - - private getOutputs = async ( - client: Client, - addressBech32: string, - ): Promise<{ [key: string]: BasicOutput }> => { - const query = [ - { address: addressBech32 }, - { hasStorageDepositReturn: false }, - { hasTimelock: false }, - ]; - const outputIds = (await client.basicOutputIds(query)).items; - const outputs = await client.getOutputs(outputIds); - return outputs.reduce( - (acc, act, i) => ({ ...acc, [outputIds[i]]: act.output as BasicOutput }), - {}, - ); - }; -} - -const createRemainder = (outputs: BasicOutput[], amount: string, nativeToken?: INativeToken) => { - const addressUnlock = outputs[0].unlockConditions.find( - (u) => u.type === UnlockConditionType.Address, - )!; - - const remainder: BasicOutputBuilderParams = { - amount: -BigInt(amount), - unlockConditions: [addressUnlock], - nativeTokens: nativeToken ? [{ amount: -nativeToken.amount, id: nativeToken.id }] : [], - }; - - for (const output of outputs) { - const nativeTokens = remainder.nativeTokens || []; - for (const nativeToken of output.nativeTokens || []) { - const index = nativeTokens.findIndex((n) => n.id === nativeToken.id); - if (index === -1) { - nativeTokens.push(nativeToken); - } else { - nativeTokens[index].amount = - BigInt(nativeTokens[index].amount) + BigInt(nativeToken.amount); - } - } - remainder.amount = BigInt(output.amount) + BigInt(remainder.amount!); - remainder.nativeTokens = nativeTokens; - } - - return remainder; -}; - -const createUnlock = async (essence: TransactionEssence, address: AddressDetails) => { - const essenceHash = Utils.hashTransactionEssence(essence); - const secretManager = getSecretManager(address.mnemonic); - return await secretManager.signatureUnlock(essenceHash, { coinType: CoinType.IOTA }); -}; diff --git a/packages/client/test/otr/otr.spec.ts b/packages/client/test/otr/otr.spec.ts index df79d6dee1..4d6c7f66e4 100644 --- a/packages/client/test/otr/otr.spec.ts +++ b/packages/client/test/otr/otr.spec.ts @@ -1,9 +1,10 @@ import { Dataset } from '@build-5/interfaces'; import * as build5 from '../../src'; +import { API_KEY, Build5 } from '../../src/https'; import { Build5OtrAddress } from '../../src/otr'; describe('', () => { - it.skip('Deep link test', async () => { + it('Deep link test', async () => { const otrAddress = Build5OtrAddress.TEST; const request = build5.otr(otrAddress).dataset(Dataset.MEMBER).validateAddress(); @@ -14,7 +15,7 @@ describe('', () => { const tag = request.getTag(deeplink); console.log(tag); - const obs = build5.otr(otrAddress).trackByTag(tag); + const obs = build5.https(Build5.TEST).project(API_KEY[Build5.TEST]).trackByTag(tag); const subs = obs.subscribe((n) => console.log(n)); await new Promise((resolve) => setTimeout(resolve, 200000)); diff --git a/packages/search/src/getManyById.ts b/packages/search/src/getManyById.ts index f3441dca74..ae4f31306b 100644 --- a/packages/search/src/getManyById.ts +++ b/packages/search/src/getManyById.ts @@ -16,7 +16,7 @@ const getManyByIdSchema = Joi.object({ dataset: Joi.string() .equal(...Object.values(Dataset)) .required(), - setIds: Joi.array().items(CommonJoi.uid(false, 7)).max(QUERY_MAX_LENGTH).required(), + setIds: Joi.array().items(CommonJoi.uid(false, 5)).max(QUERY_MAX_LENGTH).required(), subset: Joi.string() .equal(...Object.values(Subset)) .optional(),