@stamprally/core 0.19.0 → 0.20.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/dist/index.d.cts CHANGED
@@ -307,76 +307,51 @@ declare function parseAdminConfig(input: unknown): AdminRallyConfig;
307
307
  declare function safeParsePublicConfig(input: unknown): ParseResult<PublicRallyConfig>;
308
308
  declare function parsePublicConfig(input: unknown): PublicRallyConfig;
309
309
 
310
- declare function calculateDistanceMeters(aLat: number, aLon: number, bLat: number, bLon: number): number;
311
- declare function evaluateConditionDetailed(condition: CheckInCondition, context: VerificationContext): Result<ConditionMatch, ConditionMismatch>;
312
- declare function evaluateCondition(condition: CheckInCondition, context: VerificationContext): boolean;
313
- /** Derives a viewer-safe spot status without changing the supplied state. */
314
- declare function evaluateSpotStatus(spot: Pick<SpotItem, "id" | "prerequisites">, state: Pick<UserRallyState, "records">, options?: {
315
- readonly verifying?: boolean;
316
- }): SpotStatus;
317
- declare const getSpotStatus: typeof evaluateSpotStatus;
318
-
319
- declare function getOrderedSpots<TLocale extends string, TMeta extends Record<string, unknown>>(spots: ReadonlyArray<SpotItem<TLocale, TMeta>>): ReadonlyArray<SpotItem<TLocale, TMeta>>;
320
-
321
- interface StampRallyProgress {
322
- readonly acquired: number;
323
- readonly total: number;
324
- readonly percentage: number;
325
- readonly isCompleted: boolean;
326
- readonly nextAvailableSpots: ReadonlyArray<PublicSpotItem>;
327
- }
328
- declare function calculateProgress(state: StampRallyState, config: RallyConfig): StampRallyProgress;
329
-
330
- interface ClaimTicketOptions {
331
- readonly issuedAt?: string;
332
- readonly sequence?: number;
333
- }
334
- declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
335
- /** Creates a one-time ticket for a successful reward consumption. */
336
- declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
337
- declare function issueClaimTicketNumber(reward: Reward, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
338
-
339
- type ConflictResolutionPolicy = "authoritative_replay";
340
- /** Uses the server snapshot as the immutable replay baseline. */
341
- declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
342
-
343
- type RewardConsumeError = {
344
- readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
345
- readonly rewardId: string;
346
- } | {
347
- readonly code: "INVALID_PASSCODE";
348
- readonly rewardId: string;
349
- readonly message: string;
310
+ type SyncOperationAction = "CHECK_IN" | "CLAIM_REWARD";
311
+ type SyncOperationResult = {
312
+ readonly operationId: string;
313
+ readonly status: "ACCEPTED";
314
+ readonly resourceId: string;
315
+ readonly action: SyncOperationAction;
316
+ readonly appliedAt: number;
350
317
  } | {
351
- readonly code: "EXPIRED";
352
- readonly rewardId: string;
318
+ readonly operationId: string;
319
+ readonly status: "REJECTED_PERMANENT";
320
+ readonly resourceId: string;
321
+ readonly errorCode: string;
322
+ readonly reason: string;
353
323
  } | {
354
- readonly code: "USER_LIMIT_REACHED";
355
- readonly rewardId: string;
324
+ readonly operationId: string;
325
+ readonly status: "FAILED_RETRYABLE";
326
+ readonly resourceId: string;
327
+ readonly error: string;
356
328
  };
357
- interface ConsumeRewardParams {
358
- readonly reward: Reward;
359
- readonly currentState: RewardState;
360
- readonly inputPasscode?: string;
361
- readonly staffId?: string;
362
- readonly now: string;
363
- readonly userRedemptionCount?: number;
329
+ interface SyncProgressResponse {
330
+ readonly results: ReadonlyArray<SyncOperationResult>;
331
+ readonly currentState: UserRallyState;
332
+ readonly syncTimestamp: number;
364
333
  }
365
- type ConsumeResult = Result<RewardState, RewardConsumeError>;
366
- declare function reconcileRewardStates(rewards: ReadonlyArray<Reward>, currentStates: ReadonlyArray<RewardState>, acquiredStampCount: number, now: string): ReadonlyArray<RewardState>;
367
- declare function consumeReward(params: ConsumeRewardParams): ConsumeResult;
368
- interface ProcessStampValue {
369
- readonly nextState: StampRallyState;
370
- readonly events: ReadonlyArray<{
371
- readonly type: "stampAcquired";
372
- readonly record: StampRecord;
373
- }>;
334
+ interface RebuildUserStateOptions {
335
+ readonly baseline: UserRallyState;
336
+ readonly operations: ReadonlyArray<OfflineOperation>;
337
+ readonly config?: AdminRallyConfig | PublicRallyConfig;
374
338
  }
375
- declare function processStamp(state: StampRallyState, config: AdminRallyConfig, spotId: string, context: VerificationContext, now: string): Result<ProcessStampValue, StampError>;
339
+ interface RebuildUserStateResult {
340
+ readonly state: UserRallyState;
341
+ readonly rejectedOperationIds: ReadonlyArray<string>;
342
+ }
343
+ /** Replays the durable operation log on top of a server-confirmed baseline. */
344
+ declare function rebuildUserStateFromLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): UserRallyState;
345
+ declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): UserRallyState;
346
+ declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
376
347
 
377
348
  type QueueOperationStatus = "PENDING" | "IN_FLIGHT" | "ACCEPTED" | "REJECTED_PERMANENT" | "FAILED_RETRYABLE";
378
- type OfflineQueueCapability = "indexeddb" | "localstorage" | "memory" | "custom";
379
- type OfflineStorageCapability = OfflineQueueCapability | "volatile_single_tab";
349
+ type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "volatile_single_tab";
350
+ type MultiTabSyncCapability = "supported_web_locks" | "disabled_unsafe_environment";
351
+ interface OfflineQueueCapability {
352
+ readonly storage: OfflineStorageCapability;
353
+ readonly multiTabSync: MultiTabSyncCapability;
354
+ }
380
355
  type OfflineOperation = {
381
356
  readonly kind: "checkIn";
382
357
  readonly request: CheckInRequest;
@@ -407,6 +382,7 @@ interface OfflineQueueStorage {
407
382
  interface OfflineQueueCapabilityWarning {
408
383
  readonly type: "STORAGE_CAPABILITY_WARNING";
409
384
  readonly storageCapability: "volatile_single_tab" | "memory";
385
+ readonly multiTabSync: "disabled_unsafe_environment";
410
386
  readonly isStoragePersistent: boolean;
411
387
  readonly message: string;
412
388
  }
@@ -533,7 +509,76 @@ declare class OfflineQueue {
533
509
  clearRejectedHistory(): Promise<void>;
534
510
  sync(sender?: OfflineSender | undefined): Promise<void>;
535
511
  retrySync(sender?: OfflineSender | undefined): Promise<void>;
512
+ /** Applies a server-side batch response while preserving retryable operations. */
513
+ applySyncProgress(response: SyncProgressResponse): Promise<void>;
514
+ }
515
+
516
+ declare function calculateDistanceMeters(aLat: number, aLon: number, bLat: number, bLon: number): number;
517
+ declare function evaluateConditionDetailed(condition: CheckInCondition, context: VerificationContext): Result<ConditionMatch, ConditionMismatch>;
518
+ declare function evaluateCondition(condition: CheckInCondition, context: VerificationContext): boolean;
519
+ /** Derives a viewer-safe spot status without changing the supplied state. */
520
+ declare function evaluateSpotStatus(spot: Pick<SpotItem, "id" | "prerequisites">, state: Pick<UserRallyState, "records">, options?: {
521
+ readonly verifying?: boolean;
522
+ }): SpotStatus;
523
+ declare const getSpotStatus: typeof evaluateSpotStatus;
524
+
525
+ declare function getOrderedSpots<TLocale extends string, TMeta extends Record<string, unknown>>(spots: ReadonlyArray<SpotItem<TLocale, TMeta>>): ReadonlyArray<SpotItem<TLocale, TMeta>>;
526
+
527
+ interface StampRallyProgress {
528
+ readonly acquired: number;
529
+ readonly total: number;
530
+ readonly percentage: number;
531
+ readonly isCompleted: boolean;
532
+ readonly nextAvailableSpots: ReadonlyArray<PublicSpotItem>;
536
533
  }
534
+ declare function calculateProgress(state: StampRallyState, config: RallyConfig): StampRallyProgress;
535
+
536
+ interface ClaimTicketOptions {
537
+ readonly issuedAt?: string;
538
+ readonly sequence?: number;
539
+ }
540
+ declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
541
+ /** Creates a one-time ticket for a successful reward consumption. */
542
+ declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
543
+ declare function issueClaimTicketNumber(reward: Reward, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
544
+
545
+ type ConflictResolutionPolicy = "authoritative_replay";
546
+ /** Uses the server snapshot as the immutable replay baseline. */
547
+ declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
548
+
549
+ type RewardConsumeError = {
550
+ readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
551
+ readonly rewardId: string;
552
+ } | {
553
+ readonly code: "INVALID_PASSCODE";
554
+ readonly rewardId: string;
555
+ readonly message: string;
556
+ } | {
557
+ readonly code: "EXPIRED";
558
+ readonly rewardId: string;
559
+ } | {
560
+ readonly code: "USER_LIMIT_REACHED";
561
+ readonly rewardId: string;
562
+ };
563
+ interface ConsumeRewardParams {
564
+ readonly reward: Reward;
565
+ readonly currentState: RewardState;
566
+ readonly inputPasscode?: string;
567
+ readonly staffId?: string;
568
+ readonly now: string;
569
+ readonly userRedemptionCount?: number;
570
+ }
571
+ type ConsumeResult = Result<RewardState, RewardConsumeError>;
572
+ declare function reconcileRewardStates(rewards: ReadonlyArray<Reward>, currentStates: ReadonlyArray<RewardState>, acquiredStampCount: number, now: string): ReadonlyArray<RewardState>;
573
+ declare function consumeReward(params: ConsumeRewardParams): ConsumeResult;
574
+ interface ProcessStampValue {
575
+ readonly nextState: StampRallyState;
576
+ readonly events: ReadonlyArray<{
577
+ readonly type: "stampAcquired";
578
+ readonly record: StampRecord;
579
+ }>;
580
+ }
581
+ declare function processStamp(state: StampRallyState, config: AdminRallyConfig, spotId: string, context: VerificationContext, now: string): Result<ProcessStampValue, StampError>;
537
582
 
538
583
  interface StampStorage {
539
584
  load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
@@ -712,7 +757,8 @@ interface SyncAdapter {
712
757
  readonly userId: string | null;
713
758
  readonly state: UserRallyState;
714
759
  readonly anonymousSessionId?: string;
715
- }) => Promise<UserRallyState>;
760
+ readonly operations?: ReadonlyArray<OfflineOperation>;
761
+ }) => Promise<UserRallyState | SyncProgressResponse>;
716
762
  }
717
763
  interface ClientOptions {
718
764
  readonly storage?: StampStorage;
@@ -760,20 +806,6 @@ declare class StampRallyClient {
760
806
  restore(state: UserRallyState): Promise<UserRallyState>;
761
807
  }
762
808
 
763
- interface RebuildUserStateOptions {
764
- readonly baseline: UserRallyState;
765
- readonly operations: ReadonlyArray<OfflineOperation>;
766
- readonly config?: AdminRallyConfig | PublicRallyConfig;
767
- }
768
- interface RebuildUserStateResult {
769
- readonly state: UserRallyState;
770
- readonly rejectedOperationIds: ReadonlyArray<string>;
771
- }
772
- /** Replays the durable operation log on top of a server-confirmed baseline. */
773
- declare function rebuildUserStateFromLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): UserRallyState;
774
- declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): UserRallyState;
775
- declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
776
-
777
809
  type SecureTokenSecretKey = string | Uint8Array;
778
810
  interface SecureTokenOptions {
779
811
  readonly encrypt?: boolean;
@@ -879,4 +911,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
879
911
  declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
880
912
  declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
881
913
 
882
- export { type AdminRallyConfig, type CheckInCondition, type CheckInOptions, type CheckInRequest, type CheckInResult, type CheckInSuccess, type ClaimOptions, type ClaimRequest, type ClaimResult, type ClaimSuccess, type ClaimTicketOptions, type ClientError, type ClientEvent, type ClientEventListener, type ClientListener, type ClientOptions, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, ConfigValidationError, type ConflictResolutionPolicy, type ConsumeResult, type ConsumeRewardParams, type CustomValidationContext, type CustomValidator, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type NfcVerificationContext, type OfflineConflictResult, type OfflineOperation, type OfflineOperationError, type OfflineOperationLifecycleStatus, type OfflineOperationResponse, type OfflineOperationStatus, OfflineQueue, type OfflineQueueCapability, type OfflineQueueCapabilityWarning, type OfflineQueueChangeListener, type OfflineQueueOptions, type OfflineQueueStorage, type OfflineResult, type OfflineSender, type OfflineStorageCapability, type OfflineSyncResultEvent, type OfflineSyncResultListener, type ParseResult, type PasscodeCondition$1 as PasscodeCondition, type ProcessStampValue, type PublicCheckInCondition, type PublicConfigSafety, type PublicRallyConfig, type PublicReward, type PublicSpotItem, type QrDetectorOptions, type QrVerificationContext, type QueueOperationStatus, type RallyConfig, type RallyInventory, type RallyInventoryState, type RallySnapshot, type RebuildUserStateOptions, type RebuildUserStateResult, type RedemptionMethod, type RejectedOperation, type RejectedOperationHistoryEntry, type Result, type Reward, type RewardConsumeError, type RewardState, type RewardStatus, type RewardType, type RewardUnlockCondition, type SecureTokenError, type SecureTokenErrorCode, type SecureTokenOptions, type SecureTokenPayload, type SecureTokenSecretKey, type SecureTokenVerification, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type SpotStatus, type StampError, StampRallyClient, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, type SyncAdapter, type SyncConflictPolicy, type SyncEventListener, type SyncLifecycleEvent, type SyncRetryOptions, type SyncState, THEME_PRESETS, type ThemePreset, type ThemePresetId, type UserRallyState, type ValidationError, type Validator, type VerificationContext, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createAnonymousSessionId, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, evaluateSpotStatus, exportProgressToken, getCurrentGeoContext, getOrderedSpots, getSpotStatus, importProgressToken, isGeolocationSupported, isNfcSupported, isPublicConfig, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, normalizePasscode, offlineOperationId, parseAdminConfig, parsePublicConfig, processStamp, readNfcContext, readQrContext, rebuildUserStateFromLog, rebuildUserStateLog, reconcileRewardStates, resolveLocalizedText, resolveRallyStateConflict, rollbackOptimisticOperation, safeParseAdminConfig, safeParsePublicConfig, sanitizeAdminConfig, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
914
+ export { type AdminRallyConfig, type CheckInCondition, type CheckInOptions, type CheckInRequest, type CheckInResult, type CheckInSuccess, type ClaimOptions, type ClaimRequest, type ClaimResult, type ClaimSuccess, type ClaimTicketOptions, type ClientError, type ClientEvent, type ClientEventListener, type ClientListener, type ClientOptions, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, ConfigValidationError, type ConflictResolutionPolicy, type ConsumeResult, type ConsumeRewardParams, type CustomValidationContext, type CustomValidator, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type MultiTabSyncCapability, type NfcDetectorOptions, type NfcVerificationContext, type OfflineConflictResult, type OfflineOperation, type OfflineOperationError, type OfflineOperationLifecycleStatus, type OfflineOperationResponse, type OfflineOperationStatus, OfflineQueue, type OfflineQueueCapability, type OfflineQueueCapabilityWarning, type OfflineQueueChangeListener, type OfflineQueueOptions, type OfflineQueueStorage, type OfflineResult, type OfflineSender, type OfflineStorageCapability, type OfflineSyncResultEvent, type OfflineSyncResultListener, type ParseResult, type PasscodeCondition$1 as PasscodeCondition, type ProcessStampValue, type PublicCheckInCondition, type PublicConfigSafety, type PublicRallyConfig, type PublicReward, type PublicSpotItem, type QrDetectorOptions, type QrVerificationContext, type QueueOperationStatus, type RallyConfig, type RallyInventory, type RallyInventoryState, type RallySnapshot, type RebuildUserStateOptions, type RebuildUserStateResult, type RedemptionMethod, type RejectedOperation, type RejectedOperationHistoryEntry, type Result, type Reward, type RewardConsumeError, type RewardState, type RewardStatus, type RewardType, type RewardUnlockCondition, type SecureTokenError, type SecureTokenErrorCode, type SecureTokenOptions, type SecureTokenPayload, type SecureTokenSecretKey, type SecureTokenVerification, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type SpotStatus, type StampError, StampRallyClient, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, type SyncAdapter, type SyncConflictPolicy, type SyncEventListener, type SyncLifecycleEvent, type SyncOperationAction, type SyncOperationResult, type SyncProgressResponse, type SyncRetryOptions, type SyncState, THEME_PRESETS, type ThemePreset, type ThemePresetId, type UserRallyState, type ValidationError, type Validator, type VerificationContext, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createAnonymousSessionId, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, evaluateSpotStatus, exportProgressToken, getCurrentGeoContext, getOrderedSpots, getSpotStatus, importProgressToken, isGeolocationSupported, isNfcSupported, isPublicConfig, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, normalizePasscode, offlineOperationId, parseAdminConfig, parsePublicConfig, processStamp, readNfcContext, readQrContext, rebuildUserStateFromLog, rebuildUserStateLog, reconcileRewardStates, resolveLocalizedText, resolveRallyStateConflict, rollbackOptimisticOperation, safeParseAdminConfig, safeParsePublicConfig, sanitizeAdminConfig, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
package/dist/index.d.ts CHANGED
@@ -307,76 +307,51 @@ declare function parseAdminConfig(input: unknown): AdminRallyConfig;
307
307
  declare function safeParsePublicConfig(input: unknown): ParseResult<PublicRallyConfig>;
308
308
  declare function parsePublicConfig(input: unknown): PublicRallyConfig;
309
309
 
310
- declare function calculateDistanceMeters(aLat: number, aLon: number, bLat: number, bLon: number): number;
311
- declare function evaluateConditionDetailed(condition: CheckInCondition, context: VerificationContext): Result<ConditionMatch, ConditionMismatch>;
312
- declare function evaluateCondition(condition: CheckInCondition, context: VerificationContext): boolean;
313
- /** Derives a viewer-safe spot status without changing the supplied state. */
314
- declare function evaluateSpotStatus(spot: Pick<SpotItem, "id" | "prerequisites">, state: Pick<UserRallyState, "records">, options?: {
315
- readonly verifying?: boolean;
316
- }): SpotStatus;
317
- declare const getSpotStatus: typeof evaluateSpotStatus;
318
-
319
- declare function getOrderedSpots<TLocale extends string, TMeta extends Record<string, unknown>>(spots: ReadonlyArray<SpotItem<TLocale, TMeta>>): ReadonlyArray<SpotItem<TLocale, TMeta>>;
320
-
321
- interface StampRallyProgress {
322
- readonly acquired: number;
323
- readonly total: number;
324
- readonly percentage: number;
325
- readonly isCompleted: boolean;
326
- readonly nextAvailableSpots: ReadonlyArray<PublicSpotItem>;
327
- }
328
- declare function calculateProgress(state: StampRallyState, config: RallyConfig): StampRallyProgress;
329
-
330
- interface ClaimTicketOptions {
331
- readonly issuedAt?: string;
332
- readonly sequence?: number;
333
- }
334
- declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
335
- /** Creates a one-time ticket for a successful reward consumption. */
336
- declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
337
- declare function issueClaimTicketNumber(reward: Reward, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
338
-
339
- type ConflictResolutionPolicy = "authoritative_replay";
340
- /** Uses the server snapshot as the immutable replay baseline. */
341
- declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
342
-
343
- type RewardConsumeError = {
344
- readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
345
- readonly rewardId: string;
346
- } | {
347
- readonly code: "INVALID_PASSCODE";
348
- readonly rewardId: string;
349
- readonly message: string;
310
+ type SyncOperationAction = "CHECK_IN" | "CLAIM_REWARD";
311
+ type SyncOperationResult = {
312
+ readonly operationId: string;
313
+ readonly status: "ACCEPTED";
314
+ readonly resourceId: string;
315
+ readonly action: SyncOperationAction;
316
+ readonly appliedAt: number;
350
317
  } | {
351
- readonly code: "EXPIRED";
352
- readonly rewardId: string;
318
+ readonly operationId: string;
319
+ readonly status: "REJECTED_PERMANENT";
320
+ readonly resourceId: string;
321
+ readonly errorCode: string;
322
+ readonly reason: string;
353
323
  } | {
354
- readonly code: "USER_LIMIT_REACHED";
355
- readonly rewardId: string;
324
+ readonly operationId: string;
325
+ readonly status: "FAILED_RETRYABLE";
326
+ readonly resourceId: string;
327
+ readonly error: string;
356
328
  };
357
- interface ConsumeRewardParams {
358
- readonly reward: Reward;
359
- readonly currentState: RewardState;
360
- readonly inputPasscode?: string;
361
- readonly staffId?: string;
362
- readonly now: string;
363
- readonly userRedemptionCount?: number;
329
+ interface SyncProgressResponse {
330
+ readonly results: ReadonlyArray<SyncOperationResult>;
331
+ readonly currentState: UserRallyState;
332
+ readonly syncTimestamp: number;
364
333
  }
365
- type ConsumeResult = Result<RewardState, RewardConsumeError>;
366
- declare function reconcileRewardStates(rewards: ReadonlyArray<Reward>, currentStates: ReadonlyArray<RewardState>, acquiredStampCount: number, now: string): ReadonlyArray<RewardState>;
367
- declare function consumeReward(params: ConsumeRewardParams): ConsumeResult;
368
- interface ProcessStampValue {
369
- readonly nextState: StampRallyState;
370
- readonly events: ReadonlyArray<{
371
- readonly type: "stampAcquired";
372
- readonly record: StampRecord;
373
- }>;
334
+ interface RebuildUserStateOptions {
335
+ readonly baseline: UserRallyState;
336
+ readonly operations: ReadonlyArray<OfflineOperation>;
337
+ readonly config?: AdminRallyConfig | PublicRallyConfig;
374
338
  }
375
- declare function processStamp(state: StampRallyState, config: AdminRallyConfig, spotId: string, context: VerificationContext, now: string): Result<ProcessStampValue, StampError>;
339
+ interface RebuildUserStateResult {
340
+ readonly state: UserRallyState;
341
+ readonly rejectedOperationIds: ReadonlyArray<string>;
342
+ }
343
+ /** Replays the durable operation log on top of a server-confirmed baseline. */
344
+ declare function rebuildUserStateFromLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): UserRallyState;
345
+ declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): UserRallyState;
346
+ declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
376
347
 
377
348
  type QueueOperationStatus = "PENDING" | "IN_FLIGHT" | "ACCEPTED" | "REJECTED_PERMANENT" | "FAILED_RETRYABLE";
378
- type OfflineQueueCapability = "indexeddb" | "localstorage" | "memory" | "custom";
379
- type OfflineStorageCapability = OfflineQueueCapability | "volatile_single_tab";
349
+ type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "volatile_single_tab";
350
+ type MultiTabSyncCapability = "supported_web_locks" | "disabled_unsafe_environment";
351
+ interface OfflineQueueCapability {
352
+ readonly storage: OfflineStorageCapability;
353
+ readonly multiTabSync: MultiTabSyncCapability;
354
+ }
380
355
  type OfflineOperation = {
381
356
  readonly kind: "checkIn";
382
357
  readonly request: CheckInRequest;
@@ -407,6 +382,7 @@ interface OfflineQueueStorage {
407
382
  interface OfflineQueueCapabilityWarning {
408
383
  readonly type: "STORAGE_CAPABILITY_WARNING";
409
384
  readonly storageCapability: "volatile_single_tab" | "memory";
385
+ readonly multiTabSync: "disabled_unsafe_environment";
410
386
  readonly isStoragePersistent: boolean;
411
387
  readonly message: string;
412
388
  }
@@ -533,7 +509,76 @@ declare class OfflineQueue {
533
509
  clearRejectedHistory(): Promise<void>;
534
510
  sync(sender?: OfflineSender | undefined): Promise<void>;
535
511
  retrySync(sender?: OfflineSender | undefined): Promise<void>;
512
+ /** Applies a server-side batch response while preserving retryable operations. */
513
+ applySyncProgress(response: SyncProgressResponse): Promise<void>;
514
+ }
515
+
516
+ declare function calculateDistanceMeters(aLat: number, aLon: number, bLat: number, bLon: number): number;
517
+ declare function evaluateConditionDetailed(condition: CheckInCondition, context: VerificationContext): Result<ConditionMatch, ConditionMismatch>;
518
+ declare function evaluateCondition(condition: CheckInCondition, context: VerificationContext): boolean;
519
+ /** Derives a viewer-safe spot status without changing the supplied state. */
520
+ declare function evaluateSpotStatus(spot: Pick<SpotItem, "id" | "prerequisites">, state: Pick<UserRallyState, "records">, options?: {
521
+ readonly verifying?: boolean;
522
+ }): SpotStatus;
523
+ declare const getSpotStatus: typeof evaluateSpotStatus;
524
+
525
+ declare function getOrderedSpots<TLocale extends string, TMeta extends Record<string, unknown>>(spots: ReadonlyArray<SpotItem<TLocale, TMeta>>): ReadonlyArray<SpotItem<TLocale, TMeta>>;
526
+
527
+ interface StampRallyProgress {
528
+ readonly acquired: number;
529
+ readonly total: number;
530
+ readonly percentage: number;
531
+ readonly isCompleted: boolean;
532
+ readonly nextAvailableSpots: ReadonlyArray<PublicSpotItem>;
536
533
  }
534
+ declare function calculateProgress(state: StampRallyState, config: RallyConfig): StampRallyProgress;
535
+
536
+ interface ClaimTicketOptions {
537
+ readonly issuedAt?: string;
538
+ readonly sequence?: number;
539
+ }
540
+ declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
541
+ /** Creates a one-time ticket for a successful reward consumption. */
542
+ declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
543
+ declare function issueClaimTicketNumber(reward: Reward, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
544
+
545
+ type ConflictResolutionPolicy = "authoritative_replay";
546
+ /** Uses the server snapshot as the immutable replay baseline. */
547
+ declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
548
+
549
+ type RewardConsumeError = {
550
+ readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
551
+ readonly rewardId: string;
552
+ } | {
553
+ readonly code: "INVALID_PASSCODE";
554
+ readonly rewardId: string;
555
+ readonly message: string;
556
+ } | {
557
+ readonly code: "EXPIRED";
558
+ readonly rewardId: string;
559
+ } | {
560
+ readonly code: "USER_LIMIT_REACHED";
561
+ readonly rewardId: string;
562
+ };
563
+ interface ConsumeRewardParams {
564
+ readonly reward: Reward;
565
+ readonly currentState: RewardState;
566
+ readonly inputPasscode?: string;
567
+ readonly staffId?: string;
568
+ readonly now: string;
569
+ readonly userRedemptionCount?: number;
570
+ }
571
+ type ConsumeResult = Result<RewardState, RewardConsumeError>;
572
+ declare function reconcileRewardStates(rewards: ReadonlyArray<Reward>, currentStates: ReadonlyArray<RewardState>, acquiredStampCount: number, now: string): ReadonlyArray<RewardState>;
573
+ declare function consumeReward(params: ConsumeRewardParams): ConsumeResult;
574
+ interface ProcessStampValue {
575
+ readonly nextState: StampRallyState;
576
+ readonly events: ReadonlyArray<{
577
+ readonly type: "stampAcquired";
578
+ readonly record: StampRecord;
579
+ }>;
580
+ }
581
+ declare function processStamp(state: StampRallyState, config: AdminRallyConfig, spotId: string, context: VerificationContext, now: string): Result<ProcessStampValue, StampError>;
537
582
 
538
583
  interface StampStorage {
539
584
  load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
@@ -712,7 +757,8 @@ interface SyncAdapter {
712
757
  readonly userId: string | null;
713
758
  readonly state: UserRallyState;
714
759
  readonly anonymousSessionId?: string;
715
- }) => Promise<UserRallyState>;
760
+ readonly operations?: ReadonlyArray<OfflineOperation>;
761
+ }) => Promise<UserRallyState | SyncProgressResponse>;
716
762
  }
717
763
  interface ClientOptions {
718
764
  readonly storage?: StampStorage;
@@ -760,20 +806,6 @@ declare class StampRallyClient {
760
806
  restore(state: UserRallyState): Promise<UserRallyState>;
761
807
  }
762
808
 
763
- interface RebuildUserStateOptions {
764
- readonly baseline: UserRallyState;
765
- readonly operations: ReadonlyArray<OfflineOperation>;
766
- readonly config?: AdminRallyConfig | PublicRallyConfig;
767
- }
768
- interface RebuildUserStateResult {
769
- readonly state: UserRallyState;
770
- readonly rejectedOperationIds: ReadonlyArray<string>;
771
- }
772
- /** Replays the durable operation log on top of a server-confirmed baseline. */
773
- declare function rebuildUserStateFromLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): UserRallyState;
774
- declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): UserRallyState;
775
- declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
776
-
777
809
  type SecureTokenSecretKey = string | Uint8Array;
778
810
  interface SecureTokenOptions {
779
811
  readonly encrypt?: boolean;
@@ -879,4 +911,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
879
911
  declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
880
912
  declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
881
913
 
882
- export { type AdminRallyConfig, type CheckInCondition, type CheckInOptions, type CheckInRequest, type CheckInResult, type CheckInSuccess, type ClaimOptions, type ClaimRequest, type ClaimResult, type ClaimSuccess, type ClaimTicketOptions, type ClientError, type ClientEvent, type ClientEventListener, type ClientListener, type ClientOptions, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, ConfigValidationError, type ConflictResolutionPolicy, type ConsumeResult, type ConsumeRewardParams, type CustomValidationContext, type CustomValidator, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type NfcVerificationContext, type OfflineConflictResult, type OfflineOperation, type OfflineOperationError, type OfflineOperationLifecycleStatus, type OfflineOperationResponse, type OfflineOperationStatus, OfflineQueue, type OfflineQueueCapability, type OfflineQueueCapabilityWarning, type OfflineQueueChangeListener, type OfflineQueueOptions, type OfflineQueueStorage, type OfflineResult, type OfflineSender, type OfflineStorageCapability, type OfflineSyncResultEvent, type OfflineSyncResultListener, type ParseResult, type PasscodeCondition$1 as PasscodeCondition, type ProcessStampValue, type PublicCheckInCondition, type PublicConfigSafety, type PublicRallyConfig, type PublicReward, type PublicSpotItem, type QrDetectorOptions, type QrVerificationContext, type QueueOperationStatus, type RallyConfig, type RallyInventory, type RallyInventoryState, type RallySnapshot, type RebuildUserStateOptions, type RebuildUserStateResult, type RedemptionMethod, type RejectedOperation, type RejectedOperationHistoryEntry, type Result, type Reward, type RewardConsumeError, type RewardState, type RewardStatus, type RewardType, type RewardUnlockCondition, type SecureTokenError, type SecureTokenErrorCode, type SecureTokenOptions, type SecureTokenPayload, type SecureTokenSecretKey, type SecureTokenVerification, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type SpotStatus, type StampError, StampRallyClient, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, type SyncAdapter, type SyncConflictPolicy, type SyncEventListener, type SyncLifecycleEvent, type SyncRetryOptions, type SyncState, THEME_PRESETS, type ThemePreset, type ThemePresetId, type UserRallyState, type ValidationError, type Validator, type VerificationContext, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createAnonymousSessionId, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, evaluateSpotStatus, exportProgressToken, getCurrentGeoContext, getOrderedSpots, getSpotStatus, importProgressToken, isGeolocationSupported, isNfcSupported, isPublicConfig, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, normalizePasscode, offlineOperationId, parseAdminConfig, parsePublicConfig, processStamp, readNfcContext, readQrContext, rebuildUserStateFromLog, rebuildUserStateLog, reconcileRewardStates, resolveLocalizedText, resolveRallyStateConflict, rollbackOptimisticOperation, safeParseAdminConfig, safeParsePublicConfig, sanitizeAdminConfig, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
914
+ export { type AdminRallyConfig, type CheckInCondition, type CheckInOptions, type CheckInRequest, type CheckInResult, type CheckInSuccess, type ClaimOptions, type ClaimRequest, type ClaimResult, type ClaimSuccess, type ClaimTicketOptions, type ClientError, type ClientEvent, type ClientEventListener, type ClientListener, type ClientOptions, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, ConfigValidationError, type ConflictResolutionPolicy, type ConsumeResult, type ConsumeRewardParams, type CustomValidationContext, type CustomValidator, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type MultiTabSyncCapability, type NfcDetectorOptions, type NfcVerificationContext, type OfflineConflictResult, type OfflineOperation, type OfflineOperationError, type OfflineOperationLifecycleStatus, type OfflineOperationResponse, type OfflineOperationStatus, OfflineQueue, type OfflineQueueCapability, type OfflineQueueCapabilityWarning, type OfflineQueueChangeListener, type OfflineQueueOptions, type OfflineQueueStorage, type OfflineResult, type OfflineSender, type OfflineStorageCapability, type OfflineSyncResultEvent, type OfflineSyncResultListener, type ParseResult, type PasscodeCondition$1 as PasscodeCondition, type ProcessStampValue, type PublicCheckInCondition, type PublicConfigSafety, type PublicRallyConfig, type PublicReward, type PublicSpotItem, type QrDetectorOptions, type QrVerificationContext, type QueueOperationStatus, type RallyConfig, type RallyInventory, type RallyInventoryState, type RallySnapshot, type RebuildUserStateOptions, type RebuildUserStateResult, type RedemptionMethod, type RejectedOperation, type RejectedOperationHistoryEntry, type Result, type Reward, type RewardConsumeError, type RewardState, type RewardStatus, type RewardType, type RewardUnlockCondition, type SecureTokenError, type SecureTokenErrorCode, type SecureTokenOptions, type SecureTokenPayload, type SecureTokenSecretKey, type SecureTokenVerification, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type SpotStatus, type StampError, StampRallyClient, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, type SyncAdapter, type SyncConflictPolicy, type SyncEventListener, type SyncLifecycleEvent, type SyncOperationAction, type SyncOperationResult, type SyncProgressResponse, type SyncRetryOptions, type SyncState, THEME_PRESETS, type ThemePreset, type ThemePresetId, type UserRallyState, type ValidationError, type Validator, type VerificationContext, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createAnonymousSessionId, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, evaluateSpotStatus, exportProgressToken, getCurrentGeoContext, getOrderedSpots, getSpotStatus, importProgressToken, isGeolocationSupported, isNfcSupported, isPublicConfig, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, normalizePasscode, offlineOperationId, parseAdminConfig, parsePublicConfig, processStamp, readNfcContext, readQrContext, rebuildUserStateFromLog, rebuildUserStateLog, reconcileRewardStates, resolveLocalizedText, resolveRallyStateConflict, rollbackOptimisticOperation, safeParseAdminConfig, safeParsePublicConfig, sanitizeAdminConfig, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };