@usebruno/filestore 0.8.0 → 0.8.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/formats/bru/index.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,KAAW,GAuG7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,GAAG,KAAG,MA+G/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,KAAW,GA4ChF,CAAC;AAEF,eAAO,MAAM,sBAAsB,SAAU,GAAG,aAAa,OAAO,KAAG,MAuCtE,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,GAejD,CAAC;AAEF,eAAO,MAAM,uBAAuB,SAAU,GAAG,KAAG,MAOnD,CAAC;AAGF,eAAO,MAAM,gBAAgB,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,eAAuB,MAAM,iBAAiB,MAAM,KAAG,GA6D1H,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,GAAG;;;;;;;;;;;CAsBzC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/formats/bru/index.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,eAAe,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,KAAW,GAuG7E,CAAC;AAEF,eAAO,MAAM,mBAAmB,SAAU,GAAG,KAAG,MA+G/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,KAAW,GA4ChF,CAAC;AAEF,eAAO,MAAM,sBAAsB,SAAU,GAAG,aAAa,OAAO,KAAG,MAuCtE,CAAC;AAEF,eAAO,MAAM,mBAAmB,QAAS,MAAM,KAAG,GAejD,CAAC;AAEF,eAAO,MAAM,uBAAuB,SAAU,GAAG,KAAG,MAOnD,CAAC;AAGF,eAAO,MAAM,gBAAgB,SAAU,MAAM,GAAG,GAAG,WAAU,OAAO,eAAuB,MAAM,iBAAiB,MAAM,KAAG,GAwE1H,CAAC;AAEF,eAAO,MAAM,gBAAgB,SAAU,GAAG;;;;;;;;;;;CAsBzC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=example-status-swap.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example-status-swap.spec.d.ts","sourceRoot":"","sources":["../../../../src/formats/bru/tests/example-status-swap.spec.js"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usebruno/filestore",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -367,6 +367,17 @@ export const bruExampleToJson = (data: string | any, parsed: boolean = false, pa
367
367
  transformedType = 'http-request';
368
368
  }
369
369
 
370
+ /**
371
+ * Backward compatibility (pre-v3.0.2 - v3.2.0): Postman imports before PR #6876 stored status/statusText swapped
372
+ * (code: "OK", text: "202" instead of code: 202, text: "OK"). Detect and swap back.
373
+ * TODO(Sid / Shubh): Remove after v5 — all collections should be migrated by then.
374
+ */
375
+ let status = _.get(json, 'response.status', '200');
376
+ let statusText = _.get(json, 'response.statusText', 'OK');
377
+ if (isNaN(Number(status)) && !isNaN(Number(statusText))) {
378
+ [status, statusText] = [statusText, status];
379
+ }
380
+
370
381
  // Follow the same structure as the main request, but with missing fields for examples
371
382
  const transformedJson = {
372
383
  type: transformedType,
@@ -388,8 +399,8 @@ export const bruExampleToJson = (data: string | any, parsed: boolean = false, pa
388
399
  name: header.name,
389
400
  value: header.value
390
401
  })),
391
- status: String(_.get(json, 'response.status', '200')),
392
- statusText: _.get(json, 'response.statusText', 'OK'),
402
+ status: Number(status) || 200,
403
+ statusText: statusText || 'OK',
393
404
  body: {
394
405
  type: _.get(json, 'response.body.type', 'json'),
395
406
  content: _.get(json, 'response.body.content', '')
@@ -0,0 +1,109 @@
1
+ const { bruExampleToJson } = require('../index');
2
+
3
+ describe('bruExampleToJson - status/statusText swap fix', () => {
4
+ it('should parse normal status and statusText correctly', () => {
5
+ const parsed = {
6
+ name: 'Normal Example',
7
+ description: '',
8
+ request: { url: 'https://api.example.com/test', method: 'get' },
9
+ response: {
10
+ headers: [],
11
+ status: '200',
12
+ statusText: 'OK',
13
+ body: { type: 'json', content: '{}' }
14
+ }
15
+ };
16
+
17
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
18
+ expect(result.response.status).toBe(200);
19
+ expect(result.response.statusText).toBe('OK');
20
+ });
21
+
22
+ it('should swap back status and statusText when they are reversed (pre-fix Postman import)', () => {
23
+ const parsed = {
24
+ name: 'Swapped Example',
25
+ description: '',
26
+ request: { url: 'https://api.example.com/test', method: 'get' },
27
+ response: {
28
+ headers: [],
29
+ status: 'Accepted',
30
+ statusText: '202',
31
+ body: { type: 'json', content: '{}' }
32
+ }
33
+ };
34
+
35
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
36
+ expect(result.response.status).toBe(202);
37
+ expect(result.response.statusText).toBe('Accepted');
38
+ });
39
+
40
+ it('should swap back status OK and statusText 200', () => {
41
+ const parsed = {
42
+ name: 'Swapped OK Example',
43
+ description: '',
44
+ request: { url: 'https://api.example.com/test', method: 'get' },
45
+ response: {
46
+ headers: [],
47
+ status: 'OK',
48
+ statusText: '200',
49
+ body: { type: 'json', content: '{}' }
50
+ }
51
+ };
52
+
53
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
54
+ expect(result.response.status).toBe(200);
55
+ expect(result.response.statusText).toBe('OK');
56
+ });
57
+
58
+ it('should swap back status Not Found and statusText 404', () => {
59
+ const parsed = {
60
+ name: 'Swapped Not Found Example',
61
+ description: '',
62
+ request: { url: 'https://api.example.com/test', method: 'get' },
63
+ response: {
64
+ headers: [],
65
+ status: 'Not Found',
66
+ statusText: '404',
67
+ body: { type: 'json', content: '{}' }
68
+ }
69
+ };
70
+
71
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
72
+ expect(result.response.status).toBe(404);
73
+ expect(result.response.statusText).toBe('Not Found');
74
+ });
75
+
76
+ it('should not swap when status is already numeric and statusText is text (correct order)', () => {
77
+ const parsed = {
78
+ name: 'Correct Order Example',
79
+ description: '',
80
+ request: { url: 'https://api.example.com/test', method: 'get' },
81
+ response: {
82
+ headers: [],
83
+ status: '404',
84
+ statusText: 'Not Found',
85
+ body: { type: 'json', content: '{}' }
86
+ }
87
+ };
88
+
89
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
90
+ expect(result.response.status).toBe(404);
91
+ expect(result.response.statusText).toBe('Not Found');
92
+ });
93
+
94
+ it('should use defaults when response has no status', () => {
95
+ const parsed = {
96
+ name: 'No Status Example',
97
+ description: '',
98
+ request: { url: 'https://api.example.com/test', method: 'get' },
99
+ response: {
100
+ headers: [],
101
+ body: { type: 'json', content: '{}' }
102
+ }
103
+ };
104
+
105
+ const result = bruExampleToJson(parsed, true, 'http', 'GET');
106
+ expect(result.response.status).toBe(200);
107
+ expect(result.response.statusText).toBe('OK');
108
+ });
109
+ });