frenv SDK

JavaScript SDK for frenv.pe.kr microservices. Easily integrate authentication, configuration, and internationalization into your web applications.

Installation

Include the SDK via CDN or install via npm.

CDN (Recommended)

<script src="https://cdn.frenv.pe.kr/sdk.js"></script>

ES Module

import { FrenvSDK } from 'https://cdn.frenv.pe.kr/sdk.mjs';

Available Files

File Type Size
sdk.js CommonJS 16 KB
sdk.mjs ES Module 15 KB
sdk.d.ts TypeScript 8 KB

Quick Start

Initialize the SDK and start using frenv services in minutes.

Live Example
// Initialize SDK
const sdk = new FrenvSDK();
await sdk.ready();

// Set theme
await sdk.setTheme('dark');

// Load translations
const t = await sdk.loadTranslations(['common']);
console.log(t('common.hello'));
Output
> SDK initialized
> Theme set to: dark
> "Hello, World!"

SDK Initialization

Create a new SDK instance with optional configuration.

new FrenvSDK(options?)

Creates a new SDK instance.

options.authUrl
Auth service URL (default: https://auth.frenv.pe.kr)
options.configUrl
Config service URL (default: https://config.frenv.pe.kr)
const sdk = new FrenvSDK({
  authUrl: 'https://auth.frenv.pe.kr',
  configUrl: 'https://config.frenv.pe.kr'
});

// Wait for SDK to be ready
await sdk.ready();

// Access individual clients
sdk.auth    // AuthClient
sdk.config  // ConfigClient
sdk.i18n    // I18nClient

Auth Client

Handle user authentication, registration, and session management.

sdk.register(email, password, name?)

Register a new user account. SDK-level method that auto-updates user state.

email
User's email address
password
User's password
name
Optional display name
// SDK-level (recommended)
const result = await sdk.register(
  'user@example.com',
  'securePassword123',
  'John Doe'
);

if (result.success) {
  console.log('Registered:', result.user);
  console.log(sdk.isLoggedIn()); // true
}

sdk.login(email, password)

Login with email and password. Auto-updates SDK user state and config.

Login Example
// SDK-level login (recommended)
const result = await sdk.login(
  'user@example.com',
  'password123'
);

if (result.success) {
  console.log('Welcome!', result.user.name);
  // User state auto-updated
  console.log(sdk.getUser());
}
Output
> "Welcome!" "John Doe"
> { id: "...", email: "user@example.com", ... }

sdk.logout()

Logout the current user and clear SDK state.

await sdk.logout();
console.log(sdk.isLoggedIn()); // false
console.log(sdk.getUser());     // null

sdk.getUser() / sdk.isLoggedIn()

Get cached user object or check login status (synchronous).

// Check login status (sync)
if (sdk.isLoggedIn()) {
  const user = sdk.getUser();
  console.log('Current user:', user.email);
  console.log('Plan:', user.plan);
} else {
  console.log('Please login');
}

// For fresh user data, use auth client
const freshUser = await sdk.auth.getUser();

Config Client

Manage user preferences like theme and language settings.

sdk.getConfig()

Get the full user configuration including theme and language.

const config = await sdk.getConfig();

console.log(config.theme);    // { id: 'dark', name: 'Dark', ... }
console.log(config.language); // { code: 'ko', name: 'Korean', ... }
console.log(config.config);   // { theme: 'dark', language: 'ko', updatedAt: '...' }

sdk.setTheme(theme) / sdk.getTheme()

Set or get the user's theme preference.

theme
'light' | 'dark' | 'system' | custom theme id
Theme Example
// Set dark theme
await sdk.setTheme('dark');

// Get current theme (returns Theme object)
const theme = await sdk.getTheme();
console.log(theme.id);   // 'dark'
console.log(theme.name); // 'Dark Mode'
Output
> Theme saved
> "dark"
> "Dark Mode"

sdk.setLanguage(lang) / sdk.getLanguage()

Set or get the user's language preference.

lang
'ko' | 'en' | 'ja' | ...
// Set language to Korean
await sdk.setLanguage('ko');

// Get current language (synchronous)
const lang = sdk.getLanguage();
console.log(lang); // 'ko'

sdk.getThemes() / sdk.getLanguages()

Get available themes and languages.

// Get all available themes
const themes = await sdk.getThemes();
themes.forEach(t => console.log(t.name));
// "Light Mode", "Dark Mode", "System"

// Get all supported languages
const languages = await sdk.getLanguages();
languages.forEach(l => console.log(l.nativeName));
// "ν•œκ΅­μ–΄", "English", "ζ—₯本θͺž"

I18n Client

Load and use translations for internationalization.

sdk.loadTranslations(namespaces)

Load translation namespaces and return a translation function.

namespaces
Array of namespace names: ['common', 'auth', 'errors']
i18n Example
// Load translations
const t = await sdk.loadTranslations([
  'common',
  'auth'
]);

// Use translations
console.log(t('common.hello'));
console.log(t('auth.login'));

// With interpolation
console.log(t('common.welcome', {
  name: 'John'
}));
Output
> "Hello"
> "Sign In"
> "Welcome, John!"