@stamprally/server 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 +318 -455
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -118
- package/dist/index.d.ts +61 -118
- package/dist/index.js +320 -455
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,89 +1,72 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as _stamprally_core from '@stamprally/core';
|
|
2
|
+
import { UserRallyState, AdminRallyConfig } from '@stamprally/core';
|
|
3
|
+
export { UserRallyState } from '@stamprally/core';
|
|
3
4
|
|
|
4
|
-
/** Persistence contract for implementations backed by Redis, SQL, or another RDB. */
|
|
5
5
|
interface ServerPersistenceAdapter {
|
|
6
6
|
acquireLock(lockKey: string, ttlMs: number): Promise<boolean>;
|
|
7
7
|
releaseLock(lockKey: string): Promise<void>;
|
|
8
8
|
decrementRewardStock(rewardId: string): Promise<{
|
|
9
|
-
success: boolean;
|
|
10
|
-
remainingStock: number;
|
|
9
|
+
readonly success: boolean;
|
|
10
|
+
readonly remainingStock: number;
|
|
11
11
|
}>;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
incrementRewardStock(rewardId: string): Promise<void>;
|
|
13
|
+
getIdempotentResult<T>(key: string): Promise<T | null>;
|
|
14
|
+
saveIdempotentResult<T>(key: string, result: T, ttlMs: number): Promise<void>;
|
|
15
|
+
getUserClaimCount(rallyId: string, userId: string, rewardId: string): Promise<number>;
|
|
14
16
|
getUserState(rallyId: string, userId: string): Promise<UserRallyState | null>;
|
|
15
17
|
saveUserState(rallyId: string, userId: string, state: UserRallyState): Promise<void>;
|
|
16
|
-
recordAuditLog(log:
|
|
18
|
+
recordAuditLog(log: AuditLog): Promise<void>;
|
|
17
19
|
}
|
|
18
20
|
interface InMemoryServerPersistenceOptions {
|
|
19
21
|
readonly stocks?: Readonly<Record<string, number>>;
|
|
20
22
|
}
|
|
21
|
-
/** Deterministic adapter for tests and small single-process deployments. */
|
|
22
23
|
declare class InMemoryServerPersistenceAdapter implements ServerPersistenceAdapter {
|
|
23
24
|
#private;
|
|
24
25
|
constructor(options?: InMemoryServerPersistenceOptions);
|
|
25
|
-
acquireLock(
|
|
26
|
-
releaseLock(
|
|
26
|
+
acquireLock(key: string, ttlMs: number): Promise<boolean>;
|
|
27
|
+
releaseLock(key: string): Promise<void>;
|
|
27
28
|
decrementRewardStock(rewardId: string): Promise<{
|
|
28
29
|
success: boolean;
|
|
29
30
|
remainingStock: number;
|
|
30
31
|
}>;
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
incrementRewardStock(rewardId: string): Promise<void>;
|
|
33
|
+
getIdempotentResult<T>(key: string): Promise<T | null>;
|
|
34
|
+
saveIdempotentResult<T>(key: string, result: T, ttlMs: number): Promise<void>;
|
|
35
|
+
getUserClaimCount(rallyId: string, userId: string, rewardId: string): Promise<number>;
|
|
33
36
|
getUserState(rallyId: string, userId: string): Promise<UserRallyState | null>;
|
|
34
37
|
saveUserState(rallyId: string, userId: string, state: UserRallyState): Promise<void>;
|
|
35
|
-
recordAuditLog(log:
|
|
36
|
-
getAuditLogs(): ReadonlyArray<
|
|
38
|
+
recordAuditLog(log: AuditLog): Promise<void>;
|
|
39
|
+
getAuditLogs(): ReadonlyArray<AuditLog>;
|
|
40
|
+
recordClaim(rallyId: string, userId: string, rewardId: string): void;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
type
|
|
40
|
-
readonly type: "qr";
|
|
41
|
-
readonly token: string;
|
|
42
|
-
} | {
|
|
43
|
-
readonly type: "passcode";
|
|
44
|
-
readonly code: string;
|
|
45
|
-
} | {
|
|
46
|
-
readonly type: "gps";
|
|
47
|
-
readonly latitude: number;
|
|
48
|
-
readonly longitude: number;
|
|
49
|
-
} | {
|
|
50
|
-
readonly type: "custom";
|
|
51
|
-
readonly value: unknown;
|
|
52
|
-
};
|
|
53
|
-
interface UniversalCheckInRequest {
|
|
54
|
-
readonly rallyId: string;
|
|
55
|
-
readonly userId: string;
|
|
56
|
-
readonly spotId: string;
|
|
57
|
-
readonly context: UniversalVerificationContext;
|
|
58
|
-
readonly idempotencyKey: string;
|
|
59
|
-
readonly now?: string;
|
|
60
|
-
}
|
|
61
|
-
type UniversalCheckInResult = {
|
|
62
|
-
readonly ok: true;
|
|
63
|
-
readonly state: UserRallyState;
|
|
64
|
-
} | {
|
|
43
|
+
type ErrorResponse = {
|
|
65
44
|
readonly ok: false;
|
|
66
45
|
readonly code: string;
|
|
67
46
|
readonly message: string;
|
|
68
47
|
};
|
|
69
|
-
|
|
70
|
-
readonly
|
|
71
|
-
readonly
|
|
72
|
-
readonly
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
/** Atomic, adapter-backed check-in service for the universal model. */
|
|
76
|
-
declare class UniversalRallyServer {
|
|
48
|
+
type ClaimResponse = {
|
|
49
|
+
readonly ok: true;
|
|
50
|
+
readonly state: UserRallyState;
|
|
51
|
+
readonly claimTicketNumber?: string;
|
|
52
|
+
} | ErrorResponse;
|
|
53
|
+
declare class StampRallyServer {
|
|
77
54
|
#private;
|
|
78
|
-
constructor(config: AdminRallyConfig
|
|
79
|
-
|
|
55
|
+
constructor(config: AdminRallyConfig, persistence: ServerPersistenceAdapter, options?: ServerOptions);
|
|
56
|
+
handle(request: Request): Promise<Response>;
|
|
57
|
+
handleCheckIn(request: Request): Promise<Response>;
|
|
58
|
+
handleClaimReward(request: Request): Promise<Response>;
|
|
59
|
+
handleSync(request: Request): Promise<Response>;
|
|
60
|
+
checkIn(request: CheckInRequest & {
|
|
61
|
+
readonly userId: string;
|
|
62
|
+
}): Promise<CheckInResponse>;
|
|
63
|
+
claimReward(request: ClaimRewardRequest & {
|
|
64
|
+
readonly userId: string;
|
|
65
|
+
}): Promise<ClaimResponse>;
|
|
80
66
|
sync(rallyId: string, userId: string): Promise<UserRallyState>;
|
|
81
67
|
}
|
|
82
68
|
|
|
83
|
-
interface
|
|
84
|
-
readonly userId?: string;
|
|
85
|
-
}
|
|
86
|
-
interface RallyAuditLog {
|
|
69
|
+
interface AuditLog {
|
|
87
70
|
readonly id: string;
|
|
88
71
|
readonly timestamp: string;
|
|
89
72
|
readonly rallyId: string;
|
|
@@ -92,79 +75,39 @@ interface RallyAuditLog {
|
|
|
92
75
|
readonly resourceId: string;
|
|
93
76
|
readonly status: "SUCCESS" | "REJECTED";
|
|
94
77
|
readonly idempotencyKey: string;
|
|
95
|
-
readonly proofData?: unknown;
|
|
96
78
|
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
97
79
|
}
|
|
98
|
-
interface ServerStorageAdapter {
|
|
99
|
-
getRewardStock(rewardId: string): Promise<number | null>;
|
|
100
|
-
decrementRewardStock(rewardId: string): Promise<boolean>;
|
|
101
|
-
getUserClaims(userId: string, rewardId: string): Promise<number>;
|
|
102
|
-
recordAuditLog(log: RallyAuditLog): Promise<void>;
|
|
103
|
-
saveUserState(userId: string, state: UserRallyState): Promise<void>;
|
|
104
|
-
getUserState(userId: string): Promise<UserRallyState | null>;
|
|
105
|
-
}
|
|
106
|
-
interface AdminRallyConfig extends RallyConfig {
|
|
107
|
-
readonly secretKey: SecureTokenSecretKey;
|
|
108
|
-
readonly proofTtlSeconds?: number;
|
|
109
|
-
readonly authenticate?: (request: Request) => Promise<string | null> | string | null;
|
|
110
|
-
}
|
|
111
80
|
interface CheckInRequest {
|
|
112
|
-
readonly
|
|
81
|
+
readonly rallyId: string;
|
|
82
|
+
readonly userId?: string;
|
|
113
83
|
readonly spotId: string;
|
|
114
|
-
readonly
|
|
115
|
-
readonly proofData?: unknown;
|
|
84
|
+
readonly context: _stamprally_core.VerificationContext;
|
|
116
85
|
readonly idempotencyKey: string;
|
|
86
|
+
readonly now?: string;
|
|
117
87
|
}
|
|
118
88
|
interface ClaimRewardRequest {
|
|
119
|
-
readonly
|
|
89
|
+
readonly rallyId: string;
|
|
90
|
+
readonly userId?: string;
|
|
120
91
|
readonly rewardId: string;
|
|
121
|
-
readonly staffPasscode?: string;
|
|
122
92
|
readonly idempotencyKey: string;
|
|
93
|
+
readonly staffPasscode?: string;
|
|
123
94
|
readonly staffId?: string;
|
|
95
|
+
readonly now?: string;
|
|
124
96
|
}
|
|
125
|
-
|
|
126
|
-
readonly
|
|
127
|
-
readonly
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
readonly
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
readonly
|
|
135
|
-
readonly
|
|
136
|
-
readonly
|
|
137
|
-
readonly
|
|
138
|
-
|
|
139
|
-
interface StampClaimProof {
|
|
140
|
-
readonly token: string;
|
|
141
|
-
readonly rallyId: string;
|
|
142
|
-
readonly userId: string;
|
|
143
|
-
readonly spotId: string;
|
|
144
|
-
readonly acquiredAt: string;
|
|
145
|
-
}
|
|
146
|
-
interface InMemoryServerStorageOptions {
|
|
147
|
-
readonly stocks?: Readonly<Record<string, number>>;
|
|
148
|
-
}
|
|
149
|
-
declare class InMemoryServerStorage implements ServerStorageAdapter {
|
|
150
|
-
#private;
|
|
151
|
-
constructor(options?: InMemoryServerStorageOptions);
|
|
152
|
-
getRewardStock(rewardId: string): Promise<number | null>;
|
|
153
|
-
decrementRewardStock(rewardId: string): Promise<boolean>;
|
|
154
|
-
getUserClaims(userId: string, rewardId: string): Promise<number>;
|
|
155
|
-
recordAuditLog(log: RallyAuditLog): Promise<void>;
|
|
156
|
-
saveUserState(userId: string, state: UserRallyState): Promise<void>;
|
|
157
|
-
getUserState(userId: string): Promise<UserRallyState | null>;
|
|
158
|
-
getAuditLogs(): ReadonlyArray<RallyAuditLog>;
|
|
159
|
-
recordClaim(userId: string, rewardId: string): void;
|
|
160
|
-
}
|
|
161
|
-
declare class StampRallyServer {
|
|
162
|
-
#private;
|
|
163
|
-
constructor(config: AdminRallyConfig, storage: ServerStorageAdapter);
|
|
164
|
-
handle(request: Request): Promise<Response>;
|
|
165
|
-
verifyCheckIn(request: Request): Promise<Response>;
|
|
166
|
-
claimReward(request: Request): Promise<Response>;
|
|
167
|
-
syncProgress(request: Request): Promise<Response>;
|
|
97
|
+
type CheckInResponse = {
|
|
98
|
+
readonly ok: true;
|
|
99
|
+
readonly state: UserRallyState;
|
|
100
|
+
} | {
|
|
101
|
+
readonly ok: false;
|
|
102
|
+
readonly code: string;
|
|
103
|
+
readonly message: string;
|
|
104
|
+
};
|
|
105
|
+
interface ServerOptions {
|
|
106
|
+
readonly lockTtlMs?: number;
|
|
107
|
+
readonly idempotencyTtlMs?: number;
|
|
108
|
+
readonly authenticate?: (request: Request) => Promise<string | null> | string | null;
|
|
109
|
+
readonly customValidators?: Readonly<Record<string, _stamprally_core.Validator>>;
|
|
110
|
+
readonly now?: () => string;
|
|
168
111
|
}
|
|
169
112
|
|
|
170
|
-
export { type
|
|
113
|
+
export { type AuditLog, type CheckInRequest, type CheckInResponse, type ClaimRewardRequest, InMemoryServerPersistenceAdapter, type InMemoryServerPersistenceOptions, type ServerOptions, type ServerPersistenceAdapter, StampRallyServer };
|