@adstage/web-sdk
Version:
AdStage Web SDK - Production-ready marketing platform SDK with React Provider support for seamless integration
93 lines (79 loc) • 1.94 kB
text/typescript
/**
* AdStage SDK 엔드포인트 상수 관리
* 모든 API URL을 중앙에서 관리
*/
/**
* 환경별 API 엔드포인트 (읽기 전용)
*/
export const API_ENDPOINTS = {
/** 프로덕션 환경 */
production: 'https://api.adstage.app',
/** 베타 환경 (기본값) */
beta: 'https://beta-api.adstage.app'
} as const;
/**
* 기본 엔드포인트 (프로덕션 환경)
*/
export const DEFAULT_API_ENDPOINT = API_ENDPOINTS.production;
/**
* API 경로 상수
*/
export const API_PATHS = {
/** 광고 관련 */
advertisements: {
list: '/advertisements/list',
detail: '/advertisements',
events: '/advertisements/events'
},
/** 이벤트 관련 */
events: {
track: '/events/track',
}
} as const;
/**
* 완전한 API URL 생성 헬퍼
*/
export class EndpointBuilder {
private baseUrl: string;
constructor(baseUrl?: string) {
// 기본값은 베타 환경 사용
this.baseUrl = baseUrl || API_ENDPOINTS.production;
}
/**
* 기본 URL 변경
*/
setBaseUrl(url: string): void {
this.baseUrl = url;
}
/**
* 기본 URL 반환
*/
getBaseUrl(): string {
return this.baseUrl;
}
/**
* 광고 엔드포인트
*/
advertisements = {
list: () => `${this.baseUrl}${API_PATHS.advertisements.list}`,
detail: (adId: string) => `${this.baseUrl}${API_PATHS.advertisements.detail}/${adId}`,
events: (adId: string, eventType: string) =>
`${this.baseUrl}${API_PATHS.advertisements.events}/${adId}/${eventType}`
};
/**
* 이벤트 엔드포인트
*/
events = {
track: () => `${this.baseUrl}${API_PATHS.events.track}`,
};
/**
* 커스텀 경로 생성
*/
custom(path: string): string {
return `${this.baseUrl}${path.startsWith('/') ? path : `/${path}`}`;
}
}
/**
* 전역 엔드포인트 빌더 인스턴스 (기본: 베타 환경)
*/
export const endpoints = new EndpointBuilder();