(fn: (client: Autumn) => Promise<A>)
| 163 | }); |
| 164 | |
| 165 | const use = <A>(fn: (client: Autumn) => Promise<A>) => |
| 166 | Effect.tryPromise({ |
| 167 | try: () => fn(client), |
| 168 | catch: (cause): AutumnFailure => |
| 169 | isCustomerNotFoundCause(cause) |
| 170 | ? new AutumnCustomerNotFoundError({ |
| 171 | message: "Autumn has no customer for this organization", |
| 172 | cause, |
| 173 | }) |
| 174 | : new AutumnError({ message: "Autumn SDK request failed", cause }), |
| 175 | // An inline arrow's `name` is "" — not nullish — so `??` left every |
| 176 | // Autumn call tracing as the bare span `autumn.`. |
| 177 | }).pipe(Effect.withSpan(`autumn.${fn.name || "use"}`)); |
| 178 | |
| 179 | const ensureCustomer = (organizationId: string) => |
| 180 | Effect.asVoid(use((c) => c.customers.getOrCreate({ customerId: organizationId }))); |
no test coverage detected