@oasiz/sdk 1.5.3 → 1.5.4

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.js CHANGED
@@ -1,4 +1,4 @@
1
- // src/haptics.ts
1
+ // src/character.ts
2
2
  function isDevelopment() {
3
3
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
4
4
  return nodeEnv !== "production";
@@ -9,13 +9,48 @@ function getBridgeWindow() {
9
9
  }
10
10
  return window;
11
11
  }
12
- function triggerHaptic(type) {
12
+ function warnMissingBridge(methodName) {
13
+ if (isDevelopment()) {
14
+ console.warn(
15
+ "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
16
+ );
17
+ }
18
+ }
19
+ async function getPlayerCharacter() {
13
20
  const bridge = getBridgeWindow();
21
+ if (typeof bridge?.__oasizGetPlayerCharacter !== "function") {
22
+ warnMissingBridge("getPlayerCharacter");
23
+ return null;
24
+ }
25
+ try {
26
+ const result = await bridge.__oasizGetPlayerCharacter();
27
+ return result ?? null;
28
+ } catch (error) {
29
+ if (isDevelopment()) {
30
+ console.error("[oasiz/sdk] getPlayerCharacter failed:", error);
31
+ }
32
+ return null;
33
+ }
34
+ }
35
+
36
+ // src/haptics.ts
37
+ function isDevelopment2() {
38
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
39
+ return nodeEnv !== "production";
40
+ }
41
+ function getBridgeWindow2() {
42
+ if (typeof window === "undefined") {
43
+ return void 0;
44
+ }
45
+ return window;
46
+ }
47
+ function triggerHaptic(type) {
48
+ const bridge = getBridgeWindow2();
14
49
  if (typeof bridge?.triggerHaptic === "function") {
15
50
  bridge.triggerHaptic(type);
16
51
  return;
17
52
  }
18
- if (isDevelopment()) {
53
+ if (isDevelopment2()) {
19
54
  console.warn(
20
55
  "[oasiz/sdk] triggerHaptic bridge is unavailable. This is expected in local development."
21
56
  );
@@ -914,70 +949,74 @@ function enableLogOverlay(options = {}) {
914
949
  }
915
950
 
916
951
  // src/multiplayer.ts
917
- function isDevelopment2() {
952
+ function isDevelopment3() {
918
953
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
919
954
  return nodeEnv !== "production";
920
955
  }
921
- function getBridgeWindow2() {
956
+ function getBridgeWindow3() {
922
957
  if (typeof window === "undefined") {
923
958
  return void 0;
924
959
  }
925
960
  return window;
926
961
  }
927
962
  function shareRoomCode(roomCode, options) {
928
- const bridge = getBridgeWindow2();
963
+ const bridge = getBridgeWindow3();
929
964
  if (typeof bridge?.shareRoomCode === "function") {
930
965
  bridge.shareRoomCode(roomCode, options);
931
966
  return;
932
967
  }
933
- if (isDevelopment2()) {
968
+ if (isDevelopment3()) {
934
969
  console.warn(
935
970
  "[oasiz/sdk] shareRoomCode bridge is unavailable. This is expected in local development."
936
971
  );
937
972
  }
938
973
  }
939
974
  function openInviteModal() {
940
- const bridge = getBridgeWindow2();
975
+ const bridge = getBridgeWindow3();
941
976
  if (typeof bridge?.openInviteModal === "function") {
942
977
  bridge.openInviteModal();
943
978
  return;
944
979
  }
945
- if (isDevelopment2()) {
980
+ if (isDevelopment3()) {
946
981
  console.warn(
947
982
  "[oasiz/sdk] openInviteModal bridge is unavailable. This is expected in local development."
948
983
  );
949
984
  }
950
985
  }
951
986
  function getGameId() {
952
- const bridge = getBridgeWindow2();
987
+ const bridge = getBridgeWindow3();
953
988
  return bridge?.__GAME_ID__;
954
989
  }
955
990
  function getRoomCode() {
956
- const bridge = getBridgeWindow2();
991
+ const bridge = getBridgeWindow3();
957
992
  return bridge?.__ROOM_CODE__;
958
993
  }
994
+ function getPlayerId() {
995
+ const bridge = getBridgeWindow3();
996
+ return bridge?.__PLAYER_ID__;
997
+ }
959
998
  function getPlayerName() {
960
- const bridge = getBridgeWindow2();
999
+ const bridge = getBridgeWindow3();
961
1000
  return bridge?.__PLAYER_NAME__;
962
1001
  }
963
1002
  function getPlayerAvatar() {
964
- const bridge = getBridgeWindow2();
1003
+ const bridge = getBridgeWindow3();
965
1004
  return bridge?.__PLAYER_AVATAR__;
966
1005
  }
967
1006
 
968
1007
  // src/score.ts
969
- function isDevelopment3() {
1008
+ function isDevelopment4() {
970
1009
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
971
1010
  return nodeEnv !== "production";
972
1011
  }
973
- function warnMissingBridge(methodName) {
974
- if (isDevelopment3()) {
1012
+ function warnMissingBridge2(methodName) {
1013
+ if (isDevelopment4()) {
975
1014
  console.warn(
976
1015
  "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
977
1016
  );
978
1017
  }
979
1018
  }
980
- function getBridgeWindow3() {
1019
+ function getBridgeWindow4() {
981
1020
  if (typeof window === "undefined") {
982
1021
  return void 0;
983
1022
  }
@@ -985,33 +1024,92 @@ function getBridgeWindow3() {
985
1024
  }
986
1025
  function submitScore(score) {
987
1026
  if (!Number.isFinite(score)) {
988
- if (isDevelopment3()) {
1027
+ if (isDevelopment4()) {
989
1028
  console.warn("[oasiz/sdk] submitScore expected a finite number:", score);
990
1029
  }
991
1030
  return;
992
1031
  }
993
- const bridge = getBridgeWindow3();
1032
+ const bridge = getBridgeWindow4();
994
1033
  const normalizedScore = Math.max(0, Math.floor(score));
995
1034
  if (typeof bridge?.submitScore === "function") {
996
1035
  bridge.submitScore(normalizedScore);
997
1036
  return;
998
1037
  }
999
- warnMissingBridge("submitScore");
1038
+ warnMissingBridge2("submitScore");
1039
+ }
1040
+
1041
+ // src/score-edit.ts
1042
+ function isDevelopment5() {
1043
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
1044
+ return nodeEnv !== "production";
1045
+ }
1046
+ function getBridgeWindow5() {
1047
+ if (typeof window === "undefined") {
1048
+ return void 0;
1049
+ }
1050
+ return window;
1051
+ }
1052
+ function warnMissingBridge3(methodName) {
1053
+ if (isDevelopment5()) {
1054
+ console.warn(
1055
+ "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
1056
+ );
1057
+ }
1058
+ }
1059
+ async function editScore(payload, methodName) {
1060
+ const bridge = getBridgeWindow5();
1061
+ if (typeof bridge?.__oasizEditScore !== "function") {
1062
+ warnMissingBridge3(methodName);
1063
+ return null;
1064
+ }
1065
+ try {
1066
+ const result = await bridge.__oasizEditScore(payload);
1067
+ return result ?? null;
1068
+ } catch (error) {
1069
+ if (isDevelopment5()) {
1070
+ console.error("[oasiz/sdk] " + methodName + " failed:", error);
1071
+ }
1072
+ return null;
1073
+ }
1074
+ }
1075
+ async function addScore(delta) {
1076
+ if (!Number.isInteger(delta)) {
1077
+ if (isDevelopment5()) {
1078
+ console.warn("[oasiz/sdk] addScore expected an integer:", delta);
1079
+ }
1080
+ return null;
1081
+ }
1082
+ if (delta === 0) {
1083
+ return null;
1084
+ }
1085
+ return editScore({ delta }, "addScore");
1086
+ }
1087
+ async function setScore(score) {
1088
+ if (!Number.isInteger(score) || score < 0) {
1089
+ if (isDevelopment5()) {
1090
+ console.warn(
1091
+ "[oasiz/sdk] setScore expected a non-negative integer:",
1092
+ score
1093
+ );
1094
+ }
1095
+ return null;
1096
+ }
1097
+ return editScore({ score }, "setScore");
1000
1098
  }
1001
1099
 
1002
1100
  // src/share.ts
1003
- function isDevelopment4() {
1101
+ function isDevelopment6() {
1004
1102
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1005
1103
  return nodeEnv !== "production";
1006
1104
  }
1007
- function getBridgeWindow4() {
1105
+ function getBridgeWindow6() {
1008
1106
  if (typeof window === "undefined") {
1009
1107
  return void 0;
1010
1108
  }
1011
1109
  return window;
1012
1110
  }
1013
- function warnMissingBridge2(methodName) {
1014
- if (isDevelopment4()) {
1111
+ function warnMissingBridge4(methodName) {
1112
+ if (isDevelopment6()) {
1015
1113
  console.warn(
1016
1114
  "[oasiz/sdk] " + methodName + " share bridge is unavailable. This is expected in local development."
1017
1115
  );
@@ -1054,20 +1152,20 @@ function validateRequest(options) {
1054
1152
  }
1055
1153
  async function share(options) {
1056
1154
  const request = validateRequest(options);
1057
- const bridge = getBridgeWindow4();
1155
+ const bridge = getBridgeWindow6();
1058
1156
  if (typeof bridge?.__oasizShareRequest !== "function") {
1059
- warnMissingBridge2("__oasizShareRequest");
1157
+ warnMissingBridge4("__oasizShareRequest");
1060
1158
  throw new Error("Share bridge unavailable");
1061
1159
  }
1062
1160
  await bridge.__oasizShareRequest(request);
1063
1161
  }
1064
1162
 
1065
1163
  // src/state.ts
1066
- function isDevelopment5() {
1164
+ function isDevelopment7() {
1067
1165
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1068
1166
  return nodeEnv !== "production";
1069
1167
  }
1070
- function getBridgeWindow5() {
1168
+ function getBridgeWindow7() {
1071
1169
  if (typeof window === "undefined") {
1072
1170
  return void 0;
1073
1171
  }
@@ -1080,22 +1178,22 @@ function isPlainObject(value) {
1080
1178
  const proto = Object.getPrototypeOf(value);
1081
1179
  return proto === Object.prototype || proto === null;
1082
1180
  }
1083
- function warnMissingBridge3(methodName) {
1084
- if (isDevelopment5()) {
1181
+ function warnMissingBridge5(methodName) {
1182
+ if (isDevelopment7()) {
1085
1183
  console.warn(
1086
1184
  "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
1087
1185
  );
1088
1186
  }
1089
1187
  }
1090
1188
  function loadGameState() {
1091
- const bridge = getBridgeWindow5();
1189
+ const bridge = getBridgeWindow7();
1092
1190
  if (typeof bridge?.loadGameState !== "function") {
1093
- warnMissingBridge3("loadGameState");
1191
+ warnMissingBridge5("loadGameState");
1094
1192
  return {};
1095
1193
  }
1096
1194
  const state = bridge.loadGameState();
1097
1195
  if (!isPlainObject(state)) {
1098
- if (isDevelopment5()) {
1196
+ if (isDevelopment7()) {
1099
1197
  console.warn(
1100
1198
  "[oasiz/sdk] loadGameState returned invalid data. Falling back to empty object."
1101
1199
  );
@@ -1106,35 +1204,35 @@ function loadGameState() {
1106
1204
  }
1107
1205
  function saveGameState(state) {
1108
1206
  if (!isPlainObject(state)) {
1109
- if (isDevelopment5()) {
1207
+ if (isDevelopment7()) {
1110
1208
  console.warn("[oasiz/sdk] saveGameState expected a plain object:", state);
1111
1209
  }
1112
1210
  return;
1113
1211
  }
1114
- const bridge = getBridgeWindow5();
1212
+ const bridge = getBridgeWindow7();
1115
1213
  if (typeof bridge?.saveGameState === "function") {
1116
1214
  bridge.saveGameState(state);
1117
1215
  return;
1118
1216
  }
1119
- warnMissingBridge3("saveGameState");
1217
+ warnMissingBridge5("saveGameState");
1120
1218
  }
1121
1219
  function flushGameState() {
1122
- const bridge = getBridgeWindow5();
1220
+ const bridge = getBridgeWindow7();
1123
1221
  if (typeof bridge?.flushGameState === "function") {
1124
1222
  bridge.flushGameState();
1125
1223
  return;
1126
1224
  }
1127
- warnMissingBridge3("flushGameState");
1225
+ warnMissingBridge5("flushGameState");
1128
1226
  }
1129
1227
 
1130
1228
  // src/lifecycle.ts
1131
- function isDevelopment6() {
1229
+ function isDevelopment8() {
1132
1230
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1133
1231
  return nodeEnv !== "production";
1134
1232
  }
1135
1233
  function addLifecycleListener(eventName, callback) {
1136
1234
  if (typeof window === "undefined") {
1137
- if (isDevelopment6()) {
1235
+ if (isDevelopment8()) {
1138
1236
  console.warn(
1139
1237
  "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
1140
1238
  );
@@ -1154,18 +1252,18 @@ function onResume(callback) {
1154
1252
  }
1155
1253
 
1156
1254
  // src/layout.ts
1157
- function isDevelopment7() {
1255
+ function isDevelopment9() {
1158
1256
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1159
1257
  return nodeEnv !== "production";
1160
1258
  }
1161
- function getBridgeWindow6() {
1259
+ function getBridgeWindow8() {
1162
1260
  if (typeof window === "undefined") {
1163
1261
  return void 0;
1164
1262
  }
1165
1263
  return window;
1166
1264
  }
1167
- function warnMissingBridge4(methodName) {
1168
- if (isDevelopment7()) {
1265
+ function warnMissingBridge6(methodName) {
1266
+ if (isDevelopment9()) {
1169
1267
  console.warn(
1170
1268
  "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
1171
1269
  );
@@ -1198,7 +1296,7 @@ function pixelsTopToPercentOfViewport(pixels, bridge) {
1198
1296
  return normalizeSafeAreaTopPercent(pixels / h * 100);
1199
1297
  }
1200
1298
  function getSafeAreaTop() {
1201
- const bridge = getBridgeWindow6();
1299
+ const bridge = getBridgeWindow8();
1202
1300
  if (!bridge) {
1203
1301
  return 0;
1204
1302
  }
@@ -1216,12 +1314,12 @@ function getSafeAreaTop() {
1216
1314
  const px = normalizeSafeAreaTopPixels(bridge.__OASIZ_SAFE_AREA_TOP__);
1217
1315
  return pixelsTopToPercentOfViewport(px, bridge);
1218
1316
  }
1219
- warnMissingBridge4("getSafeAreaTop");
1317
+ warnMissingBridge6("getSafeAreaTop");
1220
1318
  return 0;
1221
1319
  }
1222
1320
  function setLeaderboardVisible(visible) {
1223
1321
  if (typeof visible !== "boolean") {
1224
- if (isDevelopment7()) {
1322
+ if (isDevelopment9()) {
1225
1323
  console.warn(
1226
1324
  "[oasiz/sdk] setLeaderboardVisible expected a boolean:",
1227
1325
  visible
@@ -1229,28 +1327,28 @@ function setLeaderboardVisible(visible) {
1229
1327
  }
1230
1328
  return;
1231
1329
  }
1232
- const bridge = getBridgeWindow6();
1330
+ const bridge = getBridgeWindow8();
1233
1331
  if (typeof bridge?.__oasizSetLeaderboardVisible === "function") {
1234
1332
  bridge.__oasizSetLeaderboardVisible(visible);
1235
1333
  return;
1236
1334
  }
1237
- warnMissingBridge4("__oasizSetLeaderboardVisible");
1335
+ warnMissingBridge6("__oasizSetLeaderboardVisible");
1238
1336
  }
1239
1337
 
1240
1338
  // src/navigation.ts
1241
1339
  var activeBackListeners = 0;
1242
- function isDevelopment8() {
1340
+ function isDevelopment10() {
1243
1341
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1244
1342
  return nodeEnv !== "production";
1245
1343
  }
1246
- function getBridgeWindow7() {
1344
+ function getBridgeWindow9() {
1247
1345
  if (typeof window === "undefined") {
1248
1346
  return void 0;
1249
1347
  }
1250
1348
  return window;
1251
1349
  }
1252
- function warnMissingBridge5(methodName) {
1253
- if (isDevelopment8()) {
1350
+ function warnMissingBridge7(methodName) {
1351
+ if (isDevelopment10()) {
1254
1352
  console.warn(
1255
1353
  "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
1256
1354
  );
@@ -1266,7 +1364,7 @@ function normalizeNavigationError(error) {
1266
1364
  }
1267
1365
  function addNavigationListener(eventName, callback) {
1268
1366
  if (typeof window === "undefined") {
1269
- if (isDevelopment8()) {
1367
+ if (isDevelopment10()) {
1270
1368
  console.warn(
1271
1369
  "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
1272
1370
  );
@@ -1287,24 +1385,24 @@ function onBackButton(callback) {
1287
1385
  throw normalizeNavigationError(error);
1288
1386
  }
1289
1387
  });
1290
- const bridge = getBridgeWindow7();
1388
+ const bridge = getBridgeWindow9();
1291
1389
  activeBackListeners += 1;
1292
1390
  if (activeBackListeners === 1) {
1293
1391
  if (typeof bridge?.__oasizSetBackOverride === "function") {
1294
1392
  bridge.__oasizSetBackOverride(true);
1295
1393
  } else {
1296
- warnMissingBridge5("__oasizSetBackOverride");
1394
+ warnMissingBridge7("__oasizSetBackOverride");
1297
1395
  }
1298
1396
  }
1299
1397
  return () => {
1300
1398
  off();
1301
1399
  activeBackListeners = Math.max(0, activeBackListeners - 1);
1302
1400
  if (activeBackListeners === 0) {
1303
- const currentBridge = getBridgeWindow7();
1401
+ const currentBridge = getBridgeWindow9();
1304
1402
  if (typeof currentBridge?.__oasizSetBackOverride === "function") {
1305
1403
  currentBridge.__oasizSetBackOverride(false);
1306
1404
  } else {
1307
- warnMissingBridge5("__oasizSetBackOverride");
1405
+ warnMissingBridge7("__oasizSetBackOverride");
1308
1406
  }
1309
1407
  }
1310
1408
  };
@@ -1313,17 +1411,20 @@ function onLeaveGame(callback) {
1313
1411
  return addNavigationListener("oasiz:leave", callback);
1314
1412
  }
1315
1413
  function leaveGame() {
1316
- const bridge = getBridgeWindow7();
1414
+ const bridge = getBridgeWindow9();
1317
1415
  if (typeof bridge?.__oasizLeaveGame === "function") {
1318
1416
  bridge.__oasizLeaveGame();
1319
1417
  return;
1320
1418
  }
1321
- warnMissingBridge5("__oasizLeaveGame");
1419
+ warnMissingBridge7("__oasizLeaveGame");
1322
1420
  }
1323
1421
 
1324
1422
  // src/index.ts
1325
1423
  var oasiz = {
1326
1424
  submitScore,
1425
+ addScore,
1426
+ setScore,
1427
+ getPlayerCharacter,
1327
1428
  share,
1328
1429
  triggerHaptic,
1329
1430
  enableLogOverlay,
@@ -1345,6 +1446,9 @@ var oasiz = {
1345
1446
  get roomCode() {
1346
1447
  return getRoomCode();
1347
1448
  },
1449
+ get playerId() {
1450
+ return getPlayerId();
1451
+ },
1348
1452
  get playerName() {
1349
1453
  return getPlayerName();
1350
1454
  },
@@ -1356,10 +1460,13 @@ var oasiz = {
1356
1460
  }
1357
1461
  };
1358
1462
  export {
1463
+ addScore,
1359
1464
  enableLogOverlay,
1360
1465
  flushGameState,
1361
1466
  getGameId,
1362
1467
  getPlayerAvatar,
1468
+ getPlayerCharacter,
1469
+ getPlayerId,
1363
1470
  getPlayerName,
1364
1471
  getRoomCode,
1365
1472
  getSafeAreaTop,
@@ -1373,6 +1480,7 @@ export {
1373
1480
  openInviteModal,
1374
1481
  saveGameState,
1375
1482
  setLeaderboardVisible,
1483
+ setScore,
1376
1484
  share,
1377
1485
  shareRoomCode,
1378
1486
  submitScore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oasiz/sdk",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "description": "Typed SDK for Oasiz game platform bridge APIs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",