keeperboard 2.0.3 → 2.1.1
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.d.mts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +19 -8
- package/dist/index.mjs +19 -8
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -93,6 +93,7 @@ interface HealthResult {
|
|
|
93
93
|
version: string;
|
|
94
94
|
timestamp: string;
|
|
95
95
|
}
|
|
96
|
+
type ErrorCode = 'PROFANITY_DETECTED' | 'RATE_LIMITED' | 'INVALID_REQUEST' | 'NOT_FOUND' | 'INTERNAL_ERROR';
|
|
96
97
|
interface SessionConfig {
|
|
97
98
|
/** API key from the KeeperBoard dashboard */
|
|
98
99
|
apiKey: string;
|
|
@@ -120,6 +121,14 @@ type SessionScoreResult = {
|
|
|
120
121
|
} | {
|
|
121
122
|
success: false;
|
|
122
123
|
error: string;
|
|
124
|
+
errorCode?: ErrorCode;
|
|
125
|
+
};
|
|
126
|
+
type UpdateNameResult = {
|
|
127
|
+
success: true;
|
|
128
|
+
} | {
|
|
129
|
+
success: false;
|
|
130
|
+
error: string;
|
|
131
|
+
errorCode?: ErrorCode;
|
|
123
132
|
};
|
|
124
133
|
interface SnapshotEntry {
|
|
125
134
|
rank: number;
|
|
@@ -334,9 +343,9 @@ declare class KeeperBoardSession {
|
|
|
334
343
|
}): Promise<SnapshotResult>;
|
|
335
344
|
/**
|
|
336
345
|
* Update the player's name on the server and locally.
|
|
337
|
-
* Returns true on success, false on failure.
|
|
346
|
+
* Returns `{ success: true }` on success, or `{ success: false, error, errorCode }` on failure.
|
|
338
347
|
*/
|
|
339
|
-
updatePlayerName(newName: string): Promise<
|
|
348
|
+
updatePlayerName(newName: string): Promise<UpdateNameResult>;
|
|
340
349
|
/**
|
|
341
350
|
* Retry submitting a pending score (from a previous failed submission).
|
|
342
351
|
* Call this on app startup.
|
|
@@ -510,4 +519,4 @@ declare class RetryQueue {
|
|
|
510
519
|
clear(): void;
|
|
511
520
|
}
|
|
512
521
|
|
|
513
|
-
export { Cache, type ClaimResponse, type ClaimResult, type ClaimScoreOptions, type GetLeaderboardOptions, type GetPlayerRankOptions, type HealthResponse, type HealthResult, KeeperBoardClient, type KeeperBoardConfig, KeeperBoardError, KeeperBoardSession, type LeaderboardEntry, type LeaderboardResponse, type LeaderboardResult, type NameValidationOptions, PlayerIdentity, type PlayerIdentityConfig, type PlayerResponse, type PlayerResult, type ResetSchedule, RetryQueue, type ScoreResponse, type ScoreResult, type ScoreSubmission, type SessionConfig, type SessionScoreResult, type SnapshotEntry, type SnapshotResult, type SubmitScoreOptions, type UpdatePlayerNameOptions, generatePlayerName, validateName };
|
|
522
|
+
export { Cache, type ClaimResponse, type ClaimResult, type ClaimScoreOptions, type ErrorCode, type GetLeaderboardOptions, type GetPlayerRankOptions, type HealthResponse, type HealthResult, KeeperBoardClient, type KeeperBoardConfig, KeeperBoardError, KeeperBoardSession, type LeaderboardEntry, type LeaderboardResponse, type LeaderboardResult, type NameValidationOptions, PlayerIdentity, type PlayerIdentityConfig, type PlayerResponse, type PlayerResult, type ResetSchedule, RetryQueue, type ScoreResponse, type ScoreResult, type ScoreSubmission, type SessionConfig, type SessionScoreResult, type SnapshotEntry, type SnapshotResult, type SubmitScoreOptions, type UpdateNameResult, type UpdatePlayerNameOptions, generatePlayerName, validateName };
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,7 @@ interface HealthResult {
|
|
|
93
93
|
version: string;
|
|
94
94
|
timestamp: string;
|
|
95
95
|
}
|
|
96
|
+
type ErrorCode = 'PROFANITY_DETECTED' | 'RATE_LIMITED' | 'INVALID_REQUEST' | 'NOT_FOUND' | 'INTERNAL_ERROR';
|
|
96
97
|
interface SessionConfig {
|
|
97
98
|
/** API key from the KeeperBoard dashboard */
|
|
98
99
|
apiKey: string;
|
|
@@ -120,6 +121,14 @@ type SessionScoreResult = {
|
|
|
120
121
|
} | {
|
|
121
122
|
success: false;
|
|
122
123
|
error: string;
|
|
124
|
+
errorCode?: ErrorCode;
|
|
125
|
+
};
|
|
126
|
+
type UpdateNameResult = {
|
|
127
|
+
success: true;
|
|
128
|
+
} | {
|
|
129
|
+
success: false;
|
|
130
|
+
error: string;
|
|
131
|
+
errorCode?: ErrorCode;
|
|
123
132
|
};
|
|
124
133
|
interface SnapshotEntry {
|
|
125
134
|
rank: number;
|
|
@@ -334,9 +343,9 @@ declare class KeeperBoardSession {
|
|
|
334
343
|
}): Promise<SnapshotResult>;
|
|
335
344
|
/**
|
|
336
345
|
* Update the player's name on the server and locally.
|
|
337
|
-
* Returns true on success, false on failure.
|
|
346
|
+
* Returns `{ success: true }` on success, or `{ success: false, error, errorCode }` on failure.
|
|
338
347
|
*/
|
|
339
|
-
updatePlayerName(newName: string): Promise<
|
|
348
|
+
updatePlayerName(newName: string): Promise<UpdateNameResult>;
|
|
340
349
|
/**
|
|
341
350
|
* Retry submitting a pending score (from a previous failed submission).
|
|
342
351
|
* Call this on app startup.
|
|
@@ -510,4 +519,4 @@ declare class RetryQueue {
|
|
|
510
519
|
clear(): void;
|
|
511
520
|
}
|
|
512
521
|
|
|
513
|
-
export { Cache, type ClaimResponse, type ClaimResult, type ClaimScoreOptions, type GetLeaderboardOptions, type GetPlayerRankOptions, type HealthResponse, type HealthResult, KeeperBoardClient, type KeeperBoardConfig, KeeperBoardError, KeeperBoardSession, type LeaderboardEntry, type LeaderboardResponse, type LeaderboardResult, type NameValidationOptions, PlayerIdentity, type PlayerIdentityConfig, type PlayerResponse, type PlayerResult, type ResetSchedule, RetryQueue, type ScoreResponse, type ScoreResult, type ScoreSubmission, type SessionConfig, type SessionScoreResult, type SnapshotEntry, type SnapshotResult, type SubmitScoreOptions, type UpdatePlayerNameOptions, generatePlayerName, validateName };
|
|
522
|
+
export { Cache, type ClaimResponse, type ClaimResult, type ClaimScoreOptions, type ErrorCode, type GetLeaderboardOptions, type GetPlayerRankOptions, type HealthResponse, type HealthResult, KeeperBoardClient, type KeeperBoardConfig, KeeperBoardError, KeeperBoardSession, type LeaderboardEntry, type LeaderboardResponse, type LeaderboardResult, type NameValidationOptions, PlayerIdentity, type PlayerIdentityConfig, type PlayerResponse, type PlayerResult, type ResetSchedule, RetryQueue, type ScoreResponse, type ScoreResult, type ScoreSubmission, type SessionConfig, type SessionScoreResult, type SnapshotEntry, type SnapshotResult, type SubmitScoreOptions, type UpdateNameResult, type UpdatePlayerNameOptions, generatePlayerName, validateName };
|
package/dist/index.js
CHANGED
|
@@ -720,13 +720,15 @@ var RetryQueue = class {
|
|
|
720
720
|
var DEFAULTS = {
|
|
721
721
|
minLength: 2,
|
|
722
722
|
maxLength: 12,
|
|
723
|
-
allowedPattern: /[^A-Za-z0-9_]/g
|
|
723
|
+
allowedPattern: /[^A-Za-z0-9_ ]/g
|
|
724
|
+
// Letters, numbers, underscore, space
|
|
724
725
|
};
|
|
725
726
|
function validateName(input, options) {
|
|
726
727
|
const opts = { ...DEFAULTS, ...options };
|
|
727
728
|
let name = input.trim();
|
|
728
|
-
const pattern = options?.allowedPattern ?? /[^A-Za-z0-9_]/g;
|
|
729
|
+
const pattern = options?.allowedPattern ?? /[^A-Za-z0-9_ ]/g;
|
|
729
730
|
name = name.replace(pattern, "");
|
|
731
|
+
name = name.replace(/ +/g, " ").trim();
|
|
730
732
|
name = name.substring(0, opts.maxLength);
|
|
731
733
|
if (name.length < opts.minLength) {
|
|
732
734
|
return null;
|
|
@@ -810,10 +812,14 @@ var KeeperBoardSession = class {
|
|
|
810
812
|
isNewHighScore: result.isNewHighScore
|
|
811
813
|
};
|
|
812
814
|
} catch (error) {
|
|
813
|
-
|
|
815
|
+
const errorCode = error instanceof KeeperBoardError ? error.code : void 0;
|
|
816
|
+
if (errorCode !== "PROFANITY_DETECTED") {
|
|
817
|
+
this.retryQueue?.save(score, metadata);
|
|
818
|
+
}
|
|
814
819
|
return {
|
|
815
820
|
success: false,
|
|
816
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
821
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
822
|
+
errorCode
|
|
817
823
|
};
|
|
818
824
|
} finally {
|
|
819
825
|
this.isSubmitting = false;
|
|
@@ -840,7 +846,7 @@ var KeeperBoardSession = class {
|
|
|
840
846
|
}
|
|
841
847
|
/**
|
|
842
848
|
* Update the player's name on the server and locally.
|
|
843
|
-
* Returns true on success, false on failure.
|
|
849
|
+
* Returns `{ success: true }` on success, or `{ success: false, error, errorCode }` on failure.
|
|
844
850
|
*/
|
|
845
851
|
async updatePlayerName(newName) {
|
|
846
852
|
try {
|
|
@@ -853,9 +859,14 @@ var KeeperBoardSession = class {
|
|
|
853
859
|
this.cache.invalidate();
|
|
854
860
|
this.cachedLimit = 0;
|
|
855
861
|
}
|
|
856
|
-
return true;
|
|
857
|
-
} catch {
|
|
858
|
-
|
|
862
|
+
return { success: true };
|
|
863
|
+
} catch (error) {
|
|
864
|
+
const errorCode = error instanceof KeeperBoardError ? error.code : void 0;
|
|
865
|
+
return {
|
|
866
|
+
success: false,
|
|
867
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
868
|
+
errorCode
|
|
869
|
+
};
|
|
859
870
|
}
|
|
860
871
|
}
|
|
861
872
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -687,13 +687,15 @@ var RetryQueue = class {
|
|
|
687
687
|
var DEFAULTS = {
|
|
688
688
|
minLength: 2,
|
|
689
689
|
maxLength: 12,
|
|
690
|
-
allowedPattern: /[^A-Za-z0-9_]/g
|
|
690
|
+
allowedPattern: /[^A-Za-z0-9_ ]/g
|
|
691
|
+
// Letters, numbers, underscore, space
|
|
691
692
|
};
|
|
692
693
|
function validateName(input, options) {
|
|
693
694
|
const opts = { ...DEFAULTS, ...options };
|
|
694
695
|
let name = input.trim();
|
|
695
|
-
const pattern = options?.allowedPattern ?? /[^A-Za-z0-9_]/g;
|
|
696
|
+
const pattern = options?.allowedPattern ?? /[^A-Za-z0-9_ ]/g;
|
|
696
697
|
name = name.replace(pattern, "");
|
|
698
|
+
name = name.replace(/ +/g, " ").trim();
|
|
697
699
|
name = name.substring(0, opts.maxLength);
|
|
698
700
|
if (name.length < opts.minLength) {
|
|
699
701
|
return null;
|
|
@@ -777,10 +779,14 @@ var KeeperBoardSession = class {
|
|
|
777
779
|
isNewHighScore: result.isNewHighScore
|
|
778
780
|
};
|
|
779
781
|
} catch (error) {
|
|
780
|
-
|
|
782
|
+
const errorCode = error instanceof KeeperBoardError ? error.code : void 0;
|
|
783
|
+
if (errorCode !== "PROFANITY_DETECTED") {
|
|
784
|
+
this.retryQueue?.save(score, metadata);
|
|
785
|
+
}
|
|
781
786
|
return {
|
|
782
787
|
success: false,
|
|
783
|
-
error: error instanceof Error ? error.message : "Unknown error"
|
|
788
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
789
|
+
errorCode
|
|
784
790
|
};
|
|
785
791
|
} finally {
|
|
786
792
|
this.isSubmitting = false;
|
|
@@ -807,7 +813,7 @@ var KeeperBoardSession = class {
|
|
|
807
813
|
}
|
|
808
814
|
/**
|
|
809
815
|
* Update the player's name on the server and locally.
|
|
810
|
-
* Returns true on success, false on failure.
|
|
816
|
+
* Returns `{ success: true }` on success, or `{ success: false, error, errorCode }` on failure.
|
|
811
817
|
*/
|
|
812
818
|
async updatePlayerName(newName) {
|
|
813
819
|
try {
|
|
@@ -820,9 +826,14 @@ var KeeperBoardSession = class {
|
|
|
820
826
|
this.cache.invalidate();
|
|
821
827
|
this.cachedLimit = 0;
|
|
822
828
|
}
|
|
823
|
-
return true;
|
|
824
|
-
} catch {
|
|
825
|
-
|
|
829
|
+
return { success: true };
|
|
830
|
+
} catch (error) {
|
|
831
|
+
const errorCode = error instanceof KeeperBoardError ? error.code : void 0;
|
|
832
|
+
return {
|
|
833
|
+
success: false,
|
|
834
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
835
|
+
errorCode
|
|
836
|
+
};
|
|
826
837
|
}
|
|
827
838
|
}
|
|
828
839
|
/**
|