unnbound-events 2.0.18 → 2.0.19-staging.0

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/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export type { IncomingEvent, IncomingRequest, EventMetadata, EventSource } from './lib/event';
2
2
  export type { ServerErrorOptions } from './lib/error';
3
3
  export type { EventServerOptions, EventServer } from './lib/server';
4
+ export type { Handler } from './lib/routing/endpoint';
5
+ export type { MiddlewareHandler } from './lib/routing/middleware';
6
+ export type { EventVariables, MaybePromise } from './lib/routing/types';
4
7
  export { createServer } from './lib/server';
5
8
  export { ServerError } from './lib/error';
6
9
  export { createEnqueuer } from './lib/enqueue';
@@ -24,7 +24,8 @@ const getWorkspaceId = (url) => {
24
24
  if (!url.includes('gotemper.com') && !url.includes('unnbound.ai')) {
25
25
  return url
26
26
  .replace(/^.+?\/(.+)$/, '$1')
27
- .replace(/^(sandbox\/)?a?sync\//, '')
27
+ .replace(/^(sandbox|staging)\//, '')
28
+ .replace(/^a?sync\//, '')
28
29
  .split('/')[0];
29
30
  }
30
31
  // New path-based format: {env}.workflow.gotemper.com/{sandbox/}{shortId} or workflow.gotemper.com/{sandbox/}{shortId}
@@ -32,19 +33,31 @@ const getWorkspaceId = (url) => {
32
33
  // Extract everything after the domain, then remove sandbox/ and async/ prefixes
33
34
  const path = url.replace(/^.+?\/(.+)$/, '$1');
34
35
  return path
35
- .replace(/^sandbox\//, '')
36
+ .replace(/^(sandbox|staging)\//, '')
36
37
  .replace(/^a?sync\//, '')
37
38
  .split('/')[0];
38
39
  }
39
40
  // Legacy hostname format: {shortId}.workspaces.{env}.unnbound.ai
40
41
  return url.split('.')[0];
41
42
  };
43
+ const TYPE_PATH_PREFIXES = {
44
+ sandbox: '/sandbox',
45
+ staging: '/staging',
46
+ production: '',
47
+ };
42
48
  /**
43
- * Check if the workflow URL indicates a sandbox environment
49
+ * Detect workflow type from the URL path.
50
+ * Only checks the path to avoid false positives on hostnames like staging.example.com.
44
51
  */
45
- const isSandboxUrl = (url) => {
46
- // Check if URL contains /sandbox/ path
47
- return url.includes('/sandbox/') || url.includes('/sandbox');
52
+ const getWorkflowType = (url) => {
53
+ const withoutProtocol = url.replace(/^https?:\/\//, '');
54
+ const slashIndex = withoutProtocol.indexOf('/');
55
+ const path = slashIndex === -1 ? '' : withoutProtocol.substring(slashIndex);
56
+ if (path.startsWith('/sandbox'))
57
+ return 'sandbox';
58
+ if (path.startsWith('/staging'))
59
+ return 'staging';
60
+ return 'production';
48
61
  };
49
62
  /**
50
63
  * Extract workflow domain from URL
@@ -88,31 +101,23 @@ const getWorkflowDomain = (url) => {
88
101
  // Custom domain - return hostname as-is
89
102
  return hostname;
90
103
  };
91
- // Generate a simple UUID v4
92
- const _generateId = () => {
93
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
94
- const r = (Math.random() * 16) | 0;
95
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
96
- return v.toString(16);
97
- });
98
- };
99
104
  /**
100
105
  * Create an HTTP-based enqueuer that posts to the ingress service.
101
106
  * Used for legacy SQS mode or cross-workflow communication.
102
107
  *
103
108
  * URL format:
104
109
  * - Sandbox: https://{env}.dev.workflow.gotemper.com/sandbox/async/{shortId} (dev) or https://workflow.gotemper.com/sandbox/async/{shortId} (prod)
110
+ * - Staging: https://{env}.dev.workflow.gotemper.com/staging/async/{shortId} (dev) or https://workflow.gotemper.com/staging/async/{shortId} (prod)
105
111
  * - Production: https://{env}.dev.workflow.gotemper.com/async/{shortId} (dev) or https://workflow.gotemper.com/async/{shortId} (prod)
106
112
  */
107
113
  const createHttpEnqueuer = () => {
108
114
  const url = process.env.UNNBOUND_WORKFLOW_URL;
109
115
  if (!url)
110
116
  throw new Error('UNNBOUND_WORKFLOW_URL is not configured. Reach out to support.');
111
- // Construct base URL with sandbox prefix if applicable
112
117
  const workspaceId = getWorkspaceId(url);
113
118
  const domain = getWorkflowDomain(url);
114
- const sandboxPrefix = isSandboxUrl(url) ? '/sandbox' : '';
115
- const baseURL = `https://${domain}${sandboxPrefix}/async/${workspaceId}`;
119
+ const workflowType = getWorkflowType(url);
120
+ const baseURL = `https://${domain}${TYPE_PATH_PREFIXES[workflowType]}/async/${workspaceId}`;
116
121
  const client = (0, unnbound_logger_sdk_1.traceAxios)(axios_1.default.create({ baseURL }), { getPayload: internal_1.internal });
117
122
  return async (event, metadata) => {
118
123
  unnbound_logger_sdk_1.logger.info({ event, metadata }, 'Enqueuing event via HTTP...');
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.attachTraceHeaders = exports.respondWith = exports.patchEndpoint = exports.parseEndpointArguments = exports.buildEndpointArguments = void 0;
4
4
  const unnbound_logger_sdk_1 = require("unnbound-logger-sdk");
5
- const storage_1 = require("unnbound-logger-sdk/dist/storage");
6
- const types_1 = require("unnbound-logger-sdk/dist/types");
7
5
  const utils_1 = require("../utils");
8
6
  const middleware_1 = require("./middleware");
9
7
  const buildEndpointArguments = (...args) => {
@@ -39,13 +37,13 @@ const respondWith = (context, result) => {
39
37
  };
40
38
  exports.respondWith = respondWith;
41
39
  const attachTraceHeaders = (headers) => {
42
- const { traceId, messageId } = storage_1.storage.getStore() ?? {};
40
+ const { traceId, messageId } = unnbound_logger_sdk_1.storage.getStore() ?? {};
43
41
  if (!traceId || !messageId)
44
42
  return headers;
45
43
  return {
46
44
  ...headers,
47
- [types_1.defaultTraceHeaderKey]: headers?.[types_1.defaultTraceHeaderKey] ?? traceId,
48
- [types_1.defaultMessageHeaderKey]: headers?.[types_1.defaultMessageHeaderKey] ?? messageId,
45
+ [unnbound_logger_sdk_1.defaultTraceHeaderKey]: headers?.[unnbound_logger_sdk_1.defaultTraceHeaderKey] ?? traceId,
46
+ [unnbound_logger_sdk_1.defaultMessageHeaderKey]: headers?.[unnbound_logger_sdk_1.defaultMessageHeaderKey] ?? messageId,
49
47
  };
50
48
  };
51
49
  exports.attachTraceHeaders = attachTraceHeaders;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "unnbound-events",
3
3
  "description": "Unified events SDK to handle HTTP routes and queued messages with a single routing API.",
4
- "version": "2.0.18",
4
+ "version": "2.0.19-staging.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "build": "tsc",
8
+ "build": "bun x tsc",
9
9
  "test": "echo 'No tests'",
10
10
  "typecheck": "tsc -noEmit",
11
11
  "lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
@@ -29,9 +29,9 @@
29
29
  "dependencies": {
30
30
  "@aws-sdk/client-s3": "^3.0.0",
31
31
  "@aws-sdk/client-sqs": "^3.0.0",
32
- "@hono/node-server": "^1.19.6",
32
+ "@hono/node-server": "^1.19.11",
33
33
  "axios": "^1.12.2",
34
- "hono": "^4.11.4",
34
+ "hono": "^4.12.7",
35
35
  "ioredis": "^5.4.1",
36
36
  "unnbound-logger-sdk": "^3.0.34"
37
37
  },