UNPKG

@arc-publishing/sdk-identity

Version:
48 lines 2.29 kB
import { __assign, __awaiter, __generator } from "tslib"; import { headers, logPrefix } from './constants'; import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler'; import { isAPIErrorResponse } from '../serviceHelpers/APIErrorResponse'; import Identity from './identity'; import { isUserSegment } from './userSegments'; export default function getUserSegments() { return __awaiter(this, void 0, void 0, function () { var isLoggedIn; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, Identity.isLoggedIn()]; case 1: isLoggedIn = _a.sent(); if (!isLoggedIn) { throw new Error("".concat(logPrefix, " Missing or invalid jwt")); } return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v2/identity/segmentation"), { method: 'GET', cache: 'no-cache', headers: __assign({ Authorization: "Bearer ".concat(Identity.userIdentity.accessToken) }, headers) }) .then(JSONResponseHandler) .then(function (json) { var userSegments = { updated: new Date(), uuid: Identity.userIdentity.uuid, segments: {} }; if (isUserSegment(json)) { Identity.userSegments = __assign(__assign({}, userSegments), { segments: json }); return json; } else { if (!isAPIErrorResponse(json)) { Identity.userSegments = userSegments; return {}; } else { throw json; } } })]; } }); }); } //# sourceMappingURL=getUserSegments.js.map