@oneblink/sdk-core 0.1.1 → 0.1.3-beta.1
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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/replaceCustomValues.js +15 -15
- package/dist/replaceCustomValues.js.map +1 -1
- package/dist/userService.d.ts +3 -0
- package/dist/userService.js +78 -0
- package/dist/userService.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- `replaceCustomValues()` adding `"undefined"` to string
|
|
13
|
+
|
|
14
|
+
## [0.1.2] - 2021-09-08
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- [`userService`](./docs/userService.md)
|
|
19
|
+
|
|
10
20
|
## [0.1.1] - 2021-09-01
|
|
11
21
|
|
|
12
22
|
### Added
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * as formElementsService from './formElementsService';
|
|
2
|
+
export * as conditionalLogicService from './conditionalLogicService';
|
|
3
3
|
import replaceCustomValues from './replaceCustomValues';
|
|
4
|
-
|
|
5
|
-
export
|
|
4
|
+
export * as typeCastService from './typeCastService';
|
|
5
|
+
export * as userService from './userService';
|
|
6
|
+
export { replaceCustomValues };
|
package/dist/index.js
CHANGED
|
@@ -22,13 +22,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
26
|
-
|
|
27
|
-
exports.
|
|
28
|
-
const conditionalLogicService = __importStar(require("./conditionalLogicService"));
|
|
29
|
-
exports.conditionalLogicService = conditionalLogicService;
|
|
25
|
+
exports.replaceCustomValues = exports.userService = exports.typeCastService = exports.conditionalLogicService = exports.formElementsService = void 0;
|
|
26
|
+
exports.formElementsService = __importStar(require("./formElementsService"));
|
|
27
|
+
exports.conditionalLogicService = __importStar(require("./conditionalLogicService"));
|
|
30
28
|
const replaceCustomValues_1 = __importDefault(require("./replaceCustomValues"));
|
|
31
29
|
exports.replaceCustomValues = replaceCustomValues_1.default;
|
|
32
|
-
|
|
33
|
-
exports.
|
|
30
|
+
exports.typeCastService = __importStar(require("./typeCastService"));
|
|
31
|
+
exports.userService = __importStar(require("./userService"));
|
|
34
32
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA4D;AAC5D,qFAAoE;AACpE,gFAAuD;AAI9C,8BAJF,6BAAmB,CAIE;AAH5B,qEAAoD;AACpD,6DAA4C","sourcesContent":["export * as formElementsService from './formElementsService'\nexport * as conditionalLogicService from './conditionalLogicService'\nimport replaceCustomValues from './replaceCustomValues'\nexport * as typeCastService from './typeCastService'\nexport * as userService from './userService'\n\nexport { replaceCustomValues }\n"]}
|
|
@@ -49,23 +49,23 @@ function getElementSubmissionValue({ propertyName, submission, form, formatDate,
|
|
|
49
49
|
element.type !== 'section' &&
|
|
50
50
|
element.name === propertyName);
|
|
51
51
|
const value = submission[propertyName];
|
|
52
|
-
if (value
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
if (value === undefined || value === null) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
switch (formElement === null || formElement === void 0 ? void 0 : formElement.type) {
|
|
56
|
+
case 'datetime': {
|
|
57
|
+
return `${formatDate(value)} ${formatTime(value)}`;
|
|
58
|
+
}
|
|
59
|
+
case 'date': {
|
|
60
|
+
return formatDate(value);
|
|
61
|
+
}
|
|
62
|
+
case 'time': {
|
|
63
|
+
return formatTime(value);
|
|
64
|
+
}
|
|
65
|
+
default: {
|
|
66
|
+
return value;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
return value;
|
|
69
69
|
}
|
|
70
70
|
function replaceElementValues(text, { form, submission, formatDate, formatTime, }) {
|
|
71
71
|
const matches = text.match(/({ELEMENT:)([^}]+)(})/g);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replaceCustomValues.js","sourceRoot":"","sources":["../src/replaceCustomValues.ts"],"names":[],"mappings":";;AACA,+DAAuD;AAYvD,MAAM,aAAa,GAAG;IACpB;QACE,MAAM,EAAE,gBAAgB;QACxB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,kBAAkB;QAC1B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;KACpD;IACD;QACE,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;KACpD;IACD;QACE,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"version":3,"file":"replaceCustomValues.js","sourceRoot":"","sources":["../src/replaceCustomValues.ts"],"names":[],"mappings":";;AACA,+DAAuD;AAYvD,MAAM,aAAa,GAAG;IACpB;QACE,MAAM,EAAE,gBAAgB;QACxB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,kBAAkB;QAC1B,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;KACpD;IACD;QACE,MAAM,EAAE,WAAW;QACnB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE;KAC7D;IACD;QACE,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,CAAC,EAAE,IAAI,EAAuB,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI;KACpD;IACD;QACE,MAAM,EAAE,QAAQ;QAChB,KAAK,EAAE,CAAC,EACN,mBAAmB,EACnB,UAAU,EACV,UAAU,GACU,EAAE,EAAE;YACxB,IAAI,CAAC,mBAAmB,EAAE;gBACxB,OAAO,EAAE,CAAA;aACV;YACD,OAAO,GAAG,UAAU,CAAC,mBAAmB,CAAC,IAAI,UAAU,CACrD,mBAAmB,CACpB,EAAE,CAAA;QACL,CAAC;KACF;IACD;QACE,MAAM,EAAE,aAAa;QACrB,KAAK,EAAE,CAAC,EAAE,mBAAmB,EAAuB,EAAE,EAAE,CACtD,mBAAmB,IAAI,EAAE;KAC5B;IACD;QACE,MAAM,EAAE,iBAAiB;QACzB,KAAK,EAAE,CAAC,EAAE,YAAY,EAAuB,EAAE,EAAE,CAAC,YAAY,IAAI,EAAE;KACrE;IACD;QACE,MAAM,EAAE,eAAe;QACvB,KAAK,EAAE,CAAC,EAAE,UAAU,EAAuB,EAAE,EAAE,CAAC,UAAU,IAAI,EAAE;KACjE;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AS,EAAE,KAAK,EAAE,EAAE;QACzC,MAAM,YAAY,GAAG,KAAK,CAAC,SAAS,CAClC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EACtB,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CACvB,CAAA;QAED,MAAM,KAAK,GAAG,yBAAyB,CAAC;YACtC,YAAY;YACZ,IAAI;YACJ,UAAU;YACV,UAAU;YACV,UAAU;SACX,CAAC,CAAA;QAEF,OAAO,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IACxC,CAAC,EAAE,IAAI,CAAC,CAAA;AACV,CAAC;AAED,SAAwB,mBAAmB,CACzC,IAAY,EACZ,EACE,IAAI,EACJ,UAAU,EACV,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,kBAAkB,GAGnB;IAED,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,EAAE;QACxC,IAAI;QACJ,UAAU;QACV,UAAU;QACV,UAAU;KACX,CAAC,CAAA;IACF,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,WAAW,EAAE,EAAE;QACrD,OAAO,SAAS,CAAC,OAAO,CACtB,WAAW,CAAC,MAAM,EAClB,WAAW,CAAC,KAAK,CAAC;YAChB,IAAI;YACJ,mBAAmB;YACnB,UAAU;YACV,YAAY;YACZ,UAAU;YACV,UAAU;YACV,kBAAkB;SACnB,CAAC,CACH,CAAA;IACH,CAAC,EAAE,MAAM,CAAC,CAAA;AACZ,CAAC;AAnCD,sCAmCC","sourcesContent":["import { FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { findFormElement } from './formElementsService'\n\ntype CustomValuesOptions = {\n form: FormTypes.Form\n externalId?: string\n submissionId: string\n submissionTimestamp: string\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n previousApprovalId?: string\n}\n\nconst CUSTOM_VALUES = [\n {\n string: '{INFO_PAGE_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{INFO_PAGE_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{FORM_ID}',\n value: ({ form }: CustomValuesOptions) => form.id.toString(),\n },\n {\n string: '{FORM_NAME}',\n value: ({ form }: CustomValuesOptions) => form.name,\n },\n {\n string: '{DATE}',\n value: ({\n submissionTimestamp,\n formatDate,\n formatTime,\n }: CustomValuesOptions) => {\n if (!submissionTimestamp) {\n return ''\n }\n return `${formatDate(submissionTimestamp)} ${formatTime(\n submissionTimestamp,\n )}`\n },\n },\n {\n string: '{TIMESTAMP}',\n value: ({ submissionTimestamp }: CustomValuesOptions) =>\n submissionTimestamp || '',\n },\n {\n string: '{SUBMISSION_ID}',\n value: ({ submissionId }: CustomValuesOptions) => submissionId || '',\n },\n {\n string: '{EXTERNAL_ID}',\n value: ({ externalId }: CustomValuesOptions) => externalId || '',\n },\n {\n string: '{PREVIOUS_APPROVAL_ID}',\n value: ({ previousApprovalId }: CustomValuesOptions) =>\n previousApprovalId || '',\n },\n]\n\nfunction getElementSubmissionValue({\n propertyName,\n submission,\n form,\n formatDate,\n formatTime,\n}: {\n propertyName: string\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n}): string {\n const formElement = findFormElement(\n form.elements,\n (element) =>\n element.type !== 'page' &&\n element.type !== 'section' &&\n element.name === propertyName,\n )\n\n const value = submission[propertyName]\n if (value === undefined || value === null) {\n return ''\n }\n\n switch (formElement?.type) {\n case 'datetime': {\n return `${formatDate(value)} ${formatTime(value)}`\n }\n case 'date': {\n return formatDate(value)\n }\n case 'time': {\n return formatTime(value)\n }\n default: {\n return value\n }\n }\n}\n\nfunction replaceElementValues(\n text: string,\n {\n form,\n submission,\n formatDate,\n formatTime,\n }: {\n form: FormTypes.Form\n submission: SubmissionTypes.S3SubmissionData['submission']\n formatDate: (value: string) => string\n formatTime: (value: string) => string\n },\n): string {\n const matches = text.match(/({ELEMENT:)([^}]+)(})/g)\n if (!matches) {\n return text\n }\n\n return matches.reduce((newString, match) => {\n const propertyName = match.substring(\n match.indexOf(':') + 1,\n match.lastIndexOf('}'),\n )\n\n const value = getElementSubmissionValue({\n propertyName,\n form,\n submission,\n formatDate,\n formatTime,\n })\n\n return newString.replace(match, value)\n }, text)\n}\n\nexport default function replaceCustomValues(\n text: string,\n {\n form,\n submission,\n externalId,\n submissionId,\n submissionTimestamp,\n formatDate,\n formatTime,\n previousApprovalId,\n }: CustomValuesOptions & {\n submission: SubmissionTypes.S3SubmissionData['submission']\n },\n): string {\n const string = replaceElementValues(text, {\n form,\n submission,\n formatDate,\n formatTime,\n })\n return CUSTOM_VALUES.reduce((newString, customValue) => {\n return newString.replace(\n customValue.string,\n customValue.value({\n form,\n submissionTimestamp,\n externalId,\n submissionId,\n formatDate,\n formatTime,\n previousApprovalId,\n }),\n )\n }, string)\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUserFriendlyName = exports.parseUserProfile = void 0;
|
|
4
|
+
function parseUserProfile(data) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
if (typeof data !== 'object' || !data) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const jwtPayload = data;
|
|
10
|
+
if (typeof jwtPayload.sub !== 'string') {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const userProfile = {
|
|
14
|
+
isSAMLUser: false,
|
|
15
|
+
providerType: 'Cognito',
|
|
16
|
+
providerUserId: jwtPayload.sub,
|
|
17
|
+
userId: jwtPayload.sub,
|
|
18
|
+
email: typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,
|
|
19
|
+
firstName: typeof jwtPayload.given_name === 'string'
|
|
20
|
+
? jwtPayload.given_name
|
|
21
|
+
: undefined,
|
|
22
|
+
lastName: typeof jwtPayload.family_name === 'string'
|
|
23
|
+
? jwtPayload.family_name
|
|
24
|
+
: undefined,
|
|
25
|
+
fullName: typeof jwtPayload.name === 'string' ? jwtPayload.name : undefined,
|
|
26
|
+
picture: typeof jwtPayload.picture === 'string' ? jwtPayload.picture : undefined,
|
|
27
|
+
role: typeof jwtPayload['custom:role'] === 'string'
|
|
28
|
+
? jwtPayload['custom:role']
|
|
29
|
+
: undefined,
|
|
30
|
+
username: typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,
|
|
31
|
+
supervisor: {
|
|
32
|
+
fullName: typeof jwtPayload['custom:supervisor_name'] === 'string'
|
|
33
|
+
? jwtPayload['custom:supervisor_name']
|
|
34
|
+
: undefined,
|
|
35
|
+
email: typeof jwtPayload['custom:supervisor_email'] === 'string'
|
|
36
|
+
? jwtPayload['custom:supervisor_email']
|
|
37
|
+
: undefined,
|
|
38
|
+
providerUserId: typeof jwtPayload['custom:supervisor_user_id'] === 'string'
|
|
39
|
+
? jwtPayload['custom:supervisor_user_id']
|
|
40
|
+
: undefined,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
if (!((_a = userProfile.supervisor) === null || _a === void 0 ? void 0 : _a.fullName) &&
|
|
44
|
+
!((_b = userProfile.supervisor) === null || _b === void 0 ? void 0 : _b.email) &&
|
|
45
|
+
!((_c = userProfile.supervisor) === null || _c === void 0 ? void 0 : _c.providerUserId)) {
|
|
46
|
+
userProfile.supervisor = undefined;
|
|
47
|
+
}
|
|
48
|
+
if (jwtPayload.identities &&
|
|
49
|
+
Array.isArray(jwtPayload.identities) &&
|
|
50
|
+
jwtPayload.identities.length) {
|
|
51
|
+
const { providerType, userId } = jwtPayload.identities[0];
|
|
52
|
+
userProfile.providerType = providerType;
|
|
53
|
+
userProfile.providerUserId = userId;
|
|
54
|
+
userProfile.isSAMLUser = providerType === 'SAML';
|
|
55
|
+
if (userProfile.isSAMLUser) {
|
|
56
|
+
userProfile.username = jwtPayload.preferred_username || userId;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return userProfile;
|
|
60
|
+
}
|
|
61
|
+
exports.parseUserProfile = parseUserProfile;
|
|
62
|
+
function getUserFriendlyName(userProfile) {
|
|
63
|
+
if (userProfile.fullName) {
|
|
64
|
+
return userProfile.fullName;
|
|
65
|
+
}
|
|
66
|
+
if (userProfile.firstName || userProfile.lastName) {
|
|
67
|
+
return [userProfile.firstName, userProfile.lastName].join(' ').trim();
|
|
68
|
+
}
|
|
69
|
+
if (userProfile.email) {
|
|
70
|
+
return userProfile.email;
|
|
71
|
+
}
|
|
72
|
+
if (userProfile.username) {
|
|
73
|
+
return userProfile.username;
|
|
74
|
+
}
|
|
75
|
+
return userProfile.userId;
|
|
76
|
+
}
|
|
77
|
+
exports.getUserFriendlyName = getUserFriendlyName;
|
|
78
|
+
//# sourceMappingURL=userService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userService.js","sourceRoot":"","sources":["../src/userService.ts"],"names":[],"mappings":";;;AAEA,SAAgB,gBAAgB,CAC9B,IAAa;;IAEb,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE;QACrC,OAAM;KACP;IACD,MAAM,UAAU,GAAG,IAA+B,CAAA;IAClD,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE;QACtC,OAAM;KACP;IACD,MAAM,WAAW,GAA0B;QACzC,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,SAAS;QACvB,cAAc,EAAE,UAAU,CAAC,GAAG;QAC9B,MAAM,EAAE,UAAU,CAAC,GAAG;QACtB,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;QAC1E,SAAS,EACP,OAAO,UAAU,CAAC,UAAU,KAAK,QAAQ;YACvC,CAAC,CAAC,UAAU,CAAC,UAAU;YACvB,CAAC,CAAC,SAAS;QACf,QAAQ,EACN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SAAS,CAAA;KACnC;IAED,IACE,UAAU,CAAC,UAAU;QACrB,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC;QACpC,UAAU,CAAC,UAAU,CAAC,MAAM,EAC5B;QACA,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QACzD,WAAW,CAAC,YAAY,GAAG,YAAY,CAAA;QACvC,WAAW,CAAC,cAAc,GAAG,MAAM,CAAA;QACnC,WAAW,CAAC,UAAU,GAAG,YAAY,KAAK,MAAM,CAAA;QAChD,IAAI,WAAW,CAAC,UAAU,EAAE;YAC1B,WAAW,CAAC,QAAQ,GAAG,UAAU,CAAC,kBAAkB,IAAI,MAAM,CAAA;SAC/D;KACF;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAxED,4CAwEC;AAED,SAAgB,mBAAmB,CACjC,WAAkC;IAElC,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAA;KAC5B;IAED,IAAI,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,QAAQ,EAAE;QACjD,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;KACtE;IAED,IAAI,WAAW,CAAC,KAAK,EAAE;QACrB,OAAO,WAAW,CAAC,KAAK,CAAA;KACzB;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE;QACxB,OAAO,WAAW,CAAC,QAAQ,CAAA;KAC5B;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC;AApBD,kDAoBC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\n\nexport function parseUserProfile(\n data: unknown,\n): MiscTypes.UserProfile | undefined {\n if (typeof data !== 'object' || !data) {\n return\n }\n const jwtPayload = data as Record<string, unknown>\n if (typeof jwtPayload.sub !== 'string') {\n return\n }\n const userProfile: MiscTypes.UserProfile = {\n isSAMLUser: false,\n providerType: 'Cognito',\n providerUserId: jwtPayload.sub,\n userId: jwtPayload.sub,\n email: typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,\n firstName:\n typeof jwtPayload.given_name === 'string'\n ? jwtPayload.given_name\n : undefined,\n lastName:\n typeof jwtPayload.family_name === 'string'\n ? jwtPayload.family_name\n : undefined,\n fullName: typeof jwtPayload.name === 'string' ? jwtPayload.name : undefined,\n picture:\n typeof jwtPayload.picture === 'string' ? jwtPayload.picture : undefined,\n role:\n typeof jwtPayload['custom:role'] === 'string'\n ? jwtPayload['custom:role']\n : undefined,\n username:\n typeof jwtPayload.email === 'string' ? jwtPayload.email : undefined,\n supervisor: {\n fullName:\n typeof jwtPayload['custom:supervisor_name'] === 'string'\n ? jwtPayload['custom:supervisor_name']\n : undefined,\n email:\n typeof jwtPayload['custom:supervisor_email'] === 'string'\n ? jwtPayload['custom:supervisor_email']\n : undefined,\n providerUserId:\n typeof jwtPayload['custom:supervisor_user_id'] === 'string'\n ? jwtPayload['custom:supervisor_user_id']\n : undefined,\n },\n }\n\n if (\n !userProfile.supervisor?.fullName &&\n !userProfile.supervisor?.email &&\n !userProfile.supervisor?.providerUserId\n ) {\n userProfile.supervisor = undefined\n }\n\n if (\n jwtPayload.identities &&\n Array.isArray(jwtPayload.identities) &&\n jwtPayload.identities.length\n ) {\n const { providerType, userId } = jwtPayload.identities[0]\n userProfile.providerType = providerType\n userProfile.providerUserId = userId\n userProfile.isSAMLUser = providerType === 'SAML'\n if (userProfile.isSAMLUser) {\n userProfile.username = jwtPayload.preferred_username || userId\n }\n }\n\n return userProfile\n}\n\nexport function getUserFriendlyName(\n userProfile: MiscTypes.UserProfile,\n): string {\n if (userProfile.fullName) {\n return userProfile.fullName\n }\n\n if (userProfile.firstName || userProfile.lastName) {\n return [userProfile.firstName, userProfile.lastName].join(' ').trim()\n }\n\n if (userProfile.email) {\n return userProfile.email\n }\n\n if (userProfile.username) {\n return userProfile.username\n }\n\n return userProfile.userId\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneblink/sdk-core",
|
|
3
3
|
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
|
|
4
|
-
"version": "0.1.1",
|
|
4
|
+
"version": "0.1.3-beta.1",
|
|
5
5
|
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/oneblink/sdk-core-js/issues"
|