@lessly/sdk-app 94.0.0 → 94.2.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
@@ -33,6 +33,27 @@ function isAccessDenied(err) {
33
33
  const { status, code } = err;
34
34
  return status === 403 && typeof code === "string" && ACCESS_DENIED_CODES.has(code);
35
35
  }
36
+ var ENTITLEMENT_ERRORS = /* @__PURE__ */ new Set(["entitlement_exhausted", "entitlement_unavailable"]);
37
+ function entitlementRefusal(err) {
38
+ if (typeof err !== "object" || err === null) return null;
39
+ const { status, body } = err;
40
+ if (status !== 402 || typeof body !== "object" || body === null) return null;
41
+ const { error } = body;
42
+ return typeof error === "string" && ENTITLEMENT_ERRORS.has(error) ? body : null;
43
+ }
44
+ function isEntitlementError(err) {
45
+ return entitlementRefusal(err) !== null;
46
+ }
47
+ function upgradeUrl(err) {
48
+ const url = entitlementRefusal(err)?.upgrade_url;
49
+ if (typeof url !== "string") return null;
50
+ try {
51
+ const { protocol } = new URL(url);
52
+ return protocol === "https:" || protocol === "http:" ? url : null;
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
36
57
 
37
58
  // src/runtime/csrf.ts
38
59
  var CSRF_COOKIES = ["lepsto_csrf", "lessly_csrf"];
@@ -1276,6 +1297,6 @@ var operations2 = operations;
1276
1297
  // src/runtime/compositions.ts
1277
1298
  var compositions2 = compositions;
1278
1299
 
1279
- export { LesslyApiError, accessReason, compositions2 as compositions, connectStream, createLesslyApp, isAccessDenied, operations2 as operations, platformApiBaseUrl };
1300
+ export { LesslyApiError, accessReason, compositions2 as compositions, connectStream, createLesslyApp, isAccessDenied, isEntitlementError, operations2 as operations, platformApiBaseUrl, upgradeUrl };
1280
1301
  //# sourceMappingURL=index.js.map
1281
1302
  //# sourceMappingURL=index.js.map