@atsignal/browser 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.cjs +192 -0
- package/dist/index.d.cts +47 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +166 -0
- package/dist/signal.global.js +2052 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NETHRU Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@atsignal/browser`
|
|
2
|
+
|
|
3
|
+
Browser SDK for Signal analytics with a default singleton, `newInstance()`, browser storage helpers, and plugin registration support.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @atsignal/browser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import signal from "@atsignal/browser";
|
|
15
|
+
|
|
16
|
+
await signal.init("your-api-key", {
|
|
17
|
+
persistQueue: false,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await signal.track("PageView");
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Optional browser plugins are published as separate packages. For example, install `@atsignal/browser-plugin-enrich-context` and import it before using `signal.plugins.enrichContext()`.
|
|
24
|
+
|
|
25
|
+
More SDK details live in the monorepo root README.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
BrowserCookieStorage: () => BrowserCookieStorage,
|
|
24
|
+
BrowserLocalStorage: () => BrowserLocalStorage,
|
|
25
|
+
SignalBrowserClient: () => SignalBrowserClient,
|
|
26
|
+
default: () => src_default,
|
|
27
|
+
newInstance: () => newInstance,
|
|
28
|
+
registerBrowserPlugin: () => registerBrowserPlugin
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
var import_js_core2 = require("@atsignal/js-core");
|
|
32
|
+
|
|
33
|
+
// src/plugin-registry.ts
|
|
34
|
+
var pluginRegistry = /* @__PURE__ */ Object.create(null);
|
|
35
|
+
function browserPluginRegistry() {
|
|
36
|
+
return pluginRegistry;
|
|
37
|
+
}
|
|
38
|
+
function registerBrowserPlugin(name, factory) {
|
|
39
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
40
|
+
throw new Error("Browser plugin registration requires a non-empty name");
|
|
41
|
+
}
|
|
42
|
+
if (typeof factory !== "function") {
|
|
43
|
+
throw new Error(`Browser plugin registration requires a factory for ${name}`);
|
|
44
|
+
}
|
|
45
|
+
pluginRegistry[name] = factory;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/storage.ts
|
|
49
|
+
var import_js_core = require("@atsignal/js-core");
|
|
50
|
+
function canUseDocument() {
|
|
51
|
+
return typeof document !== "undefined" && typeof document.cookie === "string";
|
|
52
|
+
}
|
|
53
|
+
var BrowserCookieStorage = class {
|
|
54
|
+
constructor(options = {}) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
this._options = {
|
|
57
|
+
path: (_a = options.path) != null ? _a : "/",
|
|
58
|
+
sameSite: (_b = options.sameSite) != null ? _b : "Lax",
|
|
59
|
+
secure: options.secure,
|
|
60
|
+
domain: options.domain,
|
|
61
|
+
maxAgeDays: options.maxAgeDays
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
get(key) {
|
|
65
|
+
if (!canUseDocument()) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const encodedKey = encodeURIComponent(key);
|
|
69
|
+
const parts = document.cookie.split(";");
|
|
70
|
+
for (const part of parts) {
|
|
71
|
+
const [name, rawValue] = part.trim().split("=");
|
|
72
|
+
if (name !== encodedKey || !rawValue) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(decodeURIComponent(rawValue));
|
|
77
|
+
} catch (e) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
set(key, value) {
|
|
84
|
+
if (!canUseDocument()) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const encodedKey = encodeURIComponent(key);
|
|
88
|
+
const encodedValue = encodeURIComponent(JSON.stringify(value));
|
|
89
|
+
const attributes = [`${encodedKey}=${encodedValue}`];
|
|
90
|
+
if (typeof this._options.maxAgeDays === "number" && Number.isFinite(this._options.maxAgeDays) && this._options.maxAgeDays > 0) {
|
|
91
|
+
attributes.push(`Max-Age=${Math.floor(this._options.maxAgeDays * 24 * 60 * 60)}`);
|
|
92
|
+
}
|
|
93
|
+
if (this._options.domain) {
|
|
94
|
+
attributes.push(`Domain=${this._options.domain}`);
|
|
95
|
+
}
|
|
96
|
+
if (this._options.path) {
|
|
97
|
+
attributes.push(`Path=${this._options.path}`);
|
|
98
|
+
}
|
|
99
|
+
if (this._options.sameSite) {
|
|
100
|
+
attributes.push(`SameSite=${this._options.sameSite}`);
|
|
101
|
+
}
|
|
102
|
+
if (this._options.secure) {
|
|
103
|
+
attributes.push("Secure");
|
|
104
|
+
}
|
|
105
|
+
document.cookie = attributes.join("; ");
|
|
106
|
+
}
|
|
107
|
+
remove(key) {
|
|
108
|
+
if (!canUseDocument()) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const encodedKey = encodeURIComponent(key);
|
|
112
|
+
const attributes = [`${encodedKey}=`, "Max-Age=0"];
|
|
113
|
+
if (this._options.domain) {
|
|
114
|
+
attributes.push(`Domain=${this._options.domain}`);
|
|
115
|
+
}
|
|
116
|
+
if (this._options.path) {
|
|
117
|
+
attributes.push(`Path=${this._options.path}`);
|
|
118
|
+
}
|
|
119
|
+
document.cookie = attributes.join("; ");
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var BrowserLocalStorage = class {
|
|
123
|
+
constructor(storage) {
|
|
124
|
+
if (storage) {
|
|
125
|
+
this._storage = storage;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (typeof localStorage === "undefined") {
|
|
129
|
+
throw new Error("localStorage is not available in this environment");
|
|
130
|
+
}
|
|
131
|
+
this._storage = localStorage;
|
|
132
|
+
}
|
|
133
|
+
get(key) {
|
|
134
|
+
try {
|
|
135
|
+
const value = this._storage.getItem(key);
|
|
136
|
+
if (!value) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
return JSON.parse(value);
|
|
140
|
+
} catch (e) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
set(key, value) {
|
|
145
|
+
try {
|
|
146
|
+
this._storage.setItem(key, JSON.stringify(value));
|
|
147
|
+
} catch (e) {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
remove(key) {
|
|
151
|
+
try {
|
|
152
|
+
this._storage.removeItem(key);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
function createDefaultBrowserIdentityStorage() {
|
|
158
|
+
return canUseDocument() ? new BrowserCookieStorage() : new import_js_core.InMemoryStorage();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/index.ts
|
|
162
|
+
var SignalBrowserClient = class extends import_js_core2.SignalClient {
|
|
163
|
+
resolveInitConfig(options) {
|
|
164
|
+
var _a, _b, _c, _d;
|
|
165
|
+
const identityStorage = (_b = (_a = options.storage) == null ? void 0 : _a.identity) != null ? _b : createDefaultBrowserIdentityStorage();
|
|
166
|
+
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
167
|
+
return {
|
|
168
|
+
...options,
|
|
169
|
+
transport: (_d = options.transport) != null ? _d : (0, import_js_core2.createFetchTransport)({ keepalive: true }),
|
|
170
|
+
storage: {
|
|
171
|
+
identity: identityStorage,
|
|
172
|
+
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
function newInstance() {
|
|
178
|
+
return new SignalBrowserClient();
|
|
179
|
+
}
|
|
180
|
+
var signal = Object.assign(new SignalBrowserClient(), {
|
|
181
|
+
newInstance,
|
|
182
|
+
plugins: browserPluginRegistry()
|
|
183
|
+
});
|
|
184
|
+
var src_default = signal;
|
|
185
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
186
|
+
0 && (module.exports = {
|
|
187
|
+
BrowserCookieStorage,
|
|
188
|
+
BrowserLocalStorage,
|
|
189
|
+
SignalBrowserClient,
|
|
190
|
+
newInstance,
|
|
191
|
+
registerBrowserPlugin
|
|
192
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig, Transport, QueueStorageInput } from '@atsignal/js-core';
|
|
2
|
+
export { ClientPlugin } from '@atsignal/js-core';
|
|
3
|
+
|
|
4
|
+
type BrowserPluginFactory = (...args: unknown[]) => ClientPlugin;
|
|
5
|
+
type BrowserPluginRegistry = Record<string, BrowserPluginFactory>;
|
|
6
|
+
declare function registerBrowserPlugin(name: string, factory: BrowserPluginFactory): void;
|
|
7
|
+
|
|
8
|
+
interface CookieStorageOptions {
|
|
9
|
+
domain?: string;
|
|
10
|
+
path?: string;
|
|
11
|
+
secure?: boolean;
|
|
12
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
13
|
+
maxAgeDays?: number;
|
|
14
|
+
}
|
|
15
|
+
declare class BrowserCookieStorage implements KeyValueStorage {
|
|
16
|
+
private _options;
|
|
17
|
+
constructor(options?: CookieStorageOptions);
|
|
18
|
+
get<T>(key: string): T | null;
|
|
19
|
+
set<T>(key: string, value: T): void;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
}
|
|
22
|
+
declare class BrowserLocalStorage implements KeyValueStorage {
|
|
23
|
+
private _storage;
|
|
24
|
+
constructor(storage?: Storage);
|
|
25
|
+
get<T>(key: string): T | null;
|
|
26
|
+
set<T>(key: string, value: T): void;
|
|
27
|
+
remove(key: string): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface SignalBrowserOptions extends Omit<ClientConfig, "storage"> {
|
|
31
|
+
transport?: Transport;
|
|
32
|
+
storage?: {
|
|
33
|
+
identity?: KeyValueStorage;
|
|
34
|
+
queue?: QueueStorageInput;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare class SignalBrowserClient extends SignalClient<SignalBrowserOptions> {
|
|
38
|
+
protected resolveInitConfig(options: SignalBrowserOptions): ClientConfig;
|
|
39
|
+
}
|
|
40
|
+
declare function newInstance(): SignalBrowserClient;
|
|
41
|
+
type SignalBrowser = SignalBrowserClient & {
|
|
42
|
+
newInstance: typeof newInstance;
|
|
43
|
+
plugins: BrowserPluginRegistry;
|
|
44
|
+
};
|
|
45
|
+
declare const signal: SignalBrowser;
|
|
46
|
+
|
|
47
|
+
export { BrowserCookieStorage, BrowserLocalStorage, type BrowserPluginRegistry, type CookieStorageOptions, type SignalBrowser, SignalBrowserClient, type SignalBrowserOptions, signal as default, newInstance, registerBrowserPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig, Transport, QueueStorageInput } from '@atsignal/js-core';
|
|
2
|
+
export { ClientPlugin } from '@atsignal/js-core';
|
|
3
|
+
|
|
4
|
+
type BrowserPluginFactory = (...args: unknown[]) => ClientPlugin;
|
|
5
|
+
type BrowserPluginRegistry = Record<string, BrowserPluginFactory>;
|
|
6
|
+
declare function registerBrowserPlugin(name: string, factory: BrowserPluginFactory): void;
|
|
7
|
+
|
|
8
|
+
interface CookieStorageOptions {
|
|
9
|
+
domain?: string;
|
|
10
|
+
path?: string;
|
|
11
|
+
secure?: boolean;
|
|
12
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
13
|
+
maxAgeDays?: number;
|
|
14
|
+
}
|
|
15
|
+
declare class BrowserCookieStorage implements KeyValueStorage {
|
|
16
|
+
private _options;
|
|
17
|
+
constructor(options?: CookieStorageOptions);
|
|
18
|
+
get<T>(key: string): T | null;
|
|
19
|
+
set<T>(key: string, value: T): void;
|
|
20
|
+
remove(key: string): void;
|
|
21
|
+
}
|
|
22
|
+
declare class BrowserLocalStorage implements KeyValueStorage {
|
|
23
|
+
private _storage;
|
|
24
|
+
constructor(storage?: Storage);
|
|
25
|
+
get<T>(key: string): T | null;
|
|
26
|
+
set<T>(key: string, value: T): void;
|
|
27
|
+
remove(key: string): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface SignalBrowserOptions extends Omit<ClientConfig, "storage"> {
|
|
31
|
+
transport?: Transport;
|
|
32
|
+
storage?: {
|
|
33
|
+
identity?: KeyValueStorage;
|
|
34
|
+
queue?: QueueStorageInput;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare class SignalBrowserClient extends SignalClient<SignalBrowserOptions> {
|
|
38
|
+
protected resolveInitConfig(options: SignalBrowserOptions): ClientConfig;
|
|
39
|
+
}
|
|
40
|
+
declare function newInstance(): SignalBrowserClient;
|
|
41
|
+
type SignalBrowser = SignalBrowserClient & {
|
|
42
|
+
newInstance: typeof newInstance;
|
|
43
|
+
plugins: BrowserPluginRegistry;
|
|
44
|
+
};
|
|
45
|
+
declare const signal: SignalBrowser;
|
|
46
|
+
|
|
47
|
+
export { BrowserCookieStorage, BrowserLocalStorage, type BrowserPluginRegistry, type CookieStorageOptions, type SignalBrowser, SignalBrowserClient, type SignalBrowserOptions, signal as default, newInstance, registerBrowserPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
SignalClient,
|
|
4
|
+
createFetchTransport
|
|
5
|
+
} from "@atsignal/js-core";
|
|
6
|
+
|
|
7
|
+
// src/plugin-registry.ts
|
|
8
|
+
var pluginRegistry = /* @__PURE__ */ Object.create(null);
|
|
9
|
+
function browserPluginRegistry() {
|
|
10
|
+
return pluginRegistry;
|
|
11
|
+
}
|
|
12
|
+
function registerBrowserPlugin(name, factory) {
|
|
13
|
+
if (typeof name !== "string" || name.length === 0) {
|
|
14
|
+
throw new Error("Browser plugin registration requires a non-empty name");
|
|
15
|
+
}
|
|
16
|
+
if (typeof factory !== "function") {
|
|
17
|
+
throw new Error(`Browser plugin registration requires a factory for ${name}`);
|
|
18
|
+
}
|
|
19
|
+
pluginRegistry[name] = factory;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/storage.ts
|
|
23
|
+
import { InMemoryStorage } from "@atsignal/js-core";
|
|
24
|
+
function canUseDocument() {
|
|
25
|
+
return typeof document !== "undefined" && typeof document.cookie === "string";
|
|
26
|
+
}
|
|
27
|
+
var BrowserCookieStorage = class {
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
this._options = {
|
|
31
|
+
path: (_a = options.path) != null ? _a : "/",
|
|
32
|
+
sameSite: (_b = options.sameSite) != null ? _b : "Lax",
|
|
33
|
+
secure: options.secure,
|
|
34
|
+
domain: options.domain,
|
|
35
|
+
maxAgeDays: options.maxAgeDays
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
get(key) {
|
|
39
|
+
if (!canUseDocument()) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const encodedKey = encodeURIComponent(key);
|
|
43
|
+
const parts = document.cookie.split(";");
|
|
44
|
+
for (const part of parts) {
|
|
45
|
+
const [name, rawValue] = part.trim().split("=");
|
|
46
|
+
if (name !== encodedKey || !rawValue) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return JSON.parse(decodeURIComponent(rawValue));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
set(key, value) {
|
|
58
|
+
if (!canUseDocument()) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const encodedKey = encodeURIComponent(key);
|
|
62
|
+
const encodedValue = encodeURIComponent(JSON.stringify(value));
|
|
63
|
+
const attributes = [`${encodedKey}=${encodedValue}`];
|
|
64
|
+
if (typeof this._options.maxAgeDays === "number" && Number.isFinite(this._options.maxAgeDays) && this._options.maxAgeDays > 0) {
|
|
65
|
+
attributes.push(`Max-Age=${Math.floor(this._options.maxAgeDays * 24 * 60 * 60)}`);
|
|
66
|
+
}
|
|
67
|
+
if (this._options.domain) {
|
|
68
|
+
attributes.push(`Domain=${this._options.domain}`);
|
|
69
|
+
}
|
|
70
|
+
if (this._options.path) {
|
|
71
|
+
attributes.push(`Path=${this._options.path}`);
|
|
72
|
+
}
|
|
73
|
+
if (this._options.sameSite) {
|
|
74
|
+
attributes.push(`SameSite=${this._options.sameSite}`);
|
|
75
|
+
}
|
|
76
|
+
if (this._options.secure) {
|
|
77
|
+
attributes.push("Secure");
|
|
78
|
+
}
|
|
79
|
+
document.cookie = attributes.join("; ");
|
|
80
|
+
}
|
|
81
|
+
remove(key) {
|
|
82
|
+
if (!canUseDocument()) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const encodedKey = encodeURIComponent(key);
|
|
86
|
+
const attributes = [`${encodedKey}=`, "Max-Age=0"];
|
|
87
|
+
if (this._options.domain) {
|
|
88
|
+
attributes.push(`Domain=${this._options.domain}`);
|
|
89
|
+
}
|
|
90
|
+
if (this._options.path) {
|
|
91
|
+
attributes.push(`Path=${this._options.path}`);
|
|
92
|
+
}
|
|
93
|
+
document.cookie = attributes.join("; ");
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var BrowserLocalStorage = class {
|
|
97
|
+
constructor(storage) {
|
|
98
|
+
if (storage) {
|
|
99
|
+
this._storage = storage;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (typeof localStorage === "undefined") {
|
|
103
|
+
throw new Error("localStorage is not available in this environment");
|
|
104
|
+
}
|
|
105
|
+
this._storage = localStorage;
|
|
106
|
+
}
|
|
107
|
+
get(key) {
|
|
108
|
+
try {
|
|
109
|
+
const value = this._storage.getItem(key);
|
|
110
|
+
if (!value) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return JSON.parse(value);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
set(key, value) {
|
|
119
|
+
try {
|
|
120
|
+
this._storage.setItem(key, JSON.stringify(value));
|
|
121
|
+
} catch (e) {
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
remove(key) {
|
|
125
|
+
try {
|
|
126
|
+
this._storage.removeItem(key);
|
|
127
|
+
} catch (e) {
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
function createDefaultBrowserIdentityStorage() {
|
|
132
|
+
return canUseDocument() ? new BrowserCookieStorage() : new InMemoryStorage();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/index.ts
|
|
136
|
+
var SignalBrowserClient = class extends SignalClient {
|
|
137
|
+
resolveInitConfig(options) {
|
|
138
|
+
var _a, _b, _c, _d;
|
|
139
|
+
const identityStorage = (_b = (_a = options.storage) == null ? void 0 : _a.identity) != null ? _b : createDefaultBrowserIdentityStorage();
|
|
140
|
+
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
141
|
+
return {
|
|
142
|
+
...options,
|
|
143
|
+
transport: (_d = options.transport) != null ? _d : createFetchTransport({ keepalive: true }),
|
|
144
|
+
storage: {
|
|
145
|
+
identity: identityStorage,
|
|
146
|
+
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
function newInstance() {
|
|
152
|
+
return new SignalBrowserClient();
|
|
153
|
+
}
|
|
154
|
+
var signal = Object.assign(new SignalBrowserClient(), {
|
|
155
|
+
newInstance,
|
|
156
|
+
plugins: browserPluginRegistry()
|
|
157
|
+
});
|
|
158
|
+
var src_default = signal;
|
|
159
|
+
export {
|
|
160
|
+
BrowserCookieStorage,
|
|
161
|
+
BrowserLocalStorage,
|
|
162
|
+
SignalBrowserClient,
|
|
163
|
+
src_default as default,
|
|
164
|
+
newInstance,
|
|
165
|
+
registerBrowserPlugin
|
|
166
|
+
};
|