@fangorn-network/sdk 2026.10.27-dev → 2026.10.28

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.
@@ -7,8 +7,15 @@ import { erc20Abi, hexToBigInt } from "viem";
7
7
  /**
8
8
  * Client for the AppRegistry's app management: apps and their ERC-5643
9
9
  * subscriptions, the publishers each app accepts, the agent card, and the
10
- * protocol admin's powers. What an app presents — its members, less exclusions — is
11
- * read through the registry (`ChainRegistry`), not this client.
10
+ * protocol admin's powers.
11
+ *
12
+ * An app can be renamed (`renameApp`): the new id is an alias of the id the app
13
+ * was claimed under, its canonical id. The contract accepts any id an app has gone
14
+ * by, so this client may be scoped to any of them; what the contract keys by the
15
+ * canonical id alone (the token, events) is resolved here first.
16
+ *
17
+ * What an app presents — its members, less exclusions — is read through the
18
+ * registry (`ChainRegistry`), not this client.
12
19
  *
13
20
  * Scoped to one app, which may be unset: then only the calls that take no app work.
14
21
  */
@@ -34,9 +41,12 @@ var AppRegistryClient = class {
34
41
  if (!this.appId) throw new Error("no app chosen: pass `appId` to Fangorn.create() or call setAppId()");
35
42
  return this.appId;
36
43
  }
37
- /** The app's subscription token: an app's token id is its app id. */
38
- tokenId(appId = this.app()) {
39
- return hexToBigInt(appId);
44
+ /**
45
+ * The app's subscription token: its canonical id, as a number. Not the id
46
+ * passed in, if that is an id the app was renamed to.
47
+ */
48
+ async tokenId(appId = this.app()) {
49
+ return hexToBigInt(await this.canonicalAppId(appId));
40
50
  }
41
51
  executeWrite(functionName, args) {
42
52
  return sendWrite(this.publicClient, requireWallet(this.walletClient, functionName), this.contractAddress, APP_REGISTRY_ABI, functionName, args);
@@ -81,23 +91,24 @@ var AppRegistryClient = class {
81
91
  const expiry = await this.expiresAt();
82
92
  throw new Error(`app ${this.app()} cannot be renewed until less than one period is left — it expires ${(/* @__PURE__ */ new Date(Number(expiry) * 1e3)).toISOString()}`);
83
93
  }
94
+ const tokenId = await this.tokenId();
84
95
  await this.approveUsdc(fee);
85
- return this.executeWrite("renewSubscription", [this.tokenId(), period]);
96
+ return this.executeWrite("renewSubscription", [tokenId, period]);
86
97
  }
87
98
  /**
88
99
  * End this app's subscription now (owner only): the expiry becomes zero and
89
100
  * nothing is refunded. Until it is renewed the app provides no storage and includes nothing.
90
101
  */
91
102
  async cancelSubscription() {
92
- return this.executeWrite("cancelSubscription", [this.tokenId()]);
103
+ return this.executeWrite("cancelSubscription", [await this.tokenId()]);
93
104
  }
94
105
  /** Unix seconds this app's subscription expires at; 0 once cancelled. Reverts for an unclaimed app. */
95
106
  async expiresAt(appId = this.app()) {
96
- return this.read("expiresAt", [this.tokenId(appId)]);
107
+ return this.read("expiresAt", [await this.tokenId(appId)]);
97
108
  }
98
109
  /** True while less than one period is left, or the subscription has expired. */
99
110
  async isRenewable() {
100
- return this.read("isRenewable", [this.tokenId()]);
111
+ return this.read("isRenewable", [await this.tokenId()]);
101
112
  }
102
113
  /** How long one payment lasts, in seconds. */
103
114
  async subscriptionPeriod() {
@@ -114,23 +125,47 @@ var AppRegistryClient = class {
114
125
  async getAppOwner(appId = this.app()) {
115
126
  return this.read("getAppOwner", [appId]);
116
127
  }
117
- /** How many apps have been claimed. */
128
+ /**
129
+ * Give this app a new id (owner only). Nothing moves: `newId` becomes an
130
+ * alias of the canonical id, so the app's publishers, exclusions,
131
+ * subscription and token carry on, and every id it went by still resolves to
132
+ * it. `newId` must be unclaimed, or an id this app already goes by (renaming
133
+ * back); one held by another app reverts `AppAlreadyRegistered`.
134
+ *
135
+ * This client stays scoped to the id it had, which still works; switch it
136
+ * with `setAppId(newId)`.
137
+ */
138
+ async renameApp(newId) {
139
+ return this.executeWrite("renameApp", [this.app(), newId]);
140
+ }
141
+ /** The id this app (or `appId`) was claimed under. An id no app goes by comes back unchanged. */
142
+ async canonicalAppId(appId = this.app()) {
143
+ return this.read("canonicalAppId", [appId]);
144
+ }
145
+ /**
146
+ * The id this app (or `appId`) goes by now: the last it was renamed to, or its
147
+ * canonical id. An id no app goes by comes back unchanged.
148
+ */
149
+ async currentAppId(appId = this.app()) {
150
+ return this.read("currentAppId", [appId]);
151
+ }
152
+ /** How many apps have been claimed. A rename adds none. */
118
153
  async appCount() {
119
154
  return this.read("appCount", []);
120
155
  }
121
- /** Up to `limit` app ids from position `offset`, oldest first; fewer past the end. */
156
+ /** Up to `limit` canonical app ids from position `offset`, oldest first; fewer past the end. */
122
157
  async appsPage(offset, limit) {
123
158
  return this.read("appsPage", [offset, limit]);
124
159
  }
125
160
  /**
126
- * Every claimed app id, oldest first.
161
+ * Every claimed app id (canonical; see `currentAppId`), oldest first.
127
162
  * ponytail: one eth_call for all of them; page with `appsPage` once the list
128
163
  * outgrows the RPC's eth_call gas cap (tens of thousands of apps).
129
164
  */
130
165
  async allApps() {
131
166
  return this.appsPage(0n, await this.appCount());
132
167
  }
133
- /** The app ids `owner` claimed, oldest first. */
168
+ /** The app ids `owner` claimed (canonical; see `currentAppId`), oldest first. */
134
169
  async appsOf(owner) {
135
170
  return this.read("appsOf", [owner]);
136
171
  }
@@ -142,14 +177,6 @@ var AppRegistryClient = class {
142
177
  async setAppAgentUri(agentUri) {
143
178
  return this.executeWrite("setAppAgentUri", [this.app(), agentUri]);
144
179
  }
145
- /** Send the join fees the caller is still owed, from the old join flow, to `to`. */
146
- async withdrawJoinFees(to = this.senderAddress()) {
147
- return this.executeWrite("withdrawJoinFees", [to]);
148
- }
149
- /** Join fees still owed to `owner` from the old join flow, in USDC base units. Nothing adds to it. */
150
- async joinFeesOwed(owner = this.senderAddress()) {
151
- return this.read("joinFeesOwed", [owner]);
152
- }
153
180
  async isAppSuspended() {
154
181
  return this.read("isAppSuspended", [this.app()]);
155
182
  }
@@ -201,6 +228,9 @@ var AppRegistryClient = class {
201
228
  * `AppAgentChanged` events, oldest first. The last one for an app is its
202
229
  * current card; an empty `agentUri` means the owner unset it.
203
230
  *
231
+ * Events carry the canonical id: `appId` may be any id the app goes by, and
232
+ * each log's `appId` is the canonical one.
233
+ *
204
234
  * Leave `appId` out to list every app that has ever set a card. To list apps,
205
235
  * use `allApps` or `appsOf`, which are one read each; this is a windowed log
206
236
  * scan, for a card's history. `fromBlock` is required because scanning from genesis on an L2 costs
@@ -208,11 +238,12 @@ var AppRegistryClient = class {
208
238
  * a block you know to be before the app's registration.
209
239
  */
210
240
  async getAppAgentLogs(opts) {
241
+ const appId = opts.appId && await this.canonicalAppId(opts.appId);
211
242
  return (await getLogsInWindows(this.publicClient, opts.fromBlock, opts.toBlock, (from, to) => this.publicClient.getContractEvents({
212
243
  address: this.contractAddress,
213
244
  abi: APP_REGISTRY_ABI,
214
245
  eventName: "AppAgentChanged",
215
- args: opts.appId ? { app_id: opts.appId } : {},
246
+ args: appId ? { app_id: appId } : {},
216
247
  fromBlock: from,
217
248
  toBlock: to,
218
249
  strict: true
@@ -27,16 +27,6 @@ declare const DATA_REGISTRY_ABI: readonly [{
27
27
  readonly internalType: "address";
28
28
  }];
29
29
  readonly stateMutability: "view";
30
- }, {
31
- readonly type: "function";
32
- readonly name: "appRegistry";
33
- readonly inputs: readonly [];
34
- readonly outputs: readonly [{
35
- readonly name: "";
36
- readonly type: "address";
37
- readonly internalType: "address";
38
- }];
39
- readonly stateMutability: "view";
40
30
  }, {
41
31
  readonly type: "function";
42
32
  readonly name: "getHead";
@@ -66,10 +56,6 @@ declare const DATA_REGISTRY_ABI: readonly [{
66
56
  readonly name: "admin_";
67
57
  readonly type: "address";
68
58
  readonly internalType: "address";
69
- }, {
70
- readonly name: "appRegistry_";
71
- readonly type: "address";
72
- readonly internalType: "address";
73
59
  }];
74
60
  readonly outputs: readonly [];
75
61
  readonly stateMutability: "nonpayable";
@@ -93,16 +79,6 @@ declare const DATA_REGISTRY_ABI: readonly [{
93
79
  }];
94
80
  readonly outputs: readonly [];
95
81
  readonly stateMutability: "nonpayable";
96
- }, {
97
- readonly type: "function";
98
- readonly name: "setAppRegistry";
99
- readonly inputs: readonly [{
100
- readonly name: "registry";
101
- readonly type: "address";
102
- readonly internalType: "address";
103
- }];
104
- readonly outputs: readonly [];
105
- readonly stateMutability: "nonpayable";
106
82
  }, {
107
83
  readonly type: "function";
108
84
  readonly name: "update";
@@ -31,17 +31,6 @@ const DATA_REGISTRY_ABI = [
31
31
  }],
32
32
  "stateMutability": "view"
33
33
  },
34
- {
35
- "type": "function",
36
- "name": "appRegistry",
37
- "inputs": [],
38
- "outputs": [{
39
- "name": "",
40
- "type": "address",
41
- "internalType": "address"
42
- }],
43
- "stateMutability": "view"
44
- },
45
34
  {
46
35
  "type": "function",
47
36
  "name": "getHead",
@@ -72,10 +61,6 @@ const DATA_REGISTRY_ABI = [
72
61
  "name": "admin_",
73
62
  "type": "address",
74
63
  "internalType": "address"
75
- }, {
76
- "name": "appRegistry_",
77
- "type": "address",
78
- "internalType": "address"
79
64
  }],
80
65
  "outputs": [],
81
66
  "stateMutability": "nonpayable"
@@ -102,17 +87,6 @@ const DATA_REGISTRY_ABI = [
102
87
  "outputs": [],
103
88
  "stateMutability": "nonpayable"
104
89
  },
105
- {
106
- "type": "function",
107
- "name": "setAppRegistry",
108
- "inputs": [{
109
- "name": "registry",
110
- "type": "address",
111
- "internalType": "address"
112
- }],
113
- "outputs": [],
114
- "stateMutability": "nonpayable"
115
- },
116
90
  {
117
91
  "type": "function",
118
92
  "name": "update",
@@ -3,8 +3,6 @@ declare enum PublisherStatus {
3
3
  NONE = 0,
4
4
  ACTIVE = 1,
5
5
  SUSPENDED = 2,
6
- /** Retired: invited under the old join flow and never joined. Not a member. */
7
- INVITED = 3,
8
6
  }
9
7
  //#endregion
10
8
  export { PublisherStatus };
@@ -3,8 +3,6 @@ let PublisherStatus = /* @__PURE__ */ function(PublisherStatus$1) {
3
3
  PublisherStatus$1[PublisherStatus$1["NONE"] = 0] = "NONE";
4
4
  PublisherStatus$1[PublisherStatus$1["ACTIVE"] = 1] = "ACTIVE";
5
5
  PublisherStatus$1[PublisherStatus$1["SUSPENDED"] = 2] = "SUSPENDED";
6
- /** Retired: invited under the old join flow and never joined. Not a member. */
7
- PublisherStatus$1[PublisherStatus$1["INVITED"] = 3] = "INVITED";
8
6
  return PublisherStatus$1;
9
7
  }({});
10
8
 
package/lib/fangorn.d.ts CHANGED
@@ -349,6 +349,16 @@ declare class Fangorn {
349
349
  * from `subscribe`/`subscribeApp` keep their original filter until aborted.
350
350
  */
351
351
  setAppId(nameOrId: string | undefined): void;
352
+ /**
353
+ * Rename this client's app (owner only) — to a name (`"my-app"`) or an app id —
354
+ * and point this client at the new id.
355
+ *
356
+ * Nothing moves on chain: the new id is an alias of the id the app was claimed
357
+ * under, so its publishers, exclusions, subscription and token carry on, and
358
+ * clients still on an old id keep working. The new id must be unclaimed, or one
359
+ * this app already went by (renaming back).
360
+ */
361
+ renameApp(nameOrId: string): Promise<Hash>;
352
362
  getStorage(): MetadataStorage;
353
363
  /**
354
364
  * Swap the storage backend at runtime — e.g. move from access-worker signed
package/lib/fangorn.js CHANGED
@@ -657,6 +657,22 @@ var Fangorn = class Fangorn {
657
657
  this.nsCache.clear();
658
658
  this._feed = null;
659
659
  }
660
+ /**
661
+ * Rename this client's app (owner only) — to a name (`"my-app"`) or an app id —
662
+ * and point this client at the new id.
663
+ *
664
+ * Nothing moves on chain: the new id is an alias of the id the app was claimed
665
+ * under, so its publishers, exclusions, subscription and token carry on, and
666
+ * clients still on an old id keep working. The new id must be unclaimed, or one
667
+ * this app already went by (renaming back).
668
+ */
669
+ async renameApp(nameOrId) {
670
+ const chosen = nonBlank(nameOrId);
671
+ if (!chosen) throw new Error("the new app name must not be blank");
672
+ const txHash = await this.getAppRegistry().renameApp(toAppId(chosen));
673
+ this.setAppId(chosen);
674
+ return txHash;
675
+ }
660
676
  getStorage() {
661
677
  if (!this.ctx.metadataStorage) throw new Error("storage is not configured. Pass { pinata: { ... } } or { signedUrl: { ... } } to Fangorn.create()");
662
678
  return this.ctx.metadataStorage;