@ahmedramez-org/chat 0.7.0 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -149,7 +149,7 @@ export declare function chatPageOf(url: string): string | null;
149
149
  export declare const NOT_INCORTA = "not_incorta";
150
150
  /** `fetchClientId`'s error code: no answer from the instance itself (down, offline, redirected away, too slow). */
151
151
  export declare const INCORTA_UNREACHABLE = "incorta_unreachable";
152
- /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting). */
152
+ /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting), not Incorta's `oauth_server_disabled` refusal. */
153
153
  export declare const INCORTA_UNAVAILABLE = "incorta_unavailable";
154
154
  /**
155
155
  * The apps' client Copilot names for a workspace now, or null when it cannot say within
@@ -174,12 +174,13 @@ export declare function signInFailure(error: unknown): SignInFailure | undefined
174
174
  /** Each app's words for a `signInFailure`, one copy so every app says the same. */
175
175
  export declare const SIGN_IN_FAILURE_TEXT: Record<SignInFailure, string>;
176
176
  /**
177
- * Asks Copilot for the apps' OAuth client on a tenant (it registers one per tenant, D-119): the
178
- * check that the address is an Incorta that signs the apps in, before any browser sign-in. It
179
- * sends nothing of the user's (no cookie, no token) and gives up after `timeoutMs`. Throws an error
180
- * coded `NOT_INCORTA` when the address is not such an Incorta (or the tenant is unknown: Copilot
181
- * cannot tell them apart), `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect
182
- * leaves it), `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
177
+ * Asks Incorta for the apps' OAuth client on a tenant (`GET /oauth/{tenant}/intelligence-chat-client`:
178
+ * Incorta creates one per tenant, D-244): the check that the address is an Incorta that signs the
179
+ * apps in, before any browser sign-in. It sends nothing of the user's (no cookie, no token) and gives
180
+ * up after `timeoutMs`. Throws an error coded `NOT_INCORTA` when the address is not such an Incorta
181
+ * (or the tenant is unknown, Copilot is off for it, or its OAuth server is off),
182
+ * `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect leaves it),
183
+ * `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
183
184
  */
184
185
  export declare function fetchClientId(incortaUrl: string, tenant: string, fetchImpl?: typeof fetch, { timeoutMs }?: {
185
186
  timeoutMs?: number;
package/contract/host.js CHANGED
@@ -235,7 +235,7 @@ export function chatPageOf(url) {
235
235
  export const NOT_INCORTA = 'not_incorta';
236
236
  /** `fetchClientId`'s error code: no answer from the instance itself (down, offline, redirected away, too slow). */
237
237
  export const INCORTA_UNREACHABLE = 'incorta_unreachable';
238
- /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting). */
238
+ /** `fetchClientId`'s error code: the instance's gateway answered 502, 503 or 504 (down or restarting), not Incorta's `oauth_server_disabled` refusal. */
239
239
  export const INCORTA_UNAVAILABLE = 'incorta_unavailable';
240
240
  /**
241
241
  * The apps' client Copilot names for a workspace now, or null when it cannot say within
@@ -276,21 +276,25 @@ export const SIGN_IN_FAILURE_TEXT = {
276
276
  failed: 'Something went wrong. Try again.',
277
277
  };
278
278
  /**
279
- * Asks Copilot for the apps' OAuth client on a tenant (it registers one per tenant, D-119): the
280
- * check that the address is an Incorta that signs the apps in, before any browser sign-in. It
281
- * sends nothing of the user's (no cookie, no token) and gives up after `timeoutMs`. Throws an error
282
- * coded `NOT_INCORTA` when the address is not such an Incorta (or the tenant is unknown: Copilot
283
- * cannot tell them apart), `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect
284
- * leaves it), `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
279
+ * Asks Incorta for the apps' OAuth client on a tenant (`GET /oauth/{tenant}/intelligence-chat-client`:
280
+ * Incorta creates one per tenant, D-244): the check that the address is an Incorta that signs the
281
+ * apps in, before any browser sign-in. It sends nothing of the user's (no cookie, no token) and gives
282
+ * up after `timeoutMs`. Throws an error coded `NOT_INCORTA` when the address is not such an Incorta
283
+ * (or the tenant is unknown, Copilot is off for it, or its OAuth server is off),
284
+ * `INCORTA_UNREACHABLE` when the instance does not answer (or a redirect leaves it),
285
+ * `INCORTA_UNAVAILABLE` when its gateway says it is down, and a plain one otherwise.
285
286
  */
286
287
  export async function fetchClientId(incortaUrl, tenant, fetchImpl = globalThis.fetch, { timeoutMs = 10_000 } = {}) {
287
288
  const coded = (code, why, cause) => Object.assign(new Error(why, { cause }), { code });
289
+ // The tenant is a path segment: only a plain name, never `.` or `..`, which would leave it.
290
+ if (!/^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/.test(tenant) || /^\.+$/.test(tenant))
291
+ throw coded(NOT_INCORTA, 'Not a tenant name');
288
292
  const deadline = new AbortController();
289
293
  const timer = setTimeout(() => deadline.abort(), timeoutMs);
290
294
  try {
291
295
  let answer;
292
296
  try {
293
- answer = await fetchImpl(`${incortaUrl}/copilot/native/oauth-client?tenant=${encodeURIComponent(tenant)}`, { credentials: 'omit', signal: deadline.signal });
297
+ answer = await fetchImpl(`${incortaUrl}/oauth/${encodeURIComponent(tenant)}/intelligence-chat-client`, { credentials: 'omit', signal: deadline.signal });
294
298
  }
295
299
  catch (error) {
296
300
  throw coded(INCORTA_UNREACHABLE, 'Incorta did not answer', error);
@@ -298,9 +302,15 @@ export async function fetchClientId(incortaUrl, tenant, fetchImpl = globalThis.f
298
302
  // A captive portal or a gateway's sign-in page answers in its place.
299
303
  if (answer.url && new URL(answer.url).origin !== new URL(incortaUrl).origin)
300
304
  throw coded(INCORTA_UNREACHABLE, 'Redirected off the instance');
301
- if (answer.status === 502 || answer.status === 503 || answer.status === 504)
305
+ if (answer.status === 502 || answer.status === 503 || answer.status === 504) {
306
+ // Incorta's `oauth_server_disabled` refusal is a setting, not an outage. Sent as 400
307
+ // today (NOT_INCORTA below), as 503 once Incorta sends the status it intends.
308
+ const why = (await answer.json().catch(() => null));
309
+ if (why?.error === 'oauth_server_disabled')
310
+ throw coded(NOT_INCORTA, 'Incorta signs no apps in');
302
311
  throw coded(INCORTA_UNAVAILABLE, `Incorta answered HTTP ${answer.status}.`);
303
- // 404: not an Incorta, the apps' sign-in is off, or the tenant is unknown; 400: not a tenant name.
312
+ }
313
+ // 404: not an Incorta, Copilot is off, or the tenant is unknown; 400: not a tenant name.
304
314
  if (answer.status === 404 || answer.status === 400)
305
315
  throw coded(NOT_INCORTA, `No app client (HTTP ${answer.status})`);
306
316
  if (!answer.ok)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahmedramez-org/chat",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-beta.1",
4
4
  "description": "Incorta's chat for any app: a connector and React component that load the prebuilt chat from IncortaCopilot (or a pinned copy), and the host contract types and checks.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {