@canva/cli 1.6.0 → 1.8.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/CHANGELOG.md +22 -0
- package/README.md +1 -1
- package/cli.js +436 -436
- package/package.json +1 -1
- package/templates/base/package.json +1 -1
- package/templates/base/scripts/copy_env.ts +4 -1
- package/templates/dam/package.json +1 -1
- package/templates/dam/scripts/copy_env.ts +4 -1
- package/templates/data_connector/package.json +1 -1
- package/templates/data_connector/scripts/copy_env.ts +4 -1
- package/templates/gen_ai/package.json +1 -1
- package/templates/gen_ai/scripts/copy_env.ts +4 -1
- package/templates/hello_world/package.json +1 -1
- package/templates/hello_world/scripts/copy_env.ts +4 -1
- package/templates/base/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/common/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/common/utils/tests/table_wrapper.tests.ts +0 -252
- package/templates/dam/scripts/start/tests/start.tests.ts +0 -61
- package/templates/dam/utils/backend/jwt_middleware/tests/jwt_middleware.tests.ts +0 -630
- package/templates/data_connector/scripts/start/tests/start.tests.ts +0 -61
- package/templates/gen_ai/scripts/start/tests/start.tests.ts +0 -61
- package/templates/gen_ai/utils/backend/bearer_middleware/tests/bearer_middleware.tests.ts +0 -192
- package/templates/hello_world/scripts/start/tests/start.tests.ts +0 -61
- /package/templates/base/scripts/{start/tests/start.tests.ts → start.tests.ts} +0 -0
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import type { ChildProcess } from "child_process";
|
|
4
|
-
import { spawn } from "child_process";
|
|
5
|
-
import * as treeKill from "tree-kill";
|
|
6
|
-
|
|
7
|
-
describe("start script", () => {
|
|
8
|
-
let serverProcess: ChildProcess;
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
12
|
-
treeKill(serverProcess.pid);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should execute 'npm run start' and start a dev server", async () => {
|
|
17
|
-
const testServerPort = 8089;
|
|
18
|
-
serverProcess = await spawn(
|
|
19
|
-
`npm run start -- -p ${testServerPort} --no-preview`,
|
|
20
|
-
{
|
|
21
|
-
shell: true,
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (!serverProcess.pid) {
|
|
26
|
-
throw new Error("Unable to start server");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// wait for the server to start and collect output until it reports the running URL
|
|
30
|
-
let output = "";
|
|
31
|
-
await new Promise<void>((resolve, reject) => {
|
|
32
|
-
serverProcess.stdout?.on("data", (data) => {
|
|
33
|
-
output += data.toString();
|
|
34
|
-
if (output.includes("Development URL")) {
|
|
35
|
-
resolve();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
serverProcess.stderr?.on("data", (data) => {
|
|
40
|
-
console.error("Server process error: ", data.toString());
|
|
41
|
-
reject();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// timeout and fail test if the server hasn't correctly started in 10 seconds
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
47
|
-
treeKill(serverProcess.pid);
|
|
48
|
-
}
|
|
49
|
-
reject(new Error("Test timed out"));
|
|
50
|
-
}, 10000);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// check that the server is running and accessible
|
|
54
|
-
const expectedServerURL = `http://localhost:${testServerPort}`;
|
|
55
|
-
expect(output).toContain(expectedServerURL);
|
|
56
|
-
expect(serverProcess.exitCode).toBeNull();
|
|
57
|
-
|
|
58
|
-
// clean up
|
|
59
|
-
treeKill(serverProcess.pid);
|
|
60
|
-
}, 15000); // 15 seconds timeout to allow for the server to start
|
|
61
|
-
});
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
2
|
-
import type { NextFunction, Request, Response } from "express";
|
|
3
|
-
import type {
|
|
4
|
-
createBearerMiddleware,
|
|
5
|
-
GetTokenFromRequest,
|
|
6
|
-
} from "../bearer_middleware";
|
|
7
|
-
|
|
8
|
-
type Middleware = (req: Request, res: Response, next: NextFunction) => void;
|
|
9
|
-
|
|
10
|
-
describe("createBearerMiddleware", () => {
|
|
11
|
-
let fakeGetTokenFromRequest: jest.MockedFn<GetTokenFromRequest>;
|
|
12
|
-
let verify: jest.MockedFn<(token: string) => Promise<string | undefined>>;
|
|
13
|
-
|
|
14
|
-
let req: Request;
|
|
15
|
-
let res: Response;
|
|
16
|
-
let next: jest.MockedFn<() => void>;
|
|
17
|
-
|
|
18
|
-
let AuthorizationError: typeof Error;
|
|
19
|
-
let createBearerMiddlewareFn: typeof createBearerMiddleware;
|
|
20
|
-
let bearerMiddleware: Middleware;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
jest.resetAllMocks();
|
|
24
|
-
jest.resetModules();
|
|
25
|
-
|
|
26
|
-
fakeGetTokenFromRequest = jest.fn();
|
|
27
|
-
verify = jest.fn();
|
|
28
|
-
|
|
29
|
-
const middlewareModule = require("../bearer_middleware");
|
|
30
|
-
createBearerMiddlewareFn = middlewareModule.createBearerMiddleware;
|
|
31
|
-
AuthorizationError = middlewareModule.AuthorizationError;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("When called", () => {
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
req = {
|
|
37
|
-
header: (_name: string) => undefined,
|
|
38
|
-
} as Request;
|
|
39
|
-
|
|
40
|
-
res = {
|
|
41
|
-
status: jest.fn().mockReturnThis(),
|
|
42
|
-
json: jest.fn().mockReturnThis(),
|
|
43
|
-
send: jest.fn().mockReturnThis(),
|
|
44
|
-
} as unknown as Response;
|
|
45
|
-
|
|
46
|
-
next = jest.fn();
|
|
47
|
-
|
|
48
|
-
bearerMiddleware = createBearerMiddlewareFn(
|
|
49
|
-
verify,
|
|
50
|
-
fakeGetTokenFromRequest,
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("When `getTokenFromRequest` throws an exception ('Fake error')", () => {
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
fakeGetTokenFromRequest.mockRejectedValue(
|
|
57
|
-
new AuthorizationError("Fake error"),
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it(`Does not call next() and returns HTTP 401 with error = "unauthorized" and message = "Fake error"`, async () => {
|
|
62
|
-
expect.assertions(8);
|
|
63
|
-
|
|
64
|
-
expect(fakeGetTokenFromRequest).not.toHaveBeenCalled();
|
|
65
|
-
await bearerMiddleware(req, res, next);
|
|
66
|
-
|
|
67
|
-
expect(fakeGetTokenFromRequest).toHaveBeenCalledTimes(1);
|
|
68
|
-
expect(fakeGetTokenFromRequest).toHaveBeenLastCalledWith(req);
|
|
69
|
-
|
|
70
|
-
expect(res.status).toHaveBeenCalledTimes(1);
|
|
71
|
-
expect(res.status).toHaveBeenLastCalledWith(401);
|
|
72
|
-
|
|
73
|
-
expect(res.json).toHaveBeenCalledTimes(1);
|
|
74
|
-
expect(res.json).toHaveBeenLastCalledWith({
|
|
75
|
-
error: "unauthorized",
|
|
76
|
-
message: "Fake error",
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
expect(next).not.toHaveBeenCalled();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("When the middleware cannot verify the token", () => {
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
fakeGetTokenFromRequest.mockReturnValue("TOKEN");
|
|
86
|
-
|
|
87
|
-
verify.mockImplementation(() => Promise.resolve(undefined));
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it(`Does not call next() and returns HTTP 401 with error = "unauthorized" and message = "Token is invalid"`, async () => {
|
|
91
|
-
expect.assertions(5);
|
|
92
|
-
|
|
93
|
-
await bearerMiddleware(req, res, next);
|
|
94
|
-
|
|
95
|
-
expect(res.status).toHaveBeenCalledTimes(1);
|
|
96
|
-
expect(res.status).toHaveBeenLastCalledWith(401);
|
|
97
|
-
|
|
98
|
-
expect(res.json).toHaveBeenCalledTimes(1);
|
|
99
|
-
expect(res.json).toHaveBeenLastCalledWith({
|
|
100
|
-
error: "unauthorized",
|
|
101
|
-
message: "Token is invalid",
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
expect(next).not.toHaveBeenCalled();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("getTokenFromHttpHeader", () => {
|
|
111
|
-
let getHeader: jest.MockedFn<(name: string) => string | undefined>;
|
|
112
|
-
let req: Request;
|
|
113
|
-
let getTokenFromHttpHeader: (req: Request) => string;
|
|
114
|
-
let AuthorizationError: typeof Error;
|
|
115
|
-
|
|
116
|
-
beforeEach(() => {
|
|
117
|
-
getHeader = jest.fn();
|
|
118
|
-
req = {
|
|
119
|
-
header: (name: string) => getHeader(name),
|
|
120
|
-
} as Request;
|
|
121
|
-
|
|
122
|
-
const bearerMiddlewareModule = require("../bearer_middleware");
|
|
123
|
-
getTokenFromHttpHeader = bearerMiddlewareModule.getTokenFromHttpHeader;
|
|
124
|
-
AuthorizationError = bearerMiddlewareModule.AuthorizationError;
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("When the 'Authorization' header is missing", () => {
|
|
128
|
-
beforeEach(() => {
|
|
129
|
-
getHeader.mockReturnValue(undefined);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it(`Throws a AuthorizationError with message = 'Missing the "Authorization" header'`, async () => {
|
|
133
|
-
expect.assertions(3);
|
|
134
|
-
|
|
135
|
-
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
136
|
-
new AuthorizationError('Missing the "Authorization" header'),
|
|
137
|
-
);
|
|
138
|
-
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
139
|
-
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("When the 'Authorization' header doesn't have a Bearer scheme", () => {
|
|
144
|
-
beforeEach(() => {
|
|
145
|
-
getHeader.mockReturnValue("Beerer FAKE_TOKEN");
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it(`Throws a AuthorizationError with message = 'Missing a "Bearer" token in the "Authorization" header''`, async () => {
|
|
149
|
-
expect.assertions(3);
|
|
150
|
-
|
|
151
|
-
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
152
|
-
new AuthorizationError(
|
|
153
|
-
'Missing a "Bearer" token in the "Authorization" header',
|
|
154
|
-
),
|
|
155
|
-
);
|
|
156
|
-
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
157
|
-
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("When the 'Authorization' Bearer scheme header doesn't have a token", () => {
|
|
162
|
-
beforeEach(() => {
|
|
163
|
-
getHeader.mockReturnValue("Bearer ");
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it(`Throws a AuthorizationError with message = 'Missing a "Bearer" token in the "Authorization" header'`, async () => {
|
|
167
|
-
expect.assertions(3);
|
|
168
|
-
|
|
169
|
-
expect(() => getTokenFromHttpHeader(req)).toThrow(
|
|
170
|
-
new AuthorizationError(
|
|
171
|
-
'Missing a "Bearer" token in the "Authorization" header',
|
|
172
|
-
),
|
|
173
|
-
);
|
|
174
|
-
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
175
|
-
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe("When the 'Authorization' Bearer scheme header has a token", () => {
|
|
180
|
-
beforeEach(() => {
|
|
181
|
-
getHeader.mockReturnValue("Bearer TOKEN");
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it(`Returns the token`, async () => {
|
|
185
|
-
expect.assertions(3);
|
|
186
|
-
|
|
187
|
-
expect(getTokenFromHttpHeader(req)).toEqual("TOKEN");
|
|
188
|
-
expect(getHeader).toHaveBeenCalledTimes(1);
|
|
189
|
-
expect(getHeader).toHaveBeenLastCalledWith("Authorization");
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import type { ChildProcess } from "child_process";
|
|
4
|
-
import { spawn } from "child_process";
|
|
5
|
-
import * as treeKill from "tree-kill";
|
|
6
|
-
|
|
7
|
-
describe("start script", () => {
|
|
8
|
-
let serverProcess: ChildProcess;
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
12
|
-
treeKill(serverProcess.pid);
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("should execute 'npm run start' and start a dev server", async () => {
|
|
17
|
-
const testServerPort = 8089;
|
|
18
|
-
serverProcess = await spawn(
|
|
19
|
-
`npm run start -- -p ${testServerPort} --no-preview`,
|
|
20
|
-
{
|
|
21
|
-
shell: true,
|
|
22
|
-
},
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
if (!serverProcess.pid) {
|
|
26
|
-
throw new Error("Unable to start server");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// wait for the server to start and collect output until it reports the running URL
|
|
30
|
-
let output = "";
|
|
31
|
-
await new Promise<void>((resolve, reject) => {
|
|
32
|
-
serverProcess.stdout?.on("data", (data) => {
|
|
33
|
-
output += data.toString();
|
|
34
|
-
if (output.includes("Development URL")) {
|
|
35
|
-
resolve();
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
serverProcess.stderr?.on("data", (data) => {
|
|
40
|
-
console.error("Server process error: ", data.toString());
|
|
41
|
-
reject();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// timeout and fail test if the server hasn't correctly started in 10 seconds
|
|
45
|
-
setTimeout(() => {
|
|
46
|
-
if (serverProcess?.pid && !serverProcess.exitCode) {
|
|
47
|
-
treeKill(serverProcess.pid);
|
|
48
|
-
}
|
|
49
|
-
reject(new Error("Test timed out"));
|
|
50
|
-
}, 10000);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// check that the server is running and accessible
|
|
54
|
-
const expectedServerURL = `http://localhost:${testServerPort}`;
|
|
55
|
-
expect(output).toContain(expectedServerURL);
|
|
56
|
-
expect(serverProcess.exitCode).toBeNull();
|
|
57
|
-
|
|
58
|
-
// clean up
|
|
59
|
-
treeKill(serverProcess.pid);
|
|
60
|
-
}, 15000); // 15 seconds timeout to allow for the server to start
|
|
61
|
-
});
|
|
File without changes
|