@pixels-online/pixels-client-js-sdk 1.21.0 → 2.1.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.
@@ -1,485 +0,0 @@
1
- import { Stringable } from '.';
2
- import { IBlockchainSyncStatus } from './blockchain/user_wallet';
3
- import { IUser, Restriction } from './user';
4
- export declare const DEFAULT_ENTITY_KIND = "_default";
5
- export type IClientPlayer = {
6
- /** @deprecated use gameData instead */
7
- snapshot: IClientPlayerSnapshot;
8
- /** @deprecated use stackedData instead */
9
- data?: IClientPlayerData | null;
10
- gameData: IClientPlayerSnapshot;
11
- stackedData: IClientStackedData;
12
- };
13
- export interface IPlayerSnapshot {
14
- _id: string;
15
- gameId: string;
16
- playerId: string;
17
- /** when this was last linked to a unified user */
18
- unifiedUserLinkedAt?: number;
19
- /** when this was last unlinked to a unified user */
20
- unifiedUserUnlinkedAt?: number;
21
- /** player that referred this player to this game */
22
- referredById?: string;
23
- username?: string;
24
- snapshotLastUpdated: number;
25
- offersLastChecked?: number;
26
- daysInGame: number;
27
- loginStreak: number;
28
- daysInGameLastUpdated: number;
29
- /** timestamp when player first signed up */
30
- dateSignedUp?: number;
31
- /** dynamic key value pairs that external apps can set to anything */
32
- dynamic?: Record<string, string | number | boolean>;
33
- /** staked tokens data for this player */
34
- stakedTokens?: Record<
35
- /** the key is the token name. Eg. PIXEL or RON */
36
- string, {
37
- balance?: number;
38
- totalClaimed?: number;
39
- totalStaked?: number;
40
- lastStake?: number;
41
- lastUnstake?: number;
42
- }>;
43
- currencies?: Record<string, {
44
- balance?: number;
45
- in?: number;
46
- out?: number;
47
- lastUpdated?: number;
48
- }>;
49
- levels?: Record<string, {
50
- level?: number;
51
- lastUpdated?: number;
52
- }>;
53
- quests?: Record<string, {
54
- completions?: number;
55
- lastUpdated?: number;
56
- }>;
57
- trustScore?: number;
58
- trustLastUpdated?: number;
59
- achievements?: Record<string, {
60
- count?: number;
61
- lastUpdated: number;
62
- }>;
63
- memberships?: Record<string, {
64
- count?: number;
65
- expiresAt?: number;
66
- lastUpdated?: number;
67
- }>;
68
- /** auth identifiers. like social tiktok or email or sms or whatever */
69
- identifiers?: Array<{
70
- /** id */
71
- identifier: string;
72
- /** sms/email/tiktok etc */
73
- platform: string;
74
- lastUpdated: number;
75
- }>;
76
- cryptoWallets?: Array<{
77
- address: string;
78
- lastUpdated?: number;
79
- }>;
80
- tags?: Array<string>;
81
- tagsLastUpdated?: number;
82
- entityKind?: string;
83
- /**
84
- * Links to other entities (players, pets, guilds, etc.)
85
- */
86
- entityLinks?: Array<{
87
- /** if undefined, it means same game */
88
- gameId?: string;
89
- playerId: string;
90
- kind?: string;
91
- }>;
92
- /**
93
- * collection of information about IP address player connected from
94
- */
95
- ip?: IPlayerIpInfo;
96
- }
97
- export type IClientStackedData = IClientUser & IConditionEvaluationData & {
98
- apps: {
99
- [gameId: string]: IClientPlayerData;
100
- };
101
- };
102
- export type IClientUser = Pick<IUser, 'appConnections' | 'providers'>;
103
- export type IClientPlayerSnapshot = Omit<IPlayerSnapshot, 'tags' | 'tagsLastUpdated' | 'ip' | 'identifiers' | 'cryptoWallets'>;
104
- export type IClientPlayerData = Omit<IPlayerData, '_id' | 'restriction' | 'blockchainSync'>;
105
- export interface IConditionEvaluationData {
106
- cryptoWallets?: Array<{
107
- address: string;
108
- balances: Record<string, number>;
109
- }>;
110
- }
111
- export interface IPlayerDataCurrency {
112
- /**
113
- * balance held
114
- */
115
- balance: number;
116
- /**
117
- * total amount deposited
118
- */
119
- in?: number;
120
- /**
121
- * total amount withdrawn
122
- */
123
- out?: number;
124
- /**
125
- * last updated timestamp
126
- * if not present, means never updated
127
- */
128
- lastUpdated?: number;
129
- }
130
- export interface IPlayerData {
131
- _id?: Stringable;
132
- gameId: string;
133
- playerId: string;
134
- currencies?: Record<string, IPlayerDataCurrency>;
135
- blockchainSync?: Record<string, IBlockchainSyncStatus>;
136
- restriction?: Restriction;
137
- }
138
- export interface IPlayerIpInfo {
139
- lastUpdated: Date;
140
- ipAddress: string;
141
- vpn?: boolean;
142
- proxy?: boolean;
143
- tor?: boolean;
144
- relay?: boolean;
145
- timeZone: string;
146
- regionCode?: string;
147
- countryCode?: string;
148
- continentCode?: string;
149
- }
150
- export interface IBaseCondition {
151
- /** how many days worth of consecutive logins are required to surface? Or complete this? If checking completion conditions, we need to subtract
152
- * this number from IPlayerOffer.completionTrackers.currentLoginStreak to see how many consecutive logins the player has had since surfacing this offer.
153
- */
154
- loginStreak?: number;
155
- levels?: Record<string, {
156
- /** public facing display name */
157
- name: string;
158
- /** min level required */
159
- min?: number;
160
- /** max level for offer */
161
- max?: number;
162
- }>;
163
- stakedTokens?: Record<string, {
164
- /** public facing display name */
165
- name: string;
166
- /** min amount of tokens that need to be staked? */
167
- min?: number;
168
- }>;
169
- /** if the condition revolves around having a specific amount of currency or currencies. Key is the currencyId
170
- * and the value is the min or max amount of that currency the player must have to be eligible for this offer
171
- */
172
- currencies?: Record<string, {
173
- /** public facing display name */
174
- name: string;
175
- /** if the player has this currency, how much do they need to have? */
176
- min?: number;
177
- /** if the player has this currency, how much do they need to have? */
178
- max?: number;
179
- /** required deposits required for this currency */
180
- in?: number;
181
- /** required withdrawals required for this currency */
182
- out?: number;
183
- }>;
184
- /** for high-rep kind, how much rep does a player need to qualify? */
185
- minTrustScore?: number;
186
- maxTrustScore?: number;
187
- /** number of days that the player has logged in-game. Not the absolute amount of time playing the game. But number of days they have logged in for.
188
- * Can obtain this on a DAILY join_room player metric if it is set up.
189
- */
190
- minDaysInGame?: number;
191
- /** achievements that this player has */
192
- achievements?: Record<string, {
193
- name: string;
194
- minCount?: number;
195
- }>;
196
- memberships?: Record<string, {
197
- /** public facing display name */
198
- name: string;
199
- /** if the player has this currency, how much do they need to have? */
200
- minCount?: number;
201
- /** if the player has this currency, how much do they need to have? */
202
- maxCount?: number;
203
- /** how long does a player have to have this membership? */
204
- minMs?: number;
205
- /** max duration a player can have this membership for */
206
- maxMs?: number;
207
- }>;
208
- /** player must have completed these quests for this offer to surface */
209
- quests?: Record<string, {
210
- /** public facing display name */
211
- name: string;
212
- /** if a min number of quest completions is required */
213
- completions?: number;
214
- }>;
215
- /**
216
- * For player snapshot entities that are linked to other player snap entities,
217
- * what are the min and max number of links of a specific link kind?
218
- * Keys are link kinds (e.g., "pet", "guild", "npc", etc.)
219
- */
220
- links?: Record<string, {
221
- /** minimum number of links of this type required */
222
- min?: number;
223
- /** maximum number of links of this type allowed */
224
- max?: number;
225
- /** Template using {current}, {min}, {max}, {type} - e.g., "Own {min} pets ({current}/{min})" */
226
- template?: string;
227
- }>;
228
- /** dynamic field conditions */
229
- dynamic?: IDynamicGroup;
230
- /** Auth platform identifiers condition */
231
- identifiers?: {
232
- /** List of auth platforms to check (e.g., 'tiktok', 'google', 'email') */
233
- platforms: string[];
234
- /** 'AND' = player must have ALL platforms, 'OR' = player must have ANY platform */
235
- behaviour: 'AND' | 'OR';
236
- };
237
- /**
238
- * On-chain token balance conditions - check wallet balances across specified contracts/networks.
239
- * Balances are summed across all specified contracts and all player wallets.
240
- */
241
- tokenBalances?: Array<{
242
- /** Display name for this condition (e.g., "PIXEL Token") */
243
- name: string;
244
- /** List of contract+network pairs to check. Balances summed across all pairs. */
245
- contracts: Array<{
246
- /** Token contract address (lowercase) */
247
- contractAddress: string;
248
- /** Network identifier (e.g., 'ronin-mainnet', 'ethereum-mainnet') */
249
- network: string;
250
- }>;
251
- /** Minimum total balance required */
252
- min?: number;
253
- /** Maximum total balance allowed */
254
- max?: number;
255
- }>;
256
- }
257
- export interface ISurfacingCondition extends IBaseCondition {
258
- /** number of days that the player has logged in-game. Not the absolute amount of time playing the game. But number of days they have logged in for.
259
- * Can obtain this on a DAILY join_room player metric if it is set up.
260
- */
261
- maxDaysInGame?: number;
262
- /** player must have all tags specified to be eligible */
263
- andTags?: Array<string>;
264
- /** player can have any of these tags to be eligible */
265
- orTags?: Array<string>;
266
- /** player cannot have any of these tags */
267
- notTags?: Array<string>;
268
- /** minimum signup date (timestamp) - player must have signed up after this date */
269
- minDateSignedUp?: number;
270
- /** maximum signup date (timestamp) - player must have signed up before this date */
271
- maxDateSignedUp?: number;
272
- /** player must have completed ALL of these offers (AND logic) - array of offer IDs */
273
- completedOffers?: Array<string>;
274
- /** surfacing contexts */
275
- contexts?: Array<string>;
276
- /** if true, offer can only be surfaced programmatically (e.g., via spawnLinkedOffer) - never through normal auto-surfacing */
277
- programmatic?: boolean;
278
- /** entity types that this offer can surface to - undefined or empty means only regular players. */
279
- targetEntityTypes?: string[];
280
- /** List of allowed country codes (whitelist mode) */
281
- allowedCountries?: Array<string>;
282
- /** List of restricted country codes (blacklist mode) - mutually exclusive with allowedCountries */
283
- restrictedCountries?: Array<string>;
284
- /** List of blocked network types - VPN/TOR/PROXY/RELAY */
285
- networkRestrictions?: Array<'vpn' | 'tor' | 'proxy' | 'relay'>;
286
- /** Check if any linked entity (by kind) has a specific offer in surfaced/viewed status. */
287
- linkedEntityOffers?: {
288
- /** The entityLink kind to filter (e.g., "parent", "guild", "pet") */
289
- kind?: string;
290
- /** The offer_id to check for on linked entities */
291
- offer_id?: string;
292
- conditions?: ISurfacingCondition;
293
- };
294
- }
295
- /** conditions that must be met for an already surfaced offer to be claimable */
296
- export interface ICompletionCondition extends IBaseCondition {
297
- /** itemId that must be bought to complete */
298
- buyItem?: {
299
- id: string;
300
- name: string;
301
- /** amount of item bought or currency spent/deposited to fufil condition */
302
- amount?: number;
303
- };
304
- /** currencyId that must be spent to complete */
305
- spendCurrency?: {
306
- id: string;
307
- name: string;
308
- /** amount of item bought or currency spent/deposited to fufil condition */
309
- amount?: number;
310
- };
311
- /** currencyId that must be deposited to complete */
312
- depositCurrency?: {
313
- id: string;
314
- name: string;
315
- /** amount of item bought or currency spent/deposited to fufil condition */
316
- amount?: number;
317
- };
318
- /** social media content condition - player must attach content meeting requirements */
319
- social?: {
320
- /** 'attach' (default) = user attaches single content, 'accumulate' = auto-sum all matching content */
321
- mode?: 'attach' | 'accumulate';
322
- /** platforms accepted (OR logic) - e.g., ['tiktok', 'instagram', 'youtube'] */
323
- platforms: string[];
324
- /** words that must ALL appear in video title or description (case-insensitive). Hashtags must match exactly including # */
325
- requiredWords: string[];
326
- /** minimum view count required on the video (0 = no requirement) */
327
- minViews: number;
328
- /** minimum like count required on the video (0 = no requirement) */
329
- minLikes: number;
330
- /** minimum comment count required on the video (0 = no requirement) */
331
- minComments: number;
332
- /** content must be posted after this timestamp in milliseconds (defaults to time of offer creation) */
333
- postedAfterMs: number;
334
- };
335
- login?: boolean;
336
- /** for contexts that require completion conditions. We have a name field so that we can display a user-friendly name
337
- * for the completion condition when it is rendered to the player. */
338
- context?: {
339
- id: string;
340
- name: string;
341
- };
342
- /**
343
- * Linked completions - wait for N linked entities to complete their offers
344
- */
345
- linkedCompletions?: {
346
- /** Number of linked entity completions required */
347
- min: number;
348
- /** Template using {current}, {required} - e.g., "Complete {current}/{required} referrals" */
349
- template?: string;
350
- };
351
- /**
352
- * Dynamic field tracker - tracks changes to dynamic fields AFTER offer surfacing.
353
- * Unlike the base `dynamic` condition which checks snapshot totals,
354
- * this tracks per-offer values since surfacing.
355
- */
356
- dynamicTracker?: IDynamicGroup;
357
- /**
358
- * Contract interaction tracker - tracks blockchain events for currencies, NFTs, and custom events.
359
- * Keyed by condition ID for multiple trackers.
360
- */
361
- contractInteractions?: Record<string, {
362
- /** Template using {current}, {amount} - e.g., "Spend {amount} PIXEL ({current}/{amount})" */
363
- template: string;
364
- /**
365
- * Event type to track:
366
- * - 'spend': Currency transferred OUT (onchain_currency_tx kind=spend)
367
- * - 'earn': Currency transferred IN (onchain_currency_tx kind=earn)
368
- * - 'lose': NFT transferred OUT (onchain_item_tx kind=lose)
369
- * - 'gain': NFT transferred IN (onchain_item_tx kind=gain)
370
- * - 'onchain_X': Custom event (e.g., 'onchain_staked')
371
- */
372
- event: 'spend' | 'earn' | 'lose' | 'gain' | `onchain_${string}`;
373
- /** List of contract+network pairs to track. Events from any of these count. */
374
- contracts: Array<{
375
- /** Contract address (lowercase) */
376
- contractAddress: string;
377
- /** Network identifier (e.g., 'ronin-mainnet', 'ethereum-mainnet') */
378
- network: string;
379
- }>;
380
- /** Optional: Only count transfers TO these addresses (for spend/lose). Empty = all destinations. */
381
- destinations?: string[];
382
- /** Optional: Only count transfers FROM these addresses (for earn/gain). Empty = all sources. */
383
- sources?: string[];
384
- /**
385
- * Target amount/count:
386
- * - For currencies (spend/earn): token amount
387
- * - For NFTs (gain/lose): NFT count
388
- * - For custom events: event occurrence count
389
- */
390
- amount: number;
391
- }>;
392
- }
393
- /**
394
- * TypeScript interface for dynamicGroupSchema
395
- */
396
- export type DynamicConditionOperator = '==' | '!=' | '>' | '>=' | '<' | '<=' | 'has' | 'not_has';
397
- export interface IDynamicCondition {
398
- key: string;
399
- compareTo: string | number | boolean;
400
- operator: DynamicConditionOperator;
401
- /** If you only want to update this tracker key every X hrs (like once per day), set here */
402
- intervalHr?: number;
403
- }
404
- /**
405
- * links[i] is the link between conditions[i] and conditions[i+1]. Can be 'AND', 'OR', or 'AND NOT'.
406
- */
407
- export type DynamicConditionLink = 'AND' | 'OR' | 'AND NOT';
408
- export interface IDynamicGroup {
409
- conditions: Array<IDynamicCondition>;
410
- links?: Array<DynamicConditionLink>;
411
- /** Display template using {keyName} syntax for referenced dynamic keys */
412
- template?: string;
413
- }
414
- /** Social tracker for attach mode - user manually attaches a single piece of content */
415
- export interface ISocialTrackerAttach {
416
- /** platform name - tiktok, instagram, or youtube */
417
- platform: string;
418
- /** video ID on the platform */
419
- videoId: string;
420
- /** platform specific user ID */
421
- userId: string;
422
- /** cached video title for display */
423
- title?: string;
424
- /** cached view count */
425
- views: number;
426
- /** cached like count */
427
- likes?: number;
428
- /** cached comment count */
429
- comments?: number;
430
- /** timestamp of last validation check (for 5-minute cache) */
431
- lastChecked: Date;
432
- }
433
- /** Social tracker for accumulate mode - auto-sum all matching content */
434
- export interface ISocialTrackerAccumulate {
435
- /** sum of view counts across all matching content */
436
- views: number;
437
- /** sum of like counts across all matching content */
438
- likes?: number;
439
- /** sum of comment counts across all matching content */
440
- comments?: number;
441
- /** timestamp of last validation check (for 5-minute cache) */
442
- lastChecked: Date;
443
- /** number of matching content items */
444
- matchCount: number;
445
- }
446
- export interface ICompletionDynamicTracker {
447
- value: string | number | boolean;
448
- lastUpdated?: number;
449
- }
450
- /** tracking the player's status for completing the conditions to claim the offer, if
451
- * required.
452
- */
453
- export interface ICompletionTrackers {
454
- /** how many counts of the required item has been bought. itemId and amount required defined in completionConditions */
455
- buyItem?: number;
456
- /** how many counts of the required currency has been spent. currencyId and amount required defined in completionConditions */
457
- spendCurrency?: number;
458
- /** how many counts of the required currency has been deposited. currencyId and amount required defined in completionConditions */
459
- depositCurrency?: number;
460
- /** the number of days that have been consecutively logged in at the time of surfacing this offer */
461
- currentLoginStreak?: number;
462
- /** tracks attached social media content and cached validation state */
463
- social?: ISocialTrackerAttach | ISocialTrackerAccumulate;
464
- /** completed context for this player */
465
- context?: string;
466
- /**
467
- * Count of linked entities that have completed their offers.
468
- * For example a referrer refers 5 other referees that have all
469
- * completed the referral criteria. this would then be a value of 5.
470
- */
471
- linkedCompletions?: number;
472
- /**
473
- * Tracked dynamic field values per key.
474
- * Key = dynamic field key, Value = tracked value since offer surfaced
475
- */
476
- dynamicTracker?: Record<string, ICompletionDynamicTracker>;
477
- /**
478
- * Tracked contract interaction values per condition ID.
479
- * Key = condition ID, Value = accumulated amount/count since offer surfaced
480
- * - For spend/earn: token amount
481
- * - For gain/lose: NFT count
482
- * - For custom onchain events: event occurrence count
483
- */
484
- contractInteractions?: Record<string, number>;
485
- }
@@ -1,39 +0,0 @@
1
- export interface IReward {
2
- /** reward kind */
3
- kind: RewardKind;
4
- /** if the trigger is type daily-login, which day is this reward for? */
5
- /** reward id for rewards of kind item, coins, exp or loyalty currency */
6
- rewardId?: string;
7
- /** amount of reward to give. If kind is discount, then this refers to the discount amount, as a fraction */
8
- amount: number;
9
- /** public facing name for this reward */
10
- name: string;
11
- /** unique image url for this reward */
12
- image?: string;
13
- }
14
- export type RewardKind = (typeof rewardKinds)[number];
15
- /** for client side sdk */
16
- export interface IResolvedReward extends IReward {
17
- image?: string;
18
- }
19
- export declare const rewardKinds: readonly ["item", "coins", "exp", "trust_points", "loyalty_currency", "discount"];
20
- export declare const rewardSchema: {
21
- _id: boolean;
22
- kind: {
23
- type: StringConstructor;
24
- enum: readonly ["item", "coins", "exp", "trust_points", "loyalty_currency", "discount"];
25
- };
26
- rewardId: {
27
- type: StringConstructor;
28
- validate: {
29
- validator: (this: IReward, value: string | undefined) => boolean;
30
- message: string;
31
- };
32
- };
33
- skillId: StringConstructor;
34
- currencyId: StringConstructor;
35
- itemId: StringConstructor;
36
- amount: NumberConstructor;
37
- name: StringConstructor;
38
- image: StringConstructor;
39
- };
@@ -1,62 +0,0 @@
1
- import { Stringable } from '.';
2
- export interface AppConnection {
3
- gameId: string;
4
- playerId: string;
5
- linkedAt: Date;
6
- }
7
- export type Restriction = {
8
- kind?: 'block' | 'restrict';
9
- start?: number;
10
- until?: number;
11
- eventCount: number;
12
- message?: string;
13
- };
14
- export interface IUser {
15
- _id: Stringable;
16
- deleted?: boolean;
17
- authId: string;
18
- appConnections?: Array<AppConnection>;
19
- cryptoWallets?: Array<{
20
- address: string;
21
- createdAt: number;
22
- }>;
23
- rewardWallets?: Array<{
24
- address: string;
25
- createdAt: number;
26
- networks: Array<string>;
27
- }>;
28
- providers?: Array<{
29
- provider: string;
30
- accessToken: string;
31
- refreshToken?: string;
32
- expiresAt?: Date;
33
- refreshTokenExpiresAt?: Date;
34
- scope?: string;
35
- tokenType?: string;
36
- providerUserId?: string;
37
- updatedAt: Date;
38
- displayName?: string;
39
- username?: string;
40
- }>;
41
- restriction?: Restriction;
42
- }
43
- export interface IAuthProvider {
44
- type: string;
45
- providerUserId?: string;
46
- profilePic: string;
47
- username?: string;
48
- displayName?: string;
49
- }
50
- export interface AuthMethods {
51
- wallets?: Array<{
52
- address: string;
53
- type: string;
54
- }>;
55
- emails?: Array<{
56
- email: string;
57
- }>;
58
- phones?: Array<{
59
- phone: string;
60
- }>;
61
- providers?: Array<IAuthProvider>;
62
- }
@@ -1,36 +0,0 @@
1
- export type ProviderType = 'coinbase' | 'okx' | 'metamask' | 'trust' | 'ronin' | 'walletConnect' | string;
2
- export interface ICryptoWallet {
3
- /**
4
- * wallet address
5
- */
6
- address: string;
7
- added?: number;
8
- wallet?: ProviderType;
9
- providers?: Array<ProviderType>;
10
- }
11
- export interface ICryptoBalance {
12
- /**
13
- * balance held
14
- */
15
- balance: number;
16
- /**
17
- * total amount deposited
18
- */
19
- in?: number;
20
- /**
21
- * total amount withdrawn
22
- */
23
- out?: number;
24
- /**
25
- * last updated timestamp
26
- * if not present, means never updated
27
- */
28
- lastUpdated?: number;
29
- }
30
- export type CoinSyncStatusType = 'pending' | 'success' | 'error' | 'exclusive' | 'synced' | null;
31
- export interface IBlockchainSyncStatus {
32
- ts: number | null;
33
- status: CoinSyncStatusType;
34
- waiting?: boolean;
35
- error?: string;
36
- }
@@ -1,5 +0,0 @@
1
- export declare const addressNetworkId: (contractAddress: string, network: string) => string;
2
- export declare const deconstructAddressNetworkId: (addressNetwork: string) => {
3
- address: string;
4
- network: string;
5
- };