@oneblink/sdk-core 8.1.0 → 8.2.0-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.
@@ -41,11 +41,15 @@ function parseUserProfile(data) {
41
41
  firstName: typeof jwtPayload.given_name === 'string'
42
42
  ? jwtPayload.given_name
43
43
  : undefined,
44
+ middleName: typeof jwtPayload.middle_name === 'string'
45
+ ? jwtPayload.middle_name
46
+ : undefined,
44
47
  lastName: typeof jwtPayload.family_name === 'string'
45
48
  ? jwtPayload.family_name
46
49
  : undefined,
47
50
  fullName: typeof jwtPayload.name === 'string' ? jwtPayload.name : undefined,
48
51
  picture: typeof jwtPayload.picture === 'string' ? jwtPayload.picture : undefined,
52
+ address: typeof jwtPayload.address === 'string' ? jwtPayload.address : undefined,
49
53
  role: typeof jwtPayload['custom:role'] === 'string'
50
54
  ? jwtPayload['custom:role']
51
55
  : undefined,
@@ -70,6 +74,39 @@ function parseUserProfile(data) {
70
74
  groups: typeof jwtPayload['custom:groups'] === 'string'
71
75
  ? jwtPayload['custom:groups'].split(',').map((group) => group.trim())
72
76
  : undefined,
77
+ areaCode: typeof jwtPayload['custom:area_code'] === 'string'
78
+ ? jwtPayload['custom:area_code']
79
+ : undefined,
80
+ city: typeof jwtPayload['custom:city'] === 'string'
81
+ ? jwtPayload['custom:city']
82
+ : undefined,
83
+ state: typeof jwtPayload['custom:state'] === 'string'
84
+ ? jwtPayload['custom:state']
85
+ : undefined,
86
+ country: typeof jwtPayload['custom:country'] === 'string'
87
+ ? jwtPayload['custom:country']
88
+ : undefined,
89
+ countryCallingCode: typeof jwtPayload['custom:country_calling_code'] === 'string'
90
+ ? jwtPayload['custom:country_calling_code']
91
+ : undefined,
92
+ department: typeof jwtPayload['custom:department'] === 'string'
93
+ ? jwtPayload['custom:department']
94
+ : undefined,
95
+ division: typeof jwtPayload['custom:division'] === 'string'
96
+ ? jwtPayload['custom:division']
97
+ : undefined,
98
+ bargain: typeof jwtPayload['custom:bargain'] === 'string'
99
+ ? jwtPayload['custom:bargain']
100
+ : undefined,
101
+ employeeNumber: typeof jwtPayload['custom:employee_number'] === 'string'
102
+ ? jwtPayload['custom:employee_number']
103
+ : undefined,
104
+ departmentHeadFullName: typeof jwtPayload['custom:departmenthead_name'] === 'string'
105
+ ? jwtPayload['custom:departmenthead_name']
106
+ : undefined,
107
+ departmentHeadEmail: typeof jwtPayload['custom:departmenthead_email'] === 'string'
108
+ ? jwtPayload['custom:departmenthead_email']
109
+ : undefined,
73
110
  };
74
111
  if (!((_a = userProfile.supervisor) === null || _a === void 0 ? void 0 : _a.fullName) &&
75
112
  !((_b = userProfile.supervisor) === null || _b === void 0 ? void 0 : _b.email) &&
@@ -1 +1 @@
1
- {"version":3,"file":"userService.js","sourceRoot":"","sources":["../src/userService.ts"],"names":[],"mappings":";;AAoBA,4CAwFC;AAmBD,kDAoBC;AAjJD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAC9B,IAAa;;IAEb,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACtC,OAAM;IACR,CAAC;IACD,MAAM,UAAU,GAAG,IAA+B,CAAA;IAClD,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAM;IACR,CAAC;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,aAAa,EACX,OAAO,UAAU,CAAC,cAAc,KAAK,SAAS;YAC5C,CAAC,CAAC,UAAU,CAAC,cAAc;YAC3B,CAAC,CAAC,SAAS;QACf,SAAS,EACP,OAA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B,CACjC,WAAkC;IAElC,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,QAAQ,CAAA;IAC7B,CAAC;IAED,IAAI,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QAClD,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACvE,CAAC;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC,KAAK,CAAA;IAC1B,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,QAAQ,CAAA;IAC7B,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\n\n/**\n * Parse a User Profile based on a JWT payload. Will return `undefined` if not a\n * valid JWT payload\n *\n * #### Example\n *\n * ```js\n * import jwtDecode from 'jwt-decode'\n *\n * const jwtPayload = jwtDecode('a valid token from a user')\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * if (userProfile) {\n * // continue\n * }\n * ```\n *\n * @param data An object containing all parameters to be passed to the function\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 emailVerified:\n typeof jwtPayload.email_verified === 'boolean'\n ? jwtPayload.email_verified\n : 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 : jwtPayload.sub,\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 phoneNumber:\n typeof jwtPayload['custom:phone_number'] === 'string'\n ? jwtPayload['custom:phone_number']\n : undefined,\n phoneNumberVerified:\n typeof jwtPayload['custom:phone_number_verified'] === 'boolean'\n ? jwtPayload['custom:phone_number_verified']\n : undefined,\n groups:\n typeof jwtPayload['custom:groups'] === 'string'\n ? jwtPayload['custom:groups'].split(',').map((group) => group.trim())\n : undefined,\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\n/**\n * A friendly `string` that represents the a [User Profile](#user-profile). Uses\n * first name, last name, full name, email address or username.\n *\n * #### Example\n *\n * ```js\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * const name = userService.getUserFriendlyName(userProfile)\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @param userProfile\n * @returns\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"]}
1
+ {"version":3,"file":"userService.js","sourceRoot":"","sources":["../src/userService.ts"],"names":[],"mappings":";;AAoBA,4CA0IC;AAmBD,kDAoBC;AAnMD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAC9B,IAAa;;IAEb,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACtC,OAAM;IACR,CAAC;IACD,MAAM,UAAU,GAAG,IAA+B,CAAA;IAClD,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAM;IACR,CAAC;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,aAAa,EACX,OAAO,UAAU,CAAC,cAAc,KAAK,SAAS;YAC5C,CAAC,CAAC,UAAU,CAAC,cAAc;YAC3B,CAAC,CAAC,SAAS;QACf,SAAS,EACP,OAAO,UAAU,CAAC,UAAU,KAAK,QAAQ;YACvC,CAAC,CAAC,UAAU,CAAC,UAAU;YACvB,CAAC,CAAC,SAAS;QACf,UAAU,EACR,OAAO,UAAU,CAAC,WAAW,KAAK,QAAQ;YACxC,CAAC,CAAC,UAAU,CAAC,WAAW;YACxB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CAAC,UAAU,GAAG,YAAY,KAAK,MAAM,CAAA;QAChD,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;YAC3B,WAAW,CAAC,QAAQ,GAAG,UAAU,CAAC,kBAAkB,IAAI,MAAM,CAAA;QAChE,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,mBAAmB,CACjC,WAAkC;IAElC,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,QAAQ,CAAA;IAC7B,CAAC;IAED,IAAI,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QAClD,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;IACvE,CAAC;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC,KAAK,CAAA;IAC1B,CAAC;IAED,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,WAAW,CAAC,QAAQ,CAAA;IAC7B,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC","sourcesContent":["import { MiscTypes } from '@oneblink/types'\n\n/**\n * Parse a User Profile based on a JWT payload. Will return `undefined` if not a\n * valid JWT payload\n *\n * #### Example\n *\n * ```js\n * import jwtDecode from 'jwt-decode'\n *\n * const jwtPayload = jwtDecode('a valid token from a user')\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * if (userProfile) {\n * // continue\n * }\n * ```\n *\n * @param data An object containing all parameters to be passed to the function\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 emailVerified:\n typeof jwtPayload.email_verified === 'boolean'\n ? jwtPayload.email_verified\n : undefined,\n firstName:\n typeof jwtPayload.given_name === 'string'\n ? jwtPayload.given_name\n : undefined,\n middleName:\n typeof jwtPayload.middle_name === 'string'\n ? jwtPayload.middle_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 address:\n typeof jwtPayload.address === 'string' ? jwtPayload.address : undefined,\n role:\n typeof jwtPayload['custom:role'] === 'string'\n ? jwtPayload['custom:role']\n : undefined,\n username:\n typeof jwtPayload.email === 'string' ? jwtPayload.email : jwtPayload.sub,\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 phoneNumber:\n typeof jwtPayload['custom:phone_number'] === 'string'\n ? jwtPayload['custom:phone_number']\n : undefined,\n phoneNumberVerified:\n typeof jwtPayload['custom:phone_number_verified'] === 'boolean'\n ? jwtPayload['custom:phone_number_verified']\n : undefined,\n groups:\n typeof jwtPayload['custom:groups'] === 'string'\n ? jwtPayload['custom:groups'].split(',').map((group) => group.trim())\n : undefined,\n areaCode:\n typeof jwtPayload['custom:area_code'] === 'string'\n ? jwtPayload['custom:area_code']\n : undefined,\n city:\n typeof jwtPayload['custom:city'] === 'string'\n ? jwtPayload['custom:city']\n : undefined,\n state:\n typeof jwtPayload['custom:state'] === 'string'\n ? jwtPayload['custom:state']\n : undefined,\n country:\n typeof jwtPayload['custom:country'] === 'string'\n ? jwtPayload['custom:country']\n : undefined,\n countryCallingCode:\n typeof jwtPayload['custom:country_calling_code'] === 'string'\n ? jwtPayload['custom:country_calling_code']\n : undefined,\n department:\n typeof jwtPayload['custom:department'] === 'string'\n ? jwtPayload['custom:department']\n : undefined,\n division:\n typeof jwtPayload['custom:division'] === 'string'\n ? jwtPayload['custom:division']\n : undefined,\n bargain:\n typeof jwtPayload['custom:bargain'] === 'string'\n ? jwtPayload['custom:bargain']\n : undefined,\n employeeNumber:\n typeof jwtPayload['custom:employee_number'] === 'string'\n ? jwtPayload['custom:employee_number']\n : undefined,\n departmentHeadFullName:\n typeof jwtPayload['custom:departmenthead_name'] === 'string'\n ? jwtPayload['custom:departmenthead_name']\n : undefined,\n departmentHeadEmail:\n typeof jwtPayload['custom:departmenthead_email'] === 'string'\n ? jwtPayload['custom:departmenthead_email']\n : undefined,\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\n/**\n * A friendly `string` that represents the a [User Profile](#user-profile). Uses\n * first name, last name, full name, email address or username.\n *\n * #### Example\n *\n * ```js\n * const userProfile = userService.parseUserProfile(jwtPayload)\n * const name = userService.getUserFriendlyName(userProfile)\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @param userProfile\n * @returns\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": "8.1.0",
4
+ "version": "8.2.0-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"