Skip to content

Commit

Permalink
Merge branch 'develop' into feature/support-translations-for-shelves-…
Browse files Browse the repository at this point in the history
…menu-items
  • Loading branch information
CarinaDraganJW authored Sep 23, 2024
2 parents 7e733d8 + 0e51bc4 commit aa713b7
Show file tree
Hide file tree
Showing 53 changed files with 4,442 additions and 24 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/test-unit-snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test - Unit and Snapshot
name: Test - Unit, Integration, Snapshot

on:
push:
Expand All @@ -21,3 +21,11 @@ jobs:
yarn test
env:
CI: true
# Dummy environment variables for testing the access-bridge service
APP_SITE_ID: test1234
APP_API_SECRET: dummy_secret
APP_STRIPE_SECRET: dummy_stripe_secret
APP_BIND_ADDR: localhost
APP_BIND_PORT: 3001
APP_ACCESS_CONTROL_API_HOST: https://test-cdn.jwplayer.com
APP_SIMS_API_HOST: https://test-sims.jwplayer.com
1 change: 0 additions & 1 deletion knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const config: KnipConfig = {
'i18next-parser',
'luxon', // Used in tests
'playwright', // Used in test configs
'sharp', // Requirement for @vite-pwa/assets-generator
'tsconfig-paths', // Used for e2e test setup
'virtual:pwa-register', // Service Worker code is injected at build time
'virtual:polyfills', // Polyfills are conditionally injected
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"prepare": "husky install",
"test": "TZ=UTC LC_ALL=en_US.UTF-8 vitest run",
"test-watch": "TZ=UTC LC_ALL=en_US.UTF-8 vitest",
"web": "yarn --cwd platforms/web"
"web": "yarn --cwd platforms/web",
"access-bridge": "yarn --cwd platforms/access-bridge"
},
"devDependencies": {
"@commitlint/cli": "^17.8.1",
Expand Down
8 changes: 8 additions & 0 deletions packages/common/types/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type JWError = {
code: string;
description: string;
};

export type JWErrorResponse = {
errors: JWError[];
};
4 changes: 4 additions & 0 deletions packages/common/types/passport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type PassportResponse = {
passport: string;
refresh_token: string;
};
49 changes: 49 additions & 0 deletions packages/common/types/payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
type Recurrence = {
// The frequency at which a subscription is billed. One of `day`, `week`, `month`, or `year`.
interval: 'day' | 'week' | 'month' | 'year';
// Recurrence duration, for example, `interval=month` and `duration=3` bills every 3 months.
duration: number;
// Trial period interval. For example, a month-long trial is different from a 30-day trial.
trial_period_interval: 'day' | 'week' | 'month' | 'year';
// Duration of the trial period (in the unit defined by trial_period_interval).
trial_period_duration: number | null;
};

export type Price = {
// Unique identifier for the object.
store_price_id: string;
// Dictionary of currencies, where the key is the currency code and the value is an object with an amount property.
// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
currencies: {
[currency_code: string]: {
// The unit amount in cents (or local equivalent) to be charged, represented as a whole integer.
amount: number | null;
};
};
// Default currency code for this price.
default_currency: string;
// Recurrence details. Can be a Recurrence object or 'one_time'.
recurrence: Recurrence | 'one_time';
// Billing scheme. For now, we only support `per_unit`.
billing_scheme: 'per_unit';
};

export type Product = {
// Unique identifier for the object.
store_product_id: string;
// The product's name, meant to be displayable to the customer.
name: string;
// The product's description, meant to be displayable to the customer.
description: string;
// The ID of the default price this product is associated with.
default_store_price_id: string;
// Array of price objects.
prices: Price[];
};

// General checkout parameters type. Can be extended by specific payment providers, e.g. Stripe
export type CheckoutParams = {
price_id: string;
success_url: string;
cancel_url: string;
};
37 changes: 37 additions & 0 deletions packages/common/types/plans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
type AccessOptions = {
drm_policy_id: string;
include_tags: string[] | null;
exclude_tags: string[] | null;
include_custom_params: string[] | null;
exclude_custom_params: string[] | null;
};

type PlanExternalProviders = {
stripe?: string;
apple?: string;
google?: string;
};

export type AccessControlPlan = {
id: string;
exp: number;
};

export type Plan = {
id: string;
original_id: number;
exp: number;
metadata: {
name: string;
access: AccessOptions;
access_model: 'free' | 'freeauth' | 'svod';
external_providers: PlanExternalProviders;
};
};

export type PlansResponse = {
total: number;
page: number;
page_length: number;
plans: Plan[];
};
37 changes: 37 additions & 0 deletions platforms/access-bridge/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Application version - Used for tracking and identifying specific releases.
# Automatically set to the version specified in package.json.
# Helps in associating logs, errors, and other metrics with particular versions of the application.
APP_VERSION=$npm_package_version

# Secrets responsible for signing a request to authenticate with the JW Delivery Gateway.
# In order to use the AC System this authentication is crucial.
# The secrets can be found in the JW Dashboard, under the API Credentials in the top right settings icon.
# Make sure the secrets are V1 and that they refer to the desired property.
# For production env, use this reference on how to store them: https://cloud.google.com/run/docs/configuring/services/secrets
APP_API_SECRET=customer_v1_secret
# site_id or property_id represents the key that corresponds to the APP_API_SECRET defined earlier.
APP_SITE_ID=customer_site_id
# Stripe secret responsible for authenticating Stripe API calls
APP_STRIPE_SECRET=stripe_secret

# Non-secret variables
# Specifies the network address or IP address on which the server listens for incoming connections.
APP_BIND_ADDR=localhost
# Specifies the port number on which the server listens for incoming connections.
APP_BIND_PORT=8080
# Specifies the client URL responsible for access related stuff
APP_ACCESS_CONTROL_API_HOST=https://cdn-dev.jwplayer.com
# Specifies the client URL responsible for plans related stuff
APP_SIMS_API_HOST=https://daily-sims.jwplayer.com

# These are optional and should be added only if tracing with Sentry is needed
# Set the APP_SENTRY_DSN variable to enable Sentry error tracking and performance monitoring.
# Set APP_SENTRY_AUTH_TOKEN to allow Sentry to provide readable stack traces (source maps).
# If this variable is not set, Sentry will not be initialized.
# For production environments, ensure you configure the `APP_SENTRY_TRACE_RATE`
# according to your monitoring needs to balance performance and resource usage.
APP_SENTRY_DSN=
APP_SENTRY_AUTH_TOKEN=
APP_SENTRY_TRACE_RATE=
APP_SENTRY_ORG_NAME=
APP_SENTRY_PROJ_NAME=
12 changes: 12 additions & 0 deletions platforms/access-bridge/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
extends: ['jwp/typescript'],
rules: {
"max-len": ["error", { "code": 120 }],
"import/no-unused-modules": ["error"]
},
env: {
node: true, // Enables recognition of Node.js global variables and scoping rules
},
ignorePatterns: ['build'],
};

6 changes: 6 additions & 0 deletions platforms/access-bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
build
*.local
.env
# Sentry Config File
.env.sentry-build-plugin
1 change: 1 addition & 0 deletions platforms/access-bridge/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
70 changes: 70 additions & 0 deletions platforms/access-bridge/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
PACKAGE_JSON := ./package.json
BACKUP_PACKAGE_JSON := ./package-backup.json
ROOT_YARN_LOCK := ../../yarn.lock
PROJECT_YARN_LOCK := ./yarn.lock

# Default target: deploy and ensure cleanup runs regardless
.PHONY: deploy
deploy: check-setup backup-package modify-package copy-yarn-lock try-deploy post-deploy

# Step 0: Check setup
.PHONY: check-setup
check-setup:
@echo "Checking setup..."
@command -v gcloud >/dev/null 2>&1 || { echo "Error: gcloud is not installed. Please install Google Cloud SDK."; exit 1; }
@command -v yarn >/dev/null 2>&1 || { echo "Error: yarn is not installed. Please install Yarn."; exit 1; }
@echo "All required tools are installed."
@# Check if Google Cloud is configured
@gcloud config get-value project >/dev/null 2>&1 || { echo "Error: Google Cloud project is not configured. Run 'gcloud init'."; exit 1; }
@echo "Google Cloud is configured."

# Step 1: Backup the original package.json
.PHONY: backup-package
backup-package:
@echo "Deployment started..."
@cp $(PACKAGE_JSON) $(BACKUP_PACKAGE_JSON)

# Step 2: Modify `package.json` by removing internal dependencies
# In a monorepo setup, internal packages are not deployed. This step ensures that only the relevant,
# external dependencies are included in the `package.json` for deployment.
.PHONY: modify-package
modify-package:
@# Use `sed` to remove specific internal dependencies by editing package.json in place
@sed -i.bak '/"@jwp\/ott-common"/d' $(PACKAGE_JSON)
@sed -i.bak '/"eslint-config-jwp"/d' $(PACKAGE_JSON)
@rm -f $(PACKAGE_JSON).bak

# Step 3: Copy the root `yarn.lock` to the project directory
# To maintain dependency consistency in a monorepo, copy the root `yarn.lock` file to the project
# directory so Google Cloud Run can correctly compare and resolve dependencies.
.PHONY: copy-yarn-lock
copy-yarn-lock:
@cp $(ROOT_YARN_LOCK) $(PROJECT_YARN_LOCK)

# Step 4: Deploy to Google Cloud Run
.PHONY: try-deploy
try-deploy:
@{ \
set -e; \
trap 'make post-deploy; exit 1;' INT TERM HUP; \
gcloud run deploy access-bridge \
--source=. \
--platform=managed \
--region= \
--allow-unauthenticated; \
make post-deploy; \
}

# Step 5: Cleanup (run whether deploy succeeds or fails)
.PHONY: post-deploy
post-deploy: restore-package clean

# Step 6: Restore the original package.json
.PHONY: restore-package
restore-package:
@mv $(BACKUP_PACKAGE_JSON) $(PACKAGE_JSON)

# Step 7: Clean up copied yarn.lock
.PHONY: clean
clean:
@rm -f $(PROJECT_YARN_LOCK)
Loading

0 comments on commit aa713b7

Please sign in to comment.