@domino-sdk/relay 0.24.0 → 0.25.1
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/authoring.d.ts +52 -10
- package/dist/authoring.js +48 -8
- package/dist/browser.d.ts +431 -27
- package/dist/browser.js +22 -7
- package/dist/chunk-7QICEKC2.js +229 -0
- package/dist/{chunk-ZOL7RYHW.js → chunk-AKB266O5.js} +46 -3
- package/dist/chunk-D6BX627V.js +175 -0
- package/dist/{chunk-UYS522ER.js → chunk-IXLY3A7B.js} +550 -396
- package/dist/chunk-MZFUQQDP.js +355 -0
- package/dist/{chunk-RTBIXGMH.js → chunk-S44XSDW2.js} +779 -46
- package/dist/index.d.ts +1186 -56
- package/dist/index.js +123 -11
- package/dist/portal-proxy.js +10 -5
- package/dist/react/index.d.ts +498 -13
- package/dist/react/index.js +316 -40
- package/dist/schema.d.ts +82 -2
- package/dist/schema.js +1 -1
- package/dist/{submission-input-CK4Dy19H.d.ts → submission-input-Ckpb4sBv.d.ts} +1899 -2
- package/package.json +5 -3
- package/dist/chunk-57TGYC5Y.js +0 -37
- package/dist/chunk-ND3CVNIW.js +0 -61
package/dist/browser.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
browserSubmissionStore,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
cosmosSigner,
|
|
4
|
+
createBrowserRelayClient,
|
|
5
|
+
discoverCosmosWallets,
|
|
6
|
+
discoverEvmWallets,
|
|
7
|
+
discoverSolanaWallets,
|
|
8
|
+
evmSigner,
|
|
9
|
+
solanaSigner,
|
|
10
|
+
walletStandardSolanaSigner
|
|
11
|
+
} from "./chunk-MZFUQQDP.js";
|
|
12
|
+
import "./chunk-S44XSDW2.js";
|
|
13
|
+
import "./chunk-AKB266O5.js";
|
|
14
|
+
import "./chunk-7QICEKC2.js";
|
|
15
|
+
import "./chunk-D6BX627V.js";
|
|
16
|
+
import "./chunk-IXLY3A7B.js";
|
|
9
17
|
export {
|
|
10
18
|
browserSubmissionStore,
|
|
11
|
-
|
|
19
|
+
cosmosSigner,
|
|
20
|
+
createBrowserRelayClient,
|
|
21
|
+
discoverCosmosWallets,
|
|
22
|
+
discoverEvmWallets,
|
|
23
|
+
discoverSolanaWallets,
|
|
24
|
+
evmSigner,
|
|
25
|
+
solanaSigner,
|
|
26
|
+
walletStandardSolanaSigner
|
|
12
27
|
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import {
|
|
2
|
+
identifier
|
|
3
|
+
} from "./chunk-IXLY3A7B.js";
|
|
4
|
+
|
|
5
|
+
// src/auth.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var authScopeSchema = z.object({
|
|
8
|
+
organization: identifier,
|
|
9
|
+
project: identifier,
|
|
10
|
+
environment: z.enum(["test", "live"])
|
|
11
|
+
}).strict();
|
|
12
|
+
var principalSchema = z.discriminatedUnion("kind", [
|
|
13
|
+
z.object({ kind: z.literal("member"), member: identifier }).strict(),
|
|
14
|
+
z.object({ kind: z.literal("staff"), subject: identifier }).strict(),
|
|
15
|
+
z.object({ kind: z.literal("operator"), subject: identifier }).strict()
|
|
16
|
+
]);
|
|
17
|
+
var sessionSchema = authScopeSchema.extend({
|
|
18
|
+
id: identifier,
|
|
19
|
+
principal: principalSchema,
|
|
20
|
+
expiresAt: z.number()
|
|
21
|
+
});
|
|
22
|
+
var memberSummarySchema = z.object({
|
|
23
|
+
member: identifier,
|
|
24
|
+
avatarSeed: z.string().min(1).max(100)
|
|
25
|
+
});
|
|
26
|
+
var exchangeSchema = authScopeSchema.extend({
|
|
27
|
+
identity: z.object({ issuer: identifier, subject: z.string().min(1).max(200) }).strict(),
|
|
28
|
+
role: z.enum(["member", "staff", "operator"])
|
|
29
|
+
}).strict();
|
|
30
|
+
var exchangeResultSchema = z.object({
|
|
31
|
+
token: z.string(),
|
|
32
|
+
session: sessionSchema
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// src/wallet.ts
|
|
36
|
+
import { z as z2 } from "zod";
|
|
37
|
+
var solanaAddressSchema = z2.string().min(32).max(44).regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
38
|
+
var walletConnectionSchema = z2.object({
|
|
39
|
+
chain: z2.literal("solana"),
|
|
40
|
+
address: solanaAddressSchema,
|
|
41
|
+
verifiedAt: z2.number().int().nonnegative(),
|
|
42
|
+
revision: z2.number().int().positive()
|
|
43
|
+
}).strict();
|
|
44
|
+
var walletChallengeInputSchema = z2.object({
|
|
45
|
+
chain: z2.literal("solana"),
|
|
46
|
+
address: solanaAddressSchema
|
|
47
|
+
}).strict();
|
|
48
|
+
var walletChallengeSchema = walletChallengeInputSchema.extend({
|
|
49
|
+
id: z2.string().uuid(),
|
|
50
|
+
message: z2.string(),
|
|
51
|
+
expiresAt: z2.number()
|
|
52
|
+
});
|
|
53
|
+
var walletProofSchema = z2.object({
|
|
54
|
+
challenge: z2.string().uuid(),
|
|
55
|
+
signature: z2.string().min(64).max(88).regex(/^[1-9A-HJ-NP-Za-km-z]+$/)
|
|
56
|
+
}).strict();
|
|
57
|
+
var solanaBalanceSchema = z2.object({
|
|
58
|
+
address: solanaAddressSchema,
|
|
59
|
+
network: z2.literal("mainnet-beta"),
|
|
60
|
+
lamports: z2.string().regex(/^(0|[1-9][0-9]*)$/),
|
|
61
|
+
slot: z2.number().int().nonnegative().safe(),
|
|
62
|
+
observedAt: z2.number().int().nonnegative()
|
|
63
|
+
}).strict();
|
|
64
|
+
var walletChainSchema = z2.enum(["solana", "eip155", "cosmos"]);
|
|
65
|
+
var cosmosNetworks = {
|
|
66
|
+
"cosmos:pio-mainnet-1": {
|
|
67
|
+
chainId: "pio-mainnet-1",
|
|
68
|
+
prefix: "pb",
|
|
69
|
+
name: "Provenance"
|
|
70
|
+
},
|
|
71
|
+
"cosmos:pio-testnet-1": {
|
|
72
|
+
chainId: "pio-testnet-1",
|
|
73
|
+
prefix: "tp",
|
|
74
|
+
name: "Provenance testnet"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var cosmosNetworkSchema = z2.enum([
|
|
78
|
+
"cosmos:pio-mainnet-1",
|
|
79
|
+
"cosmos:pio-testnet-1"
|
|
80
|
+
]);
|
|
81
|
+
var solanaMainnet = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
82
|
+
var evmAddressSchema = z2.string().regex(/^0x[0-9a-fA-F]{40}$/);
|
|
83
|
+
var cosmosAddressSchema = z2.string().min(8).max(90).regex(/^[a-z]{1,20}1[02-9ac-hj-np-z]{38,}$/);
|
|
84
|
+
var walletAddressInputSchema = z2.discriminatedUnion("chain", [
|
|
85
|
+
z2.object({ chain: z2.literal("solana"), address: solanaAddressSchema }).strict(),
|
|
86
|
+
z2.object({
|
|
87
|
+
chain: z2.literal("eip155"),
|
|
88
|
+
address: evmAddressSchema,
|
|
89
|
+
/** Shown in the sign-in message's Chain ID line only: links are chain-agnostic. Defaults to 1. */
|
|
90
|
+
chainId: z2.number().int().positive().safe().optional()
|
|
91
|
+
}).strict(),
|
|
92
|
+
z2.object({
|
|
93
|
+
chain: z2.literal("cosmos"),
|
|
94
|
+
network: cosmosNetworkSchema,
|
|
95
|
+
address: cosmosAddressSchema
|
|
96
|
+
}).strict()
|
|
97
|
+
]);
|
|
98
|
+
var walletMessageChallengeSchema = z2.object({
|
|
99
|
+
id: z2.string().min(1).max(200),
|
|
100
|
+
purpose: z2.enum(["link", "sign-in"]),
|
|
101
|
+
chain: walletChainSchema,
|
|
102
|
+
network: cosmosNetworkSchema.nullable(),
|
|
103
|
+
/** Canonical (base58, EIP-55 or lowercase bech32). The signer must sign with this address. */
|
|
104
|
+
address: z2.string(),
|
|
105
|
+
message: z2.string().max(4096),
|
|
106
|
+
expiresAt: z2.number().int()
|
|
107
|
+
});
|
|
108
|
+
var walletSignatureSchema = z2.object({
|
|
109
|
+
challenge: z2.string().min(1).max(200),
|
|
110
|
+
/** solana: base58, 64 bytes · eip155: 0x and 130 hex digits (65 bytes) · cosmos: base64, 64 bytes (r‖s) */
|
|
111
|
+
signature: z2.string().min(1).max(256),
|
|
112
|
+
/** cosmos only: the base64 33-byte compressed secp256k1 key from signArbitrary's pub_key.value */
|
|
113
|
+
publicKey: z2.string().max(128).optional()
|
|
114
|
+
}).strict();
|
|
115
|
+
var linkedWalletSchema = z2.object({
|
|
116
|
+
chain: walletChainSchema,
|
|
117
|
+
network: cosmosNetworkSchema.nullable(),
|
|
118
|
+
address: z2.string(),
|
|
119
|
+
verifiedAt: z2.number().int().nonnegative(),
|
|
120
|
+
revision: z2.number().int().positive(),
|
|
121
|
+
/** True when this wallet can sign in: it was first used through wallet sign-in. Linking never enables sign-in. */
|
|
122
|
+
signIn: z2.boolean()
|
|
123
|
+
});
|
|
124
|
+
var walletUnlinkInputSchema = z2.object({ chain: walletChainSchema, address: z2.string().min(1).max(100) }).strict();
|
|
125
|
+
async function walletAddressInput(signer) {
|
|
126
|
+
const address = await signer.address();
|
|
127
|
+
switch (signer.chain) {
|
|
128
|
+
case "solana":
|
|
129
|
+
return { chain: "solana", address };
|
|
130
|
+
case "eip155":
|
|
131
|
+
return {
|
|
132
|
+
chain: "eip155",
|
|
133
|
+
address,
|
|
134
|
+
...signer.chainId ? { chainId: await signer.chainId() } : {}
|
|
135
|
+
};
|
|
136
|
+
case "cosmos":
|
|
137
|
+
if (!signer.network) {
|
|
138
|
+
throw new Error("Choose a Cosmos network for this wallet");
|
|
139
|
+
}
|
|
140
|
+
return { chain: "cosmos", network: signer.network, address };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var WALLETS_PER_CHAIN = 5;
|
|
144
|
+
var walletSignInNetworkSchema = z2.enum([
|
|
145
|
+
"solana",
|
|
146
|
+
"eip155",
|
|
147
|
+
"cosmos:pio-mainnet-1",
|
|
148
|
+
"cosmos:pio-testnet-1"
|
|
149
|
+
]);
|
|
150
|
+
function walletSignInNetwork(wallet) {
|
|
151
|
+
if (wallet.chain === "cosmos") {
|
|
152
|
+
if (!wallet.network) {
|
|
153
|
+
throw new Error("A Cosmos wallet belongs to its own network");
|
|
154
|
+
}
|
|
155
|
+
return wallet.network;
|
|
156
|
+
}
|
|
157
|
+
return wallet.chain;
|
|
158
|
+
}
|
|
159
|
+
function caip10(wallet, network) {
|
|
160
|
+
if (wallet.chain === "cosmos") {
|
|
161
|
+
if (!wallet.network || network && network !== wallet.network) {
|
|
162
|
+
throw new Error("A Cosmos wallet belongs to its own network");
|
|
163
|
+
}
|
|
164
|
+
return `${wallet.network}:${wallet.address}`;
|
|
165
|
+
}
|
|
166
|
+
const selected = network ?? (wallet.chain === "solana" ? solanaMainnet : "eip155:1");
|
|
167
|
+
const syntax = wallet.chain === "solana" ? /^solana:[1-9A-HJ-NP-Za-km-z]{32}$/ : /^eip155:[1-9][0-9]{0,15}$/;
|
|
168
|
+
if (!syntax.test(selected)) {
|
|
169
|
+
throw new Error(`Use a ${wallet.chain} network for this wallet`);
|
|
170
|
+
}
|
|
171
|
+
return `${selected}:${wallet.address}`;
|
|
172
|
+
}
|
|
173
|
+
function isWalletParticipantRoute(path) {
|
|
174
|
+
return /^\/v1\/me\/(?:wallet(?:\/challenge|\/verify)?|wallets(?:\/challenge|\/verify|\/unlink)?)$/.test(
|
|
175
|
+
path
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
var units = z2.string().regex(/^(0|[1-9][0-9]*)$/);
|
|
179
|
+
var walletBalanceSchema = z2.object({
|
|
180
|
+
/** Canonical CAIP-2 ID: `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` or `eip155:<chain ID>`. */
|
|
181
|
+
chain: z2.string(),
|
|
182
|
+
/** The canonical mint (base58) or EIP-55 contract address; null for the native coin. */
|
|
183
|
+
token: z2.string().nullable(),
|
|
184
|
+
/** Null only for an ERC-20 contract without `decimals()`. */
|
|
185
|
+
decimals: z2.number().int().min(0).max(255).nullable(),
|
|
186
|
+
/** The sum over `wallets`. */
|
|
187
|
+
total: units,
|
|
188
|
+
wallets: z2.array(z2.object({ address: z2.string(), amount: units }).strict()),
|
|
189
|
+
/** Solana: the lowest slot the reads saw. EVM: the latest block when the read started (approximate). */
|
|
190
|
+
at: z2.object({ kind: z2.enum(["slot", "block"]), number: units }).strict(),
|
|
191
|
+
observedAt: z2.number().int().nonnegative()
|
|
192
|
+
}).strict();
|
|
193
|
+
function isWalletSignInRoute(path) {
|
|
194
|
+
return /^\/v1\/auth\/wallet\/(?:start|verify)$/.test(path);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
authScopeSchema,
|
|
199
|
+
principalSchema,
|
|
200
|
+
sessionSchema,
|
|
201
|
+
memberSummarySchema,
|
|
202
|
+
exchangeSchema,
|
|
203
|
+
exchangeResultSchema,
|
|
204
|
+
solanaAddressSchema,
|
|
205
|
+
walletConnectionSchema,
|
|
206
|
+
walletChallengeInputSchema,
|
|
207
|
+
walletChallengeSchema,
|
|
208
|
+
walletProofSchema,
|
|
209
|
+
solanaBalanceSchema,
|
|
210
|
+
walletChainSchema,
|
|
211
|
+
cosmosNetworks,
|
|
212
|
+
cosmosNetworkSchema,
|
|
213
|
+
solanaMainnet,
|
|
214
|
+
evmAddressSchema,
|
|
215
|
+
cosmosAddressSchema,
|
|
216
|
+
walletAddressInputSchema,
|
|
217
|
+
walletMessageChallengeSchema,
|
|
218
|
+
walletSignatureSchema,
|
|
219
|
+
linkedWalletSchema,
|
|
220
|
+
walletUnlinkInputSchema,
|
|
221
|
+
walletAddressInput,
|
|
222
|
+
WALLETS_PER_CHAIN,
|
|
223
|
+
walletSignInNetworkSchema,
|
|
224
|
+
walletSignInNetwork,
|
|
225
|
+
caip10,
|
|
226
|
+
isWalletParticipantRoute,
|
|
227
|
+
walletBalanceSchema,
|
|
228
|
+
isWalletSignInRoute
|
|
229
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
profileSummarySchema
|
|
3
|
+
} from "./chunk-D6BX627V.js";
|
|
1
4
|
import {
|
|
2
5
|
contentMetricSchema,
|
|
3
6
|
contentMetricsSchema,
|
|
4
7
|
identifier,
|
|
5
8
|
pointsRewardSchema,
|
|
6
9
|
tierRewardSchema
|
|
7
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-IXLY3A7B.js";
|
|
8
11
|
|
|
9
12
|
// src/engagement.ts
|
|
10
13
|
import { z } from "zod";
|
|
@@ -417,11 +420,18 @@ var leaderboardQuerySchema = z4.object({
|
|
|
417
420
|
cursor: z4.string().max(4096).optional()
|
|
418
421
|
}).strict();
|
|
419
422
|
var leaderboardRowSchema = z4.object({
|
|
423
|
+
/** The row's stable key: a pseudonym per board and member. */
|
|
420
424
|
participant: identifier,
|
|
421
425
|
member: identifier.optional(),
|
|
426
|
+
/** The profile's name where the viewer can see it, otherwise the pseudonym's. */
|
|
422
427
|
name: z4.string(),
|
|
423
428
|
score: integer,
|
|
424
|
-
rank: integer.positive()
|
|
429
|
+
rank: integer.positive(),
|
|
430
|
+
/**
|
|
431
|
+
* The member's profile, where the project shows profiles to this viewer and the member has not
|
|
432
|
+
* hidden theirs. Older servers omit it.
|
|
433
|
+
*/
|
|
434
|
+
profile: profileSummarySchema.nullable().default(null)
|
|
425
435
|
});
|
|
426
436
|
var leaderboardPageSchema = z4.object({
|
|
427
437
|
leaderboard: identifier,
|
|
@@ -517,6 +527,37 @@ var leaderboardGroupSchema = z4.object({
|
|
|
517
527
|
reason: z4.string().trim().min(1).max(1e3)
|
|
518
528
|
}).strict();
|
|
519
529
|
|
|
530
|
+
// src/units.ts
|
|
531
|
+
function checkDecimals(decimals) {
|
|
532
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255) {
|
|
533
|
+
throw new Error("Token decimals must be an integer from 0 to 255");
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function parseUnits(value, decimals) {
|
|
537
|
+
checkDecimals(decimals);
|
|
538
|
+
const match = /^(\d+)(?:\.(\d+))?$/.exec(value.trim());
|
|
539
|
+
if (!match) {
|
|
540
|
+
throw new Error(`Use a decimal amount such as "1.5", not "${value}"`);
|
|
541
|
+
}
|
|
542
|
+
const [, whole, fraction = ""] = match;
|
|
543
|
+
const significant = fraction.replace(/0+$/, "");
|
|
544
|
+
if (significant.length > decimals) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
`"${value}" has more than ${decimals} decimal places, which this token cannot hold`
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
return BigInt(whole + significant.padEnd(decimals, "0"));
|
|
550
|
+
}
|
|
551
|
+
function formatUnits(amount3, decimals) {
|
|
552
|
+
checkDecimals(decimals);
|
|
553
|
+
const value = typeof amount3 === "bigint" ? amount3 : BigInt(amount3);
|
|
554
|
+
const sign = value < 0n ? "-" : "";
|
|
555
|
+
const digits = (value < 0n ? -value : value).toString().padStart(decimals + 1, "0");
|
|
556
|
+
const whole = digits.slice(0, digits.length - decimals);
|
|
557
|
+
const fraction = digits.slice(digits.length - decimals).replace(/0+$/, "");
|
|
558
|
+
return sign + whole + (fraction ? "." + fraction : "");
|
|
559
|
+
}
|
|
560
|
+
|
|
520
561
|
export {
|
|
521
562
|
engagementDefinitionSchema,
|
|
522
563
|
engagementScoreInputSchema,
|
|
@@ -566,5 +607,7 @@ export {
|
|
|
566
607
|
pointsResultSchema,
|
|
567
608
|
pointsAccountSchema,
|
|
568
609
|
leaderboardExclusionSchema,
|
|
569
|
-
leaderboardGroupSchema
|
|
610
|
+
leaderboardGroupSchema,
|
|
611
|
+
parseUnits,
|
|
612
|
+
formatUnits
|
|
570
613
|
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
identifier
|
|
3
|
+
} from "./chunk-IXLY3A7B.js";
|
|
4
|
+
|
|
5
|
+
// src/profiles.ts
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
var count = z.number().int().nonnegative().safe();
|
|
8
|
+
var profileVisibilitySchema = z.enum([
|
|
9
|
+
"private",
|
|
10
|
+
"participants",
|
|
11
|
+
"public"
|
|
12
|
+
]);
|
|
13
|
+
var profileDefaultsSchema = z.enum(["generated", "accounts"]);
|
|
14
|
+
var avatarProviderSchema = z.enum(["x", "discord", "google"]);
|
|
15
|
+
var avatarSeedSchema = z.string().min(1).max(100);
|
|
16
|
+
var profileAvatarSchema = z.discriminatedUnion("source", [
|
|
17
|
+
z.object({
|
|
18
|
+
source: z.literal("upload"),
|
|
19
|
+
url: z.string().url(),
|
|
20
|
+
seed: avatarSeedSchema
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
source: z.literal("account"),
|
|
24
|
+
provider: avatarProviderSchema,
|
|
25
|
+
url: z.string().url(),
|
|
26
|
+
seed: avatarSeedSchema
|
|
27
|
+
}),
|
|
28
|
+
z.object({ source: z.literal("generated"), seed: avatarSeedSchema })
|
|
29
|
+
]);
|
|
30
|
+
var profileSummarySchema = z.object({
|
|
31
|
+
id: identifier,
|
|
32
|
+
name: z.string(),
|
|
33
|
+
avatar: profileAvatarSchema
|
|
34
|
+
});
|
|
35
|
+
var invisible = /[\p{Cc}----]/u;
|
|
36
|
+
var displayNameSchema = z.string().max(200).transform((value) => value.normalize("NFC").replace(/\s+/g, " ").trim()).pipe(
|
|
37
|
+
z.string().min(1, "Enter a name").max(40, "Use at most 40 characters").refine((value) => !invisible.test(value), "Use visible characters only")
|
|
38
|
+
);
|
|
39
|
+
var profileUpdateSchema = z.object({
|
|
40
|
+
displayName: displayNameSchema.nullable().optional(),
|
|
41
|
+
avatar: z.discriminatedUnion("source", [
|
|
42
|
+
z.object({
|
|
43
|
+
source: z.literal("account"),
|
|
44
|
+
provider: avatarProviderSchema
|
|
45
|
+
}).strict(),
|
|
46
|
+
z.object({ source: z.literal("generated") }).strict()
|
|
47
|
+
]).nullable().optional(),
|
|
48
|
+
hidden: z.boolean().optional()
|
|
49
|
+
}).strict().refine(
|
|
50
|
+
(value) => Object.values(value).some((field) => field !== void 0),
|
|
51
|
+
"Change at least one field"
|
|
52
|
+
);
|
|
53
|
+
var ownProfileSchema = profileSummarySchema.extend({
|
|
54
|
+
/** The name the member chose, or null for the default. */
|
|
55
|
+
displayName: z.string().nullable(),
|
|
56
|
+
/** The avatar the member chose: `default` follows the project's defaults. */
|
|
57
|
+
avatarChoice: z.enum(["default", "upload", "account", "generated"]),
|
|
58
|
+
/** The account of an `account` choice. */
|
|
59
|
+
avatarProvider: avatarProviderSchema.nullable(),
|
|
60
|
+
hidden: z.boolean(),
|
|
61
|
+
/** An operator locked the name and avatar; the member can still hide the profile. */
|
|
62
|
+
locked: z.boolean(),
|
|
63
|
+
/** Who can see profiles in this project, so the app can explain it. */
|
|
64
|
+
visibility: profileVisibilitySchema,
|
|
65
|
+
/** The member's connected accounts a picture or name can come from. */
|
|
66
|
+
options: z.array(
|
|
67
|
+
z.object({
|
|
68
|
+
provider: avatarProviderSchema,
|
|
69
|
+
name: z.string().nullable(),
|
|
70
|
+
imageUrl: z.string().url().nullable()
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
});
|
|
74
|
+
var publicProfileSchema = profileSummarySchema.extend({
|
|
75
|
+
/** The profile is the viewer's own. */
|
|
76
|
+
self: z.boolean(),
|
|
77
|
+
leaderboards: z.array(
|
|
78
|
+
z.object({
|
|
79
|
+
leaderboard: identifier,
|
|
80
|
+
key: identifier.optional(),
|
|
81
|
+
title: z.string(),
|
|
82
|
+
rank: count.positive(),
|
|
83
|
+
score: z.number().int().safe(),
|
|
84
|
+
/** Ranked participants on the board. */
|
|
85
|
+
total: count
|
|
86
|
+
})
|
|
87
|
+
).nullable(),
|
|
88
|
+
quests: z.array(
|
|
89
|
+
z.object({
|
|
90
|
+
quest: identifier,
|
|
91
|
+
key: identifier.optional(),
|
|
92
|
+
title: z.string(),
|
|
93
|
+
completions: count.positive(),
|
|
94
|
+
/** Null for completions recorded before completion times were. */
|
|
95
|
+
lastCompletedAt: count.nullable()
|
|
96
|
+
})
|
|
97
|
+
).max(200).nullable(),
|
|
98
|
+
referrals: z.object({
|
|
99
|
+
/** Members this member invited. */
|
|
100
|
+
attributed: count,
|
|
101
|
+
programs: z.array(
|
|
102
|
+
z.object({
|
|
103
|
+
program: identifier,
|
|
104
|
+
key: identifier.optional(),
|
|
105
|
+
title: z.string(),
|
|
106
|
+
qualified: count,
|
|
107
|
+
milestones: z.array(
|
|
108
|
+
z.object({ id: identifier, count, reached: z.boolean() })
|
|
109
|
+
)
|
|
110
|
+
})
|
|
111
|
+
)
|
|
112
|
+
}).nullable()
|
|
113
|
+
});
|
|
114
|
+
var profileSettingsSchema = z.object({
|
|
115
|
+
visibility: profileVisibilitySchema,
|
|
116
|
+
defaults: profileDefaultsSchema,
|
|
117
|
+
/** The sections a profile page shows. */
|
|
118
|
+
sections: z.object({
|
|
119
|
+
leaderboards: z.boolean(),
|
|
120
|
+
quests: z.boolean(),
|
|
121
|
+
referrals: z.boolean()
|
|
122
|
+
}),
|
|
123
|
+
revision: count,
|
|
124
|
+
actor: z.string().nullable(),
|
|
125
|
+
updatedAt: count.nullable()
|
|
126
|
+
});
|
|
127
|
+
var profileSettingsInputSchema = profileSettingsSchema.omit({ revision: true, actor: true, updatedAt: true }).extend({
|
|
128
|
+
actionId: identifier,
|
|
129
|
+
/** The revision the change was made against; a newer one is a 409. */
|
|
130
|
+
expectedRevision: count,
|
|
131
|
+
reason: z.string().trim().min(1).max(500)
|
|
132
|
+
}).strict();
|
|
133
|
+
var profileModerationSchema = z.object({
|
|
134
|
+
actionId: identifier,
|
|
135
|
+
resetName: z.boolean().default(false),
|
|
136
|
+
removeAvatar: z.boolean().default(false),
|
|
137
|
+
/** True locks the name and avatar, false unlocks them. */
|
|
138
|
+
lock: z.boolean().optional(),
|
|
139
|
+
reason: z.string().trim().min(1).max(1e3)
|
|
140
|
+
}).strict().refine(
|
|
141
|
+
(value) => value.resetName || value.removeAvatar || value.lock !== void 0,
|
|
142
|
+
"Choose an action"
|
|
143
|
+
);
|
|
144
|
+
var managedProfileSchema = ownProfileSchema.omit({ options: true }).extend({
|
|
145
|
+
member: identifier,
|
|
146
|
+
lockedAt: count.nullable(),
|
|
147
|
+
lockedBy: z.string().nullable(),
|
|
148
|
+
lockedReason: z.string().nullable(),
|
|
149
|
+
updatedAt: count
|
|
150
|
+
});
|
|
151
|
+
var AVATAR_UPLOAD_LIMIT = 5 * 1024 * 1024;
|
|
152
|
+
var avatarUploadTypes = ["image/jpeg", "image/png", "image/webp"];
|
|
153
|
+
function isProfileParticipantRoute(path, method) {
|
|
154
|
+
return method === "GET" && (path === "/v1/me/profile" || /^\/v1\/profiles\/[\w-]+$/.test(path)) || method === "POST" && (path === "/v1/me/profile" || path === "/v1/me/profile/avatar");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export {
|
|
158
|
+
profileVisibilitySchema,
|
|
159
|
+
profileDefaultsSchema,
|
|
160
|
+
avatarProviderSchema,
|
|
161
|
+
avatarSeedSchema,
|
|
162
|
+
profileAvatarSchema,
|
|
163
|
+
profileSummarySchema,
|
|
164
|
+
displayNameSchema,
|
|
165
|
+
profileUpdateSchema,
|
|
166
|
+
ownProfileSchema,
|
|
167
|
+
publicProfileSchema,
|
|
168
|
+
profileSettingsSchema,
|
|
169
|
+
profileSettingsInputSchema,
|
|
170
|
+
profileModerationSchema,
|
|
171
|
+
managedProfileSchema,
|
|
172
|
+
AVATAR_UPLOAD_LIMIT,
|
|
173
|
+
avatarUploadTypes,
|
|
174
|
+
isProfileParticipantRoute
|
|
175
|
+
};
|