1.0.1 • Published 2 years ago
@cogsworthdev/embed-sdk-node v1.0.1
Cogsworth Embed App Backend SDK
The Cogsworth Embed App SDK allows Cogsworth partners to embed the Cogsworth Embed application in their own sites with minimal configuration.
Installation
npm install @cogsworthdev/embed-sdk-node
# or
yarn add @cogsworthdev/embed-sdk-node
Usage
In order to securely generate a signed payload, it is required that you set up an endpoint in your backend. Your client application can then consume this endpoint to render the embed application.
The package needs to be configured with your Cogsworth account ID and API key, which you can find in your Cogsworh Dashboard:
import CogsworthSDK from '@cogsworth4/embed-sdk-node'
const cogsworth = new CogsworthSDK({
partnerId: 'xxxxx',
apiKey: 'xxxxxx',
})
You can then use the SDK to generate a secure payload:
const payload = cogsworth.generateClientPayload({
user: {
id: 'xxxxxxxx',
email: 'user@example.com',
name: 'Dr. Test User',
},
business: {
id: 'xxxxxxxx',
name: 'Example Business',
timezone: 'Sydney/Australia',
userRole: 'OWNER',
location: 'https://partner.com/room/xxxxxxxx',
},
})
Payload data
The payload needs to contain a user
and a business
objects, which require the following details:
User
user.id
- A unique identifier for the user in your systemuser.email
- Emails are unique for each useruser.name
- The user name
Business
business.id
- A unique identifier for the user in your systembusiness.name
- The business namebusiness.timezone
- See a List of possible timezones.business.userRole
- The role for the provided user in this business. Can be one of the following:"OWNER"
: The business owner. Has full access to the business. Cogsworth can provision new businesses for owners only."ADMIN"
: The business owner. Has full access to the business."STAFF"
: Has limited access. Cannot change business settings and can only see their own appointments.
business.location
-Optional- The default location for the business appointments. If the value starts with https, it will be detected as a URL.
Full example
const handler = (req, res) => {
const cogsworth = new CogsworthSDK({
partnerId: "xxxxxxxx",
apiKey: "xxxxxxxx",
});
const clientPayload = cogsworth.generateClientPayload({
user: {
id: "xxxxxxxx",
email: "user@example.com",
name: "Dr. Test User",
},
business: {
id: "xxxxxxxx",
name: "Example Business",
timezone: "Sydney/Australia",
userRole: "OWNER",
location: "https://www.partner.com/room/xxxxxxxx",
});
res.send(clientPayload);
};