@kwiz/common 1.0.149 → 1.0.151

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.
Files changed (135) hide show
  1. package/.mocharc.js +12 -0
  2. package/lib/cjs/_dependencies.js +2 -2
  3. package/lib/cjs/_dependencies.js.map +1 -1
  4. package/lib/cjs/config.js +1 -2
  5. package/lib/cjs/config.js.map +1 -1
  6. package/lib/cjs/helpers/base64.js +7 -8
  7. package/lib/cjs/helpers/base64.js.map +1 -1
  8. package/lib/cjs/helpers/browser.js +80 -93
  9. package/lib/cjs/helpers/browser.js.map +1 -1
  10. package/lib/cjs/helpers/browserinfo.js +10 -5
  11. package/lib/cjs/helpers/browserinfo.js.map +1 -1
  12. package/lib/cjs/helpers/collections.base.js +33 -34
  13. package/lib/cjs/helpers/collections.base.js.map +1 -1
  14. package/lib/cjs/helpers/collections.js +3 -4
  15. package/lib/cjs/helpers/collections.js.map +1 -1
  16. package/lib/cjs/helpers/color.js +3 -4
  17. package/lib/cjs/helpers/color.js.map +1 -1
  18. package/lib/cjs/helpers/cookies.js +5 -6
  19. package/lib/cjs/helpers/cookies.js.map +1 -1
  20. package/lib/cjs/helpers/date.js +17 -17
  21. package/lib/cjs/helpers/date.js.map +1 -1
  22. package/lib/cjs/helpers/debug.js +7 -8
  23. package/lib/cjs/helpers/debug.js.map +1 -1
  24. package/lib/cjs/helpers/emails.js +2 -2
  25. package/lib/cjs/helpers/emails.js.map +1 -1
  26. package/lib/cjs/helpers/eval.js +1 -2
  27. package/lib/cjs/helpers/eval.js.map +1 -1
  28. package/lib/cjs/helpers/file.js +4 -4
  29. package/lib/cjs/helpers/file.js.map +1 -1
  30. package/lib/cjs/helpers/flatted.js +2 -2
  31. package/lib/cjs/helpers/flatted.js.map +1 -1
  32. package/lib/cjs/helpers/functions.js +1 -2
  33. package/lib/cjs/helpers/functions.js.map +1 -1
  34. package/lib/cjs/helpers/graph/calendar.types.js +2 -3
  35. package/lib/cjs/helpers/graph/calendar.types.js.map +1 -1
  36. package/lib/cjs/helpers/http.js +3 -3
  37. package/lib/cjs/helpers/http.js.map +1 -1
  38. package/lib/cjs/helpers/json.js +3 -4
  39. package/lib/cjs/helpers/json.js.map +1 -1
  40. package/lib/cjs/helpers/md5.js +5 -2
  41. package/lib/cjs/helpers/md5.js.map +1 -1
  42. package/lib/cjs/helpers/objects.js +16 -16
  43. package/lib/cjs/helpers/objects.js.map +1 -1
  44. package/lib/cjs/helpers/promises.js +8 -9
  45. package/lib/cjs/helpers/promises.js.map +1 -1
  46. package/lib/cjs/helpers/random.js +2 -3
  47. package/lib/cjs/helpers/random.js.map +1 -1
  48. package/lib/cjs/helpers/scheduler/scheduler.js +4 -4
  49. package/lib/cjs/helpers/scheduler/scheduler.js.map +1 -1
  50. package/lib/cjs/helpers/sharepoint.js +57 -55
  51. package/lib/cjs/helpers/sharepoint.js.map +1 -1
  52. package/lib/cjs/helpers/strings.js +29 -30
  53. package/lib/cjs/helpers/strings.js.map +1 -1
  54. package/lib/cjs/helpers/typecheckers.js +36 -36
  55. package/lib/cjs/helpers/typecheckers.js.map +1 -1
  56. package/lib/cjs/helpers/url.js +14 -15
  57. package/lib/cjs/helpers/url.js.map +1 -1
  58. package/lib/cjs/utils/auth/common.js +11 -10
  59. package/lib/cjs/utils/auth/common.js.map +1 -1
  60. package/lib/cjs/utils/auth/discovery.js +4 -5
  61. package/lib/cjs/utils/auth/discovery.js.map +1 -1
  62. package/lib/cjs/utils/base64.js +1 -2
  63. package/lib/cjs/utils/base64.js.map +1 -1
  64. package/lib/cjs/utils/date.js +2 -3
  65. package/lib/cjs/utils/date.js.map +1 -1
  66. package/lib/cjs/utils/emails.js +1 -2
  67. package/lib/cjs/utils/emails.js.map +1 -1
  68. package/lib/cjs/utils/localstoragecache.js +8 -8
  69. package/lib/cjs/utils/localstoragecache.js.map +1 -1
  70. package/lib/cjs/utils/rest.js +52 -42
  71. package/lib/cjs/utils/rest.js.map +1 -1
  72. package/lib/cjs/utils/sharepoint.rest/common.js +32 -27
  73. package/lib/cjs/utils/sharepoint.rest/common.js.map +1 -1
  74. package/lib/cjs/utils/sharepoint.rest/date.js +8 -6
  75. package/lib/cjs/utils/sharepoint.rest/date.js.map +1 -1
  76. package/lib/cjs/utils/sharepoint.rest/file.folder.js +28 -29
  77. package/lib/cjs/utils/sharepoint.rest/file.folder.js.map +1 -1
  78. package/lib/cjs/utils/sharepoint.rest/item.js +33 -32
  79. package/lib/cjs/utils/sharepoint.rest/item.js.map +1 -1
  80. package/lib/cjs/utils/sharepoint.rest/list.js +116 -72
  81. package/lib/cjs/utils/sharepoint.rest/list.js.map +1 -1
  82. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsByCaml.js +1 -2
  83. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsByCaml.js.map +1 -1
  84. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsById.js +2 -3
  85. package/lib/cjs/utils/sharepoint.rest/listutils/GetListItemsById.js.map +1 -1
  86. package/lib/cjs/utils/sharepoint.rest/listutils/common.js +2 -2
  87. package/lib/cjs/utils/sharepoint.rest/listutils/common.js.map +1 -1
  88. package/lib/cjs/utils/sharepoint.rest/location.js +2 -3
  89. package/lib/cjs/utils/sharepoint.rest/location.js.map +1 -1
  90. package/lib/cjs/utils/sharepoint.rest/navigation-links.js +3 -4
  91. package/lib/cjs/utils/sharepoint.rest/navigation-links.js.map +1 -1
  92. package/lib/cjs/utils/sharepoint.rest/user.js +26 -27
  93. package/lib/cjs/utils/sharepoint.rest/user.js.map +1 -1
  94. package/lib/cjs/utils/sharepoint.rest/web.js +109 -73
  95. package/lib/cjs/utils/sharepoint.rest/web.js.map +1 -1
  96. package/lib/esm/helpers/browser.js +8 -20
  97. package/lib/esm/helpers/browser.js.map +1 -1
  98. package/lib/esm/helpers/browserinfo.js +5 -1
  99. package/lib/esm/helpers/browserinfo.js.map +1 -1
  100. package/lib/esm/helpers/md5.js +4 -0
  101. package/lib/esm/helpers/md5.js.map +1 -1
  102. package/lib/esm/helpers/sharepoint.js +12 -10
  103. package/lib/esm/helpers/sharepoint.js.map +1 -1
  104. package/lib/esm/helpers/typecheckers.js +1 -1
  105. package/lib/esm/helpers/typecheckers.js.map +1 -1
  106. package/lib/esm/utils/auth/common.js +7 -5
  107. package/lib/esm/utils/auth/common.js.map +1 -1
  108. package/lib/esm/utils/rest.js +48 -38
  109. package/lib/esm/utils/rest.js.map +1 -1
  110. package/lib/esm/utils/sharepoint.rest/common.js +20 -16
  111. package/lib/esm/utils/sharepoint.rest/common.js.map +1 -1
  112. package/lib/esm/utils/sharepoint.rest/date.js +7 -4
  113. package/lib/esm/utils/sharepoint.rest/date.js.map +1 -1
  114. package/lib/esm/utils/sharepoint.rest/item.js +7 -6
  115. package/lib/esm/utils/sharepoint.rest/item.js.map +1 -1
  116. package/lib/esm/utils/sharepoint.rest/list.js +57 -13
  117. package/lib/esm/utils/sharepoint.rest/list.js.map +1 -1
  118. package/lib/esm/utils/sharepoint.rest/web.js +46 -9
  119. package/lib/esm/utils/sharepoint.rest/web.js.map +1 -1
  120. package/lib/types/helpers/browser.d.ts +1 -1
  121. package/lib/types/helpers/browserinfo.d.ts +1 -0
  122. package/lib/types/helpers/sharepoint.d.ts +1 -1
  123. package/lib/types/utils/sharepoint.rest/common.d.ts +2 -0
  124. package/lib/types/utils/sharepoint.rest/item.d.ts +4 -1
  125. package/lib/types/utils/sharepoint.rest/list.d.ts +11 -2
  126. package/lib/types/utils/sharepoint.rest/web.d.ts +3 -1
  127. package/package.json +12 -3
  128. package/test/auth.ts +31 -0
  129. package/test/hooks.ts +181 -0
  130. package/test/readme.md +61 -0
  131. package/test/sp/files-folders.ts +258 -0
  132. package/test/sp/items.ts +295 -0
  133. package/test/sp/lists.ts +679 -0
  134. package/test/sp/users.ts +57 -0
  135. package/test/sp/webs.ts +43 -0
@@ -0,0 +1,295 @@
1
+ import assert from "assert";
2
+
3
+ import { genericCreateField, genericCreateList } from "./lists";
4
+
5
+ import {
6
+ AddItem,
7
+ GetListItemFieldDisplayValue,
8
+ GetListItemFieldValues,
9
+ UpdateItem,
10
+ RecycleListItem,
11
+ DeleteListItem,
12
+ GetListItemsByCaml,
13
+ GetItemsById,
14
+ GetListItemFieldValue,
15
+ GetListItemFieldValuesHistory,
16
+ AddAttachment,
17
+ GetListItemAttachments,
18
+ DeleteAttachment,
19
+ } from "../../src";
20
+
21
+ function createCamlQueryById(itemId: number): string {
22
+ return `<Where><Eq><FieldRef Name='ID'/><Value Type='Number'>${itemId}</Value></Eq></Where>`;
23
+ }
24
+
25
+ function createCamlQueryByTitle(itemTitle: string): string {
26
+ return `<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>${itemTitle}</Value></Eq></Where>`;
27
+ }
28
+
29
+ async function genericCreateItem(siteUrl: string, listId: string, title: string) {
30
+ const itemData = { Title: title };
31
+ return await AddItem(siteUrl, listId, itemData);
32
+ }
33
+
34
+ describe("List Items", function () {
35
+
36
+ let listId: string, listTitle: string;
37
+ let fieldId: string, fieldTitle: string, fieldInternalName: string;
38
+ const columns = ['Title', 'ID', 'Id', 'FileLeafRef', 'FileDirRef', 'FileRef', 'FileSystemObjectType'];
39
+
40
+ before(async function () {
41
+ ({ Id: listId, Title: listTitle } = await genericCreateList(this.siteUrl, `TestList_${Date.now()}`));
42
+ ({ Id: fieldId, Title: fieldTitle, InternalName: fieldInternalName } = await genericCreateField(this.siteUrl, listId, `TestField_${Date.now()}`));
43
+ });
44
+
45
+ describe("AddItem", function () {
46
+
47
+ let itemId: number, itemTitle: string;
48
+
49
+ specify("add generic item", async function () {
50
+ let success: boolean, errorMessage: string | undefined;
51
+ itemTitle = `TestItem_${Date.now()}`;
52
+ ({ success, errorMessage, itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
53
+
54
+ assert.ok(success, "'AddItem' should be true");
55
+ assert.strictEqual(errorMessage, null, "'errorMessage' should be null");
56
+ assert.ok(itemId, "'itemId' should be valid");
57
+ });
58
+
59
+ specify("verify item by Id", async function () {
60
+ const result = await GetListItemsByCaml(this.siteUrl, listId, createCamlQueryById(itemId), { columns: columns });
61
+ assert.strictEqual(result.length, 1, "GetListItemsByCaml should return one item");
62
+ assert.strictEqual(result[0].Id, itemId, "'Id' should match expected id");
63
+ assert.strictEqual(result[0].Title, itemTitle, "'Title' should match expected title");
64
+ });
65
+
66
+ specify("verify list by Title", async function () {
67
+ const result = await GetListItemsByCaml(this.siteUrl, listTitle, createCamlQueryByTitle(itemTitle), { columns: columns });
68
+ assert.strictEqual(result.length, 1, "GetListItemsByCaml should return one item");
69
+ assert.strictEqual(result[0].Id, itemId, "'Id' should match expected id");
70
+ assert.strictEqual(result[0].Title, itemTitle, "'Title' should match expected title");
71
+ });
72
+
73
+ });
74
+
75
+ describe("GetItemsById", function () {
76
+
77
+ let itemId: number, itemTitle: string;
78
+
79
+ before(async function () {
80
+ itemTitle = `TestItem_${Date.now()}`;
81
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
82
+ });
83
+
84
+ specify("get item by Id", async function () {
85
+ const result = await GetItemsById(this.siteUrl, listId, [itemId]);
86
+ assert.strictEqual(result.filter(x => true).length, 1, "GetItemsById should return one item");
87
+ assert.strictEqual(result[itemId].Id, itemId, "'Id' should match expected id");
88
+ assert.strictEqual(result[itemId].Title, itemTitle, "'Title' should match expected title");
89
+ });
90
+ });
91
+
92
+ describe("GetListItemsByCaml", function () {
93
+
94
+ let itemId: number, itemTitle: string;
95
+
96
+ before(async function () {
97
+ itemTitle = `TestItem_${Date.now()}`;
98
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
99
+ });
100
+
101
+ specify("get item by Id", async function () {
102
+ const result = await GetListItemsByCaml(this.siteUrl, listId, createCamlQueryById(itemId), { columns: columns });
103
+ assert.strictEqual(result.length, 1, "GetListItemsByCaml should return one item");
104
+ assert.strictEqual(result[0].Id, itemId, "'Id' should match expected id");
105
+ assert.strictEqual(result[0].Title, itemTitle, "'Title' should match expected title");
106
+ });
107
+
108
+ specify("get item by Title", async function () {
109
+ const result = await GetListItemsByCaml(this.siteUrl, listTitle, createCamlQueryByTitle(itemTitle), { columns: columns });
110
+ assert.strictEqual(result.length, 1, "GetListItemsByCaml should return one item");
111
+ assert.strictEqual(result[0].Id, itemId, "'Id' should match expected id");
112
+ assert.strictEqual(result[0].Title, itemTitle, "'Title' should match expected title");
113
+ });
114
+ });
115
+
116
+ describe("DeleteItem by Id", function () {
117
+
118
+ let itemId: number, itemTitle: string;
119
+
120
+ before(async function () {
121
+ itemTitle = `TestItem_${Date.now()}`;
122
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
123
+ });
124
+
125
+ specify("delete item by Id", async function () {
126
+ const { deleted, errorMessage } = await DeleteListItem(this.siteUrl, listId, itemId);
127
+ assert.ok(deleted, "'deleted' should be true");
128
+ });
129
+
130
+ specify("verify delete by Id", async function () {
131
+ const result = await GetListItemsByCaml(this.siteUrl, listId, createCamlQueryById(itemId), { columns: columns });
132
+ assert.strictEqual(result.length, 0, "GetListItemsByCaml should return no items after deletion");
133
+ });
134
+
135
+ specify("verify by Title", async function () {
136
+ const result = await GetListItemsByCaml(this.siteUrl, listTitle, createCamlQueryByTitle(itemTitle), { columns: columns });
137
+ assert.strictEqual(result.length, 0, "GetListItemsByCaml should return no items after deletion");
138
+ });
139
+ });
140
+
141
+ describe("RecycleItem by Id", function () {
142
+
143
+ let itemId: number, itemTitle: string;
144
+
145
+ before(async function () {
146
+ itemTitle = `TestItem_${Date.now()}`;
147
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
148
+ });
149
+
150
+ specify("recycle item by Id", async function () {
151
+ const { recycled, errorMessage } = await RecycleListItem(this.siteUrl, listId, itemId);
152
+ assert.ok(recycled, "'recycled' should be true");
153
+ assert.strictEqual(errorMessage, undefined, "'errorMessage' should be undefined");
154
+ });
155
+
156
+ specify("verify recycle by Id", async function () {
157
+ const result = await GetListItemsByCaml(this.siteUrl, listId, createCamlQueryById(itemId), { columns: columns });
158
+ assert.strictEqual(result.length, 0, "GetListItemsByCaml should return no items after recycling");
159
+ });
160
+
161
+ specify("verify recycle by Title", async function () {
162
+ const result = await GetListItemsByCaml(this.siteUrl, listTitle, createCamlQueryByTitle(itemTitle), { columns: columns });
163
+ assert.strictEqual(result.length, 0, "GetListItemsByCaml should return no items after recycling");
164
+ });
165
+ });
166
+
167
+ describe("UpdateItem", function () {
168
+
169
+ let itemId: number, itemTitle: string;
170
+
171
+ before(async function () {
172
+ itemTitle = `TestItem_${Date.now()}`;
173
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
174
+ });
175
+
176
+ const updatedTitle = `UpdatedTitle_${Date.now()}`;
177
+
178
+ specify("update Title field value", async function () {
179
+ const result = await UpdateItem(this.siteUrl, listId, itemId, { Title: updatedTitle });
180
+ assert.strictEqual(result.success, true, "UpdateItem should report success");
181
+ assert.strictEqual(result.itemId, itemId, "UpdateItem should return the correct item ID");
182
+ });
183
+
184
+ specify("verify by Id", async function () {
185
+ const values = await GetListItemFieldValues(this.siteUrl, listId, itemId, ["Title"]);
186
+ assert.strictEqual(values.Title, updatedTitle, "Title should match the updated value");
187
+ });
188
+ });
189
+
190
+
191
+
192
+
193
+ describe("GetListItemField...", function () {
194
+
195
+ let itemId: number, itemTitle: string, itemFieldValue: string;
196
+
197
+ before(async function () {
198
+ itemTitle = `TestItem_${Date.now()}`;
199
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
200
+ itemFieldValue = `TestValue_${Date.now()}`;
201
+ await UpdateItem(this.siteUrl, listId, itemId, { [fieldInternalName]: itemFieldValue });
202
+ });
203
+
204
+ describe("GetListItemFieldValue", function () {
205
+ specify("get Title field value", async function () {
206
+ const value = await GetListItemFieldValue(this.siteUrl, listId, itemId, "Title");
207
+ assert.strictEqual(value, itemTitle, "returned value should match title");
208
+ });
209
+ specify("get custom field value", async function () {
210
+ const value = await GetListItemFieldValue(this.siteUrl, listId, itemId, fieldInternalName);
211
+ assert.strictEqual(value, itemFieldValue, "returned field value should match custom field value");
212
+ });
213
+ });
214
+
215
+ describe("GetListItemFieldValues", function () {
216
+ specify("get Title field value and custom field value", async function () {
217
+ const values = await GetListItemFieldValues(this.siteUrl, listId, itemId, ["Title", "ID", fieldInternalName]);
218
+ assert.ok(values, "should return values");
219
+ assert.strictEqual(values.Title, itemTitle, "Title value should be correct");
220
+ assert.strictEqual(values.ID, itemId, "ID value should be correct");
221
+ assert.strictEqual(values[fieldInternalName], itemFieldValue, "Custom field value should be correct");
222
+ });
223
+ });
224
+
225
+ describe("GetListItemFieldDisplayValue", function () {
226
+ specify("get Title field display value", async function () {
227
+ const value = await GetListItemFieldDisplayValue(this.siteUrl, listId, itemId, "Title");
228
+ assert.strictEqual(value, itemTitle, "returned value should match title");
229
+ });
230
+ specify("get custom field display value", async function () {
231
+ const value = await GetListItemFieldDisplayValue(this.siteUrl, listId, itemId, fieldInternalName);
232
+ assert.strictEqual(value, itemFieldValue, "returned field value should match custom field value");
233
+ });
234
+ });
235
+
236
+ describe("GetListItemFieldDisplayValues", function () {
237
+ specify("get Title field display value and custom field display value", async function () {
238
+ const values = await GetListItemFieldValues(this.siteUrl, listId, itemId, ["Title", "ID", fieldInternalName]);
239
+ assert.ok(values, "should return values");
240
+ assert.strictEqual(values.Title, itemTitle, "Title value should be correct");
241
+ assert.strictEqual(values.ID, itemId, "ID value should be correct");
242
+ assert.strictEqual(values[fieldInternalName], itemFieldValue, "custom field value should be correct");
243
+ });
244
+ });
245
+
246
+ describe("GetListItemFieldValueHistory", function () {
247
+ specify("get Title field history and custom field history", async function () {
248
+ const history = await GetListItemFieldValuesHistory(this.siteUrl, listId, itemId, ["Title", fieldInternalName]);
249
+ assert.ok(history, "should return history");
250
+ assert.strictEqual(history.length, 2, "should have two versions");
251
+ assert.strictEqual(history[1].Title, itemTitle, "first Title is correct");
252
+ assert.strictEqual(history[1][fieldInternalName.replace(/_/g, '_x005f_')], null, "first custom field value is null");
253
+ assert.strictEqual(history[0].Title, itemTitle, "second Title is correct");
254
+ assert.strictEqual(history[0][fieldInternalName.replace(/_/g, '_x005f_')], itemFieldValue, "second custom field value is correct");
255
+ });
256
+ });
257
+ });
258
+
259
+ describe("Attachments", function () {
260
+
261
+ let itemId: number;
262
+ const itemTitle = `Item_With_Attachments_${Date.now()}`;
263
+ const attachmentFileName = "test-attachment.txt";
264
+ const attachmentContent = "This is the content of the attachment.";
265
+
266
+ before(async function () {
267
+ ({ itemId } = await genericCreateItem(this.siteUrl, listId, itemTitle));
268
+ });
269
+
270
+ specify("AddAttachment should add a file to the list item", async function () {
271
+ const result = await AddAttachment(this.siteUrl, listId, itemId, attachmentFileName, attachmentContent as any);
272
+
273
+ assert.ok(result, "AddAttachment should return a result object");
274
+ assert.strictEqual(result.FileName, attachmentFileName, "Attached file name should match");
275
+ assert.ok(result.ServerRelativeUrl.endsWith(attachmentFileName), "ServerRelativeUrl should end with the file name");
276
+ });
277
+
278
+ specify("GetListItemAttachments should retrieve the added attachment", async function () {
279
+ const attachments = await GetListItemAttachments(this.siteUrl, listId, itemId);
280
+ assert.ok(Array.isArray(attachments), "GetListItemAttachments should return an array");
281
+ assert.strictEqual(attachments.length, 1, "There should be exactly one attachment");
282
+ assert.strictEqual(attachments[0].FileName, attachmentFileName, "The retrieved attachment's FileName should match");
283
+ });
284
+
285
+ specify("DeleteAttachment should remove the file from the list item", async function () {
286
+ const result = await DeleteAttachment(this.siteUrl, listId, itemId, attachmentFileName);
287
+ assert.ok(result.deleted, "'deleted' should be true");
288
+ });
289
+
290
+ specify("GetListItemAttachments should confirm the attachment is deleted", async function () {
291
+ const attachments = await GetListItemAttachments(this.siteUrl, listId, itemId);
292
+ assert.strictEqual(attachments.length, 0, "There should be no attachments after deletion");
293
+ });
294
+ });
295
+ });