New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@trigger.dev/sdk

Package Overview
Dependencies
Maintainers
2
Versions
497
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trigger.dev/sdk - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

8

dist/index.d.ts

@@ -18,3 +18,4 @@ import * as zod from 'zod';

type LogLevel = "log" | "error" | "warn" | "info" | "debug";
declare const logLevels: readonly ["disabled", "log", "error", "warn", "info", "debug"];
type LogLevel = (typeof logLevels)[number];

@@ -52,2 +53,7 @@ type TriggerCustomEvent = z.infer<typeof SerializableCustomEventSchema>;

logLevel?: LogLevel;
/**
* The TTL for the trigger in seconds. If the trigger is not run within this time, it will be aborted. Defaults to 3600 seconds (1 hour).
* @type {number}
*/
triggerTTL?: number;
run: (event: z.infer<TSchema>, ctx: TriggerContext) => Promise<any>;

@@ -54,0 +60,0 @@ };

231

dist/index.js

@@ -197,3 +197,3 @@ "use strict";

name: import_zod6.z.string(),
source: JsonSchema
source: ScheduleSourceSchema
});

@@ -361,3 +361,4 @@ var TriggerMetadataSchema = import_zod6.z.discriminatedUnion("type", [

packageVersion: import_zod8.z.string(),
packageName: import_zod8.z.string()
packageName: import_zod8.z.string(),
triggerTTL: import_zod8.z.number().optional()
}),

@@ -384,3 +385,3 @@ response: import_zod8.z.discriminatedUnion("type", [

runId: import_zod8.z.string(),
output: import_zod8.z.string(),
output: import_zod8.z.string().optional(),
timestamp: import_zod8.z.string()

@@ -422,2 +423,64 @@ }),

var import_node_crypto = require("crypto");
// ../internal-bridge/src/logger.ts
var logLevels = [
"disabled",
"log",
"error",
"warn",
"info",
"debug"
];
var _name, _level;
var Logger = class {
constructor(name2, level = "disabled") {
__privateAdd(this, _name, void 0);
__privateAdd(this, _level, void 0);
__privateSet(this, _name, name2);
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
}
log(...args) {
if (__privateGet(this, _level) < 1)
return;
console.log(`[${__privateGet(this, _name)}] `, ...args);
}
error(...args) {
if (__privateGet(this, _level) < 2)
return;
console.error(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
warn(...args) {
if (__privateGet(this, _level) < 3)
return;
console.warn(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
info(...args) {
if (__privateGet(this, _level) < 4)
return;
console.info(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
debug(...args) {
if (__privateGet(this, _level) < 5)
return;
console.debug(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
};
__name(Logger, "Logger");
_name = new WeakMap();
_level = new WeakMap();
function formattedDateTime() {
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const milliseconds = date.getMilliseconds();
const formattedHours = hours < 10 ? `0${hours}` : hours;
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds;
const formattedMilliseconds = milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds;
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}.${formattedMilliseconds}`;
}
__name(formattedDateTime, "formattedDateTime");
// ../internal-bridge/src/zodRPC.ts
var RPCMessageSchema = import_zod10.z.object({

@@ -432,3 +495,3 @@ id: import_zod10.z.string(),

});
var _connection, _sender, _receiver, _handlers, _pendingCalls, _onMessage, onMessage_fn, _onCall, onCall_fn, _onResponse, onResponse_fn, _handleCall, handleCall_fn, _handleResponse, handleResponse_fn;
var _connection, _sender, _receiver, _handlers, _pendingCalls, _logger, _onMessage, onMessage_fn, _onCall, onCall_fn, _onResponse, onResponse_fn, _handleCall, handleCall_fn, _handleResponse, handleResponse_fn;
var ZodRPC = class {

@@ -446,2 +509,3 @@ constructor(options) {

__privateAdd(this, _pendingCalls, /* @__PURE__ */ new Map());
__privateAdd(this, _logger, new Logger("ZodRPC"));
__privateSet(this, _connection, options.connection);

@@ -484,2 +548,3 @@ __privateSet(this, _sender, options.sender);

_pendingCalls = new WeakMap();
_logger = new WeakMap();
_onMessage = new WeakSet();

@@ -496,3 +561,3 @@ onMessage_fn = /* @__PURE__ */ __name(async function(rawData) {

} catch (err) {
console.error(err);
__privateGet(this, _logger).error(err);
}

@@ -506,6 +571,6 @@ }, "#onMessage");

if (callError instanceof import_zod10.ZodError) {
console.error(`[ZodRPC][foobar] Received invalid call:
__privateGet(this, _logger).error(`[ZodRPC] Received invalid call:
${JSON.stringify(message)}: `, callError.errors);
} else {
console.error(`[ZodRPC] Error handling call:
__privateGet(this, _logger).error(`[ZodRPC] Error handling call:
${JSON.stringify(message)}: `, callError);

@@ -521,7 +586,7 @@ }

if (callError instanceof import_zod10.ZodError) {
console.error(`[ZodRPC] Received invalid response
__privateGet(this, _logger).error(`[ZodRPC] Received invalid response
${JSON.stringify(message1)}: `, callError.flatten());
} else {
console.error(`[ZodRPC] Error handling response
__privateGet(this, _logger).error(`[ZodRPC] Error handling response

@@ -540,2 +605,5 @@ ${JSON.stringify(message1)}: `, callError);

}
__privateGet(this, _logger).debug("Received call", {
message: message2
});
const inputs = method.request.parse(message2.data);

@@ -552,3 +620,3 @@ const handler = __privateGet(this, _handlers)[methodName];

} catch (err) {
console.error("Failed sending response", preparedResponseText, err);
__privateGet(this, _logger).error("Failed sending response", preparedResponseText, err);
}

@@ -593,61 +661,2 @@ return;

// ../internal-bridge/src/logger.ts
var logLevels = [
"log",
"error",
"warn",
"info",
"debug"
];
var _name, _level;
var Logger = class {
constructor(name2, level = "info") {
__privateAdd(this, _name, void 0);
__privateAdd(this, _level, void 0);
__privateSet(this, _name, name2);
__privateSet(this, _level, logLevels.indexOf(process.env.TRIGGER_LOG_LEVEL ?? level));
}
log(...args) {
if (__privateGet(this, _level) < 0)
return;
console.log(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
error(...args) {
if (__privateGet(this, _level) < 1)
return;
console.error(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
warn(...args) {
if (__privateGet(this, _level) < 2)
return;
console.warn(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
info(...args) {
if (__privateGet(this, _level) < 3)
return;
console.info(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
debug(...args) {
if (__privateGet(this, _level) < 4)
return;
console.debug(`[${formattedDateTime()}] [${__privateGet(this, _name)}] `, ...args);
}
};
__name(Logger, "Logger");
_name = new WeakMap();
_level = new WeakMap();
function formattedDateTime() {
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
const seconds = date.getSeconds();
const milliseconds = date.getMilliseconds();
const formattedHours = hours < 10 ? `0${hours}` : hours;
const formattedMinutes = minutes < 10 ? `0${minutes}` : minutes;
const formattedSeconds = seconds < 10 ? `0${seconds}` : seconds;
const formattedMilliseconds = milliseconds < 10 ? `00${milliseconds}` : milliseconds < 100 ? `0${milliseconds}` : milliseconds;
return `${formattedHours}:${formattedMinutes}:${formattedSeconds}.${formattedMilliseconds}`;
}
__name(formattedDateTime, "formattedDateTime");
// src/client.ts

@@ -659,3 +668,3 @@ var import_uuid2 = require("uuid");

var name = "@trigger.dev/sdk";
var version = "0.2.1";
var version = "0.2.2";

@@ -671,3 +680,3 @@ // src/connection.ts

__name(NotConnectedError, "NotConnectedError");
var _socket, _connectTimeout, _sendTimeout, _pingTimeout, _isAuthenticated, _timeouts, _isClosed, _pendingMessages, _logger, _pingIntervalHandle, _pingIntervalMs, _closeUnresponsiveConnectionTimeoutMs, _startPingInterval, startPingInterval_fn, _ping, ping_fn;
var _socket, _connectTimeout, _sendTimeout, _pingTimeout, _isAuthenticated, _timeouts, _isClosed, _pendingMessages, _logger2, _pingIntervalHandle, _pingIntervalMs, _closeUnresponsiveConnectionTimeoutMs, _startPingInterval, startPingInterval_fn, _ping, ping_fn;
var HostConnection = class {

@@ -685,3 +694,3 @@ constructor(socket, options) {

__privateAdd(this, _pendingMessages, /* @__PURE__ */ new Map());
__privateAdd(this, _logger, void 0);
__privateAdd(this, _logger2, void 0);
__privateAdd(this, _pingIntervalHandle, void 0);

@@ -701,3 +710,3 @@ __privateAdd(this, _pingIntervalMs, 3e4);

__privateSet(this, _timeouts, /* @__PURE__ */ new Set());
__privateSet(this, _logger, new Logger("trigger.dev connection"));
__privateSet(this, _logger2, new Logger("trigger.dev connection"));
this.onClose.attach(() => {

@@ -765,10 +774,10 @@ __privateSet(this, _isClosed, true);

async connect() {
__privateGet(this, _logger).debug("[connect] Attempting to connect");
__privateGet(this, _logger2).debug("[connect] Attempting to connect");
return new Promise((resolve, reject) => {
if (__privateGet(this, _socket).readyState === __privateGet(this, _socket).OPEN && __privateGet(this, _isAuthenticated)) {
__privateGet(this, _logger).debug("[connect] Already connected, resolving");
__privateGet(this, _logger2).debug("[connect] Already connected, resolving");
return resolve();
}
const failTimeout = setTimeout(() => {
__privateGet(this, _logger).debug("[connect] Connection timed out, rejecting");
__privateGet(this, _logger2).debug("[connect] Connection timed out, rejecting");
reject(new TimeoutError());

@@ -780,3 +789,3 @@ }, __privateGet(this, _connectTimeout));

__privateGet(this, _timeouts).delete(failTimeout);
__privateGet(this, _logger).debug("[connect] Connected, resolving");
__privateGet(this, _logger2).debug("[connect] Connected, resolving");
resolve();

@@ -825,3 +834,3 @@ });

_pendingMessages = new WeakMap();
_logger = new WeakMap();
_logger2 = new WeakMap();
_pingIntervalHandle = new WeakMap();

@@ -845,8 +854,8 @@ _pingIntervalMs = new WeakMap();

} catch (err) {
__privateGet(this, _logger).warn("Pong not received in time");
__privateGet(this, _logger2).warn("Pong not received in time");
if (!(err instanceof TimeoutError)) {
__privateGet(this, _logger).error(err);
__privateGet(this, _logger2).error(err);
}
if (lastSuccessfulPing.getTime() < new Date().getTime() - __privateGet(this, _closeUnresponsiveConnectionTimeoutMs)) {
__privateGet(this, _logger).error("No pong received in last three minutes, closing connection to Interval and retrying...");
__privateGet(this, _logger2).error("No pong received in last three minutes, closing connection to Interval and retrying...");
if (__privateGet(this, _pingIntervalHandle)) {

@@ -881,7 +890,7 @@ clearInterval(__privateGet(this, _pingIntervalHandle));

__privateGet(this, _timeouts).delete(failTimeout);
__privateGet(this, _logger).debug(`Resolving ping`);
__privateGet(this, _logger2).debug(`Resolving ping`);
resolve();
}
});
__privateGet(this, _logger).debug(`Sending ping ${id} to ${socket.url}`);
__privateGet(this, _logger2).debug(`Sending ping ${id} to ${socket.url}`);
socket.ping(id, void 0, (err) => {

@@ -920,3 +929,3 @@ if (err) {

// src/client.ts
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger2, _closedByUser, _responseCompleteCallbacks, _waitForCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
var _trigger, _options, _connection2, _serverRPC, _apiKey, _endpoint, _isConnected, _retryIntervalMs, _logger3, _closedByUser, _responseCompleteCallbacks, _waitForCallbacks, _initializeConnection, initializeConnection_fn, _initializeRPC, initializeRPC_fn, _initializeHost, initializeHost_fn, _send, send_fn;
var TriggerClient = class {

@@ -936,3 +945,3 @@ constructor(trigger, options) {

__privateAdd(this, _retryIntervalMs, 3e3);
__privateAdd(this, _logger2, void 0);
__privateAdd(this, _logger3, void 0);
__privateAdd(this, _closedByUser, false);

@@ -949,3 +958,3 @@ __privateAdd(this, _responseCompleteCallbacks, /* @__PURE__ */ new Map());

__privateSet(this, _endpoint, __privateGet(this, _options).endpoint ?? "wss://wss.trigger.dev/ws");
__privateSet(this, _logger2, new Logger("trigger.dev", __privateGet(this, _options).logLevel));
__privateSet(this, _logger3, new Logger("trigger.dev", __privateGet(this, _options).logLevel));
}

@@ -975,3 +984,3 @@ async listen(instanceId) {

_retryIntervalMs = new WeakMap();
_logger2 = new WeakMap();
_logger3 = new WeakMap();
_closedByUser = new WeakMap();

@@ -983,3 +992,3 @@ _responseCompleteCallbacks = new WeakMap();

const id = instanceId ?? (0, import_uuid2.v4)();
__privateGet(this, _logger2).debug("Initializing connection", {
__privateGet(this, _logger3).debug("Initializing connection", {
id,

@@ -999,20 +1008,20 @@ endpoint: __privateGet(this, _endpoint)

if (__privateGet(this, _closedByUser)) {
__privateGet(this, _logger2).debug("Connection closed by user, so we won't reconnect");
__privateGet(this, _logger3).debug("Connection closed by user, so we won't reconnect");
__privateSet(this, _closedByUser, false);
return;
}
__privateGet(this, _logger2).error(`\u{1F6A9} Could not connect to trigger.dev (code ${code})`);
__privateGet(this, _logger3).error(`\u{1F6A9} Could not connect to trigger.dev (code ${code})`);
if (reason) {
__privateGet(this, _logger2).error("Reason:", reason);
__privateGet(this, _logger3).error("Reason:", reason);
}
if (!__privateGet(this, _isConnected))
return;
__privateGet(this, _logger2).log("\u{1F50C} Reconnecting to trigger.dev...");
__privateGet(this, _logger3).log("\u{1F50C} Reconnecting to trigger.dev...");
__privateSet(this, _isConnected, false);
while (!__privateGet(this, _isConnected)) {
__privateMethod(this, _initializeConnection, initializeConnection_fn).call(this, id).then(() => {
__privateGet(this, _logger2).log("\u26A1 Reconnection successful");
__privateGet(this, _logger3).log("\u26A1 Reconnection successful");
}).catch(() => {
});
__privateGet(this, _logger2).debug(`Reconnection failed, retrying in ${Math.round(__privateGet(this, _retryIntervalMs) / 1e3)} seconds`, id);
__privateGet(this, _logger3).debug(`Reconnection failed, retrying in ${Math.round(__privateGet(this, _retryIntervalMs) / 1e3)} seconds`, id);
await new Promise((resolve) => setTimeout(resolve, __privateGet(this, _retryIntervalMs)));

@@ -1022,3 +1031,3 @@ }

await connection.connect();
__privateGet(this, _logger2).debug("Connection initialized", id);
__privateGet(this, _logger3).debug("Connection initialized", id);
__privateSet(this, _connection2, connection);

@@ -1042,6 +1051,6 @@ __privateSet(this, _isConnected, true);

RESOLVE_DELAY: async (data) => {
__privateGet(this, _logger2).debug("Handling RESOLVE_DELAY", data);
__privateGet(this, _logger3).debug("Handling RESOLVE_DELAY", data);
const waitCallbacks = __privateGet(this, _waitForCallbacks).get(messageKey(data.meta.runId, data.key));
if (!waitCallbacks) {
__privateGet(this, _logger2).debug(`Could not find wait callbacks for wait ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
__privateGet(this, _logger3).debug(`Could not find wait callbacks for wait ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
return true;

@@ -1054,6 +1063,6 @@ }

RESOLVE_REQUEST: async (data) => {
__privateGet(this, _logger2).debug("Handling RESOLVE_REQUEST", data);
__privateGet(this, _logger3).debug("Handling RESOLVE_REQUEST", data);
const requestCallbacks = __privateGet(this, _responseCompleteCallbacks).get(messageKey(data.meta.runId, data.key));
if (!requestCallbacks) {
__privateGet(this, _logger2).debug(`Could not find request callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
__privateGet(this, _logger3).debug(`Could not find request callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
return true;

@@ -1066,6 +1075,6 @@ }

REJECT_REQUEST: async (data) => {
__privateGet(this, _logger2).debug("Handling REJECT_REQUEST", data);
__privateGet(this, _logger3).debug("Handling REJECT_REQUEST", data);
const requestCallbacks = __privateGet(this, _responseCompleteCallbacks).get(messageKey(data.meta.runId, data.key));
if (!requestCallbacks) {
__privateGet(this, _logger2).debug(`Could not find request callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
__privateGet(this, _logger3).debug(`Could not find request callbacks for request ID ${messageKey(data.meta.runId, data.key)}. This can happen when a workflow run is resumed`);
return true;

@@ -1078,3 +1087,3 @@ }

TRIGGER_WORKFLOW: async (data) => {
__privateGet(this, _logger2).debug("Handling TRIGGER_WORKFLOW", data);
__privateGet(this, _logger3).debug("Handling TRIGGER_WORKFLOW", data);
const ctx = {

@@ -1148,3 +1157,3 @@ id: data.id,

const eventData = __privateGet(this, _options).on.schema.parse(data.trigger.input);
__privateGet(this, _logger2).debug("Parsed event data", eventData);
__privateGet(this, _logger3).debug("Parsed event data", eventData);
triggerRunLocalStorage.run({

@@ -1180,3 +1189,3 @@ performRequest: async (key, options) => {

}, () => {
__privateGet(this, _logger2).debug("Running trigger...");
__privateGet(this, _logger3).debug("Running trigger...");
serverRPC.send("START_WORKFLOW_RUN", {

@@ -1187,2 +1196,3 @@ runId: data.id,

return __privateGet(this, _trigger).options.run(eventData, ctx).then((output) => {
__privateGet(this, _logger3).log(`Completed workflow '${__privateGet(this, _options).name}', run ${data.id} \u{1F3C3}`);
return serverRPC.send("COMPLETE_WORKFLOW_RUN", {

@@ -1227,3 +1237,3 @@ runId: data.id,

});
__privateGet(this, _logger2).debug("Successfully initialized RPC with server");
__privateGet(this, _logger3).debug("Successfully initialized RPC with server");
__privateSet(this, _serverRPC, serverRPC);

@@ -1245,3 +1255,4 @@ }, "#initializeRPC");

packageVersion: version,
packageName: name
packageName: name,
triggerTTL: __privateGet(this, _options).triggerTTL
});

@@ -1251,3 +1262,3 @@ if (response?.type === "error") {

}
__privateGet(this, _logger2).debug("Successfully initialized workflow with server");
__privateGet(this, _logger3).debug("Successfully initialized workflow with server");
}, "#initializeHost");

@@ -1260,8 +1271,8 @@ _send = new WeakSet();

try {
__privateGet(this, _logger2).debug(`Sending RPC request to server: ${methodName}`, request);
__privateGet(this, _logger3).debug(`Sending RPC request to server: ${methodName}`, request);
return await __privateGet(this, _serverRPC).send(methodName, request);
} catch (err) {
if (err instanceof TimeoutError) {
__privateGet(this, _logger2).log(`RPC call timed out, retrying in ${Math.round(__privateGet(this, _retryIntervalMs) / 1e3)}s...`);
__privateGet(this, _logger2).error(err);
__privateGet(this, _logger3).log(`RPC call timed out, retrying in ${Math.round(__privateGet(this, _retryIntervalMs) / 1e3)}s...`);
__privateGet(this, _logger3).error(err);
await sleep(__privateGet(this, _retryIntervalMs));

@@ -1268,0 +1279,0 @@ } else {

{
"name": "@trigger.dev/sdk",
"version": "0.2.1",
"version": "0.2.2",
"description": "trigger.dev Node.JS SDK",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc