@collective-intelligence/external-apps-client-sdk 0.2.18 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/effect.js CHANGED
@@ -1,5 +1,5 @@
1
- import { D as CiTransportError, E as CiErrorCode, O as FederatedAuthError, T as CiError, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, k as FederatedAuthErrorCode, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-DaANR0QD.js";
2
- import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-dVoDg4IP.js";
1
+ import { D as CiTransportError, E as CiErrorCode, O as FederatedAuthError, T as CiError, a as layerConfig$3, c as layerLegacyConfig, f as makeEntityHttpExecute, i as layer$3, k as FederatedAuthErrorCode, n as Resources, o as layerFromEntityTransport, s as layerLegacy, t as LegacyResources } from "./service-Db0c8eg9.js";
2
+ import { C as RealtimeClient, D as subscribe, T as layerConfig$2, _ as layerDirect, a as layer$1, b as layerProxy, c as layerFederated, d as layerServerSessionConfig, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer$4, i as FixedWorkflows, l as layerFederatedConfig, n as layer, o as layerConfig$1, p as Runs, r as layerConfig, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, v as layerDirectConfig, w as layer$2, x as layerProxyConfig, y as layerFromExecutor } from "./service-BIyZo-CO.js";
3
3
  import * as Schema from "effect/Schema";
4
4
  /**
5
5
  * The wire Schemas of the CI envelopes that `./effect` exports. The Type of
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
- import { A as errors_exports, C as isClientOperationId, D as CiTransportError, O as FederatedAuthError, b as proxyHttpOptions, d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol, v as directHttpOptions, w as toCiResult, x as clientOperationIds, y as makeHttpExecute } from "./service-DaANR0QD.js";
2
- import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-dVoDg4IP.js";
3
- import { t as createResourceClient } from "./resources-DhUOIac7.js";
1
+ import { A as errors_exports, C as isClientOperationId, D as CiTransportError, O as FederatedAuthError, b as proxyHttpOptions, d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol, v as directHttpOptions, w as toCiResult, x as clientOperationIds, y as makeHttpExecute } from "./service-Db0c8eg9.js";
2
+ import { A as layerFromFactory, E as makeConnection, M as currentLink, N as createFetchEventSourceFactory, O as realtimeTopicKey, S as make, a as layer$2, c as layerFederated, f as DEFAULT_FOLLOW_RUN_DEADLINE_MS, g as CiClient, h as layer, i as FixedWorkflows, j as layerBrowser, k as layer$3, m as followSource, n as layer$1, p as Runs, s as FederatedAuth, t as DelegatedRuntime, u as layerServerSession, y as layerFromExecutor } from "./service-BIyZo-CO.js";
3
+ import { t as createResourceClient } from "./resources-B6e3qsBD.js";
4
+ import * as Schema from "effect/Schema";
4
5
  import * as Clock from "effect/Clock";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Duration from "effect/Duration";
@@ -89,7 +90,7 @@ const createServerSessionAuth = (options) => {
89
90
  */
90
91
  /** A read of the source; a rejection is a transport failure. */
91
92
  const read = (call) => Effect.tryPromise({
92
- catch: (cause) => cause instanceof CiTransportError ? cause : new CiTransportError({ cause }),
93
+ catch: (cause) => Schema.is(CiTransportError)(cause) ? cause : new CiTransportError({ cause }),
93
94
  try: call
94
95
  }).pipe(Effect.map(toCiResult));
95
96
  const sourceOf = (runs) => ({
@@ -1,4 +1,5 @@
1
- import { D as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-DaANR0QD.js";
1
+ import { D as CiTransportError, l as makeEntityCore, p as runEntityRequest, r as fromEntityTransport, u as makeLegacyResourceCore } from "./service-Db0c8eg9.js";
2
+ import * as Schema from "effect/Schema";
2
3
  import * as Layer from "effect/Layer";
3
4
  import * as ManagedRuntime from "effect/ManagedRuntime";
4
5
  /**
@@ -92,7 +93,7 @@ const createLegacyResourceClient = (options) => {
92
93
  try {
93
94
  return await runtime.runPromise(call(correlationId, requestOptions), signal === void 0 ? void 0 : { signal });
94
95
  } catch (error) {
95
- if (error instanceof CiTransportError) return {
96
+ if (Schema.is(CiTransportError)(error)) return {
96
97
  correlationId,
97
98
  error: unavailable(error.cause),
98
99
  ok: false
package/dist/resources.js CHANGED
@@ -1,3 +1,3 @@
1
- import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-DaANR0QD.js";
2
- import { t as createResourceClient } from "./resources-DhUOIac7.js";
1
+ import { d as createEntityHttpTransport, g as isEntityReadLimitError, h as isEntityBatchRefusedError, m as createEntityProtocol } from "./service-Db0c8eg9.js";
2
+ import { t as createResourceClient } from "./resources-B6e3qsBD.js";
3
3
  export { createEntityHttpTransport, createEntityProtocol, createResourceClient, isEntityBatchRefusedError, isEntityReadLimitError };
@@ -1,4 +1,4 @@
1
- import { D as CiTransportError, O as FederatedAuthError, S as fromCiResult, T as CiError, _ as backendErrorCode, b as proxyHttpOptions, j as ciErrorCodes, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-DaANR0QD.js";
1
+ import { D as CiTransportError, O as FederatedAuthError, S as fromCiResult, T as CiError, _ as backendErrorCode, b as proxyHttpOptions, j as ciErrorCodes, v as directHttpOptions, w as toCiResult, y as makeHttpExecute } from "./service-Db0c8eg9.js";
2
2
  import * as Predicate from "effect/Predicate";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as Arr from "effect/Array";
@@ -900,7 +900,7 @@ const make$3 = (executeResult) => CiClient.of({
900
900
  */
901
901
  const executeOf = (executor) => (operationId, input, options) => Effect.tryPromise({
902
902
  catch: (error) => {
903
- if (error instanceof CiTransportError) return error;
903
+ if (Schema.is(CiTransportError)(error)) return error;
904
904
  throw error;
905
905
  },
906
906
  try: (signal) => executor.execute(operationId, input, {
@@ -1102,13 +1102,9 @@ var FederatedAuth = class extends Context.Service()("@collective-intelligence/ex
1102
1102
  const configurationError = (message) => new FederatedAuthError("configuration_error", message);
1103
1103
  const transportError = (cause) => new CiTransportError({ cause });
1104
1104
  const loginRequired = () => new FederatedAuthError("reauthorization_required", "A new CI login is required");
1105
- const readJson = (response) => Effect.promise(async () => {
1106
- try {
1107
- return await response.json();
1108
- } catch {
1109
- return null;
1110
- }
1111
- });
1105
+ /** The JSON text of a value; callers turn a value that JSON cannot write, bad input, into a Defect. */
1106
+ const encodeJsonText = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
1107
+ const readJson = (response) => Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
1112
1108
  /** The browser navigation; without one, a configuration error. */
1113
1109
  const navigation = (navigate) => {
1114
1110
  if (navigate !== void 0) return (url) => Effect.sync(() => navigate(url));
@@ -1272,7 +1268,7 @@ const makeFederated = Effect.fnUntraced(function* makeFederated(options) {
1272
1268
  state: createOauthRandomValue(crypto),
1273
1269
  verifier: pkce.verifier
1274
1270
  };
1275
- storage.setItem(storageKey, JSON.stringify(transaction));
1271
+ storage.setItem(storageKey, yield* encodeJsonText(transaction).pipe(Effect.orDie));
1276
1272
  const authorizationUrl = new URL("/oauth/authorize", tenantOrigin);
1277
1273
  authorizationUrl.searchParams.set("client_id", options.clientId);
1278
1274
  authorizationUrl.searchParams.set("redirect_uri", redirectUri.href);
@@ -1571,13 +1567,7 @@ const make$1 = (options) => {
1571
1567
  signal
1572
1568
  })
1573
1569
  });
1574
- const payload = yield* Effect.promise(async () => {
1575
- try {
1576
- return await response.json();
1577
- } catch {
1578
- return null;
1579
- }
1580
- });
1570
+ const payload = yield* Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
1581
1571
  return yield* runIdOf(response, payload);
1582
1572
  }) });
1583
1573
  };
@@ -1616,7 +1606,7 @@ const mapAuthState = (state) => {
1616
1606
  };
1617
1607
  /** The message of a failed session read; a transport failure names its cause. */
1618
1608
  const failureMessage = (error) => {
1619
- if (error instanceof CiTransportError) return failureMessage(error.cause);
1609
+ if (Schema.is(CiTransportError)(error)) return failureMessage(error.cause);
1620
1610
  return error instanceof Error && error.message !== "" ? error.message : "CI session verification is unavailable";
1621
1611
  };
1622
1612
  const resolvedPaths = (options) => ({
@@ -128,7 +128,7 @@ const decodeCiError = Schema.decodeUnknownOption(CiError);
128
128
  * becomes `internal`, so an Expected Error always has its class.
129
129
  */
130
130
  const toCiError = (error) => {
131
- if (error instanceof CiError) return error;
131
+ if (Schema.is(CiError)(error)) return error;
132
132
  const { details, ...fields } = error;
133
133
  return decodeCiError({
134
134
  ...fields,
@@ -144,7 +144,7 @@ const toCiError = (error) => {
144
144
  })));
145
145
  };
146
146
  /** Internal. The envelope with a `CiError` instance as its error (AC-015). */
147
- const toCiResult = (result) => result.ok || result.error instanceof CiError ? result : {
147
+ const toCiResult = (result) => result.ok || Schema.is(CiError)(result.error) ? result : {
148
148
  correlationId: result.correlationId,
149
149
  error: toCiError(result.error),
150
150
  ok: false
@@ -394,22 +394,10 @@ const clientFailure = (error) => ({
394
394
  error,
395
395
  ok: false
396
396
  });
397
- const responseJson = (response) => Effect.promise(async () => {
398
- try {
399
- return await response.json();
400
- } catch {
401
- return null;
402
- }
403
- });
397
+ const responseJson = (response) => Effect.tryPromise(() => response.json()).pipe(Effect.orElseSucceed(() => null));
404
398
  const transportError$1 = (cause) => new CiTransportError({ cause });
405
399
  /** The bearer token of `authorization`; `null` when it fails. */
406
- const accessToken = (authorization) => Effect.promise(async () => {
407
- try {
408
- return { token: await authorization?.() };
409
- } catch {
410
- return null;
411
- }
412
- });
400
+ const accessToken = (authorization) => Effect.tryPromise(() => Promise.resolve(authorization?.())).pipe(Effect.map((token) => ({ token })), Effect.orElseSucceed(() => null));
413
401
  /**
414
402
  * The HTTP adapter of `CiClient`: one operation per dedicated Application
415
403
  * HTTP route. A CI error answer is a `CiError` in the envelope, and so is an
@@ -8488,13 +8476,7 @@ const makeEntityHttpExecute = (options) => {
8488
8476
  });
8489
8477
  if (destination.kind === "ci") headers.set("x-organization-id", destination.organizationId);
8490
8478
  if (authentication.mode === "federated") {
8491
- const token = yield* Effect.promise(async () => {
8492
- try {
8493
- return { value: await authentication.auth.getAccessToken() };
8494
- } catch {
8495
- return null;
8496
- }
8497
- });
8479
+ const token = yield* Effect.tryPromise(() => Promise.resolve(authentication.auth.getAccessToken())).pipe(Effect.map((value) => ({ value })), Effect.orElseSucceed(() => null));
8498
8480
  if (token === null) return failure$1(request, {
8499
8481
  code: "unauthenticated",
8500
8482
  message: "CI login is required",
@@ -8520,7 +8502,7 @@ const makeEntityHttpExecute = (options) => {
8520
8502
  });
8521
8503
  const result = yield* Effect.tryPromise({
8522
8504
  catch: transportError,
8523
- try: async () => await response.json()
8505
+ try: () => response.json()
8524
8506
  });
8525
8507
  return yield* Effect.try({
8526
8508
  catch: transportError,
@@ -8539,7 +8521,7 @@ const runEntityRequest = async (runtime, effect, request) => {
8539
8521
  try {
8540
8522
  return await runtime.runPromise(effect, signal === void 0 ? void 0 : { signal });
8541
8523
  } catch (error) {
8542
- if (!(error instanceof CiTransportError) && signal?.aborted !== true) throw error;
8524
+ if (!Schema.is(CiTransportError)(error) && signal?.aborted !== true) throw error;
8543
8525
  return {
8544
8526
  correlationId: request.correlationId,
8545
8527
  error: {
@@ -8591,7 +8573,7 @@ const capabilityOf = {
8591
8573
  };
8592
8574
  /** The adapter over an `EntityTransport` of the app; a rejection fails with `CiTransportError`. */
8593
8575
  const fromEntityTransport = (transport) => (request, options) => Effect.tryPromise({
8594
- catch: (cause) => cause instanceof CiTransportError ? cause : new CiTransportError({ cause }),
8576
+ catch: (cause) => Schema.is(CiTransportError)(cause) ? cause : new CiTransportError({ cause }),
8595
8577
  try: (signal) => transport.execute(request, { signal: options.signal === void 0 ? signal : AbortSignal.any([options.signal, signal]) })
8596
8578
  });
8597
8579
  /** Internal. The envelope core of the entity client of one definition. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@collective-intelligence/external-apps-client-sdk",
3
- "version": "0.2.18",
3
+ "version": "0.2.20",
4
4
  "description": "Framework-neutral client for Collective Intelligence external applications.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -62,6 +62,7 @@
62
62
  "@effect/eslint-plugin": "0.3.2",
63
63
  "@effect/vitest": "4.1.2",
64
64
  "@oxlint/plugins": "1.90.0",
65
+ "@punks/lints": "0.2.0",
65
66
  "@types/bun": "1.4.2",
66
67
  "@typescript-eslint/utils": "8.22.0",
67
68
  "effect": "4.1.2",
@@ -74,5 +75,5 @@
74
75
  "ultracite": "7.10.7",
75
76
  "vitest": "5.0.2"
76
77
  },
77
- "gitHead": "b9fb8e902754f2b7fa4ba97a4103cbb37d7f36f6"
78
+ "gitHead": "4cefe91552731170db20795b65c41115fd65c62b"
78
79
  }