@stamprally/core 0.20.1 → 0.22.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
@@ -346,12 +346,22 @@ declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): User
346
346
  declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
347
347
 
348
348
  type QueueOperationStatus = "PENDING" | "IN_FLIGHT" | "ACCEPTED" | "REJECTED_PERMANENT" | "FAILED_RETRYABLE";
349
- type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "volatile_single_tab";
349
+ type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "disabled" | "volatile_single_tab";
350
350
  type MultiTabSyncCapability = "supported_web_locks" | "disabled_unsafe_environment";
351
- interface OfflineQueueCapability {
352
- readonly storage: OfflineStorageCapability;
351
+ type QueueCapabilityMode = "persistent" | "volatile_memory";
352
+ type LegacyQueueCapability = "persistent" | "volatile";
353
+ type LegacyQueueCapabilityString = "indexeddb" | "localstorage" | "memory" | "custom" | "disabled";
354
+ interface QueueCapabilitiesDetail {
355
+ readonly storageType: "indexeddb" | "localstorage" | "memory" | "custom" | "none";
356
+ readonly isPersistent: boolean;
353
357
  readonly multiTabSync: MultiTabSyncCapability;
354
358
  }
359
+ /** The legacy string exposed by `queueCapability`. */
360
+ type QueueCapability = LegacyQueueCapabilityString;
361
+ /** @deprecated Use LegacyQueueCapabilityString. */
362
+ type OfflineQueueCapability = LegacyQueueCapabilityString;
363
+ /** @deprecated Use the string value of `queueCapability` directly. */
364
+ declare function getLegacyQueueCapability(capability: LegacyQueueCapabilityString | QueueCapabilitiesDetail): LegacyQueueCapability;
355
365
  type OfflineOperation = {
356
366
  readonly kind: "checkIn";
357
367
  readonly request: CheckInRequest;
@@ -478,7 +488,8 @@ declare class OfflineQueue {
478
488
  constructor(options?: OfflineQueueOptions);
479
489
  get syncState(): SyncState;
480
490
  get pendingCount(): number;
481
- get queueCapability(): OfflineQueueCapability;
491
+ get queueCapability(): QueueCapability;
492
+ get queueCapabilities(): QueueCapabilitiesDetail;
482
493
  get storageCapability(): OfflineStorageCapability;
483
494
  get isStoragePersistent(): boolean;
484
495
  get rejectedHistory(): ReadonlyArray<RejectedOperationHistoryEntry>;
@@ -546,6 +557,12 @@ type ConflictResolutionPolicy = "authoritative_replay";
546
557
  /** Uses the server snapshot as the immutable replay baseline. */
547
558
  declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
548
559
 
560
+ interface DeterministicallySortableOperation {
561
+ readonly operationId: string;
562
+ readonly timestamp: number;
563
+ }
564
+ /** Sorts operations independently of queue insertion order or network arrival order. */
565
+ declare function sortOperationsDeterministically<T extends DeterministicallySortableOperation>(operations: ReadonlyArray<T>): T[];
549
566
  type RewardConsumeError = {
550
567
  readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
551
568
  readonly rewardId: string;
@@ -768,7 +785,7 @@ interface ClientOptions {
768
785
  readonly clock?: () => string;
769
786
  readonly userId?: string | null;
770
787
  readonly anonymousSessionId?: string;
771
- readonly offlineQueue?: OfflineQueue;
788
+ readonly offlineQueue?: OfflineQueue | false;
772
789
  }
773
790
  type StorageOrOptions = StampStorage | ClientOptions;
774
791
  declare class StampRallyClient {
@@ -782,7 +799,8 @@ declare class StampRallyClient {
782
799
  get pendingCount(): number;
783
800
  get rejectedHistory(): ReadonlyArray<RejectedOperationHistoryEntry>;
784
801
  getSyncRevision(): number;
785
- get queueCapability(): OfflineQueueCapability;
802
+ get queueCapability(): QueueCapability;
803
+ get queueCapabilities(): QueueCapabilitiesDetail;
786
804
  get storageCapability(): OfflineStorageCapability;
787
805
  get isStoragePersistent(): boolean;
788
806
  discardRejected(operationId: string): Promise<boolean>;
@@ -911,4 +929,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
911
929
  declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
912
930
  declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
913
931
 
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 };
932
+ 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 DeterministicallySortableOperation, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, type LegacyQueueCapability, type LegacyQueueCapabilityString, 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 QueueCapabilitiesDetail, type QueueCapability, type QueueCapabilityMode, 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, getLegacyQueueCapability, 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, sortOperationsDeterministically, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
package/dist/index.d.ts CHANGED
@@ -346,12 +346,22 @@ declare function rebuildUserStateFromLog(options: RebuildUserStateOptions): User
346
346
  declare function rebuildUserStateLog(baseline: UserRallyState, operations: ReadonlyArray<OfflineOperation>, config?: AdminRallyConfig | PublicRallyConfig): RebuildUserStateResult;
347
347
 
348
348
  type QueueOperationStatus = "PENDING" | "IN_FLIGHT" | "ACCEPTED" | "REJECTED_PERMANENT" | "FAILED_RETRYABLE";
349
- type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "volatile_single_tab";
349
+ type OfflineStorageCapability = "indexeddb" | "localstorage" | "memory" | "custom" | "disabled" | "volatile_single_tab";
350
350
  type MultiTabSyncCapability = "supported_web_locks" | "disabled_unsafe_environment";
351
- interface OfflineQueueCapability {
352
- readonly storage: OfflineStorageCapability;
351
+ type QueueCapabilityMode = "persistent" | "volatile_memory";
352
+ type LegacyQueueCapability = "persistent" | "volatile";
353
+ type LegacyQueueCapabilityString = "indexeddb" | "localstorage" | "memory" | "custom" | "disabled";
354
+ interface QueueCapabilitiesDetail {
355
+ readonly storageType: "indexeddb" | "localstorage" | "memory" | "custom" | "none";
356
+ readonly isPersistent: boolean;
353
357
  readonly multiTabSync: MultiTabSyncCapability;
354
358
  }
359
+ /** The legacy string exposed by `queueCapability`. */
360
+ type QueueCapability = LegacyQueueCapabilityString;
361
+ /** @deprecated Use LegacyQueueCapabilityString. */
362
+ type OfflineQueueCapability = LegacyQueueCapabilityString;
363
+ /** @deprecated Use the string value of `queueCapability` directly. */
364
+ declare function getLegacyQueueCapability(capability: LegacyQueueCapabilityString | QueueCapabilitiesDetail): LegacyQueueCapability;
355
365
  type OfflineOperation = {
356
366
  readonly kind: "checkIn";
357
367
  readonly request: CheckInRequest;
@@ -478,7 +488,8 @@ declare class OfflineQueue {
478
488
  constructor(options?: OfflineQueueOptions);
479
489
  get syncState(): SyncState;
480
490
  get pendingCount(): number;
481
- get queueCapability(): OfflineQueueCapability;
491
+ get queueCapability(): QueueCapability;
492
+ get queueCapabilities(): QueueCapabilitiesDetail;
482
493
  get storageCapability(): OfflineStorageCapability;
483
494
  get isStoragePersistent(): boolean;
484
495
  get rejectedHistory(): ReadonlyArray<RejectedOperationHistoryEntry>;
@@ -546,6 +557,12 @@ type ConflictResolutionPolicy = "authoritative_replay";
546
557
  /** Uses the server snapshot as the immutable replay baseline. */
547
558
  declare function resolveRallyStateConflict(serverState: UserRallyState, _localState: UserRallyState): UserRallyState;
548
559
 
560
+ interface DeterministicallySortableOperation {
561
+ readonly operationId: string;
562
+ readonly timestamp: number;
563
+ }
564
+ /** Sorts operations independently of queue insertion order or network arrival order. */
565
+ declare function sortOperationsDeterministically<T extends DeterministicallySortableOperation>(operations: ReadonlyArray<T>): T[];
549
566
  type RewardConsumeError = {
550
567
  readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
551
568
  readonly rewardId: string;
@@ -768,7 +785,7 @@ interface ClientOptions {
768
785
  readonly clock?: () => string;
769
786
  readonly userId?: string | null;
770
787
  readonly anonymousSessionId?: string;
771
- readonly offlineQueue?: OfflineQueue;
788
+ readonly offlineQueue?: OfflineQueue | false;
772
789
  }
773
790
  type StorageOrOptions = StampStorage | ClientOptions;
774
791
  declare class StampRallyClient {
@@ -782,7 +799,8 @@ declare class StampRallyClient {
782
799
  get pendingCount(): number;
783
800
  get rejectedHistory(): ReadonlyArray<RejectedOperationHistoryEntry>;
784
801
  getSyncRevision(): number;
785
- get queueCapability(): OfflineQueueCapability;
802
+ get queueCapability(): QueueCapability;
803
+ get queueCapabilities(): QueueCapabilitiesDetail;
786
804
  get storageCapability(): OfflineStorageCapability;
787
805
  get isStoragePersistent(): boolean;
788
806
  discardRejected(operationId: string): Promise<boolean>;
@@ -911,4 +929,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
911
929
  declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
912
930
  declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
913
931
 
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 };
932
+ 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 DeterministicallySortableOperation, type ExternalReference, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, type IndexedDBOfflineQueueOptions, IndexedDBOfflineQueueStorage, type InventoryAggregationMode, type LegacyQueueCapability, type LegacyQueueCapabilityString, 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 QueueCapabilitiesDetail, type QueueCapability, type QueueCapabilityMode, 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, getLegacyQueueCapability, 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, sortOperationsDeterministically, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
package/dist/index.js CHANGED
@@ -455,6 +455,12 @@ async function readQrContext(videoElement, options = {}) {
455
455
  }
456
456
 
457
457
  // src/engine/transition.ts
458
+ function sortOperationsDeterministically(operations) {
459
+ return [...operations].sort((left, right) => {
460
+ if (left.timestamp !== right.timestamp) return left.timestamp - right.timestamp;
461
+ return left.operationId.localeCompare(right.operationId);
462
+ });
463
+ }
458
464
  function reconcileRewardStates(rewards, currentStates, acquiredStampCount, now) {
459
465
  const states = new Map(currentStates.map((state) => [state.rewardId, state]));
460
466
  return rewards.map((reward2) => {
@@ -1005,6 +1011,11 @@ var IndexedDBAdapter = class {
1005
1011
  };
1006
1012
 
1007
1013
  // src/client/offlineQueue.ts
1014
+ function getLegacyQueueCapability(capability) {
1015
+ if (typeof capability === "string")
1016
+ return capability === "memory" || capability === "disabled" ? "volatile" : "persistent";
1017
+ return capability.isPersistent ? "persistent" : "volatile";
1018
+ }
1008
1019
  function rollbackOptimisticOperation(state, operation) {
1009
1020
  const previous = operation.request.state;
1010
1021
  if (operation.kind === "checkIn") {
@@ -1263,8 +1274,14 @@ var OfflineQueue = class {
1263
1274
  return this.#operations.length;
1264
1275
  }
1265
1276
  get queueCapability() {
1277
+ return this.#queueCapability;
1278
+ }
1279
+ get queueCapabilities() {
1280
+ const storageType = this.#queueCapability;
1281
+ const isPersistent = storageType !== "memory";
1266
1282
  return {
1267
- storage: this.#queueCapability,
1283
+ storageType,
1284
+ isPersistent,
1268
1285
  multiTabSync: this.#hasWebLocks() ? "supported_web_locks" : "disabled_unsafe_environment"
1269
1286
  };
1270
1287
  }
@@ -1323,7 +1340,7 @@ var OfflineQueue = class {
1323
1340
  }
1324
1341
  if (this.#queueCapability === "memory")
1325
1342
  this.#warnCapability("Offline queue persistence is unavailable; queued data is memory-only.");
1326
- if (this.queueCapability.multiTabSync === "disabled_unsafe_environment")
1343
+ if (this.queueCapabilities.multiTabSync === "disabled_unsafe_environment")
1327
1344
  this.#warnCapability(
1328
1345
  "Web Locks is unavailable; automatic cross-tab synchronization is disabled. Sync must be triggered by the foreground tab."
1329
1346
  );
@@ -1761,8 +1778,11 @@ function isReplayable(operation) {
1761
1778
  return operation.status === void 0 || operation.status === "ACCEPTED" || operation.status === "PENDING" || operation.status === "IN_FLIGHT" || operation.status === "FAILED_RETRYABLE";
1762
1779
  }
1763
1780
  function operationId(operation) {
1764
- const identity = operation.request.userId ?? operation.request.anonymousSessionId ?? "anonymous";
1765
- return `${operation.kind}:${operation.request.rallyId}:${identity}:${operation.request.idempotencyKey}`;
1781
+ return offlineOperationId(operation);
1782
+ }
1783
+ function operationTimestamp(operation) {
1784
+ const parsed = Date.parse(operation.request.now);
1785
+ return Number.isFinite(parsed) ? parsed : Number.MAX_SAFE_INTEGER;
1766
1786
  }
1767
1787
  function applyInventoryDelta(state, previous, optimistic) {
1768
1788
  const previousInventory = previous.inventory;
@@ -1838,12 +1858,19 @@ function rebuildUserStateFromLog(baselineOrOptions, operationsArgument, configAr
1838
1858
  function rebuildUserStateLog(baseline, operations, config) {
1839
1859
  let state = cloneState(baseline);
1840
1860
  const rejectedOperationIds = [];
1861
+ const sortedOperations = sortOperationsDeterministically(
1862
+ operations.map((operation) => ({
1863
+ operation,
1864
+ operationId: offlineOperationId(operation),
1865
+ timestamp: operationTimestamp(operation)
1866
+ }))
1867
+ ).map(({ operation }) => operation);
1841
1868
  const rejectedCheckIns = new Set(
1842
- operations.filter(
1869
+ sortedOperations.filter(
1843
1870
  (operation) => operation.status === "REJECTED_PERMANENT" && operation.kind === "checkIn"
1844
1871
  ).map((operation) => operation.kind === "checkIn" ? operation.request.spotId : void 0).filter((spotId) => spotId !== void 0)
1845
1872
  );
1846
- for (const operation of operations) {
1873
+ for (const operation of sortedOperations) {
1847
1874
  if (operation.status === "REJECTED_PERMANENT") {
1848
1875
  if (operation.kind === "checkIn") rejectedCheckIns.add(operation.request.spotId);
1849
1876
  continue;
@@ -1951,7 +1978,7 @@ var StampRallyClient = class {
1951
1978
  this.#storage = this.#options.storage ?? new InMemoryStorage();
1952
1979
  this.#anonymousSessionId = this.#options.anonymousSessionId ?? createAnonymousSessionId();
1953
1980
  this.#userId = this.#options.userId ?? this.#anonymousSessionId;
1954
- this.#offlineQueue = this.#options.offlineQueue;
1981
+ this.#offlineQueue = this.#options.offlineQueue === false ? void 0 : this.#options.offlineQueue;
1955
1982
  this.#offlineQueue?.setReplayConfig(config);
1956
1983
  this.#offlineQueue?.setSyncResultListener((event) => this.#handleOfflineSyncResult(event));
1957
1984
  this.#offlineQueue?.setCapabilityWarningListener(
@@ -1987,16 +2014,20 @@ var StampRallyClient = class {
1987
2014
  return this.#syncRevision;
1988
2015
  }
1989
2016
  get queueCapability() {
1990
- return this.#offlineQueue?.queueCapability ?? {
1991
- storage: "custom",
2017
+ return this.#offlineQueue?.queueCapability ?? "disabled";
2018
+ }
2019
+ get queueCapabilities() {
2020
+ return this.#offlineQueue?.queueCapabilities ?? {
2021
+ storageType: "none",
2022
+ isPersistent: false,
1992
2023
  multiTabSync: "disabled_unsafe_environment"
1993
2024
  };
1994
2025
  }
1995
2026
  get storageCapability() {
1996
- return this.#offlineQueue?.storageCapability ?? "custom";
2027
+ return this.#offlineQueue?.storageCapability ?? "disabled";
1997
2028
  }
1998
2029
  get isStoragePersistent() {
1999
- return this.#offlineQueue?.isStoragePersistent ?? true;
2030
+ return this.#offlineQueue?.isStoragePersistent ?? false;
2000
2031
  }
2001
2032
  discardRejected(operationId2) {
2002
2033
  return this.#offlineQueue?.discardRejected(operationId2) ?? Promise.resolve(false);
@@ -3454,6 +3485,6 @@ async function verifySnapshotToken(token, secretKey, now = Date.now()) {
3454
3485
  }
3455
3486
  }
3456
3487
 
3457
- export { ConfigValidationError, DEFAULT_SHEET_THEME, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, IndexedDBOfflineQueueStorage, LocalStorageAdapter, OfflineQueue, StampRallyClient, StorageAdapterError, THEME_PRESETS, 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 };
3488
+ export { ConfigValidationError, DEFAULT_SHEET_THEME, MemoryQueueStorage as InMemoryOfflineQueueStorage, InMemoryStorage, IndexedDBAdapter, IndexedDBOfflineQueueStorage, LocalStorageAdapter, OfflineQueue, StampRallyClient, StorageAdapterError, THEME_PRESETS, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createAnonymousSessionId, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, evaluateSpotStatus, exportProgressToken, getCurrentGeoContext, getLegacyQueueCapability, 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, sortOperationsDeterministically, storageKey, toLocalizedString, toPublicConfig, updateLocalizedField, validatePublicConfigSafety, validateRallyConfigRelations, verifyPasscode, verifySecureToken, verifySnapshotToken };
3458
3489
  //# sourceMappingURL=index.js.map
3459
3490
  //# sourceMappingURL=index.js.map