(fn: (client: Autumn) => Promise<A>)
| 107 | }); |
| 108 | |
| 109 | const use = <A>(fn: (client: Autumn) => Promise<A>) => |
| 110 | Effect.tryPromise({ |
| 111 | try: () => fn(client), |
| 112 | catch: (cause): AutumnFailure => |
| 113 | isCustomerNotFoundCause(cause) |
| 114 | ? new AutumnCustomerNotFoundError({ |
| 115 | message: "Autumn has no customer for this organization", |
| 116 | cause, |
| 117 | }) |
| 118 | : new AutumnError({ message: "Autumn SDK request failed", cause }), |
| 119 | // An inline arrow's `name` is "" — not nullish — so `??` left every |
| 120 | // Autumn call tracing as the bare span `autumn.`. |
| 121 | }).pipe(Effect.withSpan(`autumn.${fn.name || "use"}`)); |
| 122 | |
| 123 | const ensureCustomer = (organizationId: string) => |
| 124 | Effect.asVoid(use((c) => c.customers.getOrCreate({ customerId: organizationId }))); |
no test coverage detected