Skip to content

Commit

Permalink
Merge pull request #1 from seamapi/base-class
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x authored Sep 19, 2023
2 parents 773cc84 + da3f6e9 commit 396edf5
Show file tree
Hide file tree
Showing 20 changed files with 1,689 additions and 223 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
],
"import/extensions": ["error", "ignorePackages"],
"import/no-duplicates": ["error", { "prefer-inline": true }],
"import/no-relative-parent-imports": "error",
"simple-import-sort/imports": [
"error",
{
"groups": [
["^\\u0000"],
["^node:"],
["^@?\\w"],
["@seamapi/http"],
["@seamapi/http/connect"],
["^lib/"],
["^"],
["^\\."]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
write-mode: overwrite
path: index.js
contents: |
import '@seamapi/http'
import '@seamapi/http/connect'
- name: Install
run: npm install --save ${{ steps.packages.outputs.paths }}
- name: Run
Expand Down
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()
23 changes: 0 additions & 23 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')
}
Loading

0 comments on commit 396edf5

Please sign in to comment.