@cloudcannon/sdk 0.0.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/dist/index.d.ts +77 -0
- package/dist/index.js +60 -0
- package/dist/schema.d.ts +8738 -0
- package/dist/schema.js +5 -0
- package/dist/src/errors.d.ts +7 -0
- package/dist/src/errors.js +13 -0
- package/dist/src/inbox.d.ts +7 -0
- package/dist/src/inbox.js +16 -0
- package/dist/src/org.d.ts +22 -0
- package/dist/src/org.js +121 -0
- package/dist/src/site-inbox.d.ts +9 -0
- package/dist/src/site-inbox.js +24 -0
- package/dist/src/site.d.ts +51 -0
- package/dist/src/site.js +254 -0
- package/package.json +57 -0
package/dist/schema.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export class InboxClient {
|
|
2
|
+
#uuid;
|
|
3
|
+
#client;
|
|
4
|
+
constructor(uuid, client) {
|
|
5
|
+
this.#uuid = uuid;
|
|
6
|
+
this.#client = client;
|
|
7
|
+
}
|
|
8
|
+
async getSubmissions() {
|
|
9
|
+
const resp = await this.#client.fetch(`/inboxes/${this.#uuid}/form-hooks`);
|
|
10
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
11
|
+
throw new Error('Error fetching submissions. Permission denied');
|
|
12
|
+
}
|
|
13
|
+
const submissions = await resp.json();
|
|
14
|
+
return submissions;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type CloudCannonClient from '../index.ts';
|
|
2
|
+
import type { Dam, Inbox, Org, Provider, ProviderDetails, Site } from '../index.ts';
|
|
3
|
+
import type { operations } from '../schema.js';
|
|
4
|
+
export interface ConnectSiteOptions extends ProviderDetails {
|
|
5
|
+
folder?: string;
|
|
6
|
+
}
|
|
7
|
+
export type Repository = operations['Providers_Repositories']['responses']['200']['content']['application/json'][number];
|
|
8
|
+
export type CreateInboxOptions = operations['Organization Inboxes_Create']['requestBody']['content']['application/json'];
|
|
9
|
+
export type CreateDamOptions = operations['DAMs_Create']['requestBody']['content']['application/json'];
|
|
10
|
+
export declare class OrgClient {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(uuid: string, client: CloudCannonClient);
|
|
13
|
+
sites(): Promise<Site[]>;
|
|
14
|
+
createSite(name: string, stableDomain?: string): Promise<Site>;
|
|
15
|
+
connectSite(name: string, providerDetails: ConnectSiteOptions, stableDomain?: string): Promise<Site>;
|
|
16
|
+
get(): Promise<Org>;
|
|
17
|
+
getInboxes(): Promise<Inbox[]>;
|
|
18
|
+
createInbox(body: CreateInboxOptions): Promise<Inbox>;
|
|
19
|
+
getDams(): Promise<Dam[]>;
|
|
20
|
+
createDam(body: CreateDamOptions): Promise<Dam>;
|
|
21
|
+
getRepositories(provider: Provider): Promise<Repository[]>;
|
|
22
|
+
}
|
package/dist/src/org.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
export class OrgClient {
|
|
3
|
+
#uuid;
|
|
4
|
+
#client;
|
|
5
|
+
constructor(uuid, client) {
|
|
6
|
+
this.#uuid = uuid;
|
|
7
|
+
this.#client = client;
|
|
8
|
+
}
|
|
9
|
+
async sites() {
|
|
10
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/sites`);
|
|
11
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
12
|
+
throw new Error('Error fetching sites. Permission denied');
|
|
13
|
+
}
|
|
14
|
+
const sites = await resp.json();
|
|
15
|
+
return sites;
|
|
16
|
+
}
|
|
17
|
+
async createSite(name, stableDomain) {
|
|
18
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/sites`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
body: { site_name: name, stable_domain: stableDomain },
|
|
21
|
+
});
|
|
22
|
+
if (resp.status === 401) {
|
|
23
|
+
throw new Error('Error creating site. Permission denied');
|
|
24
|
+
}
|
|
25
|
+
if (resp.status === 422) {
|
|
26
|
+
const errorResp = await resp.json();
|
|
27
|
+
throw new ApiError('Error creating site. Invalid request', errorResp.errors, `/orgs/${this.#uuid}/sites`, { name, stableDomain }, 422);
|
|
28
|
+
}
|
|
29
|
+
const siteResp = await resp.json();
|
|
30
|
+
if (!siteResp) {
|
|
31
|
+
throw new Error('Invalid response');
|
|
32
|
+
}
|
|
33
|
+
return siteResp;
|
|
34
|
+
}
|
|
35
|
+
async connectSite(name, providerDetails, stableDomain) {
|
|
36
|
+
const body = {
|
|
37
|
+
site_name: name,
|
|
38
|
+
stable_domain: stableDomain,
|
|
39
|
+
provider: providerDetails.provider,
|
|
40
|
+
repo: providerDetails.repository,
|
|
41
|
+
branch: providerDetails.branch,
|
|
42
|
+
folder: providerDetails.folder,
|
|
43
|
+
};
|
|
44
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/sites/connect`, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
body,
|
|
47
|
+
});
|
|
48
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
49
|
+
throw new Error('Error creating site. Permission denied');
|
|
50
|
+
}
|
|
51
|
+
if (resp.status === 422) {
|
|
52
|
+
const errorResp = await resp.json();
|
|
53
|
+
throw new ApiError('Error creating site. Invalid request', errorResp.errors, `/orgs/${this.#uuid}/sites/connect`, body, 422);
|
|
54
|
+
}
|
|
55
|
+
const siteResp = await resp.json();
|
|
56
|
+
return siteResp;
|
|
57
|
+
}
|
|
58
|
+
async get() {
|
|
59
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}`);
|
|
60
|
+
if (resp.status === 403) {
|
|
61
|
+
throw new Error('Error fetching org. Permission denied');
|
|
62
|
+
}
|
|
63
|
+
const org = await resp.json();
|
|
64
|
+
return org;
|
|
65
|
+
}
|
|
66
|
+
async getInboxes() {
|
|
67
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/inboxes`);
|
|
68
|
+
if (resp.status === 403) {
|
|
69
|
+
throw new Error('Error fetching inboxes. Permission denied');
|
|
70
|
+
}
|
|
71
|
+
const inboxes = await resp.json();
|
|
72
|
+
return inboxes;
|
|
73
|
+
}
|
|
74
|
+
async createInbox(body) {
|
|
75
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/inboxes`, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
body,
|
|
78
|
+
});
|
|
79
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
80
|
+
throw new Error('Error creating inbox. Permission denied');
|
|
81
|
+
}
|
|
82
|
+
if (resp.status === 422) {
|
|
83
|
+
const errorResp = await resp.json();
|
|
84
|
+
throw new ApiError('Error creating inbox. Invalid request', errorResp.errors, `/orgs/${this.#uuid}/inboxes`, body, 422);
|
|
85
|
+
}
|
|
86
|
+
const inbox = await resp.json();
|
|
87
|
+
return inbox;
|
|
88
|
+
}
|
|
89
|
+
async getDams() {
|
|
90
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/dams`);
|
|
91
|
+
const dams = await resp.json();
|
|
92
|
+
return dams;
|
|
93
|
+
}
|
|
94
|
+
async createDam(body) {
|
|
95
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/dams`, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
body,
|
|
98
|
+
});
|
|
99
|
+
if (resp.status === 401) {
|
|
100
|
+
throw new Error('Error creating dam. Permission denied');
|
|
101
|
+
}
|
|
102
|
+
if (resp.status === 422) {
|
|
103
|
+
const errorResp = await resp.json();
|
|
104
|
+
throw new ApiError('Error creating dam. Invalid request', errorResp.errors, `/orgs/${this.#uuid}/dams`, body, 422);
|
|
105
|
+
}
|
|
106
|
+
const dam = await resp.json();
|
|
107
|
+
return dam;
|
|
108
|
+
}
|
|
109
|
+
async getRepositories(provider) {
|
|
110
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/providers/${provider}/repositories`);
|
|
111
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
112
|
+
throw new Error('Error fetching repositories. Permission denied');
|
|
113
|
+
}
|
|
114
|
+
if (resp.status === 422) {
|
|
115
|
+
const errorResp = await resp.json();
|
|
116
|
+
throw new ApiError('Error fetching repositories. Invalid request', errorResp.errors, `/orgs/${this.#uuid}/providers/${provider}/repositories`, null, 422);
|
|
117
|
+
}
|
|
118
|
+
const repos = await resp.json();
|
|
119
|
+
return repos;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type CloudCannonClient from '../index.ts';
|
|
2
|
+
import type { SiteInbox } from '../index.ts';
|
|
3
|
+
import type { operations } from '../schema.js';
|
|
4
|
+
export type UpdateInboxOptions = operations['Site Inboxes_Update']['requestBody']['content']['application/json'];
|
|
5
|
+
export declare class SiteInboxClient {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(uuid: string, client: CloudCannonClient);
|
|
8
|
+
update(body: UpdateInboxOptions): Promise<SiteInbox>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
export class SiteInboxClient {
|
|
3
|
+
#uuid;
|
|
4
|
+
#client;
|
|
5
|
+
constructor(uuid, client) {
|
|
6
|
+
this.#uuid = uuid;
|
|
7
|
+
this.#client = client;
|
|
8
|
+
}
|
|
9
|
+
async update(body) {
|
|
10
|
+
const resp = await this.#client.fetch(`/site-inboxes/${this.#uuid}`, {
|
|
11
|
+
method: 'PUT',
|
|
12
|
+
body,
|
|
13
|
+
});
|
|
14
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
15
|
+
throw new Error('Error updating inbox. Permission denied');
|
|
16
|
+
}
|
|
17
|
+
if (resp.status === 422) {
|
|
18
|
+
const errorResp = await resp.json();
|
|
19
|
+
throw new ApiError('Error updating inbox. Invalid request', errorResp.errors, `/site-inboxes/${this.#uuid}`, { method: 'PUT', body }, resp.status);
|
|
20
|
+
}
|
|
21
|
+
const siteInbox = await resp.json();
|
|
22
|
+
return siteInbox;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type CloudCannonClient from '../index.ts';
|
|
2
|
+
import type { Build, ProviderDetails, Site, SiteDam, SiteInbox, SiteScan, Sync } from '../index.ts';
|
|
3
|
+
import type { operations } from '../schema.js';
|
|
4
|
+
export type BuildConfiguration = Partial<Omit<operations['Sites_UpdateBuild']['requestBody']['content']['application/json'], 'build_configuration'>> & {
|
|
5
|
+
compile?: {
|
|
6
|
+
install_command?: string;
|
|
7
|
+
build_command?: string;
|
|
8
|
+
output_path: string;
|
|
9
|
+
environment_variables?: [{
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}];
|
|
13
|
+
hugoVersion?: string;
|
|
14
|
+
denoVersion?: string;
|
|
15
|
+
rubyVersion?: string;
|
|
16
|
+
nodeVersion?: string;
|
|
17
|
+
preserved_paths?: string[];
|
|
18
|
+
preserveOutput?: boolean;
|
|
19
|
+
includeGit?: boolean;
|
|
20
|
+
manually_configure_urls?: boolean;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export type UpdateSiteOptions = operations['Sites_Update']['requestBody']['content']['application/json'];
|
|
24
|
+
export type CopySiteOptions = operations['Sites_Copy']['requestBody']['content']['application/json'];
|
|
25
|
+
export type ConnectInboxOptions = operations['Site Inboxes_Create']['requestBody']['content']['application/json'];
|
|
26
|
+
export type ConnectDamOptions = operations['Dams_Create']['requestBody']['content']['application/json'];
|
|
27
|
+
export declare class SiteClient {
|
|
28
|
+
#private;
|
|
29
|
+
constructor(uuid: string, client: CloudCannonClient);
|
|
30
|
+
get(): Promise<Site>;
|
|
31
|
+
update(body: UpdateSiteOptions): Promise<Site>;
|
|
32
|
+
delete(): Promise<void>;
|
|
33
|
+
copy(body: CopySiteOptions): Promise<Site>;
|
|
34
|
+
updateBuildConfig(options: BuildConfiguration): Promise<Site>;
|
|
35
|
+
getBuilds(): Promise<Build[]>;
|
|
36
|
+
rebuild(): Promise<void>;
|
|
37
|
+
getFile(path: string): Promise<Response>;
|
|
38
|
+
getSyncs(): Promise<Sync[]>;
|
|
39
|
+
getScan(): Promise<SiteScan>;
|
|
40
|
+
getScreenshotHashes(): Promise<Record<string, string>>;
|
|
41
|
+
getScreenshot(device: 'desktop' | 'mobile', path: string): Promise<Response>;
|
|
42
|
+
connectSourceProvider(options: ProviderDetails): Promise<Site>;
|
|
43
|
+
updateSourceProvider(options: Omit<ProviderDetails, 'provider'>): Promise<Site>;
|
|
44
|
+
disconnectSourceProvider(): Promise<Site>;
|
|
45
|
+
connectOutputProvider(options: ProviderDetails): Promise<Site>;
|
|
46
|
+
disconnectOutputProvider(): Promise<Site>;
|
|
47
|
+
getInboxConnections(): Promise<SiteInbox[]>;
|
|
48
|
+
connectInbox(body: ConnectInboxOptions): Promise<SiteInbox>;
|
|
49
|
+
getDamConnections(): Promise<SiteDam[]>;
|
|
50
|
+
connectDam(body: ConnectDamOptions): Promise<SiteDam>;
|
|
51
|
+
}
|
package/dist/src/site.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { ApiError } from "./errors.js";
|
|
2
|
+
export class SiteClient {
|
|
3
|
+
#uuid;
|
|
4
|
+
#client;
|
|
5
|
+
constructor(uuid, client) {
|
|
6
|
+
this.#uuid = uuid;
|
|
7
|
+
this.#client = client;
|
|
8
|
+
}
|
|
9
|
+
async get() {
|
|
10
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}`);
|
|
11
|
+
const site = await resp.json();
|
|
12
|
+
return site;
|
|
13
|
+
}
|
|
14
|
+
async update(body) {
|
|
15
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}`, {
|
|
16
|
+
method: 'PUT',
|
|
17
|
+
body,
|
|
18
|
+
});
|
|
19
|
+
if (resp.status === 422) {
|
|
20
|
+
const errorResp = await resp.json();
|
|
21
|
+
throw new ApiError('Error updating site. Invalid request', errorResp.errors, `/sites/${this.#uuid}`, { method: 'PUT', body }, resp.status);
|
|
22
|
+
}
|
|
23
|
+
const site = await resp.json();
|
|
24
|
+
return site;
|
|
25
|
+
}
|
|
26
|
+
async delete() {
|
|
27
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}`, {
|
|
28
|
+
method: 'DELETE',
|
|
29
|
+
});
|
|
30
|
+
if (resp.status === 422) {
|
|
31
|
+
const errorResp = await resp.json();
|
|
32
|
+
throw new ApiError('Error deleting site. Invalid request', errorResp.errors, `/sites/${this.#uuid}`, { method: 'DELETE' }, resp.status);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async copy(body) {
|
|
36
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/copy`, {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body,
|
|
39
|
+
});
|
|
40
|
+
if (resp.status === 402) {
|
|
41
|
+
throw new Error('Error copying site. Feature not on plan');
|
|
42
|
+
}
|
|
43
|
+
if (resp.status === 422) {
|
|
44
|
+
const errorResp = await resp.json();
|
|
45
|
+
throw new ApiError('Error copying site. Invalid request', errorResp.errors, `/sites/${this.#uuid}/copy`, { method: 'POST', body }, resp.status);
|
|
46
|
+
}
|
|
47
|
+
const site = await resp.json();
|
|
48
|
+
return site;
|
|
49
|
+
}
|
|
50
|
+
async updateBuildConfig(options) {
|
|
51
|
+
const buildConfiguration = {
|
|
52
|
+
compile: {
|
|
53
|
+
...options.compile,
|
|
54
|
+
preserved_paths: options.compile?.preserved_paths?.join(','),
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const body = {
|
|
58
|
+
...options,
|
|
59
|
+
uses_i18n: !!options.uses_i18n,
|
|
60
|
+
build_configuration: JSON.stringify(buildConfiguration),
|
|
61
|
+
};
|
|
62
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/build`, {
|
|
63
|
+
method: 'PUT',
|
|
64
|
+
body,
|
|
65
|
+
});
|
|
66
|
+
if (resp.status === 422) {
|
|
67
|
+
const errorResp = await resp.json();
|
|
68
|
+
throw new ApiError('Error updating build configuration. Invalid request', errorResp.errors, `/sites/${this.#uuid}/build`, { method: 'PUT', body }, resp.status);
|
|
69
|
+
}
|
|
70
|
+
const site = await resp.json();
|
|
71
|
+
return site;
|
|
72
|
+
}
|
|
73
|
+
async getBuilds() {
|
|
74
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/builds`);
|
|
75
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
76
|
+
throw new Error('Error fetching builds. Permission denied');
|
|
77
|
+
}
|
|
78
|
+
const builds = await resp.json();
|
|
79
|
+
return builds;
|
|
80
|
+
}
|
|
81
|
+
async rebuild() {
|
|
82
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/builds`, {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
});
|
|
85
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
86
|
+
throw new Error('Error creating build. Permission denied');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async getFile(path) {
|
|
90
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/files/${encodeURIComponent(path)}`);
|
|
91
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
92
|
+
throw new Error('Error fetching file. Permission denied');
|
|
93
|
+
}
|
|
94
|
+
if (resp.status === 404) {
|
|
95
|
+
throw new Error('Error fetching file. File not found');
|
|
96
|
+
}
|
|
97
|
+
if (resp.status === 422) {
|
|
98
|
+
const errorResp = await resp.json();
|
|
99
|
+
throw new ApiError('Error fetching file. Invalid request', errorResp.errors, `/sites/${this.#uuid}/files/${encodeURIComponent(path)}`, {}, resp.status);
|
|
100
|
+
}
|
|
101
|
+
return resp;
|
|
102
|
+
}
|
|
103
|
+
async getSyncs() {
|
|
104
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/syncs`);
|
|
105
|
+
if (resp.status === 401) {
|
|
106
|
+
throw new Error('Error fetching syncs. Permission denied');
|
|
107
|
+
}
|
|
108
|
+
const syncs = await resp.json();
|
|
109
|
+
return syncs;
|
|
110
|
+
}
|
|
111
|
+
async getScan() {
|
|
112
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/scans`);
|
|
113
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
114
|
+
throw new Error('Error fetching scans. Permission denied');
|
|
115
|
+
}
|
|
116
|
+
const scan = await resp.json();
|
|
117
|
+
return scan;
|
|
118
|
+
}
|
|
119
|
+
async getScreenshotHashes() {
|
|
120
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/screenshots`);
|
|
121
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
122
|
+
throw new Error('Error fetching file. Permission denied');
|
|
123
|
+
}
|
|
124
|
+
const screenshots = await resp.json();
|
|
125
|
+
return screenshots;
|
|
126
|
+
}
|
|
127
|
+
async getScreenshot(device, path) {
|
|
128
|
+
return this.#client.fetch(`/sites/${this.#uuid}/screenshots/${device}?path=${encodeURIComponent(path)}`);
|
|
129
|
+
}
|
|
130
|
+
async connectSourceProvider(options) {
|
|
131
|
+
const body = {
|
|
132
|
+
storage_provider: options.provider,
|
|
133
|
+
custom_data: {
|
|
134
|
+
branch: options.branch,
|
|
135
|
+
full_name: options.repository,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/providers`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
body,
|
|
141
|
+
});
|
|
142
|
+
if (resp.status === 422) {
|
|
143
|
+
const errorResp = await resp.json();
|
|
144
|
+
throw new ApiError('Error adding provider. Invalid request', errorResp.errors, `/sites/${this.#uuid}/providers`, { method: 'POST', body }, resp.status);
|
|
145
|
+
}
|
|
146
|
+
const site = await resp.json();
|
|
147
|
+
return site;
|
|
148
|
+
}
|
|
149
|
+
async updateSourceProvider(options) {
|
|
150
|
+
const body = {
|
|
151
|
+
custom_data: {
|
|
152
|
+
branch: options.branch,
|
|
153
|
+
full_name: options.repository,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/providers`, {
|
|
157
|
+
method: 'PUT',
|
|
158
|
+
body,
|
|
159
|
+
});
|
|
160
|
+
if (resp.status === 422) {
|
|
161
|
+
const errorResp = await resp.json();
|
|
162
|
+
throw new ApiError('Error updating provider. Invalid request', errorResp.errors, `/sites/${this.#uuid}/providers`, { method: 'PUT', body }, resp.status);
|
|
163
|
+
}
|
|
164
|
+
const site = await resp.json();
|
|
165
|
+
return site;
|
|
166
|
+
}
|
|
167
|
+
async disconnectSourceProvider() {
|
|
168
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/providers`, {
|
|
169
|
+
method: 'DELETE',
|
|
170
|
+
});
|
|
171
|
+
if (resp.status === 422) {
|
|
172
|
+
const errorResp = await resp.json();
|
|
173
|
+
throw new ApiError('Error removing provider. Invalid request', errorResp.errors, `/sites/${this.#uuid}/providers`, { method: 'DELETE' }, resp.status);
|
|
174
|
+
}
|
|
175
|
+
const site = await resp.json();
|
|
176
|
+
return site;
|
|
177
|
+
}
|
|
178
|
+
async connectOutputProvider(options) {
|
|
179
|
+
const body = {
|
|
180
|
+
storage_provider: options.provider,
|
|
181
|
+
custom_data: {
|
|
182
|
+
branch: options.branch,
|
|
183
|
+
full_name: options.repository,
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/output-providers`, {
|
|
187
|
+
method: 'POST',
|
|
188
|
+
body,
|
|
189
|
+
});
|
|
190
|
+
if (resp.status === 422) {
|
|
191
|
+
const errorResp = await resp.json();
|
|
192
|
+
throw new ApiError('Error adding output provider. Invalid request', errorResp.errors, `/sites/${this.#uuid}/output-providers`, { method: 'POST', body }, resp.status);
|
|
193
|
+
}
|
|
194
|
+
const site = await resp.json();
|
|
195
|
+
return site;
|
|
196
|
+
}
|
|
197
|
+
async disconnectOutputProvider() {
|
|
198
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/output-providers`, {
|
|
199
|
+
method: 'DELETE',
|
|
200
|
+
});
|
|
201
|
+
if (resp.status === 422) {
|
|
202
|
+
const errorResp = await resp.json();
|
|
203
|
+
throw new ApiError('Error removing output provider. Invalid request', errorResp.errors, `/sites/${this.#uuid}/output-providers`, { method: 'DELETE' }, resp.status);
|
|
204
|
+
}
|
|
205
|
+
const site = await resp.json();
|
|
206
|
+
return site;
|
|
207
|
+
}
|
|
208
|
+
async getInboxConnections() {
|
|
209
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/inboxes`);
|
|
210
|
+
if (resp.status === 403) {
|
|
211
|
+
throw new Error('Error fetching inboxes. Permission denied');
|
|
212
|
+
}
|
|
213
|
+
const inboxes = await resp.json();
|
|
214
|
+
return inboxes;
|
|
215
|
+
}
|
|
216
|
+
async connectInbox(body) {
|
|
217
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/inboxes`, {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
body,
|
|
220
|
+
});
|
|
221
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
222
|
+
throw new Error('Error creating inbox. Permission denied');
|
|
223
|
+
}
|
|
224
|
+
if (resp.status === 422) {
|
|
225
|
+
const errorResp = await resp.json();
|
|
226
|
+
throw new ApiError('Error creating inbox. Invalid request', errorResp.errors, `/sites/${this.#uuid}/inboxes`, { method: 'POST', body }, resp.status);
|
|
227
|
+
}
|
|
228
|
+
const inbox = await resp.json();
|
|
229
|
+
return inbox;
|
|
230
|
+
}
|
|
231
|
+
async getDamConnections() {
|
|
232
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/dams`);
|
|
233
|
+
if (resp.status === 403) {
|
|
234
|
+
throw new Error('Error fetching dams. Permission denied');
|
|
235
|
+
}
|
|
236
|
+
const dams = await resp.json();
|
|
237
|
+
return dams;
|
|
238
|
+
}
|
|
239
|
+
async connectDam(body) {
|
|
240
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/dams`, {
|
|
241
|
+
method: 'POST',
|
|
242
|
+
body,
|
|
243
|
+
});
|
|
244
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
245
|
+
throw new Error('Error creating dam. Permission denied');
|
|
246
|
+
}
|
|
247
|
+
if (resp.status === 422) {
|
|
248
|
+
const errorResp = await resp.json();
|
|
249
|
+
throw new ApiError('Error creating dam. Invalid request', errorResp.errors, `/sites/${this.#uuid}/dams`, { method: 'POST', body }, resp.status);
|
|
250
|
+
}
|
|
251
|
+
const dam = await resp.json();
|
|
252
|
+
return dam;
|
|
253
|
+
}
|
|
254
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cloudcannon/sdk",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"description": "REST API client for the CloudCannon CMS.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cloudcannon",
|
|
8
|
+
"cms",
|
|
9
|
+
"sdk",
|
|
10
|
+
"static site generator",
|
|
11
|
+
"configuration"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/CloudCannon/sdk#readme",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/CloudCannon/sdk.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/CloudCannon/sdk/issues",
|
|
20
|
+
"email": "support@cloudcannon.com"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"devEngines": {
|
|
33
|
+
"packageManager": {
|
|
34
|
+
"name": "npm"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc",
|
|
42
|
+
"test": "node --test",
|
|
43
|
+
"test:watch": "node --test --watch",
|
|
44
|
+
"test:coverage": "node --test --test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info",
|
|
45
|
+
"lint": "biome check && tsc --noEmit",
|
|
46
|
+
"lint:fix": "biome check --fix"
|
|
47
|
+
},
|
|
48
|
+
"author": "CloudCannon <support@cloudcannon.com>",
|
|
49
|
+
"license": "ISC",
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@biomejs/biome": "2.4.13",
|
|
52
|
+
"@types/node": "25.6.0",
|
|
53
|
+
"typescript": "6.0.3"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
}
|
|
57
|
+
}
|