@simonarcher/fika-types 1.0.43 → 1.0.45

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.ts CHANGED
@@ -7,3 +7,4 @@ export * from './coffeeEvents';
7
7
  export * from './quest';
8
8
  export * from './notificationChannels';
9
9
  export * from './userShopOrder';
10
+ export * from './loyalty';
package/dist/index.js CHANGED
@@ -32,3 +32,5 @@ __exportStar(require("./quest"), exports);
32
32
  __exportStar(require("./notificationChannels"), exports);
33
33
  // Export all user shop order-related types
34
34
  __exportStar(require("./userShopOrder"), exports);
35
+ // Export all loyalty-related types
36
+ __exportStar(require("./loyalty"), exports);
@@ -0,0 +1,339 @@
1
+ import { Timestamp as AdminTimestamp } from "firebase-admin/firestore";
2
+ /**
3
+ * JWT payload structure for voucher QR codes
4
+ * Contains essential voucher information for secure redemption
5
+ */
6
+ export interface QRTokenPayload {
7
+ /** Unique voucher identifier */
8
+ voucherId: string;
9
+ /** User who owns the voucher */
10
+ userId: string;
11
+ /** Shop where voucher can be redeemed */
12
+ shopId: string;
13
+ /** Token expiry timestamp (Unix time) */
14
+ exp: number;
15
+ /** Token issued at timestamp (Unix time) */
16
+ iat: number;
17
+ /** 6-digit backup verification code */
18
+ securityCode: string;
19
+ }
20
+ /**
21
+ * Enhanced voucher document with QR token support
22
+ * Extends the basic voucher with security and redemption tracking
23
+ */
24
+ export interface LoyaltyVoucher {
25
+ /** Unique voucher identifier */
26
+ id: string;
27
+ /** User who earned the voucher */
28
+ userId: string;
29
+ /** Shop where voucher can be redeemed */
30
+ shopId: string;
31
+ /** Stamps used to create this voucher */
32
+ stamps: string[];
33
+ /** When voucher was created */
34
+ createdAt: AdminTimestamp;
35
+ /** Whether voucher is still valid */
36
+ valid: boolean;
37
+ /** Whether voucher has been redeemed */
38
+ redeemed: boolean;
39
+ /** When voucher was redeemed (if applicable) */
40
+ redeemedAt?: AdminTimestamp;
41
+ /** Staff member who processed redemption */
42
+ redeemedBy?: string;
43
+ /** Shop ID where redemption occurred */
44
+ redemptionLocation?: string;
45
+ /** Current QR token (if active) */
46
+ qrToken?: string;
47
+ /** When current QR token expires */
48
+ tokenExpiresAt?: AdminTimestamp;
49
+ /** Current 6-digit security code */
50
+ securityCode?: string;
51
+ /** Type of reward (e.g., 'free_coffee', 'discount') */
52
+ rewardType: string;
53
+ /** Human-readable reward description */
54
+ rewardDescription: string;
55
+ }
56
+ /**
57
+ * Request to generate a new QR token for a voucher
58
+ */
59
+ export interface GenerateQRRequest {
60
+ /** Voucher to generate QR code for */
61
+ voucherId: string;
62
+ /** User requesting the QR code */
63
+ userId: string;
64
+ }
65
+ /**
66
+ * Response containing QR token information
67
+ */
68
+ export interface GenerateQRResponse {
69
+ /** JWT token for QR code */
70
+ qrToken: string;
71
+ /** When token expires (ISO string) */
72
+ expiresAt: string;
73
+ /** 6-digit backup code */
74
+ securityCode: string;
75
+ /** Success status */
76
+ success: boolean;
77
+ }
78
+ /**
79
+ * Request to redeem a voucher via QR scan
80
+ */
81
+ export interface RedeemVoucherRequest {
82
+ /** JWT token from QR code */
83
+ qrToken: string;
84
+ /** Staff member processing redemption */
85
+ staffId: string;
86
+ /** Shop where redemption is happening */
87
+ shopId: string;
88
+ }
89
+ /**
90
+ * Request to validate a voucher without redeeming
91
+ */
92
+ export interface ValidateVoucherRequest {
93
+ /** JWT token from QR code */
94
+ qrToken: string;
95
+ /** Shop validating the voucher */
96
+ shopId: string;
97
+ }
98
+ /**
99
+ * User information for voucher redemption display
100
+ */
101
+ export interface VoucherUserInfo {
102
+ /** User's display name */
103
+ name?: string;
104
+ /** User's email */
105
+ email?: string;
106
+ /** User's profile picture URL */
107
+ profilePicture?: string;
108
+ /** User ID */
109
+ userId: string;
110
+ }
111
+ /**
112
+ * Response for voucher redemption
113
+ */
114
+ export interface RedeemVoucherResponse {
115
+ /** Whether redemption was successful */
116
+ success: boolean;
117
+ /** Error message if redemption failed */
118
+ message?: string;
119
+ /** Redeemed voucher details */
120
+ voucher?: LoyaltyVoucher;
121
+ /** User information */
122
+ user?: VoucherUserInfo;
123
+ }
124
+ /**
125
+ * Response for voucher validation
126
+ */
127
+ export interface ValidateVoucherResponse {
128
+ /** Whether voucher is valid */
129
+ valid: boolean;
130
+ /** Error message if validation failed */
131
+ message?: string;
132
+ /** Voucher details (if valid) */
133
+ voucher?: LoyaltyVoucher;
134
+ /** User information (if valid) */
135
+ user?: VoucherUserInfo;
136
+ }
137
+ /**
138
+ * Configuration for QR token generation
139
+ */
140
+ export interface QRTokenConfig {
141
+ /** JWT secret for signing tokens */
142
+ secret: string;
143
+ /** Token expiry time in minutes */
144
+ expiryMinutes: number;
145
+ }
146
+ /**
147
+ * Request to refresh a QR token
148
+ */
149
+ export interface RefreshQRTokenRequest {
150
+ /** Current QR token (can be expired) */
151
+ qrToken: string;
152
+ /** User ID for verification */
153
+ userId: string;
154
+ /** Optional custom expiry time in minutes */
155
+ customExpiryMinutes?: number;
156
+ }
157
+ /**
158
+ * Response from QR token refresh
159
+ */
160
+ export interface RefreshQRTokenResponse {
161
+ /** Success status */
162
+ success: boolean;
163
+ /** New QR token (if successful) */
164
+ qrToken?: string;
165
+ /** New expiry time (if successful) */
166
+ expiresAt?: string;
167
+ /** New security code (if successful) */
168
+ securityCode?: string;
169
+ /** Error message (if failed) */
170
+ message?: string;
171
+ /** Time remaining on old token (if any) */
172
+ oldTokenTimeRemaining?: {
173
+ totalMs: number;
174
+ minutes: number;
175
+ seconds: number;
176
+ isExpired: boolean;
177
+ };
178
+ }
179
+ /**
180
+ * Request to check QR token expiry status
181
+ */
182
+ export interface CheckTokenExpiryRequest {
183
+ /** QR token to check */
184
+ qrToken: string;
185
+ /** User ID for verification */
186
+ userId: string;
187
+ }
188
+ /**
189
+ * Response from token expiry check
190
+ */
191
+ export interface CheckTokenExpiryResponse {
192
+ /** Success status */
193
+ success: boolean;
194
+ /** Whether token is expired */
195
+ isExpired: boolean;
196
+ /** Expiry time */
197
+ expiresAt?: string;
198
+ /** Time remaining until expiry */
199
+ timeRemaining?: {
200
+ totalMs: number;
201
+ minutes: number;
202
+ seconds: number;
203
+ };
204
+ /** Voucher information */
205
+ voucherInfo?: {
206
+ voucherId: string;
207
+ shopId: string;
208
+ };
209
+ /** Error message (if failed) */
210
+ message?: string;
211
+ }
212
+ /**
213
+ * User QR code payload for stamp collection
214
+ * Simple user identification for business scanning
215
+ */
216
+ export interface UserQRPayload {
217
+ /** User ID for identification */
218
+ userId: string;
219
+ /** User's name for display */
220
+ userName?: string;
221
+ /** QR generation timestamp */
222
+ generatedAt: number;
223
+ /** QR code type identifier */
224
+ type: 'user_identification';
225
+ }
226
+ /**
227
+ * Request to validate a user QR code
228
+ */
229
+ export interface ValidateUserQRRequest {
230
+ /** User QR code content */
231
+ userQR: string;
232
+ /** Shop ID where validation is happening */
233
+ shopId: string;
234
+ /** Staff ID performing the validation */
235
+ staffId?: string;
236
+ }
237
+ /**
238
+ * Response from user QR validation
239
+ */
240
+ export interface ValidateUserQRResponse {
241
+ /** Whether validation was successful */
242
+ success: boolean;
243
+ /** Whether the QR code is valid */
244
+ valid: boolean;
245
+ /** Error message if validation failed */
246
+ message?: string;
247
+ /** User information if valid */
248
+ user?: {
249
+ userId: string;
250
+ name?: string;
251
+ email?: string;
252
+ profilePicture?: string;
253
+ };
254
+ /** Current stamp count for this shop */
255
+ currentStamps?: number;
256
+ /** Stamps required for voucher */
257
+ stampsRequired?: number;
258
+ /** Whether user can create a voucher */
259
+ canCreateVoucher?: boolean;
260
+ }
261
+ /**
262
+ * Request to reward stamps to a user
263
+ */
264
+ export interface RewardStampsRequest {
265
+ /** User to reward stamps to */
266
+ userId: string;
267
+ /** Shop awarding the stamps */
268
+ shopId: string;
269
+ /** Number of stamps to award */
270
+ stampCount: number;
271
+ /** Staff member awarding the stamps */
272
+ staffId: string;
273
+ /** Method of stamp award */
274
+ issueMethod: 'app' | 'nfc';
275
+ /** Type of stamp */
276
+ type?: string;
277
+ }
278
+ /**
279
+ * Response from stamp reward
280
+ */
281
+ export interface RewardStampsResponse {
282
+ /** Whether reward was successful */
283
+ success: boolean;
284
+ /** Error message if failed */
285
+ message?: string;
286
+ /** New total stamp count for user at shop */
287
+ newStampCount?: number;
288
+ /** Stamps awarded in this transaction */
289
+ stampsAwarded?: number;
290
+ /** User information */
291
+ user?: {
292
+ userId: string;
293
+ name?: string;
294
+ email?: string;
295
+ };
296
+ /** Whether user can now create a voucher */
297
+ canCreateVoucher?: boolean;
298
+ /** Stamps required for voucher */
299
+ stampsRequired?: number;
300
+ /** Action ID for the stamp reward transaction */
301
+ actionId?: string;
302
+ }
303
+ /**
304
+ * Request to get user stamp progress
305
+ */
306
+ export interface UserStampProgressRequest {
307
+ /** User ID */
308
+ userId: string;
309
+ /** Shop ID */
310
+ shopId: string;
311
+ }
312
+ /**
313
+ * Response with user stamp progress
314
+ */
315
+ export interface UserStampProgressResponse {
316
+ /** Success status */
317
+ success: boolean;
318
+ /** Current number of stamps */
319
+ currentStamps: number;
320
+ /** Stamps required for voucher */
321
+ stampsRequired: number;
322
+ /** Whether user can create voucher */
323
+ canCreateVoucher: boolean;
324
+ /** User information */
325
+ user?: {
326
+ userId: string;
327
+ name?: string;
328
+ email?: string;
329
+ };
330
+ /** Shop information */
331
+ shop?: {
332
+ shopId: string;
333
+ name?: string;
334
+ rewardType?: string;
335
+ rewardDescription?: string;
336
+ };
337
+ /** Error message if failed */
338
+ message?: string;
339
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,11 @@
1
+ export interface SaveUserShopOrderRequest {
2
+ userId: string;
3
+ shopId: string;
4
+ orderDate: Date;
5
+ loyaltyRewardActionId?: string;
6
+ items: UserShopOrderItem[];
7
+ servedByStaffId?: string;
8
+ }
1
9
  export interface UserShopOrder {
2
10
  id: string;
3
11
  userId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonarcher/fika-types",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "Shared TypeScript types for Fika projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",