@ankhorage/infra 1.0.6 → 2.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 (60) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -1
  3. package/dist/adapters/minikube/auth/index.d.ts.map +1 -1
  4. package/dist/adapters/minikube/auth/index.js +13 -1
  5. package/dist/adapters/minikube/auth/index.js.map +1 -1
  6. package/dist/adapters/minikube/auth/oauthRuntime.d.ts +4 -0
  7. package/dist/adapters/minikube/auth/oauthRuntime.d.ts.map +1 -0
  8. package/dist/adapters/minikube/auth/oauthRuntime.js +144 -0
  9. package/dist/adapters/minikube/auth/oauthRuntime.js.map +1 -0
  10. package/dist/adapters/minikube/index.d.ts.map +1 -1
  11. package/dist/adapters/minikube/index.js +15 -6
  12. package/dist/adapters/minikube/index.js.map +1 -1
  13. package/dist/authRedirects.d.ts +19 -0
  14. package/dist/authRedirects.d.ts.map +1 -0
  15. package/dist/authRedirects.js +80 -0
  16. package/dist/authRedirects.js.map +1 -0
  17. package/dist/generatedApiDatabase.d.ts +20 -0
  18. package/dist/generatedApiDatabase.d.ts.map +1 -0
  19. package/dist/generatedApiDatabase.js +343 -0
  20. package/dist/generatedApiDatabase.js.map +1 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/project.d.ts +1 -1
  26. package/dist/project.d.ts.map +1 -1
  27. package/dist/project.js +3 -0
  28. package/dist/project.js.map +1 -1
  29. package/dist/testSupport.d.ts.map +1 -1
  30. package/dist/testSupport.js +1 -0
  31. package/dist/testSupport.js.map +1 -1
  32. package/dist/types.d.ts +1 -1
  33. package/dist/types.d.ts.map +1 -1
  34. package/dist/types.js.map +1 -1
  35. package/package.json +2 -2
  36. package/src/adapters/minikube/auth/index.ts +14 -1
  37. package/src/adapters/minikube/auth/oauthRuntime.ts +169 -0
  38. package/src/adapters/minikube/auth/supabase/oauthRuntime.test.ts +143 -0
  39. package/src/adapters/minikube/auth/supabase/providerAssignments.test.ts +36 -0
  40. package/src/adapters/minikube/index.ts +20 -6
  41. package/src/authRedirects.test.ts +63 -0
  42. package/src/authRedirects.ts +113 -0
  43. package/src/generatedApiDatabase.test.ts +355 -0
  44. package/src/generatedApiDatabase.ts +558 -0
  45. package/src/index.ts +14 -2
  46. package/src/project.ts +3 -1
  47. package/src/testSupport.ts +1 -0
  48. package/src/types.ts +1 -1
  49. package/dist/apiArtifacts.d.ts +0 -8
  50. package/dist/apiArtifacts.d.ts.map +0 -1
  51. package/dist/apiArtifacts.js +0 -35
  52. package/dist/apiArtifacts.js.map +0 -1
  53. package/dist/apis.d.ts +0 -11
  54. package/dist/apis.d.ts.map +0 -1
  55. package/dist/apis.js +0 -354
  56. package/dist/apis.js.map +0 -1
  57. package/src/apiArtifacts.test.ts +0 -54
  58. package/src/apiArtifacts.ts +0 -107
  59. package/src/apis.test.ts +0 -212
  60. package/src/apis.ts +0 -534
package/src/apis.test.ts DELETED
@@ -1,212 +0,0 @@
1
- import type { AppManifest } from '@ankhorage/contracts';
2
- import { describe, expect, test } from 'bun:test';
3
-
4
- import { generateInfrastructure } from './index';
5
- import { createAppManifest } from './testSupport';
6
- import type { InfraManifestInput } from './types';
7
-
8
- describe('API infrastructure generation', () => {
9
- test('generates provider-neutral API, seed, handlers, and OpenAPI artifacts', () => {
10
- const manifest: InfraManifestInput = {
11
- deployment: {
12
- target: 'minikube',
13
- monitoring: false,
14
- },
15
- database: {
16
- provider: 'supabase',
17
- tier: 'dev',
18
- },
19
- plugins: [],
20
- };
21
-
22
- const appManifest: Pick<
23
- AppManifest,
24
- 'data' | 'metadata' | 'navigator' | 'screens' | 'settings'
25
- > = {
26
- metadata: {
27
- name: 'Cards',
28
- slug: 'cards',
29
- version: '1.0.0',
30
- themeId: 'default',
31
- },
32
- data: {
33
- apis: {
34
- poker_situations: {
35
- id: 'poker_situations',
36
- kind: 'generated',
37
- label: 'Poker situations',
38
- description: 'App-owned poker trainer situations.',
39
- basePath: '/api/poker-situations',
40
- preset: 'crud',
41
- resource: {
42
- kind: 'collection',
43
- collection: {
44
- name: 'poker_situations',
45
- primaryKey: 'id',
46
- fields: [
47
- { name: 'id', type: 'uuid', required: true, unique: true },
48
- { name: 'title', type: 'text', required: true },
49
- { name: 'description', type: 'text', required: true },
50
- { name: 'availableActions', type: 'json' },
51
- { name: 'correctAction', type: 'text' },
52
- ],
53
- },
54
- seed: [
55
- {
56
- title: 'Button faces a raise',
57
- description: 'Choose the best action with position and stack depth in mind.',
58
- availableActions: [
59
- { label: 'Fold', value: 'fold' },
60
- { label: 'Call', value: 'call' },
61
- { label: 'Raise', value: 'raise' },
62
- ],
63
- correctAction: 'raise',
64
- },
65
- ],
66
- },
67
- endpoints: [
68
- {
69
- id: 'poker_situations.list',
70
- method: 'GET',
71
- path: '/',
72
- intent: 'list',
73
- },
74
- {
75
- id: 'poker_situations.read',
76
- method: 'GET',
77
- path: '/{id}',
78
- intent: 'read',
79
- },
80
- {
81
- id: 'poker_situations.create',
82
- method: 'POST',
83
- path: '/',
84
- intent: 'create',
85
- },
86
- {
87
- id: 'poker_situations.leaderboard',
88
- method: 'GET',
89
- path: '/leaderboard',
90
- intent: 'custom',
91
- },
92
- ],
93
- },
94
- },
95
- },
96
- navigator: {
97
- type: 'stack',
98
- routes: [],
99
- },
100
- screens: {},
101
- settings: {
102
- localization: {
103
- defaultLocale: 'en',
104
- locales: ['en'],
105
- },
106
- authFlow: {
107
- signInRoute: '/sign-in',
108
- signUpRoute: '/sign-up',
109
- signOutRoute: '/sign-out',
110
- unauthorizedRoute: '/sign-in',
111
- postSignInRoute: '/',
112
- },
113
- },
114
- };
115
-
116
- const result = generateInfrastructure(manifest, { namespaceHint: 'cards', appManifest });
117
- const rerun = generateInfrastructure(manifest, { namespaceHint: 'cards', appManifest });
118
- const paths = result.files.map((file) => file.path);
119
-
120
- expect(result.files).toEqual(rerun.files);
121
- expect(paths).toContain('infra/minikube/db/apis.json');
122
- expect(paths).toContain('infra/minikube/db/api-seed.json');
123
- expect(paths).toContain('infra/minikube/db/migrations/001_apis.sql');
124
- expect(paths).toContain('infra/minikube/db/seeds/001_api_seed.sql');
125
- expect(paths).toContain('infra/minikube/db/README.md');
126
- expect(paths).toContain('src/generated/apis/resources.ts');
127
- expect(paths).toContain('src/generated/apis/appApi.ts');
128
- expect(paths).toContain('src/generated/apis/apiHandlers.ts');
129
- expect(paths).toContain('src/generated/apis/openapi.json');
130
- expect(paths.some((path) => path.includes('datasets'))).toBe(false);
131
-
132
- const resourcesFile = result.files.find(
133
- (file) => file.path === 'src/generated/apis/resources.ts',
134
- );
135
- expect(resourcesFile?.content).toContain('GENERATED_APIS');
136
- expect(resourcesFile?.content).toContain('poker_situations');
137
- expect(resourcesFile?.content).toContain('availableActions');
138
-
139
- const apiFile = result.files.find((file) => file.path === 'src/generated/apis/appApi.ts');
140
- expect(apiFile?.content).toContain('poker_situations.list');
141
- expect(apiFile?.content).toContain('/api/poker-situations');
142
- expect(apiFile?.content).toContain('poker_situations.read');
143
- expect(apiFile?.content).toContain('/api/poker-situations/{id}');
144
- expect(apiFile?.content).toContain('poker_situations.leaderboard');
145
- expect(apiFile?.content).toContain('/api/poker-situations/leaderboard');
146
-
147
- const handlersFile = result.files.find(
148
- (file) => file.path === 'src/generated/apis/apiHandlers.ts',
149
- );
150
- expect(handlersFile?.content).toContain('handleGeneratedApiList');
151
- expect(handlersFile?.content).toContain('handleGeneratedApiCreate');
152
- expect(handlersFile?.content).toContain('createGeneratedApiMemoryStore');
153
- expect(handlersFile?.content).toContain('poker_situations');
154
- expect(handlersFile?.content).not.toContain('Dataset');
155
-
156
- const openApiFile = result.files.find(
157
- (file) => file.path === 'src/generated/apis/openapi.json',
158
- );
159
- expect(openApiFile?.content).toContain('Generated app API');
160
- expect(openApiFile?.content).toContain('poker_situations.create');
161
- expect(openApiFile?.content).toContain('poker_situations.leaderboard');
162
- expect(openApiFile?.content).toContain('x-ankh-api');
163
- expect(openApiFile?.content).not.toContain('x-ankh-dataset');
164
-
165
- const migrationFile = result.files.find(
166
- (file) => file.path === 'infra/minikube/db/migrations/001_apis.sql',
167
- );
168
- expect(migrationFile?.content).toContain('create extension if not exists pgcrypto');
169
- expect(migrationFile?.content).toContain(
170
- 'create table if not exists "public"."poker_situations"',
171
- );
172
- expect(migrationFile?.content).toContain('"id" uuid default gen_random_uuid() primary key');
173
- expect(migrationFile?.content).toContain('"availableActions" jsonb');
174
-
175
- const seedFile = result.files.find((file) => file.path === 'infra/minikube/db/api-seed.json');
176
- expect(seedFile?.content).toContain('Button faces a raise');
177
- expect(seedFile?.content).toContain('correctAction');
178
- expect(seedFile?.content).toContain('"id"');
179
-
180
- const seedSqlFile = result.files.find(
181
- (file) => file.path === 'infra/minikube/db/seeds/001_api_seed.sql',
182
- );
183
- expect(seedSqlFile?.content).toContain('insert into "public"."poker_situations"');
184
- expect(seedSqlFile?.content).toContain('Button faces a raise');
185
- expect(seedSqlFile?.content).toContain('on conflict ("id") do nothing');
186
- });
187
-
188
- test('reports selected state adapter dependencies', () => {
189
- const manifest: InfraManifestInput = {
190
- deployment: {
191
- target: 'minikube',
192
- monitoring: false,
193
- },
194
- state: {
195
- provider: 'legend',
196
- persistence: 'none',
197
- },
198
- plugins: [],
199
- };
200
-
201
- const result = generateInfrastructure(manifest, { appManifest: createAppManifest('cards') });
202
-
203
- expect(result.meta.providers).toContain('legend');
204
- expect(result.dependencies).toEqual([
205
- {
206
- name: '@ankhorage/state-legend',
207
- version: '^0.1.0',
208
- reason: 'Selected by infra.state.provider=legend.',
209
- },
210
- ]);
211
- });
212
- });