@tolinku/web-sdk 0.4.0 → 0.5.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/dist/index.js +40 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -24
- package/dist/index.mjs.map +1 -1
- package/dist/tolinku.min.js +20 -20
- package/dist/tolinku.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
// src/types.ts
|
|
4
|
+
var SDK_VERSION = "0.5.0";
|
|
5
|
+
|
|
3
6
|
// src/client.ts
|
|
4
7
|
var MAX_RETRIES = 3;
|
|
5
8
|
var BASE_DELAY_MS = 500;
|
|
@@ -170,6 +173,11 @@ var HttpClient = class {
|
|
|
170
173
|
headers() {
|
|
171
174
|
return {
|
|
172
175
|
"X-API-Key": this.apiKey,
|
|
176
|
+
// Which SDK and version made the call. The other Tolinku SDKs say this in
|
|
177
|
+
// User-Agent, which a browser will not let a script set, so it goes in a
|
|
178
|
+
// header of our own. Without it a web integration is unidentifiable in the
|
|
179
|
+
// field and a version-specific bug cannot be traced to a version.
|
|
180
|
+
"X-Tolinku-SDK": `web/${SDK_VERSION}`,
|
|
173
181
|
// Browsers default to "Accept: */*", which a server content-negotiating an
|
|
174
182
|
// error page reads as "HTML is fine". Saying so explicitly keeps an error
|
|
175
183
|
// parseable instead of arriving as a rendered page.
|
|
@@ -600,12 +608,12 @@ var Deferred = class {
|
|
|
600
608
|
try {
|
|
601
609
|
const link = await this.client.postPublic("/v1/api/deferred/claim-by-signals", {
|
|
602
610
|
appspace_id: options.appspaceId,
|
|
603
|
-
timezone: options.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
604
|
-
language: options.language || navigator.language,
|
|
605
|
-
screen_width: options.screenWidth || window.screen.width,
|
|
606
|
-
screen_height: options.screenHeight || window.screen.height,
|
|
611
|
+
timezone: override(options.timezone) || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
612
|
+
language: override(options.language) || navigator.language,
|
|
613
|
+
screen_width: override(options.screenWidth) || window.screen.width,
|
|
614
|
+
screen_height: override(options.screenHeight) || window.screen.height,
|
|
607
615
|
// Separates devices reporting identical logical dimensions.
|
|
608
|
-
device_pixel_ratio: options.devicePixelRatio || window.devicePixelRatio || 1
|
|
616
|
+
device_pixel_ratio: override(options.devicePixelRatio) || window.devicePixelRatio || 1
|
|
609
617
|
});
|
|
610
618
|
return { link, settled: true };
|
|
611
619
|
} catch (err) {
|
|
@@ -627,6 +635,30 @@ var Deferred = class {
|
|
|
627
635
|
}
|
|
628
636
|
}
|
|
629
637
|
};
|
|
638
|
+
function override(value) {
|
|
639
|
+
if (typeof value === "string") {
|
|
640
|
+
const trimmed = value.trim();
|
|
641
|
+
return trimmed === "" ? void 0 : trimmed;
|
|
642
|
+
}
|
|
643
|
+
if (typeof value === "number") {
|
|
644
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
645
|
+
}
|
|
646
|
+
return void 0;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/url-safety.ts
|
|
650
|
+
function isSafeUrl(url) {
|
|
651
|
+
if (typeof url !== "string") return false;
|
|
652
|
+
const trimmed = url.trim();
|
|
653
|
+
if (!trimmed) return false;
|
|
654
|
+
try {
|
|
655
|
+
const base = typeof window !== "undefined" ? window.location.href : void 0;
|
|
656
|
+
const parsed = new URL(trimmed, base);
|
|
657
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
658
|
+
} catch {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
630
662
|
|
|
631
663
|
// src/storage.ts
|
|
632
664
|
var BANNER_KEY = "tolinku_banner_dismissed";
|
|
@@ -745,14 +777,6 @@ function sanitizeClass(val) {
|
|
|
745
777
|
if (!val || typeof val !== "string") return "";
|
|
746
778
|
return val.replace(/[^a-zA-Z0-9_\-\s]/g, "").slice(0, 100).trim();
|
|
747
779
|
}
|
|
748
|
-
function isSafeUrl(url) {
|
|
749
|
-
try {
|
|
750
|
-
const parsed = new URL(url, window.location.href);
|
|
751
|
-
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
752
|
-
} catch {
|
|
753
|
-
return false;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
780
|
var Banners = class {
|
|
757
781
|
constructor(client) {
|
|
758
782
|
this.client = client;
|
|
@@ -1178,7 +1202,7 @@ var Messages = class {
|
|
|
1178
1202
|
}
|
|
1179
1203
|
case "Image": {
|
|
1180
1204
|
const url = props.url || "";
|
|
1181
|
-
if (!
|
|
1205
|
+
if (!isSafeUrl(url)) return null;
|
|
1182
1206
|
const el = document.createElement("img");
|
|
1183
1207
|
el.src = url;
|
|
1184
1208
|
el.alt = props.alt || "";
|
|
@@ -1209,7 +1233,7 @@ var Messages = class {
|
|
|
1209
1233
|
if (options.onButtonPress) {
|
|
1210
1234
|
options.onButtonPress(action, messageId);
|
|
1211
1235
|
} else if (action) {
|
|
1212
|
-
if (
|
|
1236
|
+
if (isSafeUrl(action)) {
|
|
1213
1237
|
window.location.href = action;
|
|
1214
1238
|
}
|
|
1215
1239
|
}
|
|
@@ -1254,16 +1278,8 @@ var Messages = class {
|
|
|
1254
1278
|
}
|
|
1255
1279
|
}
|
|
1256
1280
|
};
|
|
1257
|
-
function isSafeUrl2(url) {
|
|
1258
|
-
try {
|
|
1259
|
-
const parsed = new URL(url, window.location.href);
|
|
1260
|
-
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
1261
|
-
} catch {
|
|
1262
|
-
return false;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
1281
|
function sanitizeCssUrl(url) {
|
|
1266
|
-
if (!
|
|
1282
|
+
if (!isSafeUrl(url)) return null;
|
|
1267
1283
|
return url.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "").replace(/\r/g, "");
|
|
1268
1284
|
}
|
|
1269
1285
|
function sanitizeTextAlign(value) {
|