@proveanything/smartlinks 1.3.45 → 1.3.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.
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.45 | Generated: 2026-02-19T14:43:39.335Z
3
+ Version: 1.3.46 | Generated: 2026-02-19T21:09:09.402Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -87,7 +87,10 @@ Return whether proxy mode is currently enabled.
87
87
  extraHeaders?: Record<string, string>
88
88
  iframeAutoResize?: boolean // default true when in iframe
89
89
  logger?: Logger // optional console-like or function to enable verbose logging
90
- }) → `void`
90
+ /**
91
+ * When true, bypasses the idempotency guard and forces a full re-initialization.
92
+ * Use only when you intentionally need to reset all SDK state (e.g. in tests or
93
+ * when switching accounts) → `void`
91
94
  Call this once (e.g. at app startup) to configure baseURL/auth.
92
95
 
93
96
  **setNgrokSkipBrowserWarning**(flag: boolean) → `void`
@@ -102,6 +105,9 @@ Allows setting the bearerToken at runtime (e.g. after login/logout).
102
105
  **getBaseURL**() → `string | null`
103
106
  Get the currently configured API base URL. Returns null if initializeApi() has not been called yet.
104
107
 
108
+ **isInitialized**() → `boolean`
109
+ Returns true if initializeApi() has been called at least once. Useful for guards in widgets or shared modules that want to skip initialization when another module has already done it. ```ts if (!isInitialized()) { initializeApi({ baseURL: 'https://smartlinks.app/api/v1' }) } ```
110
+
105
111
  **proxyUploadFormData**(path: string,
106
112
  formData: FormData,
107
113
  onProgress?: (percent: number) → `void`
package/dist/http.d.ts CHANGED
@@ -16,6 +16,13 @@ export declare function initializeApi(options: {
16
16
  extraHeaders?: Record<string, string>;
17
17
  iframeAutoResize?: boolean;
18
18
  logger?: Logger;
19
+ /**
20
+ * When true, bypasses the idempotency guard and forces a full re-initialization.
21
+ * Use only when you intentionally need to reset all SDK state (e.g. in tests or
22
+ * when switching accounts). In normal application code, prefer letting the guard
23
+ * protect runtime state such as login tokens.
24
+ */
25
+ force?: boolean;
19
26
  }): void;
20
27
  /** Enable/disable automatic "ngrok-skip-browser-warning" header. */
21
28
  export declare function setNgrokSkipBrowserWarning(flag: boolean): void;
@@ -30,6 +37,19 @@ export declare function setBearerToken(token: string | undefined): void;
30
37
  * Returns null if initializeApi() has not been called yet.
31
38
  */
32
39
  export declare function getBaseURL(): string | null;
40
+ /**
41
+ * Returns true if initializeApi() has been called at least once.
42
+ * Useful for guards in widgets or shared modules that want to skip
43
+ * initialization when another module has already done it.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * if (!isInitialized()) {
48
+ * initializeApi({ baseURL: 'https://smartlinks.app/api/v1' })
49
+ * }
50
+ * ```
51
+ */
52
+ export declare function isInitialized(): boolean;
33
53
  /**
34
54
  * Upload a FormData payload via proxy with progress events using chunked postMessage.
35
55
  * Parent is expected to implement the counterpart protocol.
package/dist/http.js CHANGED
@@ -20,6 +20,8 @@ let bearerToken = undefined;
20
20
  let proxyMode = false;
21
21
  let ngrokSkipBrowserWarning = false;
22
22
  let extraHeadersGlobal = {};
23
+ /** Whether initializeApi has been successfully called at least once. */
24
+ let initialized = false;
23
25
  let logger;
24
26
  function logDebug(...args) {
25
27
  if (!logger)
@@ -169,9 +171,32 @@ function normalizeErrorResponse(responseBody, statusCode) {
169
171
  import { iframe } from './iframe';
170
172
  export function initializeApi(options) {
171
173
  // Normalize baseURL by removing trailing slashes.
172
- baseURL = options.baseURL.replace(/\/+$/g, "");
174
+ const normalizedBaseURL = options.baseURL.replace(/\/+$/g, "");
175
+ // ------------------------------------------------------------------
176
+ // Firebase-style idempotency guard
177
+ // If we have already been initialized with the same baseURL and the
178
+ // caller is not forcing a reset, return immediately. This prevents
179
+ // any module – widget, component, or re-rendered page – from
180
+ // accidentally wiping runtime state such as a bearerToken that was
181
+ // set by auth.login() after the first initialization.
182
+ // ------------------------------------------------------------------
183
+ if (initialized && !options.force && baseURL === normalizedBaseURL) {
184
+ logDebug('[smartlinks] initializeApi: already initialized with this baseURL – skipping.', { baseURL });
185
+ return;
186
+ }
187
+ baseURL = normalizedBaseURL;
173
188
  apiKey = options.apiKey;
174
- bearerToken = options.bearerToken;
189
+ // Only overwrite bearerToken when the caller explicitly supplies one,
190
+ // OR when this is the very first initialization (start with a clean slate).
191
+ // Re-initialization calls that omit bearerToken must NOT clear a token that
192
+ // was acquired at runtime (e.g. from a successful auth.login()).
193
+ if (options.bearerToken !== undefined) {
194
+ bearerToken = options.bearerToken;
195
+ }
196
+ else if (!initialized) {
197
+ bearerToken = undefined;
198
+ }
199
+ // else: preserve the existing runtime bearerToken.
175
200
  proxyMode = !!options.proxyMode;
176
201
  // Auto-enable ngrok skip header if domain contains .ngrok.io and user did not explicitly set the flag.
177
202
  // Infer ngrok usage from common domains (.ngrok.io or .ngrok-free.dev)
@@ -185,6 +210,7 @@ export function initializeApi(options) {
185
210
  iframe.enableAutoIframeResize();
186
211
  }
187
212
  logger = options.logger;
213
+ initialized = true;
188
214
  logDebug('[smartlinks] initializeApi', {
189
215
  baseURL,
190
216
  proxyMode,
@@ -215,6 +241,21 @@ export function setBearerToken(token) {
215
241
  export function getBaseURL() {
216
242
  return baseURL;
217
243
  }
244
+ /**
245
+ * Returns true if initializeApi() has been called at least once.
246
+ * Useful for guards in widgets or shared modules that want to skip
247
+ * initialization when another module has already done it.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * if (!isInitialized()) {
252
+ * initializeApi({ baseURL: 'https://smartlinks.app/api/v1' })
253
+ * }
254
+ * ```
255
+ */
256
+ export function isInitialized() {
257
+ return initialized;
258
+ }
218
259
  // Map of pending proxy requests: id -> {resolve, reject}
219
260
  const proxyPending = {};
220
261
  function generateProxyId() {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { initializeApi, request, sendCustomProxyMessage } from "./http";
1
+ export { initializeApi, isInitialized, request, sendCustomProxyMessage } from "./http";
2
2
  export * from "./api";
3
3
  export * from "./types";
4
4
  export { iframe } from "./iframe";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/index.ts
2
2
  // Top-level entrypoint of the npm package. Re-export initializeApi + all namespaces.
3
- export { initializeApi, request, sendCustomProxyMessage } from "./http";
3
+ export { initializeApi, isInitialized, request, sendCustomProxyMessage } from "./http";
4
4
  export * from "./api";
5
5
  export * from "./types";
6
6
  // Iframe namespace
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.45 | Generated: 2026-02-19T14:43:39.335Z
3
+ Version: 1.3.46 | Generated: 2026-02-19T21:09:09.402Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -87,7 +87,10 @@ Return whether proxy mode is currently enabled.
87
87
  extraHeaders?: Record<string, string>
88
88
  iframeAutoResize?: boolean // default true when in iframe
89
89
  logger?: Logger // optional console-like or function to enable verbose logging
90
- }) → `void`
90
+ /**
91
+ * When true, bypasses the idempotency guard and forces a full re-initialization.
92
+ * Use only when you intentionally need to reset all SDK state (e.g. in tests or
93
+ * when switching accounts) → `void`
91
94
  Call this once (e.g. at app startup) to configure baseURL/auth.
92
95
 
93
96
  **setNgrokSkipBrowserWarning**(flag: boolean) → `void`
@@ -102,6 +105,9 @@ Allows setting the bearerToken at runtime (e.g. after login/logout).
102
105
  **getBaseURL**() → `string | null`
103
106
  Get the currently configured API base URL. Returns null if initializeApi() has not been called yet.
104
107
 
108
+ **isInitialized**() → `boolean`
109
+ Returns true if initializeApi() has been called at least once. Useful for guards in widgets or shared modules that want to skip initialization when another module has already done it. ```ts if (!isInitialized()) { initializeApi({ baseURL: 'https://smartlinks.app/api/v1' }) } ```
110
+
105
111
  **proxyUploadFormData**(path: string,
106
112
  formData: FormData,
107
113
  onProgress?: (percent: number) → `void`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.3.45",
3
+ "version": "1.3.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",