Skip to content

Commit 958acdc

Browse files
razor-xseambot
andauthored
feat: Allow access to undocumented API (#349)
* Generate undocumented endpoints * Add isUndocumented to context * Add isUndocumentedApiEnabled option * ci: Generate code * Add test for undocumented flag * Fix isUndocumentedApiEnabled generation * ci: Generate code --------- Co-authored-by: Seam Bot <seambot@getseam.com>
1 parent ec2b45b commit 958acdc

File tree

84 files changed

+7259
-17
lines changed

Some content is hidden

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

84 files changed

+7259
-17
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,19 @@ const seam = new SeamHttpEndpoints()
524524
const devices = await seam['/devices/list']()
525525
```
526526

527+
#### Enable undocumented API
528+
529+
Pass the `isUndocumentedApiEnabled` option to allow using the undocumented API.
530+
This API is used internally and is not directly supported.
531+
Do not use the undocumented API in production environments.
532+
Seam is not responsible for any issues you may encounter with the undocumented API.
533+
534+
```ts
535+
import { SeamHttp } from '@seamapi/http/connect'
536+
537+
const seam = new SeamHttp({ isUndocumentedApiEnabled: true })
538+
```
539+
527540
#### Inspecting the Request
528541

529542
All client methods return an instance of `SeamHttpRequest`.

codegen/layouts/endpoints.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export class SeamHttpEndpoints {
2121
get['{{path}}'](): {{className}}['{{methodName}}']
2222
{
2323
const { client, defaults } = this
24+
{{#if isUndocumented}}
25+
if (!this.defaults.isUndocumentedApiEnabled) {
26+
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
27+
}
28+
{{/if}}
2429
return function {{functionName}} (...args: Parameters<{{className}}['{{methodName}}']>): ReturnType<{{className}}['{{methodName}}']>
2530
{
2631
const seam = {{className}}.fromClient(client, defaults)

codegen/layouts/partials/route-class-endpoint.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
{{#if hasOptions}}options: {{optionsTypeName}} = {},{{/if}}
44
): SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>
55
{
6+
{{#if isUndocumented}}
7+
if (!this.defaults.isUndocumentedApiEnabled) {
8+
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
9+
}
10+
{{/if}}
611
return new SeamHttpRequest(this, {
712
pathname: '{{path}}',
813
method: '{{method}}',

codegen/layouts/partials/route-class-methods.hbs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ static ltsVersion = seamApiLtsVersion
55

66
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
77
const options = parseOptions(apiKeyOrOptions)
8+
{{#if isUndocumented}}
9+
if (!options.isUndocumentedApiEnabled) {
10+
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
11+
}
12+
{{/if}}
813
this.client = 'client' in options ? options.client : createClient(options)
914
this.defaults = limitToSeamHttpRequestOptions(options)
1015
}

codegen/lib/connect.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@ export const connect = (
2828
metalsmith: Metalsmith,
2929
): void => {
3030
const metadata = metalsmith.metadata() as Metadata
31-
const { blueprint } = metadata
32-
33-
const namespaces = blueprint.namespaces.filter(
34-
({ isUndocumented }) => !isUndocumented,
35-
)
36-
const routes = blueprint.routes.filter(
37-
({ isUndocumented }) => !isUndocumented,
38-
)
31+
const {
32+
blueprint: { namespaces, routes },
33+
} = metadata
3934

4035
const nodes = [...namespaces, ...routes]
4136

codegen/lib/layouts/endpoints.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export const setEndpointsLayoutContext = (
2222
file.className = getClassName('Endpoints')
2323
file.skipClientSessionImport = true
2424
file.endpoints = routes.flatMap((route) =>
25-
route.endpoints
26-
.filter(({ isUndocumented }) => !isUndocumented)
27-
.map((endpoint) => getEndpointLayoutContext(endpoint, route)),
25+
route.endpoints.map((endpoint) =>
26+
getEndpointLayoutContext(endpoint, route),
27+
),
2828
)
2929
file.routeImports = routes.map((route) => {
3030
return {

codegen/lib/layouts/route.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { camelCase, kebabCase, pascalCase } from 'change-case'
44

55
export interface RouteLayoutContext {
66
className: string
7+
isUndocumented: boolean
78
endpoints: EndpointLayoutContext[]
89
subroutes: SubrouteLayoutContext[]
910
skipClientSessionImport: boolean
@@ -30,6 +31,7 @@ export interface EndpointLayoutContext {
3031
returnsActionAttempt: boolean
3132
returnsVoid: boolean
3233
isOptionalParamsOk: boolean
34+
isUndocumented: boolean
3335
}
3436

3537
export interface SubrouteLayoutContext {
@@ -44,15 +46,13 @@ export const setRouteLayoutContext = (
4446
nodes: Array<Route | Namespace>,
4547
): void => {
4648
file.className = getClassName(node?.path ?? null)
49+
file.isUndocumented = node?.isUndocumented ?? false
4750
file.skipClientSessionImport =
4851
node == null || node?.path === '/client_sessions'
4952

5053
file.endpoints = []
5154
if (node != null && 'endpoints' in node) {
52-
const endpoints = node.endpoints.filter(
53-
({ isUndocumented }) => !isUndocumented,
54-
)
55-
file.endpoints = endpoints.map((endpoint) =>
55+
file.endpoints = node.endpoints.map((endpoint) =>
5656
getEndpointLayoutContext(endpoint, node),
5757
)
5858
}
@@ -64,7 +64,7 @@ export const setRouteLayoutContext = (
6464
}
6565

6666
const getSubrouteLayoutContext = (
67-
route: Pick<Route, 'path' | 'name'>,
67+
route: Pick<Route, 'path' | 'name' | 'isUndocumented'>,
6868
): SubrouteLayoutContext => {
6969
return {
7070
fileName: `${kebabCase(route.name)}/index.js`,
@@ -116,6 +116,7 @@ export const getEndpointLayoutContext = (
116116
// UPSTREAM: Needs support in blueprint, fallback to true for now.
117117
// https://github.com/seamapi/blueprint/issues/205
118118
isOptionalParamsOk: true,
119+
isUndocumented: endpoint.isUndocumented,
119120
...getResponseContext(endpoint),
120121
}
121122
}

src/lib/seam/connect/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ interface SeamHttpCommonOptions extends ClientOptions, SeamHttpRequestOptions {
2222

2323
export interface SeamHttpRequestOptions {
2424
waitForActionAttempt?: boolean | ResolveActionAttemptOptions
25+
isUndocumentedApiEnabled?: boolean
2526
}
2627

2728
export interface SeamHttpFromPublishableKeyOptions
@@ -33,7 +34,7 @@ export interface SeamHttpMultiWorkspaceOptionsFromEnv
3334
extends SeamHttpCommonOptions {}
3435

3536
export interface SeamHttpMultiWorkspaceOptionsWithClient
36-
extends SeamHttpRequestOptions {
37+
extends SeamHttpCommonOptions {
3738
client: Client
3839
}
3940

src/lib/seam/connect/parse-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const getNormalizedOptions = (
6464
: apiKeyOrOptions
6565

6666
const requestOptions = {
67+
isUndocumentedApiEnabled: options.isUndocumentedApiEnabled ?? false,
6768
waitForActionAttempt: options.waitForActionAttempt ?? true,
6869
}
6970

@@ -181,6 +182,7 @@ export const isSeamHttpRequestOption = (
181182
key: string,
182183
): key is keyof SeamHttpRequestOptions => {
183184
const keys: Record<keyof SeamHttpRequestOptions, true> = {
185+
isUndocumentedApiEnabled: true,
184186
waitForActionAttempt: true,
185187
}
186188
return Object.keys(keys).includes(key)

src/lib/seam/connect/routes/acs/access-groups/access-groups.ts

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/seam/connect/routes/acs/access-groups/index.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/seam/connect/routes/acs/access-groups/unmanaged/index.ts

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)