@3sixty/mailbox-connector-gmail 0.0.0-stage → 0.20.0-next.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.
Files changed (38) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +76 -2
  3. package/dist/es/connectorSchema/gmailEmailConnectorConfigSchema.js +51 -0
  4. package/dist/es/connectorSchema/gmailEmailConnectorConfigSchema.js.map +1 -0
  5. package/dist/es/connectorSchema/gmailEmailConnectorStateSchema.js +45 -0
  6. package/dist/es/connectorSchema/gmailEmailConnectorStateSchema.js.map +1 -0
  7. package/dist/es/gmailEmailConnector.js +773 -0
  8. package/dist/es/gmailEmailConnector.js.map +1 -0
  9. package/dist/es/index.js +10 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/models/IGmailEmailConnectorConfig.js +4 -0
  12. package/dist/es/models/IGmailEmailConnectorConfig.js.map +1 -0
  13. package/dist/es/models/IGmailEmailConnectorConstructorOptions.js +2 -0
  14. package/dist/es/models/IGmailEmailConnectorConstructorOptions.js.map +1 -0
  15. package/dist/es/models/IGmailEmailConnectorState.js +4 -0
  16. package/dist/es/models/IGmailEmailConnectorState.js.map +1 -0
  17. package/dist/es/schema.js +17 -0
  18. package/dist/es/schema.js.map +1 -0
  19. package/dist/types/connectorSchema/gmailEmailConnectorConfigSchema.d.ts +5 -0
  20. package/dist/types/connectorSchema/gmailEmailConnectorStateSchema.d.ts +7 -0
  21. package/dist/types/gmailEmailConnector.d.ts +64 -0
  22. package/dist/types/index.d.ts +7 -0
  23. package/dist/types/models/IGmailEmailConnectorConfig.d.ts +56 -0
  24. package/dist/types/models/IGmailEmailConnectorConstructorOptions.d.ts +19 -0
  25. package/dist/types/models/IGmailEmailConnectorState.d.ts +39 -0
  26. package/dist/types/schema.d.ts +7 -0
  27. package/docs/changelog.md +0 -0
  28. package/docs/examples.md +174 -0
  29. package/docs/reference/classes/GmailEmailConnector.md +218 -0
  30. package/docs/reference/functions/initSchema.md +12 -0
  31. package/docs/reference/index.md +20 -0
  32. package/docs/reference/interfaces/IGmailEmailConnectorConfig.md +110 -0
  33. package/docs/reference/interfaces/IGmailEmailConnectorConstructorOptions.md +33 -0
  34. package/docs/reference/interfaces/IGmailEmailConnectorState.md +63 -0
  35. package/docs/reference/variables/GmailEmailConnectorConfigSchema.md +5 -0
  36. package/docs/reference/variables/GmailEmailConnectorStateSchema.md +7 -0
  37. package/locales/en.json +41 -0
  38. package/package.json +57 -5
@@ -0,0 +1,218 @@
1
+ # Class: GmailEmailConnector
2
+
3
+ Gmail email protocol connector. Monitors a mailbox for new messages using the Gmail API.
4
+
5
+ ## Implements
6
+
7
+ - `IEmailProtocolConnector`\<[`IGmailEmailConnectorState`](../interfaces/IGmailEmailConnectorState.md)\>
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new GmailEmailConnector**(`options`): `GmailEmailConnector`
14
+
15
+ Create a new instance of GmailEmailConnector.
16
+
17
+ #### Parameters
18
+
19
+ ##### options
20
+
21
+ [`IGmailEmailConnectorConstructorOptions`](../interfaces/IGmailEmailConnectorConstructorOptions.md)
22
+
23
+ The options for the connector.
24
+
25
+ #### Returns
26
+
27
+ `GmailEmailConnector`
28
+
29
+ #### Throws
30
+
31
+ GeneralError if neither a service account key nor an OAuth client is supplied.
32
+
33
+ ## Properties
34
+
35
+ ### CLASS\_NAME {#class_name}
36
+
37
+ > `readonly` `static` **CLASS\_NAME**: `string`
38
+
39
+ The class name.
40
+
41
+ ***
42
+
43
+ ### NAMESPACE {#namespace}
44
+
45
+ > `readonly` `static` **NAMESPACE**: `string` = `"gmail"`
46
+
47
+ The protocol namespace identifier.
48
+
49
+ ## Methods
50
+
51
+ ### className() {#classname}
52
+
53
+ > **className**(): `string`
54
+
55
+ Get the class name.
56
+
57
+ #### Returns
58
+
59
+ `string`
60
+
61
+ The class name.
62
+
63
+ #### Implementation of
64
+
65
+ `IEmailProtocolConnector.className`
66
+
67
+ ***
68
+
69
+ ### retrieve() {#retrieve}
70
+
71
+ > **retrieve**(`instanceId`, `state`, `authCallback`, `retrievalCallback`, `options`): `Promise`\<`void`\>
72
+
73
+ Start the internal polling loop for the given instance.
74
+
75
+ #### Parameters
76
+
77
+ ##### instanceId
78
+
79
+ `string`
80
+
81
+ The identifier of the mailbox instance being polled.
82
+
83
+ ##### state
84
+
85
+ [`IGmailEmailConnectorState`](../interfaces/IGmailEmailConnectorState.md)
86
+
87
+ The current connector state for the instance.
88
+
89
+ ##### authCallback
90
+
91
+ `IEmailProtocolConnectorAuthCallback`
92
+
93
+ Callback invoked when authentication fails during a poll cycle.
94
+
95
+ ##### retrievalCallback
96
+
97
+ `IEmailProtocolConnectorRetrievalCallback`
98
+
99
+ Callback invoked with retrieved messages after each poll cycle.
100
+
101
+ ##### options
102
+
103
+ `IEmailProtocolConnectorOptions`
104
+
105
+ Options supplied by the owning component, carrying the consent callback URI.
106
+
107
+ #### Returns
108
+
109
+ `Promise`\<`void`\>
110
+
111
+ A promise that resolves when the polling loop has been started.
112
+
113
+ #### Implementation of
114
+
115
+ `IEmailProtocolConnector.retrieve`
116
+
117
+ ***
118
+
119
+ ### initiateAuth() {#initiateauth}
120
+
121
+ > **initiateAuth**(`instanceId`, `state`, `options`): `Promise`\<`IEmailProtocolConnectorAuthState` \| `undefined`\>
122
+
123
+ Start the consent flow for a mailbox which has no refresh token yet.
124
+
125
+ #### Parameters
126
+
127
+ ##### instanceId
128
+
129
+ `string`
130
+
131
+ The identifier of the mailbox instance being authenticated.
132
+
133
+ ##### state
134
+
135
+ [`IGmailEmailConnectorState`](../interfaces/IGmailEmailConnectorState.md)
136
+
137
+ The current connector state for the instance.
138
+
139
+ ##### options
140
+
141
+ `IEmailProtocolConnectorOptions`
142
+
143
+ Options supplied by the owning component, carrying the consent callback URI
144
+ and the state which correlates the consent response back to the mailbox.
145
+
146
+ #### Returns
147
+
148
+ `Promise`\<`IEmailProtocolConnectorAuthState` \| `undefined`\>
149
+
150
+ The auth state carrying the consent URL to open, or undefined when the mailbox can
151
+ already authenticate itself from a service account key or a refresh token in its state.
152
+
153
+ #### Implementation of
154
+
155
+ `IEmailProtocolConnector.initiateAuth`
156
+
157
+ ***
158
+
159
+ ### completeAuth() {#completeauth}
160
+
161
+ > **completeAuth**(`instanceId`, `authPayload`, `options`): `Promise`\<`void`\>
162
+
163
+ Complete the consent flow with the authorisation code handed to the redirect URI.
164
+ The issued credentials are applied to this connector instance so the next poll uses them,
165
+ and the refresh token is placed in the state reported through the auth callback given by
166
+ retrieve, so the owning component vaults it and lifts the authentication halt.
167
+
168
+ #### Parameters
169
+
170
+ ##### instanceId
171
+
172
+ `string`
173
+
174
+ The identifier of the mailbox instance being authenticated.
175
+
176
+ ##### authPayload
177
+
178
+ `unknown`
179
+
180
+ The redirect query, carrying the authorisation code as its code property.
181
+
182
+ ##### options
183
+
184
+ `IEmailProtocolConnectorOptions`
185
+
186
+ Options supplied by the owning component, carrying the consent callback URI.
187
+
188
+ #### Returns
189
+
190
+ `Promise`\<`void`\>
191
+
192
+ A promise that resolves when the flow has been completed.
193
+
194
+ #### Throws
195
+
196
+ GeneralError if the authorisation code could not be exchanged for tokens.
197
+
198
+ #### Implementation of
199
+
200
+ `IEmailProtocolConnector.completeAuth`
201
+
202
+ ***
203
+
204
+ ### retrieveStop() {#retrievestop}
205
+
206
+ > **retrieveStop**(): `Promise`\<`void`\>
207
+
208
+ Stop the polling loop for this connector.
209
+
210
+ #### Returns
211
+
212
+ `Promise`\<`void`\>
213
+
214
+ A promise that resolves when the polling loop has been stopped.
215
+
216
+ #### Implementation of
217
+
218
+ `IEmailProtocolConnector.retrieveStop`
@@ -0,0 +1,12 @@
1
+ # Function: initSchema()
2
+
3
+ > **initSchema**(): `void`
4
+
5
+ Initialise the connector schemas for the Gmail connector.
6
+ The connector constructor calls this as well, so registering here is only needed to make the
7
+ schemas available before any connector instance has been built, such as for a mailbox which
8
+ is stored but not currently polled.
9
+
10
+ ## Returns
11
+
12
+ `void`
@@ -0,0 +1,20 @@
1
+ # @3sixty/mailbox-connector-gmail
2
+
3
+ ## Classes
4
+
5
+ - [GmailEmailConnector](classes/GmailEmailConnector.md)
6
+
7
+ ## Interfaces
8
+
9
+ - [IGmailEmailConnectorConfig](interfaces/IGmailEmailConnectorConfig.md)
10
+ - [IGmailEmailConnectorConstructorOptions](interfaces/IGmailEmailConnectorConstructorOptions.md)
11
+ - [IGmailEmailConnectorState](interfaces/IGmailEmailConnectorState.md)
12
+
13
+ ## Variables
14
+
15
+ - [GmailEmailConnectorConfigSchema](variables/GmailEmailConnectorConfigSchema.md)
16
+ - [GmailEmailConnectorStateSchema](variables/GmailEmailConnectorStateSchema.md)
17
+
18
+ ## Functions
19
+
20
+ - [initSchema](functions/initSchema.md)
@@ -0,0 +1,110 @@
1
+ # Interface: IGmailEmailConnectorConfig
2
+
3
+ Configuration for the Gmail email connector.
4
+
5
+ ## Properties
6
+
7
+ ### emailAddress {#emailaddress}
8
+
9
+ > **emailAddress**: `string`
10
+
11
+ The address of the mailbox to monitor, for example "user@example.com".
12
+ Used as the Gmail API user identifier, and as the impersonated subject
13
+ when a service account key is supplied.
14
+
15
+ ***
16
+
17
+ ### clientId? {#clientid}
18
+
19
+ > `optional` **clientId?**: `string`
20
+
21
+ The OAuth 2.0 client identifier from the Google Cloud project.
22
+ Required unless serviceAccountKey is supplied.
23
+
24
+ ***
25
+
26
+ ### clientSecret? {#clientsecret}
27
+
28
+ > `optional` **clientSecret?**: `string`
29
+
30
+ The OAuth 2.0 client secret from the Google Cloud project. Stored securely in the vault.
31
+ Required unless serviceAccountKey is supplied.
32
+
33
+ ***
34
+
35
+ ### serviceAccountKey? {#serviceaccountkey}
36
+
37
+ > `optional` **serviceAccountKey?**: `string`
38
+
39
+ The JSON service account key used for domain-wide delegation, as a string.
40
+ Stored securely in the vault. When supplied this takes precedence over the
41
+ authorisation code credentials and the mailbox is accessed by impersonating emailAddress.
42
+
43
+ ***
44
+
45
+ ### labelIds? {#labelids}
46
+
47
+ > `optional` **labelIds?**: `string`[]
48
+
49
+ The identifiers of the labels to monitor for new messages.
50
+ A message carrying any of them is delivered, so the mailbox sync walks one label at a time
51
+ because the Gmail message list requires a message to carry every label it is given.
52
+
53
+ #### Default
54
+
55
+ ```ts
56
+ ["INBOX"]
57
+ ```
58
+
59
+ ***
60
+
61
+ ### maxMessagesPerPoll? {#maxmessagesperpoll}
62
+
63
+ > `optional` **maxMessagesPerPoll?**: `number`
64
+
65
+ The maximum number of messages to retrieve during a single poll of the initial sync.
66
+ Later polls continue from where the previous one finished.
67
+
68
+ #### Default
69
+
70
+ ```ts
71
+ 50
72
+ ```
73
+
74
+ ***
75
+
76
+ ### maxDeliveredIdHistory? {#maxdeliveredidhistory}
77
+
78
+ > `optional` **maxDeliveredIdHistory?**: `number`
79
+
80
+ The number of delivered message identifiers retained in the connector state.
81
+ These guard against a message being delivered twice when a poll cycle is replayed.
82
+
83
+ #### Default
84
+
85
+ ```ts
86
+ 200
87
+ ```
88
+
89
+ ***
90
+
91
+ ### pollingIntervalMinutes? {#pollingintervalminutes}
92
+
93
+ > `optional` **pollingIntervalMinutes?**: `number`
94
+
95
+ How often to poll for new messages, in minutes.
96
+
97
+ #### Default
98
+
99
+ ```ts
100
+ 2
101
+ ```
102
+
103
+ ***
104
+
105
+ ### mutexTimeoutMs? {#mutextimeoutms}
106
+
107
+ > `optional` **mutexTimeoutMs?**: `number`
108
+
109
+ Maximum time in milliseconds to wait for the poll mutex before skipping the tick.
110
+ When not set, the mutex waits based on the system default.
@@ -0,0 +1,33 @@
1
+ # Interface: IGmailEmailConnectorConstructorOptions
2
+
3
+ Constructor options for the Gmail email connector.
4
+
5
+ ## Properties
6
+
7
+ ### taskSchedulerComponentType? {#taskschedulercomponenttype}
8
+
9
+ > `optional` **taskSchedulerComponentType?**: `string`
10
+
11
+ The component type for the task scheduler used to manage polling intervals.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ "task-scheduler"
17
+ ```
18
+
19
+ ***
20
+
21
+ ### loggingComponentType? {#loggingcomponenttype}
22
+
23
+ > `optional` **loggingComponentType?**: `string`
24
+
25
+ The component type for logging.
26
+
27
+ ***
28
+
29
+ ### config {#config}
30
+
31
+ > **config**: [`IGmailEmailConnectorConfig`](IGmailEmailConnectorConfig.md)
32
+
33
+ The configuration for the Gmail connector.
@@ -0,0 +1,63 @@
1
+ # Interface: IGmailEmailConnectorState
2
+
3
+ Runtime state persisted between poll cycles for a Gmail connector.
4
+
5
+ ## Properties
6
+
7
+ ### refreshToken? {#refreshtoken}
8
+
9
+ > `optional` **refreshToken?**: `string`
10
+
11
+ The OAuth 2.0 refresh token the consent flow issued for the mailbox, declared secure in the
12
+ connector state schema so the owning component vaults it rather than persisting it here.
13
+ Unset until consent has been given, while the connector supplies a consent URL instead of
14
+ polling, and never set for a mailbox authenticated by a service account key.
15
+
16
+ ***
17
+
18
+ ### historyId? {#historyid}
19
+
20
+ > `optional` **historyId?**: `string`
21
+
22
+ The mailbox history identifier processing has reached.
23
+ Later polls ask the Gmail history API for the changes which follow it.
24
+
25
+ ***
26
+
27
+ ### syncPageTokens? {#syncpagetokens}
28
+
29
+ > `optional` **syncPageTokens?**: `object`
30
+
31
+ The page tokens for the next page of the initial mailbox sync, keyed by label identifier.
32
+ Only set while initialSyncComplete is false and more pages remain for that label.
33
+
34
+ #### Index Signature
35
+
36
+ \[`labelId`: `string`\]: `string`
37
+
38
+ ***
39
+
40
+ ### syncCompletedLabelIds? {#synccompletedlabelids}
41
+
42
+ > `optional` **syncCompletedLabelIds?**: `string`[]
43
+
44
+ The labels whose existing messages have all been walked during the initial sync.
45
+
46
+ ***
47
+
48
+ ### initialSyncComplete? {#initialsynccomplete}
49
+
50
+ > `optional` **initialSyncComplete?**: `boolean`
51
+
52
+ Whether the initial sync of the existing mailbox contents has finished.
53
+ Until it has, polling walks the message list rather than the history API.
54
+
55
+ ***
56
+
57
+ ### deliveredMessageIds? {#deliveredmessageids}
58
+
59
+ > `optional` **deliveredMessageIds?**: `string`[]
60
+
61
+ The identifiers of the most recently delivered messages, oldest first.
62
+ Gmail message identifiers are permanent, so this prevents a message being
63
+ delivered twice when a poll cycle is replayed after a persistence failure.
@@ -0,0 +1,5 @@
1
+ # Variable: GmailEmailConnectorConfigSchema
2
+
3
+ > `const` **GmailEmailConnectorConfigSchema**: `IMailboxConfigField`[]
4
+
5
+ The configuration field schema for Gmail connectors.
@@ -0,0 +1,7 @@
1
+ # Variable: GmailEmailConnectorStateSchema
2
+
3
+ > `const` **GmailEmailConnectorStateSchema**: `IMailboxConfigField`[]
4
+
5
+ The runtime state field schema for Gmail connectors.
6
+ The refresh token is issued by the consent flow rather than configured, so it travels in the
7
+ connector state and is marked secure to keep it in the vault.
@@ -0,0 +1,41 @@
1
+ {
2
+ "error": {
3
+ "gmailEmailConnector": {
4
+ "pollFailed": "Poll failed",
5
+ "authCodeExchangeFailed": "The authorization code could not be exchanged for tokens",
6
+ "noRefreshTokenIssued": "The consent flow did not issue a refresh token",
7
+ "authFlowNotStarted": "The connector has no authentication flow in progress to complete",
8
+ "consentAccountMismatch": "The consent was given by an account other than {emailAddress}",
9
+ "missingOAuthCredentials": "The clientId and clientSecret are required when no serviceAccountKey is supplied",
10
+ "invalidServiceAccountKey": "The serviceAccountKey is not a valid service account JSON key"
11
+ }
12
+ },
13
+ "info": {
14
+ "gmailEmailConnector": {
15
+ "emailReceived": "Email received \"{subject}\""
16
+ }
17
+ },
18
+ "warn": {
19
+ "gmailEmailConnector": {
20
+ "consentRequired": "Mailbox requires OAuth consent before it can be polled",
21
+ "historyExpired": "Mailbox history expired, restarting the mailbox sync"
22
+ }
23
+ },
24
+ "gmailEmailConnectorConfigSchema": {
25
+ "emailAddress": "Email Address",
26
+ "clientId": "OAuth Client ID",
27
+ "clientSecret": "OAuth Client Secret",
28
+ "serviceAccountKey": "Service Account Key",
29
+ "labelIds": "Label IDs",
30
+ "maxMessagesPerPoll": "Maximum Messages Per Poll",
31
+ "pollingIntervalMinutes": "Polling Interval (Minutes)"
32
+ },
33
+ "gmailEmailConnectorStateSchema": {
34
+ "refreshToken": "OAuth Refresh Token",
35
+ "historyId": "Mailbox History ID",
36
+ "syncPageTokens": "Sync Page Tokens",
37
+ "syncCompletedLabelIds": "Synced Label IDs",
38
+ "initialSyncComplete": "Initial Sync Complete",
39
+ "deliveredMessageIds": "Delivered Message IDs"
40
+ }
41
+ }
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
- "name": "@3sixty/mailbox-connector-gmail",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@3sixty/mailbox-connector-gmail",
3
+ "version": "0.20.0-next.0",
4
+ "description": "Gmail connector for email mailbox ingestion.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/3sixtyglobal/messaging.git",
8
+ "directory": "packages/mailbox-connector-gmail"
9
+ },
10
+ "author": "martyn.janes@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=24.0.0"
15
+ },
16
+ "dependencies": {
17
+ "@3sixty/background-task-models": "next",
18
+ "@3sixty/core": "next",
19
+ "@3sixty/entity": "next",
20
+ "@3sixty/logging-models": "next",
21
+ "@3sixty/mailbox-models": "0.20.0-next.0",
22
+ "@3sixty/nameof": "next",
23
+ "googleapis": "181.0.0"
24
+ },
25
+ "main": "./dist/es/index.js",
26
+ "types": "./dist/types/index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/types/index.d.ts",
30
+ "import": "./dist/es/index.js",
31
+ "default": "./dist/es/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist/es",
36
+ "dist/types",
37
+ "locales",
38
+ "docs"
39
+ ],
40
+ "keywords": [
41
+ "twin",
42
+ "trade",
43
+ "iota",
44
+ "framework",
45
+ "blockchain",
46
+ "messaging",
47
+ "mailbox",
48
+ "email",
49
+ "gmail",
50
+ "google",
51
+ "oauth",
52
+ "connector"
53
+ ],
54
+ "bugs": {
55
+ "url": "git+https://github.com/3sixtyglobal/messaging/issues"
56
+ },
57
+ "homepage": "https://3sixty.global"
58
+ }