@smile-io/smile-js 0.6.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/README.md +54 -0
- package/dist/index.bundled.d.ts +452 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.esm.js +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Smile.io JavaScript SDK (Smile.js)
|
|
2
|
+
|
|
3
|
+
This package allows you to load Smile.io's JavaScript SDK (Smile.js) as a CommonJS or ES module, and provides TypeScript declarations for autocomplete and type checking.
|
|
4
|
+
|
|
5
|
+
**[Full SDK documentation and reference →](https://dev.smile.io/js/)**
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Use npm to install the package:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @smile-io/smile-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### `loadSmile()`
|
|
18
|
+
|
|
19
|
+
This function returns a `Promise` that resolves with an instance of the JavaScript SDK. It loads the SDK by inserting a script tag into the DOM. Calling `loadSmile()` in a server environment will resolve to `null` and the SDK will not be loaded.
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import { loadSmile } from '@smile-io/smile-js';
|
|
23
|
+
|
|
24
|
+
const Smile = await loadSmile();
|
|
25
|
+
|
|
26
|
+
if (Smile) {
|
|
27
|
+
// The SDK was successfully loaded and
|
|
28
|
+
// is ready to be initialized
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
For more information on how to initialize and use the JavaScript SDK, refer to the [JavaScript SDK documentation](https://dev.smile.io/js/).
|
|
33
|
+
|
|
34
|
+
## Versioning
|
|
35
|
+
|
|
36
|
+
Calling `loadSmile()` always fetches the latest version of the JavaScript SDK for the major version of `@smile-io/smile-js` that you have installed. For example, any package version in the `1.x.x` range will load the latest release of Smile.js v1 from Smile's CDN. This ensures that you always get the latest non-breaking improvements and bug fixes, regardless of which version of the package you're using.
|
|
37
|
+
|
|
38
|
+
While we still recommend keeping up to date with the latest version of the `@smile-io/smile-js` package, minor and patch version bumps will only represent changes to:
|
|
39
|
+
|
|
40
|
+
- TypeScript type updates (new fields, methods, or resources)
|
|
41
|
+
- Improvements or bug fixes to the code that loads the SDK from Smile’s CDN
|
|
42
|
+
|
|
43
|
+
To learn more, refer to the [SDK versioning explainer](https://dev.smile.io/js/concepts/versioning).
|
|
44
|
+
|
|
45
|
+
## TypeScript support
|
|
46
|
+
|
|
47
|
+
This package includes TypeScript declarations for the JavaScript SDK. Import and use them like you would any other types.
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { loadSmile } from '@smile-io/smile-js';
|
|
51
|
+
import type { Smile, Customer, PointsProduct } from '@smile-io/smile-js';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
We may occasionally release minor and patch versions of `@smile-io/smile-js` with small but backwards-incompatible changes to the type declarations. These changes will not affect the behavior of the SDK itself.
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of a customer in the loyalty program.
|
|
3
|
+
* - `candidate`: An individual that has not yet joined the loyalty program. Depending on program settings, they may or may not earn points.
|
|
4
|
+
* - `member`: An active loyalty program participant.
|
|
5
|
+
* - `disabled`: An individual that has been excluded from the program and cannot earn or redeem rewards.
|
|
6
|
+
*/
|
|
7
|
+
type CustomerState = "member" | "candidate" | "disabled";
|
|
8
|
+
/**
|
|
9
|
+
* Customer object.
|
|
10
|
+
*
|
|
11
|
+
* Customers represent individuals in the loyalty program.
|
|
12
|
+
*/
|
|
13
|
+
interface Customer {
|
|
14
|
+
/** The unique identifier of the customer. */
|
|
15
|
+
id: number;
|
|
16
|
+
/** The customer's first name. */
|
|
17
|
+
firstName: string | null;
|
|
18
|
+
/** The customer's last name. */
|
|
19
|
+
lastName: string | null;
|
|
20
|
+
/** The customer's email address. */
|
|
21
|
+
email: string;
|
|
22
|
+
/** The customer's birthday. A year value of `1004` means only the customer's birth day and month is available. */
|
|
23
|
+
dateOfBirth: string | null;
|
|
24
|
+
/** The customer's unique referral URL. Used to share with friends as part of the referral program. */
|
|
25
|
+
referralUrl: string;
|
|
26
|
+
/** The customer's state in the loyalty program. */
|
|
27
|
+
state: CustomerState;
|
|
28
|
+
/** Date and time the customer was created at in Smile. */
|
|
29
|
+
createdAt: string;
|
|
30
|
+
/** The date the customer was last updated in Smile. */
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Partial VIP tier object.
|
|
35
|
+
*
|
|
36
|
+
* A condensed representation of a VIP tier containing only key fields.
|
|
37
|
+
*/
|
|
38
|
+
interface VipTierPartial {
|
|
39
|
+
/** The unique identifier of the VIP tier. */
|
|
40
|
+
id: number;
|
|
41
|
+
/** The name of the VIP tier. */
|
|
42
|
+
name: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Customer VIP status object.
|
|
46
|
+
*
|
|
47
|
+
* An object containing details about the customer's status within the VIP program.
|
|
48
|
+
*/
|
|
49
|
+
interface CustomerVipStatus {
|
|
50
|
+
/** The amount the customer has already spent or earned within the current VIP period. */
|
|
51
|
+
progressValue: number;
|
|
52
|
+
/**
|
|
53
|
+
* A partial representation of the customer's current VIP tier.
|
|
54
|
+
* A `null` value indicates that the customer is not in a VIP tier.
|
|
55
|
+
*/
|
|
56
|
+
vipTier: VipTierPartial | null;
|
|
57
|
+
/**
|
|
58
|
+
* The date the customer's current VIP tier expires.
|
|
59
|
+
* For all-time VIP programs, this will be `null` because tiers do not expire.
|
|
60
|
+
*/
|
|
61
|
+
vipTierExpiresAt: string | null;
|
|
62
|
+
/**
|
|
63
|
+
* The additional amount the customer must spend or earn before the end of the current VIP
|
|
64
|
+
* period to retain their VIP tier until the end of the next VIP period.
|
|
65
|
+
* For all-time VIP programs or if the customer has already spent or earned enough this
|
|
66
|
+
* period to retain their current VIP tier, this will be `null`.
|
|
67
|
+
*/
|
|
68
|
+
deltaToRetainVipTier: number | null;
|
|
69
|
+
/**
|
|
70
|
+
* The end date for the current VIP period. For calendar-year VIP programs, this will be the
|
|
71
|
+
* end of the current calendar year. For all-time VIP programs, this will be `null`.
|
|
72
|
+
*/
|
|
73
|
+
currentVipPeriodEnd: string | null;
|
|
74
|
+
/**
|
|
75
|
+
* A partial representation of the next VIP tier that the customer will move into if they meet the minimum spending or
|
|
76
|
+
* earning requirement. If the customer is already in the highest tier, this will be `null`.
|
|
77
|
+
*/
|
|
78
|
+
nextVipTier: VipTierPartial | null;
|
|
79
|
+
/**
|
|
80
|
+
* The amount the customer must spend or earn within the current VIP period to reach the
|
|
81
|
+
* next VIP tier. If the customer is already in the highest tier, this will be `null`.
|
|
82
|
+
*/
|
|
83
|
+
deltaToNextVipTier: number | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Customer points wallet object.
|
|
87
|
+
*
|
|
88
|
+
* Represents the customer's current points balance.
|
|
89
|
+
*/
|
|
90
|
+
interface CustomerPointsWallet {
|
|
91
|
+
/** The customer's current points balance. */
|
|
92
|
+
balance: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Customer points product object.
|
|
96
|
+
*
|
|
97
|
+
* A customer points product is a version of a points product that is specific to the currently logged-in customer.
|
|
98
|
+
*/
|
|
99
|
+
interface CustomerPointsProduct {
|
|
100
|
+
/** Name of the reward that the customer will receive when their points are redeemed. */
|
|
101
|
+
name: string;
|
|
102
|
+
/** Number of points needed to purchase this reward. */
|
|
103
|
+
pointsPrice: number;
|
|
104
|
+
/** A nested Points Product object representing the points product that this reward is based on. */
|
|
105
|
+
pointsProduct: PointsProduct;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* How points are exchanged for a given reward / points product.
|
|
109
|
+
* - `fixed`: A fixed amount of points for a predetermined reward value.
|
|
110
|
+
* - `variable`: A variable amount of points for a dynamic reward value.
|
|
111
|
+
*/
|
|
112
|
+
type PointsProductExchangeType = "fixed" | "variable";
|
|
113
|
+
/**
|
|
114
|
+
* Points product object.
|
|
115
|
+
*
|
|
116
|
+
* Points products are rewards that customers can redeem points for.
|
|
117
|
+
*/
|
|
118
|
+
interface PointsProduct {
|
|
119
|
+
/** The unique identifier for the points product. */
|
|
120
|
+
id: number;
|
|
121
|
+
/**
|
|
122
|
+
* How points are exchanged for the reward.
|
|
123
|
+
*/
|
|
124
|
+
exchangeType: PointsProductExchangeType;
|
|
125
|
+
/** A human readable description of how a customer spends points on this reward. It includes the points branding for the program. */
|
|
126
|
+
exchangeDescription: string;
|
|
127
|
+
/** Number of points needed to purchase this reward (only present when `exchangeType` is `fixed`). */
|
|
128
|
+
pointsPrice?: number;
|
|
129
|
+
/** The number of points between each notch on the slider (only present when `exchangeType` is `variable`). */
|
|
130
|
+
variablePointsStep?: number;
|
|
131
|
+
/** The corresponding reward value for each step increment on the slider (only present when `exchangeType` is `variable`). */
|
|
132
|
+
variablePointsStepRewardValue?: number;
|
|
133
|
+
/** The minimum amount of points the customer must spend to get this reward (only present when `exchangeType` is `variable`). */
|
|
134
|
+
variablePointsMin?: number;
|
|
135
|
+
/** The maximum amount of points the customer can spend on this reward (only present when `exchangeType` is `variable`). */
|
|
136
|
+
variablePointsMax?: number;
|
|
137
|
+
/** A nested Reward object representing the reward issued to the customer when they purchase the points product. */
|
|
138
|
+
reward: Reward;
|
|
139
|
+
/** Date and time at which the points product was created. */
|
|
140
|
+
createdAt: string;
|
|
141
|
+
/** Date and time at which the points product was updated. */
|
|
142
|
+
updatedAt: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The fulfillment status of a reward fulfillment, indicating whether the reward is available to the customer.
|
|
146
|
+
* - `pending`: The reward is being fulfilled asynchronously and is not yet available to the customer.
|
|
147
|
+
* - `issued`: The reward has been successfully fulfilled and is available for use by the customer.
|
|
148
|
+
* - `cancelled`: The reward has been revoked and is no longer available to the customer.
|
|
149
|
+
* - `failed`: The reward could not be fulfilled and is not available to the customer.
|
|
150
|
+
*/
|
|
151
|
+
type RewardFulfillmentStatus = "pending" | "issued" | "cancelled" | "failed";
|
|
152
|
+
/**
|
|
153
|
+
* Reward fulfillment object.
|
|
154
|
+
*
|
|
155
|
+
* A reward fulfillment is a reward that has been issued to a customer.
|
|
156
|
+
*/
|
|
157
|
+
interface RewardFulfillment {
|
|
158
|
+
/** The unique identifier of the reward fulfillment. */
|
|
159
|
+
id: number;
|
|
160
|
+
/** The reward fulfillment's name. */
|
|
161
|
+
name: string;
|
|
162
|
+
/**
|
|
163
|
+
* A unique code for the customer to use. This is commonly a discount code
|
|
164
|
+
* the customer applies at checkout on their next order, but it can be a unique code
|
|
165
|
+
* they use for other purposes like accessing an exclusive page on the merchant's website.
|
|
166
|
+
*/
|
|
167
|
+
code: string;
|
|
168
|
+
/**
|
|
169
|
+
* The fulfillment status of the reward fulfillment, indicating whether the reward is available to the customer.
|
|
170
|
+
*/
|
|
171
|
+
fulfillmentStatus: RewardFulfillmentStatus;
|
|
172
|
+
/**
|
|
173
|
+
* Date and time at which the code associated with the reward fulfillment expires
|
|
174
|
+
* and is no longer valid. If empty, the code does not expire.
|
|
175
|
+
*/
|
|
176
|
+
expiresAt: string | null;
|
|
177
|
+
/** The reward fulfillment's image. */
|
|
178
|
+
imageUrl: string | null;
|
|
179
|
+
/**
|
|
180
|
+
* Date and time at which the reward fulfillment was used by the customer. This
|
|
181
|
+
* field will be blank if the reward fulfillment has not yet been used, or if it
|
|
182
|
+
* does not support usage tracking.
|
|
183
|
+
*/
|
|
184
|
+
usedAt: string | null;
|
|
185
|
+
/** Date and time at which the reward fulfillment was created. */
|
|
186
|
+
createdAt: string;
|
|
187
|
+
/** Date and time at which the reward fulfillment was updated. */
|
|
188
|
+
updatedAt: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Reward object.
|
|
192
|
+
*
|
|
193
|
+
* A reward is the configuration for a type of coupon/discount/benefit/perk that can be issued to a customer.
|
|
194
|
+
*/
|
|
195
|
+
interface Reward {
|
|
196
|
+
/** The unique identifier of the reward. */
|
|
197
|
+
id: number;
|
|
198
|
+
/** The name of the reward. */
|
|
199
|
+
name: string;
|
|
200
|
+
/** A description of the reward. */
|
|
201
|
+
description: string | null;
|
|
202
|
+
/** An image for the reward. */
|
|
203
|
+
imageUrl: string | null;
|
|
204
|
+
/** Date and time at which the reward was created. */
|
|
205
|
+
createdAt: string;
|
|
206
|
+
/** Date and time at which the reward was updated. */
|
|
207
|
+
updatedAt: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Activity object.
|
|
211
|
+
*
|
|
212
|
+
* Activities represent actions performed by customers in the loyalty program.
|
|
213
|
+
* They are used to determine when rewards should be issued, track customer behavior,
|
|
214
|
+
* and personalize the customer experience.
|
|
215
|
+
*/
|
|
216
|
+
interface Activity {
|
|
217
|
+
/** The unique identifier of the activity. */
|
|
218
|
+
id: number;
|
|
219
|
+
/** The ID of the customer who performed the activity. */
|
|
220
|
+
customerId: number;
|
|
221
|
+
/** A token identifying the activity that was performed. */
|
|
222
|
+
token: string;
|
|
223
|
+
/** A unique identifier for the activity in the external system (e.g. the order number). */
|
|
224
|
+
distinctId: string | null;
|
|
225
|
+
/**
|
|
226
|
+
* The date and time the activity was performed by the customer in the external system (e.g. when
|
|
227
|
+
* the action actually occurred, which is often earlier than when the activity is created in Smile).
|
|
228
|
+
*/
|
|
229
|
+
createdOnOriginAt: string | null;
|
|
230
|
+
/** Date and time at which the activity was created in Smile. */
|
|
231
|
+
createdAt: string;
|
|
232
|
+
/** Date and time the activity was last updated in Smile. */
|
|
233
|
+
updatedAt: string;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Points purchase object.
|
|
237
|
+
*
|
|
238
|
+
* A points purchase is a record representing when a customer spends points on a reward.
|
|
239
|
+
* Much like spending money on a product results in an order, spending points on a points
|
|
240
|
+
* product results in a points purchase.
|
|
241
|
+
*/
|
|
242
|
+
interface PointsPurchase {
|
|
243
|
+
/** The unique identifier for the points purchase. */
|
|
244
|
+
id: number;
|
|
245
|
+
/** The unique identifier of the points product that was purchased. */
|
|
246
|
+
pointsProductId: number;
|
|
247
|
+
/** The total points spent by the customer. */
|
|
248
|
+
pointsSpent: number;
|
|
249
|
+
/**
|
|
250
|
+
* A nested Reward Fulfillment object representing the reward issued to the customer
|
|
251
|
+
* when they purchased the points product.
|
|
252
|
+
*/
|
|
253
|
+
rewardFulfillment: RewardFulfillment;
|
|
254
|
+
/** Date and time at which the points purchase was created. */
|
|
255
|
+
createdAt: string;
|
|
256
|
+
/** Date and time at which the points purchase was updated. */
|
|
257
|
+
updatedAt: string;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Options for purchasing a points product.
|
|
261
|
+
*/
|
|
262
|
+
interface PointsPurchaseOptions {
|
|
263
|
+
/**
|
|
264
|
+
* A positive integer representing the number of points that will be spent on the points
|
|
265
|
+
* product. Only applies when purchasing a points product whose `exchangeType` is
|
|
266
|
+
* `variable`, otherwise should be left blank.
|
|
267
|
+
*/
|
|
268
|
+
pointsToSpend?: number;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Points settings object.
|
|
272
|
+
*
|
|
273
|
+
* Configuration for the account's points program.
|
|
274
|
+
*/
|
|
275
|
+
interface PointsSetting {
|
|
276
|
+
/** The branding of the account's points currency. */
|
|
277
|
+
pointsLabel: {
|
|
278
|
+
/** The singular unit for a point. */
|
|
279
|
+
one: string;
|
|
280
|
+
/** The unit for zero or many points. */
|
|
281
|
+
other: string;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
declare const POINTS_SETTINGS_IDENTIFIER = "pointsSettings";
|
|
285
|
+
declare const POINTS_PRODUCTS_IDENTIFIER = "pointsProducts";
|
|
286
|
+
declare const REWARD_FULFILLMENTS_IDENTIFIER = "rewardFulfillments";
|
|
287
|
+
declare const CUSTOMER_POINTS_PRODUCTS_IDENTIFIER = "customerPointsProducts";
|
|
288
|
+
declare const CUSTOMER_VIP_STATUS_IDENTIFIER = "customerVipStatus";
|
|
289
|
+
declare const CUSTOMER_POINTS_WALLET_IDENTIFIER = "customerPointsWallet";
|
|
290
|
+
/**
|
|
291
|
+
* Resource keys for all objects that can be preloaded.
|
|
292
|
+
*/
|
|
293
|
+
type PreloadableIdentifier = typeof POINTS_SETTINGS_IDENTIFIER | typeof POINTS_PRODUCTS_IDENTIFIER | typeof REWARD_FULFILLMENTS_IDENTIFIER | typeof CUSTOMER_POINTS_PRODUCTS_IDENTIFIER | typeof CUSTOMER_VIP_STATUS_IDENTIFIER | typeof CUSTOMER_POINTS_WALLET_IDENTIFIER;
|
|
294
|
+
/**
|
|
295
|
+
* Resource keys for objects that require a logged-in customer to preload.
|
|
296
|
+
*/
|
|
297
|
+
type CustomerPreloadableIdentifier = typeof REWARD_FULFILLMENTS_IDENTIFIER | typeof CUSTOMER_POINTS_PRODUCTS_IDENTIFIER | typeof CUSTOMER_VIP_STATUS_IDENTIFIER | typeof CUSTOMER_POINTS_WALLET_IDENTIFIER;
|
|
298
|
+
/**
|
|
299
|
+
* Resource keys for objects that can be preloaded without a logged-in customer.
|
|
300
|
+
*/
|
|
301
|
+
type ProgramPreloadableIdentifier = typeof POINTS_SETTINGS_IDENTIFIER | typeof POINTS_PRODUCTS_IDENTIFIER;
|
|
302
|
+
/**
|
|
303
|
+
* Authentication credentials for preloading data from the API.
|
|
304
|
+
*/
|
|
305
|
+
interface PreloadCredentials {
|
|
306
|
+
/** The account's publishable key. */
|
|
307
|
+
publishableKey: string;
|
|
308
|
+
/** The customer token for customer-scoped requests (optional). */
|
|
309
|
+
customerToken: string | null;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Options for initializing the JavaScript SDK.
|
|
313
|
+
*/
|
|
314
|
+
interface SmileInitializeOptions {
|
|
315
|
+
publishableKey: string;
|
|
316
|
+
customerToken?: string | null;
|
|
317
|
+
preload?: PreloadableIdentifier[];
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Options for customer login.
|
|
321
|
+
*/
|
|
322
|
+
interface CustomerLoginOptions {
|
|
323
|
+
customerToken: string;
|
|
324
|
+
preload?: PreloadableIdentifier[];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Custom error class for API errors that includes HTTP status code and request ID.
|
|
329
|
+
*
|
|
330
|
+
* @extends Error
|
|
331
|
+
*/
|
|
332
|
+
declare class ApiError extends Error {
|
|
333
|
+
readonly status: number;
|
|
334
|
+
readonly requestId?: string;
|
|
335
|
+
constructor(message: string, status: number, requestId?: string);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
interface ActivityCreateOptions {
|
|
339
|
+
token: string;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Optional configuration object for formatting points.
|
|
344
|
+
*/
|
|
345
|
+
interface FormatPointsOptions {
|
|
346
|
+
/**
|
|
347
|
+
* A boolean value specifying whether the loyalty program's points label should be included in the returned string.
|
|
348
|
+
* Defaults to `true` if not specified.
|
|
349
|
+
*/
|
|
350
|
+
showPointsLabel?: boolean;
|
|
351
|
+
/**
|
|
352
|
+
* A string that will be included before the loyalty program's points label in the returned string.
|
|
353
|
+
* Defaults to an empty string if not specified.
|
|
354
|
+
*/
|
|
355
|
+
pointsLabelPrefix?: string;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Valid SDK format types for how the SDK was loaded.
|
|
360
|
+
*/
|
|
361
|
+
type SdkFormat = "esm" | "cjs" | "umd";
|
|
362
|
+
/**
|
|
363
|
+
* SDK information for debugging how the SDK was loaded.
|
|
364
|
+
*/
|
|
365
|
+
interface SdkInfo {
|
|
366
|
+
/** The module format used to load the SDK (`esm`, `cjs`, or `umd`). */
|
|
367
|
+
format: SdkFormat;
|
|
368
|
+
/** The NPM package version if loaded via NPM, or empty string if not. */
|
|
369
|
+
npmVersion: string;
|
|
370
|
+
/** The git SHA of the build. */
|
|
371
|
+
sha: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Loader info set by the NPM package for the UMD bundle to consume.
|
|
375
|
+
*/
|
|
376
|
+
type NpmLoaderInfo = Pick<SdkInfo, "format" | "npmVersion">;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Public API interface for the Smile SDK.
|
|
380
|
+
*
|
|
381
|
+
* Defines the complete public API surface that consumers can rely on.
|
|
382
|
+
* All methods and properties in this interface represent the stable, documented API.
|
|
383
|
+
*/
|
|
384
|
+
interface SmileInterface {
|
|
385
|
+
initialize: (options: SmileInitializeOptions) => Promise<void>;
|
|
386
|
+
reset: () => void;
|
|
387
|
+
activities: {
|
|
388
|
+
create: (options: ActivityCreateOptions) => Promise<Activity>;
|
|
389
|
+
};
|
|
390
|
+
customer: {
|
|
391
|
+
current: () => Customer | null;
|
|
392
|
+
login: (options: CustomerLoginOptions) => Promise<void>;
|
|
393
|
+
logout: () => void;
|
|
394
|
+
};
|
|
395
|
+
customerPointsProducts: {
|
|
396
|
+
get: () => Promise<CustomerPointsProduct[]>;
|
|
397
|
+
preloaded: () => CustomerPointsProduct[] | null;
|
|
398
|
+
};
|
|
399
|
+
customerPointsWallet: {
|
|
400
|
+
get: () => Promise<CustomerPointsWallet>;
|
|
401
|
+
preloaded: () => CustomerPointsWallet | null;
|
|
402
|
+
};
|
|
403
|
+
customerVipStatus: {
|
|
404
|
+
get: () => Promise<CustomerVipStatus>;
|
|
405
|
+
preloaded: () => CustomerVipStatus | null;
|
|
406
|
+
};
|
|
407
|
+
formatPoints: (pointsAmount: number, options?: FormatPointsOptions) => string;
|
|
408
|
+
pointsProducts: {
|
|
409
|
+
get: () => Promise<PointsProduct[]>;
|
|
410
|
+
getById: (id: number) => Promise<PointsProduct>;
|
|
411
|
+
preloaded: () => PointsProduct[] | null;
|
|
412
|
+
purchase: (id: number, options?: PointsPurchaseOptions) => Promise<PointsPurchase>;
|
|
413
|
+
};
|
|
414
|
+
pointsSettings: {
|
|
415
|
+
get: () => Promise<PointsSetting>;
|
|
416
|
+
preloaded: () => PointsSetting | null;
|
|
417
|
+
};
|
|
418
|
+
preload: (preloadableIdentifiers: PreloadableIdentifier[]) => Promise<void>;
|
|
419
|
+
rewardFulfillments: {
|
|
420
|
+
get: () => Promise<RewardFulfillment[]>;
|
|
421
|
+
preloaded: () => RewardFulfillment[] | null;
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
declare const NPM_LOADER_INFO_KEY = "__SMILE_SDK_LOADER_INFO";
|
|
426
|
+
declare global {
|
|
427
|
+
interface Window {
|
|
428
|
+
Smile?: SmileInterface;
|
|
429
|
+
[NPM_LOADER_INFO_KEY]?: NpmLoaderInfo;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Loads the Smile.js SDK from CDN and returns the initialized Smile instance.
|
|
434
|
+
*
|
|
435
|
+
* This function dynamically loads the SDK script and makes it available for use.
|
|
436
|
+
* Safe to call in server-side rendering contexts - returns `null` when `window` is undefined.
|
|
437
|
+
*
|
|
438
|
+
* @returns Promise that resolves to the Smile SDK instance, or `null` in non-browser environments.
|
|
439
|
+
* @throws Error if the build configuration is missing required environment variables.
|
|
440
|
+
* @example
|
|
441
|
+
* ```typescript
|
|
442
|
+
* const smile = await loadSmile();
|
|
443
|
+
* if (smile) {
|
|
444
|
+
* // Initialize the SDK
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function loadSmile(): Promise<SmileInterface | null>;
|
|
449
|
+
type Smile = SmileInterface;
|
|
450
|
+
|
|
451
|
+
export { ApiError, NPM_LOADER_INFO_KEY, loadSmile };
|
|
452
|
+
export type { Activity, ActivityCreateOptions, Customer, CustomerLoginOptions, CustomerPointsProduct, CustomerPointsWallet, CustomerPreloadableIdentifier, CustomerState, CustomerVipStatus, FormatPointsOptions, PointsProduct, PointsProductExchangeType, PointsPurchase, PointsPurchaseOptions, PointsSetting, PreloadCredentials, PreloadableIdentifier, ProgramPreloadableIdentifier, Reward, RewardFulfillment, Smile, SmileInitializeOptions, VipTierPartial };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class e extends Error{status;requestId;constructor(e,t,n){super(e),this.name="ApiError",this.status=t,this.requestId=n}}const t=/\/v\d[^/]*\//;let n=null;function r(e){return null!==n?n:(n=new Promise((n,r)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)try{const o=function(e){return document.querySelector(`script[src="${e}"]`)}(e),s=function(e){const n=Array.from(document.querySelectorAll('script[src^="https://toluakindele-smile-js.ngrok.io"]')),r=[];if(!e.match(t))return r;const o=e.split(t);if(2!==o.length)return r;const[s,i]=o;for(const o of n){const n=o.src||o.getAttribute("src")||"";n!==e&&n.startsWith(s)&&n.endsWith(i)&&t.test(n)&&r.push(o)}return r}(e);if(s.length>0){const t=s.map(e=>e.src).join(", ");return void r(new Error(`Version conflict detected. Multiple versions of Smile.js are present on the page (${t}, ${e}). Ensure only one version of the script exists on the page.`))}if(window.Smile&&o)return void n(window.Smile);const i=o||function(e){const t=document.createElement("script");t.src=e;const n=document.head||document.body;if(!n)throw new Error("Expected document.body not to be null. Smile.js requires a <body> element.");return n.appendChild(t),t}(e);i.addEventListener("load",()=>{window.Smile?n(window.Smile):r(new Error("Smile.js not available"))}),i.addEventListener("error",e=>{r(new Error("Failed to load Smile.js",{cause:e}))})}catch(e){r(e)}else n(null)}),n.catch(e=>(n=null,Promise.reject(e))))}const o="__SMILE_SDK_LOADER_INFO";exports.ApiError=e,exports.NPM_LOADER_INFO_KEY=o,exports.loadSmile=async function(){if("undefined"==typeof window)return null;const e=function(){const e="0.5.2",t=new URL("https://toluakindele-smile-js.ngrok.io/dist/index.js");return t.searchParams.set("format","cjs"),t.searchParams.set("version",e),window[o]={format:"cjs",npmVersion:e},t.toString()}(),t=await r(e);return t||null};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class e extends Error{status;requestId;constructor(e,t,n){super(e),this.name="ApiError",this.status=t,this.requestId=n}}const t=/\/v\d[^/]*\//;let n=null;function r(e){return null!==n?n:(n=new Promise((n,r)=>{if("undefined"!=typeof window&&"undefined"!=typeof document)try{const o=function(e){return document.querySelector(`script[src="${e}"]`)}(e),s=function(e){const n=Array.from(document.querySelectorAll('script[src^="https://toluakindele-smile-js.ngrok.io"]')),r=[];if(!e.match(t))return r;const o=e.split(t);if(2!==o.length)return r;const[s,i]=o;for(const o of n){const n=o.src||o.getAttribute("src")||"";n!==e&&n.startsWith(s)&&n.endsWith(i)&&t.test(n)&&r.push(o)}return r}(e);if(s.length>0){const t=s.map(e=>e.src).join(", ");return void r(new Error(`Version conflict detected. Multiple versions of Smile.js are present on the page (${t}, ${e}). Ensure only one version of the script exists on the page.`))}if(window.Smile&&o)return void n(window.Smile);const i=o||function(e){const t=document.createElement("script");t.src=e;const n=document.head||document.body;if(!n)throw new Error("Expected document.body not to be null. Smile.js requires a <body> element.");return n.appendChild(t),t}(e);i.addEventListener("load",()=>{window.Smile?n(window.Smile):r(new Error("Smile.js not available"))}),i.addEventListener("error",e=>{r(new Error("Failed to load Smile.js",{cause:e}))})}catch(e){r(e)}else n(null)}),n.catch(e=>(n=null,Promise.reject(e))))}const o="__SMILE_SDK_LOADER_INFO";async function s(){if("undefined"==typeof window)return null;const e=function(){const e="0.5.2",t=new URL("https://toluakindele-smile-js.ngrok.io/dist/index.js");return t.searchParams.set("format","esm"),t.searchParams.set("version",e),window[o]={format:"esm",npmVersion:e},t.toString()}(),t=await r(e);return t||null}export{e as ApiError,o as NPM_LOADER_INFO_KEY,s as loadSmile};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smile-io/smile-js",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"directory": "package"
|
|
7
|
+
},
|
|
8
|
+
"description": "Smile.io Javascript SDK (Smile.js)",
|
|
9
|
+
"license": "UNLICENSED",
|
|
10
|
+
"homepage": "https://dev.smile.io/js",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"Smile.io",
|
|
13
|
+
"Smile.js",
|
|
14
|
+
"JavaScript",
|
|
15
|
+
"TypeScript"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.bundled.d.ts",
|
|
20
|
+
"import": "./dist/index.esm.js",
|
|
21
|
+
"require": "./dist/index.cjs.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/index.cjs.js",
|
|
25
|
+
"module": "dist/index.esm.js",
|
|
26
|
+
"types": "dist/index.bundled.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"README.md",
|
|
29
|
+
"dist/index.bundled.d.ts",
|
|
30
|
+
"dist/index.cjs.js",
|
|
31
|
+
"dist/index.esm.js"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {}
|
|
37
|
+
}
|