@stamprally/server 0.15.0 → 0.17.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 +1 -1
- package/dist/index.cjs +476 -134
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -30
- package/dist/index.d.ts +65 -30
- package/dist/index.js +472 -135
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,16 @@ import * as _stamprally_core from '@stamprally/core';
|
|
|
2
2
|
import { UserRallyState, AdminRallyConfig } from '@stamprally/core';
|
|
3
3
|
export { UserRallyState } from '@stamprally/core';
|
|
4
4
|
|
|
5
|
+
/** Authentication already verified by the host application's middleware. */
|
|
6
|
+
interface TrustedAuthContext {
|
|
7
|
+
readonly authenticatedUserId: string;
|
|
8
|
+
readonly isAnonymous?: boolean;
|
|
9
|
+
readonly sessionId?: string;
|
|
10
|
+
readonly claims?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** @deprecated Use TrustedAuthContext. */
|
|
13
|
+
type AuthenticationContext = TrustedAuthContext;
|
|
14
|
+
|
|
5
15
|
interface UserClaimRecord {
|
|
6
16
|
readonly rallyId: string;
|
|
7
17
|
readonly userId: string;
|
|
@@ -18,6 +28,10 @@ interface ClaimRewardTransactionParams {
|
|
|
18
28
|
readonly idempotencyKey?: string;
|
|
19
29
|
readonly proofData?: unknown;
|
|
20
30
|
readonly idempotencyTtlMs?: number;
|
|
31
|
+
/** The configured per-reward stock limit, or null for unlimited stock. */
|
|
32
|
+
readonly rewardStockLimit: number | null;
|
|
33
|
+
/** The configured shared stock limit, or null when shared inventory is disabled. */
|
|
34
|
+
readonly sharedStockLimit: number | null;
|
|
21
35
|
/** Used when the first claim is made before a user state has been stored. */
|
|
22
36
|
readonly initialUserState?: UserRallyState;
|
|
23
37
|
readonly stockKey?: string;
|
|
@@ -35,6 +49,16 @@ interface ClaimRewardTransactionMutation {
|
|
|
35
49
|
/** A domain rejection is committed as an audit/idempotency record without mutations. */
|
|
36
50
|
readonly error?: string;
|
|
37
51
|
}
|
|
52
|
+
interface ClaimRewardMutationContext {
|
|
53
|
+
readonly rewardStock: number | null;
|
|
54
|
+
readonly sharedStock: number | null;
|
|
55
|
+
readonly primaryStock: number | null;
|
|
56
|
+
readonly secondaryStock: number | null;
|
|
57
|
+
/** @deprecated Use rewardStock. */
|
|
58
|
+
readonly stock: number | null;
|
|
59
|
+
readonly claimCount: number;
|
|
60
|
+
readonly userState: UserRallyState;
|
|
61
|
+
}
|
|
38
62
|
interface CheckInTransactionParams {
|
|
39
63
|
readonly rallyId: string;
|
|
40
64
|
readonly userId: string;
|
|
@@ -63,15 +87,12 @@ interface ServerPersistenceAdapter {
|
|
|
63
87
|
* Atomically commits stock, user state, claim count, audit log, and idempotency data.
|
|
64
88
|
* Adapters must roll back every write when the callback or any commit operation fails.
|
|
65
89
|
*/
|
|
66
|
-
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
67
|
-
readonly stock: number | null;
|
|
68
|
-
readonly secondaryStock: number | null;
|
|
69
|
-
readonly claimCount: number;
|
|
70
|
-
readonly userState: UserRallyState;
|
|
71
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
90
|
+
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
72
91
|
readonly success: boolean;
|
|
73
92
|
readonly error?: string;
|
|
74
93
|
}>;
|
|
94
|
+
/** Set false when the adapter cannot persist per-reward inventory atomically. */
|
|
95
|
+
readonly supportsRewardStock?: boolean;
|
|
75
96
|
acquireLock(rallyId: string, lockKey: string, ttlMs: number): Promise<boolean>;
|
|
76
97
|
releaseLock(rallyId: string, lockKey: string): Promise<void>;
|
|
77
98
|
getRewardStock(rallyId: string, rewardId: string): Promise<number | null>;
|
|
@@ -95,6 +116,7 @@ interface InMemoryServerPersistenceOptions {
|
|
|
95
116
|
}
|
|
96
117
|
declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapter {
|
|
97
118
|
#private;
|
|
119
|
+
readonly supportsRewardStock: boolean;
|
|
98
120
|
constructor(options?: InMemoryServerPersistenceOptions);
|
|
99
121
|
acquireLock(rallyId: string, key: string, ttlMs: number): Promise<boolean>;
|
|
100
122
|
releaseLock(rallyId: string, key: string): Promise<void>;
|
|
@@ -104,12 +126,7 @@ declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapt
|
|
|
104
126
|
remainingStock: number;
|
|
105
127
|
}>;
|
|
106
128
|
restoreRewardStock(rallyId: string, rewardId: string, count?: number): Promise<void>;
|
|
107
|
-
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
108
|
-
readonly stock: number | null;
|
|
109
|
-
readonly secondaryStock: number | null;
|
|
110
|
-
readonly claimCount: number;
|
|
111
|
-
readonly userState: UserRallyState;
|
|
112
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
129
|
+
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
113
130
|
readonly success: boolean;
|
|
114
131
|
readonly error?: string;
|
|
115
132
|
}>;
|
|
@@ -135,7 +152,7 @@ declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapt
|
|
|
135
152
|
/** @deprecated Use recordUserClaim with a ticket number and timestamp. */
|
|
136
153
|
recordClaim(params: UserClaimRecord): Promise<void>;
|
|
137
154
|
recordClaim(rallyId: string, userId: string, rewardId: string): Promise<void>;
|
|
138
|
-
runTransaction<T>(
|
|
155
|
+
runTransaction<T>(rallyId: string, operation: (transaction: ServerPersistenceAdapter) => Promise<T>): Promise<T>;
|
|
139
156
|
}
|
|
140
157
|
|
|
141
158
|
/**
|
|
@@ -168,11 +185,7 @@ interface SqlClaimRewardStore<Tx> {
|
|
|
168
185
|
* while unexpected write failures reject the transaction and roll everything
|
|
169
186
|
* back.
|
|
170
187
|
*/
|
|
171
|
-
declare function executeClaimRewardTransaction<Tx>(database: SqlTransactionDatabase<Tx>, store: SqlClaimRewardStore<Tx>, params: ClaimRewardTransactionParams, mutation: (current: {
|
|
172
|
-
readonly stock: number | null;
|
|
173
|
-
readonly claimCount: number;
|
|
174
|
-
readonly userState: UserRallyState;
|
|
175
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
188
|
+
declare function executeClaimRewardTransaction<Tx>(database: SqlTransactionDatabase<Tx>, store: SqlClaimRewardStore<Tx>, params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
176
189
|
readonly success: boolean;
|
|
177
190
|
readonly error?: string;
|
|
178
191
|
}>;
|
|
@@ -211,11 +224,27 @@ type RequestValidationResult<T> = {
|
|
|
211
224
|
readonly success: false;
|
|
212
225
|
readonly errors: ReadonlyArray<RequestValidationError>;
|
|
213
226
|
};
|
|
227
|
+
declare class RequestValidationException extends Error {
|
|
228
|
+
readonly code = "VALIDATION_FAILED";
|
|
229
|
+
readonly errors: ReadonlyArray<RequestValidationError>;
|
|
230
|
+
constructor(errors: ReadonlyArray<RequestValidationError>);
|
|
231
|
+
}
|
|
214
232
|
declare function validateCheckInRequest(value: unknown): RequestValidationResult<CheckInRequest>;
|
|
215
233
|
declare function validateClaimRewardRequest(value: unknown): RequestValidationResult<ClaimRewardRequest>;
|
|
234
|
+
declare function assertValidCheckInParams(value: unknown, config: AdminRallyConfig): asserts value is CheckInRequest & {
|
|
235
|
+
readonly userId: string;
|
|
236
|
+
};
|
|
237
|
+
declare function assertValidClaimParams(value: unknown, config: AdminRallyConfig): asserts value is ClaimRewardRequest & {
|
|
238
|
+
readonly userId: string;
|
|
239
|
+
};
|
|
240
|
+
declare function assertValidSyncParams(value: unknown, config: AdminRallyConfig): asserts value is {
|
|
241
|
+
readonly rallyId: string;
|
|
242
|
+
readonly userId: string;
|
|
243
|
+
};
|
|
216
244
|
declare function validateSyncRequest(value: unknown): RequestValidationResult<{
|
|
217
245
|
readonly rallyId: string;
|
|
218
246
|
readonly userId?: string;
|
|
247
|
+
readonly anonymousSessionId?: string;
|
|
219
248
|
}>;
|
|
220
249
|
|
|
221
250
|
type ErrorResponse = {
|
|
@@ -240,15 +269,22 @@ declare class StampRallyServer {
|
|
|
240
269
|
handleCheckIn(request: Request): Promise<Response>;
|
|
241
270
|
handleClaimReward(request: Request): Promise<Response>;
|
|
242
271
|
handleSync(request: Request): Promise<Response>;
|
|
243
|
-
checkIn(request: CheckInRequest
|
|
244
|
-
|
|
245
|
-
}): Promise<CheckInResponse>;
|
|
246
|
-
claimReward(request: ClaimRewardRequest & {
|
|
247
|
-
readonly userId: string;
|
|
248
|
-
}): Promise<ClaimResponse>;
|
|
272
|
+
checkIn(request: CheckInRequest, authContext?: TrustedAuthContext): Promise<CheckInResponse>;
|
|
273
|
+
claimReward(request: ClaimRewardRequest, authContext?: TrustedAuthContext): Promise<ClaimResponse>;
|
|
249
274
|
sync(rallyId: string, userId: string): Promise<UserRallyState>;
|
|
275
|
+
syncProgress(request: {
|
|
276
|
+
readonly rallyId: string;
|
|
277
|
+
readonly userId?: string;
|
|
278
|
+
readonly anonymousSessionId?: string;
|
|
279
|
+
}): Promise<UserRallyState>;
|
|
250
280
|
}
|
|
251
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Runs the minimum atomicity and idempotency contract against a persistence adapter.
|
|
284
|
+
* The function throws a descriptive error when the adapter violates the contract.
|
|
285
|
+
*/
|
|
286
|
+
declare function runPersistenceAdapterComplianceTests(createAdapter: () => Promise<ServerPersistenceAdapter>): Promise<void>;
|
|
287
|
+
|
|
252
288
|
interface AuditLog {
|
|
253
289
|
readonly id: string;
|
|
254
290
|
readonly timestamp: string;
|
|
@@ -264,6 +300,7 @@ type SyncOperationStatus = "ACCEPTED" | "REJECTED_PERMANENT" | "RETRYABLE_ERROR"
|
|
|
264
300
|
interface CheckInRequest {
|
|
265
301
|
readonly rallyId: string;
|
|
266
302
|
readonly userId?: string;
|
|
303
|
+
readonly anonymousSessionId?: string;
|
|
267
304
|
readonly spotId: string;
|
|
268
305
|
readonly context: _stamprally_core.VerificationContext;
|
|
269
306
|
readonly idempotencyKey: string;
|
|
@@ -272,6 +309,7 @@ interface CheckInRequest {
|
|
|
272
309
|
interface ClaimRewardRequest {
|
|
273
310
|
readonly rallyId: string;
|
|
274
311
|
readonly userId?: string;
|
|
312
|
+
readonly anonymousSessionId?: string;
|
|
275
313
|
readonly rewardId: string;
|
|
276
314
|
readonly idempotencyKey: string;
|
|
277
315
|
readonly staffPasscode?: string;
|
|
@@ -291,13 +329,10 @@ type CheckInResponse = {
|
|
|
291
329
|
interface ServerOptions {
|
|
292
330
|
readonly lockTtlMs?: number;
|
|
293
331
|
readonly idempotencyTtlMs?: number;
|
|
294
|
-
readonly authenticate?: (request: Request) => Promise<string |
|
|
332
|
+
readonly authenticate?: (request: Request) => Promise<string | TrustedAuthContext | null> | string | TrustedAuthContext | null;
|
|
295
333
|
readonly customValidators?: Readonly<Record<string, _stamprally_core.Validator>>;
|
|
296
334
|
readonly now?: () => string;
|
|
297
|
-
readonly anonymousPolicy?: "session_scoped" | "reject";
|
|
298
|
-
}
|
|
299
|
-
interface AuthenticationContext {
|
|
300
|
-
readonly authenticatedUserId: string;
|
|
335
|
+
readonly anonymousPolicy?: "session_scoped" | "reject" | "shared_global_opt_in_insecure";
|
|
301
336
|
}
|
|
302
337
|
|
|
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 };
|
|
338
|
+
export { type AuditLog, type AuthenticationContext, type CheckInRequest, type CheckInResponse, type CheckInTransactionMutation, type CheckInTransactionParams, type ClaimRewardMutationContext, type ClaimRewardRequest, type ClaimRewardTransactionMutation, type ClaimRewardTransactionParams, InMemoryServerPersistenceAdapter, type InMemoryServerPersistenceOptions, type RedisMultiExecutor, type RequestValidationError, RequestValidationException, type RequestValidationResult, type ServerOptions, type ServerPersistenceAdapter, type SqlCheckInStore, type SqlClaimRewardStore, type SqlTransactionDatabase, StampRallyServer, type SyncOperationStatus, type TrustedAuthContext, type UserClaimRecord, assertValidCheckInParams, assertValidClaimParams, assertValidSyncParams, executeCheckInTransaction, executeClaimRewardTransaction, executeRedisTransaction, runPersistenceAdapterComplianceTests, validateCheckInRequest, validateClaimRewardRequest, validateSyncRequest };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,16 @@ import * as _stamprally_core from '@stamprally/core';
|
|
|
2
2
|
import { UserRallyState, AdminRallyConfig } from '@stamprally/core';
|
|
3
3
|
export { UserRallyState } from '@stamprally/core';
|
|
4
4
|
|
|
5
|
+
/** Authentication already verified by the host application's middleware. */
|
|
6
|
+
interface TrustedAuthContext {
|
|
7
|
+
readonly authenticatedUserId: string;
|
|
8
|
+
readonly isAnonymous?: boolean;
|
|
9
|
+
readonly sessionId?: string;
|
|
10
|
+
readonly claims?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/** @deprecated Use TrustedAuthContext. */
|
|
13
|
+
type AuthenticationContext = TrustedAuthContext;
|
|
14
|
+
|
|
5
15
|
interface UserClaimRecord {
|
|
6
16
|
readonly rallyId: string;
|
|
7
17
|
readonly userId: string;
|
|
@@ -18,6 +28,10 @@ interface ClaimRewardTransactionParams {
|
|
|
18
28
|
readonly idempotencyKey?: string;
|
|
19
29
|
readonly proofData?: unknown;
|
|
20
30
|
readonly idempotencyTtlMs?: number;
|
|
31
|
+
/** The configured per-reward stock limit, or null for unlimited stock. */
|
|
32
|
+
readonly rewardStockLimit: number | null;
|
|
33
|
+
/** The configured shared stock limit, or null when shared inventory is disabled. */
|
|
34
|
+
readonly sharedStockLimit: number | null;
|
|
21
35
|
/** Used when the first claim is made before a user state has been stored. */
|
|
22
36
|
readonly initialUserState?: UserRallyState;
|
|
23
37
|
readonly stockKey?: string;
|
|
@@ -35,6 +49,16 @@ interface ClaimRewardTransactionMutation {
|
|
|
35
49
|
/** A domain rejection is committed as an audit/idempotency record without mutations. */
|
|
36
50
|
readonly error?: string;
|
|
37
51
|
}
|
|
52
|
+
interface ClaimRewardMutationContext {
|
|
53
|
+
readonly rewardStock: number | null;
|
|
54
|
+
readonly sharedStock: number | null;
|
|
55
|
+
readonly primaryStock: number | null;
|
|
56
|
+
readonly secondaryStock: number | null;
|
|
57
|
+
/** @deprecated Use rewardStock. */
|
|
58
|
+
readonly stock: number | null;
|
|
59
|
+
readonly claimCount: number;
|
|
60
|
+
readonly userState: UserRallyState;
|
|
61
|
+
}
|
|
38
62
|
interface CheckInTransactionParams {
|
|
39
63
|
readonly rallyId: string;
|
|
40
64
|
readonly userId: string;
|
|
@@ -63,15 +87,12 @@ interface ServerPersistenceAdapter {
|
|
|
63
87
|
* Atomically commits stock, user state, claim count, audit log, and idempotency data.
|
|
64
88
|
* Adapters must roll back every write when the callback or any commit operation fails.
|
|
65
89
|
*/
|
|
66
|
-
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
67
|
-
readonly stock: number | null;
|
|
68
|
-
readonly secondaryStock: number | null;
|
|
69
|
-
readonly claimCount: number;
|
|
70
|
-
readonly userState: UserRallyState;
|
|
71
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
90
|
+
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
72
91
|
readonly success: boolean;
|
|
73
92
|
readonly error?: string;
|
|
74
93
|
}>;
|
|
94
|
+
/** Set false when the adapter cannot persist per-reward inventory atomically. */
|
|
95
|
+
readonly supportsRewardStock?: boolean;
|
|
75
96
|
acquireLock(rallyId: string, lockKey: string, ttlMs: number): Promise<boolean>;
|
|
76
97
|
releaseLock(rallyId: string, lockKey: string): Promise<void>;
|
|
77
98
|
getRewardStock(rallyId: string, rewardId: string): Promise<number | null>;
|
|
@@ -95,6 +116,7 @@ interface InMemoryServerPersistenceOptions {
|
|
|
95
116
|
}
|
|
96
117
|
declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapter {
|
|
97
118
|
#private;
|
|
119
|
+
readonly supportsRewardStock: boolean;
|
|
98
120
|
constructor(options?: InMemoryServerPersistenceOptions);
|
|
99
121
|
acquireLock(rallyId: string, key: string, ttlMs: number): Promise<boolean>;
|
|
100
122
|
releaseLock(rallyId: string, key: string): Promise<void>;
|
|
@@ -104,12 +126,7 @@ declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapt
|
|
|
104
126
|
remainingStock: number;
|
|
105
127
|
}>;
|
|
106
128
|
restoreRewardStock(rallyId: string, rewardId: string, count?: number): Promise<void>;
|
|
107
|
-
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: {
|
|
108
|
-
readonly stock: number | null;
|
|
109
|
-
readonly secondaryStock: number | null;
|
|
110
|
-
readonly claimCount: number;
|
|
111
|
-
readonly userState: UserRallyState;
|
|
112
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
129
|
+
executeClaimRewardTransaction(params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
113
130
|
readonly success: boolean;
|
|
114
131
|
readonly error?: string;
|
|
115
132
|
}>;
|
|
@@ -135,7 +152,7 @@ declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapt
|
|
|
135
152
|
/** @deprecated Use recordUserClaim with a ticket number and timestamp. */
|
|
136
153
|
recordClaim(params: UserClaimRecord): Promise<void>;
|
|
137
154
|
recordClaim(rallyId: string, userId: string, rewardId: string): Promise<void>;
|
|
138
|
-
runTransaction<T>(
|
|
155
|
+
runTransaction<T>(rallyId: string, operation: (transaction: ServerPersistenceAdapter) => Promise<T>): Promise<T>;
|
|
139
156
|
}
|
|
140
157
|
|
|
141
158
|
/**
|
|
@@ -168,11 +185,7 @@ interface SqlClaimRewardStore<Tx> {
|
|
|
168
185
|
* while unexpected write failures reject the transaction and roll everything
|
|
169
186
|
* back.
|
|
170
187
|
*/
|
|
171
|
-
declare function executeClaimRewardTransaction<Tx>(database: SqlTransactionDatabase<Tx>, store: SqlClaimRewardStore<Tx>, params: ClaimRewardTransactionParams, mutation: (current: {
|
|
172
|
-
readonly stock: number | null;
|
|
173
|
-
readonly claimCount: number;
|
|
174
|
-
readonly userState: UserRallyState;
|
|
175
|
-
}) => ClaimRewardTransactionMutation): Promise<{
|
|
188
|
+
declare function executeClaimRewardTransaction<Tx>(database: SqlTransactionDatabase<Tx>, store: SqlClaimRewardStore<Tx>, params: ClaimRewardTransactionParams, mutation: (current: ClaimRewardMutationContext) => ClaimRewardTransactionMutation): Promise<{
|
|
176
189
|
readonly success: boolean;
|
|
177
190
|
readonly error?: string;
|
|
178
191
|
}>;
|
|
@@ -211,11 +224,27 @@ type RequestValidationResult<T> = {
|
|
|
211
224
|
readonly success: false;
|
|
212
225
|
readonly errors: ReadonlyArray<RequestValidationError>;
|
|
213
226
|
};
|
|
227
|
+
declare class RequestValidationException extends Error {
|
|
228
|
+
readonly code = "VALIDATION_FAILED";
|
|
229
|
+
readonly errors: ReadonlyArray<RequestValidationError>;
|
|
230
|
+
constructor(errors: ReadonlyArray<RequestValidationError>);
|
|
231
|
+
}
|
|
214
232
|
declare function validateCheckInRequest(value: unknown): RequestValidationResult<CheckInRequest>;
|
|
215
233
|
declare function validateClaimRewardRequest(value: unknown): RequestValidationResult<ClaimRewardRequest>;
|
|
234
|
+
declare function assertValidCheckInParams(value: unknown, config: AdminRallyConfig): asserts value is CheckInRequest & {
|
|
235
|
+
readonly userId: string;
|
|
236
|
+
};
|
|
237
|
+
declare function assertValidClaimParams(value: unknown, config: AdminRallyConfig): asserts value is ClaimRewardRequest & {
|
|
238
|
+
readonly userId: string;
|
|
239
|
+
};
|
|
240
|
+
declare function assertValidSyncParams(value: unknown, config: AdminRallyConfig): asserts value is {
|
|
241
|
+
readonly rallyId: string;
|
|
242
|
+
readonly userId: string;
|
|
243
|
+
};
|
|
216
244
|
declare function validateSyncRequest(value: unknown): RequestValidationResult<{
|
|
217
245
|
readonly rallyId: string;
|
|
218
246
|
readonly userId?: string;
|
|
247
|
+
readonly anonymousSessionId?: string;
|
|
219
248
|
}>;
|
|
220
249
|
|
|
221
250
|
type ErrorResponse = {
|
|
@@ -240,15 +269,22 @@ declare class StampRallyServer {
|
|
|
240
269
|
handleCheckIn(request: Request): Promise<Response>;
|
|
241
270
|
handleClaimReward(request: Request): Promise<Response>;
|
|
242
271
|
handleSync(request: Request): Promise<Response>;
|
|
243
|
-
checkIn(request: CheckInRequest
|
|
244
|
-
|
|
245
|
-
}): Promise<CheckInResponse>;
|
|
246
|
-
claimReward(request: ClaimRewardRequest & {
|
|
247
|
-
readonly userId: string;
|
|
248
|
-
}): Promise<ClaimResponse>;
|
|
272
|
+
checkIn(request: CheckInRequest, authContext?: TrustedAuthContext): Promise<CheckInResponse>;
|
|
273
|
+
claimReward(request: ClaimRewardRequest, authContext?: TrustedAuthContext): Promise<ClaimResponse>;
|
|
249
274
|
sync(rallyId: string, userId: string): Promise<UserRallyState>;
|
|
275
|
+
syncProgress(request: {
|
|
276
|
+
readonly rallyId: string;
|
|
277
|
+
readonly userId?: string;
|
|
278
|
+
readonly anonymousSessionId?: string;
|
|
279
|
+
}): Promise<UserRallyState>;
|
|
250
280
|
}
|
|
251
281
|
|
|
282
|
+
/**
|
|
283
|
+
* Runs the minimum atomicity and idempotency contract against a persistence adapter.
|
|
284
|
+
* The function throws a descriptive error when the adapter violates the contract.
|
|
285
|
+
*/
|
|
286
|
+
declare function runPersistenceAdapterComplianceTests(createAdapter: () => Promise<ServerPersistenceAdapter>): Promise<void>;
|
|
287
|
+
|
|
252
288
|
interface AuditLog {
|
|
253
289
|
readonly id: string;
|
|
254
290
|
readonly timestamp: string;
|
|
@@ -264,6 +300,7 @@ type SyncOperationStatus = "ACCEPTED" | "REJECTED_PERMANENT" | "RETRYABLE_ERROR"
|
|
|
264
300
|
interface CheckInRequest {
|
|
265
301
|
readonly rallyId: string;
|
|
266
302
|
readonly userId?: string;
|
|
303
|
+
readonly anonymousSessionId?: string;
|
|
267
304
|
readonly spotId: string;
|
|
268
305
|
readonly context: _stamprally_core.VerificationContext;
|
|
269
306
|
readonly idempotencyKey: string;
|
|
@@ -272,6 +309,7 @@ interface CheckInRequest {
|
|
|
272
309
|
interface ClaimRewardRequest {
|
|
273
310
|
readonly rallyId: string;
|
|
274
311
|
readonly userId?: string;
|
|
312
|
+
readonly anonymousSessionId?: string;
|
|
275
313
|
readonly rewardId: string;
|
|
276
314
|
readonly idempotencyKey: string;
|
|
277
315
|
readonly staffPasscode?: string;
|
|
@@ -291,13 +329,10 @@ type CheckInResponse = {
|
|
|
291
329
|
interface ServerOptions {
|
|
292
330
|
readonly lockTtlMs?: number;
|
|
293
331
|
readonly idempotencyTtlMs?: number;
|
|
294
|
-
readonly authenticate?: (request: Request) => Promise<string |
|
|
332
|
+
readonly authenticate?: (request: Request) => Promise<string | TrustedAuthContext | null> | string | TrustedAuthContext | null;
|
|
295
333
|
readonly customValidators?: Readonly<Record<string, _stamprally_core.Validator>>;
|
|
296
334
|
readonly now?: () => string;
|
|
297
|
-
readonly anonymousPolicy?: "session_scoped" | "reject";
|
|
298
|
-
}
|
|
299
|
-
interface AuthenticationContext {
|
|
300
|
-
readonly authenticatedUserId: string;
|
|
335
|
+
readonly anonymousPolicy?: "session_scoped" | "reject" | "shared_global_opt_in_insecure";
|
|
301
336
|
}
|
|
302
337
|
|
|
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 };
|
|
338
|
+
export { type AuditLog, type AuthenticationContext, type CheckInRequest, type CheckInResponse, type CheckInTransactionMutation, type CheckInTransactionParams, type ClaimRewardMutationContext, type ClaimRewardRequest, type ClaimRewardTransactionMutation, type ClaimRewardTransactionParams, InMemoryServerPersistenceAdapter, type InMemoryServerPersistenceOptions, type RedisMultiExecutor, type RequestValidationError, RequestValidationException, type RequestValidationResult, type ServerOptions, type ServerPersistenceAdapter, type SqlCheckInStore, type SqlClaimRewardStore, type SqlTransactionDatabase, StampRallyServer, type SyncOperationStatus, type TrustedAuthContext, type UserClaimRecord, assertValidCheckInParams, assertValidClaimParams, assertValidSyncParams, executeCheckInTransaction, executeClaimRewardTransaction, executeRedisTransaction, runPersistenceAdapterComplianceTests, validateCheckInRequest, validateClaimRewardRequest, validateSyncRequest };
|