Skip to content

Commit fd90995

Browse files
add onboard profile name and start time to onboardConfig
1 parent 3f9c15c commit fd90995

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

package-lock.json

Lines changed: 20 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/spacecat-shared-data-access/src/models/site/config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ export const configSchema = Joi.object({
383383
}),
384384
).optional(),
385385
}).optional(),
386+
onboardConfig: Joi.object({
387+
lastProfile: Joi.string().optional(),
388+
lastStartTime: Joi.number().optional(),
389+
}).optional(),
386390
contentAiConfig: Joi.object({
387391
index: Joi.string().optional(),
388392
}).optional(),
@@ -494,6 +498,7 @@ export const Config = (data = {}) => {
494498
self.getLlmoCdnBucketConfig = () => state?.llmo?.cdnBucketConfig;
495499
self.getTokowakaConfig = () => state?.tokowakaConfig;
496500
self.getEdgeOptimizeConfig = () => state?.edgeOptimizeConfig;
501+
self.getOnboardConfig = () => state?.onboardConfig;
497502
self.updateSlackConfig = (channel, workspace, invitedUserCount) => {
498503
state.slack = {
499504
channel,
@@ -814,6 +819,10 @@ export const Config = (data = {}) => {
814819
state.edgeOptimizeConfig = edgeOptimizeConfig;
815820
};
816821

822+
self.updateOnboardConfig = (onboardConfig) => {
823+
state.onboardConfig = { ...(state.onboardConfig || {}), ...onboardConfig };
824+
};
825+
817826
return Object.freeze(self);
818827
};
819828

@@ -831,4 +840,5 @@ Config.toDynamoItem = (config) => ({
831840
llmo: config.getLlmoConfig(),
832841
tokowakaConfig: config.getTokowakaConfig(),
833842
edgeOptimizeConfig: config.getEdgeOptimizeConfig(),
843+
onboardConfig: config.getOnboardConfig(),
834844
});

packages/spacecat-shared-data-access/src/models/site/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export interface SiteConfig {
146146
urlPatterns?: Array<LlmoUrlPattern>;
147147
customerIntent?: Array<LlmoCustomerIntent>;
148148
};
149+
onboardConfig?: {
150+
lastProfile?: string;
151+
lastStartTime?: number;
152+
};
149153
};
150154
extractWellKnownTags(tags: Array<string>): Partial<Record<WellKnownLmmoTag, string>>;
151155
getSlackConfig(): { workspace?: string; channel?: string; invitedUserCount?: number };
@@ -197,6 +201,8 @@ export interface SiteConfig {
197201
updateLlmoCustomerIntent(intentKey: string, updateData: Partial<LlmoCustomerIntent>): void;
198202
addLlmoTag(tag: string): void;
199203
removeLlmoTag(tag: string): void;
204+
getOnboardConfig(): { lastProfile?: string; lastStartTime?: number } | undefined;
205+
updateOnboardConfig(onboardConfig: { lastProfile?: string; lastStartTime?: number }): void;
200206
}
201207

202208
export interface Site extends BaseModel {

packages/spacecat-shared-data-access/test/unit/models/site/config.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,62 @@ describe('Config Tests', () => {
27632763
});
27642764
});
27652765

2766+
describe('onboard config', () => {
2767+
it('returns undefined when not set', () => {
2768+
const config = Config();
2769+
expect(config.getOnboardConfig()).to.be.undefined;
2770+
});
2771+
2772+
it('creates a Config with onboardConfig property', () => {
2773+
const config = Config({ onboardConfig: { lastProfile: 'paid' } });
2774+
expect(config.getOnboardConfig()).to.deep.equal({ lastProfile: 'paid' });
2775+
});
2776+
2777+
it('stores lastStartTime', () => {
2778+
const startTime = Date.now();
2779+
const config = Config({ onboardConfig: { lastProfile: 'paid', lastStartTime: startTime } });
2780+
expect(config.getOnboardConfig().lastStartTime).to.equal(startTime);
2781+
});
2782+
2783+
it('updates onboard config', () => {
2784+
const config = Config();
2785+
config.updateOnboardConfig({ lastProfile: 'paid' });
2786+
expect(config.getOnboardConfig()).to.deep.equal({ lastProfile: 'paid' });
2787+
});
2788+
2789+
it('merges lastStartTime into existing onboard config', () => {
2790+
const startTime = Date.now();
2791+
const config = Config({ onboardConfig: { lastProfile: 'paid' } });
2792+
config.updateOnboardConfig({ lastStartTime: startTime });
2793+
expect(config.getOnboardConfig()).to.deep.equal({ lastProfile: 'paid', lastStartTime: startTime });
2794+
});
2795+
2796+
it('merges into existing onboard config', () => {
2797+
const config = Config({ onboardConfig: { lastProfile: 'demo' } });
2798+
config.updateOnboardConfig({ lastProfile: 'paid' });
2799+
expect(config.getOnboardConfig()).to.deep.equal({ lastProfile: 'paid' });
2800+
});
2801+
2802+
it('stores only lastStartTime when lastProfile is absent', () => {
2803+
const startTime = Date.now();
2804+
const config = Config({ onboardConfig: { lastStartTime: startTime } });
2805+
expect(config.getOnboardConfig()).to.deep.equal({ lastStartTime: startTime });
2806+
});
2807+
2808+
it('includes onboardConfig in toDynamoItem', () => {
2809+
const startTime = Date.now();
2810+
const config = Config({ onboardConfig: { lastProfile: 'paid', lastStartTime: startTime } });
2811+
const dynamoItem = Config.toDynamoItem(config);
2812+
expect(dynamoItem.onboardConfig).to.deep.equal({ lastProfile: 'paid', lastStartTime: startTime });
2813+
});
2814+
2815+
it('omits onboardConfig from toDynamoItem when not set', () => {
2816+
const config = Config();
2817+
const dynamoItem = Config.toDynamoItem(config);
2818+
expect(dynamoItem.onboardConfig).to.be.undefined;
2819+
});
2820+
});
2821+
27662822
describe('LLMO Well Known Tags', () => {
27672823
const { extractWellKnownTags } = Config();
27682824

0 commit comments

Comments
 (0)