@based/client 2.5.1 → 2.6.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 +305 -34
- package/dist/Client.d.ts +14 -2
- package/dist/Client.js +48 -20
- package/dist/Client.js.map +1 -1
- package/dist/Emitter.d.ts +0 -0
- package/dist/Emitter.js +0 -0
- package/dist/Emitter.js.map +0 -0
- package/dist/auth.d.ts +10 -0
- package/dist/auth.js +75 -0
- package/dist/auth.js.map +1 -0
- package/dist/createError.d.ts +2 -4
- package/dist/createError.js +2 -1
- package/dist/createError.js.map +1 -1
- package/dist/file/fetch.d.ts +0 -0
- package/dist/file/fetch.js +0 -0
- package/dist/file/fetch.js.map +0 -0
- package/dist/file/getUrl.d.ts +0 -0
- package/dist/file/getUrl.js +0 -0
- package/dist/file/getUrl.js.map +0 -0
- package/dist/file/index.d.ts +0 -0
- package/dist/file/index.js +0 -0
- package/dist/file/index.js.map +0 -0
- package/dist/file/stream/browser.d.ts +0 -0
- package/dist/file/stream/browser.js +0 -0
- package/dist/file/stream/browser.js.map +0 -0
- package/dist/file/stream/index.d.ts +0 -0
- package/dist/file/stream/index.js +0 -0
- package/dist/file/stream/index.js.map +0 -0
- package/dist/file/uploadFileBrowser.d.ts +0 -0
- package/dist/file/uploadFileBrowser.js +0 -0
- package/dist/file/uploadFileBrowser.js.map +0 -0
- package/dist/findPrefix.d.ts +0 -0
- package/dist/findPrefix.js +0 -0
- package/dist/findPrefix.js.map +0 -0
- package/dist/idleTimeout.d.ts +0 -0
- package/dist/idleTimeout.js +0 -0
- package/dist/idleTimeout.js.map +0 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/dist/observable/index.d.ts +0 -0
- package/dist/observable/index.js +0 -0
- package/dist/observable/index.js.map +0 -0
- package/dist/printBasedObject.d.ts +0 -0
- package/dist/printBasedObject.js +0 -0
- package/dist/printBasedObject.js.map +0 -0
- package/dist/queue.d.ts +2 -2
- package/dist/queue.js +2 -1
- package/dist/queue.js.map +1 -1
- package/dist/request.d.ts +1 -1
- package/dist/request.js +21 -1
- package/dist/request.js.map +1 -1
- package/dist/selvaTypes/get.d.ts +0 -0
- package/dist/selvaTypes/get.js +0 -0
- package/dist/selvaTypes/get.js.map +0 -0
- package/dist/selvaTypes/schema.d.ts +0 -0
- package/dist/selvaTypes/schema.js +0 -0
- package/dist/selvaTypes/schema.js.map +0 -0
- package/dist/selvaTypes/set.d.ts +0 -0
- package/dist/selvaTypes/set.js +0 -0
- package/dist/selvaTypes/set.js.map +0 -0
- package/dist/subscriptions/addGetSubscriber.d.ts +0 -0
- package/dist/subscriptions/addGetSubscriber.js +0 -0
- package/dist/subscriptions/addGetSubscriber.js.map +0 -0
- package/dist/subscriptions/addSubscriber.d.ts +0 -0
- package/dist/subscriptions/addSubscriber.js +0 -0
- package/dist/subscriptions/addSubscriber.js.map +0 -0
- package/dist/subscriptions/generateId.d.ts +0 -0
- package/dist/subscriptions/generateId.js +0 -0
- package/dist/subscriptions/generateId.js.map +0 -0
- package/dist/subscriptions/incomingSubscription.d.ts +0 -0
- package/dist/subscriptions/incomingSubscription.js +0 -0
- package/dist/subscriptions/incomingSubscription.js.map +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.d.ts +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.js +0 -0
- package/dist/subscriptions/incomingSubscriptionDiff.js.map +0 -0
- package/dist/subscriptions/index.d.ts +0 -0
- package/dist/subscriptions/index.js +0 -0
- package/dist/subscriptions/index.js.map +0 -0
- package/dist/subscriptions/logoutSubscriptions.d.ts +0 -0
- package/dist/subscriptions/logoutSubscriptions.js +0 -0
- package/dist/subscriptions/logoutSubscriptions.js.map +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.d.ts +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js +0 -0
- package/dist/subscriptions/removeSendSubscriptionDataFromQueue.js.map +0 -0
- package/dist/subscriptions/removeSubscriber.d.ts +0 -0
- package/dist/subscriptions/removeSubscriber.js +0 -0
- package/dist/subscriptions/removeSubscriber.js.map +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.d.ts +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.js +0 -0
- package/dist/subscriptions/removeUnsubscribesFromQueue.js.map +0 -0
- package/dist/subscriptions/sendAllSubscriptions.d.ts +0 -0
- package/dist/subscriptions/sendAllSubscriptions.js +0 -0
- package/dist/subscriptions/sendAllSubscriptions.js.map +0 -0
- package/dist/token.d.ts +0 -0
- package/dist/token.js +0 -0
- package/dist/token.js.map +0 -0
- package/dist/track.d.ts +0 -0
- package/dist/track.js +0 -0
- package/dist/track.js.map +0 -0
- package/dist/types.d.ts +253 -0
- package/dist/types.js +58 -0
- package/dist/types.js.map +1 -0
- package/dist/websocket/index.d.ts +0 -0
- package/dist/websocket/index.js +0 -0
- package/dist/websocket/index.js.map +0 -0
- package/dist/websocket/types.d.ts +0 -0
- package/dist/websocket/types.js +0 -0
- package/dist/websocket/types.js.map +0 -0
- package/dist/websocket/urlLoader.d.ts +0 -0
- package/dist/websocket/urlLoader.js +0 -0
- package/dist/websocket/urlLoader.js.map +0 -0
- package/docs/authorize.md +56 -0
- package/docs/files.md +66 -0
- package/docs/get-started.md +60 -0
- package/docs/get.md +759 -0
- package/docs/schema.md +218 -0
- package/docs/set.md +508 -0
- package/package.json +6 -4
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { GetOptions } from './selvaTypes/get';
|
|
3
|
+
import type { SetOptions } from './selvaTypes/set';
|
|
4
|
+
import type { Schema } from './selvaTypes/schema';
|
|
5
|
+
import { Readable } from 'stream';
|
|
6
|
+
export { GetOptions, SetOptions, Schema };
|
|
7
|
+
export declare type DigestOptions = string;
|
|
8
|
+
export declare enum RequestTypes {
|
|
9
|
+
Subscription = 1,
|
|
10
|
+
SubscriptionDiff = 2,
|
|
11
|
+
SendSubscriptionData = 3,
|
|
12
|
+
Unsubscribe = 4,
|
|
13
|
+
Set = 5,
|
|
14
|
+
Get = 6,
|
|
15
|
+
Configuration = 7,
|
|
16
|
+
GetConfiguration = 8,
|
|
17
|
+
Call = 9,
|
|
18
|
+
GetSubscription = 10,
|
|
19
|
+
Delete = 11,
|
|
20
|
+
Copy = 12,
|
|
21
|
+
Digest = 13,
|
|
22
|
+
Token = 14,
|
|
23
|
+
Track = 15,
|
|
24
|
+
Auth = 16
|
|
25
|
+
}
|
|
26
|
+
export declare enum AuthRequestTypes {
|
|
27
|
+
Login = 1,
|
|
28
|
+
Logout = 2,
|
|
29
|
+
RenewToken = 3
|
|
30
|
+
}
|
|
31
|
+
export declare type Configuration = {
|
|
32
|
+
schema: {
|
|
33
|
+
[db: string]: Schema;
|
|
34
|
+
};
|
|
35
|
+
dbs: string[];
|
|
36
|
+
};
|
|
37
|
+
export declare type Query = GetOptions;
|
|
38
|
+
export declare type GenericObject = {
|
|
39
|
+
[key: string]: any;
|
|
40
|
+
};
|
|
41
|
+
export declare type Copy = {
|
|
42
|
+
$id: string;
|
|
43
|
+
db?: string;
|
|
44
|
+
deep?: boolean;
|
|
45
|
+
parents?: string[];
|
|
46
|
+
excludeFields?: string[];
|
|
47
|
+
};
|
|
48
|
+
export declare type ErrorObject = {
|
|
49
|
+
type: string;
|
|
50
|
+
message: string;
|
|
51
|
+
name?: string;
|
|
52
|
+
query?: GenericObject;
|
|
53
|
+
payload?: any;
|
|
54
|
+
auth?: boolean;
|
|
55
|
+
code?: string;
|
|
56
|
+
};
|
|
57
|
+
export declare type FunctionCallMessage = [RequestTypes.Call, string, number, any?];
|
|
58
|
+
export declare type TrackMessage = [RequestTypes.Track, TrackPayload];
|
|
59
|
+
export declare type RequestMessage<T = GenericObject> = [
|
|
60
|
+
(RequestTypes.Set | RequestTypes.Get | RequestTypes.Configuration | RequestTypes.GetConfiguration | RequestTypes.Delete | RequestTypes.Copy | RequestTypes.Digest),
|
|
61
|
+
number,
|
|
62
|
+
T
|
|
63
|
+
];
|
|
64
|
+
export declare type TokenMessage = [RequestTypes.Token, string?, boolean?];
|
|
65
|
+
export declare type AuthMessage = [
|
|
66
|
+
RequestTypes.Auth,
|
|
67
|
+
AuthRequestTypes,
|
|
68
|
+
number,
|
|
69
|
+
GenericObject?
|
|
70
|
+
];
|
|
71
|
+
export declare type SubscribeMessage = [
|
|
72
|
+
RequestTypes.Subscription,
|
|
73
|
+
number,
|
|
74
|
+
GenericObject?,
|
|
75
|
+
number?,
|
|
76
|
+
(2 | 1 | 0)?,
|
|
77
|
+
string?
|
|
78
|
+
];
|
|
79
|
+
export declare type SendSubscriptionDataMessage = [
|
|
80
|
+
RequestTypes.SendSubscriptionData,
|
|
81
|
+
number,
|
|
82
|
+
number?
|
|
83
|
+
];
|
|
84
|
+
export declare type SendSubscriptionGetDataMessage = [
|
|
85
|
+
RequestTypes.GetSubscription,
|
|
86
|
+
number,
|
|
87
|
+
GenericObject?,
|
|
88
|
+
number?,
|
|
89
|
+
string?
|
|
90
|
+
];
|
|
91
|
+
export declare type UnsubscribeMessage = [
|
|
92
|
+
RequestTypes.Unsubscribe,
|
|
93
|
+
number
|
|
94
|
+
];
|
|
95
|
+
export declare type SubscriptionMessage = SubscribeMessage | SendSubscriptionDataMessage | UnsubscribeMessage | SendSubscriptionGetDataMessage;
|
|
96
|
+
export declare type Message = RequestMessage | SubscriptionMessage | FunctionCallMessage | AuthMessage;
|
|
97
|
+
export declare type SubscriptionDiffData = [
|
|
98
|
+
RequestTypes.SubscriptionDiff,
|
|
99
|
+
number,
|
|
100
|
+
GenericObject,
|
|
101
|
+
[
|
|
102
|
+
number,
|
|
103
|
+
number
|
|
104
|
+
]
|
|
105
|
+
];
|
|
106
|
+
export declare type SubscriptionData = [
|
|
107
|
+
RequestTypes.Subscription,
|
|
108
|
+
number,
|
|
109
|
+
GenericObject,
|
|
110
|
+
number?,
|
|
111
|
+
ErrorObject?
|
|
112
|
+
];
|
|
113
|
+
export declare type RequestData = [
|
|
114
|
+
(RequestTypes.Set | RequestTypes.Get | RequestTypes.Configuration | RequestTypes.GetConfiguration | RequestTypes.Call | RequestTypes.Delete | RequestTypes.Copy | RequestTypes.Digest),
|
|
115
|
+
number,
|
|
116
|
+
any,
|
|
117
|
+
ErrorObject?
|
|
118
|
+
];
|
|
119
|
+
export declare type AuthorizedData = [RequestTypes.Token, number[], boolean?];
|
|
120
|
+
export declare type AuthData = [
|
|
121
|
+
RequestTypes.Auth,
|
|
122
|
+
number,
|
|
123
|
+
GenericObject,
|
|
124
|
+
ErrorObject?
|
|
125
|
+
];
|
|
126
|
+
export declare type ResponseData = SubscriptionDiffData | SubscriptionData | RequestData | AuthorizedData | AuthData;
|
|
127
|
+
export declare type TrackPayload = {
|
|
128
|
+
t: string;
|
|
129
|
+
u?: 1;
|
|
130
|
+
s?: 1;
|
|
131
|
+
e?: 1;
|
|
132
|
+
r?: 1;
|
|
133
|
+
o?: TrackOpts;
|
|
134
|
+
};
|
|
135
|
+
export declare type TrackOpts = {
|
|
136
|
+
amount?: number;
|
|
137
|
+
};
|
|
138
|
+
export declare type SendTokenOptions = {
|
|
139
|
+
isBasedUser?: boolean;
|
|
140
|
+
isApiKey?: boolean;
|
|
141
|
+
refreshToken?: string;
|
|
142
|
+
};
|
|
143
|
+
export declare type AnalyticsResult = {
|
|
144
|
+
all: {
|
|
145
|
+
total: number;
|
|
146
|
+
geo?: {
|
|
147
|
+
[isoCode: string]: number;
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
unique: {
|
|
151
|
+
total: number;
|
|
152
|
+
geo?: {
|
|
153
|
+
[isoCode: string]: number;
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
active: {
|
|
157
|
+
total: number;
|
|
158
|
+
max: number;
|
|
159
|
+
geo?: {
|
|
160
|
+
[isoCode: string]: number;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
export declare type AnalyticsHistoryResult = {
|
|
165
|
+
all: {
|
|
166
|
+
total: [number, number][];
|
|
167
|
+
geo?: {
|
|
168
|
+
[isoCode: string]: [number, number][];
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
unique: {
|
|
172
|
+
total: [number, number][];
|
|
173
|
+
geo?: {
|
|
174
|
+
[isoCode: string]: [number, number][];
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
active: {
|
|
178
|
+
total: [number, number][];
|
|
179
|
+
geo?: {
|
|
180
|
+
[isoCode: string]: [number, number][];
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
export declare type AnalyticsTypes = string[];
|
|
185
|
+
export declare type AnalyticsTypesOpts = {
|
|
186
|
+
type?: string;
|
|
187
|
+
$types: true;
|
|
188
|
+
};
|
|
189
|
+
export declare function isAnalyticsTypesOpts(opts: AnalyticsOpts | AnalyticsTypesOpts): opts is AnalyticsTypesOpts;
|
|
190
|
+
export declare function isAnalyticsHistoryOpts(opts: AnalyticsOpts | AnalyticsTypesOpts): opts is AnalyticsHistoryOpts;
|
|
191
|
+
export declare type AnalyticsOpts = {
|
|
192
|
+
type: string;
|
|
193
|
+
params?: {
|
|
194
|
+
[key: string]: number | string | boolean;
|
|
195
|
+
};
|
|
196
|
+
$geo?: string[] | boolean;
|
|
197
|
+
};
|
|
198
|
+
export declare type AnalyticsHistoryOpts = {
|
|
199
|
+
type: string;
|
|
200
|
+
params?: {
|
|
201
|
+
[key: string]: number | string | boolean;
|
|
202
|
+
};
|
|
203
|
+
$geo?: string[] | boolean;
|
|
204
|
+
$history: boolean | number;
|
|
205
|
+
};
|
|
206
|
+
export declare type LoginOpts = {
|
|
207
|
+
email: string;
|
|
208
|
+
password: string;
|
|
209
|
+
};
|
|
210
|
+
export declare type RenewTokenOpts = {
|
|
211
|
+
refreshToken: string;
|
|
212
|
+
};
|
|
213
|
+
export declare type FileUploadOptions = {
|
|
214
|
+
contents: Buffer | ArrayBuffer | string | File | Blob;
|
|
215
|
+
mimeType?: string;
|
|
216
|
+
name?: string;
|
|
217
|
+
url?: string | (() => Promise<string>);
|
|
218
|
+
id?: string;
|
|
219
|
+
raw?: boolean;
|
|
220
|
+
parents?: string[];
|
|
221
|
+
functionName?: string;
|
|
222
|
+
};
|
|
223
|
+
export declare type FileUploadStream = {
|
|
224
|
+
contents: Readable;
|
|
225
|
+
mimeType?: string;
|
|
226
|
+
extension?: string;
|
|
227
|
+
size: number;
|
|
228
|
+
name?: string;
|
|
229
|
+
url?: string | (() => Promise<string>);
|
|
230
|
+
id?: string;
|
|
231
|
+
raw?: boolean;
|
|
232
|
+
parents?: string[];
|
|
233
|
+
functionName?: string;
|
|
234
|
+
};
|
|
235
|
+
export declare type FileUploadPath = {
|
|
236
|
+
path: string;
|
|
237
|
+
mimeType?: string;
|
|
238
|
+
extension?: string;
|
|
239
|
+
name?: string;
|
|
240
|
+
url?: string | (() => Promise<string>);
|
|
241
|
+
id?: string;
|
|
242
|
+
raw?: boolean;
|
|
243
|
+
parents?: string[];
|
|
244
|
+
functionName?: string;
|
|
245
|
+
};
|
|
246
|
+
export declare type FileUploadSrc = {
|
|
247
|
+
src: string;
|
|
248
|
+
mimeType?: string;
|
|
249
|
+
name?: string;
|
|
250
|
+
id?: string;
|
|
251
|
+
parents?: string[];
|
|
252
|
+
size?: number;
|
|
253
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAnalyticsHistoryOpts = exports.isAnalyticsTypesOpts = exports.AuthRequestTypes = exports.RequestTypes = void 0;
|
|
4
|
+
// eslint-disable-next-line
|
|
5
|
+
var RequestTypes;
|
|
6
|
+
(function (RequestTypes) {
|
|
7
|
+
// eslint-disable-next-line
|
|
8
|
+
RequestTypes[RequestTypes["Subscription"] = 1] = "Subscription";
|
|
9
|
+
// eslint-disable-next-line
|
|
10
|
+
RequestTypes[RequestTypes["SubscriptionDiff"] = 2] = "SubscriptionDiff";
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
RequestTypes[RequestTypes["SendSubscriptionData"] = 3] = "SendSubscriptionData";
|
|
13
|
+
// eslint-disable-next-line
|
|
14
|
+
RequestTypes[RequestTypes["Unsubscribe"] = 4] = "Unsubscribe";
|
|
15
|
+
// eslint-disable-next-line
|
|
16
|
+
RequestTypes[RequestTypes["Set"] = 5] = "Set";
|
|
17
|
+
// eslint-disable-next-line
|
|
18
|
+
RequestTypes[RequestTypes["Get"] = 6] = "Get";
|
|
19
|
+
// eslint-disable-next-line
|
|
20
|
+
RequestTypes[RequestTypes["Configuration"] = 7] = "Configuration";
|
|
21
|
+
// eslint-disable-next-line
|
|
22
|
+
RequestTypes[RequestTypes["GetConfiguration"] = 8] = "GetConfiguration";
|
|
23
|
+
// eslint-disable-next-line
|
|
24
|
+
RequestTypes[RequestTypes["Call"] = 9] = "Call";
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
RequestTypes[RequestTypes["GetSubscription"] = 10] = "GetSubscription";
|
|
27
|
+
// eslint-disable-next-line
|
|
28
|
+
RequestTypes[RequestTypes["Delete"] = 11] = "Delete";
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
RequestTypes[RequestTypes["Copy"] = 12] = "Copy";
|
|
31
|
+
// eslint-disable-next-line
|
|
32
|
+
RequestTypes[RequestTypes["Digest"] = 13] = "Digest";
|
|
33
|
+
// eslint-disable-next-line
|
|
34
|
+
RequestTypes[RequestTypes["Token"] = 14] = "Token";
|
|
35
|
+
// eslint-disable-next-line
|
|
36
|
+
RequestTypes[RequestTypes["Track"] = 15] = "Track";
|
|
37
|
+
// eslint-disable-next-line
|
|
38
|
+
RequestTypes[RequestTypes["Auth"] = 16] = "Auth";
|
|
39
|
+
})(RequestTypes = exports.RequestTypes || (exports.RequestTypes = {}));
|
|
40
|
+
var AuthRequestTypes;
|
|
41
|
+
(function (AuthRequestTypes) {
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
AuthRequestTypes[AuthRequestTypes["Login"] = 1] = "Login";
|
|
44
|
+
// eslint-disable-next-line
|
|
45
|
+
AuthRequestTypes[AuthRequestTypes["Logout"] = 2] = "Logout";
|
|
46
|
+
// eslint-disable-next-line
|
|
47
|
+
AuthRequestTypes[AuthRequestTypes["RenewToken"] = 3] = "RenewToken";
|
|
48
|
+
})(AuthRequestTypes = exports.AuthRequestTypes || (exports.AuthRequestTypes = {}));
|
|
49
|
+
function isAnalyticsTypesOpts(opts) {
|
|
50
|
+
return opts.$types === true;
|
|
51
|
+
}
|
|
52
|
+
exports.isAnalyticsTypesOpts = isAnalyticsTypesOpts;
|
|
53
|
+
function isAnalyticsHistoryOpts(opts) {
|
|
54
|
+
const hasHistory = opts.$history;
|
|
55
|
+
return !!hasHistory;
|
|
56
|
+
}
|
|
57
|
+
exports.isAnalyticsHistoryOpts = isAnalyticsHistoryOpts;
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AASA,2BAA2B;AAC3B,IAAY,YAiCX;AAjCD,WAAY,YAAY;IACtB,2BAA2B;IAC3B,+DAAgB,CAAA;IAChB,2BAA2B;IAC3B,uEAAoB,CAAA;IACpB,2BAA2B;IAC3B,+EAAwB,CAAA;IACxB,2BAA2B;IAC3B,6DAAe,CAAA;IACf,2BAA2B;IAC3B,6CAAO,CAAA;IACP,2BAA2B;IAC3B,6CAAO,CAAA;IACP,2BAA2B;IAC3B,iEAAiB,CAAA;IACjB,2BAA2B;IAC3B,uEAAoB,CAAA;IACpB,2BAA2B;IAC3B,+CAAQ,CAAA;IACR,2BAA2B;IAC3B,sEAAoB,CAAA;IACpB,2BAA2B;IAC3B,oDAAW,CAAA;IACX,2BAA2B;IAC3B,gDAAS,CAAA;IACT,2BAA2B;IAC3B,oDAAW,CAAA;IACX,2BAA2B;IAC3B,kDAAU,CAAA;IACV,2BAA2B;IAC3B,kDAAU,CAAA;IACV,2BAA2B;IAC3B,gDAAS,CAAA;AACX,CAAC,EAjCW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAiCvB;AAED,IAAY,gBAOX;AAPD,WAAY,gBAAgB;IAC1B,2BAA2B;IAC3B,yDAAS,CAAA;IACT,2BAA2B;IAC3B,2DAAU,CAAA;IACV,2BAA2B;IAC3B,mEAAc,CAAA;AAChB,CAAC,EAPW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAO3B;AA2OD,SAAgB,oBAAoB,CAClC,IAAwC;IAExC,OAAQ,IAA2B,CAAC,MAAM,KAAK,IAAI,CAAA;AACrD,CAAC;AAJD,oDAIC;AAED,SAAgB,sBAAsB,CACpC,IAAwC;IAExC,MAAM,UAAU,GAAI,IAA6B,CAAC,QAAQ,CAAA;IAC1D,OAAO,CAAC,CAAC,UAAU,CAAA;AACrB,CAAC;AALD,wDAKC"}
|
|
File without changes
|
package/dist/websocket/index.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/websocket/types.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `Authorize` data function
|
|
2
|
+
|
|
3
|
+
The authorize data function is a special function that serves as an authorization gatekeeper for the based queries and calls to data functions. It is run every time one is requested and blocks or allows access to the data.
|
|
4
|
+
It works and has the same signature as normal data functions and should return a Promise with `true` or `false` boolean.
|
|
5
|
+
You can have your access logic here. For example, checking if the user is authenticated or if it matches whatever criteria you need for your application.
|
|
6
|
+
|
|
7
|
+
example:
|
|
8
|
+
```javascript
|
|
9
|
+
export default async ({ based, user, payload, name, type, callstack}) => {
|
|
10
|
+
// ...
|
|
11
|
+
return true // or false
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Exposed parameters
|
|
16
|
+
|
|
17
|
+
| Parameter | Description |
|
|
18
|
+
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
19
|
+
| `based` | Based client |
|
|
20
|
+
| `user` | User object. Exposes token information about the user |
|
|
21
|
+
| `payload` | The query requested or the payload sent to the function |
|
|
22
|
+
| `name` | Name of the function. Empty in case of a query |
|
|
23
|
+
| `type` | Type of call. `function` or `query` usually |
|
|
24
|
+
| `callstack` | Array with the names of the data function call stack. If one function calls another, the first function name will show in the callstack of the second function and so on. |
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## `user.token()`
|
|
28
|
+
|
|
29
|
+
The `user` parameter exposes functionality to identify the user. If a user is authenticated, the based client will send an authorization token in the message. You can validate the token and decode it using the `user.token()`
|
|
30
|
+
Will return `undefined` in case of an invalid token.
|
|
31
|
+
|
|
32
|
+
Example:
|
|
33
|
+
```javascript
|
|
34
|
+
export default async ({ based, user, payload, name, type, callstack}) => {
|
|
35
|
+
// Leve this for now. Identifies a user as an UI user.
|
|
36
|
+
if (user.isBased) return true
|
|
37
|
+
|
|
38
|
+
const token = user.token('publicKeySecret')
|
|
39
|
+
if (token.id) {
|
|
40
|
+
return true
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## How to setup?
|
|
48
|
+
The `authorize` function can be created directly on the Functions section of the Based UI or deployed using the CLI with the [`based deploy`](https://github.com/atelier-saulx/based/blob/main/packages/cli/README.md#deploy) command.
|
|
49
|
+
It should be set as a non-observable function with the following config:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"name": "authorize",
|
|
54
|
+
"observable": false
|
|
55
|
+
}
|
|
56
|
+
```
|
package/docs/files.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
## Files
|
|
2
|
+
|
|
3
|
+
Based provides a way to upload and serve user content without hassle using the `client.file()` API.
|
|
4
|
+
Assets uploaded through this tool are then served through a global CDN network, which allows for caching and fast content-delivery.
|
|
5
|
+
|
|
6
|
+
An additional optimization step is executed when the user uploads a video or an image.
|
|
7
|
+
Images are optimized and compressed, and served through an image specific CDN, while videos get transcoded to multiple resolutions, in HLS format.
|
|
8
|
+
|
|
9
|
+
### Introduction
|
|
10
|
+
|
|
11
|
+
Files can be uploaded using the Based client, which in addition to uploading the file, also sets a node of type `file` on the database, which can then be queried and referenced, like you would for any other node.
|
|
12
|
+
|
|
13
|
+
This default type has several fields describing the file, including it's size, mime-type, timestamps for creation and update, progress status, and more. A crucial field is `src`, which contains a link that points to the file (through the appropriate CDN).
|
|
14
|
+
|
|
15
|
+
> :exclamation: Video files will take longer to become available due to the transcoding process.
|
|
16
|
+
|
|
17
|
+
### Usage
|
|
18
|
+
|
|
19
|
+
#### Upload
|
|
20
|
+
|
|
21
|
+
`client.file()` returns a promise that resolves with the new node's ID.
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import based from '@based/client'
|
|
25
|
+
const client = based({
|
|
26
|
+
org: 'saulx',
|
|
27
|
+
project: 'test',
|
|
28
|
+
env: 'production',
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const fileId = await client.file({
|
|
32
|
+
contents: 'This is a string I want to store as plain text!',
|
|
33
|
+
mimeType: 'text/plain',
|
|
34
|
+
name: 'my-file-name',
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The upload progress of the file can then be tracked by _observing_ the `progress` field of the resulting node.
|
|
39
|
+
|
|
40
|
+
#### Accessing the file
|
|
41
|
+
|
|
42
|
+
The file can be accessed by querying the database.
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const data = await client.get({
|
|
46
|
+
$id: fileId,
|
|
47
|
+
$all: true,
|
|
48
|
+
})
|
|
49
|
+
/*
|
|
50
|
+
data = {
|
|
51
|
+
id: "fi6a535226",
|
|
52
|
+
name: "eb3f67a3bc65325bf739ebddd94403e5(1).png",
|
|
53
|
+
mimeType: "image/png",
|
|
54
|
+
version: "eb3f67a3bc65325bf739ebddd94403e5",
|
|
55
|
+
origin: "https://based-env-files-do-usproduction-enb-xz-apz--orn-t-v-...98446afcb87d.png",
|
|
56
|
+
src: "https://based-2129034536588.imgix.net/fi6a535226/84e62df3-75...98446afcb87d.png",
|
|
57
|
+
progress: 1,
|
|
58
|
+
size: 61901,
|
|
59
|
+
type: "file",
|
|
60
|
+
createdAt: 1650360875043,
|
|
61
|
+
updatedAt: 1650360882865,
|
|
62
|
+
}
|
|
63
|
+
*/
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
When using this API, one should always link to the file using the `src` field, since it's the one using the CDN. Pointing to the `origin` would lead to significantly higher data costs.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="javascript:void(0);" style="pointer-events: none;">
|
|
3
|
+
<img src="../../../.docs/assets/based-logo-black.svg#gh-light-mode-only" style="width: 350px; padding-bottom: 10px;" />
|
|
4
|
+
<img src="../../../.docs/assets/based.svg#gh-dark-mode-only" style="width: 350px; padding-bottom: 10px;" />
|
|
5
|
+
|
|
6
|
+
</a>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
# Getting started
|
|
10
|
+
|
|
11
|
+
The first step in getting started with using Based is creating a new project. To do so, after logging in, click the `+ New Project` button and type in a new project name.
|
|
12
|
+
Each project can have multiple environments (e.g. development and production).
|
|
13
|
+
|
|
14
|
+
Go to the based [dashboard](https://based-website.vercel.app/dashboard)
|
|
15
|
+
|
|
16
|
+
<!-- create-new-project video -->
|
|
17
|
+
|
|
18
|
+
https://user-images.githubusercontent.com/16743760/164229679-0555beb5-4c56-4843-8fc6-266fa7f15ee4.mov
|
|
19
|
+
|
|
20
|
+
In order to start adding data to the project, a **schema** is needed. The schema defines your data types, for examples the users of a chat app. To add a new type, click the `+ Create a new type` button.
|
|
21
|
+
Each type can have any number of fields that describe it, for example a user's email. These can be added in the schema editor using the `+ Add Type` button.
|
|
22
|
+
|
|
23
|
+
<!-- add-user-type-to-schema video-->
|
|
24
|
+
|
|
25
|
+
https://user-images.githubusercontent.com/16743760/164229696-83de5222-2d8c-4778-8769-a0c3eea1f239.mov
|
|
26
|
+
|
|
27
|
+
Next, it's time to add some content! This can be done through the Dashboard using the built-in content editor.
|
|
28
|
+
|
|
29
|
+
<!-- add-content video -->
|
|
30
|
+
|
|
31
|
+
https://user-images.githubusercontent.com/16743760/164229707-bc9652a2-0823-44b7-825d-1efdcc080ce6.mov
|
|
32
|
+
|
|
33
|
+
Once the environment is up and running, it is time to jump into the code side of things.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import based from '@based/client'
|
|
37
|
+
|
|
38
|
+
const client = based({
|
|
39
|
+
org: 'my-org',
|
|
40
|
+
project: 'chat',
|
|
41
|
+
env: 'production',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
// observe some data
|
|
45
|
+
await client.observe(
|
|
46
|
+
{ $id: 'root', children: { $all: true, $list: true } },
|
|
47
|
+
(data) => {
|
|
48
|
+
console.log(data)
|
|
49
|
+
}
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// set data
|
|
53
|
+
await client.set({
|
|
54
|
+
type: 'user',
|
|
55
|
+
email: 'francesco@example.com',
|
|
56
|
+
favoriteThing: 'pizza',
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
> [Click here to read more about the Javascript Based SDK](../README.md)
|