@carrierllc/sdk 0.2.13 → 0.2.15

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.
@@ -1925,7 +1925,7 @@
1925
1925
  "options": [
1926
1926
  {
1927
1927
  "flags": "--pack <pack>",
1928
- "description": "Pack id (pack_500/pack_1000/pack_2500/pack_5000) or exact EUR-cents amount.",
1928
+ "description": "Pack id (pack_25/pack_50/pack_100/pack_500/pack_1000/pack_2500/pack_5000) or exact EUR-cents amount.",
1929
1929
  "required": false
1930
1930
  }
1931
1931
  ]
@@ -2950,7 +2950,7 @@
2950
2950
  "method": "PATCH",
2951
2951
  "path": "/v1/storefronts/{id}/plans/{slug}",
2952
2952
  "tag": "Storefront",
2953
- "summary": "Change the price, sale state, or display order of an existing plan. Omitted fields stay as stored. A plan on another storefront is not found.",
2953
+ "summary": "Change the price, sale state, display order, or stored Stripe Price of an existing plan. The Price id and its mode are set together; null clears both. The Price is stored, not yet charged. Omitted fields stay as stored. A plan on another storefront is not found.",
2954
2954
  "security": "bearer",
2955
2955
  "body": true,
2956
2956
  "bodyRequired": true,
@@ -32,6 +32,10 @@ export interface StorefrontPlanInput {
32
32
  active?: boolean;
33
33
  /** Display order on the storefront (ascending). Defaults to 0; ties fall back to slug. */
34
34
  sortOrder?: number;
35
+ /** Existing Stripe Price id (`price_…`), stored, not yet charged. Null clears the id and the mode. Set with stripePriceMode. */
36
+ stripePriceId?: string | null;
37
+ /** `test` or `live`. Null clears the id and the mode. Set with stripePriceId. */
38
+ stripePriceMode?: "test" | "live" | null;
35
39
  }
36
40
  export interface ExistingStorefrontBrand {
37
41
  theme?: Record<string, unknown>;
@@ -52,6 +56,8 @@ export interface StorefrontPlanBody {
52
56
  description?: string;
53
57
  active?: boolean;
54
58
  sort_order?: number;
59
+ stripe_price_id?: string | null;
60
+ stripe_price_mode?: "test" | "live" | null;
55
61
  }
56
62
  export declare function storefrontBrandPatch(input: StorefrontBrandInput, existing?: ExistingStorefrontBrand): {
57
63
  theme?: Record<string, unknown>;
@@ -4,6 +4,8 @@
4
4
  * onto the store already saved before it is sent.
5
5
  */
6
6
  export { logoFileDataUrl, logoReference, majorToCents, parseCountryInput, parseDataGb, parseValidityDays, } from "./storefront-labels.js";
7
+ const STRIPE_PRICE_ID_RE = /^price_[A-Za-z0-9_]+$/;
8
+ const STRIPE_PRICE_ID_MAX_LENGTH = 255;
7
9
  const THEME_FIELDS = [
8
10
  ["accent", "accent"],
9
11
  ["accentDark", "accentDark"],
@@ -43,6 +45,8 @@ export function completePlanInput(input, plans) {
43
45
  input.description,
44
46
  input.active,
45
47
  input.sortOrder,
48
+ input.stripePriceId,
49
+ input.stripePriceMode,
46
50
  ].some((value) => value !== undefined);
47
51
  if (!touched)
48
52
  return input;
@@ -72,6 +76,9 @@ export function storefrontPlanBody(input) {
72
76
  if (input.accountId !== undefined && (!Number.isSafeInteger(input.accountId) || input.accountId <= 0)) {
73
77
  return { error: "OCS account id must be a positive integer." };
74
78
  }
79
+ const stripe = stripePriceFields(input.stripePriceId, input.stripePriceMode);
80
+ if (stripe && "error" in stripe)
81
+ return stripe;
75
82
  const productId = input.productId?.trim() ?? "";
76
83
  if (productId !== "") {
77
84
  const body = { product_id: productId };
@@ -83,7 +90,7 @@ export function storefrontPlanBody(input) {
83
90
  body.active = input.active;
84
91
  if (input.sortOrder !== undefined)
85
92
  body.sort_order = input.sortOrder;
86
- return body;
93
+ return stripe ? { ...body, ...stripe } : body;
87
94
  }
88
95
  const touched = [
89
96
  input.slug,
@@ -99,6 +106,8 @@ export function storefrontPlanBody(input) {
99
106
  input.description,
100
107
  input.active,
101
108
  input.sortOrder,
109
+ input.stripePriceId,
110
+ input.stripePriceMode,
102
111
  ].some((value) => value !== undefined);
103
112
  if (!touched)
104
113
  return null;
@@ -135,7 +144,29 @@ export function storefrontPlanBody(input) {
135
144
  body.active = input.active;
136
145
  if (input.sortOrder !== undefined)
137
146
  body.sort_order = input.sortOrder;
138
- return body;
147
+ return stripe ? { ...body, ...stripe } : body;
148
+ }
149
+ /** Null clears both fields. A Price id and its mode are sent together. */
150
+ function stripePriceFields(id, mode) {
151
+ if (id === undefined && mode === undefined)
152
+ return undefined;
153
+ if (typeof id === "string") {
154
+ const trimmed = id.trim();
155
+ if (trimmed.length < 1 || trimmed.length > STRIPE_PRICE_ID_MAX_LENGTH || !STRIPE_PRICE_ID_RE.test(trimmed)) {
156
+ return { error: "stripe_price_id must look like price_… and be 1-255 characters." };
157
+ }
158
+ id = trimmed;
159
+ }
160
+ if (id === null || mode === null) {
161
+ if ((id !== undefined && id !== null) || (mode !== undefined && mode !== null)) {
162
+ return { error: "Sending null clears both stripe_price_id and stripe_price_mode." };
163
+ }
164
+ return { stripe_price_id: null, stripe_price_mode: null };
165
+ }
166
+ if (id === undefined || mode === undefined) {
167
+ return { error: "stripe_price_id and stripe_price_mode must be set together." };
168
+ }
169
+ return { stripe_price_id: id, stripe_price_mode: mode };
139
170
  }
140
171
  export function isStorefrontPlanError(value) {
141
172
  return value !== null && "error" in value;
package/dist/types.d.ts CHANGED
@@ -71,9 +71,11 @@ export interface HostedStorefront {
71
71
  ocs_package_template_id: number;
72
72
  ocs_account_id: number | null;
73
73
  account_status: "owned" | "not_owned" | "unset" | "unknown";
74
+ stripe_price_id?: string | null;
75
+ stripe_price_mode?: "test" | "live" | null;
74
76
  }>;
75
77
  }
76
- export type StorefrontPlanUpdateParams = Pick<StorefrontPlanParams, "price_cents" | "active" | "ocs_account_id"> & {
78
+ export type StorefrontPlanUpdateParams = Pick<StorefrontPlanParams, "price_cents" | "active" | "ocs_account_id" | "stripe_price_id" | "stripe_price_mode"> & {
77
79
  sort_order?: number;
78
80
  };
79
81
  export interface StorefrontPlanParams {
@@ -91,6 +93,10 @@ export interface StorefrontPlanParams {
91
93
  validity_days?: number;
92
94
  regions?: string[];
93
95
  active?: boolean;
96
+ /** Existing Stripe Price id (`price_…`), stored, not yet charged. Null clears the id and the mode. Set together with stripe_price_mode. */
97
+ stripe_price_id?: string | null;
98
+ /** `test` or `live`. Null clears the id and the mode. Set together with stripe_price_id. */
99
+ stripe_price_mode?: "test" | "live" | null;
94
100
  }
95
101
  export interface StorefrontCreateParams {
96
102
  slug: string;
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Published version. Keep this equal to package.json. */
2
- export declare const SDK_VERSION = "0.2.13";
3
- export declare const USER_AGENT = "@carrierllc/sdk/0.2.13";
2
+ export declare const SDK_VERSION = "0.2.15";
3
+ export declare const USER_AGENT = "@carrierllc/sdk/0.2.15";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** Published version. Keep this equal to package.json. */
2
- export const SDK_VERSION = "0.2.13";
2
+ export const SDK_VERSION = "0.2.15";
3
3
  export const USER_AGENT = `@carrierllc/sdk/${SDK_VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrierllc/sdk",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "TypeScript client for the Carrier API, MCP server, and CLI.",
5
5
  "license": "MIT",
6
6
  "type": "module",