Skip to content

Commit d76e8fd

Browse files
committed
commit
1 parent 4871b0d commit d76e8fd

File tree

376 files changed

+44420
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

376 files changed

+44420
-0
lines changed

browser/.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/** @type { import('eslint').Linter.Config } */
2+
module.exports = {
3+
ignorePatterns: ['e2e-tests', 'qa', '/*.tmp.*/'],
4+
extends: ['../../.eslintrc'],
5+
env: {
6+
node: true, // TODO: change to false when node is abstracted out
7+
browser: true,
8+
},
9+
}

browser/.lintstagedrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require("@internal/config").lintStagedConfig

browser/ARCHITECTURE.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Architecture
2+
3+
## Codebases
4+
5+
analytics-next is comprised of two different codebases:
6+
7+
- [analytics-next](https://github.com/segmentio/analytics-next): All core functionality of AJSN
8+
- [integrations](https://github.com/segmentio/analytics.js-integrations): All existing legacy client side destinations
9+
10+
This diagram outlines the relationship between these two codebases (cloudfront being where the integrations are hosted):
11+
![Architecture](.github/architecture.png?raw=true)
12+
13+
## Core
14+
15+
Some of the bigger core modules are briefly outlined here -
16+
17+
- arguments-resolver: Responsible for reshuffling arguments in event calls
18+
- context: Responsible for building context objects for different events
19+
- emitter: Responsible for emitting events and adding listeners for them
20+
- events: Responsible for building the different Segment events (track, page, etc), and normalizing those events
21+
- logger: Responsible for building and flushing the logs that will be carried around in an events context object
22+
- queue: The heart of AJSN, the queue is responsible for managing events which will be delivered to plugins and destinations, and handles things such as retries, timeouts, and delivery reliability
23+
- user: Responsible for all of the logic built around an analytics user
24+
25+
The general end to end flow of analytics-next core is as follows:
26+
27+
1. Legacy settings and destinations are loaded from the segment CDN
28+
2. The Analytics object is instantiated with the loaded settings, and sets up things such as new/existing users and an event queue.
29+
3. Events are built and queued when a user makes a Segment call (ie. analytics.track())
30+
4. The event is dispatched, goes through all enabled plugins, and is finally sent through the segment.io plugin to get the data into Segment
31+
32+
## Everything is a Plugin
33+
34+
When developing against analytics-next you will likely be writing plugins, which can augment AJSN functionality and enrich data. Plugins are isolated chunks which you can build, test, version, and deploy independently of the rest of the codebase. Extensions are bounded by AJSN which handles things such as observability, retries, and error management.
35+
36+
Plugins can be of two different priorities:
37+
38+
- Critical: AJSN should expect this plugin to be loaded before starting event delivery
39+
- Non-critical: AJSN can start event delivery before this plugin has finished loading
40+
41+
and can be of five different types:
42+
43+
- Before: Pleguns that need to be run before any other plugins are run. An example of this would be validating events before passing them along to other plugins.
44+
- After: Plugins that need to run after all other plugins have run. An example of this is the segment.io integration, which will wait for destinations to succeed or fail so that it can send its observability metrics.
45+
- Destination: Destinations to send the event to (ie. legacy destinations). Does not modify the event and failure does not halt execution.
46+
- Enrichment: Modifies an event, failure here could halt the event pipeline.
47+
- Utility: Plugins that change AJSN functionality and don't fall into the other categories.
48+
49+
## Observability
50+
51+
Every event and plugin has a context object, which contains both metrics and logs that were collected throughout their lifetime. Logs can be used for debugging, and the metrics will be included when the event is sent to Segment.

browser/CHANGELOG.md

Lines changed: 490 additions & 0 deletions
Large diffs are not rendered by default.

browser/LICENSE.MD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright © 2021 Segment
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

browser/Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
BIN := ./node_modules/.bin
2+
yarn_run := yarn run -T browser
3+
4+
help: ## Lists all available make tasks and some short documentation about them
5+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-24s\033[0m %s\n", $$1, $$2}'
6+
.PHONY: help
7+
8+
9+
## Basic repo maintenance
10+
11+
# Installs npm dependencies
12+
node_modules:
13+
yarn install --immutable
14+
@touch $@
15+
16+
build-browser: build # build dependencies
17+
$(yarn_run) umd --no-stats
18+
.PHONY: build-browser
19+
20+
build: ## Builds libraries in prod mode, and all dependencies
21+
yarn run -T browser . build
22+
.PHONY: build
23+
24+
clean: ## Clean the build directory
25+
rm -rf dist generated
26+
.PHONY: clean
27+
28+
## Test Commands
29+
30+
tdd: node_modules ## Runs unit tests in watch mode
31+
$(yarn_run) test --watch
32+
.PHONY: tdd
33+
34+
test-unit: node_modules ## Runs unit tests
35+
$(yarn_run) test
36+
.PHONY: test-unit
37+
38+
test-coverage: node_modules ## Runs unit tests with coverage
39+
$(yarn_run) test --coverage --forceExit
40+
.PHONY: test-coverage
41+
42+
test-qa: build-browser ## Runs all QA tests in a single command
43+
$(yarn_run) test --runTestsByPath qa/__tests__/*.test.ts --testPathIgnorePatterns qa/__tests__/destinations.test.ts --reporters="default" --reporters="<rootDir>/qa/lib/jest-reporter.js" ${args}
44+
.PHONY: test-coverage
45+
46+
test-qa-destinations: build-browser ## Runs Destination QA tests. options. DESTINATION=amplitude DEBUG=true
47+
$(yarn_run) test --forceExit --runTestsByPath qa/__tests__/destinations.test.ts --reporters="default" --reporters="<rootDir>/qa/lib/jest-reporter.js" ${args}
48+
.PHONY: test-coverage
49+
50+
test-integration: build ## Runs all integration tests in a single command
51+
$(yarn_run) test --forceExit --runTestsByPath e2e-tests/**/*.test.ts ${args}
52+
.PHONY: test-coverage
53+
54+
test-perf: build ## Runs all integration tests in a single command
55+
$(yarn_run) test --forceExit --runTestsByPath e2e-tests/performance/*.test.ts ${args}
56+
.PHONY: test-coverage
57+
58+
lint: node_modules ## Lints the source code
59+
$(yarn_run) lint
60+
.PHONY: lint
61+
62+
ci:
63+
bash ./scripts/ci.sh
64+
.PHONY: ci
65+
66+
handshake:
67+
@echo "📡 Establishing Remote connection"
68+
@robo --config ~/dev/src/github.com/segmentio/robofiles/development/robo.yml prod.ssh echo "✅ Connected"
69+
.PHONY: handshake
70+
71+
rebuild-sources-prod: handshake ## Rebuilds all sources that are using ajs-next
72+
@aws-okta exec prod-privileged -- ./scripts/ajs-sources.js
73+
.PHONY: rebuild-sources-prod
74+
75+
rebuild-sources-stage: # Rebuilds all sources that are using ajs-next in stage
76+
@robo --config ~/dev/src/github.com/segmentio/robofiles/development/robo.yml rebuild-all-stage
77+
.PHONY: rebuild-sources-stage
78+
79+
analyze:
80+
NODE_ENV=production $(BIN)/webpack --profile --json > stats.json && $(BIN)/webpack-bundle-analyzer --port 4200 stats.json
81+
.PHONY: analyze
82+
83+
dev: ## Starts a dev server that is ready for development
84+
yarn workspace @playground/next-playground run dev
85+
.PHONY: dev

0 commit comments

Comments
 (0)