@oasiz/sdk 1.0.1 → 1.1.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.js CHANGED
@@ -33,10 +33,10 @@ function getBridgeWindow2() {
33
33
  }
34
34
  return window;
35
35
  }
36
- function shareRoomCode(roomCode) {
36
+ function shareRoomCode(roomCode, options) {
37
37
  const bridge = getBridgeWindow2();
38
38
  if (typeof bridge?.shareRoomCode === "function") {
39
- bridge.shareRoomCode(roomCode);
39
+ bridge.shareRoomCode(roomCode, options);
40
40
  return;
41
41
  }
42
42
  if (isDevelopment2()) {
@@ -45,6 +45,18 @@ function shareRoomCode(roomCode) {
45
45
  );
46
46
  }
47
47
  }
48
+ function openInviteModal() {
49
+ const bridge = getBridgeWindow2();
50
+ if (typeof bridge?.openInviteModal === "function") {
51
+ bridge.openInviteModal();
52
+ return;
53
+ }
54
+ if (isDevelopment2()) {
55
+ console.warn(
56
+ "[oasiz/sdk] openInviteModal bridge is unavailable. This is expected in local development."
57
+ );
58
+ }
59
+ }
48
60
  function getGameId() {
49
61
  const bridge = getBridgeWindow2();
50
62
  return bridge?.__GAME_ID__;
@@ -95,6 +107,14 @@ function submitScore(score) {
95
107
  }
96
108
  warnMissingBridge("submitScore");
97
109
  }
110
+ function emitScoreConfig(config) {
111
+ const bridge = getBridgeWindow3();
112
+ if (typeof bridge?.emitScoreConfig === "function") {
113
+ bridge.emitScoreConfig(config);
114
+ return;
115
+ }
116
+ warnMissingBridge("emitScoreConfig");
117
+ }
98
118
 
99
119
  // src/state.ts
100
120
  function isDevelopment4() {
@@ -187,16 +207,90 @@ function onResume(callback) {
187
207
  return addLifecycleListener("oasiz:resume", callback);
188
208
  }
189
209
 
210
+ // src/navigation.ts
211
+ var activeBackListeners = 0;
212
+ function isDevelopment6() {
213
+ const nodeEnv = globalThis.process?.env?.NODE_ENV;
214
+ return nodeEnv !== "production";
215
+ }
216
+ function getBridgeWindow5() {
217
+ if (typeof window === "undefined") {
218
+ return void 0;
219
+ }
220
+ return window;
221
+ }
222
+ function warnMissingBridge3(methodName) {
223
+ if (isDevelopment6()) {
224
+ console.warn(
225
+ "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
226
+ );
227
+ }
228
+ }
229
+ function addNavigationListener(eventName, callback) {
230
+ if (typeof window === "undefined") {
231
+ if (isDevelopment6()) {
232
+ console.warn(
233
+ "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
234
+ );
235
+ }
236
+ return () => {
237
+ };
238
+ }
239
+ const handler = () => callback();
240
+ window.addEventListener(eventName, handler);
241
+ return () => window.removeEventListener(eventName, handler);
242
+ }
243
+ function onBackButton(callback) {
244
+ const off = addNavigationListener("oasiz:back", callback);
245
+ const bridge = getBridgeWindow5();
246
+ activeBackListeners += 1;
247
+ if (activeBackListeners === 1) {
248
+ if (typeof bridge?.__oasizSetBackOverride === "function") {
249
+ bridge.__oasizSetBackOverride(true);
250
+ } else {
251
+ warnMissingBridge3("__oasizSetBackOverride");
252
+ }
253
+ }
254
+ return () => {
255
+ off();
256
+ activeBackListeners = Math.max(0, activeBackListeners - 1);
257
+ if (activeBackListeners === 0) {
258
+ const currentBridge = getBridgeWindow5();
259
+ if (typeof currentBridge?.__oasizSetBackOverride === "function") {
260
+ currentBridge.__oasizSetBackOverride(false);
261
+ } else {
262
+ warnMissingBridge3("__oasizSetBackOverride");
263
+ }
264
+ }
265
+ };
266
+ }
267
+ function onLeaveGame(callback) {
268
+ return addNavigationListener("oasiz:leave", callback);
269
+ }
270
+ function leaveGame() {
271
+ const bridge = getBridgeWindow5();
272
+ if (typeof bridge?.__oasizLeaveGame === "function") {
273
+ bridge.__oasizLeaveGame();
274
+ return;
275
+ }
276
+ warnMissingBridge3("__oasizLeaveGame");
277
+ }
278
+
190
279
  // src/index.ts
191
280
  var oasiz = {
192
281
  submitScore,
282
+ emitScoreConfig,
193
283
  triggerHaptic,
194
284
  loadGameState,
195
285
  saveGameState,
196
286
  flushGameState,
197
287
  shareRoomCode,
288
+ openInviteModal,
198
289
  onPause,
199
290
  onResume,
291
+ onBackButton,
292
+ onLeaveGame,
293
+ leaveGame,
200
294
  get gameId() {
201
295
  return getGameId();
202
296
  },
@@ -211,15 +305,20 @@ var oasiz = {
211
305
  }
212
306
  };
213
307
  export {
308
+ emitScoreConfig,
214
309
  flushGameState,
215
310
  getGameId,
216
311
  getPlayerAvatar,
217
312
  getPlayerName,
218
313
  getRoomCode,
314
+ leaveGame,
219
315
  loadGameState,
220
316
  oasiz,
317
+ onBackButton,
318
+ onLeaveGame,
221
319
  onPause,
222
320
  onResume,
321
+ openInviteModal,
223
322
  saveGameState,
224
323
  shareRoomCode,
225
324
  submitScore,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oasiz/sdk",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Typed SDK for Oasiz game platform bridge APIs.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -10,8 +10,7 @@
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js",
13
- "require": "./dist/index.cjs",
14
- "script": "./dist/index.global.js"
13
+ "require": "./dist/index.cjs"
15
14
  }
16
15
  },
17
16
  "files": [
@@ -19,11 +18,9 @@
19
18
  ],
20
19
  "sideEffects": false,
21
20
  "scripts": {
22
- "build": "tsup src/index.ts --format esm,cjs,iife --global-name oasiz --dts",
21
+ "build": "tsup src/index.ts --format esm,cjs --dts",
23
22
  "prepack": "bun run build",
24
- "test": "node --experimental-strip-types --test ./tests/**/*.test.ts",
25
- "docs": "typedoc",
26
- "docs:watch": "typedoc --watch"
23
+ "test": "node --experimental-strip-types --test ./tests/**/*.test.ts"
27
24
  },
28
25
  "publishConfig": {
29
26
  "access": "public"
@@ -50,7 +47,6 @@
50
47
  "@types/node": "^25.3.0",
51
48
  "semantic-release": "^25.0.3",
52
49
  "tsup": "^8.5.1",
53
- "typedoc": "^0.28.17",
54
50
  "typescript": "^5.9.3"
55
51
  }
56
52
  }
@@ -1,252 +0,0 @@
1
- "use strict";
2
- var oasiz = (() => {
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- flushGameState: () => flushGameState,
25
- getGameId: () => getGameId,
26
- getPlayerAvatar: () => getPlayerAvatar,
27
- getPlayerName: () => getPlayerName,
28
- getRoomCode: () => getRoomCode,
29
- loadGameState: () => loadGameState,
30
- oasiz: () => oasiz,
31
- onPause: () => onPause,
32
- onResume: () => onResume,
33
- saveGameState: () => saveGameState,
34
- shareRoomCode: () => shareRoomCode,
35
- submitScore: () => submitScore,
36
- triggerHaptic: () => triggerHaptic
37
- });
38
-
39
- // src/haptics.ts
40
- function isDevelopment() {
41
- const nodeEnv = globalThis.process?.env?.NODE_ENV;
42
- return nodeEnv !== "production";
43
- }
44
- function getBridgeWindow() {
45
- if (typeof window === "undefined") {
46
- return void 0;
47
- }
48
- return window;
49
- }
50
- function triggerHaptic(type) {
51
- const bridge = getBridgeWindow();
52
- if (typeof bridge?.triggerHaptic === "function") {
53
- bridge.triggerHaptic(type);
54
- return;
55
- }
56
- if (isDevelopment()) {
57
- console.warn(
58
- "[oasiz/sdk] triggerHaptic bridge is unavailable. This is expected in local development."
59
- );
60
- }
61
- }
62
-
63
- // src/multiplayer.ts
64
- function isDevelopment2() {
65
- const nodeEnv = globalThis.process?.env?.NODE_ENV;
66
- return nodeEnv !== "production";
67
- }
68
- function getBridgeWindow2() {
69
- if (typeof window === "undefined") {
70
- return void 0;
71
- }
72
- return window;
73
- }
74
- function shareRoomCode(roomCode) {
75
- const bridge = getBridgeWindow2();
76
- if (typeof bridge?.shareRoomCode === "function") {
77
- bridge.shareRoomCode(roomCode);
78
- return;
79
- }
80
- if (isDevelopment2()) {
81
- console.warn(
82
- "[oasiz/sdk] shareRoomCode bridge is unavailable. This is expected in local development."
83
- );
84
- }
85
- }
86
- function getGameId() {
87
- const bridge = getBridgeWindow2();
88
- return bridge?.__GAME_ID__;
89
- }
90
- function getRoomCode() {
91
- const bridge = getBridgeWindow2();
92
- return bridge?.__ROOM_CODE__;
93
- }
94
- function getPlayerName() {
95
- const bridge = getBridgeWindow2();
96
- return bridge?.__PLAYER_NAME__;
97
- }
98
- function getPlayerAvatar() {
99
- const bridge = getBridgeWindow2();
100
- return bridge?.__PLAYER_AVATAR__;
101
- }
102
-
103
- // src/score.ts
104
- function isDevelopment3() {
105
- const nodeEnv = globalThis.process?.env?.NODE_ENV;
106
- return nodeEnv !== "production";
107
- }
108
- function warnMissingBridge(methodName) {
109
- if (isDevelopment3()) {
110
- console.warn(
111
- "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
112
- );
113
- }
114
- }
115
- function getBridgeWindow3() {
116
- if (typeof window === "undefined") {
117
- return void 0;
118
- }
119
- return window;
120
- }
121
- function submitScore(score) {
122
- if (!Number.isFinite(score)) {
123
- if (isDevelopment3()) {
124
- console.warn("[oasiz/sdk] submitScore expected a finite number:", score);
125
- }
126
- return;
127
- }
128
- const bridge = getBridgeWindow3();
129
- const normalizedScore = Math.max(0, Math.floor(score));
130
- if (typeof bridge?.submitScore === "function") {
131
- bridge.submitScore(normalizedScore);
132
- return;
133
- }
134
- warnMissingBridge("submitScore");
135
- }
136
-
137
- // src/state.ts
138
- function isDevelopment4() {
139
- const nodeEnv = globalThis.process?.env?.NODE_ENV;
140
- return nodeEnv !== "production";
141
- }
142
- function getBridgeWindow4() {
143
- if (typeof window === "undefined") {
144
- return void 0;
145
- }
146
- return window;
147
- }
148
- function isPlainObject(value) {
149
- if (!value || typeof value !== "object" || Array.isArray(value)) {
150
- return false;
151
- }
152
- const proto = Object.getPrototypeOf(value);
153
- return proto === Object.prototype || proto === null;
154
- }
155
- function warnMissingBridge2(methodName) {
156
- if (isDevelopment4()) {
157
- console.warn(
158
- "[oasiz/sdk] " + methodName + " bridge is unavailable. This is expected in local development."
159
- );
160
- }
161
- }
162
- function loadGameState() {
163
- const bridge = getBridgeWindow4();
164
- if (typeof bridge?.loadGameState !== "function") {
165
- warnMissingBridge2("loadGameState");
166
- return {};
167
- }
168
- const state = bridge.loadGameState();
169
- if (!isPlainObject(state)) {
170
- if (isDevelopment4()) {
171
- console.warn(
172
- "[oasiz/sdk] loadGameState returned invalid data. Falling back to empty object."
173
- );
174
- }
175
- return {};
176
- }
177
- return state;
178
- }
179
- function saveGameState(state) {
180
- if (!isPlainObject(state)) {
181
- if (isDevelopment4()) {
182
- console.warn("[oasiz/sdk] saveGameState expected a plain object:", state);
183
- }
184
- return;
185
- }
186
- const bridge = getBridgeWindow4();
187
- if (typeof bridge?.saveGameState === "function") {
188
- bridge.saveGameState(state);
189
- return;
190
- }
191
- warnMissingBridge2("saveGameState");
192
- }
193
- function flushGameState() {
194
- const bridge = getBridgeWindow4();
195
- if (typeof bridge?.flushGameState === "function") {
196
- bridge.flushGameState();
197
- return;
198
- }
199
- warnMissingBridge2("flushGameState");
200
- }
201
-
202
- // src/lifecycle.ts
203
- function isDevelopment5() {
204
- const nodeEnv = globalThis.process?.env?.NODE_ENV;
205
- return nodeEnv !== "production";
206
- }
207
- function addLifecycleListener(eventName, callback) {
208
- if (typeof window === "undefined") {
209
- if (isDevelopment5()) {
210
- console.warn(
211
- "[oasiz/sdk] " + eventName + " listener registered without a browser window. This is expected in local development."
212
- );
213
- }
214
- return () => {
215
- };
216
- }
217
- const handler = () => callback();
218
- window.addEventListener(eventName, handler);
219
- return () => window.removeEventListener(eventName, handler);
220
- }
221
- function onPause(callback) {
222
- return addLifecycleListener("oasiz:pause", callback);
223
- }
224
- function onResume(callback) {
225
- return addLifecycleListener("oasiz:resume", callback);
226
- }
227
-
228
- // src/index.ts
229
- var oasiz = {
230
- submitScore,
231
- triggerHaptic,
232
- loadGameState,
233
- saveGameState,
234
- flushGameState,
235
- shareRoomCode,
236
- onPause,
237
- onResume,
238
- get gameId() {
239
- return getGameId();
240
- },
241
- get roomCode() {
242
- return getRoomCode();
243
- },
244
- get playerName() {
245
- return getPlayerName();
246
- },
247
- get playerAvatar() {
248
- return getPlayerAvatar();
249
- }
250
- };
251
- return __toCommonJS(index_exports);
252
- })();