@proveanything/smartlinks 1.3.13 → 1.3.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/dist/docs/API_SUMMARY.md +23 -20
- package/dist/http.d.ts +5 -0
- package/dist/http.js +7 -0
- package/dist/iframeResponder.js +35 -29
- package/docs/API_SUMMARY.md +23 -20
- package/package.json +1 -1
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.16 | Generated: 2026-02-06T12:14:25.408Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -63,15 +63,15 @@ Core HTTP functions for API configuration and communication:
|
|
|
63
63
|
**isProxyEnabled**() → `boolean`
|
|
64
64
|
Return whether proxy mode is currently enabled.
|
|
65
65
|
|
|
66
|
-
**initializeApi**(options: {
|
|
67
|
-
baseURL: string
|
|
68
|
-
apiKey?: string
|
|
69
|
-
bearerToken?: string
|
|
70
|
-
proxyMode?: boolean
|
|
71
|
-
ngrokSkipBrowserWarning?: boolean
|
|
72
|
-
extraHeaders?: Record<string, string>
|
|
73
|
-
iframeAutoResize?: boolean // default true when in iframe
|
|
74
|
-
logger?: Logger // optional console-like or function to enable verbose logging
|
|
66
|
+
**initializeApi**(options: {
|
|
67
|
+
baseURL: string
|
|
68
|
+
apiKey?: string
|
|
69
|
+
bearerToken?: string
|
|
70
|
+
proxyMode?: boolean
|
|
71
|
+
ngrokSkipBrowserWarning?: boolean
|
|
72
|
+
extraHeaders?: Record<string, string>
|
|
73
|
+
iframeAutoResize?: boolean // default true when in iframe
|
|
74
|
+
logger?: Logger // optional console-like or function to enable verbose logging
|
|
75
75
|
}) → `void`
|
|
76
76
|
Call this once (e.g. at app startup) to configure baseURL/auth.
|
|
77
77
|
|
|
@@ -84,34 +84,37 @@ Replace or augment globally applied custom headers.
|
|
|
84
84
|
**setBearerToken**(token: string | undefined) → `void`
|
|
85
85
|
Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
86
86
|
|
|
87
|
-
**
|
|
88
|
-
|
|
87
|
+
**getBaseURL**() → `string | null`
|
|
88
|
+
Get the currently configured API base URL. Returns null if initializeApi() has not been called yet.
|
|
89
|
+
|
|
90
|
+
**proxyUploadFormData**(path: string,
|
|
91
|
+
formData: FormData,
|
|
89
92
|
onProgress?: (percent: number) → `void`
|
|
90
93
|
Upload a FormData payload via proxy with progress events using chunked postMessage. Parent is expected to implement the counterpart protocol.
|
|
91
94
|
|
|
92
95
|
**request**(path: string) → `Promise<T>`
|
|
93
96
|
Internal helper that performs a GET request to \`\${baseURL}\${path}\`, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
94
97
|
|
|
95
|
-
**post**(path: string,
|
|
96
|
-
body: any,
|
|
98
|
+
**post**(path: string,
|
|
99
|
+
body: any,
|
|
97
100
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
98
101
|
Internal helper that performs a POST request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
99
102
|
|
|
100
|
-
**put**(path: string,
|
|
101
|
-
body: any,
|
|
103
|
+
**put**(path: string,
|
|
104
|
+
body: any,
|
|
102
105
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
103
106
|
Internal helper that performs a PUT request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
104
107
|
|
|
105
|
-
**patch**(path: string,
|
|
106
|
-
body: any,
|
|
108
|
+
**patch**(path: string,
|
|
109
|
+
body: any,
|
|
107
110
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
108
111
|
Internal helper that performs a PATCH request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
109
112
|
|
|
110
|
-
**requestWithOptions**(path: string,
|
|
113
|
+
**requestWithOptions**(path: string,
|
|
111
114
|
options: RequestInit) → `Promise<T>`
|
|
112
115
|
Internal helper that performs a request to `${baseURL}${path}` with custom options, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
113
116
|
|
|
114
|
-
**del**(path: string,
|
|
117
|
+
**del**(path: string,
|
|
115
118
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
116
119
|
Internal helper that performs a DELETE request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
117
120
|
|
package/dist/http.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export declare function setExtraHeaders(headers: Record<string, string>): void;
|
|
|
25
25
|
* Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
26
26
|
*/
|
|
27
27
|
export declare function setBearerToken(token: string | undefined): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the currently configured API base URL.
|
|
30
|
+
* Returns null if initializeApi() has not been called yet.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getBaseURL(): string | null;
|
|
28
33
|
/**
|
|
29
34
|
* Upload a FormData payload via proxy with progress events using chunked postMessage.
|
|
30
35
|
* Parent is expected to implement the counterpart protocol.
|
package/dist/http.js
CHANGED
|
@@ -208,6 +208,13 @@ export function setExtraHeaders(headers) {
|
|
|
208
208
|
export function setBearerToken(token) {
|
|
209
209
|
bearerToken = token;
|
|
210
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Get the currently configured API base URL.
|
|
213
|
+
* Returns null if initializeApi() has not been called yet.
|
|
214
|
+
*/
|
|
215
|
+
export function getBaseURL() {
|
|
216
|
+
return baseURL;
|
|
217
|
+
}
|
|
211
218
|
// Map of pending proxy requests: id -> {resolve, reject}
|
|
212
219
|
const proxyPending = {};
|
|
213
220
|
function generateProxyId() {
|
package/dist/iframeResponder.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// =============================================================================
|
|
4
4
|
import * as cache from './cache';
|
|
5
5
|
import { collection } from './api/collection';
|
|
6
|
+
import { getBaseURL } from './http';
|
|
6
7
|
/**
|
|
7
8
|
* Parent-side iframe responder for SmartLinks microapp embedding.
|
|
8
9
|
*
|
|
@@ -217,38 +218,38 @@ export class IframeResponder {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
// Build URL - respect the URL format from server (hash routing or not)
|
|
220
|
-
|
|
221
|
-
//
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
let finalUrl = this.appUrl;
|
|
222
|
+
// Check if this URL uses hash routing (has a # in it)
|
|
223
|
+
const hasHash = finalUrl.includes('#');
|
|
224
|
+
console.log('[IframeResponder] URL has hash routing:', hasHash);
|
|
225
|
+
if (hasHash) {
|
|
226
|
+
// Hash-routed app - build params into the hash portion
|
|
227
|
+
const [baseWithHash, existingQuery = ''] = finalUrl.split('?');
|
|
228
|
+
const existingParams = new URLSearchParams(existingQuery);
|
|
229
|
+
params.forEach((value, key) => existingParams.set(key, value));
|
|
230
|
+
// Add initialPath if provided
|
|
231
|
+
if (this.options.initialPath) {
|
|
232
|
+
const path = this.options.initialPath.startsWith('/') ? this.options.initialPath : '/' + this.options.initialPath;
|
|
233
|
+
// Insert path before the ?
|
|
234
|
+
const [beforeHash, afterHash] = baseWithHash.split('#');
|
|
235
|
+
finalUrl = `${beforeHash}#${afterHash || ''}${path}?${existingParams.toString()}`;
|
|
232
236
|
}
|
|
233
237
|
else {
|
|
234
|
-
|
|
235
|
-
url.pathname = url.pathname.replace(/\/$/, '') + cleanPath;
|
|
238
|
+
finalUrl = `${baseWithHash}?${existingParams.toString()}`;
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
|
-
// Add query params
|
|
239
|
-
if (isHashRouted) {
|
|
240
|
-
// Hash routing - params go in the hash after ?
|
|
241
|
-
const hashParts = url.hash.slice(1).split('?'); // Remove # and split
|
|
242
|
-
const hashPath = hashParts[0];
|
|
243
|
-
const existingParams = hashParts[1] ? new URLSearchParams(hashParts[1]) : new URLSearchParams();
|
|
244
|
-
params.forEach((value, key) => existingParams.set(key, value));
|
|
245
|
-
url.hash = '#' + hashPath + '?' + existingParams.toString();
|
|
246
|
-
}
|
|
247
241
|
else {
|
|
248
|
-
// Path
|
|
242
|
+
// Path-routed app - use URL API to add params normally
|
|
243
|
+
const url = new URL(finalUrl);
|
|
244
|
+
// Add initialPath if provided
|
|
245
|
+
if (this.options.initialPath) {
|
|
246
|
+
const path = this.options.initialPath.startsWith('/') ? this.options.initialPath : '/' + this.options.initialPath;
|
|
247
|
+
url.pathname = url.pathname.replace(/\/$/, '') + path;
|
|
248
|
+
}
|
|
249
|
+
// Add query params
|
|
249
250
|
params.forEach((value, key) => url.searchParams.set(key, value));
|
|
251
|
+
finalUrl = url.toString();
|
|
250
252
|
}
|
|
251
|
-
const finalUrl = url.toString();
|
|
252
253
|
console.log('[IframeResponder] Final iframe URL:', finalUrl);
|
|
253
254
|
return finalUrl;
|
|
254
255
|
}
|
|
@@ -431,9 +432,11 @@ export class IframeResponder {
|
|
|
431
432
|
return;
|
|
432
433
|
}
|
|
433
434
|
}
|
|
434
|
-
// Forward to actual API using SDK's
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
// Forward to actual API using SDK's configured baseURL
|
|
436
|
+
const baseUrl = getBaseURL();
|
|
437
|
+
if (!baseUrl) {
|
|
438
|
+
throw new Error('SDK not initialized - call initializeApi() first');
|
|
439
|
+
}
|
|
437
440
|
const fetchOptions = {
|
|
438
441
|
method: proxyData.method,
|
|
439
442
|
headers: proxyData.headers,
|
|
@@ -524,7 +527,10 @@ export class IframeResponder {
|
|
|
524
527
|
upload.fields.forEach(([key, value]) => formData.append(key, value));
|
|
525
528
|
formData.append(upload.fileInfo.key || 'file', blob, upload.fileInfo.name || 'upload.bin');
|
|
526
529
|
const path = upload.path.startsWith('/') ? upload.path.slice(1) : upload.path;
|
|
527
|
-
const baseUrl =
|
|
530
|
+
const baseUrl = getBaseURL();
|
|
531
|
+
if (!baseUrl) {
|
|
532
|
+
throw new Error('SDK not initialized - call initializeApi() first');
|
|
533
|
+
}
|
|
528
534
|
const response = await fetch(`${baseUrl}/${path}`, {
|
|
529
535
|
method: 'POST',
|
|
530
536
|
body: formData,
|
package/docs/API_SUMMARY.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Smartlinks API Summary
|
|
2
2
|
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.16 | Generated: 2026-02-06T12:14:25.408Z
|
|
4
4
|
|
|
5
5
|
This is a concise summary of all available API functions and types.
|
|
6
6
|
|
|
@@ -63,15 +63,15 @@ Core HTTP functions for API configuration and communication:
|
|
|
63
63
|
**isProxyEnabled**() → `boolean`
|
|
64
64
|
Return whether proxy mode is currently enabled.
|
|
65
65
|
|
|
66
|
-
**initializeApi**(options: {
|
|
67
|
-
baseURL: string
|
|
68
|
-
apiKey?: string
|
|
69
|
-
bearerToken?: string
|
|
70
|
-
proxyMode?: boolean
|
|
71
|
-
ngrokSkipBrowserWarning?: boolean
|
|
72
|
-
extraHeaders?: Record<string, string>
|
|
73
|
-
iframeAutoResize?: boolean // default true when in iframe
|
|
74
|
-
logger?: Logger // optional console-like or function to enable verbose logging
|
|
66
|
+
**initializeApi**(options: {
|
|
67
|
+
baseURL: string
|
|
68
|
+
apiKey?: string
|
|
69
|
+
bearerToken?: string
|
|
70
|
+
proxyMode?: boolean
|
|
71
|
+
ngrokSkipBrowserWarning?: boolean
|
|
72
|
+
extraHeaders?: Record<string, string>
|
|
73
|
+
iframeAutoResize?: boolean // default true when in iframe
|
|
74
|
+
logger?: Logger // optional console-like or function to enable verbose logging
|
|
75
75
|
}) → `void`
|
|
76
76
|
Call this once (e.g. at app startup) to configure baseURL/auth.
|
|
77
77
|
|
|
@@ -84,34 +84,37 @@ Replace or augment globally applied custom headers.
|
|
|
84
84
|
**setBearerToken**(token: string | undefined) → `void`
|
|
85
85
|
Allows setting the bearerToken at runtime (e.g. after login/logout).
|
|
86
86
|
|
|
87
|
-
**
|
|
88
|
-
|
|
87
|
+
**getBaseURL**() → `string | null`
|
|
88
|
+
Get the currently configured API base URL. Returns null if initializeApi() has not been called yet.
|
|
89
|
+
|
|
90
|
+
**proxyUploadFormData**(path: string,
|
|
91
|
+
formData: FormData,
|
|
89
92
|
onProgress?: (percent: number) → `void`
|
|
90
93
|
Upload a FormData payload via proxy with progress events using chunked postMessage. Parent is expected to implement the counterpart protocol.
|
|
91
94
|
|
|
92
95
|
**request**(path: string) → `Promise<T>`
|
|
93
96
|
Internal helper that performs a GET request to \`\${baseURL}\${path}\`, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
94
97
|
|
|
95
|
-
**post**(path: string,
|
|
96
|
-
body: any,
|
|
98
|
+
**post**(path: string,
|
|
99
|
+
body: any,
|
|
97
100
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
98
101
|
Internal helper that performs a POST request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
99
102
|
|
|
100
|
-
**put**(path: string,
|
|
101
|
-
body: any,
|
|
103
|
+
**put**(path: string,
|
|
104
|
+
body: any,
|
|
102
105
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
103
106
|
Internal helper that performs a PUT request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
104
107
|
|
|
105
|
-
**patch**(path: string,
|
|
106
|
-
body: any,
|
|
108
|
+
**patch**(path: string,
|
|
109
|
+
body: any,
|
|
107
110
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
108
111
|
Internal helper that performs a PATCH request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. If body is FormData, Content-Type is not set. Returns the parsed JSON as T, or throws an Error.
|
|
109
112
|
|
|
110
|
-
**requestWithOptions**(path: string,
|
|
113
|
+
**requestWithOptions**(path: string,
|
|
111
114
|
options: RequestInit) → `Promise<T>`
|
|
112
115
|
Internal helper that performs a request to `${baseURL}${path}` with custom options, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
113
116
|
|
|
114
|
-
**del**(path: string,
|
|
117
|
+
**del**(path: string,
|
|
115
118
|
extraHeaders?: Record<string, string>) → `Promise<T>`
|
|
116
119
|
Internal helper that performs a DELETE request to `${baseURL}${path}`, injecting headers for apiKey or bearerToken if present. Returns the parsed JSON as T, or throws an Error.
|
|
117
120
|
|