@commercengine/pos 0.3.0 → 0.3.2

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
@@ -443,18 +443,16 @@ function extractUserInfoFromToken(token) {
443
443
  isLoggedIn: payload.is_logged_in,
444
444
  customerId: payload.customer_id,
445
445
  customerGroupId: payload.customer_group_id,
446
- device: {
447
- deviceId: payload.device.device_id,
448
- deviceName: payload.device.device_name
449
- },
446
+ roles: payload.roles.map((role) => ({
447
+ roleId: role.role_id,
448
+ roleName: role.role_name,
449
+ locationId: role.location_id,
450
+ locationName: role.location_name
451
+ })),
450
452
  location: {
451
453
  id: payload.location.id,
452
454
  name: payload.location.name
453
455
  },
454
- role: {
455
- id: payload.role.id,
456
- name: payload.role.name
457
- },
458
456
  tenantId: payload.tenant_id,
459
457
  channel: {
460
458
  id: payload.channel.id,
@@ -521,16 +519,6 @@ function isUserAuthenticated(token) {
521
519
  return !!userInfo?.isLoggedIn;
522
520
  }
523
521
  /**
524
- * Get the device ID from a POS JWT token
525
- *
526
- * @param token - The JWT token
527
- * @returns Device ID or null if token is invalid
528
- */
529
- function getDeviceIdFromToken(token) {
530
- const userInfo = extractUserInfoFromToken(token);
531
- return userInfo?.device?.deviceId || null;
532
- }
533
- /**
534
522
  * Get the location ID from a POS JWT token
535
523
  *
536
524
  * @param token - The JWT token
@@ -541,14 +529,16 @@ function getLocationIdFromToken(token) {
541
529
  return userInfo?.location?.id || null;
542
530
  }
543
531
  /**
544
- * Get the role information from a POS JWT token
532
+ * Get the role information from a POS JWT token for the current location
545
533
  *
546
534
  * @param token - The JWT token
547
- * @returns Role object with id and name, or null if token is invalid
535
+ * @returns Role object for the current location, or null if token is invalid
548
536
  */
549
537
  function getRoleFromToken(token) {
550
538
  const userInfo = extractUserInfoFromToken(token);
551
- return userInfo?.role || null;
539
+ if (!userInfo?.roles || userInfo.roles.length === 0) return null;
540
+ const currentLocationRole = userInfo.roles.find((role) => role.locationId === userInfo.location.id);
541
+ return currentLocationRole || userInfo.roles[0] || null;
552
542
  }
553
543
  /**
554
544
  * Get the tenant ID from a POS JWT token
@@ -1133,6 +1123,26 @@ var PosClient = class extends PosAPIClient {
1133
1123
  return this.executeRequest(() => this.client.POST("/pos/auth/refresh-token", { body }));
1134
1124
  }
1135
1125
  /**
1126
+ * Get POS user details
1127
+ * @param pathParams - User ID
1128
+ * @returns Promise with user details
1129
+ * @example
1130
+ * ```typescript
1131
+ * const { data, error } = await pos.getUser({
1132
+ * id: "01H9USER12345ABCDE"
1133
+ * });
1134
+ *
1135
+ * if (error) {
1136
+ * console.error("Failed to get user:", error.message);
1137
+ * } else {
1138
+ * console.log("User:", data.user);
1139
+ * }
1140
+ * ```
1141
+ */
1142
+ async getUser(pathParams) {
1143
+ return this.executeRequest(() => this.client.GET("/pos/users/{id}", { params: { path: pathParams } }));
1144
+ }
1145
+ /**
1136
1146
  * Logout
1137
1147
  * @returns Promise with logout confirmation
1138
1148
  * @example
@@ -2988,17 +2998,6 @@ var PosSDK = class {
2988
2998
  return isUserAuthenticated(token);
2989
2999
  }
2990
3000
  /**
2991
- * Get the device ID from the current access token
2992
- * This is commonly needed for POS API requests
2993
- *
2994
- * @returns Device ID or null if no token or invalid token
2995
- */
2996
- async getDeviceId() {
2997
- const token = await this.getAccessToken();
2998
- if (!token) return null;
2999
- return getDeviceIdFromToken(token);
3000
- }
3001
- /**
3002
3001
  * Get the location ID from the current access token
3003
3002
  * This is commonly needed for POS API requests
3004
3003
  *
@@ -3012,7 +3011,7 @@ var PosSDK = class {
3012
3011
  /**
3013
3012
  * Get the role information from the current access token
3014
3013
  *
3015
- * @returns Role object with id and name, or null if no token or invalid token
3014
+ * @returns Role object with roleId, roleName, locationId, and locationName, or null if no token or invalid token
3016
3015
  */
3017
3016
  async getRole() {
3018
3017
  const token = await this.getAccessToken();