-
Notifications
You must be signed in to change notification settings - Fork 0
/
merchi-ssr.js
27 lines (25 loc) · 955 Bytes
/
merchi-ssr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { merchi as sdk_merchi } from "../../sdk/javascript/merchi";
import { cleanUndefinedToNull } from "./entity-resolver";
const MERCHI = sdk_merchi("https://api.staging.merchi.co/", "https://websockets.staging.merchi.co/");
export async function useSSR(fun) {
return {
props: {
data: await new Promise((resolve, reject) => {
fun((data) => {
if (Array.isArray(data)) {
const resolution = cleanUndefinedToNull(MERCHI.toJsonList(data))
resolve(resolution)
} else {
const resolution = cleanUndefinedToNull(MERCHI.toJson(data))
resolve(resolution)
}
}, reject)
})
}
}
}
export async function fetchSSR(entity, embed) {
return useSSR((onSuccess, onFailed) => {
entity.get(onSuccess, onFailed, embed)
})
}