@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greenmind/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.40",
|
|
4
4
|
"description": "GreenMind's command line, gm: sign in once, manage environments and keys, and check, push, upload and run extensions",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
"bun": ">=1.4.2"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
|
-
"access": "public"
|
|
24
|
+
"access": "public",
|
|
25
|
+
"provenance": false
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@commander-js/extra-typings": "~15.0.0",
|
|
28
|
-
"@greenmind/ext-function-host": "0.9.
|
|
29
|
-
"@greenmind/ext-schema": "0.9.
|
|
30
|
-
"@greenmind/ext-sdk": "0.9.
|
|
29
|
+
"@greenmind/ext-function-host": "0.9.40",
|
|
30
|
+
"@greenmind/ext-schema": "0.9.40",
|
|
31
|
+
"@greenmind/ext-sdk": "0.9.40",
|
|
31
32
|
"commander": "~15.0.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
package/src/client.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
type CollectionStorageName,
|
|
4
4
|
type CollectionStorageSetRequest,
|
|
5
5
|
collectionStorageAnswer,
|
|
6
|
-
CONFIG_DEFAULTS_PATH,
|
|
7
6
|
type ConfigDefaultsAnswer,
|
|
8
7
|
type ConfigDefaultsRequest,
|
|
9
8
|
type ConnectorCheckAnswer,
|
|
@@ -11,53 +10,48 @@ import {
|
|
|
11
10
|
connectorCheckAnswer,
|
|
12
11
|
type FlowSwitchRequest,
|
|
13
12
|
type FunctionRuntimeSetRequest,
|
|
14
|
-
type PublishKeyCreateRequest,
|
|
15
|
-
type ServerKeyCreateRequest,
|
|
16
13
|
s,
|
|
17
|
-
ENVIRONMENTS_PATH,
|
|
18
14
|
type EnvironmentListAnswer,
|
|
19
15
|
type EnvironmentStatus,
|
|
20
16
|
environmentListAnswer,
|
|
21
|
-
environmentPaths,
|
|
22
17
|
environmentStatus,
|
|
23
|
-
|
|
18
|
+
type EventsReplayAnswer,
|
|
19
|
+
type EventsReplayRequest,
|
|
20
|
+
eventsReplayAnswer,
|
|
24
21
|
type ExtToolDiscovery,
|
|
25
22
|
extToolDiscovery,
|
|
26
|
-
FLOW_SWITCH_PATH,
|
|
27
23
|
type FlowSwitchAnswer,
|
|
28
24
|
type FunctionRuntimeAnswer,
|
|
29
25
|
type FunctionRuntimeName,
|
|
30
26
|
flowSwitchAnswer,
|
|
31
27
|
functionRuntimeAnswer,
|
|
28
|
+
type JobEnqueueRequest,
|
|
32
29
|
type Json,
|
|
33
|
-
type
|
|
34
|
-
type
|
|
30
|
+
type KeyCreateRequest,
|
|
31
|
+
type KeyUpdateRequest,
|
|
32
|
+
type PoolCreateRequestWire,
|
|
33
|
+
type PoolSettingsWire,
|
|
35
34
|
parserOf,
|
|
36
|
-
publishKeyCreated,
|
|
37
|
-
publishKeyListAnswer,
|
|
38
35
|
type Schema,
|
|
39
36
|
type SeededValue,
|
|
40
|
-
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
DEVELOPER_CLI_PATH,
|
|
38
|
+
type DeveloperEnvironment,
|
|
39
|
+
type DeveloperRefusal,
|
|
40
|
+
developerPaths,
|
|
41
|
+
developerRefusal,
|
|
42
|
+
environmentAddressOf,
|
|
43
|
+
platformFailure,
|
|
45
44
|
} from '@greenmind/ext-schema'
|
|
46
45
|
import type { CompiledDefinition } from '@greenmind/ext-sdk'
|
|
47
|
-
import { CLI_VERSION, VERSION_HEADER } from './constants'
|
|
46
|
+
import { CLI_VERSION, ENV_ORG, VERSION_HEADER } from './constants'
|
|
48
47
|
import {
|
|
49
|
-
CHECK_PATH,
|
|
50
48
|
type CheckAnswer,
|
|
51
49
|
type CheckIssue,
|
|
52
50
|
checkAnswer,
|
|
53
51
|
checkIssues,
|
|
54
|
-
FUNCTION_UPLOAD_PATH,
|
|
55
52
|
type FunctionUploadAnswer,
|
|
56
53
|
type FunctionUploadRequest,
|
|
57
54
|
functionUploadAnswer,
|
|
58
|
-
type PlatformFailure,
|
|
59
|
-
PUSH_PATH,
|
|
60
|
-
platformFailure,
|
|
61
55
|
type PushAnswer,
|
|
62
56
|
pushAnswer,
|
|
63
57
|
type SourceRef,
|
|
@@ -69,14 +63,14 @@ export class PlatformError extends Error {
|
|
|
69
63
|
constructor(
|
|
70
64
|
message: string,
|
|
71
65
|
readonly status: number,
|
|
72
|
-
readonly failure?:
|
|
66
|
+
readonly failure?: DeveloperRefusal,
|
|
73
67
|
) {
|
|
74
68
|
super(message)
|
|
75
69
|
}
|
|
76
70
|
|
|
77
|
-
/** The refusal's code, such as `forbidden` or `
|
|
71
|
+
/** The refusal's code, such as `forbidden` or `not-found`. */
|
|
78
72
|
get code(): string | undefined {
|
|
79
|
-
return this.failure?.
|
|
73
|
+
return this.failure?.code
|
|
80
74
|
}
|
|
81
75
|
|
|
82
76
|
/** The definitions' issues, when the platform refused them. */
|
|
@@ -101,8 +95,12 @@ export interface TokenSource {
|
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
interface CommonOptions {
|
|
104
|
-
/** The
|
|
98
|
+
/** The developer API's origin, such as `https://developer.publishing.example.test`. */
|
|
105
99
|
readonly baseUrl: string
|
|
100
|
+
/** The handle of the org whose environments the calls name; every environment's call needs one. */
|
|
101
|
+
readonly org?: string
|
|
102
|
+
/** The environment a call that names none is for: the one `--env` named, say. */
|
|
103
|
+
readonly appKey?: string
|
|
106
104
|
/** Replaced in tests; defaults to the global `fetch`. */
|
|
107
105
|
readonly fetch?: typeof fetch
|
|
108
106
|
/** Sent as `x-gm-cli-version`; the package's own version unless a test says otherwise. */
|
|
@@ -112,11 +110,14 @@ interface CommonOptions {
|
|
|
112
110
|
export type PlatformClientOptions = CommonOptions &
|
|
113
111
|
(
|
|
114
112
|
| {
|
|
115
|
-
/**
|
|
116
|
-
|
|
113
|
+
/**
|
|
114
|
+
* An org key, held by the platform to its scope and permissions in each environment a call
|
|
115
|
+
* names: `edit_config` to push, upload, seed or switch flows, `view_config` to check.
|
|
116
|
+
*/
|
|
117
|
+
readonly orgKey: string
|
|
117
118
|
readonly tokens?: undefined
|
|
118
119
|
}
|
|
119
|
-
| { readonly tokens: TokenSource; readonly
|
|
120
|
+
| { readonly tokens: TokenSource; readonly orgKey?: undefined }
|
|
120
121
|
)
|
|
121
122
|
|
|
122
123
|
interface DefinitionsBody {
|
|
@@ -134,10 +135,14 @@ type Body =
|
|
|
134
135
|
| FunctionUploadRequest
|
|
135
136
|
| ConfigDefaultsRequest
|
|
136
137
|
| FlowSwitchRequest
|
|
137
|
-
|
|
|
138
|
-
| PublishKeyCreateRequest
|
|
138
|
+
| EventsReplayRequest
|
|
139
139
|
| FunctionRuntimeSetRequest
|
|
140
140
|
| CollectionStorageSetRequest
|
|
141
|
+
| KeyCreateRequest
|
|
142
|
+
| KeyUpdateRequest
|
|
143
|
+
| PoolCreateRequestWire
|
|
144
|
+
| PoolSettingsWire
|
|
145
|
+
| JobEnqueueRequest
|
|
141
146
|
| RequestBody
|
|
142
147
|
|
|
143
148
|
/** A body for `request`: one of the wire's request shapes, which are plain JSON. */
|
|
@@ -158,27 +163,34 @@ function parseJson(text: string): Json | undefined {
|
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
/**
|
|
167
|
+
* A refusal in the developer API's `{ code, message, retryable }` form, or in the platform's
|
|
168
|
+
* `{ error, message }` form, said the developer API's way; undefined for an answer that is
|
|
169
|
+
* neither.
|
|
170
|
+
*/
|
|
171
|
+
function refusalOf(got: Exchange): DeveloperRefusal | undefined {
|
|
172
|
+
const developer = parserOf(developerRefusal).safeParse(got.json)
|
|
173
|
+
if (developer.success) return developer.data
|
|
174
|
+
const platform = parserOf(platformFailure).safeParse(got.json)
|
|
175
|
+
if (!platform.success) return undefined
|
|
176
|
+
const { error, message, details } = platform.data
|
|
177
|
+
return { code: error, message, retryable: got.status === 503, details }
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
/**
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
return `${path}?${new URLSearchParams({ [SETUP_APP_KEY_PARAM]: appKey }).toString()}`
|
|
180
|
+
/** The code of a refusal, if the answer is one. */
|
|
181
|
+
function refusalCodeOf(got: Exchange): string | undefined {
|
|
182
|
+
return refusalOf(got)?.code
|
|
171
183
|
}
|
|
172
184
|
|
|
173
185
|
/**
|
|
174
|
-
* What a platform says about signing in to it (`
|
|
175
|
-
* anybody has one. Throws a `PlatformError` where it answers anything else.
|
|
186
|
+
* What a platform says about signing in to it (`DEVELOPER_CLI_PATH`), asked with no credential
|
|
187
|
+
* before anybody has one. Throws a `PlatformError` where it answers anything else.
|
|
176
188
|
*/
|
|
177
189
|
export async function readToolDiscovery(
|
|
178
190
|
platformUrl: string,
|
|
179
191
|
send: typeof fetch = fetch,
|
|
180
192
|
): Promise<ExtToolDiscovery> {
|
|
181
|
-
const url = `${platformUrl.replace(/\/+$/, '')}${
|
|
193
|
+
const url = `${platformUrl.replace(/\/+$/, '')}${DEVELOPER_CLI_PATH}`
|
|
182
194
|
let response: Response
|
|
183
195
|
try {
|
|
184
196
|
response = await send(url, {
|
|
@@ -202,19 +214,23 @@ export async function readToolDiscovery(
|
|
|
202
214
|
}
|
|
203
215
|
|
|
204
216
|
/**
|
|
205
|
-
* Calls the
|
|
217
|
+
* Calls the developer API with an org key or as a signed-in person, and parses every answer with
|
|
206
218
|
* the shape `@greenmind/ext-schema` gives it. A refusal becomes a `PlatformError` naming its code.
|
|
207
219
|
*/
|
|
208
220
|
export class PlatformClient {
|
|
209
221
|
private readonly base: string
|
|
210
|
-
private readonly
|
|
222
|
+
private readonly org?: string
|
|
223
|
+
private readonly appKey?: string
|
|
224
|
+
private readonly orgKey?: string
|
|
211
225
|
private readonly tokens?: TokenSource
|
|
212
226
|
private readonly send: typeof fetch
|
|
213
227
|
private readonly version: string
|
|
214
228
|
|
|
215
229
|
constructor(options: PlatformClientOptions) {
|
|
216
230
|
this.base = options.baseUrl.replace(/\/+$/, '')
|
|
217
|
-
this.
|
|
231
|
+
this.org = options.org
|
|
232
|
+
this.appKey = options.appKey
|
|
233
|
+
this.orgKey = options.orgKey
|
|
218
234
|
this.tokens = options.tokens
|
|
219
235
|
this.send = options.fetch ?? fetch
|
|
220
236
|
this.version = options.cliVersion ?? CLI_VERSION
|
|
@@ -222,16 +238,22 @@ export class PlatformClient {
|
|
|
222
238
|
|
|
223
239
|
/** A client with this one's credential for another GreenMind service, at `baseUrl`. */
|
|
224
240
|
at(baseUrl: string): PlatformClient {
|
|
225
|
-
const common = {
|
|
241
|
+
const common = {
|
|
242
|
+
baseUrl,
|
|
243
|
+
org: this.org,
|
|
244
|
+
appKey: this.appKey,
|
|
245
|
+
fetch: this.send,
|
|
246
|
+
cliVersion: this.version,
|
|
247
|
+
}
|
|
226
248
|
if (this.tokens) return new PlatformClient({ ...common, tokens: this.tokens })
|
|
227
|
-
return new PlatformClient({ ...common,
|
|
249
|
+
return new PlatformClient({ ...common, orgKey: this.orgKey ?? '' })
|
|
228
250
|
}
|
|
229
251
|
|
|
230
252
|
/**
|
|
231
253
|
* Any route, for commands this client has no method of its own for: the answer parsed with
|
|
232
254
|
* `answer`, a refusal a `PlatformError`, and a refused sign-in renewed once, as every call is.
|
|
233
255
|
*/
|
|
234
|
-
request<T>(method: string, path: string, body:
|
|
256
|
+
request<T>(method: string, path: string, body: Body | undefined, answer: Schema<T>) {
|
|
235
257
|
return this.call(method, path, body, answer)
|
|
236
258
|
}
|
|
237
259
|
|
|
@@ -246,27 +268,34 @@ export class PlatformClient {
|
|
|
246
268
|
}
|
|
247
269
|
|
|
248
270
|
/**
|
|
249
|
-
* What the environment's validation says of these definitions, and which environment it is.
|
|
250
|
-
*
|
|
271
|
+
* What the environment's validation says of these definitions, and which environment it is.
|
|
272
|
+
* `appKey` names the environment, or the client's own when left out, as for every call.
|
|
251
273
|
*/
|
|
252
274
|
check(definitions: readonly CompiledDefinition[], appKey?: string): Promise<CheckAnswer> {
|
|
253
|
-
return this.call(
|
|
275
|
+
return this.call(
|
|
276
|
+
'POST',
|
|
277
|
+
this.pathOf(appKey, developerPaths.definitionsCheck),
|
|
278
|
+
{ definitions },
|
|
279
|
+
checkAnswer,
|
|
280
|
+
)
|
|
254
281
|
}
|
|
255
282
|
|
|
256
283
|
/**
|
|
257
284
|
* Makes each definition a new version in the environment, unless it already holds that hash; with
|
|
258
|
-
* `live`, then makes each pushed version live
|
|
285
|
+
* `live`, then makes each pushed version live, and with `retire` too, takes the flows and
|
|
286
|
+
* schedules an earlier push made live and this one leaves out off the live set.
|
|
259
287
|
*/
|
|
260
288
|
push(
|
|
261
289
|
definitions: readonly CompiledDefinition[],
|
|
262
290
|
source?: SourceRef,
|
|
263
291
|
live?: boolean,
|
|
264
292
|
appKey?: string,
|
|
293
|
+
retire?: boolean,
|
|
265
294
|
): Promise<PushAnswer> {
|
|
266
295
|
return this.call(
|
|
267
296
|
'POST',
|
|
268
|
-
this.
|
|
269
|
-
{ definitions, source, live },
|
|
297
|
+
this.pathOf(appKey, developerPaths.definitions),
|
|
298
|
+
{ definitions, source, live, ...(retire && { retire }) },
|
|
270
299
|
pushAnswer,
|
|
271
300
|
)
|
|
272
301
|
}
|
|
@@ -275,92 +304,111 @@ export class PlatformClient {
|
|
|
275
304
|
upload(body: FunctionUploadRequest, appKey?: string): Promise<FunctionUploadAnswer> {
|
|
276
305
|
return this.call(
|
|
277
306
|
'POST',
|
|
278
|
-
this.
|
|
307
|
+
this.pathOf(appKey, developerPaths.functions),
|
|
279
308
|
body,
|
|
280
309
|
functionUploadAnswer,
|
|
281
310
|
)
|
|
282
311
|
}
|
|
283
312
|
|
|
284
313
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
314
|
+
* An environment's route on the developer API. The address names the org, the project and the
|
|
315
|
+
* environment, so every call needs an org and an environment, the call's or the client's own.
|
|
287
316
|
*/
|
|
288
|
-
private
|
|
289
|
-
|
|
317
|
+
private pathOf(
|
|
318
|
+
appKey: string | undefined,
|
|
319
|
+
route: (environment: DeveloperEnvironment) => string,
|
|
320
|
+
): string {
|
|
321
|
+
return route(this.environmentOf(appKey))
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** The address of `appKey`, or of the client's own environment, in the client's org. */
|
|
325
|
+
environmentOf(appKey?: string): DeveloperEnvironment {
|
|
326
|
+
const named = appKey ?? this.appKey
|
|
327
|
+
if (named === undefined) {
|
|
328
|
+
throw new PlatformError('Name the environment with --env <app key>.', 400)
|
|
329
|
+
}
|
|
330
|
+
return environmentAddressOf({ org: this.orgHandle(), appKey: named })
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** The org the calls name; refused when none was given. */
|
|
334
|
+
orgHandle(): string {
|
|
335
|
+
if (!this.org) {
|
|
290
336
|
throw new PlatformError(
|
|
291
|
-
|
|
337
|
+
`Name the organisation the environment is in with --org <handle> or ${ENV_ORG}.`,
|
|
292
338
|
400,
|
|
293
339
|
)
|
|
294
340
|
}
|
|
295
|
-
return
|
|
341
|
+
return this.org
|
|
296
342
|
}
|
|
297
343
|
|
|
298
|
-
/** Every environment the person may read. */
|
|
299
|
-
listEnvironments(): Promise<EnvironmentListAnswer> {
|
|
300
|
-
return this.call(
|
|
344
|
+
/** Every environment of `project` the person may read. */
|
|
345
|
+
listEnvironments(project: string): Promise<EnvironmentListAnswer> {
|
|
346
|
+
return this.call(
|
|
347
|
+
'GET',
|
|
348
|
+
developerPaths.apps({ org: this.orgHandle(), project }),
|
|
349
|
+
undefined,
|
|
350
|
+
environmentListAnswer,
|
|
351
|
+
)
|
|
301
352
|
}
|
|
302
353
|
|
|
303
354
|
environmentStatus(appKey: string): Promise<EnvironmentStatus> {
|
|
304
|
-
return this.call(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
createServerKey(appKey: string, name: string): Promise<ServerKeyCreated> {
|
|
312
|
-
return this.call('POST', environmentPaths.serverKeys(appKey), { name }, serverKeyCreated)
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async revokeServerKey(appKey: string, keyId: string): Promise<void> {
|
|
316
|
-
await this.callNoContent('DELETE', environmentPaths.serverKey(appKey, keyId))
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
listPublishKeys(appKey: string): Promise<PublishKeyListAnswer> {
|
|
320
|
-
return this.call('GET', environmentPaths.publishKeys(appKey), undefined, publishKeyListAnswer)
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
createPublishKey(appKey: string, label: string): Promise<PublishKeyCreated> {
|
|
324
|
-
return this.call('POST', environmentPaths.publishKeys(appKey), { label }, publishKeyCreated)
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async revokePublishKey(appKey: string, keyId: string): Promise<void> {
|
|
328
|
-
await this.callNoContent('DELETE', environmentPaths.publishKey(appKey, keyId))
|
|
355
|
+
return this.call(
|
|
356
|
+
'GET',
|
|
357
|
+
this.pathOf(appKey, developerPaths.environment),
|
|
358
|
+
undefined,
|
|
359
|
+
environmentStatus,
|
|
360
|
+
)
|
|
329
361
|
}
|
|
330
362
|
|
|
331
|
-
/**
|
|
332
|
-
* Gives the environment each value it lacks; one it holds is left as it is. A signed-in person
|
|
333
|
-
* names the environment; a publish key needs none, and one it names must be its own.
|
|
334
|
-
*/
|
|
363
|
+
/** Gives the environment each value it lacks; one it holds is left as it is. */
|
|
335
364
|
seedConfigDefaults(
|
|
336
365
|
values: readonly SeededValue[],
|
|
337
366
|
appKey?: string,
|
|
338
367
|
): Promise<ConfigDefaultsAnswer> {
|
|
339
368
|
return this.call(
|
|
340
369
|
'POST',
|
|
341
|
-
|
|
370
|
+
this.pathOf(appKey, developerPaths.configDefaults),
|
|
342
371
|
{ values },
|
|
343
372
|
configDefaultsAnswer,
|
|
344
373
|
)
|
|
345
374
|
}
|
|
346
375
|
|
|
347
|
-
/** As `seedConfigDefaults`, a signed-in person names the environment. */
|
|
348
376
|
switchFlows(
|
|
349
377
|
flows: readonly { readonly key: string; readonly enabled: boolean }[],
|
|
350
378
|
appKey?: string,
|
|
351
379
|
): Promise<FlowSwitchAnswer> {
|
|
352
|
-
return this.call(
|
|
380
|
+
return this.call(
|
|
381
|
+
'PATCH',
|
|
382
|
+
this.pathOf(appKey, developerPaths.flows),
|
|
383
|
+
{ flows },
|
|
384
|
+
flowSwitchAnswer,
|
|
385
|
+
)
|
|
353
386
|
}
|
|
354
387
|
|
|
355
|
-
/**
|
|
388
|
+
/** One call of a replay of kept events into a flow; send `next` back as `after` to carry on. */
|
|
389
|
+
replayEvents(request: EventsReplayRequest, appKey?: string): Promise<EventsReplayAnswer> {
|
|
390
|
+
return this.call(
|
|
391
|
+
'POST',
|
|
392
|
+
this.pathOf(appKey, developerPaths.eventsReplay),
|
|
393
|
+
request,
|
|
394
|
+
eventsReplayAnswer,
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** Whether this client acts as a signed-in person rather than with an org key. */
|
|
356
399
|
get signedIn(): boolean {
|
|
357
400
|
return this.tokens !== undefined
|
|
358
401
|
}
|
|
359
402
|
|
|
403
|
+
/** The org handle the calls name, if one was given. */
|
|
404
|
+
get orgName(): string | undefined {
|
|
405
|
+
return this.org
|
|
406
|
+
}
|
|
407
|
+
|
|
360
408
|
functionRuntime(appKey: string): Promise<FunctionRuntimeAnswer> {
|
|
361
409
|
return this.call(
|
|
362
410
|
'GET',
|
|
363
|
-
|
|
411
|
+
this.pathOf(appKey, developerPaths.functionsRuntime),
|
|
364
412
|
undefined,
|
|
365
413
|
functionRuntimeAnswer,
|
|
366
414
|
)
|
|
@@ -373,7 +421,7 @@ export class PlatformClient {
|
|
|
373
421
|
): Promise<FunctionRuntimeAnswer> {
|
|
374
422
|
return this.call(
|
|
375
423
|
'PUT',
|
|
376
|
-
|
|
424
|
+
this.pathOf(appKey, developerPaths.functionsRuntime),
|
|
377
425
|
{ runtime },
|
|
378
426
|
functionRuntimeAnswer,
|
|
379
427
|
)
|
|
@@ -382,7 +430,7 @@ export class PlatformClient {
|
|
|
382
430
|
collectionStorage(appKey: string): Promise<CollectionStorageAnswer> {
|
|
383
431
|
return this.call(
|
|
384
432
|
'GET',
|
|
385
|
-
|
|
433
|
+
this.pathOf(appKey, developerPaths.collectionsStorage),
|
|
386
434
|
undefined,
|
|
387
435
|
collectionStorageAnswer,
|
|
388
436
|
)
|
|
@@ -395,7 +443,7 @@ export class PlatformClient {
|
|
|
395
443
|
): Promise<CollectionStorageAnswer> {
|
|
396
444
|
return this.call(
|
|
397
445
|
'PUT',
|
|
398
|
-
|
|
446
|
+
this.pathOf(appKey, developerPaths.collectionsStorage),
|
|
399
447
|
{ default: mode },
|
|
400
448
|
collectionStorageAnswer,
|
|
401
449
|
)
|
|
@@ -405,7 +453,7 @@ export class PlatformClient {
|
|
|
405
453
|
checkConnector(appKey: string, connection: string): Promise<ConnectorCheckAnswer> {
|
|
406
454
|
return this.call(
|
|
407
455
|
'POST',
|
|
408
|
-
|
|
456
|
+
this.pathOf(appKey, (environment) => developerPaths.connectionCheck(environment, connection)),
|
|
409
457
|
{},
|
|
410
458
|
connectorCheckAnswer,
|
|
411
459
|
)
|
|
@@ -448,7 +496,7 @@ export class PlatformClient {
|
|
|
448
496
|
* loops. A 401 that is not the platform's refusal of the sign-in (a proxy's, say) spends nothing.
|
|
449
497
|
*/
|
|
450
498
|
private async exchange(method: string, path: string, body: Body | undefined): Promise<Exchange> {
|
|
451
|
-
const token = this.tokens ? await this.tokens.accessToken() : this.
|
|
499
|
+
const token = this.tokens ? await this.tokens.accessToken() : this.orgKey
|
|
452
500
|
const first = await this.once(method, path, body, token)
|
|
453
501
|
if (first.status !== 401 || !this.tokens || !token) return first
|
|
454
502
|
if (refusalCodeOf(first) !== 'unauthorized') return first
|
|
@@ -477,8 +525,7 @@ export class PlatformClient {
|
|
|
477
525
|
}
|
|
478
526
|
|
|
479
527
|
private refusal(got: Exchange): PlatformError {
|
|
480
|
-
const
|
|
481
|
-
const details = failure.success ? failure.data : undefined
|
|
528
|
+
const details = refusalOf(got)
|
|
482
529
|
// Only the platform's own refusal naming the version it needs: a 426 from anything in between
|
|
483
530
|
// (a proxy asking for another protocol) is not about this tool's version.
|
|
484
531
|
const minimum = minimumVersion.safeParse(details?.details?.['minimum'])
|
|
@@ -489,27 +536,14 @@ export class PlatformClient {
|
|
|
489
536
|
details,
|
|
490
537
|
)
|
|
491
538
|
}
|
|
492
|
-
if (got.status === 401 && this.tokens && details?.
|
|
539
|
+
if (got.status === 401 && this.tokens && details?.code === 'unauthorized') {
|
|
493
540
|
return new PlatformError(
|
|
494
541
|
'The platform did not accept your sign-in. Run `gm login` to sign in again.',
|
|
495
542
|
got.status,
|
|
496
543
|
details,
|
|
497
544
|
)
|
|
498
545
|
}
|
|
499
|
-
if (
|
|
500
|
-
|
|
501
|
-
'Your sign-in could not be checked with GreenMind just now, and nothing was changed. Try again in a moment.',
|
|
502
|
-
got.status,
|
|
503
|
-
details,
|
|
504
|
-
)
|
|
505
|
-
}
|
|
506
|
-
if (!failure.success) {
|
|
507
|
-
return new PlatformError(`The platform answered ${got.status}.`, got.status)
|
|
508
|
-
}
|
|
509
|
-
return new PlatformError(
|
|
510
|
-
`${failure.data.error}: ${failure.data.message}`,
|
|
511
|
-
got.status,
|
|
512
|
-
failure.data,
|
|
513
|
-
)
|
|
546
|
+
if (!details) return new PlatformError(`The platform answered ${got.status}.`, got.status)
|
|
547
|
+
return new PlatformError(`${details.code}: ${details.message}`, got.status, details)
|
|
514
548
|
}
|
|
515
549
|
}
|