@iblai/data-layer 1.9.5 → 1.9.6

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/dist/index.js CHANGED
@@ -39052,6 +39052,7 @@ exports.SERVICES = void 0;
39052
39052
  SERVICES["LMS"] = "LMS";
39053
39053
  SERVICES["DM"] = "DM";
39054
39054
  SERVICES["AXD"] = "AXD";
39055
+ SERVICES["STUDIO"] = "STUDIO";
39055
39056
  })(exports.SERVICES || (exports.SERVICES = {}));
39056
39057
 
39057
39058
  class Config {
@@ -39061,6 +39062,7 @@ Config.lmsUrl = 'https://learn.iblai.app';
39061
39062
  Config.dmUrl = 'https://base.manager.iblai.app';
39062
39063
  Config.axdUrl = 'https://base.manager.iblai.app';
39063
39064
  Config.mentorIframeUrl = 'https://mentor.iblai.tech';
39065
+ Config.studioUrl = 'https://studio.iblai.app';
39064
39066
  Config.httpErrorHandlers = {};
39065
39067
 
39066
39068
  class IblDataLayer {
@@ -39127,10 +39129,23 @@ const getServiceUrl = (service) => {
39127
39129
  return Config.lmsUrl;
39128
39130
  case exports.SERVICES.DM:
39129
39131
  return Config.dmUrl;
39132
+ case exports.SERVICES.STUDIO:
39133
+ return Config.studioUrl;
39130
39134
  default:
39131
39135
  return Config.dmUrl;
39132
39136
  }
39133
39137
  };
39138
+ /**
39139
+ * Read a cookie value by name. Returns null outside the browser or when the
39140
+ * cookie is absent. Used for Studio's CSRF token (`csrftoken`).
39141
+ */
39142
+ const getCookieValue = (name) => {
39143
+ if (typeof document === 'undefined') {
39144
+ return null;
39145
+ }
39146
+ const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
39147
+ return match ? decodeURIComponent(match[1]) : null;
39148
+ };
39134
39149
  /**
39135
39150
  * Get the headers required for API requests based on the provided service type.
39136
39151
  */
@@ -39154,7 +39169,8 @@ const getHeaders = async (service) => {
39154
39169
  return; // No Authorization header when no valid token
39155
39170
  }
39156
39171
  let prefix;
39157
- if (service === exports.SERVICES.LMS) {
39172
+ // Studio (Open edX CMS) accepts the same edX token as the LMS.
39173
+ if (service === exports.SERVICES.LMS || service === exports.SERVICES.STUDIO) {
39158
39174
  if (token.length > 30) {
39159
39175
  prefix = 'JWT';
39160
39176
  }
@@ -39257,7 +39273,7 @@ const isErrorObject = (data) => {
39257
39273
  const baseQuery = (service, jsonContentType = true, contentType, skipAuth = false) => query.fetchBaseQuery({
39258
39274
  baseUrl: getServiceUrl(service),
39259
39275
  timeout: 30000, // 30 second timeout
39260
- credentials: service === exports.SERVICES.LEGACY_LMS ? 'include' : 'omit',
39276
+ credentials: service === exports.SERVICES.LEGACY_LMS || service === exports.SERVICES.STUDIO ? 'include' : 'omit',
39261
39277
  prepareHeaders: async (headers) => {
39262
39278
  // Only add auth headers if skipAuth is false
39263
39279
  if (!skipAuth) {
@@ -39275,6 +39291,18 @@ const baseQuery = (service, jsonContentType = true, contentType, skipAuth = fals
39275
39291
  if (contentType) {
39276
39292
  headers.set('Content-Type', contentType);
39277
39293
  }
39294
+ // Studio (Open edX CMS) endpoints require the Django CSRF token and only
39295
+ // return JSON when asked for it explicitly.
39296
+ if (service === exports.SERVICES.STUDIO) {
39297
+ const csrfToken = getCookieValue('csrftoken');
39298
+ if (csrfToken) {
39299
+ headers.set('X-CSRFToken', csrfToken);
39300
+ }
39301
+ if (!headers.has('Accept')) {
39302
+ headers.set('Accept', 'application/json');
39303
+ }
39304
+ headers.set('X-Requested-With', 'XMLHttpRequest');
39305
+ }
39278
39306
  // Add CSRF protection headers for LMS service
39279
39307
  if (service === exports.SERVICES.LMS) {
39280
39308
  // Use mentorIframeUrl for both origin and referer
@@ -42834,6 +42862,155 @@ const edxSsoApiSlice = react.createApi({
42834
42862
  });
42835
42863
  const { useGetEdxSSOTokenQuery, useLazyGetEdxSSOTokenQuery } = edxSsoApiSlice;
42836
42864
 
42865
+ const STUDIO_AUTHORING_ENDPOINTS = {
42866
+ CREATE_COURSE: {
42867
+ path: (contentType) => `/api/ibl/manage/${contentType}/`,
42868
+ service: exports.SERVICES.STUDIO,
42869
+ },
42870
+ DELETE_COURSE: {
42871
+ path: () => '/api/ibl/manage/course/delete',
42872
+ service: exports.SERVICES.STUDIO,
42873
+ },
42874
+ COURSE_SETTINGS: {
42875
+ path: (contentType) => `/api/ibl/v1/${contentType}_settings/`,
42876
+ service: exports.SERVICES.STUDIO,
42877
+ },
42878
+ CREATE_XBLOCK: {
42879
+ path: () => '/xblock/',
42880
+ service: exports.SERVICES.STUDIO,
42881
+ },
42882
+ UPDATE_XBLOCK: {
42883
+ path: (locator) => `/xblock/${locator}`,
42884
+ service: exports.SERVICES.STUDIO,
42885
+ },
42886
+ SCORM_SUBMIT: {
42887
+ path: (locator) => `/xblock/${locator}/handler/studio_submit`,
42888
+ service: exports.SERVICES.STUDIO,
42889
+ },
42890
+ UPLOAD_ASSET: {
42891
+ path: (courseKey) => `/assets/${courseKey}/`,
42892
+ service: exports.SERVICES.STUDIO,
42893
+ },
42894
+ ADVANCED_SETTINGS: {
42895
+ path: (courseKey) => `/settings/advanced/${courseKey}`,
42896
+ service: exports.SERVICES.STUDIO,
42897
+ },
42898
+ VIDEO_UPLOAD: {
42899
+ path: (courseKey) => `/api/v1/ibl/course/${courseKey}/s3-upload`,
42900
+ service: exports.SERVICES.STUDIO,
42901
+ },
42902
+ };
42903
+
42904
+ /**
42905
+ * Studio (Open edX CMS) course-authoring endpoints. These hit the Studio host
42906
+ * (`Config.studioUrl`) with cookie-session auth + CSRF token, mirroring how
42907
+ * Studio's own frontend talks to it.
42908
+ */
42909
+ const studioAuthoringApiSlice = react.createApi({
42910
+ reducerPath: 'studioAuthoringApiSlice',
42911
+ baseQuery: iblFetchBaseQuery,
42912
+ endpoints: (builder) => ({
42913
+ /** Create the course (or library) shell. Returns `course_key`. */
42914
+ createStudioCourse: builder.mutation({
42915
+ query: ({ courseData, contentType = 'course' }) => ({
42916
+ url: STUDIO_AUTHORING_ENDPOINTS.CREATE_COURSE.path(contentType),
42917
+ service: STUDIO_AUTHORING_ENDPOINTS.CREATE_COURSE.service,
42918
+ method: 'POST',
42919
+ body: courseData,
42920
+ }),
42921
+ }),
42922
+ /** Delete a course — used as rollback when a later creation step fails. */
42923
+ deleteStudioCourse: builder.mutation({
42924
+ query: ({ courseKey }) => ({
42925
+ url: STUDIO_AUTHORING_ENDPOINTS.DELETE_COURSE.path(),
42926
+ service: STUDIO_AUTHORING_ENDPOINTS.DELETE_COURSE.service,
42927
+ method: 'POST',
42928
+ body: { course_key: courseKey },
42929
+ }),
42930
+ }),
42931
+ /** Set the full course settings/metadata payload. */
42932
+ updateStudioCourseSettings: builder.mutation({
42933
+ query: ({ settings, contentType = 'course' }) => ({
42934
+ url: STUDIO_AUTHORING_ENDPOINTS.COURSE_SETTINGS.path(contentType),
42935
+ service: STUDIO_AUTHORING_ENDPOINTS.COURSE_SETTINGS.service,
42936
+ method: 'POST',
42937
+ body: settings,
42938
+ }),
42939
+ }),
42940
+ /**
42941
+ * Create an xblock node (chapter / sequential / vertical / video / scorm)
42942
+ * under `parent_locator`.
42943
+ */
42944
+ createStudioXblock: builder.mutation({
42945
+ query: (blockData) => ({
42946
+ url: STUDIO_AUTHORING_ENDPOINTS.CREATE_XBLOCK.path(),
42947
+ service: STUDIO_AUTHORING_ENDPOINTS.CREATE_XBLOCK.service,
42948
+ method: 'POST',
42949
+ body: blockData,
42950
+ }),
42951
+ }),
42952
+ /**
42953
+ * Update an existing xblock by locator — used for video metadata and for
42954
+ * publishing a unit (`{ publish: 'make_public' }`).
42955
+ */
42956
+ updateStudioXblock: builder.mutation({
42957
+ query: ({ locator, blockData }) => ({
42958
+ url: STUDIO_AUTHORING_ENDPOINTS.UPDATE_XBLOCK.path(encodeURIComponent(locator)),
42959
+ service: STUDIO_AUTHORING_ENDPOINTS.UPDATE_XBLOCK.service,
42960
+ method: 'POST',
42961
+ body: blockData,
42962
+ }),
42963
+ }),
42964
+ /** Upload the SCORM zip to the scorm xblock's `studio_submit` handler. */
42965
+ uploadStudioScormPackage: builder.mutation({
42966
+ query: ({ locator, formData }) => ({
42967
+ url: STUDIO_AUTHORING_ENDPOINTS.SCORM_SUBMIT.path(encodeURIComponent(locator)),
42968
+ service: STUDIO_AUTHORING_ENDPOINTS.SCORM_SUBMIT.service,
42969
+ method: 'POST',
42970
+ body: formData,
42971
+ isJson: false,
42972
+ }),
42973
+ }),
42974
+ /** Upload a course asset (e.g. the course card image). */
42975
+ uploadStudioCourseAsset: builder.mutation({
42976
+ query: ({ courseKey, formData }) => ({
42977
+ url: STUDIO_AUTHORING_ENDPOINTS.UPLOAD_ASSET.path(encodeURIComponent(courseKey)),
42978
+ service: STUDIO_AUTHORING_ENDPOINTS.UPLOAD_ASSET.service,
42979
+ method: 'POST',
42980
+ body: formData,
42981
+ isJson: true,
42982
+ // Asset upload is authenticated by the Studio session cookie + CSRF
42983
+ // token alone; no Authorization header.
42984
+ skipAuth: true,
42985
+ // Matches how Studio's own frontend requests the asset endpoint. Set
42986
+ // explicitly so the base query keeps it instead of defaulting to
42987
+ // `application/json`.
42988
+ headers: { Accept: 'application/json, text/plain, */*' },
42989
+ }),
42990
+ }),
42991
+ /** Set Studio advanced settings (e.g. enable the `scorm` module). */
42992
+ setStudioAdvancedSettings: builder.mutation({
42993
+ query: ({ courseKey, settings }) => ({
42994
+ url: STUDIO_AUTHORING_ENDPOINTS.ADVANCED_SETTINGS.path(encodeURIComponent(courseKey)),
42995
+ service: STUDIO_AUTHORING_ENDPOINTS.ADVANCED_SETTINGS.service,
42996
+ method: 'POST',
42997
+ body: settings,
42998
+ }),
42999
+ }),
43000
+ /** Upload a raw video file to course storage; returns `{ file_url }`. */
43001
+ uploadStudioCourseVideo: builder.mutation({
43002
+ query: ({ courseKey, formData }) => ({
43003
+ url: STUDIO_AUTHORING_ENDPOINTS.VIDEO_UPLOAD.path(encodeURIComponent(courseKey)),
43004
+ service: STUDIO_AUTHORING_ENDPOINTS.VIDEO_UPLOAD.service,
43005
+ method: 'POST',
43006
+ body: formData,
43007
+ isJson: false,
43008
+ }),
43009
+ }),
43010
+ }),
43011
+ });
43012
+ const { useCreateStudioCourseMutation, useDeleteStudioCourseMutation, useUpdateStudioCourseSettingsMutation, useCreateStudioXblockMutation, useUpdateStudioXblockMutation, useUploadStudioScormPackageMutation, useUploadStudioCourseAssetMutation, useSetStudioAdvancedSettingsMutation, useUploadStudioCourseVideoMutation, } = studioAuthoringApiSlice;
43013
+
42837
43014
  const searchApiSlice = react.createApi({
42838
43015
  reducerPath: 'searchApiSlice',
42839
43016
  baseQuery: iblFakeBaseQuery,
@@ -46247,6 +46424,7 @@ const mentorReducer = {
46247
46424
  [coursesApiSlice.reducerPath]: coursesApiSlice.reducer,
46248
46425
  [courseMetadataApiSlice.reducerPath]: courseMetadataApiSlice.reducer,
46249
46426
  [edxSsoApiSlice.reducerPath]: edxSsoApiSlice.reducer,
46427
+ [studioAuthoringApiSlice.reducerPath]: studioAuthoringApiSlice.reducer,
46250
46428
  [clawApiSlice.reducerPath]: clawApiSlice.reducer,
46251
46429
  [evaluationsApiSlice.reducerPath]: evaluationsApiSlice.reducer,
46252
46430
  [watchedGroupsApiSlice.reducerPath]: watchedGroupsApiSlice.reducer,
@@ -46304,6 +46482,7 @@ const mentorMiddleware = [
46304
46482
  coursesApiSlice.middleware,
46305
46483
  courseMetadataApiSlice.middleware,
46306
46484
  edxSsoApiSlice.middleware,
46485
+ studioAuthoringApiSlice.middleware,
46307
46486
  clawApiSlice.middleware,
46308
46487
  evaluationsApiSlice.middleware,
46309
46488
  watchedGroupsApiSlice.middleware,
@@ -46349,6 +46528,7 @@ const skillsReducer = {
46349
46528
  [coursesApiSlice.reducerPath]: coursesApiSlice.reducer,
46350
46529
  [courseMetadataApiSlice.reducerPath]: courseMetadataApiSlice.reducer,
46351
46530
  [edxSsoApiSlice.reducerPath]: edxSsoApiSlice.reducer,
46531
+ [studioAuthoringApiSlice.reducerPath]: studioAuthoringApiSlice.reducer,
46352
46532
  [watchedGroupsApiSlice.reducerPath]: watchedGroupsApiSlice.reducer,
46353
46533
  [chatPrivacyApiSlice.reducerPath]: chatPrivacyApiSlice.reducer,
46354
46534
  };
@@ -46390,16 +46570,20 @@ const skillsMiddleware = [
46390
46570
  coursesApiSlice.middleware,
46391
46571
  courseMetadataApiSlice.middleware,
46392
46572
  edxSsoApiSlice.middleware,
46573
+ studioAuthoringApiSlice.middleware,
46393
46574
  watchedGroupsApiSlice.middleware,
46394
46575
  chatPrivacyApiSlice.middleware,
46395
46576
  ];
46396
46577
 
46397
- const initializeDataLayer = (dmUrl, lmsUrl, legacyLmsUrl, storageService, httpErrorHandler = {}) => {
46578
+ const initializeDataLayer = (dmUrl, lmsUrl, legacyLmsUrl, storageService, httpErrorHandler = {}, studioUrl) => {
46398
46579
  IblDataLayer.storage = storageService;
46399
46580
  Config.dmUrl = dmUrl;
46400
46581
  Config.lmsUrl = lmsUrl;
46401
46582
  Config.legacyLmsUrl = legacyLmsUrl;
46402
46583
  Config.httpErrorHandlers = httpErrorHandler;
46584
+ if (studioUrl) {
46585
+ Config.studioUrl = studioUrl;
46586
+ }
46403
46587
  };
46404
46588
 
46405
46589
  exports.APP_IDENTIFIERS = APP_IDENTIFIERS;
@@ -46467,6 +46651,7 @@ exports.PROJECTS_QUERY_KEYS = PROJECTS_QUERY_KEYS;
46467
46651
  exports.QUERY_PARAMS = QUERY_PARAMS;
46468
46652
  exports.RETIREMENT_ENDPOINTS = RETIREMENT_ENDPOINTS;
46469
46653
  exports.STORAGE_KEYS = STORAGE_KEYS;
46654
+ exports.STUDIO_AUTHORING_ENDPOINTS = STUDIO_AUTHORING_ENDPOINTS;
46470
46655
  exports.SUGGESTED_PRIVACY_ENTITIES = SUGGESTED_PRIVACY_ENTITIES;
46471
46656
  exports.TENANT_IDENTIFIERS = TENANT_IDENTIFIERS;
46472
46657
  exports.TENANT_LOGO_ENDPOINTS = TENANT_LOGO_ENDPOINTS;
@@ -46556,6 +46741,7 @@ exports.skillsApiSlice = skillsApiSlice;
46556
46741
  exports.skillsMiddleware = skillsMiddleware;
46557
46742
  exports.skillsReducer = skillsReducer;
46558
46743
  exports.stripeApiSlice = stripeApiSlice;
46744
+ exports.studioAuthoringApiSlice = studioAuthoringApiSlice;
46559
46745
  exports.tenantApiReducer = tenantApiReducer;
46560
46746
  exports.tenantApiSlice = tenantApiSlice;
46561
46747
  exports.tenantLogoApiSlice = tenantLogoApiSlice;
@@ -46636,6 +46822,8 @@ exports.useCreateSessionIdMutation = useCreateSessionIdMutation;
46636
46822
  exports.useCreateShareableLinkMutation = useCreateShareableLinkMutation;
46637
46823
  exports.useCreateStripeCheckoutSessionMutation = useCreateStripeCheckoutSessionMutation;
46638
46824
  exports.useCreateStripeCustomerPortalMutation = useCreateStripeCustomerPortalMutation;
46825
+ exports.useCreateStudioCourseMutation = useCreateStudioCourseMutation;
46826
+ exports.useCreateStudioXblockMutation = useCreateStudioXblockMutation;
46639
46827
  exports.useCreateTrainingDocumentRetrainScheduleMutation = useCreateTrainingDocumentRetrainScheduleMutation;
46640
46828
  exports.useCreateUserCompanyMutation = useCreateUserCompanyMutation;
46641
46829
  exports.useCreateUserEducationMutation = useCreateUserEducationMutation;
@@ -46684,6 +46872,7 @@ exports.useDeleteRbacGroupMutation = useDeleteRbacGroupMutation;
46684
46872
  exports.useDeleteRbacPolicyMutation = useDeleteRbacPolicyMutation;
46685
46873
  exports.useDeleteRbacRoleMutation = useDeleteRbacRoleMutation;
46686
46874
  exports.useDeleteRecommendedPromptMutation = useDeleteRecommendedPromptMutation;
46875
+ exports.useDeleteStudioCourseMutation = useDeleteStudioCourseMutation;
46687
46876
  exports.useDeleteTrainingDocumentMutation = useDeleteTrainingDocumentMutation;
46688
46877
  exports.useDeleteUserEducationMutation = useDeleteUserEducationMutation;
46689
46878
  exports.useDeleteUserExperienceMutation = useDeleteUserExperienceMutation;
@@ -47165,6 +47354,7 @@ exports.useSendNotificationMutation = useSendNotificationMutation;
47165
47354
  exports.useSetCurrentVersionMutation = useSetCurrentVersionMutation;
47166
47355
  exports.useSetPlatformConfigurationsMutation = useSetPlatformConfigurationsMutation;
47167
47356
  exports.useSetStudentMentorCreationStatusMutation = useSetStudentMentorCreationStatusMutation;
47357
+ exports.useSetStudioAdvancedSettingsMutation = useSetStudioAdvancedSettingsMutation;
47168
47358
  exports.useStarMentorMutation = useStarMentorMutation;
47169
47359
  exports.useStarredMentorsQuery = useStarredMentorsQuery;
47170
47360
  exports.useStartEvalRunMutation = useStartEvalRunMutation;
@@ -47218,6 +47408,8 @@ exports.useUpdateRbacRoleMutation = useUpdateRbacRoleMutation;
47218
47408
  exports.useUpdateRecommendedPromptMutation = useUpdateRecommendedPromptMutation;
47219
47409
  exports.useUpdateSessionDisableChathistoryMutation = useUpdateSessionDisableChathistoryMutation;
47220
47410
  exports.useUpdateShareableLinkMutation = useUpdateShareableLinkMutation;
47411
+ exports.useUpdateStudioCourseSettingsMutation = useUpdateStudioCourseSettingsMutation;
47412
+ exports.useUpdateStudioXblockMutation = useUpdateStudioXblockMutation;
47221
47413
  exports.useUpdateTemplateMutation = useUpdateTemplateMutation;
47222
47414
  exports.useUpdateTenantChatPrivacyConfigMutation = useUpdateTenantChatPrivacyConfigMutation;
47223
47415
  exports.useUpdateTenantMetadataMutation = useUpdateTenantMetadataMutation;
@@ -47242,6 +47434,9 @@ exports.useUploadDarkLogoMutation = useUploadDarkLogoMutation;
47242
47434
  exports.useUploadEvalDatasetCsvMutation = useUploadEvalDatasetCsvMutation;
47243
47435
  exports.useUploadLightLogoMutation = useUploadLightLogoMutation;
47244
47436
  exports.useUploadProfileImageMutation = useUploadProfileImageMutation;
47437
+ exports.useUploadStudioCourseAssetMutation = useUploadStudioCourseAssetMutation;
47438
+ exports.useUploadStudioCourseVideoMutation = useUploadStudioCourseVideoMutation;
47439
+ exports.useUploadStudioScormPackageMutation = useUploadStudioScormPackageMutation;
47245
47440
  exports.useUsersGradesPassedQuery = useUsersGradesPassedQuery;
47246
47441
  exports.useValidateWorkflowMutation = useValidateWorkflowMutation;
47247
47442
  exports.userApiSlice = userApiSlice;