@thescaffold/jsx-polylog 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 ADDED
@@ -0,0 +1,159 @@
1
+ # Scaffold
2
+
3
+ ## JSX Polylog
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-polylog
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-polylog';
43
+
44
+ init({
45
+ // config
46
+ });
47
+ ```
48
+
49
+ 2. Events
50
+
51
+ - identify
52
+
53
+ ```ts
54
+ import { events } from '@thescaffold/jsx-polylog';
55
+
56
+ events.identify(id, payload, options);
57
+ ```
58
+
59
+ - track
60
+
61
+ ```ts
62
+ import { events } from '@thescaffold/jsx-polylog';
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-polylog'
73
+
74
+ jobs.schedule(id, payload, options)
75
+ ```
76
+
77
+ 4. Files
78
+
79
+ - Upload file
80
+
81
+ ```
82
+ import { files } from '@thescaffold/jsx-polylog'
83
+
84
+ files.upload(name, files, options)
85
+ ```
86
+
87
+ 5. Forms
88
+
89
+ - Submit form
90
+
91
+ ```
92
+ import { forms } from '@thescaffold/jsx-polylog'
93
+
94
+ forms.submit(name, payload, options)
95
+ ```
96
+
97
+ 6. Webhooks
98
+
99
+ - register webhook
100
+
101
+ ```
102
+ import { webhooks } from '@thescaffold/jsx-polylog'
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-polylog';
114
+
115
+ events.identify(id, payload, options);
116
+ ```
117
+
118
+ - track
119
+
120
+ ```ts
121
+ import { events } from '@thescaffold/jsx-polylog';
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,2 @@
1
+ import { Config } from '../utils/values';
2
+ export declare const getConfig: () => Config;
@@ -0,0 +1,2 @@
1
+ import { Config } from '../utils/values';
2
+ export declare const init: (c: Config | any) => void;
@@ -0,0 +1,4 @@
1
+ import { Item } from '../utils/values';
2
+ export declare const push: (...items: Item[]) => void;
3
+ export declare const pop: (length?: number) => Item[];
4
+ export declare const length: () => number;
@@ -0,0 +1,8 @@
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 function isFunction(value: any): boolean;
@@ -0,0 +1,197 @@
1
+ export type Data = Record<string, any>;
2
+ export declare enum EventEntityType {
3
+ Source = "source",
4
+ Channel = "channel"
5
+ }
6
+ export declare enum CategoryType {
7
+ Form = "form",
8
+ File = "file",
9
+ Webhook = "webhook",
10
+ Job = "job",
11
+ Event = "event",
12
+ Log = "log",
13
+ Motion = "motion",
14
+ Message = "message",
15
+ Others = "others"
16
+ }
17
+ export interface Item {
18
+ category: CategoryType;
19
+ payload: any;
20
+ entityId?: string;
21
+ entityName?: EventEntityType;
22
+ reference?: string;
23
+ version?: string;
24
+ sourceId?: string;
25
+ source?: string;
26
+ type?: string;
27
+ }
28
+ export interface Items {
29
+ items: Item[];
30
+ }
31
+ export declare enum LogType {
32
+ INFO = "info",
33
+ WARN = "warn",
34
+ ERROR = "error"
35
+ }
36
+ export interface EventData extends Data {
37
+ }
38
+ export interface FileData extends Data {
39
+ name: string;
40
+ file: string;
41
+ mime?: string;
42
+ size?: string;
43
+ }
44
+ export interface FormData extends Data {
45
+ }
46
+ export interface JobData extends Data {
47
+ url: string;
48
+ frequency: string;
49
+ startAt: string;
50
+ endAt: string;
51
+ }
52
+ export interface LogData extends Data {
53
+ time?: string;
54
+ type: LogType;
55
+ message: string;
56
+ data?: Data;
57
+ title?: string;
58
+ }
59
+ export interface WebhookRegisterData extends Data {
60
+ events: string[];
61
+ url: string;
62
+ }
63
+ export interface WebhookDispatchData extends Data {
64
+ event: string;
65
+ data?: Data;
66
+ }
67
+ export interface MessageData extends Data {
68
+ type: 'identify' | 'track';
69
+ channel: 'email' | 'sms' | 'push' | 'webhook' | string;
70
+ template: string;
71
+ data?: Data;
72
+ provider?: string;
73
+ from?: string;
74
+ to?: string;
75
+ replyTo?: string;
76
+ subject?: string;
77
+ }
78
+ export interface MotionData extends Data {
79
+ type: 'identify' | 'track';
80
+ data?: Data;
81
+ }
82
+ export interface Config {
83
+ /**
84
+ * Destination server base url
85
+ *
86
+ * Require
87
+ */
88
+ server: string;
89
+ /**
90
+ * Access token
91
+ */
92
+ credential: string;
93
+ /**
94
+ * SourceId
95
+ */
96
+ sourceId: string;
97
+ /**
98
+ * log display filter
99
+ */
100
+ logs?: LogType[];
101
+ batch?: {
102
+ /**
103
+ * events and logs are sent to server in batches
104
+ * use interval to set the interval of flushing in mils
105
+ *
106
+ * Default to 5000mils
107
+ */
108
+ interval?: number;
109
+ /**
110
+ * The length of time to wait after a failure before retry
111
+ */
112
+ backoff?: number;
113
+ /**
114
+ * The number of retries before given up
115
+ *
116
+ * default to 3
117
+ */
118
+ limit?: number;
119
+ };
120
+ log?: {
121
+ /**
122
+ * if `true`, log primitive would be automatically captured
123
+ *
124
+ * Defaults to true
125
+ */
126
+ auto?: boolean;
127
+ };
128
+ event?: {
129
+ /**
130
+ * if `true`, events would be automatically captured
131
+ *
132
+ * On browser, page loads, clicks and mouse move events would be auto captured
133
+ *
134
+ * On server (Node), everything that goes through event emitter would be captured
135
+ *
136
+ * Defaults to true
137
+ */
138
+ auto?: boolean;
139
+ /**
140
+ * if defined, only events in the array would be captured
141
+ *
142
+ * events names can be build-in or custom
143
+ */
144
+ names?: string[];
145
+ };
146
+ debug?: boolean;
147
+ }
148
+ export interface IdentifyOptions {
149
+ }
150
+ export interface TrackOptions {
151
+ }
152
+ export interface MessageOptions {
153
+ }
154
+ export interface UploadOptions {
155
+ }
156
+ export interface SubmitOptions {
157
+ }
158
+ export interface ScheduleOptions {
159
+ }
160
+ export interface LogOptions {
161
+ }
162
+ export interface RegisterOptions {
163
+ }
164
+ export interface DispatchOptions {
165
+ }
166
+ export interface SendOptions {
167
+ }
168
+ export interface BaseResponseBody {
169
+ status: 'success' | 'error' | string;
170
+ title: string;
171
+ message: string;
172
+ data?: any;
173
+ meta?: any;
174
+ raw?: string;
175
+ headers?: any;
176
+ [key: string]: any;
177
+ }
178
+ export interface BaseRequestBody {
179
+ [key: string]: any;
180
+ }
181
+ export interface BaseEntity {
182
+ id?: string;
183
+ createdAt?: string;
184
+ updateAt?: string;
185
+ deletedAt?: string;
186
+ [key: string]: any;
187
+ }
188
+ export interface BaseRequestQuery {
189
+ query?: string;
190
+ page?: number;
191
+ from?: string;
192
+ to?: string;
193
+ perPage?: number;
194
+ relations?: string;
195
+ columns?: string;
196
+ [key: string]: any;
197
+ }
@@ -0,0 +1,4 @@
1
+ import { EventData, IdentifyOptions, MessageOptions, TrackOptions } from '../common/utils/values';
2
+ export declare const identify: (id: string, attributes: EventData, options?: IdentifyOptions) => void;
3
+ export declare const track: (id: string, type: string, attributes: EventData, options?: TrackOptions) => void;
4
+ export declare const message: (type: string, attributes: EventData, options?: MessageOptions) => void;
package/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ declare const events: {
2
+ identify: (id: string, attributes: import("./common/utils/values").EventData, options?: import("./common/utils/values").IdentifyOptions | undefined) => void;
3
+ track: (id: string, type: string, attributes: import("./common/utils/values").EventData, options?: import("./common/utils/values").TrackOptions | undefined) => void;
4
+ message: (type: string, attributes: import("./common/utils/values").EventData, options?: import("./common/utils/values").MessageOptions | undefined) => void;
5
+ };
6
+ /**
7
+ * Public APIs
8
+ */
9
+ export { init } from './common/init/index';
10
+ export * from './common/utils/values';
11
+ export * from './platform/index';
12
+ export * from './request/index';
13
+ export { events };
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./jsx-polylog.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./jsx-polylog.cjs.development.js')
8
+ }