Skip to content

Commit 396edf5

Browse files
authored
Merge pull request #1 from seamapi/base-class
2 parents 773cc84 + da3f6e9 commit 396edf5

File tree

20 files changed

+1689
-223
lines changed

20 files changed

+1689
-223
lines changed

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
],
2121
"import/extensions": ["error", "ignorePackages"],
2222
"import/no-duplicates": ["error", { "prefer-inline": true }],
23+
"import/no-relative-parent-imports": "error",
2324
"simple-import-sort/imports": [
2425
"error",
2526
{
2627
"groups": [
2728
["^\\u0000"],
2829
["^node:"],
2930
["^@?\\w"],
30-
["@seamapi/http"],
31+
["@seamapi/http/connect"],
3132
["^lib/"],
3233
["^"],
3334
["^\\."]

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
write-mode: overwrite
101101
path: index.js
102102
contents: |
103-
import '@seamapi/http'
103+
import '@seamapi/http/connect'
104104
- name: Install
105105
run: npm install --save ${{ steps.packages.outputs.paths }}
106106
- name: Run

examples/index.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
#!/usr/bin/env tsx
22

3-
import landlubber from 'landlubber'
3+
import { env } from 'node:process'
44

5-
import * as todo from './todo.js'
5+
import landlubber, {
6+
type DefaultContext,
7+
defaultMiddleware,
8+
type EmptyOptions,
9+
type Handler as DefaultHandler,
10+
type MiddlewareFunction,
11+
} from 'landlubber'
612

7-
const commands = [todo]
13+
import { SeamHttp } from '@seamapi/http/connect'
814

9-
await landlubber(commands).parse()
15+
import * as workspace from './workspace.js'
16+
17+
export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context>
18+
19+
type Context = DefaultContext & ClientContext
20+
21+
interface ClientContext {
22+
client: SeamHttp
23+
}
24+
25+
const commands = [workspace]
26+
27+
const createAppContext: MiddlewareFunction = async (argv) => {
28+
const apiKey = argv['api-key']
29+
if (typeof apiKey !== 'string') throw new Error('Missing Seam API key')
30+
const client = SeamHttp.fromApiKey(apiKey)
31+
argv['client'] = client
32+
}
33+
34+
const middleware = [...defaultMiddleware, createAppContext]
35+
36+
await landlubber<Context>(commands, { middleware })
37+
.describe('api-key', 'Seam API key')
38+
.string('api-key')
39+
.default('api-key', env['SEAM_API_KEY'], 'SEAM_API_KEY')
40+
.demandOption('api-key')
41+
.parse()

examples/todo.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/workspace.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Builder, Command, Describe } from 'landlubber'
2+
3+
import type { Handler } from './index.js'
4+
5+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
6+
interface Options {}
7+
8+
export const command: Command = 'workspace'
9+
10+
export const describe: Describe = 'Get workspace'
11+
12+
export const builder: Builder = {}
13+
14+
export const handler: Handler<Options> = async ({ client, logger }) => {
15+
const workspace = await client.workspaces.get()
16+
logger.info({ workspace }, 'workspace')
17+
}

0 commit comments

Comments
 (0)