@swell/cli 2.0.20 → 2.2.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/dist/commands/api/delete.d.ts +15 -0
- package/dist/commands/api/delete.js +26 -0
- package/dist/commands/api/get.d.ts +15 -0
- package/dist/commands/api/get.js +31 -0
- package/dist/commands/api/index.d.ts +7 -0
- package/dist/commands/api/index.js +16 -0
- package/dist/commands/api/post.d.ts +16 -0
- package/dist/commands/api/post.js +33 -0
- package/dist/commands/api/put.d.ts +16 -0
- package/dist/commands/api/put.js +33 -0
- package/dist/commands/app/dev.d.ts +18 -4
- package/dist/commands/app/dev.js +383 -5
- package/dist/commands/app/frontend/dev.d.ts +6 -5
- package/dist/commands/app/frontend/dev.js +127 -58
- package/dist/commands/app/install.js +3 -3
- package/dist/commands/app/pull.d.ts +1 -1
- package/dist/commands/app/pull.js +6 -6
- package/dist/commands/app/push.d.ts +3 -3
- package/dist/commands/app/push.js +8 -6
- package/dist/commands/app/release.d.ts +1 -1
- package/dist/commands/app/release.js +1 -1
- package/dist/commands/app/version.d.ts +1 -1
- package/dist/commands/app/version.js +5 -3
- package/dist/commands/create/app.d.ts +10 -2
- package/dist/commands/create/app.js +226 -57
- package/dist/commands/create/content.d.ts +4 -0
- package/dist/commands/create/content.js +83 -15
- package/dist/commands/create/function.js +27 -5
- package/dist/commands/create/model.d.ts +4 -0
- package/dist/commands/create/model.js +120 -25
- package/dist/commands/inspect/content.d.ts +25 -0
- package/dist/commands/inspect/content.js +159 -0
- package/dist/commands/inspect/index.d.ts +7 -0
- package/dist/commands/inspect/index.js +16 -0
- package/dist/commands/inspect/models.d.ts +27 -0
- package/dist/commands/inspect/models.js +197 -0
- package/dist/commands/schema.d.ts +27 -0
- package/dist/commands/schema.js +231 -0
- package/dist/commands/theme/dev.d.ts +1 -1
- package/dist/commands/theme/dev.js +2 -2
- package/dist/commands/theme/init.d.ts +1 -1
- package/dist/commands/theme/init.js +1 -1
- package/dist/commands/theme/pull.d.ts +2 -2
- package/dist/commands/theme/pull.js +2 -2
- package/dist/commands/theme/push.d.ts +1 -1
- package/dist/commands/theme/push.js +1 -1
- package/dist/create-app-command.d.ts +14 -0
- package/dist/create-app-command.js +198 -15
- package/dist/create-collection-command.js +4 -1
- package/dist/create-config-command.js +4 -0
- package/dist/env/local.d.ts +2 -0
- package/dist/env/local.js +2 -0
- package/dist/env/production.d.ts +2 -0
- package/dist/env/production.js +2 -0
- package/dist/env/review.d.ts +2 -0
- package/dist/env/review.js +2 -0
- package/dist/env/staging.d.ts +2 -0
- package/dist/env/staging.js +2 -0
- package/dist/lib/api.d.ts +16 -5
- package/dist/lib/api.js +67 -25
- package/dist/lib/app-config.js +1 -0
- package/dist/lib/apps/app-config.d.ts +49 -0
- package/dist/lib/apps/app-config.js +21 -14
- package/dist/lib/apps/index.d.ts +5 -4
- package/dist/lib/apps/index.js +109 -21
- package/dist/lib/bundle.js +2 -1
- package/dist/lib/config.d.ts +1 -1
- package/dist/lib/constants.d.ts +2 -4
- package/dist/lib/constants.js +6 -4
- package/dist/lib/create/content.d.ts +5 -1
- package/dist/lib/create/content.js +8 -1
- package/dist/lib/create/function.d.ts +2 -1
- package/dist/lib/create/function.js +7 -3
- package/dist/lib/create/model.d.ts +1 -0
- package/dist/lib/create/schemas.d.ts +6 -0
- package/dist/lib/create/schemas.js +6 -0
- package/dist/lib/proxy.d.ts +1 -0
- package/dist/lib/proxy.js +29 -1
- package/dist/lib/sessions.js +4 -3
- package/dist/lib/style.js +0 -1
- package/dist/lib/swell-function-wrapper.d.ts +23 -4
- package/dist/lib/swell-function-wrapper.js +11 -4
- package/dist/lib/theme-sync.d.ts +6 -6
- package/dist/lib/theme-sync.js +49 -39
- package/dist/push-app-command.d.ts +12 -8
- package/dist/push-app-command.js +108 -29
- package/dist/remote-app-command.d.ts +1 -1
- package/dist/remote-app-command.js +4 -2
- package/dist/swell-api-command.d.ts +13 -0
- package/dist/swell-api-command.js +75 -0
- package/dist/swell-command.d.ts +1 -1
- package/dist/swell-command.js +9 -9
- package/package.json +10 -1
- package/oclif.manifest.json +0 -1895
|
@@ -174,14 +174,14 @@ export class AppConfig {
|
|
|
174
174
|
: this.fileData?.toString('utf8');
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
class AppConfigDefault extends AppConfig {
|
|
177
|
+
export class AppConfigDefault extends AppConfig {
|
|
178
178
|
hasValues = false;
|
|
179
179
|
type = ConfigType.FILE;
|
|
180
180
|
preparePostData(postData) {
|
|
181
181
|
return postData;
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
class AppConfigModel extends AppConfig {
|
|
184
|
+
export class AppConfigModel extends AppConfig {
|
|
185
185
|
hasValues = true;
|
|
186
186
|
type = ConfigType.MODEL;
|
|
187
187
|
preparePostData(postData) {
|
|
@@ -190,7 +190,7 @@ class AppConfigModel extends AppConfig {
|
|
|
190
190
|
return postData;
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
|
-
class AppConfigContent extends AppConfig {
|
|
193
|
+
export class AppConfigContent extends AppConfig {
|
|
194
194
|
hasValues = true;
|
|
195
195
|
type = ConfigType.CONTENT;
|
|
196
196
|
preparePostData(postData) {
|
|
@@ -198,7 +198,7 @@ class AppConfigContent extends AppConfig {
|
|
|
198
198
|
return postData;
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
-
class AppConfigNotification extends AppConfig {
|
|
201
|
+
export class AppConfigNotification extends AppConfig {
|
|
202
202
|
hasValues = true;
|
|
203
203
|
type = ConfigType.NOTIFICATION;
|
|
204
204
|
preparePostData(postData) {
|
|
@@ -225,35 +225,42 @@ class AppConfigNotification extends AppConfig {
|
|
|
225
225
|
return postData;
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
class AppConfigSetting extends AppConfig {
|
|
228
|
+
export class AppConfigSetting extends AppConfig {
|
|
229
229
|
hasValues = true;
|
|
230
230
|
type = ConfigType.SETTING;
|
|
231
231
|
preparePostData(postData) {
|
|
232
232
|
return postData;
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
|
-
class AppConfigWebhook extends AppConfig {
|
|
235
|
+
export class AppConfigWebhook extends AppConfig {
|
|
236
236
|
hasValues = true;
|
|
237
237
|
type = ConfigType.WEBHOOK;
|
|
238
238
|
preparePostData(postData) {
|
|
239
239
|
return postData;
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
|
-
class AppConfigFunction extends AppConfig {
|
|
242
|
+
export class AppConfigFunction extends AppConfig {
|
|
243
243
|
hasValues = true;
|
|
244
244
|
type = ConfigType.FUNCTION;
|
|
245
|
+
isRootFunction() {
|
|
246
|
+
return (this.isRootConfig('functions') &&
|
|
247
|
+
(this.filePath.endsWith('.js') || this.filePath.endsWith('.ts')));
|
|
248
|
+
}
|
|
245
249
|
async preparePostData(postData) {
|
|
246
|
-
|
|
247
|
-
(this.filePath.endsWith('.js') || this.filePath.endsWith('.ts'));
|
|
248
|
-
if (isFunction) {
|
|
250
|
+
if (this.isRootFunction()) {
|
|
249
251
|
try {
|
|
252
|
+
// get file contents and if it's empty ignore
|
|
253
|
+
const fileData = this.prepareFileData();
|
|
254
|
+
if (!fileData) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
250
257
|
const { code, config } = await bundleFunction(this.filePath);
|
|
251
258
|
if (!config) {
|
|
252
259
|
throw new IgnoringFileError('Function must export a `config` object.');
|
|
253
260
|
}
|
|
254
261
|
// Save the original file and the bundled version
|
|
255
262
|
postData.file = {
|
|
256
|
-
data:
|
|
263
|
+
data: fileData,
|
|
257
264
|
};
|
|
258
265
|
postData.build_file = {
|
|
259
266
|
content_type: 'text/javascript',
|
|
@@ -269,15 +276,15 @@ class AppConfigFunction extends AppConfig {
|
|
|
269
276
|
}
|
|
270
277
|
}
|
|
271
278
|
// Assets do not get installed but saved as plain files
|
|
272
|
-
class AppConfigAsset extends AppConfigDefault {
|
|
279
|
+
export class AppConfigAsset extends AppConfigDefault {
|
|
273
280
|
hasValues = false;
|
|
274
281
|
type = ConfigType.ASSET;
|
|
275
282
|
}
|
|
276
|
-
class AppConfigFrontend extends AppConfigDefault {
|
|
283
|
+
export class AppConfigFrontend extends AppConfigDefault {
|
|
277
284
|
hasValues = false;
|
|
278
285
|
type = ConfigType.FRONTEND;
|
|
279
286
|
}
|
|
280
|
-
class AppConfigTheme extends AppConfigDefault {
|
|
287
|
+
export class AppConfigTheme extends AppConfigDefault {
|
|
281
288
|
hasValues = false;
|
|
282
289
|
type = ConfigType.THEME;
|
|
283
290
|
preparePostData(postData) {
|
package/dist/lib/apps/index.d.ts
CHANGED
|
@@ -117,15 +117,16 @@ export declare enum ConfigInputFields {
|
|
|
117
117
|
VERSION = "version"
|
|
118
118
|
}
|
|
119
119
|
export interface FrontendProjectType {
|
|
120
|
-
buildCommand
|
|
121
|
-
configFileName: string;
|
|
122
|
-
deployPath: string;
|
|
120
|
+
buildCommand?: string;
|
|
123
121
|
devCommand: string;
|
|
124
|
-
installCommand
|
|
122
|
+
installCommand?: string;
|
|
123
|
+
mainPackage: string;
|
|
125
124
|
name: string;
|
|
126
125
|
slug: string;
|
|
127
126
|
}
|
|
128
127
|
export declare const FrontendProjectTypes: FrontendProjectType[];
|
|
128
|
+
export declare function getFrontendProjectSlugs(withNone?: boolean, withLegacy?: boolean): string[];
|
|
129
|
+
export declare function getFrontendProjectValidValues(withNone?: boolean, withLegacy?: boolean): string;
|
|
129
130
|
export declare function getAppSlugId(app: App): string | undefined;
|
|
130
131
|
export declare function getFrontendProjectType(appPath: string): FrontendProjectType | undefined;
|
|
131
132
|
export declare function getConfigTypeFromPath(path: string): ConfigType | undefined;
|
package/dist/lib/apps/index.js
CHANGED
|
@@ -46,7 +46,7 @@ const ConfigTypeBatchOrder = [
|
|
|
46
46
|
ConfigType.FRONTEND,
|
|
47
47
|
ConfigType.FILE,
|
|
48
48
|
];
|
|
49
|
-
// Configs available for
|
|
49
|
+
// Configs available for admin/integration app types
|
|
50
50
|
const StandardConfigTypes = [
|
|
51
51
|
'MODEL',
|
|
52
52
|
'CONTENT',
|
|
@@ -56,7 +56,6 @@ const StandardConfigTypes = [
|
|
|
56
56
|
'NOTIFICATION',
|
|
57
57
|
'SETTING',
|
|
58
58
|
'WEBHOOK',
|
|
59
|
-
'THEME',
|
|
60
59
|
];
|
|
61
60
|
export const StorefrontConfigTypes = [
|
|
62
61
|
'FRONTEND',
|
|
@@ -94,39 +93,128 @@ export var ConfigInputFields;
|
|
|
94
93
|
ConfigInputFields["VALUES"] = "values";
|
|
95
94
|
ConfigInputFields["VERSION"] = "version";
|
|
96
95
|
})(ConfigInputFields || (ConfigInputFields = {}));
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
configFileName: 'next.config',
|
|
101
|
-
deployPath: '.vercel/output/static',
|
|
102
|
-
devCommand: 'npx next dev --port ${PORT}',
|
|
103
|
-
installCommand: 'npx create-next-app@latest frontend --typescript --use-npm --src-dir --app --eslint --import-alias "@/*" --tailwind',
|
|
104
|
-
name: 'Next.js',
|
|
105
|
-
slug: 'nextjs',
|
|
106
|
-
},
|
|
96
|
+
// Legacy apps (pre-workspace) - Astro only (Proxima, Sunrise)
|
|
97
|
+
// Uses direct commands without workspace prefix
|
|
98
|
+
const LegacyFrontendProjectTypes = [
|
|
107
99
|
{
|
|
108
100
|
buildCommand: 'npx astro build',
|
|
109
|
-
configFileName: 'astro.config',
|
|
110
|
-
deployPath: 'dist',
|
|
111
101
|
devCommand: 'npx astro dev --port ${PORT}',
|
|
112
|
-
|
|
102
|
+
mainPackage: 'astro',
|
|
103
|
+
name: 'Astro',
|
|
104
|
+
slug: 'astro',
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
// Modern apps (workspace-based) - All frameworks
|
|
108
|
+
export const FrontendProjectTypes = [
|
|
109
|
+
{
|
|
110
|
+
buildCommand: 'npm exec --workspace=frontend -- astro build',
|
|
111
|
+
devCommand: 'npm exec --workspace=frontend -- astro dev --port ${PORT}',
|
|
112
|
+
installCommand: 'npm create cloudflare@latest -- frontend --framework=astro --deploy=false --git=false -- --no-git --yes --skip-houston --typescript strict',
|
|
113
|
+
mainPackage: 'astro',
|
|
113
114
|
name: 'Astro',
|
|
114
115
|
slug: 'astro',
|
|
115
116
|
},
|
|
117
|
+
{
|
|
118
|
+
buildCommand: 'npm exec --workspace=frontend -- ng build',
|
|
119
|
+
devCommand: 'npm exec --workspace=frontend -- ng serve --port ${PORT}',
|
|
120
|
+
installCommand: 'npm create cloudflare@latest -- frontend --framework=angular --deploy=false --git=false -- --style=sass --zoneless --ai-config=none',
|
|
121
|
+
mainPackage: '@angular/core',
|
|
122
|
+
name: 'Angular',
|
|
123
|
+
slug: 'angular',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
devCommand: 'npm exec --workspace=frontend -- wrangler dev --port ${PORT}',
|
|
127
|
+
installCommand: 'npm create cloudflare@latest -- frontend --framework=hono --deploy=false --git=false',
|
|
128
|
+
mainPackage: 'hono',
|
|
129
|
+
name: 'Hono',
|
|
130
|
+
slug: 'hono',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
buildCommand: 'npm exec --workspace=frontend -- nuxt build',
|
|
134
|
+
devCommand: 'npm exec --workspace=frontend -- nuxt dev --port ${PORT}',
|
|
135
|
+
installCommand: 'npm create cloudflare@latest -- frontend --framework=nuxt --deploy=false --git=false -- --no-modules -f',
|
|
136
|
+
mainPackage: 'nuxt',
|
|
137
|
+
name: 'Nuxt',
|
|
138
|
+
slug: 'nuxt',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
buildCommand: 'npm exec --workspace=frontend -- opennextjs-cloudflare build',
|
|
142
|
+
// devCommand: 'npm exec --workspace=frontend -- opennextjs-cloudflare build && npm exec --workspace=frontend -- opennextjs-cloudflare preview --port=${PORT}',
|
|
143
|
+
devCommand: 'npm exec --workspace=frontend -- next dev --turbopack --port ${PORT}',
|
|
144
|
+
installCommand: 'npm create cloudflare@latest -- frontend --framework=next --deploy=false --git=false -- --typescript --use-npm --src-dir --app --eslint --import-alias "@/*" --tailwind --turbopack',
|
|
145
|
+
mainPackage: 'next',
|
|
146
|
+
name: 'Next.js',
|
|
147
|
+
slug: 'nextjs',
|
|
148
|
+
},
|
|
116
149
|
];
|
|
117
|
-
|
|
150
|
+
export function getFrontendProjectSlugs(withNone = true, withLegacy = true) {
|
|
151
|
+
const types = withLegacy
|
|
152
|
+
? FrontendProjectTypes
|
|
153
|
+
: FrontendProjectTypes.filter((projectType) => projectType.installCommand);
|
|
154
|
+
const slugs = types.map((projectType) => projectType.slug);
|
|
155
|
+
if (withNone) {
|
|
156
|
+
slugs.push('none');
|
|
157
|
+
}
|
|
158
|
+
return slugs;
|
|
159
|
+
}
|
|
160
|
+
export function getFrontendProjectValidValues(withNone = true, withLegacy = true) {
|
|
161
|
+
return getFrontendProjectSlugs(withNone, withLegacy).join(', ');
|
|
162
|
+
}
|
|
118
163
|
export function getAppSlugId(app) {
|
|
119
164
|
return toAppId(app.private_id) || app.public_id || app.id;
|
|
120
165
|
}
|
|
166
|
+
function hasWorkspaceStructure(appPath) {
|
|
167
|
+
// Check if root package.json has workspaces field including 'frontend'
|
|
168
|
+
const rootPkgPath = path.join(appPath, 'package.json');
|
|
169
|
+
if (!filePathExists(rootPkgPath)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const content = fs.readFileSync(rootPkgPath, 'utf8');
|
|
174
|
+
const pkg = JSON.parse(content);
|
|
175
|
+
return Array.isArray(pkg.workspaces) && pkg.workspaces.includes('frontend');
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
121
181
|
export function getFrontendProjectType(appPath) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
182
|
+
// Detect workspace structure and select appropriate config
|
|
183
|
+
const hasWorkspace = hasWorkspaceStructure(appPath);
|
|
184
|
+
const projectTypes = hasWorkspace
|
|
185
|
+
? FrontendProjectTypes
|
|
186
|
+
: LegacyFrontendProjectTypes;
|
|
187
|
+
// Try frontend/package.json first (new workspace structure), then root package.json (old structure)
|
|
188
|
+
const pkgPaths = [
|
|
189
|
+
path.join(appPath, 'frontend', 'package.json'),
|
|
190
|
+
path.join(appPath, 'package.json'),
|
|
191
|
+
];
|
|
192
|
+
for (const pkgPath of pkgPaths) {
|
|
193
|
+
if (!filePathExists(pkgPath)) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const content = fs.readFileSync(pkgPath, 'utf8');
|
|
198
|
+
const pkg = JSON.parse(content);
|
|
199
|
+
for (const projectType of projectTypes) {
|
|
200
|
+
if (pkg.dependencies?.[projectType.mainPackage] ||
|
|
201
|
+
pkg.devDependencies?.[projectType.mainPackage]) {
|
|
202
|
+
// Create a copy to avoid mutating the original
|
|
203
|
+
const detectedType = { ...projectType };
|
|
204
|
+
// If buildCommand not explicitly set in framework definition, detect it
|
|
205
|
+
detectedType.buildCommand ||=
|
|
206
|
+
// Check if package.json has a "build" script, if not set to empty string (no build needed)
|
|
207
|
+
pkg.scripts?.build ? 'npm run build' : '';
|
|
208
|
+
return detectedType;
|
|
209
|
+
}
|
|
127
210
|
}
|
|
128
211
|
}
|
|
212
|
+
catch {
|
|
213
|
+
// Ignore JSON parse errors, try next path
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
129
216
|
}
|
|
217
|
+
return undefined;
|
|
130
218
|
}
|
|
131
219
|
export function getConfigTypeFromPath(path) {
|
|
132
220
|
for (const type in ConfigPaths) {
|
package/dist/lib/bundle.js
CHANGED
|
@@ -11,7 +11,8 @@ export async function bundleFunction(filePath) {
|
|
|
11
11
|
metafile: true,
|
|
12
12
|
platform: 'node',
|
|
13
13
|
target: ['chrome58'],
|
|
14
|
-
write: false,
|
|
14
|
+
write: false,
|
|
15
|
+
logLevel: 'silent', // Do not output compile errors
|
|
15
16
|
});
|
|
16
17
|
const { metafile: { inputs }, outputFiles: [{ text: origCode }], } = buildResult;
|
|
17
18
|
// TODO: make a separate method to get dependencies for watch command
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ declare function getAll(): any;
|
|
|
8
8
|
declare function getDefaultStore(): string;
|
|
9
9
|
declare function setDefaultStore(storeId: string): void;
|
|
10
10
|
declare function getDefaultStorefront(appPath: string): {
|
|
11
|
-
id: string;
|
|
12
11
|
env?: string;
|
|
12
|
+
id: string;
|
|
13
13
|
};
|
|
14
14
|
declare function setDefaultStorefront(appPath: string, storefrontId: string, env?: string): void;
|
|
15
15
|
declare function getSessionId(storeId: string): any;
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export declare const API_BASE_URL: any;
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const APP_PAGES_HOST: any;
|
|
5
|
-
export declare const STOREFRONT_FRONTEND_HOST: any;
|
|
2
|
+
export declare const LOCAL_PROXY_PROVIDER: any;
|
|
3
|
+
export declare const SCHEMAS_BASE_URL: any;
|
|
6
4
|
export declare function getAdminApiBaseUrl(storeId: string): any;
|
|
7
5
|
export declare function getLoginHost(storeId?: string): any;
|
|
8
6
|
export declare function getAppFrontendHost(storeId: string, installedAppId: string): any;
|
package/dist/lib/constants.js
CHANGED
|
@@ -4,15 +4,17 @@ import { env } from './config.js';
|
|
|
4
4
|
// url for backend api calls
|
|
5
5
|
export const API_BASE_URL = env.get('API_BASE_URL') || defaultEnv.API_BASE_URL;
|
|
6
6
|
// url for admin api calls
|
|
7
|
-
|
|
7
|
+
const ADMIN_API_BASE_URL = env.get('ADMIN_API_BASE_URL') || defaultEnv.ADMIN_API_BASE_URL;
|
|
8
8
|
// url host for admin login
|
|
9
|
-
|
|
9
|
+
const LOGIN_HOST = env.get('LOGIN_HOST') || defaultEnv.LOGIN_HOST;
|
|
10
10
|
// url host for app frontend
|
|
11
|
-
|
|
11
|
+
const APP_PAGES_HOST = env.get('APP_PAGES_HOST') || defaultEnv.APP_PAGES_HOST;
|
|
12
12
|
// url host for storefront app frontend
|
|
13
|
-
|
|
13
|
+
const STOREFRONT_FRONTEND_HOST = env.get('STOREFRONT_FRONTEND_HOST') ||
|
|
14
14
|
env.get('STOREFRONT_PAGES_HOST') || // Deprecated
|
|
15
15
|
defaultEnv.STOREFRONT_FRONTEND_HOST;
|
|
16
|
+
export const LOCAL_PROXY_PROVIDER = env.get('LOCAL_PROXY_PROVIDER') || defaultEnv.LOCAL_PROXY_PROVIDER;
|
|
17
|
+
export const SCHEMAS_BASE_URL = env.get('SCHEMAS_BASE_URL') || defaultEnv.SCHEMAS_BASE_URL;
|
|
16
18
|
// helpers to get constants with replacements
|
|
17
19
|
export function getAdminApiBaseUrl(storeId) {
|
|
18
20
|
return ADMIN_API_BASE_URL.replace('${STORE_ID}', storeId);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
interface CreateContentFileBody {
|
|
2
|
+
$schema: string;
|
|
2
3
|
collection: string;
|
|
3
4
|
description?: string;
|
|
4
5
|
fields?: ContentFieldProps[];
|
|
@@ -18,6 +19,9 @@ interface ContentFieldProps {
|
|
|
18
19
|
label: string;
|
|
19
20
|
type?: ContentType;
|
|
20
21
|
}
|
|
22
|
+
declare const validateViews: (values: string[], onError: (msg: string, options: {
|
|
23
|
+
exit: number;
|
|
24
|
+
}) => never) => void;
|
|
21
25
|
declare const parseViews: (views: string[]) => ContentViewProps[];
|
|
22
26
|
declare const parseFields: (fields: string[]) => ContentFieldProps[];
|
|
23
|
-
export { CreateContentFileBody, parseFields, parseViews };
|
|
27
|
+
export { CreateContentFileBody, parseFields, parseViews, validateViews };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { titleize } from 'inflection';
|
|
2
|
+
const validContentViewValues = ['list', 'edit', 'new'];
|
|
3
|
+
const validateViews = (values, onError) => {
|
|
4
|
+
const invalid = values.filter((v) => !validContentViewValues.includes(v));
|
|
5
|
+
if (invalid.length > 0) {
|
|
6
|
+
onError(`Invalid view(s): ${invalid.join(', ')}\n\nValid views: ${validContentViewValues.join(', ')}\n\nExample: swell create content visitors -v list,edit,new -y`, { exit: 1 });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
2
9
|
const parseViews = (views) => {
|
|
3
10
|
if (views.length === 0) {
|
|
4
11
|
return [];
|
|
@@ -37,4 +44,4 @@ const parseFields = (fields) => {
|
|
|
37
44
|
}
|
|
38
45
|
return fieldResponse;
|
|
39
46
|
};
|
|
40
|
-
export { parseFields, parseViews };
|
|
47
|
+
export { parseFields, parseViews, validateViews };
|
|
@@ -7,11 +7,12 @@ interface CreateFunctionArgs {
|
|
|
7
7
|
interface WriteFunctionFileParams {
|
|
8
8
|
description: string;
|
|
9
9
|
events: string;
|
|
10
|
+
extension?: string;
|
|
10
11
|
functionName: string;
|
|
11
12
|
language: FunctionLanguage;
|
|
12
13
|
route: string;
|
|
13
14
|
schedule: string;
|
|
14
15
|
trigger: FunctionType;
|
|
15
16
|
}
|
|
16
|
-
declare const getFunctionTemplate: ({ description, events, language, route, schedule, trigger, }: WriteFunctionFileParams) => string;
|
|
17
|
+
declare const getFunctionTemplate: ({ description, events, extension, language, route, schedule, trigger, }: WriteFunctionFileParams) => string;
|
|
17
18
|
export { CreateFunctionArgs, FunctionLanguage, FunctionType, WriteFunctionFileParams, getFunctionTemplate, };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const getFunctionTemplate = ({ description, events, language, route, schedule, trigger, }) => {
|
|
1
|
+
const getFunctionTemplate = ({ description, events, extension, language, route, schedule, trigger, }) => {
|
|
2
2
|
let typeAppend = ``;
|
|
3
3
|
if (trigger === 'model') {
|
|
4
4
|
const eventsList = events
|
|
@@ -24,12 +24,16 @@ const getFunctionTemplate = ({ description, events, language, route, schedule, t
|
|
|
24
24
|
schedule: '${schedule}',
|
|
25
25
|
},`;
|
|
26
26
|
}
|
|
27
|
+
let extensionAppend = '';
|
|
28
|
+
if (extension) {
|
|
29
|
+
extensionAppend = `extension: '${extension}',\n `;
|
|
30
|
+
}
|
|
27
31
|
return `export const config${language === 'ts' ? ': SwellConfig' : ''} = {
|
|
28
|
-
description: '${description}'${typeAppend}
|
|
32
|
+
${extensionAppend}description: '${description}'${typeAppend}
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
export default async function (req${language === 'ts' ? ': SwellRequest' : ''}) {
|
|
32
|
-
const { swell, store,
|
|
36
|
+
const { swell, store, data } = req;
|
|
33
37
|
}
|
|
34
38
|
`;
|
|
35
39
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SCHEMAS: {
|
|
2
|
+
readonly CONTENT: "https://json.swell.store/content.json";
|
|
3
|
+
readonly MODEL: "https://json.swell.store/model.json";
|
|
4
|
+
readonly NOTIFICATION: "https://json.swell.store/notification.json";
|
|
5
|
+
readonly SETTING: "https://json.swell.store/setting.json";
|
|
6
|
+
};
|
package/dist/lib/proxy.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getProxyUrl(port: number): Promise<string>;
|
package/dist/lib/proxy.js
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import localtunnel from 'localtunnel';
|
|
2
|
+
import ngrok from 'ngrok';
|
|
3
|
+
import { LOCAL_PROXY_PROVIDER } from './constants.js';
|
|
4
|
+
export async function getProxyUrl(port) {
|
|
5
|
+
const provider = LOCAL_PROXY_PROVIDER || 'localtunnel';
|
|
6
|
+
try {
|
|
7
|
+
switch (provider) {
|
|
8
|
+
case 'local': {
|
|
9
|
+
return `http://localhost:${port}`;
|
|
10
|
+
}
|
|
11
|
+
case 'ngrok': {
|
|
12
|
+
return await ngrok.connect({
|
|
13
|
+
addr: port,
|
|
14
|
+
region: 'us', // TODO: make it configurable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line unicorn/no-useless-switch-case
|
|
18
|
+
case 'localtunnel':
|
|
19
|
+
default: {
|
|
20
|
+
const tunnel = await localtunnel({ port });
|
|
21
|
+
return tunnel.url;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.log(error);
|
|
27
|
+
throw new Error(`Unable to start tunnel on port ${port} (${provider}): ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/dist/lib/sessions.js
CHANGED
|
@@ -2,6 +2,7 @@ import { ux } from '@oclif/core';
|
|
|
2
2
|
import * as http from 'node:http';
|
|
3
3
|
import open from 'open';
|
|
4
4
|
import { getLoginHost } from './constants.js';
|
|
5
|
+
import { getProxyUrl } from './proxy.js';
|
|
5
6
|
import style from './style.js';
|
|
6
7
|
/**
|
|
7
8
|
* Get the session id for the passed in store. If the session is not found,
|
|
@@ -90,10 +91,10 @@ function serverForLogin({ onPost, onStart, storeId, }) {
|
|
|
90
91
|
res.end('Not Found');
|
|
91
92
|
}
|
|
92
93
|
});
|
|
93
|
-
server.listen(0,
|
|
94
|
+
server.listen(0, async () => {
|
|
94
95
|
const serverAddr = server.address();
|
|
95
|
-
|
|
96
|
-
const localServerUrl = Buffer.from(
|
|
96
|
+
const proxyUrl = await getProxyUrl(serverAddr.port);
|
|
97
|
+
const localServerUrl = Buffer.from(proxyUrl).toString('base64');
|
|
97
98
|
const loginUrl = `${getLoginHost(storeId)}/admin?cli=${localServerUrl}`;
|
|
98
99
|
onStart(loginUrl);
|
|
99
100
|
});
|
package/dist/lib/style.js
CHANGED
|
@@ -48,10 +48,28 @@ declare function executeModuleHandler(req: SwellRequest, context: Event): Promis
|
|
|
48
48
|
* @returns {boolean}
|
|
49
49
|
*/
|
|
50
50
|
declare function isOrdinaryObject(val: any): boolean;
|
|
51
|
-
declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
declare namespace originalConsole {
|
|
52
|
+
let log: {
|
|
53
|
+
(...data: any[]): void;
|
|
54
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
55
|
+
};
|
|
56
|
+
let info: {
|
|
57
|
+
(...data: any[]): void;
|
|
58
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
59
|
+
};
|
|
60
|
+
let debug: {
|
|
61
|
+
(...data: any[]): void;
|
|
62
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
63
|
+
};
|
|
64
|
+
let warn: {
|
|
65
|
+
(...data: any[]): void;
|
|
66
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
67
|
+
};
|
|
68
|
+
let error: {
|
|
69
|
+
(...data: any[]): void;
|
|
70
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
55
73
|
/**
|
|
56
74
|
* Class representing a Swell request.
|
|
57
75
|
*/
|
|
@@ -68,6 +86,7 @@ declare class SwellRequest {
|
|
|
68
86
|
logParams: any;
|
|
69
87
|
apiHost: any;
|
|
70
88
|
id: any;
|
|
89
|
+
isLocalDev: boolean;
|
|
71
90
|
swell: SwellAPI;
|
|
72
91
|
body: {};
|
|
73
92
|
query: {};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
2
|
+
const originalConsole = {
|
|
3
|
+
log: console.log,
|
|
4
|
+
info: console.info,
|
|
5
|
+
debug: console.debug,
|
|
6
|
+
warn: console.warn,
|
|
7
|
+
error: console.error,
|
|
8
|
+
};
|
|
3
9
|
addEventListener('fetch', (event) => {
|
|
4
10
|
event.respondWith(request(event.request, event.env, event));
|
|
5
11
|
});
|
|
@@ -93,6 +99,8 @@ class SwellRequest {
|
|
|
93
99
|
this.logParams = this.parseJson(req.headers.get('Swell-Request-Log'));
|
|
94
100
|
this.apiHost = req.headers.get('Swell-API-Host') || 'https://api.schema.io';
|
|
95
101
|
this.id = req.headers.get('Swell-Request-ID') || this.logParams?.req_id;
|
|
102
|
+
// Check if the request is from a local development environment
|
|
103
|
+
this.isLocalDev = req.headers.get('Swell-Local-Dev') === 'true';
|
|
96
104
|
// Swell client
|
|
97
105
|
this.swell = new SwellAPI(this, context);
|
|
98
106
|
// URL of the original request
|
|
@@ -142,7 +150,7 @@ class SwellRequest {
|
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
log(level, ...line) {
|
|
145
|
-
|
|
153
|
+
originalConsole[level]?.(...line);
|
|
146
154
|
this._logs.push({
|
|
147
155
|
date: Date.now(),
|
|
148
156
|
line: line.map((l) => (l instanceof Error ? l.stack : JSON.stringify(l))),
|
|
@@ -150,7 +158,7 @@ class SwellRequest {
|
|
|
150
158
|
});
|
|
151
159
|
}
|
|
152
160
|
getIngestableLogs(response) {
|
|
153
|
-
if (!this.logParams) {
|
|
161
|
+
if (!this.logParams || this.isLocalDev) {
|
|
154
162
|
return;
|
|
155
163
|
}
|
|
156
164
|
if (this.logParams.$start) {
|
|
@@ -384,4 +392,3 @@ function isOrdinaryObject(val) {
|
|
|
384
392
|
val !== null &&
|
|
385
393
|
Object.getPrototypeOf(val) === Object.prototype);
|
|
386
394
|
}
|
|
387
|
-
;
|
package/dist/lib/theme-sync.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ interface ThemeSyncOptions {
|
|
|
3
3
|
targetUrl: string;
|
|
4
4
|
}
|
|
5
5
|
export declare class ThemeSync {
|
|
6
|
-
private readonly
|
|
6
|
+
private readonly options;
|
|
7
7
|
private readonly proxy;
|
|
8
|
+
private readonly server;
|
|
8
9
|
private readonly wss;
|
|
9
|
-
private readonly options;
|
|
10
|
-
private selectPort;
|
|
11
10
|
constructor(options: ThemeSyncOptions);
|
|
12
|
-
start(): Promise<number>;
|
|
13
11
|
reload(): void;
|
|
14
|
-
|
|
12
|
+
start(): Promise<number>;
|
|
15
13
|
private decodeRequestBody;
|
|
16
|
-
private shouldInjectScript;
|
|
17
14
|
private injectScript;
|
|
15
|
+
private parseRequestBody;
|
|
16
|
+
private selectPort;
|
|
17
|
+
private shouldInjectScript;
|
|
18
18
|
}
|
|
19
19
|
export {};
|