Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
sim/scripts/generate-deployment-config.ts at main · simstudioai/sim · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
simstudioai
sim
Repository navigation
Code
Issues
128
(128)
Pull requests
217
(217)
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
sim
/
scripts
/
generate-deployment-config.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
118 lines (108 loc) · 4.33 KB
main
Breadcrumbs
sim
/
scripts
/
generate-deployment-config.ts
Copy path
Top
File metadata and controls
Code
Blame
118 lines (108 loc) · 4.33 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bun
/**
* Generates deployment facts from the canonical OAuth registry.
*
* The setup package cannot import the application registry at runtime, so it
* consumes this checked-in projection instead. Deployment policy does not
* belong here; special availability rules remain handwritten in
* `packages/deployment-config/src/service-account-metadata.ts`.
*
* Usage:
* bun run scripts/generate-deployment-config.ts
* bun run scripts/generate-deployment-config.ts --check
*/
import
{
readFile
,
writeFile
}
from
'node:fs/promises'
import
{
dirname
,
resolve
}
from
'node:path'
import
{
fileURLToPath
}
from
'node:url'
import
{
getAllOAuthServices
}
from
'../apps/sim/lib/oauth/utils'
import
{
INTEGRATION_METADATA
}
from
'../packages/deployment-config/src/integration-metadata'
import
{
formatGeneratedSource
}
from
'./format-generated-source'
const
SCRIPT_DIR
=
dirname
(
fileURLToPath
(
import
.
meta
.
url
)
)
const
ROOT
=
resolve
(
SCRIPT_DIR
,
'..'
)
const
OUTPUT_PATH
=
resolve
(
ROOT
,
'packages/deployment-config/src/service-account-providers.generated.ts'
)
const
CHECK_MODE
=
process
.
argv
.
includes
(
'--check'
)
interface
CanonicalOAuthDeploymentFacts
{
credentialConfiguredOAuthServiceIds
:
readonly
string
[
]
serviceAccountProviders
:
ReadonlyMap
<
string
,
string
>
}
function
buildOAuthDeploymentFacts
(
)
:
CanonicalOAuthDeploymentFacts
{
const
canonicalServices
=
new
Map
<
string
,
{
credentialConfigured
:
boolean
;
serviceAccountProviderId
?:
string
}
>
(
)
for
(
const
service
of
getAllOAuthServices
(
)
)
{
if
(
canonicalServices
.
has
(
service
.
serviceId
)
)
{
throw
new
Error
(
`Duplicate canonical OAuth service id:
${
service
.
serviceId
}
`
)
}
canonicalServices
.
set
(
service
.
serviceId
,
{
credentialConfigured
:
Boolean
(
service
.
clientConfiguration
)
,
serviceAccountProviderId
:
service
.
serviceAccountProviderId
,
}
)
}
const
catalogServiceIds
=
new
Set
<
string
>
(
)
for
(
const
integration
of
INTEGRATION_METADATA
)
{
if
(
integration
.
authType
!==
'oauth'
)
continue
if
(
!
integration
.
oauthServiceId
)
{
throw
new
Error
(
'Generated integration catalog contains an OAuth entry without oauthServiceId'
)
}
catalogServiceIds
.
add
(
integration
.
oauthServiceId
)
}
const
providers
=
new
Map
<
string
,
string
>
(
)
const
credentialConfiguredOAuthServiceIds
:
string
[
]
=
[
]
for
(
const
serviceId
of
[
...
catalogServiceIds
]
.
sort
(
)
)
{
if
(
!
canonicalServices
.
has
(
serviceId
)
)
{
throw
new
Error
(
`Integration catalog references unknown OAuth service:
${
serviceId
}
`
)
}
const
service
=
canonicalServices
.
get
(
serviceId
)
if
(
service
?.
credentialConfigured
)
credentialConfiguredOAuthServiceIds
.
push
(
serviceId
)
const
providerId
=
service
?.
serviceAccountProviderId
if
(
providerId
)
providers
.
set
(
serviceId
,
providerId
)
}
return
{
credentialConfiguredOAuthServiceIds
,
serviceAccountProviders
:
providers
}
}
function
renderOAuthDeploymentFacts
(
facts
:
CanonicalOAuthDeploymentFacts
)
:
string
{
const
quote
=
(
value
:
string
)
=>
`'
${
value
.
replace
(
/
\\
/
g
,
'\\\\'
)
.
replace
(
/
'
/
g
,
"\\'"
)
}
'`
const
entries
=
[
...
facts
.
serviceAccountProviders
]
.
map
(
(
[
serviceId
,
providerId
]
)
=>
`
${
/
^
[
A
-
Z
a
-
z
_
$
]
[
\w
$
]
*
$
/
.
test
(
serviceId
)
?
serviceId
:
quote
(
serviceId
)
}
:
${
quote
(
providerId
)
}
,`
)
.
join
(
'\n'
)
const
credentialConfiguredServiceIds
=
facts
.
credentialConfiguredOAuthServiceIds
.
map
(
(
serviceId
)
=>
`
${
quote
(
serviceId
)
}
,`
)
.
join
(
'\n'
)
return
`/**
* Generated by \`bun run generate:deployment-config\` from the canonical OAuth
* registry and integration catalog. Do not edit this file directly.
*/
export const SERVICE_ACCOUNT_PROVIDER_BY_OAUTH_SERVICE_ID = {
${
entries
}
} as const
/** OAuth services whose users supply app credentials when connecting an account. */
export const CREDENTIAL_CONFIGURED_OAUTH_SERVICE_IDS = [
${
credentialConfiguredServiceIds
}
] as const
`
}
const
generated
=
formatGeneratedSource
(
renderOAuthDeploymentFacts
(
buildOAuthDeploymentFacts
(
)
)
,
OUTPUT_PATH
,
ROOT
)
if
(
CHECK_MODE
)
{
const
current
=
await
readFile
(
OUTPUT_PATH
,
'utf8'
)
.
catch
(
(
)
=>
''
)
if
(
current
!==
generated
)
{
throw
new
Error
(
'Deployment config is stale. Run `bun run generate:deployment-config` and commit the result.'
)
}
process
.
stdout
.
write
(
'Deployment config is current.\n'
)
}
else
{
await
writeFile
(
OUTPUT_PATH
,
generated
)
process
.
stdout
.
write
(
`Generated
${
OUTPUT_PATH
}
\n`
)
}
You can’t perform that action at this time.