@sylphx/sdk 0.3.7 → 0.4.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.
@@ -1313,6 +1313,13 @@ var SylphxError = class _SylphxError extends Error {
1313
1313
  static isRateLimited(err) {
1314
1314
  return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS";
1315
1315
  }
1316
+ /**
1317
+ * Check if error is an account lockout error (too many failed login attempts).
1318
+ * When true, `error.data?.lockoutUntil` contains the ISO 8601 timestamp when the lockout expires.
1319
+ */
1320
+ static isAccountLocked(err) {
1321
+ return err instanceof _SylphxError && err.code === "TOO_MANY_REQUESTS" && err.data?.code === "ACCOUNT_LOCKED";
1322
+ }
1316
1323
  /**
1317
1324
  * Check if error is a quota exceeded error (plan limit reached)
1318
1325
  */
@@ -2619,11 +2626,16 @@ async function cachedFetch(params) {
2619
2626
  }
2620
2627
  }
2621
2628
  function sanitizeOptions(options) {
2622
- return {
2623
- ...options,
2624
- secretKey: validateAndSanitizeSecretKey(options.secretKey),
2625
- platformUrl: (options.platformUrl ?? `https://${DEFAULT_SDK_API_HOST}`).trim()
2626
- };
2629
+ const secretKey = validateAndSanitizeSecretKey(options.secretKey);
2630
+ let platformUrl;
2631
+ if (options.platformUrl) {
2632
+ platformUrl = options.platformUrl.trim();
2633
+ } else {
2634
+ const parts = secretKey.split("_");
2635
+ const ref = parts.length === 4 ? parts[2] : null;
2636
+ platformUrl = ref ? `https://${ref}.${DEFAULT_SDK_API_HOST}` : `https://${DEFAULT_SDK_API_HOST}`;
2637
+ }
2638
+ return { ...options, secretKey, platformUrl };
2627
2639
  }
2628
2640
  function sdkHeaders(secretKey) {
2629
2641
  return { "x-app-secret": secretKey };
@@ -2683,13 +2695,20 @@ async function getAppMetadata(options) {
2683
2695
  });
2684
2696
  }
2685
2697
  async function getAppConfig(options) {
2686
- const { secretKey, appId, platformUrl } = options;
2698
+ const { secretKey, appId } = options;
2699
+ const resolvedPlatformUrl = (() => {
2700
+ if (options.platformUrl) return options.platformUrl.trim();
2701
+ const keyForRef = secretKey || appId;
2702
+ const parts = keyForRef?.split("_") ?? [];
2703
+ const ref = parts.length === 4 ? parts[2] : null;
2704
+ return ref ? `https://${ref}.${DEFAULT_SDK_API_HOST}` : `https://${DEFAULT_SDK_API_HOST}`;
2705
+ })();
2687
2706
  const [plans, consentTypes, oauthProviders, featureFlags, app] = await Promise.all([
2688
- getPlans({ secretKey, platformUrl }),
2689
- getConsentTypes({ secretKey, platformUrl }),
2690
- getOAuthProvidersWithInfo({ appId, platformUrl }),
2691
- getFeatureFlags({ secretKey, platformUrl }),
2692
- getAppMetadata({ secretKey, platformUrl })
2707
+ getPlans({ secretKey, platformUrl: resolvedPlatformUrl }),
2708
+ getConsentTypes({ secretKey, platformUrl: resolvedPlatformUrl }),
2709
+ getOAuthProvidersWithInfo({ appId, platformUrl: resolvedPlatformUrl }),
2710
+ getFeatureFlags({ secretKey, platformUrl: resolvedPlatformUrl }),
2711
+ getAppMetadata({ secretKey, platformUrl: resolvedPlatformUrl })
2693
2712
  ]);
2694
2713
  return {
2695
2714
  plans,