@uns-kit/core 0.0.31 → 0.0.34

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../src/app-config.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,SAAS,GAAG;IACpB,GAAG,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC;QAC7C,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACtC,eAAe,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QACrC,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;KAC7C,CAAC;IACF,KAAK,CAAC,EAAE;QACJ,IAAI,EAAE,MAAM,GAAG,CAAC;YACZ,2CAA2C;YAC3C,QAAQ,EAAE,QAAQ,CAAC;YACnB,uDAAuD;YACvD,KAAK,EAAE,MAAM,CAAC;SACjB,GAAG;YACA,iDAAiD;YACjD,QAAQ,EAAE,UAAU,CAAC;YACrB,wEAAwE;YACxE,GAAG,EAAE,MAAM,CAAC;YACZ,gFAAgF;YAChF,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;YAC/B,6EAA6E;YAC7E,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;SAChC,GAAG;YACA,sDAAsD;YACtD,QAAQ,EAAE,QAAQ,CAAC;YACnB,yDAAyD;YACzD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;YACzB,+EAA+E;YAC/E,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACnC,6EAA6E;YAC7E,QAAQ,CAAC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,GAAG,SAAS,CAAC;YAC/B,4EAA4E;YAC5E,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YACjC,wEAAwE;YACxE,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;YAC/B,oFAAoF;YACpF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;SAChC,CAAC,CAAC,GAAG,SAAS,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC,CAAC;IACF,MAAM,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAChC,GAAG,SAAS,CAAC;CACjB,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../src/app-config.ts"],"names":[],"mappings":"","sourcesContent":["/* Auto-generated. Do not edit by hand. */\nexport type AppConfig = {\n uns: {\n graphql: string;\n rest: string;\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n processName?: string | undefined;\n handover?: boolean;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n input?: {\n host: string | ({\n /** Use the supplied host or IP address. */\n provider: \"inline\";\n /** Host or IP address that should be used directly. */\n value: string;\n } | {\n /** Resolve the host from an external mapping. */\n provider: \"external\";\n /** Identifier used when resolving the host from HostResolverOptions. */\n key: string;\n /** Allow the external host to be missing without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host when optional is true and the external entry is missing. */\n default?: string | undefined;\n } | {\n /** Resolve the host from local network interfaces. */\n provider: \"system\";\n /** Address family to return when scanning interfaces. */\n family?: \"IPv4\" | \"IPv6\";\n /** Specific interface to read (falls back to the first match when omitted). */\n interfaceName?: string | undefined;\n /** Allow the interface lookup to fail without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host/IP when optional is true and no interface matches. */\n default?: string | undefined;\n });\n username?: string | undefined;\n password?: (string | ({\n /** Load the secret from an environment variable. */\n provider: \"env\";\n /** Name of the environment variable to read. */\n key: string;\n /** Allow the variable to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback value when optional is true and the variable is missing. */\n default?: string | undefined;\n } | {\n /** Load the secret from Infisical. */\n provider: \"infisical\";\n /** Secret folder path in Infisical, e.g. '/app/database'. */\n path: string;\n /** Secret key/name inside the given path. */\n key: string;\n /** Allow the secret to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Infisical environment override (defaults to current mode if omitted). */\n environment?: string | undefined;\n /** Optional Infisical project identifier when not using the default. */\n projectId?: string | undefined;\n /** Fallback value when the secret is missing and optional resolution is allowed. */\n default?: string | undefined;\n })) | undefined;\n clientId?: string | undefined;\n } | undefined;\n output?: {\n host: string | ({\n /** Use the supplied host or IP address. */\n provider: \"inline\";\n /** Host or IP address that should be used directly. */\n value: string;\n } | {\n /** Resolve the host from an external mapping. */\n provider: \"external\";\n /** Identifier used when resolving the host from HostResolverOptions. */\n key: string;\n /** Allow the external host to be missing without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host when optional is true and the external entry is missing. */\n default?: string | undefined;\n } | {\n /** Resolve the host from local network interfaces. */\n provider: \"system\";\n /** Address family to return when scanning interfaces. */\n family?: \"IPv4\" | \"IPv6\";\n /** Specific interface to read (falls back to the first match when omitted). */\n interfaceName?: string | undefined;\n /** Allow the interface lookup to fail without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host/IP when optional is true and no interface matches. */\n default?: string | undefined;\n });\n username?: string | undefined;\n password?: (string | ({\n /** Load the secret from an environment variable. */\n provider: \"env\";\n /** Name of the environment variable to read. */\n key: string;\n /** Allow the variable to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback value when optional is true and the variable is missing. */\n default?: string | undefined;\n } | {\n /** Load the secret from Infisical. */\n provider: \"infisical\";\n /** Secret folder path in Infisical, e.g. '/app/database'. */\n path: string;\n /** Secret key/name inside the given path. */\n key: string;\n /** Allow the secret to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Infisical environment override (defaults to current mode if omitted). */\n environment?: string | undefined;\n /** Optional Infisical project identifier when not using the default. */\n projectId?: string | undefined;\n /** Fallback value when the secret is missing and optional resolution is allowed. */\n default?: string | undefined;\n })) | undefined;\n clientId?: string | undefined;\n } | undefined;\n infra: {\n host: string | ({\n /** Use the supplied host or IP address. */\n provider: \"inline\";\n /** Host or IP address that should be used directly. */\n value: string;\n } | {\n /** Resolve the host from an external mapping. */\n provider: \"external\";\n /** Identifier used when resolving the host from HostResolverOptions. */\n key: string;\n /** Allow the external host to be missing without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host when optional is true and the external entry is missing. */\n default?: string | undefined;\n } | {\n /** Resolve the host from local network interfaces. */\n provider: \"system\";\n /** Address family to return when scanning interfaces. */\n family?: \"IPv4\" | \"IPv6\";\n /** Specific interface to read (falls back to the first match when omitted). */\n interfaceName?: string | undefined;\n /** Allow the interface lookup to fail without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback host/IP when optional is true and no interface matches. */\n default?: string | undefined;\n });\n username?: string | undefined;\n password?: (string | ({\n /** Load the secret from an environment variable. */\n provider: \"env\";\n /** Name of the environment variable to read. */\n key: string;\n /** Allow the variable to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback value when optional is true and the variable is missing. */\n default?: string | undefined;\n } | {\n /** Load the secret from Infisical. */\n provider: \"infisical\";\n /** Secret folder path in Infisical, e.g. '/app/database'. */\n path: string;\n /** Secret key/name inside the given path. */\n key: string;\n /** Allow the secret to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Infisical environment override (defaults to current mode if omitted). */\n environment?: string | undefined;\n /** Optional Infisical project identifier when not using the default. */\n projectId?: string | undefined;\n /** Fallback value when the secret is missing and optional resolution is allowed. */\n default?: string | undefined;\n })) | undefined;\n clientId?: string | undefined;\n };\n devops?: {\n provider?: string | undefined;\n organization: string;\n project?: string | undefined;\n } | undefined;\n}\n"]}
@@ -2,6 +2,34 @@ export interface ProjectAppConfig {
2
2
  uns: {
3
3
  graphql: string;
4
4
  rest: string;
5
+ /** Email used when authenticating to graphql endpoint of the UNS instance. */
6
+ email: string;
7
+ /** Password or secret value paired with the UNS email. */
8
+ password: string | ({
9
+ /** Load the secret from an environment variable. */
10
+ provider: "env";
11
+ /** Name of the environment variable to read. */
12
+ key: string;
13
+ /** Allow the variable to be absent without throwing during resolution. */
14
+ optional?: boolean | undefined;
15
+ /** Fallback value when optional is true and the variable is missing. */
16
+ default?: string | undefined;
17
+ } | {
18
+ /** Load the secret from Infisical. */
19
+ provider: "infisical";
20
+ /** Secret folder path in Infisical, e.g. '/app/database'. */
21
+ path: string;
22
+ /** Secret key/name inside the given path. */
23
+ key: string;
24
+ /** Allow the secret to be absent without throwing during resolution. */
25
+ optional?: boolean | undefined;
26
+ /** Infisical environment override (defaults to current mode if omitted). */
27
+ environment?: string | undefined;
28
+ /** Optional Infisical project identifier when not using the default. */
29
+ projectId?: string | undefined;
30
+ /** Fallback value when the secret is missing and optional resolution is allowed. */
31
+ default?: string | undefined;
32
+ });
5
33
  instanceMode?: "wait" | "force" | "handover";
6
34
  processName?: string | undefined;
7
35
  handover?: boolean;
@@ -35,8 +63,4 @@ export interface ProjectAppConfig {
35
63
  }
36
64
  export interface AppConfig extends ProjectAppConfig {
37
65
  }
38
- declare module "@uns-kit/core/config/app-config.js" {
39
- interface AppConfig extends ProjectAppConfig {
40
- }
41
- }
42
66
  //# sourceMappingURL=app-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-config.d.ts","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,gBAAgB;IAC7B,GAAG,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,YAAY,CAAC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S,GAAG,MAAM,GAAG,MAAM,CAAC;KAC7C,CAAC;IACF,KAAK,CAAC,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC,GAAG,SAAS,CAAC;IACd,MAAM,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC,GAAG,SAAS,CAAC;IACd,KAAK,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACjC,CAAC;IACF,MAAM,CAAC,EAAE;QACL,QAAQ,CAAC,EAAE,cAAc,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KAChC,GAAG,SAAS,CAAC;CACjB;AAED,MAAM,WAAW,SAAU,SAAQ,gBAAgB;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"","sourcesContent":["/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig {\n uns: {\n graphql: string;\n rest: string;\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n processName?: string | undefined;\n handover?: boolean;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n input?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n output?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n infra: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n };\n devops?: {\n provider?: \"azure-devops\";\n organization: string;\n project?: string | undefined;\n } | undefined;\n}\n\nexport interface AppConfig extends ProjectAppConfig {}\n\ndeclare module \"@uns-kit/core/config/app-config.js\" {\n interface AppConfig extends ProjectAppConfig {}\n}\n"]}
1
+ {"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../src/config/app-config.ts"],"names":[],"mappings":"","sourcesContent":["/* Auto-generated. Do not edit by hand. */\nexport interface ProjectAppConfig {\n uns: {\n graphql: string;\n rest: string;\n /** Email used when authenticating to graphql endpoint of the UNS instance. */\n email: string;\n /** Password or secret value paired with the UNS email. */\n password: string | ({\n /** Load the secret from an environment variable. */\n provider: \"env\";\n /** Name of the environment variable to read. */\n key: string;\n /** Allow the variable to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Fallback value when optional is true and the variable is missing. */\n default?: string | undefined;\n } | {\n /** Load the secret from Infisical. */\n provider: \"infisical\";\n /** Secret folder path in Infisical, e.g. '/app/database'. */\n path: string;\n /** Secret key/name inside the given path. */\n key: string;\n /** Allow the secret to be absent without throwing during resolution. */\n optional?: boolean | undefined;\n /** Infisical environment override (defaults to current mode if omitted). */\n environment?: string | undefined;\n /** Optional Infisical project identifier when not using the default. */\n projectId?: string | undefined;\n /** Fallback value when the secret is missing and optional resolution is allowed. */\n default?: string | undefined;\n });\n instanceMode?: \"wait\" | \"force\" | \"handover\";\n processName?: string | undefined;\n handover?: boolean;\n jwksWellKnownUrl?: string | undefined;\n kidWellKnownUrl?: string | undefined;\n env?: \"dev\" | \"staging\" | \"test\" | \"prod\";\n };\n input?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n output?: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n } | undefined;\n infra: {\n host: string;\n username?: string | undefined;\n password?: string | undefined;\n clientId?: string | undefined;\n };\n devops?: {\n provider?: \"azure-devops\";\n organization: string;\n project?: string | undefined;\n } | undefined;\n}\n\nexport interface AppConfig extends ProjectAppConfig {}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"auth-client.d.ts","sourceRoot":"","sources":["../../../src/tools/auth/auth-client.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO;WAMM,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;IASpC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IA0BvC,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,QAAQ;mBAOF,gBAAgB;IAWrC,OAAO,CAAC,MAAM,CAAC,oBAAoB;YAWrB,KAAK;YAmBL,OAAO;YAmBP,aAAa;WAKd,iBAAiB,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CA0C/E"}
1
+ {"version":3,"file":"auth-client.d.ts","sourceRoot":"","sources":["../../../src/tools/auth/auth-client.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,KAAK,CAAgB;IAE7B,OAAO;WAMM,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC;IAQpC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAuCvC,OAAO,CAAC,MAAM,CAAC,SAAS;IAWxB,OAAO,CAAC,MAAM,CAAC,QAAQ;mBAOF,gBAAgB;IAWrC,OAAO,CAAC,MAAM,CAAC,oBAAoB;YAWrB,KAAK;YAmBL,OAAO;YAmBP,aAAa;WAKd,iBAAiB,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CA0C/E"}
@@ -2,6 +2,7 @@ import { ConfigFile } from "../../config-file.js";
2
2
  import { SecureStoreFactory } from "./secure-store.js";
3
3
  import jwt from "jsonwebtoken";
4
4
  import readline from "readline";
5
+ const cfg = await ConfigFile.loadConfig();
5
6
  /**
6
7
  * AuthClient handles acquiring and refreshing JWT access tokens
7
8
  * using the configured REST base URL.
@@ -16,7 +17,6 @@ export class AuthClient {
16
17
  this.namespace = `uns-auth:${this.restBase}`;
17
18
  }
18
19
  static async create() {
19
- const cfg = await ConfigFile.loadConfig();
20
20
  const restBase = cfg?.uns?.rest;
21
21
  if (!restBase)
22
22
  throw new Error("config.uns.rest is not set");
@@ -41,6 +41,19 @@ export class AuthClient {
41
41
  // ignore, fallback to login
42
42
  }
43
43
  }
44
+ // First try to get email and password from config
45
+ const configEmail = cfg?.uns?.email;
46
+ const configPassword = cfg?.uns?.password;
47
+ if (typeof configEmail === "string" && typeof configPassword === "string") {
48
+ try {
49
+ const loggedIn = await this.login(configEmail, configPassword);
50
+ await this.persistTokens(loggedIn.accessToken, loggedIn.refreshToken);
51
+ return loggedIn.accessToken;
52
+ }
53
+ catch {
54
+ // ignore, fallback to interactive login
55
+ }
56
+ }
44
57
  // Interactive login
45
58
  const { email, password } = await AuthClient.promptCredentials();
46
59
  const loggedIn = await this.login(email, password);
@@ -1 +1 @@
1
- {"version":3,"file":"auth-client.js","sourceRoot":"","sources":["../../../src/tools/auth/auth-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAgB,MAAM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C,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,CAAC;YAC/C,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QAC7B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ConfigFile } from \"../../config-file.js\";\nimport { SecureStoreFactory, ISecureStore } from \"./secure-store.js\";\nimport jwt from \"jsonwebtoken\";\nimport readline from \"readline\";\n\ntype LoginResponse = {\n accessToken: string;\n};\n\n/**\n * AuthClient handles acquiring and refreshing JWT access tokens\n * using the configured REST base URL.\n */\nexport class AuthClient {\n private readonly restBase: string;\n private readonly namespace: string;\n private store!: ISecureStore;\n\n private constructor(restBase: string) {\n this.restBase = restBase.replace(/\\/$/, \"\");\n // namespace store by rest base to allow multiple environments\n this.namespace = `uns-auth:${this.restBase}`;\n }\n\n static async create(): Promise<AuthClient> {\n const cfg = await ConfigFile.loadConfig();\n const restBase: string = cfg?.uns?.rest;\n if (!restBase) throw new Error(\"config.uns.rest is not set\");\n const client = new AuthClient(restBase);\n client.store = await SecureStoreFactory.create(client.namespace);\n return client;\n }\n\n async getAccessToken(): Promise<string> {\n const accessToken = await this.store.get(\"accessToken\");\n const refreshToken = await this.store.get(\"refreshToken\");\n\n if (accessToken && !AuthClient.isExpired(accessToken)) {\n return accessToken;\n }\n\n // Try refresh if we have refresh token\n if (refreshToken) {\n try {\n const refreshed = await this.refresh(refreshToken);\n await this.persistTokens(refreshed.accessToken, refreshed.refreshToken);\n return refreshed.accessToken;\n } catch {\n // ignore, fallback to login\n }\n }\n\n // Interactive login\n const { email, password } = await AuthClient.promptCredentials();\n const loggedIn = await this.login(email, password);\n await this.persistTokens(loggedIn.accessToken, loggedIn.refreshToken);\n return loggedIn.accessToken;\n }\n\n private static isExpired(token: string, skewSeconds = 30): boolean {\n try {\n const decoded: any = jwt.decode(token);\n if (!decoded || typeof decoded !== \"object\" || !decoded.exp) return true;\n const now = Math.floor(Date.now() / 1000);\n return decoded.exp <= now + skewSeconds;\n } catch {\n return true;\n }\n }\n\n private static endpoint(base: string, tail: string): string {\n // base ends without trailing slash; tail must not start with slash\n const b = base.replace(/\\/$/, \"\");\n const t = tail.replace(/^\\//, \"\");\n return `${b}/${t}`;\n }\n\n private static async fetchWithTimeout(url: string, init: RequestInit = {}, timeoutMs = 10_000): Promise<Response> {\n const controller = new AbortController();\n const id = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const resp = await fetch(url, { ...init, signal: controller.signal });\n return resp;\n } finally {\n clearTimeout(id);\n }\n }\n\n private static extractRefreshCookie(resp: Response): string | null {\n const anyHeaders: any = resp.headers as any;\n const getSetCookie = typeof anyHeaders.getSetCookie === \"function\" ? anyHeaders.getSetCookie.bind(anyHeaders) : null;\n const candidates: string[] = getSetCookie ? getSetCookie() : (resp.headers.get(\"set-cookie\") ? [resp.headers.get(\"set-cookie\") as string] : []);\n for (const header of candidates) {\n const match = header.match(/(?:^|;\\s*)RefreshToken=([^;]+)/i);\n if (match) return match[1];\n }\n return null;\n }\n\n private async login(email: string, password: string): Promise<{ accessToken: string; refreshToken: string; }> {\n const url = AuthClient.endpoint(this.restBase, \"auth/login\");\n const resp = await AuthClient.fetchWithTimeout(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email, password }),\n }, 12_000);\n\n if (!resp.ok) {\n throw new Error(`Login failed: ${resp.status} ${resp.statusText}`);\n }\n const data = (await resp.json()) as LoginResponse;\n const refreshToken = AuthClient.extractRefreshCookie(resp);\n if (!data?.accessToken || !refreshToken) {\n throw new Error(\"Login response missing tokens\");\n }\n return { accessToken: data.accessToken, refreshToken };\n }\n\n private async refresh(refreshToken: string): Promise<{ accessToken: string; refreshToken: string; }> {\n const url = AuthClient.endpoint(this.restBase, \"auth/refresh\");\n const resp = await AuthClient.fetchWithTimeout(url, {\n method: \"POST\",\n headers: {\n // server expects cookie RefreshToken\n \"Cookie\": `RefreshToken=${refreshToken}`,\n },\n }, 8_000);\n\n if (!resp.ok) {\n throw new Error(`Refresh failed: ${resp.status} ${resp.statusText}`);\n }\n const data = (await resp.json()) as LoginResponse;\n const newRefreshToken = AuthClient.extractRefreshCookie(resp) || refreshToken;\n if (!data?.accessToken) throw new Error(\"Refresh response missing accessToken\");\n return { accessToken: data.accessToken, refreshToken: newRefreshToken };\n }\n\n private async persistTokens(accessToken: string, refreshToken: string): Promise<void> {\n await this.store.set(\"accessToken\", accessToken);\n await this.store.set(\"refreshToken\", refreshToken);\n }\n\n static async promptCredentials(): Promise<{ email: string; password: string }> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });\n\n const ask = (q: string) => new Promise<string>((resolve) => rl.question(q, (ans) => resolve(ans.trim())));\n\n const askMasked = (q: string) => new Promise<string>((resolve) => {\n const anyRl = rl as any;\n const out: any = anyRl.output || process.stdout;\n const origWrite = (anyRl._writeToOutput as ((str: string) => void))?.bind(rl) || ((s: string) => out.write(s));\n anyRl.stdoutMuted = true;\n anyRl._writeToOutput = function (stringToWrite: string) {\n // Keep prompt text intact; mask user input\n if (anyRl.stdoutMuted) {\n if (stringToWrite.startsWith(q)) {\n out.write(stringToWrite);\n } else if (stringToWrite.endsWith(\"\\n\")) {\n out.write(\"\\n\");\n } else {\n out.write(\"*\");\n }\n } else {\n origWrite(stringToWrite);\n }\n };\n rl.question(q, (value) => {\n anyRl.stdoutMuted = false;\n anyRl._writeToOutput = origWrite;\n out.write(\"\\n\");\n resolve(value.trim());\n });\n });\n\n try {\n const email = await ask(\"Email: \");\n const password = await askMasked(\"Password: \");\n rl.close();\n return { email, password };\n } catch (e) {\n rl.close();\n throw e;\n }\n }\n}\n"]}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AC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;wBAChC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAC3B,CAAC;yBAAM,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;wBACxC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAClB,CAAC;yBAAM,CAAC;wBACN,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACjB,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,SAAS,CAAC,aAAa,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC,CAAC;YACF,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;gBACvB,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;gBAC1B,KAAK,CAAC,cAAc,GAAG,SAAS,CAAC;gBACjC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAChB,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;YACnC,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,CAAC;YAC/C,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QAC7B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF","sourcesContent":["import { ConfigFile } from \"../../config-file.js\";\nimport { SecureStoreFactory, ISecureStore } from \"./secure-store.js\";\nimport jwt from \"jsonwebtoken\";\nimport readline from \"readline\";\n\nconst cfg = await ConfigFile.loadConfig();\n\ntype LoginResponse = {\n accessToken: string;\n};\n\n/**\n * AuthClient handles acquiring and refreshing JWT access tokens\n * using the configured REST base URL.\n */\nexport class AuthClient {\n private readonly restBase: string;\n private readonly namespace: string;\n private store!: ISecureStore;\n\n private constructor(restBase: string) {\n this.restBase = restBase.replace(/\\/$/, \"\");\n // namespace store by rest base to allow multiple environments\n this.namespace = `uns-auth:${this.restBase}`;\n }\n\n static async create(): Promise<AuthClient> {\n const restBase: string = cfg?.uns?.rest;\n if (!restBase) throw new Error(\"config.uns.rest is not set\");\n const client = new AuthClient(restBase);\n client.store = await SecureStoreFactory.create(client.namespace);\n return client;\n }\n\n async getAccessToken(): Promise<string> {\n const accessToken = await this.store.get(\"accessToken\");\n const refreshToken = await this.store.get(\"refreshToken\");\n\n if (accessToken && !AuthClient.isExpired(accessToken)) {\n return accessToken;\n }\n\n // Try refresh if we have refresh token\n if (refreshToken) {\n try {\n const refreshed = await this.refresh(refreshToken);\n await this.persistTokens(refreshed.accessToken, refreshed.refreshToken);\n return refreshed.accessToken;\n } catch {\n // ignore, fallback to login\n }\n }\n\n // First try to get email and password from config\n const configEmail = cfg?.uns?.email;\n const configPassword = cfg?.uns?.password;\n if (typeof configEmail === \"string\" && typeof configPassword === \"string\") {\n try {\n const loggedIn = await this.login(configEmail, configPassword);\n await this.persistTokens(loggedIn.accessToken, loggedIn.refreshToken);\n return loggedIn.accessToken;\n } catch {\n // ignore, fallback to interactive login\n }\n }\n\n // Interactive login\n const { email, password } = await AuthClient.promptCredentials();\n const loggedIn = await this.login(email, password);\n await this.persistTokens(loggedIn.accessToken, loggedIn.refreshToken);\n return loggedIn.accessToken;\n }\n\n private static isExpired(token: string, skewSeconds = 30): boolean {\n try {\n const decoded: any = jwt.decode(token);\n if (!decoded || typeof decoded !== \"object\" || !decoded.exp) return true;\n const now = Math.floor(Date.now() / 1000);\n return decoded.exp <= now + skewSeconds;\n } catch {\n return true;\n }\n }\n\n private static endpoint(base: string, tail: string): string {\n // base ends without trailing slash; tail must not start with slash\n const b = base.replace(/\\/$/, \"\");\n const t = tail.replace(/^\\//, \"\");\n return `${b}/${t}`;\n }\n\n private static async fetchWithTimeout(url: string, init: RequestInit = {}, timeoutMs = 10_000): Promise<Response> {\n const controller = new AbortController();\n const id = setTimeout(() => controller.abort(), timeoutMs);\n try {\n const resp = await fetch(url, { ...init, signal: controller.signal });\n return resp;\n } finally {\n clearTimeout(id);\n }\n }\n\n private static extractRefreshCookie(resp: Response): string | null {\n const anyHeaders: any = resp.headers as any;\n const getSetCookie = typeof anyHeaders.getSetCookie === \"function\" ? anyHeaders.getSetCookie.bind(anyHeaders) : null;\n const candidates: string[] = getSetCookie ? getSetCookie() : (resp.headers.get(\"set-cookie\") ? [resp.headers.get(\"set-cookie\") as string] : []);\n for (const header of candidates) {\n const match = header.match(/(?:^|;\\s*)RefreshToken=([^;]+)/i);\n if (match) return match[1];\n }\n return null;\n }\n\n private async login(email: string, password: string): Promise<{ accessToken: string; refreshToken: string; }> {\n const url = AuthClient.endpoint(this.restBase, \"auth/login\");\n const resp = await AuthClient.fetchWithTimeout(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ email, password }),\n }, 12_000);\n\n if (!resp.ok) {\n throw new Error(`Login failed: ${resp.status} ${resp.statusText}`);\n }\n const data = (await resp.json()) as LoginResponse;\n const refreshToken = AuthClient.extractRefreshCookie(resp);\n if (!data?.accessToken || !refreshToken) {\n throw new Error(\"Login response missing tokens\");\n }\n return { accessToken: data.accessToken, refreshToken };\n }\n\n private async refresh(refreshToken: string): Promise<{ accessToken: string; refreshToken: string; }> {\n const url = AuthClient.endpoint(this.restBase, \"auth/refresh\");\n const resp = await AuthClient.fetchWithTimeout(url, {\n method: \"POST\",\n headers: {\n // server expects cookie RefreshToken\n \"Cookie\": `RefreshToken=${refreshToken}`,\n },\n }, 8_000);\n\n if (!resp.ok) {\n throw new Error(`Refresh failed: ${resp.status} ${resp.statusText}`);\n }\n const data = (await resp.json()) as LoginResponse;\n const newRefreshToken = AuthClient.extractRefreshCookie(resp) || refreshToken;\n if (!data?.accessToken) throw new Error(\"Refresh response missing accessToken\");\n return { accessToken: data.accessToken, refreshToken: newRefreshToken };\n }\n\n private async persistTokens(accessToken: string, refreshToken: string): Promise<void> {\n await this.store.set(\"accessToken\", accessToken);\n await this.store.set(\"refreshToken\", refreshToken);\n }\n\n static async promptCredentials(): Promise<{ email: string; password: string }> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });\n\n const ask = (q: string) => new Promise<string>((resolve) => rl.question(q, (ans) => resolve(ans.trim())));\n\n const askMasked = (q: string) => new Promise<string>((resolve) => {\n const anyRl = rl as any;\n const out: any = anyRl.output || process.stdout;\n const origWrite = (anyRl._writeToOutput as ((str: string) => void))?.bind(rl) || ((s: string) => out.write(s));\n anyRl.stdoutMuted = true;\n anyRl._writeToOutput = function (stringToWrite: string) {\n // Keep prompt text intact; mask user input\n if (anyRl.stdoutMuted) {\n if (stringToWrite.startsWith(q)) {\n out.write(stringToWrite);\n } else if (stringToWrite.endsWith(\"\\n\")) {\n out.write(\"\\n\");\n } else {\n out.write(\"*\");\n }\n } else {\n origWrite(stringToWrite);\n }\n };\n rl.question(q, (value) => {\n anyRl.stdoutMuted = false;\n anyRl._writeToOutput = origWrite;\n out.write(\"\\n\");\n resolve(value.trim());\n });\n });\n\n try {\n const email = await ask(\"Email: \");\n const password = await askMasked(\"Password: \");\n rl.close();\n return { email, password };\n } catch (e) {\n rl.close();\n throw e;\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/tools/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAG/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,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AAS,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,IAAI,CACd,kCAAkC,QAAQ,8CAA8C,OAAO,GAAG,CACnG,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,QAAQ,IAAI,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACrC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,KAAK,GAAG,MAAM,CAAC;IACf,GAAG,EAAE,CAAC;AACR,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,EAAE,CAAC,QAAQ,CACT,0GAA0G,EAC1G,CAAC,QAAQ,EAAE,EAAE;QACX,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,QAAQ,CAAC;QACjB,GAAG,EAAE,CAAC;IACR,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import * as azdev from \"azure-devops-node-api\";\nimport * as ga from \"azure-devops-node-api/GitApi\";\nimport { GitRepository } from \"azure-devops-node-api/interfaces/TfvcInterfaces\";\nimport chalk from \"chalk\";\nimport { readFile } from \"fs/promises\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport fs from \"fs-extra\";\nimport { basePath } from \"./base-path.js\";\n\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\nexport const packageJsonPath = path.join(basePath, \"package.json\");\nconst orgUrl = \"https://example-org@dev.azure.com/example-org\";\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet token: string = \"\";\nconst packageJson = JSON.parse(await readFile(packageJsonPath, \"utf8\"));\nconst repoName: string = packageJson.name;\n\nasync function run() {\n let repos: GitRepository[];\n let gitApi: ga.IGitApi;\n const project = \"example-project\";\n try {\n const authHandler = azdev.getPersonalAccessTokenHandler(token);\n const connection = new azdev.WebApi(orgUrl, authHandler);\n gitApi = await connection.getGitApi();\n repos = await gitApi.getRepositories(project); \n } catch (error) {\n console.error(\"Your AZURE_PAT environment variable has probably expired.\");\n console.log(\"Please update your AZURE_PAT environment with a new one on.\");\n console.log(\"You can create a new one at[https://dev.azure.com/example-org/_usersSettings/tokens]\");\n }\n\n if (repos.filter((x) => x.name == repoName).length > 0) {\n console.log(\n chalk.red.bold(\n `Error: Repository ${repoName} in project ${project} already exists.`,\n ),\n );\n } else {\n process.stdout.write(`Create ${repoName} in project ${project}`);\n try {\n await gitApi.createRepository({ name: repoName }, project);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Initialize local git repository on branch master`);\n try {\n await git.init();\n await git.checkoutLocalBranch(\"master\");\n await git.add(\".\");\n await git.commit(\"Initial commit\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Add remote origin.`);\n try {\n await git.remote([\n \"add\",\n \"origin\",\n `git@ssh.dev.azure.com:v3/example-org/example-project/${repoName}`,\n ]);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Push master to remote`);\n try {\n await git.push(\"origin\", \"master\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Create default config.json from config-template.json`);\n try {\n fs.copyFileSync(path.join(basePath,'config-template.json'), path.join(basePath,'config.json'));\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n console.log(\n chalk.green.bold(\n `\\nNow you can add pipeline for ${repoName} in Azure DevOps pipelines for the project ${project}.`,\n ),\n );\n }\n}\n\nconsole.log(chalk.green.bold(`Create new RTT: ${repoName}\\n`));\n\nconst envPat = process.env.AZURE_PAT;\nif (envPat && envPat.length > 10) {\n rl.close();\n console.log(\"Using PAT from your AZURE_PAT environment\");\n token = envPat;\n run();\n} else {\n console.log(\"Could not find AZURE_PAT environment.\");\n rl.question(\n `Please enter your PAT, you can create one at [https://dev.azure.com/example-org/_usersSettings/tokens]: `,\n (newToken) => {\n rl.close();\n token = newToken;\n run();\n },\n ); \n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../src/tools/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,uBAAuB,CAAC;AAG/C,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEjE,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AACnE,MAAM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G,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,QAAQ,IAAI,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;AACrC,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;IACjC,EAAE,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;IACzD,KAAK,GAAG,MAAM,CAAC;IACf,GAAG,EAAE,CAAC;AACR,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;IACrD,EAAE,CAAC,QAAQ,CACT,oGAAoG,EACpG,CAAC,QAAQ,EAAE,EAAE;QACX,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,QAAQ,CAAC;QACjB,GAAG,EAAE,CAAC;IACR,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import * as azdev from \"azure-devops-node-api\";\nimport * as ga from \"azure-devops-node-api/GitApi\";\nimport { GitRepository } from \"azure-devops-node-api/interfaces/TfvcInterfaces\";\nimport chalk from \"chalk\";\nimport { readFile } from \"fs/promises\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport fs from \"fs-extra\";\nimport { basePath } from \"./base-path.js\";\n\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\nexport const packageJsonPath = path.join(basePath, \"package.json\");\nconst orgUrl = \"https://sijit@dev.azure.com/sijit\";\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nlet token: string = \"\";\nconst packageJson = JSON.parse(await readFile(packageJsonPath, \"utf8\"));\nconst repoName: string = packageJson.name;\n\nasync function run() {\n let repos: GitRepository[];\n let gitApi: ga.IGitApi;\n const project = \"industry40\";\n try {\n const authHandler = azdev.getPersonalAccessTokenHandler(token);\n const connection = new azdev.WebApi(orgUrl, authHandler);\n gitApi = await connection.getGitApi();\n repos = await gitApi.getRepositories(project); \n } catch (error) {\n console.error(\"Your AZURE_PAT environment variable has probably expired.\");\n console.log(\"Please update your AZURE_PAT environment with a new one on.\");\n console.log(\"You can create a new one at[https://dev.azure.com/sijit/_usersSettings/tokens]\");\n }\n\n if (repos.filter((x) => x.name == repoName).length > 0) {\n console.log(\n chalk.red.bold(\n `Error: Repository ${repoName} in project ${project} already exists.`,\n ),\n );\n } else {\n process.stdout.write(`Create ${repoName} in project ${project}`);\n try {\n await gitApi.createRepository({ name: repoName }, project);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Initialize local git repository on branch master`);\n try {\n await git.init();\n await git.checkoutLocalBranch(\"master\");\n await git.add(\".\");\n await git.commit(\"Initial commit\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Add remote origin.`);\n try {\n await git.remote([\n \"add\",\n \"origin\",\n `git@ssh.dev.azure.com:v3/sijit/industry40/${repoName}`,\n ]);\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Push master to remote`);\n try {\n await git.push(\"origin\", \"master\");\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n process.stdout.write(`Create default config.json from config-template.json`);\n try {\n fs.copyFileSync(path.join(basePath,'config-template.json'), path.join(basePath,'config.json'));\n console.log(chalk.green.bold(` ... OK`));\n } catch (error) {\n console.error(chalk.red.bold(`\\n${error}`));\n }\n\n console.log(\n chalk.green.bold(\n `\\nNow you can add pipeline for ${repoName} in Azure DevOps pipelines for the project ${project}.`,\n ),\n );\n }\n}\n\nconsole.log(chalk.green.bold(`Create new RTT: ${repoName}\\n`));\n\nconst envPat = process.env.AZURE_PAT;\nif (envPat && envPat.length > 10) {\n rl.close();\n console.log(\"Using PAT from your AZURE_PAT environment\");\n token = envPat;\n run();\n} else {\n console.log(\"Could not find AZURE_PAT environment.\");\n rl.question(\n `Please enter your PAT, you can create one at [https://dev.azure.com/sijit/_usersSettings/tokens]: `,\n (newToken) => {\n rl.close();\n token = newToken;\n run();\n },\n ); \n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"update-tools.js","sourceRoot":"","sources":["../../src/tools/update-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEjE,IAAI,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;IACb,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1C,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,I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AC;AACH,CAAC","sourcesContent":["import { CleanOptions, SimpleGit, simpleGit } from \"simple-git\";\nimport { basePath } from \"./base-path.js\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport fs from \"fs-extra\";\nimport { execSync } from \"child_process\";\n\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\ntry {\n await main();\n rl.close();\n} catch (error) {\n console.log(chalk.red.bold(`\\n${error}`));\n rl.close();\n}\n\nasync function main() {\n const tmpRtt = path.join(basePath, \"/tmp-rtt\");\n try {\n console.log(`Pull template-ts-nodejs into tmp-rtt`);\n await git.clone(\"git@ssh.dev.azure.com:v3/example-org/example-project/template-uns-rtt\", tmpRtt);\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n try {\n console.log(`Overwrite tools`);\n fs.copySync(path.join(tmpRtt, \"/src/tools\"), path.join(basePath, \"/src/tools\"), {overwrite: true});\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n // Update library version JSON at repo root from template\n try {\n const srcJson = path.join(tmpRtt, 'uns-library.json');\n const dstJson = path.join(basePath, 'uns-library.json');\n if (fs.existsSync(srcJson)) {\n fs.copyFileSync(srcJson, dstJson);\n const ver = JSON.parse(fs.readFileSync(srcJson, 'utf8')).version;\n console.log(`Updated uns-library.json -> ${ver}`);\n } else {\n // Fallback for older templates: synthesize from package.json\n const tmpPackageJsonPath = path.join(tmpRtt, 'package.json');\n const tmpPackageJson = JSON.parse(fs.readFileSync(tmpPackageJsonPath, 'utf8'));\n const payload = JSON.stringify({ name: tmpPackageJson.name, version: tmpPackageJson.version }, null, 2);\n fs.writeFileSync(dstJson, payload + \"\\n\", 'utf8');\n console.log(`Updated uns-library.json -> ${tmpPackageJson.version}`);\n }\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`));\n return;\n }\n\n try {\n console.log(`Running update-rtt from tools`);\n // Propagate any CLI args to update-rtt (e.g., --dry-run)\n const args = process.argv.slice(2).join(\" \");\n // Run the TypeScript tool directly to avoid relying on a successful build\n execSync(`tsx ./src/tools/update-rtt.ts ${args}`.trim(), { stdio: 'inherit' });\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return; \n }\n}\n"]}
1
+ {"version":3,"file":"update-tools.js","sourceRoot":"","sources":["../../src/tools/update-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAa,SAAS,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACvB,CAAC,CAAC;AAEH,MAAM,GAAG,GAAc,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEjE,IAAI,CAAC;IACH,MAAM,IAAI,EAAE,CAAC;IACb,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1C,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC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SimpleGit, simpleGit } from \"simple-git\";\nimport { basePath } from \"./base-path.js\";\nimport readline from \"node:readline\";\nimport * as path from \"path\";\nimport chalk from \"chalk\";\nimport fs from \"fs-extra\";\nimport { execSync } from \"child_process\";\n\n\nconst rl = readline.createInterface({\n input: process.stdin,\n output: process.stdout,\n});\n\nconst git: SimpleGit = simpleGit(\"./\").clean(CleanOptions.FORCE);\n\ntry {\n await main();\n rl.close();\n} catch (error) {\n console.log(chalk.red.bold(`\\n${error}`));\n rl.close();\n}\n\nasync function main() {\n const tmpRtt = path.join(basePath, \"/tmp-rtt\");\n try {\n console.log(`Pull template-ts-nodejs into tmp-rtt`);\n await git.clone(\"git@ssh.dev.azure.com:v3/sijit/industry40/template-uns-rtt\", tmpRtt);\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n try {\n console.log(`Overwrite tools`);\n fs.copySync(path.join(tmpRtt, \"/src/tools\"), path.join(basePath, \"/src/tools\"), {overwrite: true});\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return;\n }\n\n // Update library version JSON at repo root from template\n try {\n const srcJson = path.join(tmpRtt, 'uns-library.json');\n const dstJson = path.join(basePath, 'uns-library.json');\n if (fs.existsSync(srcJson)) {\n fs.copyFileSync(srcJson, dstJson);\n const ver = JSON.parse(fs.readFileSync(srcJson, 'utf8')).version;\n console.log(`Updated uns-library.json -> ${ver}`);\n } else {\n // Fallback for older templates: synthesize from package.json\n const tmpPackageJsonPath = path.join(tmpRtt, 'package.json');\n const tmpPackageJson = JSON.parse(fs.readFileSync(tmpPackageJsonPath, 'utf8'));\n const payload = JSON.stringify({ name: tmpPackageJson.name, version: tmpPackageJson.version }, null, 2);\n fs.writeFileSync(dstJson, payload + \"\\n\", 'utf8');\n console.log(`Updated uns-library.json -> ${tmpPackageJson.version}`);\n }\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`));\n return;\n }\n\n try {\n console.log(`Running update-rtt from tools`);\n // Propagate any CLI args to update-rtt (e.g., --dry-run)\n const args = process.argv.slice(2).join(\" \");\n // Run the TypeScript tool directly to avoid relying on a successful build\n execSync(`tsx ./src/tools/update-rtt.ts ${args}`.trim(), { stdio: 'inherit' });\n } catch (error) {\n console.error(chalk.red.bold(`exec error: ${error}`)); \n return; \n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"handover-manager.d.ts","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAGlD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe;IACnB,KAAK,EAAE,2BAA2B,CAAC,qBAAqB,CAAC,CAA4D;IAC5H,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,MAAM,CAAkB;IACzB,sBAAsB,EAAE,OAAO,CAAS;IACxC,eAAe,EAAE,OAAO,CAAQ;IAChC,iBAAiB,EAAE,OAAO,CAAS;gBAE9B,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,sBAAsB,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO;IAwB5K;;;OAGG;IACU,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoExE;;OAEG;YACW,cAAc;CAyI7B"}
1
+ {"version":3,"file":"handover-manager.d.ts","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAGlD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAEzD;;;;GAIG;AACH,qBAAa,eAAe;IACnB,KAAK,EAAE,2BAA2B,CAAC,qBAAqB,CAAC,CAA4D;IAC5H,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,kBAAkB,CAAkB;IAC5C,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,MAAM,CAAkB;IACzB,sBAAsB,EAAE,OAAO,CAAS;IACxC,eAAe,EAAE,OAAO,CAAQ;IAChC,iBAAiB,EAAE,OAAO,CAAS;gBAE9B,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,sBAAsB,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO;IA0B5K;;;OAGG;IACU,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAoExE;;OAEG;YACW,cAAc;CAyI7B"}
@@ -28,7 +28,9 @@ export class HandoverManager {
28
28
  this.handoverEnabled = handoverEnabled;
29
29
  this.forceStartEnabled = forceStartEnabled;
30
30
  // Instantiate the topic builder.
31
- this.topicBuilder = new MqttTopicBuilder(`uns-infra/${PACKAGE_INFO.name}/${PACKAGE_INFO.version}/${processName}/`);
31
+ const packageName = PACKAGE_INFO.name;
32
+ const version = PACKAGE_INFO.version;
33
+ this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);
32
34
  // Set status as active after a timeout if no other active process are detected.
33
35
  this.activeTimeout = setTimeout(() => {
34
36
  logger.info(`${this.processName} - No active message received within timeout. Assuming no other process is running.`);
@@ -1 +1 @@
1
- {"version":3,"file":"handover-manager.js","sourceRoot":"","sources":["../../src/uns/handover-manager.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;GAIG;AACH,MAAM,OAAO,eAAe;IACnB,KAAK,GAAuD,IAAI,2BAA2B,EAAyB,CAAC;IACpH,WAAW,CAAS;IACpB,SAAS,CAAY;IACrB,cAAc,CAAiB;IAC/B,kBAAkB,GAAY,KAAK,CAAC;IACpC,kBAAkB,GAAY,KAAK,CAAC;IACpC,YAAY,CAAmB;IAC/B,aAAa,CAA6B;IAC1C,MAAM,GAAY,KAAK,CAAC;IACzB,sBAAsB,GAAY,KAAK,CAAC;IACxC,eAAe,GAAY,IAAI,CAAC;IAChC,iBAAiB,GAAY,KAAK,CAAC;IAE1C,YAAY,WAAmB,EAAE,SAAoB,EAAE,cAA8B,EAAE,sBAA+B,EAAE,eAAwB,EAAE,iBAA0B;QAC1K,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,cAAc,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AAC,SAAS,CAAC,OAAO,CAC1B,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,IAAI,EAAE,EAC5C,IAAI,CAAC,SAAS,CAAC;oBACb,IAAI,EAAE,cAAc;iBACrB,CAAC,EACF;oBACE,MAAM,EAAE,KAAK;oBACb,UAAU,EAAE;wBACV,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE;wBACnD,cAAc,EAAE;4BACd,WAAW,EAAE,IAAI,CAAC,WAAW;yBAC9B;qBACF;iBACF,CACF,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,+BAA+B,CAAC,CAAC;YAClE,CAAC;YAED,oBAAoB;YACpB,6EAA6E;YAC7E,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,iCAAiC,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,GAAG,CAAC,CAAC;gBAC1H,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;gBAChC,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;gBAEhC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,yCAAyC,CAAC,CAAC;gBAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,0CAA0C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;CACF","sourcesContent":["import { UnsEvents } from \"./uns-interfaces.js\";\nimport logger from \"../logger.js\";\nimport { HandoverManagerEventEmitter } from \"./handover-manager-event-emitter.js\";\nimport { HandoverManagerEvents } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { ACTIVE_TIMEOUT, PACKAGE_INFO } from \"./process-config.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\n\n/**\n * HandoverManager is responsible for all handover-related logic,\n * including handling incoming MQTT messages, issuing handover requests,\n * and processing handover responses.\n */\nexport class HandoverManager {\n public event: HandoverManagerEventEmitter<HandoverManagerEvents> = new HandoverManagerEventEmitter<HandoverManagerEvents>();\n private processName: string;\n private mqttProxy: MqttProxy;\n private unsMqttProxies: UnsMqttProxy[];\n private requestingHandover: boolean = false;\n private handoverInProgress: boolean = false;\n private topicBuilder: MqttTopicBuilder;\n private activeTimeout: NodeJS.Timeout | undefined;\n private active: boolean = false;\n public handoverRequestEnabled: boolean = false;\n public handoverEnabled: boolean = true;\n public forceStartEnabled: boolean = false;\n\n constructor(processName: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean) {\n this.processName = processName;\n this.mqttProxy = mqttProxy;\n this.unsMqttProxies = unsMqttProxies;\n this.handoverRequestEnabled = handoverRequestEnabled;\n this.handoverEnabled = handoverEnabled;\n this.forceStartEnabled = forceStartEnabled;\n\n // Instantiate the topic builder.\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${PACKAGE_INFO.name}/${PACKAGE_INFO.version}/${processName}/`);\n\n // Set status as active after a timeout if no other active process are detected.\n this.activeTimeout = setTimeout(() => {\n logger.info(`${this.processName} - No active message received within timeout. Assuming no other process is running.`);\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n }, ACTIVE_TIMEOUT);\n }\n\n /**\n * Main entry point for handling incoming MQTT messages.\n * It checks the topic and delegates to the corresponding handler.\n */\n public async handleMqttMessage(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n // Check if the packet is active messages from other processes and this process is not active.\n if (\n this.requestingHandover === false &&\n this.topicBuilder.getActiveTopic() !== event.topic &&\n this.active === false &&\n this.handoverInProgress === false\n ) {\n logger.info(`${this.processName} - Another process is active on ${event.topic}.`);\n\n if (this.handoverRequestEnabled) {\n // Requester process\n // Publish a handover request message after 10 seconds to the handover topic.\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.event.emit(\"handoverManager\", { active: this.active });\n this.requestingHandover = true;\n logger.info(`${this.processName} - Requesting handover in 10 seconds.`);\n setTimeout(async () => {\n const eventHandoverTopic = new MqttTopicBuilder(MqttTopicBuilder.extractBaseTopic(event.topic)).getHandoverTopic();\n logger.info(`${this.processName} - Requesting handover ${eventHandoverTopic}.`);\n this.handoverInProgress = true;\n await this.mqttProxy.publish(eventHandoverTopic, JSON.stringify({ type: \"handover_request\" }), {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n });\n }, 10000);\n } else {\n if (this.forceStartEnabled) {\n // Force start the process even if another process is active.\n logger.info(`${this.processName} - Force starting the process.`);\n logger.warn(`${this.processName} - Warning: Source and destination being the same may lead to duplicate messages.`);\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n }\n );\n }\n else {\n logger.info(`${this.processName} - Waiting for the other process on topic ${event.topic} to become passive.`);\n this.activeTimeout.refresh();\n }\n }\n }\n\n // Check if the packet is an handover message, sent to a handover topic.\n if (event.topic === this.topicBuilder.getHandoverTopic() && this.handoverEnabled) {\n if (event.packet?.properties?.userProperties?.processName && event.packet.properties.userProperties.processName !== this.processName) {\n await this.handleHandover(event);\n }\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing MQTT message: ${error.message}`);\n return;\n }\n }\n\n /**\n * Handles handovers.\n */\n private async handleHandover(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n const response = JSON.parse(event.message.toString());\n // Responder process\n // Check if the message is a handover request and publish MULTIPLE handover_subscriber messages\n if (response.type === \"handover_request\") {\n logger.info(\n `${this.processName} - Received handover request from ${event.packet?.properties?.userProperties?.processName}. Accepting handover.`,\n );\n\n // Set all UNS proxy instance subscribers to passive and drain the queue.\n const mqttWorkerData: UnsEvents[\"mqttWorker\"][] = [];\n for (let i = 0; i < this.unsMqttProxies.length; i++) {\n const unsProxy = this.unsMqttProxies[i];\n const workerData = await unsProxy.setSubscriberPassiveAndDrainQueue();\n mqttWorkerData.push(workerData);\n }\n logger.info(`${this.processName} - Handover request accepted. Sending handover_subscriber messages.`);\n\n // Publish handover_subscriber messages for each instance that has processed some data.\n for (let i = 0; i < mqttWorkerData.length; i++) {\n const workerData = mqttWorkerData[i];\n if (workerData.batchSize > 0) {\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_subscriber\",\n batchSize: workerData.batchSize,\n referenceHash: workerData.referenceHash,\n instanceName: workerData.instanceName,\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n }\n }\n logger.info(`${this.processName} - Handover subscriber messages sent.`);\n\n // Publish a single handover acknowledgment only when all\n // handover_subscriber messages have been sent\n this.active = false;\n this.event.emit(\"handoverManager\", { active: this.active });\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_fin\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover fin message sent.`);\n\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n unsProxy.stop();\n });\n }\n\n // Requestor process\n // Check if the message is one of the handover_subscriber message in response to handover_request\n // and publish a handover_ack message\n if (response.type === \"handover_subscriber\") {\n // Find correct unsProxy instance for handover_subscriber and set it active\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n if (unsProxy.instanceName === response.instanceName) {\n unsProxy.setSubscriberActive(response.batchSize, response.referenceHash);\n }\n });\n }\n\n // Requestor process\n // Check if the message is a handover_fin at the end of handover_subscriber messages\n if (response.type === \"handover_fin\") {\n logger.info(`${this.processName} - Received handover fin from ${event.packet?.properties?.userProperties?.processName}.`);\n\n // Maybe we should count the number of requests that were allrady made TODO\n // this.handoverInProgress = false;\n // this.requestingHandover = false;\n\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n logger.info(`${this.processName} - Handover completed.`);\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n\n // Maybe we should reply with handover_ack.\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_ack\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover ack message sent.`);\n }\n\n // Responder process\n // Check if the message is a handover_ack at the end of handover_fin messages\n if (response.type === \"handover_ack\") {\n logger.info(`${this.processName} - Received handover ack from ${event.packet?.properties?.userProperties?.processName}.`);\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n logger.info(`${this.processName} - Handover completed. Exiting process.`);\n process.exit(0);\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing handover response: ${error.message}`);\n }\n }\n}\n"]}
1
+ {"version":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E;wBACV,aAAa,EAAE,IAAI,CAAC,YAAY,CAAC,gBAAgB,EAAE;wBACnD,cAAc,EAAE;4BACd,WAAW,EAAE,IAAI,CAAC,WAAW;yBAC9B;qBACF;iBACF,CACF,CAAC;gBACF,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,+BAA+B,CAAC,CAAC;YAClE,CAAC;YAED,oBAAoB;YACpB,6EAA6E;YAC7E,IAAI,QAAQ,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBACrC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,iCAAiC,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,GAAG,CAAC,CAAC;gBAC1H,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;gBAChC,IAAI,CAAC,kBAAkB,GAAG,KAAK,CAAC;gBAEhC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,yCAAyC,CAAC,CAAC;gBAC1E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,WAAW,0CAA0C,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;CACF","sourcesContent":["import { UnsEvents } from \"./uns-interfaces.js\";\nimport logger from \"../logger.js\";\nimport { HandoverManagerEventEmitter } from \"./handover-manager-event-emitter.js\";\nimport { HandoverManagerEvents } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { ACTIVE_TIMEOUT, PACKAGE_INFO } from \"./process-config.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\n\n/**\n * HandoverManager is responsible for all handover-related logic,\n * including handling incoming MQTT messages, issuing handover requests,\n * and processing handover responses.\n */\nexport class HandoverManager {\n public event: HandoverManagerEventEmitter<HandoverManagerEvents> = new HandoverManagerEventEmitter<HandoverManagerEvents>();\n private processName: string;\n private mqttProxy: MqttProxy;\n private unsMqttProxies: UnsMqttProxy[];\n private requestingHandover: boolean = false;\n private handoverInProgress: boolean = false;\n private topicBuilder: MqttTopicBuilder;\n private activeTimeout: NodeJS.Timeout | undefined;\n private active: boolean = false;\n public handoverRequestEnabled: boolean = false;\n public handoverEnabled: boolean = true;\n public forceStartEnabled: boolean = false;\n\n constructor(processName: string, mqttProxy: MqttProxy, unsMqttProxies: UnsMqttProxy[], handoverRequestEnabled: boolean, handoverEnabled: boolean, forceStartEnabled: boolean) {\n this.processName = processName;\n this.mqttProxy = mqttProxy;\n this.unsMqttProxies = unsMqttProxies;\n this.handoverRequestEnabled = handoverRequestEnabled;\n this.handoverEnabled = handoverEnabled;\n this.forceStartEnabled = forceStartEnabled;\n\n // Instantiate the topic builder.\n const packageName = PACKAGE_INFO.name;\n const version = PACKAGE_INFO.version;\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);\n\n // Set status as active after a timeout if no other active process are detected.\n this.activeTimeout = setTimeout(() => {\n logger.info(`${this.processName} - No active message received within timeout. Assuming no other process is running.`);\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n }, ACTIVE_TIMEOUT);\n }\n\n /**\n * Main entry point for handling incoming MQTT messages.\n * It checks the topic and delegates to the corresponding handler.\n */\n public async handleMqttMessage(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n // Check if the packet is active messages from other processes and this process is not active.\n if (\n this.requestingHandover === false &&\n this.topicBuilder.getActiveTopic() !== event.topic &&\n this.active === false &&\n this.handoverInProgress === false\n ) {\n logger.info(`${this.processName} - Another process is active on ${event.topic}.`);\n\n if (this.handoverRequestEnabled) {\n // Requester process\n // Publish a handover request message after 10 seconds to the handover topic.\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.event.emit(\"handoverManager\", { active: this.active });\n this.requestingHandover = true;\n logger.info(`${this.processName} - Requesting handover in 10 seconds.`);\n setTimeout(async () => {\n const eventHandoverTopic = new MqttTopicBuilder(MqttTopicBuilder.extractBaseTopic(event.topic)).getHandoverTopic();\n logger.info(`${this.processName} - Requesting handover ${eventHandoverTopic}.`);\n this.handoverInProgress = true;\n await this.mqttProxy.publish(eventHandoverTopic, JSON.stringify({ type: \"handover_request\" }), {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n });\n }, 10000);\n } else {\n if (this.forceStartEnabled) {\n // Force start the process even if another process is active.\n logger.info(`${this.processName} - Force starting the process.`);\n logger.warn(`${this.processName} - Warning: Source and destination being the same may lead to duplicate messages.`);\n clearTimeout(this.activeTimeout); // Clear the active timeout if it exists - prevent this process from becoming active after a timeout.\n this.activeTimeout = undefined;\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n }\n );\n }\n else {\n logger.info(`${this.processName} - Waiting for the other process on topic ${event.topic} to become passive.`);\n this.activeTimeout.refresh();\n }\n }\n }\n\n // Check if the packet is an handover message, sent to a handover topic.\n if (event.topic === this.topicBuilder.getHandoverTopic() && this.handoverEnabled) {\n if (event.packet?.properties?.userProperties?.processName && event.packet.properties.userProperties.processName !== this.processName) {\n await this.handleHandover(event);\n }\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing MQTT message: ${error.message}`);\n return;\n }\n }\n\n /**\n * Handles handovers.\n */\n private async handleHandover(event: UnsEvents[\"input\"]): Promise<void> {\n try {\n const response = JSON.parse(event.message.toString());\n // Responder process\n // Check if the message is a handover request and publish MULTIPLE handover_subscriber messages\n if (response.type === \"handover_request\") {\n logger.info(\n `${this.processName} - Received handover request from ${event.packet?.properties?.userProperties?.processName}. Accepting handover.`,\n );\n\n // Set all UNS proxy instance subscribers to passive and drain the queue.\n const mqttWorkerData: UnsEvents[\"mqttWorker\"][] = [];\n for (let i = 0; i < this.unsMqttProxies.length; i++) {\n const unsProxy = this.unsMqttProxies[i];\n const workerData = await unsProxy.setSubscriberPassiveAndDrainQueue();\n mqttWorkerData.push(workerData);\n }\n logger.info(`${this.processName} - Handover request accepted. Sending handover_subscriber messages.`);\n\n // Publish handover_subscriber messages for each instance that has processed some data.\n for (let i = 0; i < mqttWorkerData.length; i++) {\n const workerData = mqttWorkerData[i];\n if (workerData.batchSize > 0) {\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_subscriber\",\n batchSize: workerData.batchSize,\n referenceHash: workerData.referenceHash,\n instanceName: workerData.instanceName,\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n }\n }\n logger.info(`${this.processName} - Handover subscriber messages sent.`);\n\n // Publish a single handover acknowledgment only when all\n // handover_subscriber messages have been sent\n this.active = false;\n this.event.emit(\"handoverManager\", { active: this.active });\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_fin\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover fin message sent.`);\n\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n unsProxy.stop();\n });\n }\n\n // Requestor process\n // Check if the message is one of the handover_subscriber message in response to handover_request\n // and publish a handover_ack message\n if (response.type === \"handover_subscriber\") {\n // Find correct unsProxy instance for handover_subscriber and set it active\n this.unsMqttProxies.forEach((unsProxy: UnsMqttProxy) => {\n if (unsProxy.instanceName === response.instanceName) {\n unsProxy.setSubscriberActive(response.batchSize, response.referenceHash);\n }\n });\n }\n\n // Requestor process\n // Check if the message is a handover_fin at the end of handover_subscriber messages\n if (response.type === \"handover_fin\") {\n logger.info(`${this.processName} - Received handover fin from ${event.packet?.properties?.userProperties?.processName}.`);\n\n // Maybe we should count the number of requests that were allrady made TODO\n // this.handoverInProgress = false;\n // this.requestingHandover = false;\n\n this.active = true;\n this.event.emit(\"handoverManager\", { active: this.active });\n logger.info(`${this.processName} - Handover completed.`);\n // Activate all UNS proxy instance publishers and subscribers.\n this.unsMqttProxies.forEach((unsProxy) => {\n unsProxy.setPublisherActive();\n unsProxy.setSubscriberActive();\n });\n\n // Maybe we should reply with handover_ack.\n await this.mqttProxy.publish(\n event.packet.properties?.responseTopic ?? \"\",\n JSON.stringify({\n type: \"handover_ack\",\n }),\n {\n retain: false,\n properties: {\n responseTopic: this.topicBuilder.getHandoverTopic(),\n userProperties: {\n processName: this.processName,\n },\n },\n },\n );\n logger.info(`${this.processName} - Handover ack message sent.`);\n }\n\n // Responder process\n // Check if the message is a handover_ack at the end of handover_fin messages\n if (response.type === \"handover_ack\") {\n logger.info(`${this.processName} - Received handover ack from ${event.packet?.properties?.userProperties?.processName}.`);\n this.handoverInProgress = false;\n this.requestingHandover = false;\n\n logger.info(`${this.processName} - Handover completed. Exiting process.`);\n process.exit(0);\n }\n } catch (error) {\n logger.error(`${this.processName} - Error processing handover response: ${error.message}`);\n }\n }\n}\n"]}
@@ -51,8 +51,8 @@ export declare const unsCoreSchema: z.ZodObject<{
51
51
  kidWellKnownUrl: z.ZodOptional<z.ZodString>;
52
52
  env: z.ZodDefault<z.ZodEnum<["dev", "staging", "test", "prod"]>>;
53
53
  }, "strict", z.ZodTypeAny, {
54
- handover?: boolean;
55
54
  env?: "dev" | "staging" | "test" | "prod";
55
+ handover?: boolean;
56
56
  processName?: string;
57
57
  password?: string | {
58
58
  provider?: "env";
@@ -75,8 +75,8 @@ export declare const unsCoreSchema: z.ZodObject<{
75
75
  jwksWellKnownUrl?: string;
76
76
  kidWellKnownUrl?: string;
77
77
  }, {
78
- handover?: boolean;
79
78
  env?: "dev" | "staging" | "test" | "prod";
79
+ handover?: boolean;
80
80
  processName?: string;
81
81
  password?: string | {
82
82
  provider?: "env";
@@ -567,8 +567,8 @@ export declare const unsCoreSchema: z.ZodObject<{
567
567
  }>>;
568
568
  }, "strict", z.ZodTypeAny, {
569
569
  uns?: {
570
- handover?: boolean;
571
570
  env?: "dev" | "staging" | "test" | "prod";
571
+ handover?: boolean;
572
572
  processName?: string;
573
573
  password?: string | {
574
574
  provider?: "env";
@@ -697,8 +697,8 @@ export declare const unsCoreSchema: z.ZodObject<{
697
697
  };
698
698
  }, {
699
699
  uns?: {
700
- handover?: boolean;
701
700
  env?: "dev" | "staging" | "test" | "prod";
701
+ handover?: boolean;
702
702
  processName?: string;
703
703
  password?: string | {
704
704
  provider?: "env";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/core",
3
- "version": "0.0.31",
3
+ "version": "0.0.34",
4
4
  "description": "Core utilities and runtime building blocks for UNS-based realtime transformers.",
5
5
  "type": "module",
6
6
  "license": "MIT",