@krtuworks/sdk 0.0.0-stage → 1.0.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/AGENTS.md +48 -0
- package/CHANGELOG.md +22 -0
- package/LICENSE +201 -0
- package/NOTICE +6 -0
- package/README.md +24 -2
- package/dist/api.d.ts +34 -0
- package/dist/api.js +61 -0
- package/dist/avatarReports.d.ts +15 -0
- package/dist/avatarReports.js +18 -0
- package/dist/bugs.d.ts +114 -0
- package/dist/bugs.js +276 -0
- package/dist/client.d.ts +390 -0
- package/dist/client.js +666 -0
- package/dist/clock.d.ts +19 -0
- package/dist/clock.js +32 -0
- package/dist/config.d.ts +85 -0
- package/dist/config.js +68 -0
- package/dist/deviceKey.d.ts +32 -0
- package/dist/deviceKey.js +26 -0
- package/dist/entitlements.d.ts +48 -0
- package/dist/entitlements.js +113 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.js +32 -0
- package/dist/events.d.ts +93 -0
- package/dist/events.js +304 -0
- package/dist/families.d.ts +94 -0
- package/dist/families.js +1 -0
- package/dist/files.d.ts +108 -0
- package/dist/files.js +215 -0
- package/dist/identity.d.ts +129 -0
- package/dist/identity.js +437 -0
- package/dist/ids.d.ts +13 -0
- package/dist/ids.js +61 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +7 -0
- package/dist/jwt.d.ts +2 -0
- package/dist/jwt.js +8 -0
- package/dist/locks.d.ts +6 -0
- package/dist/locks.js +20 -0
- package/dist/presence.d.ts +45 -0
- package/dist/presence.js +97 -0
- package/dist/progress.d.ts +108 -0
- package/dist/progress.js +347 -0
- package/dist/progression.d.ts +39 -0
- package/dist/progression.js +81 -0
- package/dist/remoteConfig.d.ts +48 -0
- package/dist/remoteConfig.js +70 -0
- package/dist/sessions.d.ts +45 -0
- package/dist/sessions.js +157 -0
- package/dist/store.d.ts +18 -0
- package/dist/store.js +57 -0
- package/dist/transport.d.ts +30 -0
- package/dist/transport.js +73 -0
- package/dist/validator.d.ts +43 -0
- package/dist/validator.js +252 -0
- package/package.json +40 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Krtuworks SDK for JavaScript and TypeScript: instructions for coding agents
|
|
2
|
+
|
|
3
|
+
`@krtuworks/sdk` connects a web game or app (browser or Node 20+) to Krtuworks: Krtuworks ID sign-in, guests, sessions, events, stats and achievements, cloud files, remote config and A/B tests. It has no dependencies.
|
|
4
|
+
|
|
5
|
+
## Before you start
|
|
6
|
+
- Check the project folder. A `*.uproject` file means Unreal: use the Krtuworks Unreal plugin. `ProjectSettings/ProjectVersion.txt` means Unity: use `com.krtuworks.sdk`. Only a `package.json` with neither means this package.
|
|
7
|
+
- Get the app's `krtuworks-config.json` from the partner console (the app's Credentials page) or from the Krtuworks MCP tool `get_setup`. Never write it by hand and never guess an id in it. It holds no secret, so it may be committed.
|
|
8
|
+
- In a browser, the app's web client must list the page's origin and the sign-in return address. Krtuworks sets them up on the Credentials page; a sign-in from an origin that is not listed fails.
|
|
9
|
+
|
|
10
|
+
## Required steps
|
|
11
|
+
1. `npm install @krtuworks/sdk`
|
|
12
|
+
2. Put `krtuworks-config.json` where the app can import it.
|
|
13
|
+
3. Call `Krtuworks.initialize` once, when the app starts, and keep the client it returns:
|
|
14
|
+
```ts
|
|
15
|
+
import { Krtuworks } from '@krtuworks/sdk';
|
|
16
|
+
import config from './krtuworks-config.json';
|
|
17
|
+
|
|
18
|
+
const krtu = await Krtuworks.initialize({ config, environment: 'TEST', platform: 'WEB', build: '1.4.2', redirectUri: 'https://example.com/signed-in' });
|
|
19
|
+
```
|
|
20
|
+
- `environment`: `TEST` while developing, `LIVE` in the released build. Test players and their data never reach LIVE.
|
|
21
|
+
- `build`: the version label of this build. Give each released build its own label.
|
|
22
|
+
- `platform`: where the app runs (`WEB`, `WINDOWS`, `MACOS`, `LINUX`, `IOS`, `ANDROID`, `STEAM` …).
|
|
23
|
+
- `redirectUri` (web): the sign-in return address. It must be one of the web client's registered https return addresses, set on the partner console's Credentials page. `signIn()` throws without it; `signIn({ redirectUri })` can give it later.
|
|
24
|
+
- Under Node there is no window, so the SDK uses the native client (the config's `clientId`, not `webClientId`) and needs no `redirectUri`. Use `platform: 'WINDOWS'`, `'MACOS'` or `'LINUX'`, not `'WEB'`.
|
|
25
|
+
4. Sign the player in. `await krtu.signInAsGuest({ birthDate: 'YYYY-MM-DD' })` makes a guest account with no sign-in screen: the app's age screen asks the birth date (13 or older) and shows the Krtuworks ID Terms and Privacy Notice, which the player accepts (`acceptedTerms` defaults to `CURRENT_TERMS`). On the next start the same device signs in again with no input. `await krtu.signIn()` opens Krtuworks ID; on the return page call `await krtu.completeSignIn()`. A guest who signs in keeps their progress.
|
|
26
|
+
5. Call `await krtu.shutdown()` when the app closes (Node). In a browser the SDK sends on its own when the page is hidden.
|
|
27
|
+
|
|
28
|
+
## Rules
|
|
29
|
+
- Events: `krtu.track(type, data)` with a ready-made family (`screen_view`, `economy`, `item`, `performance`, `settings`, `error` …) or a type defined on the console. It returns `false` when nothing was kept (the module is off, statistics are switched off, or the player opted out); that is not an error.
|
|
30
|
+
- Stats and achievements: `incrementStat`, `setStat`, `unlockAchievement`. They are kept on the device until the server has them and are never counted twice: do not add your own retry.
|
|
31
|
+
- Leaderboards: `submitScore(key, value, { details? })` (a whole number below 10^15, details 1 to 64 bytes) is kept on the device like a stat and never lost; the server decides what the board keeps. Read with `getLeaderboards()` (the player's own score and rank per board) and `getLeaderboardEntries(key, { scope: 'global' | 'around', limit, offset })`. Names shown are Krtuworks usernames (`null`: show "Player"). Reads throw `module_disabled` while the leaderboards module is off; scores wait. The SDK never writes scores to a platform; the server mirrors them.
|
|
32
|
+
- Rich presence (games only): `setPresence(key, params?)` answers `{ applied, reason? }` and never throws for those reasons (`not_game`, `module_disabled`, `hidden`, `unknown_state`, `param_missing`, `states_unknown`). The states are declared on the console; `LEVEL` (the open `level.start`) and `SESSION_MINUTES` fill themselves. A browser has no platform presence, so a call that passes every rule answers `no_platform`; `clearPresence()` and `setPresenceGroup()` do nothing there. The player's choice: `presenceVisible()` (cached, `null` until known) and `await setPresenceVisible(bool)`; false makes `setPresence` answer `hidden`.
|
|
33
|
+
- DLC ownership (games only): `ownsDlc(key)` takes the DLC's product key from the console and answers at once with a boolean (`false` for an unknown key). It reads what the server confirmed in this launch, else the last server answer kept on the device, so it works offline after one online launch. `entitlements()` lists the licences (`sku` `base` first, then the DLCs; `status` `ACTIVE`, `REVOKED` or `null`; `checked` is true for what the server confirmed in this launch) and `await refreshEntitlements()` asks the server now. Do not keep your own ownership flags.
|
|
34
|
+
- Levels and deaths (`krtu.level.*`, `death`) are for games only; in an app they do nothing.
|
|
35
|
+
- Cloud files: `krtu.files.save(slot, bytes)` and `krtu.files.read(slot)`. A save conflict (`file_conflict`) carries the current version: let the player choose, do not overwrite.
|
|
36
|
+
- Check `krtu.gate()` at start: it tells about maintenance and a required update.
|
|
37
|
+
- Errors are `KrtuworksError` with a `code`. A network error does not lose data: the SDK keeps what it has and sends it later.
|
|
38
|
+
- Never put a server key or any other Krtuworks secret into app code. This package needs none.
|
|
39
|
+
|
|
40
|
+
## Verify
|
|
41
|
+
Run the validator against TEST. It checks the config, the build label and the platform, then makes a test round (sign-in, session, event, remote config, cloud save, progress, bug report) with the app's own setup:
|
|
42
|
+
```ts
|
|
43
|
+
import { validate } from '@krtuworks/sdk';
|
|
44
|
+
|
|
45
|
+
const report = await validate({ config, platform: 'WEB', build: '1.4.2', redirectUri: 'https://example.com/signed-in' });
|
|
46
|
+
console.log(report.ok, report.checks);
|
|
47
|
+
```
|
|
48
|
+
`report.ok` must be `true`. Each check is `PASSED`, `FAILED` (with `detail`) or `SKIPPED` (a module that is off, an app with no save slots or no achievements). A build whose report is not green is not released in LIVE. In a browser (the web client) the validator also needs an https `redirectUri`, one of the web client's registered return addresses.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@krtuworks/sdk`. Versions follow semantic versioning; a breaking change is marked **Breaking**.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
First release.
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
- `Krtuworks.initialize` with the app's `krtuworks-config.json`, TEST and LIVE environments, the app's type (`GAME`, `MOBILE_APP`, `WEB_APP`, `DESKTOP_APP`).
|
|
11
|
+
- Guests with a device key (no sign-in screen), Krtuworks ID sign-in in the browser (PKCE), a guest's progress kept when they sign in.
|
|
12
|
+
- Sessions, events (ready-made families and the app's own types), levels and deaths for games.
|
|
13
|
+
- Stats and achievements kept on the device until the server has them, never counted twice; platform achievement sync (with the open session: the server mirrors only with the platform account the session proved).
|
|
14
|
+
- Cloud saves with conflict handling and resumable uploads.
|
|
15
|
+
- Remote config, SDK modules, maintenance and required-update gate, A/B tests, player profile card.
|
|
16
|
+
- Bug reports with a screenshot and the "fixed" notice; profile picture reports.
|
|
17
|
+
- A guest's account deletion, its cancellation and data copy from inside the app.
|
|
18
|
+
- The validator (`validate`) for the release report.
|
|
19
|
+
- Leaderboards (the `leaderboards` module): `submitScore` kept on the device until the server has it (a lost answer goes again with the same op id), `getLeaderboards()` and `getLeaderboardEntries()` (global or around the player).
|
|
20
|
+
- Rich presence (games only): `setPresence`, `clearPresence`, `setPresenceGroup`, `presenceVisible`, `setPresenceVisible` and the `presence` module. The states and the player's choice are kept per player and revalidated with the ETag; a browser has no platform presence, so a valid `setPresence` answers `no_platform`.
|
|
21
|
+
- `getProgress()` stats carry `platformIds` (a stat's name on Steam).
|
|
22
|
+
- DLC ownership: `entitlements()` (the licences the server last said, kept per player and environment on the device), `refreshEntitlements()` (`GET /v1/me/entitlements`) and `ownsDlc(key)`. A browser has no platform client to ask, so it answers with what the server confirmed in this launch, else the last server answer kept from an earlier launch.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 [yyyy] [name of copyright owner]
|
|
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,6 @@
|
|
|
1
|
+
Krtuworks SDK
|
|
2
|
+
Copyright 2026 Krtuworks LLC
|
|
3
|
+
|
|
4
|
+
This product includes software developed at Krtuworks LLC (https://krtuworks.com).
|
|
5
|
+
"Krtuworks" and the Krtuworks logo are trademarks of Krtuworks LLC; the Apache License does not grant
|
|
6
|
+
permission to use them (section 6).
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Krtuworks SDK for JavaScript and TypeScript
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@krtuworks/sdk` connects a web game or app (browser or Node 20+) to Krtuworks: Krtuworks ID sign-in and guests with no sign-in screen, sessions, events and dashboards, stats, achievements and leaderboards, cloud saves, remote config and A/B tests, bug reports and the release report. It has no dependencies.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @krtuworks/sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Krtuworks } from '@krtuworks/sdk';
|
|
11
|
+
import config from './krtuworks-config.json';
|
|
12
|
+
|
|
13
|
+
const krtu = await Krtuworks.initialize({ config, environment: 'TEST', platform: 'WEB', build: '1.0.0', redirectUri: 'https://example.com/signed-in' });
|
|
14
|
+
await krtu.signInAsGuest({ birthDate: '2000-01-31' });
|
|
15
|
+
krtu.track('screen_view', { screen: 'menu' });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Your app's `krtuworks-config.json` comes from the app's Credentials page in the [partner console](https://partner.krtuworks.com).
|
|
19
|
+
|
|
20
|
+
- Documentation: [partner.krtuworks.com/docs](https://partner.krtuworks.com/docs)
|
|
21
|
+
- Coding agents: [`AGENTS.md`](AGENTS.md)
|
|
22
|
+
- Changes: [`CHANGELOG.md`](CHANGELOG.md)
|
|
23
|
+
- Support: support@krtuworks.com
|
|
24
|
+
|
|
25
|
+
Licensed under the [Apache License 2.0](LICENSE). The Krtuworks name and logo are not covered by the licence ([`NOTICE`](NOTICE)).
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Clock } from './clock.js';
|
|
2
|
+
import type { ResolvedOptions } from './config.js';
|
|
3
|
+
import type { Identity } from './identity.js';
|
|
4
|
+
import { type Answer } from './transport.js';
|
|
5
|
+
export interface PlayerCall {
|
|
6
|
+
method?: string;
|
|
7
|
+
query?: Record<string, string | number | boolean | undefined | null>;
|
|
8
|
+
json?: unknown;
|
|
9
|
+
body?: BodyInit;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
/** Read the body as bytes (a file). */
|
|
12
|
+
bytes?: boolean;
|
|
13
|
+
keepalive?: boolean;
|
|
14
|
+
/** Statuses that are answers, not failures (304, 202 …); 2xx always are. */
|
|
15
|
+
accept?: number[];
|
|
16
|
+
}
|
|
17
|
+
/** The player's calls to the server (`/v1`, Bearer + X-Krtu-Build). */
|
|
18
|
+
export declare class Api {
|
|
19
|
+
private readonly opts;
|
|
20
|
+
private readonly identity;
|
|
21
|
+
private readonly fetchFn;
|
|
22
|
+
private readonly clock;
|
|
23
|
+
constructor(opts: ResolvedOptions, identity: Identity, fetchFn: typeof fetch, clock: Clock);
|
|
24
|
+
url(path: string, query?: PlayerCall['query']): string;
|
|
25
|
+
/** A call without a player (the remote config). */
|
|
26
|
+
open(path: string, call?: PlayerCall): Promise<Answer>;
|
|
27
|
+
/**
|
|
28
|
+
* A player's call. An expired or revoked token is refreshed once and the call made again; a merged
|
|
29
|
+
* account is reported to the identity; an answer that arrives after the player changed is dropped
|
|
30
|
+
* (`context_changed`), so it can never land in another player's state.
|
|
31
|
+
*/
|
|
32
|
+
player(path: string, call?: PlayerCall): Promise<Answer>;
|
|
33
|
+
private attempt;
|
|
34
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { KrtuworksError } from './errors.js';
|
|
2
|
+
import { errorOf, send } from './transport.js';
|
|
3
|
+
/** The player's calls to the server (`/v1`, Bearer + X-Krtu-Build). */
|
|
4
|
+
export class Api {
|
|
5
|
+
opts;
|
|
6
|
+
identity;
|
|
7
|
+
fetchFn;
|
|
8
|
+
clock;
|
|
9
|
+
constructor(opts, identity, fetchFn, clock) {
|
|
10
|
+
this.opts = opts;
|
|
11
|
+
this.identity = identity;
|
|
12
|
+
this.fetchFn = fetchFn;
|
|
13
|
+
this.clock = clock;
|
|
14
|
+
}
|
|
15
|
+
url(path, query) {
|
|
16
|
+
const url = new URL(`${this.opts.devOrigin}${path}`);
|
|
17
|
+
for (const [k, v] of Object.entries(query ?? {}))
|
|
18
|
+
if (v !== undefined && v !== null)
|
|
19
|
+
url.searchParams.set(k, String(v));
|
|
20
|
+
return url.toString();
|
|
21
|
+
}
|
|
22
|
+
/** A call without a player (the remote config). */
|
|
23
|
+
async open(path, call = {}) {
|
|
24
|
+
const answer = await send(this.fetchFn, this.clock, this.url(path, call.query), { method: call.method ?? 'GET', headers: { ...call.headers } });
|
|
25
|
+
if (answer.status >= 400 && !call.accept?.includes(answer.status))
|
|
26
|
+
throw errorOf(answer);
|
|
27
|
+
return answer;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A player's call. An expired or revoked token is refreshed once and the call made again; a merged
|
|
31
|
+
* account is reported to the identity; an answer that arrives after the player changed is dropped
|
|
32
|
+
* (`context_changed`), so it can never land in another player's state.
|
|
33
|
+
*/
|
|
34
|
+
async player(path, call = {}) {
|
|
35
|
+
const generation = this.identity.generation;
|
|
36
|
+
const subject = this.identity.player?.subject ?? null;
|
|
37
|
+
let answer = await this.attempt(path, call, false);
|
|
38
|
+
if (answer.status === 401) {
|
|
39
|
+
const err = errorOf(answer);
|
|
40
|
+
if (err.code === 'account_merged' && subject)
|
|
41
|
+
await this.identity.markMerged(subject, typeof err.details.mergedInto === 'string' ? err.details.mergedInto : null);
|
|
42
|
+
if (err.code === 'token_expired' || err.code === 'token_revoked' || err.code === 'invalid_token')
|
|
43
|
+
answer = await this.attempt(path, call, true);
|
|
44
|
+
}
|
|
45
|
+
if (this.identity.generation !== generation)
|
|
46
|
+
throw new KrtuworksError('context_changed', 'The player changed while the call ran; its answer was dropped.');
|
|
47
|
+
if ((answer.status >= 300 || answer.status < 200) && !call.accept?.includes(answer.status))
|
|
48
|
+
throw errorOf(answer);
|
|
49
|
+
return answer;
|
|
50
|
+
}
|
|
51
|
+
async attempt(path, call, forceRefresh) {
|
|
52
|
+
const token = await this.identity.accessToken(forceRefresh);
|
|
53
|
+
const headers = { authorization: `Bearer ${token}`, 'x-krtu-build': this.opts.build, ...call.headers };
|
|
54
|
+
let body = call.body;
|
|
55
|
+
if (call.json !== undefined) {
|
|
56
|
+
headers['content-type'] = 'application/json';
|
|
57
|
+
body = JSON.stringify(call.json);
|
|
58
|
+
}
|
|
59
|
+
return send(this.fetchFn, this.clock, this.url(path, call.query), { method: call.method ?? 'GET', headers, body, bytes: call.bytes, keepalive: call.keepalive });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reporting another player's profile picture (POST /v1/players/:subject/avatar-report): a reason from a
|
|
3
|
+
* fixed list and an optional note. Krtuworks reviews the picture; the player who reports is never told
|
|
4
|
+
* an outcome. One report per player and picture, at most 10 a day.
|
|
5
|
+
*/
|
|
6
|
+
export declare const AVATAR_REPORT_REASONS: readonly ["SEXUAL", "HATE", "VIOLENCE", "IMPERSONATION", "SPAM", "OTHER"];
|
|
7
|
+
export type AvatarReportReason = (typeof AVATAR_REPORT_REASONS)[number];
|
|
8
|
+
export declare const AVATAR_REPORT_NOTE_MAX = 300;
|
|
9
|
+
export declare function avatarReportBody(subject: string, reason: string, note?: string | null): {
|
|
10
|
+
path: string;
|
|
11
|
+
json: {
|
|
12
|
+
reason: AvatarReportReason;
|
|
13
|
+
note?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KrtuworksError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reporting another player's profile picture (POST /v1/players/:subject/avatar-report): a reason from a
|
|
4
|
+
* fixed list and an optional note. Krtuworks reviews the picture; the player who reports is never told
|
|
5
|
+
* an outcome. One report per player and picture, at most 10 a day.
|
|
6
|
+
*/
|
|
7
|
+
export const AVATAR_REPORT_REASONS = ['SEXUAL', 'HATE', 'VIOLENCE', 'IMPERSONATION', 'SPAM', 'OTHER'];
|
|
8
|
+
export const AVATAR_REPORT_NOTE_MAX = 300;
|
|
9
|
+
export function avatarReportBody(subject, reason, note) {
|
|
10
|
+
if (typeof subject !== 'string' || !subject || subject.length > 200)
|
|
11
|
+
throw new KrtuworksError('invalid_request', 'Name the player by the subject your app knows them by.', 400);
|
|
12
|
+
if (!AVATAR_REPORT_REASONS.includes(reason))
|
|
13
|
+
throw new KrtuworksError('invalid_request', `reason is one of ${AVATAR_REPORT_REASONS.join(', ')}.`, 400);
|
|
14
|
+
const trimmed = typeof note === 'string' ? note.trim() : '';
|
|
15
|
+
if (trimmed.length > AVATAR_REPORT_NOTE_MAX)
|
|
16
|
+
throw new KrtuworksError('invalid_request', `A note is at most ${AVATAR_REPORT_NOTE_MAX} characters.`, 400);
|
|
17
|
+
return { path: `/v1/players/${encodeURIComponent(subject)}/avatar-report`, json: { reason: reason, ...(trimmed ? { note: trimmed } : {}) } };
|
|
18
|
+
}
|
package/dist/bugs.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { Api } from './api.js';
|
|
2
|
+
import type { ResolvedOptions } from './config.js';
|
|
3
|
+
import type { EventPosition, WireEvent } from './events.js';
|
|
4
|
+
import type { KrtuStore } from './store.js';
|
|
5
|
+
/** The fixed categories: the same menu in every app. */
|
|
6
|
+
export declare const BUG_CATEGORIES: readonly ["CRASH", "GAMEPLAY", "GRAPHICS", "AUDIO", "PERFORMANCE", "CONTROLS", "TEXT", "OTHER"];
|
|
7
|
+
export type BugCategory = (typeof BUG_CATEGORIES)[number];
|
|
8
|
+
export interface BugReportInput {
|
|
9
|
+
category: BugCategory;
|
|
10
|
+
/** What the player wrote, 1-4000 characters. */
|
|
11
|
+
description: string;
|
|
12
|
+
/** A picture of the screen (PNG, JPEG or WebP, at most 5 MB); the player may leave it out. */
|
|
13
|
+
screenshot?: Uint8Array | ArrayBuffer | Blob;
|
|
14
|
+
/** Where the player is; the level in play when not given. */
|
|
15
|
+
level?: string;
|
|
16
|
+
position?: EventPosition;
|
|
17
|
+
/** The frame rate now; the last one the performance family told when not given. */
|
|
18
|
+
fps?: number;
|
|
19
|
+
}
|
|
20
|
+
/** A report as its player sees it: never the notes, the assignee or the labels. */
|
|
21
|
+
export interface BugReportView {
|
|
22
|
+
id: string;
|
|
23
|
+
category: BugCategory;
|
|
24
|
+
description: string | null;
|
|
25
|
+
platform: string;
|
|
26
|
+
build: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
screenshot: boolean;
|
|
29
|
+
/** NEW, INVESTIGATING, RESOLVED, CANNOT_REPRODUCE or DUPLICATE; a duplicate shows its original's. */
|
|
30
|
+
status: string;
|
|
31
|
+
fixedIn: string | null;
|
|
32
|
+
fixedAt: string | null;
|
|
33
|
+
duplicate: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface BugFlushResult {
|
|
36
|
+
sent: number;
|
|
37
|
+
/** Reports or screenshots the server refused for good; they are not sent again. */
|
|
38
|
+
dropped: Array<{
|
|
39
|
+
reportId: string;
|
|
40
|
+
code: string;
|
|
41
|
+
screenshotOnly: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
stoppedBy?: string;
|
|
44
|
+
}
|
|
45
|
+
interface FixedState {
|
|
46
|
+
told: string[];
|
|
47
|
+
}
|
|
48
|
+
/** The picture's type from its first bytes (what the server takes). */
|
|
49
|
+
export declare function screenshotType(bytes: Uint8Array): string | null;
|
|
50
|
+
/**
|
|
51
|
+
* The body the server takes for a report: the player's words and what the SDK knows of the moment (the
|
|
52
|
+
* platform, build, device, language, level, place, frame rate, the last events and log lines).
|
|
53
|
+
* Checked here so a report that can never be taken is refused at once instead of waiting in the queue.
|
|
54
|
+
*/
|
|
55
|
+
export declare function reportBody(input: BugReportInput, context: {
|
|
56
|
+
reportId: string;
|
|
57
|
+
opts: ResolvedOptions;
|
|
58
|
+
level: string | null;
|
|
59
|
+
fps: number | null;
|
|
60
|
+
events: Record<string, unknown>[];
|
|
61
|
+
log: string;
|
|
62
|
+
}): Record<string, unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* The reports a player told about since the last check: the first check of a player on this device
|
|
65
|
+
* tells nothing (it only learns what was already fixed); a report made here starts the record empty,
|
|
66
|
+
* so its fix is told even when another device saw it first.
|
|
67
|
+
*/
|
|
68
|
+
export declare function newlyFixed(reports: BugReportView[], state: FixedState | undefined): {
|
|
69
|
+
fixed: BugReportView[];
|
|
70
|
+
state: FixedState;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Bug reports from inside the app: a report is kept on the device first and
|
|
74
|
+
* sent when it can be (offline, before the player exists, after a merge), its screenshot right after
|
|
75
|
+
* it. The server takes a reportId once; the body is frozen when the report is made, so sending it again
|
|
76
|
+
* after a lost answer gets the same report. The last events and log lines are kept in memory only.
|
|
77
|
+
*/
|
|
78
|
+
export declare class BugReports {
|
|
79
|
+
private readonly opts;
|
|
80
|
+
private readonly store;
|
|
81
|
+
private readonly api;
|
|
82
|
+
private readonly owner;
|
|
83
|
+
private readonly subject;
|
|
84
|
+
private readonly events;
|
|
85
|
+
private logLines;
|
|
86
|
+
private logChars;
|
|
87
|
+
private lastFps;
|
|
88
|
+
/** Reports that wait before their next try (in memory: a new launch tries them all again). */
|
|
89
|
+
private readonly waitUntil;
|
|
90
|
+
private readonly fixedListeners;
|
|
91
|
+
constructor(opts: ResolvedOptions, store: KrtuStore, api: Api, owner: () => string, subject: () => string | null);
|
|
92
|
+
private prefix;
|
|
93
|
+
private fixedKey;
|
|
94
|
+
/** An event the SDK kept, for the next report's "last events". */
|
|
95
|
+
noteEvent(event: WireEvent): void;
|
|
96
|
+
/** A line for the next report's log (the app's own, and the errors the SDK told). */
|
|
97
|
+
log(message: string): void;
|
|
98
|
+
report(input: BugReportInput, level: string | null): Promise<{
|
|
99
|
+
reportId: string;
|
|
100
|
+
}>;
|
|
101
|
+
/** Reports (with their screenshots) that wait on this device for the player, or for the first player. */
|
|
102
|
+
waiting(): Promise<number>;
|
|
103
|
+
/** Hands one owner's waiting reports to another (the anonymous queue to the first player, a confirmed merge). */
|
|
104
|
+
move(from: string, to: string): Promise<void>;
|
|
105
|
+
flush(now?: number): Promise<BugFlushResult>;
|
|
106
|
+
/** The player's reports in this app and environment, newest first; fixes not told yet are told. */
|
|
107
|
+
mine(): Promise<BugReportView[]>;
|
|
108
|
+
/** At a player's arrival: only when this device keeps a record for them (they reported here, or the app read their reports). */
|
|
109
|
+
checkFixed(): Promise<void>;
|
|
110
|
+
private tellFixed;
|
|
111
|
+
onFixed(listener: (report: BugReportView) => void): () => void;
|
|
112
|
+
resetBackoff(): void;
|
|
113
|
+
}
|
|
114
|
+
export {};
|