@axinom/mosaic-user-auth 0.3.8-rc.5 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1637,9 +1637,6 @@ const InitiateConsumerPasswordResetDocument = { "kind": "Document", "definitions
1637
1637
  const CheckPasswordResetOtpDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CheckPasswordResetOtp" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "CheckConsumerPasswordResetOtpInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "checkConsumerPasswordResetOtp" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "isOtpValid" }, "arguments": [], "directives": [] }] } }] } }] };
1638
1638
  const CompleteConsumerPasswordResetDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CompleteConsumerPasswordReset" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "CompleteConsumerPasswordResetInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "completeConsumerPasswordReset" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "idpUserId" }, "arguments": [], "directives": [] }] } }] } }] };
1639
1639
 
1640
- // A valid user token is cached in order to reduce unnecessary calls to the User Auth API
1641
- // It is nullified just before the expiry so that the next call to `getUserToken` will retrieve a new token
1642
- let currentUserToken = null;
1643
1640
  function invokeUserAuthMethod(method, userAuthConfig, isRootLevel = false) {
1644
1641
  return __awaiter(this, void 0, void 0, function* () {
1645
1642
  const endpointUrl = new URL(`${userAuthConfig.tenantId}/${userAuthConfig.environmentId}/${userAuthConfig.applicationId}/${method}`, userAuthConfig.userAuthBaseUrl);
@@ -1955,21 +1952,6 @@ const fetchUserToken = (userAuthConfig) => __awaiter(void 0, void 0, void 0, fun
1955
1952
  };
1956
1953
  }
1957
1954
  });
1958
- /**
1959
- * Returns a user token. The method will ensure to avoid unnecessary API calls by caching valid user tokens.
1960
- */
1961
- const getUserToken = (userAuthConfig) => __awaiter(void 0, void 0, void 0, function* () {
1962
- if ((currentUserToken === null || currentUserToken === void 0 ? void 0 : currentUserToken.expiresAt) === undefined ||
1963
- currentUserToken.expiresAt <= new Date(Date.now())) {
1964
- currentUserToken = null;
1965
- }
1966
- if (currentUserToken !== null) {
1967
- // A valid user token is already available
1968
- return Promise.resolve(currentUserToken);
1969
- }
1970
- currentUserToken = yield fetchUserToken(userAuthConfig);
1971
- return currentUserToken;
1972
- });
1973
1955
  const logoutUser = (userAuthConfig) => __awaiter(void 0, void 0, void 0, function* () {
1974
1956
  const logoutResponse = yield invokeUserAuthMethod('sign-out', userAuthConfig);
1975
1957
  return logoutResponse.code === dist.SignOutResponseCode.SUCCESS;
@@ -2073,18 +2055,18 @@ var UsersOrderBy$1;
2073
2055
  UsersOrderBy["UPDATED_USER_ASC"] = "UPDATED_USER_ASC";
2074
2056
  UsersOrderBy["UPDATED_USER_DESC"] = "UPDATED_USER_DESC";
2075
2057
  })(UsersOrderBy$1 || (UsersOrderBy$1 = {}));
2076
- const SetActiveProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "SetActiveProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UUID" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "setActiveProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "profileId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] };
2077
- const GetUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UUID" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "id" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] };
2078
- const GetUserProfilesDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetUserProfiles" }, "variableDefinitions": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfiles" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "nodes" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2079
- const CreateUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "CreateUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "createUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2080
- const UpdateUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UpdateUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "updateUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2081
- const DeleteUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeleteUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "DeleteUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "deleteUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profileData" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2058
+ const SetActiveProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "SetActiveProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UUID" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "setActiveProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "profileId" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] };
2059
+ const GetUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UUID" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "id" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "profileId" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] };
2060
+ const GetUserProfilesDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "query", "name": { "kind": "Name", "value": "GetUserProfiles" }, "variableDefinitions": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfiles" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "nodes" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2061
+ const CreateUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "CreateUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "CreateUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "createUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2062
+ const UpdateUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "UpdateUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "UpdateUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "updateUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2063
+ const DeleteUserProfileDocument = { "kind": "Document", "definitions": [{ "kind": "OperationDefinition", "operation": "mutation", "name": { "kind": "Name", "value": "DeleteUserProfile" }, "variableDefinitions": [{ "kind": "VariableDefinition", "variable": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } }, "type": { "kind": "NonNullType", "type": { "kind": "NamedType", "name": { "kind": "Name", "value": "DeleteUserProfileInput" } } }, "directives": [] }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "deleteUserProfile" }, "arguments": [{ "kind": "Argument", "name": { "kind": "Name", "value": "input" }, "value": { "kind": "Variable", "name": { "kind": "Name", "value": "input" } } }], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "userProfile" }, "arguments": [], "directives": [], "selectionSet": { "kind": "SelectionSet", "selections": [{ "kind": "Field", "name": { "kind": "Name", "value": "id" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "displayName" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "defaultProfile" }, "arguments": [], "directives": [] }, { "kind": "Field", "name": { "kind": "Name", "value": "profilePictureUrl" }, "arguments": [], "directives": [] }] } }] } }] } }] };
2082
2064
 
2083
2065
  const setActiveProfile = (userServiceBaseUrl, accessToken, profileId) => __awaiter(void 0, void 0, void 0, function* () {
2084
2066
  const variables = {
2085
2067
  profileId,
2086
2068
  };
2087
- const activeUserProfile = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2069
+ const activeUserProfile = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2088
2070
  method: 'POST',
2089
2071
  cache: 'no-cache',
2090
2072
  redirect: 'follow',
@@ -2094,14 +2076,24 @@ const setActiveProfile = (userServiceBaseUrl, accessToken, profileId) => __await
2094
2076
  'content-type': 'application/json',
2095
2077
  },
2096
2078
  body: stringifyGqlQuery(SetActiveProfileDocument, variables),
2097
- })).json()).data.setActiveProfile;
2098
- return activeUserProfile !== undefined && activeUserProfile !== null;
2079
+ })).json();
2080
+ if (activeUserProfile.errors === undefined) {
2081
+ return {
2082
+ code: 'SUCCESS',
2083
+ };
2084
+ }
2085
+ else {
2086
+ return {
2087
+ code: 'ERROR',
2088
+ message: activeUserProfile.errors[0].message,
2089
+ };
2090
+ }
2099
2091
  });
2100
2092
  const getUserProfile = (userServiceBaseUrl, accessToken, profileId) => __awaiter(void 0, void 0, void 0, function* () {
2101
2093
  const variables = {
2102
2094
  profileId,
2103
2095
  };
2104
- const userProfile = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2096
+ const userProfileResponse = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2105
2097
  method: 'POST',
2106
2098
  cache: 'no-cache',
2107
2099
  redirect: 'follow',
@@ -2111,11 +2103,22 @@ const getUserProfile = (userServiceBaseUrl, accessToken, profileId) => __awaiter
2111
2103
  'content-type': 'application/json',
2112
2104
  },
2113
2105
  body: stringifyGqlQuery(GetUserProfileDocument, variables),
2114
- })).json()).data.userProfile;
2115
- return userProfile;
2106
+ })).json();
2107
+ if (userProfileResponse.errors === undefined) {
2108
+ return {
2109
+ code: 'SUCCESS',
2110
+ userProfile: userProfileResponse.data.userProfile,
2111
+ };
2112
+ }
2113
+ else {
2114
+ return {
2115
+ code: 'ERROR',
2116
+ message: userProfileResponse.errors[0].message,
2117
+ };
2118
+ }
2116
2119
  });
2117
2120
  const getUserProfiles = (userServiceBaseUrl, accessToken) => __awaiter(void 0, void 0, void 0, function* () {
2118
- const userProfiles = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2121
+ const userProfilesResponse = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2119
2122
  method: 'POST',
2120
2123
  cache: 'no-cache',
2121
2124
  redirect: 'follow',
@@ -2125,18 +2128,30 @@ const getUserProfiles = (userServiceBaseUrl, accessToken) => __awaiter(void 0, v
2125
2128
  'content-type': 'application/json',
2126
2129
  },
2127
2130
  body: stringifyGqlQuery(GetUserProfilesDocument),
2128
- })).json()).data.userProfiles.nodes;
2129
- return userProfiles;
2131
+ })).json();
2132
+ if (userProfilesResponse.errors === undefined) {
2133
+ return {
2134
+ code: 'SUCCESS',
2135
+ userProfiles: userProfilesResponse.data.userProfiles.nodes,
2136
+ };
2137
+ }
2138
+ else {
2139
+ return {
2140
+ code: 'ERROR',
2141
+ message: userProfilesResponse.errors[0].message,
2142
+ };
2143
+ }
2130
2144
  });
2131
- const createUserProfile = (userServiceBaseUrl, accessToken, displayName) => __awaiter(void 0, void 0, void 0, function* () {
2145
+ const createUserProfile = (userServiceBaseUrl, accessToken, displayName, profilePictureUrl) => __awaiter(void 0, void 0, void 0, function* () {
2132
2146
  const variables = {
2133
2147
  input: {
2134
2148
  userProfile: {
2135
2149
  displayName: displayName,
2150
+ profilePictureUrl: profilePictureUrl === '' ? null : profilePictureUrl,
2136
2151
  },
2137
2152
  },
2138
2153
  };
2139
- const createdUserProfile = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2154
+ const createUserProfileResponse = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2140
2155
  method: 'POST',
2141
2156
  cache: 'no-cache',
2142
2157
  redirect: 'follow',
@@ -2146,8 +2161,19 @@ const createUserProfile = (userServiceBaseUrl, accessToken, displayName) => __aw
2146
2161
  'content-type': 'application/json',
2147
2162
  },
2148
2163
  body: stringifyGqlQuery(CreateUserProfileDocument, variables),
2149
- })).json()).data.createUserProfile.userProfile;
2150
- return createdUserProfile;
2164
+ })).json();
2165
+ if (createUserProfileResponse.errors === undefined) {
2166
+ return {
2167
+ code: 'SUCCESS',
2168
+ createdUserProfile: createUserProfileResponse.data.createUserProfile.userProfile,
2169
+ };
2170
+ }
2171
+ else {
2172
+ return {
2173
+ code: 'ERROR',
2174
+ message: createUserProfileResponse.errors[0].message,
2175
+ };
2176
+ }
2151
2177
  });
2152
2178
  /**
2153
2179
  * Updates a user profile
@@ -2160,12 +2186,13 @@ const updateUserProfile = (userServiceBaseUrl, accessToken, userProfileToUpdate)
2160
2186
  id: userProfileToUpdate.id,
2161
2187
  patch: {
2162
2188
  displayName: userProfileToUpdate.displayName,
2163
- profilePictureUrl: userProfileToUpdate.profilePictureUrl,
2164
- profileData: userProfileToUpdate.profileData,
2189
+ profilePictureUrl: userProfileToUpdate.profilePictureUrl === ''
2190
+ ? null
2191
+ : userProfileToUpdate.profilePictureUrl,
2165
2192
  },
2166
2193
  },
2167
2194
  };
2168
- const updatedUserProfile = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2195
+ const updateUserProfileResponse = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2169
2196
  method: 'POST',
2170
2197
  cache: 'no-cache',
2171
2198
  redirect: 'follow',
@@ -2175,8 +2202,19 @@ const updateUserProfile = (userServiceBaseUrl, accessToken, userProfileToUpdate)
2175
2202
  'content-type': 'application/json',
2176
2203
  },
2177
2204
  body: stringifyGqlQuery(UpdateUserProfileDocument, variables),
2178
- })).json()).data.updateUserProfile.userProfile;
2179
- return updatedUserProfile;
2205
+ })).json();
2206
+ if (updateUserProfileResponse.errors === undefined) {
2207
+ return {
2208
+ code: 'SUCCESS',
2209
+ updatedUserProfile: updateUserProfileResponse.data.updateUserProfile.userProfile,
2210
+ };
2211
+ }
2212
+ else {
2213
+ return {
2214
+ code: 'ERROR',
2215
+ message: updateUserProfileResponse.errors[0].message,
2216
+ };
2217
+ }
2180
2218
  });
2181
2219
  const deleteUserProfile = (userServiceBaseUrl, accessToken, userProfileId) => __awaiter(void 0, void 0, void 0, function* () {
2182
2220
  const variables = {
@@ -2184,7 +2222,7 @@ const deleteUserProfile = (userServiceBaseUrl, accessToken, userProfileId) => __
2184
2222
  id: userProfileId,
2185
2223
  },
2186
2224
  };
2187
- const deletedUserProfile = (yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2225
+ const deleteUserProfileResponse = yield (yield fetch(`${userServiceBaseUrl}/graphql`, {
2188
2226
  method: 'POST',
2189
2227
  cache: 'no-cache',
2190
2228
  redirect: 'follow',
@@ -2194,8 +2232,19 @@ const deleteUserProfile = (userServiceBaseUrl, accessToken, userProfileId) => __
2194
2232
  'content-type': 'application/json',
2195
2233
  },
2196
2234
  body: stringifyGqlQuery(DeleteUserProfileDocument, variables),
2197
- })).json()).data.deleteUserProfile.userProfile;
2198
- return deletedUserProfile;
2235
+ })).json();
2236
+ if (deleteUserProfileResponse.errors === undefined) {
2237
+ return {
2238
+ code: 'SUCCESS',
2239
+ deletedUserProfile: deleteUserProfileResponse.data.deleteUserProfile.userProfile,
2240
+ };
2241
+ }
2242
+ else {
2243
+ return {
2244
+ code: 'ERROR',
2245
+ message: deleteUserProfileResponse.errors[0].message,
2246
+ };
2247
+ }
2199
2248
  });
2200
2249
 
2201
2250
  /**
@@ -2228,11 +2277,11 @@ class UserServiceClient {
2228
2277
  this.fetchToken = () => __awaiter(this, void 0, void 0, function* () {
2229
2278
  try {
2230
2279
  const userToken = yield fetchUserToken(this.userAuthConfig);
2231
- const userProfile = yield getUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, userToken.profileId);
2280
+ const userProfileResponse = yield getUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, userToken.profileId);
2232
2281
  return {
2233
2282
  code: 'SUCCESS',
2234
2283
  userToken,
2235
- userProfile,
2284
+ userProfile: userProfileResponse.userProfile,
2236
2285
  nextTokenRenewalAt: new Date(Date.now() +
2237
2286
  (userToken.expiresInSeconds -
2238
2287
  inAdvanceTokenRenewalDurationInSeconds) *
@@ -2534,49 +2583,79 @@ class UserServiceClient {
2534
2583
  /**
2535
2584
  * Sets a given Profile ID as the active profile
2536
2585
  */
2537
- this.setActiveProfile = (profileId) => __awaiter(this, void 0, void 0, function* () {
2538
- const userToken = yield getUserToken(this.userAuthConfig);
2539
- const result = yield setActiveProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, profileId);
2540
- // current token is invalid now since the active profile has changed
2541
- // we clear the current token response here so that the next call will retrieve a new token
2542
- this.tokenResponse = null;
2543
- return result;
2586
+ this.setActiveProfile = (endUserAccessToken, profileId) => __awaiter(this, void 0, void 0, function* () {
2587
+ try {
2588
+ const result = yield setActiveProfile(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken, profileId);
2589
+ // current token is invalid now since the active profile has changed
2590
+ // we clear the current token response here so that the next call will retrieve a new token
2591
+ this.tokenResponse = null;
2592
+ return result;
2593
+ }
2594
+ catch (error) {
2595
+ assertError(error);
2596
+ return { code: 'ERROR', message: error.message };
2597
+ }
2544
2598
  });
2545
2599
  /**
2546
2600
  * Returns a user profile
2547
2601
  */
2548
- this.getUserProfile = (profileId) => __awaiter(this, void 0, void 0, function* () {
2549
- const userToken = yield getUserToken(this.userAuthConfig);
2550
- return getUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, profileId);
2602
+ this.getUserProfile = (endUserAccessToken, profileId) => __awaiter(this, void 0, void 0, function* () {
2603
+ try {
2604
+ return getUserProfile(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken, profileId);
2605
+ }
2606
+ catch (error) {
2607
+ assertError(error);
2608
+ return { code: 'ERROR', message: error.message };
2609
+ }
2551
2610
  });
2552
2611
  /**
2553
2612
  * Returns an array of all user profiles
2554
2613
  */
2555
- this.getUserProfiles = () => __awaiter(this, void 0, void 0, function* () {
2556
- const userToken = yield getUserToken(this.userAuthConfig);
2557
- return getUserProfiles(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken);
2614
+ this.getUserProfiles = (endUserAccessToken) => __awaiter(this, void 0, void 0, function* () {
2615
+ try {
2616
+ return getUserProfiles(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken);
2617
+ }
2618
+ catch (error) {
2619
+ assertError(error);
2620
+ return { code: 'ERROR', message: error.message };
2621
+ }
2558
2622
  });
2559
2623
  /**
2560
2624
  * Creates a new user profile
2561
2625
  */
2562
- this.createUserProfile = (displayName) => __awaiter(this, void 0, void 0, function* () {
2563
- const userToken = yield getUserToken(this.userAuthConfig);
2564
- return createUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, displayName);
2626
+ this.createUserProfile = (endUserAccessToken, displayName, profilePictureUrl) => __awaiter(this, void 0, void 0, function* () {
2627
+ try {
2628
+ return createUserProfile(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken, displayName, profilePictureUrl);
2629
+ }
2630
+ catch (error) {
2631
+ assertError(error);
2632
+ return { code: 'ERROR', message: error.message };
2633
+ }
2565
2634
  });
2566
2635
  /**
2567
2636
  * Updates a user profile
2568
2637
  * @param userProfileToUpdate User Profile object with required updates. This should be based on the current user profile object, with the required changes done on top of it.
2569
2638
  */
2570
- this.updateUserProfile = (userProfileToUpdate) => __awaiter(this, void 0, void 0, function* () {
2571
- const userToken = yield getUserToken(this.userAuthConfig);
2572
- return updateUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, userProfileToUpdate);
2639
+ this.updateUserProfile = (endUserAccessToken, userProfileToUpdate) => __awaiter(this, void 0, void 0, function* () {
2640
+ try {
2641
+ return updateUserProfile(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken, userProfileToUpdate);
2642
+ }
2643
+ catch (error) {
2644
+ assertError(error);
2645
+ return { code: 'ERROR', message: error.message };
2646
+ }
2573
2647
  });
2574
2648
  /**
2575
2649
  * Deletes a user profile
2576
2650
  */
2577
- this.deleteUserProfile = (userProfileId) => __awaiter(this, void 0, void 0, function* () {
2578
- const userToken = yield getUserToken(this.userAuthConfig);
2579
- return deleteUserProfile(this.userServiceConfig.userServiceBaseUrl, userToken.accessToken, userProfileId);
2651
+ this.deleteUserProfile = (endUserAccessToken, userProfileId) => __awaiter(this, void 0, void 0, function* () {
2652
+ try {
2653
+ return deleteUserProfile(this.userServiceConfig.userServiceBaseUrl, endUserAccessToken, userProfileId);
2654
+ }
2655
+ catch (error) {
2656
+ assertError(error);
2657
+ return { code: 'ERROR', message: error.message };
2658
+ }
2580
2659
  });
2581
2660
  /**
2582
2661
  * Authenticate a consumer application and receive an Application Token