@stamprally/core 0.3.0 → 0.5.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.cjs +263 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -3
- package/dist/index.d.ts +74 -3
- package/dist/index.js +261 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -113,6 +113,7 @@ type Result<T, E> = {
|
|
|
113
113
|
type SupportedLocale = "ja" | "en";
|
|
114
114
|
type LocalizedString<TLocale extends string = SupportedLocale> = Record<TLocale, string>;
|
|
115
115
|
type LocalizedText<TLocale extends string = string> = string | Partial<Record<TLocale, string>>;
|
|
116
|
+
type LocaleDictionary<TLocale extends string = string> = Readonly<Record<TLocale, Readonly<Record<string, string>>>>;
|
|
116
117
|
type SlotShape = "circle" | "square" | "rounded";
|
|
117
118
|
type FontFamily = "system-ui" | "serif" | "rounded-sans" | "monospace" | "handwritten";
|
|
118
119
|
interface SheetTheme {
|
|
@@ -141,6 +142,7 @@ interface SpotItem<TLocale extends string = SupportedLocale, TMeta extends Recor
|
|
|
141
142
|
readonly description?: LocalizedText<TLocale>;
|
|
142
143
|
readonly hint?: LocalizedText<TLocale>;
|
|
143
144
|
readonly condition: StampCondition;
|
|
145
|
+
readonly orderIndex?: number;
|
|
144
146
|
readonly order?: number;
|
|
145
147
|
readonly deckId?: string;
|
|
146
148
|
readonly groupId?: string;
|
|
@@ -161,7 +163,20 @@ interface StampRecord {
|
|
|
161
163
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
162
164
|
}
|
|
163
165
|
type RewardType = "digital" | "in_person";
|
|
164
|
-
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only";
|
|
166
|
+
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only" | "server_claim";
|
|
167
|
+
type RewardUnlockCondition = {
|
|
168
|
+
readonly type: "stamp_count";
|
|
169
|
+
readonly count: number;
|
|
170
|
+
} | {
|
|
171
|
+
readonly type: "stamps";
|
|
172
|
+
readonly stampIds: ReadonlyArray<string>;
|
|
173
|
+
} | {
|
|
174
|
+
readonly type: "group_complete";
|
|
175
|
+
readonly groupId: string;
|
|
176
|
+
} | {
|
|
177
|
+
readonly type: "all" | "any";
|
|
178
|
+
readonly conditions: ReadonlyArray<RewardUnlockCondition>;
|
|
179
|
+
};
|
|
165
180
|
type RewardStatus = "LOCKED" | "AVAILABLE" | "CONSUMED" | "EXPIRED";
|
|
166
181
|
interface RewardItem<TLocale extends string = SupportedLocale> {
|
|
167
182
|
readonly id: string;
|
|
@@ -170,9 +185,12 @@ interface RewardItem<TLocale extends string = SupportedLocale> {
|
|
|
170
185
|
readonly type: RewardType;
|
|
171
186
|
readonly redemptionMethod: RedemptionMethod;
|
|
172
187
|
readonly requiredStampCount: number;
|
|
188
|
+
readonly conditions?: ReadonlyArray<RewardUnlockCondition>;
|
|
173
189
|
readonly digitalContentUrl?: string;
|
|
174
190
|
readonly staffPasscode?: string;
|
|
175
191
|
readonly validUntil?: string;
|
|
192
|
+
readonly stockLimit?: number;
|
|
193
|
+
readonly userClaimLimit?: number;
|
|
176
194
|
readonly maxStock?: number;
|
|
177
195
|
readonly limitPerUser?: number;
|
|
178
196
|
readonly claimTicketNumber?: string;
|
|
@@ -210,7 +228,7 @@ declare function resolveLocalizedText<TLocale extends string = SupportedLocale>(
|
|
|
210
228
|
declare function toLocalizedString(text: LocalizedText | undefined): LocalizedString;
|
|
211
229
|
declare function toLocalizedString<TLocale extends string>(text: LocalizedText<TLocale> | undefined): LocalizedString<TLocale>;
|
|
212
230
|
|
|
213
|
-
declare function migrateRallyConfig(raw: unknown): RallyConfig
|
|
231
|
+
declare function migrateRallyConfig<TLocale extends string = SupportedLocale>(raw: unknown): RallyConfig<TLocale>;
|
|
214
232
|
|
|
215
233
|
type PublicRewardItem<TLocale extends string = string> = Omit<RewardItem<TLocale>, "staffPasscode">;
|
|
216
234
|
type PublicRallyConfig<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> = Omit<RallyConfig<TLocale, TMeta>, "rewards"> & {
|
|
@@ -279,6 +297,8 @@ interface ClaimTicketOptions {
|
|
|
279
297
|
readonly sequence?: number;
|
|
280
298
|
}
|
|
281
299
|
declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
|
|
300
|
+
/** Creates a one-time ticket for a successful reward consumption. */
|
|
301
|
+
declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
|
|
282
302
|
declare function issueClaimTicketNumber(reward: RewardItem, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
|
|
283
303
|
|
|
284
304
|
type StampRallyEvent = {
|
|
@@ -309,12 +329,14 @@ type RewardConsumeError = {
|
|
|
309
329
|
readonly message: string;
|
|
310
330
|
} | {
|
|
311
331
|
readonly code: "EXPIRED";
|
|
332
|
+
readonly reason: "EXPIRED";
|
|
312
333
|
readonly rewardId: string;
|
|
313
334
|
} | {
|
|
314
335
|
readonly code: "OUT_OF_STOCK";
|
|
315
336
|
readonly rewardId: string;
|
|
316
337
|
} | {
|
|
317
338
|
readonly code: "USER_LIMIT_REACHED";
|
|
339
|
+
readonly reason: "LIMIT_EXCEEDED";
|
|
318
340
|
readonly rewardId: string;
|
|
319
341
|
} | {
|
|
320
342
|
readonly code: "REWARD_NOT_FOUND";
|
|
@@ -400,6 +422,22 @@ declare class IndexedDBAdapter implements StampStorage {
|
|
|
400
422
|
}
|
|
401
423
|
|
|
402
424
|
type StampRallyListener = (state: StampRallyState) => void;
|
|
425
|
+
type StampRallyClientEvent = {
|
|
426
|
+
readonly type: "checkIn";
|
|
427
|
+
readonly stampId: string;
|
|
428
|
+
readonly state: StampRallyState;
|
|
429
|
+
} | {
|
|
430
|
+
readonly type: "rewardClaimed";
|
|
431
|
+
readonly rewardId: string;
|
|
432
|
+
readonly state: StampRallyState;
|
|
433
|
+
} | {
|
|
434
|
+
readonly type: "syncCompleted";
|
|
435
|
+
readonly state: StampRallyState;
|
|
436
|
+
} | {
|
|
437
|
+
readonly type: "error";
|
|
438
|
+
readonly error: unknown;
|
|
439
|
+
};
|
|
440
|
+
type StampRallyEventListener = (event: StampRallyClientEvent) => void;
|
|
403
441
|
type Clock = () => string;
|
|
404
442
|
declare class StampRallyClient {
|
|
405
443
|
#private;
|
|
@@ -407,6 +445,13 @@ declare class StampRallyClient {
|
|
|
407
445
|
getState(): StampRallyState | null;
|
|
408
446
|
getConfig(): RallyConfig;
|
|
409
447
|
subscribe(listener: StampRallyListener): () => void;
|
|
448
|
+
subscribe(listener: StampRallyEventListener, options: {
|
|
449
|
+
readonly events: true;
|
|
450
|
+
}): () => void;
|
|
451
|
+
subscribeEvents(listener: StampRallyEventListener): () => void;
|
|
452
|
+
updateConfig(newConfig: PublicRallyConfig): Promise<StampRallyState>;
|
|
453
|
+
notifyRewardClaimed(rewardId: string, state?: StampRallyState | null): void;
|
|
454
|
+
notifySyncCompleted(state?: StampRallyState | null): void;
|
|
410
455
|
init(): Promise<StampRallyState>;
|
|
411
456
|
initialize(): Promise<StampRallyState>;
|
|
412
457
|
acquire(stampId: string, context: VerificationContext, now?: string): Promise<Result<ProcessStampValue, StampError>>;
|
|
@@ -414,6 +459,32 @@ declare class StampRallyClient {
|
|
|
414
459
|
restore(state: StampRallyState): Promise<StampRallyState>;
|
|
415
460
|
}
|
|
416
461
|
|
|
462
|
+
type SecureTokenSecretKey = string | Uint8Array;
|
|
463
|
+
interface SecureTokenOptions {
|
|
464
|
+
readonly encrypt?: boolean;
|
|
465
|
+
readonly expiresInSeconds?: number;
|
|
466
|
+
}
|
|
467
|
+
interface SecureTokenPayload {
|
|
468
|
+
readonly [key: string]: unknown;
|
|
469
|
+
readonly exp?: number;
|
|
470
|
+
}
|
|
471
|
+
type SecureTokenErrorCode = "MALFORMED" | "INVALID_SIGNATURE" | "DECRYPTION_FAILED" | "INVALID_PAYLOAD" | "EXPIRED";
|
|
472
|
+
interface SecureTokenError {
|
|
473
|
+
readonly code: SecureTokenErrorCode;
|
|
474
|
+
readonly message: string;
|
|
475
|
+
}
|
|
476
|
+
type SecureTokenVerification<T extends SecureTokenPayload = SecureTokenPayload> = {
|
|
477
|
+
readonly ok: true;
|
|
478
|
+
readonly valid: true;
|
|
479
|
+
readonly payload: T;
|
|
480
|
+
} | {
|
|
481
|
+
readonly ok: false;
|
|
482
|
+
readonly valid: false;
|
|
483
|
+
readonly error: SecureTokenError;
|
|
484
|
+
};
|
|
485
|
+
declare function createSecureToken<T extends SecureTokenPayload>(payload: T, secretKey: SecureTokenSecretKey, options?: SecureTokenOptions): Promise<string>;
|
|
486
|
+
declare function verifySecureToken<T extends SecureTokenPayload = SecureTokenPayload>(token: string, secretKey: SecureTokenSecretKey, now?: number): Promise<SecureTokenVerification<T>>;
|
|
487
|
+
|
|
417
488
|
type DetectorKind = "geolocation" | "nfc" | "qr";
|
|
418
489
|
type DetectorErrorCode = "UNSUPPORTED" | "PERMISSION_DENIED" | "POSITION_UNAVAILABLE" | "TIMEOUT" | "ABORTED" | "READ_FAILED" | "INVALID_DATA" | "NO_TOKEN";
|
|
419
490
|
interface DetectorError {
|
|
@@ -489,4 +560,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
|
|
|
489
560
|
declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
|
|
490
561
|
declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
|
|
491
562
|
|
|
492
|
-
export { CURRENT_RALLY_CONFIG_VERSION, type CheckInContext, type CheckInErrorCode, type CheckInInput, type CheckInResult$1 as CheckInResult, type ClaimTicketOptions, type Clock, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, type ConsumeResult, type ConsumeRewardParams, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type PasscodeCondition, type ProcessStampValue, type PublicRallyConfig, type PublicRewardItem, type QrDetectorOptions, type RallyConfig, type RallyConfigValidationResult, type RallySnapshot, type RedemptionMethod, type Result, type RewardConsumeError, type RewardItem, type RewardState, type RewardStatus, type RewardType, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type StampCondition, type StampDefinition, type StampError, StampRallyClient, type StampRallyEvent, type StampRallyListener, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, THEME_PRESETS, type ThemePreset, type ThemePresetId, type TokenVerificationContext, type ValidationError, type VerificationContext, calculateDistanceMeters, calculateProgress, consumeReward, createClaimTicketNumber, createSignedSnapshotToken, evaluateCheckIn, evaluateCondition, evaluateConditionDetailed, exportProgressToken, getCurrentGeoContext, importProgressToken, isGeolocationSupported, isNfcSupported, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, migrateRallyConfig, normalizePasscode, processStamp, readNfcContext, readQrContext, reconcileRewardStates, resolveLocalizedText, stripSensitiveConfig, toLocalizedString, validateRallyConfig, verifyPasscode, verifySnapshotToken };
|
|
563
|
+
export { CURRENT_RALLY_CONFIG_VERSION, type CheckInContext, type CheckInErrorCode, type CheckInInput, type CheckInResult$1 as CheckInResult, type ClaimTicketOptions, type Clock, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, type ConsumeResult, type ConsumeRewardParams, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type PasscodeCondition, type ProcessStampValue, type PublicRallyConfig, type PublicRewardItem, type QrDetectorOptions, type RallyConfig, type RallyConfigValidationResult, type RallySnapshot, type RedemptionMethod, type Result, type RewardConsumeError, type RewardItem, 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 StampCondition, type StampDefinition, type StampError, StampRallyClient, type StampRallyClientEvent, type StampRallyEvent, type StampRallyEventListener, type StampRallyListener, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, THEME_PRESETS, type ThemePreset, type ThemePresetId, type TokenVerificationContext, type ValidationError, type VerificationContext, calculateDistanceMeters, calculateProgress, consumeReward, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCheckIn, evaluateCondition, evaluateConditionDetailed, exportProgressToken, getCurrentGeoContext, importProgressToken, isGeolocationSupported, isNfcSupported, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, migrateRallyConfig, normalizePasscode, processStamp, readNfcContext, readQrContext, reconcileRewardStates, resolveLocalizedText, stripSensitiveConfig, toLocalizedString, validateRallyConfig, verifyPasscode, verifySecureToken, verifySnapshotToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,7 @@ type Result<T, E> = {
|
|
|
113
113
|
type SupportedLocale = "ja" | "en";
|
|
114
114
|
type LocalizedString<TLocale extends string = SupportedLocale> = Record<TLocale, string>;
|
|
115
115
|
type LocalizedText<TLocale extends string = string> = string | Partial<Record<TLocale, string>>;
|
|
116
|
+
type LocaleDictionary<TLocale extends string = string> = Readonly<Record<TLocale, Readonly<Record<string, string>>>>;
|
|
116
117
|
type SlotShape = "circle" | "square" | "rounded";
|
|
117
118
|
type FontFamily = "system-ui" | "serif" | "rounded-sans" | "monospace" | "handwritten";
|
|
118
119
|
interface SheetTheme {
|
|
@@ -141,6 +142,7 @@ interface SpotItem<TLocale extends string = SupportedLocale, TMeta extends Recor
|
|
|
141
142
|
readonly description?: LocalizedText<TLocale>;
|
|
142
143
|
readonly hint?: LocalizedText<TLocale>;
|
|
143
144
|
readonly condition: StampCondition;
|
|
145
|
+
readonly orderIndex?: number;
|
|
144
146
|
readonly order?: number;
|
|
145
147
|
readonly deckId?: string;
|
|
146
148
|
readonly groupId?: string;
|
|
@@ -161,7 +163,20 @@ interface StampRecord {
|
|
|
161
163
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
162
164
|
}
|
|
163
165
|
type RewardType = "digital" | "in_person";
|
|
164
|
-
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only";
|
|
166
|
+
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only" | "server_claim";
|
|
167
|
+
type RewardUnlockCondition = {
|
|
168
|
+
readonly type: "stamp_count";
|
|
169
|
+
readonly count: number;
|
|
170
|
+
} | {
|
|
171
|
+
readonly type: "stamps";
|
|
172
|
+
readonly stampIds: ReadonlyArray<string>;
|
|
173
|
+
} | {
|
|
174
|
+
readonly type: "group_complete";
|
|
175
|
+
readonly groupId: string;
|
|
176
|
+
} | {
|
|
177
|
+
readonly type: "all" | "any";
|
|
178
|
+
readonly conditions: ReadonlyArray<RewardUnlockCondition>;
|
|
179
|
+
};
|
|
165
180
|
type RewardStatus = "LOCKED" | "AVAILABLE" | "CONSUMED" | "EXPIRED";
|
|
166
181
|
interface RewardItem<TLocale extends string = SupportedLocale> {
|
|
167
182
|
readonly id: string;
|
|
@@ -170,9 +185,12 @@ interface RewardItem<TLocale extends string = SupportedLocale> {
|
|
|
170
185
|
readonly type: RewardType;
|
|
171
186
|
readonly redemptionMethod: RedemptionMethod;
|
|
172
187
|
readonly requiredStampCount: number;
|
|
188
|
+
readonly conditions?: ReadonlyArray<RewardUnlockCondition>;
|
|
173
189
|
readonly digitalContentUrl?: string;
|
|
174
190
|
readonly staffPasscode?: string;
|
|
175
191
|
readonly validUntil?: string;
|
|
192
|
+
readonly stockLimit?: number;
|
|
193
|
+
readonly userClaimLimit?: number;
|
|
176
194
|
readonly maxStock?: number;
|
|
177
195
|
readonly limitPerUser?: number;
|
|
178
196
|
readonly claimTicketNumber?: string;
|
|
@@ -210,7 +228,7 @@ declare function resolveLocalizedText<TLocale extends string = SupportedLocale>(
|
|
|
210
228
|
declare function toLocalizedString(text: LocalizedText | undefined): LocalizedString;
|
|
211
229
|
declare function toLocalizedString<TLocale extends string>(text: LocalizedText<TLocale> | undefined): LocalizedString<TLocale>;
|
|
212
230
|
|
|
213
|
-
declare function migrateRallyConfig(raw: unknown): RallyConfig
|
|
231
|
+
declare function migrateRallyConfig<TLocale extends string = SupportedLocale>(raw: unknown): RallyConfig<TLocale>;
|
|
214
232
|
|
|
215
233
|
type PublicRewardItem<TLocale extends string = string> = Omit<RewardItem<TLocale>, "staffPasscode">;
|
|
216
234
|
type PublicRallyConfig<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> = Omit<RallyConfig<TLocale, TMeta>, "rewards"> & {
|
|
@@ -279,6 +297,8 @@ interface ClaimTicketOptions {
|
|
|
279
297
|
readonly sequence?: number;
|
|
280
298
|
}
|
|
281
299
|
declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
|
|
300
|
+
/** Creates a one-time ticket for a successful reward consumption. */
|
|
301
|
+
declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
|
|
282
302
|
declare function issueClaimTicketNumber(reward: RewardItem, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
|
|
283
303
|
|
|
284
304
|
type StampRallyEvent = {
|
|
@@ -309,12 +329,14 @@ type RewardConsumeError = {
|
|
|
309
329
|
readonly message: string;
|
|
310
330
|
} | {
|
|
311
331
|
readonly code: "EXPIRED";
|
|
332
|
+
readonly reason: "EXPIRED";
|
|
312
333
|
readonly rewardId: string;
|
|
313
334
|
} | {
|
|
314
335
|
readonly code: "OUT_OF_STOCK";
|
|
315
336
|
readonly rewardId: string;
|
|
316
337
|
} | {
|
|
317
338
|
readonly code: "USER_LIMIT_REACHED";
|
|
339
|
+
readonly reason: "LIMIT_EXCEEDED";
|
|
318
340
|
readonly rewardId: string;
|
|
319
341
|
} | {
|
|
320
342
|
readonly code: "REWARD_NOT_FOUND";
|
|
@@ -400,6 +422,22 @@ declare class IndexedDBAdapter implements StampStorage {
|
|
|
400
422
|
}
|
|
401
423
|
|
|
402
424
|
type StampRallyListener = (state: StampRallyState) => void;
|
|
425
|
+
type StampRallyClientEvent = {
|
|
426
|
+
readonly type: "checkIn";
|
|
427
|
+
readonly stampId: string;
|
|
428
|
+
readonly state: StampRallyState;
|
|
429
|
+
} | {
|
|
430
|
+
readonly type: "rewardClaimed";
|
|
431
|
+
readonly rewardId: string;
|
|
432
|
+
readonly state: StampRallyState;
|
|
433
|
+
} | {
|
|
434
|
+
readonly type: "syncCompleted";
|
|
435
|
+
readonly state: StampRallyState;
|
|
436
|
+
} | {
|
|
437
|
+
readonly type: "error";
|
|
438
|
+
readonly error: unknown;
|
|
439
|
+
};
|
|
440
|
+
type StampRallyEventListener = (event: StampRallyClientEvent) => void;
|
|
403
441
|
type Clock = () => string;
|
|
404
442
|
declare class StampRallyClient {
|
|
405
443
|
#private;
|
|
@@ -407,6 +445,13 @@ declare class StampRallyClient {
|
|
|
407
445
|
getState(): StampRallyState | null;
|
|
408
446
|
getConfig(): RallyConfig;
|
|
409
447
|
subscribe(listener: StampRallyListener): () => void;
|
|
448
|
+
subscribe(listener: StampRallyEventListener, options: {
|
|
449
|
+
readonly events: true;
|
|
450
|
+
}): () => void;
|
|
451
|
+
subscribeEvents(listener: StampRallyEventListener): () => void;
|
|
452
|
+
updateConfig(newConfig: PublicRallyConfig): Promise<StampRallyState>;
|
|
453
|
+
notifyRewardClaimed(rewardId: string, state?: StampRallyState | null): void;
|
|
454
|
+
notifySyncCompleted(state?: StampRallyState | null): void;
|
|
410
455
|
init(): Promise<StampRallyState>;
|
|
411
456
|
initialize(): Promise<StampRallyState>;
|
|
412
457
|
acquire(stampId: string, context: VerificationContext, now?: string): Promise<Result<ProcessStampValue, StampError>>;
|
|
@@ -414,6 +459,32 @@ declare class StampRallyClient {
|
|
|
414
459
|
restore(state: StampRallyState): Promise<StampRallyState>;
|
|
415
460
|
}
|
|
416
461
|
|
|
462
|
+
type SecureTokenSecretKey = string | Uint8Array;
|
|
463
|
+
interface SecureTokenOptions {
|
|
464
|
+
readonly encrypt?: boolean;
|
|
465
|
+
readonly expiresInSeconds?: number;
|
|
466
|
+
}
|
|
467
|
+
interface SecureTokenPayload {
|
|
468
|
+
readonly [key: string]: unknown;
|
|
469
|
+
readonly exp?: number;
|
|
470
|
+
}
|
|
471
|
+
type SecureTokenErrorCode = "MALFORMED" | "INVALID_SIGNATURE" | "DECRYPTION_FAILED" | "INVALID_PAYLOAD" | "EXPIRED";
|
|
472
|
+
interface SecureTokenError {
|
|
473
|
+
readonly code: SecureTokenErrorCode;
|
|
474
|
+
readonly message: string;
|
|
475
|
+
}
|
|
476
|
+
type SecureTokenVerification<T extends SecureTokenPayload = SecureTokenPayload> = {
|
|
477
|
+
readonly ok: true;
|
|
478
|
+
readonly valid: true;
|
|
479
|
+
readonly payload: T;
|
|
480
|
+
} | {
|
|
481
|
+
readonly ok: false;
|
|
482
|
+
readonly valid: false;
|
|
483
|
+
readonly error: SecureTokenError;
|
|
484
|
+
};
|
|
485
|
+
declare function createSecureToken<T extends SecureTokenPayload>(payload: T, secretKey: SecureTokenSecretKey, options?: SecureTokenOptions): Promise<string>;
|
|
486
|
+
declare function verifySecureToken<T extends SecureTokenPayload = SecureTokenPayload>(token: string, secretKey: SecureTokenSecretKey, now?: number): Promise<SecureTokenVerification<T>>;
|
|
487
|
+
|
|
417
488
|
type DetectorKind = "geolocation" | "nfc" | "qr";
|
|
418
489
|
type DetectorErrorCode = "UNSUPPORTED" | "PERMISSION_DENIED" | "POSITION_UNAVAILABLE" | "TIMEOUT" | "ABORTED" | "READ_FAILED" | "INVALID_DATA" | "NO_TOKEN";
|
|
419
490
|
interface DetectorError {
|
|
@@ -489,4 +560,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
|
|
|
489
560
|
declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
|
|
490
561
|
declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
|
|
491
562
|
|
|
492
|
-
export { CURRENT_RALLY_CONFIG_VERSION, type CheckInContext, type CheckInErrorCode, type CheckInInput, type CheckInResult$1 as CheckInResult, type ClaimTicketOptions, type Clock, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, type ConsumeResult, type ConsumeRewardParams, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type PasscodeCondition, type ProcessStampValue, type PublicRallyConfig, type PublicRewardItem, type QrDetectorOptions, type RallyConfig, type RallyConfigValidationResult, type RallySnapshot, type RedemptionMethod, type Result, type RewardConsumeError, type RewardItem, type RewardState, type RewardStatus, type RewardType, type SheetTheme, type SlotShape, type SnapshotSecretKey, type SnapshotTokenError, type SnapshotTokenErrorCode, type SnapshotTokenPayload, type SnapshotTokenVerification, type SpotItem, type StampCondition, type StampDefinition, type StampError, StampRallyClient, type StampRallyEvent, type StampRallyListener, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, THEME_PRESETS, type ThemePreset, type ThemePresetId, type TokenVerificationContext, type ValidationError, type VerificationContext, calculateDistanceMeters, calculateProgress, consumeReward, createClaimTicketNumber, createSignedSnapshotToken, evaluateCheckIn, evaluateCondition, evaluateConditionDetailed, exportProgressToken, getCurrentGeoContext, importProgressToken, isGeolocationSupported, isNfcSupported, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, migrateRallyConfig, normalizePasscode, processStamp, readNfcContext, readQrContext, reconcileRewardStates, resolveLocalizedText, stripSensitiveConfig, toLocalizedString, validateRallyConfig, verifyPasscode, verifySnapshotToken };
|
|
563
|
+
export { CURRENT_RALLY_CONFIG_VERSION, type CheckInContext, type CheckInErrorCode, type CheckInInput, type CheckInResult$1 as CheckInResult, type ClaimTicketOptions, type Clock, type CompositeConditionFailure, type ConditionMatch, type ConditionMismatch, type ConsumeResult, type ConsumeRewardParams, DEFAULT_SHEET_THEME, type DetectorError, type DetectorErrorCode, type DetectorKind, type DetectorResult, type FontFamily, type GeoDetectorOptions, type GeoVerificationContext, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type PasscodeCondition, type ProcessStampValue, type PublicRallyConfig, type PublicRewardItem, type QrDetectorOptions, type RallyConfig, type RallyConfigValidationResult, type RallySnapshot, type RedemptionMethod, type Result, type RewardConsumeError, type RewardItem, 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 StampCondition, type StampDefinition, type StampError, StampRallyClient, type StampRallyClientEvent, type StampRallyEvent, type StampRallyEventListener, type StampRallyListener, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, THEME_PRESETS, type ThemePreset, type ThemePresetId, type TokenVerificationContext, type ValidationError, type VerificationContext, calculateDistanceMeters, calculateProgress, consumeReward, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCheckIn, evaluateCondition, evaluateConditionDetailed, exportProgressToken, getCurrentGeoContext, importProgressToken, isGeolocationSupported, isNfcSupported, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, migrateRallyConfig, normalizePasscode, processStamp, readNfcContext, readQrContext, reconcileRewardStates, resolveLocalizedText, stripSensitiveConfig, toLocalizedString, validateRallyConfig, verifyPasscode, verifySecureToken, verifySnapshotToken };
|