From f85f2fe9469046551fd0f305deebe72dc0071fe1 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Tue, 20 Aug 2024 14:48:43 +0200 Subject: [PATCH 01/12] feat: add `@magicbell/project-client` package --- .eslintrc.cjs | 2 +- example/package.json | 1 + package.json | 3 +- packages/project-client/.gitignore | 2 + packages/project-client/LICENSE | 194 +++++++++++++++++++ packages/project-client/README.md | 0 packages/project-client/liblab.config.json | 46 +++++ packages/project-client/package.json | 51 +++++ packages/project-client/scripts/build.ts | 159 +++++++++++++++ packages/project-client/scripts/sync-docs.ts | 190 ++++++++++++++++++ packages/project-client/tsconfig.build.json | 14 ++ packages/user-client/scripts/build.ts | 6 + tsconfig.json | 1 + 13 files changed, 667 insertions(+), 2 deletions(-) create mode 100644 packages/project-client/.gitignore create mode 100644 packages/project-client/LICENSE create mode 100644 packages/project-client/README.md create mode 100644 packages/project-client/liblab.config.json create mode 100644 packages/project-client/package.json create mode 100644 packages/project-client/scripts/build.ts create mode 100644 packages/project-client/scripts/sync-docs.ts create mode 100644 packages/project-client/tsconfig.build.json diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 1dd335bc6..3f4cdf4ed 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -46,7 +46,7 @@ module.exports = { } }, { - files: './packages/user-client/**/*.{ts,tsx}', + files: './packages/{project,user}-client/**/*.{ts,tsx}', rules: { '@typescript-eslint/no-empty-interface': 'off', '@typescript-eslint/no-unused-vars': 'off', diff --git a/example/package.json b/example/package.json index 1272ae7af..7687966ac 100644 --- a/example/package.json +++ b/example/package.json @@ -21,6 +21,7 @@ "@magicbell/embeddable": "../packages/embeddable", "@magicbell/in-app": "../packages/in-app", "@magicbell/magicbell-react": "../packages/react", + "@magicbell/project-client": "../packages/project-client", "@magicbell/react-headless": "../packages/react-headless", "@magicbell/user-client": "../packages/user-client", "@magicbell/utils": "../packages/utils", diff --git a/package.json b/package.json index 8ffafb4b6..943e376ce 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "start:example": "yarn --cwd example && yarn --cwd example start", "start:storybook": "cross-env NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 6006", "start:playground": "yarn --cwd packages/playground start", - "codegen": "turbo run codegen --parallel --no-cache", + "codegen": "turbo run codegen --concurrency 1 --no-cache", "build": "turbo run build", "build:example": "yarn --cwd example && yarn --cwd example build", "build:storybook": "build-storybook", @@ -59,6 +59,7 @@ "@testing-library/user-event": "^14.5.2", "@tsconfig/create-react-app": "^2.0.5", "@types/jest": "^29.5.10", + "@types/node": "^20.14.8", "@types/react": "^18.2.42", "@types/react-dom": "^18.2.17", "@typescript-eslint/eslint-plugin": "^7.16.0", diff --git a/packages/project-client/.gitignore b/packages/project-client/.gitignore new file mode 100644 index 000000000..8313d20b7 --- /dev/null +++ b/packages/project-client/.gitignore @@ -0,0 +1,2 @@ +magicbell-client.swagger.json +output diff --git a/packages/project-client/LICENSE b/packages/project-client/LICENSE new file mode 100644 index 000000000..2b3bdb112 --- /dev/null +++ b/packages/project-client/LICENSE @@ -0,0 +1,194 @@ +LICENSE AGREEMENT + +By downloading or using this software made available by MagicBell, Inc. +("MagicBell") or any documentation that accompanies it (collectively, the +"Software"), you and the company or entity that you represent (collectively, +"you" or "your") are consenting to be bound by and are becoming a party to this +License Agreement (this "Agreement"). You hereby represent and warrant that you +are authorized and lawfully able to bind such company or entity that you +represent to this Agreement. If you do not have such authority or do not agree +to all of the terms of this Agreement, you may not download or use the Software. + +LICENSE GRANT. Subject to your compliance with and the terms and conditions of +this Agreement, MagicBell, Inc. ("MagicBell") hereby grants you a limited, +personal, non-exclusive, non-sublicensable, non-transferable license to (a) use, +install, and run the Software solely to create and display a customized user +interface in connection with your internal use of MagicBell’s embeddable +notification inbox product (the "MagicBell Product"); and (b) modify the +Software (the results thereof, "Modifications") solely to customize your user +interface in connection with your use of the MagicBell Product; (c) compile and +execute object code versions of the Software (including as incorporating your +Modifications) solely to use internally your customized MagicBell Product user +interface; and (d) make electronic copies of the Software and any Modifications +as required for backup or archival purposes. You acknowledge that your use of +any components provided with the Software that are licensed under an open source +software license ("Open Source Components") are not part of the Software +licensed hereunder and are subject to and governed solely by the terms of the +applicable license(s) for that software, and not by this Agreement. + +RESTRICTIONS. You are responsible for all activities that occur in connection +with the Software. Except as otherwise expressly authorized by MagicBell, you +may not directly or indirectly: (a) sublicense, sell, assign, distribute, +modify, make derivative works of, make any commercial use of, use on a timeshare +or service bureau basis, use for the benefit of a third party or otherwise +commercialize the Software (or any Modifications); (b) allow third parties to +access or use the source code of the Software (or any Modifications); use the +Software (or any Modifications) to create or facilitate the creation of, or +otherwise incorporate any portion of the Software (or any Modifications) in, +any product or service that is competitive with the MagicBell Product; (c) use +the Software (or any Modifications) to perform comparisons or other +"benchmarking" activities; (d) remove any proprietary notices or branding from +the Software; and/or (e) use the Software (or any Modifications) in violation +of any applicable laws or regulations or outside of the scope of the license +granted in Section 1. You shall ensure that there is no direct or indirect use +of, or sharing of, the Software (or any Modifications), or other information +based upon or derived from the Software (or any Modifications) to develop such +competitive products. Without derogating the generality of the foregoing, +development of any competitive product shall include having direct or indirect +access to, supervising, consulting or assisting in the development of, or +product any specifications, documentations, object code or source code for, all +or part of any competitive product. + +AUTHORIZED USERS. Subject to the rights granted to you under this Agreement, +you may permit your employees, contractors and agents to exercise the rights +granted herein in accordance with the Agreement solely on behalf of you to +provide services to you, provided that you are liable for all acts and omissions +thereof to the extent that any such acts and omissions, if performed by you, +would constitute a breach or, or otherwise giver right to liability to you, +under this Agreement. You represent and warrant that you shall not permit any +third party to access or use the Software (or any Modifications) except as +expressly permitted under this Agreement. + +OPEN SOURCE COMPONENTS. You and your authorized users shall not use any Open +Source Components in connection with the Software or any Modifications or in any +way that could subject the Software to an open source license. + +OWNERSHIP. As between MagicBell and you, MagicBell or its licensors shall own +and retain all proprietary rights, including all patent, copyright, trade +secret, trademark and other intellectual property rights, in and to the Software +and any Modifications and you hereby irrevocably transfer, convey and assign to +MagicBell all right, title, and interest in any Modifications regardless of +whether such Modifications are actually delivered to MagicBell. MagicBell shall +have the exclusive right to apply for or register any patents, mask work rights, +copyrights, and such other proprietary protections with respect thereto. You +acknowledge that the license granted under Section 2 of this Agreement does not +provide you with title or ownership to the Software or any such Modifications, +but only a right of limited use under the terms and conditions of this +Agreement. + +You represent and warrant to MagicBell that you have the full right, and have +obtained all consents, approvals, authorizations, permits and licenses required +or necessary, to allow you to grant to MagicBell the assignments and rights +provided for herein and otherwise fully perform this Agreement (and have written +enforceable agreements with all persons necessary to give you the rights to do +the foregoing). + +LIMITATIONS ON MODIFICATIONS TO SOFTWARE. Notwithstanding any provision in this +Agreement, Modifications may only be created and used by you as permitted by +this Agreement. You are solely responsible for all use of Modifications and, +without limiting anything herein, MagicBell will have no liability with respect +to Modifications. You will not assert against MagicBell, its affiliates or +their customers, direct or indirect, agents and contractors, in any way, any +intellectual property rights that you may obtain relating to any Modifications +for the Software. + +SUPPORT AND UPGRADES. If MagicBell provides you with any upgrades, patches, +enhancements or fixes for the Software that it makes generally available free +of charge in connection with the Software, then the items that are provided will +become part of the Software and subject to this Agreement. MagicBell shall have +no obligation, however, under this Agreement or otherwise to provide any +upgrades, patches, enhancements, fixes or any other support to you for the +Software. + +WARRANTY AND DISCLAIMER. USE OF THE SOFTWARE IS ENTIRELY AT YOUR OWN RISK. +MAGICBELL PROVIDES THE SOFTWARE "AS IS" AND "AS AVAILABLE" WITHOUT ANY WARRANTY +OF ANY KIND AND HEREBY DISCLAIMS, FOR ITSELF AND ITS LICENSORS AND SUPPLIERS, +ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, PERFORMANCE, ACCURACY, +RELIABILITY, NON-INFRINGEMENT, AND WARRANTIES ARISING OUT OF COURSE OF +PERFORMANCE, COURSE OF DEALING OR USAGE IN TRADE. MAGICBELL DOES NOT WARRANT +THAT THE SOFTWARE IS ERROR-FREE, WILL FUNCTION WITHOUT INTERRUPTION, WILL MEET +ANY SPECIFIC NEED THAT YOU MAY HAVE, THAT ALL DEFECTS WILL BE CORRECTED OR THAT +IT IS SUFFICIENTLY DOCUMENTED TO BE USEABLE BY YOU. THIS DISCLAIMER OF WARRANTY +CONSTITUTES AN ESSENTIAL PART OF THE AGREEMENT. + +LIMITATION OF LIABILITY. NOTWITHSTANDING ANYTHING ELSE, UNDER NO CIRCUMSTANCES +SHALL MAGICBELL OR ITS LICENSORS OR SUPPLIERS, BE LIABLE TO YOU OR ANY OTHER +PERSON WITH RESPECT TO THE SUBJECT MATTER OF THIS AGREEMENT UNDER ANY CONTRACT, +TORT, NEGLIGENCE, STRICT LIABILITY, WARRANTY OR OTHER LEGAL OR EQUITABLE THEORY, +FOR ANY INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND +INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, +LOSS OF DATA, COSTS OF PROCUREMENT OF SUBSTITUTE GOODS, SERVICES, TECHNOLOGY OR +RIGHTS, INTERRUPTION OF BUSINESS, ACCURACY OF RESULTS, COMPUTER FAILURE OR +MALFUNCTION, OR OTHER DAMAGES IN EXCESS OF ONE HUNDRED DOLLARS (US$100), EVEN IF +AWARE OF THE POSSIBILITY OF SUCH DAMAGES. + +BASIS OF BARGAIN. YOU AND MAGICBELL EACH RECOGNIZE AND AGREE THAT THE WARRANTY +DISCLAIMERS AND LIABILITY AND REMEDY LIMITATIONS IN THIS AGREEMENT ARE MATERIAL, +BARGAINED FOR BASES FOR THIS AGREEMENT AND THAT THEY HAVE BEEN TAKEN INTO +ACCOUNT AND REFLECTED IN DETERMINING THE CONSIDERATION TO BE GIVEN BY EACH PARTY +UNDER THIS AGREEMENT AND IN THE DECISION BY EACH PARTY TO ENTER INTO THIS +AGREEMENT. + +TERM AND TERMINATION. The term of this Agreement will begin when the Software +is downloaded or accessed and shall continue until terminated pursuant to this +section. Either party may terminate this Agreement and the licenses granted +herein at any time. MagicBell may terminate this Agreement and the licenses +granted in this Agreement immediately if you breach any provision of this +Agreement, including but not limited to, if you are or become a competitor of +the MagicBell or make or sell any competitive products, in additional to all +other available remedies. Upon termination, all of your rights and licenses +under this Agreement cease to exist, including, for the avoidance of doubt, any +rights in any Modifications you may have developed; you must cease exercise of +the licensed rights herein; you must destroy or remove from all hard drives, +networks, and storage media, all copies and extracts of the Software and all +Modifications in your possession or control; and this sentence, all remedies for +breach, and Sections 2 through 10 and 12 through 14 shall survive any +termination of this Agreement. Any continued use of the Software by you or +attempt by you to exercise any rights under this Agreement after this Agreement +has been terminated will be considered copyright infringement and you will be +subject to all applicable remedies. + +FEEDBACK. You agree that MagicBell may collect or you may provide to MagicBell +comments, feedback, suggestions or other information related to the Software, or +modifications, corrections, improvements, derivatives and extensions to the +Software (collectively, "Feedback"), and you hereby grant MagicBell the +perpetual and irrevocable right (and the perpetual and irrevocable right to +permit others) to use and fully exercise and exploit the Feedback in any manner +to improve, develop and otherwise exploit applications, services or technology, +and otherwise in connection with its business during and after the term of this +Agreement. + +GOVERNMENT RESTRICTED RIGHTS. All software, technology, and accompanying +documentation are deemed to be "commercial computer software" and "commercial +computer software documentation," respectively, pursuant to DFAR Section +227.7202 and FAR Section 12.212, as applicable. Any use, modification, +reproduction, release, performance, display, transfer or disclosure of the +Software and accompanying documentation by any agency, department or other +entity of any government, shall be governed solely by the terms of this +Agreement and shall be prohibited except to the extent expressly permitted by +the terms herein or in a writing signed by an authorized signatory on behalf of +MagicBell. No other rights are granted. + +MISCELLANEOUS. You may not assign or transfer this Agreement, by operation of +law or otherwise, or any of your rights under this Agreement (including any +license rights granted to you), to any third party without MagicBell’s prior +written consent, which consent will not be unreasonably withheld or delayed. + +MagicBell may assign this Agreement, without consent, including, but not limited +to, affiliates or any successor to all or substantially all of its business or +assets to which this Agreement relates, whether by merger, sale of assets, sale +of stock, reorganization or otherwise. Any attempted assignment or transfer in +violation of the foregoing will be null and void. This Agreement contains the +complete agreement between you and MagicBell regarding the Software and +supersedes all prior agreements and representations between you and MagicBell +regarding the Software. This Agreement may only be amended and any provision +may only be waived by a writing executed by both parties. You agree to promptly +provide MagicBell with all information and documentation that MagicBell requests +to verify your compliance with this Agreement. If any provision of this +Agreement is held to be invalid or unenforceable, it shall be reformed to the +limited extent necessary to make it enforceable. This Agreement shall be +governed by and construed in accordance with the laws of California, without +regard to its conflicts of laws provisions. California will have exclusive +jurisdiction and venue under this Agreement. The United Nations Convention on +Contracts for the International Sale of Goods does not apply to this Agreement. diff --git a/packages/project-client/README.md b/packages/project-client/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/packages/project-client/liblab.config.json b/packages/project-client/liblab.config.json new file mode 100644 index 000000000..694221da4 --- /dev/null +++ b/packages/project-client/liblab.config.json @@ -0,0 +1,46 @@ +{ + "sdkName": "client", + "apiVersion": "2.0.0", + "apiName": "magicbell-api", + "specFilePath": "./magicbell-client.swagger.json", + "languages": ["typescript"], + "auth": ["bearer"], + "customizations": { + "includeOptionalSnippetParameters": true, + "authentication": { + "access": { + "prefix": "Bearer" + } + }, + "devContainer": false, + "generateEnv": true, + "inferServiceNames": false, + "injectedModels": [], + "license": { + "type": "CUSTOM", + "url": "https://raw.githubusercontent.com/magicbell/magicbell-js/main/LICENSE" + }, + "responseHeaders": false, + "retry": { + "enabled": true, + "maxAttempts": 3, + "retryDelay": 150 + } + }, + "languageOptions": { + "typescript": { + "bundle": false, + "exportClassDefault": false, + "httpClient": "axios", + "npmName": "project-client", + "npmOrg": "magicbell", + "githubRepoName": "magicbell-js", + "ignoreFiles": [], + "sdkVersion": "0.1.0", + "liblabVersion": "1" + } + }, + "publishing": { + "githubOrg": "magicbell" + } +} diff --git a/packages/project-client/package.json b/packages/project-client/package.json new file mode 100644 index 000000000..8159027cd --- /dev/null +++ b/packages/project-client/package.json @@ -0,0 +1,51 @@ +{ + "name": "@magicbell/project-client", + "version": "0.1.0", + "description": "Client - OpenAPI 3.1.0 Specification for MagicBell API.", + "repository": { + "type": "git", + "url": "https://github.com/magicbell/magicbell-js.git", + "directory": "packages/project-client" + }, + "license": "SEE LICENSE IN LICENSE", + "author": "Client", + "exports": { + "require": "./dist/commonjs/index.js", + "types": "./dist/commonjs/index.d.ts", + "default": "./dist/esm/index.js" + }, + "main": "./dist/commonjs/index.js", + "unpkg": "./dist/index.umd.js", + "module": "./dist/esm/index.js", + "source": "./src/index.ts", + "browser": "./dist/index.umd.js", + "types": "./dist/commonjs/index.d.ts", + "files": [ + "dist", + "README.md" + ], + "scripts": { + "build": "run-s build:*", + "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs", + "build:esm": "tsc --project tsconfig.build.json --module esnext --outDir dist/esm", + "codegen": "tsx scripts/build.ts", + "lint": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to .", + "lint:ci": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to . --cache --quiet", + "lint:fix": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to . --cache --fix", + "rebuild": "rm -rf dist/ && tsc", + "start": "rm -rf dist/ && tsc -w", + "test": "jest --detectOpenHandles", + "version": "tsc --version" + }, + "dependencies": { + "axios": "^1.0.0" + }, + "devDependencies": { + "@types/jest": "^29.5.10", + "@types/node": "^20.14.8", + "jest": "^29.7.0", + "nock": "^13.2.4", + "ts-jest": "^29.2.0", + "typescript": "^5.5.3" + } +} diff --git a/packages/project-client/scripts/build.ts b/packages/project-client/scripts/build.ts new file mode 100644 index 000000000..deefa7163 --- /dev/null +++ b/packages/project-client/scripts/build.ts @@ -0,0 +1,159 @@ +import { execSync } from 'node:child_process'; +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; +import { parseArgs } from 'node:util'; + +import Debug from 'debug'; +import { rimraf } from 'rimraf'; +import { sortPackageJson } from 'sort-package-json'; + +import rootPkgJson from '../../../package.json'; + +const debug = Debug('build'); + +async function move(oldPath: string, newPath: string) { + await rimraf(newPath); + await fs.mkdir(path.dirname(newPath), { recursive: true }); + await fs.rename(oldPath, newPath); +} + +function deleteUserPaths(schema: any) { + schema.tags = schema.tags.filter((x: any) => x.name !== 'admin' && x.name !== 'user'); + + for (const path of Object.keys(schema.paths)) { + for (const method of Object.keys(schema.paths[path])) { + const operation = schema.paths[path][method]; + if (!('tags' in operation) || !Array.isArray(operation.tags)) continue; + + // delete operation if it's not for admins + if (operation.tags.includes('admin')) { + operation.tags = operation.tags.filter((x: any) => x !== 'admin'); + } else { + delete schema.paths[path][method]; + debug(`delete ${path}/${method}`); + + // delete path if no operations left + if (Object.keys(schema.paths[path]).length > 0) continue; + delete schema.paths[path]; + debug(`delete ${path}`); + } + } + } + + return schema; +} + +function findAllRefs(obj: any, refs = new Set()) { + if (typeof obj !== 'object' || obj === null) return refs; + + if (Array.isArray(obj)) { + obj.forEach((item) => findAllRefs(item, refs)); + } else { + for (const key in obj) { + if (key === '$ref' && typeof obj[key] === 'string') { + refs.add(obj[key]); + } else { + findAllRefs(obj[key], refs); + } + } + } + + return refs; +} + +function deleteUnreferencedComponents(swagger: any) { + let refs = findAllRefs(swagger); + const components = swagger.components && swagger.components.schemas; + let initialCount, currentCount; + + do { + initialCount = Object.keys(components || {}).length; + + if (components) { + for (const schema in components) { + const refString = `#/components/schemas/${schema}`; + if (!refs.has(refString)) { + delete components[schema]; + // console.log(`delete ${refString}`) + } + } + } + + refs = findAllRefs(swagger); // Recalculate references after deletion + currentCount = Object.keys(components || {}).length; + } while (initialCount !== currentCount); +} + +async function readFileOrUrl(path: string): Promise { + if (/^http?s:\/\//.test(path)) { + return fetch(path, { headers: { 'content-type': 'application/json' } }).then((x) => x.text()); + } + + return fs.readFile(path, { encoding: 'utf-8' }); +} + +const { values: args } = parseArgs({ + options: { + spec: { type: 'string', short: 's' }, + }, +}); + +async function build(specfile = 'https://public.magicbell.com/specs/swagger.json') { + const liblabConfig = JSON.parse(await fs.readFile('./liblab.config.json', { encoding: 'utf-8' })); + let swaggerJSON = await readFileOrUrl(specfile); + const spec = JSON.parse(swaggerJSON); + + deleteUserPaths(spec); + deleteUnreferencedComponents(spec); + + swaggerJSON = JSON.stringify(spec, null, 2); + + await fs.writeFile(liblabConfig.specFilePath, swaggerJSON); + execSync(`npx -y liblab@latest build -y`, { stdio: 'inherit' }); + await rimraf(liblabConfig.specFilePath); + + await move('output/typescript/src', './src'); + // tests are currently ignored, as they're not stable between rebuilds, liblab is looking into this + // await move('output/typescript/test', './test'); + await move('output/typescript/package.json', './package.json'); + await move('output/typescript/README.md', './README.md'); + await rimraf('output'); + + // patch package.json + let pkgJson = JSON.parse(await fs.readFile('./package.json', { encoding: 'utf-8' })); + pkgJson.scripts.codegen = 'tsx scripts/build.ts'; + + pkgJson.scripts['build'] = 'run-s build:*'; + pkgJson.scripts['build:cjs'] = 'tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs'; + pkgJson.scripts['build:esm'] = 'tsc --project tsconfig.build.json --module esnext --outDir dist/esm'; + pkgJson.scripts['start'] = 'rm -rf dist/ && tsc -w'; + + delete pkgJson.scripts['watch']; + delete pkgJson.scripts['build:umd']; + delete pkgJson.scripts['build:all']; + delete pkgJson.scripts['prepublishOnly']; + + for (const key of Object.keys(pkgJson.devDependencies)) { + if (/eslint|prettier/.test(key)) { + delete pkgJson.devDependencies[key]; + } else if (rootPkgJson.dependencies[key]) { + pkgJson.devDependencies[key] = rootPkgJson.dependencies[key]; + } + } + + pkgJson.repository = { + type: 'git', + url: 'https://github.com/magicbell/magicbell-js.git', + directory: 'packages/project-client', + }; + + pkgJson = sortPackageJson(pkgJson); + await fs.writeFile('./package.json', JSON.stringify(pkgJson, null, 2) + '\n'); + + execSync(`yarn --cwd ../.. eslint --fix .`, { stdio: 'inherit' }); + execSync(`yarn --cwd ../.. manypkg fix`, { stdio: 'inherit' }); + execSync(`yarn --cwd ../..`, { stdio: 'inherit' }); + execSync(`yarn build`, { stdio: 'inherit' }); +} + +build(args.spec); diff --git a/packages/project-client/scripts/sync-docs.ts b/packages/project-client/scripts/sync-docs.ts new file mode 100644 index 000000000..4a8aad436 --- /dev/null +++ b/packages/project-client/scripts/sync-docs.ts @@ -0,0 +1,190 @@ +/* eslint-disable no-console */ +import * as fs from 'node:fs/promises'; +import * as path from 'node:path'; + +import { replaceBlock } from '@magicbell/codegen'; +import { Octokit } from '@octokit/rest'; +import { config } from 'dotenv'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +config(); + +const GITHUB_TOKEN = process.env.GITHUB_TOKEN!; +const REPO_OWNER = 'smeijer'; +const REPO_NAME = 'test'; +const FILE_PATH = 'src/docs/the-doc-to-update-2.mdx'; //'src/docs/docs/03-libraries/javascript-project-client.mdx'; +const BRANCH_NAME = 'magicbella/update-sdk-docs'; +const BASE_BRANCH = 'main'; + +if (!GITHUB_TOKEN) { + console.log('GITHUB_TOKEN environment variable is missing'); + process.exit(1); +} + +const octokit = new Octokit({ + auth: GITHUB_TOKEN, +}); + +async function fetchMainBranchSha() { + const response = await octokit.git.getRef({ + owner: REPO_OWNER, + repo: REPO_NAME, + ref: `heads/${BASE_BRANCH}`, + }); + return response.data.object.sha; +} + +async function ensureBranchFromMain() { + const mainBranchSha = await fetchMainBranchSha(); + + try { + await octokit.git.createRef({ + owner: REPO_OWNER, + repo: REPO_NAME, + ref: `refs/heads/${BRANCH_NAME}`, + sha: mainBranchSha, + }); + console.log(`Branch ${BRANCH_NAME} created successfully.`); + } catch (error: any) { + if (error.status === 422 && error.message.includes('Reference already exists')) { + console.log(`Branch ${BRANCH_NAME} already exists. Ensuring it's up to date.`); + await octokit.git.updateRef({ + owner: REPO_OWNER, + repo: REPO_NAME, + ref: `heads/${BRANCH_NAME}`, + sha: mainBranchSha, + force: true, + }); + } else { + throw error; + } + } +} + +async function fetchFileContent() { + try { + const response = await octokit.repos.getContent({ + owner: REPO_OWNER, + repo: REPO_NAME, + path: FILE_PATH, + ref: `heads/${BASE_BRANCH}`, + }); + + const fileContent = Buffer.from(response.data['content'], 'base64').toString('utf-8'); + return { content: fileContent, sha: response.data['sha'], exists: true }; + } catch (error: any) { + if (error.status === 404) { + return { content: '', sha: '', exists: false }; + } else { + throw error; + } + } +} + +async function updateFile(content: string, sha: string) { + const updatedContent = Buffer.from(content).toString('base64'); + + await octokit.repos.createOrUpdateFileContents({ + owner: REPO_OWNER, + repo: REPO_NAME, + path: FILE_PATH, + message: 'docs: update sdk documentation', + content: updatedContent, + branch: BRANCH_NAME, + sha: sha, + }); +} + +async function createOrUpdatePullRequest() { + const { data: pullRequests } = await octokit.pulls.list({ + owner: REPO_OWNER, + repo: REPO_NAME, + state: 'open', + head: `${REPO_OWNER}:${BRANCH_NAME}`, + base: BASE_BRANCH, + }); + + const title = 'docs: update sdk documentation'; + const body = 'Automated update of sdk documentation'; + + if (pullRequests.length > 0) { + const pr = pullRequests[0]; + console.log(`Pull request #${pr.number} already exists. Updating...`); + await octokit.pulls.update({ + owner: REPO_OWNER, + repo: REPO_NAME, + pull_number: pr.number, + title, + body, + }); + } else { + console.log('Creating new pull request.'); + await octokit.pulls.create({ + owner: REPO_OWNER, + repo: REPO_NAME, + head: BRANCH_NAME, + base: BASE_BRANCH, + title, + body, + }); + } +} + +function getMarkdownSection(markdown: string, sectionTitle: string) { + const lines = markdown.split('\n'); + const matcher = sectionTitle.startsWith('#') + ? (line) => line.trim() === sectionTitle.trim() + : (line) => line.trim().endsWith(`# ${sectionTitle}`); + + const startIndex = lines.findIndex(matcher); + + if (startIndex === -1) { + return null; // Section not found + } + + const needle = sectionTitle.split(' ')[0] + ' '; + + const endIndex = lines.findIndex((line, index) => { + if (index <= startIndex) return false; + return line.startsWith(needle); + }); + + const sectionLines = lines.slice(startIndex + 1, endIndex === -1 ? undefined : endIndex); + + return { + title: sectionTitle.replace(needle, '').trim(), + content: sectionLines.join('\n').trim(), + startIndex, + endIndex, + }; +} + +export async function syncDocs() { + try { + const readme = await fs.readFile(path.join(__dirname, '..', 'README.md'), { encoding: 'utf-8' }); + const allMethods = getMarkdownSection(readme, '## All Methods'); + + const { content, sha, exists } = await fetchFileContent(); + const patchedContent = replaceBlock(content, 'ALL_METHODS', allMethods.content); + + if (content === patchedContent) { + console.log('files are already up to date'); + return; + } + + await ensureBranchFromMain(); + await updateFile(patchedContent, exists ? sha : ''); + await createOrUpdatePullRequest(); + console.log('Pull request processed successfully.'); + } catch (error) { + console.error('Error updating documentation:', error); + } +} + +syncDocs().catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/packages/project-client/tsconfig.build.json b/packages/project-client/tsconfig.build.json new file mode 100644 index 000000000..d4cb15091 --- /dev/null +++ b/packages/project-client/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.build.json", + "include": ["src"], + "exclude": ["src/client/@custom_types"], + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist", + "target": "es2018", + "baseUrl": "./", + "declarationMap": true, + "lib": ["ES2021.String", "dom", "esnext"], + "noEmit": false + } +} diff --git a/packages/user-client/scripts/build.ts b/packages/user-client/scripts/build.ts index e4e5e6e79..cb693f230 100644 --- a/packages/user-client/scripts/build.ts +++ b/packages/user-client/scripts/build.ts @@ -6,6 +6,8 @@ import { parseArgs } from 'node:util'; import { rimraf } from 'rimraf'; import { sortPackageJson } from 'sort-package-json'; +import rootPkgJson from '../../../package.json'; + async function move(oldPath: string, newPath: string) { await rimraf(newPath); await fs.mkdir(path.dirname(newPath), { recursive: true }); @@ -121,7 +123,9 @@ async function build(specfile = 'https://public.magicbell.com/specs/swagger.json pkgJson.scripts['build'] = 'run-s build:*'; pkgJson.scripts['build:cjs'] = 'tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs'; pkgJson.scripts['build:esm'] = 'tsc --project tsconfig.build.json --module esnext --outDir dist/esm'; + pkgJson.scripts['start'] = 'rm -rf dist/ && tsc -w'; + delete pkgJson.scripts['watch']; delete pkgJson.scripts['build:umd']; delete pkgJson.scripts['build:all']; delete pkgJson.scripts['prepublishOnly']; @@ -129,6 +133,8 @@ async function build(specfile = 'https://public.magicbell.com/specs/swagger.json for (const key of Object.keys(pkgJson.devDependencies)) { if (/eslint|prettier/.test(key)) { delete pkgJson.devDependencies[key]; + } else if (rootPkgJson.dependencies[key]) { + pkgJson.devDependencies[key] = rootPkgJson.dependencies[key]; } } diff --git a/tsconfig.json b/tsconfig.json index 2a315e9b8..80cfbe8dd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "@magicbell/embeddable": ["packages/embeddable/src"], "@magicbell/in-app": ["packages/in-app/src"], "@magicbell/magicbell-react": ["packages/react/src"], + "@magicbell/project-client": ["packages/project-client/src"], "@magicbell/react-headless": ["packages/react-headless/src"], "@magicbell/user-client": ["packages/user-client/src"], "@magicbell/utils": ["packages/utils/src"], From 83d23bfb22ec63a0b9e608927533e00bc96bca38 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Wed, 21 Aug 2024 16:16:49 +0200 Subject: [PATCH 02/12] chore: generate client --- packages/project-client/README.md | 1339 +++++++++++++++++ packages/project-client/src/BaseService.ts | 46 + packages/project-client/src/hooks/Hook.ts | 28 + .../project-client/src/http/Environment.ts | 3 + .../project-client/src/http/HTTPClient.ts | 12 + .../project-client/src/http/HTTPLibrary.ts | 159 ++ .../src/http/QuerySerializer.ts | 40 + .../src/http/errors/BadGateway.ts | 11 + .../src/http/errors/BadRequest.ts | 11 + .../src/http/errors/Conflict.ts | 11 + .../src/http/errors/ExpectationFailed.ts | 11 + .../src/http/errors/FailedDependency.ts | 11 + .../src/http/errors/Forbidden.ts | 11 + .../src/http/errors/GatewayTimeout.ts | 11 + .../project-client/src/http/errors/Gone.ts | 11 + .../http/errors/HttpVersionNotSupported.ts | 11 + .../src/http/errors/InternalServerError.ts | 11 + .../src/http/errors/LengthRequired.ts | 11 + .../project-client/src/http/errors/Locked.ts | 11 + .../src/http/errors/LoopDetected.ts | 11 + .../src/http/errors/MethodNotAllowed.ts | 14 + .../src/http/errors/MisdirectedRequest.ts | 11 + .../errors/NetworkAuthenticationRequired.ts | 11 + .../src/http/errors/NotAcceptable.ts | 11 + .../src/http/errors/NotExtended.ts | 11 + .../src/http/errors/NotFound.ts | 11 + .../src/http/errors/NotImplemented.ts | 11 + .../src/http/errors/PayloadTooLarge.ts | 14 + .../src/http/errors/PaymentRequired.ts | 11 + .../src/http/errors/PreconditionFailed.ts | 11 + .../src/http/errors/PreconditionRequired.ts | 11 + .../errors/ProxyAuthenticationRequired.ts | 14 + .../src/http/errors/RangeNotSatisfiable.ts | 11 + .../errors/RequestHeaderFieldsTooLarge.ts | 11 + .../src/http/errors/RequestTimeout.ts | 11 + .../src/http/errors/ServiceUnavailable.ts | 14 + .../src/http/errors/TooEarly.ts | 11 + .../src/http/errors/TooManyRequests.ts | 14 + .../src/http/errors/Unauthorized.ts | 14 + .../http/errors/UnavailableForLegalReasons.ts | 11 + .../src/http/errors/UnprocessableEntity.ts | 11 + .../src/http/errors/UnsufficientStorage.ts | 11 + .../src/http/errors/UnsupportedMediaType.ts | 11 + .../src/http/errors/UpgradeRequired.ts | 11 + .../src/http/errors/UriTooLong.ts | 11 + .../src/http/errors/VariantAlsoNegotiates.ts | 11 + .../project-client/src/http/errors/base.ts | 52 + .../project-client/src/http/errors/index.ts | 83 + .../project-client/src/http/httpExceptions.ts | 135 ++ packages/project-client/src/index.ts | 51 + packages/project-client/src/models.ts | 44 + .../project-client/src/services/README.md | 1254 +++++++++++++++ .../src/services/broadcasts/Broadcasts.ts | 67 + .../src/services/broadcasts/index.ts | 3 + .../services/broadcasts/models/Broadcast.ts | 92 ++ .../models/BroadcastListResponse.ts | 13 + .../models/CreateBroadcastRequest.ts | 92 ++ .../src/services/broadcasts/models/Topic.ts | 6 + .../src/services/broadcasts/models/User.ts | 66 + .../src/services/channels/Channels.ts | 310 ++++ .../src/services/channels/index.ts | 11 + .../src/services/channels/models/ApnsToken.ts | 6 + .../channels/models/ApnsTokenWithMetadata.ts | 14 + .../models/ArrayWithMetadataOfApnsToken.ts | 16 + .../models/ArrayWithMetadataOfFcmToken.ts | 16 + .../models/ArrayWithMetadataOfSlackToken.ts | 16 + .../models/ArrayWithMetadataOfTeamsToken.ts | 16 + .../models/ArrayWithMetadataOfWebPushToken.ts | 16 + .../services/channels/models/DiscardResult.ts | 4 + .../src/services/channels/models/FcmToken.ts | 6 + .../channels/models/FcmTokenWithMetadata.ts | 14 + .../services/channels/models/SlackToken.ts | 12 + .../channels/models/SlackTokenWithMetadata.ts | 14 + .../services/channels/models/TeamsToken.ts | 1 + .../channels/models/TeamsTokenWithMetadata.ts | 14 + .../services/channels/models/WebPushToken.ts | 8 + .../models/WebPushTokenWithMetadata.ts | 14 + .../src/services/integrations/Integrations.ts | 393 +++++ .../src/services/integrations/index.ts | 23 + .../integrations/models/ApnsConfig.ts | 9 + .../services/integrations/models/FcmConfig.ts | 15 + .../integrations/models/InboxConfig.ts | 11 + .../models/ListIntegrationsResponse.ts | 10 + .../integrations/models/MailgunConfig.ts | 7 + .../integrations/models/PingConfig.ts | 6 + .../models/SaveApnsIntegrationRequest.ts | 9 + .../models/SaveFcmIntegrationRequest.ts | 15 + .../models/SaveInboxIntegrationRequest.ts | 11 + .../models/SaveMailgunIntegrationRequest.ts | 7 + .../models/SavePingEmailIntegrationRequest.ts | 6 + .../models/SaveSendgridIntegrationRequest.ts | 28 + .../models/SaveSlackIntegrationRequest.ts | 7 + .../models/SaveStripeIntegrationRequest.ts | 6 + .../models/SaveTemplatesIntegrationRequest.ts | 1 + .../SaveTemplatesIntegrationResponse.ts | 1 + .../models/SaveTwilioIntegrationRequest.ts | 24 + .../models/SaveWebPushIntegrationRequest.ts | 4 + .../integrations/models/SendgridConfig.ts | 28 + .../integrations/models/SlackConfig.ts | 7 + .../integrations/models/StripeConfig.ts | 6 + .../integrations/models/TwilioConfig.ts | 24 + .../integrations/models/WebpushConfig.ts | 4 + 102 files changed, 5202 insertions(+) create mode 100644 packages/project-client/src/BaseService.ts create mode 100644 packages/project-client/src/hooks/Hook.ts create mode 100644 packages/project-client/src/http/Environment.ts create mode 100644 packages/project-client/src/http/HTTPClient.ts create mode 100644 packages/project-client/src/http/HTTPLibrary.ts create mode 100644 packages/project-client/src/http/QuerySerializer.ts create mode 100644 packages/project-client/src/http/errors/BadGateway.ts create mode 100644 packages/project-client/src/http/errors/BadRequest.ts create mode 100644 packages/project-client/src/http/errors/Conflict.ts create mode 100644 packages/project-client/src/http/errors/ExpectationFailed.ts create mode 100644 packages/project-client/src/http/errors/FailedDependency.ts create mode 100644 packages/project-client/src/http/errors/Forbidden.ts create mode 100644 packages/project-client/src/http/errors/GatewayTimeout.ts create mode 100644 packages/project-client/src/http/errors/Gone.ts create mode 100644 packages/project-client/src/http/errors/HttpVersionNotSupported.ts create mode 100644 packages/project-client/src/http/errors/InternalServerError.ts create mode 100644 packages/project-client/src/http/errors/LengthRequired.ts create mode 100644 packages/project-client/src/http/errors/Locked.ts create mode 100644 packages/project-client/src/http/errors/LoopDetected.ts create mode 100644 packages/project-client/src/http/errors/MethodNotAllowed.ts create mode 100644 packages/project-client/src/http/errors/MisdirectedRequest.ts create mode 100644 packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts create mode 100644 packages/project-client/src/http/errors/NotAcceptable.ts create mode 100644 packages/project-client/src/http/errors/NotExtended.ts create mode 100644 packages/project-client/src/http/errors/NotFound.ts create mode 100644 packages/project-client/src/http/errors/NotImplemented.ts create mode 100644 packages/project-client/src/http/errors/PayloadTooLarge.ts create mode 100644 packages/project-client/src/http/errors/PaymentRequired.ts create mode 100644 packages/project-client/src/http/errors/PreconditionFailed.ts create mode 100644 packages/project-client/src/http/errors/PreconditionRequired.ts create mode 100644 packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts create mode 100644 packages/project-client/src/http/errors/RangeNotSatisfiable.ts create mode 100644 packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts create mode 100644 packages/project-client/src/http/errors/RequestTimeout.ts create mode 100644 packages/project-client/src/http/errors/ServiceUnavailable.ts create mode 100644 packages/project-client/src/http/errors/TooEarly.ts create mode 100644 packages/project-client/src/http/errors/TooManyRequests.ts create mode 100644 packages/project-client/src/http/errors/Unauthorized.ts create mode 100644 packages/project-client/src/http/errors/UnavailableForLegalReasons.ts create mode 100644 packages/project-client/src/http/errors/UnprocessableEntity.ts create mode 100644 packages/project-client/src/http/errors/UnsufficientStorage.ts create mode 100644 packages/project-client/src/http/errors/UnsupportedMediaType.ts create mode 100644 packages/project-client/src/http/errors/UpgradeRequired.ts create mode 100644 packages/project-client/src/http/errors/UriTooLong.ts create mode 100644 packages/project-client/src/http/errors/VariantAlsoNegotiates.ts create mode 100644 packages/project-client/src/http/errors/base.ts create mode 100644 packages/project-client/src/http/errors/index.ts create mode 100644 packages/project-client/src/http/httpExceptions.ts create mode 100644 packages/project-client/src/index.ts create mode 100644 packages/project-client/src/models.ts create mode 100644 packages/project-client/src/services/README.md create mode 100644 packages/project-client/src/services/broadcasts/Broadcasts.ts create mode 100644 packages/project-client/src/services/broadcasts/index.ts create mode 100644 packages/project-client/src/services/broadcasts/models/Broadcast.ts create mode 100644 packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts create mode 100644 packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts create mode 100644 packages/project-client/src/services/broadcasts/models/Topic.ts create mode 100644 packages/project-client/src/services/broadcasts/models/User.ts create mode 100644 packages/project-client/src/services/channels/Channels.ts create mode 100644 packages/project-client/src/services/channels/index.ts create mode 100644 packages/project-client/src/services/channels/models/ApnsToken.ts create mode 100644 packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts create mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts create mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts create mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts create mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts create mode 100644 packages/project-client/src/services/channels/models/DiscardResult.ts create mode 100644 packages/project-client/src/services/channels/models/FcmToken.ts create mode 100644 packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/channels/models/SlackToken.ts create mode 100644 packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/channels/models/TeamsToken.ts create mode 100644 packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/channels/models/WebPushToken.ts create mode 100644 packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/integrations/Integrations.ts create mode 100644 packages/project-client/src/services/integrations/index.ts create mode 100644 packages/project-client/src/services/integrations/models/ApnsConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/FcmConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/InboxConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts create mode 100644 packages/project-client/src/services/integrations/models/MailgunConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/PingConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts create mode 100644 packages/project-client/src/services/integrations/models/SendgridConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/SlackConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/StripeConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/TwilioConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/WebpushConfig.ts diff --git a/packages/project-client/README.md b/packages/project-client/README.md index e69de29bb..40f9bc5db 100644 --- a/packages/project-client/README.md +++ b/packages/project-client/README.md @@ -0,0 +1,1339 @@ +# Client Typescript SDK 0.1.0 + +The Typescript SDK for Client. + +- API version: 0.1.0 +- SDK version: 0.1.0 + +## Table of Contents + +- [About the API](#requirements) +- [Installation](#installation) +- [Authentication](#authentication) + - [Access Token](#access-token) +- [API Endpoint Services](#api-endpoint-services) +- [API Models](#api-models) +- [Sample Usage](#sample-usage) +- [Client Services](#client-services) +- [License](#license) + +## About the API + +OpenAPI 3.1.0 Specification for MagicBell API. + +## Installation + +```sh +npm install project-client +``` + +## Authentication + +To see whether an endpoint needs a specific type of authentication check the endpoint's documentation. + +### Access Token + +The Client API uses access tokens as a form of authentication. You can set the access token when initializing the SDK through the constructor: + +``` +const sdk = new Client('YOUR_ACCESS_TOKEN') +``` + +Or through the `setAccessToken` method: + +``` +const sdk = new Client() +sdk.setAccessToken('YOUR_ACCESS_TOKEN') +``` + +You can also set it for each service individually: + +``` +const sdk = new Client() +sdk.broadcasts.setAccessToken('YOUR_ACCESS_TOKEN') +``` + +## Sample Usage + +Here is a simple program demonstrating usage of this SDK. It can also be found in the `examples/src/index.ts` file in this directory. + +When running the sample make sure to use `npm install` to install all the dependencies. + +```Typescript +import { Client } from '@magicbell/project-client'; + + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + try { + const result = await sdk.broadcasts + .listBroadcasts(); + console.log(result); + } catch (err) { + const error = err as Error; + console.error(error.message); + } +})(); + + +``` + +# Client Services + +A list of all services and services methods. + +- Services + + - [Broadcasts](#broadcasts) + + - [Integrations](#integrations) + + - [Channels](#channels) + +- [All Methods](#all-methods) + +## Broadcasts + +| Method | Description | +| :---------------------------------- | :---------- | +| [createBroadcast](#createbroadcast) | | +| [listBroadcasts](#listbroadcasts) | | +| [fetchBroadcast](#fetchbroadcast) | | + +## Integrations + +| Method | Description | +| :-------------------------------------------------------- | :---------- | +| [listIntegrations](#listintegrations) | | +| [deleteApnsIntegration](#deleteapnsintegration) | | +| [saveApnsIntegration](#saveapnsintegration) | | +| [deleteFcmIntegration](#deletefcmintegration) | | +| [saveFcmIntegration](#savefcmintegration) | | +| [deleteInboxIntegration](#deleteinboxintegration) | | +| [saveInboxIntegration](#saveinboxintegration) | | +| [deleteMailgunIntegration](#deletemailgunintegration) | | +| [saveMailgunIntegration](#savemailgunintegration) | | +| [deletePingEmailIntegration](#deletepingemailintegration) | | +| [savePingEmailIntegration](#savepingemailintegration) | | +| [deleteSendgridIntegration](#deletesendgridintegration) | | +| [saveSendgridIntegration](#savesendgridintegration) | | +| [deleteSlackIntegration](#deleteslackintegration) | | +| [saveSlackIntegration](#saveslackintegration) | | +| [deleteStripeIntegration](#deletestripeintegration) | | +| [saveStripeIntegration](#savestripeintegration) | | +| [deleteTemplatesIntegration](#deletetemplatesintegration) | | +| [saveTemplatesIntegration](#savetemplatesintegration) | | +| [deleteTwilioIntegration](#deletetwiliointegration) | | +| [saveTwilioIntegration](#savetwiliointegration) | | +| [deleteWebPushIntegration](#deletewebpushintegration) | | +| [saveWebPushIntegration](#savewebpushintegration) | | + +## Channels + +| Method | Description | +| :---------------------------------------------------------------- | :---------- | +| [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | | +| [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | | +| [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | | +| [getMobilePushFcmUserTokens](#getmobilepushfcmusertokens) | | +| [getMobilePushFcmUserToken](#getmobilepushfcmusertoken) | | +| [discardMobilePushFcmUserToken](#discardmobilepushfcmusertoken) | | +| [getSlackUserTokens](#getslackusertokens) | | +| [getSlackUserToken](#getslackusertoken) | | +| [discardSlackUserToken](#discardslackusertoken) | | +| [getTeamsUserTokens](#getteamsusertokens) | | +| [getTeamsUserToken](#getteamsusertoken) | | +| [discardTeamsUserToken](#discardteamsusertoken) | | +| [getWebPushUserTokens](#getwebpushusertokens) | | +| [getWebPushUserToken](#getwebpushusertoken) | | +| [discardWebPushUserToken](#discardwebpushusertoken) | | + +## All Methods + +### **createBroadcast** + +- HTTP Method: POST +- Endpoint: /broadcasts + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +Broadcast + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + action_url: 'https://example.com', + category: 'example', + content: 'Hello, World!', + custom_attributes: {}, + overrides: {}, + recipients: [ + { + custom_attributes: { + plan: 'enterprise', + preferred_pronoun: 'They', + pricing_version: 'v10', + }, + external_id: '83d987a-83fd034', + first_name: 'Person', + last_name: 'Doe', + phone_numbers: ['+1 5005550001'], + }, + ], + title: 'Hello, World!', + topic: 'example', + }; + const result = await sdk.broadcasts.createBroadcast(input); + console.log(result); +})(); + +``` + +### **listBroadcasts** + +- HTTP Method: GET +- Endpoint: /broadcasts + +**Return Type** + +BroadcastListResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.broadcasts.listBroadcasts(); + console.log(result); +})(); + +``` + +### **fetchBroadcast** + +- HTTP Method: GET +- Endpoint: /broadcasts/{broadcast_id} + +**Required Parameters** + +| Name | Type | Description | +| :---------- | :----- | :---------- | +| broadcastId | string | | + +**Return Type** + +Broadcast + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.broadcasts.fetchBroadcast('broadcast_id'); + console.log(result); +})(); + +``` + +### **listIntegrations** + +- HTTP Method: GET +- Endpoint: /integrations + +**Return Type** + +ListIntegrationsResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.listIntegrations(); + console.log(result); +})(); + +``` + +### **deleteApnsIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/apns + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteApnsIntegration(); + console.log(result); +})(); + +``` + +### **saveApnsIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/apns + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +ApnsConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }; + const result = await sdk.integrations.saveApnsIntegration(input); + console.log(result); +})(); + +``` + +### **deleteFcmIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/fcm + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteFcmIntegration(); + console.log(result); +})(); + +``` + +### **saveFcmIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/fcm + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +FcmConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + auth_provider_x509_cert_url: '', + auth_uri: '', + client_email: '', + client_id: '', + client_x509_cert_url: '', + private_key: + '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQ8J\n-----END PRIVATE', + private_key_id: 'e7', + project_id: 'universe-1', + token_uri: '', + type: 'service_account', + universe_domain: 'universe-1.firebaseapp.com', + }; + const result = await sdk.integrations.saveFcmIntegration(input); + console.log(result); +})(); + +``` + +### **deleteInboxIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/inbox + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteInboxIntegration(); + console.log(result); +})(); + +``` + +### **saveInboxIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/inbox + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +InboxConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + apns: { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }, + }; + const result = await sdk.integrations.saveInboxIntegration(input); + console.log(result); +})(); + +``` + +### **deleteMailgunIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/mailgun + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteMailgunIntegration(); + console.log(result); +})(); + +``` + +### **saveMailgunIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/mailgun + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +MailgunConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { api_key: 'mailgun_api_key', domain: 'mailgun_domain', region: 'us' }; + const result = await sdk.integrations.saveMailgunIntegration(input); + console.log(result); +})(); + +``` + +### **deletePingEmailIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/ping_email + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deletePingEmailIntegration(); + console.log(result); +})(); + +``` + +### **savePingEmailIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/ping_email + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +PingConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { url: 'https://example.com/webhook' }; + const result = await sdk.integrations.savePingEmailIntegration(input); + console.log(result); +})(); + +``` + +### **deleteSendgridIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/sendgrid + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteSendgridIntegration(); + console.log(result); +})(); + +``` + +### **saveSendgridIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/sendgrid + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SendgridConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + api_key: 'SG.1234567890', + from: { email: 'matt@magicbell.com', name: 'Matt' }, + reply_to: { email: 'hana@magicbell.com', name: 'Hana' }, + }; + const result = await sdk.integrations.saveSendgridIntegration(input); + console.log(result); +})(); + +``` + +### **deleteSlackIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/slack + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteSlackIntegration(); + console.log(result); +})(); + +``` + +### **saveSlackIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/slack + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SlackConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + app_id: '12345678901', + client_id: '1.0', + client_secret: '12345678901234567890123456789012', + signing_secret: '12345678901234567890123456789012', + }; + const result = await sdk.integrations.saveSlackIntegration(input); + console.log(result); +})(); + +``` + +### **deleteStripeIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/stripe + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteStripeIntegration(); + console.log(result); +})(); + +``` + +### **saveStripeIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/stripe + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +StripeConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + webhook_signing_secret: + 'whsec_e5cf4458caae49ae72d8f275deb9b63bdd41dd5c932c27c9346d428fb9e1d0a0', + }; + const result = await sdk.integrations.saveStripeIntegration(input); + console.log(result); +})(); + +``` + +### **deleteTemplatesIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/templates + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteTemplatesIntegration(); + console.log(result); +})(); + +``` + +### **saveTemplatesIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/templates + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SaveTemplatesIntegrationResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + apns: { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }, + }; + const result = await sdk.integrations.saveTemplatesIntegration(input); + console.log(result); +})(); + +``` + +### **deleteTwilioIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/twilio + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteTwilioIntegration(); + console.log(result); +})(); + +``` + +### **saveTwilioIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/twilio + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +TwilioConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + account_sid: 'ACXXXXXXXX', + api_key: 'SKXXXXXXXX', + api_secret: 'your_api_secret', + from: '+15017122661', + region: 'us1', + }; + const result = await sdk.integrations.saveTwilioIntegration(input); + console.log(result); +})(); + +``` + +### **deleteWebPushIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/web_push + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteWebPushIntegration(); + console.log(result); +})(); + +``` + +### **saveWebPushIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/web_push + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +WebpushConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { private_key: '', public_key: '' }; + const result = await sdk.integrations.saveWebPushIntegration(input); + console.log(result); +})(); + +``` + +### **getMobilePushApnsUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfApnsToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushApnsUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getMobilePushApnsUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +ApnsTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushApnsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardMobilePushApnsUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardMobilePushApnsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getMobilePushFcmUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfFcmToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushFcmUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getMobilePushFcmUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +FcmTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushFcmUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardMobilePushFcmUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardMobilePushFcmUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getSlackUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/slack/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfSlackToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getSlackUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getSlackUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +SlackTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getSlackUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardSlackUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardSlackUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getTeamsUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/teams/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfTeamsToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getTeamsUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getTeamsUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +TeamsTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getTeamsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardTeamsUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardTeamsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getWebPushUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/web_push/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfWebPushToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getWebPushUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getWebPushUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +WebPushTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getWebPushUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardWebPushUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardWebPushUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +## License + +See license in LICENSE. diff --git a/packages/project-client/src/BaseService.ts b/packages/project-client/src/BaseService.ts new file mode 100644 index 000000000..b612717fc --- /dev/null +++ b/packages/project-client/src/BaseService.ts @@ -0,0 +1,46 @@ +import { Environment } from './http/Environment'; +import { Headers } from './http/HTTPClient'; +import HTTPLibrary from './http/HTTPLibrary'; + +export default class BaseService { + public baseUrl: string = Environment.DEFAULT; + + public httpClient = new HTTPLibrary(); + + private accessToken = ''; + + private accessTokenPrefix = 'Bearer'; + + setAccessToken(accessToken: string): void { + this.accessToken = accessToken; + } + + getAuthorizationHeader(): Headers { + const accessTokenAuth = { Authorization: `${this.accessTokenPrefix} ${this.accessToken}` }; + + return { ...accessTokenAuth }; + } + + setBaseUrl(url: string): void { + this.baseUrl = url; + } + + constructor(accessToken = '') { + this.setAccessToken(accessToken); + } + + static patternMatching(value: string, pattern: string, variableName: string): string { + if (!value) { + throw new Error(`${variableName} cannot be null or undefined`); + } + if (!value.match(new RegExp(pattern))) { + throw new Error(`Invalid value for ${variableName}: must match ${pattern}`); + } + return value; + } + + static urlEncode = (input: { [key: string]: any }): string => + Object.keys(input) + .map((key) => `${key}=${encodeURIComponent(input[key])}`) + .join('&'); +} diff --git a/packages/project-client/src/hooks/Hook.ts b/packages/project-client/src/hooks/Hook.ts new file mode 100644 index 000000000..443030bed --- /dev/null +++ b/packages/project-client/src/hooks/Hook.ts @@ -0,0 +1,28 @@ +export interface Request { + method: string; + url: string; + input?: object; + headers: object; +} + +export interface Response { + data: object; + headers: object; + status: number; +} + +export interface Exception extends Error { + title: string; + type?: string; + detail?: string; + instance?: string; + statusCode: number; +} + +export interface Hook { + beforeRequest(request: Request): Promise; + + afterResponse(request: Request, response: Response): Promise; + + onError(error: Exception): Promise; +} diff --git a/packages/project-client/src/http/Environment.ts b/packages/project-client/src/http/Environment.ts new file mode 100644 index 000000000..836b28fba --- /dev/null +++ b/packages/project-client/src/http/Environment.ts @@ -0,0 +1,3 @@ +export enum Environment { + DEFAULT = 'https://api.magicbell.com/v2', +} diff --git a/packages/project-client/src/http/HTTPClient.ts b/packages/project-client/src/http/HTTPClient.ts new file mode 100644 index 000000000..2a37df8eb --- /dev/null +++ b/packages/project-client/src/http/HTTPClient.ts @@ -0,0 +1,12 @@ +export interface Headers extends Record {} + +/** + * Defines the basic operations for an HTTP client. + */ +export default interface HTTPClient { + get(url: string, input: any, headers: Headers, retry?: boolean): Promise; + post(url: string, input: any, headers: Headers, retry?: boolean): Promise; + delete(url: string, input: any, headers: Headers, retry?: boolean): Promise; + put(url: string, input: any, headers: Headers, retry?: boolean): Promise; + patch(url: string, input: any, headers: Headers, retry?: boolean): Promise; +} diff --git a/packages/project-client/src/http/HTTPLibrary.ts b/packages/project-client/src/http/HTTPLibrary.ts new file mode 100644 index 000000000..427976c22 --- /dev/null +++ b/packages/project-client/src/http/HTTPLibrary.ts @@ -0,0 +1,159 @@ +import axios, { AxiosError } from 'axios'; + +import HTTPClient, { Headers } from './HTTPClient'; +import throwHttpError from './httpExceptions'; + +// Ignore TS errors when checking if we are running inside Deno or Bun +declare const Deno: any; +declare const Bun: any; + +export default class HTTPLibrary implements HTTPClient { + readonly retryAttempts: number = 3; + readonly retryDelayMs: number = 150; + + private static readonly responseMapper: Map = new Map([ + ['type', 'type_'], + ['from', 'from_'], + ]); + + private readonly requestMapper: Map = new Map([ + ['type_', 'type'], + ['from_', 'from'], + ]); + + async get(url: string, input: any, headers: Headers, retry = false): Promise { + const request = () => + axios.get(url, { + headers: { ...headers, ...this.getUserAgentHeader() }, + data: Object.keys(input).length > 0 ? HTTPLibrary.convertKeysWithMapper(input, this.requestMapper) : undefined, + }); + + const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); + return HTTPLibrary.handleResponse(response); + } + + async post(url: string, input: any, headers: Headers, retry = false): Promise { + const request = () => + axios.post(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { + headers: { ...headers, ...this.getUserAgentHeader() }, + }); + + const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); + + return HTTPLibrary.handleResponse(response); + } + + async delete(url: string, input: any, headers: Headers, retry = false): Promise { + const request = () => + axios.delete(url, { + headers: { ...headers, ...this.getUserAgentHeader() }, + data: HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), + }); + + const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); + + return HTTPLibrary.handleResponse(response); + } + + async put(url: string, input: any, headers: Headers, retry = false): Promise { + const request = () => + axios.put(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { + headers: { ...headers, ...this.getUserAgentHeader() }, + }); + + const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); + + return HTTPLibrary.handleResponse(response); + } + + async patch(url: string, input: any, headers: Headers, retry = false): Promise { + const request = () => + axios.patch(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { + headers: { ...headers, ...this.getUserAgentHeader() }, + }); + + const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); + + return HTTPLibrary.handleResponse(response); + } + + async retry(retries: number, callbackFn: () => any, delay: number): Promise { + let result: any; + + try { + result = await callbackFn(); + } catch (e: any) { + if ((e as AxiosError).isAxiosError) { + if (e.response) { + if (![500, 503, 504].includes(e.response.status)) { + return e.response; + } + } + } + if (retries > 1) { + // eslint-disable-next-line no-promise-executor-return + await new Promise((resolve) => setTimeout(resolve, delay)); + result = await this.retry(retries - 1, callbackFn, delay * 2); + } else { + throw e; + } + } + + return result; + } + + private static handleResponse(response: any) { + if (response.status >= 400) { + throwHttpError(response); + } + + response.data = HTTPLibrary.convertKeysWithMapper(response.data, this.responseMapper); + + return response; + } + + private getUserAgentHeader(): Headers { + const userAgentBase = 'Client/0.1.0'; + + let userAgent = ''; + if (typeof window !== 'undefined') { + return {}; + } else if (typeof process !== 'undefined') { + userAgent = `Node.js/${process.version} ${userAgentBase}`; + } else if (typeof Deno !== 'undefined') { + userAgent = `Deno/${Deno.version.deno} ${userAgentBase}`; + } else if (typeof Bun !== 'undefined') { + userAgent = `Bun/${Bun.version} ${userAgentBase}`; + } else { + userAgent = userAgentBase; + } + + return { 'User-Agent': userAgent }; + } + + /** + *Converts keys in an object using a provided JSON mapper. + * @param {any} obj - The object to convert keys for. + * @param {Object} jsonMapper - The JSON mapper containing key mappings. + * @returns {any} - The object with converted keys. + */ + private static convertKeysWithMapper(obj: T, jsonMapper: Map): any { + if (!obj || typeof obj !== 'object') { + return obj; + } + + if (Array.isArray(obj)) { + return obj.map((item) => HTTPLibrary.convertKeysWithMapper(item, jsonMapper)); + } + + const convertedObj: Record = {}; + Object.entries(obj).forEach(([key, value]) => { + if (value !== undefined) { + const convertedKey = jsonMapper.get(key) || key; + convertedObj[convertedKey] = HTTPLibrary.convertKeysWithMapper(value, jsonMapper); + } + }); + + return convertedObj; + } +} diff --git a/packages/project-client/src/http/QuerySerializer.ts b/packages/project-client/src/http/QuerySerializer.ts new file mode 100644 index 000000000..2cdb72f58 --- /dev/null +++ b/packages/project-client/src/http/QuerySerializer.ts @@ -0,0 +1,40 @@ +export type Explode = boolean; +export type QueryStyles = 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject'; +export type PathStyles = 'simple' | 'label' | 'matrix'; + +const styleMethods: Record = { + simple: (value: unknown, explode: boolean) => { + // Check if the value is an array + if (Array.isArray(value)) { + return explode ? value.join(',') : value.join(); + } + + // Check if the value is an object + if (typeof value === 'object' && value !== null) { + if (explode) { + // Serialize object with exploded format: "key=value,key2=value2" + return Object.entries(value) + .map(([parameterName, parameterValue]) => `${parameterName}=${parameterValue}`) + .join(','); + } + // Serialize object with non-exploded format: "key,value,key2,value2" + return Object.entries(value) + .flatMap(([parameterName, parameterValue]) => [parameterName, parameterValue]) + .join(','); + } + + // For primitive values + return String(value); + }, +}; + +export function serializePath(style: PathStyles, explode: Explode, value: unknown, key?: string): string { + const method = styleMethods[style]; + if (!method) return ''; + // The `simple` and `label` styles do not require a `key` + if (!key) { + return method(value, explode); + } else { + return method(key, value, explode); + } +} diff --git a/packages/project-client/src/http/errors/BadGateway.ts b/packages/project-client/src/http/errors/BadGateway.ts new file mode 100644 index 000000000..604658808 --- /dev/null +++ b/packages/project-client/src/http/errors/BadGateway.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class BadGateway extends BaseHTTPError { + statusCode = 502; + + title = 'Bad Gateway'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/BadRequest.ts b/packages/project-client/src/http/errors/BadRequest.ts new file mode 100644 index 000000000..cefa85bf4 --- /dev/null +++ b/packages/project-client/src/http/errors/BadRequest.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class BadRequest extends BaseHTTPError { + statusCode = 400; + + title = 'Bad Request'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/Conflict.ts b/packages/project-client/src/http/errors/Conflict.ts new file mode 100644 index 000000000..d11577ee4 --- /dev/null +++ b/packages/project-client/src/http/errors/Conflict.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class Conflict extends BaseHTTPError { + statusCode = 409; + + title = 'Conflict'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/ExpectationFailed.ts b/packages/project-client/src/http/errors/ExpectationFailed.ts new file mode 100644 index 000000000..69704d5cd --- /dev/null +++ b/packages/project-client/src/http/errors/ExpectationFailed.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class ExpectationFailed extends BaseHTTPError { + statusCode = 417; + + title = 'Expectation Failed'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/FailedDependency.ts b/packages/project-client/src/http/errors/FailedDependency.ts new file mode 100644 index 000000000..3e753de3f --- /dev/null +++ b/packages/project-client/src/http/errors/FailedDependency.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class FailedDependency extends BaseHTTPError { + statusCode = 424; + + title = 'Failed Dependency'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/Forbidden.ts b/packages/project-client/src/http/errors/Forbidden.ts new file mode 100644 index 000000000..a6172ca5b --- /dev/null +++ b/packages/project-client/src/http/errors/Forbidden.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class Forbidden extends BaseHTTPError { + statusCode = 403; + + title = 'Forbidden'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/GatewayTimeout.ts b/packages/project-client/src/http/errors/GatewayTimeout.ts new file mode 100644 index 000000000..74b358567 --- /dev/null +++ b/packages/project-client/src/http/errors/GatewayTimeout.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class GatewayTimeout extends BaseHTTPError { + statusCode = 504; + + title = 'Gateway Timeout'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/Gone.ts b/packages/project-client/src/http/errors/Gone.ts new file mode 100644 index 000000000..83ddffbc5 --- /dev/null +++ b/packages/project-client/src/http/errors/Gone.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class Gone extends BaseHTTPError { + statusCode = 410; + + title = 'Gone'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/HttpVersionNotSupported.ts b/packages/project-client/src/http/errors/HttpVersionNotSupported.ts new file mode 100644 index 000000000..7c9619456 --- /dev/null +++ b/packages/project-client/src/http/errors/HttpVersionNotSupported.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class HttpVersionNotSupported extends BaseHTTPError { + statusCode = 505; + + title = 'HTTP Version Not Supported'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/InternalServerError.ts b/packages/project-client/src/http/errors/InternalServerError.ts new file mode 100644 index 000000000..b93f1fd35 --- /dev/null +++ b/packages/project-client/src/http/errors/InternalServerError.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class InternalServerError extends BaseHTTPError { + statusCode = 500; + + title = 'Internal Server Error'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/LengthRequired.ts b/packages/project-client/src/http/errors/LengthRequired.ts new file mode 100644 index 000000000..12be92a99 --- /dev/null +++ b/packages/project-client/src/http/errors/LengthRequired.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class LengthRequired extends BaseHTTPError { + statusCode = 411; + + title = 'LengthRequired'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/Locked.ts b/packages/project-client/src/http/errors/Locked.ts new file mode 100644 index 000000000..da78abb28 --- /dev/null +++ b/packages/project-client/src/http/errors/Locked.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class Locked extends BaseHTTPError { + statusCode = 423; + + title = 'Locked'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/LoopDetected.ts b/packages/project-client/src/http/errors/LoopDetected.ts new file mode 100644 index 000000000..b62c383a4 --- /dev/null +++ b/packages/project-client/src/http/errors/LoopDetected.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class LoopDetected extends BaseHTTPError { + statusCode = 508; + + title = 'Loop Detected'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/MethodNotAllowed.ts b/packages/project-client/src/http/errors/MethodNotAllowed.ts new file mode 100644 index 000000000..fa86ff5e6 --- /dev/null +++ b/packages/project-client/src/http/errors/MethodNotAllowed.ts @@ -0,0 +1,14 @@ +import { BaseHTTPError } from './base'; + +export default class MethodNotAllowed extends BaseHTTPError { + statusCode = 405; + + title = 'Method Not Allowed'; + + allow?: string[]; + + constructor(detail = '', allow?: string[]) { + super(detail); + this.allow = allow; + } +} diff --git a/packages/project-client/src/http/errors/MisdirectedRequest.ts b/packages/project-client/src/http/errors/MisdirectedRequest.ts new file mode 100644 index 000000000..1ceb1d5d5 --- /dev/null +++ b/packages/project-client/src/http/errors/MisdirectedRequest.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class MisdirectedRequest extends BaseHTTPError { + statusCode = 421; + + title = 'Misdirected Request'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts b/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts new file mode 100644 index 000000000..26a962745 --- /dev/null +++ b/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class NetworkAuthenticationRequired extends BaseHTTPError { + statusCode = 511; + + title = 'Network Authentication Required'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/NotAcceptable.ts b/packages/project-client/src/http/errors/NotAcceptable.ts new file mode 100644 index 000000000..408df59a9 --- /dev/null +++ b/packages/project-client/src/http/errors/NotAcceptable.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class NotAcceptable extends BaseHTTPError { + statusCode = 406; + + title = 'Not Acceptable'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/NotExtended.ts b/packages/project-client/src/http/errors/NotExtended.ts new file mode 100644 index 000000000..ec3ddd852 --- /dev/null +++ b/packages/project-client/src/http/errors/NotExtended.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class NotExtended extends BaseHTTPError { + statusCode = 510; + + title = 'Not Extended'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/NotFound.ts b/packages/project-client/src/http/errors/NotFound.ts new file mode 100644 index 000000000..fdf9198e2 --- /dev/null +++ b/packages/project-client/src/http/errors/NotFound.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class NotFound extends BaseHTTPError { + statusCode = 404; + + title = 'Not Found'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/NotImplemented.ts b/packages/project-client/src/http/errors/NotImplemented.ts new file mode 100644 index 000000000..a286272d2 --- /dev/null +++ b/packages/project-client/src/http/errors/NotImplemented.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class NotImplemented extends BaseHTTPError { + statusCode = 501; + + title = 'Not Implemented'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/PayloadTooLarge.ts b/packages/project-client/src/http/errors/PayloadTooLarge.ts new file mode 100644 index 000000000..98ddc60e5 --- /dev/null +++ b/packages/project-client/src/http/errors/PayloadTooLarge.ts @@ -0,0 +1,14 @@ +import { BaseHTTPError } from './base'; + +export default class PayloadTooLarge extends BaseHTTPError { + statusCode = 413; + + title = 'Payload Too Large'; + + retryAfter: number | null; + + constructor(detail = '', retryAfter: number | null = null) { + super(detail); + this.retryAfter = retryAfter; + } +} diff --git a/packages/project-client/src/http/errors/PaymentRequired.ts b/packages/project-client/src/http/errors/PaymentRequired.ts new file mode 100644 index 000000000..8951b7b51 --- /dev/null +++ b/packages/project-client/src/http/errors/PaymentRequired.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class PaymentRequired extends BaseHTTPError { + statusCode = 402; + + title = 'Payment Required'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/PreconditionFailed.ts b/packages/project-client/src/http/errors/PreconditionFailed.ts new file mode 100644 index 000000000..c7bee9104 --- /dev/null +++ b/packages/project-client/src/http/errors/PreconditionFailed.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class PreconditionFailed extends BaseHTTPError { + statusCode = 412; + + title = 'PreconditionFailed'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/PreconditionRequired.ts b/packages/project-client/src/http/errors/PreconditionRequired.ts new file mode 100644 index 000000000..983d50523 --- /dev/null +++ b/packages/project-client/src/http/errors/PreconditionRequired.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class PreconditionRequired extends BaseHTTPError { + statusCode = 428; + + title = 'Precondition Required'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts b/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts new file mode 100644 index 000000000..814545fac --- /dev/null +++ b/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts @@ -0,0 +1,14 @@ +import { AuthenticateChallenge, BaseHTTPError } from './base'; + +export default class ProxyAuthenticationRequired extends BaseHTTPError { + statusCode = 407; + + title = 'Proxy Authentication Required'; + + proxyAuthenticate?: AuthenticateChallenge; + + constructor(detail = '', proxyAuthenticate?: AuthenticateChallenge) { + super(detail); + this.proxyAuthenticate = proxyAuthenticate; + } +} diff --git a/packages/project-client/src/http/errors/RangeNotSatisfiable.ts b/packages/project-client/src/http/errors/RangeNotSatisfiable.ts new file mode 100644 index 000000000..8cb2efc1a --- /dev/null +++ b/packages/project-client/src/http/errors/RangeNotSatisfiable.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class RangeNotSatisfiable extends BaseHTTPError { + statusCode = 416; + + title = 'Range Not Satisfiable'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts b/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts new file mode 100644 index 000000000..16000c75b --- /dev/null +++ b/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class RequestHeaderFieldsTooLarge extends BaseHTTPError { + statusCode = 431; + + title = 'Request Header Fields Too Large'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/RequestTimeout.ts b/packages/project-client/src/http/errors/RequestTimeout.ts new file mode 100644 index 000000000..68949280c --- /dev/null +++ b/packages/project-client/src/http/errors/RequestTimeout.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class RequestTimeout extends BaseHTTPError { + statusCode = 408; + + title = 'Request Timeout'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/ServiceUnavailable.ts b/packages/project-client/src/http/errors/ServiceUnavailable.ts new file mode 100644 index 000000000..b7ce5b201 --- /dev/null +++ b/packages/project-client/src/http/errors/ServiceUnavailable.ts @@ -0,0 +1,14 @@ +import { BaseHTTPError } from './base'; + +export default class ServiceUnavailable extends BaseHTTPError { + statusCode = 503; + + title = 'Service Unavailable'; + + retryAfter: number | null; + + constructor(detail = '', retryAfter: number | null = null) { + super(detail); + this.retryAfter = retryAfter; + } +} diff --git a/packages/project-client/src/http/errors/TooEarly.ts b/packages/project-client/src/http/errors/TooEarly.ts new file mode 100644 index 000000000..c870167ae --- /dev/null +++ b/packages/project-client/src/http/errors/TooEarly.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class TooEarly extends BaseHTTPError { + statusCode = 425; + + title = 'Too Early'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/TooManyRequests.ts b/packages/project-client/src/http/errors/TooManyRequests.ts new file mode 100644 index 000000000..ec7f76055 --- /dev/null +++ b/packages/project-client/src/http/errors/TooManyRequests.ts @@ -0,0 +1,14 @@ +import { BaseHTTPError } from './base'; + +export default class TooManyRequests extends BaseHTTPError { + statusCode = 429; + + title = 'Too Many Requests'; + + retryAfter: number | null; + + constructor(detail = '', retryAfter: number | null = null) { + super(detail); + this.retryAfter = retryAfter; + } +} diff --git a/packages/project-client/src/http/errors/Unauthorized.ts b/packages/project-client/src/http/errors/Unauthorized.ts new file mode 100644 index 000000000..0edb7d0a3 --- /dev/null +++ b/packages/project-client/src/http/errors/Unauthorized.ts @@ -0,0 +1,14 @@ +import { AuthenticateChallenge, BaseHTTPError } from './base'; + +export default class Unauthorized extends BaseHTTPError { + statusCode = 401; + + title = 'Unauthorized'; + + wwwAuthenticate?: AuthenticateChallenge; + + constructor(detail = '', wwwAuthenticate?: AuthenticateChallenge) { + super(detail); + this.wwwAuthenticate = wwwAuthenticate; + } +} diff --git a/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts b/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts new file mode 100644 index 000000000..27aef0e04 --- /dev/null +++ b/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UnavailableForLegalReasons extends BaseHTTPError { + statusCode = 451; + + title = 'Unavailable For Legal Reasons'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/UnprocessableEntity.ts b/packages/project-client/src/http/errors/UnprocessableEntity.ts new file mode 100644 index 000000000..9b0713cd1 --- /dev/null +++ b/packages/project-client/src/http/errors/UnprocessableEntity.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UnprocessableEntity extends BaseHTTPError { + statusCode = 422; + + title = 'Unprocessable Entity'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/UnsufficientStorage.ts b/packages/project-client/src/http/errors/UnsufficientStorage.ts new file mode 100644 index 000000000..07179cf6c --- /dev/null +++ b/packages/project-client/src/http/errors/UnsufficientStorage.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UnsufficientStorage extends BaseHTTPError { + statusCode = 507; + + title = 'Unsufficient Storage'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/UnsupportedMediaType.ts b/packages/project-client/src/http/errors/UnsupportedMediaType.ts new file mode 100644 index 000000000..1c8777725 --- /dev/null +++ b/packages/project-client/src/http/errors/UnsupportedMediaType.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UnsupportedMediaType extends BaseHTTPError { + statusCode = 415; + + title = 'Unsupported Media Type'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/UpgradeRequired.ts b/packages/project-client/src/http/errors/UpgradeRequired.ts new file mode 100644 index 000000000..dee381703 --- /dev/null +++ b/packages/project-client/src/http/errors/UpgradeRequired.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UpgradeRequired extends BaseHTTPError { + statusCode = 426; + + title = 'Upgrade Required'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/UriTooLong.ts b/packages/project-client/src/http/errors/UriTooLong.ts new file mode 100644 index 000000000..ce46ea64c --- /dev/null +++ b/packages/project-client/src/http/errors/UriTooLong.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class UriTooLong extends BaseHTTPError { + statusCode = 414; + + title = 'URI Too Long'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts b/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts new file mode 100644 index 000000000..275e9528c --- /dev/null +++ b/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts @@ -0,0 +1,11 @@ +import { BaseHTTPError } from './base'; + +export default class VariantAlsoNegotiates extends BaseHTTPError { + statusCode = 506; + + title = 'Variant Also Negotiates'; + + constructor(detail = '') { + super(detail); + } +} diff --git a/packages/project-client/src/http/errors/base.ts b/packages/project-client/src/http/errors/base.ts new file mode 100644 index 000000000..d41d9c30e --- /dev/null +++ b/packages/project-client/src/http/errors/base.ts @@ -0,0 +1,52 @@ +export interface IHTTPError extends Error { + statusCode: number; +} + +export interface IHTTPErrorDescription extends IHTTPError { + type?: string; + title: string; + detail?: string; + instance?: string; +} + +export function isHTTPError(error: unknown): error is IHTTPError { + if (!error) { + return false; + } + return Number.isInteger((error as IHTTPError).statusCode); +} + +export function isHTTPIssue(error: unknown): error is IHTTPErrorDescription { + if (!error) { + return false; + } + return (error as IHTTPErrorDescription).title !== undefined && isHTTPError(error); +} + +export class BaseHTTPError extends Error implements IHTTPError { + public type?: string; + + public title = 'Internal Server Error'; + + public detail?: string; + + public instance?: string; + + public statusCode = 500; + + constructor(detail = '') { + super(detail || 'An Unknown HTTP Error Occurred'); + this.detail = detail; + this.stack = (new Error()).stack; + } +} + +export function isClientError(error: Error): boolean { + return isHTTPError(error); +} + +export function isServerError(e: Error): boolean { + return isHTTPError(e) && e.statusCode >= 500 && e.statusCode <= 599; +} + +export type AuthenticateChallenge = string | string[]; diff --git a/packages/project-client/src/http/errors/index.ts b/packages/project-client/src/http/errors/index.ts new file mode 100644 index 000000000..22607d349 --- /dev/null +++ b/packages/project-client/src/http/errors/index.ts @@ -0,0 +1,83 @@ +import BadGateway from './BadGateway'; +import BadRequest from './BadRequest'; +import { BaseHTTPError } from './base'; +import Conflict from './Conflict'; +import ExpectationFailed from './ExpectationFailed'; +import FailedDependency from './FailedDependency'; +import Forbidden from './Forbidden'; +import GatewayTimeout from './GatewayTimeout'; +import Gone from './Gone'; +import HttpVersionNotSupported from './HttpVersionNotSupported'; +import InternalServerError from './InternalServerError'; +import LengthRequired from './LengthRequired'; +import Locked from './Locked'; +import LoopDetected from './LoopDetected'; +import MethodNotAllowed from './MethodNotAllowed'; +import MisdirectedRequest from './MisdirectedRequest'; +import NetworkAuthenticationRequired from './NetworkAuthenticationRequired'; +import NotAcceptable from './NotAcceptable'; +import NotExtended from './NotExtended'; +import NotFound from './NotFound'; +import NotImplemented from './NotImplemented'; +import PayloadTooLarge from './PayloadTooLarge'; +import PaymentRequired from './PaymentRequired'; +import PreconditionFailed from './PreconditionFailed'; +import PreconditionRequired from './PreconditionRequired'; +import ProxyAuthenticationRequired from './ProxyAuthenticationRequired'; +import RangeNotSatisfiable from './RangeNotSatisfiable'; +import RequestHeaderFieldsTooLarge from './RequestHeaderFieldsTooLarge'; +import RequestTimeout from './RequestTimeout'; +import ServiceUnavailable from './ServiceUnavailable'; +import TooEarly from './TooEarly'; +import TooManyRequests from './TooManyRequests'; +import Unauthorized from './Unauthorized'; +import UnavailableForLegalReasons from './UnavailableForLegalReasons'; +import UnprocessableEntity from './UnprocessableEntity'; +import UnsufficientStorage from './UnsufficientStorage'; +import UnsupportedMediaType from './UnsupportedMediaType'; +import UpgradeRequired from './UpgradeRequired'; +import UriTooLong from './UriTooLong'; +import VariantAlsoNegotiates from './VariantAlsoNegotiates'; + +export { + BadGateway, + BadRequest, + BaseHTTPError, + Conflict, + ExpectationFailed, + FailedDependency, + Forbidden, + GatewayTimeout, + Gone, + HttpVersionNotSupported, + InternalServerError, + LengthRequired, + Locked, + LoopDetected, + MethodNotAllowed, + MisdirectedRequest, + NetworkAuthenticationRequired, + NotAcceptable, + NotExtended, + NotFound, + NotImplemented, + PayloadTooLarge, + PaymentRequired, + PreconditionFailed, + PreconditionRequired, + ProxyAuthenticationRequired, + RangeNotSatisfiable, + RequestHeaderFieldsTooLarge, + RequestTimeout, + ServiceUnavailable, + TooEarly, + TooManyRequests, + Unauthorized, + UnavailableForLegalReasons, + UnprocessableEntity, + UnsufficientStorage, + UnsupportedMediaType, + UpgradeRequired, + UriTooLong, + VariantAlsoNegotiates, +}; diff --git a/packages/project-client/src/http/httpExceptions.ts b/packages/project-client/src/http/httpExceptions.ts new file mode 100644 index 000000000..d36bbdaed --- /dev/null +++ b/packages/project-client/src/http/httpExceptions.ts @@ -0,0 +1,135 @@ +import { + BadGateway, + BadRequest, + BaseHTTPError, + Conflict, + ExpectationFailed, + FailedDependency, + Forbidden, + GatewayTimeout, + Gone, + HttpVersionNotSupported, + InternalServerError, + LengthRequired, + Locked, + LoopDetected, + MethodNotAllowed, + MisdirectedRequest, + NetworkAuthenticationRequired, + NotAcceptable, + NotExtended, + NotFound, + NotImplemented, + PayloadTooLarge, + PaymentRequired, + PreconditionFailed, + PreconditionRequired, + ProxyAuthenticationRequired, + RangeNotSatisfiable, + RequestHeaderFieldsTooLarge, + RequestTimeout, + ServiceUnavailable, + TooEarly, + TooManyRequests, + Unauthorized, + UnavailableForLegalReasons, + UnprocessableEntity, + UnsufficientStorage, + UnsupportedMediaType, + UpgradeRequired, + UriTooLong, + VariantAlsoNegotiates, +} from './errors'; + +interface HttpResponseWithError { + status: number; + headers: any; + data?: any; +} + +interface NumberToClass { + [key: number]: any; +} + +const statusCodeToErrorFunction: NumberToClass = { + 400: BadRequest, + 401: Unauthorized, + 402: PaymentRequired, + 403: Forbidden, + 404: NotFound, + 405: MethodNotAllowed, + 406: NotAcceptable, + 407: ProxyAuthenticationRequired, + 408: RequestTimeout, + 409: Conflict, + 410: Gone, + 411: LengthRequired, + 412: PreconditionFailed, + 413: PayloadTooLarge, + 414: UriTooLong, + 415: UnsupportedMediaType, + 416: RangeNotSatisfiable, + 417: ExpectationFailed, + 421: MisdirectedRequest, + 422: UnprocessableEntity, + 423: Locked, + 424: FailedDependency, + 425: TooEarly, + 426: UpgradeRequired, + 428: PreconditionRequired, + 429: TooManyRequests, + 431: RequestHeaderFieldsTooLarge, + 451: UnavailableForLegalReasons, + 500: InternalServerError, + 501: NotImplemented, + 502: BadGateway, + 503: ServiceUnavailable, + 504: GatewayTimeout, + 505: HttpVersionNotSupported, + 506: VariantAlsoNegotiates, + 507: UnsufficientStorage, + 508: LoopDetected, + 510: NotExtended, + 511: NetworkAuthenticationRequired, +}; + +/** + * @summary This function will throw an error. + * + * @param {HttpResponseWithError} response - the response from a request, must contain a status and data fields + * @throws {Error} - an http error + */ +export default function throwHttpError(response: HttpResponseWithError): never { + let error: BaseHTTPError = new BaseHTTPError(response.data); + switch (response.status) { + case 401: + error = new Unauthorized(response.data, response.headers['WWW-Authenticate']); + break; + case 405: + // this indicates a bug in the spec if it allows a method that the server rejects + error = new MethodNotAllowed(response.data, response.headers.allowed); + break; + case 407: + error = new ProxyAuthenticationRequired(response.data, response.headers['Proxy-Authenticate']); + break; + case 413: + error = new PayloadTooLarge(response.data, response.headers['Retry-After']); + break; + case 429: + error = new TooManyRequests(response.data, response.headers['Retry-After']); + break; + case 503: + error = new ServiceUnavailable(response.data, response.headers['Retry-After']); + break; + default: + if (response.status in statusCodeToErrorFunction) { + error = new statusCodeToErrorFunction[response.status](response.data); + } else { + const error = new BaseHTTPError(response.data); + error.statusCode = response.status; + error.title = 'unknown error'; + } + } + + throw error; +} diff --git a/packages/project-client/src/index.ts b/packages/project-client/src/index.ts new file mode 100644 index 000000000..c29ba6480 --- /dev/null +++ b/packages/project-client/src/index.ts @@ -0,0 +1,51 @@ +import { BroadcastsService } from './services/broadcasts/Broadcasts'; +import { ChannelsService } from './services/channels/Channels'; +import { IntegrationsService } from './services/integrations/Integrations'; + +export * from './models'; +export * as BroadcastsModels from './services/broadcasts'; +export * as ChannelsModels from './services/channels'; +export * as IntegrationsModels from './services/integrations'; + +type Config = { + accessToken?: string; +}; + +export * from './http/errors'; + +/** + * OpenAPI 3.1.0 Specification for MagicBell API. + */ +export class Client { + public broadcasts: BroadcastsService; + public channels: ChannelsService; + public integrations: IntegrationsService; + + constructor({ accessToken = '' }: Config) { + this.broadcasts = new BroadcastsService(accessToken); + this.channels = new ChannelsService(accessToken); + this.integrations = new IntegrationsService(accessToken); + } + + /** + * Sets the baseUrl that the SDK will use for its requests. + * @param {string} url + */ + setBaseUrl(url: string): void { + this.broadcasts.setBaseUrl(url); + this.channels.setBaseUrl(url); + this.integrations.setBaseUrl(url); + } + + /** + * Sets the access token used to authenticate. + * @param {string} accessToken + */ + setAccessToken(accessToken: string) { + this.broadcasts.setAccessToken(accessToken); + this.channels.setAccessToken(accessToken); + this.integrations.setAccessToken(accessToken); + } +} + +// c029837e0e474b76bc487506e8799df5e3335891efe4fb02bda7a1441840310c diff --git a/packages/project-client/src/models.ts b/packages/project-client/src/models.ts new file mode 100644 index 000000000..fe5b5ca50 --- /dev/null +++ b/packages/project-client/src/models.ts @@ -0,0 +1,44 @@ +export type { Broadcast } from './services/broadcasts/models/Broadcast'; +export type { BroadcastListResponse } from './services/broadcasts/models/BroadcastListResponse'; +export type { CreateBroadcastRequest } from './services/broadcasts/models/CreateBroadcastRequest'; +export type { Topic } from './services/broadcasts/models/Topic'; +export type { User } from './services/broadcasts/models/User'; +export type { ApnsToken } from './services/channels/models/ApnsToken'; +export type { ApnsTokenWithMetadata } from './services/channels/models/ApnsTokenWithMetadata'; +export type { ArrayWithMetadataOfApnsToken } from './services/channels/models/ArrayWithMetadataOfApnsToken'; +export type { ArrayWithMetadataOfFcmToken } from './services/channels/models/ArrayWithMetadataOfFcmToken'; +export type { ArrayWithMetadataOfSlackToken } from './services/channels/models/ArrayWithMetadataOfSlackToken'; +export type { ArrayWithMetadataOfTeamsToken } from './services/channels/models/ArrayWithMetadataOfTeamsToken'; +export type { ArrayWithMetadataOfWebPushToken } from './services/channels/models/ArrayWithMetadataOfWebPushToken'; +export type { DiscardResult } from './services/channels/models/DiscardResult'; +export type { FcmToken } from './services/channels/models/FcmToken'; +export type { FcmTokenWithMetadata } from './services/channels/models/FcmTokenWithMetadata'; +export type { SlackToken } from './services/channels/models/SlackToken'; +export type { SlackTokenWithMetadata } from './services/channels/models/SlackTokenWithMetadata'; +export type { TeamsToken } from './services/channels/models/TeamsToken'; +export type { TeamsTokenWithMetadata } from './services/channels/models/TeamsTokenWithMetadata'; +export type { WebPushToken } from './services/channels/models/WebPushToken'; +export type { WebPushTokenWithMetadata } from './services/channels/models/WebPushTokenWithMetadata'; +export type { ApnsConfig } from './services/integrations/models/ApnsConfig'; +export type { FcmConfig } from './services/integrations/models/FcmConfig'; +export type { InboxConfig } from './services/integrations/models/InboxConfig'; +export type { ListIntegrationsResponse } from './services/integrations/models/ListIntegrationsResponse'; +export type { MailgunConfig } from './services/integrations/models/MailgunConfig'; +export type { PingConfig } from './services/integrations/models/PingConfig'; +export type { SaveApnsIntegrationRequest } from './services/integrations/models/SaveApnsIntegrationRequest'; +export type { SaveFcmIntegrationRequest } from './services/integrations/models/SaveFcmIntegrationRequest'; +export type { SaveInboxIntegrationRequest } from './services/integrations/models/SaveInboxIntegrationRequest'; +export type { SaveMailgunIntegrationRequest } from './services/integrations/models/SaveMailgunIntegrationRequest'; +export type { SavePingEmailIntegrationRequest } from './services/integrations/models/SavePingEmailIntegrationRequest'; +export type { SaveSendgridIntegrationRequest } from './services/integrations/models/SaveSendgridIntegrationRequest'; +export type { SaveSlackIntegrationRequest } from './services/integrations/models/SaveSlackIntegrationRequest'; +export type { SaveStripeIntegrationRequest } from './services/integrations/models/SaveStripeIntegrationRequest'; +export type { SaveTemplatesIntegrationRequest } from './services/integrations/models/SaveTemplatesIntegrationRequest'; +export type { SaveTemplatesIntegrationResponse } from './services/integrations/models/SaveTemplatesIntegrationResponse'; +export type { SaveTwilioIntegrationRequest } from './services/integrations/models/SaveTwilioIntegrationRequest'; +export type { SaveWebPushIntegrationRequest } from './services/integrations/models/SaveWebPushIntegrationRequest'; +export type { SendgridConfig } from './services/integrations/models/SendgridConfig'; +export type { SlackConfig } from './services/integrations/models/SlackConfig'; +export type { StripeConfig } from './services/integrations/models/StripeConfig'; +export type { TwilioConfig } from './services/integrations/models/TwilioConfig'; +export type { WebpushConfig } from './services/integrations/models/WebpushConfig'; diff --git a/packages/project-client/src/services/README.md b/packages/project-client/src/services/README.md new file mode 100644 index 000000000..dfaf8391a --- /dev/null +++ b/packages/project-client/src/services/README.md @@ -0,0 +1,1254 @@ +# Client Services + +A list of all services and services methods. + +- Services + + - [Broadcasts](#broadcasts) + + - [Integrations](#integrations) + + - [Channels](#channels) + +- [All Methods](#all-methods) + +## Broadcasts + +| Method | Description | +| :---------------------------------- | :---------- | +| [createBroadcast](#createbroadcast) | | +| [listBroadcasts](#listbroadcasts) | | +| [fetchBroadcast](#fetchbroadcast) | | + +## Integrations + +| Method | Description | +| :-------------------------------------------------------- | :---------- | +| [listIntegrations](#listintegrations) | | +| [deleteApnsIntegration](#deleteapnsintegration) | | +| [saveApnsIntegration](#saveapnsintegration) | | +| [deleteFcmIntegration](#deletefcmintegration) | | +| [saveFcmIntegration](#savefcmintegration) | | +| [deleteInboxIntegration](#deleteinboxintegration) | | +| [saveInboxIntegration](#saveinboxintegration) | | +| [deleteMailgunIntegration](#deletemailgunintegration) | | +| [saveMailgunIntegration](#savemailgunintegration) | | +| [deletePingEmailIntegration](#deletepingemailintegration) | | +| [savePingEmailIntegration](#savepingemailintegration) | | +| [deleteSendgridIntegration](#deletesendgridintegration) | | +| [saveSendgridIntegration](#savesendgridintegration) | | +| [deleteSlackIntegration](#deleteslackintegration) | | +| [saveSlackIntegration](#saveslackintegration) | | +| [deleteStripeIntegration](#deletestripeintegration) | | +| [saveStripeIntegration](#savestripeintegration) | | +| [deleteTemplatesIntegration](#deletetemplatesintegration) | | +| [saveTemplatesIntegration](#savetemplatesintegration) | | +| [deleteTwilioIntegration](#deletetwiliointegration) | | +| [saveTwilioIntegration](#savetwiliointegration) | | +| [deleteWebPushIntegration](#deletewebpushintegration) | | +| [saveWebPushIntegration](#savewebpushintegration) | | + +## Channels + +| Method | Description | +| :---------------------------------------------------------------- | :---------- | +| [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | | +| [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | | +| [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | | +| [getMobilePushFcmUserTokens](#getmobilepushfcmusertokens) | | +| [getMobilePushFcmUserToken](#getmobilepushfcmusertoken) | | +| [discardMobilePushFcmUserToken](#discardmobilepushfcmusertoken) | | +| [getSlackUserTokens](#getslackusertokens) | | +| [getSlackUserToken](#getslackusertoken) | | +| [discardSlackUserToken](#discardslackusertoken) | | +| [getTeamsUserTokens](#getteamsusertokens) | | +| [getTeamsUserToken](#getteamsusertoken) | | +| [discardTeamsUserToken](#discardteamsusertoken) | | +| [getWebPushUserTokens](#getwebpushusertokens) | | +| [getWebPushUserToken](#getwebpushusertoken) | | +| [discardWebPushUserToken](#discardwebpushusertoken) | | + +## All Methods + +### **createBroadcast** + +- HTTP Method: POST +- Endpoint: /broadcasts + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +Broadcast + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + action_url: 'https://example.com', + category: 'example', + content: 'Hello, World!', + custom_attributes: {}, + overrides: {}, + recipients: [ + { + custom_attributes: { + plan: 'enterprise', + preferred_pronoun: 'They', + pricing_version: 'v10', + }, + external_id: '83d987a-83fd034', + first_name: 'Person', + last_name: 'Doe', + phone_numbers: ['+1 5005550001'], + }, + ], + title: 'Hello, World!', + topic: 'example', + }; + const result = await sdk.broadcasts.createBroadcast(input); + console.log(result); +})(); + +``` + +### **listBroadcasts** + +- HTTP Method: GET +- Endpoint: /broadcasts + +**Return Type** + +BroadcastListResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.broadcasts.listBroadcasts(); + console.log(result); +})(); + +``` + +### **fetchBroadcast** + +- HTTP Method: GET +- Endpoint: /broadcasts/{broadcast_id} + +**Required Parameters** + +| Name | Type | Description | +| :---------- | :----- | :---------- | +| broadcastId | string | | + +**Return Type** + +Broadcast + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.broadcasts.fetchBroadcast('broadcast_id'); + console.log(result); +})(); + +``` + +### **listIntegrations** + +- HTTP Method: GET +- Endpoint: /integrations + +**Return Type** + +ListIntegrationsResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.listIntegrations(); + console.log(result); +})(); + +``` + +### **deleteApnsIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/apns + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteApnsIntegration(); + console.log(result); +})(); + +``` + +### **saveApnsIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/apns + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +ApnsConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }; + const result = await sdk.integrations.saveApnsIntegration(input); + console.log(result); +})(); + +``` + +### **deleteFcmIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/fcm + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteFcmIntegration(); + console.log(result); +})(); + +``` + +### **saveFcmIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/fcm + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +FcmConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + auth_provider_x509_cert_url: '', + auth_uri: '', + client_email: '', + client_id: '', + client_x509_cert_url: '', + private_key: + '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQ8J\n-----END PRIVATE', + private_key_id: 'e7', + project_id: 'universe-1', + token_uri: '', + type: 'service_account', + universe_domain: 'universe-1.firebaseapp.com', + }; + const result = await sdk.integrations.saveFcmIntegration(input); + console.log(result); +})(); + +``` + +### **deleteInboxIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/inbox + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteInboxIntegration(); + console.log(result); +})(); + +``` + +### **saveInboxIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/inbox + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +InboxConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + apns: { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }, + }; + const result = await sdk.integrations.saveInboxIntegration(input); + console.log(result); +})(); + +``` + +### **deleteMailgunIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/mailgun + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteMailgunIntegration(); + console.log(result); +})(); + +``` + +### **saveMailgunIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/mailgun + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +MailgunConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { api_key: 'mailgun_api_key', domain: 'mailgun_domain', region: 'us' }; + const result = await sdk.integrations.saveMailgunIntegration(input); + console.log(result); +})(); + +``` + +### **deletePingEmailIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/ping_email + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deletePingEmailIntegration(); + console.log(result); +})(); + +``` + +### **savePingEmailIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/ping_email + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +PingConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { url: 'https://example.com/webhook' }; + const result = await sdk.integrations.savePingEmailIntegration(input); + console.log(result); +})(); + +``` + +### **deleteSendgridIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/sendgrid + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteSendgridIntegration(); + console.log(result); +})(); + +``` + +### **saveSendgridIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/sendgrid + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SendgridConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + api_key: 'SG.1234567890', + from: { email: 'matt@magicbell.com', name: 'Matt' }, + reply_to: { email: 'hana@magicbell.com', name: 'Hana' }, + }; + const result = await sdk.integrations.saveSendgridIntegration(input); + console.log(result); +})(); + +``` + +### **deleteSlackIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/slack + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteSlackIntegration(); + console.log(result); +})(); + +``` + +### **saveSlackIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/slack + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SlackConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + app_id: '12345678901', + client_id: '1.0', + client_secret: '12345678901234567890123456789012', + signing_secret: '12345678901234567890123456789012', + }; + const result = await sdk.integrations.saveSlackIntegration(input); + console.log(result); +})(); + +``` + +### **deleteStripeIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/stripe + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteStripeIntegration(); + console.log(result); +})(); + +``` + +### **saveStripeIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/stripe + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +StripeConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + webhook_signing_secret: + 'whsec_e5cf4458caae49ae72d8f275deb9b63bdd41dd5c932c27c9346d428fb9e1d0a0', + }; + const result = await sdk.integrations.saveStripeIntegration(input); + console.log(result); +})(); + +``` + +### **deleteTemplatesIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/templates + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteTemplatesIntegration(); + console.log(result); +})(); + +``` + +### **saveTemplatesIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/templates + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +SaveTemplatesIntegrationResponse + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + apns: { + app_id: 'com.example.myapp', + badge: 'unread', + certificate: 'MIICXQIBAAKBgQC3J2', + key_id: 'ABCD1234EF', + team_id: 'ABCD1234EF', + }, + }; + const result = await sdk.integrations.saveTemplatesIntegration(input); + console.log(result); +})(); + +``` + +### **deleteTwilioIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/twilio + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteTwilioIntegration(); + console.log(result); +})(); + +``` + +### **saveTwilioIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/twilio + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +TwilioConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { + account_sid: 'ACXXXXXXXX', + api_key: 'SKXXXXXXXX', + api_secret: 'your_api_secret', + from: '+15017122661', + region: 'us1', + }; + const result = await sdk.integrations.saveTwilioIntegration(input); + console.log(result); +})(); + +``` + +### **deleteWebPushIntegration** + +- HTTP Method: DELETE +- Endpoint: /integrations/web_push + +**Return Type** + +Returns a dict object. + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.integrations.deleteWebPushIntegration(); + console.log(result); +})(); + +``` + +### **saveWebPushIntegration** + +- HTTP Method: PUT +- Endpoint: /integrations/web_push + +**Required Parameters** + +| input | object | Request body. | + +**Return Type** + +WebpushConfig + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const input = { private_key: '', public_key: '' }; + const result = await sdk.integrations.saveWebPushIntegration(input); + console.log(result); +})(); + +``` + +### **getMobilePushApnsUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfApnsToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushApnsUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getMobilePushApnsUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +ApnsTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushApnsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardMobilePushApnsUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardMobilePushApnsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getMobilePushFcmUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfFcmToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushFcmUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getMobilePushFcmUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +FcmTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getMobilePushFcmUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardMobilePushFcmUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardMobilePushFcmUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getSlackUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/slack/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfSlackToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getSlackUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getSlackUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +SlackTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getSlackUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardSlackUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardSlackUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getTeamsUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/teams/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfTeamsToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getTeamsUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getTeamsUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +TeamsTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getTeamsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardTeamsUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardTeamsUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **getWebPushUserTokens** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/web_push/tokens + +**Required Parameters** + +| Name | Type | Description | +| :----- | :----- | :---------- | +| userId | string | | + +**Return Type** + +ArrayWithMetadataOfWebPushToken + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getWebPushUserTokens('user_id'); + console.log(result); +})(); + +``` + +### **getWebPushUserToken** + +- HTTP Method: GET +- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +WebPushTokenWithMetadata + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.getWebPushUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` + +### **discardWebPushUserToken** + +- HTTP Method: DELETE +- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} + +**Required Parameters** + +| Name | Type | Description | +| :------ | :----- | :---------- | +| userId | string | | +| tokenId | string | | + +**Return Type** + +DiscardResult + +**Example Usage Code Snippet** + +```Typescript +import { Client } from '@magicbell/project-client'; + +const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); + +(async () => { + const result = await sdk.channels.discardWebPushUserToken('user_id', 'token_id'); + console.log(result); +})(); + +``` diff --git a/packages/project-client/src/services/broadcasts/Broadcasts.ts b/packages/project-client/src/services/broadcasts/Broadcasts.ts new file mode 100644 index 000000000..5c90f8e3b --- /dev/null +++ b/packages/project-client/src/services/broadcasts/Broadcasts.ts @@ -0,0 +1,67 @@ +import BaseService from '../../BaseService'; +import { serializePath } from '../../http/QuerySerializer'; +import { Broadcast } from './models/Broadcast'; +import { BroadcastListResponse } from './models/BroadcastListResponse'; +import { CreateBroadcastRequest } from './models/CreateBroadcastRequest'; + +export class BroadcastsService extends BaseService { + /** + * @description Returns a list of broadcasts + */ + async listBroadcasts(): Promise { + const urlEndpoint = '/broadcasts'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as BroadcastListResponse; + return responseModel; + } + + /** + * @description Handles the create notification request. + */ + async createBroadcast(input: CreateBroadcastRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/broadcasts'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.post( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as Broadcast; + return responseModel; + } + + /** + * @description Returns a broadcast + */ + async fetchBroadcast(broadcastId: string): Promise { + if (broadcastId === undefined) { + throw new Error('The following parameter is required: broadcastId, cannot be empty or blank'); + } + let urlEndpoint = '/broadcasts/{broadcast_id}'; + urlEndpoint = urlEndpoint.replace('{broadcast_id}', serializePath('simple', false, broadcastId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as Broadcast; + return responseModel; + } +} diff --git a/packages/project-client/src/services/broadcasts/index.ts b/packages/project-client/src/services/broadcasts/index.ts new file mode 100644 index 000000000..11e083bc5 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/index.ts @@ -0,0 +1,3 @@ +export type { Broadcast } from './models/Broadcast'; +export type { BroadcastListResponse } from './models/BroadcastListResponse'; +export type { CreateBroadcastRequest } from './models/CreateBroadcastRequest'; diff --git a/packages/project-client/src/services/broadcasts/models/Broadcast.ts b/packages/project-client/src/services/broadcasts/models/Broadcast.ts new file mode 100644 index 000000000..f72dd6b5e --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/Broadcast.ts @@ -0,0 +1,92 @@ +import { Topic } from './Topic'; +import { User } from './User'; + +export interface Broadcast { + action_url?: string; + category?: string; + content?: string; + custom_attributes?: CustomAttributes; + overrides?: Overrides; + /** + * @minItems 1 + * @maxItems 1000 + */ + recipients: [Topic | User, ...(Topic | User)[]]; + title: string; + topic?: string; +} +interface CustomAttributes { + [k: string]: unknown; +} +interface Overrides { + channels?: Channels; + providers?: Providers; +} +interface Channels { + email?: Email; + in_app?: InApp; + mobile_push?: MobilePush; + slack?: Slack; + sms?: Sms; + web_push?: WebPush; +} +interface Email { + action_url?: string; + content?: string; + title?: string; +} +interface InApp { + action_url?: string; + content?: string; + title?: string; +} +interface MobilePush { + action_url?: string; + content?: string; + title?: string; +} +interface Slack { + action_url?: string; + content?: string; + title?: string; +} +interface Sms { + action_url?: string; + content?: string; + title?: string; +} +interface WebPush { + action_url?: string; + content?: string; + title?: string; +} +interface Providers { + amazon_ses?: AmazonSes; + android?: Android; + ios?: Ios; + mailgun?: Mailgun; + postmark?: Postmark; + sendgrid?: Sendgrid; + slack?: Slack1; +} +interface AmazonSes { + [k: string]: unknown; +} +interface Android { + [k: string]: unknown; +} +interface Ios { + [k: string]: unknown; +} +interface Mailgun { + [k: string]: unknown; +} +interface Postmark { + [k: string]: unknown; +} +interface Sendgrid { + [k: string]: unknown; +} +interface Slack1 { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts b/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts new file mode 100644 index 000000000..c2c1a69b1 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts @@ -0,0 +1,13 @@ +import { Broadcast } from './Broadcast'; + +export interface BroadcastListResponse { + /** + * Number of the page returned. + */ + current_page: number; + /** + * Number of entities per page. + */ + per_page: number; + broadcasts: Broadcast[]; +} diff --git a/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts b/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts new file mode 100644 index 000000000..538414c4d --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts @@ -0,0 +1,92 @@ +import { Topic } from './Topic'; +import { User } from './User'; + +export interface CreateBroadcastRequest { + action_url?: string; + category?: string; + content?: string; + custom_attributes?: CustomAttributes; + overrides?: Overrides; + /** + * @minItems 1 + * @maxItems 1000 + */ + recipients: [Topic | User, ...(Topic | User)[]]; + title: string; + topic?: string; +} +interface CustomAttributes { + [k: string]: unknown; +} +interface Overrides { + channels?: Channels; + providers?: Providers; +} +interface Channels { + email?: Email; + in_app?: InApp; + mobile_push?: MobilePush; + slack?: Slack; + sms?: Sms; + web_push?: WebPush; +} +interface Email { + action_url?: string; + content?: string; + title?: string; +} +interface InApp { + action_url?: string; + content?: string; + title?: string; +} +interface MobilePush { + action_url?: string; + content?: string; + title?: string; +} +interface Slack { + action_url?: string; + content?: string; + title?: string; +} +interface Sms { + action_url?: string; + content?: string; + title?: string; +} +interface WebPush { + action_url?: string; + content?: string; + title?: string; +} +interface Providers { + amazon_ses?: AmazonSes; + android?: Android; + ios?: Ios; + mailgun?: Mailgun; + postmark?: Postmark; + sendgrid?: Sendgrid; + slack?: Slack1; +} +interface AmazonSes { + [k: string]: unknown; +} +interface Android { + [k: string]: unknown; +} +interface Ios { + [k: string]: unknown; +} +interface Mailgun { + [k: string]: unknown; +} +interface Postmark { + [k: string]: unknown; +} +interface Sendgrid { + [k: string]: unknown; +} +interface Slack1 { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/broadcasts/models/Topic.ts b/packages/project-client/src/services/broadcasts/models/Topic.ts new file mode 100644 index 000000000..9eaf96ccc --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/Topic.ts @@ -0,0 +1,6 @@ +export interface Topic { + topic: Topic1; +} +export interface Topic1 { + subscribers: boolean; +} diff --git a/packages/project-client/src/services/broadcasts/models/User.ts b/packages/project-client/src/services/broadcasts/models/User.ts new file mode 100644 index 000000000..71b285bd7 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/User.ts @@ -0,0 +1,66 @@ +export type User = + | { + email: Email; + external_id?: ExternalId; + custom_attributes?: CustomAttributes; + first_name?: FirstName; + last_name?: LastName; + phone_numbers?: PhoneNumbers; + } + | { + email: Email1; + external_id?: ExternalId1; + custom_attributes?: CustomAttributes1; + first_name?: FirstName1; + last_name?: LastName1; + phone_numbers?: PhoneNumbers1; + } + | { + email?: Email2; + external_id: ExternalId2; + custom_attributes?: CustomAttributes2; + first_name?: FirstName2; + last_name?: LastName2; + phone_numbers?: PhoneNumbers2; + } + | { + email?: Email3; + external_id: ExternalId3; + custom_attributes?: CustomAttributes3; + first_name?: FirstName3; + last_name?: LastName3; + phone_numbers?: PhoneNumbers3; + }; +type Email = string; +type ExternalId = string; +type FirstName = string; +type LastName = string; +type PhoneNumbers = string[]; +type Email1 = string; +type ExternalId1 = string; +type FirstName1 = string; +type LastName1 = string; +type PhoneNumbers1 = string[]; +type Email2 = string; +type ExternalId2 = string; +type FirstName2 = string; +type LastName2 = string; +type PhoneNumbers2 = string[]; +type Email3 = string; +type ExternalId3 = string; +type FirstName3 = string; +type LastName3 = string; +type PhoneNumbers3 = string[]; + +interface CustomAttributes { + [k: string]: unknown; +} +interface CustomAttributes1 { + [k: string]: unknown; +} +interface CustomAttributes2 { + [k: string]: unknown; +} +interface CustomAttributes3 { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/channels/Channels.ts b/packages/project-client/src/services/channels/Channels.ts new file mode 100644 index 000000000..34657a33d --- /dev/null +++ b/packages/project-client/src/services/channels/Channels.ts @@ -0,0 +1,310 @@ +import BaseService from '../../BaseService'; +import { serializePath } from '../../http/QuerySerializer'; +import { ApnsTokenWithMetadata } from './models/ApnsTokenWithMetadata'; +import { ArrayWithMetadataOfApnsToken } from './models/ArrayWithMetadataOfApnsToken'; +import { ArrayWithMetadataOfFcmToken } from './models/ArrayWithMetadataOfFcmToken'; +import { ArrayWithMetadataOfSlackToken } from './models/ArrayWithMetadataOfSlackToken'; +import { ArrayWithMetadataOfTeamsToken } from './models/ArrayWithMetadataOfTeamsToken'; +import { ArrayWithMetadataOfWebPushToken } from './models/ArrayWithMetadataOfWebPushToken'; +import { DiscardResult } from './models/DiscardResult'; +import { FcmTokenWithMetadata } from './models/FcmTokenWithMetadata'; +import { SlackTokenWithMetadata } from './models/SlackTokenWithMetadata'; +import { TeamsTokenWithMetadata } from './models/TeamsTokenWithMetadata'; +import { WebPushTokenWithMetadata } from './models/WebPushTokenWithMetadata'; + +export class ChannelsService extends BaseService { + async getMobilePushApnsUserTokens(userId: string): Promise { + if (userId === undefined) { + throw new Error('The following parameter is required: userId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ArrayWithMetadataOfApnsToken; + return responseModel; + } + + async getMobilePushApnsUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ApnsTokenWithMetadata; + return responseModel; + } + + async discardMobilePushApnsUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as DiscardResult; + return responseModel; + } + + async getMobilePushFcmUserTokens(userId: string): Promise { + if (userId === undefined) { + throw new Error('The following parameter is required: userId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ArrayWithMetadataOfFcmToken; + return responseModel; + } + + async getMobilePushFcmUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as FcmTokenWithMetadata; + return responseModel; + } + + async discardMobilePushFcmUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as DiscardResult; + return responseModel; + } + + async getSlackUserTokens(userId: string): Promise { + if (userId === undefined) { + throw new Error('The following parameter is required: userId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/slack/tokens'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ArrayWithMetadataOfSlackToken; + return responseModel; + } + + async getSlackUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/slack/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as SlackTokenWithMetadata; + return responseModel; + } + + async discardSlackUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/slack/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as DiscardResult; + return responseModel; + } + + async getTeamsUserTokens(userId: string): Promise { + if (userId === undefined) { + throw new Error('The following parameter is required: userId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/teams/tokens'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ArrayWithMetadataOfTeamsToken; + return responseModel; + } + + async getTeamsUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/teams/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as TeamsTokenWithMetadata; + return responseModel; + } + + async discardTeamsUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/teams/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as DiscardResult; + return responseModel; + } + + async getWebPushUserTokens(userId: string): Promise { + if (userId === undefined) { + throw new Error('The following parameter is required: userId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/web_push/tokens'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ArrayWithMetadataOfWebPushToken; + return responseModel; + } + + async getWebPushUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/web_push/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as WebPushTokenWithMetadata; + return responseModel; + } + + async discardWebPushUserToken(userId: string, tokenId: string): Promise { + if (userId === undefined || tokenId === undefined) { + throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); + } + let urlEndpoint = '/users/{user_id}/channels/web_push/tokens/{token_id}'; + urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); + urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as DiscardResult; + return responseModel; + } +} diff --git a/packages/project-client/src/services/channels/index.ts b/packages/project-client/src/services/channels/index.ts new file mode 100644 index 000000000..a80fbbc2f --- /dev/null +++ b/packages/project-client/src/services/channels/index.ts @@ -0,0 +1,11 @@ +export type { ApnsTokenWithMetadata } from './models/ApnsTokenWithMetadata'; +export type { ArrayWithMetadataOfApnsToken } from './models/ArrayWithMetadataOfApnsToken'; +export type { ArrayWithMetadataOfFcmToken } from './models/ArrayWithMetadataOfFcmToken'; +export type { ArrayWithMetadataOfSlackToken } from './models/ArrayWithMetadataOfSlackToken'; +export type { ArrayWithMetadataOfTeamsToken } from './models/ArrayWithMetadataOfTeamsToken'; +export type { ArrayWithMetadataOfWebPushToken } from './models/ArrayWithMetadataOfWebPushToken'; +export type { DiscardResult } from './models/DiscardResult'; +export type { FcmTokenWithMetadata } from './models/FcmTokenWithMetadata'; +export type { SlackTokenWithMetadata } from './models/SlackTokenWithMetadata'; +export type { TeamsTokenWithMetadata } from './models/TeamsTokenWithMetadata'; +export type { WebPushTokenWithMetadata } from './models/WebPushTokenWithMetadata'; diff --git a/packages/project-client/src/services/channels/models/ApnsToken.ts b/packages/project-client/src/services/channels/models/ApnsToken.ts new file mode 100644 index 000000000..b09a7ba29 --- /dev/null +++ b/packages/project-client/src/services/channels/models/ApnsToken.ts @@ -0,0 +1,6 @@ +type InstallationId = 'development' | 'production'; + +export interface ApnsToken { + device_token: string; + installation_id?: InstallationId; +} diff --git a/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts new file mode 100644 index 000000000..b59481de9 --- /dev/null +++ b/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts @@ -0,0 +1,14 @@ +import { ApnsToken } from './ApnsToken'; + +type Data = ApnsToken; + +export interface ApnsTokenWithMetadata { + data: Data; + metadata: Metadata; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts new file mode 100644 index 000000000..63f550037 --- /dev/null +++ b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts @@ -0,0 +1,16 @@ +import { ApnsToken } from './ApnsToken'; + +type Data = ApnsToken; + +export interface ArrayWithMetadataOfApnsToken { + data: { + data: Data; + metadata: Metadata; + }[]; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts new file mode 100644 index 000000000..8645e33a2 --- /dev/null +++ b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts @@ -0,0 +1,16 @@ +import { FcmToken } from './FcmToken'; + +type Data = FcmToken; + +export interface ArrayWithMetadataOfFcmToken { + data: { + data: Data; + metadata: Metadata; + }[]; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts new file mode 100644 index 000000000..8392dddca --- /dev/null +++ b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts @@ -0,0 +1,16 @@ +import { SlackToken } from './SlackToken'; + +type Data = SlackToken; + +export interface ArrayWithMetadataOfSlackToken { + data: { + data: Data; + metadata: Metadata; + }[]; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts new file mode 100644 index 000000000..3b6d2b5df --- /dev/null +++ b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts @@ -0,0 +1,16 @@ +import { TeamsToken } from './TeamsToken'; + +type Data = TeamsToken; + +export interface ArrayWithMetadataOfTeamsToken { + data: { + data: Data; + metadata: Metadata; + }[]; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts new file mode 100644 index 000000000..fa68aa35d --- /dev/null +++ b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts @@ -0,0 +1,16 @@ +import { WebPushToken } from './WebPushToken'; + +type Data = WebPushToken; + +export interface ArrayWithMetadataOfWebPushToken { + data: { + data: Data; + metadata: Metadata; + }[]; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/DiscardResult.ts b/packages/project-client/src/services/channels/models/DiscardResult.ts new file mode 100644 index 000000000..77643bc61 --- /dev/null +++ b/packages/project-client/src/services/channels/models/DiscardResult.ts @@ -0,0 +1,4 @@ +export interface DiscardResult { + discarded_at?: string; + id?: string; +} diff --git a/packages/project-client/src/services/channels/models/FcmToken.ts b/packages/project-client/src/services/channels/models/FcmToken.ts new file mode 100644 index 000000000..7043fee31 --- /dev/null +++ b/packages/project-client/src/services/channels/models/FcmToken.ts @@ -0,0 +1,6 @@ +type InstallationId = 'development' | 'production'; + +export interface FcmToken { + device_token: string; + installation_id?: InstallationId; +} diff --git a/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts new file mode 100644 index 000000000..46925b058 --- /dev/null +++ b/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts @@ -0,0 +1,14 @@ +import { FcmToken } from './FcmToken'; + +type Data = FcmToken; + +export interface FcmTokenWithMetadata { + data: Data; + metadata: Metadata; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/SlackToken.ts b/packages/project-client/src/services/channels/models/SlackToken.ts new file mode 100644 index 000000000..46db8652d --- /dev/null +++ b/packages/project-client/src/services/channels/models/SlackToken.ts @@ -0,0 +1,12 @@ +export interface SlackToken { + oauth?: Oauth; + webhook?: Webhook; +} +interface Oauth { + channel_id: string; + installation_id: string; + scope?: string; +} +interface Webhook { + url: string; +} diff --git a/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts new file mode 100644 index 000000000..47f9edd8f --- /dev/null +++ b/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts @@ -0,0 +1,14 @@ +import { SlackToken } from './SlackToken'; + +type Data = SlackToken; + +export interface SlackTokenWithMetadata { + data: Data; + metadata: Metadata; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/TeamsToken.ts b/packages/project-client/src/services/channels/models/TeamsToken.ts new file mode 100644 index 000000000..207768b58 --- /dev/null +++ b/packages/project-client/src/services/channels/models/TeamsToken.ts @@ -0,0 +1 @@ +export interface TeamsToken {} diff --git a/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts new file mode 100644 index 000000000..04e418ca5 --- /dev/null +++ b/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts @@ -0,0 +1,14 @@ +import { TeamsToken } from './TeamsToken'; + +type Data = TeamsToken; + +export interface TeamsTokenWithMetadata { + data: Data; + metadata: Metadata; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/channels/models/WebPushToken.ts b/packages/project-client/src/services/channels/models/WebPushToken.ts new file mode 100644 index 000000000..a69af1965 --- /dev/null +++ b/packages/project-client/src/services/channels/models/WebPushToken.ts @@ -0,0 +1,8 @@ +export interface WebPushToken { + endpoint: string; + keys: Keys; +} +interface Keys { + auth: string; + p256dh: string; +} diff --git a/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts new file mode 100644 index 000000000..1d26abff7 --- /dev/null +++ b/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts @@ -0,0 +1,14 @@ +import { WebPushToken } from './WebPushToken'; + +type Data = WebPushToken; + +export interface WebPushTokenWithMetadata { + data: Data; + metadata: Metadata; +} +interface Metadata { + created_at: string; + discarded_at?: string; + id: string; + updated_at?: string; +} diff --git a/packages/project-client/src/services/integrations/Integrations.ts b/packages/project-client/src/services/integrations/Integrations.ts new file mode 100644 index 000000000..fb3a61847 --- /dev/null +++ b/packages/project-client/src/services/integrations/Integrations.ts @@ -0,0 +1,393 @@ +import BaseService from '../../BaseService'; +import { ApnsConfig } from './models/ApnsConfig'; +import { FcmConfig } from './models/FcmConfig'; +import { InboxConfig } from './models/InboxConfig'; +import { ListIntegrationsResponse } from './models/ListIntegrationsResponse'; +import { MailgunConfig } from './models/MailgunConfig'; +import { PingConfig } from './models/PingConfig'; +import { SaveApnsIntegrationRequest } from './models/SaveApnsIntegrationRequest'; +import { SaveFcmIntegrationRequest } from './models/SaveFcmIntegrationRequest'; +import { SaveInboxIntegrationRequest } from './models/SaveInboxIntegrationRequest'; +import { SaveMailgunIntegrationRequest } from './models/SaveMailgunIntegrationRequest'; +import { SavePingEmailIntegrationRequest } from './models/SavePingEmailIntegrationRequest'; +import { SaveSendgridIntegrationRequest } from './models/SaveSendgridIntegrationRequest'; +import { SaveSlackIntegrationRequest } from './models/SaveSlackIntegrationRequest'; +import { SaveStripeIntegrationRequest } from './models/SaveStripeIntegrationRequest'; +import { SaveTemplatesIntegrationRequest } from './models/SaveTemplatesIntegrationRequest'; +import { SaveTemplatesIntegrationResponse } from './models/SaveTemplatesIntegrationResponse'; +import { SaveTwilioIntegrationRequest } from './models/SaveTwilioIntegrationRequest'; +import { SaveWebPushIntegrationRequest } from './models/SaveWebPushIntegrationRequest'; +import { SendgridConfig } from './models/SendgridConfig'; +import { SlackConfig } from './models/SlackConfig'; +import { StripeConfig } from './models/StripeConfig'; +import { TwilioConfig } from './models/TwilioConfig'; +import { WebpushConfig } from './models/WebpushConfig'; + +export class IntegrationsService extends BaseService { + async listIntegrations(): Promise { + const urlEndpoint = '/integrations'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.get( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ListIntegrationsResponse; + return responseModel; + } + + async saveApnsIntegration(input: SaveApnsIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/apns'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as ApnsConfig; + return responseModel; + } + + async deleteApnsIntegration(): Promise { + const urlEndpoint = '/integrations/apns'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveFcmIntegration(input: SaveFcmIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/fcm'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as FcmConfig; + return responseModel; + } + + async deleteFcmIntegration(): Promise { + const urlEndpoint = '/integrations/fcm'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveInboxIntegration(input: SaveInboxIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/inbox'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as InboxConfig; + return responseModel; + } + + async deleteInboxIntegration(): Promise { + const urlEndpoint = '/integrations/inbox'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveMailgunIntegration(input: SaveMailgunIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/mailgun'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as MailgunConfig; + return responseModel; + } + + async deleteMailgunIntegration(): Promise { + const urlEndpoint = '/integrations/mailgun'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async savePingEmailIntegration(input: SavePingEmailIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/ping_email'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as PingConfig; + return responseModel; + } + + async deletePingEmailIntegration(): Promise { + const urlEndpoint = '/integrations/ping_email'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveSendgridIntegration(input: SaveSendgridIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/sendgrid'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as SendgridConfig; + return responseModel; + } + + async deleteSendgridIntegration(): Promise { + const urlEndpoint = '/integrations/sendgrid'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveSlackIntegration(input: SaveSlackIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/slack'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as SlackConfig; + return responseModel; + } + + async deleteSlackIntegration(): Promise { + const urlEndpoint = '/integrations/slack'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveStripeIntegration(input: SaveStripeIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/stripe'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as StripeConfig; + return responseModel; + } + + async deleteStripeIntegration(): Promise { + const urlEndpoint = '/integrations/stripe'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveTemplatesIntegration(input: SaveTemplatesIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/templates'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as SaveTemplatesIntegrationResponse; + return responseModel; + } + + async deleteTemplatesIntegration(): Promise { + const urlEndpoint = '/integrations/templates'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveTwilioIntegration(input: SaveTwilioIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/twilio'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as TwilioConfig; + return responseModel; + } + + async deleteTwilioIntegration(): Promise { + const urlEndpoint = '/integrations/twilio'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } + + async saveWebPushIntegration(input: SaveWebPushIntegrationRequest): Promise { + const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; + const urlEndpoint = '/integrations/web_push'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.put( + finalUrl, + input, + { + ...headers, + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data as WebpushConfig; + return responseModel; + } + + async deleteWebPushIntegration(): Promise { + const urlEndpoint = '/integrations/web_push'; + const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); + const response: any = await this.httpClient.delete( + finalUrl, + {}, + { + ...this.getAuthorizationHeader(), + }, + true, + ); + const responseModel = response.data; + return responseModel; + } +} diff --git a/packages/project-client/src/services/integrations/index.ts b/packages/project-client/src/services/integrations/index.ts new file mode 100644 index 000000000..9afcc7794 --- /dev/null +++ b/packages/project-client/src/services/integrations/index.ts @@ -0,0 +1,23 @@ +export type { ApnsConfig } from './models/ApnsConfig'; +export type { FcmConfig } from './models/FcmConfig'; +export type { InboxConfig } from './models/InboxConfig'; +export type { ListIntegrationsResponse } from './models/ListIntegrationsResponse'; +export type { MailgunConfig } from './models/MailgunConfig'; +export type { PingConfig } from './models/PingConfig'; +export type { SaveApnsIntegrationRequest } from './models/SaveApnsIntegrationRequest'; +export type { SaveFcmIntegrationRequest } from './models/SaveFcmIntegrationRequest'; +export type { SaveInboxIntegrationRequest } from './models/SaveInboxIntegrationRequest'; +export type { SaveMailgunIntegrationRequest } from './models/SaveMailgunIntegrationRequest'; +export type { SavePingEmailIntegrationRequest } from './models/SavePingEmailIntegrationRequest'; +export type { SaveSendgridIntegrationRequest } from './models/SaveSendgridIntegrationRequest'; +export type { SaveSlackIntegrationRequest } from './models/SaveSlackIntegrationRequest'; +export type { SaveStripeIntegrationRequest } from './models/SaveStripeIntegrationRequest'; +export type { SaveTemplatesIntegrationRequest } from './models/SaveTemplatesIntegrationRequest'; +export type { SaveTemplatesIntegrationResponse } from './models/SaveTemplatesIntegrationResponse'; +export type { SaveTwilioIntegrationRequest } from './models/SaveTwilioIntegrationRequest'; +export type { SaveWebPushIntegrationRequest } from './models/SaveWebPushIntegrationRequest'; +export type { SendgridConfig } from './models/SendgridConfig'; +export type { SlackConfig } from './models/SlackConfig'; +export type { StripeConfig } from './models/StripeConfig'; +export type { TwilioConfig } from './models/TwilioConfig'; +export type { WebpushConfig } from './models/WebpushConfig'; diff --git a/packages/project-client/src/services/integrations/models/ApnsConfig.ts b/packages/project-client/src/services/integrations/models/ApnsConfig.ts new file mode 100644 index 000000000..c91f8fbbf --- /dev/null +++ b/packages/project-client/src/services/integrations/models/ApnsConfig.ts @@ -0,0 +1,9 @@ +type Badge = 'unread' | 'unseen'; + +export interface ApnsConfig { + app_id: string; + badge: Badge; + certificate: string; + key_id: string; + team_id: string; +} diff --git a/packages/project-client/src/services/integrations/models/FcmConfig.ts b/packages/project-client/src/services/integrations/models/FcmConfig.ts new file mode 100644 index 000000000..b8788e791 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/FcmConfig.ts @@ -0,0 +1,15 @@ +type Type_ = 'service_account'; + +export interface FcmConfig { + auth_provider_x509_cert_url: string; + auth_uri: string; + client_email: string; + client_id: string; + client_x509_cert_url: string; + private_key: string; + private_key_id: string; + project_id: string; + token_uri: string; + universe_domain: string; + type_: Type_; +} diff --git a/packages/project-client/src/services/integrations/models/InboxConfig.ts b/packages/project-client/src/services/integrations/models/InboxConfig.ts new file mode 100644 index 000000000..192605542 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/InboxConfig.ts @@ -0,0 +1,11 @@ +export interface InboxConfig { + images: Images; + locale: string; + theme: Theme; +} +interface Images { + [k: string]: unknown; +} +interface Theme { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts b/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts new file mode 100644 index 000000000..370ae587e --- /dev/null +++ b/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts @@ -0,0 +1,10 @@ +export interface ListIntegrationsResponse { + integrations?: { + config?: Config; + id?: string; + name?: string; + }[]; +} +interface Config { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/integrations/models/MailgunConfig.ts b/packages/project-client/src/services/integrations/models/MailgunConfig.ts new file mode 100644 index 000000000..dd3305a60 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/MailgunConfig.ts @@ -0,0 +1,7 @@ +type Region = 'us' | 'eu'; + +export interface MailgunConfig { + api_key: string; + domain: string; + region: Region; +} diff --git a/packages/project-client/src/services/integrations/models/PingConfig.ts b/packages/project-client/src/services/integrations/models/PingConfig.ts new file mode 100644 index 000000000..0fafbac78 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/PingConfig.ts @@ -0,0 +1,6 @@ +export interface PingConfig { + /** + * URL to ping + */ + url: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts new file mode 100644 index 000000000..54a008917 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts @@ -0,0 +1,9 @@ +type Badge = 'unread' | 'unseen'; + +export interface SaveApnsIntegrationRequest { + app_id: string; + badge: Badge; + certificate: string; + key_id: string; + team_id: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts new file mode 100644 index 000000000..e0152c9f0 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts @@ -0,0 +1,15 @@ +type Type_ = 'service_account'; + +export interface SaveFcmIntegrationRequest { + auth_provider_x509_cert_url: string; + auth_uri: string; + client_email: string; + client_id: string; + client_x509_cert_url: string; + private_key: string; + private_key_id: string; + project_id: string; + token_uri: string; + universe_domain: string; + type_: Type_; +} diff --git a/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts new file mode 100644 index 000000000..da53a1fc0 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts @@ -0,0 +1,11 @@ +export interface SaveInboxIntegrationRequest { + images: Images; + locale: string; + theme: Theme; +} +interface Images { + [k: string]: unknown; +} +interface Theme { + [k: string]: unknown; +} diff --git a/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts new file mode 100644 index 000000000..079e72b15 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts @@ -0,0 +1,7 @@ +type Region = 'us' | 'eu'; + +export interface SaveMailgunIntegrationRequest { + api_key: string; + domain: string; + region: Region; +} diff --git a/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts new file mode 100644 index 000000000..9869a5dfb --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts @@ -0,0 +1,6 @@ +export interface SavePingEmailIntegrationRequest { + /** + * URL to ping + */ + url: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts new file mode 100644 index 000000000..eda46ec4f --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts @@ -0,0 +1,28 @@ +export interface SaveSendgridIntegrationRequest { + /** + * The API key for Sendgrid + */ + api_key: string; + reply_to?: ReplyTo; + from_?: From_; +} +interface ReplyTo { + /** + * The email address to reply to + */ + email: string; + /** + * The name to reply to + */ + name?: string; +} +interface From_ { + /** + * The email address to send from + */ + email: string; + /** + * The name to send from + */ + name?: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts new file mode 100644 index 000000000..ebcfbea8a --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts @@ -0,0 +1,7 @@ +export interface SaveSlackIntegrationRequest { + app_id: string; + client_id: string; + client_secret: string; + id?: string; + signing_secret: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts new file mode 100644 index 000000000..477968e42 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts @@ -0,0 +1,6 @@ +export interface SaveStripeIntegrationRequest { + /** + * The signing secret to verify incoming requests from Stripe + */ + webhook_signing_secret: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts new file mode 100644 index 000000000..eec72bdc0 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts @@ -0,0 +1 @@ +export interface SaveTemplatesIntegrationRequest {} diff --git a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts new file mode 100644 index 000000000..dac80797a --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts @@ -0,0 +1 @@ +export interface SaveTemplatesIntegrationResponse {} diff --git a/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts new file mode 100644 index 000000000..402b0a6cf --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts @@ -0,0 +1,24 @@ +/** + * The region to use for Twilio, defaults to 'us1' + */ +type Region = 'us1' | 'ie1' | 'au1'; + +export interface SaveTwilioIntegrationRequest { + /** + * The SID for your Twilio account + */ + account_sid: string; + /** + * The API key for Twilio + */ + api_key: string; + /** + * The API Secret for Twilio + */ + api_secret: string; + region?: Region; + /** + * The phone number to send from, in E.164 format + */ + from_: string; +} diff --git a/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts new file mode 100644 index 000000000..132955413 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts @@ -0,0 +1,4 @@ +export interface SaveWebPushIntegrationRequest { + private_key: string; + public_key: string; +} diff --git a/packages/project-client/src/services/integrations/models/SendgridConfig.ts b/packages/project-client/src/services/integrations/models/SendgridConfig.ts new file mode 100644 index 000000000..7b575b85b --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SendgridConfig.ts @@ -0,0 +1,28 @@ +export interface SendgridConfig { + /** + * The API key for Sendgrid + */ + api_key: string; + reply_to?: ReplyTo; + from_?: From_; +} +interface ReplyTo { + /** + * The email address to reply to + */ + email: string; + /** + * The name to reply to + */ + name?: string; +} +interface From_ { + /** + * The email address to send from + */ + email: string; + /** + * The name to send from + */ + name?: string; +} diff --git a/packages/project-client/src/services/integrations/models/SlackConfig.ts b/packages/project-client/src/services/integrations/models/SlackConfig.ts new file mode 100644 index 000000000..1385a9746 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/SlackConfig.ts @@ -0,0 +1,7 @@ +export interface SlackConfig { + app_id: string; + client_id: string; + client_secret: string; + id?: string; + signing_secret: string; +} diff --git a/packages/project-client/src/services/integrations/models/StripeConfig.ts b/packages/project-client/src/services/integrations/models/StripeConfig.ts new file mode 100644 index 000000000..f6dc5a287 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/StripeConfig.ts @@ -0,0 +1,6 @@ +export interface StripeConfig { + /** + * The signing secret to verify incoming requests from Stripe + */ + webhook_signing_secret: string; +} diff --git a/packages/project-client/src/services/integrations/models/TwilioConfig.ts b/packages/project-client/src/services/integrations/models/TwilioConfig.ts new file mode 100644 index 000000000..e1a3d7245 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/TwilioConfig.ts @@ -0,0 +1,24 @@ +/** + * The region to use for Twilio, defaults to 'us1' + */ +type Region = 'us1' | 'ie1' | 'au1'; + +export interface TwilioConfig { + /** + * The SID for your Twilio account + */ + account_sid: string; + /** + * The API key for Twilio + */ + api_key: string; + /** + * The API Secret for Twilio + */ + api_secret: string; + region?: Region; + /** + * The phone number to send from, in E.164 format + */ + from_: string; +} diff --git a/packages/project-client/src/services/integrations/models/WebpushConfig.ts b/packages/project-client/src/services/integrations/models/WebpushConfig.ts new file mode 100644 index 000000000..8496b1167 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/WebpushConfig.ts @@ -0,0 +1,4 @@ +export interface WebpushConfig { + private_key: string; + public_key: string; +} From 5a4bd81e68bec80a7879f5dd63821a28bd4d0d51 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Thu, 22 Aug 2024 14:02:18 +0200 Subject: [PATCH 03/12] chore: allow unused vars --- packages/project-client/tsconfig.build.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/project-client/tsconfig.build.json b/packages/project-client/tsconfig.build.json index d4cb15091..18c1cbdc6 100644 --- a/packages/project-client/tsconfig.build.json +++ b/packages/project-client/tsconfig.build.json @@ -9,6 +9,8 @@ "baseUrl": "./", "declarationMap": true, "lib": ["ES2021.String", "dom", "esnext"], - "noEmit": false + "noEmit": false, + "noUnusedLocals": false, + "noUnusedParameters": false } } From c2085bb99b43933bb28d836a6fa97d9df9f51f73 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Thu, 22 Aug 2024 14:36:20 +0200 Subject: [PATCH 04/12] chore: use liblab typescript v2 sdk --- packages/project-client/liblab.config.json | 3 +-- packages/project-client/scripts/build.ts | 17 ++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/project-client/liblab.config.json b/packages/project-client/liblab.config.json index 694221da4..459fe175b 100644 --- a/packages/project-client/liblab.config.json +++ b/packages/project-client/liblab.config.json @@ -31,13 +31,12 @@ "typescript": { "bundle": false, "exportClassDefault": false, - "httpClient": "axios", "npmName": "project-client", "npmOrg": "magicbell", "githubRepoName": "magicbell-js", "ignoreFiles": [], "sdkVersion": "0.1.0", - "liblabVersion": "1" + "liblabVersion": "2" } }, "publishing": { diff --git a/packages/project-client/scripts/build.ts b/packages/project-client/scripts/build.ts index deefa7163..32e1b6aae 100644 --- a/packages/project-client/scripts/build.ts +++ b/packages/project-client/scripts/build.ts @@ -117,21 +117,20 @@ async function build(specfile = 'https://public.magicbell.com/specs/swagger.json // await move('output/typescript/test', './test'); await move('output/typescript/package.json', './package.json'); await move('output/typescript/README.md', './README.md'); + await move('output/typescript/documentation', './docs'); await rimraf('output'); // patch package.json let pkgJson = JSON.parse(await fs.readFile('./package.json', { encoding: 'utf-8' })); pkgJson.scripts.codegen = 'tsx scripts/build.ts'; - pkgJson.scripts['build'] = 'run-s build:*'; - pkgJson.scripts['build:cjs'] = 'tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs'; - pkgJson.scripts['build:esm'] = 'tsc --project tsconfig.build.json --module esnext --outDir dist/esm'; - pkgJson.scripts['start'] = 'rm -rf dist/ && tsc -w'; - - delete pkgJson.scripts['watch']; - delete pkgJson.scripts['build:umd']; - delete pkgJson.scripts['build:all']; - delete pkgJson.scripts['prepublishOnly']; + pkgJson.scripts = { + build: 'run-s build:*', + 'build:cjs': 'tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs', + 'build:esm': 'tsc --project tsconfig.build.json --module esnext --outDir dist/esm', + start: 'rm -rf dist/ && tsc -w', + codegen: 'tsx scripts/build.ts', + }; for (const key of Object.keys(pkgJson.devDependencies)) { if (/eslint|prettier/.test(key)) { From 6123d174406e65f0465354c657159c3c42233a59 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Thu, 22 Aug 2024 14:36:51 +0200 Subject: [PATCH 05/12] chore: regen --- packages/project-client/README.md | 1391 +------------- .../project-client/docs/models/ApnsConfig.md | 20 + .../project-client/docs/models/ApnsToken.md | 17 + .../docs/models/ApnsTokenWithMetadata.md | 19 + .../models/ArrayWithMetadataOfApnsToken.md | 27 + .../models/ArrayWithMetadataOfFcmToken.md | 27 + .../models/ArrayWithMetadataOfSlackToken.md | 27 + .../models/ArrayWithMetadataOfTeamsToken.md | 27 + .../models/ArrayWithMetadataOfWebPushToken.md | 27 + .../project-client/docs/models/Broadcast.md | 110 ++ .../docs/models/BroadcastListResponse.md | 9 + .../docs/models/DiscardResult.md | 8 + .../project-client/docs/models/FcmConfig.md | 25 + .../project-client/docs/models/FcmToken.md | 17 + .../docs/models/FcmTokenWithMetadata.md | 19 + .../project-client/docs/models/InboxConfig.md | 9 + .../docs/models/ListIntegrationsResponse.md | 17 + .../docs/models/MailgunConfig.md | 18 + .../project-client/docs/models/PingConfig.md | 7 + .../docs/models/SendgridConfig.md | 27 + .../project-client/docs/models/SlackConfig.md | 11 + .../project-client/docs/models/SlackToken.md | 26 + .../docs/models/SlackTokenWithMetadata.md | 19 + .../docs/models/StripeConfig.md | 7 + .../docs/models/TeamsTokenWithMetadata.md | 19 + .../docs/models/TwilioConfig.md | 23 + .../docs/models/WebPushToken.md | 17 + .../docs/models/WebPushTokenWithMetadata.md | 19 + .../docs/models/WebpushConfig.md | 8 + .../docs/services/BroadcastsService.md | 183 ++ .../docs/services/ChannelsService.md | 594 ++++++ .../docs/services/IntegrationsService.md | 1542 ++++++++++++++++ packages/project-client/package.json | 34 +- packages/project-client/src/BaseService.ts | 46 - packages/project-client/src/hooks/Hook.ts | 28 - .../project-client/src/http/HTTPClient.ts | 12 - .../project-client/src/http/HTTPLibrary.ts | 159 -- .../src/http/QuerySerializer.ts | 40 - packages/project-client/src/http/client.ts | 35 + packages/project-client/src/http/error.ts | 12 + .../src/http/errors/BadGateway.ts | 11 - .../src/http/errors/BadRequest.ts | 11 - .../src/http/errors/Conflict.ts | 11 - .../src/http/errors/ExpectationFailed.ts | 11 - .../src/http/errors/FailedDependency.ts | 11 - .../src/http/errors/Forbidden.ts | 11 - .../src/http/errors/GatewayTimeout.ts | 11 - .../project-client/src/http/errors/Gone.ts | 11 - .../http/errors/HttpVersionNotSupported.ts | 11 - .../src/http/errors/InternalServerError.ts | 11 - .../src/http/errors/LengthRequired.ts | 11 - .../project-client/src/http/errors/Locked.ts | 11 - .../src/http/errors/LoopDetected.ts | 11 - .../src/http/errors/MethodNotAllowed.ts | 14 - .../src/http/errors/MisdirectedRequest.ts | 11 - .../errors/NetworkAuthenticationRequired.ts | 11 - .../src/http/errors/NotAcceptable.ts | 11 - .../src/http/errors/NotExtended.ts | 11 - .../src/http/errors/NotFound.ts | 11 - .../src/http/errors/NotImplemented.ts | 11 - .../src/http/errors/PayloadTooLarge.ts | 14 - .../src/http/errors/PaymentRequired.ts | 11 - .../src/http/errors/PreconditionFailed.ts | 11 - .../src/http/errors/PreconditionRequired.ts | 11 - .../errors/ProxyAuthenticationRequired.ts | 14 - .../src/http/errors/RangeNotSatisfiable.ts | 11 - .../errors/RequestHeaderFieldsTooLarge.ts | 11 - .../src/http/errors/RequestTimeout.ts | 11 - .../src/http/errors/ServiceUnavailable.ts | 14 - .../src/http/errors/TooEarly.ts | 11 - .../src/http/errors/TooManyRequests.ts | 14 - .../src/http/errors/Unauthorized.ts | 14 - .../http/errors/UnavailableForLegalReasons.ts | 11 - .../src/http/errors/UnprocessableEntity.ts | 11 - .../src/http/errors/UnsufficientStorage.ts | 11 - .../src/http/errors/UnsupportedMediaType.ts | 11 - .../src/http/errors/UpgradeRequired.ts | 11 - .../src/http/errors/UriTooLong.ts | 11 - .../src/http/errors/VariantAlsoNegotiates.ts | 11 - .../project-client/src/http/errors/base.ts | 52 - .../project-client/src/http/errors/index.ts | 83 - .../src/http/handlers/auth-handler.ts | 34 + .../src/http/handlers/handler-chain.ts | 22 + .../src/http/handlers/hook-handler.ts | 38 + .../handlers/request-validation-handler.ts | 71 + .../handlers/response-validation-handler.ts | 106 ++ .../src/http/handlers/retry-handler.ts | 40 + .../src/http/handlers/terminating-handler.ts | 9 + .../src/http/hooks/custom-hook.ts | 28 + .../project-client/src/http/hooks/hook.ts | 40 + .../project-client/src/http/httpExceptions.ts | 135 -- packages/project-client/src/http/index.ts | 1 + .../src/http/serialization/base-serializer.ts | 139 ++ .../http/serialization/header-serializer.ts | 19 + .../src/http/serialization/path-serializer.ts | 12 + .../http/serialization/query-serializer.ts | 18 + .../src/http/transport/request-builder.ts | 165 ++ .../src/http/transport/request.ts | 210 +++ .../http/transport/transport-hook-adapter.ts | 85 + packages/project-client/src/http/types.ts | 70 + packages/project-client/src/index.ts | 94 +- packages/project-client/src/models.ts | 44 - .../project-client/src/services/README.md | 1254 ------------- .../src/services/base-service.ts | 27 + .../src/services/broadcasts/Broadcasts.ts | 132 +- .../src/services/broadcasts/index.ts | 5 +- .../services/broadcasts/models/Broadcast.ts | 179 +- .../models/BroadcastListResponse.ts | 13 - .../models/CreateBroadcastRequest.ts | 92 - .../src/services/broadcasts/models/Topic.ts | 6 - .../src/services/broadcasts/models/User.ts | 66 - .../models/broadcast-list-response.ts | 59 + .../services/broadcasts/models/channels.ts | 82 + .../src/services/broadcasts/models/email.ts | 53 + .../src/services/broadcasts/models/in-app.ts | 53 + .../src/services/broadcasts/models/index.ts | 11 + .../services/broadcasts/models/mobile-push.ts | 53 + .../services/broadcasts/models/overrides.ts | 49 + .../services/broadcasts/models/providers.ts | 81 + .../src/services/broadcasts/models/slack.ts | 53 + .../src/services/broadcasts/models/sms.ts | 53 + .../services/broadcasts/models/web-push.ts | 53 + .../src/services/channels/Channels.ts | 878 ++++++--- .../src/services/channels/index.ts | 13 +- .../src/services/channels/models/ApnsToken.ts | 6 - .../channels/models/ApnsTokenWithMetadata.ts | 14 - .../models/ArrayWithMetadataOfApnsToken.ts | 16 - .../models/ArrayWithMetadataOfFcmToken.ts | 16 - .../models/ArrayWithMetadataOfSlackToken.ts | 16 - .../models/ArrayWithMetadataOfTeamsToken.ts | 16 - .../models/ArrayWithMetadataOfWebPushToken.ts | 16 - .../services/channels/models/DiscardResult.ts | 4 - .../src/services/channels/models/FcmToken.ts | 6 - .../channels/models/FcmTokenWithMetadata.ts | 14 - .../services/channels/models/SlackToken.ts | 12 - .../channels/models/SlackTokenWithMetadata.ts | 14 - .../services/channels/models/TeamsToken.ts | 1 - .../channels/models/TeamsTokenWithMetadata.ts | 14 - .../services/channels/models/WebPushToken.ts | 8 - .../models/WebPushTokenWithMetadata.ts | 14 - .../models/apns-token-installation-id.ts | 4 + .../apns-token-with-metadata-metadata.ts | 63 + .../models/apns-token-with-metadata.ts | 55 + .../services/channels/models/apns-token.ts | 46 + .../array-with-metadata-of-apns-token-data.ts | 49 + .../array-with-metadata-of-apns-token.ts | 47 + .../array-with-metadata-of-fcm-token-data.ts | 49 + .../array-with-metadata-of-fcm-token.ts | 47 + ...array-with-metadata-of-slack-token-data.ts | 51 + .../array-with-metadata-of-slack-token.ts | 47 + ...array-with-metadata-of-teams-token-data.ts | 48 + .../array-with-metadata-of-teams-token.ts | 47 + ...ay-with-metadata-of-web-push-token-data.ts | 51 + .../array-with-metadata-of-web-push-token.ts | 47 + .../channels/models/data-metadata-1.ts | 63 + .../channels/models/data-metadata-2.ts | 63 + .../channels/models/data-metadata-3.ts | 63 + .../channels/models/data-metadata-4.ts | 63 + .../channels/models/data-metadata-5.ts | 63 + .../channels/models/discard-result.ts | 46 + .../models/fcm-token-installation-id.ts | 4 + .../fcm-token-with-metadata-metadata.ts | 63 + .../models/fcm-token-with-metadata.ts | 55 + .../src/services/channels/models/fcm-token.ts | 46 + .../src/services/channels/models/index.ts | 41 + .../src/services/channels/models/keys.ts | 46 + .../src/services/channels/models/oauth.ts | 53 + .../slack-token-with-metadata-metadata.ts | 63 + .../models/slack-token-with-metadata.ts | 55 + .../services/channels/models/slack-token.ts | 49 + .../teams-token-with-metadata-metadata.ts | 63 + .../models/teams-token-with-metadata.ts | 54 + .../web-push-token-with-metadata-metadata.ts | 63 + .../models/web-push-token-with-metadata.ts | 55 + .../channels/models/web-push-token.ts | 48 + .../src/services/channels/models/webhook.ts | 41 + .../src/services/integrations/Integrations.ts | 1618 +++++++++++++---- .../src/services/integrations/index.ts | 25 +- .../integrations/models/ApnsConfig.ts | 9 - .../services/integrations/models/FcmConfig.ts | 15 - .../integrations/models/InboxConfig.ts | 11 - .../models/ListIntegrationsResponse.ts | 10 - .../integrations/models/MailgunConfig.ts | 7 - .../integrations/models/PingConfig.ts | 6 - .../models/SaveApnsIntegrationRequest.ts | 9 - .../models/SaveFcmIntegrationRequest.ts | 15 - .../models/SaveInboxIntegrationRequest.ts | 11 - .../models/SaveMailgunIntegrationRequest.ts | 7 - .../models/SavePingEmailIntegrationRequest.ts | 6 - .../models/SaveSendgridIntegrationRequest.ts | 28 - .../models/SaveSlackIntegrationRequest.ts | 7 - .../models/SaveStripeIntegrationRequest.ts | 6 - .../models/SaveTemplatesIntegrationRequest.ts | 1 - .../SaveTemplatesIntegrationResponse.ts | 1 - .../models/SaveTwilioIntegrationRequest.ts | 24 - .../models/SaveWebPushIntegrationRequest.ts | 4 - .../integrations/models/SendgridConfig.ts | 28 - .../integrations/models/SlackConfig.ts | 7 - .../integrations/models/StripeConfig.ts | 6 - .../integrations/models/TwilioConfig.ts | 24 - .../integrations/models/WebpushConfig.ts | 4 - .../integrations/models/apns-config.ts | 69 + .../src/services/integrations/models/badge.ts | 4 + .../integrations/models/fcm-config.ts | 105 ++ .../integrations/models/inbox-config.ts | 53 + .../src/services/integrations/models/index.ts | 21 + .../integrations/models/integrations.ts | 53 + .../models/list-integrations-response.ts | 43 + .../models/mailgun-config-region.ts | 4 + .../integrations/models/mailgun-config.ts | 53 + .../integrations/models/ping-config.ts | 41 + .../services/integrations/models/reply-to.ts | 46 + .../integrations/models/sendgrid-config.ts | 60 + .../integrations/models/slack-config.ts | 77 + .../integrations/models/stripe-config.ts | 41 + .../models/twilio-config-region.ts | 5 + .../integrations/models/twilio-config.ts | 77 + .../src/services/integrations/models/type_.ts | 3 + .../integrations/models/webpush-config.ts | 46 + yarn.lock | 5 + 220 files changed, 9488 insertions(+), 5114 deletions(-) create mode 100644 packages/project-client/docs/models/ApnsConfig.md create mode 100644 packages/project-client/docs/models/ApnsToken.md create mode 100644 packages/project-client/docs/models/ApnsTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfApnsToken.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfFcmToken.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfSlackToken.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfTeamsToken.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfWebPushToken.md create mode 100644 packages/project-client/docs/models/Broadcast.md create mode 100644 packages/project-client/docs/models/BroadcastListResponse.md create mode 100644 packages/project-client/docs/models/DiscardResult.md create mode 100644 packages/project-client/docs/models/FcmConfig.md create mode 100644 packages/project-client/docs/models/FcmToken.md create mode 100644 packages/project-client/docs/models/FcmTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/InboxConfig.md create mode 100644 packages/project-client/docs/models/ListIntegrationsResponse.md create mode 100644 packages/project-client/docs/models/MailgunConfig.md create mode 100644 packages/project-client/docs/models/PingConfig.md create mode 100644 packages/project-client/docs/models/SendgridConfig.md create mode 100644 packages/project-client/docs/models/SlackConfig.md create mode 100644 packages/project-client/docs/models/SlackToken.md create mode 100644 packages/project-client/docs/models/SlackTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/StripeConfig.md create mode 100644 packages/project-client/docs/models/TeamsTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/TwilioConfig.md create mode 100644 packages/project-client/docs/models/WebPushToken.md create mode 100644 packages/project-client/docs/models/WebPushTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/WebpushConfig.md create mode 100644 packages/project-client/docs/services/BroadcastsService.md create mode 100644 packages/project-client/docs/services/ChannelsService.md create mode 100644 packages/project-client/docs/services/IntegrationsService.md delete mode 100644 packages/project-client/src/BaseService.ts delete mode 100644 packages/project-client/src/hooks/Hook.ts delete mode 100644 packages/project-client/src/http/HTTPClient.ts delete mode 100644 packages/project-client/src/http/HTTPLibrary.ts delete mode 100644 packages/project-client/src/http/QuerySerializer.ts create mode 100644 packages/project-client/src/http/client.ts create mode 100644 packages/project-client/src/http/error.ts delete mode 100644 packages/project-client/src/http/errors/BadGateway.ts delete mode 100644 packages/project-client/src/http/errors/BadRequest.ts delete mode 100644 packages/project-client/src/http/errors/Conflict.ts delete mode 100644 packages/project-client/src/http/errors/ExpectationFailed.ts delete mode 100644 packages/project-client/src/http/errors/FailedDependency.ts delete mode 100644 packages/project-client/src/http/errors/Forbidden.ts delete mode 100644 packages/project-client/src/http/errors/GatewayTimeout.ts delete mode 100644 packages/project-client/src/http/errors/Gone.ts delete mode 100644 packages/project-client/src/http/errors/HttpVersionNotSupported.ts delete mode 100644 packages/project-client/src/http/errors/InternalServerError.ts delete mode 100644 packages/project-client/src/http/errors/LengthRequired.ts delete mode 100644 packages/project-client/src/http/errors/Locked.ts delete mode 100644 packages/project-client/src/http/errors/LoopDetected.ts delete mode 100644 packages/project-client/src/http/errors/MethodNotAllowed.ts delete mode 100644 packages/project-client/src/http/errors/MisdirectedRequest.ts delete mode 100644 packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts delete mode 100644 packages/project-client/src/http/errors/NotAcceptable.ts delete mode 100644 packages/project-client/src/http/errors/NotExtended.ts delete mode 100644 packages/project-client/src/http/errors/NotFound.ts delete mode 100644 packages/project-client/src/http/errors/NotImplemented.ts delete mode 100644 packages/project-client/src/http/errors/PayloadTooLarge.ts delete mode 100644 packages/project-client/src/http/errors/PaymentRequired.ts delete mode 100644 packages/project-client/src/http/errors/PreconditionFailed.ts delete mode 100644 packages/project-client/src/http/errors/PreconditionRequired.ts delete mode 100644 packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts delete mode 100644 packages/project-client/src/http/errors/RangeNotSatisfiable.ts delete mode 100644 packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts delete mode 100644 packages/project-client/src/http/errors/RequestTimeout.ts delete mode 100644 packages/project-client/src/http/errors/ServiceUnavailable.ts delete mode 100644 packages/project-client/src/http/errors/TooEarly.ts delete mode 100644 packages/project-client/src/http/errors/TooManyRequests.ts delete mode 100644 packages/project-client/src/http/errors/Unauthorized.ts delete mode 100644 packages/project-client/src/http/errors/UnavailableForLegalReasons.ts delete mode 100644 packages/project-client/src/http/errors/UnprocessableEntity.ts delete mode 100644 packages/project-client/src/http/errors/UnsufficientStorage.ts delete mode 100644 packages/project-client/src/http/errors/UnsupportedMediaType.ts delete mode 100644 packages/project-client/src/http/errors/UpgradeRequired.ts delete mode 100644 packages/project-client/src/http/errors/UriTooLong.ts delete mode 100644 packages/project-client/src/http/errors/VariantAlsoNegotiates.ts delete mode 100644 packages/project-client/src/http/errors/base.ts delete mode 100644 packages/project-client/src/http/errors/index.ts create mode 100644 packages/project-client/src/http/handlers/auth-handler.ts create mode 100644 packages/project-client/src/http/handlers/handler-chain.ts create mode 100644 packages/project-client/src/http/handlers/hook-handler.ts create mode 100644 packages/project-client/src/http/handlers/request-validation-handler.ts create mode 100644 packages/project-client/src/http/handlers/response-validation-handler.ts create mode 100644 packages/project-client/src/http/handlers/retry-handler.ts create mode 100644 packages/project-client/src/http/handlers/terminating-handler.ts create mode 100644 packages/project-client/src/http/hooks/custom-hook.ts create mode 100644 packages/project-client/src/http/hooks/hook.ts delete mode 100644 packages/project-client/src/http/httpExceptions.ts create mode 100644 packages/project-client/src/http/index.ts create mode 100644 packages/project-client/src/http/serialization/base-serializer.ts create mode 100644 packages/project-client/src/http/serialization/header-serializer.ts create mode 100644 packages/project-client/src/http/serialization/path-serializer.ts create mode 100644 packages/project-client/src/http/serialization/query-serializer.ts create mode 100644 packages/project-client/src/http/transport/request-builder.ts create mode 100644 packages/project-client/src/http/transport/request.ts create mode 100644 packages/project-client/src/http/transport/transport-hook-adapter.ts create mode 100644 packages/project-client/src/http/types.ts delete mode 100644 packages/project-client/src/models.ts delete mode 100644 packages/project-client/src/services/README.md create mode 100644 packages/project-client/src/services/base-service.ts delete mode 100644 packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts delete mode 100644 packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts delete mode 100644 packages/project-client/src/services/broadcasts/models/Topic.ts delete mode 100644 packages/project-client/src/services/broadcasts/models/User.ts create mode 100644 packages/project-client/src/services/broadcasts/models/broadcast-list-response.ts create mode 100644 packages/project-client/src/services/broadcasts/models/channels.ts create mode 100644 packages/project-client/src/services/broadcasts/models/email.ts create mode 100644 packages/project-client/src/services/broadcasts/models/in-app.ts create mode 100644 packages/project-client/src/services/broadcasts/models/index.ts create mode 100644 packages/project-client/src/services/broadcasts/models/mobile-push.ts create mode 100644 packages/project-client/src/services/broadcasts/models/overrides.ts create mode 100644 packages/project-client/src/services/broadcasts/models/providers.ts create mode 100644 packages/project-client/src/services/broadcasts/models/slack.ts create mode 100644 packages/project-client/src/services/broadcasts/models/sms.ts create mode 100644 packages/project-client/src/services/broadcasts/models/web-push.ts delete mode 100644 packages/project-client/src/services/channels/models/ApnsToken.ts delete mode 100644 packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts delete mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts delete mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts delete mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts delete mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts delete mode 100644 packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts delete mode 100644 packages/project-client/src/services/channels/models/DiscardResult.ts delete mode 100644 packages/project-client/src/services/channels/models/FcmToken.ts delete mode 100644 packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts delete mode 100644 packages/project-client/src/services/channels/models/SlackToken.ts delete mode 100644 packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts delete mode 100644 packages/project-client/src/services/channels/models/TeamsToken.ts delete mode 100644 packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts delete mode 100644 packages/project-client/src/services/channels/models/WebPushToken.ts delete mode 100644 packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts create mode 100644 packages/project-client/src/services/channels/models/apns-token-installation-id.ts create mode 100644 packages/project-client/src/services/channels/models/apns-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/apns-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/apns-token.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-1.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-2.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-3.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-4.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-5.ts create mode 100644 packages/project-client/src/services/channels/models/discard-result.ts create mode 100644 packages/project-client/src/services/channels/models/fcm-token-installation-id.ts create mode 100644 packages/project-client/src/services/channels/models/fcm-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/fcm-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/fcm-token.ts create mode 100644 packages/project-client/src/services/channels/models/index.ts create mode 100644 packages/project-client/src/services/channels/models/keys.ts create mode 100644 packages/project-client/src/services/channels/models/oauth.ts create mode 100644 packages/project-client/src/services/channels/models/slack-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/slack-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/slack-token.ts create mode 100644 packages/project-client/src/services/channels/models/teams-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/teams-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/web-push-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/web-push-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/web-push-token.ts create mode 100644 packages/project-client/src/services/channels/models/webhook.ts delete mode 100644 packages/project-client/src/services/integrations/models/ApnsConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/FcmConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/InboxConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts delete mode 100644 packages/project-client/src/services/integrations/models/MailgunConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/PingConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts delete mode 100644 packages/project-client/src/services/integrations/models/SendgridConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/SlackConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/StripeConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/TwilioConfig.ts delete mode 100644 packages/project-client/src/services/integrations/models/WebpushConfig.ts create mode 100644 packages/project-client/src/services/integrations/models/apns-config.ts create mode 100644 packages/project-client/src/services/integrations/models/badge.ts create mode 100644 packages/project-client/src/services/integrations/models/fcm-config.ts create mode 100644 packages/project-client/src/services/integrations/models/inbox-config.ts create mode 100644 packages/project-client/src/services/integrations/models/index.ts create mode 100644 packages/project-client/src/services/integrations/models/integrations.ts create mode 100644 packages/project-client/src/services/integrations/models/list-integrations-response.ts create mode 100644 packages/project-client/src/services/integrations/models/mailgun-config-region.ts create mode 100644 packages/project-client/src/services/integrations/models/mailgun-config.ts create mode 100644 packages/project-client/src/services/integrations/models/ping-config.ts create mode 100644 packages/project-client/src/services/integrations/models/reply-to.ts create mode 100644 packages/project-client/src/services/integrations/models/sendgrid-config.ts create mode 100644 packages/project-client/src/services/integrations/models/slack-config.ts create mode 100644 packages/project-client/src/services/integrations/models/stripe-config.ts create mode 100644 packages/project-client/src/services/integrations/models/twilio-config-region.ts create mode 100644 packages/project-client/src/services/integrations/models/twilio-config.ts create mode 100644 packages/project-client/src/services/integrations/models/type_.ts create mode 100644 packages/project-client/src/services/integrations/models/webpush-config.ts diff --git a/packages/project-client/README.md b/packages/project-client/README.md index 40f9bc5db..e6d18be97 100644 --- a/packages/project-client/README.md +++ b/packages/project-client/README.md @@ -1,1339 +1,134 @@ -# Client Typescript SDK 0.1.0 +# Client TypeScript SDK 0.1.0 -The Typescript SDK for Client. +Welcome to the Client SDK documentation. This guide will help you get started with integrating and using the Client SDK in your project. -- API version: 0.1.0 -- SDK version: 0.1.0 +## Versions -## Table of Contents - -- [About the API](#requirements) -- [Installation](#installation) -- [Authentication](#authentication) - - [Access Token](#access-token) -- [API Endpoint Services](#api-endpoint-services) -- [API Models](#api-models) -- [Sample Usage](#sample-usage) -- [Client Services](#client-services) -- [License](#license) +- API version: `2.0.0` +- SDK version: `0.1.0` ## About the API OpenAPI 3.1.0 Specification for MagicBell API. -## Installation - -```sh -npm install project-client -``` - -## Authentication - -To see whether an endpoint needs a specific type of authentication check the endpoint's documentation. - -### Access Token - -The Client API uses access tokens as a form of authentication. You can set the access token when initializing the SDK through the constructor: - -``` -const sdk = new Client('YOUR_ACCESS_TOKEN') -``` - -Or through the `setAccessToken` method: - -``` -const sdk = new Client() -sdk.setAccessToken('YOUR_ACCESS_TOKEN') -``` - -You can also set it for each service individually: - -``` -const sdk = new Client() -sdk.broadcasts.setAccessToken('YOUR_ACCESS_TOKEN') -``` - -## Sample Usage - -Here is a simple program demonstrating usage of this SDK. It can also be found in the `examples/src/index.ts` file in this directory. - -When running the sample make sure to use `npm install` to install all the dependencies. - -```Typescript -import { Client } from '@magicbell/project-client'; - - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - try { - const result = await sdk.broadcasts - .listBroadcasts(); - console.log(result); - } catch (err) { - const error = err as Error; - console.error(error.message); - } -})(); - - -``` - -# Client Services - -A list of all services and services methods. - -- Services - - - [Broadcasts](#broadcasts) - - - [Integrations](#integrations) - - - [Channels](#channels) - -- [All Methods](#all-methods) - -## Broadcasts - -| Method | Description | -| :---------------------------------- | :---------- | -| [createBroadcast](#createbroadcast) | | -| [listBroadcasts](#listbroadcasts) | | -| [fetchBroadcast](#fetchbroadcast) | | - -## Integrations - -| Method | Description | -| :-------------------------------------------------------- | :---------- | -| [listIntegrations](#listintegrations) | | -| [deleteApnsIntegration](#deleteapnsintegration) | | -| [saveApnsIntegration](#saveapnsintegration) | | -| [deleteFcmIntegration](#deletefcmintegration) | | -| [saveFcmIntegration](#savefcmintegration) | | -| [deleteInboxIntegration](#deleteinboxintegration) | | -| [saveInboxIntegration](#saveinboxintegration) | | -| [deleteMailgunIntegration](#deletemailgunintegration) | | -| [saveMailgunIntegration](#savemailgunintegration) | | -| [deletePingEmailIntegration](#deletepingemailintegration) | | -| [savePingEmailIntegration](#savepingemailintegration) | | -| [deleteSendgridIntegration](#deletesendgridintegration) | | -| [saveSendgridIntegration](#savesendgridintegration) | | -| [deleteSlackIntegration](#deleteslackintegration) | | -| [saveSlackIntegration](#saveslackintegration) | | -| [deleteStripeIntegration](#deletestripeintegration) | | -| [saveStripeIntegration](#savestripeintegration) | | -| [deleteTemplatesIntegration](#deletetemplatesintegration) | | -| [saveTemplatesIntegration](#savetemplatesintegration) | | -| [deleteTwilioIntegration](#deletetwiliointegration) | | -| [saveTwilioIntegration](#savetwiliointegration) | | -| [deleteWebPushIntegration](#deletewebpushintegration) | | -| [saveWebPushIntegration](#savewebpushintegration) | | - -## Channels - -| Method | Description | -| :---------------------------------------------------------------- | :---------- | -| [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | | -| [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | | -| [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | | -| [getMobilePushFcmUserTokens](#getmobilepushfcmusertokens) | | -| [getMobilePushFcmUserToken](#getmobilepushfcmusertoken) | | -| [discardMobilePushFcmUserToken](#discardmobilepushfcmusertoken) | | -| [getSlackUserTokens](#getslackusertokens) | | -| [getSlackUserToken](#getslackusertoken) | | -| [discardSlackUserToken](#discardslackusertoken) | | -| [getTeamsUserTokens](#getteamsusertokens) | | -| [getTeamsUserToken](#getteamsusertoken) | | -| [discardTeamsUserToken](#discardteamsusertoken) | | -| [getWebPushUserTokens](#getwebpushusertokens) | | -| [getWebPushUserToken](#getwebpushusertoken) | | -| [discardWebPushUserToken](#discardwebpushusertoken) | | - -## All Methods - -### **createBroadcast** - -- HTTP Method: POST -- Endpoint: /broadcasts - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -Broadcast - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - action_url: 'https://example.com', - category: 'example', - content: 'Hello, World!', - custom_attributes: {}, - overrides: {}, - recipients: [ - { - custom_attributes: { - plan: 'enterprise', - preferred_pronoun: 'They', - pricing_version: 'v10', - }, - external_id: '83d987a-83fd034', - first_name: 'Person', - last_name: 'Doe', - phone_numbers: ['+1 5005550001'], - }, - ], - title: 'Hello, World!', - topic: 'example', - }; - const result = await sdk.broadcasts.createBroadcast(input); - console.log(result); -})(); - -``` - -### **listBroadcasts** - -- HTTP Method: GET -- Endpoint: /broadcasts - -**Return Type** - -BroadcastListResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.broadcasts.listBroadcasts(); - console.log(result); -})(); - -``` - -### **fetchBroadcast** - -- HTTP Method: GET -- Endpoint: /broadcasts/{broadcast_id} - -**Required Parameters** - -| Name | Type | Description | -| :---------- | :----- | :---------- | -| broadcastId | string | | - -**Return Type** - -Broadcast - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.broadcasts.fetchBroadcast('broadcast_id'); - console.log(result); -})(); - -``` - -### **listIntegrations** - -- HTTP Method: GET -- Endpoint: /integrations - -**Return Type** - -ListIntegrationsResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.listIntegrations(); - console.log(result); -})(); - -``` - -### **deleteApnsIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/apns - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteApnsIntegration(); - console.log(result); -})(); - -``` - -### **saveApnsIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/apns - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -ApnsConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }; - const result = await sdk.integrations.saveApnsIntegration(input); - console.log(result); -})(); - -``` - -### **deleteFcmIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/fcm - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteFcmIntegration(); - console.log(result); -})(); - -``` - -### **saveFcmIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/fcm - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -FcmConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - auth_provider_x509_cert_url: '', - auth_uri: '', - client_email: '', - client_id: '', - client_x509_cert_url: '', - private_key: - '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQ8J\n-----END PRIVATE', - private_key_id: 'e7', - project_id: 'universe-1', - token_uri: '', - type: 'service_account', - universe_domain: 'universe-1.firebaseapp.com', - }; - const result = await sdk.integrations.saveFcmIntegration(input); - console.log(result); -})(); - -``` - -### **deleteInboxIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/inbox - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteInboxIntegration(); - console.log(result); -})(); - -``` - -### **saveInboxIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/inbox - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -InboxConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - apns: { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }, - }; - const result = await sdk.integrations.saveInboxIntegration(input); - console.log(result); -})(); - -``` - -### **deleteMailgunIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/mailgun - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteMailgunIntegration(); - console.log(result); -})(); - -``` - -### **saveMailgunIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/mailgun - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -MailgunConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { api_key: 'mailgun_api_key', domain: 'mailgun_domain', region: 'us' }; - const result = await sdk.integrations.saveMailgunIntegration(input); - console.log(result); -})(); - -``` - -### **deletePingEmailIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/ping_email - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deletePingEmailIntegration(); - console.log(result); -})(); - -``` - -### **savePingEmailIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/ping_email - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -PingConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { url: 'https://example.com/webhook' }; - const result = await sdk.integrations.savePingEmailIntegration(input); - console.log(result); -})(); - -``` - -### **deleteSendgridIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/sendgrid - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteSendgridIntegration(); - console.log(result); -})(); - -``` - -### **saveSendgridIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/sendgrid - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SendgridConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - api_key: 'SG.1234567890', - from: { email: 'matt@magicbell.com', name: 'Matt' }, - reply_to: { email: 'hana@magicbell.com', name: 'Hana' }, - }; - const result = await sdk.integrations.saveSendgridIntegration(input); - console.log(result); -})(); - -``` - -### **deleteSlackIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/slack - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteSlackIntegration(); - console.log(result); -})(); - -``` - -### **saveSlackIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/slack - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SlackConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - app_id: '12345678901', - client_id: '1.0', - client_secret: '12345678901234567890123456789012', - signing_secret: '12345678901234567890123456789012', - }; - const result = await sdk.integrations.saveSlackIntegration(input); - console.log(result); -})(); - -``` - -### **deleteStripeIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/stripe - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteStripeIntegration(); - console.log(result); -})(); - -``` - -### **saveStripeIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/stripe - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -StripeConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - webhook_signing_secret: - 'whsec_e5cf4458caae49ae72d8f275deb9b63bdd41dd5c932c27c9346d428fb9e1d0a0', - }; - const result = await sdk.integrations.saveStripeIntegration(input); - console.log(result); -})(); - -``` - -### **deleteTemplatesIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/templates - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteTemplatesIntegration(); - console.log(result); -})(); - -``` - -### **saveTemplatesIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/templates - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SaveTemplatesIntegrationResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - apns: { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }, - }; - const result = await sdk.integrations.saveTemplatesIntegration(input); - console.log(result); -})(); - -``` - -### **deleteTwilioIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/twilio - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteTwilioIntegration(); - console.log(result); -})(); - -``` - -### **saveTwilioIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/twilio - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -TwilioConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - account_sid: 'ACXXXXXXXX', - api_key: 'SKXXXXXXXX', - api_secret: 'your_api_secret', - from: '+15017122661', - region: 'us1', - }; - const result = await sdk.integrations.saveTwilioIntegration(input); - console.log(result); -})(); - -``` - -### **deleteWebPushIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/web_push - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteWebPushIntegration(); - console.log(result); -})(); - -``` - -### **saveWebPushIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/web_push - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -WebpushConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { private_key: '', public_key: '' }; - const result = await sdk.integrations.saveWebPushIntegration(input); - console.log(result); -})(); - -``` - -### **getMobilePushApnsUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfApnsToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushApnsUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getMobilePushApnsUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -ApnsTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushApnsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardMobilePushApnsUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardMobilePushApnsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getMobilePushFcmUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfFcmToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushFcmUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getMobilePushFcmUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -FcmTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushFcmUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardMobilePushFcmUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardMobilePushFcmUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getSlackUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/slack/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfSlackToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getSlackUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getSlackUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -SlackTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getSlackUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardSlackUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardSlackUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getTeamsUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/teams/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfTeamsToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getTeamsUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getTeamsUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | +## Table of Contents -**Return Type** +- [Setup & Configuration](#setup--configuration) + - [Supported Language Versions](#supported-language-versions) + - [Installation](#installation) +- [Authentication](#authentication) + - [Access Token Authentication](#access-token-authentication) +- [Setting a Custom Timeout](#setting-a-custom-timeout) +- [Services](#services) +- [Models](#models) -TeamsTokenWithMetadata +# Setup & Configuration -**Example Usage Code Snippet** +## Supported Language Versions -```Typescript -import { Client } from '@magicbell/project-client'; +This SDK is compatible with the following versions: `TypeScript >= 4.8.4` -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); +## Installation -(async () => { - const result = await sdk.channels.getTeamsUserToken('user_id', 'token_id'); - console.log(result); -})(); +To get started with the SDK, we recommend installing using `npm`: +```bash +npm install @magicbell/project-client ``` -### **discardTeamsUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** +## Authentication -DiscardResult +### Access Token Authentication -**Example Usage Code Snippet** +The Client API uses an Access Token for authentication. -```Typescript -import { Client } from '@magicbell/project-client'; +This token must be provided to authenticate your requests to the API. -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); +#### Setting the Access Token -(async () => { - const result = await sdk.channels.discardTeamsUserToken('user_id', 'token_id'); - console.log(result); -})(); +When you initialize the SDK, you can set the access token as follows: +```ts +const sdk = new Client({ token: 'YOUR_TOKEN' }); ``` -### **getWebPushUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/web_push/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfWebPushToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getWebPushUserTokens('user_id'); - console.log(result); -})(); +If you need to set or update the access token after initializing the SDK, you can use: +```ts +const sdk = new Client(); +sdk.token = 'YOUR_TOKEN'; ``` -### **getWebPushUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -WebPushTokenWithMetadata +## Setting a Custom Timeout -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getWebPushUserToken('user_id', 'token_id'); - console.log(result); -})(); +You can set a custom timeout for the SDK's HTTP requests as follows: +```ts +const client = new Client({ timeout: 10000 }); ``` -### **discardWebPushUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} +## Services -**Required Parameters** +The SDK provides various services to interact with the API. -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | +
+Below is a list of all available services with links to their detailed documentation: -**Return Type** +| Name | +| :------------------------------------------------------------------- | +| [BroadcastsService](documentation/services/BroadcastsService.md) | +| [IntegrationsService](documentation/services/IntegrationsService.md) | +| [JwtService](documentation/services/JwtService.md) | +| [ChannelsService](documentation/services/ChannelsService.md) | -DiscardResult +
-**Example Usage Code Snippet** +## Models -```Typescript -import { Client } from '@magicbell/project-client'; +The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently. -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardWebPushUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` +
+Below is a list of all available models with links to their detailed documentation: -## License +| Name | Description | +| :----------------------------------------------------------------------------------------- | :---------- | +| [BroadcastListResponse](documentation/models/BroadcastListResponse.md) | | +| [Broadcast](documentation/models/Broadcast.md) | | +| [ListIntegrationsResponse](documentation/models/ListIntegrationsResponse.md) | | +| [ApnsConfig](documentation/models/ApnsConfig.md) | | +| [FcmConfig](documentation/models/FcmConfig.md) | | +| [GithubConfig](documentation/models/GithubConfig.md) | | +| [InboxConfig](documentation/models/InboxConfig.md) | | +| [MailgunConfig](documentation/models/MailgunConfig.md) | | +| [PingConfig](documentation/models/PingConfig.md) | | +| [SendgridConfig](documentation/models/SendgridConfig.md) | | +| [SesConfig](documentation/models/SesConfig.md) | | +| [SlackConfig](documentation/models/SlackConfig.md) | | +| [StripeConfig](documentation/models/StripeConfig.md) | | +| [TwilioConfig](documentation/models/TwilioConfig.md) | | +| [WebpushConfig](documentation/models/WebpushConfig.md) | | +| [FetchTokensResponse](documentation/models/FetchTokensResponse.md) | | +| [CreateProjectTokenRequest](documentation/models/CreateProjectTokenRequest.md) | | +| [AccessToken](documentation/models/AccessToken.md) | | +| [DiscardTokenResponse](documentation/models/DiscardTokenResponse.md) | | +| [CreateUserTokenRequest](documentation/models/CreateUserTokenRequest.md) | | +| [ArrayWithMetadataOfInboxToken](documentation/models/ArrayWithMetadataOfInboxToken.md) | | +| [InboxTokenWithMetadata](documentation/models/InboxTokenWithMetadata.md) | | +| [DiscardResult](documentation/models/DiscardResult.md) | | +| [ArrayWithMetadataOfApnsToken](documentation/models/ArrayWithMetadataOfApnsToken.md) | | +| [ApnsTokenWithMetadata](documentation/models/ApnsTokenWithMetadata.md) | | +| [ArrayWithMetadataOfFcmToken](documentation/models/ArrayWithMetadataOfFcmToken.md) | | +| [FcmTokenWithMetadata](documentation/models/FcmTokenWithMetadata.md) | | +| [ArrayWithMetadataOfSlackToken](documentation/models/ArrayWithMetadataOfSlackToken.md) | | +| [SlackTokenWithMetadata](documentation/models/SlackTokenWithMetadata.md) | | +| [ArrayWithMetadataOfTeamsToken](documentation/models/ArrayWithMetadataOfTeamsToken.md) | | +| [TeamsTokenWithMetadata](documentation/models/TeamsTokenWithMetadata.md) | | +| [ArrayWithMetadataOfWebPushToken](documentation/models/ArrayWithMetadataOfWebPushToken.md) | | +| [WebPushTokenWithMetadata](documentation/models/WebPushTokenWithMetadata.md) | | +| [InboxToken](documentation/models/InboxToken.md) | | +| [ApnsToken](documentation/models/ApnsToken.md) | | +| [FcmToken](documentation/models/FcmToken.md) | | +| [SlackToken](documentation/models/SlackToken.md) | | +| [WebPushToken](documentation/models/WebPushToken.md) | | -See license in LICENSE. +
diff --git a/packages/project-client/docs/models/ApnsConfig.md b/packages/project-client/docs/models/ApnsConfig.md new file mode 100644 index 000000000..b6006bf14 --- /dev/null +++ b/packages/project-client/docs/models/ApnsConfig.md @@ -0,0 +1,20 @@ +# ApnsConfig + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| appId | string | ✅ | | +| badge | Badge | ✅ | | +| certificate | string | ✅ | | +| keyId | string | ✅ | | +| teamId | string | ✅ | | + +# Badge + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| UNREAD | string | ✅ | "unread" | +| UNSEEN | string | ✅ | "unseen" | diff --git a/packages/project-client/docs/models/ApnsToken.md b/packages/project-client/docs/models/ApnsToken.md new file mode 100644 index 000000000..c7a7ce850 --- /dev/null +++ b/packages/project-client/docs/models/ApnsToken.md @@ -0,0 +1,17 @@ +# ApnsToken + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :---------------------- | :------- | :---------- | +| deviceToken | string | ✅ | | +| installationId | ApnsTokenInstallationId | ❌ | | + +# ApnsTokenInstallationId + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/project-client/docs/models/ApnsTokenWithMetadata.md b/packages/project-client/docs/models/ApnsTokenWithMetadata.md new file mode 100644 index 000000000..dff58f5e2 --- /dev/null +++ b/packages/project-client/docs/models/ApnsTokenWithMetadata.md @@ -0,0 +1,19 @@ +# ApnsTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :---------------------------- | :------- | :---------- | +| data | ApnsToken | ✅ | | +| metadata | ApnsTokenWithMetadataMetadata | ✅ | | + +# ApnsTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfApnsToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfApnsToken.md new file mode 100644 index 000000000..802e12a2a --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfApnsToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfApnsToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :--------------------------------- | :------- | :---------- | +| data | ArrayWithMetadataOfApnsTokenData[] | ✅ | | + +# ArrayWithMetadataOfApnsTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | ApnsToken | ✅ | | +| metadata | DataMetadata2 | ✅ | | + +# DataMetadata2 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfFcmToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfFcmToken.md new file mode 100644 index 000000000..201103a9a --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfFcmToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfFcmToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :-------------------------------- | :------- | :---------- | +| data | ArrayWithMetadataOfFcmTokenData[] | ✅ | | + +# ArrayWithMetadataOfFcmTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | FcmToken | ✅ | | +| metadata | DataMetadata3 | ✅ | | + +# DataMetadata3 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfSlackToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfSlackToken.md new file mode 100644 index 000000000..e00cd4f62 --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfSlackToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfSlackToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------- | +| data | ArrayWithMetadataOfSlackTokenData[] | ✅ | | + +# ArrayWithMetadataOfSlackTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | SlackToken | ✅ | | +| metadata | DataMetadata4 | ✅ | | + +# DataMetadata4 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfTeamsToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfTeamsToken.md new file mode 100644 index 000000000..d3b3c426c --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfTeamsToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfTeamsToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------- | +| data | ArrayWithMetadataOfTeamsTokenData[] | ✅ | | + +# ArrayWithMetadataOfTeamsTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | any | ✅ | | +| metadata | DataMetadata5 | ✅ | | + +# DataMetadata5 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfWebPushToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfWebPushToken.md new file mode 100644 index 000000000..9568193a1 --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfWebPushToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfWebPushToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :------------------------------------ | :------- | :---------- | +| data | ArrayWithMetadataOfWebPushTokenData[] | ✅ | | + +# ArrayWithMetadataOfWebPushTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | WebPushToken | ✅ | | +| metadata | DataMetadata6 | ✅ | | + +# DataMetadata6 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/Broadcast.md b/packages/project-client/docs/models/Broadcast.md new file mode 100644 index 000000000..551cd09c8 --- /dev/null +++ b/packages/project-client/docs/models/Broadcast.md @@ -0,0 +1,110 @@ +# Broadcast + +**Properties** + +| Name | Type | Required | Description | +| :--------------- | :-------- | :------- | :---------- | +| recipients | any[] | ✅ | | +| title | string | ✅ | | +| actionUrl | string | ❌ | | +| category | string | ❌ | | +| content | string | ❌ | | +| customAttributes | any | ❌ | | +| overrides | Overrides | ❌ | | +| topic | string | ❌ | | + +# Overrides + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :-------- | :------- | :---------- | +| channels | Channels | ❌ | | +| providers | Providers | ❌ | | + +# Channels + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :--------- | :------- | :---------- | +| email | Email | ❌ | | +| inApp | InApp | ❌ | | +| mobilePush | MobilePush | ❌ | | +| slack | Slack | ❌ | | +| sms | Sms | ❌ | | +| webPush | WebPush | ❌ | | + +# Email + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# InApp + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# MobilePush + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# Slack + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# Sms + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# WebPush + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| actionUrl | string | ❌ | | +| content | string | ❌ | | +| title | string | ❌ | | + +# Providers + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :--- | :------- | :---------- | +| amazonSes | any | ❌ | | +| android | any | ❌ | | +| ios | any | ❌ | | +| mailgun | any | ❌ | | +| postmark | any | ❌ | | +| sendgrid | any | ❌ | | +| slack | any | ❌ | | diff --git a/packages/project-client/docs/models/BroadcastListResponse.md b/packages/project-client/docs/models/BroadcastListResponse.md new file mode 100644 index 000000000..39fe994fd --- /dev/null +++ b/packages/project-client/docs/models/BroadcastListResponse.md @@ -0,0 +1,9 @@ +# BroadcastListResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :---------- | :------- | :--------------------------- | +| currentPage | number | ✅ | Number of the page returned. | +| perPage | number | ✅ | Number of entities per page. | +| broadcasts | Broadcast[] | ✅ | | diff --git a/packages/project-client/docs/models/DiscardResult.md b/packages/project-client/docs/models/DiscardResult.md new file mode 100644 index 000000000..083d20e7d --- /dev/null +++ b/packages/project-client/docs/models/DiscardResult.md @@ -0,0 +1,8 @@ +# DiscardResult + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| discardedAt | string | ❌ | | +| id | string | ❌ | | diff --git a/packages/project-client/docs/models/FcmConfig.md b/packages/project-client/docs/models/FcmConfig.md new file mode 100644 index 000000000..d5fe72a5e --- /dev/null +++ b/packages/project-client/docs/models/FcmConfig.md @@ -0,0 +1,25 @@ +# FcmConfig + +**Properties** + +| Name | Type | Required | Description | +| :---------------------- | :----- | :------- | :---------- | +| authProviderX509CertUrl | string | ✅ | | +| authUri | string | ✅ | | +| clientEmail | string | ✅ | | +| clientId | string | ✅ | | +| clientX509CertUrl | string | ✅ | | +| privateKey | string | ✅ | | +| privateKeyId | string | ✅ | | +| projectId | string | ✅ | | +| tokenUri | string | ✅ | | +| type | Type\_ | ✅ | | +| universeDomain | string | ✅ | | + +# Type\_ + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----- | :------- | :---------------- | +| SERVICEACCOUNT | string | ✅ | "service_account" | diff --git a/packages/project-client/docs/models/FcmToken.md b/packages/project-client/docs/models/FcmToken.md new file mode 100644 index 000000000..b4548ec28 --- /dev/null +++ b/packages/project-client/docs/models/FcmToken.md @@ -0,0 +1,17 @@ +# FcmToken + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :--------------------- | :------- | :---------- | +| deviceToken | string | ✅ | | +| installationId | FcmTokenInstallationId | ❌ | | + +# FcmTokenInstallationId + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :------------ | +| DEVELOPMENT | string | ✅ | "development" | +| PRODUCTION | string | ✅ | "production" | diff --git a/packages/project-client/docs/models/FcmTokenWithMetadata.md b/packages/project-client/docs/models/FcmTokenWithMetadata.md new file mode 100644 index 000000000..554e9832e --- /dev/null +++ b/packages/project-client/docs/models/FcmTokenWithMetadata.md @@ -0,0 +1,19 @@ +# FcmTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :--------------------------- | :------- | :---------- | +| data | FcmToken | ✅ | | +| metadata | FcmTokenWithMetadataMetadata | ✅ | | + +# FcmTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/InboxConfig.md b/packages/project-client/docs/models/InboxConfig.md new file mode 100644 index 000000000..6d7cda954 --- /dev/null +++ b/packages/project-client/docs/models/InboxConfig.md @@ -0,0 +1,9 @@ +# InboxConfig + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| images | any | ✅ | | +| locale | string | ✅ | | +| theme | any | ✅ | | diff --git a/packages/project-client/docs/models/ListIntegrationsResponse.md b/packages/project-client/docs/models/ListIntegrationsResponse.md new file mode 100644 index 000000000..93b5da48d --- /dev/null +++ b/packages/project-client/docs/models/ListIntegrationsResponse.md @@ -0,0 +1,17 @@ +# ListIntegrationsResponse + +**Properties** + +| Name | Type | Required | Description | +| :----------- | :------------- | :------- | :---------- | +| integrations | Integrations[] | ❌ | | + +# Integrations + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| config | any | ❌ | | +| id | string | ❌ | | +| name | string | ❌ | | diff --git a/packages/project-client/docs/models/MailgunConfig.md b/packages/project-client/docs/models/MailgunConfig.md new file mode 100644 index 000000000..f4c6435b9 --- /dev/null +++ b/packages/project-client/docs/models/MailgunConfig.md @@ -0,0 +1,18 @@ +# MailgunConfig + +**Properties** + +| Name | Type | Required | Description | +| :----- | :------------------ | :------- | :---------- | +| apiKey | string | ✅ | | +| domain | string | ✅ | | +| region | MailgunConfigRegion | ✅ | | + +# MailgunConfigRegion + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| US | string | ✅ | "us" | +| EU | string | ✅ | "eu" | diff --git a/packages/project-client/docs/models/PingConfig.md b/packages/project-client/docs/models/PingConfig.md new file mode 100644 index 000000000..4350c6fe8 --- /dev/null +++ b/packages/project-client/docs/models/PingConfig.md @@ -0,0 +1,7 @@ +# PingConfig + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ✅ | URL to ping | diff --git a/packages/project-client/docs/models/SendgridConfig.md b/packages/project-client/docs/models/SendgridConfig.md new file mode 100644 index 000000000..00ed1cc62 --- /dev/null +++ b/packages/project-client/docs/models/SendgridConfig.md @@ -0,0 +1,27 @@ +# SendgridConfig + +**Properties** + +| Name | Type | Required | Description | +| :------ | :----------------- | :------- | :----------------------- | +| apiKey | string | ✅ | The API key for Sendgrid | +| from | SendgridConfigFrom | ❌ | | +| replyTo | ReplyTo | ❌ | | + +# SendgridConfigFrom + +**Properties** + +| Name | Type | Required | Description | +| :---- | :----- | :------- | :----------------------------- | +| email | string | ✅ | The email address to send from | +| name | string | ❌ | The name to send from | + +# ReplyTo + +**Properties** + +| Name | Type | Required | Description | +| :---- | :----- | :------- | :---------------------------- | +| email | string | ✅ | The email address to reply to | +| name | string | ❌ | The name to reply to | diff --git a/packages/project-client/docs/models/SlackConfig.md b/packages/project-client/docs/models/SlackConfig.md new file mode 100644 index 000000000..0366f21d9 --- /dev/null +++ b/packages/project-client/docs/models/SlackConfig.md @@ -0,0 +1,11 @@ +# SlackConfig + +**Properties** + +| Name | Type | Required | Description | +| :------------ | :----- | :------- | :---------- | +| appId | string | ✅ | | +| clientId | string | ✅ | | +| clientSecret | string | ✅ | | +| signingSecret | string | ✅ | | +| id | string | ❌ | | diff --git a/packages/project-client/docs/models/SlackToken.md b/packages/project-client/docs/models/SlackToken.md new file mode 100644 index 000000000..03697085b --- /dev/null +++ b/packages/project-client/docs/models/SlackToken.md @@ -0,0 +1,26 @@ +# SlackToken + +**Properties** + +| Name | Type | Required | Description | +| :------ | :------ | :------- | :---------- | +| oauth | Oauth | ❌ | | +| webhook | Webhook | ❌ | | + +# Oauth + +**Properties** + +| Name | Type | Required | Description | +| :------------- | :----- | :------- | :---------- | +| channelId | string | ✅ | | +| installationId | string | ✅ | | +| scope | string | ❌ | | + +# Webhook + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| url | string | ✅ | | diff --git a/packages/project-client/docs/models/SlackTokenWithMetadata.md b/packages/project-client/docs/models/SlackTokenWithMetadata.md new file mode 100644 index 000000000..4bb1dd6ef --- /dev/null +++ b/packages/project-client/docs/models/SlackTokenWithMetadata.md @@ -0,0 +1,19 @@ +# SlackTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :----------------------------- | :------- | :---------- | +| data | SlackToken | ✅ | | +| metadata | SlackTokenWithMetadataMetadata | ✅ | | + +# SlackTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/StripeConfig.md b/packages/project-client/docs/models/StripeConfig.md new file mode 100644 index 000000000..6a3a79ea3 --- /dev/null +++ b/packages/project-client/docs/models/StripeConfig.md @@ -0,0 +1,7 @@ +# StripeConfig + +**Properties** + +| Name | Type | Required | Description | +| :------------------- | :----- | :------- | :--------------------------------------------------------- | +| webhookSigningSecret | string | ✅ | The signing secret to verify incoming requests from Stripe | diff --git a/packages/project-client/docs/models/TeamsTokenWithMetadata.md b/packages/project-client/docs/models/TeamsTokenWithMetadata.md new file mode 100644 index 000000000..780c16eca --- /dev/null +++ b/packages/project-client/docs/models/TeamsTokenWithMetadata.md @@ -0,0 +1,19 @@ +# TeamsTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :----------------------------- | :------- | :---------- | +| data | any | ✅ | | +| metadata | TeamsTokenWithMetadataMetadata | ✅ | | + +# TeamsTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/TwilioConfig.md b/packages/project-client/docs/models/TwilioConfig.md new file mode 100644 index 000000000..1a6a63cb8 --- /dev/null +++ b/packages/project-client/docs/models/TwilioConfig.md @@ -0,0 +1,23 @@ +# TwilioConfig + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :----------------- | :------- | :---------------------------------------------- | +| accountSid | string | ✅ | The SID for your Twilio account | +| apiKey | string | ✅ | The API key for Twilio | +| apiSecret | string | ✅ | The API Secret for Twilio | +| from | string | ✅ | The phone number to send from, in E.164 format | +| region | TwilioConfigRegion | ❌ | The region to use for Twilio, defaults to 'us1' | + +# TwilioConfigRegion + +The region to use for Twilio, defaults to 'us1' + +**Properties** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| US1 | string | ✅ | "us1" | +| IE1 | string | ✅ | "ie1" | +| AU1 | string | ✅ | "au1" | diff --git a/packages/project-client/docs/models/WebPushToken.md b/packages/project-client/docs/models/WebPushToken.md new file mode 100644 index 000000000..23e8a46df --- /dev/null +++ b/packages/project-client/docs/models/WebPushToken.md @@ -0,0 +1,17 @@ +# WebPushToken + +**Properties** + +| Name | Type | Required | Description | +| :------- | :----- | :------- | :---------- | +| endpoint | string | ✅ | | +| keys | Keys | ✅ | | + +# Keys + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| auth | string | ✅ | | +| p256dh | string | ✅ | | diff --git a/packages/project-client/docs/models/WebPushTokenWithMetadata.md b/packages/project-client/docs/models/WebPushTokenWithMetadata.md new file mode 100644 index 000000000..21d9e1bea --- /dev/null +++ b/packages/project-client/docs/models/WebPushTokenWithMetadata.md @@ -0,0 +1,19 @@ +# WebPushTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------------------------- | :------- | :---------- | +| data | WebPushToken | ✅ | | +| metadata | WebPushTokenWithMetadataMetadata | ✅ | | + +# WebPushTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/WebpushConfig.md b/packages/project-client/docs/models/WebpushConfig.md new file mode 100644 index 000000000..7bb99601b --- /dev/null +++ b/packages/project-client/docs/models/WebpushConfig.md @@ -0,0 +1,8 @@ +# WebpushConfig + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :----- | :------- | :---------- | +| privateKey | string | ✅ | | +| publicKey | string | ✅ | | diff --git a/packages/project-client/docs/services/BroadcastsService.md b/packages/project-client/docs/services/BroadcastsService.md new file mode 100644 index 000000000..3e17416fd --- /dev/null +++ b/packages/project-client/docs/services/BroadcastsService.md @@ -0,0 +1,183 @@ +# BroadcastsService + +A list of all methods in the `BroadcastsService` service. Click on the method name to view detailed information about that method. + +| Methods | Description | +| :------------------------------------ | :--------------------------------------- | +| [list_broadcasts](#list_broadcasts) | Returns a list of broadcasts | +| [create_broadcast](#create_broadcast) | Handles the create notification request. | +| [fetch_broadcast](#fetch_broadcast) | Returns a broadcast | + +## list_broadcasts + +Returns a list of broadcasts + +- HTTP Method: `GET` +- Endpoint: `/broadcasts` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :-------------------------------------------------------- | +| page | number | ❌ | The page number of the paginated response. Defaults to 1. | +| perPage | number | ❌ | The number of items per page. Defaults to 20. | + +**Return Type** + +`BroadcastListResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.broadcasts.listBroadcasts({ + page: 8, + perPage: 2, + }); + + console.log(data); +})(); +``` + +## create_broadcast + +Handles the create notification request. + +- HTTP Method: `POST` +- Endpoint: `/broadcasts` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------------- | +| body | [Broadcast](../models/Broadcast.md) | ❌ | The request body. | + +**Return Type** + +`Broadcast` + +**Example Usage Code Snippet** + +```typescript +import { Broadcast, Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const email: Email = { + actionUrl: 'nisi ea Duis ipsum', + content: 'commodo', + title: 'enim', + }; + + const inApp: InApp = { + actionUrl: 'commodo reprehenderit', + content: 'aliqua occaecat', + title: 'amet', + }; + + const mobilePush: MobilePush = { + actionUrl: 'essead consectetur elit', + content: 'nostrud aliqua sed irure', + title: 'enim dolore', + }; + + const slack: Slack = { + actionUrl: 'id non occaecat cupidatat ad', + content: 'nostrud', + title: 'laborum commodo magna', + }; + + const sms: Sms = { + actionUrl: 'exdolore elit', + content: 'Excepteur occaecat eu ipsum', + title: 'in', + }; + + const webPush: WebPush = { + actionUrl: 'ipsum magna', + content: 'eiusmod', + title: 'cupidatat Lorem sed', + }; + + const channels: Channels = { + email: email, + inApp: inApp, + mobilePush: mobilePush, + slack: slack, + sms: sms, + webPush: webPush, + }; + + const providers: Providers = { + amazonSes: {}, + android: {}, + ios: {}, + mailgun: {}, + postmark: {}, + sendgrid: {}, + slack: {}, + }; + + const overrides: Overrides = { + channels: channels, + providers: providers, + }; + + const broadcast: Broadcast = { + actionUrl: 'sed incididunt', + category: 'non officia', + content: 'qui enim sunt ea dolor', + customAttributes: {}, + overrides: overrides, + recipients: [{}], + title: 'quis fugiat', + topic: 'mollit ut consecte', + }; + + const { data } = await client.broadcasts.createBroadcast(input); + + console.log(data); +})(); +``` + +## fetch_broadcast + +Returns a broadcast + +- HTTP Method: `GET` +- Endpoint: `/broadcasts/{broadcast_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| broadcastId | string | ✅ | | + +**Return Type** + +`Broadcast` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.broadcasts.fetchBroadcast('broadcast_id'); + + console.log(data); +})(); +``` diff --git a/packages/project-client/docs/services/ChannelsService.md b/packages/project-client/docs/services/ChannelsService.md new file mode 100644 index 000000000..a3479444f --- /dev/null +++ b/packages/project-client/docs/services/ChannelsService.md @@ -0,0 +1,594 @@ +# ChannelsService + +A list of all methods in the `ChannelsService` service. Click on the method name to view detailed information about that method. + +| Methods | Description | +| :-------------------------------------------------------------------------- | :---------- | +| [get_in_app_user_tokens](#get_in_app_user_tokens) | | +| [get_in_app_user_token](#get_in_app_user_token) | | +| [discard_in_app_user_token](#discard_in_app_user_token) | | +| [get_mobile_push_apns_user_tokens](#get_mobile_push_apns_user_tokens) | | +| [get_mobile_push_apns_user_token](#get_mobile_push_apns_user_token) | | +| [discard_mobile_push_apns_user_token](#discard_mobile_push_apns_user_token) | | +| [get_mobile_push_fcm_user_tokens](#get_mobile_push_fcm_user_tokens) | | +| [get_mobile_push_fcm_user_token](#get_mobile_push_fcm_user_token) | | +| [discard_mobile_push_fcm_user_token](#discard_mobile_push_fcm_user_token) | | +| [get_slack_user_tokens](#get_slack_user_tokens) | | +| [get_slack_user_token](#get_slack_user_token) | | +| [discard_slack_user_token](#discard_slack_user_token) | | +| [get_teams_user_tokens](#get_teams_user_tokens) | | +| [get_teams_user_token](#get_teams_user_token) | | +| [discard_teams_user_token](#discard_teams_user_token) | | +| [get_web_push_user_tokens](#get_web_push_user_tokens) | | +| [get_web_push_user_token](#get_web_push_user_token) | | +| [discard_web_push_user_token](#discard_web_push_user_token) | | + +## get_in_app_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/in_app/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfInboxToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getInAppUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_in_app_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/in_app/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`InboxTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getInAppUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_in_app_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/in_app/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardInAppUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## get_mobile_push_apns_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/mobile_push/apns/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfApnsToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getMobilePushApnsUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_mobile_push_apns_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`ApnsTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getMobilePushApnsUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_mobile_push_apns_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardMobilePushApnsUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## get_mobile_push_fcm_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/mobile_push/fcm/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfFcmToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getMobilePushFcmUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_mobile_push_fcm_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`FcmTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getMobilePushFcmUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_mobile_push_fcm_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardMobilePushFcmUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## get_slack_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/slack/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfSlackToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getSlackUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_slack_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/slack/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`SlackTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getSlackUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_slack_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/slack/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardSlackUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## get_teams_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/teams/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfTeamsToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getTeamsUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_teams_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/teams/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`TeamsTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getTeamsUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_teams_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/teams/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardTeamsUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## get_web_push_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/web_push/tokens` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`ArrayWithMetadataOfWebPushToken` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getWebPushUserTokens('user_id'); + + console.log(data); +})(); +``` + +## get_web_push_user_token + +- HTTP Method: `GET` +- Endpoint: `/users/{user_id}/channels/web_push/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`WebPushTokenWithMetadata` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.getWebPushUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` + +## discard_web_push_user_token + +- HTTP Method: `DELETE` +- Endpoint: `/users/{user_id}/channels/web_push/tokens/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| userId | string | ✅ | | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardResult` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.channels.discardWebPushUserToken('user_id', 'token_id'); + + console.log(data); +})(); +``` diff --git a/packages/project-client/docs/services/IntegrationsService.md b/packages/project-client/docs/services/IntegrationsService.md new file mode 100644 index 000000000..b016b10dd --- /dev/null +++ b/packages/project-client/docs/services/IntegrationsService.md @@ -0,0 +1,1542 @@ +# IntegrationsService + +A list of all methods in the `IntegrationsService` service. Click on the method name to view detailed information about that method. + +| Methods | Description | +| :-------------------------------------------------------------------------- | :---------- | +| [list_integrations](#list_integrations) | | +| [get_apns_integration](#get_apns_integration) | | +| [save_apns_integration](#save_apns_integration) | | +| [delete_apns_integration](#delete_apns_integration) | | +| [delete_apns_integration_by_id](#delete_apns_integration_by_id) | | +| [get_fcm_integration](#get_fcm_integration) | | +| [save_fcm_integration](#save_fcm_integration) | | +| [delete_fcm_integration](#delete_fcm_integration) | | +| [delete_fcm_integration_by_id](#delete_fcm_integration_by_id) | | +| [get_github_integration](#get_github_integration) | | +| [save_github_integration](#save_github_integration) | | +| [delete_github_integration](#delete_github_integration) | | +| [delete_github_integration_by_id](#delete_github_integration_by_id) | | +| [get_inbox_integration](#get_inbox_integration) | | +| [save_inbox_integration](#save_inbox_integration) | | +| [delete_inbox_integration](#delete_inbox_integration) | | +| [delete_inbox_integration_by_id](#delete_inbox_integration_by_id) | | +| [get_mailgun_integration](#get_mailgun_integration) | | +| [save_mailgun_integration](#save_mailgun_integration) | | +| [delete_mailgun_integration](#delete_mailgun_integration) | | +| [delete_mailgun_integration_by_id](#delete_mailgun_integration_by_id) | | +| [get_ping_email_integration](#get_ping_email_integration) | | +| [save_ping_email_integration](#save_ping_email_integration) | | +| [delete_ping_email_integration](#delete_ping_email_integration) | | +| [delete_ping_email_integration_by_id](#delete_ping_email_integration_by_id) | | +| [get_sendgrid_integration](#get_sendgrid_integration) | | +| [save_sendgrid_integration](#save_sendgrid_integration) | | +| [delete_sendgrid_integration](#delete_sendgrid_integration) | | +| [delete_sendgrid_integration_by_id](#delete_sendgrid_integration_by_id) | | +| [get_ses_integration](#get_ses_integration) | | +| [save_ses_integration](#save_ses_integration) | | +| [delete_ses_integration](#delete_ses_integration) | | +| [delete_ses_integration_by_id](#delete_ses_integration_by_id) | | +| [get_slack_integration](#get_slack_integration) | | +| [save_slack_integration](#save_slack_integration) | | +| [delete_slack_integration](#delete_slack_integration) | | +| [delete_slack_integration_by_id](#delete_slack_integration_by_id) | | +| [get_stripe_integration](#get_stripe_integration) | | +| [save_stripe_integration](#save_stripe_integration) | | +| [delete_stripe_integration](#delete_stripe_integration) | | +| [delete_stripe_integration_by_id](#delete_stripe_integration_by_id) | | +| [get_templates_integration](#get_templates_integration) | | +| [save_templates_integration](#save_templates_integration) | | +| [delete_templates_integration](#delete_templates_integration) | | +| [delete_templates_integration_by_id](#delete_templates_integration_by_id) | | +| [get_twilio_integration](#get_twilio_integration) | | +| [save_twilio_integration](#save_twilio_integration) | | +| [delete_twilio_integration](#delete_twilio_integration) | | +| [delete_twilio_integration_by_id](#delete_twilio_integration_by_id) | | +| [get_web_push_integration](#get_web_push_integration) | | +| [save_web_push_integration](#save_web_push_integration) | | +| [delete_web_push_integration](#delete_web_push_integration) | | +| [delete_web_push_integration_by_id](#delete_web_push_integration_by_id) | | + +## list_integrations + +- HTTP Method: `GET` +- Endpoint: `/integrations` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.listIntegrations(); + + console.log(data); +})(); +``` + +## get_apns_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/apns` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getApnsIntegration(); + + console.log(data); +})(); +``` + +## save_apns_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/apns` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------ | :------- | :---------------- | +| body | [ApnsConfig](../models/ApnsConfig.md) | ❌ | The request body. | + +**Return Type** + +`ApnsConfig` + +**Example Usage Code Snippet** + +```typescript +import { ApnsConfig, Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const badge = Badge.UNREAD; + + const apnsConfig: ApnsConfig = { + appId: 'Fd8+9', + badge: badge, + certificate: 'certificate', + keyId: 'magna nost', + teamId: 'officia oc', + }; + + const { data } = await client.integrations.saveApnsIntegration(input); + + console.log(data); +})(); +``` + +## delete_apns_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/apns` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteApnsIntegration(); + + console.log(data); +})(); +``` + +## delete_apns_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/apns/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteApnsIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_fcm_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/fcm` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getFcmIntegration(); + + console.log(data); +})(); +``` + +## save_fcm_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/fcm` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------------- | +| body | [FcmConfig](../models/FcmConfig.md) | ❌ | The request body. | + +**Return Type** + +`FcmConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, FcmConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const type_ = Type_.SERVICEACCOUNT; + + const fcmConfig: FcmConfig = { + authProviderX509CertUrl: 'auth_provider_x509_cert_url', + authUri: 'auth_uri', + clientEmail: 'client_email', + clientId: 'client_id', + clientX509CertUrl: 'client_x509_cert_url', + privateKey: 'private_key', + privateKeyId: 'private_key_id', + projectId: 'project_id', + tokenUri: 'token_uri', + type: type_, + universeDomain: 'universe_domain', + }; + + const { data } = await client.integrations.saveFcmIntegration(input); + + console.log(data); +})(); +``` + +## delete_fcm_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/fcm` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteFcmIntegration(); + + console.log(data); +})(); +``` + +## delete_fcm_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/fcm/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteFcmIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_github_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/github` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getGithubIntegration(); + + console.log(data); +})(); +``` + +## save_github_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/github` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------------- | :------- | :---------------- | +| body | [GithubConfig](../models/GithubConfig.md) | ❌ | The request body. | + +**Return Type** + +`GithubConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, GithubConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const githubConfig: GithubConfig = { + webhookSigningSecret: 'dolore', + }; + + const { data } = await client.integrations.saveGithubIntegration(input); + + console.log(data); +})(); +``` + +## delete_github_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/github` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteGithubIntegration(); + + console.log(data); +})(); +``` + +## delete_github_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/github/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteGithubIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_inbox_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/inbox` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getInboxIntegration(); + + console.log(data); +})(); +``` + +## save_inbox_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/inbox` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :-------------------------------------- | :------- | :---------------- | +| body | [InboxConfig](../models/InboxConfig.md) | ❌ | The request body. | + +**Return Type** + +`InboxConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, InboxConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const inboxConfig: InboxConfig = { + images: {}, + locale: 'qui', + theme: {}, + }; + + const { data } = await client.integrations.saveInboxIntegration(input); + + console.log(data); +})(); +``` + +## delete_inbox_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/inbox` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteInboxIntegration(); + + console.log(data); +})(); +``` + +## delete_inbox_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/inbox/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteInboxIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_mailgun_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/mailgun` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getMailgunIntegration(); + + console.log(data); +})(); +``` + +## save_mailgun_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/mailgun` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------------ | :------- | :---------------- | +| body | [MailgunConfig](../models/MailgunConfig.md) | ❌ | The request body. | + +**Return Type** + +`MailgunConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, MailgunConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const mailgunConfigRegion = MailgunConfigRegion.US; + + const mailgunConfig: MailgunConfig = { + apiKey: 'co', + domain: 'm', + region: mailgunConfigRegion, + }; + + const { data } = await client.integrations.saveMailgunIntegration(input); + + console.log(data); +})(); +``` + +## delete_mailgun_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/mailgun` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteMailgunIntegration(); + + console.log(data); +})(); +``` + +## delete_mailgun_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/mailgun/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteMailgunIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_ping_email_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/ping_email` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getPingEmailIntegration(); + + console.log(data); +})(); +``` + +## save_ping_email_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/ping_email` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------ | :------- | :---------------- | +| body | [PingConfig](../models/PingConfig.md) | ❌ | The request body. | + +**Return Type** + +`PingConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, PingConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const pingConfig: PingConfig = { + url: 'ut cupidatat', + }; + + const { data } = await client.integrations.savePingEmailIntegration(input); + + console.log(data); +})(); +``` + +## delete_ping_email_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/ping_email` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deletePingEmailIntegration(); + + console.log(data); +})(); +``` + +## delete_ping_email_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/ping_email/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deletePingEmailIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_sendgrid_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/sendgrid` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getSendgridIntegration(); + + console.log(data); +})(); +``` + +## save_sendgrid_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/sendgrid` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :-------------------------------------------- | :------- | :---------------- | +| body | [SendgridConfig](../models/SendgridConfig.md) | ❌ | The request body. | + +**Return Type** + +`SendgridConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, SendgridConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const sendgridConfigFrom: SendgridConfigFrom = { + email: 'email', + name: 'name', + }; + + const replyTo: ReplyTo = { + email: 'email', + name: 'name', + }; + + const sendgridConfig: SendgridConfig = { + apiKey: 'api_key', + from: sendgridConfigFrom, + replyTo: replyTo, + }; + + const { data } = await client.integrations.saveSendgridIntegration(input); + + console.log(data); +})(); +``` + +## delete_sendgrid_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/sendgrid` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSendgridIntegration(); + + console.log(data); +})(); +``` + +## delete_sendgrid_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/sendgrid/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSendgridIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_ses_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/ses` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getSesIntegration(); + + console.log(data); +})(); +``` + +## save_ses_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/ses` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------------- | +| body | [SesConfig](../models/SesConfig.md) | ❌ | The request body. | + +**Return Type** + +`SesConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, SesConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const sesConfigFrom: SesConfigFrom = { + email: 'email', + name: 'name', + }; + + const sesConfig: SesConfig = { + endpoint: 'sit ipsum', + from: sesConfigFrom, + keyId: 'ex ', + region: 'in repr', + secretKey: 'ali', + }; + + const { data } = await client.integrations.saveSesIntegration(input); + + console.log(data); +})(); +``` + +## delete_ses_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/ses` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSesIntegration(); + + console.log(data); +})(); +``` + +## delete_ses_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/ses/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSesIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_slack_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/slack` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getSlackIntegration(); + + console.log(data); +})(); +``` + +## save_slack_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/slack` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :-------------------------------------- | :------- | :---------------- | +| body | [SlackConfig](../models/SlackConfig.md) | ❌ | The request body. | + +**Return Type** + +`SlackConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, SlackConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const slackConfig: SlackConfig = { + appId: 'X2ZNPXG8L', + clientId: '430411624.02717865207', + clientSecret: 'labore in ea fugiat magnainsed v', + id: 'CM0mBN', + signingSecret: 'exercitation Excepteur et euanim', + }; + + const { data } = await client.integrations.saveSlackIntegration(input); + + console.log(data); +})(); +``` + +## delete_slack_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/slack` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSlackIntegration(); + + console.log(data); +})(); +``` + +## delete_slack_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/slack/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteSlackIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_stripe_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/stripe` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getStripeIntegration(); + + console.log(data); +})(); +``` + +## save_stripe_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/stripe` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------------- | :------- | :---------------- | +| body | [StripeConfig](../models/StripeConfig.md) | ❌ | The request body. | + +**Return Type** + +`StripeConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, StripeConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const stripeConfig: StripeConfig = { + webhookSigningSecret: 'et nisi', + }; + + const { data } = await client.integrations.saveStripeIntegration(input); + + console.log(data); +})(); +``` + +## delete_stripe_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/stripe` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteStripeIntegration(); + + console.log(data); +})(); +``` + +## delete_stripe_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/stripe/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteStripeIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_templates_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/templates` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getTemplatesIntegration(); + + console.log(data); +})(); +``` + +## save_templates_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/templates` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :--- | :------- | :---------------- | +| body | any | ❌ | The request body. | + +**Return Type** + +`any` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const input = {}; + + const { data } = await client.integrations.saveTemplatesIntegration(input); + + console.log(data); +})(); +``` + +## delete_templates_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/templates` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteTemplatesIntegration(); + + console.log(data); +})(); +``` + +## delete_templates_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/templates/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteTemplatesIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_twilio_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/twilio` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getTwilioIntegration(); + + console.log(data); +})(); +``` + +## save_twilio_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/twilio` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :---------------------------------------- | :------- | :---------------- | +| body | [TwilioConfig](../models/TwilioConfig.md) | ❌ | The request body. | + +**Return Type** + +`TwilioConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, TwilioConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const twilioConfigRegion = TwilioConfigRegion.US1; + + const twilioConfig: TwilioConfig = { + accountSid: 'sunt', + apiKey: 'laboris non sunt fugiat', + apiSecret: 'aliqua sit laboris labore', + from: '+959', + region: twilioConfigRegion, + }; + + const { data } = await client.integrations.saveTwilioIntegration(input); + + console.log(data); +})(); +``` + +## delete_twilio_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/twilio` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteTwilioIntegration(); + + console.log(data); +})(); +``` + +## delete_twilio_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/twilio/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteTwilioIntegrationById('id'); + + console.log(data); +})(); +``` + +## get_web_push_integration + +- HTTP Method: `GET` +- Endpoint: `/integrations/web_push` + +**Return Type** + +`ListIntegrationsResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.getWebPushIntegration(); + + console.log(data); +})(); +``` + +## save_web_push_integration + +- HTTP Method: `PUT` +- Endpoint: `/integrations/web_push` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------------ | :------- | :---------------- | +| body | [WebpushConfig](../models/WebpushConfig.md) | ❌ | The request body. | + +**Return Type** + +`WebpushConfig` + +**Example Usage Code Snippet** + +```typescript +import { Client, WebpushConfig } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const webpushConfig: WebpushConfig = { + privateKey: 'pariatur occaecat magna', + publicKey: 'exercitati', + }; + + const { data } = await client.integrations.saveWebPushIntegration(input); + + console.log(data); +})(); +``` + +## delete_web_push_integration + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/web_push` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteWebPushIntegration(); + + console.log(data); +})(); +``` + +## delete_web_push_integration_by_id + +- HTTP Method: `DELETE` +- Endpoint: `/integrations/web_push/{id}` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :----- | :------- | :---------- | +| id | string | ✅ | | + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.integrations.deleteWebPushIntegrationById('id'); + + console.log(data); +})(); +``` diff --git a/packages/project-client/package.json b/packages/project-client/package.json index 8159027cd..e2c63c536 100644 --- a/packages/project-client/package.json +++ b/packages/project-client/package.json @@ -1,18 +1,25 @@ { "name": "@magicbell/project-client", "version": "0.1.0", - "description": "Client - OpenAPI 3.1.0 Specification for MagicBell API.", + "description": "OpenAPI 3.1.0 Specification for MagicBell API.", + "keywords": [ + "typescript", + "sdk", + "api", + "client" + ], "repository": { "type": "git", "url": "https://github.com/magicbell/magicbell-js.git", "directory": "packages/project-client" }, - "license": "SEE LICENSE IN LICENSE", - "author": "Client", + "author": "MagicBell", "exports": { - "require": "./dist/commonjs/index.js", - "types": "./dist/commonjs/index.d.ts", - "default": "./dist/esm/index.js" + ".": { + "require": "./dist/index.js", + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } }, "main": "./dist/commonjs/index.js", "unpkg": "./dist/index.umd.js", @@ -29,23 +36,12 @@ "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir dist/commonjs", "build:esm": "tsc --project tsconfig.build.json --module esnext --outDir dist/esm", "codegen": "tsx scripts/build.ts", - "lint": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to .", - "lint:ci": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to . --cache --quiet", - "lint:fix": "eslint --ext .ts,.js ./src/ --resolve-plugins-relative-to . --cache --fix", - "rebuild": "rm -rf dist/ && tsc", - "start": "rm -rf dist/ && tsc -w", - "test": "jest --detectOpenHandles", - "version": "tsc --version" + "start": "rm -rf dist/ && tsc -w" }, "dependencies": { - "axios": "^1.0.0" + "zod": "3.22.0" }, "devDependencies": { - "@types/jest": "^29.5.10", - "@types/node": "^20.14.8", - "jest": "^29.7.0", - "nock": "^13.2.4", - "ts-jest": "^29.2.0", "typescript": "^5.5.3" } } diff --git a/packages/project-client/src/BaseService.ts b/packages/project-client/src/BaseService.ts deleted file mode 100644 index b612717fc..000000000 --- a/packages/project-client/src/BaseService.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { Environment } from './http/Environment'; -import { Headers } from './http/HTTPClient'; -import HTTPLibrary from './http/HTTPLibrary'; - -export default class BaseService { - public baseUrl: string = Environment.DEFAULT; - - public httpClient = new HTTPLibrary(); - - private accessToken = ''; - - private accessTokenPrefix = 'Bearer'; - - setAccessToken(accessToken: string): void { - this.accessToken = accessToken; - } - - getAuthorizationHeader(): Headers { - const accessTokenAuth = { Authorization: `${this.accessTokenPrefix} ${this.accessToken}` }; - - return { ...accessTokenAuth }; - } - - setBaseUrl(url: string): void { - this.baseUrl = url; - } - - constructor(accessToken = '') { - this.setAccessToken(accessToken); - } - - static patternMatching(value: string, pattern: string, variableName: string): string { - if (!value) { - throw new Error(`${variableName} cannot be null or undefined`); - } - if (!value.match(new RegExp(pattern))) { - throw new Error(`Invalid value for ${variableName}: must match ${pattern}`); - } - return value; - } - - static urlEncode = (input: { [key: string]: any }): string => - Object.keys(input) - .map((key) => `${key}=${encodeURIComponent(input[key])}`) - .join('&'); -} diff --git a/packages/project-client/src/hooks/Hook.ts b/packages/project-client/src/hooks/Hook.ts deleted file mode 100644 index 443030bed..000000000 --- a/packages/project-client/src/hooks/Hook.ts +++ /dev/null @@ -1,28 +0,0 @@ -export interface Request { - method: string; - url: string; - input?: object; - headers: object; -} - -export interface Response { - data: object; - headers: object; - status: number; -} - -export interface Exception extends Error { - title: string; - type?: string; - detail?: string; - instance?: string; - statusCode: number; -} - -export interface Hook { - beforeRequest(request: Request): Promise; - - afterResponse(request: Request, response: Response): Promise; - - onError(error: Exception): Promise; -} diff --git a/packages/project-client/src/http/HTTPClient.ts b/packages/project-client/src/http/HTTPClient.ts deleted file mode 100644 index 2a37df8eb..000000000 --- a/packages/project-client/src/http/HTTPClient.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface Headers extends Record {} - -/** - * Defines the basic operations for an HTTP client. - */ -export default interface HTTPClient { - get(url: string, input: any, headers: Headers, retry?: boolean): Promise; - post(url: string, input: any, headers: Headers, retry?: boolean): Promise; - delete(url: string, input: any, headers: Headers, retry?: boolean): Promise; - put(url: string, input: any, headers: Headers, retry?: boolean): Promise; - patch(url: string, input: any, headers: Headers, retry?: boolean): Promise; -} diff --git a/packages/project-client/src/http/HTTPLibrary.ts b/packages/project-client/src/http/HTTPLibrary.ts deleted file mode 100644 index 427976c22..000000000 --- a/packages/project-client/src/http/HTTPLibrary.ts +++ /dev/null @@ -1,159 +0,0 @@ -import axios, { AxiosError } from 'axios'; - -import HTTPClient, { Headers } from './HTTPClient'; -import throwHttpError from './httpExceptions'; - -// Ignore TS errors when checking if we are running inside Deno or Bun -declare const Deno: any; -declare const Bun: any; - -export default class HTTPLibrary implements HTTPClient { - readonly retryAttempts: number = 3; - readonly retryDelayMs: number = 150; - - private static readonly responseMapper: Map = new Map([ - ['type', 'type_'], - ['from', 'from_'], - ]); - - private readonly requestMapper: Map = new Map([ - ['type_', 'type'], - ['from_', 'from'], - ]); - - async get(url: string, input: any, headers: Headers, retry = false): Promise { - const request = () => - axios.get(url, { - headers: { ...headers, ...this.getUserAgentHeader() }, - data: Object.keys(input).length > 0 ? HTTPLibrary.convertKeysWithMapper(input, this.requestMapper) : undefined, - }); - - const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); - return HTTPLibrary.handleResponse(response); - } - - async post(url: string, input: any, headers: Headers, retry = false): Promise { - const request = () => - axios.post(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async delete(url: string, input: any, headers: Headers, retry = false): Promise { - const request = () => - axios.delete(url, { - headers: { ...headers, ...this.getUserAgentHeader() }, - data: HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), - }); - - const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async put(url: string, input: any, headers: Headers, retry = false): Promise { - const request = () => - axios.put(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async patch(url: string, input: any, headers: Headers, retry = false): Promise { - const request = () => - axios.patch(url, HTTPLibrary.convertKeysWithMapper(input, this.requestMapper), { - headers: { ...headers, ...this.getUserAgentHeader() }, - }); - - const response = retry ? await this.retry(this.retryAttempts, request, this.retryDelayMs) : await request(); - - return HTTPLibrary.handleResponse(response); - } - - async retry(retries: number, callbackFn: () => any, delay: number): Promise { - let result: any; - - try { - result = await callbackFn(); - } catch (e: any) { - if ((e as AxiosError).isAxiosError) { - if (e.response) { - if (![500, 503, 504].includes(e.response.status)) { - return e.response; - } - } - } - if (retries > 1) { - // eslint-disable-next-line no-promise-executor-return - await new Promise((resolve) => setTimeout(resolve, delay)); - result = await this.retry(retries - 1, callbackFn, delay * 2); - } else { - throw e; - } - } - - return result; - } - - private static handleResponse(response: any) { - if (response.status >= 400) { - throwHttpError(response); - } - - response.data = HTTPLibrary.convertKeysWithMapper(response.data, this.responseMapper); - - return response; - } - - private getUserAgentHeader(): Headers { - const userAgentBase = 'Client/0.1.0'; - - let userAgent = ''; - if (typeof window !== 'undefined') { - return {}; - } else if (typeof process !== 'undefined') { - userAgent = `Node.js/${process.version} ${userAgentBase}`; - } else if (typeof Deno !== 'undefined') { - userAgent = `Deno/${Deno.version.deno} ${userAgentBase}`; - } else if (typeof Bun !== 'undefined') { - userAgent = `Bun/${Bun.version} ${userAgentBase}`; - } else { - userAgent = userAgentBase; - } - - return { 'User-Agent': userAgent }; - } - - /** - *Converts keys in an object using a provided JSON mapper. - * @param {any} obj - The object to convert keys for. - * @param {Object} jsonMapper - The JSON mapper containing key mappings. - * @returns {any} - The object with converted keys. - */ - private static convertKeysWithMapper(obj: T, jsonMapper: Map): any { - if (!obj || typeof obj !== 'object') { - return obj; - } - - if (Array.isArray(obj)) { - return obj.map((item) => HTTPLibrary.convertKeysWithMapper(item, jsonMapper)); - } - - const convertedObj: Record = {}; - Object.entries(obj).forEach(([key, value]) => { - if (value !== undefined) { - const convertedKey = jsonMapper.get(key) || key; - convertedObj[convertedKey] = HTTPLibrary.convertKeysWithMapper(value, jsonMapper); - } - }); - - return convertedObj; - } -} diff --git a/packages/project-client/src/http/QuerySerializer.ts b/packages/project-client/src/http/QuerySerializer.ts deleted file mode 100644 index 2cdb72f58..000000000 --- a/packages/project-client/src/http/QuerySerializer.ts +++ /dev/null @@ -1,40 +0,0 @@ -export type Explode = boolean; -export type QueryStyles = 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject'; -export type PathStyles = 'simple' | 'label' | 'matrix'; - -const styleMethods: Record = { - simple: (value: unknown, explode: boolean) => { - // Check if the value is an array - if (Array.isArray(value)) { - return explode ? value.join(',') : value.join(); - } - - // Check if the value is an object - if (typeof value === 'object' && value !== null) { - if (explode) { - // Serialize object with exploded format: "key=value,key2=value2" - return Object.entries(value) - .map(([parameterName, parameterValue]) => `${parameterName}=${parameterValue}`) - .join(','); - } - // Serialize object with non-exploded format: "key,value,key2,value2" - return Object.entries(value) - .flatMap(([parameterName, parameterValue]) => [parameterName, parameterValue]) - .join(','); - } - - // For primitive values - return String(value); - }, -}; - -export function serializePath(style: PathStyles, explode: Explode, value: unknown, key?: string): string { - const method = styleMethods[style]; - if (!method) return ''; - // The `simple` and `label` styles do not require a `key` - if (!key) { - return method(value, explode); - } else { - return method(key, value, explode); - } -} diff --git a/packages/project-client/src/http/client.ts b/packages/project-client/src/http/client.ts new file mode 100644 index 000000000..3487ef482 --- /dev/null +++ b/packages/project-client/src/http/client.ts @@ -0,0 +1,35 @@ +import { AuthHandler } from './handlers/auth-handler'; +import { RequestHandlerChain } from './handlers/handler-chain'; +import { HookHandler } from './handlers/hook-handler'; +import { RequestValidationHandler } from './handlers/request-validation-handler'; +import { ResponseValidationHandler } from './handlers/response-validation-handler'; +import { RetryHandler } from './handlers/retry-handler'; +import { TerminatingHandler } from './handlers/terminating-handler'; +import { CustomHook } from './hooks/custom-hook'; +import { Request } from './transport/request'; +import { HttpResponse, SdkConfig } from './types'; + +export class HttpClient { + private readonly requestHandlerChain = new RequestHandlerChain(); + + constructor(private config: SdkConfig, hook = new CustomHook()) { + this.requestHandlerChain.addHandler(new ResponseValidationHandler()); + this.requestHandlerChain.addHandler(new RequestValidationHandler()); + this.requestHandlerChain.addHandler(new AuthHandler()); + this.requestHandlerChain.addHandler(new RetryHandler()); + this.requestHandlerChain.addHandler(new HookHandler(hook)); + this.requestHandlerChain.addHandler(new TerminatingHandler()); + } + + call(request: Request): Promise> { + return this.requestHandlerChain.callChain(request); + } + + setBaseUrl(url: string): void { + this.config.baseUrl = url; + } + + setConfig(config: SdkConfig): void { + this.config = config; + } +} diff --git a/packages/project-client/src/http/error.ts b/packages/project-client/src/http/error.ts new file mode 100644 index 000000000..4dc1d6bd5 --- /dev/null +++ b/packages/project-client/src/http/error.ts @@ -0,0 +1,12 @@ +import { HttpMetadata } from './types'; + +export class HttpError extends Error { + public readonly error: string; + public readonly metadata: HttpMetadata; + + constructor(metadata: HttpMetadata, error?: string) { + super(error); + this.error = metadata.statusText; + this.metadata = metadata; + } +} diff --git a/packages/project-client/src/http/errors/BadGateway.ts b/packages/project-client/src/http/errors/BadGateway.ts deleted file mode 100644 index 604658808..000000000 --- a/packages/project-client/src/http/errors/BadGateway.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class BadGateway extends BaseHTTPError { - statusCode = 502; - - title = 'Bad Gateway'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/BadRequest.ts b/packages/project-client/src/http/errors/BadRequest.ts deleted file mode 100644 index cefa85bf4..000000000 --- a/packages/project-client/src/http/errors/BadRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class BadRequest extends BaseHTTPError { - statusCode = 400; - - title = 'Bad Request'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/Conflict.ts b/packages/project-client/src/http/errors/Conflict.ts deleted file mode 100644 index d11577ee4..000000000 --- a/packages/project-client/src/http/errors/Conflict.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Conflict extends BaseHTTPError { - statusCode = 409; - - title = 'Conflict'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/ExpectationFailed.ts b/packages/project-client/src/http/errors/ExpectationFailed.ts deleted file mode 100644 index 69704d5cd..000000000 --- a/packages/project-client/src/http/errors/ExpectationFailed.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class ExpectationFailed extends BaseHTTPError { - statusCode = 417; - - title = 'Expectation Failed'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/FailedDependency.ts b/packages/project-client/src/http/errors/FailedDependency.ts deleted file mode 100644 index 3e753de3f..000000000 --- a/packages/project-client/src/http/errors/FailedDependency.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class FailedDependency extends BaseHTTPError { - statusCode = 424; - - title = 'Failed Dependency'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/Forbidden.ts b/packages/project-client/src/http/errors/Forbidden.ts deleted file mode 100644 index a6172ca5b..000000000 --- a/packages/project-client/src/http/errors/Forbidden.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Forbidden extends BaseHTTPError { - statusCode = 403; - - title = 'Forbidden'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/GatewayTimeout.ts b/packages/project-client/src/http/errors/GatewayTimeout.ts deleted file mode 100644 index 74b358567..000000000 --- a/packages/project-client/src/http/errors/GatewayTimeout.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class GatewayTimeout extends BaseHTTPError { - statusCode = 504; - - title = 'Gateway Timeout'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/Gone.ts b/packages/project-client/src/http/errors/Gone.ts deleted file mode 100644 index 83ddffbc5..000000000 --- a/packages/project-client/src/http/errors/Gone.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Gone extends BaseHTTPError { - statusCode = 410; - - title = 'Gone'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/HttpVersionNotSupported.ts b/packages/project-client/src/http/errors/HttpVersionNotSupported.ts deleted file mode 100644 index 7c9619456..000000000 --- a/packages/project-client/src/http/errors/HttpVersionNotSupported.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class HttpVersionNotSupported extends BaseHTTPError { - statusCode = 505; - - title = 'HTTP Version Not Supported'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/InternalServerError.ts b/packages/project-client/src/http/errors/InternalServerError.ts deleted file mode 100644 index b93f1fd35..000000000 --- a/packages/project-client/src/http/errors/InternalServerError.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class InternalServerError extends BaseHTTPError { - statusCode = 500; - - title = 'Internal Server Error'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/LengthRequired.ts b/packages/project-client/src/http/errors/LengthRequired.ts deleted file mode 100644 index 12be92a99..000000000 --- a/packages/project-client/src/http/errors/LengthRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class LengthRequired extends BaseHTTPError { - statusCode = 411; - - title = 'LengthRequired'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/Locked.ts b/packages/project-client/src/http/errors/Locked.ts deleted file mode 100644 index da78abb28..000000000 --- a/packages/project-client/src/http/errors/Locked.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class Locked extends BaseHTTPError { - statusCode = 423; - - title = 'Locked'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/LoopDetected.ts b/packages/project-client/src/http/errors/LoopDetected.ts deleted file mode 100644 index b62c383a4..000000000 --- a/packages/project-client/src/http/errors/LoopDetected.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class LoopDetected extends BaseHTTPError { - statusCode = 508; - - title = 'Loop Detected'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/MethodNotAllowed.ts b/packages/project-client/src/http/errors/MethodNotAllowed.ts deleted file mode 100644 index fa86ff5e6..000000000 --- a/packages/project-client/src/http/errors/MethodNotAllowed.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class MethodNotAllowed extends BaseHTTPError { - statusCode = 405; - - title = 'Method Not Allowed'; - - allow?: string[]; - - constructor(detail = '', allow?: string[]) { - super(detail); - this.allow = allow; - } -} diff --git a/packages/project-client/src/http/errors/MisdirectedRequest.ts b/packages/project-client/src/http/errors/MisdirectedRequest.ts deleted file mode 100644 index 1ceb1d5d5..000000000 --- a/packages/project-client/src/http/errors/MisdirectedRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class MisdirectedRequest extends BaseHTTPError { - statusCode = 421; - - title = 'Misdirected Request'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts b/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts deleted file mode 100644 index 26a962745..000000000 --- a/packages/project-client/src/http/errors/NetworkAuthenticationRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NetworkAuthenticationRequired extends BaseHTTPError { - statusCode = 511; - - title = 'Network Authentication Required'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/NotAcceptable.ts b/packages/project-client/src/http/errors/NotAcceptable.ts deleted file mode 100644 index 408df59a9..000000000 --- a/packages/project-client/src/http/errors/NotAcceptable.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotAcceptable extends BaseHTTPError { - statusCode = 406; - - title = 'Not Acceptable'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/NotExtended.ts b/packages/project-client/src/http/errors/NotExtended.ts deleted file mode 100644 index ec3ddd852..000000000 --- a/packages/project-client/src/http/errors/NotExtended.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotExtended extends BaseHTTPError { - statusCode = 510; - - title = 'Not Extended'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/NotFound.ts b/packages/project-client/src/http/errors/NotFound.ts deleted file mode 100644 index fdf9198e2..000000000 --- a/packages/project-client/src/http/errors/NotFound.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotFound extends BaseHTTPError { - statusCode = 404; - - title = 'Not Found'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/NotImplemented.ts b/packages/project-client/src/http/errors/NotImplemented.ts deleted file mode 100644 index a286272d2..000000000 --- a/packages/project-client/src/http/errors/NotImplemented.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class NotImplemented extends BaseHTTPError { - statusCode = 501; - - title = 'Not Implemented'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/PayloadTooLarge.ts b/packages/project-client/src/http/errors/PayloadTooLarge.ts deleted file mode 100644 index 98ddc60e5..000000000 --- a/packages/project-client/src/http/errors/PayloadTooLarge.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PayloadTooLarge extends BaseHTTPError { - statusCode = 413; - - title = 'Payload Too Large'; - - retryAfter: number | null; - - constructor(detail = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/packages/project-client/src/http/errors/PaymentRequired.ts b/packages/project-client/src/http/errors/PaymentRequired.ts deleted file mode 100644 index 8951b7b51..000000000 --- a/packages/project-client/src/http/errors/PaymentRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PaymentRequired extends BaseHTTPError { - statusCode = 402; - - title = 'Payment Required'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/PreconditionFailed.ts b/packages/project-client/src/http/errors/PreconditionFailed.ts deleted file mode 100644 index c7bee9104..000000000 --- a/packages/project-client/src/http/errors/PreconditionFailed.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PreconditionFailed extends BaseHTTPError { - statusCode = 412; - - title = 'PreconditionFailed'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/PreconditionRequired.ts b/packages/project-client/src/http/errors/PreconditionRequired.ts deleted file mode 100644 index 983d50523..000000000 --- a/packages/project-client/src/http/errors/PreconditionRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class PreconditionRequired extends BaseHTTPError { - statusCode = 428; - - title = 'Precondition Required'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts b/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts deleted file mode 100644 index 814545fac..000000000 --- a/packages/project-client/src/http/errors/ProxyAuthenticationRequired.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AuthenticateChallenge, BaseHTTPError } from './base'; - -export default class ProxyAuthenticationRequired extends BaseHTTPError { - statusCode = 407; - - title = 'Proxy Authentication Required'; - - proxyAuthenticate?: AuthenticateChallenge; - - constructor(detail = '', proxyAuthenticate?: AuthenticateChallenge) { - super(detail); - this.proxyAuthenticate = proxyAuthenticate; - } -} diff --git a/packages/project-client/src/http/errors/RangeNotSatisfiable.ts b/packages/project-client/src/http/errors/RangeNotSatisfiable.ts deleted file mode 100644 index 8cb2efc1a..000000000 --- a/packages/project-client/src/http/errors/RangeNotSatisfiable.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RangeNotSatisfiable extends BaseHTTPError { - statusCode = 416; - - title = 'Range Not Satisfiable'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts b/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts deleted file mode 100644 index 16000c75b..000000000 --- a/packages/project-client/src/http/errors/RequestHeaderFieldsTooLarge.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RequestHeaderFieldsTooLarge extends BaseHTTPError { - statusCode = 431; - - title = 'Request Header Fields Too Large'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/RequestTimeout.ts b/packages/project-client/src/http/errors/RequestTimeout.ts deleted file mode 100644 index 68949280c..000000000 --- a/packages/project-client/src/http/errors/RequestTimeout.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class RequestTimeout extends BaseHTTPError { - statusCode = 408; - - title = 'Request Timeout'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/ServiceUnavailable.ts b/packages/project-client/src/http/errors/ServiceUnavailable.ts deleted file mode 100644 index b7ce5b201..000000000 --- a/packages/project-client/src/http/errors/ServiceUnavailable.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class ServiceUnavailable extends BaseHTTPError { - statusCode = 503; - - title = 'Service Unavailable'; - - retryAfter: number | null; - - constructor(detail = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/packages/project-client/src/http/errors/TooEarly.ts b/packages/project-client/src/http/errors/TooEarly.ts deleted file mode 100644 index c870167ae..000000000 --- a/packages/project-client/src/http/errors/TooEarly.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class TooEarly extends BaseHTTPError { - statusCode = 425; - - title = 'Too Early'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/TooManyRequests.ts b/packages/project-client/src/http/errors/TooManyRequests.ts deleted file mode 100644 index ec7f76055..000000000 --- a/packages/project-client/src/http/errors/TooManyRequests.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class TooManyRequests extends BaseHTTPError { - statusCode = 429; - - title = 'Too Many Requests'; - - retryAfter: number | null; - - constructor(detail = '', retryAfter: number | null = null) { - super(detail); - this.retryAfter = retryAfter; - } -} diff --git a/packages/project-client/src/http/errors/Unauthorized.ts b/packages/project-client/src/http/errors/Unauthorized.ts deleted file mode 100644 index 0edb7d0a3..000000000 --- a/packages/project-client/src/http/errors/Unauthorized.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { AuthenticateChallenge, BaseHTTPError } from './base'; - -export default class Unauthorized extends BaseHTTPError { - statusCode = 401; - - title = 'Unauthorized'; - - wwwAuthenticate?: AuthenticateChallenge; - - constructor(detail = '', wwwAuthenticate?: AuthenticateChallenge) { - super(detail); - this.wwwAuthenticate = wwwAuthenticate; - } -} diff --git a/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts b/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts deleted file mode 100644 index 27aef0e04..000000000 --- a/packages/project-client/src/http/errors/UnavailableForLegalReasons.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnavailableForLegalReasons extends BaseHTTPError { - statusCode = 451; - - title = 'Unavailable For Legal Reasons'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/UnprocessableEntity.ts b/packages/project-client/src/http/errors/UnprocessableEntity.ts deleted file mode 100644 index 9b0713cd1..000000000 --- a/packages/project-client/src/http/errors/UnprocessableEntity.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnprocessableEntity extends BaseHTTPError { - statusCode = 422; - - title = 'Unprocessable Entity'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/UnsufficientStorage.ts b/packages/project-client/src/http/errors/UnsufficientStorage.ts deleted file mode 100644 index 07179cf6c..000000000 --- a/packages/project-client/src/http/errors/UnsufficientStorage.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnsufficientStorage extends BaseHTTPError { - statusCode = 507; - - title = 'Unsufficient Storage'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/UnsupportedMediaType.ts b/packages/project-client/src/http/errors/UnsupportedMediaType.ts deleted file mode 100644 index 1c8777725..000000000 --- a/packages/project-client/src/http/errors/UnsupportedMediaType.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UnsupportedMediaType extends BaseHTTPError { - statusCode = 415; - - title = 'Unsupported Media Type'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/UpgradeRequired.ts b/packages/project-client/src/http/errors/UpgradeRequired.ts deleted file mode 100644 index dee381703..000000000 --- a/packages/project-client/src/http/errors/UpgradeRequired.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UpgradeRequired extends BaseHTTPError { - statusCode = 426; - - title = 'Upgrade Required'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/UriTooLong.ts b/packages/project-client/src/http/errors/UriTooLong.ts deleted file mode 100644 index ce46ea64c..000000000 --- a/packages/project-client/src/http/errors/UriTooLong.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class UriTooLong extends BaseHTTPError { - statusCode = 414; - - title = 'URI Too Long'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts b/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts deleted file mode 100644 index 275e9528c..000000000 --- a/packages/project-client/src/http/errors/VariantAlsoNegotiates.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { BaseHTTPError } from './base'; - -export default class VariantAlsoNegotiates extends BaseHTTPError { - statusCode = 506; - - title = 'Variant Also Negotiates'; - - constructor(detail = '') { - super(detail); - } -} diff --git a/packages/project-client/src/http/errors/base.ts b/packages/project-client/src/http/errors/base.ts deleted file mode 100644 index d41d9c30e..000000000 --- a/packages/project-client/src/http/errors/base.ts +++ /dev/null @@ -1,52 +0,0 @@ -export interface IHTTPError extends Error { - statusCode: number; -} - -export interface IHTTPErrorDescription extends IHTTPError { - type?: string; - title: string; - detail?: string; - instance?: string; -} - -export function isHTTPError(error: unknown): error is IHTTPError { - if (!error) { - return false; - } - return Number.isInteger((error as IHTTPError).statusCode); -} - -export function isHTTPIssue(error: unknown): error is IHTTPErrorDescription { - if (!error) { - return false; - } - return (error as IHTTPErrorDescription).title !== undefined && isHTTPError(error); -} - -export class BaseHTTPError extends Error implements IHTTPError { - public type?: string; - - public title = 'Internal Server Error'; - - public detail?: string; - - public instance?: string; - - public statusCode = 500; - - constructor(detail = '') { - super(detail || 'An Unknown HTTP Error Occurred'); - this.detail = detail; - this.stack = (new Error()).stack; - } -} - -export function isClientError(error: Error): boolean { - return isHTTPError(error); -} - -export function isServerError(e: Error): boolean { - return isHTTPError(e) && e.statusCode >= 500 && e.statusCode <= 599; -} - -export type AuthenticateChallenge = string | string[]; diff --git a/packages/project-client/src/http/errors/index.ts b/packages/project-client/src/http/errors/index.ts deleted file mode 100644 index 22607d349..000000000 --- a/packages/project-client/src/http/errors/index.ts +++ /dev/null @@ -1,83 +0,0 @@ -import BadGateway from './BadGateway'; -import BadRequest from './BadRequest'; -import { BaseHTTPError } from './base'; -import Conflict from './Conflict'; -import ExpectationFailed from './ExpectationFailed'; -import FailedDependency from './FailedDependency'; -import Forbidden from './Forbidden'; -import GatewayTimeout from './GatewayTimeout'; -import Gone from './Gone'; -import HttpVersionNotSupported from './HttpVersionNotSupported'; -import InternalServerError from './InternalServerError'; -import LengthRequired from './LengthRequired'; -import Locked from './Locked'; -import LoopDetected from './LoopDetected'; -import MethodNotAllowed from './MethodNotAllowed'; -import MisdirectedRequest from './MisdirectedRequest'; -import NetworkAuthenticationRequired from './NetworkAuthenticationRequired'; -import NotAcceptable from './NotAcceptable'; -import NotExtended from './NotExtended'; -import NotFound from './NotFound'; -import NotImplemented from './NotImplemented'; -import PayloadTooLarge from './PayloadTooLarge'; -import PaymentRequired from './PaymentRequired'; -import PreconditionFailed from './PreconditionFailed'; -import PreconditionRequired from './PreconditionRequired'; -import ProxyAuthenticationRequired from './ProxyAuthenticationRequired'; -import RangeNotSatisfiable from './RangeNotSatisfiable'; -import RequestHeaderFieldsTooLarge from './RequestHeaderFieldsTooLarge'; -import RequestTimeout from './RequestTimeout'; -import ServiceUnavailable from './ServiceUnavailable'; -import TooEarly from './TooEarly'; -import TooManyRequests from './TooManyRequests'; -import Unauthorized from './Unauthorized'; -import UnavailableForLegalReasons from './UnavailableForLegalReasons'; -import UnprocessableEntity from './UnprocessableEntity'; -import UnsufficientStorage from './UnsufficientStorage'; -import UnsupportedMediaType from './UnsupportedMediaType'; -import UpgradeRequired from './UpgradeRequired'; -import UriTooLong from './UriTooLong'; -import VariantAlsoNegotiates from './VariantAlsoNegotiates'; - -export { - BadGateway, - BadRequest, - BaseHTTPError, - Conflict, - ExpectationFailed, - FailedDependency, - Forbidden, - GatewayTimeout, - Gone, - HttpVersionNotSupported, - InternalServerError, - LengthRequired, - Locked, - LoopDetected, - MethodNotAllowed, - MisdirectedRequest, - NetworkAuthenticationRequired, - NotAcceptable, - NotExtended, - NotFound, - NotImplemented, - PayloadTooLarge, - PaymentRequired, - PreconditionFailed, - PreconditionRequired, - ProxyAuthenticationRequired, - RangeNotSatisfiable, - RequestHeaderFieldsTooLarge, - RequestTimeout, - ServiceUnavailable, - TooEarly, - TooManyRequests, - Unauthorized, - UnavailableForLegalReasons, - UnprocessableEntity, - UnsufficientStorage, - UnsupportedMediaType, - UpgradeRequired, - UriTooLong, - VariantAlsoNegotiates, -}; diff --git a/packages/project-client/src/http/handlers/auth-handler.ts b/packages/project-client/src/http/handlers/auth-handler.ts new file mode 100644 index 000000000..9fdc35fcb --- /dev/null +++ b/packages/project-client/src/http/handlers/auth-handler.ts @@ -0,0 +1,34 @@ +import { SerializationStyle } from '../serialization/base-serializer'; +import { Request } from '../transport/request'; +import { HttpResponse, RequestHandler } from '../types'; + +export class AuthHandler implements RequestHandler { + next?: RequestHandler; + + async handle(request: Request): Promise> { + const requestWithAuth = this.addAccessTokenHeader(request); + + if (!this.next) { + throw new Error(`No next handler set in ${AuthHandler.name}`); + } + + return this.next?.handle(requestWithAuth); + } + + private addAccessTokenHeader(request: Request): Request { + const { token } = request.config; + if (!token) { + return request; + } + + request.addHeaderParam('Authorization', { + key: 'Authorization', + value: `Bearer ${token}`, + explode: false, + encode: false, + style: SerializationStyle.SIMPLE, + }); + + return request; + } +} diff --git a/packages/project-client/src/http/handlers/handler-chain.ts b/packages/project-client/src/http/handlers/handler-chain.ts new file mode 100644 index 000000000..9f56b046e --- /dev/null +++ b/packages/project-client/src/http/handlers/handler-chain.ts @@ -0,0 +1,22 @@ +import { Request } from '../transport/request'; +import { HttpResponse, RequestHandler } from '../types'; + +export class RequestHandlerChain { + private readonly handlers: RequestHandler[] = []; + + addHandler(handler: RequestHandler): void { + if (this.handlers.length > 0) { + const previousHandler = this.handlers[this.handlers.length - 1]; + previousHandler.next = handler; + } + this.handlers.push(handler); + } + + async callChain(request: Request): Promise> { + if (!this.handlers.length) { + throw new Error('No handlers added to the chain'); + } + + return this.handlers[0].handle(request); + } +} diff --git a/packages/project-client/src/http/handlers/hook-handler.ts b/packages/project-client/src/http/handlers/hook-handler.ts new file mode 100644 index 000000000..7921baffc --- /dev/null +++ b/packages/project-client/src/http/handlers/hook-handler.ts @@ -0,0 +1,38 @@ +import { HttpError } from '../error'; +import { Hook } from '../hooks/hook'; +import { Request } from '../transport/request'; +import { TransportHookAdapter } from '../transport/transport-hook-adapter'; +import { HttpResponse, RequestHandler } from '../types'; + +export class HookHandler implements RequestHandler { + next?: RequestHandler; + + constructor(private readonly hook: Hook) {} + + async handle(request: Request): Promise> { + if (!this.next) { + throw new Error('No next handler set in hook handler.'); + } + + const hook = new TransportHookAdapter(); + + const hookParams = this.getHookParams(request); + + const nextRequest = await hook.beforeRequest(request, hookParams); + + const response = await this.next.handle(nextRequest); + + if (response.metadata.status < 400) { + return await hook.afterResponse(nextRequest, response, hookParams); + } + + const error = await hook.onError(nextRequest, response, hookParams); + + throw new HttpError(error.metadata, error.error); + } + + private getHookParams(_request: Request): Map { + const hookParams: Map = new Map(); + return hookParams; + } +} diff --git a/packages/project-client/src/http/handlers/request-validation-handler.ts b/packages/project-client/src/http/handlers/request-validation-handler.ts new file mode 100644 index 000000000..5e6e8e868 --- /dev/null +++ b/packages/project-client/src/http/handlers/request-validation-handler.ts @@ -0,0 +1,71 @@ +import { Request } from '../transport/request'; +import { ContentType, HttpResponse, RequestHandler } from '../types'; + +export class RequestValidationHandler implements RequestHandler { + next?: RequestHandler; + + async handle(request: Request): Promise> { + if (!this.next) { + throw new Error('No next handler set in ContentTypeHandler.'); + } + + if (request.requestContentType === ContentType.Json) { + request.body = JSON.stringify(request.requestSchema?.parse(request.body)); + } else if ( + request.requestContentType === ContentType.Xml || + request.requestContentType === ContentType.Binary || + request.requestContentType === ContentType.Text + ) { + request.body = request.body; + } else if (request.requestContentType === ContentType.FormUrlEncoded) { + request.body = this.toFormUrlEncoded(request.body); + } else if (request.requestContentType === ContentType.MultipartFormData) { + request.body = this.toFormData(request.body); + } else { + request.body = JSON.stringify(request.requestSchema?.parse(request.body)); + } + + return await this.next.handle(request); + } + + toFormUrlEncoded(body: BodyInit | undefined): string { + if (body === undefined) { + return ''; + } + + if (typeof body === 'string') { + return body; + } + + if (body instanceof URLSearchParams) { + return body.toString(); + } + + if (body instanceof FormData) { + const params = new URLSearchParams(); + body.forEach((value, key) => { + params.append(key, value.toString()); + }); + return params.toString(); + } + + return ''; + } + + toFormData(body: Record): FormData | undefined { + const formData = new FormData(); + + Object.keys(body).forEach((key: any) => { + const value: any = body[key]; + if (Array.isArray(value)) { + value.forEach((v, i) => formData.append(`${key}[${i}]`, v)); + } else if (value instanceof ArrayBuffer) { + formData.append(key, new Blob([value])); + } else { + formData.append(key, value); + } + }); + + return formData; + } +} diff --git a/packages/project-client/src/http/handlers/response-validation-handler.ts b/packages/project-client/src/http/handlers/response-validation-handler.ts new file mode 100644 index 000000000..a589c09f1 --- /dev/null +++ b/packages/project-client/src/http/handlers/response-validation-handler.ts @@ -0,0 +1,106 @@ +import { ZodUndefined } from 'zod'; + +import { Request } from '../transport/request'; +import { ContentType, HttpResponse, RequestHandler } from '../types'; + +export class ResponseValidationHandler implements RequestHandler { + next?: RequestHandler; + + async handle(request: Request): Promise> { + const response = await this.next!.handle(request); + + if (!this.hasContent(request, response)) { + return response; + } + + if (request.responseContentType === ContentType.Json) { + const decodedBody = new TextDecoder().decode(response.raw); + const json = JSON.parse(decodedBody); + return { + ...response, + data: this.validate(request, json), + }; + } else if ( + request.responseContentType === ContentType.Binary || + request.responseContentType === ContentType.Image + ) { + return { + ...response, + data: this.validate(request, response.raw), + }; + } else if (request.responseContentType === ContentType.Text || request.responseContentType === ContentType.Xml) { + const text = new TextDecoder().decode(response.raw); + return { + ...response, + data: this.validate(request, text), + }; + } else if (request.responseContentType === ContentType.FormUrlEncoded) { + const urlEncoded = this.fromUrlEncoded(new TextDecoder().decode(response.raw)); + return { + ...response, + data: this.validate(request, urlEncoded), + }; + } else if (request.responseContentType === ContentType.MultipartFormData) { + const formData = this.fromFormData(response.raw); + return { + ...response, + data: this.validate(request, formData), + }; + } else { + const decodedBody = new TextDecoder().decode(response.raw); + const json = JSON.parse(decodedBody); + return { + ...response, + data: this.validate(request, json), + }; + } + } + + private validate(request: Request, data: any): T { + if (request.validation?.responseValidation) { + return request.responseSchema.parse(data); + } + return data; + } + + private hasContent(request: Request, response: HttpResponse): boolean { + return ( + !!request.responseSchema && !(request.responseSchema instanceof ZodUndefined) && response.metadata.status !== 204 + ); + } + + private fromUrlEncoded(urlEncodedData: string): object { + const pairs = urlEncodedData.split('&'); + const result: Record = {}; + + pairs.forEach((pair) => { + const [key, value] = pair.split('='); + if (key && value !== undefined) { + result[decodeURIComponent(key)] = decodeURIComponent(value); + } + }); + + return result; + } + + private fromFormData(arrayBuffer: ArrayBuffer): Record { + const decoder = new TextDecoder(); + const text = decoder.decode(arrayBuffer); + + const boundary = text.split('\r\n')[0]; + const parts = text.split(boundary).slice(1, -1); + + const formDataObj: Record = {}; + + parts.forEach((part) => { + const [header, value] = part.split('\r\n\r\n'); + const nameMatch = header.match(/name="([^"]+)"/); + if (nameMatch) { + const name = nameMatch[1].trim(); + formDataObj[name] = value?.trim() || ''; + } + }); + + return formDataObj; + } +} diff --git a/packages/project-client/src/http/handlers/retry-handler.ts b/packages/project-client/src/http/handlers/retry-handler.ts new file mode 100644 index 000000000..d3f191b82 --- /dev/null +++ b/packages/project-client/src/http/handlers/retry-handler.ts @@ -0,0 +1,40 @@ +import { HttpError } from '../error'; +import { Request } from '../transport/request'; +import { HttpResponse, RequestHandler } from '../types'; + +export class RetryHandler implements RequestHandler { + next?: RequestHandler; + + async handle(request: Request): Promise> { + if (!this.next) { + throw new Error('No next handler set in retry handler.'); + } + + for (let attempt = 1; attempt <= request.retry.attempts; attempt++) { + try { + return await this.next.handle(request); + } catch (error: any) { + if (!this.shouldRetry(error) || attempt === request.retry.attempts) { + throw error; + } + await this.delay(request.retry.delayMs); + } + } + + throw new Error('Error retrying request.'); + } + + private shouldRetry(error: Error): boolean { + return error instanceof HttpError && (error.metadata.status >= 500 || error.metadata.status === 408); + } + + private delay(delayMs: number | undefined): Promise { + if (!delayMs) { + return Promise.resolve(); + } + + return new Promise((resolve, reject) => { + setTimeout(() => resolve(), delayMs); + }); + } +} diff --git a/packages/project-client/src/http/handlers/terminating-handler.ts b/packages/project-client/src/http/handlers/terminating-handler.ts new file mode 100644 index 000000000..12f03fc7e --- /dev/null +++ b/packages/project-client/src/http/handlers/terminating-handler.ts @@ -0,0 +1,9 @@ +import { Request } from '../transport/request'; +import { RequestAxiosAdapter } from '../transport/request-axios-adapter'; +import { HttpResponse, RequestHandler } from '../types'; + +export class TerminatingHandler implements RequestHandler { + async handle(request: Request): Promise> { + return new RequestAxiosAdapter(request).send(); + } +} diff --git a/packages/project-client/src/http/hooks/custom-hook.ts b/packages/project-client/src/http/hooks/custom-hook.ts new file mode 100644 index 000000000..8bd856f19 --- /dev/null +++ b/packages/project-client/src/http/hooks/custom-hook.ts @@ -0,0 +1,28 @@ +import { HttpMetadata } from '../types'; +import { Hook, HttpError, HttpRequest, HttpResponse } from './hook'; + +export class CustomHook implements Hook { + public async beforeRequest(request: HttpRequest, params: Map): Promise { + return request; + } + + public async afterResponse( + request: HttpRequest, + response: HttpResponse, + params: Map, + ): Promise> { + return response; + } + + public async onError( + request: HttpRequest, + response: HttpResponse, + params: Map, + ): Promise { + return new CustomHttpError('a custom error message', response.metadata); + } +} + +class CustomHttpError implements HttpError { + constructor(public error: string, public metadata: HttpMetadata) {} +} diff --git a/packages/project-client/src/http/hooks/hook.ts b/packages/project-client/src/http/hooks/hook.ts new file mode 100644 index 000000000..9ca243357 --- /dev/null +++ b/packages/project-client/src/http/hooks/hook.ts @@ -0,0 +1,40 @@ +type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; + +export interface HttpRequest { + baseUrl: string; + method: HttpMethod; + path: string; + headers: Map; + body?: BodyInit; + abortSignal?: AbortSignal; + queryParams: Map; +} + +interface HttpMetadata { + status: number; + statusText: string; + headers: Record; +} + +export interface HttpResponse { + data?: T; + metadata: HttpMetadata; + raw: ArrayBuffer; +} + +export interface HttpError { + error: string; + metadata: HttpMetadata; +} + +export interface Hook { + beforeRequest(request: HttpRequest, params: Map): Promise; + + afterResponse( + request: HttpRequest, + response: HttpResponse, + params: Map, + ): Promise>; + + onError(request: HttpRequest, response: HttpResponse, params: Map): Promise; +} diff --git a/packages/project-client/src/http/httpExceptions.ts b/packages/project-client/src/http/httpExceptions.ts deleted file mode 100644 index d36bbdaed..000000000 --- a/packages/project-client/src/http/httpExceptions.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { - BadGateway, - BadRequest, - BaseHTTPError, - Conflict, - ExpectationFailed, - FailedDependency, - Forbidden, - GatewayTimeout, - Gone, - HttpVersionNotSupported, - InternalServerError, - LengthRequired, - Locked, - LoopDetected, - MethodNotAllowed, - MisdirectedRequest, - NetworkAuthenticationRequired, - NotAcceptable, - NotExtended, - NotFound, - NotImplemented, - PayloadTooLarge, - PaymentRequired, - PreconditionFailed, - PreconditionRequired, - ProxyAuthenticationRequired, - RangeNotSatisfiable, - RequestHeaderFieldsTooLarge, - RequestTimeout, - ServiceUnavailable, - TooEarly, - TooManyRequests, - Unauthorized, - UnavailableForLegalReasons, - UnprocessableEntity, - UnsufficientStorage, - UnsupportedMediaType, - UpgradeRequired, - UriTooLong, - VariantAlsoNegotiates, -} from './errors'; - -interface HttpResponseWithError { - status: number; - headers: any; - data?: any; -} - -interface NumberToClass { - [key: number]: any; -} - -const statusCodeToErrorFunction: NumberToClass = { - 400: BadRequest, - 401: Unauthorized, - 402: PaymentRequired, - 403: Forbidden, - 404: NotFound, - 405: MethodNotAllowed, - 406: NotAcceptable, - 407: ProxyAuthenticationRequired, - 408: RequestTimeout, - 409: Conflict, - 410: Gone, - 411: LengthRequired, - 412: PreconditionFailed, - 413: PayloadTooLarge, - 414: UriTooLong, - 415: UnsupportedMediaType, - 416: RangeNotSatisfiable, - 417: ExpectationFailed, - 421: MisdirectedRequest, - 422: UnprocessableEntity, - 423: Locked, - 424: FailedDependency, - 425: TooEarly, - 426: UpgradeRequired, - 428: PreconditionRequired, - 429: TooManyRequests, - 431: RequestHeaderFieldsTooLarge, - 451: UnavailableForLegalReasons, - 500: InternalServerError, - 501: NotImplemented, - 502: BadGateway, - 503: ServiceUnavailable, - 504: GatewayTimeout, - 505: HttpVersionNotSupported, - 506: VariantAlsoNegotiates, - 507: UnsufficientStorage, - 508: LoopDetected, - 510: NotExtended, - 511: NetworkAuthenticationRequired, -}; - -/** - * @summary This function will throw an error. - * - * @param {HttpResponseWithError} response - the response from a request, must contain a status and data fields - * @throws {Error} - an http error - */ -export default function throwHttpError(response: HttpResponseWithError): never { - let error: BaseHTTPError = new BaseHTTPError(response.data); - switch (response.status) { - case 401: - error = new Unauthorized(response.data, response.headers['WWW-Authenticate']); - break; - case 405: - // this indicates a bug in the spec if it allows a method that the server rejects - error = new MethodNotAllowed(response.data, response.headers.allowed); - break; - case 407: - error = new ProxyAuthenticationRequired(response.data, response.headers['Proxy-Authenticate']); - break; - case 413: - error = new PayloadTooLarge(response.data, response.headers['Retry-After']); - break; - case 429: - error = new TooManyRequests(response.data, response.headers['Retry-After']); - break; - case 503: - error = new ServiceUnavailable(response.data, response.headers['Retry-After']); - break; - default: - if (response.status in statusCodeToErrorFunction) { - error = new statusCodeToErrorFunction[response.status](response.data); - } else { - const error = new BaseHTTPError(response.data); - error.statusCode = response.status; - error.title = 'unknown error'; - } - } - - throw error; -} diff --git a/packages/project-client/src/http/index.ts b/packages/project-client/src/http/index.ts new file mode 100644 index 000000000..d8231fa58 --- /dev/null +++ b/packages/project-client/src/http/index.ts @@ -0,0 +1 @@ +export type { RequestConfig, RetryOptions, SdkConfig, ValidationOptions } from './types.ts'; diff --git a/packages/project-client/src/http/serialization/base-serializer.ts b/packages/project-client/src/http/serialization/base-serializer.ts new file mode 100644 index 000000000..7d0c7824e --- /dev/null +++ b/packages/project-client/src/http/serialization/base-serializer.ts @@ -0,0 +1,139 @@ +import { RequestParameter } from '../transport/request'; + +export type SerializationOptions = { + explode: boolean; + style: SerializationStyle; + encode: boolean; +}; + +export enum SerializationStyle { + SIMPLE = 'simple', + LABEL = 'label', + MATRIX = 'matrix', + FORM = 'form', + SPACE_DELIMITED = 'space_delimited', + PIPE_DELIMITED = 'pipe_delimited', + DEEP_OBJECT = 'deep_object', + NONE = 'none', +} + +export class Serializer { + protected serializeValue(param: RequestParameter): string { + if (Array.isArray(param.value)) { + return this.serializeArray(param.value, param); + } + + if (this.isNonNullObject(param.value)) { + return this.serializeObject(param.value, param); + } + + return this.serializePrimitive(param); + } + + private serializePrimitive(param: RequestParameter): string { + if (param.style === SerializationStyle.LABEL) { + return `.${param.value}`; + } else if (param.style === SerializationStyle.MATRIX) { + return `;${param.key}=${param.value}`; + } else if (param.style === SerializationStyle.FORM) { + return `${encodeURIComponent(param.key || '')}=${encodeURIComponent(`${param.value}`)}`; + } + + return `${param.value}`; + } + + private serializeArray(value: unknown[], param: RequestParameter): string { + if (param.explode) { + this.serializeArrayExploded(value, param); + return this.serializeArrayExploded(value, param); + } + + if (param.style === SerializationStyle.SIMPLE) { + return `${value.join(',')}`; + } else if (param.style === SerializationStyle.LABEL) { + return `.${value.join(',')}`; + } else if (param.style === SerializationStyle.MATRIX) { + return `;${param.key}=${value.join(',')}`; + } else if (param.style === SerializationStyle.FORM) { + return `${encodeURIComponent(param.key || '')}=${encodeURIComponent(value.join(','))}`; + } else if (param.style === SerializationStyle.SPACE_DELIMITED) { + return `${param.key}=${value.join(' ')}`; + } else if (param.style === SerializationStyle.PIPE_DELIMITED) { + return `${param.key}=${value.join('|')}`; + } + + return `${value.join(',')}`; + } + + private serializeArrayExploded(value: unknown[], param: RequestParameter): string { + if (param.style === SerializationStyle.SIMPLE) { + return value.map((val) => `${val}`).join(','); + } else if (param.style === SerializationStyle.LABEL) { + return value.map((val) => `.${val}`).join(''); + } else if (param.style === SerializationStyle.MATRIX) { + return value.map((val) => `;${param.key}=${val}`).join(''); + } else if ( + param.style === SerializationStyle.FORM || + param.style === SerializationStyle.SPACE_DELIMITED || + param.style === SerializationStyle.PIPE_DELIMITED + ) { + return value.map((val) => `${encodeURIComponent(param.key || '')}=${encodeURIComponent(`${val}`)}`).join('&'); + } + + return `${value.join(',')}`; + } + + private serializeObject(obj: object, param: RequestParameter): string { + if (param.explode) { + if (param.style === SerializationStyle.SIMPLE) { + return Object.entries(obj) + .map(([key, val]) => `${key}=${val}`) + .join(','); + } else if (param.style === SerializationStyle.LABEL) { + return Object.entries(obj) + .map(([key, val]) => `.${key}=${val}`) + .join(''); + } else if (param.style === SerializationStyle.MATRIX) { + return Object.entries(obj) + .map(([key, val]) => `;${key}=${val}`) + .join(''); + } else if (param.style === SerializationStyle.FORM) { + return Object.entries(obj) + .map(([key, val]) => `${key}=${val}`) + .join('&'); + } + } + + if (param.style === SerializationStyle.SIMPLE) { + return Object.entries(obj) + .map(([key, val]) => `${key},${val}`) + .join(','); + } else if (param.style === SerializationStyle.LABEL) { + return `.${Object.entries(obj) + .map(([key, val]) => `${key},${val}`) + .join(',')}`; + } else if (param.style === SerializationStyle.MATRIX) { + return `;${param.key}=${Object.entries(obj) + .map(([key, val]) => `${key},${val}`) + .join(',')}`; + } else if (param.style === SerializationStyle.FORM) { + return Object.entries(obj) + .map(([key, val]) => `${key}=${val}`) + .join('&'); + } else if (param.style === SerializationStyle.DEEP_OBJECT) { + return Object.entries(obj) + .map(([key, val]) => { + return `${param.key}[${key}]=${val}`; + }) + .join('&'); + } + + return Object.entries(obj) + .map(([key, val]) => `${key}=${val}`) + .join('&'); + } + + private isNonNullObject(value: unknown): value is object { + return typeof value === 'object' && value !== null; + } +} diff --git a/packages/project-client/src/http/serialization/header-serializer.ts b/packages/project-client/src/http/serialization/header-serializer.ts new file mode 100644 index 000000000..98f2fae41 --- /dev/null +++ b/packages/project-client/src/http/serialization/header-serializer.ts @@ -0,0 +1,19 @@ +import { RequestParameter } from '../transport/request'; +import { Serializer } from './base-serializer'; + +export class HeaderSerializer extends Serializer { + public serialize(headerParams: Map | undefined): HeadersInit | undefined { + if (!headerParams || !headerParams.size) { + return undefined; + } + + const headers: HeadersInit = {}; + headerParams.forEach((param) => { + if (!param.key) { + return; + } + headers[param.key] = this.serializeValue(param); + }); + return headers; + } +} diff --git a/packages/project-client/src/http/serialization/path-serializer.ts b/packages/project-client/src/http/serialization/path-serializer.ts new file mode 100644 index 000000000..000fa9d47 --- /dev/null +++ b/packages/project-client/src/http/serialization/path-serializer.ts @@ -0,0 +1,12 @@ +import { RequestParameter } from '../transport/request'; +import { Serializer } from './base-serializer'; + +export class PathSerializer extends Serializer { + public serialize(pathPattern: string, pathArguments: Map): string { + let serializedPath = pathPattern; + pathArguments.forEach((param: RequestParameter) => { + serializedPath = serializedPath.replace(`{${param.key}}`, `${this.serializeValue(param)}`); + }); + return serializedPath; + } +} diff --git a/packages/project-client/src/http/serialization/query-serializer.ts b/packages/project-client/src/http/serialization/query-serializer.ts new file mode 100644 index 000000000..26a193c63 --- /dev/null +++ b/packages/project-client/src/http/serialization/query-serializer.ts @@ -0,0 +1,18 @@ +import { RequestParameter } from '../transport/request'; +import { Serializer } from './base-serializer'; + +export class QuerySerializer extends Serializer { + public serialize(queryParams: Map): string { + if (!queryParams || !queryParams.size) { + return ''; + } + + const query: string[] = []; + + queryParams.forEach((param) => { + return query.push(`${this.serializeValue(param)}`); + }); + + return query.length ? `?${query.join('&')}` : ''; + } +} diff --git a/packages/project-client/src/http/transport/request-builder.ts b/packages/project-client/src/http/transport/request-builder.ts new file mode 100644 index 000000000..e4744d3ee --- /dev/null +++ b/packages/project-client/src/http/transport/request-builder.ts @@ -0,0 +1,165 @@ +import z, { ZodType } from 'zod'; + +import { Environment } from '../environment'; +import { SerializationStyle } from '../serialization/base-serializer'; +import { ContentType, HttpMethod, RequestConfig, SdkConfig } from '../types'; +import { CreateRequestParameters, Request, RequestParameter } from './request'; + +export class RequestBuilder { + private params: CreateRequestParameters; + + constructor() { + this.params = { + baseUrl: Environment.DEFAULT, + method: 'GET', + path: '', + config: {}, + responseSchema: z.any(), + requestSchema: z.any(), + requestContentType: ContentType.Json, + responseContentType: ContentType.Json, + retry: { + attempts: 3, + delayMs: 150, + }, + validation: { + responseValidation: true, + }, + pathParams: new Map(), + queryParams: new Map(), + headers: new Map(), + }; + } + + setRetryAttempts(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + if (requestConfig?.retry?.attempts !== undefined) { + this.params.retry.attempts = requestConfig.retry.attempts; + } else if (sdkConfig?.retry?.attempts !== undefined) { + this.params.retry.attempts = sdkConfig.retry.attempts; + } + + return this; + } + + setRetryDelayMs(sdkConfig?: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + if (requestConfig?.retry?.delayMs !== undefined) { + this.params.retry.delayMs = requestConfig.retry.delayMs; + } else if (sdkConfig?.retry?.delayMs !== undefined) { + this.params.retry.delayMs = sdkConfig.retry.delayMs; + } + + return this; + } + + setResponseValidation(sdkConfig: SdkConfig, requestConfig?: RequestConfig): RequestBuilder { + if (requestConfig?.validation?.responseValidation !== undefined) { + this.params.validation.responseValidation = requestConfig.validation.responseValidation; + } else if (sdkConfig?.validation?.responseValidation !== undefined) { + this.params.validation.responseValidation = sdkConfig.validation.responseValidation; + } + + return this; + } + + setBaseUrl(sdkConfig: SdkConfig): RequestBuilder { + if (sdkConfig?.baseUrl !== undefined) { + this.params.baseUrl = sdkConfig.baseUrl; + } + + return this; + } + + setMethod(method: HttpMethod): RequestBuilder { + this.params.method = method; + return this; + } + + setPath(path: string): RequestBuilder { + this.params.path = path; + return this; + } + + setConfig(config: SdkConfig): RequestBuilder { + this.params.config = config; + return this; + } + + setRequestContentType(contentType: ContentType): RequestBuilder { + this.params.requestContentType = contentType; + return this; + } + + setResponseContentType(contentType: ContentType): RequestBuilder { + this.params.responseContentType = contentType; + return this; + } + + setRequestSchema(requestSchema: ZodType): RequestBuilder { + this.params.requestSchema = requestSchema; + return this; + } + + setResponseSchema(responseSchema: ZodType): RequestBuilder { + this.params.responseSchema = responseSchema; + return this; + } + + addBody(body?: any): RequestBuilder { + if (body !== undefined) { + this.params.body = body; + } + return this; + } + + addPathParam(param: Partial): RequestBuilder { + if (param.value === undefined || param.key === undefined) { + return this; + } + + this.params.pathParams.set(param.key, { + key: param.key, + value: param.value, + explode: param.explode ?? true, + style: param.style ?? SerializationStyle.SIMPLE, + encode: param.encode ?? true, + }); + + return this; + } + + addQueryParam(param: Partial): RequestBuilder { + if (param.value === undefined || param.key === undefined) { + return this; + } + + this.params.queryParams.set(param.key, { + key: param.key, + value: param.value, + explode: param.explode ?? true, + style: param.style ?? SerializationStyle.FORM, + encode: param.encode ?? true, + }); + + return this; + } + + addHeaderParam(param: Partial): RequestBuilder { + if (param.value === undefined || param.key === undefined) { + return this; + } + + this.params.headers.set(param.key, { + key: param.key, + value: param.value, + explode: param.explode ?? true, + style: param.style ?? SerializationStyle.SIMPLE, + encode: param.encode ?? false, + }); + + return this; + } + + public build(): Request { + return new Request(this.params); + } +} diff --git a/packages/project-client/src/http/transport/request.ts b/packages/project-client/src/http/transport/request.ts new file mode 100644 index 000000000..82af8178c --- /dev/null +++ b/packages/project-client/src/http/transport/request.ts @@ -0,0 +1,210 @@ +import { ZodType } from 'zod'; + +import { HttpRequest } from '../hooks/hook'; +import { SerializationStyle } from '../serialization/base-serializer'; +import { HeaderSerializer } from '../serialization/header-serializer'; +import { PathSerializer } from '../serialization/path-serializer'; +import { QuerySerializer } from '../serialization/query-serializer'; +import { ContentType, HttpMethod, RetryOptions, SdkConfig, ValidationOptions } from '../types'; + +export interface CreateRequestParameters { + baseUrl: string; + method: HttpMethod; + body?: any; + headers: Map; + queryParams: Map; + pathParams: Map; + path: string; + config: SdkConfig; + responseSchema: ZodType; + requestSchema: ZodType; + requestContentType: ContentType; + responseContentType: ContentType; + validation: ValidationOptions; + retry: RetryOptions; +} + +export interface RequestParameter { + key: string | undefined; + value: unknown; + explode: boolean; + encode: boolean; + style: SerializationStyle; +} + +export class Request { + public baseUrl = ''; + + public headers: Map = new Map(); + + public queryParams: Map = new Map(); + + public pathParams: Map = new Map(); + + public body?: any; + + public method: HttpMethod; + + public path: string; + + public config: SdkConfig; + + public responseSchema: ZodType; + + public requestSchema: ZodType; + + public requestContentType: ContentType; + + public responseContentType: ContentType; + + public validation: ValidationOptions = {} as any; + + public retry: RetryOptions = {} as any; + + private readonly pathPattern: string; + + constructor(params: CreateRequestParameters) { + this.baseUrl = params.baseUrl; + this.method = params.method; + this.pathPattern = params.path; + this.body = params.body; + this.path = this.constructPath(); + this.config = params.config; + this.pathParams = params.pathParams; + this.headers = params.headers; + this.queryParams = params.queryParams; + this.responseSchema = params.responseSchema; + this.requestSchema = params.requestSchema; + this.requestContentType = params.requestContentType; + this.responseContentType = params.responseContentType; + this.retry = params.retry; + this.validation = params.validation; + } + + addHeaderParam(key: string, param: RequestParameter): void { + if (param.value === undefined) { + return; + } + + if (param.explode === undefined) { + param.explode = false; + } + + if (param.style === undefined) { + param.style = SerializationStyle.SIMPLE; + } + + if (param.encode === undefined) { + param.encode = false; + } + + this.headers.set(key, param); + } + + addQueryParam(key: string, param: RequestParameter): void { + if (param.value === undefined) { + return; + } + + if (param.explode === undefined) { + param.explode = true; + } + + if (param.style === undefined) { + param.style = SerializationStyle.FORM; + } + + if (param.encode === undefined) { + param.encode = true; + } + + this.queryParams.set(key, param); + } + + addPathParam(key: string, param: RequestParameter): void { + if (param.value === undefined) { + return; + } + + if (param.explode === undefined) { + param.explode = false; + } + + if (param.style === undefined) { + param.style = SerializationStyle.SIMPLE; + } + + if (param.encode === undefined) { + param.encode = true; + } + + this.pathParams.set(key, param); + } + + addBody(body: any): void { + if (body === undefined) { + return; + } + + this.body = body; + } + + public updateFromHookRequest(hookRequest: HttpRequest): void { + this.baseUrl = hookRequest.baseUrl; + this.method = hookRequest.method; + this.path = hookRequest.path; + this.body = hookRequest.body; + } + + public toHookRequest(): HttpRequest { + return { + baseUrl: this.baseUrl, + method: this.method, + path: this.path, + headers: this.headers, + body: this.body, + queryParams: this.queryParams, + }; + } + + public constructFullUrl(): string { + const queryString = new QuerySerializer().serialize(this.queryParams); + const path = this.constructPath(); + return `${this.baseUrl}${path}${queryString}`; + } + + public copy(overrides?: Partial>) { + const createRequestParams: CreateRequestParameters = { + baseUrl: overrides?.baseUrl ?? this.baseUrl, + method: overrides?.method ?? this.method, + path: overrides?.path ?? this.path, + body: overrides?.body ?? this.body, + config: overrides?.config ?? this.config, + pathParams: overrides?.pathParams ?? this.pathParams, + queryParams: overrides?.queryParams ?? this.queryParams, + headers: overrides?.headers ?? this.headers, + responseSchema: overrides?.responseSchema ?? this.responseSchema, + requestSchema: overrides?.requestSchema ?? this.requestSchema, + requestContentType: overrides?.requestContentType ?? this.requestContentType, + responseContentType: overrides?.responseContentType ?? this.responseContentType, + retry: overrides?.retry ?? this.retry, + validation: overrides?.validation ?? this.validation, + }; + return new Request({ + ...createRequestParams, + ...overrides, + }); + } + + public getHeaders(): HeadersInit | undefined { + if (!this.headers || !this.headers.size) { + return undefined; + } + + return new HeaderSerializer().serialize(this.headers); + } + + private constructPath(): string { + return new PathSerializer().serialize(this.pathPattern, this.pathParams); + } +} diff --git a/packages/project-client/src/http/transport/transport-hook-adapter.ts b/packages/project-client/src/http/transport/transport-hook-adapter.ts new file mode 100644 index 000000000..0ae51d6ce --- /dev/null +++ b/packages/project-client/src/http/transport/transport-hook-adapter.ts @@ -0,0 +1,85 @@ +import { CustomHook } from '../hooks/custom-hook'; +import { HttpError, HttpRequest } from '../hooks/hook'; +import { SerializationStyle } from '../serialization/base-serializer'; +import { HttpResponse } from '../types'; +import { Request, RequestParameter } from './request'; + +export class TransportHookAdapter { + private hook: CustomHook = new CustomHook(); + + public async beforeRequest(request: Request, params: Map): Promise> { + const hookRequest = this.requestToHookRequest(request); + + const newRequest = await this.hook.beforeRequest(hookRequest, params); + + const newTransportRequest = request.copy({ + baseUrl: newRequest.baseUrl, + method: newRequest.method, + path: newRequest.path, + body: newRequest.body, + queryParams: this.hookParamsToTransportParams(newRequest.queryParams, request.queryParams, true), + headers: this.hookParamsToTransportParams(newRequest.headers, request.headers, false), + }); + + return newTransportRequest; + } + + public async afterResponse( + request: Request, + response: HttpResponse, + params: Map, + ): Promise> { + const hookRequest = this.requestToHookRequest(request); + return this.hook.afterResponse(hookRequest, response, params); + } + + public async onError( + request: Request, + response: HttpResponse, + params: Map, + ): Promise { + const hookRequest = this.requestToHookRequest(request); + return this.hook.onError(hookRequest, response, params); + } + + private requestToHookRequest(request: Request): HttpRequest { + const hookHeaders: Map = new Map(); + request.headers.forEach((header, key) => { + hookHeaders.set(key, header.value); + }); + + const hookQueryParams: Map = new Map(); + request.queryParams.forEach((queryParam, key) => { + hookQueryParams.set(key, queryParam.value); + }); + + const hookRequest: HttpRequest = { + baseUrl: request.baseUrl, + method: request.method, + path: request.path, + headers: hookHeaders, + body: request.body, + queryParams: hookQueryParams, + }; + return hookRequest; + } + + private hookParamsToTransportParams( + hookParams: Map, + originalTransportParams: Map, + encode: boolean, + ): Map { + const transportParams: Map = new Map(); + hookParams.forEach((hookParamValue, hookParamKey) => { + const requestParam = originalTransportParams.get(hookParamKey); + transportParams.set(hookParamKey, { + key: hookParamKey, + value: hookParamValue, + encode: requestParam?.encode ?? false, + style: requestParam?.style || SerializationStyle.NONE, + explode: requestParam?.explode ?? false, + }); + }); + return transportParams; + } +} diff --git a/packages/project-client/src/http/types.ts b/packages/project-client/src/http/types.ts new file mode 100644 index 000000000..a3870a4f2 --- /dev/null +++ b/packages/project-client/src/http/types.ts @@ -0,0 +1,70 @@ +import { ZodType } from 'zod'; + +import { Environment } from './environment'; +import { Request } from './transport/request'; + +export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; + +export interface SdkConfig { + baseUrl?: string; + environment?: Environment; + timeout?: number; + token?: string; + retry?: RetryOptions; + validation?: ValidationOptions; +} + +export interface HttpMetadata { + status: number; + statusText: string; + headers: Record; +} + +export interface HttpResponse { + data?: T; + metadata: HttpMetadata; + raw: ArrayBuffer; +} + +export interface RequestHandler { + next?: RequestHandler; + + handle(request: Request): Promise>; +} + +export enum ContentType { + Json = 'json', + Xml = 'xml', + Pdf = 'pdf', + Image = 'image', + File = 'file', + Binary = 'binary', + FormUrlEncoded = 'form', + Text = 'text', + MultipartFormData = 'multipartFormData', +} + +export interface Options { + responseSchema: ZodType; + requestSchema?: ZodType; + body?: any; + requestContentType?: ContentType; + responseContentType?: ContentType; + abortSignal?: AbortSignal; + queryParams?: Record; + retry?: RetryOptions; +} + +export interface RequestConfig { + retry?: RetryOptions; + validation?: ValidationOptions; +} + +export interface RetryOptions { + attempts: number; + delayMs?: number; +} + +export interface ValidationOptions { + responseValidation?: boolean; +} diff --git a/packages/project-client/src/index.ts b/packages/project-client/src/index.ts index c29ba6480..a7bc397a6 100644 --- a/packages/project-client/src/index.ts +++ b/packages/project-client/src/index.ts @@ -1,50 +1,66 @@ -import { BroadcastsService } from './services/broadcasts/Broadcasts'; -import { ChannelsService } from './services/channels/Channels'; -import { IntegrationsService } from './services/integrations/Integrations'; +import { Environment } from './http/environment'; +import { SdkConfig } from './http/types'; +import { BroadcastsService } from './services/broadcasts'; +import { ChannelsService } from './services/channels'; +import { IntegrationsService } from './services/integrations'; +import { JwtService } from './services/jwt'; -export * from './models'; -export * as BroadcastsModels from './services/broadcasts'; -export * as ChannelsModels from './services/channels'; -export * as IntegrationsModels from './services/integrations'; +export type * from './http'; +export * from './services/broadcasts'; +export * from './services/channels'; +export * from './services/integrations'; +export * from './services/jwt'; -type Config = { - accessToken?: string; -}; +export class Client { + public readonly broadcasts: BroadcastsService; -export * from './http/errors'; + public readonly integrations: IntegrationsService; -/** - * OpenAPI 3.1.0 Specification for MagicBell API. - */ -export class Client { - public broadcasts: BroadcastsService; - public channels: ChannelsService; - public integrations: IntegrationsService; - - constructor({ accessToken = '' }: Config) { - this.broadcasts = new BroadcastsService(accessToken); - this.channels = new ChannelsService(accessToken); - this.integrations = new IntegrationsService(accessToken); + public readonly jwt: JwtService; + + public readonly channels: ChannelsService; + + constructor(public config: SdkConfig) { + const baseUrl = config.environment || config.baseUrl || Environment.DEFAULT; + this.config = { + ...config, + baseUrl, + }; + this.broadcasts = new BroadcastsService(this.config); + + this.integrations = new IntegrationsService(this.config); + + this.jwt = new JwtService(this.config); + + this.channels = new ChannelsService(this.config); + } + + set baseUrl(baseUrl: string) { + this.broadcasts.baseUrl = baseUrl; + this.integrations.baseUrl = baseUrl; + this.jwt.baseUrl = baseUrl; + this.channels.baseUrl = baseUrl; + } + + set environment(environment: Environment) { + this.broadcasts.baseUrl = environment; + this.integrations.baseUrl = environment; + this.jwt.baseUrl = environment; + this.channels.baseUrl = environment; } - /** - * Sets the baseUrl that the SDK will use for its requests. - * @param {string} url - */ - setBaseUrl(url: string): void { - this.broadcasts.setBaseUrl(url); - this.channels.setBaseUrl(url); - this.integrations.setBaseUrl(url); + set timeout(timeout: number) { + this.broadcasts.timeout = timeout; + this.integrations.timeout = timeout; + this.jwt.timeout = timeout; + this.channels.timeout = timeout; } - /** - * Sets the access token used to authenticate. - * @param {string} accessToken - */ - setAccessToken(accessToken: string) { - this.broadcasts.setAccessToken(accessToken); - this.channels.setAccessToken(accessToken); - this.integrations.setAccessToken(accessToken); + set token(token: string) { + this.broadcasts.token = token; + this.integrations.token = token; + this.jwt.token = token; + this.channels.token = token; } } diff --git a/packages/project-client/src/models.ts b/packages/project-client/src/models.ts deleted file mode 100644 index fe5b5ca50..000000000 --- a/packages/project-client/src/models.ts +++ /dev/null @@ -1,44 +0,0 @@ -export type { Broadcast } from './services/broadcasts/models/Broadcast'; -export type { BroadcastListResponse } from './services/broadcasts/models/BroadcastListResponse'; -export type { CreateBroadcastRequest } from './services/broadcasts/models/CreateBroadcastRequest'; -export type { Topic } from './services/broadcasts/models/Topic'; -export type { User } from './services/broadcasts/models/User'; -export type { ApnsToken } from './services/channels/models/ApnsToken'; -export type { ApnsTokenWithMetadata } from './services/channels/models/ApnsTokenWithMetadata'; -export type { ArrayWithMetadataOfApnsToken } from './services/channels/models/ArrayWithMetadataOfApnsToken'; -export type { ArrayWithMetadataOfFcmToken } from './services/channels/models/ArrayWithMetadataOfFcmToken'; -export type { ArrayWithMetadataOfSlackToken } from './services/channels/models/ArrayWithMetadataOfSlackToken'; -export type { ArrayWithMetadataOfTeamsToken } from './services/channels/models/ArrayWithMetadataOfTeamsToken'; -export type { ArrayWithMetadataOfWebPushToken } from './services/channels/models/ArrayWithMetadataOfWebPushToken'; -export type { DiscardResult } from './services/channels/models/DiscardResult'; -export type { FcmToken } from './services/channels/models/FcmToken'; -export type { FcmTokenWithMetadata } from './services/channels/models/FcmTokenWithMetadata'; -export type { SlackToken } from './services/channels/models/SlackToken'; -export type { SlackTokenWithMetadata } from './services/channels/models/SlackTokenWithMetadata'; -export type { TeamsToken } from './services/channels/models/TeamsToken'; -export type { TeamsTokenWithMetadata } from './services/channels/models/TeamsTokenWithMetadata'; -export type { WebPushToken } from './services/channels/models/WebPushToken'; -export type { WebPushTokenWithMetadata } from './services/channels/models/WebPushTokenWithMetadata'; -export type { ApnsConfig } from './services/integrations/models/ApnsConfig'; -export type { FcmConfig } from './services/integrations/models/FcmConfig'; -export type { InboxConfig } from './services/integrations/models/InboxConfig'; -export type { ListIntegrationsResponse } from './services/integrations/models/ListIntegrationsResponse'; -export type { MailgunConfig } from './services/integrations/models/MailgunConfig'; -export type { PingConfig } from './services/integrations/models/PingConfig'; -export type { SaveApnsIntegrationRequest } from './services/integrations/models/SaveApnsIntegrationRequest'; -export type { SaveFcmIntegrationRequest } from './services/integrations/models/SaveFcmIntegrationRequest'; -export type { SaveInboxIntegrationRequest } from './services/integrations/models/SaveInboxIntegrationRequest'; -export type { SaveMailgunIntegrationRequest } from './services/integrations/models/SaveMailgunIntegrationRequest'; -export type { SavePingEmailIntegrationRequest } from './services/integrations/models/SavePingEmailIntegrationRequest'; -export type { SaveSendgridIntegrationRequest } from './services/integrations/models/SaveSendgridIntegrationRequest'; -export type { SaveSlackIntegrationRequest } from './services/integrations/models/SaveSlackIntegrationRequest'; -export type { SaveStripeIntegrationRequest } from './services/integrations/models/SaveStripeIntegrationRequest'; -export type { SaveTemplatesIntegrationRequest } from './services/integrations/models/SaveTemplatesIntegrationRequest'; -export type { SaveTemplatesIntegrationResponse } from './services/integrations/models/SaveTemplatesIntegrationResponse'; -export type { SaveTwilioIntegrationRequest } from './services/integrations/models/SaveTwilioIntegrationRequest'; -export type { SaveWebPushIntegrationRequest } from './services/integrations/models/SaveWebPushIntegrationRequest'; -export type { SendgridConfig } from './services/integrations/models/SendgridConfig'; -export type { SlackConfig } from './services/integrations/models/SlackConfig'; -export type { StripeConfig } from './services/integrations/models/StripeConfig'; -export type { TwilioConfig } from './services/integrations/models/TwilioConfig'; -export type { WebpushConfig } from './services/integrations/models/WebpushConfig'; diff --git a/packages/project-client/src/services/README.md b/packages/project-client/src/services/README.md deleted file mode 100644 index dfaf8391a..000000000 --- a/packages/project-client/src/services/README.md +++ /dev/null @@ -1,1254 +0,0 @@ -# Client Services - -A list of all services and services methods. - -- Services - - - [Broadcasts](#broadcasts) - - - [Integrations](#integrations) - - - [Channels](#channels) - -- [All Methods](#all-methods) - -## Broadcasts - -| Method | Description | -| :---------------------------------- | :---------- | -| [createBroadcast](#createbroadcast) | | -| [listBroadcasts](#listbroadcasts) | | -| [fetchBroadcast](#fetchbroadcast) | | - -## Integrations - -| Method | Description | -| :-------------------------------------------------------- | :---------- | -| [listIntegrations](#listintegrations) | | -| [deleteApnsIntegration](#deleteapnsintegration) | | -| [saveApnsIntegration](#saveapnsintegration) | | -| [deleteFcmIntegration](#deletefcmintegration) | | -| [saveFcmIntegration](#savefcmintegration) | | -| [deleteInboxIntegration](#deleteinboxintegration) | | -| [saveInboxIntegration](#saveinboxintegration) | | -| [deleteMailgunIntegration](#deletemailgunintegration) | | -| [saveMailgunIntegration](#savemailgunintegration) | | -| [deletePingEmailIntegration](#deletepingemailintegration) | | -| [savePingEmailIntegration](#savepingemailintegration) | | -| [deleteSendgridIntegration](#deletesendgridintegration) | | -| [saveSendgridIntegration](#savesendgridintegration) | | -| [deleteSlackIntegration](#deleteslackintegration) | | -| [saveSlackIntegration](#saveslackintegration) | | -| [deleteStripeIntegration](#deletestripeintegration) | | -| [saveStripeIntegration](#savestripeintegration) | | -| [deleteTemplatesIntegration](#deletetemplatesintegration) | | -| [saveTemplatesIntegration](#savetemplatesintegration) | | -| [deleteTwilioIntegration](#deletetwiliointegration) | | -| [saveTwilioIntegration](#savetwiliointegration) | | -| [deleteWebPushIntegration](#deletewebpushintegration) | | -| [saveWebPushIntegration](#savewebpushintegration) | | - -## Channels - -| Method | Description | -| :---------------------------------------------------------------- | :---------- | -| [getMobilePushApnsUserTokens](#getmobilepushapnsusertokens) | | -| [getMobilePushApnsUserToken](#getmobilepushapnsusertoken) | | -| [discardMobilePushApnsUserToken](#discardmobilepushapnsusertoken) | | -| [getMobilePushFcmUserTokens](#getmobilepushfcmusertokens) | | -| [getMobilePushFcmUserToken](#getmobilepushfcmusertoken) | | -| [discardMobilePushFcmUserToken](#discardmobilepushfcmusertoken) | | -| [getSlackUserTokens](#getslackusertokens) | | -| [getSlackUserToken](#getslackusertoken) | | -| [discardSlackUserToken](#discardslackusertoken) | | -| [getTeamsUserTokens](#getteamsusertokens) | | -| [getTeamsUserToken](#getteamsusertoken) | | -| [discardTeamsUserToken](#discardteamsusertoken) | | -| [getWebPushUserTokens](#getwebpushusertokens) | | -| [getWebPushUserToken](#getwebpushusertoken) | | -| [discardWebPushUserToken](#discardwebpushusertoken) | | - -## All Methods - -### **createBroadcast** - -- HTTP Method: POST -- Endpoint: /broadcasts - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -Broadcast - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - action_url: 'https://example.com', - category: 'example', - content: 'Hello, World!', - custom_attributes: {}, - overrides: {}, - recipients: [ - { - custom_attributes: { - plan: 'enterprise', - preferred_pronoun: 'They', - pricing_version: 'v10', - }, - external_id: '83d987a-83fd034', - first_name: 'Person', - last_name: 'Doe', - phone_numbers: ['+1 5005550001'], - }, - ], - title: 'Hello, World!', - topic: 'example', - }; - const result = await sdk.broadcasts.createBroadcast(input); - console.log(result); -})(); - -``` - -### **listBroadcasts** - -- HTTP Method: GET -- Endpoint: /broadcasts - -**Return Type** - -BroadcastListResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.broadcasts.listBroadcasts(); - console.log(result); -})(); - -``` - -### **fetchBroadcast** - -- HTTP Method: GET -- Endpoint: /broadcasts/{broadcast_id} - -**Required Parameters** - -| Name | Type | Description | -| :---------- | :----- | :---------- | -| broadcastId | string | | - -**Return Type** - -Broadcast - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.broadcasts.fetchBroadcast('broadcast_id'); - console.log(result); -})(); - -``` - -### **listIntegrations** - -- HTTP Method: GET -- Endpoint: /integrations - -**Return Type** - -ListIntegrationsResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.listIntegrations(); - console.log(result); -})(); - -``` - -### **deleteApnsIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/apns - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteApnsIntegration(); - console.log(result); -})(); - -``` - -### **saveApnsIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/apns - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -ApnsConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }; - const result = await sdk.integrations.saveApnsIntegration(input); - console.log(result); -})(); - -``` - -### **deleteFcmIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/fcm - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteFcmIntegration(); - console.log(result); -})(); - -``` - -### **saveFcmIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/fcm - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -FcmConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - auth_provider_x509_cert_url: '', - auth_uri: '', - client_email: '', - client_id: '', - client_x509_cert_url: '', - private_key: - '-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDQ8J\n-----END PRIVATE', - private_key_id: 'e7', - project_id: 'universe-1', - token_uri: '', - type: 'service_account', - universe_domain: 'universe-1.firebaseapp.com', - }; - const result = await sdk.integrations.saveFcmIntegration(input); - console.log(result); -})(); - -``` - -### **deleteInboxIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/inbox - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteInboxIntegration(); - console.log(result); -})(); - -``` - -### **saveInboxIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/inbox - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -InboxConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - apns: { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }, - }; - const result = await sdk.integrations.saveInboxIntegration(input); - console.log(result); -})(); - -``` - -### **deleteMailgunIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/mailgun - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteMailgunIntegration(); - console.log(result); -})(); - -``` - -### **saveMailgunIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/mailgun - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -MailgunConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { api_key: 'mailgun_api_key', domain: 'mailgun_domain', region: 'us' }; - const result = await sdk.integrations.saveMailgunIntegration(input); - console.log(result); -})(); - -``` - -### **deletePingEmailIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/ping_email - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deletePingEmailIntegration(); - console.log(result); -})(); - -``` - -### **savePingEmailIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/ping_email - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -PingConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { url: 'https://example.com/webhook' }; - const result = await sdk.integrations.savePingEmailIntegration(input); - console.log(result); -})(); - -``` - -### **deleteSendgridIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/sendgrid - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteSendgridIntegration(); - console.log(result); -})(); - -``` - -### **saveSendgridIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/sendgrid - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SendgridConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - api_key: 'SG.1234567890', - from: { email: 'matt@magicbell.com', name: 'Matt' }, - reply_to: { email: 'hana@magicbell.com', name: 'Hana' }, - }; - const result = await sdk.integrations.saveSendgridIntegration(input); - console.log(result); -})(); - -``` - -### **deleteSlackIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/slack - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteSlackIntegration(); - console.log(result); -})(); - -``` - -### **saveSlackIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/slack - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SlackConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - app_id: '12345678901', - client_id: '1.0', - client_secret: '12345678901234567890123456789012', - signing_secret: '12345678901234567890123456789012', - }; - const result = await sdk.integrations.saveSlackIntegration(input); - console.log(result); -})(); - -``` - -### **deleteStripeIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/stripe - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteStripeIntegration(); - console.log(result); -})(); - -``` - -### **saveStripeIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/stripe - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -StripeConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - webhook_signing_secret: - 'whsec_e5cf4458caae49ae72d8f275deb9b63bdd41dd5c932c27c9346d428fb9e1d0a0', - }; - const result = await sdk.integrations.saveStripeIntegration(input); - console.log(result); -})(); - -``` - -### **deleteTemplatesIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/templates - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteTemplatesIntegration(); - console.log(result); -})(); - -``` - -### **saveTemplatesIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/templates - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -SaveTemplatesIntegrationResponse - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - apns: { - app_id: 'com.example.myapp', - badge: 'unread', - certificate: 'MIICXQIBAAKBgQC3J2', - key_id: 'ABCD1234EF', - team_id: 'ABCD1234EF', - }, - }; - const result = await sdk.integrations.saveTemplatesIntegration(input); - console.log(result); -})(); - -``` - -### **deleteTwilioIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/twilio - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteTwilioIntegration(); - console.log(result); -})(); - -``` - -### **saveTwilioIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/twilio - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -TwilioConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { - account_sid: 'ACXXXXXXXX', - api_key: 'SKXXXXXXXX', - api_secret: 'your_api_secret', - from: '+15017122661', - region: 'us1', - }; - const result = await sdk.integrations.saveTwilioIntegration(input); - console.log(result); -})(); - -``` - -### **deleteWebPushIntegration** - -- HTTP Method: DELETE -- Endpoint: /integrations/web_push - -**Return Type** - -Returns a dict object. - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.integrations.deleteWebPushIntegration(); - console.log(result); -})(); - -``` - -### **saveWebPushIntegration** - -- HTTP Method: PUT -- Endpoint: /integrations/web_push - -**Required Parameters** - -| input | object | Request body. | - -**Return Type** - -WebpushConfig - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const input = { private_key: '', public_key: '' }; - const result = await sdk.integrations.saveWebPushIntegration(input); - console.log(result); -})(); - -``` - -### **getMobilePushApnsUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfApnsToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushApnsUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getMobilePushApnsUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -ApnsTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushApnsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardMobilePushApnsUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/mobile_push/apns/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardMobilePushApnsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getMobilePushFcmUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfFcmToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushFcmUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getMobilePushFcmUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -FcmTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getMobilePushFcmUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardMobilePushFcmUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/mobile_push/fcm/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardMobilePushFcmUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getSlackUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/slack/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfSlackToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getSlackUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getSlackUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -SlackTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getSlackUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardSlackUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/slack/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardSlackUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getTeamsUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/teams/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfTeamsToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getTeamsUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getTeamsUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -TeamsTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getTeamsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardTeamsUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/teams/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardTeamsUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **getWebPushUserTokens** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/web_push/tokens - -**Required Parameters** - -| Name | Type | Description | -| :----- | :----- | :---------- | -| userId | string | | - -**Return Type** - -ArrayWithMetadataOfWebPushToken - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getWebPushUserTokens('user_id'); - console.log(result); -})(); - -``` - -### **getWebPushUserToken** - -- HTTP Method: GET -- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -WebPushTokenWithMetadata - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.getWebPushUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` - -### **discardWebPushUserToken** - -- HTTP Method: DELETE -- Endpoint: /users/{user_id}/channels/web_push/tokens/{token_id} - -**Required Parameters** - -| Name | Type | Description | -| :------ | :----- | :---------- | -| userId | string | | -| tokenId | string | | - -**Return Type** - -DiscardResult - -**Example Usage Code Snippet** - -```Typescript -import { Client } from '@magicbell/project-client'; - -const sdk = new Client({ accessToken: process.env.CLIENT_ACCESS_TOKEN }); - -(async () => { - const result = await sdk.channels.discardWebPushUserToken('user_id', 'token_id'); - console.log(result); -})(); - -``` diff --git a/packages/project-client/src/services/base-service.ts b/packages/project-client/src/services/base-service.ts new file mode 100644 index 000000000..311c14644 --- /dev/null +++ b/packages/project-client/src/services/base-service.ts @@ -0,0 +1,27 @@ +import { HttpClient } from '../http/client'; +import { Environment } from '../http/environment'; +import { SdkConfig } from '../http/types'; + +export class BaseService { + public client: HttpClient; + + constructor(public config: SdkConfig) { + this.client = new HttpClient(this.config); + } + + set baseUrl(baseUrl: string) { + this.config.baseUrl = baseUrl; + } + + set environment(environment: Environment) { + this.config.environment = environment; + } + + set timeout(timeout: number) { + this.config.timeout = timeout; + } + + set token(token: string) { + this.config.token = token; + } +} diff --git a/packages/project-client/src/services/broadcasts/Broadcasts.ts b/packages/project-client/src/services/broadcasts/Broadcasts.ts index 5c90f8e3b..6c9e4d0c7 100644 --- a/packages/project-client/src/services/broadcasts/Broadcasts.ts +++ b/packages/project-client/src/services/broadcasts/Broadcasts.ts @@ -1,67 +1,93 @@ -import BaseService from '../../BaseService'; -import { serializePath } from '../../http/QuerySerializer'; -import { Broadcast } from './models/Broadcast'; -import { BroadcastListResponse } from './models/BroadcastListResponse'; -import { CreateBroadcastRequest } from './models/CreateBroadcastRequest'; +import { z } from 'zod'; + +import { RequestBuilder } from '../../http/transport/request-builder'; +import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; +import { BaseService } from '../base-service'; +import { Broadcast, broadcastRequest, broadcastResponse } from './models/broadcast'; +import { BroadcastListResponse, broadcastListResponseResponse } from './models/broadcast-list-response'; +import { ListBroadcastsParams } from './request-params'; export class BroadcastsService extends BaseService { /** - * @description Returns a list of broadcasts + * Returns a list of broadcasts + * @param {number} [page] - The page number of the paginated response. Defaults to 1. + * @param {number} [perPage] - The number of items per page. Defaults to 20. + * @returns {Promise>} OK */ - async listBroadcasts(): Promise { - const urlEndpoint = '/broadcasts'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as BroadcastListResponse; - return responseModel; + async listBroadcasts( + params?: ListBroadcastsParams, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/broadcasts') + .setRequestSchema(z.any()) + .setResponseSchema(broadcastListResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addQueryParam({ + key: 'page', + value: params?.page, + }) + .addQueryParam({ + key: 'per_page', + value: params?.perPage, + }) + .build(); + return this.client.call(request); } /** - * @description Handles the create notification request. + * Handles the create notification request. + * @returns {Promise>} Created */ - async createBroadcast(input: CreateBroadcastRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/broadcasts'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.post( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as Broadcast; - return responseModel; + async createBroadcast(body: Broadcast, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('POST') + .setPath('/broadcasts') + .setRequestSchema(broadcastRequest) + .setResponseSchema(broadcastResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); } /** - * @description Returns a broadcast + * Returns a broadcast + * @param {string} broadcastId - + * @returns {Promise>} OK */ - async fetchBroadcast(broadcastId: string): Promise { - if (broadcastId === undefined) { - throw new Error('The following parameter is required: broadcastId, cannot be empty or blank'); - } - let urlEndpoint = '/broadcasts/{broadcast_id}'; - urlEndpoint = urlEndpoint.replace('{broadcast_id}', serializePath('simple', false, broadcastId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as Broadcast; - return responseModel; + async fetchBroadcast(broadcastId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/broadcasts/{broadcast_id}') + .setRequestSchema(z.any()) + .setResponseSchema(broadcastResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'broadcast_id', + value: broadcastId, + }) + .build(); + return this.client.call(request); } } diff --git a/packages/project-client/src/services/broadcasts/index.ts b/packages/project-client/src/services/broadcasts/index.ts index 11e083bc5..7d928e693 100644 --- a/packages/project-client/src/services/broadcasts/index.ts +++ b/packages/project-client/src/services/broadcasts/index.ts @@ -1,3 +1,2 @@ -export type { Broadcast } from './models/Broadcast'; -export type { BroadcastListResponse } from './models/BroadcastListResponse'; -export type { CreateBroadcastRequest } from './models/CreateBroadcastRequest'; +export { BroadcastsService } from './broadcasts'; +export * from './models'; diff --git a/packages/project-client/src/services/broadcasts/models/Broadcast.ts b/packages/project-client/src/services/broadcasts/models/Broadcast.ts index f72dd6b5e..78bdf715b 100644 --- a/packages/project-client/src/services/broadcasts/models/Broadcast.ts +++ b/packages/project-client/src/services/broadcasts/models/Broadcast.ts @@ -1,92 +1,89 @@ -import { Topic } from './Topic'; -import { User } from './User'; +import { z } from 'zod'; -export interface Broadcast { - action_url?: string; - category?: string; - content?: string; - custom_attributes?: CustomAttributes; - overrides?: Overrides; - /** - * @minItems 1 - * @maxItems 1000 - */ - recipients: [Topic | User, ...(Topic | User)[]]; - title: string; - topic?: string; -} -interface CustomAttributes { - [k: string]: unknown; -} -interface Overrides { - channels?: Channels; - providers?: Providers; -} -interface Channels { - email?: Email; - in_app?: InApp; - mobile_push?: MobilePush; - slack?: Slack; - sms?: Sms; - web_push?: WebPush; -} -interface Email { - action_url?: string; - content?: string; - title?: string; -} -interface InApp { - action_url?: string; - content?: string; - title?: string; -} -interface MobilePush { - action_url?: string; - content?: string; - title?: string; -} -interface Slack { - action_url?: string; - content?: string; - title?: string; -} -interface Sms { - action_url?: string; - content?: string; - title?: string; -} -interface WebPush { - action_url?: string; - content?: string; - title?: string; -} -interface Providers { - amazon_ses?: AmazonSes; - android?: Android; - ios?: Ios; - mailgun?: Mailgun; - postmark?: Postmark; - sendgrid?: Sendgrid; - slack?: Slack1; -} -interface AmazonSes { - [k: string]: unknown; -} -interface Android { - [k: string]: unknown; -} -interface Ios { - [k: string]: unknown; -} -interface Mailgun { - [k: string]: unknown; -} -interface Postmark { - [k: string]: unknown; -} -interface Sendgrid { - [k: string]: unknown; -} -interface Slack1 { - [k: string]: unknown; -} +import { overrides, overridesRequest, overridesResponse } from './overrides'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const broadcast = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + category: z.string().max(100).optional().nullable(), + content: z.string().max(10485760).optional().nullable(), + customAttributes: z.any().optional().nullable(), + overrides: overrides.optional().nullable(), + recipients: z.array(z.any()).min(1).max(1000), + title: z.string().min(1).max(255), + topic: z.string().max(100).optional().nullable(), + }); +}); + +/** + * + * @typedef {Broadcast} broadcast + * @property {string} + * @property {string} + * @property {string} + * @property {any} + * @property {Overrides} + * @property {any[]} + * @property {string} + * @property {string} + */ +export type Broadcast = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const broadcastResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + category: z.string().max(100).optional().nullable(), + content: z.string().max(10485760).optional().nullable(), + custom_attributes: z.any().optional().nullable(), + overrides: overridesResponse.optional().nullable(), + recipients: z.array(z.any()).min(1).max(1000), + title: z.string().min(1).max(255), + topic: z.string().max(100).optional().nullable(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + category: data['category'], + content: data['content'], + customAttributes: data['custom_attributes'], + overrides: data['overrides'], + recipients: data['recipients'], + title: data['title'], + topic: data['topic'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const broadcastRequest = z.lazy(() => { + return z + .object({ + actionUrl: z.string().nullish(), + category: z.string().nullish(), + content: z.string().nullish(), + customAttributes: z.any().nullish(), + overrides: overridesRequest.nullish(), + recipients: z.array(z.any()).nullish(), + title: z.string().nullish(), + topic: z.string().nullish(), + }) + .transform((data) => ({ + action_url: data['actionUrl'], + category: data['category'], + content: data['content'], + custom_attributes: data['customAttributes'], + overrides: data['overrides'], + recipients: data['recipients'], + title: data['title'], + topic: data['topic'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts b/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts deleted file mode 100644 index c2c1a69b1..000000000 --- a/packages/project-client/src/services/broadcasts/models/BroadcastListResponse.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Broadcast } from './Broadcast'; - -export interface BroadcastListResponse { - /** - * Number of the page returned. - */ - current_page: number; - /** - * Number of entities per page. - */ - per_page: number; - broadcasts: Broadcast[]; -} diff --git a/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts b/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts deleted file mode 100644 index 538414c4d..000000000 --- a/packages/project-client/src/services/broadcasts/models/CreateBroadcastRequest.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { Topic } from './Topic'; -import { User } from './User'; - -export interface CreateBroadcastRequest { - action_url?: string; - category?: string; - content?: string; - custom_attributes?: CustomAttributes; - overrides?: Overrides; - /** - * @minItems 1 - * @maxItems 1000 - */ - recipients: [Topic | User, ...(Topic | User)[]]; - title: string; - topic?: string; -} -interface CustomAttributes { - [k: string]: unknown; -} -interface Overrides { - channels?: Channels; - providers?: Providers; -} -interface Channels { - email?: Email; - in_app?: InApp; - mobile_push?: MobilePush; - slack?: Slack; - sms?: Sms; - web_push?: WebPush; -} -interface Email { - action_url?: string; - content?: string; - title?: string; -} -interface InApp { - action_url?: string; - content?: string; - title?: string; -} -interface MobilePush { - action_url?: string; - content?: string; - title?: string; -} -interface Slack { - action_url?: string; - content?: string; - title?: string; -} -interface Sms { - action_url?: string; - content?: string; - title?: string; -} -interface WebPush { - action_url?: string; - content?: string; - title?: string; -} -interface Providers { - amazon_ses?: AmazonSes; - android?: Android; - ios?: Ios; - mailgun?: Mailgun; - postmark?: Postmark; - sendgrid?: Sendgrid; - slack?: Slack1; -} -interface AmazonSes { - [k: string]: unknown; -} -interface Android { - [k: string]: unknown; -} -interface Ios { - [k: string]: unknown; -} -interface Mailgun { - [k: string]: unknown; -} -interface Postmark { - [k: string]: unknown; -} -interface Sendgrid { - [k: string]: unknown; -} -interface Slack1 { - [k: string]: unknown; -} diff --git a/packages/project-client/src/services/broadcasts/models/Topic.ts b/packages/project-client/src/services/broadcasts/models/Topic.ts deleted file mode 100644 index 9eaf96ccc..000000000 --- a/packages/project-client/src/services/broadcasts/models/Topic.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Topic { - topic: Topic1; -} -export interface Topic1 { - subscribers: boolean; -} diff --git a/packages/project-client/src/services/broadcasts/models/User.ts b/packages/project-client/src/services/broadcasts/models/User.ts deleted file mode 100644 index 71b285bd7..000000000 --- a/packages/project-client/src/services/broadcasts/models/User.ts +++ /dev/null @@ -1,66 +0,0 @@ -export type User = - | { - email: Email; - external_id?: ExternalId; - custom_attributes?: CustomAttributes; - first_name?: FirstName; - last_name?: LastName; - phone_numbers?: PhoneNumbers; - } - | { - email: Email1; - external_id?: ExternalId1; - custom_attributes?: CustomAttributes1; - first_name?: FirstName1; - last_name?: LastName1; - phone_numbers?: PhoneNumbers1; - } - | { - email?: Email2; - external_id: ExternalId2; - custom_attributes?: CustomAttributes2; - first_name?: FirstName2; - last_name?: LastName2; - phone_numbers?: PhoneNumbers2; - } - | { - email?: Email3; - external_id: ExternalId3; - custom_attributes?: CustomAttributes3; - first_name?: FirstName3; - last_name?: LastName3; - phone_numbers?: PhoneNumbers3; - }; -type Email = string; -type ExternalId = string; -type FirstName = string; -type LastName = string; -type PhoneNumbers = string[]; -type Email1 = string; -type ExternalId1 = string; -type FirstName1 = string; -type LastName1 = string; -type PhoneNumbers1 = string[]; -type Email2 = string; -type ExternalId2 = string; -type FirstName2 = string; -type LastName2 = string; -type PhoneNumbers2 = string[]; -type Email3 = string; -type ExternalId3 = string; -type FirstName3 = string; -type LastName3 = string; -type PhoneNumbers3 = string[]; - -interface CustomAttributes { - [k: string]: unknown; -} -interface CustomAttributes1 { - [k: string]: unknown; -} -interface CustomAttributes2 { - [k: string]: unknown; -} -interface CustomAttributes3 { - [k: string]: unknown; -} diff --git a/packages/project-client/src/services/broadcasts/models/broadcast-list-response.ts b/packages/project-client/src/services/broadcasts/models/broadcast-list-response.ts new file mode 100644 index 000000000..ba2b6c613 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/broadcast-list-response.ts @@ -0,0 +1,59 @@ +import { z } from 'zod'; + +import { broadcast, broadcastRequest, broadcastResponse } from './broadcast'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const broadcastListResponse = z.lazy(() => { + return z.object({ + currentPage: z.number(), + perPage: z.number(), + broadcasts: z.array(broadcast), + }); +}); + +/** + * + * @typedef {BroadcastListResponse} broadcastListResponse + * @property {number} - Number of the page returned. + * @property {number} - Number of entities per page. + * @property {Broadcast[]} + */ +export type BroadcastListResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const broadcastListResponseResponse = z.lazy(() => { + return z + .object({ + current_page: z.number(), + per_page: z.number(), + broadcasts: z.array(broadcastResponse), + }) + .transform((data) => ({ + currentPage: data['current_page'], + perPage: data['per_page'], + broadcasts: data['broadcasts'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const broadcastListResponseRequest = z.lazy(() => { + return z + .object({ + currentPage: z.number().nullish(), + perPage: z.number().nullish(), + broadcasts: z.array(broadcastRequest).nullish(), + }) + .transform((data) => ({ + current_page: data['currentPage'], + per_page: data['perPage'], + broadcasts: data['broadcasts'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/channels.ts b/packages/project-client/src/services/broadcasts/models/channels.ts new file mode 100644 index 000000000..3232af227 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/channels.ts @@ -0,0 +1,82 @@ +import { z } from 'zod'; + +import { email, emailRequest, emailResponse } from './email'; +import { inApp, inAppRequest, inAppResponse } from './in-app'; +import { mobilePush, mobilePushRequest, mobilePushResponse } from './mobile-push'; +import { slack, slackRequest, slackResponse } from './slack'; +import { sms, smsRequest, smsResponse } from './sms'; +import { webPush, webPushRequest, webPushResponse } from './web-push'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const channels = z.lazy(() => { + return z.object({ + email: email.optional(), + inApp: inApp.optional(), + mobilePush: mobilePush.optional(), + slack: slack.optional(), + sms: sms.optional(), + webPush: webPush.optional(), + }); +}); + +/** + * + * @typedef {Channels} channels + * @property {Email} + * @property {InApp} + * @property {MobilePush} + * @property {Slack} + * @property {Sms} + * @property {WebPush} + */ +export type Channels = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const channelsResponse = z.lazy(() => { + return z + .object({ + email: emailResponse.optional(), + in_app: inAppResponse.optional(), + mobile_push: mobilePushResponse.optional(), + slack: slackResponse.optional(), + sms: smsResponse.optional(), + web_push: webPushResponse.optional(), + }) + .transform((data) => ({ + email: data['email'], + inApp: data['in_app'], + mobilePush: data['mobile_push'], + slack: data['slack'], + sms: data['sms'], + webPush: data['web_push'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const channelsRequest = z.lazy(() => { + return z + .object({ + email: emailRequest.nullish(), + inApp: inAppRequest.nullish(), + mobilePush: mobilePushRequest.nullish(), + slack: slackRequest.nullish(), + sms: smsRequest.nullish(), + webPush: webPushRequest.nullish(), + }) + .transform((data) => ({ + email: data['email'], + in_app: data['inApp'], + mobile_push: data['mobilePush'], + slack: data['slack'], + sms: data['sms'], + web_push: data['webPush'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/email.ts b/packages/project-client/src/services/broadcasts/models/email.ts new file mode 100644 index 000000000..dee39063d --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/email.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const email = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {Email} email + * @property {string} + * @property {string} + * @property {string} + */ +export type Email = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const emailResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const emailRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/in-app.ts b/packages/project-client/src/services/broadcasts/models/in-app.ts new file mode 100644 index 000000000..d0b69023a --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/in-app.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const inApp = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {InApp} inApp + * @property {string} + * @property {string} + * @property {string} + */ +export type InApp = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const inAppResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const inAppRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/index.ts b/packages/project-client/src/services/broadcasts/models/index.ts new file mode 100644 index 000000000..32846bda1 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/index.ts @@ -0,0 +1,11 @@ +export type { Broadcast } from './broadcast'; +export type { BroadcastListResponse } from './broadcast-list-response'; +export type { Channels } from './channels'; +export type { Email } from './email'; +export type { InApp } from './in-app'; +export type { MobilePush } from './mobile-push'; +export type { Overrides } from './overrides'; +export type { Providers } from './providers'; +export type { Slack } from './slack'; +export type { Sms } from './sms'; +export type { WebPush } from './web-push'; diff --git a/packages/project-client/src/services/broadcasts/models/mobile-push.ts b/packages/project-client/src/services/broadcasts/models/mobile-push.ts new file mode 100644 index 000000000..237be8b19 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/mobile-push.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const mobilePush = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {MobilePush} mobilePush + * @property {string} + * @property {string} + * @property {string} + */ +export type MobilePush = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const mobilePushResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const mobilePushRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/overrides.ts b/packages/project-client/src/services/broadcasts/models/overrides.ts new file mode 100644 index 000000000..ba2a06736 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/overrides.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { channels, channelsRequest, channelsResponse } from './channels'; +import { providers, providersRequest, providersResponse } from './providers'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const overrides = z.lazy(() => { + return z.object({ + channels: channels.optional(), + providers: providers.optional(), + }); +}); + +/** + * + * @typedef {Overrides} overrides + * @property {Channels} + * @property {Providers} + */ +export type Overrides = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const overridesResponse = z.lazy(() => { + return z + .object({ + channels: channelsResponse.optional(), + providers: providersResponse.optional(), + }) + .transform((data) => ({ + channels: data['channels'], + providers: data['providers'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const overridesRequest = z.lazy(() => { + return z.object({ channels: channelsRequest.nullish(), providers: providersRequest.nullish() }).transform((data) => ({ + channels: data['channels'], + providers: data['providers'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/providers.ts b/packages/project-client/src/services/broadcasts/models/providers.ts new file mode 100644 index 000000000..6f1783604 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/providers.ts @@ -0,0 +1,81 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const providers = z.lazy(() => { + return z.object({ + amazonSes: z.any().optional(), + android: z.any().optional(), + ios: z.any().optional(), + mailgun: z.any().optional(), + postmark: z.any().optional(), + sendgrid: z.any().optional(), + slack: z.any().optional(), + }); +}); + +/** + * + * @typedef {Providers} providers + * @property {any} + * @property {any} + * @property {any} + * @property {any} + * @property {any} + * @property {any} + * @property {any} + */ +export type Providers = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const providersResponse = z.lazy(() => { + return z + .object({ + amazon_ses: z.any().optional(), + android: z.any().optional(), + ios: z.any().optional(), + mailgun: z.any().optional(), + postmark: z.any().optional(), + sendgrid: z.any().optional(), + slack: z.any().optional(), + }) + .transform((data) => ({ + amazonSes: data['amazon_ses'], + android: data['android'], + ios: data['ios'], + mailgun: data['mailgun'], + postmark: data['postmark'], + sendgrid: data['sendgrid'], + slack: data['slack'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const providersRequest = z.lazy(() => { + return z + .object({ + amazonSes: z.any().nullish(), + android: z.any().nullish(), + ios: z.any().nullish(), + mailgun: z.any().nullish(), + postmark: z.any().nullish(), + sendgrid: z.any().nullish(), + slack: z.any().nullish(), + }) + .transform((data) => ({ + amazon_ses: data['amazonSes'], + android: data['android'], + ios: data['ios'], + mailgun: data['mailgun'], + postmark: data['postmark'], + sendgrid: data['sendgrid'], + slack: data['slack'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/slack.ts b/packages/project-client/src/services/broadcasts/models/slack.ts new file mode 100644 index 000000000..f4e955853 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/slack.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slack = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {Slack} slack + * @property {string} + * @property {string} + * @property {string} + */ +export type Slack = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/sms.ts b/packages/project-client/src/services/broadcasts/models/sms.ts new file mode 100644 index 000000000..b997b876a --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/sms.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const sms = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {Sms} sms + * @property {string} + * @property {string} + * @property {string} + */ +export type Sms = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const smsResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const smsRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/broadcasts/models/web-push.ts b/packages/project-client/src/services/broadcasts/models/web-push.ts new file mode 100644 index 000000000..7cf79a951 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/models/web-push.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPush = z.lazy(() => { + return z.object({ + actionUrl: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }); +}); + +/** + * + * @typedef {WebPush} webPush + * @property {string} + * @property {string} + * @property {string} + */ +export type WebPush = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushResponse = z.lazy(() => { + return z + .object({ + action_url: z.string().max(2048).optional().nullable(), + content: z.string().max(1048576).optional(), + title: z.string().min(1).max(255).optional(), + }) + .transform((data) => ({ + actionUrl: data['action_url'], + content: data['content'], + title: data['title'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushRequest = z.lazy(() => { + return z + .object({ actionUrl: z.string().nullish(), content: z.string().nullish(), title: z.string().nullish() }) + .transform((data) => ({ + action_url: data['actionUrl'], + content: data['content'], + title: data['title'], + })); +}); diff --git a/packages/project-client/src/services/channels/Channels.ts b/packages/project-client/src/services/channels/Channels.ts index 34657a33d..4868bef4c 100644 --- a/packages/project-client/src/services/channels/Channels.ts +++ b/packages/project-client/src/services/channels/Channels.ts @@ -1,310 +1,632 @@ -import BaseService from '../../BaseService'; -import { serializePath } from '../../http/QuerySerializer'; -import { ApnsTokenWithMetadata } from './models/ApnsTokenWithMetadata'; -import { ArrayWithMetadataOfApnsToken } from './models/ArrayWithMetadataOfApnsToken'; -import { ArrayWithMetadataOfFcmToken } from './models/ArrayWithMetadataOfFcmToken'; -import { ArrayWithMetadataOfSlackToken } from './models/ArrayWithMetadataOfSlackToken'; -import { ArrayWithMetadataOfTeamsToken } from './models/ArrayWithMetadataOfTeamsToken'; -import { ArrayWithMetadataOfWebPushToken } from './models/ArrayWithMetadataOfWebPushToken'; -import { DiscardResult } from './models/DiscardResult'; -import { FcmTokenWithMetadata } from './models/FcmTokenWithMetadata'; -import { SlackTokenWithMetadata } from './models/SlackTokenWithMetadata'; -import { TeamsTokenWithMetadata } from './models/TeamsTokenWithMetadata'; -import { WebPushTokenWithMetadata } from './models/WebPushTokenWithMetadata'; +import { z } from 'zod'; + +import { RequestBuilder } from '../../http/transport/request-builder'; +import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; +import { BaseService } from '../base-service'; +import { ApnsTokenWithMetadata, apnsTokenWithMetadataResponse } from './models/apns-token-with-metadata'; +import { + ArrayWithMetadataOfApnsToken, + arrayWithMetadataOfApnsTokenResponse, +} from './models/array-with-metadata-of-apns-token'; +import { + ArrayWithMetadataOfFcmToken, + arrayWithMetadataOfFcmTokenResponse, +} from './models/array-with-metadata-of-fcm-token'; +import { + ArrayWithMetadataOfInboxToken, + arrayWithMetadataOfInboxTokenResponse, +} from './models/array-with-metadata-of-inbox-token'; +import { + ArrayWithMetadataOfSlackToken, + arrayWithMetadataOfSlackTokenResponse, +} from './models/array-with-metadata-of-slack-token'; +import { + ArrayWithMetadataOfTeamsToken, + arrayWithMetadataOfTeamsTokenResponse, +} from './models/array-with-metadata-of-teams-token'; +import { + ArrayWithMetadataOfWebPushToken, + arrayWithMetadataOfWebPushTokenResponse, +} from './models/array-with-metadata-of-web-push-token'; +import { DiscardResult, discardResultResponse } from './models/discard-result'; +import { FcmTokenWithMetadata, fcmTokenWithMetadataResponse } from './models/fcm-token-with-metadata'; +import { InboxTokenWithMetadata, inboxTokenWithMetadataResponse } from './models/inbox-token-with-metadata'; +import { SlackTokenWithMetadata, slackTokenWithMetadataResponse } from './models/slack-token-with-metadata'; +import { TeamsTokenWithMetadata, teamsTokenWithMetadataResponse } from './models/teams-token-with-metadata'; +import { WebPushTokenWithMetadata, webPushTokenWithMetadataResponse } from './models/web-push-token-with-metadata'; export class ChannelsService extends BaseService { - async getMobilePushApnsUserTokens(userId: string): Promise { - if (userId === undefined) { - throw new Error('The following parameter is required: userId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ArrayWithMetadataOfApnsToken; - return responseModel; + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getInAppUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/in_app/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfInboxTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getInAppUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/in_app/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(inboxTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardInAppUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/in_app/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getMobilePushApnsUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/mobile_push/apns/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfApnsTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); } - async getMobilePushApnsUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ApnsTokenWithMetadata; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getMobilePushApnsUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(apnsTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async discardMobilePushApnsUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as DiscardResult; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardMobilePushApnsUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/mobile_push/apns/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async getMobilePushFcmUserTokens(userId: string): Promise { - if (userId === undefined) { - throw new Error('The following parameter is required: userId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ArrayWithMetadataOfFcmToken; - return responseModel; + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getMobilePushFcmUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfFcmTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); } - async getMobilePushFcmUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as FcmTokenWithMetadata; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getMobilePushFcmUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(fcmTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async discardMobilePushFcmUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as DiscardResult; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardMobilePushFcmUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/mobile_push/fcm/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async getSlackUserTokens(userId: string): Promise { - if (userId === undefined) { - throw new Error('The following parameter is required: userId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/slack/tokens'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ArrayWithMetadataOfSlackToken; - return responseModel; + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getSlackUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/slack/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfSlackTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); } - async getSlackUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/slack/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as SlackTokenWithMetadata; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getSlackUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/slack/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(slackTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async discardSlackUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/slack/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as DiscardResult; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardSlackUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/slack/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async getTeamsUserTokens(userId: string): Promise { - if (userId === undefined) { - throw new Error('The following parameter is required: userId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/teams/tokens'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ArrayWithMetadataOfTeamsToken; - return responseModel; + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getTeamsUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/teams/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfTeamsTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); } - async getTeamsUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/teams/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as TeamsTokenWithMetadata; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getTeamsUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/teams/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(teamsTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async discardTeamsUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/teams/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as DiscardResult; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardTeamsUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/teams/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async getWebPushUserTokens(userId: string): Promise { - if (userId === undefined) { - throw new Error('The following parameter is required: userId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/web_push/tokens'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ArrayWithMetadataOfWebPushToken; - return responseModel; + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async getWebPushUserTokens( + userId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/web_push/tokens') + .setRequestSchema(z.any()) + .setResponseSchema(arrayWithMetadataOfWebPushTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); } - async getWebPushUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/web_push/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as WebPushTokenWithMetadata; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async getWebPushUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/users/{user_id}/channels/web_push/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(webPushTokenWithMetadataResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } - async discardWebPushUserToken(userId: string, tokenId: string): Promise { - if (userId === undefined || tokenId === undefined) { - throw new Error('The following are required parameters: userId,tokenId, cannot be empty or blank'); - } - let urlEndpoint = '/users/{user_id}/channels/web_push/tokens/{token_id}'; - urlEndpoint = urlEndpoint.replace('{user_id}', serializePath('simple', false, userId, undefined)); - urlEndpoint = urlEndpoint.replace('{token_id}', serializePath('simple', false, tokenId, undefined)); - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as DiscardResult; - return responseModel; + /** + * + * @param {string} userId - + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardWebPushUserToken( + userId: string, + tokenId: string, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/users/{user_id}/channels/web_push/tokens/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardResultResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); } } diff --git a/packages/project-client/src/services/channels/index.ts b/packages/project-client/src/services/channels/index.ts index a80fbbc2f..c98715cb2 100644 --- a/packages/project-client/src/services/channels/index.ts +++ b/packages/project-client/src/services/channels/index.ts @@ -1,11 +1,2 @@ -export type { ApnsTokenWithMetadata } from './models/ApnsTokenWithMetadata'; -export type { ArrayWithMetadataOfApnsToken } from './models/ArrayWithMetadataOfApnsToken'; -export type { ArrayWithMetadataOfFcmToken } from './models/ArrayWithMetadataOfFcmToken'; -export type { ArrayWithMetadataOfSlackToken } from './models/ArrayWithMetadataOfSlackToken'; -export type { ArrayWithMetadataOfTeamsToken } from './models/ArrayWithMetadataOfTeamsToken'; -export type { ArrayWithMetadataOfWebPushToken } from './models/ArrayWithMetadataOfWebPushToken'; -export type { DiscardResult } from './models/DiscardResult'; -export type { FcmTokenWithMetadata } from './models/FcmTokenWithMetadata'; -export type { SlackTokenWithMetadata } from './models/SlackTokenWithMetadata'; -export type { TeamsTokenWithMetadata } from './models/TeamsTokenWithMetadata'; -export type { WebPushTokenWithMetadata } from './models/WebPushTokenWithMetadata'; +export { ChannelsService } from './channels'; +export * from './models'; diff --git a/packages/project-client/src/services/channels/models/ApnsToken.ts b/packages/project-client/src/services/channels/models/ApnsToken.ts deleted file mode 100644 index b09a7ba29..000000000 --- a/packages/project-client/src/services/channels/models/ApnsToken.ts +++ /dev/null @@ -1,6 +0,0 @@ -type InstallationId = 'development' | 'production'; - -export interface ApnsToken { - device_token: string; - installation_id?: InstallationId; -} diff --git a/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts deleted file mode 100644 index b59481de9..000000000 --- a/packages/project-client/src/services/channels/models/ApnsTokenWithMetadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ApnsToken } from './ApnsToken'; - -type Data = ApnsToken; - -export interface ApnsTokenWithMetadata { - data: Data; - metadata: Metadata; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts deleted file mode 100644 index 63f550037..000000000 --- a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfApnsToken.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ApnsToken } from './ApnsToken'; - -type Data = ApnsToken; - -export interface ArrayWithMetadataOfApnsToken { - data: { - data: Data; - metadata: Metadata; - }[]; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts deleted file mode 100644 index 8645e33a2..000000000 --- a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfFcmToken.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { FcmToken } from './FcmToken'; - -type Data = FcmToken; - -export interface ArrayWithMetadataOfFcmToken { - data: { - data: Data; - metadata: Metadata; - }[]; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts deleted file mode 100644 index 8392dddca..000000000 --- a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfSlackToken.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { SlackToken } from './SlackToken'; - -type Data = SlackToken; - -export interface ArrayWithMetadataOfSlackToken { - data: { - data: Data; - metadata: Metadata; - }[]; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts deleted file mode 100644 index 3b6d2b5df..000000000 --- a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfTeamsToken.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { TeamsToken } from './TeamsToken'; - -type Data = TeamsToken; - -export interface ArrayWithMetadataOfTeamsToken { - data: { - data: Data; - metadata: Metadata; - }[]; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts b/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts deleted file mode 100644 index fa68aa35d..000000000 --- a/packages/project-client/src/services/channels/models/ArrayWithMetadataOfWebPushToken.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { WebPushToken } from './WebPushToken'; - -type Data = WebPushToken; - -export interface ArrayWithMetadataOfWebPushToken { - data: { - data: Data; - metadata: Metadata; - }[]; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/DiscardResult.ts b/packages/project-client/src/services/channels/models/DiscardResult.ts deleted file mode 100644 index 77643bc61..000000000 --- a/packages/project-client/src/services/channels/models/DiscardResult.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface DiscardResult { - discarded_at?: string; - id?: string; -} diff --git a/packages/project-client/src/services/channels/models/FcmToken.ts b/packages/project-client/src/services/channels/models/FcmToken.ts deleted file mode 100644 index 7043fee31..000000000 --- a/packages/project-client/src/services/channels/models/FcmToken.ts +++ /dev/null @@ -1,6 +0,0 @@ -type InstallationId = 'development' | 'production'; - -export interface FcmToken { - device_token: string; - installation_id?: InstallationId; -} diff --git a/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts deleted file mode 100644 index 46925b058..000000000 --- a/packages/project-client/src/services/channels/models/FcmTokenWithMetadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { FcmToken } from './FcmToken'; - -type Data = FcmToken; - -export interface FcmTokenWithMetadata { - data: Data; - metadata: Metadata; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/SlackToken.ts b/packages/project-client/src/services/channels/models/SlackToken.ts deleted file mode 100644 index 46db8652d..000000000 --- a/packages/project-client/src/services/channels/models/SlackToken.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface SlackToken { - oauth?: Oauth; - webhook?: Webhook; -} -interface Oauth { - channel_id: string; - installation_id: string; - scope?: string; -} -interface Webhook { - url: string; -} diff --git a/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts deleted file mode 100644 index 47f9edd8f..000000000 --- a/packages/project-client/src/services/channels/models/SlackTokenWithMetadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { SlackToken } from './SlackToken'; - -type Data = SlackToken; - -export interface SlackTokenWithMetadata { - data: Data; - metadata: Metadata; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/TeamsToken.ts b/packages/project-client/src/services/channels/models/TeamsToken.ts deleted file mode 100644 index 207768b58..000000000 --- a/packages/project-client/src/services/channels/models/TeamsToken.ts +++ /dev/null @@ -1 +0,0 @@ -export interface TeamsToken {} diff --git a/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts deleted file mode 100644 index 04e418ca5..000000000 --- a/packages/project-client/src/services/channels/models/TeamsTokenWithMetadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { TeamsToken } from './TeamsToken'; - -type Data = TeamsToken; - -export interface TeamsTokenWithMetadata { - data: Data; - metadata: Metadata; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/WebPushToken.ts b/packages/project-client/src/services/channels/models/WebPushToken.ts deleted file mode 100644 index a69af1965..000000000 --- a/packages/project-client/src/services/channels/models/WebPushToken.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface WebPushToken { - endpoint: string; - keys: Keys; -} -interface Keys { - auth: string; - p256dh: string; -} diff --git a/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts b/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts deleted file mode 100644 index 1d26abff7..000000000 --- a/packages/project-client/src/services/channels/models/WebPushTokenWithMetadata.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { WebPushToken } from './WebPushToken'; - -type Data = WebPushToken; - -export interface WebPushTokenWithMetadata { - data: Data; - metadata: Metadata; -} -interface Metadata { - created_at: string; - discarded_at?: string; - id: string; - updated_at?: string; -} diff --git a/packages/project-client/src/services/channels/models/apns-token-installation-id.ts b/packages/project-client/src/services/channels/models/apns-token-installation-id.ts new file mode 100644 index 000000000..2e2f4bc08 --- /dev/null +++ b/packages/project-client/src/services/channels/models/apns-token-installation-id.ts @@ -0,0 +1,4 @@ +export enum ApnsTokenInstallationId { + DEVELOPMENT = 'development', + PRODUCTION = 'production', +} diff --git a/packages/project-client/src/services/channels/models/apns-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/apns-token-with-metadata-metadata.ts new file mode 100644 index 000000000..4589d744a --- /dev/null +++ b/packages/project-client/src/services/channels/models/apns-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const apnsTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {ApnsTokenWithMetadataMetadata} apnsTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type ApnsTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/apns-token-with-metadata.ts b/packages/project-client/src/services/channels/models/apns-token-with-metadata.ts new file mode 100644 index 000000000..321a0e4c9 --- /dev/null +++ b/packages/project-client/src/services/channels/models/apns-token-with-metadata.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; + +import { apnsToken, apnsTokenRequest, apnsTokenResponse } from './apns-token'; +import { + apnsTokenWithMetadataMetadata, + apnsTokenWithMetadataMetadataRequest, + apnsTokenWithMetadataMetadataResponse, +} from './apns-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const apnsTokenWithMetadata = z.lazy(() => { + return z.object({ + data: apnsToken, + metadata: apnsTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {ApnsTokenWithMetadata} apnsTokenWithMetadata + * @property {ApnsToken} + * @property {ApnsTokenWithMetadataMetadata} + */ +export type ApnsTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: apnsTokenResponse, + metadata: apnsTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: apnsTokenRequest.nullish(), metadata: apnsTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/apns-token.ts b/packages/project-client/src/services/channels/models/apns-token.ts new file mode 100644 index 000000000..ce41d600f --- /dev/null +++ b/packages/project-client/src/services/channels/models/apns-token.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const apnsToken = z.lazy(() => { + return z.object({ + deviceToken: z.string().min(64), + installationId: z.string().optional(), + }); +}); + +/** + * + * @typedef {ApnsToken} apnsToken + * @property {string} + * @property {ApnsTokenInstallationId} + */ +export type ApnsToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenResponse = z.lazy(() => { + return z + .object({ + device_token: z.string().min(64), + installation_id: z.string().optional(), + }) + .transform((data) => ({ + deviceToken: data['device_token'], + installationId: data['installation_id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const apnsTokenRequest = z.lazy(() => { + return z.object({ deviceToken: z.string().nullish(), installationId: z.string().nullish() }).transform((data) => ({ + device_token: data['deviceToken'], + installation_id: data['installationId'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token-data.ts new file mode 100644 index 000000000..bdbed0503 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token-data.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { apnsToken, apnsTokenRequest, apnsTokenResponse } from './apns-token'; +import { dataMetadata2, dataMetadata2Request, dataMetadata2Response } from './data-metadata-2'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfApnsTokenData = z.lazy(() => { + return z.object({ + data: apnsToken, + metadata: dataMetadata2, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfApnsTokenData} arrayWithMetadataOfApnsTokenData + * @property {ApnsToken} + * @property {DataMetadata2} + */ +export type ArrayWithMetadataOfApnsTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfApnsTokenDataResponse = z.lazy(() => { + return z + .object({ + data: apnsTokenResponse, + metadata: dataMetadata2Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfApnsTokenDataRequest = z.lazy(() => { + return z.object({ data: apnsTokenRequest.nullish(), metadata: dataMetadata2Request.nullish() }).transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token.ts new file mode 100644 index 000000000..1007933b6 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-apns-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfApnsTokenData, + arrayWithMetadataOfApnsTokenDataRequest, + arrayWithMetadataOfApnsTokenDataResponse, +} from './array-with-metadata-of-apns-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfApnsToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfApnsTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfApnsToken} arrayWithMetadataOfApnsToken + * @property {ArrayWithMetadataOfApnsTokenData[]} + */ +export type ArrayWithMetadataOfApnsToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfApnsTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfApnsTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfApnsTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfApnsTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token-data.ts new file mode 100644 index 000000000..0af8d31e5 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token-data.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { dataMetadata3, dataMetadata3Request, dataMetadata3Response } from './data-metadata-3'; +import { fcmToken, fcmTokenRequest, fcmTokenResponse } from './fcm-token'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfFcmTokenData = z.lazy(() => { + return z.object({ + data: fcmToken, + metadata: dataMetadata3, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfFcmTokenData} arrayWithMetadataOfFcmTokenData + * @property {FcmToken} + * @property {DataMetadata3} + */ +export type ArrayWithMetadataOfFcmTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfFcmTokenDataResponse = z.lazy(() => { + return z + .object({ + data: fcmTokenResponse, + metadata: dataMetadata3Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfFcmTokenDataRequest = z.lazy(() => { + return z.object({ data: fcmTokenRequest.nullish(), metadata: dataMetadata3Request.nullish() }).transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token.ts new file mode 100644 index 000000000..a39c8c029 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-fcm-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfFcmTokenData, + arrayWithMetadataOfFcmTokenDataRequest, + arrayWithMetadataOfFcmTokenDataResponse, +} from './array-with-metadata-of-fcm-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfFcmToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfFcmTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfFcmToken} arrayWithMetadataOfFcmToken + * @property {ArrayWithMetadataOfFcmTokenData[]} + */ +export type ArrayWithMetadataOfFcmToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfFcmTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfFcmTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfFcmTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfFcmTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token-data.ts new file mode 100644 index 000000000..0ab60fe7a --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token-data.ts @@ -0,0 +1,51 @@ +import { z } from 'zod'; + +import { dataMetadata4, dataMetadata4Request, dataMetadata4Response } from './data-metadata-4'; +import { slackToken, slackTokenRequest, slackTokenResponse } from './slack-token'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfSlackTokenData = z.lazy(() => { + return z.object({ + data: slackToken, + metadata: dataMetadata4, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfSlackTokenData} arrayWithMetadataOfSlackTokenData + * @property {SlackToken} + * @property {DataMetadata4} + */ +export type ArrayWithMetadataOfSlackTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfSlackTokenDataResponse = z.lazy(() => { + return z + .object({ + data: slackTokenResponse, + metadata: dataMetadata4Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfSlackTokenDataRequest = z.lazy(() => { + return z + .object({ data: slackTokenRequest.nullish(), metadata: dataMetadata4Request.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token.ts new file mode 100644 index 000000000..3fcd51ec0 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-slack-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfSlackTokenData, + arrayWithMetadataOfSlackTokenDataRequest, + arrayWithMetadataOfSlackTokenDataResponse, +} from './array-with-metadata-of-slack-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfSlackToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfSlackTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfSlackToken} arrayWithMetadataOfSlackToken + * @property {ArrayWithMetadataOfSlackTokenData[]} + */ +export type ArrayWithMetadataOfSlackToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfSlackTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfSlackTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfSlackTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfSlackTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token-data.ts new file mode 100644 index 000000000..db76fcf16 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token-data.ts @@ -0,0 +1,48 @@ +import { z } from 'zod'; + +import { dataMetadata5, dataMetadata5Request, dataMetadata5Response } from './data-metadata-5'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfTeamsTokenData = z.lazy(() => { + return z.object({ + data: z.any(), + metadata: dataMetadata5, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfTeamsTokenData} arrayWithMetadataOfTeamsTokenData + * @property {any} + * @property {DataMetadata5} + */ +export type ArrayWithMetadataOfTeamsTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfTeamsTokenDataResponse = z.lazy(() => { + return z + .object({ + data: z.any(), + metadata: dataMetadata5Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfTeamsTokenDataRequest = z.lazy(() => { + return z.object({ data: z.any().nullish(), metadata: dataMetadata5Request.nullish() }).transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token.ts new file mode 100644 index 000000000..8bb4d30d8 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-teams-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfTeamsTokenData, + arrayWithMetadataOfTeamsTokenDataRequest, + arrayWithMetadataOfTeamsTokenDataResponse, +} from './array-with-metadata-of-teams-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfTeamsToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfTeamsTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfTeamsToken} arrayWithMetadataOfTeamsToken + * @property {ArrayWithMetadataOfTeamsTokenData[]} + */ +export type ArrayWithMetadataOfTeamsToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfTeamsTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfTeamsTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfTeamsTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfTeamsTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token-data.ts new file mode 100644 index 000000000..9095a04ac --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token-data.ts @@ -0,0 +1,51 @@ +import { z } from 'zod'; + +import { dataMetadata6, dataMetadata6Request, dataMetadata6Response } from './data-metadata-6'; +import { webPushToken, webPushTokenRequest, webPushTokenResponse } from './web-push-token'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfWebPushTokenData = z.lazy(() => { + return z.object({ + data: webPushToken, + metadata: dataMetadata6, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfWebPushTokenData} arrayWithMetadataOfWebPushTokenData + * @property {WebPushToken} + * @property {DataMetadata6} + */ +export type ArrayWithMetadataOfWebPushTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfWebPushTokenDataResponse = z.lazy(() => { + return z + .object({ + data: webPushTokenResponse, + metadata: dataMetadata6Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfWebPushTokenDataRequest = z.lazy(() => { + return z + .object({ data: webPushTokenRequest.nullish(), metadata: dataMetadata6Request.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token.ts new file mode 100644 index 000000000..d4df1ad02 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-web-push-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfWebPushTokenData, + arrayWithMetadataOfWebPushTokenDataRequest, + arrayWithMetadataOfWebPushTokenDataResponse, +} from './array-with-metadata-of-web-push-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfWebPushToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfWebPushTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfWebPushToken} arrayWithMetadataOfWebPushToken + * @property {ArrayWithMetadataOfWebPushTokenData[]} + */ +export type ArrayWithMetadataOfWebPushToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfWebPushTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfWebPushTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfWebPushTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfWebPushTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-1.ts b/packages/project-client/src/services/channels/models/data-metadata-1.ts new file mode 100644 index 000000000..732f8247f --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-1.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata1 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata1} dataMetadata1 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata1 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata1Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata1Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-2.ts b/packages/project-client/src/services/channels/models/data-metadata-2.ts new file mode 100644 index 000000000..0ff39c53b --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-2.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata2 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata2} dataMetadata2 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata2 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata2Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata2Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-3.ts b/packages/project-client/src/services/channels/models/data-metadata-3.ts new file mode 100644 index 000000000..3be1233fd --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-3.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata3 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata3} dataMetadata3 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata3 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata3Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata3Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-4.ts b/packages/project-client/src/services/channels/models/data-metadata-4.ts new file mode 100644 index 000000000..369befbeb --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-4.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata4 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata4} dataMetadata4 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata4 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata4Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata4Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-5.ts b/packages/project-client/src/services/channels/models/data-metadata-5.ts new file mode 100644 index 000000000..e8761fa95 --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-5.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata5 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata5} dataMetadata5 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata5 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata5Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata5Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/discard-result.ts b/packages/project-client/src/services/channels/models/discard-result.ts new file mode 100644 index 000000000..ae59d4a30 --- /dev/null +++ b/packages/project-client/src/services/channels/models/discard-result.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const discardResult = z.lazy(() => { + return z.object({ + discardedAt: z.string().optional(), + id: z.string().optional(), + }); +}); + +/** + * + * @typedef {DiscardResult} discardResult + * @property {string} + * @property {string} + */ +export type DiscardResult = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const discardResultResponse = z.lazy(() => { + return z + .object({ + discarded_at: z.string().optional(), + id: z.string().optional(), + }) + .transform((data) => ({ + discardedAt: data['discarded_at'], + id: data['id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const discardResultRequest = z.lazy(() => { + return z.object({ discardedAt: z.string().nullish(), id: z.string().nullish() }).transform((data) => ({ + discarded_at: data['discardedAt'], + id: data['id'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/fcm-token-installation-id.ts b/packages/project-client/src/services/channels/models/fcm-token-installation-id.ts new file mode 100644 index 000000000..e1f07e230 --- /dev/null +++ b/packages/project-client/src/services/channels/models/fcm-token-installation-id.ts @@ -0,0 +1,4 @@ +export enum FcmTokenInstallationId { + DEVELOPMENT = 'development', + PRODUCTION = 'production', +} diff --git a/packages/project-client/src/services/channels/models/fcm-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/fcm-token-with-metadata-metadata.ts new file mode 100644 index 000000000..ed8f1b7c6 --- /dev/null +++ b/packages/project-client/src/services/channels/models/fcm-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {FcmTokenWithMetadataMetadata} fcmTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type FcmTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/fcm-token-with-metadata.ts b/packages/project-client/src/services/channels/models/fcm-token-with-metadata.ts new file mode 100644 index 000000000..23573fb01 --- /dev/null +++ b/packages/project-client/src/services/channels/models/fcm-token-with-metadata.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; + +import { fcmToken, fcmTokenRequest, fcmTokenResponse } from './fcm-token'; +import { + fcmTokenWithMetadataMetadata, + fcmTokenWithMetadataMetadataRequest, + fcmTokenWithMetadataMetadataResponse, +} from './fcm-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmTokenWithMetadata = z.lazy(() => { + return z.object({ + data: fcmToken, + metadata: fcmTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {FcmTokenWithMetadata} fcmTokenWithMetadata + * @property {FcmToken} + * @property {FcmTokenWithMetadataMetadata} + */ +export type FcmTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: fcmTokenResponse, + metadata: fcmTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: fcmTokenRequest.nullish(), metadata: fcmTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/fcm-token.ts b/packages/project-client/src/services/channels/models/fcm-token.ts new file mode 100644 index 000000000..8b9052d1a --- /dev/null +++ b/packages/project-client/src/services/channels/models/fcm-token.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmToken = z.lazy(() => { + return z.object({ + deviceToken: z.string().min(64), + installationId: z.string().optional(), + }); +}); + +/** + * + * @typedef {FcmToken} fcmToken + * @property {string} + * @property {FcmTokenInstallationId} + */ +export type FcmToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenResponse = z.lazy(() => { + return z + .object({ + device_token: z.string().min(64), + installation_id: z.string().optional(), + }) + .transform((data) => ({ + deviceToken: data['device_token'], + installationId: data['installation_id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmTokenRequest = z.lazy(() => { + return z.object({ deviceToken: z.string().nullish(), installationId: z.string().nullish() }).transform((data) => ({ + device_token: data['deviceToken'], + installation_id: data['installationId'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/index.ts b/packages/project-client/src/services/channels/models/index.ts new file mode 100644 index 000000000..15a326e2e --- /dev/null +++ b/packages/project-client/src/services/channels/models/index.ts @@ -0,0 +1,41 @@ +export type { ApnsToken } from './apns-token'; +export { ApnsTokenInstallationId } from './apns-token-installation-id'; +export type { ApnsTokenWithMetadata } from './apns-token-with-metadata'; +export type { ApnsTokenWithMetadataMetadata } from './apns-token-with-metadata-metadata'; +export type { ArrayWithMetadataOfApnsToken } from './array-with-metadata-of-apns-token'; +export type { ArrayWithMetadataOfApnsTokenData } from './array-with-metadata-of-apns-token-data'; +export type { ArrayWithMetadataOfFcmToken } from './array-with-metadata-of-fcm-token'; +export type { ArrayWithMetadataOfFcmTokenData } from './array-with-metadata-of-fcm-token-data'; +export type { ArrayWithMetadataOfInboxToken } from './array-with-metadata-of-inbox-token'; +export type { ArrayWithMetadataOfInboxTokenData } from './array-with-metadata-of-inbox-token-data'; +export type { ArrayWithMetadataOfSlackToken } from './array-with-metadata-of-slack-token'; +export type { ArrayWithMetadataOfSlackTokenData } from './array-with-metadata-of-slack-token-data'; +export type { ArrayWithMetadataOfTeamsToken } from './array-with-metadata-of-teams-token'; +export type { ArrayWithMetadataOfTeamsTokenData } from './array-with-metadata-of-teams-token-data'; +export type { ArrayWithMetadataOfWebPushToken } from './array-with-metadata-of-web-push-token'; +export type { ArrayWithMetadataOfWebPushTokenData } from './array-with-metadata-of-web-push-token-data'; +export type { DataMetadata1 } from './data-metadata-1'; +export type { DataMetadata2 } from './data-metadata-2'; +export type { DataMetadata3 } from './data-metadata-3'; +export type { DataMetadata4 } from './data-metadata-4'; +export type { DataMetadata5 } from './data-metadata-5'; +export type { DataMetadata6 } from './data-metadata-6'; +export type { DiscardResult } from './discard-result'; +export type { FcmToken } from './fcm-token'; +export { FcmTokenInstallationId } from './fcm-token-installation-id'; +export type { FcmTokenWithMetadata } from './fcm-token-with-metadata'; +export type { FcmTokenWithMetadataMetadata } from './fcm-token-with-metadata-metadata'; +export type { InboxToken } from './inbox-token'; +export type { InboxTokenWithMetadata } from './inbox-token-with-metadata'; +export type { InboxTokenWithMetadataMetadata } from './inbox-token-with-metadata-metadata'; +export type { Keys } from './keys'; +export type { Oauth } from './oauth'; +export type { SlackToken } from './slack-token'; +export type { SlackTokenWithMetadata } from './slack-token-with-metadata'; +export type { SlackTokenWithMetadataMetadata } from './slack-token-with-metadata-metadata'; +export type { TeamsTokenWithMetadata } from './teams-token-with-metadata'; +export type { TeamsTokenWithMetadataMetadata } from './teams-token-with-metadata-metadata'; +export type { WebPushToken } from './web-push-token'; +export type { WebPushTokenWithMetadata } from './web-push-token-with-metadata'; +export type { WebPushTokenWithMetadataMetadata } from './web-push-token-with-metadata-metadata'; +export type { Webhook } from './webhook'; diff --git a/packages/project-client/src/services/channels/models/keys.ts b/packages/project-client/src/services/channels/models/keys.ts new file mode 100644 index 000000000..3c59e4017 --- /dev/null +++ b/packages/project-client/src/services/channels/models/keys.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const keys = z.lazy(() => { + return z.object({ + auth: z.string(), + p256dh: z.string(), + }); +}); + +/** + * + * @typedef {Keys} keys + * @property {string} + * @property {string} + */ +export type Keys = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const keysResponse = z.lazy(() => { + return z + .object({ + auth: z.string(), + p256dh: z.string(), + }) + .transform((data) => ({ + auth: data['auth'], + p256dh: data['p256dh'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const keysRequest = z.lazy(() => { + return z.object({ auth: z.string().nullish(), p256dh: z.string().nullish() }).transform((data) => ({ + auth: data['auth'], + p256dh: data['p256dh'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/oauth.ts b/packages/project-client/src/services/channels/models/oauth.ts new file mode 100644 index 000000000..e5802f93b --- /dev/null +++ b/packages/project-client/src/services/channels/models/oauth.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const oauth = z.lazy(() => { + return z.object({ + channelId: z.string(), + installationId: z.string(), + scope: z.string().optional(), + }); +}); + +/** + * + * @typedef {Oauth} oauth + * @property {string} + * @property {string} + * @property {string} + */ +export type Oauth = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const oauthResponse = z.lazy(() => { + return z + .object({ + channel_id: z.string(), + installation_id: z.string(), + scope: z.string().optional(), + }) + .transform((data) => ({ + channelId: data['channel_id'], + installationId: data['installation_id'], + scope: data['scope'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const oauthRequest = z.lazy(() => { + return z + .object({ channelId: z.string().nullish(), installationId: z.string().nullish(), scope: z.string().nullish() }) + .transform((data) => ({ + channel_id: data['channelId'], + installation_id: data['installationId'], + scope: data['scope'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/slack-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/slack-token-with-metadata-metadata.ts new file mode 100644 index 000000000..3e82d9b20 --- /dev/null +++ b/packages/project-client/src/services/channels/models/slack-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {SlackTokenWithMetadataMetadata} slackTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type SlackTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/slack-token-with-metadata.ts b/packages/project-client/src/services/channels/models/slack-token-with-metadata.ts new file mode 100644 index 000000000..2afc50fe1 --- /dev/null +++ b/packages/project-client/src/services/channels/models/slack-token-with-metadata.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; + +import { slackToken, slackTokenRequest, slackTokenResponse } from './slack-token'; +import { + slackTokenWithMetadataMetadata, + slackTokenWithMetadataMetadataRequest, + slackTokenWithMetadataMetadataResponse, +} from './slack-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackTokenWithMetadata = z.lazy(() => { + return z.object({ + data: slackToken, + metadata: slackTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {SlackTokenWithMetadata} slackTokenWithMetadata + * @property {SlackToken} + * @property {SlackTokenWithMetadataMetadata} + */ +export type SlackTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: slackTokenResponse, + metadata: slackTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: slackTokenRequest.nullish(), metadata: slackTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/slack-token.ts b/packages/project-client/src/services/channels/models/slack-token.ts new file mode 100644 index 000000000..c8087f811 --- /dev/null +++ b/packages/project-client/src/services/channels/models/slack-token.ts @@ -0,0 +1,49 @@ +import { z } from 'zod'; + +import { oauth, oauthRequest, oauthResponse } from './oauth'; +import { webhook, webhookRequest, webhookResponse } from './webhook'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackToken = z.lazy(() => { + return z.object({ + oauth: oauth.optional(), + webhook: webhook.optional(), + }); +}); + +/** + * + * @typedef {SlackToken} slackToken + * @property {Oauth} + * @property {Webhook} + */ +export type SlackToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenResponse = z.lazy(() => { + return z + .object({ + oauth: oauthResponse.optional(), + webhook: webhookResponse.optional(), + }) + .transform((data) => ({ + oauth: data['oauth'], + webhook: data['webhook'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackTokenRequest = z.lazy(() => { + return z.object({ oauth: oauthRequest.nullish(), webhook: webhookRequest.nullish() }).transform((data) => ({ + oauth: data['oauth'], + webhook: data['webhook'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/teams-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/teams-token-with-metadata-metadata.ts new file mode 100644 index 000000000..8a5e8a0b2 --- /dev/null +++ b/packages/project-client/src/services/channels/models/teams-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const teamsTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {TeamsTokenWithMetadataMetadata} teamsTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type TeamsTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/teams-token-with-metadata.ts b/packages/project-client/src/services/channels/models/teams-token-with-metadata.ts new file mode 100644 index 000000000..d64c03b65 --- /dev/null +++ b/packages/project-client/src/services/channels/models/teams-token-with-metadata.ts @@ -0,0 +1,54 @@ +import { z } from 'zod'; + +import { + teamsTokenWithMetadataMetadata, + teamsTokenWithMetadataMetadataRequest, + teamsTokenWithMetadataMetadataResponse, +} from './teams-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const teamsTokenWithMetadata = z.lazy(() => { + return z.object({ + data: z.any(), + metadata: teamsTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {TeamsTokenWithMetadata} teamsTokenWithMetadata + * @property {any} + * @property {TeamsTokenWithMetadataMetadata} + */ +export type TeamsTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: z.any(), + metadata: teamsTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const teamsTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: z.any().nullish(), metadata: teamsTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/web-push-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/web-push-token-with-metadata-metadata.ts new file mode 100644 index 000000000..9d3dd1698 --- /dev/null +++ b/packages/project-client/src/services/channels/models/web-push-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {WebPushTokenWithMetadataMetadata} webPushTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type WebPushTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/web-push-token-with-metadata.ts b/packages/project-client/src/services/channels/models/web-push-token-with-metadata.ts new file mode 100644 index 000000000..3a774fb10 --- /dev/null +++ b/packages/project-client/src/services/channels/models/web-push-token-with-metadata.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; + +import { webPushToken, webPushTokenRequest, webPushTokenResponse } from './web-push-token'; +import { + webPushTokenWithMetadataMetadata, + webPushTokenWithMetadataMetadataRequest, + webPushTokenWithMetadataMetadataResponse, +} from './web-push-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushTokenWithMetadata = z.lazy(() => { + return z.object({ + data: webPushToken, + metadata: webPushTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {WebPushTokenWithMetadata} webPushTokenWithMetadata + * @property {WebPushToken} + * @property {WebPushTokenWithMetadataMetadata} + */ +export type WebPushTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: webPushTokenResponse, + metadata: webPushTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: webPushTokenRequest.nullish(), metadata: webPushTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/web-push-token.ts b/packages/project-client/src/services/channels/models/web-push-token.ts new file mode 100644 index 000000000..03bb666e6 --- /dev/null +++ b/packages/project-client/src/services/channels/models/web-push-token.ts @@ -0,0 +1,48 @@ +import { z } from 'zod'; + +import { keys, keysRequest, keysResponse } from './keys'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webPushToken = z.lazy(() => { + return z.object({ + endpoint: z.string(), + keys: keys, + }); +}); + +/** + * + * @typedef {WebPushToken} webPushToken + * @property {string} + * @property {Keys} + */ +export type WebPushToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenResponse = z.lazy(() => { + return z + .object({ + endpoint: z.string(), + keys: keysResponse, + }) + .transform((data) => ({ + endpoint: data['endpoint'], + keys: data['keys'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webPushTokenRequest = z.lazy(() => { + return z.object({ endpoint: z.string().nullish(), keys: keysRequest.nullish() }).transform((data) => ({ + endpoint: data['endpoint'], + keys: data['keys'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/webhook.ts b/packages/project-client/src/services/channels/models/webhook.ts new file mode 100644 index 000000000..80d30b9ff --- /dev/null +++ b/packages/project-client/src/services/channels/models/webhook.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webhook = z.lazy(() => { + return z.object({ + url: z.string(), + }); +}); + +/** + * + * @typedef {Webhook} webhook + * @property {string} + */ +export type Webhook = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webhookResponse = z.lazy(() => { + return z + .object({ + url: z.string(), + }) + .transform((data) => ({ + url: data['url'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webhookRequest = z.lazy(() => { + return z.object({ url: z.string().nullish() }).transform((data) => ({ + url: data['url'], + })); +}); diff --git a/packages/project-client/src/services/integrations/Integrations.ts b/packages/project-client/src/services/integrations/Integrations.ts index fb3a61847..2cf114c90 100644 --- a/packages/project-client/src/services/integrations/Integrations.ts +++ b/packages/project-client/src/services/integrations/Integrations.ts @@ -1,393 +1,1233 @@ -import BaseService from '../../BaseService'; -import { ApnsConfig } from './models/ApnsConfig'; -import { FcmConfig } from './models/FcmConfig'; -import { InboxConfig } from './models/InboxConfig'; -import { ListIntegrationsResponse } from './models/ListIntegrationsResponse'; -import { MailgunConfig } from './models/MailgunConfig'; -import { PingConfig } from './models/PingConfig'; -import { SaveApnsIntegrationRequest } from './models/SaveApnsIntegrationRequest'; -import { SaveFcmIntegrationRequest } from './models/SaveFcmIntegrationRequest'; -import { SaveInboxIntegrationRequest } from './models/SaveInboxIntegrationRequest'; -import { SaveMailgunIntegrationRequest } from './models/SaveMailgunIntegrationRequest'; -import { SavePingEmailIntegrationRequest } from './models/SavePingEmailIntegrationRequest'; -import { SaveSendgridIntegrationRequest } from './models/SaveSendgridIntegrationRequest'; -import { SaveSlackIntegrationRequest } from './models/SaveSlackIntegrationRequest'; -import { SaveStripeIntegrationRequest } from './models/SaveStripeIntegrationRequest'; -import { SaveTemplatesIntegrationRequest } from './models/SaveTemplatesIntegrationRequest'; -import { SaveTemplatesIntegrationResponse } from './models/SaveTemplatesIntegrationResponse'; -import { SaveTwilioIntegrationRequest } from './models/SaveTwilioIntegrationRequest'; -import { SaveWebPushIntegrationRequest } from './models/SaveWebPushIntegrationRequest'; -import { SendgridConfig } from './models/SendgridConfig'; -import { SlackConfig } from './models/SlackConfig'; -import { StripeConfig } from './models/StripeConfig'; -import { TwilioConfig } from './models/TwilioConfig'; -import { WebpushConfig } from './models/WebpushConfig'; +import { z } from 'zod'; + +import { RequestBuilder } from '../../http/transport/request-builder'; +import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; +import { BaseService } from '../base-service'; +import { ApnsConfig, apnsConfigRequest, apnsConfigResponse } from './models/apns-config'; +import { FcmConfig, fcmConfigRequest, fcmConfigResponse } from './models/fcm-config'; +import { GithubConfig, githubConfigRequest, githubConfigResponse } from './models/github-config'; +import { InboxConfig, inboxConfigRequest, inboxConfigResponse } from './models/inbox-config'; +import { ListIntegrationsResponse, listIntegrationsResponseResponse } from './models/list-integrations-response'; +import { MailgunConfig, mailgunConfigRequest, mailgunConfigResponse } from './models/mailgun-config'; +import { PingConfig, pingConfigRequest, pingConfigResponse } from './models/ping-config'; +import { SendgridConfig, sendgridConfigRequest, sendgridConfigResponse } from './models/sendgrid-config'; +import { SesConfig, sesConfigRequest, sesConfigResponse } from './models/ses-config'; +import { SlackConfig, slackConfigRequest, slackConfigResponse } from './models/slack-config'; +import { StripeConfig, stripeConfigRequest, stripeConfigResponse } from './models/stripe-config'; +import { TwilioConfig, twilioConfigRequest, twilioConfigResponse } from './models/twilio-config'; +import { WebpushConfig, webpushConfigRequest, webpushConfigResponse } from './models/webpush-config'; export class IntegrationsService extends BaseService { - async listIntegrations(): Promise { - const urlEndpoint = '/integrations'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.get( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ListIntegrationsResponse; - return responseModel; - } - - async saveApnsIntegration(input: SaveApnsIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/apns'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as ApnsConfig; - return responseModel; - } - - async deleteApnsIntegration(): Promise { - const urlEndpoint = '/integrations/apns'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveFcmIntegration(input: SaveFcmIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/fcm'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as FcmConfig; - return responseModel; - } - - async deleteFcmIntegration(): Promise { - const urlEndpoint = '/integrations/fcm'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveInboxIntegration(input: SaveInboxIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/inbox'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as InboxConfig; - return responseModel; - } - - async deleteInboxIntegration(): Promise { - const urlEndpoint = '/integrations/inbox'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveMailgunIntegration(input: SaveMailgunIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/mailgun'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as MailgunConfig; - return responseModel; - } - - async deleteMailgunIntegration(): Promise { - const urlEndpoint = '/integrations/mailgun'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async savePingEmailIntegration(input: SavePingEmailIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/ping_email'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as PingConfig; - return responseModel; - } - - async deletePingEmailIntegration(): Promise { - const urlEndpoint = '/integrations/ping_email'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveSendgridIntegration(input: SaveSendgridIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/sendgrid'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as SendgridConfig; - return responseModel; - } - - async deleteSendgridIntegration(): Promise { - const urlEndpoint = '/integrations/sendgrid'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveSlackIntegration(input: SaveSlackIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/slack'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as SlackConfig; - return responseModel; - } - - async deleteSlackIntegration(): Promise { - const urlEndpoint = '/integrations/slack'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveStripeIntegration(input: SaveStripeIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/stripe'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as StripeConfig; - return responseModel; - } - - async deleteStripeIntegration(): Promise { - const urlEndpoint = '/integrations/stripe'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveTemplatesIntegration(input: SaveTemplatesIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/templates'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as SaveTemplatesIntegrationResponse; - return responseModel; - } - - async deleteTemplatesIntegration(): Promise { - const urlEndpoint = '/integrations/templates'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveTwilioIntegration(input: SaveTwilioIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/twilio'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as TwilioConfig; - return responseModel; - } - - async deleteTwilioIntegration(): Promise { - const urlEndpoint = '/integrations/twilio'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; - } - - async saveWebPushIntegration(input: SaveWebPushIntegrationRequest): Promise { - const headers: { [key: string]: string } = { 'Content-Type': 'application/json' }; - const urlEndpoint = '/integrations/web_push'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.put( - finalUrl, - input, - { - ...headers, - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data as WebpushConfig; - return responseModel; - } - - async deleteWebPushIntegration(): Promise { - const urlEndpoint = '/integrations/web_push'; - const finalUrl = encodeURI(`${this.baseUrl + urlEndpoint}`); - const response: any = await this.httpClient.delete( - finalUrl, - {}, - { - ...this.getAuthorizationHeader(), - }, - true, - ); - const responseModel = response.data; - return responseModel; + /** + * + * @returns {Promise>} OK + */ + async listIntegrations(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getApnsIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/apns') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveApnsIntegration(body: ApnsConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/apns') + .setRequestSchema(apnsConfigRequest) + .setResponseSchema(apnsConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteApnsIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/apns') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteApnsIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/apns/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getFcmIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/fcm') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveFcmIntegration(body: FcmConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/fcm') + .setRequestSchema(fcmConfigRequest) + .setResponseSchema(fcmConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteFcmIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/fcm') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteFcmIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/fcm/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getGithubIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/github') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveGithubIntegration(body: GithubConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/github') + .setRequestSchema(githubConfigRequest) + .setResponseSchema(githubConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteGithubIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/github') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteGithubIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/github/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getInboxIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/inbox') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveInboxIntegration(body: InboxConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/inbox') + .setRequestSchema(inboxConfigRequest) + .setResponseSchema(inboxConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteInboxIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/inbox') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteInboxIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/inbox/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getMailgunIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/mailgun') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveMailgunIntegration( + body: MailgunConfig, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/mailgun') + .setRequestSchema(mailgunConfigRequest) + .setResponseSchema(mailgunConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteMailgunIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/mailgun') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteMailgunIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/mailgun/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getPingEmailIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/ping_email') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async savePingEmailIntegration(body: PingConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/ping_email') + .setRequestSchema(pingConfigRequest) + .setResponseSchema(pingConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deletePingEmailIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/ping_email') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deletePingEmailIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/ping_email/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getSendgridIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/sendgrid') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveSendgridIntegration( + body: SendgridConfig, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/sendgrid') + .setRequestSchema(sendgridConfigRequest) + .setResponseSchema(sendgridConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteSendgridIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/sendgrid') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteSendgridIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/sendgrid/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getSesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/ses') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveSesIntegration(body: SesConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/ses') + .setRequestSchema(sesConfigRequest) + .setResponseSchema(sesConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteSesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/ses') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteSesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/ses/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getSlackIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/slack') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveSlackIntegration(body: SlackConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/slack') + .setRequestSchema(slackConfigRequest) + .setResponseSchema(slackConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteSlackIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/slack') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteSlackIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/slack/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getStripeIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/stripe') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveStripeIntegration(body: StripeConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/stripe') + .setRequestSchema(stripeConfigRequest) + .setResponseSchema(stripeConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteStripeIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/stripe') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteStripeIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/stripe/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getTemplatesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/templates') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveTemplatesIntegration(body: any, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/templates') + .setRequestSchema(z.any()) + .setResponseSchema(z.any()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteTemplatesIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/templates') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteTemplatesIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/templates/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getTwilioIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/twilio') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveTwilioIntegration(body: TwilioConfig, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/twilio') + .setRequestSchema(twilioConfigRequest) + .setResponseSchema(twilioConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteTwilioIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/twilio') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteTwilioIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/twilio/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async getWebPushIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/integrations/web_push') + .setRequestSchema(z.any()) + .setResponseSchema(listIntegrationsResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} OK + */ + async saveWebPushIntegration( + body: WebpushConfig, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('PUT') + .setPath('/integrations/web_push') + .setRequestSchema(webpushConfigRequest) + .setResponseSchema(webpushConfigResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} No Content + */ + async deleteWebPushIntegration(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/web_push') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} id - + * @returns {Promise>} No Content + */ + async deleteWebPushIntegrationById(id: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/integrations/web_push/{id}') + .setRequestSchema(z.any()) + .setResponseSchema(z.undefined()) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'id', + value: id, + }) + .build(); + return this.client.call(request); } } diff --git a/packages/project-client/src/services/integrations/index.ts b/packages/project-client/src/services/integrations/index.ts index 9afcc7794..4887df074 100644 --- a/packages/project-client/src/services/integrations/index.ts +++ b/packages/project-client/src/services/integrations/index.ts @@ -1,23 +1,2 @@ -export type { ApnsConfig } from './models/ApnsConfig'; -export type { FcmConfig } from './models/FcmConfig'; -export type { InboxConfig } from './models/InboxConfig'; -export type { ListIntegrationsResponse } from './models/ListIntegrationsResponse'; -export type { MailgunConfig } from './models/MailgunConfig'; -export type { PingConfig } from './models/PingConfig'; -export type { SaveApnsIntegrationRequest } from './models/SaveApnsIntegrationRequest'; -export type { SaveFcmIntegrationRequest } from './models/SaveFcmIntegrationRequest'; -export type { SaveInboxIntegrationRequest } from './models/SaveInboxIntegrationRequest'; -export type { SaveMailgunIntegrationRequest } from './models/SaveMailgunIntegrationRequest'; -export type { SavePingEmailIntegrationRequest } from './models/SavePingEmailIntegrationRequest'; -export type { SaveSendgridIntegrationRequest } from './models/SaveSendgridIntegrationRequest'; -export type { SaveSlackIntegrationRequest } from './models/SaveSlackIntegrationRequest'; -export type { SaveStripeIntegrationRequest } from './models/SaveStripeIntegrationRequest'; -export type { SaveTemplatesIntegrationRequest } from './models/SaveTemplatesIntegrationRequest'; -export type { SaveTemplatesIntegrationResponse } from './models/SaveTemplatesIntegrationResponse'; -export type { SaveTwilioIntegrationRequest } from './models/SaveTwilioIntegrationRequest'; -export type { SaveWebPushIntegrationRequest } from './models/SaveWebPushIntegrationRequest'; -export type { SendgridConfig } from './models/SendgridConfig'; -export type { SlackConfig } from './models/SlackConfig'; -export type { StripeConfig } from './models/StripeConfig'; -export type { TwilioConfig } from './models/TwilioConfig'; -export type { WebpushConfig } from './models/WebpushConfig'; +export { IntegrationsService } from './integrations'; +export * from './models'; diff --git a/packages/project-client/src/services/integrations/models/ApnsConfig.ts b/packages/project-client/src/services/integrations/models/ApnsConfig.ts deleted file mode 100644 index c91f8fbbf..000000000 --- a/packages/project-client/src/services/integrations/models/ApnsConfig.ts +++ /dev/null @@ -1,9 +0,0 @@ -type Badge = 'unread' | 'unseen'; - -export interface ApnsConfig { - app_id: string; - badge: Badge; - certificate: string; - key_id: string; - team_id: string; -} diff --git a/packages/project-client/src/services/integrations/models/FcmConfig.ts b/packages/project-client/src/services/integrations/models/FcmConfig.ts deleted file mode 100644 index b8788e791..000000000 --- a/packages/project-client/src/services/integrations/models/FcmConfig.ts +++ /dev/null @@ -1,15 +0,0 @@ -type Type_ = 'service_account'; - -export interface FcmConfig { - auth_provider_x509_cert_url: string; - auth_uri: string; - client_email: string; - client_id: string; - client_x509_cert_url: string; - private_key: string; - private_key_id: string; - project_id: string; - token_uri: string; - universe_domain: string; - type_: Type_; -} diff --git a/packages/project-client/src/services/integrations/models/InboxConfig.ts b/packages/project-client/src/services/integrations/models/InboxConfig.ts deleted file mode 100644 index 192605542..000000000 --- a/packages/project-client/src/services/integrations/models/InboxConfig.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface InboxConfig { - images: Images; - locale: string; - theme: Theme; -} -interface Images { - [k: string]: unknown; -} -interface Theme { - [k: string]: unknown; -} diff --git a/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts b/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts deleted file mode 100644 index 370ae587e..000000000 --- a/packages/project-client/src/services/integrations/models/ListIntegrationsResponse.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface ListIntegrationsResponse { - integrations?: { - config?: Config; - id?: string; - name?: string; - }[]; -} -interface Config { - [k: string]: unknown; -} diff --git a/packages/project-client/src/services/integrations/models/MailgunConfig.ts b/packages/project-client/src/services/integrations/models/MailgunConfig.ts deleted file mode 100644 index dd3305a60..000000000 --- a/packages/project-client/src/services/integrations/models/MailgunConfig.ts +++ /dev/null @@ -1,7 +0,0 @@ -type Region = 'us' | 'eu'; - -export interface MailgunConfig { - api_key: string; - domain: string; - region: Region; -} diff --git a/packages/project-client/src/services/integrations/models/PingConfig.ts b/packages/project-client/src/services/integrations/models/PingConfig.ts deleted file mode 100644 index 0fafbac78..000000000 --- a/packages/project-client/src/services/integrations/models/PingConfig.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface PingConfig { - /** - * URL to ping - */ - url: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts deleted file mode 100644 index 54a008917..000000000 --- a/packages/project-client/src/services/integrations/models/SaveApnsIntegrationRequest.ts +++ /dev/null @@ -1,9 +0,0 @@ -type Badge = 'unread' | 'unseen'; - -export interface SaveApnsIntegrationRequest { - app_id: string; - badge: Badge; - certificate: string; - key_id: string; - team_id: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts deleted file mode 100644 index e0152c9f0..000000000 --- a/packages/project-client/src/services/integrations/models/SaveFcmIntegrationRequest.ts +++ /dev/null @@ -1,15 +0,0 @@ -type Type_ = 'service_account'; - -export interface SaveFcmIntegrationRequest { - auth_provider_x509_cert_url: string; - auth_uri: string; - client_email: string; - client_id: string; - client_x509_cert_url: string; - private_key: string; - private_key_id: string; - project_id: string; - token_uri: string; - universe_domain: string; - type_: Type_; -} diff --git a/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts deleted file mode 100644 index da53a1fc0..000000000 --- a/packages/project-client/src/services/integrations/models/SaveInboxIntegrationRequest.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface SaveInboxIntegrationRequest { - images: Images; - locale: string; - theme: Theme; -} -interface Images { - [k: string]: unknown; -} -interface Theme { - [k: string]: unknown; -} diff --git a/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts deleted file mode 100644 index 079e72b15..000000000 --- a/packages/project-client/src/services/integrations/models/SaveMailgunIntegrationRequest.ts +++ /dev/null @@ -1,7 +0,0 @@ -type Region = 'us' | 'eu'; - -export interface SaveMailgunIntegrationRequest { - api_key: string; - domain: string; - region: Region; -} diff --git a/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts deleted file mode 100644 index 9869a5dfb..000000000 --- a/packages/project-client/src/services/integrations/models/SavePingEmailIntegrationRequest.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface SavePingEmailIntegrationRequest { - /** - * URL to ping - */ - url: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts deleted file mode 100644 index eda46ec4f..000000000 --- a/packages/project-client/src/services/integrations/models/SaveSendgridIntegrationRequest.ts +++ /dev/null @@ -1,28 +0,0 @@ -export interface SaveSendgridIntegrationRequest { - /** - * The API key for Sendgrid - */ - api_key: string; - reply_to?: ReplyTo; - from_?: From_; -} -interface ReplyTo { - /** - * The email address to reply to - */ - email: string; - /** - * The name to reply to - */ - name?: string; -} -interface From_ { - /** - * The email address to send from - */ - email: string; - /** - * The name to send from - */ - name?: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts deleted file mode 100644 index ebcfbea8a..000000000 --- a/packages/project-client/src/services/integrations/models/SaveSlackIntegrationRequest.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface SaveSlackIntegrationRequest { - app_id: string; - client_id: string; - client_secret: string; - id?: string; - signing_secret: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts deleted file mode 100644 index 477968e42..000000000 --- a/packages/project-client/src/services/integrations/models/SaveStripeIntegrationRequest.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface SaveStripeIntegrationRequest { - /** - * The signing secret to verify incoming requests from Stripe - */ - webhook_signing_secret: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts deleted file mode 100644 index eec72bdc0..000000000 --- a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationRequest.ts +++ /dev/null @@ -1 +0,0 @@ -export interface SaveTemplatesIntegrationRequest {} diff --git a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts b/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts deleted file mode 100644 index dac80797a..000000000 --- a/packages/project-client/src/services/integrations/models/SaveTemplatesIntegrationResponse.ts +++ /dev/null @@ -1 +0,0 @@ -export interface SaveTemplatesIntegrationResponse {} diff --git a/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts deleted file mode 100644 index 402b0a6cf..000000000 --- a/packages/project-client/src/services/integrations/models/SaveTwilioIntegrationRequest.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * The region to use for Twilio, defaults to 'us1' - */ -type Region = 'us1' | 'ie1' | 'au1'; - -export interface SaveTwilioIntegrationRequest { - /** - * The SID for your Twilio account - */ - account_sid: string; - /** - * The API key for Twilio - */ - api_key: string; - /** - * The API Secret for Twilio - */ - api_secret: string; - region?: Region; - /** - * The phone number to send from, in E.164 format - */ - from_: string; -} diff --git a/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts b/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts deleted file mode 100644 index 132955413..000000000 --- a/packages/project-client/src/services/integrations/models/SaveWebPushIntegrationRequest.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface SaveWebPushIntegrationRequest { - private_key: string; - public_key: string; -} diff --git a/packages/project-client/src/services/integrations/models/SendgridConfig.ts b/packages/project-client/src/services/integrations/models/SendgridConfig.ts deleted file mode 100644 index 7b575b85b..000000000 --- a/packages/project-client/src/services/integrations/models/SendgridConfig.ts +++ /dev/null @@ -1,28 +0,0 @@ -export interface SendgridConfig { - /** - * The API key for Sendgrid - */ - api_key: string; - reply_to?: ReplyTo; - from_?: From_; -} -interface ReplyTo { - /** - * The email address to reply to - */ - email: string; - /** - * The name to reply to - */ - name?: string; -} -interface From_ { - /** - * The email address to send from - */ - email: string; - /** - * The name to send from - */ - name?: string; -} diff --git a/packages/project-client/src/services/integrations/models/SlackConfig.ts b/packages/project-client/src/services/integrations/models/SlackConfig.ts deleted file mode 100644 index 1385a9746..000000000 --- a/packages/project-client/src/services/integrations/models/SlackConfig.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface SlackConfig { - app_id: string; - client_id: string; - client_secret: string; - id?: string; - signing_secret: string; -} diff --git a/packages/project-client/src/services/integrations/models/StripeConfig.ts b/packages/project-client/src/services/integrations/models/StripeConfig.ts deleted file mode 100644 index f6dc5a287..000000000 --- a/packages/project-client/src/services/integrations/models/StripeConfig.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface StripeConfig { - /** - * The signing secret to verify incoming requests from Stripe - */ - webhook_signing_secret: string; -} diff --git a/packages/project-client/src/services/integrations/models/TwilioConfig.ts b/packages/project-client/src/services/integrations/models/TwilioConfig.ts deleted file mode 100644 index e1a3d7245..000000000 --- a/packages/project-client/src/services/integrations/models/TwilioConfig.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * The region to use for Twilio, defaults to 'us1' - */ -type Region = 'us1' | 'ie1' | 'au1'; - -export interface TwilioConfig { - /** - * The SID for your Twilio account - */ - account_sid: string; - /** - * The API key for Twilio - */ - api_key: string; - /** - * The API Secret for Twilio - */ - api_secret: string; - region?: Region; - /** - * The phone number to send from, in E.164 format - */ - from_: string; -} diff --git a/packages/project-client/src/services/integrations/models/WebpushConfig.ts b/packages/project-client/src/services/integrations/models/WebpushConfig.ts deleted file mode 100644 index 8496b1167..000000000 --- a/packages/project-client/src/services/integrations/models/WebpushConfig.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface WebpushConfig { - private_key: string; - public_key: string; -} diff --git a/packages/project-client/src/services/integrations/models/apns-config.ts b/packages/project-client/src/services/integrations/models/apns-config.ts new file mode 100644 index 000000000..9d2d04b34 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/apns-config.ts @@ -0,0 +1,69 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const apnsConfig = z.lazy(() => { + return z.object({ + appId: z.string().regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/), + badge: z.string(), + certificate: z.string(), + keyId: z.string().min(10).max(10), + teamId: z.string().min(10).max(10), + }); +}); + +/** + * + * @typedef {ApnsConfig} apnsConfig + * @property {string} + * @property {Badge} + * @property {string} + * @property {string} + * @property {string} + */ +export type ApnsConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const apnsConfigResponse = z.lazy(() => { + return z + .object({ + app_id: z.string().regex(/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*$/), + badge: z.string(), + certificate: z.string(), + key_id: z.string().min(10).max(10), + team_id: z.string().min(10).max(10), + }) + .transform((data) => ({ + appId: data['app_id'], + badge: data['badge'], + certificate: data['certificate'], + keyId: data['key_id'], + teamId: data['team_id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const apnsConfigRequest = z.lazy(() => { + return z + .object({ + appId: z.string().nullish(), + badge: z.string().nullish(), + certificate: z.string().nullish(), + keyId: z.string().nullish(), + teamId: z.string().nullish(), + }) + .transform((data) => ({ + app_id: data['appId'], + badge: data['badge'], + certificate: data['certificate'], + key_id: data['keyId'], + team_id: data['teamId'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/badge.ts b/packages/project-client/src/services/integrations/models/badge.ts new file mode 100644 index 000000000..643a316f5 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/badge.ts @@ -0,0 +1,4 @@ +export enum Badge { + UNREAD = 'unread', + UNSEEN = 'unseen', +} diff --git a/packages/project-client/src/services/integrations/models/fcm-config.ts b/packages/project-client/src/services/integrations/models/fcm-config.ts new file mode 100644 index 000000000..4e978fd33 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/fcm-config.ts @@ -0,0 +1,105 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fcmConfig = z.lazy(() => { + return z.object({ + authProviderX509CertUrl: z.string(), + authUri: z.string(), + clientEmail: z.string(), + clientId: z.string(), + clientX509CertUrl: z.string(), + privateKey: z.string(), + privateKeyId: z.string(), + projectId: z.string(), + tokenUri: z.string(), + type: z.string(), + universeDomain: z.string(), + }); +}); + +/** + * + * @typedef {FcmConfig} fcmConfig + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {Type_} + * @property {string} + */ +export type FcmConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fcmConfigResponse = z.lazy(() => { + return z + .object({ + auth_provider_x509_cert_url: z.string(), + auth_uri: z.string(), + client_email: z.string(), + client_id: z.string(), + client_x509_cert_url: z.string(), + private_key: z.string(), + private_key_id: z.string(), + project_id: z.string(), + token_uri: z.string(), + type: z.string(), + universe_domain: z.string(), + }) + .transform((data) => ({ + authProviderX509CertUrl: data['auth_provider_x509_cert_url'], + authUri: data['auth_uri'], + clientEmail: data['client_email'], + clientId: data['client_id'], + clientX509CertUrl: data['client_x509_cert_url'], + privateKey: data['private_key'], + privateKeyId: data['private_key_id'], + projectId: data['project_id'], + tokenUri: data['token_uri'], + type: data['type'], + universeDomain: data['universe_domain'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fcmConfigRequest = z.lazy(() => { + return z + .object({ + authProviderX509CertUrl: z.string().nullish(), + authUri: z.string().nullish(), + clientEmail: z.string().nullish(), + clientId: z.string().nullish(), + clientX509CertUrl: z.string().nullish(), + privateKey: z.string().nullish(), + privateKeyId: z.string().nullish(), + projectId: z.string().nullish(), + tokenUri: z.string().nullish(), + type: z.string().nullish(), + universeDomain: z.string().nullish(), + }) + .transform((data) => ({ + auth_provider_x509_cert_url: data['authProviderX509CertUrl'], + auth_uri: data['authUri'], + client_email: data['clientEmail'], + client_id: data['clientId'], + client_x509_cert_url: data['clientX509CertUrl'], + private_key: data['privateKey'], + private_key_id: data['privateKeyId'], + project_id: data['projectId'], + token_uri: data['tokenUri'], + type: data['type'], + universe_domain: data['universeDomain'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/inbox-config.ts b/packages/project-client/src/services/integrations/models/inbox-config.ts new file mode 100644 index 000000000..8513a4ef9 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/inbox-config.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const inboxConfig = z.lazy(() => { + return z.object({ + images: z.any().nullable(), + locale: z.string().min(2).nullable(), + theme: z.any().nullable(), + }); +}); + +/** + * + * @typedef {InboxConfig} inboxConfig + * @property {any} + * @property {string} + * @property {any} + */ +export type InboxConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const inboxConfigResponse = z.lazy(() => { + return z + .object({ + images: z.any().nullable(), + locale: z.string().min(2).nullable(), + theme: z.any().nullable(), + }) + .transform((data) => ({ + images: data['images'], + locale: data['locale'], + theme: data['theme'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const inboxConfigRequest = z.lazy(() => { + return z + .object({ images: z.any().nullish(), locale: z.string().nullish(), theme: z.any().nullish() }) + .transform((data) => ({ + images: data['images'], + locale: data['locale'], + theme: data['theme'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/index.ts b/packages/project-client/src/services/integrations/models/index.ts new file mode 100644 index 000000000..36d6482c7 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/index.ts @@ -0,0 +1,21 @@ +export type { ApnsConfig } from './apns-config'; +export { Badge } from './badge'; +export type { FcmConfig } from './fcm-config'; +export type { GithubConfig } from './github-config'; +export type { InboxConfig } from './inbox-config'; +export type { Integrations } from './integrations'; +export type { ListIntegrationsResponse } from './list-integrations-response'; +export type { MailgunConfig } from './mailgun-config'; +export { MailgunConfigRegion } from './mailgun-config-region'; +export type { PingConfig } from './ping-config'; +export type { ReplyTo } from './reply-to'; +export type { SendgridConfig } from './sendgrid-config'; +export type { SendgridConfigFrom } from './sendgrid-config-from'; +export type { SesConfig } from './ses-config'; +export type { SesConfigFrom } from './ses-config-from'; +export type { SlackConfig } from './slack-config'; +export type { StripeConfig } from './stripe-config'; +export type { TwilioConfig } from './twilio-config'; +export { TwilioConfigRegion } from './twilio-config-region'; +export { Type_ } from './type_'; +export type { WebpushConfig } from './webpush-config'; diff --git a/packages/project-client/src/services/integrations/models/integrations.ts b/packages/project-client/src/services/integrations/models/integrations.ts new file mode 100644 index 000000000..ebef95bd8 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/integrations.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const integrations = z.lazy(() => { + return z.object({ + config: z.any().optional(), + id: z.string().optional(), + name: z.string().optional(), + }); +}); + +/** + * + * @typedef {Integrations} integrations + * @property {any} + * @property {string} + * @property {string} + */ +export type Integrations = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const integrationsResponse = z.lazy(() => { + return z + .object({ + config: z.any().optional(), + id: z.string().optional(), + name: z.string().optional(), + }) + .transform((data) => ({ + config: data['config'], + id: data['id'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const integrationsRequest = z.lazy(() => { + return z + .object({ config: z.any().nullish(), id: z.string().nullish(), name: z.string().nullish() }) + .transform((data) => ({ + config: data['config'], + id: data['id'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/list-integrations-response.ts b/packages/project-client/src/services/integrations/models/list-integrations-response.ts new file mode 100644 index 000000000..1dc2ce227 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/list-integrations-response.ts @@ -0,0 +1,43 @@ +import { z } from 'zod'; + +import { integrations, integrationsRequest, integrationsResponse } from './integrations'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const listIntegrationsResponse = z.lazy(() => { + return z.object({ + integrations: z.array(integrations).optional(), + }); +}); + +/** + * + * @typedef {ListIntegrationsResponse} listIntegrationsResponse + * @property {Integrations[]} + */ +export type ListIntegrationsResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const listIntegrationsResponseResponse = z.lazy(() => { + return z + .object({ + integrations: z.array(integrationsResponse).optional(), + }) + .transform((data) => ({ + integrations: data['integrations'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const listIntegrationsResponseRequest = z.lazy(() => { + return z.object({ integrations: z.array(integrationsRequest).nullish() }).transform((data) => ({ + integrations: data['integrations'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/mailgun-config-region.ts b/packages/project-client/src/services/integrations/models/mailgun-config-region.ts new file mode 100644 index 000000000..f8548acec --- /dev/null +++ b/packages/project-client/src/services/integrations/models/mailgun-config-region.ts @@ -0,0 +1,4 @@ +export enum MailgunConfigRegion { + US = 'us', + EU = 'eu', +} diff --git a/packages/project-client/src/services/integrations/models/mailgun-config.ts b/packages/project-client/src/services/integrations/models/mailgun-config.ts new file mode 100644 index 000000000..dbe4390c4 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/mailgun-config.ts @@ -0,0 +1,53 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const mailgunConfig = z.lazy(() => { + return z.object({ + apiKey: z.string().min(1), + domain: z.string().min(1), + region: z.string(), + }); +}); + +/** + * + * @typedef {MailgunConfig} mailgunConfig + * @property {string} + * @property {string} + * @property {MailgunConfigRegion} + */ +export type MailgunConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const mailgunConfigResponse = z.lazy(() => { + return z + .object({ + api_key: z.string().min(1), + domain: z.string().min(1), + region: z.string(), + }) + .transform((data) => ({ + apiKey: data['api_key'], + domain: data['domain'], + region: data['region'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const mailgunConfigRequest = z.lazy(() => { + return z + .object({ apiKey: z.string().nullish(), domain: z.string().nullish(), region: z.string().nullish() }) + .transform((data) => ({ + api_key: data['apiKey'], + domain: data['domain'], + region: data['region'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/ping-config.ts b/packages/project-client/src/services/integrations/models/ping-config.ts new file mode 100644 index 000000000..3c2b47dd8 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/ping-config.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const pingConfig = z.lazy(() => { + return z.object({ + url: z.string().min(1).max(100), + }); +}); + +/** + * + * @typedef {PingConfig} pingConfig + * @property {string} - URL to ping + */ +export type PingConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const pingConfigResponse = z.lazy(() => { + return z + .object({ + url: z.string().min(1).max(100), + }) + .transform((data) => ({ + url: data['url'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const pingConfigRequest = z.lazy(() => { + return z.object({ url: z.string().nullish() }).transform((data) => ({ + url: data['url'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/reply-to.ts b/packages/project-client/src/services/integrations/models/reply-to.ts new file mode 100644 index 000000000..5aa4b93cd --- /dev/null +++ b/packages/project-client/src/services/integrations/models/reply-to.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const replyTo = z.lazy(() => { + return z.object({ + email: z.string(), + name: z.string().optional(), + }); +}); + +/** + * + * @typedef {ReplyTo} replyTo + * @property {string} - The email address to reply to + * @property {string} - The name to reply to + */ +export type ReplyTo = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const replyToResponse = z.lazy(() => { + return z + .object({ + email: z.string(), + name: z.string().optional(), + }) + .transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const replyToRequest = z.lazy(() => { + return z.object({ email: z.string().nullish(), name: z.string().nullish() }).transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/sendgrid-config.ts b/packages/project-client/src/services/integrations/models/sendgrid-config.ts new file mode 100644 index 000000000..14b965c0a --- /dev/null +++ b/packages/project-client/src/services/integrations/models/sendgrid-config.ts @@ -0,0 +1,60 @@ +import { z } from 'zod'; + +import { replyTo, replyToRequest, replyToResponse } from './reply-to'; +import { sendgridConfigFrom, sendgridConfigFromRequest, sendgridConfigFromResponse } from './sendgrid-config-from'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const sendgridConfig = z.lazy(() => { + return z.object({ + apiKey: z.string(), + from: sendgridConfigFrom.optional(), + replyTo: replyTo.optional(), + }); +}); + +/** + * + * @typedef {SendgridConfig} sendgridConfig + * @property {string} - The API key for Sendgrid + * @property {SendgridConfigFrom} + * @property {ReplyTo} + */ +export type SendgridConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const sendgridConfigResponse = z.lazy(() => { + return z + .object({ + api_key: z.string(), + from: sendgridConfigFromResponse.optional(), + reply_to: replyToResponse.optional(), + }) + .transform((data) => ({ + apiKey: data['api_key'], + from: data['from'], + replyTo: data['reply_to'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const sendgridConfigRequest = z.lazy(() => { + return z + .object({ + apiKey: z.string().nullish(), + from: sendgridConfigFromRequest.nullish(), + replyTo: replyToRequest.nullish(), + }) + .transform((data) => ({ + api_key: data['apiKey'], + from: data['from'], + reply_to: data['replyTo'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/slack-config.ts b/packages/project-client/src/services/integrations/models/slack-config.ts new file mode 100644 index 000000000..45eface92 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/slack-config.ts @@ -0,0 +1,77 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const slackConfig = z.lazy(() => { + return z.object({ + appId: z.string().regex(/^[0-9A-Z]+$/), + clientId: z.string().regex(/^[0-9]+\.[0-9]+$/), + clientSecret: z.string().min(32).max(32), + id: z + .string() + .min(1) + .regex(/^[\w]*/) + .optional(), + signingSecret: z.string().min(32).max(32), + }); +}); + +/** + * + * @typedef {SlackConfig} slackConfig + * @property {string} + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type SlackConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const slackConfigResponse = z.lazy(() => { + return z + .object({ + app_id: z.string().regex(/^[0-9A-Z]+$/), + client_id: z.string().regex(/^[0-9]+\.[0-9]+$/), + client_secret: z.string().min(32).max(32), + id: z + .string() + .min(1) + .regex(/^[\w]*/) + .optional(), + signing_secret: z.string().min(32).max(32), + }) + .transform((data) => ({ + appId: data['app_id'], + clientId: data['client_id'], + clientSecret: data['client_secret'], + id: data['id'], + signingSecret: data['signing_secret'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const slackConfigRequest = z.lazy(() => { + return z + .object({ + appId: z.string().nullish(), + clientId: z.string().nullish(), + clientSecret: z.string().nullish(), + id: z.string().nullish(), + signingSecret: z.string().nullish(), + }) + .transform((data) => ({ + app_id: data['appId'], + client_id: data['clientId'], + client_secret: data['clientSecret'], + id: data['id'], + signing_secret: data['signingSecret'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/stripe-config.ts b/packages/project-client/src/services/integrations/models/stripe-config.ts new file mode 100644 index 000000000..1777d4ce0 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/stripe-config.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const stripeConfig = z.lazy(() => { + return z.object({ + webhookSigningSecret: z.string().min(1).max(100), + }); +}); + +/** + * + * @typedef {StripeConfig} stripeConfig + * @property {string} - The signing secret to verify incoming requests from Stripe + */ +export type StripeConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const stripeConfigResponse = z.lazy(() => { + return z + .object({ + webhook_signing_secret: z.string().min(1).max(100), + }) + .transform((data) => ({ + webhookSigningSecret: data['webhook_signing_secret'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const stripeConfigRequest = z.lazy(() => { + return z.object({ webhookSigningSecret: z.string().nullish() }).transform((data) => ({ + webhook_signing_secret: data['webhookSigningSecret'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/twilio-config-region.ts b/packages/project-client/src/services/integrations/models/twilio-config-region.ts new file mode 100644 index 000000000..f78838f53 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/twilio-config-region.ts @@ -0,0 +1,5 @@ +export enum TwilioConfigRegion { + US1 = 'us1', + IE1 = 'ie1', + AU1 = 'au1', +} diff --git a/packages/project-client/src/services/integrations/models/twilio-config.ts b/packages/project-client/src/services/integrations/models/twilio-config.ts new file mode 100644 index 000000000..d619c371c --- /dev/null +++ b/packages/project-client/src/services/integrations/models/twilio-config.ts @@ -0,0 +1,77 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const twilioConfig = z.lazy(() => { + return z.object({ + accountSid: z.string().min(1).max(100), + apiKey: z.string().min(1).max(100), + apiSecret: z.string().min(1).max(100), + from: z + .string() + .min(1) + .max(100) + .regex(/^\+[0-9]{1,14}$/), + region: z.string().optional(), + }); +}); + +/** + * + * @typedef {TwilioConfig} twilioConfig + * @property {string} - The SID for your Twilio account + * @property {string} - The API key for Twilio + * @property {string} - The API Secret for Twilio + * @property {string} - The phone number to send from, in E.164 format + * @property {TwilioConfigRegion} - The region to use for Twilio, defaults to 'us1' + */ +export type TwilioConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const twilioConfigResponse = z.lazy(() => { + return z + .object({ + account_sid: z.string().min(1).max(100), + api_key: z.string().min(1).max(100), + api_secret: z.string().min(1).max(100), + from: z + .string() + .min(1) + .max(100) + .regex(/^\+[0-9]{1,14}$/), + region: z.string().optional(), + }) + .transform((data) => ({ + accountSid: data['account_sid'], + apiKey: data['api_key'], + apiSecret: data['api_secret'], + from: data['from'], + region: data['region'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const twilioConfigRequest = z.lazy(() => { + return z + .object({ + accountSid: z.string().nullish(), + apiKey: z.string().nullish(), + apiSecret: z.string().nullish(), + from: z.string().nullish(), + region: z.string().nullish(), + }) + .transform((data) => ({ + account_sid: data['accountSid'], + api_key: data['apiKey'], + api_secret: data['apiSecret'], + from: data['from'], + region: data['region'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/type_.ts b/packages/project-client/src/services/integrations/models/type_.ts new file mode 100644 index 000000000..c25e45051 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/type_.ts @@ -0,0 +1,3 @@ +export enum Type_ { + SERVICEACCOUNT = 'service_account', +} diff --git a/packages/project-client/src/services/integrations/models/webpush-config.ts b/packages/project-client/src/services/integrations/models/webpush-config.ts new file mode 100644 index 000000000..8221dcd8e --- /dev/null +++ b/packages/project-client/src/services/integrations/models/webpush-config.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const webpushConfig = z.lazy(() => { + return z.object({ + privateKey: z.string().min(8).max(128), + publicKey: z.string().min(8).max(128), + }); +}); + +/** + * + * @typedef {WebpushConfig} webpushConfig + * @property {string} + * @property {string} + */ +export type WebpushConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const webpushConfigResponse = z.lazy(() => { + return z + .object({ + private_key: z.string().min(8).max(128), + public_key: z.string().min(8).max(128), + }) + .transform((data) => ({ + privateKey: data['private_key'], + publicKey: data['public_key'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const webpushConfigRequest = z.lazy(() => { + return z.object({ privateKey: z.string().nullish(), publicKey: z.string().nullish() }).transform((data) => ({ + private_key: data['privateKey'], + public_key: data['publicKey'], + })); +}); diff --git a/yarn.lock b/yarn.lock index 0f2fdabdc..6c8213528 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15617,6 +15617,11 @@ yocto-queue@^1.0.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.1.1.tgz#fef65ce3ac9f8a32ceac5a634f74e17e5b232110" integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g== +zod@3.22.0: + version "3.22.0" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.0.tgz#2478211a9bf477eb2d7d2ce031b5f8ff0d596407" + integrity sha512-y5KZY/ssf5n7hCGDGGtcJO/EBJEm5Pa+QQvFBeyMOtnFYOSflalxIFFvdaYevPhePcmcKC4aTbFkCcXN7D0O8Q== + zod@3.23.8: version "3.23.8" resolved "https://registry.yarnpkg.com/zod/-/zod-3.23.8.tgz#e37b957b5d52079769fb8097099b592f0ef4067d" From 2a510c3efb8f0b0ed7989f71c26c2befb3efc733 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 09:59:43 +0200 Subject: [PATCH 06/12] chore: bump axios --- .eslintignore | 1 + packages/codegen/package.json | 2 +- packages/project-client/package.json | 1 + yarn.lock | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index 31cea6480..479c3a36f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ /node_modules coverage dist +tsconfig.json diff --git a/packages/codegen/package.json b/packages/codegen/package.json index f691b3f4a..914134f19 100644 --- a/packages/codegen/package.json +++ b/packages/codegen/package.json @@ -41,7 +41,7 @@ "dependencies": { "@apidevtools/swagger-parser": "^10.1.0", "ast-types": "^0.14.2", - "axios": "^1.0.0", + "axios": "^1.7.4", "eslint": "^8.57.0", "json-schema-merge-allof": "^0.8.1", "json5": "^2.2.3", diff --git a/packages/project-client/package.json b/packages/project-client/package.json index e2c63c536..882ee950a 100644 --- a/packages/project-client/package.json +++ b/packages/project-client/package.json @@ -39,6 +39,7 @@ "start": "rm -rf dist/ && tsc -w" }, "dependencies": { + "axios": "^1.7.4", "zod": "3.22.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 6c8213528..d01550b0b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5703,7 +5703,7 @@ axios@^0.27.2: follow-redirects "^1.14.9" form-data "^4.0.0" -axios@^1.0.0: +axios@^1.7.4: version "1.7.4" resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2" integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw== From da0745d129ad04eb6cc52b3d958b16c200f55faf Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 10:02:57 +0200 Subject: [PATCH 07/12] chore: use openapi.v2.json spec file --- packages/project-client/scripts/build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/project-client/scripts/build.ts b/packages/project-client/scripts/build.ts index 32e1b6aae..8e467701e 100644 --- a/packages/project-client/scripts/build.ts +++ b/packages/project-client/scripts/build.ts @@ -98,7 +98,7 @@ const { values: args } = parseArgs({ }, }); -async function build(specfile = 'https://public.magicbell.com/specs/swagger.json') { +async function build(specfile = 'https://public.magicbell.com/specs/openapi.v2.json') { const liblabConfig = JSON.parse(await fs.readFile('./liblab.config.json', { encoding: 'utf-8' })); let swaggerJSON = await readFileOrUrl(specfile); const spec = JSON.parse(swaggerJSON); From 0c27b6887a09d42b33706fd0438ffa20aa04f946 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 10:25:29 +0200 Subject: [PATCH 08/12] chore: sync axios versions --- packages/user-client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/user-client/package.json b/packages/user-client/package.json index 4d6d1a321..6027fd1f0 100644 --- a/packages/user-client/package.json +++ b/packages/user-client/package.json @@ -38,7 +38,7 @@ "version": "tsc --version" }, "dependencies": { - "axios": "^1.0.0" + "axios": "^1.7.4" }, "devDependencies": { "@types/jest": "^29.5.10", From 902f7e53eb764a0cee7b6aac6ed4d34cf567d5f3 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 10:25:58 +0200 Subject: [PATCH 09/12] chore: commit unversioned files --- .../project-client/docs/models/AccessToken.md | 10 + .../models/ArrayWithMetadataOfInboxToken.md | 27 +++ .../docs/models/CreateProjectTokenRequest.md | 8 + .../docs/models/CreateUserTokenRequest.md | 10 + .../docs/models/DiscardTokenResponse.md | 8 + .../docs/models/FetchTokensResponse.md | 18 ++ .../docs/models/GithubConfig.md | 7 + .../project-client/docs/models/InboxToken.md | 7 + .../docs/models/InboxTokenWithMetadata.md | 19 ++ .../project-client/docs/models/SesConfig.md | 20 ++ .../docs/services/JwtService.md | 204 ++++++++++++++++++ .../http/transport/request-axios-adapter.ts | 98 +++++++++ .../src/services/broadcasts/request-params.ts | 4 + ...array-with-metadata-of-inbox-token-data.ts | 51 +++++ .../array-with-metadata-of-inbox-token.ts | 47 ++++ .../channels/models/data-metadata-6.ts | 63 ++++++ .../inbox-token-with-metadata-metadata.ts | 63 ++++++ .../models/inbox-token-with-metadata.ts | 55 +++++ .../services/channels/models/inbox-token.ts | 41 ++++ .../integrations/models/github-config.ts | 41 ++++ .../models/sendgrid-config-from.ts | 46 ++++ .../integrations/models/ses-config-from.ts | 46 ++++ .../integrations/models/ses-config.ts | 71 ++++++ .../project-client/src/services/jwt/index.ts | 2 + .../project-client/src/services/jwt/jwt.ts | 160 ++++++++++++++ .../src/services/jwt/models/access-token.ts | 63 ++++++ .../models/create-project-token-request.ts | 46 ++++ .../jwt/models/create-user-token-request.ts | 63 ++++++ .../jwt/models/discard-token-response.ts | 46 ++++ .../jwt/models/fetch-tokens-response.ts | 43 ++++ .../src/services/jwt/models/index.ts | 6 + .../src/services/jwt/models/tokens.ts | 63 ++++++ 32 files changed, 1456 insertions(+) create mode 100644 packages/project-client/docs/models/AccessToken.md create mode 100644 packages/project-client/docs/models/ArrayWithMetadataOfInboxToken.md create mode 100644 packages/project-client/docs/models/CreateProjectTokenRequest.md create mode 100644 packages/project-client/docs/models/CreateUserTokenRequest.md create mode 100644 packages/project-client/docs/models/DiscardTokenResponse.md create mode 100644 packages/project-client/docs/models/FetchTokensResponse.md create mode 100644 packages/project-client/docs/models/GithubConfig.md create mode 100644 packages/project-client/docs/models/InboxToken.md create mode 100644 packages/project-client/docs/models/InboxTokenWithMetadata.md create mode 100644 packages/project-client/docs/models/SesConfig.md create mode 100644 packages/project-client/docs/services/JwtService.md create mode 100644 packages/project-client/src/http/transport/request-axios-adapter.ts create mode 100644 packages/project-client/src/services/broadcasts/request-params.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token-data.ts create mode 100644 packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token.ts create mode 100644 packages/project-client/src/services/channels/models/data-metadata-6.ts create mode 100644 packages/project-client/src/services/channels/models/inbox-token-with-metadata-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/inbox-token-with-metadata.ts create mode 100644 packages/project-client/src/services/channels/models/inbox-token.ts create mode 100644 packages/project-client/src/services/integrations/models/github-config.ts create mode 100644 packages/project-client/src/services/integrations/models/sendgrid-config-from.ts create mode 100644 packages/project-client/src/services/integrations/models/ses-config-from.ts create mode 100644 packages/project-client/src/services/integrations/models/ses-config.ts create mode 100644 packages/project-client/src/services/jwt/index.ts create mode 100644 packages/project-client/src/services/jwt/jwt.ts create mode 100644 packages/project-client/src/services/jwt/models/access-token.ts create mode 100644 packages/project-client/src/services/jwt/models/create-project-token-request.ts create mode 100644 packages/project-client/src/services/jwt/models/create-user-token-request.ts create mode 100644 packages/project-client/src/services/jwt/models/discard-token-response.ts create mode 100644 packages/project-client/src/services/jwt/models/fetch-tokens-response.ts create mode 100644 packages/project-client/src/services/jwt/models/index.ts create mode 100644 packages/project-client/src/services/jwt/models/tokens.ts diff --git a/packages/project-client/docs/models/AccessToken.md b/packages/project-client/docs/models/AccessToken.md new file mode 100644 index 000000000..1193f6c2f --- /dev/null +++ b/packages/project-client/docs/models/AccessToken.md @@ -0,0 +1,10 @@ +# AccessToken + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| token | string | ✅ | | +| tokenId | string | ✅ | | +| expiresAt | string | ❌ | | diff --git a/packages/project-client/docs/models/ArrayWithMetadataOfInboxToken.md b/packages/project-client/docs/models/ArrayWithMetadataOfInboxToken.md new file mode 100644 index 000000000..a3bd4dda3 --- /dev/null +++ b/packages/project-client/docs/models/ArrayWithMetadataOfInboxToken.md @@ -0,0 +1,27 @@ +# ArrayWithMetadataOfInboxToken + +**Properties** + +| Name | Type | Required | Description | +| :--- | :---------------------------------- | :------- | :---------- | +| data | ArrayWithMetadataOfInboxTokenData[] | ✅ | | + +# ArrayWithMetadataOfInboxTokenData + +**Properties** + +| Name | Type | Required | Description | +| :------- | :------------ | :------- | :---------- | +| data | InboxToken | ✅ | | +| metadata | DataMetadata1 | ✅ | | + +# DataMetadata1 + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/CreateProjectTokenRequest.md b/packages/project-client/docs/models/CreateProjectTokenRequest.md new file mode 100644 index 000000000..c5884cd66 --- /dev/null +++ b/packages/project-client/docs/models/CreateProjectTokenRequest.md @@ -0,0 +1,8 @@ +# CreateProjectTokenRequest + +**Properties** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :----------------------------------------------------- | +| name | string | ✅ | The name of the token. | +| expiry | number | ❌ | The duration for which the token is valid (in seconds) | diff --git a/packages/project-client/docs/models/CreateUserTokenRequest.md b/packages/project-client/docs/models/CreateUserTokenRequest.md new file mode 100644 index 000000000..6d214de46 --- /dev/null +++ b/packages/project-client/docs/models/CreateUserTokenRequest.md @@ -0,0 +1,10 @@ +# CreateUserTokenRequest + +**Properties** + +| Name | Type | Required | Description | +| :--------- | :----- | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| email | string | ❌ | The user's email. | +| expiry | number | ❌ | The duration for which the token is valid (in seconds) | +| externalId | string | ❌ | A unique string that MagicBell can utilize to identify the user uniquely. We recommend setting this attribute to the ID of the user in your database. Provide the external id if the user's email is unavailable. | +| name | string | ❌ | The name of the token. | diff --git a/packages/project-client/docs/models/DiscardTokenResponse.md b/packages/project-client/docs/models/DiscardTokenResponse.md new file mode 100644 index 000000000..fda165f56 --- /dev/null +++ b/packages/project-client/docs/models/DiscardTokenResponse.md @@ -0,0 +1,8 @@ +# DiscardTokenResponse + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| discardedAt | string | ✅ | | +| tokenId | string | ✅ | | diff --git a/packages/project-client/docs/models/FetchTokensResponse.md b/packages/project-client/docs/models/FetchTokensResponse.md new file mode 100644 index 000000000..0d8b8003f --- /dev/null +++ b/packages/project-client/docs/models/FetchTokensResponse.md @@ -0,0 +1,18 @@ +# FetchTokensResponse + +**Properties** + +| Name | Type | Required | Description | +| :----- | :------- | :------- | :---------- | +| tokens | Tokens[] | ✅ | | + +# Tokens + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| expiresAt | string | ❌ | | +| id | string | ❌ | | +| name | string | ❌ | | diff --git a/packages/project-client/docs/models/GithubConfig.md b/packages/project-client/docs/models/GithubConfig.md new file mode 100644 index 000000000..e884bcf78 --- /dev/null +++ b/packages/project-client/docs/models/GithubConfig.md @@ -0,0 +1,7 @@ +# GithubConfig + +**Properties** + +| Name | Type | Required | Description | +| :------------------- | :----- | :------- | :--------------------------------------------------------- | +| webhookSigningSecret | string | ✅ | The signing secret to verify incoming requests from Stripe | diff --git a/packages/project-client/docs/models/InboxToken.md b/packages/project-client/docs/models/InboxToken.md new file mode 100644 index 000000000..b940caf68 --- /dev/null +++ b/packages/project-client/docs/models/InboxToken.md @@ -0,0 +1,7 @@ +# InboxToken + +**Properties** + +| Name | Type | Required | Description | +| :---- | :----- | :------- | :---------- | +| token | string | ✅ | | diff --git a/packages/project-client/docs/models/InboxTokenWithMetadata.md b/packages/project-client/docs/models/InboxTokenWithMetadata.md new file mode 100644 index 000000000..00839c8c0 --- /dev/null +++ b/packages/project-client/docs/models/InboxTokenWithMetadata.md @@ -0,0 +1,19 @@ +# InboxTokenWithMetadata + +**Properties** + +| Name | Type | Required | Description | +| :------- | :----------------------------- | :------- | :---------- | +| data | InboxToken | ✅ | | +| metadata | InboxTokenWithMetadataMetadata | ✅ | | + +# InboxTokenWithMetadataMetadata + +**Properties** + +| Name | Type | Required | Description | +| :---------- | :----- | :------- | :---------- | +| createdAt | string | ✅ | | +| id | string | ✅ | | +| discardedAt | string | ❌ | | +| updatedAt | string | ❌ | | diff --git a/packages/project-client/docs/models/SesConfig.md b/packages/project-client/docs/models/SesConfig.md new file mode 100644 index 000000000..6c84da4f6 --- /dev/null +++ b/packages/project-client/docs/models/SesConfig.md @@ -0,0 +1,20 @@ +# SesConfig + +**Properties** + +| Name | Type | Required | Description | +| :-------- | :------------ | :------- | :----------------------------------------------- | +| keyId | string | ✅ | AWS Access Key ID | +| region | string | ✅ | AWS Region | +| secretKey | string | ✅ | AWS Secret Key | +| endpoint | string | ❌ | HTTP endpoint to send requests to (testing only) | +| from | SesConfigFrom | ❌ | | + +# SesConfigFrom + +**Properties** + +| Name | Type | Required | Description | +| :---- | :----- | :------- | :----------------------------- | +| email | string | ✅ | The email address to send from | +| name | string | ❌ | The name to send from | diff --git a/packages/project-client/docs/services/JwtService.md b/packages/project-client/docs/services/JwtService.md new file mode 100644 index 000000000..adfd65e49 --- /dev/null +++ b/packages/project-client/docs/services/JwtService.md @@ -0,0 +1,204 @@ +# JwtService + +A list of all methods in the `JwtService` service. Click on the method name to view detailed information about that method. + +| Methods | Description | +| :-------------------------------------------- | :---------- | +| [fetch_project_tokens](#fetch_project_tokens) | | +| [create_project_jwt](#create_project_jwt) | | +| [discard_project_jwt](#discard_project_jwt) | | +| [create_user_jwt](#create_user_jwt) | | +| [discard_user_jwt](#discard_user_jwt) | | +| [fetch_user_tokens](#fetch_user_tokens) | | + +## fetch_project_tokens + +- HTTP Method: `GET` +- Endpoint: `/jwt/project` + +**Return Type** + +`FetchTokensResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.jwt.fetchProjectTokens(); + + console.log(data); +})(); +``` + +## create_project_jwt + +- HTTP Method: `POST` +- Endpoint: `/jwt/project` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------------------------------------ | :------- | :---------------- | +| body | [CreateProjectTokenRequest](../models/CreateProjectTokenRequest.md) | ❌ | The request body. | + +**Return Type** + +`AccessToken` + +**Example Usage Code Snippet** + +```typescript +import { Client, CreateProjectTokenRequest } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const createProjectTokenRequest: CreateProjectTokenRequest = { + expiry: 1, + name: 'culpa', + }; + + const { data } = await client.jwt.createProjectJwt(input); + + console.log(data); +})(); +``` + +## discard_project_jwt + +- HTTP Method: `DELETE` +- Endpoint: `/jwt/project/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardTokenResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.jwt.discardProjectJwt('token_id'); + + console.log(data); +})(); +``` + +## create_user_jwt + +- HTTP Method: `POST` +- Endpoint: `/jwt/user` + +**Parameters** + +| Name | Type | Required | Description | +| :--- | :------------------------------------------------------------ | :------- | :---------------- | +| body | [CreateUserTokenRequest](../models/CreateUserTokenRequest.md) | ❌ | The request body. | + +**Return Type** + +`AccessToken` + +**Example Usage Code Snippet** + +```typescript +import { Client, CreateUserTokenRequest } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const createUserTokenRequest: CreateUserTokenRequest = { + email: 'laborum esse do dolore ullamco', + expiry: 6, + externalId: 'ut officia', + name: 'exercitation esse', + }; + + const { data } = await client.jwt.createUserJwt(input); + + console.log(data); +})(); +``` + +## discard_user_jwt + +- HTTP Method: `DELETE` +- Endpoint: `/jwt/user/{token_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :------ | :----- | :------- | :---------- | +| tokenId | string | ✅ | | + +**Return Type** + +`DiscardTokenResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.jwt.discardUserJwt('token_id'); + + console.log(data); +})(); +``` + +## fetch_user_tokens + +- HTTP Method: `GET` +- Endpoint: `/jwt/user/{user_id}` + +**Parameters** + +| Name | Type | Required | Description | +| :----- | :----- | :------- | :---------- | +| userId | string | ✅ | | + +**Return Type** + +`FetchTokensResponse` + +**Example Usage Code Snippet** + +```typescript +import { Client } from '@magicbell/project-client'; + +(async () => { + const client = new Client({ + token: 'YOUR_TOKEN', + }); + + const { data } = await client.jwt.fetchUserTokens('user_id'); + + console.log(data); +})(); +``` diff --git a/packages/project-client/src/http/transport/request-axios-adapter.ts b/packages/project-client/src/http/transport/request-axios-adapter.ts new file mode 100644 index 000000000..e7e14ff0b --- /dev/null +++ b/packages/project-client/src/http/transport/request-axios-adapter.ts @@ -0,0 +1,98 @@ +import axios, { AxiosRequestConfig, AxiosResponse, isAxiosError } from 'axios'; + +import { HttpError } from '../error'; +import { HttpMetadata, HttpResponse } from '../types'; +import { Request } from './request'; + +export interface HttpAdapter { + send(): Promise; +} + +export class RequestAxiosAdapter implements HttpAdapter { + private config: AxiosRequestConfig = { + responseType: 'arraybuffer', + }; + + constructor(private request: Request) { + this.setHeaders(); + this.setTimeout(); + } + + public async send(): Promise> { + const method = this.getMethod(); + const { body } = this.request; + let axiosResponse: AxiosResponse; + + try { + if (!!body) { + axiosResponse = await method(this.request.constructFullUrl(), body, this.config); + } else { + axiosResponse = await method(this.request.constructFullUrl(), this.config); + } + } catch (err) { + if (!isAxiosError(err)) { + throw err; + } + axiosResponse = err.response; + } + + const headerRecord: Record = {}; + Object.keys(axiosResponse.headers).forEach((key) => { + headerRecord[key] = axiosResponse.headers[key]; + }); + + const metadata: HttpMetadata = { + status: axiosResponse.status, + statusText: axiosResponse.statusText || '', + headers: headerRecord, + }; + + if (metadata.status >= 400) { + throw new HttpError(metadata); + } + + return { + metadata, + raw: axiosResponse.data.buffer.slice( + axiosResponse.data.byteOffset, + axiosResponse.data.byteOffset + axiosResponse.data.byteLength, + ), + }; + } + + private getMethod(): (url: string, data?: any, config?: AxiosRequestConfig) => Promise { + if (this.request.method === 'POST') { + return axios.post; + } else if (this.request.method === 'GET') { + return axios.get; + } else if (this.request.method === 'PUT') { + return axios.put; + } else if (this.request.method === 'DELETE') { + return axios.delete; + } + throw new Error('invalid method!!!!'); + } + + private setHeaders(): void { + if (!this.request.headers) { + return; + } + + const headersRecord: Record = {}; + new Headers(this.request.getHeaders()).forEach((value, key) => { + headersRecord[key] = value; + }); + + this.config = { + ...this.config, + headers: headersRecord, + }; + } + + private setTimeout(): void { + this.config = { + ...this.config, + timeout: this.request.config.timeout, + }; + } +} diff --git a/packages/project-client/src/services/broadcasts/request-params.ts b/packages/project-client/src/services/broadcasts/request-params.ts new file mode 100644 index 000000000..e191cec19 --- /dev/null +++ b/packages/project-client/src/services/broadcasts/request-params.ts @@ -0,0 +1,4 @@ +export interface ListBroadcastsParams { + page?: number; + perPage?: number; +} diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token-data.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token-data.ts new file mode 100644 index 000000000..72cef23ff --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token-data.ts @@ -0,0 +1,51 @@ +import { z } from 'zod'; + +import { dataMetadata1, dataMetadata1Request, dataMetadata1Response } from './data-metadata-1'; +import { inboxToken, inboxTokenRequest, inboxTokenResponse } from './inbox-token'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfInboxTokenData = z.lazy(() => { + return z.object({ + data: inboxToken, + metadata: dataMetadata1, + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfInboxTokenData} arrayWithMetadataOfInboxTokenData + * @property {InboxToken} + * @property {DataMetadata1} + */ +export type ArrayWithMetadataOfInboxTokenData = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfInboxTokenDataResponse = z.lazy(() => { + return z + .object({ + data: inboxTokenResponse, + metadata: dataMetadata1Response, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfInboxTokenDataRequest = z.lazy(() => { + return z + .object({ data: inboxTokenRequest.nullish(), metadata: dataMetadata1Request.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token.ts b/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token.ts new file mode 100644 index 000000000..02f34cdb0 --- /dev/null +++ b/packages/project-client/src/services/channels/models/array-with-metadata-of-inbox-token.ts @@ -0,0 +1,47 @@ +import { z } from 'zod'; + +import { + arrayWithMetadataOfInboxTokenData, + arrayWithMetadataOfInboxTokenDataRequest, + arrayWithMetadataOfInboxTokenDataResponse, +} from './array-with-metadata-of-inbox-token-data'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const arrayWithMetadataOfInboxToken = z.lazy(() => { + return z.object({ + data: z.array(arrayWithMetadataOfInboxTokenData), + }); +}); + +/** + * + * @typedef {ArrayWithMetadataOfInboxToken} arrayWithMetadataOfInboxToken + * @property {ArrayWithMetadataOfInboxTokenData[]} + */ +export type ArrayWithMetadataOfInboxToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfInboxTokenResponse = z.lazy(() => { + return z + .object({ + data: z.array(arrayWithMetadataOfInboxTokenDataResponse), + }) + .transform((data) => ({ + data: data['data'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const arrayWithMetadataOfInboxTokenRequest = z.lazy(() => { + return z.object({ data: z.array(arrayWithMetadataOfInboxTokenDataRequest).nullish() }).transform((data) => ({ + data: data['data'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/data-metadata-6.ts b/packages/project-client/src/services/channels/models/data-metadata-6.ts new file mode 100644 index 000000000..de750a4d5 --- /dev/null +++ b/packages/project-client/src/services/channels/models/data-metadata-6.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const dataMetadata6 = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {DataMetadata6} dataMetadata6 + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type DataMetadata6 = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata6Response = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const dataMetadata6Request = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/inbox-token-with-metadata-metadata.ts b/packages/project-client/src/services/channels/models/inbox-token-with-metadata-metadata.ts new file mode 100644 index 000000000..47a99e2c3 --- /dev/null +++ b/packages/project-client/src/services/channels/models/inbox-token-with-metadata-metadata.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const inboxTokenWithMetadataMetadata = z.lazy(() => { + return z.object({ + createdAt: z.string(), + discardedAt: z.string().optional(), + id: z.string(), + updatedAt: z.string().optional(), + }); +}); + +/** + * + * @typedef {InboxTokenWithMetadataMetadata} inboxTokenWithMetadataMetadata + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type InboxTokenWithMetadataMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenWithMetadataMetadataResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + discarded_at: z.string().optional(), + id: z.string(), + updated_at: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + discardedAt: data['discarded_at'], + id: data['id'], + updatedAt: data['updated_at'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenWithMetadataMetadataRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + discardedAt: z.string().nullish(), + id: z.string().nullish(), + updatedAt: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + discarded_at: data['discardedAt'], + id: data['id'], + updated_at: data['updatedAt'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/inbox-token-with-metadata.ts b/packages/project-client/src/services/channels/models/inbox-token-with-metadata.ts new file mode 100644 index 000000000..14cb0bd2d --- /dev/null +++ b/packages/project-client/src/services/channels/models/inbox-token-with-metadata.ts @@ -0,0 +1,55 @@ +import { z } from 'zod'; + +import { inboxToken, inboxTokenRequest, inboxTokenResponse } from './inbox-token'; +import { + inboxTokenWithMetadataMetadata, + inboxTokenWithMetadataMetadataRequest, + inboxTokenWithMetadataMetadataResponse, +} from './inbox-token-with-metadata-metadata'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const inboxTokenWithMetadata = z.lazy(() => { + return z.object({ + data: inboxToken, + metadata: inboxTokenWithMetadataMetadata, + }); +}); + +/** + * + * @typedef {InboxTokenWithMetadata} inboxTokenWithMetadata + * @property {InboxToken} + * @property {InboxTokenWithMetadataMetadata} + */ +export type InboxTokenWithMetadata = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenWithMetadataResponse = z.lazy(() => { + return z + .object({ + data: inboxTokenResponse, + metadata: inboxTokenWithMetadataMetadataResponse, + }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenWithMetadataRequest = z.lazy(() => { + return z + .object({ data: inboxTokenRequest.nullish(), metadata: inboxTokenWithMetadataMetadataRequest.nullish() }) + .transform((data) => ({ + data: data['data'], + metadata: data['metadata'], + })); +}); diff --git a/packages/project-client/src/services/channels/models/inbox-token.ts b/packages/project-client/src/services/channels/models/inbox-token.ts new file mode 100644 index 000000000..cf8432cdc --- /dev/null +++ b/packages/project-client/src/services/channels/models/inbox-token.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const inboxToken = z.lazy(() => { + return z.object({ + token: z.string(), + }); +}); + +/** + * + * @typedef {InboxToken} inboxToken + * @property {string} + */ +export type InboxToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenResponse = z.lazy(() => { + return z + .object({ + token: z.string(), + }) + .transform((data) => ({ + token: data['token'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const inboxTokenRequest = z.lazy(() => { + return z.object({ token: z.string().nullish() }).transform((data) => ({ + token: data['token'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/github-config.ts b/packages/project-client/src/services/integrations/models/github-config.ts new file mode 100644 index 000000000..945bb249d --- /dev/null +++ b/packages/project-client/src/services/integrations/models/github-config.ts @@ -0,0 +1,41 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const githubConfig = z.lazy(() => { + return z.object({ + webhookSigningSecret: z.string().min(1).max(100), + }); +}); + +/** + * + * @typedef {GithubConfig} githubConfig + * @property {string} - The signing secret to verify incoming requests from Stripe + */ +export type GithubConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const githubConfigResponse = z.lazy(() => { + return z + .object({ + webhook_signing_secret: z.string().min(1).max(100), + }) + .transform((data) => ({ + webhookSigningSecret: data['webhook_signing_secret'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const githubConfigRequest = z.lazy(() => { + return z.object({ webhookSigningSecret: z.string().nullish() }).transform((data) => ({ + webhook_signing_secret: data['webhookSigningSecret'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/sendgrid-config-from.ts b/packages/project-client/src/services/integrations/models/sendgrid-config-from.ts new file mode 100644 index 000000000..eca87fff5 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/sendgrid-config-from.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const sendgridConfigFrom = z.lazy(() => { + return z.object({ + email: z.string(), + name: z.string().optional(), + }); +}); + +/** + * + * @typedef {SendgridConfigFrom} sendgridConfigFrom + * @property {string} - The email address to send from + * @property {string} - The name to send from + */ +export type SendgridConfigFrom = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const sendgridConfigFromResponse = z.lazy(() => { + return z + .object({ + email: z.string(), + name: z.string().optional(), + }) + .transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const sendgridConfigFromRequest = z.lazy(() => { + return z.object({ email: z.string().nullish(), name: z.string().nullish() }).transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/ses-config-from.ts b/packages/project-client/src/services/integrations/models/ses-config-from.ts new file mode 100644 index 000000000..5ee8af515 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/ses-config-from.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const sesConfigFrom = z.lazy(() => { + return z.object({ + email: z.string(), + name: z.string().optional(), + }); +}); + +/** + * + * @typedef {SesConfigFrom} sesConfigFrom + * @property {string} - The email address to send from + * @property {string} - The name to send from + */ +export type SesConfigFrom = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const sesConfigFromResponse = z.lazy(() => { + return z + .object({ + email: z.string(), + name: z.string().optional(), + }) + .transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const sesConfigFromRequest = z.lazy(() => { + return z.object({ email: z.string().nullish(), name: z.string().nullish() }).transform((data) => ({ + email: data['email'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/integrations/models/ses-config.ts b/packages/project-client/src/services/integrations/models/ses-config.ts new file mode 100644 index 000000000..82c3c01e8 --- /dev/null +++ b/packages/project-client/src/services/integrations/models/ses-config.ts @@ -0,0 +1,71 @@ +import { z } from 'zod'; + +import { sesConfigFrom, sesConfigFromRequest, sesConfigFromResponse } from './ses-config-from'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const sesConfig = z.lazy(() => { + return z.object({ + endpoint: z.string().min(1).optional(), + from: sesConfigFrom.optional(), + keyId: z.string().min(1), + region: z.string().min(1), + secretKey: z.string().min(1), + }); +}); + +/** + * + * @typedef {SesConfig} sesConfig + * @property {string} - HTTP endpoint to send requests to (testing only) + * @property {SesConfigFrom} + * @property {string} - AWS Access Key ID + * @property {string} - AWS Region + * @property {string} - AWS Secret Key + */ +export type SesConfig = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const sesConfigResponse = z.lazy(() => { + return z + .object({ + endpoint: z.string().min(1).optional(), + from: sesConfigFromResponse.optional(), + key_id: z.string().min(1), + region: z.string().min(1), + secret_key: z.string().min(1), + }) + .transform((data) => ({ + endpoint: data['endpoint'], + from: data['from'], + keyId: data['key_id'], + region: data['region'], + secretKey: data['secret_key'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const sesConfigRequest = z.lazy(() => { + return z + .object({ + endpoint: z.string().nullish(), + from: sesConfigFromRequest.nullish(), + keyId: z.string().nullish(), + region: z.string().nullish(), + secretKey: z.string().nullish(), + }) + .transform((data) => ({ + endpoint: data['endpoint'], + from: data['from'], + key_id: data['keyId'], + region: data['region'], + secret_key: data['secretKey'], + })); +}); diff --git a/packages/project-client/src/services/jwt/index.ts b/packages/project-client/src/services/jwt/index.ts new file mode 100644 index 000000000..ccbbfa9c6 --- /dev/null +++ b/packages/project-client/src/services/jwt/index.ts @@ -0,0 +1,2 @@ +export { JwtService } from './jwt'; +export * from './models'; diff --git a/packages/project-client/src/services/jwt/jwt.ts b/packages/project-client/src/services/jwt/jwt.ts new file mode 100644 index 000000000..32e001b88 --- /dev/null +++ b/packages/project-client/src/services/jwt/jwt.ts @@ -0,0 +1,160 @@ +import { z } from 'zod'; + +import { RequestBuilder } from '../../http/transport/request-builder'; +import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; +import { BaseService } from '../base-service'; +import { AccessToken, accessTokenResponse } from './models/access-token'; +import { CreateProjectTokenRequest, createProjectTokenRequestRequest } from './models/create-project-token-request'; +import { CreateUserTokenRequest, createUserTokenRequestRequest } from './models/create-user-token-request'; +import { DiscardTokenResponse, discardTokenResponseResponse } from './models/discard-token-response'; +import { FetchTokensResponse, fetchTokensResponseResponse } from './models/fetch-tokens-response'; + +export class JwtService extends BaseService { + /** + * + * @returns {Promise>} OK + */ + async fetchProjectTokens(requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/jwt/project') + .setRequestSchema(z.any()) + .setResponseSchema(fetchTokensResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} Created + */ + async createProjectJwt( + body: CreateProjectTokenRequest, + requestConfig?: RequestConfig, + ): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('POST') + .setPath('/jwt/project') + .setRequestSchema(createProjectTokenRequestRequest) + .setResponseSchema(accessTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardProjectJwt(tokenId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/jwt/project/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardTokenResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @returns {Promise>} Created + */ + async createUserJwt(body: CreateUserTokenRequest, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('POST') + .setPath('/jwt/user') + .setRequestSchema(createUserTokenRequestRequest) + .setResponseSchema(accessTokenResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addHeaderParam({ key: 'Content-Type', value: 'application/json' }) + .addBody(body) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} tokenId - + * @returns {Promise>} OK + */ + async discardUserJwt(tokenId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('DELETE') + .setPath('/jwt/user/{token_id}') + .setRequestSchema(z.any()) + .setResponseSchema(discardTokenResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'token_id', + value: tokenId, + }) + .build(); + return this.client.call(request); + } + + /** + * + * @param {string} userId - + * @returns {Promise>} OK + */ + async fetchUserTokens(userId: string, requestConfig?: RequestConfig): Promise> { + const request = new RequestBuilder() + .setConfig(this.config) + .setBaseUrl(this.config) + .setMethod('GET') + .setPath('/jwt/user/{user_id}') + .setRequestSchema(z.any()) + .setResponseSchema(fetchTokensResponseResponse) + .setRequestContentType(ContentType.Json) + .setResponseContentType(ContentType.Json) + .setRetryAttempts(this.config, requestConfig) + .setRetryDelayMs(this.config, requestConfig) + .setResponseValidation(this.config, requestConfig) + .addPathParam({ + key: 'user_id', + value: userId, + }) + .build(); + return this.client.call(request); + } +} diff --git a/packages/project-client/src/services/jwt/models/access-token.ts b/packages/project-client/src/services/jwt/models/access-token.ts new file mode 100644 index 000000000..addfee85b --- /dev/null +++ b/packages/project-client/src/services/jwt/models/access-token.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const accessToken = z.lazy(() => { + return z.object({ + createdAt: z.string(), + expiresAt: z.string().optional(), + token: z.string(), + tokenId: z.string(), + }); +}); + +/** + * + * @typedef {AccessToken} accessToken + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type AccessToken = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const accessTokenResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + expires_at: z.string().optional(), + token: z.string(), + token_id: z.string(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + expiresAt: data['expires_at'], + token: data['token'], + tokenId: data['token_id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const accessTokenRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + expiresAt: z.string().nullish(), + token: z.string().nullish(), + tokenId: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + expires_at: data['expiresAt'], + token: data['token'], + token_id: data['tokenId'], + })); +}); diff --git a/packages/project-client/src/services/jwt/models/create-project-token-request.ts b/packages/project-client/src/services/jwt/models/create-project-token-request.ts new file mode 100644 index 000000000..9d79b81fa --- /dev/null +++ b/packages/project-client/src/services/jwt/models/create-project-token-request.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const createProjectTokenRequest = z.lazy(() => { + return z.object({ + expiry: z.number().gte(1).optional(), + name: z.string().max(255), + }); +}); + +/** + * + * @typedef {CreateProjectTokenRequest} createProjectTokenRequest + * @property {number} - The duration for which the token is valid (in seconds) + * @property {string} - The name of the token. + */ +export type CreateProjectTokenRequest = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const createProjectTokenRequestResponse = z.lazy(() => { + return z + .object({ + expiry: z.number().gte(1).optional(), + name: z.string().max(255), + }) + .transform((data) => ({ + expiry: data['expiry'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const createProjectTokenRequestRequest = z.lazy(() => { + return z.object({ expiry: z.number().nullish(), name: z.string().nullish() }).transform((data) => ({ + expiry: data['expiry'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/jwt/models/create-user-token-request.ts b/packages/project-client/src/services/jwt/models/create-user-token-request.ts new file mode 100644 index 000000000..723e55db7 --- /dev/null +++ b/packages/project-client/src/services/jwt/models/create-user-token-request.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const createUserTokenRequest = z.lazy(() => { + return z.object({ + email: z.string().max(255).optional(), + expiry: z.number().gte(1).optional(), + externalId: z.string().max(255).optional(), + name: z.string().max(255).optional(), + }); +}); + +/** + * + * @typedef {CreateUserTokenRequest} createUserTokenRequest + * @property {string} - The user's email. + * @property {number} - The duration for which the token is valid (in seconds) + * @property {string} - A unique string that MagicBell can utilize to identify the user uniquely. We recommend setting this attribute to the ID of the user in your database. Provide the external id if the user's email is unavailable. + * @property {string} - The name of the token. + */ +export type CreateUserTokenRequest = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const createUserTokenRequestResponse = z.lazy(() => { + return z + .object({ + email: z.string().max(255).optional(), + expiry: z.number().gte(1).optional(), + external_id: z.string().max(255).optional(), + name: z.string().max(255).optional(), + }) + .transform((data) => ({ + email: data['email'], + expiry: data['expiry'], + externalId: data['external_id'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const createUserTokenRequestRequest = z.lazy(() => { + return z + .object({ + email: z.string().nullish(), + expiry: z.number().nullish(), + externalId: z.string().nullish(), + name: z.string().nullish(), + }) + .transform((data) => ({ + email: data['email'], + expiry: data['expiry'], + external_id: data['externalId'], + name: data['name'], + })); +}); diff --git a/packages/project-client/src/services/jwt/models/discard-token-response.ts b/packages/project-client/src/services/jwt/models/discard-token-response.ts new file mode 100644 index 000000000..e5b899351 --- /dev/null +++ b/packages/project-client/src/services/jwt/models/discard-token-response.ts @@ -0,0 +1,46 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const discardTokenResponse = z.lazy(() => { + return z.object({ + discardedAt: z.string(), + tokenId: z.string(), + }); +}); + +/** + * + * @typedef {DiscardTokenResponse} discardTokenResponse + * @property {string} + * @property {string} + */ +export type DiscardTokenResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const discardTokenResponseResponse = z.lazy(() => { + return z + .object({ + discarded_at: z.string(), + token_id: z.string(), + }) + .transform((data) => ({ + discardedAt: data['discarded_at'], + tokenId: data['token_id'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const discardTokenResponseRequest = z.lazy(() => { + return z.object({ discardedAt: z.string().nullish(), tokenId: z.string().nullish() }).transform((data) => ({ + discarded_at: data['discardedAt'], + token_id: data['tokenId'], + })); +}); diff --git a/packages/project-client/src/services/jwt/models/fetch-tokens-response.ts b/packages/project-client/src/services/jwt/models/fetch-tokens-response.ts new file mode 100644 index 000000000..bff89076e --- /dev/null +++ b/packages/project-client/src/services/jwt/models/fetch-tokens-response.ts @@ -0,0 +1,43 @@ +import { z } from 'zod'; + +import { tokens, tokensRequest, tokensResponse } from './tokens'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const fetchTokensResponse = z.lazy(() => { + return z.object({ + tokens: z.array(tokens), + }); +}); + +/** + * + * @typedef {FetchTokensResponse} fetchTokensResponse + * @property {Tokens[]} + */ +export type FetchTokensResponse = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const fetchTokensResponseResponse = z.lazy(() => { + return z + .object({ + tokens: z.array(tokensResponse), + }) + .transform((data) => ({ + tokens: data['tokens'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const fetchTokensResponseRequest = z.lazy(() => { + return z.object({ tokens: z.array(tokensRequest).nullish() }).transform((data) => ({ + tokens: data['tokens'], + })); +}); diff --git a/packages/project-client/src/services/jwt/models/index.ts b/packages/project-client/src/services/jwt/models/index.ts new file mode 100644 index 000000000..509e18f30 --- /dev/null +++ b/packages/project-client/src/services/jwt/models/index.ts @@ -0,0 +1,6 @@ +export type { AccessToken } from './access-token'; +export type { CreateProjectTokenRequest } from './create-project-token-request'; +export type { CreateUserTokenRequest } from './create-user-token-request'; +export type { DiscardTokenResponse } from './discard-token-response'; +export type { FetchTokensResponse } from './fetch-tokens-response'; +export type { Tokens } from './tokens'; diff --git a/packages/project-client/src/services/jwt/models/tokens.ts b/packages/project-client/src/services/jwt/models/tokens.ts new file mode 100644 index 000000000..2c29a56eb --- /dev/null +++ b/packages/project-client/src/services/jwt/models/tokens.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; + +/** + * The shape of the model inside the application code - what the users use + */ +export const tokens = z.lazy(() => { + return z.object({ + createdAt: z.string(), + expiresAt: z.string().optional(), + id: z.string().optional(), + name: z.string().optional(), + }); +}); + +/** + * + * @typedef {Tokens} tokens + * @property {string} + * @property {string} + * @property {string} + * @property {string} + */ +export type Tokens = z.infer; + +/** + * The shape of the model mapping from the api schema into the application shape. + * Is equal to application shape if all property names match the api schema + */ +export const tokensResponse = z.lazy(() => { + return z + .object({ + created_at: z.string(), + expires_at: z.string().optional(), + id: z.string().optional(), + name: z.string().optional(), + }) + .transform((data) => ({ + createdAt: data['created_at'], + expiresAt: data['expires_at'], + id: data['id'], + name: data['name'], + })); +}); + +/** + * The shape of the model mapping from the application shape into the api schema. + * Is equal to application shape if all property names match the api schema + */ +export const tokensRequest = z.lazy(() => { + return z + .object({ + createdAt: z.string().nullish(), + expiresAt: z.string().nullish(), + id: z.string().nullish(), + name: z.string().nullish(), + }) + .transform((data) => ({ + created_at: data['createdAt'], + expires_at: data['expiresAt'], + id: data['id'], + name: data['name'], + })); +}); From a767d7f786a3dd7cb07043cf6efc81d3f292af03 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 10:38:12 +0200 Subject: [PATCH 10/12] chore: regen --- .../docs/services/BroadcastsService.md | 58 ++++++++----------- .../docs/services/IntegrationsService.md | 26 ++++----- .../src/services/broadcasts/Broadcasts.ts | 17 +----- .../src/services/broadcasts/request-params.ts | 4 -- .../src/services/channels/Channels.ts | 1 + .../src/services/integrations/Integrations.ts | 1 + 6 files changed, 41 insertions(+), 66 deletions(-) delete mode 100644 packages/project-client/src/services/broadcasts/request-params.ts diff --git a/packages/project-client/docs/services/BroadcastsService.md b/packages/project-client/docs/services/BroadcastsService.md index 3e17416fd..6144365d5 100644 --- a/packages/project-client/docs/services/BroadcastsService.md +++ b/packages/project-client/docs/services/BroadcastsService.md @@ -15,13 +15,6 @@ Returns a list of broadcasts - HTTP Method: `GET` - Endpoint: `/broadcasts` -**Parameters** - -| Name | Type | Required | Description | -| :------ | :----- | :------- | :-------------------------------------------------------- | -| page | number | ❌ | The page number of the paginated response. Defaults to 1. | -| perPage | number | ❌ | The number of items per page. Defaults to 20. | - **Return Type** `BroadcastListResponse` @@ -36,10 +29,7 @@ import { Client } from '@magicbell/project-client'; token: 'YOUR_TOKEN', }); - const { data } = await client.broadcasts.listBroadcasts({ - page: 8, - perPage: 2, - }); + const { data } = await client.broadcasts.listBroadcasts(); console.log(data); })(); @@ -73,39 +63,39 @@ import { Broadcast, Client } from '@magicbell/project-client'; }); const email: Email = { - actionUrl: 'nisi ea Duis ipsum', - content: 'commodo', - title: 'enim', + actionUrl: 'ipsum esse', + content: 'sit veniam', + title: 'in id ex aliqua', }; const inApp: InApp = { - actionUrl: 'commodo reprehenderit', - content: 'aliqua occaecat', - title: 'amet', + actionUrl: 'ullamco labore voluptate', + content: 'consequat magna Excepteur dolor mollit', + title: 'irure', }; const mobilePush: MobilePush = { - actionUrl: 'essead consectetur elit', - content: 'nostrud aliqua sed irure', - title: 'enim dolore', + actionUrl: 'elitdolore adipisicing anim elit deserunt', + content: 'cupidatat elit', + title: 'ut', }; const slack: Slack = { - actionUrl: 'id non occaecat cupidatat ad', - content: 'nostrud', - title: 'laborum commodo magna', + actionUrl: 'sit commodo consectetur Duis', + content: 'proident sed quis Lorem', + title: 'magna reprehenderit ut deserunt nisi', }; const sms: Sms = { - actionUrl: 'exdolore elit', - content: 'Excepteur occaecat eu ipsum', - title: 'in', + actionUrl: 'irure Excepteur exercitation', + content: 'et adipisicing in elit', + title: 'sint voluptate ipsum cupidatat', }; const webPush: WebPush = { - actionUrl: 'ipsum magna', - content: 'eiusmod', - title: 'cupidatat Lorem sed', + actionUrl: 'dolor in elit id', + content: 'est ea elit exercitation dolore', + title: 'aute eiusmod ea', }; const channels: Channels = { @@ -133,14 +123,14 @@ import { Broadcast, Client } from '@magicbell/project-client'; }; const broadcast: Broadcast = { - actionUrl: 'sed incididunt', - category: 'non officia', - content: 'qui enim sunt ea dolor', + actionUrl: 'Ut aliquip est laboris', + category: 'sint in eu tempor magna', + content: 'aliqua ad dolor officia', customAttributes: {}, overrides: overrides, recipients: [{}], - title: 'quis fugiat', - topic: 'mollit ut consecte', + title: 'nisi elit amet laboris tempor', + topic: 'nulla consequat do incididunt', }; const { data } = await client.broadcasts.createBroadcast(input); diff --git a/packages/project-client/docs/services/IntegrationsService.md b/packages/project-client/docs/services/IntegrationsService.md index b016b10dd..628fdfb8a 100644 --- a/packages/project-client/docs/services/IntegrationsService.md +++ b/packages/project-client/docs/services/IntegrationsService.md @@ -136,11 +136,11 @@ import { ApnsConfig, Client } from '@magicbell/project-client'; const badge = Badge.UNREAD; const apnsConfig: ApnsConfig = { - appId: 'Fd8+9', + appId: 'iAYqMy12w9iGu7ff1EsX`Yd7Od!5pFmfIMNCPzvFgZiCEg+ihR0u2bAgXQlSqFd8hh', badge: badge, certificate: 'certificate', - keyId: 'magna nost', - teamId: 'officia oc', + keyId: 'nostrud ul', + teamId: 'ut reprehe', }; const { data } = await client.integrations.saveApnsIntegration(input); @@ -368,7 +368,7 @@ import { Client, GithubConfig } from '@magicbell/project-client'; }); const githubConfig: GithubConfig = { - webhookSigningSecret: 'dolore', + webhookSigningSecret: 'adipisicing', }; const { data } = await client.integrations.saveGithubIntegration(input); @@ -477,7 +477,7 @@ import { Client, InboxConfig } from '@magicbell/project-client'; const inboxConfig: InboxConfig = { images: {}, - locale: 'qui', + locale: 'dolore moll', theme: {}, }; @@ -588,8 +588,8 @@ import { Client, MailgunConfig } from '@magicbell/project-client'; const mailgunConfigRegion = MailgunConfigRegion.US; const mailgunConfig: MailgunConfig = { - apiKey: 'co', - domain: 'm', + apiKey: 'molli', + domain: 'do ', region: mailgunConfigRegion, }; @@ -698,7 +698,7 @@ import { Client, PingConfig } from '@magicbell/project-client'; }); const pingConfig: PingConfig = { - url: 'ut cupidatat', + url: 'laboris Duis', }; const { data } = await client.integrations.savePingEmailIntegration(input); @@ -931,11 +931,11 @@ import { Client, SesConfig } from '@magicbell/project-client'; }; const sesConfig: SesConfig = { - endpoint: 'sit ipsum', + endpoint: 'dolor e', from: sesConfigFrom, - keyId: 'ex ', - region: 'in repr', - secretKey: 'ali', + keyId: 'cillum no', + region: 'dolor culpa co', + secretKey: 'pa', }; const { data } = await client.integrations.saveSesIntegration(input); @@ -1043,7 +1043,7 @@ import { Client, SlackConfig } from '@magicbell/project-client'; }); const slackConfig: SlackConfig = { - appId: 'X2ZNPXG8L', + appId: '6SX2ZNPXG8L', clientId: '430411624.02717865207', clientSecret: 'labore in ea fugiat magnainsed v', id: 'CM0mBN', diff --git a/packages/project-client/src/services/broadcasts/Broadcasts.ts b/packages/project-client/src/services/broadcasts/Broadcasts.ts index 6c9e4d0c7..ad711f5da 100644 --- a/packages/project-client/src/services/broadcasts/Broadcasts.ts +++ b/packages/project-client/src/services/broadcasts/Broadcasts.ts @@ -1,23 +1,18 @@ import { z } from 'zod'; +import { SerializationStyle } from '../../http/serialization/base-serializer'; import { RequestBuilder } from '../../http/transport/request-builder'; import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; import { BaseService } from '../base-service'; import { Broadcast, broadcastRequest, broadcastResponse } from './models/broadcast'; import { BroadcastListResponse, broadcastListResponseResponse } from './models/broadcast-list-response'; -import { ListBroadcastsParams } from './request-params'; export class BroadcastsService extends BaseService { /** * Returns a list of broadcasts - * @param {number} [page] - The page number of the paginated response. Defaults to 1. - * @param {number} [perPage] - The number of items per page. Defaults to 20. * @returns {Promise>} OK */ - async listBroadcasts( - params?: ListBroadcastsParams, - requestConfig?: RequestConfig, - ): Promise> { + async listBroadcasts(requestConfig?: RequestConfig): Promise> { const request = new RequestBuilder() .setConfig(this.config) .setBaseUrl(this.config) @@ -30,14 +25,6 @@ export class BroadcastsService extends BaseService { .setRetryAttempts(this.config, requestConfig) .setRetryDelayMs(this.config, requestConfig) .setResponseValidation(this.config, requestConfig) - .addQueryParam({ - key: 'page', - value: params?.page, - }) - .addQueryParam({ - key: 'per_page', - value: params?.perPage, - }) .build(); return this.client.call(request); } diff --git a/packages/project-client/src/services/broadcasts/request-params.ts b/packages/project-client/src/services/broadcasts/request-params.ts deleted file mode 100644 index e191cec19..000000000 --- a/packages/project-client/src/services/broadcasts/request-params.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface ListBroadcastsParams { - page?: number; - perPage?: number; -} diff --git a/packages/project-client/src/services/channels/Channels.ts b/packages/project-client/src/services/channels/Channels.ts index 4868bef4c..00572e0d8 100644 --- a/packages/project-client/src/services/channels/Channels.ts +++ b/packages/project-client/src/services/channels/Channels.ts @@ -1,5 +1,6 @@ import { z } from 'zod'; +import { SerializationStyle } from '../../http/serialization/base-serializer'; import { RequestBuilder } from '../../http/transport/request-builder'; import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; import { BaseService } from '../base-service'; diff --git a/packages/project-client/src/services/integrations/Integrations.ts b/packages/project-client/src/services/integrations/Integrations.ts index 2cf114c90..5a130596e 100644 --- a/packages/project-client/src/services/integrations/Integrations.ts +++ b/packages/project-client/src/services/integrations/Integrations.ts @@ -1,5 +1,6 @@ import { z } from 'zod'; +import { SerializationStyle } from '../../http/serialization/base-serializer'; import { RequestBuilder } from '../../http/transport/request-builder'; import { ContentType, HttpResponse, RequestConfig } from '../../http/types'; import { BaseService } from '../base-service'; From d35e9e81cc3e7f2ce63a7142e99ccc2a87bf1daa Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 12:43:30 +0200 Subject: [PATCH 11/12] chore: ignore unused locals --- tsconfig.build.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.build.json b/tsconfig.build.json index 3a673645e..5196335fa 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -8,7 +8,7 @@ "declaration": true, "sourceMap": true, "strict": false, - "noUnusedLocals": true, + "noUnusedLocals": false, "noUnusedParameters": false, "noImplicitReturns": false, "noFallthroughCasesInSwitch": true, From 5330971c1c190e7a60be88439e60551b7a553ea0 Mon Sep 17 00:00:00 2001 From: Stephan Meijer Date: Fri, 23 Aug 2024 13:40:50 +0200 Subject: [PATCH 12/12] chore: fix case --- .../project-client/src/http/{Environment.ts => environment.ts} | 0 .../src/services/broadcasts/{Broadcasts.ts => broadcasts.ts} | 0 .../src/services/broadcasts/models/{Broadcast.ts => broadcast.ts} | 0 .../src/services/channels/{Channels.ts => channels.ts} | 0 .../services/integrations/{Integrations.ts => integrations.ts} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename packages/project-client/src/http/{Environment.ts => environment.ts} (100%) rename packages/project-client/src/services/broadcasts/{Broadcasts.ts => broadcasts.ts} (100%) rename packages/project-client/src/services/broadcasts/models/{Broadcast.ts => broadcast.ts} (100%) rename packages/project-client/src/services/channels/{Channels.ts => channels.ts} (100%) rename packages/project-client/src/services/integrations/{Integrations.ts => integrations.ts} (100%) diff --git a/packages/project-client/src/http/Environment.ts b/packages/project-client/src/http/environment.ts similarity index 100% rename from packages/project-client/src/http/Environment.ts rename to packages/project-client/src/http/environment.ts diff --git a/packages/project-client/src/services/broadcasts/Broadcasts.ts b/packages/project-client/src/services/broadcasts/broadcasts.ts similarity index 100% rename from packages/project-client/src/services/broadcasts/Broadcasts.ts rename to packages/project-client/src/services/broadcasts/broadcasts.ts diff --git a/packages/project-client/src/services/broadcasts/models/Broadcast.ts b/packages/project-client/src/services/broadcasts/models/broadcast.ts similarity index 100% rename from packages/project-client/src/services/broadcasts/models/Broadcast.ts rename to packages/project-client/src/services/broadcasts/models/broadcast.ts diff --git a/packages/project-client/src/services/channels/Channels.ts b/packages/project-client/src/services/channels/channels.ts similarity index 100% rename from packages/project-client/src/services/channels/Channels.ts rename to packages/project-client/src/services/channels/channels.ts diff --git a/packages/project-client/src/services/integrations/Integrations.ts b/packages/project-client/src/services/integrations/integrations.ts similarity index 100% rename from packages/project-client/src/services/integrations/Integrations.ts rename to packages/project-client/src/services/integrations/integrations.ts