Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@instantdb/admin

Package Overview
Dependencies
Maintainers
0
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@instantdb/admin - npm Package Compare versions

Comparing version 0.14.29 to 0.14.30

129

dist/index.d.ts

@@ -1,2 +0,2 @@

import { tx, lookup, i, id, type TransactionChunk, type AuthToken, type Exactly, type User, type Query, type QueryResponse, type InstaQLQueryParams, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes } from "@instantdb/core";
import { tx, lookup, i, id, type TransactionChunk, type AuthToken, type Exactly, type User, type Query, type QueryResponse, type DoNotUseQueryResponse, type InstaQLQueryParams, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type DoNotUseInstantSchema, type DoNotUseUnknownSchema } from "@instantdb/core";
type DebugCheckResult = {

@@ -17,2 +17,11 @@ /** The ID of the record. */

};
type DoNotUseConfig<Schema extends DoNotUseInstantSchema<any, any, any>> = {
appId: string;
adminToken: string;
apiURI?: string;
schema?: Schema;
};
type DoNotUseFilledConfig<Schema extends DoNotUseInstantSchema<any, any, any>> = DoNotUseConfig<Schema> & {
apiURI: string;
};
type FilledConfig = Config & {

@@ -53,2 +62,3 @@ apiURI: string;

}): InstantAdmin<Schema, WithCardinalityInference>;
declare function do_not_use_init_experimental<Schema extends DoNotUseInstantSchema<any, any, any> = DoNotUseUnknownSchema>(config: DoNotUseConfig<Schema>): DoNotUseInstantAdmin<Schema>;
/**

@@ -340,3 +350,118 @@ *

}
export { init, init_experimental, id, tx, lookup, i, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdmin, type User, type InstaQLQueryParams, type Query, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, };
/**
*
* The first step: init your application!
*
* Visit https://instantdb.com/dash to get your `appId` and `adminToken` :)
*
* @example
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
*/
declare class DoNotUseInstantAdmin<Schema extends DoNotUseInstantSchema<any, any, any>> {
config: DoNotUseFilledConfig<Schema>;
auth: Auth;
storage: Storage;
impersonationOpts?: ImpersonationOpts;
tx: import("@instantdb/core").TxChunk<Schema>;
constructor(_config: DoNotUseConfig<Schema>);
/**
* Sometimes you want to scope queries to a specific user.
*
* You can provide a user's auth token, email, or impersonate a guest.
*
* @see https://instantdb.com/docs/backend#impersonating-users
* @example
* await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
*/
asUser: (opts: ImpersonationOpts) => DoNotUseInstantAdmin<Schema>;
/**
* Use this to query your data!
*
* @see https://instantdb.com/docs/instaql
*
* @example
* // fetch all goals
* await db.query({ goals: {} })
*
* // goals where the title is "Get Fit"
* await db.query({ goals: { $: { where: { title: "Get Fit" } } } })
*
* // all goals, _alongside_ their todos
* await db.query({ goals: { todos: {} } })
*/
query: <Q extends InstaQLQueryParams<Schema>>(query: Q) => Promise<DoNotUseQueryResponse<Q, Schema>>;
/**
* Use this to write data! You can create, update, delete, and link objects
*
* @see https://instantdb.com/docs/instaml
*
* @example
* // Create a new object in the `goals` namespace
* const goalId = id();
* db.transact(tx.goals[goalId].update({title: "Get fit"}))
*
* // Update the title
* db.transact(tx.goals[goalId].update({title: "Get super fit"}))
*
* // Delete it
* db.transact(tx.goals[goalId].delete())
*
* // Or create an association:
* todoId = id();
* db.transact([
* tx.todos[todoId].update({ title: 'Go on a run' }),
* tx.goals[goalId].link({todos: todoId}),
* ])
*/
transact: (inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[]) => Promise<any>;
/**
* Like `query`, but returns debugging information
* for permissions checks along with the result.
* Useful for inspecting the values returned by the permissions checks.
* Note, this will return debug information for *all* entities
* that match the query's `where` clauses.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the query.
*
* @see https://instantdb.com/docs/instaql
*
* @example
* await db.asUser({ guest: true }).debugQuery(
* { goals: {} },
* { rules: { goals: { allow: { read: "auth.id != null" } } }
* )
*/
debugQuery: <Q extends InstaQLQueryParams<Schema>>(query: Q, opts?: {
rules: any;
}) => Promise<{
result: DoNotUseQueryResponse<Q, Schema>;
checkResults: DebugCheckResult[];
}>;
/**
* Like `transact`, but does not write to the database.
* Returns debugging information for permissions checks.
* Useful for inspecting the values returned by the permissions checks.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the duration of the transaction.
*
* @example
* const goalId = id();
* db.asUser({ guest: true }).debugTransact(
* [tx.goals[goalId].update({title: "Get fit"})],
* { rules: { goals: { allow: { update: "auth.id != null" } } }
* )
*/
debugTransact: (inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[], opts?: {
rules?: any;
}) => Promise<any>;
}
export { init, init_experimental, do_not_use_init_experimental, id, tx, lookup, i, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdmin, type User, type InstaQLQueryParams, type Query, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type DoNotUseInstantSchema, type DoNotUseUnknownSchema, };
//# sourceMappingURL=index.d.ts.map

@@ -18,2 +18,3 @@ "use strict";

exports.init_experimental = init_experimental;
exports.do_not_use_init_experimental = do_not_use_init_experimental;
const core_1 = require("@instantdb/core");

@@ -32,2 +33,9 @@ Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_1.tx; } });

}
function doNotUseConfigWithDefaults(config) {
const defaultConfig = {
apiURI: "https://api.instantdb.com",
};
const r = Object.assign(Object.assign({}, defaultConfig), config);
return r;
}
function withImpersonation(headers, opts) {

@@ -110,2 +118,5 @@ if ("email" in opts) {

}
function do_not_use_init_experimental(config) {
return new DoNotUseInstantAdmin(config);
}
/**

@@ -503,2 +514,154 @@ *

}
/**
*
* The first step: init your application!
*
* Visit https://instantdb.com/dash to get your `appId` and `adminToken` :)
*
* @example
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
*/
class DoNotUseInstantAdmin {
constructor(_config) {
this.tx = (0, core_1.txInit)();
/**
* Sometimes you want to scope queries to a specific user.
*
* You can provide a user's auth token, email, or impersonate a guest.
*
* @see https://instantdb.com/docs/backend#impersonating-users
* @example
* await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
*/
this.asUser = (opts) => {
const newClient = new DoNotUseInstantAdmin(Object.assign({}, this.config));
newClient.impersonationOpts = opts;
return newClient;
};
/**
* Use this to query your data!
*
* @see https://instantdb.com/docs/instaql
*
* @example
* // fetch all goals
* await db.query({ goals: {} })
*
* // goals where the title is "Get Fit"
* await db.query({ goals: { $: { where: { title: "Get Fit" } } } })
*
* // all goals, _alongside_ their todos
* await db.query({ goals: { todos: {} } })
*/
this.query = (query) => {
return jsonFetch(`${this.config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
query: query,
"inference?": true,
}),
});
};
/**
* Use this to write data! You can create, update, delete, and link objects
*
* @see https://instantdb.com/docs/instaml
*
* @example
* // Create a new object in the `goals` namespace
* const goalId = id();
* db.transact(tx.goals[goalId].update({title: "Get fit"}))
*
* // Update the title
* db.transact(tx.goals[goalId].update({title: "Get super fit"}))
*
* // Delete it
* db.transact(tx.goals[goalId].delete())
*
* // Or create an association:
* todoId = id();
* db.transact([
* tx.todos[todoId].update({ title: 'Go on a run' }),
* tx.goals[goalId].link({todos: todoId}),
* ])
*/
this.transact = (inputChunks) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => (0, core_1.getOps)(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ steps: steps }),
});
};
/**
* Like `query`, but returns debugging information
* for permissions checks along with the result.
* Useful for inspecting the values returned by the permissions checks.
* Note, this will return debug information for *all* entities
* that match the query's `where` clauses.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the query.
*
* @see https://instantdb.com/docs/instaql
*
* @example
* await db.asUser({ guest: true }).debugQuery(
* { goals: {} },
* { rules: { goals: { allow: { read: "auth.id != null" } } }
* )
*/
this.debugQuery = (query, opts) => __awaiter(this, void 0, void 0, function* () {
const response = yield jsonFetch(`${this.config.apiURI}/admin/query_perms_check`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ query, "rules-override": opts === null || opts === void 0 ? void 0 : opts.rules }),
});
return {
result: response.result,
checkResults: response["check-results"],
};
});
/**
* Like `transact`, but does not write to the database.
* Returns debugging information for permissions checks.
* Useful for inspecting the values returned by the permissions checks.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the duration of the transaction.
*
* @example
* const goalId = id();
* db.asUser({ guest: true }).debugTransact(
* [tx.goals[goalId].update({title: "Get fit"})],
* { rules: { goals: { allow: { update: "auth.id != null" } } }
* )
*/
this.debugTransact = (inputChunks, opts) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => (0, core_1.getOps)(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact_perms_check`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
steps: steps,
"rules-override": opts === null || opts === void 0 ? void 0 : opts.rules,
// @ts-expect-error because we're using a private API (for now)
"dangerously-commit-tx": opts === null || opts === void 0 ? void 0 : opts.__dangerouslyCommit,
}),
});
};
this.config = doNotUseConfigWithDefaults(_config);
this.auth = new Auth(this.config);
this.storage = new Storage(this.config);
}
}
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { tx, lookup, i, id, type TransactionChunk, type AuthToken, type Exactly, type User, type Query, type QueryResponse, type InstaQLQueryParams, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes } from "@instantdb/core";
import { tx, lookup, i, id, type TransactionChunk, type AuthToken, type Exactly, type User, type Query, type QueryResponse, type DoNotUseQueryResponse, type InstaQLQueryParams, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type DoNotUseInstantSchema, type DoNotUseUnknownSchema } from "@instantdb/core";
type DebugCheckResult = {

@@ -17,2 +17,11 @@ /** The ID of the record. */

};
type DoNotUseConfig<Schema extends DoNotUseInstantSchema<any, any, any>> = {
appId: string;
adminToken: string;
apiURI?: string;
schema?: Schema;
};
type DoNotUseFilledConfig<Schema extends DoNotUseInstantSchema<any, any, any>> = DoNotUseConfig<Schema> & {
apiURI: string;
};
type FilledConfig = Config & {

@@ -53,2 +62,3 @@ apiURI: string;

}): InstantAdmin<Schema, WithCardinalityInference>;
declare function do_not_use_init_experimental<Schema extends DoNotUseInstantSchema<any, any, any> = DoNotUseUnknownSchema>(config: DoNotUseConfig<Schema>): DoNotUseInstantAdmin<Schema>;
/**

@@ -340,3 +350,118 @@ *

}
export { init, init_experimental, id, tx, lookup, i, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdmin, type User, type InstaQLQueryParams, type Query, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, };
/**
*
* The first step: init your application!
*
* Visit https://instantdb.com/dash to get your `appId` and `adminToken` :)
*
* @example
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
*/
declare class DoNotUseInstantAdmin<Schema extends DoNotUseInstantSchema<any, any, any>> {
config: DoNotUseFilledConfig<Schema>;
auth: Auth;
storage: Storage;
impersonationOpts?: ImpersonationOpts;
tx: import("@instantdb/core").TxChunk<Schema>;
constructor(_config: DoNotUseConfig<Schema>);
/**
* Sometimes you want to scope queries to a specific user.
*
* You can provide a user's auth token, email, or impersonate a guest.
*
* @see https://instantdb.com/docs/backend#impersonating-users
* @example
* await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
*/
asUser: (opts: ImpersonationOpts) => DoNotUseInstantAdmin<Schema>;
/**
* Use this to query your data!
*
* @see https://instantdb.com/docs/instaql
*
* @example
* // fetch all goals
* await db.query({ goals: {} })
*
* // goals where the title is "Get Fit"
* await db.query({ goals: { $: { where: { title: "Get Fit" } } } })
*
* // all goals, _alongside_ their todos
* await db.query({ goals: { todos: {} } })
*/
query: <Q extends InstaQLQueryParams<Schema>>(query: Q) => Promise<DoNotUseQueryResponse<Q, Schema>>;
/**
* Use this to write data! You can create, update, delete, and link objects
*
* @see https://instantdb.com/docs/instaml
*
* @example
* // Create a new object in the `goals` namespace
* const goalId = id();
* db.transact(tx.goals[goalId].update({title: "Get fit"}))
*
* // Update the title
* db.transact(tx.goals[goalId].update({title: "Get super fit"}))
*
* // Delete it
* db.transact(tx.goals[goalId].delete())
*
* // Or create an association:
* todoId = id();
* db.transact([
* tx.todos[todoId].update({ title: 'Go on a run' }),
* tx.goals[goalId].link({todos: todoId}),
* ])
*/
transact: (inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[]) => Promise<any>;
/**
* Like `query`, but returns debugging information
* for permissions checks along with the result.
* Useful for inspecting the values returned by the permissions checks.
* Note, this will return debug information for *all* entities
* that match the query's `where` clauses.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the query.
*
* @see https://instantdb.com/docs/instaql
*
* @example
* await db.asUser({ guest: true }).debugQuery(
* { goals: {} },
* { rules: { goals: { allow: { read: "auth.id != null" } } }
* )
*/
debugQuery: <Q extends InstaQLQueryParams<Schema>>(query: Q, opts?: {
rules: any;
}) => Promise<{
result: DoNotUseQueryResponse<Q, Schema>;
checkResults: DebugCheckResult[];
}>;
/**
* Like `transact`, but does not write to the database.
* Returns debugging information for permissions checks.
* Useful for inspecting the values returned by the permissions checks.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the duration of the transaction.
*
* @example
* const goalId = id();
* db.asUser({ guest: true }).debugTransact(
* [tx.goals[goalId].update({title: "Get fit"})],
* { rules: { goals: { allow: { update: "auth.id != null" } } }
* )
*/
debugTransact: (inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[], opts?: {
rules?: any;
}) => Promise<any>;
}
export { init, init_experimental, do_not_use_init_experimental, id, tx, lookup, i, type Config, type ImpersonationOpts, type TransactionChunk, type DebugCheckResult, type InstantAdmin, type User, type InstaQLQueryParams, type Query, type QueryResponse, type InstantQuery, type InstantQueryResult, type InstantSchema, type InstantSchemaDatabase, type InstantObject, type InstantEntity, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type InstantGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type DoNotUseInstantSchema, type DoNotUseUnknownSchema, };
//# sourceMappingURL=index.d.ts.map

@@ -19,2 +19,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
function doNotUseConfigWithDefaults(config) {
const defaultConfig = {
apiURI: "https://api.instantdb.com",
};
const r = Object.assign(Object.assign({}, defaultConfig), config);
return r;
}
function withImpersonation(headers, opts) {

@@ -97,2 +104,5 @@ if ("email" in opts) {

}
function do_not_use_init_experimental(config) {
return new DoNotUseInstantAdmin(config);
}
/**

@@ -490,3 +500,155 @@ *

}
export { init, init_experimental, id, tx, lookup, i, };
/**
*
* The first step: init your application!
*
* Visit https://instantdb.com/dash to get your `appId` and `adminToken` :)
*
* @example
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
*/
class DoNotUseInstantAdmin {
constructor(_config) {
this.tx = txInit();
/**
* Sometimes you want to scope queries to a specific user.
*
* You can provide a user's auth token, email, or impersonate a guest.
*
* @see https://instantdb.com/docs/backend#impersonating-users
* @example
* await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
*/
this.asUser = (opts) => {
const newClient = new DoNotUseInstantAdmin(Object.assign({}, this.config));
newClient.impersonationOpts = opts;
return newClient;
};
/**
* Use this to query your data!
*
* @see https://instantdb.com/docs/instaql
*
* @example
* // fetch all goals
* await db.query({ goals: {} })
*
* // goals where the title is "Get Fit"
* await db.query({ goals: { $: { where: { title: "Get Fit" } } } })
*
* // all goals, _alongside_ their todos
* await db.query({ goals: { todos: {} } })
*/
this.query = (query) => {
return jsonFetch(`${this.config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
query: query,
"inference?": true,
}),
});
};
/**
* Use this to write data! You can create, update, delete, and link objects
*
* @see https://instantdb.com/docs/instaml
*
* @example
* // Create a new object in the `goals` namespace
* const goalId = id();
* db.transact(tx.goals[goalId].update({title: "Get fit"}))
*
* // Update the title
* db.transact(tx.goals[goalId].update({title: "Get super fit"}))
*
* // Delete it
* db.transact(tx.goals[goalId].delete())
*
* // Or create an association:
* todoId = id();
* db.transact([
* tx.todos[todoId].update({ title: 'Go on a run' }),
* tx.goals[goalId].link({todos: todoId}),
* ])
*/
this.transact = (inputChunks) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ steps: steps }),
});
};
/**
* Like `query`, but returns debugging information
* for permissions checks along with the result.
* Useful for inspecting the values returned by the permissions checks.
* Note, this will return debug information for *all* entities
* that match the query's `where` clauses.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the query.
*
* @see https://instantdb.com/docs/instaql
*
* @example
* await db.asUser({ guest: true }).debugQuery(
* { goals: {} },
* { rules: { goals: { allow: { read: "auth.id != null" } } }
* )
*/
this.debugQuery = (query, opts) => __awaiter(this, void 0, void 0, function* () {
const response = yield jsonFetch(`${this.config.apiURI}/admin/query_perms_check`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ query, "rules-override": opts === null || opts === void 0 ? void 0 : opts.rules }),
});
return {
result: response.result,
checkResults: response["check-results"],
};
});
/**
* Like `transact`, but does not write to the database.
* Returns debugging information for permissions checks.
* Useful for inspecting the values returned by the permissions checks.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the duration of the transaction.
*
* @example
* const goalId = id();
* db.asUser({ guest: true }).debugTransact(
* [tx.goals[goalId].update({title: "Get fit"})],
* { rules: { goals: { allow: { update: "auth.id != null" } } }
* )
*/
this.debugTransact = (inputChunks, opts) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact_perms_check`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
steps: steps,
"rules-override": opts === null || opts === void 0 ? void 0 : opts.rules,
// @ts-expect-error because we're using a private API (for now)
"dangerously-commit-tx": opts === null || opts === void 0 ? void 0 : opts.__dangerouslyCommit,
}),
});
};
this.config = doNotUseConfigWithDefaults(_config);
this.auth = new Auth(this.config);
this.storage = new Storage(this.config);
}
}
export { init, init_experimental, do_not_use_init_experimental, id, tx, lookup, i, };
//# sourceMappingURL=index.js.map

2

dist/module/version.d.ts
export default version;
declare const version: "v0.14.29";
declare const version: "v0.14.30";
//# sourceMappingURL=version.d.ts.map
// Autogenerated by publish_packages.clj
const version = "v0.14.29";
const version = "v0.14.30";
export default version;
//# sourceMappingURL=version.js.map
export default version;
declare const version: "v0.14.29";
declare const version: "v0.14.30";
//# sourceMappingURL=version.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Autogenerated by publish_packages.clj
const version = "v0.14.29";
const version = "v0.14.30";
exports.default = version;
//# sourceMappingURL=version.js.map
{
"name": "@instantdb/admin",
"version": "v0.14.29",
"version": "v0.14.30",
"description": "Admin SDK for Instant DB",

@@ -28,4 +28,4 @@ "main": "dist/index.js",

"dependencies": {
"@instantdb/core": "v0.14.29"
"@instantdb/core": "v0.14.30"
}
}

@@ -19,2 +19,3 @@ import {

type QueryResponse,
type DoNotUseQueryResponse,
type InstaQLQueryParams,

@@ -41,2 +42,4 @@ type InstantQuery,

type ValueTypes,
type DoNotUseInstantSchema,
type DoNotUseUnknownSchema,
} from "@instantdb/core";

@@ -63,2 +66,12 @@

type DoNotUseConfig<Schema extends DoNotUseInstantSchema<any, any, any>> = {
appId: string;
adminToken: string;
apiURI?: string;
schema?: Schema;
};
type DoNotUseFilledConfig<Schema extends DoNotUseInstantSchema<any, any, any>> =
DoNotUseConfig<Schema> & { apiURI: string };
type FilledConfig = Config & { apiURI: string };

@@ -79,2 +92,12 @@

function doNotUseConfigWithDefaults<
Schema extends DoNotUseInstantSchema<any, any, any>,
>(config: DoNotUseConfig<Schema>): DoNotUseFilledConfig<Schema> {
const defaultConfig = {
apiURI: "https://api.instantdb.com",
};
const r = { ...defaultConfig, ...config };
return r;
}
function withImpersonation(

@@ -183,2 +206,8 @@ headers: { [key: string]: string },

function do_not_use_init_experimental<
Schema extends DoNotUseInstantSchema<any, any, any> = DoNotUseUnknownSchema,
>(config: DoNotUseConfig<Schema>) {
return new DoNotUseInstantAdmin<Schema>(config);
}
/**

@@ -683,5 +712,191 @@ *

/**
*
* The first step: init your application!
*
* Visit https://instantdb.com/dash to get your `appId` and `adminToken` :)
*
* @example
* const db = init({ appId: "my-app-id", adminToken: "my-admin-token" })
*/
class DoNotUseInstantAdmin<
Schema extends DoNotUseInstantSchema<any, any, any>,
> {
config: DoNotUseFilledConfig<Schema>;
auth: Auth;
storage: Storage;
impersonationOpts?: ImpersonationOpts;
public tx = txInit<Schema>();
constructor(_config: DoNotUseConfig<Schema>) {
this.config = doNotUseConfigWithDefaults(_config);
this.auth = new Auth(this.config);
this.storage = new Storage(this.config);
}
/**
* Sometimes you want to scope queries to a specific user.
*
* You can provide a user's auth token, email, or impersonate a guest.
*
* @see https://instantdb.com/docs/backend#impersonating-users
* @example
* await db.asUser({email: "stopa@instantdb.com"}).query({ goals: {} })
*/
asUser = (opts: ImpersonationOpts): DoNotUseInstantAdmin<Schema> => {
const newClient = new DoNotUseInstantAdmin<Schema>({
...this.config,
});
newClient.impersonationOpts = opts;
return newClient;
};
/**
* Use this to query your data!
*
* @see https://instantdb.com/docs/instaql
*
* @example
* // fetch all goals
* await db.query({ goals: {} })
*
* // goals where the title is "Get Fit"
* await db.query({ goals: { $: { where: { title: "Get Fit" } } } })
*
* // all goals, _alongside_ their todos
* await db.query({ goals: { todos: {} } })
*/
query = <Q extends InstaQLQueryParams<Schema>>(
query: Q,
): Promise<DoNotUseQueryResponse<Q, Schema>> => {
return jsonFetch(`${this.config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
query: query,
"inference?": true,
}),
});
};
/**
* Use this to write data! You can create, update, delete, and link objects
*
* @see https://instantdb.com/docs/instaml
*
* @example
* // Create a new object in the `goals` namespace
* const goalId = id();
* db.transact(tx.goals[goalId].update({title: "Get fit"}))
*
* // Update the title
* db.transact(tx.goals[goalId].update({title: "Get super fit"}))
*
* // Delete it
* db.transact(tx.goals[goalId].delete())
*
* // Or create an association:
* todoId = id();
* db.transact([
* tx.todos[todoId].update({ title: 'Go on a run' }),
* tx.goals[goalId].link({todos: todoId}),
* ])
*/
transact = (
inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],
) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ steps: steps }),
});
};
/**
* Like `query`, but returns debugging information
* for permissions checks along with the result.
* Useful for inspecting the values returned by the permissions checks.
* Note, this will return debug information for *all* entities
* that match the query's `where` clauses.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the query.
*
* @see https://instantdb.com/docs/instaql
*
* @example
* await db.asUser({ guest: true }).debugQuery(
* { goals: {} },
* { rules: { goals: { allow: { read: "auth.id != null" } } }
* )
*/
debugQuery = async <Q extends InstaQLQueryParams<Schema>>(
query: Q,
opts?: { rules: any },
): Promise<{
result: DoNotUseQueryResponse<Q, Schema>;
checkResults: DebugCheckResult[];
}> => {
const response = await jsonFetch(
`${this.config.apiURI}/admin/query_perms_check`,
{
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({ query, "rules-override": opts?.rules }),
},
);
return {
result: response.result,
checkResults: response["check-results"],
};
};
/**
* Like `transact`, but does not write to the database.
* Returns debugging information for permissions checks.
* Useful for inspecting the values returned by the permissions checks.
*
* Requires a user/guest context to be set with `asUser`,
* since permissions checks are user-specific.
*
* Accepts an optional configuration object with a `rules` key.
* The provided rules will override the rules in the database for the duration of the transaction.
*
* @example
* const goalId = id();
* db.asUser({ guest: true }).debugTransact(
* [tx.goals[goalId].update({title: "Get fit"})],
* { rules: { goals: { allow: { update: "auth.id != null" } } }
* )
*/
debugTransact = (
inputChunks: TransactionChunk<any, any> | TransactionChunk<any, any>[],
opts?: { rules?: any },
) => {
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${this.config.apiURI}/admin/transact_perms_check`, {
method: "POST",
headers: authorizedHeaders(this.config, this.impersonationOpts),
body: JSON.stringify({
steps: steps,
"rules-override": opts?.rules,
// @ts-expect-error because we're using a private API (for now)
"dangerously-commit-tx": opts?.__dangerouslyCommit,
}),
});
};
}
export {
init,
init_experimental,
do_not_use_init_experimental,
id,

@@ -726,2 +941,4 @@ tx,

type ValueTypes,
type DoNotUseInstantSchema,
type DoNotUseUnknownSchema,
};
// Autogenerated by publish_packages.clj
const version = "v0.14.29";
const version = "v0.14.30";
export default version;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc