Commit 2fad78ad authored by Fred Chasen's avatar Fred Chasen Committed by fchasen@mozilla.com
Browse files

Bug 1964849 - Remove Shopping toolkit component. r=shopping-reviewers,kpatenio

parent 02f73af4
Loading
Loading
Loading
Loading
+0 −4
Changes for modules/libpref/init/all.js: 0 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -540,10 +540,6 @@ pref("toolkit.scrollbox.clickToScroll.scrollDelay", 150);

pref("toolkit.shopping.ohttpConfigURL", "https://prod.ohttp-gateway.prod.webservices.mozgcp.net/ohttp-configs");
pref("toolkit.shopping.ohttpRelayURL", "https://mozilla-ohttp.fastly-edge.com/");
pref("toolkit.shopping.environment", "prod");

// Determines whether Review Checker is enabled for de and fr domains
pref("toolkit.shopping.experience2023.defr", false);

// Controls logging for Sqlite.sys.mjs.
pref("toolkit.sqlitejsm.loglevel", "Error");
+0 −1
Changes for toolkit/components/moz.build: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ DIRS += [
    "search",
    "sessionstore",
    "shell",
    "shopping",
    "startup",
    "statusfilter",
    "telemetry",
+0 −143
Changes for toolkit/components/shopping/content/ProductConfig.mjs: 0 added lines, 143 removed lines.
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

let { XPCOMUtils } = ChromeUtils.importESModule(
  "resource://gre/modules/XPCOMUtils.sys.mjs"
);

const ANALYSIS_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/analysis_response.schema.json";
const ANALYSIS_REQUEST_SCHEMA =
  "chrome://global/content/shopping/analysis_request.schema.json";

const ANALYZE_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/analyze_response.schema.json";
const ANALYZE_REQUEST_SCHEMA =
  "chrome://global/content/shopping/analyze_request.schema.json";

const ANALYSIS_STATUS_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/analysis_status_response.schema.json";
const ANALYSIS_STATUS_REQUEST_SCHEMA =
  "chrome://global/content/shopping/analysis_status_request.schema.json";

const RECOMMENDATIONS_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/recommendations_response.schema.json";
const RECOMMENDATIONS_REQUEST_SCHEMA =
  "chrome://global/content/shopping/recommendations_request.schema.json";

const ATTRIBUTION_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/attribution_response.schema.json";
const ATTRIBUTION_REQUEST_SCHEMA =
  "chrome://global/content/shopping/attribution_request.schema.json";

const REPORTING_RESPONSE_SCHEMA =
  "chrome://global/content/shopping/reporting_response.schema.json";
const REPORTING_REQUEST_SCHEMA =
  "chrome://global/content/shopping/reporting_request.schema.json";

// Allow switching to the stage or test environments by changing the
// "toolkit.shopping.environment" pref from "prod" to "stage" or "test".
const lazy = {};
XPCOMUtils.defineLazyPreferenceGetter(
  lazy,
  "env",
  "toolkit.shopping.environment",
  "prod",
  null,
  // If the pref is set to an unexpected string value, "prod" will be used.
  prefValue =>
    ["prod", "stage", "test"].includes(prefValue) ? prefValue : "prod"
);

// prettier-ignore
const Environments = {
  prod: {
    ANALYSIS_API:        "https://trustwerty.com/api/v2/fx/analysis",
    ANALYSIS_STATUS_API: "https://trustwerty.com/api/v1/fx/analysis_status",
    ANALYZE_API:         "https://trustwerty.com/api/v1/fx/analyze",
    ATTRIBUTION_API:     "https://pe.fakespot.com/api/v1/fx/events",
    RECOMMENDATIONS_API: "https://a.fakespot.com/v2/fx/sp_search",
    REPORTING_API:       "https://trustwerty.com/api/v1/fx/report",
  },
  stage: {
    ANALYSIS_API:        "https://staging.trustwerty.com/api/v2/fx/analysis",
    ANALYSIS_STATUS_API: "https://staging.trustwerty.com/api/v1/fx/analysis_status",
    ANALYZE_API:         "https://staging.trustwerty.com/api/v1/fx/analyze",
    ATTRIBUTION_API:     "https://staging-partner-ads.fakespot.io/api/v1/fx/events",
    RECOMMENDATIONS_API: "https://staging-affiliates.fakespot.io/v2/fx/sp_search",
    REPORTING_API:       "https://staging.trustwerty.com/api/v1/fx/report",
  },
  test: {
    ANALYSIS_API:        "https://example.com/browser/toolkit/components/shopping/test/browser/analysis.sjs",
    ANALYSIS_STATUS_API: "https://example.com/browser/toolkit/components/shopping/test/browser/analysis_status.sjs",
    ANALYZE_API:         "https://example.com/browser/toolkit/components/shopping/test/browser/analyze.sjs",
    ATTRIBUTION_API:     "https://example.com/browser/toolkit/components/shopping/test/browser/attribution.sjs",
    RECOMMENDATIONS_API: "https://example.com/browser/toolkit/components/shopping/test/browser/recommendations.sjs",
    REPORTING_API:       "https://example.com/browser/toolkit/components/shopping/test/browser/reporting.sjs",
  },
};

const ShoppingEnvironment = {
  get ANALYSIS_API() {
    return Environments[lazy.env].ANALYSIS_API;
  },
  get ANALYSIS_STATUS_API() {
    return Environments[lazy.env].ANALYSIS_STATUS_API;
  },
  get ANALYZE_API() {
    return Environments[lazy.env].ANALYZE_API;
  },
  get ATTRIBUTION_API() {
    return Environments[lazy.env].ATTRIBUTION_API;
  },
  get RECOMMENDATIONS_API() {
    return Environments[lazy.env].RECOMMENDATIONS_API;
  },
  get REPORTING_API() {
    return Environments[lazy.env].REPORTING_API;
  },
};

const ProductConfig = {
  amazon: {
    productIdFromURLRegex:
      /(?:[\/]|$|%2F)(?<productId>[A-Z0-9]{10})(?:[\/]|$|\#|\?|%2F)/,
    validTLDs: ["com"],
  },
  walmart: {
    productIdFromURLRegex:
      /\/ip\/(?:[A-Za-z0-9-]{1,320}\/)?(?<productId>[0-9]{3,13})/,
    validTLDs: ["com"],
  },
  bestbuy: {
    productIdFromURLRegex: /\/(?<productId>\d+\.p)/,
    validTLDs: ["com"],
  },
};

const ProductConfigDEFR = structuredClone(ProductConfig);
ProductConfigDEFR.amazon.validTLDs = ["com", "de", "fr"];

if (lazy.env == "test") {
  // Also allow example.com to allow for testing.
  ProductConfig.example = ProductConfig.amazon;
}

export {
  ANALYSIS_RESPONSE_SCHEMA,
  ANALYSIS_REQUEST_SCHEMA,
  ANALYZE_RESPONSE_SCHEMA,
  ANALYZE_REQUEST_SCHEMA,
  ANALYSIS_STATUS_RESPONSE_SCHEMA,
  ANALYSIS_STATUS_REQUEST_SCHEMA,
  RECOMMENDATIONS_RESPONSE_SCHEMA,
  RECOMMENDATIONS_REQUEST_SCHEMA,
  ATTRIBUTION_RESPONSE_SCHEMA,
  ATTRIBUTION_REQUEST_SCHEMA,
  REPORTING_RESPONSE_SCHEMA,
  REPORTING_REQUEST_SCHEMA,
  ProductConfig,
  ProductConfigDEFR,
  ShoppingEnvironment,
};
+0 −36
Changes for toolkit/components/shopping/content/ProductValidator.sys.mjs: 0 added lines, 36 removed lines.
Original line number Diff line number Diff line
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

import { JsonSchema } from "resource://gre/modules/JsonSchema.sys.mjs";

let schemas = {};

/**
 * Validate JSON result from the shopping API.
 *
 * @param {object} json
 *  JSON object from the API request.
 * @param {string} SchemaURL
 *  URL string for the schema to validate with.
 * @param {boolean} logErrors
 *  Should invalid JSON log out the errors.
 * @returns {boolean} result
 *  If the JSON is valid or not.
 */
async function validate(json, SchemaURL, logErrors) {
  if (!schemas[SchemaURL]) {
    schemas[SchemaURL] = await fetch(SchemaURL).then(rsp => rsp.json());
  }

  let result = JsonSchema.validate(json, schemas[SchemaURL]);
  let { errors } = result;
  if (!result.valid && logErrors) {
    console.error(`Invalid result: ${JSON.stringify(errors, undefined, 2)}`);
  }
  return result.valid;
}

export const ProductValidator = {
  validate,
};
+0 −976

File deleted.

Preview size limit exceeded, changes collapsed.

Loading