Skip to content

Commit dbd70d1

Browse files
committed
Few more minor fixes and additions
1 parent dcef2ab commit dbd70d1

File tree

7 files changed

+39
-26
lines changed

7 files changed

+39
-26
lines changed

packages/core/src/baseclient.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
620620
this._updateSessionFromEvent(session, processedEvent);
621621
}
622622

623-
this._sendEvent(processedEvent, this._getAttachments(scope));
623+
this._sendEvent(processedEvent, this._attachmentsFromScope(scope));
624624
return processedEvent;
625625
})
626626
.then(null, reason => {
@@ -657,8 +657,10 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
657657
);
658658
}
659659

660-
/** */
661-
protected _getAttachments(scope: Scope | undefined): AttachmentItem[] | undefined {
660+
/**
661+
* Loads attachment items from scope
662+
*/
663+
protected _attachmentsFromScope(scope: Scope | undefined): AttachmentItem[] | undefined {
662664
return scope?.getAttachments()?.map(a => createAttachmentEnvelopeItem(a));
663665
}
664666

packages/node/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class NodeClient extends BaseClient<NodeClientOptions> {
155155
/**
156156
* @inheritDoc
157157
*/
158-
protected _getAttachments(scope: Scope | undefined): AttachmentItem[] | undefined {
158+
protected _attachmentsFromScope(scope: Scope | undefined): AttachmentItem[] | undefined {
159159
return scope?.getAttachments()?.map(attachment => {
160160
let [pathOrData, options] = attachment;
161161

packages/node/src/transports/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const GZIP_THRESHOLD = 1024 * 32;
3030

3131
/**
3232
* Gets a stream from a Uint8Array or string
33-
* We don't have Readable.from in earlier versions of node
33+
* Readable.from was added in node.sj v12.3.0, v10.17.0
3434
*/
3535
function streamFromBody(body: Uint8Array | string): Readable {
3636
return new Readable({

packages/types/src/scope.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,20 @@ export interface Scope {
160160
*/
161161
clearBreadcrumbs(): this;
162162

163+
/**
164+
* Adds an attachment to the scope
165+
* @param pathOrData A Uint8Array containing the attachment bytes
166+
* @param options Attachment options
167+
*/
163168
addAttachment(pathOrData: string | Uint8Array, options?: AttachmentOptions): this;
164169

170+
/**
171+
* Returns an array of attachments on the scope
172+
*/
165173
getAttachments(): Attachment[];
166174

175+
/**
176+
* Clears attachments from the scope
177+
*/
167178
clearAttachments(): this;
168179
}

packages/utils/src/attachment.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/utils/src/envelope.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Envelope } from '@sentry/types';
1+
import { Attachment, AttachmentItem, Envelope } from '@sentry/types';
22

33
import { isPrimitive } from './is';
44

@@ -98,3 +98,23 @@ function concatBuffers(buffers: Uint8Array[]): Uint8Array {
9898

9999
return merged;
100100
}
101+
102+
/**
103+
* Creates attachment envelope items
104+
*/
105+
export function createAttachmentEnvelopeItem(attachment: Attachment): AttachmentItem {
106+
const [pathOrData, options] = attachment;
107+
108+
const buffer = typeof pathOrData === 'string' ? new TextEncoder().encode(pathOrData) : pathOrData;
109+
110+
return [
111+
{
112+
type: 'attachment',
113+
length: buffer.length,
114+
filename: options?.filename || 'No filename',
115+
content_type: options?.contentType,
116+
attachment_type: options?.attachmentType,
117+
},
118+
buffer,
119+
];
120+
}

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@ export * from './env';
2323
export * from './envelope';
2424
export * from './clientreport';
2525
export * from './ratelimit';
26-
export * from './attachment';

0 commit comments

Comments
 (0)