@doany-ai/sdk 0.2.3 → 0.2.4

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
@@ -11,7 +11,7 @@ export type { FunctionsModule, FunctionName, FunctionNameRegistry, } from "./mod
11
11
  export type { AgentsModule, AgentName, AgentNameRegistry, AgentConversation, AgentMessage, AgentMessageReasoning, AgentMessageToolCall, AgentMessageUsage, AgentMessageCustomContext, AgentMessageMetadata, CreateConversationParams, } from "./modules/agents.types.js";
12
12
  export type { AiGatewayModule, AiGatewayConnection, } from "./modules/ai-gateway.types.js";
13
13
  export type { AppLogsModule } from "./modules/app-logs.types.js";
14
- export type { PaymentsModule, CheckoutLineItem, CreateCheckoutParams, CreateCheckoutResult, CheckoutSession, SubscriptionState, BillingPortalParams, } from "./modules/payments.types.js";
14
+ export type { PaymentsModule, CheckoutLineItem, CreateCheckoutParams, CreateCheckoutResult, CreateEmbeddedCheckoutResult, CheckoutSession, SubscriptionState, BillingPortalParams, } from "./modules/payments.types.js";
15
15
  export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
16
16
  export type { ConnectorsModule, UserConnectorsModule, } from "./modules/connectors.types.js";
17
17
  export type { CustomIntegrationsModule, CustomIntegrationCallParams, CustomIntegrationCallResponse, } from "./modules/custom-integrations.types.js";
@@ -9,18 +9,19 @@
9
9
  * @internal
10
10
  */
11
11
  export function createPaymentsModule(axios, appId) {
12
+ async function createCheckoutSession(params) {
13
+ const data = await axios.request({
14
+ method: "POST",
15
+ url: `/apps/${appId}/payments/checkout-session`,
16
+ data: params,
17
+ });
18
+ return data;
19
+ }
12
20
  // This client's response interceptor resolves requests to the response body.
13
21
  // Axios's declared return type does not reflect that, so the results below
14
22
  // are cast through `unknown`.
15
23
  return {
16
- async createCheckoutSession(params) {
17
- const data = await axios.request({
18
- method: "POST",
19
- url: `/apps/${appId}/payments/checkout-session`,
20
- data: params,
21
- });
22
- return data;
23
- },
24
+ createCheckoutSession,
24
25
  async getSubscription(subscriptionId) {
25
26
  const data = await axios.request({
26
27
  method: "GET",
@@ -45,6 +45,18 @@ export type CreateCheckoutParams = {
45
45
  customer_email?: string;
46
46
  /** Your own data, returned with the order. Up to 20 keys. */
47
47
  metadata?: Record<string, string>;
48
+ /**
49
+ * Where the payment form appears.
50
+ *
51
+ * `hosted` — the default — sends the customer to checkout.stripe.com and
52
+ * brings them back to `success_path`. `embedded` keeps them on your page:
53
+ * mount Stripe.js with the `client_secret` you get back instead. An embedded
54
+ * session has no `url` at all, which is why the two results differ.
55
+ *
56
+ * `cancel_path` is ignored when embedded. There is nowhere to send someone
57
+ * who never left — closing your dialog is the cancel.
58
+ */
59
+ ui_mode?: "hosted" | "embedded";
48
60
  };
49
61
  export type CreateCheckoutResult = {
50
62
  id: string;
@@ -63,6 +75,27 @@ export type CreateCheckoutResult = {
63
75
  /** `month` / `year` / `week` for a subscription, `null` for a one-off. */
64
76
  interval: string | null;
65
77
  };
78
+ /**
79
+ * What `ui_mode: "embedded"` returns instead.
80
+ *
81
+ * None of the three added fields is a secret. `client_secret` authorises this
82
+ * one session, the publishable key exists to be read off a page, and Stripe.js
83
+ * already puts the account id in its own requests — but all three have to reach
84
+ * the browser for the form to mount.
85
+ */
86
+ export type CreateEmbeddedCheckoutResult = Omit<CreateCheckoutResult, "url"> & {
87
+ /** Always `null`: an embedded session has no page to send anyone to. */
88
+ url: null;
89
+ /** Pass to `loadStripe(...).initEmbeddedCheckout({ clientSecret })`. */
90
+ client_secret: string;
91
+ /** Pass to `loadStripe(publishable_key, { stripeAccount: stripe_account })`. */
92
+ publishable_key: string;
93
+ /**
94
+ * The connected account the charge belongs to, and `null` in test mode —
95
+ * there the shared sandbox is doany's own account, not the founder's.
96
+ */
97
+ stripe_account: string | null;
98
+ };
66
99
  export type SubscriptionState = {
67
100
  id: string;
68
101
  mode: "test" | "live";
@@ -127,6 +160,23 @@ export type CheckoutSession = {
127
160
  amount_total: number | null;
128
161
  }>;
129
162
  metadata: Record<string, string>;
163
+ /**
164
+ * A session for the tab Stripe just returned to, when it came back signed
165
+ * out. Hand it to {@linkcode AuthModule.setToken} BEFORE reading or writing
166
+ * the user, or every write on the success page answers 401.
167
+ *
168
+ * Only ever present inside the editor preview, and only once per checkout.
169
+ * Checkout has to open in a new tab — an iframe cannot redirect itself to
170
+ * Stripe — and a preview login is a one-time code redeemed out of the URL
171
+ * at boot, so that tab starts with nothing of its own. A published site
172
+ * has a real session and never receives this.
173
+ *
174
+ * @example
175
+ * const session = await doany.payments.getCheckoutSession(sessionId);
176
+ * if (session.access_token) doany.auth.setToken(session.access_token);
177
+ * const user = await doany.auth.me(); // now this is the buyer
178
+ */
179
+ access_token?: string;
130
180
  };
131
181
  /**
132
182
  * Take card payments on your site.
@@ -169,7 +219,31 @@ export interface PaymentsModule {
169
219
  * window.location.href = url;
170
220
  * ```
171
221
  */
172
- createCheckoutSession(params: CreateCheckoutParams): Promise<CreateCheckoutResult>;
222
+ createCheckoutSession(params: CreateCheckoutParams & {
223
+ ui_mode: "embedded";
224
+ }): Promise<CreateEmbeddedCheckoutResult>;
225
+ createCheckoutSession(params: CreateCheckoutParams & {
226
+ ui_mode?: "hosted";
227
+ }): Promise<CreateCheckoutResult>;
228
+ /**
229
+ * When the mode is not known at the call site — the params came from a
230
+ * variable typed `CreateCheckoutParams`, so they could be either — the result
231
+ * is the union, and `client_secret` is reachable only after narrowing:
232
+ *
233
+ * ```ts
234
+ * const session = await doany.payments.createCheckoutSession(params);
235
+ * if ("client_secret" in session) mountStripe(session.client_secret);
236
+ * else window.location.href = session.url;
237
+ * ```
238
+ *
239
+ * Narrow on the key, not on `if (session.url)`. `url` is `string` on one
240
+ * side and `null` on the other, and an empty string is falsy too, so
241
+ * truthiness leaves both members in play and reaches neither field.
242
+ *
243
+ * Without this third signature such a call fell through to the hosted
244
+ * signature and was told `url: string` for a session that returns null.
245
+ */
246
+ createCheckoutSession(params: CreateCheckoutParams): Promise<CreateCheckoutResult | CreateEmbeddedCheckoutResult>;
173
247
  /**
174
248
  * Reads a checkout back — what a success page calls to confirm the payment.
175
249
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doany-ai/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "JavaScript SDK for the doany app platform (API-compatible fork of @base44/sdk)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",