Skip to content

plugin-gateway: add ClientApplication and client.application (discord.js parity) #208

Closed

Description

@RedStar071

Context

@wolfstar/plugin-gateway has no Application/ClientApplication structure, so there is no client.application. In discord.js it is the entry point for everything owned by the application rather than by a guild, and #207 (ApplicationEmoji, ApplicationCommand and their managers) cannot land without it. This issue tracks the structure on its own, as the prerequisite of #207.

Proposal

  1. Application base and ClientApplication, like discord.js:
    • Application: id, name, description, icon, iconURL(), coverURL(), createdTimestamp/createdAt, toString().
    • ClientApplication: flags, tags, installParams, integrationTypesConfig, customInstallURL, owner (user or team), botPublic, botRequireCodeGrant, guildId/guild, approximateGuildCount, approximateUserInstallCount, interactionsEndpointURL, roleConnectionsVerificationURL, eventWebhooksURL/eventWebhooksStatus/eventWebhooksTypes, and partial.
  2. client.application. Decide where it comes from:
    • the READY payload carries a partial application (id and flags), which is what discord.js starts from;
    • the client already knows its clientId from the options, so a partial ClientApplication could exist before READY, or without a gateway connection at all.
  3. Methods. fetch() (GET /applications/@me), edit() (PATCH /applications/@me), fetchRoleConnectionMetadataRecords() and editRoleConnectionMetadataRecords().
  4. Manager slots. Leave room for application.commands and application.emojis (plugin-gateway: port ApplicationEmoji (with its manager) and ApplicationCommand (discord.js parity) #207), and for application.entitlements and fetchSKUs() (the entitlements sub-project).
  5. Cache. The application is a single object per client: decide whether it lives on the client like discord.js, or goes through @wolfstar/plugin-cache so that every process of a sharded or brokered deployment sees the same data.

Questions

  • Team and TeamMember are needed for owner when the application belongs to a team. Port them here, or expose the raw owner first?
  • Does @wolfstar/http-framework already expose application data (ID, public key) that this should reuse instead of duplicating?
  • Is a partial client.application available before READY acceptable, given clientId is a required option?

Out of scope

The managers and structures of #207, entitlements and SKUs, and interaction structures.

Activity

  1. pullfrog commented on Oct 5, 2026

    @pullfrog
    Contributor

    Assessment

    Actionable, and a good prerequisite split from #207. Nothing exists yet: READY (packages/plugin-gateway/src/util/dispatch.ts:151) builds client.user and drops data.application, and GatewayClient has no application field. ApplicationFlagsBitField already exists in util/flags.ts, @discordjs/core covers every route needed (api.applications.getCurrent and editCurrent, plus the role connection metadata API), and @wolfstar/http-framework's Client already exposes id (see the client.id fallback in the USER_UPDATE handler).

    Proposed design

    1. Structures (new src/structures/applications/, exported from structures/index.ts)

    • Application<Data> extends Structure, in the shape of AnonymousGuild: id, name, description, icon, iconURL(), coverURL(), createdTimestamp/createdAt, toString(). CDN URLs go through util/cdn.ts (appIcon for both, as discord.js does; to confirm against @discordjs/rest).
    • ClientApplication extends Application: the getters listed in the issue, typed from APIApplication. flags is an ApplicationFlagsBitField. partial is true while name is absent.
    • Data type: Pick<APIApplication, "id"> & Partial<Omit<APIApplication, "id">>, so the same class holds the { id } seed, the READY payload (id and flags) and a full GET /applications/@me.
    • Methods follow the repo's two-line edit() shape (await this.client.api…; return this[kPatch](data)): fetch(), edit(), fetchRoleConnectionMetadataRecords(), editRoleConnectionMetadataRecords(). edit() options resolve icon and coverImage through resolveImageOption, as ClientUser#edit does.

    2. Where client.application comes from

    • Create new ClientApplication({ id: this.id }) in the GatewayClient constructor. It exists before READY and without a gateway connection, which answers question 3: yes, acceptable. clientId is required, so client.application is typed non-null (discord.js types it nullable). That is a deliberate, superset-compatible deviation and should be documented.
    • READY patches the same instance in place (client.application[kPatch](data.application)) instead of replacing it, so references held by user code stay valid.
    • This also works for broker workers that replay dispatches without ever seeing READY themselves.
    • READY has no before hook, so no DispatchStateCodecs entry is needed. tests/dispatch-state.test.ts only requires one for handlers that define before.

    3. Cache (point 5)

    • Recommend keeping it on the client, like discord.js and like client.user, and not adding a plugin-cache entity.
    • It is one tiny object per client. It has no gateway update event, and each process gets the same READY payload anyway.
    • A new store would mean a plugin-cache change and changeset, a READY op, a codec and StructureStoreAdapter wiring, all for a value that fetch() can refresh.
    • Revisit only if cross-process freshness of fetch()/edit() results turns out to matter.

    4. Team / TeamMember (question 1)

    • Recommend porting a small Team and TeamMember here, so owner is a typed User | Team | null and not a raw union. They are small (APITeam plus members) and teamIcon is available in the CDN helper.
    • Fall back to exposing the raw APITeam if it grows. Team can't be a standalone issue because owner depends on it.
    • A User owner goes through client.users._build (not new User) so it binds the client.

    5. Manager slots (point 4)

    6. http-framework overlap (question 2)

    Work breakdown

    1. Application, ClientApplication, Team, TeamMember structures, plus exports and GatewayClient#application with the READY patch.
    2. fetch, edit and the role connection metadata methods, with typed options.
    3. Tests, in tests/applications.test.ts and the style of webhooks.test.ts/client-ready.test.ts:
      • the partial seed before READY
      • in-place READY patch
      • fetch and edit against a mocked REST
      • CDN URLs and partial
      • a type-level test under tests/types/
    4. A minor changeset for @wolfstar/plugin-gateway, then the quality gates: pnpm lint, pnpm build, pnpm typecheck, pnpm test.

    Open points for the author

    • Confirm the non-null client.application (vs discord.js's nullable).
    • Confirm Team/TeamMember ship in this issue.
    • Confirm the cache stays on the client.

    I haven't started implementation. Say the word (or answer the open points) and I'll proceed.

    Pullfrog  | Implement plan ➔ | View workflow run | via Pullfrog | Using claude-sonnet-5-5 | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions