Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"interfaces/CoreIntegrations",
"interfaces/CustomIntegrationsModule"
],
"interfaces/AppModule": [
"type-aliases/AppPublicSettings"
],
"type-aliases/ActorsModule": [
"interfaces/ActorRef",
"interfaces/Connection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2155,7 +2155,7 @@ function cleanupSortFieldSignature(dir) {
}

/**
* Fix truncated intersection types in ParamField type attributes.
* Fix truncated or collapsed types in ParamField and ResponseField type attributes.
* TypeDoc renders (Partial<T> & { id: string })[] as "Partial<...> & object[]".
*/
function cleanupTruncatedParamTypes(dir) {
Expand All @@ -2180,6 +2180,16 @@ function cleanupTruncatedParamTypes(dir) {
modified = true;
}

// AppPublicSettings ends in `| string`, so TypeScript reduces it to plain
// `string` and TypeDoc renders the public_settings field as "string".
if (content.includes('<ResponseField name="public_settings" type="string"')) {
content = content.replace(
/(<ResponseField name="public_settings" type=)"string"/g,
'$1"AppPublicSettings"'
);
modified = true;
}

if (modified) {
fs.writeFileSync(entryPath, content, "utf-8");
console.log(`Cleaned truncated param type: ${path.relative(DOCS_DIR, entryPath)}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"ActorClient",
"ActorRegistry",
"ActorNameRegistry"
],
[
"AppPublicSettings"
]
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[
"AiGatewayConnection",
"ActorConnectOptions",
"AppPublicSettingsResponse",
"DeleteManyResult",
"DeleteResult",
"EntityAggregateResult",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"AnalyticsModule",
"AppLogsModule",
"AppModule",
"AppPublicSettings",
"AppPublicSettingsResponse",
"AuthModule",
"ConnectorApiRequest",
Expand Down
59 changes: 38 additions & 21 deletions packages/sdk/src/modules/app.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
/**
* The app's access policy: whether the app is reachable without an account, and
* who may sign in.
* The app's [visibility](/Setting-up-your-app/Managing-access#setting-your-app-visibility).
*
* You can set and manage the app's visibility in the app's dashboard or with the Base44 CLI [`visibility`](/developers/references/cli/commands/visibility) command.
*
* The following table shows the supported values and the visibility each one represents:
*
* | Value | Visibility |
* | --- | --- |
* | `private_with_login` | **Private**: Only [invited users](/Setting-up-your-app/Managing-access#inviting-users-to-your-app) |
* | `workspace_with_login` | **Workspace**: Users in your Base44 [workspace](/documentation/account-and-billing/about-workspaces) |
* | `public_with_login` | **Public (login required)**: Visitors must log in |
* | `public_without_login` | **Public (no login)**: Anyone |
*
* <Note>
* If your workspace [enforces SSO for apps](/Enterprise/Enterprise-SSO-and-app-visibility), apps set to `public_without_login` also require sign-in.
* </Note>
*/
export type AppPublicSettings =
| "private_with_login"
Expand All @@ -10,47 +24,50 @@ export type AppPublicSettings =
| string;

/**
* The app's public configuration, as returned by {@link AppModule.getPublicSettings}.
* The app's public settings.
*/
export interface AppPublicSettingsResponse {
/** The app's ID. */
id: string;
/** The app's access policy. */
/**
* The app's visibility.
* For supported values, see [`AppPublicSettings`](#apppublicsettings).
*/
public_settings: AppPublicSettings;
}

/**
* App module for reading the app's own public configuration.
* App module for reading an app's public settings.
*
* Use it to read the app's visibility and determine whether the current visitor can access the app.
* If the app requires login, use `redirectToLogin()` from the {@link AuthModule | auth module} to send the visitor to the login page.
*
* Use it to discover how the app is gated before rendering it, so a private app
* can send the visitor to login instead of rendering an empty shell.
* Learn more about [app visibility](/Setting-up-your-app/Managing-access#setting-your-app-visibility).
*
* ## Authentication Modes
* ## Authentication modes
*
* This module is available to use with a client in all authentication modes. The
* client's token, when it has one, is sent with the request — a signed-in visitor
* who has no access to the app is reported differently from an anonymous one.
* You can use this module with a client in any authentication mode. The client sends its token, if it has one, with the request.
*/
export interface AppModule {
/**
* Get the app's public configuration.
* Retrieves the app's public settings.
*
* Rejects with a {@linkcode Base44Error} when the visitor may not open the app:
* `status` is `403` and `data.extra_data.reason` says why — `"auth_required"`
* when the visitor must sign in, `"user_not_registered"` when the signed-in
* visitor has no access to this app.
* Rejects with a {@linkcode Base44Error} that has a `status` of `403` when the visitor can't access the app.
* Check `data.extra_data.reason` to find the cause:
* - `auth_required`: The visitor must sign in.
* - `user_not_registered`: The visitor is signed in but doesn't have access.
*
* @returns Promise resolving to the app's ID and access policy.
* @returns Promise resolving to the app's ID and visibility.
*
* @example
* ```typescript
* // Decide what to render before the app boots
* // Redirect a visitor who isn't signed in
* try {
* const { public_settings } = await base44.app.getPublicSettings();
* console.log('App access policy:', public_settings);
* console.log('App visibility:', public_settings);
* } catch (error) {
* if (error.status === 403) {
* console.log('Blocked because:', error.data?.extra_data?.reason);
* if (error.status === 403 && error.data?.extra_data?.reason === 'auth_required') {
* base44.auth.redirectToLogin('<URL to return to after login>');
* }
* }
* ```
Expand Down
Loading