@xemahq/biomes-platform-ms365 0.1.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 +175 -0
- package/contributions/microsoft.connector-adapter.contribution.json +67 -0
- package/dist/connector-adapters/index.d.ts +11 -0
- package/dist/connector-adapters/index.d.ts.map +1 -0
- package/dist/connector-adapters/index.js +202 -0
- package/dist/connector-adapters/index.js.map +1 -0
- package/dist/graph/graph-client.d.ts +32 -0
- package/dist/graph/graph-client.d.ts.map +1 -0
- package/dist/graph/graph-client.js +128 -0
- package/dist/graph/graph-client.js.map +1 -0
- package/dist/graph/graph-types.d.ts +81 -0
- package/dist/graph/graph-types.d.ts.map +1 -0
- package/dist/graph/graph-types.js +7 -0
- package/dist/graph/graph-types.js.map +1 -0
- package/dist/graph/mail-envelope.d.ts +12 -0
- package/dist/graph/mail-envelope.d.ts.map +1 -0
- package/dist/graph/mail-envelope.js +23 -0
- package/dist/graph/mail-envelope.js.map +1 -0
- package/dist/graph/message-normalizer.d.ts +25 -0
- package/dist/graph/message-normalizer.d.ts.map +1 -0
- package/dist/graph/message-normalizer.js +143 -0
- package/dist/graph/message-normalizer.js.map +1 -0
- package/dist/graph/subscription-lifecycle.d.ts +19 -0
- package/dist/graph/subscription-lifecycle.d.ts.map +1 -0
- package/dist/graph/subscription-lifecycle.js +114 -0
- package/dist/graph/subscription-lifecycle.js.map +1 -0
- package/install-schema/install.json +28 -0
- package/package.json +37 -0
- package/xema-biome.json +120 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Xema Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
|
|
4
|
+
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
|
5
|
+
|
|
6
|
+
-----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
|
|
10
|
+
Licensor: Neuralchowder Inc.
|
|
11
|
+
|
|
12
|
+
Licensed Work: Xema. The Licensed Work is (c) 2026 Neuralchowder Inc.
|
|
13
|
+
|
|
14
|
+
The Licensed Work includes, without limitation, Xema Core, Xema Runtime,
|
|
15
|
+
Xema Kernel, Xema control plane, Xema application runtime, Xema biome
|
|
16
|
+
runtime, Xema biome registry, Xema store services, Xema orchestration
|
|
17
|
+
services, Xema agents, Xema skills, Xema memory services, Xema APIs, Xema
|
|
18
|
+
user interfaces, Xema command-line tools, Xema deployment artifacts, Xema
|
|
19
|
+
templates, Xema specifications, Xema schemas, Xema manifests, Xema
|
|
20
|
+
documentation, Xema examples, and all source code, object code, binaries,
|
|
21
|
+
packages, modules, configuration files, manifests, schemas, examples,
|
|
22
|
+
templates, documentation, and derivative works included in or distributed
|
|
23
|
+
as part of the Xema software project.
|
|
24
|
+
|
|
25
|
+
The Licensed Work does not include any third-party software, libraries,
|
|
26
|
+
dependencies, packages, assets, or components that are distributed with the
|
|
27
|
+
Licensed Work but are governed by their own separate license terms. Such
|
|
28
|
+
third-party materials remain subject to their respective licenses.
|
|
29
|
+
|
|
30
|
+
A specific file, package, component, or directory may state that it is
|
|
31
|
+
governed by a different license. In that case, that specific file, package,
|
|
32
|
+
component, or directory is governed by the license expressly stated therein.
|
|
33
|
+
|
|
34
|
+
Additional Use Grant:
|
|
35
|
+
|
|
36
|
+
You may make production use of the Licensed Work, provided that your use
|
|
37
|
+
does not include offering, providing, making available, distributing,
|
|
38
|
+
hosting, managing, embedding, reselling, white-labeling, sublicensing,
|
|
39
|
+
commercializing, or otherwise making the Licensed Work, or any modified
|
|
40
|
+
version or derivative work of the Licensed Work, available to Third Parties
|
|
41
|
+
as part of a Competitive Offering.
|
|
42
|
+
|
|
43
|
+
The following definitions and clarifications form part of, and govern
|
|
44
|
+
the interpretation of, the Additional Use Grant set out above.
|
|
45
|
+
|
|
46
|
+
1. "Production Use" means any use of the Licensed Work other than for
|
|
47
|
+
development, testing, evaluation, demonstration, experimentation,
|
|
48
|
+
benchmarking, or other non-production purposes.
|
|
49
|
+
|
|
50
|
+
2. "Affiliate" means any entity that, directly or indirectly,
|
|
51
|
+
controls, is controlled by, or is under common control with you,
|
|
52
|
+
where "control" means ownership of more than fifty percent (50%) of
|
|
53
|
+
the voting interests of the entity, or the power to direct its
|
|
54
|
+
management.
|
|
55
|
+
|
|
56
|
+
3. "Third Party" means any natural person or legal entity other than
|
|
57
|
+
you and your Affiliates.
|
|
58
|
+
|
|
59
|
+
4. "Competitive Offering" means any product or service, made available
|
|
60
|
+
to one or more Third Parties for a fee or other consideration
|
|
61
|
+
(including without limitation on a paid, subscription,
|
|
62
|
+
advertising-supported, hosted, or managed-service basis), that is
|
|
63
|
+
offered or marketed as, or that competes with, a software platform,
|
|
64
|
+
runtime, orchestration system, agent or automation system,
|
|
65
|
+
extension or distribution marketplace, or other software system
|
|
66
|
+
that provides, in substantial part, the same or substantially
|
|
67
|
+
similar capabilities as those provided by the Licensed Work. A
|
|
68
|
+
product or service is a Competitive Offering whether the Licensed
|
|
69
|
+
Work is provided in whole or in part, alone or bundled with other
|
|
70
|
+
software, and whether modified or unmodified.
|
|
71
|
+
|
|
72
|
+
5. Providing, hosting, or managing the Licensed Work for a Third Party,
|
|
73
|
+
or otherwise making the Licensed Work available to a Third Party as
|
|
74
|
+
a hosted or managed service such that the Third Party obtains the
|
|
75
|
+
principal value or functionality of the Licensed Work, is a
|
|
76
|
+
Competitive Offering and is not permitted by the Additional Use
|
|
77
|
+
Grant.
|
|
78
|
+
|
|
79
|
+
6. Subject to the foregoing, the Additional Use Grant permits you to
|
|
80
|
+
make Production Use of the Licensed Work for your own internal
|
|
81
|
+
business purposes and to build, operate, and provide your own
|
|
82
|
+
products and services to Third Parties, provided that the Licensed
|
|
83
|
+
Work itself (whether modified or unmodified) is not the product or
|
|
84
|
+
service, and is not a Competitive Offering, made available to those
|
|
85
|
+
Third Parties.
|
|
86
|
+
|
|
87
|
+
7. You may modify the Licensed Work and create derivative works for
|
|
88
|
+
any purpose permitted by this License. Any Production Use of such
|
|
89
|
+
modified or derivative works remains subject to the same
|
|
90
|
+
restrictions as the Licensed Work, including the prohibition on
|
|
91
|
+
Competitive Offerings.
|
|
92
|
+
|
|
93
|
+
8. Use of the Licensed Work by your own employees, contractors, and
|
|
94
|
+
agents, acting on your behalf and for your benefit, is not by
|
|
95
|
+
itself making the Licensed Work available to a Third Party.
|
|
96
|
+
|
|
97
|
+
9. Embedding or distributing the Licensed Work as a component of your
|
|
98
|
+
own product or service is permitted only where the Licensed Work
|
|
99
|
+
does not constitute the principal value of that product or service
|
|
100
|
+
and the product or service is not a Competitive Offering.
|
|
101
|
+
|
|
102
|
+
10. Nothing in this Additional Use Grant grants any right to use any
|
|
103
|
+
name, trademark, service mark, or logo of the Licensor or its
|
|
104
|
+
Affiliates, except as reasonably required for customary
|
|
105
|
+
attribution.
|
|
106
|
+
|
|
107
|
+
11. The rights stated in this Additional Use Grant are the maximum
|
|
108
|
+
rights granted for Production Use prior to the Change Date. Any
|
|
109
|
+
Production Use not expressly permitted requires a separate
|
|
110
|
+
commercial license from the Licensor.
|
|
111
|
+
|
|
112
|
+
12. If any provision of this Additional Use Grant is held invalid or
|
|
113
|
+
unenforceable, that provision shall be limited or eliminated to
|
|
114
|
+
the minimum extent necessary so that the remainder of this
|
|
115
|
+
Additional Use Grant, and of this License, remains in full force
|
|
116
|
+
and effect. The Licensor reserves all rights not expressly granted
|
|
117
|
+
by this License.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Change Date: Four years from the date the specific version of the Licensed
|
|
121
|
+
Work is first publicly released by Licensor.
|
|
122
|
+
|
|
123
|
+
Change License: Mozilla Public License, Version 2.0
|
|
124
|
+
|
|
125
|
+
For information about alternative licensing arrangements, commercial
|
|
126
|
+
licensing, enterprise licensing, OEM licensing, appliance licensing, managed
|
|
127
|
+
service licensing, cloud provider licensing, or other commercial use of the
|
|
128
|
+
Licensed Work, please contact: licensing@neuralchowder.com
|
|
129
|
+
|
|
130
|
+
-----------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
Notice
|
|
133
|
+
|
|
134
|
+
Business Source License 1.1
|
|
135
|
+
|
|
136
|
+
Terms
|
|
137
|
+
|
|
138
|
+
The Licensor hereby grants you the right to copy, modify, create derivative
|
|
139
|
+
works, redistribute, and make non-production use of the Licensed Work. The
|
|
140
|
+
Licensor may make an Additional Use Grant, above, permitting limited
|
|
141
|
+
production use.
|
|
142
|
+
|
|
143
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly
|
|
144
|
+
available distribution of a specific version of the Licensed Work under this
|
|
145
|
+
License, whichever comes first, the Licensor hereby grants you rights under
|
|
146
|
+
the terms of the Change License, and the rights granted in the paragraph above
|
|
147
|
+
terminate.
|
|
148
|
+
|
|
149
|
+
If your use of the Licensed Work does not comply with the requirements
|
|
150
|
+
currently in effect as described in this License, you must purchase a
|
|
151
|
+
commercial license from the Licensor, its affiliated entities, or authorized
|
|
152
|
+
resellers, or you must refrain from using the Licensed Work.
|
|
153
|
+
|
|
154
|
+
All copies of the original and modified Licensed Work, and derivative works of
|
|
155
|
+
the Licensed Work, are subject to this License. This License applies separately
|
|
156
|
+
for each version of the Licensed Work and the Change Date may vary for each
|
|
157
|
+
version of the Licensed Work released by Licensor.
|
|
158
|
+
|
|
159
|
+
You must conspicuously display this License on each original or modified copy
|
|
160
|
+
of the Licensed Work. If you receive the Licensed Work in original or modified
|
|
161
|
+
form from a third party, the terms and conditions set forth in this License
|
|
162
|
+
apply to your use of that work.
|
|
163
|
+
|
|
164
|
+
Any use of the Licensed Work in violation of this License will automatically
|
|
165
|
+
terminate your rights under this License for the current and all other
|
|
166
|
+
versions of the Licensed Work.
|
|
167
|
+
|
|
168
|
+
This License does not grant you any right in any trademark or logo of Licensor
|
|
169
|
+
or its affiliates, provided that you may use a trademark or logo of Licensor
|
|
170
|
+
as expressly required by this License.
|
|
171
|
+
|
|
172
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
|
|
173
|
+
"AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
|
|
174
|
+
OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
175
|
+
FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kind": "connector-adapter",
|
|
3
|
+
"manifest": {
|
|
4
|
+
"provider": {
|
|
5
|
+
"providerKey": "microsoft",
|
|
6
|
+
"displayName": "Microsoft 365",
|
|
7
|
+
"description": "Microsoft 365 / Outlook via OAuth. One Azure AD (Entra ID) app registration backs every Microsoft connector (Outlook mail today) with incremental Graph scopes.",
|
|
8
|
+
"iconName": "Mail",
|
|
9
|
+
"category": "Email",
|
|
10
|
+
"appAuthKind": "oauth2",
|
|
11
|
+
"allowOrgOverride": true,
|
|
12
|
+
"appCredentialSchema": [
|
|
13
|
+
{
|
|
14
|
+
"key": "clientId",
|
|
15
|
+
"label": "Application (client) ID",
|
|
16
|
+
"type": "TEXT",
|
|
17
|
+
"required": true,
|
|
18
|
+
"isSecret": false,
|
|
19
|
+
"transform": "TRIM",
|
|
20
|
+
"placeholder": "11111111-1111-1111-1111-111111111111"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"key": "clientSecret",
|
|
24
|
+
"label": "Client secret",
|
|
25
|
+
"type": "PASSWORD",
|
|
26
|
+
"required": true,
|
|
27
|
+
"isSecret": true,
|
|
28
|
+
"transform": "TRIM"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"key": "tenantId",
|
|
32
|
+
"label": "Azure AD tenant id (optional)",
|
|
33
|
+
"type": "TEXT",
|
|
34
|
+
"required": false,
|
|
35
|
+
"isSecret": false,
|
|
36
|
+
"transform": "TRIM",
|
|
37
|
+
"placeholder": "common",
|
|
38
|
+
"hint": "Leave blank / use \"common\" for a multi-tenant app registration."
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"oauthEndpoints": {
|
|
42
|
+
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
|
|
43
|
+
"tokenUrl": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
|
|
44
|
+
"extraAuthorizeParams": {
|
|
45
|
+
"response_mode": "query",
|
|
46
|
+
"prompt": "consent"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"connectors": [
|
|
51
|
+
{
|
|
52
|
+
"connectorKey": "MICROSOFT_GRAPH",
|
|
53
|
+
"displayName": "Microsoft 365 (Outlook Mail)",
|
|
54
|
+
"description": "Read Outlook mail via Microsoft Graph OAuth.",
|
|
55
|
+
"iconName": "Mail",
|
|
56
|
+
"providerKey": "microsoft",
|
|
57
|
+
"scopes": [
|
|
58
|
+
"offline_access",
|
|
59
|
+
"https://graph.microsoft.com/Mail.Read",
|
|
60
|
+
"https://graph.microsoft.com/User.Read"
|
|
61
|
+
],
|
|
62
|
+
"connectionCredentialKind": "oauth_user",
|
|
63
|
+
"adapterKind": "mail"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ConnectorAdapterModule } from '@xemahq/biome-sdk/adapter';
|
|
2
|
+
import { type ConnectorDescriptor, type ProviderDescriptor } from '@xemahq/kernel-contracts/connector';
|
|
3
|
+
export declare const microsoftGraphProvider: ConnectorAdapterModule;
|
|
4
|
+
declare const connectorAdapters: readonly ConnectorAdapterModule[];
|
|
5
|
+
export default connectorAdapters;
|
|
6
|
+
export declare const providerDescriptor: ProviderDescriptor;
|
|
7
|
+
export declare const connectorDescriptors: readonly ConnectorDescriptor[];
|
|
8
|
+
export { parseMessageResourcePath, drainMessageDelta, establishInboxSubscription, renewIfDue, resolveValidationHandshake, getMailboxAddress, } from '../graph/subscription-lifecycle.js';
|
|
9
|
+
export { GraphClient } from '../graph/graph-client.js';
|
|
10
|
+
export { buildMailEnvelope } from '../graph/mail-envelope.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/connector-adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,sBAAsB,EAG5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAQL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EAExB,MAAM,oCAAoC,CAAC;AA0M5C,eAAO,MAAM,sBAAsB,EAAE,sBAgCnC,CAAC;AAEH,QAAA,MAAM,iBAAiB,EAAE,SAAS,sBAAsB,EAA6B,CAAC;AACtF,eAAe,iBAAiB,CAAC;AAuBjC,eAAO,MAAM,kBAAkB,EAAE,kBAoDhC,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,SAAS,mBAAmB,EAoB9D,CAAC;AAsDF,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,EACV,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { adapterError, defineConnectorAdapter, err, } from '@xemahq/biome-sdk/adapter';
|
|
2
|
+
import { CredentialFieldTransform, CredentialFieldType, CredentialKind, ConnectorOnboardingKind, MICROSOFT_OAUTH_ENDPOINTS, ProviderAppAuthKind, ProviderOrigin, } from '@xemahq/kernel-contracts/connector';
|
|
3
|
+
import { buildMailEnvelope, MAIL_EVENT } from '../graph/mail-envelope.js';
|
|
4
|
+
import { verifyClientState } from '../graph/subscription-lifecycle.js';
|
|
5
|
+
const PROVIDER_SLUG = 'microsoft_graph';
|
|
6
|
+
const microsoftGraphVerifier = {
|
|
7
|
+
signatureHeader: 'x-ms-graph-client-state',
|
|
8
|
+
algorithm: 'none',
|
|
9
|
+
secretSource: 'org-connection-secret',
|
|
10
|
+
verify({ rawBody, secret }) {
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = JSON.parse(Buffer.from(rawBody).toString('utf8'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return err(adapterError('malformed-payload', 'graph notification body is not valid JSON'));
|
|
17
|
+
}
|
|
18
|
+
const notification = firstNotification(parsed);
|
|
19
|
+
if (!notification) {
|
|
20
|
+
return err(adapterError('malformed-payload', 'graph notification: empty value[]'));
|
|
21
|
+
}
|
|
22
|
+
return verifyClientState(notification, secret);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
const microsoftGraphEventMapper = {
|
|
26
|
+
map({ rawEvent }) {
|
|
27
|
+
const notification = firstNotification(rawEvent);
|
|
28
|
+
if (!notification) {
|
|
29
|
+
return err(adapterError('malformed-payload', 'graph notification: empty or invalid value[]'));
|
|
30
|
+
}
|
|
31
|
+
const embedded = embeddedMessage(notification);
|
|
32
|
+
if (!embedded) {
|
|
33
|
+
return err(adapterError('unsupported-event', 'graph plain notification carries no embedded message resource; fetch path handles it out-of-band'));
|
|
34
|
+
}
|
|
35
|
+
return buildMailEnvelope(embedded, { event: MAIL_EVENT.MESSAGE_RECEIVED });
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
const microsoftGraphIdempotencyKeyExtractor = ({ rawBody }) => {
|
|
39
|
+
const notification = firstNotification(rawBody);
|
|
40
|
+
const deliveryId = notification?.resourceData?.id ??
|
|
41
|
+
embeddedMessage(notification)?.id ??
|
|
42
|
+
notification?.subscriptionId;
|
|
43
|
+
if (!deliveryId) {
|
|
44
|
+
throw new Error('graph notification: cannot derive a deterministic idempotency key (no resourceData.id, embedded message id, or subscriptionId)');
|
|
45
|
+
}
|
|
46
|
+
return `MICROSOFT_GRAPH:${deliveryId}`;
|
|
47
|
+
};
|
|
48
|
+
const microsoftGraphOrgResolver = {
|
|
49
|
+
async resolve({ rawBody, lookup }) {
|
|
50
|
+
const notification = firstNotification(rawBody);
|
|
51
|
+
const subscriptionId = notification?.subscriptionId;
|
|
52
|
+
if (typeof subscriptionId !== 'string' || subscriptionId.length === 0) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return lookup.byExternalInstallationId(PROVIDER_SLUG, subscriptionId);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
const microsoftGraphOnboarding = {
|
|
59
|
+
provider: PROVIDER_SLUG,
|
|
60
|
+
displayName: 'Microsoft 365 (Outlook Mail)',
|
|
61
|
+
description: 'Microsoft 365 / Outlook mailbox intake. Subscribes to Graph change notifications and ingests inbound mail into MailOps.',
|
|
62
|
+
iconName: 'Mail',
|
|
63
|
+
kind: ConnectorOnboardingKind.CREDENTIALS,
|
|
64
|
+
supportedProjectBindingAdapterKinds: [],
|
|
65
|
+
fields: [
|
|
66
|
+
{
|
|
67
|
+
key: 'mailboxUserId',
|
|
68
|
+
label: 'Mailbox User ID or UPN',
|
|
69
|
+
type: CredentialFieldType.TEXT,
|
|
70
|
+
required: true,
|
|
71
|
+
isSecret: false,
|
|
72
|
+
placeholder: 'intake@contoso.onmicrosoft.com',
|
|
73
|
+
transform: CredentialFieldTransform.TRIM,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
hint: 'Sign in with Microsoft and grant Graph Mail.Read access, then supply the mailbox to monitor. The Azure AD app registration itself (tenant, client id, client secret) is provisioned once by an admin under Provider credentials — you are not asked for it here.',
|
|
77
|
+
};
|
|
78
|
+
export const microsoftGraphProvider = defineConnectorAdapter({
|
|
79
|
+
adapterKind: 'mail',
|
|
80
|
+
provider: PROVIDER_SLUG,
|
|
81
|
+
displayName: 'Microsoft 365 (Outlook Mail)',
|
|
82
|
+
webhook: {
|
|
83
|
+
verifier: microsoftGraphVerifier,
|
|
84
|
+
eventMapper: microsoftGraphEventMapper,
|
|
85
|
+
orgResolver: microsoftGraphOrgResolver,
|
|
86
|
+
idempotencyKeyExtractor: microsoftGraphIdempotencyKeyExtractor,
|
|
87
|
+
},
|
|
88
|
+
credentialKind: CredentialKind.OAuthUser,
|
|
89
|
+
oauthConfig: {
|
|
90
|
+
clientIdEnvVar: 'MS365_OAUTH_CLIENT_ID',
|
|
91
|
+
clientSecretEnvVar: 'MS365_OAUTH_CLIENT_SECRET',
|
|
92
|
+
...MICROSOFT_OAUTH_ENDPOINTS,
|
|
93
|
+
scopes: [
|
|
94
|
+
'offline_access',
|
|
95
|
+
'https://graph.microsoft.com/Mail.Read',
|
|
96
|
+
'https://graph.microsoft.com/User.Read',
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
resources: {},
|
|
100
|
+
actions: {},
|
|
101
|
+
onboarding: microsoftGraphOnboarding,
|
|
102
|
+
});
|
|
103
|
+
const connectorAdapters = [microsoftGraphProvider];
|
|
104
|
+
export default connectorAdapters;
|
|
105
|
+
const MICROSOFT_PROVIDER_KEY = 'microsoft';
|
|
106
|
+
export const providerDescriptor = {
|
|
107
|
+
providerKey: MICROSOFT_PROVIDER_KEY,
|
|
108
|
+
displayName: 'Microsoft 365',
|
|
109
|
+
description: 'Microsoft 365 / Outlook via OAuth. One Azure AD (Entra ID) app registration backs every Microsoft connector (Outlook mail today) with incremental Graph scopes.',
|
|
110
|
+
iconName: 'Mail',
|
|
111
|
+
category: 'Email',
|
|
112
|
+
appAuthKind: ProviderAppAuthKind.OAuth2,
|
|
113
|
+
origin: ProviderOrigin.Biome,
|
|
114
|
+
allowOrgOverride: true,
|
|
115
|
+
appCredentialSchema: [
|
|
116
|
+
{
|
|
117
|
+
key: 'clientId',
|
|
118
|
+
label: 'Application (client) ID',
|
|
119
|
+
type: CredentialFieldType.TEXT,
|
|
120
|
+
required: true,
|
|
121
|
+
isSecret: false,
|
|
122
|
+
transform: CredentialFieldTransform.TRIM,
|
|
123
|
+
placeholder: '11111111-1111-1111-1111-111111111111',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
key: 'clientSecret',
|
|
127
|
+
label: 'Client secret',
|
|
128
|
+
type: CredentialFieldType.PASSWORD,
|
|
129
|
+
required: true,
|
|
130
|
+
isSecret: true,
|
|
131
|
+
transform: CredentialFieldTransform.TRIM,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: 'tenantId',
|
|
135
|
+
label: 'Azure AD tenant id (optional)',
|
|
136
|
+
type: CredentialFieldType.TEXT,
|
|
137
|
+
required: false,
|
|
138
|
+
isSecret: false,
|
|
139
|
+
transform: CredentialFieldTransform.TRIM,
|
|
140
|
+
placeholder: 'common',
|
|
141
|
+
hint: 'Leave blank / use "common" for a multi-tenant app registration.',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
oauthEndpoints: {
|
|
145
|
+
...MICROSOFT_OAUTH_ENDPOINTS,
|
|
146
|
+
extraAuthorizeParams: {
|
|
147
|
+
response_mode: 'query',
|
|
148
|
+
prompt: 'consent',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
export const connectorDescriptors = [
|
|
153
|
+
{
|
|
154
|
+
connectorKey: 'MICROSOFT_GRAPH',
|
|
155
|
+
displayName: 'Microsoft 365 (Outlook Mail)',
|
|
156
|
+
description: 'Read Outlook mail via Microsoft Graph OAuth.',
|
|
157
|
+
iconName: 'Mail',
|
|
158
|
+
providerKey: MICROSOFT_PROVIDER_KEY,
|
|
159
|
+
scopes: [
|
|
160
|
+
'offline_access',
|
|
161
|
+
'https://graph.microsoft.com/Mail.Read',
|
|
162
|
+
'https://graph.microsoft.com/User.Read',
|
|
163
|
+
],
|
|
164
|
+
connectionCredentialKind: CredentialKind.OAuthUser,
|
|
165
|
+
adapterKind: 'mail',
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
function firstNotification(raw) {
|
|
169
|
+
if (!raw || typeof raw !== 'object') {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const value = raw.value;
|
|
173
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
const first = value[0];
|
|
177
|
+
if (!first || typeof first !== 'object') {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
return first;
|
|
181
|
+
}
|
|
182
|
+
function embeddedMessage(notification) {
|
|
183
|
+
if (!notification) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const data = notification.resourceData;
|
|
187
|
+
if (!data || typeof data !== 'object') {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
const candidate = data;
|
|
191
|
+
const hasMessageShape = typeof candidate['id'] === 'string' &&
|
|
192
|
+
('from' in candidate ||
|
|
193
|
+
'toRecipients' in candidate ||
|
|
194
|
+
'subject' in candidate ||
|
|
195
|
+
'body' in candidate ||
|
|
196
|
+
'receivedDateTime' in candidate);
|
|
197
|
+
return hasMessageShape ? candidate : null;
|
|
198
|
+
}
|
|
199
|
+
export { parseMessageResourcePath, drainMessageDelta, establishInboxSubscription, renewIfDue, resolveValidationHandshake, getMailboxAddress, } from '../graph/subscription-lifecycle.js';
|
|
200
|
+
export { GraphClient } from '../graph/graph-client.js';
|
|
201
|
+
export { buildMailEnvelope } from '../graph/mail-envelope.js';
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connector-adapters/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,GAAG,GAMJ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,cAAc,EACd,uBAAuB,EACvB,yBAAyB,EACzB,mBAAmB,EACnB,cAAc,GAIf,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,2BAA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,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAQD,SAAS,eAAe,CACtB,YAA4C;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,GAAG,YAAY,CAAC,YAAuB,CAAC;IAClD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,SAAS,GAAG,IAA+B,CAAC;IAIlD,MAAM,eAAe,GACnB,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,QAAQ;QACnC,CAAC,MAAM,IAAI,SAAS;YAClB,cAAc,IAAI,SAAS;YAC3B,SAAS,IAAI,SAAS;YACtB,MAAM,IAAI,SAAS;YACnB,kBAAkB,IAAI,SAAS,CAAC,CAAC;IACrC,OAAO,eAAe,CAAC,CAAC,CAAE,SAA6C,CAAC,CAAC,CAAC,IAAI,CAAC;AACjF,CAAC;AAMD,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,0BAA0B,EAC1B,UAAU,EACV,0BAA0B,EAC1B,iBAAiB,GAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type Result } from '@xemahq/biome-sdk/adapter';
|
|
2
|
+
import { GraphChangeType } from './graph-types.js';
|
|
3
|
+
import type { GraphMessageDeltaPage, GraphMessageResource, GraphSubscription, GraphUser } from './graph-types.js';
|
|
4
|
+
export declare const MAX_SUBSCRIPTION_LIFETIME_MS: number;
|
|
5
|
+
export declare const SUBSCRIPTION_RENEWAL_SKEW_MS: number;
|
|
6
|
+
export interface GraphClientConfig {
|
|
7
|
+
readonly accessToken: string;
|
|
8
|
+
readonly baseUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface CreateSubscriptionInput {
|
|
11
|
+
readonly resource: string;
|
|
12
|
+
readonly notificationUrl: string;
|
|
13
|
+
readonly clientState: string;
|
|
14
|
+
readonly changeType?: GraphChangeType;
|
|
15
|
+
}
|
|
16
|
+
export declare class GraphClient {
|
|
17
|
+
private readonly baseUrl;
|
|
18
|
+
private readonly accessToken;
|
|
19
|
+
constructor(config: GraphClientConfig);
|
|
20
|
+
getMessage(userId: string, messageId: string): Promise<Result<GraphMessageResource>>;
|
|
21
|
+
getMe(): Promise<Result<GraphUser>>;
|
|
22
|
+
createSubscription(input: CreateSubscriptionInput): Promise<Result<GraphSubscription>>;
|
|
23
|
+
renewSubscription(subscriptionId: string): Promise<Result<GraphSubscription>>;
|
|
24
|
+
deleteSubscription(subscriptionId: string): Promise<Result<void>>;
|
|
25
|
+
getMessageDelta(userId: string, deltaOrNextLink?: string): Promise<Result<GraphMessageDeltaPage>>;
|
|
26
|
+
private requestJson;
|
|
27
|
+
private requestAbsoluteJson;
|
|
28
|
+
private fetchWithTimeout;
|
|
29
|
+
private fetchAbsolute;
|
|
30
|
+
private toAdapterError;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=graph-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-client.d.ts","sourceRoot":"","sources":["../../src/graph/graph-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK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AmB;IAqBjC,OAAO,CAAC,gBAAgB;YAQV,aAAa;YAwBb,cAAc;CAoB7B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { adapterError, err, ok } from '@xemahq/biome-sdk/adapter';
|
|
2
|
+
import { GraphChangeType } from './graph-types.js';
|
|
3
|
+
const GRAPH_BASE_URL = 'https://graph.microsoft.com/v1.0';
|
|
4
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
5
|
+
export const MAX_SUBSCRIPTION_LIFETIME_MS = 4_230 * 60 * 1000;
|
|
6
|
+
export const SUBSCRIPTION_RENEWAL_SKEW_MS = 6 * 60 * 60 * 1000;
|
|
7
|
+
export class GraphClient {
|
|
8
|
+
baseUrl;
|
|
9
|
+
accessToken;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
if (!config.accessToken) {
|
|
12
|
+
throw new Error('GraphClient requires a non-empty accessToken');
|
|
13
|
+
}
|
|
14
|
+
this.accessToken = config.accessToken;
|
|
15
|
+
this.baseUrl = (config.baseUrl ?? GRAPH_BASE_URL).replace(/\/+$/, '');
|
|
16
|
+
}
|
|
17
|
+
async getMessage(userId, messageId) {
|
|
18
|
+
if (!userId || !messageId) {
|
|
19
|
+
return err(adapterError('malformed-payload', 'getMessage requires userId and messageId'));
|
|
20
|
+
}
|
|
21
|
+
const select = '$select=id,conversationId,internetMessageId,subject,receivedDateTime,sentDateTime,from,sender,toRecipients,ccRecipients,bccRecipients,body,bodyPreview,categories,hasAttachments,internetMessageHeaders';
|
|
22
|
+
const expand = '$expand=attachments';
|
|
23
|
+
const path = `users/${encodeURIComponent(userId)}/messages/${encodeURIComponent(messageId)}?${select}&${expand}`;
|
|
24
|
+
return this.requestJson('GET', path);
|
|
25
|
+
}
|
|
26
|
+
async getMe() {
|
|
27
|
+
return this.requestJson('GET', 'me?$select=mail,userPrincipalName');
|
|
28
|
+
}
|
|
29
|
+
async createSubscription(input) {
|
|
30
|
+
const expirationDateTime = new Date(Date.now() + MAX_SUBSCRIPTION_LIFETIME_MS).toISOString();
|
|
31
|
+
const body = {
|
|
32
|
+
changeType: input.changeType ?? GraphChangeType.CREATED,
|
|
33
|
+
notificationUrl: input.notificationUrl,
|
|
34
|
+
resource: input.resource,
|
|
35
|
+
expirationDateTime,
|
|
36
|
+
clientState: input.clientState,
|
|
37
|
+
};
|
|
38
|
+
return this.requestJson('POST', 'subscriptions', body);
|
|
39
|
+
}
|
|
40
|
+
async renewSubscription(subscriptionId) {
|
|
41
|
+
if (!subscriptionId) {
|
|
42
|
+
return err(adapterError('malformed-payload', 'renewSubscription requires subscriptionId'));
|
|
43
|
+
}
|
|
44
|
+
const expirationDateTime = new Date(Date.now() + MAX_SUBSCRIPTION_LIFETIME_MS).toISOString();
|
|
45
|
+
return this.requestJson('PATCH', `subscriptions/${encodeURIComponent(subscriptionId)}`, { expirationDateTime });
|
|
46
|
+
}
|
|
47
|
+
async deleteSubscription(subscriptionId) {
|
|
48
|
+
if (!subscriptionId) {
|
|
49
|
+
return err(adapterError('malformed-payload', 'deleteSubscription requires subscriptionId'));
|
|
50
|
+
}
|
|
51
|
+
const response = await this.fetchWithTimeout('DELETE', `subscriptions/${encodeURIComponent(subscriptionId)}`);
|
|
52
|
+
if (!response) {
|
|
53
|
+
return err(adapterError('upstream-unavailable', 'graph subscription delete: network error'));
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok && response.status !== 404) {
|
|
56
|
+
return err(await this.toAdapterError(response, 'subscription delete'));
|
|
57
|
+
}
|
|
58
|
+
return ok(undefined);
|
|
59
|
+
}
|
|
60
|
+
async getMessageDelta(userId, deltaOrNextLink) {
|
|
61
|
+
if (!userId) {
|
|
62
|
+
return err(adapterError('malformed-payload', 'getMessageDelta requires userId'));
|
|
63
|
+
}
|
|
64
|
+
if (deltaOrNextLink) {
|
|
65
|
+
return this.requestAbsoluteJson('GET', deltaOrNextLink);
|
|
66
|
+
}
|
|
67
|
+
const path = `users/${encodeURIComponent(userId)}/mailFolders('inbox')/messages/delta`;
|
|
68
|
+
return this.requestJson('GET', path);
|
|
69
|
+
}
|
|
70
|
+
async requestJson(method, path, body) {
|
|
71
|
+
return this.requestAbsoluteJson(method, `${this.baseUrl}/${path}`, body);
|
|
72
|
+
}
|
|
73
|
+
async requestAbsoluteJson(method, url, body) {
|
|
74
|
+
const response = await this.fetchAbsolute(method, url, body);
|
|
75
|
+
if (!response) {
|
|
76
|
+
return err(adapterError('upstream-unavailable', `graph ${method} ${url}: network error / timeout`));
|
|
77
|
+
}
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
return err(await this.toAdapterError(response, `${method} ${url}`));
|
|
80
|
+
}
|
|
81
|
+
const json = (await response.json().catch(() => null));
|
|
82
|
+
if (json === null) {
|
|
83
|
+
return err(adapterError('upstream-unavailable', `graph ${method} ${url}: empty/invalid JSON`));
|
|
84
|
+
}
|
|
85
|
+
return ok(json);
|
|
86
|
+
}
|
|
87
|
+
fetchWithTimeout(method, path, body) {
|
|
88
|
+
return this.fetchAbsolute(method, `${this.baseUrl}/${path}`, body);
|
|
89
|
+
}
|
|
90
|
+
async fetchAbsolute(method, url, body) {
|
|
91
|
+
const headers = {
|
|
92
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
93
|
+
Accept: 'application/json',
|
|
94
|
+
};
|
|
95
|
+
if (body !== undefined) {
|
|
96
|
+
headers['Content-Type'] = 'application/json';
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return await fetch(url, {
|
|
100
|
+
method,
|
|
101
|
+
headers,
|
|
102
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
103
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async toAdapterError(response, context) {
|
|
111
|
+
const text = await response.text().catch(() => '');
|
|
112
|
+
const snippet = text.slice(0, 300);
|
|
113
|
+
if (response.status === 401 || response.status === 403) {
|
|
114
|
+
return adapterError('unauthorized', `graph ${context}: HTTP ${response.status} — ${snippet}`);
|
|
115
|
+
}
|
|
116
|
+
if (response.status === 404) {
|
|
117
|
+
return adapterError('not-found', `graph ${context}: HTTP 404 — ${snippet}`);
|
|
118
|
+
}
|
|
119
|
+
if (response.status === 429) {
|
|
120
|
+
const retryAfter = Number(response.headers.get('retry-after') ?? '');
|
|
121
|
+
return adapterError('rate-limited', `graph ${context}: HTTP 429`, {
|
|
122
|
+
...(Number.isFinite(retryAfter) ? { retryAfterSec: retryAfter } : {}),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return adapterError('upstream-unavailable', `graph ${context}: HTTP ${response.status} — ${snippet}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=graph-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-client.js","sourceRoot":"","sources":["../../src/graph/graph-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AA2BnD,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAC1D,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAOlC,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,GAAG,EAAE,GAAG,IAAI,CAAC;AAC9D,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAyB/D,MAAM,OAAO,WAAW;IACL,OAAO,CAAS;IAChB,WAAW,CAAS;IAErC,YAAY,MAAyB;QACnC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC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