@greenmind/cli 0.9.31 → 0.9.40
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/package.json +6 -5
- package/src/client.ts +155 -121
- package/src/command.ts +509 -93
- package/src/commands.ts +47 -24
- package/src/constants.ts +8 -6
- package/src/credentials.ts +2 -2
- package/src/environment-commands.ts +54 -133
- package/src/index.ts +1 -1
- package/src/load.ts +7 -3
- package/src/org-commands.ts +579 -0
- package/src/protocol.ts +5 -7
- package/src/runner-command.ts +118 -0
- package/src/session.ts +20 -7
package/src/commands.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
2
|
import { functionRequest, type Json, parserOf, s } from '@greenmind/ext-schema'
|
|
3
3
|
import {
|
|
4
|
+
checkProject,
|
|
4
5
|
type CompiledDefinition,
|
|
5
6
|
type DefinitionBase,
|
|
6
7
|
type FunctionAnswer,
|
|
@@ -25,18 +26,33 @@ function describe(definition: CompiledDefinition): string {
|
|
|
25
26
|
return `${definition.kind.padEnd(10)} ${definition.key} ${short(definition.contentHash)}`
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
/** An environment's issue or one the SDK found, which name their definition the same way. */
|
|
30
|
+
type Issue = Pick<CheckIssue, 'key' | 'step' | 'message'> & { readonly kind: string }
|
|
31
|
+
|
|
32
|
+
function printIssues(issues: readonly Issue[], print: Print): void {
|
|
29
33
|
for (const issue of issues) {
|
|
30
34
|
const step = issue.step ? ` (step ${issue.step})` : ''
|
|
31
35
|
print(` ${issue.kind} ${issue.key}${step}: ${issue.message}`)
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The gateway rules the files can be held to without an environment, printed when broken. What
|
|
41
|
+
* `wraps` may name is the environment's to say, so only its check holds that one.
|
|
42
|
+
*/
|
|
43
|
+
function passesRules(definitions: readonly CompiledDefinition[], print: Print): boolean {
|
|
44
|
+
const issues = checkProject(definitions)
|
|
45
|
+
if (issues.length === 0) return true
|
|
46
|
+
print(`${issues.length} rule${issues.length === 1 ? ' is' : 's are'} broken:`)
|
|
47
|
+
printIssues(issues, print)
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
export interface CheckOptions {
|
|
36
52
|
readonly paths: readonly string[]
|
|
37
53
|
/** With a client the environment's own validation runs too; without, only what the SDK can say. */
|
|
38
54
|
readonly client?: PlatformClient
|
|
39
|
-
/** The environment
|
|
55
|
+
/** The environment checked against; the client's own when left out. */
|
|
40
56
|
readonly appKey?: string
|
|
41
57
|
}
|
|
42
58
|
|
|
@@ -44,6 +60,7 @@ export interface CheckOptions {
|
|
|
44
60
|
export async function runCheck(options: CheckOptions, print: Print): Promise<boolean> {
|
|
45
61
|
const definitions = await loadDefinitions(options.paths)
|
|
46
62
|
for (const definition of definitions) print(describe(definition))
|
|
63
|
+
if (!passesRules(definitions, print)) return false
|
|
47
64
|
if (!options.client) {
|
|
48
65
|
print(
|
|
49
66
|
`${definitions.length} definitions compile. Give a platform address and key to check them against an environment.`,
|
|
@@ -66,26 +83,22 @@ export interface PushOptions {
|
|
|
66
83
|
readonly paths: readonly string[]
|
|
67
84
|
readonly client: PlatformClient
|
|
68
85
|
readonly source?: SourceRef
|
|
69
|
-
/** Also make each pushed version live.
|
|
86
|
+
/** Also make each pushed version live. */
|
|
70
87
|
readonly live?: boolean
|
|
71
|
-
/**
|
|
88
|
+
/** With `live`, take the flows and schedules the files no longer hold off the live set. */
|
|
89
|
+
readonly retire?: boolean
|
|
90
|
+
/** The environment pushed to; the client's own when left out. */
|
|
72
91
|
readonly appKey?: string
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
/**
|
|
76
|
-
* Checks the files against the environment
|
|
77
|
-
*
|
|
78
|
-
* is never pushed to.
|
|
95
|
+
* Checks the files against the environment, and only if it accepts them pushes them, and with
|
|
96
|
+
* `live` makes them live. Whether the caller may is the platform's to say: `edit_config` there.
|
|
79
97
|
*/
|
|
80
98
|
export async function runPush(options: PushOptions, print: Print): Promise<boolean> {
|
|
81
99
|
const definitions = await loadDefinitions(options.paths)
|
|
100
|
+
if (!passesRules(definitions, print)) return false
|
|
82
101
|
const checked = await options.client.check(definitions, options.appKey)
|
|
83
|
-
if (checked.environment.protected) {
|
|
84
|
-
print(
|
|
85
|
-
`${checked.environment.appKey} is changed by a release, not by a push. Push to a test environment and promote from there.`,
|
|
86
|
-
)
|
|
87
|
-
return false
|
|
88
|
-
}
|
|
89
102
|
if (checked.issues.length > 0) {
|
|
90
103
|
print(
|
|
91
104
|
`${checked.environment.appKey} refuses ${checked.issues.length} issue${checked.issues.length === 1 ? '' : 's'}, so nothing was pushed:`,
|
|
@@ -98,44 +111,54 @@ export async function runPush(options: PushOptions, print: Print): Promise<boole
|
|
|
98
111
|
options.source,
|
|
99
112
|
options.live,
|
|
100
113
|
options.appKey,
|
|
114
|
+
options.retire,
|
|
101
115
|
)
|
|
102
116
|
for (const result of pushed.results) {
|
|
103
117
|
print(
|
|
104
118
|
`${result.created ? 'new version' : 'unchanged '} ${result.kind.padEnd(10)} ${result.key} ${short(result.contentHash)}`,
|
|
105
119
|
)
|
|
106
120
|
}
|
|
121
|
+
for (const each of pushed.retired ?? []) print(`retired ${each.kind.padEnd(10)} ${each.key}`)
|
|
107
122
|
const made = pushed.results.filter((result) => result.created).length
|
|
123
|
+
const retired = pushed.retired?.length ? ` ${pushed.retired.length} retired.` : ''
|
|
108
124
|
print(
|
|
109
|
-
`${pushed.environment.appKey}: ${made} new, ${pushed.results.length - made} unchanged.${pushed.live ? ' All made live.' : ''}`,
|
|
125
|
+
`${pushed.environment.appKey}: ${made} new, ${pushed.results.length - made} unchanged.${pushed.live ? ' All made live.' : ''}${retired}`,
|
|
110
126
|
)
|
|
127
|
+
const landing = landingLine(pushed.landing)
|
|
128
|
+
if (landing) print(landing)
|
|
111
129
|
return true
|
|
112
130
|
}
|
|
113
131
|
|
|
132
|
+
/** What a live push's landing means for the game database; nothing where there was none to land. */
|
|
133
|
+
function landingLine(landing: 'landed' | 'pending' | undefined): string | null {
|
|
134
|
+
switch (landing) {
|
|
135
|
+
case 'landed':
|
|
136
|
+
return 'Landed in the game database.'
|
|
137
|
+
case 'pending':
|
|
138
|
+
return 'Landing in the game database is pending; it is retried automatically until the engine takes it.'
|
|
139
|
+
case undefined:
|
|
140
|
+
return null
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
114
144
|
export interface UploadOptions {
|
|
115
145
|
readonly paths: readonly string[]
|
|
116
146
|
readonly client: PlatformClient
|
|
117
147
|
readonly source?: SourceRef
|
|
118
148
|
/** Bun build plugins the bundle's sources need to compile. */
|
|
119
149
|
readonly plugins?: readonly import('bun').BunPlugin[]
|
|
120
|
-
/** The environment
|
|
150
|
+
/** The environment uploaded to; the client's own when left out. */
|
|
121
151
|
readonly appKey?: string
|
|
122
152
|
}
|
|
123
153
|
|
|
124
154
|
/**
|
|
125
|
-
* Builds the functions the files define into one bundle and uploads it to the environment
|
|
126
|
-
*
|
|
127
|
-
* and never uploads to one a release owns.
|
|
155
|
+
* Builds the functions the files define into one bundle and uploads it to the environment, with
|
|
156
|
+
* the functions as versions naming it. Like a push, it asks the environment to check them first.
|
|
128
157
|
*/
|
|
129
158
|
export async function runUpload(options: UploadOptions, print: Print): Promise<boolean> {
|
|
130
159
|
const bundle = await buildBundle(options.paths, options.plugins)
|
|
131
160
|
print(`bundle ${short(bundle.contentHash)} ${bundle.bytes.length} bytes`)
|
|
132
161
|
const checked = await options.client.check(bundle.definitions, options.appKey)
|
|
133
|
-
if (checked.environment.protected) {
|
|
134
|
-
print(
|
|
135
|
-
`${checked.environment.appKey} is changed by a release, not by an upload. Upload to a test environment and promote from there.`,
|
|
136
|
-
)
|
|
137
|
-
return false
|
|
138
|
-
}
|
|
139
162
|
if (checked.issues.length > 0) {
|
|
140
163
|
print(
|
|
141
164
|
`${checked.environment.appKey} refuses ${checked.issues.length} issue${checked.issues.length === 1 ? '' : 's'}, so nothing was uploaded:`,
|
package/src/constants.ts
CHANGED
|
@@ -2,13 +2,12 @@ import pkg from '../package.json'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The few values this tool knows before it has asked a platform anything. Where to sign in, and
|
|
5
|
-
* with which client and scopes, are the platform's to say
|
|
6
|
-
*
|
|
7
|
-
* flag overrides each.
|
|
5
|
+
* with which client and scopes, are the platform's to say (`GET /cli` on the developer API);
|
|
6
|
+
* `gm login` reads them from the platform it signs in to, and a flag overrides each.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
/** The
|
|
11
|
-
export const DEFAULT_PLATFORM_URL = 'https://
|
|
9
|
+
/** The developer API a command calls when neither `--url` nor `GM_DEVELOPER_URL` names one. */
|
|
10
|
+
export const DEFAULT_PLATFORM_URL = 'https://developer.publishing.greenmindmedia.com'
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
13
|
* The command line's client at GreenMind's identity server: the same on every stage, and what the
|
|
@@ -29,7 +28,10 @@ export const VERSION_HEADER = 'x-gm-cli-version'
|
|
|
29
28
|
|
|
30
29
|
export const CLI_VERSION: string = pkg.version
|
|
31
30
|
|
|
32
|
-
export const ENV_URL = '
|
|
31
|
+
export const ENV_URL = 'GM_DEVELOPER_URL'
|
|
32
|
+
/** The handle of the org whose environments a command names, when `--org` does not. */
|
|
33
|
+
export const ENV_ORG = 'GM_ORG'
|
|
34
|
+
/** An org key a build calls with, when `--key` gives none. */
|
|
33
35
|
export const ENV_KEY = 'GM_PUBLISH_KEY'
|
|
34
36
|
export const ENV_ISSUER = 'GM_IDENTITY_URL'
|
|
35
37
|
|
package/src/credentials.ts
CHANGED
|
@@ -17,8 +17,8 @@ import { ENV_CONFIG_DIR } from './constants'
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Where a signed-in person's tokens are kept: one file in the user's own configuration directory,
|
|
20
|
-
* keyed by platform address, holding the tokens and nothing that works without signing in (never
|
|
21
|
-
*
|
|
20
|
+
* keyed by platform address, holding the tokens and nothing that works without signing in (never an
|
|
21
|
+
* org key). Changes to it go through `withLock`, because a refresh token is
|
|
22
22
|
* spent by one use and two processes must not both spend it.
|
|
23
23
|
*/
|
|
24
24
|
|
|
@@ -10,22 +10,18 @@ import {
|
|
|
10
10
|
type FunctionRuntimeEffect,
|
|
11
11
|
type FunctionRuntimeName,
|
|
12
12
|
parserOf,
|
|
13
|
-
type PublishKeyEntry,
|
|
14
13
|
SETUP_ITEMS_MAX,
|
|
15
14
|
type SeededValue,
|
|
16
|
-
type ServerKeyEntry,
|
|
17
15
|
} from '@greenmind/ext-schema'
|
|
18
|
-
import {
|
|
16
|
+
import type { PlatformClient } from './client'
|
|
19
17
|
import { type Print, runPush, runUpload } from './commands'
|
|
20
|
-
import { ENV_KEY, ENV_URL } from './constants'
|
|
21
18
|
import type { LoadedExtConfig } from './ext-config'
|
|
22
19
|
import { loadDefinitions, LoadError } from './load'
|
|
23
20
|
import type { SourceRef } from './protocol'
|
|
24
21
|
|
|
25
22
|
/**
|
|
26
23
|
* What each environment-setup command does once it has a client: ask the platform, print what it
|
|
27
|
-
* said in a readable layout, answer whether it went well.
|
|
28
|
-
* printed here once and nowhere else.
|
|
24
|
+
* said in a readable layout, answer whether it went well.
|
|
29
25
|
*/
|
|
30
26
|
|
|
31
27
|
/** Rows laid out in columns two spaces apart, the last cell of each left as long as it is. */
|
|
@@ -49,21 +45,24 @@ export function columns(rows: readonly (readonly string[])[], indent = ''): stri
|
|
|
49
45
|
const when = (instant: string | null) => instant ?? 'never'
|
|
50
46
|
const plural = (count: number, word: string) => `${count} ${word}${count === 1 ? '' : 's'}`
|
|
51
47
|
|
|
52
|
-
export async function runEnvironmentList(
|
|
53
|
-
|
|
48
|
+
export async function runEnvironmentList(
|
|
49
|
+
client: PlatformClient,
|
|
50
|
+
project: string,
|
|
51
|
+
print: Print,
|
|
52
|
+
): Promise<boolean> {
|
|
53
|
+
const { environments } = await client.listEnvironments(project)
|
|
54
54
|
if (environments.length === 0) {
|
|
55
|
-
print(
|
|
55
|
+
print(`You can read no environments of ${project}.`)
|
|
56
56
|
return true
|
|
57
57
|
}
|
|
58
58
|
const rows = environments.map((each) => [
|
|
59
59
|
each.appKey,
|
|
60
60
|
each.environment,
|
|
61
|
-
each.protected ? 'protected' : '',
|
|
62
61
|
`${each.org.name} / ${each.project.name}`,
|
|
63
62
|
each.level ? `can ${each.level}` : '',
|
|
64
63
|
])
|
|
65
64
|
for (const line of columns([
|
|
66
|
-
['APP KEY', 'ENVIRONMENT', '
|
|
65
|
+
['APP KEY', 'ENVIRONMENT', 'ORGANISATION / PROJECT', 'ACCESS'],
|
|
67
66
|
...rows,
|
|
68
67
|
])) {
|
|
69
68
|
print(line)
|
|
@@ -84,7 +83,7 @@ function runtimeLine(effect: FunctionRuntimeEffect | null): string[] {
|
|
|
84
83
|
/** Every field of an environment's status, grouped the way somebody reads it. */
|
|
85
84
|
export function describeStatus(status: EnvironmentStatus): string[] {
|
|
86
85
|
const lines: string[] = [
|
|
87
|
-
`${status.appKey} ${status.name} (${status.environment}
|
|
86
|
+
`${status.appKey} ${status.name} (${status.environment})`,
|
|
88
87
|
`Project ${status.project.name} (${status.project.key})`,
|
|
89
88
|
status.gameDatabaseKey
|
|
90
89
|
? `Database ${status.gameDatabaseKey}`
|
|
@@ -124,10 +123,10 @@ export function describeStatus(status: EnvironmentStatus): string[] {
|
|
|
124
123
|
} else {
|
|
125
124
|
lines.push('Last landing nothing was ever landed or queued')
|
|
126
125
|
}
|
|
127
|
-
const {
|
|
126
|
+
const { actAsServer, editConfig } = status.keys
|
|
128
127
|
lines.push(
|
|
129
|
-
`
|
|
130
|
-
`
|
|
128
|
+
`Org keys ${actAsServer.live} live acting as a server, ${actAsServer.revoked} revoked`,
|
|
129
|
+
` ${editConfig.live} live holding edit_config, ${editConfig.revoked} revoked`,
|
|
131
130
|
)
|
|
132
131
|
return lines
|
|
133
132
|
}
|
|
@@ -141,103 +140,6 @@ export async function runEnvironmentStatus(
|
|
|
141
140
|
return true
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
type KeyKind = 'server' | 'publish'
|
|
145
|
-
|
|
146
|
-
function describeKeys(entries: readonly (ServerKeyEntry | PublishKeyEntry)[]): string[] {
|
|
147
|
-
if (entries.length === 0) return ['No keys.']
|
|
148
|
-
return columns([
|
|
149
|
-
['ID', 'NAME', 'PREFIX', 'CREATED', 'LAST USED', ''],
|
|
150
|
-
...entries.map((each) => [
|
|
151
|
-
each.id,
|
|
152
|
-
'name' in each ? each.name : each.label,
|
|
153
|
-
each.prefix,
|
|
154
|
-
each.createdAt,
|
|
155
|
-
when(each.lastUsedAt),
|
|
156
|
-
each.revokedAt ? `revoked ${each.revokedAt}` : '',
|
|
157
|
-
]),
|
|
158
|
-
])
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function runKeysList(
|
|
162
|
-
client: PlatformClient,
|
|
163
|
-
kind: KeyKind,
|
|
164
|
-
appKey: string,
|
|
165
|
-
print: Print,
|
|
166
|
-
): Promise<boolean> {
|
|
167
|
-
const keys =
|
|
168
|
-
kind === 'server'
|
|
169
|
-
? (await client.listServerKeys(appKey)).keys
|
|
170
|
-
: (await client.listPublishKeys(appKey)).keys
|
|
171
|
-
for (const line of describeKeys(keys)) print(line)
|
|
172
|
-
return true
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Makes a key and prints its secret, the one time the platform ever gives it. For a server key
|
|
177
|
-
* the next step is the studio's: its backend's own config, which this tool cannot reach.
|
|
178
|
-
*/
|
|
179
|
-
export async function runKeysCreate(
|
|
180
|
-
client: PlatformClient,
|
|
181
|
-
kind: KeyKind,
|
|
182
|
-
appKey: string,
|
|
183
|
-
name: string,
|
|
184
|
-
print: Print,
|
|
185
|
-
): Promise<boolean> {
|
|
186
|
-
const created =
|
|
187
|
-
kind === 'server'
|
|
188
|
-
? await client.createServerKey(appKey, name)
|
|
189
|
-
: await client.createPublishKey(appKey, name)
|
|
190
|
-
print(`Created the ${kind} key ${created.key.prefix} for ${appKey}.`)
|
|
191
|
-
print('')
|
|
192
|
-
print(created.secret)
|
|
193
|
-
print('')
|
|
194
|
-
print(
|
|
195
|
-
'This is the only time the key is shown; it is kept only as a hash and cannot be read back.',
|
|
196
|
-
)
|
|
197
|
-
if (kind === 'server') {
|
|
198
|
-
print(
|
|
199
|
-
`Next: put the platform address (${client.address}) and this key in your game backend's own config.`,
|
|
200
|
-
)
|
|
201
|
-
} else {
|
|
202
|
-
print(`Next: give it to your build as ${ENV_KEY}, with ${ENV_URL} set to ${client.address}.`)
|
|
203
|
-
}
|
|
204
|
-
return true
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** A key by its id, or by its prefix where that names exactly one. */
|
|
208
|
-
async function keyIdOf(
|
|
209
|
-
client: PlatformClient,
|
|
210
|
-
kind: KeyKind,
|
|
211
|
-
appKey: string,
|
|
212
|
-
given: string,
|
|
213
|
-
): Promise<string> {
|
|
214
|
-
const keys =
|
|
215
|
-
kind === 'server'
|
|
216
|
-
? (await client.listServerKeys(appKey)).keys
|
|
217
|
-
: (await client.listPublishKeys(appKey)).keys
|
|
218
|
-
if (keys.some((each) => each.id === given)) return given
|
|
219
|
-
const byPrefix = keys.filter((each) => each.prefix === given)
|
|
220
|
-
if (byPrefix.length === 1 && byPrefix[0]) return byPrefix[0].id
|
|
221
|
-
throw new PlatformError(
|
|
222
|
-
`${appKey} has no ${kind} key with the id or prefix ${given}. \`gm pub keys ${kind} list ${appKey}\` shows them.`,
|
|
223
|
-
404,
|
|
224
|
-
)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export async function runKeysRevoke(
|
|
228
|
-
client: PlatformClient,
|
|
229
|
-
kind: KeyKind,
|
|
230
|
-
appKey: string,
|
|
231
|
-
given: string,
|
|
232
|
-
print: Print,
|
|
233
|
-
): Promise<boolean> {
|
|
234
|
-
const id = await keyIdOf(client, kind, appKey, given)
|
|
235
|
-
if (kind === 'server') await client.revokeServerKey(appKey, id)
|
|
236
|
-
else await client.revokePublishKey(appKey, id)
|
|
237
|
-
print(`Revoked the ${kind} key ${given} of ${appKey}.`)
|
|
238
|
-
return true
|
|
239
|
-
}
|
|
240
|
-
|
|
241
143
|
/** The values in a file: `{ values: [...] }` as the route takes them, or the list alone. */
|
|
242
144
|
export function readSeedFile(file: string): readonly SeededValue[] {
|
|
243
145
|
let body: object | null
|
|
@@ -268,20 +170,6 @@ function chunks<T>(items: readonly T[]): T[][] {
|
|
|
268
170
|
return out
|
|
269
171
|
}
|
|
270
172
|
|
|
271
|
-
/**
|
|
272
|
-
* The environment a setup command acts in: a publish key's own, so one named must be it (the
|
|
273
|
-
* platform checks); a signed-in person has to name it, since their sign-in reaches several.
|
|
274
|
-
*/
|
|
275
|
-
function setupEnvironment(client: PlatformClient, appKey: string | undefined): string | undefined {
|
|
276
|
-
if (appKey === undefined && client.signedIn) {
|
|
277
|
-
throw new PlatformError(
|
|
278
|
-
'Signed in as a person, name the environment with --env <app key>; a publish key needs none.',
|
|
279
|
-
400,
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
return appKey
|
|
283
|
-
}
|
|
284
|
-
|
|
285
173
|
export async function runConfigSeed(
|
|
286
174
|
client: PlatformClient,
|
|
287
175
|
values: readonly SeededValue[],
|
|
@@ -292,10 +180,9 @@ export async function runConfigSeed(
|
|
|
292
180
|
print('There are no config values to seed.')
|
|
293
181
|
return true
|
|
294
182
|
}
|
|
295
|
-
const environment = setupEnvironment(client, appKey)
|
|
296
183
|
const seeded: string[] = []
|
|
297
184
|
for (const part of chunks(values)) {
|
|
298
|
-
seeded.push(...(await client.seedConfigDefaults(part,
|
|
185
|
+
seeded.push(...(await client.seedConfigDefaults(part, appKey)).seeded)
|
|
299
186
|
}
|
|
300
187
|
for (const name of seeded) print(`seeded ${name}`)
|
|
301
188
|
print(
|
|
@@ -315,11 +202,10 @@ export async function runFlowSwitch(
|
|
|
315
202
|
print('There are no flows to switch.')
|
|
316
203
|
return true
|
|
317
204
|
}
|
|
318
|
-
const environment = setupEnvironment(client, appKey)
|
|
319
205
|
for (const part of chunks(keys)) {
|
|
320
206
|
const answer = await client.switchFlows(
|
|
321
207
|
part.map((key) => ({ key, enabled })),
|
|
322
|
-
|
|
208
|
+
appKey,
|
|
323
209
|
)
|
|
324
210
|
for (const flow of answer.flows) print(`${flow.enabled ? 'on ' : 'off'} ${flow.key}`)
|
|
325
211
|
}
|
|
@@ -327,6 +213,38 @@ export async function runFlowSwitch(
|
|
|
327
213
|
return true
|
|
328
214
|
}
|
|
329
215
|
|
|
216
|
+
/**
|
|
217
|
+
* Replays the kept events of a window into one flow, call after call until the window is done, so
|
|
218
|
+
* one command covers a window of any size. A repeat starts nothing the first did.
|
|
219
|
+
*/
|
|
220
|
+
export async function runEventsReplay(
|
|
221
|
+
client: Pick<PlatformClient, 'replayEvents'>,
|
|
222
|
+
window: { flow: string; from?: string; to?: string },
|
|
223
|
+
print: Print,
|
|
224
|
+
appKey?: string,
|
|
225
|
+
): Promise<boolean> {
|
|
226
|
+
let events = 0
|
|
227
|
+
let queued = 0
|
|
228
|
+
let after: string | undefined
|
|
229
|
+
let span = ''
|
|
230
|
+
for (;;) {
|
|
231
|
+
const answer = await client.replayEvents(
|
|
232
|
+
after === undefined ? window : { ...window, after },
|
|
233
|
+
appKey,
|
|
234
|
+
)
|
|
235
|
+
events += answer.events
|
|
236
|
+
queued += answer.queued
|
|
237
|
+
span = `${answer.from} to ${answer.to} (the plan keeps ${plural(answer.windowDays, 'day')})`
|
|
238
|
+
if (answer.next === null) break
|
|
239
|
+
after = answer.next
|
|
240
|
+
}
|
|
241
|
+
print(`${window.flow}: ${plural(events, 'kept event')} from ${span}.`)
|
|
242
|
+
print(
|
|
243
|
+
`${plural(queued, 'run')} started; the other events the flow had already run, or its filter turned away.`,
|
|
244
|
+
)
|
|
245
|
+
return true
|
|
246
|
+
}
|
|
247
|
+
|
|
330
248
|
/** Every flow the given paths define, by key. */
|
|
331
249
|
export async function flowKeysOf(paths: readonly string[]): Promise<string[]> {
|
|
332
250
|
const definitions = await loadDefinitions(paths)
|
|
@@ -488,8 +406,10 @@ export interface DeployOptions {
|
|
|
488
406
|
readonly client: PlatformClient
|
|
489
407
|
readonly config: LoadedExtConfig
|
|
490
408
|
readonly source?: SourceRef
|
|
491
|
-
/** The environment
|
|
409
|
+
/** The environment deployed to; the client's own when left out. */
|
|
492
410
|
readonly appKey?: string
|
|
411
|
+
/** Take the flows and schedules the files no longer define off the live set as it pushes. */
|
|
412
|
+
readonly retire?: boolean
|
|
493
413
|
}
|
|
494
414
|
|
|
495
415
|
/**
|
|
@@ -498,7 +418,7 @@ export interface DeployOptions {
|
|
|
498
418
|
* take alone, so a failure can be mended and the step run again.
|
|
499
419
|
*/
|
|
500
420
|
export async function runDeploy(options: DeployOptions, print: Print): Promise<boolean> {
|
|
501
|
-
const { client, config, source, appKey } = options
|
|
421
|
+
const { client, config, source, appKey, retire } = options
|
|
502
422
|
const steps: { name: string; run: () => Promise<boolean> }[] = [
|
|
503
423
|
{
|
|
504
424
|
name: 'upload',
|
|
@@ -507,7 +427,8 @@ export async function runDeploy(options: DeployOptions, print: Print): Promise<b
|
|
|
507
427
|
},
|
|
508
428
|
{
|
|
509
429
|
name: 'push',
|
|
510
|
-
run: () =>
|
|
430
|
+
run: () =>
|
|
431
|
+
runPush({ paths: config.paths, client, source, live: true, retire, appKey }, print),
|
|
511
432
|
},
|
|
512
433
|
]
|
|
513
434
|
if (config.configDefaults.length > 0) {
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* A build of the command line can carry more than the published one through `GmCommandContext`:
|
|
8
8
|
* more commands under a product, and more `gm login` switches asking for further scopes.
|
|
9
9
|
*
|
|
10
|
-
* What it says to the
|
|
10
|
+
* What it says to the tooling API is in `protocol.ts` and `client.ts`.
|
|
11
11
|
*/
|
|
12
12
|
export {
|
|
13
13
|
PlatformClient,
|
package/src/load.ts
CHANGED
|
@@ -38,7 +38,11 @@ export function kindOfStored(body: Json): DefinitionKind | undefined {
|
|
|
38
38
|
if ('sentBy' in body) return 'event'
|
|
39
39
|
if ('scope' in body && 'fields' in body) return 'collection'
|
|
40
40
|
if ('reads' in body) return 'function'
|
|
41
|
-
if ('
|
|
41
|
+
if ('in' in body && 'out' in body) return 'socket'
|
|
42
|
+
if ('guard' in body && 'flow' in body) return 'webhook'
|
|
43
|
+
if ('label' in body) return 'permission'
|
|
44
|
+
if ('cron' in body && 'target' in body) return 'schedule'
|
|
45
|
+
if ('input' in body && 'key' in body) return 'job'
|
|
42
46
|
return undefined
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -75,7 +79,7 @@ function loadStored(file: string): CompiledDefinition {
|
|
|
75
79
|
const kind = kindOfStored(body)
|
|
76
80
|
if (!kind) {
|
|
77
81
|
throw new LoadError(
|
|
78
|
-
`${file} is not a stored definition: expected a flow (trigger and steps), event (sentBy), collection (scope and fields), function (reads)
|
|
82
|
+
`${file} is not a stored definition: expected a flow (trigger and steps), event (sentBy), collection (scope and fields), function (reads), socket (in and out), webhook (guard and flow) or permission (label).`,
|
|
79
83
|
)
|
|
80
84
|
}
|
|
81
85
|
try {
|
|
@@ -113,7 +117,7 @@ export async function loadDefinitions(paths: readonly string[]): Promise<Compile
|
|
|
113
117
|
// whose definitions were made by an SDK that marks them differently from this one.
|
|
114
118
|
if (merged.size === 0) {
|
|
115
119
|
throw new LoadError(
|
|
116
|
-
`No flow, function,
|
|
120
|
+
`No flow, function, event, collection, socket, webhook or permission is defined in ${paths.join(', ')}. Export each definition from its module, made with defineFlow, defineFunction and the rest of the SDK.`,
|
|
117
121
|
)
|
|
118
122
|
}
|
|
119
123
|
const order = (kind: DefinitionKind) => DEFINITION_KINDS.indexOf(kind)
|