@proveanything/smartlinks 1.0.45 → 1.0.47

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/API_SUMMARY.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.0.45 | Generated: 2025-11-22T17:29:38.790Z
3
+ Version: 1.0.47 | Generated: 2025-11-23T09:18:23.853Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -35,9 +35,17 @@ Core HTTP functions for API configuration and communication:
35
35
  apiKey?: string
36
36
  bearerToken?: string
37
37
  proxyMode?: boolean
38
+ ngrokSkipBrowserWarning?: boolean
39
+ extraHeaders?: Record<string, string>
38
40
  }) → `void`
39
41
  Call this once (e.g. at app startup) to configure baseURL/auth.
40
42
 
43
+ **setNgrokSkipBrowserWarning**(flag: boolean) → `void`
44
+ Enable/disable automatic "ngrok-skip-browser-warning" header.
45
+
46
+ **setExtraHeaders**(headers: Record<string, string>) → `void`
47
+ Replace or augment globally applied custom headers.
48
+
41
49
  **setBearerToken**(token: string | undefined) → `void`
42
50
  Allows setting the bearerToken at runtime (e.g. after login/logout).
43
51
 
package/README.md CHANGED
@@ -21,16 +21,16 @@ npm install @proveanything/smartlinks
21
21
 
22
22
  ## Quick start
23
23
 
24
- Initialize once at app startup with your API base URL. You may provide the URL with or without a trailing slash – the SDK normalizes it. In Node, you can also provide an API key for server-to-server calls.
24
+ Initialize once at app startup with your API base URL. Trailing slashes are optional (normalized). In Node, you can also provide an API key for server-to-server calls. You can enable an ngrok header or supply custom headers.
25
25
 
26
26
  ```ts
27
27
  import { initializeApi } from '@proveanything/smartlinks'
28
28
 
29
29
  initializeApi({
30
- // Both forms are accepted; trailing slashes are stripped automatically:
31
- // baseURL: 'https://smartlinks.app/api/v1/'
32
- baseURL: 'https://smartlinks.app/api/v1',
33
- // apiKey: process.env.SMARTLINKS_API_KEY, // Node/server only (optional)
30
+ baseURL: 'https://smartlinks.app/api/v1', // or 'https://smartlinks.app/api/v1/'
31
+ // apiKey: process.env.SMARTLINKS_API_KEY, // Node/server only (optional)
32
+ // ngrokSkipBrowserWarning: true, // adds 'ngrok-skip-browser-warning: true'
33
+ // extraHeaders: { 'X-Debug': '1' } // merged into every request
34
34
  })
35
35
  ```
36
36
 
@@ -55,7 +55,7 @@ Use the built-in helpers to log in and verify tokens. After a successful login,
55
55
  import { initializeApi } from '@proveanything/smartlinks'
56
56
  import { auth } from '@proveanything/smartlinks'
57
57
 
58
- initializeApi({ baseURL: 'https://smartlinks.app/api/v1/' }) // works (slash removed internally)
58
+ initializeApi({ baseURL: 'https://smartlinks.app/api/v1/' }) // trailing slash OK
59
59
 
60
60
  // Email + password login (browser or Node)
61
61
  const user = await auth.login('user@example.com', 'password')
@@ -135,7 +135,7 @@ The SDK works in modern browsers. Initialize once and call public endpoints with
135
135
  import { initializeApi } from '@proveanything/smartlinks'
136
136
  import { collection } from '@proveanything/smartlinks'
137
137
 
138
- initializeApi({ baseURL: 'https://smartlinks.app/api/v1' }) // trailing slash optional
138
+ initializeApi({ baseURL: 'https://smartlinks.app/api/v1' })
139
139
  const collections = await collection.list(false)
140
140
  ```
141
141
 
@@ -145,11 +145,16 @@ For a fuller UI example, see `examples/react-demo.tsx`.
145
145
 
146
146
  ```ts
147
147
  initializeApi({
148
- baseURL: string, // Provide with or without trailing slash; SDK normalizes
148
+ baseURL: string, // with or without trailing slash
149
149
  apiKey?: string, // Node/server only
150
150
  bearerToken?: string, // optional at init; set by auth.login/verifyToken
151
151
  proxyMode?: boolean // set true if running inside an iframe and using parent proxy
152
+ ngrokSkipBrowserWarning?: boolean // forces header 'ngrok-skip-browser-warning: true'
153
+ extraHeaders?: Record<string,string> // custom headers merged in each request
152
154
  })
155
+
156
+ // Auto-detection: If baseURL contains '.ngrok.io' or '.ngrok-free.dev' the header is added automatically
157
+ // unless you explicitly set ngrokSkipBrowserWarning: false.
153
158
  ```
154
159
 
155
160
  When embedding the SDK in an iframe with `proxyMode: true`, you can also use:
@@ -157,6 +162,11 @@ When embedding the SDK in an iframe with `proxyMode: true`, you can also use:
157
162
  ```ts
158
163
  import { sendCustomProxyMessage } from '@proveanything/smartlinks'
159
164
  const data = await sendCustomProxyMessage('my-action', { foo: 'bar' })
165
+
166
+ // Toggle ngrok header or update custom headers later:
167
+ import { setNgrokSkipBrowserWarning, setExtraHeaders } from '@proveanything/smartlinks'
168
+ setNgrokSkipBrowserWarning(true)
169
+ setExtraHeaders({ 'X-Debug': '1' })
160
170
  ```
161
171
 
162
172
  ## Full API surface
package/dist/http.d.ts CHANGED
@@ -12,7 +12,13 @@ export declare function initializeApi(options: {
12
12
  apiKey?: string;
13
13
  bearerToken?: string;
14
14
  proxyMode?: boolean;
15
+ ngrokSkipBrowserWarning?: boolean;
16
+ extraHeaders?: Record<string, string>;
15
17
  }): void;
18
+ /** Enable/disable automatic "ngrok-skip-browser-warning" header. */
19
+ export declare function setNgrokSkipBrowserWarning(flag: boolean): void;
20
+ /** Replace or augment globally applied custom headers. */
21
+ export declare function setExtraHeaders(headers: Record<string, string>): void;
16
22
  /**
17
23
  * Allows setting the bearerToken at runtime (e.g. after login/logout).
18
24
  */
package/dist/http.js CHANGED
@@ -6,6 +6,8 @@ let baseURL = null;
6
6
  let apiKey = undefined;
7
7
  let bearerToken = undefined;
8
8
  let proxyMode = false;
9
+ let ngrokSkipBrowserWarning = false;
10
+ let extraHeadersGlobal = {};
9
11
  /**
10
12
  * Call this once (e.g. at app startup) to configure baseURL/auth.
11
13
  *
@@ -16,10 +18,26 @@ let proxyMode = false;
16
18
  * @property {boolean} [options.proxyMode] - (Optional) Tells the API that it is running in an iframe via parent proxy
17
19
  */
18
20
  export function initializeApi(options) {
19
- baseURL = options.baseURL.replace(/\/+\$/, ""); // trim trailing slash
21
+ // Normalize baseURL by removing trailing slashes.
22
+ baseURL = options.baseURL.replace(/\/+$/g, "");
20
23
  apiKey = options.apiKey;
21
24
  bearerToken = options.bearerToken;
22
25
  proxyMode = !!options.proxyMode;
26
+ // Auto-enable ngrok skip header if domain contains .ngrok.io and user did not explicitly set the flag.
27
+ // Infer ngrok usage from common domains (.ngrok.io or .ngrok-free.dev)
28
+ const inferredNgrok = /(\.ngrok\.io|\.ngrok-free\.dev)(\b|\/)/i.test(baseURL);
29
+ ngrokSkipBrowserWarning = options.ngrokSkipBrowserWarning !== undefined
30
+ ? !!options.ngrokSkipBrowserWarning
31
+ : inferredNgrok;
32
+ extraHeadersGlobal = options.extraHeaders ? Object.assign({}, options.extraHeaders) : {};
33
+ }
34
+ /** Enable/disable automatic "ngrok-skip-browser-warning" header. */
35
+ export function setNgrokSkipBrowserWarning(flag) {
36
+ ngrokSkipBrowserWarning = flag;
37
+ }
38
+ /** Replace or augment globally applied custom headers. */
39
+ export function setExtraHeaders(headers) {
40
+ extraHeadersGlobal = Object.assign({}, headers);
23
41
  }
24
42
  /**
25
43
  * Allows setting the bearerToken at runtime (e.g. after login/logout).
@@ -85,15 +103,15 @@ export async function request(path) {
85
103
  throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
86
104
  }
87
105
  const url = `${baseURL}${path}`;
88
- const headers = {
89
- "Content-Type": "application/json",
90
- };
91
- if (apiKey) {
106
+ const headers = { "Content-Type": "application/json" };
107
+ if (apiKey)
92
108
  headers["X-API-Key"] = apiKey;
93
- }
94
- if (bearerToken) {
109
+ if (bearerToken)
95
110
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
96
- }
111
+ if (ngrokSkipBrowserWarning)
112
+ headers["ngrok-skip-browser-warning"] = "true";
113
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
114
+ headers[k] = v;
97
115
  const response = await fetch(url, {
98
116
  method: "GET",
99
117
  headers,
@@ -129,6 +147,11 @@ export async function post(path, body, extraHeaders) {
129
147
  headers["X-API-Key"] = apiKey;
130
148
  if (bearerToken)
131
149
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
150
+ if (ngrokSkipBrowserWarning)
151
+ headers["ngrok-skip-browser-warning"] = "true";
152
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
153
+ if (!(k in headers))
154
+ headers[k] = v;
132
155
  // Only set Content-Type for non-FormData bodies
133
156
  if (!(body instanceof FormData)) {
134
157
  headers["Content-Type"] = "application/json";
@@ -168,6 +191,11 @@ export async function put(path, body, extraHeaders) {
168
191
  headers["X-API-Key"] = apiKey;
169
192
  if (bearerToken)
170
193
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
194
+ if (ngrokSkipBrowserWarning)
195
+ headers["ngrok-skip-browser-warning"] = "true";
196
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
197
+ if (!(k in headers))
198
+ headers[k] = v;
171
199
  // Only set Content-Type for non-FormData bodies
172
200
  if (!(body instanceof FormData)) {
173
201
  headers["Content-Type"] = "application/json";
@@ -218,7 +246,11 @@ export async function requestWithOptions(path, options) {
218
246
  extraHeaders = Object.assign({}, options.headers);
219
247
  }
220
248
  }
221
- const headers = Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, (apiKey ? { "X-API-Key": apiKey } : {})), (bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {})), extraHeaders);
249
+ const headers = Object.assign(Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, (apiKey ? { "X-API-Key": apiKey } : {})), (bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {})), (ngrokSkipBrowserWarning ? { "ngrok-skip-browser-warning": "true" } : {})), extraHeaders);
250
+ // Merge global custom headers (do not override existing keys from options.headers)
251
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
252
+ if (!(k in headers))
253
+ headers[k] = v;
222
254
  const response = await fetch(url, Object.assign(Object.assign({}, options), { headers }));
223
255
  if (!response.ok) {
224
256
  try {
@@ -249,6 +281,11 @@ export async function del(path, extraHeaders) {
249
281
  headers["X-API-Key"] = apiKey;
250
282
  if (bearerToken)
251
283
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
284
+ if (ngrokSkipBrowserWarning)
285
+ headers["ngrok-skip-browser-warning"] = "true";
286
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
287
+ if (!(k in headers))
288
+ headers[k] = v;
252
289
  const response = await fetch(url, {
253
290
  method: "DELETE",
254
291
  headers,
@@ -276,6 +313,11 @@ export function getApiHeaders() {
276
313
  headers["X-API-Key"] = apiKey;
277
314
  if (bearerToken)
278
315
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
316
+ if (ngrokSkipBrowserWarning)
317
+ headers["ngrok-skip-browser-warning"] = "true";
318
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
319
+ if (!(k in headers))
320
+ headers[k] = v;
279
321
  return headers;
280
322
  }
281
323
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.0.45",
3
+ "version": "1.0.47",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",