Skip to content

Commit b2481d6

Browse files
authored
Changed accurateAsOf in Registrar Actions from optional to required (#1907)
1 parent b781245 commit b2481d6

5 files changed

Lines changed: 32 additions & 10 deletions

File tree

.changeset/shy-rabbits-drum.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ensnode/ensnode-sdk": minor
3+
"ensapi": minor
4+
---
5+
6+
Made `accurateAsOf` a required field in the Registrar Actions API response (`RegistrarActionsResponseOk`).

apps/ensapi/src/handlers/api/explore/registrar-actions-api.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ async function fetchRegistrarActions(parentNode: Node | undefined, query: Regist
101101
*/
102102
app.openapi(getRegistrarActionsRoute, async (c) => {
103103
try {
104+
// Defensive: `registrarActionsApiMiddleware` already short-circuits with a
105+
// serialized 503 when indexingStatus is an Error, so this branch is
106+
// unreachable at runtime — kept only for TypeScript type narrowing.
107+
if (c.var.indexingStatus instanceof Error) {
108+
throw new Error("Indexing status has not been loaded yet");
109+
}
110+
111+
// Get the accurateAsOf timestamp from the omnichain indexing cursor
112+
const accurateAsOf = c.var.indexingStatus.snapshot.omnichainSnapshot.omnichainIndexingCursor;
113+
104114
const query = c.req.valid("query");
105115
const { registrarActions, pageContext } = await fetchRegistrarActions(undefined, query);
106116

@@ -110,6 +120,7 @@ app.openapi(getRegistrarActionsRoute, async (c) => {
110120
responseCode: RegistrarActionsResponseCodes.Ok,
111121
registrarActions,
112122
pageContext,
123+
accurateAsOf,
113124
} satisfies RegistrarActionsResponseOk),
114125
);
115126
} catch (error) {
@@ -163,17 +174,20 @@ app.openapi(getRegistrarActionsRoute, async (c) => {
163174
*/
164175
app.openapi(getRegistrarActionsByParentNodeRoute, async (c) => {
165176
try {
177+
// Defensive: `registrarActionsApiMiddleware` already short-circuits with a
178+
// serialized 503 when indexingStatus is an Error, so this branch is
179+
// unreachable at runtime — kept only for TypeScript type narrowing.
166180
if (c.var.indexingStatus instanceof Error) {
167181
throw new Error("Indexing status has not been loaded yet");
168182
}
169183

184+
// Get the accurateAsOf timestamp from the omnichain indexing cursor
185+
const accurateAsOf = c.var.indexingStatus.snapshot.omnichainSnapshot.omnichainIndexingCursor;
186+
170187
const { parentNode } = c.req.valid("param");
171188
const query = c.req.valid("query");
172189
const { registrarActions, pageContext } = await fetchRegistrarActions(parentNode, query);
173190

174-
// Get the accurateAsOf timestamp from the slowest chain indexing cursor
175-
const accurateAsOf = c.var.indexingStatus.snapshot.slowestChainIndexingCursor;
176-
177191
// respond with success response
178192
return c.json(
179193
serializeRegistrarActionsResponse({

packages/ensnode-sdk/src/ensapi/api/registrar-actions/response.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,11 @@ export type RegistrarActionsResponseOk = {
5656
* The {@link UnixTimestamp} of when the data used to build the list of {@link NamedRegistrarAction} was accurate as of.
5757
*
5858
* @remarks
59-
* **Note:** This value represents the `slowestChainIndexingCursor` from the latest omnichain indexing status
59+
* **Note:** This value represents the `omnichainIndexingCursor` from the latest omnichain indexing status
6060
* snapshot captured by ENSApi. The state returned in the response is guaranteed to be accurate as of this
6161
* timestamp but may be from a timestamp higher than this value.
62-
*
63-
* **Temporary:** This field is currently optional to maintain backward compatibility with ENS Awards
64-
* using older snapshot NPM packages. This will be changed to required in a future release.
65-
* See: https://github.com/namehash/ensnode/issues/1497
6662
*/
67-
accurateAsOf?: UnixTimestamp;
63+
accurateAsOf: UnixTimestamp;
6864
};
6965

7066
/**

packages/ensnode-sdk/src/ensapi/api/registrar-actions/zod-schemas.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ describe("ENSNode API Schema", () => {
125125
expect(() => makeRegistrarActionsResponseSchema().parse(validResponseOk)).not.toThrowError();
126126
});
127127

128+
it("rejects ResponseOk object missing required accurateAsOf", () => {
129+
const { accurateAsOf: _accurateAsOf, ...invalidResponseOk } = validResponseOk;
130+
131+
expect(() => makeRegistrarActionsResponseSchema().parse(invalidResponseOk)).toThrowError();
132+
});
133+
128134
it("can parse valid ResponseError object", () => {
129135
const parsed = makeRegistrarActionsResponseSchema().parse(validResponseError);
130136

packages/ensnode-sdk/src/ensapi/api/registrar-actions/zod-schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const makeRegistrarActionsResponseOkSchema = (
4343
responseCode: z.literal(RegistrarActionsResponseCodes.Ok),
4444
registrarActions: z.array(makeNamedRegistrarActionSchema(valueLabel)),
4545
pageContext: makeResponsePageContextSchema(`${valueLabel}.pageContext`),
46-
accurateAsOf: makeUnixTimestampSchema(`${valueLabel}.accurateAsOf`).optional(),
46+
accurateAsOf: makeUnixTimestampSchema(`${valueLabel}.accurateAsOf`),
4747
});
4848

4949
/**

0 commit comments

Comments
 (0)