microsoft-onedrive-mock 1.0.3 → 1.0.5

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/index.js CHANGED
@@ -52,25 +52,36 @@ const createApp = (config = {}) => {
52
52
  }
53
53
  next();
54
54
  }));
55
- app.use(express_1.default.json({
55
+ const rawParser = express_1.default.raw({
56
+ type: '*/*',
57
+ limit: '50mb',
56
58
  verify: (req, res, buf) => {
57
59
  req.rawBody = buf;
58
60
  }
59
- }));
60
- app.use(express_1.default.text({
61
- type: ['multipart/mixed', 'multipart/related', 'text/*', 'application/xml', 'application/octet-stream'],
61
+ });
62
+ // For file contents and upload sessions, always parse as raw regardless of Content-Type.
63
+ // This prevents express.json() from attempting to parse invalid JSON and crashing.
64
+ app.use((req, res, next) => {
65
+ if (req.path.endsWith('/content') || req.path.includes('/upload-sessions')) {
66
+ rawParser(req, res, next);
67
+ }
68
+ else {
69
+ next();
70
+ }
71
+ });
72
+ app.use(express_1.default.json({
62
73
  verify: (req, res, buf) => {
63
74
  req.rawBody = buf;
64
75
  }
65
76
  }));
66
- // Explicit raw body for binary uploads
67
- app.use(express_1.default.raw({
68
- type: '*/*',
69
- limit: '50mb',
77
+ app.use(express_1.default.text({
78
+ type: ['multipart/mixed', 'multipart/related', 'text/*', 'application/xml', 'application/octet-stream'],
70
79
  verify: (req, res, buf) => {
71
80
  req.rawBody = buf;
72
81
  }
73
82
  }));
83
+ // Explicit raw body for binary uploads (catch-all for other routes if not json/text)
84
+ app.use(rawParser);
74
85
  // Batch Route
75
86
  app.post('/v1.0/$batch', batch_1.handleBatchRequest);
76
87
  // Debug
@@ -101,6 +112,20 @@ const createApp = (config = {}) => {
101
112
  next();
102
113
  });
103
114
  app.use((0, v1_1.createV1Router)());
115
+ // Error handler for body-parser syntax errors
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ app.use((err, req, res, next) => {
118
+ if (err instanceof SyntaxError && 'status' in err && err.status === 400 && 'body' in err) {
119
+ res.status(400).json({
120
+ error: {
121
+ code: 'invalidRequest',
122
+ message: err.message
123
+ }
124
+ });
125
+ return;
126
+ }
127
+ next(err);
128
+ });
104
129
  return app;
105
130
  };
106
131
  exports.createApp = createApp;
package/dist/routes/v1.js CHANGED
@@ -48,15 +48,39 @@ const createV1Router = () => {
48
48
  app.get('/v1.0/me/drive/items/:itemId/children', (req, res) => {
49
49
  const itemId = req.params.itemId;
50
50
  let children = store_1.driveStore.listItems(itemId);
51
- // Basic OData $filter REJECTION
51
+ // Basic OData $filter support for lastModifiedDateTime (RxDB sync)
52
52
  if (req.query.$filter && typeof req.query.$filter === 'string') {
53
- res.status(400).json({
54
- error: {
55
- code: 'invalidRequest',
56
- message: 'Invalid request'
57
- }
58
- });
59
- return;
53
+ const filterStr = req.query.$filter;
54
+ // Support formats like: lastModifiedDateTime ge '2026-03-07T16:41:28.611Z'
55
+ const match = filterStr.match(/lastModifiedDateTime\s+(ge|gt|le|lt|eq)\s+'?([^'\s]+)'?/);
56
+ if (match) {
57
+ const operator = match[1];
58
+ const dateVal = match[2];
59
+ children = children.filter(c => {
60
+ const cTime = c.lastModifiedDateTime || "";
61
+ if (operator === 'ge')
62
+ return cTime >= dateVal;
63
+ if (operator === 'gt')
64
+ return cTime > dateVal;
65
+ if (operator === 'le')
66
+ return cTime <= dateVal;
67
+ if (operator === 'lt')
68
+ return cTime < dateVal;
69
+ if (operator === 'eq')
70
+ return cTime === dateVal;
71
+ return true;
72
+ });
73
+ }
74
+ else {
75
+ // For unsupported filters, return 400 to match real API strictness
76
+ res.status(400).json({
77
+ error: {
78
+ code: 'invalidRequest',
79
+ message: 'Invalid request'
80
+ }
81
+ });
82
+ return;
83
+ }
60
84
  }
61
85
  // Basic OData $orderby support
62
86
  if (req.query.$orderby && typeof req.query.$orderby === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microsoft-onedrive-mock",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Mock-Server that simulates being Microsoft OneDrive. Used for testing.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",