@twintag/twintag-sdk 0.2.235-TTPL-1970-twintagsdk-397570c85978488f2e5cebf3cab22c0a2faa6217

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.
@@ -0,0 +1,368 @@
1
+ import { Client } from './client';
2
+ import { Project } from './project';
3
+ import { FileInfo } from './files';
4
+ import { VirtualFile } from './virtual';
5
+ import { ListObject } from './listObject';
6
+ import { OfflineOptions } from '@twintag/model';
7
+ import { ViewInit } from './base';
8
+ /**
9
+ * CreateBag creates a free bag without an association to an Enterprise project.
10
+ */
11
+ export declare function createBag(qid?: string): Promise<View>;
12
+ /**
13
+ * CreateBagInternal is the internal createBag function.
14
+ *
15
+ * @internal */
16
+ export declare function createBagInternal(client: Client, project?: Project, qid?: string): Promise<View>;
17
+ /**
18
+ * The view class allows you to interact with a view into a bag.
19
+ * A view is represented by a `qid`. This is the string you see in its url:
20
+ * `https://twintag.io/<qid>`.
21
+ * A bag can have multiple views, each view can have different rights associated.
22
+ * For example: owner, download-only, upload-only, ...
23
+ *
24
+ * To construct a view object, you pass its QID, E.g.:
25
+ * ```
26
+ * let view = new Twintag.View(viewId)
27
+ * ```
28
+ */
29
+ export declare class View {
30
+ private _base;
31
+ private _epsilon;
32
+ /**
33
+ * Construct a view by its QID.
34
+ *
35
+ * @param init Internal parameter.
36
+ */
37
+ constructor(qid: string);
38
+ get qid(): string;
39
+ set qid(val: string);
40
+ get _client(): Client;
41
+ set _client(val: Client);
42
+ get _data(): ViewObject;
43
+ set _data(val: ViewObject);
44
+ get project(): Project;
45
+ set project(val: Project);
46
+ useCaching(val: boolean): void;
47
+ /**
48
+ * _setConfig allows us to pass internal state.
49
+ *
50
+ * @internal */
51
+ _setConfig(init: ViewInit): void;
52
+ /**
53
+ * Set the token used for authorization. This can be used to authorize
54
+ * requests by the project API key rather than the view QID. However,
55
+ * It is recommended use the {@link Project} object instead.
56
+ */
57
+ setToken(token: string): void;
58
+ private fileURL;
59
+ private fileURLUpload;
60
+ /**
61
+ * Data gets the view definition. This includes the view rights.
62
+ */
63
+ data(): Promise<ViewObject>;
64
+ /**
65
+ * Upload allows you to upload a file into a bag.
66
+ *
67
+ * Required rights: upload.
68
+ *
69
+ * @param name Optionally overwrite the file name.
70
+ * @param parent: parent of the file. FileQid of the folder
71
+ *
72
+ * @category File management
73
+ */
74
+ upload(f: File, name?: string, parent?: string): Promise<FileInfo>;
75
+ /**
76
+ * Upload a {@VirtualFile | virtual file} into a bag.
77
+ *
78
+ * Required rights: owner.
79
+ *
80
+ * @category File management
81
+ */
82
+ uploadVirtual(f: VirtualFile, name: string): Promise<void>;
83
+ /**
84
+ * Download a file from a bag.
85
+ *
86
+ * Required rights: download.
87
+ *
88
+ * @category File management
89
+ */
90
+ download(name: string): Promise<ReadableStream>;
91
+ /**
92
+ * Convenience method to download a JSON file from a bag and parse it.
93
+ *
94
+ * Required rights: download.
95
+ *
96
+ * @category File management
97
+ */
98
+ downloadJSON<T>(name: string): Promise<T>;
99
+ /**
100
+ * Rename a file from a bag.
101
+ *
102
+ * Required rights: upload & download.
103
+ *
104
+ * @category File management
105
+ */
106
+ rename(source: FileInfo, name: string): Promise<FileInfo>;
107
+ /**
108
+ * Move a file.
109
+ *
110
+ * Required rights: upload & download, plus owner rights when specifying a bag.
111
+ *
112
+ * @category File management
113
+ */
114
+ move(source: FileInfo, name?: string, parent?: string, view?: string): Promise<FileInfo>;
115
+ /**
116
+ * Copy a file.
117
+ *
118
+ * Required rights: upload & download, plus owner rights when specifying a bag.
119
+ *
120
+ * @category File management
121
+ */
122
+ copy(source: FileInfo, name?: string, parent?: string, view?: string): Promise<FileInfo>;
123
+ private doMove;
124
+ /**
125
+ * Delete a file from a bag.
126
+ *
127
+ * Required rights: delete.
128
+ *
129
+ * @category File management
130
+ */
131
+ delete(file: FileInfo): Promise<void>;
132
+ /**
133
+ * Delete an entire bag.
134
+ *
135
+ * Required rights: owner.
136
+ */
137
+ deleteBag(): Promise<void>;
138
+ /**
139
+ * Get a view with limited rights.
140
+ *
141
+ * Required rights: owner.
142
+ */
143
+ getUserView(rights: string[]): Promise<View>;
144
+ /**
145
+ * List the files in the bag or a sub-folder.
146
+ *
147
+ * Required rights: list.
148
+ *
149
+ * @category File management
150
+ */
151
+ list(folder?: string): Promise<FileInfo[]>;
152
+ /**
153
+ * This method creates a folder for a twintag.
154
+ * @param folderName
155
+ * @param folderParent
156
+ * @returns
157
+ */
158
+ addFolder<T>(folderName: string, folderParent?: string): Promise<T>;
159
+ /**
160
+ * Seal the bag.
161
+ *
162
+ * Required rights: list.
163
+ *
164
+ * @hidden
165
+ */
166
+ seal(): Promise<void>;
167
+ /**
168
+ * Get the bag metadata of this specific bag. The metadata is returned as an object.
169
+ *
170
+ * Required rights: download.
171
+ *
172
+ * @param lang: optional language value. Allowed inputs are "all" or any language defined in project languages. If no value is passed, then project's default language will be used for returning data
173
+ * @category Metadata
174
+ */
175
+ getMetadata<T>(lang?: string): Promise<T>;
176
+ /**
177
+ * Set the bag metadata of this specific bag. Returns a full view of the resulting metadata.
178
+ *
179
+ * Required rights: owner.
180
+ *
181
+ * @param data An object representing the metadata.
182
+ *
183
+ * @category Metadata
184
+ */
185
+ setMetadata<T>(data: T): Promise<T>;
186
+ /**
187
+ * Get the bag data of a specific bag and object. The data is returned as an object.
188
+ *
189
+ * Required rights: download.
190
+ *
191
+ * @param objectAPIName The apiName of the object for which the data is being requested
192
+ *
193
+ * @param attribute Optional parameter to specify the attribute for which the data is required
194
+ *
195
+ * @category Structured Data
196
+ */
197
+ getData<T>(objectAPIName: string, attribute?: string): Promise<T>;
198
+ /**
199
+ * Set the bag data of this specific bag and object. Returns a full view of the resulting data.
200
+ *
201
+ * Required rights: owner.
202
+ *
203
+ * @param data An object representing the data.
204
+ * @param objectApiName APIName of the object for which the data is being set.
205
+ *
206
+ * @category Structured Data
207
+ */
208
+ setData<T>(objectApiName: string, data: T): Promise<T>;
209
+ /**
210
+ * Get an object for the view
211
+ *
212
+ * Required rights: owner.
213
+ *
214
+ * @param objectApiName APIName of the object
215
+ *
216
+ * @category Structured Data
217
+ */
218
+ object(objectApiName: string): Promise<ListObject>;
219
+ /**
220
+ * Sends notification to the registered users of the view.
221
+ *
222
+ * Required rights: owner.
223
+ *
224
+ * @param message message to be sent as a notification.
225
+ * @param channel optional, if not specified then default channel is 'email'
226
+ *
227
+ * Example:
228
+ * ```js
229
+ * await viewObj.notify(`This is a custom email body.`)
230
+ * ```
231
+ *
232
+ * You can further customize email body by passing {@link NotificationRequest}:
233
+ * ```js
234
+ * await viewObj.notify({
235
+ * message: "custom user message"
236
+ * subject: "custom email subject"
237
+ * bagAlias: "Custom alias for bag"
238
+ * showBagReport: true
239
+ * language: "en-GB"
240
+ * })
241
+ * ```
242
+ * You can provide any ISO 15897 locale for language attribute.
243
+ * Currently supported values: en_GB, nl_BE, fr_BE
244
+ * @category Notification
245
+ */
246
+ notify<T>(request: string | NotificationRequest, channel?: string): Promise<T>;
247
+ /**
248
+ * Sends email to the registered users of the view.
249
+ *
250
+ * @param request message to be sent.
251
+ *
252
+ * Example:
253
+ * ```js
254
+ * await viewObj.sendFeedback({content: 'This is test content'})
255
+ * ```
256
+ *
257
+ * You can further customize email body by passing {@link FeedbackRequest}:
258
+ * ```js
259
+ * await viewObj.sendFeedback({
260
+ * content: 'This is test content',
261
+ * subject: "custom email subject",
262
+ * email: 'email';
263
+ * })
264
+ * ```
265
+ * @category Notification
266
+ */
267
+ sendFeedback<T>(request: string | FeedbackRequest): Promise<T>;
268
+ /**
269
+ * Sends email
270
+ *
271
+ * Required rights: Any.
272
+ *
273
+ * @param request EmailRequest object
274
+ *
275
+ * Example:
276
+ *
277
+ * You can call this method by passing {@link EmailRequest}:
278
+ * ```js
279
+ * await viewObj.sendToSubscribers({
280
+ * recepients: ["to@mail.com"]
281
+ * body: "email body"
282
+ * subject: "email subject"
283
+ * cc: ["cc@mail.com"]
284
+ * bcc: ["bcc@mail.com"]
285
+ * })
286
+ * ```
287
+ * @category Notifications
288
+ */
289
+ sendToSubscribers<T>(request: EmailRequest): Promise<T>;
290
+ /**
291
+ * Execute an epsilon.
292
+ *
293
+ * Required rights: any.
294
+ *
295
+ * @param filename name of epsilon file.
296
+ * @param requestOptions object
297
+ * @param action (optional) title/name of request for offline support
298
+ *
299
+ * @category Structured Data
300
+ */
301
+ executeEpsilon<T>(filename: string, requestOptions: any, offlineOptions?: OfflineOptions): Promise<T>;
302
+ }
303
+ /**
304
+ * Notification request message.
305
+ */
306
+ interface NotificationRequest {
307
+ message: string;
308
+ subject?: string;
309
+ bagAlias?: string;
310
+ showBagReport?: boolean;
311
+ language?: string;
312
+ }
313
+ /**
314
+ * Notification request message.
315
+ */
316
+ export interface EmailRequest {
317
+ sender?: string;
318
+ recipients?: string[];
319
+ body?: string;
320
+ subject?: string;
321
+ cc?: string[];
322
+ bcc?: string[];
323
+ toSubscribers?: boolean;
324
+ mergeVars?: {};
325
+ /**
326
+ * template used for mailchimp templates. This will override the default template in admin settings.
327
+ */
328
+ template?: string;
329
+ }
330
+ /**
331
+ * FeedbackRequest message.
332
+ */
333
+ interface FeedbackRequest {
334
+ email?: string;
335
+ subject?: string;
336
+ content: string;
337
+ rating?: number;
338
+ }
339
+ /**
340
+ * View information data
341
+ */
342
+ interface ViewObjectData {
343
+ rights: string[];
344
+ project: ProjectData;
345
+ }
346
+ /**
347
+ * Project information data
348
+ */
349
+ interface ProjectData {
350
+ projectId: string;
351
+ projectName: string;
352
+ companyName: string;
353
+ }
354
+ /**
355
+ * View information
356
+ */
357
+ export interface ViewObject {
358
+ id: string;
359
+ type: string;
360
+ bagQid: string;
361
+ data: ViewObjectData;
362
+ uploadsession: string;
363
+ state: string;
364
+ wsToken: string;
365
+ wsSeed: string;
366
+ authToken: string;
367
+ }
368
+ export {};
@@ -0,0 +1,92 @@
1
+ /**
2
+ * A virtual file is a file that doesn't have static content like a normal file.
3
+ * Instead, the content of the file is materialized upon request.
4
+ *
5
+ * To create a virtual file you first construct one of the VirtualFile sub-classes.
6
+ * Next, you upload them using {@link View.uploadVirtual}. E.g.:
7
+ * ```js
8
+ * let virtual = new Twintag.Link("https://example.com")
9
+ * await view.uploadVirtual(virtual, "My link")
10
+ * ```
11
+ */
12
+ export declare abstract class VirtualFile {
13
+ /**
14
+ * Get the virtual file mode.
15
+ *
16
+ * @internal
17
+ */
18
+ readonly mode: number;
19
+ /**
20
+ * Construct a virtual file.
21
+ *
22
+ * @internal
23
+ * */
24
+ constructor(mode: number);
25
+ /**
26
+ * Get the virtual file definition.
27
+ *
28
+ * @internal
29
+ */
30
+ abstract GetDefinition(): Definition;
31
+ }
32
+ /**
33
+ * A link is a virtual file that represents a web link.
34
+ *
35
+ * First construct the link, next upload it to a bag using {@link View.uploadVirtual}. E.g.:
36
+ * ```js
37
+ * let virtual = new Twintag.Link("https://example.com")
38
+ * await view.uploadVirtual(virtual, "My link")
39
+ * ```
40
+ */
41
+ export declare class Link extends VirtualFile {
42
+ /**
43
+ *
44
+ * The link URL.
45
+ */
46
+ readonly url: string;
47
+ /**
48
+ *
49
+ * The link target.
50
+ */
51
+ readonly target: string;
52
+ /**
53
+ *
54
+ * Construct a web link by URL.
55
+ *
56
+ * @param target The default target is "_blank ". Other targets may be restricted.
57
+ */
58
+ constructor(url: string, target?: string);
59
+ /**
60
+ * Get the virtual file definition.
61
+ *
62
+ * @internal
63
+ */
64
+ GetDefinition(): Definition;
65
+ }
66
+ /**
67
+ * Link virtual file data.
68
+ *
69
+ * @internal
70
+ */
71
+ export interface LinkData {
72
+ url: string;
73
+ target: string;
74
+ }
75
+ /**
76
+ * Virtual file definition data.
77
+ *
78
+ * @internal
79
+ */
80
+ export interface DefinitionData {
81
+ type: string;
82
+ data: LinkData;
83
+ }
84
+ /**
85
+ * Virtual file definition.
86
+ *
87
+ * @internal
88
+ */
89
+ export interface Definition {
90
+ specversion: string;
91
+ definition: any;
92
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@twintag/twintag-sdk",
3
+ "version": "0.2.235-TTPL-1970-twintagsdk-397570c85978488f2e5cebf3cab22c0a2faa6217",
4
+ "description": "Twintag SDK",
5
+ "author": "Twintag",
6
+ "license": "",
7
+ "repository": "git+https://github.com/esoptra/twintag-sdk.git",
8
+ "main": "lib/twintag.js",
9
+ "module": "lib/twintag.esm.js",
10
+ "types": "lib/types/index.d.ts",
11
+ "files": [
12
+ "lib"
13
+ ],
14
+ "private": false
15
+ }