set-device-token.ts
1 import type { Identification } from "~/models"; 2 import { defaultFetcher, type Fetcher, type Request } from "@literate.ink/utilities"; 3 import { CLIENT_TYPE, SERVICE_VERSION, SOAP_URL, SOAP_USER_AGENT } from "~/core/constants"; 4 import { xml } from "~/core/xml"; 5 6 export const setDeviceToken = async (identification: Identification, fetcher: Fetcher = defaultFetcher): Promise<void> => { 7 const body = xml.header + xml.envelope(` 8 <SetDeviceToken xmlns="Service" id="o0" c:root="1"> 9 ${xml.property("version", SERVICE_VERSION)} 10 ${xml.property("channel", "AIZ")} 11 ${xml.property("format", "T")} 12 ${xml.property("model", "A")} 13 ${xml.property("language", "fr")} 14 ${xml.property("sessionId", identification.sessionID)} 15 ${xml.property("userId", identification.identifier)} 16 ${xml.property("tokentype", "GCM")} 17 ${xml.property("token", identification.token)} 18 </SetDeviceToken> 19 `); 20 21 const request: Request = { 22 content: body, 23 headers: { 24 "Authorization": `Bearer ${identification.accessToken}`, 25 "clientVersion": SERVICE_VERSION, 26 "Content-Type": "text/xml;charset=utf-8", 27 "smoneyClientType": CLIENT_TYPE, 28 "SOAPAction": "Service/SetDeviceToken", 29 "User-Agent": SOAP_USER_AGENT 30 }, 31 method: "POST", 32 url: SOAP_URL 33 }; 34 35 await fetcher(request); 36 };