@zapier/zapier-sdk 0.18.0 → 0.18.1
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/index.cjs +52 -49
- package/dist/index.mjs +52 -49
- package/dist/plugins/eventEmission/transport.d.ts +8 -18
- package/dist/plugins/eventEmission/transport.d.ts.map +1 -1
- package/dist/plugins/eventEmission/transport.js +47 -44
- package/dist/plugins/eventEmission/transport.test.js +36 -25
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4916,70 +4916,73 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
4916
4916
|
// src/plugins/eventEmission/transport.ts
|
|
4917
4917
|
var DEFAULT_RETRY_ATTEMPTS = 2;
|
|
4918
4918
|
var DEFAULT_RETRY_DELAY_MS = 300;
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
);
|
|
4930
|
-
} catch {
|
|
4931
|
-
}
|
|
4932
|
-
}
|
|
4933
|
-
async emitWithRetry(subject, event, attemptsLeft) {
|
|
4919
|
+
function createHttpTransport(config) {
|
|
4920
|
+
const delay = async (ms) => {
|
|
4921
|
+
return new Promise((resolve2) => {
|
|
4922
|
+
const timer = setTimeout(resolve2, ms);
|
|
4923
|
+
if (typeof timer.unref === "function") {
|
|
4924
|
+
timer.unref();
|
|
4925
|
+
}
|
|
4926
|
+
});
|
|
4927
|
+
};
|
|
4928
|
+
const emitWithRetry = async (subject, event, attemptsLeft) => {
|
|
4934
4929
|
try {
|
|
4935
4930
|
const payload = {
|
|
4936
4931
|
subject,
|
|
4937
4932
|
properties: event
|
|
4938
4933
|
};
|
|
4939
|
-
const response = await fetch(
|
|
4934
|
+
const response = await fetch(config.endpoint, {
|
|
4940
4935
|
method: "POST",
|
|
4941
4936
|
headers: {
|
|
4942
4937
|
"Content-Type": "application/json",
|
|
4943
|
-
...
|
|
4938
|
+
...config.headers
|
|
4944
4939
|
},
|
|
4945
4940
|
body: JSON.stringify(payload)
|
|
4946
4941
|
});
|
|
4947
4942
|
if (!response.ok && attemptsLeft > 1) {
|
|
4948
|
-
await
|
|
4949
|
-
return
|
|
4943
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
4944
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
4950
4945
|
}
|
|
4951
4946
|
} catch (error) {
|
|
4952
4947
|
if (attemptsLeft > 1) {
|
|
4953
|
-
await
|
|
4954
|
-
return
|
|
4948
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
4949
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
4955
4950
|
}
|
|
4956
4951
|
throw error;
|
|
4957
4952
|
}
|
|
4958
|
-
}
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4953
|
+
};
|
|
4954
|
+
return {
|
|
4955
|
+
async emit(subject, event) {
|
|
4956
|
+
try {
|
|
4957
|
+
await emitWithRetry(
|
|
4958
|
+
subject,
|
|
4959
|
+
event,
|
|
4960
|
+
config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
|
|
4961
|
+
);
|
|
4962
|
+
} catch {
|
|
4964
4963
|
}
|
|
4965
|
-
});
|
|
4966
|
-
}
|
|
4967
|
-
};
|
|
4968
|
-
var ConsoleTransport = class {
|
|
4969
|
-
async emit(subject, event) {
|
|
4970
|
-
try {
|
|
4971
|
-
console.log(
|
|
4972
|
-
"[SDK Telemetry]",
|
|
4973
|
-
JSON.stringify({ subject, properties: event }, null, 2)
|
|
4974
|
-
);
|
|
4975
|
-
} catch {
|
|
4976
4964
|
}
|
|
4977
|
-
}
|
|
4978
|
-
}
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4965
|
+
};
|
|
4966
|
+
}
|
|
4967
|
+
function createConsoleTransport() {
|
|
4968
|
+
return {
|
|
4969
|
+
async emit(subject, event) {
|
|
4970
|
+
try {
|
|
4971
|
+
console.log(
|
|
4972
|
+
"[SDK Telemetry]",
|
|
4973
|
+
JSON.stringify({ subject, properties: event }, null, 2)
|
|
4974
|
+
);
|
|
4975
|
+
} catch {
|
|
4976
|
+
}
|
|
4977
|
+
}
|
|
4978
|
+
};
|
|
4979
|
+
}
|
|
4980
|
+
function createNoopTransport() {
|
|
4981
|
+
return {
|
|
4982
|
+
async emit(_subject, _event) {
|
|
4983
|
+
}
|
|
4984
|
+
};
|
|
4985
|
+
}
|
|
4983
4986
|
function createTransport(config) {
|
|
4984
4987
|
try {
|
|
4985
4988
|
switch (config.type) {
|
|
@@ -4987,20 +4990,20 @@ function createTransport(config) {
|
|
|
4987
4990
|
if (!config.endpoint) {
|
|
4988
4991
|
throw new Error("HTTP transport requires endpoint");
|
|
4989
4992
|
}
|
|
4990
|
-
return
|
|
4993
|
+
return createHttpTransport({
|
|
4991
4994
|
endpoint: config.endpoint,
|
|
4992
4995
|
headers: config.headers,
|
|
4993
4996
|
retryAttempts: config.retryAttempts,
|
|
4994
4997
|
retryDelayMs: config.retryDelayMs
|
|
4995
4998
|
});
|
|
4996
4999
|
case "console":
|
|
4997
|
-
return
|
|
5000
|
+
return createConsoleTransport();
|
|
4998
5001
|
case "noop":
|
|
4999
5002
|
default:
|
|
5000
|
-
return
|
|
5003
|
+
return createNoopTransport();
|
|
5001
5004
|
}
|
|
5002
5005
|
} catch {
|
|
5003
|
-
return
|
|
5006
|
+
return createNoopTransport();
|
|
5004
5007
|
}
|
|
5005
5008
|
}
|
|
5006
5009
|
function generateEventId() {
|
|
@@ -5069,7 +5072,7 @@ function getCpuTime() {
|
|
|
5069
5072
|
|
|
5070
5073
|
// package.json
|
|
5071
5074
|
var package_default = {
|
|
5072
|
-
version: "0.18.
|
|
5075
|
+
version: "0.18.1"};
|
|
5073
5076
|
|
|
5074
5077
|
// src/plugins/eventEmission/builders.ts
|
|
5075
5078
|
function createBaseEvent(context = {}) {
|
package/dist/index.mjs
CHANGED
|
@@ -4894,70 +4894,73 @@ var listInputFieldChoicesPlugin = ({ context, sdk }) => {
|
|
|
4894
4894
|
// src/plugins/eventEmission/transport.ts
|
|
4895
4895
|
var DEFAULT_RETRY_ATTEMPTS = 2;
|
|
4896
4896
|
var DEFAULT_RETRY_DELAY_MS = 300;
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
);
|
|
4908
|
-
} catch {
|
|
4909
|
-
}
|
|
4910
|
-
}
|
|
4911
|
-
async emitWithRetry(subject, event, attemptsLeft) {
|
|
4897
|
+
function createHttpTransport(config) {
|
|
4898
|
+
const delay = async (ms) => {
|
|
4899
|
+
return new Promise((resolve2) => {
|
|
4900
|
+
const timer = setTimeout(resolve2, ms);
|
|
4901
|
+
if (typeof timer.unref === "function") {
|
|
4902
|
+
timer.unref();
|
|
4903
|
+
}
|
|
4904
|
+
});
|
|
4905
|
+
};
|
|
4906
|
+
const emitWithRetry = async (subject, event, attemptsLeft) => {
|
|
4912
4907
|
try {
|
|
4913
4908
|
const payload = {
|
|
4914
4909
|
subject,
|
|
4915
4910
|
properties: event
|
|
4916
4911
|
};
|
|
4917
|
-
const response = await fetch(
|
|
4912
|
+
const response = await fetch(config.endpoint, {
|
|
4918
4913
|
method: "POST",
|
|
4919
4914
|
headers: {
|
|
4920
4915
|
"Content-Type": "application/json",
|
|
4921
|
-
...
|
|
4916
|
+
...config.headers
|
|
4922
4917
|
},
|
|
4923
4918
|
body: JSON.stringify(payload)
|
|
4924
4919
|
});
|
|
4925
4920
|
if (!response.ok && attemptsLeft > 1) {
|
|
4926
|
-
await
|
|
4927
|
-
return
|
|
4921
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
4922
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
4928
4923
|
}
|
|
4929
4924
|
} catch (error) {
|
|
4930
4925
|
if (attemptsLeft > 1) {
|
|
4931
|
-
await
|
|
4932
|
-
return
|
|
4926
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
4927
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
4933
4928
|
}
|
|
4934
4929
|
throw error;
|
|
4935
4930
|
}
|
|
4936
|
-
}
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4931
|
+
};
|
|
4932
|
+
return {
|
|
4933
|
+
async emit(subject, event) {
|
|
4934
|
+
try {
|
|
4935
|
+
await emitWithRetry(
|
|
4936
|
+
subject,
|
|
4937
|
+
event,
|
|
4938
|
+
config.retryAttempts || DEFAULT_RETRY_ATTEMPTS
|
|
4939
|
+
);
|
|
4940
|
+
} catch {
|
|
4942
4941
|
}
|
|
4943
|
-
});
|
|
4944
|
-
}
|
|
4945
|
-
};
|
|
4946
|
-
var ConsoleTransport = class {
|
|
4947
|
-
async emit(subject, event) {
|
|
4948
|
-
try {
|
|
4949
|
-
console.log(
|
|
4950
|
-
"[SDK Telemetry]",
|
|
4951
|
-
JSON.stringify({ subject, properties: event }, null, 2)
|
|
4952
|
-
);
|
|
4953
|
-
} catch {
|
|
4954
4942
|
}
|
|
4955
|
-
}
|
|
4956
|
-
}
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4943
|
+
};
|
|
4944
|
+
}
|
|
4945
|
+
function createConsoleTransport() {
|
|
4946
|
+
return {
|
|
4947
|
+
async emit(subject, event) {
|
|
4948
|
+
try {
|
|
4949
|
+
console.log(
|
|
4950
|
+
"[SDK Telemetry]",
|
|
4951
|
+
JSON.stringify({ subject, properties: event }, null, 2)
|
|
4952
|
+
);
|
|
4953
|
+
} catch {
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
};
|
|
4957
|
+
}
|
|
4958
|
+
function createNoopTransport() {
|
|
4959
|
+
return {
|
|
4960
|
+
async emit(_subject, _event) {
|
|
4961
|
+
}
|
|
4962
|
+
};
|
|
4963
|
+
}
|
|
4961
4964
|
function createTransport(config) {
|
|
4962
4965
|
try {
|
|
4963
4966
|
switch (config.type) {
|
|
@@ -4965,20 +4968,20 @@ function createTransport(config) {
|
|
|
4965
4968
|
if (!config.endpoint) {
|
|
4966
4969
|
throw new Error("HTTP transport requires endpoint");
|
|
4967
4970
|
}
|
|
4968
|
-
return
|
|
4971
|
+
return createHttpTransport({
|
|
4969
4972
|
endpoint: config.endpoint,
|
|
4970
4973
|
headers: config.headers,
|
|
4971
4974
|
retryAttempts: config.retryAttempts,
|
|
4972
4975
|
retryDelayMs: config.retryDelayMs
|
|
4973
4976
|
});
|
|
4974
4977
|
case "console":
|
|
4975
|
-
return
|
|
4978
|
+
return createConsoleTransport();
|
|
4976
4979
|
case "noop":
|
|
4977
4980
|
default:
|
|
4978
|
-
return
|
|
4981
|
+
return createNoopTransport();
|
|
4979
4982
|
}
|
|
4980
4983
|
} catch {
|
|
4981
|
-
return
|
|
4984
|
+
return createNoopTransport();
|
|
4982
4985
|
}
|
|
4983
4986
|
}
|
|
4984
4987
|
function generateEventId() {
|
|
@@ -5047,7 +5050,7 @@ function getCpuTime() {
|
|
|
5047
5050
|
|
|
5048
5051
|
// package.json
|
|
5049
5052
|
var package_default = {
|
|
5050
|
-
version: "0.18.
|
|
5053
|
+
version: "0.18.1"};
|
|
5051
5054
|
|
|
5052
5055
|
// src/plugins/eventEmission/builders.ts
|
|
5053
5056
|
function createBaseEvent(context = {}) {
|
|
@@ -15,23 +15,13 @@ export interface TransportConfig {
|
|
|
15
15
|
retryAttempts?: number;
|
|
16
16
|
retryDelayMs?: number;
|
|
17
17
|
}
|
|
18
|
-
export declare
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
emit<T extends any>(subject: string, event: T): Promise<void>;
|
|
27
|
-
private emitWithRetry;
|
|
28
|
-
private delay;
|
|
29
|
-
}
|
|
30
|
-
export declare class ConsoleTransport implements EventTransport {
|
|
31
|
-
emit<T extends any>(subject: string, event: T): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
export declare class NoopTransport implements EventTransport {
|
|
34
|
-
emit<T extends any>(_subject: string, _event: T): Promise<void>;
|
|
35
|
-
}
|
|
18
|
+
export declare function createHttpTransport(config: {
|
|
19
|
+
endpoint: string;
|
|
20
|
+
headers?: Record<string, string>;
|
|
21
|
+
retryAttempts?: number;
|
|
22
|
+
retryDelayMs?: number;
|
|
23
|
+
}): EventTransport;
|
|
24
|
+
export declare function createConsoleTransport(): EventTransport;
|
|
25
|
+
export declare function createNoopTransport(): EventTransport;
|
|
36
26
|
export declare function createTransport(config: TransportConfig): EventTransport;
|
|
37
27
|
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAGD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,cAAc,CAwDjB;AAGD,wBAAgB,sBAAsB,IAAI,cAAc,CAavD;AAGD,wBAAgB,mBAAmB,IAAI,cAAc,CAMpD;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,cAAc,CAyBvE"}
|
|
@@ -8,70 +8,73 @@
|
|
|
8
8
|
const DEFAULT_RETRY_ATTEMPTS = 2;
|
|
9
9
|
const DEFAULT_RETRY_DELAY_MS = 300;
|
|
10
10
|
// HTTP Transport - sends events to remote endpoint
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
async emitWithRetry(subject, event, attemptsLeft) {
|
|
11
|
+
export function createHttpTransport(config) {
|
|
12
|
+
const delay = async (ms) => {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const timer = setTimeout(resolve, ms);
|
|
15
|
+
if (typeof timer.unref === "function") {
|
|
16
|
+
timer.unref();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const emitWithRetry = async (subject, event, attemptsLeft) => {
|
|
24
21
|
try {
|
|
25
22
|
const payload = {
|
|
26
23
|
subject,
|
|
27
24
|
properties: event,
|
|
28
25
|
};
|
|
29
|
-
const response = await fetch(
|
|
26
|
+
const response = await fetch(config.endpoint, {
|
|
30
27
|
method: "POST",
|
|
31
28
|
headers: {
|
|
32
29
|
"Content-Type": "application/json",
|
|
33
|
-
...
|
|
30
|
+
...config.headers,
|
|
34
31
|
},
|
|
35
32
|
body: JSON.stringify(payload),
|
|
36
33
|
});
|
|
37
34
|
if (!response.ok && attemptsLeft > 1) {
|
|
38
|
-
await
|
|
39
|
-
return
|
|
35
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
36
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
catch (error) {
|
|
43
40
|
if (attemptsLeft > 1) {
|
|
44
|
-
await
|
|
45
|
-
return
|
|
41
|
+
await delay(config.retryDelayMs || DEFAULT_RETRY_DELAY_MS);
|
|
42
|
+
return emitWithRetry(subject, event, attemptsLeft - 1);
|
|
46
43
|
}
|
|
47
44
|
throw error;
|
|
48
45
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
timer.unref();
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
async emit(subject, event) {
|
|
49
|
+
try {
|
|
50
|
+
await emitWithRetry(subject, event, config.retryAttempts || DEFAULT_RETRY_ATTEMPTS);
|
|
55
51
|
}
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
catch {
|
|
53
|
+
// Silent failure - never throw
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
58
57
|
}
|
|
59
58
|
// Console Transport - logs events to console (for development)
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
export function createConsoleTransport() {
|
|
60
|
+
return {
|
|
61
|
+
async emit(subject, event) {
|
|
62
|
+
try {
|
|
63
|
+
console.log("[SDK Telemetry]", JSON.stringify({ subject, properties: event }, null, 2));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Silent failure - never throw
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
69
70
|
}
|
|
70
71
|
// No-op Transport - discards all events (for testing/disabled state)
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
72
|
+
export function createNoopTransport() {
|
|
73
|
+
return {
|
|
74
|
+
async emit(_subject, _event) {
|
|
75
|
+
// Intentionally do nothing
|
|
76
|
+
},
|
|
77
|
+
};
|
|
75
78
|
}
|
|
76
79
|
// Transport factory
|
|
77
80
|
export function createTransport(config) {
|
|
@@ -81,21 +84,21 @@ export function createTransport(config) {
|
|
|
81
84
|
if (!config.endpoint) {
|
|
82
85
|
throw new Error("HTTP transport requires endpoint");
|
|
83
86
|
}
|
|
84
|
-
return
|
|
87
|
+
return createHttpTransport({
|
|
85
88
|
endpoint: config.endpoint,
|
|
86
89
|
headers: config.headers,
|
|
87
90
|
retryAttempts: config.retryAttempts,
|
|
88
91
|
retryDelayMs: config.retryDelayMs,
|
|
89
92
|
});
|
|
90
93
|
case "console":
|
|
91
|
-
return
|
|
94
|
+
return createConsoleTransport();
|
|
92
95
|
case "noop":
|
|
93
96
|
default:
|
|
94
|
-
return
|
|
97
|
+
return createNoopTransport();
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
catch {
|
|
98
101
|
// If transport creation fails, return noop to maintain silent operation
|
|
99
|
-
return
|
|
102
|
+
return createNoopTransport();
|
|
100
103
|
}
|
|
101
104
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Tests for Event Transport Layer
|
|
3
3
|
*/
|
|
4
4
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
5
|
-
import {
|
|
5
|
+
import { createHttpTransport, createConsoleTransport, createNoopTransport, createTransport, } from "./transport";
|
|
6
6
|
// Mock fetch globally
|
|
7
7
|
const mockFetch = vi.fn();
|
|
8
8
|
global.fetch = mockFetch;
|
|
@@ -20,13 +20,13 @@ describe("Transport Layer", () => {
|
|
|
20
20
|
beforeEach(() => {
|
|
21
21
|
vi.clearAllMocks();
|
|
22
22
|
});
|
|
23
|
-
describe("
|
|
23
|
+
describe("createHttpTransport", () => {
|
|
24
24
|
it("should emit events via HTTP successfully", async () => {
|
|
25
25
|
mockFetch.mockResolvedValueOnce({
|
|
26
26
|
ok: true,
|
|
27
27
|
status: 200,
|
|
28
28
|
});
|
|
29
|
-
const transport =
|
|
29
|
+
const transport = createHttpTransport({
|
|
30
30
|
endpoint: "https://telemetry.example.com/events",
|
|
31
31
|
headers: { "x-api-key": "test-key" },
|
|
32
32
|
});
|
|
@@ -49,7 +49,7 @@ describe("Transport Layer", () => {
|
|
|
49
49
|
.mockResolvedValueOnce({ ok: false, status: 500 })
|
|
50
50
|
.mockResolvedValueOnce({ ok: false, status: 500 })
|
|
51
51
|
.mockResolvedValueOnce({ ok: true, status: 200 });
|
|
52
|
-
const transport =
|
|
52
|
+
const transport = createHttpTransport({
|
|
53
53
|
endpoint: "https://telemetry.example.com/events",
|
|
54
54
|
retryAttempts: 3,
|
|
55
55
|
retryDelayMs: 10, // Short delay for testing
|
|
@@ -59,7 +59,7 @@ describe("Transport Layer", () => {
|
|
|
59
59
|
});
|
|
60
60
|
it("should handle network errors silently", async () => {
|
|
61
61
|
mockFetch.mockRejectedValue(new Error("Network error"));
|
|
62
|
-
const transport =
|
|
62
|
+
const transport = createHttpTransport({
|
|
63
63
|
endpoint: "https://telemetry.example.com/events",
|
|
64
64
|
retryAttempts: 1,
|
|
65
65
|
retryDelayMs: 1,
|
|
@@ -69,7 +69,7 @@ describe("Transport Layer", () => {
|
|
|
69
69
|
});
|
|
70
70
|
it("should stop retrying after max attempts", async () => {
|
|
71
71
|
mockFetch.mockResolvedValue({ ok: false, status: 500 });
|
|
72
|
-
const transport =
|
|
72
|
+
const transport = createHttpTransport({
|
|
73
73
|
endpoint: "https://telemetry.example.com/events",
|
|
74
74
|
retryAttempts: 2,
|
|
75
75
|
retryDelayMs: 1,
|
|
@@ -78,9 +78,9 @@ describe("Transport Layer", () => {
|
|
|
78
78
|
expect(mockFetch).toHaveBeenCalledTimes(2);
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
-
describe("
|
|
81
|
+
describe("createConsoleTransport", () => {
|
|
82
82
|
it("should log events to console", async () => {
|
|
83
|
-
const transport =
|
|
83
|
+
const transport = createConsoleTransport();
|
|
84
84
|
await transport.emit(sampleSubject, sampleEvent);
|
|
85
85
|
expect(mockConsoleLog).toHaveBeenCalledWith("[SDK Telemetry]", JSON.stringify({ subject: sampleSubject, properties: sampleEvent }, null, 2));
|
|
86
86
|
});
|
|
@@ -88,14 +88,14 @@ describe("Transport Layer", () => {
|
|
|
88
88
|
mockConsoleLog.mockImplementation(() => {
|
|
89
89
|
throw new Error("Console error");
|
|
90
90
|
});
|
|
91
|
-
const transport =
|
|
91
|
+
const transport = createConsoleTransport();
|
|
92
92
|
// Should not throw despite console error
|
|
93
93
|
await expect(transport.emit(sampleSubject, sampleEvent)).resolves.toBeUndefined();
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
|
-
describe("
|
|
96
|
+
describe("createNoopTransport", () => {
|
|
97
97
|
it("should do nothing when emitting events", async () => {
|
|
98
|
-
const transport =
|
|
98
|
+
const transport = createNoopTransport();
|
|
99
99
|
await transport.emit(sampleSubject, sampleEvent);
|
|
100
100
|
// Verify no side effects
|
|
101
101
|
expect(mockFetch).not.toHaveBeenCalled();
|
|
@@ -103,7 +103,8 @@ describe("Transport Layer", () => {
|
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
describe("createTransport", () => {
|
|
106
|
-
it("should create HTTP transport with valid config", () => {
|
|
106
|
+
it("should create HTTP transport with valid config", async () => {
|
|
107
|
+
mockFetch.mockResolvedValueOnce({ ok: true, status: 200 });
|
|
107
108
|
const transport = createTransport({
|
|
108
109
|
type: "http",
|
|
109
110
|
endpoint: "https://example.com",
|
|
@@ -111,42 +112,52 @@ describe("Transport Layer", () => {
|
|
|
111
112
|
retryAttempts: 5,
|
|
112
113
|
retryDelayMs: 2000,
|
|
113
114
|
});
|
|
114
|
-
expect(transport).
|
|
115
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
116
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
117
|
+
expect(mockFetch).toHaveBeenCalledWith("https://example.com", expect.any(Object));
|
|
115
118
|
});
|
|
116
|
-
it("should create console transport", () => {
|
|
119
|
+
it("should create console transport", async () => {
|
|
117
120
|
const transport = createTransport({
|
|
118
121
|
type: "console",
|
|
119
122
|
});
|
|
120
|
-
expect(transport).
|
|
123
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
124
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
125
|
+
expect(mockConsoleLog).toHaveBeenCalled();
|
|
121
126
|
});
|
|
122
|
-
it("should create noop transport by default", () => {
|
|
127
|
+
it("should create noop transport by default", async () => {
|
|
123
128
|
const transport = createTransport({
|
|
124
129
|
type: "noop",
|
|
125
130
|
});
|
|
126
|
-
expect(transport).
|
|
131
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
132
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
133
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
134
|
+
expect(mockConsoleLog).not.toHaveBeenCalled();
|
|
127
135
|
});
|
|
128
|
-
it("should fallback to noop transport on invalid HTTP config", () => {
|
|
136
|
+
it("should fallback to noop transport on invalid HTTP config", async () => {
|
|
129
137
|
const transport = createTransport({
|
|
130
138
|
type: "http",
|
|
131
139
|
// Missing endpoint
|
|
132
140
|
});
|
|
133
|
-
expect(transport).
|
|
141
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
142
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
143
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
134
144
|
});
|
|
135
|
-
it("should fallback to noop transport on unknown type", () => {
|
|
145
|
+
it("should fallback to noop transport on unknown type", async () => {
|
|
136
146
|
const transport = createTransport({
|
|
137
147
|
type: "unknown",
|
|
138
148
|
});
|
|
139
|
-
expect(transport).
|
|
149
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
150
|
+
await transport.emit(sampleSubject, sampleEvent);
|
|
151
|
+
expect(mockFetch).not.toHaveBeenCalled();
|
|
152
|
+
expect(mockConsoleLog).not.toHaveBeenCalled();
|
|
140
153
|
});
|
|
141
|
-
it("should handle transport creation errors gracefully", () => {
|
|
142
|
-
// Since createTransport already handles errors internally,
|
|
143
|
-
// this test verifies that invalid configs don't throw
|
|
154
|
+
it("should handle transport creation errors gracefully", async () => {
|
|
144
155
|
expect(() => {
|
|
145
156
|
const transport = createTransport({
|
|
146
157
|
type: "http",
|
|
147
158
|
// Missing required endpoint - should fallback to noop
|
|
148
159
|
});
|
|
149
|
-
expect(transport).
|
|
160
|
+
expect(transport.emit).toBeTypeOf("function");
|
|
150
161
|
}).not.toThrow();
|
|
151
162
|
});
|
|
152
163
|
});
|