@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.
- package/CHANGELOG.md +12 -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 +457 -11
- package/dist/index.d.mts +389 -158
- 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 +428 -15
- 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/index.test.js +3 -1
- package/dist/plugins/listActions/schemas.d.ts +2 -2
- package/dist/plugins/listAuthentications/index.test.js +3 -1
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +4 -4
- package/dist/plugins/listInputFields/schemas.d.ts +2 -2
- package/dist/plugins/manifest/index.d.ts +9 -1
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +19 -7
- package/dist/plugins/manifest/index.test.js +4 -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 +3 -3
- 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/plugins/listActions/index.test.ts +3 -1
- package/src/plugins/listAuthentications/index.test.ts +3 -1
- package/src/plugins/manifest/index.test.ts +4 -4
- package/src/plugins/manifest/index.ts +39 -14
- 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) => ({
|
|
@@ -2822,8 +2825,15 @@ var manifestPlugin = (params) => {
|
|
|
2822
2825
|
if (!resolvedApp) return null;
|
|
2823
2826
|
return `${resolvedApp.implementationName}@${resolvedApp.version || "latest"}`;
|
|
2824
2827
|
};
|
|
2825
|
-
const updateManifestEntry = async (
|
|
2826
|
-
const
|
|
2828
|
+
const updateManifestEntry = async (options2) => {
|
|
2829
|
+
const {
|
|
2830
|
+
appKey,
|
|
2831
|
+
entry,
|
|
2832
|
+
configPath = DEFAULT_CONFIG_PATH,
|
|
2833
|
+
skipWrite = false,
|
|
2834
|
+
manifest: inputManifest
|
|
2835
|
+
} = options2;
|
|
2836
|
+
const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
|
|
2827
2837
|
let existingEntry = findManifestEntry({
|
|
2828
2838
|
appKey,
|
|
2829
2839
|
manifest: manifest2
|
|
@@ -2854,10 +2864,18 @@ var manifestPlugin = (params) => {
|
|
|
2854
2864
|
api
|
|
2855
2865
|
});
|
|
2856
2866
|
}
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2867
|
+
const updatedManifest = {
|
|
2868
|
+
...manifest2,
|
|
2869
|
+
apps: {
|
|
2870
|
+
...manifest2.apps,
|
|
2871
|
+
[manifestKey]: entry
|
|
2872
|
+
}
|
|
2873
|
+
};
|
|
2874
|
+
if (!skipWrite) {
|
|
2875
|
+
await writeManifestToFile(updatedManifest, configPath);
|
|
2876
|
+
resolvedManifest = void 0;
|
|
2877
|
+
}
|
|
2878
|
+
return [manifestKey, entry, updatedManifest];
|
|
2861
2879
|
};
|
|
2862
2880
|
return {
|
|
2863
2881
|
context: {
|
|
@@ -3160,7 +3178,7 @@ async function pollUntilComplete(options) {
|
|
|
3160
3178
|
// Up to timeout + 10s: poll every 10s
|
|
3161
3179
|
];
|
|
3162
3180
|
if (initialDelay > 0) {
|
|
3163
|
-
await setTimeout(initialDelay);
|
|
3181
|
+
await setTimeout$1(initialDelay);
|
|
3164
3182
|
}
|
|
3165
3183
|
while (true) {
|
|
3166
3184
|
attempts++;
|
|
@@ -3180,7 +3198,7 @@ async function pollUntilComplete(options) {
|
|
|
3180
3198
|
}
|
|
3181
3199
|
if (attempts > 1) {
|
|
3182
3200
|
const waitTime = calculateWaitTime(pollingInterval[1], errorCount);
|
|
3183
|
-
await setTimeout(waitTime);
|
|
3201
|
+
await setTimeout$1(waitTime);
|
|
3184
3202
|
}
|
|
3185
3203
|
try {
|
|
3186
3204
|
const response = await fetchPoll();
|
|
@@ -3809,6 +3827,401 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
3809
3827
|
};
|
|
3810
3828
|
};
|
|
3811
3829
|
|
|
3830
|
+
// src/plugins/eventEmission/transport.ts
|
|
3831
|
+
var DEFAULT_RETRY_ATTEMPTS = 2;
|
|
3832
|
+
var DEFAULT_RETRY_DELAY_MS = 300;
|
|
3833
|
+
var HttpTransport = class {
|
|
3834
|
+
constructor(config) {
|
|
3835
|
+
this.config = config;
|
|
3836
|
+
}
|
|
3837
|
+
async emit(subject, event) {
|
|
3838
|
+
try {
|
|
3839
|
+
await this.emitWithRetry(
|
|
3840
|
+
subject,
|
|
3841
|
+
event,
|
|
3842
|
+
this.config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
|
|
3843
|
+
);
|
|
3844
|
+
} catch {
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3847
|
+
async emitWithRetry(subject, event, attemptsLeft) {
|
|
3848
|
+
try {
|
|
3849
|
+
const payload = {
|
|
3850
|
+
subject,
|
|
3851
|
+
properties: event
|
|
3852
|
+
};
|
|
3853
|
+
const response = await fetch(this.config.endpoint, {
|
|
3854
|
+
method: "POST",
|
|
3855
|
+
headers: {
|
|
3856
|
+
"Content-Type": "application/json",
|
|
3857
|
+
...this.config.headers
|
|
3858
|
+
},
|
|
3859
|
+
body: JSON.stringify(payload)
|
|
3860
|
+
});
|
|
3861
|
+
if (!response.ok && attemptsLeft > 1) {
|
|
3862
|
+
await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
3863
|
+
return this.emitWithRetry(subject, event, attemptsLeft - 1);
|
|
3864
|
+
}
|
|
3865
|
+
} catch (error) {
|
|
3866
|
+
if (attemptsLeft > 1) {
|
|
3867
|
+
await this.delay(this.config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
3868
|
+
return this.emitWithRetry(subject, event, attemptsLeft - 1);
|
|
3869
|
+
}
|
|
3870
|
+
throw error;
|
|
3871
|
+
}
|
|
3872
|
+
}
|
|
3873
|
+
async delay(ms) {
|
|
3874
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
3875
|
+
}
|
|
3876
|
+
};
|
|
3877
|
+
var ConsoleTransport = class {
|
|
3878
|
+
async emit(subject, event) {
|
|
3879
|
+
try {
|
|
3880
|
+
console.log(
|
|
3881
|
+
"[SDK Telemetry]",
|
|
3882
|
+
JSON.stringify({ subject, properties: event }, null, 2)
|
|
3883
|
+
);
|
|
3884
|
+
} catch {
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
};
|
|
3888
|
+
var NoopTransport = class {
|
|
3889
|
+
async emit(_subject, _event) {
|
|
3890
|
+
}
|
|
3891
|
+
};
|
|
3892
|
+
function createTransport(config) {
|
|
3893
|
+
try {
|
|
3894
|
+
switch (config.type) {
|
|
3895
|
+
case "http":
|
|
3896
|
+
if (!config.endpoint) {
|
|
3897
|
+
throw new Error("HTTP transport requires endpoint");
|
|
3898
|
+
}
|
|
3899
|
+
return new HttpTransport({
|
|
3900
|
+
endpoint: config.endpoint,
|
|
3901
|
+
headers: config.headers,
|
|
3902
|
+
retryAttempts: config.retryAttempts,
|
|
3903
|
+
retryDelayMs: config.retryDelayMs
|
|
3904
|
+
});
|
|
3905
|
+
case "console":
|
|
3906
|
+
return new ConsoleTransport();
|
|
3907
|
+
case "noop":
|
|
3908
|
+
default:
|
|
3909
|
+
return new NoopTransport();
|
|
3910
|
+
}
|
|
3911
|
+
} catch {
|
|
3912
|
+
return new NoopTransport();
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
function generateEventId() {
|
|
3916
|
+
return crypto.randomUUID();
|
|
3917
|
+
}
|
|
3918
|
+
function getCurrentTimestamp() {
|
|
3919
|
+
return Date.now();
|
|
3920
|
+
}
|
|
3921
|
+
function getReleaseId() {
|
|
3922
|
+
return process?.env?.SDK_RELEASE_ID || "development";
|
|
3923
|
+
}
|
|
3924
|
+
function getOsInfo() {
|
|
3925
|
+
try {
|
|
3926
|
+
return {
|
|
3927
|
+
platform: os.platform() || null,
|
|
3928
|
+
release: os.release() || null,
|
|
3929
|
+
architecture: os.arch() || null
|
|
3930
|
+
};
|
|
3931
|
+
} catch {
|
|
3932
|
+
return {
|
|
3933
|
+
platform: null,
|
|
3934
|
+
release: null,
|
|
3935
|
+
architecture: null
|
|
3936
|
+
};
|
|
3937
|
+
}
|
|
3938
|
+
}
|
|
3939
|
+
function getPlatformVersions() {
|
|
3940
|
+
const versions = {};
|
|
3941
|
+
if (typeof process?.versions === "object") {
|
|
3942
|
+
for (const [key, value] of Object.entries(process.versions)) {
|
|
3943
|
+
versions[key] = value || null;
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
return versions;
|
|
3947
|
+
}
|
|
3948
|
+
function isCi() {
|
|
3949
|
+
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);
|
|
3950
|
+
}
|
|
3951
|
+
function getCiPlatform() {
|
|
3952
|
+
if (process?.env?.GITHUB_ACTIONS) return "github-actions";
|
|
3953
|
+
if (process?.env?.JENKINS_URL) return "jenkins";
|
|
3954
|
+
if (process?.env?.GITLAB_CI) return "gitlab-ci";
|
|
3955
|
+
if (process?.env?.CIRCLECI) return "circleci";
|
|
3956
|
+
if (process?.env?.TRAVIS) return "travis";
|
|
3957
|
+
if (process?.env?.BUILDKITE) return "buildkite";
|
|
3958
|
+
if (process?.env?.DRONE) return "drone";
|
|
3959
|
+
if (process?.env?.BITBUCKET_PIPELINES_UUID) return "bitbucket-pipelines";
|
|
3960
|
+
if (process?.env?.CI || process?.env?.CONTINUOUS_INTEGRATION)
|
|
3961
|
+
return "unknown-ci";
|
|
3962
|
+
return null;
|
|
3963
|
+
}
|
|
3964
|
+
function getMemoryUsage() {
|
|
3965
|
+
if (process?.memoryUsage) {
|
|
3966
|
+
const usage = process.memoryUsage();
|
|
3967
|
+
return usage.rss || null;
|
|
3968
|
+
}
|
|
3969
|
+
return null;
|
|
3970
|
+
}
|
|
3971
|
+
function getCpuTime() {
|
|
3972
|
+
if (process?.cpuUsage) {
|
|
3973
|
+
const usage = process.cpuUsage();
|
|
3974
|
+
return Math.round((usage.user + usage.system) / 1e3);
|
|
3975
|
+
}
|
|
3976
|
+
return null;
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
// package.json
|
|
3980
|
+
var package_default = {
|
|
3981
|
+
version: "0.13.5"};
|
|
3982
|
+
|
|
3983
|
+
// src/plugins/eventEmission/builders.ts
|
|
3984
|
+
function createBaseEvent(context = {}) {
|
|
3985
|
+
return {
|
|
3986
|
+
event_id: generateEventId(),
|
|
3987
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
3988
|
+
release_id: getReleaseId(),
|
|
3989
|
+
customuser_id: context.customuser_id,
|
|
3990
|
+
account_id: context.account_id,
|
|
3991
|
+
identity_id: context.identity_id,
|
|
3992
|
+
visitor_id: context.visitor_id,
|
|
3993
|
+
correlation_id: context.correlation_id
|
|
3994
|
+
};
|
|
3995
|
+
}
|
|
3996
|
+
function buildErrorEvent(data, context = {}) {
|
|
3997
|
+
return {
|
|
3998
|
+
...createBaseEvent(context),
|
|
3999
|
+
zap_id: context.zap_id,
|
|
4000
|
+
node_id: context.node_id,
|
|
4001
|
+
selected_api: context.selected_api,
|
|
4002
|
+
app_id: context.app_id,
|
|
4003
|
+
app_version_id: context.app_version_id,
|
|
4004
|
+
environment: context.environment,
|
|
4005
|
+
sdk_version: package_default.version,
|
|
4006
|
+
...data
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
function buildApplicationLifecycleEvent(data, context = {}) {
|
|
4010
|
+
const osInfo = getOsInfo();
|
|
4011
|
+
const platformVersions = getPlatformVersions();
|
|
4012
|
+
return {
|
|
4013
|
+
...createBaseEvent(context),
|
|
4014
|
+
selected_api: context.selected_api,
|
|
4015
|
+
app_id: context.app_id,
|
|
4016
|
+
app_version_id: context.app_version_id,
|
|
4017
|
+
sdk_version: package_default.version,
|
|
4018
|
+
cli_version: null,
|
|
4019
|
+
memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
|
|
4020
|
+
peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
|
|
4021
|
+
cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
|
|
4022
|
+
os_platform: osInfo.platform,
|
|
4023
|
+
os_release: osInfo.release,
|
|
4024
|
+
os_architecture: osInfo.architecture,
|
|
4025
|
+
platform_versions: platformVersions,
|
|
4026
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
4027
|
+
is_ci_environment: isCi(),
|
|
4028
|
+
ci_platform: getCiPlatform(),
|
|
4029
|
+
session_id: null,
|
|
4030
|
+
metadata: null,
|
|
4031
|
+
process_argv: process.argv || null,
|
|
4032
|
+
...data
|
|
4033
|
+
};
|
|
4034
|
+
}
|
|
4035
|
+
function buildErrorEventWithContext(data, context = {}) {
|
|
4036
|
+
const executionTime = data.execution_start_time ? Date.now() - data.execution_start_time : null;
|
|
4037
|
+
return {
|
|
4038
|
+
...createBaseEvent(context),
|
|
4039
|
+
zap_id: context.zap_id,
|
|
4040
|
+
node_id: context.node_id,
|
|
4041
|
+
selected_api: context.selected_api,
|
|
4042
|
+
app_id: context.app_id,
|
|
4043
|
+
app_version_id: context.app_version_id,
|
|
4044
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
4045
|
+
sdk_version: package_default.version,
|
|
4046
|
+
execution_time_before_error_ms: executionTime,
|
|
4047
|
+
...data
|
|
4048
|
+
};
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
// src/plugins/eventEmission/index.ts
|
|
4052
|
+
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4053
|
+
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
4054
|
+
async function silentEmit(transport, subject, event) {
|
|
4055
|
+
try {
|
|
4056
|
+
transport.emit(subject, event).catch(() => {
|
|
4057
|
+
});
|
|
4058
|
+
} catch {
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
function getTransportConfig() {
|
|
4062
|
+
const envTransport = process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT;
|
|
4063
|
+
if (envTransport === "noop" || envTransport === "disabled") {
|
|
4064
|
+
return { type: "noop" };
|
|
4065
|
+
}
|
|
4066
|
+
if (envTransport === "console") {
|
|
4067
|
+
return { type: "console" };
|
|
4068
|
+
}
|
|
4069
|
+
const endpoint = process?.env?.ZAPIER_SDK_TELEMETRY_ENDPOINT || TRACKING_API_ENDPOINT;
|
|
4070
|
+
return {
|
|
4071
|
+
type: "http",
|
|
4072
|
+
endpoint
|
|
4073
|
+
};
|
|
4074
|
+
}
|
|
4075
|
+
var eventEmissionPlugin = ({ context }) => {
|
|
4076
|
+
const defaultTransport = getTransportConfig();
|
|
4077
|
+
const config = {
|
|
4078
|
+
enabled: context.options.eventEmission?.enabled ?? true,
|
|
4079
|
+
transport: (
|
|
4080
|
+
// If env var is set, use it (defaultTransport will be from env)
|
|
4081
|
+
process?.env?.ZAPIER_SDK_TELEMETRY_TRANSPORT ? defaultTransport : (
|
|
4082
|
+
// Otherwise, use option transport or default
|
|
4083
|
+
context.options.eventEmission?.transport ?? defaultTransport
|
|
4084
|
+
)
|
|
4085
|
+
)
|
|
4086
|
+
};
|
|
4087
|
+
const startupTime = Date.now();
|
|
4088
|
+
let shutdownStartTime = null;
|
|
4089
|
+
if (!config.enabled) {
|
|
4090
|
+
return {
|
|
4091
|
+
context: {
|
|
4092
|
+
eventEmission: {
|
|
4093
|
+
transport: createTransport({ type: "noop" }),
|
|
4094
|
+
config,
|
|
4095
|
+
emit: () => {
|
|
4096
|
+
},
|
|
4097
|
+
createBaseEvent: () => ({
|
|
4098
|
+
event_id: generateEventId(),
|
|
4099
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4100
|
+
release_id: getReleaseId(),
|
|
4101
|
+
customuser_id: null,
|
|
4102
|
+
account_id: null,
|
|
4103
|
+
identity_id: null,
|
|
4104
|
+
visitor_id: null,
|
|
4105
|
+
correlation_id: null
|
|
4106
|
+
})
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
};
|
|
4110
|
+
}
|
|
4111
|
+
let transport;
|
|
4112
|
+
try {
|
|
4113
|
+
transport = createTransport(config.transport || { type: "noop" });
|
|
4114
|
+
} catch {
|
|
4115
|
+
transport = createTransport({ type: "noop" });
|
|
4116
|
+
}
|
|
4117
|
+
const createBaseEventHelper = () => ({
|
|
4118
|
+
event_id: generateEventId(),
|
|
4119
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4120
|
+
release_id: getReleaseId(),
|
|
4121
|
+
customuser_id: null,
|
|
4122
|
+
account_id: null,
|
|
4123
|
+
identity_id: null,
|
|
4124
|
+
visitor_id: null,
|
|
4125
|
+
correlation_id: null
|
|
4126
|
+
});
|
|
4127
|
+
if (config.enabled) {
|
|
4128
|
+
const startupEvent = buildApplicationLifecycleEvent({
|
|
4129
|
+
lifecycle_event_type: "startup"
|
|
4130
|
+
});
|
|
4131
|
+
silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, startupEvent);
|
|
4132
|
+
if (typeof process?.on === "function") {
|
|
4133
|
+
process.on("exit", (code) => {
|
|
4134
|
+
const uptime = Date.now() - startupTime;
|
|
4135
|
+
const shutdownDuration = shutdownStartTime ? Date.now() - shutdownStartTime : null;
|
|
4136
|
+
const exitEvent = buildApplicationLifecycleEvent({
|
|
4137
|
+
lifecycle_event_type: "exit",
|
|
4138
|
+
exit_code: code,
|
|
4139
|
+
uptime_ms: uptime,
|
|
4140
|
+
is_graceful_shutdown: code === 0,
|
|
4141
|
+
shutdown_duration_ms: shutdownDuration
|
|
4142
|
+
});
|
|
4143
|
+
silentEmit(transport, APPLICATION_LIFECYCLE_EVENT_SUBJECT, exitEvent);
|
|
4144
|
+
});
|
|
4145
|
+
process.on("uncaughtException", async (error) => {
|
|
4146
|
+
const errorEvent = buildErrorEventWithContext({
|
|
4147
|
+
error_message: error.message || "Unknown error",
|
|
4148
|
+
error_type: "UncaughtException",
|
|
4149
|
+
error_stack_trace: error.stack || null,
|
|
4150
|
+
error_severity: "critical",
|
|
4151
|
+
is_user_facing: false,
|
|
4152
|
+
is_recoverable: false,
|
|
4153
|
+
execution_start_time: startupTime
|
|
4154
|
+
});
|
|
4155
|
+
try {
|
|
4156
|
+
await Promise.race([
|
|
4157
|
+
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4158
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4159
|
+
]);
|
|
4160
|
+
} catch {
|
|
4161
|
+
}
|
|
4162
|
+
});
|
|
4163
|
+
process.on(
|
|
4164
|
+
"unhandledRejection",
|
|
4165
|
+
async (reason, promise) => {
|
|
4166
|
+
const errorMessage = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
4167
|
+
const errorStack = reason instanceof Error ? reason.stack : null;
|
|
4168
|
+
const errorEvent = buildErrorEventWithContext({
|
|
4169
|
+
error_message: errorMessage,
|
|
4170
|
+
error_type: "UnhandledRejection",
|
|
4171
|
+
error_stack_trace: errorStack,
|
|
4172
|
+
error_severity: "critical",
|
|
4173
|
+
is_user_facing: false,
|
|
4174
|
+
is_recoverable: false,
|
|
4175
|
+
execution_start_time: startupTime,
|
|
4176
|
+
error_metadata: {
|
|
4177
|
+
promise: String(promise)
|
|
4178
|
+
}
|
|
4179
|
+
});
|
|
4180
|
+
try {
|
|
4181
|
+
await Promise.race([
|
|
4182
|
+
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4183
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4184
|
+
]);
|
|
4185
|
+
} catch {
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
);
|
|
4189
|
+
const handleSignal = async (signal) => {
|
|
4190
|
+
shutdownStartTime = Date.now();
|
|
4191
|
+
const uptime = Date.now() - startupTime;
|
|
4192
|
+
const signalEvent = buildApplicationLifecycleEvent({
|
|
4193
|
+
lifecycle_event_type: "signal_termination",
|
|
4194
|
+
signal_name: signal,
|
|
4195
|
+
uptime_ms: uptime,
|
|
4196
|
+
is_graceful_shutdown: true
|
|
4197
|
+
});
|
|
4198
|
+
try {
|
|
4199
|
+
await Promise.race([
|
|
4200
|
+
transport.emit(APPLICATION_LIFECYCLE_EVENT_SUBJECT, signalEvent),
|
|
4201
|
+
new Promise((resolve2) => setTimeout(resolve2, 300))
|
|
4202
|
+
]);
|
|
4203
|
+
} catch {
|
|
4204
|
+
}
|
|
4205
|
+
};
|
|
4206
|
+
["SIGINT", "SIGTERM"].forEach((signal) => {
|
|
4207
|
+
process.on(signal, () => handleSignal(signal));
|
|
4208
|
+
});
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
return {
|
|
4212
|
+
context: {
|
|
4213
|
+
eventEmission: {
|
|
4214
|
+
transport,
|
|
4215
|
+
config,
|
|
4216
|
+
emit: (subject, event) => {
|
|
4217
|
+
silentEmit(transport, subject, event);
|
|
4218
|
+
},
|
|
4219
|
+
createBaseEvent: createBaseEventHelper
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
};
|
|
4223
|
+
};
|
|
4224
|
+
|
|
3812
4225
|
// src/sdk.ts
|
|
3813
4226
|
function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
|
|
3814
4227
|
return {
|
|
@@ -3858,10 +4271,10 @@ function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} })
|
|
|
3858
4271
|
};
|
|
3859
4272
|
}
|
|
3860
4273
|
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);
|
|
4274
|
+
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
4275
|
}
|
|
3863
4276
|
function createZapierSdk(options = {}) {
|
|
3864
4277
|
return createZapierSdkWithoutRegistry(options).addPlugin(registryPlugin);
|
|
3865
4278
|
}
|
|
3866
4279
|
|
|
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 };
|
|
4280
|
+
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
|