@domino-sdk/relay 0.12.0 → 0.14.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/build.d.mts +4 -1
- package/build.mjs +15 -8
- package/dist/authoring.d.ts +4 -3
- package/dist/authoring.js +22 -9
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +6 -5
- package/dist/{chunk-CE5XVIJQ.js → chunk-CJARNIVP.js} +265 -76
- package/dist/{chunk-3UOTI4IU.js → chunk-FUQYKTOJ.js} +30 -7
- package/dist/{chunk-VDWQL6HV.js → chunk-I2CCMGN6.js} +1 -1
- package/dist/{chunk-NLMEK77N.js → chunk-YZJOZL4V.js} +146 -60
- package/dist/index.d.ts +86 -2
- package/dist/index.js +46 -6
- package/dist/portal-proxy.js +26 -13
- package/dist/schema.d.ts +12 -12
- package/dist/schema.js +1 -1
- package/dist/{settings-B61jIDDA.d.ts → settings-CU2y-wUM.d.ts} +382 -1
- package/package.json +1 -1
package/build.d.mts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
/** Bundle a default-exported quest module without executing it on the build host. */
|
|
2
|
-
export declare function buildQuest(
|
|
2
|
+
export declare function buildQuest(
|
|
3
|
+
entry: string,
|
|
4
|
+
options?: { exportName?: string }
|
|
5
|
+
): Promise<{ code: string }>
|
package/build.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { resolve, dirname } from "node:path"
|
|
2
|
-
import { build } from "esbuild"
|
|
1
|
+
import { resolve, dirname } from "node:path"
|
|
2
|
+
import { build } from "esbuild"
|
|
3
|
+
|
|
3
4
|
/** Bundle an authored quest without evaluating developer code in the build process. */
|
|
4
5
|
export async function buildQuest(entry, options = {}) {
|
|
5
6
|
if (
|
|
6
7
|
options.exportName &&
|
|
7
8
|
!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(options.exportName)
|
|
8
|
-
)
|
|
9
|
-
throw new Error("Invalid quest export name")
|
|
9
|
+
) {
|
|
10
|
+
throw new Error("Invalid quest export name")
|
|
11
|
+
}
|
|
12
|
+
|
|
10
13
|
const result = await build({
|
|
11
14
|
...(options.exportName
|
|
12
15
|
? {
|
|
@@ -25,8 +28,12 @@ export async function buildQuest(entry, options = {}) {
|
|
|
25
28
|
platform: "neutral",
|
|
26
29
|
target: "es2022",
|
|
27
30
|
minify: true,
|
|
28
|
-
})
|
|
29
|
-
const file = result.outputFiles[0]
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
})
|
|
32
|
+
const file = result.outputFiles[0]
|
|
33
|
+
|
|
34
|
+
if (!file) {
|
|
35
|
+
throw new Error("Quest build produced no module")
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { code: file.text }
|
|
32
39
|
}
|
package/dist/authoring.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as Observation, D as DiscordMember, a as DiscordMessage, W as WalletConnection, S as SolanaBalance, o as observationTriggerSchema, B as Budget, A as AuthoringIdentity, I as IntegrationProvider, b as StreakPolicy } from './settings-
|
|
2
|
-
export { d as defineLeaderboard,
|
|
1
|
+
import { O as Observation, T as TrackerReader, D as DiscordMember, a as DiscordMessage, W as WalletConnection, S as SolanaBalance, o as observationTriggerSchema, B as Budget, A as AuthoringIdentity, I as IntegrationProvider, b as StreakPolicy } from './settings-CU2y-wUM.js';
|
|
2
|
+
export { c as customSource, d as defineLeaderboard, e as defineReferral, f as defineTracker, g as discord, p as pointLedgers, s as settings, h as streak, x } from './settings-CU2y-wUM.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { PhotoResult, rewardSchema, triggerSchema, QuestPresentation, QuizEvidence, Decision, TieredRewardDefinition } from './schema.js';
|
|
5
5
|
|
|
@@ -137,6 +137,7 @@ type EvaluationContext<T, I = {
|
|
|
137
137
|
input: I;
|
|
138
138
|
observation: Observation | null;
|
|
139
139
|
eligibleAt: number;
|
|
140
|
+
trackers: TrackerReader;
|
|
140
141
|
review: {
|
|
141
142
|
photo(options: {
|
|
142
143
|
image: string;
|
|
@@ -336,7 +337,7 @@ declare function defineQuest<T extends Record<string, z.ZodType>, const G extend
|
|
|
336
337
|
trigger: {
|
|
337
338
|
kind: "manual";
|
|
338
339
|
input: "photo" | "quiz" | "none";
|
|
339
|
-
actor?: "
|
|
340
|
+
actor?: "staff" | "member" | undefined;
|
|
340
341
|
} | {
|
|
341
342
|
kind: "automatic";
|
|
342
343
|
observation?: {
|
package/dist/authoring.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
authoringKey,
|
|
3
|
+
customSource,
|
|
3
4
|
defineLeaderboard,
|
|
4
|
-
defineReferral
|
|
5
|
-
|
|
5
|
+
defineReferral,
|
|
6
|
+
defineTracker,
|
|
7
|
+
x
|
|
8
|
+
} from "./chunk-CJARNIVP.js";
|
|
6
9
|
import {
|
|
7
10
|
budgetSchema,
|
|
8
11
|
decisionSchema,
|
|
@@ -19,7 +22,7 @@ import {
|
|
|
19
22
|
streak,
|
|
20
23
|
tierRewardSchema,
|
|
21
24
|
tieredRewardDefinitionSchema
|
|
22
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-FUQYKTOJ.js";
|
|
23
26
|
|
|
24
27
|
// src/authoring.ts
|
|
25
28
|
import { z } from "zod";
|
|
@@ -99,18 +102,21 @@ var evaluators = {
|
|
|
99
102
|
image: ctx.input.photo,
|
|
100
103
|
criteria: config.criteria
|
|
101
104
|
});
|
|
102
|
-
if (result.kind === "unclear")
|
|
105
|
+
if (result.kind === "unclear") {
|
|
103
106
|
return config.unclear === "human-review" ? decision.review({ reason: result.reason }) : decision.reject({ reason: result.reason });
|
|
107
|
+
}
|
|
104
108
|
return result.kind === "pass" ? decision.accept() : decision.reject({ reason: result.reason });
|
|
105
109
|
};
|
|
106
110
|
}
|
|
107
111
|
};
|
|
108
112
|
function defineQuest(definition) {
|
|
109
113
|
const key = authoringKey(definition);
|
|
110
|
-
if (definition.completion.kind === "streak" && (definition.trigger.kind !== "automatic" || !definition.trigger.observation))
|
|
114
|
+
if (definition.completion.kind === "streak" && (definition.trigger.kind !== "automatic" || !definition.trigger.observation)) {
|
|
111
115
|
throw new Error("Streaks require an automatic observation trigger");
|
|
112
|
-
|
|
116
|
+
}
|
|
117
|
+
if (definition.trigger.kind === "manual" && definition.trigger.input !== "none" && !definition.evaluate) {
|
|
113
118
|
throw new Error("Evidence quests require an evaluator");
|
|
119
|
+
}
|
|
114
120
|
const fields = Object.fromEntries(
|
|
115
121
|
Object.entries(definition.settings.shape).map(([key2, schema]) => [
|
|
116
122
|
key2,
|
|
@@ -164,12 +170,16 @@ function defineQuest(definition) {
|
|
|
164
170
|
observation: ctx.observation ?? null,
|
|
165
171
|
eligibleAt: ctx.eligibleAt,
|
|
166
172
|
review: ctx.review,
|
|
173
|
+
trackers: ctx.trackers,
|
|
167
174
|
wallet: ctx.wallet,
|
|
168
175
|
discord: ctx.discord
|
|
169
176
|
}) : decision.accept();
|
|
170
|
-
if (!result)
|
|
171
|
-
|
|
177
|
+
if (!result) {
|
|
178
|
+
throw new Error("Evaluator returned no decision");
|
|
179
|
+
}
|
|
180
|
+
if (result.kind === "review" && !ctx.humanReview) {
|
|
172
181
|
return decisionSchema.parse({ kind: "reject", reason: result.reason });
|
|
182
|
+
}
|
|
173
183
|
return decisionSchema.parse(
|
|
174
184
|
result.kind === "accept" || result.kind === "review" ? {
|
|
175
185
|
...result,
|
|
@@ -185,12 +195,14 @@ export {
|
|
|
185
195
|
automatic,
|
|
186
196
|
budget,
|
|
187
197
|
completed,
|
|
198
|
+
customSource,
|
|
188
199
|
decision,
|
|
189
200
|
defineLeaderboard,
|
|
190
201
|
defineQuest,
|
|
191
202
|
defineQuestType,
|
|
192
203
|
defineReferral,
|
|
193
204
|
defineTieredReward,
|
|
205
|
+
defineTracker,
|
|
194
206
|
discord,
|
|
195
207
|
discordRole,
|
|
196
208
|
evaluators,
|
|
@@ -203,5 +215,6 @@ export {
|
|
|
203
215
|
settings,
|
|
204
216
|
staffHandover,
|
|
205
217
|
streak,
|
|
206
|
-
untracked
|
|
218
|
+
untracked,
|
|
219
|
+
x
|
|
207
220
|
};
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SubmitInput, ReviewListOptions, MemberListOptions, ReleaseInput, beginHandoverSchema } from './schema.js';
|
|
2
2
|
import { SubmissionStore, createRelayClient, QuestView, QuestController, ProgressObservation, questExperienceSchema, ProgressObserver, ExchangeInput, PhotoSubmission, QuizSubmission, ClaimSubmission } from './index.js';
|
|
3
|
-
import { r as referralAcceptSchema, L as LeaderboardQuery, w as walletChallengeInputSchema,
|
|
3
|
+
import { r as referralAcceptSchema, L as LeaderboardQuery, w as walletChallengeInputSchema, i as walletProofSchema, j as AuthProvider } from './settings-CU2y-wUM.js';
|
|
4
4
|
import * as zod from 'zod';
|
|
5
5
|
|
|
6
6
|
/** Browser client with durable submission recovery; safe to construct during SSR. */
|
package/dist/browser.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createRelayClient
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-YZJOZL4V.js";
|
|
4
|
+
import "./chunk-CJARNIVP.js";
|
|
5
|
+
import "./chunk-I2CCMGN6.js";
|
|
6
|
+
import "./chunk-FUQYKTOJ.js";
|
|
7
7
|
|
|
8
8
|
// src/browser.ts
|
|
9
9
|
function createBrowserRelayClient(options) {
|
|
@@ -15,10 +15,11 @@ function createBrowserRelayClient(options) {
|
|
|
15
15
|
function browserSubmissionStore() {
|
|
16
16
|
let database;
|
|
17
17
|
function open() {
|
|
18
|
-
if (!globalThis.indexedDB || !globalThis.navigator?.locks)
|
|
18
|
+
if (!globalThis.indexedDB || !globalThis.navigator?.locks) {
|
|
19
19
|
throw new Error(
|
|
20
20
|
"This browser cannot safely save submissions. Use a browser with IndexedDB and Web Locks enabled."
|
|
21
21
|
);
|
|
22
|
+
}
|
|
22
23
|
return database ??= new Promise((resolve, reject) => {
|
|
23
24
|
const request = indexedDB.open("domino-relay-submissions", 1);
|
|
24
25
|
request.onupgradeneeded = () => request.result.createObjectStore("submissions");
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
identifier,
|
|
3
3
|
pointsRewardSchema,
|
|
4
4
|
tierRewardSchema
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FUQYKTOJ.js";
|
|
6
6
|
|
|
7
7
|
// src/authoring-identity.ts
|
|
8
8
|
import { z } from "zod";
|
|
@@ -11,18 +11,20 @@ var authoringIdentityShape = {
|
|
|
11
11
|
id: identifier.optional()
|
|
12
12
|
};
|
|
13
13
|
function validateAuthoringIdentity(value, ctx) {
|
|
14
|
-
if (!value.key && !value.id)
|
|
14
|
+
if (!value.key && !value.id) {
|
|
15
15
|
ctx.addIssue({
|
|
16
16
|
code: "custom",
|
|
17
17
|
path: ["key"],
|
|
18
18
|
message: "Provide an authoring key. Legacy id is also accepted."
|
|
19
19
|
});
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
if (value.key && value.id && value.key !== value.id) {
|
|
21
22
|
ctx.addIssue({
|
|
22
23
|
code: "custom",
|
|
23
24
|
path: ["key"],
|
|
24
25
|
message: "id and key must match. Keep the existing authoring name to preserve identity."
|
|
25
26
|
});
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
29
|
function normalizeAuthoringIdentity(value) {
|
|
28
30
|
const { id, key, ...properties } = value;
|
|
@@ -70,14 +72,18 @@ var referralDefinitionSchema = z2.object({
|
|
|
70
72
|
}).strict()
|
|
71
73
|
).max(20).default([])
|
|
72
74
|
}).strict().superRefine((value, ctx) => {
|
|
73
|
-
for (const entries of [value.milestones, value.bonuses])
|
|
74
|
-
if (new Set(entries.map((e) => e.id)).size !== entries.length)
|
|
75
|
+
for (const entries of [value.milestones, value.bonuses]) {
|
|
76
|
+
if (new Set(entries.map((e) => e.id)).size !== entries.length) {
|
|
75
77
|
ctx.addIssue({ code: "custom", message: "Rule IDs must be unique" });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
76
80
|
});
|
|
77
81
|
var referralAuthoringSchema = z2.object(referralDefinitionSchema.shape).omit({ id: true }).extend(authoringIdentityShape).strict().superRefine(validateAuthoringIdentity).superRefine((value, ctx) => {
|
|
78
|
-
for (const entries of [value.milestones, value.bonuses])
|
|
79
|
-
if (new Set(entries.map((entry) => entry.id)).size !== entries.length)
|
|
82
|
+
for (const entries of [value.milestones, value.bonuses]) {
|
|
83
|
+
if (new Set(entries.map((entry) => entry.id)).size !== entries.length) {
|
|
80
84
|
ctx.addIssue({ code: "custom", message: "Rule keys must be unique" });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
81
87
|
}).transform(normalizeAuthoringIdentity);
|
|
82
88
|
function defineReferral(input) {
|
|
83
89
|
const definition = referralAuthoringSchema.parse(input);
|
|
@@ -187,18 +193,181 @@ var referralManagementSchema = z2.object({
|
|
|
187
193
|
next: amount.nullable()
|
|
188
194
|
});
|
|
189
195
|
|
|
190
|
-
// src/
|
|
196
|
+
// src/trackers.ts
|
|
191
197
|
import { z as z3 } from "zod";
|
|
192
|
-
var
|
|
193
|
-
var
|
|
194
|
-
var
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
+
var timestamp = z3.number().int().safe().nonnegative().max(864e13);
|
|
199
|
+
var count = z3.number().int().safe().nonnegative();
|
|
200
|
+
var externalId = z3.string().min(1).max(256);
|
|
201
|
+
var metric = count.nullable().default(null);
|
|
202
|
+
var xTweetSchema = z3.looseObject({
|
|
203
|
+
id: externalId,
|
|
204
|
+
userId: externalId,
|
|
205
|
+
content: z3.string(),
|
|
206
|
+
createdAt: z3.iso.datetime({ offset: true }),
|
|
207
|
+
author: z3.looseObject({
|
|
208
|
+
id: externalId,
|
|
209
|
+
username: z3.string(),
|
|
210
|
+
name: z3.string(),
|
|
211
|
+
verified: z3.boolean().nullable().default(null)
|
|
212
|
+
}),
|
|
213
|
+
likeCount: metric,
|
|
214
|
+
replyCount: metric,
|
|
215
|
+
retweetCount: metric,
|
|
216
|
+
quoteCount: metric,
|
|
217
|
+
viewCount: metric,
|
|
218
|
+
bookmarkCount: metric,
|
|
219
|
+
isReply: z3.boolean(),
|
|
220
|
+
isRetweet: z3.boolean(),
|
|
221
|
+
isQuoteTweet: z3.boolean()
|
|
222
|
+
});
|
|
223
|
+
var trackerSourceSchema = z3.discriminatedUnion("kind", [
|
|
198
224
|
z3.object({
|
|
199
|
-
kind: z3.literal("
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
kind: z3.literal("x-search"),
|
|
226
|
+
query: z3.string().trim().min(1).max(2e3)
|
|
227
|
+
}).strict(),
|
|
228
|
+
z3.object({ kind: z3.literal("custom"), namespace: identifier }).strict()
|
|
229
|
+
]);
|
|
230
|
+
var x = {
|
|
231
|
+
search: (input) => trackerSourceSchema.options[0].parse({ kind: "x-search", ...input })
|
|
232
|
+
};
|
|
233
|
+
var customSource = (namespace) => trackerSourceSchema.options[1].parse({ kind: "custom", namespace });
|
|
234
|
+
var windowSchema = z3.object({ start: timestamp, end: timestamp.optional() }).strict().refine(
|
|
235
|
+
(w) => w.end === void 0 || w.end > w.start,
|
|
236
|
+
"End must follow start"
|
|
237
|
+
);
|
|
238
|
+
var trackerDefinitionSchema = z3.object({
|
|
239
|
+
key: identifier,
|
|
240
|
+
title: z3.string().trim().min(1).max(120),
|
|
241
|
+
source: trackerSourceSchema,
|
|
242
|
+
window: windowSchema,
|
|
243
|
+
refreshSeconds: z3.number().int().min(300).max(86400).default(21600),
|
|
244
|
+
maxPages: z3.number().int().min(1).max(1e3).default(60)
|
|
245
|
+
}).strict();
|
|
246
|
+
var trackerArtifactSchema = z3.union([
|
|
247
|
+
trackerDefinitionSchema,
|
|
248
|
+
z3.object({ code: z3.string().min(1).max(2e6) }).strict()
|
|
249
|
+
]);
|
|
250
|
+
function defineTracker(input) {
|
|
251
|
+
return trackerDefinitionSchema.parse(input);
|
|
252
|
+
}
|
|
253
|
+
var publishedTrackerSchema = z3.object({
|
|
254
|
+
id: identifier,
|
|
255
|
+
version: identifier,
|
|
256
|
+
definition: trackerDefinitionSchema,
|
|
257
|
+
publishedAt: timestamp,
|
|
258
|
+
actor: z3.string().nullable()
|
|
259
|
+
});
|
|
260
|
+
var trackerStatusSchema = z3.object({
|
|
261
|
+
published: publishedTrackerSchema,
|
|
262
|
+
paused: z3.boolean(),
|
|
263
|
+
state: z3.enum(["idle", "syncing", "error", "complete"]),
|
|
264
|
+
lastStartedAt: timestamp.nullable(),
|
|
265
|
+
lastCompletedAt: timestamp.nullable(),
|
|
266
|
+
nextSyncAt: timestamp.nullable(),
|
|
267
|
+
coverage: z3.enum(["unknown", "partial", "complete"]),
|
|
268
|
+
error: z3.string().nullable(),
|
|
269
|
+
records: count
|
|
270
|
+
});
|
|
271
|
+
var trackerControlSchema = z3.object({
|
|
272
|
+
actionId: identifier,
|
|
273
|
+
action: z3.enum(["pause", "resume", "refresh"])
|
|
274
|
+
}).strict();
|
|
275
|
+
var trackerRecordInputSchema = z3.object({
|
|
276
|
+
id: externalId,
|
|
277
|
+
occurredAt: timestamp,
|
|
278
|
+
observedAt: timestamp,
|
|
279
|
+
author: z3.object({
|
|
280
|
+
id: externalId,
|
|
281
|
+
verified: z3.boolean().nullable().default(null)
|
|
282
|
+
}).strict().nullable().default(null),
|
|
283
|
+
data: z3.record(z3.string(), z3.json()),
|
|
284
|
+
removed: z3.boolean().default(false)
|
|
285
|
+
}).strict().refine(
|
|
286
|
+
(v) => new TextEncoder().encode(JSON.stringify(v.data)).byteLength <= 131072,
|
|
287
|
+
"Record exceeds 128 KB"
|
|
288
|
+
);
|
|
289
|
+
var trackerRecordSchema = trackerRecordInputSchema.safeExtend({
|
|
290
|
+
source: z3.string(),
|
|
291
|
+
firstSeenAt: timestamp
|
|
292
|
+
});
|
|
293
|
+
var trackerIngestSchema = z3.object({
|
|
294
|
+
actionId: identifier,
|
|
295
|
+
records: z3.array(trackerRecordInputSchema).min(1).max(100)
|
|
296
|
+
}).strict();
|
|
297
|
+
var trackerIngestResultSchema = z3.object({ stored: count });
|
|
298
|
+
var booleanQuery = z3.union([
|
|
299
|
+
z3.boolean(),
|
|
300
|
+
z3.enum(["true", "false"]).transform((v) => v === "true")
|
|
301
|
+
]);
|
|
302
|
+
var trackerQuerySchema = z3.object({
|
|
303
|
+
author: externalId.optional(),
|
|
304
|
+
member: identifier.optional(),
|
|
305
|
+
verified: booleanQuery.optional(),
|
|
306
|
+
since: z3.coerce.number().int().safe().nonnegative().optional(),
|
|
307
|
+
until: z3.coerce.number().int().safe().nonnegative().optional(),
|
|
308
|
+
removed: booleanQuery.default(false),
|
|
309
|
+
minLikes: z3.coerce.number().int().safe().nonnegative().optional(),
|
|
310
|
+
minViews: z3.coerce.number().int().safe().nonnegative().optional(),
|
|
311
|
+
limit: z3.coerce.number().int().min(1).max(100).default(25),
|
|
312
|
+
cursor: z3.string().max(2048).optional()
|
|
313
|
+
}).strict().refine(
|
|
314
|
+
(q) => q.since === void 0 || q.until === void 0 || q.until > q.since,
|
|
315
|
+
"Until must follow since"
|
|
316
|
+
);
|
|
317
|
+
var trackerPageSchema = z3.object({
|
|
318
|
+
tracker: identifier,
|
|
319
|
+
items: z3.array(trackerRecordSchema),
|
|
320
|
+
nextCursor: z3.string().nullable(),
|
|
321
|
+
total: count,
|
|
322
|
+
status: trackerStatusSchema
|
|
323
|
+
});
|
|
324
|
+
var trackerSummarySchema = z3.object({
|
|
325
|
+
records: count,
|
|
326
|
+
authors: count,
|
|
327
|
+
metrics: z3.object({
|
|
328
|
+
likes: count,
|
|
329
|
+
replies: count,
|
|
330
|
+
reposts: count,
|
|
331
|
+
quotes: count,
|
|
332
|
+
views: count,
|
|
333
|
+
bookmarks: count
|
|
334
|
+
}),
|
|
335
|
+
missingMetrics: count,
|
|
336
|
+
status: trackerStatusSchema
|
|
337
|
+
});
|
|
338
|
+
var trackerPreviewLimits = {
|
|
339
|
+
pages: 3,
|
|
340
|
+
posts: 100,
|
|
341
|
+
days: 30
|
|
342
|
+
};
|
|
343
|
+
var trackerPreviewInputSchema = z3.object({
|
|
344
|
+
query: trackerSourceSchema.options[0].shape.query,
|
|
345
|
+
/** Start of the searched window. The window ends when the sample is fetched. */
|
|
346
|
+
since: timestamp
|
|
347
|
+
}).strict();
|
|
348
|
+
var trackerPreviewSchema = z3.object({
|
|
349
|
+
query: z3.string(),
|
|
350
|
+
since: timestamp,
|
|
351
|
+
fetchedAt: timestamp,
|
|
352
|
+
pages: count,
|
|
353
|
+
/** Every match in the sample, newest first, verified or not. */
|
|
354
|
+
posts: z3.array(xTweetSchema).max(trackerPreviewLimits.posts),
|
|
355
|
+
/** X had more matches than the sample holds. */
|
|
356
|
+
more: z3.boolean()
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// src/leaderboards.ts
|
|
360
|
+
import { z as z4 } from "zod";
|
|
361
|
+
var integer = z4.number().int().safe();
|
|
362
|
+
var timestamp2 = integer.nonnegative().max(864e13);
|
|
363
|
+
var leaderboardWindowSchema = z4.discriminatedUnion("kind", [
|
|
364
|
+
z4.object({ kind: z4.literal("all-time") }).strict(),
|
|
365
|
+
z4.object({ kind: z4.literal("fixed"), start: timestamp2, end: timestamp2 }).strict().refine((w) => w.end > w.start, "Window end must follow its start"),
|
|
366
|
+
z4.object({ kind: z4.literal("rolling"), days: integer.min(1).max(3660) }).strict(),
|
|
367
|
+
z4.object({
|
|
368
|
+
kind: z4.literal("calendar"),
|
|
369
|
+
period: z4.enum(["day", "week", "month"]),
|
|
370
|
+
timeZone: z4.string().min(1).max(100).refine((zone) => {
|
|
202
371
|
try {
|
|
203
372
|
new Intl.DateTimeFormat("en", { timeZone: zone });
|
|
204
373
|
return true;
|
|
@@ -210,22 +379,22 @@ var leaderboardWindowSchema = z3.discriminatedUnion("kind", [
|
|
|
210
379
|
]);
|
|
211
380
|
var periodScore = {
|
|
212
381
|
window: leaderboardWindowSchema.default({ kind: "all-time" }),
|
|
213
|
-
quests:
|
|
382
|
+
quests: z4.array(identifier).min(1).max(100).optional()
|
|
214
383
|
};
|
|
215
|
-
var leaderboardDefinitionSchema =
|
|
384
|
+
var leaderboardDefinitionSchema = z4.object({
|
|
216
385
|
id: identifier,
|
|
217
386
|
key: identifier.optional(),
|
|
218
|
-
title:
|
|
387
|
+
title: z4.string().trim().min(1).max(120),
|
|
219
388
|
balance: identifier,
|
|
220
|
-
score:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
kind:
|
|
389
|
+
score: z4.discriminatedUnion("kind", [
|
|
390
|
+
z4.object({ kind: z4.literal("balance") }).strict(),
|
|
391
|
+
z4.object({ kind: z4.literal("earned"), ...periodScore }).strict(),
|
|
392
|
+
z4.object({
|
|
393
|
+
kind: z4.literal("net"),
|
|
225
394
|
window: leaderboardWindowSchema.default({ kind: "all-time" })
|
|
226
395
|
}).strict()
|
|
227
396
|
]).default({ kind: "balance" }),
|
|
228
|
-
access:
|
|
397
|
+
access: z4.enum(["participants", "public"]).default("participants"),
|
|
229
398
|
group: identifier.optional()
|
|
230
399
|
}).strict();
|
|
231
400
|
var leaderboardAuthoringSchema = leaderboardDefinitionSchema.omit({ id: true }).extend(authoringIdentityShape).strict().superRefine(validateAuthoringIdentity).transform(normalizeAuthoringIdentity);
|
|
@@ -237,42 +406,42 @@ function defineLeaderboard(input) {
|
|
|
237
406
|
id: definition.key
|
|
238
407
|
};
|
|
239
408
|
}
|
|
240
|
-
var leaderboardArtifactSchema =
|
|
409
|
+
var leaderboardArtifactSchema = z4.union([
|
|
241
410
|
leaderboardAuthoringSchema,
|
|
242
|
-
|
|
411
|
+
z4.object({ code: z4.string().min(1).max(2e6) }).strict()
|
|
243
412
|
]);
|
|
244
|
-
var publishedLeaderboardSchema =
|
|
413
|
+
var publishedLeaderboardSchema = z4.object({
|
|
245
414
|
version: identifier,
|
|
246
415
|
definition: leaderboardDefinitionSchema,
|
|
247
|
-
publishedAt:
|
|
248
|
-
actor:
|
|
416
|
+
publishedAt: timestamp2,
|
|
417
|
+
actor: z4.string().nullable()
|
|
249
418
|
});
|
|
250
|
-
var leaderboardQuerySchema =
|
|
251
|
-
limit:
|
|
252
|
-
cursor:
|
|
419
|
+
var leaderboardQuerySchema = z4.object({
|
|
420
|
+
limit: z4.coerce.number().int().min(1).max(100).default(25),
|
|
421
|
+
cursor: z4.string().max(4096).optional()
|
|
253
422
|
}).strict();
|
|
254
|
-
var leaderboardRowSchema =
|
|
423
|
+
var leaderboardRowSchema = z4.object({
|
|
255
424
|
participant: identifier,
|
|
256
425
|
member: identifier.optional(),
|
|
257
|
-
name:
|
|
426
|
+
name: z4.string(),
|
|
258
427
|
score: integer,
|
|
259
428
|
rank: integer.positive()
|
|
260
429
|
});
|
|
261
|
-
var leaderboardPageSchema =
|
|
430
|
+
var leaderboardPageSchema = z4.object({
|
|
262
431
|
leaderboard: identifier,
|
|
263
|
-
title:
|
|
432
|
+
title: z4.string(),
|
|
264
433
|
version: identifier,
|
|
265
|
-
calculation:
|
|
266
|
-
period:
|
|
267
|
-
calculatedAt:
|
|
268
|
-
lastEntryAt:
|
|
434
|
+
calculation: z4.enum(["balance", "earned", "net"]),
|
|
435
|
+
period: z4.object({ start: timestamp2.nullable(), end: timestamp2.nullable() }),
|
|
436
|
+
calculatedAt: timestamp2,
|
|
437
|
+
lastEntryAt: timestamp2.nullable(),
|
|
269
438
|
total: integer.nonnegative(),
|
|
270
|
-
items:
|
|
439
|
+
items: z4.array(leaderboardRowSchema),
|
|
271
440
|
me: leaderboardRowSchema.nullable(),
|
|
272
|
-
nearby:
|
|
273
|
-
nextCursor:
|
|
441
|
+
nearby: z4.array(leaderboardRowSchema),
|
|
442
|
+
nextCursor: z4.string().nullable()
|
|
274
443
|
});
|
|
275
|
-
var leaderboardPreviewSchema =
|
|
444
|
+
var leaderboardPreviewSchema = z4.object({
|
|
276
445
|
published: publishedLeaderboardSchema,
|
|
277
446
|
before: leaderboardPageSchema.nullable(),
|
|
278
447
|
after: leaderboardPageSchema
|
|
@@ -281,75 +450,75 @@ var mutationBase = {
|
|
|
281
450
|
actionId: identifier,
|
|
282
451
|
member: identifier,
|
|
283
452
|
balance: identifier,
|
|
284
|
-
reason:
|
|
453
|
+
reason: z4.string().trim().min(1).max(1e3)
|
|
285
454
|
};
|
|
286
|
-
var datedMutation = { ...mutationBase, effectiveAt:
|
|
287
|
-
var pointsMutationSchema =
|
|
288
|
-
|
|
455
|
+
var datedMutation = { ...mutationBase, effectiveAt: timestamp2.optional() };
|
|
456
|
+
var pointsMutationSchema = z4.discriminatedUnion("kind", [
|
|
457
|
+
z4.object({
|
|
289
458
|
...datedMutation,
|
|
290
|
-
kind:
|
|
291
|
-
referralEligible:
|
|
459
|
+
kind: z4.literal("award"),
|
|
460
|
+
referralEligible: z4.boolean().optional(),
|
|
292
461
|
amount: integer.positive()
|
|
293
462
|
}).strict(),
|
|
294
|
-
|
|
463
|
+
z4.object({
|
|
295
464
|
...datedMutation,
|
|
296
|
-
kind:
|
|
465
|
+
kind: z4.literal("spend"),
|
|
297
466
|
amount: integer.positive()
|
|
298
467
|
}).strict(),
|
|
299
|
-
|
|
468
|
+
z4.object({
|
|
300
469
|
...datedMutation,
|
|
301
|
-
kind:
|
|
470
|
+
kind: z4.literal("adjust"),
|
|
302
471
|
amount: integer.refine((n) => n !== 0)
|
|
303
472
|
}).strict(),
|
|
304
|
-
|
|
473
|
+
z4.object({
|
|
305
474
|
...datedMutation,
|
|
306
|
-
kind:
|
|
475
|
+
kind: z4.literal("set"),
|
|
307
476
|
total: integer.nonnegative(),
|
|
308
477
|
expectedTotal: integer.nonnegative(),
|
|
309
|
-
classification:
|
|
478
|
+
classification: z4.enum(["earned", "spend"])
|
|
310
479
|
}).strict(),
|
|
311
|
-
|
|
480
|
+
z4.object({
|
|
312
481
|
...mutationBase,
|
|
313
|
-
kind:
|
|
482
|
+
kind: z4.literal("reverse"),
|
|
314
483
|
entry: identifier,
|
|
315
484
|
amount: integer.positive()
|
|
316
485
|
}).strict()
|
|
317
486
|
]);
|
|
318
|
-
var pointsEntrySchema =
|
|
487
|
+
var pointsEntrySchema = z4.object({
|
|
319
488
|
id: identifier,
|
|
320
|
-
completion:
|
|
489
|
+
completion: z4.string().nullable(),
|
|
321
490
|
member: identifier,
|
|
322
491
|
balance: identifier,
|
|
323
492
|
amount: integer,
|
|
324
|
-
kind:
|
|
325
|
-
effectiveAt:
|
|
326
|
-
receivedAt:
|
|
493
|
+
kind: z4.enum(["award", "spend", "adjust", "reverse"]),
|
|
494
|
+
effectiveAt: timestamp2,
|
|
495
|
+
receivedAt: timestamp2,
|
|
327
496
|
quest: identifier.nullable(),
|
|
328
497
|
original: identifier.nullable(),
|
|
329
|
-
reason:
|
|
330
|
-
actor:
|
|
498
|
+
reason: z4.string(),
|
|
499
|
+
actor: z4.string().nullable()
|
|
331
500
|
});
|
|
332
|
-
var pointsResultSchema =
|
|
501
|
+
var pointsResultSchema = z4.object({
|
|
333
502
|
entry: pointsEntrySchema,
|
|
334
503
|
total: integer.nonnegative()
|
|
335
504
|
});
|
|
336
|
-
var pointsAccountSchema =
|
|
505
|
+
var pointsAccountSchema = z4.object({
|
|
337
506
|
member: identifier,
|
|
338
507
|
balance: identifier,
|
|
339
508
|
total: integer.nonnegative(),
|
|
340
509
|
held: integer.nonnegative()
|
|
341
510
|
});
|
|
342
|
-
var leaderboardExclusionSchema =
|
|
511
|
+
var leaderboardExclusionSchema = z4.object({
|
|
343
512
|
actionId: identifier,
|
|
344
513
|
member: identifier,
|
|
345
|
-
excluded:
|
|
346
|
-
reason:
|
|
514
|
+
excluded: z4.boolean(),
|
|
515
|
+
reason: z4.string().trim().min(1).max(1e3)
|
|
347
516
|
}).strict();
|
|
348
|
-
var leaderboardGroupSchema =
|
|
517
|
+
var leaderboardGroupSchema = z4.object({
|
|
349
518
|
actionId: identifier,
|
|
350
519
|
member: identifier,
|
|
351
|
-
included:
|
|
352
|
-
reason:
|
|
520
|
+
included: z4.boolean(),
|
|
521
|
+
reason: z4.string().trim().min(1).max(1e3)
|
|
353
522
|
}).strict();
|
|
354
523
|
|
|
355
524
|
export {
|
|
@@ -369,6 +538,26 @@ export {
|
|
|
369
538
|
referralSummarySchema,
|
|
370
539
|
referralHistorySchema,
|
|
371
540
|
referralManagementSchema,
|
|
541
|
+
xTweetSchema,
|
|
542
|
+
trackerSourceSchema,
|
|
543
|
+
x,
|
|
544
|
+
customSource,
|
|
545
|
+
trackerDefinitionSchema,
|
|
546
|
+
trackerArtifactSchema,
|
|
547
|
+
defineTracker,
|
|
548
|
+
publishedTrackerSchema,
|
|
549
|
+
trackerStatusSchema,
|
|
550
|
+
trackerControlSchema,
|
|
551
|
+
trackerRecordInputSchema,
|
|
552
|
+
trackerRecordSchema,
|
|
553
|
+
trackerIngestSchema,
|
|
554
|
+
trackerIngestResultSchema,
|
|
555
|
+
trackerQuerySchema,
|
|
556
|
+
trackerPageSchema,
|
|
557
|
+
trackerSummarySchema,
|
|
558
|
+
trackerPreviewLimits,
|
|
559
|
+
trackerPreviewInputSchema,
|
|
560
|
+
trackerPreviewSchema,
|
|
372
561
|
leaderboardWindowSchema,
|
|
373
562
|
leaderboardDefinitionSchema,
|
|
374
563
|
leaderboardAuthoringSchema,
|