Skip to content

Commit

Permalink
feat: enable headers for event source (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Feb 19, 2025
1 parent 73370ea commit 97300cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"pack:rename": "node scripts/releasePackagesRename.js",
"prepublishOnly": "npm run build && npm run generate:assets",
"test": "jest --coverage --testPathIgnorePatterns ./test/blackbox",
"test:update": "npm run test -- -u",
"coverage": "nyc npm run test",
"bump:version": "npm --no-git-tag-version --allow-same-version version $VERSION",
"runtime:prepare": "npm link",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function renderFetch({
: []),
{
parameter:
'options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string}',
'options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string, headers?: Record<string, string>}',
jsDoc: ' * @param options additionally used to handle the event source'
}
];
Expand All @@ -57,7 +57,8 @@ ${functionName}: async (
let eventsUrl: string = ${addressToUse};
const url = \`\${options.baseUrl}/\${eventsUrl}\`
const headers: Record<string, string> = {
Accept: 'text/event-stream',
...options.headers ?? {},
Accept: 'text/event-stream'
}
if(options.authorization) {
headers['authorization'] = \`Bearer \${options?.authorization}\`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,13 @@ event_source: {
*/
listenForUserSignedup: async (
callback: (messageEvent: MessageTypeModule.MessageType | null, error?: string) => void,
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string}
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string, headers?: Record<string, string>}
) => {
let eventsUrl: string = 'user/signedup';
const url = \`\${options.baseUrl}/\${eventsUrl}\`
const headers: Record<string, string> = {
Accept: 'text/event-stream',
...options.headers ?? {},
Accept: 'text/event-stream'
}
if(options.authorization) {
headers['authorization'] = \`Bearer \${options?.authorization}\`;
Expand Down Expand Up @@ -696,12 +697,13 @@ event_source: {
*/
listenForUserSignedup: async (
callback: (messageEvent: MessageTypeModule.MessageType | null, error?: string) => void,
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string}
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string, headers?: Record<string, string>}
) => {
let eventsUrl: string = 'user/signedup';
const url = \`\${options.baseUrl}/\${eventsUrl}\`
const headers: Record<string, string> = {
Accept: 'text/event-stream',
...options.headers ?? {},
Accept: 'text/event-stream'
}
if(options.authorization) {
headers['authorization'] = \`Bearer \${options?.authorization}\`;
Expand Down Expand Up @@ -1105,12 +1107,13 @@ event_source: {
*/
listenForPing: async (
callback: (messageEvent: MessageTypeModule.MessageType | null, error?: string) => void,
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string}
options: {authorization?: string, onClose?: (err?: string) => void, baseUrl: string, headers?: Record<string, string>}
) => {
let eventsUrl: string = '/ping';
const url = \`\${options.baseUrl}/\${eventsUrl}\`
const headers: Record<string, string> = {
Accept: 'text/event-stream',
...options.headers ?? {},
Accept: 'text/event-stream'
}
if(options.authorization) {
headers['authorization'] = \`Bearer \${options?.authorization}\`;
Expand Down

0 comments on commit 97300cb

Please sign in to comment.