castle-web-cli 0.4.228 → 0.4.229

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.
@@ -1,4 +1,5 @@
1
1
  import type { Json } from "../types";
2
+ import type { MultiplayerWorldCharacterCommand } from "../multiplayer";
2
3
  export type MultiplayerSessionMode = "named" | "party" | "public";
3
4
  export interface PlayerIdentity {
4
5
  userId: string;
@@ -21,6 +22,11 @@ export interface PlatformWorldCheckpoint {
21
22
  export interface PlatformWorldSnapshot {
22
23
  revision: string;
23
24
  checkpoint: PlatformWorldCheckpoint | null;
25
+ /** Selected destination timing policy, stamped by hosts that support catch-up. */
26
+ worldTime?: PlatformWorldTimeConfig;
27
+ }
28
+ export interface PlatformWorldTimeConfig {
29
+ advance: "wallClock";
24
30
  }
25
31
  export interface PlatformHandle {
26
32
  send(connId: string, text: string): void;
@@ -67,7 +73,7 @@ export interface PlatformWorldCharacterCommand {
67
73
  speaker: PlayerIdentity & {
68
74
  playerId: string;
69
75
  };
70
- command: unknown;
76
+ command: MultiplayerWorldCharacterCommand;
71
77
  }
72
78
  export interface PlatformWorldCharacterRead {
73
79
  grantId: string;
@@ -1,7 +1,8 @@
1
1
  import type { MultiplayerSessionMode, PlatformHandle, PlayerIdentity } from "./platformHandle";
2
2
  import type { Json } from "../types";
3
+ import type { MultiplayerWorldCharacterCommand, MultiplayerWorldCharacterCommandResult, MultiplayerWorldCharacterCommandResultValue } from "../multiplayer";
3
4
  import { type ServerStorage } from "./storage";
4
- export type { MultiplayerSessionMode, PlatformHandle, PlatformSessionConfig, PlatformWorldCheckpoint, PlatformWorldSnapshot, PlayerIdentity, } from "./platformHandle";
5
+ export type { MultiplayerSessionMode, PlatformHandle, PlatformSessionConfig, PlatformWorldCheckpoint, PlatformWorldSnapshot, PlatformWorldTimeConfig, PlayerIdentity, } from "./platformHandle";
5
6
  export type { CharacterKnowledgeSource, CompleteCharacterBeatInput, DeliverCharacterKnowledgeInput, RecordCharacterEventInput, SetCharacterGameStateInput, ShareCharacterClaimInput, ServerStorage, ServerStorageBoard, ServerStorageBoardScore, ServerStorageListEntry, ServerStorageListOptions, ServerStorageListPage, ServerPlaythrough, ServerPlaythroughCharacters, ServerCharacterHistoryOptions, ServerStorageScope, } from "./storage";
6
7
  export interface MultiplayerServerPlayer extends PlayerIdentity {
7
8
  playerId: string;
@@ -53,10 +54,26 @@ export interface MultiplayerServerWorld {
53
54
  read(): Promise<MultiplayerWorldSnapshot>;
54
55
  /** Commits exactly against expectedRevision; conflicts never partially write. */
55
56
  commit(input: MultiplayerWorldCommitInput): Promise<MultiplayerWorldCommitReceipt>;
57
+ catchUp(options: MultiplayerWorldCatchUpOptions): Promise<MultiplayerWorldCatchUpResult>;
56
58
  readonly journal: MultiplayerServerWorldJournal;
57
59
  readonly participants: MultiplayerServerWorldParticipants;
60
+ readonly notifications: MultiplayerServerWorldNotifications;
58
61
  readonly characters: MultiplayerServerWorldCharacters;
59
62
  }
63
+ export interface MultiplayerWorldCatchUpOptions {
64
+ key?: string;
65
+ maxElapsedMs?: number;
66
+ apply(input: {
67
+ elapsedMs: number;
68
+ now: number;
69
+ checkpoint: MultiplayerWorldCheckpoint | null;
70
+ }): MultiplayerWorldCheckpoint | Promise<MultiplayerWorldCheckpoint>;
71
+ }
72
+ export interface MultiplayerWorldCatchUpResult {
73
+ applied: boolean;
74
+ elapsedMs: number;
75
+ revision: string;
76
+ }
60
77
  export interface MultiplayerWorldJournalAppendInput {
61
78
  operationId: string;
62
79
  entries: readonly MultiplayerWorldJournalAppendEntry[];
@@ -112,6 +129,31 @@ export interface MultiplayerWorldParticipantsReadResult {
112
129
  export interface MultiplayerServerWorldParticipants {
113
130
  read(options?: MultiplayerWorldParticipantsReadOptions): Promise<MultiplayerWorldParticipantsReadResult>;
114
131
  }
132
+ export interface MultiplayerWorldNotificationNotifyInput {
133
+ key: string;
134
+ participantIds: readonly string[];
135
+ templateId: string;
136
+ slots?: Readonly<Record<string, string>>;
137
+ at?: string;
138
+ expiresAt?: string;
139
+ }
140
+ export interface MultiplayerWorldNotificationNotifyResult {
141
+ key: string;
142
+ accepted: number;
143
+ skipped: number;
144
+ limited: number;
145
+ }
146
+ export interface MultiplayerWorldNotificationCancelInput {
147
+ key: string;
148
+ participantIds?: readonly string[];
149
+ }
150
+ export interface MultiplayerWorldNotificationCancelResult {
151
+ cancelled: number;
152
+ }
153
+ export interface MultiplayerServerWorldNotifications {
154
+ notify(input: MultiplayerWorldNotificationNotifyInput): Promise<MultiplayerWorldNotificationNotifyResult>;
155
+ cancel(input: MultiplayerWorldNotificationCancelInput): Promise<MultiplayerWorldNotificationCancelResult>;
156
+ }
115
157
  export interface MultiplayerServerWorldCharacters {
116
158
  create(input: MultiplayerWorldRuntimeCharacterCreateInput): Promise<MultiplayerWorldRuntimeCharacterCreateReceipt>;
117
159
  list(): Promise<MultiplayerWorldCharacterList>;
@@ -155,14 +197,21 @@ export interface MultiplayerWorldRuntimeCharacterCreateReceipt {
155
197
  export interface MultiplayerWorldCharacterList {
156
198
  characters: readonly MultiplayerWorldCharacterSummary[];
157
199
  }
158
- export interface MultiplayerWorldCharacterCommandRequest {
200
+ interface MultiplayerWorldCharacterCommandRequestFor<Command extends MultiplayerWorldCharacterCommand> {
201
+ /** Command discriminator mirrored at the request level for TypeScript narrowing. */
202
+ readonly type: Command["type"];
159
203
  readonly requestId: string;
160
204
  readonly operationId: string;
161
205
  readonly speaker: MultiplayerServerPlayer;
162
- readonly command: Readonly<Record<string, unknown>>;
163
- apply(): Promise<unknown>;
206
+ readonly command: Readonly<Command>;
207
+ apply(): Promise<MultiplayerWorldCharacterCommandResult<MultiplayerWorldCharacterCommandResultValue<Command>>>;
164
208
  reject(code?: string): void;
165
209
  }
210
+ export type MultiplayerWorldCharacterCommandRequest = {
211
+ [Type in MultiplayerWorldCharacterCommand["type"]]: MultiplayerWorldCharacterCommandRequestFor<Extract<MultiplayerWorldCharacterCommand, {
212
+ type: Type;
213
+ }>>;
214
+ }[MultiplayerWorldCharacterCommand["type"]];
166
215
  export interface MultiplayerWorldCharacterReadRequest {
167
216
  readonly requestId: string;
168
217
  readonly speaker: MultiplayerServerPlayer;
@@ -103,6 +103,7 @@ async function bootSession(platformHandle, callbacks) {
103
103
  let settled = false;
104
104
  const brokerFailure = { rejection: null };
105
105
  const command = Object.freeze({
106
+ type: request.command.type,
106
107
  requestId: request.requestId,
107
108
  operationId: request.operationId,
108
109
  speaker: Object.freeze(joinedPlayer(request.speaker.playerId, request.speaker)),
@@ -264,6 +265,15 @@ const WORLD_JOURNAL_MAX_READ_LIMIT = 128;
264
265
  const WORLD_PARTICIPANTS_MAX_READ_LIMIT = 256;
265
266
  const WORLD_JOURNAL_MAX_SEQUENCE = "9223372036854775807";
266
267
  const SAFE_WORLD_JOURNAL_KIND = /^[A-Za-z0-9_.:-]+$/;
268
+ const WORLD_NOTIFICATIONS_MAX_PARTICIPANTS = 16;
269
+ const WORLD_NOTIFICATIONS_MAX_SLOTS = 4;
270
+ const WORLD_NOTIFICATIONS_MAX_SLOT_CHARACTERS = 40;
271
+ const WORLD_NOTIFICATIONS_MAX_SCHEDULE_MS = 30 * 24 * 60 * 60 * 1_000;
272
+ const WORLD_NOTIFICATIONS_PAST_TOLERANCE_MS = 60 * 1_000;
273
+ const WORLD_CATCH_UP_DEFAULT_MAX_ELAPSED_MS = 7 * 24 * 60 * 60 * 1_000;
274
+ const SAFE_WORLD_NOTIFICATION_KEY = /^[A-Za-z0-9_-]+$/;
275
+ const CANONICAL_WORLD_NOTIFICATION_TIME = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,3}))?Z$/;
276
+ const URL_IN_WORLD_NOTIFICATION_TEXT = /(?:https?:\/\/|www\.|\b[a-z0-9-]+\.(?:app|com|dev|gg|io|net|org|xyz)\b)/i;
267
277
  function createServerWorld(platformHandle) {
268
278
  if (!platformHandle.config.world)
269
279
  return null;
@@ -272,36 +282,149 @@ function createServerWorld(platformHandle) {
272
282
  throw worldError("The persistent-world checkpoint broker is unavailable.", "read");
273
283
  }
274
284
  const initial = parseWorldSnapshot(platformHandle.config.world, "read");
285
+ const read = async () => {
286
+ const result = await platformHandle.worldCheckpointRead();
287
+ return parseWorldSnapshot(parsePlatformJson(result, "read"), "read");
288
+ };
289
+ const commit = async (input) => {
290
+ const expectedRevision = assertWorldRevision(input?.expectedRevision);
291
+ const operationId = assertWorldOperationId(input?.operationId);
292
+ const checkpoint = assertWorldCheckpoint(input?.checkpoint);
293
+ const raw = await platformHandle.worldCheckpointCommit(JSON.stringify({
294
+ expectedRevision,
295
+ operationId,
296
+ checkpoint,
297
+ }));
298
+ const result = parsePlatformJson(raw, "commit");
299
+ if (typeof result.replayed !== "boolean") {
300
+ throw worldError("The platform returned an invalid commit receipt.", "commit");
301
+ }
302
+ return Object.freeze({
303
+ revision: assertWorldRevision(result.revision),
304
+ replayed: result.replayed,
305
+ operationId,
306
+ });
307
+ };
275
308
  return Object.freeze({
276
309
  snapshot: initial,
277
310
  journal: createServerWorldJournal(platformHandle),
278
311
  participants: createServerWorldParticipants(platformHandle),
312
+ notifications: createServerWorldNotifications(platformHandle),
279
313
  characters: createServerWorldCharacters(platformHandle),
280
- async read() {
281
- const result = await platformHandle.worldCheckpointRead();
282
- return parseWorldSnapshot(parsePlatformJson(result, "read"), "read");
314
+ read,
315
+ commit,
316
+ async catchUp(options) {
317
+ return catchUpWorld(platformHandle.config.world?.worldTime, read, commit, options);
283
318
  },
284
- async commit(input) {
285
- const expectedRevision = assertWorldRevision(input?.expectedRevision);
286
- const operationId = assertWorldOperationId(input?.operationId);
287
- const checkpoint = assertWorldCheckpoint(input?.checkpoint);
288
- const raw = await platformHandle.worldCheckpointCommit(JSON.stringify({
289
- expectedRevision,
290
- operationId,
291
- checkpoint,
292
- }));
293
- const result = parsePlatformJson(raw, "commit");
294
- if (typeof result.replayed !== "boolean") {
295
- throw worldError("The platform returned an invalid commit receipt.", "commit");
319
+ });
320
+ }
321
+ async function catchUpWorld(worldTime, read, commit, options) {
322
+ const operation = "session.world.catchUp";
323
+ if (worldTime?.advance !== "wallClock") {
324
+ throw worldJournalArgumentError('The destination must opt in with worldTime.advance set to "wallClock".', operation);
325
+ }
326
+ assertOnlyKeys(options, ["key", "maxElapsedMs", "apply"], operation, "options");
327
+ const key = options.key === undefined
328
+ ? "advancedThroughMs"
329
+ : assertWorldCatchUpKey(options.key, operation);
330
+ const maxElapsedMs = options.maxElapsedMs === undefined
331
+ ? WORLD_CATCH_UP_DEFAULT_MAX_ELAPSED_MS
332
+ : assertBoundedInteger(options.maxElapsedMs, 0, Number.MAX_SAFE_INTEGER, "maxElapsedMs", operation);
333
+ if (typeof options.apply !== "function") {
334
+ throw worldJournalArgumentError("apply must be a function.", operation);
335
+ }
336
+ const now = Date.now();
337
+ let snapshot = await read();
338
+ for (let attempt = 0; attempt < 2; attempt += 1) {
339
+ const state = worldCatchUpState(snapshot.checkpoint, key, now, maxElapsedMs, operation);
340
+ if (state.markerExists && state.elapsedMs === 0) {
341
+ if (state.markerMs >= now) {
342
+ return Object.freeze({ applied: false, elapsedMs: 0, revision: snapshot.revision });
343
+ }
344
+ const checkpoint = checkpointWithCatchUpMarker(snapshot.checkpoint, key, state.markerMs, now, operation);
345
+ try {
346
+ const receipt = await commit({
347
+ expectedRevision: snapshot.revision,
348
+ operationId: `catchUp:${snapshot.revision}`,
349
+ checkpoint,
350
+ });
351
+ return Object.freeze({ applied: false, elapsedMs: 0, revision: receipt.revision });
296
352
  }
353
+ catch (error) {
354
+ if (attempt !== 0 || !isWorldRevisionConflict(error))
355
+ throw error;
356
+ snapshot = await read();
357
+ continue;
358
+ }
359
+ }
360
+ const returned = await options.apply(Object.freeze({
361
+ elapsedMs: state.elapsedMs,
362
+ now,
363
+ checkpoint: snapshot.checkpoint,
364
+ }));
365
+ const normalized = assertWorldCheckpoint(returned, "commit");
366
+ if (!isRecord(normalized.value)) {
367
+ throw worldJournalArgumentError("apply must return a checkpoint whose value is an object.", operation);
368
+ }
369
+ const checkpoint = checkpointWithCatchUpMarker(normalized, key, state.markerMs, now, operation);
370
+ try {
371
+ const receipt = await commit({
372
+ expectedRevision: snapshot.revision,
373
+ operationId: `catchUp:${snapshot.revision}`,
374
+ checkpoint,
375
+ });
297
376
  return Object.freeze({
298
- revision: assertWorldRevision(result.revision),
299
- replayed: result.replayed,
300
- operationId,
377
+ applied: !receipt.replayed,
378
+ elapsedMs: state.elapsedMs,
379
+ revision: receipt.revision,
301
380
  });
302
- },
381
+ }
382
+ catch (error) {
383
+ if (attempt !== 0 || !isWorldRevisionConflict(error))
384
+ throw error;
385
+ snapshot = await read();
386
+ }
387
+ }
388
+ throw new TypeError(`${operation}: unreachable catch-up state.`);
389
+ }
390
+ function assertWorldCatchUpKey(value, operation) {
391
+ if (typeof value !== "string") {
392
+ throw worldJournalArgumentError("key must be a string.", operation);
393
+ }
394
+ return value;
395
+ }
396
+ function worldCatchUpState(checkpoint, key, now, maxElapsedMs, operation) {
397
+ if (!checkpoint ||
398
+ !isRecord(checkpoint.value) ||
399
+ !Object.prototype.hasOwnProperty.call(checkpoint.value, key)) {
400
+ return { markerExists: false, markerMs: now, elapsedMs: 0 };
401
+ }
402
+ const advancedThroughMs = checkpoint.value[key];
403
+ if (!Number.isSafeInteger(advancedThroughMs) || advancedThroughMs < 0) {
404
+ throw worldJournalArgumentError(`checkpoint.value.${key} must be a non-negative integer timestamp in milliseconds.`, operation);
405
+ }
406
+ const markerMs = advancedThroughMs;
407
+ return {
408
+ markerExists: true,
409
+ markerMs,
410
+ elapsedMs: Math.min(maxElapsedMs, Math.max(0, now - markerMs)),
411
+ };
412
+ }
413
+ function checkpointWithCatchUpMarker(checkpoint, key, existingMarkerMs, now, operation) {
414
+ if (!isRecord(checkpoint.value)) {
415
+ throw worldJournalArgumentError("apply must return a checkpoint whose value is an object.", operation);
416
+ }
417
+ return Object.freeze({
418
+ version: checkpoint.version,
419
+ value: Object.freeze({
420
+ ...checkpoint.value,
421
+ [key]: Math.max(existingMarkerMs, now),
422
+ }),
303
423
  });
304
424
  }
425
+ function isWorldRevisionConflict(error) {
426
+ return isRecord(error) && error.code === "CAULDRON_WORLD_REVISION_CONFLICT";
427
+ }
305
428
  function createServerWorldJournal(platformHandle) {
306
429
  return Object.freeze({
307
430
  async append(input) {
@@ -382,6 +505,167 @@ function createServerWorldParticipants(platformHandle) {
382
505
  },
383
506
  });
384
507
  }
508
+ function createServerWorldNotifications(platformHandle) {
509
+ return Object.freeze({
510
+ async notify(input) {
511
+ const operation = "session.world.notifications.notify";
512
+ assertOnlyKeys(input, ["key", "participantIds", "templateId", "slots", "at", "expiresAt"], operation, "input");
513
+ const now = Date.now();
514
+ const key = assertWorldNotificationSafeKey(input.key, "key", operation);
515
+ const participantIds = normalizeParticipantIds(input.participantIds, WORLD_NOTIFICATIONS_MAX_PARTICIPANTS, "participantIds", operation);
516
+ const templateId = assertWorldNotificationSafeKey(input.templateId, "templateId", operation);
517
+ const slots = input.slots === undefined
518
+ ? undefined
519
+ : normalizeWorldNotificationSlots(input.slots, operation);
520
+ const at = input.at === undefined
521
+ ? undefined
522
+ : assertWorldNotificationTime(input.at, "at", operation);
523
+ const atMs = at?.milliseconds ?? now;
524
+ if (atMs < now - WORLD_NOTIFICATIONS_PAST_TOLERANCE_MS ||
525
+ atMs > now + WORLD_NOTIFICATIONS_MAX_SCHEDULE_MS) {
526
+ throw worldJournalArgumentError("at must be no more than 60 seconds in the past and at most 30 days ahead.", operation);
527
+ }
528
+ // Ghost clamps a tolerated past `at` to its own now, so expiry is judged
529
+ // against that effective time, not the original timestamp.
530
+ const effectiveAtMs = Math.max(atMs, now);
531
+ const expiresAt = input.expiresAt === undefined
532
+ ? undefined
533
+ : assertWorldNotificationTime(input.expiresAt, "expiresAt", operation);
534
+ if (expiresAt &&
535
+ (expiresAt.milliseconds <= effectiveAtMs ||
536
+ expiresAt.milliseconds > effectiveAtMs + WORLD_NOTIFICATIONS_MAX_SCHEDULE_MS)) {
537
+ throw worldJournalArgumentError("expiresAt must be after at and at most 30 days after it.", operation);
538
+ }
539
+ const args = {
540
+ key,
541
+ participantIds,
542
+ templateId,
543
+ ...(slots === undefined ? {} : { slots }),
544
+ ...(at === undefined ? {} : { at: at.value }),
545
+ ...(expiresAt === undefined ? {} : { expiresAt: expiresAt.value }),
546
+ };
547
+ const result = parseWorldNotificationResult(await callWorldNotificationStorage(platformHandle, "worldNotify", args, operation), operation);
548
+ if (result.key !== key)
549
+ throw invalidWorldNotificationResponse(operation);
550
+ return Object.freeze({
551
+ key,
552
+ accepted: parseWorldNotificationCount(result.accepted, operation),
553
+ skipped: parseWorldNotificationCount(result.skipped, operation),
554
+ limited: parseWorldNotificationCount(result.limited, operation),
555
+ });
556
+ },
557
+ async cancel(input) {
558
+ const operation = "session.world.notifications.cancel";
559
+ assertOnlyKeys(input, ["key", "participantIds"], operation, "input");
560
+ const key = assertWorldNotificationSafeKey(input.key, "key", operation);
561
+ const participantIds = input.participantIds === undefined
562
+ ? undefined
563
+ : normalizeParticipantIds(input.participantIds, WORLD_NOTIFICATIONS_MAX_PARTICIPANTS, "participantIds", operation);
564
+ const args = {
565
+ key,
566
+ ...(participantIds === undefined ? {} : { participantIds }),
567
+ };
568
+ const result = parseWorldNotificationResult(await callWorldNotificationStorage(platformHandle, "worldNotifyCancel", args, operation), operation);
569
+ return Object.freeze({
570
+ cancelled: parseWorldNotificationCount(result.cancelled, operation),
571
+ });
572
+ },
573
+ });
574
+ }
575
+ function assertWorldNotificationSafeKey(value, field, operation) {
576
+ if (typeof value !== "string" ||
577
+ worldNotificationCharacters(value) < 1 ||
578
+ worldNotificationCharacters(value) > 64 ||
579
+ !SAFE_WORLD_NOTIFICATION_KEY.test(value)) {
580
+ throw worldJournalArgumentError(`${field} must be a safe key of at most 64 characters.`, operation);
581
+ }
582
+ return value;
583
+ }
584
+ function normalizeWorldNotificationSlots(value, operation) {
585
+ if (!isRecord(value)) {
586
+ throw worldJournalArgumentError("slots must be an object.", operation);
587
+ }
588
+ const entries = Object.entries(value);
589
+ if (entries.length > WORLD_NOTIFICATIONS_MAX_SLOTS) {
590
+ throw worldJournalArgumentError(`slots may contain at most ${WORLD_NOTIFICATIONS_MAX_SLOTS} values.`, operation);
591
+ }
592
+ const normalized = {};
593
+ for (const [key, slotValue] of entries.sort(([left], [right]) => left.localeCompare(right))) {
594
+ assertWorldNotificationSafeKey(key, `slots.${key}`, operation);
595
+ if (typeof slotValue !== "string" ||
596
+ worldNotificationCharacters(slotValue) < 1 ||
597
+ worldNotificationCharacters(slotValue) > WORLD_NOTIFICATIONS_MAX_SLOT_CHARACTERS ||
598
+ slotValue.includes("\0") ||
599
+ hasUnpairedSurrogate(slotValue) ||
600
+ slotValue.includes("\n") ||
601
+ slotValue.includes("\r") ||
602
+ URL_IN_WORLD_NOTIFICATION_TEXT.test(slotValue)) {
603
+ throw worldJournalArgumentError(`slots.${key} must be 1 through ${WORLD_NOTIFICATIONS_MAX_SLOT_CHARACTERS} ` +
604
+ "characters of single-line text without a URL.", operation);
605
+ }
606
+ normalized[key] = slotValue;
607
+ }
608
+ return Object.freeze(normalized);
609
+ }
610
+ function worldNotificationCharacters(value) {
611
+ return Array.from(value).length;
612
+ }
613
+ function assertWorldNotificationTime(value, field, operation) {
614
+ if (typeof value !== "string") {
615
+ throw worldJournalArgumentError(`${field} must be a canonical ISO 8601 time with at most millisecond precision.`, operation);
616
+ }
617
+ const match = CANONICAL_WORLD_NOTIFICATION_TIME.exec(value);
618
+ const milliseconds = Date.parse(value);
619
+ if (!match || !Number.isFinite(milliseconds)) {
620
+ throw worldJournalArgumentError(`${field} must be a canonical ISO 8601 time with at most millisecond precision.`, operation);
621
+ }
622
+ const normalized = new Date(milliseconds).toISOString();
623
+ const normalizedFraction = normalized.slice(20, 23);
624
+ if (normalized.slice(0, 19) !== match[1] ||
625
+ (match[2] === undefined
626
+ ? normalizedFraction !== "000"
627
+ : normalizedFraction !== match[2].padEnd(3, "0"))) {
628
+ throw worldJournalArgumentError(`${field} must be a canonical ISO 8601 time with at most millisecond precision.`, operation);
629
+ }
630
+ return { value, milliseconds };
631
+ }
632
+ async function callWorldNotificationStorage(platformHandle, op, args, operation) {
633
+ if (typeof platformHandle.storage !== "function" || platformHandle.storageEnabled === false) {
634
+ throw worldNotificationsUnavailable(operation);
635
+ }
636
+ try {
637
+ return await platformHandle.storage(op, JSON.stringify(args));
638
+ }
639
+ catch (error) {
640
+ if (isUnknownStorageOperation(error))
641
+ throw worldNotificationsUnavailable(operation);
642
+ throw error;
643
+ }
644
+ }
645
+ function worldNotificationsUnavailable(operation) {
646
+ return storageError("CAULDRON_WORLD_NOTIFICATIONS_UNAVAILABLE", "This Castle host does not support persistent-world notifications.", operation);
647
+ }
648
+ function parseWorldNotificationResult(value, operation) {
649
+ let result;
650
+ try {
651
+ result = JSON.parse(value);
652
+ }
653
+ catch {
654
+ throw invalidWorldNotificationResponse(operation);
655
+ }
656
+ if (!isRecord(result))
657
+ throw invalidWorldNotificationResponse(operation);
658
+ return result;
659
+ }
660
+ function parseWorldNotificationCount(value, operation) {
661
+ if (!Number.isSafeInteger(value) || value < 0) {
662
+ throw invalidWorldNotificationResponse(operation);
663
+ }
664
+ return value;
665
+ }
666
+ function invalidWorldNotificationResponse(operation) {
667
+ return new TypeError(`${operation}: The platform returned an invalid response.`);
668
+ }
385
669
  function normalizeWorldJournalAppendEntry(value, index, operation) {
386
670
  const field = `entries[${index}]`;
387
671
  assertOnlyKeys(value, ["kind", "disclosure", "participantIds", "data"], operation, field);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "castle-web-cli",
3
- "version": "0.4.228",
3
+ "version": "0.4.229",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/castle-xyz/castle-experimental-web.git"