@ysk-kit/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/dist/add-capability.d.ts +4 -0
  3. package/dist/add-capability.d.ts.map +1 -0
  4. package/dist/add-capability.js +104 -0
  5. package/dist/add-capability.js.map +1 -0
  6. package/dist/add-module.d.ts +5 -0
  7. package/dist/add-module.d.ts.map +1 -0
  8. package/dist/add-module.js +210 -0
  9. package/dist/add-module.js.map +1 -0
  10. package/dist/agent-stubs.d.ts +3 -0
  11. package/dist/agent-stubs.d.ts.map +1 -0
  12. package/dist/agent-stubs.js +25 -0
  13. package/dist/agent-stubs.js.map +1 -0
  14. package/dist/apply-capability.d.ts +3 -0
  15. package/dist/apply-capability.d.ts.map +1 -0
  16. package/dist/apply-capability.js +189 -0
  17. package/dist/apply-capability.js.map +1 -0
  18. package/dist/capability-catalog.d.ts +25 -0
  19. package/dist/capability-catalog.d.ts.map +1 -0
  20. package/dist/capability-catalog.js +123 -0
  21. package/dist/capability-catalog.js.map +1 -0
  22. package/dist/capability-patches.d.ts +40 -0
  23. package/dist/capability-patches.d.ts.map +1 -0
  24. package/dist/capability-patches.js +616 -0
  25. package/dist/capability-patches.js.map +1 -0
  26. package/dist/check-agent.d.ts +9 -0
  27. package/dist/check-agent.d.ts.map +1 -0
  28. package/dist/check-agent.js +85 -0
  29. package/dist/check-agent.js.map +1 -0
  30. package/dist/generate-openapi.d.ts +2 -0
  31. package/dist/generate-openapi.d.ts.map +1 -0
  32. package/dist/generate-openapi.js +52 -0
  33. package/dist/generate-openapi.js.map +1 -0
  34. package/dist/help.d.ts +2 -0
  35. package/dist/help.d.ts.map +1 -0
  36. package/dist/help.js +54 -0
  37. package/dist/help.js.map +1 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.d.ts.map +1 -0
  40. package/dist/index.js +59 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/merge-prisma.d.ts +15 -0
  43. package/dist/merge-prisma.d.ts.map +1 -0
  44. package/dist/merge-prisma.js +90 -0
  45. package/dist/merge-prisma.js.map +1 -0
  46. package/dist/patch-text.d.ts +17 -0
  47. package/dist/patch-text.d.ts.map +1 -0
  48. package/dist/patch-text.js +72 -0
  49. package/dist/patch-text.js.map +1 -0
  50. package/dist/upgrade.d.ts +16 -0
  51. package/dist/upgrade.d.ts.map +1 -0
  52. package/dist/upgrade.js +110 -0
  53. package/dist/upgrade.js.map +1 -0
  54. package/package.json +41 -0
  55. package/templates/agent/skills/add-capability/SKILL.md +8 -0
  56. package/templates/agent/skills/add-module/SKILL.md +8 -0
  57. package/templates/agent/skills/envelope-api/SKILL.md +8 -0
  58. package/templates/agent/skills/fix-layers/SKILL.md +8 -0
  59. package/templates/agent/skills/new-product/SKILL.md +8 -0
  60. package/templates/agent/skills/verify-change/SKILL.md +8 -0
  61. package/templates/agent/ysk-kit.mdc +6 -0
  62. package/templates/capabilities/billing/apps/api/src/modules/billing/application/billing-service.ts +140 -0
  63. package/templates/capabilities/billing/apps/api/src/modules/billing/domain/billing-port.ts +23 -0
  64. package/templates/capabilities/billing/apps/api/src/modules/billing/domain/subscription-repository.ts +22 -0
  65. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/billing-router.ts +85 -0
  66. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/billing.app.test.ts +273 -0
  67. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/log-billing.ts +31 -0
  68. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/memory-subscription-repository.ts +27 -0
  69. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/prisma-subscription-repository.ts +52 -0
  70. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/stripe-billing.test.ts +127 -0
  71. package/templates/capabilities/billing/apps/api/src/modules/billing/infra/stripe-billing.ts +160 -0
  72. package/templates/capabilities/billing/apps/web/src/features/orgs/billing-page.tsx +183 -0
  73. package/templates/capabilities/billing/packages/contracts/src/api/billing.ts +85 -0
  74. package/templates/capabilities/billing/packages/contracts/src/dto/billing.ts +59 -0
  75. package/templates/capabilities/billing/packages/sdk/src/resources/billing.ts +38 -0
  76. package/templates/capabilities/billing/packages/web-sdk/src/billing-hooks.ts +56 -0
  77. package/templates/capabilities/llm/apps/api/src/modules/llm/application/llm-service.ts +48 -0
  78. package/templates/capabilities/llm/apps/api/src/modules/llm/domain/usage-repository.ts +10 -0
  79. package/templates/capabilities/llm/apps/api/src/modules/llm/infra/llm-router.ts +88 -0
  80. package/templates/capabilities/llm/apps/api/src/modules/llm/infra/llm.app.test.ts +89 -0
  81. package/templates/capabilities/llm/apps/api/src/modules/llm/infra/memory-usage-repository.ts +13 -0
  82. package/templates/capabilities/llm/apps/api/src/modules/llm/infra/prisma-usage-repository.ts +17 -0
  83. package/templates/capabilities/llm/apps/web/src/features/llm/llm-page.tsx +53 -0
  84. package/templates/capabilities/llm/packages/contracts/src/api/llm.ts +26 -0
  85. package/templates/capabilities/llm/packages/contracts/src/dto/llm.ts +33 -0
  86. package/templates/capabilities/llm/packages/sdk/src/resources/llm.ts +68 -0
  87. package/templates/capabilities/llm/packages/web-sdk/src/llm-hooks.ts +12 -0
  88. package/templates/capabilities/push/apps/api/src/modules/devices/application/device-service.ts +42 -0
  89. package/templates/capabilities/push/apps/api/src/modules/devices/domain/device-repository.ts +22 -0
  90. package/templates/capabilities/push/apps/api/src/modules/devices/infra/device-router.ts +42 -0
  91. package/templates/capabilities/push/apps/api/src/modules/devices/infra/device.app.test.ts +34 -0
  92. package/templates/capabilities/push/apps/api/src/modules/devices/infra/memory-device-repository.ts +33 -0
  93. package/templates/capabilities/push/apps/api/src/modules/devices/infra/prisma-device-repository.ts +42 -0
  94. package/templates/capabilities/push/apps/mobile/src/adapters/push.ts +21 -0
  95. package/templates/capabilities/push/packages/contracts/src/api/devices.ts +33 -0
  96. package/templates/capabilities/push/packages/contracts/src/dto/device.ts +18 -0
  97. package/templates/capabilities/push/packages/sdk/src/resources/devices.ts +10 -0
  98. package/templates/capabilities/team/apps/api/src/modules/organizations/application/organization-service.ts +272 -0
  99. package/templates/capabilities/team/apps/api/src/modules/organizations/domain/organization-repository.ts +58 -0
  100. package/templates/capabilities/team/apps/api/src/modules/organizations/infra/memory-organization-repository.ts +141 -0
  101. package/templates/capabilities/team/apps/api/src/modules/organizations/infra/organization-router.ts +130 -0
  102. package/templates/capabilities/team/apps/api/src/modules/organizations/infra/organization.app.test.ts +213 -0
  103. package/templates/capabilities/team/apps/api/src/modules/organizations/infra/prisma-organization-repository.ts +142 -0
  104. package/templates/capabilities/team/apps/mobile/src/screens/invite-screen.tsx +40 -0
  105. package/templates/capabilities/team/apps/mobile/src/screens/org-detail-screen.tsx +154 -0
  106. package/templates/capabilities/team/apps/mobile/src/screens/orgs-screen.tsx +53 -0
  107. package/templates/capabilities/team/apps/web/src/features/orgs/invite-page.tsx +77 -0
  108. package/templates/capabilities/team/apps/web/src/features/orgs/org-detail-page.tsx +138 -0
  109. package/templates/capabilities/team/apps/web/src/features/orgs/orgs-page.tsx +73 -0
  110. package/templates/capabilities/team/packages/contracts/src/api/organizations.ts +154 -0
  111. package/templates/capabilities/team/packages/contracts/src/dto/organization.ts +58 -0
  112. package/templates/capabilities/team/packages/sdk/src/resources/organizations.ts +53 -0
  113. package/templates/capabilities/team/packages/web-sdk/src/organizations-hooks.ts +80 -0
  114. package/templates/module/api.ts.tmpl +32 -0
  115. package/templates/module/application-service.ts.tmpl +9 -0
  116. package/templates/module/domain-repository.ts.tmpl +15 -0
  117. package/templates/module/dto.ts.tmpl +21 -0
  118. package/templates/module/memory-repository.ts.tmpl +36 -0
  119. package/templates/module/model.prisma.tmpl +8 -0
  120. package/templates/module/prisma-repository.ts.tmpl +38 -0
  121. package/templates/module/router.ts.tmpl +32 -0
  122. package/templates/module/sdk-resource.ts.tmpl +17 -0
  123. package/templates/module/service.test.ts.tmpl +33 -0
  124. package/templates/module/web-hooks.ts.tmpl +24 -0
  125. package/templates/module/web-page.tsx.tmpl +69 -0
@@ -0,0 +1,38 @@
1
+ import { slicePage } from '@ysk-kit/application';
2
+ import type { I{{pascal}}Repository } from '../domain/{{kebab}}-repository';
3
+ import type { PrismaClient } from '../../../generated/prisma/client';
4
+
5
+ const toDto = (row: {
6
+ id: string;
7
+ title: string;
8
+ body: string;
9
+ authorId: string;
10
+ createdAt: Date;
11
+ updatedAt: Date;
12
+ }) => ({
13
+ id: row.id,
14
+ title: row.title,
15
+ body: row.body,
16
+ authorId: row.authorId,
17
+ createdAt: row.createdAt.toISOString(),
18
+ updatedAt: row.updatedAt.toISOString(),
19
+ });
20
+
21
+ export const createPrisma{{pascal}}Repository = (prisma: PrismaClient): I{{pascal}}Repository => ({
22
+ async create(authorId, input) {
23
+ const row = await prisma.{{camel}}.create({
24
+ data: { title: input.title, body: input.body, authorId },
25
+ });
26
+ return toDto(row);
27
+ },
28
+ async listForAuthor(authorId, query) {
29
+ const rows = await prisma.{{camel}}.findMany({
30
+ where: { authorId },
31
+ orderBy: { createdAt: 'desc' },
32
+ take: query.limit + 1,
33
+ ...(query.cursor ? { cursor: { id: query.cursor }, skip: 1 } : {}),
34
+ });
35
+ const page = slicePage(rows, query.limit);
36
+ return { items: page.items.map(toDto), nextCursor: page.nextCursor };
37
+ },
38
+ });
@@ -0,0 +1,32 @@
1
+ import { type HttpHandler, mountContract } from '@ysk-kit/api-express';
2
+ import { appContract, type Create{{pascal}}Command, type PageQuery } from '@ysk-kit/contracts';
3
+ import { AppError } from '@ysk-kit/domain-kernel';
4
+ import type { Express } from 'express';
5
+ import type { {{pascal}}Service } from '../application/{{kebab}}-service';
6
+
7
+ export const {{camel}}Handlers = (service: {{pascal}}Service): Record<string, HttpHandler> => ({
8
+ list: {
9
+ auth: 'required',
10
+ handle: async ({ query, auth }) => {
11
+ if (!auth) throw new AppError('UNAUTHENTICATED');
12
+ return {
13
+ status: 200,
14
+ body: { ok: true, data: await service.list(auth.sub, query as PageQuery) },
15
+ };
16
+ },
17
+ },
18
+ create: {
19
+ auth: 'required',
20
+ handle: async ({ body, auth }) => {
21
+ if (!auth) throw new AppError('UNAUTHENTICATED');
22
+ return {
23
+ status: 201,
24
+ body: { ok: true, data: await service.create(auth.sub, body as Create{{pascal}}Command) },
25
+ };
26
+ },
27
+ },
28
+ });
29
+
30
+ export const register{{pascal}}Routes = (app: Express, service: {{pascal}}Service): void => {
31
+ mountContract(app, appContract.{{camel}}, {{camel}}Handlers(service));
32
+ };
@@ -0,0 +1,17 @@
1
+ import type { Create{{pascal}}Command, Paginated{{pascal}}, {{pascal}}Dto } from '@ysk-kit/contracts';
2
+ import type { HttpClient } from '../http';
3
+
4
+ const toQuery = (query?: { cursor?: string; limit?: number }): string => {
5
+ const params = new URLSearchParams();
6
+ if (query?.cursor) params.set('cursor', query.cursor);
7
+ if (query?.limit) params.set('limit', String(query.limit));
8
+ const encoded = params.toString();
9
+ return encoded.length > 0 ? `?${encoded}` : '';
10
+ };
11
+
12
+ export const {{camel}}Resource = (http: HttpClient) => ({
13
+ list: (query?: { cursor?: string; limit?: number }) =>
14
+ http.request<Paginated{{pascal}}>(`/v1/{{kebab}}${toQuery(query)}`),
15
+ create: (body: Create{{pascal}}Command) =>
16
+ http.request<{{pascal}}Dto>('/v1/{{kebab}}', { method: 'POST', body: JSON.stringify(body) }),
17
+ });
@@ -0,0 +1,33 @@
1
+ import request from 'supertest';
2
+ import { describe, expect, it } from 'vitest';
3
+ import { createApp } from '../../../app';
4
+ import { createMemoryInput } from '../../../create-memory-input';
5
+ import { create{{pascal}}Service } from '../application/{{kebab}}-service';
6
+ import { createMemory{{pascal}}Repository } from './memory-{{kebab}}-repository';
7
+
8
+ describe('{{kebab}} service', () => {
9
+ it('creates and lists rows for the author', async () => {
10
+ const service = create{{pascal}}Service(createMemory{{pascal}}Repository());
11
+ const created = await service.create('11111111-1111-1111-1111-111111111111', {
12
+ title: 'Hello',
13
+ body: 'World',
14
+ });
15
+ expect(created.title).toBe('Hello');
16
+ expect(created.body).toBe('World');
17
+ const page = await service.list('11111111-1111-1111-1111-111111111111', { limit: 20 });
18
+ expect(page.items).toHaveLength(1);
19
+ expect(page.items[0]?.id).toBe(created.id);
20
+ const other = await service.list('22222222-2222-2222-2222-222222222222', { limit: 20 });
21
+ expect(other.items).toHaveLength(0);
22
+ });
23
+ });
24
+
25
+ describe('{{kebab}} HTTP', () => {
26
+ it('returns UNAUTHENTICATED without a session', async () => {
27
+ const mem = createMemoryInput();
28
+ const app = createApp(mem.input);
29
+ const res = await request(app).post('/v1/{{kebab}}').send({ title: 'Hello', body: 'World' });
30
+ expect(res.status).toBe(401);
31
+ expect(res.body).toMatchObject({ ok: false, error: { code: 'UNAUTHENTICATED' } });
32
+ });
33
+ });
@@ -0,0 +1,24 @@
1
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import type { Create{{pascal}}Command } from '@ysk-kit/contracts';
3
+ import type { YskClient } from '@ysk-kit/sdk';
4
+
5
+ export const {{camel}}QueryKey = ['{{kebab}}'] as const;
6
+
7
+ export function create{{pascal}}Hooks(client: YskClient) {
8
+ return {
9
+ useList: (query?: { cursor?: string; limit?: number }) =>
10
+ useQuery({
11
+ queryKey: [...{{camel}}QueryKey, query],
12
+ queryFn: () => client.{{camel}}.list(query),
13
+ }),
14
+ useCreate: () => {
15
+ const qc = useQueryClient();
16
+ return useMutation({
17
+ mutationFn: (body: Create{{pascal}}Command) => client.{{camel}}.create(body),
18
+ onSuccess: () => {
19
+ void qc.invalidateQueries({ queryKey: {{camel}}QueryKey });
20
+ },
21
+ });
22
+ },
23
+ };
24
+ }
@@ -0,0 +1,69 @@
1
+ import { Create{{pascal}}CommandSchema } from '@ysk-kit/contracts';
2
+ import { Button, Input, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@ysk-kit/ui';
3
+ import { create{{pascal}}Hooks } from '@ysk-kit/web-sdk';
4
+ import { type FormEvent, useState } from 'react';
5
+ import { api } from '../../lib/client';
6
+
7
+ const hooks = create{{pascal}}Hooks(api);
8
+
9
+ export function {{pascal}}Page() {
10
+ const list = hooks.useList();
11
+ const create = hooks.useCreate();
12
+ const [title, setTitle] = useState('');
13
+ const [body, setBody] = useState('');
14
+ const [formError, setFormError] = useState<string | null>(null);
15
+
16
+ const onSubmit = (event: FormEvent) => {
17
+ event.preventDefault();
18
+ const parsed = Create{{pascal}}CommandSchema.safeParse({ title, body });
19
+ if (!parsed.success) {
20
+ setFormError(parsed.error.issues[0]?.message ?? 'Invalid');
21
+ return;
22
+ }
23
+ create.mutate(parsed.data, {
24
+ onSuccess: () => {
25
+ setTitle('');
26
+ setBody('');
27
+ setFormError(null);
28
+ },
29
+ onError: (error) => setFormError(error.message),
30
+ });
31
+ };
32
+
33
+ return (
34
+ <section className="space-y-4">
35
+ <h1 className="text-2xl font-semibold">{{pascal}}</h1>
36
+ {list.error ? <p className="text-sm text-red-600">{list.error.message}</p> : null}
37
+ {formError ? <p className="text-sm text-red-600">{formError}</p> : null}
38
+ <form onSubmit={onSubmit} className="grid max-w-md gap-3">
39
+ <label className="grid gap-1 text-sm" htmlFor="{{kebab}}-title">
40
+ Title
41
+ <Input id="{{kebab}}-title" value={title} onChange={(e) => setTitle(e.target.value)} required />
42
+ </label>
43
+ <label className="grid gap-1 text-sm" htmlFor="{{kebab}}-body">
44
+ Body
45
+ <Input id="{{kebab}}-body" value={body} onChange={(e) => setBody(e.target.value)} />
46
+ </label>
47
+ <Button type="submit" disabled={create.isPending}>
48
+ Create
49
+ </Button>
50
+ </form>
51
+ <Table>
52
+ <TableHeader>
53
+ <TableRow>
54
+ <TableHead>Title</TableHead>
55
+ <TableHead>Body</TableHead>
56
+ </TableRow>
57
+ </TableHeader>
58
+ <TableBody>
59
+ {(list.data?.items ?? []).map((item) => (
60
+ <TableRow key={item.id}>
61
+ <TableCell>{item.title}</TableCell>
62
+ <TableCell>{item.body}</TableCell>
63
+ </TableRow>
64
+ ))}
65
+ </TableBody>
66
+ </Table>
67
+ </section>
68
+ );
69
+ }