@thescaffold/jsx-blobs 0.0.0
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/README.md +159 -0
- package/common/init/config.d.ts +2 -0
- package/common/init/index.d.ts +2 -0
- package/common/queue/index.d.ts +4 -0
- package/common/utils/functions.d.ts +15 -0
- package/common/utils/values.d.ts +109 -0
- package/files/index.d.ts +10 -0
- package/index.d.ts +9 -0
- package/index.js +8 -0
- package/jsx-blobs.cjs.development.js +1408 -0
- package/jsx-blobs.cjs.development.js.map +1 -0
- package/jsx-blobs.cjs.production.min.js +2 -0
- package/jsx-blobs.cjs.production.min.js.map +1 -0
- package/jsx-blobs.esm.js +1392 -0
- package/jsx-blobs.esm.js.map +1 -0
- package/package.json +16 -0
- package/platform/base-entity-service.service.d.ts +13 -0
- package/platform/base-service.service.d.ts +9 -0
- package/platform/index.d.ts +2 -0
- package/request/batch.d.ts +1 -0
- package/request/index.d.ts +2 -0
- package/request/methods.d.ts +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Scaffold
|
|
2
|
+
|
|
3
|
+
## JSX Blobs
|
|
4
|
+
|
|
5
|
+
### Introduction
|
|
6
|
+
|
|
7
|
+
This is the javascript SDK for scaffold platform. It covers APIs for the following services:
|
|
8
|
+
|
|
9
|
+
- Events
|
|
10
|
+
- Files
|
|
11
|
+
- Forms
|
|
12
|
+
- Jobs
|
|
13
|
+
- Logs
|
|
14
|
+
- Messages
|
|
15
|
+
- Motion
|
|
16
|
+
- Webhooks
|
|
17
|
+
|
|
18
|
+
### Supported Platforms
|
|
19
|
+
|
|
20
|
+
- Browser
|
|
21
|
+
- Node.js (Javascript/Typescript)
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
24
|
+
|
|
25
|
+
1. NPM
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
$ npm i @thescaffold/jsx-blobs
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. CDN
|
|
32
|
+
|
|
33
|
+
```html
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Usage & API
|
|
38
|
+
|
|
39
|
+
1. Initialization
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { init } from '@thescaffold/jsx-blobs';
|
|
43
|
+
|
|
44
|
+
init({
|
|
45
|
+
// config
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. Events
|
|
50
|
+
|
|
51
|
+
- identify
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { events } from '@thescaffold/jsx-blobs';
|
|
55
|
+
|
|
56
|
+
events.identify(id, payload, options);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
- track
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { events } from '@thescaffold/jsx-blobs';
|
|
63
|
+
|
|
64
|
+
events.track(id, payload, options);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
3. Jobs
|
|
68
|
+
|
|
69
|
+
- Schedule a new job
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
import { jobs } from '@thescaffold/jsx-blobs'
|
|
73
|
+
|
|
74
|
+
jobs.schedule(id, payload, options)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
4. Files
|
|
78
|
+
|
|
79
|
+
- Upload file
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
import { files } from '@thescaffold/jsx-blobs'
|
|
83
|
+
|
|
84
|
+
files.upload(name, files, options)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
5. Forms
|
|
88
|
+
|
|
89
|
+
- Submit form
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
import { forms } from '@thescaffold/jsx-blobs'
|
|
93
|
+
|
|
94
|
+
forms.submit(name, payload, options)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
6. Webhooks
|
|
98
|
+
|
|
99
|
+
- register webhook
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
import { webhooks } from '@thescaffold/jsx-blobs'
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
webhooks.register(name, payload, options)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
7. Logs
|
|
109
|
+
|
|
110
|
+
- identify
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
import { events } from '@thescaffold/jsx-blobs';
|
|
114
|
+
|
|
115
|
+
events.identify(id, payload, options);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- track
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { events } from '@thescaffold/jsx-blobs';
|
|
122
|
+
|
|
123
|
+
events.track(id, payload, options);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Commands
|
|
127
|
+
|
|
128
|
+
DTS scaffolds your new library inside `/src`.
|
|
129
|
+
|
|
130
|
+
To run DTS, use:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm start # or yarn start
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
|
|
137
|
+
|
|
138
|
+
To do a one-off build, use `npm run build` or `yarn build`.
|
|
139
|
+
|
|
140
|
+
To run tests, use `npm test` or `yarn test`.
|
|
141
|
+
|
|
142
|
+
## Custom Commands
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
# build and sync locally
|
|
146
|
+
$ node ./build --env=dev --sync=true
|
|
147
|
+
|
|
148
|
+
# build and publish
|
|
149
|
+
$ node ./build --env=prod --sync=true --version=x.x.x
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Publish
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
$ git tag <version e.g v0.0.0>
|
|
156
|
+
$ git push origin <version>
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## License
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Config, LogType } from './values';
|
|
2
|
+
export declare const isNode: () => boolean;
|
|
3
|
+
export declare const isBrowser: () => boolean;
|
|
4
|
+
export declare const isObject: (x: any) => boolean;
|
|
5
|
+
export declare const recursiveMerge: (target: any, ...sources: any[]) => any;
|
|
6
|
+
export declare const managedLog: (title: string, message: any, config: Config, ...types: LogType[]) => void;
|
|
7
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
8
|
+
export declare const isFunction: (value: any) => boolean;
|
|
9
|
+
export declare const streamFileChunks: (input: string | FileList, callback: (chunk: string, index: number) => void | Promise<void>, chunkSize?: number) => Promise<number>;
|
|
10
|
+
export declare const streamFileChunksForNode: (path: string, callback: (chunk: string, index: number) => void | Promise<void>, chunkSize?: number) => Promise<number>;
|
|
11
|
+
export declare const streamFileChunksForBrowser: (files: FileList, callback: (chunk: string, index: number) => void | Promise<void>, chunkSize?: number) => Promise<number>;
|
|
12
|
+
export declare const getFileMeta: (input: string | FileList) => Promise<[string?, string?, number?, string?]>;
|
|
13
|
+
export declare const getFileMetaForNode: (path: string) => Promise<[string?, string?, number?, string?]>;
|
|
14
|
+
export declare const getFileMetaForBrowser: (files: FileList) => Promise<[string?, string?, number?, string?]>;
|
|
15
|
+
export declare const uint8ToBase64: (bytes: Uint8Array) => string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export type Data = Record<string, any>;
|
|
2
|
+
export declare enum CategoryType {
|
|
3
|
+
Form = "form",
|
|
4
|
+
File = "file",
|
|
5
|
+
Webhook = "webhook",
|
|
6
|
+
Job = "job",
|
|
7
|
+
Event = "event",
|
|
8
|
+
Log = "log",
|
|
9
|
+
Motion = "motion",
|
|
10
|
+
Message = "message",
|
|
11
|
+
Others = "others"
|
|
12
|
+
}
|
|
13
|
+
export declare enum LogType {
|
|
14
|
+
INFO = "info",
|
|
15
|
+
WARN = "warn",
|
|
16
|
+
ERROR = "error"
|
|
17
|
+
}
|
|
18
|
+
export interface Config {
|
|
19
|
+
/**
|
|
20
|
+
* Destination server base url
|
|
21
|
+
*
|
|
22
|
+
* Require
|
|
23
|
+
*/
|
|
24
|
+
server: string;
|
|
25
|
+
/**
|
|
26
|
+
* Access token
|
|
27
|
+
*/
|
|
28
|
+
credential: string;
|
|
29
|
+
/**
|
|
30
|
+
* SourceId
|
|
31
|
+
*/
|
|
32
|
+
sourceId: string;
|
|
33
|
+
batch?: {
|
|
34
|
+
/**
|
|
35
|
+
* events and logs are sent to server in batches
|
|
36
|
+
* use interval to set the interval of flushing in mils
|
|
37
|
+
*
|
|
38
|
+
* Default to 5000mils
|
|
39
|
+
*/
|
|
40
|
+
interval?: number;
|
|
41
|
+
/**
|
|
42
|
+
* The length of time to wait after a failure before retry
|
|
43
|
+
*/
|
|
44
|
+
backoff?: number;
|
|
45
|
+
/**
|
|
46
|
+
* The number of retries before given up
|
|
47
|
+
*
|
|
48
|
+
* default to 3
|
|
49
|
+
*/
|
|
50
|
+
limit?: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* log display filter
|
|
54
|
+
*/
|
|
55
|
+
logs?: LogType[];
|
|
56
|
+
debug?: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface BaseResponseBody {
|
|
59
|
+
status: 'success' | 'error' | string;
|
|
60
|
+
title: string;
|
|
61
|
+
message: string;
|
|
62
|
+
data?: any;
|
|
63
|
+
meta?: any;
|
|
64
|
+
raw?: string;
|
|
65
|
+
headers?: any;
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}
|
|
68
|
+
export interface BaseRequestBody {
|
|
69
|
+
[key: string]: any;
|
|
70
|
+
}
|
|
71
|
+
export interface BaseEntity {
|
|
72
|
+
id?: string;
|
|
73
|
+
createdAt?: string;
|
|
74
|
+
updateAt?: string;
|
|
75
|
+
deletedAt?: string;
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
}
|
|
78
|
+
export interface BaseRequestQuery {
|
|
79
|
+
query?: string;
|
|
80
|
+
page?: number;
|
|
81
|
+
from?: string;
|
|
82
|
+
to?: string;
|
|
83
|
+
perPage?: number;
|
|
84
|
+
relations?: string;
|
|
85
|
+
columns?: string;
|
|
86
|
+
[key: string]: any;
|
|
87
|
+
}
|
|
88
|
+
export interface File {
|
|
89
|
+
type: string;
|
|
90
|
+
parentId?: string;
|
|
91
|
+
name: string;
|
|
92
|
+
tags?: string[];
|
|
93
|
+
size: number;
|
|
94
|
+
mime: string;
|
|
95
|
+
status?: string;
|
|
96
|
+
meta?: any;
|
|
97
|
+
}
|
|
98
|
+
export interface Page {
|
|
99
|
+
fileId: string;
|
|
100
|
+
index: number;
|
|
101
|
+
raw: string;
|
|
102
|
+
status?: string;
|
|
103
|
+
meta?: any;
|
|
104
|
+
}
|
|
105
|
+
export interface Item {
|
|
106
|
+
file: File;
|
|
107
|
+
pages: Page[];
|
|
108
|
+
}
|
|
109
|
+
export declare const mimeMap: Record<string, string>;
|
package/files/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { File, Page } from '../common/utils/values';
|
|
2
|
+
export declare const init: (file: File) => Promise<any>;
|
|
3
|
+
export declare const batch: (pages: Page[]) => Promise<any>;
|
|
4
|
+
export declare const verify: (file: File) => Promise<any>;
|
|
5
|
+
export declare const upload: (input: string | FileList, parentId?: string, tags?: string[]) => Promise<any[]>;
|
|
6
|
+
/**
|
|
7
|
+
* return the full URL for the given file ID
|
|
8
|
+
* @param id
|
|
9
|
+
*/
|
|
10
|
+
export declare const download: (id: string) => string;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { download, upload } from './files/index';
|
|
2
|
+
/**
|
|
3
|
+
* Public APIs
|
|
4
|
+
*/
|
|
5
|
+
export { init } from './common/init/index';
|
|
6
|
+
export * from './common/utils/values';
|
|
7
|
+
export * from './platform/index';
|
|
8
|
+
export * from './request/index';
|
|
9
|
+
export { download, upload };
|