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

Refactor the SDK to use the new HTTP event tracker #410

Merged
merged 23 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
50 changes: 50 additions & 0 deletions .github/workflows/pr-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: PR preview

on:
pull_request:
types:
- synchronize
- opened

env:
BASE_ENDPOINT: https://api.croct.io
MAX_QUERY_LENGTH: 500

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-lock.json') }}

- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: npm ci

- name: Build package
run: npm run build

- name: Prepare release
run: |-
cp package.json LICENSE README.md build/
cd build
find . -type f -path '*/*\.js.map' -exec sed -i -e "s~../src~src~" {} +
sed -i -e "s~<@version@>~0.0.0-dev~" constants.*
sed -i -e "s~<@baseEndpointUrl@>~${BASE_ENDPOINT}~" constants.*
sed -i -e "s~parseInt('<@maxQueryLength@>', 10)~${MAX_QUERY_LENGTH}~" constants.*
cp -r ../src src

- name: Publish preview
run: |-
npx pkg-pr-new publish \
--compact --comment=update \
./build
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"jest-extended": "^4.0.0",
"jest-websocket-mock": "^2.4.0",
"mock-socket": "^9.1.5",
"node-fetch": "^2.6.7",
"ts-jest": "^29.0.3",
"typescript": "^5.0.0"
Expand Down
153 changes: 0 additions & 153 deletions src/channel/beaconSocketChannel.ts

This file was deleted.

28 changes: 28 additions & 0 deletions src/channel/channel.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
import {formatMessage} from '../error';

export class MessageDeliveryError extends Error {
public readonly retryable: boolean;

public constructor(message: string, retryable: boolean) {
super(message);

this.retryable = retryable;

Object.setPrototypeOf(this, MessageDeliveryError.prototype);
}

public static fromCause(cause: any, retryable?: boolean): MessageDeliveryError {
if (cause instanceof MessageDeliveryError) {
return cause;
}

const error = new MessageDeliveryError(formatMessage(cause), retryable ?? true);

if (cause instanceof Error) {
error.stack = cause.stack;
}

return error;
}
}

export interface Closeable {
close(): Promise<void>;
}
Expand Down
8 changes: 4 additions & 4 deletions src/channel/guaranteedChannel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Logger, NullLogger} from '../logging';
import {DuplexChannel, OutputChannel} from './channel';
import {DuplexChannel, MessageDeliveryError, OutputChannel} from './channel';

export type MessageStamper<M, S> = {
generate(message: M): S,
Expand Down Expand Up @@ -49,7 +49,7 @@ export class GuaranteedChannel<M, S> implements OutputChannel<M> {

public publish(message: M): Promise<void> {
if (this.closed) {
return Promise.reject(new Error('Channel is closed.'));
return Promise.reject(new MessageDeliveryError('Channel is closed.', false));
}

return new Promise((resolve, reject): void => {
Expand Down Expand Up @@ -99,7 +99,7 @@ export class GuaranteedChannel<M, S> implements OutputChannel<M> {
() => {
if (this.closed) {
// Cancel delay immediately when the channel is closed
abort(new Error('Connection deliberately closed.'));
abort(new MessageDeliveryError('Connection deliberately closed.', false));
}
},
0,
Expand All @@ -109,7 +109,7 @@ export class GuaranteedChannel<M, S> implements OutputChannel<M> {

timeoutTimer = window.setTimeout(
() => {
abort(new Error('Maximum confirmation time reached.'));
abort(new MessageDeliveryError('Maximum confirmation time reached.', true));
},
this.options.ackTimeout,
);
Expand Down
Loading
Loading