Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/modules/Analysis/Analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TagoIOModule from "../../common/TagoIOModule.ts";
import { openSSEListening } from "../../infrastructure/apiSSE.ts";
import getRegionObj, { setRuntimeRegion } from "../../regions.ts";
import ConsoleService from "../Services/Console.ts";
import type { AnalysisConstructorParams, AnalysisEnvironment, analysisFunction } from "./analysis.types.ts";
import type { AnalysisConstructorParams, AnalysisEnvironment, analysisFunction, AnalysisItem } from "./analysis.types.ts";

/**
* Analysis execution context for TagoIO
Expand Down Expand Up @@ -211,6 +211,15 @@ class Analysis extends TagoIOModule<AnalysisConstructorParams> {

return new Analysis(analysis, params);
}

public async info(): Promise<AnalysisItem> {
const result = await this.doRequest<AnalysisItem>({
path: "/info",
method: "GET",
});

return result;
}
}

export default Analysis;
10 changes: 9 additions & 1 deletion src/modules/Analysis/analysis.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Regions, RegionsObj } from "../../regions.ts";
import type { GenericID } from "../../common/common.types.ts";

type analysisFunction = (context: any, data: any) => any;

Expand All @@ -24,6 +25,13 @@ interface AnalysisConstructorParams {
loadEnvOnProcess?: boolean;
}

interface AnalysisItem {
id: GenericID;
name: string;
run_on: "tago" | "external";
active: boolean;
}

interface AnalysisEnvironment {
[key: string]: string;
}
Expand All @@ -40,4 +48,4 @@ interface TagoContext {
log: (...args: any[]) => void;
}

export type { AnalysisConstructorParams, analysisFunction, AnalysisEnvironment, TagoContext };
export type { AnalysisConstructorParams, analysisFunction, AnalysisEnvironment, TagoContext, AnalysisItem };
5 changes: 4 additions & 1 deletion src/modules/Services/PDF.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TagoIOModule, { type GenericModuleParams } from "../../common/TagoIOModule.ts";
import { getTDeployRegion } from "../../regions.ts";

interface PDFResult {
status: boolean;
Expand Down Expand Up @@ -92,7 +93,9 @@ class PDFService extends TagoIOModule<GenericModuleParams> {
*/
public async generate(params: PDFParams): Promise<PDFResult> {
try {
const response = await fetch("https://pdf.middleware.tago.io", {
const tdeploy = getTDeployRegion(this.params.region);
const pdfUri = tdeploy ? `https://pdf.${tdeploy}.tagoio.net` : "https://pdf.middleware.tago.io";
const response = await fetch(pdfUri, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
22 changes: 16 additions & 6 deletions src/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,31 @@ const regionsDefinition: Record<string, RegionsObjApi | undefined> = {
/** Runtime region cache */
let runtimeRegion: RegionsObj | undefined;

/**
* Extracts TDeploy region configuration if present
* @param region Region configuration
* @returns TDeploy id or undefined
*/
function getTDeployRegion(region?: Regions | RegionsObj): string {
if (region && typeof region === "object" && "tdeploy" in region && region.tdeploy) {
return region.tdeploy.trim();
}
return undefined;
}

/**
* Get connection URI for Realtime and API
* @internal
* @param region Region
*/
function getConnectionURI(region?: Regions | RegionsObj): RegionsObj {
// Handle tdeploy in RegionsObj - takes precedence
if (region && typeof region === "object" && "tdeploy" in region && region.tdeploy) {
const tdeploy = region.tdeploy.trim();
if (tdeploy) {
return {
const tdeploy = getTDeployRegion(region);
if (tdeploy) {
return {
api: `https://api.${tdeploy}.tagoio.net`,
sse: `https://sse.${tdeploy}.tagoio.net/events`,
};
}
}

let normalizedRegion = region;
Expand Down Expand Up @@ -138,4 +148,4 @@ function setRuntimeRegion(region: RegionsObj): void {

export default getConnectionURI;
export type { Regions, RegionsObj };
export { regionsDefinition, setRuntimeRegion };
export { regionsDefinition, setRuntimeRegion, getTDeployRegion };