@sogni-ai/sogni-client 0.0.8 → 0.0.9

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 (89) hide show
  1. package/dist/Account/CurrentAccount.d.ts +26 -0
  2. package/dist/Account/CurrentAccount.js +76 -0
  3. package/dist/Account/CurrentAccount.js.map +1 -0
  4. package/dist/Account/index.d.ts +31 -0
  5. package/dist/Account/index.js +172 -0
  6. package/dist/Account/index.js.map +1 -0
  7. package/dist/Account/types.d.ts +57 -0
  8. package/dist/Account/types.js +3 -0
  9. package/dist/Account/types.js.map +1 -0
  10. package/dist/ApiClient/ApiClient.d.ts +42 -0
  11. package/dist/ApiClient/ApiClient.js +79 -0
  12. package/dist/ApiClient/ApiClient.js.map +1 -0
  13. package/dist/ApiClient/WebSocketClient/ErrorCode.d.ts +7 -0
  14. package/dist/ApiClient/WebSocketClient/ErrorCode.js +18 -0
  15. package/dist/ApiClient/WebSocketClient/ErrorCode.js.map +1 -0
  16. package/dist/ApiClient/WebSocketClient/events.d.ts +83 -0
  17. package/dist/ApiClient/WebSocketClient/events.js +3 -0
  18. package/dist/ApiClient/WebSocketClient/events.js.map +1 -0
  19. package/dist/ApiClient/WebSocketClient/index.d.ts +28 -0
  20. package/dist/ApiClient/WebSocketClient/index.js +166 -0
  21. package/dist/ApiClient/WebSocketClient/index.js.map +1 -0
  22. package/dist/ApiClient/WebSocketClient/messages.d.ts +5 -0
  23. package/dist/ApiClient/WebSocketClient/messages.js +3 -0
  24. package/dist/ApiClient/WebSocketClient/messages.js.map +1 -0
  25. package/dist/ApiClient/WebSocketClient/types.d.ts +1 -0
  26. package/dist/ApiClient/WebSocketClient/types.js +3 -0
  27. package/dist/ApiClient/WebSocketClient/types.js.map +1 -0
  28. package/dist/ApiClient/events.d.ts +19 -0
  29. package/dist/ApiClient/events.js +3 -0
  30. package/dist/ApiClient/events.js.map +1 -0
  31. package/dist/ApiGroup.d.ts +16 -0
  32. package/dist/ApiGroup.js +16 -0
  33. package/dist/ApiGroup.js.map +1 -0
  34. package/dist/Projects/Job.d.ts +31 -0
  35. package/dist/Projects/Job.js +52 -0
  36. package/dist/Projects/Job.js.map +1 -0
  37. package/dist/Projects/Project.d.ts +50 -0
  38. package/dist/Projects/Project.js +94 -0
  39. package/dist/Projects/Project.js.map +1 -0
  40. package/dist/Projects/createJobRequestMessage.d.ts +63 -0
  41. package/dist/Projects/createJobRequestMessage.js +68 -0
  42. package/dist/Projects/createJobRequestMessage.js.map +1 -0
  43. package/dist/Projects/index.d.ts +41 -0
  44. package/dist/Projects/index.js +253 -0
  45. package/dist/Projects/index.js.map +1 -0
  46. package/dist/Projects/models.json +8906 -0
  47. package/dist/Projects/types/EstimationResponse.d.ts +40 -0
  48. package/dist/Projects/types/EstimationResponse.js +3 -0
  49. package/dist/Projects/types/EstimationResponse.js.map +1 -0
  50. package/dist/Projects/types/events.d.ts +51 -0
  51. package/dist/Projects/types/events.js +3 -0
  52. package/dist/Projects/types/events.js.map +1 -0
  53. package/dist/Projects/types/index.d.ts +58 -0
  54. package/dist/Projects/types/index.js +3 -0
  55. package/dist/Projects/types/index.js.map +1 -0
  56. package/dist/Stats/index.d.ts +6 -0
  57. package/dist/Stats/index.js +25 -0
  58. package/dist/Stats/index.js.map +1 -0
  59. package/dist/Stats/types.d.ts +19 -0
  60. package/dist/Stats/types.js +3 -0
  61. package/dist/Stats/types.js.map +1 -0
  62. package/dist/index.d.ts +39 -0
  63. package/dist/index.js +81 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/lib/DataEntity.d.ts +18 -0
  66. package/dist/lib/DataEntity.js +31 -0
  67. package/dist/lib/DataEntity.js.map +1 -0
  68. package/dist/lib/EIP712Helper.d.ts +13 -0
  69. package/dist/lib/EIP712Helper.js +39 -0
  70. package/dist/lib/EIP712Helper.js.map +1 -0
  71. package/dist/lib/RestClient.d.ts +18 -0
  72. package/dist/lib/RestClient.js +69 -0
  73. package/dist/lib/RestClient.js.map +1 -0
  74. package/dist/lib/TypedEventEmitter.d.ts +34 -0
  75. package/dist/lib/TypedEventEmitter.js +58 -0
  76. package/dist/lib/TypedEventEmitter.js.map +1 -0
  77. package/dist/lib/base64.d.ts +2 -0
  78. package/dist/lib/base64.js +15 -0
  79. package/dist/lib/base64.js.map +1 -0
  80. package/dist/lib/isNodejs.d.ts +2 -0
  81. package/dist/lib/isNodejs.js +5 -0
  82. package/dist/lib/isNodejs.js.map +1 -0
  83. package/dist/types/ErrorData.d.ts +5 -0
  84. package/dist/types/ErrorData.js +3 -0
  85. package/dist/types/ErrorData.js.map +1 -0
  86. package/dist/types/json.d.ts +5 -0
  87. package/dist/types/json.js +3 -0
  88. package/dist/types/json.js.map +1 -0
  89. package/package.json +1 -1
@@ -0,0 +1,40 @@
1
+ export interface EstimationResponse {
2
+ request: Request;
3
+ rate: Rate;
4
+ quote: Quote;
5
+ }
6
+ export interface Quote {
7
+ model: Model;
8
+ job: Job;
9
+ project: Job;
10
+ }
11
+ export interface Job {
12
+ costInRenderSec: string;
13
+ costInUSD: string;
14
+ costInToken: string;
15
+ calculatedStepCount?: number;
16
+ }
17
+ export interface Model {
18
+ weight: string;
19
+ secPerStep: string;
20
+ secPerPreview: string;
21
+ secForCN: string;
22
+ }
23
+ export interface Rate {
24
+ costPerBaseHQRenderInUSD: string;
25
+ tokenMarkePriceUSD: string;
26
+ costPerRenderSecUSD: string;
27
+ costPerRenderSecToken: string;
28
+ network: string;
29
+ networkCostMultiplier: string;
30
+ }
31
+ export interface Request {
32
+ model: string;
33
+ name: string;
34
+ imageCount: number;
35
+ stepCount: number;
36
+ previewCount: number;
37
+ cnEnabled: boolean;
38
+ denoiseStrength: string;
39
+ time: Date;
40
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EstimationResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EstimationResponse.js","sourceRoot":"","sources":["../../../src/Projects/types/EstimationResponse.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import { AvailableModel } from './index';
2
+ import ErrorData from '../../types/ErrorData';
3
+ export interface ProjectEventBase {
4
+ projectId: string;
5
+ }
6
+ export interface ProjectQueued extends ProjectEventBase {
7
+ type: 'queued';
8
+ queuePosition: number;
9
+ }
10
+ export interface ProjectCompleted extends ProjectEventBase {
11
+ type: 'completed';
12
+ }
13
+ export interface ProjectError extends ProjectEventBase {
14
+ type: 'error';
15
+ error: ErrorData;
16
+ }
17
+ export type ProjectEvent = ProjectQueued | ProjectCompleted | ProjectError;
18
+ export interface JobEventBase {
19
+ projectId: string;
20
+ jobId: string;
21
+ }
22
+ export interface JobInitiating extends JobEventBase {
23
+ type: 'initiating';
24
+ }
25
+ export interface JobStarted extends JobEventBase {
26
+ type: 'started';
27
+ }
28
+ export interface JobProgress extends JobEventBase {
29
+ type: 'progress';
30
+ step: number;
31
+ stepCount: number;
32
+ }
33
+ export interface JobPreview extends JobEventBase {
34
+ type: 'preview';
35
+ url: string;
36
+ }
37
+ export interface JobCompleted extends JobEventBase {
38
+ type: 'completed';
39
+ steps: number;
40
+ resultUrl: string;
41
+ }
42
+ export interface JobError extends JobEventBase {
43
+ type: 'error';
44
+ error: ErrorData;
45
+ }
46
+ export type JobEvent = JobInitiating | JobStarted | JobProgress | JobPreview | JobCompleted | JobError;
47
+ export interface ProjectApiEvents {
48
+ availableModels: AvailableModel[];
49
+ project: ProjectEvent;
50
+ job: JobEvent;
51
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../../src/Projects/types/events.ts"],"names":[],"mappings":""}
@@ -0,0 +1,58 @@
1
+ import { SupernetType } from '../../ApiClient/WebSocketClient/types';
2
+ export interface AvailableModel {
3
+ id: string;
4
+ name: string;
5
+ workerCount: number;
6
+ }
7
+ export interface AiModel {
8
+ isSD3: boolean;
9
+ modelShortName: string;
10
+ isIOSslowest: boolean;
11
+ hasOriginalVersionOnly: boolean;
12
+ isUserModel: boolean;
13
+ isTurboXL: boolean;
14
+ isRealistic: boolean;
15
+ isArtistic: boolean;
16
+ tier: string;
17
+ splitAttentionSuffix: string;
18
+ isSD3XL: boolean;
19
+ originalAttentionSuffix: string;
20
+ isLCM: boolean;
21
+ zipWeight: number;
22
+ modelId: string;
23
+ modelVersion: string;
24
+ parentId: string;
25
+ quantized: boolean;
26
+ isXL: boolean;
27
+ splitAttentionV2Suffix: string;
28
+ supportsAttentionV2: boolean;
29
+ supportsControlNet: boolean;
30
+ supportsEncoder: boolean;
31
+ onlySplitEinsumV2available: boolean;
32
+ customSize?: number[];
33
+ }
34
+ export interface ProjectParams {
35
+ modelId: string;
36
+ positivePrompt: string;
37
+ negativePrompt: string;
38
+ stylePrompt: string;
39
+ steps: number;
40
+ guidance: number;
41
+ seed: string;
42
+ numberOfImages: number;
43
+ }
44
+ export type ImageUrlParams = {
45
+ imageId: string;
46
+ jobId: string;
47
+ type: 'preview' | 'complete' | 'startingImage' | 'cnImage';
48
+ startContentType?: string;
49
+ };
50
+ export interface EstimateRequest {
51
+ network: SupernetType;
52
+ model: string;
53
+ imageCount: number;
54
+ stepCount: number;
55
+ previewCount: number;
56
+ cnEnabled?: boolean;
57
+ denoiseStrength?: number;
58
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/Projects/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import ApiGroup from '../ApiGroup';
2
+ import { LeaderboardItem, LeaderboardParams } from './types';
3
+ declare class StatsApi extends ApiGroup {
4
+ leaderboard(params: LeaderboardParams): Promise<LeaderboardItem[]>;
5
+ }
6
+ export default StatsApi;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ApiGroup_1 = __importDefault(require("../ApiGroup"));
16
+ class StatsApi extends ApiGroup_1.default {
17
+ leaderboard(params) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const res = yield this.client.rest.get('/v1/leaderboard/', params);
20
+ return res.data;
21
+ });
22
+ }
23
+ }
24
+ exports.default = StatsApi;
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Stats/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,2DAAmC;AAInC,MAAM,QAAS,SAAQ,kBAAQ;IACvB,WAAW,CAAC,MAAyB;;YACzC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CACpC,kBAAkB,EAClB,MAAM,CACP,CAAC;YACF,OAAO,GAAG,CAAC,IAAI,CAAC;QAClB,CAAC;KAAA;CACF;AAED,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,19 @@
1
+ export type LeaderboardType = 'renderUSDCompleteWorker' | 'renderUSDCompleteArtist' | 'renderSecCompleteWorker' | 'renderSecCompleteArtist' | 'renderTokenCompleteWorker' | 'renderTokenCompleteArtist' | 'jobCompleteWorker' | 'jobCompleteArtist' | 'projectCompleteArtist' | 'uloginWorker' | 'uloginArtist' | 'tokenVolume' | 'referral';
2
+ export interface LeaderboardParams {
3
+ type: LeaderboardType;
4
+ period: 'day' | 'lifetime';
5
+ username?: string;
6
+ network?: 'fast' | 'relaxed' | 'all';
7
+ page?: number;
8
+ limit?: number;
9
+ date?: number;
10
+ address?: string;
11
+ }
12
+ export interface LeaderboardItem {
13
+ rank: number;
14
+ username: string;
15
+ address: string;
16
+ country: string;
17
+ value: string;
18
+ role: string;
19
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/Stats/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import AccountApi from './Account';
2
+ import { ApiError } from './ApiClient/ApiClient';
3
+ import ProjectsApi from './Projects';
4
+ import StatsApi from './Stats';
5
+ import { AvailableModel } from './Projects/types';
6
+ import CurrentAccount from './Account/CurrentAccount';
7
+ import DataEntity from './lib/DataEntity';
8
+ import Project, { ProjectStatus } from './Projects/Project';
9
+ import Job, { JobStatus } from './Projects/Job';
10
+ import { SupernetType } from './ApiClient/WebSocketClient/types';
11
+ import ErrorData from './types/ErrorData';
12
+ import * as ProjectApiEvents from './Projects/types/events';
13
+ export type { AvailableModel, CurrentAccount, DataEntity, ErrorData, Job, JobStatus, ProjectApiEvents, ProjectStatus, Project, SupernetType };
14
+ export { ApiError };
15
+ export interface BaseConfig {
16
+ appId: string;
17
+ restEndpoint: string;
18
+ socketEndpoint: string;
19
+ }
20
+ export interface SimpleConfig extends BaseConfig {
21
+ testnet: boolean;
22
+ }
23
+ export interface FullConfig extends BaseConfig {
24
+ jsonRpcUrl: string;
25
+ }
26
+ export type SogniClientConfig = SimpleConfig | FullConfig;
27
+ export declare class SogniClient {
28
+ account: AccountApi;
29
+ projects: ProjectsApi;
30
+ stats: StatsApi;
31
+ private constructor();
32
+ get currentAccount(): CurrentAccount;
33
+ /**
34
+ * Instance creation may involve async operations, so we use a static method
35
+ * @param config
36
+ */
37
+ static createInstance(config: SogniClientConfig): Promise<SogniClient>;
38
+ }
39
+ export default SogniClient;
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.SogniClient = exports.ApiError = void 0;
39
+ const ethers_1 = require("ethers");
40
+ const Account_1 = __importDefault(require("./Account"));
41
+ const ApiClient_1 = __importStar(require("./ApiClient/ApiClient"));
42
+ Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return ApiClient_1.ApiError; } });
43
+ const EIP712Helper_1 = __importDefault(require("./lib/EIP712Helper"));
44
+ const Projects_1 = __importDefault(require("./Projects"));
45
+ const Stats_1 = __importDefault(require("./Stats"));
46
+ class SogniClient {
47
+ constructor(config) {
48
+ this.account = new Account_1.default(config);
49
+ this.projects = new Projects_1.default(config);
50
+ this.stats = new Stats_1.default(config);
51
+ }
52
+ get currentAccount() {
53
+ return this.account.currentAccount;
54
+ }
55
+ /**
56
+ * Instance creation may involve async operations, so we use a static method
57
+ * @param config
58
+ */
59
+ static createInstance(config) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ const client = new ApiClient_1.default(config.restEndpoint, config.socketEndpoint, config.appId);
62
+ let provider;
63
+ if ('jsonRpcUrl' in config) {
64
+ provider = new ethers_1.JsonRpcProvider(config.jsonRpcUrl);
65
+ }
66
+ else {
67
+ provider = (0, ethers_1.getDefaultProvider)(config.testnet ? 84532 : 8453);
68
+ }
69
+ const chainId = yield provider.getNetwork().then((network) => network.chainId);
70
+ const eip712 = new EIP712Helper_1.default({
71
+ name: 'Sogni-testnet',
72
+ version: '1',
73
+ chainId: chainId.toString()
74
+ });
75
+ return new SogniClient({ client, provider, eip712 });
76
+ });
77
+ }
78
+ }
79
+ exports.SogniClient = SogniClient;
80
+ exports.default = SogniClient;
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAI,WAAW,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACvD,CAAC;KAAA;CACF;AAnCD,kCAmCC;AAED,kBAAe,WAAW,CAAC"}
@@ -0,0 +1,18 @@
1
+ import TypedEventEmitter from './TypedEventEmitter';
2
+ export interface EntityEvents {
3
+ updated: string[];
4
+ }
5
+ declare abstract class DataEntity<D, E extends EntityEvents = EntityEvents> extends TypedEventEmitter<E> {
6
+ protected data: D;
7
+ constructor(data: D);
8
+ /**
9
+ * @internal
10
+ * @param delta
11
+ */
12
+ _update(delta: Partial<D>): void;
13
+ /**
14
+ * Get a copy of the entity's data
15
+ */
16
+ toJSON(): D;
17
+ }
18
+ export default DataEntity;
@@ -0,0 +1,31 @@
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
+ const lodash_1 = require("lodash");
7
+ const TypedEventEmitter_1 = __importDefault(require("./TypedEventEmitter"));
8
+ class DataEntity extends TypedEventEmitter_1.default {
9
+ constructor(data) {
10
+ super();
11
+ this.data = data;
12
+ }
13
+ /**
14
+ * @internal
15
+ * @param delta
16
+ */
17
+ _update(delta) {
18
+ //@ts-ignore
19
+ const changedKeys = Object.keys(delta).filter((key) => this.data[key] !== delta[key]);
20
+ this.data = Object.assign(Object.assign({}, this.data), delta);
21
+ this.emit('updated', changedKeys);
22
+ }
23
+ /**
24
+ * Get a copy of the entity's data
25
+ */
26
+ toJSON() {
27
+ return (0, lodash_1.cloneDeep)(this.data);
28
+ }
29
+ }
30
+ exports.default = DataEntity;
31
+ //# sourceMappingURL=DataEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DataEntity.js","sourceRoot":"","sources":["../../src/lib/DataEntity.ts"],"names":[],"mappings":";;;;;AAAA,mCAAmC;AACnC,4EAAoD;AAMpD,MAAe,UAAqD,SAAQ,2BAAoB;IAG9F,YAAY,IAAO;QACjB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAiB;QACvB,YAAY;QACZ,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QACtF,IAAI,CAAC,IAAI,mCAAQ,IAAI,CAAC,IAAI,GAAK,KAAK,CAAE,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAA,kBAAS,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { AbstractSigner } from 'ethers';
2
+ type SupportedTypes = 'authentication' | 'signup';
3
+ interface Options {
4
+ name: string;
5
+ version: string;
6
+ chainId: string;
7
+ }
8
+ declare class EIP712Helper {
9
+ private readonly EIP712Domain;
10
+ constructor(options: Options);
11
+ signTypedData(signer: AbstractSigner, type: SupportedTypes, data: Record<string, string | number>): Promise<string>;
12
+ }
13
+ export default EIP712Helper;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const EIP712_TYPES = {
4
+ authentication: {
5
+ Authentication: [
6
+ { name: 'walletAddress', type: 'address' },
7
+ { name: 'nonce', type: 'string' }
8
+ ]
9
+ },
10
+ signup: {
11
+ Signup: [
12
+ { name: 'appid', type: 'string' },
13
+ { name: 'username', type: 'string' },
14
+ { name: 'email', type: 'string' },
15
+ { name: 'subscribe', type: 'uint256' },
16
+ { name: 'walletAddress', type: 'address' },
17
+ { name: 'nonce', type: 'string' }
18
+ ]
19
+ }
20
+ };
21
+ class EIP712Helper {
22
+ constructor(options) {
23
+ this.EIP712Domain = {
24
+ name: options.name,
25
+ version: options.version,
26
+ chainId: options.chainId,
27
+ verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
28
+ };
29
+ }
30
+ signTypedData(signer, type, data) {
31
+ const types = EIP712_TYPES[type];
32
+ if (!types) {
33
+ throw new Error(`Unknown type: ${type}`);
34
+ }
35
+ return signer.signTypedData(this.EIP712Domain, types, data);
36
+ }
37
+ }
38
+ exports.default = EIP712Helper;
39
+ //# sourceMappingURL=EIP712Helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EIP712Helper.js","sourceRoot":"","sources":["../../src/lib/EIP712Helper.ts"],"names":[],"mappings":";;AAKA,MAAM,YAAY,GAAwC;IACxD,cAAc,EAAE;QACd,cAAc,EAAE;YACd,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE;YAC1C,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;SAClC;KACF;IACD,MAAM,EAAE;QACN,MAAM,EAAE;YACN,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;YACjC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE;YACpC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;YACjC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE;YACtC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,EAAE;YAC1C,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE;SAClC;KACF;CACF,CAAC;AAQF,MAAM,YAAY;IAGhB,YAAY,OAAgB;QAC1B,IAAI,CAAC,YAAY,GAAG;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,iBAAiB,EAAE,4CAA4C;SAChE,CAAC;IACJ,CAAC;IAED,aAAa,CACX,MAAsB,EACtB,IAAoB,EACpB,IAAqC;QAErC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9D,CAAC;CACF;AAED,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,18 @@
1
+ import TypedEventEmitter, { EventMap } from './TypedEventEmitter';
2
+ import { JSONValue } from '../types/json';
3
+ export interface AuthData {
4
+ token: string;
5
+ }
6
+ declare class RestClient<E extends EventMap = never> extends TypedEventEmitter<E> {
7
+ readonly baseUrl: string;
8
+ _auth: AuthData | null;
9
+ constructor(baseUrl: string);
10
+ get auth(): AuthData | null;
11
+ set auth(auth: AuthData | null);
12
+ private formatUrl;
13
+ private request;
14
+ private processResponse;
15
+ get<T = JSONValue>(path: string, query?: Record<string, any>): Promise<T>;
16
+ post<T = JSONValue>(path: string, body?: Record<string, unknown>): Promise<T>;
17
+ }
18
+ export default RestClient;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const ApiClient_1 = require("../ApiClient/ApiClient");
16
+ const TypedEventEmitter_1 = __importDefault(require("./TypedEventEmitter"));
17
+ class RestClient extends TypedEventEmitter_1.default {
18
+ constructor(baseUrl) {
19
+ super();
20
+ this._auth = null;
21
+ this.baseUrl = baseUrl;
22
+ }
23
+ get auth() {
24
+ return this._auth;
25
+ }
26
+ set auth(auth) {
27
+ this._auth = auth;
28
+ }
29
+ formatUrl(relativeUrl, query = {}) {
30
+ const url = new URL(relativeUrl, this.baseUrl);
31
+ Object.keys(query).forEach((key) => {
32
+ url.searchParams.append(key, query[key]);
33
+ });
34
+ return url.toString();
35
+ }
36
+ request(url, options = {}) {
37
+ return fetch(url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, (options.headers || {})), (this.auth ? { Authorization: this.auth.token } : {})) })).then((r) => this.processResponse(r));
38
+ }
39
+ processResponse(response) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ let responseData;
42
+ try {
43
+ responseData = yield response.json();
44
+ }
45
+ catch (e) {
46
+ console.error('Failed to parse response:', e);
47
+ throw new Error('Failed to parse response');
48
+ }
49
+ if (!response.ok) {
50
+ throw new ApiClient_1.ApiError(response.status, responseData);
51
+ }
52
+ return responseData;
53
+ });
54
+ }
55
+ get(path, query = {}) {
56
+ return this.request(this.formatUrl(path, query), query);
57
+ }
58
+ post(path, body = {}) {
59
+ return this.request(this.formatUrl(path), {
60
+ method: 'POST',
61
+ headers: {
62
+ 'Content-Type': 'application/json'
63
+ },
64
+ body: JSON.stringify(body)
65
+ });
66
+ }
67
+ }
68
+ exports.default = RestClient;
69
+ //# sourceMappingURL=RestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RestClient.js","sourceRoot":"","sources":["../../src/lib/RestClient.ts"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Y,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACvC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,CAAC,CAAC,CAAC;gBAC9C,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;YAC9C,CAAC;YACD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,IAAI,oBAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAgC,CAAC,CAAC;YACxE,CAAC;YACD,OAAO,YAAyB,CAAC;QACnC,CAAC;KAAA;IAED,GAAG,CAAgB,IAAY,EAAE,QAA6B,EAAE;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAI,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAgB,IAAY,EAAE,OAAgC,EAAE;QAClE,OAAO,IAAI,CAAC,OAAO,CAAI,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC3C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,34 @@
1
+ export interface EventMap {
2
+ [event: string]: any;
3
+ }
4
+ export type EventListener<D> = (data: D) => void;
5
+ declare abstract class TypedEventEmitter<E extends EventMap> {
6
+ protected listeners: {
7
+ [K in keyof E]?: EventListener<E[K]>[];
8
+ };
9
+ /**
10
+ * Add an event listener, returns a function that can be called to remove the listener
11
+ * @param event
12
+ * @param listener
13
+ */
14
+ on<T extends keyof E>(event: T, listener: EventListener<E[T]>): () => void;
15
+ /**
16
+ * Add an event listener that will be called only once
17
+ * @param event
18
+ * @param listener
19
+ */
20
+ once<T extends keyof E>(event: T, listener: EventListener<E[T]>): () => void;
21
+ /**
22
+ * Remove an event listener
23
+ * @param event
24
+ * @param listener
25
+ */
26
+ off<T extends keyof E>(event: T, listener: EventListener<E[T]>): void;
27
+ /**
28
+ * Dispatch an event to all listeners
29
+ * @param event
30
+ * @param data
31
+ */
32
+ emit<T extends keyof E>(event: T, data: E[T]): void;
33
+ }
34
+ export default TypedEventEmitter;