@insforge/sdk 1.2.9 → 1.3.0-ssr.0

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/index.mjs CHANGED
@@ -628,7 +628,9 @@ var HttpClient = class {
628
628
  try {
629
629
  await this.refreshAndSaveSession();
630
630
  } catch (error2) {
631
- this.clearAuthSession();
631
+ if (error2 instanceof InsForgeError && (error2.statusCode === 401 || error2.statusCode === 403)) {
632
+ this.clearAuthSession();
633
+ }
632
634
  throw error2;
633
635
  }
634
636
  return await this.handleRequest(method, path, {
@@ -734,7 +736,9 @@ var HttpClient = class {
734
736
  try {
735
737
  newTokenData = await this.refreshAndSaveSession();
736
738
  } catch (error) {
737
- this.clearAuthSession();
739
+ if (error instanceof InsForgeError && (error.statusCode === 401 || error.statusCode === 403)) {
740
+ this.clearAuthSession();
741
+ }
738
742
  throw error;
739
743
  }
740
744
  const retryHeaders = new Headers(initHeaders);
@@ -882,7 +886,7 @@ function cleanUrlParams(...params) {
882
886
  }
883
887
 
884
888
  // src/modules/auth/auth.ts
885
- import { oAuthProvidersSchema } from "@insforge/shared-schemas";
889
+ import { ERROR_CODES, oAuthProvidersSchema } from "@insforge/shared-schemas";
886
890
  var Auth = class {
887
891
  constructor(http, tokenManager, options = {}) {
888
892
  this.http = http;
@@ -1127,8 +1131,11 @@ var Auth = class {
1127
1131
  * Browser mode:
1128
1132
  * - Uses httpOnly refresh cookie and optional CSRF header.
1129
1133
  *
1130
- * Server mode (`isServerMode: true`):
1134
+ * Legacy server mode (`isServerMode: true`):
1131
1135
  * - Uses mobile auth flow and requires `refreshToken` in request body.
1136
+ *
1137
+ * SSR apps should prefer `createRefreshAuthRouter()` / `refreshAuth()` from
1138
+ * `@insforge/sdk/ssr`.
1132
1139
  */
1133
1140
  async refreshSession(options) {
1134
1141
  try {
@@ -1138,7 +1145,7 @@ var Auth = class {
1138
1145
  error: new InsForgeError(
1139
1146
  "refreshToken is required when refreshing session in server mode",
1140
1147
  400,
1141
- "REFRESH_TOKEN_REQUIRED"
1148
+ ERROR_CODES.AUTH_UNAUTHORIZED
1142
1149
  )
1143
1150
  };
1144
1151
  }
@@ -1600,10 +1607,23 @@ var StorageBucket = class {
1600
1607
  */
1601
1608
  async download(path) {
1602
1609
  try {
1603
- const strategyResponse = await this.http.post(
1604
- `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,
1605
- { expiresIn: 3600 }
1606
- );
1610
+ const encodedKey = encodeURIComponent(path);
1611
+ let strategyResponse;
1612
+ try {
1613
+ strategyResponse = await this.http.get(
1614
+ `/api/storage/buckets/${this.bucketName}/download-strategy/objects/${encodedKey}`
1615
+ );
1616
+ } catch (err) {
1617
+ const status = err instanceof InsForgeError ? err.statusCode : void 0;
1618
+ if (status === 404 || status === 405) {
1619
+ strategyResponse = await this.http.post(
1620
+ `/api/storage/buckets/${this.bucketName}/objects/${encodedKey}/download-strategy`,
1621
+ {}
1622
+ );
1623
+ } else {
1624
+ throw err;
1625
+ }
1626
+ }
1607
1627
  const downloadUrl = strategyResponse.url;
1608
1628
  const headers = {};
1609
1629
  if (strategyResponse.method === "direct") {