@zing-protocol/zing-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.
@@ -24,6 +24,8 @@ export declare class ZingClient {
24
24
  getDerivedWorksID(address: string): string;
25
25
  getDerivedMembershipID(address: string): string;
26
26
  getReferralID(address: string): string;
27
+ getIsActiveStudio(owner: string): Promise<boolean>;
28
+ getIsStudioOwner(owner: string, studioId: string): boolean;
27
29
  getStudio(owner: string): Promise<{
28
30
  id: string;
29
31
  owner: string;
@@ -229,6 +231,7 @@ export declare class ZingClient {
229
231
  }[];
230
232
  };
231
233
  }[]>;
234
+ getIsWorkOwner(owner: string, workId: string): Promise<boolean>;
232
235
  getBalance(owner: string, coinSymbol: CoinSymbol): Promise<import("node_modules/@mysten/sui/dist/grpc/proto/sui/rpc/v2/state_service.mjs").GetBalanceResponse>;
233
236
  getSessionKey(saltServerUrl: string, signer: ZKLoginSignerState, owner: string): Promise<SessionKey | null>;
234
237
  buildSealApproveTransactionBytes(owner: string): Promise<Uint8Array<ArrayBuffer>>;
@@ -8,6 +8,7 @@ import { getDerivedMembershipID, getDerivedStorageID, getDerivedStudioID, getDer
8
8
  import { importFileKey } from "../mutations/seal.js";
9
9
  import { signPersonalMessage } from "../mutations/signer.js";
10
10
  import { SessionKey } from "@mysten/seal";
11
+ import { bcs } from "@mysten/sui/bcs";
11
12
  import { Transaction, coinWithBalance } from "@mysten/sui/transactions";
12
13
  import { fromHex } from "@mysten/sui/utils";
13
14
  export class ZingClient {
@@ -36,6 +37,17 @@ export class ZingClient {
36
37
  getReferralID(address) {
37
38
  return getReferralID(this.config.zing.ZING_STUDIO_CONFIG_SHARED_OBJECT_REF.objectId, address);
38
39
  }
40
+ async getIsActiveStudio(owner) {
41
+ const studio = await this.getStudio(owner);
42
+ const now = new Date();
43
+ if (!studio)
44
+ return false;
45
+ return (now.getTime() >= Number(studio.period[0]) &&
46
+ now.getTime() < Number(studio.period[1]));
47
+ }
48
+ getIsStudioOwner(owner, studioId) {
49
+ return this.getDerivedStudioID(owner) == studioId;
50
+ }
39
51
  async getStudio(owner) {
40
52
  return getStudio(this.suiGrpcClient, this.getDerivedStudioID(owner));
41
53
  }
@@ -63,6 +75,21 @@ export class ZingClient {
63
75
  async getWorksByObjectIds(owner, workObjectIds, workType) {
64
76
  return getWorksByObjectIds(this.suiGrpcClient, workObjectIds, workType ? this.config.zing.ZING_WORKS_TYPE[workType] : undefined);
65
77
  }
78
+ async getIsWorkOwner(owner, workId) {
79
+ try {
80
+ await this.suiGrpcClient.core.getDynamicObjectField({
81
+ parentId: this.getDerivedWorksID(owner),
82
+ name: {
83
+ type: "0x2::object::ID",
84
+ bcs: bcs.Address.serialize(workId).toBytes(),
85
+ },
86
+ });
87
+ return true;
88
+ }
89
+ catch {
90
+ return false;
91
+ }
92
+ }
66
93
  async getBalance(owner, coinSymbol) {
67
94
  return this.suiGrpcClient.stateService
68
95
  .getBalance({
@@ -22,7 +22,7 @@ export const mainnetZingConfig = {
22
22
  article: "0x6ee54cd57f6f30a70cffeccb16251fc59be211a9706d7c8f0ea8e08c22aaf667::article::Article",
23
23
  },
24
24
  EVENT_TYPES: {
25
- publishArticleEvent: "0x6ee54cd57f6f30a70cffeccb16251fc59be211a9706d7c8f0ea8e08c22aaf667::article::PublishArticle",
25
+ publishArticleEvent: "0x6ee54cd57f6f30a70cffeccb16251fc59be211a9706d7c8f0ea8e08c22aaf667::article::PublishArticleEvent",
26
26
  },
27
27
  };
28
28
  // walrus
package/dist/const.js CHANGED
@@ -1,7 +1,11 @@
1
1
  export const SEAL_SERVERS_CONFIGS = {
2
2
  mainnet: [
3
3
  {
4
- objectId: "0x145540d931f182fef76467dd8074c9839aea126852d90d18e1556fcbbd1208b6",
4
+ objectId: "0x72829123b9bdf679d208382c79b097a03211a38e8d72dcbd0e926c4a7e82c83f",
5
+ weight: 1,
6
+ },
7
+ {
8
+ objectId: "0x8426e907162193ba0b3db8c50ecdd0eae91cd47e7097270cd7fc6c472d8c4c69",
5
9
  weight: 1,
6
10
  },
7
11
  ],
package/dist/getters.js CHANGED
@@ -200,20 +200,25 @@ export async function getMembers(suiGrpcClient, membershipTableId, cursor, limit
200
200
  };
201
201
  }
202
202
  export async function getReferral(suiGrpcClient, referralID) {
203
- const res = await suiGrpcClient.ledgerService.getObject({
204
- objectId: referralID,
205
- readMask: {
206
- paths: ["bcs"],
207
- },
208
- });
209
- if (!res.response.object?.bcs?.value) {
203
+ try {
204
+ const res = await suiGrpcClient.ledgerService.getObject({
205
+ objectId: referralID,
206
+ readMask: {
207
+ paths: ["bcs"],
208
+ },
209
+ });
210
+ if (!res.response.object?.bcs?.value) {
211
+ return null;
212
+ }
213
+ const suiMoveObject = bcs.Object.parse(res.response.object.bcs.value);
214
+ if (suiMoveObject.data.$kind === "Package")
215
+ throw new Error("Move Object is Package");
216
+ const field = Field(bcs.vector(bcs.u8()), Referral).parse(suiMoveObject.data.Move.contents);
217
+ return field.value;
218
+ }
219
+ catch {
210
220
  return null;
211
221
  }
212
- const suiMoveObject = bcs.Object.parse(res.response.object.bcs.value);
213
- if (suiMoveObject.data.$kind === "Package")
214
- throw new Error("Move Object is Package");
215
- const field = Field(bcs.vector(bcs.u8()), Referral).parse(suiMoveObject.data.Move.contents);
216
- return field.value;
217
222
  }
218
223
  export async function getWork(suiGrpcClient, workId, workType) {
219
224
  const res = await suiGrpcClient.ledgerService.getObject({
@@ -1,2 +1,3 @@
1
1
  export * from "./helpers.js";
2
+ export * from "./blob.js";
2
3
  export type * from "./types.js";
@@ -1 +1,2 @@
1
1
  export * from "./helpers.js";
2
+ export * from "./blob.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./walrusStore.js";
2
2
  export * from "./walletStore.js";
3
3
  export * from "./zkloginStore.js";
4
+ export * from "./uploadStore.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./walrusStore.js";
2
2
  export * from "./walletStore.js";
3
3
  export * from "./zkloginStore.js";
4
+ export * from "./uploadStore.js";
@@ -0,0 +1,29 @@
1
+ import type { PublishArticleEvent } from "../_generated/zing_studio/article.js";
2
+ import type { WalrusUploadFlowStage } from "../config/common.js";
3
+ type UploadJobType = "post";
4
+ type UploadJobStatus = "uploading" | "success" | "error";
5
+ interface UploadJob {
6
+ id: string;
7
+ type: UploadJobType;
8
+ status: UploadJobStatus;
9
+ progress: number;
10
+ stage?: WalrusUploadFlowStage | "Downloading";
11
+ toastId: string | number;
12
+ error?: string;
13
+ startedAt: number;
14
+ completedAt?: number;
15
+ studioId: string;
16
+ articleData?: typeof PublishArticleEvent.$inferType;
17
+ }
18
+ interface UploadStore {
19
+ jobs: UploadJob[];
20
+ addJob: (job: Omit<UploadJob, "startedAt">) => void;
21
+ updateJob: (id: string, updates: Partial<UploadJob>) => void;
22
+ removeJob: (id: string) => void;
23
+ clearCompleted: () => void;
24
+ getJob: (id: string) => UploadJob | undefined;
25
+ getActiveJobs: () => UploadJob[];
26
+ }
27
+ export declare const useUploadStore: import("zustand").UseBoundStore<import("zustand").StoreApi<UploadStore>>;
28
+ export declare const uploadActions: UploadStore;
29
+ export type { UploadJob, UploadJobStatus, UploadJobType, UploadStore };
@@ -0,0 +1,39 @@
1
+ import { create } from "zustand";
2
+ // Create the Zustand store using the standard React-compatible `create` function
3
+ const useUploadStoreBase = create((set, get) => ({
4
+ jobs: [],
5
+ addJob(job) {
6
+ const newJob = {
7
+ ...job,
8
+ startedAt: Date.now(),
9
+ };
10
+ set((state) => ({
11
+ jobs: [...state.jobs, newJob],
12
+ }));
13
+ },
14
+ updateJob(id, updates) {
15
+ set((state) => ({
16
+ jobs: state.jobs.map((j) => (j.id === id ? { ...j, ...updates } : j)),
17
+ }));
18
+ },
19
+ removeJob(id) {
20
+ set((state) => ({
21
+ jobs: state.jobs.filter((j) => j.id !== id),
22
+ }));
23
+ },
24
+ clearCompleted() {
25
+ set((state) => ({
26
+ jobs: state.jobs.filter((j) => j.status === "uploading" || j.status === "error"),
27
+ }));
28
+ },
29
+ getJob(id) {
30
+ return get().jobs.find((j) => j.id === id);
31
+ },
32
+ getActiveJobs() {
33
+ return get().jobs.filter((j) => j.status === "uploading");
34
+ },
35
+ }));
36
+ // Export the hook as the default export (React-compatible)
37
+ export const useUploadStore = useUploadStoreBase;
38
+ // Export actions for non-React usage (these access the store directly)
39
+ export const uploadActions = useUploadStoreBase.getState();
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@zing-protocol/zing-sdk",
3
3
  "sideEffects": false,
4
4
  "type": "module",
5
- "version": "0.1.3",
5
+ "version": "0.1.5",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {