@instantdb/admin
Advanced tools
Comparing version 0.12.16 to 0.12.17
@@ -152,2 +152,3 @@ import { tx, lookup, TransactionChunk } from "@instantdb/core"; | ||
auth: Auth; | ||
storage: Storage; | ||
impersonationOpts?: ImpersonationOpts; | ||
@@ -350,3 +351,61 @@ constructor(_config: Config); | ||
} | ||
type UploadMetadata = { | ||
contentType?: string; | ||
} & Record<string, any>; | ||
type StorageFile = { | ||
key: string; | ||
name: string; | ||
size: number; | ||
etag: string; | ||
last_modified: number; | ||
}; | ||
/** | ||
* Functions to manage file storage. | ||
*/ | ||
declare class Storage { | ||
config: FilledConfig; | ||
constructor(config: FilledConfig); | ||
/** | ||
* Uploads file at the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const buffer = fs.readFileSync('demo.png'); | ||
* const isSuccess = await db.storage.upload('photos/demo.png', buffer); | ||
*/ | ||
upload: (pathname: string, file: Buffer, metadata?: UploadMetadata) => Promise<boolean>; | ||
/** | ||
* Retrieves a download URL for the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const url = await db.storage.getDownloadUrl('photos/demo.png'); | ||
*/ | ||
getDownloadUrl: (pathname: string) => Promise<string>; | ||
/** | ||
* Retrieves a list of all the files that have been uploaded by this app. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const files = await db.storage.list(); | ||
*/ | ||
list: () => Promise<StorageFile[]>; | ||
/** | ||
* Deletes a file by its path name (e.g. "photos/demo.png"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.delete("photos/demo.png"); | ||
*/ | ||
delete: (pathname: string) => Promise<void>; | ||
/** | ||
* Deletes multiple files by their path names (e.g. "photos/demo.png", "essays/demo.txt"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]); | ||
*/ | ||
deleteMany: (pathnames: string[]) => Promise<void>; | ||
} | ||
export { init, id, tx, lookup, Config, ImpersonationOpts, TransactionChunk, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -244,2 +244,3 @@ "use strict"; | ||
this.auth = new Auth(this.config); | ||
this.storage = new Storage(this.config); | ||
} | ||
@@ -372,2 +373,91 @@ } | ||
} | ||
/** | ||
* Functions to manage file storage. | ||
*/ | ||
class Storage { | ||
constructor(config) { | ||
/** | ||
* Uploads file at the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const buffer = fs.readFileSync('demo.png'); | ||
* const isSuccess = await db.storage.upload('photos/demo.png', buffer); | ||
*/ | ||
this.upload = (pathname_1, file_1, ...args_1) => __awaiter(this, [pathname_1, file_1, ...args_1], void 0, function* (pathname, file, metadata = {}) { | ||
const { data: presignedUrl } = yield jsonFetch(`${this.config.apiURI}/admin/storage/signed-upload-url`, { | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ | ||
app_id: this.config.appId, | ||
filename: pathname, | ||
}), | ||
}); | ||
const { ok } = yield fetch(presignedUrl, { | ||
method: "PUT", | ||
body: file, | ||
headers: { | ||
"Content-Type": metadata.contentType || "application/octet-stream", | ||
}, | ||
}); | ||
return ok; | ||
}); | ||
/** | ||
* Retrieves a download URL for the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const url = await db.storage.getDownloadUrl('photos/demo.png'); | ||
*/ | ||
this.getDownloadUrl = (pathname) => __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield jsonFetch(`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(pathname)}`, { | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
return data; | ||
}); | ||
/** | ||
* Retrieves a list of all the files that have been uploaded by this app. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const files = await db.storage.list(); | ||
*/ | ||
this.list = () => __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield jsonFetch(`${this.config.apiURI}/admin/storage/files`, { | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
return data; | ||
}); | ||
/** | ||
* Deletes a file by its path name (e.g. "photos/demo.png"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.delete("photos/demo.png"); | ||
*/ | ||
this.delete = (pathname) => __awaiter(this, void 0, void 0, function* () { | ||
yield jsonFetch(`${this.config.apiURI}/admin/storage/files?filename=${encodeURIComponent(pathname)}`, { | ||
method: "DELETE", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
}); | ||
/** | ||
* Deletes multiple files by their path names (e.g. "photos/demo.png", "essays/demo.txt"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]); | ||
*/ | ||
this.deleteMany = (pathnames) => __awaiter(this, void 0, void 0, function* () { | ||
yield jsonFetch(`${this.config.apiURI}/admin/storage/files/delete`, { | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ filenames: pathnames }), | ||
}); | ||
}); | ||
this.config = config; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -152,2 +152,3 @@ import { tx, lookup, TransactionChunk } from "@instantdb/core"; | ||
auth: Auth; | ||
storage: Storage; | ||
impersonationOpts?: ImpersonationOpts; | ||
@@ -350,3 +351,61 @@ constructor(_config: Config); | ||
} | ||
type UploadMetadata = { | ||
contentType?: string; | ||
} & Record<string, any>; | ||
type StorageFile = { | ||
key: string; | ||
name: string; | ||
size: number; | ||
etag: string; | ||
last_modified: number; | ||
}; | ||
/** | ||
* Functions to manage file storage. | ||
*/ | ||
declare class Storage { | ||
config: FilledConfig; | ||
constructor(config: FilledConfig); | ||
/** | ||
* Uploads file at the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const buffer = fs.readFileSync('demo.png'); | ||
* const isSuccess = await db.storage.upload('photos/demo.png', buffer); | ||
*/ | ||
upload: (pathname: string, file: Buffer, metadata?: UploadMetadata) => Promise<boolean>; | ||
/** | ||
* Retrieves a download URL for the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const url = await db.storage.getDownloadUrl('photos/demo.png'); | ||
*/ | ||
getDownloadUrl: (pathname: string) => Promise<string>; | ||
/** | ||
* Retrieves a list of all the files that have been uploaded by this app. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const files = await db.storage.list(); | ||
*/ | ||
list: () => Promise<StorageFile[]>; | ||
/** | ||
* Deletes a file by its path name (e.g. "photos/demo.png"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.delete("photos/demo.png"); | ||
*/ | ||
delete: (pathname: string) => Promise<void>; | ||
/** | ||
* Deletes multiple files by their path names (e.g. "photos/demo.png", "essays/demo.txt"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]); | ||
*/ | ||
deleteMany: (pathnames: string[]) => Promise<void>; | ||
} | ||
export { init, id, tx, lookup, Config, ImpersonationOpts, TransactionChunk, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -237,2 +237,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
this.auth = new Auth(this.config); | ||
this.storage = new Storage(this.config); | ||
} | ||
@@ -365,3 +366,92 @@ } | ||
} | ||
/** | ||
* Functions to manage file storage. | ||
*/ | ||
class Storage { | ||
constructor(config) { | ||
/** | ||
* Uploads file at the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const buffer = fs.readFileSync('demo.png'); | ||
* const isSuccess = await db.storage.upload('photos/demo.png', buffer); | ||
*/ | ||
this.upload = (pathname_1, file_1, ...args_1) => __awaiter(this, [pathname_1, file_1, ...args_1], void 0, function* (pathname, file, metadata = {}) { | ||
const { data: presignedUrl } = yield jsonFetch(`${this.config.apiURI}/admin/storage/signed-upload-url`, { | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ | ||
app_id: this.config.appId, | ||
filename: pathname, | ||
}), | ||
}); | ||
const { ok } = yield fetch(presignedUrl, { | ||
method: "PUT", | ||
body: file, | ||
headers: { | ||
"Content-Type": metadata.contentType || "application/octet-stream", | ||
}, | ||
}); | ||
return ok; | ||
}); | ||
/** | ||
* Retrieves a download URL for the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const url = await db.storage.getDownloadUrl('photos/demo.png'); | ||
*/ | ||
this.getDownloadUrl = (pathname) => __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield jsonFetch(`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(pathname)}`, { | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
return data; | ||
}); | ||
/** | ||
* Retrieves a list of all the files that have been uploaded by this app. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const files = await db.storage.list(); | ||
*/ | ||
this.list = () => __awaiter(this, void 0, void 0, function* () { | ||
const { data } = yield jsonFetch(`${this.config.apiURI}/admin/storage/files`, { | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
return data; | ||
}); | ||
/** | ||
* Deletes a file by its path name (e.g. "photos/demo.png"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.delete("photos/demo.png"); | ||
*/ | ||
this.delete = (pathname) => __awaiter(this, void 0, void 0, function* () { | ||
yield jsonFetch(`${this.config.apiURI}/admin/storage/files?filename=${encodeURIComponent(pathname)}`, { | ||
method: "DELETE", | ||
headers: authorizedHeaders(this.config), | ||
}); | ||
}); | ||
/** | ||
* Deletes multiple files by their path names (e.g. "photos/demo.png", "essays/demo.txt"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]); | ||
*/ | ||
this.deleteMany = (pathnames) => __awaiter(this, void 0, void 0, function* () { | ||
yield jsonFetch(`${this.config.apiURI}/admin/storage/files/delete`, { | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ filenames: pathnames }), | ||
}); | ||
}); | ||
this.config = config; | ||
} | ||
} | ||
export { init, id, tx, lookup, }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@instantdb/admin", | ||
"version": "v0.12.16", | ||
"version": "v0.12.17", | ||
"description": "Admin SDK for Instant DB", | ||
@@ -27,4 +27,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@instantdb/core": "v0.12.16" | ||
"@instantdb/core": "v0.12.17" | ||
} | ||
} |
127
src/index.ts
@@ -250,2 +250,3 @@ import { tx, lookup, TransactionChunk, getOps } from "@instantdb/core"; | ||
auth: Auth; | ||
storage: Storage; | ||
impersonationOpts?: ImpersonationOpts; | ||
@@ -256,2 +257,3 @@ | ||
this.auth = new Auth(this.config); | ||
this.storage = new Storage(this.config); | ||
} | ||
@@ -561,2 +563,127 @@ | ||
type UploadMetadata = { contentType?: string } & Record<string, any>; | ||
type StorageFile = { | ||
key: string; | ||
name: string; | ||
size: number; | ||
etag: string; | ||
last_modified: number; | ||
}; | ||
/** | ||
* Functions to manage file storage. | ||
*/ | ||
class Storage { | ||
config: FilledConfig; | ||
constructor(config: FilledConfig) { | ||
this.config = config; | ||
} | ||
/** | ||
* Uploads file at the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const buffer = fs.readFileSync('demo.png'); | ||
* const isSuccess = await db.storage.upload('photos/demo.png', buffer); | ||
*/ | ||
upload = async ( | ||
pathname: string, | ||
file: Buffer, | ||
metadata: UploadMetadata = {}, | ||
): Promise<boolean> => { | ||
const { data: presignedUrl } = await jsonFetch( | ||
`${this.config.apiURI}/admin/storage/signed-upload-url`, | ||
{ | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ | ||
app_id: this.config.appId, | ||
filename: pathname, | ||
}), | ||
}, | ||
); | ||
const { ok } = await fetch(presignedUrl, { | ||
method: "PUT", | ||
body: file, | ||
headers: { | ||
"Content-Type": metadata.contentType || "application/octet-stream", | ||
}, | ||
}); | ||
return ok; | ||
}; | ||
/** | ||
* Retrieves a download URL for the provided path. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const url = await db.storage.getDownloadUrl('photos/demo.png'); | ||
*/ | ||
getDownloadUrl = async (pathname: string): Promise<string> => { | ||
const { data } = await jsonFetch( | ||
`${this.config.apiURI}/admin/storage/signed-download-url?app_id=${this.config.appId}&filename=${encodeURIComponent(pathname)}`, | ||
{ | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}, | ||
); | ||
return data; | ||
}; | ||
/** | ||
* Retrieves a list of all the files that have been uploaded by this app. | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* const files = await db.storage.list(); | ||
*/ | ||
list = async (): Promise<StorageFile[]> => { | ||
const { data } = await jsonFetch( | ||
`${this.config.apiURI}/admin/storage/files`, | ||
{ | ||
method: "GET", | ||
headers: authorizedHeaders(this.config), | ||
}, | ||
); | ||
return data; | ||
}; | ||
/** | ||
* Deletes a file by its path name (e.g. "photos/demo.png"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.delete("photos/demo.png"); | ||
*/ | ||
delete = async (pathname: string): Promise<void> => { | ||
await jsonFetch( | ||
`${this.config.apiURI}/admin/storage/files?filename=${encodeURIComponent(pathname)}`, | ||
{ | ||
method: "DELETE", | ||
headers: authorizedHeaders(this.config), | ||
}, | ||
); | ||
}; | ||
/** | ||
* Deletes multiple files by their path names (e.g. "photos/demo.png", "essays/demo.txt"). | ||
* | ||
* @see https://instantdb.com/docs/storage | ||
* @example | ||
* await db.storage.deleteMany(["images/1.png", "images/2.png", "images/3.png"]); | ||
*/ | ||
deleteMany = async (pathnames: string[]): Promise<void> => { | ||
await jsonFetch(`${this.config.apiURI}/admin/storage/files/delete`, { | ||
method: "POST", | ||
headers: authorizedHeaders(this.config), | ||
body: JSON.stringify({ filenames: pathnames }), | ||
}); | ||
}; | ||
} | ||
export { | ||
@@ -563,0 +690,0 @@ init, |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
111321
2389
5
Updated@instantdb/core@v0.12.17