@totop/platform-sdk 1.1.0 → 1.1.2
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/AI-INTEGRATION.md +2 -2
- package/README.md +8 -2
- package/dist/core.d.ts +6 -3
- package/dist/index.d.ts +3 -3
- package/dist/totop-platform.esm.js +9 -11
- package/dist/totop-platform.global.js +9 -11
- package/package.json +1 -1
package/AI-INTEGRATION.md
CHANGED
|
@@ -5,7 +5,7 @@ Follow these instructions exactly when integrating ToTop authentication with Cur
|
|
|
5
5
|
1. Install the exact reviewed version of `@totop/platform-sdk` supplied by ToTop.
|
|
6
6
|
2. Copy the supplied `totop.auth.json` to the application's public root. Do not edit its `clientId`, URLs, type, scopes, or minimum SDK version.
|
|
7
7
|
3. Import `ToTop` and call `await ToTop.init('/totop.auth.json')` once during application startup. This call also completes an OAuth callback when `code` and `state` are present.
|
|
8
|
-
4. Call `await ToTop.login()` when the user chooses to sign in. Do not implement OAuth, PKCE, token exchange, refresh, or callback parsing yourself.
|
|
8
|
+
4. Call `await ToTop.login()` when the user chooses to sign in. Use `await ToTop.login({ selectAccount: true })` only for an explicit “Switch account” action or when the product requires account choice after local sign-out. Do not implement OAuth, PKCE, token exchange, refresh, or callback parsing yourself.
|
|
9
9
|
5. Read the display profile with `ToTop.getUser()`.
|
|
10
10
|
6. Call `ToTop.authorizedFetch()` for ToTop protected APIs. Never manually add a bearer token unless implementing a reviewed server integration.
|
|
11
11
|
7. For a game, use `ToTop.cloudSave.save/load/list/restore`; do not call the save API or implement revision handling manually. Handle `ToTopCloudSaveConflictError` without silently overwriting its `currentSave`.
|
|
@@ -14,4 +14,4 @@ Follow these instructions exactly when integrating ToTop authentication with Cur
|
|
|
14
14
|
10. Do not add a client secret to browser code. Browser apps and games are public PKCE clients.
|
|
15
15
|
11. Run `npx totop-platform verify` and resolve every failure before delivery.
|
|
16
16
|
|
|
17
|
-
The application must not silently authorize after local sign-out. A signed-in ToTop browser session may skip credential entry only after the user chooses the application’s sign-in action.
|
|
17
|
+
The application must not silently authorize after local sign-out. A signed-in ToTop browser session may skip credential entry only after the user chooses the application’s sign-in action. Local sign-out does not end the shared ToTop SSO session; account switching must use `login({ selectAccount: true })`, not global logout.
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Browser SDK for reviewed ToTop applications and games. It provides unified identity, protected API access, cloud saves, token rotation, and local/global logout separation.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npm install @totop/platform-sdk@1.1.
|
|
6
|
+
npm install @totop/platform-sdk@1.1.2
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```ts
|
|
@@ -12,6 +12,10 @@ import { ToTop } from '@totop/platform-sdk'
|
|
|
12
12
|
await ToTop.init('/totop.auth.json')
|
|
13
13
|
await ToTop.login()
|
|
14
14
|
|
|
15
|
+
// Use this only for an explicit “Switch account” action, or when a product
|
|
16
|
+
// wants account choice after its own local sign-out.
|
|
17
|
+
await ToTop.login({ selectAccount: true })
|
|
18
|
+
|
|
15
19
|
const user = ToTop.getUser()
|
|
16
20
|
|
|
17
21
|
// Games get cloud save without implementing HTTP, tokens or revision handling.
|
|
@@ -23,7 +27,7 @@ const response = await ToTop.authorizedFetch('https://api.totop.ai/game-api/game
|
|
|
23
27
|
await ToTop.logout()
|
|
24
28
|
```
|
|
25
29
|
|
|
26
|
-
The reviewed `totop.auth.json` is public configuration and contains no secret. Access tokens stay in memory; rotating refresh tokens are limited to the current browser tab's `sessionStorage
|
|
30
|
+
The reviewed `totop.auth.json` is public configuration and contains no secret. Access tokens stay in memory; rotating refresh tokens are limited to the current browser tab's `sessionStorage`. The server enforces an absolute 30-day lifetime for every refresh-token family.
|
|
27
31
|
|
|
28
32
|
## Cloud save (game clients)
|
|
29
33
|
|
|
@@ -43,3 +47,5 @@ await ToTop.cloudSave.restore((payload, save) => game.restore(payload), 0)
|
|
|
43
47
|
The SDK remembers each loaded revision and sends the correct optimistic-concurrency value automatically. A concurrent write throws `ToTopCloudSaveConflictError`, whose `currentSave` is the authoritative cloud copy. A save payload must be a JSON object and is limited to 1 MiB per slot.
|
|
44
48
|
|
|
45
49
|
Run `npx totop-platform verify` in the integrating project before publishing.
|
|
50
|
+
|
|
51
|
+
`logout()` ends only the current SDK client session; it intentionally keeps the shared `auth.totop.ai` browser session so other ToTop services remain signed in. A later `login()` may reuse that account. Use `login({ selectAccount: true })` for an explicit account-choice flow. Reserve `logout({ global: true })` for a separately labelled “Sign out everywhere” action.
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const PLATFORM_SDK_VERSION = "1.1.
|
|
1
|
+
export declare const PLATFORM_SDK_VERSION = "1.1.2";
|
|
2
2
|
export type ToTopPlatformConfig = {
|
|
3
3
|
version: 1;
|
|
4
4
|
clientId: string;
|
|
@@ -29,6 +29,9 @@ export type ToTopCloudSaveOptions = {
|
|
|
29
29
|
schemaVersion?: number;
|
|
30
30
|
baseRevision?: number;
|
|
31
31
|
};
|
|
32
|
+
export type ToTopLoginOptions = {
|
|
33
|
+
selectAccount?: boolean;
|
|
34
|
+
};
|
|
32
35
|
export declare class ToTopCloudSaveConflictError<T extends Record<string, unknown> = Record<string, unknown>> extends Error {
|
|
33
36
|
readonly currentSave: ToTopCloudSave<T> | null;
|
|
34
37
|
readonly code = "revision_conflict";
|
|
@@ -81,8 +84,8 @@ export declare class ToTopPlatformClient {
|
|
|
81
84
|
private parseCloudSave;
|
|
82
85
|
init(input?: ToTopPlatformConfig | string): Promise<this>;
|
|
83
86
|
handleCallback(): Promise<boolean>;
|
|
84
|
-
login(): Promise<void>;
|
|
85
|
-
requireLogin(): Promise<void>;
|
|
87
|
+
login(input?: ToTopLoginOptions): Promise<void>;
|
|
88
|
+
requireLogin(input?: ToTopLoginOptions): Promise<void>;
|
|
86
89
|
getUser(): ToTopUser | null;
|
|
87
90
|
getAccessToken(): Promise<string>;
|
|
88
91
|
authorizedFetch(input: string | URL, init?: RequestInit): Promise<Response>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ export declare const ToTop: {
|
|
|
3
3
|
version: string;
|
|
4
4
|
init: (input?: ToTopPlatformConfig | string) => Promise</*elided*/ any>;
|
|
5
5
|
handleCallback: () => Promise<boolean>;
|
|
6
|
-
login: () => Promise<void>;
|
|
7
|
-
requireLogin: () => Promise<void>;
|
|
6
|
+
login: (input?: import("./core.js").ToTopLoginOptions) => Promise<void>;
|
|
7
|
+
requireLogin: (input?: import("./core.js").ToTopLoginOptions) => Promise<void>;
|
|
8
8
|
getUser: () => import("./core.js").ToTopUser | null;
|
|
9
9
|
getAccessToken: () => Promise<string>;
|
|
10
10
|
authorizedFetch: (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
@@ -19,4 +19,4 @@ export declare const ToTop: {
|
|
|
19
19
|
}) => Promise<void>;
|
|
20
20
|
};
|
|
21
21
|
export { ToTopPlatformClient, PLATFORM_SDK_VERSION, MemoryTabStorage, ToTopCloudSaveConflictError, validateConfig } from './core.js';
|
|
22
|
-
export type { ToTopPlatformConfig, ToTopCloudSave, ToTopCloudSaveOptions, ToTopUser, TabStorage } from './core.js';
|
|
22
|
+
export type { ToTopPlatformConfig, ToTopCloudSave, ToTopCloudSaveOptions, ToTopLoginOptions, ToTopUser, TabStorage } from './core.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/auth-sdk/src/core.ts
|
|
2
|
-
var PLATFORM_SDK_VERSION = "1.1.
|
|
2
|
+
var PLATFORM_SDK_VERSION = "1.1.2";
|
|
3
3
|
var CONFIG_VERSION = 1;
|
|
4
4
|
var MAX_CLOUD_SAVE_BYTES = 1024 * 1024;
|
|
5
5
|
var SESSION_PREFIX = "totop:auth-sdk:";
|
|
@@ -212,12 +212,12 @@ var ToTopPlatformClient = class {
|
|
|
212
212
|
throw error;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
async login() {
|
|
216
|
-
return this.requireLogin();
|
|
215
|
+
async login(input = {}) {
|
|
216
|
+
return this.requireLogin(input);
|
|
217
217
|
}
|
|
218
|
-
async requireLogin() {
|
|
218
|
+
async requireLogin(input = {}) {
|
|
219
219
|
const config = this.requireConfig();
|
|
220
|
-
if (this.accessToken && this.accessExpiresAt > this.now() + 5e3) return;
|
|
220
|
+
if (!input.selectAccount && this.accessToken && this.accessExpiresAt > this.now() + 5e3) return;
|
|
221
221
|
const verifier = b64url((this.deps.randomBytes ?? random)(32));
|
|
222
222
|
const state = b64url((this.deps.randomBytes ?? random)(24));
|
|
223
223
|
const digest = this.deps.digest ?? (async (value) => new Uint8Array(await crypto.subtle.digest("SHA-256", value)));
|
|
@@ -235,7 +235,7 @@ var ToTopPlatformClient = class {
|
|
|
235
235
|
url = new URL("/oauth/authorize", config.issuer);
|
|
236
236
|
url.search = new URLSearchParams({ client_id: config.clientId, response_type: "code", redirect_uri: config.redirectUri, scope: config.scopes.join(" "), resource: this.resource(), state, code_challenge: challenge, code_challenge_method: "S256" }).toString();
|
|
237
237
|
}
|
|
238
|
-
;
|
|
238
|
+
if (input.selectAccount) url.searchParams.set("prompt", "select_account");
|
|
239
239
|
(this.deps.navigate ?? ((target) => location.assign(target)))(url.href);
|
|
240
240
|
}
|
|
241
241
|
getUser() {
|
|
@@ -337,8 +337,7 @@ var ToTopPlatformClient = class {
|
|
|
337
337
|
if (this.refreshFlight) return this.refreshFlight;
|
|
338
338
|
const config = this.requireConfig();
|
|
339
339
|
const token = this.deps.storage.getItem(this.key("refresh"));
|
|
340
|
-
|
|
341
|
-
if (!token || familyExpires <= this.now()) {
|
|
340
|
+
if (!token) {
|
|
342
341
|
this.clearState();
|
|
343
342
|
throw new Error("login required");
|
|
344
343
|
}
|
|
@@ -381,7 +380,6 @@ var ToTopPlatformClient = class {
|
|
|
381
380
|
this.accessToken = result.access_token;
|
|
382
381
|
this.accessExpiresAt = this.now() + result.expires_in * 1e3;
|
|
383
382
|
this.deps.storage.setItem(this.key("refresh"), result.refresh_token);
|
|
384
|
-
if (!this.deps.storage.getItem(this.key("family_expires"))) this.deps.storage.setItem(this.key("family_expires"), String(this.now() + 8 * 60 * 60 * 1e3));
|
|
385
383
|
} finally {
|
|
386
384
|
this.controllers.delete(controller);
|
|
387
385
|
}
|
|
@@ -406,8 +404,8 @@ var ToTop = {
|
|
|
406
404
|
return ToTop;
|
|
407
405
|
},
|
|
408
406
|
handleCallback: () => browserClient().handleCallback(),
|
|
409
|
-
login: () => browserClient().login(),
|
|
410
|
-
requireLogin: () => browserClient().requireLogin(),
|
|
407
|
+
login: (input) => browserClient().login(input),
|
|
408
|
+
requireLogin: (input) => browserClient().requireLogin(input),
|
|
411
409
|
getUser: () => browserClient().getUser(),
|
|
412
410
|
getAccessToken: () => browserClient().getAccessToken(),
|
|
413
411
|
authorizedFetch: (input, init) => browserClient().authorizedFetch(input, init),
|
|
@@ -30,7 +30,7 @@ var ToTopPlatformSDK = (() => {
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
// packages/auth-sdk/src/core.ts
|
|
33
|
-
var PLATFORM_SDK_VERSION = "1.1.
|
|
33
|
+
var PLATFORM_SDK_VERSION = "1.1.2";
|
|
34
34
|
var CONFIG_VERSION = 1;
|
|
35
35
|
var MAX_CLOUD_SAVE_BYTES = 1024 * 1024;
|
|
36
36
|
var SESSION_PREFIX = "totop:auth-sdk:";
|
|
@@ -243,12 +243,12 @@ var ToTopPlatformSDK = (() => {
|
|
|
243
243
|
throw error;
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
|
-
async login() {
|
|
247
|
-
return this.requireLogin();
|
|
246
|
+
async login(input = {}) {
|
|
247
|
+
return this.requireLogin(input);
|
|
248
248
|
}
|
|
249
|
-
async requireLogin() {
|
|
249
|
+
async requireLogin(input = {}) {
|
|
250
250
|
const config = this.requireConfig();
|
|
251
|
-
if (this.accessToken && this.accessExpiresAt > this.now() + 5e3) return;
|
|
251
|
+
if (!input.selectAccount && this.accessToken && this.accessExpiresAt > this.now() + 5e3) return;
|
|
252
252
|
const verifier = b64url((this.deps.randomBytes ?? random)(32));
|
|
253
253
|
const state = b64url((this.deps.randomBytes ?? random)(24));
|
|
254
254
|
const digest = this.deps.digest ?? (async (value) => new Uint8Array(await crypto.subtle.digest("SHA-256", value)));
|
|
@@ -266,7 +266,7 @@ var ToTopPlatformSDK = (() => {
|
|
|
266
266
|
url = new URL("/oauth/authorize", config.issuer);
|
|
267
267
|
url.search = new URLSearchParams({ client_id: config.clientId, response_type: "code", redirect_uri: config.redirectUri, scope: config.scopes.join(" "), resource: this.resource(), state, code_challenge: challenge, code_challenge_method: "S256" }).toString();
|
|
268
268
|
}
|
|
269
|
-
;
|
|
269
|
+
if (input.selectAccount) url.searchParams.set("prompt", "select_account");
|
|
270
270
|
(this.deps.navigate ?? ((target) => location.assign(target)))(url.href);
|
|
271
271
|
}
|
|
272
272
|
getUser() {
|
|
@@ -368,8 +368,7 @@ var ToTopPlatformSDK = (() => {
|
|
|
368
368
|
if (this.refreshFlight) return this.refreshFlight;
|
|
369
369
|
const config = this.requireConfig();
|
|
370
370
|
const token = this.deps.storage.getItem(this.key("refresh"));
|
|
371
|
-
|
|
372
|
-
if (!token || familyExpires <= this.now()) {
|
|
371
|
+
if (!token) {
|
|
373
372
|
this.clearState();
|
|
374
373
|
throw new Error("login required");
|
|
375
374
|
}
|
|
@@ -412,7 +411,6 @@ var ToTopPlatformSDK = (() => {
|
|
|
412
411
|
this.accessToken = result.access_token;
|
|
413
412
|
this.accessExpiresAt = this.now() + result.expires_in * 1e3;
|
|
414
413
|
this.deps.storage.setItem(this.key("refresh"), result.refresh_token);
|
|
415
|
-
if (!this.deps.storage.getItem(this.key("family_expires"))) this.deps.storage.setItem(this.key("family_expires"), String(this.now() + 8 * 60 * 60 * 1e3));
|
|
416
414
|
} finally {
|
|
417
415
|
this.controllers.delete(controller);
|
|
418
416
|
}
|
|
@@ -437,8 +435,8 @@ var ToTopPlatformSDK = (() => {
|
|
|
437
435
|
return ToTop;
|
|
438
436
|
},
|
|
439
437
|
handleCallback: () => browserClient().handleCallback(),
|
|
440
|
-
login: () => browserClient().login(),
|
|
441
|
-
requireLogin: () => browserClient().requireLogin(),
|
|
438
|
+
login: (input) => browserClient().login(input),
|
|
439
|
+
requireLogin: (input) => browserClient().requireLogin(input),
|
|
442
440
|
getUser: () => browserClient().getUser(),
|
|
443
441
|
getAccessToken: () => browserClient().getAccessToken(),
|
|
444
442
|
authorizedFetch: (input, init) => browserClient().authorizedFetch(input, init),
|