@zapier/zapier-sdk 0.13.3 → 0.13.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.
- package/CHANGELOG.md +6 -0
- package/dist/api/schemas.d.ts +174 -174
- package/dist/constants.d.ts +4 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/index.cjs +436 -5
- package/dist/index.d.mts +380 -156
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +407 -9
- package/dist/plugins/api/index.d.ts +1 -3
- package/dist/plugins/api/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/builders.d.ts +13 -0
- package/dist/plugins/eventEmission/builders.d.ts.map +1 -0
- package/dist/plugins/eventEmission/builders.js +78 -0
- package/dist/plugins/eventEmission/index.d.ts +34 -0
- package/dist/plugins/eventEmission/index.d.ts.map +1 -0
- package/dist/plugins/eventEmission/index.js +216 -0
- package/dist/plugins/eventEmission/index.test.d.ts +5 -0
- package/dist/plugins/eventEmission/index.test.d.ts.map +1 -0
- package/dist/plugins/eventEmission/index.test.js +143 -0
- package/dist/plugins/eventEmission/transport.d.ts +37 -0
- package/dist/plugins/eventEmission/transport.d.ts.map +1 -0
- package/dist/plugins/eventEmission/transport.js +96 -0
- package/dist/plugins/eventEmission/transport.test.d.ts +5 -0
- package/dist/plugins/eventEmission/transport.test.d.ts.map +1 -0
- package/dist/plugins/eventEmission/transport.test.js +153 -0
- package/dist/plugins/eventEmission/types.d.ts +53 -0
- package/dist/plugins/eventEmission/types.d.ts.map +1 -0
- package/dist/plugins/eventEmission/types.js +1 -0
- package/dist/plugins/eventEmission/utils.d.ts +45 -0
- package/dist/plugins/eventEmission/utils.d.ts.map +1 -0
- package/dist/plugins/eventEmission/utils.js +114 -0
- package/dist/plugins/fetch/schemas.d.ts +4 -4
- package/dist/plugins/getAction/schemas.d.ts +2 -2
- package/dist/plugins/listActions/schemas.d.ts +2 -2
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/schemas.d.ts +2 -2
- package/dist/plugins/request/schemas.d.ts +4 -4
- package/dist/plugins/runAction/schemas.d.ts +2 -2
- package/dist/resolvers/actionType.d.ts.map +1 -1
- package/dist/resolvers/actionType.js +2 -3
- package/dist/resolvers/authenticationId.d.ts.map +1 -1
- package/dist/schemas/Action.d.ts +2 -2
- package/dist/schemas/App.d.ts +30 -30
- package/dist/sdk.d.ts +2 -2
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +4 -1
- package/dist/types/sdk.d.ts +5 -1
- package/dist/types/sdk.d.ts.map +1 -1
- package/dist/types/telemetry-events.d.ts +76 -0
- package/dist/types/telemetry-events.d.ts.map +1 -0
- package/dist/types/telemetry-events.js +8 -0
- package/package.json +1 -1
- package/src/constants.ts +6 -0
- package/src/index.ts +24 -0
- package/src/plugins/api/index.ts +1 -5
- package/src/plugins/eventEmission/builders.ts +115 -0
- package/src/plugins/eventEmission/index.test.ts +169 -0
- package/src/plugins/eventEmission/index.ts +294 -0
- package/src/plugins/eventEmission/transport.test.ts +214 -0
- package/src/plugins/eventEmission/transport.ts +135 -0
- package/src/plugins/eventEmission/types.ts +58 -0
- package/src/plugins/eventEmission/utils.ts +121 -0
- package/src/resolvers/actionType.ts +4 -3
- package/src/resolvers/authenticationId.ts +2 -1
- package/src/sdk.ts +5 -1
- package/src/types/sdk.ts +7 -1
- package/src/types/telemetry-events.ts +85 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -31,4 +31,7 @@ export type { FunctionRegistryEntry } from "./types/sdk";
|
|
|
31
31
|
export type { Plugin, PluginProvides, PluginDependencies, PluginOptions, GetSdkType, GetContextType, Sdk, } from "./types/plugin";
|
|
32
32
|
export { registryPlugin } from "./plugins/registry";
|
|
33
33
|
export type { ZapierSdk } from "./types/sdk";
|
|
34
|
+
export type { BaseEvent } from "./types/telemetry-events";
|
|
35
|
+
export type { EventEmissionContext, EventContext, ApplicationLifecycleEventData, EnhancedErrorEventData, } from "./plugins/eventEmission";
|
|
36
|
+
export { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, isCi, getCiPlatform, getMemoryUsage, getCpuTime, buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, } from "./plugins/eventEmission";
|
|
34
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAG9B,YAAY,EACV,MAAM,EACN,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGhE,cAAc,aAAa,CAAC;AAG5B,cAAc,QAAQ,CAAC;AAIvB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,SAAS,EACT,gBAAgB,GACjB,MAAM,OAAO,CAAC;AAGf,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,YAAY,EACV,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,cAAc,EACd,GAAG,GACJ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAG9B,YAAY,EACV,MAAM,EACN,GAAG,EACH,IAAI,EACJ,KAAK,EACL,MAAM,EACN,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,uBAAuB,EACvB,WAAW,GACZ,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGhE,cAAc,aAAa,CAAC;AAG5B,cAAc,QAAQ,CAAC;AAIvB,OAAO,EACL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,eAAe,EACf,8BAA8B,EAC9B,SAAS,EACT,gBAAgB,GACjB,MAAM,OAAO,CAAC;AAGf,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,YAAY,EACV,MAAM,EACN,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,cAAc,EACd,GAAG,GACJ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7C,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EACV,oBAAoB,EACpB,YAAY,EACZ,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,IAAI,EACJ,aAAa,EACb,cAAc,EACd,UAAU,EACV,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,3 +35,4 @@ export { RelayRequestSchema, RelayFetchSchema, } from "./plugins/request/schemas
|
|
|
35
35
|
export { createZapierSdk, createZapierSdkWithoutRegistry, createSdk, } from "./sdk";
|
|
36
36
|
// Export registry plugin for manual use
|
|
37
37
|
export { registryPlugin } from "./plugins/registry";
|
|
38
|
+
export { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, isCi, getCiPlatform, getMemoryUsage, getCpuTime, buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, } from "./plugins/eventEmission";
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { setTimeout } from 'timers/promises';
|
|
2
|
+
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
|
3
|
+
import * as os from 'os';
|
|
3
4
|
|
|
4
5
|
// src/types/properties.ts
|
|
5
6
|
function withFormatter(schema, formatMeta) {
|
|
@@ -32,6 +33,7 @@ function isPositional(schema) {
|
|
|
32
33
|
|
|
33
34
|
// src/constants.ts
|
|
34
35
|
var MAX_PAGE_LIMIT = 1e4;
|
|
36
|
+
var TRACKING_API_ENDPOINT = "https://zapier.com/api/v4/tracking/event/";
|
|
35
37
|
|
|
36
38
|
// src/types/properties.ts
|
|
37
39
|
var AppKeyPropertySchema = withPositional(
|
|
@@ -368,7 +370,7 @@ var FetchInitSchema = z.object({
|
|
|
368
370
|
// src/plugins/fetch/index.ts
|
|
369
371
|
var fetchPlugin = ({ sdk }) => {
|
|
370
372
|
return {
|
|
371
|
-
fetch: async function
|
|
373
|
+
fetch: async function fetch2(url, init) {
|
|
372
374
|
const {
|
|
373
375
|
authenticationId,
|
|
374
376
|
callbackUrl,
|
|
@@ -1407,9 +1409,10 @@ var actionTypeResolver = {
|
|
|
1407
1409
|
const actionsResponse = await sdk.listActions({
|
|
1408
1410
|
appKey: resolvedParams.appKey
|
|
1409
1411
|
});
|
|
1410
|
-
const
|
|
1411
|
-
|
|
1412
|
-
|
|
1412
|
+
const actionTypes = actionsResponse.data.map(
|
|
1413
|
+
(action) => action.action_type
|
|
1414
|
+
);
|
|
1415
|
+
const types = [...new Set(actionTypes)];
|
|
1413
1416
|
return types.map((type) => ({ key: type, name: type }));
|
|
1414
1417
|
},
|
|
1415
1418
|
prompt: (types) => ({
|
|
@@ -3160,7 +3163,7 @@ async function pollUntilComplete(options) {
|
|
|
3160
3163
|
// Up to timeout + 10s: poll every 10s
|
|
3161
3164
|
];
|
|
3162
3165
|
if (initialDelay > 0) {
|
|
3163
|
-
await setTimeout(initialDelay);
|
|
3166
|
+
await setTimeout$1(initialDelay);
|
|
3164
3167
|
}
|
|
3165
3168
|
while (true) {
|
|
3166
3169
|
attempts++;
|
|
@@ -3180,7 +3183,7 @@ async function pollUntilComplete(options) {
|
|
|
3180
3183
|
}
|
|
3181
3184
|
if (attempts > 1) {
|
|
3182
3185
|
const waitTime = calculateWaitTime(pollingInterval[1], errorCount);
|
|
3183
|
-
await setTimeout(waitTime);
|
|
3186
|
+
await setTimeout$1(waitTime);
|
|
3184
3187
|
}
|
|
3185
3188
|
try {
|
|
3186
3189
|
const response = await fetchPoll();
|
|
@@ -3809,6 +3812,401 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
3809
3812
|
};
|
|
3810
3813
|
};
|
|
3811
3814
|
|
|
3815
|
+
// src/plugins/eventEmission/transport.ts
|
|
3816
|
+
var DEFAULT_RETRY_ATTEMPTS = 2;
|
|
3817
|
+
var DEFAULT_RETRY_DELAY_MS = 300;
|
|
3818
|
+
var HttpTransport = class {
|
|
3819
|
+
constructor(config) {
|
|
3820
|
+
this.config = config;
|
|
3821
|
+
}
|
|
3822
|
+
async emit(subject, event) {
|
|
3823
|
+
try {
|
|
3824
|
+
await this.emitWithRetry(
|
|
3825
|
+
subject,
|
|
3826
|
+
event,
|
|
3827
|
+
this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
|
|
3828
|
+
);
|
|
3829
|
+
} catch {
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
async emitWithRetry(subject, event, attemptsLeft) {
|
|
3833
|
+
try {
|
|
3834
|
+
const payload = {
|
|
3835
|
+
subject,
|
|
3836
|
+
properties: event
|
|
3837
|
+
};
|
|
3838
|
+
const response = await fetch(this.config.endpoint, {
|
|
3839
|
+
method: "POST",
|
|
3840
|
+
headers: {
|
|
3841
|
+
"Content-Type": "application/json",
|
|
3842
|
+
...this.config.headers
|
|
3843
|
+
},
|
|
3844
|
+
body: JSON.stringify(payload)
|
|
3845
|
+
});
|
|
3846
|
+
if (!response.ok && attemptsLeft > 1) {
|
|
3847
|
+
await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
3848
|
+
return this.emitWithRetry(subject, event, attemptsLeft - 1);
|
|
3849
|
+
}
|
|
3850
|
+
} catch (error) {
|
|
3851
|
+
if (attemptsLeft > 1) {
|
|
3852
|
+
await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
3853
|
+
return this.emitWithRetry(subject, event, attemptsLeft - 1);
|
|
3854
|
+
}
|
|
3855
|
+
throw error;
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
async delay(ms) {
|
|
3859
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
var ConsoleTransport = class {
|
|
3863
|
+
async emit(subject, event) {
|
|
3864
|
+
try {
|
|
3865
|
+
console.log(
|
|
3866
|
+
"[SDK Telemetry]",
|
|
3867
|
+
JSON.stringify({ subject, properties: event }, null, 2)
|
|
3868
|
+
);
|
|
3869
|
+
} catch {
|
|
3870
|
+
}
|
|
3871
|
+
}
|
|
3872
|
+
};
|
|
3873
|
+
var NoopTransport = class {
|
|
3874
|
+
async emit(_subject, _event) {
|
|
3875
|
+
}
|
|
3876
|
+
};
|
|
3877
|
+
function createTransport(config) {
|
|
3878
|
+
try {
|
|
3879
|
+
switch (config.type) {
|
|
3880
|
+
case "http":
|
|
3881
|
+
if (!config.endpoint) {
|
|
3882
|
+
throw new Error("HTTP transport requires endpoint");
|
|
3883
|
+
}
|
|
3884
|
+
return new HttpTransport({
|
|
3885
|
+
endpoint: config.endpoint,
|
|
3886
|
+
headers: config.headers,
|
|
3887
|
+
retryAttempts: config.retryAttempts,
|
|
3888
|
+
retryDelayMs: config.retryDelayMs
|
|
3889
|
+
});
|
|
3890
|
+
case "console":
|
|
3891
|
+
return new ConsoleTransport();
|
|
3892
|
+
case "noop":
|
|
3893
|
+
default:
|
|
3894
|
+
return new NoopTransport();
|
|
3895
|
+
}
|
|
3896
|
+
} catch {
|
|
3897
|
+
return new NoopTransport();
|
|
3898
|
+
}
|
|
3899
|
+
}
|
|
3900
|
+
function generateEventId() {
|
|
3901
|
+
return crypto.randomUUID();
|
|
3902
|
+
}
|
|
3903
|
+
function getCurrentTimestamp() {
|
|
3904
|
+
return Date.now();
|
|
3905
|
+
}
|
|
3906
|
+
function getReleaseId() {
|
|
3907
|
+
return process?.env?.SDK_RELEASE_ID || "development";
|
|
3908
|
+
}
|
|
3909
|
+
function getOsInfo() {
|
|
3910
|
+
try {
|
|
3911
|
+
return {
|
|
3912
|
+
platform: os.platform() || null,
|
|
3913
|
+
release: os.release() || null,
|
|
3914
|
+
architecture: os.arch() || null
|
|
3915
|
+
};
|
|
3916
|
+
} catch {
|
|
3917
|
+
return {
|
|
3918
|
+
platform: null,
|
|
3919
|
+
release: null,
|
|
3920
|
+
architecture: null
|
|
3921
|
+
};
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
function getPlatformVersions() {
|
|
3925
|
+
const versions = {};
|
|
3926
|
+
if (typeof process?.versions === "object") {
|
|
3927
|
+
for (const [key, value] of Object.entries(process.versions)) {
|
|
3928
|
+
versions[key] = value || null;
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
return versions;
|
|
3932
|
+
}
|
|
3933
|
+
function isCi() {
|
|
3934
|
+
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);
|
|
3935
|
+
}
|
|
3936
|
+
function getCiPlatform() {
|
|
3937
|
+
if (process?.env?.GITHUB_ACTIONS) return "github-actions";
|
|
3938
|
+
if (process?.env?.JENKINS_URL) return "jenkins";
|
|
3939
|
+
if (process?.env?.GITLAB_CI) return "gitlab-ci";
|
|
3940
|
+
if (process?.env?.CIRCLECI) return "circleci";
|
|
3941
|
+
if (process?.env?.TRAVIS) return "travis";
|
|
3942
|
+
if (process?.env?.BUILDKITE) return "buildkite";
|
|
3943
|
+
if (process?.env?.DRONE) return "drone";
|
|
3944
|
+
if (process?.env?.BITBUCKET_PIPELINES_UUID) return "bitbucket-pipelines";
|
|
3945
|
+
if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
|
|
3946
|
+
return "unknown-ci";
|
|
3947
|
+
return null;
|
|
3948
|
+
}
|
|
3949
|
+
function getMemoryUsage() {
|
|
3950
|
+
if (process?.memoryUsage) {
|
|
3951
|
+
const usage = process.memoryUsage();
|
|
3952
|
+
return usage.rss || null;
|
|
3953
|
+
}
|
|
3954
|
+
return null;
|
|
3955
|
+
}
|
|
3956
|
+
function getCpuTime() {
|
|
3957
|
+
if (process?.cpuUsage) {
|
|
3958
|
+
const usage = process.cpuUsage();
|
|
3959
|
+
return Math.round((usage.user + usage.system) / 1e3);
|
|
3960
|
+
}
|
|
3961
|
+
return null;
|
|
3962
|
+
}
|
|
3963
|
+
|
|
3964
|
+
// package.json
|
|
3965
|
+
var package_default = {
|
|
3966
|
+
version: "0.13.4"};
|
|
3967
|
+
|
|
3968
|
+
// src/plugins/eventEmission/builders.ts
|
|
3969
|
+
function createBaseEvent(context = {}) {
|
|
3970
|
+
return {
|
|
3971
|
+
event_id: generateEventId(),
|
|
3972
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
3973
|
+
release_id: getReleaseId(),
|
|
3974
|
+
customuser_id: context.customuser_id,
|
|
3975
|
+
account_id: context.account_id,
|
|
3976
|
+
identity_id: context.identity_id,
|
|
3977
|
+
visitor_id: context.visitor_id,
|
|
3978
|
+
correlation_id: context.correlation_id
|
|
3979
|
+
};
|
|
3980
|
+
}
|
|
3981
|
+
function buildErrorEvent(data, context = {}) {
|
|
3982
|
+
return {
|
|
3983
|
+
...createBaseEvent(context),
|
|
3984
|
+
zap_id: context.zap_id,
|
|
3985
|
+
node_id: context.node_id,
|
|
3986
|
+
selected_api: context.selected_api,
|
|
3987
|
+
app_id: context.app_id,
|
|
3988
|
+
app_version_id: context.app_version_id,
|
|
3989
|
+
environment: context.environment,
|
|
3990
|
+
sdk_version: package_default.version,
|
|
3991
|
+
...data
|
|
3992
|
+
};
|
|
3993
|
+
}
|
|
3994
|
+
function buildApplicationLifecycleEvent(data, context = {}) {
|
|
3995
|
+
const osInfo = getOsInfo();
|
|
3996
|
+
const platformVersions = getPlatformVersions();
|
|
3997
|
+
return {
|
|
3998
|
+
...createBaseEvent(context),
|
|
3999
|
+
selected_api: context.selected_api,
|
|
4000
|
+
app_id: context.app_id,
|
|
4001
|
+
app_version_id: context.app_version_id,
|
|
4002
|
+
sdk_version: package_default.version,
|
|
4003
|
+
cli_version: null,
|
|
4004
|
+
memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
|
|
4005
|
+
peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
|
|
4006
|
+
cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
|
|
4007
|
+
os_platform: osInfo.platform,
|
|
4008
|
+
os_release: osInfo.release,
|
|
4009
|
+
os_architecture: osInfo.architecture,
|
|
4010
|
+
platform_versions: platformVersions,
|
|
4011
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
4012
|
+
is_ci_environment: isCi(),
|
|
4013
|
+
ci_platform: getCiPlatform(),
|
|
4014
|
+
session_id: null,
|
|
4015
|
+
metadata: null,
|
|
4016
|
+
process_argv: process.argv || null,
|
|
4017
|
+
...data
|
|
4018
|
+
};
|
|
4019
|
+
}
|
|
4020
|
+
function buildErrorEventWithContext(data, context = {}) {
|
|
4021
|
+
const executionTime = data.execution_start_time ? Date.now() - data.execution_start_time : null;
|
|
4022
|
+
return {
|
|
4023
|
+
...createBaseEvent(context),
|
|
4024
|
+
zap_id: context.zap_id,
|
|
4025
|
+
node_id: context.node_id,
|
|
4026
|
+
selected_api: context.selected_api,
|
|
4027
|
+
app_id: context.app_id,
|
|
4028
|
+
app_version_id: context.app_version_id,
|
|
4029
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
4030
|
+
sdk_version: package_default.version,
|
|
4031
|
+
execution_time_before_error_ms: executionTime,
|
|
4032
|
+
...data
|
|
4033
|
+
};
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
// src/plugins/eventEmission/index.ts
|
|
4037
|
+
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4038
|
+
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
4039
|
+
async function silentEmit(transport, subject, event) {
|
|
4040
|
+
try {
|
|
4041
|
+
transport.emit(subject, event).catch(() => {
|
|
4042
|
+
});
|
|
4043
|
+
} catch {
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
function getTransportConfig() {
|
|
4047
|
+
const envTransport = process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT;
|
|
4048
|
+
if (envTransport === "noop" || envTransport === "disabled") {
|
|
4049
|
+
return { type: "noop" };
|
|
4050
|
+
}
|
|
4051
|
+
if (envTransport === "console") {
|
|
4052
|
+
return { type: "console" };
|
|
4053
|
+
}
|
|
4054
|
+
const endpoint = process?.env?.ZAPIER_SDK_TELEMETRY_ENDPOINT || TRACKING_API_ENDPOINT;
|
|
4055
|
+
return {
|
|
4056
|
+
type: "http",
|
|
4057
|
+
endpoint
|
|
4058
|
+
};
|
|
4059
|
+
}
|
|
4060
|
+
var eventEmissionPlugin = ({ context }) => {
|
|
4061
|
+
const defaultTransport = getTransportConfig();
|
|
4062
|
+
const config = {
|
|
4063
|
+
enabled: context.options.eventEmission?.enabled ?? true,
|
|
4064
|
+
transport: (
|
|
4065
|
+
// If env var is set, use it (defaultTransport will be from env)
|
|
4066
|
+
process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
|
|
4067
|
+
// Otherwise, use option transport or default
|
|
4068
|
+
context.options.eventEmission?.transport ?? defaultTransport
|
|
4069
|
+
)
|
|
4070
|
+
)
|
|
4071
|
+
};
|
|
4072
|
+
const startupTime = Date.now();
|
|
4073
|
+
let shutdownStartTime = null;
|
|
4074
|
+
if (!config.enabled) {
|
|
4075
|
+
return {
|
|
4076
|
+
context: {
|
|
4077
|
+
eventEmission: {
|
|
4078
|
+
transport: createTransport({ type: "noop" }),
|
|
4079
|
+
config,
|
|
4080
|
+
emit: () => {
|
|
4081
|
+
},
|
|
4082
|
+
createBaseEvent: () => ({
|
|
4083
|
+
event_id: generateEventId(),
|
|
4084
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4085
|
+
release_id: getReleaseId(),
|
|
4086
|
+
customuser_id: null,
|
|
4087
|
+
account_id: null,
|
|
4088
|
+
identity_id: null,
|
|
4089
|
+
visitor_id: null,
|
|
4090
|
+
correlation_id: null
|
|
4091
|
+
})
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
};
|
|
4095
|
+
}
|
|
4096
|
+
let transport;
|
|
4097
|
+
try {
|
|
4098
|
+
transport = createTransport(config.transport || { type: "noop" });
|
|
4099
|
+
} catch {
|
|
4100
|
+
transport = createTransport({ type: "noop" });
|
|
4101
|
+
}
|
|
4102
|
+
const createBaseEventHelper = () => ({
|
|
4103
|
+
event_id: generateEventId(),
|
|
4104
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4105
|
+
release_id: getReleaseId(),
|
|
4106
|
+
customuser_id: null,
|
|
4107
|
+
account_id: null,
|
|
4108
|
+
identity_id: null,
|
|
4109
|
+
visitor_id: null,
|
|
4110
|
+
correlation_id: null
|
|
4111
|
+
});
|
|
4112
|
+
if (config.enabled) {
|
|
4113
|
+
const startupEvent = buildApplicationLifecycleEvent({
|
|
4114
|
+
lifecycle_event_type: "startup"
|
|
4115
|
+
});
|
|
4116
|
+
silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, startupEvent);
|
|
4117
|
+
if (typeof process?.on === "function") {
|
|
4118
|
+
process.on("exit", (code) => {
|
|
4119
|
+
const uptime = Date.now() - startupTime;
|
|
4120
|
+
const shutdownDuration = shutdownStartTime ? Date.now() - shutdownStartTime : null;
|
|
4121
|
+
const exitEvent = buildApplicationLifecycleEvent({
|
|
4122
|
+
lifecycle_event_type: "exit",
|
|
4123
|
+
exit_code: code,
|
|
4124
|
+
uptime_ms: uptime,
|
|
4125
|
+
is_graceful_shutdown: code === 0,
|
|
4126
|
+
shutdown_duration_ms: shutdownDuration
|
|
4127
|
+
});
|
|
4128
|
+
silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, exitEvent);
|
|
4129
|
+
});
|
|
4130
|
+
process.on("uncaughtException", async (error) => {
|
|
4131
|
+
const errorEvent = buildErrorEventWithContext({
|
|
4132
|
+
error_message: error.message || "Unknown error",
|
|
4133
|
+
error_type: "UncaughtException",
|
|
4134
|
+
error_stack_trace: error.stack || null,
|
|
4135
|
+
error_severity: "critical",
|
|
4136
|
+
is_user_facing: false,
|
|
4137
|
+
is_recoverable: false,
|
|
4138
|
+
execution_start_time: startupTime
|
|
4139
|
+
});
|
|
4140
|
+
try {
|
|
4141
|
+
await Promise.race([
|
|
4142
|
+
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4143
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4144
|
+
]);
|
|
4145
|
+
} catch {
|
|
4146
|
+
}
|
|
4147
|
+
});
|
|
4148
|
+
process.on(
|
|
4149
|
+
"unhandledRejection",
|
|
4150
|
+
async (reason, promise) => {
|
|
4151
|
+
const errorMessage = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
4152
|
+
const errorStack = reason instanceof Error ? reason.stack : null;
|
|
4153
|
+
const errorEvent = buildErrorEventWithContext({
|
|
4154
|
+
error_message: errorMessage,
|
|
4155
|
+
error_type: "UnhandledRejection",
|
|
4156
|
+
error_stack_trace: errorStack,
|
|
4157
|
+
error_severity: "critical",
|
|
4158
|
+
is_user_facing: false,
|
|
4159
|
+
is_recoverable: false,
|
|
4160
|
+
execution_start_time: startupTime,
|
|
4161
|
+
error_metadata: {
|
|
4162
|
+
promise: String(promise)
|
|
4163
|
+
}
|
|
4164
|
+
});
|
|
4165
|
+
try {
|
|
4166
|
+
await Promise.race([
|
|
4167
|
+
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4168
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4169
|
+
]);
|
|
4170
|
+
} catch {
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
);
|
|
4174
|
+
const handleSignal = async (signal) => {
|
|
4175
|
+
shutdownStartTime = Date.now();
|
|
4176
|
+
const uptime = Date.now() - startupTime;
|
|
4177
|
+
const signalEvent = buildApplicationLifecycleEvent({
|
|
4178
|
+
lifecycle_event_type: "signal_termination",
|
|
4179
|
+
signal_name: signal,
|
|
4180
|
+
uptime_ms: uptime,
|
|
4181
|
+
is_graceful_shutdown: true
|
|
4182
|
+
});
|
|
4183
|
+
try {
|
|
4184
|
+
await Promise.race([
|
|
4185
|
+
transport.emit(APPLICATION_LIFECYCLE_EVENT_SUBJECT, signalEvent),
|
|
4186
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4187
|
+
]);
|
|
4188
|
+
} catch {
|
|
4189
|
+
}
|
|
4190
|
+
};
|
|
4191
|
+
["SIGINT", "SIGTERM"].forEach((signal) => {
|
|
4192
|
+
process.on(signal, () => handleSignal(signal));
|
|
4193
|
+
});
|
|
4194
|
+
}
|
|
4195
|
+
}
|
|
4196
|
+
return {
|
|
4197
|
+
context: {
|
|
4198
|
+
eventEmission: {
|
|
4199
|
+
transport,
|
|
4200
|
+
config,
|
|
4201
|
+
emit: (subject, event) => {
|
|
4202
|
+
silentEmit(transport, subject, event);
|
|
4203
|
+
},
|
|
4204
|
+
createBaseEvent: createBaseEventHelper
|
|
4205
|
+
}
|
|
4206
|
+
}
|
|
4207
|
+
};
|
|
4208
|
+
};
|
|
4209
|
+
|
|
3812
4210
|
// src/sdk.ts
|
|
3813
4211
|
function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
|
|
3814
4212
|
return {
|
|
@@ -3858,10 +4256,10 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
|
|
|
3858
4256
|
};
|
|
3859
4257
|
}
|
|
3860
4258
|
function createZapierSdkWithoutRegistry(options = {}) {
|
|
3861
|
-
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);
|
|
4259
|
+
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);
|
|
3862
4260
|
}
|
|
3863
4261
|
function createZapierSdk(options = {}) {
|
|
3864
4262
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
3865
4263
|
}
|
|
3866
4264
|
|
|
3867
|
-
export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getPreferredManifestEntryKey, getProfilePlugin, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin, toSnakeCase, toTitleCase };
|
|
4265
|
+
export { ActionKeyPropertySchema, ActionTypePropertySchema, AppKeyPropertySchema, AuthenticationIdPropertySchema, DEFAULT_CONFIG_PATH, DebugPropertySchema, InputsPropertySchema, LimitPropertySchema, OffsetPropertySchema, OutputPropertySchema, ParamsPropertySchema, RelayFetchSchema, RelayRequestSchema, ZapierActionError, ZapierApiError, ZapierAppNotFoundError, ZapierAuthenticationError, ZapierBundleError, ZapierConfigurationError, ZapierError, ZapierNotFoundError, ZapierResourceNotFoundError, ZapierTimeoutError, ZapierUnknownError, ZapierValidationError, actionKeyResolver, actionTypeResolver, apiPlugin, appKeyResolver, appsPlugin, authenticationIdGenericResolver, authenticationIdResolver, buildApplicationLifecycleEvent, buildErrorEvent, buildErrorEventWithContext, createBaseEvent, createFunction, createSdk, createZapierSdk, createZapierSdkWithoutRegistry, fetchPlugin, findFirstAuthenticationPlugin, findManifestEntry, findUniqueAuthenticationPlugin, formatErrorMessage, generateEventId, getActionPlugin, getAppPlugin, getAuthenticationPlugin, getCiPlatform, getCpuTime, getCurrentTimestamp, getMemoryUsage, getOsInfo, getPlatformVersions, getPreferredManifestEntryKey, getProfilePlugin, getReleaseId, getTokenFromCliLogin, getTokenFromEnv, getTokenFromEnvOrConfig, inputFieldKeyResolver, inputsAllOptionalResolver, inputsResolver, isCi, isPositional, listActionsPlugin, listAppsPlugin, listAuthenticationsPlugin, listInputFieldsPlugin, manifestPlugin, readManifestFromFile, registryPlugin, requestPlugin, runActionPlugin, toSnakeCase, toTitleCase };
|
|
@@ -8,7 +8,5 @@ export interface ApiPluginProvides {
|
|
|
8
8
|
api: ApiClient;
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
-
export declare const apiPlugin: Plugin<{},
|
|
12
|
-
{}, // requires no context
|
|
13
|
-
ApiPluginProvides>;
|
|
11
|
+
export declare const apiPlugin: Plugin<{}, {}, ApiPluginProvides>;
|
|
14
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/api/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC;KAChB,CAAC;CACH;AAGD,eAAO,MAAM,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/api/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE;QACP,GAAG,EAAE,SAAS,CAAC;KAChB,CAAC;CACH;AAGD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,iBAAiB,CA2BvD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event builder utilities for creating telemetry events
|
|
3
|
+
*
|
|
4
|
+
* Provides builder functions that auto-populate common fields and ensure
|
|
5
|
+
* schema compliance for all event types.
|
|
6
|
+
*/
|
|
7
|
+
import type { ErrorOccurredEvent, ApplicationLifecycleEvent, BaseEvent } from "../../types/telemetry-events";
|
|
8
|
+
import type { ApplicationLifecycleEventData, EnhancedErrorEventData, ErrorEventData, EventContext } from "./types";
|
|
9
|
+
export declare function createBaseEvent(context?: EventContext): BaseEvent;
|
|
10
|
+
export declare function buildErrorEvent(data: ErrorEventData, context?: EventContext): ErrorOccurredEvent;
|
|
11
|
+
export declare function buildApplicationLifecycleEvent(data: ApplicationLifecycleEventData, context?: EventContext): ApplicationLifecycleEvent;
|
|
12
|
+
export declare function buildErrorEventWithContext(data: EnhancedErrorEventData, context?: EventContext): ErrorOccurredEvent;
|
|
13
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/builders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,SAAS,EACV,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,6BAA6B,EAC7B,sBAAsB,EACtB,cAAc,EACd,YAAY,EACb,MAAM,SAAS,CAAC;AAgBjB,wBAAgB,eAAe,CAAC,OAAO,GAAE,YAAiB,GAAG,SAAS,CAWrE;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,cAAc,EACpB,OAAO,GAAE,YAAiB,GACzB,kBAAkB,CAYpB;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,6BAA6B,EACnC,OAAO,GAAE,YAAiB,GACzB,yBAAyB,CA0B3B;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,GAAE,YAAiB,GACzB,kBAAkB,CAiBpB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event builder utilities for creating telemetry events
|
|
3
|
+
*
|
|
4
|
+
* Provides builder functions that auto-populate common fields and ensure
|
|
5
|
+
* schema compliance for all event types.
|
|
6
|
+
*/
|
|
7
|
+
import { generateEventId, getCurrentTimestamp, getReleaseId, getOsInfo, getPlatformVersions, getMemoryUsage, getCpuTime, isCi, getCiPlatform, } from "./utils";
|
|
8
|
+
import sdkPackageJson from "../../../package.json";
|
|
9
|
+
// Create base event with auto-populated common fields
|
|
10
|
+
// Kept for backward compatibility but can be replaced with direct construction
|
|
11
|
+
export function createBaseEvent(context = {}) {
|
|
12
|
+
return {
|
|
13
|
+
event_id: generateEventId(),
|
|
14
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
15
|
+
release_id: getReleaseId(),
|
|
16
|
+
customuser_id: context.customuser_id,
|
|
17
|
+
account_id: context.account_id,
|
|
18
|
+
identity_id: context.identity_id,
|
|
19
|
+
visitor_id: context.visitor_id,
|
|
20
|
+
correlation_id: context.correlation_id,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function buildErrorEvent(data, context = {}) {
|
|
24
|
+
return {
|
|
25
|
+
...createBaseEvent(context),
|
|
26
|
+
zap_id: context.zap_id,
|
|
27
|
+
node_id: context.node_id,
|
|
28
|
+
selected_api: context.selected_api,
|
|
29
|
+
app_id: context.app_id,
|
|
30
|
+
app_version_id: context.app_version_id,
|
|
31
|
+
environment: context.environment,
|
|
32
|
+
sdk_version: sdkPackageJson.version,
|
|
33
|
+
...data,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function buildApplicationLifecycleEvent(data, context = {}) {
|
|
37
|
+
const osInfo = getOsInfo();
|
|
38
|
+
const platformVersions = getPlatformVersions();
|
|
39
|
+
return {
|
|
40
|
+
...createBaseEvent(context),
|
|
41
|
+
selected_api: context.selected_api,
|
|
42
|
+
app_id: context.app_id,
|
|
43
|
+
app_version_id: context.app_version_id,
|
|
44
|
+
sdk_version: sdkPackageJson.version,
|
|
45
|
+
cli_version: null,
|
|
46
|
+
memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
|
|
47
|
+
peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
|
|
48
|
+
cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
|
|
49
|
+
os_platform: osInfo.platform,
|
|
50
|
+
os_release: osInfo.release,
|
|
51
|
+
os_architecture: osInfo.architecture,
|
|
52
|
+
platform_versions: platformVersions,
|
|
53
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
54
|
+
is_ci_environment: isCi(),
|
|
55
|
+
ci_platform: getCiPlatform(),
|
|
56
|
+
session_id: null,
|
|
57
|
+
metadata: null,
|
|
58
|
+
process_argv: process.argv || null,
|
|
59
|
+
...data,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function buildErrorEventWithContext(data, context = {}) {
|
|
63
|
+
const executionTime = data.execution_start_time
|
|
64
|
+
? Date.now() - data.execution_start_time
|
|
65
|
+
: null;
|
|
66
|
+
return {
|
|
67
|
+
...createBaseEvent(context),
|
|
68
|
+
zap_id: context.zap_id,
|
|
69
|
+
node_id: context.node_id,
|
|
70
|
+
selected_api: context.selected_api,
|
|
71
|
+
app_id: context.app_id,
|
|
72
|
+
app_version_id: context.app_version_id,
|
|
73
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
74
|
+
sdk_version: sdkPackageJson.version,
|
|
75
|
+
execution_time_before_error_ms: executionTime,
|
|
76
|
+
...data,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Emission Plugin for Zapier SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides silent telemetry event emission capability to the SDK.
|
|
5
|
+
* All events are emitted asynchronously and failures are silently handled.
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from "../../types/plugin";
|
|
8
|
+
import type { BaseEvent } from "../../types/telemetry-events";
|
|
9
|
+
import type { EventTransport, TransportConfig } from "./transport";
|
|
10
|
+
export interface EventEmissionConfig {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
transport?: TransportConfig;
|
|
13
|
+
}
|
|
14
|
+
export interface EventEmissionContext {
|
|
15
|
+
eventEmission: {
|
|
16
|
+
transport: EventTransport;
|
|
17
|
+
config: EventEmissionConfig;
|
|
18
|
+
emit<T extends any>(subject: string, event: T): void;
|
|
19
|
+
createBaseEvent(): BaseEvent;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface EventEmissionProvides {
|
|
23
|
+
context: EventEmissionContext;
|
|
24
|
+
}
|
|
25
|
+
export declare const eventEmissionPlugin: Plugin<{}, {
|
|
26
|
+
options: {
|
|
27
|
+
eventEmission?: EventEmissionConfig;
|
|
28
|
+
};
|
|
29
|
+
}, EventEmissionProvides>;
|
|
30
|
+
export type { EventContext, ApplicationLifecycleEventData, EnhancedErrorEventData, } from "./types";
|
|
31
|
+
export { buildApplicationLifecycleEvent, buildErrorEventWithContext, buildErrorEvent, createBaseEvent, } from "./builders";
|
|
32
|
+
export type { BaseEvent } from "../../types/telemetry-events";
|
|
33
|
+
export * from "./utils";
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAUnE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE;QACb,SAAS,EAAE,cAAc,CAAC;QAC1B,MAAM,EAAE,mBAAmB,CAAC;QAE5B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAErD,eAAe,IAAI,SAAS,CAAC;KAC9B,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AA4CD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,EAAE,EACF;IAAE,OAAO,EAAE;QAAE,aAAa,CAAC,EAAE,mBAAmB,CAAA;KAAE,CAAA;CAAE,EACpD,qBAAqB,CAiMtB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,cAAc,SAAS,CAAC"}
|