@reactionary/source 0.3.4 → 0.3.6

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,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { IdentityIdentifierSchema, WebStoreIdentifierSchema } from './models/identifiers.model.js';
2
+ import { WebStoreIdentifierSchema } from './models/identifiers.model.js';
3
3
  import { CurrencySchema } from './models/currency.model.js';
4
4
  import { IdentitySchema } from './models/identity.model.js';
5
5
 
@@ -14,12 +14,12 @@ export const LanguageContextSchema = z.looseObject( {
14
14
  export const IdentityContextSchema = z.looseObject({
15
15
  identity: IdentitySchema,
16
16
  personalizationKey: z.string(),
17
- lastUpdated: z.date()
17
+ lastUpdated: z.coerce.date()
18
18
  });
19
19
 
20
- export const SessionSchema = z.record(z.string(), z.any()).and(z.object({
20
+ export const SessionSchema = z.looseObject({
21
21
  identityContext: IdentityContextSchema
22
- }));
22
+ });
23
23
 
24
24
  export const TaxJurisdictionSchema = z.object( {
25
25
  countryCode: z.string().default('US'),
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { createInitialRequestContext } from "../initialization.js";
3
+ import { RequestContextSchema } from "../schemas/session.schema.js";
4
+
5
+ describe('Request Context', () => {
6
+ it('should be able to serialize the request context as a JSON string, and have it parse', async () => {
7
+ const context = createInitialRequestContext();
8
+ const contextString = JSON.stringify(context);
9
+ const reconstructedContext = JSON.parse(contextString);
10
+
11
+ const parse = RequestContextSchema.safeParse(reconstructedContext);
12
+
13
+ expect(parse.success).toBe(true);
14
+ });
15
+ });
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@reactionary/examples-node",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "main": "index.js",
5
5
  "types": "src/index.d.ts",
6
6
  "dependencies": {
7
- "@reactionary/core": "0.3.4",
8
- "@reactionary/provider-commercetools": "0.3.4",
9
- "@reactionary/provider-algolia": "0.3.4",
10
- "@reactionary/provider-medusa": "0.3.4",
11
- "@reactionary/provider-meilisearch": "0.3.4"
7
+ "@reactionary/core": "0.3.6",
8
+ "@reactionary/provider-commercetools": "0.3.6",
9
+ "@reactionary/provider-algolia": "0.3.6",
10
+ "@reactionary/provider-medusa": "0.3.6",
11
+ "@reactionary/provider-meilisearch": "0.3.6"
12
12
  },
13
13
  "type": "module"
14
14
  }
@@ -76,6 +76,8 @@ describe.each([PrimaryProvider.MEILISEARCH])(
76
76
  }
77
77
 
78
78
  expect(result.value.length).toBeGreaterThan(0);
79
+ expect(result.value[0].product.key).toBeDefined();
80
+ expect(result.value[0].recommendationIdentifier.key).toBeDefined();
79
81
  });
80
82
 
81
83
  it('should return an empty result for an unknown sku', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/source",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -40,7 +40,7 @@ export class RequestContextTokenStore implements MedusaCustomStorage {
40
40
  this.context.session[SESSION_KEY] = {};
41
41
  }
42
42
  const retVal = this.context.session[SESSION_KEY]
43
- ? this.context.session[SESSION_KEY][this.keyPrefix + '_' + key] || null
43
+ ? (this.context.session[SESSION_KEY] as MedusaSession)[this.keyPrefix + '_' + key] || null
44
44
  : null;
45
45
  if (debug.enabled) {
46
46
  debug(
@@ -49,7 +49,7 @@ export class RequestContextTokenStore implements MedusaCustomStorage {
49
49
  }`
50
50
  );
51
51
  }
52
- return Promise.resolve(retVal);
52
+ return Promise.resolve(retVal as any);
53
53
  }
54
54
 
55
55
  setItem(key: string, value: string): Promise<void> {
@@ -63,7 +63,7 @@ export class RequestContextTokenStore implements MedusaCustomStorage {
63
63
  } - Value: ${value}`
64
64
  );
65
65
  }
66
- this.context.session[SESSION_KEY][this.keyPrefix + '_' + key] = value;
66
+ (this.context.session[SESSION_KEY] as MedusaSession)[this.keyPrefix + '_' + key] = value;
67
67
  return Promise.resolve();
68
68
  }
69
69
 
@@ -74,7 +74,7 @@ export class RequestContextTokenStore implements MedusaCustomStorage {
74
74
  if (debug.enabled) {
75
75
  debug(`Removing token item for key: ${this.keyPrefix + '_' + key}`);
76
76
  }
77
- delete this.context.session[SESSION_KEY][this.keyPrefix + '_' + key];
77
+ delete (this.context.session[SESSION_KEY] as MedusaSession)[this.keyPrefix + '_' + key];
78
78
  return Promise.resolve();
79
79
  }
80
80
  }
@@ -220,12 +220,12 @@ export class MedusaAPI {
220
220
 
221
221
  public getSessionData(): MedusaSession {
222
222
  return this.context.session[SESSION_KEY]
223
- ? this.context.session[SESSION_KEY]
223
+ ? this.context.session[SESSION_KEY] as Partial<MedusaSession>
224
224
  : MedusaSessionSchema.parse({});
225
225
  }
226
226
 
227
227
  public setSessionData(sessionData: Partial<MedusaSession>): void {
228
- const existingData = this.context.session[SESSION_KEY];
228
+ const existingData = this.context.session[SESSION_KEY] as Partial<MedusaSession>;
229
229
 
230
230
  this.context.session[SESSION_KEY] = {
231
231
  ...existingData,
@@ -12,7 +12,7 @@ import { MeiliSearch, type Hits, type RecordAny, type SearchParams, type SearchR
12
12
  import type { MeilisearchConfiguration } from '../schema/configuration.schema.js';
13
13
 
14
14
  interface MeilisearchRecommendHit {
15
- id: string;
15
+ objectID: string;
16
16
  }
17
17
 
18
18
  /**
@@ -78,11 +78,11 @@ export class MeilisearchProductRecommendationsProvider extends ProductRecommenda
78
78
  protected parseRecommendations(recommendation: SearchResponse<MeilisearchRecommendHit>, algorithm: string): ProductRecommendation[] {
79
79
  return recommendation.hits.map((hit) => ({
80
80
  recommendationIdentifier: {
81
- key: hit.id,
81
+ key: hit.objectID,
82
82
  algorithm,
83
83
  },
84
84
  product: {
85
- key: hit.id,
85
+ key: hit.objectID,
86
86
  },
87
87
  }));
88
88
  }