@swell/cli 1.0.2 → 2.0.1-alpha.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/LICENSE.md +21 -0
- package/README.md +1 -1
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +7 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +7 -0
- package/dist/app-command.d.ts +22 -0
- package/dist/app-command.js +45 -0
- package/dist/commands/app/_pull.d.ts +8 -0
- package/dist/commands/app/_pull.js +45 -0
- package/dist/commands/app/_uninstall.d.ts +12 -0
- package/dist/commands/app/_uninstall.js +45 -0
- package/dist/commands/app/info.d.ts +15 -0
- package/dist/commands/app/info.js +92 -0
- package/dist/commands/app/install.d.ts +17 -0
- package/dist/commands/app/install.js +177 -0
- package/dist/commands/app/push.d.ts +17 -0
- package/dist/commands/app/push.js +158 -0
- package/dist/commands/app/version.d.ts +18 -0
- package/dist/commands/app/version.js +156 -0
- package/dist/commands/app/watch.d.ts +15 -0
- package/dist/commands/app/watch.js +110 -0
- package/dist/commands/create/app.d.ts +21 -0
- package/dist/commands/create/app.js +210 -0
- package/dist/commands/create/content.d.ts +19 -0
- package/dist/commands/create/content.js +87 -0
- package/dist/commands/create/function.d.ts +25 -0
- package/dist/commands/create/function.js +191 -0
- package/dist/commands/create/index.d.ts +6 -0
- package/dist/commands/create/index.js +34 -0
- package/dist/commands/create/model.d.ts +19 -0
- package/dist/commands/create/model.js +87 -0
- package/dist/commands/create/notification.d.ts +25 -0
- package/dist/commands/create/notification.js +170 -0
- package/dist/commands/login.d.ts +22 -0
- package/dist/commands/login.js +77 -0
- package/dist/commands/logout.d.ts +8 -0
- package/dist/commands/logout.js +45 -0
- package/dist/commands/logs.d.ts +23 -0
- package/dist/commands/logs.js +207 -0
- package/dist/commands/switch.d.ts +10 -0
- package/dist/commands/switch.js +41 -0
- package/dist/commands/whoami.d.ts +7 -0
- package/dist/commands/whoami.js +24 -0
- package/dist/create-collection-command.d.ts +26 -0
- package/dist/create-collection-command.js +97 -0
- package/dist/create-command.d.ts +16 -0
- package/dist/create-command.js +59 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/api.d.ts +13 -0
- package/dist/lib/api.js +117 -0
- package/dist/lib/app-config.d.ts +29 -0
- package/dist/lib/app-config.js +127 -0
- package/dist/lib/apps/app-config.d.ts +42 -0
- package/dist/lib/apps/app-config.js +167 -0
- package/dist/lib/apps/index.d.ts +67 -0
- package/dist/lib/apps/index.js +167 -0
- package/dist/lib/apps/paths.d.ts +18 -0
- package/dist/lib/apps/paths.js +54 -0
- package/dist/lib/bundle.d.ts +1 -0
- package/dist/lib/bundle.js +40 -0
- package/dist/lib/config.d.ts +37 -0
- package/dist/lib/config.js +131 -0
- package/dist/lib/constants.d.ts +5 -0
- package/dist/lib/constants.js +17 -0
- package/dist/lib/create/content.d.ts +23 -0
- package/dist/lib/create/content.js +40 -0
- package/dist/lib/create/function.d.ts +17 -0
- package/dist/lib/create/function.js +36 -0
- package/dist/lib/create/index.d.ts +13 -0
- package/dist/lib/create/index.js +20 -0
- package/dist/lib/create/model.d.ts +22 -0
- package/dist/lib/create/model.js +30 -0
- package/dist/lib/create/notification.d.ts +25 -0
- package/dist/lib/create/notification.js +1 -0
- package/dist/lib/info.d.ts +38 -0
- package/dist/lib/info.js +91 -0
- package/dist/lib/logs/index.d.ts +23 -0
- package/dist/lib/logs/index.js +88 -0
- package/dist/lib/logs/line-output.d.ts +5 -0
- package/dist/lib/logs/line-output.js +13 -0
- package/dist/lib/logs/output.d.ts +7 -0
- package/dist/lib/logs/output.js +8 -0
- package/dist/lib/logs/table-output.d.ts +11 -0
- package/dist/lib/logs/table-output.js +128 -0
- package/dist/lib/sessions.d.ts +9 -0
- package/dist/lib/sessions.js +110 -0
- package/dist/lib/stores.d.ts +63 -0
- package/dist/lib/stores.js +173 -0
- package/dist/lib/style.d.ts +24 -0
- package/dist/lib/style.js +29 -0
- package/dist/lib/swell-function-wrapper.d.ts +88 -0
- package/dist/lib/swell-function-wrapper.js +302 -0
- package/dist/remote-app-command.d.ts +36 -0
- package/dist/remote-app-command.js +367 -0
- package/dist/swell-command.d.ts +21 -0
- package/dist/swell-command.js +43 -0
- package/oclif.manifest.json +1085 -0
- package/package.json +89 -42
- package/LICENSE +0 -674
- package/dist/bin/multipart-parser-85ef9626.js +0 -456
- package/dist/bin/swell-0f71f07d.js +0 -30670
- package/dist/bin/swell.js +0 -24
- package/dist/man/swell.1 +0 -85
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the session id for the passed in store. If the session is not found,
|
|
3
|
+
* open the browser to login and return the session id.
|
|
4
|
+
*
|
|
5
|
+
* @param storeId - The store to get the session id for
|
|
6
|
+
* @returns A promise that resolves to the session id
|
|
7
|
+
*/
|
|
8
|
+
declare function getSessionIdOrLoginInBrowser(storeId?: string | undefined): Promise<string[]>;
|
|
9
|
+
export { getSessionIdOrLoginInBrowser };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ux } from '@oclif/core';
|
|
2
|
+
import * as http from 'node:http';
|
|
3
|
+
import open from 'open';
|
|
4
|
+
import { getLoginHost } from './constants.js';
|
|
5
|
+
import style from './style.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get the session id for the passed in store. If the session is not found,
|
|
8
|
+
* open the browser to login and return the session id.
|
|
9
|
+
*
|
|
10
|
+
* @param storeId - The store to get the session id for
|
|
11
|
+
* @returns A promise that resolves to the session id
|
|
12
|
+
*/
|
|
13
|
+
function getSessionIdOrLoginInBrowser(storeId) {
|
|
14
|
+
return new Promise((resolve, _reject) => {
|
|
15
|
+
const onSessionId = (sessionId, storeId) => resolve([sessionId, storeId]);
|
|
16
|
+
createServer(onSessionId, storeId);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function createServer(onSessionId, storeId) {
|
|
20
|
+
// the spinner is used to show progress while waiting for the browser
|
|
21
|
+
const spinner = ux.action;
|
|
22
|
+
serverForLogin({
|
|
23
|
+
storeId,
|
|
24
|
+
onPost(req) {
|
|
25
|
+
// we received the session id from the browser so we can move on
|
|
26
|
+
const sessionId = req.headers['x-session'];
|
|
27
|
+
const storeId = req.headers['x-store'];
|
|
28
|
+
if (sessionId) {
|
|
29
|
+
spinner.stop('Browser authentication successful');
|
|
30
|
+
onSessionId(sessionId, storeId);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
async onStart(loginUrl) {
|
|
34
|
+
spinner.start([
|
|
35
|
+
"Open this link if your browser doesn't launch it automatically:",
|
|
36
|
+
`${style.link(loginUrl)}`,
|
|
37
|
+
].join(' '));
|
|
38
|
+
await open(loginUrl);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Start a local HTTP server to handle the POST and GET requests from the
|
|
44
|
+
* browser login flow.
|
|
45
|
+
*
|
|
46
|
+
* The POST request will contain the session id in the `x-session` header.
|
|
47
|
+
*
|
|
48
|
+
* The GET request will be used to close the connection after the login flow
|
|
49
|
+
* is complete.
|
|
50
|
+
*
|
|
51
|
+
* @param onSessionId - A callback to run when the session id is received
|
|
52
|
+
* from the browser
|
|
53
|
+
* @returns void
|
|
54
|
+
*/
|
|
55
|
+
function serverForLogin({ storeId, onPost, onStart, }) {
|
|
56
|
+
// flag to track if the POST and GET requests have been handled
|
|
57
|
+
// we only want to handle them once
|
|
58
|
+
let postHandled = false;
|
|
59
|
+
let getHandled = false;
|
|
60
|
+
// Create the HTTP server
|
|
61
|
+
const server = http.createServer(async (req, res) => {
|
|
62
|
+
// Set CORS headers
|
|
63
|
+
res.setHeader('Access-Control-Allow-Origin', getLoginHost(storeId));
|
|
64
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
65
|
+
res.setHeader('Access-Control-Allow-Headers', 'Origin, Content-Type, x-session, x-store');
|
|
66
|
+
if (req.method === 'POST' && !postHandled) {
|
|
67
|
+
onPost(req);
|
|
68
|
+
res.statusCode = 200;
|
|
69
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
70
|
+
res.end('POST request handled');
|
|
71
|
+
postHandled = true;
|
|
72
|
+
}
|
|
73
|
+
else if (req.method === 'GET' && !getHandled) {
|
|
74
|
+
res.statusCode = 200;
|
|
75
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
76
|
+
// Close the HTTP connection to prevent `server.close()` from hanging
|
|
77
|
+
res.setHeader('connection', 'close');
|
|
78
|
+
// The browser will show this message in the window
|
|
79
|
+
res.end('Authentication successful, you can close this window and return to the terminal.');
|
|
80
|
+
getHandled = true;
|
|
81
|
+
}
|
|
82
|
+
else if (req.method === 'OPTIONS') {
|
|
83
|
+
res.statusCode = 200;
|
|
84
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
85
|
+
res.end('ok');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Return 404 for subsequent requests or other request types
|
|
89
|
+
res.statusCode = 404;
|
|
90
|
+
res.end('Not Found');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
server.listen(0, '127.0.0.1', async () => {
|
|
94
|
+
const serverAddr = server.address();
|
|
95
|
+
// the port will be dynamically assigned, one of the available ports
|
|
96
|
+
const localServerUrl = Buffer.from(`http://${serverAddr.address}:${serverAddr.port}/`).toString('base64');
|
|
97
|
+
const loginUrl = `${getLoginHost(storeId)}/admin?cli=${localServerUrl}`;
|
|
98
|
+
onStart(loginUrl);
|
|
99
|
+
});
|
|
100
|
+
const closeInterval = setInterval(() => {
|
|
101
|
+
if (postHandled) {
|
|
102
|
+
server.close(() => {
|
|
103
|
+
clearInterval(closeInterval);
|
|
104
|
+
});
|
|
105
|
+
server.emit('close');
|
|
106
|
+
server.removeAllListeners('close');
|
|
107
|
+
}
|
|
108
|
+
}, 100);
|
|
109
|
+
}
|
|
110
|
+
export { getSessionIdOrLoginInBrowser };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a list of stores while also highlighting the current store.
|
|
3
|
+
*
|
|
4
|
+
* @example <caption>Example output:</caption>
|
|
5
|
+
*
|
|
6
|
+
* > Stores you are logged in to:
|
|
7
|
+
* >
|
|
8
|
+
* > - Test Store, test
|
|
9
|
+
* > - Another Test, another-test (current)
|
|
10
|
+
*
|
|
11
|
+
* @param stores - The stores to build the display for
|
|
12
|
+
* @param currentStoreId - The ID of the default store
|
|
13
|
+
* @returns A list of stores ready to display.
|
|
14
|
+
*/
|
|
15
|
+
declare function showStores(stores: Store[], currentStoreId: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Select the store to login to from a CLI prompt.
|
|
18
|
+
*
|
|
19
|
+
* By default it will only show stores for which we don't already have a
|
|
20
|
+
* session id. If `force` is true, show all stores to pull the session id
|
|
21
|
+
* again.
|
|
22
|
+
*
|
|
23
|
+
* @param currentStoreId - The ID of the default store
|
|
24
|
+
* @param authorizations - The authorizations for the current user
|
|
25
|
+
* @param force - Whether to show all stores or not
|
|
26
|
+
*
|
|
27
|
+
* @returns The store ID to login to
|
|
28
|
+
*/
|
|
29
|
+
declare function selectStoreId({ authorizations, currentStoreId, force, }: {
|
|
30
|
+
authorizations: UserAuthorization[];
|
|
31
|
+
currentStoreId: string;
|
|
32
|
+
force: boolean;
|
|
33
|
+
}): Promise<any>;
|
|
34
|
+
/**
|
|
35
|
+
* Select the store to switch to from a CLI prompt from the list of
|
|
36
|
+
* already logged in stores.
|
|
37
|
+
*
|
|
38
|
+
* @returns The store ID to switch to
|
|
39
|
+
* @throws CLIError - If there are no stores to switch to
|
|
40
|
+
*/
|
|
41
|
+
declare function selectLoggedInStoreId(message?: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Select an environment.
|
|
44
|
+
*
|
|
45
|
+
* @throws CLIError - If there are no stores to switch to
|
|
46
|
+
*/
|
|
47
|
+
declare function selectEnvironmentId(message?: string): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Ask the user if they want to make the given store id the default store.
|
|
50
|
+
*
|
|
51
|
+
* If there is no current store id, it will always be set as the default
|
|
52
|
+
* without asking.
|
|
53
|
+
*
|
|
54
|
+
* @param currentStoreId - The ID of the default store
|
|
55
|
+
* @param storeId - The ID of the store to set as the default
|
|
56
|
+
*
|
|
57
|
+
* @returns void
|
|
58
|
+
*/
|
|
59
|
+
declare function modifyDefaultStore({ currentStoreId, storeId, }: {
|
|
60
|
+
currentStoreId: string;
|
|
61
|
+
storeId: string;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
export { modifyDefaultStore, selectLoggedInStoreId, selectStoreId, selectEnvironmentId, showStores, };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Separator, confirm, select } from '@inquirer/prompts';
|
|
2
|
+
import { CLIError } from '@oclif/errors';
|
|
3
|
+
import config from './config.js';
|
|
4
|
+
import style from './style.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds a list of stores while also highlighting the current store.
|
|
7
|
+
*
|
|
8
|
+
* @example <caption>Example output:</caption>
|
|
9
|
+
*
|
|
10
|
+
* > Stores you are logged in to:
|
|
11
|
+
* >
|
|
12
|
+
* > - Test Store, test
|
|
13
|
+
* > - Another Test, another-test (current)
|
|
14
|
+
*
|
|
15
|
+
* @param stores - The stores to build the display for
|
|
16
|
+
* @param currentStoreId - The ID of the default store
|
|
17
|
+
* @returns A list of stores ready to display.
|
|
18
|
+
*/
|
|
19
|
+
function showStores(stores, currentStoreId) {
|
|
20
|
+
if (stores.length === 0) {
|
|
21
|
+
throw new CLIError('You are not logged in to any store.');
|
|
22
|
+
}
|
|
23
|
+
function currentStoreLabel(store) {
|
|
24
|
+
if (stores.length === 1 || store.storeId !== currentStoreId) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
return `(${style.basicHighlight('current')})`;
|
|
28
|
+
}
|
|
29
|
+
let storesOutput = '';
|
|
30
|
+
for (const [index, store] of stores.entries()) {
|
|
31
|
+
// builds each line of the output, for every store
|
|
32
|
+
// e.g. - Another Test, another-test (current)
|
|
33
|
+
storesOutput += [
|
|
34
|
+
`- ${store.name},`,
|
|
35
|
+
`${style.storeId(store.storeId)}`,
|
|
36
|
+
`${style.storeId(currentStoreLabel(store))}`,
|
|
37
|
+
// don't add a newline on the last line:
|
|
38
|
+
index === stores.length - 1 ? null : '\n',
|
|
39
|
+
]
|
|
40
|
+
.filter(Boolean)
|
|
41
|
+
.join(' ');
|
|
42
|
+
}
|
|
43
|
+
return storesOutput;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Select the store to login to from a CLI prompt.
|
|
47
|
+
*
|
|
48
|
+
* By default it will only show stores for which we don't already have a
|
|
49
|
+
* session id. If `force` is true, show all stores to pull the session id
|
|
50
|
+
* again.
|
|
51
|
+
*
|
|
52
|
+
* @param currentStoreId - The ID of the default store
|
|
53
|
+
* @param authorizations - The authorizations for the current user
|
|
54
|
+
* @param force - Whether to show all stores or not
|
|
55
|
+
*
|
|
56
|
+
* @returns The store ID to login to
|
|
57
|
+
*/
|
|
58
|
+
async function selectStoreId({ authorizations, currentStoreId, force = false, }) {
|
|
59
|
+
let selectStoreChoices;
|
|
60
|
+
let selectedStoreId;
|
|
61
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
62
|
+
if (force) {
|
|
63
|
+
// show all stores
|
|
64
|
+
selectStoreChoices = authorizations.map((auth) => ({
|
|
65
|
+
name: auth.client_name +
|
|
66
|
+
(auth.client_id === currentStoreId
|
|
67
|
+
? ` (${style.basicHighlight('current')})`
|
|
68
|
+
: ''),
|
|
69
|
+
value: auth.client_id,
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// only show the stores for which we don't already have a session id
|
|
74
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
75
|
+
selectStoreChoices = authorizations.reduce((acc, auth) => {
|
|
76
|
+
if (!config.getSessionId(auth.client_id)) {
|
|
77
|
+
acc.push({
|
|
78
|
+
name: auth.client_name,
|
|
79
|
+
value: auth.client_id,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return acc;
|
|
83
|
+
}, []);
|
|
84
|
+
}
|
|
85
|
+
// if more than one option, show the select options, otherwise just return
|
|
86
|
+
// the available one
|
|
87
|
+
if (selectStoreChoices.length > 1) {
|
|
88
|
+
selectedStoreId = await select({
|
|
89
|
+
choices: selectStoreChoices,
|
|
90
|
+
message: 'Which store do you want to login to on the CLI?',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
else if (selectStoreChoices.length === 1) {
|
|
94
|
+
selectedStoreId = selectStoreChoices[0].value;
|
|
95
|
+
}
|
|
96
|
+
// we can also return `undefined` when we already have sessions for all
|
|
97
|
+
// stores: no force and no selectStoreChoices
|
|
98
|
+
return selectedStoreId;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Select the store to switch to from a CLI prompt from the list of
|
|
102
|
+
* already logged in stores.
|
|
103
|
+
*
|
|
104
|
+
* @returns The store ID to switch to
|
|
105
|
+
* @throws CLIError - If there are no stores to switch to
|
|
106
|
+
*/
|
|
107
|
+
async function selectLoggedInStoreId(message) {
|
|
108
|
+
const currentStoreId = config.getDefaultStore();
|
|
109
|
+
const loggedInStores = config.get('stores') || [];
|
|
110
|
+
if (loggedInStores.length === 0) {
|
|
111
|
+
throw new CLIError(`You are not logged in. Run ${style.command('swell login')} to continue.`);
|
|
112
|
+
}
|
|
113
|
+
const selectStoreChoices = loggedInStores.map((store) => ({
|
|
114
|
+
name: `${store.name} (${store.storeId})` +
|
|
115
|
+
(store.storeId === currentStoreId
|
|
116
|
+
? ` [${style.basicHighlight('current')}]`
|
|
117
|
+
: ''),
|
|
118
|
+
value: store.storeId,
|
|
119
|
+
}));
|
|
120
|
+
return select({
|
|
121
|
+
choices: [
|
|
122
|
+
...selectStoreChoices,
|
|
123
|
+
new Separator(),
|
|
124
|
+
{ name: 'Login to another account', value: '' },
|
|
125
|
+
],
|
|
126
|
+
message: message || 'Which store do you want to switch to?',
|
|
127
|
+
pageSize: 25,
|
|
128
|
+
loop: false,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Select an environment.
|
|
133
|
+
*
|
|
134
|
+
* @throws CLIError - If there are no stores to switch to
|
|
135
|
+
*/
|
|
136
|
+
async function selectEnvironmentId(message) {
|
|
137
|
+
return select({
|
|
138
|
+
choices: [
|
|
139
|
+
{
|
|
140
|
+
name: '[live]',
|
|
141
|
+
value: '',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: '[test]',
|
|
145
|
+
value: 'test',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
message: message || 'Which envoronment?',
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Ask the user if they want to make the given store id the default store.
|
|
153
|
+
*
|
|
154
|
+
* If there is no current store id, it will always be set as the default
|
|
155
|
+
* without asking.
|
|
156
|
+
*
|
|
157
|
+
* @param currentStoreId - The ID of the default store
|
|
158
|
+
* @param storeId - The ID of the store to set as the default
|
|
159
|
+
*
|
|
160
|
+
* @returns void
|
|
161
|
+
*/
|
|
162
|
+
async function modifyDefaultStore({ currentStoreId, storeId, }) {
|
|
163
|
+
let modifyDefault = false;
|
|
164
|
+
if (currentStoreId && currentStoreId !== storeId) {
|
|
165
|
+
modifyDefault = await confirm({
|
|
166
|
+
message: `Do you want to make ${style.storeId(storeId)} your default store?`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (!currentStoreId || modifyDefault) {
|
|
170
|
+
config.setDefaultStore(storeId);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
export { modifyDefaultStore, selectLoggedInStoreId, selectStoreId, selectEnvironmentId, showStores, };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
basicHighlight: import("chalk").ChalkInstance;
|
|
3
|
+
error: import("chalk").ChalkInstance;
|
|
4
|
+
success: import("chalk").ChalkInstance;
|
|
5
|
+
link: import("chalk").ChalkInstance;
|
|
6
|
+
path: import("chalk").ChalkInstance;
|
|
7
|
+
dim: import("chalk").ChalkInstance;
|
|
8
|
+
command: import("chalk").ChalkInstance;
|
|
9
|
+
storeId: import("chalk").ChalkInstance;
|
|
10
|
+
currentUser: import("chalk").ChalkInstance;
|
|
11
|
+
appEnvLive: import("chalk").ChalkInstance;
|
|
12
|
+
appEnv: import("chalk").ChalkInstance;
|
|
13
|
+
appConfigName: import("chalk").ChalkInstance;
|
|
14
|
+
appConfigValue: import("chalk").ChalkInstance;
|
|
15
|
+
logDate: import("chalk").ChalkInstance;
|
|
16
|
+
logStatus: import("chalk").ChalkInstance;
|
|
17
|
+
logMethod: import("chalk").ChalkInstance;
|
|
18
|
+
logApp: import("chalk").ChalkInstance;
|
|
19
|
+
funcInfo: import("chalk").ChalkInstance;
|
|
20
|
+
funcDebug: import("chalk").ChalkInstance;
|
|
21
|
+
funcWarn: import("chalk").ChalkInstance;
|
|
22
|
+
funcError: import("chalk").ChalkInstance;
|
|
23
|
+
};
|
|
24
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable perfectionist/sort-objects */
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
export default {
|
|
4
|
+
basicHighlight: chalk.bold,
|
|
5
|
+
error: chalk.red,
|
|
6
|
+
success: chalk.green,
|
|
7
|
+
link: chalk.blueBright.underline,
|
|
8
|
+
path: chalk.underline,
|
|
9
|
+
dim: chalk.dim,
|
|
10
|
+
// styles for consistent output of some elements
|
|
11
|
+
command: chalk.magenta.bold,
|
|
12
|
+
storeId: chalk.yellow,
|
|
13
|
+
currentUser: chalk.blueBright.underline,
|
|
14
|
+
// apps
|
|
15
|
+
appEnvLive: chalk.magenta,
|
|
16
|
+
appEnv: chalk.yellow,
|
|
17
|
+
appConfigName: chalk.yellow,
|
|
18
|
+
appConfigValue: chalk.green,
|
|
19
|
+
// logs
|
|
20
|
+
logDate: chalk.cyan,
|
|
21
|
+
logStatus: chalk.yellow,
|
|
22
|
+
logMethod: chalk.green,
|
|
23
|
+
logApp: chalk.magenta,
|
|
24
|
+
// function logs
|
|
25
|
+
funcInfo: chalk.white,
|
|
26
|
+
funcDebug: chalk.cyan,
|
|
27
|
+
funcWarn: chalk.yellow,
|
|
28
|
+
funcError: chalk.red,
|
|
29
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
declare function handleRequest(originalRequest: any, _env: any, context: any): Promise<Response>;
|
|
2
|
+
/**
|
|
3
|
+
* Invokes one of the function types that are available.
|
|
4
|
+
*
|
|
5
|
+
* Type-1: Named export function handlers
|
|
6
|
+
* ```
|
|
7
|
+
* export function post (req) {
|
|
8
|
+
*
|
|
9
|
+
* }
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Important note:
|
|
13
|
+
* - `delete` func cannot be implemented in Type-1 since it's a reserved name. So, consider using Type-3.
|
|
14
|
+
*
|
|
15
|
+
* Type-2: Default export function handlers
|
|
16
|
+
* ```
|
|
17
|
+
* export default function (req) {
|
|
18
|
+
*
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Type-3: Default object with named function handlers
|
|
23
|
+
* ```
|
|
24
|
+
* export default {
|
|
25
|
+
* delete(req) {
|
|
26
|
+
*
|
|
27
|
+
* },
|
|
28
|
+
* post(req) {
|
|
29
|
+
*
|
|
30
|
+
* },
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param {SwellRequest} req
|
|
35
|
+
* @param {Event} context
|
|
36
|
+
*/
|
|
37
|
+
declare function executeModuleHandler(req: SwellRequest, context: Event): Promise<any>;
|
|
38
|
+
declare const origialConsoleLog: {
|
|
39
|
+
(...data: any[]): void;
|
|
40
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
41
|
+
};
|
|
42
|
+
declare class SwellRequest {
|
|
43
|
+
constructor(req: any, context: any);
|
|
44
|
+
originalRequest: any;
|
|
45
|
+
context: any;
|
|
46
|
+
appId: any;
|
|
47
|
+
storeId: any;
|
|
48
|
+
accessToken: any;
|
|
49
|
+
publicKey: any;
|
|
50
|
+
store: any;
|
|
51
|
+
session: any;
|
|
52
|
+
logParams: any;
|
|
53
|
+
apiHost: any;
|
|
54
|
+
id: any;
|
|
55
|
+
swell: SwellAPI;
|
|
56
|
+
body: {};
|
|
57
|
+
query: {};
|
|
58
|
+
data: {};
|
|
59
|
+
_logs: any[];
|
|
60
|
+
assignRequestProps(req: any): void;
|
|
61
|
+
initialize(): Promise<void>;
|
|
62
|
+
url: URL | undefined;
|
|
63
|
+
parseJson(input: any): any;
|
|
64
|
+
log(level: any, ...line: any[]): void;
|
|
65
|
+
ingestLogs(response: any): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
declare class SwellAPI {
|
|
68
|
+
constructor(req: any, context: any);
|
|
69
|
+
request: any;
|
|
70
|
+
baseUrl: any;
|
|
71
|
+
basicAuth: string;
|
|
72
|
+
context: any;
|
|
73
|
+
toBase64(inputString: any): string;
|
|
74
|
+
stringifyQuery(queryObject: any, prefix: any): any;
|
|
75
|
+
makeRequest(method: any, url: any, data: any): Promise<any>;
|
|
76
|
+
get(url: any, query: any): Promise<any>;
|
|
77
|
+
put(url: any, data: any): Promise<any>;
|
|
78
|
+
post(url: any, data: any): Promise<any>;
|
|
79
|
+
delete(url: any, data: any): Promise<any>;
|
|
80
|
+
settings(id?: any): Promise<any>;
|
|
81
|
+
}
|
|
82
|
+
declare class SwellError extends Error {
|
|
83
|
+
constructor(message: any, options?: {});
|
|
84
|
+
status: any;
|
|
85
|
+
}
|
|
86
|
+
declare class SwellResponse extends Response {
|
|
87
|
+
constructor(data: any, options?: {});
|
|
88
|
+
}
|