@squidcloud/cli 1.0.446 → 1.0.447

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.
@@ -0,0 +1,242 @@
1
+ # Admin & Management
2
+
3
+ This document covers programmatic management of Squid organizations, applications, integrations, and secrets.
4
+
5
+ ## Contents
6
+ - ManagementClient
7
+ - Admin Integrations
8
+ - Admin Secrets
9
+
10
+ ## ManagementClient
11
+
12
+ The ManagementClient provides programmatic management of Squid organizations and applications using management API keys.
13
+
14
+ ### Creating Management API Keys
15
+
16
+ 1. Go to Squid Console → Profile Settings → API Keys
17
+ 2. Click "Create API Key"
18
+ 3. Copy the key value (shown only once)
19
+ 4. Key format: `squid_mgmt_<uuid>`
20
+
21
+ ### Usage
22
+
23
+ ```typescript
24
+ import { ManagementClient } from '@squidcloud/client';
25
+
26
+ // Initialize with management API key
27
+ const client = new ManagementClient({
28
+ apiKey: 'squid_mgmt_xxx...', // From Console Profile Settings
29
+ consoleRegion: 'us-east-1.aws' // Your Squid region
30
+ });
31
+
32
+ // Create an organization
33
+ const { organizationId } = await client.createOrganization({
34
+ name: 'My Organization' // 2-50 characters
35
+ });
36
+ console.log('Created org:', organizationId);
37
+
38
+ // Create an application in the organization
39
+ const { appId, devApiKey, prodApiKey } = await client.createApplication({
40
+ organizationId,
41
+ name: 'My Application',
42
+ region: 'us-east-1.aws' // SquidRegion (e.g., 'us-east-1.aws', 'us-central1.gcp')
43
+ });
44
+ console.log('Created app:', appId);
45
+
46
+ // Delete an application
47
+ await client.deleteApplication(appId);
48
+ ```
49
+
50
+ ### Available Methods
51
+
52
+ | Method | Description |
53
+ |--------|-------------|
54
+ | `createOrganization({ name })` | Creates a new organization. User becomes admin. |
55
+ | `createApplication({ organizationId, name, region })` | Creates an application in an organization. Returns `{ appId, devApiKey, prodApiKey }`. |
56
+ | `deleteApplication(appId)` | Deletes an application. Requires admin role. |
57
+
58
+ ### TypeScript Types
59
+
60
+ ```typescript
61
+ import {
62
+ ManagementClient,
63
+ ManagementClientOptions,
64
+ ManagementCreateOrganizationRequest,
65
+ ManagementCreateOrganizationResponse,
66
+ ManagementCreateApplicationRequest,
67
+ ManagementCreateApplicationResponse,
68
+ } from '@squidcloud/client';
69
+ ```
70
+
71
+ ### Key Points
72
+
73
+ - Management API keys are tied to a user account
74
+ - The user associated with the key becomes the organization admin
75
+ - Keys can be suspended/reactivated/deleted in Console Profile Settings
76
+ - Different from app API keys (which bypass security rules)
77
+ - Use for CI/CD pipelines, automation scripts, and programmatic management
78
+
79
+ ### Use Cases
80
+
81
+ - Automated tenant provisioning (multi-tenant SaaS)
82
+ - CI/CD pipeline integration
83
+ - Infrastructure-as-code workflows
84
+ - Programmatic organization management
85
+ - Automated testing environments
86
+
87
+ ## Admin - Integrations
88
+
89
+ **Important:** Admin methods require initialization with an API key. They cannot be used with user authentication.
90
+
91
+ ```typescript
92
+ // Squid must be initialized with apiKey
93
+ const squid = new Squid({ appId: 'app-id', region: 'us-east-1.aws', apiKey: 'your-api-key' });
94
+
95
+ const integrations = squid.admin().integrations();
96
+
97
+ // List all or by type
98
+ const all = await integrations.list();
99
+ const databases = await integrations.list('database');
100
+
101
+ // Get one
102
+ const integration = await integrations.get('postgres-db');
103
+
104
+ // Create/update
105
+ await integrations.upsertIntegration({
106
+ id: 'my-postgres',
107
+ type: 'postgres',
108
+ connectionString: 'postgresql://...'
109
+ });
110
+
111
+ // Delete
112
+ await integrations.delete('old-integration');
113
+ await integrations.deleteMany(['int-1', 'int-2']);
114
+
115
+ // Get integration schema
116
+ const schema = await integrations.getIntegrationSchema<MySchemaType>('postgres-db');
117
+ console.log(schema);
118
+
119
+ // Set integration schema
120
+ await integrations.setIntegrationSchema('postgres-db', {
121
+ collections: [
122
+ {
123
+ name: 'users',
124
+ fields: [
125
+ { name: 'id', type: 'string', primaryKey: true },
126
+ { name: 'email', type: 'string' },
127
+ { name: 'name', type: 'string' }
128
+ ]
129
+ }
130
+ ]
131
+ });
132
+
133
+ // Generate AI descriptions for data schema (collections and fields)
134
+ const schemaResult = await integrations.generateAiDescriptionsForDataSchema('postgres-db', {
135
+ schema: currentSchema, // The current schema of the integration
136
+ collections: ['users', 'orders'], // Optional: specific collections to generate for
137
+ instructions: 'Use business terminology' // Optional: guide the AI
138
+ });
139
+ console.log(schemaResult.schema); // Schema with AI-generated descriptions
140
+
141
+ // Generate AI descriptions for associations (relationships between entities)
142
+ const assocResult = await integrations.generateAiDescriptionsForAssociations('postgres-db', {
143
+ schema: currentSchema,
144
+ associations: ['User_Order'], // Optional: specific associations to generate for
145
+ instructions: 'Explain the business relationship'
146
+ });
147
+
148
+ // Generate AI descriptions for stored procedures
149
+ const spResult = await integrations.generateAiDescriptionsForStoredProcedures('postgres-db', {
150
+ schema: currentSchema,
151
+ storedProcedures: ['calculate_totals'], // Optional: specific procedures to generate for
152
+ instructions: 'Describe what the procedure does'
153
+ });
154
+
155
+ // Generate AI descriptions for API endpoints
156
+ const apiResult = await integrations.generateAiDescriptionsForEndpoints('my-api', {
157
+ schema: apiSchema,
158
+ endpoints: ['GET /users', 'POST /orders'], // Optional: specific endpoints to generate for
159
+ instructions: 'Use REST API terminology'
160
+ });
161
+
162
+ // Discover schema from a database connection
163
+ const discovered = await integrations.discoverDataConnectionSchema('postgres-db');
164
+ console.log(discovered.schema); // Discovered tables, columns, relationships
165
+ console.log(discovered.collectionReadiness); // Permission and replication status
166
+
167
+ // Test a database connection to verify it is working (before or after saving)
168
+ const testResult = await integrations.testDataConnection({
169
+ id: 'my-postgres',
170
+ type: 'postgres',
171
+ configuration: {
172
+ connectionOptions: {
173
+ host: 'localhost',
174
+ port: 5432,
175
+ database: 'mydb',
176
+ user: 'user',
177
+ secrets: { password: 'pass' }
178
+ }
179
+ }
180
+ });
181
+ if (testResult.success) {
182
+ console.log('Connection successful!');
183
+ } else {
184
+ console.log('Connection failed:', testResult.errorMessage);
185
+ }
186
+
187
+ // Discover schema from a GraphQL endpoint
188
+ const graphqlSchema = await integrations.discoverGraphQLConnectionSchema('my-graphql', {
189
+ connectionOptions: {
190
+ url: 'https://api.example.com/graphql',
191
+ headers: { 'Authorization': 'Bearer token' }
192
+ }
193
+ });
194
+
195
+ // Discover schema from an OpenAPI spec URL
196
+ const openApiSchema = await integrations.discoverOpenApiSchema('my-api', {
197
+ discoveryOptions: {
198
+ openApiSpecUrl: 'https://api.example.com/openapi.json',
199
+ headers: { 'Authorization': 'Bearer token' }
200
+ }
201
+ });
202
+
203
+ // Discover schema from an uploaded OpenAPI spec file
204
+ const fileSchema = await integrations.discoverOpenApiSchemaFromFile('my-api');
205
+ ```
206
+
207
+ ### Admin - Secrets
208
+
209
+ ```typescript
210
+ const secrets = squid.admin().secrets();
211
+
212
+ // Get secret (returns SecretEntry | undefined, not just the value)
213
+ const secret = await secrets.get('STRIPE_KEY');
214
+ const value = secret?.value;
215
+
216
+ // Get all
217
+ const all = await secrets.getAll();
218
+
219
+ // Create/update
220
+ await secrets.upsert('API_KEY', 'secret-value');
221
+ await secrets.upsertMany([
222
+ { key: 'KEY1', value: 'val1' },
223
+ { key: 'KEY2', value: 'val2' }
224
+ ]);
225
+
226
+ // Delete
227
+ await secrets.delete('OLD_KEY');
228
+ await secrets.deleteMany(['KEY1', 'KEY2']);
229
+
230
+ // API Keys
231
+ const apiKeys = secrets.apiKeys;
232
+ await apiKeys.upsert('my-key');
233
+ const key = await apiKeys.get('my-key');
234
+ const allApiKeys = await apiKeys.getAll(); // Get all API keys
235
+ await apiKeys.delete('my-key');
236
+ ```
237
+
238
+ ## Best Practices
239
+
240
+ 1. **Copy management API key immediately** - Key value is shown only once when created
241
+ 2. **Admin methods require API key** - Cannot use user authentication, must initialize Squid with `apiKey`
242
+ 3. **Management keys ≠ App keys** - Management keys are for Console operations, app keys bypass security rules