# RestGO SDK

Configure RestGO and use login, sessions, accounts, APIs, Storage, videos, and payments.

URL: https://webrad.atentor.com/docs/restgo-sdk
Updated: 2026-11-07

## Configuration

Open **RestGo integration → Connection → Application SDK** in the sidebar.

1. Enable **Enable native RestGO integration** and enter **RestGO instance URL**.
2. Enter **Default database slug** for a default database. **Application API token** is optional and takes the token without Bearer.
3. Configure **Persist the user session**, **Session storage**, and **Session storage key**. Options are local storage, the current tab, or memory.
4. Click **Save changes** and save the project.

The RestGO object is available in pages and reusable components. Disabled integration raises RestGoNotConfiguredError. The application token is included in Preview and Build; use a token suitable for the browser.

## Login and current user

```ts
const result = await RestGO.login('ana@example.com', 'user-password', true);
if (!result.sucess) { Message(result.error.message); return; }
Message(result.data.user.fullName);
Navigate('PageHome');
```

The third argument, remember, is optional. Browser persistence follows integration settings. The public result field is named sucess.

```ts
await RestGO.auth.ready;
const user = RestGO.CurrentUser;
if (user) Message(user.nome);
// user.email, user.id, user.emailconfirmed, and user.ativo are also read-only.
```

CurrentUser reads the last confirmed identity without a request. To fetch current data and validate the session, use getUser(); its result contains fullName, email, id, avatarUrl, active, and emailConfirmed. With no user, data is null.

## Sign-up, recovery, and avatar

| Action | Method |
| --- | --- |
| Sign-up | auth.signUp({ email, password, fullName }) |
| Sign in with an object | auth.signInWithPassword({ email, password, remember }) |
| Request password recovery | auth.resetPasswordForEmail(email, { url }) |
| Confirm a new password | auth.confirmPasswordReset({ token, password }) |
| Confirm email | auth.confirmEmail(token) |
| Upload or remove an avatar | auth.uploadAvatar(file), auth.deleteAvatar() |
| Sign out | logout() or auth.signOut() |

Sign-up does not log in automatically. The RestGO instance must allow public sign-up. Recovery and confirmation depend on links sent by the server. Avatar upload uses the session and updates the SDK identity.

## Sessions and events

- auth.ready waits for initial restoration. getSession() validates the session; refreshSession() renews credentials; logout() ends the session.
- Automatic renewal uses the refresh token received at login. A network failure does not confirm logout.
- onAuthStateChange() receives INITIAL_SESSION, SIGNED_IN, SIGNED_OUT, SESSION_VALIDATED, TOKEN_REFRESHED, or USER_UPDATED. Keep the subscription and call unsubscribe() when observation ends.
- In **Interaction**, pages and reusable components offer OnLogin and OnLogout with detail.user. OnUnauthenticated allows redirection after the absence of a session is confirmed.

```ts
const subscription = RestGO.onAuthStateChange((event, session) => {
  console.log(event, session?.user.fullName);
});
// When observation ends: subscription.unsubscribe();
```

## Dynamic APIs

```ts
const endpoint = RestGO.from<{ id: number; name: string }[]>('customers', {
  database: 'main', version: 1,
});
const result = await endpoint.get({ auth: 'session', page: 1, pagination: 'simple' });
if (result.error) { Message(result.error.message); return; }
console.log(result.data, result.has_more);
```

Use get, post, put, patch, delete, head, options, or request. query, headers, and signal are call options. Pagination accepts exact, simple, and cursor; in cursor mode, set cursorColumn and reuse next_cursor.

| auth | Credential |
| --- | --- |
| session | User JWT; requires a session |
| apiToken | Application token, without Bearer |
| none | Public access, without Authorization |
| auto | Current session; otherwise, the configured token |

The mode must match the endpoint’s publication settings. Login, sign-up, recovery, and confirmation use their public routes. Storage, videos, avatars, and payments use the user session.

## Payments

Use the [Payments component](https://webrad.atentor.com/docs/payments) for the standard frontend flow. Configure its Gateway slug, sign in as the customer, and call one action from the button's async OnClick handler:

```ts
await Payments1.Pay(Edit1.value);
```

For a subscription, use Subscribe(Edit1.value); Checkout(Edit1.value) uses the Inspector's Mode. These component actions recover/persist the attempt, wait for checkout and open the provider automatically. Resume(), Refresh(), WaitForConfirmation(), CancelSubscription(), LoadHistory() and LoadMore() simplify management and return flows. Confirm financial success through RestGo rather than trusting a redirect.

Direct SDK code uses RestGO.payments.gateway(slug), with createCheckout, getOperation, listOperations, and cancelSubscription. The four routes use the customer's Authentication JWT exclusively; there is no application-token fallback. SDK methods return RestGoResult and do not automatically navigate. Direct createCheckout callers must durably save and reuse the original sourceKey, mode and idempotencyKey before POST, then save the returned operation ID before navigation. HTTP 202 is a successful pending operation.

```ts
const gateway = RestGO.payments.gateway('customer-payments');
const result = await gateway.listOperations();
if (result.error) Message(result.error.message);
else console.log(result.data.data, result.data.nextCursor);
```

Price, currency, ownership, recurrence, provider credentials and webhooks remain on RestGo. Choose the high-level Payments component unless transport-level control is required.

## APIs in the IDE

- In **RestGo integration → Connection**, the administrative connection manages endpoints. Its credential stays in the IDE, separate from the application token.
- In **Endpoints**, configure and publish the API. **Published APIs** lists available routes.
- In [API Client](https://webrad.atentor.com/docs/api-client), **Import from RestGo** imports operations; **Refresh** synchronizes previously imported clients.
- **Development login** authenticates JWT API tests in the editor. This session is separate from Preview or generated application login.

## Storage and videos

Use [File Upload](https://webrad.atentor.com/docs/file-upload) and [Video Upload](https://webrad.atentor.com/docs/video-upload) to select files and track uploads through the interface. The same operations are available in RestGO.storage and RestGO.videos.

- **Storage**: list, upload, get, update, remove, download, getPublicUrl, and usage. download returns a Blob. isPublic controls privacy; getPublicUrl only constructs the URL.
- **Videos**: upload, resumeUpload, list, get, update, and remove. Save resumeToken and select the same file to resume.
- **Processing**: process, reprocess, cancelProcessing, and waitUntilReady. Waiting observes conversion without starting it.
- **Media**: getHls, getThumbnail, and getMedia. For playback with controls and quality selection, use [Video Player](https://webrad.atentor.com/docs/video-player).
- **Manual chunks**: videos.uploads offers create, get, sendChunk, complete, and cancel. Prefer upload/resumeUpload when individual chunk control is not needed.

## Results and failures

SDK operations return { data, error }; login also returns sucess. Check error before using data. Errors include message, code, and status when available. Component methods such as ApiClient1.execute() and FileUpload1.SendToRestGO() reject their Promise on failure: use try/catch.

## SDK API

Service signatures. Expand an example to see the call.

### RestGO RestGoClient

#### `auth`

```ts
readonly auth: RestGoAuthClient;
```

#### `storage`

```ts
readonly storage: RestGoStorageClient;
```

#### `videos`

```ts
readonly videos: RestGoVideosClient;
```

#### `payments`

```ts
readonly payments: RestGoPaymentsClient;
```

#### `api`

```ts
readonly api: RestGoApiClient;
```

#### `baseUrl`

```ts
readonly baseUrl: string;
```

#### `from`

```ts
from<T = unknown>(endpoint: string, options?: RestGoEndpointOptions): RestGoEndpoint<T>;
```

Example

```ts
const endpoint = RestGO.from<{ id: number; name: string }[]>('customers', { database: 'main', version: 1 });
const result = await endpoint.get({ auth: 'session', query: { page: 1 } });
if (result.error) Message(result.error.message);
else console.log(result.data, result.page, result.has_more);
```

#### `login`

```ts
login(email: string, password: string, remember?: boolean): Promise<RestGoLoginResult>;
```

Sign in with positional parameters and report whether this login succeeded.

Example

```ts
const result = await RestGO.login('ana@example.com', 'user-password', true);
if (!result.sucess) { Message(result.error.message); return; }
Message(result.data.user.fullName);
```

#### `logout`

```ts
logout(): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.logout();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getSession`

```ts
getSession(): Promise<RestGoResult<RestGoSession | null>>;
```

Example

```ts
const result = await RestGO.getSession();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getUser`

```ts
getUser(): Promise<RestGoResult<RestGoUser | null>>;
```

Example

```ts
const result = await RestGO.getUser();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `CurrentUser`

```ts
get CurrentUser(): RestGoCurrentUser | null;
```

Last server-confirmed identity, or null before authentication/restoration.

#### `refreshSession`

```ts
refreshSession(): Promise<RestGoResult<RestGoSession>>;
```

Example

```ts
const result = await RestGO.refreshSession();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `onAuthStateChange`

```ts
onAuthStateChange(callback: (event: RestGoAuthEvent, session: RestGoSession | null) => void): {
    unsubscribe: () => void;
};
```

Example

```ts
const subscription = RestGO.onAuthStateChange((event, session) => {
  console.log(event, session?.user.fullName);
});
subscription.unsubscribe();
```

#### `dispose`

```ts
dispose(): void;
```

Release browser listeners and automatic renewal without logging the user out.

Example

```ts
// Do not dispose of the application’s shared client during navigation.
// Use dispose when closing an independent client created by createClient.
RestGO.dispose();
```

### RestGO.auth RestGoAuthClient

#### `ready`

```ts
readonly ready: Promise<RestGoResult<RestGoSession | null>>;
```

Startup checks persisted credentials with GET /auth/session.

#### `dispose`

```ts
dispose(): void;
```

Stop timers/listeners without revoking or deleting persisted credentials.

Example

```ts
// Do not dispose of the application’s shared client during navigation.
// Use dispose when closing an independent client created by createClient.
RestGO.auth.dispose();
```

#### `CurrentUser`

```ts
get CurrentUser(): RestGoCurrentUser | null;
```

Local snapshot; reading it does not issue a request or validate the session.

#### `refreshSession`

```ts
refreshSession(): Promise<RestGoResult<RestGoSession>>;
```

POST /auth/refresh, with single-use rotation serialized across callers and tabs.

Example

```ts
const result = await RestGO.auth.refreshSession();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `onAuthStateChange`

```ts
onAuthStateChange(callback: AuthListener): {
    unsubscribe: () => void;
};
```

Example

```ts
const subscription = RestGO.auth.onAuthStateChange((event, session) => {
  console.log(event, session?.user.fullName);
});
subscription.unsubscribe();
```

#### `signInWithPassword`

```ts
signInWithPassword(input: RestGoSignInInput): Promise<RestGoResult<RestGoSession>>;
```

Example

```ts
const result = await RestGO.auth.signInWithPassword({ email: 'ana@example.com', password: 'user-password', remember: true });
if (result.error) Message(result.error.message);
```

#### `signUp`

```ts
signUp(input: RestGoSignUpInput): Promise<RestGoResult<RestGoManagedUser>>;
```

Public registration. The server must allow anonymous signup. Does not start a session.

Example

```ts
const result = await RestGO.auth.signUp({ email: 'ana@example.com', password: 'user-password', fullName: 'Ana Silva' });
if (result.error) Message(result.error.message);
// Sign-up does not log in automatically.
```

#### `signOut`

```ts
signOut(): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.auth.signOut();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getSession`

```ts
getSession(): Promise<RestGoResult<RestGoSession | null>>;
```

Always asks the server; JWT expiry metadata is not proof of an active session.

Example

```ts
const result = await RestGO.auth.getSession();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getUser`

```ts
getUser(): Promise<RestGoResult<RestGoUser | null>>;
```

Example

```ts
const result = await RestGO.auth.getUser();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `setSession`

```ts
setSession(input: StoredSession): Promise<RestGoResult<RestGoSession>>;
```

Example

```ts
// Replace placeholders with values returned by your server.
const result = await RestGO.auth.setSession({
  token: 'RECEIVED-JWT',
  expiresAt: 'JWT-EXPIRY-IN-ISO-8601',
  refreshToken: 'RECEIVED-REFRESH-TOKEN',
  refreshExpiresAt: 'REFRESH-EXPIRY-IN-ISO-8601',
});
if (result.error) Message(result.error.message);
```

#### `resetPasswordForEmail`

```ts
resetPasswordForEmail(email: string, options?: {
    url?: string;
}): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.auth.resetPasswordForEmail('ana@example.com', { url: 'https://app.example.com/reset-password' });
if (result.error) Message(result.error.message);
```

#### `confirmPasswordReset`

```ts
confirmPasswordReset(input: {
    token: string;
    password: string;
}): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.auth.confirmPasswordReset({ token: 'TOKEN-FROM-LINK', password: 'new-password' });
if (result.error) Message(result.error.message);
```

#### `confirmEmail`

```ts
confirmEmail(token: string): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.auth.confirmEmail('TOKEN-FROM-LINK');
if (result.error) Message(result.error.message);
```

#### `updateUser`

```ts
updateUser(input: RestGoUpdateUserInput, options?: RestGoRequestOptions): Promise<RestGoResult<RestGoUpdateUserResult>>;
```

Example

```ts
const result = await RestGO.auth.updateUser({ fullName: 'Ana Silva' });
if (result.error) Message(result.error.message);
else console.log(result.data.user.fullName, result.data.sessionRevoked);
```

#### `resendEmailConfirmation`

```ts
resendEmailConfirmation(options?: RestGoRequestOptions & {
    url?: string;
}): Promise<RestGoResult<RestGoSuccess>>;
```

Example

```ts
const result = await RestGO.auth.resendEmailConfirmation();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `uploadAvatar`

```ts
uploadAvatar(file: Blob, options?: {
    name?: string;
    signal?: AbortSignal;
}): Promise<RestGoResult<{
    avatarUrl: string | null;
}>>;
```

Example

```ts
const file = FileUpload1.selectedFile;
if (!file) return;
const result = await RestGO.auth.uploadAvatar(file, { name: file.name });
if (result.error) Message(result.error.message);
else console.log(result.data.avatarUrl);
```

#### `deleteAvatar`

```ts
deleteAvatar(options?: RestGoRequestOptions): Promise<RestGoResult<{
    avatarUrl: string | null;
}>>;
```

Example

```ts
const result = await RestGO.auth.deleteAvatar();
if (result.error) Message(result.error.message);
else console.log(result.data.avatarUrl);
```

### RestGO.storage RestGoStorageClient

#### `list`

```ts
list(options?: RestGoListOptions): Promise<RestGoResult<RestGoList<RestGoStoredFile>>>;
```

Example

```ts
const result = await RestGO.storage.list({ page: 1, pageSize: 20, q: 'report' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `upload`

```ts
upload(file: Blob, options?: RestGoFileOptions): Promise<RestGoResult<RestGoStoredFile>>;
```

Example

```ts
const file = FileUpload1.selectedFile;
if (!file) return;
const result = await RestGO.storage.upload(file, { name: file.name, isPublic: false, onUploadProgress: p => console.log(p.percentage) });
if (result.error) Message(result.error.message);
```

#### `get`

```ts
get(id: string, options?: {
    signal?: AbortSignal;
}): Promise<RestGoResult<RestGoStoredFile>>;
```

Example

```ts
const result = await RestGO.storage.get('FILE-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `update`

```ts
update(id: string, input: RestGoFileUpdate): Promise<RestGoResult<RestGoStoredFile>>;
```

Example

```ts
const result = await RestGO.storage.update('FILE-ID', { name: 'new-name.pdf', isPublic: false });
if (result.error) Message(result.error.message);
```

#### `remove`

```ts
remove(id: string, options?: {
    signal?: AbortSignal;
}): Promise<RestGoResult<null>>;
```

Example

```ts
const result = await RestGO.storage.remove('FILE-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `download`

```ts
download(id: string, options?: {
    range?: string;
    public?: boolean;
    signal?: AbortSignal;
}): Promise<RestGoResult<Blob>>;
```

Example

```ts
const result = await RestGO.storage.download('FILE-ID', { public: false });
if (result.error) { Message(result.error.message); return; }
const blob = result.data;
console.log(blob.size, blob.type);
```

#### `getPublicUrl`

```ts
getPublicUrl(id: string): RestGoResult<{
    publicUrl: string;
}>;
```

Constructs a URL; public access still depends on the file's isPublic metadata.

Example

```ts
const result = RestGO.storage.getPublicUrl('FILE-ID');
if (!result.error) console.log(result.data.publicUrl);
// The URL does not grant public access to a private file.
```

#### `usage`

```ts
usage(options?: {
    signal?: AbortSignal;
}): Promise<RestGoResult<RestGoStorageUsage>>;
```

Example

```ts
const result = await RestGO.storage.usage();
if (result.error) Message(result.error.message);
else console.log(result.data);
```

### RestGO.videos RestGoVideosClient

#### `uploads`

```ts
readonly uploads: RestGoVideoUploadsClient;
```

#### `upload`

```ts
upload(file: File, options?: RestGoVideoUploadOptions): Promise<RestGoResult<RestGoVideo>>;
```

Example

```ts
const file = VideoUpload1.selectedFile;
if (!file) return;
const result = await RestGO.videos.upload(file, { title: 'Presentation', isPublic: false, onProgress: p => console.log(p) });
if (result.error) Message(result.error.message);
```

#### `resumeUpload`

```ts
resumeUpload(id: string, file: File, options: RestGoVideoResumeOptions): Promise<RestGoResult<RestGoVideo>>;
```

Example

```ts
const file = VideoUpload1.selectedFile;
const resumeToken = VideoUpload1.resumeToken;
if (!file || !resumeToken) return;
const result = await RestGO.videos.resumeUpload(resumeToken.uploadId, file, { resumeToken });
if (result.error) Message(result.error.message);
```

#### `list`

```ts
list(options?: RestGoVideoListOptions): Promise<RestGoResult<RestGoVideoList>>;
```

Example

```ts
const result = await RestGO.videos.list({ limit: 20, offset: 0, q: 'presentation' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `get`

```ts
get(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<RestGoVideoDetails>>;
```

Example

```ts
const result = await RestGO.videos.get('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `update`

```ts
update(id: string, input: RestGoVideoUpdate, options?: RestGoVideoRequestOptions): Promise<RestGoResult<RestGoVideo>>;
```

Example

```ts
const result = await RestGO.videos.update('VIDEO-ID', { title: 'New title', descri: 'Description', isPublic: false });
if (result.error) Message(result.error.message);
```

#### `remove`

```ts
remove(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<{
    id: string;
    status: 'deleting';
}>>;
```

Example

```ts
const result = await RestGO.videos.remove('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `process`

```ts
process(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<{
    id: string;
    jobId: string;
    status: 'pending';
}>>;
```

Example

```ts
const result = await RestGO.videos.process('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `reprocess`

```ts
reprocess(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<{
    id: string;
    jobId: string;
    status: 'pending';
}>>;
```

Example

```ts
const result = await RestGO.videos.reprocess('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `cancelProcessing`

```ts
cancelProcessing(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<{
    id: string;
    state: 'cancelled';
}>>;
```

Example

```ts
const result = await RestGO.videos.cancelProcessing('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getHls`

```ts
getHls(id: string, options?: RestGoVideoRequestOptions & {
    public?: boolean;
}): Promise<RestGoResult<RestGoVideoHlsDescriptor>>;
```

Example

```ts
const result = await RestGO.videos.getHls('VIDEO-ID', { public: false });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `getThumbnail`

```ts
getThumbnail(id: string, options?: RestGoVideoRequestOptions & {
    public?: boolean;
}): Promise<RestGoResult<Blob>>;
```

Example

```ts
const result = await RestGO.videos.getThumbnail('VIDEO-ID', { public: false });
if (result.error) Message(result.error.message);
else console.log(result.data.size);
```

#### `getMedia`

```ts
getMedia(id: string, uri: string, options?: RestGoVideoRequestOptions & {
    public?: boolean;
    range?: string;
    method?: 'GET' | 'HEAD';
}): Promise<RestGoResult<Response>>;
```

Browser media bridge: current shared session, one 401 renewal, no cookies or redirects.

Example

```ts
const result = await RestGO.videos.getMedia('VIDEO-ID', '/videos/VIDEO-ID/hls/master.m3u8', { public: false, method: 'GET' });
if (result.error) Message(result.error.message);
// Use a valid URI from this same video’s descriptor.
```

#### `waitUntilReady`

```ts
waitUntilReady(id: string, options?: RestGoVideoWaitOptions): Promise<RestGoResult<RestGoVideo>>;
```

Example

```ts
const result = await RestGO.videos.waitUntilReady('VIDEO-ID', { intervalMs: 2000, timeoutMs: 600_000, onProgress: details => console.log(details) });
if (result.error) Message(result.error.message);
```

### RestGO.videos.uploads RestGoVideoUploadsClient

#### `create`

```ts
create(input: RestGoVideoCreateInput, options?: RestGoVideoRequestOptions): Promise<RestGoResult<RestGoVideoUploadSession>>;
```

Example

```ts
const file = VideoUpload1.selectedFile;
if (!file) return;
const result = await RestGO.videos.uploads.create({ filename: file.name, sizeBytes: file.size, title: 'Presentation', isPublic: false });
if (result.error) Message(result.error.message);
```

#### `get`

```ts
get(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<RestGoVideoUploadSession>>;
```

Example

```ts
const result = await RestGO.videos.uploads.get('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `sendChunk`

```ts
sendChunk(id: string, chunk: Blob, options: RestGoVideoChunkOptions): Promise<RestGoResult<RestGoVideoUploadSession>>;
```

Example

```ts
const file = VideoUpload1.selectedFile;
const session = VideoUpload1.uploadSession;
if (!file || !session) return;
const offset = session.offset;
const chunk = file.slice(offset, offset + 1024 * 1024);
const digest = await crypto.subtle.digest('SHA-256', await chunk.arrayBuffer());
const checksum = Array.from(new Uint8Array(digest), b => b.toString(16).padStart(2, '0')).join('');
const result = await RestGO.videos.uploads.sendChunk(session.id, chunk, { offset, checksum });
if (result.error) Message(result.error.message);
// Check the confirmed offset before sending the next chunk.
```

#### `complete`

```ts
complete(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<RestGoVideo>>;
```

Example

```ts
const result = await RestGO.videos.uploads.complete('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `cancel`

```ts
cancel(id: string, options?: RestGoVideoRequestOptions): Promise<RestGoResult<{
    status: 'deleting';
}>>;
```

Example

```ts
const result = await RestGO.videos.uploads.cancel('VIDEO-OR-UPLOAD-ID');
if (result.error) Message(result.error.message);
else console.log(result.data);
```

### RestGO.payments RestGoPaymentsClient

#### `gateway`

```ts
gateway(slug: string): RestGoPaymentGatewayClient;
```

Example

```ts
const gateway = RestGO.payments.gateway('customer-payments');
const result = await gateway.listOperations();
if (result.error) Message(result.error.message);
else console.log(result.data.data);
```

### RestGO.payments.gateway('customer-payments') RestGoPaymentGatewayClient

#### `slug`

```ts
readonly slug: string;
```

#### `createCheckout`

```ts
createCheckout(input: RestGoCheckoutInput, options?: RestGoPaymentRequestOptions): Promise<RestGoResult<RestGoPaymentOperation>>;
```

Example

```ts
// Direct SDK control: persist before the first POST and reuse this saved attempt.
const session = await RestGO.getSession();
if (session.error) throw session.error;
if (!session.data) throw new Error('Sign in before starting checkout.');
const sourceKey = '123';
const storageKey = JSON.stringify(['sdk-checkout', RestGO.baseUrl, session.data.user.id, 'customer-payments', sourceKey, 'payment']);
const saved = localStorage.getItem(storageKey);
const attempt = saved === null ? { sourceKey, mode: 'payment' as const, idempotencyKey: crypto.randomUUID() }
  : JSON.parse(saved) as import('@webrad/restgo-sdk').RestGoCheckoutInput;
localStorage.setItem(storageKey, JSON.stringify(attempt));
const result = await RestGO.payments.gateway('customer-payments').createCheckout(attempt);
if (result.error) throw result.error;
localStorage.setItem(storageKey + ':operation', result.data.id);
console.log(result.data.status, result.data.checkoutState);
// Prefer Payments1.Pay(sourceKey) for automatic storage/locking, readiness and opening.
```

#### `getOperation`

```ts
getOperation(id: string, options?: RestGoPaymentRequestOptions): Promise<RestGoResult<RestGoPaymentOperation>>;
```

Example

```ts
const result = await RestGO.payments.gateway('customer-payments').getOperation('00000000-0000-4000-8000-000000000001');
if (result.error) Message(result.error.message);
else console.log(result.data.status, result.data.synchronizationPending);
```

#### `listOperations`

```ts
listOperations(options?: RestGoPaymentListOptions): Promise<RestGoResult<RestGoPaymentOperationList>>;
```

Example

```ts
const gateway = RestGO.payments.gateway('customer-payments');
const first = await gateway.listOperations();
if (first.error) throw first.error;
console.log(first.data.data);
if (first.data.nextCursor) {
  const next = await gateway.listOperations({ before: first.data.nextCursor });
  if (next.error) throw next.error;
  console.log(next.data.data);
}
```

#### `cancelSubscription`

```ts
cancelSubscription(id: string, options?: RestGoPaymentRequestOptions): Promise<RestGoResult<RestGoPaymentOperation>>;
```

Example

```ts
// Call after the customer chooses to cancel their subscription.
const result = await RestGO.payments.gateway('customer-payments').cancelSubscription('00000000-0000-4000-8000-000000000001');
if (result.error) Message(result.error.message);
else console.log(result.data.provider.periodEnd, result.data.provider.cancelAtPeriodEnd);
```

### RestGO.api RestGoApiClient

#### `from`

```ts
from(database?: string): RestGoDatabase;
```

Example

```ts
const database = RestGO.api.from('main');
const result = await database.endpoint('customers', { version: 1 }).get({ auth: 'session' });
if (result.error) Message(result.error.message);
```

#### `endpoint`

```ts
endpoint<T = unknown>(name: string, options?: RestGoEndpointOptions): RestGoEndpoint<T>;
```

Example

```ts
const endpoint = RestGO.api.endpoint('customers', { database: 'main', version: 1 });
const result = await endpoint.get({ auth: 'session' });
if (result.error) Message(result.error.message);
```

### RestGO.api.from('main') RestGoDatabase

#### `endpoint`

```ts
endpoint<T = unknown>(name: string, options?: {
    version?: number;
}): RestGoEndpoint<T>;
```

Example

```ts
const endpoint = RestGO.api.from('main').endpoint('customers', { version: 1 });
const result = await endpoint.get();
if (result.error) Message(result.error.message);
```

### RestGO.from('customers') RestGoEndpoint

#### `get`

```ts
get<U = T>(options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').get({ auth: 'session', query: { page: 1 } });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `post`

```ts
post<U = T>(body?: unknown, options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').post({ id: 42, name: 'Ana' }, { auth: 'session' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `put`

```ts
put<U = T>(body?: unknown, options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').put({ id: 42, name: 'Ana' }, { auth: 'session' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `patch`

```ts
patch<U = T>(body?: unknown, options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').patch({ id: 42, name: 'Ana' }, { auth: 'session' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `delete`

```ts
delete<U = T>(body?: unknown, options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').delete({ id: 42, name: 'Ana' }, { auth: 'session' });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `head`

```ts
head(options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<null>>;
```

Example

```ts
const result = await RestGO.from('customers').head({ auth: 'session', query: { page: 1 } });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `options`

```ts
options<U = T>(options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').options({ auth: 'session', query: { page: 1 } });
if (result.error) Message(result.error.message);
else console.log(result.data);
```

#### `request`

```ts
request<U = T>(method: RestGoHttpMethod, body?: unknown, options?: RestGoDynamicOptions): Promise<RestGoDynamicResult<U>>;
```

Example

```ts
const result = await RestGO.from('customers').request('GET', undefined, { auth: 'session', query: { page: 1 } });
if (result.error) Message(result.error.message);
else console.log(result.data);
```
