@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
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
import {
|
|
2
|
+
// Runtime (player) ops
|
|
3
|
+
GameModelCreateSessionDocument, GameModelJoinSessionDocument, GameModelSetSessionTurnDocument, GameModelCreateContainerDocument, GameModelSetPropertyDocument, GameModelAddEdgeDocument, GameModelInvokeDocument, GameModelContainerDocument, GameModelContainersDocument, GameModelContainerStateDocument, GameModelTraverseDocument, GameModelSessionDocument, GameModelSessionsDocument, GameModelEventsDocument,
|
|
4
|
+
// Studio authoring ops
|
|
5
|
+
GameModelSeedDocument, GameModelUpsertContainerTypeDocument, GameModelUpsertPropertyDefDocument, GameModelUpsertFunctionDocument, GameModelDeleteFunctionDocument, GameModelDefineFeatureDocument, GameModelGrantTierFeatureDocument, GameModelSetPolicyDocument, GameModelTypeSchemaDocument, GameModelContainerTypesDocument, GameModelPropertyDefsDocument, GameModelFunctionDocument, GameModelFunctionsDocument, GameModelFeaturesDocument, GameModelTierFeaturesDocument, GameModelPolicyDocument, GameModelRevokeTierFeatureDocument, GameModelEventsConnectionDocument,
|
|
6
|
+
// Automations (autonomous processes / NPCs)
|
|
7
|
+
GameModelUpsertAutomationDocument, GameModelDeleteAutomationDocument, GameModelSetAutomationEnabledDocument, GameModelUpsertAutomationTriggerDocument, GameModelDeleteAutomationTriggerDocument, GameModelSetAutomationPolicyDocument, GameModelRunAutomationDocument, GameModelAutomationsDocument, GameModelAutomationDocument, GameModelAutomationTriggersDocument, GameModelAutomationPolicyDocument, GameModelAutomationRunsDocument, GameModelAutomationStatsDocument, GameModelAppDiagnosticsDocument, } from '../generated/graphql.js';
|
|
8
|
+
/**
|
|
9
|
+
* Abstract **game-model** sub-client on the **game-api** — a schema-driven,
|
|
10
|
+
* server-authoritative layer for modelling game/world logic on top of the
|
|
11
|
+
* spatial voxel world. Studios *author* the model; players *query* state and
|
|
12
|
+
* *invoke* functions at runtime. Exposed as `client.gameModel`.
|
|
13
|
+
*
|
|
14
|
+
* The model is a typed graph of entities:
|
|
15
|
+
* - **Container types** are the schemas (like classes) for a kind of entity.
|
|
16
|
+
* **Property definitions** are their typed fields, each with a default value,
|
|
17
|
+
* a read **visibility** (`public | owner | hidden`) and a **writability**
|
|
18
|
+
* (`function | owner | admin`). See {@link upsertContainerType} /
|
|
19
|
+
* {@link upsertPropertyDef} / {@link typeSchema}.
|
|
20
|
+
* - **Containers** are the runtime instances of a type, optionally scoped to a
|
|
21
|
+
* session and carrying property values. See {@link createContainer},
|
|
22
|
+
* {@link container}, {@link containers}, {@link containerState}.
|
|
23
|
+
* - **Functions** are named, sandboxed behaviours over containers: typed
|
|
24
|
+
* parameters, declared property **mutations** (expressions compiled to an AST
|
|
25
|
+
* server-side — never `eval`'d), an optional return expression, an
|
|
26
|
+
* `invokeScope` (`player | server | internal`), and an **invoke policy** — an
|
|
27
|
+
* authority rule tree of `owner_of_self`, `is_host`, `is_current_turn`,
|
|
28
|
+
* `is_participant`, `tier_feature`, `group_permission`, `grid_permission`, and
|
|
29
|
+
* `condition` rules. {@link invoke} is the primary, *safe* way for players to
|
|
30
|
+
* mutate state: the server checks the policy, evaluates the expressions,
|
|
31
|
+
* applies the mutations atomically, and logs an **event**.
|
|
32
|
+
* - **Sessions** are isolated instance scopes (a match, room, or save) with
|
|
33
|
+
* **participants**, a creator, and an optional current-**turn** user for
|
|
34
|
+
* turn-based play. See {@link createSession}, {@link joinSession},
|
|
35
|
+
* {@link setSessionTurn}, {@link session}, {@link sessions}.
|
|
36
|
+
* - **Edges** are directed, typed relationships between containers (the model is
|
|
37
|
+
* a graph); {@link traverse} walks them from a root up to a depth. See
|
|
38
|
+
* {@link addEdge}.
|
|
39
|
+
* - **Events** are an audit log of every function invocation and its outcome.
|
|
40
|
+
* See {@link events}.
|
|
41
|
+
* - **App features** are keys functions gate on (via `tier_feature` rules) and
|
|
42
|
+
* that **access tiers** can be granted ({@link defineFeature},
|
|
43
|
+
* {@link grantTierFeature}); **policy** governs who may create sessions and the
|
|
44
|
+
* default participant role ({@link setPolicy}).
|
|
45
|
+
* - {@link seed} bulk-creates definitions *and* instances in one transaction for
|
|
46
|
+
* model init/import.
|
|
47
|
+
*
|
|
48
|
+
* **Encoding.** `BigInt` ids (`appId`, `tierId`, every `*UserId`) are sent and
|
|
49
|
+
* received as decimal **strings**. Container, session, function, edge, and event
|
|
50
|
+
* ids are opaque **UUID strings**. All structured values travel as JSON-encoded
|
|
51
|
+
* strings in the `*Json` fields (`metadataJson`, `propertiesJson`, `paramsJson`,
|
|
52
|
+
* `valueJson`, `returnValueJson`, `invokePolicyJson`, `idMapJson`, …) — callers
|
|
53
|
+
* `JSON.parse` / `JSON.stringify` around them. (Unlike actor/state blobs, these
|
|
54
|
+
* are JSON text, not base64.)
|
|
55
|
+
*
|
|
56
|
+
* **Auth.** Every call requires an authenticated session (a Bearer token set via
|
|
57
|
+
* `client.auth.login()` or `client.setToken()`) scoped to the target app, or it
|
|
58
|
+
* throws {@link CrowdyGraphQLError} (`UNAUTHENTICATED` / `SCOPE_MISSING`). The
|
|
59
|
+
* **studio-authoring** methods ({@link seed}, {@link upsertContainerType},
|
|
60
|
+
* {@link upsertPropertyDef}, {@link upsertFunction}, {@link deleteFunction},
|
|
61
|
+
* {@link defineFeature}, {@link grantTierFeature}, {@link setPolicy}) and the
|
|
62
|
+
* {@link typeSchema} query additionally require the app-admin **`manage_apps`**
|
|
63
|
+
* permission (otherwise `FORBIDDEN`, with `extensions.requiredPermission ===
|
|
64
|
+
* 'manage_apps'`); the runtime/player methods need only a valid token plus
|
|
65
|
+
* whatever per-operation policy applies (session-creation policy, a type's
|
|
66
|
+
* `instantiableBy` rule, a property's `writable` rule, or a function's invoke
|
|
67
|
+
* policy).
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* // Studio authors a type, then a player creates a session and invokes a function.
|
|
72
|
+
* await client.gameModel.upsertContainerType({ appId, typeName: 'Player', displayName: 'Player' });
|
|
73
|
+
* const session = await client.gameModel.createSession({ appId, name: 'Match 1' });
|
|
74
|
+
* const result = await client.gameModel.invoke({
|
|
75
|
+
* appId,
|
|
76
|
+
* functionName: 'takeDamage',
|
|
77
|
+
* selfContainerId,
|
|
78
|
+
* paramsJson: JSON.stringify({ amount: 10 }),
|
|
79
|
+
* });
|
|
80
|
+
* if (!result.success) console.warn(result.errorMessage); // authority/eval failures don't throw
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export class GameModelAPI {
|
|
84
|
+
constructor(gql) {
|
|
85
|
+
this.gql = gql;
|
|
86
|
+
}
|
|
87
|
+
// -- Runtime (player) -------------------------------------------------------
|
|
88
|
+
/**
|
|
89
|
+
* **Sessions** — create a runtime session: an isolated instance scope for
|
|
90
|
+
* containers (e.g. a match, room, or save). Subject to the app's
|
|
91
|
+
* session-creation policy ({@link setPolicy}); the caller becomes the creator
|
|
92
|
+
* and a participant.
|
|
93
|
+
*
|
|
94
|
+
* @param input - {@link CreateSessionInput}: `appId` (decimal string), an
|
|
95
|
+
* optional `name`, optional `metadataJson` (a JSON-object string), and
|
|
96
|
+
* optional `participantUserIds` (decimal-string ids of initial participants
|
|
97
|
+
* besides the creator).
|
|
98
|
+
* @returns The created {@link GmSession} (`sessionId`, `status`, creator,
|
|
99
|
+
* current turn, metadata, …).
|
|
100
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING` if the token
|
|
101
|
+
* is missing or not scoped to the app, `FORBIDDEN` if the session-creation
|
|
102
|
+
* policy disallows the caller, or `BAD_USER_INPUT` for malformed input.
|
|
103
|
+
*/
|
|
104
|
+
async createSession(input) {
|
|
105
|
+
const data = await this.gql.request(GameModelCreateSessionDocument, { input });
|
|
106
|
+
return data.gameModelCreateSession;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* **Sessions** — join an existing session as a participant, optionally with a
|
|
110
|
+
* role. Requires a valid token and access to the app.
|
|
111
|
+
*
|
|
112
|
+
* @param input - {@link JoinSessionInput}: `appId` (decimal string),
|
|
113
|
+
* `sessionId`, and an optional participant `role`.
|
|
114
|
+
* @returns The {@link GmSessionParticipant} record (`sessionId`, `userId`,
|
|
115
|
+
* `role`).
|
|
116
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
117
|
+
* `NOT_FOUND` if no such session, or `FORBIDDEN` if joining isn't permitted.
|
|
118
|
+
*/
|
|
119
|
+
async joinSession(input) {
|
|
120
|
+
const data = await this.gql.request(GameModelJoinSessionDocument, { input });
|
|
121
|
+
return data.gameModelJoinSession;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* **Sessions** — set or clear the session's current-turn user, for turn-based
|
|
125
|
+
* play (turn authority is enforced by the service).
|
|
126
|
+
*
|
|
127
|
+
* @param input - {@link SetSessionTurnInput}: `appId` (decimal string),
|
|
128
|
+
* `sessionId`, and `userId` (the decimal-string id of the user whose turn it
|
|
129
|
+
* now is) — pass `userId: null` to **clear** the turn.
|
|
130
|
+
* @returns The updated {@link GmSession} (with `currentTurnUserId` reflecting
|
|
131
|
+
* the change).
|
|
132
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
133
|
+
* `NOT_FOUND` if the session doesn't exist, or `FORBIDDEN` if the caller may
|
|
134
|
+
* not change the turn.
|
|
135
|
+
*/
|
|
136
|
+
async setSessionTurn(input) {
|
|
137
|
+
const data = await this.gql.request(GameModelSetSessionTurnDocument, { input });
|
|
138
|
+
return data.gameModelSetSessionTurn;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* **Containers** — instantiate a container (a runtime entity of a given type),
|
|
142
|
+
* optionally within a session, with an owner and initial property values.
|
|
143
|
+
* Subject to the type's `instantiableBy` rule (`admin | member | owner`).
|
|
144
|
+
*
|
|
145
|
+
* @param input - {@link CreateContainerInput}: `appId` (decimal string), an
|
|
146
|
+
* optional `sessionId` (omit for an app-global container), the `typeName` to
|
|
147
|
+
* instantiate, a `displayName`, optional `description`, optional
|
|
148
|
+
* `ownerUserId` (decimal string; defaults to the caller for member/owner
|
|
149
|
+
* instantiation), optional `metadataJson` (JSON-object string), and optional
|
|
150
|
+
* initial `properties` (each `{ key, valueType, valueJson }` with a
|
|
151
|
+
* JSON-encoded value).
|
|
152
|
+
* @returns The created {@link GmContainer}.
|
|
153
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
154
|
+
* `FORBIDDEN` if `instantiableBy` disallows the caller, `NOT_FOUND` for an
|
|
155
|
+
* unknown type, or `BAD_USER_INPUT` for malformed properties.
|
|
156
|
+
*/
|
|
157
|
+
async createContainer(input) {
|
|
158
|
+
const data = await this.gql.request(GameModelCreateContainerDocument, { input });
|
|
159
|
+
return data.gameModelCreateContainer;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* **Containers** — set a single property value on a container directly (outside
|
|
163
|
+
* a function). Allowed only when the property's `writable` rule
|
|
164
|
+
* (`function | owner | admin`) permits the caller; the value is JSON-encoded
|
|
165
|
+
* and coerced to the property's declared value type. For game-logic changes
|
|
166
|
+
* prefer {@link invoke}, which enforces an authority policy and logs an event.
|
|
167
|
+
*
|
|
168
|
+
* @param input - {@link SetContainerPropertyInput}: `appId` (decimal string),
|
|
169
|
+
* `containerId`, the property `key`, its `valueType` (must match the property
|
|
170
|
+
* definition), and `valueJson` (the JSON-encoded value to write).
|
|
171
|
+
* @returns The updated {@link GmContainer}.
|
|
172
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
173
|
+
* `FORBIDDEN` if the property's `writable` rule forbids a direct write,
|
|
174
|
+
* `NOT_FOUND` for an unknown container/property, or `BAD_USER_INPUT` for a
|
|
175
|
+
* value-type mismatch.
|
|
176
|
+
*/
|
|
177
|
+
async setProperty(input) {
|
|
178
|
+
const data = await this.gql.request(GameModelSetPropertyDocument, { input });
|
|
179
|
+
return data.gameModelSetProperty;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* **Edges** — create a directed relationship edge between two containers (the
|
|
183
|
+
* game model is a graph), with a relationship type and optional weight.
|
|
184
|
+
*
|
|
185
|
+
* @param input - {@link AddEdgeInput}: `appId` (decimal string),
|
|
186
|
+
* `fromContainerId` (source) and `toContainerId` (target), a
|
|
187
|
+
* `relationshipType` label, an optional numeric `weight`, and optional
|
|
188
|
+
* `metadataJson` (JSON-object string).
|
|
189
|
+
* @returns The created {@link GmEdge} (`edgeId`, endpoints, type, weight).
|
|
190
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
191
|
+
* `NOT_FOUND` if either container is unknown, or `BAD_USER_INPUT`.
|
|
192
|
+
*/
|
|
193
|
+
async addEdge(input) {
|
|
194
|
+
const data = await this.gql.request(GameModelAddEdgeDocument, { input });
|
|
195
|
+
return data.gameModelAddEdge;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* **Functions** — invoke a studio-defined function against a `self` container
|
|
199
|
+
* with JSON params. This is the primary, *safe* way for players to mutate game
|
|
200
|
+
* state: the server enforces the function's invoke policy (the authority rule
|
|
201
|
+
* tree — `owner_of_self` / `is_host` / `is_current_turn` / `is_participant` /
|
|
202
|
+
* `tier_feature` / `group_permission` / `grid_permission` / `condition`),
|
|
203
|
+
* evaluates its expressions, atomically applies its declared property
|
|
204
|
+
* mutations, and logs an {@link events | event}. Only `player`-scope functions
|
|
205
|
+
* are invocable here.
|
|
206
|
+
*
|
|
207
|
+
* Note: an authority denial or an expression-evaluation error is **not** a
|
|
208
|
+
* thrown exception — it comes back as a resolved result with `success: false`
|
|
209
|
+
* and an `errorMessage`. Inspect `result.success` rather than relying on
|
|
210
|
+
* `try/catch` for those cases.
|
|
211
|
+
*
|
|
212
|
+
* @param input - {@link InvokeFunctionInput}: `appId` (decimal string), the
|
|
213
|
+
* `functionName`, the `selfContainerId` (the container the function runs
|
|
214
|
+
* against, referenced as `self` in expressions), an optional `sessionId`
|
|
215
|
+
* context, and `paramsJson` (a JSON-object string of params).
|
|
216
|
+
* @returns A {@link GmInvokeResult}: `success`, the logged `eventId`, the
|
|
217
|
+
* JSON-encoded `returnValueJson`, the `mutationsApplied` (each with
|
|
218
|
+
* before/after JSON values), and `errorMessage` when `success` is `false`.
|
|
219
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
220
|
+
* `NOT_FOUND` for an unknown function/container, `FORBIDDEN` if the function
|
|
221
|
+
* isn't `player`-scope, or `BAD_USER_INPUT` for malformed params. (Authority
|
|
222
|
+
* and evaluation failures surface as `success: false`, see above.)
|
|
223
|
+
*/
|
|
224
|
+
async invoke(input) {
|
|
225
|
+
const data = await this.gql.request(GameModelInvokeDocument, { input });
|
|
226
|
+
return data.gameModelInvoke;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* **Containers** — fetch one container (instance) by id, with its full record
|
|
230
|
+
* (unfiltered metadata). For a player-facing view whose property values are
|
|
231
|
+
* filtered to what the caller may see, use {@link containerState} instead.
|
|
232
|
+
*
|
|
233
|
+
* @param variables - `{ appId, containerId }`: `appId` (decimal string) is the
|
|
234
|
+
* owning app and `containerId` is the container UUID to fetch.
|
|
235
|
+
* @returns The {@link GmContainer}.
|
|
236
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`, or
|
|
237
|
+
* `NOT_FOUND` if no such container.
|
|
238
|
+
*/
|
|
239
|
+
async container(variables) {
|
|
240
|
+
const data = await this.gql.request(GameModelContainerDocument, variables);
|
|
241
|
+
return data.gameModelContainer;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* **Containers** — list containers in an app, optionally narrowed by container
|
|
245
|
+
* type and/or session.
|
|
246
|
+
*
|
|
247
|
+
* @param variables - `{ appId, typeName?, sessionId? }`: `appId` (decimal
|
|
248
|
+
* string); optional `typeName` (omit for all types); optional `sessionId`
|
|
249
|
+
* (omit for all containers, including app-global ones).
|
|
250
|
+
* @returns The matching {@link GmContainer}s.
|
|
251
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`.
|
|
252
|
+
*/
|
|
253
|
+
async containers(variables) {
|
|
254
|
+
const data = await this.gql.request(GameModelContainersDocument, variables);
|
|
255
|
+
return data.gameModelContainers;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* **Containers** — fetch a container together with its property values
|
|
259
|
+
* filtered to what the **calling** user is allowed to see (`public` always;
|
|
260
|
+
* `owner`/`hidden` depend on the caller's relationship to the container). Use
|
|
261
|
+
* this for a player-facing view of an entity.
|
|
262
|
+
*
|
|
263
|
+
* @param variables - `{ appId, containerId }`: `appId` (decimal string) and
|
|
264
|
+
* the `containerId` UUID whose visible state to fetch.
|
|
265
|
+
* @returns A {@link GmContainerState}; its `propertiesJson` is a JSON-object
|
|
266
|
+
* string of the properties visible to the caller (`JSON.parse` it).
|
|
267
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`, or
|
|
268
|
+
* `NOT_FOUND` if no such container.
|
|
269
|
+
*/
|
|
270
|
+
async containerState(variables) {
|
|
271
|
+
const data = await this.gql.request(GameModelContainerStateDocument, variables);
|
|
272
|
+
return data.gameModelContainerState;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* **Edges** — traverse the container graph from a root container along a
|
|
276
|
+
* relationship type up to a given depth, returning the reachable nodes and the
|
|
277
|
+
* edges between them.
|
|
278
|
+
*
|
|
279
|
+
* @param variables - `{ appId, rootId, relationshipType, depth? }`: `appId`
|
|
280
|
+
* (decimal string); the `rootId` container UUID to start from; the
|
|
281
|
+
* `relationshipType` edge label to follow; and optional `depth`, the number
|
|
282
|
+
* of edge hops to follow from the root (defaults to `1`).
|
|
283
|
+
* @returns A {@link GmTraverseResult}: the `rootId`, the reachable `nodes`
|
|
284
|
+
* ({@link GmContainer}[]), and the traversed `edges` ({@link GmEdge}[]).
|
|
285
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`, or
|
|
286
|
+
* `NOT_FOUND` if the root container is unknown.
|
|
287
|
+
*/
|
|
288
|
+
async traverse(variables) {
|
|
289
|
+
const data = await this.gql.request(GameModelTraverseDocument, variables);
|
|
290
|
+
return data.gameModelTraverse;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* **Sessions** — fetch one session by id.
|
|
294
|
+
*
|
|
295
|
+
* @param variables - `{ appId, sessionId }`: `appId` (decimal string) and the
|
|
296
|
+
* `sessionId` to fetch.
|
|
297
|
+
* @returns The {@link GmSession}.
|
|
298
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`, or
|
|
299
|
+
* `NOT_FOUND` if no such session.
|
|
300
|
+
*/
|
|
301
|
+
async session(variables) {
|
|
302
|
+
const data = await this.gql.request(GameModelSessionDocument, variables);
|
|
303
|
+
return data.gameModelSession;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* **Sessions** — list sessions in an app, optionally filtered by status.
|
|
307
|
+
*
|
|
308
|
+
* @param variables - `{ appId, status? }`: `appId` (decimal string) and an
|
|
309
|
+
* optional `status` filter (e.g. `'active'`; omit for all statuses).
|
|
310
|
+
* @returns The matching {@link GmSession}s.
|
|
311
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`.
|
|
312
|
+
*/
|
|
313
|
+
async sessions(variables) {
|
|
314
|
+
const data = await this.gql.request(GameModelSessionsDocument, variables);
|
|
315
|
+
return data.gameModelSessions;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* **Events** — query the function-invocation event log (audit trail) with
|
|
319
|
+
* optional filters and pagination. Useful for debugging functions or showing
|
|
320
|
+
* recent activity.
|
|
321
|
+
*
|
|
322
|
+
* @param variables - `{ appId, sessionId?, selfContainerId?, functionName?,
|
|
323
|
+
* success?, limit?, offset? }`: `appId` (decimal string); optional
|
|
324
|
+
* `sessionId`; optional `selfContainerId` (the UUID the function ran
|
|
325
|
+
* against); optional `functionName`; optional `success` (`true` = succeeded,
|
|
326
|
+
* `false` = failed). `limit` (page size) and `offset` (rows to skip) are
|
|
327
|
+
* **deprecated** — see below.
|
|
328
|
+
* @returns The matching {@link GmEvent}s (each with `paramsJson`,
|
|
329
|
+
* `mutationsAppliedJson`, `returnValueJson`, `success`, `errorMessage`, and
|
|
330
|
+
* `executedAt`).
|
|
331
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`.
|
|
332
|
+
* @remarks The `limit`/`offset` fields use deprecated offset pagination. For
|
|
333
|
+
* large logs prefer the Relay-style `gameModelEventsConnection(first:, after:)`
|
|
334
|
+
* cursor query (available on the schema via `client.graphql`). See
|
|
335
|
+
* https://docs.crowdedkingdoms.com/overview/pagination.
|
|
336
|
+
*/
|
|
337
|
+
async events(variables) {
|
|
338
|
+
const data = await this.gql.request(GameModelEventsDocument, variables);
|
|
339
|
+
return data.gameModelEvents;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* **Events** — Relay-style cursor pagination over the function-invocation
|
|
343
|
+
* event log; the preferred alternative to {@link events} for large logs. Page
|
|
344
|
+
* with `first` plus the previous page's `pageInfo.endCursor` as `after`. See
|
|
345
|
+
* https://docs.crowdedkingdoms.com/overview/pagination.
|
|
346
|
+
*
|
|
347
|
+
* @param variables - `{ appId, first?, after?, sessionId?, selfContainerId?,
|
|
348
|
+
* functionName?, success? }`.
|
|
349
|
+
* @returns A {@link GameModelEventsConnection} (`edges { cursor node }`,
|
|
350
|
+
* `pageInfo`, `totalCount`).
|
|
351
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`.
|
|
352
|
+
*/
|
|
353
|
+
async eventsConnection(variables) {
|
|
354
|
+
const data = await this.gql.request(GameModelEventsConnectionDocument, variables);
|
|
355
|
+
return data.gameModelEventsConnection;
|
|
356
|
+
}
|
|
357
|
+
// -- Studio authoring -------------------------------------------------------
|
|
358
|
+
/**
|
|
359
|
+
* **Seed** — bulk-create game-model definitions (container types, property
|
|
360
|
+
* defs, functions) and optionally instances (containers + edges) in one
|
|
361
|
+
* transaction; used to initialize or import a model.
|
|
362
|
+
*
|
|
363
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
364
|
+
*
|
|
365
|
+
* @param input - {@link SeedGameModelInput}: `appId` (decimal string); an
|
|
366
|
+
* optional `sessionId` to seed instances into (omit/`null` = app-global);
|
|
367
|
+
* and arrays of `containerTypes`, `propertyDefinitions`, `functions`,
|
|
368
|
+
* `containers`, and `edges` to create. Seed containers carry a developer
|
|
369
|
+
* `tempId`; seed edges reference containers by those temp ids
|
|
370
|
+
* (`fromTempId`/`toTempId`).
|
|
371
|
+
* @returns A {@link GmSeedResult}: the counts created, non-fatal `warnings`,
|
|
372
|
+
* and `idMapJson` — a JSON-object string mapping each seed `tempId` to the
|
|
373
|
+
* created container UUID (`JSON.parse` it to wire up follow-up calls).
|
|
374
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
375
|
+
* `FORBIDDEN` (with `extensions.requiredPermission === 'manage_apps'`) if the
|
|
376
|
+
* caller lacks app-admin, or `BAD_USER_INPUT` for malformed definitions.
|
|
377
|
+
*/
|
|
378
|
+
async seed(input) {
|
|
379
|
+
const data = await this.gql.request(GameModelSeedDocument, { input });
|
|
380
|
+
return data.gameModelSeed;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* **Container types** — create or update a container type: the studio-defined
|
|
384
|
+
* schema for a kind of runtime entity (like a class). Idempotent on
|
|
385
|
+
* `(appId, typeName)`.
|
|
386
|
+
*
|
|
387
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
388
|
+
*
|
|
389
|
+
* @param input - {@link UpsertContainerTypeInput}: `appId` (decimal string);
|
|
390
|
+
* the `typeName` (the stable upsert key, unique per app); a `displayName`;
|
|
391
|
+
* optional `description`; optional `instantiableBy` (`admin | member |
|
|
392
|
+
* owner`); optional `defaultPropertyVisibility` (`public | owner | hidden`);
|
|
393
|
+
* and optional `metadataJson` (JSON-object string).
|
|
394
|
+
* @returns The upserted {@link GmContainerType}.
|
|
395
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
396
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `BAD_USER_INPUT`.
|
|
397
|
+
*/
|
|
398
|
+
async upsertContainerType(input) {
|
|
399
|
+
const data = await this.gql.request(GameModelUpsertContainerTypeDocument, { input });
|
|
400
|
+
return data.gameModelUpsertContainerType;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* **Property definitions** — create or update a typed property on a container
|
|
404
|
+
* type (a field with a default value, read visibility, and writability).
|
|
405
|
+
* Idempotent on `(appId, containerTypeName, key)`.
|
|
406
|
+
*
|
|
407
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
408
|
+
*
|
|
409
|
+
* @param input - {@link UpsertPropertyDefInput}: `appId` (decimal string); the
|
|
410
|
+
* `containerTypeName` to define on; the property `key` (part of the upsert
|
|
411
|
+
* key); a `valueType` (`int | float | string | bool | array | object |
|
|
412
|
+
* container_ref`); optional `defaultValueJson` (JSON-encoded default);
|
|
413
|
+
* optional `visibility` (`public | owner | hidden`); optional `writable`
|
|
414
|
+
* (`function | owner | admin`); and optional `description`.
|
|
415
|
+
* @returns The upserted {@link GmPropertyDef}.
|
|
416
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
417
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), `NOT_FOUND` for an
|
|
418
|
+
* unknown container type, or `BAD_USER_INPUT`.
|
|
419
|
+
*/
|
|
420
|
+
async upsertPropertyDef(input) {
|
|
421
|
+
const data = await this.gql.request(GameModelUpsertPropertyDefDocument, { input });
|
|
422
|
+
return data.gameModelUpsertPropertyDef;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* **Functions** — create or update a studio-defined function: a named,
|
|
426
|
+
* sandboxed behaviour with typed parameters, declared property mutations
|
|
427
|
+
* (expressions compiled to an AST server-side — never `eval`'d), an optional
|
|
428
|
+
* return expression, an invoke scope, and an invoke policy (authority rule
|
|
429
|
+
* tree). Idempotent on `(appId, name)`. Players run these via {@link invoke}.
|
|
430
|
+
*
|
|
431
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
432
|
+
*
|
|
433
|
+
* @param input - {@link UpsertFunctionInput}: `appId` (decimal string); the
|
|
434
|
+
* `name` (upsert key, used to invoke it); optional `containerTypeName` to
|
|
435
|
+
* bind to (omit for a global function); optional `description`; optional
|
|
436
|
+
* `returnType`; `parameters` (typed `{ name, valueType, required?,
|
|
437
|
+
* defaultValueJson?, … }`); `mutations` (declared writes `{ target, property,
|
|
438
|
+
* expression }`, applied atomically); optional `returnExpression`;
|
|
439
|
+
* `invokeScope` (`player | server | internal`); and `invokePolicyJson` (a
|
|
440
|
+
* JSON-encoded authority rule tree).
|
|
441
|
+
* @returns The upserted {@link GmFunction}, including any non-fatal
|
|
442
|
+
* static-analysis `warnings` from this upload.
|
|
443
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
444
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `BAD_USER_INPUT`
|
|
445
|
+
* for an expression/policy that fails to compile.
|
|
446
|
+
*/
|
|
447
|
+
async upsertFunction(input) {
|
|
448
|
+
const data = await this.gql.request(GameModelUpsertFunctionDocument, { input });
|
|
449
|
+
return data.gameModelUpsertFunction;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* **Functions** — delete a studio-defined function by name. **Destructive.**
|
|
453
|
+
*
|
|
454
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
455
|
+
*
|
|
456
|
+
* @param variables - `{ appId, name }`: `appId` (decimal string) and the
|
|
457
|
+
* function `name` to delete.
|
|
458
|
+
* @returns `true` if a function was deleted, `false` if none matched.
|
|
459
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`, or
|
|
460
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`) if the caller lacks
|
|
461
|
+
* app-admin.
|
|
462
|
+
*/
|
|
463
|
+
async deleteFunction(variables) {
|
|
464
|
+
const data = await this.gql.request(GameModelDeleteFunctionDocument, variables);
|
|
465
|
+
return data.gameModelDeleteFunction;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* **App features** — define an app feature key that functions can gate on (via
|
|
469
|
+
* a `tier_feature` authority rule) and that access tiers can be granted.
|
|
470
|
+
* Idempotent on `(appId, featureKey)`.
|
|
471
|
+
*
|
|
472
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
473
|
+
*
|
|
474
|
+
* @param input - {@link DefineAppFeatureInput}: `appId` (decimal string); the
|
|
475
|
+
* `featureKey` (referenced by `tier_feature` rules); and an optional
|
|
476
|
+
* `description`.
|
|
477
|
+
* @returns The defined {@link GmAppFeature}.
|
|
478
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
479
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `BAD_USER_INPUT`.
|
|
480
|
+
*/
|
|
481
|
+
async defineFeature(input) {
|
|
482
|
+
const data = await this.gql.request(GameModelDefineFeatureDocument, { input });
|
|
483
|
+
return data.gameModelDefineFeature;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* **App features** — grant a feature key to an access tier, so users on that
|
|
487
|
+
* tier satisfy `tier_feature` authority checks for it.
|
|
488
|
+
*
|
|
489
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
490
|
+
*
|
|
491
|
+
* @param input - {@link GrantTierFeatureInput}: `appId` (decimal string); the
|
|
492
|
+
* `tierId` (decimal string) of the access tier; and the `featureKey` to
|
|
493
|
+
* grant to that tier.
|
|
494
|
+
* @returns The {@link GmTierFeature} grant record.
|
|
495
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
496
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `NOT_FOUND` for an
|
|
497
|
+
* unknown tier/feature.
|
|
498
|
+
*/
|
|
499
|
+
async grantTierFeature(input) {
|
|
500
|
+
const data = await this.gql.request(GameModelGrantTierFeatureDocument, { input });
|
|
501
|
+
return data.gameModelGrantTierFeature;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* **Policy** — set the app's game-model runtime policy: who may create
|
|
505
|
+
* sessions and the default role assigned to new session participants.
|
|
506
|
+
*
|
|
507
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
508
|
+
*
|
|
509
|
+
* @param input - {@link SetGameModelPolicyInput}: `appId` (decimal string); an
|
|
510
|
+
* optional `sessionCreationPolicy` (`admin | member | anyone`); and an
|
|
511
|
+
* optional `defaultParticipantRole`.
|
|
512
|
+
* @returns The updated {@link GmAppPolicy}.
|
|
513
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
514
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `BAD_USER_INPUT`.
|
|
515
|
+
*/
|
|
516
|
+
async setPolicy(input) {
|
|
517
|
+
const data = await this.gql.request(GameModelSetPolicyDocument, { input });
|
|
518
|
+
return data.gameModelSetPolicy;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* **Container types** — fetch a container type's full schema: its property
|
|
522
|
+
* definitions plus the functions available on it. A studio/authoring read.
|
|
523
|
+
*
|
|
524
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
525
|
+
*
|
|
526
|
+
* @param variables - `{ appId, typeName }`: `appId` (decimal string) and the
|
|
527
|
+
* `typeName` whose schema to fetch.
|
|
528
|
+
* @returns A {@link GmTypeSchema}: the `typeName`, its `propertyDefinitions`
|
|
529
|
+
* ({@link GmPropertyDef}[]), and its `functions` ({@link GmFunction}[]).
|
|
530
|
+
* @throws {CrowdyGraphQLError} `UNAUTHENTICATED` / `SCOPE_MISSING`,
|
|
531
|
+
* `FORBIDDEN` (`requiredPermission === 'manage_apps'`), or `NOT_FOUND` for an
|
|
532
|
+
* unknown type.
|
|
533
|
+
*/
|
|
534
|
+
async typeSchema(variables) {
|
|
535
|
+
const data = await this.gql.request(GameModelTypeSchemaDocument, variables);
|
|
536
|
+
return data.gameModelTypeSchema;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* **Container types** — list every container type defined for an app. A
|
|
540
|
+
* studio/authoring read. Requires the app-admin **`manage_apps`** permission.
|
|
541
|
+
*
|
|
542
|
+
* @param variables - `{ appId }`.
|
|
543
|
+
* @returns The app's {@link GmContainerType}s.
|
|
544
|
+
*/
|
|
545
|
+
async containerTypes(variables) {
|
|
546
|
+
const data = await this.gql.request(GameModelContainerTypesDocument, variables);
|
|
547
|
+
return data.gameModelContainerTypes;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* **Property definitions** — list the property definitions for one container
|
|
551
|
+
* type. A studio/authoring read. Requires the app-admin **`manage_apps`**
|
|
552
|
+
* permission.
|
|
553
|
+
*
|
|
554
|
+
* @param variables - `{ appId, typeName }`.
|
|
555
|
+
* @returns The type's {@link GmPropertyDef}s.
|
|
556
|
+
*/
|
|
557
|
+
async propertyDefs(variables) {
|
|
558
|
+
const data = await this.gql.request(GameModelPropertyDefsDocument, variables);
|
|
559
|
+
return data.gameModelPropertyDefs;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* **Functions** — fetch one studio-defined function by name (including its
|
|
563
|
+
* parameters, mutations, and notification effects). Requires the app-admin
|
|
564
|
+
* **`manage_apps`** permission.
|
|
565
|
+
*
|
|
566
|
+
* @param variables - `{ appId, name }`.
|
|
567
|
+
* @returns The {@link GmFunction}.
|
|
568
|
+
*/
|
|
569
|
+
async getFunction(variables) {
|
|
570
|
+
const data = await this.gql.request(GameModelFunctionDocument, variables);
|
|
571
|
+
return data.gameModelFunction;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* **Functions** — list studio-defined functions for an app, optionally
|
|
575
|
+
* filtered to those bound to a container type. Requires the app-admin
|
|
576
|
+
* **`manage_apps`** permission.
|
|
577
|
+
*
|
|
578
|
+
* @param variables - `{ appId, containerTypeName? }`.
|
|
579
|
+
* @returns The matching {@link GmFunction}s.
|
|
580
|
+
*/
|
|
581
|
+
async functions(variables) {
|
|
582
|
+
const data = await this.gql.request(GameModelFunctionsDocument, variables);
|
|
583
|
+
return data.gameModelFunctions;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* **App features** — list the feature keys defined for an app. Requires the
|
|
587
|
+
* app-admin **`manage_apps`** permission.
|
|
588
|
+
*
|
|
589
|
+
* @param variables - `{ appId }`.
|
|
590
|
+
* @returns The app's {@link GmAppFeature}s.
|
|
591
|
+
*/
|
|
592
|
+
async features(variables) {
|
|
593
|
+
const data = await this.gql.request(GameModelFeaturesDocument, variables);
|
|
594
|
+
return data.gameModelFeatures;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* **App features** — list tier→feature grants for an app, optionally filtered
|
|
598
|
+
* to one tier. Requires the app-admin **`manage_apps`** permission.
|
|
599
|
+
*
|
|
600
|
+
* @param variables - `{ appId, tierId? }`.
|
|
601
|
+
* @returns The {@link GmTierFeature} grants.
|
|
602
|
+
*/
|
|
603
|
+
async tierFeatures(variables) {
|
|
604
|
+
const data = await this.gql.request(GameModelTierFeaturesDocument, variables);
|
|
605
|
+
return data.gameModelTierFeatures;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* **App features** — revoke a feature key from an access tier (the inverse of
|
|
609
|
+
* {@link grantTierFeature}). Requires the app-admin **`manage_apps`**
|
|
610
|
+
* permission.
|
|
611
|
+
*
|
|
612
|
+
* @param input - {@link GrantTierFeatureInput} (`appId`, `tierId`, `featureKey`).
|
|
613
|
+
* @returns `true` if a grant was removed.
|
|
614
|
+
*/
|
|
615
|
+
async revokeTierFeature(input) {
|
|
616
|
+
const data = await this.gql.request(GameModelRevokeTierFeatureDocument, {
|
|
617
|
+
input,
|
|
618
|
+
});
|
|
619
|
+
return data.gameModelRevokeTierFeature;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* **Policy** — read the app's game-model runtime policy (session-creation
|
|
623
|
+
* policy + default participant role). Requires the app-admin **`manage_apps`**
|
|
624
|
+
* permission.
|
|
625
|
+
*
|
|
626
|
+
* @param variables - `{ appId }`.
|
|
627
|
+
* @returns The {@link GmAppPolicy}.
|
|
628
|
+
*/
|
|
629
|
+
async policy(variables) {
|
|
630
|
+
const data = await this.gql.request(GameModelPolicyDocument, variables);
|
|
631
|
+
return data.gameModelPolicy;
|
|
632
|
+
}
|
|
633
|
+
// -- Automations (autonomous processes / NPCs) ------------------------------
|
|
634
|
+
/**
|
|
635
|
+
* **Automations** — create or update an autonomous process ("automation" /
|
|
636
|
+
* NPC): a server-driven entry-point function bound to a trigger
|
|
637
|
+
* (`schedule | event | manual`), an optional run-as identity, a target/
|
|
638
|
+
* candidate selector, and a per-automation safety budget. The entry-point
|
|
639
|
+
* function must be marked `autonomousInvocable` (see {@link upsertFunction}).
|
|
640
|
+
* Idempotent on `(appId, name)`. The game-api dispatcher runs it headlessly;
|
|
641
|
+
* a tick is just "invoke a function on behalf of the server".
|
|
642
|
+
*
|
|
643
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
644
|
+
*
|
|
645
|
+
* @param input - {@link UpsertAutomationInput}: `appId`; `name` (upsert key);
|
|
646
|
+
* `functionName`; `targetMode` (`container | type | global`) with
|
|
647
|
+
* `selfContainerId` / `targetTypeName`; optional `sessionId`, `paramsJson`,
|
|
648
|
+
* `selectorJson` (model-data candidate selection), `runAsUserId`; the trigger
|
|
649
|
+
* (`triggerType`, `scheduleKind`, `intervalMs` / `cronExpr`); and the safety
|
|
650
|
+
* budget (`maxTargets`, `maxFnDepth`, `gasLimit`, `runTimeoutMs`,
|
|
651
|
+
* `maxRunsPerMinute`, `failureThreshold`, `cooldownMs`).
|
|
652
|
+
* @returns The upserted {@link GmAutomation}, including circuit-breaker state.
|
|
653
|
+
*/
|
|
654
|
+
async upsertAutomation(input) {
|
|
655
|
+
const data = await this.gql.request(GameModelUpsertAutomationDocument, { input });
|
|
656
|
+
return data.gameModelUpsertAutomation;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* **Automations** — delete an automation by name (also removes its event
|
|
660
|
+
* triggers). **Destructive.** Requires the app-admin **`manage_apps`**
|
|
661
|
+
* permission.
|
|
662
|
+
*
|
|
663
|
+
* @param variables - `{ appId, name }`.
|
|
664
|
+
* @returns `true` if one was deleted.
|
|
665
|
+
*/
|
|
666
|
+
async deleteAutomation(variables) {
|
|
667
|
+
const data = await this.gql.request(GameModelDeleteAutomationDocument, variables);
|
|
668
|
+
return data.gameModelDeleteAutomation;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* **Automations** — enable or disable an automation. Re-enabling also resets
|
|
672
|
+
* its circuit breaker so a tripped automation resumes. Requires the app-admin
|
|
673
|
+
* **`manage_apps`** permission.
|
|
674
|
+
*
|
|
675
|
+
* @param variables - `{ appId, name, enabled }`.
|
|
676
|
+
* @returns The updated {@link GmAutomation}.
|
|
677
|
+
*/
|
|
678
|
+
async setAutomationEnabled(variables) {
|
|
679
|
+
const data = await this.gql.request(GameModelSetAutomationEnabledDocument, variables);
|
|
680
|
+
return data.gameModelSetAutomationEnabled;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* **Automations** — create an event trigger that fires an automation in
|
|
684
|
+
* reaction to model activity (`function_invoked` | `property_changed` |
|
|
685
|
+
* `container_created`), matched in the API server post-commit. Requires the
|
|
686
|
+
* app-admin **`manage_apps`** permission.
|
|
687
|
+
*
|
|
688
|
+
* @param input - {@link UpsertAutomationTriggerInput}: `appId`,
|
|
689
|
+
* `automationName`, `onEvent`, optional `functionName` /
|
|
690
|
+
* `containerTypeName` / `propertyKey` filters, and `debounceMs`.
|
|
691
|
+
* @returns The created {@link GmAutomationTrigger}.
|
|
692
|
+
*/
|
|
693
|
+
async upsertAutomationTrigger(input) {
|
|
694
|
+
const data = await this.gql.request(GameModelUpsertAutomationTriggerDocument, { input });
|
|
695
|
+
return data.gameModelUpsertAutomationTrigger;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* **Automations** — delete an event trigger by id. Requires the app-admin
|
|
699
|
+
* **`manage_apps`** permission.
|
|
700
|
+
*
|
|
701
|
+
* @param variables - `{ appId, triggerId }`.
|
|
702
|
+
* @returns `true` if one was deleted.
|
|
703
|
+
*/
|
|
704
|
+
async deleteAutomationTrigger(variables) {
|
|
705
|
+
const data = await this.gql.request(GameModelDeleteAutomationTriggerDocument, variables);
|
|
706
|
+
return data.gameModelDeleteAutomationTrigger;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* **Automations** — set the app's automation policy (platform guardrails: the
|
|
710
|
+
* kill switch, max automations, the minimum schedule interval floor, max
|
|
711
|
+
* fan-out, max event cascade depth, and the aggregate per-minute run ceiling).
|
|
712
|
+
* Requires the app-admin **`manage_apps`** permission.
|
|
713
|
+
*
|
|
714
|
+
* @param input - {@link SetAutomationPolicyInput}.
|
|
715
|
+
* @returns The updated {@link GmAutomationPolicy}.
|
|
716
|
+
*/
|
|
717
|
+
async setAutomationPolicy(input) {
|
|
718
|
+
const data = await this.gql.request(GameModelSetAutomationPolicyDocument, { input });
|
|
719
|
+
return data.gameModelSetAutomationPolicy;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* **Automations** — run an automation once, immediately (manual trigger),
|
|
723
|
+
* regardless of its schedule. Applies the same guard chain and records a run.
|
|
724
|
+
* Useful for testing an NPC. Requires the app-admin **`manage_apps`**
|
|
725
|
+
* permission.
|
|
726
|
+
*
|
|
727
|
+
* @param variables - `{ appId, name }`.
|
|
728
|
+
* @returns The recorded {@link GmAutomationRun}.
|
|
729
|
+
*/
|
|
730
|
+
async runAutomation(variables) {
|
|
731
|
+
const data = await this.gql.request(GameModelRunAutomationDocument, variables);
|
|
732
|
+
return data.gameModelRunAutomation;
|
|
733
|
+
}
|
|
734
|
+
/**
|
|
735
|
+
* **Automations** — list the automations defined for an app (with
|
|
736
|
+
* circuit-breaker state). Requires the app-admin **`manage_apps`** permission.
|
|
737
|
+
*
|
|
738
|
+
* @param variables - `{ appId }`.
|
|
739
|
+
* @returns The {@link GmAutomation}s.
|
|
740
|
+
*/
|
|
741
|
+
async automations(variables) {
|
|
742
|
+
const data = await this.gql.request(GameModelAutomationsDocument, variables);
|
|
743
|
+
return data.gameModelAutomations;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* **Automations** — fetch one automation by name. Requires the app-admin
|
|
747
|
+
* **`manage_apps`** permission.
|
|
748
|
+
*
|
|
749
|
+
* @param variables - `{ appId, name }`.
|
|
750
|
+
* @returns The {@link GmAutomation}.
|
|
751
|
+
*/
|
|
752
|
+
async automation(variables) {
|
|
753
|
+
const data = await this.gql.request(GameModelAutomationDocument, variables);
|
|
754
|
+
return data.gameModelAutomation;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* **Automations** — list event triggers for an app, optionally filtered to one
|
|
758
|
+
* automation by name. Requires the app-admin **`manage_apps`** permission.
|
|
759
|
+
*
|
|
760
|
+
* @param variables - `{ appId, automationName? }`.
|
|
761
|
+
* @returns The {@link GmAutomationTrigger}s.
|
|
762
|
+
*/
|
|
763
|
+
async automationTriggers(variables) {
|
|
764
|
+
const data = await this.gql.request(GameModelAutomationTriggersDocument, variables);
|
|
765
|
+
return data.gameModelAutomationTriggers;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* **Automations** — read the app's automation policy. Requires the app-admin
|
|
769
|
+
* **`manage_apps`** permission.
|
|
770
|
+
*
|
|
771
|
+
* @param variables - `{ appId }`.
|
|
772
|
+
* @returns The {@link GmAutomationPolicy}.
|
|
773
|
+
*/
|
|
774
|
+
async automationPolicy(variables) {
|
|
775
|
+
const data = await this.gql.request(GameModelAutomationPolicyDocument, variables);
|
|
776
|
+
return data.gameModelAutomationPolicy;
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* **Automations** — list automation runs (the monitoring/audit trail), newest
|
|
780
|
+
* first, optionally filtered by automation name and/or outcome. Requires the
|
|
781
|
+
* app-admin **`manage_apps`** permission.
|
|
782
|
+
*
|
|
783
|
+
* @param variables - `{ appId, automationName?, success?, limit?, offset? }`.
|
|
784
|
+
* @returns The {@link GmAutomationRun}s.
|
|
785
|
+
*/
|
|
786
|
+
async automationRuns(variables) {
|
|
787
|
+
const data = await this.gql.request(GameModelAutomationRunsDocument, variables);
|
|
788
|
+
return data.gameModelAutomationRuns;
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* **Automations** — aggregate automation activity over a recent window
|
|
792
|
+
* (throughput, failure rate, compute, per-automation breakdown). The
|
|
793
|
+
* "what are my NPCs doing" view. Requires the app-admin **`manage_apps`**
|
|
794
|
+
* permission.
|
|
795
|
+
*
|
|
796
|
+
* @param variables - `{ appId, windowMinutes? }` (default 60, max 1440).
|
|
797
|
+
* @returns The {@link GmAutomationStats}.
|
|
798
|
+
*/
|
|
799
|
+
async automationStats(variables) {
|
|
800
|
+
const data = await this.gql.request(GameModelAutomationStatsDocument, variables);
|
|
801
|
+
return data.gameModelAutomationStats;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* **Diagnostics** — a snapshot of an app's game-model footprint and recent
|
|
805
|
+
* activity (row counts + 24h invocation activity + top functions). Helps
|
|
806
|
+
* developers understand what is in their game and their database. Requires the
|
|
807
|
+
* app-admin **`manage_apps`** permission.
|
|
808
|
+
*
|
|
809
|
+
* @param variables - `{ appId }`.
|
|
810
|
+
* @returns The {@link GmAppDiagnostics}.
|
|
811
|
+
*/
|
|
812
|
+
async appDiagnostics(variables) {
|
|
813
|
+
const data = await this.gql.request(GameModelAppDiagnosticsDocument, variables);
|
|
814
|
+
return data.gameModelAppDiagnostics;
|
|
815
|
+
}
|
|
816
|
+
}
|