import { InstantRules, InstantSchemaDef, EntitiesDef, LinksDef, RoomsDef, InstantDBAttr, InstantDBIdent, InstantDBCheckedDataType } from '@instantdb/core'; import { InstantAPIPlatformSchema, InstantAPISchemaPlanStep, InstantAPISchemaPushStep } from './schema.ts'; import { ProgressPromise } from './ProgressPromise.ts'; import { RenameCommand } from './migrations.ts'; type Simplify = { [K in keyof T]: T[K]; } & {}; type AppDataOpts = { includePerms?: boolean | null | undefined; includeSchema?: boolean | null | undefined; }; export type InstantAPIAppDetails = Simplify<{ id: string; title: string; createdAt: Date; orgId: string | null; } & (NonNullable['includePerms'] extends true ? { perms: InstantRules; } : {}) & (NonNullable['includeSchema'] extends true ? { schema: InstantSchemaDef, RoomsDef>; } : {})>; export type InstantAPIOrgDetails = { id: string; title: string; createdAt: Date; }; export type InstantAPIGetAppResponse = Simplify<{ app: InstantAPIAppDetails; }>; export type InstantAPIListAppsResponse = Simplify<{ apps: InstantAPIAppDetails[]; }>; export type InstantAPIListOrgsResponse = { orgs: InstantAPIOrgDetails[]; }; export type InstantAPIGetAppSchemaResponse = { schema: InstantSchemaDef, RoomsDef>; }; export type InstantAPIGetAppPermsResponse = { perms: InstantRules; }; export type InstantAPICreateAppBody = { title: string; schema?: InstantSchemaDef, RoomsDef> | null | undefined; perms?: InstantRules | null | undefined; orgId?: string | null | undefined; }; export type InstantAPICreateTemporaryAppBody = { title: string; schema?: InstantSchemaDef, RoomsDef> | null | undefined; rules?: { code: InstantRules; } | null; }; export type InstantAPICreateTemporaryAppResponse = { app: Simplify & { adminToken: string; }>; expiresMs: number; }; export type InstantAPICreateAppResponse = Simplify<{ app: InstantAPIAppDetails<{ includePerms: true; includeSchema: true; }> & { adminToken: string; }; }>; export type InstantAPIUpdateAppBody = { title: string; }; export type InstantAPIUpdateAppResponse = Simplify<{ app: InstantAPIAppDetails<{}>; }>; export type InstantAPIDeleteAppResponse = Simplify<{ app: InstantAPIAppDetails<{}>; }>; export type InstantAPISchemaPushBody = { schema: InstantSchemaDef, RoomsDef>; overwrite?: false; } | { schema: InstantSchemaDef, RoomsDef>; overwrite: true; renames?: RenameCommand[]; }; export type InstantAPIPushPermsBody = { perms: InstantRules; }; export type InstantAPIPushPermsResponse = { perms: InstantRules; }; export type InstantAPITokenInfoResponse = { expiresAt: Date; scopes: string; tokenType: 'Bearer'; }; export type PlanStep = ['add-attr', InstantDBAttr] | ['update-attr', Partial] | ['index', { 'attr-id': string; 'forward-identity': InstantDBIdent; }] | ['remove-index', { 'attr-id': string; 'forward-identity': InstantDBIdent; }] | ['unique', { 'attr-id': string; 'forward-identity': InstantDBIdent; }] | ['remove-unique', { 'attr-id': string; 'forward-identity': InstantDBIdent; }] | ['required', { 'attr-id': string; 'forward-identity': InstantDBIdent; }] | [ 'remove-required', { 'attr-id': string; 'forward-identity': InstantDBIdent; } ] | [ 'check-data-type', { 'attr-id': string; 'forward-identity': InstantDBIdent; 'checked-data-type': InstantDBCheckedDataType; } ] | [ 'remove-data-type', { 'attr-id': string; 'forward-identity': InstantDBIdent; } ] | ['delete-attr', string]; export type InstantAPIPlanSchemaPushResponse = { newSchema: InstantSchemaDef, RoomsDef>; currentSchema: InstantSchemaDef, RoomsDef>; steps: InstantAPISchemaPlanStep[]; }; type InProgressStepsSummary = { friendlyDescription: string; totalCount: number; inProgressCount: number; completedCount: number; errorCount: number; steps: InstantAPISchemaPushStep[]; inProgressSteps: InstantAPISchemaPushStep[]; completedSteps: InstantAPISchemaPushStep[]; erroredSteps: InstantAPISchemaPushStep[]; }; export type InstantAPISchemaPushResponse = { newSchema: InstantSchemaDef, RoomsDef>; steps: InstantAPISchemaPushStep[]; summary: InProgressStepsSummary; }; export declare function apiSchemaToAttrs(apiSchema: InstantAPIPlatformSchema): InstantDBAttr[]; export declare function apiSchemaToInstantSchemaDef(apiSchema: InstantAPIPlatformSchema): InstantSchemaDef, RoomsDef>; export declare function translatePlanSteps(apiSteps: PlanStep[], currentAttrs: InstantDBAttr[]): InstantAPISchemaPlanStep[]; type InstantBackgroundSchemaBaseJob = { id: string; createdAt: Date; updatedAt: Date; status: 'completed' | 'waiting' | 'processing' | 'errored'; workEstimate: number | null; workCompleted: number | null; error?: 'invalid-triple-error' | 'invalid-attr-state-error' | 'triple-not-unique-error' | 'triple-too-large-error' | 'missing-required-error' | 'unexpected-error'; invalidTriplesSample?: { entityId: string; value: any; jsonType: 'string' | 'number' | 'boolean' | 'null' | 'object' | 'array' | 'date'; }[]; }; export interface InstantBackgroundSchemaRemoveDataTypeJob extends InstantBackgroundSchemaBaseJob { type: 'remove-data-type'; } export interface InstantBackgroundSchemaCheckDataTypeJob extends InstantBackgroundSchemaBaseJob { type: 'check-data-type'; checkedDataType: InstantDBCheckedDataType; } export interface InstantBackgroundSchemaAddIndexJob extends InstantBackgroundSchemaBaseJob { type: 'index'; } export interface InstantBackgroundSchemaRemoveIndexJob extends InstantBackgroundSchemaBaseJob { type: 'remove-index'; } export interface InstantBackgroundSchemaAddUniqueJob extends InstantBackgroundSchemaBaseJob { type: 'unique'; invalidUniqueValue?: any; } export interface InstantBackgroundSchemaRemoveUniqueJob extends InstantBackgroundSchemaBaseJob { type: 'remove-unique'; } export interface InstantBackgroundSchemaAddRequiredJob extends InstantBackgroundSchemaBaseJob { type: 'required'; } export interface InstantBackgroundSchemaRemoveRequiredJob extends InstantBackgroundSchemaBaseJob { type: 'remove-required'; } export type InstantBackgroundSchemaJob = InstantBackgroundSchemaRemoveDataTypeJob | InstantBackgroundSchemaCheckDataTypeJob | InstantBackgroundSchemaAddIndexJob | InstantBackgroundSchemaRemoveIndexJob | InstantBackgroundSchemaAddUniqueJob | InstantBackgroundSchemaRemoveUniqueJob | InstantBackgroundSchemaAddRequiredJob | InstantBackgroundSchemaRemoveRequiredJob; export type PlatformApiAuth = { token: string; } | { accessToken: string; refreshToken: string; clientId: string; clientSecret: string; onRefresh?: (tokenInfo: { accessToken: string; expiresAt: Date; }) => Promise; }; export type PlatformApiConfig = { auth?: PlatformApiAuth; apiURI?: string; }; export declare class PlatformApiMissingAuthError extends Error { constructor(); } /** * API methods for the Platform API * * Usage: * * ```ts * import { PlatformApi } from '@instantdb/platform'; * * const api = new PlatformApi({ auth: { token: 'oauth-access-token' } }); * const { apps } = await api.getApps({ * includeSchema: true, * includePerms: true, * }); * ``` */ export declare class PlatformApi { #private; /** * @param config – Runtime configuration. * @param config.auth.token – OAuth access-token obtained via the oauth flow * or a personal access token. * @throws {Error} When `token` is missing. */ constructor(config?: PlatformApiConfig); token(): string; canRefreshToken(): boolean; refreshToken(): Promise; withRetry any>(f: F, args: Parameters): Promise; /** * Fetch a single app by its id. * * ```ts * const { app } = await api.getApp('MY_APP_ID', { * includeSchema: true, * includePerms: true, * }); * ``` * * @template Opts – Narrow the shape of the response via the * {@link AppDataOpts} flags. * @param appId – UUID of the app. * @param opts – `{ includeSchema?: boolean; includePerms?: boolean }` * @returns A typed wrapper containing the app, whose shape is expanded * according to `Opts`. */ getApp(appId: string, opts?: Opts): Promise>; /** * List **all apps** owned by the auth owner. * * ```ts * const { apps } = await api.getApps({ * includeSchema: true, * includePerms: true, * }); * ``` * * @template Opts – Same as {@link getApp}. * @param opts – `{ includeSchema?: boolean; includePerms?: boolean }` * @returns An array wrapper; each element’s shape follows `Opts`. */ getApps(opts?: Opts): Promise>; /** * List **all orgs** that the auth owner is a member of. * * ```ts * const { orgs } = await api.getOrgs(); * ``` * * @returns An array of orgs */ getOrgs(): Promise; /** * List **all apps** owned by the auth owner. * * ```ts * const { apps } = await api.getApps({ * includeSchema: true, * includePerms: true, * }); * ``` * * @template Opts – Same as {@link getApp}. * @param opts – `{ includeSchema?: boolean; includePerms?: boolean }` * @returns An array wrapper; each element’s shape follows `Opts`. */ getAppsForOrg(orgId: string, opts?: Opts): Promise>; /** * Gets the schema for an app by its id. * * ```ts * const { schema } = await api.getSchema('MY_APP_ID'); * ``` * * @param appId -- UUID of the app */ getSchema(appId: string): Promise; /** * Gets the permissions for an app by its id. * * ```ts * const { perms } = await api.getPerms('MY_APP_ID'); * ``` * * @param appId -- UUID of the app */ getPerms(appId: string): Promise; /** * Create a new app. * * The app will be placed in the authenticated user's account * if no orgId is provided. * * Optionally set permissions and schema. * * ```ts * const { app } = await api.createApp({ * title: 'My new app', * // Optional permissions * perms: { $default: { allow: { $default: 'false' } } }, * // Optional schema * schema: i.schema({ * entities: { books: i.entity({ title: i.string() }) }, * }), * }); * ``` * * @param fields * @param fields.title -- Title for app * @param fields.schema -- Optional schema for the app * @param fields.perms -- Optional permissions for the app * @param fields.orgId -- Optional id of the org that the app will be placed in */ createApp(fields: InstantAPICreateAppBody): Promise; /** * Create a new temporary app. * * Optionally set permissions and schema. * * ```ts * const { app } = await api.createTemporaryApp({ * title: 'My new app', * // Optional permissions * perms: { $default: { allow: { $default: 'false' } } }, * // Optional schema * schema: i.schema({ * entities: { books: i.entity({ title: i.string() }) }, * }), * }); * ``` * * @param fields * @param fields.title -- Title for app * @param fields.schema -- Optional schema for the app * @param fields.perms -- Optional permissions for the app */ createTemporaryApp(fields: InstantAPICreateTemporaryAppBody): Promise; /** * Update the title of an app by its id. * * ```ts * const { app } = await api.updateApp('MY_APP_ID', { * title: 'New title', * }); * ``` * * @param appId -- UUID of the app * @param fields.title -- New title for the app */ updateApp(appId: string, fields: InstantAPIUpdateAppBody): Promise; /** * Delete an app by its id. * * ```ts * const { app } = await api.deleteApp('MY_APP_ID'); * ``` * * @param appId -- UUID of the app */ deleteApp(appId: string): Promise; /** * Dry-run a **schema push** and receive a _plan_ of steps the server would * execute. * * ```ts * const { steps } = await api.planSchemaPush(appId, body); * ``` */ planSchemaPush(appId: string, body: InstantAPISchemaPushBody): Promise; /** * Execute a **schema push**. The server returns a long-running job * represented as a {@link ProgressPromise}: you can both `await` the final * result **or** subscribe to intermediate status updates. * * ```ts * // 1) Subscribe to progress * const schema = i.schema({ * entities: { * books: i.entity({ * title: i.string().indexed(), * }), * }, * }); * const job = api.schemaPush(appId, { overwrite: true, schema: schema }); * job * .then(({ summary }) => console.log('done!', summary)) * .catch((e) => console.error(e)); * job.subscribe({ * next: (status) => renderProgress(status), * }); * * // 2) Or just await it * const result = await api.schemaPush(appId, { schema: schema }); * ``` */ schemaPush(appId: string, body: InstantAPISchemaPushBody): ProgressPromise; /** * Update permission rules for an app by its id. * * Completely replaces the current rule set. * * ```ts * const { steps } = await api.pushPerms(appId, { * perms: { * $default: { allow: { $default: 'false' } }, * books: { allow: { view: 'true', $default: 'false' } }, * }, * }); * ``` */ pushPerms(appId: string, body: InstantAPIPushPermsBody): Promise; tokenInfo(): Promise; } export {}; //# sourceMappingURL=api.d.ts.map