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