Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ const seam = new SeamHttpEndpoints()
const devices = await seam['/devices/list']()
```

#### Enable undocumented API

Pass the `isUndocumentedApiEnabled` option to allow using the undocumented API.
This API is used internally and is not directly supported.
Do not use the undocumented API in production environments.
Seam is not responsible for any issues you may encounter with the undocumented API.

```ts
import { SeamHttp } from '@seamapi/http/connect'

const seam = new SeamHttp({ isUndocumentedApiEnabled: true })
```

#### Inspecting the Request

All client methods return an instance of `SeamHttpRequest`.
Expand Down
5 changes: 5 additions & 0 deletions codegen/layouts/endpoints.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class SeamHttpEndpoints {
get['{{path}}'](): {{className}}['{{methodName}}']
{
const { client, defaults } = this
{{#if isUndocumented}}
if (!this.defaults.isUndocumentedApiEnabled) {
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
}
{{/if}}
return function {{functionName}} (...args: Parameters<{{className}}['{{methodName}}']>): ReturnType<{{className}}['{{methodName}}']>
{
const seam = {{className}}.fromClient(client, defaults)
Expand Down
5 changes: 5 additions & 0 deletions codegen/layouts/partials/route-class-endpoint.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
{{#if hasOptions}}options: {{optionsTypeName}} = {},{{/if}}
): SeamHttpRequest<{{#if returnsVoid}}void, undefined{{else}}{{responseTypeName}}, '{{responseKey}}'{{/if}}>
{
{{#if isUndocumented}}
if (!this.defaults.isUndocumentedApiEnabled) {
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
}
{{/if}}
return new SeamHttpRequest(this, {
pathname: '{{path}}',
method: '{{method}}',
Expand Down
5 changes: 5 additions & 0 deletions codegen/layouts/partials/route-class-methods.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ static ltsVersion = seamApiLtsVersion

constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
const options = parseOptions(apiKeyOrOptions)
{{#if isUndocumented}}
if (!options.isUndocumentedApiEnabled) {
throw new Error('Cannot use undocumented API without isUndocumentedApiEnabled')
}
{{/if}}
this.client = 'client' in options ? options.client : createClient(options)
this.defaults = limitToSeamHttpRequestOptions(options)
}
Expand Down
11 changes: 3 additions & 8 deletions codegen/lib/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ export const connect = (
metalsmith: Metalsmith,
): void => {
const metadata = metalsmith.metadata() as Metadata
const { blueprint } = metadata

const namespaces = blueprint.namespaces.filter(
({ isUndocumented }) => !isUndocumented,
)
const routes = blueprint.routes.filter(
({ isUndocumented }) => !isUndocumented,
)
const {
blueprint: { namespaces, routes },
} = metadata

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

Expand Down
6 changes: 3 additions & 3 deletions codegen/lib/layouts/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const setEndpointsLayoutContext = (
file.className = getClassName('Endpoints')
file.skipClientSessionImport = true
file.endpoints = routes.flatMap((route) =>
route.endpoints
.filter(({ isUndocumented }) => !isUndocumented)
.map((endpoint) => getEndpointLayoutContext(endpoint, route)),
route.endpoints.map((endpoint) =>
getEndpointLayoutContext(endpoint, route),
),
)
file.routeImports = routes.map((route) => {
return {
Expand Down
11 changes: 6 additions & 5 deletions codegen/lib/layouts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { camelCase, kebabCase, pascalCase } from 'change-case'

export interface RouteLayoutContext {
className: string
isUndocumented: boolean
endpoints: EndpointLayoutContext[]
subroutes: SubrouteLayoutContext[]
skipClientSessionImport: boolean
Expand All @@ -30,6 +31,7 @@ export interface EndpointLayoutContext {
returnsActionAttempt: boolean
returnsVoid: boolean
isOptionalParamsOk: boolean
isUndocumented: boolean
}

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

file.endpoints = []
if (node != null && 'endpoints' in node) {
const endpoints = node.endpoints.filter(
({ isUndocumented }) => !isUndocumented,
)
file.endpoints = endpoints.map((endpoint) =>
file.endpoints = node.endpoints.map((endpoint) =>
getEndpointLayoutContext(endpoint, node),
)
}
Expand All @@ -64,7 +64,7 @@ export const setRouteLayoutContext = (
}

const getSubrouteLayoutContext = (
route: Pick<Route, 'path' | 'name'>,
route: Pick<Route, 'path' | 'name' | 'isUndocumented'>,
): SubrouteLayoutContext => {
return {
fileName: `${kebabCase(route.name)}/index.js`,
Expand Down Expand Up @@ -116,6 +116,7 @@ export const getEndpointLayoutContext = (
// UPSTREAM: Needs support in blueprint, fallback to true for now.
// https://github.com/seamapi/blueprint/issues/205
isOptionalParamsOk: true,
isUndocumented: endpoint.isUndocumented,
...getResponseContext(endpoint),
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/seam/connect/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface SeamHttpCommonOptions extends ClientOptions, SeamHttpRequestOptions {

export interface SeamHttpRequestOptions {
waitForActionAttempt?: boolean | ResolveActionAttemptOptions
isUndocumentedApiEnabled?: boolean
}

export interface SeamHttpFromPublishableKeyOptions
Expand All @@ -33,7 +34,7 @@ export interface SeamHttpMultiWorkspaceOptionsFromEnv
extends SeamHttpCommonOptions {}

export interface SeamHttpMultiWorkspaceOptionsWithClient
extends SeamHttpRequestOptions {
extends SeamHttpCommonOptions {
client: Client
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib/seam/connect/parse-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const getNormalizedOptions = (
: apiKeyOrOptions

const requestOptions = {
isUndocumentedApiEnabled: options.isUndocumentedApiEnabled ?? false,
waitForActionAttempt: options.waitForActionAttempt ?? true,
}

Expand Down Expand Up @@ -181,6 +182,7 @@ export const isSeamHttpRequestOption = (
key: string,
): key is keyof SeamHttpRequestOptions => {
const keys: Record<keyof SeamHttpRequestOptions, true> = {
isUndocumentedApiEnabled: true,
waitForActionAttempt: true,
}
return Object.keys(keys).includes(key)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/lib/seam/connect/routes/acs/access-groups/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading