@adhese/sdk 0.8.0 → 0.8.1

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/dist/index.js CHANGED
@@ -121,6 +121,56 @@ function createSafeFrame({
121
121
  dispose
122
122
  };
123
123
  }
124
+ const name = "@adhese/sdk";
125
+ const type = "module";
126
+ const version = "0.8.1";
127
+ const description = "Adhese SDK";
128
+ const license = "GPL-3.0";
129
+ const repository = {
130
+ type: "git",
131
+ url: "git+https://github.com/adhese/sdk_typescript.git"
132
+ };
133
+ const main = "./dist/index.cjs";
134
+ const module = "./dist/index.js";
135
+ const types = "./dist/index.d.ts";
136
+ const files = [
137
+ "LICENSE",
138
+ "README.md",
139
+ "dist"
140
+ ];
141
+ const scripts = {
142
+ dev: "vitest --config vite.config.npm.ts --silent",
143
+ "dev:verbose": "vitest --config vite.config.npm.ts",
144
+ test: "vitest --config vite.config.npm.ts --silent --run --coverage",
145
+ "test:verbose": "vitest --config vite.config.npm.ts --run --coverage",
146
+ build: "npm run build:npm && npm run build:standalone",
147
+ "build:npm": "vite build --config vite.config.npm.ts && tsup src/index.ts --dts-only --minify --format esm",
148
+ "build:standalone": "vite build --config vite.config.standalone.ts",
149
+ lint: "eslint . --ignore-pattern **/*.md/**/*",
150
+ "lint:fix": "eslint --fix . --ignore-pattern **/*.md/**/*",
151
+ clean: "rm -rf dist",
152
+ typecheck: "tsc --noEmit",
153
+ prepareRelease: "npm run build"
154
+ };
155
+ const dependencies = {
156
+ "@vue/runtime-core": "^3.4.21",
157
+ remeda: "^1.61.0",
158
+ zod: "^3.23.0"
159
+ };
160
+ const packageJson = {
161
+ name,
162
+ type,
163
+ version,
164
+ description,
165
+ license,
166
+ repository,
167
+ main,
168
+ module,
169
+ types,
170
+ files,
171
+ scripts,
172
+ dependencies
173
+ };
124
174
  function renderIframe(ad, element) {
125
175
  const iframe = document.createElement("iframe");
126
176
  iframe.srcdoc = `
@@ -199,6 +249,53 @@ function createQueryDetector({
199
249
  dispose
200
250
  };
201
251
  }
252
+ const hookMap = /* @__PURE__ */ new Map();
253
+ function clearAllHooks() {
254
+ hookMap.clear();
255
+ }
256
+ function createHook(name2, {
257
+ onRun,
258
+ onAdd
259
+ } = {}) {
260
+ hookMap.set(name2, /* @__PURE__ */ new Set());
261
+ const run = async (arg) => {
262
+ let latestResult = arg;
263
+ for (const callback of hookMap.get(name2) ?? [])
264
+ latestResult = await callback(latestResult) ?? latestResult;
265
+ onRun == null ? void 0 : onRun(hookMap.get(name2));
266
+ return latestResult;
267
+ };
268
+ function add(callback) {
269
+ const hookSet = hookMap.get(name2);
270
+ if (hookSet)
271
+ hookSet.add(callback);
272
+ else
273
+ hookMap.set(name2, /* @__PURE__ */ new Set([callback]));
274
+ onAdd == null ? void 0 : onAdd(hookSet);
275
+ return () => {
276
+ var _a;
277
+ (_a = hookMap.get(name2)) == null ? void 0 : _a.delete(callback);
278
+ };
279
+ }
280
+ return [run, add];
281
+ }
282
+ let resolveOnInitPromise = () => {
283
+ };
284
+ let isInit = false;
285
+ const waitOnInit = new Promise((resolve) => {
286
+ resolveOnInitPromise = resolve;
287
+ });
288
+ const [runOnInit, onInit] = createHook("onInit", {
289
+ onRun(callbacks) {
290
+ isInit = true;
291
+ resolveOnInitPromise();
292
+ callbacks == null ? void 0 : callbacks.clear();
293
+ },
294
+ onAdd() {
295
+ if (isInit)
296
+ runOnInit().catch(console.error);
297
+ }
298
+ });
202
299
  const defaultLogLevels = ["trace", "debug", "info", "warn", "error"];
203
300
  function createLogger({
204
301
  scope,
@@ -272,54 +369,6 @@ function createLogger({
272
369
  const logger = createLogger({
273
370
  scope: "Adhese SDK"
274
371
  });
275
- const hookMap = /* @__PURE__ */ new Map();
276
- function clearAllHooks() {
277
- hookMap.clear();
278
- }
279
- function createHook(name, {
280
- onRun,
281
- onAdd
282
- } = {}) {
283
- hookMap.set(name, /* @__PURE__ */ new Set());
284
- const run = async (arg) => {
285
- let latestResult = arg;
286
- for (const callback of hookMap.get(name) ?? [])
287
- latestResult = await callback(latestResult) ?? latestResult;
288
- onRun == null ? void 0 : onRun(hookMap.get(name));
289
- return latestResult;
290
- };
291
- function add(callback) {
292
- const hookSet = hookMap.get(name);
293
- if (hookSet)
294
- hookSet.add(callback);
295
- else
296
- hookMap.set(name, /* @__PURE__ */ new Set([callback]));
297
- onAdd == null ? void 0 : onAdd(hookSet);
298
- return () => {
299
- var _a;
300
- (_a = hookMap.get(name)) == null ? void 0 : _a.delete(callback);
301
- };
302
- }
303
- return [run, add];
304
- }
305
- let resolveOnInitPromise = () => {
306
- };
307
- let isInit = false;
308
- const waitOnInit = new Promise((resolve) => {
309
- resolveOnInitPromise = resolve;
310
- });
311
- const [runOnInit, onInit] = createHook("onInit", {
312
- onRun(callbacks) {
313
- isInit = true;
314
- resolveOnInitPromise();
315
- logger.debug("Initialization completed");
316
- callbacks == null ? void 0 : callbacks.clear();
317
- },
318
- onAdd() {
319
- if (isInit)
320
- runOnInit().catch(logger.error);
321
- }
322
- });
323
372
  const [runOnRequest, onRequest] = createHook("onRequest");
324
373
  const [runOnResponse, onResponse] = createHook("onResponse");
325
374
  const numberLike = union([coerce.string().regex(/^\d+$/), literal("")]).transform((value) => value === "" ? void 0 : Number(value));
@@ -615,7 +664,7 @@ async function requestAd({
615
664
  return ad;
616
665
  }
617
666
  const [runOnRender, onRender] = createHook("onRender");
618
- function useViewabilityObserver({ context, ad, name, element }) {
667
+ function useViewabilityObserver({ context, ad, name: name2, element }) {
619
668
  let timeoutId = null;
620
669
  const {
621
670
  threshold,
@@ -638,7 +687,7 @@ function useViewabilityObserver({ context, ad, name, element }) {
638
687
  timeoutId = null;
639
688
  if ((_a = ad.value) == null ? void 0 : _a.viewableImpressionCounter) {
640
689
  trackingPixel.value = addTrackingPixel(ad.value.viewableImpressionCounter);
641
- logger.debug(`Viewability tracking pixel fired for ${name.value}`);
690
+ logger.debug(`Viewability tracking pixel fired for ${name2.value}`);
642
691
  (_c = context.events) == null ? void 0 : _c.changeSlots.dispatch(Array.from(((_b = context.getAll) == null ? void 0 : _b.call(context)) ?? []));
643
692
  }
644
693
  }, duration);
@@ -728,8 +777,8 @@ function createSlot(options) {
728
777
  }
729
778
  const ad = ref(null);
730
779
  const originalAd = ref(ad.value);
731
- const name = computed(() => generateName(context.location, format.value, slot));
732
- watch(name, async (newName, oldName) => {
780
+ const name2 = computed(() => generateName(context.location, format.value, slot));
781
+ watch(name2, async (newName, oldName) => {
733
782
  var _a;
734
783
  if (newName === oldName)
735
784
  return;
@@ -775,7 +824,7 @@ function createSlot(options) {
775
824
  ] = useViewabilityObserver({
776
825
  context,
777
826
  ad,
778
- name,
827
+ name: name2,
779
828
  element
780
829
  });
781
830
  const impressionTrackingPixelElement = ref(null);
@@ -783,7 +832,7 @@ function createSlot(options) {
783
832
  async function requestAd$1() {
784
833
  const response = await requestAd({
785
834
  slot: {
786
- name: name.value,
835
+ name: name2.value,
787
836
  parameters
788
837
  },
789
838
  context
@@ -814,7 +863,7 @@ function createSlot(options) {
814
863
  }
815
864
  if (renderAd.impressionCounter && !impressionTrackingPixelElement.value) {
816
865
  impressionTrackingPixelElement.value = addTrackingPixel(renderAd.impressionCounter);
817
- logger.debug(`Impression tracking pixel fired for ${name.value}`);
866
+ logger.debug(`Impression tracking pixel fired for ${name2.value}`);
818
867
  }
819
868
  logger.debug("Slot rendered", {
820
869
  renderedElement: element,
@@ -851,7 +900,7 @@ function createSlot(options) {
851
900
  slot,
852
901
  parameters,
853
902
  format,
854
- name,
903
+ name: name2,
855
904
  ad,
856
905
  isViewabilityTracked,
857
906
  isImpressionTracked,
@@ -875,12 +924,12 @@ async function findDomSlots(context) {
875
924
  var _a;
876
925
  if (!element.dataset.format)
877
926
  return false;
878
- const name = generateName(
927
+ const name2 = generateName(
879
928
  context.location,
880
929
  element.dataset.format,
881
930
  element.dataset.slot
882
931
  );
883
- return !((_a = context.getAll) == null ? void 0 : _a.call(context).some((activeSlot) => activeSlot.name.value === name));
932
+ return !((_a = context.getAll) == null ? void 0 : _a.call(context).some((activeSlot) => activeSlot.name.value === name2));
884
933
  }).map((element) => createSlot({
885
934
  format: element.dataset.format,
886
935
  containingElement: element,
@@ -941,8 +990,8 @@ function createSlotManager({
941
990
  slots.set(slot.name.value, slot);
942
991
  return domSlots;
943
992
  }
944
- function get(name) {
945
- return slots.get(name);
993
+ function get(name2) {
994
+ return slots.get(name2);
946
995
  }
947
996
  function dispose() {
948
997
  for (const slot of slots.values())
@@ -1005,12 +1054,11 @@ let isDisposed = false;
1005
1054
  const [runOnDispose, onDispose] = createHook("onDispose", {
1006
1055
  onRun(callbacks) {
1007
1056
  isDisposed = true;
1008
- logger.debug("Disposal completed");
1009
1057
  callbacks == null ? void 0 : callbacks.clear();
1010
1058
  },
1011
1059
  onAdd() {
1012
1060
  if (isDisposed)
1013
- runOnDispose().catch(logger.error);
1061
+ runOnDispose().catch(console.error);
1014
1062
  }
1015
1063
  });
1016
1064
  function createAdhese(options) {
@@ -1046,7 +1094,13 @@ function createAdhese(options) {
1046
1094
  });
1047
1095
  for (const [index, plugin] of mergedOptions.plugins.entries()) {
1048
1096
  plugin(context, {
1049
- index
1097
+ index,
1098
+ version: packageJson.version,
1099
+ onInit,
1100
+ onDispose,
1101
+ onRender,
1102
+ onRequest,
1103
+ onResponse
1050
1104
  });
1051
1105
  }
1052
1106
  context.events = createEventManager();
@@ -1103,8 +1157,8 @@ function createAdhese(options) {
1103
1157
  function getAll() {
1104
1158
  return slotManager.getAll() ?? [];
1105
1159
  }
1106
- function get(name) {
1107
- return slotManager.get(name);
1160
+ function get(name2) {
1161
+ return slotManager.get(name2);
1108
1162
  }
1109
1163
  function addSlot(slotOptions) {
1110
1164
  if (!slotManager)
@@ -1212,11 +1266,6 @@ function createAdhese(options) {
1212
1266
  export {
1213
1267
  createAdhese,
1214
1268
  logger,
1215
- onDispose,
1216
- onInit,
1217
- onRender,
1218
- onRequest,
1219
- onResponse,
1220
1269
  requestAd,
1221
1270
  requestAds
1222
1271
  };