@defold-typescript/library-types 0.24.0 → 0.26.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.
@@ -0,0 +1,95 @@
1
+ /** @noSelfInFile **/
2
+
3
+ /**
4
+ * @see {@link https://github.com/heroiclabs/nakama-defold|Github Source}
5
+ * @noResolution
6
+ */
7
+ declare module 'nakama.session' {
8
+ /**
9
+ * A session built from an authentication response. `create` fills the refresh half
10
+ * only when the response carried a refresh token, and `vars` only when the access
11
+ * token carried a `vrs` claim, so those six are absent as often as they are present.
12
+ */
13
+ interface Session {
14
+ /** When `create` built this session, from `os.time()`. */
15
+ created: number;
16
+ /** The access token the server issued, as the JWT string it arrived as. */
17
+ token: string;
18
+ /** The access token's `exp` claim, in seconds since the epoch. */
19
+ expires: number;
20
+ /** The username the access token's `usn` claim carries. */
21
+ username: string;
22
+ /** The user id the access token's `uid` claim carries. */
23
+ user_id: string;
24
+ /** The session variables the access token's `vrs` claim carries, if any. */
25
+ vars?: unknown;
26
+ /** The refresh token the server issued, if the response carried one. */
27
+ refresh_token?: string;
28
+ /** The refresh token's `exp` claim, in seconds since the epoch. */
29
+ refresh_token_expires?: number;
30
+ /** The username the refresh token's `usn` claim carries. */
31
+ refresh_token_username?: string;
32
+ /** The user id the refresh token's `uid` claim carries. */
33
+ refresh_token_user_id?: string;
34
+ /** The session variables the refresh token's `vrs` claim carries. */
35
+ refresh_token_vars?: unknown;
36
+ }
37
+
38
+ /**
39
+ * The authentication response `create` reads. Only `token` is required; the refresh
40
+ * token is decoded when present, and every other key of the response is ignored.
41
+ */
42
+ interface SessionData {
43
+ token: string;
44
+ refresh_token?: string;
45
+ }
46
+
47
+ /**
48
+ * Whether the session's access token expires within the next twenty-four hours.
49
+ * Refresh the session while this is true rather than waiting for it to expire.
50
+ * @param session A session created with `create`.
51
+ */
52
+ function is_token_expired_soon(session: Session): boolean;
53
+
54
+ /**
55
+ * Whether the session's access token has already expired.
56
+ * @param session A session created with `create`.
57
+ */
58
+ function is_token_expired(session: Session): boolean;
59
+
60
+ /**
61
+ * Upstream's backwards-compatible alias of `is_token_expired`, kept because older
62
+ * code calls it. New code should call `is_token_expired`.
63
+ * @param session A session created with `create`.
64
+ */
65
+ function expired(session: Session): boolean;
66
+
67
+ /**
68
+ * Whether the session's refresh token has expired. A session created without a
69
+ * refresh token counts as expired, there being nothing left to refresh with.
70
+ * @param session A session created with `create`.
71
+ */
72
+ function is_refresh_token_expired(session: Session): boolean;
73
+
74
+ /**
75
+ * Builds a session from an authentication response, decoding the tokens it carries
76
+ * to read their expiry, username, user id and session variables.
77
+ * @param data The authentication response, which must carry a `token`.
78
+ */
79
+ function create(data: SessionData): Session;
80
+
81
+ /**
82
+ * Writes a session to disk under the project title, so it survives a restart.
83
+ * @param session The session to store.
84
+ * @param id Names the saved session. Defaults to `nakama`.
85
+ * @returns Whether the save succeeded.
86
+ */
87
+ function store(session: Session, id?: string): boolean;
88
+
89
+ /**
90
+ * Reads back a session written by `store`.
91
+ * @param id The name the session was stored under. Defaults to `nakama`.
92
+ * @returns The stored session, or `nil` if nothing usable was stored under that name.
93
+ */
94
+ function restore(id?: string): Session | undefined;
95
+ }