Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-mirrors-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-storefront/sdk": patch
---

[CHANGED] SDK extension allows now to override module methods in `extend` property.
5 changes: 5 additions & 0 deletions .changeset/silver-squids-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-storefront/sdk": minor
---

[ADDED] New SDK module - `middlewareModule`. It is a recommended way to communicate with the Server Middleware.
5 changes: 3 additions & 2 deletions packages/sdk/jest.config.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { baseConfig } from "@vue-storefront/jest-config";

export default {
...baseConfig,
// globalSetup: "./__tests__/integration/__config__/jest.setup.global.ts",
// globalTeardown: "./__tests__/integration/__config__/jest.teardown.global.ts",
globalSetup: "./src/__tests__/integration/__config__/jest.setup.global.ts",
globalTeardown:
"./src/__tests__/integration/__config__/jest.teardown.global.ts",
// setupFilesAfterEnv: ["./__tests__/integration/__config__/jest.setup.ts"],
};
5 changes: 4 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"babel-preset-node": "^5.1.1",
"nodemon": "^2.0.20",
"ts-jest": "^29.0.2",
"ts-node-dev": "^2.0.0"
"ts-node-dev": "^2.0.0",
"@vue-storefront/middleware": "*",
"isomorphic-fetch": "^3.0.0",
"axios": "^1.6.7"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
26 changes: 26 additions & 0 deletions packages/sdk/src/__tests__/__mocks__/apiClient/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
const { apiClientFactory } = require("@vue-storefront/middleware");

const onCreate = (settings) => {
return {
config: settings,
client: null,
};
};

const { createApiClient } = apiClientFactory({
onCreate,
api: {
getProduct: async (_context, params) => {
return { id: params.id, name: "Test Product" };
},
getProducts: async (_context, _params) => {
return [{ id: 1, name: "Test Product" }];
},
getCategory: async (_context, id) => {
return { id, name: "Test Category" };
},
},
});

exports.createApiClient = createApiClient;
16 changes: 16 additions & 0 deletions packages/sdk/src/__tests__/__mocks__/apiClient/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type Endpoints = {
/**
* Get the product by id.
*/
getProduct: (params: { id: number }) => Promise<{ id: number; name: string }>;
/**
* Get the list of products.
*/
getProducts: (params: {
limit: number;
}) => Promise<{ id: number; name: string }[]>;
/**
* Get the category by id.
*/
getCategory: (id: number) => Promise<{ id: number; name: string }>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Express } from "express";
import { Server } from "http";
import { createServer } from "@vue-storefront/middleware";
import { ExtendedGlobalThis } from "./types";

async function runMiddleware(app: Express): Promise<Server> {
return new Promise((resolve) => {
const server = app.listen(8181, async () => {
resolve(server);
});
});
}

export default async () => {
const app = await createServer({
integrations: {
commerce: {
location: "./src/__tests__/__mocks__/apiClient/server",
configuration: {},
},
},
});
const server = await runMiddleware(app);
(globalThis as ExtendedGlobalThis).__MIDDLEWARE__ = server;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExtendedGlobalThis } from "./types";

export default () => {
(globalThis as ExtendedGlobalThis).__MIDDLEWARE__.close();
};
4 changes: 4 additions & 0 deletions packages/sdk/src/__tests__/integration/__config__/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Server } from "http";

export type GlobalThis = typeof globalThis;
export type ExtendedGlobalThis = GlobalThis & { __MIDDLEWARE__: Server };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initSDK } from "../../bootstrap";
import { buildModule } from "../../module/buildModule";
import { buildModule } from "../../modules/buildModule";
import { createModuleMock } from "../__mocks__/createModuleMock";

describe("[ConnectorStructure]", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/__tests__/integration/hooks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { buildModule } from "../../module/buildModule";
import { buildModule } from "../../modules/buildModule";
import proxyModule1Mock from "../__mocks__/proxyModule1.mock";
import { initSDK } from "../../bootstrap";
import { createModuleMock } from "../__mocks__/createModuleMock";
Expand Down
Loading