@stamprally/server 0.14.0 → 0.15.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/README.md +10 -3
- package/dist/index.cjs +326 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -4
- package/dist/index.d.ts +41 -4
- package/dist/index.js +325 -64
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,14 @@ interface ClaimRewardTransactionParams {
|
|
|
20
20
|
readonly idempotencyTtlMs?: number;
|
|
21
21
|
/** Used when the first claim is made before a user state has been stored. */
|
|
22
22
|
readonly initialUserState?: UserRallyState;
|
|
23
|
+
readonly stockKey?: string;
|
|
24
|
+
readonly secondaryStockKey?: string;
|
|
25
|
+
readonly initialStock?: number | null;
|
|
26
|
+
readonly initialSecondaryStock?: number | null;
|
|
23
27
|
}
|
|
24
28
|
interface ClaimRewardTransactionMutation {
|
|
25
29
|
readonly nextStock: number | null;
|
|
30
|
+
readonly nextSecondaryStock?: number | null;
|
|
26
31
|
readonly nextUserState: UserRallyState;
|
|
27
32
|
readonly auditLog: AuditLog;
|
|
28
33
|
/** The server response is persisted by the adapter with the idempotency key. */
|
|
@@ -60,6 +65,7 @@ interface ServerPersistenceAdapter {
|
|
|
60
65
|
*/
|
|
61
66
|
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
62
67
|
readonly stock: number | null;
|
|
68
|
+
readonly secondaryStock: number | null;
|
|
63
69
|
readonly claimCount: number;
|
|
64
70
|
readonly userState: UserRallyState;
|
|
65
71
|
}) => ClaimRewardTransactionMutation): Promise<{
|
|
@@ -100,6 +106,7 @@ declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapt
|
|
|
100
106
|
restoreRewardStock(rallyId: string, rewardId: string, count?: number): Promise<void>;
|
|
101
107
|
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
102
108
|
readonly stock: number | null;
|
|
109
|
+
readonly secondaryStock: number | null;
|
|
103
110
|
readonly claimCount: number;
|
|
104
111
|
readonly userState: UserRallyState;
|
|
105
112
|
}) => ClaimRewardTransactionMutation): Promise<{
|
|
@@ -144,10 +151,12 @@ interface SqlTransactionDatabase<Tx> {
|
|
|
144
151
|
interface SqlClaimRewardStore<Tx> {
|
|
145
152
|
readContext(transaction: Tx, params: ClaimRewardTransactionParams): Promise<{
|
|
146
153
|
readonly stock: number | null;
|
|
154
|
+
readonly secondaryStock?: number | null;
|
|
147
155
|
readonly claimCount: number;
|
|
148
156
|
readonly userState: UserRallyState;
|
|
149
157
|
}>;
|
|
150
158
|
writeStock(transaction: Tx, params: ClaimRewardTransactionParams, nextStock: number): Promise<void>;
|
|
159
|
+
writeSecondaryStock?(transaction: Tx, params: ClaimRewardTransactionParams, nextStock: number): Promise<void>;
|
|
151
160
|
writeUserState(transaction: Tx, params: ClaimRewardTransactionParams, state: UserRallyState): Promise<void>;
|
|
152
161
|
writeClaimRecord(transaction: Tx, params: ClaimRewardTransactionParams, state: UserRallyState): Promise<void>;
|
|
153
162
|
writeAudit(transaction: Tx, log: AuditLog): Promise<void>;
|
|
@@ -167,11 +176,33 @@ declare function executeClaimRewardTransaction<Tx>(database: SqlTransactionDatab
|
|
|
167
176
|
readonly success: boolean;
|
|
168
177
|
readonly error?: string;
|
|
169
178
|
}>;
|
|
179
|
+
interface SqlCheckInStore<Tx> {
|
|
180
|
+
readUserState?(transaction: Tx, params: CheckInTransactionParams): Promise<UserRallyState>;
|
|
181
|
+
writeUserState(transaction: Tx, params: CheckInTransactionParams, state: UserRallyState): Promise<void>;
|
|
182
|
+
writeAudit(transaction: Tx, log: AuditLog): Promise<void>;
|
|
183
|
+
writeIdempotency(transaction: Tx, params: CheckInTransactionParams, result: unknown): Promise<void>;
|
|
184
|
+
}
|
|
185
|
+
/** Reference transaction block for a check-in state, audit, and idempotency write. */
|
|
186
|
+
declare function executeCheckInTransaction<Tx>(database: SqlTransactionDatabase<Tx>, store: SqlCheckInStore<Tx>, params: CheckInTransactionParams, mutation: (current: {
|
|
187
|
+
readonly userState: UserRallyState;
|
|
188
|
+
}) => CheckInTransactionMutation, current?: UserRallyState): Promise<{
|
|
189
|
+
readonly success: boolean;
|
|
190
|
+
readonly error?: string;
|
|
191
|
+
}>;
|
|
192
|
+
interface RedisMultiExecutor<TMulti> {
|
|
193
|
+
multi(): TMulti;
|
|
194
|
+
exec(multi: TMulti): Promise<ReadonlyArray<unknown> | null>;
|
|
195
|
+
}
|
|
196
|
+
/** Reference for Redis MULTI/EXEC adapters: all queued commands commit together. */
|
|
197
|
+
declare function executeRedisTransaction<TMulti>(redis: RedisMultiExecutor<TMulti>, queue: (multi: TMulti) => void): Promise<{
|
|
198
|
+
readonly success: boolean;
|
|
199
|
+
readonly error?: string;
|
|
200
|
+
}>;
|
|
170
201
|
|
|
171
202
|
interface RequestValidationError {
|
|
172
203
|
readonly path: string;
|
|
173
204
|
readonly message: string;
|
|
174
|
-
readonly code:
|
|
205
|
+
readonly code: string;
|
|
175
206
|
}
|
|
176
207
|
type RequestValidationResult<T> = {
|
|
177
208
|
readonly success: true;
|
|
@@ -196,7 +227,12 @@ type ClaimResponse = {
|
|
|
196
227
|
readonly ok: true;
|
|
197
228
|
readonly state: UserRallyState;
|
|
198
229
|
readonly claimTicketNumber?: string;
|
|
230
|
+
readonly inventory?: InventoryStatus;
|
|
199
231
|
} | ErrorResponse;
|
|
232
|
+
interface InventoryStatus {
|
|
233
|
+
readonly sharedRemaining?: number;
|
|
234
|
+
readonly rewardRemaining?: number;
|
|
235
|
+
}
|
|
200
236
|
declare class StampRallyServer {
|
|
201
237
|
#private;
|
|
202
238
|
constructor(config: AdminRallyConfig, persistence: ServerPersistenceAdapter, options?: ServerOptions);
|
|
@@ -231,7 +267,7 @@ interface CheckInRequest {
|
|
|
231
267
|
readonly spotId: string;
|
|
232
268
|
readonly context: _stamprally_core.VerificationContext;
|
|
233
269
|
readonly idempotencyKey: string;
|
|
234
|
-
readonly now?: string;
|
|
270
|
+
readonly now?: string | number;
|
|
235
271
|
}
|
|
236
272
|
interface ClaimRewardRequest {
|
|
237
273
|
readonly rallyId: string;
|
|
@@ -240,7 +276,7 @@ interface ClaimRewardRequest {
|
|
|
240
276
|
readonly idempotencyKey: string;
|
|
241
277
|
readonly staffPasscode?: string;
|
|
242
278
|
readonly staffId?: string;
|
|
243
|
-
readonly now?: string;
|
|
279
|
+
readonly now?: string | number;
|
|
244
280
|
}
|
|
245
281
|
type CheckInResponse = {
|
|
246
282
|
readonly ok: true;
|
|
@@ -258,9 +294,10 @@ interface ServerOptions {
|
|
|
258
294
|
readonly authenticate?: (request: Request) => Promise<string | AuthenticationContext | null> | string | AuthenticationContext | null;
|
|
259
295
|
readonly customValidators?: Readonly<Record<string, _stamprally_core.Validator>>;
|
|
260
296
|
readonly now?: () => string;
|
|
297
|
+
readonly anonymousPolicy?: "session_scoped" | "reject";
|
|
261
298
|
}
|
|
262
299
|
interface AuthenticationContext {
|
|
263
300
|
readonly authenticatedUserId: string;
|
|
264
301
|
}
|
|
265
302
|
|
|
266
|
-
export { type AuditLog, type AuthenticationContext, type CheckInRequest, type CheckInResponse, type CheckInTransactionMutation, type CheckInTransactionParams, type ClaimRewardRequest, type ClaimRewardTransactionMutation, type ClaimRewardTransactionParams, InMemoryServerPersistenceAdapter, type InMemoryServerPersistenceOptions, type RequestValidationError, type RequestValidationResult, type ServerOptions, type ServerPersistenceAdapter, type SqlClaimRewardStore, type SqlTransactionDatabase, StampRallyServer, type SyncOperationStatus, type UserClaimRecord, executeClaimRewardTransaction, validateCheckInRequest, validateClaimRewardRequest, validateSyncRequest };
|
|
303
|
+
export { type AuditLog, type AuthenticationContext, type CheckInRequest, type CheckInResponse, type CheckInTransactionMutation, type CheckInTransactionParams, type ClaimRewardRequest, type ClaimRewardTransactionMutation, type ClaimRewardTransactionParams, InMemoryServerPersistenceAdapter, type InMemoryServerPersistenceOptions, type RedisMultiExecutor, type RequestValidationError, type RequestValidationResult, type ServerOptions, type ServerPersistenceAdapter, type SqlCheckInStore, type SqlClaimRewardStore, type SqlTransactionDatabase, StampRallyServer, type SyncOperationStatus, type UserClaimRecord, executeCheckInTransaction, executeClaimRewardTransaction, executeRedisTransaction, validateCheckInRequest, validateClaimRewardRequest, validateSyncRequest };
|