@adhese/sdk 0.14.0 → 0.15.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @adhese/sdk
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 467d857: Move SafeFrame code to a seperate plugin instead of including it
8
+
9
+ ## 0.14.1
10
+
11
+ ### Patch Changes
12
+
13
+ - eca8056: Move all vue-runtime-core exports to @adhese/sdk-shared
14
+ - Updated dependencies [eca8056]
15
+ - @adhese/sdk-shared@0.4.0
16
+
3
17
  ## 0.14.0
4
18
 
5
19
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1,62 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const sdkShared = require("@adhese/sdk-shared");
4
- const runtimeCore = require("@vue/runtime-core");
5
4
  const remeda = require("remeda");
6
- function createSafeFrame({
7
- renderFile,
8
- context
9
- }) {
10
- const safeFrame = window.$sf;
11
- if (!safeFrame)
12
- throw new Error("SafeFrame not found");
13
- const adhesePositions = /* @__PURE__ */ new Set();
14
- const config = new safeFrame.host.Config({
15
- auto: false,
16
- debug: context.debug,
17
- renderFile
18
- });
19
- function addPosition(ad, element) {
20
- var _a;
21
- if (!safeFrame)
22
- throw new Error("SafeFrame not found");
23
- const html = ad.ext === "js" && ad.body ? ad.body : ad.tag;
24
- if (typeof html !== "string")
25
- throw new Error("Ad tag is not a string");
26
- const elementId = element.id || `ad-${ad.id}-${sdkShared.uniqueId()}`;
27
- element.id = elementId;
28
- const position = new safeFrame.host.Position({
29
- id: elementId,
30
- html,
31
- src: ad.ext === "js" ? (_a = ad.swfSrc) == null ? void 0 : _a.href : void 0,
32
- config: new safeFrame.host.PosConfig({
33
- id: elementId,
34
- w: Number(ad.width),
35
- h: Number(ad.height),
36
- size: `${Number(ad.width)}x${Number(ad.height)}`,
37
- tgt: html.includes('target="_self"') ? "_self" : "_blank",
38
- dest: elementId
39
- })
40
- });
41
- adhesePositions.add(position);
42
- return position;
43
- }
44
- async function render(position) {
45
- if (!safeFrame)
46
- throw new Error("SafeFrame not found");
47
- safeFrame.host.render(position);
48
- }
49
- function dispose() {
50
- }
51
- return {
52
- config,
53
- addPosition,
54
- render,
55
- dispose
56
- };
57
- }
58
5
  const name = "@adhese/sdk";
59
- const version = "0.14.0";
6
+ const version = "0.15.0";
60
7
  function renderIframe(ad, element) {
61
8
  const iframe = document.createElement("iframe");
62
9
  iframe.srcdoc = `
@@ -287,7 +234,7 @@ function requestWithPost({
287
234
  const payload = {
288
235
  ...options,
289
236
  slots: options.slots.map((slot) => ({
290
- slotname: runtimeCore.toValue(slot.name),
237
+ slotname: sdkShared.toValue(slot.name),
291
238
  parameters: parseParameters(slot.parameters)
292
239
  })),
293
240
  parameters: context.parameters && parseParameters(context.parameters)
@@ -302,7 +249,7 @@ function requestWithPost({
302
249
  });
303
250
  }
304
251
  async function requestWithGet({ context, slots }) {
305
- return fetch(new URL(`${context.options.host}/json/sl${slots.map((slot) => runtimeCore.toValue(slot.name)).join("/sl")}`), {
252
+ return fetch(new URL(`${context.options.host}/json/sl${slots.map((slot) => sdkShared.toValue(slot.name)).join("/sl")}`), {
306
253
  method: "GET",
307
254
  headers: {
308
255
  // eslint-disable-next-line ts/naming-convention
@@ -335,7 +282,7 @@ const runRequestAdsBatch = remeda.debounce(async (context) => {
335
282
  context
336
283
  });
337
284
  for (const { options, resolve } of batch.values()) {
338
- const ad = ads.find(({ slotName }) => runtimeCore.toValue(slotName) === runtimeCore.toValue(options.slot.name));
285
+ const ad = ads.find(({ slotName }) => sdkShared.toValue(slotName) === sdkShared.toValue(options.slot.name));
339
286
  if (ad)
340
287
  resolve(ad);
341
288
  else
@@ -350,7 +297,7 @@ const runRequestAdsBatch = remeda.debounce(async (context) => {
350
297
  async function requestAd(options) {
351
298
  const promise = new Promise(
352
299
  (resolve) => {
353
- batch.set(runtimeCore.toValue(options.slot.name), { options, resolve });
300
+ batch.set(sdkShared.toValue(options.slot.name), { options, resolve });
354
301
  }
355
302
  );
356
303
  await runRequestAdsBatch.call(options.context);
@@ -413,8 +360,8 @@ function useViewabilityObserver({ context, ad, name: name2, element }) {
413
360
  rootMargin: "0px",
414
361
  ...context.options.viewabilityTrackingOptions
415
362
  };
416
- const trackingPixel = runtimeCore.ref(null);
417
- const isTracked = runtimeCore.computed(() => Boolean(trackingPixel.value));
363
+ const trackingPixel = sdkShared.ref(null);
364
+ const isTracked = sdkShared.computed(() => Boolean(trackingPixel.value));
418
365
  const viewabilityObserver = new IntersectionObserver(([entry]) => {
419
366
  if (context.options.viewabilityTracking && !trackingPixel.value && ad) {
420
367
  const ratio = remeda.round(entry.intersectionRatio, 1);
@@ -446,7 +393,7 @@ function useViewabilityObserver({ context, ad, name: name2, element }) {
446
393
  viewabilityObserver.unobserve(newElement);
447
394
  };
448
395
  }
449
- runtimeCore.watch(element, observe);
396
+ sdkShared.watch(element, observe);
450
397
  observe(element.value);
451
398
  return [isTracked, () => {
452
399
  var _a;
@@ -456,7 +403,7 @@ function useViewabilityObserver({ context, ad, name: name2, element }) {
456
403
  }
457
404
  function useRenderIntersectionObserver({ options, element }) {
458
405
  var _a;
459
- const isInViewport = runtimeCore.ref(false);
406
+ const isInViewport = sdkShared.ref(false);
460
407
  const renderIntersectionObserver = new IntersectionObserver((entries) => {
461
408
  isInViewport.value = entries.some((entry) => entry.isIntersecting);
462
409
  }, {
@@ -473,7 +420,7 @@ function useRenderIntersectionObserver({ options, element }) {
473
420
  renderIntersectionObserver.unobserve(newElement);
474
421
  };
475
422
  }
476
- runtimeCore.watch(element, observe);
423
+ sdkShared.watch(element, observe);
477
424
  observe(element.value);
478
425
  return [isInViewport, () => {
479
426
  renderIntersectionObserver.disconnect();
@@ -497,22 +444,27 @@ function useSlotHooks({ setup }, slotContext, id) {
497
444
  }
498
445
  const renderFunctions = {
499
446
  iframe: renderIframe,
500
- inline: renderInline
447
+ inline: renderInline,
448
+ none: remeda.doNothing
501
449
  };
502
450
  function createSlot(slotOptions) {
503
- const scope = runtimeCore.effectScope();
451
+ const scope = sdkShared.effectScope();
452
+ const mergedOptions = {
453
+ renderMode: "iframe",
454
+ ...slotOptions
455
+ };
504
456
  return scope.run(() => {
505
- const slotContext = runtimeCore.ref(null);
506
- const options = runOnSlotCreate(slotOptions);
457
+ const slotContext = sdkShared.ref(null);
458
+ const options = runOnSlotCreate(mergedOptions);
507
459
  const id = sdkShared.uniqueId();
508
460
  const { runOnSlotRender, runOnDispose: runOnDispose2, runOnRequest: runOnRequest2 } = useSlotHooks(options, slotContext, id);
509
461
  const {
510
462
  containingElement,
511
463
  slot,
512
464
  context,
513
- renderMode = "iframe"
514
- } = options;
515
- const parameters = runtimeCore.reactive(new Map(Object.entries(options.parameters ?? {})));
465
+ renderMode
466
+ } = mergedOptions;
467
+ const parameters = sdkShared.reactive(new Map(Object.entries(options.parameters ?? {})));
516
468
  let queryDetector = null;
517
469
  if (typeof options.format !== "string") {
518
470
  queryDetector = createQueryDetector({
@@ -520,14 +472,14 @@ function createSlot(slotOptions) {
520
472
  queries: Object.fromEntries(options.format.map((item) => [item.format, item.query]))
521
473
  });
522
474
  }
523
- const format = runtimeCore.ref(queryDetector ? queryDetector.getQuery() : options.format);
475
+ const format = sdkShared.ref(queryDetector ? queryDetector.getQuery() : options.format);
524
476
  function onQueryChange(newFormat) {
525
477
  format.value = newFormat;
526
478
  }
527
- const ad = runtimeCore.ref(null);
528
- const originalAd = runtimeCore.ref(ad.value);
529
- const name2 = runtimeCore.computed(() => generateName(context.location, format.value, slot));
530
- runtimeCore.watch(name2, async (newName, oldName) => {
479
+ const ad = sdkShared.ref(null);
480
+ const originalAd = sdkShared.ref(ad.value);
481
+ const name2 = sdkShared.computed(() => generateName(context.location, format.value, slot));
482
+ sdkShared.watch(name2, async (newName, oldName) => {
531
483
  if (newName === oldName)
532
484
  return;
533
485
  const newAd = await requestAd$1();
@@ -536,8 +488,8 @@ function createSlot(slotOptions) {
536
488
  originalAd.value = newAd;
537
489
  });
538
490
  const isDomLoaded = useDomLoaded();
539
- const isDisposed2 = runtimeCore.ref(false);
540
- const element = runtimeCore.computed(
491
+ const isDisposed2 = sdkShared.ref(false);
492
+ const element = sdkShared.computed(
541
493
  () => {
542
494
  if (!(typeof containingElement === "string" || !containingElement))
543
495
  return containingElement;
@@ -550,14 +502,14 @@ function createSlot(slotOptions) {
550
502
  options,
551
503
  element
552
504
  });
553
- const status = runtimeCore.ref("initializing");
554
- runtimeCore.watch([ad, isInViewport], async ([newAd, newIsInViewport], [oldAd]) => {
505
+ const status = sdkShared.ref("initializing");
506
+ sdkShared.watch([ad, isInViewport], async ([newAd, newIsInViewport], [oldAd]) => {
555
507
  if ((!newAd || oldAd && remeda.isDeepEqual(newAd, oldAd)) && status.value === "rendered")
556
508
  return;
557
509
  if (newIsInViewport)
558
510
  await render(newAd ?? void 0);
559
511
  });
560
- runtimeCore.watch(isInViewport, (value) => {
512
+ sdkShared.watch(isInViewport, (value) => {
561
513
  var _a;
562
514
  (_a = options.onViewabilityChanged) == null ? void 0 : _a.call(options, value);
563
515
  });
@@ -570,8 +522,8 @@ function createSlot(slotOptions) {
570
522
  name: name2,
571
523
  element
572
524
  });
573
- const impressionTrackingPixelElement = runtimeCore.ref(null);
574
- const isImpressionTracked = runtimeCore.computed(() => Boolean(impressionTrackingPixelElement.value));
525
+ const impressionTrackingPixelElement = sdkShared.ref(null);
526
+ const isImpressionTracked = sdkShared.computed(() => Boolean(impressionTrackingPixelElement.value));
575
527
  async function requestAd$1() {
576
528
  status.value = "loading";
577
529
  await runOnRequest2();
@@ -610,12 +562,7 @@ function createSlot(slotOptions) {
610
562
  }
611
563
  if (context.debug)
612
564
  element.value.style.position = "relative";
613
- if (context.safeFrame && renderAd && renderMode === "iframe") {
614
- const position = context.safeFrame.addPosition(renderAd, element.value);
615
- await context.safeFrame.render(position);
616
- } else {
617
- renderFunctions[renderMode](renderAd, element.value);
618
- }
565
+ renderFunctions[renderMode](renderAd, element.value);
619
566
  if (renderAd.impressionCounter && !impressionTrackingPixelElement.value) {
620
567
  impressionTrackingPixelElement.value = addTrackingPixel(renderAd.impressionCounter);
621
568
  logger.debug(`Impression tracking pixel fired for ${name2.value}`);
@@ -658,7 +605,7 @@ function createSlot(slotOptions) {
658
605
  return;
659
606
  ad.value = await requestAd$1();
660
607
  });
661
- const state = runtimeCore.reactive({
608
+ const state = sdkShared.reactive({
662
609
  location: context.location ?? "",
663
610
  lazyLoading: options.lazyLoading ?? false,
664
611
  slot,
@@ -676,7 +623,7 @@ function createSlot(slotOptions) {
676
623
  request: requestAd$1,
677
624
  dispose
678
625
  });
679
- runtimeCore.watch(state, (newState) => {
626
+ sdkShared.watch(state, (newState) => {
680
627
  slotContext.value = newState;
681
628
  }, {
682
629
  deep: true,
@@ -686,7 +633,7 @@ function createSlot(slotOptions) {
686
633
  });
687
634
  }
688
635
  function useDomLoaded() {
689
- const isDomLoaded = runtimeCore.ref(false);
636
+ const isDomLoaded = sdkShared.ref(false);
690
637
  onInit(async () => {
691
638
  await sdkShared.waitForDomLoad();
692
639
  isDomLoaded.value = true;
@@ -828,7 +775,7 @@ const [runOnDispose, onDispose] = createSyncHook("onDispose", {
828
775
  }
829
776
  });
830
777
  function createAdhese(options) {
831
- const scope = runtimeCore.effectScope();
778
+ const scope = sdkShared.effectScope();
832
779
  return scope.run(() => {
833
780
  const mergedOptions = {
834
781
  host: `https://ads-${options.account}.adhese.com`,
@@ -841,14 +788,13 @@ function createAdhese(options) {
841
788
  consent: false,
842
789
  logReferrer: true,
843
790
  logUrl: true,
844
- safeFrame: false,
845
791
  eagerRendering: false,
846
792
  viewabilityTracking: true,
847
793
  plugins: [],
848
794
  ...options
849
795
  };
850
796
  setupLogging(mergedOptions);
851
- const context = runtimeCore.reactive({
797
+ const context = sdkShared.reactive({
852
798
  location: mergedOptions.location,
853
799
  consent: mergedOptions.consent,
854
800
  debug: mergedOptions.debug,
@@ -876,11 +822,7 @@ function createAdhese(options) {
876
822
  });
877
823
  }
878
824
  context.events = sdkShared.createEventManager();
879
- context.safeFrame = options.safeFrame ? createSafeFrame({
880
- renderFile: `${mergedOptions.poolHost}/sf/r.html`,
881
- context
882
- }) : void 0;
883
- runtimeCore.watch(() => context.location, (newLocation) => {
825
+ sdkShared.watch(() => context.location, (newLocation) => {
884
826
  var _a;
885
827
  (_a = context.events) == null ? void 0 : _a.locationChange.dispatch(newLocation);
886
828
  });
@@ -889,7 +831,7 @@ function createAdhese(options) {
889
831
  queries: mergedOptions.queries
890
832
  });
891
833
  context.parameters = createParameters(mergedOptions, queryDetector);
892
- runtimeCore.watch(
834
+ sdkShared.watch(
893
835
  () => context.parameters,
894
836
  (newParameters) => {
895
837
  var _a;
@@ -906,7 +848,7 @@ function createAdhese(options) {
906
848
  (_b = context.parameters) == null ? void 0 : _b.set("br", query);
907
849
  await fetchAllUnrenderedSlots();
908
850
  }
909
- runtimeCore.watch(() => context.consent, (newConsent) => {
851
+ sdkShared.watch(() => context.consent, (newConsent) => {
910
852
  var _a, _b;
911
853
  (_a = context.parameters) == null ? void 0 : _a.set("tl", newConsent ? "all" : "none");
912
854
  (_b = context.events) == null ? void 0 : _b.consentChange.dispatch(newConsent);
@@ -937,7 +879,7 @@ function createAdhese(options) {
937
879
  return domSlots;
938
880
  }
939
881
  context.findDomSlots = findDomSlots2;
940
- runtimeCore.watch(() => context.debug, async (newDebug) => {
882
+ sdkShared.watch(() => context.debug, async (newDebug) => {
941
883
  var _a, _b;
942
884
  if (newDebug) {
943
885
  logger.setMinLogLevelThreshold("debug");
@@ -1000,97 +942,5 @@ function createAdhese(options) {
1000
942
  return context;
1001
943
  });
1002
944
  }
1003
- Object.defineProperty(exports, "computed", {
1004
- enumerable: true,
1005
- get: () => runtimeCore.computed
1006
- });
1007
- Object.defineProperty(exports, "customRef", {
1008
- enumerable: true,
1009
- get: () => runtimeCore.customRef
1010
- });
1011
- Object.defineProperty(exports, "effectScope", {
1012
- enumerable: true,
1013
- get: () => runtimeCore.effectScope
1014
- });
1015
- Object.defineProperty(exports, "isProxy", {
1016
- enumerable: true,
1017
- get: () => runtimeCore.isProxy
1018
- });
1019
- Object.defineProperty(exports, "isReactive", {
1020
- enumerable: true,
1021
- get: () => runtimeCore.isReactive
1022
- });
1023
- Object.defineProperty(exports, "isReadonly", {
1024
- enumerable: true,
1025
- get: () => runtimeCore.isReadonly
1026
- });
1027
- Object.defineProperty(exports, "isRef", {
1028
- enumerable: true,
1029
- get: () => runtimeCore.isRef
1030
- });
1031
- Object.defineProperty(exports, "isShallow", {
1032
- enumerable: true,
1033
- get: () => runtimeCore.isShallow
1034
- });
1035
- Object.defineProperty(exports, "markRaw", {
1036
- enumerable: true,
1037
- get: () => runtimeCore.markRaw
1038
- });
1039
- Object.defineProperty(exports, "reactive", {
1040
- enumerable: true,
1041
- get: () => runtimeCore.reactive
1042
- });
1043
- Object.defineProperty(exports, "readonly", {
1044
- enumerable: true,
1045
- get: () => runtimeCore.readonly
1046
- });
1047
- Object.defineProperty(exports, "ref", {
1048
- enumerable: true,
1049
- get: () => runtimeCore.ref
1050
- });
1051
- Object.defineProperty(exports, "shallowReactive", {
1052
- enumerable: true,
1053
- get: () => runtimeCore.shallowReactive
1054
- });
1055
- Object.defineProperty(exports, "shallowReadonly", {
1056
- enumerable: true,
1057
- get: () => runtimeCore.shallowReadonly
1058
- });
1059
- Object.defineProperty(exports, "shallowRef", {
1060
- enumerable: true,
1061
- get: () => runtimeCore.shallowRef
1062
- });
1063
- Object.defineProperty(exports, "toRaw", {
1064
- enumerable: true,
1065
- get: () => runtimeCore.toRaw
1066
- });
1067
- Object.defineProperty(exports, "toRefs", {
1068
- enumerable: true,
1069
- get: () => runtimeCore.toRefs
1070
- });
1071
- Object.defineProperty(exports, "toValue", {
1072
- enumerable: true,
1073
- get: () => runtimeCore.toValue
1074
- });
1075
- Object.defineProperty(exports, "unref", {
1076
- enumerable: true,
1077
- get: () => runtimeCore.unref
1078
- });
1079
- Object.defineProperty(exports, "watch", {
1080
- enumerable: true,
1081
- get: () => runtimeCore.watch
1082
- });
1083
- Object.defineProperty(exports, "watchEffect", {
1084
- enumerable: true,
1085
- get: () => runtimeCore.watchEffect
1086
- });
1087
- Object.defineProperty(exports, "watchPostEffect", {
1088
- enumerable: true,
1089
- get: () => runtimeCore.watchPostEffect
1090
- });
1091
- Object.defineProperty(exports, "watchSyncEffect", {
1092
- enumerable: true,
1093
- get: () => runtimeCore.watchSyncEffect
1094
- });
1095
945
  exports.createAdhese = createAdhese;
1096
946
  //# sourceMappingURL=index.cjs.map