@cloudcannon/sdk 0.0.2 → 0.0.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.
- package/README.md +1514 -0
- package/dist/index.d.ts +15 -9
- package/dist/index.js +15 -6
- package/dist/schema.d.ts +932 -155
- package/dist/src/backup.d.ts +6 -0
- package/dist/src/backup.js +15 -0
- package/dist/src/helpers/query.d.ts +28 -0
- package/dist/src/helpers/query.js +34 -0
- package/dist/src/inbox.d.ts +4 -1
- package/dist/src/inbox.js +5 -3
- package/dist/src/org.d.ts +7 -3
- package/dist/src/org.js +13 -9
- package/dist/src/site.d.ts +13 -3
- package/dist/src/site.js +42 -6
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class BackupClient {
|
|
2
|
+
#uuid;
|
|
3
|
+
#client;
|
|
4
|
+
constructor(uuid, client) {
|
|
5
|
+
this.#uuid = uuid;
|
|
6
|
+
this.#client = client;
|
|
7
|
+
}
|
|
8
|
+
async download() {
|
|
9
|
+
const resp = await this.#client.fetch(`/site-archives/${this.#uuid}/download`);
|
|
10
|
+
if (resp.status === 401 || resp.status === 403) {
|
|
11
|
+
throw new Error('Error downloading backup. Permission denied');
|
|
12
|
+
}
|
|
13
|
+
return resp;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type PaginationOptions = {
|
|
2
|
+
page?: number;
|
|
3
|
+
items?: number;
|
|
4
|
+
};
|
|
5
|
+
export type SortingOptions<Op> = Op extends {
|
|
6
|
+
parameters: {
|
|
7
|
+
query?: infer Q;
|
|
8
|
+
};
|
|
9
|
+
} ? Pick<NonNullable<Q>, Extract<keyof NonNullable<Q>, 'sort_attribute' | 'sort_direction'>> : never;
|
|
10
|
+
export type FilterOptions<Op> = Op extends {
|
|
11
|
+
parameters: {
|
|
12
|
+
query?: infer Q;
|
|
13
|
+
};
|
|
14
|
+
} ? {
|
|
15
|
+
filters?: Omit<NonNullable<Q>, 'page' | 'items' | 'sort_attribute' | 'sort_direction'>;
|
|
16
|
+
} : never;
|
|
17
|
+
export type PaginatedResponse<T> = {
|
|
18
|
+
items: T[];
|
|
19
|
+
current_page?: number;
|
|
20
|
+
total_items?: number;
|
|
21
|
+
total_pages?: number;
|
|
22
|
+
};
|
|
23
|
+
export declare function buildQuery(options?: PaginationOptions & {
|
|
24
|
+
sort_attribute?: string;
|
|
25
|
+
sort_direction?: 'ASC' | 'DESC';
|
|
26
|
+
filters?: Record<string, unknown>;
|
|
27
|
+
}): string;
|
|
28
|
+
export declare function paginatedResponse<T>(items: T[], headers: Headers): PaginatedResponse<T>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function buildQuery(options = {}) {
|
|
2
|
+
const params = new URLSearchParams();
|
|
3
|
+
if (options.page !== undefined)
|
|
4
|
+
params.set('page', String(options.page));
|
|
5
|
+
if (options.items !== undefined)
|
|
6
|
+
params.set('items', String(options.items));
|
|
7
|
+
if (options.sort_attribute !== undefined)
|
|
8
|
+
params.set('sort_attribute', options.sort_attribute);
|
|
9
|
+
if (options.sort_direction !== undefined)
|
|
10
|
+
params.set('sort_direction', options.sort_direction);
|
|
11
|
+
if (options.filters) {
|
|
12
|
+
for (const [key, value] of Object.entries(options.filters)) {
|
|
13
|
+
if (value !== undefined) {
|
|
14
|
+
params.set(key, String(value));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return params.toString();
|
|
19
|
+
}
|
|
20
|
+
export function paginatedResponse(items, headers) {
|
|
21
|
+
const parse = (name) => {
|
|
22
|
+
const value = headers.get(name);
|
|
23
|
+
if (value === null)
|
|
24
|
+
return undefined;
|
|
25
|
+
const parsed = Number(value);
|
|
26
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
items,
|
|
30
|
+
current_page: parse('current_page'),
|
|
31
|
+
total_items: parse('total_items'),
|
|
32
|
+
total_pages: parse('total_pages'),
|
|
33
|
+
};
|
|
34
|
+
}
|
package/dist/src/inbox.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type CloudCannonClient from '../index.ts';
|
|
2
2
|
import type { FormSubmission } from '../index.ts';
|
|
3
|
+
import type { operations } from '../schema.js';
|
|
4
|
+
import { type FilterOptions, type PaginatedResponse, type PaginationOptions, type SortingOptions } from './helpers/query.ts';
|
|
5
|
+
export type ListInboxSubmissionsOptions = PaginationOptions & SortingOptions<operations['Inbox Form Hooks_Index']> & FilterOptions<operations['Inbox Form Hooks_Index']>;
|
|
3
6
|
export declare class InboxClient {
|
|
4
7
|
#private;
|
|
5
8
|
constructor(uuid: string, client: CloudCannonClient);
|
|
6
|
-
getSubmissions(): Promise<FormSubmission
|
|
9
|
+
getSubmissions(options?: ListInboxSubmissionsOptions): Promise<PaginatedResponse<FormSubmission>>;
|
|
7
10
|
}
|
package/dist/src/inbox.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { buildQuery, paginatedResponse, } from "./helpers/query.js";
|
|
1
2
|
export class InboxClient {
|
|
2
3
|
#uuid;
|
|
3
4
|
#client;
|
|
@@ -5,12 +6,13 @@ export class InboxClient {
|
|
|
5
6
|
this.#uuid = uuid;
|
|
6
7
|
this.#client = client;
|
|
7
8
|
}
|
|
8
|
-
async getSubmissions() {
|
|
9
|
-
const
|
|
9
|
+
async getSubmissions(options = {}) {
|
|
10
|
+
const query = buildQuery(options);
|
|
11
|
+
const resp = await this.#client.fetch(`/inboxes/${this.#uuid}/form-hooks?${query}`);
|
|
10
12
|
if (resp.status === 401 || resp.status === 403) {
|
|
11
13
|
throw new Error('Error fetching submissions. Permission denied');
|
|
12
14
|
}
|
|
13
15
|
const submissions = await resp.json();
|
|
14
|
-
return submissions;
|
|
16
|
+
return paginatedResponse(submissions, resp.headers);
|
|
15
17
|
}
|
|
16
18
|
}
|
package/dist/src/org.d.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import type CloudCannonClient from '../index.ts';
|
|
2
2
|
import type { Dam, Inbox, Org, Provider, ProviderDetails, Site } from '../index.ts';
|
|
3
3
|
import type { operations } from '../schema.js';
|
|
4
|
+
import { type FilterOptions, type PaginatedResponse, type PaginationOptions, type SortingOptions } from './helpers/query.ts';
|
|
4
5
|
export interface ConnectSiteOptions extends ProviderDetails {
|
|
5
6
|
folder?: string;
|
|
6
7
|
}
|
|
7
8
|
export type Repository = operations['Providers_Repositories']['responses']['200']['content']['application/json'][number];
|
|
9
|
+
export type ListOrgSitesOptions = PaginationOptions & SortingOptions<operations['Sites_Index']> & FilterOptions<operations['Sites_Index']>;
|
|
10
|
+
export type ListOrgInboxesOptions = PaginationOptions & SortingOptions<operations['Organization Inboxes_Index']> & FilterOptions<operations['Organization Inboxes_Index']>;
|
|
11
|
+
export type ListOrgDamsOptions = PaginationOptions & SortingOptions<operations['DAMs_Index']> & FilterOptions<operations['DAMs_Index']>;
|
|
8
12
|
export type CreateInboxOptions = operations['Organization Inboxes_Create']['requestBody']['content']['application/json'];
|
|
9
13
|
export type CreateDamOptions = operations['DAMs_Create']['requestBody']['content']['application/json'];
|
|
10
14
|
export declare class OrgClient {
|
|
11
15
|
#private;
|
|
12
16
|
constructor(uuid: string, client: CloudCannonClient);
|
|
13
|
-
sites(): Promise<Site
|
|
17
|
+
sites(options?: ListOrgSitesOptions): Promise<PaginatedResponse<Site>>;
|
|
14
18
|
createSite(name: string, stableDomain?: string): Promise<Site>;
|
|
15
19
|
connectSite(name: string, providerDetails: ConnectSiteOptions, stableDomain?: string): Promise<Site>;
|
|
16
20
|
get(): Promise<Org>;
|
|
17
|
-
getInboxes(): Promise<Inbox
|
|
21
|
+
getInboxes(options?: ListOrgInboxesOptions): Promise<PaginatedResponse<Inbox>>;
|
|
18
22
|
createInbox(body: CreateInboxOptions): Promise<Inbox>;
|
|
19
|
-
getDams(): Promise<Dam
|
|
23
|
+
getDams(options?: ListOrgDamsOptions): Promise<PaginatedResponse<Dam>>;
|
|
20
24
|
createDam(body: CreateDamOptions): Promise<Dam>;
|
|
21
25
|
getRepositories(provider: Provider): Promise<Repository[]>;
|
|
22
26
|
}
|
package/dist/src/org.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApiError } from "./errors.js";
|
|
2
|
+
import { buildQuery, paginatedResponse, } from "./helpers/query.js";
|
|
2
3
|
export class OrgClient {
|
|
3
4
|
#uuid;
|
|
4
5
|
#client;
|
|
@@ -6,13 +7,14 @@ export class OrgClient {
|
|
|
6
7
|
this.#uuid = uuid;
|
|
7
8
|
this.#client = client;
|
|
8
9
|
}
|
|
9
|
-
async sites() {
|
|
10
|
-
const
|
|
10
|
+
async sites(options = {}) {
|
|
11
|
+
const query = buildQuery(options);
|
|
12
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/sites?${query}`);
|
|
11
13
|
if (resp.status === 401 || resp.status === 403) {
|
|
12
14
|
throw new Error('Error fetching sites. Permission denied');
|
|
13
15
|
}
|
|
14
16
|
const sites = await resp.json();
|
|
15
|
-
return sites;
|
|
17
|
+
return paginatedResponse(sites, resp.headers);
|
|
16
18
|
}
|
|
17
19
|
async createSite(name, stableDomain) {
|
|
18
20
|
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/sites`, {
|
|
@@ -63,13 +65,14 @@ export class OrgClient {
|
|
|
63
65
|
const org = await resp.json();
|
|
64
66
|
return org;
|
|
65
67
|
}
|
|
66
|
-
async getInboxes() {
|
|
67
|
-
const
|
|
68
|
+
async getInboxes(options = {}) {
|
|
69
|
+
const query = buildQuery(options);
|
|
70
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/inboxes?${query}`);
|
|
68
71
|
if (resp.status === 403) {
|
|
69
72
|
throw new Error('Error fetching inboxes. Permission denied');
|
|
70
73
|
}
|
|
71
74
|
const inboxes = await resp.json();
|
|
72
|
-
return inboxes;
|
|
75
|
+
return paginatedResponse(inboxes, resp.headers);
|
|
73
76
|
}
|
|
74
77
|
async createInbox(body) {
|
|
75
78
|
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/inboxes`, {
|
|
@@ -86,10 +89,11 @@ export class OrgClient {
|
|
|
86
89
|
const inbox = await resp.json();
|
|
87
90
|
return inbox;
|
|
88
91
|
}
|
|
89
|
-
async getDams() {
|
|
90
|
-
const
|
|
92
|
+
async getDams(options = {}) {
|
|
93
|
+
const query = buildQuery(options);
|
|
94
|
+
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/dams?${query}`);
|
|
91
95
|
const dams = await resp.json();
|
|
92
|
-
return dams;
|
|
96
|
+
return paginatedResponse(dams, resp.headers);
|
|
93
97
|
}
|
|
94
98
|
async createDam(body) {
|
|
95
99
|
const resp = await this.#client.fetch(`/orgs/${this.#uuid}/dams`, {
|
package/dist/src/site.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type CloudCannonClient from '../index.ts';
|
|
2
|
-
import type { Build, EditingSession, ProviderDetails, Site, SiteDam, SiteInbox, SiteScan, Sync } from '../index.ts';
|
|
2
|
+
import type { Backup, Build, EditingSession, ProviderDetails, Site, SiteDam, SiteInbox, SiteScan, Sync } from '../index.ts';
|
|
3
3
|
import type { operations } from '../schema.js';
|
|
4
|
+
import { type FilterOptions, type PaginatedResponse, type PaginationOptions, type SortingOptions } from './helpers/query.ts';
|
|
4
5
|
export type BuildConfiguration = Partial<Omit<operations['Sites_UpdateBuild']['requestBody']['content']['application/json'], 'build_configuration'>> & {
|
|
5
6
|
compile?: {
|
|
6
7
|
install_command?: string;
|
|
@@ -22,6 +23,10 @@ export type BuildConfiguration = Partial<Omit<operations['Sites_UpdateBuild']['r
|
|
|
22
23
|
};
|
|
23
24
|
export type UpdateSiteOptions = operations['Sites_Update']['requestBody']['content']['application/json'];
|
|
24
25
|
export type CopySiteOptions = operations['Sites_Copy']['requestBody']['content']['application/json'];
|
|
26
|
+
export type ListSiteBuildsOptions = PaginationOptions & SortingOptions<operations['Builds_Index']> & FilterOptions<operations['Builds_Index']>;
|
|
27
|
+
export type ListSiteBackupsOptions = PaginationOptions & SortingOptions<operations['Backups_Index']> & FilterOptions<operations['Backups_Index']>;
|
|
28
|
+
export type ListSiteSyncsOptions = PaginationOptions & SortingOptions<operations['Syncs_Index']> & FilterOptions<operations['Syncs_Index']>;
|
|
29
|
+
export type CreateBackupOptions = operations['Backups_Create']['requestBody']['content']['application/json'];
|
|
25
30
|
export type ConnectInboxOptions = operations['Site Inboxes_Create']['requestBody']['content']['application/json'];
|
|
26
31
|
export type ConnectDamOptions = operations['Dams_Create']['requestBody']['content']['application/json'];
|
|
27
32
|
export type FileListing = operations['Files_Index']['responses']['200']['content']['application/json'][number];
|
|
@@ -37,11 +42,15 @@ export declare class SiteClient {
|
|
|
37
42
|
delete(): Promise<void>;
|
|
38
43
|
copy(body: CopySiteOptions): Promise<Site>;
|
|
39
44
|
updateBuildConfig(options: BuildConfiguration): Promise<Site>;
|
|
40
|
-
getBuilds(): Promise<Build
|
|
45
|
+
getBuilds(options?: ListSiteBuildsOptions): Promise<PaginatedResponse<Build>>;
|
|
41
46
|
rebuild(): Promise<void>;
|
|
47
|
+
listBackups(options?: ListSiteBackupsOptions): Promise<PaginatedResponse<Backup>>;
|
|
48
|
+
createBackup(body?: CreateBackupOptions): Promise<{
|
|
49
|
+
socket_message_id?: string;
|
|
50
|
+
}>;
|
|
42
51
|
listFiles(): Promise<FileListing[]>;
|
|
43
52
|
getFile(path: string): Promise<Response>;
|
|
44
|
-
getSyncs(): Promise<Sync
|
|
53
|
+
getSyncs(options?: ListSiteSyncsOptions): Promise<PaginatedResponse<Sync>>;
|
|
45
54
|
getScan(): Promise<SiteScan>;
|
|
46
55
|
getScreenshotHashes(): Promise<Record<string, string>>;
|
|
47
56
|
getScreenshot(device: 'desktop' | 'mobile', path: string): Promise<Response>;
|
|
@@ -58,4 +67,5 @@ export declare class SiteClient {
|
|
|
58
67
|
createEditingSession(): Promise<EditingSession>;
|
|
59
68
|
getLatestEditingSession(): Promise<EditingSession>;
|
|
60
69
|
uploadFile(path: string, content: BlobPart, options?: UploadFileOptions): Promise<void>;
|
|
70
|
+
triggerPull(): Promise<void>;
|
|
61
71
|
}
|
package/dist/src/site.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApiError } from "./errors.js";
|
|
2
|
+
import { buildQuery, paginatedResponse, } from "./helpers/query.js";
|
|
2
3
|
export class SiteClient {
|
|
3
4
|
#uuid;
|
|
4
5
|
#client;
|
|
@@ -70,13 +71,14 @@ export class SiteClient {
|
|
|
70
71
|
const site = await resp.json();
|
|
71
72
|
return site;
|
|
72
73
|
}
|
|
73
|
-
async getBuilds() {
|
|
74
|
-
const
|
|
74
|
+
async getBuilds(options = {}) {
|
|
75
|
+
const query = buildQuery(options);
|
|
76
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/builds?${query}`);
|
|
75
77
|
if (resp.status === 401 || resp.status === 403) {
|
|
76
78
|
throw new Error('Error fetching builds. Permission denied');
|
|
77
79
|
}
|
|
78
80
|
const builds = await resp.json();
|
|
79
|
-
return builds;
|
|
81
|
+
return paginatedResponse(builds, resp.headers);
|
|
80
82
|
}
|
|
81
83
|
async rebuild() {
|
|
82
84
|
const resp = await this.#client.fetch(`/sites/${this.#uuid}/builds`, {
|
|
@@ -86,6 +88,30 @@ export class SiteClient {
|
|
|
86
88
|
throw new Error('Error creating build. Permission denied');
|
|
87
89
|
}
|
|
88
90
|
}
|
|
91
|
+
async listBackups(options = {}) {
|
|
92
|
+
const query = buildQuery(options);
|
|
93
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/archives?${query}`);
|
|
94
|
+
if (resp.status === 401) {
|
|
95
|
+
throw new Error('Error fetching backups. Permission denied');
|
|
96
|
+
}
|
|
97
|
+
const items = await resp.json();
|
|
98
|
+
return paginatedResponse(items, resp.headers);
|
|
99
|
+
}
|
|
100
|
+
async createBackup(body = {}) {
|
|
101
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/archives`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
body,
|
|
104
|
+
});
|
|
105
|
+
if (resp.status === 401) {
|
|
106
|
+
throw new Error('Error creating backup. Permission denied');
|
|
107
|
+
}
|
|
108
|
+
if (resp.status === 422) {
|
|
109
|
+
const errorResp = await resp.json();
|
|
110
|
+
throw new ApiError('Error creating backup. Invalid request', errorResp.errors, `/sites/${this.#uuid}/archives`, { method: 'POST', body }, resp.status);
|
|
111
|
+
}
|
|
112
|
+
const result = await resp.json();
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
89
115
|
async listFiles() {
|
|
90
116
|
const resp = await this.#client.fetch(`/sites/${this.#uuid}/files`);
|
|
91
117
|
if (resp.status === 401) {
|
|
@@ -112,13 +138,14 @@ export class SiteClient {
|
|
|
112
138
|
}
|
|
113
139
|
return resp;
|
|
114
140
|
}
|
|
115
|
-
async getSyncs() {
|
|
116
|
-
const
|
|
141
|
+
async getSyncs(options = {}) {
|
|
142
|
+
const query = buildQuery(options);
|
|
143
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/syncs?${query}`);
|
|
117
144
|
if (resp.status === 401) {
|
|
118
145
|
throw new Error('Error fetching syncs. Permission denied');
|
|
119
146
|
}
|
|
120
147
|
const syncs = await resp.json();
|
|
121
|
-
return syncs;
|
|
148
|
+
return paginatedResponse(syncs, resp.headers);
|
|
122
149
|
}
|
|
123
150
|
async getScan() {
|
|
124
151
|
const resp = await this.#client.fetch(`/sites/${this.#uuid}/scans`);
|
|
@@ -342,4 +369,13 @@ export class SiteClient {
|
|
|
342
369
|
previous_content_hash: contentHash,
|
|
343
370
|
});
|
|
344
371
|
}
|
|
372
|
+
async triggerPull() {
|
|
373
|
+
const resp = await this.#client.fetch(`/sites/${this.#uuid}/providers/sync`, {
|
|
374
|
+
method: 'POST',
|
|
375
|
+
});
|
|
376
|
+
if (resp.status === 422) {
|
|
377
|
+
const errorResp = await resp.json();
|
|
378
|
+
throw new ApiError('Error triggering pull on site. Invalid request', errorResp.errors, `/sites/${this.#uuid}/providers/sync`, { method: 'POST' }, resp.status);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
345
381
|
}
|