@repobit/dex-target 0.1.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/LICENSE.MD ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-present Bitdefender
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@bitdefender/dex-target`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ import Target from '@bitdefender/dex-target';
9
+
10
+ // TODO: DEMONSTRATE API
11
+ ```
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ export default class Target {
2
+ static urlParameters = this.getUrlParameters();
3
+ static cachedMboxes = new Map();
4
+ static _configMbox;
5
+ static controller = new AbortController();
6
+ // initialize the alloyProxy variable on the window
7
+ // this is a mirror of Adobe WebSDK's alloy
8
+ static {
9
+ if (!window.alloyProxy) {
10
+ function __alloy(...args) {
11
+ return new Promise((resolve, reject) => {
12
+ window.alloyProxy.q.push([resolve, reject, args]);
13
+ });
14
+ }
15
+ window.alloyProxy = __alloy;
16
+ window.alloyProxy.q = [];
17
+ }
18
+ this._configMbox = this.getOffers({ mboxNames: 'config-mbox' });
19
+ }
20
+ /** get an object containing all the url query parameters */
21
+ static getUrlParameters() {
22
+ const urlParams = new URLSearchParams(window.location.search);
23
+ const parameters = {};
24
+ urlParams.forEach((value, key) => {
25
+ parameters[key] = value;
26
+ });
27
+ return parameters;
28
+ }
29
+ static get configMbox() {
30
+ return this._configMbox;
31
+ }
32
+ /** add adobe_mc parameter at the end of the url */
33
+ static async appendVisitorIDsTo(url) {
34
+ if (url.includes('adobe_mc')) {
35
+ return url;
36
+ }
37
+ try {
38
+ return (await window.alloyProxy("appendIdentityToUrl", { url })).url;
39
+ }
40
+ catch (e) {
41
+ console.warn(e);
42
+ return url;
43
+ }
44
+ }
45
+ /** abort all the Target calls for casese where Target does not load */
46
+ static abort() {
47
+ this.controller.abort();
48
+ }
49
+ static async getOffers(param) {
50
+ if (this.controller.signal?.aborted) {
51
+ return {};
52
+ }
53
+ let { mboxNames } = param;
54
+ const { parameters, profileParameters } = param;
55
+ if (!Array.isArray(mboxNames)) {
56
+ mboxNames = [mboxNames];
57
+ }
58
+ const notRequestedMboxes = mboxNames.filter(mbox => !this.cachedMboxes.has(`${mbox}_${JSON.stringify(parameters)}`));
59
+ if (notRequestedMboxes.length) {
60
+ const notRequestedOffersCall = window.alloyProxy('sendEvent', {
61
+ decisionScopes: notRequestedMboxes,
62
+ data: {
63
+ "__adobe": {
64
+ "target": Object.assign({}, this.urlParameters, parameters ? parameters : {}, profileParameters ? profileParameters : {})
65
+ }
66
+ },
67
+ renderDecisions: true
68
+ });
69
+ notRequestedMboxes.forEach(mbox => {
70
+ const receivedMboxOfferCall = new Promise((resolve, reject) => {
71
+ notRequestedOffersCall.then(result => {
72
+ const mboxResult = result.propositions.find((offer) => offer.scope === mbox)?.items[0].data?.content;
73
+ resolve(mboxResult);
74
+ }).catch(e => {
75
+ reject(e);
76
+ });
77
+ this.controller.signal?.addEventListener("abort", reject);
78
+ });
79
+ this.cachedMboxes.set(`${mbox}_${JSON.stringify(parameters)}`, receivedMboxOfferCall);
80
+ });
81
+ }
82
+ const mboxesPromises = mboxNames.map(mboxName => this.cachedMboxes.get(`${mboxName}_${JSON.stringify(parameters)}`));
83
+ const resolvedMboxes = await Promise.allSettled(mboxesPromises);
84
+ const offersResult = mboxNames.reduce((acc, mboxName, index) => {
85
+ acc[mboxName] = resolvedMboxes[index].status === 'fulfilled' ? resolvedMboxes[index].value : undefined;
86
+ return acc;
87
+ }, {});
88
+ return mboxNames.length > 1 ? offersResult : offersResult[mboxNames[0]];
89
+ }
90
+ }
91
+ window.BD = window.BD || {};
92
+ window.BD.Target = Target;
93
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@repobit/dex-target",
3
+ "version": "0.1.0",
4
+ "description": "Client for Adobe Target",
5
+ "author": "Constantin Ioan Mihai <iconstantin@bitdefender.com>",
6
+ "homepage": "https://github.com/bitdefender/dex-core#readme",
7
+ "license": "ISC",
8
+ "main": "dist/index.js",
9
+ "directories": {
10
+ "src": "src",
11
+ "test": "__tests__"
12
+ },
13
+ "files": [
14
+ "lib"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/bitdefender/dex-core.git"
22
+ },
23
+ "scripts": {
24
+ "build": "tsc -p tsconfig.json",
25
+ "test": "jest --passWithNoTests"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/bitdefender/dex-core/issues"
29
+ },
30
+ "module": "dist/index.js",
31
+ "type": "module",
32
+ "types": "dist/index.d.ts",
33
+ "devDependencies": {
34
+ "@eslint/js": "^9.19.0",
35
+ "@stylistic/eslint-plugin": "^3.0.1",
36
+ "@types/jest": "^29.5.14",
37
+ "eslint": "^9.19.0",
38
+ "globals": "^15.14.0",
39
+ "jest": "^29.7.0",
40
+ "jiti": "^2.4.2",
41
+ "ts-jest": "^29.2.5",
42
+ "ts-node": "^10.9.2",
43
+ "typescript": "^5.7.3",
44
+ "typescript-eslint": "^8.23.0"
45
+ },
46
+ "gitHead": "17d7435f03d6e3310005cd91516e1f7533e04df3"
47
+ }