@legendsoflearning/lol-sdk-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.d.mts +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +12 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/index.mjs +3 -0
- package/dist/auth/index.mjs.map +1 -0
- package/dist/cache/index.d.mts +26 -0
- package/dist/cache/index.d.ts +26 -0
- package/dist/cache/index.js +63 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/index.mjs +60 -0
- package/dist/cache/index.mjs.map +1 -0
- package/dist/chunk-Q4UXELOU.mjs +284 -0
- package/dist/chunk-Q4UXELOU.mjs.map +1 -0
- package/dist/chunk-WWN77BBN.js +286 -0
- package/dist/chunk-WWN77BBN.js.map +1 -0
- package/dist/generated/admins/index.d.mts +2566 -0
- package/dist/generated/admins/index.d.ts +2566 -0
- package/dist/generated/admins/index.js +110 -0
- package/dist/generated/admins/index.js.map +1 -0
- package/dist/generated/admins/index.mjs +97 -0
- package/dist/generated/admins/index.mjs.map +1 -0
- package/dist/generated/developers/index.d.mts +330 -0
- package/dist/generated/developers/index.d.ts +330 -0
- package/dist/generated/developers/index.js +30 -0
- package/dist/generated/developers/index.js.map +1 -0
- package/dist/generated/developers/index.mjs +25 -0
- package/dist/generated/developers/index.mjs.map +1 -0
- package/dist/generated/parents/index.d.mts +1097 -0
- package/dist/generated/parents/index.d.ts +1097 -0
- package/dist/generated/parents/index.js +112 -0
- package/dist/generated/parents/index.js.map +1 -0
- package/dist/generated/parents/index.mjs +99 -0
- package/dist/generated/parents/index.mjs.map +1 -0
- package/dist/generated/play/index.d.mts +1060 -0
- package/dist/generated/play/index.d.ts +1060 -0
- package/dist/generated/play/index.js +109 -0
- package/dist/generated/play/index.js.map +1 -0
- package/dist/generated/play/index.mjs +96 -0
- package/dist/generated/play/index.mjs.map +1 -0
- package/dist/generated/public/index.d.mts +791 -0
- package/dist/generated/public/index.d.ts +791 -0
- package/dist/generated/public/index.js +39 -0
- package/dist/generated/public/index.js.map +1 -0
- package/dist/generated/public/index.mjs +33 -0
- package/dist/generated/public/index.mjs.map +1 -0
- package/dist/generated/teachers/index.d.mts +6205 -0
- package/dist/generated/teachers/index.d.ts +6205 -0
- package/dist/generated/teachers/index.js +353 -0
- package/dist/generated/teachers/index.js.map +1 -0
- package/dist/generated/teachers/index.mjs +282 -0
- package/dist/generated/teachers/index.mjs.map +1 -0
- package/dist/index-vM3xPKfV.d.mts +173 -0
- package/dist/index-vM3xPKfV.d.ts +173 -0
- package/dist/index.d.mts +154 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +352 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +336 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API endpoint definitions for Legends of Learning backend.
|
|
3
|
+
*/
|
|
4
|
+
type ApiType = 'teachers' | 'parents' | 'play' | 'public' | 'developers' | 'admin';
|
|
5
|
+
interface ApiEndpoint {
|
|
6
|
+
graphql: string;
|
|
7
|
+
websocket?: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
declare const API_ENDPOINTS: Record<ApiType, ApiEndpoint>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Core type definitions for the Legends SDK.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface QueryOptions<TVariables = Record<string, unknown>> {
|
|
17
|
+
variables?: TVariables;
|
|
18
|
+
fetchPolicy?: 'cache-first' | 'network-only' | 'cache-only' | 'no-cache';
|
|
19
|
+
errorPolicy?: 'none' | 'ignore' | 'all';
|
|
20
|
+
}
|
|
21
|
+
interface QueryResult<TData> {
|
|
22
|
+
data: TData;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
error?: Error;
|
|
25
|
+
networkStatus: number;
|
|
26
|
+
}
|
|
27
|
+
interface MutationOptions<TVariables = Record<string, unknown>> {
|
|
28
|
+
variables?: TVariables;
|
|
29
|
+
optimisticResponse?: unknown;
|
|
30
|
+
refetchQueries?: string[];
|
|
31
|
+
awaitRefetchQueries?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface MutationResult<TData> {
|
|
34
|
+
data?: TData;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error?: Error;
|
|
37
|
+
called: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface SubscriptionOptions<TVariables = Record<string, unknown>> {
|
|
40
|
+
variables?: TVariables;
|
|
41
|
+
shouldResubscribe?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface Session {
|
|
44
|
+
user: {
|
|
45
|
+
id: string;
|
|
46
|
+
email?: string;
|
|
47
|
+
firstName?: string;
|
|
48
|
+
lastName?: string;
|
|
49
|
+
role?: string;
|
|
50
|
+
};
|
|
51
|
+
token?: string;
|
|
52
|
+
expiresAt: Date;
|
|
53
|
+
}
|
|
54
|
+
interface Credentials {
|
|
55
|
+
email: string;
|
|
56
|
+
password: string;
|
|
57
|
+
rememberMe?: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface SignUpInput {
|
|
60
|
+
email: string;
|
|
61
|
+
password: string;
|
|
62
|
+
firstName: string;
|
|
63
|
+
lastName: string;
|
|
64
|
+
agreedToTerms?: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface AuthResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
session?: Session;
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
type OAuthProvider = 'google' | 'clever' | 'canvas' | 'classlink';
|
|
72
|
+
type Unsubscribe = () => void;
|
|
73
|
+
type AuthCallback = (session: Session | null) => void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Authentication module for the Legends SDK.
|
|
77
|
+
*
|
|
78
|
+
* Supports two auth modes:
|
|
79
|
+
* - 'cookie' (default): Uses session cookies, best for same-domain apps
|
|
80
|
+
* - 'token': Uses X-Session-Token header, works cross-domain
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
type AuthMode = 'cookie' | 'token';
|
|
84
|
+
interface AuthConfig {
|
|
85
|
+
/**
|
|
86
|
+
* Authentication mode.
|
|
87
|
+
* - 'cookie': Uses session cookies (same-domain only)
|
|
88
|
+
* - 'token': Uses X-Session-Token header (cross-domain)
|
|
89
|
+
* @default 'cookie'
|
|
90
|
+
*/
|
|
91
|
+
mode?: AuthMode;
|
|
92
|
+
/**
|
|
93
|
+
* Storage mechanism for session data.
|
|
94
|
+
* @default 'localStorage'
|
|
95
|
+
*/
|
|
96
|
+
storage?: 'localStorage' | 'sessionStorage' | 'memory' | Storage;
|
|
97
|
+
/**
|
|
98
|
+
* Auto-refresh tokens before expiry.
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
autoRefresh?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Callback when auth state changes.
|
|
104
|
+
*/
|
|
105
|
+
onAuthChange?: AuthCallback;
|
|
106
|
+
/**
|
|
107
|
+
* Client ID for OAuth flows (for registered third-party apps).
|
|
108
|
+
*/
|
|
109
|
+
clientId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Redirect URI for OAuth flows.
|
|
112
|
+
* @default window.location.origin + '/auth/callback'
|
|
113
|
+
*/
|
|
114
|
+
redirectUri?: string;
|
|
115
|
+
}
|
|
116
|
+
interface Auth {
|
|
117
|
+
/**
|
|
118
|
+
* Sign in with email and password.
|
|
119
|
+
*/
|
|
120
|
+
signIn(credentials: Credentials): Promise<AuthResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Sign up with email, password, and profile info.
|
|
123
|
+
*/
|
|
124
|
+
signUp(input: SignUpInput): Promise<AuthResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Sign in with OAuth provider.
|
|
127
|
+
* For third-party apps, this initiates the OAuth authorization flow.
|
|
128
|
+
*/
|
|
129
|
+
signInWithOAuth(provider: OAuthProvider): Promise<AuthResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Handle OAuth callback (for third-party apps).
|
|
132
|
+
* Call this on your redirect_uri page to complete the OAuth flow.
|
|
133
|
+
*/
|
|
134
|
+
handleOAuthCallback(params: {
|
|
135
|
+
code?: string;
|
|
136
|
+
error?: string;
|
|
137
|
+
}): Promise<AuthResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Sign out and clear session.
|
|
140
|
+
*/
|
|
141
|
+
signOut(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the current session.
|
|
144
|
+
*/
|
|
145
|
+
getSession(): Session | null;
|
|
146
|
+
/**
|
|
147
|
+
* Get auth headers for API requests (token mode only).
|
|
148
|
+
* Returns headers object with X-Session-Token if authenticated.
|
|
149
|
+
*/
|
|
150
|
+
getAuthHeaders(): Record<string, string>;
|
|
151
|
+
/**
|
|
152
|
+
* Get the current auth mode.
|
|
153
|
+
*/
|
|
154
|
+
getMode(): AuthMode;
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to auth state changes.
|
|
157
|
+
*/
|
|
158
|
+
onAuthChange(callback: AuthCallback): Unsubscribe;
|
|
159
|
+
/**
|
|
160
|
+
* Refresh the current token.
|
|
161
|
+
*/
|
|
162
|
+
refreshToken(): Promise<Session | null>;
|
|
163
|
+
/**
|
|
164
|
+
* @internal Handle auth errors from the API.
|
|
165
|
+
*/
|
|
166
|
+
_handleAuthError(): void;
|
|
167
|
+
}
|
|
168
|
+
declare function createAuth(config: AuthConfig & {
|
|
169
|
+
api: ApiType;
|
|
170
|
+
baseUrl: string;
|
|
171
|
+
}): Auth;
|
|
172
|
+
|
|
173
|
+
export { type ApiType as A, type Credentials as C, type MutationOptions as M, type OAuthProvider as O, type QueryOptions as Q, type SubscriptionOptions as S, type AuthConfig as a, type QueryResult as b, type MutationResult as c, type Auth as d, type ApiEndpoint as e, API_ENDPOINTS as f, type AuthMode as g, type Session as h, type SignUpInput as i, type AuthResult as j, createAuth as k };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API endpoint definitions for Legends of Learning backend.
|
|
3
|
+
*/
|
|
4
|
+
type ApiType = 'teachers' | 'parents' | 'play' | 'public' | 'developers' | 'admin';
|
|
5
|
+
interface ApiEndpoint {
|
|
6
|
+
graphql: string;
|
|
7
|
+
websocket?: string;
|
|
8
|
+
description: string;
|
|
9
|
+
}
|
|
10
|
+
declare const API_ENDPOINTS: Record<ApiType, ApiEndpoint>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Core type definitions for the Legends SDK.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
interface QueryOptions<TVariables = Record<string, unknown>> {
|
|
17
|
+
variables?: TVariables;
|
|
18
|
+
fetchPolicy?: 'cache-first' | 'network-only' | 'cache-only' | 'no-cache';
|
|
19
|
+
errorPolicy?: 'none' | 'ignore' | 'all';
|
|
20
|
+
}
|
|
21
|
+
interface QueryResult<TData> {
|
|
22
|
+
data: TData;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
error?: Error;
|
|
25
|
+
networkStatus: number;
|
|
26
|
+
}
|
|
27
|
+
interface MutationOptions<TVariables = Record<string, unknown>> {
|
|
28
|
+
variables?: TVariables;
|
|
29
|
+
optimisticResponse?: unknown;
|
|
30
|
+
refetchQueries?: string[];
|
|
31
|
+
awaitRefetchQueries?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface MutationResult<TData> {
|
|
34
|
+
data?: TData;
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error?: Error;
|
|
37
|
+
called: boolean;
|
|
38
|
+
}
|
|
39
|
+
interface SubscriptionOptions<TVariables = Record<string, unknown>> {
|
|
40
|
+
variables?: TVariables;
|
|
41
|
+
shouldResubscribe?: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface Session {
|
|
44
|
+
user: {
|
|
45
|
+
id: string;
|
|
46
|
+
email?: string;
|
|
47
|
+
firstName?: string;
|
|
48
|
+
lastName?: string;
|
|
49
|
+
role?: string;
|
|
50
|
+
};
|
|
51
|
+
token?: string;
|
|
52
|
+
expiresAt: Date;
|
|
53
|
+
}
|
|
54
|
+
interface Credentials {
|
|
55
|
+
email: string;
|
|
56
|
+
password: string;
|
|
57
|
+
rememberMe?: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface SignUpInput {
|
|
60
|
+
email: string;
|
|
61
|
+
password: string;
|
|
62
|
+
firstName: string;
|
|
63
|
+
lastName: string;
|
|
64
|
+
agreedToTerms?: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface AuthResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
session?: Session;
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
type OAuthProvider = 'google' | 'clever' | 'canvas' | 'classlink';
|
|
72
|
+
type Unsubscribe = () => void;
|
|
73
|
+
type AuthCallback = (session: Session | null) => void;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Authentication module for the Legends SDK.
|
|
77
|
+
*
|
|
78
|
+
* Supports two auth modes:
|
|
79
|
+
* - 'cookie' (default): Uses session cookies, best for same-domain apps
|
|
80
|
+
* - 'token': Uses X-Session-Token header, works cross-domain
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
type AuthMode = 'cookie' | 'token';
|
|
84
|
+
interface AuthConfig {
|
|
85
|
+
/**
|
|
86
|
+
* Authentication mode.
|
|
87
|
+
* - 'cookie': Uses session cookies (same-domain only)
|
|
88
|
+
* - 'token': Uses X-Session-Token header (cross-domain)
|
|
89
|
+
* @default 'cookie'
|
|
90
|
+
*/
|
|
91
|
+
mode?: AuthMode;
|
|
92
|
+
/**
|
|
93
|
+
* Storage mechanism for session data.
|
|
94
|
+
* @default 'localStorage'
|
|
95
|
+
*/
|
|
96
|
+
storage?: 'localStorage' | 'sessionStorage' | 'memory' | Storage;
|
|
97
|
+
/**
|
|
98
|
+
* Auto-refresh tokens before expiry.
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
autoRefresh?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Callback when auth state changes.
|
|
104
|
+
*/
|
|
105
|
+
onAuthChange?: AuthCallback;
|
|
106
|
+
/**
|
|
107
|
+
* Client ID for OAuth flows (for registered third-party apps).
|
|
108
|
+
*/
|
|
109
|
+
clientId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Redirect URI for OAuth flows.
|
|
112
|
+
* @default window.location.origin + '/auth/callback'
|
|
113
|
+
*/
|
|
114
|
+
redirectUri?: string;
|
|
115
|
+
}
|
|
116
|
+
interface Auth {
|
|
117
|
+
/**
|
|
118
|
+
* Sign in with email and password.
|
|
119
|
+
*/
|
|
120
|
+
signIn(credentials: Credentials): Promise<AuthResult>;
|
|
121
|
+
/**
|
|
122
|
+
* Sign up with email, password, and profile info.
|
|
123
|
+
*/
|
|
124
|
+
signUp(input: SignUpInput): Promise<AuthResult>;
|
|
125
|
+
/**
|
|
126
|
+
* Sign in with OAuth provider.
|
|
127
|
+
* For third-party apps, this initiates the OAuth authorization flow.
|
|
128
|
+
*/
|
|
129
|
+
signInWithOAuth(provider: OAuthProvider): Promise<AuthResult>;
|
|
130
|
+
/**
|
|
131
|
+
* Handle OAuth callback (for third-party apps).
|
|
132
|
+
* Call this on your redirect_uri page to complete the OAuth flow.
|
|
133
|
+
*/
|
|
134
|
+
handleOAuthCallback(params: {
|
|
135
|
+
code?: string;
|
|
136
|
+
error?: string;
|
|
137
|
+
}): Promise<AuthResult>;
|
|
138
|
+
/**
|
|
139
|
+
* Sign out and clear session.
|
|
140
|
+
*/
|
|
141
|
+
signOut(): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Get the current session.
|
|
144
|
+
*/
|
|
145
|
+
getSession(): Session | null;
|
|
146
|
+
/**
|
|
147
|
+
* Get auth headers for API requests (token mode only).
|
|
148
|
+
* Returns headers object with X-Session-Token if authenticated.
|
|
149
|
+
*/
|
|
150
|
+
getAuthHeaders(): Record<string, string>;
|
|
151
|
+
/**
|
|
152
|
+
* Get the current auth mode.
|
|
153
|
+
*/
|
|
154
|
+
getMode(): AuthMode;
|
|
155
|
+
/**
|
|
156
|
+
* Subscribe to auth state changes.
|
|
157
|
+
*/
|
|
158
|
+
onAuthChange(callback: AuthCallback): Unsubscribe;
|
|
159
|
+
/**
|
|
160
|
+
* Refresh the current token.
|
|
161
|
+
*/
|
|
162
|
+
refreshToken(): Promise<Session | null>;
|
|
163
|
+
/**
|
|
164
|
+
* @internal Handle auth errors from the API.
|
|
165
|
+
*/
|
|
166
|
+
_handleAuthError(): void;
|
|
167
|
+
}
|
|
168
|
+
declare function createAuth(config: AuthConfig & {
|
|
169
|
+
api: ApiType;
|
|
170
|
+
baseUrl: string;
|
|
171
|
+
}): Auth;
|
|
172
|
+
|
|
173
|
+
export { type ApiType as A, type Credentials as C, type MutationOptions as M, type OAuthProvider as O, type QueryOptions as Q, type SubscriptionOptions as S, type AuthConfig as a, type QueryResult as b, type MutationResult as c, type Auth as d, type ApiEndpoint as e, API_ENDPOINTS as f, type AuthMode as g, type Session as h, type SignUpInput as i, type AuthResult as j, createAuth as k };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { InMemoryCacheConfig, TypedDocumentNode, NormalizedCacheObject, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { A as ApiType, a as AuthConfig, Q as QueryOptions, b as QueryResult, M as MutationOptions, c as MutationResult, d as Auth } from './index-vM3xPKfV.mjs';
|
|
3
|
+
export { f as API_ENDPOINTS, e as ApiEndpoint, g as AuthMode, j as AuthResult, C as Credentials, O as OAuthProvider, h as Session, i as SignUpInput, S as SubscriptionOptions } from './index-vM3xPKfV.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Logging utilities for the Legends SDK.
|
|
7
|
+
*/
|
|
8
|
+
declare enum LogLevel {
|
|
9
|
+
DEBUG = 0,
|
|
10
|
+
INFO = 1,
|
|
11
|
+
WARN = 2,
|
|
12
|
+
ERROR = 3,
|
|
13
|
+
NONE = 4
|
|
14
|
+
}
|
|
15
|
+
interface Logger {
|
|
16
|
+
debug(message: string, data?: unknown): void;
|
|
17
|
+
info(message: string, data?: unknown): void;
|
|
18
|
+
warn(message: string, data?: unknown): void;
|
|
19
|
+
error(message: string, data?: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
interface LoggerConfig {
|
|
22
|
+
level: LogLevel;
|
|
23
|
+
prefix?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function createLogger(config?: Partial<LoggerConfig>): Logger;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Main client implementation for the Legends SDK.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface LolClientConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Which API to connect to.
|
|
34
|
+
*/
|
|
35
|
+
api: ApiType;
|
|
36
|
+
/**
|
|
37
|
+
* Base URL for the API. Defaults to production.
|
|
38
|
+
*/
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* OAuth client ID for third-party apps.
|
|
42
|
+
*/
|
|
43
|
+
clientId?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Authentication mode: 'cookie' (same-domain) or 'token' (cross-domain).
|
|
46
|
+
*/
|
|
47
|
+
mode?: 'cookie' | 'token';
|
|
48
|
+
/**
|
|
49
|
+
* Authentication configuration.
|
|
50
|
+
*/
|
|
51
|
+
auth?: AuthConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Apollo cache configuration.
|
|
54
|
+
*/
|
|
55
|
+
cache?: InMemoryCacheConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Global error handler.
|
|
58
|
+
*/
|
|
59
|
+
onError?: (error: Error) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Enable debug logging.
|
|
62
|
+
*/
|
|
63
|
+
debug?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Log level.
|
|
66
|
+
*/
|
|
67
|
+
logLevel?: LogLevel;
|
|
68
|
+
/**
|
|
69
|
+
* Custom logger implementation.
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* Enable SSR mode.
|
|
74
|
+
*/
|
|
75
|
+
ssr?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Cookies for SSR (from request).
|
|
78
|
+
*/
|
|
79
|
+
cookie?: string;
|
|
80
|
+
}
|
|
81
|
+
interface LolClient<_TApi extends ApiType = ApiType> {
|
|
82
|
+
/**
|
|
83
|
+
* Execute a GraphQL query.
|
|
84
|
+
*/
|
|
85
|
+
query<TData, TVariables extends Record<string, unknown>>(document: TypedDocumentNode<TData, TVariables>, options?: QueryOptions<TVariables>): Promise<QueryResult<TData>>;
|
|
86
|
+
/**
|
|
87
|
+
* Execute a GraphQL mutation.
|
|
88
|
+
*/
|
|
89
|
+
mutate<TData, TVariables extends Record<string, unknown>>(document: TypedDocumentNode<TData, TVariables>, options?: MutationOptions<TVariables>): Promise<MutationResult<TData>>;
|
|
90
|
+
/**
|
|
91
|
+
* Authentication module.
|
|
92
|
+
*/
|
|
93
|
+
auth: Auth;
|
|
94
|
+
/**
|
|
95
|
+
* Cache operations.
|
|
96
|
+
*/
|
|
97
|
+
cache: {
|
|
98
|
+
read<TData>(document: TypedDocumentNode<TData, Record<string, unknown>>): TData | null;
|
|
99
|
+
write<TData>(document: TypedDocumentNode<TData, Record<string, unknown>>, data: TData): void;
|
|
100
|
+
evict(id: string): boolean;
|
|
101
|
+
reset(): Promise<void>;
|
|
102
|
+
clear(): Promise<void>;
|
|
103
|
+
extract(): NormalizedCacheObject;
|
|
104
|
+
restore(data: NormalizedCacheObject): void;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Get the underlying Apollo client.
|
|
108
|
+
*/
|
|
109
|
+
getApolloClient(): ApolloClient<NormalizedCacheObject>;
|
|
110
|
+
}
|
|
111
|
+
declare function createClient<TApi extends ApiType>(config: LolClientConfig & {
|
|
112
|
+
api: TApi;
|
|
113
|
+
}): LolClient<TApi>;
|
|
114
|
+
declare const APOLLO_STATE_PROP_NAME = "__APOLLO_STATE__";
|
|
115
|
+
declare function addApolloState<P extends Record<string, unknown>>(client: LolClient, pageProps: {
|
|
116
|
+
props: P;
|
|
117
|
+
}): {
|
|
118
|
+
props: P & {
|
|
119
|
+
[APOLLO_STATE_PROP_NAME]: NormalizedCacheObject;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
declare function initializeClientWithState<TApi extends ApiType>(config: LolClientConfig & {
|
|
123
|
+
api: TApi;
|
|
124
|
+
}, initialState?: NormalizedCacheObject): LolClient<TApi>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Error types for the Legends SDK.
|
|
128
|
+
*/
|
|
129
|
+
type ErrorCode = 'NOT_AUTHENTICATED' | 'NOT_AUTHORIZED' | 'NOT_FOUND' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'RATE_LIMITED' | 'SERVER_ERROR' | 'UNKNOWN';
|
|
130
|
+
declare class LolError extends Error {
|
|
131
|
+
readonly code: ErrorCode;
|
|
132
|
+
readonly details?: Record<string, unknown>;
|
|
133
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
134
|
+
}
|
|
135
|
+
declare class AuthError extends LolError {
|
|
136
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
137
|
+
}
|
|
138
|
+
declare class NetworkError extends LolError {
|
|
139
|
+
readonly statusCode?: number;
|
|
140
|
+
constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
|
|
141
|
+
}
|
|
142
|
+
declare class GraphQLError extends LolError {
|
|
143
|
+
readonly locations?: Array<{
|
|
144
|
+
line: number;
|
|
145
|
+
column: number;
|
|
146
|
+
}>;
|
|
147
|
+
readonly path?: string[];
|
|
148
|
+
constructor(message: string, code: ErrorCode, locations?: Array<{
|
|
149
|
+
line: number;
|
|
150
|
+
column: number;
|
|
151
|
+
}>, path?: string[], details?: Record<string, unknown>);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { APOLLO_STATE_PROP_NAME, ApiType, Auth, AuthConfig, AuthError, type ErrorCode, GraphQLError, LogLevel, type Logger, type LolClient, type LolClientConfig, LolError, MutationOptions, MutationResult, NetworkError, QueryOptions, QueryResult, addApolloState, createClient, createLogger, initializeClientWithState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { InMemoryCacheConfig, TypedDocumentNode, NormalizedCacheObject, ApolloClient } from '@apollo/client';
|
|
2
|
+
import { A as ApiType, a as AuthConfig, Q as QueryOptions, b as QueryResult, M as MutationOptions, c as MutationResult, d as Auth } from './index-vM3xPKfV.js';
|
|
3
|
+
export { f as API_ENDPOINTS, e as ApiEndpoint, g as AuthMode, j as AuthResult, C as Credentials, O as OAuthProvider, h as Session, i as SignUpInput, S as SubscriptionOptions } from './index-vM3xPKfV.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Logging utilities for the Legends SDK.
|
|
7
|
+
*/
|
|
8
|
+
declare enum LogLevel {
|
|
9
|
+
DEBUG = 0,
|
|
10
|
+
INFO = 1,
|
|
11
|
+
WARN = 2,
|
|
12
|
+
ERROR = 3,
|
|
13
|
+
NONE = 4
|
|
14
|
+
}
|
|
15
|
+
interface Logger {
|
|
16
|
+
debug(message: string, data?: unknown): void;
|
|
17
|
+
info(message: string, data?: unknown): void;
|
|
18
|
+
warn(message: string, data?: unknown): void;
|
|
19
|
+
error(message: string, data?: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
interface LoggerConfig {
|
|
22
|
+
level: LogLevel;
|
|
23
|
+
prefix?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function createLogger(config?: Partial<LoggerConfig>): Logger;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Main client implementation for the Legends SDK.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
interface LolClientConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Which API to connect to.
|
|
34
|
+
*/
|
|
35
|
+
api: ApiType;
|
|
36
|
+
/**
|
|
37
|
+
* Base URL for the API. Defaults to production.
|
|
38
|
+
*/
|
|
39
|
+
baseUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* OAuth client ID for third-party apps.
|
|
42
|
+
*/
|
|
43
|
+
clientId?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Authentication mode: 'cookie' (same-domain) or 'token' (cross-domain).
|
|
46
|
+
*/
|
|
47
|
+
mode?: 'cookie' | 'token';
|
|
48
|
+
/**
|
|
49
|
+
* Authentication configuration.
|
|
50
|
+
*/
|
|
51
|
+
auth?: AuthConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Apollo cache configuration.
|
|
54
|
+
*/
|
|
55
|
+
cache?: InMemoryCacheConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Global error handler.
|
|
58
|
+
*/
|
|
59
|
+
onError?: (error: Error) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Enable debug logging.
|
|
62
|
+
*/
|
|
63
|
+
debug?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Log level.
|
|
66
|
+
*/
|
|
67
|
+
logLevel?: LogLevel;
|
|
68
|
+
/**
|
|
69
|
+
* Custom logger implementation.
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* Enable SSR mode.
|
|
74
|
+
*/
|
|
75
|
+
ssr?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Cookies for SSR (from request).
|
|
78
|
+
*/
|
|
79
|
+
cookie?: string;
|
|
80
|
+
}
|
|
81
|
+
interface LolClient<_TApi extends ApiType = ApiType> {
|
|
82
|
+
/**
|
|
83
|
+
* Execute a GraphQL query.
|
|
84
|
+
*/
|
|
85
|
+
query<TData, TVariables extends Record<string, unknown>>(document: TypedDocumentNode<TData, TVariables>, options?: QueryOptions<TVariables>): Promise<QueryResult<TData>>;
|
|
86
|
+
/**
|
|
87
|
+
* Execute a GraphQL mutation.
|
|
88
|
+
*/
|
|
89
|
+
mutate<TData, TVariables extends Record<string, unknown>>(document: TypedDocumentNode<TData, TVariables>, options?: MutationOptions<TVariables>): Promise<MutationResult<TData>>;
|
|
90
|
+
/**
|
|
91
|
+
* Authentication module.
|
|
92
|
+
*/
|
|
93
|
+
auth: Auth;
|
|
94
|
+
/**
|
|
95
|
+
* Cache operations.
|
|
96
|
+
*/
|
|
97
|
+
cache: {
|
|
98
|
+
read<TData>(document: TypedDocumentNode<TData, Record<string, unknown>>): TData | null;
|
|
99
|
+
write<TData>(document: TypedDocumentNode<TData, Record<string, unknown>>, data: TData): void;
|
|
100
|
+
evict(id: string): boolean;
|
|
101
|
+
reset(): Promise<void>;
|
|
102
|
+
clear(): Promise<void>;
|
|
103
|
+
extract(): NormalizedCacheObject;
|
|
104
|
+
restore(data: NormalizedCacheObject): void;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Get the underlying Apollo client.
|
|
108
|
+
*/
|
|
109
|
+
getApolloClient(): ApolloClient<NormalizedCacheObject>;
|
|
110
|
+
}
|
|
111
|
+
declare function createClient<TApi extends ApiType>(config: LolClientConfig & {
|
|
112
|
+
api: TApi;
|
|
113
|
+
}): LolClient<TApi>;
|
|
114
|
+
declare const APOLLO_STATE_PROP_NAME = "__APOLLO_STATE__";
|
|
115
|
+
declare function addApolloState<P extends Record<string, unknown>>(client: LolClient, pageProps: {
|
|
116
|
+
props: P;
|
|
117
|
+
}): {
|
|
118
|
+
props: P & {
|
|
119
|
+
[APOLLO_STATE_PROP_NAME]: NormalizedCacheObject;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
declare function initializeClientWithState<TApi extends ApiType>(config: LolClientConfig & {
|
|
123
|
+
api: TApi;
|
|
124
|
+
}, initialState?: NormalizedCacheObject): LolClient<TApi>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Error types for the Legends SDK.
|
|
128
|
+
*/
|
|
129
|
+
type ErrorCode = 'NOT_AUTHENTICATED' | 'NOT_AUTHORIZED' | 'NOT_FOUND' | 'VALIDATION_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'RATE_LIMITED' | 'SERVER_ERROR' | 'UNKNOWN';
|
|
130
|
+
declare class LolError extends Error {
|
|
131
|
+
readonly code: ErrorCode;
|
|
132
|
+
readonly details?: Record<string, unknown>;
|
|
133
|
+
constructor(message: string, code?: ErrorCode, details?: Record<string, unknown>);
|
|
134
|
+
}
|
|
135
|
+
declare class AuthError extends LolError {
|
|
136
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
137
|
+
}
|
|
138
|
+
declare class NetworkError extends LolError {
|
|
139
|
+
readonly statusCode?: number;
|
|
140
|
+
constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
|
|
141
|
+
}
|
|
142
|
+
declare class GraphQLError extends LolError {
|
|
143
|
+
readonly locations?: Array<{
|
|
144
|
+
line: number;
|
|
145
|
+
column: number;
|
|
146
|
+
}>;
|
|
147
|
+
readonly path?: string[];
|
|
148
|
+
constructor(message: string, code: ErrorCode, locations?: Array<{
|
|
149
|
+
line: number;
|
|
150
|
+
column: number;
|
|
151
|
+
}>, path?: string[], details?: Record<string, unknown>);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export { APOLLO_STATE_PROP_NAME, ApiType, Auth, AuthConfig, AuthError, type ErrorCode, GraphQLError, LogLevel, type Logger, type LolClient, type LolClientConfig, LolError, MutationOptions, MutationResult, NetworkError, QueryOptions, QueryResult, addApolloState, createClient, createLogger, initializeClientWithState };
|