Skip to main content

SourceSync-App

The Main SDK is the core component of the SourceSync platform. It handles initialization, configuration, and provides access to fundamental features.

Installation​

npm install sourcesync-sdk

Initialization​

To use the SourceSync SDK, you must first initialize it with your app key:

import { initializeApp } from 'sourcesync-sdk/app';

const app = await initializeApp({
appKey: 'YOUR_API_KEY',
env: 'prod' // or 'dev' for development
});

Key Concepts​

App Instance​

The app object returned by initializeApp is your main point of interaction with the SourceSync SDK. It provides access to various services and configurations.

Environment​

The env parameter in the initialization config determines whether you're working in a development or production environment. This affects things like error logging and API endpoints.

API Reference​

initializeApp(config: SourceSyncConfig): Promise<SourceSyncApp>​

Initializes the SourceSync SDK.

Parameters:

  • config: An object containing:
    • appKey: Your SourceSync API key
    • env: 'prod' or 'dev'

Returns: A Promise that resolves to a SourceSyncApp instance.

SourceSyncApp​

Properties:

  • config: The configuration used to initialize the app.

Methods:

  • getActivation(id: string): Promise<Activation>: Retrieves an activation by ID.
  • getCurrentEnvironment(): string: Returns the current environment ('prod' or 'dev').

Best Practices​

  1. Store your API key in environment variables for security.
  2. Initialize the SDK as early as possible in your application lifecycle.
  3. Use try-catch blocks when initializing to handle potential errors.

Example Usage​

import { initializeApp } from 'sourcesync-sdk/app';

async function setupSourceSync() {
try {
const app = await initializeApp({
appKey: process.env.SOURCESYNC_API_KEY,
env: process.env.NODE_ENV === 'production' ? 'prod' : 'dev'
});

console.log('SourceSync initialized in', app.getCurrentEnvironment(), 'environment');

// Use the app instance for further operations
const activation = await app.getActivation('some-activation-id');
// ...
} catch (error) {
console.error('Failed to initialize SourceSync:', error);
}
}

setupSourceSync();

For more advanced usage and integration with other SourceSync libraries, refer to the Moment and Render library documentation.