Skip to content

Commit

Permalink
Remove todo and add basic test and example
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Sep 19, 2023
1 parent 087eff3 commit da3f6e9
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 49 deletions.
40 changes: 36 additions & 4 deletions examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
#!/usr/bin/env tsx

import landlubber from 'landlubber'
import { env } from 'node:process'

import * as todo from './todo.js'
import landlubber, {
type DefaultContext,
defaultMiddleware,
type EmptyOptions,
type Handler as DefaultHandler,
type MiddlewareFunction,
} from 'landlubber'

const commands = [todo]
import { SeamHttp } from '@seamapi/http/connect'

await landlubber(commands).parse()
import * as workspace from './workspace.js'

export type Handler<Options = EmptyOptions> = DefaultHandler<Options, Context>

type Context = DefaultContext & ClientContext

interface ClientContext {
client: SeamHttp
}

const commands = [workspace]

const createAppContext: MiddlewareFunction = async (argv) => {
const apiKey = argv['api-key']
if (typeof apiKey !== 'string') throw new Error('Missing Seam API key')
const client = SeamHttp.fromApiKey(apiKey)
argv['client'] = client
}

const middleware = [...defaultMiddleware, createAppContext]

await landlubber<Context>(commands, { middleware })
.describe('api-key', 'Seam API key')
.string('api-key')
.default('api-key', env['SEAM_API_KEY'], 'SEAM_API_KEY')
.demandOption('api-key')
.parse()
22 changes: 0 additions & 22 deletions examples/todo.ts

This file was deleted.

17 changes: 17 additions & 0 deletions examples/workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Builder, Command, Describe } from 'landlubber'

import type { Handler } from './index.js'

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface Options {}

export const command: Command = 'workspace'

export const describe: Describe = 'Get workspace'

export const builder: Builder = {}

export const handler: Handler<Options> = async ({ client, logger }) => {
const workspace = await client.workspaces.get()
logger.info({ workspace }, 'workspace')
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"node": ">=16.13.0",
"npm": ">= 8.1.0"
},
"dependencies": {
"@seamapi/types": "^1.12.0"
},
"devDependencies": {
"@types/node": "^18.11.18",
"ava": "^5.0.1",
Expand All @@ -88,8 +91,5 @@
"tsup": "^7.2.0",
"tsx": "^3.12.1",
"typescript": "^5.1.0"
},
"dependencies": {
"@seamapi/types": "^1.12.0"
}
}
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default } from 'lib/index.js'
export * from 'lib/index.js'
export default null
2 changes: 0 additions & 2 deletions src/lib/index.ts

This file was deleted.

7 changes: 7 additions & 0 deletions src/lib/seam/connect/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava'

import { SeamHttp } from './client.js'

test('SeamHttp: fromApiKey', (t) => {
t.truthy(SeamHttp.fromApiKey('some-api-key'))
})
20 changes: 19 additions & 1 deletion src/lib/seam/connect/client.ts
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
export class SeamHttpClient {}
export class SeamHttp {
static fromApiKey(_apiKey: string): SeamHttp {
return new SeamHttp()
}

static fromClientSessionToken(): SeamHttp {
return new SeamHttp()
}

static async fromPublishableKey(): Promise<SeamHttp> {
return new SeamHttp()
}

workspaces = {
async get(): Promise<null> {
return null
},
}
}
7 changes: 0 additions & 7 deletions src/lib/todo.test.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/todo.ts

This file was deleted.

7 changes: 7 additions & 0 deletions test/seam/connect/client.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava'

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

test('SeamHttp: fromApiKey', (t) => {
t.truthy(SeamHttp.fromApiKey('some-api-key'))
})
6 changes: 0 additions & 6 deletions test/todo.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
}
},
"files": ["src/index.ts"],
"include": ["src/**/*", "test/**/*", "examples/**/*"]
"include": ["src/**/*", "test/**/*", "examples/**/*", "tsup.config.ts"]
}

0 comments on commit da3f6e9

Please sign in to comment.