@smartico/public-api 0.0.393 → 0.0.395

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartico/public-api",
3
- "version": "0.0.393",
3
+ "version": "0.0.395",
4
4
  "description": "Smartico public API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -42,6 +42,7 @@ export const prizeTransform = (items: RafflePrize[]): TRafflePrize[] => {
42
42
  name: item.public_meta.name,
43
43
  description: item.public_meta.description,
44
44
  image_url: item.public_meta.image_url,
45
+ custom_data: item.public_meta.custom_data,
45
46
  prizes_per_run: item.prizes_per_run,
46
47
  prizes_per_run_actual: item.prizes_per_run_actual,
47
48
  chances_to_win_perc: item.chances_to_win_perc,
@@ -157,6 +157,32 @@ const GAMES_API_URL = 'https://r-games-api.smr.vc';
157
157
  const AVATAR_DOMAIN = 'https://img{ENV_ID}.smr.vc';
158
158
  const DEFAULT_LANG_EN = 'EN';
159
159
 
160
+ const SMR_TO_CLOUDFRONT_DOMAINS: { [key: string]: string } = {
161
+ 'img.smr.vc': 'd1am61onjxtys8.cloudfront.net',
162
+ 'img3.smr.vc': 'd3dubbodzd2q05.cloudfront.net',
163
+ 'img4.smr.vc': 'dvm0p9vsezqr2.cloudfront.net',
164
+ 'img5.smr.vc': 'd3gen1ksvxhac8.cloudfront.net',
165
+ 'img6.smr.vc': 'db1kmyg7iufeo.cloudfront.net',
166
+ 'img7.smr.vc': 'd36om2g86xefo6.cloudfront.net',
167
+ 'img8.smr.vc': 'd2zme31v54n5pb.cloudfront.net',
168
+
169
+ 'static.smr.vc': 'dtt380pweilws.cloudfront.net',
170
+ 'static3.smr.vc': 'd1qt8ake8g4imn.cloudfront.net',
171
+ 'static4.smr.vc': 'd146b4m7rkvjkw.cloudfront.net',
172
+ 'static5.smr.vc': 'd3l7suk1kl9rwh.cloudfront.net',
173
+ 'static6.smr.vc': 'd121pfj16xdfcq.cloudfront.net',
174
+ 'static7.smr.vc': 'd21deilz814qgl.cloudfront.net',
175
+ 'static8.smr.vc': 'd1uffsroxjy2ku.cloudfront.net',
176
+ };
177
+
178
+ // Single combined matcher built once, so a call is one pass instead of one per domain.
179
+ const SMR_DOMAIN_REGEX = new RegExp(
180
+ Object.keys(SMR_TO_CLOUDFRONT_DOMAINS)
181
+ .map((d) => d.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
182
+ .join('|'),
183
+ 'g',
184
+ );
185
+
160
186
  interface Tracker {
161
187
  label_api_key: string;
162
188
  userPublicProps: any;
@@ -241,34 +267,22 @@ class SmarticoAPI {
241
267
  return value as T;
242
268
  }
243
269
 
244
- const domains = {
245
- 'img.smr.vc': 'd1am61onjxtys8.cloudfront.net',
246
- 'img3.smr.vc': 'd3dubbodzd2q05.cloudfront.net',
247
- 'img4.smr.vc': 'dvm0p9vsezqr2.cloudfront.net',
248
- 'img5.smr.vc': 'd3gen1ksvxhac8.cloudfront.net',
249
- 'img6.smr.vc': 'db1kmyg7iufeo.cloudfront.net',
250
- 'img7.smr.vc': 'd36om2g86xefo6.cloudfront.net',
251
- 'img8.smr.vc': 'd2zme31v54n5pb.cloudfront.net',
252
-
253
- 'static.smr.vc': 'dtt380pweilws.cloudfront.net',
254
- 'static3.smr.vc': 'd1qt8ake8g4imn.cloudfront.net',
255
- 'static4.smr.vc': 'd146b4m7rkvjkw.cloudfront.net',
256
- 'static5.smr.vc': 'd3l7suk1kl9rwh.cloudfront.net',
257
- 'static6.smr.vc': 'd121pfj16xdfcq.cloudfront.net',
258
- 'static7.smr.vc': 'd21deilz814qgl.cloudfront.net',
259
- 'static8.smr.vc': 'd1uffsroxjy2ku.cloudfront.net',
260
- }
270
+ const isString = typeof value === 'string';
271
+ const source = isString ? (value as string) : JSON.stringify(value);
261
272
 
262
- const escapeRegExp = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
273
+ const replaced = source.replace(SMR_DOMAIN_REGEX, (match) => SMR_TO_CLOUDFRONT_DOMAINS[match]);
263
274
 
264
- let replacedValue = typeof value === 'string' ? value : JSON.stringify(value);
275
+ // No domain matched: skip the JSON re-parse and return the input untouched.
276
+ if (replaced === source) {
277
+ return value as T;
278
+ }
265
279
 
266
- for (const [oldDomain, newDomain] of Object.entries(domains)) {
267
- replacedValue = replacedValue.replace(new RegExp(escapeRegExp(oldDomain), 'g'), newDomain);
280
+ if (isString) {
281
+ return replaced as T;
268
282
  }
269
283
 
270
284
  try {
271
- return typeof value === 'string' ? replacedValue as T : JSON.parse(replacedValue)
285
+ return JSON.parse(replaced);
272
286
  } catch (err) {
273
287
  return value as T;
274
288
  }
@@ -1402,6 +1402,11 @@ export interface TRafflePrize {
1402
1402
  description: string;
1403
1403
  /** URL of the image that represents the prize, 256x256px */
1404
1404
  image_url: string;
1405
+ /**
1406
+ * Custom data field set in the backoffice prize setup.
1407
+ * Can be used to build custom UI for gamification.
1408
+ */
1409
+ custom_data?: string;
1405
1410
  /**
1406
1411
  * The number of prizes available per run of the draw.
1407
1412
  * E.g. if the draw is run daily, this is the number of prizes available each day, for example 3 iPhones.