webflow-api 1.0.3 → 1.1.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.
Files changed (74) hide show
  1. package/README.md +4 -5
  2. package/dist/api/collection.d.ts +51 -0
  3. package/dist/api/collection.js +35 -0
  4. package/dist/api/index.d.ts +7 -0
  5. package/dist/api/index.js +33 -0
  6. package/dist/api/item.d.ts +143 -0
  7. package/dist/api/item.js +131 -0
  8. package/dist/api/membership.d.ts +91 -0
  9. package/dist/api/membership.js +80 -0
  10. package/dist/api/meta.d.ts +51 -0
  11. package/dist/api/meta.js +24 -0
  12. package/dist/api/oauth.d.ts +67 -0
  13. package/dist/api/oauth.js +65 -0
  14. package/dist/api/site.d.ts +65 -0
  15. package/dist/api/site.js +59 -0
  16. package/dist/api/webhook.d.ts +80 -0
  17. package/dist/api/webhook.js +67 -0
  18. package/dist/core/client.d.ts +40 -0
  19. package/dist/core/client.js +49 -0
  20. package/dist/core/error.d.ts +19 -0
  21. package/dist/core/error.js +23 -0
  22. package/dist/core/index.d.ts +3 -0
  23. package/dist/core/index.js +19 -0
  24. package/dist/core/options.d.ts +8 -0
  25. package/dist/core/options.js +5 -0
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +2 -9
  28. package/dist/webflow.d.ts +366 -0
  29. package/dist/webflow.js +388 -0
  30. package/dist/wrapper/collection.d.ts +85 -0
  31. package/dist/wrapper/collection.js +94 -0
  32. package/dist/wrapper/index.d.ts +6 -0
  33. package/dist/wrapper/index.js +22 -0
  34. package/dist/wrapper/item.d.ts +140 -0
  35. package/dist/wrapper/item.js +153 -0
  36. package/dist/wrapper/membership.d.ts +91 -0
  37. package/dist/wrapper/membership.js +106 -0
  38. package/dist/wrapper/response.d.ts +16 -0
  39. package/dist/wrapper/response.js +17 -0
  40. package/dist/wrapper/site.d.ts +119 -0
  41. package/dist/wrapper/site.js +136 -0
  42. package/dist/wrapper/webhook.d.ts +78 -0
  43. package/dist/wrapper/webhook.js +82 -0
  44. package/package.json +16 -18
  45. package/src/api/collection.ts +87 -0
  46. package/src/api/index.ts +7 -0
  47. package/src/api/item.ts +231 -0
  48. package/src/api/membership.ts +125 -0
  49. package/src/api/meta.ts +61 -0
  50. package/src/api/oauth.ts +119 -0
  51. package/src/api/site.ts +86 -0
  52. package/src/api/webhook.ts +125 -0
  53. package/src/core/client.ts +76 -0
  54. package/src/core/error.ts +32 -0
  55. package/src/core/index.ts +3 -0
  56. package/src/core/options.ts +9 -0
  57. package/src/index.ts +3 -0
  58. package/src/webflow.ts +487 -0
  59. package/src/wrapper/collection.ts +115 -0
  60. package/src/wrapper/index.ts +6 -0
  61. package/src/wrapper/item.ts +218 -0
  62. package/src/wrapper/membership.ts +138 -0
  63. package/src/wrapper/response.ts +25 -0
  64. package/src/wrapper/site.ts +164 -0
  65. package/src/wrapper/webhook.ts +116 -0
  66. package/yarn.lock +392 -1515
  67. package/dist/ResponseWrapper.js +0 -135
  68. package/dist/Webflow.js +0 -344
  69. package/dist/WebflowClient.js +0 -115
  70. package/index.d.ts +0 -430
  71. package/src/ResponseWrapper.js +0 -103
  72. package/src/Webflow.js +0 -301
  73. package/src/WebflowClient.js +0 -98
  74. package/src/index.js +0 -3
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SiteWrapper = void 0;
4
+ const _1 = require(".");
5
+ const api_1 = require("../api");
6
+ class SiteWrapper {
7
+ constructor(client, site) {
8
+ this.client = client;
9
+ Object.assign(this, site);
10
+ }
11
+ /**************************************************************
12
+ * Static Methods
13
+ **************************************************************/
14
+ /**
15
+ * Get a single Site
16
+ * @param client The Webflow client
17
+ * @param params The Site information
18
+ * @param params.siteId The Site ID
19
+ * @returns The Site
20
+ */
21
+ static async getOne(client, { siteId }) {
22
+ const res = await api_1.Site.getOne(client, { siteId });
23
+ const site = new SiteWrapper(client, res.data);
24
+ return (0, _1.ResponseWrapper)(res, site);
25
+ }
26
+ /**
27
+ * Get a list of Sites available
28
+ * @param client The Webflow client
29
+ * @param params The query parameters (optional)
30
+ * @returns A list of Sites
31
+ */
32
+ static async list(client, params) {
33
+ const res = await api_1.Site.list(client, params);
34
+ const sites = res.data.map((s) => new SiteWrapper(client, s));
35
+ return (0, _1.ResponseWrapper)(res, sites);
36
+ }
37
+ /**
38
+ * Get a list of Domains for a Site
39
+ * @param client The Webflow client
40
+ * @param params The Site information
41
+ * @param params.siteId The Site ID
42
+ * @returns A list of Domains
43
+ */
44
+ static async domains(client, { siteId }) {
45
+ const res = await api_1.Site.domains(client, { siteId });
46
+ return (0, _1.ResponseWrapper)(res, res.data);
47
+ }
48
+ /**
49
+ * Publish a Site
50
+ * @param client The Webflow client
51
+ * @param params The Site information
52
+ * @param params.siteId The Site ID
53
+ * @param params.domain The domains to publish
54
+ * @returns The result of the publish
55
+ */
56
+ static async publish(client, { siteId, domains }) {
57
+ const res = await api_1.Site.publish(client, { siteId, domains });
58
+ return (0, _1.ResponseWrapper)(res);
59
+ }
60
+ /**************************************************************
61
+ * Instance Methods
62
+ **************************************************************/
63
+ /**
64
+ * Get a list of domains for a site
65
+ * @returns A list of domains
66
+ */
67
+ async domains() {
68
+ const res = await api_1.Site.domains(this.client, { siteId: this._id });
69
+ return (0, _1.ResponseWrapper)(res);
70
+ }
71
+ /**
72
+ * Publish a site
73
+ * @param domains The domains to publish to
74
+ * @returns The publish result
75
+ */
76
+ async publishSite(domains) {
77
+ const res = await api_1.Site.publish(this.client, { siteId: this._id, domains });
78
+ return (0, _1.ResponseWrapper)(res);
79
+ }
80
+ /**
81
+ * Get a single Collection
82
+ * @param params The params for the request
83
+ * @param params.collectionId The collection ID
84
+ * @returns A single Collection
85
+ */
86
+ async collection({ collectionId }) {
87
+ return _1.CollectionWrapper.getOne(this.client, { collectionId });
88
+ }
89
+ /**
90
+ * Get a list of Collections
91
+ * @returns A list of Collections
92
+ */
93
+ async collections() {
94
+ return _1.CollectionWrapper.list(this.client, { siteId: this._id });
95
+ }
96
+ /**
97
+ * Get a single Webhook
98
+ * @param params The params for the request
99
+ * @param params.webhookId The webhook ID
100
+ * @returns A single Webhook
101
+ */
102
+ async webhook({ webhookId }) {
103
+ return _1.WebhookWrapper.getOne(this.client, { siteId: this._id, webhookId });
104
+ }
105
+ /**
106
+ * Get a list of Webhooks
107
+ * @param params The query string parameters (optional)
108
+ * @returns A list of Webhooks
109
+ */
110
+ async webhooks(params) {
111
+ return _1.WebhookWrapper.list(this.client, { siteId: this._id }, params);
112
+ }
113
+ /**
114
+ * Remove a Webhook
115
+ * @param params The query string parameters (optional)
116
+ * @param params.webhookId The Webhook ID
117
+ * @returns The result of the removal
118
+ */
119
+ async removeWebhook({ webhookId }) {
120
+ return _1.WebhookWrapper.remove(this.client, { siteId: this._id, webhookId });
121
+ }
122
+ /**
123
+ * Create a new Webhook
124
+ * @param params1 The params for the request
125
+ * @param params1.url The URL to send the webhook to
126
+ * @param params1.triggerType The event to trigger the webhook
127
+ * @param params1.filter The filter to apply to the webhook (optional: form_submission only)
128
+ * @param params The query string parameters (optional)
129
+ * @returns The created webhook
130
+ */
131
+ async createWebhook({ triggerType, filter, url }) {
132
+ const _params = { url, siteId: this._id, triggerType, filter };
133
+ return _1.WebhookWrapper.create(this.client, _params);
134
+ }
135
+ }
136
+ exports.SiteWrapper = SiteWrapper;
@@ -0,0 +1,78 @@
1
+ import { Client, QueryString } from "../core";
2
+ import { Webhook } from "../api";
3
+ export declare type CreateWebhookParams = {
4
+ url: string;
5
+ siteId: string;
6
+ triggerType: string;
7
+ filter?: Webhook.Filter;
8
+ };
9
+ export declare class WebhookWrapper implements Webhook.IWebhook {
10
+ private client;
11
+ triggerType: Webhook.TriggerType;
12
+ triggerId: string;
13
+ createdOn: string;
14
+ lastUsed?: string;
15
+ site: string;
16
+ _id: string;
17
+ filter?: {
18
+ name: string;
19
+ };
20
+ constructor(client: Client, webhook: Webhook.IWebhook);
21
+ /**************************************************************
22
+ * Static Methods
23
+ **************************************************************/
24
+ /**
25
+ * Get a Webhook
26
+ * @param client The Webflow client
27
+ * @param params The Webhook params
28
+ * @param params.siteId The Site ID
29
+ * @param params.webhookId The Webhook ID
30
+ * @returns The Webhook
31
+ */
32
+ static getOne(client: Client, { siteId, webhookId }: {
33
+ siteId: string;
34
+ webhookId: string;
35
+ }): Promise<import("./response").MetaResponse<WebhookWrapper>>;
36
+ /**
37
+ * List Webhooks
38
+ * @param client The Webflow client
39
+ * @param param1 The Webhook params
40
+ * @param param1.siteId The Site ID
41
+ * @param params Query string params (optional)
42
+ * @returns A list of Webhooks
43
+ */
44
+ static list(client: Client, { siteId }: {
45
+ siteId: string;
46
+ }, params?: QueryString): Promise<import("./response").MetaResponse<WebhookWrapper[]>>;
47
+ /**
48
+ * Remove a Webhook
49
+ * @param client The Webflow client
50
+ * @param params The Webhook params
51
+ * @param params.siteId The Site ID
52
+ * @param params.webhookId The Webhook ID
53
+ * @returns The result of the removal
54
+ */
55
+ static remove(client: Client, { siteId, webhookId }: {
56
+ siteId: string;
57
+ webhookId: string;
58
+ }): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
59
+ /**
60
+ * Create a Webhook
61
+ * @param client The Webflow client
62
+ * @param param1 The Webhook params
63
+ * @param param1.siteId The Site ID
64
+ * @param param1.url The URL to send the Webhook to
65
+ * @param param1.triggerType The event to trigger the Webhook
66
+ * @param param1.filter The filter to use (optional: form_submission only)
67
+ * @returns The created Webhook
68
+ */
69
+ static create(client: Client, { triggerType, siteId, filter, url }: CreateWebhookParams): Promise<import("./response").MetaResponse<WebhookWrapper>>;
70
+ /**************************************************************
71
+ * Instance Methods
72
+ **************************************************************/
73
+ /**
74
+ * Remove a Webhook
75
+ * @returns The result of the removal
76
+ */
77
+ remove(): Promise<import("./response").MetaResponse<Webhook.IRemoveResult>>;
78
+ }
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhookWrapper = void 0;
4
+ const _1 = require(".");
5
+ const api_1 = require("../api");
6
+ class WebhookWrapper {
7
+ constructor(client, webhook) {
8
+ this.client = client;
9
+ Object.assign(this, webhook);
10
+ }
11
+ /**************************************************************
12
+ * Static Methods
13
+ **************************************************************/
14
+ /**
15
+ * Get a Webhook
16
+ * @param client The Webflow client
17
+ * @param params The Webhook params
18
+ * @param params.siteId The Site ID
19
+ * @param params.webhookId The Webhook ID
20
+ * @returns The Webhook
21
+ */
22
+ static async getOne(client, { siteId, webhookId }) {
23
+ const res = await api_1.Webhook.getOne(client, { siteId, webhookId });
24
+ const webhook = new WebhookWrapper(client, res.data);
25
+ return (0, _1.ResponseWrapper)(res, webhook);
26
+ }
27
+ /**
28
+ * List Webhooks
29
+ * @param client The Webflow client
30
+ * @param param1 The Webhook params
31
+ * @param param1.siteId The Site ID
32
+ * @param params Query string params (optional)
33
+ * @returns A list of Webhooks
34
+ */
35
+ static async list(client, { siteId }, params) {
36
+ const res = await api_1.Webhook.list(client, { siteId }, params);
37
+ const webhooks = res.data.map((w) => new WebhookWrapper(client, w));
38
+ return (0, _1.ResponseWrapper)(res, webhooks);
39
+ }
40
+ /**
41
+ * Remove a Webhook
42
+ * @param client The Webflow client
43
+ * @param params The Webhook params
44
+ * @param params.siteId The Site ID
45
+ * @param params.webhookId The Webhook ID
46
+ * @returns The result of the removal
47
+ */
48
+ static async remove(client, { siteId, webhookId }) {
49
+ const res = await api_1.Webhook.remove(client, { siteId, webhookId });
50
+ return (0, _1.ResponseWrapper)(res);
51
+ }
52
+ /**
53
+ * Create a Webhook
54
+ * @param client The Webflow client
55
+ * @param param1 The Webhook params
56
+ * @param param1.siteId The Site ID
57
+ * @param param1.url The URL to send the Webhook to
58
+ * @param param1.triggerType The event to trigger the Webhook
59
+ * @param param1.filter The filter to use (optional: form_submission only)
60
+ * @returns The created Webhook
61
+ */
62
+ static async create(client, { triggerType, siteId, filter, url }) {
63
+ const args = { triggerType, siteId, filter, url };
64
+ const res = await api_1.Webhook.create(client, args);
65
+ const _webhook = new WebhookWrapper(client, res.data);
66
+ return (0, _1.ResponseWrapper)(res, _webhook);
67
+ }
68
+ /**************************************************************
69
+ * Instance Methods
70
+ **************************************************************/
71
+ /**
72
+ * Remove a Webhook
73
+ * @returns The result of the removal
74
+ */
75
+ async remove() {
76
+ return WebhookWrapper.remove(this.client, {
77
+ webhookId: this._id,
78
+ siteId: this.site,
79
+ });
80
+ }
81
+ }
82
+ exports.WebhookWrapper = WebhookWrapper;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "webflow-api",
3
3
  "description": "Webflow's official Node.js SDK for Data APIs",
4
- "version": "1.0.3",
5
- "types": "index.d.ts",
4
+ "version": "1.1.1",
5
+ "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "contributors": [
8
8
  "John Agan (https://github.com/johnagan)"
@@ -16,35 +16,33 @@
16
16
  "dist",
17
17
  "src",
18
18
  "LICENSE",
19
- "yarn.lock",
20
- "index.d.ts"
19
+ "yarn.lock"
21
20
  ],
22
21
  "scripts": {
23
- "compile": "BABEL_ENV=production babel --out-dir dist src/",
24
- "build": " yarn clean && yarn compile",
25
- "watch": "yarn build --watch",
22
+ "build": "yarn clean && tsc -p ./",
23
+ "lint": "eslint . --ext .ts,.tsx",
26
24
  "prepublish": "yarn build",
25
+ "watch": "tsc -watch -p ./",
27
26
  "clean": "rm -rf dist",
28
- "lint": "eslint",
29
27
  "test": "jest"
30
28
  },
31
29
  "devDependencies": {
32
- "@babel/cli": "^7.19.3",
33
- "@babel/core": "^7.19.6",
34
- "@babel/preset-env": "^7.19.4",
35
- "@babel/register": "^7.18.9",
36
30
  "@jest/globals": "^29.2.2",
37
- "babel-jest": "^29.2.2",
38
- "babel-plugin-add-module-exports": "^1.0.4",
31
+ "@types/isomorphic-fetch": "^0.0.36",
32
+ "@types/jest": "^29.2.1",
33
+ "@types/node": "^18.11.9",
34
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
35
+ "@typescript-eslint/parser": "^5.42.0",
36
+ "axios-mock-adapter": "^1.21.2",
39
37
  "eslint": "^8.12.0",
40
- "eslint-config-airbnb-base": "^15.0.0",
41
38
  "eslint-config-prettier": "^8.5.0",
42
- "eslint-plugin-import": "^2.26.0",
43
39
  "eslint-plugin-prettier": "^4.2.1",
44
40
  "jest": "^29.2.2",
45
- "nock": "^13.0.7"
41
+ "prettier": "^2.7.1",
42
+ "ts-jest": "^29.0.3",
43
+ "typescript": "^4.8.4"
46
44
  },
47
45
  "dependencies": {
48
- "isomorphic-fetch": "^3.0.0"
46
+ "axios": "^1.1.3"
49
47
  }
50
48
  }
@@ -0,0 +1,87 @@
1
+ import { Client, QueryString, requireArgs } from "../core";
2
+
3
+ /**************************************************************
4
+ * Types
5
+ **************************************************************/
6
+ export type CollectionFieldType =
7
+ | "Bool"
8
+ | "Color"
9
+ | "Date"
10
+ | "ExtFileRef"
11
+ | "Set"
12
+ | "ImageRef"
13
+ | "Set"
14
+ | "ItemRef"
15
+ | "ItemRefSet"
16
+ | "Link"
17
+ | "Number"
18
+ | "Option"
19
+ | "PlainText"
20
+ | "RichText"
21
+ | "Video"
22
+ | "User"
23
+ | string;
24
+
25
+ export type CollectionField = {
26
+ id: string;
27
+ type: CollectionFieldType;
28
+ slug: string;
29
+ name: string;
30
+ required: boolean;
31
+ editable: boolean;
32
+ // TODO: add a better type
33
+ validations?: any;
34
+ };
35
+
36
+ /**************************************************************
37
+ * Interfaces
38
+ **************************************************************/
39
+ export interface ICollection {
40
+ _id: string;
41
+ lastUpdated: string;
42
+ createdOn: string;
43
+ name: string;
44
+ slug: string;
45
+ singularName: string;
46
+ fields: CollectionField[];
47
+ }
48
+
49
+ /**************************************************************
50
+ * Functions
51
+ **************************************************************/
52
+
53
+ /**
54
+ * Get a list of Collections
55
+ * @param client The Webflow client
56
+ * @param params1 The params for the request
57
+ * @param params1.siteId The site ID
58
+ * @param params The query string parameters (optional)
59
+ * @returns A list of Collections
60
+ */
61
+ export function list(
62
+ client: Client,
63
+ { siteId }: { siteId: string },
64
+ params?: QueryString
65
+ ) {
66
+ requireArgs({ siteId });
67
+ const path = `/sites/${siteId}/collections`;
68
+ return client.get<ICollection[]>(path, { params });
69
+ }
70
+
71
+ /**
72
+ * Get a single Collection
73
+ * @param client The Webflow client
74
+ * @param params The params for the request
75
+ * @param params.collectionId The collection ID
76
+ * @param params.params The query string parameters (optional)
77
+ * @returns A single Collection
78
+ */
79
+ export function getOne(
80
+ client: Client,
81
+ { collectionId }: { collectionId: string },
82
+ params?: QueryString
83
+ ) {
84
+ requireArgs({ collectionId });
85
+ const path = `/collections/${collectionId}`;
86
+ return client.get<ICollection>(path, { params });
87
+ }
@@ -0,0 +1,7 @@
1
+ export * as Membership from "./membership";
2
+ export * as Collection from "./collection";
3
+ export * as Webhook from "./webhook";
4
+ export * as OAuth from "./oauth";
5
+ export * as Item from "./item";
6
+ export * as Site from "./site";
7
+ export * as Meta from "./meta";
@@ -0,0 +1,231 @@
1
+ import { Client, PaginatedData, QueryString, requireArgs } from "../core";
2
+
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
+
21
+ export interface IItemDelete {
22
+ deleted: number;
23
+ }
24
+
25
+ export interface IPublishItems {
26
+ publishedItemIds: string[];
27
+ errors: string[];
28
+ }
29
+
30
+ export interface IDeletedItems {
31
+ deletedItemIds: string[];
32
+ errors: string[];
33
+ }
34
+
35
+ /**************************************************************
36
+ * Types
37
+ **************************************************************/
38
+ export type PageinatedItems = PaginatedData & {
39
+ items: IItem[];
40
+ };
41
+
42
+ /**************************************************************
43
+ * Functions
44
+ **************************************************************/
45
+
46
+ /**
47
+ * Get a single Item
48
+ * @param client The Webflow client
49
+ * @param params The params for the request
50
+ * @param params.collectionId The Collection ID
51
+ * @param params.itemId The Item ID
52
+ * @returns A single Item
53
+ */
54
+ export function getOne(
55
+ client: Client,
56
+ { collectionId, itemId }: { collectionId: string; itemId: string }
57
+ ) {
58
+ requireArgs({ collectionId, itemId });
59
+ const path = `/collections/${collectionId}/items/${itemId}`;
60
+ // The API returns a paginated list with one record :(
61
+ return client.get<PageinatedItems>(path);
62
+ }
63
+
64
+ /**
65
+ * Get a list of Items
66
+ * @param client The Webflow client
67
+ * @param params The params for the request
68
+ * @param params.collectionId The Collection ID
69
+ * @param params.limit The number of items to return (optional)
70
+ * @param params.offset The number of items to skip (optional)
71
+ * @returns A list of Items
72
+ */
73
+ export function list(
74
+ client: Client,
75
+ {
76
+ collectionId,
77
+ limit,
78
+ offset,
79
+ }: { collectionId: string; limit?: number; offset?: number }
80
+ ) {
81
+ requireArgs({ collectionId });
82
+ const params = { limit, offset };
83
+ const path = `/collections/${collectionId}/items`;
84
+ return client.get<PageinatedItems>(path, { params });
85
+ }
86
+
87
+ /**
88
+ * Create a new Item
89
+ * @param client The Webflow client
90
+ * @param params The params for the request
91
+ * @param params.collectionId The Collection ID
92
+ * @param params.fields The Item fields to create
93
+ * @returns The created Item
94
+ */
95
+ export function create(
96
+ client: Client,
97
+ { collectionId, fields }: { fields: any; collectionId: string }
98
+ ) {
99
+ requireArgs({ collectionId });
100
+ const path = `/collections/${collectionId}/items`;
101
+ return client.post<IItem>(path, { fields });
102
+ }
103
+
104
+ /**
105
+ * Update a single Item
106
+ * @param client The Webflow client
107
+ * @param params The params for the request
108
+ * @param params.collectionId The Collection ID
109
+ * @param params.itemId The Item ID
110
+ * @param params.fields The fields to update
111
+ * @returns The updated Item
112
+ */
113
+ export function update(
114
+ client: Client,
115
+ {
116
+ collectionId,
117
+ itemId,
118
+ fields,
119
+ }: {
120
+ fields: any;
121
+ itemId: string;
122
+ collectionId: string;
123
+ }
124
+ ) {
125
+ requireArgs({ collectionId, itemId });
126
+ const path = `/collections/${collectionId}/items/${itemId}`;
127
+ return client.put<IItem>(path, { fields });
128
+ }
129
+
130
+ /**
131
+ * Patch a single Item
132
+ * @param client The Webflow client
133
+ * @param params The params for the request
134
+ * @param params.collectionId The Collection ID
135
+ * @param params.itemId The Item ID
136
+ * @param params.fields The fields to patch
137
+ * @returns The patched Item
138
+ */
139
+ export function patch(
140
+ client: Client,
141
+ {
142
+ collectionId,
143
+ itemId,
144
+ fields,
145
+ }: {
146
+ fields: any;
147
+ itemId: string;
148
+ collectionId: string;
149
+ }
150
+ ) {
151
+ requireArgs({ collectionId, itemId });
152
+ const path = `/collections/${collectionId}/items/${itemId}`;
153
+ return client.patch<IItem>(path, { fields });
154
+ }
155
+
156
+ /**
157
+ * Remove a single Item
158
+ * @param client The Webflow client
159
+ * @param params The params for the request
160
+ * @param params.collectionId The Collection ID
161
+ * @param params.itemId The Item ID
162
+ * @returns The result from the removal
163
+ */
164
+ export function remove(
165
+ client: Client,
166
+ {
167
+ collectionId,
168
+ itemId,
169
+ }: {
170
+ itemId: string;
171
+ collectionId: string;
172
+ }
173
+ ) {
174
+ requireArgs({ collectionId, itemId });
175
+ const path = `/collections/${collectionId}/items/${itemId}`;
176
+ return client.delete<IItemDelete>(path);
177
+ }
178
+
179
+ /**
180
+ * Unpublishes a list of Items
181
+ * @param client The Webflow client
182
+ * @param params The params for the request
183
+ * @param params.collectionId The Collection ID
184
+ * @param params.live Unpublish from the live site
185
+ * @returns The result of the unpublish
186
+ */
187
+ export function unpublish(
188
+ client: Client,
189
+ {
190
+ collectionId,
191
+ itemIds,
192
+ live = false,
193
+ }: {
194
+ live?: boolean;
195
+ itemIds: string[];
196
+ collectionId: string;
197
+ }
198
+ ) {
199
+ requireArgs({ collectionId, itemIds });
200
+ const params = { live };
201
+ const data = { itemIds };
202
+ const url = `/collections/${collectionId}/items`;
203
+ const _params = { method: "DELETE", url, data, params };
204
+
205
+ // DELETE spec doesn't support body in delete
206
+ // RFC-9110 https://tools.ietf.org/html/rfc9110
207
+ return client.request<IDeletedItems>(_params);
208
+ }
209
+
210
+ /**
211
+ * Publishes a list of Items
212
+ * @param client The Webflow client
213
+ * @param params The request parameters
214
+ * @param params.collectionId The Collection ID
215
+ * @param params.itemIds The list of Item IDs to publish
216
+ * @param params.live Publish to live site
217
+ * @returns The result of the publish
218
+ */
219
+ export function publish(
220
+ client: Client,
221
+ {
222
+ itemIds,
223
+ live = false,
224
+ collectionId,
225
+ }: { live?: boolean; itemIds: string[]; collectionId: string }
226
+ ) {
227
+ requireArgs({ collectionId, itemIds });
228
+ const params = { live };
229
+ const path = `/collections/${collectionId}/items/publish`;
230
+ return client.put<IPublishItems>(path, { itemIds }, { params });
231
+ }