Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update api endpoints #1379

Merged
merged 4 commits into from
Jan 14, 2025
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
4 changes: 1 addition & 3 deletions packages/init/test/__testutils__/mockAWSACLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const mockAWSACLAPI = (
ctx: TestContext,
config?: MockAWSACLAPIConfig,
): MockAWSACLAPIReturnType => {
const endpoint =
config?.endpoint ??
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/";
const endpoint = config?.endpoint ?? "https://acl-provider.prismic.io/";

const s3ACL = {
uploadEndpoint:
Expand Down
11 changes: 4 additions & 7 deletions packages/manager/src/constants/API_ENDPOINTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const API_ENDPOINTS: APIEndpoints = (() => {
),
SliceMachineV1: addTrailingSlash(
process.env.slice_machine_v1_endpoint ??
"https://mc5qopc07a.execute-api.us-east-1.amazonaws.com/v1/",
"https://sm-api.wroom.io/v1/",
),
RepositoryService: addTrailingSlash(
process.env.repository_api ?? "https://repository.internal.wroom.io/",
Expand Down Expand Up @@ -83,12 +83,10 @@ If you didn't intend to run Slice Machine this way, stop it immediately and unse
PrismicAuthentication: "https://auth.wroom.io/",
PrismicModels: "https://customtypes.wroom.io/",
PrismicUser: "https://user-service.wroom.io/",
AwsAclProvider:
"https://2iamcvnxf4.execute-api.us-east-1.amazonaws.com/stage/",
AwsAclProvider: "https://acl-provider.wroom.io/",
PrismicEmbed: "https://oembed.wroom.io",
PrismicUnsplash: "https://unsplash.wroom.io/",
SliceMachineV1:
"https://mc5qopc07a.execute-api.us-east-1.amazonaws.com/v1/",
SliceMachineV1: "https://sm-api.wroom.io/v1/",
RepositoryService: "https://repository.internal.wroom.io/",
LocaleService: "https://locale.internal.wroom.io/",
};
Expand All @@ -101,8 +99,7 @@ If you didn't intend to run Slice Machine this way, stop it immediately and unse
PrismicAuthentication: "https://auth.prismic.io/",
PrismicModels: "https://customtypes.prismic.io/",
PrismicUser: "https://user-service.prismic.io/",
AwsAclProvider:
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/",
AwsAclProvider: "https://acl-provider.prismic.io/",
PrismicEmbed: "https://oembed.prismic.io",
PrismicUnsplash: "https://unsplash.prismic.io/",
SliceMachineV1: "https://sm-api.prismic.io/v1/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { BaseManager } from "../BaseManager";

import {
AllChangeTypes,
BulkBody,
PushBody,
ChangeTypes,
ClientError,
PushChangesLimit,
Expand Down Expand Up @@ -403,16 +403,15 @@ export class PrismicRepositoryManager extends BaseManager {
);

// Compute the POST body
const requestBody: BulkBody = {
const requestBody: PushBody = {
confirmDeleteDocuments: args.confirmDeleteDocuments,
changes: allChanges,
};

const repositoryName = await this.project.getResolvedRepositoryName();

// TODO: move to customtypes client
const response = await this._fetch({
url: new URL("./bulk", API_ENDPOINTS.PrismicModels),
url: new URL("./push", API_ENDPOINTS.SliceMachineV1),
method: "POST",
body: requestBody,
repository: repositoryName,
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/managers/prismicRepository/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export type AllChangeTypes =
| CustomTypeInsertChange
| CustomTypeUpdateChange
| CustomTypeDeleteChange;
export interface BulkBody extends Record<string, unknown> {
export interface PushBody {
confirmDeleteDocuments: boolean;
changes: AllChangeTypes[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ it("returns global Slice Machine state", async () => {
const result = await manager.getState();

expect(result.env.endpoints).toStrictEqual({
AwsAclProvider:
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/",
AwsAclProvider: "https://acl-provider.prismic.io/",
PrismicEmbed: "https://oembed.prismic.io",
PrismicAuthentication: "https://auth.prismic.io/",
PrismicModels: "https://customtypes.prismic.io/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { createPrismicAuthLoginResponse } from "./__testutils__/createPrismicAut
import { createTestPlugin } from "./__testutils__/createTestPlugin";
import { createTestProject } from "./__testutils__/createTestProject";
import { mockAWSACLAPI } from "./__testutils__/mockAWSACLAPI";
import { mockCustomTypesAPI } from "./__testutils__/mockCustomTypesAPI";
import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI";
import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI";
import { mockSliceMachineAPI } from "./__testutils__/mockSliceMachineAPI";

import { createSliceMachineManager } from "../src";
import { BulkBody, ChangeTypes } from "../src/managers/prismicRepository/types";
import { PushBody, ChangeTypes } from "../src/managers/prismicRepository/types";

const pushChangesPayload = (
sliceIDs = ["slice1"],
Expand All @@ -31,7 +31,7 @@ const pushChangesPayload = (
],
});

it("pushes changes using the bulk API", async (ctx) => {
it("pushes changes using the push API", async (ctx) => {
const customTypeModel = ctx.mockPrismic.model.customType();
const sharedSliceModel = ctx.mockPrismic.model.sharedSlice();
const adapter = createTestPlugin({
Expand All @@ -56,8 +56,8 @@ it("pushes changes using the bulk API", async (ctx) => {

mockPrismicUserAPI(ctx);
mockPrismicAuthAPI(ctx);
mockCustomTypesAPI(ctx, {
async onBulk(req, res, ctx) {
mockSliceMachineAPI(ctx, {
async onPush(req, res, ctx) {
if (req.headers.get("user-agent") === "slice-machine") {
sentModel = await req.json();

Expand All @@ -82,7 +82,7 @@ it("pushes changes using the bulk API", async (ctx) => {
pushChangesPayload([sharedSliceModel.id], [customTypeModel.id]),
);

const expectedAPIPayload: BulkBody = {
const expectedAPIPayload: PushBody = {
changes: [
{
id: sharedSliceModel.id,
Expand All @@ -102,7 +102,7 @@ it("pushes changes using the bulk API", async (ctx) => {
expect(sentModel).toStrictEqual(expectedAPIPayload);
});

it("pushes changes using the bulk API to the selected environment when an environment is set", async (ctx) => {
it("pushes changes using the push 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 All @@ -129,8 +129,8 @@ it("pushes changes using the bulk API to the selected environment when an enviro

mockPrismicUserAPI(ctx);
mockPrismicAuthAPI(ctx);
mockCustomTypesAPI(ctx, {
async onBulk(req, res, ctx) {
mockSliceMachineAPI(ctx, {
async onPush(req, res, ctx) {
if (
req.headers.get("user-agent") === "slice-machine" &&
req.headers.get("repository") === "foo"
Expand All @@ -157,7 +157,7 @@ it("pushes changes using the bulk API to the selected environment when an enviro
pushChangesPayload([sharedSliceModel.id], [customTypeModel.id]),
);

const expectedAPIPayload: BulkBody = {
const expectedAPIPayload: PushBody = {
changes: [
{
id: sharedSliceModel.id,
Expand Down
4 changes: 1 addition & 3 deletions packages/manager/test/__testutils__/mockAWSACLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const mockAWSACLAPI = (
ctx: TestContext,
config?: MockAWSACLAPIConfig,
): MockAWSACLAPIReturnType => {
const endpoint =
config?.endpoint ??
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/";
const endpoint = config?.endpoint ?? "https://acl-provider.prismic.io/";

const s3ACL = {
uploadEndpoint:
Expand Down
7 changes: 0 additions & 7 deletions packages/manager/test/__testutils__/mockCustomTypesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type MockCustomTypesAPIConfig = {
onSliceGet?: Parameters<typeof rest.get>[1];
onSliceInsert?: Parameters<typeof rest.post>[1];
onSliceUpdate?: Parameters<typeof rest.post>[1];
onBulk?: Parameters<typeof rest.post>[1];
};

export const mockCustomTypesAPI = (
Expand Down Expand Up @@ -104,10 +103,4 @@ export const mockCustomTypesAPI = (
),
);
}

if (config?.onBulk) {
ctx.msw.use(
rest.post(new URL("./bulk", endpoint).toString(), config.onBulk),
);
}
};
7 changes: 7 additions & 0 deletions packages/manager/test/__testutils__/mockSliceMachineAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type MockSliceMachineAPIConfig = {
expectedCookies: string[];
environments: Environment[];
};
onPush?: Parameters<typeof rest.post>[1];
};

export const mockSliceMachineAPI = (
Expand Down Expand Up @@ -47,4 +48,10 @@ export const mockSliceMachineAPI = (
),
);
}

if (config.onPush) {
ctx.msw.use(
rest.post(new URL("./push", endpoint).toString(), config.onPush),
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export const mockAWSACLAPI = (
ctx: TestContext,
config?: MockAWSACLAPIConfig,
): MockAWSACLAPIReturnType => {
const endpoint =
config?.endpoint ??
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/";
const endpoint = config?.endpoint ?? "https://acl-provider.prismic.io/";

const s3ACL = {
uploadEndpoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export const dummyServerState: Pick<
PrismicAuthentication: "https://auth.prismic.io/",
PrismicModels: "https://customtypes.prismic.io/",
PrismicUser: "https://user-service.prismic.io/",
AwsAclProvider:
"https://0yyeb2g040.execute-api.us-east-1.amazonaws.com/prod/",
AwsAclProvider: "https://acl-provider.prismic.io/",
PrismicEmbed: "https://oembed.prismic.io",
PrismicUnsplash: "https://unsplash.prismic.io/",
SliceMachineV1: "https://sm-api.prismic.io/v1/",
Expand Down
Loading