@show-karma/karma-gap-sdk 0.4.24 → 0.4.25

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/core/class/GAP.js CHANGED
@@ -233,11 +233,13 @@ class GAP extends types_1.Facade {
233
233
  const currentChainId = chainId ||
234
234
  Number((await signer.provider.getNetwork())?.chainId ||
235
235
  (await signer.getChainId()));
236
- if (chainId && !rpcConfig) {
237
- throw new Error(`rpcConfig is required when specifying chainId for cross-chain operations. ` +
238
- `Either provide rpcConfig or omit chainId to use the signer's chain.`);
239
- }
240
- const provider = chainId && rpcConfig
236
+ // Use rpcConfig provider if available for the target chain,
237
+ // otherwise fall back to signer (which may already be a provider
238
+ // for the correct chain, e.g. when created by the frontend).
239
+ const rpcUrl = chainId && rpcConfig
240
+ ? rpcConfig[chainId]
241
+ : undefined;
242
+ const provider = rpcUrl
241
243
  ? (0, get_web3_provider_1.getWeb3Provider)(chainId, rpcConfig)
242
244
  : signer;
243
245
  const network = Object.values(consts_1.Networks).find((n) => +n.chainId === Number(currentChainId));
@@ -258,11 +260,13 @@ class GAP extends types_1.Facade {
258
260
  const currentChainId = chainId ||
259
261
  Number((await signer.provider.getNetwork())?.chainId ||
260
262
  (await signer.getChainId()));
261
- if (chainId && !rpcConfig) {
262
- throw new Error(`rpcConfig is required when specifying chainId for cross-chain operations. ` +
263
- `Either provide rpcConfig or omit chainId to use the signer's chain.`);
264
- }
265
- const provider = chainId && rpcConfig
263
+ // Use rpcConfig provider if available for the target chain,
264
+ // otherwise fall back to signer (which may already be a provider
265
+ // for the correct chain, e.g. when created by the frontend).
266
+ const rpcUrl = chainId && rpcConfig
267
+ ? rpcConfig[chainId]
268
+ : undefined;
269
+ const provider = rpcUrl
266
270
  ? (0, get_web3_provider_1.getWeb3Provider)(chainId, rpcConfig)
267
271
  : signer;
268
272
  const network = Object.values(consts_1.Networks).find((n) => +n.chainId === Number(currentChainId));
@@ -2,72 +2,72 @@ import { AxiosGQL } from "../../GraphQL/AxiosGQL";
2
2
  import { Hex, IAttestationResponse, ICommunityResponse, ICommunityAdminsResponse, IGrantResponse, IProjectResponse, ISearchResponse, IProjectMilestoneResponse, ITrackResponse, ITrackAssignmentResponse, IProjectTrackResponse } from "./types";
3
3
  export declare class GapIndexerApi extends AxiosGQL {
4
4
  constructor(url: string);
5
- attestation(uid: Hex): Promise<import("axios").AxiosResponse<IAttestationResponse, any, {}>>;
6
- attestations(schemaUID: string, search?: string): Promise<import("axios").AxiosResponse<IAttestationResponse[], any, {}>>;
7
- attestationsOf(schemaUID: string, attester: Hex): Promise<import("axios").AxiosResponse<IAttestationResponse[], any, {}>>;
5
+ attestation(uid: Hex): Promise<import("axios").AxiosResponse<IAttestationResponse, any>>;
6
+ attestations(schemaUID: string, search?: string): Promise<import("axios").AxiosResponse<IAttestationResponse[], any>>;
7
+ attestationsOf(schemaUID: string, attester: Hex): Promise<import("axios").AxiosResponse<IAttestationResponse[], any>>;
8
8
  /**
9
9
  * Community
10
10
  */
11
- communities(search?: string): Promise<import("axios").AxiosResponse<ICommunityResponse[], any, {}>>;
12
- communitiesOf(address: Hex, withGrants: boolean): Promise<import("axios").AxiosResponse<ICommunityResponse[], any, {}>>;
13
- adminOf(address: Hex): Promise<import("axios").AxiosResponse<ICommunityResponse[], any, {}>>;
14
- communityBySlug(slug: string): Promise<import("axios").AxiosResponse<ICommunityResponse, any, {}>>;
15
- communityAdmins(uid: Hex): Promise<import("axios").AxiosResponse<ICommunityAdminsResponse, any, {}>>;
11
+ communities(search?: string): Promise<import("axios").AxiosResponse<ICommunityResponse[], any>>;
12
+ communitiesOf(address: Hex, withGrants: boolean): Promise<import("axios").AxiosResponse<ICommunityResponse[], any>>;
13
+ adminOf(address: Hex): Promise<import("axios").AxiosResponse<ICommunityResponse[], any>>;
14
+ communityBySlug(slug: string): Promise<import("axios").AxiosResponse<ICommunityResponse, any>>;
15
+ communityAdmins(uid: Hex): Promise<import("axios").AxiosResponse<ICommunityAdminsResponse, any>>;
16
16
  /**
17
17
  * Project
18
18
  */
19
- projectBySlug(slug: string): Promise<import("axios").AxiosResponse<IProjectResponse, any, {}>>;
20
- search(query: string): Promise<import("axios").AxiosResponse<ISearchResponse, any, {}>>;
21
- searchProjects(query: string): Promise<import("axios").AxiosResponse<IProjectResponse[], any, {}>>;
22
- projects(name?: string): Promise<import("axios").AxiosResponse<IProjectResponse[], any, {}>>;
23
- projectsOf(grantee: Hex): Promise<import("axios").AxiosResponse<IProjectResponse[], any, {}>>;
24
- projectMilestones(uidOrSlug: string): Promise<import("axios").AxiosResponse<IProjectMilestoneResponse[], any, {}>>;
19
+ projectBySlug(slug: string): Promise<import("axios").AxiosResponse<IProjectResponse, any>>;
20
+ search(query: string): Promise<import("axios").AxiosResponse<ISearchResponse, any>>;
21
+ searchProjects(query: string): Promise<import("axios").AxiosResponse<IProjectResponse[], any>>;
22
+ projects(name?: string): Promise<import("axios").AxiosResponse<IProjectResponse[], any>>;
23
+ projectsOf(grantee: Hex): Promise<import("axios").AxiosResponse<IProjectResponse[], any>>;
24
+ projectMilestones(uidOrSlug: string): Promise<import("axios").AxiosResponse<IProjectMilestoneResponse[], any>>;
25
25
  /**
26
26
  * Grantee
27
27
  */
28
- grantee(address: Hex): Promise<import("axios").AxiosResponse<any, any, {}>>;
28
+ grantee(address: Hex): Promise<import("axios").AxiosResponse<any, any>>;
29
29
  grantees(): Promise<import("axios").AxiosResponse<{
30
30
  [key: `0x${string}`]: {
31
31
  grants: number;
32
32
  projects: number;
33
33
  };
34
- }, any, {}>>;
34
+ }, any>>;
35
35
  /**
36
36
  * Grant
37
37
  */
38
- grantsOf(grantee: Hex, withCommunity?: boolean): Promise<import("axios").AxiosResponse<IGrantResponse[], any, {}>>;
39
- grantsFor(uid: string, withCommunity?: boolean): Promise<import("axios").AxiosResponse<IGrantResponse[], any, {}>>;
40
- grantsForExtProject(projectExtId: string): Promise<import("axios").AxiosResponse<IGrantResponse[], any, {}>>;
41
- grantBySlug(slug: Hex): Promise<import("axios").AxiosResponse<IGrantResponse, any, {}>>;
38
+ grantsOf(grantee: Hex, withCommunity?: boolean): Promise<import("axios").AxiosResponse<IGrantResponse[], any>>;
39
+ grantsFor(uid: string, withCommunity?: boolean): Promise<import("axios").AxiosResponse<IGrantResponse[], any>>;
40
+ grantsForExtProject(projectExtId: string): Promise<import("axios").AxiosResponse<IGrantResponse[], any>>;
41
+ grantBySlug(slug: Hex): Promise<import("axios").AxiosResponse<IGrantResponse, any>>;
42
42
  grantsByCommunity(uid: Hex, page?: number, pageLimit?: number): Promise<import("axios").AxiosResponse<{
43
43
  data: IGrantResponse[];
44
- }, any, {}>>;
44
+ }, any>>;
45
45
  /**
46
46
  * Milestone
47
47
  */
48
- milestonesOf(uid: Hex): Promise<import("axios").AxiosResponse<any, any, {}>>;
48
+ milestonesOf(uid: Hex): Promise<import("axios").AxiosResponse<any, any>>;
49
49
  slugExists(slug: string): Promise<boolean>;
50
50
  /**
51
51
  * Tracks
52
52
  */
53
- getTracks(communityUID: string, includeArchived?: boolean): Promise<import("axios").AxiosResponse<ITrackResponse[], any, {}>>;
54
- getTrackById(id: string): Promise<import("axios").AxiosResponse<ITrackResponse, any, {}>>;
53
+ getTracks(communityUID: string, includeArchived?: boolean): Promise<import("axios").AxiosResponse<ITrackResponse[], any>>;
54
+ getTrackById(id: string): Promise<import("axios").AxiosResponse<ITrackResponse, any>>;
55
55
  createTrack(data: {
56
56
  name: string;
57
57
  description?: string;
58
58
  communityUID: string;
59
- }): Promise<import("axios").AxiosResponse<ITrackResponse, any, {}>>;
59
+ }): Promise<import("axios").AxiosResponse<ITrackResponse, any>>;
60
60
  updateTrack(id: string, data: {
61
61
  name?: string;
62
62
  description?: string;
63
63
  communityUID?: string;
64
- }): Promise<import("axios").AxiosResponse<ITrackResponse, any, {}>>;
65
- archiveTrack(id: string): Promise<import("axios").AxiosResponse<ITrackResponse, any, {}>>;
66
- assignTracksToProgram(programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<ITrackAssignmentResponse[], any, {}>>;
67
- unassignTrackFromProgram(programId: string, trackId: string): Promise<import("axios").AxiosResponse<ITrackAssignmentResponse, any, {}>>;
68
- getTracksForProgram(programId: string): Promise<import("axios").AxiosResponse<ITrackResponse[], any, {}>>;
69
- getTracksForProject(projectId: string, programId: string, activeOnly?: boolean): Promise<import("axios").AxiosResponse<ITrackResponse[], any, {}>>;
70
- assignTracksToProject(projectId: string, programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<any[], any, {}>>;
71
- unassignTracksFromProject(projectId: string, programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<any[], any, {}>>;
72
- getProjectsByTrack(communityId: string, programId: string, trackId?: string): Promise<import("axios").AxiosResponse<IProjectTrackResponse[], any, {}>>;
64
+ }): Promise<import("axios").AxiosResponse<ITrackResponse, any>>;
65
+ archiveTrack(id: string): Promise<import("axios").AxiosResponse<ITrackResponse, any>>;
66
+ assignTracksToProgram(programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<ITrackAssignmentResponse[], any>>;
67
+ unassignTrackFromProgram(programId: string, trackId: string): Promise<import("axios").AxiosResponse<ITrackAssignmentResponse, any>>;
68
+ getTracksForProgram(programId: string): Promise<import("axios").AxiosResponse<ITrackResponse[], any>>;
69
+ getTracksForProject(projectId: string, programId: string, activeOnly?: boolean): Promise<import("axios").AxiosResponse<ITrackResponse[], any>>;
70
+ assignTracksToProject(projectId: string, programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<any[], any>>;
71
+ unassignTracksFromProject(projectId: string, programId: string, trackIds: string[]): Promise<import("axios").AxiosResponse<any[], any>>;
72
+ getProjectsByTrack(communityId: string, programId: string, trackId?: string): Promise<import("axios").AxiosResponse<IProjectTrackResponse[], any>>;
73
73
  }
@@ -0,0 +1,23 @@
1
+ import { RemoteStorage } from "./RemoteStorage";
2
+ import { TRemoteStorageOutput } from "core/types";
3
+ export interface IpfsStorageOptions {
4
+ token: string;
5
+ }
6
+ export declare class IpfsStorage extends RemoteStorage {
7
+ private pinataJWTToken;
8
+ constructor(opts: IpfsStorageOptions,
9
+ /**
10
+ * If set, will send request to another server instead of
11
+ * using the local instance
12
+ */
13
+ sponsor?: RemoteStorage["sponsor"]);
14
+ private assert;
15
+ save<T = unknown>(data: T): Promise<string>;
16
+ encode(data: string): TRemoteStorageOutput<string>;
17
+ get<T = unknown>(args: {
18
+ cid: string;
19
+ }): Promise<T>;
20
+ saveAndGetCID(data: any, pinataMetadata?: {
21
+ name: string;
22
+ }): Promise<any>;
23
+ }
@@ -0,0 +1,56 @@
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.IpfsStorage = void 0;
7
+ const RemoteStorage_1 = require("./RemoteStorage");
8
+ const SchemaError_1 = require("../SchemaError");
9
+ const utils_1 = require("../../utils");
10
+ const axios_1 = __importDefault(require("axios"));
11
+ class IpfsStorage extends RemoteStorage_1.RemoteStorage {
12
+ constructor(opts,
13
+ /**
14
+ * If set, will send request to another server instead of
15
+ * using the local instance
16
+ */
17
+ sponsor) {
18
+ super(0 /* STORAGE_TYPE.IPFS */, sponsor);
19
+ this.assert(opts);
20
+ this.pinataJWTToken = opts.token;
21
+ }
22
+ assert(opts) { }
23
+ async save(data) {
24
+ try {
25
+ const cid = await this.saveAndGetCID(data);
26
+ return cid;
27
+ }
28
+ catch (error) {
29
+ throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
30
+ }
31
+ }
32
+ encode(data) {
33
+ return { hash: data, storageType: this.storageType };
34
+ }
35
+ async get(args) {
36
+ return (0, utils_1.getIPFSData)(args.cid);
37
+ }
38
+ async saveAndGetCID(data, pinataMetadata = { name: "via karma-gap-sdk" }) {
39
+ try {
40
+ const res = await axios_1.default.post("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
41
+ pinataContent: data,
42
+ pinataMetadata: pinataMetadata,
43
+ }, {
44
+ headers: {
45
+ "Content-Type": "application/json",
46
+ Authorization: `Bearer ${this.pinataJWTToken}`,
47
+ },
48
+ });
49
+ return res.data.IpfsHash;
50
+ }
51
+ catch (error) {
52
+ throw new SchemaError_1.RemoteStorageError("REMOTE_STORAGE_UPLOAD", `Error adding data to IPFS`);
53
+ }
54
+ }
55
+ }
56
+ exports.IpfsStorage = IpfsStorage;
@@ -0,0 +1,41 @@
1
+ import { STORAGE_TYPE, TRemoteStorageOutput } from 'core/types';
2
+ interface SponsoredRemote {
3
+ url: string;
4
+ responseParser: (response: any) => string;
5
+ }
6
+ export declare abstract class RemoteStorage<C = unknown> {
7
+ protected client: C;
8
+ readonly storageType: number;
9
+ readonly sponsor?: SponsoredRemote;
10
+ constructor(storageType: STORAGE_TYPE,
11
+ /**
12
+ * If set, will try to POST request to another server instead of
13
+ * using the local instance.
14
+ *
15
+ * > If a response parser is not set, it will try to get { cid: string }.
16
+ */
17
+ sponsor: SponsoredRemote);
18
+ /**
19
+ * Try to save data to remote storage and return the CID.
20
+ * IF sponsorUrl is set, this method will be automatically
21
+ * intercepted and will send a POST request to the sponsorUrl
22
+ * with the contents: `{ data: T, type: "<AttestationType>" }`
23
+ */
24
+ abstract save<T = unknown>(data: T, schemaName: string): Promise<string>;
25
+ /**
26
+ * Encodes the data according to the remote storage type parameters
27
+ * OR returns the data as is if no encoding is required
28
+ */
29
+ abstract encode(data: unknown): TRemoteStorageOutput;
30
+ /**
31
+ * Get data from Remote Storage
32
+ */
33
+ abstract get<T = unknown>(args: unknown): Promise<T>;
34
+ /**
35
+ * If sponsorUrl is set, intercept the save method and send a POST request
36
+ * to the sponsorUrl instead of using the local instance.
37
+ * @returns
38
+ */
39
+ private interceptRemoteStorage;
40
+ }
41
+ export {};
@@ -0,0 +1,38 @@
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.RemoteStorage = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class RemoteStorage {
9
+ constructor(storageType,
10
+ /**
11
+ * If set, will try to POST request to another server instead of
12
+ * using the local instance.
13
+ *
14
+ * > If a response parser is not set, it will try to get { cid: string }.
15
+ */
16
+ sponsor) {
17
+ this.storageType = storageType;
18
+ this.sponsor = sponsor;
19
+ this.interceptRemoteStorage();
20
+ }
21
+ /**
22
+ * If sponsorUrl is set, intercept the save method and send a POST request
23
+ * to the sponsorUrl instead of using the local instance.
24
+ * @returns
25
+ */
26
+ interceptRemoteStorage() {
27
+ if (!this.sponsor?.url)
28
+ return;
29
+ this.save = async (data, schemaName) => {
30
+ const { data: response } = await axios_1.default.post(this.sponsor.url, {
31
+ data: data,
32
+ type: schemaName,
33
+ });
34
+ return this.sponsor.responseParser?.(response) || response.cid;
35
+ };
36
+ }
37
+ }
38
+ exports.RemoteStorage = RemoteStorage;
@@ -0,0 +1 @@
1
+ export declare function getIPFSData<T>(cid: string): Promise<T>;
@@ -0,0 +1,19 @@
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.getIPFSData = getIPFSData;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ async function getIPFSData(cid) {
9
+ try {
10
+ const { data } = await axios_1.default.get(`https://ipfs.io/ipfs/${cid}`, {
11
+ timeout: 5000,
12
+ });
13
+ return data;
14
+ }
15
+ catch (err) {
16
+ console.error(err);
17
+ throw new Error(`Error to retrive data for CID: ${cid}`);
18
+ }
19
+ }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.4.24",
6
+ "version": "0.4.25",
7
7
  "description": "Simple and easy interface between EAS and Karma.",
8
8
  "main": "./index.js",
9
9
  "author": "KarmaHQ",