@insforge/sdk 1.3.2-razorpay.1 → 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/dist/ssr.d.ts CHANGED
@@ -1,72 +1,23 @@
1
- import { a as InsForgeConfig, I as InsForgeClient, m as AuthRefreshResponse, e as InsForgeError } from './client-Co8KxT-n.js';
1
+ import { I as InsForgeClient } from './client-DoWwzWnh.js';
2
+ import { I as InsForgeConfig, e as AuthRefreshResponse, d as InsForgeError } from './types-NjykhyRq.js';
3
+ import { A as AuthCookieSettings, C as CookieStore } from './middleware-DLZiheYP.js';
4
+ export { f as AuthCookieNames, h as AuthCookieOptions, i as CookieOptions, j as CookieReader, k as CookieWriter, D as DEFAULT_ACCESS_TOKEN_COOKIE, b as DEFAULT_REFRESH_TOKEN_COOKIE, U as UpdateSessionOptions, a as UpdateSessionResult, c as accessTokenCookieOptions, d as clearAuthCookies, g as getAccessTokenCookieName, e as getRefreshTokenCookieName, r as refreshTokenCookieOptions, s as setAuthCookies, u as updateSession } from './middleware-DLZiheYP.js';
2
5
  import '@insforge/shared-schemas';
3
6
  import '@supabase/postgrest-js';
4
7
 
5
- declare const DEFAULT_ACCESS_TOKEN_COOKIE = "insforge_access_token";
6
- declare const DEFAULT_REFRESH_TOKEN_COOKIE = "insforge_refresh_token";
7
- interface AuthCookieNames {
8
- accessToken?: string;
9
- refreshToken?: string;
10
- }
11
- interface CookieOptions {
12
- domain?: string;
13
- path?: string;
14
- expires?: Date;
15
- maxAge?: number;
16
- httpOnly?: boolean;
17
- secure?: boolean;
18
- sameSite?: 'lax' | 'strict' | 'none';
19
- }
20
- interface AuthCookieOptions {
21
- accessToken?: CookieOptions;
22
- refreshToken?: CookieOptions;
23
- }
24
- type CookieStoreValue = string | {
25
- value?: string | null;
26
- } | undefined | null;
27
- interface CookieReader {
28
- get(name: string): CookieStoreValue;
29
- }
30
- interface CookieWriter {
31
- set?(name: string, value: string, options?: CookieOptions): unknown;
32
- set?(options: {
33
- name: string;
34
- value: string;
35
- } & CookieOptions): unknown;
36
- delete?(name: string): unknown;
37
- delete?(options: {
38
- name: string;
39
- } & CookieOptions): unknown;
40
- }
41
- interface CookieStore extends CookieReader, CookieWriter {
42
- }
43
- interface AuthCookieSettings {
44
- names?: AuthCookieNames;
45
- options?: AuthCookieOptions;
46
- }
47
- declare function getAccessTokenCookieName(names?: AuthCookieNames): string;
48
- declare function getRefreshTokenCookieName(names?: AuthCookieNames): string;
49
- declare function accessTokenCookieOptions(token: string, overrides?: CookieOptions): CookieOptions;
50
- declare function refreshTokenCookieOptions(token: string, overrides?: CookieOptions): CookieOptions;
51
- declare function setAuthCookies(cookies: CookieWriter | undefined, tokens: {
52
- accessToken: string;
53
- refreshToken?: string | null;
54
- }, settings?: AuthCookieSettings): void;
55
- declare function clearAuthCookies(cookies: CookieWriter | undefined, settings?: AuthCookieSettings): void;
56
-
57
- interface CreateBrowserClientOptions extends Omit<InsForgeConfig, 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
8
+ interface CreateBrowserClientOptions extends Omit<InsForgeConfig, 'accessToken' | 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
58
9
  refreshUrl?: string;
59
10
  refreshLeewaySeconds?: number;
60
11
  }
61
12
  declare function createBrowserClient(options?: CreateBrowserClientOptions): InsForgeClient;
62
13
 
63
- interface CreateServerClientOptions extends Omit<InsForgeConfig, 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
14
+ interface CreateServerClientOptions extends Omit<InsForgeConfig, 'accessToken' | 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
64
15
  cookies?: Pick<CookieStore, 'get'>;
65
16
  accessToken?: string;
66
17
  }
67
18
  declare function createServerClient(options?: CreateServerClientOptions): InsForgeClient;
68
19
 
69
- interface RefreshAuthOptions extends Omit<InsForgeConfig, 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
20
+ interface RefreshAuthOptions extends Omit<InsForgeConfig, 'accessToken' | 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
70
21
  request?: Request;
71
22
  cookies?: Pick<CookieStore, 'get'>;
72
23
  refreshToken?: string;
@@ -84,16 +35,4 @@ declare function createRefreshAuthRouter(options?: Omit<RefreshAuthOptions, 'req
84
35
  POST: RefreshAuthRouteHandler;
85
36
  };
86
37
 
87
- interface UpdateSessionOptions extends Omit<InsForgeConfig, 'edgeFunctionToken' | 'isServerMode' | 'auth'>, AuthCookieSettings {
88
- requestCookies: CookieStore;
89
- responseCookies: CookieStore;
90
- refreshLeewaySeconds?: number;
91
- }
92
- interface UpdateSessionResult {
93
- refreshed: boolean;
94
- accessToken: string | null;
95
- error: InsForgeError | null;
96
- }
97
- declare function updateSession(options: UpdateSessionOptions): Promise<UpdateSessionResult>;
98
-
99
- export { type AuthCookieNames, type AuthCookieOptions, type AuthCookieSettings, type CookieOptions, type CookieReader, type CookieStore, type CookieWriter, type CreateBrowserClientOptions, type CreateServerClientOptions, DEFAULT_ACCESS_TOKEN_COOKIE, DEFAULT_REFRESH_TOKEN_COOKIE, type RefreshAuthOptions, type RefreshAuthResult, type RefreshAuthRouteHandler, type UpdateSessionOptions, type UpdateSessionResult, accessTokenCookieOptions, clearAuthCookies, createBrowserClient, createRefreshAuthRouter, createServerClient, getAccessTokenCookieName, getRefreshTokenCookieName, refreshAuth, refreshTokenCookieOptions, setAuthCookies, updateSession };
38
+ export { AuthCookieSettings, CookieStore, type CreateBrowserClientOptions, type CreateServerClientOptions, type RefreshAuthOptions, type RefreshAuthResult, type RefreshAuthRouteHandler, createBrowserClient, createRefreshAuthRouter, createServerClient, refreshAuth };
package/dist/ssr.js CHANGED
@@ -445,7 +445,7 @@ var HttpClient = class {
445
445
  return Math.round(jitter);
446
446
  }
447
447
  shouldRefreshAccessToken(statusCode, errorCode, authToken, options = {}) {
448
- return statusCode === 401 && REFRESHABLE_AUTH_ERROR_CODES.has(errorCode ?? "") && !this.config.isServerMode && !this.config.edgeFunctionToken && !options.skipAuthRefresh && authToken !== null;
448
+ return statusCode === 401 && REFRESHABLE_AUTH_ERROR_CODES.has(errorCode ?? "") && !this.config.isServerMode && !this.config.accessToken && !this.config.edgeFunctionToken && !options.skipAuthRefresh && authToken !== null;
449
449
  }
450
450
  async fetchWithRetry(args) {
451
451
  const {
@@ -1657,7 +1657,7 @@ var StorageBucket = class {
1657
1657
  size: file.size,
1658
1658
  mimeType: file.type || "application/octet-stream",
1659
1659
  uploadedAt: (/* @__PURE__ */ new Date()).toISOString(),
1660
- url: this.getPublicUrl(strategy.key)
1660
+ url: this.getPublicUrl(strategy.key).data.publicUrl
1661
1661
  },
1662
1662
  error: null
1663
1663
  };
@@ -1729,11 +1729,101 @@ var StorageBucket = class {
1729
1729
  }
1730
1730
  }
1731
1731
  /**
1732
- * Get public URL for a file
1732
+ * Get the public URL for an object in a public bucket.
1733
+ *
1734
+ * Pure string construction — no network call, no auth. The URL only resolves
1735
+ * if the bucket is public; for private objects use {@link createSignedUrl}.
1736
+ *
1733
1737
  * @param path - The object key/path
1738
+ * @returns `{ data: { publicUrl }, error }` — matches the external SDK pattern,
1739
+ * so `const { data } = getPublicUrl(path)` then `data.publicUrl`.
1734
1740
  */
1735
1741
  getPublicUrl(path) {
1736
- return `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;
1742
+ const publicUrl = `${this.http.baseUrl}/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}`;
1743
+ return { data: { publicUrl }, error: null };
1744
+ }
1745
+ /**
1746
+ * Resolve a download strategy (signed or direct URL) for an object with a
1747
+ * caller-supplied TTL. Prefers the canonical GET route and falls back to the
1748
+ * legacy POST alias so signed-URL creation still works against older backends
1749
+ * that predate the GET route (they return 404/405 for it). A genuine
1750
+ * "object not found" (STORAGE_NOT_FOUND) is not retried.
1751
+ */
1752
+ async requestDownloadStrategy(path, expiresIn) {
1753
+ const encoded = encodeURIComponent(path);
1754
+ try {
1755
+ return await this.http.get(
1756
+ `/api/storage/buckets/${this.bucketName}/download-strategy/objects/${encoded}`,
1757
+ { params: { expiresIn: expiresIn.toString() } }
1758
+ );
1759
+ } catch (error) {
1760
+ const status = error instanceof InsForgeError ? error.statusCode : void 0;
1761
+ const isMissingRoute = (status === 404 || status === 405) && !(error instanceof InsForgeError && error.error === "STORAGE_NOT_FOUND");
1762
+ if (!isMissingRoute) throw error;
1763
+ return await this.http.post(
1764
+ `/api/storage/buckets/${this.bucketName}/objects/${encoded}/download-strategy`,
1765
+ { expiresIn }
1766
+ );
1767
+ }
1768
+ }
1769
+ /**
1770
+ * Create a signed URL for an object.
1771
+ *
1772
+ * Returns a time-limited, credential-free URL that can be handed directly to
1773
+ * a browser (`<img src>`), an email, or a third party — no SDK or session is
1774
+ * needed to fetch it. Authorization is enforced when the URL is minted (the
1775
+ * caller must be allowed to read the object), so the resulting link is a
1776
+ * pre-authorized capability scoped to this one object until it expires.
1777
+ *
1778
+ * @param path - The object key/path
1779
+ * @param expiresIn - Lifetime in seconds (default 3600 = 1h, max 604800 = 7d).
1780
+ * Honored for private buckets; public buckets return their long-lived URL.
1781
+ */
1782
+ async createSignedUrl(path, expiresIn = 3600) {
1783
+ try {
1784
+ const strategy = await this.requestDownloadStrategy(path, expiresIn);
1785
+ return {
1786
+ data: {
1787
+ signedUrl: strategy.url,
1788
+ expiresAt: strategy.expiresAt ? new Date(strategy.expiresAt).toISOString() : null
1789
+ },
1790
+ error: null
1791
+ };
1792
+ } catch (error) {
1793
+ return {
1794
+ data: null,
1795
+ error: error instanceof InsForgeError ? error : new InsForgeError("Failed to create signed URL", 500, "STORAGE_ERROR")
1796
+ };
1797
+ }
1798
+ }
1799
+ /**
1800
+ * Create signed URLs for multiple objects in a single call.
1801
+ *
1802
+ * Each entry resolves independently: a failure on one key (not found / not
1803
+ * permitted) is reported on that entry's `error` without failing the rest.
1804
+ *
1805
+ * @param paths - The object keys/paths
1806
+ * @param expiresIn - Lifetime in seconds (default 3600 = 1h, max 604800 = 7d)
1807
+ */
1808
+ async createSignedUrls(paths, expiresIn = 3600) {
1809
+ try {
1810
+ const data = await Promise.all(
1811
+ paths.map(async (path) => {
1812
+ const { data: signed, error } = await this.createSignedUrl(path, expiresIn);
1813
+ return {
1814
+ path,
1815
+ signedUrl: signed?.signedUrl ?? null,
1816
+ error: error ? error.message : null
1817
+ };
1818
+ })
1819
+ );
1820
+ return { data, error: null };
1821
+ } catch (error) {
1822
+ return {
1823
+ data: null,
1824
+ error: error instanceof InsForgeError ? error : new InsForgeError("Failed to create signed URLs", 500, "STORAGE_ERROR")
1825
+ };
1826
+ }
1737
1827
  }
1738
1828
  /**
1739
1829
  * List objects in the bucket
@@ -2712,12 +2802,13 @@ var InsForgeClient = class {
2712
2802
  const logger = new Logger(config.debug);
2713
2803
  this.tokenManager = new TokenManager();
2714
2804
  this.http = new HttpClient(config, this.tokenManager, logger);
2715
- if (config.edgeFunctionToken) {
2716
- this.http.setAuthToken(config.edgeFunctionToken);
2717
- this.tokenManager.setAccessToken(config.edgeFunctionToken);
2805
+ const accessToken = config.accessToken ?? config.edgeFunctionToken;
2806
+ if (accessToken) {
2807
+ this.http.setAuthToken(accessToken);
2808
+ this.tokenManager.setAccessToken(accessToken);
2718
2809
  }
2719
2810
  this.auth = new Auth(this.http, this.tokenManager, {
2720
- isServerMode: config.isServerMode ?? !!config.edgeFunctionToken
2811
+ isServerMode: config.isServerMode ?? !!accessToken
2721
2812
  });
2722
2813
  this.database = new Database(this.http);
2723
2814
  this.storage = new Storage(this.http);
@@ -3123,7 +3214,10 @@ function createBrowserClient(options = {}) {
3123
3214
  ...options,
3124
3215
  baseUrl,
3125
3216
  anonKey,
3126
- fetch: ssrFetch
3217
+ fetch: ssrFetch,
3218
+ // Browser clients manage tokens via the refresh route, not a static
3219
+ // config token; shadow any untyped accessToken in the options spread.
3220
+ accessToken: void 0
3127
3221
  });
3128
3222
  const setAccessToken = client.setAccessToken.bind(client);
3129
3223
  client.setAccessToken = (token) => {
@@ -3161,7 +3255,10 @@ function createServerClient(options = {}) {
3161
3255
  baseUrl,
3162
3256
  anonKey,
3163
3257
  isServerMode: true,
3164
- edgeFunctionToken: accessToken ?? void 0
3258
+ accessToken: accessToken ?? void 0,
3259
+ // The cookie/option token is the only credential source here; shadow any
3260
+ // untyped edgeFunctionToken smuggled through the options spread.
3261
+ edgeFunctionToken: void 0
3165
3262
  });
3166
3263
  }
3167
3264