@modelrelay/sdk 0.18.0 → 0.20.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.cjs CHANGED
@@ -96,7 +96,11 @@ var ErrorCodes = {
96
96
  SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE",
97
97
  INVALID_INPUT: "INVALID_INPUT",
98
98
  PAYMENT_REQUIRED: "PAYMENT_REQUIRED",
99
- METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED"
99
+ METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED",
100
+ /** No tiers configured for the project - create a tier first. */
101
+ NO_TIERS: "NO_TIERS",
102
+ /** No free tier available for auto-provisioning - create a free tier or use checkout flow. */
103
+ NO_FREE_TIER: "NO_FREE_TIER"
100
104
  };
101
105
  var ModelRelayError = class extends Error {
102
106
  constructor(message, opts) {
@@ -165,6 +169,29 @@ var APIError = class extends ModelRelayError {
165
169
  isUnavailable() {
166
170
  return this.code === ErrorCodes.SERVICE_UNAVAILABLE;
167
171
  }
172
+ /**
173
+ * Returns true if the error indicates no tiers are configured.
174
+ * To resolve: create at least one tier in your project dashboard.
175
+ */
176
+ isNoTiers() {
177
+ return this.code === ErrorCodes.NO_TIERS;
178
+ }
179
+ /**
180
+ * Returns true if the error indicates no free tier is available for auto-provisioning.
181
+ * To resolve: either create a free tier for automatic customer creation,
182
+ * or use the checkout flow to create paying customers first.
183
+ */
184
+ isNoFreeTier() {
185
+ return this.code === ErrorCodes.NO_FREE_TIER;
186
+ }
187
+ /**
188
+ * Returns true if this is a customer provisioning error (NO_TIERS or NO_FREE_TIER).
189
+ * These errors occur when calling frontendToken() with a customer that doesn't exist
190
+ * and automatic provisioning cannot complete.
191
+ */
192
+ isProvisioningError() {
193
+ return this.isNoTiers() || this.isNoFreeTier();
194
+ }
168
195
  };
169
196
  async function parseErrorResponse(response, retries) {
170
197
  const requestId = response.headers.get("X-ModelRelay-Chat-Request-Id") || response.headers.get("X-Request-Id") || void 0;
@@ -347,7 +374,7 @@ function isTokenReusable(token) {
347
374
  // package.json
348
375
  var package_default = {
349
376
  name: "@modelrelay/sdk",
350
- version: "0.18.0",
377
+ version: "0.20.0",
351
378
  description: "TypeScript SDK for the ModelRelay API",
352
379
  type: "module",
353
380
  main: "dist/index.cjs",
@@ -2061,14 +2088,15 @@ var TiersClient = class {
2061
2088
  /**
2062
2089
  * Create a Stripe checkout session for a tier (Stripe-first flow).
2063
2090
  *
2064
- * This enables users to subscribe before authenticating. After checkout
2065
- * completes, a customer record is created with the provided email. The
2066
- * customer can later be linked to an identity via POST /customers/claim.
2091
+ * This enables users to subscribe before authenticating. Stripe collects
2092
+ * the customer's email during checkout. After checkout completes, a
2093
+ * customer record is created with the email from Stripe. The customer
2094
+ * can later be linked to an identity via POST /customers/claim.
2067
2095
  *
2068
2096
  * Requires a secret key (mr_sk_*).
2069
2097
  *
2070
2098
  * @param tierId - The tier ID to create a checkout session for
2071
- * @param request - Checkout session request with email and redirect URLs
2099
+ * @param request - Checkout session request with redirect URLs
2072
2100
  * @returns Checkout session with Stripe URL
2073
2101
  */
2074
2102
  async checkout(tierId, request) {
@@ -2076,9 +2104,6 @@ var TiersClient = class {
2076
2104
  if (!tierId?.trim()) {
2077
2105
  throw new ConfigError("tierId is required");
2078
2106
  }
2079
- if (!request.email?.trim()) {
2080
- throw new ConfigError("email is required");
2081
- }
2082
2107
  if (!request.success_url?.trim()) {
2083
2108
  throw new ConfigError("success_url is required");
2084
2109
  }
package/dist/index.d.cts CHANGED
@@ -910,9 +910,9 @@ interface Tier {
910
910
  }
911
911
  /**
912
912
  * Request to create a tier checkout session (Stripe-first flow).
913
+ * Stripe collects the customer's email during checkout.
913
914
  */
914
915
  interface TierCheckoutRequest {
915
- email: string;
916
916
  success_url: string;
917
917
  cancel_url: string;
918
918
  }
@@ -947,14 +947,15 @@ declare class TiersClient {
947
947
  /**
948
948
  * Create a Stripe checkout session for a tier (Stripe-first flow).
949
949
  *
950
- * This enables users to subscribe before authenticating. After checkout
951
- * completes, a customer record is created with the provided email. The
952
- * customer can later be linked to an identity via POST /customers/claim.
950
+ * This enables users to subscribe before authenticating. Stripe collects
951
+ * the customer's email during checkout. After checkout completes, a
952
+ * customer record is created with the email from Stripe. The customer
953
+ * can later be linked to an identity via POST /customers/claim.
953
954
  *
954
955
  * Requires a secret key (mr_sk_*).
955
956
  *
956
957
  * @param tierId - The tier ID to create a checkout session for
957
- * @param request - Checkout session request with email and redirect URLs
958
+ * @param request - Checkout session request with redirect URLs
958
959
  * @returns Checkout session with Stripe URL
959
960
  */
960
961
  checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
@@ -976,6 +977,10 @@ declare const ErrorCodes: {
976
977
  readonly INVALID_INPUT: "INVALID_INPUT";
977
978
  readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
978
979
  readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
980
+ /** No tiers configured for the project - create a tier first. */
981
+ readonly NO_TIERS: "NO_TIERS";
982
+ /** No free tier available for auto-provisioning - create a free tier or use checkout flow. */
983
+ readonly NO_FREE_TIER: "NO_FREE_TIER";
979
984
  };
980
985
  type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
981
986
  type ErrorCategory = "config" | "transport" | "api";
@@ -1031,6 +1036,23 @@ declare class APIError extends ModelRelayError {
1031
1036
  isForbidden(): boolean;
1032
1037
  /** Returns true if the error is a service unavailable error. */
1033
1038
  isUnavailable(): boolean;
1039
+ /**
1040
+ * Returns true if the error indicates no tiers are configured.
1041
+ * To resolve: create at least one tier in your project dashboard.
1042
+ */
1043
+ isNoTiers(): boolean;
1044
+ /**
1045
+ * Returns true if the error indicates no free tier is available for auto-provisioning.
1046
+ * To resolve: either create a free tier for automatic customer creation,
1047
+ * or use the checkout flow to create paying customers first.
1048
+ */
1049
+ isNoFreeTier(): boolean;
1050
+ /**
1051
+ * Returns true if this is a customer provisioning error (NO_TIERS or NO_FREE_TIER).
1052
+ * These errors occur when calling frontendToken() with a customer that doesn't exist
1053
+ * and automatic provisioning cannot complete.
1054
+ */
1055
+ isProvisioningError(): boolean;
1034
1056
  }
1035
1057
  declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
1036
1058
 
package/dist/index.d.ts CHANGED
@@ -910,9 +910,9 @@ interface Tier {
910
910
  }
911
911
  /**
912
912
  * Request to create a tier checkout session (Stripe-first flow).
913
+ * Stripe collects the customer's email during checkout.
913
914
  */
914
915
  interface TierCheckoutRequest {
915
- email: string;
916
916
  success_url: string;
917
917
  cancel_url: string;
918
918
  }
@@ -947,14 +947,15 @@ declare class TiersClient {
947
947
  /**
948
948
  * Create a Stripe checkout session for a tier (Stripe-first flow).
949
949
  *
950
- * This enables users to subscribe before authenticating. After checkout
951
- * completes, a customer record is created with the provided email. The
952
- * customer can later be linked to an identity via POST /customers/claim.
950
+ * This enables users to subscribe before authenticating. Stripe collects
951
+ * the customer's email during checkout. After checkout completes, a
952
+ * customer record is created with the email from Stripe. The customer
953
+ * can later be linked to an identity via POST /customers/claim.
953
954
  *
954
955
  * Requires a secret key (mr_sk_*).
955
956
  *
956
957
  * @param tierId - The tier ID to create a checkout session for
957
- * @param request - Checkout session request with email and redirect URLs
958
+ * @param request - Checkout session request with redirect URLs
958
959
  * @returns Checkout session with Stripe URL
959
960
  */
960
961
  checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
@@ -976,6 +977,10 @@ declare const ErrorCodes: {
976
977
  readonly INVALID_INPUT: "INVALID_INPUT";
977
978
  readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
978
979
  readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
980
+ /** No tiers configured for the project - create a tier first. */
981
+ readonly NO_TIERS: "NO_TIERS";
982
+ /** No free tier available for auto-provisioning - create a free tier or use checkout flow. */
983
+ readonly NO_FREE_TIER: "NO_FREE_TIER";
979
984
  };
980
985
  type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
981
986
  type ErrorCategory = "config" | "transport" | "api";
@@ -1031,6 +1036,23 @@ declare class APIError extends ModelRelayError {
1031
1036
  isForbidden(): boolean;
1032
1037
  /** Returns true if the error is a service unavailable error. */
1033
1038
  isUnavailable(): boolean;
1039
+ /**
1040
+ * Returns true if the error indicates no tiers are configured.
1041
+ * To resolve: create at least one tier in your project dashboard.
1042
+ */
1043
+ isNoTiers(): boolean;
1044
+ /**
1045
+ * Returns true if the error indicates no free tier is available for auto-provisioning.
1046
+ * To resolve: either create a free tier for automatic customer creation,
1047
+ * or use the checkout flow to create paying customers first.
1048
+ */
1049
+ isNoFreeTier(): boolean;
1050
+ /**
1051
+ * Returns true if this is a customer provisioning error (NO_TIERS or NO_FREE_TIER).
1052
+ * These errors occur when calling frontendToken() with a customer that doesn't exist
1053
+ * and automatic provisioning cannot complete.
1054
+ */
1055
+ isProvisioningError(): boolean;
1034
1056
  }
1035
1057
  declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
1036
1058
 
package/dist/index.js CHANGED
@@ -10,7 +10,11 @@ var ErrorCodes = {
10
10
  SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE",
11
11
  INVALID_INPUT: "INVALID_INPUT",
12
12
  PAYMENT_REQUIRED: "PAYMENT_REQUIRED",
13
- METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED"
13
+ METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED",
14
+ /** No tiers configured for the project - create a tier first. */
15
+ NO_TIERS: "NO_TIERS",
16
+ /** No free tier available for auto-provisioning - create a free tier or use checkout flow. */
17
+ NO_FREE_TIER: "NO_FREE_TIER"
14
18
  };
15
19
  var ModelRelayError = class extends Error {
16
20
  constructor(message, opts) {
@@ -79,6 +83,29 @@ var APIError = class extends ModelRelayError {
79
83
  isUnavailable() {
80
84
  return this.code === ErrorCodes.SERVICE_UNAVAILABLE;
81
85
  }
86
+ /**
87
+ * Returns true if the error indicates no tiers are configured.
88
+ * To resolve: create at least one tier in your project dashboard.
89
+ */
90
+ isNoTiers() {
91
+ return this.code === ErrorCodes.NO_TIERS;
92
+ }
93
+ /**
94
+ * Returns true if the error indicates no free tier is available for auto-provisioning.
95
+ * To resolve: either create a free tier for automatic customer creation,
96
+ * or use the checkout flow to create paying customers first.
97
+ */
98
+ isNoFreeTier() {
99
+ return this.code === ErrorCodes.NO_FREE_TIER;
100
+ }
101
+ /**
102
+ * Returns true if this is a customer provisioning error (NO_TIERS or NO_FREE_TIER).
103
+ * These errors occur when calling frontendToken() with a customer that doesn't exist
104
+ * and automatic provisioning cannot complete.
105
+ */
106
+ isProvisioningError() {
107
+ return this.isNoTiers() || this.isNoFreeTier();
108
+ }
82
109
  };
83
110
  async function parseErrorResponse(response, retries) {
84
111
  const requestId = response.headers.get("X-ModelRelay-Chat-Request-Id") || response.headers.get("X-Request-Id") || void 0;
@@ -261,7 +288,7 @@ function isTokenReusable(token) {
261
288
  // package.json
262
289
  var package_default = {
263
290
  name: "@modelrelay/sdk",
264
- version: "0.18.0",
291
+ version: "0.20.0",
265
292
  description: "TypeScript SDK for the ModelRelay API",
266
293
  type: "module",
267
294
  main: "dist/index.cjs",
@@ -1975,14 +2002,15 @@ var TiersClient = class {
1975
2002
  /**
1976
2003
  * Create a Stripe checkout session for a tier (Stripe-first flow).
1977
2004
  *
1978
- * This enables users to subscribe before authenticating. After checkout
1979
- * completes, a customer record is created with the provided email. The
1980
- * customer can later be linked to an identity via POST /customers/claim.
2005
+ * This enables users to subscribe before authenticating. Stripe collects
2006
+ * the customer's email during checkout. After checkout completes, a
2007
+ * customer record is created with the email from Stripe. The customer
2008
+ * can later be linked to an identity via POST /customers/claim.
1981
2009
  *
1982
2010
  * Requires a secret key (mr_sk_*).
1983
2011
  *
1984
2012
  * @param tierId - The tier ID to create a checkout session for
1985
- * @param request - Checkout session request with email and redirect URLs
2013
+ * @param request - Checkout session request with redirect URLs
1986
2014
  * @returns Checkout session with Stripe URL
1987
2015
  */
1988
2016
  async checkout(tierId, request) {
@@ -1990,9 +2018,6 @@ var TiersClient = class {
1990
2018
  if (!tierId?.trim()) {
1991
2019
  throw new ConfigError("tierId is required");
1992
2020
  }
1993
- if (!request.email?.trim()) {
1994
- throw new ConfigError("email is required");
1995
- }
1996
2021
  if (!request.success_url?.trim()) {
1997
2022
  throw new ConfigError("success_url is required");
1998
2023
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelrelay/sdk",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "TypeScript SDK for the ModelRelay API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",