playkit-sdk 1.2.8-beta.4 → 1.2.9

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * playkit-sdk v1.2.8-beta.4
2
+ * playkit-sdk v1.2.9
3
3
  * PlayKit SDK for JavaScript
4
4
  * @license SEE LICENSE IN LICENSE
5
5
  */
@@ -1147,41 +1147,40 @@ class AuthFlowManager extends EventEmitter {
1147
1147
  left: 0;
1148
1148
  right: 0;
1149
1149
  bottom: 0;
1150
- background: rgba(0, 0, 0, 0.48);
1151
- backdrop-filter: blur(8px);
1150
+ background: rgba(0, 0, 0, 0.8);
1152
1151
  }
1153
1152
 
1154
1153
  .playkit-auth-container {
1155
1154
  position: relative;
1156
- background: #FFFFFF;
1157
- border-radius: 4px;
1158
- box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
1155
+ background: #fff;
1156
+ border: 1px solid rgba(0, 0, 0, 0.1);
1157
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.05);
1159
1158
  width: 90%;
1160
- max-width: 420px;
1159
+ max-width: 320px;
1161
1160
  overflow: hidden;
1162
1161
  }
1163
1162
 
1164
1163
  .playkit-auth-panel {
1165
- padding: 40px 32px;
1164
+ padding: 24px;
1166
1165
  }
1167
1166
 
1168
1167
  .playkit-auth-header {
1169
1168
  text-align: center;
1170
- margin-bottom: 32px;
1169
+ margin-bottom: 20px;
1171
1170
  position: relative;
1172
1171
  }
1173
1172
 
1174
1173
  .playkit-auth-header h2 {
1175
1174
  margin: 0 0 8px 0;
1176
- font-size: 28px;
1175
+ font-size: 14px;
1177
1176
  font-weight: 600;
1178
- color: #000000;
1177
+ color: #171717;
1179
1178
  }
1180
1179
 
1181
1180
  .playkit-auth-header p {
1182
1181
  margin: 0;
1183
1182
  font-size: 14px;
1184
- color: #666666;
1183
+ color: #666;
1185
1184
  line-height: 1.5;
1186
1185
  }
1187
1186
 
@@ -1193,22 +1192,20 @@ class AuthFlowManager extends EventEmitter {
1193
1192
  border: none;
1194
1193
  cursor: pointer;
1195
1194
  padding: 4px;
1196
- border-radius: 2px;
1197
- color: #666666;
1198
- transition: background-color 0.15s ease, color 0.15s ease;
1195
+ color: #666;
1196
+ transition: background-color 0.2s ease, color 0.2s ease;
1199
1197
  }
1200
1198
 
1201
1199
  .playkit-back-button:hover {
1202
- background: #F6F6F6;
1203
- color: #000000;
1200
+ background: #f5f5f5;
1201
+ color: #171717;
1204
1202
  }
1205
1203
 
1206
1204
  .playkit-auth-toggle {
1207
1205
  display: flex;
1208
- background: #F6F6F6;
1209
- border-radius: 2px;
1206
+ background: #f5f5f5;
1210
1207
  padding: 2px;
1211
- margin-bottom: 24px;
1208
+ margin-bottom: 20px;
1212
1209
  gap: 2px;
1213
1210
  }
1214
1211
 
@@ -1218,9 +1215,8 @@ class AuthFlowManager extends EventEmitter {
1218
1215
  justify-content: center;
1219
1216
  align-items: center;
1220
1217
  padding: 10px 16px;
1221
- border-radius: 2px;
1222
1218
  cursor: pointer;
1223
- transition: background-color 0.15s ease;
1219
+ transition: background-color 0.2s ease;
1224
1220
  }
1225
1221
 
1226
1222
  .playkit-toggle-option input {
@@ -1230,20 +1226,20 @@ class AuthFlowManager extends EventEmitter {
1230
1226
  .playkit-toggle-option span {
1231
1227
  font-size: 14px;
1232
1228
  font-weight: 500;
1233
- color: #666666;
1234
- transition: color 0.15s ease;
1229
+ color: #666;
1230
+ transition: color 0.2s ease;
1235
1231
  }
1236
1232
 
1237
1233
  .playkit-toggle-option input:checked + span {
1238
- color: #FFFFFF;
1234
+ color: #fff;
1239
1235
  }
1240
1236
 
1241
1237
  .playkit-toggle-option:has(input:checked) {
1242
- background: #276EF1;
1238
+ background: #171717;
1243
1239
  }
1244
1240
 
1245
1241
  .playkit-auth-input-group {
1246
- margin-bottom: 24px;
1242
+ margin-bottom: 20px;
1247
1243
  }
1248
1244
 
1249
1245
  .playkit-input-wrapper {
@@ -1255,29 +1251,27 @@ class AuthFlowManager extends EventEmitter {
1255
1251
  .playkit-input-icon {
1256
1252
  position: absolute;
1257
1253
  left: 12px;
1258
- color: #999999;
1254
+ color: #999;
1259
1255
  pointer-events: none;
1260
1256
  }
1261
1257
 
1262
1258
  .playkit-input-wrapper input {
1263
1259
  width: 100%;
1264
- padding: 12px 12px 12px 44px;
1265
- border: 1px solid #CCCCCC;
1266
- border-radius: 2px;
1260
+ padding: 10px 12px 10px 44px;
1261
+ border: 1px solid #e5e7eb;
1267
1262
  font-size: 14px;
1268
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
1263
+ transition: border-color 0.2s ease;
1269
1264
  box-sizing: border-box;
1270
- background: #FFFFFF;
1265
+ background: #fff;
1271
1266
  }
1272
1267
 
1273
1268
  .playkit-input-wrapper input:hover {
1274
- border-color: #999999;
1269
+ border-color: #d4d4d4;
1275
1270
  }
1276
1271
 
1277
1272
  .playkit-input-wrapper input:focus {
1278
1273
  outline: none;
1279
- border-color: #276EF1;
1280
- box-shadow: 0 0 0 3px rgba(39, 110, 241, 0.1);
1274
+ border-color: #171717;
1281
1275
  }
1282
1276
 
1283
1277
  .playkit-code-inputs {
@@ -1287,16 +1281,15 @@ class AuthFlowManager extends EventEmitter {
1287
1281
  }
1288
1282
 
1289
1283
  .playkit-code-input {
1290
- width: 48px !important;
1291
- height: 56px;
1284
+ width: 40px !important;
1285
+ height: 48px;
1292
1286
  text-align: center;
1293
- font-size: 24px;
1287
+ font-size: 20px;
1294
1288
  font-weight: 600;
1295
- border: 1px solid #CCCCCC !important;
1296
- border-radius: 2px;
1289
+ border: 1px solid #e5e7eb !important;
1297
1290
  padding: 0 !important;
1298
- transition: border-color 0.15s ease, box-shadow 0.15s ease;
1299
- background: #FFFFFF;
1291
+ transition: border-color 0.2s ease;
1292
+ background: #fff;
1300
1293
  -moz-appearance: textfield;
1301
1294
  }
1302
1295
 
@@ -1307,48 +1300,46 @@ class AuthFlowManager extends EventEmitter {
1307
1300
  }
1308
1301
 
1309
1302
  .playkit-code-input:hover {
1310
- border-color: #999999 !important;
1303
+ border-color: #d4d4d4 !important;
1311
1304
  }
1312
1305
 
1313
1306
  .playkit-code-input:focus {
1314
1307
  outline: none;
1315
- border-color: #276EF1 !important;
1316
- box-shadow: 0 0 0 3px rgba(39, 110, 241, 0.1);
1308
+ border-color: #171717 !important;
1317
1309
  }
1318
1310
 
1319
1311
  .playkit-auth-button {
1320
1312
  width: 100%;
1321
- padding: 12px 16px;
1322
- background: #276EF1;
1323
- color: #FFFFFF;
1313
+ padding: 10px 16px;
1314
+ background: #171717;
1315
+ color: white;
1324
1316
  border: none;
1325
- border-radius: 2px;
1326
1317
  font-size: 14px;
1327
1318
  font-weight: 500;
1328
1319
  cursor: pointer;
1329
- transition: background-color 0.15s ease;
1320
+ transition: background 0.2s ease;
1330
1321
  }
1331
1322
 
1332
1323
  .playkit-auth-button:hover:not(:disabled) {
1333
- background: #174EB6;
1324
+ background: #404040;
1334
1325
  }
1335
1326
 
1336
1327
  .playkit-auth-button:active:not(:disabled) {
1337
- background: #0F3A8A;
1328
+ background: #0a0a0a;
1338
1329
  }
1339
1330
 
1340
1331
  .playkit-auth-button:disabled {
1341
- background: #CCCCCC;
1332
+ background: #e5e7eb;
1333
+ color: #999;
1342
1334
  cursor: not-allowed;
1343
1335
  }
1344
1336
 
1345
1337
  .playkit-auth-error {
1346
1338
  margin-top: 16px;
1347
1339
  padding: 12px 16px;
1348
- background: #FEF0F0;
1349
- border: 1px solid #FDD;
1350
- border-radius: 2px;
1351
- color: #CC3333;
1340
+ background: #fef2f2;
1341
+ border: 1px solid #fecaca;
1342
+ color: #dc2626;
1352
1343
  font-size: 13px;
1353
1344
  text-align: left;
1354
1345
  display: none;
@@ -1368,16 +1359,15 @@ class AuthFlowManager extends EventEmitter {
1368
1359
  display: flex;
1369
1360
  justify-content: center;
1370
1361
  align-items: center;
1371
- border-radius: 4px;
1372
1362
  }
1373
1363
 
1374
1364
  .playkit-spinner {
1375
- width: 40px;
1376
- height: 40px;
1377
- border: 3px solid #F0F0F0;
1378
- border-top: 3px solid #276EF1;
1365
+ width: 24px;
1366
+ height: 24px;
1367
+ border: 2px solid #e5e7eb;
1368
+ border-top: 2px solid #171717;
1379
1369
  border-radius: 50%;
1380
- animation: playkit-spin 0.8s linear infinite;
1370
+ animation: playkit-spin 1s linear infinite;
1381
1371
  }
1382
1372
 
1383
1373
  @keyframes playkit-spin {
@@ -1389,17 +1379,16 @@ class AuthFlowManager extends EventEmitter {
1389
1379
  .playkit-auth-container {
1390
1380
  width: 95%;
1391
1381
  max-width: none;
1392
- border-radius: 2px;
1393
1382
  }
1394
1383
 
1395
1384
  .playkit-auth-panel {
1396
- padding: 32px 24px;
1385
+ padding: 20px;
1397
1386
  }
1398
1387
 
1399
1388
  .playkit-code-input {
1400
- width: 40px !important;
1401
- height: 48px;
1402
- font-size: 20px;
1389
+ width: 36px !important;
1390
+ height: 44px;
1391
+ font-size: 18px;
1403
1392
  }
1404
1393
 
1405
1394
  .playkit-code-inputs {
@@ -2608,6 +2597,25 @@ class AuthManager extends EventEmitter {
2608
2597
  isAuthenticated() {
2609
2598
  return this.authState.isAuthenticated;
2610
2599
  }
2600
+ /**
2601
+ * Check if current authentication is using developerToken
2602
+ */
2603
+ isDeveloperTokenAuth() {
2604
+ return this.authState.tokenType === 'developer';
2605
+ }
2606
+ /**
2607
+ * Clear developerToken authentication state.
2608
+ * Used when falling back to player login after developerToken failure.
2609
+ */
2610
+ clearDeveloperToken() {
2611
+ if (this.authState.tokenType === 'developer') {
2612
+ this.authState = {
2613
+ isAuthenticated: false,
2614
+ };
2615
+ // Also clear the developerToken from config to prevent re-use
2616
+ this.config.developerToken = undefined;
2617
+ }
2618
+ }
2611
2619
  /**
2612
2620
  * Check if token is expired
2613
2621
  */
@@ -3050,13 +3058,13 @@ class RechargeManager extends EventEmitter {
3050
3058
  left: 0;
3051
3059
  right: 0;
3052
3060
  bottom: 0;
3053
- background-color: rgba(0, 0, 0, 0.5);
3054
- backdrop-filter: blur(4px);
3061
+ background: rgba(0, 0, 0, 0.8);
3055
3062
  display: flex;
3056
3063
  justify-content: center;
3057
3064
  align-items: center;
3058
3065
  z-index: 999999;
3059
3066
  animation: playkit-recharge-fadeIn 0.2s ease-out;
3067
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3060
3068
  }
3061
3069
 
3062
3070
  @keyframes playkit-recharge-fadeIn {
@@ -3069,140 +3077,111 @@ class RechargeManager extends EventEmitter {
3069
3077
  }
3070
3078
 
3071
3079
  .playkit-recharge-modal {
3072
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
3073
- border-radius: 16px;
3074
- box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
3075
- padding: 32px;
3076
- max-width: 400px;
3080
+ background: #fff;
3081
+ border: 1px solid rgba(0, 0, 0, 0.1);
3082
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.05);
3083
+ padding: 24px;
3084
+ max-width: 320px;
3077
3085
  width: 90%;
3078
3086
  position: relative;
3079
- animation: playkit-recharge-slideUp 0.3s ease-out;
3080
- }
3081
-
3082
- @keyframes playkit-recharge-slideUp {
3083
- from {
3084
- transform: translateY(20px);
3085
- opacity: 0;
3086
- }
3087
- to {
3088
- transform: translateY(0);
3089
- opacity: 1;
3090
- }
3087
+ text-align: center;
3091
3088
  }
3092
3089
 
3093
3090
  .playkit-recharge-title {
3094
- font-size: 24px;
3095
- font-weight: bold;
3096
- color: #ffffff;
3097
- margin: 0 0 16px 0;
3091
+ font-size: 14px;
3092
+ font-weight: 600;
3093
+ color: #171717;
3094
+ margin: 0 0 8px 0;
3098
3095
  text-align: center;
3099
3096
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3100
3097
  }
3101
3098
 
3102
3099
  .playkit-recharge-message {
3103
- font-size: 16px;
3104
- color: rgba(255, 255, 255, 0.9);
3105
- margin: 0 0 24px 0;
3100
+ font-size: 14px;
3101
+ color: #666;
3102
+ margin: 0 0 20px 0;
3106
3103
  text-align: center;
3107
3104
  line-height: 1.5;
3108
3105
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3109
3106
  }
3110
3107
 
3111
3108
  .playkit-recharge-balance {
3112
- background: rgba(255, 255, 255, 0.15);
3113
- border-radius: 12px;
3109
+ background: #f5f5f5;
3110
+ border: 1px solid #e5e7eb;
3114
3111
  padding: 16px;
3115
- margin: 0 0 24px 0;
3112
+ margin: 0 0 20px 0;
3116
3113
  text-align: center;
3117
- backdrop-filter: blur(10px);
3118
3114
  }
3119
3115
 
3120
3116
  .playkit-recharge-balance-label {
3121
- font-size: 14px;
3122
- color: rgba(255, 255, 255, 0.8);
3117
+ font-size: 12px;
3118
+ color: #666;
3123
3119
  margin: 0 0 8px 0;
3124
3120
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3125
3121
  }
3126
3122
 
3127
3123
  .playkit-recharge-balance-value {
3128
- font-size: 32px;
3124
+ font-size: 24px;
3129
3125
  font-weight: bold;
3130
- color: #ffffff;
3126
+ color: #171717;
3131
3127
  margin: 0;
3132
3128
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3133
3129
  }
3134
3130
 
3135
3131
  .playkit-recharge-balance-unit {
3136
- font-size: 16px;
3137
- color: rgba(255, 255, 255, 0.8);
3138
- margin-left: 8px;
3132
+ font-size: 14px;
3133
+ color: #666;
3134
+ margin-left: 4px;
3139
3135
  }
3140
3136
 
3141
3137
  .playkit-recharge-buttons {
3142
3138
  display: flex;
3143
- gap: 12px;
3144
- justify-content: center;
3139
+ flex-direction: column;
3140
+ gap: 8px;
3145
3141
  }
3146
3142
 
3147
3143
  .playkit-recharge-button {
3148
- flex: 1;
3149
- padding: 12px 24px;
3144
+ width: 100%;
3145
+ padding: 10px 16px;
3150
3146
  border: none;
3151
- border-radius: 8px;
3152
- font-size: 16px;
3153
- font-weight: 600;
3147
+ font-size: 14px;
3148
+ font-weight: 500;
3154
3149
  cursor: pointer;
3155
3150
  transition: all 0.2s ease;
3156
3151
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3157
3152
  }
3158
3153
 
3159
3154
  .playkit-recharge-button-primary {
3160
- background: #ffffff;
3161
- color: #667eea;
3155
+ background: #171717;
3156
+ color: white;
3162
3157
  }
3163
3158
 
3164
3159
  .playkit-recharge-button-primary:hover {
3165
- transform: translateY(-2px);
3166
- box-shadow: 0 8px 16px rgba(255, 255, 255, 0.2);
3160
+ background: #404040;
3167
3161
  }
3168
3162
 
3169
3163
  .playkit-recharge-button-primary:active {
3170
- transform: translateY(0);
3164
+ background: #0a0a0a;
3171
3165
  }
3172
3166
 
3173
3167
  .playkit-recharge-button-secondary {
3174
- background: rgba(255, 255, 255, 0.15);
3175
- color: #ffffff;
3176
- border: 1px solid rgba(255, 255, 255, 0.3);
3168
+ background: transparent;
3169
+ color: #666;
3170
+ border: 1px solid #e5e7eb;
3177
3171
  }
3178
3172
 
3179
3173
  .playkit-recharge-button-secondary:hover {
3180
- background: rgba(255, 255, 255, 0.25);
3174
+ background: #f5f5f5;
3175
+ border-color: #d4d4d4;
3181
3176
  }
3182
3177
 
3183
3178
  .playkit-recharge-button-secondary:active {
3184
- background: rgba(255, 255, 255, 0.15);
3179
+ background: #e5e5e5;
3185
3180
  }
3186
3181
 
3187
3182
  @media (max-width: 480px) {
3188
3183
  .playkit-recharge-modal {
3189
- padding: 24px;
3190
- }
3191
-
3192
- .playkit-recharge-title {
3193
- font-size: 20px;
3194
- }
3195
-
3196
- .playkit-recharge-message {
3197
- font-size: 14px;
3198
- }
3199
-
3200
- .playkit-recharge-balance-value {
3201
- font-size: 28px;
3202
- }
3203
-
3204
- .playkit-recharge-buttons {
3205
- flex-direction: column;
3184
+ padding: 20px;
3206
3185
  }
3207
3186
  }
3208
3187
 
@@ -3211,9 +3190,9 @@ class RechargeManager extends EventEmitter {
3211
3190
  position: fixed;
3212
3191
  top: 20px;
3213
3192
  right: 20px;
3214
- background: linear-gradient(135deg, #10b981 0%, #059669 100%);
3215
- border-radius: 12px;
3216
- box-shadow: 0 10px 40px rgba(16, 185, 129, 0.3), 0 4px 12px rgba(0, 0, 0, 0.1);
3193
+ background: #fff;
3194
+ border: 1px solid rgba(0, 0, 0, 0.1);
3195
+ box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1);
3217
3196
  padding: 16px 20px;
3218
3197
  min-width: 240px;
3219
3198
  max-width: 320px;
@@ -3222,6 +3201,7 @@ class RechargeManager extends EventEmitter {
3222
3201
  display: flex;
3223
3202
  align-items: flex-start;
3224
3203
  gap: 12px;
3204
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3225
3205
  }
3226
3206
 
3227
3207
  .playkit-daily-refresh-toast.hiding {
@@ -3253,7 +3233,7 @@ class RechargeManager extends EventEmitter {
3253
3233
  .playkit-toast-icon {
3254
3234
  width: 24px;
3255
3235
  height: 24px;
3256
- background: rgba(255, 255, 255, 0.2);
3236
+ background: #171717;
3257
3237
  border-radius: 50%;
3258
3238
  display: flex;
3259
3239
  align-items: center;
@@ -3271,7 +3251,7 @@ class RechargeManager extends EventEmitter {
3271
3251
  flex: 1;
3272
3252
  font-size: 14px;
3273
3253
  font-weight: 500;
3274
- color: #ffffff;
3254
+ color: #171717;
3275
3255
  line-height: 1.4;
3276
3256
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
3277
3257
  }
@@ -3447,19 +3427,11 @@ class PlayerClient extends EventEmitter {
3447
3427
  * Get player information
3448
3428
  */
3449
3429
  async getPlayerInfo() {
3450
- var _a, _b;
3430
+ var _a, _b, _c;
3451
3431
  const token = this.authManager.getToken();
3452
3432
  if (!token) {
3453
3433
  throw new PlayKitError('Not authenticated', 'NOT_AUTHENTICATED');
3454
3434
  }
3455
- // If using developer token, return mock player info
3456
- const authState = this.authManager.getAuthState();
3457
- if (authState.tokenType === 'developer') {
3458
- return {
3459
- userId: 'developer',
3460
- credits: 999999,
3461
- };
3462
- }
3463
3435
  try {
3464
3436
  // Build headers with X-Game-Id to support Global Developer Token
3465
3437
  const headers = {
@@ -3489,13 +3461,14 @@ class PlayerClient extends EventEmitter {
3489
3461
  const data = await response.json();
3490
3462
  this.playerInfo = {
3491
3463
  userId: data.userId,
3464
+ balance: (_a = data.balance) !== null && _a !== void 0 ? _a : 0,
3492
3465
  credits: data.credits,
3493
- nickname: (_a = data.nickname) !== null && _a !== void 0 ? _a : null,
3466
+ nickname: (_b = data.nickname) !== null && _b !== void 0 ? _b : null,
3494
3467
  dailyRefresh: data.dailyRefresh,
3495
3468
  };
3496
3469
  this.emit('player_info_updated', this.playerInfo);
3497
3470
  // Emit daily refresh event if credits were refreshed
3498
- if ((_b = data.dailyRefresh) === null || _b === void 0 ? void 0 : _b.refreshed) {
3471
+ if ((_c = data.dailyRefresh) === null || _c === void 0 ? void 0 : _c.refreshed) {
3499
3472
  this.emit('daily_credits_refreshed', data.dailyRefresh);
3500
3473
  // Show toast notification if enabled
3501
3474
  if (this.rechargeConfig.showDailyRefreshToast !== false) {
@@ -3611,7 +3584,7 @@ class PlayerClient extends EventEmitter {
3611
3584
  this.logger.warn('RechargeManager not initialized. Cannot show modal.');
3612
3585
  return;
3613
3586
  }
3614
- const balance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.credits;
3587
+ const balance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.balance;
3615
3588
  await this.rechargeManager.showInsufficientBalanceModal({
3616
3589
  currentBalance: balance,
3617
3590
  message: customMessage,
@@ -3644,9 +3617,9 @@ class PlayerClient extends EventEmitter {
3644
3617
  this.balanceCheckInterval = setInterval(async () => {
3645
3618
  var _a, _b;
3646
3619
  try {
3647
- const oldBalance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.credits;
3620
+ const oldBalance = (_a = this.playerInfo) === null || _a === void 0 ? void 0 : _a.balance;
3648
3621
  await this.refreshPlayerInfo();
3649
- const newBalance = (_b = this.playerInfo) === null || _b === void 0 ? void 0 : _b.credits;
3622
+ const newBalance = (_b = this.playerInfo) === null || _b === void 0 ? void 0 : _b.balance;
3650
3623
  // Emit balance_updated event
3651
3624
  if (newBalance !== undefined) {
3652
3625
  this.emit('balance_updated', newBalance);
@@ -6110,6 +6083,8 @@ class PlayKitSDK extends EventEmitter {
6110
6083
  // Initialize logging system
6111
6084
  this.initializeLogging(this.config);
6112
6085
  this.logger = Logger.getLogger('PlayKitSDK');
6086
+ // Initialize fallback configuration with defaults
6087
+ this.fallbackConfig = Object.assign({ enabled: true }, config.developerTokenFallback);
6113
6088
  // Initialize managers and providers
6114
6089
  this.authManager = new AuthManager(this.config);
6115
6090
  this.playerClient = new PlayerClient(this.authManager, this.config, this.config.recharge);
@@ -6167,7 +6142,8 @@ class PlayKitSDK extends EventEmitter {
6167
6142
  await this.authManager.initialize();
6168
6143
  this.initialized = true;
6169
6144
  // Show developer token indicator if using developer token (browser mode only)
6170
- if (this.config.developerToken && this.config.mode !== 'server' && typeof window !== 'undefined') {
6145
+ const isDeveloperTokenMode = this.authManager.isDeveloperTokenAuth();
6146
+ if (isDeveloperTokenMode && this.config.mode !== 'server' && typeof window !== 'undefined') {
6171
6147
  this.showDeveloperTokenIndicator();
6172
6148
  }
6173
6149
  // Always verify token validity and fetch user info after authentication
@@ -6177,20 +6153,26 @@ class PlayKitSDK extends EventEmitter {
6177
6153
  this.logger.debug('Token validated and user info fetched');
6178
6154
  }
6179
6155
  catch (error) {
6180
- // If token is invalid, logout and restart auth flow
6181
- this.logger.error('Token validation failed:', error);
6182
- await this.authManager.logout();
6183
- // Auto-restart login flow in browser environment
6184
- if (typeof window !== 'undefined') {
6185
- this.logger.debug('Restarting authentication flow...');
6186
- const authMethod = this.config.authMethod || 'device';
6187
- await this.authManager.startAuthFlow(authMethod);
6188
- // Retry getting player info after re-authentication
6189
- await this.playerClient.getPlayerInfo();
6190
- this.logger.debug('Re-authentication successful, token validated');
6156
+ // Check if this is a developerToken failure
6157
+ if (isDeveloperTokenMode) {
6158
+ await this.handleDeveloperTokenFailure(error);
6191
6159
  }
6192
6160
  else {
6193
- throw new Error('Token validation failed: ' + (error instanceof Error ? error.message : String(error)));
6161
+ // If token is invalid, logout and restart auth flow
6162
+ this.logger.error('Token validation failed:', error);
6163
+ await this.authManager.logout();
6164
+ // Auto-restart login flow in browser environment
6165
+ if (typeof window !== 'undefined') {
6166
+ this.logger.debug('Restarting authentication flow...');
6167
+ const authMethod = this.config.authMethod || 'device';
6168
+ await this.authManager.startAuthFlow(authMethod);
6169
+ // Retry getting player info after re-authentication
6170
+ await this.playerClient.getPlayerInfo();
6171
+ this.logger.debug('Re-authentication successful, token validated');
6172
+ }
6173
+ else {
6174
+ throw new Error('Token validation failed: ' + (error instanceof Error ? error.message : String(error)));
6175
+ }
6194
6176
  }
6195
6177
  }
6196
6178
  }
@@ -6202,6 +6184,50 @@ class PlayKitSDK extends EventEmitter {
6202
6184
  throw error;
6203
6185
  }
6204
6186
  }
6187
+ /**
6188
+ * Handle developerToken authentication failure with optional fallback to player login.
6189
+ * This is called when a developerToken is provided but fails validation.
6190
+ *
6191
+ * @param error - The error that caused the developerToken failure
6192
+ */
6193
+ async handleDeveloperTokenFailure(error) {
6194
+ const willFallback = this.fallbackConfig.enabled !== false &&
6195
+ typeof window !== 'undefined' &&
6196
+ this.config.mode !== 'server';
6197
+ // Emit developer_token_failed event
6198
+ this.emit('developer_token_failed', {
6199
+ error,
6200
+ willFallback,
6201
+ });
6202
+ this.logger.warn('DeveloperToken validation failed', { error, willFallback });
6203
+ // Clear developer token state and indicator
6204
+ this.authManager.clearDeveloperToken();
6205
+ this.hideDeveloperTokenIndicator();
6206
+ if (!willFallback) {
6207
+ // Fallback disabled or not in browser - throw the error
6208
+ throw new PlayKitError('DeveloperToken validation failed: ' + (error instanceof Error ? error.message : String(error)), 'DEVELOPER_TOKEN_INVALID');
6209
+ }
6210
+ // Emit fallback started event
6211
+ const fallbackMethod = this.config.authMethod || 'device';
6212
+ this.emit('developer_token_fallback_started', { fallbackMethod });
6213
+ this.logger.debug('Starting fallback to player login', { fallbackMethod });
6214
+ try {
6215
+ // Start player login flow
6216
+ await this.authManager.startAuthFlow(fallbackMethod);
6217
+ // Verify the new token
6218
+ await this.playerClient.getPlayerInfo();
6219
+ // Emit fallback completed event
6220
+ const authState = this.authManager.getAuthState();
6221
+ this.emit('developer_token_fallback_completed', { authState });
6222
+ this.logger.debug('DeveloperToken fallback completed successfully');
6223
+ }
6224
+ catch (fallbackError) {
6225
+ // Emit fallback failed event
6226
+ this.emit('developer_token_fallback_failed', { error: fallbackError });
6227
+ this.logger.error('DeveloperToken fallback failed', fallbackError);
6228
+ throw fallbackError;
6229
+ }
6230
+ }
6205
6231
  /**
6206
6232
  * Show developer token indicator in top-left corner
6207
6233
  */
@@ -6275,10 +6301,20 @@ class PlayKitSDK extends EventEmitter {
6275
6301
  await this.authManager.logout();
6276
6302
  this.hideDeveloperTokenIndicator();
6277
6303
  }
6304
+ /**
6305
+ * Ensure SDK is initialized before making API calls
6306
+ * @throws PlayKitError if not initialized
6307
+ */
6308
+ ensureInitialized() {
6309
+ if (!this.initialized) {
6310
+ throw new PlayKitError('SDK not initialized. Call await sdk.initialize() before using API methods.', 'NOT_INITIALIZED');
6311
+ }
6312
+ }
6278
6313
  /**
6279
6314
  * Get player information
6280
6315
  */
6281
6316
  async getPlayerInfo() {
6317
+ this.ensureInitialized();
6282
6318
  return await this.playerClient.getPlayerInfo();
6283
6319
  }
6284
6320
  /**
@@ -6286,6 +6322,7 @@ class PlayKitSDK extends EventEmitter {
6286
6322
  * Automatically uses the SDK's schema library
6287
6323
  */
6288
6324
  createChatClient(model) {
6325
+ this.ensureInitialized();
6289
6326
  const client = new ChatClient(this.chatProvider, model || this.config.defaultChatModel);
6290
6327
  // Automatically use the SDK's schema library
6291
6328
  client.setSchemaLibrary(this.schemaLibrary);
@@ -6295,6 +6332,7 @@ class PlayKitSDK extends EventEmitter {
6295
6332
  * Create an image client
6296
6333
  */
6297
6334
  createImageClient(model) {
6335
+ this.ensureInitialized();
6298
6336
  return new ImageClient(this.imageProvider, model || this.config.defaultImageModel);
6299
6337
  }
6300
6338
  /**
@@ -6302,6 +6340,7 @@ class PlayKitSDK extends EventEmitter {
6302
6340
  * @param model - Transcription model to use (default: 'whisper-large')
6303
6341
  */
6304
6342
  createTranscriptionClient(model) {
6343
+ this.ensureInitialized();
6305
6344
  return new TranscriptionClient(this.transcriptionProvider, model || this.config.defaultTranscriptionModel);
6306
6345
  }
6307
6346
  /**
@@ -6309,6 +6348,7 @@ class PlayKitSDK extends EventEmitter {
6309
6348
  * Automatically registers with AIContextManager
6310
6349
  */
6311
6350
  createNPCClient(config) {
6351
+ this.ensureInitialized();
6312
6352
  const chatClient = this.createChatClient(config === null || config === void 0 ? void 0 : config.model);
6313
6353
  const npc = new NPCClient(chatClient, config);
6314
6354
  // Register with context manager
@@ -6407,6 +6447,7 @@ class PlayKitSDK extends EventEmitter {
6407
6447
  * Show insufficient balance modal
6408
6448
  */
6409
6449
  async showInsufficientBalanceModal(customMessage) {
6450
+ this.ensureInitialized();
6410
6451
  return await this.playerClient.showInsufficientBalanceModal(customMessage);
6411
6452
  }
6412
6453
  /**
@@ -6434,14 +6475,15 @@ class PlayKitSDK extends EventEmitter {
6434
6475
  getCachedBalance() {
6435
6476
  var _a;
6436
6477
  const playerInfo = this.playerClient.getCachedPlayerInfo();
6437
- return (_a = playerInfo === null || playerInfo === void 0 ? void 0 : playerInfo.credits) !== null && _a !== void 0 ? _a : null;
6478
+ return (_a = playerInfo === null || playerInfo === void 0 ? void 0 : playerInfo.balance) !== null && _a !== void 0 ? _a : null;
6438
6479
  }
6439
6480
  /**
6440
6481
  * Refresh and get player's current balance
6441
6482
  */
6442
6483
  async refreshBalance() {
6484
+ this.ensureInitialized();
6443
6485
  const playerInfo = await this.playerClient.refreshPlayerInfo();
6444
- return playerInfo.credits;
6486
+ return playerInfo.balance;
6445
6487
  }
6446
6488
  // ============================================================
6447
6489
  // Player Profile Methods
@@ -6460,6 +6502,7 @@ class PlayKitSDK extends EventEmitter {
6460
6502
  * @throws PlayKitError if validation fails or token type is invalid
6461
6503
  */
6462
6504
  async setNickname(nickname) {
6505
+ this.ensureInitialized();
6463
6506
  return await this.playerClient.setNickname(nickname);
6464
6507
  }
6465
6508
  // ============================================================