@ankhorage/contracts 0.0.4 → 0.1.2

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # @ankhorage/contracts
2
+
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - fc2928d: update publish config to 'public' access
8
+
9
+ ## 0.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 7075528: add repository metadata
14
+
15
+ ## 0.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 07b8da7: Add shared auth and database adapter contracts.
20
+
21
+ ### Patch Changes
22
+
23
+ - 5c800d8: add missing script
24
+
25
+ ## 0.0.4
26
+
27
+ ### Patch Changes
28
+
29
+ - Refresh the README copy so the published package overview and usage example stay aligned with the current messaging.
30
+
31
+ ## 0.0.3
32
+
33
+ ### Patch Changes
34
+
35
+ - 908b4de: Export `APP_CATEGORIES` and `AppCategory` so template packages can consume the shared category contract instead of redefining it.
36
+
37
+ ## 0.0.2
38
+
39
+ ### Patch Changes
40
+
41
+ - 2c2e771: Migrate to @ankhorage/devtools for shared ESLint and Prettier configuration.
package/README.md CHANGED
@@ -1,20 +1,63 @@
1
1
  # contracts
2
2
 
3
- Shared type definitions for applications.
3
+ Shared public contracts for Ankhorage packages and standalone provider packages.
4
4
 
5
5
  ## 🎯 What you get
6
+
6
7
  - Strongly typed app structures
7
- - Clear contracts between systems
8
+ - Serializable schemas for app manifests and UI definitions
9
+ - Provider-neutral runtime contracts for auth and database adapters
10
+ - Clear contracts between systems without depending on framework internals
8
11
 
9
12
  ## ✨ Features
10
- - Serializable schemas
11
- - App manifests
12
- - UI definitions
13
+
14
+ - Serializable app, action, theme, infra, and auth config contracts
15
+ - UI and navigation definitions
16
+ - Auth adapter contracts using `signIn`, `signUp`, and `signOut` naming
17
+ - Database adapter contracts for provider-neutral CRUD-style access
18
+ - Dedicated subpath exports for focused imports
13
19
 
14
20
  ## 📦 Usage
21
+
15
22
  ```ts
16
- import { AppManifest } from '@ankhorage/contracts'
23
+ import type { AppManifest } from '@ankhorage/contracts';
24
+ import type { AuthAdapter } from '@ankhorage/contracts/auth';
25
+ import type { DbAdapter } from '@ankhorage/contracts/db';
26
+ ```
27
+
28
+ Provider packages can implement the shared contracts without importing runtime,
29
+ CLI, ZORA, Expo Router, or app-generation logic.
30
+
31
+ ```ts
32
+ import type { AuthAdapter } from '@ankhorage/contracts/auth';
33
+
34
+ export function createSupabaseAuthAdapter(): AuthAdapter {
35
+ return {
36
+ async signIn(input) {
37
+ return {
38
+ ok: true,
39
+ data: {
40
+ accessToken: `token:${input.identifier.value}`,
41
+ user: { id: 'user-1', email: input.identifier.value },
42
+ },
43
+ };
44
+ },
45
+ async signUp(input) {
46
+ return { ok: true, data: { id: 'user-1', email: input.identifier.value } };
47
+ },
48
+ async signOut() {
49
+ return { ok: true };
50
+ },
51
+ async getSession() {
52
+ return { ok: true, data: null };
53
+ },
54
+ };
55
+ }
17
56
  ```
18
57
 
19
58
  ## 🧠 Why this exists
20
- Separates data contracts from implementation.
59
+
60
+ Contracts separates shared data and runtime contracts from implementation details.
61
+ Standalone packages such as Supabase, Clerk, or database providers can depend on
62
+ these contracts while staying independent from Ankhorage app generation,
63
+ runtime, CLI, and UI packages.
package/dist/auth.d.ts ADDED
@@ -0,0 +1,78 @@
1
+ export type AuthIdentifierKind = 'email' | 'phone' | 'username';
2
+ export interface AuthIdentifier {
3
+ kind: AuthIdentifierKind;
4
+ value: string;
5
+ }
6
+ export interface AuthUser {
7
+ id: string;
8
+ email?: string;
9
+ phone?: string;
10
+ username?: string;
11
+ displayName?: string;
12
+ avatarUrl?: string;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ export interface AuthSession {
16
+ accessToken: string;
17
+ refreshToken?: string;
18
+ expiresAt?: number;
19
+ tokenType?: string;
20
+ user: AuthUser;
21
+ }
22
+ export interface AuthAdapterError {
23
+ code: string;
24
+ message: string;
25
+ cause?: unknown;
26
+ }
27
+ export type AuthResult<TData = void> = {
28
+ ok: true;
29
+ data?: TData;
30
+ } | {
31
+ ok: false;
32
+ error: AuthAdapterError;
33
+ };
34
+ export interface SignInInput {
35
+ identifier: AuthIdentifier;
36
+ password?: string;
37
+ otp?: string;
38
+ redirectTo?: string;
39
+ metadata?: Record<string, unknown>;
40
+ }
41
+ export interface SignUpInput {
42
+ identifier: AuthIdentifier;
43
+ password?: string;
44
+ profile?: Record<string, unknown>;
45
+ redirectTo?: string;
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+ export interface SignOutInput {
49
+ allDevices?: boolean;
50
+ }
51
+ export interface PasswordResetInput {
52
+ identifier: AuthIdentifier;
53
+ redirectTo?: string;
54
+ }
55
+ export interface VerifyOtpInput {
56
+ identifier: AuthIdentifier;
57
+ token: string;
58
+ redirectTo?: string;
59
+ metadata?: Record<string, unknown>;
60
+ }
61
+ export interface AuthAdapterCapabilities {
62
+ signInIdentifiers: AuthIdentifierKind[];
63
+ supportsSignUp: boolean;
64
+ supportsPasswordReset: boolean;
65
+ supportsOtp: boolean;
66
+ supportsSessionRefresh: boolean;
67
+ }
68
+ export interface AuthAdapter {
69
+ readonly capabilities?: AuthAdapterCapabilities;
70
+ signIn(input: SignInInput): Promise<AuthResult<AuthSession>>;
71
+ signUp(input: SignUpInput): Promise<AuthResult<AuthSession | AuthUser>>;
72
+ signOut(input?: SignOutInput): Promise<AuthResult>;
73
+ getSession(): Promise<AuthResult<AuthSession | null>>;
74
+ refreshSession?(): Promise<AuthResult<AuthSession | null>>;
75
+ requestPasswordReset?(input: PasswordResetInput): Promise<AuthResult>;
76
+ verifyOtp?(input: VerifyOtpInput): Promise<AuthResult<AuthSession>>;
77
+ }
78
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,OAA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OAAO,CAAC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC;IAE3D,oBAAoB,CAAC,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACtE,SAAS,CAAC,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;CACrE"}
package/dist/auth.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"","sourcesContent":["export type AuthIdentifierKind = 'email' | 'phone' | 'username';\n\nexport interface AuthIdentifier {\n kind: AuthIdentifierKind;\n value: string;\n}\n\nexport interface AuthUser {\n id: string;\n email?: string;\n phone?: string;\n username?: string;\n displayName?: string;\n avatarUrl?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface AuthSession {\n accessToken: string;\n refreshToken?: string;\n expiresAt?: number;\n tokenType?: string;\n user: AuthUser;\n}\n\nexport interface AuthAdapterError {\n code: string;\n message: string;\n cause?: unknown;\n}\n\nexport type AuthResult<TData = void> =\n | {\n ok: true;\n data?: TData;\n }\n | {\n ok: false;\n error: AuthAdapterError;\n };\n\nexport interface SignInInput {\n identifier: AuthIdentifier;\n password?: string;\n otp?: string;\n redirectTo?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface SignUpInput {\n identifier: AuthIdentifier;\n password?: string;\n profile?: Record<string, unknown>;\n redirectTo?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface SignOutInput {\n allDevices?: boolean;\n}\n\nexport interface PasswordResetInput {\n identifier: AuthIdentifier;\n redirectTo?: string;\n}\n\nexport interface VerifyOtpInput {\n identifier: AuthIdentifier;\n token: string;\n redirectTo?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface AuthAdapterCapabilities {\n signInIdentifiers: AuthIdentifierKind[];\n supportsSignUp: boolean;\n supportsPasswordReset: boolean;\n supportsOtp: boolean;\n supportsSessionRefresh: boolean;\n}\n\nexport interface AuthAdapter {\n readonly capabilities?: AuthAdapterCapabilities;\n\n signIn(input: SignInInput): Promise<AuthResult<AuthSession>>;\n signUp(input: SignUpInput): Promise<AuthResult<AuthSession | AuthUser>>;\n signOut(input?: SignOutInput): Promise<AuthResult>;\n\n getSession(): Promise<AuthResult<AuthSession | null>>;\n refreshSession?(): Promise<AuthResult<AuthSession | null>>;\n\n requestPasswordReset?(input: PasswordResetInput): Promise<AuthResult>;\n verifyOtp?(input: VerifyOtpInput): Promise<AuthResult<AuthSession>>;\n}\n"]}
package/dist/db.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ export type DbRecord = Record<string, unknown>;
2
+ export type DbSortDirection = 'asc' | 'desc';
3
+ export interface DbAdapterError {
4
+ code: string;
5
+ message: string;
6
+ cause?: unknown;
7
+ }
8
+ export type DbResult<TData = void> = {
9
+ ok: true;
10
+ data?: TData;
11
+ } | {
12
+ ok: false;
13
+ error: DbAdapterError;
14
+ };
15
+ export interface DbSort {
16
+ field: string;
17
+ direction?: DbSortDirection;
18
+ }
19
+ export interface DbPage {
20
+ limit?: number;
21
+ offset?: number;
22
+ }
23
+ export type DbFilterOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'contains' | 'startsWith' | 'endsWith';
24
+ export interface DbFilter {
25
+ field: string;
26
+ operator: DbFilterOperator;
27
+ value: unknown;
28
+ }
29
+ export interface DbSelectInput {
30
+ table: string;
31
+ columns?: string[];
32
+ filters?: DbFilter[];
33
+ sort?: DbSort[];
34
+ page?: DbPage;
35
+ }
36
+ export interface DbFindByIdInput {
37
+ table: string;
38
+ id: string | number;
39
+ columns?: string[];
40
+ }
41
+ export interface DbInsertInput<TRecord extends object = DbRecord> {
42
+ table: string;
43
+ values: TRecord | TRecord[];
44
+ }
45
+ export interface DbUpdateInput<TRecord extends object = DbRecord> {
46
+ table: string;
47
+ values: Partial<TRecord>;
48
+ filters: DbFilter[];
49
+ }
50
+ export interface DbDeleteInput {
51
+ table: string;
52
+ filters: DbFilter[];
53
+ }
54
+ export interface DbAdapterCapabilities {
55
+ supportsTransactions: boolean;
56
+ supportsReturning: boolean;
57
+ supportsRealtime: boolean;
58
+ }
59
+ export interface DbAdapter {
60
+ readonly capabilities?: DbAdapterCapabilities;
61
+ select<TRecord extends object = DbRecord>(input: DbSelectInput): Promise<DbResult<TRecord[]>>;
62
+ findById<TRecord extends object = DbRecord>(input: DbFindByIdInput): Promise<DbResult<TRecord | null>>;
63
+ insert<TRecord extends object = DbRecord>(input: DbInsertInput<TRecord>): Promise<DbResult<TRecord[]>>;
64
+ update<TRecord extends object = DbRecord>(input: DbUpdateInput<TRecord>): Promise<DbResult<TRecord[]>>;
65
+ delete<TRecord extends object = DbRecord>(input: DbDeleteInput): Promise<DbResult<TRecord[]>>;
66
+ transaction?<TResult>(run: (adapter: DbAdapter) => Promise<TResult>): Promise<DbResult<TResult>>;
67
+ }
68
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC/C,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,MAAM,QAAQ,CAAC,KAAK,GAAG,IAAI,IAC7B;IACE,EAAE,EAAE,IAAI,CAAC;IACT,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,GACD;IACE,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,cAAc,CAAC;CACvB,CAAC;AAEN,MAAM,WAAW,MAAM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"","sources":["../src/db.ts"],"names":[],"mappings":"","sourcesContent":["export type DbRecord = Record<string, unknown>;\nexport type DbSortDirection = 'asc' | 'desc';\n\nexport interface DbAdapterError {\n code: string;\n message: string;\n cause?: unknown;\n}\n\nexport type DbResult<TData = void> =\n | {\n ok: true;\n data?: TData;\n }\n | {\n ok: false;\n error: DbAdapterError;\n };\n\nexport interface DbSort {\n field: string;\n direction?: DbSortDirection;\n}\n\nexport interface DbPage {\n limit?: number;\n offset?: number;\n}\n\nexport type DbFilterOperator =\n | 'eq'\n | 'neq'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte'\n | 'in'\n | 'contains'\n | 'startsWith'\n | 'endsWith';\n\nexport interface DbFilter {\n field: string;\n operator: DbFilterOperator;\n value: unknown;\n}\n\nexport interface DbSelectInput {\n table: string;\n columns?: string[];\n filters?: DbFilter[];\n sort?: DbSort[];\n page?: DbPage;\n}\n\nexport interface DbFindByIdInput {\n table: string;\n id: string | number;\n columns?: string[];\n}\n\nexport interface DbInsertInput<TRecord extends object = DbRecord> {\n table: string;\n values: TRecord | TRecord[];\n}\n\nexport interface DbUpdateInput<TRecord extends object = DbRecord> {\n table: string;\n values: Partial<TRecord>;\n filters: DbFilter[];\n}\n\nexport interface DbDeleteInput {\n table: string;\n filters: DbFilter[];\n}\n\nexport interface DbAdapterCapabilities {\n supportsTransactions: boolean;\n supportsReturning: boolean;\n supportsRealtime: boolean;\n}\n\nexport interface DbAdapter {\n readonly capabilities?: DbAdapterCapabilities;\n\n select<TRecord extends object = DbRecord>(input: DbSelectInput): Promise<DbResult<TRecord[]>>;\n findById<TRecord extends object = DbRecord>(\n input: DbFindByIdInput,\n ): Promise<DbResult<TRecord | null>>;\n insert<TRecord extends object = DbRecord>(\n input: DbInsertInput<TRecord>,\n ): Promise<DbResult<TRecord[]>>;\n update<TRecord extends object = DbRecord>(\n input: DbUpdateInput<TRecord>,\n ): Promise<DbResult<TRecord[]>>;\n delete<TRecord extends object = DbRecord>(input: DbDeleteInput): Promise<DbResult<TRecord[]>>;\n\n transaction?<TResult>(run: (adapter: DbAdapter) => Promise<TResult>): Promise<DbResult<TResult>>;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './auth';
2
+ export * from './db';
1
3
  export * from './types';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './auth';
2
+ export * from './db';
1
3
  export * from './types';
2
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC","sourcesContent":["export * from './auth';\nexport * from './db';\nexport * from './types';\n"]}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyFA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAU,CAAC;AAGpE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,eAAe;IACf,uBAAuB;IACvB,iBAAiB;IACjB,oBAAoB;IACpB,qBAAqB;IACrB,eAAe;IACf,YAAY;IACZ,OAAO;IACP,iBAAiB;IACjB,gBAAgB;IAChB,aAAa;IACb,W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AoB,GAAG,CAAC,YAAY,EAAE,qBAAqB,CAAU,CAAC;AAGnF,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,GAAG,sBAAsB;IACzB,WAAW;IACX,UAAU;IACV,aAAa;IACb,WAAW;CACH,CAAC","sourcesContent":["export type ColorHarmony =\n | 'monochromatic'\n | 'analogous'\n | 'complementary'\n | 'triadic'\n | 'tetradic'\n | 'splitComplementary';\n\nexport type SystemTone = 'neutral' | 'pastel' | 'earth' | 'jewel' | 'fluorescent';\n\nexport interface ThemeModeConfig {\n primaryColor: string;\n harmony: ColorHarmony;\n systemTone: SystemTone;\n}\n\nexport interface ThemeConfig {\n id: string;\n name: string;\n light: ThemeModeConfig;\n dark: ThemeModeConfig;\n}\n\nexport type ActionType =\n | 'navigate'\n | 'alert'\n | 'console'\n | 'toggleDarkMode'\n | 'setLanguage'\n | 'search'\n | 'filter';\n\nexport interface NavigateAction {\n type: 'navigate';\n payload: {\n route: string;\n params?: Record<string, number | string>;\n };\n}\n\nexport interface AlertAction {\n type: 'alert';\n payload?: {\n message?: string;\n };\n}\n\nexport interface ConsoleAction {\n type: 'console';\n payload?: Record<string, unknown>;\n}\n\nexport interface ToggleDarkModeAction {\n type: 'toggleDarkMode';\n payload?: never;\n}\n\nexport interface SetLanguageAction {\n type: 'setLanguage';\n payload: {\n locale: string;\n };\n}\n\nexport interface SearchAction {\n type: 'search';\n payload: {\n query: string;\n scope?: string;\n };\n}\n\nexport interface FilterAction {\n type: 'filter';\n payload: {\n filterKey: string;\n filterValue: string;\n };\n}\n\nexport type Action =\n | AlertAction\n | ConsoleAction\n | FilterAction\n | NavigateAction\n | SearchAction\n | SetLanguageAction\n | ToggleDarkModeAction;\n\nexport const NAVIGATOR_TYPES = ['stack', 'tabs', 'drawer'] as const;\nexport type NavigatorType = (typeof NAVIGATOR_TYPES)[number];\n\nexport const APP_CATEGORIES = [\n 'books_reading',\n 'business_productivity',\n 'developer_tools',\n 'education_learning',\n 'entertainment_media',\n 'finance_money',\n 'food_drink',\n 'games',\n 'graphics_design',\n 'health_fitness',\n 'kids_family',\n 'lifestyle',\n 'medical',\n 'music_audio',\n 'navigation_travel',\n 'news_magazines',\n 'photo_video',\n 'reference',\n 'shopping_commerce',\n 'social_community',\n 'sports',\n 'utilities_tools',\n 'weather',\n] as const;\nexport type AppCategory = (typeof APP_CATEGORIES)[number];\n\nexport const DEPLOYMENT_TARGETS = ['minikube'] as const;\nexport type KnownDeploymentTarget = (typeof DEPLOYMENT_TARGETS)[number];\nexport type DeploymentTarget = KnownDeploymentTarget | (string & {});\n\nexport const DATABASE_PROVIDERS = ['supabase'] as const;\nexport type KnownDatabaseProvider = (typeof DATABASE_PROVIDERS)[number];\nexport type DatabaseProvider = KnownDatabaseProvider | (string & {});\n\nexport const DATABASE_TIERS = ['dev', 'prod'] as const;\nexport type DatabaseTier = (typeof DATABASE_TIERS)[number];\n\nexport const STORAGE_PROVIDERS = ['auto', 's3', 'r2'] as const;\nexport type StorageProvider = (typeof STORAGE_PROVIDERS)[number];\n\nexport const AUTHZ_KINDS = ['RBAC', 'ABAC'] as const;\nexport type AuthzKind = (typeof AUTHZ_KINDS)[number];\n\nexport const AUTHZ_ENGINES = ['cerbos', 'native'] as const;\nexport type AuthzEngine = (typeof AUTHZ_ENGINES)[number];\n\nexport const AUTH_SCOPES = ['global', 'none', 'integrated'] as const;\nexport type AuthScope = (typeof AUTH_SCOPES)[number];\n\nexport const AUTH_PROVIDERS = ['supabase'] as const;\nexport type KnownAuthProvider = (typeof AUTH_PROVIDERS)[number];\nexport type AuthProvider = KnownAuthProvider | (string & {});\n\nexport const AUTH_LOGIN_IDENTIFIERS = ['email', 'username', 'phone'] as const;\nexport type AuthLoginIdentifier = (typeof AUTH_LOGIN_IDENTIFIERS)[number];\n\nexport const AUTH_REGISTRATION_FIELDS = [\n ...AUTH_LOGIN_IDENTIFIERS,\n 'password',\n 'firstName',\n 'lastName',\n 'displayName',\n 'avatarUrl',\n] as const;\nexport type KnownAuthRegistrationField = (typeof AUTH_REGISTRATION_FIELDS)[number];\nexport type AuthRegistrationField = KnownAuthRegistrationField | (string & {});\n\nexport const AUTH_SIGNUP_POLICIES = ['autoSignIn', 'requireVerification'] as const;\nexport type AuthSignupPolicy = (typeof AUTH_SIGNUP_POLICIES)[number];\n\nexport const AUTH_PROFILE_FIELDS = [\n ...AUTH_LOGIN_IDENTIFIERS,\n 'firstName',\n 'lastName',\n 'displayName',\n 'avatarUrl',\n] as const;\nexport type KnownAuthProfileField = (typeof AUTH_PROFILE_FIELDS)[number];\nexport type AuthProfileField = KnownAuthProfileField | (string & {});\n\nexport interface IconSpec {\n name: string;\n provider?: string;\n size?: number | string;\n color?: string;\n}\n\nexport interface UiNode {\n id: string;\n type: string;\n alias?: string;\n props?: Record<string, unknown>;\n children?: UiNode[];\n style?: Record<string, number | string>;\n}\n\nexport interface ScreenSpec {\n id: string;\n name: string;\n title?: string;\n description?: string;\n root: UiNode;\n}\n\nexport interface NavigatorSpec {\n type: NavigatorType;\n initialRouteName?: string;\n routes: RouteDefinition[];\n options?: Record<string, unknown>;\n}\n\nexport interface RouteDefinition {\n name: string;\n path?: string;\n label?: string;\n icon?: IconSpec;\n hideInTabBar?: boolean;\n guards?: string[];\n screenId?: string;\n navigator?: NavigatorSpec;\n}\n\nexport interface DeploymentSpec {\n target: DeploymentTarget;\n monitoring: boolean;\n}\n\nexport interface DatabaseSpec {\n provider: DatabaseProvider;\n tier: DatabaseTier;\n}\n\nexport interface StorageSpec {\n provider: StorageProvider;\n buckets: string[];\n}\n\nexport interface AuthzSpec {\n kind: AuthzKind;\n engine: AuthzEngine;\n}\n\nexport interface AuthLoginSpec {\n identifiers: AuthLoginIdentifier[];\n}\n\nexport interface AuthRegistrationSpec {\n requiredFields: AuthRegistrationField[];\n optionalFields?: AuthRegistrationField[];\n signupPolicy?: AuthSignupPolicy;\n}\n\nexport interface AuthProfileSpec {\n fields: AuthProfileField[];\n}\n\nexport interface AuthSpec {\n scope: AuthScope;\n provider: AuthProvider;\n authorization: AuthzSpec;\n login?: AuthLoginSpec;\n registration?: AuthRegistrationSpec;\n profile?: AuthProfileSpec;\n}\n\nexport interface NetworkingSpec {\n domain?: string;\n cdn: boolean;\n}\n\nexport interface InfraManifest {\n deployment?: DeploymentSpec;\n auth?: AuthSpec;\n database?: DatabaseSpec;\n storage?: StorageSpec;\n networking?: NetworkingSpec;\n plugins: string[];\n pluginsConfig?: Record<string, unknown>;\n}\n\nexport interface AppManifest {\n metadata: {\n name: string;\n slug: string;\n version: string;\n themeId: string;\n created?: string;\n updated?: string;\n };\n themes: ThemeConfig[];\n activeThemeId: string;\n activeThemeMode?: 'dark' | 'light';\n infra: InfraManifest;\n navigator: NavigatorSpec;\n screens: Record<string, ScreenSpec>;\n settings: {\n apiBaseUrl?: string;\n localization: {\n defaultLocale: string;\n locales: string[];\n };\n authFlow: {\n loginRoute: string;\n unauthorizedRoute: string;\n postLoginRoute: string;\n };\n };\n}\n"]}
package/package.json CHANGED
@@ -1,37 +1,60 @@
1
1
  {
2
2
  "name": "@ankhorage/contracts",
3
- "type": "module",
4
- "version": "0.0.4",
5
- "description": "Serializable app, action, and theme config contracts for Ankhorage.",
3
+ "version": "0.1.2",
6
4
  "main": "./dist/index.js",
7
- "sideEffects": false,
8
- "types": "./dist/index.d.ts",
9
- "files": [
10
- "dist"
11
- ],
5
+ "devDependencies": {
6
+ "@ankhorage/devtools": "^1.0.0",
7
+ "@changesets/cli": "^2.30.0",
8
+ "@types/bun": "^1.3.13",
9
+ "@types/node": "^25.2.3",
10
+ "typescript": "^5.9.3"
11
+ },
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
15
  "default": "./dist/index.js"
16
+ },
17
+ "./auth": {
18
+ "types": "./dist/auth.d.ts",
19
+ "default": "./dist/auth.js"
20
+ },
21
+ "./db": {
22
+ "types": "./dist/db.d.ts",
23
+ "default": "./dist/db.js"
16
24
  }
17
25
  },
26
+ "description": "Serializable app, action, and theme config contracts for Ankhorage.",
27
+ "files": [
28
+ "dist",
29
+ "src",
30
+ "package.json",
31
+ "README.md",
32
+ "CHANGELOG.md",
33
+ "LICENSE"
34
+ ],
35
+ "packageManager": "bun@1.3.13",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/ankhorage/contracts"
39
+ },
40
+ "homepage": "https://github.com/ankhorage/contracts#readme",
41
+ "bugs": {
42
+ "url": "https://github.com/ankhorage/contracts/issues"
43
+ },
18
44
  "scripts": {
19
45
  "build": "rm -rf dist tsconfig.tsbuildinfo && bun x tsc -p tsconfig.json",
20
46
  "lint": "eslint . --max-warnings=0",
21
47
  "lint:fix": "eslint . --fix --max-warnings=0",
22
48
  "format": "prettier --write .",
23
49
  "format:check": "prettier --check .",
24
- "test": "bun test src"
50
+ "test": "bun test src",
51
+ "version-packages": "changeset version"
25
52
  },
26
- "devDependencies": {
27
- "@ankhorage/devtools": "^1.0.0",
28
- "@changesets/cli": "^2.30.0",
29
- "@types/bun": "^1.3.11",
30
- "@types/node": "^25.2.3",
31
- "typescript": "^5.9.3"
53
+ "sideEffects": false,
54
+ "type": "module",
55
+ "types": "./dist/index.d.ts",
56
+ "publishConfig": {
57
+ "access": "public"
32
58
  },
33
- "packageManager": "bun@1.3.11",
34
- "dependencies": {
35
- "bun": "^1.3.11"
36
- }
59
+ "license": "MIT"
37
60
  }
package/src/auth.ts ADDED
@@ -0,0 +1,94 @@
1
+ export type AuthIdentifierKind = 'email' | 'phone' | 'username';
2
+
3
+ export interface AuthIdentifier {
4
+ kind: AuthIdentifierKind;
5
+ value: string;
6
+ }
7
+
8
+ export interface AuthUser {
9
+ id: string;
10
+ email?: string;
11
+ phone?: string;
12
+ username?: string;
13
+ displayName?: string;
14
+ avatarUrl?: string;
15
+ metadata?: Record<string, unknown>;
16
+ }
17
+
18
+ export interface AuthSession {
19
+ accessToken: string;
20
+ refreshToken?: string;
21
+ expiresAt?: number;
22
+ tokenType?: string;
23
+ user: AuthUser;
24
+ }
25
+
26
+ export interface AuthAdapterError {
27
+ code: string;
28
+ message: string;
29
+ cause?: unknown;
30
+ }
31
+
32
+ export type AuthResult<TData = void> =
33
+ | {
34
+ ok: true;
35
+ data?: TData;
36
+ }
37
+ | {
38
+ ok: false;
39
+ error: AuthAdapterError;
40
+ };
41
+
42
+ export interface SignInInput {
43
+ identifier: AuthIdentifier;
44
+ password?: string;
45
+ otp?: string;
46
+ redirectTo?: string;
47
+ metadata?: Record<string, unknown>;
48
+ }
49
+
50
+ export interface SignUpInput {
51
+ identifier: AuthIdentifier;
52
+ password?: string;
53
+ profile?: Record<string, unknown>;
54
+ redirectTo?: string;
55
+ metadata?: Record<string, unknown>;
56
+ }
57
+
58
+ export interface SignOutInput {
59
+ allDevices?: boolean;
60
+ }
61
+
62
+ export interface PasswordResetInput {
63
+ identifier: AuthIdentifier;
64
+ redirectTo?: string;
65
+ }
66
+
67
+ export interface VerifyOtpInput {
68
+ identifier: AuthIdentifier;
69
+ token: string;
70
+ redirectTo?: string;
71
+ metadata?: Record<string, unknown>;
72
+ }
73
+
74
+ export interface AuthAdapterCapabilities {
75
+ signInIdentifiers: AuthIdentifierKind[];
76
+ supportsSignUp: boolean;
77
+ supportsPasswordReset: boolean;
78
+ supportsOtp: boolean;
79
+ supportsSessionRefresh: boolean;
80
+ }
81
+
82
+ export interface AuthAdapter {
83
+ readonly capabilities?: AuthAdapterCapabilities;
84
+
85
+ signIn(input: SignInInput): Promise<AuthResult<AuthSession>>;
86
+ signUp(input: SignUpInput): Promise<AuthResult<AuthSession | AuthUser>>;
87
+ signOut(input?: SignOutInput): Promise<AuthResult>;
88
+
89
+ getSession(): Promise<AuthResult<AuthSession | null>>;
90
+ refreshSession?(): Promise<AuthResult<AuthSession | null>>;
91
+
92
+ requestPasswordReset?(input: PasswordResetInput): Promise<AuthResult>;
93
+ verifyOtp?(input: VerifyOtpInput): Promise<AuthResult<AuthSession>>;
94
+ }
@@ -0,0 +1,147 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+
3
+ import {
4
+ APP_CATEGORIES,
5
+ type AppCategory,
6
+ AUTH_PROVIDERS,
7
+ type AuthAdapter,
8
+ type DbAdapter,
9
+ DEPLOYMENT_TARGETS,
10
+ NAVIGATOR_TYPES,
11
+ type SignInInput,
12
+ type ThemeConfig,
13
+ } from './index';
14
+
15
+ describe('contracts', () => {
16
+ it('exports stable platform constants', () => {
17
+ expect(NAVIGATOR_TYPES).toEqual(['stack', 'tabs', 'drawer']);
18
+ expect(APP_CATEGORIES).toEqual([
19
+ 'books_reading',
20
+ 'business_productivity',
21
+ 'developer_tools',
22
+ 'education_learning',
23
+ 'entertainment_media',
24
+ 'finance_money',
25
+ 'food_drink',
26
+ 'games',
27
+ 'graphics_design',
28
+ 'health_fitness',
29
+ 'kids_family',
30
+ 'lifestyle',
31
+ 'medical',
32
+ 'music_audio',
33
+ 'navigation_travel',
34
+ 'news_magazines',
35
+ 'photo_video',
36
+ 'reference',
37
+ 'shopping_commerce',
38
+ 'social_community',
39
+ 'sports',
40
+ 'utilities_tools',
41
+ 'weather',
42
+ ]);
43
+ expect(DEPLOYMENT_TARGETS).toEqual(['minikube']);
44
+ expect(AUTH_PROVIDERS).toEqual(['supabase']);
45
+ });
46
+
47
+ it('exports the app category union for template packages', () => {
48
+ const category: AppCategory = 'developer_tools';
49
+ expect(category).toBe('developer_tools');
50
+ });
51
+
52
+ it('accepts the current serialized theme config shape', () => {
53
+ const theme: ThemeConfig = {
54
+ id: 'theme-default',
55
+ name: 'Default',
56
+ light: {
57
+ primaryColor: '#3366ff',
58
+ harmony: 'analogous',
59
+ systemTone: 'neutral',
60
+ },
61
+ dark: {
62
+ primaryColor: '#3366ff',
63
+ harmony: 'analogous',
64
+ systemTone: 'neutral',
65
+ },
66
+ };
67
+
68
+ expect(theme.light.primaryColor).toBe('#3366ff');
69
+ expect(theme.dark.systemTone).toBe('neutral');
70
+ });
71
+
72
+ it('accepts provider-neutral auth and db adapter implementations', async () => {
73
+ const authAdapter: AuthAdapter = {
74
+ capabilities: {
75
+ signInIdentifiers: ['email'],
76
+ supportsSignUp: true,
77
+ supportsPasswordReset: true,
78
+ supportsOtp: false,
79
+ supportsSessionRefresh: true,
80
+ },
81
+ async signIn(input: SignInInput) {
82
+ await new Promise((resolve) => setTimeout(resolve, 1));
83
+ return {
84
+ ok: true,
85
+ data: {
86
+ accessToken: `token:${input.identifier.value}`,
87
+ user: {
88
+ id: 'user-1',
89
+ email: input.identifier.value,
90
+ },
91
+ },
92
+ };
93
+ },
94
+ async signUp(input) {
95
+ await new Promise((resolve) => setTimeout(resolve, 1));
96
+ return {
97
+ ok: true,
98
+ data: {
99
+ id: 'user-1',
100
+ email: input.identifier.value,
101
+ },
102
+ };
103
+ },
104
+ async signOut() {
105
+ await new Promise((resolve) => setTimeout(resolve, 1));
106
+ return { ok: true };
107
+ },
108
+ async getSession() {
109
+ await new Promise((resolve) => setTimeout(resolve, 1));
110
+ return { ok: true, data: null };
111
+ },
112
+ };
113
+
114
+ const dbAdapter: DbAdapter = {
115
+ async select() {
116
+ await new Promise((resolve) => setTimeout(resolve, 1));
117
+ return { ok: true, data: [{ id: 'row-1' }] };
118
+ },
119
+ async findById() {
120
+ await new Promise((resolve) => setTimeout(resolve, 1));
121
+ return { ok: true, data: { id: 'row-1' } };
122
+ },
123
+ async insert(input) {
124
+ const values = Array.isArray(input.values) ? input.values : [input.values];
125
+ await new Promise((resolve) => setTimeout(resolve, 1));
126
+ return { ok: true, data: values };
127
+ },
128
+ async update(input) {
129
+ await new Promise((resolve) => setTimeout(resolve, 1));
130
+ return { ok: true, data: [input.values] };
131
+ },
132
+ async delete() {
133
+ await new Promise((resolve) => setTimeout(resolve, 1));
134
+ return { ok: true, data: [] };
135
+ },
136
+ } as DbAdapter;
137
+
138
+ const signInResult = await authAdapter.signIn({
139
+ identifier: { kind: 'email', value: 'hello@example.com' },
140
+ password: 'secret',
141
+ });
142
+ const selectResult = await dbAdapter.select({ table: 'profiles' });
143
+
144
+ expect(signInResult.ok).toBe(true);
145
+ expect(selectResult.ok).toBe(true);
146
+ });
147
+ });
package/src/db.ts ADDED
@@ -0,0 +1,100 @@
1
+ export type DbRecord = Record<string, unknown>;
2
+ export type DbSortDirection = 'asc' | 'desc';
3
+
4
+ export interface DbAdapterError {
5
+ code: string;
6
+ message: string;
7
+ cause?: unknown;
8
+ }
9
+
10
+ export type DbResult<TData = void> =
11
+ | {
12
+ ok: true;
13
+ data?: TData;
14
+ }
15
+ | {
16
+ ok: false;
17
+ error: DbAdapterError;
18
+ };
19
+
20
+ export interface DbSort {
21
+ field: string;
22
+ direction?: DbSortDirection;
23
+ }
24
+
25
+ export interface DbPage {
26
+ limit?: number;
27
+ offset?: number;
28
+ }
29
+
30
+ export type DbFilterOperator =
31
+ | 'eq'
32
+ | 'neq'
33
+ | 'gt'
34
+ | 'gte'
35
+ | 'lt'
36
+ | 'lte'
37
+ | 'in'
38
+ | 'contains'
39
+ | 'startsWith'
40
+ | 'endsWith';
41
+
42
+ export interface DbFilter {
43
+ field: string;
44
+ operator: DbFilterOperator;
45
+ value: unknown;
46
+ }
47
+
48
+ export interface DbSelectInput {
49
+ table: string;
50
+ columns?: string[];
51
+ filters?: DbFilter[];
52
+ sort?: DbSort[];
53
+ page?: DbPage;
54
+ }
55
+
56
+ export interface DbFindByIdInput {
57
+ table: string;
58
+ id: string | number;
59
+ columns?: string[];
60
+ }
61
+
62
+ export interface DbInsertInput<TRecord extends object = DbRecord> {
63
+ table: string;
64
+ values: TRecord | TRecord[];
65
+ }
66
+
67
+ export interface DbUpdateInput<TRecord extends object = DbRecord> {
68
+ table: string;
69
+ values: Partial<TRecord>;
70
+ filters: DbFilter[];
71
+ }
72
+
73
+ export interface DbDeleteInput {
74
+ table: string;
75
+ filters: DbFilter[];
76
+ }
77
+
78
+ export interface DbAdapterCapabilities {
79
+ supportsTransactions: boolean;
80
+ supportsReturning: boolean;
81
+ supportsRealtime: boolean;
82
+ }
83
+
84
+ export interface DbAdapter {
85
+ readonly capabilities?: DbAdapterCapabilities;
86
+
87
+ select<TRecord extends object = DbRecord>(input: DbSelectInput): Promise<DbResult<TRecord[]>>;
88
+ findById<TRecord extends object = DbRecord>(
89
+ input: DbFindByIdInput,
90
+ ): Promise<DbResult<TRecord | null>>;
91
+ insert<TRecord extends object = DbRecord>(
92
+ input: DbInsertInput<TRecord>,
93
+ ): Promise<DbResult<TRecord[]>>;
94
+ update<TRecord extends object = DbRecord>(
95
+ input: DbUpdateInput<TRecord>,
96
+ ): Promise<DbResult<TRecord[]>>;
97
+ delete<TRecord extends object = DbRecord>(input: DbDeleteInput): Promise<DbResult<TRecord[]>>;
98
+
99
+ transaction?<TResult>(run: (adapter: DbAdapter) => Promise<TResult>): Promise<DbResult<TResult>>;
100
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './auth';
2
+ export * from './db';
3
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,301 @@
1
+ export type ColorHarmony =
2
+ | 'monochromatic'
3
+ | 'analogous'
4
+ | 'complementary'
5
+ | 'triadic'
6
+ | 'tetradic'
7
+ | 'splitComplementary';
8
+
9
+ export type SystemTone = 'neutral' | 'pastel' | 'earth' | 'jewel' | 'fluorescent';
10
+
11
+ export interface ThemeModeConfig {
12
+ primaryColor: string;
13
+ harmony: ColorHarmony;
14
+ systemTone: SystemTone;
15
+ }
16
+
17
+ export interface ThemeConfig {
18
+ id: string;
19
+ name: string;
20
+ light: ThemeModeConfig;
21
+ dark: ThemeModeConfig;
22
+ }
23
+
24
+ export type ActionType =
25
+ | 'navigate'
26
+ | 'alert'
27
+ | 'console'
28
+ | 'toggleDarkMode'
29
+ | 'setLanguage'
30
+ | 'search'
31
+ | 'filter';
32
+
33
+ export interface NavigateAction {
34
+ type: 'navigate';
35
+ payload: {
36
+ route: string;
37
+ params?: Record<string, number | string>;
38
+ };
39
+ }
40
+
41
+ export interface AlertAction {
42
+ type: 'alert';
43
+ payload?: {
44
+ message?: string;
45
+ };
46
+ }
47
+
48
+ export interface ConsoleAction {
49
+ type: 'console';
50
+ payload?: Record<string, unknown>;
51
+ }
52
+
53
+ export interface ToggleDarkModeAction {
54
+ type: 'toggleDarkMode';
55
+ payload?: never;
56
+ }
57
+
58
+ export interface SetLanguageAction {
59
+ type: 'setLanguage';
60
+ payload: {
61
+ locale: string;
62
+ };
63
+ }
64
+
65
+ export interface SearchAction {
66
+ type: 'search';
67
+ payload: {
68
+ query: string;
69
+ scope?: string;
70
+ };
71
+ }
72
+
73
+ export interface FilterAction {
74
+ type: 'filter';
75
+ payload: {
76
+ filterKey: string;
77
+ filterValue: string;
78
+ };
79
+ }
80
+
81
+ export type Action =
82
+ | AlertAction
83
+ | ConsoleAction
84
+ | FilterAction
85
+ | NavigateAction
86
+ | SearchAction
87
+ | SetLanguageAction
88
+ | ToggleDarkModeAction;
89
+
90
+ export const NAVIGATOR_TYPES = ['stack', 'tabs', 'drawer'] as const;
91
+ export type NavigatorType = (typeof NAVIGATOR_TYPES)[number];
92
+
93
+ export const APP_CATEGORIES = [
94
+ 'books_reading',
95
+ 'business_productivity',
96
+ 'developer_tools',
97
+ 'education_learning',
98
+ 'entertainment_media',
99
+ 'finance_money',
100
+ 'food_drink',
101
+ 'games',
102
+ 'graphics_design',
103
+ 'health_fitness',
104
+ 'kids_family',
105
+ 'lifestyle',
106
+ 'medical',
107
+ 'music_audio',
108
+ 'navigation_travel',
109
+ 'news_magazines',
110
+ 'photo_video',
111
+ 'reference',
112
+ 'shopping_commerce',
113
+ 'social_community',
114
+ 'sports',
115
+ 'utilities_tools',
116
+ 'weather',
117
+ ] as const;
118
+ export type AppCategory = (typeof APP_CATEGORIES)[number];
119
+
120
+ export const DEPLOYMENT_TARGETS = ['minikube'] as const;
121
+ export type KnownDeploymentTarget = (typeof DEPLOYMENT_TARGETS)[number];
122
+ export type DeploymentTarget = KnownDeploymentTarget | (string & {});
123
+
124
+ export const DATABASE_PROVIDERS = ['supabase'] as const;
125
+ export type KnownDatabaseProvider = (typeof DATABASE_PROVIDERS)[number];
126
+ export type DatabaseProvider = KnownDatabaseProvider | (string & {});
127
+
128
+ export const DATABASE_TIERS = ['dev', 'prod'] as const;
129
+ export type DatabaseTier = (typeof DATABASE_TIERS)[number];
130
+
131
+ export const STORAGE_PROVIDERS = ['auto', 's3', 'r2'] as const;
132
+ export type StorageProvider = (typeof STORAGE_PROVIDERS)[number];
133
+
134
+ export const AUTHZ_KINDS = ['RBAC', 'ABAC'] as const;
135
+ export type AuthzKind = (typeof AUTHZ_KINDS)[number];
136
+
137
+ export const AUTHZ_ENGINES = ['cerbos', 'native'] as const;
138
+ export type AuthzEngine = (typeof AUTHZ_ENGINES)[number];
139
+
140
+ export const AUTH_SCOPES = ['global', 'none', 'integrated'] as const;
141
+ export type AuthScope = (typeof AUTH_SCOPES)[number];
142
+
143
+ export const AUTH_PROVIDERS = ['supabase'] as const;
144
+ export type KnownAuthProvider = (typeof AUTH_PROVIDERS)[number];
145
+ export type AuthProvider = KnownAuthProvider | (string & {});
146
+
147
+ export const AUTH_LOGIN_IDENTIFIERS = ['email', 'username', 'phone'] as const;
148
+ export type AuthLoginIdentifier = (typeof AUTH_LOGIN_IDENTIFIERS)[number];
149
+
150
+ export const AUTH_REGISTRATION_FIELDS = [
151
+ ...AUTH_LOGIN_IDENTIFIERS,
152
+ 'password',
153
+ 'firstName',
154
+ 'lastName',
155
+ 'displayName',
156
+ 'avatarUrl',
157
+ ] as const;
158
+ export type KnownAuthRegistrationField = (typeof AUTH_REGISTRATION_FIELDS)[number];
159
+ export type AuthRegistrationField = KnownAuthRegistrationField | (string & {});
160
+
161
+ export const AUTH_SIGNUP_POLICIES = ['autoSignIn', 'requireVerification'] as const;
162
+ export type AuthSignupPolicy = (typeof AUTH_SIGNUP_POLICIES)[number];
163
+
164
+ export const AUTH_PROFILE_FIELDS = [
165
+ ...AUTH_LOGIN_IDENTIFIERS,
166
+ 'firstName',
167
+ 'lastName',
168
+ 'displayName',
169
+ 'avatarUrl',
170
+ ] as const;
171
+ export type KnownAuthProfileField = (typeof AUTH_PROFILE_FIELDS)[number];
172
+ export type AuthProfileField = KnownAuthProfileField | (string & {});
173
+
174
+ export interface IconSpec {
175
+ name: string;
176
+ provider?: string;
177
+ size?: number | string;
178
+ color?: string;
179
+ }
180
+
181
+ export interface UiNode {
182
+ id: string;
183
+ type: string;
184
+ alias?: string;
185
+ props?: Record<string, unknown>;
186
+ children?: UiNode[];
187
+ style?: Record<string, number | string>;
188
+ }
189
+
190
+ export interface ScreenSpec {
191
+ id: string;
192
+ name: string;
193
+ title?: string;
194
+ description?: string;
195
+ root: UiNode;
196
+ }
197
+
198
+ export interface NavigatorSpec {
199
+ type: NavigatorType;
200
+ initialRouteName?: string;
201
+ routes: RouteDefinition[];
202
+ options?: Record<string, unknown>;
203
+ }
204
+
205
+ export interface RouteDefinition {
206
+ name: string;
207
+ path?: string;
208
+ label?: string;
209
+ icon?: IconSpec;
210
+ hideInTabBar?: boolean;
211
+ guards?: string[];
212
+ screenId?: string;
213
+ navigator?: NavigatorSpec;
214
+ }
215
+
216
+ export interface DeploymentSpec {
217
+ target: DeploymentTarget;
218
+ monitoring: boolean;
219
+ }
220
+
221
+ export interface DatabaseSpec {
222
+ provider: DatabaseProvider;
223
+ tier: DatabaseTier;
224
+ }
225
+
226
+ export interface StorageSpec {
227
+ provider: StorageProvider;
228
+ buckets: string[];
229
+ }
230
+
231
+ export interface AuthzSpec {
232
+ kind: AuthzKind;
233
+ engine: AuthzEngine;
234
+ }
235
+
236
+ export interface AuthLoginSpec {
237
+ identifiers: AuthLoginIdentifier[];
238
+ }
239
+
240
+ export interface AuthRegistrationSpec {
241
+ requiredFields: AuthRegistrationField[];
242
+ optionalFields?: AuthRegistrationField[];
243
+ signupPolicy?: AuthSignupPolicy;
244
+ }
245
+
246
+ export interface AuthProfileSpec {
247
+ fields: AuthProfileField[];
248
+ }
249
+
250
+ export interface AuthSpec {
251
+ scope: AuthScope;
252
+ provider: AuthProvider;
253
+ authorization: AuthzSpec;
254
+ login?: AuthLoginSpec;
255
+ registration?: AuthRegistrationSpec;
256
+ profile?: AuthProfileSpec;
257
+ }
258
+
259
+ export interface NetworkingSpec {
260
+ domain?: string;
261
+ cdn: boolean;
262
+ }
263
+
264
+ export interface InfraManifest {
265
+ deployment?: DeploymentSpec;
266
+ auth?: AuthSpec;
267
+ database?: DatabaseSpec;
268
+ storage?: StorageSpec;
269
+ networking?: NetworkingSpec;
270
+ plugins: string[];
271
+ pluginsConfig?: Record<string, unknown>;
272
+ }
273
+
274
+ export interface AppManifest {
275
+ metadata: {
276
+ name: string;
277
+ slug: string;
278
+ version: string;
279
+ themeId: string;
280
+ created?: string;
281
+ updated?: string;
282
+ };
283
+ themes: ThemeConfig[];
284
+ activeThemeId: string;
285
+ activeThemeMode?: 'dark' | 'light';
286
+ infra: InfraManifest;
287
+ navigator: NavigatorSpec;
288
+ screens: Record<string, ScreenSpec>;
289
+ settings: {
290
+ apiBaseUrl?: string;
291
+ localization: {
292
+ defaultLocale: string;
293
+ locales: string[];
294
+ };
295
+ authFlow: {
296
+ loginRoute: string;
297
+ unauthorizedRoute: string;
298
+ postLoginRoute: string;
299
+ };
300
+ };
301
+ }