@ludo.ninja/api 2.1.3 → 2.1.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.
@@ -1,2 +0,0 @@
1
- import { ApolloClient, NormalizedCacheObject } from "@apollo/client";
2
- export declare function initializeApollo(initialState?: null, domain?: string): ApolloClient<NormalizedCacheObject>;
@@ -1,185 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.initializeApollo = void 0;
7
- const client_1 = require("@apollo/client");
8
- const error_1 = require("@apollo/client/link/error");
9
- const context_1 = require("@apollo/client/link/context");
10
- const apollo_upload_client_1 = require("apollo-upload-client");
11
- const deepmerge_1 = __importDefault(require("deepmerge"));
12
- const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
13
- const cookies_1 = require("../cookies");
14
- const typePolicies_1 = require("./typePolicies");
15
- const subscriptions_1 = require("@apollo/client/link/subscriptions");
16
- const utilities_1 = require("@apollo/client/utilities");
17
- const graphql_ws_1 = require("graphql-ws");
18
- const index_1 = require("../index");
19
- let isRefreshing = false;
20
- let pendingRequests = [];
21
- let mainDomain = "";
22
- const resolvePendingRequests = () => {
23
- pendingRequests.map((callback) => callback());
24
- pendingRequests = [];
25
- };
26
- let apolloClient;
27
- const errorLink = (0, error_1.onError)(({ graphQLErrors, networkError, operation, forward }) => {
28
- const { authToken, refreshToken } = (0, cookies_1.getCookies)();
29
- if (graphQLErrors) {
30
- graphQLErrors.forEach(({ message, locations, path }) => console.warn(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`));
31
- for (const err of graphQLErrors) {
32
- if (err.message.includes("Auth token not found") && authToken) {
33
- let forward$;
34
- const client = apolloClient ?? createApolloClient();
35
- if (!isRefreshing) {
36
- isRefreshing = true;
37
- forward$ = (0, client_1.fromPromise)(client
38
- .mutate({
39
- context: { uri: index_1.hosts.authHost },
40
- variables: { refreshToken },
41
- mutation: index_1.schema.RefreshTokenDocument,
42
- })
43
- .then(({ data: { refreshToken: { tokenAuth, tokenRefresh }, }, }) => {
44
- (0, cookies_1.refreshCookies)(tokenAuth, tokenRefresh, mainDomain);
45
- resolvePendingRequests();
46
- return true;
47
- })
48
- .catch(async () => {
49
- await apolloClient?.mutate({
50
- context: { uri: index_1.hosts.authHost },
51
- mutation: index_1.schema.RevokeTokenDocument,
52
- });
53
- (0, cookies_1.destroyCookies)(mainDomain);
54
- pendingRequests = [];
55
- window.location.replace("/");
56
- return false;
57
- })
58
- .finally(() => {
59
- isRefreshing = false;
60
- })).filter((value) => Boolean(value));
61
- }
62
- else {
63
- forward$ = (0, client_1.fromPromise)(new Promise((resolve) => {
64
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
- // @ts-ignore
66
- pendingRequests.push(() => resolve());
67
- }));
68
- }
69
- return forward$.flatMap(() => forward(operation));
70
- }
71
- }
72
- }
73
- if (networkError) {
74
- console.warn(`[Network error]: ${networkError}`);
75
- if (networkError.message.includes("401") && authToken) {
76
- let forward$;
77
- const client = apolloClient ?? createApolloClient();
78
- if (!isRefreshing) {
79
- isRefreshing = true;
80
- forward$ = (0, client_1.fromPromise)(client
81
- .mutate({
82
- context: { uri: index_1.hosts.authHost },
83
- variables: { refreshToken },
84
- mutation: index_1.schema.RefreshTokenDocument,
85
- })
86
- .then(({ data: { refreshToken: { tokenAuth, tokenRefresh }, }, }) => {
87
- (0, cookies_1.refreshCookies)(tokenAuth, tokenRefresh, mainDomain);
88
- resolvePendingRequests();
89
- return true;
90
- })
91
- .catch(async () => {
92
- await apolloClient?.mutate({
93
- context: { uri: index_1.hosts.authHost },
94
- mutation: index_1.schema.RevokeTokenDocument,
95
- });
96
- (0, cookies_1.destroyCookies)(mainDomain);
97
- pendingRequests = [];
98
- window.location.replace("/");
99
- return false;
100
- })
101
- .finally(() => {
102
- isRefreshing = false;
103
- })).filter((value) => Boolean(value));
104
- }
105
- else {
106
- forward$ = (0, client_1.fromPromise)(new Promise((resolve) => {
107
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
108
- // @ts-ignore
109
- pendingRequests.push(() => resolve());
110
- }));
111
- }
112
- return forward$.flatMap(() => forward(operation));
113
- }
114
- }
115
- });
116
- const authLink = (0, context_1.setContext)(async (operation, { headers }) => {
117
- const { authToken } = (0, cookies_1.getCookies)();
118
- const header = authToken
119
- ? {
120
- headers: { ...headers, "x-client-authorization": `${authToken}` },
121
- }
122
- : { headers: { ...headers } };
123
- return {
124
- headers: header.headers,
125
- };
126
- });
127
- const httpLink = (0, apollo_upload_client_1.createUploadLink)({
128
- uri: index_1.hosts.authHost,
129
- });
130
- const wsLink = typeof window !== "undefined"
131
- ? new subscriptions_1.GraphQLWsLink((0, graphql_ws_1.createClient)({
132
- url: index_1.hosts.experiencesSubscriptionHost,
133
- retryAttempts: 3,
134
- on: {
135
- connected: () => console.log("GraphQLWsLink connected"),
136
- closed: () => console.log("GraphQLWsLink closed"),
137
- },
138
- }))
139
- : null;
140
- const opsLink = (0, client_1.from)([errorLink, authLink, httpLink]);
141
- const terminatingLink = typeof window !== "undefined" && wsLink !== null
142
- ? (0, client_1.split)(({ query }) => {
143
- const definition = (0, utilities_1.getMainDefinition)(query);
144
- return definition.kind === "OperationDefinition" && definition.operation === "subscription";
145
- }, wsLink, opsLink)
146
- : httpLink;
147
- function createApolloClient() {
148
- return new client_1.ApolloClient({
149
- ssrMode: typeof window === "undefined",
150
- link: terminatingLink,
151
- cache: new client_1.InMemoryCache({
152
- typePolicies: typePolicies_1.typePoliciesPortal,
153
- addTypename: true,
154
- resultCaching: true,
155
- }),
156
- });
157
- }
158
- function initializeApollo(initialState = null, domain = "ludo.ninja") {
159
- const _apolloClient = apolloClient ?? createApolloClient();
160
- mainDomain = domain;
161
- // If your page has Next.js data fetching methods that use Apollo Client, the initial state
162
- // gets hydrated here
163
- if (initialState) {
164
- // Get existing cache, loaded during client side data fetching
165
- const existingCache = _apolloClient.extract();
166
- // Merge the initialState from getStaticProps/getServerSideProps in the existing cache
167
- const data = (0, deepmerge_1.default)(existingCache, initialState, {
168
- // combine arrays using object equality (like in sets)
169
- arrayMerge: (destinationArray, sourceArray) => [
170
- ...sourceArray,
171
- ...destinationArray.filter((d) => sourceArray.every((s) => !(0, lodash_isequal_1.default)(d, s))),
172
- ],
173
- });
174
- // Restore the cache with the merged data
175
- _apolloClient.cache.restore(data);
176
- }
177
- // For SSG and SSR always create a new Apollo Client
178
- if (typeof window === "undefined")
179
- return _apolloClient;
180
- // Create the Apollo Client once in the client
181
- if (!apolloClient)
182
- apolloClient = _apolloClient;
183
- return _apolloClient;
184
- }
185
- exports.initializeApollo = initializeApollo;
@@ -1,2 +0,0 @@
1
- import { TypePolicies } from "@apollo/client";
2
- export declare const typePoliciesPortal: TypePolicies;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typePoliciesPortal = void 0;
4
- exports.typePoliciesPortal = {
5
- Query: {
6
- fields: {
7
- fetchAsset: {
8
- keyArgs: ["rank", "likes", "assetId"],
9
- merge: true,
10
- },
11
- fetchUserGalleries: {
12
- keyArgs: ["galleryId"],
13
- merge: true,
14
- },
15
- fetchUserFavorites: {
16
- keyArgs: ["galleryId"],
17
- merge: true,
18
- },
19
- fetchUserFavoritesV2: {
20
- keyArgs: ["galleryId"],
21
- merge: true,
22
- },
23
- fetchMyFavoritesV2: {
24
- keyArgs: ["galleryId"],
25
- merge: true,
26
- },
27
- fetchMyGalleriesV2: {
28
- keyArgs: ["galleryId"],
29
- merge: true,
30
- },
31
- fetchUserGalleriesV2: {
32
- keyArgs: ["galleryId"],
33
- merge: true,
34
- },
35
- fetchCreations: {
36
- keyArgs: ["itemId"],
37
- merge: true,
38
- },
39
- CollectionPage: {
40
- keyArgs: ["collectionId"],
41
- merge: true,
42
- },
43
- fetchCreationsByType: {
44
- keyArgs: ["nextPageToken"],
45
- merge: true,
46
- },
47
- fetchAllCreations: {
48
- keyArgs: ["nextPageToken"],
49
- merge: true,
50
- },
51
- },
52
- },
53
- };
@@ -1,19 +0,0 @@
1
- declare const assignCookies: (userId: string, wallets: Array<string>, authToken: string, refreshToken: string, newUser: string, inviteCode: string, domain?: string) => void;
2
- declare const refreshCookies: (authToken: string, refreshToken: string, domain?: string) => void;
3
- declare const getCookies: () => {
4
- authToken: string;
5
- refreshToken: string;
6
- userId: string;
7
- wallets: string;
8
- newUser: string;
9
- inviteCode: string;
10
- } | {
11
- authToken: null;
12
- refreshToken: null;
13
- userId: null;
14
- wallets: null;
15
- newUser: null;
16
- inviteCode: null;
17
- };
18
- declare const destroyCookies: (domain?: string) => void;
19
- export { assignCookies, refreshCookies, destroyCookies, getCookies };
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCookies = exports.destroyCookies = exports.refreshCookies = exports.assignCookies = void 0;
4
- const nookies_1 = require("nookies");
5
- const assignCookies = (userId, wallets, authToken, refreshToken, newUser, inviteCode, domain = "ludo.ninja") => {
6
- if (userId)
7
- (0, nookies_1.setCookie)(null, "userId", userId, { maxAge: 2629800000, path: "/", domain });
8
- if (wallets)
9
- (0, nookies_1.setCookie)(null, "wallets", wallets.join(), {
10
- maxAge: 2629800000,
11
- path: "/",
12
- domain,
13
- });
14
- if (authToken)
15
- (0, nookies_1.setCookie)(null, "authToken", authToken, {
16
- maxAge: 2629800000,
17
- path: "/",
18
- domain,
19
- });
20
- if (refreshToken)
21
- (0, nookies_1.setCookie)(null, "refreshToken", refreshToken, {
22
- maxAge: 2629800000,
23
- path: "/",
24
- domain,
25
- });
26
- if (newUser)
27
- (0, nookies_1.setCookie)(null, "newUser", newUser, {
28
- maxAge: 2629800000,
29
- path: "/",
30
- domain,
31
- });
32
- if (inviteCode)
33
- (0, nookies_1.setCookie)(null, "inviteCode", inviteCode, {
34
- maxAge: 2629800000,
35
- path: "/",
36
- domain,
37
- });
38
- };
39
- exports.assignCookies = assignCookies;
40
- const refreshCookies = (authToken, refreshToken, domain = "ludo.ninja") => {
41
- if (authToken)
42
- (0, nookies_1.setCookie)(null, "authToken", authToken, {
43
- maxAge: 2629800000,
44
- path: "/",
45
- domain,
46
- });
47
- if (refreshToken)
48
- (0, nookies_1.setCookie)(null, "refreshToken", refreshToken, {
49
- maxAge: 2629800000,
50
- path: "/",
51
- domain,
52
- });
53
- };
54
- exports.refreshCookies = refreshCookies;
55
- const getCookies = () => {
56
- const { authToken, refreshToken, userId, wallets, newUser, inviteCode } = (0, nookies_1.parseCookies)();
57
- if (authToken && refreshToken && userId && wallets && newUser && inviteCode) {
58
- return {
59
- authToken,
60
- refreshToken,
61
- userId,
62
- wallets,
63
- newUser,
64
- inviteCode,
65
- };
66
- }
67
- return {
68
- authToken: null,
69
- refreshToken: null,
70
- userId: null,
71
- wallets: null,
72
- newUser: null,
73
- inviteCode: null,
74
- };
75
- };
76
- exports.getCookies = getCookies;
77
- const destroyCookies = (domain = "ludo.ninja") => {
78
- (0, nookies_1.destroyCookie)(null, "userId", { path: "/", domain });
79
- (0, nookies_1.destroyCookie)(null, "wallets", { path: "/", domain });
80
- (0, nookies_1.destroyCookie)(null, "authToken", { path: "/", domain });
81
- (0, nookies_1.destroyCookie)(null, "refreshToken", { path: "/", domain });
82
- (0, nookies_1.destroyCookie)(null, "newUser", { path: "/", domain });
83
- (0, nookies_1.destroyCookie)(null, "inviteCode", { path: "/", domain });
84
- };
85
- exports.destroyCookies = destroyCookies;
@@ -1,27 +0,0 @@
1
- export declare const authHost = "https://auth.ludo.ninja:8080/graphql";
2
- export declare const identityHost = "https://identities.ludo.ninja:8090/graphql";
3
- export declare const assetsHost = "https://assets.ludo.ninja:8090/graphql";
4
- export declare const collectionsHost = "https://collections.ludo.ninja:8090/graphql";
5
- export declare const serverAssetsHost = "http://server-assets.istio.svc.k8s.local:8090/graphql";
6
- export declare const serverCollectionsHost = "http://server-collections.istio.svc.k8s.local:8090/graphql";
7
- export declare const serverIdentityHost = "http://server-identities.istio.svc.k8s.local:8090/graphql";
8
- export declare const galleriesHost = "https://galleries.ludo.ninja:8090/graphql";
9
- export declare const serverGalleriesHost = "http://server-galleries.istio.svc.k8s.local:8090/graphql";
10
- export declare const mediasHost = "https://medias.ludo.ninja:8090/graphql";
11
- export declare const serverImagesHost = "http://server-images.istio.svc.k8s.local:8090/graphql";
12
- export declare const searchHost = "https://search.ludo.ninja:8090/graphql";
13
- export declare const showCaseHost = "https://showcase.ludo.ninja:8090/graphql";
14
- export declare const showCaseHostSSR = "http://ssr.showcase.ludo.ninja:8090/graphql";
15
- export declare const serverShowCaseHost = "http://server-showcase.istio.svc.k8s.local:8090/graphql";
16
- export declare const serverSearchHost = "http://server-search.istio.svc.k8s.local:8090/graphql";
17
- export declare const preferencesHost = "https://preferences.ludo.ninja:8090/graphql";
18
- export declare const preferencesHostSSR = "https://ssr-preferences.ludo.ninja:8091/graphql";
19
- export declare const searchHostSSR = "https://ssr-search.ludo.ninja:8091/graphql";
20
- export declare const serverPreferencesHost = "http://server-preferences.istio.svc.k8s.local:8090/graphql";
21
- export declare const ethereumHost = "https://ethereum.ludo.ninja:8545";
22
- export declare const eventsHost = "wss://events.ludo.ninja:8090/subscriptions";
23
- export declare const experiencesSubscriptionHost = "wss://experiences.ludo.ninja:8090/subscriptions";
24
- export declare const opportunitiesHost = "https://opportunities.ludo.ninja:8090/graphql";
25
- export declare const extensionHost = "https://chrome.ludo.ninja:8092/graphql";
26
- export declare const experiencesHost = "https://experiences.ludo.ninja:8090/graphql";
27
- export declare const serverExperiencesHost = "http://server-experiences.istio.svc.k8s.local:8090/graphql";
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serverExperiencesHost = exports.experiencesHost = exports.extensionHost = exports.opportunitiesHost = exports.experiencesSubscriptionHost = exports.eventsHost = exports.ethereumHost = exports.serverPreferencesHost = exports.searchHostSSR = exports.preferencesHostSSR = exports.preferencesHost = exports.serverSearchHost = exports.serverShowCaseHost = exports.showCaseHostSSR = exports.showCaseHost = exports.searchHost = exports.serverImagesHost = exports.mediasHost = exports.serverGalleriesHost = exports.galleriesHost = exports.serverIdentityHost = exports.serverCollectionsHost = exports.serverAssetsHost = exports.collectionsHost = exports.assetsHost = exports.identityHost = exports.authHost = void 0;
4
- exports.authHost = "https://auth.ludo.ninja:8080/graphql";
5
- exports.identityHost = "https://identities.ludo.ninja:8090/graphql";
6
- exports.assetsHost = "https://assets.ludo.ninja:8090/graphql";
7
- exports.collectionsHost = "https://collections.ludo.ninja:8090/graphql";
8
- exports.serverAssetsHost = "http://server-assets.istio.svc.k8s.local:8090/graphql";
9
- exports.serverCollectionsHost = "http://server-collections.istio.svc.k8s.local:8090/graphql";
10
- exports.serverIdentityHost = "http://server-identities.istio.svc.k8s.local:8090/graphql";
11
- exports.galleriesHost = "https://galleries.ludo.ninja:8090/graphql";
12
- exports.serverGalleriesHost = "http://server-galleries.istio.svc.k8s.local:8090/graphql";
13
- exports.mediasHost = "https://medias.ludo.ninja:8090/graphql";
14
- exports.serverImagesHost = "http://server-images.istio.svc.k8s.local:8090/graphql";
15
- exports.searchHost = "https://search.ludo.ninja:8090/graphql";
16
- exports.showCaseHost = "https://showcase.ludo.ninja:8090/graphql";
17
- exports.showCaseHostSSR = "http://ssr.showcase.ludo.ninja:8090/graphql";
18
- exports.serverShowCaseHost = "http://server-showcase.istio.svc.k8s.local:8090/graphql";
19
- exports.serverSearchHost = "http://server-search.istio.svc.k8s.local:8090/graphql";
20
- exports.preferencesHost = "https://preferences.ludo.ninja:8090/graphql";
21
- exports.preferencesHostSSR = "https://ssr-preferences.ludo.ninja:8091/graphql";
22
- exports.searchHostSSR = "https://ssr-search.ludo.ninja:8091/graphql";
23
- exports.serverPreferencesHost = "http://server-preferences.istio.svc.k8s.local:8090/graphql";
24
- exports.ethereumHost = "https://ethereum.ludo.ninja:8545";
25
- exports.eventsHost = `wss://events.ludo.ninja:8090/subscriptions`;
26
- exports.experiencesSubscriptionHost = "wss://experiences.ludo.ninja:8090/subscriptions";
27
- exports.opportunitiesHost = "https://opportunities.ludo.ninja:8090/graphql";
28
- exports.extensionHost = "https://chrome.ludo.ninja:8092/graphql";
29
- exports.experiencesHost = "https://experiences.ludo.ninja:8090/graphql";
30
- exports.serverExperiencesHost = "http://server-experiences.istio.svc.k8s.local:8090/graphql";
package/build/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import * as schema from "./graphql_tools/__generated__/schema";
2
- import * as hosts from "./hosts";
3
- import * as graphqlConfig from "./config";
4
- import * as authCookies from "./cookies";
5
- export { schema, hosts, graphqlConfig, authCookies };