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
5 changes: 5 additions & 0 deletions .changeset/sync-sdk-with-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'scope3': major
---

Sync SDK with current OpenAPI specification. Removes stale storefront-only and deprecated resources (agents, billing/storefront, inventory-sources, notifications, readiness, bundles, signals, sales-agents, conversion-events, creative-sets). Adds all missing buyer endpoints (discovery, accounts, planning-briefs, moderation, storefronts, audit-logs, notification-preferences). Replaces typed campaign creation methods with generic create/update/delete. Fixes schema generation regex escaping bug.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scope3",
"version": "2.1.0",
"version": "3.0.0",
"description": "Scope3 SDK - REST and MCP client for the Agentic Platform",
"engines": {
"node": ">=18"
Expand Down
11 changes: 11 additions & 0 deletions scripts/generate-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ function postProcessSchemas(filePath: string) {

content = content.replace(/\\&/g, '&');

// Fix regex literals that break Prettier's parser.
// openapi-zod-client double-escapes backslashes before slashes (e.g. \\/) which Prettier
// interprets as "backslash literal" + "end of regex". Replace \\/ with \/ inside .regex() calls.
content = content.replace(
/\.regex\(\/([^)]+)\/([gimsuy]*)\)/g,
(_match, body: string, flags: string) => {
const fixed = body.replace(/\\\\\//g, '\\/');
return `.regex(/${fixed}/${flags})`;
}
);

// Normalize schema names to PascalCase
const nameRenames: Array<[RegExp, string]> = [];
const namePattern = /^const ([a-z]\w*_\w+|[a-z]\w+) = /gm;
Expand Down
159 changes: 2 additions & 157 deletions src/__tests__/cli/commands/storefront.test.ts
Original file line number Diff line number Diff line change
@@ -1,158 +1,3 @@
import { Command } from 'commander';
import { storefrontCommand } from '../../../cli/commands/storefront';
import * as utils from '../../../cli/utils';
import * as format from '../../../cli/format';

jest.mock('../../../cli/utils');
jest.mock('../../../cli/format');

const mockCreateClient = utils.createClient as jest.MockedFunction<typeof utils.createClient>;
const mockFormatOutput = format.formatOutput as jest.MockedFunction<typeof format.formatOutput>;
const mockPrintError = format.printError as jest.MockedFunction<typeof format.printError>;
const mockPrintSuccess = format.printSuccess as jest.MockedFunction<typeof format.printSuccess>;

describe('storefront command', () => {
let program: Command;
let mockClient: {
storefront: {
get: jest.Mock;
create: jest.Mock;
update: jest.Mock;
delete: jest.Mock;
};
agents: {
list: jest.Mock;
get: jest.Mock;
};
};
const originalExit = process.exit;

beforeEach(() => {
mockClient = {
storefront: {
get: jest.fn(),
create: jest.fn(),
update: jest.fn(),
delete: jest.fn(),
},
agents: {
list: jest.fn(),
get: jest.fn(),
},
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mockCreateClient.mockReturnValue(mockClient as any);
process.exit = jest.fn() as never;

program = new Command();
program.option('--api-key <key>', 'API key');
program.option('--format <format>', 'Output format', 'table');
program.option('--persona <persona>', 'Persona', 'storefront');
program.addCommand(storefrontCommand);
});

afterEach(() => {
jest.restoreAllMocks();
process.exit = originalExit;
});

describe('get', () => {
it('should call client.storefront.get', async () => {
mockClient.storefront.get.mockResolvedValue({
data: { platformId: 'plat-1', name: 'Test' },
});

await program.parseAsync(['node', 'test', 'storefront', 'get', '--api-key', 'sk-test']);

expect(mockClient.storefront.get).toHaveBeenCalled();
expect(mockFormatOutput).toHaveBeenCalled();
});
});

describe('create', () => {
it('should call client.storefront.create with required args', async () => {
mockClient.storefront.create.mockResolvedValue({
data: { platformId: 'plat-1', name: 'My Store' },
});

await program.parseAsync([
'node',
'test',
'storefront',
'create',
'--api-key',
'sk-test',
'--platform-id',
'plat-1',
'--name',
'My Store',
]);

expect(mockClient.storefront.create).toHaveBeenCalledWith(
expect.objectContaining({
platformId: 'plat-1',
name: 'My Store',
})
);
expect(mockPrintSuccess).toHaveBeenCalled();
});
});

describe('delete', () => {
it('should call client.storefront.delete', async () => {
mockClient.storefront.delete.mockResolvedValue(undefined);

await program.parseAsync(['node', 'test', 'storefront', 'delete', '--api-key', 'sk-test']);

expect(mockClient.storefront.delete).toHaveBeenCalled();
expect(mockPrintSuccess).toHaveBeenCalled();
});
});

describe('error handling', () => {
it('should print error and exit on failure', async () => {
mockClient.storefront.get.mockRejectedValue(new Error('Unauthorized'));

await program.parseAsync(['node', 'test', 'storefront', 'get', '--api-key', 'sk-test']);

expect(mockPrintError).toHaveBeenCalledWith('Unauthorized');
expect(process.exit).toHaveBeenCalledWith(1);
});
});

describe('agents subcommand', () => {
it('should call client.agents.list', async () => {
mockClient.agents.list.mockResolvedValue({ data: [] });

await program.parseAsync([
'node',
'test',
'storefront',
'agents',
'list',
'--api-key',
'sk-test',
]);

expect(mockClient.agents.list).toHaveBeenCalled();
expect(mockFormatOutput).toHaveBeenCalled();
});

it('should call client.agents.get with agentId', async () => {
mockClient.agents.get.mockResolvedValue({ data: { id: 'agent-1' } });

await program.parseAsync([
'node',
'test',
'storefront',
'agents',
'get',
'agent-1',
'--api-key',
'sk-test',
]);

expect(mockClient.agents.get).toHaveBeenCalledWith('agent-1');
});
});
describe('removed', () => {
it.todo('resource removed in v3');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the resource is gone, just delete the test file - the describe('removed') placeholder is noise. also 'resource removed in v3' is a temporal reference in code (same issue with the other it.todo stubs across the removed test files)

});
Loading