@flare-engine/leaderboards 0.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/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Grzegorz Otto
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @flare-engine/leaderboards
|
|
2
|
+
|
|
3
|
+
Typed `LeaderboardsProvider` interface + `NoopLeaderboardsProvider` + React context. Stub-only at 0.1.0; concrete adapters (Game Center, Google Play Games, Steam) land at 0.2.0.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
bun add @flare-engine/leaderboards
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import {
|
|
15
|
+
LeaderboardsContext,
|
|
16
|
+
useLeaderboards,
|
|
17
|
+
NoopLeaderboardsProvider,
|
|
18
|
+
} from '@flare-engine/leaderboards';
|
|
19
|
+
|
|
20
|
+
export function App() {
|
|
21
|
+
return (
|
|
22
|
+
<LeaderboardsContext.Provider value={NoopLeaderboardsProvider}>
|
|
23
|
+
{/* ... */}
|
|
24
|
+
</LeaderboardsContext.Provider>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`useLeaderboards()` returns the provider; call `submit(boardId, score)`, `fetch(boardId)`, etc. against the interface — swapping `NoopLeaderboardsProvider` for a real adapter at 0.2.0 requires no consumer changes.
|
|
30
|
+
|
|
31
|
+
## Recipe — env-var-gated lazy load
|
|
32
|
+
|
|
33
|
+
When 0.2.0 adapters land (e.g. `@flare-engine/leaderboards-gamecenter`), wrap them behind an env-var gate so CI / unit tests / dev builds without API keys fall back to `NoopLeaderboardsProvider` and never touch the native SDK. See [.github/skills/flare-tier2-stubs/SKILL.md § Lazy-SDK adapter recipe](../../.github/skills/flare-tier2-stubs/SKILL.md#lazy-sdk-adapter-recipe) for the full pattern; canonical implementation at [apps/pan-tvardowski/src/iap/provider.ts](../../apps/pan-tvardowski/src/iap/provider.ts) (RevenueCat / IAP — same shape).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/** Opaque leaderboard identifier — adapter-defined (e.g., "daily_high_score"). */
|
|
4
|
+
type LeaderboardId = string;
|
|
5
|
+
/** A single leaderboard row. */
|
|
6
|
+
interface ScoreEntry {
|
|
7
|
+
playerId: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
score: number;
|
|
10
|
+
rank: number;
|
|
11
|
+
meta?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Leaderboard provider interface. Consumers supply a concrete adapter (Game
|
|
15
|
+
* Center, Google Play Games, Steam, custom backend) at the app boundary.
|
|
16
|
+
* 0.1.0 ships the interface + a no-op default so downstream packages can
|
|
17
|
+
* depend on it without forcing a platform choice.
|
|
18
|
+
*/
|
|
19
|
+
interface LeaderboardsProvider {
|
|
20
|
+
submitScore(id: LeaderboardId, score: number, meta?: Record<string, unknown>): Promise<void>;
|
|
21
|
+
getTopN(id: LeaderboardId, n: number): Promise<readonly ScoreEntry[]>;
|
|
22
|
+
getPlayerRank(id: LeaderboardId): Promise<number | null>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Default no-op provider. Submissions resolve silently; queries return empty
|
|
26
|
+
* arrays and `null` rank.
|
|
27
|
+
*/
|
|
28
|
+
declare const NoopLeaderboardsProvider: LeaderboardsProvider;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* React context carrying the active `LeaderboardsProvider`. Defaults to
|
|
32
|
+
* `NoopLeaderboardsProvider` so `useLeaderboards()` never throws on a bare
|
|
33
|
+
* tree — consumers wrap their app in a `<LeaderboardsContext.Provider>` with
|
|
34
|
+
* a real adapter when they need one.
|
|
35
|
+
*/
|
|
36
|
+
declare const LeaderboardsContext: react.Context<LeaderboardsProvider>;
|
|
37
|
+
/** Hook returning the current `LeaderboardsProvider`. */
|
|
38
|
+
declare function useLeaderboards(): LeaderboardsProvider;
|
|
39
|
+
|
|
40
|
+
export { type LeaderboardId, LeaderboardsContext, type LeaderboardsProvider, NoopLeaderboardsProvider, type ScoreEntry, useLeaderboards };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
|
|
3
|
+
/** Opaque leaderboard identifier — adapter-defined (e.g., "daily_high_score"). */
|
|
4
|
+
type LeaderboardId = string;
|
|
5
|
+
/** A single leaderboard row. */
|
|
6
|
+
interface ScoreEntry {
|
|
7
|
+
playerId: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
score: number;
|
|
10
|
+
rank: number;
|
|
11
|
+
meta?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Leaderboard provider interface. Consumers supply a concrete adapter (Game
|
|
15
|
+
* Center, Google Play Games, Steam, custom backend) at the app boundary.
|
|
16
|
+
* 0.1.0 ships the interface + a no-op default so downstream packages can
|
|
17
|
+
* depend on it without forcing a platform choice.
|
|
18
|
+
*/
|
|
19
|
+
interface LeaderboardsProvider {
|
|
20
|
+
submitScore(id: LeaderboardId, score: number, meta?: Record<string, unknown>): Promise<void>;
|
|
21
|
+
getTopN(id: LeaderboardId, n: number): Promise<readonly ScoreEntry[]>;
|
|
22
|
+
getPlayerRank(id: LeaderboardId): Promise<number | null>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Default no-op provider. Submissions resolve silently; queries return empty
|
|
26
|
+
* arrays and `null` rank.
|
|
27
|
+
*/
|
|
28
|
+
declare const NoopLeaderboardsProvider: LeaderboardsProvider;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* React context carrying the active `LeaderboardsProvider`. Defaults to
|
|
32
|
+
* `NoopLeaderboardsProvider` so `useLeaderboards()` never throws on a bare
|
|
33
|
+
* tree — consumers wrap their app in a `<LeaderboardsContext.Provider>` with
|
|
34
|
+
* a real adapter when they need one.
|
|
35
|
+
*/
|
|
36
|
+
declare const LeaderboardsContext: react.Context<LeaderboardsProvider>;
|
|
37
|
+
/** Hook returning the current `LeaderboardsProvider`. */
|
|
38
|
+
declare function useLeaderboards(): LeaderboardsProvider;
|
|
39
|
+
|
|
40
|
+
export { type LeaderboardId, LeaderboardsContext, type LeaderboardsProvider, NoopLeaderboardsProvider, type ScoreEntry, useLeaderboards };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
LeaderboardsContext: () => LeaderboardsContext,
|
|
24
|
+
NoopLeaderboardsProvider: () => NoopLeaderboardsProvider,
|
|
25
|
+
useLeaderboards: () => useLeaderboards
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/provider.ts
|
|
30
|
+
var NoopLeaderboardsProvider = {
|
|
31
|
+
async submitScore() {
|
|
32
|
+
},
|
|
33
|
+
async getTopN() {
|
|
34
|
+
return [];
|
|
35
|
+
},
|
|
36
|
+
async getPlayerRank() {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/context.ts
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var LeaderboardsContext = (0, import_react.createContext)(NoopLeaderboardsProvider);
|
|
44
|
+
function useLeaderboards() {
|
|
45
|
+
return (0, import_react.useContext)(LeaderboardsContext);
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
LeaderboardsContext,
|
|
50
|
+
NoopLeaderboardsProvider,
|
|
51
|
+
useLeaderboards
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.ts","../src/context.ts"],"sourcesContent":["export {\n NoopLeaderboardsProvider,\n type LeaderboardId,\n type LeaderboardsProvider,\n type ScoreEntry,\n} from './provider.js';\nexport { LeaderboardsContext, useLeaderboards } from './context.js';\n","/** Opaque leaderboard identifier — adapter-defined (e.g., \"daily_high_score\"). */\nexport type LeaderboardId = string;\n\n/** A single leaderboard row. */\nexport interface ScoreEntry {\n playerId: string;\n displayName: string;\n score: number;\n rank: number;\n meta?: Record<string, unknown>;\n}\n\n/**\n * Leaderboard provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * 0.1.0 ships the interface + a no-op default so downstream packages can\n * depend on it without forcing a platform choice.\n */\nexport interface LeaderboardsProvider {\n submitScore(id: LeaderboardId, score: number, meta?: Record<string, unknown>): Promise<void>;\n getTopN(id: LeaderboardId, n: number): Promise<readonly ScoreEntry[]>;\n getPlayerRank(id: LeaderboardId): Promise<number | null>;\n}\n\n/**\n * Default no-op provider. Submissions resolve silently; queries return empty\n * arrays and `null` rank.\n */\nexport const NoopLeaderboardsProvider: LeaderboardsProvider = {\n async submitScore(): Promise<void> {\n // no-op\n },\n async getTopN(): Promise<readonly ScoreEntry[]> {\n return [];\n },\n async getPlayerRank(): Promise<number | null> {\n return null;\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type LeaderboardsProvider, NoopLeaderboardsProvider } from './provider.js';\n\n/**\n * React context carrying the active `LeaderboardsProvider`. Defaults to\n * `NoopLeaderboardsProvider` so `useLeaderboards()` never throws on a bare\n * tree — consumers wrap their app in a `<LeaderboardsContext.Provider>` with\n * a real adapter when they need one.\n */\nexport const LeaderboardsContext = createContext<LeaderboardsProvider>(NoopLeaderboardsProvider);\n\n/** Hook returning the current `LeaderboardsProvider`. */\nexport function useLeaderboards(): LeaderboardsProvider {\n return useContext(LeaderboardsContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BO,IAAM,2BAAiD;AAAA,EAC5D,MAAM,cAA6B;AAAA,EAEnC;AAAA,EACA,MAAM,UAA0C;AAC9C,WAAO,CAAC;AAAA,EACV;AAAA,EACA,MAAM,gBAAwC;AAC5C,WAAO;AAAA,EACT;AACF;;;ACtCA,mBAA0C;AASnC,IAAM,0BAAsB,4BAAoC,wBAAwB;AAGxF,SAAS,kBAAwC;AACtD,aAAO,yBAAW,mBAAmB;AACvC;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
var NoopLeaderboardsProvider = {
|
|
3
|
+
async submitScore() {
|
|
4
|
+
},
|
|
5
|
+
async getTopN() {
|
|
6
|
+
return [];
|
|
7
|
+
},
|
|
8
|
+
async getPlayerRank() {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/context.ts
|
|
14
|
+
import { createContext, useContext } from "react";
|
|
15
|
+
var LeaderboardsContext = createContext(NoopLeaderboardsProvider);
|
|
16
|
+
function useLeaderboards() {
|
|
17
|
+
return useContext(LeaderboardsContext);
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
LeaderboardsContext,
|
|
21
|
+
NoopLeaderboardsProvider,
|
|
22
|
+
useLeaderboards
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider.ts","../src/context.ts"],"sourcesContent":["/** Opaque leaderboard identifier — adapter-defined (e.g., \"daily_high_score\"). */\nexport type LeaderboardId = string;\n\n/** A single leaderboard row. */\nexport interface ScoreEntry {\n playerId: string;\n displayName: string;\n score: number;\n rank: number;\n meta?: Record<string, unknown>;\n}\n\n/**\n * Leaderboard provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * 0.1.0 ships the interface + a no-op default so downstream packages can\n * depend on it without forcing a platform choice.\n */\nexport interface LeaderboardsProvider {\n submitScore(id: LeaderboardId, score: number, meta?: Record<string, unknown>): Promise<void>;\n getTopN(id: LeaderboardId, n: number): Promise<readonly ScoreEntry[]>;\n getPlayerRank(id: LeaderboardId): Promise<number | null>;\n}\n\n/**\n * Default no-op provider. Submissions resolve silently; queries return empty\n * arrays and `null` rank.\n */\nexport const NoopLeaderboardsProvider: LeaderboardsProvider = {\n async submitScore(): Promise<void> {\n // no-op\n },\n async getTopN(): Promise<readonly ScoreEntry[]> {\n return [];\n },\n async getPlayerRank(): Promise<number | null> {\n return null;\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type LeaderboardsProvider, NoopLeaderboardsProvider } from './provider.js';\n\n/**\n * React context carrying the active `LeaderboardsProvider`. Defaults to\n * `NoopLeaderboardsProvider` so `useLeaderboards()` never throws on a bare\n * tree — consumers wrap their app in a `<LeaderboardsContext.Provider>` with\n * a real adapter when they need one.\n */\nexport const LeaderboardsContext = createContext<LeaderboardsProvider>(NoopLeaderboardsProvider);\n\n/** Hook returning the current `LeaderboardsProvider`. */\nexport function useLeaderboards(): LeaderboardsProvider {\n return useContext(LeaderboardsContext);\n}\n"],"mappings":";AA4BO,IAAM,2BAAiD;AAAA,EAC5D,MAAM,cAA6B;AAAA,EAEnC;AAAA,EACA,MAAM,UAA0C;AAC9C,WAAO,CAAC;AAAA,EACV;AAAA,EACA,MAAM,gBAAwC;AAC5C,WAAO;AAAA,EACT;AACF;;;ACtCA,SAAS,eAAe,kBAAkB;AASnC,IAAM,sBAAsB,cAAoC,wBAAwB;AAGxF,SAAS,kBAAwC;AACtD,SAAO,WAAW,mBAAmB;AACvC;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flare-engine/leaderboards",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Leaderboard provider interface (consumer-supplied adapter)",
|
|
5
|
+
"keywords": ["flare-engine", "leaderboards", "provider", "interface"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "Grzegorz Otto",
|
|
8
|
+
"homepage": "https://github.com/grzott/flare-engine#readme",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/grzott/flare-engine/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/grzott/flare-engine.git",
|
|
15
|
+
"directory": "packages/leaderboards"
|
|
16
|
+
},
|
|
17
|
+
"main": "dist/index.js",
|
|
18
|
+
"module": "dist/index.mjs",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"test": "bun test",
|
|
31
|
+
"lint": "biome check src/",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/react": "^18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": ">=18.0.0"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "restricted",
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false
|
|
45
|
+
}
|