@fraym/graphql 0.37.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Becklyn Studios
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # react
2
+
3
+ Easily integrate the Freym graphql api in yout project.
4
+ Use this package with the [urql](https://nearform.com/open-source/urql/docs/basics/react-preact/) GraphQl client.
5
+
6
+ ## Docs
7
+
8
+ Please have a look at our [documentation](https://docs.freym.becklyn.app/docs/sdk/react).
9
+
10
+ ## License
11
+
12
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,4 @@
1
+ import { ClientOptions } from "./options";
2
+ export type JWT = string | null;
3
+ export declare const getOptionalClient: (url: string, jwt: JWT, options?: ClientOptions) => import("@urql/core").Client | null;
4
+ export declare const getClient: (url: string, jwt: NonNullable<JWT>, options?: ClientOptions) => import("@urql/core").Client;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{getClient:function(){return getClient},getOptionalClient:function(){return getOptionalClient}});var _core=require("@urql/core");var _exchangerequestpolicy=require("@urql/exchange-request-policy");var _exchangeretry=require("@urql/exchange-retry");var _exchange=require("./exchange");var _options=require("./options");var getOptionalClient=function(url,jwt,options){if(!jwt){return null}return getClient(url,jwt,options)};var getClient=function(url,jwt,options){var _getClientOptions=(0,_options.getClientOptions)(options),cacheTtl=_getClientOptions.cacheTtl,enableCache=_getClientOptions.enableCache;return(0,_core.createClient)({url:url,fetchOptions:{headers:{"Content-Type":"application/json"}},exchanges:[(0,_exchange.getSubscriptionExchange)(url,jwt),(0,_exchangerequestpolicy.requestPolicyExchange)({ttl:cacheTtl}),enableCache?_core.cacheExchange:null,(0,_exchange.getAuthExchange)(jwt),(0,_exchangeretry.retryExchange)({initialDelayMs:1e3,maxDelayMs:5e3,randomDelay:true,maxNumberAttempts:3}),_core.fetchExchange].filter(function(exchange){return exchange!==null})})};
@@ -0,0 +1,2 @@
1
+ export declare const getAuthExchange: (jwt: string) => import("@urql/core").Exchange;
2
+ export declare const getSubscriptionExchange: (url: string, jwt: string) => import("@urql/core").Exchange | null;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{getAuthExchange:function(){return getAuthExchange},getSubscriptionExchange:function(){return getSubscriptionExchange}});var _core=require("@urql/core");var _exchangeauth=require("@urql/exchange-auth");var _wsClient=require("./wsClient");function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(_next,_throw)}}function _async_to_generator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value)}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err)}_next(undefined)})}}function _define_property(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _object_spread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};var ownKeys=Object.keys(source);if(typeof Object.getOwnPropertySymbols==="function"){ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))}ownKeys.forEach(function(key){_define_property(target,key,source[key])})}return target}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})}keys.push.apply(keys,symbols)}return keys}function _object_spread_props(target,source){source=source!=null?source:{};if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source))}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))})}return target}function _ts_generator(thisArg,body){var f,y,t,_={label:0,sent:function(){if(t[0]&1)throw t[1];return t[1]},trys:[],ops:[]},g=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return g.next=verb(0),g["throw"]=verb(1),g["return"]=verb(2),typeof Symbol==="function"&&(g[Symbol.iterator]=function(){return this}),g;function verb(n){return function(v){return step([n,v])}}function step(op){if(f)throw new TypeError("Generator is already executing.");while(g&&(g=0,op[0]&&(_=0)),_)try{if(f=1,y&&(t=op[0]&2?y["return"]:op[0]?y["throw"]||((t=y["return"])&&t.call(y),0):y.next)&&!(t=t.call(y,op[1])).done)return t;if(y=0,t)op=[op[0]&2,t.value];switch(op[0]){case 0:case 1:t=op;break;case 4:_.label++;return{value:op[1],done:false};case 5:_.label++;y=op[1];op=[0];continue;case 7:op=_.ops.pop();_.trys.pop();continue;default:if(!(t=_.trys,t=t.length>0&&t[t.length-1])&&(op[0]===6||op[0]===2)){_=0;continue}if(op[0]===3&&(!t||op[1]>t[0]&&op[1]<t[3])){_.label=op[1];break}if(op[0]===6&&_.label<t[1]){_.label=t[1];t=op;break}if(t&&_.label<t[2]){_.label=t[2];_.ops.push(op);break}if(t[2])_.ops.pop();_.trys.pop();continue}op=body.call(thisArg,_)}catch(e){op=[6,e];y=0}finally{f=t=0}if(op[0]&5)throw op[1];return{value:op[0]?op[1]:void 0,done:true}}}var getAuthExchange=function(jwt){return(0,_exchangeauth.authExchange)(function(utils){return _async_to_generator(function(){return _ts_generator(this,function(_state){return[2,{addAuthToOperation:function(operation){return utils.appendHeaders(operation,{Authorization:"Bearer ".concat(jwt)})},didAuthError:function didAuthError(error){return error.graphQLErrors.some(function(e){var _e_extensions;return((_e_extensions=e.extensions)===null||_e_extensions===void 0?void 0:_e_extensions.code)==="FORBIDDEN"})},refreshAuth:function(){return _async_to_generator(function(){return _ts_generator(this,function(_state){throw new Error("JWT expired")})})()}}]})})()})};var getSubscriptionExchange=function(url,jwt){var wsClient=(0,_wsClient.getWsClient)(url,jwt);return wsClient?(0,_core.subscriptionExchange)({forwardSubscription:function forwardSubscription(request){var input=_object_spread_props(_object_spread({},request),{query:request.query||""});return{subscribe:function subscribe(sink){var unsubscribe=wsClient.subscribe(input,{next:function(value){sink.next({data:value})},error:console.error,complete:console.log});return{unsubscribe:unsubscribe}}}}}):null};
@@ -0,0 +1,8 @@
1
+ export type ClientOptions = {
2
+ enableCache?: boolean;
3
+ cacheTtl?: number;
4
+ };
5
+ export declare const getClientOptions: (options?: ClientOptions) => {
6
+ enableCache: boolean;
7
+ cacheTtl: number;
8
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"getClientOptions",{enumerable:true,get:function(){return getClientOptions}});var getClientOptions=function(options){var _options_enableCache,_options_cacheTtl;return{enableCache:(_options_enableCache=options===null||options===void 0?void 0:options.enableCache)!==null&&_options_enableCache!==void 0?_options_enableCache:false,cacheTtl:(_options_cacheTtl=options===null||options===void 0?void 0:options.cacheTtl)!==null&&_options_cacheTtl!==void 0?_options_cacheTtl:3e5}};
@@ -0,0 +1,2 @@
1
+ import { Client } from "graphql-ws";
2
+ export declare const getWsClient: (url: string, jwt: string) => Client | null;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"getWsClient",{enumerable:true,get:function(){return getWsClient}});var _graphqlws=require("graphql-ws");var wsClients={};var getWsClient=function(url,jwt){var wsClient=null;if(wsClients[url]&&wsClients[url][jwt]){wsClient=wsClients[url][jwt]}else{if(typeof window!=="undefined"){if(!wsClients[url]){wsClients[url]={}}wsClients[url][jwt]=(0,_graphqlws.createClient)({url:getWsUrl(url),lazy:true,retryAttempts:Infinity,shouldRetry:function(){return true},connectionParams:function(){return{Authorization:"Bearer ".concat(jwt)}}});wsClient=wsClients[url][jwt]}}return wsClient};var getWsUrl=function(url){if(url.startsWith("https://")){return url.replace("https://","wss://")}else{return url.replace("http://","ws://")}};
@@ -0,0 +1,7 @@
1
+ import { CombinedError, Operation } from "@urql/core";
2
+ export type GraphqlError = CombinedError;
3
+ export type GraphqlOperation = Operation;
4
+ export declare const getErrorFromResult: <Data = any>(result: {
5
+ data?: Data;
6
+ error?: GraphqlError;
7
+ }, operation: Operation) => GraphqlError | null;
package/dist/error.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"getErrorFromResult",{enumerable:true,get:function(){return getErrorFromResult}});var _core=require("@urql/core");var getErrorFromResult=function(result,operation){var _result_error;return(_result_error=result.error)!==null&&_result_error!==void 0?_result_error:result.data?null:new _core.CombinedError({graphQLErrors:[],networkError:new Error("No data returned from ".concat(operation.kind))})};
@@ -0,0 +1,20 @@
1
+ import { CombinedError, Operation, RequestPolicy } from "@urql/core";
2
+ import { JWT } from "./client/client";
3
+ import { ClientOptions } from "./client/options";
4
+ export type OnGraphqlErrorFunction = (error: CombinedError, operation: Operation) => CombinedError | null;
5
+ interface BaseOptions {
6
+ url: string;
7
+ jwt: JWT;
8
+ requestPolicy?: RequestPolicy;
9
+ clientOptions?: ClientOptions;
10
+ onGraphqlError?: OnGraphqlErrorFunction;
11
+ }
12
+ export interface UseQueryOptions extends BaseOptions {
13
+ paused?: boolean;
14
+ }
15
+ export interface UseSubscriptionOptions<T> extends UseQueryOptions {
16
+ onSubscriptionUpdate?: (updateData: T) => T;
17
+ }
18
+ export type UseMutationOptions = BaseOptions;
19
+ export declare const defaultOnSubscriptionUpdate: <T>(v: T) => T;
20
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"defaultOnSubscriptionUpdate",{enumerable:true,get:function(){return defaultOnSubscriptionUpdate}});var defaultOnSubscriptionUpdate=function(v){return v};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@fraym/graphql",
3
+ "version": "0.37.0",
4
+ "license": "MIT",
5
+ "homepage": "https://github.com/fraym/freym-api",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/fraym/freym-api.git"
9
+ },
10
+ "description": "Easily integrate Freym GraphQl endpoints into your JS app",
11
+ "scripts": {
12
+ "build": "rm -rf dist && tsc && npx swc . -d dist",
13
+ "lint": "eslint && prettier --check \"**/*.{ts,tsx,json,scss,css}\"",
14
+ "fix": "eslint --fix && prettier --write \"**/*.{ts,tsx,json,scss,css}\""
15
+ },
16
+ "files": [
17
+ "dist/**/*"
18
+ ],
19
+ "exports": {
20
+ "./*": {
21
+ "types": "./dist/*.d.ts",
22
+ "default": "./dist/*.js"
23
+ },
24
+ "./client/*": {
25
+ "types": "./dist/client/*.d.ts",
26
+ "default": "./dist/client/*.js"
27
+ }
28
+ },
29
+ "engines": {
30
+ "node": ">=20"
31
+ },
32
+ "dependencies": {
33
+ "@urql/exchange-auth": "^2.2.1",
34
+ "@urql/exchange-request-policy": "^1.2.1",
35
+ "@urql/exchange-retry": "^1.3.1",
36
+ "@urql/core": "^5.1.1",
37
+ "graphql-ws": "^6.0.5"
38
+ },
39
+ "prettier": "@becklyn/prettier"
40
+ }