dce-reactkit 3.11.4 → 3.12.1-beta-cross-server.2

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 (41) hide show
  1. package/.vscode/settings.json +1 -3
  2. package/README.md +20 -0
  3. package/dist/cjs/index.js +294 -162
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/types/helpers/dataSigner.d.ts +38 -0
  6. package/dist/cjs/types/helpers/genRouteHandler.d.ts +10 -10
  7. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/index.d.ts +15 -13
  8. package/dist/cjs/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -6
  9. package/dist/cjs/types/index.d.ts +3 -2
  10. package/dist/cjs/types/server/initCrossServerCredentialCollection.d.ts +8 -0
  11. package/dist/cjs/types/server/initServer.d.ts +11 -0
  12. package/dist/cjs/types/types/CrossServerCredential.d.ts +11 -0
  13. package/dist/cjs/types/types/ReactKitErrorCode.d.ts +13 -1
  14. package/dist/esm/index.js +293 -162
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/types/helpers/dataSigner.d.ts +38 -0
  17. package/dist/esm/types/helpers/genRouteHandler.d.ts +10 -10
  18. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/index.d.ts +15 -13
  19. package/dist/esm/types/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.d.ts +0 -6
  20. package/dist/esm/types/index.d.ts +3 -2
  21. package/dist/esm/types/server/initCrossServerCredentialCollection.d.ts +8 -0
  22. package/dist/esm/types/server/initServer.d.ts +11 -0
  23. package/dist/esm/types/types/CrossServerCredential.d.ts +11 -0
  24. package/dist/esm/types/types/ReactKitErrorCode.d.ts +13 -1
  25. package/dist/index.d.ts +62 -35
  26. package/genEncodedSecret.ts +28 -0
  27. package/package.json +5 -2
  28. package/src/components/IntelliTable.tsx +1 -1
  29. package/src/components/ItemPicker/NestableItemList.tsx +0 -1
  30. package/src/helpers/dataSigner.ts +232 -0
  31. package/src/helpers/genRouteHandler.ts +55 -95
  32. package/src/helpers/visitEndpointOnAnotherServer/index.ts +42 -41
  33. package/src/helpers/visitEndpointOnAnotherServer/sendServerToServerRequest.ts +3 -5
  34. package/src/index.ts +4 -2
  35. package/src/server/initCrossServerCredentialCollection.ts +16 -0
  36. package/src/server/initServer.ts +18 -0
  37. package/src/types/CrossServerCredential.ts +16 -0
  38. package/src/types/ReactKitErrorCode.tsx +13 -1
  39. package/dist/cjs/types/helpers/getWordCount.d.ts +0 -10
  40. package/dist/esm/types/helpers/getWordCount.d.ts +0 -10
  41. package/src/helpers/getWordCount.ts +0 -26
@@ -27,6 +27,9 @@ let _cacclGetLaunchInfo: GetLaunchInfoFunction;
27
27
  // Stored copy of dce-mango log collection
28
28
  let _logCollection: any;
29
29
 
30
+ // Stored copy of dce-mango cross-server credential collection
31
+ let _crossServerCredentialCollection: any;
32
+
30
33
  /*------------------------------------------------------------------------*/
31
34
  /* Helpers */
32
35
  /*------------------------------------------------------------------------*/
@@ -58,6 +61,16 @@ export const internalGetLogCollection = () => {
58
61
  return _logCollection ?? null;
59
62
  };
60
63
 
64
+ /**
65
+ * Get cross-server credential collection
66
+ * @author Gabe Abrams
67
+ * @return cross-server credential collection if one was included during launch or null
68
+ * if we don't have a cross-server credential collection (yet)
69
+ */
70
+ export const internalGetCrossServerCredentialCollection = () => {
71
+ return _crossServerCredentialCollection ?? null;
72
+ };
73
+
61
74
  /*------------------------------------------------------------------------*/
62
75
  /* Main */
63
76
  /*------------------------------------------------------------------------*/
@@ -78,6 +91,9 @@ export const internalGetLogCollection = () => {
78
91
  * userIds are allowed to review logs. If a dce-mango collection, only
79
92
  * Canvas admins with entries in that collection ({ userId, ...}) are allowed
80
93
  * to review logs
94
+ * @param [opts.crossServerCredentialCollection] mongo collection from dce-mango to use for
95
+ * storing cross-server credentials. If none is included, cross-server credentials
96
+ * are not supported
81
97
  */
82
98
  const initServer = (
83
99
  opts: {
@@ -85,10 +101,12 @@ const initServer = (
85
101
  getLaunchInfo: GetLaunchInfoFunction,
86
102
  logCollection?: any,
87
103
  logReviewAdmins?: (number[] | any),
104
+ crossServerCredentialCollection?: any,
88
105
  },
89
106
  ) => {
90
107
  _cacclGetLaunchInfo = opts.getLaunchInfo;
91
108
  _logCollection = opts.logCollection;
109
+ _crossServerCredentialCollection = opts.crossServerCredentialCollection;
92
110
 
93
111
  /*----------------------------------------*/
94
112
  /* Logging */
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Single cross-server credential
3
+ * @author Gabe Abrams
4
+ */
5
+ type CrossServerCredential = {
6
+ // Description of the credential (human-readable)
7
+ description: string,
8
+ // The key of the credential
9
+ key: string,
10
+ // The encoded secret of the credential
11
+ encodedeSecret: string,
12
+ // The list of scopes for the credential
13
+ scopes: string[],
14
+ };
15
+
16
+ export default CrossServerCredential;
@@ -1,4 +1,4 @@
1
- // Highest error code = DRK18
1
+ // Highest error code = DRK30
2
2
 
3
3
  /**
4
4
  * List of error codes built into the react kit
@@ -25,6 +25,18 @@ enum ReactKitErrorCode {
25
25
  NotConnected = 'DRK14',
26
26
  SelfSigned = 'DRK15',
27
27
  ResponseParseError = 'DRK16',
28
+ PackUnparseable = 'DRK28',
29
+ PackInvalidMethod = 'DRK19',
30
+ PackInvalidPath = 'DRK20',
31
+ PackInvalidCollection = 'DRK21',
32
+ PackInvalidCredential = 'DRK23',
33
+ PackInvalidScope = 'DRK22',
34
+ PackInvalidTimestamp = 'DRK24',
35
+ PackInvalidSignature = 'DRK25',
36
+ PackInvalidBody = 'DRK26',
37
+ CrossServerNoCredentialsToSignWith = 'DRK27',
38
+ CrossServerNoPack = 'DRK29',
39
+ CrossServerNoCredentialEncodingSalt = 'DRK30',
28
40
  }
29
41
 
30
42
  export default ReactKitErrorCode;
@@ -1,10 +0,0 @@
1
- /**
2
- * Get number of words in string
3
- * @author Gardenia Liu
4
- * @author Allison Zhang
5
- * @author Gabe Abrams
6
- * @param text the string to check
7
- * @returns number of words in the string
8
- */
9
- declare const getWordCount: (text: string) => number;
10
- export default getWordCount;
@@ -1,10 +0,0 @@
1
- /**
2
- * Get number of words in string
3
- * @author Gardenia Liu
4
- * @author Allison Zhang
5
- * @author Gabe Abrams
6
- * @param text the string to check
7
- * @returns number of words in the string
8
- */
9
- declare const getWordCount: (text: string) => number;
10
- export default getWordCount;
@@ -1,26 +0,0 @@
1
- const punctuationRegex = /[!@#$%^&*(),.?\/;:'"\-\[\]]/g;
2
-
3
- /**
4
- * Get number of words in string
5
- * @author Gardenia Liu
6
- * @author Allison Zhang
7
- * @author Gabe Abrams
8
- * @param text the string to check
9
- * @returns number of words in the string
10
- */
11
- const getWordCount = (text: string): number => {
12
- const trimmedTextWithoutPunctuation = (
13
- text
14
- // Remove leading and trailing whitespace
15
- .trim()
16
- // Remove punctuation
17
- .replace(punctuationRegex, '')
18
- );
19
- if (trimmedTextWithoutPunctuation.length === 0) {
20
- return 0;
21
- }
22
-
23
- return trimmedTextWithoutPunctuation.split(/\s+/g).length;
24
- };
25
-
26
- export default getWordCount;