@adobe/alloy 2.34.2-beta.0 → 2.34.2-beta.2
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/alloy.js +36 -26
- package/dist/alloy.min.js +1 -1
- package/dist/types/browser/src/components/Personalization/dom-actions/scripts.d.ts +2 -2
- package/dist/types/browser/src/components/PushNotifications/index.d.ts +4 -4
- package/package.json +1 -1
- package/src/components/Personalization/dom-actions/appendHtml.js +3 -3
- package/src/components/Personalization/dom-actions/insertHtmlAfter.js +3 -3
- package/src/components/Personalization/dom-actions/insertHtmlBefore.js +3 -3
- package/src/components/Personalization/dom-actions/prependHtml.js +3 -3
- package/src/components/Personalization/dom-actions/scripts.js +21 -12
- package/src/components/PushNotifications/index.js +4 -4
- package/src/components/PushNotifications/request/makeSendPushSubscriptionRequest.js +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function is(element: any, tagName: any): boolean;
|
|
2
2
|
export function getInlineScripts(fragment: any): any[];
|
|
3
|
-
export function
|
|
3
|
+
export function getRemoteScripts(fragment: any): any[];
|
|
4
4
|
export function executeInlineScripts(parent: any, scripts: any): void;
|
|
5
|
-
export function executeRemoteScripts(
|
|
5
|
+
export function executeRemoteScripts(scripts: any): Promise<any[]>;
|
|
@@ -4,16 +4,16 @@ export default createPushNotifications;
|
|
|
4
4
|
*
|
|
5
5
|
* @param {Object} options
|
|
6
6
|
* @param {{ orgId: string, datastreamId: string, edgeDomain: string, edgeBasePath: string, pushNotifications: { vapidPublicKey: string, appId: string, trackingDatasetId: string }}} options.config
|
|
7
|
-
* @param {StorageCreator} options.createNamespacedStorage
|
|
8
7
|
* @param {EventManager} options.eventManager
|
|
9
8
|
* @param {Logger} options.logger
|
|
10
9
|
* @param {ConsentManager} options.consent
|
|
11
10
|
* @param {IdentityManager} options.identity
|
|
12
11
|
* @param {function(): string} options.getBrowser
|
|
13
12
|
* @param {EdgeRequestExecutor} options.sendEdgeNetworkRequest
|
|
13
|
+
* @param {PlatformServices} options.platformServices
|
|
14
14
|
* @returns {{ lifecycle: object, commands: { sendPushSubscription: object } }}
|
|
15
15
|
*/
|
|
16
|
-
declare function createPushNotifications({
|
|
16
|
+
declare function createPushNotifications({ eventManager, config, logger, consent, identity, getBrowser, sendEdgeNetworkRequest, platformServices, }: {
|
|
17
17
|
config: {
|
|
18
18
|
orgId: string;
|
|
19
19
|
datastreamId: string;
|
|
@@ -25,13 +25,13 @@ declare function createPushNotifications({ createNamespacedStorage, eventManager
|
|
|
25
25
|
trackingDatasetId: string;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
createNamespacedStorage: StorageCreator;
|
|
29
28
|
eventManager: EventManager;
|
|
30
29
|
logger: Logger;
|
|
31
30
|
consent: ConsentManager;
|
|
32
31
|
identity: IdentityManager;
|
|
33
32
|
getBrowser: () => string;
|
|
34
33
|
sendEdgeNetworkRequest: EdgeRequestExecutor;
|
|
34
|
+
platformServices: PlatformServices;
|
|
35
35
|
}): {
|
|
36
36
|
lifecycle: object;
|
|
37
37
|
commands: {
|
|
@@ -42,9 +42,9 @@ declare namespace createPushNotifications {
|
|
|
42
42
|
let namespace: string;
|
|
43
43
|
let configValidators: Function;
|
|
44
44
|
}
|
|
45
|
-
import type { StorageCreator } from '@adobe/alloy-core/utils/types.js';
|
|
46
45
|
import type { EventManager } from '@adobe/alloy-core/core/types.js';
|
|
47
46
|
import type { Logger } from '@adobe/alloy-core/core/types.js';
|
|
48
47
|
import type { ConsentManager } from '@adobe/alloy-core/core/consent/types.js';
|
|
49
48
|
import type { IdentityManager } from '@adobe/alloy-core/core/identity/types.js';
|
|
50
49
|
import type { EdgeRequestExecutor } from '@adobe/alloy-core/core/edgeNetwork/types.js';
|
|
50
|
+
import type { PlatformServices } from '@adobe/alloy-core/services';
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
executeInlineScripts,
|
|
19
19
|
executeRemoteScripts,
|
|
20
20
|
getInlineScripts,
|
|
21
|
-
|
|
21
|
+
getRemoteScripts,
|
|
22
22
|
} from "./scripts.js";
|
|
23
23
|
|
|
24
24
|
export default (container, html, decorateProposition) => {
|
|
@@ -26,7 +26,7 @@ export default (container, html, decorateProposition) => {
|
|
|
26
26
|
addNonceToInlineStyleElements(fragment);
|
|
27
27
|
const elements = getChildNodes(fragment);
|
|
28
28
|
const scripts = getInlineScripts(fragment);
|
|
29
|
-
const
|
|
29
|
+
const remoteScripts = getRemoteScripts(fragment);
|
|
30
30
|
|
|
31
31
|
loadImages(fragment);
|
|
32
32
|
|
|
@@ -38,5 +38,5 @@ export default (container, html, decorateProposition) => {
|
|
|
38
38
|
|
|
39
39
|
executeInlineScripts(container, scripts);
|
|
40
40
|
|
|
41
|
-
return executeRemoteScripts(
|
|
41
|
+
return executeRemoteScripts(remoteScripts);
|
|
42
42
|
};
|
|
@@ -15,7 +15,7 @@ import { loadImages } from "./images.js";
|
|
|
15
15
|
import addNonceToInlineStyleElements from "./addNonceToInlineStyleElements.js";
|
|
16
16
|
import {
|
|
17
17
|
getInlineScripts,
|
|
18
|
-
|
|
18
|
+
getRemoteScripts,
|
|
19
19
|
executeInlineScripts,
|
|
20
20
|
executeRemoteScripts,
|
|
21
21
|
} from "./scripts.js";
|
|
@@ -25,7 +25,7 @@ export default (container, html, decorateProposition) => {
|
|
|
25
25
|
addNonceToInlineStyleElements(fragment);
|
|
26
26
|
const elements = getChildNodes(fragment);
|
|
27
27
|
const scripts = getInlineScripts(fragment);
|
|
28
|
-
const
|
|
28
|
+
const remoteScripts = getRemoteScripts(fragment);
|
|
29
29
|
|
|
30
30
|
loadImages(fragment);
|
|
31
31
|
|
|
@@ -39,5 +39,5 @@ export default (container, html, decorateProposition) => {
|
|
|
39
39
|
|
|
40
40
|
executeInlineScripts(container, scripts);
|
|
41
41
|
|
|
42
|
-
return executeRemoteScripts(
|
|
42
|
+
return executeRemoteScripts(remoteScripts);
|
|
43
43
|
};
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
executeInlineScripts,
|
|
18
18
|
executeRemoteScripts,
|
|
19
19
|
getInlineScripts,
|
|
20
|
-
|
|
20
|
+
getRemoteScripts,
|
|
21
21
|
} from "./scripts.js";
|
|
22
22
|
|
|
23
23
|
export default (container, html, decorateProposition) => {
|
|
@@ -25,7 +25,7 @@ export default (container, html, decorateProposition) => {
|
|
|
25
25
|
addNonceToInlineStyleElements(fragment);
|
|
26
26
|
const elements = getChildNodes(fragment);
|
|
27
27
|
const scripts = getInlineScripts(fragment);
|
|
28
|
-
const
|
|
28
|
+
const remoteScripts = getRemoteScripts(fragment);
|
|
29
29
|
|
|
30
30
|
loadImages(fragment);
|
|
31
31
|
|
|
@@ -36,5 +36,5 @@ export default (container, html, decorateProposition) => {
|
|
|
36
36
|
|
|
37
37
|
executeInlineScripts(container, scripts);
|
|
38
38
|
|
|
39
|
-
return executeRemoteScripts(
|
|
39
|
+
return executeRemoteScripts(remoteScripts);
|
|
40
40
|
};
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
executeInlineScripts,
|
|
24
24
|
executeRemoteScripts,
|
|
25
25
|
getInlineScripts,
|
|
26
|
-
|
|
26
|
+
getRemoteScripts,
|
|
27
27
|
} from "./scripts.js";
|
|
28
28
|
|
|
29
29
|
export default (container, html, decorateProposition) => {
|
|
@@ -31,7 +31,7 @@ export default (container, html, decorateProposition) => {
|
|
|
31
31
|
addNonceToInlineStyleElements(fragment);
|
|
32
32
|
const elements = getChildNodes(fragment);
|
|
33
33
|
const scripts = getInlineScripts(fragment);
|
|
34
|
-
const
|
|
34
|
+
const remoteScripts = getRemoteScripts(fragment);
|
|
35
35
|
const { length } = elements;
|
|
36
36
|
let i = length - 1;
|
|
37
37
|
|
|
@@ -56,5 +56,5 @@ export default (container, html, decorateProposition) => {
|
|
|
56
56
|
|
|
57
57
|
executeInlineScripts(container, scripts);
|
|
58
58
|
|
|
59
|
-
return executeRemoteScripts(
|
|
59
|
+
return executeRemoteScripts(remoteScripts);
|
|
60
60
|
};
|
|
@@ -24,10 +24,24 @@ const getPromise = (url, script) => {
|
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
|
-
const loadScript = (
|
|
27
|
+
const loadScript = (source) => {
|
|
28
|
+
const url = getAttribute(source, SRC);
|
|
28
29
|
const script = document.createElement("script");
|
|
29
|
-
|
|
30
|
+
// Preserve all author-supplied attributes (class, type, data-*, etc.) so
|
|
31
|
+
// consumers relying on them keep working.
|
|
32
|
+
const { attributes } = source;
|
|
33
|
+
for (let i = 0; i < attributes.length; i += 1) {
|
|
34
|
+
const { name, value } = attributes[i];
|
|
35
|
+
script.setAttribute(name, value);
|
|
36
|
+
}
|
|
37
|
+
// Override invariants last so they can't be clobbered by the source element.
|
|
38
|
+
const nonce = getNonce();
|
|
39
|
+
if (nonce) {
|
|
40
|
+
script.setAttribute("nonce", nonce);
|
|
41
|
+
}
|
|
30
42
|
script.async = true;
|
|
43
|
+
// Assign load handlers after copying attributes so a copied inline
|
|
44
|
+
// onload/onerror attribute can't break load-completion tracking.
|
|
31
45
|
const promise = getPromise(url, script);
|
|
32
46
|
document.head.appendChild(script);
|
|
33
47
|
return promise;
|
|
@@ -70,7 +84,7 @@ export const getInlineScripts = (fragment) => {
|
|
|
70
84
|
return result;
|
|
71
85
|
};
|
|
72
86
|
|
|
73
|
-
export const
|
|
87
|
+
export const getRemoteScripts = (fragment) => {
|
|
74
88
|
const scripts = selectNodes(SCRIPT, fragment);
|
|
75
89
|
const result = [];
|
|
76
90
|
const { length } = scripts;
|
|
@@ -78,17 +92,12 @@ export const getRemoteScriptsUrls = (fragment) => {
|
|
|
78
92
|
for (let i = 0; i < length; i += 1) {
|
|
79
93
|
const element = scripts[i];
|
|
80
94
|
|
|
95
|
+
// isRemoteScript already requires a non-empty src attribute.
|
|
81
96
|
if (!isRemoteScript(element)) {
|
|
82
97
|
continue;
|
|
83
98
|
}
|
|
84
99
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!url) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
result.push(url);
|
|
100
|
+
result.push(element);
|
|
92
101
|
}
|
|
93
102
|
|
|
94
103
|
return result;
|
|
@@ -101,6 +110,6 @@ export const executeInlineScripts = (parent, scripts) => {
|
|
|
101
110
|
});
|
|
102
111
|
};
|
|
103
112
|
|
|
104
|
-
export const executeRemoteScripts = (
|
|
105
|
-
return Promise.all(
|
|
113
|
+
export const executeRemoteScripts = (scripts) => {
|
|
114
|
+
return Promise.all(scripts.map(loadScript));
|
|
106
115
|
};
|
|
@@ -10,11 +10,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
/** @import { StorageCreator } from '@adobe/alloy-core/utils/types.js' */
|
|
14
13
|
/** @import { EventManager, Logger } from '@adobe/alloy-core/core/types.js' */
|
|
15
14
|
/** @import { IdentityManager } from '@adobe/alloy-core/core/identity/types.js' */
|
|
16
15
|
/** @import { ConsentManager } from '@adobe/alloy-core/core/consent/types.js' */
|
|
17
16
|
/** @import { EdgeRequestExecutor } from '@adobe/alloy-core/core/edgeNetwork/types.js' */
|
|
17
|
+
/** @import { PlatformServices } from '@adobe/alloy-core/services' */
|
|
18
18
|
|
|
19
19
|
import { objectOf, string } from "@adobe/alloy-core/utils/validation";
|
|
20
20
|
import { sanitizeOrgIdForCookieName } from "@adobe/alloy-core/utils";
|
|
@@ -35,17 +35,16 @@ const isComponentConfigured = ({
|
|
|
35
35
|
*
|
|
36
36
|
* @param {Object} options
|
|
37
37
|
* @param {{ orgId: string, datastreamId: string, edgeDomain: string, edgeBasePath: string, pushNotifications: { vapidPublicKey: string, appId: string, trackingDatasetId: string }}} options.config
|
|
38
|
-
* @param {StorageCreator} options.createNamespacedStorage
|
|
39
38
|
* @param {EventManager} options.eventManager
|
|
40
39
|
* @param {Logger} options.logger
|
|
41
40
|
* @param {ConsentManager} options.consent
|
|
42
41
|
* @param {IdentityManager} options.identity
|
|
43
42
|
* @param {function(): string} options.getBrowser
|
|
44
43
|
* @param {EdgeRequestExecutor} options.sendEdgeNetworkRequest
|
|
44
|
+
* @param {PlatformServices} options.platformServices
|
|
45
45
|
* @returns {{ lifecycle: object, commands: { sendPushSubscription: object } }}
|
|
46
46
|
*/
|
|
47
47
|
const createPushNotifications = ({
|
|
48
|
-
createNamespacedStorage,
|
|
49
48
|
eventManager,
|
|
50
49
|
config,
|
|
51
50
|
logger,
|
|
@@ -53,6 +52,7 @@ const createPushNotifications = ({
|
|
|
53
52
|
identity,
|
|
54
53
|
getBrowser,
|
|
55
54
|
sendEdgeNetworkRequest,
|
|
55
|
+
platformServices,
|
|
56
56
|
}) => {
|
|
57
57
|
return {
|
|
58
58
|
lifecycle: {
|
|
@@ -92,7 +92,7 @@ const createPushNotifications = ({
|
|
|
92
92
|
},
|
|
93
93
|
} = config || {};
|
|
94
94
|
|
|
95
|
-
const storage = createNamespacedStorage(
|
|
95
|
+
const storage = platformServices.storage.createNamespacedStorage(
|
|
96
96
|
`${sanitizeOrgIdForCookieName(orgId)}.pushNotifications.`,
|
|
97
97
|
);
|
|
98
98
|
|
|
@@ -69,8 +69,9 @@ export default async ({
|
|
|
69
69
|
);
|
|
70
70
|
|
|
71
71
|
const cacheValue = `${ecid}${serializedPushSubscriptionDetails}`;
|
|
72
|
+
const storedValue = await storage.getItem(SUBSCRIPTION_DETAILS);
|
|
72
73
|
|
|
73
|
-
if (cacheValue ===
|
|
74
|
+
if (cacheValue === storedValue) {
|
|
74
75
|
logger.info(
|
|
75
76
|
"Subscription details have not changed. Not sending to the server.",
|
|
76
77
|
);
|