@crowdedkingdoms/crowdyjs 8.1.0 → 8.2.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.
@@ -0,0 +1,81 @@
1
+ import type { GameAppsAPI } from '../domains/gameApps.js';
2
+ import type { GameModelAPI } from '../domains/gameModel.js';
3
+ import type { Scalars, SeedPropertyInput } from '../generated/graphql.js';
4
+ import { type KitInvokeResult } from './shared.js';
5
+ /** Options for {@link PlotsKit}. Must match the deployed plot blueprint. */
6
+ export interface PlotsKitOptions {
7
+ /** The `typeName` the plot blueprint was deployed with. Defaults to `'Plot'`. */
8
+ typeName?: string;
9
+ }
10
+ /** A parsed view of one plot. */
11
+ export interface KitPlot {
12
+ containerId: string;
13
+ displayName: string;
14
+ gridId: number;
15
+ price: number;
16
+ /** 0 when unowned. */
17
+ ownerUserId: number;
18
+ rentPrice?: number;
19
+ rentTtlSeconds?: number;
20
+ }
21
+ /**
22
+ * Runtime helpers for the {@link plotBlueprint} conventions: list/create
23
+ * plots and drive the buy/rent/evict functions whose permission effects grant
24
+ * or revoke real, replication-enforced grid permissions transactionally with
25
+ * the currency mutation. Authorization (wallet ownership, price, plot
26
+ * ownership) is enforced server-side — a denial resolves with
27
+ * `success: false`, never an exception.
28
+ *
29
+ * Obtained via `client.kit(appId).plots`.
30
+ */
31
+ export declare class PlotsKit {
32
+ private readonly appId;
33
+ private readonly gameModel;
34
+ private readonly gameApps;
35
+ private readonly names;
36
+ constructor(appId: Scalars['BigInt']['input'], gameModel: GameModelAPI, gameApps: GameAppsAPI, options?: PlotsKitOptions);
37
+ /**
38
+ * Instantiate a plot over an existing grid (admin — the type is
39
+ * admin-instantiable). Create the grid first (`client.gameApps.createGrid`)
40
+ * and pass its id here.
41
+ */
42
+ create(input: {
43
+ displayName: string;
44
+ gridId: Scalars['BigInt']['input'];
45
+ price: number;
46
+ rentPrice?: number;
47
+ rentTtlSeconds?: number;
48
+ properties?: SeedPropertyInput[];
49
+ }): Promise<{
50
+ __typename?: "GmContainer";
51
+ containerId: string;
52
+ appId: string;
53
+ sessionId: string | null;
54
+ typeName: string;
55
+ displayName: string;
56
+ description: string | null;
57
+ ownerUserId: string | null;
58
+ metadataJson: string;
59
+ }>;
60
+ /** List plots with parsed state (grid, price, current owner). */
61
+ list(): Promise<KitPlot[]>;
62
+ /**
63
+ * Buy a plot: spends the price from the caller's wallet AND grants the
64
+ * blueprint's grid permissions in one transaction. Resolves with the
65
+ * wallet's remaining balance.
66
+ */
67
+ buy(plotId: string, walletId: string): Promise<KitInvokeResult<number>>;
68
+ /**
69
+ * Rent a plot (blueprint deployed with `rentable: true`): like {@link buy}
70
+ * but the grant expires after the plot's `rent_ttl_seconds`.
71
+ */
72
+ rent(plotId: string, walletId: string): Promise<KitInvokeResult<number>>;
73
+ /** Revoke a user's permissions on a plot (plot owner or app admin). */
74
+ evict(plotId: string, targetUserId: Scalars['BigInt']['input']): Promise<KitInvokeResult>;
75
+ /**
76
+ * A user's effective permission keys on a plot's grid (for HUD display —
77
+ * enforcement happens server-side regardless).
78
+ */
79
+ accessOf(userId: Scalars['BigInt']['input'], gridId: Scalars['BigInt']['input']): Promise<string[]>;
80
+ }
81
+ //# sourceMappingURL=plots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plots.d.ts","sourceRoot":"","sources":["../../src/kit/plots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAErB,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iCAAiC;AACjC,MAAM,WAA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K,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC;IAS/F;;;OAGG;IACG,QAAQ,CACZ,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,EAClC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GACjC,OAAO,CAAC,MAAM,EAAE,CAAC;CAQrB"}
@@ -0,0 +1,113 @@
1
+ import { plotNames } from './blueprints.js';
2
+ import { kitContainerProperties, kitInvoke, } from './shared.js';
3
+ /**
4
+ * Runtime helpers for the {@link plotBlueprint} conventions: list/create
5
+ * plots and drive the buy/rent/evict functions whose permission effects grant
6
+ * or revoke real, replication-enforced grid permissions transactionally with
7
+ * the currency mutation. Authorization (wallet ownership, price, plot
8
+ * ownership) is enforced server-side — a denial resolves with
9
+ * `success: false`, never an exception.
10
+ *
11
+ * Obtained via `client.kit(appId).plots`.
12
+ */
13
+ export class PlotsKit {
14
+ constructor(appId, gameModel, gameApps, options = {}) {
15
+ this.appId = appId;
16
+ this.gameModel = gameModel;
17
+ this.gameApps = gameApps;
18
+ this.names = plotNames(options.typeName);
19
+ }
20
+ /**
21
+ * Instantiate a plot over an existing grid (admin — the type is
22
+ * admin-instantiable). Create the grid first (`client.gameApps.createGrid`)
23
+ * and pass its id here.
24
+ */
25
+ async create(input) {
26
+ const properties = [
27
+ { key: 'grid_id', valueType: 'int', valueJson: String(input.gridId) },
28
+ { key: 'price', valueType: 'int', valueJson: String(input.price) },
29
+ ...(input.rentPrice !== undefined
30
+ ? [{ key: 'rent_price', valueType: 'int', valueJson: String(input.rentPrice) }]
31
+ : []),
32
+ ...(input.rentTtlSeconds !== undefined
33
+ ? [
34
+ {
35
+ key: 'rent_ttl_seconds',
36
+ valueType: 'int',
37
+ valueJson: String(input.rentTtlSeconds),
38
+ },
39
+ ]
40
+ : []),
41
+ ...(input.properties ?? []),
42
+ ];
43
+ return this.gameModel.createContainer({
44
+ appId: this.appId,
45
+ typeName: this.names.plotType,
46
+ displayName: input.displayName,
47
+ properties,
48
+ });
49
+ }
50
+ /** List plots with parsed state (grid, price, current owner). */
51
+ async list() {
52
+ const containers = await this.gameModel.containers({
53
+ appId: this.appId,
54
+ typeName: this.names.plotType,
55
+ });
56
+ return Promise.all(containers.map(async (c) => {
57
+ const props = await kitContainerProperties(this.gameModel, String(this.appId), c.containerId);
58
+ return {
59
+ containerId: c.containerId,
60
+ displayName: c.displayName,
61
+ gridId: Number(props.grid_id ?? 0),
62
+ price: Number(props.price ?? 0),
63
+ ownerUserId: Number(props.owner_user_id ?? 0),
64
+ ...(props.rent_price !== undefined ? { rentPrice: Number(props.rent_price) } : {}),
65
+ ...(props.rent_ttl_seconds !== undefined
66
+ ? { rentTtlSeconds: Number(props.rent_ttl_seconds) }
67
+ : {}),
68
+ };
69
+ }));
70
+ }
71
+ /**
72
+ * Buy a plot: spends the price from the caller's wallet AND grants the
73
+ * blueprint's grid permissions in one transaction. Resolves with the
74
+ * wallet's remaining balance.
75
+ */
76
+ async buy(plotId, walletId) {
77
+ return kitInvoke(this.gameModel, {
78
+ appId: String(this.appId),
79
+ functionName: this.names.buyFn,
80
+ selfContainerId: plotId,
81
+ params: { wallet_id: walletId },
82
+ });
83
+ }
84
+ /**
85
+ * Rent a plot (blueprint deployed with `rentable: true`): like {@link buy}
86
+ * but the grant expires after the plot's `rent_ttl_seconds`.
87
+ */
88
+ async rent(plotId, walletId) {
89
+ return kitInvoke(this.gameModel, {
90
+ appId: String(this.appId),
91
+ functionName: this.names.rentFn,
92
+ selfContainerId: plotId,
93
+ params: { wallet_id: walletId },
94
+ });
95
+ }
96
+ /** Revoke a user's permissions on a plot (plot owner or app admin). */
97
+ async evict(plotId, targetUserId) {
98
+ return kitInvoke(this.gameModel, {
99
+ appId: String(this.appId),
100
+ functionName: this.names.evictFn,
101
+ selfContainerId: plotId,
102
+ params: { target_user_id: Number(targetUserId) },
103
+ });
104
+ }
105
+ /**
106
+ * A user's effective permission keys on a plot's grid (for HUD display —
107
+ * enforcement happens server-side regardless).
108
+ */
109
+ async accessOf(userId, gridId) {
110
+ const res = await this.gameApps.userPermissions(String(this.appId), String(gridId), String(userId));
111
+ return [...res.permissionKeys];
112
+ }
113
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdedkingdoms/crowdyjs",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "Client SDK for Crowded Kingdoms GraphQL API with UDP proxy support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",