@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/schemas/App.d.ts
CHANGED
|
@@ -63,19 +63,19 @@ export declare const AppItemSchema: z.ZodObject<Omit<{
|
|
|
63
63
|
search_and_write: z.ZodOptional<z.ZodNumber>;
|
|
64
64
|
filter: z.ZodOptional<z.ZodNumber>;
|
|
65
65
|
}, "strip", z.ZodTypeAny, {
|
|
66
|
+
search?: number | undefined;
|
|
66
67
|
filter?: number | undefined;
|
|
67
68
|
read?: number | undefined;
|
|
68
69
|
read_bulk?: number | undefined;
|
|
69
70
|
write?: number | undefined;
|
|
70
|
-
search?: number | undefined;
|
|
71
71
|
search_or_write?: number | undefined;
|
|
72
72
|
search_and_write?: number | undefined;
|
|
73
73
|
}, {
|
|
74
|
+
search?: number | undefined;
|
|
74
75
|
filter?: number | undefined;
|
|
75
76
|
read?: number | undefined;
|
|
76
77
|
read_bulk?: number | undefined;
|
|
77
78
|
write?: number | undefined;
|
|
78
|
-
search?: number | undefined;
|
|
79
79
|
search_or_write?: number | undefined;
|
|
80
80
|
search_and_write?: number | undefined;
|
|
81
81
|
}>>;
|
|
@@ -94,16 +94,25 @@ export declare const AppItemSchema: z.ZodObject<Omit<{
|
|
|
94
94
|
title: string;
|
|
95
95
|
slug: string;
|
|
96
96
|
implementation_id: string;
|
|
97
|
-
description?: string | undefined;
|
|
98
|
-
is_hidden?: boolean | undefined;
|
|
99
|
-
age_in_days?: number | undefined;
|
|
100
|
-
api_docs_url?: string | undefined;
|
|
101
|
-
banner?: string | undefined;
|
|
102
97
|
categories?: {
|
|
103
98
|
id: number;
|
|
104
99
|
name: string;
|
|
105
100
|
slug: string;
|
|
106
101
|
}[] | undefined;
|
|
102
|
+
actions?: {
|
|
103
|
+
search?: number | undefined;
|
|
104
|
+
filter?: number | undefined;
|
|
105
|
+
read?: number | undefined;
|
|
106
|
+
read_bulk?: number | undefined;
|
|
107
|
+
write?: number | undefined;
|
|
108
|
+
search_or_write?: number | undefined;
|
|
109
|
+
search_and_write?: number | undefined;
|
|
110
|
+
} | undefined;
|
|
111
|
+
description?: string | undefined;
|
|
112
|
+
is_hidden?: boolean | undefined;
|
|
113
|
+
age_in_days?: number | undefined;
|
|
114
|
+
api_docs_url?: string | undefined;
|
|
115
|
+
banner?: string | undefined;
|
|
107
116
|
image?: string | undefined;
|
|
108
117
|
images?: {
|
|
109
118
|
url_16x16?: string | undefined;
|
|
@@ -120,15 +129,6 @@ export declare const AppItemSchema: z.ZodObject<Omit<{
|
|
|
120
129
|
popularity?: number | undefined;
|
|
121
130
|
primary_color?: string | undefined;
|
|
122
131
|
auth_type?: string | undefined;
|
|
123
|
-
actions?: {
|
|
124
|
-
filter?: number | undefined;
|
|
125
|
-
read?: number | undefined;
|
|
126
|
-
read_bulk?: number | undefined;
|
|
127
|
-
write?: number | undefined;
|
|
128
|
-
search?: number | undefined;
|
|
129
|
-
search_or_write?: number | undefined;
|
|
130
|
-
search_and_write?: number | undefined;
|
|
131
|
-
} | undefined;
|
|
132
132
|
is_deprecated?: boolean | undefined;
|
|
133
133
|
secondary_color?: string | undefined;
|
|
134
134
|
has_filters?: boolean | undefined;
|
|
@@ -146,16 +146,25 @@ export declare const AppItemSchema: z.ZodObject<Omit<{
|
|
|
146
146
|
title: string;
|
|
147
147
|
slug: string;
|
|
148
148
|
implementation_id: string;
|
|
149
|
-
description?: string | undefined;
|
|
150
|
-
is_hidden?: boolean | undefined;
|
|
151
|
-
age_in_days?: number | undefined;
|
|
152
|
-
api_docs_url?: string | undefined;
|
|
153
|
-
banner?: string | undefined;
|
|
154
149
|
categories?: {
|
|
155
150
|
id: number;
|
|
156
151
|
name: string;
|
|
157
152
|
slug: string;
|
|
158
153
|
}[] | undefined;
|
|
154
|
+
actions?: {
|
|
155
|
+
search?: number | undefined;
|
|
156
|
+
filter?: number | undefined;
|
|
157
|
+
read?: number | undefined;
|
|
158
|
+
read_bulk?: number | undefined;
|
|
159
|
+
write?: number | undefined;
|
|
160
|
+
search_or_write?: number | undefined;
|
|
161
|
+
search_and_write?: number | undefined;
|
|
162
|
+
} | undefined;
|
|
163
|
+
description?: string | undefined;
|
|
164
|
+
is_hidden?: boolean | undefined;
|
|
165
|
+
age_in_days?: number | undefined;
|
|
166
|
+
api_docs_url?: string | undefined;
|
|
167
|
+
banner?: string | undefined;
|
|
159
168
|
image?: string | undefined;
|
|
160
169
|
images?: {
|
|
161
170
|
url_16x16?: string | undefined;
|
|
@@ -172,15 +181,6 @@ export declare const AppItemSchema: z.ZodObject<Omit<{
|
|
|
172
181
|
popularity?: number | undefined;
|
|
173
182
|
primary_color?: string | undefined;
|
|
174
183
|
auth_type?: string | undefined;
|
|
175
|
-
actions?: {
|
|
176
|
-
filter?: number | undefined;
|
|
177
|
-
read?: number | undefined;
|
|
178
|
-
read_bulk?: number | undefined;
|
|
179
|
-
write?: number | undefined;
|
|
180
|
-
search?: number | undefined;
|
|
181
|
-
search_or_write?: number | undefined;
|
|
182
|
-
search_and_write?: number | undefined;
|
|
183
|
-
} | undefined;
|
|
184
184
|
is_deprecated?: boolean | undefined;
|
|
185
185
|
secondary_color?: string | undefined;
|
|
186
186
|
has_filters?: boolean | undefined;
|
package/dist/sdk.d.ts
CHANGED
|
@@ -13,14 +13,14 @@ export declare function createSdk<TCurrentSdk = {}, TCurrentContext extends {
|
|
|
13
13
|
getContext(): TCurrentContext;
|
|
14
14
|
}, TRequiresContext, TProvides>, addPluginOptions?: Record<string, unknown>): Sdk<TCurrentSdk & ExtractSdkProperties<TProvides>, TCurrentContext & NonNullable<ExtractContextProperties<TProvides>>>;
|
|
15
15
|
};
|
|
16
|
-
export declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk<ExtractSdkProperties<import(".").ApiPluginProvides> & ExtractSdkProperties<import(".").ManifestPluginProvides> & ExtractSdkProperties<import(".").ListAppsPluginProvides> & ExtractSdkProperties<import(".").GetAppPluginProvides> & ExtractSdkProperties<import(".").ListActionsPluginProvides> & ExtractSdkProperties<import(".").GetActionPluginProvides> & ExtractSdkProperties<import(".").ListInputFieldsPluginProvides> & ExtractSdkProperties<import("./plugins/listInputFieldChoices").ListInputFieldChoicesPluginProvides> & ExtractSdkProperties<import(".").RunActionPluginProvides> & ExtractSdkProperties<import(".").ListAuthenticationsPluginProvides> & ExtractSdkProperties<import(".").GetAuthenticationPluginProvides> & ExtractSdkProperties<import(".").FindFirstAuthenticationPluginProvides> & ExtractSdkProperties<import(".").FindUniqueAuthenticationPluginProvides> & ExtractSdkProperties<import(".").RequestPluginProvides> & ExtractSdkProperties<import(".").FetchPluginProvides> & ExtractSdkProperties<import(".").AppsPluginProvides> & ExtractSdkProperties<import(".").GetProfilePluginProvides>, {
|
|
16
|
+
export declare function createZapierSdkWithoutRegistry(options?: ZapierSdkOptions): Sdk<ExtractSdkProperties<import("./plugins/eventEmission").EventEmissionProvides> & ExtractSdkProperties<import(".").ApiPluginProvides> & ExtractSdkProperties<import(".").ManifestPluginProvides> & ExtractSdkProperties<import(".").ListAppsPluginProvides> & ExtractSdkProperties<import(".").GetAppPluginProvides> & ExtractSdkProperties<import(".").ListActionsPluginProvides> & ExtractSdkProperties<import(".").GetActionPluginProvides> & ExtractSdkProperties<import(".").ListInputFieldsPluginProvides> & ExtractSdkProperties<import("./plugins/listInputFieldChoices").ListInputFieldChoicesPluginProvides> & ExtractSdkProperties<import(".").RunActionPluginProvides> & ExtractSdkProperties<import(".").ListAuthenticationsPluginProvides> & ExtractSdkProperties<import(".").GetAuthenticationPluginProvides> & ExtractSdkProperties<import(".").FindFirstAuthenticationPluginProvides> & ExtractSdkProperties<import(".").FindUniqueAuthenticationPluginProvides> & ExtractSdkProperties<import(".").RequestPluginProvides> & ExtractSdkProperties<import(".").FetchPluginProvides> & ExtractSdkProperties<import(".").AppsPluginProvides> & ExtractSdkProperties<import(".").GetProfilePluginProvides>, {
|
|
17
17
|
meta: Record<string, PluginMeta>;
|
|
18
|
-
} & {
|
|
18
|
+
} & import(".").EventEmissionContext & {
|
|
19
19
|
api: import("./api").ApiClient;
|
|
20
20
|
} & {
|
|
21
21
|
getVersionedImplementationId: import("./plugins/manifest/schemas").GetVersionedImplementationId;
|
|
22
22
|
resolveAppKeys: import("./plugins/manifest/schemas").ResolveAppKeys;
|
|
23
|
-
updateManifestEntry: (
|
|
23
|
+
updateManifestEntry: (options: import(".").UpdateManifestEntryOptions) => Promise<[string, import(".").ManifestEntry, import(".").Manifest]>;
|
|
24
24
|
} & {
|
|
25
25
|
meta: {
|
|
26
26
|
listApps: {
|
package/dist/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EACV,GAAG,EACH,MAAM,EACN,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACX,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMlD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EACV,GAAG,EACH,MAAM,EACN,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACX,MAAM,gBAAgB,CAAC;AA0BxB,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG;AAG3D,wBAAgB,SAAS,CACvB,WAAW,GAAG,EAAE,EAChB,eAAe,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,GAAG;IAC7D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAClC,EAED,OAAO,GAAE,gBAAqB,EAC9B,UAAU,GAAE,WAA+B,EAC3C,cAAc,GAAE,eAAiD;;cAKrD,gBAAgB,EAAE,SAAS,SAAS,cAAc,UAClD,MAAM,CACZ,WAAW,GAAG;QAAE,UAAU,IAAI,eAAe,CAAA;KAAE,EAC/C,gBAAgB,EAChB,SAAS,CACV,qBACiB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACxC,GAAG,CACJ,WAAW,GAAG,oBAAoB,CAAC,SAAS,CAAC,EAC7C,eAAe,GAAG,WAAW,CAAC,wBAAwB,CAAC,SAAS,CAAC,CAAC,CACnE;EA8DJ;AAED,wBAAgB,8BAA8B,CAAC,OAAO,GAAE,gBAAqB;UApFnE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2HnC;AAED,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAMzE"}
|
package/dist/sdk.js
CHANGED
|
@@ -17,6 +17,7 @@ import { listInputFieldsPlugin } from "./plugins/listInputFields";
|
|
|
17
17
|
import { listInputFieldChoicesPlugin } from "./plugins/listInputFieldChoices";
|
|
18
18
|
import { requestPlugin } from "./plugins/request";
|
|
19
19
|
import { manifestPlugin } from "./plugins/manifest";
|
|
20
|
+
import { eventEmissionPlugin } from "./plugins/eventEmission";
|
|
20
21
|
// Create SDK that supports flat plugins - returns an SDK, not a builder
|
|
21
22
|
export function createSdk(options = {}, initialSdk = {}, initialContext = { meta: {} }) {
|
|
22
23
|
return {
|
|
@@ -74,9 +75,11 @@ export function createSdk(options = {}, initialSdk = {}, initialContext = { meta
|
|
|
74
75
|
}
|
|
75
76
|
export function createZapierSdkWithoutRegistry(options = {}) {
|
|
76
77
|
return (createSdk(options)
|
|
78
|
+
// Event emission (must be first to be available to other plugins)
|
|
79
|
+
.addPlugin(eventEmissionPlugin)
|
|
77
80
|
// Provides the API client in context
|
|
78
81
|
.addPlugin(apiPlugin)
|
|
79
|
-
// Manifest plugin (provides version locking context)
|
|
82
|
+
// Manifest plugin (provides version locking context) - must come after apiPlugin
|
|
80
83
|
.addPlugin(manifestPlugin)
|
|
81
84
|
// Apps/actions/fields
|
|
82
85
|
.addPlugin(listAppsPlugin)
|
package/dist/types/sdk.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* SDK-related types and interfaces
|
|
3
3
|
*/
|
|
4
4
|
import type { EventCallback } from "./events";
|
|
5
|
+
import type { EventEmissionConfig } from "../plugins/eventEmission";
|
|
5
6
|
export interface BaseSdkOptions {
|
|
6
7
|
token?: string;
|
|
7
8
|
getToken?: () => Promise<string | undefined>;
|
|
@@ -18,6 +19,7 @@ export interface BaseSdkOptions {
|
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
21
|
};
|
|
22
|
+
eventEmission?: EventEmissionConfig;
|
|
21
23
|
}
|
|
22
24
|
import type { ListInputFieldsSdkFunction } from "../plugins/listInputFields/schemas";
|
|
23
25
|
import type { GetAuthenticationSdkFunction } from "../plugins/getAuthentication/schemas";
|
|
@@ -27,6 +29,8 @@ import type { RelayRequestSdkFunction } from "../plugins/request/schemas";
|
|
|
27
29
|
import type { z } from "zod";
|
|
28
30
|
import type { RegistryPluginProvides } from "../plugins/registry";
|
|
29
31
|
import type { GetProfilePluginProvides } from "../plugins/getProfile";
|
|
32
|
+
import type { EventEmissionProvides } from "../plugins/eventEmission";
|
|
33
|
+
import type { ApiPluginProvides } from "../plugins/api";
|
|
30
34
|
import type { AppsPluginProvides, ZapierSdkApps } from "../plugins/apps";
|
|
31
35
|
import type { ActionProxy } from "../plugins/apps/schemas";
|
|
32
36
|
import type { FetchPluginProvides } from "../plugins/fetch";
|
|
@@ -61,7 +65,7 @@ export interface FunctionRegistryEntry {
|
|
|
61
65
|
}
|
|
62
66
|
export interface ZapierSdkFunctions extends ListInputFieldsSdkFunction, GetAuthenticationSdkFunction, FindFirstAuthenticationSdkFunction, FindUniqueAuthenticationSdkFunction, RelayRequestSdkFunction {
|
|
63
67
|
}
|
|
64
|
-
export interface ZapierSdk extends GetSdkType<RegistryPluginProvides & FetchPluginProvides & AppsPluginProvides & ListAppsPluginProvides & ManifestPluginProvides & GetAppPluginProvides & ListActionsPluginProvides & GetActionPluginProvides & RunActionPluginProvides & ListAuthenticationsPluginProvides & GetAuthenticationPluginProvides & FindFirstAuthenticationPluginProvides & FindUniqueAuthenticationPluginProvides & ListInputFieldsPluginProvides & ListInputFieldChoicesPluginProvides & RequestPluginProvides & GetProfilePluginProvides> {
|
|
68
|
+
export interface ZapierSdk extends GetSdkType<RegistryPluginProvides & FetchPluginProvides & AppsPluginProvides & ListAppsPluginProvides & ManifestPluginProvides & GetAppPluginProvides & ListActionsPluginProvides & GetActionPluginProvides & RunActionPluginProvides & ListAuthenticationsPluginProvides & GetAuthenticationPluginProvides & FindFirstAuthenticationPluginProvides & FindUniqueAuthenticationPluginProvides & ListInputFieldsPluginProvides & ListInputFieldChoicesPluginProvides & RequestPluginProvides & GetProfilePluginProvides & EventEmissionProvides & ApiPluginProvides> {
|
|
65
69
|
apps: ActionProxy & ZapierSdkApps;
|
|
66
70
|
}
|
|
67
71
|
//# sourceMappingURL=sdk.d.ts.map
|
package/dist/types/sdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;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AC,CAAC,SAAS,CAAA;KAAE,CAAC,CAAC;IAC/D,YAAY,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC;IAC3B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAGD,MAAM,WAAW,kBACf,SAAQ,0BAA0B,EAChC,4BAA4B,EAC5B,kCAAkC,EAClC,mCAAmC,EACnC,uBAAuB;CAE1B;AAUD,MAAM,WAAW,SACf,SAAQ,UAAU,CAChB,sBAAsB,GACpB,mBAAmB,GACnB,kBAAkB,GAClB,sBAAsB,GACtB,sBAAsB,GACtB,oBAAoB,GACpB,yBAAyB,GACzB,uBAAuB,GACvB,uBAAuB,GACvB,iCAAiC,GACjC,+BAA+B,GAC/B,qCAAqC,GACrC,sCAAsC,GACtC,6BAA6B,GAC7B,mCAAmC,GACnC,qBAAqB,GACrB,wBAAwB,GACxB,qBAAqB,GACrB,iBAAiB,CACpB;IAED,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC;CACnC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event emission types matching Avro schemas for SDK telemetry
|
|
3
|
+
*
|
|
4
|
+
* These interfaces correspond to the Avro schemas:
|
|
5
|
+
* - application_lifecycle_event.avsc
|
|
6
|
+
* - error_occurred_event.avsc
|
|
7
|
+
*/
|
|
8
|
+
export interface BaseEvent {
|
|
9
|
+
event_id: string;
|
|
10
|
+
timestamp_ms: number;
|
|
11
|
+
release_id: string;
|
|
12
|
+
customuser_id?: number | null;
|
|
13
|
+
account_id?: number | null;
|
|
14
|
+
identity_id?: number | null;
|
|
15
|
+
visitor_id?: string | null;
|
|
16
|
+
correlation_id?: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface ErrorOccurredEvent extends BaseEvent {
|
|
19
|
+
zap_id?: number | null;
|
|
20
|
+
node_id?: number | null;
|
|
21
|
+
selected_api?: string | null;
|
|
22
|
+
app_id?: number | null;
|
|
23
|
+
app_version_id?: number | null;
|
|
24
|
+
error_message: string;
|
|
25
|
+
error_type?: string | null;
|
|
26
|
+
error_status_code?: number | null;
|
|
27
|
+
error_stack_trace?: string | null;
|
|
28
|
+
error_source_method?: string | null;
|
|
29
|
+
error_source_file?: string | null;
|
|
30
|
+
error_line_number?: number | null;
|
|
31
|
+
operation_type?: string | null;
|
|
32
|
+
operation_key?: string | null;
|
|
33
|
+
error_severity?: string | null;
|
|
34
|
+
is_user_facing: boolean;
|
|
35
|
+
is_recoverable?: boolean | null;
|
|
36
|
+
sdk_version?: string | null;
|
|
37
|
+
error_metadata?: Record<string, string | null> | null;
|
|
38
|
+
parent_error_id?: string | null;
|
|
39
|
+
error_occurred_timestamp_ms?: number | null;
|
|
40
|
+
error_code?: string | null;
|
|
41
|
+
recovery_attempted?: boolean | null;
|
|
42
|
+
recovery_action?: string | null;
|
|
43
|
+
recovery_successful?: boolean | null;
|
|
44
|
+
environment?: string | null;
|
|
45
|
+
execution_time_before_error_ms?: number | null;
|
|
46
|
+
}
|
|
47
|
+
export interface ApplicationLifecycleEvent extends BaseEvent {
|
|
48
|
+
lifecycle_event_type: "startup" | "exit" | "signal_termination";
|
|
49
|
+
selected_api?: string | null;
|
|
50
|
+
app_id?: number | null;
|
|
51
|
+
app_version_id?: number | null;
|
|
52
|
+
sdk_version?: string | null;
|
|
53
|
+
cli_version?: string | null;
|
|
54
|
+
exit_code?: number | null;
|
|
55
|
+
signal_name?: string | null;
|
|
56
|
+
uptime_ms?: number | null;
|
|
57
|
+
memory_usage_bytes?: number | null;
|
|
58
|
+
peak_memory_usage_bytes?: number | null;
|
|
59
|
+
cpu_time_ms?: number | null;
|
|
60
|
+
os_platform?: string | null;
|
|
61
|
+
os_release?: string | null;
|
|
62
|
+
os_architecture?: string | null;
|
|
63
|
+
platform_versions?: Record<string, string | null> | null;
|
|
64
|
+
environment?: string | null;
|
|
65
|
+
is_ci_environment?: boolean | null;
|
|
66
|
+
ci_platform?: string | null;
|
|
67
|
+
session_id?: string | null;
|
|
68
|
+
metadata?: Record<string, string | null> | null;
|
|
69
|
+
process_argv?: (string | null)[] | null;
|
|
70
|
+
is_graceful_shutdown?: boolean | null;
|
|
71
|
+
shutdown_duration_ms?: number | null;
|
|
72
|
+
active_requests_count?: number | null;
|
|
73
|
+
}
|
|
74
|
+
export type TelemetryEvent = ErrorOccurredEvent | ApplicationLifecycleEvent;
|
|
75
|
+
export type TelemetryEventType = "error_occurred" | "application_lifecycle";
|
|
76
|
+
//# sourceMappingURL=telemetry-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../src/types/telemetry-events.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAGD,MAAM,WAAW,kBAAmB,SAAQ,SAAS;IACnD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,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ACvC;AAGD,MAAM,MAAM,cAAc,GAAG,kBAAkB,GAAG,yBAAyB,CAAC;AAG5E,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG,uBAAuB,CAAC"}
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -8,3 +8,9 @@
|
|
|
8
8
|
* Maximum number of items that can be requested per page across all paginated functions
|
|
9
9
|
*/
|
|
10
10
|
export const MAX_PAGE_LIMIT = 10000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Default telemetry endpoint for the Tracking API
|
|
14
|
+
*/
|
|
15
|
+
export const TRACKING_API_ENDPOINT =
|
|
16
|
+
"https://zapier.com/api/v4/tracking/event/";
|
package/src/index.ts
CHANGED
|
@@ -85,3 +85,27 @@ export { registryPlugin } from "./plugins/registry";
|
|
|
85
85
|
|
|
86
86
|
// Export ZapierSdk from sdk.ts (it's now ReturnType<typeof createZapierSdk>)
|
|
87
87
|
export type { ZapierSdk } from "./types/sdk";
|
|
88
|
+
|
|
89
|
+
// Export event types and utilities for external packages
|
|
90
|
+
export type { BaseEvent } from "./types/telemetry-events";
|
|
91
|
+
export type {
|
|
92
|
+
EventEmissionContext,
|
|
93
|
+
EventContext,
|
|
94
|
+
ApplicationLifecycleEventData,
|
|
95
|
+
EnhancedErrorEventData,
|
|
96
|
+
} from "./plugins/eventEmission";
|
|
97
|
+
export {
|
|
98
|
+
generateEventId,
|
|
99
|
+
getCurrentTimestamp,
|
|
100
|
+
getReleaseId,
|
|
101
|
+
getOsInfo,
|
|
102
|
+
getPlatformVersions,
|
|
103
|
+
isCi,
|
|
104
|
+
getCiPlatform,
|
|
105
|
+
getMemoryUsage,
|
|
106
|
+
getCpuTime,
|
|
107
|
+
buildApplicationLifecycleEvent,
|
|
108
|
+
buildErrorEventWithContext,
|
|
109
|
+
buildErrorEvent,
|
|
110
|
+
createBaseEvent,
|
|
111
|
+
} from "./plugins/eventEmission";
|
package/src/plugins/api/index.ts
CHANGED
|
@@ -13,11 +13,7 @@ export interface ApiPluginProvides {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// API plugin requires no context and provides api in context
|
|
16
|
-
export const apiPlugin: Plugin<
|
|
17
|
-
{}, // no SDK dependencies
|
|
18
|
-
{}, // requires no context
|
|
19
|
-
ApiPluginProvides
|
|
20
|
-
> = (params) => {
|
|
16
|
+
export const apiPlugin: Plugin<{}, {}, ApiPluginProvides> = (params) => {
|
|
21
17
|
// Extract all options - everything passed to the plugin
|
|
22
18
|
const {
|
|
23
19
|
fetch: customFetch = globalThis.fetch,
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
|
|
8
|
+
import type {
|
|
9
|
+
ErrorOccurredEvent,
|
|
10
|
+
ApplicationLifecycleEvent,
|
|
11
|
+
BaseEvent,
|
|
12
|
+
} from "../../types/telemetry-events";
|
|
13
|
+
import type {
|
|
14
|
+
ApplicationLifecycleEventData,
|
|
15
|
+
EnhancedErrorEventData,
|
|
16
|
+
ErrorEventData,
|
|
17
|
+
EventContext,
|
|
18
|
+
} from "./types";
|
|
19
|
+
import {
|
|
20
|
+
generateEventId,
|
|
21
|
+
getCurrentTimestamp,
|
|
22
|
+
getReleaseId,
|
|
23
|
+
getOsInfo,
|
|
24
|
+
getPlatformVersions,
|
|
25
|
+
getMemoryUsage,
|
|
26
|
+
getCpuTime,
|
|
27
|
+
isCi,
|
|
28
|
+
getCiPlatform,
|
|
29
|
+
} from "./utils";
|
|
30
|
+
import sdkPackageJson from "../../../package.json";
|
|
31
|
+
|
|
32
|
+
// Create base event with auto-populated common fields
|
|
33
|
+
// Kept for backward compatibility but can be replaced with direct construction
|
|
34
|
+
export function createBaseEvent(context: EventContext = {}): BaseEvent {
|
|
35
|
+
return {
|
|
36
|
+
event_id: generateEventId(),
|
|
37
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
38
|
+
release_id: getReleaseId(),
|
|
39
|
+
customuser_id: context.customuser_id,
|
|
40
|
+
account_id: context.account_id,
|
|
41
|
+
identity_id: context.identity_id,
|
|
42
|
+
visitor_id: context.visitor_id,
|
|
43
|
+
correlation_id: context.correlation_id,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function buildErrorEvent(
|
|
48
|
+
data: ErrorEventData,
|
|
49
|
+
context: EventContext = {},
|
|
50
|
+
): ErrorOccurredEvent {
|
|
51
|
+
return {
|
|
52
|
+
...createBaseEvent(context),
|
|
53
|
+
zap_id: context.zap_id,
|
|
54
|
+
node_id: context.node_id,
|
|
55
|
+
selected_api: context.selected_api,
|
|
56
|
+
app_id: context.app_id,
|
|
57
|
+
app_version_id: context.app_version_id,
|
|
58
|
+
environment: context.environment,
|
|
59
|
+
sdk_version: sdkPackageJson.version,
|
|
60
|
+
...data,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function buildApplicationLifecycleEvent(
|
|
65
|
+
data: ApplicationLifecycleEventData,
|
|
66
|
+
context: EventContext = {},
|
|
67
|
+
): ApplicationLifecycleEvent {
|
|
68
|
+
const osInfo = getOsInfo();
|
|
69
|
+
const platformVersions = getPlatformVersions();
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
...createBaseEvent(context),
|
|
73
|
+
selected_api: context.selected_api,
|
|
74
|
+
app_id: context.app_id,
|
|
75
|
+
app_version_id: context.app_version_id,
|
|
76
|
+
sdk_version: sdkPackageJson.version,
|
|
77
|
+
cli_version: null,
|
|
78
|
+
memory_usage_bytes: data.memory_usage_bytes ?? getMemoryUsage(),
|
|
79
|
+
peak_memory_usage_bytes: data.peak_memory_usage_bytes ?? getMemoryUsage(),
|
|
80
|
+
cpu_time_ms: data.cpu_time_ms ?? getCpuTime(),
|
|
81
|
+
os_platform: osInfo.platform,
|
|
82
|
+
os_release: osInfo.release,
|
|
83
|
+
os_architecture: osInfo.architecture,
|
|
84
|
+
platform_versions: platformVersions,
|
|
85
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
86
|
+
is_ci_environment: isCi(),
|
|
87
|
+
ci_platform: getCiPlatform(),
|
|
88
|
+
session_id: null,
|
|
89
|
+
metadata: null,
|
|
90
|
+
process_argv: process.argv || null,
|
|
91
|
+
...data,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function buildErrorEventWithContext(
|
|
96
|
+
data: EnhancedErrorEventData,
|
|
97
|
+
context: EventContext = {},
|
|
98
|
+
): ErrorOccurredEvent {
|
|
99
|
+
const executionTime = data.execution_start_time
|
|
100
|
+
? Date.now() - data.execution_start_time
|
|
101
|
+
: null;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
...createBaseEvent(context),
|
|
105
|
+
zap_id: context.zap_id,
|
|
106
|
+
node_id: context.node_id,
|
|
107
|
+
selected_api: context.selected_api,
|
|
108
|
+
app_id: context.app_id,
|
|
109
|
+
app_version_id: context.app_version_id,
|
|
110
|
+
environment: context.environment ?? (process.env.NODE_ENV || null),
|
|
111
|
+
sdk_version: sdkPackageJson.version,
|
|
112
|
+
execution_time_before_error_ms: executionTime,
|
|
113
|
+
...data,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Event Emission Plugin
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
6
|
+
import { eventEmissionPlugin } from "./index";
|
|
7
|
+
import { createTransport } from "./transport";
|
|
8
|
+
import type { EventEmissionConfig } from "./index";
|
|
9
|
+
|
|
10
|
+
// Mock transport for testing
|
|
11
|
+
const mockTransport = {
|
|
12
|
+
emit: vi.fn().mockResolvedValue(undefined),
|
|
13
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
vi.mock("./transport", () => ({
|
|
17
|
+
createTransport: vi.fn(() => mockTransport),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
describe("eventEmissionPlugin", () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should create plugin with default configuration", () => {
|
|
26
|
+
const plugin = eventEmissionPlugin({
|
|
27
|
+
sdk: {},
|
|
28
|
+
context: {
|
|
29
|
+
meta: {},
|
|
30
|
+
options: {},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(plugin.context.eventEmission).toBeDefined();
|
|
35
|
+
expect(plugin.context.eventEmission.emit).toBeDefined();
|
|
36
|
+
expect(plugin.context.eventEmission.transport).toBeDefined();
|
|
37
|
+
expect(plugin.context.eventEmission.config).toBeDefined();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should create noop implementations when disabled", () => {
|
|
41
|
+
const config: EventEmissionConfig = { enabled: false };
|
|
42
|
+
const plugin = eventEmissionPlugin({
|
|
43
|
+
sdk: {},
|
|
44
|
+
context: {
|
|
45
|
+
meta: {},
|
|
46
|
+
options: { eventEmission: config },
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Should not emit any events when disabled
|
|
51
|
+
plugin.context.eventEmission.emit("platform.sdk.TestEvent", {
|
|
52
|
+
test_event: "data",
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(mockTransport.emit).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should emit events using generic emit method", async () => {
|
|
59
|
+
const plugin = eventEmissionPlugin({
|
|
60
|
+
sdk: {},
|
|
61
|
+
context: {
|
|
62
|
+
meta: {},
|
|
63
|
+
options: {
|
|
64
|
+
eventEmission: {
|
|
65
|
+
enabled: true,
|
|
66
|
+
transport: { type: "console" as const },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const testEvent = {
|
|
73
|
+
test_data: "example",
|
|
74
|
+
value: 123,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const testSubject = "test.event.TestEvent";
|
|
78
|
+
|
|
79
|
+
plugin.context.eventEmission.emit(testSubject, testEvent);
|
|
80
|
+
|
|
81
|
+
// Give async emission time to complete
|
|
82
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
83
|
+
|
|
84
|
+
expect(mockTransport.emit).toHaveBeenCalledWith(testSubject, testEvent);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should handle transport creation failures silently", () => {
|
|
88
|
+
// Mock createTransport to throw an error
|
|
89
|
+
vi.mocked(createTransport).mockImplementationOnce(() => {
|
|
90
|
+
throw new Error("Transport creation failed");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(() => {
|
|
94
|
+
eventEmissionPlugin({
|
|
95
|
+
sdk: {},
|
|
96
|
+
context: {
|
|
97
|
+
meta: {},
|
|
98
|
+
options: {
|
|
99
|
+
eventEmission: {
|
|
100
|
+
enabled: true,
|
|
101
|
+
transport: { type: "http" as const, endpoint: "invalid-url" },
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}).not.toThrow();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should handle event emission failures silently", async () => {
|
|
110
|
+
// Mock transport to throw error
|
|
111
|
+
const failingTransport = {
|
|
112
|
+
emit: vi.fn().mockRejectedValue(new Error("Network error")),
|
|
113
|
+
close: vi.fn().mockResolvedValue(undefined),
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
vi.mocked(createTransport).mockReturnValueOnce(failingTransport);
|
|
117
|
+
|
|
118
|
+
const plugin = eventEmissionPlugin({
|
|
119
|
+
sdk: {},
|
|
120
|
+
context: {
|
|
121
|
+
meta: {},
|
|
122
|
+
options: {
|
|
123
|
+
eventEmission: {
|
|
124
|
+
enabled: true,
|
|
125
|
+
transport: {
|
|
126
|
+
type: "http" as const,
|
|
127
|
+
endpoint: "https://example.com",
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// Should not throw even if transport fails
|
|
135
|
+
expect(() => {
|
|
136
|
+
plugin.context.eventEmission.emit("test.event.TestEvent", {
|
|
137
|
+
test_event: "data",
|
|
138
|
+
});
|
|
139
|
+
}).not.toThrow();
|
|
140
|
+
|
|
141
|
+
// Give async emission time to complete
|
|
142
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
143
|
+
|
|
144
|
+
expect(failingTransport.emit).toHaveBeenCalled();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should merge options with defaults", () => {
|
|
148
|
+
const plugin = eventEmissionPlugin({
|
|
149
|
+
sdk: {},
|
|
150
|
+
context: {
|
|
151
|
+
meta: {},
|
|
152
|
+
options: {
|
|
153
|
+
eventEmission: {
|
|
154
|
+
transport: {
|
|
155
|
+
type: "http" as const,
|
|
156
|
+
endpoint: "https://example.com",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(plugin.context.eventEmission.config.enabled).toBe(true);
|
|
164
|
+
expect(plugin.context.eventEmission.config.transport).toEqual({
|
|
165
|
+
type: "http",
|
|
166
|
+
endpoint: "https://example.com",
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
});
|