@karakeep/cli 0.30.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +89 -21
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -786,6 +786,9 @@ function createChain(opts) {
|
|
|
786
786
|
function isObject(value) {
|
|
787
787
|
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
788
788
|
}
|
|
789
|
+
function emptyObject() {
|
|
790
|
+
return /* @__PURE__ */ Object.create(null);
|
|
791
|
+
}
|
|
789
792
|
var __create = Object.create;
|
|
790
793
|
var __defProp = Object.defineProperty;
|
|
791
794
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -843,7 +846,7 @@ function createInnerProxy(callback, path2, memo) {
|
|
|
843
846
|
}));
|
|
844
847
|
return memo[cacheKey];
|
|
845
848
|
}
|
|
846
|
-
const createRecursiveProxy = (callback) => createInnerProxy(callback, [],
|
|
849
|
+
const createRecursiveProxy = (callback) => createInnerProxy(callback, [], emptyObject());
|
|
847
850
|
const createFlatProxy = (callback) => {
|
|
848
851
|
return new Proxy(noop, { get(_obj, name) {
|
|
849
852
|
if (name === "then") return void 0;
|
|
@@ -1093,15 +1096,15 @@ async function fetchHTTPResponse(opts) {
|
|
|
1093
1096
|
throwIfAborted(opts.signal);
|
|
1094
1097
|
const url = opts.getUrl(opts);
|
|
1095
1098
|
const body = opts.getBody(opts);
|
|
1096
|
-
const
|
|
1099
|
+
const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[opts.type];
|
|
1097
1100
|
const resolvedHeaders = await (async () => {
|
|
1098
1101
|
const heads = await opts.headers();
|
|
1099
1102
|
if (Symbol.iterator in heads) return Object.fromEntries(heads);
|
|
1100
1103
|
return heads;
|
|
1101
1104
|
})();
|
|
1102
|
-
const headers = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts.contentTypeHeader ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0), resolvedHeaders);
|
|
1105
|
+
const headers = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0), resolvedHeaders);
|
|
1103
1106
|
return getFetch(opts.fetch)(url, {
|
|
1104
|
-
method
|
|
1107
|
+
method,
|
|
1105
1108
|
signal: opts.signal,
|
|
1106
1109
|
body,
|
|
1107
1110
|
headers
|
|
@@ -1420,6 +1423,7 @@ var WsConnection = class WsConnection2 {
|
|
|
1420
1423
|
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
1421
1424
|
_this.openPromise = wsPromise.then(async (ws) => {
|
|
1422
1425
|
_this.ws = ws;
|
|
1426
|
+
ws.binaryType = "arraybuffer";
|
|
1423
1427
|
ws.addEventListener("message", function({ data }) {
|
|
1424
1428
|
if (data === "PING") this.send("PONG");
|
|
1425
1429
|
});
|
|
@@ -11369,15 +11373,23 @@ async function addToList(listId, bookmarkId) {
|
|
|
11369
11373
|
)
|
|
11370
11374
|
);
|
|
11371
11375
|
}
|
|
11372
|
-
listsCmd.command("get").description("gets all the ids of the bookmarks assigned to the list").requiredOption("--list <id>", "the id of the list").
|
|
11376
|
+
listsCmd.command("get").description("gets all the ids of the bookmarks assigned to the list").requiredOption("--list <id>", "the id of the list").option(
|
|
11377
|
+
"--include-content",
|
|
11378
|
+
"include full bookmark content in results",
|
|
11379
|
+
false
|
|
11380
|
+
).action(async (opts) => {
|
|
11373
11381
|
const api2 = getAPIClient();
|
|
11374
11382
|
try {
|
|
11375
|
-
let resp = await api2.bookmarks.getBookmarks.query({
|
|
11383
|
+
let resp = await api2.bookmarks.getBookmarks.query({
|
|
11384
|
+
listId: opts.list,
|
|
11385
|
+
includeContent: opts.includeContent
|
|
11386
|
+
});
|
|
11376
11387
|
let results = resp.bookmarks.map((b) => b.id);
|
|
11377
11388
|
while (resp.nextCursor) {
|
|
11378
11389
|
resp = await api2.bookmarks.getBookmarks.query({
|
|
11379
11390
|
listId: opts.list,
|
|
11380
|
-
cursor: resp.nextCursor
|
|
11391
|
+
cursor: resp.nextCursor,
|
|
11392
|
+
includeContent: opts.includeContent
|
|
11381
11393
|
});
|
|
11382
11394
|
results = [...results, ...resp.bookmarks.map((b) => b.id)];
|
|
11383
11395
|
}
|
|
@@ -15502,6 +15514,7 @@ const zTagCursorSchema = z.object({
|
|
|
15502
15514
|
});
|
|
15503
15515
|
const zTagListRequestSchema = z.object({
|
|
15504
15516
|
nameContains: z.string().optional(),
|
|
15517
|
+
ids: z.array(z.string()).optional(),
|
|
15505
15518
|
attachedBy: z.enum([...zAttachedByEnumSchema.options, "none"]).optional(),
|
|
15506
15519
|
sortBy: z.enum(["name", "usage", "relevance"]).optional().default("usage"),
|
|
15507
15520
|
cursor: zTagCursorSchema.nullish().default({ page: 0 }),
|
|
@@ -15684,6 +15697,7 @@ z.object({
|
|
|
15684
15697
|
// A mechanism to prioritize crawling of bookmarks depending on whether
|
|
15685
15698
|
// they were created by a user interaction or by a bulk import.
|
|
15686
15699
|
crawlPriority: z.enum(["low", "normal"]).optional(),
|
|
15700
|
+
// Deprecated
|
|
15687
15701
|
importSessionId: z.string().optional(),
|
|
15688
15702
|
source: zBookmarkSourceSchema.optional()
|
|
15689
15703
|
}).and(
|
|
@@ -15761,7 +15775,8 @@ z.object({
|
|
|
15761
15775
|
// At least one of the two must be set
|
|
15762
15776
|
tagId: z.string().optional(),
|
|
15763
15777
|
// If the tag already exists and we know its id we should pass it
|
|
15764
|
-
tagName: z.string().optional()
|
|
15778
|
+
tagName: z.string().optional(),
|
|
15779
|
+
attachedBy: zAttachedByEnumSchema.optional().default("human")
|
|
15765
15780
|
}).refine((val) => !!val.tagId || !!val.tagName, {
|
|
15766
15781
|
message: "You must provide either a tagId or a tagName",
|
|
15767
15782
|
path: ["tagId", "tagName"]
|
|
@@ -15822,16 +15837,10 @@ function collect(val, acc) {
|
|
|
15822
15837
|
return acc;
|
|
15823
15838
|
}
|
|
15824
15839
|
function normalizeBookmark(bookmark) {
|
|
15825
|
-
|
|
15840
|
+
return {
|
|
15826
15841
|
...bookmark,
|
|
15827
15842
|
tags: bookmark.tags.map((t) => t.name)
|
|
15828
15843
|
};
|
|
15829
|
-
if (ret.content.type == BookmarkTypes.LINK && ret.content.htmlContent) {
|
|
15830
|
-
if (ret.content.htmlContent.length > 10) {
|
|
15831
|
-
ret.content.htmlContent = ret.content.htmlContent.substring(0, 10) + "... <CROPPED>";
|
|
15832
|
-
}
|
|
15833
|
-
}
|
|
15834
|
-
return ret;
|
|
15835
15844
|
}
|
|
15836
15845
|
function printBookmark(bookmark) {
|
|
15837
15846
|
printObject(normalizeBookmark(bookmark));
|
|
@@ -15912,9 +15921,13 @@ bookmarkCmd.command("add").description("creates a new bookmark").option(
|
|
|
15912
15921
|
])
|
|
15913
15922
|
);
|
|
15914
15923
|
});
|
|
15915
|
-
bookmarkCmd.command("get").description("fetch information about a bookmark").argument("<id>", "The id of the bookmark to get").
|
|
15924
|
+
bookmarkCmd.command("get").description("fetch information about a bookmark").argument("<id>", "The id of the bookmark to get").option(
|
|
15925
|
+
"--include-content",
|
|
15926
|
+
"include full bookmark content in results",
|
|
15927
|
+
false
|
|
15928
|
+
).action(async (id, opts) => {
|
|
15916
15929
|
const api2 = getAPIClient();
|
|
15917
|
-
await api2.bookmarks.getBookmark.query({ bookmarkId: id }).then(printBookmark).catch(printError(`Failed to get the bookmark with id "${id}"`));
|
|
15930
|
+
await api2.bookmarks.getBookmark.query({ bookmarkId: id, includeContent: opts.includeContent }).then(printBookmark).catch(printError(`Failed to get the bookmark with id "${id}"`));
|
|
15918
15931
|
});
|
|
15919
15932
|
function printTagMessage(tags, bookmarkId, action) {
|
|
15920
15933
|
tags.forEach((tag) => {
|
|
@@ -15974,13 +15987,18 @@ bookmarkCmd.command("list").description("list all bookmarks").option(
|
|
|
15974
15987
|
"--include-archived",
|
|
15975
15988
|
"If set, archived bookmarks will be fetched as well",
|
|
15976
15989
|
false
|
|
15977
|
-
).option("--list-id <id>", "if set, only items from that list will be fetched").
|
|
15990
|
+
).option("--list-id <id>", "if set, only items from that list will be fetched").option(
|
|
15991
|
+
"--include-content",
|
|
15992
|
+
"include full bookmark content in results",
|
|
15993
|
+
false
|
|
15994
|
+
).action(async (opts) => {
|
|
15978
15995
|
const api2 = getAPIClient();
|
|
15979
15996
|
const request = {
|
|
15980
15997
|
archived: opts.includeArchived ? void 0 : false,
|
|
15981
15998
|
listId: opts.listId,
|
|
15982
15999
|
limit: MAX_NUM_BOOKMARKS_PER_PAGE,
|
|
15983
|
-
useCursorV2: true
|
|
16000
|
+
useCursorV2: true,
|
|
16001
|
+
includeContent: opts.includeContent
|
|
15984
16002
|
};
|
|
15985
16003
|
try {
|
|
15986
16004
|
let resp = await api2.bookmarks.getBookmarks.query(request);
|
|
@@ -15997,6 +16015,56 @@ bookmarkCmd.command("list").description("list all bookmarks").option(
|
|
|
15997
16015
|
printStatusMessage(false, "Failed to query bookmarks");
|
|
15998
16016
|
}
|
|
15999
16017
|
});
|
|
16018
|
+
bookmarkCmd.command("search").description("search bookmarks using query matchers").argument(
|
|
16019
|
+
"<query>",
|
|
16020
|
+
"the search query (supports matchers like tag:name, is:fav, etc.)"
|
|
16021
|
+
).option(
|
|
16022
|
+
"--limit <limit>",
|
|
16023
|
+
"number of results per page",
|
|
16024
|
+
(val) => parseInt(val, 10),
|
|
16025
|
+
50
|
|
16026
|
+
).option(
|
|
16027
|
+
"--sort-order <order>",
|
|
16028
|
+
"sort order for results",
|
|
16029
|
+
(val) => {
|
|
16030
|
+
if (val !== "relevance" && val !== "asc" && val !== "desc") {
|
|
16031
|
+
throw new Error("sort-order must be one of: relevance, asc, desc");
|
|
16032
|
+
}
|
|
16033
|
+
return val;
|
|
16034
|
+
},
|
|
16035
|
+
"relevance"
|
|
16036
|
+
).option(
|
|
16037
|
+
"--include-content",
|
|
16038
|
+
"include full bookmark content in results",
|
|
16039
|
+
false
|
|
16040
|
+
).option("--all", "fetch all results (paginate through all pages)", false).action(async (query, opts) => {
|
|
16041
|
+
const api2 = getAPIClient();
|
|
16042
|
+
const request = {
|
|
16043
|
+
text: query,
|
|
16044
|
+
limit: opts.limit,
|
|
16045
|
+
sortOrder: opts.sortOrder,
|
|
16046
|
+
includeContent: opts.includeContent
|
|
16047
|
+
};
|
|
16048
|
+
try {
|
|
16049
|
+
let resp = await api2.bookmarks.searchBookmarks.query(request);
|
|
16050
|
+
let results = resp.bookmarks;
|
|
16051
|
+
if (opts.all) {
|
|
16052
|
+
while (resp.nextCursor) {
|
|
16053
|
+
resp = await api2.bookmarks.searchBookmarks.query({
|
|
16054
|
+
...request,
|
|
16055
|
+
cursor: resp.nextCursor
|
|
16056
|
+
});
|
|
16057
|
+
results = [...results, ...resp.bookmarks];
|
|
16058
|
+
}
|
|
16059
|
+
}
|
|
16060
|
+
printObject(results.map(normalizeBookmark), { maxArrayLength: null });
|
|
16061
|
+
} catch (error2) {
|
|
16062
|
+
printStatusMessage(false, "Failed to search bookmarks");
|
|
16063
|
+
if (error2 instanceof Error) {
|
|
16064
|
+
printStatusMessage(false, error2.message);
|
|
16065
|
+
}
|
|
16066
|
+
}
|
|
16067
|
+
});
|
|
16000
16068
|
bookmarkCmd.command("delete").description("delete a bookmark").argument("<id>", "the id of the bookmark to delete").action(async (id) => {
|
|
16001
16069
|
const api2 = getAPIClient();
|
|
16002
16070
|
await api2.bookmarks.deleteBookmark.mutate({ bookmarkId: id }).then(printSuccess(`Bookmark with id '${id}' got deleted`)).catch(printError(`Failed to delete bookmark with id "${id}"`));
|
|
@@ -17306,7 +17374,7 @@ async function wipeTags(api2) {
|
|
|
17306
17374
|
throw error2;
|
|
17307
17375
|
}
|
|
17308
17376
|
}
|
|
17309
|
-
const __vite_import_meta_env__ = { "BASE_URL": "/", "CLI_VERSION": "0.
|
|
17377
|
+
const __vite_import_meta_env__ = { "BASE_URL": "/", "CLI_VERSION": "0.31.0", "DEV": false, "MODE": "production", "PROD": true, "SSR": true };
|
|
17310
17378
|
const program = new Command().name("karakeep").description("A CLI interface to interact with the karakeep api").addOption(
|
|
17311
17379
|
new Option("--api-key <key>", "the API key to interact with the API").makeOptionMandatory(true).env("KARAKEEP_API_KEY")
|
|
17312
17380
|
).addOption(
|
|
@@ -17315,7 +17383,7 @@ const program = new Command().name("karakeep").description("A CLI interface to i
|
|
|
17315
17383
|
"the address of the server to connect to"
|
|
17316
17384
|
).makeOptionMandatory(true).env("KARAKEEP_SERVER_ADDR")
|
|
17317
17385
|
).addOption(new Option("--json", "to output the result as JSON")).version(
|
|
17318
|
-
__vite_import_meta_env__ && "CLI_VERSION" in __vite_import_meta_env__ ? "0.
|
|
17386
|
+
__vite_import_meta_env__ && "CLI_VERSION" in __vite_import_meta_env__ ? "0.31.0" : "0.0.0"
|
|
17319
17387
|
);
|
|
17320
17388
|
program.addCommand(adminCmd);
|
|
17321
17389
|
program.addCommand(bookmarkCmd);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@karakeep/cli",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.31.0",
|
|
5
5
|
"description": "Command Line Interface (CLI) for Karakeep",
|
|
6
6
|
"license": "GNU Affero General Public License version 3",
|
|
7
7
|
"type": "module",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@karakeep/shared": "^0.1.0",
|
|
21
21
|
"@karakeep/trpc": "^0.1.0",
|
|
22
22
|
"@karakeep/tsconfig": "^0.1.0",
|
|
23
|
-
"@trpc/client": "^11.
|
|
24
|
-
"@trpc/server": "^11.
|
|
23
|
+
"@trpc/client": "^11.9.0",
|
|
24
|
+
"@trpc/server": "^11.9.0",
|
|
25
25
|
"@tsconfig/node22": "^22.0.0",
|
|
26
26
|
"chalk": "^5.3.0",
|
|
27
27
|
"commander": "^12.0.0",
|