Skip to content

Commit 3a3b5d3

Browse files
authored
Merge pull request #73 from adobe-rnd/remove-internal
fix: remove internal from json response
2 parents 6920210 + 81d7495 commit 3a3b5d3

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/product-json-pipe.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export async function productJSONPipe(state, req) {
6868

6969
setLastModified(state, res);
7070

71-
res.body = JSON.stringify(state.content.data, null, 2);
71+
const { internal: _, ...productData } = state.content.data;
72+
res.body = JSON.stringify(productData, null, 2);
7273
} catch (e) {
7374
const errorRes = new PipelineResponse('', {
7475
status: e instanceof PipelineStatusError ? e.code : 500,

test/fixtures/product/product-configurable.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
}
5757
]
5858
},
59+
"internal": {
60+
"images": [
61+
{ "url": "https://origin.example.com/product/images/original-a.png" },
62+
{ "url": "https://origin.example.com/product/images/original-b.png" }
63+
]
64+
},
5965
"variants": [
6066
{
6167
"sku": "5000-BLK",

test/product-json-pipe.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,37 @@ describe('Product JSON Pipe Test', () => {
112112
});
113113
});
114114

115+
it('strips the internal property from the json response', async () => {
116+
const s3Loader = new FileS3Loader();
117+
118+
s3Loader.statusCodeOverrides = {
119+
'product-configurable': 200,
120+
};
121+
122+
s3Loader.headers('product-configurable', 'sku', 'product-configurable');
123+
124+
const state = DEFAULT_STATE({
125+
log: console,
126+
s3Loader,
127+
ref: 'main',
128+
path: '/products/product-configurable.json',
129+
partition: 'live',
130+
timer: {
131+
update: () => { },
132+
},
133+
});
134+
state.info = getPathInfo('/products/product-configurable.json');
135+
const resp = await productJSONPipe(
136+
state,
137+
new PipelineRequest(new URL('https://acme.com/products/product-configurable.json')),
138+
);
139+
assert.strictEqual(resp.status, 200);
140+
141+
const body = JSON.parse(resp.body);
142+
assert.strictEqual(body.internal, undefined, 'internal property must not be exposed');
143+
assert.ok(body.name, 'product name should still be present');
144+
});
145+
115146
it('sends 400 for non json path', async () => {
116147
const state = DEFAULT_STATE({
117148
path: '/blog/article',

0 commit comments

Comments
 (0)