@crowdedkingdomstudios/crowdyjs 2.1.1 → 3.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/MIGRATION.md +26 -0
- package/README.md +110 -772
- package/dist/auth-state.d.ts +6 -16
- package/dist/auth-state.d.ts.map +1 -1
- package/dist/auth-state.js +9 -26
- package/dist/client.d.ts +14 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +22 -17
- package/dist/crowdy-client.d.ts +21 -3
- package/dist/crowdy-client.d.ts.map +1 -1
- package/dist/crowdy-client.js +37 -20
- package/dist/domains/serverStatus.d.ts +2 -1
- package/dist/domains/serverStatus.d.ts.map +1 -1
- package/dist/domains/serverStatus.js +5 -1
- package/dist/domains/udp.d.ts +19 -2
- package/dist/domains/udp.d.ts.map +1 -1
- package/dist/domains/udp.js +38 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/generated/graphql.d.ts +404 -12
- package/dist/generated/graphql.d.ts.map +1 -1
- package/dist/generated/graphql.js +2 -0
- package/dist/index.d.ts +10 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -6
- package/dist/logger.d.ts +8 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +1 -0
- package/dist/realtime.d.ts +86 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +270 -0
- package/dist/session.d.ts +27 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +61 -0
- package/dist/subscriptions.d.ts +1 -48
- package/dist/subscriptions.d.ts.map +1 -1
- package/dist/subscriptions.js +1 -192
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +50 -0
- package/dist/world.d.ts +35 -0
- package/dist/world.d.ts.map +1 -0
- package/dist/world.js +88 -0
- package/package.json +13 -3
package/dist/auth-state.d.ts
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
+
import { SessionStore, type SessionListener, type TokenStore } from './session.js';
|
|
2
|
+
export type AuthStateListener = SessionListener;
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Both the HTTP client (`GraphQLClient`) and the WebSocket subscription
|
|
5
|
-
* manager observe this. Anything that mutates auth state - the typed
|
|
6
|
-
* `client.auth.login()` / `register()` / `logout()` family, or external
|
|
7
|
-
* callers - flows through `setToken()` so subscription requests can never
|
|
8
|
-
* silently fail with "Must be authenticated to subscribe".
|
|
9
|
-
*
|
|
10
|
-
* (Replaces the previous arrangement where GraphQLClient and
|
|
11
|
-
* SubscriptionManager each held their own copy of the token.)
|
|
4
|
+
* Backwards-compatible internal name for the v3 SessionStore. Public callers
|
|
5
|
+
* should use `client.session`; older domain wrappers still accept AuthState.
|
|
12
6
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
private token;
|
|
16
|
-
private listeners;
|
|
17
|
-
getToken(): string | null;
|
|
18
|
-
setToken(token: string | null): void;
|
|
7
|
+
export declare class AuthState extends SessionStore {
|
|
8
|
+
constructor(tokenStore?: TokenStore);
|
|
19
9
|
subscribe(listener: AuthStateListener): () => void;
|
|
20
10
|
}
|
|
21
11
|
//# sourceMappingURL=auth-state.d.ts.map
|
package/dist/auth-state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-state.d.ts","sourceRoot":"","sources":["../src/auth-state.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"auth-state.d.ts","sourceRoot":"","sources":["../src/auth-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAEnF,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEhD;;;GAGG;AACH,qBAAa,SAAU,SAAQ,YAAY;gBAC7B,UAAU,CAAC,EAAE,UAAU;IAInC,SAAS,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;CAGnD"}
|
package/dist/auth-state.js
CHANGED
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
setToken(token) {
|
|
10
|
-
if (token === this.token)
|
|
11
|
-
return;
|
|
12
|
-
this.token = token;
|
|
13
|
-
for (const listener of this.listeners) {
|
|
14
|
-
try {
|
|
15
|
-
listener(token);
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
console.error('AuthState listener threw:', error);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
import { SessionStore } from './session.js';
|
|
2
|
+
/**
|
|
3
|
+
* Backwards-compatible internal name for the v3 SessionStore. Public callers
|
|
4
|
+
* should use `client.session`; older domain wrappers still accept AuthState.
|
|
5
|
+
*/
|
|
6
|
+
export class AuthState extends SessionStore {
|
|
7
|
+
constructor(tokenStore) {
|
|
8
|
+
super(tokenStore);
|
|
21
9
|
}
|
|
22
10
|
subscribe(listener) {
|
|
23
|
-
this.
|
|
24
|
-
// Replay current value immediately so listeners initialize correctly.
|
|
25
|
-
listener(this.token);
|
|
26
|
-
return () => {
|
|
27
|
-
this.listeners.delete(listener);
|
|
28
|
-
};
|
|
11
|
+
return this.onChange(listener);
|
|
29
12
|
}
|
|
30
13
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -7,27 +7,36 @@
|
|
|
7
7
|
* `client.auth.login`, `client.udp.sendActorUpdate`).
|
|
8
8
|
*/
|
|
9
9
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
10
|
-
import {
|
|
10
|
+
import type { SessionStore } from './session.js';
|
|
11
|
+
import type { CrowdyLogger } from './logger.js';
|
|
11
12
|
export interface GraphQLClientConfig {
|
|
13
|
+
httpUrl?: string;
|
|
12
14
|
graphqlEndpoint?: string;
|
|
13
15
|
timeout?: number;
|
|
16
|
+
logger?: CrowdyLogger;
|
|
14
17
|
}
|
|
15
18
|
export declare class GraphQLClient {
|
|
16
19
|
private readonly graphqlEndpoint;
|
|
17
20
|
private readonly timeout;
|
|
18
|
-
private readonly
|
|
19
|
-
|
|
21
|
+
private readonly session;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
constructor(config: GraphQLClientConfig | undefined, session: SessionStore);
|
|
20
24
|
getEndpoint(): string;
|
|
21
25
|
/**
|
|
22
26
|
* Execute a typed GraphQL operation produced by codegen and return the
|
|
23
27
|
* `data` payload. Throws on transport errors, GraphQL errors, or timeouts.
|
|
24
28
|
*/
|
|
25
|
-
request<TResult, TVariables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables
|
|
29
|
+
request<TResult, TVariables>(document: TypedDocumentNode<TResult, TVariables>, variables?: TVariables, options?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<TResult>;
|
|
26
32
|
/**
|
|
27
33
|
* Internal escape hatch for raw query strings (used by hand-written
|
|
28
34
|
* adapters that haven't migrated to typed documents yet). Prefer
|
|
29
35
|
* `request()` with a `TypedDocumentNode`.
|
|
30
36
|
*/
|
|
31
|
-
query<T = any>(query: string, variables?: Record<string,
|
|
37
|
+
query<T = any>(query: string, variables?: Record<string, unknown>, options?: {
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}): Promise<T>;
|
|
32
40
|
}
|
|
41
|
+
export { GraphQLClient as GraphQLTransport };
|
|
33
42
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.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`, `client.udp.sendActorUpdate`).
|
|
8
8
|
*/
|
|
9
9
|
import { print } from 'graphql';
|
|
10
|
+
import { silentLogger } from './logger.js';
|
|
11
|
+
import { CrowdyError, CrowdyGraphQLError, CrowdyHttpError, CrowdyNetworkError, CrowdyTimeoutError, } from './errors.js';
|
|
10
12
|
export class GraphQLClient {
|
|
11
|
-
constructor(config = {},
|
|
13
|
+
constructor(config = {}, session) {
|
|
12
14
|
this.graphqlEndpoint =
|
|
13
|
-
config.graphqlEndpoint || 'http://localhost:3000/graphql';
|
|
15
|
+
config.httpUrl || config.graphqlEndpoint || 'http://localhost:3000/graphql';
|
|
14
16
|
this.timeout = config.timeout || 60000;
|
|
15
|
-
this.
|
|
17
|
+
this.session = session;
|
|
18
|
+
this.logger = config.logger ?? silentLogger;
|
|
16
19
|
}
|
|
17
20
|
getEndpoint() {
|
|
18
21
|
return this.graphqlEndpoint;
|
|
@@ -21,19 +24,20 @@ export class GraphQLClient {
|
|
|
21
24
|
* Execute a typed GraphQL operation produced by codegen and return the
|
|
22
25
|
* `data` payload. Throws on transport errors, GraphQL errors, or timeouts.
|
|
23
26
|
*/
|
|
24
|
-
async request(document, variables) {
|
|
27
|
+
async request(document, variables, options = {}) {
|
|
25
28
|
const queryStr = print(document);
|
|
26
|
-
return this.query(queryStr, (variables ?? {}));
|
|
29
|
+
return this.query(queryStr, (variables ?? {}), options);
|
|
27
30
|
}
|
|
28
31
|
/**
|
|
29
32
|
* Internal escape hatch for raw query strings (used by hand-written
|
|
30
33
|
* adapters that haven't migrated to typed documents yet). Prefer
|
|
31
34
|
* `request()` with a `TypedDocumentNode`.
|
|
32
35
|
*/
|
|
33
|
-
async query(query, variables = {}) {
|
|
36
|
+
async query(query, variables = {}, options = {}) {
|
|
34
37
|
const controller = new AbortController();
|
|
35
38
|
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
36
|
-
const token = this.
|
|
39
|
+
const token = this.session.getToken();
|
|
40
|
+
const signal = options.signal ?? controller.signal;
|
|
37
41
|
try {
|
|
38
42
|
const requestBody = { query, variables };
|
|
39
43
|
const response = await fetch(this.graphqlEndpoint, {
|
|
@@ -43,32 +47,33 @@ export class GraphQLClient {
|
|
|
43
47
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
44
48
|
},
|
|
45
49
|
body: JSON.stringify(requestBody),
|
|
46
|
-
signal
|
|
50
|
+
signal,
|
|
47
51
|
});
|
|
48
52
|
clearTimeout(timeoutId);
|
|
49
53
|
if (!response.ok) {
|
|
50
54
|
const errorText = await response.text();
|
|
51
|
-
throw new
|
|
55
|
+
throw new CrowdyHttpError(response.status, errorText);
|
|
52
56
|
}
|
|
53
57
|
const result = await response.json();
|
|
54
58
|
if (result.errors) {
|
|
55
|
-
|
|
56
|
-
const errorMessage = Array.isArray(error.message)
|
|
57
|
-
? error.message.join(', ')
|
|
58
|
-
: error.message;
|
|
59
|
-
throw new Error(errorMessage);
|
|
59
|
+
throw new CrowdyGraphQLError(result.errors);
|
|
60
60
|
}
|
|
61
61
|
return result.data;
|
|
62
62
|
}
|
|
63
63
|
catch (error) {
|
|
64
64
|
clearTimeout(timeoutId);
|
|
65
65
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
66
|
-
throw new
|
|
66
|
+
throw new CrowdyTimeoutError(this.timeout);
|
|
67
67
|
}
|
|
68
|
-
if (error instanceof
|
|
68
|
+
if (error instanceof CrowdyError) {
|
|
69
69
|
throw error;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
throw new CrowdyNetworkError(error);
|
|
73
|
+
}
|
|
74
|
+
this.logger.error?.('GraphQL request failed', error);
|
|
75
|
+
throw new CrowdyNetworkError(error);
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
}
|
|
79
|
+
export { GraphQLClient as GraphQLTransport };
|
package/dist/crowdy-client.d.ts
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
* shortcuts are gone - use `client.auth.login()` / `client.udp.sendActorUpdate()`
|
|
6
6
|
* instead.
|
|
7
7
|
*/
|
|
8
|
+
import { AuthState } from './auth-state.js';
|
|
9
|
+
import { GraphQLClient } from './client.js';
|
|
10
|
+
import { SubscriptionManager } from './subscriptions.js';
|
|
11
|
+
import type { CrowdyLogger } from './logger.js';
|
|
12
|
+
import type { TokenStore } from './session.js';
|
|
13
|
+
import { WorldClient } from './world.js';
|
|
8
14
|
import { AuthAPI } from './domains/auth.js';
|
|
9
15
|
import { UsersAPI } from './domains/users.js';
|
|
10
16
|
import { OrganizationsAPI } from './domains/organizations.js';
|
|
@@ -21,14 +27,24 @@ import { StateAPI } from './domains/state.js';
|
|
|
21
27
|
import { ServerStatusAPI } from './domains/serverStatus.js';
|
|
22
28
|
import { UdpAPI } from './domains/udp.js';
|
|
23
29
|
export interface CrowdyClientConfig {
|
|
30
|
+
httpUrl?: string;
|
|
31
|
+
wsUrl?: string;
|
|
24
32
|
graphqlEndpoint?: string;
|
|
25
33
|
wsEndpoint?: string;
|
|
26
34
|
timeout?: number;
|
|
35
|
+
tokenStore?: TokenStore;
|
|
36
|
+
logger?: CrowdyLogger;
|
|
37
|
+
realtime?: {
|
|
38
|
+
retryAttempts?: number;
|
|
39
|
+
retryInitialDelayMs?: number;
|
|
40
|
+
retryMaxDelayMs?: number;
|
|
41
|
+
waitTimeoutMs?: number;
|
|
42
|
+
};
|
|
27
43
|
}
|
|
28
44
|
export declare class CrowdyClient {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
readonly session: AuthState;
|
|
46
|
+
readonly graphql: GraphQLClient;
|
|
47
|
+
readonly realtime: SubscriptionManager;
|
|
32
48
|
readonly auth: AuthAPI;
|
|
33
49
|
readonly users: UsersAPI;
|
|
34
50
|
readonly orgs: OrganizationsAPI;
|
|
@@ -45,7 +61,9 @@ export declare class CrowdyClient {
|
|
|
45
61
|
readonly serverStatus: ServerStatusAPI;
|
|
46
62
|
readonly udp: UdpAPI;
|
|
47
63
|
constructor(config?: CrowdyClientConfig);
|
|
64
|
+
world(appId: string): WorldClient;
|
|
48
65
|
/** Closes the WebSocket and clears the in-memory auth token. */
|
|
49
66
|
close(): void;
|
|
50
67
|
}
|
|
68
|
+
export declare function createCrowdyClient(config?: CrowdyClientConfig): CrowdyClient;
|
|
51
69
|
//# sourceMappingURL=crowdy-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crowdy-client.d.ts","sourceRoot":"","sources":["../src/crowdy-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"crowdy-client.d.ts","sourceRoot":"","sources":["../src/crowdy-client.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,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IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,eAAe,CAAC;IACvC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,MAAM,GAAE,kBAAuB;IAsC3C,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IAIjC,gEAAgE;IAChE,KAAK,IAAI,IAAI;CAId;AAED,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,kBAAuB,GAAG,YAAY,CAEhF"}
|
package/dist/crowdy-client.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { AuthState } from './auth-state.js';
|
|
9
9
|
import { GraphQLClient } from './client.js';
|
|
10
10
|
import { SubscriptionManager } from './subscriptions.js';
|
|
11
|
+
import { WorldClient } from './world.js';
|
|
11
12
|
import { AuthAPI } from './domains/auth.js';
|
|
12
13
|
import { UsersAPI } from './domains/users.js';
|
|
13
14
|
import { OrganizationsAPI } from './domains/organizations.js';
|
|
@@ -25,28 +26,44 @@ import { ServerStatusAPI } from './domains/serverStatus.js';
|
|
|
25
26
|
import { UdpAPI } from './domains/udp.js';
|
|
26
27
|
export class CrowdyClient {
|
|
27
28
|
constructor(config = {}) {
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
29
|
+
this.session = new AuthState(config.tokenStore);
|
|
30
|
+
this.graphql = new GraphQLClient({
|
|
31
|
+
httpUrl: config.httpUrl,
|
|
32
|
+
graphqlEndpoint: config.graphqlEndpoint,
|
|
33
|
+
timeout: config.timeout,
|
|
34
|
+
logger: config.logger,
|
|
35
|
+
}, this.session);
|
|
36
|
+
this.realtime = new SubscriptionManager({
|
|
37
|
+
wsUrl: config.wsUrl,
|
|
38
|
+
wsEndpoint: config.wsEndpoint,
|
|
39
|
+
logger: config.logger,
|
|
40
|
+
...config.realtime,
|
|
41
|
+
}, this.session);
|
|
42
|
+
this.auth = new AuthAPI(this.graphql, this.session);
|
|
43
|
+
this.users = new UsersAPI(this.graphql);
|
|
44
|
+
this.orgs = new OrganizationsAPI(this.graphql);
|
|
45
|
+
this.apps = new AppsAPI(this.graphql);
|
|
46
|
+
this.appAccess = new AppAccessAPI(this.graphql);
|
|
47
|
+
this.billing = new BillingAPI(this.graphql);
|
|
48
|
+
this.quotas = new QuotasAPI(this.graphql);
|
|
49
|
+
this.payments = new PaymentsAPI(this.graphql);
|
|
50
|
+
this.chunks = new ChunksAPI(this.graphql);
|
|
51
|
+
this.voxels = new VoxelsAPI(this.graphql);
|
|
52
|
+
this.actors = new ActorsAPI(this.graphql);
|
|
53
|
+
this.teleport = new TeleportAPI(this.graphql);
|
|
54
|
+
this.state = new StateAPI(this.graphql);
|
|
55
|
+
this.serverStatus = new ServerStatusAPI(this.graphql);
|
|
56
|
+
this.udp = new UdpAPI(this.graphql, this.realtime);
|
|
57
|
+
}
|
|
58
|
+
world(appId) {
|
|
59
|
+
return new WorldClient(appId, this.udp);
|
|
46
60
|
}
|
|
47
61
|
/** Closes the WebSocket and clears the in-memory auth token. */
|
|
48
62
|
close() {
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
63
|
+
this.realtime.close();
|
|
64
|
+
this.session.setToken(null);
|
|
51
65
|
}
|
|
52
66
|
}
|
|
67
|
+
export function createCrowdyClient(config = {}) {
|
|
68
|
+
return new CrowdyClient(config);
|
|
69
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GraphQLClient } from '../client.js';
|
|
2
|
-
import { type ServerWithLeastClientsQuery, type GraphqlServersQuery, type ActiveGraphQlServersQuery, type VersionInfoQuery } from '../generated/graphql.js';
|
|
2
|
+
import { type ServerWithLeastClientsQuery, type GraphqlServersQuery, type ActiveGraphQlServersQuery, type VersionInfoQuery, type GameClientBootstrapQuery, type GameClientBootstrapQueryVariables } from '../generated/graphql.js';
|
|
3
3
|
/**
|
|
4
4
|
* Server status / version info queries.
|
|
5
5
|
*
|
|
@@ -17,5 +17,6 @@ export declare class ServerStatusAPI {
|
|
|
17
17
|
listAll(): Promise<GraphqlServersQuery['graphqlServers']>;
|
|
18
18
|
listActiveGraphqlServers(): Promise<ActiveGraphQlServersQuery['activeGraphQLServers']>;
|
|
19
19
|
versionInfo(): Promise<VersionInfoQuery['versionInfo']>;
|
|
20
|
+
gameClientBootstrap(appId: GameClientBootstrapQueryVariables['appId']): Promise<GameClientBootstrapQuery['gameClientBootstrap']>;
|
|
20
21
|
}
|
|
21
22
|
//# sourceMappingURL=serverStatus.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverStatus.d.ts","sourceRoot":"","sources":["../../src/domains/serverStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAEL,KAAK,2BAA2B,EAEhC,KAAK,mBAAmB,EAExB,KAAK,yBAAyB,EAE9B,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"serverStatus.d.ts","sourceRoot":"","sources":["../../src/domains/serverStatus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAEL,KAAK,2BAA2B,EAEhC,KAAK,mBAAmB,EAExB,KAAK,yBAAyB,EAE9B,KAAK,gBAAgB,EAErB,KAAK,wBAAwB,EAC7B,KAAK,iCAAiC,EACvC,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;GASG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,aAAa;IAEhC,sBAAsB,IAAI,OAAO,CAAC,2BAA2B,CAAC,wBAAwB,CAAC,CAAC;IAKxF,OAAO,IAAI,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IAKzD,wBAAwB,IAAI,OAAO,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;IAKtF,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAKvD,mBAAmB,CACvB,KAAK,EAAE,iCAAiC,CAAC,OAAO,CAAC,GAChD,OAAO,CAAC,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAI5D"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ServerWithLeastClientsDocument, GraphqlServersDocument, ActiveGraphQlServersDocument, VersionInfoDocument, } from '../generated/graphql.js';
|
|
1
|
+
import { ServerWithLeastClientsDocument, GraphqlServersDocument, ActiveGraphQlServersDocument, VersionInfoDocument, GameClientBootstrapDocument, } from '../generated/graphql.js';
|
|
2
2
|
/**
|
|
3
3
|
* Server status / version info queries.
|
|
4
4
|
*
|
|
@@ -29,4 +29,8 @@ export class ServerStatusAPI {
|
|
|
29
29
|
const data = await this.gql.request(VersionInfoDocument, undefined);
|
|
30
30
|
return data.versionInfo;
|
|
31
31
|
}
|
|
32
|
+
async gameClientBootstrap(appId) {
|
|
33
|
+
const data = await this.gql.request(GameClientBootstrapDocument, { appId });
|
|
34
|
+
return data.gameClientBootstrap;
|
|
35
|
+
}
|
|
32
36
|
}
|
package/dist/domains/udp.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GraphQLClient } from '../client.js';
|
|
2
2
|
import type { SubscriptionManager, UdpNotificationHandlers } from '../subscriptions.js';
|
|
3
3
|
import { type ConnectUdpProxyMutation, type UdpProxyConnectionStatusQuery, type SendActorUpdateMutationVariables, type SendVoxelUpdateMutationVariables, type SendAudioPacketMutationVariables, type SendTextPacketMutationVariables, type SendClientEventMutationVariables } from '../generated/graphql.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { SpatialNotification } from '../realtime.js';
|
|
5
5
|
/**
|
|
6
6
|
* UDP proxy access for browser-style clients that can't open raw UDP
|
|
7
7
|
* sockets. Exposed as `client.udp`. All send mutations go over the same
|
|
@@ -12,21 +12,38 @@ import type { UnsubscribeFn } from '../types.js';
|
|
|
12
12
|
export declare class UdpAPI {
|
|
13
13
|
private gql;
|
|
14
14
|
private subs;
|
|
15
|
+
private readonly sequences;
|
|
15
16
|
constructor(gql: GraphQLClient, subs: SubscriptionManager);
|
|
16
17
|
connect(): Promise<ConnectUdpProxyMutation['connectUdpProxy']>;
|
|
17
18
|
disconnect(): Promise<boolean>;
|
|
18
19
|
connectionStatus(): Promise<UdpProxyConnectionStatusQuery['udpProxyConnectionStatus']>;
|
|
19
20
|
sendActorUpdate(input: SendActorUpdateMutationVariables['input']): Promise<boolean>;
|
|
21
|
+
sendActorUpdateAndWait(input: SendActorUpdateMutationVariables['input'], options?: {
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}): Promise<SpatialNotification>;
|
|
20
24
|
sendVoxelUpdate(input: SendVoxelUpdateMutationVariables['input']): Promise<boolean>;
|
|
25
|
+
sendVoxelUpdateAndWait(input: SendVoxelUpdateMutationVariables['input'], options?: {
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
}): Promise<SpatialNotification>;
|
|
21
28
|
sendAudioPacket(input: SendAudioPacketMutationVariables['input']): Promise<boolean>;
|
|
29
|
+
sendAudioPacketAndWait(input: SendAudioPacketMutationVariables['input'], options?: {
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}): Promise<SpatialNotification>;
|
|
22
32
|
sendTextPacket(input: SendTextPacketMutationVariables['input']): Promise<boolean>;
|
|
33
|
+
sendTextPacketAndWait(input: SendTextPacketMutationVariables['input'], options?: {
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
}): Promise<SpatialNotification>;
|
|
23
36
|
sendClientEvent(input: SendClientEventMutationVariables['input']): Promise<boolean>;
|
|
37
|
+
sendClientEventAndWait(input: SendClientEventMutationVariables['input'], options?: {
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
}): Promise<SpatialNotification>;
|
|
24
40
|
/**
|
|
25
41
|
* Subscribe to udpNotifications. Pass any combination of typename
|
|
26
42
|
* handlers; the returned function detaches all of them. The first
|
|
27
43
|
* subscriber opens the shared WebSocket; the last one to leave closes
|
|
28
44
|
* it.
|
|
29
45
|
*/
|
|
30
|
-
subscribe(handlers: UdpNotificationHandlers):
|
|
46
|
+
subscribe(handlers: UdpNotificationHandlers): () => void;
|
|
47
|
+
private withSequence;
|
|
31
48
|
}
|
|
32
49
|
//# sourceMappingURL=udp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/domains/udp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAEL,KAAK,uBAAuB,EAG5B,KAAK,6BAA6B,EAElC,KAAK,gCAAgC,EAErC,KAAK,gCAAgC,EAErC,KAAK,gCAAgC,EAErC,KAAK,+BAA+B,EAEpC,KAAK,gCAAgC,EACtC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"udp.d.ts","sourceRoot":"","sources":["../../src/domains/udp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACxB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,gCAAgC,CAAC,OAAO,CAAC,EAChD,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,mBAAmB,CAAC;IAOzB,cAAc,CAClB,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAC9C,OAAO,CAAC,OAAO,CAAC;IAKb,qBAAqB,CACzB,KAAK,EAAE,+BAA+B,CAAC,OAAO,CAAC,EAC/C,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,mBAAmB,CAAC;IAOzB,eAAe,CACnB,KAAK,EAAE,gCAAgC,CAAC,OAAO,CAAC,GAC/C,OAAO,CAAC,OAAO,CAAC;IAKb,sBAAsB,CAC1B,KAAK,EAAE,gCAAgC,CAAC,OAAO,CAAC,EAChD,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnC,OAAO,CAAC,mBAAmB,CAAC;IAO/B;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,IAAI;IAIxD,OAAO,CAAC,YAAY;CAQrB"}
|
package/dist/domains/udp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConnectUdpProxyDocument, DisconnectUdpProxyDocument, UdpProxyConnectionStatusDocument, SendActorUpdateDocument, SendVoxelUpdateDocument, SendAudioPacketDocument, SendTextPacketDocument, SendClientEventDocument, } from '../generated/graphql.js';
|
|
2
|
+
import { SequenceAllocator } from '../utils.js';
|
|
2
3
|
/**
|
|
3
4
|
* UDP proxy access for browser-style clients that can't open raw UDP
|
|
4
5
|
* sockets. Exposed as `client.udp`. All send mutations go over the same
|
|
@@ -10,6 +11,7 @@ export class UdpAPI {
|
|
|
10
11
|
constructor(gql, subs) {
|
|
11
12
|
this.gql = gql;
|
|
12
13
|
this.subs = subs;
|
|
14
|
+
this.sequences = new SequenceAllocator();
|
|
13
15
|
}
|
|
14
16
|
async connect() {
|
|
15
17
|
const data = await this.gql.request(ConnectUdpProxyDocument, undefined);
|
|
@@ -27,22 +29,52 @@ export class UdpAPI {
|
|
|
27
29
|
const data = await this.gql.request(SendActorUpdateDocument, { input });
|
|
28
30
|
return data.sendActorUpdate;
|
|
29
31
|
}
|
|
32
|
+
async sendActorUpdateAndWait(input, options = {}) {
|
|
33
|
+
const request = this.withSequence(input);
|
|
34
|
+
const wait = this.subs.waitForSequence(request.sequenceNumber, options.timeoutMs);
|
|
35
|
+
await this.sendActorUpdate(request);
|
|
36
|
+
return wait;
|
|
37
|
+
}
|
|
30
38
|
async sendVoxelUpdate(input) {
|
|
31
39
|
const data = await this.gql.request(SendVoxelUpdateDocument, { input });
|
|
32
40
|
return data.sendVoxelUpdate;
|
|
33
41
|
}
|
|
42
|
+
async sendVoxelUpdateAndWait(input, options = {}) {
|
|
43
|
+
const request = this.withSequence(input);
|
|
44
|
+
const wait = this.subs.waitForSequence(request.sequenceNumber, options.timeoutMs);
|
|
45
|
+
await this.sendVoxelUpdate(request);
|
|
46
|
+
return wait;
|
|
47
|
+
}
|
|
34
48
|
async sendAudioPacket(input) {
|
|
35
49
|
const data = await this.gql.request(SendAudioPacketDocument, { input });
|
|
36
50
|
return data.sendAudioPacket;
|
|
37
51
|
}
|
|
52
|
+
async sendAudioPacketAndWait(input, options = {}) {
|
|
53
|
+
const request = this.withSequence(input);
|
|
54
|
+
const wait = this.subs.waitForSequence(request.sequenceNumber, options.timeoutMs);
|
|
55
|
+
await this.sendAudioPacket(request);
|
|
56
|
+
return wait;
|
|
57
|
+
}
|
|
38
58
|
async sendTextPacket(input) {
|
|
39
59
|
const data = await this.gql.request(SendTextPacketDocument, { input });
|
|
40
60
|
return data.sendTextPacket;
|
|
41
61
|
}
|
|
62
|
+
async sendTextPacketAndWait(input, options = {}) {
|
|
63
|
+
const request = this.withSequence(input);
|
|
64
|
+
const wait = this.subs.waitForSequence(request.sequenceNumber, options.timeoutMs);
|
|
65
|
+
await this.sendTextPacket(request);
|
|
66
|
+
return wait;
|
|
67
|
+
}
|
|
42
68
|
async sendClientEvent(input) {
|
|
43
69
|
const data = await this.gql.request(SendClientEventDocument, { input });
|
|
44
70
|
return data.sendClientEvent;
|
|
45
71
|
}
|
|
72
|
+
async sendClientEventAndWait(input, options = {}) {
|
|
73
|
+
const request = this.withSequence(input);
|
|
74
|
+
const wait = this.subs.waitForSequence(request.sequenceNumber, options.timeoutMs);
|
|
75
|
+
await this.sendClientEvent(request);
|
|
76
|
+
return wait;
|
|
77
|
+
}
|
|
46
78
|
/**
|
|
47
79
|
* Subscribe to udpNotifications. Pass any combination of typename
|
|
48
80
|
* handlers; the returned function detaches all of them. The first
|
|
@@ -52,4 +84,10 @@ export class UdpAPI {
|
|
|
52
84
|
subscribe(handlers) {
|
|
53
85
|
return this.subs.subscribe(handlers);
|
|
54
86
|
}
|
|
87
|
+
withSequence(input) {
|
|
88
|
+
return {
|
|
89
|
+
...input,
|
|
90
|
+
sequenceNumber: input.sequenceNumber ?? this.sequences.next(),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
55
93
|
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface CrowdyGraphQLErrorPayload {
|
|
2
|
+
message: string;
|
|
3
|
+
locations?: readonly unknown[];
|
|
4
|
+
path?: readonly (string | number)[];
|
|
5
|
+
extensions?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface CrowdyErrorOptions {
|
|
8
|
+
message: string;
|
|
9
|
+
cause?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare class CrowdyError extends Error {
|
|
12
|
+
readonly cause?: unknown;
|
|
13
|
+
constructor(options: CrowdyErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
export declare class CrowdyHttpError extends CrowdyError {
|
|
16
|
+
readonly status: number;
|
|
17
|
+
readonly body: string;
|
|
18
|
+
constructor(status: number, body: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class CrowdyGraphQLError extends CrowdyError {
|
|
21
|
+
readonly graphqlErrors: CrowdyGraphQLErrorPayload[];
|
|
22
|
+
constructor(errors: CrowdyGraphQLErrorPayload[]);
|
|
23
|
+
get code(): unknown;
|
|
24
|
+
}
|
|
25
|
+
export declare class CrowdyNetworkError extends CrowdyError {
|
|
26
|
+
constructor(cause: unknown);
|
|
27
|
+
}
|
|
28
|
+
export declare class CrowdyTimeoutError extends CrowdyError {
|
|
29
|
+
constructor(timeoutMs: number);
|
|
30
|
+
}
|
|
31
|
+
export declare class CrowdyRealtimeError extends CrowdyError {
|
|
32
|
+
readonly code?: string;
|
|
33
|
+
readonly retryable?: boolean;
|
|
34
|
+
constructor(message: string, options?: {
|
|
35
|
+
code?: string;
|
|
36
|
+
retryable?: boolean;
|
|
37
|
+
cause?: unknown;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export declare class CrowdyProtocolError extends CrowdyError {
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACpC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,OAAO,EAAE,kBAAkB;CAKxC;AAED,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAKzC;AAED,qBAAa,kBAAmB,SAAQ,WAAW;IACjD,QAAQ,CAAC,aAAa,EAAE,yBAAyB,EAAE,CAAC;gBAExC,MAAM,EAAE,yBAAyB,EAAE;IAK/C,IAAI,IAAI,IAAI,OAAO,CAElB;CACF;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,KAAK,EAAE,OAAO;CAG3B;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,SAAS,EAAE,MAAM;CAG9B;AAED,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;gBAEjB,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;CAKnG;AAED,qBAAa,mBAAoB,SAAQ,WAAW;CAAG"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class CrowdyError extends Error {
|
|
2
|
+
constructor(options) {
|
|
3
|
+
super(options.message);
|
|
4
|
+
this.name = new.target.name;
|
|
5
|
+
this.cause = options.cause;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export class CrowdyHttpError extends CrowdyError {
|
|
9
|
+
constructor(status, body) {
|
|
10
|
+
super({ message: `HTTP ${status}: ${body}` });
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.body = body;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class CrowdyGraphQLError extends CrowdyError {
|
|
16
|
+
constructor(errors) {
|
|
17
|
+
super({ message: errors.map((error) => error.message).join('; ') });
|
|
18
|
+
this.graphqlErrors = errors;
|
|
19
|
+
}
|
|
20
|
+
get code() {
|
|
21
|
+
return this.graphqlErrors[0]?.extensions?.code;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class CrowdyNetworkError extends CrowdyError {
|
|
25
|
+
constructor(cause) {
|
|
26
|
+
super({ message: `Network error: ${String(cause)}`, cause });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export class CrowdyTimeoutError extends CrowdyError {
|
|
30
|
+
constructor(timeoutMs) {
|
|
31
|
+
super({ message: `Request timed out after ${timeoutMs}ms` });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class CrowdyRealtimeError extends CrowdyError {
|
|
35
|
+
constructor(message, options = {}) {
|
|
36
|
+
super({ message, cause: options.cause });
|
|
37
|
+
this.code = options.code;
|
|
38
|
+
this.retryable = options.retryable;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export class CrowdyProtocolError extends CrowdyError {
|
|
42
|
+
}
|