Skip to content

Commit

Permalink
Merge pull request dev-next-release - 1.21.3 (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
xrutayisire authored Dec 13, 2023
2 parents d061d33 + f17ce9c commit 6d6c0a6
Show file tree
Hide file tree
Showing 62 changed files with 1,169 additions and 408 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,14 @@ jobs:

- name: Running E2E tests
run: yarn test:e2e
env:
PRISMIC_URL: https://wroom.io
WROOM_EMAIL: ${{ secrets.EMAIL }}
WROOM_PASSWORD: ${{ secrets.PASSWORD }}

- name: Upload HTML report
uses: actions/upload-artifact@v3
if: failure()
with:
name: Playwright HTML report
path: playwright/playwright-report/
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/user-flows/scenario_custom_screenshots.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("I am an existing SM user and I want to upload screenshots on variation
sliceBuilder.goTo(slice.library, slice.name);
});

it("Upload and replace custom screenshots", () => {
it.skip("Upload and replace custom screenshots", () => {
// Upload custom screenshot on default variation
let sliceCard = new SliceCard(slice.name);
sliceCard.imagePreview.should("not.exist");
Expand Down
2 changes: 1 addition & 1 deletion e2e-projects/next-upgrade/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-upgrade",
"version": "1.21.2",
"version": "1.21.3-dev-next-release.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion e2e-projects/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cimsirp",
"version": "1.21.2",
"version": "1.21.3-dev-next-release.3",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
2 changes: 1 addition & 1 deletion e2e-projects/sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveltekit",
"version": "1.21.2",
"version": "1.21.3-dev-next-release.3",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-next",
"version": "0.3.28",
"version": "0.3.29-dev-next-release.3",
"description": "Slice Machine adapter for Next.js.",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-nuxt",
"version": "0.3.28",
"version": "0.3.29-dev-next-release.3",
"description": "Slice Machine adapter for Nuxt 3.",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-nuxt2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-nuxt2",
"version": "0.3.28",
"version": "0.3.29-dev-next-release.3",
"description": "Slice Machine adapter for Nuxt 2.",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-sveltekit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/adapter-sveltekit",
"version": "0.3.28",
"version": "0.3.29-dev-next-release.3",
"description": "Slice Machine adapter for SvelteKit.",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion packages/init/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/init",
"version": "2.9.6",
"version": "2.9.7-dev-next-release.3",
"description": "Init Prismic Slice Machine in your project",
"keywords": [
"typescript",
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@slicemachine/manager",
"version": "0.17.2",
"version": "0.17.3-dev-next-release.3",
"description": "Manage all aspects of a Slice Machine project.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,7 +65,7 @@
},
"dependencies": {
"@antfu/ni": "^0.20.0",
"@prismicio/custom-types-client": "1.2.0-alpha.0",
"@prismicio/custom-types-client": "^1.2.0",
"@prismicio/mocks": "2.0.0",
"@prismicio/types-internal": "^2.2.0",
"@segment/analytics-node": "1.1.3",
Expand Down
11 changes: 5 additions & 6 deletions packages/manager/src/managers/SliceMachineManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import {
CustomType,
} from "@prismicio/types-internal/lib/customtypes";
import { SharedSliceContent } from "@prismicio/types-internal/lib/content";
import {
ForbiddenError,
UnauthorizedError,
} from "@prismicio/custom-types-client";
import * as prismicCustomTypesClient from "@prismicio/custom-types-client";
import {
SliceMachinePlugin,
SliceMachinePluginRunner,
Expand Down Expand Up @@ -202,14 +199,16 @@ export class SliceMachineManager {
authError,
};
} catch (error) {
if (error instanceof ForbiddenError) {
if (error instanceof prismicCustomTypesClient.ForbiddenError) {
authError = {
name: "__stub__",
message: "__stub__",
reason: "__stub__",
status: 401,
};
} else if (error instanceof UnauthorizedError) {
} else if (
error instanceof prismicCustomTypesClient.UnauthorizedError
) {
authError = {
name: "__stub__",
message: "__stub__",
Expand Down
12 changes: 10 additions & 2 deletions packages/manager/src/managers/customTypes/CustomTypesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ export class CustomTypesManager extends BaseManager {
endpoint: API_ENDPOINTS.PrismicModels,
repositoryName,
token: authenticationToken,
userAgent: args.userAgent || SLICE_MACHINE_USER_AGENT,
fetch,
fetchOptions: {
headers: {
"User-Agent": args.userAgent || SLICE_MACHINE_USER_AGENT,
},
},
});

try {
Expand Down Expand Up @@ -323,8 +327,12 @@ export class CustomTypesManager extends BaseManager {
endpoint: API_ENDPOINTS.PrismicModels,
repositoryName,
token: authenticationToken,
userAgent: SLICE_MACHINE_USER_AGENT,
fetch,
fetchOptions: {
headers: {
"User-Agent": SLICE_MACHINE_USER_AGENT,
},
},
});

return await client.getAllCustomTypes();
Expand Down
12 changes: 10 additions & 2 deletions packages/manager/src/managers/slices/SlicesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,12 @@ export class SlicesManager extends BaseManager {
endpoint: API_ENDPOINTS.PrismicModels,
repositoryName,
token: authenticationToken,
userAgent: args.userAgent || SLICE_MACHINE_USER_AGENT,
fetch,
fetchOptions: {
headers: {
"User-Agent": args.userAgent || SLICE_MACHINE_USER_AGENT,
},
},
});

try {
Expand Down Expand Up @@ -987,8 +991,12 @@ export class SlicesManager extends BaseManager {
endpoint: API_ENDPOINTS.PrismicModels,
repositoryName,
token: authenticationToken,
userAgent: SLICE_MACHINE_USER_AGENT,
fetch,
fetchOptions: {
headers: {
"User-Agent": SLICE_MACHINE_USER_AGENT,
},
},
});

return await client.getAllSharedSlices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ it("fetches Custom Types from the Custom Types API", async (ctx) => {
onCustomTypeGetAll: (req, res, ctx) => {
if (
req.headers.get("repository") === sliceMachineConfig.repositoryName &&
req.headers.get("Authorization") === `Bearer ${authenticationToken}`
req.headers.get("Authorization") === `Bearer ${authenticationToken}` &&
req.headers.get("user-agent") === "slice-machine"
) {
return res(ctx.json(models));
}
Expand Down Expand Up @@ -84,7 +85,8 @@ it("fetches Custom Types from the Custom Types API using the currently set envir
onCustomTypeGetAll: (req, res, ctx) => {
if (
req.headers.get("repository") === "foo" &&
req.headers.get("Authorization") === `Bearer ${authenticationToken}`
req.headers.get("Authorization") === `Bearer ${authenticationToken}` &&
req.headers.get("user-agent") === "slice-machine"
) {
return res(ctx.json(models));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,56 @@ it("uses the update endpoint if the Custom Type already exists", async (ctx) =>
expect(sentModel).toStrictEqual({ ...model, format: "custom" });
});

it("sends the provided user agent", async (ctx) => {
const model = ctx.mockPrismic.model.customType();
const adapter = createTestPlugin({
setup: ({ hook }) => {
hook("custom-type:read", () => {
return { model };
});
},
});
const cwd = await createTestProject({ adapter });
const manager = createSliceMachineManager({
nativePlugins: { [adapter.meta.name]: adapter },
cwd,
});

await manager.plugins.initPlugins();

const repositoryName = await manager.project.getRepositoryName();

let sentModel;

mockPrismicUserAPI(ctx);
mockPrismicAuthAPI(ctx);
mockCustomTypesAPI(ctx, {
async onCustomTypeGet(req, res, ctx) {
if (
req.headers.get("user-agent") === "foo" &&
req.headers.get("repository") === repositoryName
) {
return res(ctx.status(404));
}
},
async onCustomTypeInsert(req, res, ctx) {
if (
req.headers.get("user-agent") === "foo" &&
req.headers.get("repository") === repositoryName
) {
sentModel = await req.json();

return res(ctx.status(201));
}
},
});

await manager.user.login(createPrismicAuthLoginResponse());
await manager.customTypes.pushCustomType({ id: model.id, userAgent: "foo" });
// TODO: update prismicio/mock library
expect(sentModel).toStrictEqual({ ...model, format: "custom" });
});

it("throws if plugins have not been initialized", async () => {
const cwd = await createTestProject();
const manager = createSliceMachineManager({ cwd });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const pushChangesPayload = (
],
});

it("pushes changes using the bulk delete API", async (ctx) => {
it("pushes changes using the bulk API", async (ctx) => {
const customTypeModel = ctx.mockPrismic.model.customType();
const sharedSliceModel = ctx.mockPrismic.model.sharedSlice();
const adapter = createTestPlugin({
Expand All @@ -58,9 +58,11 @@ it("pushes changes using the bulk delete API", async (ctx) => {
mockPrismicAuthAPI(ctx);
mockCustomTypesAPI(ctx, {
async onBulk(req, res, ctx) {
sentModel = await req.json();
if (req.headers.get("user-agent") === "slice-machine") {
sentModel = await req.json();

return res(ctx.status(204));
return res(ctx.status(204));
}
},
});

Expand Down Expand Up @@ -100,7 +102,7 @@ it("pushes changes using the bulk delete API", async (ctx) => {
expect(sentModel).toStrictEqual(expectedAPIPayload);
});

it("pushes changes using the bulk delete API to the production repository when an environment is set", async (ctx) => {
it("pushes changes using the bulk API to the selected environment when an environment is set", async (ctx) => {
const customTypeModel = ctx.mockPrismic.model.customType();
const sharedSliceModel = ctx.mockPrismic.model.sharedSlice();
const adapter = createTestPlugin({
Expand Down Expand Up @@ -129,7 +131,10 @@ it("pushes changes using the bulk delete API to the production repository when a
mockPrismicAuthAPI(ctx);
mockCustomTypesAPI(ctx, {
async onBulk(req, res, ctx) {
if (req.headers.get("repository") === "foo") {
if (
req.headers.get("user-agent") === "slice-machine" &&
req.headers.get("repository") === "foo"
) {
sentModel = await req.json();

return res(ctx.status(204));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ it("fetches Slices from the Custom Types API", async (ctx) => {
onSliceGetAll: (req, res, ctx) => {
if (
req.headers.get("repository") === sliceMachineConfig.repositoryName &&
req.headers.get("Authorization") === `Bearer ${authenticationToken}`
req.headers.get("Authorization") === `Bearer ${authenticationToken}` &&
req.headers.get("user-agent") === "slice-machine"
) {
return res(ctx.json(models));
}
Expand Down Expand Up @@ -84,7 +85,8 @@ it("fetches Slices from the Custom Types API using the currently set environment
onSliceGetAll: (req, res, ctx) => {
if (
req.headers.get("repository") === "foo" &&
req.headers.get("Authorization") === `Bearer ${authenticationToken}`
req.headers.get("Authorization") === `Bearer ${authenticationToken}` &&
req.headers.get("user-agent") === "slice-machine"
) {
return res(ctx.json(models));
}
Expand Down
Loading

0 comments on commit 6d6c0a6

Please sign in to comment.