Skip to content

Commit da3f6e9

Browse files
committed
Remove todo and add basic test and example
1 parent 087eff3 commit da3f6e9

File tree

13 files changed

+91
-49
lines changed

13 files changed

+91
-49
lines changed

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 & 22 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+
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
"node": ">=16.13.0",
7171
"npm": ">= 8.1.0"
7272
},
73+
"dependencies": {
74+
"@seamapi/types": "^1.12.0"
75+
},
7376
"devDependencies": {
7477
"@types/node": "^18.11.18",
7578
"ava": "^5.0.1",
@@ -88,8 +91,5 @@
8891
"tsup": "^7.2.0",
8992
"tsx": "^3.12.1",
9093
"typescript": "^5.1.0"
91-
},
92-
"dependencies": {
93-
"@seamapi/types": "^1.12.0"
9494
}
9595
}

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
export { default } from 'lib/index.js'
2-
export * from 'lib/index.js'
1+
export default null

src/lib/index.ts

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

src/lib/seam/connect/client.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import test from 'ava'
2+
3+
import { SeamHttp } from './client.js'
4+
5+
test('SeamHttp: fromApiKey', (t) => {
6+
t.truthy(SeamHttp.fromApiKey('some-api-key'))
7+
})

src/lib/seam/connect/client.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
export class SeamHttpClient {}
1+
export class SeamHttp {
2+
static fromApiKey(_apiKey: string): SeamHttp {
3+
return new SeamHttp()
4+
}
5+
6+
static fromClientSessionToken(): SeamHttp {
7+
return new SeamHttp()
8+
}
9+
10+
static async fromPublishableKey(): Promise<SeamHttp> {
11+
return new SeamHttp()
12+
}
13+
14+
workspaces = {
15+
async get(): Promise<null> {
16+
return null
17+
},
18+
}
19+
}

src/lib/todo.test.ts

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

src/lib/todo.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)