@flare-engine/achievements 0.2.1 → 0.3.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 CHANGED
@@ -1,21 +1,201 @@
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.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Grzegorz Otto
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ Flare Engine
2
+ Copyright 2026 Grzegorz Otto
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @flare-engine/achievements
2
2
 
3
- Typed `AchievementsProvider` interface + `NoopAchievementsProvider` + React context. Stub-only at 0.1.0; concrete adapters (Game Center, Google Play Games, Steam) land at 0.2.0.
3
+ Typed `AchievementsProvider` interface + `NoopAchievementsProvider` + React context, plus `createMemoryAchievements` / `createStorageAchievements` — local providers with a defined unlock/progress contract, for tests, dev, and single-player games. Concrete platform adapters (Game Center, Google Play Games, Steam) are post-launch; wire your own at the app boundary until then.
4
4
 
5
5
  ## Install
6
6
 
@@ -26,8 +26,33 @@ export function App() {
26
26
  }
27
27
  ```
28
28
 
29
- `useAchievements()` returns the provider; call `unlock(id)`, `setProgress(id, n)`, etc. against the interface — swapping `NoopAchievementsProvider` for a real adapter at 0.2.0 requires no consumer changes.
29
+ `useAchievements()` returns the active provider. The `AchievementsProvider` surface is `unlock(id, progress?)`, `getState(id)`, and `getAll()` — all async. Progress is a partial `[0, 1]` value; omit it to fully unlock.
30
30
 
31
- ## Recipe — env-var-gated lazy load
31
+ ## Local providers + the unlock contract
32
32
 
33
- When 0.2.0 adapters land (e.g. `@flare-engine/achievements-gamecenter`), wrap them behind an env-var gate so CI / unit tests / dev builds without API keys fall back to `NoopAchievementsProvider` and never touch the native SDK. See the [Lazy-SDK adapter recipe](https://github.com/grzott/flare-engine/blob/main/.claude/skills/flare-tier2-stubs/SKILL.md#lazy-sdk-adapter-recipe) for the full pattern; canonical implementation at [Pan Tvardowski's src/iap/provider.ts](https://github.com/grzott/Pan-Tvardowski/blob/main/src/iap/provider.ts) (RevenueCat / IAP — same shape).
33
+ `createMemoryAchievements()` keeps state in memory; `createStorageAchievements(store, opts?)` persists it through an injected `{ get, set }` store. Both share the same contract — the semantics adapter authors should preserve:
34
+
35
+ ```ts
36
+ import { createStorageAchievements } from '@flare-engine/achievements';
37
+ import type { AchievementsStore } from '@flare-engine/achievements';
38
+
39
+ declare const myStore: AchievementsStore;
40
+
41
+ const achievements = createStorageAchievements(myStore); // { get, set }
42
+
43
+ await achievements.unlock('first_blood', 0.5); // progress 0.5
44
+ await achievements.unlock('first_blood', 0.2); // ignored — progress stays 0.5
45
+ await achievements.unlock('first_blood'); // full unlock, latches
46
+ await achievements.getState('first_blood'); // { unlocked: true, progress: 1, unlockedAt }
47
+ ```
48
+
49
+ - **Clamped + monotonic:** progress is clamped to `[0, 1]` (non-finite → `0`) and never decreases — a lower requested value is ignored.
50
+ - **`unlock(id)` fully unlocks** (target progress `1`).
51
+ - **Latches:** reaching progress `1` sets `unlocked: true` and stamps `unlockedAt` once (via the injected `now`, default `Date.now`). Re-unlocking is a no-op — the original `unlockedAt` is kept.
52
+ - **Untracked ids** report `{ unlocked: false, progress: 0 }`.
53
+
54
+ `AchievementsStore` is a structural `{ get(key): Promise<string | null>; set(key, value): Promise<void> }` — the `get`/`set` subset of `@flare-engine/storage`'s `StorageAdapter`, so the storage provider adds no dependency and works with any async KV (AsyncStorage, an MMKV wrapper, a `localStorage` shim, …). It hydrates lazily from `store.get(key)` (default key `'flare.achievements'`), persists after every mutation, and serializes writes so concurrent unlocks can't lose an update.
55
+
56
+ ## Env-gated fallback
57
+
58
+ In CI or dev builds without platform credentials, select `NoopAchievementsProvider` (or a local provider) behind your own env flag so nothing touches a native SDK until real credentials are present.
package/dist/index.d.mts CHANGED
@@ -1,14 +1,13 @@
1
- import * as react from 'react';
2
-
1
+ //#region src/provider.d.ts
3
2
  /** Opaque achievement identifier — adapter-defined. */
4
3
  type AchievementId = string;
5
4
  /** Current state of an achievement for the local player. */
6
5
  interface AchievementState {
7
- id: AchievementId;
8
- unlocked: boolean;
9
- /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */
10
- progress: number;
11
- unlockedAt?: number;
6
+ id: AchievementId;
7
+ unlocked: boolean;
8
+ /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */
9
+ progress: number;
10
+ unlockedAt?: number;
12
11
  }
13
12
  /**
14
13
  * Achievement provider interface. Consumers supply a concrete adapter (Game
@@ -16,22 +15,65 @@ interface AchievementState {
16
15
  * `unlock()` is idempotent by contract — adapters must dedupe.
17
16
  */
18
17
  interface AchievementsProvider {
19
- unlock(id: AchievementId, progress?: number): Promise<void>;
20
- getState(id: AchievementId): Promise<AchievementState>;
21
- getAll(): Promise<readonly AchievementState[]>;
18
+ unlock(id: AchievementId, progress?: number): Promise<void>;
19
+ getState(id: AchievementId): Promise<AchievementState>;
20
+ getAll(): Promise<readonly AchievementState[]>;
22
21
  }
23
22
  /**
24
23
  * Default no-op provider. All queries report `unlocked: false, progress: 0`;
25
24
  * unlocks resolve silently.
26
25
  */
27
26
  declare const NoopAchievementsProvider: AchievementsProvider;
28
-
27
+ //#endregion
28
+ //#region src/context.d.ts
29
29
  /**
30
30
  * React context carrying the active `AchievementsProvider`. Defaults to
31
31
  * `NoopAchievementsProvider`.
32
32
  */
33
- declare const AchievementsContext: react.Context<AchievementsProvider>;
33
+ declare const AchievementsContext: import("react").Context<AchievementsProvider>;
34
34
  /** Hook returning the current `AchievementsProvider`. */
35
35
  declare function useAchievements(): AchievementsProvider;
36
-
37
- export { type AchievementId, type AchievementState, AchievementsContext, type AchievementsProvider, NoopAchievementsProvider, useAchievements };
36
+ //#endregion
37
+ //#region src/memory.d.ts
38
+ /**
39
+ * Structural async key/value store the storage-backed provider persists into.
40
+ * Matches the `get`/`set` subset of `@flare-engine/storage`'s `StorageAdapter`
41
+ * so a real adapter can be injected without depending on the storage package.
42
+ */
43
+ interface AchievementsStore {
44
+ /** Read a value. Resolves to `null` if the key is not present. */
45
+ get(key: string): Promise<string | null>;
46
+ /** Write a value. */
47
+ set(key: string, value: string): Promise<void>;
48
+ }
49
+ /** Options common to the in-memory and storage-backed providers. */
50
+ interface MemoryAchievementsOptions {
51
+ /** Clock used to stamp `unlockedAt` on latch. Defaults to `() => Date.now()`. */
52
+ now?: () => number;
53
+ }
54
+ /** Options for the storage-backed provider. */
55
+ interface StorageAchievementsOptions extends MemoryAchievementsOptions {
56
+ /** Persistence key passed to the injected store. Defaults to `'flare.achievements'`. */
57
+ key?: string;
58
+ }
59
+ /**
60
+ * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with
61
+ * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.
62
+ * State is not persisted — it lives for the lifetime of the returned provider.
63
+ */
64
+ declare function createMemoryAchievements(opts?: MemoryAchievementsOptions): AchievementsProvider;
65
+ /**
66
+ * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of
67
+ * {@link createMemoryAchievements} and persists into the injected
68
+ * {@link AchievementsStore}.
69
+ *
70
+ * State hydrates lazily from `store.get(key)` on the first call (a JSON array of
71
+ * `AchievementState`; a parse error hydrates empty) and is written back via
72
+ * `store.set` after every mutation. All mutations are serialized through a single
73
+ * chained tail promise so a read-modify-write can never interleave and lose an
74
+ * update under concurrent unlocks.
75
+ */
76
+ declare function createStorageAchievements(store: AchievementsStore, opts?: StorageAchievementsOptions): AchievementsProvider;
77
+ //#endregion
78
+ export { type AchievementId, type AchievementState, AchievementsContext, type AchievementsProvider, type AchievementsStore, type MemoryAchievementsOptions, NoopAchievementsProvider, type StorageAchievementsOptions, createMemoryAchievements, createStorageAchievements, useAchievements };
79
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/memory.ts"],"mappings":";;KACY;;UAGK;EACf,IAAI;EACJ;;EAEA;EACA;;;;;;;UAQe;EACf,OAAO,IAAI,eAAe,oBAAoB;EAC9C,SAAS,IAAI,gBAAgB,QAAQ;EACrC,UAAU,iBAAiB;;;;;;cAOhB,0BAA0B;;;;;;;cCpB1B,qCAAmB,QAAA;;iBAGhB,mBAAmB;;;;;;;;UCHlB;;EAEf,IAAI,cAAc;;EAElB,IAAI,aAAa,gBAAgB;;;UAIlB;;EAEf;;;UAIe,mCAAmC;;EAElD;;;;;;;iBAiDc,yBAAyB,OAAO,4BAA4B;;;;;;;;;;;;iBA2B5D,0BACd,OAAO,mBACP,OAAO,6BACN"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,13 @@
1
- import * as react from 'react';
2
-
1
+ //#region src/provider.d.ts
3
2
  /** Opaque achievement identifier — adapter-defined. */
4
3
  type AchievementId = string;
5
4
  /** Current state of an achievement for the local player. */
6
5
  interface AchievementState {
7
- id: AchievementId;
8
- unlocked: boolean;
9
- /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */
10
- progress: number;
11
- unlockedAt?: number;
6
+ id: AchievementId;
7
+ unlocked: boolean;
8
+ /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */
9
+ progress: number;
10
+ unlockedAt?: number;
12
11
  }
13
12
  /**
14
13
  * Achievement provider interface. Consumers supply a concrete adapter (Game
@@ -16,22 +15,65 @@ interface AchievementState {
16
15
  * `unlock()` is idempotent by contract — adapters must dedupe.
17
16
  */
18
17
  interface AchievementsProvider {
19
- unlock(id: AchievementId, progress?: number): Promise<void>;
20
- getState(id: AchievementId): Promise<AchievementState>;
21
- getAll(): Promise<readonly AchievementState[]>;
18
+ unlock(id: AchievementId, progress?: number): Promise<void>;
19
+ getState(id: AchievementId): Promise<AchievementState>;
20
+ getAll(): Promise<readonly AchievementState[]>;
22
21
  }
23
22
  /**
24
23
  * Default no-op provider. All queries report `unlocked: false, progress: 0`;
25
24
  * unlocks resolve silently.
26
25
  */
27
26
  declare const NoopAchievementsProvider: AchievementsProvider;
28
-
27
+ //#endregion
28
+ //#region src/context.d.ts
29
29
  /**
30
30
  * React context carrying the active `AchievementsProvider`. Defaults to
31
31
  * `NoopAchievementsProvider`.
32
32
  */
33
- declare const AchievementsContext: react.Context<AchievementsProvider>;
33
+ declare const AchievementsContext: import("react").Context<AchievementsProvider>;
34
34
  /** Hook returning the current `AchievementsProvider`. */
35
35
  declare function useAchievements(): AchievementsProvider;
36
-
37
- export { type AchievementId, type AchievementState, AchievementsContext, type AchievementsProvider, NoopAchievementsProvider, useAchievements };
36
+ //#endregion
37
+ //#region src/memory.d.ts
38
+ /**
39
+ * Structural async key/value store the storage-backed provider persists into.
40
+ * Matches the `get`/`set` subset of `@flare-engine/storage`'s `StorageAdapter`
41
+ * so a real adapter can be injected without depending on the storage package.
42
+ */
43
+ interface AchievementsStore {
44
+ /** Read a value. Resolves to `null` if the key is not present. */
45
+ get(key: string): Promise<string | null>;
46
+ /** Write a value. */
47
+ set(key: string, value: string): Promise<void>;
48
+ }
49
+ /** Options common to the in-memory and storage-backed providers. */
50
+ interface MemoryAchievementsOptions {
51
+ /** Clock used to stamp `unlockedAt` on latch. Defaults to `() => Date.now()`. */
52
+ now?: () => number;
53
+ }
54
+ /** Options for the storage-backed provider. */
55
+ interface StorageAchievementsOptions extends MemoryAchievementsOptions {
56
+ /** Persistence key passed to the injected store. Defaults to `'flare.achievements'`. */
57
+ key?: string;
58
+ }
59
+ /**
60
+ * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with
61
+ * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.
62
+ * State is not persisted — it lives for the lifetime of the returned provider.
63
+ */
64
+ declare function createMemoryAchievements(opts?: MemoryAchievementsOptions): AchievementsProvider;
65
+ /**
66
+ * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of
67
+ * {@link createMemoryAchievements} and persists into the injected
68
+ * {@link AchievementsStore}.
69
+ *
70
+ * State hydrates lazily from `store.get(key)` on the first call (a JSON array of
71
+ * `AchievementState`; a parse error hydrates empty) and is written back via
72
+ * `store.set` after every mutation. All mutations are serialized through a single
73
+ * chained tail promise so a read-modify-write can never interleave and lose an
74
+ * update under concurrent unlocks.
75
+ */
76
+ declare function createStorageAchievements(store: AchievementsStore, opts?: StorageAchievementsOptions): AchievementsProvider;
77
+ //#endregion
78
+ export { type AchievementId, type AchievementState, AchievementsContext, type AchievementsProvider, type AchievementsStore, type MemoryAchievementsOptions, NoopAchievementsProvider, type StorageAchievementsOptions, createMemoryAchievements, createStorageAchievements, useAchievements };
79
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/memory.ts"],"mappings":";;KACY;;UAGK;EACf,IAAI;EACJ;;EAEA;EACA;;;;;;;UAQe;EACf,OAAO,IAAI,eAAe,oBAAoB;EAC9C,SAAS,IAAI,gBAAgB,QAAQ;EACrC,UAAU,iBAAiB;;;;;;cAOhB,0BAA0B;;;;;;;cCpB1B,qCAAmB,QAAA;;iBAGhB,mBAAmB;;;;;;;;UCHlB;;EAEf,IAAI,cAAc;;EAElB,IAAI,aAAa,gBAAgB;;;UAIlB;;EAEf;;;UAIe,mCAAmC;;EAElD;;;;;;;iBAiDc,yBAAyB,OAAO,4BAA4B;;;;;;;;;;;;iBA2B5D,0BACd,OAAO,mBACP,OAAO,6BACN"}
package/dist/index.js CHANGED
@@ -1,53 +1,155 @@
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 });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let react = require("react");
3
+ //#region src/provider.ts
4
+ /**
5
+ * Default no-op provider. All queries report `unlocked: false, progress: 0`;
6
+ * unlocks resolve silently.
7
+ */
8
+ const NoopAchievementsProvider = {
9
+ async unlock() {},
10
+ async getState(id) {
11
+ return {
12
+ id,
13
+ unlocked: false,
14
+ progress: 0
15
+ };
16
+ },
17
+ async getAll() {
18
+ return [];
19
+ }
9
20
  };
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
- AchievementsContext: () => AchievementsContext,
24
- NoopAchievementsProvider: () => NoopAchievementsProvider,
25
- useAchievements: () => useAchievements
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/provider.ts
30
- var NoopAchievementsProvider = {
31
- async unlock() {
32
- },
33
- async getState(id) {
34
- return { id, unlocked: false, progress: 0 };
35
- },
36
- async getAll() {
37
- return [];
38
- }
39
- };
40
-
41
- // src/context.ts
42
- var import_react = require("react");
43
- var AchievementsContext = (0, import_react.createContext)(NoopAchievementsProvider);
21
+ //#endregion
22
+ //#region src/context.ts
23
+ /**
24
+ * React context carrying the active `AchievementsProvider`. Defaults to
25
+ * `NoopAchievementsProvider`.
26
+ */
27
+ const AchievementsContext = (0, react.createContext)(NoopAchievementsProvider);
28
+ /** Hook returning the current `AchievementsProvider`. */
44
29
  function useAchievements() {
45
- return (0, import_react.useContext)(AchievementsContext);
30
+ return (0, react.useContext)(AchievementsContext);
31
+ }
32
+ //#endregion
33
+ //#region src/memory.ts
34
+ const DEFAULT_KEY = "flare.achievements";
35
+ /** Coerce raw progress to `[0, 1]`; a non-finite value (NaN/Infinity) becomes `0`. */
36
+ function normalizeProgress(value) {
37
+ if (!Number.isFinite(value)) return 0;
38
+ if (value < 0) return 0;
39
+ if (value > 1) return 1;
40
+ return value;
46
41
  }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- AchievementsContext,
50
- NoopAchievementsProvider,
51
- useAchievements
52
- });
42
+ /** Default state for an untracked id — no `unlockedAt`. */
43
+ function defaultState(id) {
44
+ return {
45
+ id,
46
+ unlocked: false,
47
+ progress: 0
48
+ };
49
+ }
50
+ /**
51
+ * Pure state transition shared by both providers. Given the current state, an
52
+ * optional progress arg and a clock, returns the next state:
53
+ *
54
+ * - `progress` omitted means a FULL unlock (target progress `1`).
55
+ * - Progress is clamped to `[0, 1]`; non-finite input is treated as `0`.
56
+ * - Progress is MONOTONIC — it never decreases below the stored value; a lower
57
+ * requested progress is ignored.
58
+ * - Unlock LATCHES: reaching progress `1` sets `unlocked: true` and stamps
59
+ * `unlockedAt` once (via `now`). An already-unlocked state keeps its original
60
+ * `unlockedAt`, so re-unlocking is a no-op.
61
+ */
62
+ function mergeAchievement(current, progress, now) {
63
+ const requested = progress === void 0 ? 1 : normalizeProgress(progress);
64
+ const nextProgress = requested > current.progress ? requested : current.progress;
65
+ if (!current.unlocked && nextProgress < 1) return {
66
+ id: current.id,
67
+ unlocked: false,
68
+ progress: nextProgress
69
+ };
70
+ const unlockedAt = current.unlockedAt ?? now();
71
+ return {
72
+ id: current.id,
73
+ unlocked: true,
74
+ progress: 1,
75
+ unlockedAt
76
+ };
77
+ }
78
+ /**
79
+ * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with
80
+ * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.
81
+ * State is not persisted — it lives for the lifetime of the returned provider.
82
+ */
83
+ function createMemoryAchievements(opts) {
84
+ const now = opts?.now ?? (() => Date.now());
85
+ const states = /* @__PURE__ */ new Map();
86
+ return {
87
+ async unlock(id, progress) {
88
+ states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));
89
+ },
90
+ async getState(id) {
91
+ return states.get(id) ?? defaultState(id);
92
+ },
93
+ async getAll() {
94
+ return [...states.values()];
95
+ }
96
+ };
97
+ }
98
+ /**
99
+ * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of
100
+ * {@link createMemoryAchievements} and persists into the injected
101
+ * {@link AchievementsStore}.
102
+ *
103
+ * State hydrates lazily from `store.get(key)` on the first call (a JSON array of
104
+ * `AchievementState`; a parse error hydrates empty) and is written back via
105
+ * `store.set` after every mutation. All mutations are serialized through a single
106
+ * chained tail promise so a read-modify-write can never interleave and lose an
107
+ * update under concurrent unlocks.
108
+ */
109
+ function createStorageAchievements(store, opts) {
110
+ const now = opts?.now ?? (() => Date.now());
111
+ const key = opts?.key ?? DEFAULT_KEY;
112
+ const states = /* @__PURE__ */ new Map();
113
+ let hydration;
114
+ let tail = Promise.resolve();
115
+ function hydrate() {
116
+ if (hydration === void 0) hydration = store.get(key).then((raw) => {
117
+ if (raw === null) return;
118
+ try {
119
+ const parsed = JSON.parse(raw);
120
+ for (const state of parsed) states.set(state.id, state);
121
+ } catch {}
122
+ });
123
+ return hydration;
124
+ }
125
+ function persist() {
126
+ return store.set(key, JSON.stringify([...states.values()]));
127
+ }
128
+ return {
129
+ unlock(id, progress) {
130
+ const run = tail.then(async () => {
131
+ await hydrate();
132
+ states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));
133
+ await persist();
134
+ });
135
+ tail = run.catch(() => {});
136
+ return run;
137
+ },
138
+ async getState(id) {
139
+ await hydrate();
140
+ return states.get(id) ?? defaultState(id);
141
+ },
142
+ async getAll() {
143
+ await hydrate();
144
+ return [...states.values()];
145
+ }
146
+ };
147
+ }
148
+ //#endregion
149
+ exports.AchievementsContext = AchievementsContext;
150
+ exports.NoopAchievementsProvider = NoopAchievementsProvider;
151
+ exports.createMemoryAchievements = createMemoryAchievements;
152
+ exports.createStorageAchievements = createStorageAchievements;
153
+ exports.useAchievements = useAchievements;
154
+
53
155
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.ts","../src/context.ts"],"sourcesContent":["export {\n NoopAchievementsProvider,\n type AchievementId,\n type AchievementState,\n type AchievementsProvider,\n} from './provider.js';\nexport { AchievementsContext, useAchievements } from './context.js';\n","/** Opaque achievement identifier — adapter-defined. */\nexport type AchievementId = string;\n\n/** Current state of an achievement for the local player. */\nexport interface AchievementState {\n id: AchievementId;\n unlocked: boolean;\n /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */\n progress: number;\n unlockedAt?: number;\n}\n\n/**\n * Achievement provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * `unlock()` is idempotent by contract — adapters must dedupe.\n */\nexport interface AchievementsProvider {\n unlock(id: AchievementId, progress?: number): Promise<void>;\n getState(id: AchievementId): Promise<AchievementState>;\n getAll(): Promise<readonly AchievementState[]>;\n}\n\n/**\n * Default no-op provider. All queries report `unlocked: false, progress: 0`;\n * unlocks resolve silently.\n */\nexport const NoopAchievementsProvider: AchievementsProvider = {\n async unlock(): Promise<void> {\n // no-op\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return { id, unlocked: false, progress: 0 };\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [];\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AchievementsProvider, NoopAchievementsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AchievementsProvider`. Defaults to\n * `NoopAchievementsProvider`.\n */\nexport const AchievementsContext = createContext<AchievementsProvider>(NoopAchievementsProvider);\n\n/** Hook returning the current `AchievementsProvider`. */\nexport function useAchievements(): AchievementsProvider {\n return useContext(AchievementsContext);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2BO,IAAM,2BAAiD;AAAA,EAC5D,MAAM,SAAwB;AAAA,EAE9B;AAAA,EACA,MAAM,SAAS,IAA8C;AAC3D,WAAO,EAAE,IAAI,UAAU,OAAO,UAAU,EAAE;AAAA,EAC5C;AAAA,EACA,MAAM,SAA+C;AACnD,WAAO,CAAC;AAAA,EACV;AACF;;;ACrCA,mBAA0C;AAOnC,IAAM,0BAAsB,4BAAoC,wBAAwB;AAGxF,SAAS,kBAAwC;AACtD,aAAO,yBAAW,mBAAmB;AACvC;","names":[]}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/memory.ts"],"sourcesContent":["/** Opaque achievement identifier — adapter-defined. */\nexport type AchievementId = string;\n\n/** Current state of an achievement for the local player. */\nexport interface AchievementState {\n id: AchievementId;\n unlocked: boolean;\n /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */\n progress: number;\n unlockedAt?: number;\n}\n\n/**\n * Achievement provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * `unlock()` is idempotent by contract — adapters must dedupe.\n */\nexport interface AchievementsProvider {\n unlock(id: AchievementId, progress?: number): Promise<void>;\n getState(id: AchievementId): Promise<AchievementState>;\n getAll(): Promise<readonly AchievementState[]>;\n}\n\n/**\n * Default no-op provider. All queries report `unlocked: false, progress: 0`;\n * unlocks resolve silently.\n */\nexport const NoopAchievementsProvider: AchievementsProvider = {\n async unlock(): Promise<void> {\n // no-op\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return { id, unlocked: false, progress: 0 };\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [];\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AchievementsProvider, NoopAchievementsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AchievementsProvider`. Defaults to\n * `NoopAchievementsProvider`.\n */\nexport const AchievementsContext = createContext<AchievementsProvider>(NoopAchievementsProvider);\n\n/** Hook returning the current `AchievementsProvider`. */\nexport function useAchievements(): AchievementsProvider {\n return useContext(AchievementsContext);\n}\n","import type { AchievementId, AchievementState, AchievementsProvider } from './provider.js';\n\n/**\n * Structural async key/value store the storage-backed provider persists into.\n * Matches the `get`/`set` subset of `@flare-engine/storage`'s `StorageAdapter`\n * so a real adapter can be injected without depending on the storage package.\n */\nexport interface AchievementsStore {\n /** Read a value. Resolves to `null` if the key is not present. */\n get(key: string): Promise<string | null>;\n /** Write a value. */\n set(key: string, value: string): Promise<void>;\n}\n\n/** Options common to the in-memory and storage-backed providers. */\nexport interface MemoryAchievementsOptions {\n /** Clock used to stamp `unlockedAt` on latch. Defaults to `() => Date.now()`. */\n now?: () => number;\n}\n\n/** Options for the storage-backed provider. */\nexport interface StorageAchievementsOptions extends MemoryAchievementsOptions {\n /** Persistence key passed to the injected store. Defaults to `'flare.achievements'`. */\n key?: string;\n}\n\nconst DEFAULT_KEY = 'flare.achievements';\n\n/** Coerce raw progress to `[0, 1]`; a non-finite value (NaN/Infinity) becomes `0`. */\nfunction normalizeProgress(value: number): number {\n if (!Number.isFinite(value)) return 0;\n if (value < 0) return 0;\n if (value > 1) return 1;\n return value;\n}\n\n/** Default state for an untracked id — no `unlockedAt`. */\nfunction defaultState(id: AchievementId): AchievementState {\n return { id, unlocked: false, progress: 0 };\n}\n\n/**\n * Pure state transition shared by both providers. Given the current state, an\n * optional progress arg and a clock, returns the next state:\n *\n * - `progress` omitted means a FULL unlock (target progress `1`).\n * - Progress is clamped to `[0, 1]`; non-finite input is treated as `0`.\n * - Progress is MONOTONIC — it never decreases below the stored value; a lower\n * requested progress is ignored.\n * - Unlock LATCHES: reaching progress `1` sets `unlocked: true` and stamps\n * `unlockedAt` once (via `now`). An already-unlocked state keeps its original\n * `unlockedAt`, so re-unlocking is a no-op.\n */\nfunction mergeAchievement(\n current: AchievementState,\n progress: number | undefined,\n now: () => number,\n): AchievementState {\n const requested = progress === undefined ? 1 : normalizeProgress(progress);\n const nextProgress = requested > current.progress ? requested : current.progress;\n if (!current.unlocked && nextProgress < 1) {\n return { id: current.id, unlocked: false, progress: nextProgress };\n }\n const unlockedAt = current.unlockedAt ?? now();\n return { id: current.id, unlocked: true, progress: 1, unlockedAt };\n}\n\n/**\n * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with\n * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.\n * State is not persisted — it lives for the lifetime of the returned provider.\n */\nexport function createMemoryAchievements(opts?: MemoryAchievementsOptions): AchievementsProvider {\n const now = opts?.now ?? (() => Date.now());\n const states = new Map<AchievementId, AchievementState>();\n return {\n async unlock(id: AchievementId, progress?: number): Promise<void> {\n states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return states.get(id) ?? defaultState(id);\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [...states.values()];\n },\n };\n}\n\n/**\n * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of\n * {@link createMemoryAchievements} and persists into the injected\n * {@link AchievementsStore}.\n *\n * State hydrates lazily from `store.get(key)` on the first call (a JSON array of\n * `AchievementState`; a parse error hydrates empty) and is written back via\n * `store.set` after every mutation. All mutations are serialized through a single\n * chained tail promise so a read-modify-write can never interleave and lose an\n * update under concurrent unlocks.\n */\nexport function createStorageAchievements(\n store: AchievementsStore,\n opts?: StorageAchievementsOptions,\n): AchievementsProvider {\n const now = opts?.now ?? (() => Date.now());\n const key = opts?.key ?? DEFAULT_KEY;\n const states = new Map<AchievementId, AchievementState>();\n let hydration: Promise<void> | undefined;\n let tail: Promise<void> = Promise.resolve();\n\n function hydrate(): Promise<void> {\n if (hydration === undefined) {\n hydration = store.get(key).then((raw) => {\n if (raw === null) return;\n try {\n const parsed = JSON.parse(raw) as AchievementState[];\n for (const state of parsed) states.set(state.id, state);\n } catch {\n // Corrupt payload — hydrate empty.\n }\n });\n }\n return hydration;\n }\n\n function persist(): Promise<void> {\n return store.set(key, JSON.stringify([...states.values()]));\n }\n\n return {\n unlock(id: AchievementId, progress?: number): Promise<void> {\n const run = tail.then(async () => {\n await hydrate();\n states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));\n await persist();\n });\n // Swallow on the tail so one failed write cannot break serialization for\n // later mutations; the caller still observes the error via `run`.\n tail = run.catch(() => {});\n return run;\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n await hydrate();\n return states.get(id) ?? defaultState(id);\n },\n async getAll(): Promise<readonly AchievementState[]> {\n await hydrate();\n return [...states.values()];\n },\n };\n}\n"],"mappings":"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"}
package/dist/index.mjs CHANGED
@@ -1,24 +1,150 @@
1
- // src/provider.ts
2
- var NoopAchievementsProvider = {
3
- async unlock() {
4
- },
5
- async getState(id) {
6
- return { id, unlocked: false, progress: 0 };
7
- },
8
- async getAll() {
9
- return [];
10
- }
11
- };
12
-
13
- // src/context.ts
14
1
  import { createContext, useContext } from "react";
15
- var AchievementsContext = createContext(NoopAchievementsProvider);
2
+ //#region src/provider.ts
3
+ /**
4
+ * Default no-op provider. All queries report `unlocked: false, progress: 0`;
5
+ * unlocks resolve silently.
6
+ */
7
+ const NoopAchievementsProvider = {
8
+ async unlock() {},
9
+ async getState(id) {
10
+ return {
11
+ id,
12
+ unlocked: false,
13
+ progress: 0
14
+ };
15
+ },
16
+ async getAll() {
17
+ return [];
18
+ }
19
+ };
20
+ //#endregion
21
+ //#region src/context.ts
22
+ /**
23
+ * React context carrying the active `AchievementsProvider`. Defaults to
24
+ * `NoopAchievementsProvider`.
25
+ */
26
+ const AchievementsContext = createContext(NoopAchievementsProvider);
27
+ /** Hook returning the current `AchievementsProvider`. */
16
28
  function useAchievements() {
17
- return useContext(AchievementsContext);
29
+ return useContext(AchievementsContext);
18
30
  }
19
- export {
20
- AchievementsContext,
21
- NoopAchievementsProvider,
22
- useAchievements
23
- };
31
+ //#endregion
32
+ //#region src/memory.ts
33
+ const DEFAULT_KEY = "flare.achievements";
34
+ /** Coerce raw progress to `[0, 1]`; a non-finite value (NaN/Infinity) becomes `0`. */
35
+ function normalizeProgress(value) {
36
+ if (!Number.isFinite(value)) return 0;
37
+ if (value < 0) return 0;
38
+ if (value > 1) return 1;
39
+ return value;
40
+ }
41
+ /** Default state for an untracked id — no `unlockedAt`. */
42
+ function defaultState(id) {
43
+ return {
44
+ id,
45
+ unlocked: false,
46
+ progress: 0
47
+ };
48
+ }
49
+ /**
50
+ * Pure state transition shared by both providers. Given the current state, an
51
+ * optional progress arg and a clock, returns the next state:
52
+ *
53
+ * - `progress` omitted means a FULL unlock (target progress `1`).
54
+ * - Progress is clamped to `[0, 1]`; non-finite input is treated as `0`.
55
+ * - Progress is MONOTONIC — it never decreases below the stored value; a lower
56
+ * requested progress is ignored.
57
+ * - Unlock LATCHES: reaching progress `1` sets `unlocked: true` and stamps
58
+ * `unlockedAt` once (via `now`). An already-unlocked state keeps its original
59
+ * `unlockedAt`, so re-unlocking is a no-op.
60
+ */
61
+ function mergeAchievement(current, progress, now) {
62
+ const requested = progress === void 0 ? 1 : normalizeProgress(progress);
63
+ const nextProgress = requested > current.progress ? requested : current.progress;
64
+ if (!current.unlocked && nextProgress < 1) return {
65
+ id: current.id,
66
+ unlocked: false,
67
+ progress: nextProgress
68
+ };
69
+ const unlockedAt = current.unlockedAt ?? now();
70
+ return {
71
+ id: current.id,
72
+ unlocked: true,
73
+ progress: 1,
74
+ unlockedAt
75
+ };
76
+ }
77
+ /**
78
+ * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with
79
+ * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.
80
+ * State is not persisted — it lives for the lifetime of the returned provider.
81
+ */
82
+ function createMemoryAchievements(opts) {
83
+ const now = opts?.now ?? (() => Date.now());
84
+ const states = /* @__PURE__ */ new Map();
85
+ return {
86
+ async unlock(id, progress) {
87
+ states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));
88
+ },
89
+ async getState(id) {
90
+ return states.get(id) ?? defaultState(id);
91
+ },
92
+ async getAll() {
93
+ return [...states.values()];
94
+ }
95
+ };
96
+ }
97
+ /**
98
+ * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of
99
+ * {@link createMemoryAchievements} and persists into the injected
100
+ * {@link AchievementsStore}.
101
+ *
102
+ * State hydrates lazily from `store.get(key)` on the first call (a JSON array of
103
+ * `AchievementState`; a parse error hydrates empty) and is written back via
104
+ * `store.set` after every mutation. All mutations are serialized through a single
105
+ * chained tail promise so a read-modify-write can never interleave and lose an
106
+ * update under concurrent unlocks.
107
+ */
108
+ function createStorageAchievements(store, opts) {
109
+ const now = opts?.now ?? (() => Date.now());
110
+ const key = opts?.key ?? DEFAULT_KEY;
111
+ const states = /* @__PURE__ */ new Map();
112
+ let hydration;
113
+ let tail = Promise.resolve();
114
+ function hydrate() {
115
+ if (hydration === void 0) hydration = store.get(key).then((raw) => {
116
+ if (raw === null) return;
117
+ try {
118
+ const parsed = JSON.parse(raw);
119
+ for (const state of parsed) states.set(state.id, state);
120
+ } catch {}
121
+ });
122
+ return hydration;
123
+ }
124
+ function persist() {
125
+ return store.set(key, JSON.stringify([...states.values()]));
126
+ }
127
+ return {
128
+ unlock(id, progress) {
129
+ const run = tail.then(async () => {
130
+ await hydrate();
131
+ states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));
132
+ await persist();
133
+ });
134
+ tail = run.catch(() => {});
135
+ return run;
136
+ },
137
+ async getState(id) {
138
+ await hydrate();
139
+ return states.get(id) ?? defaultState(id);
140
+ },
141
+ async getAll() {
142
+ await hydrate();
143
+ return [...states.values()];
144
+ }
145
+ };
146
+ }
147
+ //#endregion
148
+ export { AchievementsContext, NoopAchievementsProvider, createMemoryAchievements, createStorageAchievements, useAchievements };
149
+
24
150
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/provider.ts","../src/context.ts"],"sourcesContent":["/** Opaque achievement identifier — adapter-defined. */\nexport type AchievementId = string;\n\n/** Current state of an achievement for the local player. */\nexport interface AchievementState {\n id: AchievementId;\n unlocked: boolean;\n /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */\n progress: number;\n unlockedAt?: number;\n}\n\n/**\n * Achievement provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * `unlock()` is idempotent by contract — adapters must dedupe.\n */\nexport interface AchievementsProvider {\n unlock(id: AchievementId, progress?: number): Promise<void>;\n getState(id: AchievementId): Promise<AchievementState>;\n getAll(): Promise<readonly AchievementState[]>;\n}\n\n/**\n * Default no-op provider. All queries report `unlocked: false, progress: 0`;\n * unlocks resolve silently.\n */\nexport const NoopAchievementsProvider: AchievementsProvider = {\n async unlock(): Promise<void> {\n // no-op\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return { id, unlocked: false, progress: 0 };\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [];\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AchievementsProvider, NoopAchievementsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AchievementsProvider`. Defaults to\n * `NoopAchievementsProvider`.\n */\nexport const AchievementsContext = createContext<AchievementsProvider>(NoopAchievementsProvider);\n\n/** Hook returning the current `AchievementsProvider`. */\nexport function useAchievements(): AchievementsProvider {\n return useContext(AchievementsContext);\n}\n"],"mappings":";AA2BO,IAAM,2BAAiD;AAAA,EAC5D,MAAM,SAAwB;AAAA,EAE9B;AAAA,EACA,MAAM,SAAS,IAA8C;AAC3D,WAAO,EAAE,IAAI,UAAU,OAAO,UAAU,EAAE;AAAA,EAC5C;AAAA,EACA,MAAM,SAA+C;AACnD,WAAO,CAAC;AAAA,EACV;AACF;;;ACrCA,SAAS,eAAe,kBAAkB;AAOnC,IAAM,sBAAsB,cAAoC,wBAAwB;AAGxF,SAAS,kBAAwC;AACtD,SAAO,WAAW,mBAAmB;AACvC;","names":[]}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/provider.ts","../src/context.ts","../src/memory.ts"],"sourcesContent":["/** Opaque achievement identifier — adapter-defined. */\nexport type AchievementId = string;\n\n/** Current state of an achievement for the local player. */\nexport interface AchievementState {\n id: AchievementId;\n unlocked: boolean;\n /** Partial progress in the range [0, 1]. `1` implies `unlocked: true`. */\n progress: number;\n unlockedAt?: number;\n}\n\n/**\n * Achievement provider interface. Consumers supply a concrete adapter (Game\n * Center, Google Play Games, Steam, custom backend) at the app boundary.\n * `unlock()` is idempotent by contract — adapters must dedupe.\n */\nexport interface AchievementsProvider {\n unlock(id: AchievementId, progress?: number): Promise<void>;\n getState(id: AchievementId): Promise<AchievementState>;\n getAll(): Promise<readonly AchievementState[]>;\n}\n\n/**\n * Default no-op provider. All queries report `unlocked: false, progress: 0`;\n * unlocks resolve silently.\n */\nexport const NoopAchievementsProvider: AchievementsProvider = {\n async unlock(): Promise<void> {\n // no-op\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return { id, unlocked: false, progress: 0 };\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [];\n },\n};\n","import { createContext, useContext } from 'react';\nimport { type AchievementsProvider, NoopAchievementsProvider } from './provider.js';\n\n/**\n * React context carrying the active `AchievementsProvider`. Defaults to\n * `NoopAchievementsProvider`.\n */\nexport const AchievementsContext = createContext<AchievementsProvider>(NoopAchievementsProvider);\n\n/** Hook returning the current `AchievementsProvider`. */\nexport function useAchievements(): AchievementsProvider {\n return useContext(AchievementsContext);\n}\n","import type { AchievementId, AchievementState, AchievementsProvider } from './provider.js';\n\n/**\n * Structural async key/value store the storage-backed provider persists into.\n * Matches the `get`/`set` subset of `@flare-engine/storage`'s `StorageAdapter`\n * so a real adapter can be injected without depending on the storage package.\n */\nexport interface AchievementsStore {\n /** Read a value. Resolves to `null` if the key is not present. */\n get(key: string): Promise<string | null>;\n /** Write a value. */\n set(key: string, value: string): Promise<void>;\n}\n\n/** Options common to the in-memory and storage-backed providers. */\nexport interface MemoryAchievementsOptions {\n /** Clock used to stamp `unlockedAt` on latch. Defaults to `() => Date.now()`. */\n now?: () => number;\n}\n\n/** Options for the storage-backed provider. */\nexport interface StorageAchievementsOptions extends MemoryAchievementsOptions {\n /** Persistence key passed to the injected store. Defaults to `'flare.achievements'`. */\n key?: string;\n}\n\nconst DEFAULT_KEY = 'flare.achievements';\n\n/** Coerce raw progress to `[0, 1]`; a non-finite value (NaN/Infinity) becomes `0`. */\nfunction normalizeProgress(value: number): number {\n if (!Number.isFinite(value)) return 0;\n if (value < 0) return 0;\n if (value > 1) return 1;\n return value;\n}\n\n/** Default state for an untracked id — no `unlockedAt`. */\nfunction defaultState(id: AchievementId): AchievementState {\n return { id, unlocked: false, progress: 0 };\n}\n\n/**\n * Pure state transition shared by both providers. Given the current state, an\n * optional progress arg and a clock, returns the next state:\n *\n * - `progress` omitted means a FULL unlock (target progress `1`).\n * - Progress is clamped to `[0, 1]`; non-finite input is treated as `0`.\n * - Progress is MONOTONIC — it never decreases below the stored value; a lower\n * requested progress is ignored.\n * - Unlock LATCHES: reaching progress `1` sets `unlocked: true` and stamps\n * `unlockedAt` once (via `now`). An already-unlocked state keeps its original\n * `unlockedAt`, so re-unlocking is a no-op.\n */\nfunction mergeAchievement(\n current: AchievementState,\n progress: number | undefined,\n now: () => number,\n): AchievementState {\n const requested = progress === undefined ? 1 : normalizeProgress(progress);\n const nextProgress = requested > current.progress ? requested : current.progress;\n if (!current.unlocked && nextProgress < 1) {\n return { id: current.id, unlocked: false, progress: nextProgress };\n }\n const unlockedAt = current.unlockedAt ?? now();\n return { id: current.id, unlocked: true, progress: 1, unlockedAt };\n}\n\n/**\n * In-memory `AchievementsProvider`. Progress is monotonic and unlocks latch with\n * a single `unlockedAt` stamp; see {@link mergeAchievement} for exact semantics.\n * State is not persisted — it lives for the lifetime of the returned provider.\n */\nexport function createMemoryAchievements(opts?: MemoryAchievementsOptions): AchievementsProvider {\n const now = opts?.now ?? (() => Date.now());\n const states = new Map<AchievementId, AchievementState>();\n return {\n async unlock(id: AchievementId, progress?: number): Promise<void> {\n states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n return states.get(id) ?? defaultState(id);\n },\n async getAll(): Promise<readonly AchievementState[]> {\n return [...states.values()];\n },\n };\n}\n\n/**\n * Storage-backed `AchievementsProvider`. Shares the monotonic/latch semantics of\n * {@link createMemoryAchievements} and persists into the injected\n * {@link AchievementsStore}.\n *\n * State hydrates lazily from `store.get(key)` on the first call (a JSON array of\n * `AchievementState`; a parse error hydrates empty) and is written back via\n * `store.set` after every mutation. All mutations are serialized through a single\n * chained tail promise so a read-modify-write can never interleave and lose an\n * update under concurrent unlocks.\n */\nexport function createStorageAchievements(\n store: AchievementsStore,\n opts?: StorageAchievementsOptions,\n): AchievementsProvider {\n const now = opts?.now ?? (() => Date.now());\n const key = opts?.key ?? DEFAULT_KEY;\n const states = new Map<AchievementId, AchievementState>();\n let hydration: Promise<void> | undefined;\n let tail: Promise<void> = Promise.resolve();\n\n function hydrate(): Promise<void> {\n if (hydration === undefined) {\n hydration = store.get(key).then((raw) => {\n if (raw === null) return;\n try {\n const parsed = JSON.parse(raw) as AchievementState[];\n for (const state of parsed) states.set(state.id, state);\n } catch {\n // Corrupt payload — hydrate empty.\n }\n });\n }\n return hydration;\n }\n\n function persist(): Promise<void> {\n return store.set(key, JSON.stringify([...states.values()]));\n }\n\n return {\n unlock(id: AchievementId, progress?: number): Promise<void> {\n const run = tail.then(async () => {\n await hydrate();\n states.set(id, mergeAchievement(states.get(id) ?? defaultState(id), progress, now));\n await persist();\n });\n // Swallow on the tail so one failed write cannot break serialization for\n // later mutations; the caller still observes the error via `run`.\n tail = run.catch(() => {});\n return run;\n },\n async getState(id: AchievementId): Promise<AchievementState> {\n await hydrate();\n return states.get(id) ?? defaultState(id);\n },\n async getAll(): Promise<readonly AchievementState[]> {\n await hydrate();\n return [...states.values()];\n },\n };\n}\n"],"mappings":"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"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@flare-engine/achievements",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Achievements provider interface (consumer-supplied adapter)",
5
5
  "keywords": ["flare-engine", "achievements", "provider", "interface"],
6
- "license": "MIT",
6
+ "license": "Apache-2.0",
7
7
  "author": "Grzegorz Otto",
8
8
  "homepage": "https://github.com/grzott/flare-engine#readme",
9
9
  "bugs": {
@@ -19,23 +19,31 @@
19
19
  "types": "dist/index.d.ts",
20
20
  "exports": {
21
21
  ".": {
22
- "types": "./dist/index.d.ts",
23
- "import": "./dist/index.mjs",
24
- "require": "./dist/index.js"
22
+ "import": {
23
+ "types": "./dist/index.d.mts",
24
+ "default": "./dist/index.mjs"
25
+ },
26
+ "require": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ }
25
30
  }
26
31
  },
27
- "files": ["dist", "README.md", "LICENSE"],
32
+ "files": ["dist", "README.md", "LICENSE", "NOTICE"],
28
33
  "scripts": {
29
- "build": "tsup",
34
+ "build": "tsdown",
30
35
  "test": "bun test",
31
36
  "lint": "biome check src/",
32
37
  "typecheck": "tsc --noEmit"
33
38
  },
34
39
  "devDependencies": {
35
- "@types/react": "^18.0.0"
40
+ "@types/react": "^19.0.0"
36
41
  },
37
42
  "peerDependencies": {
38
- "react": ">=18.0.0"
43
+ "react": ">=19.0.0"
44
+ },
45
+ "engines": {
46
+ "node": ">=20"
39
47
  },
40
48
  "publishConfig": {
41
49
  "access": "restricted",