@swytchboard/client-sdk-ts v0.7.2
Client SDK of Swytchboard
Usage from CDN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Using CDN</title>
</head>
<body>
<div id="app">
Using CDN (jsdelivr or unpkg) to load Swytchboard Client SDK
</div>
<script src="https://cdn.jsdelivr.net/npm/@swytchboard/client-sdk-ts@0.3.0/dist/iife/index.js">
</script>
<!-- <script src="https://unpkg.com/@swytchboard/client-sdk-ts@0.3.0/dist/iife/index.js"></script> -->
<script>
const { Company } = swytchboard;
(async function () {
const { available } = await Company.available('entrypointId')
const { config } = await Company.getServiceConfig('entrypointId')
console.log({ available, config });
})();
</script>
</body>
</html>Usage from npm package
npm i @swytchboard/client-sdk-ts- Please make sure if type of module is
esmorcommonjsin your project, check packake.json file. - Add .npmrc file in your project root directory with following content. We will provide you NPM token for you or have access to generate one by yourself.
@swytchboard:registry-url:https://registry.npmjs.org/
//registry.npmjs.org/:_authToken={NPM_TOKEN}- ES Modules
import { Company } from "@swytchboard/client-sdk-ts";
async function main() {
try {
const isAvailable = await Company.available('entrypointId');
console.log(isAvailable);
} catch (error) {
console.log(error);
}
}
main();- CommonJS
const sb = require("@swytchboard/client-sdk-ts");
async function main() {
try {
const isAvailable = await sb.Company.available("entrypointId");
console.log(isAvailable);
} catch (error) {
console.log(error);
}
}
main();Installation
yarn start:browserThis builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.
To do a one-off build, use npm run build or yarn build.
To run tests, use npm test or yarn test.
Configuration
Code quality is set up for you with prettier, husky, and lint. Adjust the respective fields in package.json accordingly.
Jest
Jest tests are set up to run with npm test or yarn test.
Bundle Analysis
size-limit is set up to calculate the real cost of your library with npm run size and visualize the bundle with npm run analyze.
Esbuild
We use Esbuild as a bundler and generates multiple esbuild configs for various module formats and build settings.
TypeScript
tsconfig.json is set up to interpret dom and esnext types. Adjust according to your needs.
GitHub Actions
Two actions are added by default:
mainwhich installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrixsizewhich comments cost comparison of your library on every pull request usingsize-limit
Module Formats
CJS, ESModules, and IIFE module formats are supported.
The appropriate paths are configured in package.json and dist/index.js accordingly. Please report if any issues are found.
Publishing
This project is set up to publish to NPM using npm publish or yarn publish. Adjust the package.json accordingly.