@vizamodo/modo-dispatcher 1.1.77
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/README.md +43 -0
- package/dist/artifacts/builders.d.ts +32 -0
- package/dist/artifacts/builders.js +72 -0
- package/dist/artifacts/downloader.d.ts +28 -0
- package/dist/artifacts/downloader.js +102 -0
- package/dist/artifacts/normalizer.d.ts +22 -0
- package/dist/artifacts/normalizer.js +65 -0
- package/dist/artifacts/types.d.ts +94 -0
- package/dist/artifacts/types.js +1 -0
- package/dist/auth/identity/extract-identity.d.ts +8 -0
- package/dist/auth/identity/extract-identity.js +15 -0
- package/dist/auth/identity/normalize-teams.d.ts +1 -0
- package/dist/auth/identity/normalize-teams.js +5 -0
- package/dist/auth/identity/validate-claims.d.ts +2 -0
- package/dist/auth/identity/validate-claims.js +5 -0
- package/dist/auth/jwt/parse.d.ts +2 -0
- package/dist/auth/jwt/parse.js +16 -0
- package/dist/auth/jwt/verify.d.ts +1 -0
- package/dist/auth/jwt/verify.js +9 -0
- package/dist/auth/oauth/auth-error.d.ts +12 -0
- package/dist/auth/oauth/auth-error.js +47 -0
- package/dist/auth/oauth/auth-session-store.d.ts +30 -0
- package/dist/auth/oauth/auth-session-store.js +46 -0
- package/dist/auth/oauth/callback-server.d.ts +21 -0
- package/dist/auth/oauth/callback-server.js +319 -0
- package/dist/auth/oauth/github.d.ts +14 -0
- package/dist/auth/oauth/github.js +100 -0
- package/dist/auth/oauth/sse.d.ts +11 -0
- package/dist/auth/oauth/sse.js +67 -0
- package/dist/auth/oauth/templates/failed.html +629 -0
- package/dist/auth/oauth/templates/pending.html +620 -0
- package/dist/auth/oauth/templates/success.html +577 -0
- package/dist/auth/session/access-token.d.ts +15 -0
- package/dist/auth/session/access-token.js +64 -0
- package/dist/auth/session/login.d.ts +18 -0
- package/dist/auth/session/login.js +144 -0
- package/dist/auth/session/logout.d.ts +3 -0
- package/dist/auth/session/logout.js +21 -0
- package/dist/auth/session/refresh-token.d.ts +8 -0
- package/dist/auth/session/refresh-token.js +16 -0
- package/dist/auth/session/refresh.d.ts +2 -0
- package/dist/auth/session/refresh.js +61 -0
- package/dist/auth/session/rotate.d.ts +4 -0
- package/dist/auth/session/rotate.js +4 -0
- package/dist/auth/session/session-manager.d.ts +16 -0
- package/dist/auth/session/session-manager.js +54 -0
- package/dist/auth/session/token-state.d.ts +20 -0
- package/dist/auth/session/token-state.js +55 -0
- package/dist/auth/session/types.d.ts +35 -0
- package/dist/auth/session/types.js +1 -0
- package/dist/auth/storage/keychain.d.ts +16 -0
- package/dist/auth/storage/keychain.js +107 -0
- package/dist/auth/storage/memory.d.ts +10 -0
- package/dist/auth/storage/memory.js +15 -0
- package/dist/auth/storage/types.d.ts +5 -0
- package/dist/auth/storage/types.js +1 -0
- package/dist/config/defaults.d.ts +94 -0
- package/dist/config/defaults.js +116 -0
- package/dist/core/auth-bootstrap.d.ts +15 -0
- package/dist/core/auth-bootstrap.js +33 -0
- package/dist/core/bootstrap.d.ts +73 -0
- package/dist/core/bootstrap.js +248 -0
- package/dist/core/dispatcher.d.ts +2 -0
- package/dist/core/dispatcher.js +28 -0
- package/dist/core/ensure-bootstrap.d.ts +3 -0
- package/dist/core/ensure-bootstrap.js +25 -0
- package/dist/core/errors.d.ts +69 -0
- package/dist/core/errors.js +121 -0
- package/dist/core/runtime-orchestrator.d.ts +17 -0
- package/dist/core/runtime-orchestrator.js +47 -0
- package/dist/core/runtime.d.ts +16 -0
- package/dist/core/runtime.js +52 -0
- package/dist/core/validation.d.ts +2 -0
- package/dist/core/validation.js +21 -0
- package/dist/crypto/encrypt.d.ts +12 -0
- package/dist/crypto/encrypt.js +80 -0
- package/dist/flows/email-otp-flow.d.ts +7 -0
- package/dist/flows/email-otp-flow.js +249 -0
- package/dist/gateway/auth-header.d.ts +2 -0
- package/dist/gateway/auth-header.js +21 -0
- package/dist/gateway/client.d.ts +7 -0
- package/dist/gateway/client.js +24 -0
- package/dist/gateway/dispatch-with-bootstrap-retry.d.ts +25 -0
- package/dist/gateway/dispatch-with-bootstrap-retry.js +157 -0
- package/dist/gateway/dispatch.d.ts +23 -0
- package/dist/gateway/dispatch.js +110 -0
- package/dist/gateway/session-waiter.d.ts +11 -0
- package/dist/gateway/session-waiter.js +126 -0
- package/dist/gateway/session.d.ts +21 -0
- package/dist/gateway/session.js +74 -0
- package/dist/gateway/types.d.ts +113 -0
- package/dist/gateway/types.js +19 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +21 -0
- package/dist/runtime/runtime-context.d.ts +6 -0
- package/dist/runtime/runtime-context.js +1 -0
- package/dist/types/dispatcher.d.ts +275 -0
- package/dist/types/dispatcher.js +1 -0
- package/dist/types/payload.d.ts +5 -0
- package/dist/types/payload.js +2 -0
- package/dist/types/runtime-env.d.ts +2 -0
- package/dist/types/runtime-env.js +5 -0
- package/dist/ui/banner.d.ts +4 -0
- package/dist/ui/banner.js +20 -0
- package/dist/utils/request-dedup.d.ts +75 -0
- package/dist/utils/request-dedup.js +102 -0
- package/dist/utils/type-guards.d.ts +173 -0
- package/dist/utils/type-guards.js +232 -0
- package/package.json +43 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
/**
|
|
3
|
+
* Render a compact dispatch banner showing the acting user and team.
|
|
4
|
+
*/
|
|
5
|
+
export function renderDispatchBanner(login, teams, allowedTeams, isStatusMode) {
|
|
6
|
+
const action = isStatusMode ? "checking status" : "dispatching";
|
|
7
|
+
// Choose a single representative team to show to the user.
|
|
8
|
+
// Prefer an intersection with `allowedTeams` (if provided),
|
|
9
|
+
// otherwise fall back to the first JWT team.
|
|
10
|
+
let representative;
|
|
11
|
+
if (Array.isArray(allowedTeams) && allowedTeams.length > 0) {
|
|
12
|
+
const intersection = teams.filter((t) => allowedTeams.includes(t));
|
|
13
|
+
if (intersection.length > 0)
|
|
14
|
+
representative = intersection[0];
|
|
15
|
+
}
|
|
16
|
+
if (!representative && teams.length > 0)
|
|
17
|
+
representative = teams[0];
|
|
18
|
+
const display = representative ?? "unknown";
|
|
19
|
+
console.log(`\n[${login}] ${chalk.gray(`is ${action} as`)} ${display} …`);
|
|
20
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request deduplication utility for preventing concurrent identical requests.
|
|
3
|
+
*
|
|
4
|
+
* Multiple modules were implementing their own in-flight request tracking.
|
|
5
|
+
* This provides a reusable, type-safe solution.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/request-dedup
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Request deduplicator that prevents concurrent identical requests.
|
|
11
|
+
*
|
|
12
|
+
* When multiple callers request the same operation simultaneously,
|
|
13
|
+
* only one actual operation is performed and all callers receive the same result.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const authDeduplicator = new RequestDeduplicator<void>();
|
|
18
|
+
*
|
|
19
|
+
* async function ensureAuthenticated(): Promise<void> {
|
|
20
|
+
* return authDeduplicator.dedupe('auth', async () => {
|
|
21
|
+
* // Expensive authentication logic runs only once
|
|
22
|
+
* await performAuth();
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class RequestDeduplicator<T> {
|
|
28
|
+
private inFlight;
|
|
29
|
+
/**
|
|
30
|
+
* Execute a function with deduplication.
|
|
31
|
+
*
|
|
32
|
+
* If a request with the same key is already in flight, returns the existing promise.
|
|
33
|
+
* Otherwise, executes the function and caches the result until completion.
|
|
34
|
+
*
|
|
35
|
+
* @param key - Unique identifier for this type of request
|
|
36
|
+
* @param fn - Async function to execute
|
|
37
|
+
* @returns Promise that resolves when the operation completes
|
|
38
|
+
*/
|
|
39
|
+
dedupe(key: string, fn: () => Promise<T>): Promise<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a request with the given key is currently in flight.
|
|
42
|
+
*/
|
|
43
|
+
has(key: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Get the in-flight promise for a key, if any.
|
|
46
|
+
*/
|
|
47
|
+
get(key: string): Promise<T> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Clear a specific key or all in-flight requests.
|
|
50
|
+
*
|
|
51
|
+
* @param key - Optional key to clear. If omitted, clears all.
|
|
52
|
+
*/
|
|
53
|
+
clear(key?: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get the number of in-flight requests.
|
|
56
|
+
*/
|
|
57
|
+
get size(): number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Global deduplicators for common operations.
|
|
61
|
+
* These are shared across the application.
|
|
62
|
+
*/
|
|
63
|
+
export declare const globalDeduplicators: {
|
|
64
|
+
/** Authentication flow deduplicator */
|
|
65
|
+
readonly auth: RequestDeduplicator<void>;
|
|
66
|
+
/** Token hydration deduplicator */
|
|
67
|
+
readonly hydration: RequestDeduplicator<void>;
|
|
68
|
+
/** Token refresh deduplicator */
|
|
69
|
+
readonly refresh: RequestDeduplicator<string>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Reset all global deduplicators.
|
|
73
|
+
* Useful for testing.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resetGlobalDeduplicators(): void;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request deduplication utility for preventing concurrent identical requests.
|
|
3
|
+
*
|
|
4
|
+
* Multiple modules were implementing their own in-flight request tracking.
|
|
5
|
+
* This provides a reusable, type-safe solution.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/request-dedup
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Request deduplicator that prevents concurrent identical requests.
|
|
11
|
+
*
|
|
12
|
+
* When multiple callers request the same operation simultaneously,
|
|
13
|
+
* only one actual operation is performed and all callers receive the same result.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const authDeduplicator = new RequestDeduplicator<void>();
|
|
18
|
+
*
|
|
19
|
+
* async function ensureAuthenticated(): Promise<void> {
|
|
20
|
+
* return authDeduplicator.dedupe('auth', async () => {
|
|
21
|
+
* // Expensive authentication logic runs only once
|
|
22
|
+
* await performAuth();
|
|
23
|
+
* });
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export class RequestDeduplicator {
|
|
28
|
+
inFlight = new Map();
|
|
29
|
+
/**
|
|
30
|
+
* Execute a function with deduplication.
|
|
31
|
+
*
|
|
32
|
+
* If a request with the same key is already in flight, returns the existing promise.
|
|
33
|
+
* Otherwise, executes the function and caches the result until completion.
|
|
34
|
+
*
|
|
35
|
+
* @param key - Unique identifier for this type of request
|
|
36
|
+
* @param fn - Async function to execute
|
|
37
|
+
* @returns Promise that resolves when the operation completes
|
|
38
|
+
*/
|
|
39
|
+
async dedupe(key, fn) {
|
|
40
|
+
const existing = this.inFlight.get(key);
|
|
41
|
+
if (existing) {
|
|
42
|
+
return existing;
|
|
43
|
+
}
|
|
44
|
+
const promise = fn().finally(() => {
|
|
45
|
+
this.inFlight.delete(key);
|
|
46
|
+
});
|
|
47
|
+
this.inFlight.set(key, promise);
|
|
48
|
+
return promise;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a request with the given key is currently in flight.
|
|
52
|
+
*/
|
|
53
|
+
has(key) {
|
|
54
|
+
return this.inFlight.has(key);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the in-flight promise for a key, if any.
|
|
58
|
+
*/
|
|
59
|
+
get(key) {
|
|
60
|
+
return this.inFlight.get(key);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Clear a specific key or all in-flight requests.
|
|
64
|
+
*
|
|
65
|
+
* @param key - Optional key to clear. If omitted, clears all.
|
|
66
|
+
*/
|
|
67
|
+
clear(key) {
|
|
68
|
+
if (key) {
|
|
69
|
+
this.inFlight.delete(key);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.inFlight.clear();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the number of in-flight requests.
|
|
77
|
+
*/
|
|
78
|
+
get size() {
|
|
79
|
+
return this.inFlight.size;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Global deduplicators for common operations.
|
|
84
|
+
* These are shared across the application.
|
|
85
|
+
*/
|
|
86
|
+
export const globalDeduplicators = {
|
|
87
|
+
/** Authentication flow deduplicator */
|
|
88
|
+
auth: new RequestDeduplicator(),
|
|
89
|
+
/** Token hydration deduplicator */
|
|
90
|
+
hydration: new RequestDeduplicator(),
|
|
91
|
+
/** Token refresh deduplicator */
|
|
92
|
+
refresh: new RequestDeduplicator(),
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Reset all global deduplicators.
|
|
96
|
+
* Useful for testing.
|
|
97
|
+
*/
|
|
98
|
+
export function resetGlobalDeduplicators() {
|
|
99
|
+
globalDeduplicators.auth.clear();
|
|
100
|
+
globalDeduplicators.hydration.clear();
|
|
101
|
+
globalDeduplicators.refresh.clear();
|
|
102
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard utilities for runtime type checking.
|
|
3
|
+
*
|
|
4
|
+
* These functions provide type-safe alternatives to `as any` casts.
|
|
5
|
+
* All functions follow the TypeScript type guard pattern: `obj is T`.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/type-guards
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if a value is a non-null object.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a value is a string.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isString(value: unknown): value is string;
|
|
17
|
+
/**
|
|
18
|
+
* Check if a value is a non-empty string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isNonEmptyString(value: unknown): value is string;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a value is a number.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isNumber(value: unknown): value is number;
|
|
25
|
+
/**
|
|
26
|
+
* Check if a value is a boolean.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a value is an array.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is an array of strings.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isStringArray(value: unknown): value is string[];
|
|
37
|
+
/**
|
|
38
|
+
* Check if an object has a specific string property.
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasStringProperty<K extends string>(obj: unknown, key: K): obj is Record<K, string>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if an object has a specific number property.
|
|
43
|
+
*/
|
|
44
|
+
export declare function hasNumberProperty<K extends string>(obj: unknown, key: K): obj is Record<K, number>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if an object has a specific optional string property.
|
|
47
|
+
*/
|
|
48
|
+
export declare function hasOptionalStringProperty<K extends string>(obj: unknown, key: K): obj is Record<K, string | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if an object has a sessionId property.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hasSessionId(obj: unknown): obj is {
|
|
53
|
+
sessionId: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Check if an object has an executionKey property.
|
|
57
|
+
*/
|
|
58
|
+
export declare function hasExecutionKey(obj: unknown): obj is {
|
|
59
|
+
executionKey: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Check if an object has a wsToken property.
|
|
63
|
+
*/
|
|
64
|
+
export declare function hasWsToken(obj: unknown): obj is {
|
|
65
|
+
wsToken: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Check if an object has a wsUrl property.
|
|
69
|
+
*/
|
|
70
|
+
export declare function hasWsUrl(obj: unknown): obj is {
|
|
71
|
+
wsUrl: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Check if an object has a downloadUrl property.
|
|
75
|
+
*/
|
|
76
|
+
export declare function hasDownloadUrl(obj: unknown): obj is {
|
|
77
|
+
downloadUrl: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Check if an object has a path property.
|
|
81
|
+
*/
|
|
82
|
+
export declare function hasPath(obj: unknown): obj is {
|
|
83
|
+
path: string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Check if an object has a message property.
|
|
87
|
+
*/
|
|
88
|
+
export declare function hasMessage(obj: unknown): obj is {
|
|
89
|
+
message: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Check if an object has a stack property.
|
|
93
|
+
*/
|
|
94
|
+
export declare function hasStack(obj: unknown): obj is {
|
|
95
|
+
stack: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Check if an object has a type property with specific value.
|
|
99
|
+
*/
|
|
100
|
+
export declare function hasType<T extends string>(obj: unknown, expectedType: T): obj is {
|
|
101
|
+
type: T;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Check if an object has an action property with specific value.
|
|
105
|
+
*/
|
|
106
|
+
export declare function hasAction<T extends string>(obj: unknown, expectedAction: T): obj is {
|
|
107
|
+
action: T;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Check if an object has a status property.
|
|
111
|
+
*/
|
|
112
|
+
export declare function hasStatus(obj: unknown): obj is {
|
|
113
|
+
status: string;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Check if an object has a conclusion property.
|
|
117
|
+
*/
|
|
118
|
+
export declare function hasConclusion(obj: unknown): obj is {
|
|
119
|
+
conclusion: string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Safely extract a string property from an object.
|
|
123
|
+
* Returns undefined if the property doesn't exist or isn't a string.
|
|
124
|
+
*/
|
|
125
|
+
export declare function extractString<K extends string>(obj: unknown, key: K): string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Safely extract a number property from an object.
|
|
128
|
+
* Returns undefined if the property doesn't exist or isn't a number.
|
|
129
|
+
*/
|
|
130
|
+
export declare function extractNumber<K extends string>(obj: unknown, key: K): number | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Safely extract an object property from an object.
|
|
133
|
+
* Returns undefined if the property doesn't exist or isn't an object.
|
|
134
|
+
*/
|
|
135
|
+
export declare function extractObject<K extends string>(obj: unknown, key: K): Record<string, unknown> | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Safely extract an array property from an object.
|
|
138
|
+
* Returns undefined if the property doesn't exist or isn't an array.
|
|
139
|
+
*/
|
|
140
|
+
export declare function extractArray<K extends string>(obj: unknown, key: K): unknown[] | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Extract session ID from various possible locations in an object.
|
|
143
|
+
* Checks sessionId first, then executionKey, then returns undefined.
|
|
144
|
+
*/
|
|
145
|
+
export declare function extractSessionId(obj: unknown): string | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Extract error information from an unknown error.
|
|
148
|
+
* Returns a normalized error object with message and optional stack.
|
|
149
|
+
*/
|
|
150
|
+
export declare function extractErrorInfo(error: unknown): {
|
|
151
|
+
message: string;
|
|
152
|
+
stack?: string;
|
|
153
|
+
} | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Check if an object looks like a log artifact.
|
|
156
|
+
*/
|
|
157
|
+
export declare function isLogArtifactLike(obj: unknown): obj is {
|
|
158
|
+
path: string;
|
|
159
|
+
downloadUrl?: string;
|
|
160
|
+
status?: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Check if an object looks like a result artifact reference.
|
|
164
|
+
*/
|
|
165
|
+
export declare function isResultArtifactRef(obj: unknown): obj is {
|
|
166
|
+
downloadUrl: string;
|
|
167
|
+
path?: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Narrow an object to have specific required properties.
|
|
171
|
+
* Useful for validating gateway responses.
|
|
172
|
+
*/
|
|
173
|
+
export declare function hasRequiredProperties<T extends string>(obj: unknown, keys: readonly T[]): obj is Record<T, unknown>;
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard utilities for runtime type checking.
|
|
3
|
+
*
|
|
4
|
+
* These functions provide type-safe alternatives to `as any` casts.
|
|
5
|
+
* All functions follow the TypeScript type guard pattern: `obj is T`.
|
|
6
|
+
*
|
|
7
|
+
* @module utils/type-guards
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if a value is a non-null object.
|
|
11
|
+
*/
|
|
12
|
+
export function isObject(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Check if a value is a string.
|
|
17
|
+
*/
|
|
18
|
+
export function isString(value) {
|
|
19
|
+
return typeof value === 'string';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if a value is a non-empty string.
|
|
23
|
+
*/
|
|
24
|
+
export function isNonEmptyString(value) {
|
|
25
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check if a value is a number.
|
|
29
|
+
*/
|
|
30
|
+
export function isNumber(value) {
|
|
31
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a boolean.
|
|
35
|
+
*/
|
|
36
|
+
export function isBoolean(value) {
|
|
37
|
+
return typeof value === 'boolean';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Check if a value is an array.
|
|
41
|
+
*/
|
|
42
|
+
export function isArray(value) {
|
|
43
|
+
return Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if a value is an array of strings.
|
|
47
|
+
*/
|
|
48
|
+
export function isStringArray(value) {
|
|
49
|
+
return Array.isArray(value) && value.every(isString);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Check if an object has a specific string property.
|
|
53
|
+
*/
|
|
54
|
+
export function hasStringProperty(obj, key) {
|
|
55
|
+
return isObject(obj) && typeof obj[key] === 'string';
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if an object has a specific number property.
|
|
59
|
+
*/
|
|
60
|
+
export function hasNumberProperty(obj, key) {
|
|
61
|
+
return isObject(obj) && typeof obj[key] === 'number';
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if an object has a specific optional string property.
|
|
65
|
+
*/
|
|
66
|
+
export function hasOptionalStringProperty(obj, key) {
|
|
67
|
+
return isObject(obj) && (obj[key] === undefined || typeof obj[key] === 'string');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Check if an object has a sessionId property.
|
|
71
|
+
*/
|
|
72
|
+
export function hasSessionId(obj) {
|
|
73
|
+
return hasStringProperty(obj, 'sessionId');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if an object has an executionKey property.
|
|
77
|
+
*/
|
|
78
|
+
export function hasExecutionKey(obj) {
|
|
79
|
+
return hasStringProperty(obj, 'executionKey');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check if an object has a wsToken property.
|
|
83
|
+
*/
|
|
84
|
+
export function hasWsToken(obj) {
|
|
85
|
+
return hasStringProperty(obj, 'wsToken');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if an object has a wsUrl property.
|
|
89
|
+
*/
|
|
90
|
+
export function hasWsUrl(obj) {
|
|
91
|
+
return hasStringProperty(obj, 'wsUrl');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if an object has a downloadUrl property.
|
|
95
|
+
*/
|
|
96
|
+
export function hasDownloadUrl(obj) {
|
|
97
|
+
return hasStringProperty(obj, 'downloadUrl');
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if an object has a path property.
|
|
101
|
+
*/
|
|
102
|
+
export function hasPath(obj) {
|
|
103
|
+
return hasStringProperty(obj, 'path');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if an object has a message property.
|
|
107
|
+
*/
|
|
108
|
+
export function hasMessage(obj) {
|
|
109
|
+
return hasStringProperty(obj, 'message');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Check if an object has a stack property.
|
|
113
|
+
*/
|
|
114
|
+
export function hasStack(obj) {
|
|
115
|
+
return hasStringProperty(obj, 'stack');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if an object has a type property with specific value.
|
|
119
|
+
*/
|
|
120
|
+
export function hasType(obj, expectedType) {
|
|
121
|
+
return isObject(obj) && obj['type'] === expectedType;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Check if an object has an action property with specific value.
|
|
125
|
+
*/
|
|
126
|
+
export function hasAction(obj, expectedAction) {
|
|
127
|
+
return isObject(obj) && obj['action'] === expectedAction;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if an object has a status property.
|
|
131
|
+
*/
|
|
132
|
+
export function hasStatus(obj) {
|
|
133
|
+
return hasStringProperty(obj, 'status');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Check if an object has a conclusion property.
|
|
137
|
+
*/
|
|
138
|
+
export function hasConclusion(obj) {
|
|
139
|
+
return hasStringProperty(obj, 'conclusion');
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Safely extract a string property from an object.
|
|
143
|
+
* Returns undefined if the property doesn't exist or isn't a string.
|
|
144
|
+
*/
|
|
145
|
+
export function extractString(obj, key) {
|
|
146
|
+
if (!isObject(obj))
|
|
147
|
+
return undefined;
|
|
148
|
+
const value = obj[key];
|
|
149
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Safely extract a number property from an object.
|
|
153
|
+
* Returns undefined if the property doesn't exist or isn't a number.
|
|
154
|
+
*/
|
|
155
|
+
export function extractNumber(obj, key) {
|
|
156
|
+
if (!isObject(obj))
|
|
157
|
+
return undefined;
|
|
158
|
+
const value = obj[key];
|
|
159
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Safely extract an object property from an object.
|
|
163
|
+
* Returns undefined if the property doesn't exist or isn't an object.
|
|
164
|
+
*/
|
|
165
|
+
export function extractObject(obj, key) {
|
|
166
|
+
if (!isObject(obj))
|
|
167
|
+
return undefined;
|
|
168
|
+
const value = obj[key];
|
|
169
|
+
return isObject(value) ? value : undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Safely extract an array property from an object.
|
|
173
|
+
* Returns undefined if the property doesn't exist or isn't an array.
|
|
174
|
+
*/
|
|
175
|
+
export function extractArray(obj, key) {
|
|
176
|
+
if (!isObject(obj))
|
|
177
|
+
return undefined;
|
|
178
|
+
const value = obj[key];
|
|
179
|
+
return Array.isArray(value) ? value : undefined;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Extract session ID from various possible locations in an object.
|
|
183
|
+
* Checks sessionId first, then executionKey, then returns undefined.
|
|
184
|
+
*/
|
|
185
|
+
export function extractSessionId(obj) {
|
|
186
|
+
if (!isObject(obj))
|
|
187
|
+
return undefined;
|
|
188
|
+
if (hasSessionId(obj)) {
|
|
189
|
+
return obj.sessionId;
|
|
190
|
+
}
|
|
191
|
+
if (hasExecutionKey(obj)) {
|
|
192
|
+
return obj.executionKey;
|
|
193
|
+
}
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Extract error information from an unknown error.
|
|
198
|
+
* Returns a normalized error object with message and optional stack.
|
|
199
|
+
*/
|
|
200
|
+
export function extractErrorInfo(error) {
|
|
201
|
+
if (!isObject(error))
|
|
202
|
+
return undefined;
|
|
203
|
+
const message = extractString(error, 'message');
|
|
204
|
+
if (!message)
|
|
205
|
+
return undefined;
|
|
206
|
+
const stack = extractString(error, 'stack');
|
|
207
|
+
return {
|
|
208
|
+
message,
|
|
209
|
+
...(stack ? { stack } : {}),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Check if an object looks like a log artifact.
|
|
214
|
+
*/
|
|
215
|
+
export function isLogArtifactLike(obj) {
|
|
216
|
+
return isObject(obj) && hasPath(obj);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Check if an object looks like a result artifact reference.
|
|
220
|
+
*/
|
|
221
|
+
export function isResultArtifactRef(obj) {
|
|
222
|
+
return isObject(obj) && hasDownloadUrl(obj);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Narrow an object to have specific required properties.
|
|
226
|
+
* Useful for validating gateway responses.
|
|
227
|
+
*/
|
|
228
|
+
export function hasRequiredProperties(obj, keys) {
|
|
229
|
+
if (!isObject(obj))
|
|
230
|
+
return false;
|
|
231
|
+
return keys.every(key => key in obj);
|
|
232
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vizamodo/modo-dispatcher",
|
|
3
|
+
"version": "1.1.77",
|
|
4
|
+
"description": "Dispatcher module for GitHub workflow automation across Viza projects",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc && npm run copy:templates",
|
|
15
|
+
"copy:templates": "mkdir -p dist/auth/oauth/templates && cp src/auth/oauth/templates/*.html dist/auth/oauth/templates/",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"release:dev": "npm version prerelease --preid=dev && npm publish --tag dev --access public",
|
|
19
|
+
"release:beta": "npm version prerelease --preid=beta && npm publish --tag beta --access public",
|
|
20
|
+
"release:prod": "rm -rf dist && npx npm-check-updates -u && npm install && git add package.json package-lock.json && git commit -m 'chore(deps): auto update dependencies before release' || echo 'No changes' && node versioning.js && npm publish --tag latest --access public && git push",
|
|
21
|
+
"release:full": "rm -rf dist && npx npm-check-updates -u && npm install && git add package.json package-lock.json && git commit -m 'chore(deps): auto update dependencies before release' || echo 'No changes' && node versioning.js && npm login && npm publish --tag latest --access public && git push"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org/",
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"author": "Viza Team",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.9.1",
|
|
34
|
+
"@types/ws": "^8.18.1",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"vitest": "^4.1.7"
|
|
37
|
+
},
|
|
38
|
+
"type": "module",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"chalk": "^5.6.2",
|
|
41
|
+
"ws": "^8.20.1"
|
|
42
|
+
}
|
|
43
|
+
}
|