@permaweb/libs 0.0.85 → 0.0.87
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 +26 -32
- package/dist/index.esm.js +52 -58
- package/dist/index.js +26 -32
- package/dist/types/common/arweave.d.ts +4 -2
- package/dist/types/common/gql.d.ts +3 -3
- package/dist/types/helpers/index.d.ts +2 -0
- package/dist/types/helpers/platform-providers.d.ts +91 -0
- package/dist/types/helpers/platform.d.ts +160 -0
- package/dist/types/helpers/types.d.ts +2 -1
- package/dist/types/helpers/utils.d.ts +1 -1
- package/dist/types/index.d.ts +8 -6
- package/dist/types/services/assets.d.ts +1 -1
- package/dist/types/services/zones.d.ts +1 -0
- package/package.json +15 -3
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { DependencyType, TagType } from '../helpers/types.ts';
|
|
2
2
|
export declare function resolveTransactionWith(deps: DependencyType): (data: any) => Promise<any>;
|
|
3
3
|
export declare function createTransaction(deps: DependencyType, args: {
|
|
4
|
-
data:
|
|
4
|
+
data: any;
|
|
5
5
|
tags?: TagType[];
|
|
6
6
|
}): Promise<string>;
|
|
7
|
-
export declare function runUpload(fileBlob:
|
|
7
|
+
export declare function runUpload(fileBlob: any, // Blob or Uint8Array (React Native)
|
|
8
|
+
platform: any, // PlatformContext
|
|
9
|
+
txOpts: any & {
|
|
8
10
|
upload?: any;
|
|
9
11
|
}, uploadOpts: {
|
|
10
12
|
apiUrl: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BatchAGQLResponseType, BatchGQLArgsType, DefaultGQLResponseType, GQLArgsType, GQLNodeResponseType } from '../helpers/types.ts';
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
1
|
+
import { BatchAGQLResponseType, BatchGQLArgsType, DefaultGQLResponseType, DependencyType, GQLArgsType, GQLNodeResponseType } from '../helpers/types.ts';
|
|
2
|
+
export declare function getGQLDataWith(deps: DependencyType): (args: GQLArgsType) => Promise<DefaultGQLResponseType>;
|
|
3
|
+
export declare function getAggregatedGQLDataWith(deps: DependencyType): (args: GQLArgsType, callback?: (message: string) => void) => Promise<GQLNodeResponseType[] | null>;
|
|
4
4
|
export declare function getBatchGQLData(args: BatchGQLArgsType): Promise<BatchAGQLResponseType>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-specific provider implementations
|
|
3
|
+
* Auto-detects platform and provides appropriate implementations
|
|
4
|
+
*/
|
|
5
|
+
import type { Base64Handler, BlobHandler, CryptoProvider, FileHandler, FileInput, PlatformContext, StorageProvider, WalletProvider } from './platform.ts';
|
|
6
|
+
import { detectPlatform } from './platform.ts';
|
|
7
|
+
declare class BrowserWalletProvider implements WalletProvider {
|
|
8
|
+
dispatch(tx: any): Promise<{
|
|
9
|
+
id: string;
|
|
10
|
+
}>;
|
|
11
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
12
|
+
getActivePublicKey(): Promise<string>;
|
|
13
|
+
getAddress(): Promise<string>;
|
|
14
|
+
isConnected(): Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
declare class BrowserFileHandler implements FileHandler {
|
|
17
|
+
readAsArrayBuffer(file: any): Promise<ArrayBuffer>;
|
|
18
|
+
getContentType(file: any): string;
|
|
19
|
+
getSize(file: any): number;
|
|
20
|
+
createFile(data: Uint8Array | ArrayBuffer | string, type?: string, name?: string): FileInput;
|
|
21
|
+
isFile(input: any): boolean;
|
|
22
|
+
}
|
|
23
|
+
declare class BrowserBlobHandler implements BlobHandler {
|
|
24
|
+
createBlob(data: Uint8Array | ArrayBuffer, type?: string): any;
|
|
25
|
+
readAsArrayBuffer(blob: Blob): Promise<ArrayBuffer>;
|
|
26
|
+
slice(blob: Blob, start: number, end: number): Blob;
|
|
27
|
+
getSize(blob: Blob): number;
|
|
28
|
+
}
|
|
29
|
+
declare class BrowserCryptoProvider implements CryptoProvider {
|
|
30
|
+
randomUUID(): string;
|
|
31
|
+
getRandomValues<T extends Uint8Array>(array: T): T;
|
|
32
|
+
randomBytes(size: number): Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
declare class BrowserStorageProvider implements StorageProvider {
|
|
35
|
+
getItem(key: string): Promise<string | null>;
|
|
36
|
+
setItem(key: string, value: string): Promise<void>;
|
|
37
|
+
removeItem(key: string): Promise<void>;
|
|
38
|
+
clear(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
declare class BrowserBase64Handler implements Base64Handler {
|
|
41
|
+
encode(data: Uint8Array | ArrayBuffer | string): string;
|
|
42
|
+
decode(base64: string): Uint8Array;
|
|
43
|
+
btoa(str: string): string;
|
|
44
|
+
atob(base64: string): string;
|
|
45
|
+
}
|
|
46
|
+
declare class ReactNativeWalletProvider implements WalletProvider {
|
|
47
|
+
dispatch(_tx: any): Promise<{
|
|
48
|
+
id: string;
|
|
49
|
+
}>;
|
|
50
|
+
sign(_data: Uint8Array): Promise<Uint8Array>;
|
|
51
|
+
getActivePublicKey(): Promise<string>;
|
|
52
|
+
getAddress(): Promise<string>;
|
|
53
|
+
isConnected(): Promise<boolean>;
|
|
54
|
+
}
|
|
55
|
+
declare class ReactNativeFileHandler implements FileHandler {
|
|
56
|
+
readAsArrayBuffer(file: any): Promise<ArrayBuffer>;
|
|
57
|
+
getContentType(file: any): string;
|
|
58
|
+
getSize(file: any): number;
|
|
59
|
+
createFile(data: Uint8Array | ArrayBuffer | string, type?: string, name?: string): FileInput;
|
|
60
|
+
isFile(input: any): boolean;
|
|
61
|
+
private base64ToUint8Array;
|
|
62
|
+
private atobPolyfill;
|
|
63
|
+
}
|
|
64
|
+
declare class ReactNativeBlobHandler implements BlobHandler {
|
|
65
|
+
createBlob(data: Uint8Array | ArrayBuffer, _type?: string): any;
|
|
66
|
+
readAsArrayBuffer(blob: any): Promise<ArrayBuffer>;
|
|
67
|
+
slice(blob: any, start: number, end: number): any;
|
|
68
|
+
getSize(blob: any): number;
|
|
69
|
+
}
|
|
70
|
+
declare class ReactNativeCryptoProvider implements CryptoProvider {
|
|
71
|
+
randomUUID(): string;
|
|
72
|
+
getRandomValues<T extends Uint8Array>(array: T): T;
|
|
73
|
+
randomBytes(size: number): Uint8Array;
|
|
74
|
+
}
|
|
75
|
+
declare class ReactNativeStorageProvider implements StorageProvider {
|
|
76
|
+
private cache;
|
|
77
|
+
getItem(key: string): Promise<string | null>;
|
|
78
|
+
setItem(key: string, value: string): Promise<void>;
|
|
79
|
+
removeItem(key: string): Promise<void>;
|
|
80
|
+
clear(): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
declare class ReactNativeBase64Handler implements Base64Handler {
|
|
83
|
+
encode(data: Uint8Array | ArrayBuffer | string): string;
|
|
84
|
+
decode(base64: string): Uint8Array;
|
|
85
|
+
btoa(str: string): string;
|
|
86
|
+
atob(base64: string): string;
|
|
87
|
+
private btoaPolyfill;
|
|
88
|
+
private atobPolyfill;
|
|
89
|
+
}
|
|
90
|
+
export declare function createPlatformContext(customProviders?: Partial<PlatformContext>): PlatformContext;
|
|
91
|
+
export { BrowserBase64Handler, BrowserBlobHandler, BrowserCryptoProvider, BrowserFileHandler, BrowserStorageProvider, BrowserWalletProvider, detectPlatform, ReactNativeBase64Handler, ReactNativeBlobHandler, ReactNativeCryptoProvider, ReactNativeFileHandler, ReactNativeStorageProvider, ReactNativeWalletProvider, };
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform abstraction interfaces for cross-platform compatibility
|
|
3
|
+
* Supports Browser, Node.js, and React Native environments
|
|
4
|
+
*/
|
|
5
|
+
export interface WalletProvider {
|
|
6
|
+
/**
|
|
7
|
+
* Dispatch a transaction to the wallet for signing and submission
|
|
8
|
+
*/
|
|
9
|
+
dispatch(tx: any): Promise<{
|
|
10
|
+
id: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Sign arbitrary data
|
|
14
|
+
*/
|
|
15
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the active public key
|
|
18
|
+
*/
|
|
19
|
+
getActivePublicKey(): Promise<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Get wallet address
|
|
22
|
+
*/
|
|
23
|
+
getAddress(): Promise<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Check if wallet is connected
|
|
26
|
+
*/
|
|
27
|
+
isConnected(): Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
export interface FileInput {
|
|
30
|
+
data: Uint8Array | ArrayBuffer | string;
|
|
31
|
+
type?: string;
|
|
32
|
+
size?: number;
|
|
33
|
+
name?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface FileHandler {
|
|
36
|
+
/**
|
|
37
|
+
* Read file as ArrayBuffer
|
|
38
|
+
*/
|
|
39
|
+
readAsArrayBuffer(file: any): Promise<ArrayBuffer>;
|
|
40
|
+
/**
|
|
41
|
+
* Get content type of file
|
|
42
|
+
*/
|
|
43
|
+
getContentType(file: any): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get size of file in bytes
|
|
46
|
+
*/
|
|
47
|
+
getSize(file: any): number;
|
|
48
|
+
/**
|
|
49
|
+
* Create a file-like object from data
|
|
50
|
+
*/
|
|
51
|
+
createFile(data: Uint8Array | ArrayBuffer | string, type?: string, name?: string): FileInput;
|
|
52
|
+
/**
|
|
53
|
+
* Check if input is a file
|
|
54
|
+
*/
|
|
55
|
+
isFile(input: any): boolean;
|
|
56
|
+
}
|
|
57
|
+
export interface BlobHandler {
|
|
58
|
+
/**
|
|
59
|
+
* Create a blob from data
|
|
60
|
+
*/
|
|
61
|
+
createBlob(data: Uint8Array | ArrayBuffer, type?: string): any;
|
|
62
|
+
/**
|
|
63
|
+
* Read blob as ArrayBuffer
|
|
64
|
+
*/
|
|
65
|
+
readAsArrayBuffer(blob: any): Promise<ArrayBuffer>;
|
|
66
|
+
/**
|
|
67
|
+
* Slice a blob
|
|
68
|
+
*/
|
|
69
|
+
slice(blob: any, start: number, end: number): any;
|
|
70
|
+
/**
|
|
71
|
+
* Get blob size
|
|
72
|
+
*/
|
|
73
|
+
getSize(blob: any): number;
|
|
74
|
+
}
|
|
75
|
+
export interface CryptoProvider {
|
|
76
|
+
/**
|
|
77
|
+
* Generate a random UUID v4
|
|
78
|
+
*/
|
|
79
|
+
randomUUID(): string;
|
|
80
|
+
/**
|
|
81
|
+
* Fill array with cryptographically secure random values
|
|
82
|
+
*/
|
|
83
|
+
getRandomValues<T extends Uint8Array>(array: T): T;
|
|
84
|
+
/**
|
|
85
|
+
* Generate random bytes
|
|
86
|
+
*/
|
|
87
|
+
randomBytes(size: number): Uint8Array;
|
|
88
|
+
}
|
|
89
|
+
export interface StorageProvider {
|
|
90
|
+
/**
|
|
91
|
+
* Get item from storage
|
|
92
|
+
*/
|
|
93
|
+
getItem(key: string): Promise<string | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Set item in storage
|
|
96
|
+
*/
|
|
97
|
+
setItem(key: string, value: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Remove item from storage
|
|
100
|
+
*/
|
|
101
|
+
removeItem(key: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Clear all storage
|
|
104
|
+
*/
|
|
105
|
+
clear(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
export interface SecureStorageProvider {
|
|
108
|
+
/**
|
|
109
|
+
* Securely store a value
|
|
110
|
+
*/
|
|
111
|
+
setSecure(key: string, value: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Retrieve securely stored value
|
|
114
|
+
*/
|
|
115
|
+
getSecure(key: string): Promise<string | null>;
|
|
116
|
+
/**
|
|
117
|
+
* Delete securely stored value
|
|
118
|
+
*/
|
|
119
|
+
deleteSecure(key: string): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
export interface Base64Handler {
|
|
122
|
+
/**
|
|
123
|
+
* Encode data to base64
|
|
124
|
+
*/
|
|
125
|
+
encode(data: Uint8Array | ArrayBuffer | string): string;
|
|
126
|
+
/**
|
|
127
|
+
* Decode base64 to Uint8Array
|
|
128
|
+
*/
|
|
129
|
+
decode(base64: string): Uint8Array;
|
|
130
|
+
/**
|
|
131
|
+
* Encode string to base64 (btoa equivalent)
|
|
132
|
+
*/
|
|
133
|
+
btoa(str: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Decode base64 to string (atob equivalent)
|
|
136
|
+
*/
|
|
137
|
+
atob(base64: string): string;
|
|
138
|
+
}
|
|
139
|
+
export interface PlatformContext {
|
|
140
|
+
wallet?: WalletProvider;
|
|
141
|
+
file: FileHandler;
|
|
142
|
+
blob: BlobHandler;
|
|
143
|
+
crypto: CryptoProvider;
|
|
144
|
+
storage?: StorageProvider;
|
|
145
|
+
secureStorage?: SecureStorageProvider;
|
|
146
|
+
base64: Base64Handler;
|
|
147
|
+
}
|
|
148
|
+
export type PlatformType = 'browser' | 'node' | 'react-native';
|
|
149
|
+
export declare function detectPlatform(): PlatformType;
|
|
150
|
+
export type PlatformDependencyType = {
|
|
151
|
+
ao: any;
|
|
152
|
+
signer?: any;
|
|
153
|
+
arweave?: any;
|
|
154
|
+
node?: {
|
|
155
|
+
url: string;
|
|
156
|
+
scheduler: string;
|
|
157
|
+
authority: string;
|
|
158
|
+
};
|
|
159
|
+
platform?: PlatformContext;
|
|
160
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type DependencyType = {
|
|
2
|
-
ao
|
|
2
|
+
ao?: any;
|
|
3
3
|
signer?: any;
|
|
4
4
|
arweave?: any;
|
|
5
5
|
node?: {
|
|
@@ -7,6 +7,7 @@ export type DependencyType = {
|
|
|
7
7
|
scheduler: string;
|
|
8
8
|
authority: string;
|
|
9
9
|
};
|
|
10
|
+
gateway?: string;
|
|
10
11
|
};
|
|
11
12
|
export type ProcessReadType = {
|
|
12
13
|
processId: string;
|
|
@@ -13,7 +13,7 @@ export declare function splitTagValue(tag: any): any;
|
|
|
13
13
|
export declare function getTagDisplay(value: string): string;
|
|
14
14
|
export declare function getDataURLContentType(dataURL: string): string | null;
|
|
15
15
|
export declare function getBase64Data(dataURL: string): string;
|
|
16
|
-
export declare function getByteSize(input: string |
|
|
16
|
+
export declare function getByteSize(input: string | Uint8Array | ArrayBuffer | any): number;
|
|
17
17
|
export declare function getTotalTokenBalance(tokenBalances: {
|
|
18
18
|
profileBalance: number;
|
|
19
19
|
walletBalance: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import * as Common from './common/index.ts';
|
|
2
1
|
import * as Helpers from './helpers/index.ts';
|
|
3
|
-
import
|
|
2
|
+
import type { PlatformDependencyType } from './helpers/platform.ts';
|
|
3
|
+
export type { Base64Handler, BlobHandler, CryptoProvider, FileHandler, FileInput, PlatformContext, PlatformType, SecureStorageProvider, StorageProvider, WalletProvider, } from './helpers/platform.ts';
|
|
4
|
+
export { createPlatformContext, detectPlatform } from './helpers/platform-providers.ts';
|
|
4
5
|
export * as Types from './helpers/types.ts';
|
|
5
6
|
export declare const CurrentZoneVersion: string;
|
|
6
|
-
declare function init(deps: Helpers.DependencyType): {
|
|
7
|
+
declare function init(deps: Helpers.DependencyType | PlatformDependencyType): {
|
|
7
8
|
createZone: (args: {
|
|
8
9
|
data?: any;
|
|
9
10
|
tags?: Helpers.TagType[];
|
|
10
11
|
authUsers?: string[];
|
|
12
|
+
skipModeration?: boolean;
|
|
11
13
|
}, callback?: (status: any) => void) => Promise<string | null>;
|
|
12
14
|
updateZone: (args: object, zoneId: string) => Promise<string | null>;
|
|
13
15
|
addToZone: (args: {
|
|
@@ -54,7 +56,7 @@ declare function init(deps: Helpers.DependencyType): {
|
|
|
54
56
|
getAtomicAsset: (id: string, args?: {
|
|
55
57
|
useGateway?: boolean;
|
|
56
58
|
}) => Promise<Helpers.AssetDetailType | null>;
|
|
57
|
-
getAtomicAssets:
|
|
59
|
+
getAtomicAssets: (ids: string[]) => Promise<Helpers.AssetHeaderType[] | null>;
|
|
58
60
|
createComment: (args: Helpers.CommentCreateArgType) => Promise<string>;
|
|
59
61
|
getComments: (args: {
|
|
60
62
|
commentsId: string;
|
|
@@ -155,8 +157,8 @@ declare function init(deps: Helpers.DependencyType): {
|
|
|
155
157
|
moderationId: string;
|
|
156
158
|
}) => Promise<string[] | null>;
|
|
157
159
|
resolveTransaction: (data: any) => Promise<any>;
|
|
158
|
-
getGQLData:
|
|
159
|
-
getAggregatedGQLData:
|
|
160
|
+
getGQLData: (args: Helpers.GQLArgsType) => Promise<Helpers.DefaultGQLResponseType>;
|
|
161
|
+
getAggregatedGQLData: (args: Helpers.GQLArgsType, callback?: (message: string) => void) => Promise<Helpers.GQLNodeResponseType[] | null>;
|
|
160
162
|
createProcess: (args: Helpers.ProcessCreateType, statusCB?: (status: any) => void) => Promise<string>;
|
|
161
163
|
readProcess: (args: Helpers.MessageSendType) => Promise<any>;
|
|
162
164
|
readState: (args: Helpers.ProcessReadType) => Promise<any>;
|
|
@@ -6,5 +6,5 @@ export declare function getAtomicAsset(deps: DependencyType, id: string, args?:
|
|
|
6
6
|
export declare function getAtomicAssetWith(deps: DependencyType): (id: string, args?: {
|
|
7
7
|
useGateway?: boolean;
|
|
8
8
|
}) => Promise<AssetDetailType | null>;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function getAtomicAssetsWith(deps: DependencyType): (ids: string[]) => Promise<AssetHeaderType[] | null>;
|
|
10
10
|
export declare function buildAsset(element: GQLNodeResponseType): any;
|
|
@@ -3,6 +3,7 @@ export declare function createZoneWith(deps: DependencyType): (args: {
|
|
|
3
3
|
data?: any;
|
|
4
4
|
tags?: TagType[];
|
|
5
5
|
authUsers?: string[];
|
|
6
|
+
skipModeration?: boolean;
|
|
6
7
|
}, callback?: (status: any) => void) => Promise<string | null>;
|
|
7
8
|
export declare function updateZoneWith(deps: DependencyType): (args: object, zoneId: string) => Promise<string | null>;
|
|
8
9
|
export declare function addToZoneWith(deps: DependencyType): (args: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@permaweb/libs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.87",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -31,12 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
|
+
"react-native": "./dist/index.esm.js",
|
|
34
35
|
"import": "./dist/index.esm.js",
|
|
35
36
|
"require": "./dist/index.cjs"
|
|
36
37
|
},
|
|
37
38
|
"./browser": "./dist/index.esm.js",
|
|
38
|
-
"./node": "./dist/index.js"
|
|
39
|
+
"./node": "./dist/index.js",
|
|
40
|
+
"./native": "./dist/index.esm.js"
|
|
39
41
|
},
|
|
42
|
+
"react-native": "./dist/index.esm.js",
|
|
40
43
|
"scripts": {
|
|
41
44
|
"prepare": "husky install",
|
|
42
45
|
"clean:install": "rm -rf node_modules package-lock.json || true && npm cache clean --force && npm install",
|
|
@@ -44,7 +47,16 @@
|
|
|
44
47
|
"build": "node build.js"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
|
-
"@dha-team/arbundles": "^1.0.3"
|
|
50
|
+
"@dha-team/arbundles": "^1.0.3",
|
|
51
|
+
"events": "^3.3.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react-native-get-random-values": ">=1.8.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"react-native-get-random-values": {
|
|
58
|
+
"optional": true
|
|
59
|
+
}
|
|
48
60
|
},
|
|
49
61
|
"devDependencies": {
|
|
50
62
|
"@types/async-retry": "^1.4.9",
|