@salespark/toolkit 2.1.15 → 2.1.16

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 CHANGED
@@ -836,29 +836,29 @@ assessSecurityRisks([]);
836
836
  // Result: { score: 0, level: "safe", recommendations: ["Content appears safe to use"] }
837
837
  ```
838
838
 
839
- **`scrambleString(value: string, secret: string): string`** — Scrambles a string using a repeating secret (XOR) and Base64. Reversible obfuscation only (not crypto).
839
+ **`scrambleString(value: string, secret: string): SalesParkContract<object>`** — Scrambles a string using a repeating secret (XOR) and Base64. Reversible obfuscation only (not crypto).
840
840
 
841
841
  ```javascript
842
842
  const scrambled = scrambleString("Hello", "secret");
843
- // Result: "..." (base64)
843
+ // Result: { status: true, data: "..." }
844
844
 
845
- const original = descrambleString(scrambled, "secret");
846
- // Result: "Hello"
845
+ const original = descrambleString(scrambled.data, "secret");
846
+ // Result: { status: true, data: "Hello" }
847
847
  ```
848
848
 
849
- **`descrambleString(value: string, secret: string): string`** — Reverses `scrambleString` using the same secret.
849
+ **`descrambleString(value: string, secret: string): SalesParkContract<object>`** — Reverses `scrambleString` using the same secret.
850
850
 
851
- **`encodeObject(input: object, secret: string): string`** — JSON-stringifies an object, Base64-encodes it, and scrambles the result (obfuscation only).
851
+ **`encodeObject(input: object, secret: string): SalesParkContract<object>`** — JSON-stringifies an object, Base64-encodes it, and scrambles the result (obfuscation only).
852
852
 
853
853
  ```javascript
854
854
  const encoded = encodeObject({ id: 1, name: "Ana" }, "secret");
855
- // Result: "..." (base64)
855
+ // Result: { status: true, data: "..." }
856
856
 
857
- const decoded = decodeObject(encoded, "secret");
858
- // Result: { id: 1, name: "Ana" }
857
+ const decoded = decodeObject(encoded.data, "secret");
858
+ // Result: { status: true, data: { id: 1, name: "Ana" } }
859
859
  ```
860
860
 
861
- **`decodeObject(encoded: string, secret: string): object`** — Reverses `encodeObject` using the same secret.
861
+ **`decodeObject(encoded: string, secret: string): SalesParkContract<object>`** — Reverses `encodeObject` using the same secret.
862
862
 
863
863
  ### ✅ Validation Utilities
864
864
 
package/dist/index.cjs CHANGED
@@ -1824,57 +1824,80 @@ var binaryToUtf8 = (binary) => {
1824
1824
  var toBase64 = (value) => base64EncodeBinary(utf8ToBinary(value));
1825
1825
  var fromBase64 = (value) => binaryToUtf8(base64DecodeToBinary(value));
1826
1826
  var scrambleString = (value, secret) => {
1827
- if (typeof value !== "string") {
1828
- throw new TypeError("Value must be a string");
1829
- }
1830
- if (!secret || typeof secret !== "string") {
1831
- throw new TypeError("Secret must be a non-empty string");
1832
- }
1833
- let result = "";
1834
- for (let i = 0; i < value.length; i++) {
1835
- const charCode = value.charCodeAt(i) & 255;
1836
- const keyCode = secret.charCodeAt(i % secret.length) & 255;
1837
- result += String.fromCharCode(charCode ^ keyCode);
1827
+ try {
1828
+ if (typeof value !== "string") {
1829
+ return { status: false, data: "Value must be a string" };
1830
+ }
1831
+ if (!secret || typeof secret !== "string") {
1832
+ return { status: false, data: "Secret must be a non-empty string" };
1833
+ }
1834
+ let result = "";
1835
+ for (let i = 0; i < value.length; i++) {
1836
+ const charCode = value.charCodeAt(i) & 255;
1837
+ const keyCode = secret.charCodeAt(i % secret.length) & 255;
1838
+ result += String.fromCharCode(charCode ^ keyCode);
1839
+ }
1840
+ return { status: true, data: base64EncodeBinary(result) };
1841
+ } catch (error) {
1842
+ return { status: false, data: error };
1838
1843
  }
1839
- return base64EncodeBinary(result);
1840
1844
  };
1841
1845
  var descrambleString = (value, secret) => {
1842
- if (typeof value !== "string") {
1843
- throw new TypeError("Value must be a string");
1844
- }
1845
- if (!secret || typeof secret !== "string") {
1846
- throw new TypeError("Secret must be a non-empty string");
1847
- }
1848
- const decoded = base64DecodeToBinary(value);
1849
- let result = "";
1850
- for (let i = 0; i < decoded.length; i++) {
1851
- const charCode = decoded.charCodeAt(i) & 255;
1852
- const keyCode = secret.charCodeAt(i % secret.length) & 255;
1853
- result += String.fromCharCode(charCode ^ keyCode);
1846
+ try {
1847
+ if (typeof value !== "string") {
1848
+ return { status: false, data: "Value must be a string" };
1849
+ }
1850
+ if (!secret || typeof secret !== "string") {
1851
+ return { status: false, data: "Secret must be a non-empty string" };
1852
+ }
1853
+ const decoded = base64DecodeToBinary(value);
1854
+ let result = "";
1855
+ for (let i = 0; i < decoded.length; i++) {
1856
+ const charCode = decoded.charCodeAt(i) & 255;
1857
+ const keyCode = secret.charCodeAt(i % secret.length) & 255;
1858
+ result += String.fromCharCode(charCode ^ keyCode);
1859
+ }
1860
+ return { status: true, data: result };
1861
+ } catch (error) {
1862
+ return { status: false, data: error };
1854
1863
  }
1855
- return result;
1856
1864
  };
1857
1865
  var encodeObject = (input, secret) => {
1858
- if (!input || typeof input !== "object") {
1859
- throw new TypeError("Input must be an object");
1860
- }
1861
- if (!secret || typeof secret !== "string") {
1862
- throw new TypeError("Secret must be a non-empty string");
1866
+ try {
1867
+ if (!input || typeof input !== "object") {
1868
+ return { status: false, data: "Input must be an object" };
1869
+ }
1870
+ if (!secret || typeof secret !== "string") {
1871
+ return { status: false, data: "Secret must be a non-empty string" };
1872
+ }
1873
+ const jsonString = JSON.stringify(input);
1874
+ const base64 = toBase64(jsonString);
1875
+ const scrambledResponse = scrambleString(base64, secret);
1876
+ if (!scrambledResponse.status) {
1877
+ return { status: false, data: "Scrambling failed" };
1878
+ }
1879
+ return { status: true, data: scrambledResponse.data };
1880
+ } catch (error) {
1881
+ return { status: false, data: error };
1863
1882
  }
1864
- const jsonString = JSON.stringify(input);
1865
- const base64 = toBase64(jsonString);
1866
- return scrambleString(base64, secret);
1867
1883
  };
1868
1884
  var decodeObject = (encoded, secret) => {
1869
- if (typeof encoded !== "string") {
1870
- throw new TypeError("Encoded value must be a string");
1871
- }
1872
- if (!secret || typeof secret !== "string") {
1873
- throw new TypeError("Secret must be a non-empty string");
1885
+ try {
1886
+ if (typeof encoded !== "string") {
1887
+ return { status: false, data: "Encoded value must be a string" };
1888
+ }
1889
+ if (!secret || typeof secret !== "string") {
1890
+ return { status: false, data: "Secret must be a non-empty string" };
1891
+ }
1892
+ const descrambledResponse = descrambleString(encoded, secret);
1893
+ if (!descrambledResponse.status) {
1894
+ return { status: false, data: "Descrambling failed" };
1895
+ }
1896
+ const jsonString = fromBase64(descrambledResponse.data);
1897
+ return { status: true, data: JSON.parse(jsonString) };
1898
+ } catch (error) {
1899
+ return { status: false, data: error };
1874
1900
  }
1875
- const descrambled = descrambleString(encoded, secret);
1876
- const jsonString = fromBase64(descrambled);
1877
- return JSON.parse(jsonString);
1878
1901
  };
1879
1902
 
1880
1903
  // src/utils/defer.ts