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
196
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.10.32 to 0.11.0

100

dist/index.d.ts
import { tx, lookup, TransactionChunk } from "@instantdb/core";
import { User, AuthToken } from "@instantdb/core";
declare type NonEmpty<T> = {
type NonEmpty<T> = {
[K in keyof T]-?: Required<Pick<T, K>>;
}[keyof T];
declare type WhereArgs = {
type WhereArgs = {
in?: (string | number | boolean)[];
};
declare type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>;
declare type BaseWhereClause = {
type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>;
type BaseWhereClause = {
[key: string]: WhereClauseValue;
};
declare type WhereClauseWithCombinaton = {
type WhereClauseWithCombinaton = {
or?: WhereClause[] | WhereClauseValue;
and?: WhereClause[] | WhereClauseValue;
};
declare type WhereClause = WhereClauseWithCombinaton | (WhereClauseWithCombinaton & BaseWhereClause);
type WhereClause = WhereClauseWithCombinaton | (WhereClauseWithCombinaton & BaseWhereClause);
/**

@@ -25,8 +25,8 @@ * A tuple representing a cursor.

*/
declare type Cursor = [string, string, any, number];
declare type Direction = "asc" | "desc";
declare type Order = {
type Cursor = [string, string, any, number];
type Direction = "asc" | "desc";
type Order = {
serverCreatedAt: Direction;
};
declare type $Option = {
type $Option = {
$?: {

@@ -43,24 +43,24 @@ where?: WhereClause;

};
declare type Subquery = {
type Subquery = {
[namespace: string]: NamespaceVal;
};
declare type NamespaceVal = $Option | ($Option & Subquery);
type NamespaceVal = $Option | ($Option & Subquery);
interface Query {
[namespace: string]: NamespaceVal;
}
declare type InstantObject = {
type InstantObject = {
id: string;
[prop: string]: any;
};
declare type ResponseObject<K, Schema> = K extends keyof Schema ? {
type ResponseObject<K, Schema> = K extends keyof Schema ? {
id: string;
} & Schema[K] : InstantObject;
declare type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
declare type ResponseOf<Q, Schema> = {
type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
type ResponseOf<Q, Schema> = {
[K in keyof Q]: IsEmptyObject<Q[K]> extends true ? ResponseObject<K, Schema>[] : (ResponseOf<Q[K], Schema> & ResponseObject<K, Schema>)[];
};
declare type Remove$<T> = T extends object ? {
type Remove$<T> = T extends object ? {
[K in keyof T as Exclude<K, "$">]: Remove$<T[K]>;
} : T;
declare type QueryResponse<T, Schema> = ResponseOf<{
type QueryResponse<T, Schema> = ResponseOf<{
[K in keyof T]: Remove$<T[K]>;

@@ -71,3 +71,3 @@ }, Schema>;

*/
export declare type DebugCheckResult = {
export type DebugCheckResult = {
/** The ID of the record. */

@@ -104,6 +104,6 @@ id: string;

* */
declare type Exactly<Parent, Child extends Parent> = Parent & {
type Exactly<Parent, Child extends Parent> = Parent & {
[K in keyof Child]: K extends keyof Parent ? Child[K] : never;
};
declare type Config = {
type Config = {
appId: string;

@@ -113,6 +113,6 @@ adminToken: string;

};
declare type FilledConfig = Config & {
type FilledConfig = Config & {
apiURI: string;
};
declare type ImpersonationOpts = {
type ImpersonationOpts = {
email: string;

@@ -185,3 +185,3 @@ } | {

*/
query: <Q extends Query>(query: Exactly<Query, Q>) => Promise<ResponseOf<{ [K in keyof Q]: Remove$<Q[K]>; }, Schema>>;
query: <Q extends Query>(query: Exactly<Query, Q>) => Promise<QueryResponse<Q, Schema>>;
/**

@@ -235,3 +235,3 @@ * Use this to write data! You can create, update, delete, and link objects

}) => Promise<{
result: ResponseOf<{ [K in keyof Q]: Remove$<Q[K]>; }, Schema>;
result: QueryResponse<Q, Schema>;
checkResults: DebugCheckResult[];

@@ -315,52 +315,2 @@ }>;

export { init, id, tx, lookup, Config, ImpersonationOpts, TransactionChunk, };
/**
* @deprecated since 0.7.0, use db.auth instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare const auth: {
/**
* Creates a login token for the user with the given email.
* If that user does not exist, we create one.
*
* This is often useful for writing custom auth flows.
*
* @example
* app.post('/custom_sign_in', async (req, res) => {
* // ... your custom flow for users
* const token = await auth.createToken(email)
* return res.status(200).send({ token })
* })
*
* @see https://docs.instantdb.com/docs/backend#custom-auth
*/
createToken(email: string): Promise<AuthToken>;
/**
* Verifies a given token and returns the associated user.
*
* This is often useful for writing custom endpoints, where you need
* to authenticate users.
*
* @example
* app.post('/custom_endpoint', async (req, res) => {
* const user = await auth.verifyToken(req.headers['token'])
* if (!user) {
* return res.status(400).send('Uh oh, you are not authenticated')
* }
* // ...
* })
* @see https://docs.instantdb.com/docs/backend#custom-endpoints
*/
verifyToken(token: AuthToken): Promise<User>;
};
/**
* @deprecated since 0.7.0, use db.query instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare function query<Q extends Query>(query: Exactly<Query, Q>): Promise<QueryResponse<Q, {}>>;
/**
* @deprecated since 0.7.0, use db.transact instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare function transact(inputChunks: TransactionChunk | TransactionChunk[]): Promise<any>;
export { auth, query, transact };
//# sourceMappingURL=index.d.ts.map

@@ -35,3 +35,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.transact = exports.query = exports.auth = exports.lookup = exports.tx = exports.id = exports.init = void 0;
exports.lookup = exports.tx = exports.id = void 0;
exports.init = init;
const core_1 = require("@instantdb/core");

@@ -48,3 +49,2 @@ Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_1.tx; } });

const r = Object.assign(Object.assign({}, defaultConfig), config);
_GLOBAL_CONFIG = r;
return r;

@@ -125,3 +125,2 @@ }

}
exports.init = init;
/**

@@ -345,3 +344,3 @@ *

return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const config = this.config;
yield jsonFetch(`${config.apiURI}/admin/sign_out`, {

@@ -361,102 +360,2 @@ method: "POST",

}
/**
* @deprecated since 0.7.0
*/
let _GLOBAL_CONFIG = undefined;
function getConfig() {
assert(_GLOBAL_CONFIG, "Uh oh! Looks like `init` hasn't run yet. Make sure `init` runs " +
"before your first `query` or `transact`.");
return _GLOBAL_CONFIG;
}
/**
* @deprecated since 0.7.0, use db.auth instead.
* @see https://docs.instantdb.com/docs/backend
*/
const auth = {
/**
* Creates a login token for the user with the given email.
* If that user does not exist, we create one.
*
* This is often useful for writing custom auth flows.
*
* @example
* app.post('/custom_sign_in', async (req, res) => {
* // ... your custom flow for users
* const token = await auth.createToken(email)
* return res.status(200).send({ token })
* })
*
* @see https://docs.instantdb.com/docs/backend#custom-auth
*/
createToken(email) {
return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const ret = yield jsonFetch(`${config.apiURI}/admin/refresh_tokens`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ email }),
});
return ret.user.refresh_token;
});
},
/**
* Verifies a given token and returns the associated user.
*
* This is often useful for writing custom endpoints, where you need
* to authenticate users.
*
* @example
* app.post('/custom_endpoint', async (req, res) => {
* const user = await auth.verifyToken(req.headers['token'])
* if (!user) {
* return res.status(400).send('Uh oh, you are not authenticated')
* }
* // ...
* })
* @see https://docs.instantdb.com/docs/backend#custom-endpoints
*/
verifyToken(token) {
return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const res = yield jsonFetch(`${config.apiURI}/runtime/auth/verify_refresh_token`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
"app-id": config.appId,
"refresh-token": token,
}),
});
return res.user;
});
},
};
exports.auth = auth;
/**
* @deprecated since 0.7.0, use db.query instead.
* @see https://docs.instantdb.com/docs/backend
*/
function query(query) {
const config = getConfig();
return jsonFetch(`${config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ query: query }),
});
}
exports.query = query;
/**
* @deprecated since 0.7.0, use db.transact instead.
* @see https://docs.instantdb.com/docs/backend
*/
function transact(inputChunks) {
const config = getConfig();
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => (0, core_1.getOps)(tx));
return jsonFetch(`${config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ steps: steps }),
});
}
exports.transact = transact;
//# sourceMappingURL=index.js.map
import { tx, lookup, TransactionChunk } from "@instantdb/core";
import { User, AuthToken } from "@instantdb/core";
declare type NonEmpty<T> = {
type NonEmpty<T> = {
[K in keyof T]-?: Required<Pick<T, K>>;
}[keyof T];
declare type WhereArgs = {
type WhereArgs = {
in?: (string | number | boolean)[];
};
declare type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>;
declare type BaseWhereClause = {
type WhereClauseValue = string | number | boolean | NonEmpty<WhereArgs>;
type BaseWhereClause = {
[key: string]: WhereClauseValue;
};
declare type WhereClauseWithCombinaton = {
type WhereClauseWithCombinaton = {
or?: WhereClause[] | WhereClauseValue;
and?: WhereClause[] | WhereClauseValue;
};
declare type WhereClause = WhereClauseWithCombinaton | (WhereClauseWithCombinaton & BaseWhereClause);
type WhereClause = WhereClauseWithCombinaton | (WhereClauseWithCombinaton & BaseWhereClause);
/**

@@ -25,8 +25,8 @@ * A tuple representing a cursor.

*/
declare type Cursor = [string, string, any, number];
declare type Direction = "asc" | "desc";
declare type Order = {
type Cursor = [string, string, any, number];
type Direction = "asc" | "desc";
type Order = {
serverCreatedAt: Direction;
};
declare type $Option = {
type $Option = {
$?: {

@@ -43,24 +43,24 @@ where?: WhereClause;

};
declare type Subquery = {
type Subquery = {
[namespace: string]: NamespaceVal;
};
declare type NamespaceVal = $Option | ($Option & Subquery);
type NamespaceVal = $Option | ($Option & Subquery);
interface Query {
[namespace: string]: NamespaceVal;
}
declare type InstantObject = {
type InstantObject = {
id: string;
[prop: string]: any;
};
declare type ResponseObject<K, Schema> = K extends keyof Schema ? {
type ResponseObject<K, Schema> = K extends keyof Schema ? {
id: string;
} & Schema[K] : InstantObject;
declare type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
declare type ResponseOf<Q, Schema> = {
type IsEmptyObject<T> = T extends Record<string, never> ? true : false;
type ResponseOf<Q, Schema> = {
[K in keyof Q]: IsEmptyObject<Q[K]> extends true ? ResponseObject<K, Schema>[] : (ResponseOf<Q[K], Schema> & ResponseObject<K, Schema>)[];
};
declare type Remove$<T> = T extends object ? {
type Remove$<T> = T extends object ? {
[K in keyof T as Exclude<K, "$">]: Remove$<T[K]>;
} : T;
declare type QueryResponse<T, Schema> = ResponseOf<{
type QueryResponse<T, Schema> = ResponseOf<{
[K in keyof T]: Remove$<T[K]>;

@@ -71,3 +71,3 @@ }, Schema>;

*/
export declare type DebugCheckResult = {
export type DebugCheckResult = {
/** The ID of the record. */

@@ -104,6 +104,6 @@ id: string;

* */
declare type Exactly<Parent, Child extends Parent> = Parent & {
type Exactly<Parent, Child extends Parent> = Parent & {
[K in keyof Child]: K extends keyof Parent ? Child[K] : never;
};
declare type Config = {
type Config = {
appId: string;

@@ -113,6 +113,6 @@ adminToken: string;

};
declare type FilledConfig = Config & {
type FilledConfig = Config & {
apiURI: string;
};
declare type ImpersonationOpts = {
type ImpersonationOpts = {
email: string;

@@ -185,3 +185,3 @@ } | {

*/
query: <Q extends Query>(query: Exactly<Query, Q>) => Promise<ResponseOf<{ [K in keyof Q]: Remove$<Q[K]>; }, Schema>>;
query: <Q extends Query>(query: Exactly<Query, Q>) => Promise<QueryResponse<Q, Schema>>;
/**

@@ -235,3 +235,3 @@ * Use this to write data! You can create, update, delete, and link objects

}) => Promise<{
result: ResponseOf<{ [K in keyof Q]: Remove$<Q[K]>; }, Schema>;
result: QueryResponse<Q, Schema>;
checkResults: DebugCheckResult[];

@@ -315,52 +315,2 @@ }>;

export { init, id, tx, lookup, Config, ImpersonationOpts, TransactionChunk, };
/**
* @deprecated since 0.7.0, use db.auth instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare const auth: {
/**
* Creates a login token for the user with the given email.
* If that user does not exist, we create one.
*
* This is often useful for writing custom auth flows.
*
* @example
* app.post('/custom_sign_in', async (req, res) => {
* // ... your custom flow for users
* const token = await auth.createToken(email)
* return res.status(200).send({ token })
* })
*
* @see https://docs.instantdb.com/docs/backend#custom-auth
*/
createToken(email: string): Promise<AuthToken>;
/**
* Verifies a given token and returns the associated user.
*
* This is often useful for writing custom endpoints, where you need
* to authenticate users.
*
* @example
* app.post('/custom_endpoint', async (req, res) => {
* const user = await auth.verifyToken(req.headers['token'])
* if (!user) {
* return res.status(400).send('Uh oh, you are not authenticated')
* }
* // ...
* })
* @see https://docs.instantdb.com/docs/backend#custom-endpoints
*/
verifyToken(token: AuthToken): Promise<User>;
};
/**
* @deprecated since 0.7.0, use db.query instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare function query<Q extends Query>(query: Exactly<Query, Q>): Promise<QueryResponse<Q, {}>>;
/**
* @deprecated since 0.7.0, use db.transact instead.
* @see https://docs.instantdb.com/docs/backend
*/
declare function transact(inputChunks: TransactionChunk | TransactionChunk[]): Promise<any>;
export { auth, query, transact };
//# sourceMappingURL=index.d.ts.map

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

const r = Object.assign(Object.assign({}, defaultConfig), config);
_GLOBAL_CONFIG = r;
return r;

@@ -313,3 +312,3 @@ }

return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const config = this.config;
yield jsonFetch(`${config.apiURI}/admin/sign_out`, {

@@ -330,100 +329,2 @@ method: "POST",

}
/**
* @deprecated since 0.7.0
*/
let _GLOBAL_CONFIG = undefined;
function getConfig() {
assert(_GLOBAL_CONFIG, "Uh oh! Looks like `init` hasn't run yet. Make sure `init` runs " +
"before your first `query` or `transact`.");
return _GLOBAL_CONFIG;
}
/**
* @deprecated since 0.7.0, use db.auth instead.
* @see https://docs.instantdb.com/docs/backend
*/
const auth = {
/**
* Creates a login token for the user with the given email.
* If that user does not exist, we create one.
*
* This is often useful for writing custom auth flows.
*
* @example
* app.post('/custom_sign_in', async (req, res) => {
* // ... your custom flow for users
* const token = await auth.createToken(email)
* return res.status(200).send({ token })
* })
*
* @see https://docs.instantdb.com/docs/backend#custom-auth
*/
createToken(email) {
return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const ret = yield jsonFetch(`${config.apiURI}/admin/refresh_tokens`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ email }),
});
return ret.user.refresh_token;
});
},
/**
* Verifies a given token and returns the associated user.
*
* This is often useful for writing custom endpoints, where you need
* to authenticate users.
*
* @example
* app.post('/custom_endpoint', async (req, res) => {
* const user = await auth.verifyToken(req.headers['token'])
* if (!user) {
* return res.status(400).send('Uh oh, you are not authenticated')
* }
* // ...
* })
* @see https://docs.instantdb.com/docs/backend#custom-endpoints
*/
verifyToken(token) {
return __awaiter(this, void 0, void 0, function* () {
const config = getConfig();
const res = yield jsonFetch(`${config.apiURI}/runtime/auth/verify_refresh_token`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
"app-id": config.appId,
"refresh-token": token,
}),
});
return res.user;
});
},
};
/**
* @deprecated since 0.7.0, use db.query instead.
* @see https://docs.instantdb.com/docs/backend
*/
function query(query) {
const config = getConfig();
return jsonFetch(`${config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ query: query }),
});
}
/**
* @deprecated since 0.7.0, use db.transact instead.
* @see https://docs.instantdb.com/docs/backend
*/
function transact(inputChunks) {
const config = getConfig();
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ steps: steps }),
});
}
export { auth, query, transact };
//# sourceMappingURL=index.js.map
{
"name": "@instantdb/admin",
"version": "0.10.32",
"version": "0.11.0",
"description": "Admin SDK for Instant DB",

@@ -23,9 +23,9 @@ "main": "dist/index.js",

"npm-run-all": "^4.1.5",
"typescript": "^4.6.4",
"typescript": "^5.5.4",
"vitest": "^0.21.0"
},
"dependencies": {
"@instantdb/core": "0.10.32",
"@instantdb/core": "0.11.0",
"uuid": "^9.0.1"
}
}

@@ -152,3 +152,2 @@ import { tx, lookup, TransactionChunk, getOps } from "@instantdb/core";

const r = { ...defaultConfig, ...config };
_GLOBAL_CONFIG = r;
return r;

@@ -495,3 +494,3 @@ }

async signOut(email: string): Promise<void> {
const config = getConfig();
const config = this.config;
await jsonFetch(`${config.apiURI}/admin/sign_out`, {

@@ -524,112 +523,1 @@ method: "POST",

}
/**
* @deprecated since 0.7.0
*/
let _GLOBAL_CONFIG: FilledConfig | undefined = undefined;
function getConfig(): FilledConfig {
assert(
_GLOBAL_CONFIG,
"Uh oh! Looks like `init` hasn't run yet. Make sure `init` runs " +
"before your first `query` or `transact`.",
);
return _GLOBAL_CONFIG;
}
/**
* @deprecated since 0.7.0, use db.auth instead.
* @see https://docs.instantdb.com/docs/backend
*/
const auth = {
/**
* Creates a login token for the user with the given email.
* If that user does not exist, we create one.
*
* This is often useful for writing custom auth flows.
*
* @example
* app.post('/custom_sign_in', async (req, res) => {
* // ... your custom flow for users
* const token = await auth.createToken(email)
* return res.status(200).send({ token })
* })
*
* @see https://docs.instantdb.com/docs/backend#custom-auth
*/
async createToken(email: string): Promise<AuthToken> {
const config = getConfig();
const ret: { user: { refresh_token: string } } = await jsonFetch(
`${config.apiURI}/admin/refresh_tokens`,
{
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ email }),
},
);
return ret.user.refresh_token;
},
/**
* Verifies a given token and returns the associated user.
*
* This is often useful for writing custom endpoints, where you need
* to authenticate users.
*
* @example
* app.post('/custom_endpoint', async (req, res) => {
* const user = await auth.verifyToken(req.headers['token'])
* if (!user) {
* return res.status(400).send('Uh oh, you are not authenticated')
* }
* // ...
* })
* @see https://docs.instantdb.com/docs/backend#custom-endpoints
*/
async verifyToken(token: AuthToken): Promise<User> {
const config = getConfig();
const res = await jsonFetch(
`${config.apiURI}/runtime/auth/verify_refresh_token`,
{
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
"app-id": config.appId,
"refresh-token": token,
}),
},
);
return res.user;
},
};
/**
* @deprecated since 0.7.0, use db.query instead.
* @see https://docs.instantdb.com/docs/backend
*/
function query<Q extends Query>(
query: Exactly<Query, Q>,
): Promise<QueryResponse<Q, {}>> {
const config = getConfig();
return jsonFetch(`${config.apiURI}/admin/query`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ query: query }),
});
}
/**
* @deprecated since 0.7.0, use db.transact instead.
* @see https://docs.instantdb.com/docs/backend
*/
function transact(inputChunks: TransactionChunk | TransactionChunk[]) {
const config = getConfig();
const chunks = Array.isArray(inputChunks) ? inputChunks : [inputChunks];
const steps = chunks.flatMap((tx) => getOps(tx));
return jsonFetch(`${config.apiURI}/admin/transact`, {
method: "POST",
headers: authorizedHeaders(config),
body: JSON.stringify({ steps: steps }),
});
}
export { auth, query, transact };

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