@ssiriuss/connectors 0.0.0-stage → 0.0.1

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 (172) hide show
  1. package/README.md +65 -2
  2. package/dist/boxes/connectors.d.ts +2 -0
  3. package/dist/boxes/connectors.js +1 -0
  4. package/dist/features/integration-studio/README.md +24 -0
  5. package/dist/features/integration-studio/assets/connectors/api.svg +5 -0
  6. package/dist/features/integration-studio/assets/connectors/arity.png +0 -0
  7. package/dist/features/integration-studio/assets/connectors/axle.png +0 -0
  8. package/dist/features/integration-studio/assets/connectors/canopy.png +0 -0
  9. package/dist/features/integration-studio/assets/connectors/ccc.png +0 -0
  10. package/dist/features/integration-studio/assets/connectors/cmt.png +0 -0
  11. package/dist/features/integration-studio/assets/connectors/cotality.png +0 -0
  12. package/dist/features/integration-studio/assets/connectors/csv.svg +5 -0
  13. package/dist/features/integration-studio/assets/connectors/dnb.png +0 -0
  14. package/dist/features/integration-studio/assets/connectors/eagleview.png +0 -0
  15. package/dist/features/integration-studio/assets/connectors/email.svg +4 -0
  16. package/dist/features/integration-studio/assets/connectors/equifax.png +0 -0
  17. package/dist/features/integration-studio/assets/connectors/esri.svg +19 -0
  18. package/dist/features/integration-studio/assets/connectors/examone.png +0 -0
  19. package/dist/features/integration-studio/assets/connectors/experian.svg +26 -0
  20. package/dist/features/integration-studio/assets/connectors/fema.png +0 -0
  21. package/dist/features/integration-studio/assets/connectors/file.svg +4 -0
  22. package/dist/features/integration-studio/assets/connectors/fmcsa.png +0 -0
  23. package/dist/features/integration-studio/assets/connectors/ftp.svg +5 -0
  24. package/dist/features/integration-studio/assets/connectors/google-maps.png +0 -0
  25. package/dist/features/integration-studio/assets/connectors/graphql.png +0 -0
  26. package/dist/features/integration-studio/assets/connectors/grpc.png +0 -0
  27. package/dist/features/integration-studio/assets/connectors/http.svg +5 -0
  28. package/dist/features/integration-studio/assets/connectors/jdpower.png +0 -0
  29. package/dist/features/integration-studio/assets/connectors/json.svg +5 -0
  30. package/dist/features/integration-studio/assets/connectors/kafka.png +0 -0
  31. package/dist/features/integration-studio/assets/connectors/lexisnexis.png +0 -0
  32. package/dist/features/integration-studio/assets/connectors/mcp.svg +5 -0
  33. package/dist/features/integration-studio/assets/connectors/melissa.png +0 -0
  34. package/dist/features/integration-studio/assets/connectors/mib.png +0 -0
  35. package/dist/features/integration-studio/assets/connectors/milliman.png +0 -0
  36. package/dist/features/integration-studio/assets/connectors/mitchell.png +0 -0
  37. package/dist/features/integration-studio/assets/connectors/moodys.png +0 -0
  38. package/dist/features/integration-studio/assets/connectors/ncci.png +0 -0
  39. package/dist/features/integration-studio/assets/connectors/nearmap.png +0 -0
  40. package/dist/features/integration-studio/assets/connectors/nhtsa.png +0 -0
  41. package/dist/features/integration-studio/assets/connectors/nicb.png +0 -0
  42. package/dist/features/integration-studio/assets/connectors/noaa.png +0 -0
  43. package/dist/features/integration-studio/assets/connectors/ofac.png +0 -0
  44. package/dist/features/integration-studio/assets/connectors/openai.svg +31 -0
  45. package/dist/features/integration-studio/assets/connectors/openapi.png +0 -0
  46. package/dist/features/integration-studio/assets/connectors/postman.png +0 -0
  47. package/dist/features/integration-studio/assets/connectors/precisely.png +0 -0
  48. package/dist/features/integration-studio/assets/connectors/rest.svg +5 -0
  49. package/dist/features/integration-studio/assets/connectors/salesforce.png +0 -0
  50. package/dist/features/integration-studio/assets/connectors/servicebus.png +0 -0
  51. package/dist/features/integration-studio/assets/connectors/servicenow.png +0 -0
  52. package/dist/features/integration-studio/assets/connectors/sftp.svg +5 -0
  53. package/dist/features/integration-studio/assets/connectors/soap.svg +5 -0
  54. package/dist/features/integration-studio/assets/connectors/solera.png +0 -0
  55. package/dist/features/integration-studio/assets/connectors/transunion.png +0 -0
  56. package/dist/features/integration-studio/assets/connectors/verisk.png +0 -0
  57. package/dist/features/integration-studio/assets/connectors/webhook.svg +4 -0
  58. package/dist/features/integration-studio/assets/connectors/websocket.svg +5 -0
  59. package/dist/features/integration-studio/assets/connectors/xml.svg +5 -0
  60. package/dist/features/integration-studio/components/ActionEditor.d.ts +20 -0
  61. package/dist/features/integration-studio/components/ActionEditor.js +3 -0
  62. package/dist/features/integration-studio/components/ActionPanels.d.ts +20 -0
  63. package/dist/features/integration-studio/components/ActionPanels.js +1 -0
  64. package/dist/features/integration-studio/components/ActionWorkspace.d.ts +14 -0
  65. package/dist/features/integration-studio/components/ActionWorkspace.js +1 -0
  66. package/dist/features/integration-studio/components/ActionsTab.d.ts +9 -0
  67. package/dist/features/integration-studio/components/ActionsTab.js +1 -0
  68. package/dist/features/integration-studio/components/AuthProfilesTab.d.ts +8 -0
  69. package/dist/features/integration-studio/components/AuthProfilesTab.js +1 -0
  70. package/dist/features/integration-studio/components/ConnectorTypePicker.d.ts +11 -0
  71. package/dist/features/integration-studio/components/ConnectorTypePicker.js +1 -0
  72. package/dist/features/integration-studio/components/DataSourcePanel.d.ts +10 -0
  73. package/dist/features/integration-studio/components/DataSourcePanel.js +1 -0
  74. package/dist/features/integration-studio/components/EditorForm.d.ts +27 -0
  75. package/dist/features/integration-studio/components/EditorForm.js +1 -0
  76. package/dist/features/integration-studio/components/ImportSystemDialog.d.ts +13 -0
  77. package/dist/features/integration-studio/components/ImportSystemDialog.js +1 -0
  78. package/dist/features/integration-studio/components/ImportSystemFileDialog.d.ts +10 -0
  79. package/dist/features/integration-studio/components/ImportSystemFileDialog.js +1 -0
  80. package/dist/features/integration-studio/components/LogoPicker.d.ts +6 -0
  81. package/dist/features/integration-studio/components/LogoPicker.js +1 -0
  82. package/dist/features/integration-studio/components/ProfileSignIn.d.ts +14 -0
  83. package/dist/features/integration-studio/components/ProfileSignIn.js +1 -0
  84. package/dist/features/integration-studio/components/ServerKeysTab.d.ts +8 -0
  85. package/dist/features/integration-studio/components/ServerKeysTab.js +1 -0
  86. package/dist/features/integration-studio/components/SystemIcon.d.ts +6 -0
  87. package/dist/features/integration-studio/components/SystemIcon.js +1 -0
  88. package/dist/features/integration-studio/components/SystemLabelsFields.d.ts +10 -0
  89. package/dist/features/integration-studio/components/SystemLabelsFields.js +1 -0
  90. package/dist/features/integration-studio/components/SystemPills.d.ts +15 -0
  91. package/dist/features/integration-studio/components/SystemPills.js +1 -0
  92. package/dist/features/integration-studio/components/TestPanel.d.ts +11 -0
  93. package/dist/features/integration-studio/components/TestPanel.js +1 -0
  94. package/dist/features/integration-studio/components/connector-picker.css +32 -0
  95. package/dist/features/integration-studio/components/mappings/MappingsUnavailable.d.ts +8 -0
  96. package/dist/features/integration-studio/components/mappings/MappingsUnavailable.js +1 -0
  97. package/dist/features/integration-studio/components/mappings/edges.d.ts +7 -0
  98. package/dist/features/integration-studio/components/mappings/edges.js +1 -0
  99. package/dist/features/integration-studio/components/mappings/nodes.d.ts +28 -0
  100. package/dist/features/integration-studio/components/mappings/nodes.js +1 -0
  101. package/dist/features/integration-studio/components/mappings/panels.d.ts +28 -0
  102. package/dist/features/integration-studio/components/mappings/panels.js +5 -0
  103. package/dist/features/integration-studio/components/parts.d.ts +77 -0
  104. package/dist/features/integration-studio/components/parts.js +1 -0
  105. package/dist/features/integration-studio/hooks/useDatabases.d.ts +40 -0
  106. package/dist/features/integration-studio/hooks/useDatabases.js +1 -0
  107. package/dist/features/integration-studio/hooks/useResourceSave.d.ts +26 -0
  108. package/dist/features/integration-studio/hooks/useResourceSave.js +1 -0
  109. package/dist/features/integration-studio/hooks/useStudio.d.ts +218 -0
  110. package/dist/features/integration-studio/hooks/useStudio.js +1 -0
  111. package/dist/features/integration-studio/index.d.ts +8 -0
  112. package/dist/features/integration-studio/index.js +1 -0
  113. package/dist/features/integration-studio/model/action-form.d.ts +64 -0
  114. package/dist/features/integration-studio/model/action-form.js +1 -0
  115. package/dist/features/integration-studio/model/api-document.d.ts +19 -0
  116. package/dist/features/integration-studio/model/api-document.js +1 -0
  117. package/dist/features/integration-studio/model/collection-install.d.ts +15 -0
  118. package/dist/features/integration-studio/model/collection-install.js +1 -0
  119. package/dist/features/integration-studio/model/connector-form.d.ts +29 -0
  120. package/dist/features/integration-studio/model/connector-form.js +2 -0
  121. package/dist/features/integration-studio/model/connector-types.d.ts +15 -0
  122. package/dist/features/integration-studio/model/connector-types.js +1 -0
  123. package/dist/features/integration-studio/model/mappings/function-help.d.ts +1 -0
  124. package/dist/features/integration-studio/model/mappings/function-help.js +1 -0
  125. package/dist/features/integration-studio/model/mappings/mapping-model.d.ts +40 -0
  126. package/dist/features/integration-studio/model/mappings/mapping-model.js +1 -0
  127. package/dist/features/integration-studio/model/mappings/samples.d.ts +85 -0
  128. package/dist/features/integration-studio/model/mappings/samples.js +1 -0
  129. package/dist/features/integration-studio/model/presentation.d.ts +48 -0
  130. package/dist/features/integration-studio/model/presentation.js +1 -0
  131. package/dist/features/integration-studio/model/problems.d.ts +11 -0
  132. package/dist/features/integration-studio/model/problems.js +1 -0
  133. package/dist/features/integration-studio/model/profile-form.d.ts +26 -0
  134. package/dist/features/integration-studio/model/profile-form.js +1 -0
  135. package/dist/features/integration-studio/model/query-form.d.ts +33 -0
  136. package/dist/features/integration-studio/model/query-form.js +2 -0
  137. package/dist/features/integration-studio/model/system-labels.d.ts +20 -0
  138. package/dist/features/integration-studio/model/system-labels.js +1 -0
  139. package/dist/features/integration-studio/model/system-logos.d.ts +7 -0
  140. package/dist/features/integration-studio/model/system-logos.js +1 -0
  141. package/dist/features/integration-studio/pages/ConnectorLibraryPage.d.ts +5 -0
  142. package/dist/features/integration-studio/pages/ConnectorLibraryPage.js +1 -0
  143. package/dist/features/integration-studio/pages/CredentialsPage.d.ts +6 -0
  144. package/dist/features/integration-studio/pages/CredentialsPage.js +1 -0
  145. package/dist/features/integration-studio/pages/DatabasesPage.d.ts +6 -0
  146. package/dist/features/integration-studio/pages/DatabasesPage.js +1 -0
  147. package/dist/features/integration-studio/pages/MappingDesignerPage.d.ts +8 -0
  148. package/dist/features/integration-studio/pages/MappingDesignerPage.js +1 -0
  149. package/dist/features/integration-studio/pages/MappingsPage.d.ts +2 -0
  150. package/dist/features/integration-studio/pages/MappingsPage.js +1 -0
  151. package/dist/features/integration-studio/pages/QueryPage.d.ts +3 -0
  152. package/dist/features/integration-studio/pages/QueryPage.js +1 -0
  153. package/dist/features/integration-studio/pages/SystemPage.d.ts +8 -0
  154. package/dist/features/integration-studio/pages/SystemPage.js +1 -0
  155. package/dist/features/integration-studio/pages/SystemsPage.d.ts +5 -0
  156. package/dist/features/integration-studio/pages/SystemsPage.js +1 -0
  157. package/dist/features/mailboxes/README.md +5 -0
  158. package/dist/features/mailboxes/components/MailboxCreate.d.ts +5 -0
  159. package/dist/features/mailboxes/components/MailboxCreate.js +1 -0
  160. package/dist/features/mailboxes/components/MailboxDirectory.d.ts +12 -0
  161. package/dist/features/mailboxes/components/MailboxDirectory.js +1 -0
  162. package/dist/features/mailboxes/components/MailboxEditor.d.ts +11 -0
  163. package/dist/features/mailboxes/components/MailboxEditor.js +1 -0
  164. package/dist/features/mailboxes/hooks/useMailboxes.d.ts +19 -0
  165. package/dist/features/mailboxes/hooks/useMailboxes.js +1 -0
  166. package/dist/features/mailboxes/index.d.ts +1 -0
  167. package/dist/features/mailboxes/index.js +1 -0
  168. package/dist/features/mailboxes/pages/MailboxesPage.d.ts +1 -0
  169. package/dist/features/mailboxes/pages/MailboxesPage.js +1 -0
  170. package/dist/shared/api/message-mappings.d.ts +121 -0
  171. package/dist/shared/api/message-mappings.js +1 -0
  172. package/package.json +24 -4
@@ -0,0 +1,48 @@
1
+ import type { ActionRole, ActionStatus, AuthProfileKind, HttpMethod, ResponseMode, RunOutcome } from '@/shared/api/integrations';
2
+ /** aria wiring for a control inside `Field`. */
3
+ export declare const described: (id: string, error?: string, hint?: boolean) => {
4
+ id: string;
5
+ 'aria-invalid': boolean | undefined;
6
+ 'aria-describedby': string | undefined;
7
+ };
8
+ export declare const fieldClass = "h-9 w-full rounded-lg border border-input bg-card px-2 text-sm";
9
+ /** Colour supports the label; the text always carries the meaning (WCAG 1.4.1). */
10
+ export declare const statusLabels: Record<ActionStatus, {
11
+ label: string;
12
+ className: string;
13
+ }>;
14
+ export declare const statusOrder: readonly ActionStatus[];
15
+ export declare const methodClasses: Record<HttpMethod, string>;
16
+ export declare const methods: readonly HttpMethod[];
17
+ /** How a response body becomes the output, with what each choice does. */
18
+ export declare const responseModeLabels: Record<ResponseMode, {
19
+ label: string;
20
+ hint: string;
21
+ }>;
22
+ export declare const responseModes: readonly ResponseMode[];
23
+ export declare const roles: readonly ActionRole[];
24
+ /** What each kind needs; `secret` names what `secret_ref` points at (none: keyless). */
25
+ export type KindSpec = {
26
+ label: string;
27
+ config: readonly {
28
+ key: string;
29
+ label: string;
30
+ required: boolean;
31
+ placeholder: string;
32
+ }[];
33
+ secret: string | null;
34
+ };
35
+ /**
36
+ * The kinds the backend accepts today (`mtls` is in the contract but refused). Config
37
+ * keys are the backend's allowlist; anything secret goes through `secret_ref` only.
38
+ */
39
+ export declare const authKinds: Partial<Record<AuthProfileKind, KindSpec>>;
40
+ export declare const kindLabel: (kind: AuthProfileKind) => string;
41
+ export declare const outcomeLabels: Record<RunOutcome, string>;
42
+ /** Template roots and filters the backend's sandbox accepts (help only; it validates). */
43
+ export declare const templateRoots: readonly ['base', 'connector', 'tenant', 'event', 'entity', 'flow', 'task', 'case_ref', 'ref', 'q', 'input', 'record', 'policy', 'cursor', 'maps', 'idempotency_key'];
44
+ export declare const templateFilters: readonly ['upper', 'lower', 'trim', 'string', 'json', 'urlencode', 'iso', 'default:<value>', 'map_<name>'];
45
+ /** Date and time in the person's style (preferences); epoch milliseconds from the API. */
46
+ export declare function formatTime(ms: number | null | undefined): string;
47
+ export declare const shortHash: (hash: string | null | undefined) => string;
48
+ export declare const UUID: RegExp;
@@ -0,0 +1 @@
1
+ import{formatInstant as e}from"@/shared/lib/datetime";export const described=(e,t,n)=>({id:e,"aria-invalid":t?!0:void 0,"aria-describedby":t?`${e}-error`:n?`${e}-hint`:void 0});export const fieldClass=`h-9 w-full rounded-lg border border-input bg-card px-2 text-sm`;export const statusLabels={draft:{label:`Draft`,className:`bg-muted text-muted-foreground`},tested:{label:`Tested`,className:`bg-primary/10 text-primary`},published:{label:`Published`,className:`bg-success/10 text-success-foreground`},retired:{label:`Retired`,className:`bg-muted text-muted-foreground line-through`}};export const statusOrder=[`draft`,`tested`,`published`,`retired`];export const methodClasses={GET:`border-sky-500/25 bg-sky-500/10 text-sky-700 dark:text-sky-300`,POST:`border-emerald-500/25 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,PUT:`border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-300`,PATCH:`border-violet-500/25 bg-violet-500/10 text-violet-700 dark:text-violet-300`,DELETE:`border-destructive/25 bg-destructive/10 text-destructive`};export const methods=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`];export const responseModeLabels={auto:{label:`Automatic`,hint:`From the response headers: a download is stored as a file, JSON is read as JSON, anything else as text.`},file:{label:`File (download)`,hint:`Stored in file storage, up to 64 MB. The output is the file reference (file.uri, file.name, file.size_bytes), never its content.`},json:{label:`JSON`,hint:`Read as JSON whatever the headers say.`},text:{label:`Text`,hint:`The body as text.`}};export const responseModes=[`auto`,`file`,`json`,`text`];export const roles=[`case.create`,`case.update`,`case.close`,`task.create`,`task.update`,`task.close`,`task.get`,`task.list_updates`,`reference.search`,`reference.get`,`record.search`,`record.get`,`record.create`,`record.update`,`notification.send`,`custom`];export const authKinds={oauth2_client_credentials:{label:`OAuth 2.0 client credentials`,config:[{key:`token_url`,label:`Token URL`,required:!0,placeholder:`https://login.example.com/oauth2/token`},{key:`client_id`,label:`Client ID`,required:!0,placeholder:`<client-id>`},{key:`scope`,label:`Scope`,required:!1,placeholder:`api://<app-id>/.default`},{key:`audience`,label:`Audience`,required:!1,placeholder:`https://api.example.com`}],secret:`the client secret`},oauth2_authorization_code:{label:`OAuth sign-in (authorization code)`,config:[{key:`client_id`,label:`Client ID`,required:!0,placeholder:`<client-id>`},{key:`authorize_url`,label:`Authorize URL`,required:!0,placeholder:`https://github.com/login/oauth/authorize`},{key:`token_url`,label:`Token URL`,required:!0,placeholder:`https://github.com/login/oauth/access_token`},{key:`scope`,label:`Scope`,required:!1,placeholder:`repo read:org`}],secret:`the client secret`},api_key_header:{label:`API key header`,config:[{key:`header`,label:`Header name`,required:!1,placeholder:`X-API-Key`}],secret:`the API key`},basic:{label:`Basic`,config:[{key:`username`,label:`Username`,required:!0,placeholder:`integration-user`}],secret:`the password`},bearer_static:{label:`Static bearer token`,config:[],secret:`the bearer value`},entra_managed_identity:{label:`Entra managed identity`,config:[{key:`scope`,label:`Scope`,required:!0,placeholder:`api://<app-id>/.default`}],secret:null}};export const kindLabel=e=>authKinds[e]?.label??e;export const outcomeLabels={rendered:`Rendered`,succeeded:`Succeeded`,failed:`Failed`,refused:`Refused`,error:`Error`};export const templateRoots=[`base`,`connector`,`tenant`,`event`,`entity`,`flow`,`task`,`case_ref`,`ref`,`q`,`input`,`record`,`policy`,`cursor`,`maps`,`idempotency_key`];export const templateFilters=[`upper`,`lower`,`trim`,`string`,`json`,`urlencode`,`iso`,`default:<value>`,`map_<name>`];export function formatTime(t){return e(t||null)}export const shortHash=e=>e?e.slice(0,12):`—`;export const UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -0,0 +1,11 @@
1
+ /** The message to show for an error, preferring the readable meaning of its problem code. */
2
+ export declare function problemMessage(error: Error): string;
3
+ /**
4
+ * Splits a save error into field messages and what is left for the form-level notice.
5
+ * Domain problems read "field: reason" (`name: …`, `config.token_url: …`), request
6
+ * validation lists "field: reason" details; `codes` maps a problem code to its field.
7
+ */
8
+ export declare function fieldProblems<F extends string>(error: Error | null, fields: Record<string, F>, codes?: Record<string, F>): {
9
+ fields: Partial<Record<F, string>>;
10
+ rest: Error | null;
11
+ };
@@ -0,0 +1 @@
1
+ import{ApiError as e}from"@/shared/api/client";const t={ACTION_UNCHANGED:`Nothing changed compared with the version you started from.`,ACTION_VERSION_STALE:`A newer version of this action exists. Open the latest version and change that one.`,ACTION_LIFECYCLE:`This step is not allowed in the version’s current status.`,ACTION_LIVE_WRITE_UNCONFIRMED:`A live test of a write action changes the target system: tick the confirmation first.`,ACTION_LIVE_TEST_UNAVAILABLE:`Live calls are not configured on this server. Dry runs still work.`,CONNECTOR_IN_USE:`Live actions still use this connector: retire them first.`,AUTH_PROFILE_IN_USE:`A connector or action still uses this auth profile.`};export function problemMessage(n){return n instanceof e&&n.code&&t[n.code]?`${t[n.code]} (${n.message})`:n.message}export function fieldProblems(t,n,r={}){if(!(t instanceof e)||t.status===412)return{fields:{},rest:t};let i=t.code?r[t.code]:void 0;if(i)return{fields:{[i]:t.message},rest:null};if(t.status!==422)return{fields:{},rest:t};let a={},o=[],s=t.details.length?t.details:[t.message];for(let e of s){let t=/^([A-Za-z_.]+?)(?: › [^:]+)?: (.+)$/.exec(e),r=t?.[1],i=r?n[r]??n[r.split(`.`)[0]??``]:void 0;i&&t?.[2]&&!a[i]?a[i]=t[2]:o.push(e)}return o.length?{fields:a,rest:t.details.length?new e(t.message,t.status,t.correlationId,{code:t.code,details:o}):Object.keys(a).length?null:t}:{fields:a,rest:null}}
@@ -0,0 +1,26 @@
1
+ import { type AuthProfile, type AuthProfileKind, type AuthProfileWrite } from '@/shared/api/integrations';
2
+ /**
3
+ * The auth profile editor's draft. The secret is either kept in Integration Studio
4
+ * (`kept`; `secret` is the new value to store, never shown again) or named in Key Vault
5
+ * (`secret_ref`).
6
+ */
7
+ export type ProfileDraft = {
8
+ display_name: string;
9
+ name: string;
10
+ kind: AuthProfileKind;
11
+ config: Record<string, string>;
12
+ kept: boolean;
13
+ secret_ref: string;
14
+ secret: string;
15
+ /** Kept as it is: the grid's switch turns a credential on or off. */
16
+ enabled: boolean;
17
+ };
18
+ export type ProfileField = 'name' | 'kind' | 'secret_ref' | 'secret' | `config.${string}`;
19
+ export declare function fromProfile(profile?: AuthProfile): ProfileDraft;
20
+ /** The technical name a display name suggests: "CRM OAuth" → crm-oauth. */
21
+ export declare const credentialName: (displayName: string) => string;
22
+ /** Only the keys the chosen kind allows are sent; switching kind never leaks old keys. */
23
+ export declare function toProfileWrite(draft: ProfileDraft): AuthProfileWrite;
24
+ /** Client-side checks that mirror the contract; the server stays the authority. A secret
25
+ * kept here must be typed when the profile is created; later it is optional (replace). */
26
+ export declare function profileProblems(draft: ProfileDraft, secretStored?: boolean): Partial<Record<ProfileField, string>>;
@@ -0,0 +1 @@
1
+ import{KEPT_IN_STUDIO as e}from"@/shared/api/integrations";import{authKinds as t}from"./presentation";export function fromProfile(t){return{display_name:t?.display_name??``,name:t?.name??``,kind:t?.kind??`oauth2_client_credentials`,config:{...t?.config},kept:!t||t.secret_ref===e,secret_ref:t?.secret_ref===e?``:t?.secret_ref??``,secret:``,enabled:t?.enabled??!0}}export const credentialName=e=>e.toLowerCase().replace(/[^a-z0-9._-]+/g,`-`).replace(/^[^a-z]+|[-._]+$/g,``).slice(0,64);const n=/^[A-Za-z0-9][A-Za-z0-9/._-]{0,254}$/,r=/^[a-zA-Z][a-zA-Z0-9._-]{0,63}$/;export function toProfileWrite(n){let r=t[n.kind],i=Object.fromEntries((r?.config??[]).map(e=>[e.key,(n.config[e.key]??``).trim()]).filter(([,e])=>e)),a=n.kept?e:n.secret_ref.trim()||null;return{name:n.name.trim(),display_name:n.display_name.trim()||null,kind:n.kind,config:i,secret_ref:r?.secret?a:null,enabled:n.enabled}}export function profileProblems(e,i=!1){let a=t[e.kind],o={};r.test(e.name.trim())||(o.name=`A letter, then letters, digits, '.', '_' or '-' (max 64).`);for(let t of a?.config??[])t.required&&!(e.config[t.key]??``).trim()&&(o[`config.${t.key}`]=`Enter the ${t.label.toLowerCase()}.`);return a?.secret&&!e.kept&&!n.test(e.secret_ref.trim())&&(o.secret_ref=`Enter the secret name, such as servicenow-client-secret.`),a?.secret&&e.kept&&!i&&!e.secret&&(o.secret=`Enter ${a.secret}.`),e.secret&&e.secret!==e.secret.trim()&&(o.secret=`Remove the spaces around the secret.`),o}
@@ -0,0 +1,33 @@
1
+ import type { DbQuery, DbQueryWrite, SideEffect } from '@/shared/api/integrations';
2
+ /** One `:name` parameter of a query, as a row: its JSON Schema type, format and whether it
3
+ * is required. The backend binds it; it is never spliced into the SQL. */
4
+ export type ParameterRow = {
5
+ name: string;
6
+ type: ParameterType;
7
+ format: ParameterFormat;
8
+ required: boolean;
9
+ };
10
+ export declare const PARAMETER_TYPES: readonly ['string', 'integer', 'number', 'boolean', 'object', 'array'];
11
+ export type ParameterType = (typeof PARAMETER_TYPES)[number];
12
+ export declare const PARAMETER_FORMATS: readonly ['', 'uuid', 'date', 'date-time', 'time'];
13
+ export type ParameterFormat = (typeof PARAMETER_FORMATS)[number];
14
+ export type QueryForm = {
15
+ name: string;
16
+ data_source_id: string;
17
+ statement: string;
18
+ side_effect: SideEffect;
19
+ parameters: ParameterRow[];
20
+ max_rows: number;
21
+ timeout_ms: number;
22
+ };
23
+ export declare const EMPTY_QUERY: QueryForm;
24
+ /** The `:name` parameters of a statement in order of first use, outside quotes, comments
25
+ * and dollar-quoted strings; `::type` casts are not parameters (same rules as the API). */
26
+ export declare function parameterNames(statement: string): string[];
27
+ /** Rows that follow the statement: one per parameter, keeping what was set for a name. */
28
+ export declare function syncParameters(statement: string, rows: ParameterRow[]): ParameterRow[];
29
+ export declare function formOf(query: DbQuery): QueryForm;
30
+ export declare function writeOf(form: QueryForm): DbQueryWrite;
31
+ /** A value typed as text, sent as its parameter's type (empty = not given). */
32
+ export declare function parameterValue(row: ParameterRow, text: string): unknown;
33
+ export declare const QUERY_NAME: RegExp;
@@ -0,0 +1,2 @@
1
+ export const PARAMETER_TYPES=[`string`,`integer`,`number`,`boolean`,`object`,`array`];export const PARAMETER_FORMATS=[``,`uuid`,`date`,`date-time`,`time`];export const EMPTY_QUERY={name:``,data_source_id:``,statement:``,side_effect:`read`,parameters:[],max_rows:500,timeout_ms:1e4};const e=/[A-Za-z_][A-Za-z0-9_]{0,62}/y,t=/\$([A-Za-z_][A-Za-z0-9_]*)?\$/y;export function parameterNames(n){let r=[],i=0,a=n.length;for(;i<a;){let o=n[i];if(o===`'`||o===`"`){for(i+=1;i<a;)if(n[i]===o){if(n[i+1]===o)i+=2;else break}else i+=1;i+=1}else if(n.startsWith(`--`,i)){let e=n.indexOf(`
2
+ `,i);i=e<0?a:e}else if(n.startsWith(`/*`,i)){let e=n.indexOf(`*/`,i+2);i=e<0?a:e+2}else if(o===`$`&&(t.lastIndex=i,t.test(n))){let e=n.slice(i,t.lastIndex),r=n.indexOf(e,t.lastIndex);i=r<0?a:r+e.length}else if(o===`:`&&n[i+1]===`:`)i+=2;else if(o===`:`&&(e.lastIndex=i+1,e.test(n))){let t=n.slice(i+1,e.lastIndex);r.includes(t)||r.push(t),i=e.lastIndex}else i+=1}return r}export function syncParameters(e,t){return parameterNames(e).map(e=>t.find(t=>t.name===e)??{name:e,type:`string`,format:``,required:!0})}export function formOf(e){let t=e.parameters.properties??{},n=Array.isArray(e.parameters.required)?e.parameters.required:[];return{name:e.name,data_source_id:e.data_source_id,statement:e.statement,side_effect:e.side_effect,parameters:e.parameter_names.map(e=>({name:e,type:PARAMETER_TYPES.includes(t[e]?.type??``)?t[e].type:`string`,format:PARAMETER_FORMATS.includes(t[e]?.format??``)?t[e].format:``,required:n.includes(e)})),max_rows:e.max_rows,timeout_ms:e.timeout_ms}}export function writeOf(e){return{name:e.name.trim(),data_source_id:e.data_source_id,statement:e.statement,side_effect:e.side_effect,parameters:e.parameters.length?{type:`object`,properties:Object.fromEntries(e.parameters.map(e=>[e.name,{type:e.type,...e.format&&e.type===`string`?{format:e.format}:{}}])),required:e.parameters.filter(e=>e.required).map(e=>e.name)}:{},max_rows:e.max_rows,timeout_ms:e.timeout_ms}}export function parameterValue(e,t){let n=t.trim();if(n!==``){if(e.type===`integer`||e.type===`number`)return Number(n);if(e.type===`boolean`)return n===`true`;if(e.type===`object`||e.type===`array`)try{return JSON.parse(n)}catch{return n}return t}}export const QUERY_NAME=/^[a-z0-9_]+(\.[a-z0-9_]+)+$/;
@@ -0,0 +1,20 @@
1
+ import type { Connector } from '@/shared/api/integrations';
2
+ /** How a system's credentials are obtained: a contract (paid) or an open public API. */
3
+ export type ConnectorAccess = NonNullable<Connector['access']>;
4
+ export type LineOfBusiness = Connector['lines_of_business'][number];
5
+ export declare const accessLabels: Record<ConnectorAccess, string>;
6
+ export declare const lineOfBusinessLabels: Record<LineOfBusiness, string>;
7
+ /** What a system shows beside its name: its logo and one row of pills. */
8
+ export type SystemLabels = {
9
+ logo?: string;
10
+ access?: ConnectorAccess;
11
+ lines: readonly LineOfBusiness[];
12
+ tags: readonly string[];
13
+ };
14
+ /** The system's own logo (from the logo library) and pills. */
15
+ export declare function labelsOf(system: Pick<Connector, 'icon' | 'access' | 'lines_of_business' | 'tags'>): {
16
+ logo: string | undefined;
17
+ access: "contract" | "free" | undefined;
18
+ lines: ("auto" | "commercial" | "life" | "personal" | "property" | "workers_comp")[];
19
+ tags: string[];
20
+ };
@@ -0,0 +1 @@
1
+ import{logoUrl as e}from"./system-logos";export const accessLabels={contract:`Paid`,free:`Free`};export const lineOfBusinessLabels={auto:`Auto`,commercial:`Commercial`,life:`Life`,personal:`Personal`,property:`Property`,workers_comp:`Workers' comp`};export function labelsOf(t){return{logo:e(t.icon),access:t.access??void 0,lines:t.lines_of_business,tags:t.tags}}
@@ -0,0 +1,7 @@
1
+ export type SystemLogo = {
2
+ key: string;
3
+ url: string;
4
+ };
5
+ export declare const systemLogos: readonly SystemLogo[];
6
+ /** The bundled logo's URL for a key, or undefined when the key is empty or unknown. */
7
+ export declare const logoUrl: (key: string | null | undefined) => string | undefined;
@@ -0,0 +1 @@
1
+ const e=import.meta.glob(`../assets/connectors/*.{png,svg}`,{eager:!0,query:`?url`,import:`default`});export const systemLogos=Object.entries(e).map(([e,t])=>({key:e.replace(/^.*\/|\.(png|svg)$/g,``),url:t})).sort((e,t)=>e.key.localeCompare(t.key));export const logoUrl=e=>e?systemLogos.find(t=>t.key===e)?.url:void 0;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Connector Library: ready-made external systems (endpoints and mappings, no credentials).
3
+ * Install copies one into the customer's Systems; credentials are chosen there afterwards.
4
+ */
5
+ export declare function ConnectorLibraryPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{useMutation as e,useQueryClient as t}from"@tanstack/react-query";import{ArrowUpRight as n,Download as r,FileUp as i,Globe as a,Library as o,Search as s,Trash2 as c,UserRound as ee,Waypoints as l}from"lucide-react";import{useState as u}from"react";import{Link as d}from"react-router-dom";import{paths as f}from"@/app/paths";import{installSystemCollection as te,unpublishSystemCollection as p}from"@/shared/api/integrations";import{ErrorNotice as m}from"@/shared/components/layout/ErrorNotice";import{Button as h}from"@/shared/components/ui/button";import{Input as g}from"@/shared/components/ui/input";import{ChooseTenant as _}from"@/shared/components/workspace/ChooseTenant";import{ConfirmButton as ne}from"@/shared/components/workspace/ConfirmButton";import{PersonName as v}from"@/shared/components/workspace/PersonName";import{ControlHeader as y}from"@/shared/components/workspace/ControlHeader";import{GridHeader as b}from"@/shared/components/workspace/GridHeader";import{ViewToggle as x}from"@/shared/components/workspace/ViewToggle";import{useViewMode as S}from"@/shared/hooks/useViewMode";import{formatDate as C}from"@/shared/lib/datetime";import{formatNumber as w}from"@/shared/lib/format";import{notify as T}from"@/shared/lib/notify";import{matchesSearch as E}from"@/shared/lib/search";import{cn as re}from"@/shared/lib/utils";import{ImportSystemFileDialog as D}from"../components/ImportSystemFileDialog";import{Empty as ie,Loading as O}from"../components/parts";import{SystemIcon as k}from"../components/SystemIcon";import{SystemPills as A}from"../components/SystemPills";import{actionsKey as j,collectionsKey as M,connectorsKey as N,useConnectors as P,useStudio as F,useSystemCollections as I}from"../hooks/useStudio";import{installMessages as L}from"../model/collection-install";import{problemMessage as R}from"../model/problems";import{categoryLabels as z}from"../model/connector-types";import{accessLabels as B,labelsOf as V,lineOfBusinessLabels as H}from"../model/system-labels";import{jsx as U,jsxs as W}from"react/jsx-runtime";const G=Object.keys(z),K=e=>G.find(t=>t===e),q=e=>e===1?`1 endpoint`:`${w(e)} endpoints`,J=e=>e.published_at?`Published on ${C(e.published_at)}`:`Published`,ae=(e,t)=>e===1?`1 system · ${w(t)} installed`:`${w(e)} systems · ${w(t)} installed`,oe=e=>{try{return new URL(e).host}catch{return e}};export function ConnectorLibraryPage(){let e=F(),[t,n]=u(!1);return W(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[U(y,{title:`Connector Library`,icon:o,description:`Ready-made systems with their endpoints and mappings. Install one into Systems, then add its credentials there.`,actions:e.readable&&e.scope.ready&&e.writable&&W(h,{variant:`outline`,onClick:()=>n(!0),title:`Install a whole system from a file downloaded with Export`,children:[U(i,{}),`Import file`]})}),e.readable?e.scope.ready?U(Y,{studio:e}):U(_,{children:`Installed systems belong to one customer.`}):U(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`}),t&&U(D,{studio:e,onClose:()=>n(!1)})]})}function Y({studio:i}){let o=I(i),_=P(i),y=t(),[C,w]=u(``),[D,F]=S(`sirius-connector-library-view`,`cards`),G=e({mutationFn:e=>te(e,i.scope.tenantId),onSuccess:({outcome:e})=>{T.success(L[e]);for(let e of[M(i.scope.tenantId),N(i.scope.tenantId),j(i.scope.tenantId)])y.invalidateQueries({queryKey:e})},onError:e=>T.error(`The system could not be installed: ${R(e)}`)}),Y=e({mutationFn:e=>p(e),onSuccess:()=>{T.success(`Removed from the library. Installed copies stay in Systems.`),y.invalidateQueries({queryKey:M(i.scope.tenantId)})},onError:e=>T.error(`The system could not be removed: ${R(e)}`)}),se=e=>(_.data??[]).find(t=>t.name===e)?.id,X=(o.data??[]).filter(e=>E(C,[e.display_name,e.name,e.description,e.base_url,z[K(e.category)??`api`],e.access&&B[e.access],...e.lines_of_business.map(e=>H[e]),...e.tags,q(e.endpoints),e.installed?`Installed`:void 0,e.published_by])),Z=e=>e.removable&&i.writable?W(ne,{title:`Remove ${e.display_name} from the library?`,detail:`Teams can no longer install it from here. Systems already installed stay as they are.`,action:`Remove`,destructive:!0,className:`size-8 px-0`,pending:Y.isPending&&Y.variables===e.key,onConfirm:()=>Y.mutate(e.key),children:[U(c,{"aria-hidden":`true`}),U(`span`,{className:`sr-only`,children:`Remove ${e.display_name} from the library`})]}):null,Q=e=>e.published_by?W(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-muted-foreground`,title:J(e),children:[U(ee,{className:`size-3.5 shrink-0 text-workspace`,"aria-hidden":`true`}),U(v,{subject:e.published_by,className:`truncate`}),U(`span`,{className:`sr-only`,children:J(e)})]}):null,$=e=>{let t=se(e.name);if(e.installed)return W(d,{to:t?`${f.systems}/${t}`:f.systems,className:`inline-flex h-8 items-center gap-1 rounded-md border px-3 text-xs font-medium hover:border-workspace/60 hover:text-workspace`,children:[`Open `,U(n,{className:`size-3.5`,"aria-hidden":`true`})]});let a=G.isPending&&G.variables===e.key;return W(h,{size:`sm`,disabled:!i.writable||G.isPending,"aria-label":`Install ${e.display_name}`,onClick:()=>G.mutate(e.key),children:[U(r,{}),a?`Installing…`:`Install`]})};return W(`section`,{"aria-label":`Connector Library`,children:[W(b,{className:`mb-3 rounded-xl border bg-card`,children:[W(`label`,{htmlFor:`library-search`,className:`relative min-w-0`,children:[U(`span`,{className:`sr-only`,children:`Search the library`}),U(s,{className:`pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground`,"aria-hidden":`true`}),U(g,{id:`library-search`,type:`search`,className:`h-9 w-72 max-w-full bg-card pl-8 text-sm`,placeholder:`Name, category, line of business, tag`,value:C,onChange:e=>w(e.target.value)})]}),W(`div`,{className:`ml-auto flex items-center gap-4`,children:[o.data&&U(`p`,{className:`hidden text-xs text-muted-foreground tabular-nums lg:block`,children:ae(o.data.length,o.data.filter(e=>e.installed).length)}),U(x,{mode:D,onChange:F})]})]}),o.isPending?U(O,{children:`Loading the library…`}):o.isError?U(m,{error:o.error,retry:()=>void o.refetch()}):X.length===0?U(ie,{children:o.data.length===0?`The library is empty.`:`No system in the library matches this search.`}):D===`cards`?U(`ul`,{"aria-label":`Library systems`,className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,19rem),1fr))] gap-3`,children:X.map(e=>W(`li`,{"aria-label":e.display_name,className:`flex min-w-0 flex-col rounded-xl border bg-card shadow-xs transition-[border-color,box-shadow] hover:border-workspace/50 hover:shadow-md`,children:[W(`div`,{className:`flex flex-1 flex-col gap-3 p-4`,children:[W(`div`,{className:`flex items-start gap-3`,children:[U(k,{logo:V(e).logo,className:`size-11`}),W(`div`,{className:`min-w-0 flex-1`,children:[U(`h2`,{className:`truncate text-[15px] leading-snug font-semibold text-primary`,children:e.display_name}),U(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:z[K(e.category)??`api`]})]})]}),U(`p`,{className:`line-clamp-2 min-h-10 text-[13px] leading-5 text-muted-foreground`,children:e.description||`No description.`}),U(A,{labels:V(e)})]}),W(`div`,{className:`flex items-center gap-3 border-t bg-workspace-soft/40 px-4 py-2.5 text-xs`,children:[W(`span`,{className:`inline-flex items-center gap-1.5 font-medium tabular-nums`,title:q(e.endpoints),children:[U(l,{className:`size-3.5 text-workspace`,"aria-hidden":`true`}),q(e.endpoints)]}),Q(e),W(`span`,{className:`ml-auto flex items-center gap-2`,children:[Z(e),$(e)]})]})]},e.key))}):U(`div`,{className:`overflow-x-auto rounded-xl border bg-card`,children:W(`table`,{className:`w-full text-left text-sm`,children:[U(`caption`,{className:`sr-only`,children:`Library systems`}),U(`thead`,{className:`border-b bg-muted/40 text-[11px] tracking-wide text-muted-foreground uppercase`,children:U(`tr`,{children:[`System`,`Labels`,`Base URL`,`Endpoints`,`Published by`,``].map(e=>U(`th`,{scope:`col`,className:`px-4 py-2.5 font-semibold`,children:e||U(`span`,{className:`sr-only`,children:`Install`})},e))})}),U(`tbody`,{className:`divide-y`,children:X.map(e=>W(`tr`,{className:`transition-[background-color,box-shadow] hover:bg-workspace-soft/60 hover:shadow-[inset_3px_0_0_var(--workspace)]`,children:[U(`td`,{className:`px-4 py-3`,children:W(`div`,{className:`flex min-w-0 items-center gap-3`,children:[U(k,{logo:V(e).logo,className:`size-9 rounded-lg`}),W(`div`,{className:`min-w-0`,children:[U(`span`,{className:`block truncate font-semibold text-primary`,children:e.display_name}),U(`span`,{className:`line-clamp-1 block max-w-md text-xs text-muted-foreground`,children:e.description})]})]})}),U(`td`,{className:`px-4 py-3`,children:U(A,{labels:V(e),max:2,className:`w-56`})}),U(`td`,{className:`px-4 py-3`,children:W(`span`,{className:`inline-flex max-w-56 items-center gap-1.5 rounded-md bg-muted/60 px-2 py-1 font-mono text-[11px] text-muted-foreground`,title:e.base_url,children:[U(a,{className:`size-3 shrink-0`,"aria-hidden":`true`}),U(`span`,{className:`truncate`,children:oe(e.base_url)})]})}),U(`td`,{className:re(`px-4 py-3 text-xs whitespace-nowrap tabular-nums`),children:q(e.endpoints)}),U(`td`,{className:`max-w-48 px-4 py-3 text-xs`,children:Q(e)??`—`}),U(`td`,{className:`px-4 py-3`,children:W(`span`,{className:`flex items-center justify-end gap-2`,children:[Z(e),$(e)]})})]},e.key))})]})})]})}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Credentials: the auth profiles systems authenticate with (secrets kept here encrypted, or
3
+ * named in Key Vault; OAuth sign-in connects from the editor).
4
+ * The list keeps the full width; a credential opens as its own page (back: Credentials).
5
+ */
6
+ export declare function CredentialsPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{useQuery as e}from"@tanstack/react-query";import{mcpServerKeys as t}from"@/shared/api/ai-assets";import{PageTabs as n}from"@/shared/components/workspace/PageTabs";import{useSearchParams as r}from"react-router-dom";import{KeyRound as i,Plus as a,Server as o}from"lucide-react";import{Button as s}from"@/shared/components/ui/button";import{ChooseTenant as c}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as l}from"@/shared/components/workspace/ControlHeader";import{BackLink as u}from"@/shared/components/workspace/BackLink";import{paths as d}from"@/app/paths";import{AuthProfilesTab as f}from"../components/AuthProfilesTab";import{ServerKeysTab as p}from"../components/ServerKeysTab";import{useProfiles as m,useStudio as h}from"../hooks/useStudio";import{jsx as g,jsxs as _,Fragment as v}from"react/jsx-runtime";export function CredentialsPage(){let y=h(),[b]=r(),x=b.get(`view`)===`inbound`,S=m(y),{tenantId:C,ready:w}=y.scope,T=e({queryKey:[`ai-assets`,C??`own`,`mcp-server-keys`],queryFn:({signal:e})=>t.list(C,void 0,e),enabled:w&&y.readable,retry:!1}),E=(e,t)=>t??e;return y.readable&&y.scope.ready&&!x&&y.selected?_(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[g(u,{to:d.credentials,children:`Credentials`}),g(f,{studio:y,split:E})]}):_(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[g(l,{title:`Credentials`,icon:i,description:`How calls to your systems and MCP servers authenticate: API keys, basic, bearer, OAuth client credentials and OAuth sign-in. Secrets are kept here encrypted (never shown again) or named in Key Vault.`,actions:y.readable&&y.scope.ready&&y.writable&&!x&&_(s,{onClick:()=>y.select(`new`),children:[g(a,{}),`Credential`]})}),y.readable?y.scope.ready?_(v,{children:[g(`div`,{className:`mb-3`,children:g(n,{label:`Credential directions`,param:`view`,current:x?`inbound`:``,tabs:[{id:``,label:`Outbound · our calls`,icon:i,count:S.data?.length},{id:`inbound`,label:`Inbound · MCP server keys`,icon:o,count:T.data?.length}]})}),x?g(p,{studio:y}):g(f,{studio:y,split:E})]}):g(c,{children:`Credentials belong to one customer.`}):g(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`})]})}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Databases: the database systems tools query (the App DB first, system-owned) and the
3
+ * named, versioned queries tools run. A database opens in a side panel; a query opens as
4
+ * its own page.
5
+ */
6
+ export declare function DatabasesPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{PageTabs as e}from"@/shared/components/workspace/PageTabs";import{DataTable as t,DataTableRow as n}from"@/shared/components/workspace/DataTable";import{Link as r,useNavigate as i,useSearchParams as a}from"react-router-dom";import{Database as o,FileCode2 as s,Plus as c,Zap as l}from"lucide-react";import{paths as u}from"@/app/paths";import{dataSources as d}from"@/shared/api/integrations";import{Button as f}from"@/shared/components/ui/button";import{ErrorNotice as p}from"@/shared/components/layout/ErrorNotice";import{BackLink as m}from"@/shared/components/workspace/BackLink";import{ChooseTenant as h}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as g}from"@/shared/components/workspace/ControlHeader";import{SplitButton as _}from"@/shared/components/workspace/SplitButton";import{cn as v}from"@/shared/lib/utils";import{DataSourcePanel as y}from"../components/DataSourcePanel";import{Loading as b,StatusPill as x}from"../components/parts";import{formatTime as S}from"../model/presentation";import{dataSourcesKey as C,useCheckDataSource as w,useDataSources as T,useQueryLines as E}from"../hooks/useDatabases";import{EnabledSwitch as D}from"@/shared/components/workspace/EnabledSwitch";import{useProfiles as O,useStudio as k}from"../hooks/useStudio";import{jsx as A,jsxs as j,Fragment as M}from"react/jsx-runtime";const N=[[``,`Databases`,o],[`queries`,`Queries`,s]];export function DatabasesPage(){let n=k(),l=i(),[d]=a(),f=d.get(`view`)===`queries`,v=T(n),C=E(n),w=O(n),D=v.data??[],F=n.selected,I=D.find(e=>e.id===F);if(n.readable&&n.scope.ready&&!f&&(F===`new`||I!==void 0))return j(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[A(m,{to:u.databases,children:`Databases`}),A(y,{studio:n,source:I,profiles:w.data??[],onClose:()=>n.select(``)},`${F}:${I?.version??0}`)]});let L=e=>{let t=D.find(t=>t.id===e);return t?t.display_name??t.name:`—`};return j(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[A(g,{title:`Databases`,icon:o,description:`Databases tools read and write, and the queries they run.`,actions:n.readable&&n.scope.ready&&n.writable&&(f?j(_,{onClick:()=>void l(`${u.dbQueries}/new`),menuLabel:`Create another kind of record`,actions:[{label:`Database`,icon:o,onSelect:()=>n.select(`new`)}],children:[A(c,{}),` Query`]}):j(_,{onClick:()=>n.select(`new`),menuLabel:`Create another kind of record`,actions:[{label:`Query`,icon:s,onSelect:()=>void l(`${u.dbQueries}/new`)}],children:[A(c,{}),` Database`]}))}),n.readable?n.scope.ready?j(M,{children:[A(`div`,{className:`mb-3`,children:A(e,{label:`Database views`,param:`view`,current:f?`queries`:``,tabs:N.map(([e,t,n])=>({id:e,label:t,icon:n,count:e===`queries`?C.data?.length:v.data?.length}))})}),A(`section`,{className:`overflow-hidden rounded-xl border bg-card`,children:f?C.isPending?A(b,{children:`Loading queries…`}):C.isError?A(p,{error:C.error,retry:()=>void C.refetch()}):j(t,{searchInHeader:!0,empty:A(M,{children:`No queries yet. A query is one SQL statement tools run by name.`}),className:`w-full text-left text-sm`,children:[A(`caption`,{className:`sr-only`,children:`Queries`}),A(`thead`,{className:`bg-muted/60 text-xs text-muted-foreground`,children:A(`tr`,{children:[`Query`,`Database`,`Kind`,`Version`,`Status`,`Live`,`Updated`].map(e=>A(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:e},e))})}),A(`tbody`,{className:`divide-y`,children:(C.data??[]).map(({latest:e,live:t})=>j(`tr`,{className:`hover:bg-muted/40`,children:[j(`td`,{className:`px-3 py-2.5`,children:[A(r,{to:`${u.dbQueries}/${e.id}`,className:`font-mono text-xs font-semibold text-primary hover:underline`,children:e.name}),A(`span`,{className:`block text-xs text-muted-foreground`,children:e.parameter_names.length?e.parameter_names.map(e=>`:${e}`).join(`, `):`no parameters`})]}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:L(e.data_source_id)}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:e.side_effect===`write`?`Write`:`Read`}),j(`td`,{className:`px-3 py-2.5 text-xs`,"data-grid-sort":e.version_no,children:[`v`,e.version_no]}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:A(x,{status:e.status})}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:t?`v${t.version_no}`:`—`}),A(`td`,{className:`px-3 py-2.5 text-xs whitespace-nowrap`,"data-grid-sort":e.updated_at??e.created_at,children:S(e.updated_at??e.created_at)})]},e.name))})]},`queries`):v.isPending?A(b,{children:`Loading databases…`}):v.isError?A(p,{error:v.error,retry:()=>void v.refetch()}):j(t,{searchInHeader:!0,className:`w-full text-left text-sm`,children:[A(`caption`,{className:`sr-only`,children:`Databases`}),A(`thead`,{className:`bg-muted/60 text-xs text-muted-foreground`,children:j(`tr`,{children:[[`Database`,`Connection`,`Writes`,`Updated`,`Enabled`].map(e=>A(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:e},e)),A(`th`,{scope:`col`,className:`px-3 py-2 text-right font-medium`,children:`Actions`})]})}),A(`tbody`,{className:`divide-y`,children:D.map(e=>A(P,{gridValues:[e.display_name??e.name,e.platform?`Platform database settings`:[e.host,e.port,e.database].join(` `),e.writes_allowed?`Allowed`:`Read only`,S(e.updated_at??e.created_at),e.enabled?`Enabled`:`Disabled`],source:e,writable:n.writable,onOpen:()=>n.select(e.id)},e.id))})]},`databases`)})]}):A(h,{children:`Databases and queries belong to one customer.`}):A(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`})]})}function P({source:e,onOpen:t,writable:r}){let i=w(e),a=e.display_name??e.name;return j(n,{className:`hover:bg-muted/40`,children:[A(`td`,{className:`px-3 py-2.5`,children:j(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 font-semibold text-primary hover:underline`,children:[A(`span`,{className:`flex size-7 items-center justify-center rounded-md bg-primary/12`,children:A(o,{className:`size-3.5`,"aria-hidden":`true`})}),a]})}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:e.platform?`Platform database settings`:`${e.host}:${e.port}/${e.database}`}),A(`td`,{className:`px-3 py-2.5 text-xs`,children:e.writes_allowed?`Allowed`:`Read only`}),A(`td`,{className:`px-3 py-2.5 text-xs whitespace-nowrap`,"data-grid-sort":e.updated_at??e.created_at,children:S(e.updated_at??e.created_at)}),A(`td`,{className:`px-3 py-2.5`,children:A(D,{name:a,what:`Database`,enabled:e.enabled,disabled:!r||e.platform,save:t=>d.update(e.id,{name:e.name,display_name:e.display_name,engine:e.engine,host:e.host,port:e.port,database:e.database,ssl_mode:e.ssl_mode,auth_profile_id:e.auth_profile_id,allow_write:e.allow_write,timeout_ms:e.timeout_ms,enabled:t},`"${e.version}"`),refresh:[C(e.tenant_id)]})}),A(`td`,{className:`px-3 py-2.5 text-right whitespace-nowrap`,children:A(f,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Check ${a}`,title:`Check ${a}`,disabled:i.isPending,className:v(i.isPending&&`[&_svg]:animate-spin`),onClick:()=>i.mutate(),children:A(l,{})})})]})}
@@ -0,0 +1,8 @@
1
+ import '@xyflow/react/dist/style.css';
2
+ /**
3
+ * The message mapping designer (`/integration/mappings/<id>`, `new` to create): source
4
+ * message on the left, target on the right, functions in between. Drag from a field's dot to
5
+ * a target field (or a function input) to link them; click a function to set it up. Built for
6
+ * people who are not developers: every step says what it does, and Test shows the result.
7
+ */
8
+ export declare function MappingDesignerPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{useEffect as e,useMemo as t,useState as n}from"react";import{useMutation as r,useQuery as i,useQueryClient as ee}from"@tanstack/react-query";import{useNavigate as te,useParams as a}from"react-router-dom";import{Background as ne,Controls as re,ReactFlow as ie,ReactFlowProvider as o,useReactFlow as ae}from"@xyflow/react";import"@xyflow/react/dist/style.css";import{ChevronRight as oe,Maximize2 as se,Minimize2 as ce,CircleAlert as le,GripVertical as ue,Plus as de,FlaskConical as fe,GitMerge as pe,Inbox as me,ListChecks as he,Rocket as ge,Search as _e,Send as ve,Sparkles as ye,Undo2 as be}from"lucide-react";import{paths as xe}from"@/app/paths";import{checkMapping as Se,createMapping as Ce,getMapping as s,getMappingFunctions as we,publishMapping as Te,retireMapping as Ee,saveMapping as De,suggestLinks as Oe}from"@/shared/api/message-mappings";import{ErrorNotice as ke}from"@/shared/components/layout/ErrorNotice";import{Button as c}from"@/shared/components/ui/button";import{Input as l}from"@/shared/components/ui/input";import{ChooseTenant as Ae}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as je}from"@/shared/components/workspace/ControlHeader";import{useDarkTheme as Me}from"@/shared/hooks/useDarkTheme";import{cn as u}from"@/shared/lib/utils";import{Loading as Ne,Pill as Pe}from"../components/parts";import{useStudio as Fe}from"../hooks/useStudio";import{addLink as Ie,canLink as d,defaultParams as Le,linkId as f,mappingsKey as p,NAME as Re,technicalName as ze,normalize as Be,nextStepId as Ve,positionsOf as He,removeStep as Ue,shownRef as m,withFields as We,withPosition as Ge}from"../model/mappings/mapping-model";import{FieldsCard as h,StepCard as Ke}from"../components/mappings/nodes";import{LinkLine as g}from"../components/mappings/edges";import{PreviewPanel as qe,StepPanel as Je,StructurePanel as Ye}from"../components/mappings/panels";import{starterDefinition as Xe}from"../model/mappings/samples";import{BackLink as Ze}from"@/shared/components/workspace/BackLink";import{jsx as _,jsxs as v,Fragment as y}from"react/jsx-runtime";const Qe={fields:h,step:Ke},$e={link:g},b=`application/x-mapping-function`;export function MappingDesignerPage(){let{id:e=`new`}=a(),t=Fe(),n=i({queryKey:[...p,`detail`,e],queryFn:({signal:t})=>s(e,t),enabled:e!==`new`&&t.readable,retry:!1,staleTime:1/0});return t.readable?t.scope.ready?e!==`new`&&n.isPending?_(Ne,{children:`Loading mapping…`}):e!==`new`&&n.isError?_(ke,{error:n.error,retry:()=>void n.refetch()}):_(o,{children:_(x,{saved:e===`new`?void 0:n.data,writable:t.writable,publishable:t.publishable,tenantId:t.scope.tenantId},n.data?`${n.data.data.id}-${n.data.data.version}`:`new`)}):_(Ae,{children:`Mappings belong to one customer.`}):_(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`})}function x({saved:a,writable:o,publishable:s,tenantId:Ae}){let Fe=te(),h=ee(),{screenToFlowPosition:Ke}=ae(),g=a?Be(a.data.definition):Xe(),[x,S]=n(g),[C,w]=n(a?a.data.display_name??``:`Record to policy`),[T,et]=n(a?.data.name??`record.to_target`),[tt,nt]=n(!1),[E,D]=n(a?.data.description??`Incoming record to the policy administration system`),[O,k]=n(null),[A,j]=n(null),[M,N]=n(null),[rt,it]=n(``),[at,ot]=n({}),[P,st]=n(()=>new Set),[F,I]=n(!1),ct=Me();e(()=>{if(!F)return;let e=e=>e.key===`Escape`&&I(!1);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F]);let lt=(e,t)=>({folded:P,onFold:e=>st(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),onFoldAll:n=>st(r=>{let i=new Set([...r].filter(t=>!t.startsWith(`${e}:`)));return n&&t.filter(e=>e.type===`object`||e.type===`list`).forEach(t=>i.add(`${e}:${t.path}`)),i})}),[L,R]=n(``),z=a?.data.status,B=!o,V=i({queryKey:[...p,`functions`],queryFn:({signal:e})=>we(e),staleTime:1/0,retry:!1}),H=e=>V.data?.find(t=>t.key===e),U=!a||E!==a.data.description||C.trim()!==(a.data.display_name??``)||JSON.stringify(x)!==JSON.stringify(g),ut=Re.test(T.trim()),W=async(e,t)=>{h.setQueryData([...p,`detail`,e.data.id],e),await h.invalidateQueries({queryKey:[...p,`list`]}),R(t),Fe(`${xe.mappings}/${e.data.id}`,{replace:!0})},G=r({mutationFn:()=>a?De(a.data.id,{display_name:C.trim()||null,description:E,definition:x},a.etag):Ce({name:T.trim(),display_name:C.trim()||null,description:E,definition:x},Ae),onSuccess:e=>W(e,a&&e.data.id!==a.data.id?`Saved as draft v${e.data.version_no}; the published version keeps running until you publish this one.`:`Mapping saved.`)}),K=r({mutationFn:()=>Te(a.data.id,a.etag),onSuccess:e=>W(e,`v${e.data.version_no} is live. The previous published version was retired.`)}),q=r({mutationFn:()=>Ee(a.data.id,a.etag),onSuccess:e=>W(e,`Mapping retired. Flows can no longer use it.`)}),J=r({mutationFn:()=>Se(x),onSuccess:N}),Y=r({mutationFn:()=>Oe(x),onSuccess:e=>{S(t=>e.reduce(Ie,t)),R(e.length?`Auto-map linked ${e.length} field(s) with matching names. Review them on the canvas.`:`No more fields with matching names to link.`)}}),X=t(()=>{let e=new Set;for(let t of x.links)e.add(t.source),e.add(t.target);return e},[x.links]),dt=new Set((M??[]).map(e=>e.ref).filter(Boolean)),Z=He(x),ft=[{id:`source`,type:`fields`,position:Z.source,deletable:!1,data:{side:`source`,title:`Source message`,fields:x.source_fields,linked:X,...lt(`source`,x.source_fields)}},{id:`target`,type:`fields`,position:Z.target,deletable:!1,data:{side:`target`,title:`Target message`,fields:x.target_fields,linked:X,...lt(`target`,x.target_fields)}},...x.steps.map((e,t)=>({id:e.id,type:`step`,deletable:!1,position:Z[e.id]??{x:420,y:40+t*150},data:{step:e,fn:H(e.function),linked:X,problem:dt.has(`step:${e.id}`),onInfo:()=>k({kind:`step`,id:e.id}),onDelete:B?void 0:()=>{S(t=>Ue(t,e.id)),k(t=>t?.kind===`step`&&t.id===e.id?null:t)}}}))],pt=e=>e.startsWith(`source:`)?`source`:e.startsWith(`target:`)?`target`:e.slice(5).split(`.`)[0],mt=x.links.map(e=>({id:f(e),type:`link`,data:{editable:!B},source:pt(e.source),sourceHandle:m(e.source,P),target:pt(e.target),targetHandle:m(e.target,P),selected:A===f(e),animated:A===f(e),style:{strokeWidth:2,strokeDasharray:m(e.source,P)!==e.source||m(e.target,P)!==e.target?`5 4`:void 0}})),ht=e=>{for(let t of e)if(t.type===`position`&&t.position){let{id:e,position:n}=t;S(t=>Ge(t,e,n))}},gt=e=>{!B&&d(e.sourceHandle,e.targetHandle)&&(S(t=>Ie(t,{source:e.sourceHandle,target:e.targetHandle})),N(null))},_t=e=>{S(t=>({...t,links:t.links.filter(t=>f(t)!==e)})),j(null)},vt=(e,t)=>{let n=H(e);if(!n||B)return;let r=Ke(t??{x:window.innerWidth/2,y:window.innerHeight/2});S(e=>{let t=Ve(e.steps,n.key),i={...e,steps:[...e.steps,{id:t,function:n.key,params:Le(n)}]};return Ge(i,t,{x:r.x-105,y:r.y-60})})},Q=O?.kind===`step`?x.steps.find(e=>e.id===O.id):void 0,$=rt.trim().toLowerCase(),yt=[...new Set((V.data??[]).map(e=>e.category))],bt=(M??[]).filter(e=>e.level===`error`).length;return v(`div`,{className:`workspace-admin flex h-[calc(100svh-7rem)] min-h-[34rem] flex-col`,children:[_(Ze,{to:xe.mappings,children:`Mappings`}),_(je,{title:a?a.data.display_name??a.data.name:`New mapping`,icon:pe,description:a?E||`Drag from a source field to a target field to map it.`:`Name the mapping, describe the two messages, then draw the links.`,pills:a&&v(y,{children:[_(Pe,{className:z===`published`?`bg-success/10 text-success-foreground`:z===`draft`?`bg-viz-2/12 text-viz-2`:void 0,children:z}),v(Pe,{children:[`v`,a.data.version_no]})]}),actions:v(y,{children:[v(c,{variant:`outline`,onClick:()=>k({kind:`preview`}),children:[_(fe,{}),`Test`]}),o&&_(c,{variant:`outline`,disabled:G.isPending||!U||!a&&!ut,onClick:()=>G.mutate(),children:G.isPending?`Saving…`:a?`Save`:`Create mapping`}),s&&a&&z===`draft`&&v(c,{disabled:U||K.isPending,title:U?`Save your changes first`:void 0,onClick:()=>K.mutate(),children:[_(ge,{}),`Publish`]}),s&&a&&z===`published`&&_(c,{variant:`outline`,className:`text-destructive`,disabled:q.isPending,onClick:()=>q.mutate(),children:`Retire`})]})}),(!a||o)&&v(`div`,{className:`mb-3 grid gap-3 rounded-xl border bg-card p-3 sm:grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,2fr)]`,children:[v(`label`,{htmlFor:`mapping-display-name`,className:`text-xs font-medium text-muted-foreground`,children:[`Display name`,_(l,{id:`mapping-display-name`,className:`mt-1 h-9 text-sm`,placeholder:`Record to policy admin`,maxLength:120,value:C,onChange:e=>{w(e.target.value),!a&&!tt&&et(ze(e.target.value))}})]}),v(`label`,{htmlFor:`mapping-name`,className:`text-xs font-medium text-muted-foreground`,children:[`Name`,_(l,{id:`mapping-name`,className:`mt-1 h-9 font-mono text-sm`,placeholder:`record.to_erp`,value:T,readOnly:!!a,onChange:e=>{et(e.target.value),nt(!0)}}),!a&&T.trim()&&!ut&&_(`span`,{className:`mt-1 block text-destructive`,children:`Lower-case words joined by dots, e.g. record.to_pas.`})]}),v(`label`,{htmlFor:`mapping-description`,className:`text-xs font-medium text-muted-foreground`,children:[`Description`,_(l,{id:`mapping-description`,className:`mt-1 h-9 text-sm`,placeholder:`What goes in and what comes out`,value:E,onChange:e=>D(e.target.value)})]})]}),[G.error,K.error,q.error,J.error,Y.error].map((e,t)=>e&&_(ke,{error:e},t)),L&&v(`output`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-success/40 bg-success/8 px-3 py-2 text-sm text-success-foreground`,children:[L,_(`button`,{type:`button`,"aria-label":`Dismiss`,className:`ml-auto`,onClick:()=>R(``),children:`×`})]}),M&&_(`section`,{"aria-label":`Check result`,className:u(`mb-2 rounded-lg border px-3 py-2 text-sm`,M.length?`border-warning/45 bg-warning/8`:`border-success/40 bg-success/8 text-success-foreground`),children:M.length===0?`✓ No problems: every required target field is mapped and every function is connected.`:v(y,{children:[v(`b`,{children:[bt,` error(s), `,M.length-bt,` warning(s)`]}),_(`ul`,{className:`mt-1 space-y-0.5 text-xs`,children:M.map((e,t)=>v(`li`,{className:e.level===`error`?`text-destructive`:`text-warning-foreground`,children:[_(le,{className:`mr-1 inline size-3`,"aria-hidden":`true`}),e.message]},t))})]})}),v(`div`,{className:u(`grid min-h-0 flex-1 grid-cols-[240px_minmax(0,1fr)] gap-3`,F&&`fixed inset-0 z-50 bg-background p-3`),children:[v(`aside`,{"aria-label":`Toolbox`,className:`flex min-h-0 flex-col overflow-hidden rounded-xl border bg-card`,children:[v(`div`,{className:`space-y-1.5 border-b p-2`,children:[v(c,{variant:`outline`,size:`sm`,className:`w-full justify-start`,onClick:()=>k({kind:`source`}),children:[_(me,{}),`Source structure (`,x.source_fields.length,`)`]}),v(c,{variant:`outline`,size:`sm`,className:`w-full justify-start`,onClick:()=>k({kind:`target`}),children:[_(ve,{}),`Target structure (`,x.target_fields.length,`)`]}),o&&v(c,{variant:`outline`,size:`sm`,className:`w-full justify-start`,disabled:Y.isPending,onClick:()=>Y.mutate(),children:[_(ye,{}),`Auto-map matching names`]}),v(c,{variant:`outline`,size:`sm`,className:`w-full justify-start`,disabled:J.isPending,onClick:()=>J.mutate(),children:[_(he,{}),`Check mapping`]}),o&&a&&U&&v(c,{variant:`ghost`,size:`sm`,className:`w-full justify-start`,onClick:()=>{S(g),D(a.data.description),w(a.data.display_name??``),N(null)},children:[_(be,{}),`Discard changes`]})]}),v(`div`,{className:`border-b p-2`,children:[_(`h2`,{className:`mb-1.5 text-xs font-semibold`,children:`Functions`}),v(`label`,{htmlFor:`function-search`,className:`relative block`,children:[_(`span`,{className:`sr-only`,children:`Search functions`}),_(_e,{className:`pointer-events-none absolute top-2 left-2 size-4 text-muted-foreground`,"aria-hidden":`true`}),_(l,{id:`function-search`,type:`search`,className:`h-8 pl-7 text-xs`,placeholder:`Join, date, lookup…`,value:rt,onChange:e=>it(e.target.value)})]})]}),v(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-2`,children:[V.isPending&&_(Ne,{children:`Loading functions…`}),V.error&&_(`p`,{role:`alert`,className:`px-1 text-xs text-muted-foreground`,children:`Functions could not be loaded from the server. You can still link fields directly.`}),yt.map(e=>{let t=(V.data??[]).filter(t=>t.category===e&&(!$||`${t.label} ${t.description}`.toLowerCase().includes($)));if(!t.length)return null;let n=$?!0:at[e]??!1;return v(`section`,{className:`mb-1`,children:[v(`button`,{type:`button`,"aria-expanded":n,onClick:()=>ot(t=>({...t,[e]:!n})),className:`flex w-full items-center gap-1.5 rounded-md px-1.5 py-1.5 text-left text-xs font-semibold tracking-wide text-muted-foreground uppercase hover:bg-muted`,children:[_(oe,{"aria-hidden":`true`,className:u(`size-3.5 transition-transform`,n&&`rotate-90`)}),_(`span`,{className:`flex-1`,children:e}),_(`span`,{className:`rounded-badge bg-muted px-2 text-[11px] font-normal normal-case`,children:t.length})]}),n&&t.map(e=>v(`button`,{type:`button`,disabled:B,title:`${e.description}\nClick to add, or drag onto the canvas.`,draggable:!B,onDragStart:t=>{t.dataTransfer.setData(b,e.key),t.dataTransfer.effectAllowed=`copy`},onClick:()=>vt(e.key),className:`group/fn flex w-full items-start gap-1.5 rounded-md py-1.5 pr-2 pl-5 text-left text-xs hover:bg-muted disabled:cursor-default`,children:[_(ue,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0 text-muted-foreground/50 group-hover/fn:text-muted-foreground`}),v(`span`,{className:`min-w-0 flex-1`,children:[_(`span`,{className:`font-medium`,children:e.label}),_(`span`,{className:`block truncate text-muted-foreground`,children:e.description})]}),_(de,{"aria-hidden":`true`,className:`mt-0.5 size-3.5 shrink-0 opacity-0 group-hover/fn:opacity-100`})]},e.key))]},e)})]})]}),v(`section`,{"aria-label":`Mapping canvas`,className:`relative min-h-0 overflow-hidden rounded-xl border bg-card`,children:[v(ie,{nodes:ft,edges:mt,nodeTypes:Qe,edgeTypes:$e,onNodesChange:ht,onConnect:gt,isValidConnection:e=>!B&&d(e.sourceHandle,e.targetHandle),onEdgeClick:(e,t)=>j(t.id===A?null:t.id),onEdgesDelete:e=>!B&&e.forEach(e=>_t(e.id)),onNodeClick:(e,t)=>t.type===`step`&&k({kind:`step`,id:t.id}),onPaneClick:()=>j(null),onDragOver:e=>{e.dataTransfer.types.includes(b)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=e.dataTransfer.getData(b);t&&(e.preventDefault(),vt(t,{x:e.clientX+105,y:e.clientY+60}))},nodesConnectable:!B,nodesDraggable:!0,fitView:!0,minZoom:.2,forceColorMode:ct?`dark`:`light`,panOnScroll:!0,zoomOnScroll:!1,zoomOnPinch:!0,proOptions:{hideAttribution:!0},children:[_(ne,{gap:18}),_(re,{showInteractive:!1})]}),v(c,{size:`sm`,variant:`outline`,className:`absolute top-2 right-2 z-10 bg-card`,"aria-pressed":F,title:F?`Exit full screen (Esc)`:`Full screen`,onClick:()=>I(!F),children:[_(F?ce:se,{"aria-hidden":`true`}),F?`Exit full screen`:`Full screen`]})]})]}),(O?.kind===`source`||O?.kind===`target`)&&_(Ye,{side:O.kind,fields:O.kind===`source`?x.source_fields:x.target_fields,readOnly:B,onClose:()=>k(null),onApply:e=>{S(t=>We(t,O.kind,e)),k(null),N(null)}}),Q&&_(Je,{step:Q,fn:H(Q.function),readOnly:B,linkedInputs:new Set(x.links.filter(e=>e.target.startsWith(`step:${Q.id}.`)).map(e=>e.target.slice(`step:${Q.id}.`.length))),onClose:()=>k(null),onRemove:()=>{S(e=>Ue(e,Q.id)),k(null)},onApply:e=>{S(t=>({...t,steps:t.steps.map(t=>t.id===Q.id?{...t,params:e}:t)})),k(null)}}),O?.kind===`preview`&&_(qe,{definition:x,onClose:()=>k(null)})]})}
@@ -0,0 +1,2 @@
1
+ /** Message mappings: each opens on the drag-and-drop designer. */
2
+ export declare function MappingsPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{GridHeader as e,GridHeaderSlot as t}from"@/shared/components/workspace/GridHeader";import{DataTable as n}from"@/shared/components/workspace/DataTable";import{useState as r}from"react";import{useQuery as i}from"@tanstack/react-query";import{Link as a}from"react-router-dom";import{GitMerge as o,Plus as s,Search as c}from"lucide-react";import{paths as l}from"@/app/paths";import{getMappings as u}from"@/shared/api/message-mappings";import{buttonVariants as d}from"@/shared/components/ui/button";import{Input as f}from"@/shared/components/ui/input";import{ChooseTenant as p}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as m}from"@/shared/components/workspace/ControlHeader";import{Loading as h,Pill as g}from"../components/parts";import{formatTime as _}from"../model/presentation";import{useStudio as v}from"../hooks/useStudio";import{mappingsKey as y}from"../model/mappings/mapping-model";import{MappingsUnavailable as b}from"../components/mappings/MappingsUnavailable";import{matchesSearch as x}from"@/shared/lib/search";import{jsx as S,jsxs as C}from"react/jsx-runtime";const w={published:`bg-success/10 text-success-foreground`,draft:`bg-viz-2/12 text-viz-2`,retired:void 0};export function MappingsPage(){let[T,E]=r(null),D=v(),[O,k]=r(``),A=i({queryKey:[...y,`list`,D.scope.tenantId??`own`],queryFn:({signal:e})=>u(D.scope.tenantId,e),enabled:D.readable&&D.scope.ready,retry:!1}),j=A.data??[],M=j.filter(e=>x(O,[e.display_name,e.name,e.description]));return C(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[S(m,{title:`Message mappings`,icon:o,description:`Turn one message into another without code: drag source fields onto target fields, add functions in between, test, then publish.`,actions:D.writable&&D.scope.ready&&C(a,{to:`${l.mappings}/new`,className:d(),children:[S(s,{}),`Mapping`]})}),D.readable?D.scope.ready?C(`section`,{"aria-label":`Mappings`,className:`overflow-hidden rounded-xl border bg-card`,children:[C(e,{children:[C(`label`,{htmlFor:`mapping-search`,className:`relative inline-block`,children:[S(`span`,{className:`sr-only`,children:`Search mappings`}),S(c,{className:`pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground`,"aria-hidden":`true`}),S(f,{id:`mapping-search`,type:`search`,className:`h-9 w-64 pl-8 text-sm`,placeholder:`Name or description`,value:O,onChange:e=>k(e.target.value)})]}),S(t,{ref:E})]}),A.isPending?S(h,{children:`Loading mappings…`}):A.isError?S(b,{error:A.error,retry:()=>void A.refetch()}):C(n,{empty:j.length===0?`No mappings yet. Create one and drag source fields onto target fields.`:`No mapping matches this search.`,columnsToolbar:T,externalSearch:!0,className:`w-full text-left text-sm`,children:[S(`caption`,{className:`sr-only`,children:`Message mappings`}),S(`thead`,{className:`bg-muted/60 text-xs text-muted-foreground`,children:S(`tr`,{children:[`Mapping`,`Description`,`Fields`,`Version`,`Status`,`Updated`].map(e=>S(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:e},e))})}),S(`tbody`,{className:`divide-y`,children:M.map(e=>C(`tr`,{className:`hover:bg-muted/40`,children:[C(`td`,{className:`px-3 py-2.5`,children:[S(a,{to:`${l.mappings}/${e.id}`,className:`font-semibold text-primary hover:underline`,children:e.display_name??e.name}),e.display_name&&S(`span`,{className:`block text-xs text-muted-foreground`,children:e.name})]}),S(`td`,{className:`max-w-md truncate px-3 py-2.5 text-xs text-muted-foreground`,children:e.description||`—`}),C(`td`,{className:`px-3 py-2.5 text-xs`,children:[(e.definition.source_fields??[]).length,` →`,` `,(e.definition.target_fields??[]).length,` ·`,` `,(e.definition.links??[]).length,` links`]}),C(`td`,{className:`px-3 py-2.5 text-xs whitespace-nowrap`,"data-grid-sort":e.version_no,children:[`v`,e.version_no]}),S(`td`,{className:`px-3 py-2.5 text-xs`,children:S(g,{className:w[e.status],children:e.status})}),S(`td`,{className:`px-3 py-2.5 text-xs whitespace-nowrap`,"data-grid-sort":e.updated_at??e.created_at,children:_(e.updated_at??e.created_at)})]},e.id))})]})]}):S(p,{children:`Mappings belong to one customer.`}):S(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`})]})}
@@ -0,0 +1,3 @@
1
+ /** A query as its own page: details, the statement with its parameters, a test run and the
2
+ * versions. Saving creates the next version; a passing test makes it publishable. */
3
+ export declare function QueryPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{NumberInput as e}from"@/shared/components/workspace/NumberInput";import{tabBarClass as t,tabClass as n}from"@/shared/components/workspace/tab-styles";import{DataTable as r}from"@/shared/components/workspace/DataTable";import{useState as i}from"react";import{useMutation as a,useQuery as o,useQueryClient as s}from"@tanstack/react-query";import{Link as ee,useNavigate as c,useParams as l,useSearchParams as u}from"react-router-dom";import{Archive as d,FileCode2 as f,Play as te,Rocket as ne,Save as re}from"lucide-react";import{paths as p}from"@/app/paths";import{dbQueries as m}from"@/shared/api/integrations";import{Button as h}from"@/shared/components/ui/button";import{Input as g}from"@/shared/components/ui/input";import{Textarea as ie}from"@/shared/components/ui/textarea";import{ChooseTenant as _}from"@/shared/components/workspace/ChooseTenant";import{ConfirmButton as ae}from"@/shared/components/workspace/ConfirmButton";import{ControlHeader as v}from"@/shared/components/workspace/ControlHeader";import{cn as y}from"@/shared/lib/utils";import{Field as b,Loading as x,StatusPill as S}from"../components/parts";import{problemMessage as C}from"../model/problems";import{formatTime as w}from"../model/presentation";import{EMPTY_QUERY as T,PARAMETER_FORMATS as E,PARAMETER_TYPES as D,QUERY_NAME as oe,formOf as se,parameterValue as ce,syncParameters as le,writeOf as ue}from"../model/query-form";import{useDataSources as de,useQueryLines as fe,useRefreshDatabases as pe}from"../hooks/useDatabases";import{studioKey as O,useStudio as k}from"../hooks/useStudio";import{notify as A}from"@/shared/lib/notify";import{BackLink as j}from"@/shared/components/workspace/BackLink";import{jsx as M,jsxs as N,Fragment as P}from"react/jsx-runtime";const F=[[`details`,`Details`],[`sql`,`SQL & parameters`],[`test`,`Test`],[`versions`,`Versions`]],I=`h-9 w-full rounded-md border bg-background px-2 text-sm`;export function QueryPage(){let{id:e=`new`}=l(),t=k(),n=o({queryKey:[...O,`db-query`,e],queryFn:({signal:t})=>m.get(e,t),enabled:e!==`new`&&t.readable,retry:!1,staleTime:1/0});return t.readable?t.scope.ready?e!==`new`&&n.isPending?M(x,{children:`Loading the query…`}):n.isError?M(`p`,{role:`alert`,children:C(n.error)}):M(L,{query:n.data?.data,etag:n.data?.etag??``},n.data?.etag??`new`):M(_,{children:`Queries belong to one customer.`}):M(`p`,{role:`alert`,children:`You may not view integrations.`})}function L({query:o,etag:l}){let _=k(),x=c(),L=s(),[z,B]=u(),me=de(_),he=fe(_),ge=pe(_.scope.tenantId),V=o?se(o):T,[H,_e]=i(V),[U,ve]=i({}),[W,ye]=i(null),G=F.find(([e])=>e===z.get(`tab`))?.[0]??`details`,K=JSON.stringify(H)!==JSON.stringify(V),q=e=>_e({...H,...e}),J=e=>{L.invalidateQueries({queryKey:[...O,`db-query`]}),ge(),x(`${p.dbQueries}/${e}?tab=${G}`,{replace:!0})},Y=a({mutationFn:()=>m.save(ue(H),_.scope.tenantId),onSuccess:e=>{A.success(o?`Query saved.`:`Query created.`),J(e.data.id)}}),X=a({mutationFn:()=>m.test(o.id,Object.fromEntries(H.parameters.map(e=>[e.name,ce(e,U[e.name]??``)]).filter(([,e])=>e!==void 0)),l),onSuccess:e=>{ye(e),e.query.version!==o.version&&J(e.query.id)}}),Z=a({mutationFn:()=>m.publish(o.id,l),onSuccess:e=>{A.success(`Query published.`),J(e.data.id)}}),Q=a({mutationFn:()=>m.retire(o.id,l),onSuccess:e=>{A.success(`Query retired.`),J(e.data.id)}}),be=he.data?.find(e=>e.latest.name===o?.name)?.versions??[],xe=oe.test(H.name)&&!!H.data_source_id&&H.statement.trim(),$=Y.error??X.error??Z.error??Q.error;return N(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[M(j,{to:`${p.databases}?view=queries`,children:`Queries`}),M(v,{title:o?o.name:`New query`,icon:f,description:o?`Version ${o.version_no}`:`One SQL statement tools run by name.`,pills:o&&M(S,{status:o.status}),actions:_.writable&&N(P,{children:[K&&M(`span`,{className:`text-xs font-semibold text-warning-foreground`,children:`Unsaved changes`}),N(h,{disabled:!K||!xe||Y.isPending,onClick:()=>Y.mutate(),children:[M(re,{}),` `,Y.isPending?`Saving…`:o?`Save new version`:`Save query`]}),o?.status===`tested`&&!K&&N(h,{disabled:Z.isPending,onClick:()=>Z.mutate(),children:[M(ne,{}),` `,Z.isPending?`Publishing…`:`Publish`]}),o&&o.status!==`retired`&&!K&&N(ae,{destructive:!0,title:`Retire ${o.name} v${o.version_no}?`,detail:`Tools stop running it when it is the live version.`,action:`Retire`,pending:Q.isPending,onConfirm:()=>Q.mutate(),children:[M(d,{}),` Retire`]})]})}),M(`nav`,{"aria-label":`Query views`,className:y(t,`mb-3`),children:F.map(([e,t])=>M(`button`,{type:`button`,"aria-current":G===e?`page`:void 0,onClick:()=>B(t=>{let n=new URLSearchParams(t);return e===`details`?n.delete(`tab`):n.set(`tab`,e),n},{replace:!0}),className:n(G===e),children:t},e))}),$&&M(`p`,{role:`alert`,className:`mb-3 rounded-lg border border-destructive/40 p-2.5 text-xs text-destructive`,children:C($)}),N(`fieldset`,{disabled:!_.writable,className:`min-w-0`,children:[G===`details`&&N(`section`,{"aria-label":`Details`,className:`grid gap-3 rounded-xl border bg-card p-4 md:grid-cols-2`,children:[M(b,{id:`q-name`,label:`Name`,hint:`Dotted lower-case words, e.g. orders.open_by_customer`,children:M(g,{id:`q-name`,value:H.name,disabled:!!o,className:`font-mono text-xs`,onChange:e=>q({name:e.target.value})})}),M(b,{id:`q-source`,label:`Database`,children:N(`select`,{id:`q-source`,className:I,value:H.data_source_id,onChange:e=>q({data_source_id:e.target.value}),children:[M(`option`,{value:``,children:`Choose…`}),(me.data??[]).map(e=>M(`option`,{value:e.id,children:e.display_name??e.name},e.id))]})}),M(b,{id:`q-effect`,label:`Kind`,hint:`A read runs READ ONLY; a write needs a database that allows writes.`,children:N(`select`,{id:`q-effect`,className:I,value:H.side_effect,onChange:e=>q({side_effect:e.target.value}),children:[M(`option`,{value:`read`,children:`Read`}),M(`option`,{value:`write`,children:`Write`})]})}),N(`div`,{className:`grid grid-cols-2 gap-2`,children:[M(b,{id:`q-rows`,label:`Max rows`,children:M(e,{id:`q-rows`,min:1,max:1e4,value:H.max_rows,onValueChange:e=>q({max_rows:e})})}),M(b,{id:`q-timeout`,label:`Timeout (ms)`,children:M(e,{id:`q-timeout`,min:100,max:12e4,value:H.timeout_ms,onValueChange:e=>q({timeout_ms:e})})})]})]}),G===`sql`&&N(`section`,{"aria-label":`SQL`,className:`space-y-3 rounded-xl border bg-card p-4`,children:[M(b,{id:`q-sql`,label:`Statement`,hint:`One statement. Write :name for a parameter; values are bound, never pasted into the SQL.`,children:M(ie,{id:`q-sql`,rows:10,value:H.statement,className:`font-mono text-xs`,placeholder:`SELECT number, status FROM orders WHERE customer_id = :customer_id`,onChange:e=>q({statement:e.target.value,parameters:le(e.target.value,H.parameters)})})}),H.parameters.length===0?M(`p`,{className:`text-xs text-muted-foreground`,children:`No parameters.`}):N(r,{searchInHeader:!0,className:`w-full text-xs`,"aria-label":`Parameters`,children:[M(`thead`,{className:`text-left text-muted-foreground`,children:N(`tr`,{children:[M(`th`,{className:`py-1 font-medium`,children:`Parameter`}),M(`th`,{className:`py-1 font-medium`,children:`Type`}),M(`th`,{className:`py-1 font-medium`,children:`Format`}),M(`th`,{className:`py-1 font-medium`,children:`Required`})]})}),M(`tbody`,{className:`divide-y`,children:H.parameters.map((e,t)=>{let n=e=>q({parameters:H.parameters.map((n,r)=>r===t?{...n,...e}:n)});return N(`tr`,{children:[N(`td`,{className:`py-1.5 font-mono`,children:[`:`,e.name]}),M(`td`,{className:`py-1.5 pr-2`,"data-grid-value":e.type,children:M(`select`,{"aria-label":`${e.name} type`,className:y(I,`h-7 text-xs`),value:e.type,onChange:e=>n({type:e.target.value}),children:D.map(e=>M(`option`,{children:e},e))})}),M(`td`,{className:`py-1.5 pr-2`,"data-grid-value":e.format||`text`,children:M(`select`,{"aria-label":`${e.name} format`,className:y(I,`h-7 text-xs`),value:e.format,disabled:e.type!==`string`,onChange:e=>n({format:e.target.value}),children:E.map(e=>M(`option`,{value:e,children:e||`text`},e))})}),M(`td`,{className:`py-1.5`,"data-grid-value":e.required?`Required`:`Optional`,children:M(`input`,{type:`checkbox`,"aria-label":`${e.name} required`,checked:e.required,onChange:e=>n({required:e.target.checked})})})]},e.name)})})]})]})]}),G===`test`&&M(`section`,{"aria-label":`Test`,className:`space-y-3 rounded-xl border bg-card p-4`,children:!o||K?M(`p`,{className:`text-xs text-muted-foreground`,children:`Save the query first: a test runs a saved version.`}):N(P,{children:[M(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:H.parameters.map(e=>M(b,{id:`q-in-${e.name}`,label:`${e.name}${e.required?` *`:``}`,children:M(g,{id:`q-in-${e.name}`,value:U[e.name]??``,className:`font-mono text-xs`,placeholder:e.format||e.type,onChange:t=>ve({...U,[e.name]:t.target.value})})},e.name))}),N(h,{disabled:!_.writable||X.isPending,onClick:()=>X.mutate(),children:[M(te,{}),` `,X.isPending?`Running…`:`Run test`]}),o.side_effect===`write`&&M(`p`,{className:`text-xs text-muted-foreground`,children:`A test of a write query is rolled back: it shows what would change and saves nothing. The change is saved when a tool runs the published query.`}),W&&M(R,{run:W,write:o.side_effect===`write`})]})}),G===`versions`&&M(`section`,{"aria-label":`Versions`,className:`overflow-hidden rounded-xl border bg-card`,children:N(r,{searchInHeader:!0,className:`w-full text-left text-sm`,"aria-label":`Versions`,children:[M(`thead`,{className:`bg-muted/60 text-xs text-muted-foreground`,children:M(`tr`,{children:[`Version`,`Status`,`Saved`].map(e=>M(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:e},e))})}),M(`tbody`,{className:`divide-y`,children:be.toSorted((e,t)=>t.version_no-e.version_no).map(e=>N(`tr`,{children:[M(`td`,{className:`px-3 py-2 text-xs`,children:N(ee,{to:`${p.dbQueries}/${e.id}`,className:`text-primary hover:underline`,children:[`v`,e.version_no]})}),M(`td`,{className:`px-3 py-2`,"data-grid-value":e.status,children:M(S,{status:e.status})}),M(`td`,{className:`px-3 py-2 text-xs`,"data-grid-sort":e.created_at,children:w(e.created_at)})]},e.id))})]})})]})}function R({run:e,write:t}){if(!e.ok)return N(`p`,{role:`alert`,className:`text-xs text-destructive`,children:[`Failed: `,e.error]});let n=[...new Set(e.rows.flatMap(e=>Object.keys(e)))];return N(`div`,{className:`space-y-1`,children:[N(`output`,{className:`block text-xs text-muted-foreground`,children:[e.count,` row`,e.count===1?``:`s`,t?` would change · rolled back, nothing saved`:``,e.truncated?` (more rows were cut off at the limit)`:``,` · `,e.duration_ms,` ms`]}),n.length>0&&M(`div`,{className:`overflow-x-auto rounded-lg border`,children:N(r,{searchInHeader:!0,className:`w-full text-xs`,"aria-label":`Rows`,children:[M(`thead`,{className:`sticky top-0 bg-muted text-left`,children:M(`tr`,{children:n.map(e=>M(`th`,{"data-grid-label":e,className:`px-2 py-1 font-medium`,children:e},e))})}),M(`tbody`,{className:`divide-y`,children:e.rows.map((e,t)=>M(`tr`,{children:n.map(t=>M(`td`,{className:`px-2 py-1 font-mono`,children:typeof e[t]==`object`?JSON.stringify(e[t]):String(e[t]??``)},t))},t))})]})})]})}
@@ -0,0 +1,8 @@
1
+ export type SystemTab = 'details' | 'authentication' | 'parameters' | 'endpoints' | 'mappings' | 'settings' | 'test';
2
+ /**
3
+ * One external system on its own page (`/integration/systems/<id>/<tab>`): the connection
4
+ * (Details), Authentication, Parameters (default headers), Endpoints (its versioned actions),
5
+ * Mappings, Settings (timeout and network guard) and Test. Form tabs share one draft and
6
+ * one Save; `new` creates the system.
7
+ */
8
+ export declare function SystemPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{useState as e}from"react";import{useMutation as t,useQuery as n,useQueryClient as r}from"@tanstack/react-query";import{Link as i,useNavigate as a,useParams as o,useSearchParams as ee}from"react-router-dom";import{Cable as te,CircleCheck as s,CircleX as c,Download as ne,FileUp as re,FlaskConical as ie,GitMerge as l,KeyRound as ae,Library as oe,ListTree as u,PlugZap as se,Plus as ce,Rocket as le,Save as ue,Settings2 as d,SlidersHorizontal as f,Trash2 as de,TriangleAlert as fe,Waypoints as p}from"lucide-react";import{paths as m}from"@/app/paths";import{checkConnector as pe,exportSystemCollection as me,connectors as h,publishSystemCollection as he}from"@/shared/api/integrations";import{getMappings as g}from"@/shared/api/message-mappings";import{MappingsUnavailable as _}from"../components/mappings/MappingsUnavailable";import{ErrorNotice as v}from"@/shared/components/layout/ErrorNotice";import{Button as y,buttonVariants as ge}from"@/shared/components/ui/button";import{Input as b}from"@/shared/components/ui/input";import{Textarea as _e}from"@/shared/components/ui/textarea";import{ChooseTenant as x}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as ve}from"@/shared/components/workspace/ControlHeader";import{PersonName as ye}from"@/shared/components/workspace/PersonName";import{SplitButton as be}from"@/shared/components/workspace/SplitButton";import{cn as S}from"@/shared/lib/utils";import{ActionsTab as xe}from"../components/ActionsTab";import{connectorProblems as Se,fromConnector as Ce,toConnectorWrite as C}from"../model/connector-form";import{connectorType as we}from"../model/connector-types";import{SaveError as Te}from"../components/EditorForm";import{SystemLabelsFields as Ee}from"../components/SystemLabelsFields";import{Confirm as De,Empty as w,Field as T,Loading as E,MethodBadge as Oe,PairsEditor as ke,Pill as D,StatusPill as Ae,Tabs as je}from"../components/parts";import{described as O,fieldClass as Me,formatTime as k,kindLabel as Ne}from"../model/presentation";import{fieldProblems as Pe,problemMessage as Fe}from"../model/problems";import{useResourceSave as Ie}from"../hooks/useResourceSave";import{SystemIcon as Le}from"../components/SystemIcon";import{labelsOf as A}from"../model/system-labels";import{collectionsKey as Re,connectorsKey as ze,useActionLines as Be,useDetail as j,useProfiles as Ve,useStudio as M}from"../hooks/useStudio";import{notify as N}from"@/shared/lib/notify";import{BackLink as P}from"@/shared/components/workspace/BackLink";import{useGoBack as He}from"@/shared/hooks/useGoBack";import{jsx as F,jsxs as I,Fragment as L}from"react/jsx-runtime";const R=[[`details`,`Details`,u,!1],[`authentication`,`Authentication`,ae,!1],[`parameters`,`Parameters`,f,!1],[`endpoints`,`Endpoints`,p,!0],[`mappings`,`Mappings`,l,!0],[`settings`,`Settings`,d,!1],[`test`,`Test`,ie,!0]],z={name:`details`,display_name:`details`,description:`details`,base_url:`details`,enabled:`details`,icon:`details`,access:`details`,lines_of_business:`details`,tags:`details`,auth_profile_id:`authentication`,headers:`parameters`,timeout_ms:`settings`,allowed_hosts:`settings`,allow_private_network:`settings`};function Ue({result:e}){return I(`output`,{className:S(`flex items-start gap-2 rounded-lg border p-3 text-sm`,e.ok?`border-success/30 bg-success/5 text-success-foreground`:`border-destructive/30 bg-destructive/5 text-destructive`),children:[e.ok?F(s,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":`true`}):F(c,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":`true`}),I(`span`,{children:[F(`strong`,{children:e.ok?`Connection check passed`:`Connection check failed`}),e.error_code&&F(`code`,{className:`ml-1 rounded bg-muted px-1`,children:e.error_code}),e.message&&F(`span`,{className:`block text-foreground/80`,children:e.message}),e.ok&&F(`span`,{className:`block text-foreground/80`,children:`Network guard and authentication are fine. No endpoint was called.`})]})]})}const We=(e,t)=>t?F(`section`,{"aria-label":`Endpoint`,children:t}):e;function B({title:e,hint:t,children:n}){return I(`section`,{className:`rounded-xl border bg-card p-4`,children:[F(`h2`,{className:`text-sm font-semibold`,children:e}),t&&F(`p`,{className:`mb-3 text-xs text-muted-foreground`,children:t}),F(`div`,{className:S(!t&&`mt-3`),children:n})]})}export function SystemPage(){let{id:e=``,tab:t}=o(),n=M(),r=e===`new`,i=j(`connector`,r?``:e,h.get);if(!n.readable)return F(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`});if(!n.scope.ready)return F(x,{children:`Systems, credentials and endpoints belong to one customer.`});if(!r&&i.isPending)return F(E,{children:`Loading system…`});if(!r&&i.isError)return F(v,{error:i.error,retry:()=>void i.refetch()});let a=R.find(([e])=>e===t)?.[0]??`details`;return F(V,{saved:r?void 0:i.data,studio:n,tab:a},i.data?`${i.data.data.id}-${i.data.data.version}`:`new`)}function V({saved:n,studio:o,tab:s}){let c=a(),{goBack:ie}=He(m.systems),[l]=ee(),ae=n?void 0:we(l.get(`type`)??`rest`),u=Ce(n?.data),[d,f]=e(u),[p,g]=e(!1),_=Ve(o),ge=Be(o),x=n?.data,E=`${m.systems}/${x?.id??`new`}`,j=e=>c(e===`details`?E:`${E}/${e}`),{save:M,remove:V,reload:Ke}=Ie(`connector`,h,n,{tenantId:o.scope.tenantId,listKey:ze(o.scope.tenantId),onSaved:e=>c(`${m.systems}/${e}${s===`details`?``:`/${s}`}`,{replace:!0}),onDeleted:()=>c(m.systems)}),H=t({mutationFn:()=>pe(x?.id??``),onSuccess:e=>e.ok?N.success(`Connection check passed.`):N.failure(`Connection check failed: ${e.message??e.error_code??`no answer`}.`),onError:e=>N.error(`The connection check could not run: ${e.message}`)}),U=t({mutationFn:()=>me(x?.id??``),onSuccess:e=>{let t=new Blob([`${JSON.stringify(e,null,2)}\n`],{type:`application/json`}),n=URL.createObjectURL(t),r=window.document.createElement(`a`);r.href=n,r.download=`${x?.name??`system`}.json`,r.click(),URL.revokeObjectURL(n)},onError:e=>N.error(`The system could not be exported: ${e.message}`)}),qe=r(),W=t({mutationFn:()=>he(x?.id??``,o.scope.tenantId),onSuccess:()=>{N.success(`Published to the Connector Library. Every team can now install it.`),qe.invalidateQueries({queryKey:Re(o.scope.tenantId)})},onError:e=>N.error(`The system could not be published: ${Fe(e)}`)}),G=e=>{f(t=>({...t,...e})),M.error&&M.reset()},K=Se(d),q=!n||JSON.stringify(C(d))!==JSON.stringify(C(u)),Je=Pe(M.error,{name:`name`,display_name:`display_name`,description:`description`,base_url:`base_url`,auth_profile_id:`auth_profile_id`,default_headers:`headers`,timeout_ms:`timeout_ms`,allowed_hosts:`allowed_hosts`,icon:`icon`,access:`access`,lines_of_business:`lines_of_business`,tags:`tags`},{CONNECTOR_EXISTS:`name`}),J=e=>Je.fields[e]??(q?K[e]:void 0),Ye=new Set(Object.keys(z).filter(e=>J(e)).map(e=>z[e])),Y=(ge.data??[]).filter(e=>e.latest.connector_id===x?.id),X=Y.filter(e=>e.live).length,Z=(_.data??[]).find(e=>e.id===d.auth_profile_id),Q=s===`details`||s===`authentication`||s===`parameters`||s===`settings`,$=o.writable;return s===`endpoints`&&x&&o.selected?I(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[F(P,{to:`${E}/endpoints`,children:`${x.display_name??x.name} endpoints`}),F(xe,{studio:o,fixedConnector:x.id,split:We})]}):I(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[F(P,{to:m.systems,children:`Systems`}),F(ve,{title:x?x.display_name??x.name:`New system`,icon:te,media:x&&A(x).logo?F(Le,{logo:A(x).logo,enabled:x.enabled,className:`size-10 rounded-lg`}):void 0,description:x?x.description||x.base_url:`Where the system lives and how calls reach it.`,pills:x?x&&I(L,{children:[F(D,{className:x.enabled?`bg-success/10 text-success-foreground`:void 0,children:x.enabled?`Enabled`:`Disabled`}),I(D,{children:[`v`,x.version]}),X>0&&I(D,{className:`bg-success/10 text-success-foreground`,children:[F(le,{className:`mr-1 inline size-3`,"aria-hidden":`true`}),X,` live`]})]}):F(D,{className:`bg-viz-2/12 text-viz-2`,children:ae?.label??`REST API`}),actions:I(L,{children:[$&&Q&&I(y,{type:`submit`,form:`system-form`,disabled:!q||Object.keys(K).length>0||M.isPending,children:[F(ue,{}),M.isPending?`Saving…`:n?`Save`:`Create system`]}),$&&(Q||!n)&&F(y,{type:`button`,variant:`outline`,onClick:ie,children:`Cancel`}),x&&$&&s===`endpoints`&&I(be,{onClick:()=>o.select(`new`),menuLabel:`Other ways to add endpoints`,actions:[{label:`Import`,icon:re,onSelect:()=>o.select(`import`)}],children:[F(ce,{}),` Endpoint`]}),x&&$&&I(y,{variant:`outline`,disabled:H.isPending,onClick:()=>H.mutate(),children:[F(se,{}),H.isPending?`Checking…`:`Check connection`]}),x&&I(y,{variant:`outline`,disabled:U.isPending,onClick:()=>U.mutate(),title:`Download the system, its endpoints and mappings as a collection file`,children:[F(ne,{}),U.isPending?`Exporting…`:`Export`]}),x&&$&&!x.platform&&o.scope.platform&&I(y,{variant:`outline`,disabled:W.isPending||q,onClick:()=>W.mutate(),title:q?`Save your changes first: Publish shares the saved system`:`Share the system, its endpoints and mappings in the Connector Library (no credentials)`,children:[F(oe,{}),W.isPending?`Publishing…`:`Publish`]}),x&&$&&I(y,{variant:`destructive`,onClick:()=>g(!0),children:[F(de,{}),`Delete`]})]})}),p&&x&&F(De,{destructive:!0,title:I(L,{children:[`Delete `,F(`strong`,{children:x.display_name??x.name}),`?`]}),action:`Delete system`,pending:V.isPending,error:V.error&&F(v,{error:V.error}),onCancel:()=>g(!1),onConfirm:()=>V.mutate(),children:X?`${X} live endpoint(s) use it: the delete is refused until they are retired.`:`Its call log stays.`}),H.data&&s!==`test`&&F(`div`,{className:`mb-3`,children:F(Ue,{result:H.data})}),F(je,{label:`System sections`,idPrefix:`system`,value:s,onChange:j,className:`mb-3`,items:R.map(([e,t,n,r])=>({value:e,label:I(`span`,{className:S(`inline-flex items-center gap-1.5 text-sm`,r&&!x&&`opacity-50`),children:[F(n,{className:`size-4`,"aria-hidden":`true`}),t,e===`endpoints`&&x&&F(`span`,{className:`rounded-badge bg-muted px-2 text-[12px] text-muted-foreground`,children:Y.length}),Ye.has(e)&&F(`span`,{className:`size-1.5 rounded-full bg-destructive`,"aria-label":`has problems`})]})}))}),I(`div`,{role:`tabpanel`,id:`system-panel-${s}`,"aria-labelledby":`system-tab-${s}`,className:`flex min-h-0 flex-1 flex-col gap-3`,children:[Q&&I(`form`,{id:`system-form`,"aria-label":`System`,className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),Object.keys(K).length===0&&M.mutate(C(d))},children:[s===`details`&&I(B,{title:`Connection`,hint:`The system's name and the base URL every endpoint is called on.`,children:[I(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[F(T,{id:`system-name`,label:`Name`,error:J(`name`),hint:`Unique key used by endpoints and flows.`,children:F(b,{...O(`system-name`,J(`name`),!0),className:`h-9 bg-card text-sm`,maxLength:64,placeholder:`crm`,readOnly:!$,value:d.name,onChange:e=>G({name:e.target.value})})}),F(T,{id:`system-display`,label:`Display name (optional)`,error:J(`display_name`),children:F(b,{...O(`system-display`,J(`display_name`)),className:`h-9 bg-card text-sm`,maxLength:120,placeholder:`CRM`,readOnly:!$,value:d.display_name,onChange:e=>G({display_name:e.target.value})})}),F(T,{id:`system-description`,label:`Description (optional)`,error:J(`description`),className:`sm:col-span-2`,hint:`What the system is and what flows and agents use it for.`,children:F(_e,{...O(`system-description`,J(`description`)),rows:2,maxLength:1e3,readOnly:!$,className:`bg-card text-sm`,placeholder:`Order management system: orders, changes and renewals.`,value:d.description,onChange:e=>G({description:e.target.value})})}),F(T,{id:`system-url`,label:`Base URL`,error:J(`base_url`),className:`sm:col-span-2`,hint:I(L,{children:[`Endpoints use it as `,F(`code`,{children:`{{base}}`}),`. Only this host and the allowed hosts (Settings) can be reached.`]}),children:F(b,{...O(`system-url`,J(`base_url`),!0),className:`h-9 bg-card text-sm`,maxLength:2048,placeholder:`https://<instance>.example.com`,readOnly:!$,value:d.base_url,onChange:e=>G({base_url:e.target.value})})})]}),I(`label`,{className:`mt-3 flex items-center gap-2 text-sm`,children:[F(`input`,{type:`checkbox`,className:`size-4 accent-primary`,disabled:!$,checked:d.enabled,onChange:e=>G({enabled:e.target.checked})}),`Enabled`,F(`span`,{className:`text-xs text-muted-foreground`,children:`Flows and agents call only enabled systems. Tests and checks work either way.`})]}),x&&F(`dl`,{className:`mt-4 grid grid-cols-2 gap-3 border-t pt-3 text-xs sm:grid-cols-4`,children:[[`Endpoints`,`${Y.length} (${X} live)`],[`Authentication`,Z?Z.display_name??Z.name:`None`],[`Updated`,I(L,{children:[k(x.updated_at),x.updated_by&&I(L,{children:[` · `,F(ye,{subject:x.updated_by})]})]})],[`Created`,k(x.created_at)]].map(([e,t])=>I(`div`,{children:[F(`dt`,{className:`text-muted-foreground`,children:e}),F(`dd`,{className:`mt-0.5 text-sm`,children:t})]},e))})]}),s===`details`&&F(B,{title:`Logo and labels`,hint:`What the system's card and list row show: its logo, Paid or Free, lines of business and tags.`,children:F(Ee,{draft:d,set:G,writable:$,tagsError:J(`tags`)})}),s===`authentication`&&I(B,{title:`Authentication`,hint:`The credential every call to this system uses. Secrets stay in the key vault; credentials are managed under Integration › Credentials.`,children:[F(T,{id:`system-profile`,label:`Credential (auth profile)`,error:J(`auth_profile_id`),children:I(`select`,{id:`system-profile`,className:S(Me,`h-9 max-w-md text-sm`),disabled:!$,value:d.auth_profile_id,onChange:e=>G({auth_profile_id:e.target.value}),children:[F(`option`,{value:``,children:`None (unauthenticated)`}),(_.data??[]).map(e=>I(`option`,{value:e.id,children:[e.name,` · `,Ne(e.kind)]},e.id))]})}),Z?I(`dl`,{className:`mt-3 grid max-w-2xl grid-cols-3 gap-3 rounded-lg border p-3 text-xs`,children:[I(`div`,{children:[F(`dt`,{className:`text-muted-foreground`,children:`Type`}),F(`dd`,{className:`mt-0.5 text-sm`,children:Ne(Z.kind)})]}),I(`div`,{children:[F(`dt`,{className:`text-muted-foreground`,children:`Secret reference`}),F(`dd`,{className:`mt-0.5 truncate text-sm`,children:Z.secret_ref??`—`})]}),I(`div`,{children:[F(`dt`,{className:`text-muted-foreground`,children:`Updated`}),F(`dd`,{className:`mt-0.5 text-sm`,children:k(Z.updated_at)})]})]}):F(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Calls go out without credentials. Pick a credential if the system needs one.`}),F(i,{to:Z?`${m.credentials}?item=${Z.id}`:m.credentials,className:`mt-3 inline-block text-sm text-primary hover:underline`,children:Z?`Open this credential`:`Manage credentials`})]}),s===`parameters`&&F(B,{title:`Parameters`,hint:`Default headers sent on every call to this system. Authorization, Cookie and Host are set by the platform.`,children:F(ke,{label:`Default headers`,keyLabel:`Header name`,valueLabel:`Header value`,keyPlaceholder:`Accept`,valuePlaceholder:`application/json`,rows:d.headers,error:J(`headers`),onChange:e=>G({headers:e})})}),s===`settings`&&I(B,{title:`Settings`,hint:`Timeout and the network guard for calls to this system.`,children:[I(`div`,{className:`grid max-w-3xl gap-3 sm:grid-cols-2`,children:[F(T,{id:`system-timeout`,label:`Timeout (ms)`,error:J(`timeout_ms`),children:F(b,{...O(`system-timeout`,J(`timeout_ms`)),type:`number`,min:100,max:12e4,className:`h-9 bg-card text-sm`,readOnly:!$,value:d.timeout_ms,onChange:e=>G({timeout_ms:e.target.value})})}),F(T,{id:`system-hosts`,label:`Allowed hosts (optional)`,error:J(`allowed_hosts`),className:`sm:col-span-2`,hint:`Extra hosts a call may reach, one per line (e.g. the OAuth token host); *.domain allowed.`,children:F(_e,{...O(`system-hosts`,J(`allowed_hosts`),!0),rows:3,spellCheck:!1,readOnly:!$,className:`bg-card text-sm`,placeholder:`login.example.com`,value:d.allowed_hosts,onChange:e=>G({allowed_hosts:e.target.value})})})]}),I(`label`,{className:`mt-3 flex items-center gap-2 text-sm`,children:[F(`input`,{type:`checkbox`,className:`size-4 accent-primary`,disabled:!$,checked:d.allow_private_network,onChange:e=>G({allow_private_network:e.target.checked})}),`Allow private network`]}),d.allow_private_network&&I(`p`,{role:`note`,className:`mt-2 flex items-start gap-2 rounded-md bg-warning/10 p-2 text-xs text-warning-foreground`,children:[F(fe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":`true`}),`Development only: lifts the SSRF guard for loopback, private and link-local addresses and allows plain http. Never enable it in production.`]})]}),F(Te,{error:Je.rest,onReload:n?Ke:void 0}),$&&F(`p`,{className:`text-xs text-muted-foreground`,children:n?q?`Unsaved changes in this system.`:`All changes saved.`:`Save the system to add endpoints, mappings and tests.`})]}),!Q&&!x&&F(w,{children:`Save the system first; then add its endpoints, mappings and tests here.`}),s===`endpoints`&&x&&F(xe,{studio:o,fixedConnector:x.id,split:We}),s===`mappings`&&x&&F(Ge,{}),s===`test`&&x&&I(B,{title:`Test`,hint:`Check the connection without calling an endpoint, or dry-run / call one endpoint with test input.`,children:[I(y,{variant:`outline`,disabled:!$||H.isPending,onClick:()=>H.mutate(),children:[F(se,{}),H.isPending?`Checking…`:`Check connection`]}),I(`div`,{className:`mt-3`,children:[H.data&&F(Ue,{result:H.data}),H.error&&F(v,{error:H.error})]}),F(`h3`,{className:`mt-4 mb-2 text-xs font-medium text-muted-foreground`,children:`Test an endpoint`}),Y.length===0?F(`p`,{className:`text-sm text-muted-foreground`,children:`No endpoints yet. Add one on the Endpoints tab.`}):F(`ul`,{className:`divide-y rounded-lg border`,children:Y.map(({latest:e})=>I(`li`,{className:`flex items-center gap-2 px-3 py-2 text-sm`,children:[F(Oe,{method:e.method}),F(`span`,{className:`font-medium`,title:e.name,children:e.display_name||e.name}),F(Ae,{status:e.status}),F(y,{size:`sm`,variant:`outline`,className:`ml-auto`,onClick:()=>c(`${m.systems}/${x.id}/endpoints?item=${e.id}&view=test`),children:`Test`})]},e.id))})]})]})]})}function Ge(){let e=M(),t=n({queryKey:[`message-mappings`,e.scope.tenantId??`own`],queryFn:({signal:t})=>g(e.scope.tenantId,t),enabled:e.scope.ready,retry:!1});return I(B,{title:`Mappings`,hint:`Message mappings transform a source message into what an endpoint expects (or its response into your model). Design them on the drag-and-drop canvas.`,children:[F(`div`,{className:`mb-3 flex justify-end`,children:I(i,{to:`${m.mappings}/new`,className:ge(),children:[F(l,{}),`New mapping`]})}),t.isPending?F(E,{children:`Loading mappings…`}):t.isError?F(_,{error:t.error,retry:()=>void t.refetch()}):t.data.length===0?F(w,{children:`No mappings yet. Create one and drag source fields onto target fields.`}):F(`ul`,{className:`divide-y rounded-lg border`,children:t.data.map(e=>I(`li`,{className:`flex items-center gap-3 px-3 py-2 text-sm`,children:[F(i,{to:`${m.mappings}/${e.id}`,className:`font-semibold text-primary hover:underline`,children:e.display_name??e.name}),I(`span`,{className:`text-xs text-muted-foreground`,children:[`v`,e.version_no]}),F(D,{children:e.status}),F(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.description}),F(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:k(e.updated_at)})]},e.id))})]})}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Systems: every external system the platform calls (a connector), with its authentication
3
+ * and endpoints. Each system opens as its own page; a new one starts on its Details tab.
4
+ */
5
+ export declare function SystemsPage(): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{DataTable as e}from"@/shared/components/workspace/DataTable";import{GridHeader as t,GridHeaderSlot as n}from"@/shared/components/workspace/GridHeader";import{useState as r}from"react";import{Link as i,Navigate as a,useNavigate as o,useSearchParams as s}from"react-router-dom";import{ArrowUpRight as c,Cable as l,FileJson as ee,Globe as u,KeyRound as d,Plus as f,Rocket as p,Search as te,Send as m,ShieldCheck as h,Sparkles as g,Waypoints as _}from"lucide-react";import{connectors as v}from"@/shared/api/integrations";import{paths as y}from"@/app/paths";import{ErrorNotice as ne}from"@/shared/components/layout/ErrorNotice";import{Input as re}from"@/shared/components/ui/input";import{ChooseTenant as ie}from"@/shared/components/workspace/ChooseTenant";import{ControlHeader as ae}from"@/shared/components/workspace/ControlHeader";import{SplitButton as b}from"@/shared/components/workspace/SplitButton";import{ViewToggle as x}from"@/shared/components/workspace/ViewToggle";import{useViewMode as S}from"@/shared/hooks/useViewMode";import{formatNumber as C}from"@/shared/lib/format";import{matchesSearch as w}from"@/shared/lib/search";import{cn as T}from"@/shared/lib/utils";import{ConnectorTypePicker as E}from"../components/ConnectorTypePicker";import{EnabledSwitch as D}from"@/shared/components/workspace/EnabledSwitch";import{ImportSystemDialog as O}from"../components/ImportSystemDialog";import{Empty as oe,Loading as se}from"../components/parts";import{fromConnector as k,toConnectorWrite as A}from"../model/connector-form";import{labelsOf as j,lineOfBusinessLabels as M}from"../model/system-labels";import{SystemIcon as N}from"../components/SystemIcon";import{SystemPills as P}from"../components/SystemPills";import{formatTime as F,kindLabel as I}from"../model/presentation";import{connectorsKey as L,detailKey as R,useActionLines as z,useConnectors as B,useProfiles as V,useStudio as H}from"../hooks/useStudio";import{jsx as U,jsxs as W}from"react/jsx-runtime";const G={"import-openai":`openai`,"import-openapi":`openapi`,"import-postman":`postman`},ce=e=>{try{return new URL(e).host}catch{return e}};function K(){return W(`span`,{className:`inline-flex shrink-0 items-center gap-1 rounded-badge bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,title:`Shipped with the platform`,children:[U(h,{className:`size-3`,"aria-hidden":`true`}),`Platform`]})}function q({system:e,writable:t}){return U(D,{name:e.display_name??e.name,what:`System`,enabled:e.enabled,disabled:!t||e.platform,save:t=>v.update(e.id,{...A(k(e)),enabled:t},`"${e.version}"`),refresh:[L(e.tenant_id),R(`connector`,e.id)]})}const J=e=>e===1?`1 endpoint`:`${C(e)} endpoints`;function le({count:e,live:t}){let n=`${C(t)} live`;return W(`span`,{className:`inline-flex items-center gap-3 font-medium tabular-nums`,children:[W(`span`,{className:`inline-flex items-center gap-1.5 text-foreground`,title:J(e),children:[U(_,{className:`size-3.5 shrink-0 text-workspace`,"aria-hidden":`true`}),U(`span`,{"aria-hidden":`true`,children:C(e)}),U(`span`,{className:`sr-only`,children:J(e)})]}),t>0&&W(`span`,{className:`inline-flex items-center gap-1 text-success-foreground`,title:n,children:[U(p,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),U(`span`,{"aria-hidden":`true`,children:C(t)}),U(`span`,{className:`sr-only`,children:n})]})]})}function ue({count:e,live:t}){return W(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-0.5 tabular-nums`,children:[W(`span`,{className:`inline-flex items-center gap-1.5`,children:[U(_,{className:`size-3.5 shrink-0 text-workspace`,"aria-hidden":`true`}),U(`span`,{className:`font-medium text-foreground`,children:J(e)})]}),t>0&&W(`span`,{className:`inline-flex items-center gap-1 rounded-badge bg-success/10 px-2 py-0.5 text-success-foreground`,children:[U(p,{className:`size-3`,"aria-hidden":`true`}),`${C(t)} live`]})]})}function Y({auth:e}){return e?W(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[U(d,{className:`size-3.5 shrink-0 text-workspace`,"aria-hidden":`true`}),W(`span`,{className:`min-w-0`,children:[U(`span`,{className:`block truncate font-medium text-foreground`,title:e.name,children:e.name}),U(`span`,{className:`block truncate text-muted-foreground`,children:I(e.kind)})]})]}):W(`span`,{className:`inline-flex items-center gap-1.5 text-muted-foreground`,children:[U(d,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),`No authentication`]})}function X({host:e,url:t,className:n}){return W(`span`,{className:T(`inline-flex max-w-full min-w-0 items-center gap-1.5 font-mono text-[11px] text-muted-foreground`,n),title:t,children:[U(u,{className:`size-3 shrink-0`,"aria-hidden":`true`}),U(`span`,{className:`truncate`,children:e})]})}function de({items:e}){let t=e.filter(({system:e})=>e.enabled).length,n=e.reduce((e,t)=>e+t.endpointCount,0),r=e.reduce((e,t)=>e+t.live,0),i=[e.length===1?`1 system`:`${C(e.length)} systems`,`${C(t)} enabled`,J(n),`${C(r)} live`];return U(`p`,{className:`hidden items-center gap-2 text-xs text-muted-foreground tabular-nums lg:flex`,children:i.map((e,t)=>W(`span`,{className:`inline-flex items-center gap-2`,children:[t>0&&U(`span`,{"aria-hidden":`true`,children:`·`}),e]},e))})}export function SystemsPage(){let[e]=s();if(e.get(`tab`)===`profiles`){let t=e.get(`item`);return U(a,{replace:!0,to:t?`${y.credentials}?item=${t}`:y.credentials})}return U(Z,{})}function Z(){let a=H(),s=o(),u=B(a),d=V(a),p=z(a),[h,_]=r(``),[v,D]=r(null),[k,A]=S(`sirius-systems-view`,`list`),[L,R]=r(!1),[J,Z]=r(null),Q=u.data??[],$=Q.map(e=>{let t=(p.data??[]).filter(t=>t.latest.connector_id===e.id);return{system:e,auth:(d.data??[]).find(t=>t.id===e.auth_profile_id),endpointCount:t.length,live:t.filter(e=>e.live).length,host:ce(e.base_url),updated:F(e.updated_at??e.created_at),labels:j(e)}}).filter(({system:e,auth:t,endpointCount:n,live:r,updated:i,labels:a})=>w(h,[e.name,e.display_name,e.description,e.base_url,t?.name??`None`,t&&I(t.kind),C(n),r?`${C(r)} live`:void 0,e.enabled?`Enabled`:`Disabled`,i,a.access&&(a.access===`free`?`Free`:`Paid`),...a.lines.map(e=>M[e]),...a.tags]));return W(`div`,{className:`workspace-admin flex min-h-0 flex-col`,children:[U(ae,{title:`Systems`,icon:l,description:`External systems the platform calls: where they live, how calls authenticate, and the endpoints you test, publish and monitor.`,actions:a.readable&&a.scope.ready&&a.writable&&W(b,{onClick:()=>R(!0),menuLabel:`Import a system`,actions:[{label:`Swagger`,icon:ee,onSelect:()=>Z(`openapi`)},{label:`Postman`,icon:m,onSelect:()=>Z(`postman`)},{label:`OpenAI`,icon:g,onSelect:()=>Z(`openai`)}],children:[U(f,{}),` System`]})}),a.readable?a.scope.ready?W(`section`,{"aria-label":`Systems`,className:T(k===`list`&&`overflow-hidden rounded-xl border bg-card`),children:[W(t,{className:T(k===`cards`&&`mb-3 rounded-xl border bg-card`),children:[W(`label`,{htmlFor:`system-search`,className:`relative min-w-0`,children:[U(`span`,{className:`sr-only`,children:`Search systems`}),U(te,{className:`pointer-events-none absolute top-2.5 left-2.5 size-4 text-muted-foreground`,"aria-hidden":`true`}),U(re,{id:`system-search`,type:`search`,className:`h-9 w-64 max-w-full bg-card pl-8 text-sm`,placeholder:`Search all columns`,value:h,onChange:e=>_(e.target.value)})]}),U(n,{ref:D}),W(`div`,{className:`ml-auto flex items-center gap-4`,children:[U(de,{items:$}),U(x,{mode:k,onChange:A})]})]}),u.isPending?U(se,{children:`Loading systems…`}):u.isError?U(ne,{error:u.error,retry:()=>void u.refetch()}):$.length===0?U(oe,{children:Q.length===0?`No systems yet. Add the first system you want agents and flows to call.`:`No system matches this search.`}):k===`cards`?U(`ul`,{"aria-label":`Systems`,className:`grid grid-cols-[repeat(auto-fill,minmax(min(100%,19rem),1fr))] gap-3`,children:$.map(({system:e,auth:t,endpointCount:n,live:r,host:o,labels:s})=>W(`li`,{className:T(`group relative flex min-w-0 flex-col overflow-hidden rounded-xl border bg-card text-card-foreground shadow-xs transition-[border-color,box-shadow] focus-within:border-workspace/60 hover:border-workspace/50 hover:shadow-md`,!e.enabled&&`bg-muted/30`),children:[W(`div`,{className:`flex flex-1 flex-col gap-3 p-4`,children:[W(`div`,{className:`flex items-start gap-3`,children:[U(N,{logo:s.logo,enabled:e.enabled,className:`size-11`}),W(`div`,{className:`min-w-0 flex-1`,children:[W(`h2`,{id:`system-card-${e.id}`,className:`flex items-center gap-1 text-[15px] leading-snug font-semibold`,children:[U(i,{to:`${y.systems}/${e.id}`,className:`min-w-0 truncate text-primary group-hover:underline after:absolute after:inset-0 after:rounded-xl focus-visible:outline-none`,children:e.display_name??e.name}),U(c,{className:`size-3.5 shrink-0 text-workspace opacity-0 transition-opacity group-hover:opacity-100`,"aria-hidden":`true`})]}),U(X,{host:o,url:e.base_url,className:`mt-1`})]}),W(`div`,{className:`relative z-10 flex shrink-0 flex-col items-end gap-1.5`,children:[U(q,{system:e,writable:a.writable}),e.platform&&U(K,{})]})]}),U(`p`,{className:`line-clamp-2 min-h-10 text-[13px] leading-5 wrap-anywhere text-muted-foreground`,children:e.description||(e.display_name?e.name:`No description yet.`)}),U(P,{labels:s})]}),W(`dl`,{className:`grid grid-cols-2 items-center gap-x-4 border-t bg-workspace-soft/40 px-4 py-3 text-xs`,children:[W(`div`,{className:`min-w-0`,children:[U(`dt`,{className:`sr-only`,children:`Authentication`}),U(`dd`,{children:U(Y,{auth:t})})]}),W(`div`,{className:`min-w-0`,children:[U(`dt`,{className:`sr-only`,children:`Endpoints`}),U(`dd`,{className:`relative z-10 inline-flex`,children:U(le,{count:n,live:r})})]})]})]},e.id))}):U(`div`,{className:`overflow-x-auto`,children:W(e,{externalSearch:!0,columnsToolbar:v,className:`w-full text-left text-sm`,children:[U(`caption`,{className:`sr-only`,children:`Systems`}),U(`thead`,{className:`border-b bg-muted/40 text-[11px] tracking-wide text-muted-foreground uppercase`,children:U(`tr`,{children:[`System`,`Labels`,`Base URL`,`Authentication`,`Endpoints`,`Updated`,`Enabled`].map(e=>U(`th`,{scope:`col`,className:`px-4 py-2.5 font-semibold`,children:e},e))})}),U(`tbody`,{className:`divide-y`,children:$.map(({system:e,auth:t,endpointCount:n,live:r,host:o,updated:s,labels:c})=>W(`tr`,{className:T(`transition-[background-color,box-shadow] hover:bg-workspace-soft/60 hover:shadow-[inset_3px_0_0_var(--workspace)]`,!e.enabled&&`bg-muted/25`),children:[U(`td`,{className:`px-4 py-3`,children:W(`div`,{className:`flex min-w-0 items-center gap-3`,children:[U(N,{logo:c.logo,enabled:e.enabled,className:`size-9 rounded-lg`}),W(`div`,{className:`min-w-0`,children:[W(`span`,{className:`flex items-center gap-2`,children:[U(i,{to:`${y.systems}/${e.id}`,className:`truncate font-semibold text-primary hover:underline`,children:e.display_name??e.name}),e.platform&&U(K,{})]}),(e.description||e.display_name)&&U(`span`,{className:`line-clamp-1 block max-w-md text-xs text-muted-foreground`,title:e.description?e.name:void 0,children:e.description||e.name})]})]})}),U(`td`,{className:`px-4 py-3`,"data-grid-value":[c.access&&(c.access===`free`?`Free`:`Paid`),...c.lines.map(e=>M[e]),...c.tags].filter(Boolean).join(` `),children:U(P,{labels:c,max:2,className:`w-56`})}),U(`td`,{className:`px-4 py-3`,"data-grid-value":o,children:U(X,{host:o,url:e.base_url,className:`max-w-56 rounded-md bg-muted/60 px-2 py-1`})}),U(`td`,{className:`px-4 py-3 text-xs`,"data-grid-value":t?`${t.name} ${I(t.kind)}`:`None`,children:U(Y,{auth:t})}),U(`td`,{className:`px-4 py-3 text-xs`,"data-grid-value":r?`${n} ${r} live`:n,"data-grid-sort":n,children:U(ue,{count:n,live:r})}),U(`td`,{className:`px-4 py-3 text-xs whitespace-nowrap text-muted-foreground`,"data-grid-sort":e.updated_at??e.created_at,children:s}),U(`td`,{className:`px-4 py-3`,"data-grid-value":e.enabled?`Enabled`:`Disabled`,children:U(q,{system:e,writable:a.writable})})]},e.id))})]})})]}):U(ie,{children:`Systems, credentials and endpoints belong to one customer.`}):U(`p`,{role:`alert`,children:`Your account does not have permission to view integrations.`}),L&&U(E,{onClose:()=>R(!1),onPick:e=>{let t=G[e];t?(R(!1),Z(t)):s(`${y.systems}/new?type=${e}`)}}),J&&U(O,{source:J,studio:a,onClose:()=>Z(null)})]})}
@@ -0,0 +1,5 @@
1
+ # Mailboxes
2
+
3
+ The mailboxes the platform reads email from (connectors: email accounts). Routes import
4
+ only `index.ts` (MailboxesPage). Features never import each other; shared code lives in
5
+ `@/shared`.
@@ -0,0 +1,5 @@
1
+ /** Register connection settings and a vault reference, then review the policy before polling. */
2
+ export declare function MailboxCreate({ close, created, }: {
3
+ close: () => void;
4
+ created: (id: string) => void;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{useState as e}from"react";import{Inbox as t}from"lucide-react";import{useMutation as n,useQuery as r,useQueryClient as i}from"@tanstack/react-query";import{createMailbox as a,testMailboxConnection as o}from"@/shared/api/administration";import{getTenants as s}from"@/shared/api/tenants";import{useSession as c}from"@/shared/auth/session-context";import{Button as l}from"@/shared/components/ui/button";import{Input as u}from"@/shared/components/ui/input";import{ErrorNotice as d}from"@/shared/components/layout/ErrorNotice";import{ControlHeader as f}from"@/shared/components/workspace/ControlHeader";import{notify as p}from"@/shared/lib/notify";import{jsxs as m,jsx as h,Fragment as g}from"react/jsx-runtime";function _({label:e,children:t}){return m(`label`,{className:`grid gap-2 text-sm font-medium`,children:[e,t]})}export function MailboxCreate({close:v,created:y}){let{user:b,can:x}=c(),S=i(),[C,w]=e(b?.tenant_id??``),[T,E]=e(`imap`),[D,O]=e(``),[k,A]=e(`INBOX`),[j,M]=e(``),[N,P]=e(`993`),[F,I]=e(``),[L,R]=e(``),[z,B]=e(!1),[V,H]=e(``),[U,W]=e(``),G=r({queryKey:[`tenants`],queryFn:({signal:e})=>s(e),enabled:!b?.tenant_id&&x(`admin.tenant.read`),staleTime:3e5}),K=n({mutationFn:e=>a(e),retry:!1,onSuccess:e=>{S.setQueryData([`admin`,`mailbox`,e.data.id],e),S.invalidateQueries({queryKey:[`admin`,`mailboxes`]}),p.success(`Mailbox created.`),y(e.data.id)}}),q=n({mutationFn:e=>o(e),retry:!1,onSuccess:e=>e.connected?p.success(e.message):p.failure(e.message),onError:e=>p.error(`Connection test failed: ${e.message}`)}),J=K.isPending||q.isPending,Y=()=>{J||v()},X=`h-10 w-full rounded-lg border bg-card px-3 text-sm`;return m(`form`,{"aria-label":`Add mailbox`,className:`space-y-4`,onChange:()=>{q.reset(),K.reset()},onSubmit:e=>{if(e.preventDefault(),J||!x(`admin.email_account.write`))return;let t={tenant_id:C,address:D.trim(),folder:k.trim(),enabled:!1},n=T===`imap`?{...t,provider:T,secret_ref:L.trim(),connection_config:{host:j.trim(),port:Number(N),...F.trim()?{username:F.trim()}:{}}}:{...t,provider:T,secret_ref:z?L.trim():null,connection_config:z?{app_tenant_id:V.trim(),client_id:U.trim()}:{}},r=e.nativeEvent.submitter;r instanceof HTMLButtonElement&&r.value===`test`?q.mutate(n):K.mutate(n)},children:[h(f,{title:`Add mailbox`,icon:t,description:`Add your existing mailbox. It starts disabled so you can review its policy before enabling polling.`,actions:m(g,{children:[h(l,{type:`submit`,disabled:J||!C||!x(`admin.email_account.write`),children:K.isPending?`Adding…`:`Add mailbox`}),h(l,{type:`submit`,name:`action`,value:`test`,variant:`outline`,disabled:J||!C||!x(`admin.email_account.write`),children:q.isPending?`Testing…`:`Test connection`}),h(l,{type:`button`,variant:`outline`,onClick:Y,disabled:J,children:`Cancel`})]})}),m(`fieldset`,{disabled:J,className:`max-w-3xl space-y-4 rounded-xl border bg-card p-5`,children:[h(`legend`,{className:`sr-only`,children:`Mailbox connection`}),b?.tenant_id?h(`p`,{className:`text-sm text-muted-foreground`,children:`Customer: your assigned customer`}):x(`admin.tenant.read`)?h(_,{label:`Customer`,children:m(`select`,{className:X,value:C,required:!0,onChange:e=>w(e.target.value),children:[h(`option`,{value:``,children:G.isPending?`Loading customers…`:`Select a customer`}),G.data?.map(e=>h(`option`,{value:e.id,children:e.name},e.id))]})}):h(_,{label:`Customer ID`,children:h(u,{value:C,required:!0,onChange:e=>w(e.target.value)})}),G.isError&&h(d,{error:G.error,retry:()=>void G.refetch()}),h(_,{label:`Provider`,children:m(`select`,{className:X,value:T,onChange:e=>{let t=e.target.value===`imap`?`imap`:`microsoft_graph`;E(t),A(t===`imap`?`INBOX`:`inbox`),R(``)},children:[h(`option`,{value:`imap`,children:`IMAP (TLS)`}),h(`option`,{value:`microsoft_graph`,children:`Microsoft Graph`})]})}),h(_,{label:`Email address`,children:h(u,{type:`email`,value:D,required:!0,maxLength:254,onChange:e=>O(e.target.value)})}),h(_,{label:`Folder`,children:h(u,{value:k,required:!0,maxLength:254,onChange:e=>A(e.target.value)})}),T===`imap`?m(g,{children:[m(`div`,{className:`grid grid-cols-[1fr_6rem] gap-3`,children:[h(_,{label:`IMAP host`,children:h(u,{value:j,required:!0,maxLength:253,onChange:e=>M(e.target.value),placeholder:`imap.example.com`})}),h(_,{label:`Port`,children:h(u,{type:`number`,min:1,max:65535,value:N,required:!0,onChange:e=>P(e.target.value)})})]}),h(_,{label:`Login username (optional)`,children:h(u,{value:F,maxLength:254,onChange:e=>I(e.target.value),placeholder:`Defaults to email address`})})]}):m(g,{children:[h(_,{label:`Authentication`,children:m(`select`,{className:X,value:z?`app`:`identity`,onChange:e=>B(e.target.value===`app`),children:[h(`option`,{value:`identity`,children:`Worker Azure identity`}),h(`option`,{value:`app`,children:`App registration secret`})]})}),z&&m(g,{children:[h(_,{label:`App tenant ID`,children:h(u,{value:V,required:!0,onChange:e=>H(e.target.value)})}),h(_,{label:`Client ID`,children:h(u,{value:U,required:!0,onChange:e=>W(e.target.value)})})]}),h(`p`,{className:`text-xs text-muted-foreground`,children:`The selected identity needs mailbox access granted in Microsoft 365.`})]}),(T===`imap`||z)&&m(_,{label:`Vault secret name`,children:[h(u,{value:L,required:!0,pattern:`mailbox-${C}-[a-zA-Z0-9-]+`,maxLength:127,onChange:e=>R(e.target.value),placeholder:`mailbox-${C||`<customer-id>`}-password`,"aria-label":`Vault secret name`,"aria-describedby":`vault-help vault-prefix`}),m(`span`,{id:`vault-prefix`,className:`text-xs break-all text-muted-foreground`,children:[`Use a secret named mailbox-`,C||`<customer-id>`,`-password, or another name with the same customer prefix.`]})]}),m(`details`,{className:`rounded-xl border bg-card p-3 text-sm`,children:[h(`summary`,{className:`cursor-pointer font-medium`,children:`How to use a vault password`}),h(`p`,{id:`vault-help`,className:`mt-2 text-xs leading-5 text-muted-foreground`,children:`In Azure Portal, open your Key Vault → Objects → Secrets → Generate/Import. Store the mailbox password (or app client secret), then enter only its secret name here. Your administrator must configure this deployment’s vault and grant its worker identity access. Registration saves the settings; it does not test the mailbox connection.`}),h(`a`,{className:`mt-2 inline-block text-xs text-primary underline`,href:`https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-portal`,target:`_blank`,rel:`noreferrer`,children:`Azure Key Vault instructions`})]})]}),K.error&&h(`p`,{role:`alert`,className:`text-sm text-destructive`,children:K.error.message}),q.data&&h(`output`,{className:`block text-sm`,children:q.data.message}),q.error&&h(`p`,{role:`alert`,className:`text-sm text-destructive`,children:q.error.message})]})}
@@ -0,0 +1,12 @@
1
+ import type { GridSort } from '@/shared/hooks/useGrid';
2
+ import { type Mailbox } from '@/shared/api/administration';
3
+ export type DirectoryView = 'grid' | 'list';
4
+ /** The mailbox directory as scannable cards or a comparable table. */
5
+ export declare function MailboxDirectory({ accounts, view, onOpen, sort, onSort, columnsToolbar, }: {
6
+ accounts: readonly Mailbox[];
7
+ view: DirectoryView;
8
+ onOpen: (id: string) => void;
9
+ sort: GridSort;
10
+ onSort: (column: string) => void;
11
+ columnsToolbar?: HTMLElement | null;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{DataTable as e}from"@/shared/components/workspace/DataTable";import{SortHeader as t}from"@/shared/components/workspace/SortHeader";import{useMutation as n,useQueryClient as r}from"@tanstack/react-query";import{Check as i,FileSearch as a,Mail as o,MailSearch as s,Minus as c}from"lucide-react";import{updateMailbox as l}from"@/shared/api/administration";import{useSession as u}from"@/shared/auth/session-context";import{Switch as d}from"@/shared/components/ui/switch";import{notify as f}from"@/shared/lib/notify";import{cn as p}from"@/shared/lib/utils";import{mailboxTypeLabel as m,providerLabel as h}from"@/shared/lib/mailbox-types";import{jsx as g,jsxs as _}from"react/jsx-runtime";function v({account:e}){let t=e.policy.mailbox_type;return g(`span`,{className:p(`inline-flex items-center rounded-badge border px-2.5 py-1 text-xs font-medium`,t===`none`?`text-muted-foreground`:`border-workspace/40 bg-workspace/10 text-workspace`),children:m(t)})}function y({account:e}){let t=[{label:`Email`,on:e.policy.classification_required,icon:s},{label:`Documents`,on:e.policy.document_classification_required,icon:a}];return g(`ul`,{className:`flex flex-wrap gap-1.5`,"aria-label":`Classification`,children:t.map(({label:e,on:t,icon:n})=>_(`li`,{className:p(`inline-flex items-center gap-1 rounded-badge px-2.5 py-1 text-xs`,t?`bg-success/10 text-success-foreground`:`bg-muted text-muted-foreground`),children:[g(n,{className:`size-3.5`,"aria-hidden":`true`}),e,t?g(i,{className:`size-3`,"aria-label":`required`}):g(c,{className:`size-3`,"aria-label":`not required`})]},e))})}function b({account:e}){let t=e.policy.classification_sources;return e.policy.mailbox_type===`none`||!t.length?g(`span`,{className:`text-xs text-muted-foreground`,children:`—`}):g(`span`,{className:`text-xs text-muted-foreground capitalize`,children:t.join(` · `)})}function x({account:e}){return _(`span`,{className:`glass-tile grid size-10 shrink-0 place-items-center rounded-xl`,children:[g(o,{className:`size-[18px]`,"aria-hidden":`true`}),g(`span`,{className:`sr-only`,children:h(e.provider)})]})}function S({account:e}){let{can:t}=u(),i=r(),a=n({mutationFn:t=>l(e.id,{enabled:t},`"${e.version}"`),onSuccess:t=>{f.success(t.data.enabled?`Mailbox enabled.`:`Mailbox disabled.`),i.invalidateQueries({queryKey:[`admin`,`mailboxes`]}),i.invalidateQueries({queryKey:[`admin`,`mailbox`,e.id]})},onError:e=>f.error(e.message)});return g(d,{"aria-label":`${e.address} enabled`,title:e.enabled?`Enabled`:`Disabled`,checked:a.isPending?a.variables:e.enabled,disabled:a.isPending||!t(`admin.email_account.write`),onCheckedChange:e=>a.mutate(e)})}function C({account:e,onOpen:t}){return _(`article`,{className:`glass-card flex flex-col rounded-2xl border p-4`,children:[_(`div`,{className:`flex items-start gap-3`,children:[g(x,{account:e}),_(`div`,{className:`min-w-0 flex-1`,children:[g(`h3`,{className:`truncate text-sm font-semibold`,title:e.address,children:g(`button`,{type:`button`,onClick:()=>t(e.id),className:`max-w-full truncate text-left text-primary hover:underline`,children:e.address})}),_(`p`,{className:`mt-0.5 truncate text-xs text-muted-foreground`,children:[h(e.provider),` · `,e.folder]})]}),g(S,{account:e})]}),_(`div`,{className:`mt-4 flex flex-wrap items-center gap-x-3 gap-y-2`,children:[g(v,{account:e}),g(b,{account:e})]}),g(`div`,{className:`mt-4 flex flex-wrap items-center justify-between gap-3 border-t pt-3`,children:g(y,{account:e})})]})}function w({accounts:n,onOpen:r,sort:i,onSort:a,columnsToolbar:o}){let s={sort:i,toggleSort:a},c=`px-4 py-2.5 text-left text-xs font-medium text-muted-foreground`;return g(`div`,{className:`overflow-x-auto`,children:_(e,{externalSearch:!0,columnsToolbar:o,className:`w-full table-fixed text-sm`,children:[g(`caption`,{className:`sr-only`,children:`Mailboxes`}),g(`thead`,{className:`border-b bg-muted/30`,children:_(`tr`,{children:[g(t,{column:`mailbox`,label:`Mailbox`,sort:s.sort,onSort:s.toggleSort,className:c}),g(t,{column:`request_type`,label:`Request type`,sort:s.sort,onSort:s.toggleSort,className:p(c,`hidden w-40 md:table-cell`)}),g(t,{column:`classification`,label:`Classification`,sort:s.sort,onSort:s.toggleSort,className:p(c,`hidden w-56 lg:table-cell`)}),g(t,{column:`sources`,label:`Sources`,sort:s.sort,onSort:s.toggleSort,className:p(c,`hidden w-48 xl:table-cell`)}),g(t,{column:`status`,label:`Enabled`,sort:s.sort,onSort:s.toggleSort,className:p(c,`hidden w-28 sm:table-cell`)})]})}),g(`tbody`,{className:`divide-y`,children:n.map(e=>_(`tr`,{className:`transition-colors hover:bg-muted/30`,children:[g(`td`,{className:`px-4 py-3`,children:_(`div`,{className:`flex min-w-0 items-center gap-3`,children:[g(x,{account:e}),_(`div`,{className:`min-w-0`,children:[g(`button`,{type:`button`,title:e.address,onClick:()=>r(e.id),className:`block max-w-full truncate text-left font-semibold text-primary hover:underline`,children:e.address}),_(`p`,{className:`truncate text-xs text-muted-foreground`,children:[h(e.provider),` · `,e.folder]})]})]})}),g(`td`,{className:`hidden px-4 py-3 md:table-cell`,"data-grid-value":m(e.policy.mailbox_type),children:g(v,{account:e})}),g(`td`,{className:`hidden px-4 py-3 lg:table-cell`,"data-grid-value":`Email ${e.policy.classification_required?`required`:`not required`}, documents ${e.policy.document_classification_required?`required`:`not required`}`,children:g(y,{account:e})}),g(`td`,{className:`hidden px-4 py-3 xl:table-cell`,"data-grid-value":e.policy.mailbox_type===`none`?``:e.policy.classification_sources.join(` · `),children:g(b,{account:e})}),g(`td`,{className:`hidden px-4 py-3 sm:table-cell`,"data-grid-value":e.enabled?`Enabled`:`Disabled`,children:g(S,{account:e})})]},e.id))})]})})}export function MailboxDirectory({accounts:e,view:t,onOpen:n,sort:r,onSort:i,columnsToolbar:a}){return t===`list`?g(w,{columnsToolbar:a,accounts:e,onOpen:n,sort:r,onSort:i}):g(`div`,{className:`grid gap-4 p-3 md:grid-cols-2 2xl:grid-cols-3`,children:e.map(e=>g(C,{account:e,onOpen:n},e.id))})}
@@ -0,0 +1,11 @@
1
+ import { type Mailbox, type Versioned } from '@/shared/api/administration';
2
+ /**
3
+ * Editable policy draft is isolated from background list refreshes and guarded by its read
4
+ * ETag. A page of its own (back: Mailboxes); two columns keep the whole policy on one screen.
5
+ */
6
+ export declare function MailboxEditor({ saved, writable, close, reload, }: {
7
+ saved: Versioned<Mailbox>;
8
+ writable: boolean;
9
+ close: () => void;
10
+ reload: () => void;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1 @@
1
+ import{Switch as e}from"@/shared/components/ui/switch";import{useState as t}from"react";import{useMutation as n,useQueryClient as r}from"@tanstack/react-query";import{Copy as i,Info as a,Mail as o,PlugZap as s,Save as c,Trash2 as l}from"lucide-react";import{updateMailbox as u,deleteMailbox as d,testMailboxConnection as f}from"@/shared/api/administration";import{Button as p}from"@/shared/components/ui/button";import{Input as m}from"@/shared/components/ui/input";import{ConfirmDialog as h}from"@/shared/components/workspace/ConfirmDialog";import{ControlHeader as g}from"@/shared/components/workspace/ControlHeader";import{SettingsFeedback as _}from"@/shared/components/workspace/SettingsFeedback";import{notify as v}from"@/shared/lib/notify";import{cn as y}from"@/shared/lib/utils";import{lockedEmailClassification as b,mailboxTypeLabel as ee,mailboxTypes as x,providerLabel as S}from"@/shared/lib/mailbox-types";import{jsx as C,jsxs as w,Fragment as T}from"react/jsx-runtime";const E=[`subject`,`body`],D=[`new`,`renewal`,`update`,`change`],O=e=>e.split(`,`).map(e=>e.trim()).filter(Boolean);function te({mailbox:e}){let[n,r]=t(``),a=e.connection_config,o=e=>typeof a[e]==`string`?a[e]:``,s=e.provider===`imap`?[[`Server`,`${o(`host`)}:${typeof a.port==`number`?a.port:993}`],[`Login`,o(`username`)||e.address],[`Folder`,e.folder]]:[[`Folder`,e.folder],...e.secret_ref?[[`App tenant`,o(`app_tenant_id`)],[`Client ID`,o(`client_id`)]]:[[`Identity`,`Worker Azure identity`]]];return w(`dl`,{className:`flex flex-wrap items-center gap-x-6 gap-y-1.5 border-b px-5 py-2.5 text-xs`,children:[s.map(([e,t])=>w(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[C(`dt`,{className:`text-muted-foreground`,children:e}),C(`dd`,{className:`truncate font-medium`,children:t})]},e)),e.secret_ref&&w(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[C(`dt`,{className:`text-muted-foreground`,children:`Vault secret`}),C(`dd`,{className:`truncate font-medium`,children:e.secret_ref}),C(p,{type:`button`,variant:`ghost`,size:`icon`,className:`size-6`,"aria-label":`Copy vault secret name`,onClick:()=>{navigator.clipboard.writeText(e.secret_ref??``).then(()=>r(`Copied`)).catch(()=>r(`Copy unavailable`))},children:C(i,{className:`size-3.5`})}),n&&C(`output`,{className:`text-muted-foreground`,children:n})]})]})}function k({title:t,description:n,checked:r,disabled:i,onChange:a}){return w(`div`,{className:y(`flex items-center justify-between gap-4 rounded-xl border px-3.5 py-3`,r&&`border-primary/30 bg-accent`),children:[w(`span`,{className:`min-w-0`,children:[C(`span`,{className:`block text-sm font-medium`,children:t}),C(`span`,{className:`mt-0.5 block text-xs leading-5 text-muted-foreground`,children:n})]}),C(e,{"aria-label":t,checked:r,disabled:i,onCheckedChange:a})]})}export function MailboxEditor({saved:e,writable:i,close:A,reload:j}){let[M,N]=t(e.data.policy),[P,F]=t(e.data.enabled),[I,L]=t(()=>Object.fromEntries(D.map(t=>[t,{required:e.data.policy.classification_rules[t]?.required?.join(`, `)??``,optional:e.data.policy.classification_rules[t]?.optional?.join(`, `)??``,included:t in e.data.policy.classification_rules}]))),R=r(),z={...M,classification_rules:Object.fromEntries(D.filter(e=>I[e]?.included).map(e=>[e,{required:O(I[e]?.required??``),optional:O(I[e]?.optional??``)}]))},B=Object.values(z.classification_rules).some(e=>{let t=[...e.required??[],...e.optional??[]];return new Set(t).size!==t.length||t.some(e=>!/^[a-z][a-z0-9_]{0,63}$/.test(e))}),V=b(M.mailbox_type),H=M.mailbox_type!==`none`,U=M.classification_required&&!M.classification_sources.length?`Select at least one source for email classification.`:B?`Use unique snake_case field names. A field cannot be both required and optional.`:null,W=P!==e.data.enabled||JSON.stringify(z)!==JSON.stringify(e.data.policy),G=n({mutationFn:()=>u(e.data.id,{enabled:P,policy:z},e.etag),retry:!1,onSuccess:t=>{R.setQueryData([`admin`,`mailbox`,e.data.id],t),R.invalidateQueries({queryKey:[`admin`,`mailboxes`]}),v.success(`Mailbox saved.`)}}),[K,q]=t(!1),J=n({mutationFn:()=>d(e.data.id,e.etag),retry:!1,onSuccess:()=>{A(),v.success(`Mailbox deleted.`),R.removeQueries({queryKey:[`admin`,`mailbox`,e.data.id],type:`inactive`}),R.invalidateQueries({queryKey:[`admin`,`mailboxes`]})}}),Y=n({mutationFn:()=>f(e.data.id),retry:!1,onSuccess:e=>e.connected?v.success(e.message):v.failure(e.message),onError:e=>v.error(`Connection test failed: ${e.message}`)}),X=G.isPending||J.isPending||Y.isPending,Z=`mailbox-policy-${e.data.id}`,Q=(e,t)=>N(n=>({...n,[e]:t})),$=(e,t)=>L(n=>({...n,[e]:{required:n[e]?.required??``,optional:n[e]?.optional??``,included:n[e]?.included??!1,...t}}));return w(`section`,{"aria-label":`Classification policy`,className:`flex flex-col`,children:[C(g,{title:e.data.address,icon:o,description:`Classification policy · ${S(e.data.provider)}`,pills:w(T,{children:[w(`span`,{className:`rounded-badge bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground tabular-nums ring-border`,children:[`v`,e.data.version]}),C(`span`,{className:y(`rounded-badge px-2.5 py-1 text-xs font-medium`,e.data.enabled?`bg-success/10 text-success-foreground`:`bg-muted text-muted-foreground`),children:e.data.enabled?`Enabled`:`Disabled`})]}),actions:w(T,{children:[w(p,{type:`submit`,form:Z,disabled:!i||!W||!!U||X||K,children:[C(c,{}),G.isPending?`Saving…`:`Save`]}),i&&w(p,{variant:`outline`,disabled:X||K,onClick:()=>Y.mutate(),children:[C(s,{}),Y.isPending?`Testing…`:`Test connection`]}),i&&w(p,{variant:`destructive`,disabled:X||K,onClick:()=>q(!0),children:[C(l,{}),`Delete`]})]})}),w(`div`,{className:`overflow-hidden rounded-xl border bg-card`,children:[C(te,{mailbox:e.data}),w(`form`,{id:Z,className:`flex flex-col`,onSubmit:e=>{e.preventDefault(),!U&&W&&i&&!X&&!K&&G.mutate()},children:[w(`fieldset`,{disabled:!i||X||K,className:`grid content-start gap-5 p-5 lg:grid-cols-2`,children:[C(`legend`,{className:`sr-only`,children:`Mailbox policy settings`}),w(`div`,{className:`space-y-3`,children:[C(k,{title:`Mailbox enabled`,description:`Include this account in future polling cycles.`,checked:P,onChange:F}),w(`div`,{children:[C(`label`,{htmlFor:`mailbox-type`,className:`text-sm font-semibold`,children:`Request type`}),C(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:`Classify all types, route one fixed type, or None for mailboxes without request routing (e.g. personal inboxes).`}),C(`select`,{id:`mailbox-type`,value:M.mailbox_type,onChange:e=>{let t=x.find(t=>t===e.target.value);if(!t)return;let n=b(t);N(e=>({...e,mailbox_type:t,classification_required:n??e.classification_required,document_classification_required:t!==`none`&&e.document_classification_required}))},className:`mt-2 h-10 w-full rounded-lg border bg-card px-3 text-sm`,children:x.map(e=>C(`option`,{value:e,children:e===`none`?`None (no request routing)`:ee(e)},e))})]}),C(k,{title:`Email classification required`,description:V===!0?`Always on: an All requests mailbox must determine each request type.`:V===!1?`Off: a mailbox without request routing has no type to determine.`:`Determine request type and validate required email fields.`,checked:M.classification_required,disabled:V!==null,onChange:e=>Q(`classification_required`,e)}),C(k,{title:`Document classification & extraction`,description:H?M.document_classification_required?`On: classify each attachment and extract its fields; unresolved results go to human review.`:`Off: attachments are stored only, with no classification, extraction or review.`:`Off: a mailbox without request routing stores attachments only.`,checked:M.document_classification_required,disabled:!H,onChange:e=>Q(`document_classification_required`,e)}),H&&w(`fieldset`,{children:[C(`legend`,{className:`text-sm font-semibold`,children:`Classification sources`}),C(`p`,{className:`text-xs text-muted-foreground`,children:`Content the classifier may inspect. Body is the newest message including its signature; quoted replies are left out.`}),C(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:E.map(e=>w(`label`,{className:y(`cursor-pointer rounded-lg border bg-card px-3 py-2 text-xs capitalize transition-colors`,M.classification_sources.includes(e)&&`border-primary/40 bg-accent text-primary`),children:[C(`input`,{className:`mr-2 accent-primary`,type:`checkbox`,checked:M.classification_sources.includes(e),onChange:t=>Q(`classification_sources`,t.target.checked?[...M.classification_sources,e]:M.classification_sources.filter(t=>t!==e))}),e]},e))})]})]}),H?w(`section`,{className:`min-w-0`,children:[C(`h2`,{className:`text-sm font-semibold`,children:`Field requirements`}),C(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:`Comma-separated snake_case field names per request type. Leave blank for no fields in that category.`}),C(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2 lg:grid-cols-1 xl:grid-cols-2`,children:D.map(e=>{let t=I[e];return w(`fieldset`,{className:y(`rounded-xl border bg-card p-3`,t?.included&&`border-primary/30`),children:[w(`legend`,{className:`sr-only`,children:[e,` rule`]}),w(`label`,{className:`flex items-center gap-2 text-xs font-semibold uppercase`,children:[C(`input`,{type:`checkbox`,checked:t?.included??!1,onChange:t=>$(e,{included:t.target.checked}),className:`accent-primary`}),e]}),t?.included&&C(`div`,{className:`mt-2 grid gap-2`,children:[`required`,`optional`].map(n=>w(`label`,{className:`grid gap-1 text-xs text-muted-foreground`,children:[w(`span`,{className:`capitalize`,children:[e,` `,n,` fields`]}),C(m,{className:`h-8`,value:t[n],placeholder:n===`required`?`No required fields`:`No optional fields`,onChange:t=>$(e,{included:!0,[n]:t.target.value})})]},n))})]},e)})})]}):C(`p`,{className:`h-fit rounded-xl border bg-card p-4 text-xs leading-5 text-muted-foreground`,children:`Mail from this mailbox is stored without request routing, so classification sources and field requirements do not apply. Existing rules are kept.`})]}),w(`div`,{className:`border-t bg-card px-5 py-3`,children:[C(h,{open:K,onCancel:()=>q(!1),title:`Delete ${e.data.address}?`,detail:`This removes the mailbox from future polling. Received emails, attachments and the vault secret are kept. A poll already in progress may finish.`,action:`Delete mailbox`,cancelLabel:`Keep mailbox`,destructive:!0,pending:J.isPending,error:J.error&&C(_,{error:J.error,reload:j}),onConfirm:()=>{i&&!X&&J.mutate()}}),(U||G.error)&&w(`div`,{className:`mb-3 space-y-2`,children:[U&&C(`p`,{role:`alert`,className:`text-sm text-destructive`,children:U}),C(_,{error:G.error,reload:j})]}),w(`p`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[C(a,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),i?W?`Unsaved changes · apply from the next poll`:`No changes yet · in-flight messages keep their policy snapshot`:`Read-only access`]})]})]})]})]})}