sfc-utils 1.4.211 → 1.4.212

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.
Files changed (2) hide show
  1. package/copy/googleauth.js +36 -8
  2. package/package.json +1 -1
@@ -11,6 +11,34 @@ var serviceAccountCreds = path.join(
11
11
  os.homedir(),
12
12
  "service-account-google-creds.json"
13
13
  );
14
+ var authRetryDelayMs = 10000;
15
+ var authRetryCount = 3;
16
+
17
+ var wait = function (ms) {
18
+ return new Promise((resolve) => setTimeout(resolve, ms));
19
+ };
20
+
21
+ var authorizeWithRetry = async function (jwtClient) {
22
+ for (var attempt = 1; attempt <= authRetryCount + 1; attempt++) {
23
+ try {
24
+ return await jwtClient.authorize();
25
+ } catch (err) {
26
+ console.log(
27
+ `GOOGLEAUTH: jwtClient.authorize() attempt ${attempt} failed:`,
28
+ err.message || err
29
+ );
30
+
31
+ if (attempt > authRetryCount) {
32
+ throw err;
33
+ }
34
+
35
+ console.log(
36
+ `GOOGLEAUTH: Waiting ${authRetryDelayMs / 1000} seconds before retrying service account authentication...`
37
+ );
38
+ await wait(authRetryDelayMs);
39
+ }
40
+ }
41
+ };
14
42
 
15
43
  var authenticate = function () {
16
44
  console.log("\n========== GOOGLEAUTH: authenticate() called ==========");
@@ -48,12 +76,8 @@ var authenticate = function () {
48
76
  console.log("GOOGLEAUTH: JWT client created, authorizing...");
49
77
 
50
78
  //authenticate request
51
- jwtClient.authorize(function (err, tokens) {
52
- if (err) {
53
- console.log("GOOGLEAUTH: Stage 1 error during jwtClient.authorize()");
54
- console.log("GOOGLEAUTH: Error details:", err.message || err);
55
- reject(err);
56
- } else {
79
+ authorizeWithRetry(jwtClient)
80
+ .then((tokens) => {
57
81
  console.log("Successfully connected to service account!");
58
82
  console.log(
59
83
  "GOOGLEAUTH: Token type:",
@@ -65,8 +89,12 @@ var authenticate = function () {
65
89
  );
66
90
  // Return the jwtClient as auth
67
91
  resolve(jwtClient);
68
- }
69
- });
92
+ })
93
+ .catch((err) => {
94
+ console.log("GOOGLEAUTH: Stage 1 error during jwtClient.authorize()");
95
+ console.log("GOOGLEAUTH: Error details:", err.message || err);
96
+ reject(err);
97
+ });
70
98
  } catch (err) {
71
99
  console.log("GOOGLEAUTH: Stage 2 error (catch block)");
72
100
  console.log("GOOGLEAUTH: Error details:", err.message || err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfc-utils",
3
- "version": "1.4.211",
3
+ "version": "1.4.212",
4
4
  "author": "ewagstaff <evanjwagstaff@gmail.com>",
5
5
  "dependencies": {
6
6
  "archieml": "^0.4.2",