@accelbyte/sdk 0.0.0-dev-20240828055251 → 0.0.0-dev-20240904033042
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/cjs/node/index.cjs +162 -61
- package/dist/cjs/node/index.cjs.map +1 -1
- package/dist/es/browser/index.browser.js +156 -60
- package/dist/es/browser/index.browser.js.map +1 -1
- package/dist/es/node/index.node.js +157 -60
- package/dist/es/node/index.node.js.map +1 -1
- package/dist/index.d.ts +130 -49
- package/package.json +20 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse, AxiosInstance, AxiosError } from 'axios';
|
|
2
|
-
import { z, ZodError } from 'zod';
|
|
2
|
+
import { ZodTypeAny, z, ZodError } from 'zod';
|
|
3
3
|
|
|
4
4
|
type MakeOptional<Type, UnionKeys extends keyof Type> = Omit<Type, UnionKeys> & Partial<Pick<Type, UnionKeys>>;
|
|
5
5
|
type MakeRequired<T, K extends keyof T> = T & {
|
|
6
6
|
[P in K]-?: T[P];
|
|
7
|
-
};
|
|
7
|
+
};
|
|
8
|
+
declare function isType<T extends ZodTypeAny>(schema: T, data: unknown): data is z.infer<T>;
|
|
8
9
|
|
|
9
10
|
interface CoreConfig {
|
|
10
11
|
/**
|
|
@@ -56,6 +57,10 @@ interface SdkSetConfigParam {
|
|
|
56
57
|
type ApiError = {
|
|
57
58
|
errorCode: number | string;
|
|
58
59
|
errorMessage: string;
|
|
60
|
+
};
|
|
61
|
+
type TokenConfig = {
|
|
62
|
+
accessToken?: string;
|
|
63
|
+
refreshToken?: string;
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
declare const AccelByte: {
|
|
@@ -65,6 +70,7 @@ declare class AccelByteSDK {
|
|
|
65
70
|
private coreConfig;
|
|
66
71
|
private axiosConfig;
|
|
67
72
|
private axiosInstance;
|
|
73
|
+
private token;
|
|
68
74
|
constructor({ coreConfig, axiosConfig }: SdkConstructorParam);
|
|
69
75
|
assembly(): {
|
|
70
76
|
axiosInstance: AxiosInstance;
|
|
@@ -78,6 +84,9 @@ declare class AccelByteSDK {
|
|
|
78
84
|
removeInterceptors(): AccelByteSDK;
|
|
79
85
|
removeInterceptors(filterCallback: (interceptor: Interceptor) => boolean): AccelByteSDK;
|
|
80
86
|
setConfig({ coreConfig, axiosConfig }: SdkSetConfigParam): this;
|
|
87
|
+
setToken(token: TokenConfig): void;
|
|
88
|
+
removeToken(): void;
|
|
89
|
+
getToken(): TokenConfig;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
declare enum IamErrorCode {
|
|
@@ -105,32 +114,32 @@ declare const ERROR_USER_BANNED = 10134;
|
|
|
105
114
|
|
|
106
115
|
declare const TokenWithDeviceCookieResponseV3: z.ZodObject<{
|
|
107
116
|
access_token: z.ZodString;
|
|
108
|
-
auth_trust_id: z.
|
|
109
|
-
bans: z.
|
|
117
|
+
auth_trust_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
118
|
+
bans: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
110
119
|
ban: z.ZodString;
|
|
111
|
-
disabledDate: z.
|
|
120
|
+
disabledDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
112
121
|
enabled: z.ZodBoolean;
|
|
113
122
|
endDate: z.ZodString;
|
|
114
123
|
targetedNamespace: z.ZodString;
|
|
115
124
|
}, "strip", z.ZodTypeAny, {
|
|
116
|
-
disabledDate?: string | null | undefined;
|
|
117
125
|
ban: string;
|
|
118
126
|
enabled: boolean;
|
|
119
127
|
endDate: string;
|
|
120
128
|
targetedNamespace: string;
|
|
121
|
-
}, {
|
|
122
129
|
disabledDate?: string | null | undefined;
|
|
130
|
+
}, {
|
|
123
131
|
ban: string;
|
|
124
132
|
enabled: boolean;
|
|
125
133
|
endDate: string;
|
|
126
134
|
targetedNamespace: string;
|
|
135
|
+
disabledDate?: string | null | undefined;
|
|
127
136
|
}>, "many">>>;
|
|
128
|
-
display_name: z.
|
|
137
|
+
display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
129
138
|
expires_in: z.ZodNumber;
|
|
130
|
-
is_comply: z.
|
|
131
|
-
jflgs: z.
|
|
139
|
+
is_comply: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
140
|
+
jflgs: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
132
141
|
namespace: z.ZodString;
|
|
133
|
-
namespace_roles: z.
|
|
142
|
+
namespace_roles: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
134
143
|
namespace: z.ZodString;
|
|
135
144
|
roleId: z.ZodString;
|
|
136
145
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -143,42 +152,54 @@ declare const TokenWithDeviceCookieResponseV3: z.ZodObject<{
|
|
|
143
152
|
permissions: z.ZodArray<z.ZodObject<{
|
|
144
153
|
action: z.ZodNumber;
|
|
145
154
|
resource: z.ZodString;
|
|
146
|
-
schedAction: z.
|
|
147
|
-
schedCron: z.
|
|
148
|
-
schedRange: z.
|
|
155
|
+
schedAction: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
156
|
+
schedCron: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
157
|
+
schedRange: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
149
158
|
}, "strip", z.ZodTypeAny, {
|
|
159
|
+
action: number;
|
|
160
|
+
resource: string;
|
|
150
161
|
schedAction?: number | null | undefined;
|
|
151
162
|
schedCron?: string | null | undefined;
|
|
152
163
|
schedRange?: string[] | null | undefined;
|
|
164
|
+
}, {
|
|
153
165
|
action: number;
|
|
154
166
|
resource: string;
|
|
155
|
-
}, {
|
|
156
167
|
schedAction?: number | null | undefined;
|
|
157
168
|
schedCron?: string | null | undefined;
|
|
158
169
|
schedRange?: string[] | null | undefined;
|
|
159
|
-
action: number;
|
|
160
|
-
resource: string;
|
|
161
170
|
}>, "many">;
|
|
162
|
-
platform_id: z.
|
|
163
|
-
platform_user_id: z.
|
|
164
|
-
refresh_expires_in: z.
|
|
165
|
-
refresh_token: z.
|
|
166
|
-
roles: z.
|
|
171
|
+
platform_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
172
|
+
platform_user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
173
|
+
refresh_expires_in: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
174
|
+
refresh_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
175
|
+
roles: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
|
|
167
176
|
scope: z.ZodString;
|
|
168
|
-
simultaneous_platform_id: z.
|
|
169
|
-
simultaneous_platform_user_id: z.
|
|
177
|
+
simultaneous_platform_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
178
|
+
simultaneous_platform_user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
170
179
|
token_type: z.ZodString;
|
|
171
|
-
unique_display_name: z.
|
|
172
|
-
user_id: z.
|
|
173
|
-
xuid: z.
|
|
180
|
+
unique_display_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
181
|
+
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
182
|
+
xuid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
174
183
|
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
namespace: string;
|
|
185
|
+
access_token: string;
|
|
186
|
+
expires_in: number;
|
|
187
|
+
permissions: {
|
|
188
|
+
action: number;
|
|
189
|
+
resource: string;
|
|
190
|
+
schedAction?: number | null | undefined;
|
|
191
|
+
schedCron?: string | null | undefined;
|
|
192
|
+
schedRange?: string[] | null | undefined;
|
|
193
|
+
}[];
|
|
194
|
+
scope: string;
|
|
195
|
+
token_type: string;
|
|
175
196
|
auth_trust_id?: string | null | undefined;
|
|
176
197
|
bans?: {
|
|
177
|
-
disabledDate?: string | null | undefined;
|
|
178
198
|
ban: string;
|
|
179
199
|
enabled: boolean;
|
|
180
200
|
endDate: string;
|
|
181
201
|
targetedNamespace: string;
|
|
202
|
+
disabledDate?: string | null | undefined;
|
|
182
203
|
}[] | null | undefined;
|
|
183
204
|
display_name?: string | null | undefined;
|
|
184
205
|
is_comply?: boolean | null | undefined;
|
|
@@ -197,26 +218,26 @@ declare const TokenWithDeviceCookieResponseV3: z.ZodObject<{
|
|
|
197
218
|
unique_display_name?: string | null | undefined;
|
|
198
219
|
user_id?: string | null | undefined;
|
|
199
220
|
xuid?: string | null | undefined;
|
|
221
|
+
}, {
|
|
200
222
|
namespace: string;
|
|
201
223
|
access_token: string;
|
|
202
224
|
expires_in: number;
|
|
203
225
|
permissions: {
|
|
226
|
+
action: number;
|
|
227
|
+
resource: string;
|
|
204
228
|
schedAction?: number | null | undefined;
|
|
205
229
|
schedCron?: string | null | undefined;
|
|
206
230
|
schedRange?: string[] | null | undefined;
|
|
207
|
-
action: number;
|
|
208
|
-
resource: string;
|
|
209
231
|
}[];
|
|
210
232
|
scope: string;
|
|
211
233
|
token_type: string;
|
|
212
|
-
}, {
|
|
213
234
|
auth_trust_id?: string | null | undefined;
|
|
214
235
|
bans?: {
|
|
215
|
-
disabledDate?: string | null | undefined;
|
|
216
236
|
ban: string;
|
|
217
237
|
enabled: boolean;
|
|
218
238
|
endDate: string;
|
|
219
239
|
targetedNamespace: string;
|
|
240
|
+
disabledDate?: string | null | undefined;
|
|
220
241
|
}[] | null | undefined;
|
|
221
242
|
display_name?: string | null | undefined;
|
|
222
243
|
is_comply?: boolean | null | undefined;
|
|
@@ -235,18 +256,6 @@ declare const TokenWithDeviceCookieResponseV3: z.ZodObject<{
|
|
|
235
256
|
unique_display_name?: string | null | undefined;
|
|
236
257
|
user_id?: string | null | undefined;
|
|
237
258
|
xuid?: string | null | undefined;
|
|
238
|
-
namespace: string;
|
|
239
|
-
access_token: string;
|
|
240
|
-
expires_in: number;
|
|
241
|
-
permissions: {
|
|
242
|
-
schedAction?: number | null | undefined;
|
|
243
|
-
schedCron?: string | null | undefined;
|
|
244
|
-
schedRange?: string[] | null | undefined;
|
|
245
|
-
action: number;
|
|
246
|
-
resource: string;
|
|
247
|
-
}[];
|
|
248
|
-
scope: string;
|
|
249
|
-
token_type: string;
|
|
250
259
|
}>;
|
|
251
260
|
interface TokenWithDeviceCookieResponseV3 extends z.TypeOf<typeof TokenWithDeviceCookieResponseV3> {
|
|
252
261
|
}
|
|
@@ -273,17 +282,89 @@ declare class DecodeError extends Error {
|
|
|
273
282
|
});
|
|
274
283
|
}
|
|
275
284
|
|
|
285
|
+
declare enum GrantTokenUrls {
|
|
286
|
+
GRANT_TOKEN = "/iam/v3/oauth/token",
|
|
287
|
+
GRANT_TOKEN_V4 = "/iam/v4/oauth/token"
|
|
288
|
+
}
|
|
289
|
+
type GrantTokenUrlString = `${GrantTokenUrls}`;
|
|
276
290
|
type RefreshArgs = {
|
|
277
291
|
axiosConfig: AxiosRequestConfig;
|
|
278
292
|
refreshToken?: string;
|
|
279
293
|
clientId: string;
|
|
294
|
+
tokenUrl?: GrantTokenUrlString;
|
|
280
295
|
};
|
|
281
|
-
declare const refreshWithLock: ({ axiosConfig, refreshToken, clientId }: RefreshArgs) => Promise<Partial<TokenWithDeviceCookieResponseV3> | false>;
|
|
282
|
-
declare const doRefreshSession: ({ axiosConfig, clientId, refreshToken }: RefreshArgs) => () => Promise<false | TokenWithDeviceCookieResponseV3>;
|
|
296
|
+
declare const refreshWithLock: ({ axiosConfig, refreshToken, clientId, tokenUrl }: RefreshArgs) => Promise<Partial<TokenWithDeviceCookieResponseV3> | false>;
|
|
297
|
+
declare const doRefreshSession: ({ axiosConfig, clientId, refreshToken, tokenUrl }: RefreshArgs) => () => Promise<false | TokenWithDeviceCookieResponseV3>;
|
|
283
298
|
/**
|
|
284
|
-
*
|
|
299
|
+
* If there's any config change between interceptors,
|
|
300
|
+
* The interceptors should be placed sequentially.
|
|
301
|
+
* For example, if session expired depend on the new config from get-session,
|
|
302
|
+
* the interceptors should placed like this:
|
|
303
|
+
* - refresh-session
|
|
304
|
+
* - get-session
|
|
305
|
+
* - session-expired
|
|
306
|
+
*
|
|
307
|
+
* @see: https://github.com/axios/axios#multiple-interceptors
|
|
285
308
|
*/
|
|
286
|
-
|
|
309
|
+
type RefreshSessioNInterceptorOptions = {
|
|
310
|
+
/**
|
|
311
|
+
* The URL endpoint for obtaining a new token. Defaults to `'/iam/v3/oauth/token'`.
|
|
312
|
+
*/
|
|
313
|
+
tokenUrl?: GrantTokenUrlString;
|
|
314
|
+
};
|
|
315
|
+
declare const createRefreshSessionInterceptor: (options?: RefreshSessioNInterceptorOptions) => Interceptor;
|
|
316
|
+
type GetSessionInterceptorOptions = {
|
|
317
|
+
/**
|
|
318
|
+
* The URL endpoint for obtaining a new token. Defaults to `'/iam/v3/oauth/token'`.
|
|
319
|
+
*/
|
|
320
|
+
tokenUrl?: GrantTokenUrlString;
|
|
321
|
+
/**
|
|
322
|
+
* A callback function triggered when successfully get new session.
|
|
323
|
+
*/
|
|
324
|
+
onGetUserSession: (accessToken: string, refreshToken: string) => void;
|
|
325
|
+
};
|
|
326
|
+
declare const createGetSessionInterceptor: ({ tokenUrl, onGetUserSession }: GetSessionInterceptorOptions) => Interceptor;
|
|
327
|
+
type SessionExpiredInterceptorOptions = {
|
|
328
|
+
/**
|
|
329
|
+
* The client ID used by the SDK, obtained from the Admin Portal under OAuth Clients.
|
|
330
|
+
*/
|
|
331
|
+
clientId: string;
|
|
332
|
+
/**
|
|
333
|
+
* A callback function triggered when the session has expired.
|
|
334
|
+
*/
|
|
335
|
+
onSessionExpired: () => void;
|
|
336
|
+
/**
|
|
337
|
+
* An optional array of URLs that should be ignored when handling session expiration.
|
|
338
|
+
* Default to `['/iam/v3/oauth/token', '/iam/v4/oauth/token', '/iam/v3/oauth/revoke']`
|
|
339
|
+
*/
|
|
340
|
+
expectedErrorUrls?: string[];
|
|
341
|
+
/**
|
|
342
|
+
* A callback function that retrieves the current refresh token.
|
|
343
|
+
*/
|
|
344
|
+
getRefreshToken: () => string | undefined;
|
|
345
|
+
/**
|
|
346
|
+
* The URL endpoint for obtaining a new token. Defaults to `'/iam/v3/oauth/token'`.
|
|
347
|
+
*/
|
|
348
|
+
tokenUrl?: GrantTokenUrlString;
|
|
349
|
+
};
|
|
350
|
+
declare const createSessionExpiredInterceptor: ({ clientId, onSessionExpired, expectedErrorUrls, getRefreshToken, tokenUrl }: SessionExpiredInterceptorOptions) => Interceptor;
|
|
351
|
+
|
|
352
|
+
declare const BASE_PATHS: readonly ["/achievement", "/basic", "/buildinfo", "/chat", "/cloudsave", "/content-management", "/differ", "/dsmcontroller", "/event", "/game-telemetry", "/gdpr", "/group", "/iam", "/leaderboard", "/agreement", "/lobby", "/match2", "/matchmaking", "/odin-config", "/platform", "/qosm", "/reporting", "/seasonpass", "/session", "/sessionbrowser", "/social", "/ugc", "/config"];
|
|
353
|
+
type BasePath = (typeof BASE_PATHS)[number] | (string & {});
|
|
354
|
+
|
|
355
|
+
type CreateCustomPathInterceptorOptions = {
|
|
356
|
+
/**
|
|
357
|
+
* A list of objects specifying which service base paths should be replaced.
|
|
358
|
+
* For example, providing `{'/iam': '/iam-test'}` will redirect all `'/iam'` requests to `'/iam-test'`.
|
|
359
|
+
*/
|
|
360
|
+
basePath: Partial<Record<BasePath, string>>;
|
|
361
|
+
/**
|
|
362
|
+
* Indicates whether to use the internal AccelByte network. This should only be used in a server environment.
|
|
363
|
+
* When set to true, requests will be made to `http://{service-name}/{path}` instead of the `baseURL`.
|
|
364
|
+
*/
|
|
365
|
+
isInternalNetwork?: boolean;
|
|
366
|
+
};
|
|
367
|
+
declare const createCustomPathInterceptor: ({ basePath, isInternalNetwork }: CreateCustomPathInterceptorOptions) => Interceptor;
|
|
287
368
|
|
|
288
369
|
declare const ErrorInterceptors: Array<Interceptor>;
|
|
289
370
|
|
|
@@ -352,4 +433,4 @@ declare class UrlHelper {
|
|
|
352
433
|
static removeQueryParam(fullUrlString: string, param: string): string;
|
|
353
434
|
}
|
|
354
435
|
|
|
355
|
-
export { AccelByte, AccelByteSDK, type ApiError, ApiUtils,
|
|
436
|
+
export { AccelByte, AccelByteSDK, type ApiError, ApiUtils, type AxiosConfig, BrowserHelper, CodeGenUtil, type CoreConfig, DecodeError, DesktopChecker, ERROR_CODE_LINK_DELETION_ACCOUNT, ERROR_CODE_TOKEN_EXPIRED, ERROR_LINK_ANOTHER_3RD_PARTY_ACCOUNT, ERROR_USER_BANNED, ErrorInterceptors, IamErrorCode, type Interceptor, type MakeOptional, type MakeRequired, Network, RefreshSession, type Response, type ResponseError, type SdkConstructorParam, SdkDevice, type SdkSetConfigParam, type TokenConfig, UrlHelper, Validate, createCustomPathInterceptor, createGetSessionInterceptor, createRefreshSessionInterceptor, createSessionExpiredInterceptor, doRefreshSession, isType, refreshWithLock };
|
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@accelbyte/sdk",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20240904033042",
|
|
4
4
|
"author": "AccelByte Inc",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
|
-
"main": "./
|
|
6
|
+
"main": "./dist/cjs/node/index.cjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"node": {
|
|
12
|
+
"import": "./dist/es/node/index.node.js",
|
|
13
|
+
"default": "./dist/cjs/node/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"default": "./dist/es/browser/index.browser.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
7
19
|
"type": "module",
|
|
8
20
|
"repository": {
|
|
9
21
|
"type": "git",
|
|
@@ -13,18 +25,20 @@
|
|
|
13
25
|
"build": "tsup && yarn build:dts",
|
|
14
26
|
"build:dts": "tsup src/index.ts --no-config --dts-only --format esm",
|
|
15
27
|
"test": "yarn test:unit",
|
|
16
|
-
"test:unit": "vitest",
|
|
28
|
+
"test:unit": "vitest --testTimeout=15000",
|
|
17
29
|
"test:e2e": "playwright test",
|
|
18
30
|
"clean": "npx rimraf dist && npx rimraf node_modules"
|
|
19
31
|
},
|
|
20
32
|
"devDependencies": {
|
|
33
|
+
"@anatine/zod-mock": "3.13.4",
|
|
34
|
+
"@faker-js/faker": "8.4.1",
|
|
21
35
|
"@playwright/test": "1.28.0",
|
|
22
36
|
"@types/crypto-js": "4.1.0",
|
|
23
37
|
"@types/node": "22.3.0",
|
|
24
38
|
"@types/platform": "1.3.4",
|
|
25
39
|
"@types/uuid": "8.3.4",
|
|
26
40
|
"happy-dom": "8.2.6",
|
|
27
|
-
"msw": "
|
|
41
|
+
"msw": "2.4.1",
|
|
28
42
|
"rimraf": "4.1.2",
|
|
29
43
|
"rollup": "3.29.4",
|
|
30
44
|
"tslib": "2.4.0",
|
|
@@ -33,7 +47,7 @@
|
|
|
33
47
|
"vitest": "2.0.5"
|
|
34
48
|
},
|
|
35
49
|
"dependencies": {
|
|
36
|
-
"@accelbyte/validator": "0.0.0-dev-
|
|
50
|
+
"@accelbyte/validator": "0.0.0-dev-20240904033042",
|
|
37
51
|
"axios": "1.3.6",
|
|
38
52
|
"buffer": "6.0.3",
|
|
39
53
|
"crypto-js": "4.1.1",
|
|
@@ -42,7 +56,7 @@
|
|
|
42
56
|
"query-string": "7.1.1",
|
|
43
57
|
"uuid": "8.3.2",
|
|
44
58
|
"validator": "13.7.0",
|
|
45
|
-
"zod": "3.
|
|
59
|
+
"zod": "3.23.8"
|
|
46
60
|
},
|
|
47
61
|
"sideEffects": [
|
|
48
62
|
"src/polyfills/browser.ts",
|