@bosunski/laravel-cloud-sdk 0.1.1 → 0.1.4

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.
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { createJsonApiCollectionSchema, createJsonApiResponseSchema, JsonApiResourceSchema, } from '../types/jsonApi.js';
3
3
  import { deploymentResponseSchema, serializeDeploymentResponse, } from './deployments.js';
4
+ import { keysToCamel } from '../utils/caseConversion.js';
4
5
  const colorSchema = z.enum([
5
6
  'blue',
6
7
  'green',
@@ -55,6 +56,8 @@ const environmentLogsResponseSchema = z.object({
55
56
  data: z.array(environmentLogEntrySchema),
56
57
  meta: environmentLogMetaSchema,
57
58
  });
59
+ // Transform log entry to camelCase
60
+ const transformedLogEntrySchema = environmentLogEntrySchema.transform((data) => keysToCamel(data));
58
61
  const environmentAttributesSchema = z
59
62
  .object({
60
63
  name: z.string(),
@@ -79,33 +82,17 @@ const environmentResourceSchema = JsonApiResourceSchema.extend({
79
82
  type: z.literal('environments'),
80
83
  attributes: environmentAttributesSchema,
81
84
  });
85
+ // Transform resource to camelCase with raw data preserved
86
+ const transformedEnvironmentSchema = environmentResourceSchema.transform((data) => ({
87
+ ...keysToCamel(data.attributes),
88
+ id: data.id,
89
+ raw: data,
90
+ }));
82
91
  const environmentResponseSchema = createJsonApiResponseSchema(environmentResourceSchema);
83
92
  const environmentCollectionSchema = createJsonApiCollectionSchema(environmentResourceSchema);
93
+ // Simple transformation - schema handles the conversion
84
94
  const mapEnvironment = (resource) => {
85
- const parsed = environmentResourceSchema.parse(resource);
86
- const { attributes } = parsed;
87
- return {
88
- id: parsed.id,
89
- name: attributes.name,
90
- slug: attributes.slug,
91
- status: attributes.status,
92
- createdAt: attributes.created_at,
93
- createdFromAutomation: attributes.created_from_automation,
94
- vanityDomain: attributes.vanity_domain ?? null,
95
- phpMajorVersion: attributes.php_major_version,
96
- buildCommand: attributes.build_command ?? null,
97
- nodeVersion: attributes.node_version ?? null,
98
- deployCommand: attributes.deploy_command ?? null,
99
- usesOctane: attributes.uses_octane,
100
- usesHibernation: attributes.uses_hibernation,
101
- usesPushToDeploy: attributes.uses_push_to_deploy,
102
- usesDeployHook: attributes.uses_deploy_hook,
103
- environmentVariables: attributes.environment_variables?.map((variable) => ({
104
- key: variable.key,
105
- value: variable.value ?? null,
106
- })),
107
- raw: parsed,
108
- };
95
+ return transformedEnvironmentSchema.parse(resource);
109
96
  };
110
97
  const serializeEnvironmentList = (response) => ({
111
98
  data: response.data.map(mapEnvironment),
@@ -247,13 +234,10 @@ const mapVariablesToApi = (variables) => variables.map((variable) => ({
247
234
  key: variable.key,
248
235
  value: variable.value ?? null,
249
236
  }));
250
- const mapEnvironmentLogEntry = (entry) => ({
251
- message: entry.message,
252
- level: entry.level,
253
- type: entry.type,
254
- loggedAt: entry.logged_at,
255
- data: entry.data ? { ...entry.data } : undefined,
256
- });
237
+ // Simple transformation - schema handles the conversion
238
+ const mapEnvironmentLogEntry = (entry) => {
239
+ return transformedLogEntrySchema.parse(entry);
240
+ };
257
241
  export class EnvironmentsResource {
258
242
  client;
259
243
  constructor(client) {
@@ -1,13 +1,141 @@
1
+ import { z } from 'zod';
1
2
  import { HttpClient } from '../http/client.js';
2
- import { JsonApiResponse, JsonApiResource } from '../types/jsonApi.js';
3
- export interface InstanceBackgroundProcess {
4
- type: string;
5
- processes: number;
6
- command?: string;
7
- config?: Record<string, unknown>;
8
- }
9
- export interface Instance {
3
+ import { JsonApiResponse } from '../types/jsonApi.js';
4
+ declare const transformedInstanceSchema: z.ZodPipe<z.ZodObject<{
5
+ id: z.ZodString;
6
+ relationships: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
7
+ data: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
8
+ type: z.ZodString;
9
+ id: z.ZodString;
10
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
11
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
12
+ type: z.ZodString;
13
+ id: z.ZodString;
14
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
15
+ }, z.core.$strip>>]>>;
16
+ links: z.ZodOptional<z.ZodObject<{
17
+ related: z.ZodOptional<z.ZodObject<{
18
+ href: z.ZodOptional<z.ZodString>;
19
+ rel: z.ZodOptional<z.ZodString>;
20
+ describedby: z.ZodOptional<z.ZodString>;
21
+ title: z.ZodOptional<z.ZodString>;
22
+ type: z.ZodOptional<z.ZodString>;
23
+ hreflang: z.ZodOptional<z.ZodString>;
24
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
25
+ }, z.core.$loose>>;
26
+ self: z.ZodOptional<z.ZodObject<{
27
+ href: z.ZodOptional<z.ZodString>;
28
+ rel: z.ZodOptional<z.ZodString>;
29
+ describedby: z.ZodOptional<z.ZodString>;
30
+ title: z.ZodOptional<z.ZodString>;
31
+ type: z.ZodOptional<z.ZodString>;
32
+ hreflang: z.ZodOptional<z.ZodString>;
33
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
34
+ }, z.core.$loose>>;
35
+ }, z.core.$strip>>;
36
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
37
+ }, z.core.$loose>>>;
38
+ links: z.ZodOptional<z.ZodObject<{
39
+ self: z.ZodOptional<z.ZodObject<{
40
+ href: z.ZodOptional<z.ZodString>;
41
+ rel: z.ZodOptional<z.ZodString>;
42
+ describedby: z.ZodOptional<z.ZodString>;
43
+ title: z.ZodOptional<z.ZodString>;
44
+ type: z.ZodOptional<z.ZodString>;
45
+ hreflang: z.ZodOptional<z.ZodString>;
46
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
47
+ }, z.core.$loose>>;
48
+ }, z.core.$strip>>;
49
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
50
+ type: z.ZodLiteral<"instances">;
51
+ attributes: z.ZodObject<{
52
+ name: z.ZodString;
53
+ type: z.ZodString;
54
+ size: z.ZodString;
55
+ scaling_type: z.ZodString;
56
+ min_replicas: z.ZodNumber;
57
+ max_replicas: z.ZodNumber;
58
+ uses_scheduler: z.ZodBoolean;
59
+ uses_sleep_mode: z.ZodOptional<z.ZodBoolean>;
60
+ sleep_timeout: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
61
+ uses_octane: z.ZodOptional<z.ZodBoolean>;
62
+ uses_inertia_ssr: z.ZodOptional<z.ZodBoolean>;
63
+ scaling_cpu_threshold_percentage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
64
+ scaling_memory_threshold_percentage: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
65
+ created_at: z.ZodString;
66
+ }, z.core.$loose>;
67
+ }, z.core.$loose>, z.ZodTransform<{
10
68
  id: string;
69
+ raw: {
70
+ [x: string]: unknown;
71
+ id: string;
72
+ type: "instances";
73
+ attributes: {
74
+ [x: string]: unknown;
75
+ name: string;
76
+ type: string;
77
+ size: string;
78
+ scaling_type: string;
79
+ min_replicas: number;
80
+ max_replicas: number;
81
+ uses_scheduler: boolean;
82
+ created_at: string;
83
+ uses_sleep_mode?: boolean | undefined;
84
+ sleep_timeout?: number | null | undefined;
85
+ uses_octane?: boolean | undefined;
86
+ uses_inertia_ssr?: boolean | undefined;
87
+ scaling_cpu_threshold_percentage?: number | null | undefined;
88
+ scaling_memory_threshold_percentage?: number | null | undefined;
89
+ };
90
+ relationships?: Record<string, {
91
+ [x: string]: unknown;
92
+ data?: {
93
+ type: string;
94
+ id: string;
95
+ meta?: Record<string, any> | undefined;
96
+ } | {
97
+ type: string;
98
+ id: string;
99
+ meta?: Record<string, any> | undefined;
100
+ }[] | undefined;
101
+ links?: {
102
+ related?: {
103
+ [x: string]: unknown;
104
+ href?: string | undefined;
105
+ rel?: string | undefined;
106
+ describedby?: string | undefined;
107
+ title?: string | undefined;
108
+ type?: string | undefined;
109
+ hreflang?: string | undefined;
110
+ meta?: Record<string, any> | undefined;
111
+ } | undefined;
112
+ self?: {
113
+ [x: string]: unknown;
114
+ href?: string | undefined;
115
+ rel?: string | undefined;
116
+ describedby?: string | undefined;
117
+ title?: string | undefined;
118
+ type?: string | undefined;
119
+ hreflang?: string | undefined;
120
+ meta?: Record<string, any> | undefined;
121
+ } | undefined;
122
+ } | undefined;
123
+ meta?: Record<string, any> | undefined;
124
+ }> | undefined;
125
+ links?: {
126
+ self?: {
127
+ [x: string]: unknown;
128
+ href?: string | undefined;
129
+ rel?: string | undefined;
130
+ describedby?: string | undefined;
131
+ title?: string | undefined;
132
+ type?: string | undefined;
133
+ hreflang?: string | undefined;
134
+ meta?: Record<string, any> | undefined;
135
+ } | undefined;
136
+ } | undefined;
137
+ meta?: Record<string, any> | undefined;
138
+ };
11
139
  name: string;
12
140
  type: string;
13
141
  size: string;
@@ -15,15 +143,91 @@ export interface Instance {
15
143
  minReplicas: number;
16
144
  maxReplicas: number;
17
145
  usesScheduler: boolean;
18
- usesSleepMode?: boolean;
19
- sleepTimeout?: number | null;
20
- usesOctane?: boolean;
21
- usesInertiaSsr?: boolean;
22
- scalingCpuThresholdPercentage?: number | null;
23
- scalingMemoryThresholdPercentage?: number | null;
24
146
  createdAt: string;
25
- raw: JsonApiResource;
26
- }
147
+ usesSleepMode?: boolean | undefined;
148
+ sleepTimeout?: number | null | undefined;
149
+ usesOctane?: boolean | undefined;
150
+ usesInertiaSsr?: boolean | undefined;
151
+ scalingCpuThresholdPercentage?: number | null | undefined;
152
+ scalingMemoryThresholdPercentage?: number | null | undefined;
153
+ }, {
154
+ [x: string]: unknown;
155
+ id: string;
156
+ type: "instances";
157
+ attributes: {
158
+ [x: string]: unknown;
159
+ name: string;
160
+ type: string;
161
+ size: string;
162
+ scaling_type: string;
163
+ min_replicas: number;
164
+ max_replicas: number;
165
+ uses_scheduler: boolean;
166
+ created_at: string;
167
+ uses_sleep_mode?: boolean | undefined;
168
+ sleep_timeout?: number | null | undefined;
169
+ uses_octane?: boolean | undefined;
170
+ uses_inertia_ssr?: boolean | undefined;
171
+ scaling_cpu_threshold_percentage?: number | null | undefined;
172
+ scaling_memory_threshold_percentage?: number | null | undefined;
173
+ };
174
+ relationships?: Record<string, {
175
+ [x: string]: unknown;
176
+ data?: {
177
+ type: string;
178
+ id: string;
179
+ meta?: Record<string, any> | undefined;
180
+ } | {
181
+ type: string;
182
+ id: string;
183
+ meta?: Record<string, any> | undefined;
184
+ }[] | undefined;
185
+ links?: {
186
+ related?: {
187
+ [x: string]: unknown;
188
+ href?: string | undefined;
189
+ rel?: string | undefined;
190
+ describedby?: string | undefined;
191
+ title?: string | undefined;
192
+ type?: string | undefined;
193
+ hreflang?: string | undefined;
194
+ meta?: Record<string, any> | undefined;
195
+ } | undefined;
196
+ self?: {
197
+ [x: string]: unknown;
198
+ href?: string | undefined;
199
+ rel?: string | undefined;
200
+ describedby?: string | undefined;
201
+ title?: string | undefined;
202
+ type?: string | undefined;
203
+ hreflang?: string | undefined;
204
+ meta?: Record<string, any> | undefined;
205
+ } | undefined;
206
+ } | undefined;
207
+ meta?: Record<string, any> | undefined;
208
+ }> | undefined;
209
+ links?: {
210
+ self?: {
211
+ [x: string]: unknown;
212
+ href?: string | undefined;
213
+ rel?: string | undefined;
214
+ describedby?: string | undefined;
215
+ title?: string | undefined;
216
+ type?: string | undefined;
217
+ hreflang?: string | undefined;
218
+ meta?: Record<string, any> | undefined;
219
+ } | undefined;
220
+ } | undefined;
221
+ meta?: Record<string, any> | undefined;
222
+ }>>;
223
+ export type Instance = z.infer<typeof transformedInstanceSchema>;
224
+ declare const backgroundProcessSchema: z.ZodObject<{
225
+ type: z.ZodString;
226
+ processes: z.ZodNumber;
227
+ command: z.ZodOptional<z.ZodString>;
228
+ config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
229
+ }, z.core.$strict>;
230
+ export type InstanceBackgroundProcess = z.infer<typeof backgroundProcessSchema>;
27
231
  export interface ListInstancesOptions {
28
232
  include?: Array<'environment' | 'backgroundProcesses'>;
29
233
  filter?: {
@@ -81,3 +285,4 @@ export declare class InstancesResource {
81
285
  update(instanceId: string, payload: UpdateInstancePayload): Promise<InstanceResponse>;
82
286
  delete(instanceId: string): Promise<void>;
83
287
  }
288
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { createJsonApiCollectionSchema, createJsonApiResponseSchema, JsonApiResourceSchema, } from '../types/jsonApi.js';
3
+ import { keysToCamel } from '../utils/caseConversion.js';
3
4
  const instanceAttributesSchema = z
4
5
  .object({
5
6
  name: z.string(),
@@ -22,6 +23,12 @@ const instanceResourceSchema = JsonApiResourceSchema.extend({
22
23
  type: z.literal('instances'),
23
24
  attributes: instanceAttributesSchema,
24
25
  });
26
+ // Transform resource to camelCase with raw data preserved
27
+ const transformedInstanceSchema = instanceResourceSchema.transform((data) => ({
28
+ ...keysToCamel(data.attributes),
29
+ id: data.id,
30
+ raw: data,
31
+ }));
25
32
  const instanceResponseSchema = createJsonApiResponseSchema(instanceResourceSchema);
26
33
  const instanceCollectionSchema = createJsonApiCollectionSchema(instanceResourceSchema);
27
34
  const backgroundProcessSchema = z
@@ -32,27 +39,9 @@ const backgroundProcessSchema = z
32
39
  config: z.record(z.string(), z.any()).optional(),
33
40
  })
34
41
  .strict();
42
+ // Simple transformation - schema handles the conversion
35
43
  const mapInstance = (resource) => {
36
- const parsed = instanceResourceSchema.parse(resource);
37
- const { attributes } = parsed;
38
- return {
39
- id: parsed.id,
40
- name: attributes.name,
41
- type: attributes.type,
42
- size: attributes.size,
43
- scalingType: attributes.scaling_type,
44
- minReplicas: attributes.min_replicas,
45
- maxReplicas: attributes.max_replicas,
46
- usesScheduler: attributes.uses_scheduler,
47
- usesSleepMode: attributes.uses_sleep_mode,
48
- sleepTimeout: attributes.sleep_timeout ?? null,
49
- usesOctane: attributes.uses_octane,
50
- usesInertiaSsr: attributes.uses_inertia_ssr,
51
- scalingCpuThresholdPercentage: attributes.scaling_cpu_threshold_percentage ?? null,
52
- scalingMemoryThresholdPercentage: attributes.scaling_memory_threshold_percentage ?? null,
53
- createdAt: attributes.created_at,
54
- raw: parsed,
55
- };
44
+ return transformedInstanceSchema.parse(resource);
56
45
  };
57
46
  const serializeInstanceList = (response) => ({
58
47
  data: response.data.map(mapInstance),
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Convert a snake_case string to camelCase
3
+ */
4
+ export declare function snakeToCamel(str: string): string;
5
+ /**
6
+ * TypeScript utility type to convert snake_case to camelCase at the type level
7
+ */
8
+ type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : S;
9
+ /**
10
+ * Convert all keys of an object type from snake_case to camelCase
11
+ */
12
+ export type KeysToCamelCase<T> = {
13
+ [K in keyof T as K extends string ? CamelCase<K> : K]: T[K];
14
+ };
15
+ /**
16
+ * Convert all keys in an object from snake_case to camelCase
17
+ * Recursively handles nested objects and arrays
18
+ */
19
+ export declare function keysToCamel<T extends Record<string, unknown>>(obj: T): KeysToCamelCase<T>;
20
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Convert a snake_case string to camelCase
3
+ */
4
+ export function snakeToCamel(str) {
5
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
6
+ }
7
+ /**
8
+ * Convert all keys in an object from snake_case to camelCase
9
+ * Recursively handles nested objects and arrays
10
+ */
11
+ export function keysToCamel(obj) {
12
+ if (!obj || typeof obj !== 'object') {
13
+ return obj;
14
+ }
15
+ if (Array.isArray(obj)) {
16
+ return obj.map((item) => typeof item === 'object' && item !== null ? keysToCamel(item) : item);
17
+ }
18
+ const result = {};
19
+ for (const [key, value] of Object.entries(obj)) {
20
+ const camelKey = snakeToCamel(key);
21
+ // Recursively convert nested objects and arrays
22
+ if (value && typeof value === 'object') {
23
+ if (Array.isArray(value)) {
24
+ result[camelKey] = value.map((item) => typeof item === 'object' && item !== null ? keysToCamel(item) : item);
25
+ }
26
+ else {
27
+ result[camelKey] = keysToCamel(value);
28
+ }
29
+ }
30
+ else {
31
+ result[camelKey] = value;
32
+ }
33
+ }
34
+ return result;
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bosunski/laravel-cloud-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.4",
4
4
  "description": "TypeScript client for the Laravel Cloud API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",