webflow-api 1.2.1 → 1.3.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/.eslintrc +31 -0
- package/.github/workflows/code-quality.yml +102 -0
- package/.github/workflows/npm-publish.yml +21 -0
- package/.github/workflows/semgrep.yml +24 -0
- package/.prettierignore +5 -0
- package/.prettierrc +6 -0
- package/README.md +53 -4
- package/jest.config.js +17 -0
- package/package.json +2 -7
- package/src/api/collection.ts +1 -1
- package/src/api/item.ts +4 -4
- package/src/api/meta.ts +2 -2
- package/src/api/oauth.ts +10 -3
- package/src/core/error.ts +1 -1
- package/src/core/webflow.ts +111 -4
- package/tests/api/collection.test.ts +147 -0
- package/tests/api/item.test.ts +180 -0
- package/tests/api/meta.test.ts +38 -0
- package/tests/api/oauth.test.ts +44 -0
- package/tests/api/site.test.ts +202 -0
- package/tests/api/user.test.ts +139 -0
- package/tests/api/webhook.test.ts +82 -0
- package/tests/core/error.test.ts +19 -0
- package/tests/core/response.test.ts +36 -0
- package/tests/core/webflow.test.ts +540 -0
- package/tests/fixtures/collection.fixture.ts +374 -0
- package/tests/fixtures/index.ts +7 -0
- package/tests/fixtures/item.fixture.ts +193 -0
- package/tests/fixtures/meta.fixture.ts +34 -0
- package/tests/fixtures/oauth.fixture.ts +38 -0
- package/tests/fixtures/site.fixture.ts +78 -0
- package/tests/fixtures/user.fixture.ts +175 -0
- package/tests/fixtures/webhook.fixture.ts +69 -0
- package/tsconfig.eslint.json +7 -0
- package/tsconfig.json +14 -0
- package/dist/api/collection.d.ts +0 -112
- package/dist/api/collection.js +0 -94
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.js +0 -23
- package/dist/api/item.d.ts +0 -177
- package/dist/api/item.js +0 -151
- package/dist/api/meta.d.ts +0 -53
- package/dist/api/meta.js +0 -25
- package/dist/api/oauth.d.ts +0 -69
- package/dist/api/oauth.js +0 -65
- package/dist/api/site.d.ts +0 -140
- package/dist/api/site.js +0 -137
- package/dist/api/user.d.ts +0 -143
- package/dist/api/user.js +0 -119
- package/dist/api/webhook.d.ts +0 -102
- package/dist/api/webhook.js +0 -80
- package/dist/core/error.d.ts +0 -21
- package/dist/core/error.js +0 -30
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -19
- package/dist/core/response.d.ts +0 -32
- package/dist/core/response.js +0 -26
- package/dist/core/webflow.d.ts +0 -386
- package/dist/core/webflow.js +0 -445
- package/dist/index.d.ts +0 -2
- package/yarn.lock +0 -2830
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import MockAdapter from "axios-mock-adapter";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { UserFixture } from "../fixtures";
|
|
4
|
+
import { User } from "../../src/api";
|
|
5
|
+
|
|
6
|
+
describe("Users", () => {
|
|
7
|
+
const mock = new MockAdapter(axios);
|
|
8
|
+
const client = axios.create();
|
|
9
|
+
|
|
10
|
+
describe("Static Methods", () => {
|
|
11
|
+
it("should respond with a list of users", async () => {
|
|
12
|
+
const { response, parameters } = UserFixture.list;
|
|
13
|
+
const { siteId } = parameters;
|
|
14
|
+
const path = `/sites/${siteId}/users`;
|
|
15
|
+
|
|
16
|
+
mock.onGet(path).reply(200, response);
|
|
17
|
+
const { data } = await User.list(parameters, client);
|
|
18
|
+
|
|
19
|
+
expect(data).toBeDefined();
|
|
20
|
+
expect(data.users.length).toBe(response.users.length);
|
|
21
|
+
expect(data.users[0]).toMatchObject(response.users[0]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should respond with a single user", async () => {
|
|
25
|
+
const { response, parameters } = UserFixture.getOne;
|
|
26
|
+
const { siteId, userId } = parameters;
|
|
27
|
+
const path = `/sites/${siteId}/users/${userId}`;
|
|
28
|
+
|
|
29
|
+
mock.onGet(path).reply(200, response);
|
|
30
|
+
const { data } = await User.getOne(parameters, client);
|
|
31
|
+
|
|
32
|
+
expect(data).toBeDefined();
|
|
33
|
+
expect(data._id).toBe(response._id);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should invite a user", async () => {
|
|
37
|
+
const { response, parameters } = UserFixture.invite;
|
|
38
|
+
const { siteId } = parameters;
|
|
39
|
+
const path = `/sites/${siteId}/users/invite`;
|
|
40
|
+
|
|
41
|
+
mock.onPost(path).reply(200, response);
|
|
42
|
+
const { data } = await User.invite(parameters, client);
|
|
43
|
+
|
|
44
|
+
expect(data).toBeDefined();
|
|
45
|
+
expect(data.data).toBeDefined();
|
|
46
|
+
expect(data._id).toBe(response._id);
|
|
47
|
+
expect(data.data).toMatchObject(response.data);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should update a user", async () => {
|
|
51
|
+
const { response, parameters } = UserFixture.update;
|
|
52
|
+
const { siteId, userId } = parameters;
|
|
53
|
+
const path = `/sites/${siteId}/users/${userId}`;
|
|
54
|
+
|
|
55
|
+
mock.onPatch(path).reply(200, response);
|
|
56
|
+
const { data } = await User.update(parameters, client);
|
|
57
|
+
|
|
58
|
+
expect(data).toBeDefined();
|
|
59
|
+
expect(data._id).toBe(response._id);
|
|
60
|
+
expect(data.data).toBeDefined();
|
|
61
|
+
expect(data.data).toMatchObject(response.data);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should remove a user", async () => {
|
|
65
|
+
const { response, parameters } = UserFixture.delete;
|
|
66
|
+
const { siteId, userId } = parameters;
|
|
67
|
+
const path = `/sites/${siteId}/users/${userId}`;
|
|
68
|
+
|
|
69
|
+
mock.onDelete(path).reply(200, response);
|
|
70
|
+
const { data } = await User.remove(parameters, client);
|
|
71
|
+
|
|
72
|
+
expect(data).toBeDefined();
|
|
73
|
+
expect(data.deleted).toBe(response.deleted);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should respond with a list of access groups", async () => {
|
|
77
|
+
const { response, parameters } = UserFixture.accessGroups;
|
|
78
|
+
const { siteId } = parameters;
|
|
79
|
+
const path = `/sites/${siteId}/accessgroups`;
|
|
80
|
+
|
|
81
|
+
mock.onGet(path).reply(200, response);
|
|
82
|
+
const { data } = await User.accessGroups(parameters, client);
|
|
83
|
+
|
|
84
|
+
expect(data).toBeDefined();
|
|
85
|
+
expect(data.accessGroups.length).toBe(response.accessGroups.length);
|
|
86
|
+
expect(data.accessGroups[0]).toMatchObject(response.accessGroups[0]);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("Instance Methods", () => {
|
|
91
|
+
const { parameters, response } = UserFixture.getOne;
|
|
92
|
+
const res = {
|
|
93
|
+
data: {},
|
|
94
|
+
status: 200,
|
|
95
|
+
statusText: "",
|
|
96
|
+
headers: {},
|
|
97
|
+
config: {},
|
|
98
|
+
};
|
|
99
|
+
const user = new User(client, res, response, { siteId: parameters.siteId });
|
|
100
|
+
|
|
101
|
+
it("should update a user", async () => {
|
|
102
|
+
const { response, parameters } = UserFixture.update;
|
|
103
|
+
const { siteId, userId, data } = parameters;
|
|
104
|
+
|
|
105
|
+
const path = `/sites/${siteId}/users/${userId}`;
|
|
106
|
+
mock.onPatch(path).reply(200, response);
|
|
107
|
+
const spy = jest.spyOn(User, "update");
|
|
108
|
+
|
|
109
|
+
const result = await user.update(data);
|
|
110
|
+
|
|
111
|
+
const _params = { data, siteId, userId };
|
|
112
|
+
expect(spy).toHaveBeenCalledWith(_params, client);
|
|
113
|
+
|
|
114
|
+
expect(result).toBeDefined();
|
|
115
|
+
expect(result._id).toBe(response._id);
|
|
116
|
+
|
|
117
|
+
expect(result.data).toBeDefined();
|
|
118
|
+
|
|
119
|
+
// user wrapper functions
|
|
120
|
+
expect(typeof result.update).toBe("function");
|
|
121
|
+
expect(typeof result.remove).toBe("function");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should remove a user", async () => {
|
|
125
|
+
const { response, parameters } = UserFixture.delete;
|
|
126
|
+
const { siteId, userId } = parameters;
|
|
127
|
+
|
|
128
|
+
const path = `/sites/${siteId}/users/${userId}`;
|
|
129
|
+
mock.onDelete(path).reply(200, response);
|
|
130
|
+
const spy = jest.spyOn(User, "remove");
|
|
131
|
+
|
|
132
|
+
const result = await user.remove();
|
|
133
|
+
|
|
134
|
+
expect(spy).toHaveBeenCalledWith({ siteId, userId }, client);
|
|
135
|
+
|
|
136
|
+
expect(result).toBeDefined();
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import MockAdapter from "axios-mock-adapter";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { WebhookFixture } from "../fixtures";
|
|
4
|
+
import { Webhook } from "../../src/api";
|
|
5
|
+
|
|
6
|
+
describe("Webhooks", () => {
|
|
7
|
+
const mock = new MockAdapter(axios);
|
|
8
|
+
const client = axios.create();
|
|
9
|
+
|
|
10
|
+
describe("Static Methods", () => {
|
|
11
|
+
it("should respond with a list of webhooks", async () => {
|
|
12
|
+
const { parameters, response } = WebhookFixture.list;
|
|
13
|
+
const { siteId } = parameters;
|
|
14
|
+
const path = `/sites/${siteId}/webhooks`;
|
|
15
|
+
|
|
16
|
+
mock.onGet(path).reply(200, response);
|
|
17
|
+
const { data } = await Webhook.list(parameters, client);
|
|
18
|
+
|
|
19
|
+
expect(data).toBeDefined();
|
|
20
|
+
expect(data.length).toEqual(response.length);
|
|
21
|
+
expect(data[0]).toEqual(response[0]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should respond with a single webhook", async () => {
|
|
25
|
+
const { parameters, response } = WebhookFixture.getOne;
|
|
26
|
+
const { siteId, webhookId } = parameters;
|
|
27
|
+
|
|
28
|
+
const path = `/sites/${siteId}/webhooks/${webhookId}`;
|
|
29
|
+
mock.onGet(path).reply(200, response);
|
|
30
|
+
const { data } = await Webhook.getOne(parameters, client);
|
|
31
|
+
|
|
32
|
+
expect(data).toBeDefined();
|
|
33
|
+
expect(data._id).toBe(response._id);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should create a webhook", async () => {
|
|
37
|
+
const { parameters, response } = WebhookFixture.create;
|
|
38
|
+
const { siteId } = parameters;
|
|
39
|
+
|
|
40
|
+
const path = `/sites/${siteId}/webhooks`;
|
|
41
|
+
mock.onPost(path).reply(200, response);
|
|
42
|
+
const { data } = await Webhook.create(parameters, client);
|
|
43
|
+
|
|
44
|
+
expect(data).toBeDefined();
|
|
45
|
+
expect(data._id).toBe(response._id);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should remove a webhook", async () => {
|
|
49
|
+
const { parameters, response } = WebhookFixture.delete;
|
|
50
|
+
const { siteId, webhookId } = parameters;
|
|
51
|
+
|
|
52
|
+
const path = `/sites/${siteId}/webhooks/${webhookId}`;
|
|
53
|
+
mock.onDelete(path).reply(200, response);
|
|
54
|
+
const { data } = await Webhook.remove(parameters, client);
|
|
55
|
+
|
|
56
|
+
expect(data).toBeDefined();
|
|
57
|
+
expect(data.deleted).toEqual(response.deleted);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("Instance Methods", () => {
|
|
62
|
+
const res = { data: {}, status: 200, statusText: "", headers: {}, config: {} };
|
|
63
|
+
const webhook = new Webhook(client, res, WebhookFixture.getOne.response);
|
|
64
|
+
|
|
65
|
+
it("should remove a webhook", async () => {
|
|
66
|
+
const { parameters, response } = WebhookFixture.delete;
|
|
67
|
+
const { siteId, webhookId } = parameters;
|
|
68
|
+
|
|
69
|
+
const path = `/sites/${siteId}/webhooks/${webhookId}`;
|
|
70
|
+
mock.onDelete(path).reply(200, response);
|
|
71
|
+
const spy = jest.spyOn(Webhook, "remove");
|
|
72
|
+
|
|
73
|
+
const result = await webhook.remove();
|
|
74
|
+
|
|
75
|
+
const _params = { siteId, webhookId, params: undefined };
|
|
76
|
+
expect(spy).toBeCalledWith(_params, client);
|
|
77
|
+
|
|
78
|
+
expect(result).toBeDefined();
|
|
79
|
+
expect(result.deleted).toBe(response.deleted);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ArgumentError, requireArgs } from "../../src/core/error";
|
|
2
|
+
import MockAdapter from "axios-mock-adapter";
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
|
|
5
|
+
describe("Error", () => {
|
|
6
|
+
const mock = new MockAdapter(axios);
|
|
7
|
+
|
|
8
|
+
it("should throw an ArgumentError", () => {
|
|
9
|
+
expect(() => {
|
|
10
|
+
throw new ArgumentError("name");
|
|
11
|
+
}).toThrow("Argument 'name' is required but was not present");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should throw an ArgumentError for required args", () => {
|
|
15
|
+
expect(() => {
|
|
16
|
+
requireArgs({ name: undefined });
|
|
17
|
+
}).toThrow("Argument 'name' is required but was not present");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import axios, { AxiosResponse } from "axios";
|
|
2
|
+
import { WebflowRecord, MetaResponse } from "../../src/core/response";
|
|
3
|
+
|
|
4
|
+
describe("Response", () => {
|
|
5
|
+
const client = axios.create();
|
|
6
|
+
const response: AxiosResponse = {
|
|
7
|
+
status: 200,
|
|
8
|
+
statusText: "OK",
|
|
9
|
+
headers: {
|
|
10
|
+
"x-ratelimit-limit": "100",
|
|
11
|
+
"x-ratelimit-remaining": "99",
|
|
12
|
+
},
|
|
13
|
+
config: {},
|
|
14
|
+
data: {},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
it("should create a MetaResponse", () => {
|
|
18
|
+
const meta = new MetaResponse(response);
|
|
19
|
+
expect(meta.rateLimit.limit).toBe(100);
|
|
20
|
+
expect(meta.rateLimit.remaining).toBe(99);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("should create a WebflowRecord", () => {
|
|
24
|
+
const record = new WebflowRecord(client, response, { id: "123" });
|
|
25
|
+
|
|
26
|
+
// confirm client
|
|
27
|
+
expect(record.client).toBe(client);
|
|
28
|
+
|
|
29
|
+
// confirm response
|
|
30
|
+
expect(record.response).toBe(response);
|
|
31
|
+
|
|
32
|
+
// confirm meta records
|
|
33
|
+
expect(record._meta.rateLimit.limit).toBe(100);
|
|
34
|
+
expect(record._meta.rateLimit.remaining).toBe(99);
|
|
35
|
+
});
|
|
36
|
+
});
|