Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SeamHttp client skeleton #1

Merged
merged 5 commits into from
Sep 19, 2023
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
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