codatta-frontier-sdk 0.1.3 → 0.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.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("axios");/*! js-cookie v3.0.5 | MIT */function u(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)r[n]=e[n]}return r}var g={read:function(r){return r[0]==='"'&&(r=r.slice(1,-1)),r.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(r){return encodeURIComponent(r).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function l(r,t){function e(o,i,s){if(!(typeof document>"u")){s=u({},t,s),typeof s.expires=="number"&&(s.expires=new Date(Date.now()+s.expires*864e5)),s.expires&&(s.expires=s.expires.toUTCString()),o=encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var c="";for(var a in s)s[a]&&(c+="; "+a,s[a]!==!0&&(c+="="+s[a].split(";")[0]));return document.cookie=o+"="+r.write(i,o)+c}}function n(o){if(!(typeof document>"u"||arguments.length&&!o)){for(var i=document.cookie?document.cookie.split("; "):[],s={},c=0;c<i.length;c++){var a=i[c].split("="),m=a.slice(1).join("=");try{var p=decodeURIComponent(a[0]);if(s[p]=r.read(m,p),o===p)break}catch{}}return o?s[o]:s}}return Object.create({set:e,get:n,remove:function(o,i){e(o,"",u({},i,{expires:-1}))},withAttributes:function(o){return l(this.converter,u({},this.attributes,o))},withConverter:function(o){return l(u({},this.converter,o),this.attributes)}},{attributes:{value:Object.freeze(t)},converter:{value:Object.freeze(r)}})}var h=l(g,{path:"/"});class v{constructor(){this.request=d.create({timeout:3e4}),this.setupRequestInterceptor(),this.setupResponseInterceptor()}setupRequestInterceptor(){this.request.interceptors.request.use(t=>{var s;const e=navigator.userAgent.toLowerCase(),n=e.includes("codatta")||((s=location.hash)==null?void 0:s.toLowerCase().includes("codatta")),o=h.get("auth")||localStorage.getItem("auth"),i=/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(e);return o&&(t.headers.token=o),t.headers.channel=n?"codatta-ios-app":"codatta-platform-website",t.headers.device=i?"mobile":"web",t})}setupResponseInterceptor(){this.request.interceptors.response.use(t=>{const e=t.data,n=Object.getOwnPropertyNames(e).includes("code"),o=Object.getOwnPropertyNames(e).includes("success");return n&&(e==null?void 0:e.code)!=="000000"?Promise.reject(new d.AxiosError(e==null?void 0:e.message,e==null?void 0:e.code,t.config,t.request,t)):o&&(e==null?void 0:e.success)!==!0?Promise.reject(new d.AxiosError(e==null?void 0:e.errorMessage,e==null?void 0:e.errorCode,t.config,t.request,t)):t},t=>{if(t.status===401){localStorage.removeItem("uid"),localStorage.removeItem("token"),localStorage.removeItem("auth");const e=new URL(window.location.href),n=e.pathname+e.search;window.location.href=`/account/signin?from=${encodeURIComponent(n)}`}return Promise.reject(t)})}async getTaskDetail(t){return(await this.request.post("/api/v2/frontier/task/detail",{task_id:t})).data}async submitTask(t,e){return(await this.request.post("/api/v2/frontier/task/submit",{task_id:t,data_submission:e})).data}async getTaskList(t){return(await this.request.post("/api/v2/frontier/task/list",t)).data}async getSubmissionList(t){return(await this.request.post("/api/v2/submission/list",t)).data}async getFrontierInfo(t){return(await this.request.get(`/api/v2/frontier/info?frontier_id=${t}`)).data}async getSubmissionDetail(t){return(await this.request.get("/api/v2/submission/user/detail",{params:{submission_id:t}})).data}async uploadFile(t,e){const n=new FormData;return n.append("file",t),(await this.request.post("/api/file/upload",n,{params:{content_type:t.type},onUploadProgress:e})).data}}var f=(r=>(r.TWITTER="x",r.TELEGRAM="telegram",r.DISCORD="discord",r.WEBSITE="website",r.DOC="doc",r))(f||{});exports.FrontierSDK=v;exports.MediaName=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("axios");/*! js-cookie v3.0.5 | MIT */function u(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var o in t)r[o]=t[o]}return r}var h={read:function(r){return r[0]==='"'&&(r=r.slice(1,-1)),r.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(r){return encodeURIComponent(r).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}};function l(r,e){function t(s,i,n){if(!(typeof document>"u")){n=u({},e,n),typeof n.expires=="number"&&(n.expires=new Date(Date.now()+n.expires*864e5)),n.expires&&(n.expires=n.expires.toUTCString()),s=encodeURIComponent(s).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var a="";for(var c in n)n[c]&&(a+="; "+c,n[c]!==!0&&(a+="="+n[c].split(";")[0]));return document.cookie=s+"="+r.write(i,s)+a}}function o(s){if(!(typeof document>"u"||arguments.length&&!s)){for(var i=document.cookie?document.cookie.split("; "):[],n={},a=0;a<i.length;a++){var c=i[a].split("="),m=c.slice(1).join("=");try{var p=decodeURIComponent(c[0]);if(n[p]=r.read(m,p),s===p)break}catch{}}return s?n[s]:n}}return Object.create({set:t,get:o,remove:function(s,i){t(s,"",u({},i,{expires:-1}))},withAttributes:function(s){return l(this.converter,u({},this.attributes,s))},withConverter:function(s){return l(u({},this.converter,s),this.attributes)}},{attributes:{value:Object.freeze(e)},converter:{value:Object.freeze(r)}})}var g=l(h,{path:"/"});class v{constructor(){this.request=d.create({timeout:3e4}),this.setupRequestInterceptor(),this.setupResponseInterceptor()}setupRequestInterceptor(){this.request.interceptors.request.use(e=>{var n;const t=navigator.userAgent.toLowerCase(),o=t.includes("codatta")||((n=location.hash)==null?void 0:n.toLowerCase().includes("codatta")),s=g.get("auth")||localStorage.getItem("auth"),i=/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(t);return s&&(e.headers.token=s),e.headers.channel=o?"codatta-ios-app":"codatta-platform-website",e.headers.device=i?"mobile":"web",e})}setupResponseInterceptor(){this.request.interceptors.response.use(e=>{const t=e.data,o=Object.getOwnPropertyNames(t).includes("code"),s=Object.getOwnPropertyNames(t).includes("success");return o&&(t==null?void 0:t.code)!=="000000"?Promise.reject(new d.AxiosError(t==null?void 0:t.message,t==null?void 0:t.code,e.config,e.request,e)):s&&(t==null?void 0:t.success)!==!0?Promise.reject(new d.AxiosError(t==null?void 0:t.errorMessage,t==null?void 0:t.errorCode,e.config,e.request,e)):e},e=>{if(e.status===401){localStorage.removeItem("uid"),localStorage.removeItem("token"),localStorage.removeItem("auth");const t=new URL(window.location.href),o=t.pathname+t.search;window.location.href=`/account/signin?from=${encodeURIComponent(o)}`}return Promise.reject(e)})}async getTaskDetail(e){return(await this.request.post("/api/v2/frontier/task/detail",{task_id:e})).data}async submitTask(e,t){return(await this.request.post("/api/v2/frontier/task/submit",{task_id:e,data_submission:{data:t,task_id:e}})).data}async getTaskList(e){return(await this.request.post("/api/v2/frontier/task/list",e)).data}async getSubmissionList(e){return(await this.request.post("/api/v2/submission/list",e)).data}async getFrontierInfo(e){return(await this.request.get(`/api/v2/frontier/info?frontier_id=${e}`)).data}async getSubmissionDetail(e){return(await this.request.get("/api/v2/submission/user/detail",{params:{submission_id:e}})).data}async uploadFile(e,t){const o=new FormData;return o.append("file",e),(await this.request.post("/api/file/upload",o,{params:{content_type:e.type},onUploadProgress:t})).data}async getSpecTaskInfo(e){return(await this.request.get(`/v2/spec/task/info?task_id=${e}`)).data}async getSpecTaskInfos(e){return(await this.request.get(`/v2/spec/task/infos?task_ids=${e}`)).data}async submitSpecTask(e,t,o){return(await this.request.post("/v2/spec/task/submit",{task_id:e,status:o??2,content:t})).data}async getVerificationCode({account_type:e,email:t,opt:o}){return(await this.request.post("/v2/user/get_code",{account_type:e??"email",email:t??"",opt:o??"verify"})).data.data}async checkEmail({email:e,code:t,task_id:o}){return(await this.request.post("/v2/frontier/email/check",{email:e,code:t,task_id:o})).data.data}}var f=(r=>(r.TWITTER="x",r.TELEGRAM="telegram",r.DISCORD="discord",r.WEBSITE="website",r.DOC="doc",r))(f||{});exports.FrontierSDK=v;exports.MediaName=f;
package/dist/index.d.ts CHANGED
@@ -54,24 +54,114 @@ export declare class FrontierSDK {
54
54
  constructor();
55
55
  private setupRequestInterceptor;
56
56
  private setupResponseInterceptor;
57
+ /**
58
+ * Fetch the full detail of a frontier task.
59
+ * @param taskId - Unique task ID.
60
+ * @returns Task detail including display data, submission state, and reward info.
61
+ */
57
62
  getTaskDetail(taskId: string): Promise<Response_2<TaskDetail>>;
63
+ /**
64
+ * Submit user-provided data for a frontier task.
65
+ * @param taskId - Unique task ID.
66
+ * @param data - Submission payload. Shape depends on the task template.
67
+ * @returns Updated task detail after submission.
68
+ */
58
69
  submitTask(taskId: string, data: object): Promise<Response_2<TaskDetail>>;
70
+ /**
71
+ * Fetch a paginated list of tasks for a given frontier.
72
+ * @param params.frontier_id - The frontier to query tasks for.
73
+ * @param params.page_num - Page number (1-based).
74
+ * @param params.page_size - Number of tasks per page.
75
+ * @param params.task_types - Optional comma-separated task type filter (e.g. `'submission,validation'`).
76
+ * @returns Paginated list of task details.
77
+ */
59
78
  getTaskList(params: {
60
79
  frontier_id: string;
61
80
  page_num: number;
62
81
  page_size: number;
63
82
  task_types?: string;
64
83
  }): Promise<PaginationResponse<TaskDetail[]>>;
84
+ /**
85
+ * Fetch the current user's paginated submission history.
86
+ * @param data.page_num - Page number (1-based).
87
+ * @param data.page_size - Number of items per page.
88
+ * @param data.frontier_id - Optional filter by frontier ID.
89
+ * @param data.task_ids - Optional comma-separated list of task IDs to filter by.
90
+ * @returns Paginated list of submission records.
91
+ */
65
92
  getSubmissionList(data: TPagination & {
66
93
  frontier_id?: string;
67
94
  task_ids?: string;
68
95
  }): Promise<PaginationResponse<TaskDetail[]>>;
96
+ /**
97
+ * Fetch metadata and configuration for a frontier.
98
+ * @param frontierId - Unique frontier ID.
99
+ * @returns Frontier info including name, description, rewards, and media links.
100
+ */
69
101
  getFrontierInfo(frontierId: string): Promise<Response_2<FrontierItemType>>;
102
+ /**
103
+ * Fetch the detail of a single submission record.
104
+ * @param submissionId - Unique submission ID.
105
+ * @returns Full submission record including status, rating, and rewards.
106
+ */
70
107
  getSubmissionDetail(submissionId: string): Promise<Response_2<SubmissionRecord>>;
108
+ /**
109
+ * Upload a file to the Codatta file service.
110
+ * @param file - The `File` object to upload.
111
+ * @param onProgress - Optional callback invoked during upload with Axios progress events.
112
+ * @returns An object containing `file_path` (server-side storage path) and `original_name`.
113
+ */
71
114
  uploadFile(file: File, onProgress?: (event: AxiosProgressEvent) => void): Promise<{
72
115
  file_path: string;
73
116
  original_name: string;
74
117
  }>;
118
+ /**
119
+ * Fetch the info of a single spec task.
120
+ * @param taskId - Unique task ID.
121
+ * @returns Task info including status (`1` = pending, `2` = completed) and optional content.
122
+ */
123
+ getSpecTaskInfo(taskId: string): Promise<Response_2<TaskInfo>>;
124
+ /**
125
+ * Fetch info for multiple spec tasks in a single request.
126
+ * @param taskIds - Comma-separated list of task IDs (e.g. `'id1,id2,id3'`).
127
+ * @returns Array of task info objects.
128
+ */
129
+ getSpecTaskInfos(taskIds: string): Promise<Response_2<TaskInfo[]>>;
130
+ /**
131
+ * Submit or update a spec task.
132
+ * @param taskId - Unique task ID.
133
+ * @param content - Optional freeform content to attach to the submission.
134
+ * @param status - Submission status: `1` = reject, `2` = accept (default `2`).
135
+ * @returns Updated task info after submission.
136
+ */
137
+ submitSpecTask(taskId: string, content?: string, status?: 1 | 2): Promise<Response_2<TaskInfo>>;
138
+ /**
139
+ * Request a verification code to be sent to the user's account.
140
+ * @param params.account_type - Account type. Accepted values: `'email'` (default) | `'block_chain'`.
141
+ * @param params.email - Target email address (e.g. `'xxx@gmail.com'`). Required when `account_type` is `'email'`.
142
+ * @param params.opt - Operation type: `'verify'` (default) for email verification, `'vivolight'` for vivolight-related operations.
143
+ * @returns The verification code string (relay it to `checkEmail` to complete verification).
144
+ */
145
+ getVerificationCode({ account_type, email, opt }: {
146
+ account_type?: string;
147
+ email?: string;
148
+ opt?: string;
149
+ }): Promise<string>;
150
+ /**
151
+ * Verify a user's email address against a task requirement.
152
+ * @param params.email - The email address to verify.
153
+ * @param params.code - The verification code obtained via `getVerificationCode`.
154
+ * @param params.task_id - The task ID that requires email verification.
155
+ * @returns `{ flag: true }` if verification passed; `{ flag: false, info: '<reason>' }` otherwise.
156
+ */
157
+ checkEmail({ email, code, task_id }: {
158
+ email: string;
159
+ code: string;
160
+ task_id: string;
161
+ }): Promise<{
162
+ flag: boolean;
163
+ info: string;
164
+ }>;
75
165
  }
76
166
 
77
167
  export declare enum MediaName {
@@ -82,32 +172,65 @@ export declare enum MediaName {
82
172
  DOC = "doc"
83
173
  }
84
174
 
175
+ /**
176
+ * Standard paginated response wrapper.
177
+ * @template T - The type of the `data` payload (usually an array).
178
+ */
85
179
  export declare interface PaginationResponse<T> {
180
+ /** The paginated data payload. */
86
181
  data: T;
182
+ /** Total number of items matching the query. */
87
183
  total: number;
184
+ /** Current page number, 1-based. */
88
185
  page_num: number;
186
+ /** Number of items per page. */
89
187
  page_size: number;
90
188
  }
91
189
 
92
190
  export declare type RankingGrade = 'S' | 'A' | 'B' | 'C' | 'D';
93
191
 
192
+ /**
193
+ * Standard API response wrapper.
194
+ * @template T - The type of the `data` payload.
195
+ */
94
196
  declare interface Response_2<T> {
197
+ /** The actual response payload. */
95
198
  data: T;
199
+ /** Whether the request succeeded. Always `true` on success; rejection is handled via `errorCode`. */
96
200
  success: true;
201
+ /** Error code returned by the server when `success` is false. */
97
202
  errorCode: number;
203
+ /** Human-readable error message returned by the server when `success` is false. */
98
204
  errorMessage: string;
99
205
  }
100
206
  export { Response_2 as Response }
101
207
 
208
+ /**
209
+ * A historical submission record returned by the submission list / detail endpoints.
210
+ */
102
211
  export declare interface SubmissionRecord {
212
+ /** Submission timestamp (Unix ms). */
103
213
  submission_time: number;
214
+ /** Display name of the frontier the task belongs to. */
104
215
  frontier_name: string;
216
+ /** Display name of the submitted task. */
105
217
  task_name: string;
218
+ /** Numeric review score. */
106
219
  result: number;
220
+ /** Letter grade derived from the review score (`S` > `A` > `B` > `C` > `D`). */
107
221
  rating_name: RankingGrade;
222
+ /**
223
+ * Submission review status:
224
+ * - `'PENDING'`: awaiting review
225
+ * - `'ADOPT'`: accepted and rewarded
226
+ * - `'REFUSED'`: rejected by reviewer
227
+ */
108
228
  status: 'ADOPT' | 'PENDING' | 'REFUSED';
229
+ /** Unique submission ID. */
109
230
  submission_id: string;
231
+ /** Rewards earned for this submission. */
110
232
  rewards: SubmissionReward[];
233
+ /** The original data submitted by the user, if available. */
111
234
  data_submission?: {
112
235
  data: {
113
236
  [key: string]: unknown;
@@ -122,14 +245,25 @@ export declare interface SubmissionReward {
122
245
  reward_amount: number;
123
246
  }
124
247
 
248
+ /**
249
+ * Full detail of a frontier task, including display data, submission state, and reward info.
250
+ */
125
251
  export declare interface TaskDetail {
252
+ /** ID of the frontier this task belongs to. */
126
253
  frontier_id: string;
254
+ /** Unique task ID. */
127
255
  task_id: string;
256
+ /** Display name of the task. */
128
257
  name: string;
258
+ /** Task creation timestamp (Unix ms). */
129
259
  create_time: number;
260
+ /** Associated submission ID, if any. */
130
261
  submission_id: string;
262
+ /** Internal task type identifier (e.g. `'submission'`, `'validation'`). */
131
263
  task_type: string;
264
+ /** Human-readable task type name (e.g. `'Contribute'`, `'Review'`). */
132
265
  task_type_name: string;
266
+ /** Template ID used to render this task. */
133
267
  template_id: string;
134
268
  data_display: {
135
269
  gif_resource: string;
@@ -147,23 +281,74 @@ export declare interface TaskDetail {
147
281
  [key: string]: unknown;
148
282
  lifelog_report?: string;
149
283
  };
284
+ /**
285
+ * Question group availability:
286
+ * - `1`: questions available
287
+ * - `2`: no more questions in this group
288
+ * - `3`: need to switch question group
289
+ */
150
290
  question_status?: number;
151
291
  data_requirements: unknown;
292
+ /** List of reward configurations for this task. */
152
293
  reward_info: readonly TaskRewardInfo[];
153
294
  qualification_datas: unknown[];
295
+ /**
296
+ * Current task submission status:
297
+ * - `'PENDING'`: submitted, awaiting review
298
+ * - `'SUBMITTED'`: confirmed on-chain
299
+ * - `'REFUSED'`: rejected by reviewer
300
+ * - `'ADOPT'`: accepted and rewarded
301
+ */
154
302
  status: 'PENDING' | 'SUBMITTED' | 'REFUSED' | 'ADOPT';
303
+ /** Block explorer URL for the on-chain transaction. */
155
304
  txHashUrl: string;
305
+ /** Quality grading result after review (`S` > `A` > `B` > `C` > `D`). */
156
306
  result: RankingGrade;
307
+ /**
308
+ * On-chain processing status:
309
+ * - `0`: not submitted
310
+ * - `1`: pending
311
+ * - `2`: processing
312
+ * - `3`: confirmed
313
+ * - `4`: failed
314
+ */
157
315
  chain_status: 0 | 1 | 2 | 3 | 4;
158
316
  qualification?: string;
317
+ /** Whether the user meets the qualification requirement: `0` = no, `1` = yes. */
159
318
  qualification_flag: 0 | 1;
319
+ /** User reputation score at submission time. */
160
320
  reputation: number;
321
+ /** Reward points earned for this task. `null` if not yet settled. */
161
322
  reward_points: null | number;
323
+ /**
324
+ * User reputation check flag:
325
+ * - `0`: not checked
326
+ * - `1`: passed
327
+ * - `2`: failed
328
+ */
162
329
  user_reputation_flag: 0 | 1 | 2;
330
+ /** Tags associated with this task. */
163
331
  tags: string[];
332
+ /** Reason provided by reviewer when the task is refused. */
164
333
  audit_reason?: string;
165
334
  }
166
335
 
336
+ /**
337
+ * Basic info for a spec task, used by the `/v2/spec/task/*` endpoints.
338
+ */
339
+ export declare interface TaskInfo {
340
+ /** Unique task ID. */
341
+ task_id: string;
342
+ /**
343
+ * Task processing status:
344
+ * - `1`: pending / to be processed
345
+ * - `2`: completed / accepted
346
+ */
347
+ status: 1 | 2;
348
+ /** Optional freeform content submitted with the task. */
349
+ content?: string;
350
+ }
351
+
167
352
  export declare interface TaskRewardInfo {
168
353
  reward_icon: string;
169
354
  reward_mode: string;
@@ -175,8 +360,13 @@ export declare type TaskType = 'submission' | 'validation';
175
360
 
176
361
  export declare type TaskTypeName = 'Contribute' | 'Review';
177
362
 
363
+ /**
364
+ * Common pagination parameters used in list API requests.
365
+ */
178
366
  export declare interface TPagination {
367
+ /** Current page number, 1-based. */
179
368
  page_num: number;
369
+ /** Number of items per page. */
180
370
  page_size: number;
181
371
  }
182
372
 
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import m, { AxiosError as l } from "axios";
1
+ import m, { AxiosError as f } from "axios";
2
2
  /*! js-cookie v3.0.5 | MIT */
3
3
  function u(r) {
4
- for (var t = 1; t < arguments.length; t++) {
5
- var e = arguments[t];
6
- for (var n in e)
7
- r[n] = e[n];
4
+ for (var e = 1; e < arguments.length; e++) {
5
+ var t = arguments[e];
6
+ for (var o in t)
7
+ r[o] = t[o];
8
8
  }
9
9
  return r;
10
10
  }
@@ -19,36 +19,36 @@ var h = {
19
19
  );
20
20
  }
21
21
  };
22
- function d(r, t) {
23
- function e(s, i, o) {
22
+ function d(r, e) {
23
+ function t(s, i, n) {
24
24
  if (!(typeof document > "u")) {
25
- o = u({}, t, o), typeof o.expires == "number" && (o.expires = new Date(Date.now() + o.expires * 864e5)), o.expires && (o.expires = o.expires.toUTCString()), s = encodeURIComponent(s).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
26
- var c = "";
27
- for (var a in o)
28
- o[a] && (c += "; " + a, o[a] !== !0 && (c += "=" + o[a].split(";")[0]));
29
- return document.cookie = s + "=" + r.write(i, s) + c;
25
+ n = u({}, e, n), typeof n.expires == "number" && (n.expires = new Date(Date.now() + n.expires * 864e5)), n.expires && (n.expires = n.expires.toUTCString()), s = encodeURIComponent(s).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
26
+ var a = "";
27
+ for (var c in n)
28
+ n[c] && (a += "; " + c, n[c] !== !0 && (a += "=" + n[c].split(";")[0]));
29
+ return document.cookie = s + "=" + r.write(i, s) + a;
30
30
  }
31
31
  }
32
- function n(s) {
32
+ function o(s) {
33
33
  if (!(typeof document > "u" || arguments.length && !s)) {
34
- for (var i = document.cookie ? document.cookie.split("; ") : [], o = {}, c = 0; c < i.length; c++) {
35
- var a = i[c].split("="), f = a.slice(1).join("=");
34
+ for (var i = document.cookie ? document.cookie.split("; ") : [], n = {}, a = 0; a < i.length; a++) {
35
+ var c = i[a].split("="), l = c.slice(1).join("=");
36
36
  try {
37
- var p = decodeURIComponent(a[0]);
38
- if (o[p] = r.read(f, p), s === p)
37
+ var p = decodeURIComponent(c[0]);
38
+ if (n[p] = r.read(l, p), s === p)
39
39
  break;
40
40
  } catch {
41
41
  }
42
42
  }
43
- return s ? o[s] : o;
43
+ return s ? n[s] : n;
44
44
  }
45
45
  }
46
46
  return Object.create(
47
47
  {
48
- set: e,
49
- get: n,
48
+ set: t,
49
+ get: o,
50
50
  remove: function(s, i) {
51
- e(
51
+ t(
52
52
  s,
53
53
  "",
54
54
  u({}, i, {
@@ -64,13 +64,13 @@ function d(r, t) {
64
64
  }
65
65
  },
66
66
  {
67
- attributes: { value: Object.freeze(t) },
67
+ attributes: { value: Object.freeze(e) },
68
68
  converter: { value: Object.freeze(r) }
69
69
  }
70
70
  );
71
71
  }
72
72
  var g = d(h, { path: "/" });
73
- class C {
73
+ class y {
74
74
  constructor() {
75
75
  this.request = m.create({
76
76
  timeout: 3e4
@@ -78,62 +78,174 @@ class C {
78
78
  }
79
79
  // ─── Interceptors ──────────────────────────────────────────────────────────
80
80
  setupRequestInterceptor() {
81
- this.request.interceptors.request.use((t) => {
82
- var o;
83
- const e = navigator.userAgent.toLowerCase(), n = e.includes("codatta") || ((o = location.hash) == null ? void 0 : o.toLowerCase().includes("codatta")), s = g.get("auth") || localStorage.getItem("auth"), i = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(e);
84
- return s && (t.headers.token = s), t.headers.channel = n ? "codatta-ios-app" : "codatta-platform-website", t.headers.device = i ? "mobile" : "web", t;
81
+ this.request.interceptors.request.use((e) => {
82
+ var n;
83
+ const t = navigator.userAgent.toLowerCase(), o = t.includes("codatta") || ((n = location.hash) == null ? void 0 : n.toLowerCase().includes("codatta")), s = g.get("auth") || localStorage.getItem("auth"), i = /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(t);
84
+ return s && (e.headers.token = s), e.headers.channel = o ? "codatta-ios-app" : "codatta-platform-website", e.headers.device = i ? "mobile" : "web", e;
85
85
  });
86
86
  }
87
87
  setupResponseInterceptor() {
88
88
  this.request.interceptors.response.use(
89
- (t) => {
90
- const e = t.data, n = Object.getOwnPropertyNames(e).includes("code"), s = Object.getOwnPropertyNames(e).includes("success");
91
- return n && (e == null ? void 0 : e.code) !== "000000" ? Promise.reject(new l(e == null ? void 0 : e.message, e == null ? void 0 : e.code, t.config, t.request, t)) : s && (e == null ? void 0 : e.success) !== !0 ? Promise.reject(new l(e == null ? void 0 : e.errorMessage, e == null ? void 0 : e.errorCode, t.config, t.request, t)) : t;
89
+ (e) => {
90
+ const t = e.data, o = Object.getOwnPropertyNames(t).includes("code"), s = Object.getOwnPropertyNames(t).includes("success");
91
+ return o && (t == null ? void 0 : t.code) !== "000000" ? Promise.reject(new f(t == null ? void 0 : t.message, t == null ? void 0 : t.code, e.config, e.request, e)) : s && (t == null ? void 0 : t.success) !== !0 ? Promise.reject(new f(t == null ? void 0 : t.errorMessage, t == null ? void 0 : t.errorCode, e.config, e.request, e)) : e;
92
92
  },
93
- (t) => {
94
- if (t.status === 401) {
93
+ (e) => {
94
+ if (e.status === 401) {
95
95
  localStorage.removeItem("uid"), localStorage.removeItem("token"), localStorage.removeItem("auth");
96
- const e = new URL(window.location.href), n = e.pathname + e.search;
97
- window.location.href = `/account/signin?from=${encodeURIComponent(n)}`;
96
+ const t = new URL(window.location.href), o = t.pathname + t.search;
97
+ window.location.href = `/account/signin?from=${encodeURIComponent(o)}`;
98
98
  }
99
- return Promise.reject(t);
99
+ return Promise.reject(e);
100
100
  }
101
101
  );
102
102
  }
103
103
  // ─── API Methods ───────────────────────────────────────────────────────────
104
- async getTaskDetail(t) {
105
- return (await this.request.post("/api/v2/frontier/task/detail", { task_id: t })).data;
104
+ /**
105
+ * Fetch the full detail of a frontier task.
106
+ * @param taskId - Unique task ID.
107
+ * @returns Task detail including display data, submission state, and reward info.
108
+ */
109
+ async getTaskDetail(e) {
110
+ return (await this.request.post("/api/v2/frontier/task/detail", { task_id: e })).data;
106
111
  }
107
- async submitTask(t, e) {
112
+ /**
113
+ * Submit user-provided data for a frontier task.
114
+ * @param taskId - Unique task ID.
115
+ * @param data - Submission payload. Shape depends on the task template.
116
+ * @returns Updated task detail after submission.
117
+ */
118
+ async submitTask(e, t) {
108
119
  return (await this.request.post("/api/v2/frontier/task/submit", {
109
- task_id: t,
110
- data_submission: e
120
+ task_id: e,
121
+ data_submission: {
122
+ data: t,
123
+ task_id: e
124
+ }
111
125
  })).data;
112
126
  }
113
- async getTaskList(t) {
114
- return (await this.request.post("/api/v2/frontier/task/list", t)).data;
127
+ /**
128
+ * Fetch a paginated list of tasks for a given frontier.
129
+ * @param params.frontier_id - The frontier to query tasks for.
130
+ * @param params.page_num - Page number (1-based).
131
+ * @param params.page_size - Number of tasks per page.
132
+ * @param params.task_types - Optional comma-separated task type filter (e.g. `'submission,validation'`).
133
+ * @returns Paginated list of task details.
134
+ */
135
+ async getTaskList(e) {
136
+ return (await this.request.post("/api/v2/frontier/task/list", e)).data;
115
137
  }
116
- async getSubmissionList(t) {
117
- return (await this.request.post("/api/v2/submission/list", t)).data;
138
+ /**
139
+ * Fetch the current user's paginated submission history.
140
+ * @param data.page_num - Page number (1-based).
141
+ * @param data.page_size - Number of items per page.
142
+ * @param data.frontier_id - Optional filter by frontier ID.
143
+ * @param data.task_ids - Optional comma-separated list of task IDs to filter by.
144
+ * @returns Paginated list of submission records.
145
+ */
146
+ async getSubmissionList(e) {
147
+ return (await this.request.post("/api/v2/submission/list", e)).data;
118
148
  }
119
- async getFrontierInfo(t) {
120
- return (await this.request.get(`/api/v2/frontier/info?frontier_id=${t}`)).data;
149
+ /**
150
+ * Fetch metadata and configuration for a frontier.
151
+ * @param frontierId - Unique frontier ID.
152
+ * @returns Frontier info including name, description, rewards, and media links.
153
+ */
154
+ async getFrontierInfo(e) {
155
+ return (await this.request.get(`/api/v2/frontier/info?frontier_id=${e}`)).data;
121
156
  }
122
- async getSubmissionDetail(t) {
157
+ /**
158
+ * Fetch the detail of a single submission record.
159
+ * @param submissionId - Unique submission ID.
160
+ * @returns Full submission record including status, rating, and rewards.
161
+ */
162
+ async getSubmissionDetail(e) {
123
163
  return (await this.request.get("/api/v2/submission/user/detail", {
124
- params: { submission_id: t }
164
+ params: { submission_id: e }
125
165
  })).data;
126
166
  }
127
- async uploadFile(t, e) {
128
- const n = new FormData();
129
- return n.append("file", t), (await this.request.post("/api/file/upload", n, {
130
- params: { content_type: t.type },
131
- onUploadProgress: e
167
+ /**
168
+ * Upload a file to the Codatta file service.
169
+ * @param file - The `File` object to upload.
170
+ * @param onProgress - Optional callback invoked during upload with Axios progress events.
171
+ * @returns An object containing `file_path` (server-side storage path) and `original_name`.
172
+ */
173
+ async uploadFile(e, t) {
174
+ const o = new FormData();
175
+ return o.append("file", e), (await this.request.post("/api/file/upload", o, {
176
+ params: { content_type: e.type },
177
+ onUploadProgress: t
132
178
  })).data;
133
179
  }
180
+ /**
181
+ * Fetch the info of a single spec task.
182
+ * @param taskId - Unique task ID.
183
+ * @returns Task info including status (`1` = pending, `2` = completed) and optional content.
184
+ */
185
+ async getSpecTaskInfo(e) {
186
+ return (await this.request.get(`/v2/spec/task/info?task_id=${e}`)).data;
187
+ }
188
+ /**
189
+ * Fetch info for multiple spec tasks in a single request.
190
+ * @param taskIds - Comma-separated list of task IDs (e.g. `'id1,id2,id3'`).
191
+ * @returns Array of task info objects.
192
+ */
193
+ async getSpecTaskInfos(e) {
194
+ return (await this.request.get(`/v2/spec/task/infos?task_ids=${e}`)).data;
195
+ }
196
+ /**
197
+ * Submit or update a spec task.
198
+ * @param taskId - Unique task ID.
199
+ * @param content - Optional freeform content to attach to the submission.
200
+ * @param status - Submission status: `1` = reject, `2` = accept (default `2`).
201
+ * @returns Updated task info after submission.
202
+ */
203
+ async submitSpecTask(e, t, o) {
204
+ return (await this.request.post("/v2/spec/task/submit", {
205
+ task_id: e,
206
+ status: o ?? 2,
207
+ content: t
208
+ })).data;
209
+ }
210
+ /**
211
+ * Request a verification code to be sent to the user's account.
212
+ * @param params.account_type - Account type. Accepted values: `'email'` (default) | `'block_chain'`.
213
+ * @param params.email - Target email address (e.g. `'xxx@gmail.com'`). Required when `account_type` is `'email'`.
214
+ * @param params.opt - Operation type: `'verify'` (default) for email verification, `'vivolight'` for vivolight-related operations.
215
+ * @returns The verification code string (relay it to `checkEmail` to complete verification).
216
+ */
217
+ async getVerificationCode({
218
+ account_type: e,
219
+ email: t,
220
+ opt: o
221
+ }) {
222
+ return (await this.request.post("/v2/user/get_code", {
223
+ account_type: e ?? "email",
224
+ email: t ?? "",
225
+ opt: o ?? "verify"
226
+ })).data.data;
227
+ }
228
+ /**
229
+ * Verify a user's email address against a task requirement.
230
+ * @param params.email - The email address to verify.
231
+ * @param params.code - The verification code obtained via `getVerificationCode`.
232
+ * @param params.task_id - The task ID that requires email verification.
233
+ * @returns `{ flag: true }` if verification passed; `{ flag: false, info: '<reason>' }` otherwise.
234
+ */
235
+ async checkEmail({
236
+ email: e,
237
+ code: t,
238
+ task_id: o
239
+ }) {
240
+ return (await this.request.post("/v2/frontier/email/check", {
241
+ email: e,
242
+ code: t,
243
+ task_id: o
244
+ })).data.data;
245
+ }
134
246
  }
135
- var w = /* @__PURE__ */ ((r) => (r.TWITTER = "x", r.TELEGRAM = "telegram", r.DISCORD = "discord", r.WEBSITE = "website", r.DOC = "doc", r))(w || {});
247
+ var v = /* @__PURE__ */ ((r) => (r.TWITTER = "x", r.TELEGRAM = "telegram", r.DISCORD = "discord", r.WEBSITE = "website", r.DOC = "doc", r))(v || {});
136
248
  export {
137
- C as FrontierSDK,
138
- w as MediaName
249
+ y as FrontierSDK,
250
+ v as MediaName
139
251
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codatta-frontier-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Codatta Frontier SDK - API client for Codatta Frontier platform",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",