@crowdedkingdoms/crowdyjs 1.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/LICENSE +21 -0
- package/MIGRATION.md +247 -0
- package/README.md +303 -0
- package/dist/auth-state.d.ts +11 -0
- package/dist/auth-state.d.ts.map +1 -0
- package/dist/auth-state.js +13 -0
- package/dist/client.d.ts +135 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +150 -0
- package/dist/crowdy-client.d.ts +182 -0
- package/dist/crowdy-client.d.ts.map +1 -0
- package/dist/crowdy-client.js +146 -0
- package/dist/domains/actors.d.ts +117 -0
- package/dist/domains/actors.d.ts.map +1 -0
- package/dist/domains/actors.js +140 -0
- package/dist/domains/admin.d.ts +61 -0
- package/dist/domains/admin.d.ts.map +1 -0
- package/dist/domains/admin.js +33 -0
- package/dist/domains/appAccess.d.ts +141 -0
- package/dist/domains/appAccess.d.ts.map +1 -0
- package/dist/domains/appAccess.js +198 -0
- package/dist/domains/apps.d.ts +192 -0
- package/dist/domains/apps.d.ts.map +1 -0
- package/dist/domains/apps.js +217 -0
- package/dist/domains/auth.d.ts +163 -0
- package/dist/domains/auth.d.ts.map +1 -0
- package/dist/domains/auth.js +208 -0
- package/dist/domains/avatars.d.ts +94 -0
- package/dist/domains/avatars.d.ts.map +1 -0
- package/dist/domains/avatars.js +137 -0
- package/dist/domains/billing.d.ts +97 -0
- package/dist/domains/billing.d.ts.map +1 -0
- package/dist/domains/billing.js +131 -0
- package/dist/domains/channels.d.ts +293 -0
- package/dist/domains/channels.d.ts.map +1 -0
- package/dist/domains/channels.js +353 -0
- package/dist/domains/chunks.d.ts +133 -0
- package/dist/domains/chunks.d.ts.map +1 -0
- package/dist/domains/chunks.js +153 -0
- package/dist/domains/controlPlane.d.ts +174 -0
- package/dist/domains/controlPlane.d.ts.map +1 -0
- package/dist/domains/controlPlane.js +252 -0
- package/dist/domains/environments.d.ts +155 -0
- package/dist/domains/environments.d.ts.map +1 -0
- package/dist/domains/environments.js +223 -0
- package/dist/domains/gameApps.d.ts +114 -0
- package/dist/domains/gameApps.d.ts.map +1 -0
- package/dist/domains/gameApps.js +169 -0
- package/dist/domains/gameModel.d.ts +668 -0
- package/dist/domains/gameModel.d.ts.map +1 -0
- package/dist/domains/gameModel.js +816 -0
- package/dist/domains/host.d.ts +35 -0
- package/dist/domains/host.d.ts.map +1 -0
- package/dist/domains/host.js +40 -0
- package/dist/domains/organizations.d.ts +179 -0
- package/dist/domains/organizations.d.ts.map +1 -0
- package/dist/domains/organizations.js +269 -0
- package/dist/domains/payments.d.ts +104 -0
- package/dist/domains/payments.d.ts.map +1 -0
- package/dist/domains/payments.js +129 -0
- package/dist/domains/platform.d.ts +49 -0
- package/dist/domains/platform.d.ts.map +1 -0
- package/dist/domains/platform.js +50 -0
- package/dist/domains/quotas.d.ts +62 -0
- package/dist/domains/quotas.d.ts.map +1 -0
- package/dist/domains/quotas.js +79 -0
- package/dist/domains/serverStatus.d.ts +90 -0
- package/dist/domains/serverStatus.d.ts.map +1 -0
- package/dist/domains/serverStatus.js +104 -0
- package/dist/domains/sharedEnvironment.d.ts +133 -0
- package/dist/domains/sharedEnvironment.d.ts.map +1 -0
- package/dist/domains/sharedEnvironment.js +179 -0
- package/dist/domains/state.d.ts +64 -0
- package/dist/domains/state.d.ts.map +1 -0
- package/dist/domains/state.js +75 -0
- package/dist/domains/teams.d.ts +292 -0
- package/dist/domains/teams.d.ts.map +1 -0
- package/dist/domains/teams.js +352 -0
- package/dist/domains/teleport.d.ts +41 -0
- package/dist/domains/teleport.d.ts.map +1 -0
- package/dist/domains/teleport.js +43 -0
- package/dist/domains/udp.d.ts +405 -0
- package/dist/domains/udp.d.ts.map +1 -0
- package/dist/domains/udp.js +457 -0
- package/dist/domains/usage.d.ts +76 -0
- package/dist/domains/usage.d.ts.map +1 -0
- package/dist/domains/usage.js +110 -0
- package/dist/domains/users.d.ts +147 -0
- package/dist/domains/users.d.ts.map +1 -0
- package/dist/domains/users.js +195 -0
- package/dist/domains/voxels.d.ts +136 -0
- package/dist/domains/voxels.d.ts.map +1 -0
- package/dist/domains/voxels.js +153 -0
- package/dist/errors.d.ts +158 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +142 -0
- package/dist/generated/graphql.d.ts +12206 -0
- package/dist/generated/graphql.d.ts.map +1 -0
- package/dist/generated/graphql.js +474 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- 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 +319 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +390 -0
- package/dist/session.d.ts +73 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +96 -0
- package/dist/subscriptions.d.ts +2 -0
- package/dist/subscriptions.d.ts.map +1 -0
- package/dist/subscriptions.js +1 -0
- package/dist/types.d.ts +658 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +61 -0
- package/dist/utils.d.ts +98 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +136 -0
- package/dist/world.d.ts +236 -0
- package/dist/world.d.ts.map +1 -0
- package/dist/world.js +275 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrowdyJS SDK — client SDK for Crowded Kingdoms.
|
|
3
|
+
*
|
|
4
|
+
* As of the management/game-api split, the SDK targets **two** GraphQL
|
|
5
|
+
* endpoints behind a single `CrowdyClient`:
|
|
6
|
+
*
|
|
7
|
+
* - `cks-management-api` for identity (`client.auth`, `client.users`).
|
|
8
|
+
* This is where `game_tokens` get minted.
|
|
9
|
+
* - `cks-game-api` for everything game-side (`client.chunks`,
|
|
10
|
+
* `client.voxels`, `client.actors`, `client.teleport`, `client.state`,
|
|
11
|
+
* `client.serverStatus`, `client.udp`).
|
|
12
|
+
*
|
|
13
|
+
* Both clients share a single `AuthState` so the token returned by
|
|
14
|
+
* `client.auth.login()` is automatically attached to every subsequent
|
|
15
|
+
* request, regardless of which endpoint serves it.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
*
|
|
19
|
+
* import { CrowdyClient } from '@crowdedkingdoms/crowdyjs';
|
|
20
|
+
*
|
|
21
|
+
* const client = new CrowdyClient({
|
|
22
|
+
* httpUrl: 'https://dev-game-api.crowdedkingdoms.com',
|
|
23
|
+
* wsUrl: 'wss://dev-game-api.crowdedkingdoms.com',
|
|
24
|
+
* managementUrl: 'https://dev-management-api.crowdedkingdoms.com',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const { token, user } = await client.auth.login({ email, password });
|
|
28
|
+
* const me = await client.users.me();
|
|
29
|
+
* const unsub = client.udp.subscribe({ actorUpdate: (n) => { ... } }, appId);
|
|
30
|
+
*
|
|
31
|
+
* As of v6 the SDK wraps the **full** public surface of both APIs, namespaced
|
|
32
|
+
* by audience: the game-client surface (`auth`, `users`, `udp`, `world`,
|
|
33
|
+
* `chunks`/`voxels`/`actors`/`avatars`/`state`/`teleport`/`channels`/`teams`/
|
|
34
|
+
* `gameModel`/`host`), the privileged studio-admin surface grouped under
|
|
35
|
+
* `client.admin` (`organizations`, `appAccess`, `billing`, `payments`,
|
|
36
|
+
* `quotas`, `environments`, `usage`, `sharedEnvironment`, `gameApps`; also
|
|
37
|
+
* available top-level), and the operator control-plane surface under
|
|
38
|
+
* `client.operator` (requires `is_operator`). Admin/operator calls still
|
|
39
|
+
* require the appropriate token + permission — the server enforces them; the
|
|
40
|
+
* SDK only provides typed wrappers. Drive admin/operator from a studio backend
|
|
41
|
+
* or internal tooling, never an untrusted browser.
|
|
42
|
+
*/
|
|
43
|
+
/** The published package version. Mirrors `package.json`. */
|
|
44
|
+
export declare const VERSION = "1.0.0";
|
|
45
|
+
export { CrowdyClient, createCrowdyClient, type CrowdyClientConfig, } from './crowdy-client.js';
|
|
46
|
+
export { BrowserLocalStorageTokenStore, SessionStore, type SessionListener, type TokenStore, } from './session.js';
|
|
47
|
+
export { GraphQLClient, GraphQLTransport, type GraphQLClientConfig, } from './client.js';
|
|
48
|
+
export { RealtimeClient, type RealtimeConfig, type RealtimeStatus, type SpatialNotification, type UdpNotification, type UdpNotificationHandlers, } from './realtime.js';
|
|
49
|
+
export { WorldClient, ActorClient, type ActorOptions } from './world.js';
|
|
50
|
+
export { CrowdyError, CrowdyGraphQLError, CrowdyHttpError, CrowdyNetworkError, CrowdyProtocolError, CrowdyRealtimeError, CrowdyTimeoutError, } from './errors.js';
|
|
51
|
+
export { SequenceAllocator, decodeBase64, encodeBase64, generateCrowdyUuid, validateChunkCoordinates, validateCrowdyUuid, } from './utils.js';
|
|
52
|
+
export type { BigInt, ChunkCoordinates, VoxelCoordinates, ActorUpdateNotification, ActorUpdateResponse, VoxelUpdateNotification, VoxelUpdateResponse, ClientAudioNotification, ClientTextNotification, ClientEventNotification, ServerEventNotification, GenericErrorResponse, ActorUpdateHandler, ActorUpdateResponseHandler, VoxelUpdateHandler, VoxelUpdateResponseHandler, ClientAudioHandler, ClientTextHandler, ClientEventHandler, ServerEventHandler, GenericErrorHandler, UnsubscribeFn, } from './types.js';
|
|
53
|
+
export { UdpErrorCode } from './types.js';
|
|
54
|
+
export { AuthAPI } from './domains/auth.js';
|
|
55
|
+
export { UsersAPI } from './domains/users.js';
|
|
56
|
+
export { AppsAPI, type AppRoute } from './domains/apps.js';
|
|
57
|
+
export { PlatformAPI, type PlatformConfig } from './domains/platform.js';
|
|
58
|
+
export { OrganizationsAPI } from './domains/organizations.js';
|
|
59
|
+
export { AppAccessAPI } from './domains/appAccess.js';
|
|
60
|
+
export { BillingAPI } from './domains/billing.js';
|
|
61
|
+
export { PaymentsAPI } from './domains/payments.js';
|
|
62
|
+
export { QuotasAPI } from './domains/quotas.js';
|
|
63
|
+
export { EnvironmentsAPI } from './domains/environments.js';
|
|
64
|
+
export { UsageAPI } from './domains/usage.js';
|
|
65
|
+
export { SharedEnvironmentAPI } from './domains/sharedEnvironment.js';
|
|
66
|
+
export { ControlPlaneAPI } from './domains/controlPlane.js';
|
|
67
|
+
export { AdminAPI } from './domains/admin.js';
|
|
68
|
+
export { AvatarsAPI } from './domains/avatars.js';
|
|
69
|
+
export { HostAPI } from './domains/host.js';
|
|
70
|
+
export { GameAppsAPI } from './domains/gameApps.js';
|
|
71
|
+
export { ChunksAPI } from './domains/chunks.js';
|
|
72
|
+
export { VoxelsAPI } from './domains/voxels.js';
|
|
73
|
+
export { ActorsAPI } from './domains/actors.js';
|
|
74
|
+
export { TeleportAPI } from './domains/teleport.js';
|
|
75
|
+
export { StateAPI } from './domains/state.js';
|
|
76
|
+
export { ServerStatusAPI } from './domains/serverStatus.js';
|
|
77
|
+
export { ChannelsAPI } from './domains/channels.js';
|
|
78
|
+
export { TeamsAPI } from './domains/teams.js';
|
|
79
|
+
export { UdpAPI } from './domains/udp.js';
|
|
80
|
+
export { GameModelAPI } from './domains/gameModel.js';
|
|
81
|
+
export type { ChunkCoordinatesInput, VoxelCoordinatesInput, ActorUpdateRequestInput, VoxelUpdateRequestInput, ClientAudioPacketInput, ClientTextPacketInput, ClientEventNotificationInput, UdpProxyConnectionStatus, RealtimeConnectionEvent, GameClientBootstrap, LoginUserInput, RegisterUserInput, ResetPasswordInput, UpdateGamertagInput, CreateActorInput, UpdateActorInput, ActorFilterInput, BatchActorLookupInput, CreateUserAppStateInput, UpdateUserStateInput, UpdateAvatarStateInput, UpdateActorStateInput, UpdateChunkStateInput, UpdateChunkLodsInput, ChunkUpdateInput, UpdateVoxelInput, RollbackVoxelUpdatesInput, GetChunkInput, GetChunkLodsInput, GetChunksByDistanceInput, GetVoxelListInput, ListVoxelsInput, ListVoxelUpdatesByDistanceInput, TeleportRequestInput, LodDataInput, VoxelStateInput, Chunk, ChunkLodsResponse, ChunksByDistanceResponse, ChunkVoxelResponse, ChunkVoxelUpdatesResponse, Voxel, VoxelUpdatesByDistanceResponse, VoxelUpdateHistoryEvent, RollbackVoxelEventResult, Actor, Avatar, AvatarDto, TeleportResponse, UserAppState, ServerStatus, GraphQlServer, ServerVersionInfo, VersionInfo, PageInfo, UdpNotificationsSubscription, GmContainer, GmContainerState, GmContainerType, GmPropertyDef, GmFunction, GmFunctionParam, GmFunctionMutation, GmSession, GmSessionParticipant, GmEdge, GmTraverseResult, GmInvokeResult, GmMutationApplied, GmEvent, GmTypeSchema, GmAppFeature, GmTierFeature, GmAppPolicy, GmSeedResult, UpsertContainerTypeInput, UpsertPropertyDefInput, UpsertFunctionInput, FunctionParamInput, FunctionMutationInput, SeedGameModelInput, SeedContainerInput, SeedContainerTypeInput, SeedPropertyDefInput, SeedFunctionInput, SeedEdgeInput, SeedPropertyInput, CreateSessionInput, JoinSessionInput, SetSessionTurnInput, CreateContainerInput, SetContainerPropertyInput, AddEdgeInput, InvokeFunctionInput, DefineAppFeatureInput, GrantTierFeatureInput, SetGameModelPolicyInput, Scalars, } from './generated/graphql.js';
|
|
82
|
+
export type { CreateAppInput, UpdateAppInput, CreateOrganizationInput, CreateOrgTokenInput, UpdateOrgTokenInput, InviteOrgMemberInput, CreateOrgRoleInput, UpdateOrgRoleInput, CreateAccessTierInput, UpdateAccessTierInput, GrantAppAccessInput, CreateCheckoutInput, CheckoutFilterInput, SetQuotaInput, } from './generated/graphql.js';
|
|
83
|
+
export { ServerState, AppVisibility } from './generated/graphql.js';
|
|
84
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,6DAA6D;AAC7D,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAA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EACnB,oBAAoB,EACpB,yBAAyB,EACzB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EAEvB,OAAO,GACR,MAAM,wBAAwB,CAAC;AAMhC,YAAY,EACV,cAAc,EACd,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrowdyJS SDK — client SDK for Crowded Kingdoms.
|
|
3
|
+
*
|
|
4
|
+
* As of the management/game-api split, the SDK targets **two** GraphQL
|
|
5
|
+
* endpoints behind a single `CrowdyClient`:
|
|
6
|
+
*
|
|
7
|
+
* - `cks-management-api` for identity (`client.auth`, `client.users`).
|
|
8
|
+
* This is where `game_tokens` get minted.
|
|
9
|
+
* - `cks-game-api` for everything game-side (`client.chunks`,
|
|
10
|
+
* `client.voxels`, `client.actors`, `client.teleport`, `client.state`,
|
|
11
|
+
* `client.serverStatus`, `client.udp`).
|
|
12
|
+
*
|
|
13
|
+
* Both clients share a single `AuthState` so the token returned by
|
|
14
|
+
* `client.auth.login()` is automatically attached to every subsequent
|
|
15
|
+
* request, regardless of which endpoint serves it.
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
*
|
|
19
|
+
* import { CrowdyClient } from '@crowdedkingdoms/crowdyjs';
|
|
20
|
+
*
|
|
21
|
+
* const client = new CrowdyClient({
|
|
22
|
+
* httpUrl: 'https://dev-game-api.crowdedkingdoms.com',
|
|
23
|
+
* wsUrl: 'wss://dev-game-api.crowdedkingdoms.com',
|
|
24
|
+
* managementUrl: 'https://dev-management-api.crowdedkingdoms.com',
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const { token, user } = await client.auth.login({ email, password });
|
|
28
|
+
* const me = await client.users.me();
|
|
29
|
+
* const unsub = client.udp.subscribe({ actorUpdate: (n) => { ... } }, appId);
|
|
30
|
+
*
|
|
31
|
+
* As of v6 the SDK wraps the **full** public surface of both APIs, namespaced
|
|
32
|
+
* by audience: the game-client surface (`auth`, `users`, `udp`, `world`,
|
|
33
|
+
* `chunks`/`voxels`/`actors`/`avatars`/`state`/`teleport`/`channels`/`teams`/
|
|
34
|
+
* `gameModel`/`host`), the privileged studio-admin surface grouped under
|
|
35
|
+
* `client.admin` (`organizations`, `appAccess`, `billing`, `payments`,
|
|
36
|
+
* `quotas`, `environments`, `usage`, `sharedEnvironment`, `gameApps`; also
|
|
37
|
+
* available top-level), and the operator control-plane surface under
|
|
38
|
+
* `client.operator` (requires `is_operator`). Admin/operator calls still
|
|
39
|
+
* require the appropriate token + permission — the server enforces them; the
|
|
40
|
+
* SDK only provides typed wrappers. Drive admin/operator from a studio backend
|
|
41
|
+
* or internal tooling, never an untrusted browser.
|
|
42
|
+
*/
|
|
43
|
+
/** The published package version. Mirrors `package.json`. */
|
|
44
|
+
export const VERSION = '1.0.0';
|
|
45
|
+
export { CrowdyClient, createCrowdyClient, } from './crowdy-client.js';
|
|
46
|
+
export { BrowserLocalStorageTokenStore, SessionStore, } from './session.js';
|
|
47
|
+
export { GraphQLClient, GraphQLTransport, } from './client.js';
|
|
48
|
+
export { RealtimeClient, } from './realtime.js';
|
|
49
|
+
export { WorldClient, ActorClient } from './world.js';
|
|
50
|
+
export { CrowdyError, CrowdyGraphQLError, CrowdyHttpError, CrowdyNetworkError, CrowdyProtocolError, CrowdyRealtimeError, CrowdyTimeoutError, } from './errors.js';
|
|
51
|
+
export { SequenceAllocator, decodeBase64, encodeBase64, generateCrowdyUuid, validateChunkCoordinates, validateCrowdyUuid, } from './utils.js';
|
|
52
|
+
export { UdpErrorCode } from './types.js';
|
|
53
|
+
// -----------------------------------------------------------------------------
|
|
54
|
+
// Domain wrappers.
|
|
55
|
+
// AuthAPI / UsersAPI / AppsAPI target cks-management-api; the rest target
|
|
56
|
+
// cks-game-api.
|
|
57
|
+
// -----------------------------------------------------------------------------
|
|
58
|
+
export { AuthAPI } from './domains/auth.js';
|
|
59
|
+
export { UsersAPI } from './domains/users.js';
|
|
60
|
+
export { AppsAPI } from './domains/apps.js';
|
|
61
|
+
export { PlatformAPI } from './domains/platform.js';
|
|
62
|
+
export { OrganizationsAPI } from './domains/organizations.js';
|
|
63
|
+
export { AppAccessAPI } from './domains/appAccess.js';
|
|
64
|
+
export { BillingAPI } from './domains/billing.js';
|
|
65
|
+
export { PaymentsAPI } from './domains/payments.js';
|
|
66
|
+
export { QuotasAPI } from './domains/quotas.js';
|
|
67
|
+
export { EnvironmentsAPI } from './domains/environments.js';
|
|
68
|
+
export { UsageAPI } from './domains/usage.js';
|
|
69
|
+
export { SharedEnvironmentAPI } from './domains/sharedEnvironment.js';
|
|
70
|
+
export { ControlPlaneAPI } from './domains/controlPlane.js';
|
|
71
|
+
export { AdminAPI } from './domains/admin.js';
|
|
72
|
+
export { AvatarsAPI } from './domains/avatars.js';
|
|
73
|
+
export { HostAPI } from './domains/host.js';
|
|
74
|
+
export { GameAppsAPI } from './domains/gameApps.js';
|
|
75
|
+
export { ChunksAPI } from './domains/chunks.js';
|
|
76
|
+
export { VoxelsAPI } from './domains/voxels.js';
|
|
77
|
+
export { ActorsAPI } from './domains/actors.js';
|
|
78
|
+
export { TeleportAPI } from './domains/teleport.js';
|
|
79
|
+
export { StateAPI } from './domains/state.js';
|
|
80
|
+
export { ServerStatusAPI } from './domains/serverStatus.js';
|
|
81
|
+
export { ChannelsAPI } from './domains/channels.js';
|
|
82
|
+
export { TeamsAPI } from './domains/teams.js';
|
|
83
|
+
export { UdpAPI } from './domains/udp.js';
|
|
84
|
+
export { GameModelAPI } from './domains/gameModel.js';
|
|
85
|
+
export { ServerState, AppVisibility } from './generated/graphql.js';
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface CrowdyLogger {
|
|
2
|
+
debug?(message: string, meta?: unknown): void;
|
|
3
|
+
info?(message: string, meta?: unknown): void;
|
|
4
|
+
warn?(message: string, meta?: unknown): void;
|
|
5
|
+
error?(message: string, meta?: unknown): void;
|
|
6
|
+
}
|
|
7
|
+
export declare const silentLogger: CrowdyLogger;
|
|
8
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC9C,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7C,KAAK,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/C;AAED,eAAO,MAAM,YAAY,EAAE,YAAiB,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const silentLogger = {};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import type { SessionStore } from './session.js';
|
|
2
|
+
import type { CrowdyLogger } from './logger.js';
|
|
3
|
+
import { CrowdyRealtimeError } from './errors.js';
|
|
4
|
+
import { type UdpNotificationsSubscription } from './generated/graphql.js';
|
|
5
|
+
/**
|
|
6
|
+
* Lifecycle state of the realtime WebSocket connection, as reported by
|
|
7
|
+
* {@link RealtimeClient.status} and {@link RealtimeClient.onStatus}.
|
|
8
|
+
*
|
|
9
|
+
* - `idle` — created but never connected; no socket open yet.
|
|
10
|
+
* - `connecting` — opening the socket / performing the initial handshake.
|
|
11
|
+
* - `connected` — the subscription is live and receiving notifications.
|
|
12
|
+
* - `reconnecting` — the socket dropped (or a retry is in progress) while a
|
|
13
|
+
* connection is still desired; backoff is running and it will resubscribe.
|
|
14
|
+
* - `disconnected` — intentionally closed (e.g. {@link RealtimeClient.disconnect}
|
|
15
|
+
* or the last subscriber unsubscribing).
|
|
16
|
+
* - `failed` — a fatal, non-retryable error (e.g. not authenticated, or a
|
|
17
|
+
* non-retryable `RealtimeConnectionEvent` such as `APP_ID_REQUIRED`); it will
|
|
18
|
+
* not reconnect on its own.
|
|
19
|
+
*/
|
|
20
|
+
export type RealtimeStatus = 'idle' | 'connecting' | 'connected' | 'reconnecting' | 'disconnected' | 'failed';
|
|
21
|
+
/**
|
|
22
|
+
* Any single message delivered on the `udpNotifications` subscription — the
|
|
23
|
+
* union of every spatial echo/fan-out notification plus `GenericErrorResponse`
|
|
24
|
+
* and `RealtimeConnectionEvent`. This is the codegen-derived (canonical)
|
|
25
|
+
* shape, narrowed to the non-null payload; discriminate the members by their
|
|
26
|
+
* `__typename`.
|
|
27
|
+
*/
|
|
28
|
+
export type UdpNotification = NonNullable<UdpNotificationsSubscription['udpNotifications']>;
|
|
29
|
+
/**
|
|
30
|
+
* The members of {@link UdpNotification} that carry a `sequenceNumber` and can
|
|
31
|
+
* therefore be correlated back to the send that produced them — the spatial
|
|
32
|
+
* echoes/fan-out (actor/voxel/audio/text/event notifications and responses,
|
|
33
|
+
* single-actor and channel messages) plus `GenericErrorResponse`. Excludes
|
|
34
|
+
* `RealtimeConnectionEvent`, which has no sequence number.
|
|
35
|
+
*
|
|
36
|
+
* {@link RealtimeClient.waitForSequence} resolves with one of these when a
|
|
37
|
+
* matching success arrives (it rejects instead when the match is a
|
|
38
|
+
* `GenericErrorResponse`), which is what powers the `...AndWait` spatial sends.
|
|
39
|
+
*/
|
|
40
|
+
export type SpatialNotification = Extract<UdpNotification, {
|
|
41
|
+
sequenceNumber: number;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Per-notification callbacks passed to `client.udp.subscribe(handlers, appId)`
|
|
45
|
+
* (or `client.world(appId).subscribe`). Every handler is optional — supply
|
|
46
|
+
* only the ones you care about. Each key maps a notification's GraphQL
|
|
47
|
+
* `__typename` to its callback, except {@link any} and {@link error}, which are
|
|
48
|
+
* special (see below).
|
|
49
|
+
*
|
|
50
|
+
* Handlers are dispatched synchronously as messages arrive, and exceptions
|
|
51
|
+
* thrown inside one are caught and logged so a single bad handler can't tear
|
|
52
|
+
* down the stream. For each notification {@link any} runs first, then the
|
|
53
|
+
* matching typed handler.
|
|
54
|
+
*/
|
|
55
|
+
export interface UdpNotificationHandlers {
|
|
56
|
+
/**
|
|
57
|
+
* Another actor's position/state changed within your area of interest —
|
|
58
|
+
* the spatial fan-out of someone else's `sendActorUpdate`. `state` is
|
|
59
|
+
* base64-encoded actor state.
|
|
60
|
+
*/
|
|
61
|
+
actorUpdate?: (notification: Extract<UdpNotification, {
|
|
62
|
+
__typename?: 'ActorUpdateNotification';
|
|
63
|
+
}>) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Server acknowledgement echoing one of **your own** actor updates. This is
|
|
66
|
+
* the notification a `sendActorUpdateAndWait` correlates to via
|
|
67
|
+
* `sequenceNumber`.
|
|
68
|
+
*/
|
|
69
|
+
actorUpdateResponse?: (notification: Extract<UdpNotification, {
|
|
70
|
+
__typename?: 'ActorUpdateResponse';
|
|
71
|
+
}>) => void;
|
|
72
|
+
/**
|
|
73
|
+
* A voxel changed within range — the fan-out of another client's voxel edit.
|
|
74
|
+
* `voxelState` is base64-encoded.
|
|
75
|
+
*/
|
|
76
|
+
voxelUpdate?: (notification: Extract<UdpNotification, {
|
|
77
|
+
__typename?: 'VoxelUpdateNotification';
|
|
78
|
+
}>) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Server acknowledgement echoing one of **your own** voxel updates (the
|
|
81
|
+
* `sendVoxelUpdateAndWait` correlation target).
|
|
82
|
+
*/
|
|
83
|
+
voxelUpdateResponse?: (notification: Extract<UdpNotification, {
|
|
84
|
+
__typename?: 'VoxelUpdateResponse';
|
|
85
|
+
}>) => void;
|
|
86
|
+
/**
|
|
87
|
+
* A nearby client sent a voice/audio packet; `audioData` is base64-encoded
|
|
88
|
+
* compressed audio (decode with {@link decodeBase64}).
|
|
89
|
+
*/
|
|
90
|
+
audio?: (notification: Extract<UdpNotification, {
|
|
91
|
+
__typename?: 'ClientAudioNotification';
|
|
92
|
+
}>) => void;
|
|
93
|
+
/** A nearby client sent a text/chat message (`text` is UTF-8). */
|
|
94
|
+
text?: (notification: Extract<UdpNotification, {
|
|
95
|
+
__typename?: 'ClientTextNotification';
|
|
96
|
+
}>) => void;
|
|
97
|
+
/**
|
|
98
|
+
* A nearby client emitted a custom client event (a client-defined
|
|
99
|
+
* `eventType` with a base64 `state` payload).
|
|
100
|
+
*/
|
|
101
|
+
clientEvent?: (notification: Extract<UdpNotification, {
|
|
102
|
+
__typename?: 'ClientEventNotification';
|
|
103
|
+
}>) => void;
|
|
104
|
+
/**
|
|
105
|
+
* A server-originated spatial event broadcast to a region (e.g. world or NPC
|
|
106
|
+
* events), shaped like a client event (`eventType` + base64 `state`).
|
|
107
|
+
*/
|
|
108
|
+
serverEvent?: (notification: Extract<UdpNotification, {
|
|
109
|
+
__typename?: 'ServerEventNotification';
|
|
110
|
+
}>) => void;
|
|
111
|
+
/**
|
|
112
|
+
* A direct actor-to-actor message addressed specifically to you; `payload`
|
|
113
|
+
* is base64. There is no sender echo, so this only ever arrives on the
|
|
114
|
+
* recipient's subscription.
|
|
115
|
+
*/
|
|
116
|
+
singleActorMessage?: (notification: Extract<UdpNotification, {
|
|
117
|
+
__typename?: 'SingleActorMessageNotification';
|
|
118
|
+
}>) => void;
|
|
119
|
+
/**
|
|
120
|
+
* A message broadcast on a channel (group) you're subscribed to; `payload`
|
|
121
|
+
* is base64 and opaque to the server.
|
|
122
|
+
*/
|
|
123
|
+
channelMessage?: (notification: Extract<UdpNotification, {
|
|
124
|
+
__typename?: 'ChannelMessageNotification';
|
|
125
|
+
}>) => void;
|
|
126
|
+
/**
|
|
127
|
+
* An asynchronous error for a previously sent datagram. Correlate it to the
|
|
128
|
+
* originating send via `sequenceNumber` and read `errorCode`
|
|
129
|
+
* ({@link UdpErrorCode}) for the reason. The matching `...AndWait` promise
|
|
130
|
+
* rejects on this; the handler still fires for observability.
|
|
131
|
+
*/
|
|
132
|
+
genericError?: (notification: Extract<UdpNotification, {
|
|
133
|
+
__typename?: 'GenericErrorResponse';
|
|
134
|
+
}>) => void;
|
|
135
|
+
/**
|
|
136
|
+
* A connection-lifecycle event from the game-api (handshake / auth /
|
|
137
|
+
* routing), carrying `status`, `code`, `message`, and `retryable`. A
|
|
138
|
+
* non-retryable event such as `code: 'APP_ID_REQUIRED'` means the
|
|
139
|
+
* subscription was rejected and will not be retried automatically.
|
|
140
|
+
*/
|
|
141
|
+
connectionEvent?: (notification: Extract<UdpNotification, {
|
|
142
|
+
__typename?: 'RealtimeConnectionEvent';
|
|
143
|
+
}>) => void;
|
|
144
|
+
/**
|
|
145
|
+
* SDK-level realtime failures surfaced as a {@link CrowdyRealtimeError}
|
|
146
|
+
* (socket error, auth token cleared, subscription failed, wait timeout).
|
|
147
|
+
* This is a **client-side** signal, not a server notification.
|
|
148
|
+
*/
|
|
149
|
+
error?: (error: CrowdyRealtimeError) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Catch-all invoked for **every** notification, before the specific typed
|
|
152
|
+
* handler above. Handy for logging, metrics, or custom dispatch.
|
|
153
|
+
*/
|
|
154
|
+
any?: (notification: UdpNotification) => void;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Tuning options for {@link RealtimeClient} (the WebSocket subscription layer),
|
|
158
|
+
* passed through from `CrowdyClient`'s `realtime` config. Every field is
|
|
159
|
+
* optional and has a default.
|
|
160
|
+
*/
|
|
161
|
+
export interface RealtimeConfig {
|
|
162
|
+
/**
|
|
163
|
+
* WebSocket URL of the game-api GraphQL endpoint (e.g.
|
|
164
|
+
* `wss://game.example.com/graphql`). Used when {@link wsEndpoint} is not set;
|
|
165
|
+
* falls back to `ws://localhost:3000/graphql` when both are omitted.
|
|
166
|
+
*/
|
|
167
|
+
wsUrl?: string;
|
|
168
|
+
/** Alias for {@link wsUrl}; used only when {@link wsUrl} is not provided. */
|
|
169
|
+
wsEndpoint?: string;
|
|
170
|
+
/**
|
|
171
|
+
* Maximum number of automatic reconnect attempts after the socket drops
|
|
172
|
+
* before giving up. Defaults to `8`.
|
|
173
|
+
*/
|
|
174
|
+
retryAttempts?: number;
|
|
175
|
+
/**
|
|
176
|
+
* Base delay in **milliseconds** for the exponential reconnect backoff (also
|
|
177
|
+
* the upper bound of the random jitter added to each wait). Defaults to
|
|
178
|
+
* `250`.
|
|
179
|
+
*/
|
|
180
|
+
retryInitialDelayMs?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Ceiling in **milliseconds** for the reconnect backoff, so the delay never
|
|
183
|
+
* grows past this between attempts. Defaults to `5000`.
|
|
184
|
+
*/
|
|
185
|
+
retryMaxDelayMs?: number;
|
|
186
|
+
/**
|
|
187
|
+
* Default time in **milliseconds** a `...AndWait` send waits for its matching
|
|
188
|
+
* echo before timing out (overridable per call via
|
|
189
|
+
* {@link RealtimeClient.waitForSequence}). Defaults to `5000`.
|
|
190
|
+
*/
|
|
191
|
+
waitTimeoutMs?: number;
|
|
192
|
+
/** Optional logger for realtime diagnostics. Defaults to a silent logger. */
|
|
193
|
+
logger?: CrowdyLogger;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Manages the single WebSocket subscription to the game-api's
|
|
197
|
+
* `udpNotifications` stream — the realtime layer behind `client.udp` and
|
|
198
|
+
* `client.realtime`. It opens the socket lazily on the first {@link subscribe},
|
|
199
|
+
* authenticates with the shared session token, scopes the session to one
|
|
200
|
+
* `appId`, reconnects with jittered exponential backoff, re-reads the token and
|
|
201
|
+
* resubscribes on reconnect, fans each notification out to the registered
|
|
202
|
+
* {@link UdpNotificationHandlers}, and resolves `...AndWait` sends via
|
|
203
|
+
* {@link waitForSequence}.
|
|
204
|
+
*
|
|
205
|
+
* The connection lifecycle is observable through {@link status} /
|
|
206
|
+
* {@link onStatus} ({@link RealtimeStatus}). A realtime session is scoped to a
|
|
207
|
+
* single app, so run one client per app (sharing the same token store) for a
|
|
208
|
+
* player who is in multiple apps at once.
|
|
209
|
+
*
|
|
210
|
+
* You normally interact with this through `client.udp` / `client.realtime`
|
|
211
|
+
* rather than constructing it directly.
|
|
212
|
+
*/
|
|
213
|
+
export declare class RealtimeClient {
|
|
214
|
+
private readonly session;
|
|
215
|
+
private readonly wsUrl;
|
|
216
|
+
private readonly logger;
|
|
217
|
+
private readonly retryAttempts;
|
|
218
|
+
private readonly retryInitialDelayMs;
|
|
219
|
+
private readonly retryMaxDelayMs;
|
|
220
|
+
private readonly waitTimeoutMs;
|
|
221
|
+
private client;
|
|
222
|
+
private release;
|
|
223
|
+
private desired;
|
|
224
|
+
private statusValue;
|
|
225
|
+
private readonly statusListeners;
|
|
226
|
+
private readonly subscribers;
|
|
227
|
+
private readonly pending;
|
|
228
|
+
private nextSubscriberId;
|
|
229
|
+
private subscribedAppId;
|
|
230
|
+
/**
|
|
231
|
+
* @param config - Reconnect/timeout/endpoint tuning; see
|
|
232
|
+
* {@link RealtimeConfig}.
|
|
233
|
+
* @param session - Shared session store. The client reads the Bearer token
|
|
234
|
+
* from it for the connection handshake and watches it for changes: clearing
|
|
235
|
+
* the token tears the connection down (emitting an `AUTH_CLEARED`
|
|
236
|
+
* {@link CrowdyRealtimeError}), while a token change made while connected
|
|
237
|
+
* forces a reconnect using the new token.
|
|
238
|
+
*/
|
|
239
|
+
constructor(config: RealtimeConfig | undefined, session: SessionStore);
|
|
240
|
+
/**
|
|
241
|
+
* The current connection state.
|
|
242
|
+
*
|
|
243
|
+
* @returns The latest {@link RealtimeStatus}.
|
|
244
|
+
*/
|
|
245
|
+
status(): RealtimeStatus;
|
|
246
|
+
/**
|
|
247
|
+
* Subscribe to connection-state changes. The listener is invoked
|
|
248
|
+
* **immediately** with the current status, then again on every transition.
|
|
249
|
+
*
|
|
250
|
+
* @param listener - Called with each new {@link RealtimeStatus}.
|
|
251
|
+
* @returns An unsubscribe function that removes the listener.
|
|
252
|
+
*/
|
|
253
|
+
onStatus(listener: (status: RealtimeStatus) => void): () => void;
|
|
254
|
+
/**
|
|
255
|
+
* Mark the connection as desired and open the subscription if it isn't
|
|
256
|
+
* already open. You usually don't call this directly — {@link subscribe}
|
|
257
|
+
* calls it for you; use it (or `client.realtime.connect()`) only to pre-warm
|
|
258
|
+
* the socket.
|
|
259
|
+
*
|
|
260
|
+
* @throws {CrowdyRealtimeError} `AUTH_REQUIRED` if there is no session token.
|
|
261
|
+
*/
|
|
262
|
+
connect(): void;
|
|
263
|
+
/**
|
|
264
|
+
* Close the socket and stop wanting a connection. Outstanding
|
|
265
|
+
* {@link waitForSequence} promises are left intact (they will time out on
|
|
266
|
+
* their own); use {@link close} to also reject those and drop all
|
|
267
|
+
* subscribers. Safe to call when already disconnected.
|
|
268
|
+
*/
|
|
269
|
+
disconnect(): void;
|
|
270
|
+
/**
|
|
271
|
+
* Fully tear down the client: {@link disconnect}, drop all notification
|
|
272
|
+
* subscribers, and reject every outstanding {@link waitForSequence} promise
|
|
273
|
+
* with a non-retryable {@link CrowdyRealtimeError}. Call this when disposing
|
|
274
|
+
* the SDK instance.
|
|
275
|
+
*/
|
|
276
|
+
close(): void;
|
|
277
|
+
/**
|
|
278
|
+
* Register a set of {@link UdpNotificationHandlers} and ensure the realtime
|
|
279
|
+
* connection is open, scoping the session to `appId`. The game-api requires
|
|
280
|
+
* an app id and rejects an app-agnostic subscription with a
|
|
281
|
+
* `RealtimeConnectionEvent` (`code: 'APP_ID_REQUIRED'`).
|
|
282
|
+
*
|
|
283
|
+
* Multiple handler sets can be registered at once; the returned function
|
|
284
|
+
* unregisters this one, and the socket closes automatically once the last
|
|
285
|
+
* subscriber unsubscribes.
|
|
286
|
+
*
|
|
287
|
+
* @param handlers - Callbacks for the notification types you care about.
|
|
288
|
+
* @param appId - The app to scope this realtime session to (decimal id;
|
|
289
|
+
* coerced to a string). Required.
|
|
290
|
+
* @returns An unsubscribe function that removes these handlers (and
|
|
291
|
+
* disconnects when none remain).
|
|
292
|
+
*/
|
|
293
|
+
subscribe(handlers: UdpNotificationHandlers, appId: string): () => void;
|
|
294
|
+
/**
|
|
295
|
+
* Return a promise that resolves when a notification carrying the given
|
|
296
|
+
* `sequenceNumber` arrives — the mechanism behind the `...AndWait` spatial
|
|
297
|
+
* sends. Resolves with the matching {@link SpatialNotification}, or rejects
|
|
298
|
+
* if that match is a `GenericErrorResponse` or the wait times out.
|
|
299
|
+
*
|
|
300
|
+
* @param sequenceNumber - The sequence number to wait for (as allocated by
|
|
301
|
+
* {@link SequenceAllocator} and stamped on the send).
|
|
302
|
+
* @param timeoutMs - How long to wait before rejecting, in milliseconds.
|
|
303
|
+
* Defaults to the configured {@link RealtimeConfig.waitTimeoutMs}.
|
|
304
|
+
* @returns The matching spatial notification.
|
|
305
|
+
* @throws {CrowdyRealtimeError} `UDP_SEQUENCE_TIMEOUT` (retryable) on timeout,
|
|
306
|
+
* or carrying the server `errorCode` when the match is a
|
|
307
|
+
* `GenericErrorResponse`.
|
|
308
|
+
*/
|
|
309
|
+
waitForSequence(sequenceNumber: number, timeoutMs?: number): Promise<SpatialNotification>;
|
|
310
|
+
private ensureSubscription;
|
|
311
|
+
private restart;
|
|
312
|
+
private dispatch;
|
|
313
|
+
private resolvePending;
|
|
314
|
+
private removePending;
|
|
315
|
+
private rejectAllPending;
|
|
316
|
+
private dispatchError;
|
|
317
|
+
private setStatus;
|
|
318
|
+
}
|
|
319
|
+
//# sourceMappingURL=realtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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