diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml new file mode 100644 index 0000000..9486948 --- /dev/null +++ b/.github/workflows/build-and-publish.yml @@ -0,0 +1,55 @@ +name: Build and Publish + +on: + push: + branches: [ main ] + tags: [ 'v*' ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm test + + - name: Build + run: npm run build + + publish: + needs: build + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/package.json b/package.json index 100ba9d..8ebccea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,8 @@ { - "name": "propelauth-cli", + "name": "@propelauth/cli", "version": "0.0.1", "description": "PropelAuth CLI tool", + "homepage": "https://www.propelauth.com", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/api.ts b/src/api.ts index cfca144..fa760b4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,18 +1,16 @@ -import { - ProjectsResponse, - BackendIntegrationResponse, +import { + ProjectsResponse, + BackendIntegrationResponse, FrontendIntegrationResponse, FrontendIntegrationRequest, ApiKeyRequest, - ApiKeyResponse + ApiKeyResponse, } from './types/api.js' -const BASE_API_URL = 'https://api.propelauth.localhost/cli' +const BASE_API_URL = 'https://api.propelauth.com/cli' const PROJECTS_URL = `${BASE_API_URL}/projects` -export type ApiResult = - | { success: true; data: T } - | { success: false; error: 'unauthorized' | string } +export type ApiResult = { success: true; data: T } | { success: false; error: 'unauthorized' | string } export type FetchProjectsResult = ApiResult export type BackendIntegrationResult = ApiResult @@ -21,8 +19,8 @@ export type UpdateFrontendIntegrationResult = ApiResult<{}> export type CreateApiKeyResult = ApiResult async function makeApiRequest( - url: string, - apiKey: string, + url: string, + apiKey: string, method: 'GET' | 'POST' | 'PUT' = 'GET', body?: object ): Promise> { @@ -32,9 +30,9 @@ async function makeApiRequest( 'Content-Type': 'application/json', } - const options: RequestInit = { + const options: RequestInit = { method, - headers + headers, } if (body) { @@ -56,7 +54,7 @@ async function makeApiRequest( return { success: true, data: {} as T } } - const data = await response.json() as T + const data = (await response.json()) as T return { success: true, data } } catch (err) { return { success: false, error: `API request error: ${err}` } @@ -68,8 +66,8 @@ export async function fetchProjects(apiKey: string): Promise { const url = `${BASE_API_URL}/${orgId}/project/${projectId}/be_integration` @@ -77,8 +75,8 @@ export async function fetchBackendIntegration( } export async function fetchFrontendIntegration( - apiKey: string, - orgId: string, + apiKey: string, + orgId: string, projectId: string ): Promise { const url = `${BASE_API_URL}/${orgId}/project/${projectId}/fe_integration` @@ -86,8 +84,8 @@ export async function fetchFrontendIntegration( } export async function updateFrontendIntegration( - apiKey: string, - orgId: string, + apiKey: string, + orgId: string, projectId: string, data: FrontendIntegrationRequest ): Promise { @@ -96,8 +94,8 @@ export async function updateFrontendIntegration( } export async function createApiKey( - apiKey: string, - orgId: string, + apiKey: string, + orgId: string, projectId: string, data: ApiKeyRequest ): Promise {