This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 64fbe9f474 feat: round-3 deep product build-out (69 gaps closed, all 7 products green)
Deep-audit + build-out across all products to fully-usable state; all typecheck clean.

- gitgram-web (99): wire Store feature to real endpoints, close 9 gaps
- gitgram-backend (100): close 8 flow gaps, document infra-provisioning items
- gitgram-mobile (90): fix API base-URL/path mismatch (404s) + copy proximity
  components into components/proximity wired to real screens; 15 gaps, +react-native-svg
- aitm-core (95): wire natural-language CLI flow end-to-end; 11 gaps
- aitm-api (97): fix teams metadata runtime bug; copy a2a-js server/client/grpc
  into src/a2a and wire A2A route; crates.io package search; 8 gaps
- aitm-mcp (100): fix A2A client/server card mismatch; 9 gaps
- aitm-website (95): build missing docs routes; 9 gaps

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 13:54:57 +03:00

140 lines
3.4 KiB
TypeScript

import api from './api';
/**
* Organization domain service.
*
* Wraps the shared axios instance (`services/api.ts`) and targets the backend
* routes mounted at `/api/v1/orgs` (see backend `routes/organizations.ts`).
*
* Backend contract notes:
* - `GET /v1/orgs/:slug` resolves an organization by its slug and returns
* `{ success, data }`, where `data` includes `id`, `name`, `slug`,
* `description`, `memberCount`, `repoCount`.
* - `GET /v1/orgs/:id/members` and `GET /v1/orgs/:id/repositories` are keyed by
* the organization **id** (not the slug) and return paginated
* `{ success, data, meta }` envelopes.
*
* The backend currently exposes no follow or projects endpoints for
* organizations, so this service intentionally does not implement them; the
* screen degrades gracefully where those surfaces would appear.
*/
export type OrgMemberRole = 'owner' | 'admin' | 'member';
export interface OrgUserSummary {
id: string;
username: string;
displayName: string | null;
avatar: string | null;
}
export interface Organization {
id: string;
name: string;
slug: string;
description: string | null;
website: string | null;
location: string | null;
memberCount: number;
repoCount: number;
}
export interface OrgMember {
id: string;
userId: string;
role: OrgMemberRole;
joinedAt: string;
user: OrgUserSummary;
}
export interface OrgRepository {
id: string;
owner: string;
name: string;
fullName: string;
description: string | null;
stars: number;
forks: number;
language: string | null;
ownerAvatar: string | null;
}
export interface PaginationMeta {
total: number;
page: number;
limit: number;
}
export interface PaginatedResult<T> {
items: T[];
meta: PaginationMeta;
}
interface OrgEnvelope {
data?: Organization;
}
interface PaginatedEnvelope<T> {
data?: T[];
meta?: PaginationMeta;
}
const DEFAULT_LIMIT = 20;
function emptyMeta(page: number, limit: number): PaginationMeta {
return { total: 0, page, limit };
}
function toPaginated<T>(
envelope: PaginatedEnvelope<T> | undefined,
page: number,
limit: number,
): PaginatedResult<T> {
return {
items: envelope?.data ?? [],
meta: envelope?.meta ?? emptyMeta(page, limit),
};
}
export const orgService = {
/** Resolve an organization by its slug. */
getOrg: async (slug: string): Promise<Organization | null> => {
const response = await api.get<OrgEnvelope>(`/orgs/${encodeURIComponent(slug)}`);
return response.data.data ?? null;
},
/**
* List repositories owned by an organization. Keyed by the organization id
* (resolve it via {@link getOrg} first).
*/
getOrgRepos: async (
orgId: string,
page = 1,
limit = DEFAULT_LIMIT,
): Promise<PaginatedResult<OrgRepository>> => {
const response = await api.get<PaginatedEnvelope<OrgRepository>>(
`/orgs/${encodeURIComponent(orgId)}/repositories`,
{ params: { page, limit } },
);
return toPaginated(response.data, page, limit);
},
/**
* List members of an organization. Keyed by the organization id (resolve it
* via {@link getOrg} first).
*/
getOrgMembers: async (
orgId: string,
page = 1,
limit = DEFAULT_LIMIT,
): Promise<PaginatedResult<OrgMember>> => {
const response = await api.get<PaginatedEnvelope<OrgMember>>(
`/orgs/${encodeURIComponent(orgId)}/members`,
{ params: { page, limit } },
);
return toPaginated(response.data, page, limit);
},
};
export default orgService;