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