@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/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { components, operations, paths } from './schema.ts';
|
|
2
|
+
import { InboxClient } from './src/inbox.ts';
|
|
3
|
+
import { OrgClient } from './src/org.ts';
|
|
4
|
+
import { type BuildConfiguration, SiteClient } from './src/site.ts';
|
|
5
|
+
import { SiteInboxClient } from './src/site-inbox.ts';
|
|
6
|
+
export type { BuildConfiguration };
|
|
7
|
+
export type Provider = operations['Providers_Repositories']['parameters']['path']['provider'];
|
|
8
|
+
export type Site = components['schemas']['SiteBlueprint'];
|
|
9
|
+
export type Org = components['schemas']['OrgBlueprintFull'];
|
|
10
|
+
export type Build = components['schemas']['BuildBlueprint'];
|
|
11
|
+
export type Sync = components['schemas']['SyncBlueprint'];
|
|
12
|
+
export type SiteScan = components['schemas']['SiteScannerBlueprint'];
|
|
13
|
+
export type SiteInbox = components['schemas']['SiteInboxBlueprint'];
|
|
14
|
+
export type SiteDam = components['schemas']['SiteDamBlueprint'];
|
|
15
|
+
export type FormSubmission = components['schemas']['FormHookBlueprint'];
|
|
16
|
+
export type Inbox = components['schemas']['InboxBlueprint'];
|
|
17
|
+
export type Dam = components['schemas']['DamBlueprint'];
|
|
18
|
+
export type ProviderDetails = {
|
|
19
|
+
provider: Provider;
|
|
20
|
+
repository: string;
|
|
21
|
+
branch: string;
|
|
22
|
+
};
|
|
23
|
+
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
|
+
type StripPrefix<S extends string> = S extends `/api/v0${infer Rest}` ? Rest : never;
|
|
25
|
+
type RequestBody<T> = T extends {
|
|
26
|
+
requestBody: {
|
|
27
|
+
content: {
|
|
28
|
+
'application/json': infer B;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
} ? B : never;
|
|
32
|
+
type RequestParams<T> = T extends {
|
|
33
|
+
parameters: infer P;
|
|
34
|
+
} ? P : never;
|
|
35
|
+
type ResponseMixin<S, R> = {
|
|
36
|
+
status: S;
|
|
37
|
+
json: R extends {
|
|
38
|
+
content: {
|
|
39
|
+
'application/json': infer J;
|
|
40
|
+
};
|
|
41
|
+
} ? () => Promise<J> : never;
|
|
42
|
+
};
|
|
43
|
+
type RequestMixin<M, Op> = {
|
|
44
|
+
method?: M;
|
|
45
|
+
body?: RequestBody<Op>;
|
|
46
|
+
};
|
|
47
|
+
type APIResponse<Op> = Op extends {
|
|
48
|
+
responses: infer R;
|
|
49
|
+
} ? {
|
|
50
|
+
[status in keyof R]: Omit<Response, keyof ResponseMixin<status, R[status]>> & ResponseMixin<status, R[status]>;
|
|
51
|
+
}[keyof R] : never;
|
|
52
|
+
type Split<S extends string> = S extends `${infer Head}/${infer Tail}` ? [Head, ...Split<Tail>] : [S];
|
|
53
|
+
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
|
+
type MatchURL<M extends keyof paths[keyof paths], U extends string> = {
|
|
55
|
+
[K in keyof paths]: [
|
|
56
|
+
SegmentMatch<Split<U>, Split<ParamToString<StripPrefix<K & string>>>>
|
|
57
|
+
] extends [never] ? never : RequestParams<paths[K][M]> extends never ? never : paths[K];
|
|
58
|
+
}[keyof paths];
|
|
59
|
+
type ValidURL<M extends keyof paths[keyof paths], U extends string> = MatchURL<M, U> extends never ? {
|
|
60
|
+
[K in keyof paths]: RequestParams<paths[K][M]> extends never ? never : StripPrefix<K>;
|
|
61
|
+
}[keyof paths] : U;
|
|
62
|
+
export type CloudCannonClientConfig = {
|
|
63
|
+
key: string;
|
|
64
|
+
apiOrigin?: string;
|
|
65
|
+
getCustomAuthHeaders?: () => Record<string, string>;
|
|
66
|
+
};
|
|
67
|
+
export default class CloudCannonClient {
|
|
68
|
+
#private;
|
|
69
|
+
constructor(config: CloudCannonClientConfig);
|
|
70
|
+
getAuthHeaders(): Record<string, string>;
|
|
71
|
+
fetch<const U extends string, const M extends Uppercase<keyof paths[keyof paths]> = 'GET'>(url: ValidURL<Lowercase<M>, U>, options?: Omit<RequestInit, keyof RequestMixin<M, MatchURL<Lowercase<M>, U>[Lowercase<M>]>> & RequestMixin<M, MatchURL<Lowercase<M>, U>[Lowercase<M>]>): Promise<APIResponse<MatchURL<Lowercase<M>, U>[Lowercase<M>]>>;
|
|
72
|
+
org(uuid: string): OrgClient;
|
|
73
|
+
site(uuid: string): SiteClient;
|
|
74
|
+
inbox(uuid: string): InboxClient;
|
|
75
|
+
siteInbox(uuid: string): SiteInboxClient;
|
|
76
|
+
orgs(): Promise<Org[]>;
|
|
77
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { InboxClient } from "./src/inbox.js";
|
|
2
|
+
import { OrgClient } from "./src/org.js";
|
|
3
|
+
import { SiteClient } from "./src/site.js";
|
|
4
|
+
import { SiteInboxClient } from "./src/site-inbox.js";
|
|
5
|
+
export default class CloudCannonClient {
|
|
6
|
+
#apiKey;
|
|
7
|
+
#appDomain;
|
|
8
|
+
#getCustomAuthHeaders;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.#apiKey = config.key;
|
|
11
|
+
this.#appDomain = config.apiOrigin ?? 'app.cloudcannon.com';
|
|
12
|
+
this.#getCustomAuthHeaders = config.getCustomAuthHeaders;
|
|
13
|
+
}
|
|
14
|
+
getAuthHeaders() {
|
|
15
|
+
if (this.#getCustomAuthHeaders) {
|
|
16
|
+
return {
|
|
17
|
+
...this.#getCustomAuthHeaders(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
'X-API-KEY': `${this.#apiKey}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async fetch(url, options) {
|
|
25
|
+
const requestInit = {
|
|
26
|
+
...options,
|
|
27
|
+
headers: {
|
|
28
|
+
...this.getAuthHeaders(),
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
...options?.headers,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
if (options?.body) {
|
|
34
|
+
if (typeof options?.body !== 'string') {
|
|
35
|
+
requestInit.body = JSON.stringify(options.body);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
requestInit.body = options.body;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return fetch(`https://${this.#appDomain}/api/v0${url}`, requestInit);
|
|
42
|
+
}
|
|
43
|
+
org(uuid) {
|
|
44
|
+
return new OrgClient(uuid, this);
|
|
45
|
+
}
|
|
46
|
+
site(uuid) {
|
|
47
|
+
return new SiteClient(uuid, this);
|
|
48
|
+
}
|
|
49
|
+
inbox(uuid) {
|
|
50
|
+
return new InboxClient(uuid, this);
|
|
51
|
+
}
|
|
52
|
+
siteInbox(uuid) {
|
|
53
|
+
return new SiteInboxClient(uuid, this);
|
|
54
|
+
}
|
|
55
|
+
async orgs() {
|
|
56
|
+
const resp = await this.fetch('/orgs');
|
|
57
|
+
const orgs = await resp.json();
|
|
58
|
+
return orgs;
|
|
59
|
+
}
|
|
60
|
+
}
|