@sockethub/platform-carddav 1.0.0-beta.5 → 1.0.0-beta.6

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/README.md CHANGED
@@ -122,6 +122,11 @@ book and send it back as `"object": { "syncToken": "..." }` to receive only
122
122
  what changed since then. When `truncated` is `true`, store the new token and
123
123
  sync again until it is `false`.
124
124
 
125
+ Send `"object": { "tokenOnly": true }` to get the address book's current
126
+ `syncToken` with empty `items` and `removed`, without listing every contact.
127
+ Read it before loading the contacts you need, then sync with it later. A
128
+ server that exposes no token returns `carddav:sync-unsupported`.
129
+
125
130
  On `carddav:sync-token-invalid`, drop the stored token and sync again without
126
131
  one. On `carddav:sync-unsupported`, the server does not offer WebDAV Sync; fall
127
132
  back to `query`. Other sync errors are `carddav:sync-failed`. A server that
package/dist/index.d.ts CHANGED
@@ -21,6 +21,10 @@ export default class CardDav implements PlatformInterface {
21
21
  * the result being complete. `carddav:sync-token-invalid` means start
22
22
  * over without a token; `carddav:sync-unsupported` means fall back to
23
23
  * `query`.
24
+ *
25
+ * With `object.tokenOnly: true`, returns the address book's current
26
+ * token and no contacts, so a client can start tracking changes
27
+ * without downloading every contact first.
24
28
  */
25
29
  sync(job: ActivityStream, credentials: CardDavCredentials, done: PlatformCallback): void;
26
30
  create(job: ActivityStream, credentials: CardDavCredentials, done: PlatformCallback): void;
package/dist/index.js CHANGED
@@ -42989,6 +42989,35 @@ class DavClient {
42989
42989
  }
42990
42990
  return this.readMultistatus(response);
42991
42991
  }
42992
+ async currentSyncToken(collection) {
42993
+ const response = await this.request(collection, {
42994
+ method: "PROPFIND",
42995
+ headers: {
42996
+ depth: "0",
42997
+ "content-type": "application/xml; charset=utf-8"
42998
+ },
42999
+ body: `<?xml version="1.0" encoding="utf-8"?>
43000
+ <d:propfind xmlns:d="DAV:"><d:prop><d:sync-token/></d:prop></d:propfind>`
43001
+ });
43002
+ if (response.status === 404)
43003
+ return rejectDavResponse(response, `${this.errorPrefix}:not-found`);
43004
+ if (response.status !== 207) {
43005
+ await response.body?.cancel().catch(() => {});
43006
+ throw new DavFailure(`${this.errorPrefix}:invalid-response`);
43007
+ }
43008
+ let responses;
43009
+ try {
43010
+ responses = asArray(parseDavXml(await response.text(), {
43011
+ parseTagValue: false
43012
+ }).multistatus?.response);
43013
+ } catch {
43014
+ throw new DavFailure(`${this.errorPrefix}:invalid-response`);
43015
+ }
43016
+ const token = successfulProps(responses[0] ?? {})["sync-token"];
43017
+ if (typeof token !== "string" || token.trim() === "")
43018
+ throw new DavFailure(`${this.errorPrefix}:sync-unsupported`);
43019
+ return token.trim();
43020
+ }
42992
43021
  async syncCollection(collection, prop, syncToken, namespaces = "") {
42993
43022
  const response = await this.request(collection, {
42994
43023
  method: "REPORT",
@@ -43427,7 +43456,7 @@ var ActivityStreamSchema = {
43427
43456
  var package_default = {
43428
43457
  name: "@sockethub/schemas",
43429
43458
  description: "JSON schema files for validating Sockethub Activity Streams",
43430
- version: "3.0.0-beta.5",
43459
+ version: "3.0.0-beta.6",
43431
43460
  type: "module",
43432
43461
  private: false,
43433
43462
  author: "Nick Jennings <nick@silverbucket.net>",
@@ -43497,7 +43526,7 @@ var package_default = {
43497
43526
  "ajv-formats": "^2.1.1",
43498
43527
  "ajv-formats-draft2019": "^1.6.1"
43499
43528
  },
43500
- gitHead: "cc4ffdd9714ebbd8372a88c4f2d795974e04029e",
43529
+ gitHead: "604f3da8850a19a4fd5f5e5dcec10bf283e9085e",
43501
43530
  types: "./dist/index.d.ts"
43502
43531
  };
43503
43532
 
@@ -44647,7 +44676,7 @@ class CardDavClient extends DavClient {
44647
44676
  var package_default2 = {
44648
44677
  name: "@sockethub/platform-carddav",
44649
44678
  description: "A Sockethub platform for CardDAV address books and contacts",
44650
- version: "1.0.0-beta.5",
44679
+ version: "1.0.0-beta.6",
44651
44680
  type: "module",
44652
44681
  private: false,
44653
44682
  license: "LGPL-3.0+",
@@ -44676,21 +44705,21 @@ var package_default2 = {
44676
44705
  test: "bun test src/"
44677
44706
  },
44678
44707
  dependencies: {
44679
- "@sockethub/dav": "^1.0.0-beta.5",
44680
- "@sockethub/schemas": "^3.0.0-beta.5"
44708
+ "@sockethub/dav": "^1.0.0-beta.6",
44709
+ "@sockethub/schemas": "^3.0.0-beta.6"
44681
44710
  },
44682
44711
  devDependencies: {
44683
44712
  "@types/bun": "latest"
44684
44713
  },
44685
44714
  peerDependencies: {
44686
- "@sockethub/server": "^5.0.0-beta.5"
44715
+ "@sockethub/server": "^5.0.0-beta.6"
44687
44716
  },
44688
44717
  peerDependenciesMeta: {
44689
44718
  "@sockethub/server": {
44690
44719
  optional: true
44691
44720
  }
44692
44721
  },
44693
- gitHead: "cc4ffdd9714ebbd8372a88c4f2d795974e04029e"
44722
+ gitHead: "604f3da8850a19a4fd5f5e5dcec10bf283e9085e"
44694
44723
  };
44695
44724
 
44696
44725
  // src/schema.ts
@@ -44823,7 +44852,8 @@ var syncToken = { type: "string", minLength: 1, maxLength: 4096 };
44823
44852
  var sync = {
44824
44853
  type: "object",
44825
44854
  additionalProperties: false,
44826
- properties: { syncToken }
44855
+ properties: { syncToken, tokenOnly: { const: true } },
44856
+ not: { required: ["syncToken", "tokenOnly"] }
44827
44857
  };
44828
44858
  var deletion = {
44829
44859
  type: "object",
@@ -44904,7 +44934,8 @@ var PlatformCardDavSchema = {
44904
44934
  contact2,
44905
44935
  query,
44906
44936
  deletion,
44907
- { ...sync, required: ["syncToken"] }
44937
+ { ...sync, required: ["syncToken"] },
44938
+ { ...sync, required: ["tokenOnly"] }
44908
44939
  ]
44909
44940
  }
44910
44941
  }
@@ -45080,7 +45111,12 @@ class CardDav {
45080
45111
  sync(job, credentials, done) {
45081
45112
  const client = this.client(credentials);
45082
45113
  const input = job.object ?? {};
45083
- this.book(client, credentials, job.target?.id ?? "").then((book) => client.sync(book, input.syncToken)).then((result) => done(null, {
45114
+ this.book(client, credentials, job.target?.id ?? "").then((book) => input.tokenOnly ? client.currentSyncToken(new URL(book.id)).then((syncToken) => ({
45115
+ items: [],
45116
+ removed: [],
45117
+ syncToken,
45118
+ truncated: false
45119
+ })) : client.sync(book, input.syncToken)).then((result) => done(null, {
45084
45120
  "@context": CONTEXT,
45085
45121
  ...job.id ? { id: job.id } : {},
45086
45122
  type: "collection",
@@ -45169,4 +45205,4 @@ export {
45169
45205
  parseVCard
45170
45206
  };
45171
45207
 
45172
- //# debugId=A470017A427BECB364756E2164756E21
45208
+ //# debugId=9916E0836EEA9D2664756E2164756E21