Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency @atproto/api to ^0.13.0 #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Dec 6, 2023

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@atproto/api (source) ^0.6.4 -> ^0.13.0 age adoption passing confidence

Release Notes

bluesky-social/atproto (@​atproto/api)

v0.13.20

Compare Source

Patch Changes

v0.13.19

Compare Source

Patch Changes
  • #​3171 ed2236220 Thanks @​foysalit! - Allow moderators to optionally acknowledge all open subjects of an account when acknowledging account level reports

v0.13.18

Compare Source

Patch Changes

v0.13.17

Compare Source

Patch Changes

v0.13.16

Compare Source

Patch Changes

v0.13.15

Compare Source

Patch Changes

v0.13.14

Compare Source

Patch Changes

v0.13.13

Compare Source

Patch Changes

v0.13.12

Compare Source

Patch Changes

v0.13.11

Compare Source

Patch Changes

v0.13.10

Compare Source

Patch Changes

v0.13.9

Compare Source

Patch Changes

v0.13.8

Compare Source

Patch Changes

v0.13.7

Compare Source

Patch Changes

v0.13.6

Compare Source

Patch Changes

v0.13.5

Compare Source

Patch Changes

v0.13.4

Compare Source

Patch Changes

v0.13.3

Compare Source

Patch Changes

v0.13.2

Compare Source

Patch Changes

v0.13.1

Compare Source

Patch Changes
  • #​3171 ed2236220 Thanks @​foysalit! - Allow moderators to optionally acknowledge all open subjects of an account when acknowledging account level reports

v0.13.0

Compare Source

Minor Changes
Motivation

The motivation for these changes is the need to make the @atproto/api package
compatible with OAuth session management. We don't have OAuth client support
"launched" and documented quite yet, so you can keep using the current app
password authentication system. When we do "launch" OAuth support and begin
encouraging its usage in the near future (see the OAuth
Roadmap
), these
changes will make it easier to migrate.

In addition, the redesigned session management system fixes a bug that could
cause the session data to become invalid when Agent clones are created (e.g.
using agent.withProxy()).

New Features

We've restructured the XrpcClient HTTP fetch handler to be specified during
the instantiation of the XRPC client, through the constructor, instead of using
a default implementation (which was statically defined).

With this refactor, the XRPC client is now more modular and reusable. Session
management, retries, cryptographic signing, and other request-specific logic can
be implemented in the fetch handler itself rather than by the calling code.

A new abstract class named Agent, has been added to @atproto/api. This class
will be the base class for all Bluesky agents classes in the @atproto
ecosystem. It is meant to be extended by implementations that provide session
management and fetch handling.

As you adapt your code to these changes, make sure to use the Agent type
wherever you expect to receive an agent, and use the AtpAgent type (class)
only to instantiate your client. The reason for this is to be forward compatible
with the OAuth agent implementation that will also extend Agent, and not
AtpAgent.

import { Agent, AtpAgent } from "@​atproto/api";

async function setupAgent(
  service: string,
  username: string,
  password: string,
): Promise<Agent> {
  const agent = new AtpAgent({
    service,
    persistSession: (evt, session) => {
      // handle session update
    },
  });

  await agent.login(username, password);

  return agent;
}
import { Agent } from "@&#8203;atproto/api";

async function doStuffWithAgent(agent: Agent, arg: string) {
  return agent.resolveHandle(arg);
}
import { Agent, AtpAgent } from "@&#8203;atproto/api";

class MyClass {
  agent: Agent;

  constructor() {
    this.agent = new AtpAgent();
  }
}
Breaking changes

Most of the changes introduced in this version are backward-compatible. However,
there are a couple of breaking changes you should be aware of:

  • Customizing fetch: The ability to customize the fetch: FetchHandler
    property of @atproto/xrpc's Client and @atproto/api's AtpAgent classes
    has been removed. Previously, the fetch property could be set to a function
    that would be used as the fetch handler for that instance, and was initialized
    to a default fetch handler. That property is still accessible in a read-only
    fashion through the fetchHandler property and can only be set during the
    instance creation. Attempting to set/get the fetch property will now result
    in an error.
  • The fetch() method, as well as WhatWG compliant Request and Headers
    constructors, must be globally available in your environment. Use a polyfill
    if necessary.
  • The AtpBaseClient has been removed. The AtpServiceClient has been renamed
    AtpBaseClient. Any code using either of these classes will need to be
    updated.
  • Instead of wrapping an XrpcClient in its xrpc property, the
    AtpBaseClient (formerly AtpServiceClient) class - created through
    lex-cli - now extends the XrpcClient class. This means that a client
    instance now passes the instanceof XrpcClient check. The xrpc property now
    returns the instance itself and has been deprecated.
  • setSessionPersistHandler is no longer available on the AtpAgent or
    BskyAgent classes. The session handler can only be set though the
    persistSession options of the AtpAgent constructor.
  • The new class hierarchy is as follows:
    • BskyAgent extends AtpAgent: but add no functionality (hence its
      deprecation).
    • AtpAgent extends Agent: adds password based session management.
    • Agent extends AtpBaseClient: this abstract class that adds syntactic sugar
      methods app.bsky lexicons. It also adds abstract session management
      methods and adds atproto specific utilities
      (labelers & proxy headers, cloning capability)
    • AtpBaseClient extends XrpcClient: automatically code that adds fully
      typed lexicon defined namespaces (instance.app.bsky.feed.getPosts()) to
      the XrpcClient.
    • XrpcClient is the base class.
Non-breaking changes
  • The com.* and app.* namespaces have been made directly available to every
    Agent instances.
Deprecations
  • The default export of the @atproto/xrpc package has been deprecated. Use
    named exports instead.
  • The Client and ServiceClient classes are now deprecated. They are replaced by a single XrpcClient class.
  • The default export of the @atproto/api package has been deprecated. Use
    named exports instead.
  • The BskyAgent has been deprecated. Use the AtpAgent class instead.
  • The xrpc property of the AtpClient instances has been deprecated. The
    instance itself should be used as the XRPC client.
  • The api property of the AtpAgent and BskyAgent instances has been
    deprecated. Use the instance itself instead.
Migration
The @atproto/api package

If you were relying on the AtpBaseClient solely to perform validation, use
this:

Before After
import { AtpBaseClient, ComAtprotoSyncSubscribeRepos } from "@&#8203;atproto/api";

const baseClient = new AtpBaseClient();

baseClient.xrpc.lex.assertValidXrpcMessage("io.example.doStuff", {
  // ...
});
import { lexicons } from "@&#8203;atproto/api";

lexicons.assertValidXrpcMessage("io.example.doStuff", {
  // ...
});

If you are extending the BskyAgent to perform custom session manipulation, define your own Agent subclass instead:

Before After
import { BskyAgent } from "@&#8203;atproto/api";

class MyAgent extends BskyAgent {
  private accessToken?: string;

  async createOrRefreshSession(identifier: string, password: string) {
    // custom logic here

    this.accessToken = "my-access-jwt";
  }

  async doStuff() {
    return this.call("io.example.doStuff", {
      headers: {
        Authorization: this.accessToken && `Bearer ${this.accessToken}`,
      },
    });
  }
}
import { Agent } from "@&#8203;atproto/api";

class MyAgent extends Agent {
  private accessToken?: string;
  public did?: string;

  constructor(private readonly service: string | URL) {
    super({
      service,
      headers: {
        Authorization: () =>
          this.accessToken ? `Bearer ${this.accessToken}` : null,
      },
    });
  }

  clone(): MyAgent {
    const agent = new MyAgent(this.service);
    agent.accessToken = this.accessToken;
    agent.did = this.did;
    return this.copyInto(agent);
  }

  async createOrRefreshSession(identifier: string, password: string) {
    // custom logic here

    this.did = "did:example:123";
    this.accessToken = "my-access-jwt";
  }
}

If you are monkey patching the xrpc service client to perform client-side rate limiting, you can now do this in the FetchHandler function:

Before After
import { BskyAgent } from "@&#8203;atproto/api";
import { RateLimitThreshold } from "rate-limit-threshold";

const agent = new BskyAgent();
const limiter = new RateLimitThreshold(3000, 300_000);

const origCall = agent.api.xrpc.call;
agent.api.xrpc.call = async function (...args) {
  await limiter.wait();
  return origCall.call(this, ...args);
};
import { AtpAgent } from "@&#8203;atproto/api";
import { RateLimitThreshold } from "rate-limit-threshold";

class LimitedAtpAgent extends AtpAgent {
  constructor(options: AtpAgentOptions) {
    const fetch: typeof globalThis.fetch = options.fetch ?? globalThis.fetch;
    const limiter = new RateLimitThreshold(3000, 300_000);

    super({
      ...options,
      fetch: async (...args) => {
        await limiter.wait();
        return fetch(...args);
      },
    });
  }
}

If you configure a static fetch handler on the BskyAgent class - for example
to modify the headers of every request - you can now do this by providing your
own fetch function:

Before After
import { BskyAgent, defaultFetchHandler } from "@&#8203;atproto/api";

BskyAgent.configure({
  fetch: async (httpUri, httpMethod, httpHeaders, httpReqBody) => {
    const ua = httpHeaders["User-Agent"];

    httpHeaders["User-Agent"] = ua ? `${ua} ${userAgent}` : userAgent;

    return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
  },
});
import { AtpAgent } from "@&#8203;atproto/api";

class MyAtpAgent extends AtpAgent {
  constructor(options: AtpAgentOptions) {
    const fetch = options.fetch ?? globalThis.fetch;

    super({
      ...options,
      fetch: async (url, init) => {
        const headers = new Headers(init.headers);

        const ua = headersList.get("User-Agent");
        headersList.set("User-Agent", ua ? `${ua} ${userAgent}` : userAgent);

        return fetch(url, { ...init, headers });
      },
    });
  }
}
The @atproto/xrpc package

The Client and ServiceClient classes are now deprecated. If you need a
lexicon based client, you should update the code to use the XrpcClient class
instead.

The deprecated ServiceClient class now extends the new XrpcClient class.
Because of this, the fetch FetchHandler can no longer be configured on the
Client instances (including the default export of the package). If you are not
relying on the fetch FetchHandler, the new changes should have no impact on
your code. Beware that the deprecated classes will eventually be removed in a
future version.

Since its use has completely changed, the FetchHandler type has also
completely changed. The new FetchHandler type is now a function that receives
a url pathname and a RequestInit object and returns a Promise<Response>.
This function is responsible for making the actual request to the server.

export type FetchHandler = (
  this: void,
  /**
   * The URL (pathname + query parameters) to make the request to, without the
   * origin. The origin (protocol, hostname, and port) must be added by this
   * {@&#8203;link FetchHandler}, typically based on authentication or other factors.
   */
  url: string,
  init: RequestInit,
) => Promise<Response>;

A noticeable change that has been introduced is that the uri field of the
ServiceClient class has not been ported to the new XrpcClient class. It is
now the responsibility of the FetchHandler to determine the full URL to make
the request to. The same goes for the headers, which should now be set through
the FetchHandler function.

If you do rely on the legacy Client.fetch property to perform custom logic
upon request, you will need to migrate your code to use the new XrpcClient
class. The XrpcClient class has a similar API to the old ServiceClient
class, but with a few differences:

  • The Client + ServiceClient duality was removed in favor of a single
    XrpcClient class. This means that:

    • There no longer exists a centralized lexicon registry. If you need a global
      lexicon registry, you can maintain one yourself using a new Lexicons (from
      @atproto/lexicon).
    • The FetchHandler is no longer a statically defined property of the
      Client class. Instead, it is passed as an argument to the XrpcClient
      constructor.
  • The XrpcClient constructor now requires a FetchHandler function as the
    first argument, and an optional Lexicon instance as the second argument.

  • The setHeader and unsetHeader methods were not ported to the new
    XrpcClient class. If you need to set or unset headers, you should do so in
    the FetchHandler function provided in the constructor arg.

Before After
import client, { defaultFetchHandler } from "@&#8203;atproto/xrpc";

client.fetch = function (
  httpUri: string,
  httpMethod: string,
  httpHeaders: Headers,
  httpReqBody: unknown,
) {
  // Custom logic here
  return defaultFetchHandler(httpUri, httpMethod, httpHeaders, httpReqBody);
};

client.addLexicon({
  lexicon: 1,
  id: "io.example.doStuff",
  defs: {},
});

const instance = client.service("http://my-service.com");

instance.setHeader("my-header", "my-value");

await instance.call("io.example.doStuff");
import { XrpcClient } from "@&#8203;atproto/xrpc";

const instance = new XrpcClient(
  async (url, init) => {
    const headers = new Headers(init.headers);

    headers.set("my-header", "my-value");

    // Custom logic here

    const fullUrl = new URL(url, "http://my-service.com");

    return fetch(fullUrl, { ...init, headers });
  },
  [
    {
      lexicon: 1,
      id: "io.example.doStuff",
      defs: {},
    },
  ],
);

await instance.call("io.example.doStuff");

If your fetch handler does not require any "custom logic", and all you need is
an XrpcClient that makes its HTTP requests towards a static service URL, the
previous example can be simplified to:

import { XrpcClient } from "@&#8203;atproto/xrpc";

const instance = new XrpcClient("http://my-service.com", [
  {
    lexicon: 1,
    id: "io.example.doStuff",
    defs: {},
  },
]);

If you need to add static headers to all requests, you can instead instantiate
the XrpcClient as follows:

import { XrpcClient } from "@&#8203;atproto/xrpc";

const instance = new XrpcClient(
  {
    service: "http://my-service.com",
    headers: {
      "my-header": "my-value",
    },
  },
  [
    {
      lexicon: 1,
      id: "io.example.doStuff",
      defs: {},
    },
  ],
);

If you need the headers or service url to be dynamic, you can define them using
functions:

import { XrpcClient } from "@&#8203;atproto/xrpc";

const instance = new XrpcClient(
  {
    service: () => "http://my-service.com",
    headers: {
      "my-header": () => "my-value",
      "my-ignored-header": () => null, // ignored
    },
  },
  [
    {
      lexicon: 1,
      id: "io.example.doStuff",
      defs: {},
    },
  ],
);
Patch Changes

v0.12.29

Compare Source

Patch Changes

v0.12.28

Compare Source

Patch Changes

v0.12.27

Compare Source

Patch Changes

v0.12.26

Compare Source

Patch Changes
  • #​2276 77c5306d2 Thanks @​estrattonbailey! - Updates muted words lexicons to include new attributes id, actorTarget, and expiresAt. Adds and updates methods in API SDK for better management of muted words.

v0.12.25

Compare Source

Patch Changes

v0.12.24

Compare Source

Patch Changes

v0.12.23

Compare Source

Patch Changes
  • #​2492 bc861a2c2 Thanks @​pfrazee! - Added bsky app state preference and improved protections against race conditions in preferences sdk

v0.12.22

Compare Source

Patch Changes

v0.12.21

Compare Source

Patch Changes

v0.12.20

Compare Source

Patch Changes

v0.12.19

Compare Source

Patch Changes

v0.12.18

Compare Source

Patch Changes
  • #​2557 58abcbd8b Thanks @​estrattonbailey! - Adds "social proof": knowFollowers to ViewerState for ProfileViewDetailed
    views and app.bsky.graph.getKnownFollowers method for listing known followers
    of a given user.

v0.12.17

Compare Source

Patch Changes

v0.12.16

Compare Source

Patch Changes

v0.12.15

Compare Source

Patch Changes

v0.12.14

Compare Source

Patch Changes

v0.12.13

Compare Source

Patch Changes

v0.12.12

Compare Source

Patch Changes
  • #​2442 1f560f021 Thanks @​foysalit! - Add com.atproto.label.queryLabels endpoint on appview and allow viewing external labels through ozone

v0.12.11

Compare Source

Patch Changes

v0.12.10

Compare Source

Patch Changes

v0.12.9

Compare Source

Patch Changes

v0.12.8

Compare Source

Patch Changes

v0.12.7

Compare Source

Patch Changes

v0.12.6

Compare Source

Patch Changes
  • #​2427 b9b7c5821 Thanks @​estrattonbailey! - Introduces V2 of saved feeds preferences. V2 and v1 prefs are incompatible. v1
    methods and preference objects are retained for backwards compatability, but are
    considered deprecated. Developers should immediately migrate to v2 interfaces.

v0.12.5

Compare Source

Patch Changes

v0.12.4

Compare Source

Patch Changes

v0.12.3

Compare Source

Patch Changes

v0.12.2

Compare Source

Patch Changes

v0.12.1

Compare Source

Patch Changes

v0.12.0

Compare Source

Minor Changes
Patch Changes

v0.11.2

Compare Source

Patch Changes

v0.11.1

Compare Source

Patch Changes

v0.11.0

Compare Source

Minor Changes
  • #​2302 4eaadc0ac Thanks @​dholms! - - Breaking changes
    • Redesigned the moderate* APIs which now output a ModerationUI object.
    • agent.getPreferences() output object BskyPreferences has been modified.
    • Moved Ozone routes from com.atproto.admin to tools.ozone namespace.
    • Additions
      • Added support for labeler configuration in Agent.configure() and agent.configureLabelerHeader().
      • Added agent.addLabeler() and agent.removeLabeler() preference methods.
      • Muted words and hidden posts are now handled in the moderate* APIs.
      • Added agent.getLabelers() and agent.getLabelDefinitions().
      • Added `agent.configureProxyHeader(

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from ded74a2 to 6de37fe Compare January 5, 2024 04:36
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.7.0 fix(deps): update dependency @atproto/api to ^0.8.0 Jan 5, 2024
@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from 6de37fe to 5e97db2 Compare January 19, 2024 02:06
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.8.0 fix(deps): update dependency @atproto/api to ^0.9.0 Jan 19, 2024
@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from 5e97db2 to 155d373 Compare February 22, 2024 03:26
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.9.0 fix(deps): update dependency @atproto/api to ^0.10.0 Feb 22, 2024
@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from 155d373 to 086fb49 Compare March 13, 2024 20:20
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.10.0 fix(deps): update dependency @atproto/api to ^0.11.0 Mar 13, 2024
@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from 086fb49 to 9a8e782 Compare March 19, 2024 00:16
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.11.0 fix(deps): update dependency @atproto/api to ^0.12.0 Mar 19, 2024
@renovate renovate bot force-pushed the renovate/atproto-api-0.x branch from 9a8e782 to 3c7e226 Compare August 12, 2024 20:41
@renovate renovate bot changed the title fix(deps): update dependency @atproto/api to ^0.12.0 fix(deps): update dependency @atproto/api to ^0.13.0 Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants