@inappstory/react-sdk 1.11.2 → 1.11.3

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.
@@ -2489,6 +2489,27 @@ const focusElementOnIOS = (input) => {
2489
2489
  // @ts-ignore
2490
2490
  const getNonce = () => ( true ? __webpack_require__.nc !== null && __webpack_require__.nc !== void 0 ? __webpack_require__.nc : "" : 0);
2491
2491
 
2492
+ ;// ../core/src/helpers/replaceAll.ts
2493
+ //Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
2494
+ function escapeRegExp(val) {
2495
+ return val.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
2496
+ }
2497
+ // replaceAll does not work in safari
2498
+ function replaceAll(val, match, replacement) {
2499
+ return String(val).replace(new RegExp(escapeRegExp(match), "g"), () => replacement);
2500
+ }
2501
+
2502
+ ;// ../core/src/helpers/internalFontNames.ts
2503
+
2504
+ const INTERNAL_FONT_FAMILY_NAMES = ["InternalPrimaryFont", "InternalSecondaryFont"];
2505
+ function applyInternalFontFamilyPrefix(text, prefix) {
2506
+ let result = text;
2507
+ for (const name of INTERNAL_FONT_FAMILY_NAMES) {
2508
+ result = replaceAll(result, name, `${prefix}${name}`);
2509
+ }
2510
+ return result;
2511
+ }
2512
+
2492
2513
  ;// ../core/src/helpers/isPassiveSupported.ts
2493
2514
  const isPassiveSupported = () => {
2494
2515
  let passiveSupported = false;
@@ -2994,16 +3015,6 @@ function defineValue(obj, key, val) {
2994
3015
  });
2995
3016
  }
2996
3017
 
2997
- ;// ../core/src/helpers/replaceAll.ts
2998
- //Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
2999
- function escapeRegExp(val) {
3000
- return val.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
3001
- }
3002
- // replaceAll does not work in safari
3003
- function replaceAll(val, match, replacement) {
3004
- return String(val).replace(new RegExp(escapeRegExp(match), "g"), () => replacement);
3005
- }
3006
-
3007
3018
  ;// ../core/src/helpers/sleep.ts
3008
3019
  const sleep = async (startAt, minTimeout = 300) => {
3009
3020
  return new Promise(resolve => {
@@ -3087,6 +3098,7 @@ function safeJson(input) {
3087
3098
 
3088
3099
 
3089
3100
 
3101
+
3090
3102
  ;// ../core/src/api/deviceDescriptor.ts
3091
3103
 
3092
3104
 
@@ -3306,10 +3318,13 @@ class Session {
3306
3318
  get imagePlaceholders() {
3307
3319
  return this._imagePlaceholders;
3308
3320
  }
3309
- get fontsResources() {
3310
- return this.resources.filter(resource => resource.type === "font-face");
3311
- }
3312
- constructor(sessionStore, sessionDto) {
3321
+ constructor(storyManager, sessionStore, sessionDto) {
3322
+ Object.defineProperty(this, "storyManager", {
3323
+ enumerable: true,
3324
+ configurable: true,
3325
+ writable: true,
3326
+ value: storyManager
3327
+ });
3313
3328
  Object.defineProperty(this, "sessionStore", {
3314
3329
  enumerable: true,
3315
3330
  configurable: true,
@@ -3370,12 +3385,19 @@ class Session {
3370
3385
  writable: true,
3371
3386
  value: void 0
3372
3387
  });
3388
+ Object.defineProperty(this, "fontsResources", {
3389
+ enumerable: true,
3390
+ configurable: true,
3391
+ writable: true,
3392
+ value: []
3393
+ });
3373
3394
  this.id = sessionDto.session.id;
3374
3395
  this.expireIn = sessionDto.session.expire_in;
3375
3396
  this.userKey = sessionDto.user_key || DEFAULT_USER_KEY;
3376
3397
  this.previewAspectRatio = sessionDto.preview_aspect_ratio;
3377
3398
  this.share = sessionDto.share;
3378
3399
  this.resources = this.getResources(sessionDto);
3400
+ this.fontsResources = this.applyFontsPrefix(this.resources.filter(resource => resource.type === "font-face"));
3379
3401
  this._textPlaceholders = this.mapTextPlaceholders(sessionDto.placeholders);
3380
3402
  this._imagePlaceholders = this.mapImagePlaceholders(sessionDto.image_placeholders);
3381
3403
  this.isAllowStatisticV2 = Boolean(sessionDto.is_allow_statistic_v2);
@@ -3383,6 +3405,14 @@ class Session {
3383
3405
  loadResources() {
3384
3406
  initAndLoadFonts(this.fontsResources);
3385
3407
  }
3408
+ getAllFontFamilies() {
3409
+ return [...new Set(this.fontsResources.map(fontResource => fontResource.family))];
3410
+ }
3411
+ applyFontsPrefix(fontsResources) {
3412
+ return fontsResources.map(fontResource => {
3413
+ return Object.assign(Object.assign({}, fontResource), { family: `${this.storyManager.config.fontsPrefix}${fontResource.family}` });
3414
+ });
3415
+ }
3386
3416
  getResources(sessionDto) {
3387
3417
  if (sessionDto.cache && Array.isArray(sessionDto.cache))
3388
3418
  return sessionDto.cache;
@@ -4460,6 +4490,9 @@ let StorySlide = (() => {
4460
4490
  html: ""
4461
4491
  });
4462
4492
  }
4493
+ applyFontsPrefix(prefix) {
4494
+ this._html = applyInternalFontFamilyPrefix(this._html, prefix);
4495
+ }
4463
4496
  updatePlaceholders(placeholders) {
4464
4497
  let slideHtml = this._html;
4465
4498
  for (const placeholder of placeholders)
@@ -4941,6 +4974,10 @@ let Story = (() => {
4941
4974
  setShareUrl(shareUrl) {
4942
4975
  this._shareUrl = shareUrl;
4943
4976
  }
4977
+ applyFontsPrefix(prefix) {
4978
+ for (const slide of this.slides)
4979
+ slide.applyFontsPrefix(prefix);
4980
+ }
4944
4981
  updatePlaceholders(placeholders) {
4945
4982
  if (!this.needPlaceholders)
4946
4983
  return;
@@ -9818,7 +9855,7 @@ class GameClientConfig {
9818
9855
  value: void 0
9819
9856
  });
9820
9857
  const storyManagerConfig = this.storyManager.config;
9821
- const sdkVersion = "1.11.2";
9858
+ const sdkVersion = "1.11.3";
9822
9859
  const placeholders = this.storyManager.rootStore.placeholderStore.placeholders;
9823
9860
  const session = this.storyManager.rootStore.sessionStore.session;
9824
9861
  this.sessionId = session.id;
@@ -14389,6 +14426,12 @@ let StoryManagerConfig = (() => {
14389
14426
  writable: true,
14390
14427
  value: (storyManagerConfig_runInitializers(this, __options_extraInitializers), null)
14391
14428
  });
14429
+ Object.defineProperty(this, "_fontsPrefix", {
14430
+ enumerable: true,
14431
+ configurable: true,
14432
+ writable: true,
14433
+ value: "_IAS"
14434
+ });
14392
14435
  this.update(configDto);
14393
14436
  this._isInited = true;
14394
14437
  }
@@ -14431,6 +14474,9 @@ let StoryManagerConfig = (() => {
14431
14474
  get anonymous() {
14432
14475
  return this._anonymous;
14433
14476
  }
14477
+ get fontsPrefix() {
14478
+ return this._fontsPrefix;
14479
+ }
14434
14480
  get options() {
14435
14481
  return this._options;
14436
14482
  }
@@ -14521,19 +14567,20 @@ let StoryManagerConfig = (() => {
14521
14567
  this._options = options;
14522
14568
  }
14523
14569
  update(configDto) {
14524
- var _b, _c, _d, _e, _f, _g;
14525
- this._appPackageId = (_b = configDto.appPackageId) !== null && _b !== void 0 ? _b : "";
14570
+ var _b, _c, _d, _e, _f, _g, _h;
14571
+ this._fontsPrefix = (_b = configDto.fontsPrefix) !== null && _b !== void 0 ? _b : "_IAS";
14572
+ this._appPackageId = (_c = configDto.appPackageId) !== null && _c !== void 0 ? _c : "";
14526
14573
  this._disableDeviceId = Boolean(configDto.disableDeviceId);
14527
14574
  this.setOptions(configDto.options);
14528
14575
  this.setApiKey(configDto.apiKey).catch(console.error);
14529
14576
  this.setAnonymous(configDto.anonymous);
14530
- this.setUserId((_c = configDto.userId) !== null && _c !== void 0 ? _c : "", configDto.userIdSign).catch(console.error);
14577
+ this.setUserId((_d = configDto.userId) !== null && _d !== void 0 ? _d : "", configDto.userIdSign).catch(console.error);
14531
14578
  this.setLang(configDto.lang).catch(console.error);
14532
- this.setTextPlaceholders((_d = configDto.placeholders) !== null && _d !== void 0 ? _d : {});
14533
- this.setImagePlaceholders((_e = configDto.imagePlaceholders) !== null && _e !== void 0 ? _e : {});
14534
- this.setTags((_f = configDto.tags) !== null && _f !== void 0 ? _f : []);
14579
+ this.setTextPlaceholders((_e = configDto.placeholders) !== null && _e !== void 0 ? _e : {});
14580
+ this.setImagePlaceholders((_f = configDto.imagePlaceholders) !== null && _f !== void 0 ? _f : {});
14581
+ this.setTags((_g = configDto.tags) !== null && _g !== void 0 ? _g : []);
14535
14582
  this.setDir(configDto.dir);
14536
- this._cache = configDto.cache ? Object.assign(Object.assign({}, configDto.cache), { prefetch: (_g = configDto.cache.prefetch) !== null && _g !== void 0 ? _g : true }) : null;
14583
+ this._cache = configDto.cache ? Object.assign(Object.assign({}, configDto.cache), { prefetch: (_h = configDto.cache.prefetch) !== null && _h !== void 0 ? _h : true }) : null;
14537
14584
  }
14538
14585
  mapTextPlaceholders(textPlaceholderDtos) {
14539
14586
  const textPlaceholders = [];
@@ -14640,6 +14687,9 @@ class NullStoryManagerConfig {
14640
14687
  get anonymous() {
14641
14688
  return false;
14642
14689
  }
14690
+ get fontsPrefix() {
14691
+ return "_IAS";
14692
+ }
14643
14693
  get options() {
14644
14694
  return {};
14645
14695
  }
@@ -15020,9 +15070,12 @@ let IamApi = (() => {
15020
15070
  });
15021
15071
  return response.data.messages;
15022
15072
  }
15023
- async fetchContext(messageIds) {
15073
+ async fetchContext({ needFetchStyles, messageIds }) {
15024
15074
  const response = await api.get("inappmessaging/message-context", {
15025
- params: { fields: "style,widgetsData", id: messageIds.join() }
15075
+ params: {
15076
+ fields: "widgetsData" + (needFetchStyles ? ",style" : ""),
15077
+ id: messageIds.join()
15078
+ }
15026
15079
  });
15027
15080
  return response.data;
15028
15081
  }
@@ -15517,6 +15570,9 @@ let IamMessageSlide = (() => {
15517
15570
  slideHtml = replaceAll(slideHtml, `{{nonce}}`, (_b = getNonce()) !== null && _b !== void 0 ? _b : "");
15518
15571
  return slideHtml;
15519
15572
  }
15573
+ applyFontsPrefix(prefix) {
15574
+ this._html = applyInternalFontFamilyPrefix(this._html, prefix);
15575
+ }
15520
15576
  updatePlaceholders(placeholders) {
15521
15577
  let slideHtml = this._html;
15522
15578
  for (const placeholder of placeholders)
@@ -15908,6 +15964,10 @@ let IamMessage = (() => {
15908
15964
  this._openTime = Date.now();
15909
15965
  return this._iterationId;
15910
15966
  }
15967
+ applyFontsPrefix(prefix) {
15968
+ for (const slide of this._slides)
15969
+ slide.applyFontsPrefix(prefix);
15970
+ }
15911
15971
  updatePlaceholders(placeholders) {
15912
15972
  for (const slide of this._slides)
15913
15973
  slide.updatePlaceholders(placeholders);
@@ -16749,6 +16809,7 @@ let IamReaderViewModel = (() => {
16749
16809
  this.emitCloseEvent(activeMessage);
16750
16810
  }
16751
16811
  async open(message, appearance) {
16812
+ message.applyFontsPrefix(this.storyManager.config.fontsPrefix);
16752
16813
  message.updatePlaceholders(this.storyManager.rootStore.placeholderStore.placeholders);
16753
16814
  if ((appearance === null || appearance === void 0 ? void 0 : appearance.zIndex) !== undefined) {
16754
16815
  message.appearanceOptions.zIndex = appearance.zIndex;
@@ -20060,11 +20121,11 @@ let IamStore = (() => {
20060
20121
  _IamStore__messages_accessor_storage.set(this, iamStore_runInitializers(this, __messages_initializers, __WEBPACK_EXTERNAL_MODULE_mobx_observable__.map()));
20061
20122
  _IamStore__isLoaded_accessor_storage.set(this, (iamStore_runInitializers(this, __messages_extraInitializers), iamStore_runInitializers(this, __isLoaded_initializers, false)));
20062
20123
  _IamStore__isLoading_accessor_storage.set(this, (iamStore_runInitializers(this, __isLoaded_extraInitializers), iamStore_runInitializers(this, __isLoading_initializers, false)));
20063
- Object.defineProperty(this, "_messageContext", {
20124
+ Object.defineProperty(this, "iamCSS", {
20064
20125
  enumerable: true,
20065
20126
  configurable: true,
20066
20127
  writable: true,
20067
- value: (iamStore_runInitializers(this, __isLoading_extraInitializers), null)
20128
+ value: (iamStore_runInitializers(this, __isLoading_extraInitializers), "")
20068
20129
  });
20069
20130
  }
20070
20131
  get messages() {
@@ -20076,9 +20137,6 @@ let IamStore = (() => {
20076
20137
  get isLoading() {
20077
20138
  return this._isLoading;
20078
20139
  }
20079
- get messageContext() {
20080
- return this._messageContext;
20081
- }
20082
20140
  async preload(params) {
20083
20141
  try {
20084
20142
  this._isLoaded = false;
@@ -20112,37 +20170,44 @@ let IamStore = (() => {
20112
20170
  }
20113
20171
  async fetchById(messageId) {
20114
20172
  await this.rootStore.sessionStore.open();
20115
- await this.fetchMessageContext({ messageIds: [messageId] });
20173
+ const messageContext = await this.fetchMessageContext({ messageIds: [messageId] });
20116
20174
  const messageDto = await this.iamApi.fetchById(messageId);
20117
- return this.createMessageByDto(messageDto);
20175
+ return this.createMessageByDto(messageDto, messageContext);
20118
20176
  }
20119
20177
  async fetchAll(params) {
20120
20178
  await this.rootStore.sessionStore.open();
20121
20179
  const config = this.rootStore.storyManagerConfigStore.config;
20122
20180
  const tags = params.tags ? params.tags : config.tags;
20123
20181
  const messageDtos = await this.iamApi.fetchAll({ tags: filterTags(tags), options: config.options });
20124
- await this.fetchMessageContext({ messageIds: messageDtos.map(message => message.id) });
20125
- return this.createMessagesByDtos(messageDtos);
20182
+ const messageContext = await this.fetchMessageContext({
20183
+ messageIds: messageDtos.map(message => message.id)
20184
+ });
20185
+ return this.createMessagesByDtos(messageDtos, messageContext);
20126
20186
  }
20127
20187
  async fetchMessageContext({ messageIds }) {
20128
20188
  await this.rootStore.sessionStore.open();
20129
- if (!this._messageContext)
20130
- this._messageContext = await this.iamApi.fetchContext(messageIds);
20189
+ const messageContextDto = await this.iamApi.fetchContext({
20190
+ needFetchStyles: !this.iamCSS,
20191
+ messageIds
20192
+ });
20193
+ if (!this.iamCSS && messageContextDto.style) {
20194
+ this.iamCSS = applyInternalFontFamilyPrefix(messageContextDto.style, this.rootStore.storyManagerConfigStore.config.fontsPrefix);
20195
+ }
20196
+ messageContextDto.style = this.iamCSS;
20197
+ return messageContextDto;
20131
20198
  }
20132
- createMessagesByDtos(messageDtos) {
20199
+ createMessagesByDtos(messageDtos, messageContext) {
20133
20200
  this._messages.clear();
20134
20201
  const messages = [];
20135
20202
  for (const messageDto of messageDtos) {
20136
- const message = this.createMessageByDto(messageDto);
20203
+ const message = this.createMessageByDto(messageDto, messageContext);
20137
20204
  messages.push(message);
20138
20205
  }
20139
20206
  return messages;
20140
20207
  }
20141
- createMessageByDto(messageDto) {
20142
- if (!this.messageContext)
20143
- throw new Error("[IAS]: IAM context not found");
20208
+ createMessageByDto(messageDto, messageContext) {
20144
20209
  const message = IamMessage.createByDto(messageDto);
20145
- const context = new IamMessageContext(messageDto.id, this.messageContext);
20210
+ const context = new IamMessageContext(messageDto.id, messageContext);
20146
20211
  message.setContext(context);
20147
20212
  if (!this._messages.has(message.id.toString()))
20148
20213
  this._messages.set(message.id.toString(), message);
@@ -20277,7 +20342,7 @@ let SessionStore = (() => {
20277
20342
  userIdSign: config.userIdSign,
20278
20343
  anonymous: config.anonymous
20279
20344
  });
20280
- const session = new Session(this, sessionDto);
20345
+ const session = new Session(this.storyManager, this, sessionDto);
20281
20346
  session.loadResources();
20282
20347
  this.updatePlaceholders(session);
20283
20348
  this._session = session;
@@ -20419,6 +20484,7 @@ let StoryStore = (() => {
20419
20484
  if (storiesById.has(storyDto.id))
20420
20485
  return storiesById.get(storyDto.id);
20421
20486
  const story = new Story(storyDto);
20487
+ story.applyFontsPrefix(this.storyManager.config.fontsPrefix);
20422
20488
  story.updatePlaceholders(this.rootStore.placeholderStore.placeholders);
20423
20489
  storiesById.set(storyDto.id, story);
20424
20490
  return story;
@@ -20502,6 +20568,7 @@ let StoryStore = (() => {
20502
20568
  story.setContext(storyContext);
20503
20569
  const storyDto = await this.storiesApi.fetchStorySlides({ id: story.id, feedSlug });
20504
20570
  story.setSlides((_b = storyDto.slides) !== null && _b !== void 0 ? _b : []);
20571
+ story.applyFontsPrefix(this.storyManager.config.fontsPrefix);
20505
20572
  story.updatePlaceholders(this.rootStore.placeholderStore.placeholders);
20506
20573
  await sleep(startAt);
20507
20574
  story.setCanBeShown(true);
@@ -20515,6 +20582,7 @@ let StoryStore = (() => {
20515
20582
  const storyDto = await this.storiesApi.fetchStory({ id: storyId, feedSlug, fetchShareUrl, once });
20516
20583
  const story = this.addStoryByDto(storyDto);
20517
20584
  story.setSlides((_b = storyDto.slides) !== null && _b !== void 0 ? _b : []);
20585
+ story.applyFontsPrefix(this.storyManager.config.fontsPrefix);
20518
20586
  story.updatePlaceholders(this.rootStore.placeholderStore.placeholders);
20519
20587
  return story;
20520
20588
  }
@@ -20522,6 +20590,7 @@ let StoryStore = (() => {
20522
20590
  if (this.storyCSS)
20523
20591
  return;
20524
20592
  this.storyCSS = await this.storiesApi.fetchStoryCSS();
20593
+ this.storyCSS = applyInternalFontFamilyPrefix(this.storyCSS, this.storyManager.config.fontsPrefix);
20525
20594
  }
20526
20595
  async fetchStoryContext({ id, feedSlug }) {
20527
20596
  const storyContextDto = await this.storiesApi.fetchStoryContext({
@@ -20906,7 +20975,7 @@ class UgcEditorStore {
20906
20975
  const session = await this.storyManager.rootStore.sessionStore.open();
20907
20976
  const ugcEditorConfigDto = await this.ugcEditorApi.fetchUgcEditorConfig();
20908
20977
  const storyManagerConfig = this.storyManager.config;
20909
- const sdkVersion = "1.11.2";
20978
+ const sdkVersion = "1.11.3";
20910
20979
  this._config = {
20911
20980
  sessionId: session.id,
20912
20981
  apiKey: storyManagerConfig.apiKey,
@@ -21366,11 +21435,11 @@ class StoryManager extends TypedEventEmitter {
21366
21435
  return deviceDescriptor.deviceId;
21367
21436
  }
21368
21437
  get sdkVersionName() {
21369
- const sdkVersionName = "1.11.2";
21438
+ const sdkVersionName = "1.11.3";
21370
21439
  return sdkVersionName || "0.0.0";
21371
21440
  }
21372
21441
  get sdkVersionCode() {
21373
- const sdkVersionCode = 11102;
21442
+ const sdkVersionCode = 11103;
21374
21443
  return sdkVersionCode ? parseInt(sdkVersionCode) : 0;
21375
21444
  }
21376
21445
  get lang() {
@@ -21434,7 +21503,7 @@ class StoryManager extends TypedEventEmitter {
21434
21503
  this.rootStore.storyManagerConfigStore.setConfig(configDto);
21435
21504
  }
21436
21505
  setUserAgent(userAgent) {
21437
- const sdkVersionCode = 11102;
21506
+ const sdkVersionCode = 11103;
21438
21507
  const buildVersion = sdkVersionCode ? parseInt(sdkVersionCode) : 0;
21439
21508
  // According to RFC5987, HTTP header values can legitimately be supplied using the ISO-8859-1 encoding.
21440
21509
  this._userAgent = `${userAgent} ${convertStrToLatin1(navigator.userAgent)}`;
@@ -29430,7 +29499,9 @@ const useStoryListImperativeHandle = (ref, storyListViewModel) => {
29430
29499
 
29431
29500
 
29432
29501
 
29502
+
29433
29503
  const StoryListWrapper = __WEBPACK_EXTERNAL_MODULE_react_forwardRef__((props, ref) => {
29504
+ const { storyManager } = useIASProvider();
29434
29505
  const cardOptions = props.sliderOptions.card;
29435
29506
  const favoriteCardOptions = props.sliderOptions.favoriteCard;
29436
29507
  const cardBorderOptions = cardOptions.border;
@@ -29486,7 +29557,7 @@ const StoryListWrapper = __WEBPACK_EXTERNAL_MODULE_react_forwardRef__((props, re
29486
29557
  : favoriteCardOptions.gap,
29487
29558
  "--storiesListCardUgcMaskColor": props.sliderOptions.ugcCard.mask.color,
29488
29559
  "--storiesListCardUgcMaskLinearGradient": composeCardMaskLinearGradient(props.sliderOptions.ugcCard.mask),
29489
- "--storiesListItemTitleFontFamily": "InternalPrimaryFont",
29560
+ "--storiesListItemTitleFontFamily": `${storyManager.config.fontsPrefix}InternalPrimaryFont`,
29490
29561
  "--storiesListItemTitleFont": cardOptions.title.font,
29491
29562
  "--storiesListItemTitlePadding": isNumeric(cardOptions.title.padding.toString())
29492
29563
  ? cardOptions.title.padding + "px"