@flexprice/sdk 2.1.39 → 2.1.40

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.
Files changed (70) hide show
  1. package/docs/sdk/models/analytics-view-definition.md +1 -0
  2. package/docs/sdk/models/create-customer-portal-session-request.md +17 -0
  3. package/docs/sdk/models/family.md +17 -0
  4. package/docs/sdk/models/metric.md +2 -2
  5. package/docs/sdk/models/modify-subscription-params.md +6 -5
  6. package/docs/sdk/models/modify-subscription-type.md +2 -2
  7. package/docs/sdk/models/portal-session-response.md +17 -0
  8. package/docs/sdk/models/shape.md +2 -2
  9. package/docs/sdks/analytics/README.md +6 -6
  10. package/docs/sdks/customers/README.md +72 -0
  11. package/esm/funcs/customers-create-customer-portal-session.d.ts +17 -0
  12. package/esm/funcs/customers-create-customer-portal-session.d.ts.map +1 -0
  13. package/esm/funcs/customers-create-customer-portal-session.js +91 -0
  14. package/esm/funcs/customers-create-customer-portal-session.js.map +1 -0
  15. package/esm/lib/config.d.ts +2 -2
  16. package/esm/lib/config.js +2 -2
  17. package/esm/sdk/customers.d.ts +7 -0
  18. package/esm/sdk/customers.d.ts.map +1 -1
  19. package/esm/sdk/customers.js +10 -0
  20. package/esm/sdk/customers.js.map +1 -1
  21. package/esm/sdk/models/analytics-view-definition.d.ts +3 -0
  22. package/esm/sdk/models/analytics-view-definition.d.ts.map +1 -1
  23. package/esm/sdk/models/analytics-view-definition.js +3 -0
  24. package/esm/sdk/models/analytics-view-definition.js.map +1 -1
  25. package/esm/sdk/models/create-customer-portal-session-op.d.ts +15 -0
  26. package/esm/sdk/models/create-customer-portal-session-op.d.ts.map +1 -0
  27. package/esm/sdk/models/create-customer-portal-session-op.js +17 -0
  28. package/esm/sdk/models/create-customer-portal-session-op.js.map +1 -0
  29. package/esm/sdk/models/family.d.ts +12 -0
  30. package/esm/sdk/models/family.d.ts.map +1 -0
  31. package/esm/sdk/models/family.js +15 -0
  32. package/esm/sdk/models/family.js.map +1 -0
  33. package/esm/sdk/models/index.d.ts +3 -0
  34. package/esm/sdk/models/index.d.ts.map +1 -1
  35. package/esm/sdk/models/index.js +3 -0
  36. package/esm/sdk/models/index.js.map +1 -1
  37. package/esm/sdk/models/metric.d.ts +1 -0
  38. package/esm/sdk/models/metric.d.ts.map +1 -1
  39. package/esm/sdk/models/metric.js +1 -0
  40. package/esm/sdk/models/metric.js.map +1 -1
  41. package/esm/sdk/models/modify-subscription-params.d.ts +5 -0
  42. package/esm/sdk/models/modify-subscription-params.d.ts.map +1 -1
  43. package/esm/sdk/models/modify-subscription-params.js +2 -0
  44. package/esm/sdk/models/modify-subscription-params.js.map +1 -1
  45. package/esm/sdk/models/modify-subscription-type.d.ts +1 -0
  46. package/esm/sdk/models/modify-subscription-type.d.ts.map +1 -1
  47. package/esm/sdk/models/modify-subscription-type.js +1 -0
  48. package/esm/sdk/models/modify-subscription-type.js.map +1 -1
  49. package/esm/sdk/models/portal-session-response.d.ts +12 -0
  50. package/esm/sdk/models/portal-session-response.d.ts.map +1 -0
  51. package/esm/sdk/models/portal-session-response.js +21 -0
  52. package/esm/sdk/models/portal-session-response.js.map +1 -0
  53. package/esm/sdk/models/shape.d.ts +1 -0
  54. package/esm/sdk/models/shape.d.ts.map +1 -1
  55. package/esm/sdk/models/shape.js +1 -0
  56. package/esm/sdk/models/shape.js.map +1 -1
  57. package/jsr.json +1 -1
  58. package/package.json +1 -1
  59. package/src/funcs/customers-create-customer-portal-session.ts +182 -0
  60. package/src/lib/config.ts +2 -2
  61. package/src/sdk/customers.ts +18 -0
  62. package/src/sdk/models/analytics-view-definition.ts +9 -0
  63. package/src/sdk/models/create-customer-portal-session-op.ts +43 -0
  64. package/src/sdk/models/family.ts +20 -0
  65. package/src/sdk/models/index.ts +3 -0
  66. package/src/sdk/models/metric.ts +1 -0
  67. package/src/sdk/models/modify-subscription-params.ts +7 -0
  68. package/src/sdk/models/modify-subscription-type.ts +1 -0
  69. package/src/sdk/models/portal-session-response.ts +43 -0
  70. package/src/sdk/models/shape.ts +1 -0
@@ -0,0 +1,182 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v4-mini";
6
+ import { FlexpriceCore } from "../core.js";
7
+ import { encodeSimple } from "../lib/encodings.js";
8
+ import { matchStatusCode } from "../lib/http.js";
9
+ import * as M from "../lib/matchers.js";
10
+ import { compactMap } from "../lib/primitives.js";
11
+ import { safeParse } from "../lib/schemas.js";
12
+ import { RequestOptions } from "../lib/sdks.js";
13
+ import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
14
+ import { pathToFunc } from "../lib/url.js";
15
+ import { FlexPriceError } from "../sdk/models/flex-price-error.js";
16
+ import {
17
+ ConnectionError,
18
+ InvalidRequestError,
19
+ RequestAbortedError,
20
+ RequestTimeoutError,
21
+ UnexpectedClientError,
22
+ } from "../sdk/models/http-client-errors.js";
23
+ import * as models from "../sdk/models/index.js";
24
+ import { ResponseValidationError } from "../sdk/models/response-validation-error.js";
25
+ import { SDKValidationError } from "../sdk/models/sdk-validation-error.js";
26
+ import { APICall, APIPromise } from "../types/async.js";
27
+ import { Result } from "../types/fp.js";
28
+
29
+ /**
30
+ * Create customer portal session
31
+ *
32
+ * @remarks
33
+ * Use when sending a customer to their self-serve billing portal (invoices, usage, payment methods). Returns a short-lived URL and token scoped to that customer.
34
+ */
35
+ export function customersCreateCustomerPortalSession(
36
+ client: FlexpriceCore,
37
+ externalId: string,
38
+ options?: RequestOptions,
39
+ ): APIPromise<
40
+ Result<
41
+ models.PortalSessionResponse,
42
+ | models.ErrorsErrorResponse
43
+ | FlexPriceError
44
+ | ResponseValidationError
45
+ | ConnectionError
46
+ | RequestAbortedError
47
+ | RequestTimeoutError
48
+ | InvalidRequestError
49
+ | UnexpectedClientError
50
+ | SDKValidationError
51
+ >
52
+ > {
53
+ return new APIPromise($do(
54
+ client,
55
+ externalId,
56
+ options,
57
+ ));
58
+ }
59
+
60
+ async function $do(
61
+ client: FlexpriceCore,
62
+ externalId: string,
63
+ options?: RequestOptions,
64
+ ): Promise<
65
+ [
66
+ Result<
67
+ models.PortalSessionResponse,
68
+ | models.ErrorsErrorResponse
69
+ | FlexPriceError
70
+ | ResponseValidationError
71
+ | ConnectionError
72
+ | RequestAbortedError
73
+ | RequestTimeoutError
74
+ | InvalidRequestError
75
+ | UnexpectedClientError
76
+ | SDKValidationError
77
+ >,
78
+ APICall,
79
+ ]
80
+ > {
81
+ const input: models.CreateCustomerPortalSessionRequest = {
82
+ externalId: externalId,
83
+ };
84
+
85
+ const parsed = safeParse(
86
+ input,
87
+ (value) =>
88
+ z.parse(models.CreateCustomerPortalSessionRequest$outboundSchema, value),
89
+ "Input validation failed",
90
+ );
91
+ if (!parsed.ok) {
92
+ return [parsed, { status: "invalid" }];
93
+ }
94
+ const payload = parsed.value;
95
+ const body = null;
96
+
97
+ const pathParams = {
98
+ external_id: encodeSimple("external_id", payload.external_id, {
99
+ explode: false,
100
+ charEncoding: "percent",
101
+ }),
102
+ };
103
+ const path = pathToFunc("/customers/portal/{external_id}")(pathParams);
104
+
105
+ const headers = new Headers(compactMap({
106
+ Accept: "application/json",
107
+ }));
108
+
109
+ const secConfig = await extractSecurity(client._options.apiKeyAuth);
110
+ const securityInput = secConfig == null ? {} : { apiKeyAuth: secConfig };
111
+ const requestSecurity = resolveGlobalSecurity(securityInput);
112
+
113
+ const context = {
114
+ options: client._options,
115
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
116
+ operationID: "createCustomerPortalSession",
117
+ oAuth2Scopes: null,
118
+
119
+ resolvedSecurity: requestSecurity,
120
+
121
+ securitySource: client._options.apiKeyAuth,
122
+ retryConfig: options?.retries
123
+ || client._options.retryConfig
124
+ || { strategy: "none" },
125
+ retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
126
+ };
127
+
128
+ const requestRes = client._createRequest(context, {
129
+ security: requestSecurity,
130
+ method: "GET",
131
+ baseURL: options?.serverURL,
132
+ path: path,
133
+ headers: headers,
134
+ body: body,
135
+ userAgent: client._options.userAgent,
136
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
137
+ }, options);
138
+ if (!requestRes.ok) {
139
+ return [requestRes, { status: "invalid" }];
140
+ }
141
+ const req = requestRes.value;
142
+
143
+ const doResult = await client._do(req, {
144
+ context,
145
+ isErrorStatusCode: (statusCode: number) =>
146
+ matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]),
147
+ retryConfig: context.retryConfig,
148
+ retryCodes: context.retryCodes,
149
+ });
150
+ if (!doResult.ok) {
151
+ return [doResult, { status: "request-error", request: req }];
152
+ }
153
+ const response = doResult.value;
154
+
155
+ const responseFields = {
156
+ HttpMeta: { Response: response, Request: req },
157
+ };
158
+
159
+ const [result] = await M.match<
160
+ models.PortalSessionResponse,
161
+ | models.ErrorsErrorResponse
162
+ | FlexPriceError
163
+ | ResponseValidationError
164
+ | ConnectionError
165
+ | RequestAbortedError
166
+ | RequestTimeoutError
167
+ | InvalidRequestError
168
+ | UnexpectedClientError
169
+ | SDKValidationError
170
+ >(
171
+ M.json(200, models.PortalSessionResponse$inboundSchema),
172
+ M.jsonErr([400, 404], models.ErrorsErrorResponse$inboundSchema),
173
+ M.jsonErr(500, models.ErrorsErrorResponse$inboundSchema),
174
+ M.fail("4XX"),
175
+ M.fail("5XX"),
176
+ )(response, req, { extraFields: responseFields });
177
+ if (!result.ok) {
178
+ return [result, { status: "complete", request: req, response }];
179
+ }
180
+
181
+ return [result, { status: "complete", request: req, response }];
182
+ }
package/src/lib/config.ts CHANGED
@@ -69,7 +69,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
69
69
  export const SDK_METADATA = {
70
70
  language: "typescript",
71
71
  openapiDocVersion: "1.0",
72
- sdkVersion: "2.1.39",
72
+ sdkVersion: "2.1.40",
73
73
  genVersion: "2.948.4",
74
- userAgent: "speakeasy-sdk/typescript 2.1.39 2.948.4 1.0 @flexprice/sdk",
74
+ userAgent: "speakeasy-sdk/typescript 2.1.40 2.948.4 1.0 @flexprice/sdk",
75
75
  } as const;
@@ -2,6 +2,7 @@
2
2
  * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
3
  */
4
4
 
5
+ import { customersCreateCustomerPortalSession } from "../funcs/customers-create-customer-portal-session.js";
5
6
  import { customersCreateCustomer } from "../funcs/customers-create-customer.js";
6
7
  import { customersDeleteCustomer } from "../funcs/customers-delete-customer.js";
7
8
  import { customersGetCustomerByExternalId } from "../funcs/customers-get-customer-by-external-id.js";
@@ -110,6 +111,23 @@ export class Customers extends ClientSDK {
110
111
  ));
111
112
  }
112
113
 
114
+ /**
115
+ * Create customer portal session
116
+ *
117
+ * @remarks
118
+ * Use when sending a customer to their self-serve billing portal (invoices, usage, payment methods). Returns a short-lived URL and token scoped to that customer.
119
+ */
120
+ async createCustomerPortalSession(
121
+ externalId: string,
122
+ options?: RequestOptions,
123
+ ): Promise<models.PortalSessionResponse> {
124
+ return unwrapAsync(customersCreateCustomerPortalSession(
125
+ this,
126
+ externalId,
127
+ options,
128
+ ));
129
+ }
130
+
113
131
  /**
114
132
  * Query customers
115
133
  *
@@ -30,6 +30,11 @@ import {
30
30
  AnalyticsVariable$Outbound,
31
31
  AnalyticsVariable$outboundSchema,
32
32
  } from "./analytics-variable.js";
33
+ import {
34
+ Family,
35
+ Family$inboundSchema,
36
+ Family$outboundSchema,
37
+ } from "./family.js";
33
38
  import {
34
39
  Metric,
35
40
  Metric$inboundSchema,
@@ -40,6 +45,7 @@ import { Shape, Shape$inboundSchema, Shape$outboundSchema } from "./shape.js";
40
45
 
41
46
  export type AnalyticsViewDefinition = {
42
47
  dimensions?: Array<string> | undefined;
48
+ family?: Family | undefined;
43
49
  filters?: Array<AnalyticsFilter> | undefined;
44
50
  limit?: number | undefined;
45
51
  metrics: Array<Metric>;
@@ -55,6 +61,7 @@ export const AnalyticsViewDefinition$inboundSchema: z.ZodMiniType<
55
61
  unknown
56
62
  > = z.object({
57
63
  dimensions: types.optional(z.array(types.string())),
64
+ family: types.optional(Family$inboundSchema),
58
65
  filters: types.optional(z.array(AnalyticsFilter$inboundSchema)),
59
66
  limit: types.optional(types.number()),
60
67
  metrics: z.array(Metric$inboundSchema),
@@ -66,6 +73,7 @@ export const AnalyticsViewDefinition$inboundSchema: z.ZodMiniType<
66
73
  /** @internal */
67
74
  export type AnalyticsViewDefinition$Outbound = {
68
75
  dimensions?: Array<string> | undefined;
76
+ family?: string | undefined;
69
77
  filters?: Array<AnalyticsFilter$Outbound> | undefined;
70
78
  limit?: number | undefined;
71
79
  metrics: Array<string>;
@@ -81,6 +89,7 @@ export const AnalyticsViewDefinition$outboundSchema: z.ZodMiniType<
81
89
  AnalyticsViewDefinition
82
90
  > = z.object({
83
91
  dimensions: z.optional(z.array(z.string())),
92
+ family: z.optional(Family$outboundSchema),
84
93
  filters: z.optional(z.array(AnalyticsFilter$outboundSchema)),
85
94
  limit: z.optional(z.int()),
86
95
  metrics: z.array(Metric$outboundSchema),
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v4-mini";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
7
+
8
+ export type CreateCustomerPortalSessionRequest = {
9
+ /**
10
+ * Customer external ID
11
+ */
12
+ externalId: string;
13
+ };
14
+
15
+ /** @internal */
16
+ export type CreateCustomerPortalSessionRequest$Outbound = {
17
+ external_id: string;
18
+ };
19
+
20
+ /** @internal */
21
+ export const CreateCustomerPortalSessionRequest$outboundSchema: z.ZodMiniType<
22
+ CreateCustomerPortalSessionRequest$Outbound,
23
+ CreateCustomerPortalSessionRequest
24
+ > = z.pipe(
25
+ z.object({
26
+ externalId: z.string(),
27
+ }),
28
+ z.transform((v) => {
29
+ return remap$(v, {
30
+ externalId: "external_id",
31
+ });
32
+ }),
33
+ );
34
+
35
+ export function createCustomerPortalSessionRequestToJSON(
36
+ createCustomerPortalSessionRequest: CreateCustomerPortalSessionRequest,
37
+ ): string {
38
+ return JSON.stringify(
39
+ CreateCustomerPortalSessionRequest$outboundSchema.parse(
40
+ createCustomerPortalSessionRequest,
41
+ ),
42
+ );
43
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v4-mini";
6
+ import * as openEnums from "../../types/enums.js";
7
+ import { OpenEnum } from "../../types/enums.js";
8
+
9
+ export const Family = {
10
+ Usage: "usage",
11
+ Billing: "billing",
12
+ } as const;
13
+ export type Family = OpenEnum<typeof Family>;
14
+
15
+ /** @internal */
16
+ export const Family$inboundSchema: z.ZodMiniType<Family, unknown> = openEnums
17
+ .inboundSchema(Family);
18
+ /** @internal */
19
+ export const Family$outboundSchema: z.ZodMiniType<string, Family> = openEnums
20
+ .outboundSchema(Family);
@@ -134,6 +134,7 @@ export * from "./create-coupon-request.js";
134
134
  export * from "./create-credit-grant-request.js";
135
135
  export * from "./create-credit-note-line-item-request.js";
136
136
  export * from "./create-credit-note-request.js";
137
+ export * from "./create-customer-portal-session-op.js";
137
138
  export * from "./create-customer-request.js";
138
139
  export * from "./create-entitlement-request.js";
139
140
  export * from "./create-entity-integration-mapping-request.js";
@@ -258,6 +259,7 @@ export * from "./external-tax-details.js";
258
259
  export * from "./fact-status.js";
259
260
  export * from "./failure-point-type.js";
260
261
  export * from "./failure-point.js";
262
+ export * from "./family.js";
261
263
  export * from "./feature-filter.js";
262
264
  export * from "./feature-response.js";
263
265
  export * from "./feature-type.js";
@@ -483,6 +485,7 @@ export * from "./plan-response.js";
483
485
  export * from "./plan-summary.js";
484
486
  export * from "./plan.js";
485
487
  export * from "./point-bucket.js";
488
+ export * from "./portal-session-response.js";
486
489
  export * from "./preview-subscription-change-op.js";
487
490
  export * from "./preview-subscription-modify-op.js";
488
491
  export * from "./preview-subscription-plan-change-v2-op.js";
@@ -9,6 +9,7 @@ import { OpenEnum } from "../../types/enums.js";
9
9
  export const Metric = {
10
10
  UsageQuantity: "usage_quantity",
11
11
  EventCount: "event_count",
12
+ InvoiceTotal: "invoice_total",
12
13
  } as const;
13
14
  export type Metric = OpenEnum<typeof Metric>;
14
15
 
@@ -18,6 +18,10 @@ export type ModifySubscriptionParams = {
18
18
  lineItemModifications?: Array<ModifySubscriptionLineItem> | undefined;
19
19
  modifyType?: ModifySubscriptionType | undefined;
20
20
  subscriptionId?: string | undefined;
21
+ /**
22
+ * TrialEndAt is where a trial_end checkout starts the first paid period.
23
+ */
24
+ trialEndAt?: Date | undefined;
21
25
  };
22
26
 
23
27
  /** @internal */
@@ -27,6 +31,7 @@ export type ModifySubscriptionParams$Outbound = {
27
31
  | undefined;
28
32
  modify_type?: string | undefined;
29
33
  subscription_id?: string | undefined;
34
+ trial_end_at?: string | undefined;
30
35
  };
31
36
 
32
37
  /** @internal */
@@ -40,12 +45,14 @@ export const ModifySubscriptionParams$outboundSchema: z.ZodMiniType<
40
45
  ),
41
46
  modifyType: z.optional(ModifySubscriptionType$outboundSchema),
42
47
  subscriptionId: z.optional(z.string()),
48
+ trialEndAt: z.optional(z.pipe(z.date(), z.transform(v => v.toISOString()))),
43
49
  }),
44
50
  z.transform((v) => {
45
51
  return remap$(v, {
46
52
  lineItemModifications: "line_item_modifications",
47
53
  modifyType: "modify_type",
48
54
  subscriptionId: "subscription_id",
55
+ trialEndAt: "trial_end_at",
49
56
  });
50
57
  }),
51
58
  );
@@ -8,6 +8,7 @@ import { ClosedEnum } from "../../types/enums.js";
8
8
  export const ModifySubscriptionType = {
9
9
  QuantityChange: "quantity_change",
10
10
  LineItemChange: "line_item_change",
11
+ TrialEnd: "trial_end",
11
12
  } as const;
12
13
  export type ModifySubscriptionType = ClosedEnum<typeof ModifySubscriptionType>;
13
14
 
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+
5
+ import * as z from "zod/v4-mini";
6
+ import { remap as remap$ } from "../../lib/primitives.js";
7
+ import { safeParse } from "../../lib/schemas.js";
8
+ import { Result as SafeParseResult } from "../../types/fp.js";
9
+ import * as types from "../../types/primitives.js";
10
+ import { SDKValidationError } from "./sdk-validation-error.js";
11
+
12
+ export type PortalSessionResponse = {
13
+ expiresAt?: Date | undefined;
14
+ token?: string | undefined;
15
+ url?: string | undefined;
16
+ };
17
+
18
+ /** @internal */
19
+ export const PortalSessionResponse$inboundSchema: z.ZodMiniType<
20
+ PortalSessionResponse,
21
+ unknown
22
+ > = z.pipe(
23
+ z.object({
24
+ expires_at: types.optional(types.date()),
25
+ token: types.optional(types.string()),
26
+ url: types.optional(types.string()),
27
+ }),
28
+ z.transform((v) => {
29
+ return remap$(v, {
30
+ "expires_at": "expiresAt",
31
+ });
32
+ }),
33
+ );
34
+
35
+ export function portalSessionResponseFromJSON(
36
+ jsonString: string,
37
+ ): SafeParseResult<PortalSessionResponse, SDKValidationError> {
38
+ return safeParse(
39
+ jsonString,
40
+ (x) => PortalSessionResponse$inboundSchema.parse(JSON.parse(x)),
41
+ `Failed to parse 'PortalSessionResponse' from JSON`,
42
+ );
43
+ }
@@ -9,6 +9,7 @@ import { OpenEnum } from "../../types/enums.js";
9
9
  export const Shape = {
10
10
  Timeseries: "timeseries",
11
11
  Breakdown: "breakdown",
12
+ Scalar: "scalar",
12
13
  } as const;
13
14
  export type Shape = OpenEnum<typeof Shape>;
14
15