Skip to content

Commit 883934f

Browse files
razor-xseambot
andauthored
feat: Use smith and blueprint to generate SDK (#341)
* Generate routes with blueprint and smith * ci: Generate code --------- Co-authored-by: Seam Bot <[email protected]>
1 parent 61df2b3 commit 883934f

File tree

97 files changed

+2537
-1730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2537
-1730
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
!src/**/*.d.ts
1313
!ava.config.js
1414

15+
# Codegen
16+
CODEGEN.md
17+
1518
# Build directories
1619
docs
1720
package

.prettierignore

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
# Parts of this file were adapted from
2+
# GitHub’s collection of .gitignore file templates
3+
# which are Copyright (c) 2023 GitHub, Inc.
4+
# and released under the MIT License.
5+
# For more details, visit the project page:
6+
# https://github.com/github/gitignore
7+
8+
# TypeScript build output
9+
*.d.ts
10+
*.js
11+
*.js.map
12+
!src/**/*.d.ts
13+
!ava.config.js
14+
15+
# Build directories
16+
docs
17+
package
18+
19+
# Environment versions file
20+
.versions
21+
22+
# Tern
23+
.tern-project
24+
.tern-port
25+
26+
# npm config
27+
.npmrc
28+
29+
# Temporary development files
30+
tmp
31+
32+
# Yarn lockfile (only package-lock.json supported)
33+
yarn.lock
34+
35+
# Logs
36+
logs
37+
*.log
38+
npm-debug.log*
39+
yarn-debug.log*
40+
yarn-error.log*
41+
lerna-debug.log*
42+
.pnpm-debug.log*
43+
44+
# Diagnostic reports (https://nodejs.org/api/report.html)
45+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
46+
47+
# Runtime data
48+
pids
49+
*.pid
50+
*.seed
51+
*.pid.lock
52+
53+
# Directory for instrumented libs generated by jscoverage/JSCover
54+
lib-cov
55+
56+
# Coverage directory used by tools like istanbul
57+
coverage
58+
*.lcov
59+
60+
# nyc test coverage
61+
.nyc_output
62+
63+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
64+
.grunt
65+
66+
# Bower dependency directory (https://bower.io/)
67+
bower_components
68+
69+
# node-waf configuration
70+
.lock-wscript
71+
72+
# Compiled binary addons (https://nodejs.org/api/addons.html)
73+
build/Release
74+
75+
# Dependency directories
76+
node_modules/
77+
jspm_packages/
78+
79+
# Snowpack dependency directory (https://snowpack.dev/)
80+
web_modules/
81+
82+
# TypeScript cache
83+
*.tsbuildinfo
84+
85+
# Optional npm cache directory
86+
.npm
87+
88+
# Optional eslint cache
89+
.eslintcache
90+
91+
# Optional stylelint cache
92+
.stylelintcache
93+
94+
# Microbundle cache
95+
.rpt2_cache/
96+
.rts2_cache_cjs/
97+
.rts2_cache_es/
98+
.rts2_cache_umd/
99+
100+
# Optional REPL history
101+
.node_repl_history
102+
103+
# Output of 'npm pack'
104+
*.tgz
105+
106+
# Yarn Integrity file
107+
.yarn-integrity
108+
109+
# dotenv environment variable files
110+
.env
111+
.env.development.local
112+
.env.test.local
113+
.env.production.local
114+
.env.local
115+
116+
# parcel-bundler cache (https://parceljs.org/)
117+
.cache
118+
.parcel-cache
119+
120+
# Next.js build output
121+
.next
122+
out
123+
124+
# Nuxt.js build / generate output
125+
.nuxt
126+
dist
127+
128+
# Gatsby files
129+
.cache/
130+
# Comment in the public line in if your project uses Gatsby and not Next.js
131+
# https://nextjs.org/blog/next-9-1#public-directory-support
132+
# public
133+
134+
# vuepress build output
135+
.vuepress/dist
136+
137+
# vuepress v2.x temp and cache directory
138+
.temp
139+
.cache
140+
141+
# Docusaurus cache and generated files
142+
.docusaurus
143+
144+
# Serverless directories
145+
.serverless/
146+
147+
# FuseBox cache
148+
.fusebox/
149+
150+
# DynamoDB Local files
151+
.dynamodb/
152+
153+
# TernJS port file
154+
.tern-port
155+
156+
# Stores VSCode versions used for testing VSCode extensions
157+
.vscode-test
158+
159+
# yarn v2
160+
.yarn/cache
161+
.yarn/unplugged
162+
.yarn/build-state.yml
163+
.yarn/install-state.gz
164+
.pnp.*
165+
166+
# Windows
167+
168+
# Windows thumbnail cache files
169+
Thumbs.db
170+
Thumbs.db:encryptable
171+
ehthumbs.db
172+
ehthumbs_vista.db
173+
174+
# Dump file
175+
*.stackdump
176+
177+
# Folder config file
178+
[Dd]esktop.ini
179+
180+
# Recycle Bin used on file shares
181+
$RECYCLE.BIN/
182+
183+
# Windows Installer files
184+
*.cab
185+
*.msi
186+
*.msix
187+
*.msm
188+
*.msp
189+
190+
# Windows shortcuts
191+
*.lnk
192+
193+
# macOS
194+
195+
# General
196+
.DS_Store
197+
.AppleDouble
198+
.LSOverride
199+
200+
# Icon must end with two \r
201+
Icon
202+
203+
# Thumbnails
204+
._*
205+
206+
# Files that might appear in the root of a volume
207+
.DocumentRevisions-V100
208+
.fseventsd
209+
.Spotlight-V100
210+
.TemporaryItems
211+
.Trashes
212+
.VolumeIcon.icns
213+
.com.apple.timemachine.donotpresent
214+
215+
# Directories potentially created on remote AFP share
216+
.AppleDB
217+
.AppleDesktop
218+
Network Trash Folder
219+
Temporary Items
220+
.apdisk
221+
222+
# Prettier exceptions
223+
*.hbs

codegen/content/CODEGEN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Codegen

codegen/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default null

codegen/layouts/default.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{contents}}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type {{requestTypeName}} = RouteRequest{{requestFormatSuffix}}<'{{path}}'>
2+
3+
export type {{responseTypeName}} = SetNonNullable<
4+
Required<RouteResponse<'{{path}}'>>
5+
>
6+
7+
export type {{optionsTypeName}} = {{#if returnsActionAttempt}}Pick<SeamHttpRequestOptions, 'waitForActionAttempt'>{{else}}never{{/if}}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{methodName}}(
2+
{{methodParamName}}{{#if isOptionalParamsOk}}?{{/if}}: {{requestTypeName}},
3+
{{#if hasOptions}}options: {{optionsTypeName}} = {},{{/if}}
4+
): SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>
5+
{
6+
return new SeamHttpRequest(this, {
7+
pathname: '{{path}}',
8+
method: '{{method}}',
9+
{{requestFormat}}: {{methodParamName}},
10+
responseKey: {{#if returnsVoid}}undefined{{else}}'{{responseKey}}'{{/if}},
11+
{{#if hasOptions}}options,{{/if}}
12+
})
13+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
client: Client
2+
readonly defaults: Required<SeamHttpRequestOptions>
3+
readonly ltsVersion = seamApiLtsVersion
4+
static ltsVersion = seamApiLtsVersion
5+
6+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
7+
const options = parseOptions(apiKeyOrOptions)
8+
this.client = 'client' in options ? options.client : createClient(options)
9+
this.defaults = limitToSeamHttpRequestOptions(options)
10+
}
11+
12+
static fromClient(
13+
client: SeamHttpOptionsWithClient['client'],
14+
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
15+
): {{className}} {
16+
const constructorOptions = { ...options, client }
17+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
18+
throw new SeamHttpInvalidOptionsError('Missing client')
19+
}
20+
return new {{className}}(constructorOptions)
21+
}
22+
23+
static fromApiKey(
24+
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
25+
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
26+
): {{className}} {
27+
const constructorOptions = { ...options, apiKey }
28+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
29+
throw new SeamHttpInvalidOptionsError('Missing apiKey')
30+
}
31+
return new {{className}}(constructorOptions)
32+
}
33+
34+
static fromClientSessionToken(
35+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
36+
options: Omit<
37+
SeamHttpOptionsWithClientSessionToken,
38+
'clientSessionToken'
39+
> = {},
40+
): {{className}} {
41+
const constructorOptions = { ...options, clientSessionToken }
42+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
43+
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
44+
}
45+
return new {{className}}(constructorOptions)
46+
}
47+
48+
static async fromPublishableKey(
49+
publishableKey: string,
50+
userIdentifierKey: string,
51+
options: SeamHttpFromPublishableKeyOptions = {},
52+
): Promise<{{className}}> {
53+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
54+
const clientOptions = parseOptions({ ...options, publishableKey })
55+
if (isSeamHttpOptionsWithClient(clientOptions)) {
56+
throw new SeamHttpInvalidOptionsError(
57+
'The client option cannot be used with {{className}}.fromPublishableKey',
58+
)
59+
}
60+
const client = createClient(clientOptions)
61+
const clientSessions = SeamHttpClientSessions.fromClient(client)
62+
const { token } = await clientSessions.getOrCreate({
63+
user_identifier_key: userIdentifierKey,
64+
})
65+
return {{className}}.fromClientSessionToken(token, options)
66+
}
67+
68+
static fromConsoleSessionToken(
69+
consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
70+
workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
71+
options: Omit<
72+
SeamHttpOptionsWithConsoleSessionToken,
73+
'consoleSessionToken' | 'workspaceId'
74+
> = {},
75+
): {{className}} {
76+
const constructorOptions = { ...options, consoleSessionToken, workspaceId }
77+
if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
78+
throw new SeamHttpInvalidOptionsError(
79+
'Missing consoleSessionToken or workspaceId',
80+
)
81+
}
82+
return new {{className}}(constructorOptions)
83+
}
84+
85+
static fromPersonalAccessToken(
86+
personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
87+
workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
88+
options: Omit<
89+
SeamHttpOptionsWithPersonalAccessToken,
90+
'personalAccessToken' | 'workspaceId'
91+
> = {},
92+
): {{className}} {
93+
const constructorOptions = { ...options, personalAccessToken, workspaceId }
94+
if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
95+
throw new SeamHttpInvalidOptionsError(
96+
'Missing personalAccessToken or workspaceId',
97+
)
98+
}
99+
return new {{className}}(constructorOptions)
100+
}
101+
102+
createPaginator<const TResponse, const TResponseKey extends keyof TResponse>(
103+
request: SeamHttpRequest<TResponse, TResponseKey>,
104+
): SeamPaginator<TResponse, TResponseKey> {
105+
return new SeamPaginator<TResponse, TResponseKey>(this, request)
106+
}
107+
108+
async updateClientSessionToken(
109+
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
110+
): Promise<void> {
111+
const { headers } = this.client.defaults
112+
const authHeaders = getAuthHeadersForClientSessionToken({
113+
clientSessionToken,
114+
})
115+
for (const key of Object.keys(authHeaders)) {
116+
if (headers[key] == null) {
117+
throw new Error(
118+
'Cannot update a clientSessionToken on a client created without a clientSessionToken',
119+
)
120+
}
121+
}
122+
this.client.defaults.headers = { ...headers, ...authHeaders }
123+
const clientSessions = SeamHttpClientSessions.fromClient(this.client)
124+
await clientSessions.get()
125+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
get {{ methodName }}(): {{ className }} {
2+
return {{ className }}.fromClient(this.client, this.defaults)
3+
}

0 commit comments

Comments
 (0)