@quiltt/core 3.5.6 → 3.6.1
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/CHANGELOG.md +14 -0
- package/dist/{SubscriptionLink-client-VkkcO2Yz.js → SubscriptionLink-client-DOcfhNgq.js} +74 -64
- package/dist/{index-client-D55-rzVl.js → index-client-BExxNScK.js} +1 -1
- package/dist/index.d.ts +170 -171
- package/dist/index.js +44 -44
- package/package.json +1 -1
- package/src/api/graphql/links/ActionCableLink.ts +1 -1
- package/src/api/graphql/links/AuthLink.ts +1 -1
- package/src/api/graphql/links/ErrorLink.ts +1 -1
- package/src/api/graphql/links/actioncable/README.md +1 -0
- package/src/configuration.ts +33 -19
- package/src/index.ts +2 -2
- package/src/{Storage → storage}/Local.ts +5 -5
- package/src/{Storage → storage}/Memory.ts +0 -2
- package/src/{Storage/index.ts → storage/Storage.ts} +0 -3
- package/src/storage/index.ts +3 -0
- package/src/types.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @quiltt/core
|
|
2
2
|
|
|
3
|
+
## 3.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#232](https://github.com/quiltt/quiltt-js/pull/232) [`7a119af`](https://github.com/quiltt/quiltt-js/commit/7a119af8b0ba826b8df81f5eb242c002379b4e56) Thanks [@sirwolfgang](https://github.com/sirwolfgang)! - Improve typeof checks for mobile environments
|
|
8
|
+
|
|
9
|
+
## 3.6.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#229](https://github.com/quiltt/quiltt-js/pull/229) [`f688563`](https://github.com/quiltt/quiltt-js/commit/f6885635d989fb75918cb13e449ca0eec60850fc) Thanks [@zubairaziz](https://github.com/zubairaziz)! - Fix Websockets protocol variable
|
|
14
|
+
|
|
15
|
+
- [#229](https://github.com/quiltt/quiltt-js/pull/229) [`f688563`](https://github.com/quiltt/quiltt-js/commit/f6885635d989fb75918cb13e449ca0eec60850fc) Thanks [@zubairaziz](https://github.com/zubairaziz)! - Fix Websockets protocol variable
|
|
16
|
+
|
|
3
17
|
## 3.5.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -1,66 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { ApolloLink, Observable as Observable$1 } from '@apollo/client/core/index.js';
|
|
3
3
|
import { print } from 'graphql';
|
|
4
|
-
import { c as createConsumer } from './index-client-
|
|
5
|
-
|
|
6
|
-
var name = "@quiltt/core";
|
|
7
|
-
var version$1 = "3.5.6";
|
|
8
|
-
|
|
9
|
-
const QUILTT_API_INSECURE = (()=>{
|
|
10
|
-
try {
|
|
11
|
-
return process.env.QUILTT_API_INSECURE;
|
|
12
|
-
} catch {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
})();
|
|
16
|
-
const QUILTT_API_DOMAIN = (()=>{
|
|
17
|
-
try {
|
|
18
|
-
return process.env.QUILTT_API_DOMAIN;
|
|
19
|
-
} catch {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
})();
|
|
23
|
-
const QUILTT_DEBUG = (()=>{
|
|
24
|
-
try {
|
|
25
|
-
return !!process.env.QUILTT_DEBUG || process.env.NODE_ENV !== 'production';
|
|
26
|
-
} catch {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
})();
|
|
30
|
-
const domain = QUILTT_API_DOMAIN || 'quiltt.io';
|
|
31
|
-
const protocolHttp = `http${QUILTT_API_INSECURE ? '' : 's'}`;
|
|
32
|
-
const protocolWebsockets = `ws${QUILTT_API_DOMAIN ? '' : 's'}`;
|
|
33
|
-
const debugging = QUILTT_DEBUG;
|
|
34
|
-
const version = `${name}: v${version$1}`;
|
|
35
|
-
const cdnBase = `${protocolHttp}://cdn.${domain}`;
|
|
36
|
-
const endpointAuth = `${protocolHttp}://auth.${domain}/v1/users/session`;
|
|
37
|
-
const endpointGraphQL = `${protocolHttp}://api.${domain}/v1/graphql`;
|
|
38
|
-
const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* This is designed to support singletons to share the memory states across all
|
|
42
|
-
* instance of hooks to ensure that updates only process once, by storing a value
|
|
43
|
-
* then notifying all subscribers when it's updated.
|
|
44
|
-
*/ class Observable {
|
|
45
|
-
constructor(initalState){
|
|
46
|
-
this.observers = [];
|
|
47
|
-
this.get = ()=>{
|
|
48
|
-
return this.state;
|
|
49
|
-
};
|
|
50
|
-
this.set = (nextState)=>{
|
|
51
|
-
if (this.state === nextState) return;
|
|
52
|
-
this.state = nextState;
|
|
53
|
-
this.observers.forEach((update)=>update(nextState));
|
|
54
|
-
};
|
|
55
|
-
this.subscribe = (observer)=>{
|
|
56
|
-
this.observers.push(observer);
|
|
57
|
-
};
|
|
58
|
-
this.unsubscribe = (observer)=>{
|
|
59
|
-
this.observers = this.observers.filter((update)=>update !== observer);
|
|
60
|
-
};
|
|
61
|
-
this.state = initalState;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
4
|
+
import { c as createConsumer } from './index-client-BExxNScK.js';
|
|
64
5
|
|
|
65
6
|
/**
|
|
66
7
|
* An error and type safe wrapper for localStorage.
|
|
@@ -81,7 +22,7 @@ const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
|
81
22
|
};
|
|
82
23
|
this.isDisabled = ()=>!this.isEnabled();
|
|
83
24
|
this.get = (key)=>{
|
|
84
|
-
if (typeof window === 'undefined' ||
|
|
25
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return undefined;
|
|
85
26
|
try {
|
|
86
27
|
const state = window.localStorage.getItem(`quiltt.${key}`);
|
|
87
28
|
return state ? JSON.parse(state) : state;
|
|
@@ -91,7 +32,7 @@ const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
|
91
32
|
}
|
|
92
33
|
};
|
|
93
34
|
this.set = (key, state)=>{
|
|
94
|
-
if (typeof window === 'undefined' ||
|
|
35
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return;
|
|
95
36
|
try {
|
|
96
37
|
if (state) {
|
|
97
38
|
window.localStorage.setItem(`quiltt.${key}`, JSON.stringify(state));
|
|
@@ -103,6 +44,7 @@ const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
|
103
44
|
}
|
|
104
45
|
};
|
|
105
46
|
this.remove = (key)=>{
|
|
47
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return;
|
|
106
48
|
try {
|
|
107
49
|
window.localStorage.removeItem(`quiltt.${key}`);
|
|
108
50
|
} catch (error) {
|
|
@@ -130,12 +72,37 @@ const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
|
130
72
|
});
|
|
131
73
|
}
|
|
132
74
|
};
|
|
133
|
-
if (typeof window !== 'undefined' &&
|
|
75
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener !== 'undefined') {
|
|
134
76
|
window.addEventListener('storage', this.handleStorageEvent.bind(this));
|
|
135
77
|
}
|
|
136
78
|
}
|
|
137
79
|
}
|
|
138
80
|
|
|
81
|
+
/**
|
|
82
|
+
* This is designed to support singletons to share the memory states across all
|
|
83
|
+
* instance of hooks to ensure that updates only process once, by storing a value
|
|
84
|
+
* then notifying all subscribers when it's updated.
|
|
85
|
+
*/ class Observable {
|
|
86
|
+
constructor(initalState){
|
|
87
|
+
this.observers = [];
|
|
88
|
+
this.get = ()=>{
|
|
89
|
+
return this.state;
|
|
90
|
+
};
|
|
91
|
+
this.set = (nextState)=>{
|
|
92
|
+
if (this.state === nextState) return;
|
|
93
|
+
this.state = nextState;
|
|
94
|
+
this.observers.forEach((update)=>update(nextState));
|
|
95
|
+
};
|
|
96
|
+
this.subscribe = (observer)=>{
|
|
97
|
+
this.observers.push(observer);
|
|
98
|
+
};
|
|
99
|
+
this.unsubscribe = (observer)=>{
|
|
100
|
+
this.observers = this.observers.filter((update)=>update !== observer);
|
|
101
|
+
};
|
|
102
|
+
this.state = initalState;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
139
106
|
/**
|
|
140
107
|
* This is designed to support effectively an in memory key value store singleton,
|
|
141
108
|
* similar to localstorage, but allows you to subscribe to changes within the current
|
|
@@ -236,6 +203,49 @@ const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
|
236
203
|
* basically acts like shared memory when there is no localStorage.
|
|
237
204
|
*/ const GlobalStorage = new Storage();
|
|
238
205
|
|
|
206
|
+
var name = "@quiltt/core";
|
|
207
|
+
var version$1 = "3.6.1";
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Retrieves the environment variable by key, with fallback and type conversion,
|
|
211
|
+
* supporting Node.js, Vite, and potentially other runtime environments.
|
|
212
|
+
*/ const getEnv = (key, fallback = undefined)=>{
|
|
213
|
+
try {
|
|
214
|
+
let value;
|
|
215
|
+
// Check if running under Node.js and use process.env
|
|
216
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
217
|
+
value = process.env[key];
|
|
218
|
+
}
|
|
219
|
+
// Return the value after type conversion if necessary or use fallback
|
|
220
|
+
if (value === undefined || value === null) {
|
|
221
|
+
return fallback;
|
|
222
|
+
}
|
|
223
|
+
// Convert to boolean if the value is 'true' or 'false'
|
|
224
|
+
if (value === 'true' || value === 'false') {
|
|
225
|
+
return value === 'true';
|
|
226
|
+
}
|
|
227
|
+
// Convert to number if it's numeric
|
|
228
|
+
if (!isNaN(Number(value))) {
|
|
229
|
+
return Number(value);
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
const QUILTT_API_INSECURE = getEnv('QUILTT_API_INSECURE', false);
|
|
237
|
+
const QUILTT_API_DOMAIN = getEnv('QUILTT_API_DOMAIN', 'quiltt.io');
|
|
238
|
+
const QUILTT_DEBUG = getEnv('QUILTT_DEBUG', process?.env?.NODE_ENV !== 'production');
|
|
239
|
+
const domain = QUILTT_API_DOMAIN || 'quiltt.io';
|
|
240
|
+
const protocolHttp = `http${QUILTT_API_INSECURE ? '' : 's'}`;
|
|
241
|
+
const protocolWebsockets = `ws${QUILTT_API_INSECURE ? '' : 's'}`;
|
|
242
|
+
const debugging = QUILTT_DEBUG;
|
|
243
|
+
const version = `${name}: v${version$1}`;
|
|
244
|
+
const cdnBase = `${protocolHttp}://cdn.${domain}`;
|
|
245
|
+
const endpointAuth = `${protocolHttp}://auth.${domain}/v1/users/session`;
|
|
246
|
+
const endpointGraphQL = `${protocolHttp}://api.${domain}/v1/graphql`;
|
|
247
|
+
const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
|
|
248
|
+
|
|
239
249
|
class ActionCableLink extends ApolloLink {
|
|
240
250
|
constructor(options){
|
|
241
251
|
super();
|
|
@@ -297,4 +307,4 @@ class SubscriptionLink extends ActionCableLink {
|
|
|
297
307
|
}
|
|
298
308
|
}
|
|
299
309
|
|
|
300
|
-
export { GlobalStorage as G, LocalStorage as L, MemoryStorage as M, Observable as O, SubscriptionLink as S, endpointAuth as a,
|
|
310
|
+
export { GlobalStorage as G, LocalStorage as L, MemoryStorage as M, Observable as O, SubscriptionLink as S, endpointAuth as a, Storage as b, cdnBase as c, debugging as d, endpointGraphQL as e, endpointWebsockets as f, getEnv as g, version as v };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Dispatch, SetStateAction } from 'react';
|
|
2
1
|
import { ApolloLink, Operation, NextLink, Observable as Observable$1, FetchResult, ApolloClientOptions, ApolloClient } from '@apollo/client/index.js';
|
|
3
2
|
export { ApolloError, InMemoryCache, NormalizedCacheObject, OperationVariables, gql, useMutation, useQuery, useSubscription } from '@apollo/client/index.js';
|
|
4
3
|
import { BatchHttpLink as BatchHttpLink$1 } from '@apollo/client/link/batch-http/index.js';
|
|
@@ -6,175 +5,7 @@ import * as _apollo_client from '@apollo/client';
|
|
|
6
5
|
import { HttpLink as HttpLink$1 } from '@apollo/client/link/http/index.js';
|
|
7
6
|
import { RetryLink as RetryLink$1 } from '@apollo/client/link/retry/index.js';
|
|
8
7
|
import { ApolloLink as ApolloLink$1, Operation as Operation$1, NextLink as NextLink$1, Observable as Observable$2, FetchResult as FetchResult$1 } from '@apollo/client/core/index.js';
|
|
9
|
-
|
|
10
|
-
declare const debugging: boolean;
|
|
11
|
-
declare const version: string;
|
|
12
|
-
declare const cdnBase: string;
|
|
13
|
-
declare const endpointAuth: string;
|
|
14
|
-
declare const endpointGraphQL: string;
|
|
15
|
-
declare const endpointWebsockets: string;
|
|
16
|
-
|
|
17
|
-
/** Utility types to extend default TS utilities */
|
|
18
|
-
type Maybe<T> = T | null;
|
|
19
|
-
type InputMaybe<T> = Maybe<T>;
|
|
20
|
-
type Exact<T extends {
|
|
21
|
-
[key: string]: unknown;
|
|
22
|
-
}> = {
|
|
23
|
-
[K in keyof T]: T[K];
|
|
24
|
-
};
|
|
25
|
-
type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
26
|
-
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
27
|
-
};
|
|
28
|
-
type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
29
|
-
[SubKey in K]: Maybe<T[SubKey]>;
|
|
30
|
-
};
|
|
31
|
-
type Nullable<T> = {
|
|
32
|
-
[K in keyof T]: T[K] | null;
|
|
33
|
-
};
|
|
34
|
-
type Mutable<Type> = {
|
|
35
|
-
-readonly [Key in keyof Type]: Type[Key];
|
|
36
|
-
};
|
|
37
|
-
type DeepPartial<T> = T extends object ? {
|
|
38
|
-
[P in keyof T]?: DeepPartial<T[P]>;
|
|
39
|
-
} : T;
|
|
40
|
-
type DeepReadonly<T> = T extends object ? {
|
|
41
|
-
[P in keyof T]: DeepReadonly<T[P]>;
|
|
42
|
-
} : T;
|
|
43
|
-
declare global {
|
|
44
|
-
interface Window {
|
|
45
|
-
expo: any;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type JsonWebToken<T> = {
|
|
50
|
-
token: string;
|
|
51
|
-
claims: Claims<T>;
|
|
52
|
-
};
|
|
53
|
-
type Claims<T> = RegisteredClaims & T;
|
|
54
|
-
type RegisteredClaims = {
|
|
55
|
-
iss: string;
|
|
56
|
-
sub: string;
|
|
57
|
-
aud: string;
|
|
58
|
-
exp: number;
|
|
59
|
-
nbf: number;
|
|
60
|
-
iat: number;
|
|
61
|
-
jti: string;
|
|
62
|
-
};
|
|
63
|
-
type PrivateClaims = {
|
|
64
|
-
oid: string;
|
|
65
|
-
eid: string;
|
|
66
|
-
cid: string;
|
|
67
|
-
aid: string;
|
|
68
|
-
ver: number;
|
|
69
|
-
};
|
|
70
|
-
type QuilttJWT = JsonWebToken<PrivateClaims>;
|
|
71
|
-
declare const JsonWebTokenParse: <T>(token: Maybe<string> | undefined) => Maybe<JsonWebToken<T>> | undefined;
|
|
72
|
-
|
|
73
|
-
type Observer<T> = Dispatch<SetStateAction<Maybe<T> | undefined>>;
|
|
74
|
-
/**
|
|
75
|
-
* This is designed to support singletons to share the memory states across all
|
|
76
|
-
* instance of hooks to ensure that updates only process once, by storing a value
|
|
77
|
-
* then notifying all subscribers when it's updated.
|
|
78
|
-
*/
|
|
79
|
-
declare class Observable<T> {
|
|
80
|
-
private state?;
|
|
81
|
-
private observers;
|
|
82
|
-
constructor(initalState?: Maybe<T>);
|
|
83
|
-
get: () => Maybe<T> | undefined;
|
|
84
|
-
set: (nextState: Maybe<T> | undefined) => void;
|
|
85
|
-
subscribe: (observer: Observer<T>) => void;
|
|
86
|
-
unsubscribe: (observer: Observer<T>) => void;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* An error and type safe wrapper for localStorage.
|
|
91
|
-
* It allows you to subscribe to changes;
|
|
92
|
-
* but localStorage changes only fire with another
|
|
93
|
-
* window updates the record.
|
|
94
|
-
*/
|
|
95
|
-
declare class LocalStorage<T> {
|
|
96
|
-
private observers;
|
|
97
|
-
constructor();
|
|
98
|
-
isEnabled: () => boolean;
|
|
99
|
-
isDisabled: () => boolean;
|
|
100
|
-
get: (key: string) => Maybe<T> | undefined;
|
|
101
|
-
set: (key: string, state: Maybe<T> | undefined) => void;
|
|
102
|
-
remove: (key: string) => void;
|
|
103
|
-
subscribe: (key: string, observer: Observer<T>) => void;
|
|
104
|
-
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
105
|
-
private handleStorageEvent;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* This is designed to support effectively an in memory key value store singleton,
|
|
110
|
-
* similar to localstorage, but allows you to subscribe to changes within the current
|
|
111
|
-
* window.
|
|
112
|
-
*/
|
|
113
|
-
declare class MemoryStorage<T> {
|
|
114
|
-
private observables;
|
|
115
|
-
get: (key: string) => Maybe<T> | undefined;
|
|
116
|
-
set: (key: string, state: Maybe<T> | undefined) => void;
|
|
117
|
-
subscribe: (key: string, observer: Observer<T>) => void;
|
|
118
|
-
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* This is wraps both local and memory storage to create a unified interface, that
|
|
123
|
-
* allows you to subscribe to all either changes made within this window, or changes
|
|
124
|
-
* made by other windows.
|
|
125
|
-
*/
|
|
126
|
-
declare class Storage<T> {
|
|
127
|
-
private memoryStore;
|
|
128
|
-
private localStore;
|
|
129
|
-
private observers;
|
|
130
|
-
private monitors;
|
|
131
|
-
/**
|
|
132
|
-
* Checks memoryStorage before falling back to localStorage.
|
|
133
|
-
*/
|
|
134
|
-
get: (key: string) => Maybe<T> | undefined;
|
|
135
|
-
/**
|
|
136
|
-
* We don't trust localStorage to always be present, so we can't rely on it to
|
|
137
|
-
* update memoryStorage based on emitted changes. So we manage our own
|
|
138
|
-
* emitting while using the underlying events to keep memoryStore in sync with
|
|
139
|
-
* localStore.
|
|
140
|
-
*/
|
|
141
|
-
set: (key: string, newState: Maybe<T> | undefined) => void;
|
|
142
|
-
/**
|
|
143
|
-
* Allows you to subscribe to all changes in memory or local storage as a
|
|
144
|
-
* single event.
|
|
145
|
-
*/
|
|
146
|
-
subscribe: (key: string, observer: Observer<T>) => void;
|
|
147
|
-
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
148
|
-
/**
|
|
149
|
-
* Sets bubble the changes down the stack starting with memoryStore and then
|
|
150
|
-
* localStore. memoryStore will emit changes to everything within the current
|
|
151
|
-
* window context, while localStore will emit changes to every other window
|
|
152
|
-
* context.
|
|
153
|
-
*
|
|
154
|
-
* To ensure that the other windows are updated correctly, changes to localStore
|
|
155
|
-
* need to be subscribed and updated to in memory store, which then may be subscribed
|
|
156
|
-
* to outside of storage.
|
|
157
|
-
*/
|
|
158
|
-
private monitorLocalStorageChanges;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* This is an singleton to share the memory states across all instances; This
|
|
163
|
-
* basically acts like shared memory when there is no localStorage.
|
|
164
|
-
*/
|
|
165
|
-
declare const GlobalStorage: Storage<any>;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* This is designed to support singletons to timeouts that can broadcast
|
|
169
|
-
* to any observers, preventing race conditions with multiple timeouts.
|
|
170
|
-
*/
|
|
171
|
-
declare class Timeoutable {
|
|
172
|
-
private timeout?;
|
|
173
|
-
private observers;
|
|
174
|
-
set: (callback: () => void, delay: number | undefined) => void;
|
|
175
|
-
clear: (observer: Observer<void>) => void;
|
|
176
|
-
private broadcast;
|
|
177
|
-
}
|
|
8
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
178
9
|
|
|
179
10
|
interface CallbackManager {
|
|
180
11
|
onEvent(callback: ConnectorSDKOnEventCallback): void;
|
|
@@ -444,4 +275,172 @@ declare class AuthAPI {
|
|
|
444
275
|
private body;
|
|
445
276
|
}
|
|
446
277
|
|
|
447
|
-
|
|
278
|
+
/** Utility types to extend default TS utilities */
|
|
279
|
+
type Maybe<T> = T | null;
|
|
280
|
+
type InputMaybe<T> = Maybe<T>;
|
|
281
|
+
type Exact<T extends {
|
|
282
|
+
[key: string]: unknown;
|
|
283
|
+
}> = {
|
|
284
|
+
[K in keyof T]: T[K];
|
|
285
|
+
};
|
|
286
|
+
type MakeOptional<T, K extends keyof T> = Omit<T, K> & {
|
|
287
|
+
[SubKey in K]?: Maybe<T[SubKey]>;
|
|
288
|
+
};
|
|
289
|
+
type MakeMaybe<T, K extends keyof T> = Omit<T, K> & {
|
|
290
|
+
[SubKey in K]: Maybe<T[SubKey]>;
|
|
291
|
+
};
|
|
292
|
+
type Nullable<T> = {
|
|
293
|
+
[K in keyof T]: T[K] | null;
|
|
294
|
+
};
|
|
295
|
+
type Mutable<Type> = {
|
|
296
|
+
-readonly [Key in keyof Type]: Type[Key];
|
|
297
|
+
};
|
|
298
|
+
type DeepPartial<T> = T extends object ? {
|
|
299
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
300
|
+
} : T;
|
|
301
|
+
type DeepReadonly<T> = T extends object ? {
|
|
302
|
+
[P in keyof T]: DeepReadonly<T[P]>;
|
|
303
|
+
} : T;
|
|
304
|
+
|
|
305
|
+
type Observer<T> = Dispatch<SetStateAction<Maybe<T> | undefined>>;
|
|
306
|
+
/**
|
|
307
|
+
* This is designed to support singletons to share the memory states across all
|
|
308
|
+
* instance of hooks to ensure that updates only process once, by storing a value
|
|
309
|
+
* then notifying all subscribers when it's updated.
|
|
310
|
+
*/
|
|
311
|
+
declare class Observable<T> {
|
|
312
|
+
private state?;
|
|
313
|
+
private observers;
|
|
314
|
+
constructor(initalState?: Maybe<T>);
|
|
315
|
+
get: () => Maybe<T> | undefined;
|
|
316
|
+
set: (nextState: Maybe<T> | undefined) => void;
|
|
317
|
+
subscribe: (observer: Observer<T>) => void;
|
|
318
|
+
unsubscribe: (observer: Observer<T>) => void;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* An error and type safe wrapper for localStorage.
|
|
323
|
+
* It allows you to subscribe to changes;
|
|
324
|
+
* but localStorage changes only fire with another
|
|
325
|
+
* window updates the record.
|
|
326
|
+
*/
|
|
327
|
+
declare class LocalStorage<T> {
|
|
328
|
+
private observers;
|
|
329
|
+
constructor();
|
|
330
|
+
isEnabled: () => boolean;
|
|
331
|
+
isDisabled: () => boolean;
|
|
332
|
+
get: (key: string) => Maybe<T> | undefined;
|
|
333
|
+
set: (key: string, state: Maybe<T> | undefined) => void;
|
|
334
|
+
remove: (key: string) => void;
|
|
335
|
+
subscribe: (key: string, observer: Observer<T>) => void;
|
|
336
|
+
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
337
|
+
private handleStorageEvent;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* This is designed to support effectively an in memory key value store singleton,
|
|
342
|
+
* similar to localstorage, but allows you to subscribe to changes within the current
|
|
343
|
+
* window.
|
|
344
|
+
*/
|
|
345
|
+
declare class MemoryStorage<T> {
|
|
346
|
+
private observables;
|
|
347
|
+
get: (key: string) => Maybe<T> | undefined;
|
|
348
|
+
set: (key: string, state: Maybe<T> | undefined) => void;
|
|
349
|
+
subscribe: (key: string, observer: Observer<T>) => void;
|
|
350
|
+
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* This is wraps both local and memory storage to create a unified interface, that
|
|
355
|
+
* allows you to subscribe to all either changes made within this window, or changes
|
|
356
|
+
* made by other windows.
|
|
357
|
+
*/
|
|
358
|
+
declare class Storage<T> {
|
|
359
|
+
private memoryStore;
|
|
360
|
+
private localStore;
|
|
361
|
+
private observers;
|
|
362
|
+
private monitors;
|
|
363
|
+
/**
|
|
364
|
+
* Checks memoryStorage before falling back to localStorage.
|
|
365
|
+
*/
|
|
366
|
+
get: (key: string) => Maybe<T> | undefined;
|
|
367
|
+
/**
|
|
368
|
+
* We don't trust localStorage to always be present, so we can't rely on it to
|
|
369
|
+
* update memoryStorage based on emitted changes. So we manage our own
|
|
370
|
+
* emitting while using the underlying events to keep memoryStore in sync with
|
|
371
|
+
* localStore.
|
|
372
|
+
*/
|
|
373
|
+
set: (key: string, newState: Maybe<T> | undefined) => void;
|
|
374
|
+
/**
|
|
375
|
+
* Allows you to subscribe to all changes in memory or local storage as a
|
|
376
|
+
* single event.
|
|
377
|
+
*/
|
|
378
|
+
subscribe: (key: string, observer: Observer<T>) => void;
|
|
379
|
+
unsubscribe: (key: string, observer: Observer<T>) => void;
|
|
380
|
+
/**
|
|
381
|
+
* Sets bubble the changes down the stack starting with memoryStore and then
|
|
382
|
+
* localStore. memoryStore will emit changes to everything within the current
|
|
383
|
+
* window context, while localStore will emit changes to every other window
|
|
384
|
+
* context.
|
|
385
|
+
*
|
|
386
|
+
* To ensure that the other windows are updated correctly, changes to localStore
|
|
387
|
+
* need to be subscribed and updated to in memory store, which then may be subscribed
|
|
388
|
+
* to outside of storage.
|
|
389
|
+
*/
|
|
390
|
+
private monitorLocalStorageChanges;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* This is an singleton to share the memory states across all instances; This
|
|
394
|
+
* basically acts like shared memory when there is no localStorage.
|
|
395
|
+
*/
|
|
396
|
+
declare const GlobalStorage: Storage<any>;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Retrieves the environment variable by key, with fallback and type conversion,
|
|
400
|
+
* supporting Node.js, Vite, and potentially other runtime environments.
|
|
401
|
+
*/
|
|
402
|
+
declare const getEnv: (key: string, fallback?: any) => any;
|
|
403
|
+
declare const debugging: any;
|
|
404
|
+
declare const version: string;
|
|
405
|
+
declare const cdnBase: string;
|
|
406
|
+
declare const endpointAuth: string;
|
|
407
|
+
declare const endpointGraphQL: string;
|
|
408
|
+
declare const endpointWebsockets: string;
|
|
409
|
+
|
|
410
|
+
type JsonWebToken<T> = {
|
|
411
|
+
token: string;
|
|
412
|
+
claims: Claims<T>;
|
|
413
|
+
};
|
|
414
|
+
type Claims<T> = RegisteredClaims & T;
|
|
415
|
+
type RegisteredClaims = {
|
|
416
|
+
iss: string;
|
|
417
|
+
sub: string;
|
|
418
|
+
aud: string;
|
|
419
|
+
exp: number;
|
|
420
|
+
nbf: number;
|
|
421
|
+
iat: number;
|
|
422
|
+
jti: string;
|
|
423
|
+
};
|
|
424
|
+
type PrivateClaims = {
|
|
425
|
+
oid: string;
|
|
426
|
+
eid: string;
|
|
427
|
+
cid: string;
|
|
428
|
+
aid: string;
|
|
429
|
+
ver: number;
|
|
430
|
+
};
|
|
431
|
+
type QuilttJWT = JsonWebToken<PrivateClaims>;
|
|
432
|
+
declare const JsonWebTokenParse: <T>(token: Maybe<string> | undefined) => Maybe<JsonWebToken<T>> | undefined;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* This is designed to support singletons to timeouts that can broadcast
|
|
436
|
+
* to any observers, preventing race conditions with multiple timeouts.
|
|
437
|
+
*/
|
|
438
|
+
declare class Timeoutable {
|
|
439
|
+
private timeout?;
|
|
440
|
+
private observers;
|
|
441
|
+
set: (callback: () => void, delay: number | undefined) => void;
|
|
442
|
+
clear: (observer: Observer<void>) => void;
|
|
443
|
+
private broadcast;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, type Claims, type ConnectorSDK, type ConnectorSDKCallbackMetadata, type ConnectorSDKCallbacks, type ConnectorSDKConnectOptions, type ConnectorSDKConnector, type ConnectorSDKConnectorOptions, ConnectorSDKEventType, type ConnectorSDKOnEventCallback, type ConnectorSDKOnEventExitCallback, type ConnectorSDKOnExitAbortCallback, type ConnectorSDKOnExitErrorCallback, type ConnectorSDKOnExitSuccessCallback, type ConnectorSDKOnLoadCallback, type ConnectorSDKReconnectOptions, type DeepPartial, type DeepReadonly, ErrorLink, type Exact, ForwardableLink, GlobalStorage, HttpLink, type InputMaybe, type JsonWebToken, JsonWebTokenParse, LocalStorage, type MakeMaybe, type MakeOptional, type Maybe, MemoryStorage, type Mutable, type Nullable, Observable, type Observer, type PasscodePayload, type PrivateClaims, QuilttClient, type QuilttClientOptions, type QuilttJWT, type RegisteredClaims, RetryLink, type SessionResponse, Storage, SubscriptionLink, TerminatingLink, Timeoutable, type UnprocessableData, type UnprocessableResponse, type UsernamePayload, VersionLink, cdnBase, debugging, endpointAuth, endpointGraphQL, endpointWebsockets, getEnv, version };
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,13 @@
|
|
|
1
|
-
import { G as GlobalStorage, e as endpointGraphQL, v as version, d as debugging, S as SubscriptionLink, a as endpointAuth } from './SubscriptionLink-client-VkkcO2Yz.js';
|
|
2
|
-
export { L as LocalStorage, M as MemoryStorage, O as Observable, f as Storage, c as cdnBase, b as endpointWebsockets } from './SubscriptionLink-client-VkkcO2Yz.js';
|
|
3
1
|
import { ApolloLink, ApolloClient } from '@apollo/client/index.js';
|
|
4
2
|
export { InMemoryCache, gql, useMutation, useQuery, useSubscription } from '@apollo/client/index.js';
|
|
3
|
+
import { G as GlobalStorage, e as endpointGraphQL, v as version, d as debugging, S as SubscriptionLink, a as endpointAuth } from './SubscriptionLink-client-DOcfhNgq.js';
|
|
4
|
+
export { L as LocalStorage, M as MemoryStorage, O as Observable, b as Storage, c as cdnBase, f as endpointWebsockets, g as getEnv } from './SubscriptionLink-client-DOcfhNgq.js';
|
|
5
5
|
import { BatchHttpLink as BatchHttpLink$1 } from '@apollo/client/link/batch-http/index.js';
|
|
6
6
|
import crossfetch from 'cross-fetch';
|
|
7
7
|
import { onError } from '@apollo/client/link/error/index.js';
|
|
8
8
|
import { HttpLink as HttpLink$1 } from '@apollo/client/link/http/index.js';
|
|
9
9
|
import { RetryLink as RetryLink$1 } from '@apollo/client/link/retry/index.js';
|
|
10
10
|
|
|
11
|
-
const MATCHER = /^(?:[\w-]+\.){2}[\w-]+$/;
|
|
12
|
-
const JsonWebTokenParse = (token)=>{
|
|
13
|
-
if (typeof token === 'undefined' || token === null) return token;
|
|
14
|
-
if (!MATCHER.test(token)) {
|
|
15
|
-
console.error(`Invalid Session Token: ${token}`);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const [_header, payload, _signature] = token.split('.');
|
|
19
|
-
try {
|
|
20
|
-
return {
|
|
21
|
-
token: token,
|
|
22
|
-
claims: JSON.parse(atob(payload))
|
|
23
|
-
};
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error(`Invalid Session Token: ${error}`);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This is designed to support singletons to timeouts that can broadcast
|
|
31
|
-
* to any observers, preventing race conditions with multiple timeouts.
|
|
32
|
-
*/ class Timeoutable {
|
|
33
|
-
constructor(){
|
|
34
|
-
this.observers = [];
|
|
35
|
-
this.set = (callback, delay)=>{
|
|
36
|
-
if (this.timeout) {
|
|
37
|
-
clearTimeout(this.timeout);
|
|
38
|
-
}
|
|
39
|
-
this.observers.push(callback);
|
|
40
|
-
this.timeout = setTimeout(this.broadcast.bind(this), delay);
|
|
41
|
-
};
|
|
42
|
-
this.clear = (observer)=>{
|
|
43
|
-
this.observers = this.observers.filter((callback)=>callback !== observer);
|
|
44
|
-
};
|
|
45
|
-
// Only sends to the 1st listener, but ensures that someone is notified
|
|
46
|
-
this.broadcast = ()=>{
|
|
47
|
-
if (this.observers.length === 0) return;
|
|
48
|
-
this.observers[0](undefined);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
11
|
var ConnectorSDKEventType;
|
|
54
12
|
(function(ConnectorSDKEventType) {
|
|
55
13
|
ConnectorSDKEventType["Load"] = "loaded";
|
|
@@ -286,4 +244,46 @@ class AuthAPI {
|
|
|
286
244
|
}
|
|
287
245
|
}
|
|
288
246
|
|
|
247
|
+
const MATCHER = /^(?:[\w-]+\.){2}[\w-]+$/;
|
|
248
|
+
const JsonWebTokenParse = (token)=>{
|
|
249
|
+
if (typeof token === 'undefined' || token === null) return token;
|
|
250
|
+
if (!MATCHER.test(token)) {
|
|
251
|
+
console.error(`Invalid Session Token: ${token}`);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const [_header, payload, _signature] = token.split('.');
|
|
255
|
+
try {
|
|
256
|
+
return {
|
|
257
|
+
token: token,
|
|
258
|
+
claims: JSON.parse(atob(payload))
|
|
259
|
+
};
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error(`Invalid Session Token: ${error}`);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* This is designed to support singletons to timeouts that can broadcast
|
|
267
|
+
* to any observers, preventing race conditions with multiple timeouts.
|
|
268
|
+
*/ class Timeoutable {
|
|
269
|
+
constructor(){
|
|
270
|
+
this.observers = [];
|
|
271
|
+
this.set = (callback, delay)=>{
|
|
272
|
+
if (this.timeout) {
|
|
273
|
+
clearTimeout(this.timeout);
|
|
274
|
+
}
|
|
275
|
+
this.observers.push(callback);
|
|
276
|
+
this.timeout = setTimeout(this.broadcast.bind(this), delay);
|
|
277
|
+
};
|
|
278
|
+
this.clear = (observer)=>{
|
|
279
|
+
this.observers = this.observers.filter((callback)=>callback !== observer);
|
|
280
|
+
};
|
|
281
|
+
// Only sends to the 1st listener, but ensures that someone is notified
|
|
282
|
+
this.broadcast = ()=>{
|
|
283
|
+
if (this.observers.length === 0) return;
|
|
284
|
+
this.observers[0](undefined);
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
289
|
export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, ConnectorSDKEventType, ErrorLink, ForwardableLink, GlobalStorage, HttpLink, JsonWebTokenParse, QuilttClient, RetryLink, SubscriptionLink, TerminatingLink, Timeoutable, VersionLink, debugging, endpointAuth, endpointGraphQL, version };
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GlobalStorage } from '@/
|
|
1
|
+
import { GlobalStorage } from '@/storage'
|
|
2
2
|
import type { FetchResult, NextLink, Operation } from '@apollo/client/core/index.js'
|
|
3
3
|
import { ApolloLink, Observable } from '@apollo/client/core/index.js'
|
|
4
4
|
import { print } from 'graphql'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FetchResult, NextLink, Observable, Operation } from '@apollo/client/index.js'
|
|
2
2
|
import { ApolloLink } from '@apollo/client/index.js'
|
|
3
3
|
|
|
4
|
-
import { GlobalStorage } from '@/
|
|
4
|
+
import { GlobalStorage } from '@/storage'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* unauthorizedCallback only triggers in the event the token is present, and
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is a patched version of @rails/actioncable now that https://github.com/rails/rails/pull/47939 has been merged in and released.
|
package/src/configuration.ts
CHANGED
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
import { name as packageName, version as packageVersion } from '../package.json'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the environment variable by key, with fallback and type conversion,
|
|
5
|
+
* supporting Node.js, Vite, and potentially other runtime environments.
|
|
6
|
+
*/
|
|
7
|
+
export const getEnv = (key: string, fallback: any = undefined): any => {
|
|
4
8
|
try {
|
|
5
|
-
|
|
6
|
-
} catch {
|
|
7
|
-
return undefined
|
|
8
|
-
}
|
|
9
|
-
})()
|
|
9
|
+
let value: string | undefined
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
// Check if running under Node.js and use process.env
|
|
12
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
13
|
+
value = process.env[key]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Return the value after type conversion if necessary or use fallback
|
|
17
|
+
if (value === undefined || value === null) {
|
|
18
|
+
return fallback
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Convert to boolean if the value is 'true' or 'false'
|
|
22
|
+
if (value === 'true' || value === 'false') {
|
|
23
|
+
return value === 'true'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Convert to number if it's numeric
|
|
27
|
+
if (!isNaN(Number(value))) {
|
|
28
|
+
return Number(value)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value
|
|
32
|
+
} catch (error) {
|
|
15
33
|
return undefined
|
|
16
34
|
}
|
|
17
|
-
}
|
|
35
|
+
}
|
|
18
36
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} catch {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
})()
|
|
37
|
+
const QUILTT_API_INSECURE = getEnv('QUILTT_API_INSECURE', false)
|
|
38
|
+
const QUILTT_API_DOMAIN = getEnv('QUILTT_API_DOMAIN', 'quiltt.io')
|
|
39
|
+
const QUILTT_DEBUG = getEnv('QUILTT_DEBUG', process?.env?.NODE_ENV !== 'production')
|
|
26
40
|
|
|
27
41
|
const domain = QUILTT_API_DOMAIN || 'quiltt.io'
|
|
28
42
|
const protocolHttp = `http${QUILTT_API_INSECURE ? '' : 's'}`
|
|
29
|
-
const protocolWebsockets = `ws${
|
|
43
|
+
const protocolWebsockets = `ws${QUILTT_API_INSECURE ? '' : 's'}`
|
|
30
44
|
|
|
31
45
|
export const debugging = QUILTT_DEBUG
|
|
32
46
|
export const version = `${packageName}: v${packageVersion}`
|
package/src/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export class LocalStorage<T> {
|
|
|
11
11
|
private observers: { [key: string]: Observer<T>[] } = {}
|
|
12
12
|
|
|
13
13
|
constructor() {
|
|
14
|
-
if (typeof window !== 'undefined' &&
|
|
14
|
+
if (typeof window !== 'undefined' && typeof window.addEventListener !== 'undefined') {
|
|
15
15
|
window.addEventListener('storage', this.handleStorageEvent.bind(this))
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -29,7 +29,7 @@ export class LocalStorage<T> {
|
|
|
29
29
|
isDisabled = (): boolean => !this.isEnabled()
|
|
30
30
|
|
|
31
31
|
get = (key: string): Maybe<T> | undefined => {
|
|
32
|
-
if (typeof window === 'undefined' ||
|
|
32
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return undefined
|
|
33
33
|
|
|
34
34
|
try {
|
|
35
35
|
const state = window.localStorage.getItem(`quiltt.${key}`)
|
|
@@ -41,7 +41,7 @@ export class LocalStorage<T> {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
set = (key: string, state: Maybe<T> | undefined): void => {
|
|
44
|
-
if (typeof window === 'undefined' ||
|
|
44
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return
|
|
45
45
|
|
|
46
46
|
try {
|
|
47
47
|
if (state) {
|
|
@@ -55,6 +55,8 @@ export class LocalStorage<T> {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
remove = (key: string) => {
|
|
58
|
+
if (typeof window === 'undefined' || typeof window.localStorage === 'undefined') return
|
|
59
|
+
|
|
58
60
|
try {
|
|
59
61
|
window.localStorage.removeItem(`quiltt.${key}`)
|
|
60
62
|
} catch (error) {
|
|
@@ -88,5 +90,3 @@ export class LocalStorage<T> {
|
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
|
-
|
|
92
|
-
export default LocalStorage
|
package/src/types.ts
CHANGED
|
@@ -8,8 +8,3 @@ export type Nullable<T> = { [K in keyof T]: T[K] | null }
|
|
|
8
8
|
export type Mutable<Type> = { -readonly [Key in keyof Type]: Type[Key] }
|
|
9
9
|
export type DeepPartial<T> = T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T
|
|
10
10
|
export type DeepReadonly<T> = T extends object ? { [P in keyof T]: DeepReadonly<T[P]> } : T
|
|
11
|
-
declare global {
|
|
12
|
-
interface Window {
|
|
13
|
-
expo: any
|
|
14
|
-
}
|
|
15
|
-
}
|