@stackbit/dev 0.0.48-alpha.1 → 0.0.51
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/dev.d.ts +0 -1
- package/dist/dev.js +0 -3
- package/dist/dev.js.map +1 -1
- package/dist/runner/index.d.ts +18 -49
- package/dist/runner/index.js +119 -103
- package/dist/runner/index.js.map +1 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes.js +3 -25
- package/dist/server/routes.js.map +1 -1
- package/dist/services/annotation-errors.d.ts +1 -1
- package/dist/services/annotation-errors.js +4 -5
- package/dist/services/annotation-errors.js.map +1 -1
- package/dist/services/logger.d.ts +0 -7
- package/dist/services/logger.js +1 -4
- package/dist/services/logger.js.map +1 -1
- package/package.json +5 -5
- package/src/dev.ts +1 -5
- package/src/runner/index.ts +129 -147
- package/src/server/index.ts +1 -2
- package/src/server/routes.ts +3 -31
- package/src/services/annotation-errors.ts +4 -5
- package/src/services/logger.ts +2 -12
- package/dist/types/api-methods.d.ts +0 -232
- package/dist/types/api-methods.js +0 -3
- package/dist/types/api-methods.js.map +0 -1
- package/src/types/api-methods.ts +0 -282
|
@@ -3,11 +3,4 @@ declare const logger: winston.Logger;
|
|
|
3
3
|
export declare const createLogger: ({ label }: {
|
|
4
4
|
label: string;
|
|
5
5
|
}) => winston.Logger;
|
|
6
|
-
declare module "winston" {
|
|
7
|
-
interface Logger {
|
|
8
|
-
createLogger: ({ label }: {
|
|
9
|
-
label: string;
|
|
10
|
-
}) => winston.Logger;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
6
|
export default logger;
|
package/dist/services/logger.js
CHANGED
|
@@ -24,15 +24,12 @@ const createLogger = ({ label }) => {
|
|
|
24
24
|
message: true
|
|
25
25
|
}));
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
return winston_1.default.createLogger({
|
|
28
28
|
level: config_1.default.logLevel,
|
|
29
29
|
format: winston_1.default.format.combine(...formats),
|
|
30
30
|
transports: transports
|
|
31
31
|
});
|
|
32
|
-
logger.createLogger = exports.createLogger;
|
|
33
|
-
return logger;
|
|
34
32
|
};
|
|
35
33
|
exports.createLogger = createLogger;
|
|
36
|
-
logger.createLogger = exports.createLogger;
|
|
37
34
|
exports.default = logger;
|
|
38
35
|
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,uDAA+B;AAE/B,MAAM,cAAc,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,iBAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAE5E,MAAM,UAAU,GAAG;IACf,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC;QAC3B,MAAM,EAAE,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC;KACpD,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;IAChC,KAAK,EAAE,gBAAM,CAAC,QAAQ;IACtB,UAAU,EAAE,UAAU;CACzB,CAAC,CAAC;AAEI,MAAM,YAAY,GAAG,CAAC,EAAE,KAAK,EAAqB,
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA8B;AAC9B,uDAA+B;AAE/B,MAAM,cAAc,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,iBAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAE5E,MAAM,UAAU,GAAG;IACf,IAAI,iBAAO,CAAC,UAAU,CAAC,OAAO,CAAC;QAC3B,MAAM,EAAE,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC;KACpD,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;IAChC,KAAK,EAAE,gBAAM,CAAC,QAAQ;IACtB,UAAU,EAAE,UAAU;CACzB,CAAC,CAAC;AAEI,MAAM,YAAY,GAAG,CAAC,EAAE,KAAK,EAAqB,EAAE,EAAE;IACzD,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;IACvC,IAAI,KAAK,EAAE;QACP,OAAO,CAAC,IAAI,CACR,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC;YACjB,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,IAAI;SAChB,CAAC,CACL,CAAC;KACL;IACD,OAAO,iBAAO,CAAC,YAAY,CAAC;QACxB,KAAK,EAAE,gBAAM,CAAC,QAAQ;QACtB,MAAM,EAAE,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;QAC1C,UAAU,EAAE,UAAU;KACzB,CAAC,CAAC;AACP,CAAC,CAAC;AAfW,QAAA,YAAY,gBAevB;AAEF,kBAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackbit/dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"description": "stackbit-dev",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"author": "Stackbit Inc.",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@stackbit/cms-core": "^0.0.
|
|
26
|
-
"@stackbit/dev-common": "^0.0.
|
|
27
|
-
"@stackbit/sdk": "^0.2.
|
|
25
|
+
"@stackbit/cms-core": "^0.0.17",
|
|
26
|
+
"@stackbit/dev-common": "^0.0.47",
|
|
27
|
+
"@stackbit/sdk": "^0.2.35",
|
|
28
28
|
"axios": "^0.25.0",
|
|
29
29
|
"chalk": "^4.1.0",
|
|
30
30
|
"chokidar": "^3.5.3",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"ts-jest": "^27.1.5",
|
|
59
59
|
"typescript": "^4.5.4"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "63a6adcd673968736dad88603e329f80412807d2"
|
|
62
62
|
}
|
package/src/dev.ts
CHANGED
|
@@ -17,7 +17,6 @@ interface DevOptions {
|
|
|
17
17
|
runnableDir?: string;
|
|
18
18
|
autoOpen?: boolean;
|
|
19
19
|
cmsType?: string;
|
|
20
|
-
csiEnabled?: boolean;
|
|
21
20
|
contentfulAccessToken?: string;
|
|
22
21
|
contentfulSpaceIds?: [string];
|
|
23
22
|
contentfulPreviewTokens?: [string];
|
|
@@ -49,7 +48,7 @@ export async function start(options: DevOptions) {
|
|
|
49
48
|
|
|
50
49
|
if (options.contentfulSpaceIds) {
|
|
51
50
|
localDetails.spaceIds = options.contentfulSpaceIds;
|
|
52
|
-
}
|
|
51
|
+
}
|
|
53
52
|
if (options.sanityProjectId) {
|
|
54
53
|
localDetails.projectId = options.sanityProjectId;
|
|
55
54
|
}
|
|
@@ -59,9 +58,6 @@ export async function start(options: DevOptions) {
|
|
|
59
58
|
apiKey: options.cloudinaryApiKey
|
|
60
59
|
};
|
|
61
60
|
}
|
|
62
|
-
if (process.env.CSI_ENABLED) {
|
|
63
|
-
options.csiEnabled = true;
|
|
64
|
-
}
|
|
65
61
|
|
|
66
62
|
logger.debug('Local details', { localDetails });
|
|
67
63
|
const studioUrl = `${config.appUrl}/local/${Buffer.from(JSON.stringify(localDetails)).toString('base64')}`;
|
package/src/runner/index.ts
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
3
|
+
import ssg from './ssg';
|
|
4
|
+
import Editor from '@stackbit/dev-common/dist/runner/editor';
|
|
5
|
+
import GitCMS from '@stackbit/dev-common/dist/cms/git/git';
|
|
6
|
+
import { Contentful as ContentfulCMS } from '@stackbit/dev-common/dist/cms/contentful/contentful';
|
|
7
|
+
import SanityCMS from '@stackbit/dev-common/dist/cms/sanity/sanity';
|
|
8
|
+
import Worker from '@stackbit/dev-common/dist/utils/worker';
|
|
9
|
+
import { StackbitYaml } from '@stackbit/dev-common/dist/services/stackbit-yaml';
|
|
10
|
+
import socketService from '@stackbit/dev-common/dist/services/socket-service';
|
|
6
11
|
|
|
7
12
|
import { watchDir } from '../services/file-watcher';
|
|
8
13
|
import logger from '../services/logger';
|
|
9
14
|
import consts from '../consts';
|
|
10
|
-
import ssg from './ssg';
|
|
11
15
|
import { logAnnotationErrors } from '../services/annotation-errors';
|
|
12
|
-
import {
|
|
13
|
-
APIMethodCreateDocument,
|
|
14
|
-
APIMethodCreatePreset,
|
|
15
|
-
APIMethodDeleteDocument,
|
|
16
|
-
APIMethodDeletePreset,
|
|
17
|
-
APIMethodDuplicateDocument,
|
|
18
|
-
APIMethodGetAssets,
|
|
19
|
-
APIMethodUpdateDocument,
|
|
20
|
-
APIMethodUploadAssets,
|
|
21
|
-
APIMethodValidateDocuments,
|
|
22
|
-
APIMethodPublishDocuments,
|
|
23
|
-
APIMethodCreateAndLinkDocument,
|
|
24
|
-
APIMethodUploadAndLinkAsset
|
|
25
|
-
} from '../types/api-methods';
|
|
26
16
|
|
|
27
17
|
interface RunnerOptions {
|
|
28
18
|
rootDir: string;
|
|
29
19
|
runnableDir?: string;
|
|
30
20
|
cmsType?: string;
|
|
31
|
-
csiEnabled?: boolean;
|
|
32
21
|
contentfulAccessToken?: string;
|
|
33
22
|
contentfulSpaceIds?: [string];
|
|
34
23
|
contentfulPreviewTokens?: [string];
|
|
@@ -39,90 +28,131 @@ interface RunnerOptions {
|
|
|
39
28
|
sanityStudioUrl?: string;
|
|
40
29
|
}
|
|
41
30
|
export default class Runner {
|
|
42
|
-
private
|
|
43
|
-
private
|
|
44
|
-
private
|
|
45
|
-
private
|
|
46
|
-
private
|
|
47
|
-
private readonly appDir: string;
|
|
31
|
+
private editor: any;
|
|
32
|
+
private cmsType?: string;
|
|
33
|
+
private cms: any;
|
|
34
|
+
private stackbitYaml: any;
|
|
35
|
+
private workers: any;
|
|
48
36
|
private watcher: any;
|
|
49
37
|
private ssg: any;
|
|
50
38
|
|
|
39
|
+
private readonly options: RunnerOptions;
|
|
40
|
+
private rootDir: string;
|
|
41
|
+
private appDir?: string;
|
|
42
|
+
|
|
51
43
|
constructor(options: RunnerOptions) {
|
|
44
|
+
this.options = options;
|
|
52
45
|
this.rootDir = options.rootDir;
|
|
53
46
|
this.appDir = options.runnableDir ? path.join(this.rootDir, options.runnableDir) : this.rootDir;
|
|
47
|
+
this.cmsType = options.cmsType;
|
|
54
48
|
|
|
55
49
|
this.workers = {
|
|
56
50
|
gitApp: new Worker()
|
|
57
51
|
};
|
|
52
|
+
}
|
|
58
53
|
|
|
54
|
+
async install() {
|
|
59
55
|
this.stackbitYaml = new StackbitYaml({
|
|
60
56
|
repoDir: this.rootDir,
|
|
61
57
|
appDir: this.appDir,
|
|
62
|
-
logger
|
|
58
|
+
logger,
|
|
63
59
|
userLogger: logger,
|
|
64
60
|
envName: 'local' //TODO
|
|
65
61
|
});
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
workers: this.workers,
|
|
72
|
-
rootDir: this.rootDir,
|
|
73
|
-
projectDir: this.rootDir,
|
|
74
|
-
appDir: this.appDir,
|
|
75
|
-
logger: logger,
|
|
76
|
-
userLogger: logger,
|
|
77
|
-
localDev: true,
|
|
78
|
-
contentfulAccessToken: options.contentfulAccessToken,
|
|
79
|
-
contentfulSpaces: options.contentfulSpaceIds?.map((spaceId, i) => ({
|
|
80
|
-
spaceId,
|
|
81
|
-
previewToken: options.contentfulPreviewTokens?.[i]!
|
|
82
|
-
})),
|
|
83
|
-
sanityProject: {
|
|
84
|
-
projectId: options.sanityProjectId!,
|
|
85
|
-
token: options.sanityToken!,
|
|
86
|
-
studioPath: options.sanityStudioPath!,
|
|
87
|
-
dataset: options.sanityDataset!,
|
|
88
|
-
projectUrl: options.sanityStudioUrl!
|
|
89
|
-
},
|
|
90
|
-
assetIdPrefix: consts.ASSET_ID_PREFIX,
|
|
91
|
-
staticAssetsFilePath: consts.STATIC_ASSETS_FILE_PATH,
|
|
92
|
-
staticAssetsPublicPath: consts.STATIC_ASSETS_PUBLIC_PATH,
|
|
93
|
-
staticThemeAssetsFilePath: consts.STATIC_THEME_ASSETS_FILE_PATH,
|
|
94
|
-
staticThemeAssetsPublicPath: consts.STATIC_THEME_ASSETS_PUBLIC_PATH,
|
|
95
|
-
defaultContentTypeExtensions: consts.DEFAULT_CONTENT_TYPE_EXTENSIONS
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
this.editor = new Editor({
|
|
99
|
-
contentStoreAdapter: this.contentStoreAdapter,
|
|
100
|
-
stackbitYaml: this.stackbitYaml,
|
|
101
|
-
logger: logger,
|
|
62
|
+
await this.stackbitYaml.load();
|
|
63
|
+
this.cms = this.createCms();
|
|
64
|
+
await this.cms.run();
|
|
65
|
+
this.editor = new Editor(null, this.cms, this.stackbitYaml, {
|
|
66
|
+
logger,
|
|
102
67
|
userLogger: logger,
|
|
103
68
|
stackbitUrlPathField: consts.STACKBIT_URL_PATH_FIELD
|
|
104
69
|
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async install() {
|
|
108
|
-
await this.stackbitYaml.load();
|
|
109
|
-
|
|
110
|
-
await this.contentStoreAdapter.init();
|
|
111
|
-
|
|
112
70
|
this.watcher = watchDir(this.rootDir, (filePaths) => {
|
|
113
71
|
logger.debug(`File change detected: ${filePaths}`);
|
|
114
|
-
this.handleFileChanges(filePaths)
|
|
72
|
+
this.handleFileChanges(filePaths).catch((err) => {
|
|
73
|
+
logger.debug('Handle file change error', { err, filePaths });
|
|
74
|
+
logger.error('Error handling file changes: ' + filePaths.join(', '));
|
|
75
|
+
});
|
|
115
76
|
});
|
|
116
77
|
this.ssg = _.assign({}, ssg, this.stackbitYaml.internalStackbitRunnerOptions);
|
|
117
78
|
}
|
|
118
79
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
80
|
+
createCms() {
|
|
81
|
+
let result;
|
|
82
|
+
if (this.cmsType === 'contentful') {
|
|
83
|
+
result = new ContentfulCMS({
|
|
84
|
+
accessToken: this.options.contentfulAccessToken ?? null,
|
|
85
|
+
spaces: this.options.contentfulSpaceIds!.map((spaceId, i) => ({
|
|
86
|
+
spaceId,
|
|
87
|
+
previewToken: this.options.contentfulPreviewTokens![i]
|
|
88
|
+
})),
|
|
89
|
+
stackbitYaml: this.stackbitYaml,
|
|
90
|
+
encodeDelimiter: '',
|
|
91
|
+
rootDir: this.rootDir,
|
|
92
|
+
appDir: this.appDir!,
|
|
93
|
+
repoDir: this.rootDir,
|
|
94
|
+
staticThemeAssetsFilePath: consts.STATIC_THEME_ASSETS_FILE_PATH,
|
|
95
|
+
staticThemeAssetsPublicPath: consts.STATIC_THEME_ASSETS_PUBLIC_PATH,
|
|
96
|
+
watchForContentUpdates: true,
|
|
97
|
+
onContentUpdate: () => {},
|
|
98
|
+
logger: logger,
|
|
99
|
+
userLogger: logger
|
|
100
|
+
});
|
|
101
|
+
} else if (this.cmsType === 'sanity') {
|
|
102
|
+
result = new SanityCMS({
|
|
103
|
+
rootDir: this.rootDir,
|
|
104
|
+
repoDir: this.rootDir,
|
|
105
|
+
appDir: this.appDir,
|
|
106
|
+
stackbitYaml: this.stackbitYaml,
|
|
107
|
+
encodeDelimiter: '',
|
|
108
|
+
workers: this.workers,
|
|
109
|
+
project: {
|
|
110
|
+
projectId: this.options.sanityProjectId,
|
|
111
|
+
token: this.options.sanityToken,
|
|
112
|
+
studioPath: this.options.sanityStudioPath,
|
|
113
|
+
dataset: this.options.sanityDataset,
|
|
114
|
+
projectUrl: this.options.sanityStudioUrl
|
|
115
|
+
},
|
|
116
|
+
staticAssetsFilePath: consts.STATIC_ASSETS_FILE_PATH,
|
|
117
|
+
staticAssetsPublicPath: consts.STATIC_ASSETS_PUBLIC_PATH,
|
|
118
|
+
staticThemeAssetsFilePath: consts.STATIC_THEME_ASSETS_FILE_PATH,
|
|
119
|
+
staticThemeAssetsPublicPath: consts.STATIC_THEME_ASSETS_PUBLIC_PATH,
|
|
120
|
+
defaultContentTypeExtensions: consts.DEFAULT_CONTENT_TYPE_EXTENSIONS,
|
|
121
|
+
onContentUpdate: () => {},
|
|
122
|
+
logger,
|
|
123
|
+
userLogger: logger
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
result = new GitCMS({
|
|
127
|
+
rootDir: this.rootDir,
|
|
128
|
+
repoDir: this.rootDir,
|
|
129
|
+
appDir: this.appDir,
|
|
130
|
+
stackbitYaml: this.stackbitYaml,
|
|
131
|
+
workers: this.workers,
|
|
132
|
+
assetIdPrefix: consts.ASSET_ID_PREFIX,
|
|
133
|
+
staticAssetsFilePath: consts.STATIC_ASSETS_FILE_PATH,
|
|
134
|
+
staticAssetsPublicPath: consts.STATIC_ASSETS_PUBLIC_PATH,
|
|
135
|
+
staticThemeAssetsFilePath: consts.STATIC_THEME_ASSETS_FILE_PATH,
|
|
136
|
+
staticThemeAssetsPublicPath: consts.STATIC_THEME_ASSETS_PUBLIC_PATH,
|
|
137
|
+
defaultContentTypeExtensions: consts.DEFAULT_CONTENT_TYPE_EXTENSIONS,
|
|
138
|
+
logger,
|
|
139
|
+
userLogger: logger
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async handleFileChanges(filePaths: string[]) {
|
|
146
|
+
const pullResult = await this.cms.postPull(filePaths.map((filePath) => path.join(this.rootDir, filePath))).catch((err: any) => {
|
|
147
|
+
logger.debug('Error in postPull', { err });
|
|
148
|
+
throw err;
|
|
149
|
+
});
|
|
150
|
+
if (pullResult?.schemaChanged) {
|
|
151
|
+
await this.stackbitYaml.load().catch((err: any) => {
|
|
152
|
+
logger.debug('Error handling stackbit.yaml change', { err });
|
|
153
|
+
logger.error('Error reloading stackbit.yaml');
|
|
154
|
+
});
|
|
155
|
+
socketService.notifySchemaChange();
|
|
126
156
|
}
|
|
127
157
|
}
|
|
128
158
|
|
|
@@ -147,7 +177,7 @@ export default class Runner {
|
|
|
147
177
|
return this.ssg.directChangeSocketOrigin;
|
|
148
178
|
}
|
|
149
179
|
|
|
150
|
-
async getObjects({ objectIds = [], locale }: { objectIds: string[]; locale?: string })
|
|
180
|
+
async getObjects({ objectIds = [], locale }: { objectIds: string[]; locale?: string }) {
|
|
151
181
|
return this.editor.getObjects({ objectIds, locale });
|
|
152
182
|
}
|
|
153
183
|
|
|
@@ -173,107 +203,59 @@ export default class Runner {
|
|
|
173
203
|
}
|
|
174
204
|
|
|
175
205
|
async getSiteMap() {
|
|
176
|
-
return this.editor.getSiteMap();
|
|
206
|
+
return this.editor.getSiteMap(this.cms.getEncodingResult());
|
|
177
207
|
}
|
|
178
208
|
|
|
179
209
|
async getSchema({ locale }: { locale?: string }) {
|
|
180
210
|
return this.editor.getSchema({ locale });
|
|
181
211
|
}
|
|
182
212
|
|
|
183
|
-
async getUrl(
|
|
184
|
-
return this.editor.getUrl(
|
|
213
|
+
async getUrl(objectId: string, projectId: string, locale: string): Promise<any> {
|
|
214
|
+
return this.editor.getUrl(objectId, projectId, locale);
|
|
185
215
|
}
|
|
186
216
|
|
|
187
217
|
async getObject(objectId: string, projectId: string): Promise<any> {
|
|
188
|
-
return this.
|
|
218
|
+
return this.cms.getObject(objectId, projectId);
|
|
189
219
|
}
|
|
190
220
|
|
|
191
221
|
async listAssets(filterParams: any): Promise<any> {
|
|
192
|
-
return this.
|
|
222
|
+
return this.cms.listAssets(filterParams);
|
|
193
223
|
}
|
|
194
224
|
|
|
195
225
|
async uploadAsset(url: string, filename: string, user: any): Promise<any> {
|
|
196
|
-
return this.
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async createDocument(data: APIMethodCreateDocument['data']): Promise<APIMethodCreateDocument['result']> {
|
|
200
|
-
return this.contentStoreAdapter.createDocument(data);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async createAndLinkDocument(data: APIMethodCreateAndLinkDocument['data']): Promise<APIMethodCreateAndLinkDocument['result']> {
|
|
204
|
-
return this.contentStoreAdapter.createAndLinkDocument(data);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async uploadAndLinkAsset(data: APIMethodUploadAndLinkAsset['data']): Promise<APIMethodUploadAndLinkAsset['result']> {
|
|
208
|
-
return this.contentStoreAdapter.uploadAndLinkAsset(data);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async duplicateDocument(data: APIMethodDuplicateDocument['data']): Promise<APIMethodDuplicateDocument['result']> {
|
|
212
|
-
return this.contentStoreAdapter.duplicateDocument(data);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async updateDocument(data: APIMethodUpdateDocument['data']): Promise<APIMethodUpdateDocument['result']> {
|
|
216
|
-
return this.contentStoreAdapter.updateDocument(data);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async deleteDocument(data: APIMethodDeleteDocument['data']): Promise<APIMethodDeleteDocument['result']> {
|
|
220
|
-
return this.contentStoreAdapter.deleteDocument(data);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async validateDocuments(data: APIMethodValidateDocuments['data']): Promise<APIMethodValidateDocuments['result']> {
|
|
224
|
-
return this.contentStoreAdapter.validateDocuments(data);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async publishDocuments(data: APIMethodPublishDocuments['data']): Promise<APIMethodPublishDocuments['result']> {
|
|
228
|
-
return this.contentStoreAdapter.publishDocuments(data);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
async getAssets(data: APIMethodGetAssets['data']): Promise<APIMethodGetAssets['result']> {
|
|
232
|
-
return this.contentStoreAdapter.getApiAssets(data);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
async uploadAssets(data: APIMethodUploadAssets['data']): Promise<APIMethodUploadAssets['result']> {
|
|
236
|
-
return this.contentStoreAdapter.uploadAssets(data);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async createPreset(data: APIMethodCreatePreset['data']): Promise<APIMethodCreatePreset['result']> {
|
|
240
|
-
return this.editor.createPreset(this.appDir, data.fieldDataPath, _.omit(data, ['fieldDataPath', 'user', 'dryRun']) as any, data.user, data.dryRun);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
async deletePreset(data: APIMethodDeletePreset['data']): Promise<APIMethodDeletePreset['result']> {
|
|
244
|
-
return this.editor.deletePreset(this.appDir, data.presetId, data.user);
|
|
226
|
+
return this.cms.uploadAsset(url, filename, user);
|
|
245
227
|
}
|
|
246
228
|
|
|
247
229
|
async makeAction(action: string, data: any): Promise<any> {
|
|
248
230
|
switch (action) {
|
|
249
231
|
case 'createPage':
|
|
250
|
-
return this.
|
|
232
|
+
return this.cms.createObject(data);
|
|
251
233
|
case 'duplicatePage':
|
|
252
|
-
return this.
|
|
234
|
+
return this.cms.duplicateObject(data);
|
|
253
235
|
case 'updatePage':
|
|
254
|
-
return this.
|
|
236
|
+
return this.cms.updateObject(data.changedFields);
|
|
255
237
|
case 'deleteObject':
|
|
256
|
-
return this.
|
|
238
|
+
return this.cms.deleteObject(data.srcObjectId, data.srcProjectId);
|
|
257
239
|
case 'getAssets':
|
|
258
|
-
|
|
240
|
+
const pageId = data.pageId || 1;
|
|
241
|
+
return this.cms.listAssets(data).then((result: any) => ({
|
|
242
|
+
data: result.assets,
|
|
243
|
+
meta: {
|
|
244
|
+
nextPage: pageId < result.meta.totalPages ? pageId + 1 : null
|
|
245
|
+
}
|
|
246
|
+
}));
|
|
259
247
|
case 'uploadAssets':
|
|
260
|
-
return this.
|
|
248
|
+
return this.cms.uploadAssets(data.assets);
|
|
261
249
|
case 'createPreset':
|
|
262
|
-
return this.editor.createPreset(
|
|
263
|
-
this.appDir,
|
|
264
|
-
data.fieldDataPath,
|
|
265
|
-
_.omit(data, ['fieldDataPath', 'user', 'dryRun']) as any,
|
|
266
|
-
data.user,
|
|
267
|
-
data.dryRun
|
|
268
|
-
);
|
|
250
|
+
return this.editor.createPreset(this.appDir, data.fieldDataPath, _.omit(data, ['fieldDataPath', 'user', 'dryRun']), data.user, data.dryRun);
|
|
269
251
|
case 'deletePreset':
|
|
270
252
|
return this.editor.deletePreset(this.appDir, data.presetId, data.user);
|
|
271
253
|
default:
|
|
272
|
-
throw new Error('Unsupported Operation: ' +
|
|
254
|
+
throw new Error('Unsupported Operation: ' + action);
|
|
273
255
|
}
|
|
274
256
|
}
|
|
275
257
|
|
|
276
258
|
keepAlive() {
|
|
277
|
-
this.
|
|
259
|
+
_.invoke(this.cms, 'keepAlive');
|
|
278
260
|
}
|
|
279
261
|
}
|
package/src/server/index.ts
CHANGED
|
@@ -19,7 +19,6 @@ interface ServerOptions {
|
|
|
19
19
|
runnableDir?: string;
|
|
20
20
|
uuid: string;
|
|
21
21
|
cmsType?: string;
|
|
22
|
-
csiEnabled?: boolean;
|
|
23
22
|
contentfulAccessToken?: string;
|
|
24
23
|
contentfulSpaceIds?: [string];
|
|
25
24
|
contentfulPreviewTokens?: [string];
|
|
@@ -39,7 +38,7 @@ export async function start({ serverPort, ssgPort, ssgHost, rootDir, runnableDir
|
|
|
39
38
|
logger.debug('Done runner init');
|
|
40
39
|
|
|
41
40
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
42
|
-
|
|
41
|
+
|
|
43
42
|
const server = express();
|
|
44
43
|
const httpServer = http.createServer(server);
|
|
45
44
|
socketService.use(httpServer, logger);
|
package/src/server/routes.ts
CHANGED
|
@@ -4,7 +4,6 @@ import bodyParser from 'body-parser';
|
|
|
4
4
|
import Runner from '../runner';
|
|
5
5
|
import logger from '../services/logger';
|
|
6
6
|
import { PageNotFoundError } from '@stackbit/dev-common/dist/services/response-errors';
|
|
7
|
-
import { APIMethod, APIMethodDataForMethod, APIMethodName, APIMethodResultForMethod } from '../types/api-methods';
|
|
8
7
|
|
|
9
8
|
const authMiddleware = (uuid: string) => {
|
|
10
9
|
return (req: Request, res: Response, next: NextFunction) => {
|
|
@@ -110,11 +109,9 @@ export default function routes(router: Router, runner: Runner, uuid: string) {
|
|
|
110
109
|
});
|
|
111
110
|
});
|
|
112
111
|
router.get('/_pageUrl', (req: Request, res: Response, next: NextFunction) => {
|
|
113
|
-
const {
|
|
114
|
-
const srcProjectId = req.query.srcProjectId ?? req.query.spaceId;
|
|
115
|
-
const srcDocumentId = req.query.srcDocumentId ?? req.query.entryId;
|
|
112
|
+
const { entryId: objectId, spaceId: projectId, locale } = req.query;
|
|
116
113
|
runner
|
|
117
|
-
.getUrl(
|
|
114
|
+
.getUrl(objectId as string, projectId as string, locale as string)
|
|
118
115
|
.then((url) => res.json({ url }))
|
|
119
116
|
.catch((err) => {
|
|
120
117
|
if (err !== PageNotFoundError) {
|
|
@@ -158,7 +155,6 @@ export default function routes(router: Router, runner: Runner, uuid: string) {
|
|
|
158
155
|
router.get('/_health', (req: Request, res: Response) => {
|
|
159
156
|
return res.status(200).json({ status: 'ok' });
|
|
160
157
|
});
|
|
161
|
-
|
|
162
158
|
router.post('/_action', [authMiddleware(uuid), bodyParser.json({ limit: '50mb' })], (req: Request, res: Response, next: NextFunction) => {
|
|
163
159
|
const { action, data } = req.body;
|
|
164
160
|
return runner
|
|
@@ -172,32 +168,8 @@ export default function routes(router: Router, runner: Runner, uuid: string) {
|
|
|
172
168
|
if (_.has(err, 'stack')) {
|
|
173
169
|
logger.debug('error.stack: ' + err.stack);
|
|
174
170
|
}
|
|
175
|
-
res.status(500).
|
|
171
|
+
res.status(500).send('Error');
|
|
176
172
|
next(err);
|
|
177
173
|
});
|
|
178
174
|
});
|
|
179
|
-
|
|
180
|
-
router.post(
|
|
181
|
-
'/_stackbit/:method',
|
|
182
|
-
[authMiddleware(uuid), bodyParser.json()],
|
|
183
|
-
<T extends APIMethodName>(req: Request<{ method: T }>, res: Response, next: NextFunction) => {
|
|
184
|
-
const method: APIMethodName = req.params.method;
|
|
185
|
-
if (!runner[method]) {
|
|
186
|
-
logger.error(`method ${method} is not supported`);
|
|
187
|
-
}
|
|
188
|
-
const data = req.body;
|
|
189
|
-
return runner[method](data)
|
|
190
|
-
.then((result: APIMethod['result']) => {
|
|
191
|
-
res.json(result);
|
|
192
|
-
})
|
|
193
|
-
.catch((err) => {
|
|
194
|
-
logger.error(`error executing ${method} method`, { data, error: err.message || err });
|
|
195
|
-
if (_.has(err, 'stack')) {
|
|
196
|
-
logger.debug('error.stack: ' + err.stack);
|
|
197
|
-
}
|
|
198
|
-
res.status(500).send({ error: err.message || err });
|
|
199
|
-
next(err);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
);
|
|
203
175
|
}
|
|
@@ -2,21 +2,20 @@ import chalk from 'chalk';
|
|
|
2
2
|
import _ from 'lodash';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
-
export function logAnnotationErrors(errors: any[], logger: any, baseDir: string, sourcemaps?: { [k: string]: any }) {
|
|
5
|
+
export async function logAnnotationErrors(errors: any[], logger: any, baseDir: string, sourcemaps?: { [k: string]: any }) {
|
|
6
6
|
if (_.isEmpty(errors)) {
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
logger.error(`Found ${errors.length} annotation error${errors.length !== 1 ? 's' : ''}`);
|
|
10
10
|
|
|
11
11
|
for (const error of errors) {
|
|
12
|
-
const elementXPath = error.elementXPath;
|
|
13
12
|
let message = error.message;
|
|
14
|
-
const sourcemap = sourcemaps?.[elementXPath];
|
|
13
|
+
const sourcemap = sourcemaps?.[error.elementXPath];
|
|
15
14
|
if (sourcemap) {
|
|
16
15
|
const relFileName = path.isAbsolute(sourcemap.file) ? path.relative(baseDir, sourcemap.file) : sourcemap.file;
|
|
17
16
|
message += ` (${chalk.yellow(`${relFileName}:${sourcemap.start?.line}`)})`;
|
|
18
|
-
} else if (elementXPath) {
|
|
19
|
-
message += ` (${elementXPath})`;
|
|
17
|
+
} else if (error.elementXPath) {
|
|
18
|
+
message += ` (${error.elementXPath})`;
|
|
20
19
|
}
|
|
21
20
|
logger.error(message);
|
|
22
21
|
}
|
package/src/services/logger.ts
CHANGED
|
@@ -14,7 +14,7 @@ const logger = winston.createLogger({
|
|
|
14
14
|
transports: transports
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
export const createLogger = ({ label }: { label: string })
|
|
17
|
+
export const createLogger = ({ label }: { label: string }) => {
|
|
18
18
|
const formats = defaultFormats.slice();
|
|
19
19
|
if (label) {
|
|
20
20
|
formats.push(
|
|
@@ -24,21 +24,11 @@ export const createLogger = ({ label }: { label: string }): winston.Logger => {
|
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
return winston.createLogger({
|
|
28
28
|
level: config.logLevel,
|
|
29
29
|
format: winston.format.combine(...formats),
|
|
30
30
|
transports: transports
|
|
31
31
|
});
|
|
32
|
-
logger.createLogger = createLogger;
|
|
33
|
-
return logger;
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
declare module "winston" {
|
|
37
|
-
interface Logger {
|
|
38
|
-
createLogger: ({ label }: { label: string }) => winston.Logger
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
logger.createLogger = createLogger;
|
|
43
|
-
|
|
44
34
|
export default logger;
|