@heroku-cli/heroku-connect-plugin 0.11.5 → 0.12.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/README.md +15 -13
- package/commands/connect/db/set.js +69 -0
- package/commands/connect/diagnose.js +36 -31
- package/commands/connect/export.js +29 -24
- package/commands/connect/import.js +32 -25
- package/commands/connect/info.js +27 -23
- package/commands/connect/mapping/delete.js +35 -0
- package/commands/connect/mapping/diagnose.js +35 -0
- package/commands/connect/mapping/reload.js +33 -0
- package/commands/connect/mapping/state.js +28 -0
- package/commands/connect/mapping/write-errors.js +28 -0
- package/commands/connect/notifications/acknowledge.js +34 -0
- package/commands/connect/notifications/index.js +57 -0
- package/commands/connect/pause.js +25 -20
- package/commands/connect/recover.js +27 -21
- package/commands/connect/resume.js +25 -20
- package/commands/connect/sf/auth.js +75 -0
- package/commands/connect/state.js +32 -29
- package/commands/connect/write-errors.js +24 -23
- package/commands/connect-events/db/set.js +72 -0
- package/commands/connect-events/info.js +27 -24
- package/commands/connect-events/pause.js +24 -20
- package/commands/connect-events/recover.js +26 -21
- package/commands/connect-events/resume.js +24 -20
- package/commands/connect-events/{sf-auth.js → sf/auth.js} +33 -27
- package/commands/connect-events/state.js +24 -18
- package/commands/connect-events/stream/create.js +39 -0
- package/commands/connect-events/stream/delete.js +40 -0
- package/commands/connect-events/stream/state.js +33 -0
- package/lib/clients/connect.js +5 -4
- package/lib/clients/discovery.js +3 -2
- package/lib/connect/api.js +85 -107
- package/package.json +44 -11
- package/commands/connect/db-set.js +0 -69
- package/commands/connect/mapping-delete.js +0 -33
- package/commands/connect/mapping-diagnose.js +0 -33
- package/commands/connect/mapping-reload.js +0 -31
- package/commands/connect/mapping-state.js +0 -26
- package/commands/connect/mapping-write-errors.js +0 -34
- package/commands/connect/sf-auth.js +0 -76
- package/commands/connect-events/db-set.js +0 -68
- package/commands/connect-events/stream-create.js +0 -32
- package/commands/connect-events/stream-delete.js +0 -33
- package/commands/connect-events/stream-state.js +0 -26
- package/index.js +0 -50
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const co = require('co')
|
|
1
|
+
import * as api from '../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import cli from '@heroku/heroku-cli-util'
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
export default class ConnectEventsResume extends Command {
|
|
6
|
+
static description = 'Resume a connection'
|
|
7
|
+
|
|
8
|
+
static flags = {
|
|
9
|
+
app: flags.app({ required: true }),
|
|
10
|
+
resource: flags.string({ description: 'specific connection resource name' })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run () {
|
|
14
|
+
const { flags } = await this.parse(ConnectEventsResume)
|
|
15
|
+
const context = {
|
|
16
|
+
app: flags.app,
|
|
17
|
+
flags,
|
|
18
|
+
auth: { password: this.heroku.auth }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
await cli.action('resuming connection', (async function () {
|
|
22
|
+
const connection = await api.withConnection(context, this.heroku, api.ADDON_TYPE_EVENTS)
|
|
19
23
|
context.region = connection.region_url
|
|
20
24
|
const url = `/api/v3/kafka-connections/${connection.id}/actions/resume`
|
|
21
|
-
|
|
22
|
-
}))
|
|
23
|
-
}
|
|
25
|
+
await api.request(context, 'POST', url)
|
|
26
|
+
}.bind(this))())
|
|
27
|
+
}
|
|
24
28
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const http = require('http')
|
|
1
|
+
import * as api from '../../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import cli from '@heroku/heroku-cli-util'
|
|
4
|
+
import http from 'http'
|
|
6
5
|
|
|
7
6
|
const LOCAL_PORT = 18000
|
|
8
7
|
|
|
9
|
-
function callbackServer () {
|
|
8
|
+
export function callbackServer () {
|
|
10
9
|
return new Promise(function (resolve, reject) {
|
|
11
10
|
// Create a local server that can receive the user after authoriztion is complete
|
|
12
11
|
http.createServer(function (request, response) {
|
|
@@ -25,10 +24,10 @@ function callbackServer () {
|
|
|
25
24
|
})
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
function
|
|
27
|
+
async function authenticate (context, heroku) {
|
|
29
28
|
let redir
|
|
30
|
-
|
|
31
|
-
const connection =
|
|
29
|
+
await cli.action('fetching authorizing URL', (async function () {
|
|
30
|
+
const connection = await api.withConnection(context, heroku, api.ADDON_TYPE_EVENTS)
|
|
32
31
|
context.region = connection.region_url
|
|
33
32
|
|
|
34
33
|
const url = `/api/v3/kafka-connections/${connection.id}/authorize_url`
|
|
@@ -47,29 +46,36 @@ function * run (context, heroku) {
|
|
|
47
46
|
args.domain = context.flags.domain
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
const response =
|
|
49
|
+
const response = await api.request(context, 'POST', url, args)
|
|
51
50
|
redir = response.data.redirect
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
}))
|
|
52
|
+
await cli.open(redir)
|
|
53
|
+
})())
|
|
55
54
|
|
|
56
55
|
cli.log("\nIf your browser doesn't open, please copy the following URL to proceed:\n" + redir + '\n')
|
|
57
56
|
|
|
58
|
-
|
|
57
|
+
await cli.action('waiting for authorization', callbackServer())
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
export default class ConnectEventsSfAuth extends Command {
|
|
61
|
+
static description = 'Authorize access to Salesforce for your connection'
|
|
62
|
+
|
|
63
|
+
static flags = {
|
|
64
|
+
app: flags.app({ required: true }),
|
|
65
|
+
callback: flags.string({ char: 'c', description: 'final callback URL' }),
|
|
66
|
+
environment: flags.string({ char: 'e', description: '"production", "sandbox", or "custom" [defaults to "production"]' }),
|
|
67
|
+
domain: flags.string({ char: 'd', description: 'specify a custom login domain (if using a "custom" environment)' }),
|
|
68
|
+
resource: flags.string({ description: 'specific connection resource name' })
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async run () {
|
|
72
|
+
const { flags } = await this.parse(ConnectEventsSfAuth)
|
|
73
|
+
const context = {
|
|
74
|
+
app: flags.app,
|
|
75
|
+
flags,
|
|
76
|
+
auth: { password: this.heroku.auth }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
await authenticate(context, this.heroku)
|
|
80
|
+
}
|
|
75
81
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const co = require('co')
|
|
1
|
+
import * as api from '../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import cli from '@heroku/heroku-cli-util'
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
const connections =
|
|
5
|
+
async function run (context, heroku) {
|
|
6
|
+
const connections = await api.withUserConnections(context, context.app, context.flags, heroku, true, api.ADDON_TYPE_EVENTS)
|
|
8
7
|
|
|
9
8
|
if (context.flags.json) {
|
|
10
9
|
cli.styledJSON(connections)
|
|
@@ -19,16 +18,23 @@ function * run (context, heroku) {
|
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
export default class ConnectEventsState extends Command {
|
|
22
|
+
static description = 'return the connection(s) state'
|
|
23
|
+
|
|
24
|
+
static flags = {
|
|
25
|
+
app: flags.app({ required: true }),
|
|
26
|
+
resource: flags.string({ description: 'specific connection resource name' }),
|
|
27
|
+
json: flags.boolean({ description: 'print output as json' })
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async run () {
|
|
31
|
+
const { flags } = await this.parse(ConnectEventsState)
|
|
32
|
+
const context = {
|
|
33
|
+
app: flags.app,
|
|
34
|
+
flags,
|
|
35
|
+
auth: { password: this.heroku.auth }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await run(context, this.heroku)
|
|
39
|
+
}
|
|
34
40
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as api from '../../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import { Args } from '@oclif/core'
|
|
4
|
+
import cli from '@heroku/heroku-cli-util'
|
|
5
|
+
|
|
6
|
+
export default class ConnectEventsStreamCreate extends Command {
|
|
7
|
+
static description = 'Create a stream'
|
|
8
|
+
|
|
9
|
+
static args = {
|
|
10
|
+
stream: Args.string()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static flags = {
|
|
14
|
+
app: flags.app({ required: true }),
|
|
15
|
+
resource: flags.string({ description: 'specific connection resource name' })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async run () {
|
|
19
|
+
const { args, flags } = await this.parse(ConnectEventsStreamCreate)
|
|
20
|
+
const context = {
|
|
21
|
+
app: flags.app,
|
|
22
|
+
flags,
|
|
23
|
+
args,
|
|
24
|
+
auth: { password: this.heroku.auth }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await cli.action('creating stream', (async function () {
|
|
28
|
+
const connection = await api.withConnection(context, this.heroku, api.ADDON_TYPE_EVENTS)
|
|
29
|
+
context.region = connection.region_url
|
|
30
|
+
const response = await api.request(
|
|
31
|
+
context, 'POST', `/api/v3/kafka-connections/${connection.id}/streams`,
|
|
32
|
+
{ object_name: args.stream }
|
|
33
|
+
)
|
|
34
|
+
if (response.status !== 201) {
|
|
35
|
+
throw new Error(response.data.message || 'unknown error')
|
|
36
|
+
}
|
|
37
|
+
}.bind(this))())
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as api from '../../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import { Args } from '@oclif/core'
|
|
4
|
+
import cli from '@heroku/heroku-cli-util'
|
|
5
|
+
|
|
6
|
+
export default class ConnectEventsStreamDelete extends Command {
|
|
7
|
+
static description = 'Delete an existing stream'
|
|
8
|
+
|
|
9
|
+
static args = {
|
|
10
|
+
stream: Args.string()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static flags = {
|
|
14
|
+
app: flags.app({ required: true }),
|
|
15
|
+
resource: flags.string({ description: 'specific connection resource name' }),
|
|
16
|
+
confirm: flags.string()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async run () {
|
|
20
|
+
const { args, flags } = await this.parse(ConnectEventsStreamDelete)
|
|
21
|
+
const context = {
|
|
22
|
+
app: flags.app,
|
|
23
|
+
flags,
|
|
24
|
+
args,
|
|
25
|
+
auth: { password: this.heroku.auth }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await cli.confirmApp(flags.app, flags.confirm)
|
|
29
|
+
|
|
30
|
+
await cli.action('deleting stream', (async function () {
|
|
31
|
+
const connection = await api.withConnection(context, this.heroku, api.ADDON_TYPE_EVENTS)
|
|
32
|
+
context.region = connection.region_url
|
|
33
|
+
const stream = await api.withStream(context, connection, args.stream)
|
|
34
|
+
const response = await api.request(context, 'DELETE', `/api/v3/streams/${stream.id}`)
|
|
35
|
+
if (response.status !== 204) {
|
|
36
|
+
throw new Error(response.data.message || 'unknown error')
|
|
37
|
+
}
|
|
38
|
+
}.bind(this))())
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as api from '../../../lib/connect/api.js'
|
|
2
|
+
import { Command, flags } from '@heroku-cli/command'
|
|
3
|
+
import { Args } from '@oclif/core'
|
|
4
|
+
import cli from '@heroku/heroku-cli-util'
|
|
5
|
+
|
|
6
|
+
export default class ConnectEventsStreamState extends Command {
|
|
7
|
+
static description = 'return a stream state'
|
|
8
|
+
|
|
9
|
+
static args = {
|
|
10
|
+
stream: Args.string()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static flags = {
|
|
14
|
+
app: flags.app({ required: true }),
|
|
15
|
+
resource: flags.string({ description: 'specific connection resource name' })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async run () {
|
|
19
|
+
const { args, flags } = await this.parse(ConnectEventsStreamState)
|
|
20
|
+
const context = {
|
|
21
|
+
app: flags.app,
|
|
22
|
+
flags,
|
|
23
|
+
args,
|
|
24
|
+
auth: { password: this.heroku.auth }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const connection = await api.withConnection(context, this.heroku, api.ADDON_TYPE_EVENTS)
|
|
28
|
+
context.region = connection.region_url
|
|
29
|
+
const stream = await api.withStream(context, connection, args.stream)
|
|
30
|
+
|
|
31
|
+
cli.log(stream.state)
|
|
32
|
+
}
|
|
33
|
+
}
|
package/lib/clients/connect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios'
|
|
2
2
|
|
|
3
3
|
class ConnectClient {
|
|
4
4
|
constructor (context) {
|
|
@@ -16,14 +16,15 @@ class ConnectClient {
|
|
|
16
16
|
return this.client.get(`${detailUrl}?deep=true`)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
request ({ baseURL, method, url, data }) {
|
|
19
|
+
request ({ baseURL, method, url, data, params }) {
|
|
20
20
|
return this.client({
|
|
21
21
|
baseURL,
|
|
22
22
|
method,
|
|
23
23
|
url,
|
|
24
|
-
data
|
|
24
|
+
data,
|
|
25
|
+
params
|
|
25
26
|
})
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
export { ConnectClient }
|
package/lib/clients/discovery.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
|
|
2
3
|
const baseURL = process.env.CONNECT_DISCOVERY_SERVER || (process.env.CONNECT_ADDON === 'connectqa'
|
|
3
4
|
? 'https://hc-central-qa.herokai.com'
|
|
4
5
|
: 'https://hc-central.heroku.com')
|
|
@@ -29,4 +30,4 @@ class DiscoveryClient {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
export { DiscoveryClient }
|
package/lib/connect/api.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { ConnectClient } = require('../clients/connect')
|
|
5
|
-
const { DiscoveryClient } = require('../clients/discovery')
|
|
1
|
+
import cli from '@heroku/heroku-cli-util'
|
|
2
|
+
import { ConnectClient } from '../clients/connect.js'
|
|
3
|
+
import { DiscoveryClient } from '../clients/discovery.js'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const ADDON_TYPE_SYNC = 1
|
|
6
|
+
export const ADDON_TYPE_EVENTS = 2
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
export function request (context, method, url, data, params) {
|
|
11
9
|
if (!context.region) {
|
|
12
10
|
throw new Error('Must provide region URL')
|
|
13
11
|
}
|
|
@@ -16,149 +14,129 @@ const request = exports.request = function (context, method, url, data) {
|
|
|
16
14
|
baseURL: context.region,
|
|
17
15
|
method,
|
|
18
16
|
url,
|
|
19
|
-
data
|
|
17
|
+
data,
|
|
18
|
+
params
|
|
20
19
|
})
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
export async function withUserConnections (context, appName, flags, allowNone, heroku, addonType) {
|
|
24
23
|
const connectClient = new ConnectClient(context)
|
|
25
24
|
const discoveryClient = new DiscoveryClient(context)
|
|
26
25
|
|
|
27
|
-
const searchResponse =
|
|
26
|
+
const searchResponse = await discoveryClient.searchConnections(appName, context.flags.resource, addonType)
|
|
28
27
|
const connections = searchResponse.data.results
|
|
29
28
|
|
|
30
29
|
if (connections.length === 0) {
|
|
31
|
-
return
|
|
30
|
+
return []
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
const fetchConnectionDetailFuncs = connections.map(function (c) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
return yield Promise.resolve(mergedDetails)
|
|
42
|
-
})
|
|
33
|
+
const fetchConnectionDetailFuncs = connections.map(async function (c) {
|
|
34
|
+
const response = await connectClient.getDetails(c)
|
|
35
|
+
return {
|
|
36
|
+
...c,
|
|
37
|
+
...response.data
|
|
38
|
+
}
|
|
43
39
|
})
|
|
44
40
|
|
|
45
|
-
const aggregatedConnectionsData =
|
|
46
|
-
return
|
|
47
|
-
}
|
|
41
|
+
const aggregatedConnectionsData = await Promise.all(fetchConnectionDetailFuncs)
|
|
42
|
+
return aggregatedConnectionsData
|
|
43
|
+
}
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const discoveryClient = new DiscoveryClient(context)
|
|
45
|
+
export async function withConnection (context, heroku, addonType) {
|
|
46
|
+
const connectClient = new ConnectClient(context)
|
|
47
|
+
const discoveryClient = new DiscoveryClient(context)
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
const searchResponse = await discoveryClient.searchConnections(context.app, context.flags.resource, addonType)
|
|
50
|
+
const connections = searchResponse.data.results
|
|
56
51
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return yield Promise.resolve(matchWithDetails)
|
|
52
|
+
if (connections.length === 0) {
|
|
53
|
+
throw Error('No connection(s) found')
|
|
54
|
+
} else if (connections.length > 1) {
|
|
55
|
+
throw new Error("Multiple connections found. Please use '--resource' to specify a single connection by resource name. Use 'connect:info' to list the resource names.")
|
|
56
|
+
} else {
|
|
57
|
+
const match = connections[0]
|
|
58
|
+
const matchDetailResponse = await connectClient.getDetails(match)
|
|
59
|
+
return {
|
|
60
|
+
...match,
|
|
61
|
+
...matchDetailResponse.data
|
|
69
62
|
}
|
|
70
|
-
}
|
|
63
|
+
}
|
|
71
64
|
}
|
|
72
65
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
mapping = m
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
if (mapping !== undefined) {
|
|
83
|
-
return yield Promise.resolve(mapping)
|
|
84
|
-
} else {
|
|
85
|
-
throw new Error(`No mapping configured for ${objectName}`)
|
|
66
|
+
export async function withMapping (connection, objectName) {
|
|
67
|
+
const objectNameLower = objectName?.toLowerCase()
|
|
68
|
+
let mapping
|
|
69
|
+
connection.mappings.forEach(function (m) {
|
|
70
|
+
if (m.object_name.toLowerCase() === objectNameLower) {
|
|
71
|
+
mapping = m
|
|
86
72
|
}
|
|
87
73
|
})
|
|
74
|
+
if (mapping !== undefined) {
|
|
75
|
+
return mapping
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(`No mapping configured for ${objectName}`)
|
|
78
|
+
}
|
|
88
79
|
}
|
|
89
80
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
stream = s
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
if (stream !== undefined) {
|
|
103
|
-
return yield Promise.resolve(stream)
|
|
104
|
-
} else {
|
|
105
|
-
throw new Error(`No stream configured for ${objectName}`)
|
|
81
|
+
export async function withStream (context, connection, objectName) {
|
|
82
|
+
if (!connection.streams) {
|
|
83
|
+
connection.streams = await getStreams(context, connection)
|
|
84
|
+
}
|
|
85
|
+
const objectNameLower = objectName?.toLowerCase()
|
|
86
|
+
let stream
|
|
87
|
+
connection.streams.forEach(function (s) {
|
|
88
|
+
if (s.object_name.toLowerCase() === objectNameLower) {
|
|
89
|
+
stream = s
|
|
106
90
|
}
|
|
107
91
|
})
|
|
92
|
+
if (stream !== undefined) {
|
|
93
|
+
return stream
|
|
94
|
+
} else {
|
|
95
|
+
throw new Error(`No stream configured for ${objectName}`)
|
|
96
|
+
}
|
|
108
97
|
}
|
|
109
98
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
data: null
|
|
118
|
-
})
|
|
119
|
-
const streams = response.data.results
|
|
120
|
-
return yield Promise.resolve(streams)
|
|
99
|
+
export async function getStreams (context, connection) {
|
|
100
|
+
const connectClient = new ConnectClient(context)
|
|
101
|
+
const response = await connectClient.request({
|
|
102
|
+
baseURL: connection.region_url,
|
|
103
|
+
method: 'GET',
|
|
104
|
+
url: `${connection.detail_url}/streams`,
|
|
105
|
+
data: null
|
|
121
106
|
})
|
|
107
|
+
return response.data.results
|
|
122
108
|
}
|
|
123
109
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
c.streams = yield getStreams(context, c)
|
|
129
|
-
return yield Promise.resolve(c)
|
|
130
|
-
})
|
|
131
|
-
})
|
|
132
|
-
const aggregatedConnectionsResponse = yield Promise.all(fetchConnectionStreams)
|
|
133
|
-
return yield Promise.resolve(aggregatedConnectionsResponse)
|
|
110
|
+
export async function withStreams (context, connections) {
|
|
111
|
+
const fetchConnectionStreams = connections.map(async function (c) {
|
|
112
|
+
c.streams = await getStreams(context, c)
|
|
113
|
+
return c
|
|
134
114
|
})
|
|
115
|
+
return await Promise.all(fetchConnectionStreams)
|
|
135
116
|
}
|
|
136
117
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
yield Promise.resolve(response.json)
|
|
142
|
-
return yield withUserConnections(context, app, flags, allowNone, heroku, addonType)
|
|
143
|
-
})
|
|
118
|
+
export async function requestAppAccess (context, app, flags, allowNone, heroku, addonType) {
|
|
119
|
+
const discoveryClient = new DiscoveryClient(context)
|
|
120
|
+
await discoveryClient.requestAppAccess(app, addonType)
|
|
121
|
+
return await withUserConnections(context, app, flags, allowNone, heroku, addonType)
|
|
144
122
|
}
|
|
145
123
|
|
|
146
|
-
|
|
124
|
+
export async function getWriteErrors (context, heroku) {
|
|
147
125
|
let url, action
|
|
148
126
|
const mappingName = context.args.name
|
|
149
|
-
const connection =
|
|
127
|
+
const connection = await withConnection(context, heroku)
|
|
150
128
|
context.region = connection.region_url
|
|
151
129
|
if (!mappingName) {
|
|
152
130
|
url = `/api/v3/connections/${connection.id}/errors`
|
|
153
131
|
action = `Retrieving write errors for ${connection.name}`
|
|
154
132
|
} else {
|
|
155
|
-
const mapping =
|
|
133
|
+
const mapping = await withMapping(connection, mappingName)
|
|
156
134
|
url = `/api/v3/mappings/${mapping.id}/errors`
|
|
157
135
|
action = `Retrieving write errors for ${mappingName} on ${connection.name}`
|
|
158
136
|
}
|
|
159
|
-
const results =
|
|
160
|
-
return
|
|
161
|
-
}))
|
|
137
|
+
const results = await cli.action(action, (async function () {
|
|
138
|
+
return await request(context, 'GET', url)
|
|
139
|
+
})())
|
|
162
140
|
const errors = results.data
|
|
163
141
|
|
|
164
142
|
if (errors.count === 0) {
|
|
@@ -178,4 +156,4 @@ exports.getWriteErrors = co.wrap(function * (context, heroku) {
|
|
|
178
156
|
})
|
|
179
157
|
}
|
|
180
158
|
}
|
|
181
|
-
}
|
|
159
|
+
}
|