@zapier/zapier-sdk 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/api/auth.d.ts +10 -0
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +35 -0
- package/dist/api/schemas.d.ts +38 -38
- package/dist/index.cjs +112 -23
- package/dist/index.d.mts +28 -28
- package/dist/index.mjs +112 -23
- package/dist/plugins/eventEmission/index.d.ts +1 -1
- package/dist/plugins/eventEmission/index.d.ts.map +1 -1
- package/dist/plugins/eventEmission/index.js +90 -22
- package/dist/plugins/eventEmission/index.test.js +179 -2
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/schemas/Auth.d.ts +6 -6
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -330,7 +330,7 @@ interface EventEmissionContext {
|
|
|
330
330
|
transport: EventTransport;
|
|
331
331
|
config: EventEmissionConfig;
|
|
332
332
|
emit<T extends any>(subject: string, event: T): void;
|
|
333
|
-
createBaseEvent(): BaseEvent
|
|
333
|
+
createBaseEvent(): Promise<BaseEvent>;
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
336
|
interface EventEmissionProvides {
|
|
@@ -455,19 +455,19 @@ declare const ActionSchema: z.ZodObject<{
|
|
|
455
455
|
key: string;
|
|
456
456
|
name: string;
|
|
457
457
|
description: string;
|
|
458
|
+
selected_api?: string | undefined;
|
|
458
459
|
id?: string | undefined;
|
|
459
460
|
is_important?: boolean | undefined;
|
|
460
461
|
is_hidden?: boolean | undefined;
|
|
461
|
-
selected_api?: string | undefined;
|
|
462
462
|
}, {
|
|
463
463
|
type: "search" | "filter" | "read" | "read_bulk" | "run" | "search_and_write" | "search_or_write" | "write";
|
|
464
464
|
key: string;
|
|
465
465
|
name: string;
|
|
466
466
|
description: string;
|
|
467
|
+
selected_api?: string | undefined;
|
|
467
468
|
id?: string | undefined;
|
|
468
469
|
is_important?: boolean | undefined;
|
|
469
470
|
is_hidden?: boolean | undefined;
|
|
470
|
-
selected_api?: string | undefined;
|
|
471
471
|
}>;
|
|
472
472
|
declare const ChoiceSchema: z.ZodObject<{
|
|
473
473
|
value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
|
|
@@ -616,17 +616,17 @@ declare const AuthenticationSchema: z.ZodObject<{
|
|
|
616
616
|
members: z.ZodOptional<z.ZodString>;
|
|
617
617
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
618
618
|
}, "strip", z.ZodTypeAny, {
|
|
619
|
+
account_id: number;
|
|
620
|
+
selected_api: string;
|
|
619
621
|
id: number;
|
|
620
622
|
date: string;
|
|
621
|
-
selected_api: string;
|
|
622
|
-
account_id: number;
|
|
623
623
|
is_invite_only: boolean;
|
|
624
624
|
is_private: boolean;
|
|
625
625
|
shared_with_all: boolean;
|
|
626
626
|
url?: string | undefined;
|
|
627
|
+
customuser_id?: number | undefined;
|
|
627
628
|
label?: string | null | undefined;
|
|
628
629
|
lastchanged?: string | undefined;
|
|
629
|
-
customuser_id?: number | undefined;
|
|
630
630
|
destination_selected_api?: string | null | undefined;
|
|
631
631
|
is_stale?: string | undefined;
|
|
632
632
|
is_shared?: string | undefined;
|
|
@@ -637,17 +637,17 @@ declare const AuthenticationSchema: z.ZodObject<{
|
|
|
637
637
|
members?: string | undefined;
|
|
638
638
|
permissions?: Record<string, boolean> | undefined;
|
|
639
639
|
}, {
|
|
640
|
+
account_id: number;
|
|
641
|
+
selected_api: string;
|
|
640
642
|
id: number;
|
|
641
643
|
date: string;
|
|
642
|
-
selected_api: string;
|
|
643
|
-
account_id: number;
|
|
644
644
|
is_invite_only: boolean;
|
|
645
645
|
is_private: boolean;
|
|
646
646
|
shared_with_all: boolean;
|
|
647
647
|
url?: string | undefined;
|
|
648
|
+
customuser_id?: number | undefined;
|
|
648
649
|
label?: string | null | undefined;
|
|
649
650
|
lastchanged?: string | undefined;
|
|
650
|
-
customuser_id?: number | undefined;
|
|
651
651
|
destination_selected_api?: string | null | undefined;
|
|
652
652
|
is_stale?: string | undefined;
|
|
653
653
|
is_shared?: string | undefined;
|
|
@@ -684,17 +684,17 @@ declare const AuthenticationsResponseSchema: z.ZodObject<{
|
|
|
684
684
|
members: z.ZodOptional<z.ZodString>;
|
|
685
685
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
686
686
|
}, "strip", z.ZodTypeAny, {
|
|
687
|
+
account_id: number;
|
|
688
|
+
selected_api: string;
|
|
687
689
|
id: number;
|
|
688
690
|
date: string;
|
|
689
|
-
selected_api: string;
|
|
690
|
-
account_id: number;
|
|
691
691
|
is_invite_only: boolean;
|
|
692
692
|
is_private: boolean;
|
|
693
693
|
shared_with_all: boolean;
|
|
694
694
|
url?: string | undefined;
|
|
695
|
+
customuser_id?: number | undefined;
|
|
695
696
|
label?: string | null | undefined;
|
|
696
697
|
lastchanged?: string | undefined;
|
|
697
|
-
customuser_id?: number | undefined;
|
|
698
698
|
destination_selected_api?: string | null | undefined;
|
|
699
699
|
is_stale?: string | undefined;
|
|
700
700
|
is_shared?: string | undefined;
|
|
@@ -705,17 +705,17 @@ declare const AuthenticationsResponseSchema: z.ZodObject<{
|
|
|
705
705
|
members?: string | undefined;
|
|
706
706
|
permissions?: Record<string, boolean> | undefined;
|
|
707
707
|
}, {
|
|
708
|
+
account_id: number;
|
|
709
|
+
selected_api: string;
|
|
708
710
|
id: number;
|
|
709
711
|
date: string;
|
|
710
|
-
selected_api: string;
|
|
711
|
-
account_id: number;
|
|
712
712
|
is_invite_only: boolean;
|
|
713
713
|
is_private: boolean;
|
|
714
714
|
shared_with_all: boolean;
|
|
715
715
|
url?: string | undefined;
|
|
716
|
+
customuser_id?: number | undefined;
|
|
716
717
|
label?: string | null | undefined;
|
|
717
718
|
lastchanged?: string | undefined;
|
|
718
|
-
customuser_id?: number | undefined;
|
|
719
719
|
destination_selected_api?: string | null | undefined;
|
|
720
720
|
is_stale?: string | undefined;
|
|
721
721
|
is_shared?: string | undefined;
|
|
@@ -729,17 +729,17 @@ declare const AuthenticationsResponseSchema: z.ZodObject<{
|
|
|
729
729
|
}, "strip", z.ZodTypeAny, {
|
|
730
730
|
count: number;
|
|
731
731
|
results: {
|
|
732
|
+
account_id: number;
|
|
733
|
+
selected_api: string;
|
|
732
734
|
id: number;
|
|
733
735
|
date: string;
|
|
734
|
-
selected_api: string;
|
|
735
|
-
account_id: number;
|
|
736
736
|
is_invite_only: boolean;
|
|
737
737
|
is_private: boolean;
|
|
738
738
|
shared_with_all: boolean;
|
|
739
739
|
url?: string | undefined;
|
|
740
|
+
customuser_id?: number | undefined;
|
|
740
741
|
label?: string | null | undefined;
|
|
741
742
|
lastchanged?: string | undefined;
|
|
742
|
-
customuser_id?: number | undefined;
|
|
743
743
|
destination_selected_api?: string | null | undefined;
|
|
744
744
|
is_stale?: string | undefined;
|
|
745
745
|
is_shared?: string | undefined;
|
|
@@ -755,17 +755,17 @@ declare const AuthenticationsResponseSchema: z.ZodObject<{
|
|
|
755
755
|
}, {
|
|
756
756
|
count: number;
|
|
757
757
|
results: {
|
|
758
|
+
account_id: number;
|
|
759
|
+
selected_api: string;
|
|
758
760
|
id: number;
|
|
759
761
|
date: string;
|
|
760
|
-
selected_api: string;
|
|
761
|
-
account_id: number;
|
|
762
762
|
is_invite_only: boolean;
|
|
763
763
|
is_private: boolean;
|
|
764
764
|
shared_with_all: boolean;
|
|
765
765
|
url?: string | undefined;
|
|
766
|
+
customuser_id?: number | undefined;
|
|
766
767
|
label?: string | null | undefined;
|
|
767
768
|
lastchanged?: string | undefined;
|
|
768
|
-
customuser_id?: number | undefined;
|
|
769
769
|
destination_selected_api?: string | null | undefined;
|
|
770
770
|
is_stale?: string | undefined;
|
|
771
771
|
is_shared?: string | undefined;
|
|
@@ -3022,7 +3022,7 @@ declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
3022
3022
|
groups: z.ZodOptional<z.ZodString>;
|
|
3023
3023
|
members: z.ZodOptional<z.ZodString>;
|
|
3024
3024
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
3025
|
-
}, "
|
|
3025
|
+
}, "customuser_id" | "selected_api"> & {
|
|
3026
3026
|
implementation_id: z.ZodOptional<z.ZodString>;
|
|
3027
3027
|
is_expired: z.ZodOptional<z.ZodString>;
|
|
3028
3028
|
expired_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -3030,9 +3030,9 @@ declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
3030
3030
|
app_version: z.ZodOptional<z.ZodString>;
|
|
3031
3031
|
user_id: z.ZodOptional<z.ZodNumber>;
|
|
3032
3032
|
}, "strip", z.ZodTypeAny, {
|
|
3033
|
+
account_id: number;
|
|
3033
3034
|
id: number;
|
|
3034
3035
|
date: string;
|
|
3035
|
-
account_id: number;
|
|
3036
3036
|
is_invite_only: boolean;
|
|
3037
3037
|
is_private: boolean;
|
|
3038
3038
|
shared_with_all: boolean;
|
|
@@ -3055,9 +3055,9 @@ declare const AuthenticationItemSchema: z.ZodObject<Omit<{
|
|
|
3055
3055
|
app_key?: string | undefined;
|
|
3056
3056
|
app_version?: string | undefined;
|
|
3057
3057
|
}, {
|
|
3058
|
+
account_id: number;
|
|
3058
3059
|
id: number;
|
|
3059
3060
|
date: string;
|
|
3060
|
-
account_id: number;
|
|
3061
3061
|
is_invite_only: boolean;
|
|
3062
3062
|
is_private: boolean;
|
|
3063
3063
|
shared_with_all: boolean;
|
|
@@ -3101,7 +3101,7 @@ declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
3101
3101
|
groups: z.ZodOptional<z.ZodString>;
|
|
3102
3102
|
members: z.ZodOptional<z.ZodString>;
|
|
3103
3103
|
permissions: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
|
|
3104
|
-
}, "
|
|
3104
|
+
}, "customuser_id" | "selected_api"> & {
|
|
3105
3105
|
implementation_id: z.ZodOptional<z.ZodString>;
|
|
3106
3106
|
is_expired: z.ZodOptional<z.ZodString>;
|
|
3107
3107
|
expired_at: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
@@ -3109,9 +3109,9 @@ declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
3109
3109
|
app_version: z.ZodOptional<z.ZodString>;
|
|
3110
3110
|
user_id: z.ZodOptional<z.ZodNumber>;
|
|
3111
3111
|
}, "strip", z.ZodTypeAny, {
|
|
3112
|
+
account_id: number;
|
|
3112
3113
|
id: number;
|
|
3113
3114
|
date: string;
|
|
3114
|
-
account_id: number;
|
|
3115
3115
|
is_invite_only: boolean;
|
|
3116
3116
|
is_private: boolean;
|
|
3117
3117
|
shared_with_all: boolean;
|
|
@@ -3134,9 +3134,9 @@ declare const AuthItemSchema: z.ZodObject<Omit<{
|
|
|
3134
3134
|
app_key?: string | undefined;
|
|
3135
3135
|
app_version?: string | undefined;
|
|
3136
3136
|
}, {
|
|
3137
|
+
account_id: number;
|
|
3137
3138
|
id: number;
|
|
3138
3139
|
date: string;
|
|
3139
|
-
account_id: number;
|
|
3140
3140
|
is_invite_only: boolean;
|
|
3141
3141
|
is_private: boolean;
|
|
3142
3142
|
shared_with_all: boolean;
|
|
@@ -3170,7 +3170,7 @@ declare const ActionItemSchema: z.ZodObject<Omit<{
|
|
|
3170
3170
|
is_important: z.ZodOptional<z.ZodBoolean>;
|
|
3171
3171
|
is_hidden: z.ZodOptional<z.ZodBoolean>;
|
|
3172
3172
|
selected_api: z.ZodOptional<z.ZodString>;
|
|
3173
|
-
}, "type" | "
|
|
3173
|
+
}, "type" | "selected_api" | "name"> & {
|
|
3174
3174
|
app_key: z.ZodString;
|
|
3175
3175
|
app_version: z.ZodOptional<z.ZodString>;
|
|
3176
3176
|
action_type: z.ZodEnum<["filter", "read", "read_bulk", "run", "search", "search_and_write", "search_or_write", "write"]>;
|
package/dist/index.mjs
CHANGED
|
@@ -3177,6 +3177,34 @@ function getAuthorizationHeader(token) {
|
|
|
3177
3177
|
}
|
|
3178
3178
|
return `Bearer ${token}`;
|
|
3179
3179
|
}
|
|
3180
|
+
function extractUserIdsFromJwt(token) {
|
|
3181
|
+
try {
|
|
3182
|
+
const parts = token.split(".");
|
|
3183
|
+
if (parts.length !== 3) {
|
|
3184
|
+
return { customuser_id: null, account_id: null };
|
|
3185
|
+
}
|
|
3186
|
+
const payload = JSON.parse(
|
|
3187
|
+
Buffer.from(parts[1], "base64url").toString("utf-8")
|
|
3188
|
+
);
|
|
3189
|
+
let actualPayload = payload;
|
|
3190
|
+
if (payload.sub_type === "service" && payload.njwt) {
|
|
3191
|
+
const nestedParts = payload.njwt.split(".");
|
|
3192
|
+
if (nestedParts.length === 3) {
|
|
3193
|
+
actualPayload = JSON.parse(
|
|
3194
|
+
Buffer.from(nestedParts[1], "base64url").toString("utf-8")
|
|
3195
|
+
);
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
const accountId = actualPayload["zap:acc"] != null ? parseInt(String(actualPayload["zap:acc"]), 10) : null;
|
|
3199
|
+
const customUserId = actualPayload.sub_type === "customuser" && actualPayload.sub != null ? parseInt(String(actualPayload.sub), 10) : null;
|
|
3200
|
+
return {
|
|
3201
|
+
customuser_id: customUserId !== null && !isNaN(customUserId) ? customUserId : null,
|
|
3202
|
+
account_id: accountId !== null && !isNaN(accountId) ? accountId : null
|
|
3203
|
+
};
|
|
3204
|
+
} catch {
|
|
3205
|
+
return { customuser_id: null, account_id: null };
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3180
3208
|
|
|
3181
3209
|
// src/api/debug.ts
|
|
3182
3210
|
var utilModule = null;
|
|
@@ -4573,7 +4601,7 @@ function getCpuTime() {
|
|
|
4573
4601
|
|
|
4574
4602
|
// package.json
|
|
4575
4603
|
var package_default = {
|
|
4576
|
-
version: "0.15.
|
|
4604
|
+
version: "0.15.4"};
|
|
4577
4605
|
|
|
4578
4606
|
// src/plugins/eventEmission/builders.ts
|
|
4579
4607
|
function createBaseEvent(context = {}) {
|
|
@@ -4644,17 +4672,26 @@ function buildErrorEventWithContext(data, context = {}) {
|
|
|
4644
4672
|
}
|
|
4645
4673
|
|
|
4646
4674
|
// src/plugins/eventEmission/index.ts
|
|
4675
|
+
var TELEMETRY_EMIT_TIMEOUT_MS = 300;
|
|
4647
4676
|
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4648
4677
|
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
4649
4678
|
var transportStates = /* @__PURE__ */ new WeakMap();
|
|
4650
|
-
async function silentEmit(transport, subject, event) {
|
|
4679
|
+
async function silentEmit(transport, subject, event, userContextPromise) {
|
|
4651
4680
|
try {
|
|
4652
4681
|
let state = transportStates.get(transport);
|
|
4653
4682
|
if (!state) {
|
|
4654
4683
|
state = { hasWorked: false, hasLoggedFailure: false };
|
|
4655
4684
|
transportStates.set(transport, state);
|
|
4656
4685
|
}
|
|
4657
|
-
|
|
4686
|
+
let enrichedEvent = event;
|
|
4687
|
+
if (userContextPromise) {
|
|
4688
|
+
try {
|
|
4689
|
+
const userContext = await userContextPromise;
|
|
4690
|
+
enrichedEvent = Object.assign({}, event, userContext);
|
|
4691
|
+
} catch {
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
transport.emit(subject, enrichedEvent).then(() => {
|
|
4658
4695
|
state.hasWorked = true;
|
|
4659
4696
|
}).catch((error) => {
|
|
4660
4697
|
if (!state.hasWorked && !state.hasLoggedFailure) {
|
|
@@ -4702,6 +4739,19 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4702
4739
|
)
|
|
4703
4740
|
)
|
|
4704
4741
|
};
|
|
4742
|
+
const getUserContext = (async () => {
|
|
4743
|
+
try {
|
|
4744
|
+
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
4745
|
+
const token = await getToken({
|
|
4746
|
+
baseUrl: context.options.baseUrl
|
|
4747
|
+
});
|
|
4748
|
+
if (token) {
|
|
4749
|
+
return extractUserIdsFromJwt(token);
|
|
4750
|
+
}
|
|
4751
|
+
} catch {
|
|
4752
|
+
}
|
|
4753
|
+
return { customuser_id: null, account_id: null };
|
|
4754
|
+
})();
|
|
4705
4755
|
const startupTime = Date.now();
|
|
4706
4756
|
let shutdownStartTime = null;
|
|
4707
4757
|
if (!config.enabled) {
|
|
@@ -4712,7 +4762,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4712
4762
|
config,
|
|
4713
4763
|
emit: () => {
|
|
4714
4764
|
},
|
|
4715
|
-
createBaseEvent: () => ({
|
|
4765
|
+
createBaseEvent: async () => ({
|
|
4716
4766
|
event_id: generateEventId(),
|
|
4717
4767
|
timestamp_ms: getCurrentTimestamp(),
|
|
4718
4768
|
release_id: getReleaseId(),
|
|
@@ -4732,21 +4782,34 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4732
4782
|
} catch {
|
|
4733
4783
|
transport = createTransport({ type: "noop" });
|
|
4734
4784
|
}
|
|
4735
|
-
const createBaseEventHelper = () =>
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4785
|
+
const createBaseEventHelper = async () => {
|
|
4786
|
+
const baseEvent = {
|
|
4787
|
+
event_id: generateEventId(),
|
|
4788
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4789
|
+
release_id: getReleaseId(),
|
|
4790
|
+
customuser_id: null,
|
|
4791
|
+
account_id: null,
|
|
4792
|
+
identity_id: null,
|
|
4793
|
+
visitor_id: null,
|
|
4794
|
+
correlation_id: null
|
|
4795
|
+
};
|
|
4796
|
+
try {
|
|
4797
|
+
const userContext = await getUserContext;
|
|
4798
|
+
return { ...baseEvent, ...userContext };
|
|
4799
|
+
} catch {
|
|
4800
|
+
return baseEvent;
|
|
4801
|
+
}
|
|
4802
|
+
};
|
|
4745
4803
|
if (config.enabled) {
|
|
4746
4804
|
const startupEvent = buildApplicationLifecycleEvent({
|
|
4747
4805
|
lifecycle_event_type: "startup"
|
|
4748
4806
|
});
|
|
4749
|
-
silentEmit(
|
|
4807
|
+
silentEmit(
|
|
4808
|
+
transport,
|
|
4809
|
+
APPLICATION_LIFECYCLE_EVENT_SUBJECT,
|
|
4810
|
+
startupEvent,
|
|
4811
|
+
getUserContext
|
|
4812
|
+
);
|
|
4750
4813
|
if (typeof process?.on === "function") {
|
|
4751
4814
|
process.on("exit", (code) => {
|
|
4752
4815
|
const uptime = Date.now() - startupTime;
|
|
@@ -4758,10 +4821,15 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4758
4821
|
is_graceful_shutdown: code === 0,
|
|
4759
4822
|
shutdown_duration_ms: shutdownDuration
|
|
4760
4823
|
});
|
|
4761
|
-
silentEmit(
|
|
4824
|
+
silentEmit(
|
|
4825
|
+
transport,
|
|
4826
|
+
APPLICATION_LIFECYCLE_EVENT_SUBJECT,
|
|
4827
|
+
exitEvent,
|
|
4828
|
+
getUserContext
|
|
4829
|
+
);
|
|
4762
4830
|
});
|
|
4763
4831
|
process.on("uncaughtException", async (error) => {
|
|
4764
|
-
|
|
4832
|
+
let errorEvent = buildErrorEventWithContext({
|
|
4765
4833
|
error_message: error.message || "Unknown error",
|
|
4766
4834
|
error_type: "UncaughtException",
|
|
4767
4835
|
error_stack_trace: error.stack || null,
|
|
@@ -4770,10 +4838,17 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4770
4838
|
is_recoverable: false,
|
|
4771
4839
|
execution_start_time: startupTime
|
|
4772
4840
|
});
|
|
4841
|
+
try {
|
|
4842
|
+
const userContext = await getUserContext;
|
|
4843
|
+
errorEvent = { ...errorEvent, ...userContext };
|
|
4844
|
+
} catch {
|
|
4845
|
+
}
|
|
4773
4846
|
try {
|
|
4774
4847
|
await Promise.race([
|
|
4775
4848
|
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4776
|
-
new Promise(
|
|
4849
|
+
new Promise(
|
|
4850
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4851
|
+
)
|
|
4777
4852
|
]);
|
|
4778
4853
|
} catch {
|
|
4779
4854
|
}
|
|
@@ -4783,7 +4858,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4783
4858
|
async (reason, promise) => {
|
|
4784
4859
|
const errorMessage = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
4785
4860
|
const errorStack = reason instanceof Error ? reason.stack : null;
|
|
4786
|
-
|
|
4861
|
+
let errorEvent = buildErrorEventWithContext({
|
|
4787
4862
|
error_message: errorMessage,
|
|
4788
4863
|
error_type: "UnhandledRejection",
|
|
4789
4864
|
error_stack_trace: errorStack,
|
|
@@ -4795,10 +4870,17 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4795
4870
|
promise: String(promise)
|
|
4796
4871
|
}
|
|
4797
4872
|
});
|
|
4873
|
+
try {
|
|
4874
|
+
const userContext = await getUserContext;
|
|
4875
|
+
errorEvent = { ...errorEvent, ...userContext };
|
|
4876
|
+
} catch {
|
|
4877
|
+
}
|
|
4798
4878
|
try {
|
|
4799
4879
|
await Promise.race([
|
|
4800
4880
|
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4801
|
-
new Promise(
|
|
4881
|
+
new Promise(
|
|
4882
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4883
|
+
)
|
|
4802
4884
|
]);
|
|
4803
4885
|
} catch {
|
|
4804
4886
|
}
|
|
@@ -4807,16 +4889,23 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4807
4889
|
const handleSignal = async (signal) => {
|
|
4808
4890
|
shutdownStartTime = Date.now();
|
|
4809
4891
|
const uptime = Date.now() - startupTime;
|
|
4810
|
-
|
|
4892
|
+
let signalEvent = buildApplicationLifecycleEvent({
|
|
4811
4893
|
lifecycle_event_type: "signal_termination",
|
|
4812
4894
|
signal_name: signal,
|
|
4813
4895
|
uptime_ms: uptime,
|
|
4814
4896
|
is_graceful_shutdown: true
|
|
4815
4897
|
});
|
|
4898
|
+
try {
|
|
4899
|
+
const userContext = await getUserContext;
|
|
4900
|
+
signalEvent = { ...signalEvent, ...userContext };
|
|
4901
|
+
} catch {
|
|
4902
|
+
}
|
|
4816
4903
|
try {
|
|
4817
4904
|
await Promise.race([
|
|
4818
4905
|
transport.emit(APPLICATION_LIFECYCLE_EVENT_SUBJECT, signalEvent),
|
|
4819
|
-
new Promise(
|
|
4906
|
+
new Promise(
|
|
4907
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4908
|
+
)
|
|
4820
4909
|
]);
|
|
4821
4910
|
} catch {
|
|
4822
4911
|
}
|
|
@@ -4832,7 +4921,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4832
4921
|
transport,
|
|
4833
4922
|
config,
|
|
4834
4923
|
emit: (subject, event) => {
|
|
4835
|
-
silentEmit(transport, subject, event);
|
|
4924
|
+
silentEmit(transport, subject, event, getUserContext);
|
|
4836
4925
|
},
|
|
4837
4926
|
createBaseEvent: createBaseEventHelper
|
|
4838
4927
|
}
|
|
@@ -16,7 +16,7 @@ export interface EventEmissionContext {
|
|
|
16
16
|
transport: EventTransport;
|
|
17
17
|
config: EventEmissionConfig;
|
|
18
18
|
emit<T extends any>(subject: string, event: T): void;
|
|
19
|
-
createBaseEvent(): BaseEvent
|
|
19
|
+
createBaseEvent(): Promise<BaseEvent>;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export interface EventEmissionProvides {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/eventEmission/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAenE,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAGD,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE;QACb,SAAS,EAAE,cAAc,CAAC;QAC1B,MAAM,EAAE,mBAAmB,CAAC;QAE5B,IAAI,CAAC,CAAC,SAAS,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;QAErD,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;KACvC,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,oBAAoB,CAAC;CAC/B;AA4FD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC,EAAE,EACF;IACE,OAAO,EAAE;QACP,aAAa,CAAC,EAAE,mBAAmB,CAAC;QACpC,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;CACH,EACD,qBAAqB,CAyQtB,CAAC;AAGF,YAAY,EACV,YAAY,EACZ,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,cAAc,SAAS,CAAC"}
|