@ueu/ueu-canvas 0.0.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 (133) hide show
  1. package/LICENSE +21 -0
  2. package/html-loader.js +7 -0
  3. package/jest.config.js +20 -0
  4. package/package.json +45 -0
  5. package/src/Account.ts +69 -0
  6. package/src/NotImplementedException.ts +3 -0
  7. package/src/__mocks__/Account.ts +55 -0
  8. package/src/__mocks__/index.ts +8 -0
  9. package/src/__mocks__/mockAccountData.ts +43 -0
  10. package/src/__mocks__/mockEnrollment.ts +22 -0
  11. package/src/__mocks__/mockRubricData.ts +71 -0
  12. package/src/__mocks__/mockTabData.ts +13 -0
  13. package/src/__mocks__/mockTermData.ts +7 -0
  14. package/src/__mocks__/mockUserData.ts +14 -0
  15. package/src/__mocks__/utils.ts +9 -0
  16. package/src/__tests__/canvasUtils.test.ts +527 -0
  17. package/src/__tests__/fetch.test.ts +310 -0
  18. package/src/__tests__/profile.test.ts +19 -0
  19. package/src/__tests__/rubrics.test.ts +131 -0
  20. package/src/baseCanvasObject.ts +139 -0
  21. package/src/canvasDataDefs.ts +124 -0
  22. package/src/canvasUtils.ts +420 -0
  23. package/src/consts.ts +2 -0
  24. package/src/content/BaseContentItem.ts +219 -0
  25. package/src/content/ContentKind.ts +85 -0
  26. package/src/content/__mocks__/determineContent.ts +27 -0
  27. package/src/content/__mocks__/mockAssignmentSubmission.ts +37 -0
  28. package/src/content/__mocks__/mockContentData.ts +98 -0
  29. package/src/content/__mocks__/openThisContentInTarget.ts +2 -0
  30. package/src/content/__testingUtils__/utils.ts +47 -0
  31. package/src/content/__tests__/determineContent.test.ts +101 -0
  32. package/src/content/__tests__/getContentFuncs.test.ts +78 -0
  33. package/src/content/assignments/Assignment.ts +69 -0
  34. package/src/content/assignments/AssignmentKind.ts +29 -0
  35. package/src/content/assignments/__tests__/AssignmentKind.test.ts +31 -0
  36. package/src/content/assignments/__tests__/assignments.test.ts +72 -0
  37. package/src/content/assignments/deleteAssignmentGroup.ts +15 -0
  38. package/src/content/assignments/genAssignmentGroups.ts +15 -0
  39. package/src/content/assignments/index.ts +31 -0
  40. package/src/content/assignments/legacy.ts +11 -0
  41. package/src/content/assignments/updateAssignmentDueDates.ts +25 -0
  42. package/src/content/determineContent.ts +72 -0
  43. package/src/content/discussions/Discussion.ts +32 -0
  44. package/src/content/discussions/DiscussionKind.ts +30 -0
  45. package/src/content/discussions/__tests__/DiscussionKind.test.ts +31 -0
  46. package/src/content/discussions/genEquivalentDiscussionData.ts +97 -0
  47. package/src/content/discussions/index.ts +2 -0
  48. package/src/content/getContentFuncs.ts +30 -0
  49. package/src/content/index.ts +11 -0
  50. package/src/content/openThisContentInTarget.ts +38 -0
  51. package/src/content/pages/Page.ts +35 -0
  52. package/src/content/pages/PageKind.ts +39 -0
  53. package/src/content/pages/__tests__/PageKind.test.ts +86 -0
  54. package/src/content/pages/__tests__/learningMaterialsForModule.ts +57 -0
  55. package/src/content/pages/index.ts +12 -0
  56. package/src/content/pages/learningMaterialsForModule.ts +16 -0
  57. package/src/content/pages/types.ts +11 -0
  58. package/src/content/quizzes/Quiz.ts +25 -0
  59. package/src/content/quizzes/QuizKind.ts +23 -0
  60. package/src/content/quizzes/__tests__/QuizKind.test.ts +30 -0
  61. package/src/content/quizzes/index.ts +3 -0
  62. package/src/content/quizzes/types.ts +101 -0
  63. package/src/content/types.ts +302 -0
  64. package/src/course/Course.ts +538 -0
  65. package/src/course/IBlueprintCourse.ts +8 -0
  66. package/src/course/__mocks__/blueprint.ts +31 -0
  67. package/src/course/__mocks__/mockCourseData.ts +49 -0
  68. package/src/course/__mocks__/mockLatePolicy.ts +14 -0
  69. package/src/course/__mocks__/mockModuleData.ts +60 -0
  70. package/src/course/__mocks__/mockProgressData.ts +28 -0
  71. package/src/course/__mocks__/syllabus.gallant.html +302 -0
  72. package/src/course/__mocks__/syllabus.goofus.html +288 -0
  73. package/src/course/__mocks__/syllabus.grad.html +282 -0
  74. package/src/course/__tests__/Course.test.ts +91 -0
  75. package/src/course/__tests__/blueprint.test.ts +292 -0
  76. package/src/course/__tests__/changeStartDate.test.ts +180 -0
  77. package/src/course/__tests__/index.test.ts +104 -0
  78. package/src/course/blueprint.ts +116 -0
  79. package/src/course/cachedGetAssociatedCoursesFunc.ts +13 -0
  80. package/src/course/changeStartDate.ts +139 -0
  81. package/src/course/code.ts +32 -0
  82. package/src/course/courseTypes.ts +161 -0
  83. package/src/course/getCourseIdFromUrl.ts +7 -0
  84. package/src/course/getSections.ts +9 -0
  85. package/src/course/getTermNameFromSections.ts +9 -0
  86. package/src/course/index.ts +12 -0
  87. package/src/course/migration/__mocks__/mockMigrationData.ts +39 -0
  88. package/src/course/migration/__tests__/migration.test.ts +173 -0
  89. package/src/course/migration/__tests__/migrationCache.test.ts +45 -0
  90. package/src/course/migration/index.ts +134 -0
  91. package/src/course/migration/migrationCache.ts +56 -0
  92. package/src/course/modules.ts +113 -0
  93. package/src/course/notABlueprintError.ts +3 -0
  94. package/src/course/references/getReferencesForText.test.ts +18 -0
  95. package/src/course/references/getReferencesForText.ts +12 -0
  96. package/src/course/references/getReferencesTemplate.ts +28 -0
  97. package/src/course/references/mockCiteAsResponse.ts +320 -0
  98. package/src/course/retireBlueprint.ts +21 -0
  99. package/src/course/toolbox.ts +107 -0
  100. package/src/date.ts +119 -0
  101. package/src/enrollments/EnrollmentTypes.ts +76 -0
  102. package/src/enrollments/enrollmentRole.ts +6 -0
  103. package/src/enrollments/getEnrollmentGenerator.ts +79 -0
  104. package/src/enrollments/index.ts +3 -0
  105. package/src/fetch/__mocks__/fetchJson.ts +1 -0
  106. package/src/fetch/__mocks__/getPagedDataGenerator.ts +8 -0
  107. package/src/fetch/__mocks__/index.ts +6 -0
  108. package/src/fetch/apiGetConfig.ts +10 -0
  109. package/src/fetch/apiWriteConfig.ts +13 -0
  110. package/src/fetch/canvasDataFetchGenFunc.ts +20 -0
  111. package/src/fetch/fetchJson.ts +22 -0
  112. package/src/fetch/getPagedDataGenerator.ts +157 -0
  113. package/src/fetch/index.ts +5 -0
  114. package/src/fetch/utils.ts +16 -0
  115. package/src/files.ts +60 -0
  116. package/src/fixes/annotations.ts +105 -0
  117. package/src/fixes/index.ts +81 -0
  118. package/src/index.ts +29 -0
  119. package/src/profile.ts +253 -0
  120. package/src/rubricTypes.ts +82 -0
  121. package/src/rubrics.ts +48 -0
  122. package/src/term/Term.ts +77 -0
  123. package/src/term/__tests__/dateFromTermName.test.ts +22 -0
  124. package/src/term/__tests__/getTermsGenerator.test.ts +24 -0
  125. package/src/term/dateFromTermName.ts +17 -0
  126. package/src/term/getTermsGenerator.ts +21 -0
  127. package/src/term/index.ts +3 -0
  128. package/src/toolbox.ts +19 -0
  129. package/src/types.ts +134 -0
  130. package/src/users/getUserGenerator.ts +39 -0
  131. package/src/users/index.ts +1 -0
  132. package/tsconfig.json +46 -0
  133. package/webpack.config.js +122 -0
package/src/types.ts ADDED
@@ -0,0 +1,134 @@
1
+ import {CanvasData, IUserData} from "@/canvasDataDefs";
2
+ import {ITermData} from "@/term/Term";
3
+ import {Page} from "@/content/pages/Page";
4
+
5
+ export interface ICourseData extends CanvasData {
6
+ id: number,
7
+ sis_course_id?: string,
8
+ uuid: string,
9
+ name: string,
10
+ course_code: string,
11
+ original_name: string,
12
+ workflow_state: 'available' | 'unpublished' | 'completed' | 'deleted',
13
+ account_id: number,
14
+ root_account_id: number,
15
+ enrollment_term_id: number[] | number,
16
+ grading_periods?: CanvasData[] | null,
17
+ grading_standard_id: number,
18
+ grade_passback_setting?: "nightly_sync" | "disabled" | '',
19
+ created_at: string,
20
+ start_at: string,
21
+ end_at: string,
22
+ locale: string,
23
+ enrollments: number | null,
24
+ total_students?: number,
25
+ calendar: CanvasData,
26
+ default_view: 'feed' | 'wiki' | 'modules' | 'assignments' | 'syllabus',
27
+ syllabus_body?: string,
28
+ needs_grading_count?: number,
29
+ term?: ITermData,
30
+ course_progress: CanvasData,
31
+ apply_assignment_group_weights: boolean,
32
+ permissions: Record<string, boolean>,
33
+ public_description: string,
34
+ storage_quota_mb: number,
35
+ storage_quota_used_mb: number,
36
+ hide_final_grades: boolean,
37
+ license: string,
38
+ allow_student_assignment_edits: boolean,
39
+ allow_wiki_comments: boolean,
40
+ allow_student_forum_attachments: boolean,
41
+ open_enrollment: boolean,
42
+ self_enrollment: boolean,
43
+ restrict_enrollments_to_course_dates: boolean,
44
+ course_format: string,
45
+ access_restricted_by_date?: boolean
46
+ time_zone: string,
47
+ blueprint: boolean,
48
+ blueprint_restrictions: IBlueprintContentRestrictions,
49
+ blueprint_restrictions_by_object_type: {
50
+ assignment?: IBlueprintContentRestrictions,
51
+ attachment?: IBlueprintContentRestrictions,
52
+ discussion_topic?: IBlueprintContentRestrictions,
53
+ quiz?: IBlueprintContentRestrictions,
54
+ wiki_page?: IBlueprintContentRestrictions
55
+ }
56
+ template: boolean
57
+
58
+ }
59
+
60
+ export interface ICourseSettings {
61
+ "allow_student_discussion_topics": boolean,
62
+ "allow_student_forum_attachments": boolean,
63
+ "allow_student_discussion_editing": boolean,
64
+ "grading_standard_enabled": boolean,
65
+ "grading_standard_id": number,
66
+ "allow_student_organized_groups": boolean,
67
+ "hide_final_grades": boolean,
68
+ "hide_distribution_graphs": boolean,
69
+ "hide_sections_on_course_users_page": boolean,
70
+ "lock_all_announcements": boolean,
71
+ "usage_rights_required": boolean,
72
+ "homeroom_course": boolean,
73
+ "default_due_time": string,
74
+ "conditional_release": boolean,
75
+ show_announcements_on_home_page?: boolean
76
+ }
77
+
78
+ export interface ITabData {
79
+ id: string,
80
+ html_url: string,
81
+ full_url: string,
82
+ position: number,
83
+ hidden?: boolean,
84
+ visibility: string,
85
+ label: string,
86
+ type: string
87
+ }
88
+
89
+ export interface IBlueprintContentRestrictions {
90
+ content: boolean,
91
+ points: boolean,
92
+ due_dates: boolean,
93
+ availability_dates: boolean
94
+ }
95
+
96
+ export type SectionData = Partial<ICourseData>
97
+ & Pick<ICourseData, 'id'
98
+ | 'name'
99
+ | 'course_code'
100
+ | 'sis_course_id'
101
+ >
102
+ & {
103
+ term_name: string,
104
+ teachers: {
105
+ id: number,
106
+ display_name:string,
107
+ anonymous_id: string,
108
+ avatar_image_url: string,
109
+ html_url: string,
110
+ pronouns: string
111
+ }
112
+ }
113
+ export type TopicPermissions = Record<string, any>
114
+ export type FileAttachment = Record<string, any>
115
+ export type ResizeImageMessage = {
116
+ src: string,
117
+ image: HTMLImageElement,
118
+ width: number,
119
+ height?: number
120
+ }
121
+
122
+ export interface IProfile {
123
+ user?: IUserData,
124
+ bio?: string | null,
125
+ displayName?: string | null,
126
+ image?: HTMLImageElement | null,
127
+ imageLink?: string | null,
128
+ sourcePage?: Page | null,
129
+
130
+ }
131
+
132
+ export interface IProfileWithUser extends IProfile {
133
+ user: IUserData
134
+ }
@@ -0,0 +1,39 @@
1
+ import {getPagedDataGenerator} from "@/fetch/getPagedDataGenerator";
2
+ import {IUserData} from "@/index";
3
+
4
+ export type GetUserQueryParams = {
5
+ search_term?: string;
6
+ enrollment_type?: 'student' | 'teacher' | 'ta' | 'observer' | 'designer';
7
+ sort?: 'username' | 'email' | 'sis_id' | 'integration_id' | 'last_login';
8
+ order?: 'asc' | 'desc';
9
+ include_deleted_users?: boolean;
10
+ }
11
+ export type GetAccountUserGenConfig = {
12
+ accountId: number;
13
+ queryParams?: GetUserQueryParams;
14
+ };
15
+
16
+ export type GetCourseUserGenConfig = {
17
+ courseId: number;
18
+ queryParams?: GetUserQueryParams;
19
+ };
20
+
21
+ export type GetUserGenConfig = GetAccountUserGenConfig | GetCourseUserGenConfig;
22
+
23
+ export const getUserGenerator = (
24
+ config:GetUserGenConfig
25
+ ) => {
26
+ let url:string;
27
+
28
+ if('accountId' in config) {
29
+ url = `/api/v1/accounts/${config.accountId}/users`;
30
+ } else if('courseId' in config) {
31
+ url = `/api/v1/courses/${config.courseId}/users`;
32
+ } else {
33
+ throw new Error('config type not recognized')
34
+ }
35
+
36
+ return getPagedDataGenerator<IUserData[]>(url, {
37
+ queryParams: config,
38
+ });
39
+ }
@@ -0,0 +1 @@
1
+ export * from './getUserGenerator'
package/tsconfig.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esNext",
4
+ "lib": [
5
+ "dom",
6
+ "dom.iterable",
7
+ "esnext"
8
+ ],
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "outDir": "./dist",
12
+
13
+ "types": [
14
+ "jest",
15
+ "@testing-library/jest-dom"
16
+ ],
17
+ "baseUrl": "./src",
18
+ "paths": {
19
+ "@/*": [
20
+ "./*"
21
+ ],
22
+ "@canvas/*": [
23
+ "./*"
24
+ ]
25
+ },
26
+ "sourceMap": true,
27
+ "allowJs": true,
28
+ "skipLibCheck": false,
29
+ "esModuleInterop": true,
30
+ "allowSyntheticDefaultImports": true,
31
+ "strict": true,
32
+ "forceConsistentCasingInFileNames": true,
33
+ "noFallthroughCasesInSwitch": true,
34
+ "module": "es2020",
35
+ "moduleResolution": "node",
36
+ "resolveJsonModule": true,
37
+ "isolatedModules": true,
38
+ "noEmit": false,
39
+ "emitDeclarationOnly": false,
40
+ "jsx": "react-jsx"
41
+ },
42
+ "include": [
43
+ "src",
44
+ "tests"
45
+ ]
46
+ }
@@ -0,0 +1,122 @@
1
+ /* eslint-disable @typescript-eslint/no-require-imports,@/no-undef */
2
+ //via https://medium.com/@tharshita13/creating-a-chrome-extension-with-react-a-step-by-step-guide-47fe9bab24a1
3
+
4
+ const path = require("path");
5
+ const HTMLPlugin = require("html-webpack-plugin");
6
+ const CopyPlugin = require("copy-webpack-plugin");
7
+ const webpack = require("webpack");
8
+ const packageJson = require('./package.json');
9
+ const {TsconfigPathsPlugin} = require("tsconfig-paths-webpack-plugin");
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ const dotenv = require('dotenv').config({path: __dirname + '/.env'})
12
+ const isDevelopment = process.env.NODE_ENV !== 'production'
13
+ const outputPath = path.resolve(__dirname, "./dist");
14
+
15
+ const entry = './src/index.ts';
16
+ const output = {
17
+ path: outputPath,
18
+ filename: 'index.js',
19
+ library: {
20
+ name: 'ueu_canvas',
21
+ type: 'umd',
22
+ },
23
+ globalObject: 'this',
24
+ clean: true,
25
+ }
26
+
27
+ const externals = {
28
+ assert: 'commonjs assert', // Node core module
29
+ process: 'commonjs process', // Node core module
30
+ jest: 'commonjs jest', // Testing library
31
+ 'jest-dom': 'commonjs jest-dom',
32
+ 'jest-environment-jsdom': 'commonjs jest-environment-jsdom',
33
+ '@testing-library/jest-dom': 'commonjs @testing-library/jest-dom',
34
+ // Uncomment if you want to exclude the polyfill
35
+ // 'temporal-polyfill': 'commonjs temporal-polyfill',
36
+ };
37
+
38
+
39
+ const
40
+ mjsRule = {
41
+ test: /\.mjs$/,
42
+ include: /node_modules/,
43
+ type: 'javascript/auto',
44
+ };
45
+
46
+ const tsRule = {
47
+ test: /\.tsx?$/,
48
+ use: [{
49
+ loader: "ts-loader",
50
+ options: {compilerOptions: {noEmit: false},}
51
+ }],
52
+ exclude: /node_modules|__test__/,
53
+ };
54
+
55
+ const _module = {
56
+ rules: [
57
+ mjsRule,
58
+ tsRule,
59
+ ],
60
+ };
61
+
62
+ //
63
+ // function getHtmlPlugins(chunks) {
64
+ // return chunks.map(
65
+ // (chunk) =>
66
+ // new HTMLPlugin({
67
+ // title: "React extension",
68
+ // filename: `${chunk}.html`,
69
+ // chunks: [chunk],
70
+ // })
71
+ // );
72
+ // }
73
+
74
+ const createPlugins = () => [
75
+ new webpack.ProvidePlugin({
76
+ process: require.resolve('process/browser'),
77
+ }),
78
+ // new webpack.SourceMapDevToolPlugin({
79
+ // exclude: /node_modules/,
80
+ // test: /\.(ts|js|s?[ca]ss|mjs|tsx)/,
81
+ // filename: '[name][ext].map'
82
+ // }),
83
+ new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
84
+ const mod = resource.request.replace(/^node:/, "");
85
+ switch (mod) {
86
+ case "assert":
87
+ resource.request = "assert";
88
+ break;
89
+ }
90
+ }),
91
+ ];
92
+
93
+
94
+ module.exports = {
95
+ mode: isDevelopment ? 'development' : 'production',
96
+ performance: {
97
+ hints: isDevelopment ? false : 'warning'
98
+ },
99
+ cache: {
100
+ type: 'filesystem',
101
+ allowCollectingMemory: true,
102
+ },
103
+ externals,
104
+ entry,
105
+ output,
106
+ devtool: false,
107
+ module: _module,
108
+ plugins: createPlugins(),
109
+ resolve: {
110
+ extensions: [".tsx", ".ts", ".js", ".mjs"],
111
+ alias: {
112
+ config: path.resolve(__dirname, process.env.NODE_ENV || 'development'),
113
+ },
114
+ plugins: [
115
+ new TsconfigPathsPlugin({}),
116
+ ],
117
+ },
118
+ stats: {
119
+ errorDetails: true,
120
+ }
121
+ ,
122
+ }