@useatlas/types 0.0.1 → 0.0.3

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.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Platform admin types for cross-tenant management.
3
+ *
4
+ * Used by the platform admin console to manage workspaces,
5
+ * monitor resource usage, and detect noisy neighbors.
6
+ */
7
+ import type { AtlasRole } from "./auth";
8
+ /** Resolved deploy mode — binary value after auto-detection. */
9
+ export type DeployMode = "saas" | "self-hosted";
10
+ /** Raw deploy mode setting — includes "auto" for auto-detection. */
11
+ export type DeployModeSetting = "saas" | "self-hosted" | "auto";
12
+ export declare const WORKSPACE_STATUSES: readonly ["active", "suspended", "deleted"];
13
+ export type WorkspaceStatus = (typeof WORKSPACE_STATUSES)[number];
14
+ export declare const PLAN_TIERS: readonly ["free", "trial", "team", "enterprise"];
15
+ export type PlanTier = (typeof PLAN_TIERS)[number];
16
+ export declare const NOISY_NEIGHBOR_METRICS: readonly ["queries", "tokens", "storage"];
17
+ export type NoisyNeighborMetric = (typeof NOISY_NEIGHBOR_METRICS)[number];
18
+ export interface PlatformWorkspace {
19
+ id: string;
20
+ name: string;
21
+ slug: string;
22
+ status: WorkspaceStatus;
23
+ planTier: PlanTier;
24
+ byot: boolean;
25
+ members: number;
26
+ conversations: number;
27
+ queriesLast24h: number;
28
+ connections: number;
29
+ scheduledTasks: number;
30
+ stripeCustomerId: string | null;
31
+ trialEndsAt: string | null;
32
+ suspendedAt: string | null;
33
+ deletedAt: string | null;
34
+ region: string | null;
35
+ regionAssignedAt: string | null;
36
+ createdAt: string;
37
+ }
38
+ export interface PlatformWorkspaceDetail {
39
+ workspace: PlatformWorkspace;
40
+ users: PlatformWorkspaceUser[];
41
+ }
42
+ export interface PlatformWorkspaceUser {
43
+ id: string;
44
+ name: string;
45
+ email: string;
46
+ role: AtlasRole;
47
+ createdAt: string;
48
+ }
49
+ export interface PlatformStats {
50
+ totalWorkspaces: number;
51
+ activeWorkspaces: number;
52
+ suspendedWorkspaces: number;
53
+ totalUsers: number;
54
+ totalQueries24h: number;
55
+ /** Monthly recurring revenue in USD (estimated from plan tiers). */
56
+ mrr: number;
57
+ }
58
+ export interface NoisyNeighbor {
59
+ workspaceId: string;
60
+ workspaceName: string;
61
+ planTier: PlanTier;
62
+ metric: NoisyNeighborMetric;
63
+ value: number;
64
+ median: number;
65
+ /** value / median — always > 3 for flagged neighbors. */
66
+ ratio: number;
67
+ }
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Profiler and wizard types — shared between @atlas/api (snake_case wire format)
3
+ * and @atlas/web (camelCase UI types).
4
+ *
5
+ * Canonical definitions live here; both packages import from @useatlas/types.
6
+ */
7
+ /** Valid database object types returned by profiler discovery. */
8
+ export declare const OBJECT_TYPES: readonly ["table", "view", "materialized_view"];
9
+ export type ObjectType = (typeof OBJECT_TYPES)[number];
10
+ /** Valid foreign key relationship sources. */
11
+ export declare const FK_SOURCES: readonly ["constraint", "inferred"];
12
+ export type ForeignKeySource = (typeof FK_SOURCES)[number];
13
+ /** Valid partition strategies. */
14
+ export declare const PARTITION_STRATEGIES: readonly ["range", "list", "hash"];
15
+ export type PartitionStrategy = (typeof PARTITION_STRATEGIES)[number];
16
+ export interface ForeignKey {
17
+ from_column: string;
18
+ to_table: string;
19
+ to_column: string;
20
+ source: ForeignKeySource;
21
+ }
22
+ /**
23
+ * Column profile from the database profiler.
24
+ *
25
+ * Invariant: when `is_foreign_key` is true, `fk_target_table` and
26
+ * `fk_target_column` are non-null strings. When false, both are null.
27
+ * This is enforced at construction time in the profiler, not via
28
+ * discriminated union, to keep the type ergonomic for constructors.
29
+ */
30
+ export interface ColumnProfile {
31
+ name: string;
32
+ type: string;
33
+ nullable: boolean;
34
+ unique_count: number | null;
35
+ null_count: number | null;
36
+ sample_values: string[];
37
+ is_primary_key: boolean;
38
+ is_foreign_key: boolean;
39
+ fk_target_table: string | null;
40
+ fk_target_column: string | null;
41
+ is_enum_like: boolean;
42
+ profiler_notes: string[];
43
+ }
44
+ /** Heuristic flags set by `analyzeTableProfiles`. */
45
+ export interface TableFlags {
46
+ possibly_abandoned: boolean;
47
+ possibly_denormalized: boolean;
48
+ }
49
+ /** Partition metadata for partitioned Postgres tables. */
50
+ export interface PartitionInfo {
51
+ strategy: PartitionStrategy;
52
+ key: string;
53
+ children: string[];
54
+ }
55
+ /**
56
+ * Table profile from the database profiler.
57
+ *
58
+ * `matview_populated` is only present when `object_type === "materialized_view"`.
59
+ * Check `object_type` before relying on its value.
60
+ */
61
+ export interface TableProfile {
62
+ table_name: string;
63
+ object_type: ObjectType;
64
+ row_count: number;
65
+ columns: ColumnProfile[];
66
+ primary_key_columns: string[];
67
+ foreign_keys: ForeignKey[];
68
+ inferred_foreign_keys: ForeignKey[];
69
+ profiler_notes: string[];
70
+ table_flags: TableFlags;
71
+ matview_populated?: boolean;
72
+ partition_info?: PartitionInfo;
73
+ }
74
+ export interface DatabaseObject {
75
+ name: string;
76
+ type: ObjectType;
77
+ }
78
+ export interface ProfileError {
79
+ table: string;
80
+ error: string;
81
+ }
82
+ export interface ProfilingResult {
83
+ profiles: TableProfile[];
84
+ errors: ProfileError[];
85
+ }
86
+ /** camelCase column info in the wizard generate response. */
87
+ export interface WizardEntityColumn {
88
+ name: string;
89
+ type: string;
90
+ mappedType?: string;
91
+ nullable: boolean;
92
+ isPrimaryKey: boolean;
93
+ isForeignKey: boolean;
94
+ isEnumLike: boolean;
95
+ sampleValues: string[];
96
+ uniqueCount: number | null;
97
+ nullCount: number | null;
98
+ }
99
+ /** camelCase foreign key in the wizard generate response. */
100
+ export interface WizardForeignKey {
101
+ fromColumn: string;
102
+ toTable: string;
103
+ toColumn: string;
104
+ source: ForeignKeySource;
105
+ }
106
+ /** camelCase inferred foreign key in the wizard generate response. */
107
+ export interface WizardInferredForeignKey {
108
+ fromColumn: string;
109
+ toTable: string;
110
+ toColumn: string;
111
+ }
112
+ /** camelCase heuristic flags in the wizard generate response. */
113
+ export interface WizardTableFlags {
114
+ possiblyAbandoned: boolean;
115
+ possiblyDenormalized: boolean;
116
+ }
117
+ /** Single entity result from the wizard generate endpoint. */
118
+ export interface WizardEntityResult {
119
+ tableName: string;
120
+ objectType: ObjectType;
121
+ rowCount: number;
122
+ columnCount: number;
123
+ yaml: string;
124
+ profile: {
125
+ columns: WizardEntityColumn[];
126
+ primaryKeys: string[];
127
+ foreignKeys: WizardForeignKey[];
128
+ inferredForeignKeys: WizardInferredForeignKey[];
129
+ flags: WizardTableFlags;
130
+ notes: string[];
131
+ };
132
+ }
133
+ /** Table entry returned by the wizard profile endpoint. */
134
+ export interface WizardTableEntry {
135
+ name: string;
136
+ type: ObjectType;
137
+ }
@@ -0,0 +1,27 @@
1
+ /** Prompt library types — wire format for prompt_collections and prompt_items tables. */
2
+ /** All valid prompt industries for built-in collections. */
3
+ export declare const PROMPT_INDUSTRIES: readonly ["saas", "ecommerce", "cybersecurity"];
4
+ export type PromptIndustry = (typeof PROMPT_INDUSTRIES)[number];
5
+ /** Wire format for the prompt_collections table. */
6
+ export interface PromptCollection {
7
+ id: string;
8
+ orgId: string | null;
9
+ name: string;
10
+ industry: string;
11
+ description: string;
12
+ isBuiltin: boolean;
13
+ sortOrder: number;
14
+ createdAt: string;
15
+ updatedAt: string;
16
+ }
17
+ /** Wire format for the prompt_items table. */
18
+ export interface PromptItem {
19
+ id: string;
20
+ collectionId: string;
21
+ question: string;
22
+ description: string | null;
23
+ category: string | null;
24
+ sortOrder: number;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ }
@@ -0,0 +1,16 @@
1
+ /** Query suggestion types — wire format for the query_suggestions table. */
2
+ export interface QuerySuggestion {
3
+ id: string;
4
+ orgId: string | null;
5
+ description: string;
6
+ patternSql: string;
7
+ normalizedHash: string;
8
+ tablesInvolved: string[];
9
+ primaryTable: string | null;
10
+ frequency: number;
11
+ clickedCount: number;
12
+ score: number;
13
+ lastSeenAt: string;
14
+ createdAt: string;
15
+ updatedAt: string;
16
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Data residency types for tenant-to-region routing.
3
+ *
4
+ * Used by the platform admin console and enterprise residency module
5
+ * to assign workspaces to geographic regions and route connections
6
+ * to region-specific databases.
7
+ *
8
+ * Region identifiers are operator-defined via `atlas.config.ts` — the
9
+ * `WELL_KNOWN_REGIONS` array provides suggestions for the admin UI but
10
+ * does not constrain which regions can be configured.
11
+ */
12
+ /**
13
+ * Well-known region identifiers used as suggestions in the admin UI.
14
+ * Operators may configure arbitrary region keys in atlas.config.ts.
15
+ */
16
+ export declare const WELL_KNOWN_REGIONS: readonly ["us-east", "us-west", "eu-west", "eu-central", "ap-southeast", "ap-northeast"];
17
+ /**
18
+ * Region identifier — an operator-defined string from the residency config.
19
+ * Not constrained to WELL_KNOWN_REGIONS; any string key in the regions map is valid.
20
+ */
21
+ export type Region = string;
22
+ export interface RegionConfig {
23
+ /** Display label shown in the admin console. */
24
+ label: string;
25
+ /** PostgreSQL URL for the region's internal database. Region-specific internal routing is planned for a future release. */
26
+ databaseUrl: string;
27
+ /** Optional analytics datasource URL override for this region. */
28
+ datasourceUrl?: string;
29
+ }
30
+ export interface WorkspaceRegion {
31
+ workspaceId: string;
32
+ region: Region;
33
+ /** ISO 8601 timestamp of when the region was assigned. */
34
+ assignedAt: string;
35
+ }
36
+ /** A region projected for selection UI — safe for the frontend. */
37
+ export interface RegionPickerItem {
38
+ /** Region identifier (e.g. "us-east", "eu-west"). */
39
+ id: string;
40
+ /** Human-readable display label (e.g. "US East", "EU West"). */
41
+ label: string;
42
+ /** Whether this region is the deployment's default. */
43
+ isDefault: boolean;
44
+ }
45
+ /** Valid migration status values — single source of truth for Zod schemas and type. */
46
+ export declare const MIGRATION_STATUSES: readonly ["pending", "in_progress", "completed", "failed"];
47
+ /** Status of a region migration request. */
48
+ export type MigrationStatus = (typeof MIGRATION_STATUSES)[number];
49
+ /** A workspace region migration request. */
50
+ export interface RegionMigration {
51
+ id: string;
52
+ workspaceId: string;
53
+ sourceRegion: Region;
54
+ targetRegion: Region;
55
+ status: MigrationStatus;
56
+ /** User ID of who requested the migration. */
57
+ requestedBy: string | null;
58
+ /** ISO 8601 timestamp of when the migration was requested. */
59
+ requestedAt: string;
60
+ /** ISO 8601 timestamp of when the migration completed (or failed). */
61
+ completedAt: string | null;
62
+ /** Error message if the migration failed. */
63
+ errorMessage: string | null;
64
+ }
65
+ export interface RegionStatus {
66
+ region: Region;
67
+ label: string;
68
+ workspaceCount: number;
69
+ /** Always true in current implementation. Reserved for future health checks. */
70
+ healthy: boolean;
71
+ }
@@ -1,4 +1,5 @@
1
1
  /** Semantic layer entity types — dimensions, joins, measures, query patterns, and entity shapes. */
2
+ import type { PIICategory, PIIConfidence } from "./compliance";
2
3
  /** Valid dimension types per the semantic layer YAML spec. */
3
4
  export type DimensionType = "string" | "number" | "date" | "boolean" | "timestamp";
4
5
  export interface Dimension {
@@ -8,6 +9,10 @@ export interface Dimension {
8
9
  sample_values?: string[];
9
10
  primary_key?: boolean;
10
11
  foreign_key?: boolean;
12
+ /** PII category detected during profiling. Enterprise feature. Must be set together with pii_confidence. */
13
+ pii?: PIICategory | (string & {});
14
+ /** PII detection confidence level. Must be set together with pii. */
15
+ pii_confidence?: PIIConfidence | (string & {});
11
16
  }
12
17
  export interface Join {
13
18
  to: string;
@@ -45,3 +50,51 @@ export interface SemanticEntityDetail {
45
50
  export interface EntityData extends SemanticEntityDetail {
46
51
  name: string;
47
52
  }
53
+ /** Column-level diff for a single table that exists in both DB and YAML. */
54
+ export interface SemanticTableDiff {
55
+ table: string;
56
+ addedColumns: {
57
+ name: string;
58
+ type: string;
59
+ }[];
60
+ removedColumns: {
61
+ name: string;
62
+ type: string;
63
+ }[];
64
+ typeChanges: {
65
+ name: string;
66
+ yamlType: string;
67
+ dbType: string;
68
+ }[];
69
+ }
70
+ /** Full diff result returned by `GET /api/v1/admin/semantic/diff`. */
71
+ export interface SemanticDiffResponse {
72
+ connection: string;
73
+ newTables: string[];
74
+ removedTables: string[];
75
+ tableDiffs: SemanticTableDiff[];
76
+ unchangedCount: number;
77
+ summary: {
78
+ total: number;
79
+ new: number;
80
+ removed: number;
81
+ changed: number;
82
+ unchanged: number;
83
+ };
84
+ warnings?: string[];
85
+ }
86
+ /** Column info returned by the public tables endpoint. */
87
+ export interface TableColumn {
88
+ name: string;
89
+ type: DimensionType | (string & {});
90
+ description: string;
91
+ }
92
+ /**
93
+ * Simplified table info returned by the public `GET /api/v1/tables` endpoint.
94
+ * A projection of `SemanticEntityDetail` exposing only dimensions (as columns).
95
+ */
96
+ export interface TableInfo {
97
+ table: string;
98
+ description: string;
99
+ columns: TableColumn[];
100
+ }
package/dist/share.d.ts CHANGED
@@ -1,5 +1,19 @@
1
+ /** Share visibility mode. */
2
+ export declare const SHARE_MODES: readonly ["public", "org"];
3
+ export type ShareMode = (typeof SHARE_MODES)[number];
4
+ /** Predefined expiry durations for share links (in seconds). */
5
+ export declare const SHARE_EXPIRY_OPTIONS: {
6
+ readonly "1h": 3600;
7
+ readonly "24h": 86400;
8
+ readonly "7d": 604800;
9
+ readonly "30d": 2592000;
10
+ readonly never: null;
11
+ };
12
+ export type ShareExpiryKey = keyof typeof SHARE_EXPIRY_OPTIONS;
1
13
  /** Response shape when generating a shareable link for a conversation. */
2
14
  export interface ShareLink {
3
15
  token: string;
4
16
  url: string;
17
+ expiresAt: string | null;
18
+ shareMode: ShareMode;
5
19
  }
package/dist/share.js CHANGED
@@ -0,0 +1,13 @@
1
+ // src/share.ts
2
+ var SHARE_MODES = ["public", "org"];
3
+ var SHARE_EXPIRY_OPTIONS = {
4
+ "1h": 3600,
5
+ "24h": 86400,
6
+ "7d": 604800,
7
+ "30d": 2592000,
8
+ never: null
9
+ };
10
+ export {
11
+ SHARE_MODES,
12
+ SHARE_EXPIRY_OPTIONS
13
+ };
package/dist/sla.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * SLA monitoring and alerting types.
3
+ *
4
+ * Used by platform admin console for per-workspace uptime,
5
+ * query latency, error rate tracking, and alerting.
6
+ */
7
+ /** Aggregated SLA metrics for a single workspace. */
8
+ export interface WorkspaceSLASummary {
9
+ workspaceId: string;
10
+ workspaceName: string;
11
+ latencyP50Ms: number;
12
+ latencyP95Ms: number;
13
+ latencyP99Ms: number;
14
+ /** Error rate as a percentage (0–100). */
15
+ errorRatePct: number;
16
+ /** Uptime as a percentage (0–100), derived from successful query ratio. */
17
+ uptimePct: number;
18
+ totalQueries: number;
19
+ failedQueries: number;
20
+ lastQueryAt: string | null;
21
+ }
22
+ /** A single metric data point for time-series charts. */
23
+ export interface SLAMetricPoint {
24
+ timestamp: string;
25
+ value: number;
26
+ }
27
+ /** Per-workspace detail view with time-series data. */
28
+ export interface WorkspaceSLADetail {
29
+ summary: WorkspaceSLASummary;
30
+ latencyTimeline: SLAMetricPoint[];
31
+ errorTimeline: SLAMetricPoint[];
32
+ }
33
+ export declare const SLA_ALERT_STATUSES: readonly ["firing", "resolved", "acknowledged"];
34
+ export type SLAAlertStatus = (typeof SLA_ALERT_STATUSES)[number];
35
+ export declare const SLA_ALERT_TYPES: readonly ["latency_p99", "error_rate"];
36
+ export type SLAAlertType = (typeof SLA_ALERT_TYPES)[number];
37
+ export interface SLAAlert {
38
+ id: string;
39
+ workspaceId: string;
40
+ workspaceName: string;
41
+ type: SLAAlertType;
42
+ status: SLAAlertStatus;
43
+ /** Current metric value that triggered the alert (ms for latency, % for error rate). */
44
+ currentValue: number;
45
+ /** Threshold that was exceeded (same unit as currentValue). */
46
+ threshold: number;
47
+ message: string;
48
+ firedAt: string;
49
+ resolvedAt: string | null;
50
+ acknowledgedAt: string | null;
51
+ acknowledgedBy: string | null;
52
+ }
53
+ export interface SLAThresholds {
54
+ /** P99 latency threshold in milliseconds. */
55
+ latencyP99Ms: number;
56
+ /** Error rate threshold as a percentage (0–100). */
57
+ errorRatePct: number;
58
+ }
package/dist/sso.d.ts ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Enterprise SSO types shared across API, frontend, and SDK.
3
+ *
4
+ * SSO providers are org-scoped: each organization can register one or more
5
+ * SAML/OIDC identity providers for single sign-on. Domain-based
6
+ * auto-provisioning maps email domains to organizations.
7
+ */
8
+ export declare const SSO_PROVIDER_TYPES: readonly ["saml", "oidc"];
9
+ export type SSOProviderType = (typeof SSO_PROVIDER_TYPES)[number];
10
+ /** SAML-specific configuration stored in sso_providers.config JSONB. */
11
+ export interface SSOSamlConfig {
12
+ /** IdP Entity ID (issuer). */
13
+ idpEntityId: string;
14
+ /** IdP Single Sign-On URL (HTTP-Redirect or HTTP-POST binding). */
15
+ idpSsoUrl: string;
16
+ /** IdP X.509 certificate in PEM format for signature verification. */
17
+ idpCertificate: string;
18
+ /** SP Entity ID. Must be configured explicitly when initiating SAML flows. */
19
+ spEntityId?: string;
20
+ /** SP Assertion Consumer Service URL. */
21
+ spAcsUrl?: string;
22
+ }
23
+ /** OIDC-specific configuration stored in sso_providers.config JSONB. */
24
+ export interface SSOOidcConfig {
25
+ /** OAuth2 Client ID. */
26
+ clientId: string;
27
+ /** OAuth2 Client Secret (encrypted at rest in the sso_providers.config column). */
28
+ clientSecret: string;
29
+ /** OpenID Connect Discovery URL (e.g. `https://idp.example.com/.well-known/openid-configuration`). */
30
+ discoveryUrl: string;
31
+ }
32
+ interface SSOProviderBase {
33
+ id: string;
34
+ orgId: string;
35
+ /** IdP issuer identifier (entityId for SAML, issuer URL for OIDC). */
36
+ issuer: string;
37
+ /** Email domain for auto-provisioning (e.g. "acme.com"). */
38
+ domain: string;
39
+ enabled: boolean;
40
+ /** When true, password login is blocked for this org — users must use SSO. */
41
+ ssoEnforced: boolean;
42
+ createdAt: string;
43
+ updatedAt: string;
44
+ }
45
+ export interface SSOSamlProvider extends SSOProviderBase {
46
+ type: "saml";
47
+ config: SSOSamlConfig;
48
+ }
49
+ export interface SSOOidcProvider extends SSOProviderBase {
50
+ type: "oidc";
51
+ config: SSOOidcConfig;
52
+ }
53
+ /** Discriminated union — `type` determines the shape of `config`. */
54
+ export type SSOProvider = SSOSamlProvider | SSOOidcProvider;
55
+ export type CreateSSOProviderRequest = {
56
+ type: "saml";
57
+ issuer: string;
58
+ domain: string;
59
+ enabled?: boolean;
60
+ config: SSOSamlConfig;
61
+ } | {
62
+ type: "oidc";
63
+ issuer: string;
64
+ domain: string;
65
+ enabled?: boolean;
66
+ config: SSOOidcConfig;
67
+ };
68
+ export interface UpdateSSOProviderRequest {
69
+ issuer?: string;
70
+ domain?: string;
71
+ enabled?: boolean;
72
+ config?: Record<string, unknown>;
73
+ }
74
+ /** Response shape for list endpoints. Currently total equals providers.length (no pagination yet). */
75
+ export interface SSOProviderListResponse {
76
+ providers: SSOProvider[];
77
+ total: number;
78
+ }
79
+ export {};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@useatlas/types",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Shared types for the Atlas text-to-SQL agent",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "build": "rm -rf dist && bun build src/index.ts src/auth.ts src/conversation.ts src/connection.ts src/action.ts src/scheduled-task.ts src/errors.ts src/semantic.ts src/share.ts --outdir dist --root src --target node --packages external && npx tsc -p tsconfig.build.json"
7
+ "build": "rm -rf dist && bun build src/index.ts src/auth.ts src/conversation.ts src/connection.ts src/action.ts src/scheduled-task.ts src/errors.ts src/semantic.ts src/share.ts src/billing.ts --outdir dist --root src --target node --packages external && bun x tsc -p tsconfig.build.json"
8
8
  },
9
9
  "exports": {
10
10
  ".": {
@@ -51,6 +51,11 @@
51
51
  "types": "./dist/share.d.ts",
52
52
  "import": "./dist/share.js",
53
53
  "default": "./dist/share.js"
54
+ },
55
+ "./billing": {
56
+ "types": "./dist/billing.d.ts",
57
+ "import": "./dist/billing.js",
58
+ "default": "./dist/billing.js"
54
59
  }
55
60
  },
56
61
  "main": "./dist/index.js",