UNPKG

@arc-publishing/sdk-identity

Version:
51 lines 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var constants_1 = require("./constants"); var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler")); var APIErrorResponse_1 = require("../serviceHelpers/APIErrorResponse"); var identity_1 = tslib_1.__importDefault(require("./identity")); var userSegments_1 = require("./userSegments"); function getUserSegments() { return tslib_1.__awaiter(this, void 0, void 0, function () { var isLoggedIn; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4, identity_1.default.isLoggedIn()]; case 1: isLoggedIn = _a.sent(); if (!isLoggedIn) { throw new Error("".concat(constants_1.logPrefix, " Missing or invalid jwt")); } return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v2/identity/segmentation"), { method: 'GET', cache: 'no-cache', headers: tslib_1.__assign({ Authorization: "Bearer ".concat(identity_1.default.userIdentity.accessToken) }, constants_1.headers) }) .then(JSONResponseHandler_1.default) .then(function (json) { var userSegments = { updated: new Date(), uuid: identity_1.default.userIdentity.uuid, segments: {} }; if ((0, userSegments_1.isUserSegment)(json)) { identity_1.default.userSegments = tslib_1.__assign(tslib_1.__assign({}, userSegments), { segments: json }); return json; } else { if (!(0, APIErrorResponse_1.isAPIErrorResponse)(json)) { identity_1.default.userSegments = userSegments; return {}; } else { throw json; } } })]; } }); }); } exports.default = getUserSegments; //# sourceMappingURL=getUserSegments.js.map