@atproto/api 0.10.2 → 0.10.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atproto/api
2
2
 
3
+ ## 0.10.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2247](https://github.com/bluesky-social/atproto/pull/2247) [`2a0ceb818`](https://github.com/bluesky-social/atproto/commit/2a0ceb8180faa17de8061d4fa6c361b57a2005ed) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Fix double sanitization bug when editing muted words.
8
+
9
+ - [#2247](https://github.com/bluesky-social/atproto/pull/2247) [`2a0ceb818`](https://github.com/bluesky-social/atproto/commit/2a0ceb8180faa17de8061d4fa6c361b57a2005ed) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - More sanitization of muted words, including newlines and leading/trailing whitespace
10
+
11
+ - [#2247](https://github.com/bluesky-social/atproto/pull/2247) [`2a0ceb818`](https://github.com/bluesky-social/atproto/commit/2a0ceb8180faa17de8061d4fa6c361b57a2005ed) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Add `sanitizeMutedWordValue` util
12
+
13
+ - [#2247](https://github.com/bluesky-social/atproto/pull/2247) [`2a0ceb818`](https://github.com/bluesky-social/atproto/commit/2a0ceb8180faa17de8061d4fa6c361b57a2005ed) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Handle hash emoji in mute words
14
+
3
15
  ## 0.10.2
4
16
 
5
17
  ### Patch Changes
@@ -85,7 +85,7 @@ export declare class BskyAgent extends AtpAgent {
85
85
  setFeedViewPrefs(feed: string, pref: Partial<BskyFeedViewPreference>): Promise<void>;
86
86
  setThreadViewPrefs(pref: Partial<BskyThreadViewPreference>): Promise<void>;
87
87
  setInterestsPref(pref: Partial<BskyInterestsPreference>): Promise<void>;
88
- upsertMutedWords(mutedWords: AppBskyActorDefs.MutedWord[]): Promise<void>;
88
+ upsertMutedWords(newMutedWords: AppBskyActorDefs.MutedWord[]): Promise<void>;
89
89
  updateMutedWord(mutedWord: AppBskyActorDefs.MutedWord): Promise<void>;
90
90
  removeMutedWord(mutedWord: AppBskyActorDefs.MutedWord): Promise<void>;
91
91
  hidePost(postUri: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { AtUri } from '@atproto/syntax';
2
2
  export { BlobRef, lexToJson, stringifyLex, jsonToLex, jsonStringToLex, } from '@atproto/lexicon';
3
3
  export { parseLanguage } from '@atproto/common-web';
4
4
  export * from './types';
5
+ export * from './util';
5
6
  export * from './client';
6
7
  export * from './agent';
7
8
  export * from './rich-text/rich-text';
package/dist/index.js CHANGED
@@ -9076,6 +9076,7 @@ __export(src_exports2, {
9076
9076
  moderateProfile: () => moderateProfile,
9077
9077
  moderateUserList: () => moderateUserList,
9078
9078
  parseLanguage: () => parseLanguage,
9079
+ sanitizeMutedWordValue: () => sanitizeMutedWordValue,
9079
9080
  sanitizeRichText: () => sanitizeRichText,
9080
9081
  stringifyLex: () => stringifyLex
9081
9082
  });
@@ -15383,6 +15384,11 @@ var jsonStringToLex = (val) => {
15383
15384
  return jsonToLex(JSON.parse(val));
15384
15385
  };
15385
15386
 
15387
+ // src/util.ts
15388
+ function sanitizeMutedWordValue(value) {
15389
+ return value.trim().replace(/^#(?!\ufe0f)/, "").replace(/[\r\n\u00AD\u2060\u200D\u200C\u200B]+/, "");
15390
+ }
15391
+
15386
15392
  // ../xrpc/src/types.ts
15387
15393
  var errorResponseBody = z.object({
15388
15394
  error: z.string().optional(),
@@ -32227,14 +32233,74 @@ var BskyAgent = class extends AtpAgent {
32227
32233
  return prefs.filter((p) => !defs_exports5.isInterestsPref(p)).concat([{ ...pref, $type: "app.bsky.actor.defs#interestsPref" }]);
32228
32234
  });
32229
32235
  }
32230
- async upsertMutedWords(mutedWords) {
32231
- await updateMutedWords(this, mutedWords, "upsert");
32236
+ async upsertMutedWords(newMutedWords) {
32237
+ await updatePreferences(this, (prefs) => {
32238
+ let mutedWordsPref = prefs.findLast((pref) => defs_exports5.isMutedWordsPref(pref) && defs_exports5.validateMutedWordsPref(pref).success);
32239
+ if (mutedWordsPref && defs_exports5.isMutedWordsPref(mutedWordsPref)) {
32240
+ for (const updatedWord of newMutedWords) {
32241
+ let foundMatch = false;
32242
+ const sanitizedUpdatedValue = sanitizeMutedWordValue(updatedWord.value);
32243
+ if (!sanitizedUpdatedValue)
32244
+ continue;
32245
+ for (const existingItem of mutedWordsPref.items) {
32246
+ if (existingItem.value === sanitizedUpdatedValue) {
32247
+ existingItem.targets = Array.from(/* @__PURE__ */ new Set([...existingItem.targets, ...updatedWord.targets]));
32248
+ foundMatch = true;
32249
+ break;
32250
+ }
32251
+ }
32252
+ if (!foundMatch) {
32253
+ mutedWordsPref.items.push({
32254
+ ...updatedWord,
32255
+ value: sanitizedUpdatedValue
32256
+ });
32257
+ }
32258
+ }
32259
+ } else {
32260
+ mutedWordsPref = {
32261
+ items: newMutedWords.map((w) => ({
32262
+ ...w,
32263
+ value: sanitizeMutedWordValue(w.value)
32264
+ }))
32265
+ };
32266
+ }
32267
+ return prefs.filter((p) => !defs_exports5.isMutedWordsPref(p)).concat([
32268
+ { ...mutedWordsPref, $type: "app.bsky.actor.defs#mutedWordsPref" }
32269
+ ]);
32270
+ });
32232
32271
  }
32233
32272
  async updateMutedWord(mutedWord) {
32234
- await updateMutedWords(this, [mutedWord], "update");
32273
+ await updatePreferences(this, (prefs) => {
32274
+ let mutedWordsPref = prefs.findLast((pref) => defs_exports5.isMutedWordsPref(pref) && defs_exports5.validateMutedWordsPref(pref).success);
32275
+ if (mutedWordsPref && defs_exports5.isMutedWordsPref(mutedWordsPref)) {
32276
+ for (const existingItem of mutedWordsPref.items) {
32277
+ if (existingItem.value === mutedWord.value) {
32278
+ existingItem.targets = mutedWord.targets;
32279
+ break;
32280
+ }
32281
+ }
32282
+ }
32283
+ return prefs.filter((p) => !defs_exports5.isMutedWordsPref(p)).concat([
32284
+ { ...mutedWordsPref, $type: "app.bsky.actor.defs#mutedWordsPref" }
32285
+ ]);
32286
+ });
32235
32287
  }
32236
32288
  async removeMutedWord(mutedWord) {
32237
- await updateMutedWords(this, [mutedWord], "remove");
32289
+ await updatePreferences(this, (prefs) => {
32290
+ let mutedWordsPref = prefs.findLast((pref) => defs_exports5.isMutedWordsPref(pref) && defs_exports5.validateMutedWordsPref(pref).success);
32291
+ if (mutedWordsPref && defs_exports5.isMutedWordsPref(mutedWordsPref)) {
32292
+ for (let i = 0; i < mutedWordsPref.items.length; i++) {
32293
+ const existing = mutedWordsPref.items[i];
32294
+ if (existing.value === mutedWord.value) {
32295
+ mutedWordsPref.items.splice(i, 1);
32296
+ break;
32297
+ }
32298
+ }
32299
+ }
32300
+ return prefs.filter((p) => !defs_exports5.isMutedWordsPref(p)).concat([
32301
+ { ...mutedWordsPref, $type: "app.bsky.actor.defs#mutedWordsPref" }
32302
+ ]);
32303
+ });
32238
32304
  }
32239
32305
  async hidePost(postUri) {
32240
32306
  await updateHiddenPost(this, postUri, "hide");
@@ -32273,51 +32339,6 @@ async function updateFeedPreferences(agent, cb) {
32273
32339
  });
32274
32340
  return res;
32275
32341
  }
32276
- async function updateMutedWords(agent, mutedWords, action) {
32277
- const sanitizeMutedWord = (word) => ({
32278
- value: word.value.replace(/^#/, ""),
32279
- targets: word.targets
32280
- });
32281
- await updatePreferences(agent, (prefs) => {
32282
- let mutedWordsPref = prefs.findLast((pref) => defs_exports5.isMutedWordsPref(pref) && defs_exports5.validateMutedWordsPref(pref).success);
32283
- if (mutedWordsPref && defs_exports5.isMutedWordsPref(mutedWordsPref)) {
32284
- if (action === "upsert" || action === "update") {
32285
- for (const word of mutedWords) {
32286
- let foundMatch = false;
32287
- for (const existingItem of mutedWordsPref.items) {
32288
- if (existingItem.value === sanitizeMutedWord(word).value) {
32289
- existingItem.targets = action === "upsert" ? Array.from(/* @__PURE__ */ new Set([...existingItem.targets, ...word.targets])) : word.targets;
32290
- foundMatch = true;
32291
- break;
32292
- }
32293
- }
32294
- if (action === "upsert" && !foundMatch) {
32295
- mutedWordsPref.items.push(sanitizeMutedWord(word));
32296
- }
32297
- }
32298
- } else if (action === "remove") {
32299
- for (const word of mutedWords) {
32300
- for (let i = 0; i < mutedWordsPref.items.length; i++) {
32301
- const existing = mutedWordsPref.items[i];
32302
- if (existing.value === sanitizeMutedWord(word).value) {
32303
- mutedWordsPref.items.splice(i, 1);
32304
- break;
32305
- }
32306
- }
32307
- }
32308
- }
32309
- } else {
32310
- if (action === "upsert") {
32311
- mutedWordsPref = {
32312
- items: mutedWords.map(sanitizeMutedWord)
32313
- };
32314
- }
32315
- }
32316
- return prefs.filter((p) => !defs_exports5.isMutedWordsPref(p)).concat([
32317
- { ...mutedWordsPref, $type: "app.bsky.actor.defs#mutedWordsPref" }
32318
- ]);
32319
- });
32320
- }
32321
32342
  async function updateHiddenPost(agent, postUri, action) {
32322
32343
  await updatePreferences(agent, (prefs) => {
32323
32344
  let pref = prefs.findLast((pref2) => defs_exports5.isHiddenPostsPref(pref2) && defs_exports5.validateHiddenPostsPref(pref2).success);