@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.js CHANGED
@@ -669,7 +669,9 @@ var HttpClient = class {
669
669
  try {
670
670
  await this.refreshAndSaveSession();
671
671
  } catch (error2) {
672
- this.clearAuthSession();
672
+ if (error2 instanceof InsForgeError && (error2.statusCode === 401 || error2.statusCode === 403)) {
673
+ this.clearAuthSession();
674
+ }
673
675
  throw error2;
674
676
  }
675
677
  return await this.handleRequest(method, path, {
@@ -775,7 +777,9 @@ var HttpClient = class {
775
777
  try {
776
778
  newTokenData = await this.refreshAndSaveSession();
777
779
  } catch (error) {
778
- this.clearAuthSession();
780
+ if (error instanceof InsForgeError && (error.statusCode === 401 || error.statusCode === 403)) {
781
+ this.clearAuthSession();
782
+ }
779
783
  throw error;
780
784
  }
781
785
  const retryHeaders = new Headers(initHeaders);
@@ -1168,8 +1172,11 @@ var Auth = class {
1168
1172
  * Browser mode:
1169
1173
  * - Uses httpOnly refresh cookie and optional CSRF header.
1170
1174
  *
1171
- * Server mode (`isServerMode: true`):
1175
+ * Legacy server mode (`isServerMode: true`):
1172
1176
  * - Uses mobile auth flow and requires `refreshToken` in request body.
1177
+ *
1178
+ * SSR apps should prefer `createRefreshAuthRouter()` / `refreshAuth()` from
1179
+ * `@insforge/sdk/ssr`.
1173
1180
  */
1174
1181
  async refreshSession(options) {
1175
1182
  try {
@@ -1179,7 +1186,7 @@ var Auth = class {
1179
1186
  error: new InsForgeError(
1180
1187
  "refreshToken is required when refreshing session in server mode",
1181
1188
  400,
1182
- "REFRESH_TOKEN_REQUIRED"
1189
+ import_shared_schemas.ERROR_CODES.AUTH_UNAUTHORIZED
1183
1190
  )
1184
1191
  };
1185
1192
  }
@@ -1641,10 +1648,23 @@ var StorageBucket = class {
1641
1648
  */
1642
1649
  async download(path) {
1643
1650
  try {
1644
- const strategyResponse = await this.http.post(
1645
- `/api/storage/buckets/${this.bucketName}/objects/${encodeURIComponent(path)}/download-strategy`,
1646
- { expiresIn: 3600 }
1647
- );
1651
+ const encodedKey = encodeURIComponent(path);
1652
+ let strategyResponse;
1653
+ try {
1654
+ strategyResponse = await this.http.get(
1655
+ `/api/storage/buckets/${this.bucketName}/download-strategy/objects/${encodedKey}`
1656
+ );
1657
+ } catch (err) {
1658
+ const status = err instanceof InsForgeError ? err.statusCode : void 0;
1659
+ if (status === 404 || status === 405) {
1660
+ strategyResponse = await this.http.post(
1661
+ `/api/storage/buckets/${this.bucketName}/objects/${encodedKey}/download-strategy`,
1662
+ {}
1663
+ );
1664
+ } else {
1665
+ throw err;
1666
+ }
1667
+ }
1648
1668
  const downloadUrl = strategyResponse.url;
1649
1669
  const headers = {};
1650
1670
  if (strategyResponse.method === "direct") {