@auxiora/connectors 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/dist/auth-manager.d.ts +27 -0
- package/dist/auth-manager.d.ts.map +1 -0
- package/dist/auth-manager.js +138 -0
- package/dist/auth-manager.js.map +1 -0
- package/dist/define-connector.d.ts +19 -0
- package/dist/define-connector.d.ts.map +1 -0
- package/dist/define-connector.js +27 -0
- package/dist/define-connector.js.map +1 -0
- package/dist/executor.d.ts +19 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +72 -0
- package/dist/executor.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/registry.d.ts +13 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +33 -0
- package/dist/registry.js.map +1 -0
- package/dist/trigger-manager.d.ts +19 -0
- package/dist/trigger-manager.d.ts.map +1 -0
- package/dist/trigger-manager.js +62 -0
- package/dist/trigger-manager.js.map +1 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/auth-manager.ts +177 -0
- package/src/define-connector.ts +45 -0
- package/src/executor.ts +108 -0
- package/src/index.ts +18 -0
- package/src/registry.ts +42 -0
- package/src/trigger-manager.ts +95 -0
- package/src/types.ts +111 -0
- package/tests/auth-manager.test.ts +136 -0
- package/tests/define-connector.test.ts +61 -0
- package/tests/executor.test.ts +122 -0
- package/tests/registry.test.ts +101 -0
- package/tests/trigger-manager.test.ts +135 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2026 Auxiora Contributors
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AuthConfig, StoredToken } from './types.js';
|
|
2
|
+
export interface AuthManagerVault {
|
|
3
|
+
get(name: string): string | undefined;
|
|
4
|
+
has(name: string): boolean;
|
|
5
|
+
add(name: string, value: string): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
/** In-memory token store with vault-like interface for connector auth tokens. */
|
|
8
|
+
export declare class AuthManager {
|
|
9
|
+
private tokens;
|
|
10
|
+
private vault?;
|
|
11
|
+
constructor(vault?: AuthManagerVault);
|
|
12
|
+
/** Authenticate a connector instance with the given credentials. */
|
|
13
|
+
authenticate(instanceId: string, authConfig: AuthConfig, credentials: Record<string, string>): Promise<StoredToken>;
|
|
14
|
+
/** Refresh an OAuth2 token for a connector instance. */
|
|
15
|
+
refreshToken(instanceId: string, authConfig: AuthConfig): Promise<StoredToken>;
|
|
16
|
+
/** Restore a token from vault into the in-memory store. */
|
|
17
|
+
restoreToken(instanceId: string, token: StoredToken): void;
|
|
18
|
+
/** Get the stored token for a connector instance. */
|
|
19
|
+
getToken(instanceId: string): StoredToken | undefined;
|
|
20
|
+
/** Check if a token is expired. */
|
|
21
|
+
isTokenExpired(instanceId: string): boolean;
|
|
22
|
+
/** Revoke and remove a token for a connector instance. */
|
|
23
|
+
revokeToken(instanceId: string): Promise<boolean>;
|
|
24
|
+
/** Check whether a connector instance has a stored token. */
|
|
25
|
+
hasToken(instanceId: string): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=auth-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-manager.d.ts","sourceRoot":"","sources":["../src/auth-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI1D,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACtC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjD;AAED,iFAAiF;AACjF,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,KAAK,CAAC,CAAmB;gBAErB,KAAK,CAAC,EAAE,gBAAgB;IAIpC,oEAAoE;IAC9D,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,OAAO,CAAC,WAAW,CAAC;IAmDvB,wDAAwD;IAClD,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,WAAW,CAAC;IA+DvB,2DAA2D;IAC3D,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,IAAI;IAI1D,qDAAqD;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIrD,mCAAmC;IACnC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAM3C,0DAA0D;IACpD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYvD,6DAA6D;IAC7D,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CAGtC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
|
|
2
|
+
/** In-memory token store with vault-like interface for connector auth tokens. */
|
|
3
|
+
export class AuthManager {
|
|
4
|
+
tokens = new Map();
|
|
5
|
+
vault;
|
|
6
|
+
constructor(vault) {
|
|
7
|
+
this.vault = vault;
|
|
8
|
+
}
|
|
9
|
+
/** Authenticate a connector instance with the given credentials. */
|
|
10
|
+
async authenticate(instanceId, authConfig, credentials) {
|
|
11
|
+
let token;
|
|
12
|
+
switch (authConfig.type) {
|
|
13
|
+
case 'oauth2': {
|
|
14
|
+
if (!credentials.accessToken) {
|
|
15
|
+
throw new Error('OAuth2 authentication requires an accessToken');
|
|
16
|
+
}
|
|
17
|
+
token = {
|
|
18
|
+
accessToken: credentials.accessToken,
|
|
19
|
+
refreshToken: credentials.refreshToken,
|
|
20
|
+
expiresAt: credentials.expiresAt ? parseInt(credentials.expiresAt, 10) : undefined,
|
|
21
|
+
tokenType: credentials.tokenType ?? 'Bearer',
|
|
22
|
+
scopes: authConfig.oauth2?.scopes,
|
|
23
|
+
};
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'api_key': {
|
|
27
|
+
if (!credentials.apiKey) {
|
|
28
|
+
throw new Error('API key authentication requires an apiKey');
|
|
29
|
+
}
|
|
30
|
+
token = {
|
|
31
|
+
accessToken: credentials.apiKey,
|
|
32
|
+
tokenType: 'api_key',
|
|
33
|
+
};
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case 'token': {
|
|
37
|
+
if (!credentials.token) {
|
|
38
|
+
throw new Error('Token authentication requires a token');
|
|
39
|
+
}
|
|
40
|
+
token = {
|
|
41
|
+
accessToken: credentials.token,
|
|
42
|
+
tokenType: 'Bearer',
|
|
43
|
+
};
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`Unsupported auth type: ${authConfig.type}`);
|
|
48
|
+
}
|
|
49
|
+
this.tokens.set(instanceId, token);
|
|
50
|
+
// Persist tokens to vault if available
|
|
51
|
+
if (this.vault) {
|
|
52
|
+
await this.vault.add(`connectors.${instanceId}.tokens`, JSON.stringify(token));
|
|
53
|
+
}
|
|
54
|
+
return token;
|
|
55
|
+
}
|
|
56
|
+
/** Refresh an OAuth2 token for a connector instance. */
|
|
57
|
+
async refreshToken(instanceId, authConfig) {
|
|
58
|
+
const existing = this.tokens.get(instanceId);
|
|
59
|
+
if (!existing) {
|
|
60
|
+
throw new Error(`No token found for instance "${instanceId}"`);
|
|
61
|
+
}
|
|
62
|
+
if (authConfig.type !== 'oauth2') {
|
|
63
|
+
throw new Error('Token refresh is only supported for OAuth2');
|
|
64
|
+
}
|
|
65
|
+
if (!existing.refreshToken) {
|
|
66
|
+
throw new Error('No refresh token available');
|
|
67
|
+
}
|
|
68
|
+
// Load client credentials from vault
|
|
69
|
+
const credsJson = this.vault?.get(`connectors.${instanceId}.credentials`);
|
|
70
|
+
if (!credsJson) {
|
|
71
|
+
throw new Error(`No client credentials found for instance "${instanceId}"`);
|
|
72
|
+
}
|
|
73
|
+
const creds = JSON.parse(credsJson);
|
|
74
|
+
// Call Google's token endpoint to refresh
|
|
75
|
+
const body = new URLSearchParams({
|
|
76
|
+
client_id: creds.clientId,
|
|
77
|
+
client_secret: creds.clientSecret,
|
|
78
|
+
refresh_token: existing.refreshToken,
|
|
79
|
+
grant_type: 'refresh_token',
|
|
80
|
+
});
|
|
81
|
+
const response = await fetch(GOOGLE_TOKEN_URL, {
|
|
82
|
+
method: 'POST',
|
|
83
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
84
|
+
body: body.toString(),
|
|
85
|
+
});
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errBody = await response.text();
|
|
88
|
+
throw new Error(`Token refresh failed: ${response.status} ${errBody}`);
|
|
89
|
+
}
|
|
90
|
+
const data = await response.json();
|
|
91
|
+
const refreshed = {
|
|
92
|
+
accessToken: data.access_token,
|
|
93
|
+
refreshToken: data.refresh_token ?? existing.refreshToken,
|
|
94
|
+
expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : Date.now() + 3600_000,
|
|
95
|
+
tokenType: data.token_type ?? 'Bearer',
|
|
96
|
+
scopes: existing.scopes,
|
|
97
|
+
};
|
|
98
|
+
this.tokens.set(instanceId, refreshed);
|
|
99
|
+
// Persist updated tokens to vault
|
|
100
|
+
if (this.vault) {
|
|
101
|
+
await this.vault.add(`connectors.${instanceId}.tokens`, JSON.stringify(refreshed));
|
|
102
|
+
}
|
|
103
|
+
return refreshed;
|
|
104
|
+
}
|
|
105
|
+
/** Restore a token from vault into the in-memory store. */
|
|
106
|
+
restoreToken(instanceId, token) {
|
|
107
|
+
this.tokens.set(instanceId, token);
|
|
108
|
+
}
|
|
109
|
+
/** Get the stored token for a connector instance. */
|
|
110
|
+
getToken(instanceId) {
|
|
111
|
+
return this.tokens.get(instanceId);
|
|
112
|
+
}
|
|
113
|
+
/** Check if a token is expired. */
|
|
114
|
+
isTokenExpired(instanceId) {
|
|
115
|
+
const token = this.tokens.get(instanceId);
|
|
116
|
+
if (!token || !token.expiresAt)
|
|
117
|
+
return false;
|
|
118
|
+
return Date.now() >= token.expiresAt;
|
|
119
|
+
}
|
|
120
|
+
/** Revoke and remove a token for a connector instance. */
|
|
121
|
+
async revokeToken(instanceId) {
|
|
122
|
+
const deleted = this.tokens.delete(instanceId);
|
|
123
|
+
if (deleted && this.vault) {
|
|
124
|
+
try {
|
|
125
|
+
await this.vault.add(`connectors.${instanceId}.tokens`, '');
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
// Best-effort vault cleanup
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return deleted;
|
|
132
|
+
}
|
|
133
|
+
/** Check whether a connector instance has a stored token. */
|
|
134
|
+
hasToken(instanceId) {
|
|
135
|
+
return this.tokens.has(instanceId);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=auth-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-manager.js","sourceRoot":"","sources":["../src/auth-manager.ts"],"names":[],"mappings":"AAEA,MAAM,gBAAgB,GAAG,qCAAqC,CAAC;AAQ/D,iFAAiF;AACjF,MAAM,OAAO,WAAW;IACd,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IACxC,KAAK,CAAoB;IAEjC,YAAY,KAAwB;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,oEAAoE;IACpE,KAAK,CAAC,YAAY,CAChB,UAAkB,EAClB,UAAsB,EACtB,W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D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,qDAAqD;IACrD,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,mCAAmC;IACnC,cAAc,CAAC,UAAkB;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;QAC7C,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,SAAS,CAAC;IACvC,CAAC;IAED,0DAA0D;IAC1D,KAAK,CAAC,WAAW,CAAC,UAAkB;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC/C,IAAI,OAAO,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,UAAU,SAAS,EAAE,EAAE,CAAC,CAAC;YAC9D,CAAC;YAAC,MAAM,CAAC;gBACP,4BAA4B;YAC9B,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,6DAA6D;IAC7D,QAAQ,CAAC,UAAkB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Connector, ActionDefinition, TriggerDefinition, EntityDefinition, AuthConfig, TriggerEvent } from './types.js';
|
|
2
|
+
/** Options for defining a connector via the SDK helper. */
|
|
3
|
+
export interface DefineConnectorOptions {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
version: string;
|
|
8
|
+
category: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
auth: AuthConfig;
|
|
11
|
+
actions: ActionDefinition[];
|
|
12
|
+
triggers?: TriggerDefinition[];
|
|
13
|
+
entities?: EntityDefinition[];
|
|
14
|
+
executeAction: (actionId: string, params: Record<string, unknown>, token: string) => Promise<unknown>;
|
|
15
|
+
pollTrigger?: (triggerId: string, token: string, lastPollAt?: number) => Promise<TriggerEvent[]>;
|
|
16
|
+
}
|
|
17
|
+
/** SDK helper to define a connector with validated structure. */
|
|
18
|
+
export declare function defineConnector(options: DefineConnectorOptions): Connector;
|
|
19
|
+
//# sourceMappingURL=define-connector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-connector.d.ts","sourceRoot":"","sources":["../src/define-connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7H,2DAA2D;AAC3D,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC9B,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACtG,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;CAClG;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAyB1E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** SDK helper to define a connector with validated structure. */
|
|
2
|
+
export function defineConnector(options) {
|
|
3
|
+
if (!options.id || !options.name) {
|
|
4
|
+
throw new Error('Connector id and name are required');
|
|
5
|
+
}
|
|
6
|
+
if (!options.auth) {
|
|
7
|
+
throw new Error('Connector auth config is required');
|
|
8
|
+
}
|
|
9
|
+
if (!options.actions || options.actions.length === 0) {
|
|
10
|
+
throw new Error('Connector must define at least one action');
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
id: options.id,
|
|
14
|
+
name: options.name,
|
|
15
|
+
description: options.description,
|
|
16
|
+
version: options.version,
|
|
17
|
+
category: options.category,
|
|
18
|
+
icon: options.icon,
|
|
19
|
+
auth: options.auth,
|
|
20
|
+
actions: options.actions,
|
|
21
|
+
triggers: options.triggers ?? [],
|
|
22
|
+
entities: options.entities ?? [],
|
|
23
|
+
executeAction: options.executeAction,
|
|
24
|
+
pollTrigger: options.pollTrigger,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=define-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-connector.js","sourceRoot":"","sources":["../src/define-connector.ts"],"names":[],"mappings":"AAkBA,iEAAiE;AACjE,MAAM,UAAU,eAAe,CAAC,OAA+B;IAC7D,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE;QACd,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;QAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;QAChC,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { TrustGate } from '@auxiora/autonomy';
|
|
2
|
+
import type { ActionAuditTrail } from '@auxiora/autonomy';
|
|
3
|
+
import type { ConnectorRegistry } from './registry.js';
|
|
4
|
+
import type { AuthManager } from './auth-manager.js';
|
|
5
|
+
export interface ExecutionResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
error?: string;
|
|
9
|
+
auditId?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class ActionExecutor {
|
|
12
|
+
private registry;
|
|
13
|
+
private authManager;
|
|
14
|
+
private trustGate;
|
|
15
|
+
private auditTrail;
|
|
16
|
+
constructor(registry: ConnectorRegistry, authManager: AuthManager, trustGate: TrustGate, auditTrail: ActionAuditTrail);
|
|
17
|
+
execute(connectorId: string, actionId: string, params: Record<string, unknown>, instanceId: string): Promise<ExecutionResult>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,UAAU,CAAmB;gBAGnC,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,gBAAgB;IAQxB,OAAO,CACX,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,eAAe,CAAC;CAuE5B"}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export class ActionExecutor {
|
|
2
|
+
registry;
|
|
3
|
+
authManager;
|
|
4
|
+
trustGate;
|
|
5
|
+
auditTrail;
|
|
6
|
+
constructor(registry, authManager, trustGate, auditTrail) {
|
|
7
|
+
this.registry = registry;
|
|
8
|
+
this.authManager = authManager;
|
|
9
|
+
this.trustGate = trustGate;
|
|
10
|
+
this.auditTrail = auditTrail;
|
|
11
|
+
}
|
|
12
|
+
async execute(connectorId, actionId, params, instanceId) {
|
|
13
|
+
const connector = this.registry.get(connectorId);
|
|
14
|
+
if (!connector) {
|
|
15
|
+
return { success: false, error: `Connector "${connectorId}" not found` };
|
|
16
|
+
}
|
|
17
|
+
const action = connector.actions.find((a) => a.id === actionId);
|
|
18
|
+
if (!action) {
|
|
19
|
+
return { success: false, error: `Action "${actionId}" not found in connector "${connectorId}"` };
|
|
20
|
+
}
|
|
21
|
+
// Check trust gate
|
|
22
|
+
const gateResult = this.trustGate.gate(action.trustDomain, `${connectorId}:${actionId}`, action.trustMinimum);
|
|
23
|
+
if (!gateResult.allowed) {
|
|
24
|
+
const audit = await this.auditTrail.record({
|
|
25
|
+
trustLevel: gateResult.currentLevel,
|
|
26
|
+
domain: action.trustDomain,
|
|
27
|
+
intent: `${connectorId}:${actionId}`,
|
|
28
|
+
plan: JSON.stringify(params),
|
|
29
|
+
executed: false,
|
|
30
|
+
outcome: 'failure',
|
|
31
|
+
reasoning: gateResult.message,
|
|
32
|
+
rollbackAvailable: false,
|
|
33
|
+
});
|
|
34
|
+
return { success: false, error: gateResult.message, auditId: audit.id };
|
|
35
|
+
}
|
|
36
|
+
// Get token
|
|
37
|
+
const token = this.authManager.getToken(instanceId);
|
|
38
|
+
if (!token) {
|
|
39
|
+
return { success: false, error: `No authentication token for instance "${instanceId}"` };
|
|
40
|
+
}
|
|
41
|
+
// Execute
|
|
42
|
+
try {
|
|
43
|
+
const data = await connector.executeAction(actionId, params, token.accessToken);
|
|
44
|
+
const audit = await this.auditTrail.record({
|
|
45
|
+
trustLevel: gateResult.currentLevel,
|
|
46
|
+
domain: action.trustDomain,
|
|
47
|
+
intent: `${connectorId}:${actionId}`,
|
|
48
|
+
plan: JSON.stringify(params),
|
|
49
|
+
executed: true,
|
|
50
|
+
outcome: 'success',
|
|
51
|
+
reasoning: gateResult.message,
|
|
52
|
+
rollbackAvailable: action.reversible,
|
|
53
|
+
});
|
|
54
|
+
return { success: true, data, auditId: audit.id };
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
58
|
+
const audit = await this.auditTrail.record({
|
|
59
|
+
trustLevel: gateResult.currentLevel,
|
|
60
|
+
domain: action.trustDomain,
|
|
61
|
+
intent: `${connectorId}:${actionId}`,
|
|
62
|
+
plan: JSON.stringify(params),
|
|
63
|
+
executed: true,
|
|
64
|
+
outcome: 'failure',
|
|
65
|
+
reasoning: msg,
|
|
66
|
+
rollbackAvailable: false,
|
|
67
|
+
});
|
|
68
|
+
return { success: false, error: msg, auditId: audit.id };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,cAAc;IACjB,QAAQ,CAAoB;IAC5B,WAAW,CAAc;IACzB,SAAS,CAAY;IACrB,UAAU,CAAmB;IAErC,YACE,QAA2B,EAC3B,WAAwB,EACxB,SAAoB,EACpB,UAA4B;QAE5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,OAAO,CACX,WAAmB,EACnB,QAAgB,EAChB,MAA+B,EAC/B,UAAkB;QAElB,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,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AAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QAC3D,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { AuthType, OAuth2Config, AuthConfig, ActionDefinition, ParamDefinition, TriggerDefinition, EntityDefinition, Connector, TriggerEvent, StoredToken, ConnectorInstance, } from './types.js';
|
|
2
|
+
export { ConnectorRegistry } from './registry.js';
|
|
3
|
+
export { AuthManager } from './auth-manager.js';
|
|
4
|
+
export { ActionExecutor, type ExecutionResult } from './executor.js';
|
|
5
|
+
export { TriggerManager, type TriggerHandler } from './trigger-manager.js';
|
|
6
|
+
export { defineConnector, type DefineConnectorOptions } from './define-connector.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ConnectorRegistry } from './registry.js';
|
|
2
|
+
export { AuthManager } from './auth-manager.js';
|
|
3
|
+
export { ActionExecutor } from './executor.js';
|
|
4
|
+
export { TriggerManager } from './trigger-manager.js';
|
|
5
|
+
export { defineConnector } from './define-connector.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAwB,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,cAAc,EAAuB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAA+B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Connector, ActionDefinition, TriggerDefinition } from './types.js';
|
|
2
|
+
export declare class ConnectorRegistry {
|
|
3
|
+
private connectors;
|
|
4
|
+
register(connector: Connector): void;
|
|
5
|
+
get(id: string): Connector | undefined;
|
|
6
|
+
list(): Connector[];
|
|
7
|
+
listByCategory(category: string): Connector[];
|
|
8
|
+
getActions(connectorId: string): ActionDefinition[];
|
|
9
|
+
getTriggers(connectorId: string): TriggerDefinition[];
|
|
10
|
+
has(id: string): boolean;
|
|
11
|
+
unregister(id: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEjF,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,UAAU,CAAgC;IAElD,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAOpC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAItC,IAAI,IAAI,SAAS,EAAE;IAInB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE;IAI7C,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB,EAAE;IAKnD,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,iBAAiB,EAAE;IAKrD,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIxB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;CAGhC"}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class ConnectorRegistry {
|
|
2
|
+
connectors = new Map();
|
|
3
|
+
register(connector) {
|
|
4
|
+
if (this.connectors.has(connector.id)) {
|
|
5
|
+
throw new Error(`Connector "${connector.id}" is already registered`);
|
|
6
|
+
}
|
|
7
|
+
this.connectors.set(connector.id, connector);
|
|
8
|
+
}
|
|
9
|
+
get(id) {
|
|
10
|
+
return this.connectors.get(id);
|
|
11
|
+
}
|
|
12
|
+
list() {
|
|
13
|
+
return [...this.connectors.values()];
|
|
14
|
+
}
|
|
15
|
+
listByCategory(category) {
|
|
16
|
+
return [...this.connectors.values()].filter((c) => c.category === category);
|
|
17
|
+
}
|
|
18
|
+
getActions(connectorId) {
|
|
19
|
+
const connector = this.connectors.get(connectorId);
|
|
20
|
+
return connector ? connector.actions : [];
|
|
21
|
+
}
|
|
22
|
+
getTriggers(connectorId) {
|
|
23
|
+
const connector = this.connectors.get(connectorId);
|
|
24
|
+
return connector ? connector.triggers : [];
|
|
25
|
+
}
|
|
26
|
+
has(id) {
|
|
27
|
+
return this.connectors.has(id);
|
|
28
|
+
}
|
|
29
|
+
unregister(id) {
|
|
30
|
+
return this.connectors.delete(id);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../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AAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,UAAU,CAAC,EAAU;QACnB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConnectorRegistry } from './registry.js';
|
|
2
|
+
import type { AuthManager } from './auth-manager.js';
|
|
3
|
+
import type { TriggerEvent } from './types.js';
|
|
4
|
+
export type TriggerHandler = (events: TriggerEvent[]) => void | Promise<void>;
|
|
5
|
+
export declare class TriggerManager {
|
|
6
|
+
private registry;
|
|
7
|
+
private authManager;
|
|
8
|
+
private subscriptions;
|
|
9
|
+
constructor(registry: ConnectorRegistry, authManager: AuthManager);
|
|
10
|
+
/** Subscribe to a trigger on a connector instance. Returns a subscription ID. */
|
|
11
|
+
subscribe(connectorId: string, triggerId: string, instanceId: string, handler: TriggerHandler): string;
|
|
12
|
+
/** Unsubscribe from a trigger. */
|
|
13
|
+
unsubscribe(subscriptionId: string): boolean;
|
|
14
|
+
/** Poll all subscriptions and invoke handlers for new events. */
|
|
15
|
+
pollAll(): Promise<TriggerEvent[]>;
|
|
16
|
+
/** Get all active subscription IDs. */
|
|
17
|
+
getSubscriptions(): string[];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=trigger-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-manager.d.ts","sourceRoot":"","sources":["../src/trigger-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAU9E,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAoB;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,aAAa,CAAmC;gBAE5C,QAAQ,EAAE,iBAAiB,EAAE,WAAW,EAAE,WAAW;IAKjE,iFAAiF;IACjF,SAAS,CACP,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,MAAM;IAuBT,kCAAkC;IAClC,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO;IAI5C,iEAAiE;IAC3D,OAAO,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IA+BxC,uCAAuC;IACvC,gBAAgB,IAAI,MAAM,EAAE;CAG7B"}
|