@codex-data/sdk 1.0.36 → 1.0.38

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 (148) hide show
  1. package/dist/resources/graphql.d.ts +69 -14
  2. package/dist/resources/graphql.d.ts.map +1 -1
  3. package/dist/resources/graphql.js +5 -2
  4. package/dist/resources/graphql.js.map +1 -1
  5. package/dist/sdk/Subscribe.js +5 -5
  6. package/dist/sdk/generated/gql.d.ts +24 -24
  7. package/dist/sdk/generated/gql.d.ts.map +1 -1
  8. package/dist/sdk/generated/gql.js +12 -12
  9. package/dist/sdk/generated/gql.js.map +1 -1
  10. package/dist/sdk/generated/graphql.d.ts +95 -14
  11. package/dist/sdk/generated/graphql.d.ts.map +1 -1
  12. package/dist/sdk/generated/graphql.js +17 -14
  13. package/dist/sdk/generated/graphql.js.map +1 -1
  14. package/package.json +2 -3
  15. package/dist/scripts/buildSdk.d.ts +0 -2
  16. package/dist/scripts/buildSdk.d.ts.map +0 -1
  17. package/dist/scripts/buildSdk.js +0 -135
  18. package/dist/scripts/buildSdk.js.map +0 -1
  19. package/dist/scripts/generateGraphql.d.ts +0 -31
  20. package/dist/scripts/generateGraphql.d.ts.map +0 -1
  21. package/dist/scripts/generateGraphql.js +0 -224
  22. package/dist/scripts/generateGraphql.js.map +0 -1
  23. package/dist/scripts/generateNetworkConfigs.d.ts +0 -2
  24. package/dist/scripts/generateNetworkConfigs.d.ts.map +0 -1
  25. package/dist/scripts/generateNetworkConfigs.js +0 -243
  26. package/dist/scripts/generateNetworkConfigs.js.map +0 -1
  27. package/src/index.ts +0 -2
  28. package/src/resources/.keep +0 -0
  29. package/src/resources/generated_mutations/BackfillWalletAggregates.graphql +0 -6
  30. package/src/resources/generated_mutations/CreateApiTokens.graphql +0 -9
  31. package/src/resources/generated_mutations/CreateWebhooks.graphql +0 -472
  32. package/src/resources/generated_mutations/DeleteApiToken.graphql +0 -3
  33. package/src/resources/generated_mutations/DeleteWebhooks.graphql +0 -5
  34. package/src/resources/generated_queries/ApiToken.graphql +0 -9
  35. package/src/resources/generated_queries/ApiTokens.graphql +0 -9
  36. package/src/resources/generated_queries/Balances.graphql +0 -97
  37. package/src/resources/generated_queries/Blocks.graphql +0 -7
  38. package/src/resources/generated_queries/ChartUrls.graphql +0 -7
  39. package/src/resources/generated_queries/DetailedWalletStats.graphql +0 -197
  40. package/src/resources/generated_queries/FilterExchanges.graphql +0 -43
  41. package/src/resources/generated_queries/FilterNftCollections.graphql +0 -569
  42. package/src/resources/generated_queries/FilterNftParallelAssets.graphql +0 -60
  43. package/src/resources/generated_queries/FilterNftPoolCollections.graphql +0 -71
  44. package/src/resources/generated_queries/FilterNftPools.graphql +0 -124
  45. package/src/resources/generated_queries/FilterPairs.graphql +0 -447
  46. package/src/resources/generated_queries/FilterTokenWallets.graphql +0 -144
  47. package/src/resources/generated_queries/FilterTokens.graphql +0 -570
  48. package/src/resources/generated_queries/FilterWallets.graphql +0 -57
  49. package/src/resources/generated_queries/GetBars.graphql +0 -232
  50. package/src/resources/generated_queries/GetCommunityNotes.graphql +0 -140
  51. package/src/resources/generated_queries/GetDetailedNftStats.graphql +0 -831
  52. package/src/resources/generated_queries/GetDetailedPairStats.graphql +0 -990
  53. package/src/resources/generated_queries/GetDetailedPairsStats.graphql +0 -974
  54. package/src/resources/generated_queries/GetEventLabels.graphql +0 -35
  55. package/src/resources/generated_queries/GetExchanges.graphql +0 -12
  56. package/src/resources/generated_queries/GetNetworkConfigs.graphql +0 -129
  57. package/src/resources/generated_queries/GetNetworkStats.graphql +0 -20
  58. package/src/resources/generated_queries/GetNetworkStatus.graphql +0 -8
  59. package/src/resources/generated_queries/GetNetworks.graphql +0 -7
  60. package/src/resources/generated_queries/GetNftAssets.graphql +0 -59
  61. package/src/resources/generated_queries/GetNftCollectionMetadata.graphql +0 -75
  62. package/src/resources/generated_queries/GetNftContracts.graphql +0 -39
  63. package/src/resources/generated_queries/GetNftEvents.graphql +0 -100
  64. package/src/resources/generated_queries/GetNftPool.graphql +0 -74
  65. package/src/resources/generated_queries/GetNftPoolCollection.graphql +0 -33
  66. package/src/resources/generated_queries/GetNftPoolCollectionsByExchange.graphql +0 -38
  67. package/src/resources/generated_queries/GetNftPoolEvents.graphql +0 -416
  68. package/src/resources/generated_queries/GetNftPoolStats.graphql +0 -40
  69. package/src/resources/generated_queries/GetNftPoolsByCollectionAndExchange.graphql +0 -89
  70. package/src/resources/generated_queries/GetNftPoolsByOwner.graphql +0 -89
  71. package/src/resources/generated_queries/GetParallelCardChanges.graphql +0 -57
  72. package/src/resources/generated_queries/GetPrimePoolAssets.graphql +0 -32
  73. package/src/resources/generated_queries/GetPrimePoolEvents.graphql +0 -156
  74. package/src/resources/generated_queries/GetPrimePools.graphql +0 -62
  75. package/src/resources/generated_queries/GetSymbol.graphql +0 -11
  76. package/src/resources/generated_queries/GetTokenBars.graphql +0 -121
  77. package/src/resources/generated_queries/GetTokenEvents.graphql +0 -102
  78. package/src/resources/generated_queries/GetTokenEventsForMaker.graphql +0 -102
  79. package/src/resources/generated_queries/GetTokenPrices.graphql +0 -8
  80. package/src/resources/generated_queries/GetWebhooks.graphql +0 -134
  81. package/src/resources/generated_queries/Holders.graphql +0 -100
  82. package/src/resources/generated_queries/LiquidityLocks.graphql +0 -32
  83. package/src/resources/generated_queries/LiquidityMetadata.graphql +0 -17
  84. package/src/resources/generated_queries/LiquidityMetadataByToken.graphql +0 -19
  85. package/src/resources/generated_queries/ListPairsForToken.graphql +0 -193
  86. package/src/resources/generated_queries/ListPairsWithMetadataForToken.graphql +0 -374
  87. package/src/resources/generated_queries/NftHolders.graphql +0 -12
  88. package/src/resources/generated_queries/PairMetadata.graphql +0 -234
  89. package/src/resources/generated_queries/PrimeHolders.graphql +0 -98
  90. package/src/resources/generated_queries/SearchNfts.graphql +0 -35
  91. package/src/resources/generated_queries/Token.graphql +0 -82
  92. package/src/resources/generated_queries/TokenLifecycleEvents.graphql +0 -34
  93. package/src/resources/generated_queries/TokenSparklines.graphql +0 -11
  94. package/src/resources/generated_queries/TokenTopTraders.graphql +0 -26
  95. package/src/resources/generated_queries/Tokens.graphql +0 -82
  96. package/src/resources/generated_queries/Top10HoldersPercent.graphql +0 -3
  97. package/src/resources/generated_queries/WalletAggregateBackfillState.graphql +0 -6
  98. package/src/resources/generated_queries/WalletChart.graphql +0 -20
  99. package/src/resources/generated_queries/WalletNftCollectionAssets.graphql +0 -11
  100. package/src/resources/generated_queries/WalletNftCollections.graphql +0 -10
  101. package/src/resources/generated_subscriptions/OnBalanceUpdated.graphql +0 -94
  102. package/src/resources/generated_subscriptions/OnBarsUpdated.graphql +0 -547
  103. package/src/resources/generated_subscriptions/OnDetailedStatsUpdated.graphql +0 -325
  104. package/src/resources/generated_subscriptions/OnEventLabelCreated.graphql +0 -22
  105. package/src/resources/generated_subscriptions/OnEventsCreated.graphql +0 -105
  106. package/src/resources/generated_subscriptions/OnEventsCreatedByMaker.graphql +0 -92
  107. package/src/resources/generated_subscriptions/OnHoldersUpdated.graphql +0 -100
  108. package/src/resources/generated_subscriptions/OnLatestPairUpdated.graphql +0 -42
  109. package/src/resources/generated_subscriptions/OnLatestTokens.graphql +0 -37
  110. package/src/resources/generated_subscriptions/OnLaunchpadTokenEvent.graphql +0 -97
  111. package/src/resources/generated_subscriptions/OnLaunchpadTokenEventBatch.graphql +0 -96
  112. package/src/resources/generated_subscriptions/OnNftAssetsCreated.graphql +0 -42
  113. package/src/resources/generated_subscriptions/OnNftEventsCreated.graphql +0 -82
  114. package/src/resources/generated_subscriptions/OnNftPoolEventsCreated.graphql +0 -412
  115. package/src/resources/generated_subscriptions/OnPairMetadataUpdated.graphql +0 -226
  116. package/src/resources/generated_subscriptions/OnPriceUpdated.graphql +0 -16
  117. package/src/resources/generated_subscriptions/OnPricesUpdated.graphql +0 -8
  118. package/src/resources/generated_subscriptions/OnTokenBarsUpdated.graphql +0 -545
  119. package/src/resources/generated_subscriptions/OnTokenEventsCreated.graphql +0 -92
  120. package/src/resources/generated_subscriptions/OnTokenLifecycleEventsCreated.graphql +0 -30
  121. package/src/resources/generated_subscriptions/OnUnconfirmedBarsUpdated.graphql +0 -115
  122. package/src/resources/generated_subscriptions/OnUnconfirmedEventsCreated.graphql +0 -50
  123. package/src/resources/generated_subscriptions/OnUnconfirmedEventsCreatedByMaker.graphql +0 -41
  124. package/src/resources/graphql.schema.json +0 -63375
  125. package/src/resources/graphql.ts +0 -10422
  126. package/src/resources/mutations_override/CreateWebhooks.graphql +0 -472
  127. package/src/resources/networkConfigs.json +0 -3726
  128. package/src/resources/queries_override/FilterTokenWallets.graphql +0 -144
  129. package/src/resources/queries_override/GetEventLabels.graphql +0 -35
  130. package/src/resources/queries_override/GetNetworkConfigs.graphql +0 -129
  131. package/src/resources/queries_override/GetWebhooks.graphql +0 -134
  132. package/src/resources/schema.graphql +0 -9916
  133. package/src/resources/subscriptions_override/OnEventLabelCreated.graphql +0 -22
  134. package/src/resources/subscriptions_override/OnLaunchpadTokenEventBatch.graphql +0 -96
  135. package/src/scripts/buildSdk.ts +0 -173
  136. package/src/scripts/generateGraphql.ts +0 -305
  137. package/src/scripts/generateNetworkConfigs.ts +0 -241
  138. package/src/sdk/Mutation.ts +0 -29
  139. package/src/sdk/Query.ts +0 -285
  140. package/src/sdk/Subscribe.ts +0 -465
  141. package/src/sdk/generated/fragment-masking.ts +0 -87
  142. package/src/sdk/generated/gql.ts +0 -610
  143. package/src/sdk/generated/graphql.ts +0 -11361
  144. package/src/sdk/generated/index.ts +0 -2
  145. package/src/sdk/graphql/GetPairEvents.graphql +0 -71
  146. package/src/sdk/index.test.ts +0 -454
  147. package/src/sdk/index.ts +0 -239
  148. package/src/sdk/invariant.ts +0 -34
package/src/sdk/index.ts DELETED
@@ -1,239 +0,0 @@
1
- import { TypedDocumentNode } from "@graphql-typed-document-node/core";
2
- import { GraphQLClient, Variables } from "graphql-request";
3
- import {
4
- Client as GraphQLWsClient,
5
- createClient,
6
- ExecutionResult,
7
- Sink,
8
- } from "graphql-ws";
9
- import WebSocket from "isomorphic-ws";
10
-
11
- import { invariant } from "./invariant";
12
- import { Mutation } from "./Mutation";
13
- import { Query } from "./Query";
14
- import { Subscribe } from "./Subscribe";
15
-
16
- export type CleanupFunction = () => void;
17
-
18
- export type ApiConfig = {
19
- // https://graph.codex.io/graphql
20
- apiUrl: string;
21
-
22
- // wss://graph.codex.io/graphql
23
- apiRealtimeUrl: string;
24
-
25
- // true if you want to connect a websocket, sometimes useful to turn this off in certain environments
26
- ws?: boolean;
27
-
28
- // Add static headers to the http requests
29
- headers?: Record<string, string>;
30
-
31
- // Add static headers to the ws requests
32
- wsHeaders?: Record<string, string>;
33
-
34
- // Use this to apply dynamic headers to the requests
35
- applyHeaders?: () => Promise<Record<string, string>>;
36
-
37
- // Use this to override the default fetch implementation.
38
- fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
39
- };
40
-
41
- const defaultConfig: ApiConfig = {
42
- apiUrl: `https://graph.codex.io/graphql`,
43
- apiRealtimeUrl: `wss://graph.codex.io/graphql`,
44
- ws: true,
45
- };
46
-
47
- export class Codex {
48
- private client: GraphQLClient;
49
- private wsClient: GraphQLWsClient | undefined;
50
- public queries: Query;
51
- public mutations: Mutation;
52
- public subscriptions: Subscribe;
53
-
54
- /**
55
- * @param apiKey - The api key to use for the requests.
56
- * @param apiConfig - The configuration to use for the requests.
57
- */
58
- constructor(
59
- private apiKey: string,
60
- private apiConfig?: Partial<ApiConfig>,
61
- ) {
62
- const config = this.parseConfig(this.apiConfig ?? {});
63
- this.queries = new Query(this);
64
- this.mutations = new Mutation(this);
65
- this.subscriptions = new Subscribe(this);
66
-
67
- this.client = this.createGraphQLClient(config);
68
- this.wsClient = this.createWebsocketClient(config);
69
-
70
- this.wsClient?.on("error", (error) => {
71
- console.error("Websocket error: ", error);
72
- });
73
- }
74
-
75
- private parseConfig(config: Partial<ApiConfig>) {
76
- invariant(this.apiKey, "apiKey must be defined");
77
- return Object.assign({}, defaultConfig, config);
78
- }
79
-
80
- private createGraphQLClient(config: ApiConfig) {
81
- return new GraphQLClient(config.apiUrl, {
82
- method: "POST",
83
- headers: new Headers({
84
- "Content-Type": "application/json",
85
- Authorization: this.apiKey,
86
- "X-Apollo-Operation-Name": "query",
87
- ...config.headers,
88
- }),
89
- fetch: config.fetch,
90
- });
91
- }
92
-
93
- private createWebsocketClient(config: ApiConfig) {
94
- return config.ws
95
- ? createClient({
96
- webSocketImpl: WebSocket,
97
- keepAlive: 10_000, // ping server every 10 seconds
98
- url: config.apiRealtimeUrl,
99
- connectionParams: {
100
- Authorization: this.apiKey,
101
- ...config.wsHeaders,
102
- },
103
- })
104
- : undefined;
105
- }
106
-
107
- private async getRequestHeaders() {
108
- // Get any dynamic headers
109
- const dynamicHeaders = await this.apiConfig?.applyHeaders?.();
110
- const staticHeaders = this.apiConfig?.headers;
111
- const headers = {
112
- ...staticHeaders,
113
- ...dynamicHeaders,
114
- };
115
- return headers;
116
- }
117
-
118
- /**
119
- * Need to update the headers on the websocket connection.
120
- * This is useful if the api key changes, or you need to modify the connection init params at all.
121
- * NOTE: it will dispose of the old connection, so all existing subscriptions will be closed.
122
- */
123
- public updateConfig(incomingConfig: Partial<ApiConfig>) {
124
- // If we have an existing websocket connection, dispose of it.
125
- if (this.wsClient) this.dispose();
126
-
127
- // Merge the incoming config with the existing config.
128
- const config = this.parseConfig(
129
- Object.assign({}, this.apiConfig, incomingConfig),
130
- );
131
-
132
- // Create a new websocket connection with the new headers.
133
- this.wsClient = this.createWebsocketClient(config);
134
- this.client = this.createGraphQLClient(config);
135
-
136
- this.wsClient?.on("error", (error) => {
137
- console.error("Websocket error: ", error);
138
- });
139
- this.wsClient?.on("closed", (er) => {
140
- console.log("Websocket closed", er);
141
- });
142
- this.wsClient?.on("connecting", () => {
143
- console.log("Websocket connecting");
144
- });
145
- }
146
-
147
- /**
148
- * Call this to dispose of the websocket connection, and make this class ready for garbage collection.
149
- * This will also close any open subscriptions.
150
- *
151
- * It's useful for when you need to modify some of the configuration, or when you're done with the class.
152
- */
153
- public async dispose() {
154
- this.wsClient?.dispose();
155
- }
156
-
157
- /**
158
- * This is the preferred way to execute queries.
159
- * @param doc - The graphql document node to execute.
160
- * @param args - The variables to pass to the document.
161
- * @returns The result of the query.
162
- */
163
- public async query<TResults, TVars extends Variables>(
164
- doc: TypedDocumentNode<TResults, TVars>,
165
- args: TVars = {} as TVars,
166
- ) {
167
- const res = await this.client.request<typeof doc>(
168
- doc,
169
- args,
170
- await this.getRequestHeaders(),
171
- );
172
- return res as TResults;
173
- }
174
-
175
- /**
176
- * This is functionally the same thing as the `query` method, but it's more expressive.
177
- * @param doc - The graphql document node to execute.
178
- * @param args - The variables to pass to the document.
179
- * @returns The result of the mutation.
180
- */
181
- public async mutation<TResults, TVars extends Variables>(
182
- doc: TypedDocumentNode<TResults, TVars>,
183
- args: TVars = {} as TVars,
184
- ) {
185
- const res = await this.client.request<typeof doc>(
186
- doc,
187
- args,
188
- await this.getRequestHeaders(),
189
- );
190
- return res as TResults;
191
- }
192
-
193
- /**
194
- * This should be used when you don't want to use graphql libaries to create a document node,
195
- * and would rather just pass in a string.
196
- * @param gqlString - The graphql document string to execute.
197
- * @param args - The variables to pass to the document.
198
- * @returns The result of the mutation.
199
- */
200
- public async send<TResults, V extends Variables = Variables>(
201
- gqlString: string,
202
- args: V = {} as V,
203
- ) {
204
- const res = await this.client.request<TResults>(
205
- gqlString,
206
- args,
207
- await this.getRequestHeaders(),
208
- );
209
- return res;
210
- }
211
-
212
- /**
213
- * @param doc - The graphql document string to execute.
214
- * @param args - The variables to pass to the document.
215
- * @param sink - The sink to receive the results.
216
- * @returns A cleanup function to unsubscribe from the subscription.
217
- */
218
- public subscribe<
219
- TResults,
220
- TVars extends Record<string, unknown> = Record<string, never>,
221
- >(
222
- doc: string,
223
- args: TVars,
224
- sink: Sink<ExecutionResult<TResults>>,
225
- ): CleanupFunction {
226
- if (!this.wsClient) {
227
- throw new Error("Websocket is not enabled in the config");
228
- }
229
-
230
- const cleanup = this.wsClient.subscribe<TResults>(
231
- {
232
- query: doc,
233
- variables: args,
234
- },
235
- sink,
236
- );
237
- return cleanup;
238
- }
239
- }
@@ -1,34 +0,0 @@
1
- const isProduction: boolean = process.env.NODE_ENV === "production";
2
- const prefix = "Invariant failed";
3
-
4
- // Throw an error if the condition fails
5
- // Strip out error messages for production
6
- // > Not providing an inline default argument for message as the result is smaller
7
- export function invariant(
8
- condition: unknown,
9
- // Can provide a string, or a function that returns a string for cases where
10
- // the message takes a fair amount of effort to compute
11
- message?: string | (() => string),
12
- ): asserts condition {
13
- if (condition) {
14
- return;
15
- }
16
- // Condition not passed
17
-
18
- // In production we strip the message but still throw
19
- if (isProduction) {
20
- throw new Error(prefix);
21
- }
22
-
23
- // When not in production we allow the message to pass through
24
- // *This block will be removed in production builds*
25
-
26
- const provided: string | undefined =
27
- typeof message === "function" ? message() : message;
28
-
29
- // Options:
30
- // 1. message provided: `${prefix}: ${provided}`
31
- // 2. message not provided: prefix
32
- const value: string = provided ? `${prefix}: ${provided}` : prefix;
33
- throw new Error(value);
34
- }