webflow-api 1.3.0 → 1.3.1
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/api/collection.d.ts +112 -0
- package/dist/api/collection.js +94 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +23 -0
- package/dist/api/item.d.ts +177 -0
- package/dist/api/item.js +151 -0
- package/dist/api/meta.d.ts +53 -0
- package/dist/api/meta.js +25 -0
- package/dist/api/oauth.d.ts +71 -0
- package/dist/api/oauth.js +71 -0
- package/dist/api/site.d.ts +140 -0
- package/dist/api/site.js +137 -0
- package/dist/api/user.d.ts +143 -0
- package/dist/api/user.js +119 -0
- package/dist/api/webhook.d.ts +102 -0
- package/dist/api/webhook.js +80 -0
- package/dist/core/error.d.ts +21 -0
- package/dist/core/error.js +30 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +19 -0
- package/dist/core/response.d.ts +32 -0
- package/dist/core/response.js +26 -0
- package/dist/core/webflow.d.ts +390 -0
- package/dist/core/webflow.js +518 -0
- package/dist/index.d.ts +2 -0
- package/package.json +7 -1
- package/yarn.lock +2840 -0
- package/.eslintrc +0 -31
- package/.github/workflows/code-quality.yml +0 -102
- package/.github/workflows/npm-publish.yml +0 -21
- package/.github/workflows/semgrep.yml +0 -24
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
- package/jest.config.js +0 -17
- package/tests/api/collection.test.ts +0 -147
- package/tests/api/item.test.ts +0 -180
- package/tests/api/meta.test.ts +0 -38
- package/tests/api/oauth.test.ts +0 -44
- package/tests/api/site.test.ts +0 -202
- package/tests/api/user.test.ts +0 -139
- package/tests/api/webhook.test.ts +0 -82
- package/tests/core/error.test.ts +0 -19
- package/tests/core/response.test.ts +0 -36
- package/tests/core/webflow.test.ts +0 -540
- package/tests/fixtures/collection.fixture.ts +0 -374
- package/tests/fixtures/index.ts +0 -7
- package/tests/fixtures/item.fixture.ts +0 -193
- package/tests/fixtures/meta.fixture.ts +0 -34
- package/tests/fixtures/oauth.fixture.ts +0 -38
- package/tests/fixtures/site.fixture.ts +0 -78
- package/tests/fixtures/user.fixture.ts +0 -175
- package/tests/fixtures/webhook.fixture.ts +0 -69
- package/tsconfig.eslint.json +0 -7
- package/tsconfig.json +0 -14
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { WebflowRecord } from "../core";
|
|
3
|
+
import { Item } from ".";
|
|
4
|
+
/**************************************************************
|
|
5
|
+
* Types
|
|
6
|
+
**************************************************************/
|
|
7
|
+
export declare type CollectionFieldType = "Bool" | "Color" | "Date" | "ExtFileRef" | "Set" | "ImageRef" | "Set" | "ItemRef" | "ItemRefSet" | "Link" | "Number" | "Option" | "PlainText" | "RichText" | "Video" | "User" | string;
|
|
8
|
+
export declare type CollectionField = {
|
|
9
|
+
id: string;
|
|
10
|
+
type: CollectionFieldType;
|
|
11
|
+
slug: string;
|
|
12
|
+
name: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
editable: boolean;
|
|
15
|
+
validations?: Record<string, any>;
|
|
16
|
+
};
|
|
17
|
+
/**************************************************************
|
|
18
|
+
* Interfaces
|
|
19
|
+
**************************************************************/
|
|
20
|
+
export interface ICollection {
|
|
21
|
+
_id: string;
|
|
22
|
+
lastUpdated: string;
|
|
23
|
+
createdOn: string;
|
|
24
|
+
name: string;
|
|
25
|
+
slug: string;
|
|
26
|
+
singularName: string;
|
|
27
|
+
fields: CollectionField[];
|
|
28
|
+
}
|
|
29
|
+
/**************************************************************
|
|
30
|
+
* Class
|
|
31
|
+
**************************************************************/
|
|
32
|
+
export declare class Collection extends WebflowRecord<ICollection> implements ICollection {
|
|
33
|
+
fields: CollectionField[];
|
|
34
|
+
singularName: string;
|
|
35
|
+
lastUpdated: string;
|
|
36
|
+
createdOn: string;
|
|
37
|
+
_id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
slug: string;
|
|
40
|
+
/**************************************************************
|
|
41
|
+
* Static Methods
|
|
42
|
+
**************************************************************/
|
|
43
|
+
/**
|
|
44
|
+
* Get a list of Collections
|
|
45
|
+
* @param params The params for the request
|
|
46
|
+
* @param params.siteId The site ID
|
|
47
|
+
* @param client The Axios client instance
|
|
48
|
+
* @returns A list of Collections
|
|
49
|
+
*/
|
|
50
|
+
static list({ siteId }: {
|
|
51
|
+
siteId: string;
|
|
52
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<ICollection[], any>>;
|
|
53
|
+
/**
|
|
54
|
+
* Get a single Collection
|
|
55
|
+
* @param params The params for the request
|
|
56
|
+
* @param params.collectionId The collection ID
|
|
57
|
+
* @param client The Axios client instance
|
|
58
|
+
* @returns A single Collection
|
|
59
|
+
*/
|
|
60
|
+
static getOne({ collectionId }: {
|
|
61
|
+
collectionId: string;
|
|
62
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<ICollection, any>>;
|
|
63
|
+
/**************************************************************
|
|
64
|
+
* Instance Methods
|
|
65
|
+
**************************************************************/
|
|
66
|
+
/**
|
|
67
|
+
* Get a single Item
|
|
68
|
+
* @param params The params for the request
|
|
69
|
+
* @param params.itemId The Item ID
|
|
70
|
+
* @returns A single Item
|
|
71
|
+
*/
|
|
72
|
+
item({ itemId }: {
|
|
73
|
+
itemId: string;
|
|
74
|
+
}): Promise<Item>;
|
|
75
|
+
/**
|
|
76
|
+
* Get a list of Items
|
|
77
|
+
* @param params The params for the request
|
|
78
|
+
* @param params.limit The number of items to return (optional)
|
|
79
|
+
* @param params.offset The number of items to skip (optional)
|
|
80
|
+
* @returns A list of Items
|
|
81
|
+
*/
|
|
82
|
+
items({ limit, offset }?: {
|
|
83
|
+
limit?: number;
|
|
84
|
+
offset?: number;
|
|
85
|
+
}): Promise<Item[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Remove a single Item
|
|
88
|
+
* @param params The params for the request
|
|
89
|
+
* @param params.itemId The Item ID
|
|
90
|
+
* @returns The result from the removal
|
|
91
|
+
*/
|
|
92
|
+
removeItem({ itemId }: {
|
|
93
|
+
itemId: string;
|
|
94
|
+
}): Promise<import("./item").IItemDelete>;
|
|
95
|
+
/**
|
|
96
|
+
* Create a new Item
|
|
97
|
+
* @param fields The Item fields to create
|
|
98
|
+
* @returns The created Item
|
|
99
|
+
*/
|
|
100
|
+
createItem(fields: object): Promise<Item>;
|
|
101
|
+
/**
|
|
102
|
+
* Update a single Item
|
|
103
|
+
* @param params The params for the request
|
|
104
|
+
* @param params.itemId The Item ID
|
|
105
|
+
* @param params.fields The fields to update
|
|
106
|
+
* @returns The updated Item
|
|
107
|
+
*/
|
|
108
|
+
updateItem({ itemId, fields }: {
|
|
109
|
+
itemId: string;
|
|
110
|
+
fields: object;
|
|
111
|
+
}): Promise<Item>;
|
|
112
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collection = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
/**************************************************************
|
|
7
|
+
* Class
|
|
8
|
+
**************************************************************/
|
|
9
|
+
class Collection extends core_1.WebflowRecord {
|
|
10
|
+
/**************************************************************
|
|
11
|
+
* Static Methods
|
|
12
|
+
**************************************************************/
|
|
13
|
+
/**
|
|
14
|
+
* Get a list of Collections
|
|
15
|
+
* @param params The params for the request
|
|
16
|
+
* @param params.siteId The site ID
|
|
17
|
+
* @param client The Axios client instance
|
|
18
|
+
* @returns A list of Collections
|
|
19
|
+
*/
|
|
20
|
+
static list({ siteId }, client) {
|
|
21
|
+
(0, core_1.requireArgs)({ siteId });
|
|
22
|
+
const path = `/sites/${siteId}/collections`;
|
|
23
|
+
return client.get(path);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get a single Collection
|
|
27
|
+
* @param params The params for the request
|
|
28
|
+
* @param params.collectionId The collection ID
|
|
29
|
+
* @param client The Axios client instance
|
|
30
|
+
* @returns A single Collection
|
|
31
|
+
*/
|
|
32
|
+
static getOne({ collectionId }, client) {
|
|
33
|
+
(0, core_1.requireArgs)({ collectionId });
|
|
34
|
+
const path = `/collections/${collectionId}`;
|
|
35
|
+
return client.get(path);
|
|
36
|
+
}
|
|
37
|
+
/**************************************************************
|
|
38
|
+
* Instance Methods
|
|
39
|
+
**************************************************************/
|
|
40
|
+
/**
|
|
41
|
+
* Get a single Item
|
|
42
|
+
* @param params The params for the request
|
|
43
|
+
* @param params.itemId The Item ID
|
|
44
|
+
* @returns A single Item
|
|
45
|
+
*/
|
|
46
|
+
async item({ itemId }) {
|
|
47
|
+
const res = await _1.Item.getOne({ itemId, collectionId: this._id }, this.client);
|
|
48
|
+
const [item] = res.data.items.map((data) => new _1.Item(this.client, { ...res, data }));
|
|
49
|
+
return item;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get a list of Items
|
|
53
|
+
* @param params The params for the request
|
|
54
|
+
* @param params.limit The number of items to return (optional)
|
|
55
|
+
* @param params.offset The number of items to skip (optional)
|
|
56
|
+
* @returns A list of Items
|
|
57
|
+
*/
|
|
58
|
+
async items({ limit, offset } = {}) {
|
|
59
|
+
const res = await _1.Item.list({ collectionId: this._id, limit, offset }, this.client);
|
|
60
|
+
return res.data.items.map((data) => new _1.Item(this.client, { ...res, data }));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Remove a single Item
|
|
64
|
+
* @param params The params for the request
|
|
65
|
+
* @param params.itemId The Item ID
|
|
66
|
+
* @returns The result from the removal
|
|
67
|
+
*/
|
|
68
|
+
async removeItem({ itemId }) {
|
|
69
|
+
const res = await _1.Item.remove({ itemId, collectionId: this._id }, this.client);
|
|
70
|
+
return res.data;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new Item
|
|
74
|
+
* @param fields The Item fields to create
|
|
75
|
+
* @returns The created Item
|
|
76
|
+
*/
|
|
77
|
+
async createItem(fields) {
|
|
78
|
+
const res = await _1.Item.create({ collectionId: this._id, fields }, this.client);
|
|
79
|
+
return new _1.Item(this.client, res);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Update a single Item
|
|
83
|
+
* @param params The params for the request
|
|
84
|
+
* @param params.itemId The Item ID
|
|
85
|
+
* @param params.fields The fields to update
|
|
86
|
+
* @returns The updated Item
|
|
87
|
+
*/
|
|
88
|
+
async updateItem({ itemId, fields }) {
|
|
89
|
+
const params = { itemId, collectionId: this._id, fields };
|
|
90
|
+
const res = await _1.Item.update(params, this.client);
|
|
91
|
+
return new _1.Item(this.client, res);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.Collection = Collection;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./collection"), exports);
|
|
18
|
+
__exportStar(require("./user"), exports);
|
|
19
|
+
__exportStar(require("./webhook"), exports);
|
|
20
|
+
__exportStar(require("./item"), exports);
|
|
21
|
+
__exportStar(require("./site"), exports);
|
|
22
|
+
__exportStar(require("./oauth"), exports);
|
|
23
|
+
__exportStar(require("./meta"), exports);
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
import { PaginatedData, WebflowRecord } from "../core";
|
|
3
|
+
/**************************************************************
|
|
4
|
+
* Interfaces
|
|
5
|
+
**************************************************************/
|
|
6
|
+
export interface IItem {
|
|
7
|
+
_archived: boolean;
|
|
8
|
+
_draft: boolean;
|
|
9
|
+
_id: string;
|
|
10
|
+
_cid: string;
|
|
11
|
+
name: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
"updated-on": string;
|
|
14
|
+
"created-on": string;
|
|
15
|
+
"updated-by": string;
|
|
16
|
+
"created-by": string;
|
|
17
|
+
"published-on"?: string | null;
|
|
18
|
+
"published-by"?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface IItemDelete {
|
|
21
|
+
deleted: number;
|
|
22
|
+
}
|
|
23
|
+
export interface IPublishItems {
|
|
24
|
+
publishedItemIds: string[];
|
|
25
|
+
errors: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface IDeletedItems {
|
|
28
|
+
deletedItemIds: string[];
|
|
29
|
+
errors: string[];
|
|
30
|
+
}
|
|
31
|
+
/**************************************************************
|
|
32
|
+
* Types
|
|
33
|
+
**************************************************************/
|
|
34
|
+
export declare type PaginatedItems = PaginatedData & {
|
|
35
|
+
items: IItem[];
|
|
36
|
+
};
|
|
37
|
+
/**************************************************************
|
|
38
|
+
* Class
|
|
39
|
+
**************************************************************/
|
|
40
|
+
export declare class Item extends WebflowRecord<IItem> implements IItem {
|
|
41
|
+
"published-on"?: string | null;
|
|
42
|
+
"published-by"?: string | null;
|
|
43
|
+
"updated-on": string;
|
|
44
|
+
"created-on": string;
|
|
45
|
+
"updated-by": string;
|
|
46
|
+
"created-by": string;
|
|
47
|
+
_archived: boolean;
|
|
48
|
+
_draft: boolean;
|
|
49
|
+
_cid: string;
|
|
50
|
+
name: string;
|
|
51
|
+
slug: string;
|
|
52
|
+
_id: string;
|
|
53
|
+
/**************************************************************
|
|
54
|
+
* Static Methods
|
|
55
|
+
**************************************************************/
|
|
56
|
+
/**
|
|
57
|
+
* Get a single Item
|
|
58
|
+
* @param params The params for the request
|
|
59
|
+
* @param params.collectionId The Collection ID
|
|
60
|
+
* @param params.itemId The Item ID
|
|
61
|
+
* @param client The Axios client instance
|
|
62
|
+
* @returns A single Item
|
|
63
|
+
*/
|
|
64
|
+
static getOne({ collectionId, itemId }: {
|
|
65
|
+
collectionId: string;
|
|
66
|
+
itemId: string;
|
|
67
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<PaginatedItems, any>>;
|
|
68
|
+
/**
|
|
69
|
+
* Get a list of Items
|
|
70
|
+
* @param params The params for the request
|
|
71
|
+
* @param params.collectionId The Collection ID
|
|
72
|
+
* @param params.limit The number of items to return (optional)
|
|
73
|
+
* @param params.offset The number of items to skip (optional)
|
|
74
|
+
* @param client The Axios client instance
|
|
75
|
+
* @returns A list of Items
|
|
76
|
+
*/
|
|
77
|
+
static list({ collectionId, limit, offset }: {
|
|
78
|
+
collectionId: string;
|
|
79
|
+
limit?: number;
|
|
80
|
+
offset?: number;
|
|
81
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<PaginatedItems, any>>;
|
|
82
|
+
/**
|
|
83
|
+
* Create a new Item
|
|
84
|
+
* @param params The params for the request
|
|
85
|
+
* @param params.collectionId The Collection ID
|
|
86
|
+
* @param params.fields The Item fields to create
|
|
87
|
+
* @param client The Axios client instance
|
|
88
|
+
* @returns The created Item
|
|
89
|
+
*/
|
|
90
|
+
static create({ collectionId, fields }: {
|
|
91
|
+
fields: any;
|
|
92
|
+
collectionId: string;
|
|
93
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IItem, any>>;
|
|
94
|
+
/**
|
|
95
|
+
* Update a single Item
|
|
96
|
+
* @param params The params for the request
|
|
97
|
+
* @param params.collectionId The Collection ID
|
|
98
|
+
* @param params.itemId The Item ID
|
|
99
|
+
* @param params.fields The fields to update
|
|
100
|
+
* @param client The Axios client instance
|
|
101
|
+
* @returns The updated Item
|
|
102
|
+
*/
|
|
103
|
+
static update({ collectionId, itemId, fields, }: {
|
|
104
|
+
fields: any;
|
|
105
|
+
itemId: string;
|
|
106
|
+
collectionId: string;
|
|
107
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IItem, any>>;
|
|
108
|
+
/**
|
|
109
|
+
* Patch a single Item
|
|
110
|
+
* @param params The params for the request
|
|
111
|
+
* @param params.collectionId The Collection ID
|
|
112
|
+
* @param params.itemId The Item ID
|
|
113
|
+
* @param params.fields The fields to patch
|
|
114
|
+
* @param client The Axios client instance
|
|
115
|
+
* @returns The patched Item
|
|
116
|
+
*/
|
|
117
|
+
static patch({ collectionId, itemId, fields, }: {
|
|
118
|
+
fields: any;
|
|
119
|
+
itemId: string;
|
|
120
|
+
collectionId: string;
|
|
121
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IItem, any>>;
|
|
122
|
+
/**
|
|
123
|
+
* Remove a single Item
|
|
124
|
+
* @param params The params for the request
|
|
125
|
+
* @param params.collectionId The Collection ID
|
|
126
|
+
* @param params.itemId The Item ID
|
|
127
|
+
* @param client The Axios client instance
|
|
128
|
+
* @returns The result from the removal
|
|
129
|
+
*/
|
|
130
|
+
static remove({ collectionId, itemId, }: {
|
|
131
|
+
itemId: string;
|
|
132
|
+
collectionId: string;
|
|
133
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IItemDelete, any>>;
|
|
134
|
+
/**
|
|
135
|
+
* Unpublish a list of Items
|
|
136
|
+
* @param params The params for the request
|
|
137
|
+
* @param params.collectionId The Collection ID
|
|
138
|
+
* @param params.live Unpublish from the live site
|
|
139
|
+
* @param client The Axios client instance
|
|
140
|
+
* @returns The result of the unpublish
|
|
141
|
+
*/
|
|
142
|
+
static unpublish({ collectionId, itemIds, live, }: {
|
|
143
|
+
live?: boolean;
|
|
144
|
+
itemIds: string[];
|
|
145
|
+
collectionId: string;
|
|
146
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IDeletedItems, any>>;
|
|
147
|
+
/**
|
|
148
|
+
* Publishes a list of Items
|
|
149
|
+
* @param params The request parameters
|
|
150
|
+
* @param params.collectionId The Collection ID
|
|
151
|
+
* @param params.itemIds The list of Item IDs to publish
|
|
152
|
+
* @param params.live Publish to live site
|
|
153
|
+
* @param client The Axios client instance
|
|
154
|
+
* @returns The result of the publish
|
|
155
|
+
*/
|
|
156
|
+
static publish({ itemIds, live, collectionId, }: {
|
|
157
|
+
live?: boolean;
|
|
158
|
+
itemIds: string[];
|
|
159
|
+
collectionId: string;
|
|
160
|
+
}, client: AxiosInstance): Promise<import("axios").AxiosResponse<IPublishItems, any>>;
|
|
161
|
+
/**************************************************************
|
|
162
|
+
* Instance Methods
|
|
163
|
+
**************************************************************/
|
|
164
|
+
/**
|
|
165
|
+
* Update a single Item
|
|
166
|
+
* @param fields The fields to update
|
|
167
|
+
* @returns The updated Item
|
|
168
|
+
*/
|
|
169
|
+
update({ ...fields }: {
|
|
170
|
+
[x: string]: any;
|
|
171
|
+
}): Promise<Item>;
|
|
172
|
+
/**
|
|
173
|
+
* Remove a single Item
|
|
174
|
+
* @returns The result from the removal
|
|
175
|
+
*/
|
|
176
|
+
remove(): Promise<IItemDelete>;
|
|
177
|
+
}
|
package/dist/api/item.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Item = void 0;
|
|
4
|
+
const core_1 = require("../core");
|
|
5
|
+
/**************************************************************
|
|
6
|
+
* Class
|
|
7
|
+
**************************************************************/
|
|
8
|
+
class Item extends core_1.WebflowRecord {
|
|
9
|
+
/**************************************************************
|
|
10
|
+
* Static Methods
|
|
11
|
+
**************************************************************/
|
|
12
|
+
/**
|
|
13
|
+
* Get a single Item
|
|
14
|
+
* @param params The params for the request
|
|
15
|
+
* @param params.collectionId The Collection ID
|
|
16
|
+
* @param params.itemId The Item ID
|
|
17
|
+
* @param client The Axios client instance
|
|
18
|
+
* @returns A single Item
|
|
19
|
+
*/
|
|
20
|
+
static getOne({ collectionId, itemId }, client) {
|
|
21
|
+
(0, core_1.requireArgs)({ collectionId, itemId });
|
|
22
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
23
|
+
// The API returns a paginated list with one record :(
|
|
24
|
+
return client.get(path);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get a list of Items
|
|
28
|
+
* @param params The params for the request
|
|
29
|
+
* @param params.collectionId The Collection ID
|
|
30
|
+
* @param params.limit The number of items to return (optional)
|
|
31
|
+
* @param params.offset The number of items to skip (optional)
|
|
32
|
+
* @param client The Axios client instance
|
|
33
|
+
* @returns A list of Items
|
|
34
|
+
*/
|
|
35
|
+
static list({ collectionId, limit, offset }, client) {
|
|
36
|
+
(0, core_1.requireArgs)({ collectionId });
|
|
37
|
+
const params = { limit, offset };
|
|
38
|
+
const path = `/collections/${collectionId}/items`;
|
|
39
|
+
return client.get(path, { params });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new Item
|
|
43
|
+
* @param params The params for the request
|
|
44
|
+
* @param params.collectionId The Collection ID
|
|
45
|
+
* @param params.fields The Item fields to create
|
|
46
|
+
* @param client The Axios client instance
|
|
47
|
+
* @returns The created Item
|
|
48
|
+
*/
|
|
49
|
+
static create({ collectionId, fields }, client) {
|
|
50
|
+
(0, core_1.requireArgs)({ collectionId });
|
|
51
|
+
const path = `/collections/${collectionId}/items`;
|
|
52
|
+
return client.post(path, { fields });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update a single Item
|
|
56
|
+
* @param params The params for the request
|
|
57
|
+
* @param params.collectionId The Collection ID
|
|
58
|
+
* @param params.itemId The Item ID
|
|
59
|
+
* @param params.fields The fields to update
|
|
60
|
+
* @param client The Axios client instance
|
|
61
|
+
* @returns The updated Item
|
|
62
|
+
*/
|
|
63
|
+
static update({ collectionId, itemId, fields, }, client) {
|
|
64
|
+
(0, core_1.requireArgs)({ collectionId, itemId });
|
|
65
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
66
|
+
return client.put(path, { fields });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Patch a single Item
|
|
70
|
+
* @param params The params for the request
|
|
71
|
+
* @param params.collectionId The Collection ID
|
|
72
|
+
* @param params.itemId The Item ID
|
|
73
|
+
* @param params.fields The fields to patch
|
|
74
|
+
* @param client The Axios client instance
|
|
75
|
+
* @returns The patched Item
|
|
76
|
+
*/
|
|
77
|
+
static patch({ collectionId, itemId, fields, }, client) {
|
|
78
|
+
(0, core_1.requireArgs)({ collectionId, itemId });
|
|
79
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
80
|
+
return client.patch(path, { fields });
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Remove a single Item
|
|
84
|
+
* @param params The params for the request
|
|
85
|
+
* @param params.collectionId The Collection ID
|
|
86
|
+
* @param params.itemId The Item ID
|
|
87
|
+
* @param client The Axios client instance
|
|
88
|
+
* @returns The result from the removal
|
|
89
|
+
*/
|
|
90
|
+
static remove({ collectionId, itemId, }, client) {
|
|
91
|
+
(0, core_1.requireArgs)({ collectionId, itemId });
|
|
92
|
+
const path = `/collections/${collectionId}/items/${itemId}`;
|
|
93
|
+
return client.delete(path);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Unpublish a list of Items
|
|
97
|
+
* @param params The params for the request
|
|
98
|
+
* @param params.collectionId The Collection ID
|
|
99
|
+
* @param params.live Unpublish from the live site
|
|
100
|
+
* @param client The Axios client instance
|
|
101
|
+
* @returns The result of the unpublish
|
|
102
|
+
*/
|
|
103
|
+
static unpublish({ collectionId, itemIds, live = false, }, client) {
|
|
104
|
+
(0, core_1.requireArgs)({ collectionId, itemIds });
|
|
105
|
+
const params = { live };
|
|
106
|
+
const data = { itemIds };
|
|
107
|
+
const url = `/collections/${collectionId}/items`;
|
|
108
|
+
const _params = { method: "DELETE", url, data, params };
|
|
109
|
+
// DELETE spec doesn't support body in delete
|
|
110
|
+
// RFC-9110 https://tools.ietf.org/html/rfc9110
|
|
111
|
+
return client.request(_params);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Publishes a list of Items
|
|
115
|
+
* @param params The request parameters
|
|
116
|
+
* @param params.collectionId The Collection ID
|
|
117
|
+
* @param params.itemIds The list of Item IDs to publish
|
|
118
|
+
* @param params.live Publish to live site
|
|
119
|
+
* @param client The Axios client instance
|
|
120
|
+
* @returns The result of the publish
|
|
121
|
+
*/
|
|
122
|
+
static publish({ itemIds, live = false, collectionId, }, client) {
|
|
123
|
+
(0, core_1.requireArgs)({ collectionId, itemIds });
|
|
124
|
+
const params = { live };
|
|
125
|
+
const path = `/collections/${collectionId}/items/publish`;
|
|
126
|
+
return client.put(path, { itemIds }, { params });
|
|
127
|
+
}
|
|
128
|
+
/**************************************************************
|
|
129
|
+
* Instance Methods
|
|
130
|
+
**************************************************************/
|
|
131
|
+
/**
|
|
132
|
+
* Update a single Item
|
|
133
|
+
* @param fields The fields to update
|
|
134
|
+
* @returns The updated Item
|
|
135
|
+
*/
|
|
136
|
+
async update({ ...fields }) {
|
|
137
|
+
const params = { collectionId: this._cid, itemId: this._id, fields };
|
|
138
|
+
const res = await Item.update(params, this.client);
|
|
139
|
+
return new Item(this.client, res);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Remove a single Item
|
|
143
|
+
* @returns The result from the removal
|
|
144
|
+
*/
|
|
145
|
+
async remove() {
|
|
146
|
+
const params = { collectionId: this._cid, itemId: this._id };
|
|
147
|
+
const res = await Item.remove(params, this.client);
|
|
148
|
+
return res.data;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.Item = Item;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AxiosInstance } from "axios";
|
|
2
|
+
/**************************************************************
|
|
3
|
+
* Types
|
|
4
|
+
**************************************************************/
|
|
5
|
+
export declare type InfoApplication = {
|
|
6
|
+
description: string;
|
|
7
|
+
ownerType: string;
|
|
8
|
+
homepage: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
name: string;
|
|
11
|
+
_id: string;
|
|
12
|
+
};
|
|
13
|
+
/**************************************************************
|
|
14
|
+
* Interfaces
|
|
15
|
+
**************************************************************/
|
|
16
|
+
export interface IAuthenticatedUser {
|
|
17
|
+
user: {
|
|
18
|
+
firstName: string;
|
|
19
|
+
lastName: string;
|
|
20
|
+
email: string;
|
|
21
|
+
_id: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface IAuthenticationInfo {
|
|
25
|
+
application: InfoApplication;
|
|
26
|
+
workspaces: string[];
|
|
27
|
+
rateLimit: number;
|
|
28
|
+
createdOn: string;
|
|
29
|
+
grantType: string;
|
|
30
|
+
lastUsed: string;
|
|
31
|
+
sites: string[];
|
|
32
|
+
users: string[];
|
|
33
|
+
orgs: string[];
|
|
34
|
+
status: string;
|
|
35
|
+
_id: string;
|
|
36
|
+
}
|
|
37
|
+
/**************************************************************
|
|
38
|
+
* Class
|
|
39
|
+
**************************************************************/
|
|
40
|
+
export declare class Meta {
|
|
41
|
+
/**
|
|
42
|
+
* Get the authentication info for the current token
|
|
43
|
+
* @param client The Axios client instance
|
|
44
|
+
* @returns The authentication info
|
|
45
|
+
*/
|
|
46
|
+
static info(client: AxiosInstance): Promise<import("axios").AxiosResponse<IAuthenticationInfo, any>>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the authenticated user
|
|
49
|
+
* @param client The Axios client instance
|
|
50
|
+
* @returns The authenticated user
|
|
51
|
+
*/
|
|
52
|
+
static user(client: AxiosInstance): Promise<import("axios").AxiosResponse<IAuthenticatedUser, any>>;
|
|
53
|
+
}
|
package/dist/api/meta.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Meta = void 0;
|
|
4
|
+
/**************************************************************
|
|
5
|
+
* Class
|
|
6
|
+
**************************************************************/
|
|
7
|
+
class Meta {
|
|
8
|
+
/**
|
|
9
|
+
* Get the authentication info for the current token
|
|
10
|
+
* @param client The Axios client instance
|
|
11
|
+
* @returns The authentication info
|
|
12
|
+
*/
|
|
13
|
+
static info(client) {
|
|
14
|
+
return client.get("/info");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the authenticated user
|
|
18
|
+
* @param client The Axios client instance
|
|
19
|
+
* @returns The authenticated user
|
|
20
|
+
*/
|
|
21
|
+
static user(client) {
|
|
22
|
+
return client.get("/user");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Meta = Meta;
|