@appliance.sh/api-server 1.18.0 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appliance.sh/api-server",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "",
5
5
  "author": "Eliot Lim",
6
6
  "repository": "https://github.com/appliance-sh/appliance.sh",
@@ -19,8 +19,8 @@
19
19
  "test:e2e": "vitest run --config vitest.e2e.config.ts"
20
20
  },
21
21
  "dependencies": {
22
- "@appliance.sh/infra": "1.18.0",
23
- "@appliance.sh/sdk": "1.18.0",
22
+ "@appliance.sh/infra": "1.19.0",
23
+ "@appliance.sh/sdk": "1.19.0",
24
24
  "@aws-sdk/client-s3": "^3.750.0",
25
25
  "express": "^5.2.1"
26
26
  },
package/src/main.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import express from 'express';
2
2
  import { indexRoutes } from './routes';
3
- import { infraRoutes } from './routes/infra';
3
+
4
4
  import { projectRoutes } from './routes/projects';
5
5
  import { environmentRoutes } from './routes/environments';
6
6
  import { deploymentRoutes } from './routes/deployments';
@@ -26,7 +26,6 @@ export function createApp() {
26
26
  app.use('/api/v1/projects', signatureAuth, projectRoutes);
27
27
  app.use('/api/v1/projects/:projectId/environments', signatureAuth, environmentRoutes);
28
28
  app.use('/api/v1/deployments', signatureAuth, deploymentRoutes);
29
- app.use('/api/v1/infra', signatureAuth, infraRoutes);
30
29
 
31
30
  return app;
32
31
  }
@@ -1,6 +1,6 @@
1
- import { randomUUID, randomBytes } from 'crypto';
1
+ import { randomBytes } from 'crypto';
2
2
  import { getStorageService } from './storage.service';
3
- import { ApiKeyCreateResponse } from '@appliance.sh/sdk';
3
+ import { ApiKeyCreateResponse, generateId } from '@appliance.sh/sdk';
4
4
 
5
5
  const COLLECTION = 'api-keys';
6
6
 
@@ -17,7 +17,7 @@ interface StoredApiKey {
17
17
  export class ApiKeyService {
18
18
  async create(name: string): Promise<ApiKeyCreateResponse> {
19
19
  const storage = getStorageService();
20
- const id = `ak_${randomUUID()}`;
20
+ const id = generateId('ak');
21
21
  const secret = `sk_${randomBytes(32).toString('hex')}`;
22
22
  const now = new Date().toISOString();
23
23
 
@@ -1,8 +1,15 @@
1
- import { Deployment, DeploymentInput, DeploymentStatus, DeploymentAction, EnvironmentStatus } from '@appliance.sh/sdk';
1
+ import {
2
+ Deployment,
3
+ DeploymentInput,
4
+ DeploymentStatus,
5
+ DeploymentAction,
6
+ EnvironmentStatus,
7
+ generateId,
8
+ } from '@appliance.sh/sdk';
2
9
  import { createApplianceDeploymentService } from '@appliance.sh/infra';
3
10
  import { getStorageService } from './storage.service';
4
11
  import { environmentService } from './environment.service';
5
- import { randomUUID } from 'crypto';
12
+ import { projectService } from './project.service';
6
13
 
7
14
  const COLLECTION = 'deployments';
8
15
 
@@ -18,7 +25,7 @@ export class DeploymentService {
18
25
  const now = new Date().toISOString();
19
26
  const deployment: Deployment = {
20
27
  ...input,
21
- id: randomUUID(),
28
+ id: generateId('dep'),
22
29
  projectId: environment.projectId,
23
30
  status: DeploymentStatus.Pending,
24
31
  startedAt: now,
@@ -35,6 +42,21 @@ export class DeploymentService {
35
42
  input.action === DeploymentAction.Deploy ? EnvironmentStatus.Deploying : EnvironmentStatus.Destroying;
36
43
  await environmentService.updateStatus(environment.id, envStatus);
37
44
 
45
+ // Look up the project for tagging
46
+ const project = await projectService.get(environment.projectId);
47
+ if (!project) {
48
+ throw new Error(`Project not found: ${environment.projectId}`);
49
+ }
50
+
51
+ const metadata = {
52
+ projectId: project.id,
53
+ projectName: project.name,
54
+ environmentId: environment.id,
55
+ environmentName: environment.name,
56
+ deploymentId: deployment.id,
57
+ stackName: environment.stackName,
58
+ };
59
+
38
60
  // Execute the deployment
39
61
  try {
40
62
  const deploymentService = createApplianceDeploymentService({
@@ -43,7 +65,7 @@ export class DeploymentService {
43
65
 
44
66
  let result;
45
67
  if (input.action === DeploymentAction.Deploy) {
46
- result = await deploymentService.deploy(environment.stackName);
68
+ result = await deploymentService.deploy(environment.stackName, metadata);
47
69
  } else {
48
70
  result = await deploymentService.destroy(environment.stackName);
49
71
  }
@@ -1,7 +1,6 @@
1
- import { Environment, EnvironmentInput, EnvironmentStatus } from '@appliance.sh/sdk';
1
+ import { Environment, EnvironmentInput, EnvironmentStatus, generateId } from '@appliance.sh/sdk';
2
2
  import type { ApplianceBaseConfig } from '@appliance.sh/sdk';
3
3
  import { getStorageService } from './storage.service';
4
- import { randomUUID } from 'crypto';
5
4
 
6
5
  const COLLECTION = 'environments';
7
6
 
@@ -9,7 +8,7 @@ export class EnvironmentService {
9
8
  async create(input: EnvironmentInput, projectName: string, baseConfig: ApplianceBaseConfig): Promise<Environment> {
10
9
  const storage = getStorageService();
11
10
  const now = new Date().toISOString();
12
- const id = randomUUID();
11
+ const id = generateId('env');
13
12
  const environment: Environment = {
14
13
  ...input,
15
14
  id,
@@ -1,6 +1,5 @@
1
- import { Project, ProjectInput, ProjectStatus } from '@appliance.sh/sdk';
1
+ import { Project, ProjectInput, ProjectStatus, generateId } from '@appliance.sh/sdk';
2
2
  import { getStorageService } from './storage.service';
3
- import { randomUUID } from 'crypto';
4
3
 
5
4
  const COLLECTION = 'projects';
6
5
 
@@ -10,7 +9,7 @@ export class ProjectService {
10
9
  const now = new Date().toISOString();
11
10
  const project: Project = {
12
11
  ...input,
13
- id: randomUUID(),
12
+ id: generateId('proj'),
14
13
  status: ProjectStatus.Active,
15
14
  createdAt: now,
16
15
  updatedAt: now,
@@ -1,24 +0,0 @@
1
- import { Router } from 'express';
2
- import { pulumiService } from '../../services/pulumi.service';
3
-
4
- export const infraRoutes = Router();
5
-
6
- infraRoutes.post('/deploy', async (_req, res) => {
7
- try {
8
- const result = await pulumiService.deploy();
9
- res.json(result);
10
- } catch (error) {
11
- console.error('Deploy error:', error);
12
- res.status(500).json({ error: 'Deploy failed', message: String(error) });
13
- }
14
- });
15
-
16
- infraRoutes.post('/destroy', async (_req, res) => {
17
- try {
18
- const result = await pulumiService.destroy();
19
- res.json(result);
20
- } catch (error) {
21
- console.error('Destroy error:', error);
22
- res.status(500).json({ error: 'Destroy failed', message: String(error) });
23
- }
24
- });
@@ -1,12 +0,0 @@
1
- import {
2
- ApplianceDeploymentService,
3
- createApplianceDeploymentService,
4
- type PulumiAction,
5
- type PulumiResult,
6
- } from '@appliance.sh/infra';
7
-
8
- // Re-export types for consumers
9
- export type { PulumiAction, PulumiResult };
10
-
11
- // Export a singleton instance
12
- export const pulumiService: ApplianceDeploymentService = createApplianceDeploymentService();