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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

## [2.8.0] - 2026-09-22

### Added
- `AccountResult.organization`: the organization the API key belongs to, as
`{ id, name }`, with the exported `OrganizationInfo` type. The plan, the
credits and the prepaid balance `account.get()` reports are that
organization's. The field is optional: check it before reading `id` or `name`.

Nothing was removed or renamed.

## [2.7.1] - 2026-09-19

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ console.log(account.usage.creditsLimit) // 5000 (Starter 5K)
console.log(account.usage.prepaidBalance) // 12.5
console.log(account.usage.prepaidBalanceCurrency) // 'USD'
console.log(account.apiKey.totalRequests) // 1234
console.log(account.organization?.name) // 'Acme Prints'
```

An account is funded either by a subscription allowance or by a prepaid balance,
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sudomock",
"version": "2.7.1",
"version": "2.8.0",
"description": "Official Node.js/TypeScript SDK for the SudoMock API - mockup generation from PSD files",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export type {
SubscriptionInfo,
UsageInfo,
ApiKeyInfo,
OrganizationInfo,
CreateSessionParams,
SessionResult,
StudioSessionUi,
Expand Down
10 changes: 10 additions & 0 deletions src/resources/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ export class AccountResource {
lastUsedAt: result.apiKey.lastUsedAt,
totalRequests: result.apiKey.totalRequests,
},
// Same allowlist rule as `usage` above: without this block the API's
// `organization` is dropped without a trace. Left out, not defaulted,
// when the API does not send it, so the optional type stays honest
// against a deployment that predates the field.
...(result.organization && {
organization: {
id: result.organization.id,
name: result.organization.name,
},
}),
}
}
}
13 changes: 13 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,24 @@ export interface ApiKeyInfo {
totalRequests: number
}

export interface OrganizationInfo {
/** Organization UUID. */
id: string
name: string
}

export interface AccountResult {
account: AccountInfo
subscription: SubscriptionInfo
usage: UsageInfo
apiKey: ApiKeyInfo
/**
* The organization the API key belongs to. The plan, the credits and the
* prepaid balance on this result are that organization's.
*
* Optional: check it before reading `id` or `name`.
*/
organization?: OrganizationInfo
}

// ---------------------------------------------------------------------------
Expand Down
39 changes: 38 additions & 1 deletion tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
ConnectionError,
TimeoutError,
} from '../src/errors'
import { TEST_API_KEY, TEST_BASE_URL, server } from './setup'
import {
MOCK_ACCOUNT_RESPONSE,
TEST_API_KEY,
TEST_BASE_URL,
server,
} from './setup'

function createClient(overrides: Record<string, unknown> = {}) {
return new SudoMock(TEST_API_KEY, { baseUrl: TEST_BASE_URL, ...overrides })
Expand Down Expand Up @@ -348,6 +353,38 @@ describe('case conversion', () => {
})
})

// ---------------------------------------------------------------------------
// Account allowlist
// ---------------------------------------------------------------------------

describe('account', () => {
// account.get() rebuilds the response key by key, so a block the map does not
// name vanishes without an error. That shipped once (CHANGELOG 2.5.1).
it('surfaces organization when the API sends it', async () => {
server.use(
http.get(`${TEST_BASE_URL}/api/v1/me`, () =>
HttpResponse.json({
...MOCK_ACCOUNT_RESPONSE,
data: {
...MOCK_ACCOUNT_RESPONSE.data,
organization: {
id: '55555555-5555-5555-5555-555555555555',
name: 'Test Organization',
private_state: 'internal',
},
},
}),
),
)

const result = await createClient().account.get()
expect(result.organization).toEqual({
id: '55555555-5555-5555-5555-555555555555',
name: 'Test Organization',
})
})
})

// ---------------------------------------------------------------------------
// Error hierarchy
// ---------------------------------------------------------------------------
Expand Down
Loading