@stamprally/core 0.7.0 → 0.9.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 +469 -1077
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +302 -582
- package/dist/index.d.ts +302 -582
- package/dist/index.js +465 -1067
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,126 +1,36 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
readonly
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly endsAt: string;
|
|
19
|
-
readonly condition: StampCondition;
|
|
20
|
-
};
|
|
21
|
-
type VerificationContext = {
|
|
22
|
-
readonly type: "instant";
|
|
23
|
-
} | {
|
|
24
|
-
readonly type: "token";
|
|
25
|
-
readonly token: string;
|
|
26
|
-
} | {
|
|
27
|
-
readonly type: "geo";
|
|
28
|
-
readonly currentLatitude: number;
|
|
29
|
-
readonly currentLongitude: number;
|
|
30
|
-
} | {
|
|
31
|
-
readonly type: "composite";
|
|
32
|
-
readonly contexts: ReadonlyArray<VerificationContext>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
interface ConditionMatch {
|
|
36
|
-
readonly conditionType: StampCondition["type"];
|
|
37
|
-
readonly distanceMeters?: number;
|
|
1
|
+
type SupportedLocale = "ja" | "en";
|
|
2
|
+
type LocalizedText<TLocale extends string = string> = string | Partial<Record<TLocale, string>>;
|
|
3
|
+
type LocalizedString<TLocale extends string = SupportedLocale> = Record<TLocale, string>;
|
|
4
|
+
type LocaleDictionary<TLocale extends string = string> = Readonly<Record<TLocale, Readonly<Record<string, string>>>>;
|
|
5
|
+
type SlotShape = "circle" | "square" | "rounded";
|
|
6
|
+
type FontFamily = "system-ui" | "serif" | "rounded-sans" | "monospace" | "handwritten";
|
|
7
|
+
interface SheetTheme {
|
|
8
|
+
readonly primaryColor: string;
|
|
9
|
+
readonly backgroundColor?: string;
|
|
10
|
+
readonly backgroundImageUrl?: string;
|
|
11
|
+
readonly cardBackgroundColor: string;
|
|
12
|
+
readonly textColor: string;
|
|
13
|
+
readonly slotShape: SlotShape;
|
|
14
|
+
readonly gridColumns: number;
|
|
15
|
+
readonly unclaimedOpacity?: number;
|
|
16
|
+
readonly completedStampColor?: string;
|
|
17
|
+
readonly fontFamily?: FontFamily;
|
|
38
18
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
readonly
|
|
19
|
+
type ThemePresetId = "default" | "modern_dark" | "pop_candy" | "retro_craft" | "cyber";
|
|
20
|
+
interface ThemePreset<TLocale extends string = SupportedLocale> {
|
|
21
|
+
readonly id: ThemePresetId;
|
|
22
|
+
readonly name: LocalizedString<TLocale>;
|
|
23
|
+
readonly description: LocalizedString<TLocale>;
|
|
24
|
+
readonly theme: SheetTheme;
|
|
42
25
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
readonly conditionType: Exclude<StampCondition["type"], "time_window">;
|
|
46
|
-
readonly reason: "CONTEXT_TYPE_MISMATCH";
|
|
47
|
-
readonly expectedContextType: VerificationContext["type"];
|
|
48
|
-
readonly actualContextType: VerificationContext["type"];
|
|
49
|
-
} | {
|
|
50
|
-
readonly code: "CONDITION_MISMATCH";
|
|
51
|
-
readonly conditionType: "token";
|
|
52
|
-
readonly reason: "TOKEN_MISMATCH";
|
|
53
|
-
} | {
|
|
54
|
-
readonly code: "CONDITION_MISMATCH";
|
|
55
|
-
readonly conditionType: "geo";
|
|
56
|
-
readonly reason: "INVALID_GEO_INPUT";
|
|
57
|
-
} | {
|
|
58
|
-
readonly code: "CONDITION_MISMATCH";
|
|
59
|
-
readonly conditionType: "geo";
|
|
60
|
-
readonly reason: "OUTSIDE_RADIUS";
|
|
61
|
-
readonly distanceMeters: number;
|
|
62
|
-
readonly radiusMeters: number;
|
|
63
|
-
readonly differenceMeters: number;
|
|
64
|
-
} | {
|
|
65
|
-
readonly code: "CONDITION_MISMATCH";
|
|
66
|
-
readonly conditionType: "composite";
|
|
67
|
-
readonly reason: "CONTEXT_LENGTH_MISMATCH";
|
|
68
|
-
readonly expectedCount: number;
|
|
69
|
-
readonly actualCount: number;
|
|
70
|
-
} | {
|
|
71
|
-
readonly code: "CONDITION_MISMATCH";
|
|
72
|
-
readonly conditionType: "composite";
|
|
73
|
-
readonly reason: "AND_CHILD_FAILED" | "OR_ALL_FAILED";
|
|
74
|
-
readonly failures: ReadonlyArray<CompositeConditionFailure>;
|
|
75
|
-
} | {
|
|
76
|
-
readonly code: "CONDITION_MISMATCH";
|
|
77
|
-
readonly conditionType: "time_window";
|
|
78
|
-
readonly reason: "INVALID_NOW" | "INVALID_TIME_WINDOW" | "BEFORE_START" | "AFTER_END";
|
|
79
|
-
readonly now: string;
|
|
80
|
-
readonly startsAt: string;
|
|
81
|
-
readonly endsAt: string;
|
|
82
|
-
};
|
|
83
|
-
type StampError = {
|
|
84
|
-
readonly code: "STAMP_NOT_FOUND";
|
|
85
|
-
readonly stampId: string;
|
|
86
|
-
} | {
|
|
87
|
-
readonly code: "STAMP_ALREADY_ACQUIRED";
|
|
88
|
-
readonly stampId: string;
|
|
89
|
-
} | {
|
|
90
|
-
readonly code: "INVALID_ORDER";
|
|
91
|
-
readonly stampId: string;
|
|
92
|
-
readonly expectedStampId: string;
|
|
93
|
-
} | {
|
|
94
|
-
readonly code: "CONDITION_MISMATCH";
|
|
95
|
-
readonly stampId: string;
|
|
96
|
-
readonly mismatch: ConditionMismatch;
|
|
97
|
-
} | {
|
|
98
|
-
readonly code: "OFFLINE_QUEUED";
|
|
99
|
-
readonly stampId: string;
|
|
100
|
-
readonly idempotencyKey: string;
|
|
101
|
-
} | {
|
|
102
|
-
readonly code: "INVALID_PROOF";
|
|
103
|
-
readonly stampId: string;
|
|
104
|
-
};
|
|
105
|
-
type Result<T, E> = {
|
|
106
|
-
readonly ok: true;
|
|
107
|
-
readonly value: T;
|
|
108
|
-
} | {
|
|
109
|
-
readonly ok: false;
|
|
110
|
-
readonly error: E;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/** A human-readable value that may be supplied in one or more locales. */
|
|
114
|
-
type UniversalLocalizedText<TLocale extends string = string> = string | Partial<Record<TLocale, string>>;
|
|
115
|
-
/** A link to an entity owned by the host application or another system. */
|
|
116
|
-
interface ExternalReference$1 {
|
|
26
|
+
declare const DEFAULT_SHEET_THEME: SheetTheme;
|
|
27
|
+
interface ExternalReference {
|
|
117
28
|
readonly type: string;
|
|
118
29
|
readonly id: string;
|
|
119
30
|
readonly url?: string;
|
|
120
31
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
121
32
|
}
|
|
122
|
-
|
|
123
|
-
type VerificationCondition = {
|
|
33
|
+
type CheckInCondition = {
|
|
124
34
|
readonly type: "qr";
|
|
125
35
|
readonly secretToken: string;
|
|
126
36
|
readonly qrEntryUrl?: string;
|
|
@@ -133,15 +43,17 @@ type VerificationCondition = {
|
|
|
133
43
|
readonly latitude: number;
|
|
134
44
|
readonly longitude: number;
|
|
135
45
|
readonly radiusMeters: number;
|
|
46
|
+
} | {
|
|
47
|
+
readonly type: "nfc";
|
|
48
|
+
readonly tagId: string;
|
|
136
49
|
} | {
|
|
137
50
|
readonly type: "custom";
|
|
138
51
|
readonly validatorName: string;
|
|
139
52
|
readonly secretParams?: Readonly<Record<string, unknown>>;
|
|
140
53
|
};
|
|
141
|
-
/** Safe condition metadata intended for a participant client. */
|
|
142
54
|
type PublicCheckInCondition = {
|
|
143
55
|
readonly type: "qr";
|
|
144
|
-
readonly qrEntryUrl
|
|
56
|
+
readonly qrEntryUrl?: string;
|
|
145
57
|
} | {
|
|
146
58
|
readonly type: "passcode";
|
|
147
59
|
} | {
|
|
@@ -149,39 +61,30 @@ type PublicCheckInCondition = {
|
|
|
149
61
|
readonly latitude: number;
|
|
150
62
|
readonly longitude: number;
|
|
151
63
|
readonly radiusMeters: number;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "nfc";
|
|
152
66
|
} | {
|
|
153
67
|
readonly type: "custom";
|
|
154
68
|
readonly validatorName: string;
|
|
155
69
|
};
|
|
156
|
-
interface
|
|
70
|
+
interface SpotItem<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> {
|
|
157
71
|
readonly id: string;
|
|
158
72
|
readonly orderIndex: number;
|
|
159
|
-
readonly name:
|
|
160
|
-
readonly description?:
|
|
161
|
-
readonly hint?:
|
|
73
|
+
readonly name: LocalizedText<TLocale>;
|
|
74
|
+
readonly description?: LocalizedText<TLocale>;
|
|
75
|
+
readonly hint?: LocalizedText<TLocale>;
|
|
162
76
|
readonly imageUrl?: string;
|
|
163
77
|
readonly iconUrl?: string;
|
|
164
78
|
readonly redirectUrlAfterClaim?: string;
|
|
165
|
-
readonly externalReferences?: ReadonlyArray<ExternalReference
|
|
79
|
+
readonly externalReferences?: ReadonlyArray<ExternalReference>;
|
|
166
80
|
readonly metadata?: TMeta;
|
|
167
|
-
readonly conditions: ReadonlyArray<
|
|
81
|
+
readonly conditions: ReadonlyArray<CheckInCondition>;
|
|
168
82
|
readonly prerequisites?: ReadonlyArray<string>;
|
|
169
83
|
}
|
|
170
|
-
type
|
|
171
|
-
readonly
|
|
172
|
-
readonly title: UniversalLocalizedText<TLocale>;
|
|
173
|
-
readonly description?: UniversalLocalizedText<TLocale>;
|
|
174
|
-
readonly type: "digital" | "in_person";
|
|
175
|
-
readonly redemptionMethod: "manual_slide" | "staff_passcode" | "view_only" | "server_claim";
|
|
176
|
-
readonly requiredStampCount: number;
|
|
177
|
-
readonly conditions?: ReadonlyArray<RewardUnlockCondition$1>;
|
|
178
|
-
readonly stockLimit?: number;
|
|
179
|
-
readonly userClaimLimit?: number;
|
|
180
|
-
readonly staffPasscode?: string;
|
|
181
|
-
readonly digitalContentUrl?: string;
|
|
84
|
+
type PublicSpotItem<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> = Omit<SpotItem<TLocale, TMeta>, "conditions"> & {
|
|
85
|
+
readonly conditions: ReadonlyArray<PublicCheckInCondition>;
|
|
182
86
|
};
|
|
183
|
-
type
|
|
184
|
-
type RewardUnlockCondition$1 = {
|
|
87
|
+
type RewardUnlockCondition = {
|
|
185
88
|
readonly type: "stamp_count";
|
|
186
89
|
readonly count: number;
|
|
187
90
|
} | {
|
|
@@ -189,126 +92,60 @@ type RewardUnlockCondition$1 = {
|
|
|
189
92
|
readonly stampIds: ReadonlyArray<string>;
|
|
190
93
|
} | {
|
|
191
94
|
readonly type: "all" | "any";
|
|
192
|
-
readonly conditions: ReadonlyArray<RewardUnlockCondition
|
|
95
|
+
readonly conditions: ReadonlyArray<RewardUnlockCondition>;
|
|
193
96
|
};
|
|
97
|
+
type RewardType = "digital" | "in_person";
|
|
98
|
+
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only" | "server_claim";
|
|
99
|
+
interface Reward<TLocale extends string = string> {
|
|
100
|
+
readonly id: string;
|
|
101
|
+
readonly title: LocalizedText<TLocale>;
|
|
102
|
+
readonly description?: LocalizedText<TLocale>;
|
|
103
|
+
readonly type: RewardType;
|
|
104
|
+
readonly redemptionMethod: RedemptionMethod;
|
|
105
|
+
readonly requiredStampCount: number;
|
|
106
|
+
readonly conditions?: ReadonlyArray<RewardUnlockCondition>;
|
|
107
|
+
readonly digitalContentUrl?: string;
|
|
108
|
+
readonly staffPasscode?: string;
|
|
109
|
+
readonly validUntil?: string;
|
|
110
|
+
readonly stockLimit?: number;
|
|
111
|
+
readonly userClaimLimit?: number;
|
|
112
|
+
}
|
|
113
|
+
type PublicReward<TLocale extends string = string> = Omit<Reward<TLocale>, "digitalContentUrl" | "staffPasscode">;
|
|
194
114
|
interface AdminRallyConfig<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> {
|
|
195
115
|
readonly id: string;
|
|
196
116
|
readonly version: string;
|
|
197
|
-
readonly title:
|
|
198
|
-
readonly description?:
|
|
117
|
+
readonly title: LocalizedText<TLocale>;
|
|
118
|
+
readonly description?: LocalizedText<TLocale>;
|
|
199
119
|
readonly theme?: SheetTheme;
|
|
200
|
-
readonly spots: ReadonlyArray<
|
|
201
|
-
readonly rewards: ReadonlyArray<
|
|
202
|
-
readonly
|
|
120
|
+
readonly spots: ReadonlyArray<SpotItem<TLocale, TMeta>>;
|
|
121
|
+
readonly rewards: ReadonlyArray<Reward<TLocale>>;
|
|
122
|
+
readonly staffPasscode?: string;
|
|
123
|
+
readonly inventory?: Readonly<Record<string, number>>;
|
|
124
|
+
readonly serverMetadata?: Readonly<Record<string, unknown>>;
|
|
203
125
|
readonly metadata?: TMeta;
|
|
126
|
+
readonly serverEndpoint?: string;
|
|
204
127
|
}
|
|
205
128
|
interface PublicRallyConfig<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> {
|
|
206
129
|
readonly id: string;
|
|
207
130
|
readonly version: string;
|
|
208
|
-
readonly title:
|
|
209
|
-
readonly description?:
|
|
131
|
+
readonly title: LocalizedText<TLocale>;
|
|
132
|
+
readonly description?: LocalizedText<TLocale>;
|
|
210
133
|
readonly theme?: SheetTheme;
|
|
211
|
-
readonly spots: ReadonlyArray<
|
|
212
|
-
readonly conditions: ReadonlyArray<PublicCheckInCondition>;
|
|
213
|
-
}>;
|
|
134
|
+
readonly spots: ReadonlyArray<PublicSpotItem<TLocale, TMeta>>;
|
|
214
135
|
readonly rewards: ReadonlyArray<PublicReward<TLocale>>;
|
|
215
|
-
readonly serverEndpoint?: string;
|
|
216
|
-
readonly metadata?: TMeta;
|
|
217
|
-
}
|
|
218
|
-
/** Produce the browser-safe projection without mutating the admin config. */
|
|
219
|
-
declare function toPublicRallyConfig<TLocale extends string, TMeta extends Record<string, unknown>>(config: AdminRallyConfig<TLocale, TMeta>): PublicRallyConfig<TLocale, TMeta>;
|
|
220
|
-
/** Runtime guard for values crossing the public configuration boundary. */
|
|
221
|
-
declare function isPublicRallyConfig(value: unknown): value is PublicRallyConfig;
|
|
222
|
-
|
|
223
|
-
type SupportedLocale = "ja" | "en";
|
|
224
|
-
type LocalizedString<TLocale extends string = SupportedLocale> = Record<TLocale, string>;
|
|
225
|
-
type LocalizedText$1<TLocale extends string = string> = string | Partial<Record<TLocale, string>>;
|
|
226
|
-
type LocaleDictionary<TLocale extends string = string> = Readonly<Record<TLocale, Readonly<Record<string, string>>>>;
|
|
227
|
-
type SlotShape = "circle" | "square" | "rounded";
|
|
228
|
-
type FontFamily = "system-ui" | "serif" | "rounded-sans" | "monospace" | "handwritten";
|
|
229
|
-
interface SheetTheme {
|
|
230
|
-
readonly primaryColor: string;
|
|
231
|
-
readonly backgroundColor?: string;
|
|
232
|
-
readonly backgroundImageUrl?: string;
|
|
233
|
-
readonly cardBackgroundColor: string;
|
|
234
|
-
readonly textColor: string;
|
|
235
|
-
readonly slotShape: SlotShape;
|
|
236
|
-
readonly gridColumns: number;
|
|
237
|
-
readonly unclaimedOpacity?: number;
|
|
238
|
-
readonly completedStampColor?: string;
|
|
239
|
-
readonly fontFamily?: FontFamily;
|
|
240
|
-
}
|
|
241
|
-
type ThemePresetId = "default" | "modern_dark" | "pop_candy" | "retro_craft" | "cyber";
|
|
242
|
-
interface ThemePreset<TLocale extends string = SupportedLocale> {
|
|
243
|
-
readonly id: ThemePresetId;
|
|
244
|
-
readonly name: LocalizedString<TLocale>;
|
|
245
|
-
readonly description: LocalizedString<TLocale>;
|
|
246
|
-
readonly theme: SheetTheme;
|
|
247
|
-
}
|
|
248
|
-
declare const DEFAULT_SHEET_THEME: SheetTheme;
|
|
249
|
-
interface SpotItem<TLocale extends string = SupportedLocale, TMeta extends Record<string, unknown> = Record<string, unknown>> {
|
|
250
|
-
readonly id: string;
|
|
251
|
-
readonly name: LocalizedText$1<TLocale>;
|
|
252
|
-
readonly description?: LocalizedText$1<TLocale>;
|
|
253
|
-
readonly hint?: LocalizedText$1<TLocale>;
|
|
254
|
-
readonly condition: StampCondition;
|
|
255
|
-
readonly orderIndex?: number;
|
|
256
|
-
readonly order?: number;
|
|
257
|
-
readonly deckId?: string;
|
|
258
|
-
readonly groupId?: string;
|
|
259
|
-
readonly guideId?: string;
|
|
260
|
-
readonly iconUrl?: string;
|
|
261
|
-
readonly imageUrl?: string;
|
|
262
|
-
readonly externalUrl?: string;
|
|
263
|
-
readonly redirectUrlAfterClaim?: string;
|
|
264
136
|
readonly metadata?: TMeta;
|
|
265
|
-
|
|
266
|
-
readonly conditions?: ReadonlyArray<VerificationCondition>;
|
|
267
|
-
readonly externalReferences?: ReadonlyArray<ExternalReference$1>;
|
|
268
|
-
readonly prerequisites?: ReadonlyArray<string>;
|
|
269
|
-
readonly dependsOn?: ReadonlyArray<string>;
|
|
270
|
-
readonly requiresStampIds?: ReadonlyArray<string>;
|
|
137
|
+
readonly serverEndpoint?: string;
|
|
271
138
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
139
|
+
type RallyConfig<TLocale extends string = string, TMeta extends Record<string, unknown> = Record<string, unknown>> = PublicRallyConfig<TLocale, TMeta>;
|
|
140
|
+
declare function toPublicConfig<TLocale extends string, TMeta extends Record<string, unknown>>(config: AdminRallyConfig<TLocale, TMeta>): PublicRallyConfig<TLocale, TMeta>;
|
|
141
|
+
declare function assertPublicConfig(config: unknown): asserts config is PublicRallyConfig;
|
|
142
|
+
declare function isPublicConfig(value: unknown): value is PublicRallyConfig;
|
|
143
|
+
interface StampRecord {
|
|
275
144
|
readonly stampId: string;
|
|
276
145
|
readonly acquiredAt: string;
|
|
277
146
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
278
147
|
}
|
|
279
|
-
type RewardType = "digital" | "in_person";
|
|
280
|
-
type RedemptionMethod = "manual_slide" | "staff_passcode" | "view_only" | "server_claim";
|
|
281
|
-
type RewardUnlockCondition = {
|
|
282
|
-
readonly type: "stamp_count";
|
|
283
|
-
readonly count: number;
|
|
284
|
-
} | {
|
|
285
|
-
readonly type: "stamps";
|
|
286
|
-
readonly stampIds: ReadonlyArray<string>;
|
|
287
|
-
} | {
|
|
288
|
-
readonly type: "group_complete";
|
|
289
|
-
readonly groupId: string;
|
|
290
|
-
} | {
|
|
291
|
-
readonly type: "all" | "any";
|
|
292
|
-
readonly conditions: ReadonlyArray<RewardUnlockCondition>;
|
|
293
|
-
};
|
|
294
148
|
type RewardStatus = "LOCKED" | "AVAILABLE" | "CONSUMED" | "EXPIRED";
|
|
295
|
-
interface RewardItem<TLocale extends string = SupportedLocale> {
|
|
296
|
-
readonly id: string;
|
|
297
|
-
readonly title: LocalizedText$1<TLocale>;
|
|
298
|
-
readonly description: LocalizedText$1<TLocale>;
|
|
299
|
-
readonly type: RewardType;
|
|
300
|
-
readonly redemptionMethod: RedemptionMethod;
|
|
301
|
-
readonly requiredStampCount: number;
|
|
302
|
-
readonly conditions?: ReadonlyArray<RewardUnlockCondition>;
|
|
303
|
-
readonly digitalContentUrl?: string;
|
|
304
|
-
readonly staffPasscode?: string;
|
|
305
|
-
readonly validUntil?: string;
|
|
306
|
-
readonly stockLimit?: number;
|
|
307
|
-
readonly userClaimLimit?: number;
|
|
308
|
-
readonly maxStock?: number;
|
|
309
|
-
readonly limitPerUser?: number;
|
|
310
|
-
readonly claimTicketNumber?: string;
|
|
311
|
-
}
|
|
312
149
|
interface RewardState {
|
|
313
150
|
readonly rewardId: string;
|
|
314
151
|
readonly status: RewardStatus;
|
|
@@ -321,103 +158,111 @@ interface RewardState {
|
|
|
321
158
|
}
|
|
322
159
|
interface StampRallyState {
|
|
323
160
|
readonly rallyId: string;
|
|
324
|
-
readonly
|
|
325
|
-
readonly
|
|
161
|
+
readonly userId: string | null;
|
|
162
|
+
readonly records: ReadonlyArray<StampRecord>;
|
|
163
|
+
readonly rewards: ReadonlyArray<RewardState>;
|
|
326
164
|
readonly updatedAt: string;
|
|
327
165
|
}
|
|
328
|
-
|
|
329
|
-
readonly id: string;
|
|
330
|
-
readonly title?: LocalizedText$1<TLocale>;
|
|
331
|
-
readonly description?: LocalizedText$1<TLocale>;
|
|
332
|
-
readonly stamps: ReadonlyArray<StampDefinition<TLocale, TMeta>>;
|
|
333
|
-
readonly rewards?: ReadonlyArray<RewardItem<TLocale>>;
|
|
334
|
-
readonly isSequential?: boolean;
|
|
335
|
-
readonly theme?: SheetTheme;
|
|
336
|
-
readonly version?: number;
|
|
337
|
-
readonly startDate?: string;
|
|
338
|
-
readonly endDate?: string;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
declare function resolveLocalizedText<TLocale extends string = SupportedLocale>(text: LocalizedText$1<TLocale> | undefined, locale: string, fallbackLocale?: string): string;
|
|
342
|
-
declare function toLocalizedString(text: LocalizedText$1 | undefined): LocalizedString;
|
|
343
|
-
declare function toLocalizedString<TLocale extends string>(text: LocalizedText$1<TLocale> | undefined): LocalizedString<TLocale>;
|
|
166
|
+
type UserRallyState = StampRallyState;
|
|
344
167
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
readonly
|
|
168
|
+
type VerificationContext = {
|
|
169
|
+
readonly type: "qr";
|
|
170
|
+
readonly token: string;
|
|
171
|
+
} | {
|
|
172
|
+
readonly type: "passcode";
|
|
173
|
+
readonly code: string;
|
|
174
|
+
} | {
|
|
175
|
+
readonly type: "gps";
|
|
176
|
+
readonly latitude: number;
|
|
177
|
+
readonly longitude: number;
|
|
178
|
+
} | {
|
|
179
|
+
readonly type: "nfc";
|
|
180
|
+
readonly tagId: string;
|
|
181
|
+
} | {
|
|
182
|
+
readonly type: "custom";
|
|
183
|
+
readonly value: unknown;
|
|
350
184
|
};
|
|
351
|
-
declare function stripSensitiveConfig<TLocale extends string, TMeta extends Record<string, unknown>>(config: AdminRallyConfig<TLocale, TMeta>): PublicRallyConfig<TLocale, TMeta>;
|
|
352
|
-
declare function stripSensitiveConfig<TLocale extends string, TMeta extends Record<string, unknown>>(config: RallyConfig<TLocale, TMeta>): LegacyPublicRallyConfig<TLocale, TMeta>;
|
|
353
185
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
readonly path: string;
|
|
358
|
-
readonly code: "INVALID_TYPE" | "REQUIRED" | "EMPTY_STRING" | "DUPLICATE_ID" | "INVALID_COORDINATES" | "INVALID_RADIUS" | "INVALID_VERSION" | "INVALID_REWARD" | "CYCLE_DETECTED" | "SECRET_IN_PUBLIC_CONFIG";
|
|
359
|
-
readonly message: string;
|
|
186
|
+
interface ConditionMatch {
|
|
187
|
+
readonly conditionType: CheckInCondition["type"];
|
|
188
|
+
readonly distanceMeters?: number;
|
|
360
189
|
}
|
|
361
|
-
|
|
362
|
-
readonly
|
|
363
|
-
readonly
|
|
190
|
+
type ConditionMismatch = {
|
|
191
|
+
readonly code: "CONDITION_MISMATCH";
|
|
192
|
+
readonly conditionType: CheckInCondition["type"];
|
|
193
|
+
readonly reason: "INVALID_PROOF" | "INVALID_GEO_INPUT" | "OUTSIDE_RADIUS" | "VALIDATOR_FAILED";
|
|
194
|
+
readonly distanceMeters?: number;
|
|
195
|
+
readonly radiusMeters?: number;
|
|
196
|
+
};
|
|
197
|
+
interface CompositeConditionFailure {
|
|
198
|
+
readonly index: number;
|
|
199
|
+
readonly error: ConditionMismatch;
|
|
364
200
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
readonly
|
|
373
|
-
readonly
|
|
201
|
+
type StampError = {
|
|
202
|
+
readonly code: "SPOT_NOT_FOUND";
|
|
203
|
+
readonly spotId: string;
|
|
204
|
+
} | {
|
|
205
|
+
readonly code: "STAMP_ALREADY_ACQUIRED";
|
|
206
|
+
readonly spotId: string;
|
|
207
|
+
} | {
|
|
208
|
+
readonly code: "PREREQUISITES_NOT_MET";
|
|
209
|
+
readonly spotId: string;
|
|
210
|
+
} | {
|
|
211
|
+
readonly code: "INVALID_PROOF";
|
|
212
|
+
readonly spotId: string;
|
|
213
|
+
} | {
|
|
214
|
+
readonly code: "CUSTOM_VALIDATION_FAILED";
|
|
215
|
+
readonly spotId: string;
|
|
374
216
|
readonly message: string;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
readonly valid: boolean;
|
|
378
|
-
readonly errors: ReadonlyArray<ValidationError>;
|
|
379
|
-
}
|
|
380
|
-
declare function validateRallyConfig(config: unknown): RallyConfigValidationResult;
|
|
381
|
-
|
|
382
|
-
type CheckInErrorCode = "ORDER_VIOLATION" | "OUT_OF_RANGE" | "EXPIRED" | "INVALID_PROOF" | "INVALID_CONTEXT" | "ALREADY_CLAIMED";
|
|
383
|
-
interface CheckInContext {
|
|
384
|
-
readonly verificationContext: VerificationContext;
|
|
385
|
-
readonly now?: string;
|
|
386
|
-
readonly expectedStampId?: string;
|
|
387
|
-
readonly proof?: string;
|
|
388
|
-
readonly alreadyClaimed?: boolean;
|
|
389
|
-
}
|
|
390
|
-
type CheckInInput = VerificationContext | (VerificationContext & {
|
|
391
|
-
readonly now?: string;
|
|
392
|
-
readonly expectedStampId?: string;
|
|
393
|
-
readonly alreadyClaimed?: boolean;
|
|
394
|
-
}) | CheckInContext;
|
|
395
|
-
type CheckInResult$1 = {
|
|
217
|
+
};
|
|
218
|
+
type Result<T, E> = {
|
|
396
219
|
readonly ok: true;
|
|
397
|
-
readonly
|
|
398
|
-
readonly stampId: string;
|
|
399
|
-
readonly checkedAt: string;
|
|
220
|
+
readonly value: T;
|
|
400
221
|
} | {
|
|
401
222
|
readonly ok: false;
|
|
402
|
-
readonly
|
|
403
|
-
readonly code: CheckInErrorCode;
|
|
404
|
-
readonly stampId: string;
|
|
405
|
-
readonly message: string;
|
|
223
|
+
readonly error: E;
|
|
406
224
|
};
|
|
407
|
-
|
|
225
|
+
interface CustomValidationContext {
|
|
226
|
+
readonly rallyId: string;
|
|
227
|
+
readonly spotId: string;
|
|
228
|
+
readonly proofData: unknown;
|
|
229
|
+
readonly condition: Extract<CheckInCondition, {
|
|
230
|
+
readonly type: "custom";
|
|
231
|
+
}>;
|
|
232
|
+
readonly userState: UserRallyState;
|
|
233
|
+
}
|
|
234
|
+
interface CustomValidator {
|
|
235
|
+
validate(context: CustomValidationContext): Promise<boolean | {
|
|
236
|
+
readonly valid: boolean;
|
|
237
|
+
readonly message?: string;
|
|
238
|
+
}>;
|
|
239
|
+
}
|
|
240
|
+
type Validator = CustomValidator | ((context: CustomValidationContext) => Promise<boolean | {
|
|
241
|
+
readonly valid: boolean;
|
|
242
|
+
readonly message?: string;
|
|
243
|
+
}> | boolean | {
|
|
244
|
+
readonly valid: boolean;
|
|
245
|
+
readonly message?: string;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
declare function resolveLocalizedText<TLocale extends string = SupportedLocale>(text: LocalizedText<TLocale> | undefined, locale: string, fallbackLocale?: string): string;
|
|
249
|
+
declare function toLocalizedString(text: LocalizedText | undefined): LocalizedString;
|
|
250
|
+
declare function toLocalizedString<TLocale extends string>(text: LocalizedText<TLocale> | undefined): LocalizedString<TLocale>;
|
|
408
251
|
|
|
409
|
-
declare
|
|
410
|
-
|
|
411
|
-
declare function
|
|
252
|
+
declare const THEME_PRESETS: ReadonlyArray<ThemePreset>;
|
|
253
|
+
|
|
254
|
+
declare function calculateDistanceMeters(aLat: number, aLon: number, bLat: number, bLon: number): number;
|
|
255
|
+
declare function evaluateConditionDetailed(condition: CheckInCondition, context: VerificationContext): Result<ConditionMatch, ConditionMismatch>;
|
|
256
|
+
declare function evaluateCondition(condition: CheckInCondition, context: VerificationContext): boolean;
|
|
257
|
+
|
|
258
|
+
declare function getOrderedSpots<TLocale extends string, TMeta extends Record<string, unknown>>(spots: ReadonlyArray<SpotItem<TLocale, TMeta>>): ReadonlyArray<SpotItem<TLocale, TMeta>>;
|
|
412
259
|
|
|
413
260
|
interface StampRallyProgress {
|
|
414
261
|
readonly acquired: number;
|
|
415
262
|
readonly total: number;
|
|
416
263
|
readonly percentage: number;
|
|
417
264
|
readonly isCompleted: boolean;
|
|
418
|
-
|
|
419
|
-
readonly isComplete: boolean;
|
|
420
|
-
readonly nextAvailableStamps: ReadonlyArray<StampDefinition>;
|
|
265
|
+
readonly nextAvailableSpots: ReadonlyArray<PublicSpotItem>;
|
|
421
266
|
}
|
|
422
267
|
declare function calculateProgress(state: StampRallyState, config: RallyConfig): StampRallyProgress;
|
|
423
268
|
|
|
@@ -428,29 +273,10 @@ interface ClaimTicketOptions {
|
|
|
428
273
|
declare function createClaimTicketNumber(rewardId: string, options?: ClaimTicketOptions): string;
|
|
429
274
|
/** Creates a one-time ticket for a successful reward consumption. */
|
|
430
275
|
declare function createUniqueClaimTicketNumber(rewardId: string, issuedAt: string): string;
|
|
431
|
-
declare function issueClaimTicketNumber(reward:
|
|
276
|
+
declare function issueClaimTicketNumber(reward: Reward, currentState: RewardState, options?: ClaimTicketOptions): RewardState;
|
|
432
277
|
|
|
433
|
-
type StampRallyEvent = {
|
|
434
|
-
readonly type: "stampAcquired";
|
|
435
|
-
readonly record: StampRecord$1;
|
|
436
|
-
} | {
|
|
437
|
-
readonly type: "rallyCompleted";
|
|
438
|
-
readonly rallyId: string;
|
|
439
|
-
readonly completedAt: string;
|
|
440
|
-
} | {
|
|
441
|
-
readonly type: "rewardUnlocked";
|
|
442
|
-
readonly rewardId: string;
|
|
443
|
-
readonly unlockedAt: string;
|
|
444
|
-
};
|
|
445
|
-
interface ProcessStampValue {
|
|
446
|
-
readonly nextState: StampRallyState;
|
|
447
|
-
readonly events: ReadonlyArray<StampRallyEvent>;
|
|
448
|
-
}
|
|
449
278
|
type RewardConsumeError = {
|
|
450
|
-
readonly code: "NOT_AVAILABLE";
|
|
451
|
-
readonly rewardId: string;
|
|
452
|
-
} | {
|
|
453
|
-
readonly code: "ALREADY_CONSUMED";
|
|
279
|
+
readonly code: "NOT_AVAILABLE" | "ALREADY_CONSUMED" | "OUT_OF_STOCK" | "REWARD_NOT_FOUND";
|
|
454
280
|
readonly rewardId: string;
|
|
455
281
|
} | {
|
|
456
282
|
readonly code: "INVALID_PASSCODE";
|
|
@@ -458,37 +284,35 @@ type RewardConsumeError = {
|
|
|
458
284
|
readonly message: string;
|
|
459
285
|
} | {
|
|
460
286
|
readonly code: "EXPIRED";
|
|
461
|
-
readonly reason: "EXPIRED";
|
|
462
|
-
readonly rewardId: string;
|
|
463
|
-
} | {
|
|
464
|
-
readonly code: "OUT_OF_STOCK";
|
|
465
287
|
readonly rewardId: string;
|
|
466
288
|
} | {
|
|
467
289
|
readonly code: "USER_LIMIT_REACHED";
|
|
468
|
-
readonly reason: "LIMIT_EXCEEDED";
|
|
469
|
-
readonly rewardId: string;
|
|
470
|
-
} | {
|
|
471
|
-
readonly code: "REWARD_NOT_FOUND";
|
|
472
290
|
readonly rewardId: string;
|
|
473
291
|
};
|
|
474
292
|
interface ConsumeRewardParams {
|
|
475
|
-
readonly reward:
|
|
293
|
+
readonly reward: Reward;
|
|
476
294
|
readonly currentState: RewardState;
|
|
477
295
|
readonly inputPasscode?: string;
|
|
478
296
|
readonly staffId?: string;
|
|
479
297
|
readonly now: string;
|
|
480
|
-
readonly userId?: string;
|
|
481
298
|
readonly userRedemptionCount?: number;
|
|
482
299
|
}
|
|
483
300
|
type ConsumeResult = Result<RewardState, RewardConsumeError>;
|
|
484
|
-
declare function reconcileRewardStates(rewards: ReadonlyArray<
|
|
301
|
+
declare function reconcileRewardStates(rewards: ReadonlyArray<Reward>, currentStates: ReadonlyArray<RewardState>, acquiredStampCount: number, now: string): ReadonlyArray<RewardState>;
|
|
485
302
|
declare function consumeReward(params: ConsumeRewardParams): ConsumeResult;
|
|
486
|
-
|
|
303
|
+
interface ProcessStampValue {
|
|
304
|
+
readonly nextState: StampRallyState;
|
|
305
|
+
readonly events: ReadonlyArray<{
|
|
306
|
+
readonly type: "stampAcquired";
|
|
307
|
+
readonly record: StampRecord;
|
|
308
|
+
}>;
|
|
309
|
+
}
|
|
310
|
+
declare function processStamp(state: StampRallyState, config: AdminRallyConfig, spotId: string, context: VerificationContext, now: string): Result<ProcessStampValue, StampError>;
|
|
487
311
|
|
|
488
312
|
interface StampStorage {
|
|
489
|
-
load(rallyId: string): Promise<StampRallyState | null>;
|
|
313
|
+
load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
|
|
490
314
|
save(state: StampRallyState): Promise<void>;
|
|
491
|
-
remove(rallyId: string): Promise<void>;
|
|
315
|
+
remove(rallyId: string, userId: string | null): Promise<void>;
|
|
492
316
|
}
|
|
493
317
|
interface StorageLike {
|
|
494
318
|
getItem(key: string): string | null;
|
|
@@ -511,7 +335,8 @@ declare function isStampRallyState(value: unknown): value is StampRallyState;
|
|
|
511
335
|
interface RallySnapshot {
|
|
512
336
|
readonly version: 1;
|
|
513
337
|
readonly rallyId: string;
|
|
514
|
-
readonly
|
|
338
|
+
readonly userId: string | null;
|
|
339
|
+
readonly records: ReadonlyArray<StampRecord>;
|
|
515
340
|
readonly rewards: ReadonlyArray<RewardState>;
|
|
516
341
|
readonly exportedAt: string;
|
|
517
342
|
}
|
|
@@ -519,10 +344,11 @@ declare function exportProgressToken(snapshot: RallySnapshot): string;
|
|
|
519
344
|
declare function importProgressToken(token: string, currentRallyId: string): RallySnapshot | null;
|
|
520
345
|
declare class InMemoryStorage implements StampStorage {
|
|
521
346
|
#private;
|
|
522
|
-
load(rallyId: string): Promise<StampRallyState | null>;
|
|
347
|
+
load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
|
|
523
348
|
save(state: StampRallyState): Promise<void>;
|
|
524
|
-
remove(rallyId: string): Promise<void>;
|
|
349
|
+
remove(rallyId: string, userId: string | null): Promise<void>;
|
|
525
350
|
}
|
|
351
|
+
declare function storageKey(rallyId: string, userId: string | null): string;
|
|
526
352
|
interface LocalStorageAdapterOptions {
|
|
527
353
|
readonly storage?: StorageLike | null;
|
|
528
354
|
readonly keyPrefix?: string;
|
|
@@ -534,9 +360,9 @@ type StorageWarningHandler = (error: StorageAdapterError) => void;
|
|
|
534
360
|
declare class LocalStorageAdapter implements StampStorage {
|
|
535
361
|
#private;
|
|
536
362
|
constructor(options?: LocalStorageAdapterOptions);
|
|
537
|
-
load(rallyId: string): Promise<StampRallyState | null>;
|
|
363
|
+
load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
|
|
538
364
|
save(state: StampRallyState): Promise<void>;
|
|
539
|
-
remove(rallyId: string): Promise<void>;
|
|
365
|
+
remove(rallyId: string, userId: string | null): Promise<void>;
|
|
540
366
|
}
|
|
541
367
|
interface IndexedDBAdapterOptions {
|
|
542
368
|
readonly indexedDB?: IDBFactory | null;
|
|
@@ -545,47 +371,118 @@ interface IndexedDBAdapterOptions {
|
|
|
545
371
|
declare class IndexedDBAdapter implements StampStorage {
|
|
546
372
|
#private;
|
|
547
373
|
constructor(options?: IndexedDBAdapterOptions);
|
|
548
|
-
load(rallyId: string): Promise<StampRallyState | null>;
|
|
374
|
+
load(rallyId: string, userId: string | null): Promise<StampRallyState | null>;
|
|
549
375
|
save(state: StampRallyState): Promise<void>;
|
|
550
|
-
remove(rallyId: string): Promise<void>;
|
|
376
|
+
remove(rallyId: string, userId: string | null): Promise<void>;
|
|
551
377
|
}
|
|
552
378
|
|
|
553
|
-
type
|
|
554
|
-
|
|
379
|
+
type CheckInOptions = {
|
|
380
|
+
readonly now?: string;
|
|
381
|
+
readonly idempotencyKey?: string;
|
|
382
|
+
readonly sync?: boolean;
|
|
383
|
+
};
|
|
384
|
+
type ClaimOptions = {
|
|
385
|
+
readonly now?: string;
|
|
386
|
+
readonly idempotencyKey?: string;
|
|
387
|
+
readonly staffPasscode?: string;
|
|
388
|
+
readonly staffId?: string;
|
|
389
|
+
readonly sync?: boolean;
|
|
390
|
+
};
|
|
391
|
+
type ClientError = {
|
|
392
|
+
readonly code: "SPOT_NOT_FOUND" | "STAMP_ALREADY_ACQUIRED" | "PREREQUISITES_NOT_MET" | "INVALID_PROOF";
|
|
393
|
+
readonly spotId: string;
|
|
394
|
+
readonly message: string;
|
|
395
|
+
} | {
|
|
396
|
+
readonly code: "CUSTOM_VALIDATION_FAILED";
|
|
397
|
+
readonly spotId: string;
|
|
398
|
+
readonly message: string;
|
|
399
|
+
} | {
|
|
400
|
+
readonly code: "REWARD_NOT_FOUND";
|
|
401
|
+
readonly rewardId: string;
|
|
402
|
+
readonly message: string;
|
|
403
|
+
} | {
|
|
404
|
+
readonly code: "SYNC_FAILED";
|
|
405
|
+
readonly message: string;
|
|
406
|
+
} | RewardConsumeError;
|
|
407
|
+
interface CheckInSuccess {
|
|
408
|
+
readonly state: UserRallyState;
|
|
409
|
+
readonly record: StampRecord;
|
|
410
|
+
}
|
|
411
|
+
type CheckInResult = Result<CheckInSuccess, ClientError>;
|
|
412
|
+
interface ClaimSuccess {
|
|
413
|
+
readonly state: UserRallyState;
|
|
414
|
+
readonly reward: RewardState;
|
|
415
|
+
}
|
|
416
|
+
type ClaimResult = Result<ClaimSuccess, ClientError>;
|
|
417
|
+
type ClientEvent = {
|
|
555
418
|
readonly type: "checkIn";
|
|
556
|
-
readonly
|
|
557
|
-
readonly state: StampRallyState;
|
|
419
|
+
readonly result: CheckInResult;
|
|
558
420
|
} | {
|
|
559
421
|
readonly type: "rewardClaimed";
|
|
560
|
-
readonly
|
|
561
|
-
readonly state: StampRallyState;
|
|
422
|
+
readonly result: ClaimResult;
|
|
562
423
|
} | {
|
|
563
|
-
readonly type: "
|
|
564
|
-
readonly state:
|
|
424
|
+
readonly type: "sync";
|
|
425
|
+
readonly state: UserRallyState;
|
|
565
426
|
} | {
|
|
566
427
|
readonly type: "error";
|
|
567
|
-
readonly error:
|
|
428
|
+
readonly error: ClientError;
|
|
568
429
|
};
|
|
569
|
-
type
|
|
570
|
-
type
|
|
430
|
+
type ClientListener = (state: UserRallyState) => void;
|
|
431
|
+
type ClientEventListener = (event: ClientEvent) => void;
|
|
432
|
+
interface CheckInRequest {
|
|
433
|
+
readonly rallyId: string;
|
|
434
|
+
readonly userId: string | null;
|
|
435
|
+
readonly spotId: string;
|
|
436
|
+
readonly proofData: unknown;
|
|
437
|
+
readonly idempotencyKey: string;
|
|
438
|
+
readonly now: string;
|
|
439
|
+
readonly state: UserRallyState;
|
|
440
|
+
}
|
|
441
|
+
interface ClaimRequest {
|
|
442
|
+
readonly rallyId: string;
|
|
443
|
+
readonly userId: string | null;
|
|
444
|
+
readonly rewardId: string;
|
|
445
|
+
readonly idempotencyKey: string;
|
|
446
|
+
readonly now: string;
|
|
447
|
+
readonly options: ClaimOptions;
|
|
448
|
+
readonly state: UserRallyState;
|
|
449
|
+
}
|
|
450
|
+
interface SyncAdapter {
|
|
451
|
+
readonly checkIn?: (request: CheckInRequest) => Promise<CheckInResult>;
|
|
452
|
+
readonly claimReward?: (request: ClaimRequest) => Promise<ClaimResult>;
|
|
453
|
+
readonly sync?: (request: {
|
|
454
|
+
readonly rallyId: string;
|
|
455
|
+
readonly userId: string | null;
|
|
456
|
+
readonly state: UserRallyState;
|
|
457
|
+
}) => Promise<UserRallyState>;
|
|
458
|
+
}
|
|
459
|
+
interface ClientOptions {
|
|
460
|
+
readonly storage?: StampStorage;
|
|
461
|
+
readonly syncAdapter?: SyncAdapter;
|
|
462
|
+
readonly customValidator?: Validator;
|
|
463
|
+
readonly customValidators?: Readonly<Record<string, Validator>>;
|
|
464
|
+
readonly clock?: () => string;
|
|
465
|
+
readonly userId?: string | null;
|
|
466
|
+
}
|
|
467
|
+
type StorageOrOptions = StampStorage | ClientOptions;
|
|
571
468
|
declare class StampRallyClient {
|
|
572
469
|
#private;
|
|
573
|
-
constructor(config:
|
|
574
|
-
getState(): StampRallyState | null;
|
|
470
|
+
constructor(config: PublicRallyConfig, storageOrOptions?: StorageOrOptions);
|
|
575
471
|
getConfig(): RallyConfig;
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
472
|
+
getState(): UserRallyState | null;
|
|
473
|
+
getUserId(): string | null;
|
|
474
|
+
subscribe(listener: ClientListener): () => void;
|
|
475
|
+
subscribeEvents(listener: ClientEventListener): () => void;
|
|
476
|
+
init(): Promise<UserRallyState>;
|
|
477
|
+
initialize(): Promise<UserRallyState>;
|
|
478
|
+
switchUser(newUserId: string | null): Promise<UserRallyState>;
|
|
479
|
+
getUserState(rallyId: string, userId: string): Promise<UserRallyState | null>;
|
|
480
|
+
clearUserState(userId?: string | null): Promise<void>;
|
|
481
|
+
checkIn(spotId: string, proofData: unknown, options?: CheckInOptions): Promise<CheckInResult>;
|
|
482
|
+
claimReward(rewardId: string, options?: ClaimOptions): Promise<ClaimResult>;
|
|
483
|
+
sync(adapter?: SyncAdapter | undefined): Promise<void>;
|
|
484
|
+
reset(): Promise<UserRallyState>;
|
|
485
|
+
restore(state: UserRallyState): Promise<UserRallyState>;
|
|
589
486
|
}
|
|
590
487
|
|
|
591
488
|
type SecureTokenSecretKey = string | Uint8Array;
|
|
@@ -623,23 +520,19 @@ interface DetectorError {
|
|
|
623
520
|
readonly cause?: unknown;
|
|
624
521
|
}
|
|
625
522
|
type GeoVerificationContext = Extract<VerificationContext, {
|
|
626
|
-
readonly type: "
|
|
523
|
+
readonly type: "gps";
|
|
627
524
|
}>;
|
|
628
|
-
type
|
|
629
|
-
readonly type: "
|
|
525
|
+
type QrVerificationContext = Extract<VerificationContext, {
|
|
526
|
+
readonly type: "qr";
|
|
527
|
+
}>;
|
|
528
|
+
type NfcVerificationContext = Extract<VerificationContext, {
|
|
529
|
+
readonly type: "nfc";
|
|
630
530
|
}>;
|
|
631
531
|
type DetectorResult<T extends VerificationContext> = Result<T, DetectorError>;
|
|
632
|
-
interface PasscodeCondition {
|
|
633
|
-
readonly
|
|
532
|
+
interface PasscodeCondition$1 {
|
|
533
|
+
readonly code: string;
|
|
634
534
|
readonly caseSensitive?: boolean;
|
|
635
535
|
}
|
|
636
|
-
type CheckInResult = {
|
|
637
|
-
readonly success: true;
|
|
638
|
-
} | {
|
|
639
|
-
readonly success: false;
|
|
640
|
-
readonly reason: "INVALID_PASSCODE";
|
|
641
|
-
readonly message: string;
|
|
642
|
-
};
|
|
643
536
|
|
|
644
537
|
interface GeoDetectorOptions {
|
|
645
538
|
readonly enableHighAccuracy?: boolean;
|
|
@@ -653,10 +546,18 @@ interface NfcDetectorOptions {
|
|
|
653
546
|
readonly signal?: AbortSignal;
|
|
654
547
|
}
|
|
655
548
|
declare function isNfcSupported(): boolean;
|
|
656
|
-
declare function readNfcContext(options?: NfcDetectorOptions): Promise<DetectorResult<
|
|
549
|
+
declare function readNfcContext(options?: NfcDetectorOptions): Promise<DetectorResult<NfcVerificationContext>>;
|
|
657
550
|
|
|
551
|
+
interface PasscodeCondition {
|
|
552
|
+
readonly code: string;
|
|
553
|
+
readonly caseSensitive?: boolean;
|
|
554
|
+
}
|
|
555
|
+
interface PasscodeCheckResult {
|
|
556
|
+
readonly success: boolean;
|
|
557
|
+
readonly message?: string;
|
|
558
|
+
}
|
|
658
559
|
declare function normalizePasscode(input: string, caseSensitive?: boolean): string;
|
|
659
|
-
declare function verifyPasscode(inputCode: string, condition: PasscodeCondition):
|
|
560
|
+
declare function verifyPasscode(inputCode: string, condition: PasscodeCondition): PasscodeCheckResult;
|
|
660
561
|
|
|
661
562
|
interface QrDetectorOptions {
|
|
662
563
|
readonly timeout?: number;
|
|
@@ -664,188 +565,7 @@ interface QrDetectorOptions {
|
|
|
664
565
|
readonly facingMode?: "user" | "environment";
|
|
665
566
|
}
|
|
666
567
|
declare function isQrSupported(): boolean;
|
|
667
|
-
declare function readQrContext(videoElement: HTMLVideoElement, options?: QrDetectorOptions): Promise<DetectorResult<
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Branded identifiers keep values from different parts of the domain from
|
|
671
|
-
* being exchanged accidentally while remaining plain strings at runtime.
|
|
672
|
-
*/
|
|
673
|
-
type RallyId = string & {
|
|
674
|
-
readonly __brand: "RallyId";
|
|
675
|
-
};
|
|
676
|
-
type SpotId = string & {
|
|
677
|
-
readonly __brand: "SpotId";
|
|
678
|
-
};
|
|
679
|
-
type UserId = string & {
|
|
680
|
-
readonly __brand: "UserId";
|
|
681
|
-
};
|
|
682
|
-
type Metadata = Readonly<Record<string, unknown>>;
|
|
683
|
-
/** A locale-independent fallback plus zero or more locale-specific values. */
|
|
684
|
-
interface LocalizedText<TLocale extends string = string> {
|
|
685
|
-
readonly default: string;
|
|
686
|
-
readonly translations: Readonly<Partial<Record<TLocale, string>>>;
|
|
687
|
-
}
|
|
688
|
-
/** A reference to an entity owned by an external system. */
|
|
689
|
-
interface ExternalReference {
|
|
690
|
-
readonly systemId: string;
|
|
691
|
-
readonly entityType: string;
|
|
692
|
-
readonly entityId: string;
|
|
693
|
-
readonly attributes?: Metadata;
|
|
694
|
-
}
|
|
695
|
-
/** Public, non-secret configuration for one check-in location. */
|
|
696
|
-
interface SpotDefinition<TLocale extends string = string> {
|
|
697
|
-
readonly id: SpotId;
|
|
698
|
-
readonly name: LocalizedText<TLocale>;
|
|
699
|
-
readonly description?: LocalizedText<TLocale>;
|
|
700
|
-
readonly hint?: LocalizedText<TLocale>;
|
|
701
|
-
readonly order?: number;
|
|
702
|
-
readonly iconUrl?: string;
|
|
703
|
-
readonly imageUrl?: string;
|
|
704
|
-
readonly externalReference?: ExternalReference;
|
|
705
|
-
readonly metadata?: Metadata;
|
|
706
|
-
readonly verification: VerificationRequirement;
|
|
707
|
-
readonly dependsOn?: ReadonlyArray<SpotId>;
|
|
708
|
-
}
|
|
709
|
-
/** Public description of a verifier selected at runtime through DI. */
|
|
710
|
-
interface VerificationRequirement {
|
|
711
|
-
readonly pluginId: string;
|
|
712
|
-
/** Public parameters only; secrets belong to SpotVerificationSecret. */
|
|
713
|
-
readonly parameters?: Metadata;
|
|
714
|
-
}
|
|
715
|
-
/** Public configuration safe to distribute to a browser client. */
|
|
716
|
-
interface RallyDefinition<TLocale extends string = string> {
|
|
717
|
-
readonly id: RallyId;
|
|
718
|
-
readonly title: LocalizedText<TLocale>;
|
|
719
|
-
readonly description?: LocalizedText<TLocale>;
|
|
720
|
-
readonly spots: ReadonlyArray<SpotDefinition<TLocale>>;
|
|
721
|
-
readonly startsAt?: string;
|
|
722
|
-
readonly endsAt?: string;
|
|
723
|
-
readonly externalReference?: ExternalReference;
|
|
724
|
-
readonly metadata?: Metadata;
|
|
725
|
-
}
|
|
726
|
-
interface VerificationCoordinates {
|
|
727
|
-
readonly latitude: number;
|
|
728
|
-
readonly longitude: number;
|
|
729
|
-
readonly radiusMeters: number;
|
|
730
|
-
}
|
|
731
|
-
/** Server-only material used by a verifier. Never include this in a public definition. */
|
|
732
|
-
interface SpotVerificationSecret {
|
|
733
|
-
readonly spotId: SpotId;
|
|
734
|
-
readonly pluginId: string;
|
|
735
|
-
readonly secret?: string | Readonly<Uint8Array>;
|
|
736
|
-
readonly expectedValue?: string;
|
|
737
|
-
readonly coordinates?: VerificationCoordinates;
|
|
738
|
-
readonly metadata?: Metadata;
|
|
739
|
-
}
|
|
740
|
-
/** Server-only configuration composed from a public definition and secrets. */
|
|
741
|
-
interface ServerRallyConfig<TLocale extends string = string> {
|
|
742
|
-
readonly definition: RallyDefinition<TLocale>;
|
|
743
|
-
readonly verificationSecrets: ReadonlyArray<SpotVerificationSecret>;
|
|
744
|
-
readonly schemaVersion: SchemaVersion;
|
|
745
|
-
readonly metadata?: Metadata;
|
|
746
|
-
}
|
|
747
|
-
type SchemaVersion = number;
|
|
748
|
-
interface StampRecord {
|
|
749
|
-
readonly stampId: SpotId;
|
|
750
|
-
readonly acquiredAt: string;
|
|
751
|
-
readonly verificationPluginId?: string;
|
|
752
|
-
readonly metadata?: Metadata;
|
|
753
|
-
}
|
|
754
|
-
interface RallyProgress {
|
|
755
|
-
readonly rallyId: RallyId;
|
|
756
|
-
readonly userId: UserId;
|
|
757
|
-
readonly stamps: ReadonlyArray<StampRecord>;
|
|
758
|
-
/** Monotonically increasing revision used for optimistic locking. */
|
|
759
|
-
readonly stateSequence: number;
|
|
760
|
-
readonly schemaVersion: SchemaVersion;
|
|
761
|
-
readonly updatedAt: string;
|
|
762
|
-
readonly completedAt?: string;
|
|
763
|
-
readonly metadata?: Metadata;
|
|
764
|
-
}
|
|
765
|
-
interface StorageSaveRequest {
|
|
766
|
-
readonly progress: RallyProgress;
|
|
767
|
-
readonly expectedStateSequence: number;
|
|
768
|
-
readonly idempotencyKey: string;
|
|
769
|
-
}
|
|
770
|
-
type StorageSaveOutcome = {
|
|
771
|
-
readonly status: "saved";
|
|
772
|
-
readonly progress: RallyProgress;
|
|
773
|
-
readonly idempotent: boolean;
|
|
774
|
-
} | {
|
|
775
|
-
readonly status: "conflict";
|
|
776
|
-
readonly current: RallyProgress | null;
|
|
777
|
-
};
|
|
778
|
-
/** Persistence boundary. Implementations own transactions and concurrency control. */
|
|
779
|
-
interface StorageAdapter {
|
|
780
|
-
load(rallyId: RallyId, userId: UserId): Promise<RallyProgress | null>;
|
|
781
|
-
save(request: StorageSaveRequest): Promise<StorageSaveOutcome>;
|
|
782
|
-
}
|
|
783
|
-
interface AuthContextAdapter<TRequest = unknown> {
|
|
784
|
-
getUserId(request: TRequest): Promise<UserId | null> | UserId | null;
|
|
785
|
-
}
|
|
786
|
-
interface ValidationInput<TProof = unknown> {
|
|
787
|
-
readonly rallyId: RallyId;
|
|
788
|
-
readonly spotId: SpotId;
|
|
789
|
-
readonly userId: UserId;
|
|
790
|
-
readonly proof: TProof;
|
|
791
|
-
readonly requestedAt: string;
|
|
792
|
-
readonly publicParameters?: Metadata;
|
|
793
|
-
}
|
|
794
|
-
type ValidationOutcome = {
|
|
795
|
-
readonly valid: true;
|
|
796
|
-
readonly reason?: string;
|
|
797
|
-
readonly metadata?: Metadata;
|
|
798
|
-
} | {
|
|
799
|
-
readonly valid: false;
|
|
800
|
-
readonly code: string;
|
|
801
|
-
readonly reason?: string;
|
|
802
|
-
readonly metadata?: Metadata;
|
|
803
|
-
};
|
|
804
|
-
/** Pluggable verifier for GPS, TOTP/HMAC, signatures, or application rules. */
|
|
805
|
-
interface ConditionVerifierPlugin<TProof = unknown> {
|
|
806
|
-
readonly id: string;
|
|
807
|
-
verify(input: ValidationInput<TProof>, secret: SpotVerificationSecret): Promise<ValidationOutcome> | ValidationOutcome;
|
|
808
|
-
}
|
|
809
|
-
interface CheckInAttemptAuditEntry {
|
|
810
|
-
readonly rallyId: RallyId;
|
|
811
|
-
readonly spotId: SpotId;
|
|
812
|
-
readonly userId: UserId;
|
|
813
|
-
readonly attemptedAt: string;
|
|
814
|
-
readonly outcome: ValidationOutcome;
|
|
815
|
-
readonly idempotencyKey?: string;
|
|
816
|
-
/** Use a digest or other redacted representation; never require raw proof data. */
|
|
817
|
-
readonly proofDigest?: string;
|
|
818
|
-
readonly metadata?: Metadata;
|
|
819
|
-
}
|
|
820
|
-
interface AuditLoggerAdapter {
|
|
821
|
-
logCheckInAttempt(entry: CheckInAttemptAuditEntry): Promise<void>;
|
|
822
|
-
}
|
|
823
|
-
interface StampAcquiredEvent {
|
|
824
|
-
readonly type: "stampAcquired";
|
|
825
|
-
readonly rallyId: RallyId;
|
|
826
|
-
readonly spotId: SpotId;
|
|
827
|
-
readonly userId: UserId;
|
|
828
|
-
readonly record: StampRecord;
|
|
829
|
-
}
|
|
830
|
-
interface RallyCompletedEvent {
|
|
831
|
-
readonly type: "rallyCompleted";
|
|
832
|
-
readonly rallyId: RallyId;
|
|
833
|
-
readonly userId: UserId;
|
|
834
|
-
readonly completedAt: string;
|
|
835
|
-
}
|
|
836
|
-
type RallyEvent = StampAcquiredEvent | RallyCompletedEvent;
|
|
837
|
-
interface EventPublisherAdapter {
|
|
838
|
-
publish(event: RallyEvent): Promise<void>;
|
|
839
|
-
}
|
|
840
|
-
interface SystemClockAdapter {
|
|
841
|
-
now(): string;
|
|
842
|
-
}
|
|
843
|
-
interface IdGeneratorAdapter {
|
|
844
|
-
generate(): string;
|
|
845
|
-
}
|
|
846
|
-
interface StateMigrator {
|
|
847
|
-
migrate(state: unknown, fromVersion: SchemaVersion, toVersion: SchemaVersion): RallyProgress;
|
|
848
|
-
}
|
|
568
|
+
declare function readQrContext(videoElement: HTMLVideoElement, options?: QrDetectorOptions): Promise<DetectorResult<QrVerificationContext>>;
|
|
849
569
|
|
|
850
570
|
type SnapshotSecretKey = string | Uint8Array;
|
|
851
571
|
interface SnapshotTokenPayload {
|
|
@@ -870,4 +590,4 @@ type SnapshotTokenVerification<T extends SnapshotTokenPayload = SnapshotTokenPay
|
|
|
870
590
|
declare function createSignedSnapshotToken<T extends SnapshotTokenPayload>(payload: T, secretKey: SnapshotSecretKey): Promise<string>;
|
|
871
591
|
declare function verifySnapshotToken<T extends SnapshotTokenPayload = SnapshotTokenPayload>(token: string, secretKey: SnapshotSecretKey, now?: number): Promise<SnapshotTokenVerification<T>>;
|
|
872
592
|
|
|
873
|
-
export { type AdminRallyConfig, type
|
|
593
|
+
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, 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, InMemoryStorage, IndexedDBAdapter, type IndexedDBAdapterOptions, LocalStorageAdapter, type LocalStorageAdapterOptions, type LocalStorageFailureMode, type LocaleDictionary, type LocalizedString, type LocalizedText, type NfcDetectorOptions, type NfcVerificationContext, type PasscodeCondition$1 as PasscodeCondition, type ProcessStampValue, type PublicCheckInCondition, type PublicRallyConfig, type PublicReward, type PublicSpotItem, type QrDetectorOptions, type QrVerificationContext, type RallyConfig, type RallySnapshot, type RedemptionMethod, 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 StampError, StampRallyClient, type StampRallyProgress, type StampRallyState, type StampRecord, type StampStorage, StorageAdapterError, type StorageAdapterErrorCode, type StorageLike, type StorageOperation, type StorageWarningHandler, type SupportedLocale, type SyncAdapter, THEME_PRESETS, type ThemePreset, type ThemePresetId, type UserRallyState, type Validator, type VerificationContext, assertPublicConfig, calculateDistanceMeters, calculateProgress, consumeReward, createClaimTicketNumber, createSecureToken, createSignedSnapshotToken, createUniqueClaimTicketNumber, evaluateCondition, evaluateConditionDetailed, exportProgressToken, getCurrentGeoContext, getOrderedSpots, importProgressToken, isGeolocationSupported, isNfcSupported, isPublicConfig, isQrSupported, isRewardState, isStampRallyState, issueClaimTicketNumber, normalizePasscode, processStamp, readNfcContext, readQrContext, reconcileRewardStates, resolveLocalizedText, storageKey, toLocalizedString, toPublicConfig, verifyPasscode, verifySecureToken, verifySnapshotToken };
|