Skip to content

Commit 30ca0a0

Browse files
authored
Merge pull request #199 from adobe/optimize
Optimize
2 parents 0fd87b2 + 1e7cd11 commit 30ca0a0

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

packages/optimize/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ This API fetches the propositions for the provided DecisionScope list.
175175
176176
**Syntax**
177177
```typescript
178-
updatePropositions(decisionScopes: Array<DecisionScope>, xdm: ?Map<string, any>, data: ?Map<string, any>)
178+
updatePropositions(decisionScopes: Array<DecisionScope>, xdm?: Map<string, any>, data?: Map<string, any>)
179179
```
180180
181181
**Example**
@@ -207,7 +207,7 @@ This class represents the decision scope which is used to fetch the decision pro
207207
module.exports = class DecisionScope {
208208
name: string;
209209

210-
constructor(name: ?string, activityId: ?string, placementId: ?string, itemCount: ?number) {
210+
constructor(name?: string, activityId?: string, placementId?: string, itemCount?: number) {
211211
if(name && name.trim()) {
212212
this.name = name;
213213
} else {
@@ -239,7 +239,7 @@ module.exports = class Proposition {
239239
scope: string;
240240
scopeDetails: Map<string, any>;
241241

242-
constructor(eventData: any) {
242+
constructor(eventData: PropositionEventData) {
243243
this.id = eventData['id'];
244244
this.scope = eventData['scope'];
245245
this.scopeDetails = eventData['scopeDetails'];
@@ -269,29 +269,31 @@ module.exports = class Offer {
269269
id: string;
270270
etag: string;
271271
schema: string;
272-
data: {string: any};
272+
data: Record<string, any>;
273+
meta?: Record<string, any>;
273274

274-
get content(): ?string {
275+
get content(): string {
275276
return this.data["content"];
276277
}
277278

278-
get format(): ?string {
279+
get format(): string {
279280
return this.data["format"];
280281
}
281282

282-
get language(): ?Array<string> {
283+
get language(): Array<string> {
283284
return this.data["language"];
284285
}
285286

286-
get characteristics(): ?Map<string, any> {
287+
get characteristics(): Map<string, any> {
287288
return this.data["characteristics"];
288289
}
289290

290-
constructor(eventData: any) {
291+
constructor(eventData: OfferEventData) {
291292
this.id = eventData['id'];
292293
this.etag = eventData['etag'];
293294
this.schema = eventData['schema'];
294295
this.data = eventData['data'];
296+
this.meta = eventData['meta']
295297
}
296298

297299
/**

packages/optimize/__tests__/OptimizeTests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ describe('Optimize', () => {
7575
expect(offer.format).toBe('text/plain');
7676
expect(offer.language).toBe(offerJson.data.language);
7777
expect(offer.characteristics).toBe(offerJson.data.characteristics);
78+
expect(offer.meta).toMatchObject({
79+
"custom": "custom-meta"
80+
})
7881
});
7982

8083
it('Test Offer.displayed', async () => {

packages/optimize/__tests__/offer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"characteristics": {
1111
"mobile": "true"
1212
}
13+
},
14+
"meta": {
15+
"custom": "custom-meta"
1316
}
1417
}

packages/optimize/ts/models/Offer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ interface OfferEventData {
1717
id: string;
1818
etag: string;
1919
schema: string;
20-
data: Record<string, any>;
20+
data: Record<string, any>;
21+
meta?: Record<string, any>;
2122
}
2223

2324
class Offer {
2425
id: string;
2526
etag: string;
2627
schema: string;
27-
data: Record<string, any>;
28+
data: Record<string, any>;
29+
meta?: Record<string, any>;
2830

2931
get content(): string {
3032
return this.data["content"];
@@ -47,6 +49,7 @@ class Offer {
4749
this.etag = eventData['etag'];
4850
this.schema = eventData['schema'];
4951
this.data = eventData['data'];
52+
this.meta = eventData['meta'];
5053
}
5154

5255
/**

0 commit comments

Comments
 (0)