JS Quickstart

The @cloudterms/js (opens in a new tab) package provides a type-safe SDK for interacting with the CloudTerms API.

Example (opens in a new tab)

Setup

Install @cloudterms/js

npm install @cloudterms/js

Set your environment variables

# Your application ID
CLOUDTERMS_APP_ID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Your application secret
CLOUDTERMS_APP_SECRET="sk_live.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Usage

import { CloudTerms } from '@cloudterms/js'
 
// Initialize the SDK
const cloudterms = CloudTerms()
// You can also pass in your application ID and secret, this will override the environment variables
const cloudterms2 = CloudTerms({ appId: 'my-app-id', secret: 'my-app-secret' })
 
// Get all your applications terms
const terms = await cloudterms.terms.get()
 
// Check if a user has agreed to the latest terms
const hasAgreed = await cloudterms.user.hasAgreed('some-unique-user-id')
 
// Set that a user has agreed to the latest terms
const setAgreed = await cloudterms.user.setAgreed('some-unique-user-id')

Methods

CloudTerms().terms.get()

Get all your applications terms

Response:

{
  terms: [
    {
      id: number
      applicationId: string // Your application ID
      name: string // Name of the term
      userId: string // Unique user ID provided by your application
      orgId: string | null // Your organization ID in CloudTerms, if applicable
      termId: string
      content: string // HTML content of the term
      createdAt: Date
      updatedAt: Date
    }
  ]
}

CloudTerms().user.hasAgreed(userId: string)

Check if a user has agreed to the latest terms

Parameters:

{
  userId: string // Unique user ID provided by your application
}

Response:

{
  hasAgreed: boolean
}

CloudTerms().user.setAgreed(userId: string)

Set that a user has agreed to the latest terms

Parameters:

{
  userId: string // Unique user ID provided by your application
}

Response:

{
  userId: string
  applicationId: string
  lastAgreed: Date | null // Date the user last agreed to the terms, or null if they have never agreed
}