@supabase/realtime-js
Advanced tools
Comparing version 2.11.4-next.1 to 2.11.4
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -27,0 +37,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; |
@@ -5,2 +5,3 @@ export declare const DEFAULT_HEADERS: { | ||
export declare const VSN: string; | ||
export declare const VERSION = "0.0.0-automated"; | ||
export declare const DEFAULT_TIMEOUT = 10000; | ||
@@ -7,0 +8,0 @@ export declare const WS_CLOSE_NORMAL = 1000; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CONNECTION_STATE = exports.TRANSPORTS = exports.CHANNEL_EVENTS = exports.CHANNEL_STATES = exports.SOCKET_STATES = exports.WS_CLOSE_NORMAL = exports.DEFAULT_TIMEOUT = exports.VSN = exports.DEFAULT_HEADERS = void 0; | ||
exports.CONNECTION_STATE = exports.TRANSPORTS = exports.CHANNEL_EVENTS = exports.CHANNEL_STATES = exports.SOCKET_STATES = exports.WS_CLOSE_NORMAL = exports.DEFAULT_TIMEOUT = exports.VERSION = exports.VSN = exports.DEFAULT_HEADERS = void 0; | ||
const version_1 = require("./version"); | ||
exports.DEFAULT_HEADERS = { 'X-Client-Info': `realtime-js/${version_1.version}` }; | ||
exports.VSN = '1.0.0'; | ||
exports.VERSION = version_1.version; | ||
exports.DEFAULT_TIMEOUT = 10000; | ||
@@ -15,3 +16,3 @@ exports.WS_CLOSE_NORMAL = 1000; | ||
SOCKET_STATES[SOCKET_STATES["closed"] = 3] = "closed"; | ||
})(SOCKET_STATES = exports.SOCKET_STATES || (exports.SOCKET_STATES = {})); | ||
})(SOCKET_STATES || (exports.SOCKET_STATES = SOCKET_STATES = {})); | ||
var CHANNEL_STATES; | ||
@@ -24,3 +25,3 @@ (function (CHANNEL_STATES) { | ||
CHANNEL_STATES["leaving"] = "leaving"; | ||
})(CHANNEL_STATES = exports.CHANNEL_STATES || (exports.CHANNEL_STATES = {})); | ||
})(CHANNEL_STATES || (exports.CHANNEL_STATES = CHANNEL_STATES = {})); | ||
var CHANNEL_EVENTS; | ||
@@ -34,7 +35,7 @@ (function (CHANNEL_EVENTS) { | ||
CHANNEL_EVENTS["access_token"] = "access_token"; | ||
})(CHANNEL_EVENTS = exports.CHANNEL_EVENTS || (exports.CHANNEL_EVENTS = {})); | ||
})(CHANNEL_EVENTS || (exports.CHANNEL_EVENTS = CHANNEL_EVENTS = {})); | ||
var TRANSPORTS; | ||
(function (TRANSPORTS) { | ||
TRANSPORTS["websocket"] = "websocket"; | ||
})(TRANSPORTS = exports.TRANSPORTS || (exports.TRANSPORTS = {})); | ||
})(TRANSPORTS || (exports.TRANSPORTS = TRANSPORTS = {})); | ||
var CONNECTION_STATE; | ||
@@ -46,3 +47,3 @@ (function (CONNECTION_STATE) { | ||
CONNECTION_STATE["Closed"] = "closed"; | ||
})(CONNECTION_STATE = exports.CONNECTION_STATE || (exports.CONNECTION_STATE = {})); | ||
})(CONNECTION_STATE || (exports.CONNECTION_STATE = CONNECTION_STATE = {})); | ||
//# sourceMappingURL=constants.js.map |
@@ -30,3 +30,3 @@ /** | ||
} | ||
declare type Columns = { | ||
type Columns = { | ||
name: string; | ||
@@ -37,5 +37,5 @@ type: string; | ||
}[]; | ||
declare type BaseValue = null | string | number | boolean; | ||
declare type RecordValue = BaseValue | BaseValue[]; | ||
declare type Record = { | ||
type BaseValue = null | string | number | boolean; | ||
type RecordValue = BaseValue | BaseValue[]; | ||
type Record = { | ||
[key: string]: RecordValue; | ||
@@ -42,0 +42,0 @@ }; |
@@ -35,3 +35,3 @@ "use strict"; | ||
PostgresTypes["tstzrange"] = "tstzrange"; | ||
})(PostgresTypes = exports.PostgresTypes || (exports.PostgresTypes = {})); | ||
})(PostgresTypes || (exports.PostgresTypes = PostgresTypes = {})); | ||
/** | ||
@@ -38,0 +38,0 @@ * Takes an array of columns and an object of string values then converts each string value |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.11.4-next.1"; | ||
export declare const version = "2.11.4"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '2.11.4-next.1'; | ||
exports.version = '2.11.4'; | ||
//# sourceMappingURL=version.js.map |
@@ -7,3 +7,3 @@ import { CHANNEL_STATES } from './lib/constants'; | ||
import type { RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState } from './RealtimePresence'; | ||
export declare type RealtimeChannelOptions = { | ||
export type RealtimeChannelOptions = { | ||
config: { | ||
@@ -30,3 +30,3 @@ /** | ||
}; | ||
declare type RealtimePostgresChangesPayloadBase = { | ||
type RealtimePostgresChangesPayloadBase = { | ||
schema: string; | ||
@@ -37,3 +37,3 @@ table: string; | ||
}; | ||
export declare type RealtimePostgresInsertPayload<T extends { | ||
export type RealtimePostgresInsertPayload<T extends { | ||
[key: string]: any; | ||
@@ -45,3 +45,3 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresUpdatePayload<T extends { | ||
export type RealtimePostgresUpdatePayload<T extends { | ||
[key: string]: any; | ||
@@ -53,3 +53,3 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresDeletePayload<T extends { | ||
export type RealtimePostgresDeletePayload<T extends { | ||
[key: string]: any; | ||
@@ -61,6 +61,6 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
export type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresInsertPayload<T> | RealtimePostgresUpdatePayload<T> | RealtimePostgresDeletePayload<T>; | ||
export declare type RealtimePostgresChangesFilter<T extends `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`> = { | ||
export type RealtimePostgresChangesFilter<T extends `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`> = { | ||
/** | ||
@@ -83,3 +83,3 @@ * The type of database change to listen to. | ||
}; | ||
export declare type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'error'; | ||
export type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'error'; | ||
export declare enum REALTIME_POSTGRES_CHANGES_LISTEN_EVENT { | ||
@@ -136,3 +136,3 @@ ALL = "*", | ||
/** Topic name can be any string. */ | ||
topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
topic: string, params: RealtimeChannelOptions | undefined, socket: RealtimeClient); | ||
/** Subscribe registers your client with the server */ | ||
@@ -139,0 +139,0 @@ subscribe(callback?: (status: REALTIME_SUBSCRIBE_STATES, err?: Error) => void, timeout?: number): RealtimeChannel; |
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -43,3 +53,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
REALTIME_POSTGRES_CHANGES_LISTEN_EVENT["DELETE"] = "DELETE"; | ||
})(REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = exports.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT || (exports.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = {})); | ||
})(REALTIME_POSTGRES_CHANGES_LISTEN_EVENT || (exports.REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = REALTIME_POSTGRES_CHANGES_LISTEN_EVENT = {})); | ||
var REALTIME_LISTEN_TYPES; | ||
@@ -51,3 +61,3 @@ (function (REALTIME_LISTEN_TYPES) { | ||
REALTIME_LISTEN_TYPES["SYSTEM"] = "system"; | ||
})(REALTIME_LISTEN_TYPES = exports.REALTIME_LISTEN_TYPES || (exports.REALTIME_LISTEN_TYPES = {})); | ||
})(REALTIME_LISTEN_TYPES || (exports.REALTIME_LISTEN_TYPES = REALTIME_LISTEN_TYPES = {})); | ||
var REALTIME_SUBSCRIBE_STATES; | ||
@@ -59,3 +69,3 @@ (function (REALTIME_SUBSCRIBE_STATES) { | ||
REALTIME_SUBSCRIBE_STATES["CHANNEL_ERROR"] = "CHANNEL_ERROR"; | ||
})(REALTIME_SUBSCRIBE_STATES = exports.REALTIME_SUBSCRIBE_STATES || (exports.REALTIME_SUBSCRIBE_STATES = {})); | ||
})(REALTIME_SUBSCRIBE_STATES || (exports.REALTIME_SUBSCRIBE_STATES = REALTIME_SUBSCRIBE_STATES = {})); | ||
exports.REALTIME_CHANNEL_STATES = constants_1.CHANNEL_STATES; | ||
@@ -62,0 +72,0 @@ /** A channel is the basic building block of Realtime |
@@ -0,1 +1,2 @@ | ||
import type { WebSocket as WSWebSocket } from 'ws'; | ||
import { CONNECTION_STATE } from './lib/constants'; | ||
@@ -6,4 +7,4 @@ import Serializer from './lib/serializer'; | ||
import type { RealtimeChannelOptions } from './RealtimeChannel'; | ||
declare type Fetch = typeof fetch; | ||
export declare type Channel = { | ||
type Fetch = typeof fetch; | ||
export type Channel = { | ||
name: string; | ||
@@ -14,3 +15,3 @@ inserted_at: string; | ||
}; | ||
export declare type RealtimeClientOptions = { | ||
export type RealtimeClientOptions = { | ||
transport?: WebSocketLikeConstructor; | ||
@@ -35,3 +36,3 @@ timeout?: number; | ||
}; | ||
export declare type RealtimeMessage = { | ||
export type RealtimeMessage = { | ||
topic: string; | ||
@@ -43,3 +44,3 @@ event: string; | ||
}; | ||
export declare type RealtimeRemoveChannelResponse = 'ok' | 'timed out' | 'error'; | ||
export type RealtimeRemoveChannelResponse = 'ok' | 'timed out' | 'error'; | ||
export interface WebSocketLikeConstructor { | ||
@@ -50,4 +51,3 @@ new (address: string | URL, _ignored?: any, options?: { | ||
} | ||
declare const WSWebSocket: any; | ||
export declare type WebSocketLike = WebSocket | typeof WSWebSocket | WSWebSocketDummy; | ||
export type WebSocketLike = WebSocket | WSWebSocket | WSWebSocketDummy; | ||
export interface WebSocketLikeError { | ||
@@ -54,0 +54,0 @@ error: any; |
@@ -18,9 +18,19 @@ "use strict"; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importStar = (this && this.__importStar) || (function () { | ||
var ownKeys = function(o) { | ||
ownKeys = Object.getOwnPropertyNames || function (o) { | ||
var ar = []; | ||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; | ||
return ar; | ||
}; | ||
return ownKeys(o); | ||
}; | ||
return function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -37,5 +47,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'; | ||
const WSWebSocket = NATIVE_WEBSOCKET_AVAILABLE | ||
? WebSocket | ||
: require('ws').WebSocket; | ||
const WORKER_SCRIPT = ` | ||
@@ -101,3 +108,3 @@ addEventListener("message", (e) => { | ||
else if (typeof fetch === 'undefined') { | ||
_fetch = (...args) => Promise.resolve().then(() => __importStar(require('@supabase/node-fetch'))).then(({ default: fetch }) => fetch(...args)); | ||
_fetch = (...args) => Promise.resolve(`${'@supabase/node-fetch'}`).then(s => __importStar(require(s))).then(({ default: fetch }) => fetch(...args)); | ||
} | ||
@@ -178,15 +185,13 @@ else { | ||
} | ||
else { | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null; | ||
}, | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null; | ||
}, | ||
}); | ||
Promise.resolve().then(() => __importStar(require('ws'))).then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}); | ||
Promise.resolve().then(() => __importStar(require('ws'))).then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}); | ||
this.setupConnection(); | ||
}); | ||
} | ||
this.setupConnection(); | ||
}); | ||
} | ||
@@ -314,19 +319,10 @@ /** | ||
this.accessTokenValue; | ||
if (tokenToSend) { | ||
let parsed = null; | ||
try { | ||
parsed = JSON.parse(atob(tokenToSend.split('.')[1])); | ||
} | ||
catch (_error) { } | ||
if (parsed && parsed.exp) { | ||
let now = Math.floor(Date.now() / 1000); | ||
let valid = now - parsed.exp < 0; | ||
if (!valid) { | ||
this.log('auth', `InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}`); | ||
return Promise.reject(`InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}`); | ||
} | ||
} | ||
if (this.accessTokenValue != tokenToSend) { | ||
this.accessTokenValue = tokenToSend; | ||
this.channels.forEach((channel) => { | ||
tokenToSend && channel.updateJoinPayload({ access_token: tokenToSend }); | ||
tokenToSend && | ||
channel.updateJoinPayload({ | ||
access_token: tokenToSend, | ||
version: this.headers && this.headers['X-Client-Info'], | ||
}); | ||
if (channel.joinedOnce && channel._isJoined()) { | ||
@@ -361,3 +357,3 @@ channel._push(constants_1.CHANNEL_EVENTS.access_token, { | ||
}); | ||
this.setAuth(); | ||
await this.setAuth(); | ||
} | ||
@@ -364,0 +360,0 @@ /** |
import type { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
import type RealtimeChannel from './RealtimeChannel'; | ||
declare type Presence<T extends { | ||
type Presence<T extends { | ||
[key: string]: any; | ||
@@ -8,3 +8,3 @@ } = {}> = { | ||
} & T; | ||
export declare type RealtimePresenceState<T extends { | ||
export type RealtimePresenceState<T extends { | ||
[key: string]: any; | ||
@@ -14,3 +14,3 @@ } = {}> = { | ||
}; | ||
export declare type RealtimePresenceJoinPayload<T extends { | ||
export type RealtimePresenceJoinPayload<T extends { | ||
[key: string]: any; | ||
@@ -23,3 +23,3 @@ }> = { | ||
}; | ||
export declare type RealtimePresenceLeavePayload<T extends { | ||
export type RealtimePresenceLeavePayload<T extends { | ||
[key: string]: any; | ||
@@ -37,3 +37,3 @@ }> = { | ||
} | ||
declare type RawPresenceState = { | ||
type RawPresenceState = { | ||
[key: string]: { | ||
@@ -47,3 +47,3 @@ metas: { | ||
}; | ||
declare type RawPresenceDiff = { | ||
type RawPresenceDiff = { | ||
joins: RawPresenceState; | ||
@@ -50,0 +50,0 @@ leaves: RawPresenceState; |
@@ -13,3 +13,3 @@ "use strict"; | ||
REALTIME_PRESENCE_LISTEN_EVENTS["LEAVE"] = "leave"; | ||
})(REALTIME_PRESENCE_LISTEN_EVENTS = exports.REALTIME_PRESENCE_LISTEN_EVENTS || (exports.REALTIME_PRESENCE_LISTEN_EVENTS = {})); | ||
})(REALTIME_PRESENCE_LISTEN_EVENTS || (exports.REALTIME_PRESENCE_LISTEN_EVENTS = REALTIME_PRESENCE_LISTEN_EVENTS = {})); | ||
class RealtimePresence { | ||
@@ -16,0 +16,0 @@ /** |
@@ -5,2 +5,3 @@ export declare const DEFAULT_HEADERS: { | ||
export declare const VSN: string; | ||
export declare const VERSION = "0.0.0-automated"; | ||
export declare const DEFAULT_TIMEOUT = 10000; | ||
@@ -7,0 +8,0 @@ export declare const WS_CLOSE_NORMAL = 1000; |
import { version } from './version'; | ||
export const DEFAULT_HEADERS = { 'X-Client-Info': `realtime-js/${version}` }; | ||
export const VSN = '1.0.0'; | ||
export const VERSION = version; | ||
export const DEFAULT_TIMEOUT = 10000; | ||
@@ -5,0 +6,0 @@ export const WS_CLOSE_NORMAL = 1000; |
@@ -30,3 +30,3 @@ /** | ||
} | ||
declare type Columns = { | ||
type Columns = { | ||
name: string; | ||
@@ -37,5 +37,5 @@ type: string; | ||
}[]; | ||
declare type BaseValue = null | string | number | boolean; | ||
declare type RecordValue = BaseValue | BaseValue[]; | ||
declare type Record = { | ||
type BaseValue = null | string | number | boolean; | ||
type RecordValue = BaseValue | BaseValue[]; | ||
type Record = { | ||
[key: string]: RecordValue; | ||
@@ -42,0 +42,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.11.4-next.1"; | ||
export declare const version = "2.11.4"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export const version = '2.11.4-next.1'; | ||
export const version = '2.11.4'; | ||
//# sourceMappingURL=version.js.map |
@@ -7,3 +7,3 @@ import { CHANNEL_STATES } from './lib/constants'; | ||
import type { RealtimePresenceJoinPayload, RealtimePresenceLeavePayload, RealtimePresenceState } from './RealtimePresence'; | ||
export declare type RealtimeChannelOptions = { | ||
export type RealtimeChannelOptions = { | ||
config: { | ||
@@ -30,3 +30,3 @@ /** | ||
}; | ||
declare type RealtimePostgresChangesPayloadBase = { | ||
type RealtimePostgresChangesPayloadBase = { | ||
schema: string; | ||
@@ -37,3 +37,3 @@ table: string; | ||
}; | ||
export declare type RealtimePostgresInsertPayload<T extends { | ||
export type RealtimePostgresInsertPayload<T extends { | ||
[key: string]: any; | ||
@@ -45,3 +45,3 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresUpdatePayload<T extends { | ||
export type RealtimePostgresUpdatePayload<T extends { | ||
[key: string]: any; | ||
@@ -53,3 +53,3 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresDeletePayload<T extends { | ||
export type RealtimePostgresDeletePayload<T extends { | ||
[key: string]: any; | ||
@@ -61,6 +61,6 @@ }> = RealtimePostgresChangesPayloadBase & { | ||
}; | ||
export declare type RealtimePostgresChangesPayload<T extends { | ||
export type RealtimePostgresChangesPayload<T extends { | ||
[key: string]: any; | ||
}> = RealtimePostgresInsertPayload<T> | RealtimePostgresUpdatePayload<T> | RealtimePostgresDeletePayload<T>; | ||
export declare type RealtimePostgresChangesFilter<T extends `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`> = { | ||
export type RealtimePostgresChangesFilter<T extends `${REALTIME_POSTGRES_CHANGES_LISTEN_EVENT}`> = { | ||
/** | ||
@@ -83,3 +83,3 @@ * The type of database change to listen to. | ||
}; | ||
export declare type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'error'; | ||
export type RealtimeChannelSendResponse = 'ok' | 'timed out' | 'error'; | ||
export declare enum REALTIME_POSTGRES_CHANGES_LISTEN_EVENT { | ||
@@ -136,3 +136,3 @@ ALL = "*", | ||
/** Topic name can be any string. */ | ||
topic: string, params: RealtimeChannelOptions, socket: RealtimeClient); | ||
topic: string, params: RealtimeChannelOptions | undefined, socket: RealtimeClient); | ||
/** Subscribe registers your client with the server */ | ||
@@ -139,0 +139,0 @@ subscribe(callback?: (status: REALTIME_SUBSCRIBE_STATES, err?: Error) => void, timeout?: number): RealtimeChannel; |
@@ -0,1 +1,2 @@ | ||
import type { WebSocket as WSWebSocket } from 'ws'; | ||
import { CONNECTION_STATE } from './lib/constants'; | ||
@@ -6,4 +7,4 @@ import Serializer from './lib/serializer'; | ||
import type { RealtimeChannelOptions } from './RealtimeChannel'; | ||
declare type Fetch = typeof fetch; | ||
export declare type Channel = { | ||
type Fetch = typeof fetch; | ||
export type Channel = { | ||
name: string; | ||
@@ -14,3 +15,3 @@ inserted_at: string; | ||
}; | ||
export declare type RealtimeClientOptions = { | ||
export type RealtimeClientOptions = { | ||
transport?: WebSocketLikeConstructor; | ||
@@ -35,3 +36,3 @@ timeout?: number; | ||
}; | ||
export declare type RealtimeMessage = { | ||
export type RealtimeMessage = { | ||
topic: string; | ||
@@ -43,3 +44,3 @@ event: string; | ||
}; | ||
export declare type RealtimeRemoveChannelResponse = 'ok' | 'timed out' | 'error'; | ||
export type RealtimeRemoveChannelResponse = 'ok' | 'timed out' | 'error'; | ||
export interface WebSocketLikeConstructor { | ||
@@ -50,4 +51,3 @@ new (address: string | URL, _ignored?: any, options?: { | ||
} | ||
declare const WSWebSocket: any; | ||
export declare type WebSocketLike = WebSocket | typeof WSWebSocket | WSWebSocketDummy; | ||
export type WebSocketLike = WebSocket | WSWebSocket | WSWebSocketDummy; | ||
export interface WebSocketLikeError { | ||
@@ -54,0 +54,0 @@ error: any; |
@@ -8,5 +8,2 @@ import { CHANNEL_EVENTS, CONNECTION_STATE, DEFAULT_HEADERS, DEFAULT_TIMEOUT, SOCKET_STATES, TRANSPORTS, VSN, WS_CLOSE_NORMAL, } from './lib/constants'; | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'; | ||
const WSWebSocket = NATIVE_WEBSOCKET_AVAILABLE | ||
? WebSocket | ||
: require('ws').WebSocket; | ||
const WORKER_SCRIPT = ` | ||
@@ -148,15 +145,13 @@ addEventListener("message", (e) => { | ||
} | ||
else { | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null; | ||
}, | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null; | ||
}, | ||
}); | ||
import('ws').then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}); | ||
import('ws').then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}); | ||
this.setupConnection(); | ||
}); | ||
} | ||
this.setupConnection(); | ||
}); | ||
} | ||
@@ -284,19 +279,10 @@ /** | ||
this.accessTokenValue; | ||
if (tokenToSend) { | ||
let parsed = null; | ||
try { | ||
parsed = JSON.parse(atob(tokenToSend.split('.')[1])); | ||
} | ||
catch (_error) { } | ||
if (parsed && parsed.exp) { | ||
let now = Math.floor(Date.now() / 1000); | ||
let valid = now - parsed.exp < 0; | ||
if (!valid) { | ||
this.log('auth', `InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}`); | ||
return Promise.reject(`InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}`); | ||
} | ||
} | ||
if (this.accessTokenValue != tokenToSend) { | ||
this.accessTokenValue = tokenToSend; | ||
this.channels.forEach((channel) => { | ||
tokenToSend && channel.updateJoinPayload({ access_token: tokenToSend }); | ||
tokenToSend && | ||
channel.updateJoinPayload({ | ||
access_token: tokenToSend, | ||
version: this.headers && this.headers['X-Client-Info'], | ||
}); | ||
if (channel.joinedOnce && channel._isJoined()) { | ||
@@ -331,3 +317,3 @@ channel._push(CHANNEL_EVENTS.access_token, { | ||
}); | ||
this.setAuth(); | ||
await this.setAuth(); | ||
} | ||
@@ -334,0 +320,0 @@ /** |
import type { PresenceOpts, PresenceOnJoinCallback, PresenceOnLeaveCallback } from 'phoenix'; | ||
import type RealtimeChannel from './RealtimeChannel'; | ||
declare type Presence<T extends { | ||
type Presence<T extends { | ||
[key: string]: any; | ||
@@ -8,3 +8,3 @@ } = {}> = { | ||
} & T; | ||
export declare type RealtimePresenceState<T extends { | ||
export type RealtimePresenceState<T extends { | ||
[key: string]: any; | ||
@@ -14,3 +14,3 @@ } = {}> = { | ||
}; | ||
export declare type RealtimePresenceJoinPayload<T extends { | ||
export type RealtimePresenceJoinPayload<T extends { | ||
[key: string]: any; | ||
@@ -23,3 +23,3 @@ }> = { | ||
}; | ||
export declare type RealtimePresenceLeavePayload<T extends { | ||
export type RealtimePresenceLeavePayload<T extends { | ||
[key: string]: any; | ||
@@ -37,3 +37,3 @@ }> = { | ||
} | ||
declare type RawPresenceState = { | ||
type RawPresenceState = { | ||
[key: string]: { | ||
@@ -47,3 +47,3 @@ metas: { | ||
}; | ||
declare type RawPresenceDiff = { | ||
type RawPresenceDiff = { | ||
joins: RawPresenceState; | ||
@@ -50,0 +50,0 @@ leaves: RawPresenceState; |
{ | ||
"name": "@supabase/realtime-js", | ||
"version": "2.11.4-next.1", | ||
"version": "2.11.4", | ||
"description": "Listen to realtime updates to your PostgreSQL database", | ||
@@ -42,4 +42,4 @@ "keywords": [ | ||
"@supabase/node-fetch": "^2.6.14", | ||
"@types/phoenix": "^1.5.4", | ||
"@types/ws": "^8.5.10", | ||
"@types/phoenix": "^1.6.6", | ||
"@types/ws": "^8.5.14", | ||
"ws": "^8.18.0" | ||
@@ -50,3 +50,3 @@ }, | ||
"@types/sinon": "^17.0.3", | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"@vitest/coverage-v8": "^2.1.9", | ||
"eslint": "^7.0.0", | ||
@@ -63,7 +63,7 @@ "esm": "^3.2.25", | ||
"sinon": "^18.0.0", | ||
"typedoc": "^0.22.16", | ||
"typescript": "^4.0.3", | ||
"vitest": "^2.0.5", | ||
"typedoc": "^0.27.6", | ||
"typescript": "^5.7.3", | ||
"vitest": "^2.1.9", | ||
"web-worker": "1.2.0" | ||
} | ||
} |
@@ -7,2 +7,4 @@ import { version } from './version' | ||
export const VERSION = version | ||
export const DEFAULT_TIMEOUT = 10000 | ||
@@ -9,0 +11,0 @@ |
@@ -1,1 +0,1 @@ | ||
export const version = '2.11.4-next.1' | ||
export const version = '2.11.4' |
@@ -0,1 +1,3 @@ | ||
import type { WebSocket as WSWebSocket } from 'ws' | ||
import { | ||
@@ -8,2 +10,3 @@ CHANNEL_EVENTS, | ||
TRANSPORTS, | ||
VERSION, | ||
VSN, | ||
@@ -64,10 +67,5 @@ WS_CLOSE_NORMAL, | ||
} | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined' | ||
const WSWebSocket = NATIVE_WEBSOCKET_AVAILABLE | ||
? WebSocket | ||
: require('ws').WebSocket | ||
export type WebSocketLike = WebSocket | WSWebSocket | WSWebSocketDummy | ||
export type WebSocketLike = WebSocket | typeof WSWebSocket | WSWebSocketDummy | ||
export interface WebSocketLikeError { | ||
@@ -79,2 +77,3 @@ error: any | ||
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined' | ||
const WORKER_SCRIPT = ` | ||
@@ -212,16 +211,16 @@ addEventListener("message", (e) => { | ||
return | ||
} else { | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null | ||
}, | ||
}) | ||
} | ||
import('ws').then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}) | ||
this.setupConnection() | ||
this.conn = new WSWebSocketDummy(this.endpointURL(), undefined, { | ||
close: () => { | ||
this.conn = null | ||
}, | ||
}) | ||
import('ws').then(({ default: WS }) => { | ||
this.conn = new WS(this.endpointURL(), undefined, { | ||
headers: this.headers, | ||
}) | ||
} | ||
this.setupConnection() | ||
}) | ||
} | ||
@@ -369,24 +368,10 @@ | ||
if (tokenToSend) { | ||
let parsed = null | ||
try { | ||
parsed = JSON.parse(atob(tokenToSend.split('.')[1])) | ||
} catch (_error) {} | ||
if (parsed && parsed.exp) { | ||
let now = Math.floor(Date.now() / 1000) | ||
let valid = now - parsed.exp < 0 | ||
if (!valid) { | ||
this.log( | ||
'auth', | ||
`InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}` | ||
) | ||
return Promise.reject( | ||
`InvalidJWTToken: Invalid value for JWT claim "exp" with value ${parsed.exp}` | ||
) | ||
} | ||
} | ||
if (this.accessTokenValue != tokenToSend) { | ||
this.accessTokenValue = tokenToSend | ||
this.channels.forEach((channel) => { | ||
tokenToSend && channel.updateJoinPayload({ access_token: tokenToSend }) | ||
tokenToSend && | ||
channel.updateJoinPayload({ | ||
access_token: tokenToSend, | ||
version: this.headers && this.headers['X-Client-Info'], | ||
}) | ||
@@ -424,3 +409,3 @@ if (channel.joinedOnce && channel._isJoined()) { | ||
}) | ||
this.setAuth() | ||
await this.setAuth() | ||
} | ||
@@ -427,0 +412,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
391392
0
6953
2
Updated@types/phoenix@^1.6.6
Updated@types/ws@^8.5.14