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

Release 200524 #323

Merged
merged 39 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6305402
Add campaign bundle (#298)
d-beezee Apr 10, 2024
a35bd4a
feat: Get projects by customer (#300)
d-beezee Apr 10, 2024
420deb8
rework: Refactor to class os
d-beezee Apr 11, 2024
92861fc
feat: Allow listing all device types
d-beezee Apr 11, 2024
58ebe74
feat: Return all devices
d-beezee Apr 12, 2024
b21f944
Handle custom roles (#306)
d-beezee Apr 15, 2024
7b56af7
Add additional campaign data (#307)
d-beezee Apr 22, 2024
f04ff2a
Add selects (#308)
d-beezee Apr 22, 2024
61dc399
Allow duplication options (#309)
d-beezee Apr 23, 2024
186b62e
feat: Always use campaign id as id
d-beezee Apr 24, 2024
e320f40
feat: Add create project (#310)
d-beezee Apr 26, 2024
240a8c5
feat: Add post customer (#311)
d-beezee Apr 29, 2024
d3e1fe2
feat: Add browsers and product types (#312)
d-beezee Apr 30, 2024
2b580b2
fix: Prevent working with empty data
d-beezee Apr 30, 2024
61edbb4
feat: Order campaign types by name
d-beezee Apr 30, 2024
9aaf9b4
fix: Allow empty roles
d-beezee Apr 30, 2024
cca2b10
Add phases (#313)
d-beezee May 2, 2024
f09bd55
Update permissions dossiers (#314)
d-beezee May 6, 2024
0a9c3ff
Add roles to campaigns (#315)
d-beezee May 6, 2024
a80efba
feat: Add filter by role (#316)
d-beezee May 6, 2024
552b837
feat: Allow filtering by phase (#317)
d-beezee May 6, 2024
cc6d737
feat: Add phase type (#318)
d-beezee May 7, 2024
20b27ed
Use phase visibility (#319)
d-beezee May 8, 2024
23163da
fix: Update update with where
d-beezee May 9, 2024
64ee69a
fix: Link translations
d-beezee May 9, 2024
0380aa5
test: Fix tests
d-beezee May 9, 2024
874c27c
feat: Update campaign id in duplicated manuals
d-beezee May 9, 2024
316c368
fix: Do not break data on save
d-beezee May 9, 2024
e3a2346
fix: Add terms for translations
d-beezee May 9, 2024
8cca6d6
feat: Set close date on status change
d-beezee May 10, 2024
c2dbaac
feat: Add notes field
d-beezee May 13, 2024
2bc97fe
feat: Add phase history
d-beezee May 13, 2024
4c7545e
feat: Add zapier triggers
d-beezee May 14, 2024
a8edecd
feat: Allow filterby role empty
d-beezee May 14, 2024
a0d4d46
test: Mock zap trigger
d-beezee May 14, 2024
c09f3a6
fix: Use correct webhook env
d-beezee May 15, 2024
a1899b1
fix: Allow changing csm
d-beezee May 15, 2024
03d4af7
feat: Update legacy status details
d-beezee May 17, 2024
4d10b25
test: Update phase ids
d-beezee May 17, 2024
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
6 changes: 5 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ GOOGLE_API_KEY=AIzaserejejadejedejebetudejeberesebiuno

PAYMENT_INVOICE_RECAP_CC_EMAIL=it+administration@unguess.io

SENTRY_ENVIRONMENT=local
SENTRY_ENVIRONMENT=local


CAMPAIGN_CREATION_WEBHOOK=https://webhook.site/11111111-1111-1111-1111-11111111111
STATUS_CHANGE_WEBHOOK=https://webhook.site/11111111-1111-1111-1111-11111111111
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ RUN yarn global add npm-run-all
RUN yarn build


FROM alpine:3.16 as web

COPY --from=node /usr/lib /usr/lib
COPY --from=node /usr/local/share /usr/local/share
COPY --from=node /usr/local/lib /usr/local/lib
COPY --from=node /usr/local/include /usr/local/include
COPY --from=node /usr/local/bin /usr/local/bin
FROM node:18-alpine3.16 AS web

COPY --from=base /dist /app/build
COPY package*.json /app/
Expand Down
4 changes: 4 additions & 0 deletions deployment/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ services:
GOOGLE_API_KEY: '${GOOGLE_API_KEY}'
PAYMENT_INVOICE_RECAP_CC_EMAIL: '${PAYMENT_INVOICE_RECAP_CC_EMAIL}'
SENTRY_ENVIRONMENT: ${ENVIRONMENT}
ENVIRONMENT: ${ENVIRONMENT}
SENTRY_RELEASE: ${DOCKER_IMAGE}
SENTRY_DSN: ${SENTRY_DSN}
SENTRY_SAMPLE_RATE: ${SENTRY_SAMPLE_RATE:-1}
CLOUDFRONT_KEY_ID: ${CLOUDFRONT_KEY_ID}
JOTFORM_APIKEY: ${JOTFORM_APIKEY}
WORDPRESS_API_URL: ${WORDPRESS_API_URL}
CAMPAIGN_CREATION_WEBHOOK: ${CAMPAIGN_CREATION_WEBHOOK}
STATUS_CHANGE_WEBHOOK: ${STATUS_CHANGE_WEBHOOK}
volumes:
- /var/docker/keys:/app/keys
logging:
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@appquality/tryber-database": "^0.30.0",
"@appquality/tryber-database": "^0.39.0",
"@appquality/wp-auth": "^1.0.7",
"@googlemaps/google-maps-services-js": "^3.3.7",
"@sendgrid/mail": "^7.6.0",
Expand All @@ -32,6 +32,7 @@
"body-parser": "^1.19.1",
"codice-fiscale-js": "^2.3.13",
"connect-busboy": "^1.0.0",
"core-js": "^3.6.5",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.18.1",
Expand All @@ -43,10 +44,10 @@
"mysql": "^2.18.1",
"openapi-backend": "^3.9.2",
"parse-comments": "^1.0.0",
"php-serialize": "^4.1.1",
"php-unserialize": "^0.0.1",
"spark-md5": "^3.0.2",
"uuid": "^9.0.0",
"core-js": "^3.6.5",
"wordpress-hash-node": "^1.0.0"
},
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions src/features/webhookTrigger/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { iWebhookTrigger } from "../types";

export class WebhookTrigger implements iWebhookTrigger {
async trigger() {
return;
}
}
34 changes: 34 additions & 0 deletions src/features/webhookTrigger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from "axios";
import { WebhookTypes, iWebhookTrigger } from "./types";

export class WebhookTrigger<T extends WebhookTypes["type"]>
implements iWebhookTrigger
{
private webhookUrl: string;
private data: WebhookTypes["data"];

constructor({
type,
data,
}: {
type: T;
data: Extract<WebhookTypes, { type: T }>["data"];
}) {
if (type === "status_change") {
this.webhookUrl = process.env.STATUS_CHANGE_WEBHOOK_URL || "";
} else if (type === "campaign_created") {
this.webhookUrl = process.env.CAMPAIGN_CREATION_WEBHOOK || "";
} else {
throw new Error("Invalid webhook type");
}

this.data = data;
}

async trigger() {
await axios.post(this.webhookUrl, {
...this.data,
environment: process.env.ENVIROMENT,
});
}
}
21 changes: 21 additions & 0 deletions src/features/webhookTrigger/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type StatusChangeWebhook = {
type: "status_change";
data: {
campaignId: number;
newPhase: number;
oldPhase: number;
};
};

type CampaignCreatedWebhook = {
type: "campaign_created";
data: {
campaignId: number;
};
};

export type WebhookTypes = StatusChangeWebhook | CampaignCreatedWebhook;

export interface iWebhookTrigger {
trigger(): Promise<void>;
}
96 changes: 96 additions & 0 deletions src/features/wp/WordpressJsonApiTrigger/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import axios from "axios";
import WordpressJsonApiTrigger from ".";

// mock axios

jest.mock("axios");

describe("WordpressJsonApiTrigger", () => {
beforeAll(() => {
process.env = Object.assign(process.env, {
WORDPRESS_API_URL: "https://example.com",
});
});

afterAll(() => {
jest.resetAllMocks();
process.env = Object.assign(process.env, {
WORDPRESS_API_URL: "",
});
});

afterEach(() => {
jest.clearAllMocks();
});
it("Should create a new instance of WordpressJsonApiTrigger", () => {
const instance = new WordpressJsonApiTrigger(1);
expect(instance).toBeInstanceOf(WordpressJsonApiTrigger);
});

it("Should call axios on generateUseCase", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateUseCase();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-use-cases/1",
});
});

it("Should call axios on generateMailmerges", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateMailMerges();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-crons/1",
});
});
it("Should call axios on generatePages", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generatePages();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-pages/1",
});
});

it("Should call axios on generateTasks", async () => {
const instance = new WordpressJsonApiTrigger(1);

await instance.generateTasks();

expect(axios).toHaveBeenCalledTimes(1);

expect(axios).toHaveBeenCalledWith({
headers: {
"Content-Type": "application/json",
"User-Agent": "Tryber API",
},
method: "GET",
url: "https://example.com/regenerate-campaign-tasks/1",
});
});
});
36 changes: 36 additions & 0 deletions src/features/wp/WordpressJsonApiTrigger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import axios from "axios";

class WordpressJsonApiTrigger {
constructor(private campaign: number) {}

public async generateUseCase() {
await this.postToWordpress(
`regenerate-campaign-use-cases/${this.campaign}`
);
}

public async generateMailMerges() {
await this.postToWordpress(`regenerate-campaign-crons/${this.campaign}`);
}

public async generatePages() {
await this.postToWordpress(`regenerate-campaign-pages/${this.campaign}`);
}

public async generateTasks() {
await this.postToWordpress(`regenerate-campaign-tasks/${this.campaign}`);
}

private async postToWordpress(url: string) {
await axios({
method: "GET",
url: `${process.env.WORDPRESS_API_URL}/${url}`,
headers: {
"User-Agent": "Tryber API",
"Content-Type": "application/json",
},
});
}
}

export default WordpressJsonApiTrigger;
Loading
Loading