MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / use

Function use

packages/plugins/workos-vault/src/sdk/client.ts:155–198  ·  view source on GitHub ↗
(
    operation: string,
    fn: (vault: WorkOSVaultPromiseApi) => Promise<A>,
    options?: WorkOSVaultUseOptions,
  )

Source from the content-addressed store, hash-verified

153 const client: WorkOSVaultPromiseApi = workos.vault;
154
155 const use = <A>(
156 operation: string,
157 fn: (vault: WorkOSVaultPromiseApi) => Promise<A>,
158 options?: WorkOSVaultUseOptions,
159 ): Effect.Effect<A, WorkOSVaultClientError, never> => {
160 const attempt = Effect.tryPromise({
161 try: () => fn(client),
162 catch: (cause) => new WorkOSVaultClientError({ cause, operation }),
163 });
164
165 const observed = attempt.pipe(
166 Effect.result,
167 Effect.flatMap((outcome) =>
168 Effect.gen(function* () {
169 if (Result.isSuccess(outcome)) {
170 yield* Effect.annotateCurrentSpan({ "workos_vault.outcome": "ok" });
171 return outcome;
172 }
173
174 const status = outcome.failure.status;
175 if (isExpectedVaultError(outcome.failure, options)) {
176 yield* Effect.annotateCurrentSpan({
177 "workos_vault.outcome": options?.expectedErrorOutcome ?? "expected_error",
178 "workos_vault.status": status ?? "unknown",
179 });
180 return outcome;
181 }
182
183 yield* Effect.annotateCurrentSpan({
184 "workos_vault.outcome": "error",
185 "workos_vault.status": status ?? "unknown",
186 });
187 return yield* Effect.fail(outcome.failure);
188 }),
189 ),
190 Effect.withSpan(`workos_vault.${operation}`),
191 );
192
193 return observed.pipe(
194 Effect.flatMap((outcome) =>
195 Result.isSuccess(outcome) ? Effect.succeed(outcome.success) : Effect.fail(outcome.failure),
196 ),
197 );
198 };
199
200 return {
201 use,

Callers 1

makeWorkOSVaultClientFunction · 0.70

Calls 1

isExpectedVaultErrorFunction · 0.85

Tested by

no test coverage detected