@adstage/web-sdk 2.1.5 → 2.2.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.
package/dist/index.cjs.js CHANGED
@@ -3222,14 +3222,53 @@ class AdStage {
3222
3222
  * 편의성을 위한 정적 모듈 접근자들
3223
3223
  */
3224
3224
  static get ads() {
3225
+ // 🚀 자동 초기화: 아직 초기화되지 않았으면 환경변수로 자동 초기화
3226
+ if (!AdStage.instance?._isInitialized) {
3227
+ AdStage.autoInit();
3228
+ }
3225
3229
  return AdStage.getInstance().ads;
3226
3230
  }
3227
3231
  static get events() {
3232
+ if (!AdStage.instance?._isInitialized) {
3233
+ AdStage.autoInit();
3234
+ }
3228
3235
  return AdStage.getInstance().events;
3229
3236
  }
3230
3237
  static get config() {
3238
+ if (!AdStage.instance?._isInitialized) {
3239
+ AdStage.autoInit();
3240
+ }
3231
3241
  return AdStage.getInstance().config;
3232
3242
  }
3243
+ /**
3244
+ * 🆕 자동 초기화 - 환경변수 기반
3245
+ */
3246
+ static autoInit() {
3247
+ if (typeof window === 'undefined')
3248
+ return; // 서버 사이드에서는 실행 안함
3249
+ try {
3250
+ // 환경변수에서 API 키 자동 로드
3251
+ const apiKey = window.__ADSTAGE_API_KEY__ || // 런타임 설정
3252
+ process.env.NEXT_PUBLIC_ADSTAGE_API_KEY || // Next.js
3253
+ process.env.REACT_APP_ADSTAGE_API_KEY || // Create React App
3254
+ process.env.VITE_ADSTAGE_API_KEY || // Vite
3255
+ 'demo-api-key'; // 개발용 fallback
3256
+ const isDevelopment = "production" === 'development' ||
3257
+ window.__ADSTAGE_DEBUG__ === true;
3258
+ AdStage.init({
3259
+ apiKey: apiKey,
3260
+ debug: isDevelopment,
3261
+ modules: ['ads', 'config']
3262
+ });
3263
+ if (isDevelopment) {
3264
+ console.log('🔄 AdStage SDK auto-initialized with API key:', apiKey.substring(0, 8) + '...');
3265
+ }
3266
+ }
3267
+ catch (error) {
3268
+ console.warn('AdStage auto-initialization failed:', error);
3269
+ console.warn('Please call AdStage.init() manually or set NEXT_PUBLIC_ADSTAGE_API_KEY environment variable');
3270
+ }
3271
+ }
3233
3272
  /**
3234
3273
  * SDK 리셋 (테스트용)
3235
3274
  */
package/dist/index.d.ts CHANGED
@@ -513,6 +513,10 @@ declare class AdStage {
513
513
  static get ads(): AdsModule;
514
514
  static get events(): EventsModule;
515
515
  static get config(): ConfigModule;
516
+ /**
517
+ * 🆕 자동 초기화 - 환경변수 기반
518
+ */
519
+ private static autoInit;
516
520
  /**
517
521
  * SDK 리셋 (테스트용)
518
522
  */
package/dist/index.esm.js CHANGED
@@ -3220,14 +3220,53 @@ class AdStage {
3220
3220
  * 편의성을 위한 정적 모듈 접근자들
3221
3221
  */
3222
3222
  static get ads() {
3223
+ // 🚀 자동 초기화: 아직 초기화되지 않았으면 환경변수로 자동 초기화
3224
+ if (!AdStage.instance?._isInitialized) {
3225
+ AdStage.autoInit();
3226
+ }
3223
3227
  return AdStage.getInstance().ads;
3224
3228
  }
3225
3229
  static get events() {
3230
+ if (!AdStage.instance?._isInitialized) {
3231
+ AdStage.autoInit();
3232
+ }
3226
3233
  return AdStage.getInstance().events;
3227
3234
  }
3228
3235
  static get config() {
3236
+ if (!AdStage.instance?._isInitialized) {
3237
+ AdStage.autoInit();
3238
+ }
3229
3239
  return AdStage.getInstance().config;
3230
3240
  }
3241
+ /**
3242
+ * 🆕 자동 초기화 - 환경변수 기반
3243
+ */
3244
+ static autoInit() {
3245
+ if (typeof window === 'undefined')
3246
+ return; // 서버 사이드에서는 실행 안함
3247
+ try {
3248
+ // 환경변수에서 API 키 자동 로드
3249
+ const apiKey = window.__ADSTAGE_API_KEY__ || // 런타임 설정
3250
+ process.env.NEXT_PUBLIC_ADSTAGE_API_KEY || // Next.js
3251
+ process.env.REACT_APP_ADSTAGE_API_KEY || // Create React App
3252
+ process.env.VITE_ADSTAGE_API_KEY || // Vite
3253
+ 'demo-api-key'; // 개발용 fallback
3254
+ const isDevelopment = "production" === 'development' ||
3255
+ window.__ADSTAGE_DEBUG__ === true;
3256
+ AdStage.init({
3257
+ apiKey: apiKey,
3258
+ debug: isDevelopment,
3259
+ modules: ['ads', 'config']
3260
+ });
3261
+ if (isDevelopment) {
3262
+ console.log('🔄 AdStage SDK auto-initialized with API key:', apiKey.substring(0, 8) + '...');
3263
+ }
3264
+ }
3265
+ catch (error) {
3266
+ console.warn('AdStage auto-initialization failed:', error);
3267
+ console.warn('Please call AdStage.init() manually or set NEXT_PUBLIC_ADSTAGE_API_KEY environment variable');
3268
+ }
3269
+ }
3231
3270
  /**
3232
3271
  * SDK 리셋 (테스트용)
3233
3272
  */
@@ -3220,14 +3220,53 @@ class AdStage {
3220
3220
  * 편의성을 위한 정적 모듈 접근자들
3221
3221
  */
3222
3222
  static get ads() {
3223
+ // 🚀 자동 초기화: 아직 초기화되지 않았으면 환경변수로 자동 초기화
3224
+ if (!AdStage.instance?._isInitialized) {
3225
+ AdStage.autoInit();
3226
+ }
3223
3227
  return AdStage.getInstance().ads;
3224
3228
  }
3225
3229
  static get events() {
3230
+ if (!AdStage.instance?._isInitialized) {
3231
+ AdStage.autoInit();
3232
+ }
3226
3233
  return AdStage.getInstance().events;
3227
3234
  }
3228
3235
  static get config() {
3236
+ if (!AdStage.instance?._isInitialized) {
3237
+ AdStage.autoInit();
3238
+ }
3229
3239
  return AdStage.getInstance().config;
3230
3240
  }
3241
+ /**
3242
+ * 🆕 자동 초기화 - 환경변수 기반
3243
+ */
3244
+ static autoInit() {
3245
+ if (typeof window === 'undefined')
3246
+ return; // 서버 사이드에서는 실행 안함
3247
+ try {
3248
+ // 환경변수에서 API 키 자동 로드
3249
+ const apiKey = window.__ADSTAGE_API_KEY__ || // 런타임 설정
3250
+ process.env.NEXT_PUBLIC_ADSTAGE_API_KEY || // Next.js
3251
+ process.env.REACT_APP_ADSTAGE_API_KEY || // Create React App
3252
+ process.env.VITE_ADSTAGE_API_KEY || // Vite
3253
+ 'demo-api-key'; // 개발용 fallback
3254
+ const isDevelopment = "production" === 'development' ||
3255
+ window.__ADSTAGE_DEBUG__ === true;
3256
+ AdStage.init({
3257
+ apiKey: apiKey,
3258
+ debug: isDevelopment,
3259
+ modules: ['ads', 'config']
3260
+ });
3261
+ if (isDevelopment) {
3262
+ console.log('🔄 AdStage SDK auto-initialized with API key:', apiKey.substring(0, 8) + '...');
3263
+ }
3264
+ }
3265
+ catch (error) {
3266
+ console.warn('AdStage auto-initialization failed:', error);
3267
+ console.warn('Please call AdStage.init() manually or set NEXT_PUBLIC_ADSTAGE_API_KEY environment variable');
3268
+ }
3269
+ }
3231
3270
  /**
3232
3271
  * SDK 리셋 (테스트용)
3233
3272
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adstage/web-sdk",
3
- "version": "2.1.5",
4
- "description": "AdStage Web SDK - Production-ready marketing platform SDK with namespace architecture for ads, events, and config management",
3
+ "version": "2.2.0",
4
+ "description": "AdStage Web SDK - Production-ready marketing platform SDK with auto-initialization and namespace architecture",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.esm.js",
@@ -102,17 +102,61 @@ export class AdStage {
102
102
  * 편의성을 위한 정적 모듈 접근자들
103
103
  */
104
104
  public static get ads() {
105
+ // 🚀 자동 초기화: 아직 초기화되지 않았으면 환경변수로 자동 초기화
106
+ if (!AdStage.instance?._isInitialized) {
107
+ AdStage.autoInit();
108
+ }
105
109
  return AdStage.getInstance().ads;
106
110
  }
107
111
 
108
112
  public static get events() {
113
+ if (!AdStage.instance?._isInitialized) {
114
+ AdStage.autoInit();
115
+ }
109
116
  return AdStage.getInstance().events;
110
117
  }
111
118
 
112
119
  public static get config() {
120
+ if (!AdStage.instance?._isInitialized) {
121
+ AdStage.autoInit();
122
+ }
113
123
  return AdStage.getInstance().config;
114
124
  }
115
125
 
126
+ /**
127
+ * 🆕 자동 초기화 - 환경변수 기반
128
+ */
129
+ private static autoInit(): void {
130
+ if (typeof window === 'undefined') return; // 서버 사이드에서는 실행 안함
131
+
132
+ try {
133
+ // 환경변수에서 API 키 자동 로드
134
+ const apiKey =
135
+ (window as any).__ADSTAGE_API_KEY__ || // 런타임 설정
136
+ process.env.NEXT_PUBLIC_ADSTAGE_API_KEY || // Next.js
137
+ process.env.REACT_APP_ADSTAGE_API_KEY || // Create React App
138
+ process.env.VITE_ADSTAGE_API_KEY || // Vite
139
+ 'demo-api-key'; // 개발용 fallback
140
+
141
+ const isDevelopment =
142
+ process.env.NODE_ENV === 'development' ||
143
+ (window as any).__ADSTAGE_DEBUG__ === true;
144
+
145
+ AdStage.init({
146
+ apiKey: apiKey,
147
+ debug: isDevelopment,
148
+ modules: ['ads', 'config']
149
+ });
150
+
151
+ if (isDevelopment) {
152
+ console.log('🔄 AdStage SDK auto-initialized with API key:', apiKey.substring(0, 8) + '...');
153
+ }
154
+ } catch (error) {
155
+ console.warn('AdStage auto-initialization failed:', error);
156
+ console.warn('Please call AdStage.init() manually or set NEXT_PUBLIC_ADSTAGE_API_KEY environment variable');
157
+ }
158
+ }
159
+
116
160
  /**
117
161
  * SDK 리셋 (테스트용)
118
162
  */