@tolinku/web-sdk 0.5.0 → 0.6.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/README.md +23 -0
- package/dist/index.d.mts +76 -1
- package/dist/index.d.ts +76 -1
- package/dist/index.js +65 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -1
- package/dist/index.mjs.map +1 -1
- package/dist/tolinku.min.js +17 -17
- package/dist/tolinku.min.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/types.ts
|
|
2
|
-
var SDK_VERSION = "0.
|
|
2
|
+
var SDK_VERSION = "0.6.0";
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
var MAX_RETRIES = 3;
|
|
@@ -66,6 +66,28 @@ var HttpClient = class {
|
|
|
66
66
|
}
|
|
67
67
|
return this.parseJson(res);
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* POST to a host other than the configured one, without the API key.
|
|
71
|
+
*
|
|
72
|
+
* A few public endpoints work out which Appspace they belong to from the
|
|
73
|
+
* hostname the request arrives on rather than from a key or an id, so a
|
|
74
|
+
* question about a link on a customer's own domain has to be asked on that
|
|
75
|
+
* domain. No key goes with it: the origin comes from a URL the caller was
|
|
76
|
+
* handed, which is not necessarily ours.
|
|
77
|
+
*/
|
|
78
|
+
async postPublicToOrigin(origin, path, body) {
|
|
79
|
+
const res = await this.fetchWithRetry(origin.replace(/\/+$/, "") + path, {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: { "Content-Type": "application/json" },
|
|
82
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
83
|
+
signal: this.signal
|
|
84
|
+
});
|
|
85
|
+
if (!res.ok) {
|
|
86
|
+
const data = await res.json().catch(() => ({ error: res.statusText }));
|
|
87
|
+
throw new TolinkuError(data.error || res.statusText, res.status, data.code);
|
|
88
|
+
}
|
|
89
|
+
return this.parseJson(res);
|
|
90
|
+
}
|
|
69
91
|
/** GET without API key auth (for public endpoints like banner config) */
|
|
70
92
|
async getPublic(path, params) {
|
|
71
93
|
let url = this._baseUrl + path;
|
|
@@ -644,6 +666,47 @@ function override(value) {
|
|
|
644
666
|
return void 0;
|
|
645
667
|
}
|
|
646
668
|
|
|
669
|
+
// src/links.ts
|
|
670
|
+
function isRoutablePath(path) {
|
|
671
|
+
return typeof path === "string" && path.startsWith("/") && !path.startsWith("//");
|
|
672
|
+
}
|
|
673
|
+
var Links = class {
|
|
674
|
+
constructor(client) {
|
|
675
|
+
this.client = client;
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* What this link means, or null if it means nothing here.
|
|
679
|
+
*
|
|
680
|
+
* The question goes to the link's own host, because that is how Tolinku knows
|
|
681
|
+
* which Appspace is being asked about, which also means a link on a domain
|
|
682
|
+
* that is not yours simply answers nothing.
|
|
683
|
+
*
|
|
684
|
+
* Never throws. A link that cannot be resolved, for a bad network or any
|
|
685
|
+
* other reason, is one to fall back to your own handling for.
|
|
686
|
+
*/
|
|
687
|
+
async resolve(url) {
|
|
688
|
+
if (!url || typeof url !== "string") return null;
|
|
689
|
+
let parsed;
|
|
690
|
+
try {
|
|
691
|
+
parsed = new URL(url.trim());
|
|
692
|
+
} catch {
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
696
|
+
try {
|
|
697
|
+
const result = await this.client.postPublicToOrigin(
|
|
698
|
+
parsed.origin,
|
|
699
|
+
"/v1/api/path",
|
|
700
|
+
{ path: parsed.pathname }
|
|
701
|
+
);
|
|
702
|
+
if (!result || !result.route || !isRoutablePath(result.deep_link_path)) return null;
|
|
703
|
+
return result;
|
|
704
|
+
} catch {
|
|
705
|
+
return null;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
|
|
647
710
|
// src/url-safety.ts
|
|
648
711
|
function isSafeUrl(url) {
|
|
649
712
|
if (typeof url !== "string") return false;
|
|
@@ -1326,6 +1389,7 @@ var Tolinku = class {
|
|
|
1326
1389
|
this.ecommerce = new Ecommerce(this.client, () => this._userId);
|
|
1327
1390
|
this.referrals = new Referrals(this.client);
|
|
1328
1391
|
this.deferred = new Deferred(this.client);
|
|
1392
|
+
this.links = new Links(this.client);
|
|
1329
1393
|
this.banners = new Banners(this.client);
|
|
1330
1394
|
this.messages = new Messages(this.client);
|
|
1331
1395
|
}
|