Skip to content

Commit d30485d

Browse files
committed
support f_ecom_ prefix (organization ID format) in sandbox lookup
1 parent e05b43f commit d30485d

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

packages/b2c-tooling-sdk/src/operations/ods/sandbox-lookup.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ const UUID_REGEX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
2323
*/
2424
const FRIENDLY_ID_REGEX = /^([a-z\d]{4})[-_]([a-z\d]+)$/i;
2525

26+
/**
27+
* Prefix used in organization ID format (e.g., f_ecom_zzpq_013).
28+
*/
29+
const ECOM_PREFIX = 'f_ecom_';
30+
31+
/**
32+
* Strips the f_ecom_ prefix if present.
33+
*/
34+
function normalizeIdentifier(value: string): string {
35+
if (value.toLowerCase().startsWith(ECOM_PREFIX)) {
36+
return value.slice(ECOM_PREFIX.length);
37+
}
38+
return value;
39+
}
40+
2641
/**
2742
* Error thrown when a sandbox cannot be found by its friendly identifier.
2843
*/
@@ -58,7 +73,7 @@ export function isUuid(value: string): boolean {
5873
* @returns true if the value matches the friendly format
5974
*/
6075
export function isFriendlySandboxId(value: string): boolean {
61-
return FRIENDLY_ID_REGEX.test(value);
76+
return FRIENDLY_ID_REGEX.test(normalizeIdentifier(value));
6277
}
6378

6479
/**
@@ -68,7 +83,8 @@ export function isFriendlySandboxId(value: string): boolean {
6883
* @returns Object with realm and instance, or null if not a valid friendly ID
6984
*/
7085
export function parseFriendlySandboxId(value: string): {realm: string; instance: string} | null {
71-
const match = value.match(FRIENDLY_ID_REGEX);
86+
const normalized = normalizeIdentifier(value);
87+
const match = normalized.match(FRIENDLY_ID_REGEX);
7288
if (!match) {
7389
return null;
7490
}

packages/b2c-tooling-sdk/test/operations/ods/sandbox-lookup.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ describe('sandbox-lookup', () => {
5555
expect(isFriendlySandboxId('a1b2_c3d')).to.be.true;
5656
});
5757

58+
it('should return true for friendly IDs with f_ecom_ prefix', () => {
59+
expect(isFriendlySandboxId('f_ecom_zzpq_013')).to.be.true;
60+
expect(isFriendlySandboxId('f_ecom_abcd_123')).to.be.true;
61+
expect(isFriendlySandboxId('F_ECOM_ZZZV_456')).to.be.true;
62+
});
63+
5864
it('should return false for invalid friendly IDs', () => {
5965
expect(isFriendlySandboxId('abc-123')).to.be.false; // realm too short
6066
expect(isFriendlySandboxId('abcde-123')).to.be.false; // realm too long
@@ -82,6 +88,12 @@ describe('sandbox-lookup', () => {
8288
expect(result).to.deep.equal({realm: 'abcd', instance: 'xyz'});
8389
});
8490

91+
it('should strip f_ecom_ prefix and parse', () => {
92+
expect(parseFriendlySandboxId('f_ecom_zzpq_013')).to.deep.equal({realm: 'zzpq', instance: '013'});
93+
expect(parseFriendlySandboxId('f_ecom_abcd_123')).to.deep.equal({realm: 'abcd', instance: '123'});
94+
expect(parseFriendlySandboxId('F_ECOM_ZZZV_456')).to.deep.equal({realm: 'zzzv', instance: '456'});
95+
});
96+
8597
it('should return null for invalid formats', () => {
8698
expect(parseFriendlySandboxId('abc-123')).to.be.null;
8799
expect(parseFriendlySandboxId('abcde-123')).to.be.null;
@@ -173,6 +185,23 @@ describe('sandbox-lookup', () => {
173185
expect(result).to.equal(expectedUuid);
174186
});
175187

188+
it('should look up sandbox by friendly ID with f_ecom_ prefix', async () => {
189+
const expectedUuid = 'found-uuid-1234-1234-abc123456789';
190+
191+
server.use(
192+
http.get(`${BASE_URL}/sandboxes`, ({request}) => {
193+
const url = new URL(request.url);
194+
expect(url.searchParams.get('filter_params')).to.equal('realm=zzpq');
195+
return HttpResponse.json({
196+
data: [{id: expectedUuid, realm: 'zzpq', instance: '013', state: 'started'}],
197+
});
198+
}),
199+
);
200+
201+
const result = await resolveSandboxId(odsClient, 'f_ecom_zzpq_013');
202+
expect(result).to.equal(expectedUuid);
203+
});
204+
176205
it('should throw SandboxNotFoundError when sandbox not found', async () => {
177206
server.use(
178207
http.get(`${BASE_URL}/sandboxes`, () => {

0 commit comments

Comments
 (0)