@zapier/zapier-sdk 0.40.3 → 0.40.4

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.
@@ -2,7 +2,15 @@
2
2
  * Simple utility functions for event emission
3
3
  * These are pure functions that can be used to populate common event fields
4
4
  */
5
- import * as os from "os";
5
+ // Intentional dynamic require for browser compatibility. The os module is only
6
+ // available in Node; in browser environments this gracefully falls back to nulls.
7
+ let osModule = null;
8
+ try {
9
+ osModule = require("os");
10
+ }
11
+ catch {
12
+ osModule = null;
13
+ }
6
14
  /**
7
15
  * Generate a unique event ID
8
16
  */
@@ -19,26 +27,24 @@ export function getCurrentTimestamp() {
19
27
  * Get release ID (git SHA) - in production this would come from build process
20
28
  */
21
29
  export function getReleaseId() {
22
- return process?.env?.SDK_RELEASE_ID || "development";
30
+ return globalThis.process?.env?.SDK_RELEASE_ID || "development";
23
31
  }
24
32
  /**
25
33
  * Get operating system information
26
34
  */
27
35
  export function getOsInfo() {
36
+ if (!osModule) {
37
+ return { platform: null, release: null, architecture: null };
38
+ }
28
39
  try {
29
40
  return {
30
- platform: os.platform() || null,
31
- release: os.release() || null,
32
- architecture: os.arch() || null,
41
+ platform: osModule.platform() || null,
42
+ release: osModule.release() || null,
43
+ architecture: osModule.arch() || null,
33
44
  };
34
45
  }
35
46
  catch {
36
- // Browser environment - os module not available
37
- return {
38
- platform: null,
39
- release: null,
40
- architecture: null,
41
- };
47
+ return { platform: null, release: null, architecture: null };
42
48
  }
43
49
  }
44
50
  /**
@@ -46,8 +52,8 @@ export function getOsInfo() {
46
52
  */
47
53
  export function getPlatformVersions() {
48
54
  const versions = {};
49
- if (typeof process?.versions === "object") {
50
- for (const [key, value] of Object.entries(process.versions)) {
55
+ if (typeof globalThis.process?.versions === "object") {
56
+ for (const [key, value] of Object.entries(globalThis.process.versions)) {
51
57
  versions[key] = value || null;
52
58
  }
53
59
  }
@@ -57,38 +63,39 @@ export function getPlatformVersions() {
57
63
  * Check if running in CI environment
58
64
  */
59
65
  export function isCi() {
60
- return !!(process?.env?.CI ||
61
- process?.env?.CONTINUOUS_INTEGRATION ||
62
- process?.env?.GITHUB_ACTIONS ||
63
- process?.env?.JENKINS_URL ||
64
- process?.env?.GITLAB_CI ||
65
- process?.env?.CIRCLECI ||
66
- process?.env?.TRAVIS ||
67
- process?.env?.BUILDKITE ||
68
- process?.env?.DRONE ||
69
- process?.env?.BITBUCKET_PIPELINES_UUID);
66
+ return !!(globalThis.process?.env?.CI ||
67
+ globalThis.process?.env?.CONTINUOUS_INTEGRATION ||
68
+ globalThis.process?.env?.GITHUB_ACTIONS ||
69
+ globalThis.process?.env?.JENKINS_URL ||
70
+ globalThis.process?.env?.GITLAB_CI ||
71
+ globalThis.process?.env?.CIRCLECI ||
72
+ globalThis.process?.env?.TRAVIS ||
73
+ globalThis.process?.env?.BUILDKITE ||
74
+ globalThis.process?.env?.DRONE ||
75
+ globalThis.process?.env?.BITBUCKET_PIPELINES_UUID);
70
76
  }
71
77
  /**
72
78
  * Get CI platform name if running in CI
73
79
  */
74
80
  export function getCiPlatform() {
75
- if (process?.env?.GITHUB_ACTIONS)
81
+ if (globalThis.process?.env?.GITHUB_ACTIONS)
76
82
  return "github-actions";
77
- if (process?.env?.JENKINS_URL)
83
+ if (globalThis.process?.env?.JENKINS_URL)
78
84
  return "jenkins";
79
- if (process?.env?.GITLAB_CI)
85
+ if (globalThis.process?.env?.GITLAB_CI)
80
86
  return "gitlab-ci";
81
- if (process?.env?.CIRCLECI)
87
+ if (globalThis.process?.env?.CIRCLECI)
82
88
  return "circleci";
83
- if (process?.env?.TRAVIS)
89
+ if (globalThis.process?.env?.TRAVIS)
84
90
  return "travis";
85
- if (process?.env?.BUILDKITE)
91
+ if (globalThis.process?.env?.BUILDKITE)
86
92
  return "buildkite";
87
- if (process?.env?.DRONE)
93
+ if (globalThis.process?.env?.DRONE)
88
94
  return "drone";
89
- if (process?.env?.BITBUCKET_PIPELINES_UUID)
95
+ if (globalThis.process?.env?.BITBUCKET_PIPELINES_UUID)
90
96
  return "bitbucket-pipelines";
91
- if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
97
+ if (globalThis.process?.env?.CI ||
98
+ globalThis.process?.env?.CONTINUOUS_INTEGRATION)
92
99
  return "unknown-ci";
93
100
  return null;
94
101
  }
@@ -96,8 +103,8 @@ export function getCiPlatform() {
96
103
  * Get memory usage in bytes
97
104
  */
98
105
  export function getMemoryUsage() {
99
- if (process?.memoryUsage) {
100
- const usage = process.memoryUsage();
106
+ if (globalThis.process?.memoryUsage) {
107
+ const usage = globalThis.process.memoryUsage();
101
108
  return usage.rss || null; // Resident Set Size
102
109
  }
103
110
  return null;
@@ -106,8 +113,8 @@ export function getMemoryUsage() {
106
113
  * Get CPU time in milliseconds
107
114
  */
108
115
  export function getCpuTime() {
109
- if (process?.cpuUsage) {
110
- const usage = process.cpuUsage();
116
+ if (globalThis.process?.cpuUsage) {
117
+ const usage = globalThis.process.cpuUsage();
111
118
  return Math.round((usage.user + usage.system) / 1000); // Convert to milliseconds
112
119
  }
113
120
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"batch-utils.d.ts","sourceRoot":"","sources":["../../src/utils/batch-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAwBH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAC3B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,CAuIpC"}
1
+ {"version":3,"file":"batch-utils.d.ts","sourceRoot":"","sources":["../../src/utils/batch-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA2BH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,KAAK,EAAE,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,EAC3B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,CAuIpC"}
@@ -4,8 +4,7 @@
4
4
  * This module provides utilities for executing multiple async operations
5
5
  * with concurrency control and retry logic.
6
6
  */
7
- import { setTimeout } from "timers/promises";
8
- import { calculateErrorBackoffMs, MAX_CONSECUTIVE_ERRORS } from "./retry-utils";
7
+ import { sleep, calculateErrorBackoffMs, MAX_CONSECUTIVE_ERRORS, } from "./retry-utils";
9
8
  import { ZapierTimeoutError } from "../types/errors";
10
9
  /**
11
10
  * Default number of concurrent operations
@@ -88,7 +87,7 @@ export async function batch(tasks, options = {}) {
88
87
  let result;
89
88
  // Apply per-task timeout if specified
90
89
  if (taskTimeoutMs !== undefined) {
91
- const timeoutPromise = setTimeout(taskTimeoutMs).then(() => {
90
+ const timeoutPromise = sleep(taskTimeoutMs).then(() => {
92
91
  throw new ZapierTimeoutError(`Task timed out after ${taskTimeoutMs}ms`);
93
92
  });
94
93
  result = await Promise.race([task(), timeoutPromise]);
@@ -106,7 +105,7 @@ export async function batch(tasks, options = {}) {
106
105
  if (retry && !isTimeout && newErrorCount < MAX_CONSECUTIVE_ERRORS) {
107
106
  // Calculate backoff delay (base 1000ms with jitter and error scaling)
108
107
  const waitTime = calculateErrorBackoffMs(1000, newErrorCount);
109
- await setTimeout(waitTime);
108
+ await sleep(waitTime);
110
109
  // Re-queue the task with incremented error count
111
110
  taskQueue.push({
112
111
  index,
@@ -138,7 +137,7 @@ export async function batch(tasks, options = {}) {
138
137
  // Small delay to prevent burst patterns within a worker
139
138
  // Only delay if there are more tasks to process
140
139
  if (taskQueue.length > 0 && batchDelay > 0) {
141
- await setTimeout(batchDelay);
140
+ await sleep(batchDelay);
142
141
  }
143
142
  }
144
143
  }
@@ -153,7 +152,7 @@ export async function batch(tasks, options = {}) {
153
152
  // Add small delay between starting workers to stagger the initial requests
154
153
  // Skip delay for last worker
155
154
  if (i < workerCount - 1 && batchDelay > 0) {
156
- await setTimeout(batchDelay / 10); // 10ms between worker starts
155
+ await sleep(batchDelay / 10); // 10ms between worker starts
157
156
  }
158
157
  }
159
158
  // Wait for all workers to complete
@@ -43,8 +43,8 @@ export function getTrackingBaseUrl({ trackingBaseUrl, baseUrl, }) {
43
43
  return trackingBaseUrl;
44
44
  }
45
45
  // 2. Environment variable override
46
- if (process.env.ZAPIER_TRACKING_BASE_URL) {
47
- return process.env.ZAPIER_TRACKING_BASE_URL;
46
+ if (globalThis.process?.env?.ZAPIER_TRACKING_BASE_URL) {
47
+ return globalThis.process?.env?.ZAPIER_TRACKING_BASE_URL;
48
48
  }
49
49
  // 3. Try to derive from baseUrl if it's a Zapier domain
50
50
  if (baseUrl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zapier/zapier-sdk",
3
- "version": "0.40.3",
3
+ "version": "0.40.4",
4
4
  "description": "Complete Zapier SDK - combines all Zapier SDK packages",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -40,6 +40,10 @@
40
40
  }
41
41
  }
42
42
  },
43
+ "browser": {
44
+ "@zapier/zapier-sdk-cli/login": false,
45
+ "@zapier/zapier-sdk-cli-login": false
46
+ },
43
47
  "files": [
44
48
  "dist",
45
49
  "README.md",
@@ -72,7 +76,7 @@
72
76
  "@types/node": "^24.0.1",
73
77
  "tsup": "^8.5.0",
74
78
  "typescript": "^5.8.3",
75
- "vitest": "^3.2.3",
79
+ "vitest": "^4.1.4",
76
80
  "@zapier/zapier-sdk-cli-login": "0.9.0"
77
81
  },
78
82
  "scripts": {