@fruga/sdk 1.0.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/LICENSE +15 -0
- package/README.md +118 -0
- package/connect/package.json +6 -0
- package/core/package.json +6 -0
- package/dist/connect.d.mts +73 -0
- package/dist/connect.d.ts +73 -0
- package/dist/connect.js +26 -0
- package/dist/connect.mjs +26 -0
- package/dist/core/package.json +5 -0
- package/dist/index.d.mts +398 -0
- package/dist/index.d.ts +398 -0
- package/dist/index.js +783 -0
- package/dist/index.mjs +725 -0
- package/dist/loader/package.json +17 -0
- package/dist/loader-react.d.mts +127 -0
- package/dist/loader-react.d.ts +127 -0
- package/dist/loader-react.js +26 -0
- package/dist/loader-react.mjs +26 -0
- package/dist/loader.d.mts +24 -0
- package/dist/loader.d.ts +24 -0
- package/dist/loader.js +2 -0
- package/dist/loader.mjs +2 -0
- package/dist/relay.css +3 -0
- package/dist/relay.d.mts +61 -0
- package/dist/relay.d.ts +61 -0
- package/dist/relay.js +2 -0
- package/dist/relay.mjs +2 -0
- package/loader/package.json +6 -0
- package/package.json +89 -0
- package/relay/package.json +6 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import * as zustand from 'zustand';
|
|
3
|
+
|
|
4
|
+
type RequiredActionType = 'ADD_PAYOUT_METHOD';
|
|
5
|
+
interface RequiredAction {
|
|
6
|
+
type: RequiredActionType;
|
|
7
|
+
transactionId?: number;
|
|
8
|
+
}
|
|
9
|
+
interface Wallet {
|
|
10
|
+
available: number;
|
|
11
|
+
pending: number;
|
|
12
|
+
totalBalance: number;
|
|
13
|
+
lifetimeEarned: number;
|
|
14
|
+
lifetimeRedeemed: number;
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
requiredActions: RequiredAction[] | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PayoutMethodType = 'BANK';
|
|
20
|
+
type PayoutMethodStatus = 'ACTIVE' | 'INACTIVE' | 'PENDING';
|
|
21
|
+
interface BankInfo {
|
|
22
|
+
accountLast4: string;
|
|
23
|
+
sortCodeMasked: string;
|
|
24
|
+
accountHolderName: string;
|
|
25
|
+
}
|
|
26
|
+
interface PayoutMethod {
|
|
27
|
+
id: string | number;
|
|
28
|
+
methodType: PayoutMethodType;
|
|
29
|
+
isDefault: boolean;
|
|
30
|
+
status: PayoutMethodStatus;
|
|
31
|
+
bank: BankInfo;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
updatedAt: string;
|
|
34
|
+
}
|
|
35
|
+
interface AddBankPayload {
|
|
36
|
+
accountHolderName: string;
|
|
37
|
+
accountNumber: string;
|
|
38
|
+
sortCode: string;
|
|
39
|
+
}
|
|
40
|
+
interface PayoutMethodListResponse {
|
|
41
|
+
items: PayoutMethod[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface Transaction {
|
|
45
|
+
id: number;
|
|
46
|
+
brandName: string;
|
|
47
|
+
brandLogo: string;
|
|
48
|
+
offerName: string;
|
|
49
|
+
purchaseAmount: number;
|
|
50
|
+
activityAmount: number;
|
|
51
|
+
occuredAt: string;
|
|
52
|
+
type: string;
|
|
53
|
+
status: string;
|
|
54
|
+
flow: string;
|
|
55
|
+
blockingReason?: string;
|
|
56
|
+
notes?: string;
|
|
57
|
+
partnerEventId: string;
|
|
58
|
+
redemptionContext: string;
|
|
59
|
+
}
|
|
60
|
+
interface Activity {
|
|
61
|
+
actorType: string;
|
|
62
|
+
partnerId: number;
|
|
63
|
+
transactions: Transaction[];
|
|
64
|
+
}
|
|
65
|
+
interface PaginatedActivity {
|
|
66
|
+
actorType: string;
|
|
67
|
+
partnerId: number;
|
|
68
|
+
transactions: Transaction[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare const DEFAULT_THEME: {
|
|
72
|
+
widgetTitle: string;
|
|
73
|
+
launcherLabel: string;
|
|
74
|
+
launcherIcon: "gift" | "sparkles" | "credit" | "arrow" | "none";
|
|
75
|
+
showLauncher: boolean;
|
|
76
|
+
mode: "dark" | "light";
|
|
77
|
+
allowUserThemeControl: boolean;
|
|
78
|
+
defaultTheme: "dark" | "light";
|
|
79
|
+
uiVersion: "legacy" | "current";
|
|
80
|
+
primary: string;
|
|
81
|
+
accent: string;
|
|
82
|
+
accentTextLight: string;
|
|
83
|
+
accentTextDark: string;
|
|
84
|
+
bg: string;
|
|
85
|
+
panel: string;
|
|
86
|
+
panel2: string;
|
|
87
|
+
itemBg: string;
|
|
88
|
+
text: string;
|
|
89
|
+
muted: string;
|
|
90
|
+
border: string;
|
|
91
|
+
success: string;
|
|
92
|
+
danger: string;
|
|
93
|
+
warning: string;
|
|
94
|
+
lightBg: string;
|
|
95
|
+
lightPanel: string;
|
|
96
|
+
lightPanel2: string;
|
|
97
|
+
lightItemBg: string;
|
|
98
|
+
lightText: string;
|
|
99
|
+
lightMuted: string;
|
|
100
|
+
lightBorder: string;
|
|
101
|
+
};
|
|
102
|
+
type Theme = typeof DEFAULT_THEME & {
|
|
103
|
+
textColorDark?: string;
|
|
104
|
+
textColorLight?: string;
|
|
105
|
+
};
|
|
106
|
+
type ResolvedTheme = Pick<Theme, "primary" | "accent" | "accentTextLight" | "accentTextDark" | "success" | "warning" | "widgetTitle" | "launcherLabel" | "launcherIcon" | "danger" | "allowUserThemeControl"> & {
|
|
107
|
+
bg: string;
|
|
108
|
+
panel: string;
|
|
109
|
+
panel2: string;
|
|
110
|
+
itemBg: string;
|
|
111
|
+
text: string;
|
|
112
|
+
muted: string;
|
|
113
|
+
border: string;
|
|
114
|
+
subtleBg: string;
|
|
115
|
+
tooltipBg: string;
|
|
116
|
+
tooltipBorder: string;
|
|
117
|
+
accentText: string;
|
|
118
|
+
isLight: boolean;
|
|
119
|
+
mode: "light" | "dark";
|
|
120
|
+
};
|
|
121
|
+
declare function getResolvedTheme(theme: Theme): ResolvedTheme;
|
|
122
|
+
|
|
123
|
+
interface OfferCategory {
|
|
124
|
+
id: number;
|
|
125
|
+
name: string;
|
|
126
|
+
rank: number;
|
|
127
|
+
offerCount: number;
|
|
128
|
+
}
|
|
129
|
+
type OfferCategoryResponse = OfferCategory[];
|
|
130
|
+
|
|
131
|
+
type Category = string;
|
|
132
|
+
interface Offer {
|
|
133
|
+
id: number;
|
|
134
|
+
name: string;
|
|
135
|
+
brandName: string;
|
|
136
|
+
description: string;
|
|
137
|
+
terms: string;
|
|
138
|
+
link: string;
|
|
139
|
+
type: "AFFILIATE_LINK" | "PAYMENT_LINK" | "GIFTCARD" | string;
|
|
140
|
+
logo: string;
|
|
141
|
+
cashback: number;
|
|
142
|
+
endDate: string;
|
|
143
|
+
featured: boolean;
|
|
144
|
+
categories: OfferCategory[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
interface PaginatedResponse<T> {
|
|
148
|
+
content: T[];
|
|
149
|
+
totalElements: number;
|
|
150
|
+
totalPages: number;
|
|
151
|
+
number: number;
|
|
152
|
+
size: number;
|
|
153
|
+
numberOfElements: number;
|
|
154
|
+
numberOfPages: number;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface OfferQuery {
|
|
158
|
+
pageNumber?: number;
|
|
159
|
+
pageSize?: number;
|
|
160
|
+
type?: "AFFILIATE_LINK" | "PAYMENT_LINK" | "GIFTCARD" | string;
|
|
161
|
+
query?: string;
|
|
162
|
+
featured?: boolean;
|
|
163
|
+
categories?: string[];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
type PartnerType = 'RELAY' | 'CONNECT' | 'EXTERNAL_TENANT';
|
|
167
|
+
interface PartnerConfig {
|
|
168
|
+
partnerId: string;
|
|
169
|
+
partnerType: PartnerType;
|
|
170
|
+
theme?: {
|
|
171
|
+
primaryColor?: string;
|
|
172
|
+
mode?: 'light' | 'dark';
|
|
173
|
+
};
|
|
174
|
+
features?: Record<string, boolean>;
|
|
175
|
+
appUrl?: string;
|
|
176
|
+
partnerKey?: string;
|
|
177
|
+
userId?: string;
|
|
178
|
+
}
|
|
179
|
+
interface WidgetUiConfig {
|
|
180
|
+
accent: string;
|
|
181
|
+
defaultTheme: 'light' | 'dark';
|
|
182
|
+
launcherIcon: string;
|
|
183
|
+
showLauncher: boolean;
|
|
184
|
+
launcherLabel: string;
|
|
185
|
+
accentTextDark: string;
|
|
186
|
+
accentTextLight: string;
|
|
187
|
+
allowUserThemeControl: boolean;
|
|
188
|
+
}
|
|
189
|
+
interface BootstrapAuth {
|
|
190
|
+
mode: string;
|
|
191
|
+
audience: string;
|
|
192
|
+
issuer: string;
|
|
193
|
+
tokenTtlSeconds: number;
|
|
194
|
+
}
|
|
195
|
+
interface WidgetBootstrap {
|
|
196
|
+
partnerEnvId: string;
|
|
197
|
+
partnerId: string;
|
|
198
|
+
partnerType: PartnerType;
|
|
199
|
+
partnerPayout: 'PARTNER' | 'USER';
|
|
200
|
+
auth: BootstrapAuth;
|
|
201
|
+
config: {
|
|
202
|
+
ui: WidgetUiConfig;
|
|
203
|
+
validValues: {
|
|
204
|
+
defaultTheme: string[];
|
|
205
|
+
launcherIcon: string[];
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
interface RelayConfig {
|
|
210
|
+
containerId: string;
|
|
211
|
+
partnerKey: string;
|
|
212
|
+
token?: string;
|
|
213
|
+
baseUrl?: string;
|
|
214
|
+
theme?: 'light' | 'dark';
|
|
215
|
+
primaryColor?: string;
|
|
216
|
+
userId?: string;
|
|
217
|
+
bootstrapConfig?: WidgetBootstrap;
|
|
218
|
+
isHostMobile?: boolean;
|
|
219
|
+
hostHeight?: number;
|
|
220
|
+
}
|
|
221
|
+
interface RelayState {
|
|
222
|
+
isOpen: boolean;
|
|
223
|
+
isClaimed: boolean;
|
|
224
|
+
}
|
|
225
|
+
declare global {
|
|
226
|
+
interface Window {
|
|
227
|
+
FrugaRelay?: {
|
|
228
|
+
init: (config: RelayConfig) => void;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
interface IWalletService {
|
|
234
|
+
getWallet(): Promise<Wallet>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
interface IActivityService {
|
|
238
|
+
getActivity(pageNumber?: number, pageSize?: number): Promise<PaginatedActivity>;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface IOffersService {
|
|
242
|
+
getCategories(): Promise<OfferCategoryResponse>;
|
|
243
|
+
getOffers(query: OfferQuery): Promise<PaginatedResponse<Offer>>;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
interface IPayoutService {
|
|
247
|
+
listMethods(): Promise<PayoutMethod[]>;
|
|
248
|
+
addBankMethod(payload: AddBankPayload): Promise<PayoutMethod>;
|
|
249
|
+
deleteMethod(id: string | number): Promise<void>;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare class HttpWalletService implements IWalletService {
|
|
253
|
+
private readonly baseUrl;
|
|
254
|
+
private readonly token;
|
|
255
|
+
constructor(baseUrl: string, token: string);
|
|
256
|
+
getWallet(): Promise<Wallet>;
|
|
257
|
+
private getEmptyWallet;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
type QueryParamValue = string | number | boolean | string[] | undefined | null;
|
|
261
|
+
declare abstract class BaseHttpService {
|
|
262
|
+
protected readonly baseUrl: string;
|
|
263
|
+
protected readonly token: string;
|
|
264
|
+
constructor(baseUrl: string, token: string);
|
|
265
|
+
protected fetchQuery(path: string, queryParams?: Record<string, QueryParamValue>): Promise<Response>;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
declare class HttpActivityService extends BaseHttpService implements IActivityService {
|
|
269
|
+
constructor(baseUrl: string, token: string);
|
|
270
|
+
getActivity(pageNumber?: number, pageSize?: number): Promise<PaginatedActivity>;
|
|
271
|
+
private getEmptyActivity;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
declare class HttpOffersService extends BaseHttpService implements IOffersService {
|
|
275
|
+
constructor(baseUrl: string, token: string);
|
|
276
|
+
getCategories(): Promise<OfferCategoryResponse>;
|
|
277
|
+
getOffers(query: OfferQuery): Promise<PaginatedResponse<Offer>>;
|
|
278
|
+
private getEmptyPaginatedResponse;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare class HttpPayoutService implements IPayoutService {
|
|
282
|
+
private readonly baseUrl;
|
|
283
|
+
private readonly token;
|
|
284
|
+
constructor(baseUrl: string, token: string);
|
|
285
|
+
listMethods(): Promise<PayoutMethod[]>;
|
|
286
|
+
addBankMethod(payload: AddBankPayload): Promise<PayoutMethod>;
|
|
287
|
+
deleteMethod(id: string | number): Promise<void>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
291
|
+
variant?: 'primary' | 'secondary';
|
|
292
|
+
}
|
|
293
|
+
declare const WidgetButton: React.FC<ButtonProps>;
|
|
294
|
+
declare const WidgetHeader: React.FC<{
|
|
295
|
+
title: string;
|
|
296
|
+
}>;
|
|
297
|
+
|
|
298
|
+
interface WidgetContainerProps {
|
|
299
|
+
children: ReactNode;
|
|
300
|
+
hostHeight?: number;
|
|
301
|
+
isMobile?: boolean;
|
|
302
|
+
theme: Theme;
|
|
303
|
+
}
|
|
304
|
+
declare const WidgetContainer: React.FC<WidgetContainerProps>;
|
|
305
|
+
|
|
306
|
+
interface WidgetContextType {
|
|
307
|
+
isOpen: boolean;
|
|
308
|
+
toggle: () => void;
|
|
309
|
+
setOpen: (open: boolean) => void;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* @deprecated Use useWidgetStore instead or the updated useWidget hook.
|
|
313
|
+
* The WidgetProvider is no longer required as we are using Zustand for state management.
|
|
314
|
+
*/
|
|
315
|
+
declare const WidgetProvider: React.FC<{
|
|
316
|
+
children: ReactNode;
|
|
317
|
+
}>;
|
|
318
|
+
declare const useWidget: () => WidgetContextType;
|
|
319
|
+
|
|
320
|
+
interface WidgetState {
|
|
321
|
+
isOpen: boolean;
|
|
322
|
+
isFocused: boolean;
|
|
323
|
+
isIdle: boolean;
|
|
324
|
+
mode: 'light' | 'dark';
|
|
325
|
+
token: string | null;
|
|
326
|
+
partnerPayout: 'PARTNER' | 'USER' | null;
|
|
327
|
+
toggle: () => void;
|
|
328
|
+
setOpen: (open: boolean) => void;
|
|
329
|
+
setFocused: (focused: boolean) => void;
|
|
330
|
+
setIdle: (idle: boolean) => void;
|
|
331
|
+
available: number;
|
|
332
|
+
pending: number;
|
|
333
|
+
setBalances: (available: number, pending: number) => void;
|
|
334
|
+
setMode: (mode: 'light' | 'dark') => void;
|
|
335
|
+
setToken: (token: string | null) => void;
|
|
336
|
+
setPartnerPayout: (payout: 'PARTNER' | 'USER') => void;
|
|
337
|
+
isAddingPayoutFromAlert: boolean;
|
|
338
|
+
setIsAddingPayoutFromAlert: (val: boolean) => void;
|
|
339
|
+
showPayoutSuccess: boolean;
|
|
340
|
+
setShowPayoutSuccess: (val: boolean) => void;
|
|
341
|
+
}
|
|
342
|
+
declare const useWidgetStore: zustand.UseBoundStore<zustand.StoreApi<WidgetState>>;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* A hook that returns a debounced version of the provided value.
|
|
346
|
+
* @param value The value to debounce
|
|
347
|
+
* @param delay The delay in milliseconds
|
|
348
|
+
* @returns The debounced value
|
|
349
|
+
*/
|
|
350
|
+
declare const useDebounce: <T>(value: T, delay: number) => T;
|
|
351
|
+
|
|
352
|
+
declare const STORAGE_KEYS: {
|
|
353
|
+
readonly BOOTSTRAP_DATA: "fruga_bootstrap";
|
|
354
|
+
readonly BOOTSTRAP_CONFIG: "fruga_active_config";
|
|
355
|
+
};
|
|
356
|
+
declare class StorageService {
|
|
357
|
+
static set<T>(key: string, value: T): void;
|
|
358
|
+
static get<T>(key: string): T | null;
|
|
359
|
+
static remove(key: string): void;
|
|
360
|
+
static clear(): void;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Default API Base URL for the Fruga SDK.
|
|
365
|
+
* This can be overridden at build-time using the VITE_FRUGA_API_URL environment variable.
|
|
366
|
+
*/
|
|
367
|
+
declare const DEFAULT_API_URL: string;
|
|
368
|
+
declare const getBaseUrl: (override?: string) => string;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Formats a date string to "DD-MM-YYYY"
|
|
372
|
+
* @param dateStr Date string in various formats (e.g., "YYYY-MM-DD", "DD/MM/YYYY", ISO)
|
|
373
|
+
* @returns Formatted date string "DD-MM-YYYY" (e.g., "09-04-2026")
|
|
374
|
+
*/
|
|
375
|
+
declare const formatDate: (dateStr?: string) => string;
|
|
376
|
+
/**
|
|
377
|
+
* Checks if a date is within a certain number of days from now
|
|
378
|
+
* @param dateStr Date string
|
|
379
|
+
* @param daysLimit Number of days
|
|
380
|
+
* @returns boolean
|
|
381
|
+
*/
|
|
382
|
+
declare const isWithinDays: (dateStr?: string, daysLimit?: number) => boolean;
|
|
383
|
+
/**
|
|
384
|
+
* Gets the number of days remaining until a target date
|
|
385
|
+
* @param dateStr Date string
|
|
386
|
+
* @returns Number of days (0 or more) or null if invalid
|
|
387
|
+
*/
|
|
388
|
+
declare const getDaysRemaining: (dateStr?: string) => number | null;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Truncates a string if it exceeds a certain length and adds an ellipsis.
|
|
392
|
+
* @param str The string to truncate
|
|
393
|
+
* @param maxLength The maximum length before truncation (default 40)
|
|
394
|
+
* @returns The truncated string with "..." if it was truncated, otherwise the original string.
|
|
395
|
+
*/
|
|
396
|
+
declare const truncateText: (str: string | undefined | null, maxLength?: number) => string;
|
|
397
|
+
|
|
398
|
+
export { type Activity, type AddBankPayload, type BankInfo, type BootstrapAuth, type Category, DEFAULT_API_URL, DEFAULT_THEME, DEFAULT_THEME as DefaultTheme, HttpActivityService, HttpOffersService, HttpPayoutService, HttpWalletService, type IActivityService, type IOffersService, type IPayoutService, type IWalletService, type Offer, type OfferCategory, type OfferCategoryResponse, type OfferQuery, type PaginatedActivity, type PaginatedResponse, type PartnerConfig, type PartnerType, type PayoutMethod, type PayoutMethodListResponse, type PayoutMethodStatus, type PayoutMethodType, type RelayConfig, type RelayState, type RequiredAction, type RequiredActionType, type ResolvedTheme, STORAGE_KEYS, StorageService, type Theme, type Transaction, type Wallet, type WidgetBootstrap, WidgetButton, WidgetContainer, type WidgetContainerProps, type WidgetContextType, WidgetHeader, WidgetProvider, type WidgetState, type WidgetUiConfig, formatDate, getBaseUrl, getDaysRemaining, getResolvedTheme, isWithinDays, truncateText, useDebounce, useWidget, useWidgetStore };
|