@@ -170,7 +170,7 @@ async function publishToAdminHlx(filename, outputLocation, log) {
170170 * @param {Function } say - Optional function to send messages (e.g., Slack say function)
171171 * @returns {Promise<void> }
172172 */
173- export async function copyFilesToSharepoint ( dataFolder , context , say = ( ) => { } ) {
173+ export async function copyFilesToSharepoint ( dataFolder , context , say = ( ) => { } ) {
174174 const { log, env } = context ;
175175
176176 const sharepointClient = await createSharePointClient ( env ) ;
@@ -209,7 +209,7 @@ export async function copyFilesToSharepoint(dataFolder, context, say = () => {})
209209 * @param {Function } say - Optional function to send messages (e.g., Slack say function)
210210 * @returns {Promise<void> }
211211 */
212- export async function updateIndexConfig ( dataFolder , context , say = ( ) => { } ) {
212+ export async function updateIndexConfig ( dataFolder , context , say = ( ) => { } ) {
213213 const { log, env } = context ;
214214
215215 log . debug ( 'Starting Git modification of helix query config' ) ;
@@ -260,7 +260,7 @@ export async function updateIndexConfig(dataFolder, context, say = () => {}) {
260260 * @param {object } slackContext - Slack context (optional, for Slack operations)
261261 * @returns {Promise<object> } The organization object
262262 */
263- export async function createOrFindOrganization ( imsOrgId , context , say = ( ) => { } ) {
263+ export async function createOrFindOrganization ( imsOrgId , context , say = ( ) => { } ) {
264264 const { dataAccess, log } = context ;
265265 const { Organization } = dataAccess ;
266266
@@ -320,7 +320,7 @@ export async function createOrFindSite(baseURL, organizationId, context) {
320320 * @param {Function } say - Optional function to send messages (e.g., Slack say function)
321321 * @returns {Promise<object> } The entitlement and enrollment objects
322322 */
323- export async function createEntitlementAndEnrollment ( site , context , say = ( ) => { } ) {
323+ export async function createEntitlementAndEnrollment ( site , context , say = ( ) => { } ) {
324324 const { log } = context ;
325325
326326 try {
@@ -339,6 +339,35 @@ export async function createEntitlementAndEnrollment(site, context, say = () =>
339339 }
340340}
341341
342+ export async function createEntitlementAndEnrollmentForOrg ( organization , context , say = ( ) => { } ) {
343+ const { log } = context ;
344+
345+ try {
346+ const tierClient = TierClient . createForOrg ( context , organization , LLMO_PRODUCT_CODE ) ;
347+ const { entitlement : existingEntitlement } = await tierClient . checkValidEntitlement ( LLMO_TIER ) ;
348+ const { entitlement } = await tierClient . createEntitlement ( LLMO_TIER ) ;
349+
350+ const wasNewlyCreated = ! existingEntitlement
351+ || existingEntitlement . getId ( ) !== entitlement . getId ( ) ;
352+
353+ if ( wasNewlyCreated ) {
354+ await say ( `Successfully created LLMO entitlement ${ entitlement . getId ( ) } for organization ${ organization . getId ( ) } ` ) ;
355+ } else {
356+ await say ( `Found existing LLMO entitlement ${ entitlement . getId ( ) } for organization ${ organization . getId ( ) } ` ) ;
357+ }
358+
359+ log . info ( `Successfully ensured LLMO access for organization ${ organization . getId ( ) } via entitlement ${ entitlement . getId ( ) } ` ) ;
360+
361+ return {
362+ entitlement,
363+ } ;
364+ } catch ( error ) {
365+ log . info ( `Ensuring LLMO entitlement failed: ${ error . message } ` ) ;
366+ await say ( '❌ Ensuring LLMO entitlement failed' ) ;
367+ throw error ;
368+ }
369+ }
370+
342371export async function enableAudits ( site , context , audits = [ ] ) {
343372 const { dataAccess } = context ;
344373 const { Configuration } = dataAccess ;
@@ -350,6 +379,27 @@ export async function enableAudits(site, context, audits = []) {
350379 await configuration . save ( ) ;
351380}
352381
382+ export async function performLlmoOrgOnboarding ( imsOrgId , context , say = ( ) => { } ) {
383+ const { log } = context ;
384+
385+ log . info ( `Starting LLMO organization onboarding for IMS Org ID: ${ imsOrgId } ` ) ;
386+ await say ( `:gear: Starting LLMO IMS org onboarding for *${ imsOrgId } *...` ) ;
387+ const organization = await createOrFindOrganization ( imsOrgId , context , say ) ;
388+
389+ try {
390+ const { entitlement } = await createEntitlementAndEnrollmentForOrg ( organization , context , say ) ;
391+
392+ return {
393+ organization,
394+ message : 'LLMO organization onboarding completed successfully' ,
395+ entitlement,
396+ } ;
397+ } catch ( error ) {
398+ log . error ( `Error creating entitlement for organization: ${ error . message } ` ) ;
399+ throw new Error ( `Failed to create LLMO entitlement for organization: ${ error . message } ` ) ;
400+ }
401+ }
402+
353403/**
354404 * Complete LLMO onboarding process.
355405 * @param {object } params - Onboarding parameters
0 commit comments