@oasiz/sdk 1.5.2 → 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,46 +1252,74 @@ 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
  );
1172
1270
  }
1173
1271
  }
1174
- function normalizeSafeAreaTop(value) {
1272
+ function normalizeSafeAreaTopPixels(value) {
1175
1273
  if (typeof value !== "number" || !Number.isFinite(value)) {
1176
1274
  return 0;
1177
1275
  }
1178
1276
  return Math.max(0, value);
1179
1277
  }
1278
+ function normalizeSafeAreaTopPercent(value) {
1279
+ if (typeof value !== "number" || !Number.isFinite(value)) {
1280
+ return 0;
1281
+ }
1282
+ return Math.min(100, Math.max(0, value));
1283
+ }
1284
+ function viewportInnerHeight(bridge) {
1285
+ const h = bridge.innerHeight;
1286
+ if (typeof h !== "number" || !Number.isFinite(h) || h <= 0) {
1287
+ return 0;
1288
+ }
1289
+ return h;
1290
+ }
1291
+ function pixelsTopToPercentOfViewport(pixels, bridge) {
1292
+ const h = viewportInnerHeight(bridge);
1293
+ if (h <= 0) {
1294
+ return 0;
1295
+ }
1296
+ return normalizeSafeAreaTopPercent(pixels / h * 100);
1297
+ }
1180
1298
  function getSafeAreaTop() {
1181
- const bridge = getBridgeWindow6();
1299
+ const bridge = getBridgeWindow8();
1182
1300
  if (!bridge) {
1183
1301
  return 0;
1184
1302
  }
1303
+ if (typeof bridge.getSafeAreaTopPercent === "function") {
1304
+ return normalizeSafeAreaTopPercent(bridge.getSafeAreaTopPercent());
1305
+ }
1306
+ if (typeof bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__ !== "undefined") {
1307
+ return normalizeSafeAreaTopPercent(bridge.__OASIZ_SAFE_AREA_TOP_PERCENT__);
1308
+ }
1185
1309
  if (typeof bridge.getSafeAreaTop === "function") {
1186
- return normalizeSafeAreaTop(bridge.getSafeAreaTop());
1310
+ const px = normalizeSafeAreaTopPixels(bridge.getSafeAreaTop());
1311
+ return pixelsTopToPercentOfViewport(px, bridge);
1187
1312
  }
1188
1313
  if (typeof bridge.__OASIZ_SAFE_AREA_TOP__ !== "undefined") {
1189
- return normalizeSafeAreaTop(bridge.__OASIZ_SAFE_AREA_TOP__);
1314
+ const px = normalizeSafeAreaTopPixels(bridge.__OASIZ_SAFE_AREA_TOP__);
1315
+ return pixelsTopToPercentOfViewport(px, bridge);
1190
1316
  }
1191
- warnMissingBridge4("getSafeAreaTop");
1317
+ warnMissingBridge6("getSafeAreaTop");
1192
1318
  return 0;
1193
1319
  }
1194
1320
  function setLeaderboardVisible(visible) {
1195
1321
  if (typeof visible !== "boolean") {
1196
- if (isDevelopment7()) {
1322
+ if (isDevelopment9()) {
1197
1323
  console.warn(
1198
1324
  "[oasiz/sdk] setLeaderboardVisible expected a boolean:",
1199
1325
  visible
@@ -1201,28 +1327,28 @@ function setLeaderboardVisible(visible) {
1201
1327
  }
1202
1328
  return;
1203
1329
  }
1204
- const bridge = getBridgeWindow6();
1330
+ const bridge = getBridgeWindow8();
1205
1331
  if (typeof bridge?.__oasizSetLeaderboardVisible === "function") {
1206
1332
  bridge.__oasizSetLeaderboardVisible(visible);
1207
1333
  return;
1208
1334
  }
1209
- warnMissingBridge4("__oasizSetLeaderboardVisible");
1335
+ warnMissingBridge6("__oasizSetLeaderboardVisible");
1210
1336
  }
1211
1337
 
1212
1338
  // src/navigation.ts
1213
1339
  var activeBackListeners = 0;
1214
- function isDevelopment8() {
1340
+ function isDevelopment10() {
1215
1341
  const nodeEnv = globalThis.process?.env?.NODE_ENV;
1216
1342
  return nodeEnv !== "production";
1217
1343
  }
1218
- function getBridgeWindow7() {
1344
+ function getBridgeWindow9() {
1219
1345
  if (typeof window === "undefined") {
1220
1346
  return void 0;
1221
1347
  }
1222
1348
  return window;
1223
1349
  }
1224
- function warnMissingBridge5(methodName) {
1225
- if (isDevelopment8()) {
1350
+ function warnMissingBridge7(methodName) {
1351
+ if (isDevelopment10()) {
1226
1352
  console.warn(
1227
1353
  "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
1228
1354
  );
@@ -1238,7 +1364,7 @@ function normalizeNavigationError(error) {
1238
1364
  }
1239
1365
  function addNavigationListener(eventName, callback) {
1240
1366
  if (typeof window === "undefined") {
1241
- if (isDevelopment8()) {
1367
+ if (isDevelopment10()) {
1242
1368
  console.warn(
1243
1369
  "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
1244
1370
  );
@@ -1259,24 +1385,24 @@ function onBackButton(callback) {
1259
1385
  throw normalizeNavigationError(error);
1260
1386
  }
1261
1387
  });
1262
- const bridge = getBridgeWindow7();
1388
+ const bridge = getBridgeWindow9();
1263
1389
  activeBackListeners += 1;
1264
1390
  if (activeBackListeners === 1) {
1265
1391
  if (typeof bridge?.__oasizSetBackOverride === "function") {
1266
1392
  bridge.__oasizSetBackOverride(true);
1267
1393
  } else {
1268
- warnMissingBridge5("__oasizSetBackOverride");
1394
+ warnMissingBridge7("__oasizSetBackOverride");
1269
1395
  }
1270
1396
  }
1271
1397
  return () => {
1272
1398
  off();
1273
1399
  activeBackListeners = Math.max(0, activeBackListeners - 1);
1274
1400
  if (activeBackListeners === 0) {
1275
- const currentBridge = getBridgeWindow7();
1401
+ const currentBridge = getBridgeWindow9();
1276
1402
  if (typeof currentBridge?.__oasizSetBackOverride === "function") {
1277
1403
  currentBridge.__oasizSetBackOverride(false);
1278
1404
  } else {
1279
- warnMissingBridge5("__oasizSetBackOverride");
1405
+ warnMissingBridge7("__oasizSetBackOverride");
1280
1406
  }
1281
1407
  }
1282
1408
  };
@@ -1285,17 +1411,20 @@ function onLeaveGame(callback) {
1285
1411
  return addNavigationListener("oasiz:leave", callback);
1286
1412
  }
1287
1413
  function leaveGame() {
1288
- const bridge = getBridgeWindow7();
1414
+ const bridge = getBridgeWindow9();
1289
1415
  if (typeof bridge?.__oasizLeaveGame === "function") {
1290
1416
  bridge.__oasizLeaveGame();
1291
1417
  return;
1292
1418
  }
1293
- warnMissingBridge5("__oasizLeaveGame");
1419
+ warnMissingBridge7("__oasizLeaveGame");
1294
1420
  }
1295
1421
 
1296
1422
  // src/index.ts
1297
1423
  var oasiz = {
1298
1424
  submitScore,
1425
+ addScore,
1426
+ setScore,
1427
+ getPlayerCharacter,
1299
1428
  share,
1300
1429
  triggerHaptic,
1301
1430
  enableLogOverlay,
@@ -1317,6 +1446,9 @@ var oasiz = {
1317
1446
  get roomCode() {
1318
1447
  return getRoomCode();
1319
1448
  },
1449
+ get playerId() {
1450
+ return getPlayerId();
1451
+ },
1320
1452
  get playerName() {
1321
1453
  return getPlayerName();
1322
1454
  },
@@ -1328,10 +1460,13 @@ var oasiz = {
1328
1460
  }
1329
1461
  };
1330
1462
  export {
1463
+ addScore,
1331
1464
  enableLogOverlay,
1332
1465
  flushGameState,
1333
1466
  getGameId,
1334
1467
  getPlayerAvatar,
1468
+ getPlayerCharacter,
1469
+ getPlayerId,
1335
1470
  getPlayerName,
1336
1471
  getRoomCode,
1337
1472
  getSafeAreaTop,
@@ -1345,6 +1480,7 @@ export {
1345
1480
  openInviteModal,
1346
1481
  saveGameState,
1347
1482
  setLeaderboardVisible,
1483
+ setScore,
1348
1484
  share,
1349
1485
  shareRoomCode,
1350
1486
  submitScore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oasiz/sdk",
3
- "version": "1.5.2",
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",