foobara-typescript-remote-command-generator 0.0.13 → 0.0.14
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/templates/base/RemoteCommand.ts +52 -7
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d21e54189d68b7b93ec70507e3b0fa433a4a8a380fbbd4e1df92031aea3310d2
|
4
|
+
data.tar.gz: a465fae839c9f38e29908ef3145b9d4b4c0d1de4e37d004893e54653ee783c15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4794d89263b06204d56d09a89ac110f5382e1f1d3fdc914e2fc9a2534c8b16dcec608205643f4fcd9c69ef9ec918610e3d803e3eef6663be3356dfd70b1baba
|
7
|
+
data.tar.gz: d4d2cd4b56df9f690e074695b07bda3dd7f5eb0499bf4060c8854225fb233389f75938d65a1a3134c83255988d660c288bdc8785001a2cc79c598b4397a54b00
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
import { type Outcome, SuccessfulOutcome, ErrorOutcome } from './Outcome'
|
2
2
|
import { type FoobaraError } from './Error'
|
3
3
|
|
4
|
-
export type commandState = 'initialized' | 'executing' | 'succeeded' | 'errored' | 'failed'
|
4
|
+
export type commandState = 'initialized' | 'executing' | 'refreshing_auth' | 'succeeded' | 'errored' | 'failed'
|
5
|
+
|
6
|
+
const accessTokens: Record<string, string> = {}
|
5
7
|
|
6
8
|
export default abstract class RemoteCommand<Inputs, Result, CommandError extends FoobaraError> {
|
7
9
|
static _urlBase: string | undefined
|
8
10
|
static commandName: string
|
9
11
|
static organizationName: string
|
10
12
|
static domainName: string
|
13
|
+
static authRequired: boolean = true // TODO: set this from generator
|
11
14
|
|
12
15
|
// TODO: make use of domain's config instead of process.env directly.
|
13
16
|
static get urlBase (): string {
|
@@ -73,19 +76,61 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
|
|
73
76
|
return (this.constructor as typeof RemoteCommand<Inputs, Result, CommandError>).fullCommandName
|
74
77
|
}
|
75
78
|
|
79
|
+
get commandPath (): string {
|
80
|
+
return this.fullCommandName.replace('::', '/')
|
81
|
+
}
|
82
|
+
|
76
83
|
async run (): Promise<Outcome<Result, CommandError>> {
|
77
|
-
const url = `${this.urlBase}/run/${this.
|
84
|
+
const url = `${this.urlBase}/run/${this.commandPath}`
|
78
85
|
|
79
|
-
|
80
|
-
|
86
|
+
const bearerToken = accessTokens[this.urlBase]
|
87
|
+
|
88
|
+
const requestParams: RequestInit = {
|
81
89
|
method: 'POST',
|
82
|
-
|
83
|
-
|
84
|
-
}
|
90
|
+
body: JSON.stringify(this.inputs),
|
91
|
+
credentials: 'include'
|
92
|
+
}
|
93
|
+
|
94
|
+
requestParams.headers = { 'Content-Type': 'application/json' }
|
95
|
+
|
96
|
+
if (bearerToken != null) {
|
97
|
+
requestParams.headers.Authorization = `Bearer ${bearerToken}`
|
98
|
+
}
|
99
|
+
|
100
|
+
this.commandState = 'executing'
|
101
|
+
let response = await fetch(url, requestParams)
|
102
|
+
|
103
|
+
if ((this.constructor as typeof RemoteCommand<Inputs, Result, CommandError>).authRequired &&
|
104
|
+
response.status === 401) {
|
105
|
+
this.commandState = 'refreshing_auth'
|
106
|
+
|
107
|
+
// TODO: in generator make this conditional
|
108
|
+
const { RefreshLogin } = await import('../Foobara/Auth')
|
109
|
+
// See if we can authenticate using the refresh token
|
110
|
+
const refreshCommand = new RefreshLogin({})
|
111
|
+
const outcome = await refreshCommand.run()
|
112
|
+
|
113
|
+
if (outcome.isSuccess()) {
|
114
|
+
const bearerToken = accessTokens[this.urlBase]
|
115
|
+
|
116
|
+
if (bearerToken != null) {
|
117
|
+
requestParams.headers.Authorization = `Bearer ${bearerToken}`
|
118
|
+
}
|
119
|
+
|
120
|
+
this.commandState = 'executing'
|
121
|
+
response = await fetch(url, requestParams)
|
122
|
+
}
|
123
|
+
}
|
85
124
|
|
86
125
|
const body = await response.json()
|
87
126
|
|
88
127
|
if (response.ok) {
|
128
|
+
const accessToken: string | null = response.headers.get('X-Access-Token')
|
129
|
+
|
130
|
+
if (accessToken != null) {
|
131
|
+
accessTokens[this.urlBase] = accessToken
|
132
|
+
}
|
133
|
+
|
89
134
|
this.commandState = 'succeeded'
|
90
135
|
this.outcome = new SuccessfulOutcome<Result, CommandError>(body)
|
91
136
|
} else if (response.status === 422) {
|
metadata
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foobara-typescript-remote-command-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Georgi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-31 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: foobara
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
|
-
- - "
|
16
|
+
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
18
|
+
version: 0.0.88
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
|
-
- - "
|
23
|
+
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version:
|
25
|
+
version: 0.0.88
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: foobara-files-generator
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
|
-
- - "
|
30
|
+
- - "~>"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 0.0.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
39
|
+
version: 0.0.1
|
40
40
|
email:
|
41
41
|
- azimux@gmail.com
|
42
42
|
executables: []
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.6.
|
137
|
+
rubygems_version: 3.6.6
|
138
138
|
specification_version: 4
|
139
139
|
summary: Generates remote commands for Typescript from a foobara manifest
|
140
140
|
test_files: []
|