@zapier/zapier-sdk 0.13.3 → 0.13.5

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 (81) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/schemas.d.ts +174 -174
  3. package/dist/constants.d.ts +4 -0
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/constants.js +4 -0
  6. package/dist/index.cjs +457 -11
  7. package/dist/index.d.mts +389 -158
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/index.mjs +428 -15
  12. package/dist/plugins/api/index.d.ts +1 -3
  13. package/dist/plugins/api/index.d.ts.map +1 -1
  14. package/dist/plugins/eventEmission/builders.d.ts +13 -0
  15. package/dist/plugins/eventEmission/builders.d.ts.map +1 -0
  16. package/dist/plugins/eventEmission/builders.js +78 -0
  17. package/dist/plugins/eventEmission/index.d.ts +34 -0
  18. package/dist/plugins/eventEmission/index.d.ts.map +1 -0
  19. package/dist/plugins/eventEmission/index.js +216 -0
  20. package/dist/plugins/eventEmission/index.test.d.ts +5 -0
  21. package/dist/plugins/eventEmission/index.test.d.ts.map +1 -0
  22. package/dist/plugins/eventEmission/index.test.js +143 -0
  23. package/dist/plugins/eventEmission/transport.d.ts +37 -0
  24. package/dist/plugins/eventEmission/transport.d.ts.map +1 -0
  25. package/dist/plugins/eventEmission/transport.js +96 -0
  26. package/dist/plugins/eventEmission/transport.test.d.ts +5 -0
  27. package/dist/plugins/eventEmission/transport.test.d.ts.map +1 -0
  28. package/dist/plugins/eventEmission/transport.test.js +153 -0
  29. package/dist/plugins/eventEmission/types.d.ts +53 -0
  30. package/dist/plugins/eventEmission/types.d.ts.map +1 -0
  31. package/dist/plugins/eventEmission/types.js +1 -0
  32. package/dist/plugins/eventEmission/utils.d.ts +45 -0
  33. package/dist/plugins/eventEmission/utils.d.ts.map +1 -0
  34. package/dist/plugins/eventEmission/utils.js +114 -0
  35. package/dist/plugins/fetch/schemas.d.ts +4 -4
  36. package/dist/plugins/getAction/schemas.d.ts +2 -2
  37. package/dist/plugins/listActions/index.test.js +3 -1
  38. package/dist/plugins/listActions/schemas.d.ts +2 -2
  39. package/dist/plugins/listAuthentications/index.test.js +3 -1
  40. package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
  41. package/dist/plugins/listInputFields/schemas.d.ts +2 -2
  42. package/dist/plugins/manifest/index.d.ts +9 -1
  43. package/dist/plugins/manifest/index.d.ts.map +1 -1
  44. package/dist/plugins/manifest/index.js +19 -7
  45. package/dist/plugins/manifest/index.test.js +4 -2
  46. package/dist/plugins/request/schemas.d.ts +4 -4
  47. package/dist/plugins/runAction/schemas.d.ts +2 -2
  48. package/dist/resolvers/actionType.d.ts.map +1 -1
  49. package/dist/resolvers/actionType.js +2 -3
  50. package/dist/resolvers/authenticationId.d.ts.map +1 -1
  51. package/dist/schemas/Action.d.ts +2 -2
  52. package/dist/schemas/App.d.ts +30 -30
  53. package/dist/sdk.d.ts +3 -3
  54. package/dist/sdk.d.ts.map +1 -1
  55. package/dist/sdk.js +4 -1
  56. package/dist/types/sdk.d.ts +5 -1
  57. package/dist/types/sdk.d.ts.map +1 -1
  58. package/dist/types/telemetry-events.d.ts +76 -0
  59. package/dist/types/telemetry-events.d.ts.map +1 -0
  60. package/dist/types/telemetry-events.js +8 -0
  61. package/package.json +1 -1
  62. package/src/constants.ts +6 -0
  63. package/src/index.ts +24 -0
  64. package/src/plugins/api/index.ts +1 -5
  65. package/src/plugins/eventEmission/builders.ts +115 -0
  66. package/src/plugins/eventEmission/index.test.ts +169 -0
  67. package/src/plugins/eventEmission/index.ts +294 -0
  68. package/src/plugins/eventEmission/transport.test.ts +214 -0
  69. package/src/plugins/eventEmission/transport.ts +135 -0
  70. package/src/plugins/eventEmission/types.ts +58 -0
  71. package/src/plugins/eventEmission/utils.ts +121 -0
  72. package/src/plugins/listActions/index.test.ts +3 -1
  73. package/src/plugins/listAuthentications/index.test.ts +3 -1
  74. package/src/plugins/manifest/index.test.ts +4 -4
  75. package/src/plugins/manifest/index.ts +39 -14
  76. package/src/resolvers/actionType.ts +4 -3
  77. package/src/resolvers/authenticationId.ts +2 -1
  78. package/src/sdk.ts +5 -1
  79. package/src/types/sdk.ts +7 -1
  80. package/src/types/telemetry-events.ts +85 -0
  81. package/tsconfig.tsbuildinfo +1 -1
@@ -7,4 +7,8 @@
7
7
  * Maximum number of items that can be requested per page across all paginated functions
8
8
  */
9
9
  export declare const MAX_PAGE_LIMIT = 10000;
10
+ /**
11
+ * Default telemetry endpoint for the Tracking API
12
+ */
13
+ export declare const TRACKING_API_ENDPOINT = "https://zapier.com/api/v4/tracking/event/";
10
14
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,eAAO,MAAM,cAAc,QAAQ,CAAC;AAEpC;;GAEG;AACH,eAAO,MAAM,qBAAqB,8CACW,CAAC"}
package/dist/constants.js CHANGED
@@ -7,3 +7,7 @@
7
7
  * Maximum number of items that can be requested per page across all paginated functions
8
8
  */
9
9
  export const MAX_PAGE_LIMIT = 10000;
10
+ /**
11
+ * Default telemetry endpoint for the Tracking API
12
+ */
13
+ export const TRACKING_API_ENDPOINT = "https://zapier.com/api/v4/tracking/event/";
package/dist/index.cjs CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  var zod = require('zod');
4
4
  var promises = require('timers/promises');
5
+ var os = require('os');
6
+
7
+ function _interopNamespace(e) {
8
+ if (e && e.__esModule) return e;
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
5
26
 
6
27
  // src/types/properties.ts
7
28
  function withFormatter(schema, formatMeta) {
@@ -34,6 +55,7 @@ function isPositional(schema) {
34
55
 
35
56
  // src/constants.ts
36
57
  var MAX_PAGE_LIMIT = 1e4;
58
+ var TRACKING_API_ENDPOINT = "https://zapier.com/api/v4/tracking/event/";
37
59
 
38
60
  // src/types/properties.ts
39
61
  var AppKeyPropertySchema = withPositional(
@@ -370,7 +392,7 @@ var FetchInitSchema = zod.z.object({
370
392
  // src/plugins/fetch/index.ts
371
393
  var fetchPlugin = ({ sdk }) => {
372
394
  return {
373
- fetch: async function fetch(url, init) {
395
+ fetch: async function fetch2(url, init) {
374
396
  const {
375
397
  authenticationId,
376
398
  callbackUrl,
@@ -1409,9 +1431,10 @@ var actionTypeResolver = {
1409
1431
  const actionsResponse = await sdk.listActions({
1410
1432
  appKey: resolvedParams.appKey
1411
1433
  });
1412
- const types = [
1413
- ...new Set(actionsResponse.data.map((action) => action.action_type))
1414
- ];
1434
+ const actionTypes = actionsResponse.data.map(
1435
+ (action) => action.action_type
1436
+ );
1437
+ const types = [...new Set(actionTypes)];
1415
1438
  return types.map((type) => ({ key: type, name: type }));
1416
1439
  },
1417
1440
  prompt: (types) => ({
@@ -2824,8 +2847,15 @@ var manifestPlugin = (params) => {
2824
2847
  if (!resolvedApp) return null;
2825
2848
  return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
2826
2849
  };
2827
- const updateManifestEntry = async (appKey, entry, configPath = DEFAULT_CONFIG_PATH) => {
2828
- const manifest2 = await readManifestFromFile(configPath) || { apps: {} };
2850
+ const updateManifestEntry = async (options2) => {
2851
+ const {
2852
+ appKey,
2853
+ entry,
2854
+ configPath = DEFAULT_CONFIG_PATH,
2855
+ skipWrite = false,
2856
+ manifest: inputManifest
2857
+ } = options2;
2858
+ const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
2829
2859
  let existingEntry = findManifestEntry({
2830
2860
  appKey,
2831
2861
  manifest: manifest2
@@ -2856,10 +2886,18 @@ var manifestPlugin = (params) => {
2856
2886
  api
2857
2887
  });
2858
2888
  }
2859
- manifest2.apps[manifestKey] = entry;
2860
- await writeManifestToFile(manifest2, configPath);
2861
- resolvedManifest = void 0;
2862
- return [manifestKey, entry];
2889
+ const updatedManifest = {
2890
+ ...manifest2,
2891
+ apps: {
2892
+ ...manifest2.apps,
2893
+ [manifestKey]: entry
2894
+ }
2895
+ };
2896
+ if (!skipWrite) {
2897
+ await writeManifestToFile(updatedManifest, configPath);
2898
+ resolvedManifest = void 0;
2899
+ }
2900
+ return [manifestKey, entry, updatedManifest];
2863
2901
  };
2864
2902
  return {
2865
2903
  context: {
@@ -3811,6 +3849,401 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
3811
3849
  };
3812
3850
  };
3813
3851
 
3852
+ // src/plugins/eventEmission/transport.ts
3853
+ var DEFAULT_RETRY_ATTEMPTS = 2;
3854
+ var DEFAULT_RETRY_DELAY_MS = 300;
3855
+ var HttpTransport = class {
3856
+ constructor(config) {
3857
+ this.config = config;
3858
+ }
3859
+ async emit(subject, event) {
3860
+ try {
3861
+ await this.emitWithRetry(
3862
+ subject,
3863
+ event,
3864
+ this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
3865
+ );
3866
+ } catch {
3867
+ }
3868
+ }
3869
+ async emitWithRetry(subject, event, attemptsLeft) {
3870
+ try {
3871
+ const payload = {
3872
+ subject,
3873
+ properties: event
3874
+ };
3875
+ const response = await fetch(this.config.endpoint, {
3876
+ method: "POST",
3877
+ headers: {
3878
+ "Content-Type": "application/json",
3879
+ ...this.config.headers
3880
+ },
3881
+ body: JSON.stringify(payload)
3882
+ });
3883
+ if (!response.ok && attemptsLeft > 1) {
3884
+ await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
3885
+ return this.emitWithRetry(subject, event, attemptsLeft - 1);
3886
+ }
3887
+ } catch (error) {
3888
+ if (attemptsLeft > 1) {
3889
+ await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
3890
+ return this.emitWithRetry(subject, event, attemptsLeft - 1);
3891
+ }
3892
+ throw error;
3893
+ }
3894
+ }
3895
+ async delay(ms) {
3896
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
3897
+ }
3898
+ };
3899
+ var ConsoleTransport = class {
3900
+ async emit(subject, event) {
3901
+ try {
3902
+ console.log(
3903
+ "[SDK Telemetry]",
3904
+ JSON.stringify({ subject, properties: event }, null, 2)
3905
+ );
3906
+ } catch {
3907
+ }
3908
+ }
3909
+ };
3910
+ var NoopTransport = class {
3911
+ async emit(_subject, _event) {
3912
+ }
3913
+ };
3914
+ function createTransport(config) {
3915
+ try {
3916
+ switch (config.type) {
3917
+ case "http":
3918
+ if (!config.endpoint) {
3919
+ throw new Error("HTTP transport requires endpoint");
3920
+ }
3921
+ return new HttpTransport({
3922
+ endpoint: config.endpoint,
3923
+ headers: config.headers,
3924
+ retryAttempts: config.retryAttempts,
3925
+ retryDelayMs: config.retryDelayMs
3926
+ });
3927
+ case "console":
3928
+ return new ConsoleTransport();
3929
+ case "noop":
3930
+ default:
3931
+ return new NoopTransport();
3932
+ }
3933
+ } catch {
3934
+ return new NoopTransport();
3935
+ }
3936
+ }
3937
+ function generateEventId() {
3938
+ return crypto.randomUUID();
3939
+ }
3940
+ function getCurrentTimestamp() {
3941
+ return Date.now();
3942
+ }
3943
+ function getReleaseId() {
3944
+ return process?.env?.SDK_RELEASE_ID || "development";
3945
+ }
3946
+ function getOsInfo() {
3947
+ try {
3948
+ return {
3949
+ platform: os__namespace.platform() || null,
3950
+ release: os__namespace.release() || null,
3951
+ architecture: os__namespace.arch() || null
3952
+ };
3953
+ } catch {
3954
+ return {
3955
+ platform: null,
3956
+ release: null,
3957
+ architecture: null
3958
+ };
3959
+ }
3960
+ }
3961
+ function getPlatformVersions() {
3962
+ const versions = {};
3963
+ if (typeof process?.versions === "object") {
3964
+ for (const [key, value] of Object.entries(process.versions)) {
3965
+ versions[key] = value || null;
3966
+ }
3967
+ }
3968
+ return versions;
3969
+ }
3970
+ function isCi() {
3971
+ return !!(process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION || process?.env?.GITHUB_ACTIONS || process?.env?.JENKINS_URL || process?.env?.GITLAB_CI || process?.env?.CIRCLECI || process?.env?.TRAVIS || process?.env?.BUILDKITE || process?.env?.DRONE || process?.env?.BITBUCKET_PIPELINES_UUID);
3972
+ }
3973
+ function getCiPlatform() {
3974
+ if (process?.env?.GITHUB_ACTIONS) return "github-actions";
3975
+ if (process?.env?.JENKINS_URL) return "jenkins";
3976
+ if (process?.env?.GITLAB_CI) return "gitlab-ci";
3977
+ if (process?.env?.CIRCLECI) return "circleci";
3978
+ if (process?.env?.TRAVIS) return "travis";
3979
+ if (process?.env?.BUILDKITE) return "buildkite";
3980
+ if (process?.env?.DRONE) return "drone";
3981
+ if (process?.env?.BITBUCKET_PIPELINES_UUID) return "bitbucket-pipelines";
3982
+ if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
3983
+ return "unknown-ci";
3984
+ return null;
3985
+ }
3986
+ function getMemoryUsage() {
3987
+ if (process?.memoryUsage) {
3988
+ const usage = process.memoryUsage();
3989
+ return usage.rss || null;
3990
+ }
3991
+ return null;
3992
+ }
3993
+ function getCpuTime() {
3994
+ if (process?.cpuUsage) {
3995
+ const usage = process.cpuUsage();
3996
+ return Math.round((usage.user + usage.system) / 1e3);
3997
+ }
3998
+ return null;
3999
+ }
4000
+
4001
+ // package.json
4002
+ var package_default = {
4003
+ version: "0.13.5"};
4004
+
4005
+ // src/plugins/eventEmission/builders.ts
4006
+ function createBaseEvent(context = {}) {
4007
+ return {
4008
+ event_id: generateEventId(),
4009
+ timestamp_ms: getCurrentTimestamp(),
4010
+ release_id: getReleaseId(),
4011
+ customuser_id: context.customuser_id,
4012
+ account_id: context.account_id,
4013
+ identity_id: context.identity_id,
4014
+ visitor_id: context.visitor_id,
4015
+ correlation_id: context.correlation_id
4016
+ };
4017
+ }
4018
+ function buildErrorEvent(data, context = {}) {
4019
+ return {
4020
+ ...createBaseEvent(context),
4021
+ zap_id: context.zap_id,
4022
+ node_id: context.node_id,
4023
+ selected_api: context.selected_api,
4024
+ app_id: context.app_id,
4025
+ app_version_id: context.app_version_id,
4026
+ environment: context.environment,
4027
+ sdk_version: package_default.version,
4028
+ ...data
4029
+ };
4030
+ }
4031
+ function buildApplicationLifecycleEvent(data, context = {}) {
4032
+ const osInfo = getOsInfo();
4033
+ const platformVersions = getPlatformVersions();
4034
+ return {
4035
+ ...createBaseEvent(context),
4036
+ selected_api: context.selected_api,
4037
+ app_id: context.app_id,
4038
+ app_version_id: context.app_version_id,
4039
+ sdk_version: package_default.version,
4040
+ cli_version: null,
4041
+ memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
4042
+ peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
4043
+ cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
4044
+ os_platform: osInfo.platform,
4045
+ os_release: osInfo.release,
4046
+ os_architecture: osInfo.architecture,
4047
+ platform_versions: platformVersions,
4048
+ environment: context.environment ?? (process.env.NODE_ENV || null),
4049
+ is_ci_environment: isCi(),
4050
+ ci_platform: getCiPlatform(),
4051
+ session_id: null,
4052
+ metadata: null,
4053
+ process_argv: process.argv || null,
4054
+ ...data
4055
+ };
4056
+ }
4057
+ function buildErrorEventWithContext(data, context = {}) {
4058
+ const executionTime = data.execution_start_time ? Date.now() - data.execution_start_time : null;
4059
+ return {
4060
+ ...createBaseEvent(context),
4061
+ zap_id: context.zap_id,
4062
+ node_id: context.node_id,
4063
+ selected_api: context.selected_api,
4064
+ app_id: context.app_id,
4065
+ app_version_id: context.app_version_id,
4066
+ environment: context.environment ?? (process.env.NODE_ENV || null),
4067
+ sdk_version: package_default.version,
4068
+ execution_time_before_error_ms: executionTime,
4069
+ ...data
4070
+ };
4071
+ }
4072
+
4073
+ // src/plugins/eventEmission/index.ts
4074
+ var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
4075
+ var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
4076
+ async function silentEmit(transport, subject, event) {
4077
+ try {
4078
+ transport.emit(subject, event).catch(() => {
4079
+ });
4080
+ } catch {
4081
+ }
4082
+ }
4083
+ function getTransportConfig() {
4084
+ const envTransport = process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT;
4085
+ if (envTransport === "noop" || envTransport === "disabled") {
4086
+ return { type: "noop" };
4087
+ }
4088
+ if (envTransport === "console") {
4089
+ return { type: "console" };
4090
+ }
4091
+ const endpoint = process?.env?.ZAPIER_SDK_TELEMETRY_ENDPOINT || TRACKING_API_ENDPOINT;
4092
+ return {
4093
+ type: "http",
4094
+ endpoint
4095
+ };
4096
+ }
4097
+ var eventEmissionPlugin = ({ context }) => {
4098
+ const defaultTransport = getTransportConfig();
4099
+ const config = {
4100
+ enabled: context.options.eventEmission?.enabled ?? true,
4101
+ transport: (
4102
+ // If env var is set, use it (defaultTransport will be from env)
4103
+ process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
4104
+ // Otherwise, use option transport or default
4105
+ context.options.eventEmission?.transport ?? defaultTransport
4106
+ )
4107
+ )
4108
+ };
4109
+ const startupTime = Date.now();
4110
+ let shutdownStartTime = null;
4111
+ if (!config.enabled) {
4112
+ return {
4113
+ context: {
4114
+ eventEmission: {
4115
+ transport: createTransport({ type: "noop" }),
4116
+ config,
4117
+ emit: () => {
4118
+ },
4119
+ createBaseEvent: () => ({
4120
+ event_id: generateEventId(),
4121
+ timestamp_ms: getCurrentTimestamp(),
4122
+ release_id: getReleaseId(),
4123
+ customuser_id: null,
4124
+ account_id: null,
4125
+ identity_id: null,
4126
+ visitor_id: null,
4127
+ correlation_id: null
4128
+ })
4129
+ }
4130
+ }
4131
+ };
4132
+ }
4133
+ let transport;
4134
+ try {
4135
+ transport = createTransport(config.transport || { type: "noop" });
4136
+ } catch {
4137
+ transport = createTransport({ type: "noop" });
4138
+ }
4139
+ const createBaseEventHelper = () => ({
4140
+ event_id: generateEventId(),
4141
+ timestamp_ms: getCurrentTimestamp(),
4142
+ release_id: getReleaseId(),
4143
+ customuser_id: null,
4144
+ account_id: null,
4145
+ identity_id: null,
4146
+ visitor_id: null,
4147
+ correlation_id: null
4148
+ });
4149
+ if (config.enabled) {
4150
+ const startupEvent = buildApplicationLifecycleEvent({
4151
+ lifecycle_event_type: "startup"
4152
+ });
4153
+ silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, startupEvent);
4154
+ if (typeof process?.on === "function") {
4155
+ process.on("exit", (code) => {
4156
+ const uptime = Date.now() - startupTime;
4157
+ const shutdownDuration = shutdownStartTime ? Date.now() - shutdownStartTime : null;
4158
+ const exitEvent = buildApplicationLifecycleEvent({
4159
+ lifecycle_event_type: "exit",
4160
+ exit_code: code,
4161
+ uptime_ms: uptime,
4162
+ is_graceful_shutdown: code === 0,
4163
+ shutdown_duration_ms: shutdownDuration
4164
+ });
4165
+ silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, exitEvent);
4166
+ });
4167
+ process.on("uncaughtException", async (error) => {
4168
+ const errorEvent = buildErrorEventWithContext({
4169
+ error_message: error.message || "Unknown error",
4170
+ error_type: "UncaughtException",
4171
+ error_stack_trace: error.stack || null,
4172
+ error_severity: "critical",
4173
+ is_user_facing: false,
4174
+ is_recoverable: false,
4175
+ execution_start_time: startupTime
4176
+ });
4177
+ try {
4178
+ await Promise.race([
4179
+ transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
4180
+ new Promise((resolve2) => setTimeout(resolve2, 300))
4181
+ ]);
4182
+ } catch {
4183
+ }
4184
+ });
4185
+ process.on(
4186
+ "unhandledRejection",
4187
+ async (reason, promise) => {
4188
+ const errorMessage = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
4189
+ const errorStack = reason instanceof Error ? reason.stack : null;
4190
+ const errorEvent = buildErrorEventWithContext({
4191
+ error_message: errorMessage,
4192
+ error_type: "UnhandledRejection",
4193
+ error_stack_trace: errorStack,
4194
+ error_severity: "critical",
4195
+ is_user_facing: false,
4196
+ is_recoverable: false,
4197
+ execution_start_time: startupTime,
4198
+ error_metadata: {
4199
+ promise: String(promise)
4200
+ }
4201
+ });
4202
+ try {
4203
+ await Promise.race([
4204
+ transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
4205
+ new Promise((resolve2) => setTimeout(resolve2, 300))
4206
+ ]);
4207
+ } catch {
4208
+ }
4209
+ }
4210
+ );
4211
+ const handleSignal = async (signal) => {
4212
+ shutdownStartTime = Date.now();
4213
+ const uptime = Date.now() - startupTime;
4214
+ const signalEvent = buildApplicationLifecycleEvent({
4215
+ lifecycle_event_type: "signal_termination",
4216
+ signal_name: signal,
4217
+ uptime_ms: uptime,
4218
+ is_graceful_shutdown: true
4219
+ });
4220
+ try {
4221
+ await Promise.race([
4222
+ transport.emit(APPLICATION_LIFECYCLE_EVENT_SUBJECT, signalEvent),
4223
+ new Promise((resolve2) => setTimeout(resolve2, 300))
4224
+ ]);
4225
+ } catch {
4226
+ }
4227
+ };
4228
+ ["SIGINT", "SIGTERM"].forEach((signal) => {
4229
+ process.on(signal, () => handleSignal(signal));
4230
+ });
4231
+ }
4232
+ }
4233
+ return {
4234
+ context: {
4235
+ eventEmission: {
4236
+ transport,
4237
+ config,
4238
+ emit: (subject, event) => {
4239
+ silentEmit(transport, subject, event);
4240
+ },
4241
+ createBaseEvent: createBaseEventHelper
4242
+ }
4243
+ }
4244
+ };
4245
+ };
4246
+
3814
4247
  // src/sdk.ts
3815
4248
  function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
3816
4249
  return {
@@ -3860,7 +4293,7 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
3860
4293
  };
3861
4294
  }
3862
4295
  function createZapierSdkWithoutRegistry(options = {}) {
3863
- return createSdk(options).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
4296
+ return createSdk(options).addPlugin(eventEmissionPlugin).addPlugin(apiPlugin).addPlugin(manifestPlugin).addPlugin(listAppsPlugin).addPlugin(getAppPlugin).addPlugin(listActionsPlugin).addPlugin(getActionPlugin).addPlugin(listInputFieldsPlugin).addPlugin(listInputFieldChoicesPlugin).addPlugin(runActionPlugin).addPlugin(listAuthenticationsPlugin).addPlugin(getAuthenticationPlugin).addPlugin(findFirstAuthenticationPlugin).addPlugin(findUniqueAuthenticationPlugin).addPlugin(requestPlugin).addPlugin(fetchPlugin).addPlugin(appsPlugin).addPlugin(getProfilePlugin);
3864
4297
  }
3865
4298
  function createZapierSdk(options = {}) {
3866
4299
  return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
@@ -3898,6 +4331,10 @@ exports.appKeyResolver = appKeyResolver;
3898
4331
  exports.appsPlugin = appsPlugin;
3899
4332
  exports.authenticationIdGenericResolver = authenticationIdGenericResolver;
3900
4333
  exports.authenticationIdResolver = authenticationIdResolver;
4334
+ exports.buildApplicationLifecycleEvent = buildApplicationLifecycleEvent;
4335
+ exports.buildErrorEvent = buildErrorEvent;
4336
+ exports.buildErrorEventWithContext = buildErrorEventWithContext;
4337
+ exports.createBaseEvent = createBaseEvent;
3901
4338
  exports.createFunction = createFunction;
3902
4339
  exports.createSdk = createSdk;
3903
4340
  exports.createZapierSdk = createZapierSdk;
@@ -3907,17 +4344,26 @@ exports.findFirstAuthenticationPlugin = findFirstAuthenticationPlugin;
3907
4344
  exports.findManifestEntry = findManifestEntry;
3908
4345
  exports.findUniqueAuthenticationPlugin = findUniqueAuthenticationPlugin;
3909
4346
  exports.formatErrorMessage = formatErrorMessage;
4347
+ exports.generateEventId = generateEventId;
3910
4348
  exports.getActionPlugin = getActionPlugin;
3911
4349
  exports.getAppPlugin = getAppPlugin;
3912
4350
  exports.getAuthenticationPlugin = getAuthenticationPlugin;
4351
+ exports.getCiPlatform = getCiPlatform;
4352
+ exports.getCpuTime = getCpuTime;
4353
+ exports.getCurrentTimestamp = getCurrentTimestamp;
4354
+ exports.getMemoryUsage = getMemoryUsage;
4355
+ exports.getOsInfo = getOsInfo;
4356
+ exports.getPlatformVersions = getPlatformVersions;
3913
4357
  exports.getPreferredManifestEntryKey = getPreferredManifestEntryKey;
3914
4358
  exports.getProfilePlugin = getProfilePlugin;
4359
+ exports.getReleaseId = getReleaseId;
3915
4360
  exports.getTokenFromCliLogin = getTokenFromCliLogin;
3916
4361
  exports.getTokenFromEnv = getTokenFromEnv;
3917
4362
  exports.getTokenFromEnvOrConfig = getTokenFromEnvOrConfig;
3918
4363
  exports.inputFieldKeyResolver = inputFieldKeyResolver;
3919
4364
  exports.inputsAllOptionalResolver = inputsAllOptionalResolver;
3920
4365
  exports.inputsResolver = inputsResolver;
4366
+ exports.isCi = isCi;
3921
4367
  exports.isPositional = isPositional;
3922
4368
  exports.listActionsPlugin = listActionsPlugin;
3923
4369
  exports.listAppsPlugin = listAppsPlugin;