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

Merge canary to main #1686

Merged
merged 18 commits into from
Jan 13, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .changeset/chilly-doors-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"products-feed": patch
"@saleor/apps-logger": patch
"klaviyo": patch
"segment": patch
"app-avatax": patch
"cms-v2": patch
"search": patch
"smtp": patch
---

Increased Vercel log limit to new value - 256KB. See [announcement](https://vercel.com/changelog/updated-logging-limits-for-vercel-functions) blog post from Vercel for more details.
9 changes: 9 additions & 0 deletions .changeset/empty-ligers-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"products-feed": patch
"klaviyo": patch
"cms-v2": patch
"search": patch
"smtp": patch
---

Added new `LoggerVercelTransport` support. It will help us send logs to our infrastructure without need of OTEL unstable logs API.
5 changes: 5 additions & 0 deletions .changeset/fair-cooks-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Added app version & fixed how we send events to Segment
5 changes: 5 additions & 0 deletions .changeset/four-seahorses-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Fixed broken deployment of Segment app
5 changes: 5 additions & 0 deletions .changeset/loud-trains-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Added use case to Segment webhook handler. Use case is responsible for sending event to Segment.
5 changes: 5 additions & 0 deletions .changeset/real-shrimps-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Add OTEL & improve logs in Segment app
10 changes: 10 additions & 0 deletions .changeset/rotten-seals-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"products-feed": patch
"klaviyo": patch
"app-avatax": patch
"cms-v2": patch
"search": patch
"smtp": patch
---

Escape ALLOWED_DOMAIN_PATTERN regex. It ensures that regex constructed from env variable is sanitized and can't be used to Denial of Service attack.
5 changes: 5 additions & 0 deletions .changeset/sharp-mirrors-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

After this change webhooks in Segment app will be by default disabled. After configuration is successfully set app will enable webhooks.
19 changes: 19 additions & 0 deletions .changeset/silver-mangos-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@saleor/react-hook-form-macaw": patch
"@saleor/webhook-utils": patch
"products-feed": patch
"@saleor/apps-logger": patch
"@saleor/apps-shared": patch
"@saleor/apps-otel": patch
"@saleor/trpc": patch
"klaviyo": patch
"segment": patch
"@saleor/e2e": patch
"app-avatax": patch
"cms-v2": patch
"search": patch
"@saleor/apps-ui": patch
"smtp": patch
---

Fixed autofixable liniting issues. No functional changes.
5 changes: 5 additions & 0 deletions .changeset/six-lamps-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-avatax": patch
---

Add log when suspicious calculation happen - when line tax rate is non-zero but amount of taxes is zero
5 changes: 5 additions & 0 deletions .changeset/thick-pumas-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Bringing back Segment app to apps monorepo.
5 changes: 5 additions & 0 deletions .changeset/thirty-monkeys-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"segment": patch
---

Added Sentry to Segment app
5 changes: 3 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
}
],
"words": [
"avatax",
"avalara",
"avatax",
"bruno",
"codegen",
"contentful",
Expand All @@ -39,15 +39,16 @@
"mjml",
"neverthrow",
"pactum",
"quickstart",
"saleor",
"sendgrid",
"shopx",
"strapi",
"taxjar",
"unobfuscated",
"upstash",
"upserted",
"upserting",
"upstash",
"urql"
],
"language": "en-US",
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
"App: SMTP":
- changed-files:
- any-glob-to-any-file: "apps/smtp/**/*"

"App: Segment":
- changed-files:
- any-glob-to-any-file: "apps/segment/**/*"
9 changes: 7 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: |
- args: [--frozen-lockfile, --filter=app-avatax]
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile --filter=app-avatax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we hardcode avatax here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we currently have only e2e for AvaTax app - so it doesn't make sense to install app other deps

- name: Get Saleor snapshot
run: |
BACKUP=$(pnpm dlx saleor backup list --name="snapshot-avatax-$SALEOR_VERSION" --latest --json)
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: |
- args: [--frozen-lockfile]
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check linter
run: pnpm lint
- name: Check types
Expand All @@ -40,7 +45,12 @@ jobs:
- name: Setup PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: |
- args: [--frozen-lockfile]
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run tests
run: pnpm test
9 changes: 7 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ jobs:
run: git fetch --tags origin
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
run_install: |
- args: [--frozen-lockfile]
run_install: false
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Create Release Pull Request
uses: changesets/action@e2f8e964d080ae97c874b19e27b12e0a8620fb6c # v1.4.6
id: changesets
Expand Down
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
* @saleor/apps-guild
/.github/ @saleor/SRE

/apps/avatax @saleor/shopex-js
/apps/segment @saleor/shopex-js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably merchant should own this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question - I will update after 1st version release

/apps/cms-v2 @saleor/merchant-js
/apps/klaviyo @saleor/merchant-js
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ This repository serves as a starting point in the exploration of Saleor apps.

In the `apps` folder, you will find the following applications:

- [avatax](./apps/avatax) - calculates dynamic taxes via AvaTax API
- [avatax](./apps/avatax) - calculates dynamic taxes via AvaTax API.
- [cms](./apps/cms-v2) - exports products from Saleor to CMS.
- [klaviyo](./apps/klaviyo) - send Saleor events to Klaviyo, where you can notify the customers.
- [products-feed](./apps/products-feed) - generate products feed XML
- [products-feed](./apps/products-feed) - generate products feed XML.
- [search](./apps/search) - connect Saleor with search engines.
- [smtp](./apps/smtp) - email communication with customers
- [segment](./apps/segment/) - connect Saleor with Twilio Segment.
- [smtp](./apps/smtp) - email communication with customers.

#### Other official apps

Expand All @@ -64,7 +65,6 @@ Some of the Saleor apps are available in separate repositories:
- [Taxjar integration app example](https://github.com/saleor/example-app-taxjar)
- [Invoices app example](https://github.com/saleor/example-app-invoices)
- [CRM app example](https://github.com/saleor/example-app-crm)
- [Segment app example](https://github.com/saleor/example-app-segment)
- [Sendgrid integration app example](https://github.com/saleor/example-app-sendgrid)

## Development
Expand Down
1 change: 1 addition & 0 deletions apps/avatax/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"decimal.js-light": "2.5.1",
"dotenv": "16.3.1",
"dynamodb-toolbox": "1.8.2",
"escape-string-regexp": "5.0.0",
"graphql": "16.7.1",
"graphql-tag": "2.12.6",
"jotai": "^2.4.2",
Expand Down
5 changes: 3 additions & 2 deletions apps/avatax/src/modules/app/metadata-manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { encrypt } from "@saleor/app-sdk/settings-manager";
import { Client } from "urql";
import { describe, expect, it, Mock, vi } from "vitest";
import { describe, expect, it, vi } from "vitest";

import { AppMetadataCache } from "../../lib/app-metadata-cache";
import { createSettingsManager } from "./metadata-manager";
Expand Down Expand Up @@ -36,7 +36,8 @@ describe("MetadataManager", () => {
const cache = new AppMetadataCache();
const manager = createSettingsManager(mockGqlClient, "test-id", cache);

(mockGqlClient.query as Mock).mockImplementationOnce(() => {
// @ts-expect-error mocking the request for testing
vi.mocked(mockGqlClient.query).mockImplementationOnce(() => {
return {
async toPromise() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ export class AvataxCalculateTaxesAdapter {

const transformedResponse = this.avataxCalculateTaxesResponseTransformer.transform(response);

transformedResponse.lines.forEach((l) => {
const tax = l.total_gross_amount - l.total_net_amount;
const rate = l.tax_rate;
const lineIsZero = l.total_net_amount === 0 ?? l.total_gross_amount === 0;

if (tax === 0 && rate !== 0 && !lineIsZero) {
this.logger.warn("Non-zero line has zero tax, but rate is not zero", {
taxCalculationSummary: response.summary,
});
}
});

this.logger.debug("Transformed AvaTax createTransaction response");

return transformedResponse;
Expand Down
3 changes: 2 additions & 1 deletion apps/avatax/src/pages/api/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next";
import { wrapWithLoggerContext } from "@saleor/apps-logger/node";
import { withOtel } from "@saleor/apps-otel";
import escapeStringRegexp from "escape-string-regexp";

import { env } from "@/env";
import { createLogger } from "@/logger";
Expand All @@ -27,7 +28,7 @@ export default wrapWithLoggerContext(
allowedSaleorUrls: [
(url) => {
if (allowedUrlsPattern) {
const regex = new RegExp(allowedUrlsPattern);
const regex = new RegExp(escapeStringRegexp(allowedUrlsPattern));

return regex.test(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const handler = checkoutCalculateTaxesSyncWebhook.createHandler(async (req, res,

/**
* Create deps in handler, so it's potentially faster and reduce lambda start
* TODO: It's rather not true, we should move it outside
*/
const subscriptionErrorChecker = new SubscriptionPayloadErrorChecker(logger, captureException);
const useCase = new CalculateTaxesUseCase({
Expand Down
1 change: 1 addition & 0 deletions apps/cms-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@vitejs/plugin-react": "4.3.1",
"contentful-management": "10.46.4",
"dotenv": "16.3.1",
"escape-string-regexp": "5.0.0",
"graphql": "16.7.1",
"graphql-tag": "2.12.6",
"jsdom": "^20.0.3",
Expand Down
3 changes: 2 additions & 1 deletion apps/cms-v2/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exportSentryReleaseEnvironmentVariable } from "@saleor/sentry-utils";
import { execSync } from "node:child_process";

import { exportSentryReleaseEnvironmentVariable } from "@saleor/sentry-utils";

import packageJson from "../package.json";

exportSentryReleaseEnvironmentVariable(packageJson.version);
Expand Down
21 changes: 14 additions & 7 deletions apps/cms-v2/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ if (process.env.NODE_ENV !== "production") {
}

if (typeof window === "undefined") {
import("@saleor/apps-logger/node").then(
async ({ attachLoggerOtelTransport, attachLoggerSentryTransport, LoggerContext }) => {
const loggerContext = await import("./logger-context").then((m) => m.loggerContext);
// Don't remove require - it's necessary for proper logger initialization
const {
attachLoggerSentryTransport,
attachLoggerVercelRuntimeTransport,
} = require("@saleor/apps-logger/node");

attachLoggerSentryTransport(rootLogger);
attachLoggerOtelTransport(rootLogger, packageJson.version, loggerContext);
},
);
attachLoggerSentryTransport(rootLogger);

if (process.env.NODE_ENV === "production") {
attachLoggerVercelRuntimeTransport(
rootLogger,
packageJson.version,
require("./logger-context").loggerContext,
);
}
}

export const createLogger = (name: string, params?: Record<string, unknown>) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useState } from "react";

import { BulkImportProductFragment } from "../../../generated/graphql";
import { VariantsSyncStatusListItem } from "./variants-sync-status-list";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAppBridge } from "@saleor/app-sdk/app-bridge";
import { createGraphQLClient } from "@saleor/apps-shared";
import { useEffect, useState } from "react";

import { createGraphQLClient } from "@saleor/apps-shared";
import {
BulkImportProductFragment,
FetchProductsPaginatedDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useDashboardNotification } from "@saleor/apps-shared";
import { ButtonsBox, Layout, SkeletonLayout } from "@saleor/apps-ui";
import { Box, Button, Text } from "@saleor/macaw-ui";
import { useState } from "react";

import { trpcClient } from "../trpc/trpc-client";
import { AddConnectionModal } from "./add-connection-modal";
import { ChanelProviderConnectionsSectionHeader } from "./channel-provider-connections-section-header";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AuthData } from "@saleor/app-sdk/APL";
import { SettingsManager } from "@saleor/app-sdk/settings-manager";
import { createGraphQLClient } from "@saleor/apps-shared";

import { AppConfig } from "./app-config";
import { createSettingsManager } from "./metadata-manager";
import { AuthData } from "@saleor/app-sdk/APL";
import { createGraphQLClient } from "@saleor/apps-shared";

export class AppConfigMetadataManager {
public readonly metadataKey = "app-config-v1";
Expand Down
3 changes: 2 additions & 1 deletion apps/cms-v2/src/modules/configuration/app-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect, beforeEach } from "vitest";
import { beforeEach,describe, expect, it } from "vitest";

import { AppConfig } from "./app-config";
import { ContentfulProviderConfig } from "./schemas/contentful-provider.schema";
import { DatocmsProviderConfig } from "./schemas/datocms-provider.schema";
Expand Down
Loading
Loading