Initialization
Mission
The Thinking Differently SDK acts as a developer-friendly client wrapper around our REST APIs. It handles all authentication headers, payload serialization, and filters automatically.
The Payoff
By completing this module, you will successfully integrate the official library, initialize a connection workspace, and understand the scope of the three-key design.
Estimated Time: 3 minutesModules: 4 Concepts
Select your project workspace
Open your terminal in the directory where your project resides.
Run the installation command
Download the core packages using npm for Node.js, or pip for Python environments.
Interactive Code Snippet
bash
npm install @thinkingdifferently/coreConfigure the initialization parameters
Define the core attributes such as apiKey. You can optionally define the securityKey or publicKey.
Instantiate the client class
Call new ThinkingDifferently() in Node.js, or initialize the dictionary-configured object in Python.
Interactive Code Snippet
lib/td.ts
import { ThinkingDifferently } from "@thinkingdifferently/core";export const sdk = new ThinkingDifferently({ apiKey: "td_api_your_public_client_key", // securityKey: "td_security_your_secret_server_key", // Optional: server-side only // publicKey: "your_public_pem_key" // Optional: for offline JWT verification});Thinking Differently uses three distinct security keys to balance backend performance with front-end browser isolation:
| Key Name | Location | Scope | Purpose |
|---|---|---|---|
| apiKey | Frontend / Backend | Read-only (`find`, `count`) | Safe for browsers; restricts write operations by default. |
| securityKey | Backend only | Read & Write | Admin bypass key. Never expose this key to client-side code. |
| publicKey | Frontend / Backend | JWT Verify | Used to perform secure, offline Ed25519 token signatures checks. |
Select your language flow
Toggle tabs to view typical flows for browser logins or server mutations.
Validate flow paths
Ensure your credentials correspond to client-side login tokens or environment keys.
Interactive Code Snippet
Scenario A: Browser Flow (Cookie Session Auth)
Only initialize with the public client key `apiKey`. Mutating database operations are locked unless authenticated.
typescript
import { sdk } from "./lib/td";// 1. Authenticate (returns session info, sets secure session cookies)const session = await sdk.auth.admin.credentials("[email protected]", "secure-password");// 2. Load token manually on frontendsdk.auth.admin.setToken(session.token);// 3. Write mutations are now authorizedawait sdk.collection("products").insert({ name: "Phone", price: 699 });Scenario B: Server-Side Flow (Secret Keys Auth)
Initialize with both `apiKey` and `securityKey` to grant immediate administrative writes from backend environments.
typescript
import { ThinkingDifferently } from "@thinkingdifferently/core";const sdk = new ThinkingDifferently({ apiKey: "td_api_your_public_client_key", securityKey: "td_security_your_secret_server_key" // Keeps credentials secure in environment variables});// Mutate data directlyawait sdk.collection("logs").insert({ event: "server_up", timestamp: Date.now() });