@quiltt/core 3.5.3 → 3.5.5

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/SubscriptionLink-client-B5Tmyqw7.js +300 -0
  3. package/dist/index-client-BY-d8Msy.js +561 -0
  4. package/dist/index.d.ts +395 -15
  5. package/dist/index.js +248 -11
  6. package/package.json +11 -11
  7. package/src/api/graphql/links/actioncable/logger.ts +3 -1
  8. package/src/api/graphql/links/actioncable/subscription_guarantor.ts +1 -1
  9. package/dist/AuthAPI-eba95598.d.ts +0 -70
  10. package/dist/Storage/index.cjs +0 -10
  11. package/dist/Storage/index.cjs.map +0 -1
  12. package/dist/Storage/index.d.ts +0 -2
  13. package/dist/Storage/index.js +0 -5
  14. package/dist/Storage/index.js.map +0 -1
  15. package/dist/VersionLink-b7dfbaba.d.ts +0 -56
  16. package/dist/api/graphql/index.cjs +0 -49
  17. package/dist/api/graphql/index.cjs.map +0 -1
  18. package/dist/api/graphql/index.d.ts +0 -9
  19. package/dist/api/graphql/index.js +0 -15
  20. package/dist/api/graphql/index.js.map +0 -1
  21. package/dist/api/graphql/links/actioncable/index.cjs +0 -18
  22. package/dist/api/graphql/links/actioncable/index.cjs.map +0 -1
  23. package/dist/api/graphql/links/actioncable/index.d.ts +0 -62
  24. package/dist/api/graphql/links/actioncable/index.js +0 -5
  25. package/dist/api/graphql/links/actioncable/index.js.map +0 -1
  26. package/dist/api/graphql/links/index.cjs +0 -28
  27. package/dist/api/graphql/links/index.cjs.map +0 -1
  28. package/dist/api/graphql/links/index.d.ts +0 -8
  29. package/dist/api/graphql/links/index.js +0 -14
  30. package/dist/api/graphql/links/index.js.map +0 -1
  31. package/dist/api/index.cjs +0 -54
  32. package/dist/api/index.cjs.map +0 -1
  33. package/dist/api/index.d.ts +0 -12
  34. package/dist/api/index.js +0 -16
  35. package/dist/api/index.js.map +0 -1
  36. package/dist/api/rest/index.cjs +0 -14
  37. package/dist/api/rest/index.cjs.map +0 -1
  38. package/dist/api/rest/index.d.ts +0 -2
  39. package/dist/api/rest/index.js +0 -7
  40. package/dist/api/rest/index.js.map +0 -1
  41. package/dist/browser-e775a2b2.d.ts +0 -66
  42. package/dist/client-abcf98d8.d.ts +0 -8
  43. package/dist/consumer-c13efb94.d.ts +0 -78
  44. package/dist/index-f53b61b3.d.ts +0 -129
  45. package/dist/index.cjs +0 -67
  46. package/dist/index.cjs.map +0 -1
  47. package/dist/index.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @quiltt/core
2
2
 
3
+ ## 3.5.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#218](https://github.com/quiltt/quiltt-js/pull/218) [`7dd42db`](https://github.com/quiltt/quiltt-js/commit/7dd42dbc744805d68fbff8fbed73a4bd68022b44) Thanks [@tom-quiltt](https://github.com/tom-quiltt)! - Fix changeset md to release packages
8
+
9
+ - [#213](https://github.com/quiltt/quiltt-js/pull/213) [`5648e3c`](https://github.com/quiltt/quiltt-js/commit/5648e3c91d572d97ad88115710ab840b98e1d469) Thanks [@zubairaziz](https://github.com/zubairaziz)! - Add exported files to '@quiltt/react-native'"
10
+
11
+ - [#210](https://github.com/quiltt/quiltt-js/pull/210) [`e57fdb8`](https://github.com/quiltt/quiltt-js/commit/e57fdb8c21e90b6a3492bc7a0c858031384caebf) Thanks [@zubairaziz](https://github.com/zubairaziz)! - Migrate bundler to 'bunchee'
12
+
13
+ - [#215](https://github.com/quiltt/quiltt-js/pull/215) [`c36abb4`](https://github.com/quiltt/quiltt-js/commit/c36abb47cffea3d754fd243b321f2ae50518c297) Thanks [@tom-quiltt](https://github.com/tom-quiltt)! - Remove React Native SDK about:srcdoc warning
14
+
15
+ - [#216](https://github.com/quiltt/quiltt-js/pull/216) [`2895899`](https://github.com/quiltt/quiltt-js/commit/289589913c55f8dad2e818d71c4be39c93e5a52a) Thanks [@tom-quiltt](https://github.com/tom-quiltt)! - Fix release changeset command
16
+
17
+ ## 3.5.4
18
+
19
+ ### Patch Changes
20
+
21
+ - [#209](https://github.com/quiltt/quiltt-js/pull/209) [`6c5aa5f`](https://github.com/quiltt/quiltt-js/commit/6c5aa5fb0212f9dce84e71fe91e2182f463f7318) Thanks [@tom-quiltt](https://github.com/tom-quiltt)! - Expose Institutions to React Native API
22
+
3
23
  ## 3.5.3
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,300 @@
1
+ 'use client';
2
+ import { ApolloLink, Observable as Observable$1 } from '@apollo/client/core/index.js';
3
+ import { print } from 'graphql';
4
+ import { c as createConsumer } from './index-client-BY-d8Msy.js';
5
+
6
+ var name = "@quiltt/core";
7
+ var version$1 = "3.5.5";
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
+ }
64
+
65
+ /**
66
+ * An error and type safe wrapper for localStorage.
67
+ * It allows you to subscribe to changes;
68
+ * but localStorage changes only fire with another
69
+ * window updates the record.
70
+ */ class LocalStorage {
71
+ constructor(){
72
+ this.observers = {};
73
+ this.isEnabled = ()=>{
74
+ try {
75
+ localStorage.setItem(`quiltt.ping`, 'pong');
76
+ localStorage.removeItem(`quiltt.ping`);
77
+ return true;
78
+ } catch (error) {
79
+ return false;
80
+ }
81
+ };
82
+ this.isDisabled = ()=>!this.isEnabled();
83
+ this.get = (key)=>{
84
+ if (typeof window === 'undefined' || !!window.expo) return undefined;
85
+ try {
86
+ const state = window.localStorage.getItem(`quiltt.${key}`);
87
+ return state ? JSON.parse(state) : state;
88
+ } catch (error) {
89
+ console.warn(`localStorage Error: "quiltt.${key}"`, error);
90
+ return undefined;
91
+ }
92
+ };
93
+ this.set = (key, state)=>{
94
+ if (typeof window === 'undefined' || !!window.expo) return;
95
+ try {
96
+ if (state) {
97
+ window.localStorage.setItem(`quiltt.${key}`, JSON.stringify(state));
98
+ } else {
99
+ window.localStorage.removeItem(`quiltt.${key}`);
100
+ }
101
+ } catch (error) {
102
+ console.warn(`localStorage Error: "quiltt.${key}"`, error);
103
+ }
104
+ };
105
+ this.remove = (key)=>{
106
+ try {
107
+ window.localStorage.removeItem(`quiltt.${key}`);
108
+ } catch (error) {
109
+ console.warn(`localStorage Error: "quiltt.${key}">`, error);
110
+ }
111
+ };
112
+ this.subscribe = (key, observer)=>{
113
+ if (!this.observers[key]) this.observers[key] = [];
114
+ this.observers[key].push(observer);
115
+ };
116
+ this.unsubscribe = (key, observer)=>{
117
+ this.observers[key] = this.observers[key]?.filter((update)=>update !== observer);
118
+ };
119
+ // if there is a key, then trigger the related updates. If there is not key
120
+ // it means that a record has been removed and everything needs to be rechecked.
121
+ this.handleStorageEvent = (event)=>{
122
+ if (event.key && event.key.includes('quiltt.')) {
123
+ const newState = event.newValue ? JSON.parse(event.newValue) : null;
124
+ if (this.observers[event.key]) {
125
+ this.observers[event.key].forEach((update)=>update(newState));
126
+ }
127
+ } else {
128
+ Object.entries(this.observers).forEach(([key, observers])=>{
129
+ observers.forEach((update)=>update(this.get(key)));
130
+ });
131
+ }
132
+ };
133
+ if (typeof window !== 'undefined' && !window?.expo) {
134
+ window.addEventListener('storage', this.handleStorageEvent.bind(this));
135
+ }
136
+ }
137
+ }
138
+
139
+ /**
140
+ * This is designed to support effectively an in memory key value store singleton,
141
+ * similar to localstorage, but allows you to subscribe to changes within the current
142
+ * window.
143
+ */ class MemoryStorage {
144
+ constructor(){
145
+ this.observables = {};
146
+ this.get = (key)=>{
147
+ if (this.observables[key]) {
148
+ return this.observables[key].get();
149
+ } else {
150
+ return undefined;
151
+ }
152
+ };
153
+ this.set = (key, state)=>{
154
+ if (!this.observables[key]) {
155
+ this.observables[key] = new Observable(state);
156
+ } else {
157
+ this.observables[key].set(state);
158
+ }
159
+ };
160
+ this.subscribe = (key, observer)=>{
161
+ if (!this.observables[key]) this.observables[key] = new Observable();
162
+ this.observables[key].subscribe(observer);
163
+ };
164
+ this.unsubscribe = (key, observer)=>{
165
+ if (this.observables[key]) {
166
+ this.observables[key].unsubscribe(observer);
167
+ }
168
+ };
169
+ }
170
+ }
171
+
172
+ /**
173
+ * This is wraps both local and memory storage to create a unified interface, that
174
+ * allows you to subscribe to all either changes made within this window, or changes
175
+ * made by other windows.
176
+ */ class Storage {
177
+ constructor(){
178
+ this.memoryStore = new MemoryStorage();
179
+ this.localStore = new LocalStorage();
180
+ this.observers = {};
181
+ this.monitors = new Set();
182
+ /**
183
+ * Checks memoryStorage before falling back to localStorage.
184
+ */ this.get = (key)=>{
185
+ this.monitorLocalStorageChanges(key);
186
+ let state = this.memoryStore.get(key);
187
+ if (state === undefined) {
188
+ state = this.localStore.get(key);
189
+ }
190
+ return state;
191
+ };
192
+ /**
193
+ * We don't trust localStorage to always be present, so we can't rely on it to
194
+ * update memoryStorage based on emitted changes. So we manage our own
195
+ * emitting while using the underlying events to keep memoryStore in sync with
196
+ * localStore.
197
+ */ this.set = (key, newState)=>{
198
+ this.monitorLocalStorageChanges(key);
199
+ this.localStore.set(key, newState);
200
+ this.memoryStore.set(key, newState);
201
+ this.observers[key]?.forEach((update)=>update(newState));
202
+ };
203
+ /**
204
+ * Allows you to subscribe to all changes in memory or local storage as a
205
+ * single event.
206
+ */ this.subscribe = (key, observer)=>{
207
+ if (!this.observers[key]) this.observers[key] = [];
208
+ this.observers[key].push(observer);
209
+ };
210
+ this.unsubscribe = (key, observer)=>{
211
+ this.observers[key] = this.observers[key]?.filter((update)=>update !== observer);
212
+ };
213
+ /**
214
+ * Sets bubble the changes down the stack starting with memoryStore and then
215
+ * localStore. memoryStore will emit changes to everything within the current
216
+ * window context, while localStore will emit changes to every other window
217
+ * context.
218
+ *
219
+ * To ensure that the other windows are updated correctly, changes to localStore
220
+ * need to be subscribed and updated to in memory store, which then may be subscribed
221
+ * to outside of storage.
222
+ */ this.monitorLocalStorageChanges = (key)=>{
223
+ if (this.monitors.has(key)) return;
224
+ this.monitors.add(key);
225
+ this.localStore.subscribe(key, (nextState)=>{
226
+ const prevValue = this.memoryStore.get(key);
227
+ const newState = nextState instanceof Function ? nextState(prevValue) : nextState;
228
+ this.memoryStore.set(key, newState);
229
+ this.observers[key]?.forEach((update)=>update(newState));
230
+ });
231
+ };
232
+ }
233
+ }
234
+ /**
235
+ * This is an singleton to share the memory states across all instances; This
236
+ * basically acts like shared memory when there is no localStorage.
237
+ */ const GlobalStorage = new Storage();
238
+
239
+ class ActionCableLink extends ApolloLink {
240
+ constructor(options){
241
+ super();
242
+ this.cables = {};
243
+ this.channelName = options.channelName || 'GraphqlChannel';
244
+ this.actionName = options.actionName || 'execute';
245
+ this.connectionParams = options.connectionParams || {};
246
+ }
247
+ // Interestingly, this link does _not_ call through to `next` because
248
+ // instead, it sends the request to ActionCable.
249
+ request(operation, _next) {
250
+ const token = GlobalStorage.get('session');
251
+ if (!token) {
252
+ console.warn(`QuilttClient attempted to send an unauthenticated Subscription`);
253
+ return null;
254
+ }
255
+ if (!this.cables[token]) {
256
+ this.cables[token] = createConsumer(endpointWebsockets + (token ? `?token=${token}` : ''));
257
+ }
258
+ return new Observable$1((observer)=>{
259
+ const channelId = Math.round(Date.now() + Math.random() * 100000).toString(16);
260
+ const actionName = this.actionName;
261
+ const connectionParams = typeof this.connectionParams === 'function' ? this.connectionParams(operation) : this.connectionParams;
262
+ const channel = this.cables[token].subscriptions.create(Object.assign({}, {
263
+ channel: this.channelName,
264
+ channelId: channelId
265
+ }, connectionParams), {
266
+ connected: ()=>{
267
+ channel.perform(actionName, {
268
+ query: operation.query ? print(operation.query) : null,
269
+ variables: operation.variables,
270
+ // This is added for persisted operation support:
271
+ operationId: operation.operationId,
272
+ operationName: operation.operationName
273
+ });
274
+ },
275
+ received: (payload)=>{
276
+ if (payload?.result?.data || payload?.result?.errors) {
277
+ observer.next(payload.result);
278
+ }
279
+ if (!payload.more) {
280
+ observer.complete();
281
+ }
282
+ }
283
+ });
284
+ // Make the ActionCable subscription behave like an Apollo subscription
285
+ return Object.assign(channel, {
286
+ closed: false
287
+ });
288
+ });
289
+ }
290
+ }
291
+
292
+ class SubscriptionLink extends ActionCableLink {
293
+ constructor(){
294
+ super({
295
+ channelName: 'GraphQLChannel'
296
+ });
297
+ }
298
+ }
299
+
300
+ export { GlobalStorage as G, LocalStorage as L, MemoryStorage as M, Observable as O, SubscriptionLink as S, endpointAuth as a, endpointWebsockets as b, cdnBase as c, debugging as d, endpointGraphQL as e, Storage as f, version as v };