@tinyburg/lego-tower-sdk 0.0.0-stage → 0.1.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,410 @@
1
+ /**
2
+ * LEGO Tower (game code `lt`) NBSync api endpoints.
3
+ *
4
+ * Signing: a random `salt` (signed int32) goes in the path, and `hash` is
5
+ * `md5(<preimage> + <game secret salt>)` with the preimage
6
+ * `lt/<playerId>/<salt><playerAuthKey>` (variants noted per endpoint). The
7
+ * secret salt is the value extracted from `NBSync._ss`.
8
+ *
9
+ * Verification (live server + Frida DTO inspection of the game, 2026-08-26):
10
+ * - Signing is MD5, server-validated (same scheme as Tiny Tower / Pocket
11
+ * Planes; the game computes SHA-256 only for the unauthenticated `register`).
12
+ * - Response envelopes VERIFIED by reading the game's DTO classes at runtime:
13
+ * register, player_details, sync/pull (NBSyncGameSaveResponse), current_version,
14
+ * verify_device, friend/pull_game, friend/pull_meta (meta is a flat
15
+ * Dictionary<String,Object> on pt), send_item (NBSyncItemsSendResponse),
16
+ * get_items (NBSyncItemsGetResponse: success/gifts, NO `total` unlike pp).
17
+ * `get_items` was also exercised live with a burnbot.
18
+ * - Rich endpoint set: adds snapshots, trades, mailbox, AG, and LL-friends.
19
+ * - LEGO Tower issues player ids longer than 5 chars (relaxed PlayerId schema).
20
+ *
21
+ * Game-specific save/meta schemas are left as `Schema.Unknown` placeholders.
22
+ *
23
+ * @since 1.0.0
24
+ * @category Endpoints
25
+ */
26
+
27
+ import { HttpApi, HttpApiEndpoint, HttpApiError, HttpApiGroup } from "effect/http-api";
28
+ import * as Schema from "effect/Schema";
29
+
30
+ import * as NimblebitConfig from "@tinyburg/nimblebit-sdk/NimblebitConfig";
31
+ import * as OAuthScope from "@yielded/auth/OAuthScope";
32
+
33
+ import * as Scopes from "./Scopes.ts";
34
+
35
+ /**
36
+ * LEGO Tower player id. Unlike tt/pp/pt, LEGO Tower issues ids longer than 5
37
+ * chars (e.g. `1QVVY7`), so the shared `PlayerId`
38
+ * (max length 5) is too strict here.
39
+ *
40
+ * @since 1.0.0
41
+ * @category Schemas
42
+ */
43
+ export const PlayerId = Schema.String.pipe(
44
+ Schema.check(Schema.isMinLength(1)),
45
+ Schema.check(Schema.isMaxLength(10)),
46
+ Schema.check(Schema.isPattern(/^([\dA-Z]*)$/)),
47
+ Schema.brand("PlayerId")
48
+ );
49
+
50
+ /** @internal */
51
+ export const U32 = Schema.Int.check(Schema.isUint32());
52
+
53
+ /** @internal */
54
+ export const ApiErrors = [
55
+ HttpApiError.Forbidden,
56
+ HttpApiError.BadRequest,
57
+ HttpApiError.Unauthorized,
58
+ HttpApiError.InternalServerError,
59
+ ] as const;
60
+
61
+ /** @internal */
62
+ export const ErrorResponse = Schema.Struct({ error: Schema.String });
63
+
64
+ /** @internal */
65
+ export const NotFoundResponse = Schema.Struct({ success: Schema.Literal("NotFound") });
66
+
67
+ /** @internal */
68
+ export const SentResponse = Schema.Struct({ success: Schema.Literal("Sent") });
69
+
70
+ /** @internal */
71
+ export const NotSentResponse = Schema.Struct({ success: Schema.Literal("NotSent") });
72
+
73
+ /**
74
+ * A gift/item in the general item channel (get_items / send_item). Verified DTO
75
+ * NBSyncItemsGift on pt: `{gift_id, gift_to, gift_from, gift_type, item_type,
76
+ * gift_str, h}` (no `c`, unlike pp). Left open for the data-schema work.
77
+ *
78
+ * @since 1.0.0
79
+ * @category Schemas
80
+ */
81
+ export const Gift = Schema.Unknown;
82
+
83
+ /** @internal */
84
+ export const DeviceNewPlayerEndpoint = HttpApiEndpoint.get("DeviceNewPlayer", "/register/lt/:salt1/:salt2/:hash", {
85
+ params: { salt1: U32, salt2: U32, hash: Schema.String },
86
+ error: ApiErrors,
87
+ success: [
88
+ ErrorResponse,
89
+ Schema.Struct({
90
+ playerId: PlayerId,
91
+ playerSs: NimblebitConfig.PlayerAuthKeySchema,
92
+ }).pipe(Schema.encodeKeys({ playerId: "player_id", playerSs: "player_ss" })),
93
+ ],
94
+ });
95
+
96
+ /** @internal */
97
+ export const DevicePlayerDetailsEndpoint = HttpApiEndpoint.get(
98
+ "DevicePlayerDetails",
99
+ "/player_details/lt/:playerId/:salt/:hash",
100
+ {
101
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
102
+ error: ApiErrors,
103
+ success: [
104
+ ErrorResponse,
105
+ Schema.Struct({
106
+ success: Schema.Literal("Found"),
107
+ player: Schema.Struct({
108
+ playerId: PlayerId,
109
+ playerEmail: NimblebitConfig.PlayerEmailSchema,
110
+ registered: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.BooleanFromBit)),
111
+ blacklisted: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.BooleanFromBit)),
112
+ saveVersion: Schema.NumberFromString.pipe(Schema.decodeTo(Schema.Int)),
113
+ checksum: Schema.String,
114
+ }).pipe(Schema.encodeKeys({ playerId: "player_id", playerEmail: "email", checksum: "h" })),
115
+ }),
116
+ ],
117
+ }
118
+ ).annotate(OAuthScope.Required, Scopes.Device.read.player_details.required);
119
+
120
+ /** @internal */
121
+ export const DeviceVerifyDeviceEndpoint = HttpApiEndpoint.get(
122
+ "DeviceVerifyDevice",
123
+ "/verify_device/lt/:playerId/:verificationCode",
124
+ {
125
+ params: { playerId: PlayerId, verificationCode: Schema.String },
126
+ error: ApiErrors,
127
+ success: [
128
+ ErrorResponse,
129
+ Schema.Struct({
130
+ success: Schema.Literal("NewDevice"),
131
+ playerId: PlayerId,
132
+ playerAuthKey: NimblebitConfig.PlayerAuthKeySchema,
133
+ playerEmail: NimblebitConfig.PlayerEmailSchema,
134
+ }).pipe(
135
+ Schema.encodeKeys({ playerId: "player_id", playerAuthKey: "player_ss", playerEmail: "player_email" })
136
+ ),
137
+ ],
138
+ }
139
+ ).annotate(OAuthScope.Required, Scopes.Device.write.verify_device.required);
140
+
141
+ /**
142
+ * Pull the player's cloud save. VERIFIED envelope (NBSyncGameSaveResponse). No-save
143
+ * case returns `{ error: "SaveNotFound" }`. `data` is base64 pako-deflated bytes.
144
+ *
145
+ * @internal
146
+ */
147
+ export const SyncPullSaveEndpoint = HttpApiEndpoint.get("SyncPullSave", "/sync/pull/lt/:playerId/:salt/:hash", {
148
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
149
+ error: ApiErrors,
150
+ success: [
151
+ ErrorResponse,
152
+ NotFoundResponse,
153
+ Schema.Struct({
154
+ success: Schema.Literal("Found"),
155
+ data: Schema.Uint8ArrayFromBase64,
156
+ checksum: Schema.String,
157
+ saveId: Schema.NumberFromString,
158
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id" })),
159
+ ],
160
+ });
161
+
162
+ /**
163
+ * VERIFIED envelope (NBSyncCurrentCheckResponse); no-save returns `{ error: "NoSave" }`.
164
+ *
165
+ * @internal
166
+ */
167
+ export const SyncCheckForNewerSaveEndpoint = HttpApiEndpoint.get(
168
+ "SyncCheckForNewerSave",
169
+ "/sync/current_version/lt/:playerId/:salt/:hash",
170
+ {
171
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
172
+ error: ApiErrors,
173
+ success: [
174
+ ErrorResponse,
175
+ NotFoundResponse,
176
+ Schema.Struct({
177
+ success: Schema.Literal("Found"),
178
+ checksum: Schema.String,
179
+ saveId: Schema.NumberFromString,
180
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id" })),
181
+ ],
182
+ }
183
+ );
184
+
185
+ /**
186
+ * VERIFIED live: `/get_items/lt/:playerId/:salt/:hash` -> `{ success:"Found",
187
+ * gifts:[...] }` (NBSyncItemsGetResponse; no `total` on pt).
188
+ *
189
+ * @internal
190
+ */
191
+ export const SocialGetItemsEndpoint = HttpApiEndpoint.get("SocialGetItems", "/get_items/lt/:playerId/:salt/:hash", {
192
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
193
+ error: ApiErrors,
194
+ success: [
195
+ ErrorResponse,
196
+ NotFoundResponse,
197
+ Schema.Struct({ success: Schema.Literal("Found"), gifts: Schema.Array(Gift) }),
198
+ ],
199
+ }).annotate(OAuthScope.Required, Scopes.Social.read.get_items.required);
200
+
201
+ /**
202
+ * DERIVED from Tiny Tower. Sends an item to a friend. Response VERIFIED
203
+ * (NBSyncItemsSendResponse: success/error). pt also has a `/send_pt/` variant.
204
+ *
205
+ * @internal
206
+ */
207
+ export const SocialSendItemEndpoint = HttpApiEndpoint.post(
208
+ "SocialSendItem",
209
+ "/send_item/lt/:itemType/:playerId/:friendId/:salt/:hash",
210
+ {
211
+ params: {
212
+ itemType: Schema.String,
213
+ playerId: PlayerId,
214
+ friendId: PlayerId,
215
+ salt: U32,
216
+ hash: Schema.String,
217
+ },
218
+ payload: Schema.Struct({ itemStr: Schema.String }),
219
+ error: ApiErrors,
220
+ success: [ErrorResponse, SentResponse, NotSentResponse],
221
+ }
222
+ ).annotate(OAuthScope.Required, Scopes.Social.write.send_item.required);
223
+
224
+ /**
225
+ * VERIFIED envelope (NBSyncFriendGameSaveResponse); preimage
226
+ * `lt/<playerId>/<friendId>/<salt><playerAuthKey>`.
227
+ *
228
+ * @internal
229
+ */
230
+ export const SocialPullFriendGameEndpoint = HttpApiEndpoint.get(
231
+ "SocialPullFriendGame",
232
+ "/friend/pull_game/lt/:playerId/:friendId/:salt/:hash",
233
+ {
234
+ params: {
235
+ playerId: PlayerId,
236
+ friendId: PlayerId,
237
+ salt: U32,
238
+ hash: Schema.String,
239
+ },
240
+ error: ApiErrors,
241
+ success: [
242
+ ErrorResponse,
243
+ NotFoundResponse,
244
+ Schema.Struct({
245
+ success: Schema.Literal("Found"),
246
+ data: Schema.Uint8ArrayFromBase64,
247
+ checksum: Schema.String,
248
+ saveId: Schema.NumberFromString,
249
+ playerId: PlayerId,
250
+ }).pipe(Schema.encodeKeys({ checksum: "h", saveId: "id", playerId: "player_id" })),
251
+ ],
252
+ }
253
+ ).annotate(OAuthScope.Required, Scopes.Social.read.pull_friend_game.required);
254
+
255
+ /**
256
+ * VERIFIED envelope (NBSyncFriendGameMetaResponse; `meta` is a flat
257
+ * Dictionary<String,Object> on pt). Preimage `lt/<playerId>/<salt><friendId><playerAuthKey>`.
258
+ *
259
+ * @internal
260
+ */
261
+ export const SocialPullFriendMetaEndpoint = HttpApiEndpoint.post(
262
+ "SocialPullFriendMeta",
263
+ "/friend/pull_meta/lt/:playerId/:salt/:hash",
264
+ {
265
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
266
+ payload: Schema.Struct({ friends: PlayerId }),
267
+ error: ApiErrors,
268
+ success: [
269
+ ErrorResponse,
270
+ NotFoundResponse,
271
+ Schema.Struct({
272
+ success: Schema.Literal("Found"),
273
+ meta: Schema.Record(PlayerId, Schema.Unknown),
274
+ }),
275
+ ],
276
+ }
277
+ ).annotate(OAuthScope.Required, Scopes.Social.read.pull_friend_meta.required);
278
+
279
+ /**
280
+ * VERIFIED path `/get_visits/lt/:playerId/:salt/:hash`.
281
+ *
282
+ * @internal
283
+ */
284
+ export const SocialGetVisitsEndpoint = HttpApiEndpoint.get("SocialGetVisits", "/get_visits/lt/:playerId/:salt/:hash", {
285
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
286
+ error: ApiErrors,
287
+ success: [
288
+ ErrorResponse,
289
+ NotFoundResponse,
290
+ Schema.Struct({ success: Schema.Literal("Found"), gifts: Schema.Array(Gift) }),
291
+ ],
292
+ }).annotate(OAuthScope.Required, Scopes.Social.read.get_visits.required);
293
+
294
+ /**
295
+ * Snapshot list. VERIFIED DTO NBSyncSnapshotList { success, error, saves:
296
+ * List<NBSyncSnapshotItem{ id, created, meta }> }.
297
+ *
298
+ * @internal
299
+ */
300
+ export const SyncRetrieveSnapshotListEndpoint = HttpApiEndpoint.get(
301
+ "SyncRetrieveSnapshotList",
302
+ "/sync/current_snapshots/lt/:playerId/:salt/:hash",
303
+ {
304
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
305
+ error: ApiErrors,
306
+ success: [
307
+ ErrorResponse,
308
+ NotFoundResponse,
309
+ Schema.Struct({
310
+ success: Schema.Literal("Found"),
311
+ saves: Schema.Array(
312
+ Schema.Struct({
313
+ id: Schema.Int,
314
+ created: Schema.Int,
315
+ meta: Schema.Record(Schema.String, Schema.Unknown),
316
+ })
317
+ ),
318
+ }),
319
+ ],
320
+ }
321
+ );
322
+
323
+ /**
324
+ * Pull one snapshot. Preimage `lt/<playerId>/<snapshotId>/<salt><playerAuthKey>`.
325
+ *
326
+ * @internal
327
+ */
328
+ export const SyncPullSnapshotEndpoint = HttpApiEndpoint.get(
329
+ "SyncPullSnapshot",
330
+ "/sync/pull_snapshot/lt/:playerId/:snapshotId/:salt/:hash",
331
+ {
332
+ params: { playerId: PlayerId, snapshotId: Schema.Int, salt: U32, hash: Schema.String },
333
+ error: ApiErrors,
334
+ success: [
335
+ ErrorResponse,
336
+ NotFoundResponse,
337
+ Schema.Struct({
338
+ success: Schema.Literal("Found"),
339
+ data: Schema.Uint8ArrayFromBase64,
340
+ checksum: Schema.String,
341
+ snapshotId: Schema.NumberFromString,
342
+ }).pipe(Schema.encodeKeys({ checksum: "h", snapshotId: "id" })),
343
+ ],
344
+ }
345
+ );
346
+
347
+ /**
348
+ * Trades list. VERIFIED DTO NBSyncTradeItemsGetResponse { success, trades:
349
+ * List<NBSyncTradeItem{ id, to, from, status, payload, added, expire }>, error }.
350
+ *
351
+ * @internal
352
+ */
353
+ export const TradeGetTradesEndpoint = HttpApiEndpoint.get("TradeGetTrades", "/get_trades/lt/:playerId/:salt/:hash", {
354
+ params: { playerId: PlayerId, salt: U32, hash: Schema.String },
355
+ error: ApiErrors,
356
+ success: [
357
+ ErrorResponse,
358
+ NotFoundResponse,
359
+ Schema.Struct({
360
+ success: Schema.Literal("Found"),
361
+ trades: Schema.Array(
362
+ Schema.Struct({
363
+ id: Schema.Int,
364
+ to: Schema.String,
365
+ from: Schema.String,
366
+ status: Schema.Int,
367
+ payload: Schema.String,
368
+ added: Schema.Int,
369
+ expire: Schema.Int,
370
+ })
371
+ ),
372
+ }),
373
+ ],
374
+ });
375
+
376
+ /** @internal */
377
+ export const DeviceManagementGroup = HttpApiGroup.make("DeviceManagementGroup")
378
+ .add(DeviceNewPlayerEndpoint)
379
+ .add(DevicePlayerDetailsEndpoint)
380
+ .add(DeviceVerifyDeviceEndpoint);
381
+
382
+ /** @internal */
383
+ export const SyncManagementGroup = HttpApiGroup.make("SyncManagementGroup")
384
+ .add(SyncPullSaveEndpoint)
385
+ .add(SyncCheckForNewerSaveEndpoint)
386
+ .add(SyncRetrieveSnapshotListEndpoint)
387
+ .add(SyncPullSnapshotEndpoint);
388
+
389
+ /** @internal */
390
+ export const TradeGroup = HttpApiGroup.make("TradeGroup").add(TradeGetTradesEndpoint);
391
+
392
+ /** @internal */
393
+ export const SocialGroup = HttpApiGroup.make("SocialGroup")
394
+ .add(SocialGetItemsEndpoint)
395
+ .add(SocialGetVisitsEndpoint)
396
+ .add(SocialSendItemEndpoint)
397
+ .add(SocialPullFriendGameEndpoint)
398
+ .add(SocialPullFriendMetaEndpoint);
399
+
400
+ /**
401
+ * The LEGO Tower NBSync api.
402
+ *
403
+ * @since 1.0.0
404
+ * @category Api
405
+ */
406
+ export const Api = HttpApi.make("LegoTowerApi")
407
+ .add(DeviceManagementGroup)
408
+ .add(SyncManagementGroup)
409
+ .add(SocialGroup)
410
+ .add(TradeGroup);
@@ -0,0 +1,186 @@
1
+ /**
2
+ * LEGO Tower SDK: signed calls against Nimblebit's NBSync service.
3
+ *
4
+ * Signing reuses `@tinyburg/nimblebit-sdk` (`NimblebitAuth`): the game secret
5
+ * salt (from `NBSync._ss`) is provided as the auth key, and each request is
6
+ * `md5(<preimage> + <secret salt>)` with a random uint32 `salt` in the path.
7
+ * All method preimages below are the Tiny Tower formula with the `lt` game code.
8
+ *
9
+ * The methods that were exercised live against sync.nimblebit.com are marked
10
+ * VERIFIED; save-bearing / write paths follow the same pattern but were not
11
+ * exercised. Save bytes are returned raw (base64-decoded); inflating (pako) and
12
+ * parsing into a save schema is left to the caller.
13
+ *
14
+ * @since 1.0.0
15
+ * @category SDK
16
+ */
17
+
18
+ import type * as Schema from "effect/Schema";
19
+
20
+ import * as Effect from "effect/Effect";
21
+ import * as Function from "effect/Function";
22
+ import { HttpClient, HttpClientRequest } from "effect/http";
23
+ import { HttpApiClient } from "effect/http-api";
24
+ import * as Redacted from "effect/Redacted";
25
+
26
+ import type { NimblebitConfig } from "@tinyburg/nimblebit-sdk";
27
+
28
+ import { NimblebitAuth, NimblebitError } from "@tinyburg/nimblebit-sdk";
29
+
30
+ import * as Endpoints from "./Endpoints.ts";
31
+
32
+ /**
33
+ * Requests a new player ("burnbot") from the Nimblebit servers. VERIFIED.
34
+ *
35
+ * @since 1.0.0
36
+ * @category SDK
37
+ */
38
+ export const device_newPlayer = Effect.gen(function* () {
39
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
40
+ const httpClient = yield* HttpClient.HttpClient;
41
+
42
+ const maybeAddBearerToken =
43
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
44
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
45
+ : Function.identity;
46
+
47
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
48
+ baseUrl: nimblebitAuth.host,
49
+ group: "DeviceManagementGroup",
50
+ endpoint: "DeviceNewPlayer",
51
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
52
+ });
53
+
54
+ const salt1 = yield* nimblebitAuth.salt;
55
+ const salt2 = yield* nimblebitAuth.salt;
56
+ const hash = yield* nimblebitAuth.sign(`lt/${salt1}/${salt2}`);
57
+ const response = yield* endpoint({ params: { salt1, salt2, hash } });
58
+
59
+ if ("error" in response) {
60
+ return yield* new NimblebitError.NimblebitError({
61
+ method: "DeviceNewPlayer",
62
+ module: "DeviceManagementGroup",
63
+ cause: response.error,
64
+ });
65
+ }
66
+ return response;
67
+ });
68
+
69
+ /**
70
+ * Retrieves player details. VERIFIED.
71
+ *
72
+ * @since 1.0.0
73
+ * @category SDK
74
+ */
75
+ export const device_playerDetails = Effect.fn("device_playerDetails")(function* ({
76
+ playerAuthKey,
77
+ playerId,
78
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
79
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
80
+ const httpClient = yield* HttpClient.HttpClient;
81
+
82
+ const maybeAddBearerToken =
83
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
84
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
85
+ : Function.identity;
86
+
87
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
88
+ baseUrl: nimblebitAuth.host,
89
+ group: "DeviceManagementGroup",
90
+ endpoint: "DevicePlayerDetails",
91
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
92
+ });
93
+
94
+ const salt = yield* nimblebitAuth.salt;
95
+ const hash = yield* nimblebitAuth.sign(`lt/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
96
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
97
+
98
+ if ("error" in response) {
99
+ return yield* new NimblebitError.NimblebitError({
100
+ method: "DevicePlayerDetails",
101
+ module: "DeviceManagementGroup",
102
+ cause: response.error,
103
+ });
104
+ }
105
+ return response.player;
106
+ });
107
+
108
+ /**
109
+ * Pulls the player's cloud save. Returns raw base64-decoded bytes (inflate +
110
+ * parse separately). Success envelope DERIVED from Tiny Tower.
111
+ *
112
+ * @since 1.0.0
113
+ * @category SDK
114
+ */
115
+ export const sync_pullSave = Effect.fn("sync_pullSave")(function* ({
116
+ playerAuthKey,
117
+ playerId,
118
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
119
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
120
+ const httpClient = yield* HttpClient.HttpClient;
121
+
122
+ const maybeAddBearerToken =
123
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
124
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
125
+ : Function.identity;
126
+
127
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
128
+ baseUrl: nimblebitAuth.host,
129
+ group: "SyncManagementGroup",
130
+ endpoint: "SyncPullSave",
131
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
132
+ });
133
+
134
+ const salt = yield* nimblebitAuth.salt;
135
+ const hash = yield* nimblebitAuth.sign(`lt/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
136
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
137
+
138
+ if ("error" in response) {
139
+ return yield* new NimblebitError.NimblebitError({
140
+ method: "SyncPullSave",
141
+ module: "SyncManagementGroup",
142
+ cause: response.error,
143
+ });
144
+ }
145
+ return response;
146
+ });
147
+
148
+ /**
149
+ * Lists items (parts/gifts) waiting for the player. VERIFIED
150
+ * (`/get_items/pt/...` -> `{ success:"Found", gifts:[...] }`, no total).
151
+ *
152
+ * @since 1.0.0
153
+ * @category SDK
154
+ */
155
+ export const social_getItems = Effect.fn("social_getItems")(function* ({
156
+ playerAuthKey,
157
+ playerId,
158
+ }: Schema.Schema.Type<typeof NimblebitConfig.AuthenticatedPlayerSchema>) {
159
+ const nimblebitAuth = yield* NimblebitAuth.NimblebitAuth;
160
+ const httpClient = yield* HttpClient.HttpClient;
161
+
162
+ const maybeAddBearerToken =
163
+ nimblebitAuth.host !== "https://sync.nimblebit.com"
164
+ ? HttpClientRequest.bearerToken(nimblebitAuth.authKey)
165
+ : Function.identity;
166
+
167
+ const endpoint = yield* HttpApiClient.endpoint(Endpoints.Api, {
168
+ baseUrl: nimblebitAuth.host,
169
+ group: "SocialGroup",
170
+ endpoint: "SocialGetItems",
171
+ httpClient: HttpClient.mapRequest(httpClient, maybeAddBearerToken),
172
+ });
173
+
174
+ const salt = yield* nimblebitAuth.salt;
175
+ const hash = yield* nimblebitAuth.sign(`lt/${playerId}/${salt}${Redacted.value(playerAuthKey)}`);
176
+ const response = yield* endpoint({ params: { playerId, salt, hash } });
177
+
178
+ if ("error" in response) {
179
+ return yield* new NimblebitError.NimblebitError({
180
+ method: "SocialGetItems",
181
+ module: "SocialGroup",
182
+ cause: response.error,
183
+ });
184
+ }
185
+ return response;
186
+ });
package/src/Scopes.ts ADDED
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The scopes the LEGO Tower api is guarded by, as a game-rooted tree, built with
3
+ * `@tinyburg/nimblebit-sdk`'s `defineGame`. Only the endpoints this sdk defines
4
+ * are covered; areas without both a read and a write side are left out until
5
+ * their endpoints exist.
6
+ *
7
+ * @since 1.0.0
8
+ * @category Scopes
9
+ */
10
+
11
+ import { type Game, type ScopeDescription, defineGame } from "@tinyburg/nimblebit-sdk/NimblebitScopes";
12
+
13
+ /**
14
+ * @since 1.0.0
15
+ * @category Games
16
+ */
17
+ export const LEGOTower = defineGame({
18
+ name: "legotower",
19
+ description: "LEGO Tower",
20
+ read: { description: "Everything in LEGO Tower that only looks" },
21
+ write: { description: "Everything in LEGO Tower that changes a player's game" },
22
+ areas: {
23
+ device: {
24
+ description: "Player accounts and their devices",
25
+ read: {
26
+ description: "Look up player accounts",
27
+ leaves: {
28
+ player_details: "Look up a player's public profile details",
29
+ },
30
+ },
31
+ write: {
32
+ description: "Change a player's account or devices",
33
+ leaves: {
34
+ verify_device: "Complete a device verification code",
35
+ },
36
+ },
37
+ },
38
+ social: {
39
+ description: "Gifts, visits and friends",
40
+ read: {
41
+ description: "See gifts, visits and friends' games",
42
+ leaves: {
43
+ get_items: "See the items waiting for a player",
44
+ get_visits: "See who has visited a player",
45
+ pull_friend_game: "Download a friend's game data",
46
+ pull_friend_meta: "Fetch metadata about a player's friends",
47
+ },
48
+ },
49
+ write: {
50
+ description: "Send and accept gifts and items",
51
+ leaves: {
52
+ send_item: "Send items to another player",
53
+ },
54
+ },
55
+ },
56
+ },
57
+ });
58
+
59
+ /**
60
+ * The game's areas, by name, for annotating endpoints.
61
+ *
62
+ * @since 1.0.0
63
+ * @category Areas
64
+ */
65
+ export const { device: Device, social: Social } = LEGOTower.areas;
66
+
67
+ /**
68
+ * @since 1.0.0
69
+ * @category Tree
70
+ */
71
+ export const Games: ReadonlyArray<Game> = [LEGOTower];
72
+
73
+ /**
74
+ * @since 1.0.0
75
+ * @category Tree
76
+ */
77
+ export const all = (): ReadonlyArray<ScopeDescription> =>
78
+ Games.flatMap((game) => [
79
+ game,
80
+ game.read,
81
+ game.write,
82
+ ...Object.values(game.areas).flatMap((area) => [
83
+ area,
84
+ area.read,
85
+ ...area.read.children,
86
+ area.write,
87
+ ...area.write.children,
88
+ ]),
89
+ ]);