@atproto/api 0.6.11 → 0.6.12

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.
@@ -1,6 +1,11 @@
1
1
  import { AtpAgent } from './agent';
2
2
  import { AppBskyFeedPost, AppBskyActorProfile } from './client';
3
3
  import { BskyPreferences, BskyLabelPreference } from './types';
4
+ declare global {
5
+ interface Array<T> {
6
+ findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T;
7
+ }
8
+ }
4
9
  export declare class BskyAgent extends AtpAgent {
5
10
  get app(): import("./client").AppNS;
6
11
  getTimeline: typeof this.api.app.bsky.feed.getTimeline;
@@ -67,4 +72,7 @@ export declare class BskyAgent extends AtpAgent {
67
72
  }>;
68
73
  setAdultContentEnabled(v: boolean): Promise<void>;
69
74
  setContentLabelPref(key: string, value: BskyLabelPreference): Promise<void>;
75
+ setPersonalDetails({ birthDate, }: {
76
+ birthDate: string | Date | undefined;
77
+ }): Promise<void>;
70
78
  }
package/dist/index.js CHANGED
@@ -28950,7 +28950,8 @@ var BskyAgent = class extends AtpAgent {
28950
28950
  pinned: void 0
28951
28951
  },
28952
28952
  adultContentEnabled: false,
28953
- contentLabels: {}
28953
+ contentLabels: {},
28954
+ birthDate: void 0
28954
28955
  };
28955
28956
  const res = await this.app.bsky.actor.getPreferences({});
28956
28957
  for (const pref of res.data.preferences) {
@@ -28967,6 +28968,10 @@ var BskyAgent = class extends AtpAgent {
28967
28968
  } else if (defs_exports5.isSavedFeedsPref(pref) && defs_exports5.validateSavedFeedsPref(pref).success) {
28968
28969
  prefs.feeds.saved = pref.saved;
28969
28970
  prefs.feeds.pinned = pref.pinned;
28971
+ } else if (defs_exports5.isPersonalDetailsPref(pref) && defs_exports5.validatePersonalDetailsPref(pref).success) {
28972
+ if (pref.birthDate) {
28973
+ prefs.birthDate = new Date(pref.birthDate);
28974
+ }
28970
28975
  }
28971
28976
  }
28972
28977
  return prefs;
@@ -29003,16 +29008,16 @@ var BskyAgent = class extends AtpAgent {
29003
29008
  }
29004
29009
  async setAdultContentEnabled(v) {
29005
29010
  await updatePreferences(this, (prefs) => {
29006
- const existing = prefs.find((pref) => defs_exports5.isAdultContentPref(pref) && defs_exports5.validateAdultContentPref(pref).success);
29007
- if (existing) {
29008
- existing.enabled = v;
29011
+ let adultContentPref = prefs.findLast((pref) => defs_exports5.isAdultContentPref(pref) && defs_exports5.validateAdultContentPref(pref).success);
29012
+ if (adultContentPref) {
29013
+ adultContentPref.enabled = v;
29009
29014
  } else {
29010
- prefs.push({
29015
+ adultContentPref = {
29011
29016
  $type: "app.bsky.actor.defs#adultContentPref",
29012
29017
  enabled: v
29013
- });
29018
+ };
29014
29019
  }
29015
- return prefs;
29020
+ return prefs.filter((pref) => !defs_exports5.isAdultContentPref(pref)).concat([adultContentPref]);
29016
29021
  });
29017
29022
  }
29018
29023
  async setContentLabelPref(key, value) {
@@ -29020,17 +29025,34 @@ var BskyAgent = class extends AtpAgent {
29020
29025
  value = "ignore";
29021
29026
  }
29022
29027
  await updatePreferences(this, (prefs) => {
29023
- const existing = prefs.find((pref) => defs_exports5.isContentLabelPref(pref) && defs_exports5.validateAdultContentPref(pref).success && pref.label === key);
29024
- if (existing) {
29025
- existing.visibility = value;
29028
+ let labelPref = prefs.findLast((pref) => defs_exports5.isContentLabelPref(pref) && defs_exports5.validateAdultContentPref(pref).success && pref.label === key);
29029
+ if (labelPref) {
29030
+ labelPref.visibility = value;
29026
29031
  } else {
29027
- prefs.push({
29032
+ labelPref = {
29028
29033
  $type: "app.bsky.actor.defs#contentLabelPref",
29029
29034
  label: key,
29030
29035
  visibility: value
29031
- });
29036
+ };
29037
+ }
29038
+ return prefs.filter((pref) => !defs_exports5.isContentLabelPref(pref) || pref.label !== key).concat([labelPref]);
29039
+ });
29040
+ }
29041
+ async setPersonalDetails({
29042
+ birthDate
29043
+ }) {
29044
+ birthDate = birthDate instanceof Date ? birthDate.toISOString() : birthDate;
29045
+ await updatePreferences(this, (prefs) => {
29046
+ let personalDetailsPref = prefs.findLast((pref) => defs_exports5.isPersonalDetailsPref(pref) && defs_exports5.validatePersonalDetailsPref(pref).success);
29047
+ if (personalDetailsPref) {
29048
+ personalDetailsPref.birthDate = birthDate;
29049
+ } else {
29050
+ personalDetailsPref = {
29051
+ $type: "app.bsky.actor.defs#personalDetailsPref",
29052
+ birthDate
29053
+ };
29032
29054
  }
29033
- return prefs;
29055
+ return prefs.filter((pref) => !defs_exports5.isPersonalDetailsPref(pref)).concat([personalDetailsPref]);
29034
29056
  });
29035
29057
  }
29036
29058
  };
@@ -29047,7 +29069,7 @@ async function updatePreferences(agent, cb) {
29047
29069
  async function updateFeedPreferences(agent, cb) {
29048
29070
  let res;
29049
29071
  await updatePreferences(agent, (prefs) => {
29050
- let feedsPref = prefs.find((pref) => defs_exports5.isSavedFeedsPref(pref) && defs_exports5.validateSavedFeedsPref(pref).success);
29072
+ let feedsPref = prefs.findLast((pref) => defs_exports5.isSavedFeedsPref(pref) && defs_exports5.validateSavedFeedsPref(pref).success);
29051
29073
  if (feedsPref) {
29052
29074
  res = cb(feedsPref.saved, feedsPref.pinned);
29053
29075
  feedsPref.saved = res.saved;