@internetderdinge/api 1.229.4 → 1.229.7

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.
@@ -86,6 +86,7 @@ export const getAuth0Token = async () => {
86
86
  // if (process.env.NODE_ENV !== 'production') {
87
87
  const fileToken = await loadTokenFromFile(TOKEN_FILE_PATH);
88
88
  if (fileToken && fileToken.expiresAt > now + TOKEN_BUFFER_SECONDS) {
89
+ console.warn("Auth0 Client: Using token from file cache");
89
90
  cachedToken = fileToken.token;
90
91
  tokenExpiresAt = fileToken.expiresAt;
91
92
  pendingTokenPromise = null;
@@ -93,8 +94,8 @@ export const getAuth0Token = async () => {
93
94
  }
94
95
  console.warn("Auth0 Client: Requesting new token from Auth0");
95
96
  const tokenResponse = await auth0AuthClient.oauth.clientCredentialsGrant(grantOpts);
96
- const expiresIn = tokenResponse.expires_in || 3600;
97
- cachedToken = tokenResponse.access_token;
97
+ const expiresIn = tokenResponse.data.expires_in || 3600;
98
+ cachedToken = tokenResponse.data.access_token;
98
99
  tokenExpiresAt = now + expiresIn;
99
100
  // if (process.env.NODE_ENV !== 'production') {
100
101
  await writeTokenFile(TOKEN_FILE_PATH, cachedToken, tokenExpiresAt);
@@ -91,6 +91,8 @@ export const getEvents = async (params) => {
91
91
  */
92
92
  export const activateDevice = async (deviceId, organization, enable = true, resetDevice = false) => {
93
93
  const accessToken = await getAuth0Token();
94
+ console.log(`Activating device ${deviceId} for organization ${organization} with enable=${enable} and resetDevice=${resetDevice}`);
95
+ console.log(`Using access token: ${accessToken ? "Yes" : "No"}`);
94
96
  try {
95
97
  const data = {
96
98
  deviceName: deviceId,
@@ -104,9 +104,7 @@ export const getUserByOwner = async (owner, organization) => {
104
104
  const user = await User.findOne({ owner, organization });
105
105
  if (!user)
106
106
  return null;
107
- console.log("Found user for owner and organization:", owner, organization, user);
108
107
  const auth0User = await populateAuth0User(user);
109
- console.log("Found user for owner and organizationddddddd:", owner, organization, user);
110
108
  const json = user.toJSON();
111
109
  json.auth0User = auth0User;
112
110
  return json;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@internetderdinge/api",
3
- "version": "1.229.4",
3
+ "version": "1.229.7",
4
4
  "description": "Shared OpenIoT API modules",
5
5
  "main": "dist/src/index.js",
6
6
  "type": "module",
@@ -119,6 +119,7 @@ export const getAuth0Token = async (): Promise<string> => {
119
119
  // if (process.env.NODE_ENV !== 'production') {
120
120
  const fileToken = await loadTokenFromFile(TOKEN_FILE_PATH);
121
121
  if (fileToken && fileToken.expiresAt > now + TOKEN_BUFFER_SECONDS) {
122
+ console.warn("Auth0 Client: Using token from file cache");
122
123
  cachedToken = fileToken.token;
123
124
  tokenExpiresAt = fileToken.expiresAt;
124
125
  pendingTokenPromise = null;
@@ -128,8 +129,8 @@ export const getAuth0Token = async (): Promise<string> => {
128
129
  console.warn("Auth0 Client: Requesting new token from Auth0");
129
130
  const tokenResponse =
130
131
  await auth0AuthClient.oauth.clientCredentialsGrant(grantOpts);
131
- const expiresIn = tokenResponse.expires_in || 3600;
132
- cachedToken = tokenResponse.access_token;
132
+ const expiresIn = tokenResponse.data.expires_in || 3600;
133
+ cachedToken = tokenResponse.data.access_token;
133
134
  tokenExpiresAt = now + expiresIn;
134
135
 
135
136
  // if (process.env.NODE_ENV !== 'production') {
@@ -149,6 +149,11 @@ export const activateDevice = async (
149
149
  ): Promise<any> => {
150
150
  const accessToken = await getAuth0Token();
151
151
 
152
+ console.log(
153
+ `Activating device ${deviceId} for organization ${organization} with enable=${enable} and resetDevice=${resetDevice}`,
154
+ );
155
+ console.log(`Using access token: ${accessToken ? "Yes" : "No"}`);
156
+
152
157
  try {
153
158
  const data = {
154
159
  deviceName: deviceId,
@@ -150,20 +150,8 @@ export const getUserByOwner = async (
150
150
  const user = await User.findOne({ owner, organization });
151
151
  if (!user) return null;
152
152
 
153
- console.log(
154
- "Found user for owner and organization:",
155
- owner,
156
- organization,
157
- user,
158
- );
159
153
  const auth0User = await populateAuth0User(user);
160
154
 
161
- console.log(
162
- "Found user for owner and organizationddddddd:",
163
- owner,
164
- organization,
165
- user,
166
- );
167
155
  const json = user.toJSON();
168
156
  json.auth0User = auth0User;
169
157
  return json;