@adstage/web-sdk 1.3.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +539 -34
  2. package/dist/index.cjs.js +753 -509
  3. package/dist/index.d.ts +286 -97
  4. package/dist/index.esm.js +737 -485
  5. package/dist/index.standalone.js +737 -485
  6. package/package.json +12 -13
  7. package/src/constants/endpoints.ts +93 -0
  8. package/src/core/AdStage.ts +128 -0
  9. package/src/index.ts +14 -432
  10. package/src/managers/{slider-manager.ts → carousel-slider-manager.ts} +9 -8
  11. package/src/managers/event-tracker.ts +2 -4
  12. package/src/managers/{fade-slider-manager.ts → text-transition-manager.ts} +7 -7
  13. package/src/modules/ads/AdsModule.ts +525 -0
  14. package/src/modules/config/ConfigModule.ts +124 -0
  15. package/src/modules/events/EventsModule.ts +106 -0
  16. package/src/types/config.ts +74 -3
  17. package/src/types/index.ts +2 -1
  18. package/src/utils/api-headers.ts +52 -0
  19. package/src/utils/dom-utils.ts +1 -1
  20. package/examples/README.md +0 -33
  21. package/examples/banner-ads.html +0 -512
  22. package/examples/index.html +0 -338
  23. package/examples/native-ads.html +0 -634
  24. package/examples/react-app/README.md +0 -70
  25. package/examples/react-app/index.html +0 -13
  26. package/examples/react-app/package-lock.json +0 -3042
  27. package/examples/react-app/package.json +0 -26
  28. package/examples/react-app/pnpm-lock.yaml +0 -1857
  29. package/examples/react-app/public/index.standalone.js +0 -2331
  30. package/examples/react-app/src/App.tsx +0 -226
  31. package/examples/react-app/src/index.css +0 -37
  32. package/examples/react-app/src/main.tsx +0 -10
  33. package/examples/react-app/tsconfig.json +0 -25
  34. package/examples/react-app/tsconfig.node.json +0 -10
  35. package/examples/react-app/vite.config.ts +0 -15
  36. package/examples/react-nextjs/app/globals.css +0 -200
  37. package/examples/react-nextjs/app/layout.tsx +0 -27
  38. package/examples/react-nextjs/app/page.tsx +0 -258
  39. package/examples/react-nextjs/next.config.js +0 -9
  40. package/examples/react-nextjs/package.json +0 -22
  41. package/examples/react-nextjs/pnpm-lock.yaml +0 -343
  42. package/examples/react-nextjs/tsconfig.json +0 -34
  43. package/examples/text-ads.html +0 -597
  44. package/examples/video-ads.html +0 -739
  45. package/src/react/components/AdErrorBoundary.tsx +0 -75
  46. package/src/react/components/AdSlot.tsx +0 -144
  47. package/src/react/components/BannerAd.tsx +0 -24
  48. package/src/react/components/InterstitialAd.tsx +0 -24
  49. package/src/react/components/NativeAd.tsx +0 -24
  50. package/src/react/components/TextAd.tsx +0 -24
  51. package/src/react/components/VideoAd.tsx +0 -24
  52. package/src/react/components/index.ts +0 -8
  53. package/src/react/hooks/index.ts +0 -4
  54. package/src/react/hooks/useAdSlot.ts +0 -83
  55. package/src/react/hooks/useAdStage.ts +0 -14
  56. package/src/react/hooks/useAdTracking.ts +0 -61
  57. package/src/react/index.ts +0 -4
  58. package/src/react/providers/AdStageProvider.tsx +0 -86
  59. package/src/react/providers/index.ts +0 -2
  60. package/src/utils/sdk-standalone.ts +0 -155
@@ -0,0 +1,106 @@
1
+ /**
2
+ * AdStage SDK - Events 모듈 (기본 구조)
3
+ * 이벤트 추적 시스템 - Q1 2025 구현 예정
4
+ */
5
+
6
+ import { AdStageConfig, BaseModule } from '../../types/config';
7
+
8
+ export interface EventProperties {
9
+ [key: string]: any;
10
+ }
11
+
12
+ export interface PageData {
13
+ page?: string;
14
+ title?: string;
15
+ category?: string;
16
+ [key: string]: any;
17
+ }
18
+
19
+ export class EventsModule implements BaseModule {
20
+ private _isReady = false;
21
+ private _config: AdStageConfig | null = null;
22
+
23
+ /**
24
+ * Events 모듈 초기화 (동기)
25
+ */
26
+ init(config: AdStageConfig): void {
27
+ this._config = config;
28
+ this._isReady = true;
29
+
30
+ if (config.debug) {
31
+ console.log('📊 Events module initialized (sync mode)');
32
+ }
33
+ }
34
+
35
+ /**
36
+ * 모듈 준비 상태 확인
37
+ */
38
+ isReady(): boolean {
39
+ return this._isReady;
40
+ }
41
+
42
+ /**
43
+ * 모듈 설정 반환
44
+ */
45
+ getConfig(): AdStageConfig | null {
46
+ return this._config;
47
+ }
48
+
49
+ // === 향후 구현 예정 메소드들 ===
50
+
51
+ /**
52
+ * 커스텀 이벤트 추적
53
+ * @example AdStage.events.track('page_view', { page: '/products' })
54
+ */
55
+ async track(eventName: string, properties?: EventProperties): Promise<void> {
56
+ console.log('🚧 [TODO] Event tracking:', { eventName, properties });
57
+ // TODO: Q1 2025 구현 예정
58
+ }
59
+
60
+ /**
61
+ * 페이지 뷰 이벤트
62
+ * @example AdStage.events.pageView({ page: '/home', title: 'Homepage' })
63
+ */
64
+ async pageView(pageData?: PageData): Promise<void> {
65
+ console.log('🚧 [TODO] Page view tracking:', pageData);
66
+ // TODO: Q1 2025 구현 예정
67
+ }
68
+
69
+ /**
70
+ * 사용자 액션 이벤트
71
+ * @example AdStage.events.userAction('button_click', { button_id: 'cta' })
72
+ */
73
+ async userAction(actionType: string, metadata?: EventProperties): Promise<void> {
74
+ console.log('🚧 [TODO] User action tracking:', { actionType, metadata });
75
+ // TODO: Q1 2025 구현 예정
76
+ }
77
+
78
+ /**
79
+ * 컨버전 이벤트
80
+ * @example AdStage.events.conversion({ type: 'purchase', value: 99.99 })
81
+ */
82
+ async conversion(conversionData: EventProperties): Promise<void> {
83
+ console.log('🚧 [TODO] Conversion tracking:', conversionData);
84
+ // TODO: Q1 2025 구현 예정
85
+ }
86
+
87
+ // === 배치 처리 (향후 구현) ===
88
+ batch = {
89
+ start: () => {
90
+ console.log('🚧 [TODO] Batch events start');
91
+ },
92
+ add: (eventName: string, properties: EventProperties) => {
93
+ console.log('🚧 [TODO] Batch events add:', { eventName, properties });
94
+ },
95
+ flush: async () => {
96
+ console.log('🚧 [TODO] Batch events flush');
97
+ }
98
+ };
99
+
100
+ // === 실시간 이벤트 (향후 구현) ===
101
+ realtime = {
102
+ track: async (eventName: string, properties: EventProperties) => {
103
+ console.log('🚧 [TODO] Realtime event tracking:', { eventName, properties });
104
+ }
105
+ };
106
+ }
@@ -1,8 +1,79 @@
1
1
  // SDK 설정 타입 정의
2
2
 
3
- // 메인 SDK 설정
4
3
  /**
5
- * SDK 설정
4
+ * AdStage SDK 모듈 타입
5
+ */
6
+ export type ModuleName = 'ads' | 'events' | 'config';
7
+
8
+ /**
9
+ * AdStage SDK 초기화 설정
10
+ */
11
+ export interface AdStageConfig {
12
+ /** API 키 (조직 정보 자동 추출) */
13
+ apiKey: string;
14
+
15
+ /** 디버그 모드 활성화 */
16
+ debug?: boolean;
17
+
18
+ /** API 기본 URL (선택사항, 기본값: 환경 자동 감지) */
19
+ baseUrl?: string;
20
+
21
+ /** 로드할 모듈 선택 (기본값: 모든 모듈) */
22
+ modules?: ModuleName[];
23
+
24
+ /** 요청 타임아웃 (ms) */
25
+ timeout?: number;
26
+
27
+ /** 초기화시 API 키 검증 여부 (기본값: false) */
28
+ validateOnInit?: boolean;
29
+
30
+ /** 네트워크 오류시 fallback 모드 사용 (기본값: true) */
31
+ fallbackMode?: boolean;
32
+
33
+ /** 오프라인 모드 (기본값: false) */
34
+ offlineMode?: boolean;
35
+
36
+ /** 프로덕션 모드 (엄격한 검증, 기본값: false) */
37
+ productionMode?: boolean;
38
+ }
39
+
40
+ /**
41
+ * 모듈 기본 인터페이스
42
+ */
43
+ export interface BaseModule {
44
+ /** 모듈 초기화 (동기) */
45
+ init(config: AdStageConfig): void;
46
+
47
+ /** 모듈 준비 상태 확인 */
48
+ isReady(): boolean;
49
+
50
+ /** 모듈 설정 반환 */
51
+ getConfig(): any;
52
+ }
53
+
54
+ /**
55
+ * API 응답 기본 타입
56
+ */
57
+ export interface ApiResponse<T = any> {
58
+ success: boolean;
59
+ data?: T;
60
+ error?: string;
61
+ message?: string;
62
+ }
63
+
64
+ /**
65
+ * 조직 정보
66
+ */
67
+ export interface OrganizationInfo {
68
+ id: string;
69
+ name: string;
70
+ slug: string;
71
+ settings: Record<string, any>;
72
+ }
73
+
74
+ // 메인 SDK 설정 (기존 호환성)
75
+ /**
76
+ * SDK 설정 (레거시)
6
77
  */
7
78
  export interface SDKConfig {
8
79
  clientId: string;
@@ -128,7 +199,7 @@ export interface ConfigValidationResult {
128
199
  // 기본 설정 값들
129
200
  export const DEFAULT_CONFIG: Required<SDKConfig> = {
130
201
  clientId: '',
131
- baseUrl: 'https://api.adstage.io',
202
+ baseUrl: 'https://beta-api.adstage.app', // 현재 개발 단계에서는 베타 URL 사용
132
203
  debug: false,
133
204
  batchSize: 10,
134
205
  retryCount: 3,
@@ -1,6 +1,7 @@
1
1
  // 타입 정의 통합 인덱스
2
2
  export * from './advertisement';
3
3
  export * from './api';
4
- export * from './config';
4
+ export type { AdStageConfig, ModuleName, BaseModule, OrganizationInfo } from './config';
5
+ export type { ApiResponse as ConfigApiResponse } from './config';
5
6
  export * from './events';
6
7
 
@@ -0,0 +1,52 @@
1
+ /**
2
+ * AdStage SDK - API 헤더 유틸리티
3
+ * 공통 헤더 생성 로직
4
+ */
5
+
6
+ export class ApiHeaders {
7
+ /**
8
+ * 표준 API 헤더 생성
9
+ */
10
+ static create(apiKey: string, options?: {
11
+ contentType?: string;
12
+ userAgent?: string;
13
+ currentUrl?: string;
14
+ }): Record<string, string> {
15
+ if (!apiKey) {
16
+ throw new Error('API key is required');
17
+ }
18
+
19
+ const headers: Record<string, string> = {
20
+ 'x-api-key': apiKey,
21
+ 'Content-Type': options?.contentType || 'application/json'
22
+ };
23
+
24
+ // User-Agent는 이벤트 추적에서 실제로 사용됨
25
+ if (typeof navigator !== 'undefined') {
26
+ headers['User-Agent'] = options?.userAgent || navigator.userAgent;
27
+ }
28
+
29
+ // X-Current-URL은 현재 서버에서 사용하지 않으므로 제거
30
+ // 필요시 이벤트 데이터 body에 포함
31
+
32
+ return headers;
33
+ }
34
+
35
+ /**
36
+ * 이벤트 추적용 헤더 생성
37
+ * User-Agent는 서버에서 실제로 사용됨
38
+ */
39
+ static createForEvents(apiKey: string, eventData?: Record<string, any>): Record<string, string> {
40
+ const baseHeaders = ApiHeaders.create(apiKey);
41
+
42
+ // User-Agent 오버라이드 (서버에서 실제 사용)
43
+ if (eventData?.userAgent) {
44
+ baseHeaders['User-Agent'] = eventData.userAgent;
45
+ }
46
+
47
+ // 다른 정보들은 HTTP 헤더가 아닌 이벤트 데이터 body에 포함하는 것이 적절
48
+ // (currentUrl, referrer 등은 POST body로 전송)
49
+
50
+ return baseHeaders;
51
+ }
52
+ }
@@ -286,7 +286,7 @@ export class DOMUtils {
286
286
 
287
287
  다음을 확인해보세요:
288
288
  1. HTML에 id="${id}" 요소가 있는지 확인
289
- 2. React/Vue 등에서 컴포넌트가 렌더링된 후 SDK 호출
289
+ 2. React 등에서 컴포넌트가 렌더링된 후 SDK 호출
290
290
  3. 철자가 정확한지 확인
291
291
  4. 중복된 ID가 없는지 확인
292
292
 
@@ -1,33 +0,0 @@
1
- # API Key 설정 가이드
2
-
3
- 이 예제들을 실행하기 전에 API 키를 설정해야 합니다.
4
-
5
- ## React App 예제
6
- `sdk/examples/react-app/.env` 파일의 API 키를 설정하세요:
7
- ```
8
- REACT_APP_ADSTAGE_API_KEY=your_api_key_here
9
- ```
10
-
11
- ## Next.js 예제
12
- `sdk/examples/react-nextjs/.env` 파일의 API 키를 설정하세요:
13
- ```
14
- NEXT_PUBLIC_ADSTAGE_API_KEY=your_api_key_here
15
- ```
16
-
17
- ## 실행 방법
18
-
19
- ### React App 예제
20
- ```bash
21
- cd sdk/examples/react-app
22
- pnpm install
23
- pnpm start
24
- ```
25
-
26
- ### Next.js 예제
27
- ```bash
28
- cd sdk/examples/react-nextjs
29
- pnpm install
30
- pnpm dev
31
- ```
32
-
33
- 보안상 .env 파일은 Git에 커밋되지 않습니다. 실제 API 키는 AdStage 대시보드에서 발급받으세요.