@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,274 +0,0 @@
1
- import { Stringable } from '.';
2
- import { ICompletionCondition, ICompletionTrackers, IPlayerSnapshot, ISurfacingCondition } from './player';
3
- import { IReward } from './reward';
4
- /** Referral configuration setup if we want to reward players from referring other players */
5
- export interface IOfferReferrals {
6
- /** min count of successful referrals to get this reward */
7
- minCount?: number;
8
- /** max count of successful referrals to get this reward */
9
- maxCount?: number;
10
- /** conditions that each referred player must meet in order to qualify for the referral.
11
- * don't allow tags to be used as conditions since players can't really control their tags direclty */
12
- conditions: Omit<ISurfacingCondition, 'andTags' | 'orTags' | 'notTags'>;
13
- }
14
- /** onSurface and onComplete hooks for offers. Should support:
15
- * - Spawning linked offers for referral/referee type offers
16
- * - Creating cross-game offers
17
- * - Surfacing offers to other linked player snapshots
18
- *
19
- * When an offer is SURFACED to a player, we are able to:
20
- * - surface a linked offer in same game to self
21
- * - surface a linked offer in same game to other players
22
- * - surface a linked offer in different game to other players
23
- *
24
- * When an offer is COMPLETED by a player, we are able to:
25
- * - increment linked tracker of any player offer
26
- * - surface a linked offer in same game to self
27
- * - surface a linked offer in same game to other players
28
- * - surface a linked offer in different game to other players
29
- */
30
- export interface IOfferHookEvent {
31
- _id?: undefined | false | null;
32
- kind: 'spawn_linked_offer' | 'increment_linked_tracker' | 'increment_completed_siblings';
33
- /** player snapshot entity kind that we are spawning the linked offer for */
34
- target?: 'self' | string;
35
- }
36
- export declare const offerListenerEvents: readonly ["claim_offer"];
37
- export type OfferListenerEvent = (typeof offerListenerEvents)[number];
38
- export interface IOfferListener extends IOfferHookEvent {
39
- event: OfferListenerEvent;
40
- }
41
- export interface IOffer {
42
- _id: Stringable;
43
- /** for grouping offers together if they are assocaited with each othert for easy rendering in front-end */
44
- groupId?: string;
45
- name: string;
46
- /** how high of a priority is this offer in comparison to other offers? 1 is highest priority */
47
- priority?: number;
48
- description: string;
49
- createdAt?: Date;
50
- /** notes about this offer */
51
- notes?: string;
52
- /** if this offer is tied to other offers for a/b testing, this is the ID that ties
53
- * all of the offers together
54
- */
55
- campaign?: string;
56
- image?: string;
57
- /** game that this offer corresponds to */
58
- gameId: string;
59
- /** start date of surfacing this offer to players */
60
- startDate?: Date;
61
- /** end date of surfacing this offer to players */
62
- endDate?: Date;
63
- /** if fully archived, the offer will be deleted from memory and not be surfaced anymore to ANYONE. Current players with the offer will no longer see it */
64
- archived?: boolean;
65
- /** is this offer disabled right now? */
66
- disabled?: boolean;
67
- /** labels for UI stuff */
68
- labels?: Array<string>;
69
- /** how long after completing this offer can a player get the same offer again? If undefined, this offer only shows up once EVER for the player */
70
- cooldownMs?: number;
71
- /** how long after a player receives this offer is it available for, before expiring? */
72
- expiryMs?: number;
73
- /** @description DO NOT USE! */
74
- surfacingContexts?: string[];
75
- /** conditions that all must be fulfilled if this offer is to be surfaced to a player */
76
- surfacingConditions: ISurfacingCondition;
77
- /** triggers that allow this offer to be claimable. Leave empty if merely surfacing the offer should allow claiming. */
78
- completionConditions?: ICompletionCondition;
79
- /**
80
- * Conditions for transitioning from 'completed' to 'claimable' status.
81
- * If absent, offers go directly to claimable when completionConditions are met.
82
- */
83
- claimableConditions?: {
84
- /** number of sibling offers that must be completed to make this offer claimable (-1 means all siblings) */
85
- siblingCompletions?: number;
86
- };
87
- /** what does completing this offer reward the player? */
88
- rewards: Array<IReward>;
89
- /** if you can claim rewards multiple times, what is the max claim count you can claim? */
90
- maxClaimCount?: number;
91
- /**
92
- * Linked offer configuration - specifies which offer to spawn when this offer surfaces or completes
93
- */
94
- linkedOffer?: {
95
- /** Specific offer _id to spawn */
96
- _id?: Stringable;
97
- /** OR use campaign for A/B test selection via GrowthBook.
98
- *
99
- * !!!THIS IS NOT SUPPORTED FOR CROSS-GAME OFFERS!!!
100
- */
101
- campaign?: string;
102
- };
103
- /**
104
- * Actions to perform when this offer is surfaced to a player/entity
105
- */
106
- onSurface?: Array<IOfferHookEvent>;
107
- /**
108
- * Actions to perform when ANY instance of this offer is completed
109
- * Gets copied to PlayerOffer and populated with specific IDs
110
- */
111
- onComplete?: Array<IOfferHookEvent>;
112
- /** */
113
- eventListeners?: Array<IOfferListener>;
114
- invitedGameId?: string;
115
- }
116
- export declare const PlayerOfferStatuses: readonly ["surfaced", "viewed", "completed", "claimable", "claimed", "expired"];
117
- export type PlayerOfferStatus = (typeof PlayerOfferStatuses)[number];
118
- export interface IPlayerOfferTrackers {
119
- /********************** These are not really completion trackers, but just regular trackers **********************/
120
- /** player snapshot _id of the person who surfaced this offer */
121
- surfacer_id?: Stringable;
122
- /** playerId of the person who surfaced this player offer */
123
- surfacerPlayerId?: string;
124
- /** gameId of the game who surfaced this player offer */
125
- surfacerGameId?: string;
126
- /** the referral code used to activate the .linkedOffer from the offer. */
127
- referralCode?: string;
128
- /** number of linked player offers spawned off this one. */
129
- linkedCount?: number;
130
- /** if this playerOffer was created due to someone else's offer hook event, what was their player offer _id? */
131
- linkedByPlayerOffer_id?: Stringable;
132
- /**
133
- * IDs of sibling PlayerOffers created together (e.g., both parents from a pet offer).
134
- * Used to check if all siblings completed before any can claim.
135
- * If any sibling expires, all siblings should expire (strict co-op).
136
- */
137
- siblingPlayerOffer_ids?: Stringable[];
138
- /**
139
- * Tracks how many times a linked offer has been surfaced (for cross-game offers)
140
- * Used to prevent duplicate surfacing when games are linked/unlinked/relinked
141
- */
142
- surfacedCount?: number;
143
- claimedCount?: number;
144
- }
145
- export interface IPlayerOffer {
146
- _id: Stringable;
147
- /** starts at 1. multiples of the cooldown timeframe if there is a cooldown. there is a unique index on this and
148
- * it ensures that we do not get multiple offers created for the same offer in the same cooldown timeframe if someone
149
- * tries to abuse and slam the fetchPlayerOffers endpoint
150
- */
151
- cooldownTimeframeMultiple?: number;
152
- /** offer id */
153
- offer_id: Stringable | IOffer;
154
- /** is this an offer that should be surfaced AND PUSHED in real-time to a player? */
155
- realTime?: boolean;
156
- claimedAt?: Date;
157
- rewards: Array<IReward>;
158
- /** when the player offer is created, we copy over all completion conditions to
159
- * player offer so that if the original offer changes, the player still sees whatever
160
- * the completion conditions were at the time of creation.
161
- *
162
- * If there are no completion conditions, then the offer should be claimable immediately
163
- */
164
- /** @deprecated in favour of IOffer.completionCondition. BUT ON CLIENT-SIDE WE USE THIS FIELD. but NOT on server!
165
- * Server populates this field for client.
166
- */
167
- completionConditions?: ICompletionCondition;
168
- /** tracking the player's status for completing the conditions to claim the offer, if
169
- * required.
170
- */
171
- completionTrackers?: ICompletionTrackers;
172
- trackers?: IPlayerOfferTrackers;
173
- /**
174
- * Trackers for claimableConditions (completed → claimable transition).
175
- */
176
- claimableTrackers?: {
177
- /** Counter incremented when a sibling offer completes */
178
- siblingCompletions?: number;
179
- };
180
- /** status of the offer
181
- * - surfaced: offer is now surfaced to the player, but not viewed by the player yet.
182
- * - viewed: offer has been viewed by the player, but not yet completed. The expiration time only starts when the player views the offer
183
- * - completed: individual completionConditions met, waiting for claimableConditions (e.g., all siblings must complete)
184
- * - claimable: offer has been completed and is now claimable by the player
185
- * - claimed: offer has been completed and the player has claimed the rewards.
186
- * - expired: offer has expired and is no longer available to the player
187
- */
188
- status: PlayerOfferStatus;
189
- /** player _id */
190
- playerId: string;
191
- /** game _id */
192
- gameId: string;
193
- /** created at date */
194
- createdAt: Date;
195
- /** expiry date */
196
- expiresAt?: Date;
197
- /**
198
- * Actions to perform when this PlayerOffer is completed
199
- */
200
- onComplete?: Array<IOfferHookEvent>;
201
- }
202
- declare const keysToTake: readonly ["playerId", "username", "daysInGame", "loginStreak", "levels", "quests", "currencies", "achievements", "memberships", "stakedTokens", "dynamic", "trustScore", "entityKind", "snapshotLastUpdated"];
203
- type StripLastUpdated<T> = T extends Record<string, infer U> ? U extends {
204
- lastUpdated?: any;
205
- } ? Record<string, Omit<U, 'lastUpdated'>> : T : T;
206
- export type IStrippedSnapshot = {
207
- [K in (typeof keysToTake)[number]]?: StripLastUpdated<IPlayerSnapshot[K]>;
208
- };
209
- /** Stripped sibling offer data for client rendering */
210
- export interface IClientEntityProgress {
211
- status: PlayerOfferStatus;
212
- completionTrackers?: ICompletionTrackers;
213
- completionConditions?: ICompletionCondition;
214
- snapshot?: IStrippedSnapshot;
215
- }
216
- export interface IClientOffer {
217
- /** offer id */
218
- offerId: string;
219
- instanceId: string;
220
- /** player _id */
221
- playerId: string;
222
- /** game that this offer corresponds to */
223
- gameId: string;
224
- /** optional group identifier for related offers (e.g., streak progression) */
225
- groupId?: string;
226
- name: string;
227
- description: string;
228
- image?: string;
229
- /** when the player offer is created, we copy over all completion conditions to
230
- * player offer so that if the original offer changes, the player still sees whatever
231
- * the completion conditions were at the time of creation.
232
- *
233
- * If there are no completion conditions, then the offer should be claimable immediately
234
- */
235
- completionConditions?: ICompletionCondition;
236
- /** tracking the player's status for completing the conditions to claim the offer, if
237
- * required.
238
- */
239
- completionTrackers?: ICompletionTrackers;
240
- claimableTrackers?: IPlayerOffer['claimableTrackers'];
241
- trackers?: IPlayerOfferTrackers;
242
- /** claimable conditions for the offer */
243
- claimableConditions?: IOffer['claimableConditions'];
244
- /** Labels for offer categorization and rendering
245
- * Contains:
246
- * - IOffer.labels (manual: 'featured', 'verified', 'quest')
247
- * - Server-injected labels: 'daily', 'weekly', 'avgTimeToComplete:X', 'usdValue:X'
248
- */
249
- labels?: Array<string>;
250
- /** what does completing this offer reward the player? */
251
- rewards: Array<IReward>;
252
- /** status of the offer
253
- * - surfaced: offer is now surfaced to the player, but not viewed by the player yet.
254
- * - viewed: offer has been viewed by the player, but not yet completed. The expiration time only starts when the player views the offer
255
- * - completed: individual completionConditions met, waiting for claimableConditions (e.g., all siblings must complete)
256
- * - claimable: offer has been completed and is now claimable by the player
257
- * - claimed: offer has been completed and the player has claimed the rewards.
258
- * - expired: offer has expired and is no longer available to the player
259
- */
260
- status: PlayerOfferStatus;
261
- /** created at date */
262
- createdAt: Date;
263
- /** expiry date */
264
- expiresAt?: Date;
265
- /** Number of times the player has claimed this offer (for multi-claim offers) */
266
- claimedCount?: number;
267
- /** Maximum number of times this offer can be claimed (-1 for infinite, undefined for single claim) */
268
- maxClaimCount?: number;
269
- /** Siblings */
270
- siblings?: IClientEntityProgress[];
271
- /** Progress data for linked entity's offer (e.g., pet's progress on their task) */
272
- linked?: IClientEntityProgress[];
273
- }
274
- export {};