mapnests-browser-sdk 1.0.0 → 1.0.2

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.
@@ -1,11 +1,13 @@
1
1
  export async function generateToken(apiKey) {
2
+ if (typeof window === 'undefined' || !window.crypto?.subtle) {
3
+ throw new Error('Web Crypto API not available. This SDK must be used in a browser environment.');
4
+ }
2
5
  const randInt = Math.floor(Math.random() * 1000000);
3
6
  const expires = Math.floor(Date.now() / 1000) + 30;
4
7
  const input = `${expires}:${randInt}:${apiKey}`;
5
- // Browser-only: Web Crypto API
6
8
  const encoder = new TextEncoder();
7
9
  const data = encoder.encode(input);
8
- const hashBuffer = await crypto.subtle.digest('SHA-256', data);
10
+ const hashBuffer = await window.crypto.subtle.digest('SHA-256', data);
9
11
  const hashArray = Array.from(new Uint8Array(hashBuffer));
10
12
  const hash = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
11
13
  const jsonPayload = {
@@ -13,8 +15,6 @@ export async function generateToken(apiKey) {
13
15
  expires,
14
16
  sign: hash,
15
17
  };
16
- const jsonStr = JSON.stringify(jsonPayload);
17
- // Browser: use btoa for Base64 encoding
18
- const base64 = btoa(jsonStr);
18
+ const base64 = btoa(JSON.stringify(jsonPayload));
19
19
  return base64;
20
20
  }
@@ -22,7 +22,6 @@ export async function performSecureRequest(label, apiKey, origin, jsonRequest) {
22
22
  const method = HTTP_METHOD_MAP[label] || 'GET';
23
23
  const headers = {
24
24
  'X-API-KEY': apiKey,
25
- 'Origin': origin,
26
25
  'fxsrf': tokenHeader,
27
26
  'Content-Type': 'application/json',
28
27
  };
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "mapnests-browser-sdk",
3
3
  "description": "TypeScript SDK for Mapnests API integration (Distance Matrix, Distance Matrix Details, Geocode, Reverse Geocode)",
4
- "version": "1.0.0",
4
+ "version": "1.0.2",
5
+ "browser": "dist/index.js",
5
6
  "main": "dist/index.js",
7
+ "type": "module",
6
8
  "types": "dist/index.d.ts",
7
9
  "exports": {
8
10
  ".": {