@karakeep/cli 0.29.1 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +95 -22
  2. 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, [], /* @__PURE__ */ Object.create(null));
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 { type } = opts;
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: (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[type],
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").action(async (opts) => {
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({ listId: opts.list });
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 }),
@@ -15552,6 +15565,7 @@ const zSortOrder = z.enum(["asc", "desc", "relevance"]);
15552
15565
  const zAssetTypesSchema = z.enum([
15553
15566
  "linkHtmlContent",
15554
15567
  "screenshot",
15568
+ "pdf",
15555
15569
  "assetScreenshot",
15556
15570
  "bannerImage",
15557
15571
  "fullPageArchive",
@@ -15559,6 +15573,7 @@ const zAssetTypesSchema = z.enum([
15559
15573
  "bookmarkAsset",
15560
15574
  "precrawledArchive",
15561
15575
  "userUploaded",
15576
+ "avatar",
15562
15577
  "unknown"
15563
15578
  ]);
15564
15579
  const zAssetSchema = z.object({
@@ -15577,6 +15592,7 @@ const zBookmarkedLinkSchema = z.object({
15577
15592
  imageUrl: z.string().nullish(),
15578
15593
  imageAssetId: z.string().nullish(),
15579
15594
  screenshotAssetId: z.string().nullish(),
15595
+ pdfAssetId: z.string().nullish(),
15580
15596
  fullPageArchiveAssetId: z.string().nullish(),
15581
15597
  precrawledArchiveAssetId: z.string().nullish(),
15582
15598
  videoAssetId: z.string().nullish(),
@@ -15584,6 +15600,7 @@ const zBookmarkedLinkSchema = z.object({
15584
15600
  htmlContent: z.string().nullish(),
15585
15601
  contentAssetId: z.string().nullish(),
15586
15602
  crawledAt: z.date().nullish(),
15603
+ crawlStatus: z.enum(["success", "failure", "pending"]).nullish(),
15587
15604
  author: z.string().nullish(),
15588
15605
  publisher: z.string().nullish(),
15589
15606
  datePublished: z.date().nullish(),
@@ -15680,6 +15697,7 @@ z.object({
15680
15697
  // A mechanism to prioritize crawling of bookmarks depending on whether
15681
15698
  // they were created by a user interaction or by a bulk import.
15682
15699
  crawlPriority: z.enum(["low", "normal"]).optional(),
15700
+ // Deprecated
15683
15701
  importSessionId: z.string().optional(),
15684
15702
  source: zBookmarkSourceSchema.optional()
15685
15703
  }).and(
@@ -15757,7 +15775,8 @@ z.object({
15757
15775
  // At least one of the two must be set
15758
15776
  tagId: z.string().optional(),
15759
15777
  // If the tag already exists and we know its id we should pass it
15760
- tagName: z.string().optional()
15778
+ tagName: z.string().optional(),
15779
+ attachedBy: zAttachedByEnumSchema.optional().default("human")
15761
15780
  }).refine((val) => !!val.tagId || !!val.tagName, {
15762
15781
  message: "You must provide either a tagId or a tagName",
15763
15782
  path: ["tagId", "tagName"]
@@ -15818,16 +15837,10 @@ function collect(val, acc) {
15818
15837
  return acc;
15819
15838
  }
15820
15839
  function normalizeBookmark(bookmark) {
15821
- const ret = {
15840
+ return {
15822
15841
  ...bookmark,
15823
15842
  tags: bookmark.tags.map((t) => t.name)
15824
15843
  };
15825
- if (ret.content.type == BookmarkTypes.LINK && ret.content.htmlContent) {
15826
- if (ret.content.htmlContent.length > 10) {
15827
- ret.content.htmlContent = ret.content.htmlContent.substring(0, 10) + "... <CROPPED>";
15828
- }
15829
- }
15830
- return ret;
15831
15844
  }
15832
15845
  function printBookmark(bookmark) {
15833
15846
  printObject(normalizeBookmark(bookmark));
@@ -15908,9 +15921,13 @@ bookmarkCmd.command("add").description("creates a new bookmark").option(
15908
15921
  ])
15909
15922
  );
15910
15923
  });
15911
- bookmarkCmd.command("get").description("fetch information about a bookmark").argument("<id>", "The id of the bookmark to get").action(async (id) => {
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) => {
15912
15929
  const api2 = getAPIClient();
15913
- 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}"`));
15914
15931
  });
15915
15932
  function printTagMessage(tags, bookmarkId, action) {
15916
15933
  tags.forEach((tag) => {
@@ -15970,13 +15987,18 @@ bookmarkCmd.command("list").description("list all bookmarks").option(
15970
15987
  "--include-archived",
15971
15988
  "If set, archived bookmarks will be fetched as well",
15972
15989
  false
15973
- ).option("--list-id <id>", "if set, only items from that list will be fetched").action(async (opts) => {
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) => {
15974
15995
  const api2 = getAPIClient();
15975
15996
  const request = {
15976
15997
  archived: opts.includeArchived ? void 0 : false,
15977
15998
  listId: opts.listId,
15978
15999
  limit: MAX_NUM_BOOKMARKS_PER_PAGE,
15979
- useCursorV2: true
16000
+ useCursorV2: true,
16001
+ includeContent: opts.includeContent
15980
16002
  };
15981
16003
  try {
15982
16004
  let resp = await api2.bookmarks.getBookmarks.query(request);
@@ -15993,6 +16015,56 @@ bookmarkCmd.command("list").description("list all bookmarks").option(
15993
16015
  printStatusMessage(false, "Failed to query bookmarks");
15994
16016
  }
15995
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
+ });
15996
16068
  bookmarkCmd.command("delete").description("delete a bookmark").argument("<id>", "the id of the bookmark to delete").action(async (id) => {
15997
16069
  const api2 = getAPIClient();
15998
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}"`));
@@ -16836,7 +16908,8 @@ async function migrateBookmarks(src2, dest, opts) {
16836
16908
  note: b.note ?? void 0,
16837
16909
  summary: b.summary ?? void 0,
16838
16910
  createdAt: b.createdAt,
16839
- crawlPriority: "low"
16911
+ crawlPriority: "low",
16912
+ source: b.source === null ? void 0 : b.source
16840
16913
  };
16841
16914
  let createdId = null;
16842
16915
  switch (b.content.type) {
@@ -17301,7 +17374,7 @@ async function wipeTags(api2) {
17301
17374
  throw error2;
17302
17375
  }
17303
17376
  }
17304
- const __vite_import_meta_env__ = { "BASE_URL": "/", "CLI_VERSION": "0.29.1", "DEV": false, "MODE": "production", "PROD": true, "SSR": true };
17377
+ const __vite_import_meta_env__ = { "BASE_URL": "/", "CLI_VERSION": "0.31.0", "DEV": false, "MODE": "production", "PROD": true, "SSR": true };
17305
17378
  const program = new Command().name("karakeep").description("A CLI interface to interact with the karakeep api").addOption(
17306
17379
  new Option("--api-key <key>", "the API key to interact with the API").makeOptionMandatory(true).env("KARAKEEP_API_KEY")
17307
17380
  ).addOption(
@@ -17310,7 +17383,7 @@ const program = new Command().name("karakeep").description("A CLI interface to i
17310
17383
  "the address of the server to connect to"
17311
17384
  ).makeOptionMandatory(true).env("KARAKEEP_SERVER_ADDR")
17312
17385
  ).addOption(new Option("--json", "to output the result as JSON")).version(
17313
- __vite_import_meta_env__ && "CLI_VERSION" in __vite_import_meta_env__ ? "0.29.1" : "0.0.0"
17386
+ __vite_import_meta_env__ && "CLI_VERSION" in __vite_import_meta_env__ ? "0.31.0" : "0.0.0"
17314
17387
  );
17315
17388
  program.addCommand(adminCmd);
17316
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.29.1",
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.4.3",
24
- "@trpc/server": "^11.4.3",
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",