Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions e2e-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ node dist/cli.js --input '{"writeKey":"...", ...}'

```jsonc
{
"writeKey": "your-write-key", // required
"apiHost": "https://...", // optional — SDK default if omitted
"cdnHost": "https://...", // optional — SDK default if omitted
"sequences": [ // required — event sequences to send
"writeKey": "your-write-key", // required
"apiHost": "https://...", // optional — SDK default if omitted
"cdnHost": "https://...", // optional — SDK default if omitted
"sequences": [
// required — event sequences to send
{
"delayMs": 0,
"events": [
{ "type": "track", "event": "Test", "userId": "user-1" }
]
"events": [{ "type": "track", "event": "Test", "userId": "user-1" }]
}
],
"config": { // optional
"config": {
// optional
"flushAt": 20,
"flushInterval": 30
}
Expand Down
6 changes: 3 additions & 3 deletions e2e-cli/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ if [ ! -d "$E2E_DIR" ]; then
fi
cd "$E2E_DIR"
./scripts/run-tests.sh \
--sdk-dir "$SCRIPT_DIR" \
--cli "node $SCRIPT_DIR/dist/cli.js" \
"$@"
--sdk-dir "$SCRIPT_DIR" \
--cli "node $SCRIPT_DIR/dist/cli.js" \
"$@"
90 changes: 73 additions & 17 deletions e2e-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ async function main() {
}

if (!inputStr) {
console.log(JSON.stringify({ success: false, error: 'No input provided', sentBatches: 0 }));
console.log(
JSON.stringify({
success: false,
error: 'No input provided',
sentBatches: 0,
})
);
process.exit(1);
}

Expand Down Expand Up @@ -167,14 +173,24 @@ async function main() {
case 'track': {
// Required: event name
if (!evt.event || typeof evt.event !== 'string') {
console.warn(`[WARN] Skipping track event: missing or invalid event name`, evt);
console.warn(
`[WARN] Skipping track event: missing or invalid event name`,
evt
);
continue;
}

// Optional: properties (validate if present)
const properties = evt.properties as JsonMap | undefined;
if (evt.properties !== undefined && (evt.properties === null || Array.isArray(evt.properties) || typeof evt.properties !== 'object')) {
console.warn(`[WARN] Track event "${evt.event}" has invalid properties, proceeding without them`);
if (
evt.properties !== undefined &&
(evt.properties === null ||
Array.isArray(evt.properties) ||
typeof evt.properties !== 'object')
) {
console.warn(
`[WARN] Track event "${evt.event}" has invalid properties, proceeding without them`
);
}

await client.track(evt.event, properties);
Expand All @@ -185,26 +201,44 @@ async function main() {
// Optional userId (Segment allows anonymous identify)
// Optional traits (validate if present)
const traits = evt.traits as JsonMap | undefined;
if (evt.traits !== undefined && (evt.traits === null || Array.isArray(evt.traits) || typeof evt.traits !== 'object')) {
console.warn(`[WARN] Identify event has invalid traits, proceeding without them`);
if (
evt.traits !== undefined &&
(evt.traits === null ||
Array.isArray(evt.traits) ||
typeof evt.traits !== 'object')
) {
console.warn(
`[WARN] Identify event has invalid traits, proceeding without them`
);
}

await client.identify(evt.userId, traits);
break;
}

case 'screen':
case 'page': { // RN SDK has no page(); map to screen for cross-SDK test compat
case 'page': {
// RN SDK has no page(); map to screen for cross-SDK test compat
// Required: screen/page name
if (!evt.name || typeof evt.name !== 'string') {
console.warn(`[WARN] Skipping ${evt.type} event: missing or invalid name`, evt);
console.warn(
`[WARN] Skipping ${evt.type} event: missing or invalid name`,
evt
);
continue;
}

// Optional: properties (validate if present)
const properties = evt.properties as JsonMap | undefined;
if (evt.properties !== undefined && (evt.properties === null || Array.isArray(evt.properties) || typeof evt.properties !== 'object')) {
console.warn(`[WARN] Screen "${evt.name}" has invalid properties, proceeding without them`);
if (
evt.properties !== undefined &&
(evt.properties === null ||
Array.isArray(evt.properties) ||
typeof evt.properties !== 'object')
) {
console.warn(
`[WARN] Screen "${evt.name}" has invalid properties, proceeding without them`
);
}

await client.screen(evt.name, properties);
Expand All @@ -214,14 +248,24 @@ async function main() {
case 'group': {
// Required: groupId
if (!evt.groupId || typeof evt.groupId !== 'string') {
console.warn(`[WARN] Skipping group event: missing or invalid groupId`, evt);
console.warn(
`[WARN] Skipping group event: missing or invalid groupId`,
evt
);
continue;
}

// Optional: traits (validate if present)
const traits = evt.traits as JsonMap | undefined;
if (evt.traits !== undefined && (evt.traits === null || Array.isArray(evt.traits) || typeof evt.traits !== 'object')) {
console.warn(`[WARN] Group event for "${evt.groupId}" has invalid traits, proceeding without them`);
if (
evt.traits !== undefined &&
(evt.traits === null ||
Array.isArray(evt.traits) ||
typeof evt.traits !== 'object')
) {
console.warn(
`[WARN] Group event for "${evt.groupId}" has invalid traits, proceeding without them`
);
}

await client.group(evt.groupId, traits);
Expand All @@ -231,7 +275,10 @@ async function main() {
case 'alias': {
// Required: userId
if (!evt.userId || typeof evt.userId !== 'string') {
console.warn(`[WARN] Skipping alias event: missing or invalid userId`, evt);
console.warn(
`[WARN] Skipping alias event: missing or invalid userId`,
evt
);
continue;
}

Expand All @@ -240,12 +287,19 @@ async function main() {
}

default:
console.warn(`[WARN] Skipping event: unknown event type "${evt.type}"`, evt);
console.warn(
`[WARN] Skipping event: unknown event type "${evt.type}"`,
evt
);
continue;
}
} catch (error) {
// Log but don't fail the entire sequence if one event fails
console.error(`[ERROR] Failed to process ${evt.type} event:`, error, evt);
console.error(
`[ERROR] Failed to process ${evt.type} event:`,
error,
evt
);
continue;
}
}
Expand All @@ -270,6 +324,8 @@ async function main() {
}

main().catch((e) => {
console.log(JSON.stringify({ success: false, error: String(e), sentBatches: 0 }));
console.log(
JSON.stringify({ success: false, error: String(e), sentBatches: 0 })
);
process.exit(1);
});
6 changes: 5 additions & 1 deletion e2e-cli/src/stubs/sovran.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
*/

export { createStore } from '../../../packages/sovran/src/store';
export type { Store, Notify, Unsubscribe } from '../../../packages/sovran/src/store';
export type {
Store,
Notify,
Unsubscribe,
} from '../../../packages/sovran/src/store';
export { registerBridgeStore } from '../../../packages/sovran/src/bridge';
export type {
Persistor,
Expand Down
Loading