@blinkdotnew/sdk 0.18.3 → 0.18.4
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/README.md +2 -2
- package/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +44 -18
- package/dist/index.mjs +44 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
**The full-stack TypeScript SDK that powers Blink AI-generated apps**
|
|
7
7
|
|
|
8
|
-
Blink is an AI App
|
|
8
|
+
Blink is an AI App Builder that builds fully functional apps in seconds. This SDK (`@blinkdotnew/sdk`) is the TypeScript foundation that powers every Blink app natively, providing zero-boilerplate authentication, database operations, AI capabilities, and file storage. Works seamlessly on both client-side (React, Vue, etc.) and server-side (Node.js, Deno, Edge functions).
|
|
9
9
|
|
|
10
10
|
## 🚀 Quick Start
|
|
11
11
|
|
|
@@ -133,7 +133,7 @@ const { publicUrl } = await blink.storage.upload(
|
|
|
133
133
|
|
|
134
134
|
## 🤖 What is Blink?
|
|
135
135
|
|
|
136
|
-
**Blink is an AI App
|
|
136
|
+
**Blink is an AI App Builder** that creates fully functional applications in seconds. Simply describe what you want to build, and Blink's AI agent will:
|
|
137
137
|
|
|
138
138
|
- 🏗️ **Generate complete apps** with React + TypeScript + Vite
|
|
139
139
|
- 🔧 **Auto-install this SDK** with zero configuration
|
package/dist/index.d.mts
CHANGED
|
@@ -826,6 +826,14 @@ declare class BlinkAuth {
|
|
|
826
826
|
private initializationPromise;
|
|
827
827
|
private isInitialized;
|
|
828
828
|
constructor(config: BlinkClientConfig);
|
|
829
|
+
/**
|
|
830
|
+
* Generate project-scoped storage key
|
|
831
|
+
*/
|
|
832
|
+
private getStorageKey;
|
|
833
|
+
/**
|
|
834
|
+
* Migrate existing global tokens to project-scoped storage
|
|
835
|
+
*/
|
|
836
|
+
private migrateExistingTokens;
|
|
829
837
|
/**
|
|
830
838
|
* Wait for authentication initialization to complete
|
|
831
839
|
*/
|
|
@@ -1238,6 +1246,10 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
|
|
|
1238
1246
|
private utmParams;
|
|
1239
1247
|
private persistedAttribution;
|
|
1240
1248
|
constructor(httpClient: HttpClient, projectId: string);
|
|
1249
|
+
/**
|
|
1250
|
+
* Generate project-scoped storage key for analytics
|
|
1251
|
+
*/
|
|
1252
|
+
private getStorageKey;
|
|
1241
1253
|
/**
|
|
1242
1254
|
* Log a custom analytics event
|
|
1243
1255
|
*/
|
|
@@ -1477,7 +1489,7 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1477
1489
|
* // With options
|
|
1478
1490
|
* const { text, usage } = await blink.ai.generateText({
|
|
1479
1491
|
* prompt: "Summarize this article",
|
|
1480
|
-
* model: "gpt-
|
|
1492
|
+
* model: "gpt-4.1-mini",
|
|
1481
1493
|
* maxTokens: 150,
|
|
1482
1494
|
* temperature: 0.7
|
|
1483
1495
|
* });
|
|
@@ -1485,7 +1497,7 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1485
1497
|
* // With web search (OpenAI models only)
|
|
1486
1498
|
* const { text, sources } = await blink.ai.generateText({
|
|
1487
1499
|
* prompt: "What are the latest developments in AI?",
|
|
1488
|
-
* model: "gpt-
|
|
1500
|
+
* model: "gpt-4.1-mini",
|
|
1489
1501
|
* search: true // Enables web search
|
|
1490
1502
|
* });
|
|
1491
1503
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -826,6 +826,14 @@ declare class BlinkAuth {
|
|
|
826
826
|
private initializationPromise;
|
|
827
827
|
private isInitialized;
|
|
828
828
|
constructor(config: BlinkClientConfig);
|
|
829
|
+
/**
|
|
830
|
+
* Generate project-scoped storage key
|
|
831
|
+
*/
|
|
832
|
+
private getStorageKey;
|
|
833
|
+
/**
|
|
834
|
+
* Migrate existing global tokens to project-scoped storage
|
|
835
|
+
*/
|
|
836
|
+
private migrateExistingTokens;
|
|
829
837
|
/**
|
|
830
838
|
* Wait for authentication initialization to complete
|
|
831
839
|
*/
|
|
@@ -1238,6 +1246,10 @@ declare class BlinkAnalyticsImpl implements BlinkAnalytics {
|
|
|
1238
1246
|
private utmParams;
|
|
1239
1247
|
private persistedAttribution;
|
|
1240
1248
|
constructor(httpClient: HttpClient, projectId: string);
|
|
1249
|
+
/**
|
|
1250
|
+
* Generate project-scoped storage key for analytics
|
|
1251
|
+
*/
|
|
1252
|
+
private getStorageKey;
|
|
1241
1253
|
/**
|
|
1242
1254
|
* Log a custom analytics event
|
|
1243
1255
|
*/
|
|
@@ -1477,7 +1489,7 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1477
1489
|
* // With options
|
|
1478
1490
|
* const { text, usage } = await blink.ai.generateText({
|
|
1479
1491
|
* prompt: "Summarize this article",
|
|
1480
|
-
* model: "gpt-
|
|
1492
|
+
* model: "gpt-4.1-mini",
|
|
1481
1493
|
* maxTokens: 150,
|
|
1482
1494
|
* temperature: 0.7
|
|
1483
1495
|
* });
|
|
@@ -1485,7 +1497,7 @@ declare class BlinkAIImpl implements BlinkAI {
|
|
|
1485
1497
|
* // With web search (OpenAI models only)
|
|
1486
1498
|
* const { text, sources } = await blink.ai.generateText({
|
|
1487
1499
|
* prompt: "What are the latest developments in AI?",
|
|
1488
|
-
* model: "gpt-
|
|
1500
|
+
* model: "gpt-4.1-mini",
|
|
1489
1501
|
* search: true // Enables web search
|
|
1490
1502
|
* });
|
|
1491
1503
|
*
|
package/dist/index.js
CHANGED
|
@@ -916,6 +916,9 @@ var BlinkAuth = class {
|
|
|
916
916
|
isInitialized = false;
|
|
917
917
|
constructor(config) {
|
|
918
918
|
this.config = config;
|
|
919
|
+
if (!config.projectId) {
|
|
920
|
+
throw new Error("projectId is required for authentication");
|
|
921
|
+
}
|
|
919
922
|
this.authConfig = {
|
|
920
923
|
mode: "managed",
|
|
921
924
|
// Default mode
|
|
@@ -946,6 +949,25 @@ var BlinkAuth = class {
|
|
|
946
949
|
this.isInitialized = true;
|
|
947
950
|
}
|
|
948
951
|
}
|
|
952
|
+
/**
|
|
953
|
+
* Generate project-scoped storage key
|
|
954
|
+
*/
|
|
955
|
+
getStorageKey(suffix) {
|
|
956
|
+
return `blink_${suffix}_${this.config.projectId}`;
|
|
957
|
+
}
|
|
958
|
+
/**
|
|
959
|
+
* Migrate existing global tokens to project-scoped storage
|
|
960
|
+
*/
|
|
961
|
+
migrateExistingTokens() {
|
|
962
|
+
if (typeof window === "undefined") return;
|
|
963
|
+
const oldTokens = localStorage.getItem("blink_tokens");
|
|
964
|
+
const projectKey = this.getStorageKey("tokens");
|
|
965
|
+
if (oldTokens && !localStorage.getItem(projectKey)) {
|
|
966
|
+
localStorage.setItem(projectKey, oldTokens);
|
|
967
|
+
localStorage.removeItem("blink_tokens");
|
|
968
|
+
console.log(`\u2705 Migrated tokens to project scope: ${this.config.projectId}`);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
949
971
|
/**
|
|
950
972
|
* Wait for authentication initialization to complete
|
|
951
973
|
*/
|
|
@@ -996,6 +1018,7 @@ var BlinkAuth = class {
|
|
|
996
1018
|
console.log("\u{1F680} Initializing Blink Auth...");
|
|
997
1019
|
this.setLoading(true);
|
|
998
1020
|
try {
|
|
1021
|
+
this.migrateExistingTokens();
|
|
999
1022
|
if (this.isIframe) {
|
|
1000
1023
|
console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
|
|
1001
1024
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -2068,7 +2091,7 @@ var BlinkAuth = class {
|
|
|
2068
2091
|
});
|
|
2069
2092
|
if (persist && typeof window !== "undefined") {
|
|
2070
2093
|
try {
|
|
2071
|
-
localStorage.setItem("
|
|
2094
|
+
localStorage.setItem(this.getStorageKey("tokens"), JSON.stringify(tokensWithTimestamp));
|
|
2072
2095
|
console.log("\u{1F4BE} Tokens persisted to localStorage");
|
|
2073
2096
|
} catch (error) {
|
|
2074
2097
|
console.log("\u{1F4A5} Error persisting tokens to localStorage:", error);
|
|
@@ -2119,7 +2142,7 @@ var BlinkAuth = class {
|
|
|
2119
2142
|
clearTokens() {
|
|
2120
2143
|
if (typeof window !== "undefined") {
|
|
2121
2144
|
try {
|
|
2122
|
-
localStorage.removeItem("
|
|
2145
|
+
localStorage.removeItem(this.getStorageKey("tokens"));
|
|
2123
2146
|
} catch (error) {
|
|
2124
2147
|
console.log("\u{1F4A5} Error clearing tokens from localStorage:", error);
|
|
2125
2148
|
}
|
|
@@ -2137,7 +2160,7 @@ var BlinkAuth = class {
|
|
|
2137
2160
|
return this.parentWindowTokens;
|
|
2138
2161
|
}
|
|
2139
2162
|
try {
|
|
2140
|
-
const stored = localStorage.getItem("
|
|
2163
|
+
const stored = localStorage.getItem(this.getStorageKey("tokens"));
|
|
2141
2164
|
console.log("\u{1F50D} Checking localStorage for tokens:", {
|
|
2142
2165
|
hasStoredData: !!stored,
|
|
2143
2166
|
storedLength: stored?.length || 0,
|
|
@@ -2307,7 +2330,7 @@ var BlinkAuth = class {
|
|
|
2307
2330
|
setupCrossTabSync() {
|
|
2308
2331
|
if (typeof window === "undefined") return;
|
|
2309
2332
|
window.addEventListener("storage", (e) => {
|
|
2310
|
-
if (e.key === "
|
|
2333
|
+
if (e.key === this.getStorageKey("tokens")) {
|
|
2311
2334
|
const newTokens = e.newValue ? JSON.parse(e.newValue) : null;
|
|
2312
2335
|
if (newTokens && newTokens !== this.authState.tokens) {
|
|
2313
2336
|
this.setTokens(newTokens, false).catch((error) => {
|
|
@@ -3054,7 +3077,7 @@ var BlinkAIImpl = class {
|
|
|
3054
3077
|
* // With options
|
|
3055
3078
|
* const { text, usage } = await blink.ai.generateText({
|
|
3056
3079
|
* prompt: "Summarize this article",
|
|
3057
|
-
* model: "gpt-
|
|
3080
|
+
* model: "gpt-4.1-mini",
|
|
3058
3081
|
* maxTokens: 150,
|
|
3059
3082
|
* temperature: 0.7
|
|
3060
3083
|
* });
|
|
@@ -3062,7 +3085,7 @@ var BlinkAIImpl = class {
|
|
|
3062
3085
|
* // With web search (OpenAI models only)
|
|
3063
3086
|
* const { text, sources } = await blink.ai.generateText({
|
|
3064
3087
|
* prompt: "What are the latest developments in AI?",
|
|
3065
|
-
* model: "gpt-
|
|
3088
|
+
* model: "gpt-4.1-mini",
|
|
3066
3089
|
* search: true // Enables web search
|
|
3067
3090
|
* });
|
|
3068
3091
|
*
|
|
@@ -4456,9 +4479,6 @@ var SESSION_DURATION = 30 * 60 * 1e3;
|
|
|
4456
4479
|
var MAX_BATCH_SIZE = 10;
|
|
4457
4480
|
var BATCH_TIMEOUT = 3e3;
|
|
4458
4481
|
var MAX_STRING_LENGTH = 256;
|
|
4459
|
-
var STORAGE_KEY_QUEUE = "blinkAnalyticsQueue";
|
|
4460
|
-
var STORAGE_KEY_SESSION = "blinkAnalyticsSession";
|
|
4461
|
-
var STORAGE_KEY_ATTRIBUTION = "blinkAnalyticsAttribution";
|
|
4462
4482
|
var BlinkAnalyticsImpl = class {
|
|
4463
4483
|
httpClient;
|
|
4464
4484
|
projectId;
|
|
@@ -4487,6 +4507,12 @@ var BlinkAnalyticsImpl = class {
|
|
|
4487
4507
|
this.setupRouteChangeListener();
|
|
4488
4508
|
this.setupUnloadListener();
|
|
4489
4509
|
}
|
|
4510
|
+
/**
|
|
4511
|
+
* Generate project-scoped storage key for analytics
|
|
4512
|
+
*/
|
|
4513
|
+
getStorageKey(suffix) {
|
|
4514
|
+
return `blinkAnalytics${suffix}_${this.projectId}`;
|
|
4515
|
+
}
|
|
4490
4516
|
/**
|
|
4491
4517
|
* Log a custom analytics event
|
|
4492
4518
|
*/
|
|
@@ -4543,7 +4569,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4543
4569
|
clearAttribution() {
|
|
4544
4570
|
this.persistedAttribution = {};
|
|
4545
4571
|
try {
|
|
4546
|
-
localStorage.removeItem(
|
|
4572
|
+
localStorage.removeItem(this.getStorageKey("Attribution"));
|
|
4547
4573
|
} catch {
|
|
4548
4574
|
}
|
|
4549
4575
|
}
|
|
@@ -4619,7 +4645,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4619
4645
|
}
|
|
4620
4646
|
getOrCreateSessionId() {
|
|
4621
4647
|
try {
|
|
4622
|
-
const stored = localStorage.getItem(
|
|
4648
|
+
const stored = localStorage.getItem(this.getStorageKey("Session"));
|
|
4623
4649
|
if (stored) {
|
|
4624
4650
|
const session = JSON.parse(stored);
|
|
4625
4651
|
const now = Date.now();
|
|
@@ -4627,7 +4653,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4627
4653
|
return this.createNewSession();
|
|
4628
4654
|
}
|
|
4629
4655
|
session.lastActivityAt = now;
|
|
4630
|
-
localStorage.setItem(
|
|
4656
|
+
localStorage.setItem(this.getStorageKey("Session"), JSON.stringify(session));
|
|
4631
4657
|
return session.id;
|
|
4632
4658
|
}
|
|
4633
4659
|
return this.createNewSession();
|
|
@@ -4644,14 +4670,14 @@ var BlinkAnalyticsImpl = class {
|
|
|
4644
4670
|
lastActivityAt: now
|
|
4645
4671
|
};
|
|
4646
4672
|
try {
|
|
4647
|
-
localStorage.setItem(
|
|
4673
|
+
localStorage.setItem(this.getStorageKey("Session"), JSON.stringify(session));
|
|
4648
4674
|
} catch {
|
|
4649
4675
|
}
|
|
4650
4676
|
return session.id;
|
|
4651
4677
|
}
|
|
4652
4678
|
loadQueue() {
|
|
4653
4679
|
try {
|
|
4654
|
-
const stored = localStorage.getItem(
|
|
4680
|
+
const stored = localStorage.getItem(this.getStorageKey("Queue"));
|
|
4655
4681
|
if (stored) {
|
|
4656
4682
|
this.queue = JSON.parse(stored);
|
|
4657
4683
|
if (this.queue.length > 0) {
|
|
@@ -4665,9 +4691,9 @@ var BlinkAnalyticsImpl = class {
|
|
|
4665
4691
|
persistQueue() {
|
|
4666
4692
|
try {
|
|
4667
4693
|
if (this.queue.length === 0) {
|
|
4668
|
-
localStorage.removeItem(
|
|
4694
|
+
localStorage.removeItem(this.getStorageKey("Queue"));
|
|
4669
4695
|
} else {
|
|
4670
|
-
localStorage.setItem(
|
|
4696
|
+
localStorage.setItem(this.getStorageKey("Queue"), JSON.stringify(this.queue));
|
|
4671
4697
|
}
|
|
4672
4698
|
} catch {
|
|
4673
4699
|
}
|
|
@@ -4735,7 +4761,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4735
4761
|
}
|
|
4736
4762
|
loadPersistedAttribution() {
|
|
4737
4763
|
try {
|
|
4738
|
-
const stored = localStorage.getItem(
|
|
4764
|
+
const stored = localStorage.getItem(this.getStorageKey("Attribution"));
|
|
4739
4765
|
if (stored) {
|
|
4740
4766
|
this.persistedAttribution = JSON.parse(stored);
|
|
4741
4767
|
}
|
|
@@ -4751,7 +4777,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4751
4777
|
Object.entries(this.utmParams).filter(([_, v]) => v !== null)
|
|
4752
4778
|
)
|
|
4753
4779
|
};
|
|
4754
|
-
localStorage.setItem(
|
|
4780
|
+
localStorage.setItem(this.getStorageKey("Attribution"), JSON.stringify(attribution));
|
|
4755
4781
|
this.persistedAttribution = attribution;
|
|
4756
4782
|
} catch {
|
|
4757
4783
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -914,6 +914,9 @@ var BlinkAuth = class {
|
|
|
914
914
|
isInitialized = false;
|
|
915
915
|
constructor(config) {
|
|
916
916
|
this.config = config;
|
|
917
|
+
if (!config.projectId) {
|
|
918
|
+
throw new Error("projectId is required for authentication");
|
|
919
|
+
}
|
|
917
920
|
this.authConfig = {
|
|
918
921
|
mode: "managed",
|
|
919
922
|
// Default mode
|
|
@@ -944,6 +947,25 @@ var BlinkAuth = class {
|
|
|
944
947
|
this.isInitialized = true;
|
|
945
948
|
}
|
|
946
949
|
}
|
|
950
|
+
/**
|
|
951
|
+
* Generate project-scoped storage key
|
|
952
|
+
*/
|
|
953
|
+
getStorageKey(suffix) {
|
|
954
|
+
return `blink_${suffix}_${this.config.projectId}`;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Migrate existing global tokens to project-scoped storage
|
|
958
|
+
*/
|
|
959
|
+
migrateExistingTokens() {
|
|
960
|
+
if (typeof window === "undefined") return;
|
|
961
|
+
const oldTokens = localStorage.getItem("blink_tokens");
|
|
962
|
+
const projectKey = this.getStorageKey("tokens");
|
|
963
|
+
if (oldTokens && !localStorage.getItem(projectKey)) {
|
|
964
|
+
localStorage.setItem(projectKey, oldTokens);
|
|
965
|
+
localStorage.removeItem("blink_tokens");
|
|
966
|
+
console.log(`\u2705 Migrated tokens to project scope: ${this.config.projectId}`);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
947
969
|
/**
|
|
948
970
|
* Wait for authentication initialization to complete
|
|
949
971
|
*/
|
|
@@ -994,6 +1016,7 @@ var BlinkAuth = class {
|
|
|
994
1016
|
console.log("\u{1F680} Initializing Blink Auth...");
|
|
995
1017
|
this.setLoading(true);
|
|
996
1018
|
try {
|
|
1019
|
+
this.migrateExistingTokens();
|
|
997
1020
|
if (this.isIframe) {
|
|
998
1021
|
console.log("\u{1F50D} Detected iframe environment, waiting for parent tokens...");
|
|
999
1022
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
@@ -2066,7 +2089,7 @@ var BlinkAuth = class {
|
|
|
2066
2089
|
});
|
|
2067
2090
|
if (persist && typeof window !== "undefined") {
|
|
2068
2091
|
try {
|
|
2069
|
-
localStorage.setItem("
|
|
2092
|
+
localStorage.setItem(this.getStorageKey("tokens"), JSON.stringify(tokensWithTimestamp));
|
|
2070
2093
|
console.log("\u{1F4BE} Tokens persisted to localStorage");
|
|
2071
2094
|
} catch (error) {
|
|
2072
2095
|
console.log("\u{1F4A5} Error persisting tokens to localStorage:", error);
|
|
@@ -2117,7 +2140,7 @@ var BlinkAuth = class {
|
|
|
2117
2140
|
clearTokens() {
|
|
2118
2141
|
if (typeof window !== "undefined") {
|
|
2119
2142
|
try {
|
|
2120
|
-
localStorage.removeItem("
|
|
2143
|
+
localStorage.removeItem(this.getStorageKey("tokens"));
|
|
2121
2144
|
} catch (error) {
|
|
2122
2145
|
console.log("\u{1F4A5} Error clearing tokens from localStorage:", error);
|
|
2123
2146
|
}
|
|
@@ -2135,7 +2158,7 @@ var BlinkAuth = class {
|
|
|
2135
2158
|
return this.parentWindowTokens;
|
|
2136
2159
|
}
|
|
2137
2160
|
try {
|
|
2138
|
-
const stored = localStorage.getItem("
|
|
2161
|
+
const stored = localStorage.getItem(this.getStorageKey("tokens"));
|
|
2139
2162
|
console.log("\u{1F50D} Checking localStorage for tokens:", {
|
|
2140
2163
|
hasStoredData: !!stored,
|
|
2141
2164
|
storedLength: stored?.length || 0,
|
|
@@ -2305,7 +2328,7 @@ var BlinkAuth = class {
|
|
|
2305
2328
|
setupCrossTabSync() {
|
|
2306
2329
|
if (typeof window === "undefined") return;
|
|
2307
2330
|
window.addEventListener("storage", (e) => {
|
|
2308
|
-
if (e.key === "
|
|
2331
|
+
if (e.key === this.getStorageKey("tokens")) {
|
|
2309
2332
|
const newTokens = e.newValue ? JSON.parse(e.newValue) : null;
|
|
2310
2333
|
if (newTokens && newTokens !== this.authState.tokens) {
|
|
2311
2334
|
this.setTokens(newTokens, false).catch((error) => {
|
|
@@ -3052,7 +3075,7 @@ var BlinkAIImpl = class {
|
|
|
3052
3075
|
* // With options
|
|
3053
3076
|
* const { text, usage } = await blink.ai.generateText({
|
|
3054
3077
|
* prompt: "Summarize this article",
|
|
3055
|
-
* model: "gpt-
|
|
3078
|
+
* model: "gpt-4.1-mini",
|
|
3056
3079
|
* maxTokens: 150,
|
|
3057
3080
|
* temperature: 0.7
|
|
3058
3081
|
* });
|
|
@@ -3060,7 +3083,7 @@ var BlinkAIImpl = class {
|
|
|
3060
3083
|
* // With web search (OpenAI models only)
|
|
3061
3084
|
* const { text, sources } = await blink.ai.generateText({
|
|
3062
3085
|
* prompt: "What are the latest developments in AI?",
|
|
3063
|
-
* model: "gpt-
|
|
3086
|
+
* model: "gpt-4.1-mini",
|
|
3064
3087
|
* search: true // Enables web search
|
|
3065
3088
|
* });
|
|
3066
3089
|
*
|
|
@@ -4454,9 +4477,6 @@ var SESSION_DURATION = 30 * 60 * 1e3;
|
|
|
4454
4477
|
var MAX_BATCH_SIZE = 10;
|
|
4455
4478
|
var BATCH_TIMEOUT = 3e3;
|
|
4456
4479
|
var MAX_STRING_LENGTH = 256;
|
|
4457
|
-
var STORAGE_KEY_QUEUE = "blinkAnalyticsQueue";
|
|
4458
|
-
var STORAGE_KEY_SESSION = "blinkAnalyticsSession";
|
|
4459
|
-
var STORAGE_KEY_ATTRIBUTION = "blinkAnalyticsAttribution";
|
|
4460
4480
|
var BlinkAnalyticsImpl = class {
|
|
4461
4481
|
httpClient;
|
|
4462
4482
|
projectId;
|
|
@@ -4485,6 +4505,12 @@ var BlinkAnalyticsImpl = class {
|
|
|
4485
4505
|
this.setupRouteChangeListener();
|
|
4486
4506
|
this.setupUnloadListener();
|
|
4487
4507
|
}
|
|
4508
|
+
/**
|
|
4509
|
+
* Generate project-scoped storage key for analytics
|
|
4510
|
+
*/
|
|
4511
|
+
getStorageKey(suffix) {
|
|
4512
|
+
return `blinkAnalytics${suffix}_${this.projectId}`;
|
|
4513
|
+
}
|
|
4488
4514
|
/**
|
|
4489
4515
|
* Log a custom analytics event
|
|
4490
4516
|
*/
|
|
@@ -4541,7 +4567,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4541
4567
|
clearAttribution() {
|
|
4542
4568
|
this.persistedAttribution = {};
|
|
4543
4569
|
try {
|
|
4544
|
-
localStorage.removeItem(
|
|
4570
|
+
localStorage.removeItem(this.getStorageKey("Attribution"));
|
|
4545
4571
|
} catch {
|
|
4546
4572
|
}
|
|
4547
4573
|
}
|
|
@@ -4617,7 +4643,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4617
4643
|
}
|
|
4618
4644
|
getOrCreateSessionId() {
|
|
4619
4645
|
try {
|
|
4620
|
-
const stored = localStorage.getItem(
|
|
4646
|
+
const stored = localStorage.getItem(this.getStorageKey("Session"));
|
|
4621
4647
|
if (stored) {
|
|
4622
4648
|
const session = JSON.parse(stored);
|
|
4623
4649
|
const now = Date.now();
|
|
@@ -4625,7 +4651,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4625
4651
|
return this.createNewSession();
|
|
4626
4652
|
}
|
|
4627
4653
|
session.lastActivityAt = now;
|
|
4628
|
-
localStorage.setItem(
|
|
4654
|
+
localStorage.setItem(this.getStorageKey("Session"), JSON.stringify(session));
|
|
4629
4655
|
return session.id;
|
|
4630
4656
|
}
|
|
4631
4657
|
return this.createNewSession();
|
|
@@ -4642,14 +4668,14 @@ var BlinkAnalyticsImpl = class {
|
|
|
4642
4668
|
lastActivityAt: now
|
|
4643
4669
|
};
|
|
4644
4670
|
try {
|
|
4645
|
-
localStorage.setItem(
|
|
4671
|
+
localStorage.setItem(this.getStorageKey("Session"), JSON.stringify(session));
|
|
4646
4672
|
} catch {
|
|
4647
4673
|
}
|
|
4648
4674
|
return session.id;
|
|
4649
4675
|
}
|
|
4650
4676
|
loadQueue() {
|
|
4651
4677
|
try {
|
|
4652
|
-
const stored = localStorage.getItem(
|
|
4678
|
+
const stored = localStorage.getItem(this.getStorageKey("Queue"));
|
|
4653
4679
|
if (stored) {
|
|
4654
4680
|
this.queue = JSON.parse(stored);
|
|
4655
4681
|
if (this.queue.length > 0) {
|
|
@@ -4663,9 +4689,9 @@ var BlinkAnalyticsImpl = class {
|
|
|
4663
4689
|
persistQueue() {
|
|
4664
4690
|
try {
|
|
4665
4691
|
if (this.queue.length === 0) {
|
|
4666
|
-
localStorage.removeItem(
|
|
4692
|
+
localStorage.removeItem(this.getStorageKey("Queue"));
|
|
4667
4693
|
} else {
|
|
4668
|
-
localStorage.setItem(
|
|
4694
|
+
localStorage.setItem(this.getStorageKey("Queue"), JSON.stringify(this.queue));
|
|
4669
4695
|
}
|
|
4670
4696
|
} catch {
|
|
4671
4697
|
}
|
|
@@ -4733,7 +4759,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4733
4759
|
}
|
|
4734
4760
|
loadPersistedAttribution() {
|
|
4735
4761
|
try {
|
|
4736
|
-
const stored = localStorage.getItem(
|
|
4762
|
+
const stored = localStorage.getItem(this.getStorageKey("Attribution"));
|
|
4737
4763
|
if (stored) {
|
|
4738
4764
|
this.persistedAttribution = JSON.parse(stored);
|
|
4739
4765
|
}
|
|
@@ -4749,7 +4775,7 @@ var BlinkAnalyticsImpl = class {
|
|
|
4749
4775
|
Object.entries(this.utmParams).filter(([_, v]) => v !== null)
|
|
4750
4776
|
)
|
|
4751
4777
|
};
|
|
4752
|
-
localStorage.setItem(
|
|
4778
|
+
localStorage.setItem(this.getStorageKey("Attribution"), JSON.stringify(attribution));
|
|
4753
4779
|
this.persistedAttribution = attribution;
|
|
4754
4780
|
} catch {
|
|
4755
4781
|
}
|
package/package.json
CHANGED