@croct/plug 0.18.1 → 0.19.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.
Files changed (48) hide show
  1. package/README.md +2 -1
  2. package/api/fetchContent.d.cts +1 -2
  3. package/api/fetchContent.d.ts +1 -2
  4. package/api/index.d.cts +1 -2
  5. package/api/index.d.ts +1 -2
  6. package/component.d.cts +1 -1
  7. package/component.d.ts +1 -1
  8. package/constants.cjs +1 -1
  9. package/constants.d.cts +1 -1
  10. package/constants.d.ts +1 -1
  11. package/constants.js +1 -1
  12. package/global.d.cjs +0 -0
  13. package/global.d.d.cts +30 -0
  14. package/global.d.d.ts +30 -0
  15. package/global.d.js +0 -0
  16. package/index.d.cts +2 -3
  17. package/index.d.ts +2 -3
  18. package/package.json +15 -2
  19. package/plug-Cf6SnDp4.d.cts +110 -0
  20. package/plug-DjUeWnq0.d.ts +110 -0
  21. package/plug.cjs +7 -4
  22. package/plug.d.cts +11 -77
  23. package/plug.d.ts +11 -77
  24. package/plug.js +7 -4
  25. package/plugin.d.cts +19 -39
  26. package/plugin.d.ts +19 -39
  27. package/plugins/autoTracking/index.cjs +148 -0
  28. package/plugins/autoTracking/index.d.cts +50 -0
  29. package/plugins/autoTracking/index.d.ts +50 -0
  30. package/plugins/autoTracking/index.js +124 -0
  31. package/plugins/autoTracking/structuredData.cjs +379 -0
  32. package/plugins/autoTracking/structuredData.d.cts +42 -0
  33. package/plugins/autoTracking/structuredData.d.ts +42 -0
  34. package/plugins/autoTracking/structuredData.js +353 -0
  35. package/plugins/globalVariable/index.cjs +64 -0
  36. package/plugins/globalVariable/index.d.cts +36 -0
  37. package/plugins/globalVariable/index.d.ts +36 -0
  38. package/plugins/globalVariable/index.js +40 -0
  39. package/{preview.cjs → plugins/preview/index.cjs} +2 -2
  40. package/{preview.d.ts → plugins/preview/index.d.cts} +14 -5
  41. package/{preview.d.cts → plugins/preview/index.d.ts} +14 -5
  42. package/{preview.js → plugins/preview/index.js} +2 -2
  43. package/sdk/index.d.cts +1 -1
  44. package/sdk/index.d.ts +1 -1
  45. package/playground.cjs +0 -166
  46. package/playground.d.cts +0 -64
  47. package/playground.d.ts +0 -64
  48. package/playground.js +0 -142
package/playground.cjs DELETED
@@ -1,166 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var playground_exports = {};
19
- __export(playground_exports, {
20
- PlaygroundPlugin: () => PlaygroundPlugin,
21
- factory: () => factory
22
- });
23
- module.exports = __toCommonJS(playground_exports);
24
- var import_error = require("@croct/sdk/error");
25
- var import_evaluatorFacade = require("@croct/sdk/facade/evaluatorFacade");
26
- var import_constants = require('./constants.cjs');
27
- const CONNECTION_PARAMETER = "__cplay";
28
- class PlaygroundPlugin {
29
- constructor(configuration) {
30
- this.sdkVersion = configuration.sdkVersion;
31
- this.appId = configuration.appId;
32
- this.connectionId = configuration.connectionId;
33
- this.tab = configuration.tab;
34
- this.contextFactory = configuration.contextFactory;
35
- this.storage = configuration.storage;
36
- this.eventSubscriber = configuration.eventSubscriber;
37
- this.cidAssigner = configuration.cidAssigner;
38
- this.tokenProvider = configuration.tokenProvider;
39
- this.logger = configuration.logger;
40
- }
41
- enable() {
42
- const connectionId = this.resolveConnectionId();
43
- if (connectionId === null) {
44
- return;
45
- }
46
- this.syncListener = () => this.cidAssigner.assignCid().then((cid) => {
47
- this.syncToken(connectionId, cid);
48
- }).catch((error) => {
49
- this.logger.warn(`Sync failed: ${(0, import_error.formatCause)(error)}`);
50
- });
51
- this.eventSubscriber.addListener("tokenChanged", this.syncListener);
52
- this.tab.addListener("urlChange", this.syncListener);
53
- return this.syncListener();
54
- }
55
- resolveConnectionId() {
56
- if (this.connectionId !== void 0) {
57
- this.logger.debug("Connection ID passed in configuration");
58
- return this.connectionId;
59
- }
60
- const url = new URL(this.tab.url);
61
- let connectionId = url.searchParams.get(CONNECTION_PARAMETER);
62
- if (connectionId === null || connectionId === "") {
63
- this.logger.debug("No connection ID found in URL");
64
- connectionId = this.storage.getItem("connectionId");
65
- this.logger.debug(
66
- connectionId !== null ? "Previous connection ID found" : "No previous connection ID found"
67
- );
68
- return connectionId;
69
- }
70
- this.logger.debug("Connection ID found in URL");
71
- this.storage.setItem("connectionId", connectionId);
72
- return connectionId;
73
- }
74
- disable() {
75
- if (this.syncListener !== void 0) {
76
- this.eventSubscriber.removeListener("tokenChanged", this.syncListener);
77
- this.tab.removeListener("urlChange", this.syncListener);
78
- delete this.syncListener;
79
- }
80
- }
81
- syncToken(connectionId, cid) {
82
- const iframe = document.createElement("iframe");
83
- iframe.setAttribute("src", import_constants.PLAYGROUND_CONNECT_URL);
84
- iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
85
- iframe.style.visibility = "hidden";
86
- iframe.style.opacity = "0";
87
- iframe.style.border = "0";
88
- iframe.style.width = "0";
89
- iframe.style.height = "0";
90
- const context = this.createContext();
91
- iframe.onload = () => {
92
- if (iframe.contentWindow === null) {
93
- if (document.body.contains(iframe)) {
94
- document.body.removeChild(iframe);
95
- }
96
- this.logger.warn("Sync handshake failed");
97
- return;
98
- }
99
- const listener = (event) => {
100
- if (event.origin !== import_constants.PLAYGROUND_ORIGIN || event.data !== connectionId) {
101
- return;
102
- }
103
- window.removeEventListener("message", listener);
104
- if (document.body.contains(iframe)) {
105
- document.body.removeChild(iframe);
106
- }
107
- this.logger.debug("Sync completed");
108
- };
109
- window.addEventListener("message", listener);
110
- const payload = {
111
- appId: this.appId,
112
- connectionId,
113
- sdkVersion: this.sdkVersion,
114
- tabId: this.tab.id,
115
- cid,
116
- token: this.tokenProvider.getToken()?.toString() ?? null,
117
- context
118
- };
119
- iframe.contentWindow.postMessage(payload, import_constants.PLAYGROUND_ORIGIN);
120
- this.logger.debug("Waiting for sync acknowledgment...");
121
- };
122
- this.logger.debug("Sync started");
123
- const connect = () => {
124
- document.body.appendChild(iframe);
125
- };
126
- if (document.body === null) {
127
- document.addEventListener("DOMContentLoaded", connect);
128
- } else {
129
- connect();
130
- }
131
- }
132
- createContext() {
133
- const { page, campaign, timeZone } = this.contextFactory.createContext();
134
- const context = {};
135
- if (page !== void 0) {
136
- context.page = page;
137
- }
138
- if (campaign !== void 0) {
139
- context.campaign = campaign;
140
- }
141
- if (timeZone !== void 0) {
142
- context.timeZone = timeZone;
143
- }
144
- return context;
145
- }
146
- }
147
- const factory = (props) => {
148
- const { sdk, options } = props;
149
- return new PlaygroundPlugin({
150
- sdkVersion: sdk.version,
151
- appId: sdk.appId,
152
- connectionId: options.connectionId,
153
- tab: sdk.tab,
154
- storage: sdk.getTabStorage(),
155
- tokenProvider: sdk.userTokenStore,
156
- cidAssigner: sdk.cidAssigner,
157
- contextFactory: new import_evaluatorFacade.TabContextFactory(sdk.tab),
158
- eventSubscriber: sdk.eventManager,
159
- logger: sdk.getLogger()
160
- });
161
- };
162
- // Annotate the CommonJS export names for ESM import in node:
163
- 0 && (module.exports = {
164
- PlaygroundPlugin,
165
- factory
166
- });
package/playground.d.cts DELETED
@@ -1,64 +0,0 @@
1
- import { CidAssigner } from '@croct/sdk/cid';
2
- import { ContextFactory } from '@croct/sdk/facade/evaluatorFacade';
3
- import { Campaign, Page } from '@croct/sdk/evaluator';
4
- import { Plugin, PluginFactory } from './plugin.cjs';
5
- import { SdkEventSubscriber } from './sdk/index.cjs';
6
- import { TokenProvider } from '@croct/sdk/token';
7
- import { Tab } from '@croct/sdk/tab';
8
- import { Logger } from '@croct/sdk/logging';
9
- import '@croct/sdk/facade/trackerFacade';
10
- import '@croct/sdk/facade/userFacade';
11
- import '@croct/sdk/facade/sessionFacade';
12
- import '@croct/sdk/eventManager';
13
- import '@croct/sdk/sdkEvents';
14
-
15
- type Configuration = {
16
- appId: string;
17
- connectionId?: string;
18
- sdkVersion: string;
19
- tab: Tab;
20
- contextFactory: ContextFactory;
21
- storage: Storage;
22
- eventSubscriber: SdkEventSubscriber;
23
- cidAssigner: CidAssigner;
24
- tokenProvider: TokenProvider;
25
- logger: Logger;
26
- };
27
- type SyncPayload = {
28
- appId: string;
29
- connectionId: string;
30
- sdkVersion: string;
31
- cid: string;
32
- tabId: string;
33
- token: string | null;
34
- context: {
35
- campaign?: Campaign;
36
- page?: Page;
37
- timezone?: string;
38
- };
39
- };
40
- declare class PlaygroundPlugin implements Plugin {
41
- private readonly sdkVersion;
42
- private readonly appId;
43
- private readonly connectionId?;
44
- private readonly tab;
45
- private readonly contextFactory;
46
- private readonly storage;
47
- private readonly eventSubscriber;
48
- private readonly cidAssigner;
49
- private readonly tokenProvider;
50
- private readonly logger;
51
- private syncListener?;
52
- constructor(configuration: Configuration);
53
- enable(): Promise<void> | void;
54
- private resolveConnectionId;
55
- disable(): Promise<void> | void;
56
- private syncToken;
57
- private createContext;
58
- }
59
- type Options = {
60
- connectionId?: string;
61
- };
62
- declare const factory: PluginFactory<Options>;
63
-
64
- export { type Configuration, type Options, PlaygroundPlugin, type SyncPayload, factory };
package/playground.d.ts DELETED
@@ -1,64 +0,0 @@
1
- import { CidAssigner } from '@croct/sdk/cid';
2
- import { ContextFactory } from '@croct/sdk/facade/evaluatorFacade';
3
- import { Campaign, Page } from '@croct/sdk/evaluator';
4
- import { Plugin, PluginFactory } from './plugin.js';
5
- import { SdkEventSubscriber } from './sdk/index.js';
6
- import { TokenProvider } from '@croct/sdk/token';
7
- import { Tab } from '@croct/sdk/tab';
8
- import { Logger } from '@croct/sdk/logging';
9
- import '@croct/sdk/facade/trackerFacade';
10
- import '@croct/sdk/facade/userFacade';
11
- import '@croct/sdk/facade/sessionFacade';
12
- import '@croct/sdk/eventManager';
13
- import '@croct/sdk/sdkEvents';
14
-
15
- type Configuration = {
16
- appId: string;
17
- connectionId?: string;
18
- sdkVersion: string;
19
- tab: Tab;
20
- contextFactory: ContextFactory;
21
- storage: Storage;
22
- eventSubscriber: SdkEventSubscriber;
23
- cidAssigner: CidAssigner;
24
- tokenProvider: TokenProvider;
25
- logger: Logger;
26
- };
27
- type SyncPayload = {
28
- appId: string;
29
- connectionId: string;
30
- sdkVersion: string;
31
- cid: string;
32
- tabId: string;
33
- token: string | null;
34
- context: {
35
- campaign?: Campaign;
36
- page?: Page;
37
- timezone?: string;
38
- };
39
- };
40
- declare class PlaygroundPlugin implements Plugin {
41
- private readonly sdkVersion;
42
- private readonly appId;
43
- private readonly connectionId?;
44
- private readonly tab;
45
- private readonly contextFactory;
46
- private readonly storage;
47
- private readonly eventSubscriber;
48
- private readonly cidAssigner;
49
- private readonly tokenProvider;
50
- private readonly logger;
51
- private syncListener?;
52
- constructor(configuration: Configuration);
53
- enable(): Promise<void> | void;
54
- private resolveConnectionId;
55
- disable(): Promise<void> | void;
56
- private syncToken;
57
- private createContext;
58
- }
59
- type Options = {
60
- connectionId?: string;
61
- };
62
- declare const factory: PluginFactory<Options>;
63
-
64
- export { type Configuration, type Options, PlaygroundPlugin, type SyncPayload, factory };
package/playground.js DELETED
@@ -1,142 +0,0 @@
1
- import { formatCause } from "@croct/sdk/error";
2
- import { TabContextFactory } from "@croct/sdk/facade/evaluatorFacade";
3
- import { PLAYGROUND_CONNECT_URL, PLAYGROUND_ORIGIN } from "./constants.js";
4
- const CONNECTION_PARAMETER = "__cplay";
5
- class PlaygroundPlugin {
6
- constructor(configuration) {
7
- this.sdkVersion = configuration.sdkVersion;
8
- this.appId = configuration.appId;
9
- this.connectionId = configuration.connectionId;
10
- this.tab = configuration.tab;
11
- this.contextFactory = configuration.contextFactory;
12
- this.storage = configuration.storage;
13
- this.eventSubscriber = configuration.eventSubscriber;
14
- this.cidAssigner = configuration.cidAssigner;
15
- this.tokenProvider = configuration.tokenProvider;
16
- this.logger = configuration.logger;
17
- }
18
- enable() {
19
- const connectionId = this.resolveConnectionId();
20
- if (connectionId === null) {
21
- return;
22
- }
23
- this.syncListener = () => this.cidAssigner.assignCid().then((cid) => {
24
- this.syncToken(connectionId, cid);
25
- }).catch((error) => {
26
- this.logger.warn(`Sync failed: ${formatCause(error)}`);
27
- });
28
- this.eventSubscriber.addListener("tokenChanged", this.syncListener);
29
- this.tab.addListener("urlChange", this.syncListener);
30
- return this.syncListener();
31
- }
32
- resolveConnectionId() {
33
- if (this.connectionId !== void 0) {
34
- this.logger.debug("Connection ID passed in configuration");
35
- return this.connectionId;
36
- }
37
- const url = new URL(this.tab.url);
38
- let connectionId = url.searchParams.get(CONNECTION_PARAMETER);
39
- if (connectionId === null || connectionId === "") {
40
- this.logger.debug("No connection ID found in URL");
41
- connectionId = this.storage.getItem("connectionId");
42
- this.logger.debug(
43
- connectionId !== null ? "Previous connection ID found" : "No previous connection ID found"
44
- );
45
- return connectionId;
46
- }
47
- this.logger.debug("Connection ID found in URL");
48
- this.storage.setItem("connectionId", connectionId);
49
- return connectionId;
50
- }
51
- disable() {
52
- if (this.syncListener !== void 0) {
53
- this.eventSubscriber.removeListener("tokenChanged", this.syncListener);
54
- this.tab.removeListener("urlChange", this.syncListener);
55
- delete this.syncListener;
56
- }
57
- }
58
- syncToken(connectionId, cid) {
59
- const iframe = document.createElement("iframe");
60
- iframe.setAttribute("src", PLAYGROUND_CONNECT_URL);
61
- iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
62
- iframe.style.visibility = "hidden";
63
- iframe.style.opacity = "0";
64
- iframe.style.border = "0";
65
- iframe.style.width = "0";
66
- iframe.style.height = "0";
67
- const context = this.createContext();
68
- iframe.onload = () => {
69
- if (iframe.contentWindow === null) {
70
- if (document.body.contains(iframe)) {
71
- document.body.removeChild(iframe);
72
- }
73
- this.logger.warn("Sync handshake failed");
74
- return;
75
- }
76
- const listener = (event) => {
77
- if (event.origin !== PLAYGROUND_ORIGIN || event.data !== connectionId) {
78
- return;
79
- }
80
- window.removeEventListener("message", listener);
81
- if (document.body.contains(iframe)) {
82
- document.body.removeChild(iframe);
83
- }
84
- this.logger.debug("Sync completed");
85
- };
86
- window.addEventListener("message", listener);
87
- const payload = {
88
- appId: this.appId,
89
- connectionId,
90
- sdkVersion: this.sdkVersion,
91
- tabId: this.tab.id,
92
- cid,
93
- token: this.tokenProvider.getToken()?.toString() ?? null,
94
- context
95
- };
96
- iframe.contentWindow.postMessage(payload, PLAYGROUND_ORIGIN);
97
- this.logger.debug("Waiting for sync acknowledgment...");
98
- };
99
- this.logger.debug("Sync started");
100
- const connect = () => {
101
- document.body.appendChild(iframe);
102
- };
103
- if (document.body === null) {
104
- document.addEventListener("DOMContentLoaded", connect);
105
- } else {
106
- connect();
107
- }
108
- }
109
- createContext() {
110
- const { page, campaign, timeZone } = this.contextFactory.createContext();
111
- const context = {};
112
- if (page !== void 0) {
113
- context.page = page;
114
- }
115
- if (campaign !== void 0) {
116
- context.campaign = campaign;
117
- }
118
- if (timeZone !== void 0) {
119
- context.timeZone = timeZone;
120
- }
121
- return context;
122
- }
123
- }
124
- const factory = (props) => {
125
- const { sdk, options } = props;
126
- return new PlaygroundPlugin({
127
- sdkVersion: sdk.version,
128
- appId: sdk.appId,
129
- connectionId: options.connectionId,
130
- tab: sdk.tab,
131
- storage: sdk.getTabStorage(),
132
- tokenProvider: sdk.userTokenStore,
133
- cidAssigner: sdk.cidAssigner,
134
- contextFactory: new TabContextFactory(sdk.tab),
135
- eventSubscriber: sdk.eventManager,
136
- logger: sdk.getLogger()
137
- });
138
- };
139
- export {
140
- PlaygroundPlugin,
141
- factory
142
- };