@zapier/zapier-sdk 0.15.2 → 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 +12 -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 +209 -27
- package/dist/index.d.mts +151 -59
- package/dist/index.mjs +209 -27
- 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/plugins/fetch/schemas.d.ts +2 -2
- package/dist/plugins/getAction/schemas.d.ts +2 -2
- package/dist/plugins/getInputFieldsSchema/schemas.d.ts +2 -2
- package/dist/plugins/listActions/index.test.js +25 -0
- package/dist/plugins/listActions/schemas.d.ts +2 -2
- package/dist/plugins/listAuthentications/index.test.js +20 -0
- package/dist/plugins/listInputFieldChoices/schemas.d.ts +6 -6
- package/dist/plugins/listInputFields/schemas.d.ts +6 -6
- package/dist/plugins/manifest/index.d.ts +42 -3
- package/dist/plugins/manifest/index.d.ts.map +1 -1
- package/dist/plugins/manifest/index.js +68 -1
- package/dist/plugins/manifest/index.test.js +513 -1
- package/dist/plugins/manifest/schemas.d.ts +75 -2
- package/dist/plugins/manifest/schemas.d.ts.map +1 -1
- package/dist/plugins/manifest/schemas.js +27 -3
- package/dist/plugins/request/schemas.d.ts +4 -4
- package/dist/plugins/runAction/schemas.d.ts +6 -6
- package/dist/schemas/Action.d.ts +1 -1
- package/dist/schemas/Auth.d.ts +6 -6
- package/dist/sdk.d.ts +23 -1
- package/dist/sdk.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2721,6 +2721,17 @@ async function readFile(filePath) {
|
|
|
2721
2721
|
throw new Error(`File not found: ${filePath}`);
|
|
2722
2722
|
}
|
|
2723
2723
|
var DEFAULT_CONFIG_PATH = ".zapierrc";
|
|
2724
|
+
var ActionEntrySchema = zod.z.object({
|
|
2725
|
+
appKey: zod.z.string().describe("App key (slug or implementation name)"),
|
|
2726
|
+
actionKey: zod.z.string().describe("Action key identifier"),
|
|
2727
|
+
actionType: zod.z.string().describe("Action type (e.g., 'read', 'write', 'search')"),
|
|
2728
|
+
authenticationId: zod.z.number().nullable().optional().describe("Authentication ID used"),
|
|
2729
|
+
inputs: zod.z.record(zod.z.unknown()).optional().describe("Resolved input values"),
|
|
2730
|
+
schema: zod.z.record(zod.z.unknown()).describe(
|
|
2731
|
+
"Complete JSON Schema from getInputFieldsSchema (includes $schema, type, properties, required, etc.)"
|
|
2732
|
+
),
|
|
2733
|
+
createdAt: zod.z.string().describe("ISO 8601 timestamp when created")
|
|
2734
|
+
});
|
|
2724
2735
|
var ManifestSchema = zod.z.object({
|
|
2725
2736
|
apps: zod.z.record(
|
|
2726
2737
|
zod.z.string(),
|
|
@@ -2730,8 +2741,9 @@ var ManifestSchema = zod.z.object({
|
|
|
2730
2741
|
),
|
|
2731
2742
|
version: zod.z.string().describe("Version string (e.g., '1.21.1')")
|
|
2732
2743
|
})
|
|
2733
|
-
)
|
|
2734
|
-
|
|
2744
|
+
),
|
|
2745
|
+
actions: zod.z.record(zod.z.string(), ActionEntrySchema).optional().describe("Saved action configurations with their schemas")
|
|
2746
|
+
}).describe("Manifest for app version locking and action configurations");
|
|
2735
2747
|
zod.z.object({
|
|
2736
2748
|
manifestPath: zod.z.string().optional().describe("Path to manifest file"),
|
|
2737
2749
|
manifest: zod.z.record(
|
|
@@ -3002,7 +3014,81 @@ var manifestPlugin = (params) => {
|
|
|
3002
3014
|
await writeManifestToFile(updatedManifest, configPath);
|
|
3003
3015
|
resolvedManifest = void 0;
|
|
3004
3016
|
}
|
|
3005
|
-
return
|
|
3017
|
+
return {
|
|
3018
|
+
key: manifestKey,
|
|
3019
|
+
entry,
|
|
3020
|
+
manifest: updatedManifest
|
|
3021
|
+
};
|
|
3022
|
+
};
|
|
3023
|
+
const addActionEntry = async (options2) => {
|
|
3024
|
+
const {
|
|
3025
|
+
name,
|
|
3026
|
+
entry,
|
|
3027
|
+
configPath = DEFAULT_CONFIG_PATH,
|
|
3028
|
+
skipWrite = false,
|
|
3029
|
+
manifest: inputManifest
|
|
3030
|
+
} = options2;
|
|
3031
|
+
const manifest2 = inputManifest || await readManifestFromFile(configPath) || { apps: {} };
|
|
3032
|
+
const actions = manifest2.actions || {};
|
|
3033
|
+
if (actions[name] && !skipWrite) {
|
|
3034
|
+
throw new Error(
|
|
3035
|
+
`Action "${name}" already exists. Please choose a different name or remove the existing action first.`
|
|
3036
|
+
);
|
|
3037
|
+
}
|
|
3038
|
+
const updatedManifest = {
|
|
3039
|
+
...manifest2,
|
|
3040
|
+
actions: {
|
|
3041
|
+
...actions,
|
|
3042
|
+
[name]: entry
|
|
3043
|
+
}
|
|
3044
|
+
};
|
|
3045
|
+
if (!skipWrite) {
|
|
3046
|
+
await writeManifestToFile(updatedManifest, configPath);
|
|
3047
|
+
resolvedManifest = void 0;
|
|
3048
|
+
}
|
|
3049
|
+
return {
|
|
3050
|
+
name,
|
|
3051
|
+
entry,
|
|
3052
|
+
manifest: updatedManifest
|
|
3053
|
+
};
|
|
3054
|
+
};
|
|
3055
|
+
const findActionEntry = ({
|
|
3056
|
+
name,
|
|
3057
|
+
manifest: manifest2
|
|
3058
|
+
}) => {
|
|
3059
|
+
return manifest2.actions?.[name] || null;
|
|
3060
|
+
};
|
|
3061
|
+
const listActionEntries = async ({
|
|
3062
|
+
configPath = DEFAULT_CONFIG_PATH
|
|
3063
|
+
} = {}) => {
|
|
3064
|
+
const manifest2 = await readManifestFromFile(configPath) || { };
|
|
3065
|
+
return Object.entries(manifest2.actions || {});
|
|
3066
|
+
};
|
|
3067
|
+
const deleteActionEntry = async ({
|
|
3068
|
+
name,
|
|
3069
|
+
configPath = DEFAULT_CONFIG_PATH,
|
|
3070
|
+
skipWrite = false
|
|
3071
|
+
}) => {
|
|
3072
|
+
const manifest2 = await readManifestFromFile(configPath) || { apps: {} };
|
|
3073
|
+
if (!manifest2.actions?.[name]) {
|
|
3074
|
+
throw new Error(`Action "${name}" does not exist.`);
|
|
3075
|
+
}
|
|
3076
|
+
const { [name]: removed, ...remainingActions } = manifest2.actions;
|
|
3077
|
+
const updatedManifest = {
|
|
3078
|
+
...manifest2,
|
|
3079
|
+
actions: remainingActions
|
|
3080
|
+
};
|
|
3081
|
+
if (!skipWrite) {
|
|
3082
|
+
await writeManifestToFile(updatedManifest, configPath);
|
|
3083
|
+
resolvedManifest = void 0;
|
|
3084
|
+
}
|
|
3085
|
+
return updatedManifest;
|
|
3086
|
+
};
|
|
3087
|
+
const hasActionEntry = ({
|
|
3088
|
+
name,
|
|
3089
|
+
manifest: manifest2
|
|
3090
|
+
}) => {
|
|
3091
|
+
return !!manifest2.actions?.[name];
|
|
3006
3092
|
};
|
|
3007
3093
|
return {
|
|
3008
3094
|
context: {
|
|
@@ -3012,7 +3098,14 @@ var manifestPlugin = (params) => {
|
|
|
3012
3098
|
api,
|
|
3013
3099
|
manifest: await getResolvedManifest() ?? { apps: {} }
|
|
3014
3100
|
}),
|
|
3015
|
-
updateManifestEntry
|
|
3101
|
+
updateManifestEntry,
|
|
3102
|
+
addActionEntry,
|
|
3103
|
+
findActionEntry,
|
|
3104
|
+
listActionEntries,
|
|
3105
|
+
deleteActionEntry,
|
|
3106
|
+
hasActionEntry,
|
|
3107
|
+
findManifestEntry,
|
|
3108
|
+
readManifestFromFile
|
|
3016
3109
|
}
|
|
3017
3110
|
};
|
|
3018
3111
|
};
|
|
@@ -3106,6 +3199,34 @@ function getAuthorizationHeader(token) {
|
|
|
3106
3199
|
}
|
|
3107
3200
|
return `Bearer ${token}`;
|
|
3108
3201
|
}
|
|
3202
|
+
function extractUserIdsFromJwt(token) {
|
|
3203
|
+
try {
|
|
3204
|
+
const parts = token.split(".");
|
|
3205
|
+
if (parts.length !== 3) {
|
|
3206
|
+
return { customuser_id: null, account_id: null };
|
|
3207
|
+
}
|
|
3208
|
+
const payload = JSON.parse(
|
|
3209
|
+
Buffer.from(parts[1], "base64url").toString("utf-8")
|
|
3210
|
+
);
|
|
3211
|
+
let actualPayload = payload;
|
|
3212
|
+
if (payload.sub_type === "service" && payload.njwt) {
|
|
3213
|
+
const nestedParts = payload.njwt.split(".");
|
|
3214
|
+
if (nestedParts.length === 3) {
|
|
3215
|
+
actualPayload = JSON.parse(
|
|
3216
|
+
Buffer.from(nestedParts[1], "base64url").toString("utf-8")
|
|
3217
|
+
);
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
const accountId = actualPayload["zap:acc"] != null ? parseInt(String(actualPayload["zap:acc"]), 10) : null;
|
|
3221
|
+
const customUserId = actualPayload.sub_type === "customuser" && actualPayload.sub != null ? parseInt(String(actualPayload.sub), 10) : null;
|
|
3222
|
+
return {
|
|
3223
|
+
customuser_id: customUserId !== null && !isNaN(customUserId) ? customUserId : null,
|
|
3224
|
+
account_id: accountId !== null && !isNaN(accountId) ? accountId : null
|
|
3225
|
+
};
|
|
3226
|
+
} catch {
|
|
3227
|
+
return { customuser_id: null, account_id: null };
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3109
3230
|
|
|
3110
3231
|
// src/api/debug.ts
|
|
3111
3232
|
var utilModule = null;
|
|
@@ -4502,7 +4623,7 @@ function getCpuTime() {
|
|
|
4502
4623
|
|
|
4503
4624
|
// package.json
|
|
4504
4625
|
var package_default = {
|
|
4505
|
-
version: "0.15.
|
|
4626
|
+
version: "0.15.4"};
|
|
4506
4627
|
|
|
4507
4628
|
// src/plugins/eventEmission/builders.ts
|
|
4508
4629
|
function createBaseEvent(context = {}) {
|
|
@@ -4573,17 +4694,26 @@ function buildErrorEventWithContext(data, context = {}) {
|
|
|
4573
4694
|
}
|
|
4574
4695
|
|
|
4575
4696
|
// src/plugins/eventEmission/index.ts
|
|
4697
|
+
var TELEMETRY_EMIT_TIMEOUT_MS = 300;
|
|
4576
4698
|
var APPLICATION_LIFECYCLE_EVENT_SUBJECT = "platform.sdk.ApplicationLifecycleEvent";
|
|
4577
4699
|
var ERROR_OCCURRED_EVENT_SUBJECT = "platform.sdk.ErrorOccurredEvent";
|
|
4578
4700
|
var transportStates = /* @__PURE__ */ new WeakMap();
|
|
4579
|
-
async function silentEmit(transport, subject, event) {
|
|
4701
|
+
async function silentEmit(transport, subject, event, userContextPromise) {
|
|
4580
4702
|
try {
|
|
4581
4703
|
let state = transportStates.get(transport);
|
|
4582
4704
|
if (!state) {
|
|
4583
4705
|
state = { hasWorked: false, hasLoggedFailure: false };
|
|
4584
4706
|
transportStates.set(transport, state);
|
|
4585
4707
|
}
|
|
4586
|
-
|
|
4708
|
+
let enrichedEvent = event;
|
|
4709
|
+
if (userContextPromise) {
|
|
4710
|
+
try {
|
|
4711
|
+
const userContext = await userContextPromise;
|
|
4712
|
+
enrichedEvent = Object.assign({}, event, userContext);
|
|
4713
|
+
} catch {
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
transport.emit(subject, enrichedEvent).then(() => {
|
|
4587
4717
|
state.hasWorked = true;
|
|
4588
4718
|
}).catch((error) => {
|
|
4589
4719
|
if (!state.hasWorked && !state.hasLoggedFailure) {
|
|
@@ -4631,6 +4761,19 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4631
4761
|
)
|
|
4632
4762
|
)
|
|
4633
4763
|
};
|
|
4764
|
+
const getUserContext = (async () => {
|
|
4765
|
+
try {
|
|
4766
|
+
const { getToken } = await import('@zapier/zapier-sdk-cli-login');
|
|
4767
|
+
const token = await getToken({
|
|
4768
|
+
baseUrl: context.options.baseUrl
|
|
4769
|
+
});
|
|
4770
|
+
if (token) {
|
|
4771
|
+
return extractUserIdsFromJwt(token);
|
|
4772
|
+
}
|
|
4773
|
+
} catch {
|
|
4774
|
+
}
|
|
4775
|
+
return { customuser_id: null, account_id: null };
|
|
4776
|
+
})();
|
|
4634
4777
|
const startupTime = Date.now();
|
|
4635
4778
|
let shutdownStartTime = null;
|
|
4636
4779
|
if (!config.enabled) {
|
|
@@ -4641,7 +4784,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4641
4784
|
config,
|
|
4642
4785
|
emit: () => {
|
|
4643
4786
|
},
|
|
4644
|
-
createBaseEvent: () => ({
|
|
4787
|
+
createBaseEvent: async () => ({
|
|
4645
4788
|
event_id: generateEventId(),
|
|
4646
4789
|
timestamp_ms: getCurrentTimestamp(),
|
|
4647
4790
|
release_id: getReleaseId(),
|
|
@@ -4661,21 +4804,34 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4661
4804
|
} catch {
|
|
4662
4805
|
transport = createTransport({ type: "noop" });
|
|
4663
4806
|
}
|
|
4664
|
-
const createBaseEventHelper = () =>
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4807
|
+
const createBaseEventHelper = async () => {
|
|
4808
|
+
const baseEvent = {
|
|
4809
|
+
event_id: generateEventId(),
|
|
4810
|
+
timestamp_ms: getCurrentTimestamp(),
|
|
4811
|
+
release_id: getReleaseId(),
|
|
4812
|
+
customuser_id: null,
|
|
4813
|
+
account_id: null,
|
|
4814
|
+
identity_id: null,
|
|
4815
|
+
visitor_id: null,
|
|
4816
|
+
correlation_id: null
|
|
4817
|
+
};
|
|
4818
|
+
try {
|
|
4819
|
+
const userContext = await getUserContext;
|
|
4820
|
+
return { ...baseEvent, ...userContext };
|
|
4821
|
+
} catch {
|
|
4822
|
+
return baseEvent;
|
|
4823
|
+
}
|
|
4824
|
+
};
|
|
4674
4825
|
if (config.enabled) {
|
|
4675
4826
|
const startupEvent = buildApplicationLifecycleEvent({
|
|
4676
4827
|
lifecycle_event_type: "startup"
|
|
4677
4828
|
});
|
|
4678
|
-
silentEmit(
|
|
4829
|
+
silentEmit(
|
|
4830
|
+
transport,
|
|
4831
|
+
APPLICATION_LIFECYCLE_EVENT_SUBJECT,
|
|
4832
|
+
startupEvent,
|
|
4833
|
+
getUserContext
|
|
4834
|
+
);
|
|
4679
4835
|
if (typeof process?.on === "function") {
|
|
4680
4836
|
process.on("exit", (code) => {
|
|
4681
4837
|
const uptime = Date.now() - startupTime;
|
|
@@ -4687,10 +4843,15 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4687
4843
|
is_graceful_shutdown: code === 0,
|
|
4688
4844
|
shutdown_duration_ms: shutdownDuration
|
|
4689
4845
|
});
|
|
4690
|
-
silentEmit(
|
|
4846
|
+
silentEmit(
|
|
4847
|
+
transport,
|
|
4848
|
+
APPLICATION_LIFECYCLE_EVENT_SUBJECT,
|
|
4849
|
+
exitEvent,
|
|
4850
|
+
getUserContext
|
|
4851
|
+
);
|
|
4691
4852
|
});
|
|
4692
4853
|
process.on("uncaughtException", async (error) => {
|
|
4693
|
-
|
|
4854
|
+
let errorEvent = buildErrorEventWithContext({
|
|
4694
4855
|
error_message: error.message || "Unknown error",
|
|
4695
4856
|
error_type: "UncaughtException",
|
|
4696
4857
|
error_stack_trace: error.stack || null,
|
|
@@ -4699,10 +4860,17 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4699
4860
|
is_recoverable: false,
|
|
4700
4861
|
execution_start_time: startupTime
|
|
4701
4862
|
});
|
|
4863
|
+
try {
|
|
4864
|
+
const userContext = await getUserContext;
|
|
4865
|
+
errorEvent = { ...errorEvent, ...userContext };
|
|
4866
|
+
} catch {
|
|
4867
|
+
}
|
|
4702
4868
|
try {
|
|
4703
4869
|
await Promise.race([
|
|
4704
4870
|
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4705
|
-
new Promise(
|
|
4871
|
+
new Promise(
|
|
4872
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4873
|
+
)
|
|
4706
4874
|
]);
|
|
4707
4875
|
} catch {
|
|
4708
4876
|
}
|
|
@@ -4712,7 +4880,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4712
4880
|
async (reason, promise) => {
|
|
4713
4881
|
const errorMessage = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "Unhandled promise rejection";
|
|
4714
4882
|
const errorStack = reason instanceof Error ? reason.stack : null;
|
|
4715
|
-
|
|
4883
|
+
let errorEvent = buildErrorEventWithContext({
|
|
4716
4884
|
error_message: errorMessage,
|
|
4717
4885
|
error_type: "UnhandledRejection",
|
|
4718
4886
|
error_stack_trace: errorStack,
|
|
@@ -4724,10 +4892,17 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4724
4892
|
promise: String(promise)
|
|
4725
4893
|
}
|
|
4726
4894
|
});
|
|
4895
|
+
try {
|
|
4896
|
+
const userContext = await getUserContext;
|
|
4897
|
+
errorEvent = { ...errorEvent, ...userContext };
|
|
4898
|
+
} catch {
|
|
4899
|
+
}
|
|
4727
4900
|
try {
|
|
4728
4901
|
await Promise.race([
|
|
4729
4902
|
transport.emit(ERROR_OCCURRED_EVENT_SUBJECT, errorEvent),
|
|
4730
|
-
new Promise(
|
|
4903
|
+
new Promise(
|
|
4904
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4905
|
+
)
|
|
4731
4906
|
]);
|
|
4732
4907
|
} catch {
|
|
4733
4908
|
}
|
|
@@ -4736,16 +4911,23 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4736
4911
|
const handleSignal = async (signal) => {
|
|
4737
4912
|
shutdownStartTime = Date.now();
|
|
4738
4913
|
const uptime = Date.now() - startupTime;
|
|
4739
|
-
|
|
4914
|
+
let signalEvent = buildApplicationLifecycleEvent({
|
|
4740
4915
|
lifecycle_event_type: "signal_termination",
|
|
4741
4916
|
signal_name: signal,
|
|
4742
4917
|
uptime_ms: uptime,
|
|
4743
4918
|
is_graceful_shutdown: true
|
|
4744
4919
|
});
|
|
4920
|
+
try {
|
|
4921
|
+
const userContext = await getUserContext;
|
|
4922
|
+
signalEvent = { ...signalEvent, ...userContext };
|
|
4923
|
+
} catch {
|
|
4924
|
+
}
|
|
4745
4925
|
try {
|
|
4746
4926
|
await Promise.race([
|
|
4747
4927
|
transport.emit(APPLICATION_LIFECYCLE_EVENT_SUBJECT, signalEvent),
|
|
4748
|
-
new Promise(
|
|
4928
|
+
new Promise(
|
|
4929
|
+
(resolve2) => setTimeout(resolve2, TELEMETRY_EMIT_TIMEOUT_MS)
|
|
4930
|
+
)
|
|
4749
4931
|
]);
|
|
4750
4932
|
} catch {
|
|
4751
4933
|
}
|
|
@@ -4761,7 +4943,7 @@ var eventEmissionPlugin = ({ context }) => {
|
|
|
4761
4943
|
transport,
|
|
4762
4944
|
config,
|
|
4763
4945
|
emit: (subject, event) => {
|
|
4764
|
-
silentEmit(transport, subject, event);
|
|
4946
|
+
silentEmit(transport, subject, event, getUserContext);
|
|
4765
4947
|
},
|
|
4766
4948
|
createBaseEvent: createBaseEventHelper
|
|
4767
4949
|
}
|