@insforge/sdk 1.4.0 → 1.4.1
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/README.md +17 -1
- package/SDK-REFERENCE.md +5 -1
- package/dist/{client-CqfpCc8Z.d.mts → client-DoWwzWnh.d.ts} +52 -112
- package/dist/{client-CqfpCc8Z.d.ts → client-hYdj36T6.d.mts} +52 -112
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +105 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +102 -11
- package/dist/index.mjs.map +1 -1
- package/dist/middleware-BxJ0PzUT.d.mts +67 -0
- package/dist/middleware-DLZiheYP.d.ts +67 -0
- package/dist/ssr/middleware.d.mts +3 -0
- package/dist/ssr/middleware.d.ts +3 -0
- package/dist/ssr/middleware.js +461 -0
- package/dist/ssr/middleware.js.map +1 -0
- package/dist/ssr/middleware.mjs +428 -0
- package/dist/ssr/middleware.mjs.map +1 -0
- package/dist/ssr.d.mts +8 -69
- package/dist/ssr.d.ts +8 -69
- package/dist/ssr.js +107 -10
- package/dist/ssr.js.map +1 -1
- package/dist/ssr.mjs +107 -10
- package/dist/ssr.mjs.map +1 -1
- package/dist/types-NjykhyRq.d.mts +118 -0
- package/dist/types-NjykhyRq.d.ts +118 -0
- package/package.json +6 -1
package/dist/index.mjs
CHANGED
|
@@ -397,7 +397,7 @@ var HttpClient = class {
|
|
|
397
397
|
return Math.round(jitter);
|
|
398
398
|
}
|
|
399
399
|
shouldRefreshAccessToken(statusCode, errorCode, authToken, options = {}) {
|
|
400
|
-
return statusCode === 401 && REFRESHABLE_AUTH_ERROR_CODES.has(errorCode ?? "") && !this.config.isServerMode && !this.config.edgeFunctionToken && !options.skipAuthRefresh && authToken !== null;
|
|
400
|
+
return statusCode === 401 && REFRESHABLE_AUTH_ERROR_CODES.has(errorCode ?? "") && !this.config.isServerMode && !this.config.accessToken && !this.config.edgeFunctionToken && !options.skipAuthRefresh && authToken !== null;
|
|
401
401
|
}
|
|
402
402
|
async fetchWithRetry(args) {
|
|
403
403
|
const {
|
|
@@ -1609,7 +1609,7 @@ var StorageBucket = class {
|
|
|
1609
1609
|
size: file.size,
|
|
1610
1610
|
mimeType: file.type || "application/octet-stream",
|
|
1611
1611
|
uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1612
|
-
url: this.getPublicUrl(strategy.key)
|
|
1612
|
+
url: this.getPublicUrl(strategy.key).data.publicUrl
|
|
1613
1613
|
},
|
|
1614
1614
|
error: null
|
|
1615
1615
|
};
|
|
@@ -1681,11 +1681,101 @@ var StorageBucket = class {
|
|
|
1681
1681
|
}
|
|
1682
1682
|
}
|
|
1683
1683
|
/**
|
|
1684
|
-
* Get public URL for a
|
|
1684
|
+
* Get the public URL for an object in a public bucket.
|
|
1685
|
+
*
|
|
1686
|
+
* Pure string construction — no network call, no auth. The URL only resolves
|
|
1687
|
+
* if the bucket is public; for private objects use {@link createSignedUrl}.
|
|
1688
|
+
*
|
|
1685
1689
|
* @param path - The object key/path
|
|
1690
|
+
* @returns `{ data: { publicUrl }, error }` — matches the external SDK pattern,
|
|
1691
|
+
* so `const { data } = getPublicUrl(path)` then `data.publicUrl`.
|
|
1686
1692
|
*/
|
|
1687
1693
|
getPublicUrl(path) {
|
|
1688
|
-
|
|
1694
|
+
const publicUrl = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;
|
|
1695
|
+
return { data: { publicUrl }, error: null };
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Resolve a download strategy (signed or direct URL) for an object with a
|
|
1699
|
+
* caller-supplied TTL. Prefers the canonical GET route and falls back to the
|
|
1700
|
+
* legacy POST alias so signed-URL creation still works against older backends
|
|
1701
|
+
* that predate the GET route (they return 404/405 for it). A genuine
|
|
1702
|
+
* "object not found" (STORAGE_NOT_FOUND) is not retried.
|
|
1703
|
+
*/
|
|
1704
|
+
async requestDownloadStrategy(path, expiresIn) {
|
|
1705
|
+
const encoded = encodeURIComponent(path);
|
|
1706
|
+
try {
|
|
1707
|
+
return await this.http.get(
|
|
1708
|
+
`/api/storage/buckets/${this.bucketName}/download-strategy/objects/${encoded}`,
|
|
1709
|
+
{ params: { expiresIn: expiresIn.toString() } }
|
|
1710
|
+
);
|
|
1711
|
+
} catch (error) {
|
|
1712
|
+
const status = error instanceof InsForgeError ? error.statusCode : void 0;
|
|
1713
|
+
const isMissingRoute = (status === 404 || status === 405) && !(error instanceof InsForgeError && error.error === "STORAGE_NOT_FOUND");
|
|
1714
|
+
if (!isMissingRoute) throw error;
|
|
1715
|
+
return await this.http.post(
|
|
1716
|
+
`/api/storage/buckets/${this.bucketName}/objects/${encoded}/download-strategy`,
|
|
1717
|
+
{ expiresIn }
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Create a signed URL for an object.
|
|
1723
|
+
*
|
|
1724
|
+
* Returns a time-limited, credential-free URL that can be handed directly to
|
|
1725
|
+
* a browser (`<img src>`), an email, or a third party — no SDK or session is
|
|
1726
|
+
* needed to fetch it. Authorization is enforced when the URL is minted (the
|
|
1727
|
+
* caller must be allowed to read the object), so the resulting link is a
|
|
1728
|
+
* pre-authorized capability scoped to this one object until it expires.
|
|
1729
|
+
*
|
|
1730
|
+
* @param path - The object key/path
|
|
1731
|
+
* @param expiresIn - Lifetime in seconds (default 3600 = 1h, max 604800 = 7d).
|
|
1732
|
+
* Honored for private buckets; public buckets return their long-lived URL.
|
|
1733
|
+
*/
|
|
1734
|
+
async createSignedUrl(path, expiresIn = 3600) {
|
|
1735
|
+
try {
|
|
1736
|
+
const strategy = await this.requestDownloadStrategy(path, expiresIn);
|
|
1737
|
+
return {
|
|
1738
|
+
data: {
|
|
1739
|
+
signedUrl: strategy.url,
|
|
1740
|
+
expiresAt: strategy.expiresAt ? new Date(strategy.expiresAt).toISOString() : null
|
|
1741
|
+
},
|
|
1742
|
+
error: null
|
|
1743
|
+
};
|
|
1744
|
+
} catch (error) {
|
|
1745
|
+
return {
|
|
1746
|
+
data: null,
|
|
1747
|
+
error: error instanceof InsForgeError ? error : new InsForgeError("Failed to create signed URL", 500, "STORAGE_ERROR")
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
/**
|
|
1752
|
+
* Create signed URLs for multiple objects in a single call.
|
|
1753
|
+
*
|
|
1754
|
+
* Each entry resolves independently: a failure on one key (not found / not
|
|
1755
|
+
* permitted) is reported on that entry's `error` without failing the rest.
|
|
1756
|
+
*
|
|
1757
|
+
* @param paths - The object keys/paths
|
|
1758
|
+
* @param expiresIn - Lifetime in seconds (default 3600 = 1h, max 604800 = 7d)
|
|
1759
|
+
*/
|
|
1760
|
+
async createSignedUrls(paths, expiresIn = 3600) {
|
|
1761
|
+
try {
|
|
1762
|
+
const data = await Promise.all(
|
|
1763
|
+
paths.map(async (path) => {
|
|
1764
|
+
const { data: signed, error } = await this.createSignedUrl(path, expiresIn);
|
|
1765
|
+
return {
|
|
1766
|
+
path,
|
|
1767
|
+
signedUrl: signed?.signedUrl ?? null,
|
|
1768
|
+
error: error ? error.message : null
|
|
1769
|
+
};
|
|
1770
|
+
})
|
|
1771
|
+
);
|
|
1772
|
+
return { data, error: null };
|
|
1773
|
+
} catch (error) {
|
|
1774
|
+
return {
|
|
1775
|
+
data: null,
|
|
1776
|
+
error: error instanceof InsForgeError ? error : new InsForgeError("Failed to create signed URLs", 500, "STORAGE_ERROR")
|
|
1777
|
+
};
|
|
1778
|
+
}
|
|
1689
1779
|
}
|
|
1690
1780
|
/**
|
|
1691
1781
|
* List objects in the bucket
|
|
@@ -2664,12 +2754,13 @@ var InsForgeClient = class {
|
|
|
2664
2754
|
const logger = new Logger(config.debug);
|
|
2665
2755
|
this.tokenManager = new TokenManager();
|
|
2666
2756
|
this.http = new HttpClient(config, this.tokenManager, logger);
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
this.
|
|
2757
|
+
const accessToken = config.accessToken ?? config.edgeFunctionToken;
|
|
2758
|
+
if (accessToken) {
|
|
2759
|
+
this.http.setAuthToken(accessToken);
|
|
2760
|
+
this.tokenManager.setAccessToken(accessToken);
|
|
2670
2761
|
}
|
|
2671
2762
|
this.auth = new Auth(this.http, this.tokenManager, {
|
|
2672
|
-
isServerMode: config.isServerMode ?? !!
|
|
2763
|
+
isServerMode: config.isServerMode ?? !!accessToken
|
|
2673
2764
|
});
|
|
2674
2765
|
this.database = new Database(this.http);
|
|
2675
2766
|
this.storage = new Storage(this.http);
|
|
@@ -2748,11 +2839,11 @@ function createAdminClient(config) {
|
|
|
2748
2839
|
}
|
|
2749
2840
|
return new InsForgeClient({
|
|
2750
2841
|
...clientConfig,
|
|
2751
|
-
|
|
2842
|
+
accessToken: apiKey,
|
|
2752
2843
|
isServerMode: true
|
|
2753
2844
|
});
|
|
2754
2845
|
}
|
|
2755
|
-
var
|
|
2846
|
+
var src_default = InsForgeClient;
|
|
2756
2847
|
export {
|
|
2757
2848
|
AI,
|
|
2758
2849
|
Auth,
|
|
@@ -2770,6 +2861,6 @@ export {
|
|
|
2770
2861
|
TokenManager,
|
|
2771
2862
|
createAdminClient,
|
|
2772
2863
|
createClient,
|
|
2773
|
-
|
|
2864
|
+
src_default as default
|
|
2774
2865
|
};
|
|
2775
2866
|
//# sourceMappingURL=index.mjs.map
|