@quiltt/core 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @quiltt/core
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#342](https://github.com/quiltt/quiltt-js/pull/342) [`6a387ba`](https://github.com/quiltt/quiltt-js/commit/6a387ba0db77912df85c6cd1924f63edf50f9cdd) Thanks [@sirwolfgang](https://github.com/sirwolfgang)! - Create useQuilttInstitutions hook
8
+
3
9
  ## 4.0.1
4
10
 
5
11
  ### Patch Changes
@@ -204,7 +204,7 @@ import { print } from 'graphql';
204
204
  */ const GlobalStorage = new Storage();
205
205
 
206
206
  var name = "@quiltt/core";
207
- var version$1 = "4.0.1";
207
+ var version$1 = "4.1.0";
208
208
 
209
209
  const QUILTT_API_INSECURE = (()=>{
210
210
  try {
@@ -235,6 +235,7 @@ const version = `${name}: v${version$1}`;
235
235
  const cdnBase = `${protocolHttp}://cdn.${domain}`;
236
236
  const endpointAuth = `${protocolHttp}://auth.${domain}/v1/users/session`;
237
237
  const endpointGraphQL = `${protocolHttp}://api.${domain}/v1/graphql`;
238
+ const endpointRest = `${protocolHttp}://api.${domain}/v1`;
238
239
  const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`;
239
240
 
240
241
  class ActionCableLink extends ApolloLink {
@@ -298,4 +299,4 @@ class SubscriptionLink extends ActionCableLink {
298
299
  }
299
300
  }
300
301
 
301
- 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, version as v };
302
+ export { GlobalStorage as G, LocalStorage as L, MemoryStorage as M, Observable as O, SubscriptionLink as S, endpointAuth as a, endpointRest as b, Storage as c, debugging as d, endpointGraphQL as e, cdnBase as f, endpointWebsockets as g, version as v };
package/dist/index.d.ts CHANGED
@@ -191,6 +191,23 @@ type FetchResponse<T> = {
191
191
  ok: boolean;
192
192
  };
193
193
 
194
+ type NoContentData = null;
195
+ type ErrorData = {
196
+ message: string;
197
+ instruction: string;
198
+ error_id: string;
199
+ };
200
+ type UnauthorizedData = {
201
+ message: string;
202
+ instruction: string;
203
+ };
204
+ type UnprocessableData = {
205
+ [attribute: string]: Array<string>;
206
+ };
207
+ type BadRequestResponse = FetchResponse<ErrorData>;
208
+ type UnauthorizedResponse = FetchResponse<UnauthorizedData>;
209
+ type UnprocessableResponse = FetchResponse<UnprocessableData>;
210
+
194
211
  declare enum AuthStrategies {
195
212
  Email = "email",
196
213
  Phone = "phone"
@@ -210,20 +227,11 @@ type PasscodePayload = UsernamePayload & {
210
227
  type SessionData = {
211
228
  token: string;
212
229
  };
213
- type NoContentData = null;
214
- type UnauthorizedData = {
215
- message: string;
216
- instruction: string;
217
- };
218
- type UnprocessableData = {
219
- [attribute: string]: Array<string>;
220
- };
221
230
  type Ping = SessionData | UnauthorizedData;
222
231
  type Identify = SessionData | NoContentData | UnprocessableData;
223
232
  type Authenticate = SessionData | UnauthorizedData | UnprocessableData;
224
233
  type Revoke = NoContentData | UnauthorizedData;
225
234
  type SessionResponse = FetchResponse<SessionData>;
226
- type UnprocessableResponse = FetchResponse<UnprocessableData>;
227
235
  declare class AuthAPI {
228
236
  clientId: string | undefined;
229
237
  constructor(clientId?: string | undefined);
@@ -258,6 +266,29 @@ declare class AuthAPI {
258
266
  private body;
259
267
  }
260
268
 
269
+ type InstitutionData = {
270
+ name: string;
271
+ logoUrl: string;
272
+ };
273
+ type InstitutionsData = Array<InstitutionData>;
274
+ type Search = InstitutionsData | ErrorData | UnauthorizedData;
275
+ type SearchResponse = FetchResponse<InstitutionsData>;
276
+ declare class InstitutionsAPI {
277
+ clientId: string;
278
+ agent: string;
279
+ constructor(clientId: string, agent?: string);
280
+ /**
281
+ * Response Statuses:
282
+ * - 200: OK -> Institutions Found
283
+ * - 401: Unauthorized -> Invalid Token
284
+ * - 400: Bad Request -> Invalid Request
285
+ */
286
+ search: (token: string, connectorId: string, term: string, signal?: AbortSignal) => Promise<FetchResponse<Search>>;
287
+ private config;
288
+ private validateStatus;
289
+ private body;
290
+ }
291
+
261
292
  /** Utility types to extend default TS utilities */
262
293
  type Maybe<T> = T | null;
263
294
  type InputMaybe<T> = Maybe<T>;
@@ -383,6 +414,7 @@ declare const version: string;
383
414
  declare const cdnBase: string;
384
415
  declare const endpointAuth: string;
385
416
  declare const endpointGraphQL: string;
417
+ declare const endpointRest: string;
386
418
  declare const endpointWebsockets: string;
387
419
 
388
420
  type RegisteredClaims = {
@@ -422,5 +454,5 @@ declare class Timeoutable {
422
454
  private broadcast;
423
455
  }
424
456
 
425
- export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, ConnectorSDKEventType, ErrorLink, ForwardableLink, GlobalStorage, HttpLink, JsonWebTokenParse, LocalStorage, MemoryStorage, Observable, QuilttClient, RetryLink, Storage, SubscriptionLink, TerminatingLink, Timeoutable, VersionLink, cdnBase, debugging, endpointAuth, endpointGraphQL, endpointWebsockets, version };
426
- export type { Claims, ConnectorSDK, ConnectorSDKCallbackMetadata, ConnectorSDKCallbacks, ConnectorSDKConnectOptions, ConnectorSDKConnector, ConnectorSDKConnectorOptions, ConnectorSDKOnEventCallback, ConnectorSDKOnEventExitCallback, ConnectorSDKOnExitAbortCallback, ConnectorSDKOnExitErrorCallback, ConnectorSDKOnExitSuccessCallback, ConnectorSDKOnLoadCallback, ConnectorSDKOnOpenCallback, ConnectorSDKReconnectOptions, DeepPartial, DeepReadonly, Exact, InputMaybe, JsonWebToken, MakeMaybe, MakeOptional, Maybe, Mutable, Nullable, Observer, PasscodePayload, PrivateClaims, QuilttClientOptions, QuilttJWT, RegisteredClaims, SessionResponse, UnprocessableData, UnprocessableResponse, UsernamePayload };
457
+ export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, ConnectorSDKEventType, ErrorLink, ForwardableLink, GlobalStorage, HttpLink, InstitutionsAPI, JsonWebTokenParse, LocalStorage, MemoryStorage, Observable, QuilttClient, RetryLink, Storage, SubscriptionLink, TerminatingLink, Timeoutable, VersionLink, cdnBase, debugging, endpointAuth, endpointGraphQL, endpointRest, endpointWebsockets, version };
458
+ export type { BadRequestResponse, Claims, ConnectorSDK, ConnectorSDKCallbackMetadata, ConnectorSDKCallbacks, ConnectorSDKConnectOptions, ConnectorSDKConnector, ConnectorSDKConnectorOptions, ConnectorSDKOnEventCallback, ConnectorSDKOnEventExitCallback, ConnectorSDKOnExitAbortCallback, ConnectorSDKOnExitErrorCallback, ConnectorSDKOnExitSuccessCallback, ConnectorSDKOnLoadCallback, ConnectorSDKOnOpenCallback, ConnectorSDKReconnectOptions, DeepPartial, DeepReadonly, ErrorData, Exact, InputMaybe, InstitutionData, InstitutionsData, JsonWebToken, MakeMaybe, MakeOptional, Maybe, Mutable, NoContentData, Nullable, Observer, PasscodePayload, PrivateClaims, QuilttClientOptions, QuilttJWT, RegisteredClaims, SearchResponse, SessionResponse, UnauthorizedData, UnauthorizedResponse, UnprocessableData, UnprocessableResponse, UsernamePayload };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ApolloLink, ApolloClient } from '@apollo/client/core/index.js';
2
2
  export { gql } from '@apollo/client/core/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-CVjwwmoB.js';
4
- export { L as LocalStorage, M as MemoryStorage, O as Observable, b as Storage, c as cdnBase, f as endpointWebsockets } from './SubscriptionLink-client-CVjwwmoB.js';
3
+ import { G as GlobalStorage, e as endpointGraphQL, v as version, d as debugging, S as SubscriptionLink, a as endpointAuth, b as endpointRest } from './SubscriptionLink-client-BS9H6eZn.js';
4
+ export { L as LocalStorage, M as MemoryStorage, O as Observable, c as Storage, f as cdnBase, g as endpointWebsockets } from './SubscriptionLink-client-BS9H6eZn.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';
@@ -254,6 +254,53 @@ class AuthAPI {
254
254
  }
255
255
  }
256
256
 
257
+ class InstitutionsAPI {
258
+ constructor(clientId, agent = 'web'){
259
+ /**
260
+ * Response Statuses:
261
+ * - 200: OK -> Institutions Found
262
+ * - 401: Unauthorized -> Invalid Token
263
+ * - 400: Bad Request -> Invalid Request
264
+ */ this.search = async (token, connectorId, term, signal)=>{
265
+ const params = new URLSearchParams();
266
+ params.append('connectorId', connectorId);
267
+ params.append('term', term);
268
+ const response = await fetchWithRetry(`${endpointRest}/sdk/institutions?${params}`, {
269
+ method: 'GET',
270
+ signal,
271
+ ...this.config(token)
272
+ });
273
+ return response;
274
+ };
275
+ this.config = (token)=>{
276
+ const headers = new Headers();
277
+ headers.set('Content-Type', 'application/json');
278
+ headers.set('Accept', 'application/json');
279
+ headers.set('X-Quiltt-SDK-Agent', this.agent);
280
+ headers.set('Authorization', `Bearer ${token}`);
281
+ return {
282
+ headers,
283
+ validateStatus: this.validateStatus,
284
+ retry: true
285
+ };
286
+ };
287
+ this.validateStatus = (status)=>status < 500 && status !== 429;
288
+ this.body = (payload)=>{
289
+ if (!this.clientId) {
290
+ console.error('Quiltt Client ID is not set. Unable to identify & authenticate');
291
+ }
292
+ return {
293
+ session: {
294
+ clientId: this.clientId,
295
+ ...payload
296
+ }
297
+ };
298
+ };
299
+ this.clientId = clientId;
300
+ this.agent = agent;
301
+ }
302
+ }
303
+
257
304
  const MATCHER = /^(?:[\w-]+\.){2}[\w-]+$/;
258
305
  const JsonWebTokenParse = (token)=>{
259
306
  if (typeof token === 'undefined' || token === null) return token;
@@ -296,4 +343,4 @@ const JsonWebTokenParse = (token)=>{
296
343
  }
297
344
  }
298
345
 
299
- export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, ConnectorSDKEventType, ErrorLink, ForwardableLink, GlobalStorage, HttpLink, JsonWebTokenParse, QuilttClient, RetryLink, SubscriptionLink, TerminatingLink, Timeoutable, VersionLink, debugging, endpointAuth, endpointGraphQL, version };
346
+ export { AuthAPI, AuthLink, AuthStrategies, BatchHttpLink, ConnectorSDKEventType, ErrorLink, ForwardableLink, GlobalStorage, HttpLink, InstitutionsAPI, JsonWebTokenParse, QuilttClient, RetryLink, SubscriptionLink, TerminatingLink, Timeoutable, VersionLink, debugging, endpointAuth, endpointGraphQL, endpointRest, version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quiltt/core",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Javascript API client and utilities for Quiltt",
5
5
  "keywords": [
6
6
  "quiltt",
@@ -1,6 +1,8 @@
1
1
  import { endpointAuth } from '@/configuration'
2
+
2
3
  import type { FetchResponse } from './fetchWithRetry'
3
4
  import { fetchWithRetry } from './fetchWithRetry'
5
+ import type { NoContentData, UnauthorizedData, UnprocessableData } from './types'
4
6
 
5
7
  export enum AuthStrategies {
6
8
  Email = 'email',
@@ -21,9 +23,6 @@ export type UsernamePayload = EmailInput | PhoneInput
21
23
  export type PasscodePayload = UsernamePayload & { passcode: string }
22
24
 
23
25
  type SessionData = { token: string }
24
- type NoContentData = null
25
- type UnauthorizedData = { message: string; instruction: string }
26
- export type UnprocessableData = { [attribute: string]: Array<string> }
27
26
 
28
27
  type Ping = SessionData | UnauthorizedData
29
28
  type Identify = SessionData | NoContentData | UnprocessableData
@@ -31,7 +30,6 @@ type Authenticate = SessionData | UnauthorizedData | UnprocessableData
31
30
  type Revoke = NoContentData | UnauthorizedData
32
31
 
33
32
  export type SessionResponse = FetchResponse<SessionData>
34
- export type UnprocessableResponse = FetchResponse<UnprocessableData>
35
33
 
36
34
  // https://www.quiltt.dev/api-reference/auth
37
35
  export class AuthAPI {
@@ -1 +1,3 @@
1
1
  export * from './auth'
2
+ export * from './institutions'
3
+ export * from './types'
@@ -0,0 +1,70 @@
1
+ import { endpointRest } from '@/configuration'
2
+
3
+ import type { FetchResponse } from './fetchWithRetry'
4
+ import { fetchWithRetry } from './fetchWithRetry'
5
+ import type { ErrorData, UnauthorizedData } from './types'
6
+
7
+ export type InstitutionData = { name: string; logoUrl: string }
8
+ export type InstitutionsData = Array<InstitutionData>
9
+
10
+ type Search = InstitutionsData | ErrorData | UnauthorizedData
11
+
12
+ export type SearchResponse = FetchResponse<InstitutionsData>
13
+
14
+ export class InstitutionsAPI {
15
+ clientId: string
16
+ agent: string
17
+
18
+ constructor(clientId: string, agent = 'web') {
19
+ this.clientId = clientId
20
+ this.agent = agent
21
+ }
22
+
23
+ /**
24
+ * Response Statuses:
25
+ * - 200: OK -> Institutions Found
26
+ * - 401: Unauthorized -> Invalid Token
27
+ * - 400: Bad Request -> Invalid Request
28
+ */
29
+ search = async (token: string, connectorId: string, term: string, signal?: AbortSignal) => {
30
+ const params = new URLSearchParams()
31
+ params.append('connectorId', connectorId)
32
+ params.append('term', term)
33
+
34
+ const response = await fetchWithRetry<Search>(`${endpointRest}/sdk/institutions?${params}`, {
35
+ method: 'GET',
36
+ signal,
37
+ ...this.config(token),
38
+ })
39
+ return response
40
+ }
41
+
42
+ private config = (token?: string) => {
43
+ const headers = new Headers()
44
+ headers.set('Content-Type', 'application/json')
45
+ headers.set('Accept', 'application/json')
46
+ headers.set('X-Quiltt-SDK-Agent', this.agent)
47
+ headers.set('Authorization', `Bearer ${token}`)
48
+
49
+ return {
50
+ headers,
51
+ validateStatus: this.validateStatus,
52
+ retry: true,
53
+ }
54
+ }
55
+
56
+ private validateStatus = (status: number) => status < 500 && status !== 429
57
+
58
+ private body = (payload: any) => {
59
+ if (!this.clientId) {
60
+ console.error('Quiltt Client ID is not set. Unable to identify & authenticate')
61
+ }
62
+
63
+ return {
64
+ session: {
65
+ clientId: this.clientId,
66
+ ...payload,
67
+ },
68
+ }
69
+ }
70
+ }
@@ -0,0 +1,10 @@
1
+ import type { FetchResponse } from './fetchWithRetry'
2
+
3
+ export type NoContentData = null
4
+ export type ErrorData = { message: string; instruction: string; error_id: string }
5
+ export type UnauthorizedData = { message: string; instruction: string }
6
+ export type UnprocessableData = { [attribute: string]: Array<string> }
7
+
8
+ export type BadRequestResponse = FetchResponse<ErrorData>
9
+ export type UnauthorizedResponse = FetchResponse<UnauthorizedData>
10
+ export type UnprocessableResponse = FetchResponse<UnprocessableData>
@@ -34,4 +34,5 @@ export const version = `${packageName}: v${packageVersion}`
34
34
  export const cdnBase = `${protocolHttp}://cdn.${domain}`
35
35
  export const endpointAuth = `${protocolHttp}://auth.${domain}/v1/users/session`
36
36
  export const endpointGraphQL = `${protocolHttp}://api.${domain}/v1/graphql`
37
+ export const endpointRest = `${protocolHttp}://api.${domain}/v1`
37
38
  export const endpointWebsockets = `${protocolWebsockets}://api.${domain}/websockets`