diff --git a/.github/ci.yml b/.github/workflows/ci.yml similarity index 79% rename from .github/ci.yml rename to .github/workflows/ci.yml index c63c17a..a629ae2 100644 --- a/.github/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Node.js Snippets Continuous Integration on: [push] jobs: - lint: + build: runs-on: ubuntu-latest steps: @@ -18,6 +18,10 @@ jobs: - name: Install dependencies run: npm install + - name: Install snippets dependencies + working-directory: ./snippets + run: npm install + - name: Run TypeScript compiler run: tsc diff --git a/eslint.config.mjs b/eslint.config.mjs index 14dd77d..62fac1e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -55,6 +55,5 @@ export default [...compat.extends('eslint:recommended', 'google', 'prettier'), { ignorePattern: '^import.+|test', }], - 'new-cap': 'off' }, }]; diff --git a/package-lock.json b/package-lock.json index 9700e24..acea583 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,615 +20,9 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-prettier": "^5.2.1", "globals": "^15.9.0", - "jest": "^29.5.0", "typescript": "^5.6.2" } }, - "node_modules/@ampproject/remapping": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", - "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", - "dev": true, - "dependencies": { - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.24" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@babel/code-frame": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", - "integrity": "sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==", - "dev": true, - "dependencies": { - "@babel/highlight": "^7.24.7", - "picocolors": "^1.0.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/compat-data": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.25.4.tgz", - "integrity": "sha512-+LGRog6RAsCJrrrg/IO6LGmpphNe5DiK30dGjCoxxeGv49B10/3XYGxPsAwrDlMFcFEvdAUavDT8r9k/hSyQqQ==", - "dev": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/core": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.25.2.tgz", - "integrity": "sha512-BBt3opiCOxUr9euZ5/ro/Xv8/V7yJ5bjYMqG/C1YAo8MIKAnumZalCN+msbci3Pigy4lIQfPUpfMM27HMGaYEA==", - "dev": true, - "dependencies": { - "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.25.0", - "@babel/helper-compilation-targets": "^7.25.2", - "@babel/helper-module-transforms": "^7.25.2", - "@babel/helpers": "^7.25.0", - "@babel/parser": "^7.25.0", - "@babel/template": "^7.25.0", - "@babel/traverse": "^7.25.2", - "@babel/types": "^7.25.2", - "convert-source-map": "^2.0.0", - "debug": "^4.1.0", - "gensync": "^1.0.0-beta.2", - "json5": "^2.2.3", - "semver": "^6.3.1" - }, - "engines": { - "node": ">=6.9.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/babel" - } - }, - "node_modules/@babel/core/node_modules/semver": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", - "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "dev": true, - "bin": { - "semver": "bin/semver.js" - } - }, - "node_modules/@babel/generator": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.25.6.tgz", - "integrity": "sha512-VPC82gr1seXOpkjAAKoLhP50vx4vGNlF4msF64dSFq1P8RfB+QAuJWGHPXXPc8QyfVWwwB/TNNU4+ayZmHNbZw==", - "dev": true, - "dependencies": { - "@babel/types": "^7.25.6", - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.25", - "jsesc": "^2.5.1" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-compilation-targets": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.2.tgz", - "integrity": "sha512-U2U5LsSaZ7TAt3cfaymQ8WHh0pxvdHoEk6HVpaexxixjyEquMh0L0YNJNM6CTGKMXV1iksi0iZkGw4AcFkPaaw==", - "dev": true, - "dependencies": { - "@babel/compat-data": "^7.25.2", - "@babel/helper-validator-option": "^7.24.8", - "browserslist": "^4.23.1", - "lru-cache": "^5.1.1", - "semver": "^6.3.1" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-compilation-targets/node_modules/semver": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", - "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", - "dev": true, - "bin": { - "semver": "bin/semver.js" - } - }, - "node_modules/@babel/helper-module-imports": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.7.tgz", - "integrity": "sha512-8AyH3C+74cgCVVXow/myrynrAGv+nTVg5vKu2nZph9x7RcRwzmh0VFallJuFTZ9mx6u4eSdXZfcOzSqTUm0HCA==", - "dev": true, - "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-module-transforms": { - "version": "7.25.2", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.25.2.tgz", - "integrity": "sha512-BjyRAbix6j/wv83ftcVJmBt72QtHI56C7JXZoG2xATiLpmoC7dpd8WnkikExHDVPpi/3qCmO6WY1EaXOluiecQ==", - "dev": true, - "dependencies": { - "@babel/helper-module-imports": "^7.24.7", - "@babel/helper-simple-access": "^7.24.7", - "@babel/helper-validator-identifier": "^7.24.7", - "@babel/traverse": "^7.25.2" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0" - } - }, - "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.8.tgz", - "integrity": "sha512-FFWx5142D8h2Mgr/iPVGH5G7w6jDn4jUSpZTyDnQO0Yn7Ks2Kuz6Pci8H6MPCoUJegd/UZQ3tAvfLCxQSnWWwg==", - "dev": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-simple-access": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.24.7.tgz", - "integrity": "sha512-zBAIvbCMh5Ts+b86r/CjU+4XGYIs+R1j951gxI3KmmxBMhCg4oQMsv6ZXQ64XOm/cvzfU1FmoCyt6+owc5QMYg==", - "dev": true, - "dependencies": { - "@babel/traverse": "^7.24.7", - "@babel/types": "^7.24.7" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-string-parser": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.8.tgz", - "integrity": "sha512-pO9KhhRcuUyGnJWwyEgnRJTSIZHiT+vMD0kPeD+so0l7mxkMT19g3pjY9GTnHySck/hDzq+dtW/4VgnMkippsQ==", - "dev": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-validator-identifier": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.24.7.tgz", - "integrity": "sha512-rR+PBcQ1SMQDDyF6X0wxtG8QyLCgUB0eRAGguqRLfkCA87l7yAP7ehq8SNj96OOGTO8OBV70KhuFYcIkHXOg0w==", - "dev": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-validator-option": { - "version": "7.24.8", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.24.8.tgz", - "integrity": "sha512-xb8t9tD1MHLungh/AIoWYN+gVHaB9kwlu8gffXGSt3FFEIT7RjS+xWbc2vUD1UTZdIpKj/ab3rdqJ7ufngyi2Q==", - "dev": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helpers": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.25.6.tgz", - "integrity": "sha512-Xg0tn4HcfTijTwfDwYlvVCl43V6h4KyVVX2aEm4qdO/PC6L2YvzLHFdmxhoeSA3eslcE6+ZVXHgWwopXYLNq4Q==", - "dev": true, - "dependencies": { - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.6" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/highlight": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.7.tgz", - "integrity": "sha512-EStJpq4OuY8xYfhGVXngigBJRWxftKX9ksiGDnmlY3o7B/V7KIAc9X4oiK87uPJSc/vs5L869bem5fhZa8caZw==", - "dev": true, - "dependencies": { - "@babel/helper-validator-identifier": "^7.24.7", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/highlight/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/@babel/highlight/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", - "dev": true - }, - "node_modules/@babel/highlight/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "dev": true, - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/@babel/highlight/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/parser": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.6.tgz", - "integrity": "sha512-trGdfBdbD0l1ZPmcJ83eNxB9rbEax4ALFTF7fN386TMYbeCQbyme5cOEXQhbGXKebwGaB/J52w1mrklMcbgy6Q==", - "dev": true, - "dependencies": { - "@babel/types": "^7.25.6" - }, - "bin": { - "parser": "bin/babel-parser.js" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/@babel/plugin-syntax-async-generators": { - "version": "7.8.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.8.4.tgz", - "integrity": "sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-bigint": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-bigint/-/plugin-syntax-bigint-7.8.3.tgz", - "integrity": "sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-class-properties": { - "version": "7.12.13", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.13.tgz", - "integrity": "sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.12.13" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-class-static-block": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-static-block/-/plugin-syntax-class-static-block-7.14.5.tgz", - "integrity": "sha512-b+YyPmr6ldyNnM6sqYeMWE+bgJcJpO6yS4QD7ymxgH34GBPNDM/THBh8iunyvKIZztiwLH4CJZ0RxTk9emgpjw==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.14.5" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-import-attributes": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.25.6.tgz", - "integrity": "sha512-sXaDXaJN9SNLymBdlWFA+bjzBhFD617ZaFiY13dGt7TVslVvVgA6fkZOP7Ki3IGElC45lwHdOTrCtKZGVAWeLQ==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.24.8" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-import-meta": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.10.4.tgz", - "integrity": "sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.10.4" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-json-strings": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", - "integrity": "sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.7.tgz", - "integrity": "sha512-6ddciUPe/mpMnOKv/U+RSd2vvVy+Yw/JfBB0ZHYjEZt9NLHmCUylNYlsbqCCS1Bffjlb0fCwC9Vqz+sBz6PsiQ==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.24.7" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-logical-assignment-operators": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz", - "integrity": "sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.10.4" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-nullish-coalescing-operator": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz", - "integrity": "sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-numeric-separator": { - "version": "7.10.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz", - "integrity": "sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.10.4" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-object-rest-spread": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.8.3.tgz", - "integrity": "sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-optional-catch-binding": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.8.3.tgz", - "integrity": "sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-optional-chaining": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.8.3.tgz", - "integrity": "sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-private-property-in-object": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-private-property-in-object/-/plugin-syntax-private-property-in-object-7.14.5.tgz", - "integrity": "sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.14.5" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-top-level-await": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.14.5.tgz", - "integrity": "sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.14.5" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.25.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.4.tgz", - "integrity": "sha512-uMOCoHVU52BsSWxPOMVv5qKRdeSlPuImUCB2dlPuBSU+W2/ROE7/Zg8F2Kepbk+8yBa68LlRKxO+xgEVWorsDg==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.24.8" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/template": { - "version": "7.25.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.0.tgz", - "integrity": "sha512-aOOgh1/5XzKvg1jvVz7AVrx2piJ2XBi227DHmbY6y+bM9H2FlN+IfecYu4Xl0cNiiVejlsCri89LUsbj8vJD9Q==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/parser": "^7.25.0", - "@babel/types": "^7.25.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/traverse": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.6.tgz", - "integrity": "sha512-9Vrcx5ZW6UwK5tvqsj0nGpp/XzqthkT0dqIc9g1AdtygFToNtTF67XzYS//dm+SAK9cp3B9R4ZO/46p63SCjlQ==", - "dev": true, - "dependencies": { - "@babel/code-frame": "^7.24.7", - "@babel/generator": "^7.25.6", - "@babel/parser": "^7.25.6", - "@babel/template": "^7.25.0", - "@babel/types": "^7.25.6", - "debug": "^4.3.1", - "globals": "^11.1.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/traverse/node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/types": { - "version": "7.25.6", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.6.tgz", - "integrity": "sha512-/l42B1qxpG6RdfYf343Uw1vmDjeNhneUXtzhojE7pDgfpEypmRhI6j1kr17XCVv4Cgl9HdAiQY2x0GwKm7rWCw==", - "dev": true, - "dependencies": { - "@babel/helper-string-parser": "^7.24.8", - "@babel/helper-validator-identifier": "^7.24.7", - "to-fast-properties": "^2.0.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@bcoe/v8-coverage": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz", - "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", - "dev": true - }, - "node_modules/@es-joy/jsdoccomment": { - "version": "0.48.0", - "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.48.0.tgz", - "integrity": "sha512-G6QUWIcC+KvSwXNsJyDTHvqUdNoAVJPPgkc3+Uk4WBKqZvoXhlvazOgm9aL0HwihJLQf0l+tOE2UFzXBqCqgDw==", - "dev": true, - "dependencies": { - "comment-parser": "1.4.1", - "esquery": "^1.6.0", - "jsdoc-type-pratt-parser": "~4.1.0" - }, - "engines": { - "node": ">=16" - } - }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", diff --git a/snippets/numbers/active-numbers/get/snippet.js b/snippets/numbers/active-numbers/get/snippet.js new file mode 100644 index 0000000..9dd6da3 --- /dev/null +++ b/snippets/numbers/active-numbers/get/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_rented_phoneNumber'; + + /** @type {Numbers.GetActiveNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + const response = await numbersService.activeNumber.get(requestData); + + console.log(`Rented number details:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/active-numbers/list-auto/snippet.js b/snippets/numbers/active-numbers/list-auto/snippet.js new file mode 100644 index 0000000..3ad03f2 --- /dev/null +++ b/snippets/numbers/active-numbers/list-auto/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type Numbers.ListActiveNumbersRequestData */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + }; + + console.log('List of numbers printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const rentedNumber of numbersService.activeNumber.list(requestData)) { + console.log(JSON.stringify(rentedNumber, null, 2)); + } + +}; diff --git a/snippets/numbers/active-numbers/list/snippet.js b/snippets/numbers/active-numbers/list/snippet.js new file mode 100644 index 0000000..cd58782 --- /dev/null +++ b/snippets/numbers/active-numbers/list/snippet.js @@ -0,0 +1,26 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type Numbers.ListActiveNumbersRequestData */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + }; + + /** @type {Numbers.ActiveNumber[]} */ + const activeNumbersList = []; + // Fetch a page of Numbers + let response = await numbersService.activeNumber.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + activeNumbersList.push(...response.data); + response = await response.nextPage(); + } + activeNumbersList.push(...response.data); + + console.log(`Full list of numbers printed at once (length = ${activeNumbersList.length}):\n${JSON.stringify(activeNumbersList, null, 2)}`); + +}; diff --git a/snippets/numbers/active-numbers/release/snippet.js b/snippets/numbers/active-numbers/release/snippet.js new file mode 100644 index 0000000..935db91 --- /dev/null +++ b/snippets/numbers/active-numbers/release/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_phone_number_to_be_released'; + + /** @type {Numbers.ReleaseNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + const response = await numbersService.activeNumber.release(requestData); + + console.log(`Released number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/active-numbers/update/snippet.js b/snippets/numbers/active-numbers/update/snippet.js new file mode 100644 index 0000000..5bbc842 --- /dev/null +++ b/snippets/numbers/active-numbers/update/snippet.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_phone_number_to_be_updated'; + const appId = 'YOUR_app_id'; + const displayName = 'Updated from Sinch Node.js SDK'; + + /** @type {Numbers.VoiceConfiguration} */ + const voiceConfiguration= { + appId, + type: 'RTC', + }; + + /** @type {Numbers.UpdateActiveNumberRequestData} */ + const requestData = { + phoneNumber, + updateActiveNumberRequestBody: { + displayName, + voiceConfiguration, + }, + }; + + const response = await numbersService.activeNumber.update(requestData); + + console.log(`Updated number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-numbers/check-availability/snippet.js b/snippets/numbers/available-numbers/check-availability/snippet.js new file mode 100644 index 0000000..41462d9 --- /dev/null +++ b/snippets/numbers/available-numbers/check-availability/snippet.js @@ -0,0 +1,21 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'a_phone_number'; + + /** @type {Numbers.GetAvailableNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + try { + const response = await numbersService.availableNumber.checkAvailability(requestData); + console.log(`The phone number is available:\n${JSON.stringify(response, null, 2)}`); + } catch (error) { + console.error(`ERROR: the phone number ${requestData.phoneNumber} is not available`); + } + +}; diff --git a/snippets/numbers/available-numbers/rent-any/snippet.js b/snippets/numbers/available-numbers/rent-any/snippet.js new file mode 100644 index 0000000..3ef7ebd --- /dev/null +++ b/snippets/numbers/available-numbers/rent-any/snippet.js @@ -0,0 +1,40 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const servicePlanId = 'YOUR_service_plan_id'; + const appId = 'YOUR_app_id'; + const callbackUrl = 'YOUR_callback_url'; + + /** @type {Numbers.RentAnyNumberRequestSmsConfiguration} */ + const smsConfiguration = { + servicePlanId, + }; + + /** @type {Numbers.RentAnyNumberRequestVoiceConfiguration} */ + const voiceConfiguration = { + appId, + }; + + /** @type {Numbers.RentAnyNumberRequestData} */ + const requestData = { + rentAnyNumberRequestBody: { + regionCode: 'US', + type: 'LOCAL', + numberPattern: { + pattern: '+1781', + searchPattern: 'START', + }, + smsConfiguration, + voiceConfiguration, + callbackUrl, + }, + }; + + const response = await numbersService.availableNumber.rentAny(requestData); + + console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`); + +}; diff --git a/snippets/numbers/available-numbers/rent/snippet.js b/snippets/numbers/available-numbers/rent/snippet.js new file mode 100644 index 0000000..ef6eaf1 --- /dev/null +++ b/snippets/numbers/available-numbers/rent/snippet.js @@ -0,0 +1,25 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + // Available numbers list can be retrieved by using list() function from available service, see: + // https://developers.sinch.com/docs/numbers/getting-started/node-sdk/searchavailable/ + const phoneNumber = 'available_phone_number_to_be_rented'; + const servicePlanId = 'YOUR_service_plan_id'; + + /** @type {Numbers.RentNumberRequestData} */ + const requestData = { + phoneNumber, + rentNumberRequestBody: { + smsConfiguration: { + servicePlanId, + }, + }, + }; + + const response = await numbersService.availableNumber.rent(requestData); + + console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js b/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js new file mode 100644 index 0000000..53bccc0 --- /dev/null +++ b/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type {Numbers.ListAvailableNumbersRequestData} */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + capabilities: ['SMS', 'VOICE'], + }; + + const response = await numbersService.availableNumber.list(requestData); + + console.log(`Available numbers to rent:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-regions/snippet.js b/snippets/numbers/available-regions/snippet.js new file mode 100644 index 0000000..6bf9329 --- /dev/null +++ b/snippets/numbers/available-regions/snippet.js @@ -0,0 +1,15 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type {Numbers.ListAvailableRegionsRequestData} */ + const requestData = { + types: ['LOCAL', 'MOBILE'], + }; + + const response = await numbersService.availableRegions.list(requestData); + + console.log(`Available regions:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/callback-configuration/get/snippet.js b/snippets/numbers/callback-configuration/get/snippet.js new file mode 100644 index 0000000..fc03424 --- /dev/null +++ b/snippets/numbers/callback-configuration/get/snippet.js @@ -0,0 +1,10 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const response = await numbersService.callbacks.get({}); + + console.log(`Callback configuration:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/callback-configuration/update/snippet.js b/snippets/numbers/callback-configuration/update/snippet.js new file mode 100644 index 0000000..8b9c918 --- /dev/null +++ b/snippets/numbers/callback-configuration/update/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const hmacSecret = 'New_HMAC_secret'; + + /** @type {Numbers.UpdateCallbackConfigurationRequestData} */ + const requestData = { + updateCallbackConfigurationRequestBody: { + hmacSecret, + }, + }; + + const response = await numbersService.callbacks.update(requestData); + + console.log(`Updated callback configuration:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/cancel/snippet.js b/snippets/sms/batches/cancel/snippet.js new file mode 100644 index 0000000..ffab300 --- /dev/null +++ b/snippets/sms/batches/cancel/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id_to_cancel'; + + /** @type {Sms.CancelBatchMessageRequestData} */ + const requestData= { + batch_id: batchId, + }; + + const response = await smsService.batches.cancel(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/delivery-feedback/snippet.js b/snippets/sms/batches/delivery-feedback/snippet.js new file mode 100644 index 0000000..b0fdcf1 --- /dev/null +++ b/snippets/sms/batches/delivery-feedback/snippet.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id'; + const recipientPhoneNumber = 'YOUR_recipient_phone_number'; + + /** @type {Sms.DeliveryFeedbackRequestData} */ + const requestData= { + batch_id: batchId, + deliveryFeedbackRequestBody: { + recipients: [ + recipientPhoneNumber, + ], + }, + }; + + await smsService.batches.sendDeliveryFeedback(requestData); + + console.log('The delivery feedback has been sent'); +}; diff --git a/snippets/sms/batches/dry-run/snippet.js b/snippets/sms/batches/dry-run/snippet.js new file mode 100644 index 0000000..9a1da3b --- /dev/null +++ b/snippets/sms/batches/dry-run/snippet.js @@ -0,0 +1,26 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + const body = 'This is a test SMS message using the Sinch Node.js SDK.'; + + /** @type {Sms.DryRunRequestData} */ + const requestData= { + dryRunRequestBody: { + type: 'mt_text', + from, + to: [ + recipient, + ], + body, + }, + }; + + const response = await smsService.batches.dryRun(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/get/snippet.js b/snippets/sms/batches/get/snippet.js new file mode 100644 index 0000000..d631412 --- /dev/null +++ b/snippets/sms/batches/get/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id'; + + /** @type {Sms.GetBatchMessageRequestData} */ + const requestData= { + batch_id: batchId, + }; + + const response = await smsService.batches.get(requestData); + + console.log(`Batch details:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/list-auto/snippet.js b/snippets/sms/batches/list-auto/snippet.js new file mode 100644 index 0000000..cf45540 --- /dev/null +++ b/snippets/sms/batches/list-auto/snippet.js @@ -0,0 +1,23 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + + /** @type {Sms.ListBatchesRequestData} */ + const requestData= { + start_date: oneWeekAgo, + page_size: 2, + }; + + console.log('List of batches printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const batch of smsService.batches.list(requestData)) { + console.log(JSON.stringify(batch, null, 2)); + } + +}; diff --git a/snippets/sms/batches/list/snippet.js b/snippets/sms/batches/list/snippet.js new file mode 100644 index 0000000..6282803 --- /dev/null +++ b/snippets/sms/batches/list/snippet.js @@ -0,0 +1,30 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + + /** @type {Sms.ListBatchesRequestData} */ + const requestData= { + start_date: oneWeekAgo, + page_size: 2, + }; + + /** @type {Sms.SendSMSResponse[]} */ + const batchesList = []; + // Fetch a page of Batches + let response = await smsService.batches.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + batchesList.push(...response.data); + response = await response.nextPage(); + } + batchesList.push(...response.data); + + console.log(`Full list of batches printed at once (length = ${batchesList.length}):\n${JSON.stringify(batchesList, null, 2)}`); + +}; diff --git a/snippets/sms/batches/replace/snippet.js b/snippets/sms/batches/replace/snippet.js new file mode 100644 index 0000000..9b801a0 --- /dev/null +++ b/snippets/sms/batches/replace/snippet.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService, textToHex } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + const batchId = 'the_batch_id_scheduled_in_the_future'; + + /** @type {Sms.ReplaceBatchMessageRequestData} */ + const requestData= { + batch_id: batchId, + replaceBatchMessageRequestBody: { + type: 'mt_binary', + from, + to: [ + recipient, + ], + udh: textToHex('UserDataHeader'), + body: btoa('This is a replaced message'), + client_reference: 'Sinch Node.js SDK snippet', + }, + }; + + const response = await smsService.batches.replace(requestData); + + console.log(`Replaced batch:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/send-binary-message/snippet.js b/snippets/sms/batches/send-binary-message/snippet.js new file mode 100644 index 0000000..2cffc9a --- /dev/null +++ b/snippets/sms/batches/send-binary-message/snippet.js @@ -0,0 +1,27 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService, textToHex } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.SendBinarySMSRequestData} */ + const requestData= { + sendSMSRequestBody: { + type: 'mt_binary', + from, + to: [ + recipient, + ], + body: 'SGVsbG8sIHRoaXMgaXMgYSBTTVMgZnJvbSBTaW5jaA==', + udh: textToHex('UserDataHeader'), + delivery_report: 'full', + }, + }; + + const response = await smsService.batches.sendBinaryMessage(requestData); + + console.log(`Response for binary batch:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/send-media-message/snippet.js b/snippets/sms/batches/send-media-message/snippet.js new file mode 100644 index 0000000..3b3a69c --- /dev/null +++ b/snippets/sms/batches/send-media-message/snippet.js @@ -0,0 +1,31 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.SendMediaSMSRequestData} */ + const requestData= { + sendSMSRequestBody: { + type: 'mt_media', + from, + to: [ + recipient, + ], + body: { + url: 'https://media.body.url', + message: 'Text message coming along with the media file', + }, + delivery_report: 'full', + strict_validation: true, + }, + }; + + const response = await smsService.batches.sendMediaMessage(requestData); + + console.log(`Response for MMS batch:\n${JSON.stringify(response, null, 2)}`); +}; + diff --git a/snippets/sms/batches/send-text-message/snippet.js b/snippets/sms/batches/send-text-message/snippet.js new file mode 100644 index 0000000..c1dfbd0 --- /dev/null +++ b/snippets/sms/batches/send-text-message/snippet.js @@ -0,0 +1,31 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.SendTextSMSRequestData} */ + const requestData= { + sendSMSRequestBody: { + type: 'mt_text', + from, + to: [ + recipient, + ], + body: 'Hi ${name}!', + parameters: { + name: { + [recipient]: 'John', + default: 'there', + }, + }, + }, + }; + + const response = await smsService.batches.sendTextMessage(requestData); + + console.log(`Response for SMS batch:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/send/snippet.js b/snippets/sms/batches/send/snippet.js new file mode 100644 index 0000000..ba2ee12 --- /dev/null +++ b/snippets/sms/batches/send/snippet.js @@ -0,0 +1,24 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const from = 'YOUR_sinch_phone_number'; + const recipient = 'YOUR_recipient_phone_number'; + const body = 'This is a test SMS message using the Sinch Node.js SDK.'; + + /** @type {Sms.SendSMSRequestData} */ + const requestData= { + sendSMSRequestBody: { + type: 'mt_text', + from, + to: [recipient], + body, + }, + }; + + const response = await smsService.batches.send(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/batches/update/snippet.js b/snippets/sms/batches/update/snippet.js new file mode 100644 index 0000000..403a2d7 --- /dev/null +++ b/snippets/sms/batches/update/snippet.js @@ -0,0 +1,24 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id_scheduled_in_the_future'; + const from = 'YOUR_sinch_phone_number'; + + /** @type {Sms.UpdateBatchMessageRequestData} */ + const requestData= { + batch_id: batchId, + updateBatchMessageRequestBody: { + type: 'mt_text', + from, + body: 'Hi ${name}! This is an updated message', + delivery_report: 'per_recipient', + }, + }; + + const response = await smsService.batches.update(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/delivery-reports/get-by-batch-id/snippet.js b/snippets/sms/delivery-reports/get-by-batch-id/snippet.js new file mode 100644 index 0000000..24c1dcc --- /dev/null +++ b/snippets/sms/delivery-reports/get-by-batch-id/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id'; + + /** @type {Sms.GetDeliveryReportByBatchIdRequestData} */ + const requestData= { + batch_id: batchId, + }; + + const response = await smsService.deliveryReports.get(requestData); + + console.log(`Delivery report:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/delivery-reports/get-for-number/snippet.js b/snippets/sms/delivery-reports/get-for-number/snippet.js new file mode 100644 index 0000000..5c1281d --- /dev/null +++ b/snippets/sms/delivery-reports/get-for-number/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const batchId = 'the_batch_id'; + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.GetDeliveryReportByPhoneNumberRequestData} */ + const requestData= { + batch_id: batchId, + recipient_msisdn: recipient, + }; + + const response = await smsService.deliveryReports.getForNumber(requestData); + + console.log(`Recipient delivery report:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/delivery-reports/list-auto/snippet.js b/snippets/sms/delivery-reports/list-auto/snippet.js new file mode 100644 index 0000000..b622ca4 --- /dev/null +++ b/snippets/sms/delivery-reports/list-auto/snippet.js @@ -0,0 +1,22 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + + /** @type {Sms.ListDeliveryReportsRequestData} */ + const requestData= { + start_date: oneWeekAgo, + }; + + console.log('List of delivery reports printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const deliveryReport of smsService.deliveryReports.list(requestData)) { + console.log(JSON.stringify(deliveryReport, null, 2)); + } + +}; diff --git a/snippets/sms/delivery-reports/list/snippet.js b/snippets/sms/delivery-reports/list/snippet.js new file mode 100644 index 0000000..c4cc2e3 --- /dev/null +++ b/snippets/sms/delivery-reports/list/snippet.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + + /** @type {Sms.ListDeliveryReportsRequestData} */ + const requestData= { + start_date: oneWeekAgo, + }; + + /** @type {Sms.RecipientDeliveryReport[]} */ + const deliveryReportsList = []; + // Fetch a page of Delivery Reports + let response = await smsService.deliveryReports.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + deliveryReportsList.push(...response.data); + response = await response.nextPage(); + } + deliveryReportsList.push(...response.data); + + console.log(`Full list of delivery reports printed at once (length = ${deliveryReportsList.length}):\n${JSON.stringify(deliveryReportsList, null, 2)}`); + +}; diff --git a/snippets/sms/groups/create/snippet.js b/snippets/sms/groups/create/snippet.js new file mode 100644 index 0000000..6f5b23c --- /dev/null +++ b/snippets/sms/groups/create/snippet.js @@ -0,0 +1,27 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const name = 'YOUR_group_name'; + const member1 = 'YOUR_recipient_1_phone_number'; + const member2 = 'YOUR_recipient_2_phone_number'; + const member3 = 'YOUR_recipient_3_phone_number'; + + /** @type {Sms.CreateGroupRequestData} */ + const requestData= { + createGroupRequestBody: { + name, + members: [ + member1, + member2, + member3, + ], + }, + }; + + const response = await smsService.groups.create(requestData); + + console.log(`Created group:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/groups/delete/snippet.js b/snippets/sms/groups/delete/snippet.js new file mode 100644 index 0000000..d91cf90 --- /dev/null +++ b/snippets/sms/groups/delete/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const groupId = 'YOUR_group_id'; + + /** @type {Sms.DeleteGroupRequestData} */ + const requestData= { + group_id: groupId, + }; + + await smsService.groups.delete(requestData); + + console.log('The group has been deleted.'); +}; diff --git a/snippets/sms/groups/get/snippet.js b/snippets/sms/groups/get/snippet.js new file mode 100644 index 0000000..61fbeeb --- /dev/null +++ b/snippets/sms/groups/get/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const groupId = 'YOUR_group_id'; + + /** @type {Sms.GetGroupRequestData} */ + const requestData= { + group_id: groupId, + }; + + const response = await smsService.groups.get(requestData); + + console.log(`Group details:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/groups/list-auto/snippet.js b/snippets/sms/groups/list-auto/snippet.js new file mode 100644 index 0000000..2cdbfcb --- /dev/null +++ b/snippets/sms/groups/list-auto/snippet.js @@ -0,0 +1,20 @@ +// @ts-check + +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + /** @type {Sms.ListGroupsRequestData} */ + const requestData= { + page_size: 2, + }; + + console.log('List of groups printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const group of smsService.groups.list(requestData)) { + console.log(JSON.stringify(group, null, 2)); + } + +}; diff --git a/snippets/sms/groups/list-members/snippet.js b/snippets/sms/groups/list-members/snippet.js new file mode 100644 index 0000000..52be06e --- /dev/null +++ b/snippets/sms/groups/list-members/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const groupId = 'YOUR_group_id'; + + /** @type {Sms.ListMembersRequestData} */ + const requestData= { + group_id: groupId, + }; + + const response = await smsService.groups.listMembers(requestData); + + console.log(`List of phone numbers in the group:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/groups/list/snippet.js b/snippets/sms/groups/list/snippet.js new file mode 100644 index 0000000..3d2016a --- /dev/null +++ b/snippets/sms/groups/list/snippet.js @@ -0,0 +1,27 @@ +// @ts-check + +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + /** @type {Sms.ListGroupsRequestData} */ + const requestData= { + page_size: 2, + }; + + /** @type {Sms.GroupResponse[]} */ + const groupsList = []; + // Fetch a page of Groups + let response = await smsService.groups.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + groupsList.push(...response.data); + response = await response.nextPage(); + } + groupsList.push(...response.data); + + console.log(`Full list of groups printed at once (length = ${groupsList.length}):\n${JSON.stringify(groupsList, null, 2)}`); + +}; diff --git a/snippets/sms/groups/replace/snippet.js b/snippets/sms/groups/replace/snippet.js new file mode 100644 index 0000000..b6be605 --- /dev/null +++ b/snippets/sms/groups/replace/snippet.js @@ -0,0 +1,25 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const groupId = 'YOUR_group_id'; + const member1 = 'YOUR_recipient_1_phone_number'; + const member2 = 'YOUR_recipient_2_phone_number'; + + /** @type {Sms.ReplaceGroupRequestData} */ + const requestData= { + group_id: groupId, + replaceGroupRequestBody: { + members: [ + member1, + member2, + ], + }, + }; + + const response = await smsService.groups.replace(requestData); + + console.log(`Replaced group:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/groups/update/snippet.js b/snippets/sms/groups/update/snippet.js new file mode 100644 index 0000000..6ee64aa --- /dev/null +++ b/snippets/sms/groups/update/snippet.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const groupId = 'YOUR_group_id'; + const name= 'YOUR_updated_group_name'; + const member1 = 'YOUR_recipient_1_phone_number'; + const member2 = 'YOUR_recipient_2_phone_number'; + + /** @type {Sms.UpdateGroupRequestData} */ + const requestData= { + group_id: groupId, + updateGroupRequestBody: { + name, + add: [ + member1, + ], + remove: [ + member2, + ], + }, + }; + + const response = await smsService.groups.update(requestData); + + console.log(`Updated group:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/inbounds/get/snippet.js b/snippets/sms/inbounds/get/snippet.js new file mode 100644 index 0000000..472b7d1 --- /dev/null +++ b/snippets/sms/inbounds/get/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const inboundId = 'the_inbound_id'; + + /** @type {Sms.GetInboundMessageRequestData} */ + const requestData= { + inbound_id: inboundId, + }; + + const response = await smsService.inbounds.get(requestData); + + console.log(`Inbound message:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/sms/inbounds/list-auto/snippet.js b/snippets/sms/inbounds/list-auto/snippet.js new file mode 100644 index 0000000..56acb6e --- /dev/null +++ b/snippets/sms/inbounds/list-auto/snippet.js @@ -0,0 +1,24 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.ListInboundMessagesRequestData} */ + const requestData= { + start_date: oneWeekAgo, + to: recipient, + }; + + console.log('List of inbound messages printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const inboundMessage of smsService.inbounds.list(requestData)) { + console.log(JSON.stringify(inboundMessage, null, 2)); + } + +}; diff --git a/snippets/sms/inbounds/list/snippet.js b/snippets/sms/inbounds/list/snippet.js new file mode 100644 index 0000000..18fdf65 --- /dev/null +++ b/snippets/sms/inbounds/list/snippet.js @@ -0,0 +1,31 @@ +// eslint-disable-next-line no-unused-vars +import { Sms, SmsService } from '@sinch/sdk-core'; + +/** @param {SmsService} smsService */ +export const execute = async (smsService) => { + + const oneWeekAgo = new Date(); + oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); + oneWeekAgo.setHours(0, 0, 0, 0); + const recipient = 'YOUR_recipient_phone_number'; + + /** @type {Sms.ListInboundMessagesRequestData} */ + const requestData= { + start_date: oneWeekAgo, + to: recipient, + }; + + /** @type {Sms.InboundMessageResponse[]} */ + const inboundMessagesList = []; + // Fetch a page of Inbound Messages + let response = await smsService.inbounds.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + inboundMessagesList.push(...response.data); + response = await response.nextPage(); + } + inboundMessagesList.push(...response.data); + + console.log(`Full list of inbound messages printed at once (length = ${inboundMessagesList.length}):\n${JSON.stringify(inboundMessagesList, null, 2)}`); + +}; diff --git a/snippets/verification/report-verification/report-flashcall-verification-by-id/snippet.js b/snippets/verification/report-verification/report-flashcall-verification-by-id/snippet.js new file mode 100644 index 0000000..ec96b09 --- /dev/null +++ b/snippets/verification/report-verification/report-flashcall-verification-by-id/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCLI = 'the_phone_number_calling_for_verification'; + + /** @type {Verification.ReportFlashCallVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildFlashCallRequest( + verificationID, + verificationCLI, + ); + + const response = await verificationService.verifications.reportFlashCallById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-flashcall-verification-by-identity/snippet.js b/snippets/verification/report-verification/report-flashcall-verification-by-identity/snippet.js new file mode 100644 index 0000000..f827e72 --- /dev/null +++ b/snippets/verification/report-verification/report-flashcall-verification-by-identity/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCLI = 'the_phone_number_calling_for_verification'; + + /** @type {Verification.ReportFlashCallVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildFlashCallRequest( + phoneNumber, + verificationCLI, + ); + + const response = await verificationService.verifications.reportFlashCallByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-phonecall-verification-by-id/snippet.js b/snippets/verification/report-verification/report-phonecall-verification-by-id/snippet.js new file mode 100644 index 0000000..93425a9 --- /dev/null +++ b/snippets/verification/report-verification/report-phonecall-verification-by-id/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCode = 'the_verification_code_received_by_phone_call'; + + /** @type {Verification.ReportCalloutVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildCalloutRequest( + verificationID, + verificationCode, + ); + + const response = await verificationService.verifications.reportCalloutById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-phonecall-verification-by-identity/snippet.js b/snippets/verification/report-verification/report-phonecall-verification-by-identity/snippet.js new file mode 100644 index 0000000..aa79d10 --- /dev/null +++ b/snippets/verification/report-verification/report-phonecall-verification-by-identity/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCode = 'the_verification_code_received_by_phone_call'; + + /** @type {Verification.ReportCalloutVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildCalloutRequest( + phoneNumber, + verificationCode, + ); + + const response = await verificationService.verifications.reportCalloutByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-sms-verification-by-id/snippet.js b/snippets/verification/report-verification/report-sms-verification-by-id/snippet.js new file mode 100644 index 0000000..729b20b --- /dev/null +++ b/snippets/verification/report-verification/report-sms-verification-by-id/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + const verificationCode = 'the_verification_code_received_by_SMS'; + + /** @type {Verification.ReportSmsVerificationByIdRequestData} */ + const requestData = Verification.reportVerificationByIdHelper.buildSmsRequest( + verificationID, + verificationCode, + ); + + const response = await verificationService.verifications.reportSmsById(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/report-verification/report-sms-verification-by-identity/snippet.js b/snippets/verification/report-verification/report-sms-verification-by-identity/snippet.js new file mode 100644 index 0000000..9da1b56 --- /dev/null +++ b/snippets/verification/report-verification/report-sms-verification-by-identity/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const verificationCode = 'the_verification_code_received_by_SMS'; + + /** @type {Verification.ReportSmsVerificationByIdentityRequestData} */ + const requestData = Verification.reportVerificationByIdentityHelper.buildSmsRequest( + phoneNumber, + verificationCode, + ); + + const response = await verificationService.verifications.reportSmsByIdentity(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-data-verification/snippet.js b/snippets/verification/start-verification/start-data-verification/snippet.js new file mode 100644 index 0000000..c3863d7 --- /dev/null +++ b/snippets/verification/start-verification/start-data-verification/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartSeamlessVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildSeamlessRequest( + phoneNumber, + reference, + ); + + const response = await verificationService.verifications.startSeamless(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-flashcall-verification/snippet.js b/snippets/verification/start-verification/start-flashcall-verification/snippet.js new file mode 100644 index 0000000..e927126 --- /dev/null +++ b/snippets/verification/start-verification/start-flashcall-verification/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartFlashCallVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildFlashCallRequest( + phoneNumber, + reference, + ); + + const response = await verificationService.verifications.startFlashCall(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-phonecall-verification/snippet.js b/snippets/verification/start-verification/start-phonecall-verification/snippet.js new file mode 100644 index 0000000..2dd9637 --- /dev/null +++ b/snippets/verification/start-verification/start-phonecall-verification/snippet.js @@ -0,0 +1,20 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartCalloutVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildCalloutRequest( + phoneNumber, + reference, + 'fr-FR', + ); + + const response = await verificationService.verifications.startCallout(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/start-verification/start-sms-verification/snippet.js b/snippets/verification/start-verification/start-sms-verification/snippet.js new file mode 100644 index 0000000..f71b554 --- /dev/null +++ b/snippets/verification/start-verification/start-sms-verification/snippet.js @@ -0,0 +1,22 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + const reference = 'the_verification_reference'; + + /** @type {Verification.StartSmsVerificationRequestData} */ + const requestData = Verification.startVerificationHelper.buildSmsRequest( + phoneNumber, + reference, + { + codeType: 'Alphanumeric', + }, + ); + + const response = await verificationService.verifications.startSms(requestData); + + console.log(`Response:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-id/snippet.js b/snippets/verification/verification-status/verification-by-id/snippet.js new file mode 100644 index 0000000..b30c214 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-id/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationID = 'the_verification_ID'; + + /** @type {Verification.VerificationStatusByIdRequestData} */ + const requestData = { + id: verificationID, + }; + + const response = await verificationService.verificationStatus.getById(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-identity/snippet.js b/snippets/verification/verification-status/verification-by-identity/snippet.js new file mode 100644 index 0000000..75f0cf8 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-identity/snippet.js @@ -0,0 +1,18 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const phoneNumber = 'the_phone_number_to_verify'; + + /** @type {Verification.VerificationStatusByIdentityRequestData} */ + const requestData = { + method: 'sms', + endpoint: phoneNumber, + }; + + const response = await verificationService.verificationStatus.getByIdentity(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/verification/verification-status/verification-by-reference/snippet.js b/snippets/verification/verification-status/verification-by-reference/snippet.js new file mode 100644 index 0000000..ebb30e5 --- /dev/null +++ b/snippets/verification/verification-status/verification-by-reference/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Verification, VerificationService } from '@sinch/sdk-core'; + +/** @param {VerificationService} verificationService */ +export const execute = async (verificationService) => { + + const verificationReference = 'the_verification_reference'; + + /** @type {Verification.VerificationStatusByReferenceRequestData} */ + const requestData = { + reference: verificationReference, + }; + + const response = await verificationService.verificationStatus.getByReference(requestData); + + console.log(`Verification status:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..5ae7fef --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "strict": true, + "lib": ["ES2022", "dom"], + "moduleResolution": "node", + "pretty": true, + "baseUrl": ".", + "noEmit": true, + "skipLibCheck": true + }, + "include": [ + "**/*.js" + ], + "exclude": [ + "node_modules" + ] +}