({
initOptions,
}: Args = {})
| 32 | } |
| 33 | |
| 34 | export const getPayloadClient = async ({ |
| 35 | initOptions, |
| 36 | }: Args = {}): Promise<Payload> => { |
| 37 | if (!process.env.PAYLOAD_SECRET) { |
| 38 | throw new Error('PAYLOAD_SECRET is missing') |
| 39 | } |
| 40 | |
| 41 | if (cached.client) { |
| 42 | return cached.client |
| 43 | } |
| 44 | |
| 45 | if (!cached.promise) { |
| 46 | cached.promise = payload.init({ |
| 47 | email: { |
| 48 | transport: transporter, |
| 49 | fromAddress: 'hello@joshtriedcoding.com', |
| 50 | fromName: 'DigitalHippo', |
| 51 | }, |
| 52 | secret: process.env.PAYLOAD_SECRET, |
| 53 | local: initOptions?.express ? false : true, |
| 54 | ...(initOptions || {}), |
| 55 | }) |
| 56 | } |
| 57 | |
| 58 | try { |
| 59 | cached.client = await cached.promise |
| 60 | } catch (e: unknown) { |
| 61 | cached.promise = null |
| 62 | throw e |
| 63 | } |
| 64 | |
| 65 | return cached.client |
| 66 | } |
no outgoing calls
no test coverage detected