owostack 0.3.0 → 0.3.2

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.d.ts CHANGED
@@ -137,6 +137,7 @@ declare function plan(slug: string, config: {
137
137
  price: number;
138
138
  currency: Currency;
139
139
  interval: PlanInterval;
140
+ billingType?: "recurring" | "one_time";
140
141
  features: PlanFeatureEntry[];
141
142
  planGroup?: string;
142
143
  trialDays?: number;
package/dist/index.js CHANGED
@@ -378,7 +378,8 @@ function plan(slug, config) {
378
378
  return {
379
379
  _type: "plan",
380
380
  slug,
381
- ...config
381
+ ...config,
382
+ billingType: config.billingType ?? "recurring"
382
383
  };
383
384
  }
384
385
  function creditPack(slug, config) {
@@ -438,6 +439,7 @@ function buildSyncPayload(catalog, defaultProvider) {
438
439
  price: p.price,
439
440
  currency: p.currency,
440
441
  interval: p.interval,
442
+ billingType: p.billingType,
441
443
  planGroup: p.planGroup ?? void 0,
442
444
  trialDays: p.trialDays ?? void 0,
443
445
  provider: p.provider ?? void 0,
@@ -816,12 +818,8 @@ var Owostack = class {
816
818
  body: JSON.stringify(body)
817
819
  });
818
820
  if (!response.ok) {
819
- const resp = await response.json();
820
- const errorData = resp.error || resp;
821
- throw new OwostackError(
822
- errorData.code || "unknown_error",
823
- errorData.message || errorData.error || "Request failed"
824
- );
821
+ const errorData = extractErrorDetails(await readErrorResponse(response));
822
+ throw new OwostackError(errorData.code, errorData.message);
825
823
  }
826
824
  return response.json();
827
825
  }
@@ -844,16 +842,64 @@ var Owostack = class {
844
842
  }
845
843
  });
846
844
  if (!response.ok) {
847
- const resp = await response.json();
848
- const errorData = resp.error || resp;
849
- throw new OwostackError(
850
- errorData.code || "unknown_error",
851
- errorData.message || errorData.error || "Request failed"
852
- );
845
+ const errorData = extractErrorDetails(await readErrorResponse(response));
846
+ throw new OwostackError(errorData.code, errorData.message);
853
847
  }
854
848
  return response.json();
855
849
  }
856
850
  };
851
+ function isRecord(value) {
852
+ return typeof value === "object" && value !== null;
853
+ }
854
+ function asNonEmptyString(value) {
855
+ return typeof value === "string" && value.length > 0 ? value : void 0;
856
+ }
857
+ async function readErrorResponse(response) {
858
+ const raw = await response.text().catch(() => "");
859
+ if (!raw) return null;
860
+ try {
861
+ return JSON.parse(raw);
862
+ } catch {
863
+ return raw;
864
+ }
865
+ }
866
+ function extractErrorDetails(payload) {
867
+ if (typeof payload === "string") {
868
+ return {
869
+ code: "unknown_error",
870
+ message: payload
871
+ };
872
+ }
873
+ if (!isRecord(payload)) {
874
+ return {
875
+ code: "unknown_error",
876
+ message: "Request failed"
877
+ };
878
+ }
879
+ const directCode = asNonEmptyString(payload.code);
880
+ const directMessage = asNonEmptyString(payload.message);
881
+ const directError = payload.error;
882
+ if (typeof directError === "string") {
883
+ return {
884
+ code: directCode || "unknown_error",
885
+ message: directError
886
+ };
887
+ }
888
+ if (isRecord(directError)) {
889
+ const nestedCode = asNonEmptyString(directError.code);
890
+ const nestedMessage = asNonEmptyString(directError.message) || asNonEmptyString(directError.error);
891
+ if (nestedMessage) {
892
+ return {
893
+ code: nestedCode || directCode || "unknown_error",
894
+ message: nestedMessage
895
+ };
896
+ }
897
+ }
898
+ return {
899
+ code: directCode || "unknown_error",
900
+ message: directMessage || "Request failed"
901
+ };
902
+ }
857
903
  function buildPlansFn(client) {
858
904
  const fn = ((params) => {
859
905
  const query = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owostack",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Core SDK for Owostack billing infrastructure",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -30,7 +30,7 @@
30
30
  "payments"
31
31
  ],
32
32
  "dependencies": {
33
- "@owostack/types": "0.3.0"
33
+ "@owostack/types": "0.3.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "tsup": "^8.3.6",
@@ -44,6 +44,6 @@
44
44
  "build": "tsup src/index.ts --format esm --dts --clean",
45
45
  "dev": "tsup src/index.ts --format esm --dts --watch",
46
46
  "test": "vitest",
47
- "lint": "eslint src/"
47
+ "lint": "tsc --noEmit -p tsconfig.json"
48
48
  }
49
49
  }