@giaeulate/baas-sdk 1.0.1 → 1.0.2

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": "@giaeulate/baas-sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Standalone SDK for BaaS Golang",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
package/src/client.ts CHANGED
@@ -29,6 +29,7 @@ import { createLogDrainsModule, type LogDrainsModule } from './modules/log-drain
29
29
  import { createBranchesModule, type BranchesModule } from './modules/branches';
30
30
  import { createRealtimeModule, type RealtimeModule } from './modules/realtime';
31
31
  import { createApiKeysModule, type ApiKeysModule } from './modules/api-keys';
32
+ import { createEnvironmentsModule, type EnvironmentsModule } from './modules/environments';
32
33
 
33
34
  /**
34
35
  * Main BaaS Client - Composes all feature modules
@@ -68,6 +69,7 @@ export class BaasClient extends HttpClient {
68
69
  public readonly branches: BranchesModule;
69
70
  public readonly realtime: RealtimeModule;
70
71
  public readonly apiKeys: ApiKeysModule;
72
+ public readonly environments: EnvironmentsModule;
71
73
 
72
74
  constructor(url?: string, apiKey?: string) {
73
75
  super(url, apiKey);
@@ -92,6 +94,7 @@ export class BaasClient extends HttpClient {
92
94
  this.branches = createBranchesModule(this);
93
95
  this.realtime = createRealtimeModule(this);
94
96
  this.apiKeys = createApiKeysModule(this);
97
+ this.environments = createEnvironmentsModule(this);
95
98
  }
96
99
 
97
100
  /**
@@ -250,7 +253,13 @@ export class BaasClient extends HttpClient {
250
253
  async getAuditActions() { return this.audit.getActions(); }
251
254
 
252
255
  // Realtime shortcuts
253
- subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>) {
254
- return this.realtime.subscribe<T>(table, action, callback);
256
+ subscribe<T = any>(table: string, action: RealtimeAction, callback: RealtimeCallback<T>) {
257
+ return this.realtime.subscribe<T>(table, action, callback);
255
258
  }
259
+
260
+ // Environment shortcuts
261
+ async getEnvironmentStatus() { return this.environments.status(); }
262
+ async initTestEnvironment() { return this.environments.init(); }
263
+ async promoteTestToProd() { return this.environments.promote(); }
264
+ async revertTestEnvironment() { return this.environments.revert(); }
256
265
  }
@@ -9,6 +9,7 @@ export class HttpClient {
9
9
  public url: string;
10
10
  public apiKey: string = '';
11
11
  public token: string | null = null;
12
+ private environment: string = 'prod';
12
13
 
13
14
  constructor(url?: string, apiKey?: string) {
14
15
  let baseUrl = url || (typeof window !== 'undefined' ? window.location.origin : 'http://localhost:8080');
@@ -41,6 +42,11 @@ export class HttpClient {
41
42
  if (dynamicToken) {
42
43
  headers['Authorization'] = `Bearer ${dynamicToken}`;
43
44
  }
45
+
46
+ if (this.environment && this.environment !== 'prod') {
47
+ headers['X-Environment'] = this.environment;
48
+ }
49
+
44
50
  return headers;
45
51
  }
46
52
 
@@ -106,6 +112,14 @@ export class HttpClient {
106
112
  return this.request<T>(endpoint, { method: 'DELETE' });
107
113
  }
108
114
 
115
+ setEnvironment(env: string) {
116
+ this.environment = env;
117
+ }
118
+
119
+ getEnvironment(): string {
120
+ return this.environment;
121
+ }
122
+
109
123
  logout() {
110
124
  this.token = null;
111
125
  localStorage.removeItem('baas_token');
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Environments Module - Test/Prod environment management
3
+ */
4
+
5
+ import type { HttpClient } from '../http-client';
6
+
7
+ export interface EnvironmentStatus {
8
+ test_exists: boolean;
9
+ test_status?: string;
10
+ test_created_at?: string;
11
+ test_schema_name?: string;
12
+ prod_schema_name: string;
13
+ table_count: number;
14
+ }
15
+
16
+ export interface PromoteResult {
17
+ tables_promoted: number;
18
+ status: string;
19
+ }
20
+
21
+ export interface EnvironmentsModule {
22
+ status(): Promise<EnvironmentStatus>;
23
+ init(): Promise<any>;
24
+ promote(): Promise<PromoteResult>;
25
+ revert(): Promise<any>;
26
+ setActive(env: 'test' | 'prod'): void;
27
+ getActive(): string;
28
+ }
29
+
30
+ export function createEnvironmentsModule(client: HttpClient): EnvironmentsModule {
31
+ const get = (endpoint: string) => (client as any).get(endpoint);
32
+ const post = (endpoint: string, body?: unknown) => (client as any).post(endpoint, body);
33
+
34
+ return {
35
+ async status() {
36
+ return get('/api/environments/status');
37
+ },
38
+
39
+ async init() {
40
+ return post('/api/environments/init');
41
+ },
42
+
43
+ async promote() {
44
+ return post('/api/environments/promote');
45
+ },
46
+
47
+ async revert() {
48
+ return post('/api/environments/revert');
49
+ },
50
+
51
+ setActive(env: 'test' | 'prod') {
52
+ client.setEnvironment(env);
53
+ },
54
+
55
+ getActive() {
56
+ return client.getEnvironment();
57
+ },
58
+ };
59
+ }