My App

TypeScript Types

TypeScript type definitions for the Unchange SDK

UnchangeOptions

Configuration options for initializing the SDK.

interface UnchangeOptions {
  apiKey: string;
  projectId: string;
  baseUrl?: string;
}

Properties

  • apiKey (string): Your API key for authentication
  • projectId (string): Your project ID
  • baseUrl (string, optional): Custom base URL for the API. Defaults to https://dev.untraceable.dev

Changelog

Represents a changelog entry.

interface Changelog {
  _id: string;
  _creationTime: number;
  title: string;
  content: string;
  projectId: string;
}

Properties

  • _id (string): Unique identifier for the changelog
  • _creationTime (number): Unix timestamp (milliseconds) when the changelog was created
  • title (string): The changelog title
  • content (string): The changelog content/description
  • projectId (string): The project this changelog belongs to

Example

const changelog: Changelog = {
  _id: "changelog-abc123",
  _creationTime: 1704067200000,
  title: "Version 2.0 Released",
  content: "We're excited to announce the release of version 2.0...",
  projectId: "project-xyz"
};

ChangelogWithSeenStatus

Extends Changelog with user-specific seen status.

interface ChangelogWithSeenStatus extends Changelog {
  seen: boolean;
}

Properties

Includes all properties from Changelog plus:

  • seen (boolean): Whether the user has seen/acknowledged this changelog

Example

const userChangelog: ChangelogWithSeenStatus = {
  _id: "changelog-abc123",
  _creationTime: 1704067200000,
  title: "Version 2.0 Released",
  content: "We're excited to announce...",
  projectId: "project-xyz",
  seen: false
};

CreateUserResponse

Response returned when creating a user.

interface CreateUserResponse {
  message: string;
}

Properties

  • message (string): Success message confirming user creation

Example

const response: CreateUserResponse = {
  message: "User created successfully"
};

Type Usage Examples

Strongly Typed Function

import type { Changelog, ChangelogWithSeenStatus } from 'unchange-sdk';

async function displayUserChangelog(
  userId: string
): Promise<ChangelogWithSeenStatus | null> {
  try {
    const changelog = await client.changelogs.getLatestForUser(userId);
    return changelog;
  } catch (error) {
    console.error('Error fetching changelog:', error);
    return null;
  }
}

Type Guards

function isChangelogWithSeenStatus(
  changelog: Changelog | ChangelogWithSeenStatus
): changelog is ChangelogWithSeenStatus {
  return 'seen' in changelog;
}

const data = await client.changelogs.getLatestForUser('user-123');
if (isChangelogWithSeenStatus(data)) {
  console.log('Seen status:', data.seen);
}

Partial Types

import type { Changelog } from 'unchange-sdk';

// Using Partial for updates (hypothetical)
type ChangelogUpdate = Partial<Pick<Changelog, 'title' | 'content'>>;

const update: ChangelogUpdate = {
  title: "Updated Title"
};

On this page