@cloudcannon/sdk 0.0.1 → 0.0.3

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 CHANGED
@@ -1,11 +1,18 @@
1
1
  import type { components, operations, paths } from './schema.ts';
2
+ import { BackupClient } from './src/backup.ts';
3
+ import { BuildClient } from './src/build.ts';
4
+ import { type CommitEditingSessionOptions, type CommitEditingSessionResponse, EditingSessionClient } from './src/editing-session.ts';
5
+ import { EditingSessionFileClient } from './src/editing-session-file.ts';
6
+ import { type FilterOptions, type PaginatedResponse, type PaginationOptions, type SortingOptions } from './src/helpers/query.ts';
2
7
  import { InboxClient } from './src/inbox.ts';
3
8
  import { OrgClient } from './src/org.ts';
4
9
  import { type BuildConfiguration, SiteClient } from './src/site.ts';
5
10
  import { SiteInboxClient } from './src/site-inbox.ts';
6
- export type { BuildConfiguration };
11
+ import { SyncClient } from './src/sync.ts';
12
+ export type { BuildConfiguration, CommitEditingSessionOptions, CommitEditingSessionResponse, FilterOptions, PaginatedResponse, PaginationOptions, SortingOptions, };
7
13
  export type Provider = operations['Providers_Repositories']['parameters']['path']['provider'];
8
14
  export type Site = components['schemas']['SiteBlueprint'];
15
+ export type Backup = components['schemas']['SiteArchiveBlueprint'];
9
16
  export type Org = components['schemas']['OrgBlueprintFull'];
10
17
  export type Build = components['schemas']['BuildBlueprint'];
11
18
  export type Sync = components['schemas']['SyncBlueprint'];
@@ -15,6 +22,10 @@ export type SiteDam = components['schemas']['SiteDamBlueprint'];
15
22
  export type FormSubmission = components['schemas']['FormHookBlueprint'];
16
23
  export type Inbox = components['schemas']['InboxBlueprint'];
17
24
  export type Dam = components['schemas']['DamBlueprint'];
25
+ export type EditingSession = components['schemas']['EditingSessionBlueprint'];
26
+ export type EditingSessionFile = components['schemas']['EditingSessionFileBlueprint'];
27
+ export type EditingSessionFileContribution = components['schemas']['EditingSessionFileContributionBlueprint'];
28
+ export type UploadData = operations['Index_UploadData']['responses']['200']['content']['application/json'];
18
29
  export type ProviderDetails = {
19
30
  provider: Provider;
20
31
  repository: string;
@@ -22,6 +33,7 @@ export type ProviderDetails = {
22
33
  };
23
34
  type ParamToString<S extends string> = S extends `${infer A}/{${string}}/${infer B}` ? `${A}/${string}/${ParamToString<B>}` : S extends `${infer A}/{${string}}` ? `${A}/${string}` : S;
24
35
  type StripPrefix<S extends string> = S extends `/api/v0${infer Rest}` ? Rest : never;
36
+ type StripParams<S extends string> = S extends `${infer Path}?${string}` ? Path : S;
25
37
  type RequestBody<T> = T extends {
26
38
  requestBody: {
27
39
  content: {
@@ -53,7 +65,7 @@ type Split<S extends string> = S extends `${infer Head}/${infer Tail}` ? [Head,
53
65
  type SegmentMatch<A extends string[], B extends string[]> = A['length'] extends B['length'] ? A extends [infer AH extends string, ...infer AT extends string[]] ? B extends [infer BH extends string, ...infer BT extends string[]] ? AH extends BH ? SegmentMatch<AT, BT> : never : never : true : never;
54
66
  type MatchURL<M extends keyof paths[keyof paths], U extends string> = {
55
67
  [K in keyof paths]: [
56
- SegmentMatch<Split<U>, Split<ParamToString<StripPrefix<K & string>>>>
68
+ SegmentMatch<Split<StripParams<U>>, Split<ParamToString<StripPrefix<K & string>>>>
57
69
  ] extends [never] ? never : RequestParams<paths[K][M]> extends never ? never : paths[K];
58
70
  }[keyof paths];
59
71
  type ValidURL<M extends keyof paths[keyof paths], U extends string> = MatchURL<M, U> extends never ? {
@@ -73,5 +85,11 @@ export default class CloudCannonClient {
73
85
  site(uuid: string): SiteClient;
74
86
  inbox(uuid: string): InboxClient;
75
87
  siteInbox(uuid: string): SiteInboxClient;
76
- orgs(): Promise<Org[]>;
88
+ editingSession(uuid: string): EditingSessionClient;
89
+ editingSessionFile(uuid: string): EditingSessionFileClient;
90
+ build(uuid: string): BuildClient;
91
+ backup(uuid: string): BackupClient;
92
+ sync(uuid: string): SyncClient;
93
+ orgs(options?: PaginationOptions & SortingOptions<operations['Organizations_Index']> & FilterOptions<operations['Organizations_Index']>): Promise<PaginatedResponse<Org>>;
94
+ getUploadData(): Promise<UploadData>;
77
95
  }
package/dist/index.js CHANGED
@@ -1,7 +1,13 @@
1
+ import { BackupClient } from "./src/backup.js";
2
+ import { BuildClient } from "./src/build.js";
3
+ import { EditingSessionClient, } from "./src/editing-session.js";
4
+ import { EditingSessionFileClient } from "./src/editing-session-file.js";
5
+ import { buildQuery, paginatedResponse, } from "./src/helpers/query.js";
1
6
  import { InboxClient } from "./src/inbox.js";
2
7
  import { OrgClient } from "./src/org.js";
3
8
  import { SiteClient } from "./src/site.js";
4
9
  import { SiteInboxClient } from "./src/site-inbox.js";
10
+ import { SyncClient } from "./src/sync.js";
5
11
  export default class CloudCannonClient {
6
12
  #apiKey;
7
13
  #appDomain;
@@ -52,9 +58,39 @@ export default class CloudCannonClient {
52
58
  siteInbox(uuid) {
53
59
  return new SiteInboxClient(uuid, this);
54
60
  }
55
- async orgs() {
56
- const resp = await this.fetch('/orgs');
61
+ editingSession(uuid) {
62
+ return new EditingSessionClient(uuid, this);
63
+ }
64
+ editingSessionFile(uuid) {
65
+ return new EditingSessionFileClient(uuid, this);
66
+ }
67
+ build(uuid) {
68
+ return new BuildClient(uuid, this);
69
+ }
70
+ backup(uuid) {
71
+ return new BackupClient(uuid, this);
72
+ }
73
+ sync(uuid) {
74
+ return new SyncClient(uuid, this);
75
+ }
76
+ async orgs(options = {}) {
77
+ const query = buildQuery(options);
78
+ const resp = await this.fetch(`/orgs?${query}`);
79
+ if (resp.status === 403) {
80
+ throw new Error('Error fetching orgs. Permission denied');
81
+ }
57
82
  const orgs = await resp.json();
58
- return orgs;
83
+ return paginatedResponse(orgs, resp.headers);
84
+ }
85
+ async getUploadData() {
86
+ const resp = await this.fetch('/upload-data');
87
+ if (resp.status === 403) {
88
+ throw new Error('Error fetching upload data. Permission denied');
89
+ }
90
+ if (resp.status === 422) {
91
+ throw new Error('Error fetching upload data. Invalid request');
92
+ }
93
+ const uploadData = await resp.json();
94
+ return uploadData;
59
95
  }
60
96
  }