Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
export {};
|
||
|
||
/**
|
||
* Standalone sample: create a service category via the Alga PSA API.
|
||
*
|
||
* Usage:
|
||
* ALGA_API_URL="https://algapsa.com" \
|
||
* ALGA_API_KEY="your-api-key" \
|
||
* ALGA_TENANT_ID="optional-tenant" \
|
||
* npm run sample:create-service-category -- "New Category Name"
|
||
*
|
||
* Pass the desired category name as the first CLI argument; defaults to
|
||
* "Sample Service Category" when omitted.
|
||
*/
|
||
|
||
// Public production API is served from the main domain (no api. subdomain).
|
||
const API_BASE_URL = process.env.ALGA_API_URL ?? "https://algapsa.com";
|
||
const API_KEY = process.env.ALGA_API_KEY;
|
||
const TENANT_ID = process.env.ALGA_TENANT_ID;
|
||
|
||
if (!API_KEY) {
|
||
console.error("Missing ALGA_API_KEY environment variable");
|
||
process.exit(1);
|
||
}
|
||
|
||
const categoryName = process.argv[2] ?? "Sample Service Category";
|
||
|
||
interface CreateServiceCategoryInput {
|
||
category_name: string;
|
||
description?: string;
|
||
is_active?: boolean;
|
||
}
|
||
|
||
interface ServiceCategoryResponse {
|
||
category_id: string;
|
||
category_name: string;
|
||
description: string | null;
|
||
is_active: boolean;
|
||
tenant: string;
|
||
created_by: string;
|
||
updated_by: string;
|
||
created_at: string;
|
||
updated_at: string;
|
||
}
|
||
|
||
async function createServiceCategory(input: CreateServiceCategoryInput): Promise<ServiceCategoryResponse> {
|
||
const headers: Record<string, string> = {
|
||
"Content-Type": "application/json",
|
||
"x-api-key": API_KEY!,
|
||
};
|
||
|
||
if (TENANT_ID) {
|
||
headers["x-tenant-id"] = TENANT_ID;
|
||
}
|
||
|
||
const res = await fetch(`${API_BASE_URL}/api/v1/categories/service`, {
|
||
method: "POST",
|
||
headers,
|
||
body: JSON.stringify(input),
|
||
});
|
||
|
||
if (!res.ok) {
|
||
const detail = await res.text();
|
||
throw new Error(`Service category creation failed: ${res.status} ${res.statusText} – ${detail}`);
|
||
}
|
||
|
||
return (await res.json()) as ServiceCategoryResponse;
|
||
}
|
||
|
||
(async () => {
|
||
try {
|
||
const category = await createServiceCategory({
|
||
category_name: categoryName,
|
||
description: "Created via SDK sample script",
|
||
is_active: true,
|
||
});
|
||
|
||
console.log("Created service category:");
|
||
console.log(JSON.stringify(category, null, 2));
|
||
} catch (error) {
|
||
console.error(error instanceof Error ? error.message : error);
|
||
process.exit(1);
|
||
}
|
||
})();
|