Skip to content
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
55 changes: 55 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
40 changes: 19 additions & 21 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -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<T> =
| { success: true; data: T }
| { success: false; error: 'unauthorized' | string }
export type ApiResult<T> = { success: true; data: T } | { success: false; error: 'unauthorized' | string }

export type FetchProjectsResult = ApiResult<ProjectsResponse>
export type BackendIntegrationResult = ApiResult<BackendIntegrationResponse>
Expand All @@ -21,8 +19,8 @@ export type UpdateFrontendIntegrationResult = ApiResult<{}>
export type CreateApiKeyResult = ApiResult<ApiKeyResponse>

async function makeApiRequest<T>(
url: string,
apiKey: string,
url: string,
apiKey: string,
method: 'GET' | 'POST' | 'PUT' = 'GET',
body?: object
): Promise<ApiResult<T>> {
Expand All @@ -32,9 +30,9 @@ async function makeApiRequest<T>(
'Content-Type': 'application/json',
}

const options: RequestInit = {
const options: RequestInit = {
method,
headers
headers,
}

if (body) {
Expand All @@ -56,7 +54,7 @@ async function makeApiRequest<T>(
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}` }
Expand All @@ -68,26 +66,26 @@ export async function fetchProjects(apiKey: string): Promise<FetchProjectsResult
}

export async function fetchBackendIntegration(
apiKey: string,
orgId: string,
apiKey: string,
orgId: string,
projectId: string
): Promise<BackendIntegrationResult> {
const url = `${BASE_API_URL}/${orgId}/project/${projectId}/be_integration`
return makeApiRequest<BackendIntegrationResponse>(url, apiKey)
}

export async function fetchFrontendIntegration(
apiKey: string,
orgId: string,
apiKey: string,
orgId: string,
projectId: string
): Promise<FrontendIntegrationResult> {
const url = `${BASE_API_URL}/${orgId}/project/${projectId}/fe_integration`
return makeApiRequest<FrontendIntegrationResponse>(url, apiKey)
}

export async function updateFrontendIntegration(
apiKey: string,
orgId: string,
apiKey: string,
orgId: string,
projectId: string,
data: FrontendIntegrationRequest
): Promise<UpdateFrontendIntegrationResult> {
Expand All @@ -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<CreateApiKeyResult> {
Expand Down