@reactionary/source 0.3.5 → 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 {
|
|
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.
|
|
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.
|
|
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.
|
|
8
|
-
"@reactionary/provider-commercetools": "0.3.
|
|
9
|
-
"@reactionary/provider-algolia": "0.3.
|
|
10
|
-
"@reactionary/provider-medusa": "0.3.
|
|
11
|
-
"@reactionary/provider-meilisearch": "0.3.
|
|
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
|
}
|
package/package.json
CHANGED
|
@@ -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,
|