@sitepulse/web 1.0.0 → 1.0.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.d.ts +2 -0
- package/dist/index.js +14 -3
- package/dist/index.mjs +14 -3
- package/dist/renderer.d.ts +1 -0
- package/dist/web-sdk/src/index.d.ts +2 -0
- package/dist/web-sdk/src/renderer.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export * from "./renderer";
|
|
|
4
4
|
export * from "./evaluator";
|
|
5
5
|
export interface SitePulseConfig {
|
|
6
6
|
siteId: string;
|
|
7
|
+
apiHost?: string;
|
|
7
8
|
endpointUrl?: string;
|
|
8
9
|
campaignsEndpointUrl?: string;
|
|
10
|
+
submissionsEndpointUrl?: string;
|
|
9
11
|
flushIntervalMs?: number;
|
|
10
12
|
autoTrack?: boolean;
|
|
11
13
|
autoFetchCampaigns?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1052,7 +1052,8 @@ function renderCampaignDOM(campaign, handlers = {}) {
|
|
|
1052
1052
|
const emailVal = entries.email || entries.email_address || entries.newsletter_email || null;
|
|
1053
1053
|
handlers.onSubmit?.(entries);
|
|
1054
1054
|
if (typeof fetch !== "undefined") {
|
|
1055
|
-
|
|
1055
|
+
const submitEndpoint = handlers.submissionsEndpointUrl || "/api/campaigns/submit";
|
|
1056
|
+
fetch(submitEndpoint, {
|
|
1056
1057
|
method: "POST",
|
|
1057
1058
|
headers: { "Content-Type": "application/json" },
|
|
1058
1059
|
body: JSON.stringify({
|
|
@@ -1456,9 +1457,18 @@ var SitePulseClient = class {
|
|
|
1456
1457
|
registeredCampaignTeardowns = [];
|
|
1457
1458
|
init(config) {
|
|
1458
1459
|
const isReinit = this.initialized;
|
|
1460
|
+
let inferredBase = "";
|
|
1461
|
+
if (typeof document !== "undefined" && document.currentScript?.src) {
|
|
1462
|
+
try {
|
|
1463
|
+
inferredBase = new URL(document.currentScript.src).origin;
|
|
1464
|
+
} catch {
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
const defaultHost = config.apiHost || inferredBase || (typeof window !== "undefined" && window.location.hostname === "localhost" && window.location.port === "3000" ? "" : "https://sitepulse-app-ten.vercel.app");
|
|
1459
1468
|
this.config = {
|
|
1460
|
-
endpointUrl: "/api/collect",
|
|
1461
|
-
campaignsEndpointUrl: "/api/campaigns/active",
|
|
1469
|
+
endpointUrl: defaultHost ? `${defaultHost}/api/collect` : "/api/collect",
|
|
1470
|
+
campaignsEndpointUrl: defaultHost ? `${defaultHost}/api/campaigns/active` : "/api/campaigns/active",
|
|
1471
|
+
submissionsEndpointUrl: defaultHost ? `${defaultHost}/api/campaigns/submit` : "/api/campaigns/submit",
|
|
1462
1472
|
flushIntervalMs: 5e3,
|
|
1463
1473
|
autoTrack: true,
|
|
1464
1474
|
autoFetchCampaigns: true,
|
|
@@ -1617,6 +1627,7 @@ var SitePulseClient = class {
|
|
|
1617
1627
|
campaignName: campaign.name
|
|
1618
1628
|
});
|
|
1619
1629
|
const dom = renderCampaignDOM(campaign, {
|
|
1630
|
+
submissionsEndpointUrl: handlers.submissionsEndpointUrl || this.config?.submissionsEndpointUrl,
|
|
1620
1631
|
onLinkClick: (url, eventName) => {
|
|
1621
1632
|
this.track("campaign_click", {
|
|
1622
1633
|
campaignId: campaign.id,
|
package/dist/index.mjs
CHANGED
|
@@ -1013,7 +1013,8 @@ function renderCampaignDOM(campaign, handlers = {}) {
|
|
|
1013
1013
|
const emailVal = entries.email || entries.email_address || entries.newsletter_email || null;
|
|
1014
1014
|
handlers.onSubmit?.(entries);
|
|
1015
1015
|
if (typeof fetch !== "undefined") {
|
|
1016
|
-
|
|
1016
|
+
const submitEndpoint = handlers.submissionsEndpointUrl || "/api/campaigns/submit";
|
|
1017
|
+
fetch(submitEndpoint, {
|
|
1017
1018
|
method: "POST",
|
|
1018
1019
|
headers: { "Content-Type": "application/json" },
|
|
1019
1020
|
body: JSON.stringify({
|
|
@@ -1417,9 +1418,18 @@ var SitePulseClient = class {
|
|
|
1417
1418
|
registeredCampaignTeardowns = [];
|
|
1418
1419
|
init(config) {
|
|
1419
1420
|
const isReinit = this.initialized;
|
|
1421
|
+
let inferredBase = "";
|
|
1422
|
+
if (typeof document !== "undefined" && document.currentScript?.src) {
|
|
1423
|
+
try {
|
|
1424
|
+
inferredBase = new URL(document.currentScript.src).origin;
|
|
1425
|
+
} catch {
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
const defaultHost = config.apiHost || inferredBase || (typeof window !== "undefined" && window.location.hostname === "localhost" && window.location.port === "3000" ? "" : "https://sitepulse-app-ten.vercel.app");
|
|
1420
1429
|
this.config = {
|
|
1421
|
-
endpointUrl: "/api/collect",
|
|
1422
|
-
campaignsEndpointUrl: "/api/campaigns/active",
|
|
1430
|
+
endpointUrl: defaultHost ? `${defaultHost}/api/collect` : "/api/collect",
|
|
1431
|
+
campaignsEndpointUrl: defaultHost ? `${defaultHost}/api/campaigns/active` : "/api/campaigns/active",
|
|
1432
|
+
submissionsEndpointUrl: defaultHost ? `${defaultHost}/api/campaigns/submit` : "/api/campaigns/submit",
|
|
1423
1433
|
flushIntervalMs: 5e3,
|
|
1424
1434
|
autoTrack: true,
|
|
1425
1435
|
autoFetchCampaigns: true,
|
|
@@ -1578,6 +1588,7 @@ var SitePulseClient = class {
|
|
|
1578
1588
|
campaignName: campaign.name
|
|
1579
1589
|
});
|
|
1580
1590
|
const dom = renderCampaignDOM(campaign, {
|
|
1591
|
+
submissionsEndpointUrl: handlers.submissionsEndpointUrl || this.config?.submissionsEndpointUrl,
|
|
1581
1592
|
onLinkClick: (url, eventName) => {
|
|
1582
1593
|
this.track("campaign_click", {
|
|
1583
1594
|
campaignId: campaign.id,
|
package/dist/renderer.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface CampaignActionHandlers {
|
|
|
14
14
|
onEventClick?: (eventName: string) => void;
|
|
15
15
|
onSubmit?: (formData: Record<string, string>) => void;
|
|
16
16
|
onClose?: () => void;
|
|
17
|
+
submissionsEndpointUrl?: string;
|
|
17
18
|
}
|
|
18
19
|
export declare function renderHeadingBlock(block: Extract<ContentBlock, {
|
|
19
20
|
type: "heading";
|
|
@@ -4,8 +4,10 @@ export * from "./renderer";
|
|
|
4
4
|
export * from "./evaluator";
|
|
5
5
|
export interface SitePulseConfig {
|
|
6
6
|
siteId: string;
|
|
7
|
+
apiHost?: string;
|
|
7
8
|
endpointUrl?: string;
|
|
8
9
|
campaignsEndpointUrl?: string;
|
|
10
|
+
submissionsEndpointUrl?: string;
|
|
9
11
|
flushIntervalMs?: number;
|
|
10
12
|
autoTrack?: boolean;
|
|
11
13
|
autoFetchCampaigns?: boolean;
|
|
@@ -14,6 +14,7 @@ export interface CampaignActionHandlers {
|
|
|
14
14
|
onEventClick?: (eventName: string) => void;
|
|
15
15
|
onSubmit?: (formData: Record<string, string>) => void;
|
|
16
16
|
onClose?: () => void;
|
|
17
|
+
submissionsEndpointUrl?: string;
|
|
17
18
|
}
|
|
18
19
|
export declare function renderHeadingBlock(block: Extract<ContentBlock, {
|
|
19
20
|
type: "heading";
|