@mastra/playground-ui 69.1.0-alpha.1 → 69.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,11 +4,10 @@ let _nangohq_frontend = require("@nangohq/frontend");
4
4
  _nangohq_frontend = require_rolldown_runtime.__toESM(_nangohq_frontend, 1);
5
5
  // src/domains/connect/headless-connect.ts
6
6
  /**
7
- * Headless Nango authorization for the end-user connect surface, ported from
8
- * the platform dashboard's `headless-connect` lib so Studio and the platform
9
- * share one flow. Keyed by the connect session token the launch gate releases
10
- * to the proven owner — never by a vendor URL, so no Nango-branded page is
11
- * ever shown.
7
+ * Headless Nango authorization, shared by Studio's end-user connect surface
8
+ * and the platform dashboard (which imports it from here). Keyed by a
9
+ * Nango connect session token, never by a vendor URL, so no Nango-branded
10
+ * page is ever shown.
12
11
  */
13
12
  var POPUP_AUTH_TYPES = /* @__PURE__ */ new Set([
14
13
  "OAUTH1",
@@ -18,45 +17,74 @@ var POPUP_AUTH_TYPES = /* @__PURE__ */ new Set([
18
17
  "APP",
19
18
  "CUSTOM"
20
19
  ]);
20
+ var UNAUTHENTICATED_AUTH_TYPES = /* @__PURE__ */ new Set(["NONE"]);
21
21
  var CREDENTIAL_SCHEMA_AUTH_TYPES = /* @__PURE__ */ new Set(["TWO_STEP"]);
22
- var CREDENTIAL_FIELDS_BY_AUTH_TYPE = /* @__PURE__ */ new Map([["API_KEY", [{
23
- name: "apiKey",
24
- target: "credentials",
25
- label: "API key",
26
- placeholder: "Paste your API key",
27
- secret: true,
28
- required: true,
29
- order: 0
30
- }]], ["BASIC", [{
31
- name: "username",
32
- target: "credentials",
33
- label: "Username",
34
- placeholder: "Enter your username",
35
- secret: false,
36
- required: true,
37
- order: 0
38
- }, {
39
- name: "password",
40
- target: "credentials",
41
- label: "Password",
42
- placeholder: "Enter your password",
43
- secret: true,
44
- required: true,
45
- order: 1
46
- }]]]);
22
+ var HEADLESS_AUTH_FIELD_FORMATS = /* @__PURE__ */ new Set([
23
+ "hostname",
24
+ "uri",
25
+ "uuid",
26
+ "email"
27
+ ]);
28
+ function toHeadlessAuthField(field, fallbackOrder) {
29
+ return {
30
+ name: field.name,
31
+ target: fieldTarget(field),
32
+ label: field.label || field.name,
33
+ description: field.description ?? null,
34
+ placeholder: field.placeholder ?? null,
35
+ defaultValue: field.defaultValue ?? null,
36
+ format: field.format && HEADLESS_AUTH_FIELD_FORMATS.has(field.format) ? field.format : null,
37
+ pattern: field.pattern ?? null,
38
+ options: field.options ? [...field.options] : null,
39
+ prefix: field.prefix ?? null,
40
+ suffix: field.suffix ?? null,
41
+ documentationUrl: field.documentationUrl ?? null,
42
+ warnings: { ...field.warnings },
43
+ visibleWhen: field.visibleWhen ?? null,
44
+ secret: !!field.secret,
45
+ required: !!field.required,
46
+ order: field.order ?? fallbackOrder
47
+ };
48
+ }
49
+ function credentialField(name, label, placeholder, secret, order) {
50
+ return toHeadlessAuthField({
51
+ name,
52
+ target: "credentials",
53
+ label,
54
+ placeholder,
55
+ secret,
56
+ required: true,
57
+ order
58
+ }, order);
59
+ }
60
+ var CREDENTIAL_FIELDS_BY_AUTH_TYPE = /* @__PURE__ */ new Map([
61
+ ["API_KEY", [credentialField("apiKey", "API key", "Paste your API key", true, 0)]],
62
+ ["BASIC", [credentialField("username", "Username", "Enter your username", false, 0), credentialField("password", "Password", "Enter your password", true, 1)]],
63
+ ["OAUTH2_CC", [credentialField("client_id", "Client ID", "Enter your client ID", false, 0), credentialField("client_secret", "Client secret", "Enter your client secret", true, 1)]]
64
+ ]);
47
65
  function fieldTarget(field) {
48
66
  return field.target ?? "credentials";
49
67
  }
50
68
  function supportsHeadlessAuth(authType, authFields) {
51
69
  if (authType == null) return false;
52
70
  if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) return authFields?.some((field) => fieldTarget(field) === "credentials") ?? false;
53
- return POPUP_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);
71
+ return POPUP_AUTH_TYPES.has(authType) || UNAUTHENTICATED_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);
54
72
  }
55
- /** The fields to collect before authorizing, catalog first, synthesized for API key / Basic. */
73
+ /**
74
+ * The fields to collect before authorizing: the provider's catalog fields,
75
+ * plus the built-in credential fields for its auth type when the catalog
76
+ * declares no credentials of its own (e.g. a Basic auth provider whose
77
+ * catalog only lists a subdomain).
78
+ */
56
79
  function headlessAuthFields(provider) {
57
- if (provider.authFields && provider.authFields.length > 0) return provider.authFields;
58
- if (provider.authType == null) return [];
59
- return CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType) ?? [];
80
+ const catalogFields = (provider.authFields ?? []).map(toHeadlessAuthField);
81
+ const builtInFields = provider.authType == null ? void 0 : CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType);
82
+ if (!builtInFields || catalogFields.some((field) => field.target === "credentials")) return catalogFields;
83
+ const firstOrder = catalogFields.length === 0 ? 0 : Math.max(...catalogFields.map((field) => field.order)) + 1;
84
+ return [...catalogFields, ...builtInFields.map((field, index) => ({
85
+ ...field,
86
+ order: firstOrder + index
87
+ }))];
60
88
  }
61
89
  /**
62
90
  * True when the flow needs user-collected fields before `nango.auth()` can
@@ -64,16 +92,29 @@ function headlessAuthFields(provider) {
64
92
  * without a form falls back to the hosted flow, whose page renders them.
65
93
  */
66
94
  function headlessAuthRequiresForm(provider) {
67
- return headlessAuthFields(provider).some((field) => !!field.required);
95
+ return headlessAuthFields(provider).some((field) => field.required);
68
96
  }
69
97
  function headlessAuthFieldKey(field) {
70
98
  return `${fieldTarget(field)}:${field.name}`;
71
99
  }
72
- /** Splits collected form values into the SDK's credentials vs flow params. */
100
+ /**
101
+ * Whether a field is shown given the current form values. A field with
102
+ * `visibleWhen` is visible only while its controlling field (same target
103
+ * first, then any target) holds the expected value.
104
+ */
105
+ function isHeadlessAuthFieldVisible(fields, field, values) {
106
+ const visibleWhen = field.visibleWhen;
107
+ if (!visibleWhen) return true;
108
+ const controllingField = fields.find((candidate) => fieldTarget(candidate) === fieldTarget(field) && candidate.name === visibleWhen.field) ?? fields.find((candidate) => candidate.name === visibleWhen.field);
109
+ if (!controllingField) return false;
110
+ return values[headlessAuthFieldKey(controllingField)] === visibleWhen.equals;
111
+ }
112
+ /** Splits collected form values into the SDK's credentials vs flow params, skipping hidden fields. */
73
113
  function splitHeadlessAuthValues(fields, values) {
74
114
  const credentials = {};
75
115
  const params = {};
76
116
  for (const field of fields) {
117
+ if (!isHeadlessAuthFieldVisible(fields, field, values)) continue;
77
118
  const value = values[headlessAuthFieldKey(field)];
78
119
  if (!value) continue;
79
120
  if (fieldTarget(field) === "credentials") credentials[field.name] = value;
@@ -96,9 +137,10 @@ var HeadlessAuthError = class extends Error {
96
137
  * Starts a headless Nango auth flow keyed by the session token the launch
97
138
  * gate released. For OAuth this opens the provider's consent popup and
98
139
  * reports the outcome Nango echoes back over its websocket channel. When
99
- * `credentials` are provided (API key / Basic / two-step) no popup opens —
100
- * the SDK submits the credentials to Nango, which validates them with the
101
- * provider.
140
+ * `credentials` are provided (API key / Basic / OAuth client credentials /
141
+ * two-step) no popup opens — the SDK submits the credentials to Nango, which
142
+ * validates them with the provider. Unauthenticated providers are created
143
+ * directly.
102
144
  */
103
145
  function startHeadlessAuth(input) {
104
146
  if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) return {
@@ -106,18 +148,21 @@ function startHeadlessAuth(input) {
106
148
  close: () => {}
107
149
  };
108
150
  const nango = new _nangohq_frontend.default({ connectSessionToken: input.sessionToken });
109
- const options = {};
110
- const credentials = headlessCredentials(input.authType ?? void 0, input.credentials);
111
- if (credentials) options.credentials = credentials;
112
- if (input.params) options.params = input.params;
113
- if (!input.credentials) options.detectClosedAuthWindow = true;
114
151
  return {
115
- result: nango.auth(input.integrationId, options).then(() => void 0).catch((error) => {
152
+ result: (input.authType != null && UNAUTHENTICATED_AUTH_TYPES.has(input.authType) ? nango.create(input.integrationId, input.params ? { params: input.params } : {}) : nango.auth(input.integrationId, authOptions(input))).then(() => void 0).catch((error) => {
116
153
  throw toHeadlessAuthError(error);
117
154
  }),
118
155
  close: () => nango.win?.close()
119
156
  };
120
157
  }
158
+ function authOptions(input) {
159
+ const options = {};
160
+ const credentials = headlessCredentials(input.authType ?? void 0, input.credentials);
161
+ if (credentials) options.credentials = credentials;
162
+ if (input.params) options.params = input.params;
163
+ if (!input.credentials) options.detectClosedAuthWindow = true;
164
+ return options;
165
+ }
121
166
  function headlessCredentials(authType, credentials) {
122
167
  if (!credentials) return void 0;
123
168
  if (authType === "TWO_STEP") return {
@@ -136,6 +181,7 @@ exports.HeadlessAuthError = HeadlessAuthError;
136
181
  exports.headlessAuthFieldKey = headlessAuthFieldKey;
137
182
  exports.headlessAuthFields = headlessAuthFields;
138
183
  exports.headlessAuthRequiresForm = headlessAuthRequiresForm;
184
+ exports.isHeadlessAuthFieldVisible = isHeadlessAuthFieldVisible;
139
185
  exports.splitHeadlessAuthValues = splitHeadlessAuthValues;
140
186
  exports.startHeadlessAuth = startHeadlessAuth;
141
187
  exports.supportsHeadlessAuth = supportsHeadlessAuth;
@@ -1 +1 @@
1
- {"version":3,"file":"headless-connect.cjs.js","names":["Nango","AuthError"],"sources":["../../../src/domains/connect/headless-connect.ts"],"sourcesContent":["import Nango, { AuthError } from '@nangohq/frontend';\nimport type { AuthOptions, ConnectionConfig } from '@nangohq/frontend';\n\nimport type { UserConnectAuthField, UserConnectProvider } from './types';\n\n/**\n * Headless Nango authorization for the end-user connect surface, ported from\n * the platform dashboard's `headless-connect` lib so Studio and the platform\n * share one flow. Keyed by the connect session token the launch gate releases\n * to the proven owner — never by a vendor URL, so no Nango-branded page is\n * ever shown.\n */\n\n// Auth types the browser can complete without Nango's hosted Connect UI.\n// For OAuth (including MCP, which is OAuth 2 under the hood, and CUSTOM —\n// Nango's OAuth-plus-extra-config scheme) and GitHub App installs (`APP`),\n// `nango.auth()` opens the provider's own consent or install popup directly.\n// Flow params the provider needs first (e.g. an MCP server URL) come from\n// `authFields` and are collected in our own form before `nango.auth()` runs.\n// For API key / Basic auth we collect the values ourselves and submit them\n// through `nango.auth()` — no popup at all. Anything else still needs the\n// forms the hosted Connect UI renders, so it keeps going through the launch\n// gate's 302.\nconst POPUP_AUTH_TYPES = new Set(['OAUTH1', 'OAUTH2', 'MCP_OAUTH2', 'MCP_OAUTH2_GENERIC', 'APP', 'CUSTOM']);\n\n// Two-step providers exchange user-supplied credentials against the\n// provider's token endpoint. The fields come entirely from the catalog\n// schema, so the flow is headless only when the catalog exposes a\n// credentials field — otherwise the SDK would treat the call as OAuth and\n// open its own popup.\nconst CREDENTIAL_SCHEMA_AUTH_TYPES = new Set(['TWO_STEP']);\n\nconst API_KEY_FIELDS: UserConnectAuthField[] = [\n {\n name: 'apiKey',\n target: 'credentials',\n label: 'API key',\n placeholder: 'Paste your API key',\n secret: true,\n required: true,\n order: 0,\n },\n];\n\nconst BASIC_FIELDS: UserConnectAuthField[] = [\n {\n name: 'username',\n target: 'credentials',\n label: 'Username',\n placeholder: 'Enter your username',\n secret: false,\n required: true,\n order: 0,\n },\n {\n name: 'password',\n target: 'credentials',\n label: 'Password',\n placeholder: 'Enter your password',\n secret: true,\n required: true,\n order: 1,\n },\n];\n\nconst CREDENTIAL_FIELDS_BY_AUTH_TYPE = new Map<string, UserConnectAuthField[]>([\n ['API_KEY', API_KEY_FIELDS],\n ['BASIC', BASIC_FIELDS],\n]);\n\nfunction fieldTarget(field: UserConnectAuthField): 'credentials' | 'params' {\n // Older servers don't send `target`; a collected value without one is a\n // credential (the common case for API key / Basic fields).\n return field.target ?? 'credentials';\n}\n\nexport function supportsHeadlessAuth(\n authType: string | null | undefined,\n authFields?: readonly UserConnectAuthField[] | null,\n): boolean {\n if (authType == null) return false;\n if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) {\n // Params-only fields produce no credentials, and the SDK treats a\n // credential-less TWO_STEP auth call as OAuth — it would open its own\n // popup instead of exchanging tokens. Require a credentials field.\n return authFields?.some(field => fieldTarget(field) === 'credentials') ?? false;\n }\n return POPUP_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);\n}\n\n/** The fields to collect before authorizing, catalog first, synthesized for API key / Basic. */\nexport function headlessAuthFields(\n provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>,\n): UserConnectAuthField[] {\n if (provider.authFields && provider.authFields.length > 0) return provider.authFields;\n if (provider.authType == null) return [];\n return CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType) ?? [];\n}\n\n/**\n * True when the flow needs user-collected fields before `nango.auth()` can\n * run (API key / Basic / two-step credentials, required flow params). A caller\n * without a form falls back to the hosted flow, whose page renders them.\n */\nexport function headlessAuthRequiresForm(\n provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>,\n): boolean {\n return headlessAuthFields(provider).some(field => !!field.required);\n}\n\nexport interface HeadlessAuthValues {\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}\n\nexport function headlessAuthFieldKey(field: UserConnectAuthField): string {\n return `${fieldTarget(field)}:${field.name}`;\n}\n\n/** Splits collected form values into the SDK's credentials vs flow params. */\nexport function splitHeadlessAuthValues(\n fields: UserConnectAuthField[],\n values: Record<string, string>,\n): HeadlessAuthValues {\n const credentials: Record<string, string> = {};\n const params: Record<string, string> = {};\n\n for (const field of fields) {\n const value = values[headlessAuthFieldKey(field)];\n if (!value) continue;\n if (fieldTarget(field) === 'credentials') credentials[field.name] = value;\n else params[field.name] = value;\n }\n\n return {\n credentials: Object.keys(credentials).length > 0 ? credentials : undefined,\n params: Object.keys(params).length > 0 ? params : undefined,\n };\n}\n\nexport interface HeadlessAuthHandle {\n /** Resolves when the user completes the provider's consent screen. */\n result: Promise<void>;\n /** Closes the provider popup, e.g. when the user cancels the flow. */\n close: () => void;\n}\n\nexport type HeadlessAuthFailure = 'popup_blocked' | 'window_closed' | 'failed';\n\nexport class HeadlessAuthError extends Error {\n constructor(\n message: string,\n readonly reason: HeadlessAuthFailure,\n ) {\n super(message);\n this.name = 'HeadlessAuthError';\n }\n}\n\n/**\n * Starts a headless Nango auth flow keyed by the session token the launch\n * gate released. For OAuth this opens the provider's consent popup and\n * reports the outcome Nango echoes back over its websocket channel. When\n * `credentials` are provided (API key / Basic / two-step) no popup opens —\n * the SDK submits the credentials to Nango, which validates them with the\n * provider.\n */\nexport function startHeadlessAuth(input: {\n sessionToken: string;\n integrationId: string;\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): HeadlessAuthHandle {\n if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) {\n // Without credentials the SDK would route this through its OAuth popup\n // instead of the token-exchange endpoint. Fail fast instead.\n return {\n result: Promise.reject(new HeadlessAuthError('Enter the provider credentials to connect.', 'failed')),\n close: () => {},\n };\n }\n const nango = new Nango({ connectSessionToken: input.sessionToken });\n const options: AuthOptions = {};\n const credentials = headlessCredentials(input.authType ?? undefined, input.credentials);\n if (credentials) options.credentials = credentials;\n if (input.params) options.params = input.params;\n if (!input.credentials) options.detectClosedAuthWindow = true;\n const result = nango\n .auth(input.integrationId, options)\n .then(() => undefined)\n .catch((error: unknown) => {\n throw toHeadlessAuthError(error);\n });\n return { result, close: () => nango.win?.close() };\n}\n\nfunction headlessCredentials(\n authType: string | undefined,\n credentials: Record<string, string> | undefined,\n): ConnectionConfig['credentials'] | undefined {\n if (!credentials) return undefined;\n // Two-step credentials need the discriminator so the SDK routes them to\n // Nango's `/auth/two-step` endpoint instead of the API-key/Basic paths.\n if (authType === 'TWO_STEP') return { type: 'TWO_STEP', ...credentials };\n return credentials;\n}\n\nfunction toHeadlessAuthError(error: unknown): HeadlessAuthError {\n if (error instanceof AuthError && error.type === 'blocked_by_browser') {\n return new HeadlessAuthError('Popup was blocked. Allow popups for this site and try again.', 'popup_blocked');\n }\n if (error instanceof AuthError && error.type === 'window_closed') {\n return new HeadlessAuthError('Authorization window was closed before the connection finished.', 'window_closed');\n }\n if (error instanceof AuthError && error.type === 'connection_test_failed') {\n return new HeadlessAuthError('The provider rejected these credentials. Check them and try again.', 'failed');\n }\n const message = error instanceof Error && error.message ? error.message : 'Could not authorize this connection.';\n return new HeadlessAuthError(message, 'failed');\n}\n"],"mappings":";;;;;;;;;;;;AAuBA,IAAM,mCAAmB,IAAI,IAAI;CAAC;CAAU;CAAU;CAAc;CAAsB;CAAO;AAAQ,CAAC;AAO1G,IAAM,+CAA+B,IAAI,IAAI,CAAC,UAAU,CAAC;AAmCzD,IAAM,iDAAiC,IAAI,IAAoC,CAC7E,CAAC,WAAW,CAjCZ;CACE,MAAM;CACN,QAAQ;CACR,OAAO;CACP,aAAa;CACb,QAAQ;CACR,UAAU;CACV,OAAO;AACT,CAyBY,CAAc,GAC1B,CAAC,SAAS,CAtBV;CACE,MAAM;CACN,QAAQ;CACR,OAAO;CACP,aAAa;CACb,QAAQ;CACR,UAAU;CACV,OAAO;AACT,GACA;CACE,MAAM;CACN,QAAQ;CACR,OAAO;CACP,aAAa;CACb,QAAQ;CACR,UAAU;CACV,OAAO;AACT,CAKU,CAAY,CACxB,CAAC;AAED,SAAS,YAAY,OAAuD;CAG1E,OAAO,MAAM,UAAU;AACzB;AAEA,SAAgB,qBACd,UACA,YACS;CACT,IAAI,YAAY,MAAM,OAAO;CAC7B,IAAI,6BAA6B,IAAI,QAAQ,GAI3C,OAAO,YAAY,MAAK,UAAS,YAAY,KAAK,MAAM,aAAa,KAAK;CAE5E,OAAO,iBAAiB,IAAI,QAAQ,KAAK,+BAA+B,IAAI,QAAQ;AACtF;;AAGA,SAAgB,mBACd,UACwB;CACxB,IAAI,SAAS,cAAc,SAAS,WAAW,SAAS,GAAG,OAAO,SAAS;CAC3E,IAAI,SAAS,YAAY,MAAM,OAAO,CAAC;CACvC,OAAO,+BAA+B,IAAI,SAAS,QAAQ,KAAK,CAA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,QAAQ,yBAAyB;CAOzD,OAAO;EAAE,QANM,MACZ,KAAK,MAAM,eAAe,OAAO,CAAC,CAClC,WAAW,KAAA,CAAS,CAAC,CACrB,OAAO,UAAmB;GACzB,MAAM,oBAAoB,KAAK;EACjC,CACO;EAAQ,aAAa,MAAM,KAAK,MAAM;CAAE;AACnD;AAEA,SAAS,oBACP,UACA,aAC6C;CAC7C,IAAI,CAAC,aAAa,OAAO,KAAA;CAGzB,IAAI,aAAa,YAAY,OAAO;EAAE,MAAM;EAAY,GAAG;CAAY;CACvE,OAAO;AACT;AAEA,SAAS,oBAAoB,OAAmC;CAC9D,IAAI,iBAAiBC,kBAAAA,aAAa,MAAM,SAAS,sBAC/C,OAAO,IAAI,kBAAkB,gEAAgE,eAAe;CAE9G,IAAI,iBAAiBA,kBAAAA,aAAa,MAAM,SAAS,iBAC/C,OAAO,IAAI,kBAAkB,mEAAmE,eAAe;CAEjH,IAAI,iBAAiBA,kBAAAA,aAAa,MAAM,SAAS,0BAC/C,OAAO,IAAI,kBAAkB,sEAAsE,QAAQ;CAG7G,OAAO,IAAI,kBADK,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU,wCACpC,QAAQ;AAChD"}
1
+ {"version":3,"file":"headless-connect.cjs.js","names":["Nango","AuthError"],"sources":["../../../src/domains/connect/headless-connect.ts"],"sourcesContent":["import Nango, { AuthError } from '@nangohq/frontend';\nimport type { AuthOptions, ConnectionConfig } from '@nangohq/frontend';\n\nimport type { UserConnectAuthField } from './types';\n\n/**\n * Headless Nango authorization, shared by Studio's end-user connect surface\n * and the platform dashboard (which imports it from here). Keyed by a\n * Nango connect session token, never by a vendor URL, so no Nango-branded\n * page is ever shown.\n */\n\n// Auth types the browser can complete without Nango's hosted Connect UI.\n// For OAuth (including MCP, which is OAuth 2 under the hood, and CUSTOM —\n// Nango's OAuth-plus-extra-config scheme) and GitHub App installs (`APP`),\n// `nango.auth()` opens the provider's own consent or install popup directly.\n// Flow params the provider needs first (e.g. an MCP server URL) come from\n// `authFields` and are collected in our own form before `nango.auth()` runs.\n// For API key / Basic / OAuth client credentials we collect the values\n// ourselves and submit them through `nango.auth()` — no popup at all.\n// Providers without auth (`NONE`) are created directly. Anything else still\n// needs the forms the hosted Connect UI renders, so it keeps going through\n// the launch gate's 302.\nconst POPUP_AUTH_TYPES = new Set(['OAUTH1', 'OAUTH2', 'MCP_OAUTH2', 'MCP_OAUTH2_GENERIC', 'APP', 'CUSTOM']);\n\n// Providers that need no user authentication. `nango.auth()` would open an\n// OAuth popup for them, so `startHeadlessAuth` calls `nango.create()` instead.\nconst UNAUTHENTICATED_AUTH_TYPES = new Set(['NONE']);\n\n// Two-step providers exchange user-supplied credentials against the\n// provider's token endpoint. The fields come entirely from the catalog\n// schema, so the flow is headless only when the catalog exposes a\n// credentials field — otherwise the SDK would treat the call as OAuth and\n// open its own popup.\nconst CREDENTIAL_SCHEMA_AUTH_TYPES = new Set(['TWO_STEP']);\n\nexport type HeadlessAuthFieldFormat = 'hostname' | 'uri' | 'uuid' | 'email';\n\nconst HEADLESS_AUTH_FIELD_FORMATS = new Set<string>(['hostname', 'uri', 'uuid', 'email']);\n\n/**\n * A field to collect before authorizing, with every property resolved.\n * `headlessAuthFields` produces these from the sparser wire shape\n * (`UserConnectAuthField`), so forms never have to default anything.\n */\nexport interface HeadlessAuthField {\n name: string;\n target: 'credentials' | 'params';\n label: string;\n description: string | null;\n placeholder: string | null;\n defaultValue: string | null;\n format: HeadlessAuthFieldFormat | null;\n pattern: string | null;\n options: string[] | null;\n prefix: string | null;\n suffix: string | null;\n documentationUrl: string | null;\n warnings: Record<string, string>;\n visibleWhen: { field: string; equals: string } | null;\n secret: boolean;\n required: boolean;\n order: number;\n}\n\nfunction toHeadlessAuthField(field: UserConnectAuthField, fallbackOrder: number): HeadlessAuthField {\n return {\n name: field.name,\n target: fieldTarget(field),\n label: field.label || field.name,\n description: field.description ?? null,\n placeholder: field.placeholder ?? null,\n defaultValue: field.defaultValue ?? null,\n format:\n field.format && HEADLESS_AUTH_FIELD_FORMATS.has(field.format) ? (field.format as HeadlessAuthFieldFormat) : null,\n pattern: field.pattern ?? null,\n options: field.options ? [...field.options] : null,\n prefix: field.prefix ?? null,\n suffix: field.suffix ?? null,\n documentationUrl: field.documentationUrl ?? null,\n warnings: { ...field.warnings },\n visibleWhen: field.visibleWhen ?? null,\n secret: !!field.secret,\n required: !!field.required,\n order: field.order ?? fallbackOrder,\n };\n}\n\nfunction credentialField(\n name: string,\n label: string,\n placeholder: string,\n secret: boolean,\n order: number,\n): HeadlessAuthField {\n return toHeadlessAuthField({ name, target: 'credentials', label, placeholder, secret, required: true, order }, order);\n}\n\n// Credentials Nango's hosted Connect UI collects for these auth types even\n// when the provider catalog doesn't declare them. Field names are the keys\n// the SDK routes on (e.g. `client_id` → the OAuth client credentials grant).\nconst CREDENTIAL_FIELDS_BY_AUTH_TYPE = new Map<string, HeadlessAuthField[]>([\n ['API_KEY', [credentialField('apiKey', 'API key', 'Paste your API key', true, 0)]],\n [\n 'BASIC',\n [\n credentialField('username', 'Username', 'Enter your username', false, 0),\n credentialField('password', 'Password', 'Enter your password', true, 1),\n ],\n ],\n [\n 'OAUTH2_CC',\n [\n credentialField('client_id', 'Client ID', 'Enter your client ID', false, 0),\n credentialField('client_secret', 'Client secret', 'Enter your client secret', true, 1),\n ],\n ],\n]);\n\nfunction fieldTarget(field: UserConnectAuthField): 'credentials' | 'params' {\n // Older servers don't send `target`; a collected value without one is a\n // credential (the common case for API key / Basic fields).\n return field.target ?? 'credentials';\n}\n\n/** The provider shape the headless helpers read: its auth type and catalog fields. */\nexport interface HeadlessAuthProvider {\n authType?: string | null;\n authFields?: readonly UserConnectAuthField[] | null;\n}\n\nexport function supportsHeadlessAuth(\n authType: string | null | undefined,\n authFields?: readonly UserConnectAuthField[] | null,\n): boolean {\n if (authType == null) return false;\n if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) {\n // Params-only fields produce no credentials, and the SDK treats a\n // credential-less TWO_STEP auth call as OAuth — it would open its own\n // popup instead of exchanging tokens. Require a credentials field.\n return authFields?.some(field => fieldTarget(field) === 'credentials') ?? false;\n }\n return (\n POPUP_AUTH_TYPES.has(authType) ||\n UNAUTHENTICATED_AUTH_TYPES.has(authType) ||\n CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType)\n );\n}\n\n/**\n * The fields to collect before authorizing: the provider's catalog fields,\n * plus the built-in credential fields for its auth type when the catalog\n * declares no credentials of its own (e.g. a Basic auth provider whose\n * catalog only lists a subdomain).\n */\nexport function headlessAuthFields(provider: HeadlessAuthProvider): HeadlessAuthField[] {\n const catalogFields = (provider.authFields ?? []).map(toHeadlessAuthField);\n const builtInFields = provider.authType == null ? undefined : CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType);\n if (!builtInFields || catalogFields.some(field => field.target === 'credentials')) {\n return catalogFields;\n }\n const firstOrder = catalogFields.length === 0 ? 0 : Math.max(...catalogFields.map(field => field.order)) + 1;\n return [...catalogFields, ...builtInFields.map((field, index) => ({ ...field, order: firstOrder + index }))];\n}\n\n/**\n * True when the flow needs user-collected fields before `nango.auth()` can\n * run (API key / Basic / two-step credentials, required flow params). A caller\n * without a form falls back to the hosted flow, whose page renders them.\n */\nexport function headlessAuthRequiresForm(provider: HeadlessAuthProvider): boolean {\n return headlessAuthFields(provider).some(field => field.required);\n}\n\nexport interface HeadlessAuthValues {\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}\n\nexport function headlessAuthFieldKey(field: UserConnectAuthField): string {\n return `${fieldTarget(field)}:${field.name}`;\n}\n\n/**\n * Whether a field is shown given the current form values. A field with\n * `visibleWhen` is visible only while its controlling field (same target\n * first, then any target) holds the expected value.\n */\nexport function isHeadlessAuthFieldVisible(\n fields: readonly UserConnectAuthField[],\n field: UserConnectAuthField,\n values: Readonly<Record<string, string | undefined>>,\n): boolean {\n const visibleWhen = field.visibleWhen;\n if (!visibleWhen) return true;\n const controllingField =\n fields.find(candidate => fieldTarget(candidate) === fieldTarget(field) && candidate.name === visibleWhen.field) ??\n fields.find(candidate => candidate.name === visibleWhen.field);\n if (!controllingField) return false;\n return values[headlessAuthFieldKey(controllingField)] === visibleWhen.equals;\n}\n\n/** Splits collected form values into the SDK's credentials vs flow params, skipping hidden fields. */\nexport function splitHeadlessAuthValues(\n fields: readonly UserConnectAuthField[],\n values: Record<string, string>,\n): HeadlessAuthValues {\n const credentials: Record<string, string> = {};\n const params: Record<string, string> = {};\n\n for (const field of fields) {\n if (!isHeadlessAuthFieldVisible(fields, field, values)) continue;\n const value = values[headlessAuthFieldKey(field)];\n if (!value) continue;\n if (fieldTarget(field) === 'credentials') credentials[field.name] = value;\n else params[field.name] = value;\n }\n\n return {\n credentials: Object.keys(credentials).length > 0 ? credentials : undefined,\n params: Object.keys(params).length > 0 ? params : undefined,\n };\n}\n\nexport interface HeadlessAuthHandle {\n /** Resolves when the user completes the provider's consent screen. */\n result: Promise<void>;\n /** Closes the provider popup, e.g. when the user cancels the flow. */\n close: () => void;\n}\n\nexport type HeadlessAuthFailure = 'popup_blocked' | 'window_closed' | 'failed';\n\nexport class HeadlessAuthError extends Error {\n constructor(\n message: string,\n readonly reason: HeadlessAuthFailure,\n ) {\n super(message);\n this.name = 'HeadlessAuthError';\n }\n}\n\n/**\n * Starts a headless Nango auth flow keyed by the session token the launch\n * gate released. For OAuth this opens the provider's consent popup and\n * reports the outcome Nango echoes back over its websocket channel. When\n * `credentials` are provided (API key / Basic / OAuth client credentials /\n * two-step) no popup opens — the SDK submits the credentials to Nango, which\n * validates them with the provider. Unauthenticated providers are created\n * directly.\n */\nexport function startHeadlessAuth(input: {\n sessionToken: string;\n integrationId: string;\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): HeadlessAuthHandle {\n if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) {\n // Without credentials the SDK would route this through its OAuth popup\n // instead of the token-exchange endpoint. Fail fast instead.\n return {\n result: Promise.reject(new HeadlessAuthError('Enter the provider credentials to connect.', 'failed')),\n close: () => {},\n };\n }\n const nango = new Nango({ connectSessionToken: input.sessionToken });\n const request =\n input.authType != null && UNAUTHENTICATED_AUTH_TYPES.has(input.authType)\n ? nango.create(input.integrationId, input.params ? { params: input.params } : {})\n : nango.auth(input.integrationId, authOptions(input));\n const result = request\n .then(() => undefined)\n .catch((error: unknown) => {\n throw toHeadlessAuthError(error);\n });\n return { result, close: () => nango.win?.close() };\n}\n\nfunction authOptions(input: {\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): AuthOptions {\n const options: AuthOptions = {};\n const credentials = headlessCredentials(input.authType ?? undefined, input.credentials);\n if (credentials) options.credentials = credentials;\n if (input.params) options.params = input.params;\n if (!input.credentials) options.detectClosedAuthWindow = true;\n return options;\n}\n\nfunction headlessCredentials(\n authType: string | undefined,\n credentials: Record<string, string> | undefined,\n): ConnectionConfig['credentials'] | undefined {\n if (!credentials) return undefined;\n // Two-step credentials need the discriminator so the SDK routes them to\n // Nango's `/auth/two-step` endpoint instead of the API-key/Basic paths.\n if (authType === 'TWO_STEP') return { type: 'TWO_STEP', ...credentials };\n return credentials;\n}\n\nfunction toHeadlessAuthError(error: unknown): HeadlessAuthError {\n if (error instanceof AuthError && error.type === 'blocked_by_browser') {\n return new HeadlessAuthError('Popup was blocked. Allow popups for this site and try again.', 'popup_blocked');\n }\n if (error instanceof AuthError && error.type === 'window_closed') {\n return new HeadlessAuthError('Authorization window was closed before the connection finished.', 'window_closed');\n }\n if (error instanceof AuthError && error.type === 'connection_test_failed') {\n return new HeadlessAuthError('The provider rejected these credentials. Check them and try again.', 'failed');\n }\n const message = error instanceof Error && error.message ? error.message : 'Could not authorize this connection.';\n return new HeadlessAuthError(message, 'failed');\n}\n"],"mappings":";;;;;;;;;;;AAuBA,IAAM,mCAAmB,IAAI,IAAI;CAAC;CAAU;CAAU;CAAc;CAAsB;CAAO;AAAQ,CAAC;AAI1G,IAAM,6CAA6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;GACzB,MAAM,oBAAoB,KAAK;EACjC,CACO;EAAQ,aAAa,MAAM,KAAK,MAAM;CAAE;AACnD;AAEA,SAAS,YAAY,OAIL;CACd,MAAM,UAAuB,CAAC;CAC9B,MAAM,cAAc,oBAAoB,MAAM,YAAY,KAAA,GAAW,MAAM,WAAW;CACtF,IAAI,aAAa,QAAQ,cAAc;CACvC,IAAI,MAAM,QAAQ,QAAQ,SAAS,MAAM;CACzC,IAAI,CAAC,MAAM,aAAa,QAAQ,yBAAyB;CACzD,OAAO;AACT;AAEA,SAAS,oBACP,UACA,aAC6C;CAC7C,IAAI,CAAC,aAAa,OAAO,KAAA;CAGzB,IAAI,aAAa,YAAY,OAAO;EAAE,MAAM;EAAY,GAAG;CAAY;CACvE,OAAO;AACT;AAEA,SAAS,oBAAoB,OAAmC;CAC9D,IAAI,iBAAiBC,kBAAAA,aAAa,MAAM,SAAS,sBAC/C,OAAO,IAAI,kBAAkB,gEAAgE,eAAe;CAE9G,IAAI,iBAAiBA,kBAAAA,aAAa,MAAM,SAAS,iBAC/C,OAAO,IAAI,kBAAkB,mEAAmE,eAAe;CAEjH,IAAI,iBAAiBA,kBAAAA,aAAa,MAAM,SAAS,0BAC/C,OAAO,IAAI,kBAAkB,sEAAsE,QAAQ;CAG7G,OAAO,IAAI,kBADK,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU,wCACpC,QAAQ;AAChD"}
@@ -1,11 +1,10 @@
1
1
  import Nango, { AuthError } from "@nangohq/frontend";
2
2
  // src/domains/connect/headless-connect.ts
3
3
  /**
4
- * Headless Nango authorization for the end-user connect surface, ported from
5
- * the platform dashboard's `headless-connect` lib so Studio and the platform
6
- * share one flow. Keyed by the connect session token the launch gate releases
7
- * to the proven owner — never by a vendor URL, so no Nango-branded page is
8
- * ever shown.
4
+ * Headless Nango authorization, shared by Studio's end-user connect surface
5
+ * and the platform dashboard (which imports it from here). Keyed by a
6
+ * Nango connect session token, never by a vendor URL, so no Nango-branded
7
+ * page is ever shown.
9
8
  */
10
9
  var POPUP_AUTH_TYPES = /* @__PURE__ */ new Set([
11
10
  "OAUTH1",
@@ -15,45 +14,74 @@ var POPUP_AUTH_TYPES = /* @__PURE__ */ new Set([
15
14
  "APP",
16
15
  "CUSTOM"
17
16
  ]);
17
+ var UNAUTHENTICATED_AUTH_TYPES = /* @__PURE__ */ new Set(["NONE"]);
18
18
  var CREDENTIAL_SCHEMA_AUTH_TYPES = /* @__PURE__ */ new Set(["TWO_STEP"]);
19
- var CREDENTIAL_FIELDS_BY_AUTH_TYPE = /* @__PURE__ */ new Map([["API_KEY", [{
20
- name: "apiKey",
21
- target: "credentials",
22
- label: "API key",
23
- placeholder: "Paste your API key",
24
- secret: true,
25
- required: true,
26
- order: 0
27
- }]], ["BASIC", [{
28
- name: "username",
29
- target: "credentials",
30
- label: "Username",
31
- placeholder: "Enter your username",
32
- secret: false,
33
- required: true,
34
- order: 0
35
- }, {
36
- name: "password",
37
- target: "credentials",
38
- label: "Password",
39
- placeholder: "Enter your password",
40
- secret: true,
41
- required: true,
42
- order: 1
43
- }]]]);
19
+ var HEADLESS_AUTH_FIELD_FORMATS = /* @__PURE__ */ new Set([
20
+ "hostname",
21
+ "uri",
22
+ "uuid",
23
+ "email"
24
+ ]);
25
+ function toHeadlessAuthField(field, fallbackOrder) {
26
+ return {
27
+ name: field.name,
28
+ target: fieldTarget(field),
29
+ label: field.label || field.name,
30
+ description: field.description ?? null,
31
+ placeholder: field.placeholder ?? null,
32
+ defaultValue: field.defaultValue ?? null,
33
+ format: field.format && HEADLESS_AUTH_FIELD_FORMATS.has(field.format) ? field.format : null,
34
+ pattern: field.pattern ?? null,
35
+ options: field.options ? [...field.options] : null,
36
+ prefix: field.prefix ?? null,
37
+ suffix: field.suffix ?? null,
38
+ documentationUrl: field.documentationUrl ?? null,
39
+ warnings: { ...field.warnings },
40
+ visibleWhen: field.visibleWhen ?? null,
41
+ secret: !!field.secret,
42
+ required: !!field.required,
43
+ order: field.order ?? fallbackOrder
44
+ };
45
+ }
46
+ function credentialField(name, label, placeholder, secret, order) {
47
+ return toHeadlessAuthField({
48
+ name,
49
+ target: "credentials",
50
+ label,
51
+ placeholder,
52
+ secret,
53
+ required: true,
54
+ order
55
+ }, order);
56
+ }
57
+ var CREDENTIAL_FIELDS_BY_AUTH_TYPE = /* @__PURE__ */ new Map([
58
+ ["API_KEY", [credentialField("apiKey", "API key", "Paste your API key", true, 0)]],
59
+ ["BASIC", [credentialField("username", "Username", "Enter your username", false, 0), credentialField("password", "Password", "Enter your password", true, 1)]],
60
+ ["OAUTH2_CC", [credentialField("client_id", "Client ID", "Enter your client ID", false, 0), credentialField("client_secret", "Client secret", "Enter your client secret", true, 1)]]
61
+ ]);
44
62
  function fieldTarget(field) {
45
63
  return field.target ?? "credentials";
46
64
  }
47
65
  function supportsHeadlessAuth(authType, authFields) {
48
66
  if (authType == null) return false;
49
67
  if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) return authFields?.some((field) => fieldTarget(field) === "credentials") ?? false;
50
- return POPUP_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);
68
+ return POPUP_AUTH_TYPES.has(authType) || UNAUTHENTICATED_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);
51
69
  }
52
- /** The fields to collect before authorizing, catalog first, synthesized for API key / Basic. */
70
+ /**
71
+ * The fields to collect before authorizing: the provider's catalog fields,
72
+ * plus the built-in credential fields for its auth type when the catalog
73
+ * declares no credentials of its own (e.g. a Basic auth provider whose
74
+ * catalog only lists a subdomain).
75
+ */
53
76
  function headlessAuthFields(provider) {
54
- if (provider.authFields && provider.authFields.length > 0) return provider.authFields;
55
- if (provider.authType == null) return [];
56
- return CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType) ?? [];
77
+ const catalogFields = (provider.authFields ?? []).map(toHeadlessAuthField);
78
+ const builtInFields = provider.authType == null ? void 0 : CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType);
79
+ if (!builtInFields || catalogFields.some((field) => field.target === "credentials")) return catalogFields;
80
+ const firstOrder = catalogFields.length === 0 ? 0 : Math.max(...catalogFields.map((field) => field.order)) + 1;
81
+ return [...catalogFields, ...builtInFields.map((field, index) => ({
82
+ ...field,
83
+ order: firstOrder + index
84
+ }))];
57
85
  }
58
86
  /**
59
87
  * True when the flow needs user-collected fields before `nango.auth()` can
@@ -61,16 +89,29 @@ function headlessAuthFields(provider) {
61
89
  * without a form falls back to the hosted flow, whose page renders them.
62
90
  */
63
91
  function headlessAuthRequiresForm(provider) {
64
- return headlessAuthFields(provider).some((field) => !!field.required);
92
+ return headlessAuthFields(provider).some((field) => field.required);
65
93
  }
66
94
  function headlessAuthFieldKey(field) {
67
95
  return `${fieldTarget(field)}:${field.name}`;
68
96
  }
69
- /** Splits collected form values into the SDK's credentials vs flow params. */
97
+ /**
98
+ * Whether a field is shown given the current form values. A field with
99
+ * `visibleWhen` is visible only while its controlling field (same target
100
+ * first, then any target) holds the expected value.
101
+ */
102
+ function isHeadlessAuthFieldVisible(fields, field, values) {
103
+ const visibleWhen = field.visibleWhen;
104
+ if (!visibleWhen) return true;
105
+ const controllingField = fields.find((candidate) => fieldTarget(candidate) === fieldTarget(field) && candidate.name === visibleWhen.field) ?? fields.find((candidate) => candidate.name === visibleWhen.field);
106
+ if (!controllingField) return false;
107
+ return values[headlessAuthFieldKey(controllingField)] === visibleWhen.equals;
108
+ }
109
+ /** Splits collected form values into the SDK's credentials vs flow params, skipping hidden fields. */
70
110
  function splitHeadlessAuthValues(fields, values) {
71
111
  const credentials = {};
72
112
  const params = {};
73
113
  for (const field of fields) {
114
+ if (!isHeadlessAuthFieldVisible(fields, field, values)) continue;
74
115
  const value = values[headlessAuthFieldKey(field)];
75
116
  if (!value) continue;
76
117
  if (fieldTarget(field) === "credentials") credentials[field.name] = value;
@@ -93,9 +134,10 @@ var HeadlessAuthError = class extends Error {
93
134
  * Starts a headless Nango auth flow keyed by the session token the launch
94
135
  * gate released. For OAuth this opens the provider's consent popup and
95
136
  * reports the outcome Nango echoes back over its websocket channel. When
96
- * `credentials` are provided (API key / Basic / two-step) no popup opens —
97
- * the SDK submits the credentials to Nango, which validates them with the
98
- * provider.
137
+ * `credentials` are provided (API key / Basic / OAuth client credentials /
138
+ * two-step) no popup opens — the SDK submits the credentials to Nango, which
139
+ * validates them with the provider. Unauthenticated providers are created
140
+ * directly.
99
141
  */
100
142
  function startHeadlessAuth(input) {
101
143
  if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) return {
@@ -103,18 +145,21 @@ function startHeadlessAuth(input) {
103
145
  close: () => {}
104
146
  };
105
147
  const nango = new Nango({ connectSessionToken: input.sessionToken });
106
- const options = {};
107
- const credentials = headlessCredentials(input.authType ?? void 0, input.credentials);
108
- if (credentials) options.credentials = credentials;
109
- if (input.params) options.params = input.params;
110
- if (!input.credentials) options.detectClosedAuthWindow = true;
111
148
  return {
112
- result: nango.auth(input.integrationId, options).then(() => void 0).catch((error) => {
149
+ result: (input.authType != null && UNAUTHENTICATED_AUTH_TYPES.has(input.authType) ? nango.create(input.integrationId, input.params ? { params: input.params } : {}) : nango.auth(input.integrationId, authOptions(input))).then(() => void 0).catch((error) => {
113
150
  throw toHeadlessAuthError(error);
114
151
  }),
115
152
  close: () => nango.win?.close()
116
153
  };
117
154
  }
155
+ function authOptions(input) {
156
+ const options = {};
157
+ const credentials = headlessCredentials(input.authType ?? void 0, input.credentials);
158
+ if (credentials) options.credentials = credentials;
159
+ if (input.params) options.params = input.params;
160
+ if (!input.credentials) options.detectClosedAuthWindow = true;
161
+ return options;
162
+ }
118
163
  function headlessCredentials(authType, credentials) {
119
164
  if (!credentials) return void 0;
120
165
  if (authType === "TWO_STEP") return {
@@ -129,6 +174,6 @@ function toHeadlessAuthError(error) {
129
174
  if (error instanceof AuthError && error.type === "connection_test_failed") return new HeadlessAuthError("The provider rejected these credentials. Check them and try again.", "failed");
130
175
  return new HeadlessAuthError(error instanceof Error && error.message ? error.message : "Could not authorize this connection.", "failed");
131
176
  }
132
- export { HeadlessAuthError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth };
177
+ export { HeadlessAuthError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, isHeadlessAuthFieldVisible, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth };
133
178
 
134
179
  //# sourceMappingURL=headless-connect.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"headless-connect.es.js","names":[],"sources":["../../../src/domains/connect/headless-connect.ts"],"sourcesContent":["import Nango, { AuthError } from '@nangohq/frontend';\nimport type { AuthOptions, ConnectionConfig } from '@nangohq/frontend';\n\nimport type { UserConnectAuthField, UserConnectProvider } from './types';\n\n/**\n * Headless Nango authorization for the end-user connect surface, ported from\n * the platform dashboard's `headless-connect` lib so Studio and the platform\n * share one flow. Keyed by the connect session token the launch gate releases\n * to the proven owner — never by a vendor URL, so no Nango-branded page is\n * ever shown.\n */\n\n// Auth types the browser can complete without Nango's hosted Connect UI.\n// For OAuth (including MCP, which is OAuth 2 under the hood, and CUSTOM —\n// Nango's OAuth-plus-extra-config scheme) and GitHub App installs (`APP`),\n// `nango.auth()` opens the provider's own consent or install popup directly.\n// Flow params the provider needs first (e.g. an MCP server URL) come from\n// `authFields` and are collected in our own form before `nango.auth()` runs.\n// For API key / Basic auth we collect the values ourselves and submit them\n// through `nango.auth()` — no popup at all. Anything else still needs the\n// forms the hosted Connect UI renders, so it keeps going through the launch\n// gate's 302.\nconst POPUP_AUTH_TYPES = new Set(['OAUTH1', 'OAUTH2', 'MCP_OAUTH2', 'MCP_OAUTH2_GENERIC', 'APP', 'CUSTOM']);\n\n// Two-step providers exchange user-supplied credentials against the\n// provider's token endpoint. The fields come entirely from the catalog\n// schema, so the flow is headless only when the catalog exposes a\n// credentials field — otherwise the SDK would treat the call as OAuth and\n// open its own popup.\nconst CREDENTIAL_SCHEMA_AUTH_TYPES = new Set(['TWO_STEP']);\n\nconst API_KEY_FIELDS: UserConnectAuthField[] = [\n {\n name: 'apiKey',\n target: 'credentials',\n label: 'API key',\n placeholder: 'Paste your API key',\n secret: true,\n required: true,\n order: 0,\n },\n];\n\nconst BASIC_FIELDS: UserConnectAuthField[] = [\n {\n name: 'username',\n target: 'credentials',\n label: 'Username',\n placeholder: 'Enter your username',\n secret: false,\n required: true,\n order: 0,\n },\n {\n name: 'password',\n target: 'credentials',\n label: 'Password',\n placeholder: 'Enter your password',\n secret: true,\n required: true,\n order: 1,\n },\n];\n\nconst CREDENTIAL_FIELDS_BY_AUTH_TYPE = new Map<string, UserConnectAuthField[]>([\n ['API_KEY', API_KEY_FIELDS],\n ['BASIC', BASIC_FIELDS],\n]);\n\nfunction fieldTarget(field: UserConnectAuthField): 'credentials' | 'params' {\n // Older servers don't send `target`; a collected value without one is a\n // credential (the common case for API key / Basic fields).\n return field.target ?? 'credentials';\n}\n\nexport function supportsHeadlessAuth(\n authType: string | null | undefined,\n authFields?: readonly UserConnectAuthField[] | null,\n): boolean {\n if (authType == null) return false;\n if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) {\n // Params-only fields produce no credentials, and the SDK treats a\n // credential-less TWO_STEP auth call as OAuth — it would open its own\n // popup instead of exchanging tokens. Require a credentials field.\n return authFields?.some(field => fieldTarget(field) === 'credentials') ?? false;\n }\n return POPUP_AUTH_TYPES.has(authType) || CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType);\n}\n\n/** The fields to collect before authorizing, catalog first, synthesized for API key / Basic. */\nexport function headlessAuthFields(\n provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>,\n): UserConnectAuthField[] {\n if (provider.authFields && provider.authFields.length > 0) return provider.authFields;\n if (provider.authType == null) return [];\n return CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType) ?? [];\n}\n\n/**\n * True when the flow needs user-collected fields before `nango.auth()` can\n * run (API key / Basic / two-step credentials, required flow params). A caller\n * without a form falls back to the hosted flow, whose page renders them.\n */\nexport function headlessAuthRequiresForm(\n provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>,\n): boolean {\n return headlessAuthFields(provider).some(field => !!field.required);\n}\n\nexport interface HeadlessAuthValues {\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}\n\nexport function headlessAuthFieldKey(field: UserConnectAuthField): string {\n return `${fieldTarget(field)}:${field.name}`;\n}\n\n/** Splits collected form values into the SDK's credentials vs flow params. */\nexport function splitHeadlessAuthValues(\n fields: UserConnectAuthField[],\n values: Record<string, string>,\n): HeadlessAuthValues {\n const credentials: Record<string, string> = {};\n const params: Record<string, string> = {};\n\n for (const field of fields) {\n const value = values[headlessAuthFieldKey(field)];\n if (!value) continue;\n if (fieldTarget(field) === 'credentials') credentials[field.name] = value;\n else params[field.name] = value;\n }\n\n return {\n credentials: Object.keys(credentials).length > 0 ? credentials : undefined,\n params: Object.keys(params).length > 0 ? params : undefined,\n };\n}\n\nexport interface HeadlessAuthHandle {\n /** Resolves when the user completes the provider's consent screen. */\n result: Promise<void>;\n /** Closes the provider popup, e.g. when the user cancels the flow. */\n close: () => void;\n}\n\nexport type HeadlessAuthFailure = 'popup_blocked' | 'window_closed' | 'failed';\n\nexport class HeadlessAuthError extends Error {\n constructor(\n message: string,\n readonly reason: HeadlessAuthFailure,\n ) {\n super(message);\n this.name = 'HeadlessAuthError';\n }\n}\n\n/**\n * Starts a headless Nango auth flow keyed by the session token the launch\n * gate released. For OAuth this opens the provider's consent popup and\n * reports the outcome Nango echoes back over its websocket channel. When\n * `credentials` are provided (API key / Basic / two-step) no popup opens —\n * the SDK submits the credentials to Nango, which validates them with the\n * provider.\n */\nexport function startHeadlessAuth(input: {\n sessionToken: string;\n integrationId: string;\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): HeadlessAuthHandle {\n if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) {\n // Without credentials the SDK would route this through its OAuth popup\n // instead of the token-exchange endpoint. Fail fast instead.\n return {\n result: Promise.reject(new HeadlessAuthError('Enter the provider credentials to connect.', 'failed')),\n close: () => {},\n };\n }\n const nango = new Nango({ connectSessionToken: input.sessionToken });\n const options: AuthOptions = {};\n const credentials = headlessCredentials(input.authType ?? undefined, input.credentials);\n if (credentials) options.credentials = credentials;\n if (input.params) options.params = input.params;\n if (!input.credentials) options.detectClosedAuthWindow = true;\n const result = nango\n .auth(input.integrationId, options)\n .then(() => undefined)\n .catch((error: unknown) => {\n throw toHeadlessAuthError(error);\n });\n return { result, close: () => nango.win?.close() };\n}\n\nfunction headlessCredentials(\n authType: string | undefined,\n credentials: Record<string, string> | undefined,\n): ConnectionConfig['credentials'] | undefined {\n if (!credentials) return undefined;\n // Two-step credentials need the discriminator so the SDK routes them to\n // Nango's `/auth/two-step` endpoint instead of the API-key/Basic paths.\n if (authType === 'TWO_STEP') return { type: 'TWO_STEP', ...credentials };\n return credentials;\n}\n\nfunction toHeadlessAuthError(error: unknown): HeadlessAuthError {\n if (error instanceof AuthError && error.type === 'blocked_by_browser') {\n return new HeadlessAuthError('Popup was blocked. Allow popups for this site and try again.', 'popup_blocked');\n }\n if (error instanceof AuthError && error.type === 'window_closed') {\n return new HeadlessAuthError('Authorization window was closed before the connection finished.', 'window_closed');\n }\n if (error instanceof AuthError && error.type === 'connection_test_failed') {\n return new HeadlessAuthError('The provider rejected these credentials. Check them and try again.', 'failed');\n }\n const message = error instanceof Error && error.message ? error.message : 'Could not authorize this connection.';\n return new HeadlessAuthError(message, 'failed');\n}\n"],"mappings":";;;;;;;;;AAuBA,IAAM,mCAAmB,IAAI,IAAI;CAAC;CAAU;CAAU;CAAc;CAAsB;CAAO;AAAQ,CAAC;AAO1G,IAAM,+CAA+B,IAAI,IAAI,CAAC,UAAU,CAAC;AAmCzD,IAAM,iDAAiC,IAAI,IAAoC,CAC7E,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B,gEAAgE,eAAe;CAE9G,IAAI,iBAAiB,aAAa,MAAM,SAAS,iBAC/C,OAAO,IAAI,kBAAkB,mEAAmE,eAAe;CAEjH,IAAI,iBAAiB,aAAa,MAAM,SAAS,0BAC/C,OAAO,IAAI,kBAAkB,sEAAsE,QAAQ;CAG7G,OAAO,IAAI,kBADK,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU,wCACpC,QAAQ;AAChD"}
1
+ {"version":3,"file":"headless-connect.es.js","names":[],"sources":["../../../src/domains/connect/headless-connect.ts"],"sourcesContent":["import Nango, { AuthError } from '@nangohq/frontend';\nimport type { AuthOptions, ConnectionConfig } from '@nangohq/frontend';\n\nimport type { UserConnectAuthField } from './types';\n\n/**\n * Headless Nango authorization, shared by Studio's end-user connect surface\n * and the platform dashboard (which imports it from here). Keyed by a\n * Nango connect session token, never by a vendor URL, so no Nango-branded\n * page is ever shown.\n */\n\n// Auth types the browser can complete without Nango's hosted Connect UI.\n// For OAuth (including MCP, which is OAuth 2 under the hood, and CUSTOM —\n// Nango's OAuth-plus-extra-config scheme) and GitHub App installs (`APP`),\n// `nango.auth()` opens the provider's own consent or install popup directly.\n// Flow params the provider needs first (e.g. an MCP server URL) come from\n// `authFields` and are collected in our own form before `nango.auth()` runs.\n// For API key / Basic / OAuth client credentials we collect the values\n// ourselves and submit them through `nango.auth()` — no popup at all.\n// Providers without auth (`NONE`) are created directly. Anything else still\n// needs the forms the hosted Connect UI renders, so it keeps going through\n// the launch gate's 302.\nconst POPUP_AUTH_TYPES = new Set(['OAUTH1', 'OAUTH2', 'MCP_OAUTH2', 'MCP_OAUTH2_GENERIC', 'APP', 'CUSTOM']);\n\n// Providers that need no user authentication. `nango.auth()` would open an\n// OAuth popup for them, so `startHeadlessAuth` calls `nango.create()` instead.\nconst UNAUTHENTICATED_AUTH_TYPES = new Set(['NONE']);\n\n// Two-step providers exchange user-supplied credentials against the\n// provider's token endpoint. The fields come entirely from the catalog\n// schema, so the flow is headless only when the catalog exposes a\n// credentials field — otherwise the SDK would treat the call as OAuth and\n// open its own popup.\nconst CREDENTIAL_SCHEMA_AUTH_TYPES = new Set(['TWO_STEP']);\n\nexport type HeadlessAuthFieldFormat = 'hostname' | 'uri' | 'uuid' | 'email';\n\nconst HEADLESS_AUTH_FIELD_FORMATS = new Set<string>(['hostname', 'uri', 'uuid', 'email']);\n\n/**\n * A field to collect before authorizing, with every property resolved.\n * `headlessAuthFields` produces these from the sparser wire shape\n * (`UserConnectAuthField`), so forms never have to default anything.\n */\nexport interface HeadlessAuthField {\n name: string;\n target: 'credentials' | 'params';\n label: string;\n description: string | null;\n placeholder: string | null;\n defaultValue: string | null;\n format: HeadlessAuthFieldFormat | null;\n pattern: string | null;\n options: string[] | null;\n prefix: string | null;\n suffix: string | null;\n documentationUrl: string | null;\n warnings: Record<string, string>;\n visibleWhen: { field: string; equals: string } | null;\n secret: boolean;\n required: boolean;\n order: number;\n}\n\nfunction toHeadlessAuthField(field: UserConnectAuthField, fallbackOrder: number): HeadlessAuthField {\n return {\n name: field.name,\n target: fieldTarget(field),\n label: field.label || field.name,\n description: field.description ?? null,\n placeholder: field.placeholder ?? null,\n defaultValue: field.defaultValue ?? null,\n format:\n field.format && HEADLESS_AUTH_FIELD_FORMATS.has(field.format) ? (field.format as HeadlessAuthFieldFormat) : null,\n pattern: field.pattern ?? null,\n options: field.options ? [...field.options] : null,\n prefix: field.prefix ?? null,\n suffix: field.suffix ?? null,\n documentationUrl: field.documentationUrl ?? null,\n warnings: { ...field.warnings },\n visibleWhen: field.visibleWhen ?? null,\n secret: !!field.secret,\n required: !!field.required,\n order: field.order ?? fallbackOrder,\n };\n}\n\nfunction credentialField(\n name: string,\n label: string,\n placeholder: string,\n secret: boolean,\n order: number,\n): HeadlessAuthField {\n return toHeadlessAuthField({ name, target: 'credentials', label, placeholder, secret, required: true, order }, order);\n}\n\n// Credentials Nango's hosted Connect UI collects for these auth types even\n// when the provider catalog doesn't declare them. Field names are the keys\n// the SDK routes on (e.g. `client_id` → the OAuth client credentials grant).\nconst CREDENTIAL_FIELDS_BY_AUTH_TYPE = new Map<string, HeadlessAuthField[]>([\n ['API_KEY', [credentialField('apiKey', 'API key', 'Paste your API key', true, 0)]],\n [\n 'BASIC',\n [\n credentialField('username', 'Username', 'Enter your username', false, 0),\n credentialField('password', 'Password', 'Enter your password', true, 1),\n ],\n ],\n [\n 'OAUTH2_CC',\n [\n credentialField('client_id', 'Client ID', 'Enter your client ID', false, 0),\n credentialField('client_secret', 'Client secret', 'Enter your client secret', true, 1),\n ],\n ],\n]);\n\nfunction fieldTarget(field: UserConnectAuthField): 'credentials' | 'params' {\n // Older servers don't send `target`; a collected value without one is a\n // credential (the common case for API key / Basic fields).\n return field.target ?? 'credentials';\n}\n\n/** The provider shape the headless helpers read: its auth type and catalog fields. */\nexport interface HeadlessAuthProvider {\n authType?: string | null;\n authFields?: readonly UserConnectAuthField[] | null;\n}\n\nexport function supportsHeadlessAuth(\n authType: string | null | undefined,\n authFields?: readonly UserConnectAuthField[] | null,\n): boolean {\n if (authType == null) return false;\n if (CREDENTIAL_SCHEMA_AUTH_TYPES.has(authType)) {\n // Params-only fields produce no credentials, and the SDK treats a\n // credential-less TWO_STEP auth call as OAuth — it would open its own\n // popup instead of exchanging tokens. Require a credentials field.\n return authFields?.some(field => fieldTarget(field) === 'credentials') ?? false;\n }\n return (\n POPUP_AUTH_TYPES.has(authType) ||\n UNAUTHENTICATED_AUTH_TYPES.has(authType) ||\n CREDENTIAL_FIELDS_BY_AUTH_TYPE.has(authType)\n );\n}\n\n/**\n * The fields to collect before authorizing: the provider's catalog fields,\n * plus the built-in credential fields for its auth type when the catalog\n * declares no credentials of its own (e.g. a Basic auth provider whose\n * catalog only lists a subdomain).\n */\nexport function headlessAuthFields(provider: HeadlessAuthProvider): HeadlessAuthField[] {\n const catalogFields = (provider.authFields ?? []).map(toHeadlessAuthField);\n const builtInFields = provider.authType == null ? undefined : CREDENTIAL_FIELDS_BY_AUTH_TYPE.get(provider.authType);\n if (!builtInFields || catalogFields.some(field => field.target === 'credentials')) {\n return catalogFields;\n }\n const firstOrder = catalogFields.length === 0 ? 0 : Math.max(...catalogFields.map(field => field.order)) + 1;\n return [...catalogFields, ...builtInFields.map((field, index) => ({ ...field, order: firstOrder + index }))];\n}\n\n/**\n * True when the flow needs user-collected fields before `nango.auth()` can\n * run (API key / Basic / two-step credentials, required flow params). A caller\n * without a form falls back to the hosted flow, whose page renders them.\n */\nexport function headlessAuthRequiresForm(provider: HeadlessAuthProvider): boolean {\n return headlessAuthFields(provider).some(field => field.required);\n}\n\nexport interface HeadlessAuthValues {\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}\n\nexport function headlessAuthFieldKey(field: UserConnectAuthField): string {\n return `${fieldTarget(field)}:${field.name}`;\n}\n\n/**\n * Whether a field is shown given the current form values. A field with\n * `visibleWhen` is visible only while its controlling field (same target\n * first, then any target) holds the expected value.\n */\nexport function isHeadlessAuthFieldVisible(\n fields: readonly UserConnectAuthField[],\n field: UserConnectAuthField,\n values: Readonly<Record<string, string | undefined>>,\n): boolean {\n const visibleWhen = field.visibleWhen;\n if (!visibleWhen) return true;\n const controllingField =\n fields.find(candidate => fieldTarget(candidate) === fieldTarget(field) && candidate.name === visibleWhen.field) ??\n fields.find(candidate => candidate.name === visibleWhen.field);\n if (!controllingField) return false;\n return values[headlessAuthFieldKey(controllingField)] === visibleWhen.equals;\n}\n\n/** Splits collected form values into the SDK's credentials vs flow params, skipping hidden fields. */\nexport function splitHeadlessAuthValues(\n fields: readonly UserConnectAuthField[],\n values: Record<string, string>,\n): HeadlessAuthValues {\n const credentials: Record<string, string> = {};\n const params: Record<string, string> = {};\n\n for (const field of fields) {\n if (!isHeadlessAuthFieldVisible(fields, field, values)) continue;\n const value = values[headlessAuthFieldKey(field)];\n if (!value) continue;\n if (fieldTarget(field) === 'credentials') credentials[field.name] = value;\n else params[field.name] = value;\n }\n\n return {\n credentials: Object.keys(credentials).length > 0 ? credentials : undefined,\n params: Object.keys(params).length > 0 ? params : undefined,\n };\n}\n\nexport interface HeadlessAuthHandle {\n /** Resolves when the user completes the provider's consent screen. */\n result: Promise<void>;\n /** Closes the provider popup, e.g. when the user cancels the flow. */\n close: () => void;\n}\n\nexport type HeadlessAuthFailure = 'popup_blocked' | 'window_closed' | 'failed';\n\nexport class HeadlessAuthError extends Error {\n constructor(\n message: string,\n readonly reason: HeadlessAuthFailure,\n ) {\n super(message);\n this.name = 'HeadlessAuthError';\n }\n}\n\n/**\n * Starts a headless Nango auth flow keyed by the session token the launch\n * gate released. For OAuth this opens the provider's consent popup and\n * reports the outcome Nango echoes back over its websocket channel. When\n * `credentials` are provided (API key / Basic / OAuth client credentials /\n * two-step) no popup opens — the SDK submits the credentials to Nango, which\n * validates them with the provider. Unauthenticated providers are created\n * directly.\n */\nexport function startHeadlessAuth(input: {\n sessionToken: string;\n integrationId: string;\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): HeadlessAuthHandle {\n if (input.authType != null && CREDENTIAL_SCHEMA_AUTH_TYPES.has(input.authType) && !input.credentials) {\n // Without credentials the SDK would route this through its OAuth popup\n // instead of the token-exchange endpoint. Fail fast instead.\n return {\n result: Promise.reject(new HeadlessAuthError('Enter the provider credentials to connect.', 'failed')),\n close: () => {},\n };\n }\n const nango = new Nango({ connectSessionToken: input.sessionToken });\n const request =\n input.authType != null && UNAUTHENTICATED_AUTH_TYPES.has(input.authType)\n ? nango.create(input.integrationId, input.params ? { params: input.params } : {})\n : nango.auth(input.integrationId, authOptions(input));\n const result = request\n .then(() => undefined)\n .catch((error: unknown) => {\n throw toHeadlessAuthError(error);\n });\n return { result, close: () => nango.win?.close() };\n}\n\nfunction authOptions(input: {\n authType?: string | null;\n credentials?: Record<string, string>;\n params?: Record<string, string>;\n}): AuthOptions {\n const options: AuthOptions = {};\n const credentials = headlessCredentials(input.authType ?? undefined, input.credentials);\n if (credentials) options.credentials = credentials;\n if (input.params) options.params = input.params;\n if (!input.credentials) options.detectClosedAuthWindow = true;\n return options;\n}\n\nfunction headlessCredentials(\n authType: string | undefined,\n credentials: Record<string, string> | undefined,\n): ConnectionConfig['credentials'] | undefined {\n if (!credentials) return undefined;\n // Two-step credentials need the discriminator so the SDK routes them to\n // Nango's `/auth/two-step` endpoint instead of the API-key/Basic paths.\n if (authType === 'TWO_STEP') return { type: 'TWO_STEP', ...credentials };\n return credentials;\n}\n\nfunction toHeadlessAuthError(error: unknown): HeadlessAuthError {\n if (error instanceof AuthError && error.type === 'blocked_by_browser') {\n return new HeadlessAuthError('Popup was blocked. Allow popups for this site and try again.', 'popup_blocked');\n }\n if (error instanceof AuthError && error.type === 'window_closed') {\n return new HeadlessAuthError('Authorization window was closed before the connection finished.', 'window_closed');\n }\n if (error instanceof AuthError && error.type === 'connection_test_failed') {\n return new HeadlessAuthError('The provider rejected these credentials. Check them and try again.', 'failed');\n }\n const message = error instanceof Error && error.message ? error.message : 'Could not authorize this connection.';\n return new HeadlessAuthError(message, 'failed');\n}\n"],"mappings":";;;;;;;;AAuBA,IAAM,mCAAmB,IAAI,IAAI;CAAC;CAAU;CAAU;CAAc;CAAsB;CAAO;AAAQ,CAAC;AAI1G,IAAM,6CAA6B,IAAI,IAAI,CAAC,MAAM,CAAC;AAOnD,IAAM,+CAA+B,IAAI,IAAI,CAAC,UAAU,CAAC;AAIzD,IAAM,8CAA8B,IAAI,IAAY;CAAC;CAAY;CAAO;CAAQ;AAAO,CAAC;AA2BxF,SAAS,oBAAoB,OAA6B,eAA0C;CAClG,OAAO;EACL,MAAM,MAAM;EACZ,QAAQ,YAAY,KAAK;EACzB,OAAO,MAAM,SAAS,MAAM;EAC5B,aAAa,MAAM,eAAe;EAClC,aAAa,MAAM,eAAe;EAClC,cAAc,MAAM,gBAAgB;EACpC,QACE,MAAM,UAAU,4BAA4B,IAAI,MAAM,MAAM,IAAK,MAAM,SAAqC;EAC9G,SAAS,MAAM,WAAW;EAC1B,SAAS,MAAM,UAAU,CAAC,GAAG,MAAM,OA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mC;CAC9D,IAAI,iBAAiB,aAAa,MAAM,SAAS,sBAC/C,OAAO,IAAI,kBAAkB,gEAAgE,eAAe;CAE9G,IAAI,iBAAiB,aAAa,MAAM,SAAS,iBAC/C,OAAO,IAAI,kBAAkB,mEAAmE,eAAe;CAEjH,IAAI,iBAAiB,aAAa,MAAM,SAAS,0BAC/C,OAAO,IAAI,kBAAkB,sEAAsE,QAAQ;CAG7G,OAAO,IAAI,kBADK,iBAAiB,SAAS,MAAM,UAAU,MAAM,UAAU,wCACpC,QAAQ;AAChD"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs.js","names":[],"sources":["../../../src/domains/connect/types.ts"],"sourcesContent":["/**\n * Wire contract of the end-user connect surface that `userConnectRoutes()`\n * from `@mastra/connect` mounts on the dev server (default base path\n * `/connect`). These routes are custom `apiRoutes`, so they are not part of\n * the `@mastra/client-js` SDK — the shapes below mirror\n * `packages/connect/src/user-connect-routes.ts` and must stay in sync with it.\n */\n\nexport interface UserConnectAuthField {\n name: string;\n /**\n * Where the value goes in a headless auth call: `credentials` are\n * exchanged with the provider, `params` configure the flow (e.g. an MCP\n * server URL). Missing (older servers) is treated as `credentials`.\n */\n target?: 'credentials' | 'params' | null;\n label?: string | null;\n description?: string | null;\n placeholder?: string | null;\n secret?: boolean | null;\n required?: boolean | null;\n order?: number | null;\n}\n\n/** JSON redemption of the launch gate (`Accept: application/json`). */\nexport interface UserConnectLaunchTokenResponse {\n /**\n * Nango connect session token for headless authorization, or null when the\n * server could not extract one — the client then falls back to the hosted\n * popup through the same gate's 302 flow.\n */\n sessionToken: string | null;\n expiresAt: string;\n}\n\nexport interface UserConnectProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n authFields: UserConnectAuthField[] | null;\n}\n\nexport interface UserConnectProvidersResponse {\n providers: UserConnectProvider[];\n}\n\nexport type UserConnectionScope = 'global' | 'user';\n\nexport interface UserConnection {\n id: string;\n integrationId: string;\n /**\n * Display metadata resolved server-side against the FULL platform catalog\n * (not the policy-filtered provider list), so rows for de-allowlisted\n * providers still render properly. Null when the catalog has no entry or\n * the lookup failed.\n */\n displayName: string | null;\n logoUrl: string | null;\n status: string;\n accountLabel: string | null;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectionsResponse {\n connections: UserConnection[];\n}\n\nexport interface UserConnectSessionResponse {\n connectionId: string;\n integrationId: string;\n /**\n * Server-relative launch-gate path (`{basePath}/connections/:id/launch`).\n * The popup navigates here — same-origin with the Mastra server and\n * authenticated — and the server verifies this browser owns the pending\n * session before 302ing into the vendor OAuth flow. The raw vendor connect\n * URL is never exposed to the browser.\n */\n launchUrl: string;\n expiresAt: string | null;\n}\n\nexport interface UserConnectionStatusResponse {\n id: string;\n status: string;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectErrorBody {\n error: { code: string; message: string };\n}\n\n/**\n * One provider in the structured output of the built-in `request_connection`\n * tool (`@mastra/connect`'s `ConnectPromptProvider`). Chat renders these as a\n * connect card.\n */\nexport interface ConnectPromptProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n /** Fields the UI must collect before starting headless authorization. */\n authFields: UserConnectAuthField[] | null;\n connected: boolean;\n scope: UserConnectionScope | null;\n}\n\n/** Structured output of the built-in `request_connection` tool. */\nexport interface ConnectPromptPayload {\n type: 'connect-prompt';\n requestedProvider?: string;\n providers: ConnectPromptProvider[];\n /** Outcome for the model once a paused prompt resumes, e.g. \"Linear connected successfully.\" */\n message?: string;\n /** Why the connection failed, when a paused prompt resumed without one. */\n error?: string;\n}\n\n/**\n * What the card resumes a paused `request_connection` call with once the\n * connection settles: `active`, or `failed` with the reason the card showed.\n */\nexport type ConnectPromptResume =\n | { provider: string; status: 'active' }\n | { provider: string; status: 'failed'; error: string };\n\n/** Narrows an arbitrary tool output to a connect-prompt payload. */\nexport function isConnectPromptPayload(output: unknown): output is ConnectPromptPayload {\n return (\n typeof output === 'object' &&\n output !== null &&\n (output as { type?: unknown }).type === 'connect-prompt' &&\n Array.isArray((output as { providers?: unknown }).providers)\n );\n}\n"],"mappings":";;;AAiIA,SAAgB,uBAAuB,QAAiD;CACtF,OACE,OAAO,WAAW,YAClB,WAAW,QACV,OAA8B,SAAS,oBACxC,MAAM,QAAS,OAAmC,SAAS;AAE/D"}
1
+ {"version":3,"file":"types.cjs.js","names":[],"sources":["../../../src/domains/connect/types.ts"],"sourcesContent":["/**\n * Wire contract of the end-user connect surface that `userConnectRoutes()`\n * from `@mastra/connect` mounts on the dev server (default base path\n * `/connect`). These routes are custom `apiRoutes`, so they are not part of\n * the `@mastra/client-js` SDK — the shapes below mirror\n * `packages/connect/src/user-connect-routes.ts` and must stay in sync with it.\n */\n\nexport interface UserConnectAuthField {\n name: string;\n /**\n * Where the value goes in a headless auth call: `credentials` are\n * exchanged with the provider, `params` configure the flow (e.g. an MCP\n * server URL). Missing (older servers) is treated as `credentials`.\n */\n target?: 'credentials' | 'params' | null;\n label?: string | null;\n description?: string | null;\n placeholder?: string | null;\n defaultValue?: string | null;\n /** Value format to validate against; unknown formats are ignored. */\n format?: string | null;\n pattern?: string | null;\n /** When set, the value must be one of these options (rendered as a select). */\n options?: readonly string[] | null;\n prefix?: string | null;\n suffix?: string | null;\n documentationUrl?: string | null;\n /** Warnings to show when the field holds a given value, keyed by value. */\n warnings?: Readonly<Record<string, string>> | null;\n /** Only show (and submit) the field while another field equals a value. */\n visibleWhen?: { field: string; equals: string } | null;\n secret?: boolean | null;\n required?: boolean | null;\n order?: number | null;\n}\n\n/** JSON redemption of the launch gate (`Accept: application/json`). */\nexport interface UserConnectLaunchTokenResponse {\n /**\n * Nango connect session token for headless authorization, or null when the\n * server could not extract one — the client then falls back to the hosted\n * popup through the same gate's 302 flow.\n */\n sessionToken: string | null;\n expiresAt: string;\n}\n\nexport interface UserConnectProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n authFields: UserConnectAuthField[] | null;\n}\n\nexport interface UserConnectProvidersResponse {\n providers: UserConnectProvider[];\n}\n\nexport type UserConnectionScope = 'global' | 'user';\n\nexport interface UserConnection {\n id: string;\n integrationId: string;\n /**\n * Display metadata resolved server-side against the FULL platform catalog\n * (not the policy-filtered provider list), so rows for de-allowlisted\n * providers still render properly. Null when the catalog has no entry or\n * the lookup failed.\n */\n displayName: string | null;\n logoUrl: string | null;\n status: string;\n accountLabel: string | null;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectionsResponse {\n connections: UserConnection[];\n}\n\nexport interface UserConnectSessionResponse {\n connectionId: string;\n integrationId: string;\n /**\n * Server-relative launch-gate path (`{basePath}/connections/:id/launch`).\n * The popup navigates here — same-origin with the Mastra server and\n * authenticated — and the server verifies this browser owns the pending\n * session before 302ing into the vendor OAuth flow. The raw vendor connect\n * URL is never exposed to the browser.\n */\n launchUrl: string;\n expiresAt: string | null;\n}\n\nexport interface UserConnectionStatusResponse {\n id: string;\n status: string;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectErrorBody {\n error: { code: string; message: string };\n}\n\n/**\n * One provider in the structured output of the built-in `request_connection`\n * tool (`@mastra/connect`'s `ConnectPromptProvider`). Chat renders these as a\n * connect card.\n */\nexport interface ConnectPromptProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n /** Fields the UI must collect before starting headless authorization. */\n authFields: UserConnectAuthField[] | null;\n connected: boolean;\n scope: UserConnectionScope | null;\n}\n\n/** Structured output of the built-in `request_connection` tool. */\nexport interface ConnectPromptPayload {\n type: 'connect-prompt';\n requestedProvider?: string;\n providers: ConnectPromptProvider[];\n /** Outcome for the model once a paused prompt resumes, e.g. \"Linear connected successfully.\" */\n message?: string;\n /** Why the connection failed, when a paused prompt resumed without one. */\n error?: string;\n}\n\n/**\n * What the card resumes a paused `request_connection` call with once the\n * connection settles: `active`, or `failed` with the reason the card showed.\n */\nexport type ConnectPromptResume =\n | { provider: string; status: 'active' }\n | { provider: string; status: 'failed'; error: string };\n\n/** Narrows an arbitrary tool output to a connect-prompt payload. */\nexport function isConnectPromptPayload(output: unknown): output is ConnectPromptPayload {\n return (\n typeof output === 'object' &&\n output !== null &&\n (output as { type?: unknown }).type === 'connect-prompt' &&\n Array.isArray((output as { providers?: unknown }).providers)\n );\n}\n"],"mappings":";;;AA8IA,SAAgB,uBAAuB,QAAiD;CACtF,OACE,OAAO,WAAW,YAClB,WAAW,QACV,OAA8B,SAAS,oBACxC,MAAM,QAAS,OAAmC,SAAS;AAE/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.es.js","names":[],"sources":["../../../src/domains/connect/types.ts"],"sourcesContent":["/**\n * Wire contract of the end-user connect surface that `userConnectRoutes()`\n * from `@mastra/connect` mounts on the dev server (default base path\n * `/connect`). These routes are custom `apiRoutes`, so they are not part of\n * the `@mastra/client-js` SDK — the shapes below mirror\n * `packages/connect/src/user-connect-routes.ts` and must stay in sync with it.\n */\n\nexport interface UserConnectAuthField {\n name: string;\n /**\n * Where the value goes in a headless auth call: `credentials` are\n * exchanged with the provider, `params` configure the flow (e.g. an MCP\n * server URL). Missing (older servers) is treated as `credentials`.\n */\n target?: 'credentials' | 'params' | null;\n label?: string | null;\n description?: string | null;\n placeholder?: string | null;\n secret?: boolean | null;\n required?: boolean | null;\n order?: number | null;\n}\n\n/** JSON redemption of the launch gate (`Accept: application/json`). */\nexport interface UserConnectLaunchTokenResponse {\n /**\n * Nango connect session token for headless authorization, or null when the\n * server could not extract one — the client then falls back to the hosted\n * popup through the same gate's 302 flow.\n */\n sessionToken: string | null;\n expiresAt: string;\n}\n\nexport interface UserConnectProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n authFields: UserConnectAuthField[] | null;\n}\n\nexport interface UserConnectProvidersResponse {\n providers: UserConnectProvider[];\n}\n\nexport type UserConnectionScope = 'global' | 'user';\n\nexport interface UserConnection {\n id: string;\n integrationId: string;\n /**\n * Display metadata resolved server-side against the FULL platform catalog\n * (not the policy-filtered provider list), so rows for de-allowlisted\n * providers still render properly. Null when the catalog has no entry or\n * the lookup failed.\n */\n displayName: string | null;\n logoUrl: string | null;\n status: string;\n accountLabel: string | null;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectionsResponse {\n connections: UserConnection[];\n}\n\nexport interface UserConnectSessionResponse {\n connectionId: string;\n integrationId: string;\n /**\n * Server-relative launch-gate path (`{basePath}/connections/:id/launch`).\n * The popup navigates here — same-origin with the Mastra server and\n * authenticated — and the server verifies this browser owns the pending\n * session before 302ing into the vendor OAuth flow. The raw vendor connect\n * URL is never exposed to the browser.\n */\n launchUrl: string;\n expiresAt: string | null;\n}\n\nexport interface UserConnectionStatusResponse {\n id: string;\n status: string;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectErrorBody {\n error: { code: string; message: string };\n}\n\n/**\n * One provider in the structured output of the built-in `request_connection`\n * tool (`@mastra/connect`'s `ConnectPromptProvider`). Chat renders these as a\n * connect card.\n */\nexport interface ConnectPromptProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n /** Fields the UI must collect before starting headless authorization. */\n authFields: UserConnectAuthField[] | null;\n connected: boolean;\n scope: UserConnectionScope | null;\n}\n\n/** Structured output of the built-in `request_connection` tool. */\nexport interface ConnectPromptPayload {\n type: 'connect-prompt';\n requestedProvider?: string;\n providers: ConnectPromptProvider[];\n /** Outcome for the model once a paused prompt resumes, e.g. \"Linear connected successfully.\" */\n message?: string;\n /** Why the connection failed, when a paused prompt resumed without one. */\n error?: string;\n}\n\n/**\n * What the card resumes a paused `request_connection` call with once the\n * connection settles: `active`, or `failed` with the reason the card showed.\n */\nexport type ConnectPromptResume =\n | { provider: string; status: 'active' }\n | { provider: string; status: 'failed'; error: string };\n\n/** Narrows an arbitrary tool output to a connect-prompt payload. */\nexport function isConnectPromptPayload(output: unknown): output is ConnectPromptPayload {\n return (\n typeof output === 'object' &&\n output !== null &&\n (output as { type?: unknown }).type === 'connect-prompt' &&\n Array.isArray((output as { providers?: unknown }).providers)\n );\n}\n"],"mappings":";;AAiIA,SAAgB,uBAAuB,QAAiD;CACtF,OACE,OAAO,WAAW,YAClB,WAAW,QACV,OAA8B,SAAS,oBACxC,MAAM,QAAS,OAAmC,SAAS;AAE/D"}
1
+ {"version":3,"file":"types.es.js","names":[],"sources":["../../../src/domains/connect/types.ts"],"sourcesContent":["/**\n * Wire contract of the end-user connect surface that `userConnectRoutes()`\n * from `@mastra/connect` mounts on the dev server (default base path\n * `/connect`). These routes are custom `apiRoutes`, so they are not part of\n * the `@mastra/client-js` SDK — the shapes below mirror\n * `packages/connect/src/user-connect-routes.ts` and must stay in sync with it.\n */\n\nexport interface UserConnectAuthField {\n name: string;\n /**\n * Where the value goes in a headless auth call: `credentials` are\n * exchanged with the provider, `params` configure the flow (e.g. an MCP\n * server URL). Missing (older servers) is treated as `credentials`.\n */\n target?: 'credentials' | 'params' | null;\n label?: string | null;\n description?: string | null;\n placeholder?: string | null;\n defaultValue?: string | null;\n /** Value format to validate against; unknown formats are ignored. */\n format?: string | null;\n pattern?: string | null;\n /** When set, the value must be one of these options (rendered as a select). */\n options?: readonly string[] | null;\n prefix?: string | null;\n suffix?: string | null;\n documentationUrl?: string | null;\n /** Warnings to show when the field holds a given value, keyed by value. */\n warnings?: Readonly<Record<string, string>> | null;\n /** Only show (and submit) the field while another field equals a value. */\n visibleWhen?: { field: string; equals: string } | null;\n secret?: boolean | null;\n required?: boolean | null;\n order?: number | null;\n}\n\n/** JSON redemption of the launch gate (`Accept: application/json`). */\nexport interface UserConnectLaunchTokenResponse {\n /**\n * Nango connect session token for headless authorization, or null when the\n * server could not extract one — the client then falls back to the hosted\n * popup through the same gate's 302 flow.\n */\n sessionToken: string | null;\n expiresAt: string;\n}\n\nexport interface UserConnectProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n authFields: UserConnectAuthField[] | null;\n}\n\nexport interface UserConnectProvidersResponse {\n providers: UserConnectProvider[];\n}\n\nexport type UserConnectionScope = 'global' | 'user';\n\nexport interface UserConnection {\n id: string;\n integrationId: string;\n /**\n * Display metadata resolved server-side against the FULL platform catalog\n * (not the policy-filtered provider list), so rows for de-allowlisted\n * providers still render properly. Null when the catalog has no entry or\n * the lookup failed.\n */\n displayName: string | null;\n logoUrl: string | null;\n status: string;\n accountLabel: string | null;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectionsResponse {\n connections: UserConnection[];\n}\n\nexport interface UserConnectSessionResponse {\n connectionId: string;\n integrationId: string;\n /**\n * Server-relative launch-gate path (`{basePath}/connections/:id/launch`).\n * The popup navigates here — same-origin with the Mastra server and\n * authenticated — and the server verifies this browser owns the pending\n * session before 302ing into the vendor OAuth flow. The raw vendor connect\n * URL is never exposed to the browser.\n */\n launchUrl: string;\n expiresAt: string | null;\n}\n\nexport interface UserConnectionStatusResponse {\n id: string;\n status: string;\n scope: UserConnectionScope;\n}\n\nexport interface UserConnectErrorBody {\n error: { code: string; message: string };\n}\n\n/**\n * One provider in the structured output of the built-in `request_connection`\n * tool (`@mastra/connect`'s `ConnectPromptProvider`). Chat renders these as a\n * connect card.\n */\nexport interface ConnectPromptProvider {\n id: string;\n displayName: string | null;\n logoUrl: string | null;\n authType: string | null;\n /** Fields the UI must collect before starting headless authorization. */\n authFields: UserConnectAuthField[] | null;\n connected: boolean;\n scope: UserConnectionScope | null;\n}\n\n/** Structured output of the built-in `request_connection` tool. */\nexport interface ConnectPromptPayload {\n type: 'connect-prompt';\n requestedProvider?: string;\n providers: ConnectPromptProvider[];\n /** Outcome for the model once a paused prompt resumes, e.g. \"Linear connected successfully.\" */\n message?: string;\n /** Why the connection failed, when a paused prompt resumed without one. */\n error?: string;\n}\n\n/**\n * What the card resumes a paused `request_connection` call with once the\n * connection settles: `active`, or `failed` with the reason the card showed.\n */\nexport type ConnectPromptResume =\n | { provider: string; status: 'active' }\n | { provider: string; status: 'failed'; error: string };\n\n/** Narrows an arbitrary tool output to a connect-prompt payload. */\nexport function isConnectPromptPayload(output: unknown): output is ConnectPromptPayload {\n return (\n typeof output === 'object' &&\n output !== null &&\n (output as { type?: unknown }).type === 'connect-prompt' &&\n Array.isArray((output as { providers?: unknown }).providers)\n );\n}\n"],"mappings":";;AA8IA,SAAgB,uBAAuB,QAAiD;CACtF,OACE,OAAO,WAAW,YAClB,WAAW,QACV,OAA8B,SAAS,oBACxC,MAAM,QAAS,OAAmC,SAAS;AAE/D"}
@@ -11,6 +11,7 @@ exports.headlessAuthFieldKey = require_domains_connect_headless_connect.headless
11
11
  exports.headlessAuthFields = require_domains_connect_headless_connect.headlessAuthFields;
12
12
  exports.headlessAuthRequiresForm = require_domains_connect_headless_connect.headlessAuthRequiresForm;
13
13
  exports.isConnectPromptPayload = require_domains_connect_types.isConnectPromptPayload;
14
+ exports.isHeadlessAuthFieldVisible = require_domains_connect_headless_connect.isHeadlessAuthFieldVisible;
14
15
  exports.splitHeadlessAuthValues = require_domains_connect_headless_connect.splitHeadlessAuthValues;
15
16
  exports.startHeadlessAuth = require_domains_connect_headless_connect.startHeadlessAuth;
16
17
  exports.supportsHeadlessAuth = require_domains_connect_headless_connect.supportsHeadlessAuth;
@@ -1,5 +1,5 @@
1
1
  import { isConnectPromptPayload } from "./connect/types.es.js";
2
2
  import { CONNECT_BASE_PATH, UserConnectRequestError, useConnectLaunchHref, useConnectSurface, useConnectionStatus, useCreateConnectSession, useDisconnectUserConnection, usePendingConnect, useUserConnections } from "./connect/use-user-connect.es.js";
3
- import { HeadlessAuthError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth } from "./connect/headless-connect.es.js";
3
+ import { HeadlessAuthError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, isHeadlessAuthFieldVisible, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth } from "./connect/headless-connect.es.js";
4
4
  import { ProviderLogo } from "./connect/provider-logo.es.js";
5
- export { CONNECT_BASE_PATH, HeadlessAuthError, ProviderLogo, UserConnectRequestError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, isConnectPromptPayload, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth, useConnectLaunchHref, useConnectSurface, useConnectionStatus, useCreateConnectSession, useDisconnectUserConnection, usePendingConnect, useUserConnections };
5
+ export { CONNECT_BASE_PATH, HeadlessAuthError, ProviderLogo, UserConnectRequestError, headlessAuthFieldKey, headlessAuthFields, headlessAuthRequiresForm, isConnectPromptPayload, isHeadlessAuthFieldVisible, splitHeadlessAuthValues, startHeadlessAuth, supportsHeadlessAuth, useConnectLaunchHref, useConnectSurface, useConnectionStatus, useCreateConnectSession, useDisconnectUserConnection, usePendingConnect, useUserConnections };
@@ -1,20 +1,64 @@
1
- import type { UserConnectAuthField, UserConnectProvider } from './types';
1
+ import type { UserConnectAuthField } from './types';
2
+ export type HeadlessAuthFieldFormat = 'hostname' | 'uri' | 'uuid' | 'email';
3
+ /**
4
+ * A field to collect before authorizing, with every property resolved.
5
+ * `headlessAuthFields` produces these from the sparser wire shape
6
+ * (`UserConnectAuthField`), so forms never have to default anything.
7
+ */
8
+ export interface HeadlessAuthField {
9
+ name: string;
10
+ target: 'credentials' | 'params';
11
+ label: string;
12
+ description: string | null;
13
+ placeholder: string | null;
14
+ defaultValue: string | null;
15
+ format: HeadlessAuthFieldFormat | null;
16
+ pattern: string | null;
17
+ options: string[] | null;
18
+ prefix: string | null;
19
+ suffix: string | null;
20
+ documentationUrl: string | null;
21
+ warnings: Record<string, string>;
22
+ visibleWhen: {
23
+ field: string;
24
+ equals: string;
25
+ } | null;
26
+ secret: boolean;
27
+ required: boolean;
28
+ order: number;
29
+ }
30
+ /** The provider shape the headless helpers read: its auth type and catalog fields. */
31
+ export interface HeadlessAuthProvider {
32
+ authType?: string | null;
33
+ authFields?: readonly UserConnectAuthField[] | null;
34
+ }
2
35
  export declare function supportsHeadlessAuth(authType: string | null | undefined, authFields?: readonly UserConnectAuthField[] | null): boolean;
3
- /** The fields to collect before authorizing, catalog first, synthesized for API key / Basic. */
4
- export declare function headlessAuthFields(provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>): UserConnectAuthField[];
36
+ /**
37
+ * The fields to collect before authorizing: the provider's catalog fields,
38
+ * plus the built-in credential fields for its auth type when the catalog
39
+ * declares no credentials of its own (e.g. a Basic auth provider whose
40
+ * catalog only lists a subdomain).
41
+ */
42
+ export declare function headlessAuthFields(provider: HeadlessAuthProvider): HeadlessAuthField[];
5
43
  /**
6
44
  * True when the flow needs user-collected fields before `nango.auth()` can
7
45
  * run (API key / Basic / two-step credentials, required flow params). A caller
8
46
  * without a form falls back to the hosted flow, whose page renders them.
9
47
  */
10
- export declare function headlessAuthRequiresForm(provider: Partial<Pick<UserConnectProvider, 'authType' | 'authFields'>>): boolean;
48
+ export declare function headlessAuthRequiresForm(provider: HeadlessAuthProvider): boolean;
11
49
  export interface HeadlessAuthValues {
12
50
  credentials?: Record<string, string>;
13
51
  params?: Record<string, string>;
14
52
  }
15
53
  export declare function headlessAuthFieldKey(field: UserConnectAuthField): string;
16
- /** Splits collected form values into the SDK's credentials vs flow params. */
17
- export declare function splitHeadlessAuthValues(fields: UserConnectAuthField[], values: Record<string, string>): HeadlessAuthValues;
54
+ /**
55
+ * Whether a field is shown given the current form values. A field with
56
+ * `visibleWhen` is visible only while its controlling field (same target
57
+ * first, then any target) holds the expected value.
58
+ */
59
+ export declare function isHeadlessAuthFieldVisible(fields: readonly UserConnectAuthField[], field: UserConnectAuthField, values: Readonly<Record<string, string | undefined>>): boolean;
60
+ /** Splits collected form values into the SDK's credentials vs flow params, skipping hidden fields. */
61
+ export declare function splitHeadlessAuthValues(fields: readonly UserConnectAuthField[], values: Record<string, string>): HeadlessAuthValues;
18
62
  export interface HeadlessAuthHandle {
19
63
  /** Resolves when the user completes the provider's consent screen. */
20
64
  result: Promise<void>;
@@ -30,9 +74,10 @@ export declare class HeadlessAuthError extends Error {
30
74
  * Starts a headless Nango auth flow keyed by the session token the launch
31
75
  * gate released. For OAuth this opens the provider's consent popup and
32
76
  * reports the outcome Nango echoes back over its websocket channel. When
33
- * `credentials` are provided (API key / Basic / two-step) no popup opens —
34
- * the SDK submits the credentials to Nango, which validates them with the
35
- * provider.
77
+ * `credentials` are provided (API key / Basic / OAuth client credentials /
78
+ * two-step) no popup opens — the SDK submits the credentials to Nango, which
79
+ * validates them with the provider. Unauthenticated providers are created
80
+ * directly.
36
81
  */
37
82
  export declare function startHeadlessAuth(input: {
38
83
  sessionToken: string;
@@ -16,6 +16,22 @@ export interface UserConnectAuthField {
16
16
  label?: string | null;
17
17
  description?: string | null;
18
18
  placeholder?: string | null;
19
+ defaultValue?: string | null;
20
+ /** Value format to validate against; unknown formats are ignored. */
21
+ format?: string | null;
22
+ pattern?: string | null;
23
+ /** When set, the value must be one of these options (rendered as a select). */
24
+ options?: readonly string[] | null;
25
+ prefix?: string | null;
26
+ suffix?: string | null;
27
+ documentationUrl?: string | null;
28
+ /** Warnings to show when the field holds a given value, keyed by value. */
29
+ warnings?: Readonly<Record<string, string>> | null;
30
+ /** Only show (and submit) the field while another field equals a value. */
31
+ visibleWhen?: {
32
+ field: string;
33
+ equals: string;
34
+ } | null;
19
35
  secret?: boolean | null;
20
36
  required?: boolean | null;
21
37
  order?: number | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mastra/playground-ui",
3
3
  "type": "module",
4
- "version": "69.1.0-alpha.1",
4
+ "version": "69.1.0-alpha.2",
5
5
  "description": "Mastra Playground components",
6
6
  "sideEffects": [
7
7
  "**/*.css"
@@ -224,8 +224,8 @@
224
224
  "react-dom": ">=19.0.0",
225
225
  "tailwindcss": "^4.0.0",
226
226
  "@mastra/ai-sdk": "^1.12.0",
227
- "@mastra/client-js": "^1.60.1-alpha.1",
228
- "@mastra/react": "1.15.1-alpha.1"
227
+ "@mastra/client-js": "^1.60.1-alpha.2",
228
+ "@mastra/react": "1.15.1-alpha.2"
229
229
  },
230
230
  "devDependencies": {
231
231
  "@modelcontextprotocol/client": "2.4.0",
@@ -271,10 +271,10 @@
271
271
  "vitest": "5.1.0",
272
272
  "@internal/lint": "0.0.149",
273
273
  "@mastra/ai-sdk": "1.12.0",
274
- "@mastra/client-js": "^1.60.1-alpha.1",
275
- "@mastra/core": "1.84.0-alpha.1",
276
- "@mastra/memory": "1.41.2-alpha.0",
277
- "@mastra/react": "1.15.1-alpha.1",
274
+ "@mastra/client-js": "^1.60.1-alpha.2",
275
+ "@mastra/core": "1.84.0-alpha.2",
276
+ "@mastra/memory": "1.41.2-alpha.1",
277
+ "@mastra/react": "1.15.1-alpha.2",
278
278
  "@mastra/schema-compat": "1.4.0"
279
279
  },
280
280
  "homepage": "https://mastra.ai",