@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.
@@ -48,7 +48,7 @@ export class HttpClient {
48
48
  signal: config.signal,
49
49
  });
50
50
  const contentType = response.headers.get('content-type') ?? '';
51
- const isJson = contentType.includes('application/json');
51
+ const isJson = /json/i.test(contentType);
52
52
  let parsedBody;
53
53
  if (response.status !== 204) {
54
54
  if (isJson) {
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { HttpClient } from '../http/client.js';
3
- import { JsonApiResponse, JsonApiResource } from '../types/jsonApi.js';
3
+ import { JsonApiResponse } from '../types/jsonApi.js';
4
4
  declare const regionSchema: z.ZodEnum<{
5
5
  "us-east-2": "us-east-2";
6
6
  "us-east-1": "us-east-1";
@@ -10,23 +10,208 @@ declare const regionSchema: z.ZodEnum<{
10
10
  "ap-southeast-1": "ap-southeast-1";
11
11
  "ap-southeast-2": "ap-southeast-2";
12
12
  "ca-central-1": "ca-central-1";
13
- "me-central-1": "me-central-1";
14
13
  }>;
15
- export type Region = z.infer<typeof regionSchema>;
16
- export interface ApplicationRepository {
17
- fullName?: string;
18
- defaultBranch?: string;
19
- }
20
- export interface Application {
14
+ declare const transformedApplicationSchema: z.ZodPipe<z.ZodObject<{
15
+ id: z.ZodString;
16
+ relationships: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
17
+ data: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
18
+ type: z.ZodString;
19
+ id: z.ZodString;
20
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
21
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
22
+ type: z.ZodString;
23
+ id: z.ZodString;
24
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
25
+ }, z.core.$strip>>]>>;
26
+ links: z.ZodOptional<z.ZodObject<{
27
+ related: z.ZodOptional<z.ZodObject<{
28
+ href: z.ZodOptional<z.ZodString>;
29
+ rel: z.ZodOptional<z.ZodString>;
30
+ describedby: z.ZodOptional<z.ZodString>;
31
+ title: z.ZodOptional<z.ZodString>;
32
+ type: z.ZodOptional<z.ZodString>;
33
+ hreflang: z.ZodOptional<z.ZodString>;
34
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
35
+ }, z.core.$loose>>;
36
+ self: z.ZodOptional<z.ZodObject<{
37
+ href: z.ZodOptional<z.ZodString>;
38
+ rel: z.ZodOptional<z.ZodString>;
39
+ describedby: z.ZodOptional<z.ZodString>;
40
+ title: z.ZodOptional<z.ZodString>;
41
+ type: z.ZodOptional<z.ZodString>;
42
+ hreflang: z.ZodOptional<z.ZodString>;
43
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
44
+ }, z.core.$loose>>;
45
+ }, z.core.$strip>>;
46
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
47
+ }, z.core.$loose>>>;
48
+ links: z.ZodOptional<z.ZodObject<{
49
+ self: z.ZodOptional<z.ZodObject<{
50
+ href: z.ZodOptional<z.ZodString>;
51
+ rel: z.ZodOptional<z.ZodString>;
52
+ describedby: z.ZodOptional<z.ZodString>;
53
+ title: z.ZodOptional<z.ZodString>;
54
+ type: z.ZodOptional<z.ZodString>;
55
+ hreflang: z.ZodOptional<z.ZodString>;
56
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
57
+ }, z.core.$loose>>;
58
+ }, z.core.$strip>>;
59
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
60
+ type: z.ZodLiteral<"applications">;
61
+ attributes: z.ZodObject<{
62
+ name: z.ZodString;
63
+ slug: z.ZodString;
64
+ region: z.ZodString;
65
+ slack_channel: z.ZodOptional<z.ZodNullable<z.ZodString>>;
66
+ created_at: z.ZodString;
67
+ repository: z.ZodOptional<z.ZodNullable<z.ZodObject<{
68
+ full_name: z.ZodString;
69
+ default_branch: z.ZodString;
70
+ }, z.core.$strict>>>;
71
+ }, z.core.$loose>;
72
+ }, z.core.$loose>, z.ZodTransform<{
21
73
  id: string;
74
+ raw: {
75
+ [x: string]: unknown;
76
+ id: string;
77
+ type: "applications";
78
+ attributes: {
79
+ [x: string]: unknown;
80
+ name: string;
81
+ slug: string;
82
+ region: string;
83
+ created_at: string;
84
+ slack_channel?: string | null | undefined;
85
+ repository?: {
86
+ full_name: string;
87
+ default_branch: string;
88
+ } | 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
+ };
22
139
  name: string;
23
140
  slug: string;
24
141
  region: string;
25
- slackChannel?: string | null;
26
142
  createdAt: string;
27
- repository?: ApplicationRepository;
28
- raw: JsonApiResource;
29
- }
143
+ slackChannel?: string | null | undefined;
144
+ repository?: {
145
+ full_name: string;
146
+ default_branch: string;
147
+ } | null | undefined;
148
+ }, {
149
+ [x: string]: unknown;
150
+ id: string;
151
+ type: "applications";
152
+ attributes: {
153
+ [x: string]: unknown;
154
+ name: string;
155
+ slug: string;
156
+ region: string;
157
+ created_at: string;
158
+ slack_channel?: string | null | undefined;
159
+ repository?: {
160
+ full_name: string;
161
+ default_branch: string;
162
+ } | null | undefined;
163
+ };
164
+ relationships?: Record<string, {
165
+ [x: string]: unknown;
166
+ data?: {
167
+ type: string;
168
+ id: string;
169
+ meta?: Record<string, any> | undefined;
170
+ } | {
171
+ type: string;
172
+ id: string;
173
+ meta?: Record<string, any> | undefined;
174
+ }[] | undefined;
175
+ links?: {
176
+ related?: {
177
+ [x: string]: unknown;
178
+ href?: string | undefined;
179
+ rel?: string | undefined;
180
+ describedby?: string | undefined;
181
+ title?: string | undefined;
182
+ type?: string | undefined;
183
+ hreflang?: string | undefined;
184
+ meta?: Record<string, any> | undefined;
185
+ } | undefined;
186
+ self?: {
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
+ } | undefined;
197
+ meta?: Record<string, any> | undefined;
198
+ }> | undefined;
199
+ links?: {
200
+ self?: {
201
+ [x: string]: unknown;
202
+ href?: string | undefined;
203
+ rel?: string | undefined;
204
+ describedby?: string | undefined;
205
+ title?: string | undefined;
206
+ type?: string | undefined;
207
+ hreflang?: string | undefined;
208
+ meta?: Record<string, any> | undefined;
209
+ } | undefined;
210
+ } | undefined;
211
+ meta?: Record<string, any> | undefined;
212
+ }>>;
213
+ export type Region = z.infer<typeof regionSchema>;
214
+ export type Application = z.infer<typeof transformedApplicationSchema>;
30
215
  export interface ListApplicationsOptions {
31
216
  include?: Array<'organization' | 'environments' | 'defaultEnvironment'>;
32
217
  filter?: {
@@ -50,6 +235,7 @@ export interface UpdateApplicationPayload {
50
235
  defaultEnvironmentId?: string;
51
236
  repository?: string;
52
237
  slackChannel?: string | null;
238
+ avatar?: File | Blob;
53
239
  }
54
240
  export interface ApplicationListResponse extends JsonApiResponse<Application[]> {
55
241
  }
@@ -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 regionSchema = z.enum([
4
5
  'us-east-2',
5
6
  'us-east-1',
@@ -9,14 +10,13 @@ const regionSchema = z.enum([
9
10
  'ap-southeast-1',
10
11
  'ap-southeast-2',
11
12
  'ca-central-1',
12
- 'me-central-1',
13
13
  ]);
14
14
  const repositorySchema = z
15
15
  .object({
16
16
  full_name: z.string(),
17
17
  default_branch: z.string(),
18
18
  })
19
- .partial();
19
+ .strict();
20
20
  const applicationAttributesSchema = z
21
21
  .object({
22
22
  name: z.string(),
@@ -24,33 +24,24 @@ const applicationAttributesSchema = z
24
24
  region: z.string(),
25
25
  slack_channel: z.string().nullable().optional(),
26
26
  created_at: z.string(),
27
- repository: repositorySchema.optional(),
27
+ repository: repositorySchema.nullable().optional(),
28
28
  })
29
29
  .passthrough();
30
30
  const applicationResourceSchema = JsonApiResourceSchema.extend({
31
31
  type: z.literal('applications'),
32
32
  attributes: applicationAttributesSchema,
33
33
  });
34
+ // Transform resource to camelCase with raw data preserved
35
+ const transformedApplicationSchema = applicationResourceSchema.transform((data) => ({
36
+ ...keysToCamel(data.attributes),
37
+ id: data.id,
38
+ raw: data,
39
+ }));
34
40
  const applicationResponseSchema = createJsonApiResponseSchema(applicationResourceSchema);
35
41
  const applicationCollectionSchema = createJsonApiCollectionSchema(applicationResourceSchema);
42
+ // Simple transformation - schema handles the conversion
36
43
  const mapApplication = (resource) => {
37
- const parsed = applicationResourceSchema.parse(resource);
38
- const { attributes } = parsed;
39
- return {
40
- id: parsed.id,
41
- name: attributes.name,
42
- slug: attributes.slug,
43
- region: attributes.region,
44
- slackChannel: attributes.slack_channel ?? null,
45
- createdAt: attributes.created_at,
46
- repository: attributes.repository
47
- ? {
48
- fullName: attributes.repository.full_name,
49
- defaultBranch: attributes.repository.default_branch,
50
- }
51
- : undefined,
52
- raw: parsed,
53
- };
44
+ return transformedApplicationSchema.parse(resource);
54
45
  };
55
46
  const serializeApplicationList = (response) => ({
56
47
  data: response.data.map(mapApplication),
@@ -64,6 +55,22 @@ const serializeApplicationResponse = (response) => ({
64
55
  meta: response.meta,
65
56
  links: response.links,
66
57
  });
58
+ const createApplicationSchema = z
59
+ .object({
60
+ repository: z.string().min(1),
61
+ name: z.string().min(3).max(40),
62
+ region: regionSchema,
63
+ })
64
+ .strict();
65
+ const updateApplicationSchema = z
66
+ .object({
67
+ name: z.string().min(3).max(40).optional(),
68
+ slug: z.string().min(3).optional(),
69
+ defaultEnvironmentId: z.string().optional(),
70
+ repository: z.string().optional(),
71
+ slackChannel: z.string().nullable().optional(),
72
+ })
73
+ .strict();
67
74
  export class ApplicationsResource {
68
75
  client;
69
76
  constructor(client) {
@@ -110,33 +117,22 @@ export class ApplicationsResource {
110
117
  return serializeApplicationResponse(response);
111
118
  }
112
119
  async create(payload) {
113
- const parsePayload = z
114
- .object({
115
- repository: z.string().min(1),
116
- name: z.string().min(3).max(40),
117
- region: regionSchema,
118
- })
119
- .parse(payload);
120
+ const parsedPayload = createApplicationSchema.parse(payload);
120
121
  const response = await this.client.request({
121
122
  path: '/applications',
122
123
  method: 'POST',
123
- json: parsePayload,
124
+ json: parsedPayload,
124
125
  schema: applicationResponseSchema,
125
126
  });
126
127
  return serializeApplicationResponse(response);
127
128
  }
128
129
  async update(applicationId, payload) {
129
- const parsedPayload = z
130
- .object({
131
- name: z.string().min(3).max(40).optional(),
132
- slug: z.string().min(3).optional(),
133
- defaultEnvironmentId: z.string().optional(),
134
- repository: z.string().optional(),
135
- slackChannel: z.string().nullable().optional(),
136
- })
137
- .strict()
138
- .parse(payload);
130
+ const { avatar, ...rest } = payload;
131
+ const parsedPayload = updateApplicationSchema.parse(rest);
139
132
  const form = new FormData();
133
+ if (avatar !== undefined) {
134
+ form.set('avatar', avatar);
135
+ }
140
136
  if (parsedPayload.name !== undefined) {
141
137
  form.set('name', parsedPayload.name);
142
138
  }