UNPKG

@arc-publishing/sdk-amp

Version:
36 lines 1.27 kB
import { __assign } from "tslib"; import JSONResponseHandler from '@arc-publishing/sdk-subs-core/lib/utils/JSONResponseHandler'; import { headers } from './constants'; import { getValidURL } from './utils'; import AMP from './amp'; export function isAMPReaderSaved(x) { return !!(x.message === 'ok'); } export default function saveAMPReaderID(ampReaderId) { var url = typeof window !== 'undefined' ? getValidURL(AMP.apiOrigin) : AMP.apiOrigin; return AMP._Identity .heartbeat() .then(function () { return fetch("".concat(url, "/sales/public/v1/amp/add"), { method: 'PUT', headers: __assign({ Authorization: "Bearer ".concat(AMP._Identity.userIdentity.accessToken) }, headers), body: JSON.stringify({ ampReaderId: ampReaderId }) }); }) .then(JSONResponseHandler) .then(function (json) { return new Promise(function (resolve, reject) { setTimeout(function () { if (isAMPReaderSaved(json)) { resolve(true); } else { reject(json); } }, 375); }); }); } //# sourceMappingURL=saveAMPReaderID.js.map