@proveanything/smartlinks 1.0.45 → 1.0.46

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.46 | Generated: 2025-11-23T09:12:28.424Z
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,10 +145,12 @@ 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 // sends 'ngrok-skip-browser-warning: true'
153
+ extraHeaders?: Record<string,string> // custom headers merged in each request
152
154
  })
153
155
  ```
154
156
 
@@ -157,6 +159,11 @@ When embedding the SDK in an iframe with `proxyMode: true`, you can also use:
157
159
  ```ts
158
160
  import { sendCustomProxyMessage } from '@proveanything/smartlinks'
159
161
  const data = await sendCustomProxyMessage('my-action', { foo: 'bar' })
162
+
163
+ // Toggle ngrok header or update custom headers later:
164
+ import { setNgrokSkipBrowserWarning, setExtraHeaders } from '@proveanything/smartlinks'
165
+ setNgrokSkipBrowserWarning(true)
166
+ setExtraHeaders({ 'X-Debug': '1' })
160
167
  ```
161
168
 
162
169
  ## 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,25 @@ 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
+ const inferredNgrok = /\.ngrok\.io(\b|\/)/i.test(baseURL);
28
+ ngrokSkipBrowserWarning = options.ngrokSkipBrowserWarning !== undefined
29
+ ? !!options.ngrokSkipBrowserWarning
30
+ : inferredNgrok;
31
+ extraHeadersGlobal = options.extraHeaders ? Object.assign({}, options.extraHeaders) : {};
32
+ }
33
+ /** Enable/disable automatic "ngrok-skip-browser-warning" header. */
34
+ export function setNgrokSkipBrowserWarning(flag) {
35
+ ngrokSkipBrowserWarning = flag;
36
+ }
37
+ /** Replace or augment globally applied custom headers. */
38
+ export function setExtraHeaders(headers) {
39
+ extraHeadersGlobal = Object.assign({}, headers);
23
40
  }
24
41
  /**
25
42
  * Allows setting the bearerToken at runtime (e.g. after login/logout).
@@ -85,15 +102,15 @@ export async function request(path) {
85
102
  throw new Error("HTTP client is not initialized. Call initializeApi(...) first.");
86
103
  }
87
104
  const url = `${baseURL}${path}`;
88
- const headers = {
89
- "Content-Type": "application/json",
90
- };
91
- if (apiKey) {
105
+ const headers = { "Content-Type": "application/json" };
106
+ if (apiKey)
92
107
  headers["X-API-Key"] = apiKey;
93
- }
94
- if (bearerToken) {
108
+ if (bearerToken)
95
109
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
96
- }
110
+ if (ngrokSkipBrowserWarning)
111
+ headers["ngrok-skip-browser-warning"] = "true";
112
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
113
+ headers[k] = v;
97
114
  const response = await fetch(url, {
98
115
  method: "GET",
99
116
  headers,
@@ -129,6 +146,11 @@ export async function post(path, body, extraHeaders) {
129
146
  headers["X-API-Key"] = apiKey;
130
147
  if (bearerToken)
131
148
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
149
+ if (ngrokSkipBrowserWarning)
150
+ headers["ngrok-skip-browser-warning"] = "true";
151
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
152
+ if (!(k in headers))
153
+ headers[k] = v;
132
154
  // Only set Content-Type for non-FormData bodies
133
155
  if (!(body instanceof FormData)) {
134
156
  headers["Content-Type"] = "application/json";
@@ -168,6 +190,11 @@ export async function put(path, body, extraHeaders) {
168
190
  headers["X-API-Key"] = apiKey;
169
191
  if (bearerToken)
170
192
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
193
+ if (ngrokSkipBrowserWarning)
194
+ headers["ngrok-skip-browser-warning"] = "true";
195
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
196
+ if (!(k in headers))
197
+ headers[k] = v;
171
198
  // Only set Content-Type for non-FormData bodies
172
199
  if (!(body instanceof FormData)) {
173
200
  headers["Content-Type"] = "application/json";
@@ -218,7 +245,11 @@ export async function requestWithOptions(path, options) {
218
245
  extraHeaders = Object.assign({}, options.headers);
219
246
  }
220
247
  }
221
- const headers = Object.assign(Object.assign(Object.assign({ "Content-Type": "application/json" }, (apiKey ? { "X-API-Key": apiKey } : {})), (bearerToken ? { "AUTHORIZATION": `Bearer ${bearerToken}` } : {})), extraHeaders);
248
+ 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);
249
+ // Merge global custom headers (do not override existing keys from options.headers)
250
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
251
+ if (!(k in headers))
252
+ headers[k] = v;
222
253
  const response = await fetch(url, Object.assign(Object.assign({}, options), { headers }));
223
254
  if (!response.ok) {
224
255
  try {
@@ -249,6 +280,11 @@ export async function del(path, extraHeaders) {
249
280
  headers["X-API-Key"] = apiKey;
250
281
  if (bearerToken)
251
282
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
283
+ if (ngrokSkipBrowserWarning)
284
+ headers["ngrok-skip-browser-warning"] = "true";
285
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
286
+ if (!(k in headers))
287
+ headers[k] = v;
252
288
  const response = await fetch(url, {
253
289
  method: "DELETE",
254
290
  headers,
@@ -276,6 +312,11 @@ export function getApiHeaders() {
276
312
  headers["X-API-Key"] = apiKey;
277
313
  if (bearerToken)
278
314
  headers["AUTHORIZATION"] = `Bearer ${bearerToken}`;
315
+ if (ngrokSkipBrowserWarning)
316
+ headers["ngrok-skip-browser-warning"] = "true";
317
+ for (const [k, v] of Object.entries(extraHeadersGlobal))
318
+ if (!(k in headers))
319
+ headers[k] = v;
279
320
  return headers;
280
321
  }
281
322
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.0.45",
3
+ "version": "1.0.46",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",