@takeal/cusfront-sdk 0.8.0 → 0.8.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.cts CHANGED
@@ -187,7 +187,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
187
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
188
  * release bump that forgets this file fails the test run.
189
189
  */
190
- declare const SDK_VERSION = "0.8.0";
190
+ declare const SDK_VERSION = "0.8.1";
191
191
 
192
192
  /**
193
193
  * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.
package/dist/index.d.ts CHANGED
@@ -187,7 +187,7 @@ declare function isNetworkError(e: unknown): e is NetworkError;
187
187
  * `define`. `src/version.test.ts` checks it matches `package.json`, so a
188
188
  * release bump that forgets this file fails the test run.
189
189
  */
190
- declare const SDK_VERSION = "0.8.0";
190
+ declare const SDK_VERSION = "0.8.1";
191
191
 
192
192
  /**
193
193
  * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.
package/dist/index.js CHANGED
@@ -865,10 +865,12 @@ var AuthResource = class {
865
865
  await Promise.resolve(this.tokens.set(resp.access_token));
866
866
  return resp;
867
867
  }
868
- /** Attach the first real email to a Telegram-made account (and clear
869
- * `email_pending`). 409 if taken. An account that already has a real
870
- * address gets 409 `email_change_needs_code`: change it with
871
- * {@link requestEmailChange} and {@link confirmEmailChange}. */
868
+ /** Always answers 409 `email_change_needs_code` on platform 0.8.1 and
869
+ * newer: an address is attached only after a code sent to it comes back.
870
+ * For the first real email of a Telegram-made account use
871
+ * {@link requestEmailChange} and {@link confirmEmailChange}; they clear
872
+ * `email_pending` too.
873
+ * @deprecated Use {@link requestEmailChange} and {@link confirmEmailChange}. */
872
874
  async linkEmail(input) {
873
875
  return this.http.post("/me/email", { body: { email: input.email } });
874
876
  }
@@ -1749,7 +1751,7 @@ var FundingOptionsResource = class {
1749
1751
  };
1750
1752
 
1751
1753
  // src/version.ts
1752
- var SDK_VERSION = "0.8.0";
1754
+ var SDK_VERSION = "0.8.1";
1753
1755
 
1754
1756
  // src/client-platform.ts
1755
1757
  var CLIENT_HEADER = "X-Takeal-Client";
@@ -2021,6 +2023,67 @@ function digitCount(s) {
2021
2023
  function redactText(v) {
2022
2024
  return v.replace(EMAIL, "[email]").replace(DIGIT_RUN, (m) => digitCount(m) >= 9 && digitCount(m) <= 19 ? "[number]" : m);
2023
2025
  }
2026
+ var UTM_PARAMS = [
2027
+ "utm_source",
2028
+ "utm_medium",
2029
+ "utm_campaign",
2030
+ "utm_content",
2031
+ "utm_term"
2032
+ ];
2033
+ var CLICK_ID_PARAMS = [
2034
+ "yclid",
2035
+ "ysclid",
2036
+ "gclid",
2037
+ "gbraid",
2038
+ "wbraid",
2039
+ "fbclid",
2040
+ "ttclid",
2041
+ "msclkid",
2042
+ "rb_clickid"
2043
+ ];
2044
+ var UTM_SET = new Set(UTM_PARAMS);
2045
+ var CLICK_ID_SET = new Set(CLICK_ID_PARAMS);
2046
+ var CLICK_ID_VALUE = /^[A-Za-z0-9._~-]{1,256}$/;
2047
+ function adField(key) {
2048
+ const k = key.replace(/^\$+/, "").toLowerCase().replace(/^initial_/, "");
2049
+ if (UTM_SET.has(k)) return "utm";
2050
+ if (CLICK_ID_SET.has(k)) return "click";
2051
+ return void 0;
2052
+ }
2053
+ function luhn(digits) {
2054
+ let sum = 0;
2055
+ for (let i = 0; i < digits.length; i++) {
2056
+ let d = digits.charCodeAt(digits.length - 1 - i) - 48;
2057
+ if (i % 2 === 1) {
2058
+ d *= 2;
2059
+ if (d > 9) d -= 9;
2060
+ }
2061
+ sum += d;
2062
+ }
2063
+ return sum % 10 === 0;
2064
+ }
2065
+ var NUMBER_RUN = /(?:\+\s*)?\d(?:[\d\s().-]*\d)?/g;
2066
+ function adValuePersonal(v) {
2067
+ if (v.includes("@")) return true;
2068
+ for (const m of v.match(NUMBER_RUN) ?? []) {
2069
+ const groups = m.split(/\D+/).filter(Boolean);
2070
+ const n = groups.join("").length;
2071
+ if (m.startsWith("+")) {
2072
+ if (n >= 9 && n <= 15) return true;
2073
+ continue;
2074
+ }
2075
+ if (groups.length === 1) {
2076
+ if (n >= 16 && n <= 19 && luhn(groups[0])) return true;
2077
+ continue;
2078
+ }
2079
+ if (n >= 9 && n <= 19 && (/[()]/.test(m) || groups.every((g) => g.length <= 4))) return true;
2080
+ }
2081
+ return v.split(/[\s_.~+-]+/).some((seg) => seg.length >= 20 && /\d.*\d/.test(seg) && /[A-Za-z].*[A-Za-z]/.test(seg));
2082
+ }
2083
+ function adValue(kind, v) {
2084
+ if (kind === "click") return CLICK_ID_VALUE.test(v) ? v : void 0;
2085
+ return adValuePersonal(v) ? void 0 : v;
2086
+ }
2024
2087
  function idSegment(seg) {
2025
2088
  let s = seg;
2026
2089
  try {
@@ -2032,6 +2095,13 @@ function idSegment(seg) {
2032
2095
  if (replaced !== s) return replaced;
2033
2096
  return redactText(s) === s ? seg : PLACEHOLDER;
2034
2097
  }
2098
+ function decodeQueryPart(s) {
2099
+ try {
2100
+ return decodeURIComponent(s.replace(/\+/g, " "));
2101
+ } catch {
2102
+ return s;
2103
+ }
2104
+ }
2035
2105
  function sanitizeUrl(raw) {
2036
2106
  const absolute = /^[a-z][a-z0-9+.-]*:\/\//i.test(raw);
2037
2107
  let u;
@@ -2042,14 +2112,22 @@ function sanitizeUrl(raw) {
2042
2112
  }
2043
2113
  const path = u.pathname.split("/").map((seg) => seg ? idSegment(seg) : seg).join("/");
2044
2114
  const query = [];
2045
- u.searchParams.forEach((value, key) => {
2115
+ for (const pair of u.search.replace(/^\?/, "").split("&")) {
2116
+ if (!pair) continue;
2117
+ const eq = pair.indexOf("=");
2118
+ const rawKey = eq < 0 ? pair : pair.slice(0, eq);
2119
+ const key = decodeQueryPart(rawKey);
2120
+ const value = eq < 0 ? "" : decodeQueryPart(pair.slice(eq + 1));
2121
+ const ad = adField(key);
2122
+ if (ad) {
2123
+ if (adValue(ad, value) !== void 0) query.push(pair);
2124
+ continue;
2125
+ }
2046
2126
  const k = words(key);
2047
- if (k.some((w) => SECRET_QUERY_WORDS.has(w)) || personalKey(key)) return;
2048
- if (redactText(value) !== value) return;
2049
- query.push(
2050
- `${encodeURIComponent(key)}=${isId(value) ? PLACEHOLDER : encodeURIComponent(value)}`
2051
- );
2052
- });
2127
+ if (k.some((w) => SECRET_QUERY_WORDS.has(w)) || personalKey(key)) continue;
2128
+ if (redactText(value) !== value) continue;
2129
+ query.push(isId(value) ? `${rawKey}=${PLACEHOLDER}` : pair);
2130
+ }
2053
2131
  const search = query.length ? `?${query.join("&")}` : "";
2054
2132
  return (absolute ? `${u.protocol}//${u.host}` : "") + path + search;
2055
2133
  }
@@ -2057,6 +2135,8 @@ function cleanValue(key, v, depth) {
2057
2135
  if (v === null || v === void 0 || typeof v === "number" || typeof v === "boolean") return v;
2058
2136
  if (typeof v === "string") {
2059
2137
  if (MONEY_KEYS.has(key.toLowerCase()) || UUID_ONLY.test(v)) return v;
2138
+ const ad = adField(key);
2139
+ if (ad) return adValue(ad, v);
2060
2140
  if (urlKey(key) || /^https?:\/\//i.test(v)) return sanitizeUrl(v);
2061
2141
  if (key === "$elements_chain") {
2062
2142
  return redactText(v).replace(