@edraj/tsdmart 3.0.0 → 4.0.1

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 CHANGED
@@ -19,31 +19,194 @@ make sure you define `axiosDmartInstance` with your axios instance before import
19
19
  * `login(shortname: string, password: string) -> Promise<LoginResponse>` - Performs a login action (shortname).
20
20
  * `loginBy(credentials: dict, password: string) -> Promise<LoginResponse>` - Performs a login action but altering the default identifier that you can customise.
21
21
  * `logout() -> Promise<ApiResponse>` - Performs a logout action.
22
- * `otp_request(request: SendOTPRequest,acceptLanguage: string | null = null) -> Promise<ApiResponse | null>` - Requests an OTP (One Time Password) for login.
23
- * `otp_request_login(request: SendOTPRequest,acceptLanguage: string | null = null) -> Promise<ApiResponse | null>` - Requests an OTP for login and returns a login response.
24
- * `password_reset_request(request: PasswordResetRequest) -> Promise<ApiResponse | null>` - Requests a password reset.
25
- * `confirm_otp(request: ConfirmOTPRequest) -> Promise<ApiResponse | null>` - Confirms the OTP (One Time Password) for login or password reset.
26
- * `user_reset(shortname: string) -> Promise<ApiResponse | null>` - Resets the user password by sending an OTP to the user's email.
27
- * `validate_password(password: string) -> Promise<ApiResponse | null>` - Validates the password.
28
- * `create_user(request: any) -> Promise<ActionResponse>` - Creates a new user.
29
- * `update_user(request: any) -> Promise<ActionResponse>` - Updates an existing user.
30
- * `check_existing(prop: string, value: string) -> Promise<ResponseEntry | null>` - Checks if a user exists.
31
- * `get_profile() -> Promise<ProfileResponse | null>` - Gets the profile of the current user.
22
+ * `otpRequest(request: SendOTPRequest, acceptLanguage: string | null = null) -> Promise<ApiResponse>` - Requests an OTP (One Time Password) for login.
23
+ * `otpRequestLogin(request: SendOTPRequest, acceptLanguage: string | null = null) -> Promise<ApiResponse>` - Requests an OTP for login and returns a login response.
24
+ * `passwordResetRequest(request: PasswordResetRequest) -> Promise<ApiResponse>` - Requests a password reset.
25
+ * `confirmOtp(request: ConfirmOTPRequest) -> Promise<ApiResponse>` - Confirms the OTP (One Time Password) for login or password reset.
26
+ * `userReset(shortname: string) -> Promise<ApiResponse>` - Resets the user password by sending an OTP to the user's email.
27
+ * `validatePassword(password: string) -> Promise<ApiResponse>` - Validates the password.
28
+ * `createUser(request: ActionRequestRecord) -> Promise<ActionResponse>` - Creates a new user.
29
+ * `updateUser(request: ActionRequestRecord) -> Promise<ActionResponse>` - Updates an existing user.
30
+ * `checkExisting(prop: string, value: string) -> Promise<ResponseEntry>` - Checks if a user exists.
31
+ * `getProfile() -> Promise<ProfileResponse>` - Gets the profile of the current user.
32
32
  * `query(query: QueryRequest) -> Promise<ApiQueryResponse | null>` - Performs a query action.
33
33
  * `csv(query: any) -> Promise<ApiQueryResponse>` - Query the entries as csv file.
34
34
  * `space(action: ActionRequest) -> Promise<ActionResponse>` - Performs actions on spaces.
35
35
  * `request(action: ActionRequest) -> Promise<ActionResponse>` - Performs a request action.
36
- * `retrieve_entry(resource_type: ResourceType, space_name: string, subpath: string, shortname: string, retrieve_json_payload: boolean = false, retrieve_attachments: boolean = false, validate_schema: boolean = true) -> Promise<ResponseEntry|null>` - Performs a retrieve action.
37
- * `upload_with_payload(space_name: string, subpath: string, shortname: string, resource_type: ResourceType, payload_file: File, content_type?: ContentType, schema_shortname?: string) -> Promise<ApiResponse>` - Uploads a file with a payload.
38
- * `fetchDataAsset(resourceType: string, dataAssetType: string, spaceName: string, subpath: string, shortname: string, query_string?: string, filter_data_assets?: string[], branch_name?: string) -> Promise<any>` - Fetches a data asset.
39
- * `get_spaces() -> Promise<ApiResponse | null>` - Gets the spaces (user query).
40
- * `get_children(space_name: string, subpath: string, limit: number = 20, offset: number = 0, restrict_types: Array<ResourceType> = []) -> Promise<ApiResponse | null>` - Gets the children of a space (user query).
41
- * `get_attachment_url(resource_type: ResourceType, space_name: string, subpath: string, parent_shortname: string, shortname: string, ext: string) -> string` - Constructs the URL of an attachment.
42
- * `get_space_health(space_name: string) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Gets the health check of a space.
43
- * `get_attachment_content(resource_type: string, space_name: string, subpath: string, shortname: string) -> Promise<any>` - Gets the content of an attachment.
44
- * `get_payload(resource_type: string, space_name: string, subpath: string, shortname: string, ext: string = ".json") -> Promise<any>` - Gets the payload of a resource.
45
- * `get_payload_content(resource_type: string, space_name: string, subpath: string, shortname: string, ext: string = ".json") -> Promise<any>` - Gets the content of a payload.
46
- * `progress_ticket(space_name: string, subpath: string, shortname: string, action: string, resolution?: string, comment?: string) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Performs a progress ticket action.
47
- * `submit(spaceName: string, schemaShortname: string, subpath: string, record: any) -> Promise<any>` - Submits a record (log/feedback) to Dmart.
48
- * `get_manifest() -> Promise<any>` - Gets the manifest of the current instance.
49
- * `get_settings() -> Promise<any>` - Gets the settings of the current instance.
36
+ * `retrieveEntry(request: RetrieveEntryRequest, scope: string = "managed") -> Promise<ResponseEntry | null>` - Performs a retrieve action.
37
+ * `uploadWithPayload(request: UploadWithPayloadRequest, scope: string = "managed") -> Promise<ApiResponse>` - Uploads a file with a payload.
38
+ * `fetchDataAsset(request: FetchDataAssetRequest) -> Promise<any>` - Fetches a data asset.
39
+ * `getSpaces() -> Promise<ApiResponse | null>` - Gets the spaces (user query).
40
+ * `getChildren(request: GetChildrenRequest) -> Promise<ApiResponse | null>` - Gets the children of a space (user query).
41
+ * `getAttachmentUrl(request: GetAttachmentURLRequest, scope: string = "managed") -> string` - Constructs the URL of an attachment.
42
+ * `getSpaceHealth(space_name: string) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Gets the health check of a space.
43
+ * `getPayload(request: GetPayloadRequest, scope: string = "managed") -> Promise<any>` - Gets the payload of a resource.
44
+ * `progressTicket(request: ProgressTicketRequest) -> Promise<ApiQueryResponse & { attributes: { folders_report: Object } }>` - Performs a progress ticket action.
45
+ * `submit(request: SubmitRequest) -> Promise<any>` - Submits a record (log/feedback) to Dmart.
46
+ * `getManifest() -> Promise<any>` - Gets the manifest of the current instance.
47
+ * `getSettings() -> Promise<any>` - Gets the settings of the current instance.
48
+
49
+ # Usage
50
+
51
+ * Initialize the Dmart instance:
52
+ ```js
53
+ export const dmartAxios = axios.create({
54
+ baseURL: backendURL,
55
+ withCredentials: true,
56
+ });
57
+ Dmart.setAxiosInstance(dmartAxios);
58
+ ```
59
+
60
+ ## Manage user
61
+
62
+ * Create user
63
+ ```ts
64
+ const createUserRequest: ActionRequest = {
65
+ space_name: 'users',
66
+ request_type: RequestType.create,
67
+ records: [
68
+ {
69
+ resource_type: ResourceType.user,
70
+ shortname: 'john_doe', // auto: for auto-generated shortname
71
+ attributes: {
72
+ password: 'my-password',
73
+ is_active: true,
74
+ // email, msisdn, displayname are optional
75
+ email: 'john_doe@example.com',
76
+ msisdn: '1234567890',
77
+ password: 'securePassword123',
78
+ displayname: {en: 'John Doe'},
79
+ // roles is optional
80
+ roles: ['store_manager'],
81
+ // is_msisdn_verified, is_email_verified are optional
82
+ is_msisdn_verified: true,
83
+ is_email_verified: true,
84
+ // is force_password_change is optional
85
+ is_force_password_change: false,
86
+ // payload is optional
87
+ payload: {
88
+ content_type: 'json',
89
+ body: {
90
+ additional_info: 'This is some additional information about the user.'
91
+ }
92
+ }
93
+ }
94
+ }
95
+ ]
96
+ };
97
+
98
+ const response = await Dmart.createUser(createUserRequest.records[0]);
99
+ ```
100
+
101
+ * Login with credentials
102
+
103
+ ```ts
104
+ const response = await Dmart.login('john_doe', 'securePassword123');
105
+
106
+ loginBy({email: 'john_doe@example.com'}, 'securePassword123');
107
+
108
+ loginBy({msisdn: '1234567890'}, 'securePassword123');
109
+ ```
110
+
111
+ * Get user profile
112
+
113
+ ```ts
114
+ const profileResponse = await Dmart.getProfile();
115
+ ```
116
+
117
+ * Update user
118
+
119
+ ```ts
120
+ const updateUserRequest: ActionRequest = {
121
+ space_name: 'users',
122
+ request_type: RequestType.update,
123
+ records: [
124
+ {
125
+ resource_type: ResourceType.user,
126
+ shortname: 'john_doe',
127
+ attributes: {
128
+ payload: {
129
+ content_type: 'json',
130
+ body: {
131
+ 'rotation': 'bi-weekly'
132
+ }
133
+ }
134
+ }
135
+ }
136
+ ]
137
+ };
138
+
139
+ const response = await Dmart.updateUser(updateUserRequest.records[0]);
140
+ ```
141
+
142
+ ## Managing entries
143
+
144
+ * Create entry
145
+
146
+ ```ts
147
+ const createRequest: ActionRequest = {
148
+ space_name: 'test_space',
149
+ request_type: RequestType.create,
150
+ records: [
151
+ {
152
+ resource_type: ResourceType.content,
153
+ subpath: '/dummies',
154
+ shortname: 'dummy_001',
155
+ attributes: {
156
+ payload: {
157
+ content_type: 'json',
158
+ body: {
159
+ title: 'Test Dummy Entry',
160
+ description: 'This is a test dummy entry',
161
+ status: 'active'
162
+ }
163
+ }
164
+ }
165
+ }
166
+ ]
167
+ };
168
+ const response = await Dmart.request(createRequest);
169
+ ```
170
+
171
+ * Update entry
172
+
173
+ ```ts
174
+ const updateRequest: ActionRequest = {
175
+ space_name: 'test_space',
176
+ request_type: RequestType.update,
177
+ records: [
178
+ {
179
+ resource_type: ResourceType.content,
180
+ subpath: '/dummies',
181
+ shortname: 'dummy_001',
182
+ attributes: {
183
+ payload: {
184
+ content_type: 'json',
185
+ body: {
186
+ status: 'unactive'
187
+ }
188
+ }
189
+ }
190
+ }
191
+ ]
192
+ };
193
+ const response = await Dmart.request(createRequest);
194
+ ```
195
+
196
+ * Delete entry
197
+
198
+ ```ts
199
+ const deleteRequest: ActionRequest = {
200
+ space_name: 'test_space',
201
+ request_type: RequestType.delete,
202
+ records: [
203
+ {
204
+ resource_type: ResourceType.content,
205
+ subpath: '/dummies',
206
+ shortname: 'dummy_001',
207
+ attributes: {}
208
+ }
209
+ ]
210
+ };
211
+ const response = await Dmart.request(createRequest);
212
+ ```
package/dmart.model.ts CHANGED
@@ -52,6 +52,11 @@ export interface SendOTPRequest {
52
52
  email?: string;
53
53
  }
54
54
 
55
+ export enum DmartScope {
56
+ managed = "managed",
57
+ public = "public",
58
+ }
59
+
55
60
  export interface PasswordResetRequest {
56
61
  msisdn?: string;
57
62
  shortname?: string;
@@ -344,3 +349,88 @@ export type ActionRequest = {
344
349
  export type ApiQueryResponse = ApiResponse & {
345
350
  attributes: { total: number; returned: number };
346
351
  };
352
+
353
+ export interface ResourcesFromCSVRequest {
354
+ space_name: string,
355
+ subpath: string,
356
+ resourceType: ResourceType,
357
+ schema: string,
358
+ payload: File,
359
+ }
360
+
361
+ export interface RetrieveEntryRequest {
362
+ resource_type: ResourceType,
363
+ space_name: string,
364
+ subpath: string,
365
+ shortname: string,
366
+ retrieve_json_payload: boolean,
367
+ retrieve_attachments: boolean,
368
+ validate_schema: boolean|null,
369
+ }
370
+
371
+ export interface UploadWithPayloadRequest {
372
+ space_name: string,
373
+ subpath: string,
374
+ shortname: string,
375
+ resource_type: ResourceType,
376
+ payload_file: File,
377
+ attributes?: Record<string, any> | null,
378
+ }
379
+
380
+ export interface FetchDataAssetRequest {
381
+ resourceType: string,
382
+ dataAssetType: string,
383
+ spaceName: string,
384
+ subpath: string,
385
+ shortname: string,
386
+ query_string?: string,
387
+ filter_data_assets?: string[]
388
+ }
389
+
390
+ export interface GetChildrenRequest {
391
+ space_name: string,
392
+ subpath: string,
393
+ search: string,
394
+ limit: number|null,
395
+ offset: number|null,
396
+ restrict_types: Array<ResourceType>|null
397
+ }
398
+
399
+ export interface GetAttachmentURLRequest {
400
+ resource_type: ResourceType,
401
+ space_name: string,
402
+ subpath: string,
403
+ parent_shortname: string,
404
+ shortname: string,
405
+ ext: string | null,
406
+ }
407
+
408
+ export interface GetPayloadRequest {
409
+ resource_type: ResourceType,
410
+ space_name: string,
411
+ subpath: string,
412
+ shortname: string,
413
+ schemaShortname: string | null,
414
+ ext: string,
415
+ }
416
+
417
+ export interface ProgressTicketRequest {
418
+ space_name: string,
419
+ subpath: string,
420
+ shortname: string,
421
+ action: string,
422
+ resolution?: string,
423
+ comment?: string
424
+ }
425
+
426
+ export interface SubmitRequest {
427
+ spaceName: string,
428
+ schemaShortname: string,
429
+ subpath: string,
430
+ record: any,
431
+ resourceType?: string,
432
+ workflowShortname?: string,
433
+ }
434
+
435
+
436
+