(fn: (client: Autumn) => Promise<A>)
| 129 | }); |
| 130 | |
| 131 | const use = <A>(fn: (client: Autumn) => Promise<A>) => |
| 132 | Effect.tryPromise({ |
| 133 | try: () => fn(client), |
| 134 | catch: (cause): AutumnFailure => |
| 135 | isCustomerNotFoundCause(cause) |
| 136 | ? new AutumnCustomerNotFoundError({ |
| 137 | message: "Autumn has no customer for this organization", |
| 138 | cause, |
| 139 | }) |
| 140 | : new AutumnError({ message: "Autumn SDK request failed", cause }), |
| 141 | // An inline arrow's `name` is "" — not nullish — so `??` left every |
| 142 | // Autumn call tracing as the bare span `autumn.`. |
| 143 | }).pipe(Effect.withSpan(`autumn.${fn.name || "use"}`)); |
| 144 | |
| 145 | const ensureCustomer = (organizationId: string) => |
| 146 | Effect.asVoid(use((c) => c.customers.getOrCreate({ customerId: organizationId }))); |
no test coverage detected