@base44-preview/sdk 0.8.58-beta.0-pr.366.dccfb00 → 0.8.58-pr.368.f587f1e
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/client.types.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/modules/analytics.d.ts +3 -0
- package/dist/modules/analytics.js +33 -1
- package/dist/modules/browser.types.d.ts +24 -20
- package/dist/modules/payments-checkout.d.ts +2 -5
- package/dist/modules/payments-checkout.js +5 -63
- package/dist/modules/payments.types.d.ts +3 -41
- package/dist/modules/sso.types.d.ts +3 -1
- package/package.json +1 -1
package/dist/client.types.d.ts
CHANGED
|
@@ -134,7 +134,7 @@ export interface Base44Client {
|
|
|
134
134
|
actors: ActorsModule;
|
|
135
135
|
/** {@link AuthModule | Auth module} for user authentication and management. */
|
|
136
136
|
auth: AuthModule;
|
|
137
|
-
/**
|
|
137
|
+
/** [Connectors module](/developers/references/sdk/docs/interfaces/connectors#app-user-connectors) for app-user OAuth flows. */
|
|
138
138
|
connectors: UserConnectorsModule;
|
|
139
139
|
/** {@link EntitiesModule | Entities module} for CRUD operations on your data models. */
|
|
140
140
|
entities: EntitiesModule;
|
|
@@ -241,7 +241,7 @@ export interface Base44Client {
|
|
|
241
241
|
functions: FunctionsModule;
|
|
242
242
|
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
|
|
243
243
|
integrations: IntegrationsModule;
|
|
244
|
-
/**
|
|
244
|
+
/** [Payments module](/developers/references/sdk/docs/interfaces/payments#service-role-methods) for creating checkouts, refunds, and subscription changes. */
|
|
245
245
|
payments: ServiceRolePaymentsModule;
|
|
246
246
|
/** {@link SsoModule | SSO module} for generating SSO tokens. */
|
|
247
247
|
sso: SsoModule;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type { AppLogsModule } from "./modules/app-logs.types.js";
|
|
|
14
14
|
export type { AppModule, AppPublicSettings, AppPublicSettingsResponse, } from "./modules/app.types.js";
|
|
15
15
|
export type { ActorsModule, ActorClient, ActorRef, Connection, ActorSubscription, ActorConnectOptions, ActorNameRegistry, ActorRegistry, } from "./modules/actors.types.js";
|
|
16
16
|
export type { SsoModule, SsoAccessTokenResponse } from "./modules/sso.types.js";
|
|
17
|
-
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout,
|
|
17
|
+
export type { PaymentsModule, ServiceRolePaymentsModule, PaymentsErrorCode, PaymentsRecurringFrequency, CheckoutBuyer, CheckoutFreeTrial, CheckoutItem, CheckoutItemRecurring, CheckoutPresentation, CheckoutShipping, CheckoutElement, CheckoutMount, MountableCheckout, CreateCheckoutParams, CreateCheckoutResult, CompleteCheckoutResult, EmbeddedCheckout, PayPalEmbeddedCheckout, StripeEmbeddedCheckout, MountCheckoutOptions, ListPurchasesParams, ServiceRoleListPurchasesParams, ListPurchasesResult, Purchase, PurchaseItem, PurchaseStatus, RefundParams, ShippingAddress, RefundResult, CancelSubscriptionOptions, SubscriptionResult, } from "./modules/payments.types.js";
|
|
18
18
|
export type { BrowserModule, BrowserSession, BrowserSessionOptions, } from "./modules/browser.types.js";
|
|
19
19
|
export { Actor, type Conn } from "./actor.js";
|
|
20
20
|
export type { ConnectorsModule, UserConnectorsModule, ConnectorApiRequest, ConnectorApiResponse, ConnectorApiResponsePhase, } from "./modules/connectors.types.js";
|
|
@@ -6,6 +6,9 @@ export declare const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_eve
|
|
|
6
6
|
export declare const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
7
7
|
export declare const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
8
8
|
export declare const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
9
|
+
export declare const ANALYTICS_DENIED_LOCAL_STORAGE_KEY = "base44_analytics_denied";
|
|
10
|
+
/** Whether a page in this mode may track before any consent signal. */
|
|
11
|
+
export declare function initialConsentGranted(mode: string | null): boolean;
|
|
9
12
|
export declare const ANALYTICS_MODE_META_NAME = "base44-analytics";
|
|
10
13
|
/** Whether analytics may run and store the session id on this page. */
|
|
11
14
|
export declare function isAnalyticsAllowed(): boolean;
|
|
@@ -5,6 +5,37 @@ export const ANALYTICS_INITIALIZATION_EVENT_NAME = "__initialization_event__";
|
|
|
5
5
|
export const ANALYTICS_SESSION_DURATION_EVENT_NAME = "__session_duration_event__";
|
|
6
6
|
export const ANALYTICS_CONFIG_ENABLE_URL_PARAM_KEY = "analytics-enable";
|
|
7
7
|
export const ANALYTICS_SESSION_ID_LOCAL_STORAGE_KEY = "base44_analytics_session_id";
|
|
8
|
+
// Remembers a visitor's Decline across pages. On "on" pages the SDK starts
|
|
9
|
+
// before the app's banner replays the saved choice, so without it each new
|
|
10
|
+
// page would store the id and send one batch before the denial arrives.
|
|
11
|
+
export const ANALYTICS_DENIED_LOCAL_STORAGE_KEY = "base44_analytics_denied";
|
|
12
|
+
function readAnalyticsDenied() {
|
|
13
|
+
try {
|
|
14
|
+
return localStorage.getItem(ANALYTICS_DENIED_LOCAL_STORAGE_KEY) === "1";
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function writeAnalyticsDenied(denied) {
|
|
21
|
+
try {
|
|
22
|
+
if (denied)
|
|
23
|
+
localStorage.setItem(ANALYTICS_DENIED_LOCAL_STORAGE_KEY, "1");
|
|
24
|
+
else
|
|
25
|
+
localStorage.removeItem(ANALYTICS_DENIED_LOCAL_STORAGE_KEY);
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
// storage unavailable: the banner's replay still stops tracking
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Whether a page in this mode may track before any consent signal. */
|
|
32
|
+
export function initialConsentGranted(mode) {
|
|
33
|
+
if (mode === "consent")
|
|
34
|
+
return false;
|
|
35
|
+
if (mode === "on")
|
|
36
|
+
return !readAnalyticsDenied();
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
8
39
|
// Set by the Base44 server from the app owner's choice: "off" never tracks,
|
|
9
40
|
// "consent" waits for the page's Google Consent Mode `analytics_storage` grant,
|
|
10
41
|
// "on" tracks until that consent is denied. Absent: track as before.
|
|
@@ -61,7 +92,7 @@ const consentSharedState = getSharedInstance("analytics-consent", () => {
|
|
|
61
92
|
return {
|
|
62
93
|
analyticsMode,
|
|
63
94
|
// Whether the visitor may be tracked and the session id stored.
|
|
64
|
-
consentGranted: analyticsMode
|
|
95
|
+
consentGranted: initialConsentGranted(analyticsMode),
|
|
65
96
|
isWatchingConsent: false,
|
|
66
97
|
listeners: [],
|
|
67
98
|
};
|
|
@@ -73,6 +104,7 @@ export function isAnalyticsAllowed() {
|
|
|
73
104
|
}
|
|
74
105
|
function setConsentGranted(granted) {
|
|
75
106
|
var _a;
|
|
107
|
+
writeAnalyticsDenied(!granted);
|
|
76
108
|
if (consentSharedState.consentGranted === granted)
|
|
77
109
|
return;
|
|
78
110
|
consentSharedState.consentGranted = granted;
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export interface BrowserSessionOptions {
|
|
5
5
|
/**
|
|
6
|
-
* Whether
|
|
6
|
+
* Whether Base44's browser provider records the session and keeps its diagnostic logs.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* You can't retrieve the recordings or logs through the SDK. Set this to `false` when the session shows sensitive data that shouldn't be recorded. Defaults to `true`.
|
|
9
9
|
*/
|
|
10
10
|
captureDebugArtifacts?: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Maximum lifetime of the session, in whole seconds.
|
|
13
13
|
*
|
|
14
|
-
* The session ends when the timeout expires, even if it's still in use. Base44
|
|
14
|
+
* The session ends when the timeout expires, even if it's still in use. Base44 clamps the value to between `60` and `900` seconds. Defaults to `300`.
|
|
15
15
|
*/
|
|
16
16
|
sessionTimeoutSeconds?: number;
|
|
17
17
|
}
|
|
@@ -22,7 +22,7 @@ export interface BrowserSession {
|
|
|
22
22
|
/**
|
|
23
23
|
* Opaque session identifier issued to your app.
|
|
24
24
|
*
|
|
25
|
-
* Pass it unchanged to
|
|
25
|
+
* Pass it unchanged to [`endSession()`](#endsession) to end the session from a different request.
|
|
26
26
|
*/
|
|
27
27
|
sessionId: string;
|
|
28
28
|
/**
|
|
@@ -43,25 +43,30 @@ export interface BrowserSession {
|
|
|
43
43
|
/** ISO 8601 timestamp when the browser session expires. Omitted when the provider doesn't expose it. */
|
|
44
44
|
sessionExpiresAt?: string;
|
|
45
45
|
/**
|
|
46
|
-
* Ends the session. Equivalent to calling
|
|
46
|
+
* Ends the session. Equivalent to calling [`endSession()`](#endsession) with this session's ID.
|
|
47
47
|
*/
|
|
48
48
|
end: () => Promise<void>;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Browser module for running browser automation from your backend.
|
|
52
52
|
*
|
|
53
|
-
* This module creates remote browser sessions that you can control with a CDP client library such as Playwright or Puppeteer. Base44 doesn't store browser state, so each session is independent.
|
|
53
|
+
* This module creates remote browser sessions that you can control with a [Chrome DevTools Protocol (CDP)](https://chromedevtools.github.io/devtools-protocol/) client library such as [Playwright](https://playwright.dev/docs/api/class-browsertype#browser-type-connect-over-cdp) or [Puppeteer](https://pptr.dev/api/puppeteer.puppeteer.connect). Base44 doesn't store browser state, so each session is independent.
|
|
54
54
|
*
|
|
55
|
-
*
|
|
55
|
+
* ## Authentication modes
|
|
56
|
+
*
|
|
57
|
+
* This module is only available to use with a client in [service role authentication mode](/developers/references/sdk/getting-started/client#service-role) (`base44.asServiceRole.browser`), which means it can only be used in backend environments.
|
|
56
58
|
*/
|
|
57
59
|
export interface BrowserModule {
|
|
58
60
|
/**
|
|
59
61
|
* Creates a new remote browser session and returns its connection details.
|
|
60
62
|
*
|
|
61
|
-
* Each call creates a fresh session.
|
|
63
|
+
* Each call creates a fresh session, which uses credits from the workspace that owns the app. Each session is billed by the minute until it ends. An open session keeps running until its timeout expires. When you're done, call `end()` on the session. To end it from a different request, use {@linkcode endSession | endSession()}.
|
|
62
64
|
*
|
|
63
65
|
* @param options - Optional session settings.
|
|
64
|
-
* @returns Promise resolving to the new browser session.
|
|
66
|
+
* @returns Promise resolving to the new browser session. Rejects with a [`Base44Error`](/developers/references/sdk/getting-started/work-with-sdk#error-handling) whose `code` is one of the values under [Throws](#throws).
|
|
67
|
+
* @throws `insufficient_credits`: The workspace is out of credits.
|
|
68
|
+
* @throws `rate_limited`: You created more than 100 sessions in the last minute.
|
|
69
|
+
* @throws `browser_capacity_exceeded`: Browser capacity is temporarily unavailable.
|
|
65
70
|
*
|
|
66
71
|
* @example
|
|
67
72
|
* ```typescript
|
|
@@ -93,28 +98,27 @@ export interface BrowserModule {
|
|
|
93
98
|
* const session = await base44.asServiceRole.browser.getSession({
|
|
94
99
|
* captureDebugArtifacts: false,
|
|
95
100
|
* });
|
|
96
|
-
* ```
|
|
97
101
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* });
|
|
102
|
+
* try {
|
|
103
|
+
* // Connect to session.connectionUrl and run your automation
|
|
104
|
+
* } finally {
|
|
105
|
+
* await session.end();
|
|
106
|
+
* }
|
|
104
107
|
* ```
|
|
105
108
|
*/
|
|
106
109
|
getSession(options?: BrowserSessionOptions): Promise<BrowserSession>;
|
|
107
110
|
/**
|
|
108
111
|
* Ends a browser session created by your app.
|
|
109
112
|
*
|
|
110
|
-
* Use this when the session was created in a different request. Otherwise call `end()` on the session returned by {@linkcode getSession | getSession()}. Ending a session that has already ended succeeds, so it's safe to call more than once.
|
|
113
|
+
* Use this when the session was created in a different request. Otherwise call `end()` on the session returned by {@linkcode getSession | getSession()}. Ending a session that has already ended succeeds, so it's safe to call more than once.
|
|
111
114
|
*
|
|
112
|
-
* @param sessionId - The `sessionId` returned by {@linkcode getSession | getSession()}
|
|
113
|
-
* @returns Promise that resolves when the session has ended.
|
|
115
|
+
* @param sessionId - The `sessionId` returned by {@linkcode getSession | getSession()}.
|
|
116
|
+
* @returns Promise that resolves when the session has ended. Rejects with a [`Base44Error`](/developers/references/sdk/getting-started/work-with-sdk#error-handling) whose `code` is one of the values under [Throws](#throws-2).
|
|
117
|
+
* @throws `browser_session_not_found`: The session ID wasn't issued to your app.
|
|
114
118
|
*
|
|
115
119
|
* @example
|
|
116
120
|
* ```typescript
|
|
117
|
-
* // End a session
|
|
121
|
+
* // End a session from a later request, using the ID sent in the request body
|
|
118
122
|
* import { createClientFromRequest } from 'npm:@base44/sdk';
|
|
119
123
|
*
|
|
120
124
|
* Deno.serve(async (req) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions
|
|
1
|
+
import type { CheckoutElement, CheckoutMount, CompleteCheckoutResult, MountableCheckout, MountCheckoutOptions } from "./payments.types.js";
|
|
2
2
|
/** @internal */
|
|
3
3
|
export type LoadScript = (src: string) => Promise<void>;
|
|
4
4
|
/**
|
|
@@ -8,13 +8,11 @@ export type LoadScript = (src: string) => Promise<void>;
|
|
|
8
8
|
export interface PaymentsCheckoutConfig {
|
|
9
9
|
paypal?: {
|
|
10
10
|
script_url?: string;
|
|
11
|
-
button?: PayPalButtonConfig | null;
|
|
12
11
|
};
|
|
13
12
|
stripe?: {
|
|
14
13
|
script_url?: string;
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
|
-
type PayPalButtonConfig = Pick<PayPalEmbeddedCheckout, "client_id" | "merchant_id" | "partner_attribution_id">;
|
|
18
16
|
/** @internal */
|
|
19
17
|
export interface MountCheckoutDeps {
|
|
20
18
|
completeCheckout: (checkoutId: string) => Promise<CompleteCheckoutResult>;
|
|
@@ -35,5 +33,4 @@ export declare function preloadCheckout(provider: "paypal" | "stripe", deps: Pic
|
|
|
35
33
|
* Mounts the embedded checkout that createCheckout() returned.
|
|
36
34
|
* @internal
|
|
37
35
|
*/
|
|
38
|
-
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout
|
|
39
|
-
export {};
|
|
36
|
+
export declare function mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options: MountCheckoutOptions, deps: MountCheckoutDeps): Promise<CheckoutMount>;
|
|
@@ -103,8 +103,6 @@ function mountStripe(element, scriptUrl, embedded, deps) {
|
|
|
103
103
|
activeStripeCheckout = null;
|
|
104
104
|
checkout.destroy();
|
|
105
105
|
},
|
|
106
|
-
// Stripe's own form has no single button to disable.
|
|
107
|
-
setDisabled: () => undefined,
|
|
108
106
|
};
|
|
109
107
|
activeStripeCheckout = handle;
|
|
110
108
|
return handle;
|
|
@@ -112,9 +110,7 @@ function mountStripe(element, scriptUrl, embedded, deps) {
|
|
|
112
110
|
stripeQueue = mount.catch(() => undefined);
|
|
113
111
|
return mount;
|
|
114
112
|
}
|
|
115
|
-
async function mountPayPal(element, scriptUrl, currency, embedded,
|
|
116
|
-
// A created checkout's id, or what an on-click checkout calls inside the click to create one.
|
|
117
|
-
checkout, options, deps) {
|
|
113
|
+
async function mountPayPal(element, scriptUrl, checkoutId, currency, embedded, options, deps) {
|
|
118
114
|
var _a;
|
|
119
115
|
const paypal = await loadGlobal(scriptUrl, () => browserGlobals().paypal, deps.loadScript);
|
|
120
116
|
if (typeof paypal.createInstance !== "function") {
|
|
@@ -146,10 +142,6 @@ checkout, options, deps) {
|
|
|
146
142
|
}
|
|
147
143
|
let destroyed = false;
|
|
148
144
|
let completing = false;
|
|
149
|
-
// Set once a payment goes through: another click would create and charge a second order.
|
|
150
|
-
let paid = false;
|
|
151
|
-
let starting = false;
|
|
152
|
-
let checkoutId = typeof checkout === "string" ? checkout : undefined;
|
|
153
145
|
// App callbacks run only while mounted, and their own errors never reach PayPal or onError.
|
|
154
146
|
const notify = (callback) => {
|
|
155
147
|
if (destroyed)
|
|
@@ -169,8 +161,6 @@ checkout, options, deps) {
|
|
|
169
161
|
button.disabled = true;
|
|
170
162
|
let result;
|
|
171
163
|
try {
|
|
172
|
-
if (!checkoutId)
|
|
173
|
-
throw new Error("PayPal approved a checkout that wasn't created");
|
|
174
164
|
// Runs even after destroy(), so an approved payment is still captured.
|
|
175
165
|
result = await deps.completeCheckout(checkoutId);
|
|
176
166
|
}
|
|
@@ -182,7 +172,6 @@ checkout, options, deps) {
|
|
|
182
172
|
return;
|
|
183
173
|
}
|
|
184
174
|
completing = false;
|
|
185
|
-
paid = true;
|
|
186
175
|
notify(() => { var _a; return (_a = options.onComplete) === null || _a === void 0 ? void 0 : _a.call(options, result); });
|
|
187
176
|
},
|
|
188
177
|
onCancel() {
|
|
@@ -194,26 +183,15 @@ checkout, options, deps) {
|
|
|
194
183
|
});
|
|
195
184
|
button.setAttribute("type", subscription ? "subscribe" : "pay");
|
|
196
185
|
const onClick = () => {
|
|
197
|
-
if (
|
|
186
|
+
if (completing)
|
|
198
187
|
return;
|
|
199
|
-
starting = true;
|
|
200
188
|
// Not awaited before start(), which must run inside the click to open PayPal's popup.
|
|
201
|
-
const id = Promise.resolve()
|
|
202
|
-
.then(typeof checkout === "string" ? () => checkout : checkout)
|
|
203
|
-
.then((resolved) => {
|
|
204
|
-
checkoutId = resolved;
|
|
205
|
-
return subscription ? { subscriptionId: resolved } : { orderId: resolved };
|
|
206
|
-
});
|
|
189
|
+
const id = Promise.resolve(subscription ? { subscriptionId: checkoutId } : { orderId: checkoutId });
|
|
207
190
|
const report = (error) => notify(() => { var _a; return (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error); });
|
|
208
191
|
try {
|
|
209
|
-
Promise.resolve(session.start({ presentationMode: "auto" }, id))
|
|
210
|
-
.catch(report)
|
|
211
|
-
.finally(() => {
|
|
212
|
-
starting = false;
|
|
213
|
-
});
|
|
192
|
+
Promise.resolve(session.start({ presentationMode: "auto" }, id)).catch(report);
|
|
214
193
|
}
|
|
215
194
|
catch (error) {
|
|
216
|
-
starting = false;
|
|
217
195
|
report(error);
|
|
218
196
|
}
|
|
219
197
|
};
|
|
@@ -229,26 +207,6 @@ checkout, options, deps) {
|
|
|
229
207
|
button.remove();
|
|
230
208
|
(_a = session.destroy) === null || _a === void 0 ? void 0 : _a.call(session);
|
|
231
209
|
},
|
|
232
|
-
setDisabled(disabled) {
|
|
233
|
-
// A payment being completed, or already made, keeps the button off whatever the app asks.
|
|
234
|
-
if (!completing && !paid)
|
|
235
|
-
button.disabled = disabled;
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
/** The new checkout's id, refused unless it is the checkout the button was drawn for. */
|
|
240
|
-
function onClickCheckoutId(spec, button) {
|
|
241
|
-
return async () => {
|
|
242
|
-
var _a;
|
|
243
|
-
const checkout = await spec.createCheckout();
|
|
244
|
-
const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
|
|
245
|
-
if ((embedded === null || embedded === void 0 ? void 0 : embedded.provider) !== "paypal" ||
|
|
246
|
-
embedded.intent !== spec.intent ||
|
|
247
|
-
embedded.merchant_id !== button.merchant_id ||
|
|
248
|
-
((_a = checkout.currency) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== spec.currency.toLowerCase()) {
|
|
249
|
-
throw new Error("createCheckout() returned a checkout that doesn't match the PayPal button. Check its provider, intent and currency.");
|
|
250
|
-
}
|
|
251
|
-
return checkout.checkout_id;
|
|
252
210
|
};
|
|
253
211
|
}
|
|
254
212
|
/**
|
|
@@ -279,9 +237,6 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
279
237
|
if (!element) {
|
|
280
238
|
throw new Error("mountCheckout() requires an element to render in");
|
|
281
239
|
}
|
|
282
|
-
if ("createCheckout" in checkout) {
|
|
283
|
-
return mountPayPalOnClick(element, checkout, options, deps);
|
|
284
|
-
}
|
|
285
240
|
const embedded = checkout === null || checkout === void 0 ? void 0 : checkout.embedded;
|
|
286
241
|
if (!embedded) {
|
|
287
242
|
throw new Error("This checkout isn't embedded. Create it with presentation: 'embedded', or send the buyer to its redirect_url.");
|
|
@@ -290,21 +245,8 @@ export async function mountCheckout(element, checkout, options, deps) {
|
|
|
290
245
|
case "stripe":
|
|
291
246
|
return mountStripe(element, await scriptUrlFor("stripe", deps), embedded, deps);
|
|
292
247
|
case "paypal":
|
|
293
|
-
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.currency, embedded,
|
|
248
|
+
return mountPayPal(element, await scriptUrlFor("paypal", deps), checkout.checkout_id, checkout.currency, embedded, options, deps);
|
|
294
249
|
default:
|
|
295
250
|
throw new Error(`Embedded checkout isn't supported for provider ${embedded.provider}`);
|
|
296
251
|
}
|
|
297
252
|
}
|
|
298
|
-
async function mountPayPalOnClick(element, spec, options, deps) {
|
|
299
|
-
var _a, _b;
|
|
300
|
-
if (spec.provider !== "paypal" || typeof spec.createCheckout !== "function") {
|
|
301
|
-
throw new Error("Only PayPal can create its checkout on click");
|
|
302
|
-
}
|
|
303
|
-
const scriptUrl = await scriptUrlFor("paypal", deps);
|
|
304
|
-
const button = (_b = (_a = (await deps.getConfig())) === null || _a === void 0 ? void 0 : _a.paypal) === null || _b === void 0 ? void 0 : _b.button;
|
|
305
|
-
if (!(button === null || button === void 0 ? void 0 : button.client_id) || !button.merchant_id) {
|
|
306
|
-
throw new Error("PayPal isn't ready to take payments in this app yet");
|
|
307
|
-
}
|
|
308
|
-
const embedded = { provider: "paypal", ...button, intent: spec.intent };
|
|
309
|
-
return mountPayPal(element, scriptUrl, spec.currency, embedded, onClickCheckoutId(spec, button), options, deps);
|
|
310
|
-
}
|
|
@@ -350,29 +350,12 @@ export interface MountableCheckout {
|
|
|
350
350
|
/** Data for the embedded checkout. Mounting rejects when it's `null`. */
|
|
351
351
|
embedded: EmbeddedCheckout | null;
|
|
352
352
|
}
|
|
353
|
-
/**
|
|
354
|
-
* A PayPal checkout that [`mountCheckout()`](#mountcheckout) creates when the buyer clicks PayPal's button. The button shows as soon as the page loads, the buyer clicks once, and no order is created until they do.
|
|
355
|
-
*/
|
|
356
|
-
export interface PayPalCheckoutOnClick {
|
|
357
|
-
/** Payment provider. Only PayPal can create its checkout on click. */
|
|
358
|
-
provider: "paypal";
|
|
359
|
-
/** Three-letter ISO currency code the checkout uses, such as `'usd'`. */
|
|
360
|
-
currency: string;
|
|
361
|
-
/** Whether the checkout is a one-time payment or a subscription. */
|
|
362
|
-
intent: "capture" | "subscription";
|
|
363
|
-
/**
|
|
364
|
-
* Creates the checkout when the buyer clicks, usually by calling the backend function that calls {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}. Resolve with its result. Reject to stop, for example when a required form field is empty: PayPal's window closes and `onError` receives the error.
|
|
365
|
-
*/
|
|
366
|
-
createCheckout: () => Promise<MountableCheckout>;
|
|
367
|
-
}
|
|
368
353
|
/**
|
|
369
354
|
* A mounted embedded checkout.
|
|
370
355
|
*/
|
|
371
356
|
export interface CheckoutMount {
|
|
372
357
|
/** Removes the checkout from the page. Call it when the component that holds it unmounts. For Stripe, mounting another checkout destroys this one for you. */
|
|
373
358
|
destroy: () => void;
|
|
374
|
-
/** PayPal: greys out the button and ignores clicks, for example until a required form is filled in. After a payment completes the button stays off, so `setDisabled(false)` can't start a second payment. Stripe ignores it. */
|
|
375
|
-
setDisabled: (disabled: boolean) => void;
|
|
376
359
|
}
|
|
377
360
|
/**
|
|
378
361
|
* Payments module for accepting one-time payments and subscriptions in your app through its connected payment provider.
|
|
@@ -433,14 +416,12 @@ export interface PaymentsModule {
|
|
|
433
416
|
*
|
|
434
417
|
* To make the checkout appear faster, load the library ahead of time with [`preloadCheckout()`](#preloadcheckout) when the page opens.
|
|
435
418
|
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when an on-click PayPal checkout is mounted before the app's PayPal can take payments, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
|
|
419
|
+
* Requires a browser environment and can't be used in the backend. Rejects when the checkout isn't embedded, when the payments config can't be fetched or has no valid script URL for the provider, when the provider's library fails to load, or when PayPal isn't available for the checkout's currency.
|
|
439
420
|
*
|
|
440
421
|
* The checkout's callbacks run in the buyer's browser, where they can be faked. Grant access to what the buyer paid for only after your backend confirms the purchase, for example with [`listPurchases()`](#service-role-methods) in a backend function.
|
|
441
422
|
*
|
|
442
423
|
* @param element - Element to render the checkout in. It should be empty.
|
|
443
|
-
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}
|
|
424
|
+
* @param checkout - The result of {@linkcode ServiceRolePaymentsModule.createCheckout | createCheckout()}.
|
|
444
425
|
* @param options - Callbacks for the checkout's outcome.
|
|
445
426
|
* @returns Promise resolving to the mounted checkout once it renders.
|
|
446
427
|
*
|
|
@@ -464,25 +445,6 @@ export interface PaymentsModule {
|
|
|
464
445
|
* ```
|
|
465
446
|
*
|
|
466
447
|
* @example
|
|
467
|
-
* ```typescript
|
|
468
|
-
* // PayPal: show the button on page load and create the checkout on click
|
|
469
|
-
* const mount = await base44.payments.mountCheckout(
|
|
470
|
-
* document.getElementById('paypal')!,
|
|
471
|
-
* {
|
|
472
|
-
* provider: 'paypal',
|
|
473
|
-
* currency: 'usd',
|
|
474
|
-
* intent: 'capture',
|
|
475
|
-
* createCheckout: async () =>
|
|
476
|
-
* (await base44.functions.invoke('createCheckout', { productId })).data,
|
|
477
|
-
* },
|
|
478
|
-
* { onComplete: ({ checkout_id }) => confirmPurchase(checkout_id) }
|
|
479
|
-
* );
|
|
480
|
-
*
|
|
481
|
-
* // Grey out the button until the shipping form is valid
|
|
482
|
-
* mount.setDisabled(!formIsValid);
|
|
483
|
-
* ```
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
448
|
* ```tsx
|
|
487
449
|
* // React component
|
|
488
450
|
* function Checkout({ checkout }: { checkout: CreateCheckoutResult }) {
|
|
@@ -505,7 +467,7 @@ export interface PaymentsModule {
|
|
|
505
467
|
* }
|
|
506
468
|
* ```
|
|
507
469
|
*/
|
|
508
|
-
mountCheckout(element: CheckoutElement, checkout: MountableCheckout
|
|
470
|
+
mountCheckout(element: CheckoutElement, checkout: MountableCheckout, options?: MountCheckoutOptions): Promise<CheckoutMount>;
|
|
509
471
|
/**
|
|
510
472
|
* Completes a PayPal checkout after the buyer approves it.
|
|
511
473
|
*
|
|
@@ -11,7 +11,9 @@ export interface SsoAccessTokenResponse {
|
|
|
11
11
|
* tokens allow you to authenticate Base44 users with external systems or
|
|
12
12
|
* services.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* ## Authentication modes
|
|
15
|
+
*
|
|
16
|
+
* This module is only available to use with a client in [service role authentication mode](/developers/references/sdk/getting-started/client#service-role) (`base44.asServiceRole.sso`), which means it can only be used in backend environments.
|
|
15
17
|
*/
|
|
16
18
|
export interface SsoModule {
|
|
17
19
|
/**
|