foobara-typescript-remote-command-generator 0.0.12 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1104e4a22fbc43acc6eb9224e9e4a2e66c50a9de682ec7433869852d16fa5066
4
- data.tar.gz: a3ac71e2f721f84fc3b939ab1bee3022c2db37aa69c6a315557e75470e5e0bcc
3
+ metadata.gz: d21e54189d68b7b93ec70507e3b0fa433a4a8a380fbbd4e1df92031aea3310d2
4
+ data.tar.gz: a465fae839c9f38e29908ef3145b9d4b4c0d1de4e37d004893e54653ee783c15
5
5
  SHA512:
6
- metadata.gz: bfc502a91885feb02d56384ee7add5b7740dd22159b33eb2dd844283be6f8e77ed989a494218d72f2ce98d540a335a5fafef126e7770e0b33c9e2eed32a43511
7
- data.tar.gz: 2f6a3fe9fa23fcd90014030b037f0e0eafb90b1011a795ac9755c0b9cbde88ea7bcfb56500254eb5b087bab1ec074b189887efaa94aaffbf25d17cd5158b24aa
6
+ metadata.gz: b4794d89263b06204d56d09a89ac110f5382e1f1d3fdc914e2fc9a2534c8b16dcec608205643f4fcd9c69ef9ec918610e3d803e3eef6663be3356dfd70b1baba
7
+ data.tar.gz: d4d2cd4b56df9f690e074695b07bda3dd7f5eb0499bf4060c8854225fb233389f75938d65a1a3134c83255988d660c288bdc8785001a2cc79c598b4397a54b00
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## [0.0.14] - 2025-03-29
2
+
3
+ - Send credentials: 'include'
4
+
5
+ ## [0.0.13] - 2025-03-17
6
+
7
+ - Fix bug incorrectly generating model typescript for detached entities
8
+ - Fix bug preventing Loaded/Unloaded entity import from being destructured properly
9
+ - Handle errors with prefixes
10
+ - Include custom types and models in error generator dependencies
11
+ - Fix bug preventing allow_nil from having an effect
12
+
1
13
  ## [0.0.12] - 2025-03-02
2
14
 
3
15
  - Add ability to ask RemoteCommand for its state and outcome
@@ -9,17 +9,17 @@ module Foobara
9
9
  def target_path
10
10
  p = parent
11
11
 
12
- basename = "#{error_name}.ts"
12
+ basename = "#{error_name}.ts".split("::")
13
13
 
14
14
  case parent
15
15
  when OrganizationGenerator, DomainGenerator, CommandGenerator
16
- [*p.target_dir, "errors", basename]
16
+ [*p.target_dir, "errors", *basename]
17
17
  when nil
18
18
  # :nocov:
19
19
  raise "Expected #{error_name} to have a parent but it did not"
20
20
  # :nocov:
21
21
  else
22
- [*p.target_dir, basename]
22
+ [*p.target_dir, *basename]
23
23
  end
24
24
  end
25
25
 
@@ -50,8 +50,7 @@ module Foobara
50
50
  end
51
51
 
52
52
  def dependencies
53
- # Why don't we need models and custom types?
54
- types_depended_on.select(&:detached_entity?)
53
+ types_depended_on.select { |type| type.detached_entity? || type.custom? || type.model? }
55
54
  end
56
55
 
57
56
  def ts_type_full_path
@@ -21,6 +21,10 @@ module Foobara
21
21
  *prefix, name = super
22
22
  [*prefix, "Loaded#{name}"]
23
23
  end
24
+
25
+ def import_destructure
26
+ "{ Loaded#{scoped_short_name} }"
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -76,7 +76,7 @@ module Foobara
76
76
  # :nocov:
77
77
  end
78
78
 
79
- if declaration_data["allows_nil"]
79
+ if declaration_data["allow_nil"]
80
80
  # TODO: add a custom type to the fixture manifest that includes allows_nil
81
81
  # :nocov:
82
82
  guts += " | undefined"
@@ -48,7 +48,7 @@ module Foobara
48
48
  Services::OrganizationConfigGenerator,
49
49
  Services::OrganizationManifestGenerator
50
50
  ]
51
- when Manifest::Entity
51
+ when Manifest::Entity, Manifest::DetachedEntity
52
52
  [
53
53
  Services::EntityGenerator,
54
54
  Services::EntityVariantsGenerator,
@@ -14,6 +14,10 @@ module Foobara
14
14
  *prefix, name = super
15
15
  [*prefix, "Unloaded#{name}"]
16
16
  end
17
+
18
+ def import_destructure
19
+ "{ Unloaded#{scoped_short_name} }"
20
+ end
17
21
  end
18
22
  end
19
23
  end
@@ -4,5 +4,5 @@ import <%= dependency_root.import_destructure %> from "<%= path_to_root %><%= de
4
4
 
5
5
  import { <%= error_base_class %> } from "<%= path_to_root %>base/Error"
6
6
 
7
- export class <%= error_name %> extends <%= error_base_class %><<%= context_ts_type %>> {
7
+ export class <%= short_error_name %> extends <%= error_base_class %><<%= context_ts_type %>> {
8
8
  }
@@ -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.fullCommandName}`
84
+ const url = `${this.urlBase}/run/${this.commandPath}`
78
85
 
79
- this.commandState = 'executing'
80
- const response = await fetch(url, {
86
+ const bearerToken = accessTokens[this.urlBase]
87
+
88
+ const requestParams: RequestInit = {
81
89
  method: 'POST',
82
- headers: { 'Content-Type': 'application/json' },
83
- body: JSON.stringify(this.inputs)
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.12
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-02 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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.3
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: []