dooor-shared-config 0.2.0 → 0.3.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 +2 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/pubsubClient.d.ts +25 -19
- package/dist/pubsubClient.js +31 -20
- package/dist/pubsubClient.js.map +1 -1
- package/dist/topics.d.ts +18 -11
- package/dist/topics.js +26 -19
- package/dist/topics.js.map +1 -1
- package/dist/topics.json +2 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { SERVICES, getRequestTopic, getResponseTopic, parseResponseTopic, isRequestTopic, isResponseTopic, type ServiceKey, type ServiceTopic, } from "./topics";
|
|
1
|
+
export { SERVICES, getRequestTopic, getResponseTopic, getAppResponseTopic, parseResponseTopic, isRequestTopic, isResponseTopic, type ServiceKey, type ServiceTopic, } from "./topics";
|
|
2
2
|
export { createEnvelope, type AtlasEnvelope, type IngestionRequestPayload, type IngestionRequestMessage, type IngestionResponsePayload, type IngestionResponseMessage, type AiRequestPayload, type AiRequestMessage, type AiResponsePayload, type AiResponseMessage, type ExtractionRequestPayload, type ExtractionRequestMessage, type ExtractionResponsePayload, type ExtractionResponseMessage, type AtlasRequestMessage, type AtlasResponseMessage, type AtlasMessage, type AtlasRequestPayload, type AtlasResponsePayload, } from "./messages";
|
|
3
|
-
export { getPubSubClient, resetPubSubClient, getTopic, getServiceRequestTopic, getServiceResponseTopic, publishJson, publishRequest, publishResponse, subscribeToRequests, subscribeToResponses, createMessageConsumer, type MessageHandler, } from "./pubsubClient";
|
|
3
|
+
export { getPubSubClient, resetPubSubClient, getTopic, getServiceRequestTopic, getServiceResponseTopic, publishJson, publishRequest, publishResponse, publishToApp, subscribeToRequests, subscribeToResponses, createMessageConsumer, type MessageHandler, } from "./pubsubClient";
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createMessageConsumer = exports.subscribeToResponses = exports.subscribeToRequests = exports.publishResponse = exports.publishRequest = exports.publishJson = exports.getServiceResponseTopic = exports.getServiceRequestTopic = exports.getTopic = exports.resetPubSubClient = exports.getPubSubClient = exports.createEnvelope = exports.isResponseTopic = exports.isRequestTopic = exports.parseResponseTopic = exports.getResponseTopic = exports.getRequestTopic = exports.SERVICES = void 0;
|
|
3
|
+
exports.createMessageConsumer = exports.subscribeToResponses = exports.subscribeToRequests = exports.publishToApp = exports.publishResponse = exports.publishRequest = exports.publishJson = exports.getServiceResponseTopic = exports.getServiceRequestTopic = exports.getTopic = exports.resetPubSubClient = exports.getPubSubClient = exports.createEnvelope = exports.isResponseTopic = exports.isRequestTopic = exports.parseResponseTopic = exports.getAppResponseTopic = exports.getResponseTopic = exports.getRequestTopic = exports.SERVICES = void 0;
|
|
4
4
|
// Topics and topic utilities
|
|
5
5
|
var topics_1 = require("./topics");
|
|
6
6
|
Object.defineProperty(exports, "SERVICES", { enumerable: true, get: function () { return topics_1.SERVICES; } });
|
|
7
7
|
Object.defineProperty(exports, "getRequestTopic", { enumerable: true, get: function () { return topics_1.getRequestTopic; } });
|
|
8
8
|
Object.defineProperty(exports, "getResponseTopic", { enumerable: true, get: function () { return topics_1.getResponseTopic; } });
|
|
9
|
+
Object.defineProperty(exports, "getAppResponseTopic", { enumerable: true, get: function () { return topics_1.getAppResponseTopic; } });
|
|
9
10
|
Object.defineProperty(exports, "parseResponseTopic", { enumerable: true, get: function () { return topics_1.parseResponseTopic; } });
|
|
10
11
|
Object.defineProperty(exports, "isRequestTopic", { enumerable: true, get: function () { return topics_1.isRequestTopic; } });
|
|
11
12
|
Object.defineProperty(exports, "isResponseTopic", { enumerable: true, get: function () { return topics_1.isResponseTopic; } });
|
|
@@ -22,6 +23,7 @@ Object.defineProperty(exports, "getServiceResponseTopic", { enumerable: true, ge
|
|
|
22
23
|
Object.defineProperty(exports, "publishJson", { enumerable: true, get: function () { return pubsubClient_1.publishJson; } });
|
|
23
24
|
Object.defineProperty(exports, "publishRequest", { enumerable: true, get: function () { return pubsubClient_1.publishRequest; } });
|
|
24
25
|
Object.defineProperty(exports, "publishResponse", { enumerable: true, get: function () { return pubsubClient_1.publishResponse; } });
|
|
26
|
+
Object.defineProperty(exports, "publishToApp", { enumerable: true, get: function () { return pubsubClient_1.publishToApp; } });
|
|
25
27
|
Object.defineProperty(exports, "subscribeToRequests", { enumerable: true, get: function () { return pubsubClient_1.subscribeToRequests; } });
|
|
26
28
|
Object.defineProperty(exports, "subscribeToResponses", { enumerable: true, get: function () { return pubsubClient_1.subscribeToResponses; } });
|
|
27
29
|
Object.defineProperty(exports, "createMessageConsumer", { enumerable: true, get: function () { return pubsubClient_1.createMessageConsumer; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,mCAUkB;AAThB,kGAAA,QAAQ,OAAA;AACR,yGAAA,eAAe,OAAA;AACf,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,4GAAA,kBAAkB,OAAA;AAClB,wGAAA,cAAc,OAAA;AACd,yGAAA,eAAe,OAAA;AAKjB,4BAA4B;AAC5B,uCAoBoB;AAnBlB,0GAAA,cAAc,OAAA;AAqBhB,8BAA8B;AAC9B,+CAcwB;AAbtB,+GAAA,eAAe,OAAA;AACf,iHAAA,iBAAiB,OAAA;AACjB,wGAAA,QAAQ,OAAA;AACR,sHAAA,sBAAsB,OAAA;AACtB,uHAAA,uBAAuB,OAAA;AACvB,2GAAA,WAAW,OAAA;AACX,8GAAA,cAAc,OAAA;AACd,+GAAA,eAAe,OAAA;AACf,4GAAA,YAAY,OAAA;AACZ,mHAAA,mBAAmB,OAAA;AACnB,oHAAA,oBAAoB,OAAA;AACpB,qHAAA,qBAAqB,OAAA"}
|
package/dist/pubsubClient.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PubSub, type ClientConfig, type Topic, type Subscription, type Message } from "@google-cloud/pubsub";
|
|
2
|
-
import { SERVICES, getRequestTopic, getResponseTopic, type ServiceKey } from "./topics";
|
|
2
|
+
import { SERVICES, getRequestTopic, getResponseTopic, getAppResponseTopic, type ServiceKey } from "./topics";
|
|
3
3
|
import type { AtlasEnvelope } from "./messages";
|
|
4
4
|
/**
|
|
5
5
|
* Creates (or returns a cached) PubSub client.
|
|
@@ -20,9 +20,9 @@ export declare function getTopic(topicName: string, options?: ClientConfig): Top
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function getServiceRequestTopic(service: ServiceKey, options?: ClientConfig): Topic;
|
|
22
22
|
/**
|
|
23
|
-
* Get the response topic for a service
|
|
23
|
+
* Get the response topic for a service
|
|
24
24
|
*/
|
|
25
|
-
export declare function getServiceResponseTopic(service: ServiceKey,
|
|
25
|
+
export declare function getServiceResponseTopic(service: ServiceKey, options?: ClientConfig): Topic;
|
|
26
26
|
/**
|
|
27
27
|
* Helper to publish a JSON-encoded message to any topic
|
|
28
28
|
*/
|
|
@@ -41,21 +41,21 @@ export declare function publishJson(topicName: string, message: unknown, attribu
|
|
|
41
41
|
*/
|
|
42
42
|
export declare function publishRequest<T>(service: ServiceKey, message: AtlasEnvelope<T>, attributes?: Record<string, string>, pubSubOptions?: ClientConfig): Promise<string>;
|
|
43
43
|
/**
|
|
44
|
-
* Publish a response message
|
|
45
|
-
*
|
|
44
|
+
* Publish a response message to the service's fixed response topic.
|
|
45
|
+
* The appId is preserved in the message envelope so the cortex gateway
|
|
46
|
+
* can route it to the correct app.
|
|
46
47
|
*
|
|
47
48
|
* @example
|
|
48
|
-
* // Service
|
|
49
|
-
*
|
|
50
|
-
* await publishResponse("ingestion", "scaffold", {
|
|
49
|
+
* // Service publishes response to "ingestion-service-response"
|
|
50
|
+
* await publishResponse("ingestion", {
|
|
51
51
|
* action: "INGEST_RESPONSE",
|
|
52
|
-
* appId: "
|
|
52
|
+
* appId: "scaffold",
|
|
53
53
|
* correlationId: "uuid-123",
|
|
54
54
|
* timestamp: new Date().toISOString(),
|
|
55
55
|
* payload: { status: "success", recordId: "rec-456", uploadId: "file-123" }
|
|
56
56
|
* });
|
|
57
57
|
*/
|
|
58
|
-
export declare function publishResponse<T>(service: ServiceKey,
|
|
58
|
+
export declare function publishResponse<T>(service: ServiceKey, message: AtlasEnvelope<T>, attributes?: Record<string, string>, pubSubOptions?: ClientConfig): Promise<string>;
|
|
59
59
|
/**
|
|
60
60
|
* Subscribe to a service's request topic.
|
|
61
61
|
* Returns the subscription for attaching message handlers.
|
|
@@ -74,24 +74,22 @@ export declare function publishResponse<T>(service: ServiceKey, targetAppId: str
|
|
|
74
74
|
*/
|
|
75
75
|
export declare function subscribeToRequests(service: ServiceKey, subscriptionName: string, options?: ClientConfig): Promise<Subscription>;
|
|
76
76
|
/**
|
|
77
|
-
* Subscribe to responses
|
|
78
|
-
*
|
|
77
|
+
* Subscribe to responses from a service.
|
|
78
|
+
* Used by the cortex gateway to receive responses and route them to apps.
|
|
79
79
|
*
|
|
80
80
|
* @param service - The service to receive responses from
|
|
81
|
-
* @param appId - The app's identifier
|
|
82
81
|
* @param subscriptionName - Name of the subscription
|
|
83
82
|
* @param options - PubSub client options
|
|
84
83
|
*
|
|
85
84
|
* @example
|
|
86
|
-
*
|
|
87
|
-
* const sub = await subscribeToResponses("ingestion", "scaffold", "scaffold-ingestion-responses");
|
|
85
|
+
* const sub = await subscribeToResponses("ingestion", "cortex-ingestion-responses");
|
|
88
86
|
* sub.on("message", (message) => {
|
|
89
87
|
* const data = JSON.parse(message.data.toString());
|
|
90
|
-
* //
|
|
88
|
+
* // Route to app based on data.appId...
|
|
91
89
|
* message.ack();
|
|
92
90
|
* });
|
|
93
91
|
*/
|
|
94
|
-
export declare function subscribeToResponses(service: ServiceKey,
|
|
92
|
+
export declare function subscribeToResponses(service: ServiceKey, subscriptionName: string, options?: ClientConfig): Promise<Subscription>;
|
|
95
93
|
/**
|
|
96
94
|
* Helper type for message handlers
|
|
97
95
|
*/
|
|
@@ -110,5 +108,13 @@ export type MessageHandler<T> = (envelope: AtlasEnvelope<T>, message: Message, a
|
|
|
110
108
|
* }
|
|
111
109
|
* });
|
|
112
110
|
*/
|
|
113
|
-
export declare function createMessageConsumer<T>(subscription: Subscription, handler: MessageHandler<T>, onError?: (error: Error, message: Message) => void): void;
|
|
114
|
-
|
|
111
|
+
export declare function createMessageConsumer<T>(subscription: Subscription, handler: MessageHandler<T>, onError?: (error: Error, message: Message) => void): void; /**
|
|
112
|
+
* Publish a message to an app-specific response topic.
|
|
113
|
+
* Used by the cortex gateway to forward service responses to the correct app.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* await publishToApp("bi-app", responseEnvelope);
|
|
117
|
+
* // publishes to "bi-app-responses"
|
|
118
|
+
*/
|
|
119
|
+
export declare function publishToApp<T>(appId: string, message: AtlasEnvelope<T>, attributes?: Record<string, string>, pubSubOptions?: ClientConfig): Promise<string>;
|
|
120
|
+
export { SERVICES, getRequestTopic, getResponseTopic, getAppResponseTopic };
|
package/dist/pubsubClient.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getResponseTopic = exports.getRequestTopic = exports.SERVICES = void 0;
|
|
3
|
+
exports.getAppResponseTopic = exports.getResponseTopic = exports.getRequestTopic = exports.SERVICES = void 0;
|
|
4
4
|
exports.getPubSubClient = getPubSubClient;
|
|
5
5
|
exports.resetPubSubClient = resetPubSubClient;
|
|
6
6
|
exports.getTopic = getTopic;
|
|
@@ -12,11 +12,13 @@ exports.publishResponse = publishResponse;
|
|
|
12
12
|
exports.subscribeToRequests = subscribeToRequests;
|
|
13
13
|
exports.subscribeToResponses = subscribeToResponses;
|
|
14
14
|
exports.createMessageConsumer = createMessageConsumer;
|
|
15
|
+
exports.publishToApp = publishToApp;
|
|
15
16
|
const pubsub_1 = require("@google-cloud/pubsub");
|
|
16
17
|
const topics_1 = require("./topics");
|
|
17
18
|
Object.defineProperty(exports, "SERVICES", { enumerable: true, get: function () { return topics_1.SERVICES; } });
|
|
18
19
|
Object.defineProperty(exports, "getRequestTopic", { enumerable: true, get: function () { return topics_1.getRequestTopic; } });
|
|
19
20
|
Object.defineProperty(exports, "getResponseTopic", { enumerable: true, get: function () { return topics_1.getResponseTopic; } });
|
|
21
|
+
Object.defineProperty(exports, "getAppResponseTopic", { enumerable: true, get: function () { return topics_1.getAppResponseTopic; } });
|
|
20
22
|
let cachedPubSub = null;
|
|
21
23
|
/**
|
|
22
24
|
* Creates (or returns a cached) PubSub client.
|
|
@@ -50,10 +52,10 @@ function getServiceRequestTopic(service, options) {
|
|
|
50
52
|
return getTopic(topicName, options);
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
|
-
* Get the response topic for a service
|
|
55
|
+
* Get the response topic for a service
|
|
54
56
|
*/
|
|
55
|
-
function getServiceResponseTopic(service,
|
|
56
|
-
const topicName = (0, topics_1.getResponseTopic)(service
|
|
57
|
+
function getServiceResponseTopic(service, options) {
|
|
58
|
+
const topicName = (0, topics_1.getResponseTopic)(service);
|
|
57
59
|
return getTopic(topicName, options);
|
|
58
60
|
}
|
|
59
61
|
/**
|
|
@@ -81,22 +83,22 @@ async function publishRequest(service, message, attributes, pubSubOptions) {
|
|
|
81
83
|
return publishJson(topicName, message, attributes, pubSubOptions);
|
|
82
84
|
}
|
|
83
85
|
/**
|
|
84
|
-
* Publish a response message
|
|
85
|
-
*
|
|
86
|
+
* Publish a response message to the service's fixed response topic.
|
|
87
|
+
* The appId is preserved in the message envelope so the cortex gateway
|
|
88
|
+
* can route it to the correct app.
|
|
86
89
|
*
|
|
87
90
|
* @example
|
|
88
|
-
* // Service
|
|
89
|
-
*
|
|
90
|
-
* await publishResponse("ingestion", "scaffold", {
|
|
91
|
+
* // Service publishes response to "ingestion-service-response"
|
|
92
|
+
* await publishResponse("ingestion", {
|
|
91
93
|
* action: "INGEST_RESPONSE",
|
|
92
|
-
* appId: "
|
|
94
|
+
* appId: "scaffold",
|
|
93
95
|
* correlationId: "uuid-123",
|
|
94
96
|
* timestamp: new Date().toISOString(),
|
|
95
97
|
* payload: { status: "success", recordId: "rec-456", uploadId: "file-123" }
|
|
96
98
|
* });
|
|
97
99
|
*/
|
|
98
|
-
async function publishResponse(service,
|
|
99
|
-
const topicName = (0, topics_1.getResponseTopic)(service
|
|
100
|
+
async function publishResponse(service, message, attributes, pubSubOptions) {
|
|
101
|
+
const topicName = (0, topics_1.getResponseTopic)(service);
|
|
100
102
|
return publishJson(topicName, message, attributes, pubSubOptions);
|
|
101
103
|
}
|
|
102
104
|
/**
|
|
@@ -132,26 +134,24 @@ async function subscribeToRequests(service, subscriptionName, options) {
|
|
|
132
134
|
return subscription;
|
|
133
135
|
}
|
|
134
136
|
/**
|
|
135
|
-
* Subscribe to responses
|
|
136
|
-
*
|
|
137
|
+
* Subscribe to responses from a service.
|
|
138
|
+
* Used by the cortex gateway to receive responses and route them to apps.
|
|
137
139
|
*
|
|
138
140
|
* @param service - The service to receive responses from
|
|
139
|
-
* @param appId - The app's identifier
|
|
140
141
|
* @param subscriptionName - Name of the subscription
|
|
141
142
|
* @param options - PubSub client options
|
|
142
143
|
*
|
|
143
144
|
* @example
|
|
144
|
-
*
|
|
145
|
-
* const sub = await subscribeToResponses("ingestion", "scaffold", "scaffold-ingestion-responses");
|
|
145
|
+
* const sub = await subscribeToResponses("ingestion", "cortex-ingestion-responses");
|
|
146
146
|
* sub.on("message", (message) => {
|
|
147
147
|
* const data = JSON.parse(message.data.toString());
|
|
148
|
-
* //
|
|
148
|
+
* // Route to app based on data.appId...
|
|
149
149
|
* message.ack();
|
|
150
150
|
* });
|
|
151
151
|
*/
|
|
152
|
-
async function subscribeToResponses(service,
|
|
152
|
+
async function subscribeToResponses(service, subscriptionName, options) {
|
|
153
153
|
const client = getPubSubClient(options);
|
|
154
|
-
const topicName = (0, topics_1.getResponseTopic)(service
|
|
154
|
+
const topicName = (0, topics_1.getResponseTopic)(service);
|
|
155
155
|
const subscription = client.subscription(subscriptionName);
|
|
156
156
|
const [exists] = await subscription.exists();
|
|
157
157
|
if (!exists) {
|
|
@@ -197,5 +197,16 @@ function createMessageConsumer(subscription, handler, onError) {
|
|
|
197
197
|
subscription.on("error", (err) => {
|
|
198
198
|
console.error("[PubSub] Subscription error:", err);
|
|
199
199
|
});
|
|
200
|
+
} /**
|
|
201
|
+
* Publish a message to an app-specific response topic.
|
|
202
|
+
* Used by the cortex gateway to forward service responses to the correct app.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* await publishToApp("bi-app", responseEnvelope);
|
|
206
|
+
* // publishes to "bi-app-responses"
|
|
207
|
+
*/
|
|
208
|
+
async function publishToApp(appId, message, attributes, pubSubOptions) {
|
|
209
|
+
const topicName = (0, topics_1.getAppResponseTopic)(appId);
|
|
210
|
+
return publishJson(topicName, message, attributes, pubSubOptions);
|
|
200
211
|
}
|
|
201
212
|
//# sourceMappingURL=pubsubClient.js.map
|
package/dist/pubsubClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsubClient.js","sourceRoot":"","sources":["../src/pubsubClient.ts"],"names":[],"mappings":";;;AAWA,0CAKC;AAKD,8CAEC;AAKD,4BAGC;AAKD,wDAGC;AAKD,0DAGC;AAKD,kCASC;AAcD,wCAQC;AAiBD,
|
|
1
|
+
{"version":3,"file":"pubsubClient.js","sourceRoot":"","sources":["../src/pubsubClient.ts"],"names":[],"mappings":";;;AAWA,0CAKC;AAKD,8CAEC;AAKD,4BAGC;AAKD,wDAGC;AAKD,0DAGC;AAKD,k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CAAC,IAAI,CAAC,QAAQ,EAAE,CAAqB,CAAC;YACzE,MAAM,OAAO,CACX,QAAQ,EACR,OAAO,EACP,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EACnB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CACrB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAY,EAAE,OAAO,CAAC,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;gBACzD,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QAC/B,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAA;;;;;;;GAOE;AACI,KAAK,UAAU,YAAY,CAChC,KAAa,EACb,OAAyB,EACzB,UAAmC,EACnC,aAA4B;IAE5B,MAAM,SAAS,GAAG,IAAA,4BAAmB,EAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;AACpE,CAAC"}
|
package/dist/topics.d.ts
CHANGED
|
@@ -18,27 +18,26 @@ export type ServiceTopic = (typeof SERVICES)[ServiceKey];
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function getRequestTopic(service: ServiceKey): ServiceTopic;
|
|
20
20
|
/**
|
|
21
|
-
* Get the response topic for a service
|
|
22
|
-
* Response topics are
|
|
21
|
+
* Get the response topic for a service.
|
|
22
|
+
* Response topics are fixed per service: "{service}-response"
|
|
23
23
|
*
|
|
24
|
-
*
|
|
25
|
-
* responses
|
|
24
|
+
* The appId is included in the message envelope so the cortex gateway
|
|
25
|
+
* can route responses to the correct app.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
|
-
* getResponseTopic("ingestion"
|
|
29
|
-
* getResponseTopic("ai"
|
|
28
|
+
* getResponseTopic("ingestion") // => "ingestion-service-response"
|
|
29
|
+
* getResponseTopic("ai") // => "ai-service-response"
|
|
30
30
|
*/
|
|
31
|
-
export declare function getResponseTopic(service: ServiceKey
|
|
31
|
+
export declare function getResponseTopic(service: ServiceKey): string;
|
|
32
32
|
/**
|
|
33
|
-
* Parse a response topic to extract service
|
|
33
|
+
* Parse a response topic to extract the service
|
|
34
34
|
*
|
|
35
35
|
* @example
|
|
36
|
-
* parseResponseTopic("ingestion-service-response
|
|
37
|
-
* // => { service: "ingestion"
|
|
36
|
+
* parseResponseTopic("ingestion-service-response")
|
|
37
|
+
* // => { service: "ingestion" }
|
|
38
38
|
*/
|
|
39
39
|
export declare function parseResponseTopic(topic: string): {
|
|
40
40
|
service: ServiceKey | null;
|
|
41
|
-
appId: string | null;
|
|
42
41
|
};
|
|
43
42
|
/**
|
|
44
43
|
* Check if a topic is a request topic
|
|
@@ -48,4 +47,12 @@ export declare function isRequestTopic(topic: string): boolean;
|
|
|
48
47
|
* Check if a topic is a response topic
|
|
49
48
|
*/
|
|
50
49
|
export declare function isResponseTopic(topic: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Get the response topic for a specific app.
|
|
52
|
+
* Used by the cortex gateway to forward service responses to the correct app.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* getAppResponseTopic("bi-app") // => "bi-app-responses"
|
|
56
|
+
*/
|
|
57
|
+
export declare function getAppResponseTopic(appId: string): string;
|
|
51
58
|
export { topicsConfig };
|
package/dist/topics.js
CHANGED
|
@@ -9,6 +9,7 @@ exports.getResponseTopic = getResponseTopic;
|
|
|
9
9
|
exports.parseResponseTopic = parseResponseTopic;
|
|
10
10
|
exports.isRequestTopic = isRequestTopic;
|
|
11
11
|
exports.isResponseTopic = isResponseTopic;
|
|
12
|
+
exports.getAppResponseTopic = getAppResponseTopic;
|
|
12
13
|
const topics_json_1 = __importDefault(require("./topics.json"));
|
|
13
14
|
exports.topicsConfig = topics_json_1.default;
|
|
14
15
|
/**
|
|
@@ -26,39 +27,35 @@ function getRequestTopic(service) {
|
|
|
26
27
|
return exports.SERVICES[service];
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
|
-
* Get the response topic for a service
|
|
30
|
-
* Response topics are
|
|
30
|
+
* Get the response topic for a service.
|
|
31
|
+
* Response topics are fixed per service: "{service}-response"
|
|
31
32
|
*
|
|
32
|
-
*
|
|
33
|
-
* responses
|
|
33
|
+
* The appId is included in the message envelope so the cortex gateway
|
|
34
|
+
* can route responses to the correct app.
|
|
34
35
|
*
|
|
35
36
|
* @example
|
|
36
|
-
* getResponseTopic("ingestion"
|
|
37
|
-
* getResponseTopic("ai"
|
|
37
|
+
* getResponseTopic("ingestion") // => "ingestion-service-response"
|
|
38
|
+
* getResponseTopic("ai") // => "ai-service-response"
|
|
38
39
|
*/
|
|
39
|
-
function getResponseTopic(service
|
|
40
|
+
function getResponseTopic(service) {
|
|
40
41
|
const serviceTopic = exports.SERVICES[service];
|
|
41
|
-
return `${serviceTopic}${topics_json_1.default.responsePrefix}
|
|
42
|
+
return `${serviceTopic}${topics_json_1.default.responsePrefix}`;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
|
-
* Parse a response topic to extract service
|
|
45
|
+
* Parse a response topic to extract the service
|
|
45
46
|
*
|
|
46
47
|
* @example
|
|
47
|
-
* parseResponseTopic("ingestion-service-response
|
|
48
|
-
* // => { service: "ingestion"
|
|
48
|
+
* parseResponseTopic("ingestion-service-response")
|
|
49
|
+
* // => { service: "ingestion" }
|
|
49
50
|
*/
|
|
50
51
|
function parseResponseTopic(topic) {
|
|
51
52
|
const responsePrefix = topics_json_1.default.responsePrefix;
|
|
52
53
|
for (const [key, serviceTopic] of Object.entries(exports.SERVICES)) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
service: key,
|
|
57
|
-
appId: topic.slice(prefix.length),
|
|
58
|
-
};
|
|
54
|
+
if (topic === `${serviceTopic}${responsePrefix}`) {
|
|
55
|
+
return { service: key };
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
|
-
return { service: null
|
|
58
|
+
return { service: null };
|
|
62
59
|
}
|
|
63
60
|
/**
|
|
64
61
|
* Check if a topic is a request topic
|
|
@@ -71,6 +68,16 @@ function isRequestTopic(topic) {
|
|
|
71
68
|
*/
|
|
72
69
|
function isResponseTopic(topic) {
|
|
73
70
|
const responsePrefix = topics_json_1.default.responsePrefix;
|
|
74
|
-
return Object.values(exports.SERVICES).some(serviceTopic => topic
|
|
71
|
+
return Object.values(exports.SERVICES).some(serviceTopic => topic === `${serviceTopic}${responsePrefix}`);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get the response topic for a specific app.
|
|
75
|
+
* Used by the cortex gateway to forward service responses to the correct app.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* getAppResponseTopic("bi-app") // => "bi-app-responses"
|
|
79
|
+
*/
|
|
80
|
+
function getAppResponseTopic(appId) {
|
|
81
|
+
return `${appId}${topics_json_1.default.appResponseSuffix}`;
|
|
75
82
|
}
|
|
76
83
|
//# sourceMappingURL=topics.js.map
|
package/dist/topics.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topics.js","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":";;;;;;AAgBA,0CAEC;AAaD,4CAGC;AASD,
|
|
1
|
+
{"version":3,"file":"topics.js","sourceRoot":"","sources":["../src/topics.ts"],"names":[],"mappings":";;;;;;AAgBA,0CAEC;AAaD,4CAGC;AASD,gDAUC;AAKD,wCAEC;AAKD,0CAKC;AASD,kDAEC;AAjFD,gEAAyC;AAoFhC,uBApFF,qBAAY,CAoFE;AAlFrB;;GAEG;AACU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