Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commands/apps/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default class AppsList extends ControlBaseCommand {
// Mark current app in JSON output
const appsWithCurrentFlag = apps.map((app) => ({
...app,
created: new Date(app.created).toISOString(),
modified: new Date(app.modified).toISOString(),
isCurrent: app.id === currentAppId,
}));

Expand Down
2 changes: 2 additions & 0 deletions src/commands/auth/keys/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export default class KeysCreateCommand extends ControlBaseCommand {
{
key: {
...key,
created: new Date(key.created).toISOString(),
modified: new Date(key.modified).toISOString(),
keyName: `${key.appId}.${key.id}`,
},
},
Expand Down
2 changes: 2 additions & 0 deletions src/commands/auth/keys/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export default class KeysGetCommand extends ControlBaseCommand {
{
key: {
...key,
created: new Date(key.created).toISOString(),
modified: new Date(key.modified).toISOString(),
keyName,
...(hasEnvOverride
? {
Expand Down
2 changes: 2 additions & 0 deletions src/commands/auth/keys/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default class KeysListCommand extends ControlBaseCommand {
const keyName = `${key.appId}.${key.id}`;
return {
...key,
created: new Date(key.created).toISOString(),
modified: new Date(key.modified).toISOString(),
current: keyName === currentKeyName,
keyName, // Add the full key name
};
Expand Down
11 changes: 10 additions & 1 deletion src/commands/channels/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ export default class ChannelsHistory extends AblyBaseCommand {
const lastTimestamp =
messages.length > 0 ? messages.at(-1)!.timestamp : undefined;
const next = buildPaginationNext(hasMore, lastTimestamp);
this.logJsonResult({ messages, hasMore, ...(next && { next }) }, flags);
const jsonMessages = messages.map((msg) => ({
...msg,
timestamp: msg.timestamp
? new Date(msg.timestamp).toISOString()
: undefined,
}));
this.logJsonResult(
{ messages: jsonMessages, hasMore, ...(next && { next }) },
flags,
);
} else {
if (messages.length === 0) {
this.log("No messages found in the channel history.");
Expand Down
11 changes: 10 additions & 1 deletion src/commands/integrations/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,16 @@ export default class IntegrationsCreateCommand extends ControlBaseCommand {
);

if (this.shouldOutputJson(flags)) {
this.logJsonResult({ integration: createdIntegration }, flags);
this.logJsonResult(
{
integration: {
...createdIntegration,
created: new Date(createdIntegration.created).toISOString(),
modified: new Date(createdIntegration.modified).toISOString(),
},
},
flags,
);
} else {
this.log(
formatSuccess(
Expand Down
13 changes: 7 additions & 6 deletions src/commands/integrations/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ export default class IntegrationsGetCommand extends ControlBaseCommand {
const rule = await controlApi.getRule(appId, args.ruleId);

if (this.shouldOutputJson(flags)) {
this.logJsonResult(
{
rule: structuredClone(rule) as unknown as Record<string, unknown>,
},
flags,
);
const ruleClone = structuredClone(rule) as unknown as Record<
string,
unknown
>;
ruleClone.created = new Date(rule.created).toISOString();
ruleClone.modified = new Date(rule.modified).toISOString();
this.logJsonResult({ rule: ruleClone }, flags);
} else {
this.log(formatHeading("Integration Rule Details"));
this.log(`${formatLabel("ID")} ${rule.id}`);
Expand Down
11 changes: 10 additions & 1 deletion src/commands/integrations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ export default class IntegrationsUpdateCommand extends ControlBaseCommand {
);

if (this.shouldOutputJson(flags)) {
this.logJsonResult({ rule: updatedRule }, flags);
this.logJsonResult(
{
rule: {
...updatedRule,
created: new Date(updatedRule.created).toISOString(),
modified: new Date(updatedRule.modified).toISOString(),
},
},
flags,
);
} else {
this.log(formatSuccess("Integration rule updated."));
this.log(`ID: ${updatedRule.id}`);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/rooms/messages/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export default class MessagesHistory extends ChatBaseCommand {
messages: items.map((message) => ({
clientId: message.clientId,
text: message.text,
timestamp: message.timestamp,
timestamp: message.timestamp.toISOString(),
serial: message.serial,
action: String(message.action),
...(message.metadata ? { metadata: message.metadata } : {}),
Expand Down
4 changes: 2 additions & 2 deletions src/commands/rooms/messages/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
interface ChatMessage {
clientId: string;
text: string;
timestamp: number | Date; // Support both timestamp types
timestamp: string;
serial: string;
action: string;
metadata?: Record<string, unknown>;
Expand Down Expand Up @@ -100,7 +100,7 @@ export default class MessagesSubscribe extends ChatBaseCommand {
const messageLog: ChatMessage = {
clientId: message.clientId,
text: message.text,
timestamp: message.timestamp,
timestamp: message.timestamp.toISOString(),
serial: message.serial,
action: String(messageEvent.type),
...(message.metadata ? { metadata: message.metadata } : {}),
Expand Down
8 changes: 5 additions & 3 deletions src/commands/spaces/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
formatHeading,
formatIndex,
formatLabel,
formatMessageTimestamp,
formatProgress,
formatResource,
} from "../../utils/output.js";
Expand Down Expand Up @@ -116,7 +115,10 @@ export default class SpacesGet extends SpacesBaseCommand {
isConnected: action !== "leave" && action !== "absent",
profileData: item.data?.profileUpdate?.current ?? null,
location: item.data?.locationUpdate?.current ?? null,
lastEvent: { name: action, timestamp: item.timestamp },
lastEvent: {
name: action,
timestamp: new Date(item.timestamp).toISOString(),
},
};
});

Expand Down Expand Up @@ -163,7 +165,7 @@ export default class SpacesGet extends SpacesBaseCommand {
` ${formatLabel("Last Event")} ${formatEventType(member.lastEvent.name)}`,
);
this.log(
` ${formatLabel("Event Timestamp")} ${formatMessageTimestamp(member.lastEvent.timestamp)}`,
` ${formatLabel("Event Timestamp")} ${member.lastEvent.timestamp}`,
);
this.log("");
}
Expand Down
2 changes: 1 addition & 1 deletion src/control-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class ControlBaseCommand extends AblyBaseCommand {
}

protected formatDate(timestamp: number): string {
return new Date(timestamp).toLocaleString();
return new Date(timestamp).toISOString();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/utils/spaces-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MemberOutput {
isConnected: boolean;
profileData: Record<string, unknown> | null;
location: unknown | null;
lastEvent: { name: string; timestamp: number };
lastEvent: { name: string; timestamp: string };
}

export interface CursorOutput {
Expand All @@ -30,7 +30,7 @@ export interface LockOutput {
id: string;
status: string;
member: MemberOutput;
timestamp: number;
timestamp: string;
attributes: Record<string, unknown> | null;
reason: { message?: string; code?: number; statusCode?: number } | null;
}
Expand All @@ -51,7 +51,7 @@ export function formatMemberOutput(member: SpaceMember): MemberOutput {
location: member.location ?? null,
lastEvent: {
name: member.lastEvent.name,
timestamp: member.lastEvent.timestamp,
timestamp: new Date(member.lastEvent.timestamp).toISOString(),
},
};
}
Expand All @@ -70,7 +70,7 @@ export function formatLockOutput(lock: Lock): LockOutput {
id: lock.id,
status: lock.status,
member: formatMemberOutput(lock.member),
timestamp: lock.timestamp,
timestamp: new Date(lock.timestamp).toISOString(),
attributes: (lock.attributes as Record<string, unknown>) ?? null,
reason: lock.reason
? {
Expand Down
1 change: 1 addition & 0 deletions test/unit/commands/apps/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe("apps:create command", () => {
expect(stdout).toContain(newAppId);
expect(stdout).toContain(mockAppName);
expect(stdout).toContain("Automatically switched to app");
expect(stdout).toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/);
});

it("should create an app with TLS only flag", async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/unit/commands/apps/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ describe("apps:list command", () => {
"550e8400-e29b-41d4-a716-446655440001",
);
expect(result.apps[1]).toHaveProperty("name", "Test App 2");
expect(result.apps[0].created).toBe("2022-01-01T00:00:00.000Z");
expect(result.apps[0].modified).toBe("2022-01-01T00:00:00.000Z");
});

it("should handle empty apps list", async () => {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/commands/auth/keys/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ describe("auth:keys:create command", () => {
expect(result.key).toHaveProperty("id", mockKeyId);
expect(result.key).toHaveProperty("name", "TestKey");
expect(result.key).toHaveProperty("key");
expect(result.key.created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.key.modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});

it("should use ABLY_ACCESS_TOKEN environment variable when provided", async () => {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/commands/auth/keys/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ describe("auth:keys:get command", () => {
expect(result).toHaveProperty("success", true);
expect(result).toHaveProperty("key");
expect(result.key).toHaveProperty("id", mockKeyId);
expect(result.key.created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.key.modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});

it("should show warning when fetched key is current and ABLY_API_KEY env var overrides it", async () => {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/commands/auth/keys/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ describe("auth:keys:list command", () => {
expect(result).toHaveProperty("keys");
expect(result.keys).toHaveLength(1);
expect(result.keys[0]).toHaveProperty("name", "Test Key");
expect(result.keys[0].created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.keys[0].modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});
});

Expand Down
1 change: 1 addition & 0 deletions test/unit/commands/channels/history.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ describe("channels:history command", () => {
expect(messages[0]).toHaveProperty("name", "test-event");
expect(messages[0]).toHaveProperty("data");
expect(messages[0].data).toEqual({ text: "Hello world" });
expect(messages[0].timestamp).toBe("2023-11-14T22:13:20.000Z");
});
});

Expand Down
16 changes: 16 additions & 0 deletions test/unit/commands/integrations/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ describe("integrations:create command", () => {
url: "https://example.com/webhook",
},
status: "disabled",
created: 1640995200000,
modified: 1640995200000,
});

const { stdout } = await runCommand(
Expand Down Expand Up @@ -159,6 +161,8 @@ describe("integrations:create command", () => {
url: "https://example.com/webhook",
},
status: "enabled",
created: 1640995200000,
modified: 1640995200000,
});

const { stdout } = await runCommand(
Expand Down Expand Up @@ -202,6 +206,8 @@ describe("integrations:create command", () => {
format: "json",
},
status: "enabled",
created: 1640995200000,
modified: 1640995200000,
});

const { stdout } = await runCommand(
Expand All @@ -227,6 +233,12 @@ describe("integrations:create command", () => {
expect(result).toHaveProperty("integration");
expect(result.integration).toHaveProperty("id", mockRuleId);
expect(result.integration).toHaveProperty("ruleType", "http");
expect(result.integration.created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.integration.modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});
});

Expand Down Expand Up @@ -352,6 +364,8 @@ describe("integrations:create command", () => {
url: "https://example.com/webhook",
},
status: "enabled",
created: 1640995200000,
modified: 1640995200000,
});

const { stdout } = await runCommand(
Expand Down Expand Up @@ -392,6 +406,8 @@ describe("integrations:create command", () => {
url: "https://example.com/webhook",
},
status: "enabled",
created: 1640995200000,
modified: 1640995200000,
});

const { stdout } = await runCommand(
Expand Down
6 changes: 6 additions & 0 deletions test/unit/commands/integrations/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ describe("integrations:get command", () => {
expect(result.rule).toHaveProperty("ruleType", "http");
expect(result.rule).toHaveProperty("source");
expect(result.rule.source).toHaveProperty("type", "channel.message");
expect(result.rule.created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.rule.modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});

it("should output pretty JSON when --pretty-json flag is used", async () => {
Expand Down
6 changes: 6 additions & 0 deletions test/unit/commands/integrations/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ describe("integrations:update command", () => {
expect(result).toHaveProperty("success", true);
expect(result).toHaveProperty("rule");
expect(result.rule).toHaveProperty("id", mockRuleId);
expect(result.rule.created).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
expect(result.rule.modified).toMatch(
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/,
);
});

it("should update request mode", async () => {
Expand Down
Loading