@quiltt/core 5.0.0 → 5.0.2
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 +20 -0
- package/README.md +19 -12
- package/dist/api/browser.cjs +14 -0
- package/dist/api/browser.d.ts +128 -0
- package/dist/api/browser.js +12 -0
- package/dist/api/graphql/SubscriptionLink-12s-ufJBKwu1.js +149 -0
- package/dist/api/graphql/SubscriptionLink-12s-wjkChfxO.cjs +150 -0
- package/dist/api/graphql/index.cjs +218 -0
- package/dist/api/graphql/index.d.ts +82 -0
- package/dist/api/graphql/index.js +184 -0
- package/dist/api/index.cjs +26 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/rest/index.cjs +225 -0
- package/dist/api/rest/index.d.ts +128 -0
- package/dist/api/rest/index.js +217 -0
- package/dist/auth/index.cjs +21 -0
- package/dist/auth/index.d.ts +29 -0
- package/dist/auth/index.js +19 -0
- package/dist/config/index.cjs +44 -0
- package/dist/config/index.d.ts +9 -0
- package/dist/config/index.js +36 -0
- package/dist/index.cjs +61 -0
- package/dist/index.d.ts +8 -524
- package/dist/index.js +8 -449
- package/dist/observables/index.cjs +30 -0
- package/dist/observables/index.d.ts +21 -0
- package/dist/observables/index.js +28 -0
- package/dist/storage/index.cjs +272 -0
- package/dist/storage/index.d.ts +91 -0
- package/dist/{SubscriptionLink-12s-C2VbF8Tf.js → storage/index.js} +2 -139
- package/dist/timing/index.cjs +30 -0
- package/dist/timing/index.d.ts +15 -0
- package/dist/timing/index.js +28 -0
- package/dist/types.cjs +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.js +1 -0
- package/dist/utils/index.cjs +61 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +57 -0
- package/package.json +62 -6
- package/src/api/graphql/client.ts +1 -1
- package/src/api/graphql/links/ActionCableLink.ts +7 -6
- package/src/api/graphql/links/AuthLink.ts +13 -9
- package/src/api/graphql/links/BatchHttpLink.ts +1 -1
- package/src/api/graphql/links/ErrorLink.ts +4 -0
- package/src/api/graphql/links/HttpLink.ts +1 -1
- package/src/api/graphql/links/VersionLink.ts +1 -1
- package/src/api/rest/auth.ts +1 -1
- package/src/api/rest/connectors.ts +1 -1
- package/src/auth/index.ts +1 -0
- package/src/{JsonWebToken.ts → auth/json-web-token.ts} +1 -1
- package/src/{configuration.ts → config/configuration.ts} +1 -1
- package/src/config/index.ts +1 -0
- package/src/index.ts +5 -5
- package/src/observables/index.ts +1 -0
- package/src/{Observable.ts → observables/observable.ts} +1 -1
- package/src/storage/Local.ts +1 -1
- package/src/storage/Memory.ts +2 -2
- package/src/storage/Storage.ts +1 -1
- package/src/timing/index.ts +1 -0
- package/src/{Timeoutable.ts → timing/timeoutable.ts} +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/token-validation.ts +67 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
var core = require('@apollo/client/core');
|
|
4
|
+
var index_cjs = require('../../config/index.cjs');
|
|
5
|
+
var rxjs = require('rxjs');
|
|
6
|
+
var SubscriptionLink12s = require('./SubscriptionLink-12s-wjkChfxO.cjs');
|
|
7
|
+
var batchHttp = require('@apollo/client/link/batch-http');
|
|
8
|
+
var crossfetch = require('cross-fetch');
|
|
9
|
+
var error = require('@apollo/client/link/error');
|
|
10
|
+
var index_cjs$1 = require('../../storage/index.cjs');
|
|
11
|
+
var http = require('@apollo/client/link/http');
|
|
12
|
+
var retry = require('@apollo/client/link/retry');
|
|
13
|
+
var cache = require('@apollo/client/cache');
|
|
14
|
+
var react = require('@apollo/client/react');
|
|
15
|
+
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
var crossfetch__default = /*#__PURE__*/_interopDefault(crossfetch);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Apollo Link that handles authentication and session expiration for GraphQL requests.
|
|
22
|
+
*
|
|
23
|
+
* Features:
|
|
24
|
+
* - Automatically adds Bearer token to request headers
|
|
25
|
+
* - Detects expired tokens and triggers proper error handling
|
|
26
|
+
* - Clears expired sessions from storage (triggers React re-renders via observers)
|
|
27
|
+
* - Emits GraphQL errors for consistent Apollo error handling
|
|
28
|
+
*/ class AuthLink extends core.ApolloLink {
|
|
29
|
+
request(operation, forward) {
|
|
30
|
+
const validation = SubscriptionLink12s.validateSessionToken();
|
|
31
|
+
if (!validation.valid) {
|
|
32
|
+
return new rxjs.Observable((observer)=>{
|
|
33
|
+
observer.error(validation.error);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const { token } = validation;
|
|
37
|
+
operation.setContext(({ headers = {} })=>({
|
|
38
|
+
headers: {
|
|
39
|
+
...headers,
|
|
40
|
+
authorization: `Bearer ${token}`
|
|
41
|
+
}
|
|
42
|
+
}));
|
|
43
|
+
return forward(operation);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Use `cross-fetch` only if `fetch` is not available on the `globalThis` object
|
|
48
|
+
const effectiveFetch$1 = typeof fetch === 'undefined' ? crossfetch__default.default : fetch;
|
|
49
|
+
const BatchHttpLink = new batchHttp.BatchHttpLink({
|
|
50
|
+
uri: index_cjs.endpointGraphQL,
|
|
51
|
+
fetch: effectiveFetch$1
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const ErrorLink = new error.ErrorLink(({ error, result })=>{
|
|
55
|
+
// In Apollo Client 4, errors are consolidated to the 'error' and 'result' properties
|
|
56
|
+
// Handle GraphQL errors from result
|
|
57
|
+
if (result?.errors) {
|
|
58
|
+
result.errors.forEach((graphQLError)=>{
|
|
59
|
+
const { message, path, extensions } = graphQLError;
|
|
60
|
+
const formattedPath = Array.isArray(path) ? path.join('.') : path ?? 'N/A';
|
|
61
|
+
const parts = [
|
|
62
|
+
`[Quiltt][GraphQL Error]: ${message}`,
|
|
63
|
+
`Path: ${formattedPath}`
|
|
64
|
+
];
|
|
65
|
+
if (extensions) {
|
|
66
|
+
if (extensions.code) parts.push(`Code: ${extensions.code}`);
|
|
67
|
+
if (extensions.errorId) parts.push(`Error ID: ${extensions.errorId}`);
|
|
68
|
+
if (extensions.instruction) parts.push(`Instruction: ${extensions.instruction}`);
|
|
69
|
+
if (extensions.documentationUrl) {
|
|
70
|
+
parts.push(`Docs: ${extensions.documentationUrl}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
console.warn(parts.join(' | '));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// Handle network/server errors
|
|
77
|
+
if (error) {
|
|
78
|
+
if ('statusCode' in error && error.statusCode === 401) {
|
|
79
|
+
console.warn('[Quiltt][Authentication Error]:', error);
|
|
80
|
+
index_cjs$1.GlobalStorage.set('session', null);
|
|
81
|
+
} else if ('statusCode' in error) {
|
|
82
|
+
console.warn('[Quiltt][Server Error]:', error);
|
|
83
|
+
} else {
|
|
84
|
+
console.warn('[Quiltt][Network Error]:', error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const ForwardableLink = new core.ApolloLink((operation, forward)=>forward(operation));
|
|
90
|
+
|
|
91
|
+
// Use `cross-fetch` only if `fetch` is not available on the `globalThis` object
|
|
92
|
+
const effectiveFetch = typeof fetch === 'undefined' ? crossfetch__default.default : fetch;
|
|
93
|
+
const HttpLink = new http.HttpLink({
|
|
94
|
+
uri: index_cjs.endpointGraphQL,
|
|
95
|
+
fetch: effectiveFetch
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const RetryLink = new retry.RetryLink({
|
|
99
|
+
attempts: {
|
|
100
|
+
retryIf: (error, _operation)=>{
|
|
101
|
+
if (!error) return false;
|
|
102
|
+
const statusCode = 'statusCode' in error ? error.statusCode : undefined;
|
|
103
|
+
return !statusCode || statusCode >= 500;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const TerminatingLink = new core.ApolloLink(()=>{
|
|
109
|
+
return new rxjs.Observable((observer)=>{
|
|
110
|
+
observer.complete();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Extracts version number from formatted version string
|
|
116
|
+
* @param formattedVersion - Formatted version like "@quiltt/core: v4.5.1"
|
|
117
|
+
* @returns Version number like "4.5.1" or "unknown" if not found
|
|
118
|
+
*/ const extractVersionNumber = (formattedVersion)=>{
|
|
119
|
+
// Find the 'v' prefix and extract version after it
|
|
120
|
+
const vIndex = formattedVersion.indexOf('v');
|
|
121
|
+
if (vIndex === -1) return 'unknown';
|
|
122
|
+
const versionPart = formattedVersion.substring(vIndex + 1);
|
|
123
|
+
const parts = versionPart.split('.');
|
|
124
|
+
// Validate we have at least major.minor.patch
|
|
125
|
+
if (parts.length < 3) return 'unknown';
|
|
126
|
+
// Extract numeric parts (handles cases like "4.5.1-beta")
|
|
127
|
+
const major = parts[0].match(/^\d+/)?.[0];
|
|
128
|
+
const minor = parts[1].match(/^\d+/)?.[0];
|
|
129
|
+
const patch = parts[2].match(/^\d+/)?.[0];
|
|
130
|
+
if (!major || !minor || !patch) return 'unknown';
|
|
131
|
+
return `${major}.${minor}.${patch}`;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Generates a User-Agent string following standard format
|
|
135
|
+
* Format: Quiltt/<version> (<platform-info>)
|
|
136
|
+
*/ const getUserAgent = (sdkVersion, platformInfo)=>{
|
|
137
|
+
return `Quiltt/${sdkVersion} (${platformInfo})`;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const createVersionLink = (platformInfo)=>{
|
|
141
|
+
const versionNumber = extractVersionNumber(index_cjs.version);
|
|
142
|
+
const userAgent = getUserAgent(versionNumber, platformInfo);
|
|
143
|
+
return new core.ApolloLink((operation, forward)=>{
|
|
144
|
+
operation.setContext(({ headers = {} })=>({
|
|
145
|
+
headers: {
|
|
146
|
+
...headers,
|
|
147
|
+
'Quiltt-Client-Version': index_cjs.version,
|
|
148
|
+
'User-Agent': userAgent
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
return forward(operation);
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
class QuilttClient extends core.ApolloClient {
|
|
156
|
+
constructor(options){
|
|
157
|
+
const finalOptions = {
|
|
158
|
+
...options,
|
|
159
|
+
devtools: {
|
|
160
|
+
enabled: options.devtools?.enabled ?? index_cjs.debugging
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const initialLinks = options.customLinks ? [
|
|
164
|
+
...options.customLinks
|
|
165
|
+
] : [];
|
|
166
|
+
const isOperationDefinition = (def)=>def.kind === 'OperationDefinition';
|
|
167
|
+
const isSubscriptionOperation = (operation)=>{
|
|
168
|
+
return operation.query.definitions.some((definition)=>isOperationDefinition(definition) && definition.operation === 'subscription');
|
|
169
|
+
};
|
|
170
|
+
const isBatchable = (operation)=>{
|
|
171
|
+
return operation.getContext().batchable ?? true;
|
|
172
|
+
};
|
|
173
|
+
const authLink = new AuthLink();
|
|
174
|
+
const subscriptionsLink = new SubscriptionLink12s.SubscriptionLink();
|
|
175
|
+
const quilttLink = core.ApolloLink.from([
|
|
176
|
+
...initialLinks,
|
|
177
|
+
options.versionLink,
|
|
178
|
+
authLink,
|
|
179
|
+
ErrorLink,
|
|
180
|
+
RetryLink
|
|
181
|
+
]).split(isSubscriptionOperation, subscriptionsLink, ForwardableLink).split(isBatchable, BatchHttpLink, HttpLink);
|
|
182
|
+
super({
|
|
183
|
+
link: quilttLink,
|
|
184
|
+
...finalOptions
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
Object.defineProperty(exports, "gql", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
get: function () { return core.gql; }
|
|
192
|
+
});
|
|
193
|
+
exports.SubscriptionLink = SubscriptionLink12s.SubscriptionLink;
|
|
194
|
+
Object.defineProperty(exports, "InMemoryCache", {
|
|
195
|
+
enumerable: true,
|
|
196
|
+
get: function () { return cache.InMemoryCache; }
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, "useMutation", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function () { return react.useMutation; }
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(exports, "useQuery", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
get: function () { return react.useQuery; }
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(exports, "useSubscription", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function () { return react.useSubscription; }
|
|
209
|
+
});
|
|
210
|
+
exports.AuthLink = AuthLink;
|
|
211
|
+
exports.BatchHttpLink = BatchHttpLink;
|
|
212
|
+
exports.ErrorLink = ErrorLink;
|
|
213
|
+
exports.ForwardableLink = ForwardableLink;
|
|
214
|
+
exports.HttpLink = HttpLink;
|
|
215
|
+
exports.QuilttClient = QuilttClient;
|
|
216
|
+
exports.RetryLink = RetryLink;
|
|
217
|
+
exports.TerminatingLink = TerminatingLink;
|
|
218
|
+
exports.createVersionLink = createVersionLink;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { ApolloClient, ApolloLink } from '@apollo/client/core';
|
|
2
|
+
export { OperationVariables, gql } from '@apollo/client/core';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { BatchHttpLink as BatchHttpLink$1 } from '@apollo/client/link/batch-http';
|
|
5
|
+
import { ErrorLink as ErrorLink$1 } from '@apollo/client/link/error';
|
|
6
|
+
import { HttpLink as HttpLink$1 } from '@apollo/client/link/http';
|
|
7
|
+
import { RetryLink as RetryLink$1 } from '@apollo/client/link/retry';
|
|
8
|
+
import { Consumer } from '@rails/actioncable';
|
|
9
|
+
export { InMemoryCache, NormalizedCacheObject } from '@apollo/client/cache';
|
|
10
|
+
export { useMutation, useQuery, useSubscription } from '@apollo/client/react';
|
|
11
|
+
|
|
12
|
+
type QuilttClientOptions = Omit<ApolloClient.Options, 'link'> & {
|
|
13
|
+
/** An array of initial links to inject before the default Quiltt Links */
|
|
14
|
+
customLinks?: ApolloLink[];
|
|
15
|
+
/** Platform-specific version link (required) */
|
|
16
|
+
versionLink: ApolloLink;
|
|
17
|
+
};
|
|
18
|
+
declare class QuilttClient extends ApolloClient {
|
|
19
|
+
constructor(options: QuilttClientOptions);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Apollo Link that handles authentication and session expiration for GraphQL requests.
|
|
24
|
+
*
|
|
25
|
+
* Features:
|
|
26
|
+
* - Automatically adds Bearer token to request headers
|
|
27
|
+
* - Detects expired tokens and triggers proper error handling
|
|
28
|
+
* - Clears expired sessions from storage (triggers React re-renders via observers)
|
|
29
|
+
* - Emits GraphQL errors for consistent Apollo error handling
|
|
30
|
+
*/
|
|
31
|
+
declare class AuthLink extends ApolloLink {
|
|
32
|
+
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare const BatchHttpLink: BatchHttpLink$1;
|
|
36
|
+
|
|
37
|
+
declare const ErrorLink: ErrorLink$1;
|
|
38
|
+
|
|
39
|
+
declare const ForwardableLink: ApolloLink;
|
|
40
|
+
|
|
41
|
+
declare const HttpLink: HttpLink$1;
|
|
42
|
+
|
|
43
|
+
declare const RetryLink: RetryLink$1;
|
|
44
|
+
|
|
45
|
+
type RequestResult = ApolloLink.Result<{
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}>;
|
|
48
|
+
type ConnectionParams = object | ((operation: ApolloLink.Operation) => object);
|
|
49
|
+
type SubscriptionCallbacks = {
|
|
50
|
+
connected?: (args?: {
|
|
51
|
+
reconnected: boolean;
|
|
52
|
+
}) => void;
|
|
53
|
+
disconnected?: () => void;
|
|
54
|
+
received?: (payload: unknown) => void;
|
|
55
|
+
};
|
|
56
|
+
declare class ActionCableLink extends ApolloLink {
|
|
57
|
+
cables: {
|
|
58
|
+
[id: string]: Consumer;
|
|
59
|
+
};
|
|
60
|
+
channelName: string;
|
|
61
|
+
actionName: string;
|
|
62
|
+
connectionParams: ConnectionParams;
|
|
63
|
+
callbacks: SubscriptionCallbacks;
|
|
64
|
+
constructor(options: {
|
|
65
|
+
channelName?: string;
|
|
66
|
+
actionName?: string;
|
|
67
|
+
connectionParams?: ConnectionParams;
|
|
68
|
+
callbacks?: SubscriptionCallbacks;
|
|
69
|
+
});
|
|
70
|
+
request(operation: ApolloLink.Operation, _next: ApolloLink.ForwardFunction): Observable<RequestResult>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class SubscriptionLink extends ActionCableLink {
|
|
74
|
+
constructor();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare const TerminatingLink: ApolloLink;
|
|
78
|
+
|
|
79
|
+
declare const createVersionLink: (platformInfo: string) => ApolloLink;
|
|
80
|
+
|
|
81
|
+
export { AuthLink, BatchHttpLink, ErrorLink, ForwardableLink, HttpLink, QuilttClient, RetryLink, SubscriptionLink, TerminatingLink, createVersionLink };
|
|
82
|
+
export type { QuilttClientOptions };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ApolloLink, ApolloClient } from '@apollo/client/core';
|
|
2
|
+
export { gql } from '@apollo/client/core';
|
|
3
|
+
import { endpointGraphQL, version, debugging } from '../../config/index.js';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
import { v as validateSessionToken, S as SubscriptionLink } from './SubscriptionLink-12s-ufJBKwu1.js';
|
|
6
|
+
import { BatchHttpLink as BatchHttpLink$1 } from '@apollo/client/link/batch-http';
|
|
7
|
+
import crossfetch from 'cross-fetch';
|
|
8
|
+
import { ErrorLink as ErrorLink$1 } from '@apollo/client/link/error';
|
|
9
|
+
import { GlobalStorage } from '../../storage/index.js';
|
|
10
|
+
import { HttpLink as HttpLink$1 } from '@apollo/client/link/http';
|
|
11
|
+
import { RetryLink as RetryLink$1 } from '@apollo/client/link/retry';
|
|
12
|
+
export { InMemoryCache } from '@apollo/client/cache';
|
|
13
|
+
export { useMutation, useQuery, useSubscription } from '@apollo/client/react';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Apollo Link that handles authentication and session expiration for GraphQL requests.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - Automatically adds Bearer token to request headers
|
|
20
|
+
* - Detects expired tokens and triggers proper error handling
|
|
21
|
+
* - Clears expired sessions from storage (triggers React re-renders via observers)
|
|
22
|
+
* - Emits GraphQL errors for consistent Apollo error handling
|
|
23
|
+
*/ class AuthLink extends ApolloLink {
|
|
24
|
+
request(operation, forward) {
|
|
25
|
+
const validation = validateSessionToken();
|
|
26
|
+
if (!validation.valid) {
|
|
27
|
+
return new Observable((observer)=>{
|
|
28
|
+
observer.error(validation.error);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const { token } = validation;
|
|
32
|
+
operation.setContext(({ headers = {} })=>({
|
|
33
|
+
headers: {
|
|
34
|
+
...headers,
|
|
35
|
+
authorization: `Bearer ${token}`
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
return forward(operation);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use `cross-fetch` only if `fetch` is not available on the `globalThis` object
|
|
43
|
+
const effectiveFetch$1 = typeof fetch === 'undefined' ? crossfetch : fetch;
|
|
44
|
+
const BatchHttpLink = new BatchHttpLink$1({
|
|
45
|
+
uri: endpointGraphQL,
|
|
46
|
+
fetch: effectiveFetch$1
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const ErrorLink = new ErrorLink$1(({ error, result })=>{
|
|
50
|
+
// In Apollo Client 4, errors are consolidated to the 'error' and 'result' properties
|
|
51
|
+
// Handle GraphQL errors from result
|
|
52
|
+
if (result?.errors) {
|
|
53
|
+
result.errors.forEach((graphQLError)=>{
|
|
54
|
+
const { message, path, extensions } = graphQLError;
|
|
55
|
+
const formattedPath = Array.isArray(path) ? path.join('.') : path ?? 'N/A';
|
|
56
|
+
const parts = [
|
|
57
|
+
`[Quiltt][GraphQL Error]: ${message}`,
|
|
58
|
+
`Path: ${formattedPath}`
|
|
59
|
+
];
|
|
60
|
+
if (extensions) {
|
|
61
|
+
if (extensions.code) parts.push(`Code: ${extensions.code}`);
|
|
62
|
+
if (extensions.errorId) parts.push(`Error ID: ${extensions.errorId}`);
|
|
63
|
+
if (extensions.instruction) parts.push(`Instruction: ${extensions.instruction}`);
|
|
64
|
+
if (extensions.documentationUrl) {
|
|
65
|
+
parts.push(`Docs: ${extensions.documentationUrl}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
console.warn(parts.join(' | '));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Handle network/server errors
|
|
72
|
+
if (error) {
|
|
73
|
+
if ('statusCode' in error && error.statusCode === 401) {
|
|
74
|
+
console.warn('[Quiltt][Authentication Error]:', error);
|
|
75
|
+
GlobalStorage.set('session', null);
|
|
76
|
+
} else if ('statusCode' in error) {
|
|
77
|
+
console.warn('[Quiltt][Server Error]:', error);
|
|
78
|
+
} else {
|
|
79
|
+
console.warn('[Quiltt][Network Error]:', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const ForwardableLink = new ApolloLink((operation, forward)=>forward(operation));
|
|
85
|
+
|
|
86
|
+
// Use `cross-fetch` only if `fetch` is not available on the `globalThis` object
|
|
87
|
+
const effectiveFetch = typeof fetch === 'undefined' ? crossfetch : fetch;
|
|
88
|
+
const HttpLink = new HttpLink$1({
|
|
89
|
+
uri: endpointGraphQL,
|
|
90
|
+
fetch: effectiveFetch
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const RetryLink = new RetryLink$1({
|
|
94
|
+
attempts: {
|
|
95
|
+
retryIf: (error, _operation)=>{
|
|
96
|
+
if (!error) return false;
|
|
97
|
+
const statusCode = 'statusCode' in error ? error.statusCode : undefined;
|
|
98
|
+
return !statusCode || statusCode >= 500;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const TerminatingLink = new ApolloLink(()=>{
|
|
104
|
+
return new Observable((observer)=>{
|
|
105
|
+
observer.complete();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Extracts version number from formatted version string
|
|
111
|
+
* @param formattedVersion - Formatted version like "@quiltt/core: v4.5.1"
|
|
112
|
+
* @returns Version number like "4.5.1" or "unknown" if not found
|
|
113
|
+
*/ const extractVersionNumber = (formattedVersion)=>{
|
|
114
|
+
// Find the 'v' prefix and extract version after it
|
|
115
|
+
const vIndex = formattedVersion.indexOf('v');
|
|
116
|
+
if (vIndex === -1) return 'unknown';
|
|
117
|
+
const versionPart = formattedVersion.substring(vIndex + 1);
|
|
118
|
+
const parts = versionPart.split('.');
|
|
119
|
+
// Validate we have at least major.minor.patch
|
|
120
|
+
if (parts.length < 3) return 'unknown';
|
|
121
|
+
// Extract numeric parts (handles cases like "4.5.1-beta")
|
|
122
|
+
const major = parts[0].match(/^\d+/)?.[0];
|
|
123
|
+
const minor = parts[1].match(/^\d+/)?.[0];
|
|
124
|
+
const patch = parts[2].match(/^\d+/)?.[0];
|
|
125
|
+
if (!major || !minor || !patch) return 'unknown';
|
|
126
|
+
return `${major}.${minor}.${patch}`;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Generates a User-Agent string following standard format
|
|
130
|
+
* Format: Quiltt/<version> (<platform-info>)
|
|
131
|
+
*/ const getUserAgent = (sdkVersion, platformInfo)=>{
|
|
132
|
+
return `Quiltt/${sdkVersion} (${platformInfo})`;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const createVersionLink = (platformInfo)=>{
|
|
136
|
+
const versionNumber = extractVersionNumber(version);
|
|
137
|
+
const userAgent = getUserAgent(versionNumber, platformInfo);
|
|
138
|
+
return new ApolloLink((operation, forward)=>{
|
|
139
|
+
operation.setContext(({ headers = {} })=>({
|
|
140
|
+
headers: {
|
|
141
|
+
...headers,
|
|
142
|
+
'Quiltt-Client-Version': version,
|
|
143
|
+
'User-Agent': userAgent
|
|
144
|
+
}
|
|
145
|
+
}));
|
|
146
|
+
return forward(operation);
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
class QuilttClient extends ApolloClient {
|
|
151
|
+
constructor(options){
|
|
152
|
+
const finalOptions = {
|
|
153
|
+
...options,
|
|
154
|
+
devtools: {
|
|
155
|
+
enabled: options.devtools?.enabled ?? debugging
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const initialLinks = options.customLinks ? [
|
|
159
|
+
...options.customLinks
|
|
160
|
+
] : [];
|
|
161
|
+
const isOperationDefinition = (def)=>def.kind === 'OperationDefinition';
|
|
162
|
+
const isSubscriptionOperation = (operation)=>{
|
|
163
|
+
return operation.query.definitions.some((definition)=>isOperationDefinition(definition) && definition.operation === 'subscription');
|
|
164
|
+
};
|
|
165
|
+
const isBatchable = (operation)=>{
|
|
166
|
+
return operation.getContext().batchable ?? true;
|
|
167
|
+
};
|
|
168
|
+
const authLink = new AuthLink();
|
|
169
|
+
const subscriptionsLink = new SubscriptionLink();
|
|
170
|
+
const quilttLink = ApolloLink.from([
|
|
171
|
+
...initialLinks,
|
|
172
|
+
options.versionLink,
|
|
173
|
+
authLink,
|
|
174
|
+
ErrorLink,
|
|
175
|
+
RetryLink
|
|
176
|
+
]).split(isSubscriptionOperation, subscriptionsLink, ForwardableLink).split(isBatchable, BatchHttpLink, HttpLink);
|
|
177
|
+
super({
|
|
178
|
+
link: quilttLink,
|
|
179
|
+
...finalOptions
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { AuthLink, BatchHttpLink, ErrorLink, ForwardableLink, HttpLink, QuilttClient, RetryLink, SubscriptionLink, TerminatingLink, createVersionLink };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
|
|
3
|
+
var browser_cjs = require('./browser.cjs');
|
|
4
|
+
var index_cjs = require('./graphql/index.cjs');
|
|
5
|
+
var index_cjs$1 = require('./rest/index.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
Object.keys(browser_cjs).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () { return browser_cjs[k]; }
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
Object.keys(index_cjs).forEach(function (k) {
|
|
16
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return index_cjs[k]; }
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
Object.keys(index_cjs$1).forEach(function (k) {
|
|
22
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return index_cjs$1[k]; }
|
|
25
|
+
});
|
|
26
|
+
});
|