@babylonjs-toolkit/next 9.34.100 → 9.35.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.
Files changed (109) hide show
  1. package/lib/index.d.ts +80 -14
  2. package/lib/index.d.ts.map +1 -1
  3. package/lib/index.js +80 -14
  4. package/lib/leaderboardaroundpage.d.ts +5 -0
  5. package/lib/leaderboardaroundpage.d.ts.map +1 -0
  6. package/lib/leaderboardaroundpage.js +1 -0
  7. package/lib/leaderboardcallresult.d.ts +13 -0
  8. package/lib/leaderboardcallresult.d.ts.map +1 -0
  9. package/lib/leaderboardcallresult.js +1 -0
  10. package/lib/leaderboardclient.d.ts +95 -0
  11. package/lib/leaderboardclient.d.ts.map +1 -0
  12. package/lib/leaderboardclient.js +448 -0
  13. package/lib/leaderboardclientoptions.d.ts +12 -0
  14. package/lib/leaderboardclientoptions.d.ts.map +1 -0
  15. package/lib/leaderboardclientoptions.js +1 -0
  16. package/lib/leaderboardentriespage.d.ts +10 -0
  17. package/lib/leaderboardentriespage.d.ts.map +1 -0
  18. package/lib/leaderboardentriespage.js +1 -0
  19. package/lib/leaderboardentryview.d.ts +14 -0
  20. package/lib/leaderboardentryview.d.ts.map +1 -0
  21. package/lib/leaderboardentryview.js +1 -0
  22. package/lib/leaderboarderrorbody.d.ts +6 -0
  23. package/lib/leaderboarderrorbody.d.ts.map +1 -0
  24. package/lib/leaderboarderrorbody.js +1 -0
  25. package/lib/leaderboardfetch.d.ts +2 -0
  26. package/lib/leaderboardfetch.d.ts.map +1 -0
  27. package/lib/leaderboardfetch.js +1 -0
  28. package/lib/leaderboardkeeppolicy.d.ts +2 -0
  29. package/lib/leaderboardkeeppolicy.d.ts.map +1 -0
  30. package/lib/leaderboardkeeppolicy.js +1 -0
  31. package/lib/leaderboardmetadata.d.ts +5 -0
  32. package/lib/leaderboardmetadata.d.ts.map +1 -0
  33. package/lib/leaderboardmetadata.js +1 -0
  34. package/lib/leaderboardmetadatavalue.d.ts +4 -0
  35. package/lib/leaderboardmetadatavalue.d.ts.map +1 -0
  36. package/lib/leaderboardmetadatavalue.js +1 -0
  37. package/lib/leaderboardplayersession.d.ts +6 -0
  38. package/lib/leaderboardplayersession.d.ts.map +1 -0
  39. package/lib/leaderboardplayersession.js +1 -0
  40. package/lib/leaderboardplayerview.d.ts +7 -0
  41. package/lib/leaderboardplayerview.d.ts.map +1 -0
  42. package/lib/leaderboardplayerview.js +1 -0
  43. package/lib/leaderboardpostattempt.d.ts +6 -0
  44. package/lib/leaderboardpostattempt.d.ts.map +1 -0
  45. package/lib/leaderboardpostattempt.js +1 -0
  46. package/lib/leaderboardpublicboardview.d.ts +17 -0
  47. package/lib/leaderboardpublicboardview.d.ts.map +1 -0
  48. package/lib/leaderboardpublicboardview.js +1 -0
  49. package/lib/leaderboardrangequery.d.ts +7 -0
  50. package/lib/leaderboardrangequery.d.ts.map +1 -0
  51. package/lib/leaderboardrangequery.js +1 -0
  52. package/lib/leaderboardrefusalreason.d.ts +2 -0
  53. package/lib/leaderboardrefusalreason.d.ts.map +1 -0
  54. package/lib/leaderboardrefusalreason.js +1 -0
  55. package/lib/leaderboardscoreformat.d.ts +2 -0
  56. package/lib/leaderboardscoreformat.d.ts.map +1 -0
  57. package/lib/leaderboardscoreformat.js +1 -0
  58. package/lib/leaderboardscoreresult.d.ts +18 -0
  59. package/lib/leaderboardscoreresult.d.ts.map +1 -0
  60. package/lib/leaderboardscoreresult.js +1 -0
  61. package/lib/leaderboardscoresubmission.d.ts +8 -0
  62. package/lib/leaderboardscoresubmission.d.ts.map +1 -0
  63. package/lib/leaderboardscoresubmission.js +1 -0
  64. package/lib/leaderboardseasonview.d.ts +7 -0
  65. package/lib/leaderboardseasonview.d.ts.map +1 -0
  66. package/lib/leaderboardseasonview.js +1 -0
  67. package/lib/leaderboardsortorder.d.ts +2 -0
  68. package/lib/leaderboardsortorder.d.ts.map +1 -0
  69. package/lib/leaderboardsortorder.js +1 -0
  70. package/lib/leaderboardstorage.d.ts +6 -0
  71. package/lib/leaderboardstorage.d.ts.map +1 -0
  72. package/lib/leaderboardstorage.js +1 -0
  73. package/lib/leaderboardstoredplayer.d.ts +5 -0
  74. package/lib/leaderboardstoredplayer.d.ts.map +1 -0
  75. package/lib/leaderboardstoredplayer.js +1 -0
  76. package/lib/leaderboardsubmission.d.ts +8 -0
  77. package/lib/leaderboardsubmission.d.ts.map +1 -0
  78. package/lib/leaderboardsubmission.js +1 -0
  79. package/lib/leaderboardsubmissionrequest.d.ts +12 -0
  80. package/lib/leaderboardsubmissionrequest.d.ts.map +1 -0
  81. package/lib/leaderboardsubmissionrequest.js +1 -0
  82. package/lib/leaderboardsubmissionresponse.d.ts +7 -0
  83. package/lib/leaderboardsubmissionresponse.d.ts.map +1 -0
  84. package/lib/leaderboardsubmissionresponse.js +1 -0
  85. package/lib/leaderboardsubmitresult.d.ts +15 -0
  86. package/lib/leaderboardsubmitresult.d.ts.map +1 -0
  87. package/lib/leaderboardsubmitresult.js +1 -0
  88. package/lib/leaderboardtarget.d.ts +6 -0
  89. package/lib/leaderboardtarget.d.ts.map +1 -0
  90. package/lib/leaderboardtarget.js +1 -0
  91. package/lib/leaderboardtargetentry.d.ts +9 -0
  92. package/lib/leaderboardtargetentry.d.ts.map +1 -0
  93. package/lib/leaderboardtargetentry.js +1 -0
  94. package/lib/leaderboardtrustlevel.d.ts +2 -0
  95. package/lib/leaderboardtrustlevel.d.ts.map +1 -0
  96. package/lib/leaderboardtrustlevel.js +1 -0
  97. package/lib/leaderboardvariantdimension.d.ts +6 -0
  98. package/lib/leaderboardvariantdimension.d.ts.map +1 -0
  99. package/lib/leaderboardvariantdimension.js +1 -0
  100. package/lib/leaderboardwriteoutcome.d.ts +2 -0
  101. package/lib/leaderboardwriteoutcome.d.ts.map +1 -0
  102. package/lib/leaderboardwriteoutcome.js +1 -0
  103. package/lib/project.d.ts +15 -0
  104. package/lib/project.d.ts.map +1 -1
  105. package/lib/project.js +74 -14
  106. package/lib/scenemanager.d.ts +5 -0
  107. package/lib/scenemanager.d.ts.map +1 -1
  108. package/lib/scenemanager.js +46 -23
  109. package/package.json +17 -13
@@ -0,0 +1,448 @@
1
+ export class LeaderboardClient {
2
+ constructor(options) {
3
+ this.memoryPlayer = null;
4
+ this.memoryPending = [];
5
+ this.storageFailed = false;
6
+ this.flushInFlight = null;
7
+ this.endpoint = LeaderboardClient.toHttpEndpoint(options.serverUrl);
8
+ this.authToken = options.authToken ?? "";
9
+ this.buildVersion = options.buildVersion ?? null;
10
+ this.storage = (options.storage !== undefined) ? options.storage : LeaderboardClient.defaultStorage();
11
+ this.fetchFunction = options.fetchFunction ?? null;
12
+ this.requestTimeoutMs = options.requestTimeoutMs ?? LeaderboardClient.DEFAULT_REQUEST_TIMEOUT_MS;
13
+ this.maximumPendingSubmissions = options.maximumPendingSubmissions ?? LeaderboardClient.DEFAULT_MAXIMUM_PENDING_SUBMISSIONS;
14
+ }
15
+ get httpEndpoint() {
16
+ return this.endpoint;
17
+ }
18
+ get pendingCount() {
19
+ return this.readPending().length;
20
+ }
21
+ get playerKey() {
22
+ const storedPlayer = this.readStoredPlayer();
23
+ return (storedPlayer != null) ? storedPlayer.playerKey : null;
24
+ }
25
+ static toHttpEndpoint(serverUrl) {
26
+ if (serverUrl.startsWith("wss://"))
27
+ return "https://" + serverUrl.substring("wss://".length);
28
+ if (serverUrl.startsWith("ws://"))
29
+ return "http://" + serverUrl.substring("ws://".length);
30
+ return serverUrl;
31
+ }
32
+ setAuthToken(token) {
33
+ this.authToken = token ?? "";
34
+ }
35
+ forgetPlayerKey() {
36
+ this.forgetPlayer();
37
+ }
38
+ async getPlayer() {
39
+ try {
40
+ const storedPlayer = this.readStoredPlayer();
41
+ const firstAnswer = await this.requestPlayerSession(storedPlayer);
42
+ if (storedPlayer == null || !LeaderboardClient.isInvalidPlayer(firstAnswer))
43
+ return firstAnswer;
44
+ this.forgetPlayer();
45
+ return await this.requestPlayerSession(null);
46
+ }
47
+ catch (error) {
48
+ return LeaderboardClient.notSent(error);
49
+ }
50
+ }
51
+ async setDisplayName(displayName) {
52
+ try {
53
+ return await this.postAsIdentifiedPlayer("players/me/name", { displayName: displayName });
54
+ }
55
+ catch (error) {
56
+ return LeaderboardClient.notSent(error);
57
+ }
58
+ }
59
+ async submit(submission) {
60
+ let request = null;
61
+ try {
62
+ request = this.buildSubmissionRequest(submission);
63
+ await this.flushPending();
64
+ const answer = await this.postSubmission(request);
65
+ if (answer.status === "ok")
66
+ return { status: "sent", response: answer.value };
67
+ if (answer.status === "refused") {
68
+ if (LeaderboardClient.isAuthRefusal(answer))
69
+ this.queueSubmission(request);
70
+ return { status: "refused", reason: answer.reason, message: answer.message };
71
+ }
72
+ return this.queueSubmission(request);
73
+ }
74
+ catch (error) {
75
+ if (request != null)
76
+ return this.queueSubmission(request);
77
+ return { status: "refused", reason: "invalidRequest", message: LeaderboardClient.describeError(error) };
78
+ }
79
+ }
80
+ async flushPending() {
81
+ if (this.flushInFlight != null)
82
+ return this.flushInFlight;
83
+ this.flushInFlight = this.flushQueue();
84
+ try {
85
+ return await this.flushInFlight;
86
+ }
87
+ finally {
88
+ this.flushInFlight = null;
89
+ }
90
+ }
91
+ async listBoards() {
92
+ return this.getJson("boards");
93
+ }
94
+ async listSeasons(boardId) {
95
+ return this.getJson("boards/" + encodeURIComponent(boardId) + "/seasons");
96
+ }
97
+ async getTop(boardId, query) {
98
+ try {
99
+ const range = query ?? {};
100
+ const parameters = [
101
+ ["variant", (range.variant != null) ? JSON.stringify(range.variant) : undefined],
102
+ ["season", range.seasonId],
103
+ ["offset", range.offset],
104
+ ["limit", range.limit]
105
+ ];
106
+ const path = "boards/" + encodeURIComponent(boardId) + "/entries" + LeaderboardClient.queryString(parameters);
107
+ return await this.getJson(path);
108
+ }
109
+ catch (error) {
110
+ return LeaderboardClient.notSent(error);
111
+ }
112
+ }
113
+ async getAroundMe(boardId, variant, window, seasonId) {
114
+ try {
115
+ const body = { variant: variant ?? null };
116
+ if (seasonId !== undefined)
117
+ body.seasonId = seasonId;
118
+ if (window !== undefined)
119
+ body.window = window;
120
+ return await this.postAsStoredPlayer("boards/" + encodeURIComponent(boardId) + "/around", body);
121
+ }
122
+ catch (error) {
123
+ return LeaderboardClient.notSent(error);
124
+ }
125
+ }
126
+ async getMyEntries(targets) {
127
+ try {
128
+ return await this.postAsStoredPlayer("entries/mine", { targets: targets });
129
+ }
130
+ catch (error) {
131
+ return LeaderboardClient.notSent(error);
132
+ }
133
+ }
134
+ async getPlayersEntries(boardId, playerIds, variant, seasonId) {
135
+ try {
136
+ const body = { variant: variant ?? null, playerIds: playerIds };
137
+ if (seasonId !== undefined)
138
+ body.seasonId = seasonId;
139
+ return await this.postJson("boards/" + encodeURIComponent(boardId) + "/players", body);
140
+ }
141
+ catch (error) {
142
+ return LeaderboardClient.notSent(error);
143
+ }
144
+ }
145
+ async deleteMyData() {
146
+ try {
147
+ const answer = await this.postAsStoredPlayer("players/me/delete", {});
148
+ if (answer.status !== "ok")
149
+ return answer;
150
+ this.forgetPlayer();
151
+ this.writePending([]);
152
+ return { status: "ok", value: answer.value.erasedEntries };
153
+ }
154
+ catch (error) {
155
+ return LeaderboardClient.notSent(error);
156
+ }
157
+ }
158
+ postJson(path, body) {
159
+ return this.send("POST", path, body);
160
+ }
161
+ getJson(path) {
162
+ return this.send("GET", path, null);
163
+ }
164
+ async send(method, path, body) {
165
+ try {
166
+ const fetchFunction = this.fetchFunction ?? LeaderboardClient.globalFetch();
167
+ if (fetchFunction == null)
168
+ return { status: "notSent", message: LeaderboardClient.NO_FETCH_MESSAGE };
169
+ const response = await fetchFunction(this.routeUrl(path), this.requestInit(method, body));
170
+ const answerBody = await LeaderboardClient.readBody(response);
171
+ return LeaderboardClient.sortAnswer(response.status, answerBody);
172
+ }
173
+ catch (error) {
174
+ return LeaderboardClient.notSent(error);
175
+ }
176
+ }
177
+ routeUrl(path) {
178
+ const base = this.endpoint.endsWith("/") ? this.endpoint.substring(0, this.endpoint.length - 1) : this.endpoint;
179
+ return base + LeaderboardClient.API_PATH + path;
180
+ }
181
+ requestInit(method, body) {
182
+ const headers = {};
183
+ if (body != null)
184
+ headers["Content-Type"] = "application/json";
185
+ if (this.authToken.length > 0)
186
+ headers["Authorization"] = "Bearer " + this.authToken;
187
+ const init = { method: method, headers: headers };
188
+ if (body != null)
189
+ init.body = JSON.stringify(body);
190
+ const signal = this.timeoutSignal();
191
+ if (signal != null)
192
+ init.signal = signal;
193
+ return init;
194
+ }
195
+ async postAsStoredPlayer(path, fields) {
196
+ const storedPlayer = this.readStoredPlayer();
197
+ const answer = await this.postJson(path, LeaderboardClient.withPlayerKey(fields, storedPlayer));
198
+ if (storedPlayer != null && LeaderboardClient.isInvalidPlayer(answer))
199
+ this.forgetPlayer();
200
+ return answer;
201
+ }
202
+ async postAsIdentifiedPlayer(path, fields) {
203
+ const firstAttempt = await this.postWithIdentity(path, fields);
204
+ if (!firstAttempt.usedKey || !LeaderboardClient.isInvalidPlayer(firstAttempt.answer))
205
+ return firstAttempt.answer;
206
+ this.forgetPlayer();
207
+ const secondAttempt = await this.postWithIdentity(path, fields);
208
+ return secondAttempt.answer;
209
+ }
210
+ async postWithIdentity(path, fields) {
211
+ const identity = await this.ensureIdentity();
212
+ if (identity.status !== "ok")
213
+ return { answer: identity, usedKey: false };
214
+ const storedPlayer = this.readStoredPlayer();
215
+ const answer = await this.postJson(path, LeaderboardClient.withPlayerKey(fields, storedPlayer));
216
+ return { answer: answer, usedKey: storedPlayer != null };
217
+ }
218
+ async ensureIdentity() {
219
+ if (this.readStoredPlayer() != null)
220
+ return { status: "ok", value: null };
221
+ const player = await this.getPlayer();
222
+ if (player.status !== "ok")
223
+ return player;
224
+ return { status: "ok", value: null };
225
+ }
226
+ async requestPlayerSession(storedPlayer) {
227
+ const answer = await this.postJson("players", LeaderboardClient.withPlayerKey({}, storedPlayer));
228
+ if (answer.status !== "ok")
229
+ return answer;
230
+ const session = answer.value;
231
+ if (session.playerKey != null)
232
+ this.storePlayer({ playerId: session.player.playerId, playerKey: session.playerKey });
233
+ return { status: "ok", value: session.player };
234
+ }
235
+ postSubmission(request) {
236
+ return this.postAsIdentifiedPlayer("submissions", request);
237
+ }
238
+ buildSubmissionRequest(submission) {
239
+ return {
240
+ submissionId: LeaderboardClient.newSubmissionId(),
241
+ gameMode: submission.gameMode ?? null,
242
+ buildVersion: this.buildVersion,
243
+ sessionName: submission.sessionName ?? null,
244
+ durationMs: submission.durationMs ?? null,
245
+ clientTime: new Date().toISOString(),
246
+ scores: submission.scores
247
+ };
248
+ }
249
+ async flushQueue() {
250
+ let sentCount = 0;
251
+ try {
252
+ const pending = this.readPending();
253
+ for (const request of pending) {
254
+ const answer = await this.postSubmission(request);
255
+ if (answer.status === "notSent" || LeaderboardClient.isAuthRefusal(answer))
256
+ break;
257
+ if (answer.status === "ok")
258
+ sentCount++;
259
+ this.removePending(request.submissionId);
260
+ }
261
+ }
262
+ catch {
263
+ }
264
+ return sentCount;
265
+ }
266
+ queueSubmission(request) {
267
+ const pending = this.readPending().filter((waiting) => waiting.submissionId !== request.submissionId);
268
+ pending.push(request);
269
+ const overflow = Math.max(0, pending.length - Math.max(1, this.maximumPendingSubmissions));
270
+ this.writePending(pending.slice(overflow));
271
+ return { status: "queued", submissionId: request.submissionId, message: LeaderboardClient.QUEUED_MESSAGE };
272
+ }
273
+ removePending(submissionId) {
274
+ this.writePending(this.readPending().filter((waiting) => waiting.submissionId !== submissionId));
275
+ }
276
+ readStoredPlayer() {
277
+ const storedText = this.readStorageItem(this.storageKey(LeaderboardClient.PLAYER_STORAGE_SUFFIX));
278
+ if (storedText === undefined)
279
+ return this.memoryPlayer;
280
+ if (storedText == null)
281
+ return null;
282
+ try {
283
+ const parsed = JSON.parse(storedText);
284
+ const isValid = parsed != null && typeof parsed.playerId === "string" && typeof parsed.playerKey === "string";
285
+ return isValid ? parsed : null;
286
+ }
287
+ catch {
288
+ return null;
289
+ }
290
+ }
291
+ storePlayer(player) {
292
+ this.memoryPlayer = player;
293
+ this.writeStorageItem(this.storageKey(LeaderboardClient.PLAYER_STORAGE_SUFFIX), JSON.stringify(player));
294
+ }
295
+ forgetPlayer() {
296
+ this.memoryPlayer = null;
297
+ this.removeStorageItem(this.storageKey(LeaderboardClient.PLAYER_STORAGE_SUFFIX));
298
+ }
299
+ readPending() {
300
+ const storedText = this.readStorageItem(this.storageKey(LeaderboardClient.PENDING_STORAGE_SUFFIX));
301
+ if (storedText === undefined)
302
+ return this.memoryPending.slice();
303
+ if (storedText == null)
304
+ return [];
305
+ try {
306
+ const parsed = JSON.parse(storedText);
307
+ return Array.isArray(parsed) ? parsed.filter((request) => request != null && typeof request.submissionId === "string") : [];
308
+ }
309
+ catch {
310
+ return [];
311
+ }
312
+ }
313
+ writePending(pending) {
314
+ this.memoryPending = pending.slice();
315
+ const key = this.storageKey(LeaderboardClient.PENDING_STORAGE_SUFFIX);
316
+ if (pending.length > 0)
317
+ this.writeStorageItem(key, JSON.stringify(pending));
318
+ else
319
+ this.removeStorageItem(key);
320
+ }
321
+ storageKey(suffix) {
322
+ return LeaderboardClient.STORAGE_PREFIX + this.endpoint + suffix;
323
+ }
324
+ readStorageItem(key) {
325
+ if (this.storage == null || this.storageFailed)
326
+ return undefined;
327
+ try {
328
+ return this.storage.getItem(key);
329
+ }
330
+ catch {
331
+ this.storageFailed = true;
332
+ return undefined;
333
+ }
334
+ }
335
+ writeStorageItem(key, value) {
336
+ if (this.storage == null || this.storageFailed)
337
+ return;
338
+ try {
339
+ this.storage.setItem(key, value);
340
+ }
341
+ catch {
342
+ this.storageFailed = true;
343
+ }
344
+ }
345
+ removeStorageItem(key) {
346
+ if (this.storage == null || this.storageFailed)
347
+ return;
348
+ try {
349
+ this.storage.removeItem(key);
350
+ }
351
+ catch {
352
+ this.storageFailed = true;
353
+ }
354
+ }
355
+ static newSubmissionId() {
356
+ const cryptoObject = (typeof globalThis !== "undefined") ? globalThis.crypto : undefined;
357
+ if (cryptoObject != null && typeof cryptoObject.randomUUID === "function")
358
+ return cryptoObject.randomUUID();
359
+ if (cryptoObject != null && typeof cryptoObject.getRandomValues === "function") {
360
+ const randomBytes = cryptoObject.getRandomValues(new Uint8Array(LeaderboardClient.SUBMISSION_ID_RANDOM_BYTES));
361
+ return Array.from(randomBytes, (byteValue) => byteValue.toString(16).padStart(2, "0")).join("");
362
+ }
363
+ const randomDigits = Math.random().toFixed(LeaderboardClient.FALLBACK_RANDOM_DIGITS).substring(2);
364
+ const clockDigits = String(Date.now()).padStart(LeaderboardClient.MINIMUM_SUBMISSION_ID_LENGTH, "0");
365
+ return clockDigits + "-" + randomDigits;
366
+ }
367
+ timeoutSignal() {
368
+ if (typeof AbortSignal === "undefined" || typeof AbortSignal.timeout !== "function")
369
+ return null;
370
+ return AbortSignal.timeout(this.requestTimeoutMs);
371
+ }
372
+ static queryString(parameters) {
373
+ const pairs = parameters
374
+ .filter((parameter) => parameter[1] !== undefined && parameter[1] !== null)
375
+ .map((parameter) => encodeURIComponent(parameter[0]) + "=" + encodeURIComponent(String(parameter[1])));
376
+ return (pairs.length > 0) ? "?" + pairs.join("&") : "";
377
+ }
378
+ static defaultStorage() {
379
+ try {
380
+ if (typeof window === "undefined" || window.localStorage == null)
381
+ return null;
382
+ return window.localStorage;
383
+ }
384
+ catch {
385
+ return null;
386
+ }
387
+ }
388
+ static globalFetch() {
389
+ if (typeof fetch !== "function")
390
+ return null;
391
+ return (url, init) => fetch(url, init);
392
+ }
393
+ static withPlayerKey(fields, storedPlayer) {
394
+ const body = Object.assign({}, fields);
395
+ if (storedPlayer != null)
396
+ body.playerKey = storedPlayer.playerKey;
397
+ return body;
398
+ }
399
+ static async readBody(response) {
400
+ try {
401
+ return await response.json();
402
+ }
403
+ catch {
404
+ return null;
405
+ }
406
+ }
407
+ static sortAnswer(status, body) {
408
+ if (status < LeaderboardClient.HTTP_FIRST_FAILURE_STATUS)
409
+ return { status: "ok", value: body };
410
+ const errorBody = (body != null && typeof body === "object") ? body : {};
411
+ const message = (typeof errorBody.error === "string") ? errorBody.error : "HTTP " + status;
412
+ const isRetryable = status === LeaderboardClient.HTTP_TOO_MANY_REQUESTS || status >= LeaderboardClient.HTTP_FIRST_SERVER_ERROR;
413
+ if (isRetryable)
414
+ return { status: "notSent", message: message };
415
+ const reason = (typeof errorBody.reason === "string") ? errorBody.reason : "invalidRequest";
416
+ return { status: "refused", reason: reason, message: message };
417
+ }
418
+ static isInvalidPlayer(answer) {
419
+ return answer.status === "refused" && answer.reason === "invalidPlayer";
420
+ }
421
+ static isAuthRefusal(answer) {
422
+ if (answer.status !== "refused")
423
+ return false;
424
+ return answer.reason === "authRequired" || answer.reason === "authRefused";
425
+ }
426
+ static notSent(error) {
427
+ return { status: "notSent", message: LeaderboardClient.describeError(error) };
428
+ }
429
+ static describeError(error) {
430
+ if (error instanceof Error)
431
+ return error.message;
432
+ return String(error);
433
+ }
434
+ }
435
+ LeaderboardClient.DEFAULT_REQUEST_TIMEOUT_MS = 8000;
436
+ LeaderboardClient.DEFAULT_MAXIMUM_PENDING_SUBMISSIONS = 50;
437
+ LeaderboardClient.API_PATH = "/game-server/leaderboards/";
438
+ LeaderboardClient.STORAGE_PREFIX = "bt.leaderboards.";
439
+ LeaderboardClient.PLAYER_STORAGE_SUFFIX = ".player";
440
+ LeaderboardClient.PENDING_STORAGE_SUFFIX = ".pending";
441
+ LeaderboardClient.SUBMISSION_ID_RANDOM_BYTES = 16;
442
+ LeaderboardClient.MINIMUM_SUBMISSION_ID_LENGTH = 8;
443
+ LeaderboardClient.FALLBACK_RANDOM_DIGITS = 10;
444
+ LeaderboardClient.HTTP_FIRST_FAILURE_STATUS = 300;
445
+ LeaderboardClient.HTTP_TOO_MANY_REQUESTS = 429;
446
+ LeaderboardClient.HTTP_FIRST_SERVER_ERROR = 500;
447
+ LeaderboardClient.NO_FETCH_MESSAGE = "no fetch function is available";
448
+ LeaderboardClient.QUEUED_MESSAGE = "the submission was not sent; it waits on this device and is sent on a later call";
@@ -0,0 +1,12 @@
1
+ import { LeaderboardStorage } from './leaderboardstorage';
2
+ import { LeaderboardFetch } from './leaderboardfetch';
3
+ export interface LeaderboardClientOptions {
4
+ serverUrl: string;
5
+ authToken?: string;
6
+ buildVersion?: string;
7
+ storage?: LeaderboardStorage | null;
8
+ fetchFunction?: LeaderboardFetch;
9
+ requestTimeoutMs?: number;
10
+ maximumPendingSubmissions?: number;
11
+ }
12
+ //# sourceMappingURL=leaderboardclientoptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardclientoptions.d.ts","sourceRoot":"","sources":["../src/leaderboardclientoptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,wBAAwB;IAEjC,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAEpC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IAEjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACtC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { LeaderboardEntryView } from './leaderboardentryview';
2
+ export interface LeaderboardEntriesPage {
3
+ boardId: string;
4
+ seasonId: number;
5
+ variantKey: string;
6
+ total: number;
7
+ offset: number;
8
+ entries: LeaderboardEntryView[];
9
+ }
10
+ //# sourceMappingURL=leaderboardentriespage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardentriespage.d.ts","sourceRoot":"","sources":["../src/leaderboardentriespage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IAEnB,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,oBAAoB,EAAE,CAAC;CACnC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { LeaderboardMetadata } from './leaderboardmetadata';
2
+ import { LeaderboardTrustLevel } from './leaderboardtrustlevel';
3
+ export interface LeaderboardEntryView {
4
+ rank: number;
5
+ playerId: string;
6
+ displayName: string;
7
+ avatar?: string | null;
8
+ score: number;
9
+ metadata: LeaderboardMetadata | null;
10
+ trustLevel: LeaderboardTrustLevel;
11
+ submittedAt: string;
12
+ achievedAt: string;
13
+ }
14
+ //# sourceMappingURL=leaderboardentryview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardentryview.d.ts","sourceRoot":"","sources":["../src/leaderboardentryview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,WAAW,oBAAoB;IAE7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IAEjB,WAAW,EAAE,MAAM,CAAC;IAEpB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;IACrC,UAAU,EAAE,qBAAqB,CAAC;IAElC,WAAW,EAAE,MAAM,CAAC;IAEpB,UAAU,EAAE,MAAM,CAAC;CACtB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { LeaderboardRefusalReason } from './leaderboardrefusalreason';
2
+ export interface LeaderboardErrorBody {
3
+ error: string;
4
+ reason: LeaderboardRefusalReason;
5
+ }
6
+ //# sourceMappingURL=leaderboarderrorbody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboarderrorbody.d.ts","sourceRoot":"","sources":["../src/leaderboarderrorbody.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,oBAAoB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,wBAAwB,CAAC;CACpC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type LeaderboardFetch = (url: string, init: RequestInit) => Promise<Response>;
2
+ //# sourceMappingURL=leaderboardfetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardfetch.d.ts","sourceRoot":"","sources":["../src/leaderboardfetch.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type LeaderboardKeepPolicy = "best" | "latest" | "sum";
2
+ //# sourceMappingURL=leaderboardkeeppolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardkeeppolicy.d.ts","sourceRoot":"","sources":["../src/leaderboardkeeppolicy.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { LeaderboardMetadataValue } from './leaderboardmetadatavalue';
2
+ export type LeaderboardMetadata = {
3
+ [key: string]: LeaderboardMetadataValue;
4
+ };
5
+ //# sourceMappingURL=leaderboardmetadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardmetadata.d.ts","sourceRoot":"","sources":["../src/leaderboardmetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,MAAM,MAAM,mBAAmB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,wBAAwB,CAAA;CAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export type LeaderboardMetadataValue = string | number | boolean | null | LeaderboardMetadataValue[] | {
2
+ [key: string]: LeaderboardMetadataValue;
3
+ };
4
+ //# sourceMappingURL=leaderboardmetadatavalue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardmetadatavalue.d.ts","sourceRoot":"","sources":["../src/leaderboardmetadatavalue.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,wBAAwB,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,wBAAwB,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,wBAAwB,CAAA;CAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { LeaderboardPlayerView } from './leaderboardplayerview';
2
+ export interface LeaderboardPlayerSession {
3
+ player: LeaderboardPlayerView;
4
+ playerKey: string | null;
5
+ }
6
+ //# sourceMappingURL=leaderboardplayersession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardplayersession.d.ts","sourceRoot":"","sources":["../src/leaderboardplayersession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,WAAW,wBAAwB;IACjC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface LeaderboardPlayerView {
2
+ playerId: string;
3
+ displayName: string;
4
+ kind: "anonymous" | "user" | "manual";
5
+ createdAt: string;
6
+ }
7
+ //# sourceMappingURL=leaderboardplayerview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardplayerview.d.ts","sourceRoot":"","sources":["../src/leaderboardplayerview.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,qBAAqB;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { LeaderboardCallResult } from './leaderboardcallresult';
2
+ export interface LeaderboardPostAttempt<Value> {
3
+ answer: LeaderboardCallResult<Value>;
4
+ usedKey: boolean;
5
+ }
6
+ //# sourceMappingURL=leaderboardpostattempt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardpostattempt.d.ts","sourceRoot":"","sources":["../src/leaderboardpostattempt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,WAAW,sBAAsB,CAAC,KAAK;IACrC,MAAM,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;CACpB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { LeaderboardSortOrder } from './leaderboardsortorder';
2
+ import { LeaderboardScoreFormat } from './leaderboardscoreformat';
3
+ import { LeaderboardKeepPolicy } from './leaderboardkeeppolicy';
4
+ import { LeaderboardVariantDimension } from './leaderboardvariantdimension';
5
+ export interface LeaderboardPublicBoardView {
6
+ boardId: string;
7
+ displayName: string;
8
+ description: string;
9
+ sortOrder: LeaderboardSortOrder;
10
+ scoreFormat: LeaderboardScoreFormat;
11
+ keepPolicy: LeaderboardKeepPolicy;
12
+ dimensions: LeaderboardVariantDimension[];
13
+ currentSeasonId: number;
14
+ currentSeasonStartedAt: string;
15
+ nextResetAt: string | null;
16
+ }
17
+ //# sourceMappingURL=leaderboardpublicboardview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardpublicboardview.d.ts","sourceRoot":"","sources":["../src/leaderboardpublicboardview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAE5E,MAAM,WAAW,0BAA0B;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,oBAAoB,CAAC;IAChC,WAAW,EAAE,sBAAsB,CAAC;IACpC,UAAU,EAAE,qBAAqB,CAAC;IAClC,UAAU,EAAE,2BAA2B,EAAE,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,MAAM,CAAC;IAE/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface LeaderboardRangeQuery {
2
+ variant?: Record<string, string> | null;
3
+ seasonId?: number;
4
+ offset?: number;
5
+ limit?: number;
6
+ }
7
+ //# sourceMappingURL=leaderboardrangequery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leaderboardrangequery.d.ts","sourceRoot":"","sources":["../src/leaderboardrangequery.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,qBAAqB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1 @@
1
+ export {};